Skip to content

Enable local variables in functions#25

Closed
keyboardDrummer-bot wants to merge 1 commit into
mainfrom
enable-local-variables-in-functions
Closed

Enable local variables in functions#25
keyboardDrummer-bot wants to merge 1 commit into
mainfrom
enable-local-variables-in-functions

Conversation

@keyboardDrummer-bot
Copy link
Copy Markdown
Collaborator

Closes #24

Changes

LaurelToCoreTranslator.lean: In the translateExpr case for Block with LocalVariable (with initializer), replaced the disallowed error with the actual translation:

let coreMonoType ← translateType ty
return .app () (.abs () name.text (some coreMonoType) bodyExpr) valueExpr

This encodes var x: T := v; body as the beta-redex (λ x:T. body) v, which the Core evaluator already handles via beta reduction, and the Preconditions module already handles as a let-binding pattern.

T3_ControlFlowError.lean: Removed the three error: local variables in functions are not YET supported annotations and the associated comments, since local variables in functions are now supported.

Verification

  • LaurelToCoreTranslator builds successfully
  • All Laurel fundamental tests pass (T1 through T21)
  • All transform tests pass

Translate local variables in function bodies to Core using the
app(abs(name, type, body), value) pattern (beta-redex encoding of
let-bindings).

- Replace the 'disallowed' error in LaurelToCoreTranslator with the
  actual translation using translateType and app/abs.
- Remove the corresponding error annotations from T3_ControlFlowError.

Closes #24
@keyboardDrummer
Copy link
Copy Markdown
Owner

@keyboardDrummer-bot please open this PR in the upstream repository

@keyboardDrummer-bot
Copy link
Copy Markdown
Collaborator Author

Opened strata-org#1023 in the upstream repository with the same changes. It's in draft mode with you assigned.

keyboardDrummer pushed a commit that referenced this pull request May 21, 2026
## Summary

Extends the Boole language pipeline with new language features, curated
benchmark
targets anchored to dalek-lite (Curve25519/Ed25519), and a testing
infrastructure
upgrade across all Boole seeds.

## Language features

**`Sequence T` type and slicing ops**
- `toCoreMonoType` handles `.Sequence _ elem → .tcons "Sequence" [elem]`
- All 8 Core inherited ops wired up in `Verify.lean`
- Three Boole-specific wrappers: `Sequence.skip`, `Sequence.dropFirst`,
  `Sequence.subrange`
- Typed empty-sequence constants:
`Sequence.empty_bv8/bv16/bv32/bv64/int` — each
needs a distinct token since 0-ary polymorphic `Sequence.empty` has no
arguments
  to infer the type from

**Bitvector loop variables** (`for i : bvN := init to limit`)
- `for_to_by` and `for_downto_by` dispatch guard/step/increment to
  `Bv{N}.ULe/Add/Sub` when the loop variable is a bitvector type

**`decreases` annotations**
- `for v := init to/downto limit` accepts an optional `decreases e`
clause;
forwarded to the Core while-loop measure field and actively verified by
cvc5
- Functions and procedures accept an optional `decreases e` clause using
Core's
  existing `Measure` category — no new grammar category introduced
- All three forms reuse Core's single `measure_mk` op; no duplicate
constructs
- Function termination is verified by strata-org#1092; procedure-level `decreases`
is
silently dropped with a `dbg_trace` warning pending int-based
termination support

**Lambda abstraction and application**
- `fun x : T => body` lowers to nested Core `.abs` nodes
- `(f)(x)` lowers to `.app () f x`

**Inline `let`-block postconditions**
- `let v := e in body` in spec/ensures positions lowers via
`withBVarExprs`

**`choose` assignment**
- `w := choose z : T :: pred(z)` lowers to `havoc w; assume pred[z/w]`

**Bitvector comparisons**
- Unsigned (`<`, `<=`, `>`, `>=`) default to `Bv{N}.ULt/ULe/UGt/UGe` via
  `toBvCmpOp`
- Signed (`<s`, `<=s`, `>s`, `>=s`) lower to `Bv{N}.SLt/SLe/SGt/SGe`

## New seeds

- `embedded_postcondition.lean` — inline let-block in `ensures`
- `montgomery_loop_invariant.lean` — relational while-loop invariant;
linear
  arithmetic case verifies via cvc5 and `smtVCsCorrect`
- `scalar_reduce.lean` — B2 `reduce()` axiom with abstract types
- `sha256_compact_indexed.lean` — SHA-256 compact port (indexed
`Sequence`
encoding); all 19 VCs pass; loop counters use `int` (faithful to Rust's
`usize`
semantics, avoids uninterpreted cast to `Sequence` index); remaining
gaps:
iterator protocol (#27), fixed-size array syntax (#25), slice types
(#26)

Fully implemented seeds graduated from `FeatureRequests/` to the main
Boole test
folder: `early_return.lean`, `choose_operator.lean`,
`bitvector_ops.lean`,
`embedded_postcondition.lean`.

## Seed test infrastructure

Replaced `#guard_msgs (drop info) in` with explicit `/-- info: ... -/` +
`#guard_msgs in` across all Boole seeds. Added `(options := .quiet)`
uniformly.

## Documentation

- New `docs/BooleBenchmarks.md`: five real-world benchmark targets from
dalek-lite
- Updated `docs/BooleFeatureRequests.md`: all new seeds in inventory
table,
  implemented features extended

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: Michael Tautschnig <mt@debian.org>
Co-authored-by: Aaron Tomb <aarotomb@amazon.com>
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
Co-authored-by: Juneyoung Lee <136006969+aqjune-aws@users.noreply.github.com>
Co-authored-by: keyboardDrummer-bot <keyboardDrummer-bot@users.noreply.github.com>
Co-authored-by: Mikaël Mayer <MikaelMayer@users.noreply.github.com>
Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
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.

Enable local variables in functions

2 participants