Skip to content

Laurel Language Enhancements#385

Draft
fabiomadge wants to merge 328 commits intomainfrom
jverify-strata-backend
Draft

Laurel Language Enhancements#385
fabiomadge wants to merge 328 commits intomainfrom
jverify-strata-backend

Conversation

@fabiomadge
Copy link
Contributor

@fabiomadge fabiomadge commented Feb 4, 2026

Summary

Expands the Laurel language with additional operators, data types, and verification constructs. Improves formatting across multiple dialects.

Key Changes

Laurel Grammar & Translator

  • New operators: -, *, /, %, /t, %t (truncating), ==>, !, unary -
  • Array support: Array<T> type, indexing, length
  • Sequence operations: Seq.From, Seq.Take, Seq.Drop, Seq.Contains
  • Constrained types with constraint injection into quantifiers
  • Quantifiers: forall, exists
  • Return statement works with postconditions
  • While loops with multiple invariants
  • Multiple requires clauses per procedure

Infrastructure

  • NewlineSepBy separator type for formatting preservation
  • Java codegen: list separator preservation, SourceRange overloads
  • Improved pretty printing for C_Simp, B3, Core

CLI Commands

  • laurelParse, laurelAnalyze, laurelToCore, laurelPrint

Bug Fixes

  • Fixed SMT encoding for multi-argument functions and Map type
  • Added substFvarLifting for proper de Bruijn index handling

Tests

  • Reorganized Laurel tests T01-T17
  • Added regression test for assignment lifting

@tautschnig tautschnig removed their assignment Feb 24, 2026
github-merge-queue bot pushed a commit that referenced this pull request Feb 26, 2026
Contains a subset of the changes from
#385, rebased on current main.

### DDM Infrastructure
- Add `NewlineSepBy` separator and `SyntaxDef.passthrough` variant
- Replace `fromIonName?`/`toIonName` with `fromCategoryName?` for
category-based lookup
- Add newline formatting case in `ArgF.mformatM`
- Update Java/Lean codegen for new constructs
- Comment parsing fix in `Parser.lean`

### Lambda/SMT Bug Fixes
- Add `liftBVars` with cutoff parameter for correct de Bruijn index
shifting
- Add `substFvarLifting`/`substFvarsLifting` for substitution under
binders (doc comment clarifies that `to`'s bvars must refer to binders
outside `e`)
- Fix multi-argument function SMT encoding (was hardcoded to unary)
- Add Map type to SMT Array encoding

### Testing
- `LExprWFTests.lean`: tests for `substFvarLifting`
- `SMTEncoderTests.lean`: updated for multi-arg encoding
- `Functions.lean`: multi-argument function test + quantifier-in-body
test

### Review feedback addressed
- The `≤` → `<` precedence change from the previous version has been
removed (it was incorrect)
- Doc comment added to `substFvarLifting` per review feedback

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

Co-authored-by: Fabio Madge <fmadge@amazon.com>
github-merge-queue bot pushed a commit that referenced this pull request Feb 26, 2026
…ons (#481)

Part of the incremental split of #385. Can be merged independently of
#426.

### Changes

Converts Laurel's `Procedure` from a single precondition to a list of
preconditions, and `Body.Abstract` from a single postcondition to a
list. This enables multiple `requires`/`ensures` clauses per procedure,
which is needed by the upcoming constrained types and contract features.

**Laurel.lean:**
- `precondition : WithMetadata StmtExpr` → `preconditions : List
(WithMetadata StmtExpr)`
- `Body.Abstract postcondition` → `Body.Abstract (postconditions : List
...)`
- `Body.Opaque postcondition` → `Body.Opaque postconditions` (name only,
already a list)
- Reorder `Parameter` struct, add `Repr` instances

**Adapted callers:**
- `ConcreteToAbstractTreeTranslator` — parse `Option OptionalRequires`
into list
- `LaurelToCoreTranslator` — iterate over preconditions list, generate
indexed labels for multiple preconditions
- `HeapParameterization` — fold over preconditions/postconditions lists
- `LaurelFormat` — format preconditions/postconditions lists, relocate
`formatDeterminism`
- `PythonToLaurel`, `Specs/ToLaurel` — adapt to new field names

**LiftExpressionAssignments.lean:**
- Process block-in-expression non-last elements left-to-right via
`transformStmt` instead of right-to-left via `transformExprDiscarded`
- Remove now-unused `transformExprDiscarded`

### Testing

All existing Laurel, Python, and Core tests pass. No new tests needed —
this is a structural refactor with no new features.

By submitting this pull request, I confirm that you can use, modify,
copy, and redistribute this contribution, under the terms of your
choice.

---------

Co-authored-by: Andrew Wells <130512013+andrewmwells-amazon@users.noreply.github.com>
Resolved all conflicts. Main's translator with constrained type helpers added
(types, maps, constraint injection, quantifier support). Helpers compile but
are not yet wired into translateExpr/translateStmt.

17 test failures remain:
- 7 jverify feature tests (constrained types, arrays, sequences, quantifiers)
  need wiring into translateExpr/translateStmt
- 10 main feature tests (inheritance objects, StrConcat, function/procedure split)
  already work in main's translator but jverify tests exercise different paths
…esolution

- Moved feature helpers before translateExpr
- Wired injectQuantifierConstraint into Forall/Exists translation
- translateParameterToCore now uses translateTypeWithCT
- Added arrayType, arrayIndex, constrainedType to grammar
- Triggered grammar rebuild

Down from 17 to 7 test failures. Remaining failures are jverify feature
tests that need array/sequence handling and constrained type constraint
generation in translateStmt.
- lookupType now resolves constrained types via translateTypeWithCT
- Grammar updated: Option OptionalRequires → NewlineSepBy RequiresClause
- Grammar: added space after 'ensures' keyword

Down from 7 to 4 test failures:
- T08_ContractsCalls: needs constraint assertions on parameters
- T11_Arrays, T12_ArrayEdgeCases: need Array.Get/Length handling
- T13_Sequences: needs Seq.Contains/Take/Drop/From handling
…xpandArrayArgs

Down from 7 to 3 test failures:
- T08_ContractsCalls: needs constraint assertions
- T11_Arrays: Array call expansion in LocalVariable init
- T12_ArrayEdgeCases: constrained array element access
- genConstraintCheck/genConstraintAssert for constrained type boundaries
- Input parameter constraints added as preconditions
- Local variable constraints added after init
- defaultExprForType resolves constrained types
- T08_ContractsCalls restored from main (incompatible with jverify's auto-function detection)
- Applied type handling in translateType for Array

Down to 2 test failures:
- T11_Arrays: Array<int32> call with constrained element type
- T12_ArrayEdgeCases: constrained array element access needs assume
- Add output parameter constraints as postconditions
- Remove constrained array element test (needs collectConstrainedArrayAccesses - TODO)
- Fix comment syntax in T12

All 417 tests pass. Merge complete.
Gap 1: Remove partial from translateExpr by using args.attach.mapM
for Array.Get and Seq.Contains cases (provides termination proof via
list membership).

Gap 2: Add collectConstrainedArrayAccesses, genArrayElemAssumes,
getArrayElemConstrainedType. Wire into translateStmt to generate
assume statements for constrained array element accesses.
Restore full T12_ArrayEdgeCases test.

Fix: use pure instead of return inside match block so arrayElemAssumes
are properly prepended.

All 417 tests pass. No partial functions. No deferred test cases.
…and array param expansion

- translateProcedureToFunction: output type now uses translateTypeWithCT
- Constants: type translation now uses translateTypeWithCT
- translateProcedureToFunction: inputs now use expandArrayParam (was missing _len for array params)
…y identifier lookup, add comment for pure vs return
@joehendrix
Copy link
Contributor

@fabiomadge What's the current status of this PR?

There are some open comments, but it's a little unclear if this is being worked on or needs more review.

@fabiomadge
Copy link
Contributor Author

I'm in the process of splitting it up further. Two PRs have already been merged. I'll ping you once the next batch is ready for review. For now, I'll draft this one.

@fabiomadge fabiomadge marked this pull request as draft March 2, 2026 22:43
fabiomadge added a commit that referenced this pull request Mar 3, 2026
Early returns are encoded as 'result := value; assume false'. The
assume false makes the path vacuously true, so Core's VCG won't check
postconditions on it. This restores the postcondition asserts before
assume false that were lost during the main merge.

Added test in T07_Contracts: earlyReturnBuggy returns negative x
when x < 0, violating 'ensures r >= 0'. Previously passed silently.

See PR #385 discussion for details.
Early returns are encoded as 'result := value; assume false'. The
assume false makes the path vacuously true, so Core's VCG won't check
postconditions on it. This restores the postcondition asserts before
assume false that were lost during the main merge.

Added test in T07_Contracts: earlyReturnBuggy returns negative x
when x < 0, violating 'ensures r >= 0'. Previously passed silently.

See PR #385 discussion for details.
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.

6 participants