Skip to content

Support return statements in Laurel functions#486

Open
keyboardDrummer wants to merge 40 commits intomainfrom
remy/functionControlFlow
Open

Support return statements in Laurel functions#486
keyboardDrummer wants to merge 40 commits intomainfrom
remy/functionControlFlow

Conversation

@keyboardDrummer
Copy link
Contributor

@keyboardDrummer keyboardDrummer commented Feb 26, 2026

Changes

Functional:

  • Adds a new EliminateReturnsInExpression pass that tries to eliminate return statements.
  • Adds not supported message for assert, assume, and local variable declarations without an initializer, that occur in expressions.

Refactoring:

  • Introduces a MetaData type abbreviation and refactors the disallowed helper signature
  • Renames boogie* variables to core* in translateStmt

Performance:

  • Partitions liftImperativeExpressions to skip functional procedures. This does not change the outcome of the pipeline but it might reduce work a bit.

Testing

  • Added cases to T3_ControlFlow
  • Added T3_ControlFlowError to clarify that assert and assume are not yet supported in functions

@keyboardDrummer keyboardDrummer changed the title remy/functionControlFlow Support return statements in Laurel functions Mar 3, 2026
@keyboardDrummer keyboardDrummer marked this pull request as ready for review March 3, 2026 11:40
@keyboardDrummer keyboardDrummer requested a review from a team March 3, 2026 11:40
@joehendrix
Copy link
Contributor

Minor note: canBeCoreFunctionBody and isPureExpr in LaurelToCoreTranslator.lean (lines 451–506) appear to be dead code — neither is called anywhere in the codebase. The translation pipeline partitions by isFunctional (line 591) and attempts translation directly via tryTranslatePureToFunction, collecting diagnostics rather than pre-checking purity. Consider removing these or adding a comment explaining their intended future use.

@joehendrix
Copy link
Contributor

The PR description understates the scope of this change. Beyond supporting return statements, this PR also:

  • Adds a new EliminateReturnsInExpression pass that rewrites guard patterns (if-then without else) into if-then-else expression trees
  • Partitions liftImperativeExpressions to skip functional procedures
  • Adds translateExpr handlers for Assert, Assume, and LocalVariable blocks in pure context
  • Introduces a MetaData type abbreviation and refactors the disallowed helper signature
  • Renames boogie* variables to core* in translateStmt

Consider updating the description to better reflect the full set of changes.

Copy link
Contributor

@fabiomadge fabiomadge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The return elimination pass has a wrong-code bug when a full if-else (with returns in both branches) appears as a non-last statement in a function body. We could also just disallow it, or fail properly. See inline comment for details and repro.

joehendrix
joehendrix previously approved these changes Mar 4, 2026
Copy link
Contributor

@joehendrix joehendrix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left one performance comment, but I don't consider it blocking.

fabiomadge
fabiomadge previously approved these changes Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants