Skip to content

feat(laurel): short-circuit AndThen/OrElse, eager And/Or, forLoop, javaGen improvements#590

Merged
keyboardDrummer merged 5 commits intostrata-org:mainfrom
fabiomadge:feat/laurel-short-circuit-and-javagen-improvements
Mar 19, 2026
Merged

feat(laurel): short-circuit AndThen/OrElse, eager And/Or, forLoop, javaGen improvements#590
keyboardDrummer merged 5 commits intostrata-org:mainfrom
fabiomadge:feat/laurel-short-circuit-and-javagen-improvements

Conversation

@fabiomadge
Copy link
Copy Markdown
Contributor

@fabiomadge fabiomadge commented Mar 17, 2026

Changes

Short-circuit and eager boolean operators

  • Add AndThen/OrElse operations (short-circuit via ite in Core)
  • Keep And/Or as eager (boolAndOp/boolOrOp)
  • Grammar: &&/|| map to AndThen/OrElse, &/| map to And/Or
  • Implies uses short-circuit (ite a b true)
  • Desugar AndThen/OrElse/Implies to IfThenElse before expression lifting when the second operand contains imperative calls, preserving short-circuit semantics
  • Tests cover pure path (function with requires false, division by zero) and imperative path (procedure with requires false) for all three operators

For loop

  • Add forLoop grammar op: for(init; cond; step) invariants body
  • Desugars to Block[init, While(cond, invariants, Block[body, step])] in ConcreteToAbstractTreeTranslator
  • Test in T17_ForLoop.lean

javaGen CLI improvements

  • Accepts a dialect name (e.g. Laurel) in addition to a file path
  • Integration test for preloaded dialect path

Solver config

  • Extract laurelVerifyOptions to deduplicate z3 solver config across Laurel commands

Windows fix

@fabiomadge fabiomadge requested a review from a team March 17, 2026 05:56
Comment thread Strata/Languages/Laurel/LaurelToCoreTranslator.lean Outdated
Comment thread StrataMain.lean Outdated
@keyboardDrummer
Copy link
Copy Markdown
Contributor

Curious what made you decide to support generating based on the preloaded Laurel grammar - a nice addition btw.

Copy link
Copy Markdown
Contributor

@keyboardDrummer keyboardDrummer left a comment

Choose a reason for hiding this comment

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

To prevent accidental unsoundness due to Laurel consumers misinterpreting the meaning of And/Or/Implies, please rename them to make the laziness clear, and please add tests to confirm the laziness. To do the equivalent of an assert false in the assert false branches, you can call a function with requires false as a precondition.

@fabiomadge fabiomadge force-pushed the feat/laurel-short-circuit-and-javagen-improvements branch 4 times, most recently from 64c1724 to c39a7af Compare March 17, 2026 20:51
@fabiomadge fabiomadge changed the title feat(laurel): short-circuit And/Or/Implies; improve javaGen CLI and test feat(laurel): short-circuit AndThen/OrElse, eager And/Or, forLoop, javaGen improvements Mar 17, 2026
@fabiomadge
Copy link
Copy Markdown
Contributor Author

The preloading of Laurel in buildDialectFileMap broke javaGen when passed the .st file path — it threw 'Laurel already loaded'. This was a blocker for JVerify's make generate-laurel-ast. The fix follows the same pattern as the print command.

aqjune-aws
aqjune-aws previously approved these changes Mar 17, 2026
@fabiomadge fabiomadge force-pushed the feat/laurel-short-circuit-and-javagen-improvements branch 3 times, most recently from fa1bf01 to 306194c Compare March 18, 2026 01:57
Comment thread Strata/Languages/Laurel/LaurelToCoreTranslator.lean
@fabiomadge fabiomadge force-pushed the feat/laurel-short-circuit-and-javagen-improvements branch 2 times, most recently from 3895a30 to a95df0a Compare March 18, 2026 04:48
- Translate And, Or, Implies to short-circuit ite expressions in
  LaurelToCoreTranslator instead of non-short-circuit boolean ops
- javaGen now accepts a dialect name (e.g. Laurel) in addition to a
  file path, with a helpful error when neither resolves
- Add integration test for javaGen with preloaded dialects, with
  proper cleanup on all exit paths and failure on missing files
- Add comments documenting why Laurel pipeline commands use z3
…, forLoop, tests

- Add AndThen/OrElse operations (short-circuit via ite in Core)
- Keep And/Or as eager (boolAndOp/boolOrOp), expose with & / | syntax
- Grammar: && / || map to AndThen/OrElse, & / | map to And/Or
- Add forLoop grammar op, desugars to Block[init, While(cond, inv, Block[body, step])]
- Add short-circuit laziness tests (requires false, division by zero)
- Add for loop test
- Deduplicate solver config (laurelVerifyOptions)
- Touch LaurelGrammar.lean to trigger grammar rebuild
On Windows, z3 outputs 'unsat\r\n'. String.extract produces a Substring,
and trimAscii returns a Slice that doesn't match string literals in
pattern matching. Adding .toString converts it to a String first.
@fabiomadge fabiomadge force-pushed the feat/laurel-short-circuit-and-javagen-improvements branch from a95df0a to 83169fe Compare March 18, 2026 05:08
Comment thread Strata/Languages/Laurel/LiftImperativeExpressions.lean Outdated
Add DesugarShortCircuit pass that rewrites AndThen/OrElse/Implies to
IfThenElse when the second operand contains imperative calls. Called
from the translate pipeline before LiftImperativeExpressions.

Pure operands pass through unchanged and are handled by the Core translator.
Tests cover both pure and imperative paths for all three operators.
@fabiomadge fabiomadge force-pushed the feat/laurel-short-circuit-and-javagen-improvements branch from 83169fe to a88f294 Compare March 18, 2026 20:42
@keyboardDrummer
Copy link
Copy Markdown
Contributor

The preloading of Laurel in buildDialectFileMap broke javaGen when passed the .st file path — it threw 'Laurel already loaded'. This was a blocker for JVerify's make generate-laurel-ast. The fix follows the same pattern as the print command.

Interesting! Thanks

Copy link
Copy Markdown
Contributor

@keyboardDrummer keyboardDrummer left a comment

Choose a reason for hiding this comment

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

Looks great, thanks

Comment thread Strata/Languages/Laurel/LaurelToCoreTranslator.lean
@keyboardDrummer keyboardDrummer added this pull request to the merge queue Mar 19, 2026
Merged via the queue into strata-org:main with commit 706fdad Mar 19, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants