Migrate PEx expressions to the shared expression-visitor base#952
Merged
ankushdesai merged 1 commit intoMay 25, 2026
Merged
Conversation
PExCodeGenerator now extends ExpressionGenerator<CompilationContext>; its WriteExpr switch is replaced by the 31 Write*Expr overrides (bodies moved verbatim). PEx's Nondet/FairNondet shared a switch arm, now routed through a small WriteRandomBool helper to keep the emission identical. With both PChecker and PEx on the base, adding a new IPExpr node forces both to handle it at compile time. Verified: CompilerCore builds clean; PEx-generated Java for tutorials 1-6 is byte-for-byte identical to master (EspressoMachine fails PEx codegen identically on both, due to the pre-existing 'receive in loop' limitation, unrelated to this change).
Contributor
There was a problem hiding this comment.
Pull request overview
Phase 2 of the shared expression-visitor refactor: migrates PExCodeGenerator onto the ExpressionGenerator<CompilationContext> base introduced in #951, replacing the single WriteExpr switch with 31 per-node Write*Expr overrides whose bodies are moved verbatim.
Changes:
PExCodeGeneratornow extendsExpressionGenerator<CompilationContext>instead of having its ownWriteExprswitch.- The previously combined
NondetExpr/FairNondetExprswitch arm is split into two overrides that delegate to a new privateWriteRandomBoolhelper, preserving emitted output. - The old
defaultarm that emitted/* Skipping expr ... */is dropped in favor of the base class's throw (dead in practice).
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Phase 2 of the shared expression-visitor refactor. Migrates PEx onto
ExpressionGenerator<TContext>(introduced in #951).PExCodeGeneratornow extendsExpressionGenerator<CompilationContext>, and itsWriteExprswitch is replaced by the 31Write*Exproverrides, bodies moved verbatim. PEx'sNondetExpr/FairNondetExprpreviously shared one switch arm; they're now two overrides routed through a small privateWriteRandomBoolhelper so the emitted code is unchanged.With PChecker (#951) and PEx both on the base, adding a new
IPExprnode forces both backends to handle it or fail to compile.Verification (local, .NET 8)
CompilerCorebuilds clean (only the unrelated pre-existingTransformASTPass.cs:796CS0162 warning).diff -rqclean). EspressoMachine fails PEx codegen identically on both old and new — the pre-existing "receive in a loop body is not supported" limitation (TransformASTPass.cs:793), unrelated to this change.Note on the old
defaultarmPEx's previous
WriteExprdefaultemitted a/* Skipping expr ... */comment; the shared base throws instead. Since all three imperative backends handle the identical 31-node set, that arm was dead for real input — confirmed by the byte-identical tutorial output.Follow-ups
WriteStmtbase + migrate PChecker/PEx statements.Generated by Claude Code