Skip to content

Extend LiftImperativeExpression pass to handle assert/assume#46

Draft
keyboardDrummer-bot wants to merge 1 commit into
mainfrom
lift-imperative-assert-assume
Draft

Extend LiftImperativeExpression pass to handle assert/assume#46
keyboardDrummer-bot wants to merge 1 commit into
mainfrom
lift-imperative-assert-assume

Conversation

@keyboardDrummer-bot
Copy link
Copy Markdown
Collaborator

Extends the LiftImperativeExpression pass to handle assert and assume nodes, as described in #43.

Changes

Strata/Languages/Laurel/LiftImperativeExpressions.lean:

  • Added .Assert and .Assume cases to transformExpr — when these appear in expression context (e.g. inside block expressions), their conditions are transformed with a fresh substitution context (to lift any assignments within), and the assert/assume itself is lifted to prepends using the correct ordering pattern.
  • Updated transformStmt for .Assert and .Assume to always transform their conditions, lifting assignments and imperative calls (previously only handled nondet holes).
  • Added .Assert and .Assume to containsAssignmentOrImperativeCall for recursive detection of impure expressions within assert/assume conditions.

StrataTest/Languages/Laurel/LiftExpressionAssignmentsTest.lean:

  • Added test for the example from the issue: var y := { assert x > 0; 3 } and assert (x := 2) == 2
  • Added test for assume (x := 2) == 2

StrataTest/Languages/Laurel/Examples/Fundamentals/T2_ImpureExpressionsError.lean:

  • Removed error expectations for assert with assignments/imperative calls in procedure bodies, since these are now handled by the lift pass (errors remain for contracts/functions which are pure contexts).

Prepend ordering

For lifted nodes, the prepend ordering follows the pattern from the issue:

argPrepends ++ liftedNode ++ prePrepends

ensuring child prepends come before the lifted node itself, and outer prepends come after.

Fixes #43"

- Add Assert/Assume cases to transformExpr so assignments within
  assert/assume conditions in expression context are lifted correctly
- Update transformStmt for Assert/Assume to always transform their
  conditions (lifting assignments and imperative calls)
- Add Assert/Assume to containsAssignmentOrImperativeCall for recursive
  detection
- Use fresh substitution context when processing assert/assume in
  expression position to avoid applying outer substitutions
- Follow the prepend ordering pattern: child prepends come before the
  lifted node itself

Fixes #43
@keyboardDrummer-bot
Copy link
Copy Markdown
Collaborator Author

The "Run internal benchmarks of Strata" failure is not caused by the code changes in this PR. It's a systemic issue affecting all PRs on this fork — the CI workflow's benchmark job is hardcoded to pull source from strata-org/Strata.git but the commit SHA only exists in keyboardDrummer/Strata, so CodeBuild can't find the commit and fails immediately (~1 minute runtime). The same failure occurs on PR #44 and other PRs from this fork.

Locally, the build and all 591 test jobs pass successfully with no errors.

@github-actions github-actions Bot added the Git conflicts PR has merge conflicts with the base branch label May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Git conflicts PR has merge conflicts with the base branch Laurel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend LiftImperativeExpression pass

2 participants