Skip to content

Conversation

@MikaelMayer
Copy link
Contributor

@MikaelMayer MikaelMayer commented Feb 3, 2026

Add DDM support for parsing functions that are not top-level + Strata Core support to parse function statements

Extends Core DDM with:

  • Function statement categories for statement-based function bodies
  • Top-level block statement command support

All tests pass.

MikaelMayer and others added 21 commits January 27, 2026 11:14
…or Func

- Added ToFormat for generic Func with proper constraints
- Added [ToFormat T.IDMeta] to Factory.lean section variables
- Removed unnecessary ToFormat instances from test files and Program.lean
- Removed custom Env.format function (now uses default ToFormat)
- Function bodies now display properly instead of showing <body>
- Resolved conflict in Factory.lean (Factory_wf moved to FactoryWF.lean in main)
- Applied rotate_left fix to FactoryWF.lean
- Modified testFuncDeclSymbolic to show functions capture variables by reference
- Function declared with n=10, then n mutated to 20, function uses n=20 at call time
- Proof obligation correctly shows result should be 25 (5+20), not 15 (5+10)
- Reverted Env.lean to main (custom scope formatting not needed)
…claration time

- Functions now capture variable values at declaration time, not by reference
- Free variables in function body are substituted with their current values from environment
- Test demonstrates: n=10 at declaration, n=20 after mutation, function uses n=10
- Proof obligation correctly shows result is 15 (5+10), not 25 (5+20)
@MikaelMayer MikaelMayer requested a review from a team as a code owner February 3, 2026 17:43
@MikaelMayer MikaelMayer marked this pull request as draft February 3, 2026 17:47
@MikaelMayer MikaelMayer force-pushed the add-function-statements-ddm branch from bc38faa to 10713a3 Compare February 3, 2026 17:51
…duplication

- Move generic Func structure to Strata/DL/Util/Func.lean
- Add PureFunc to Imperative, removing Lambda->Imperative dependency
- Fix funcDecl type checking to add function to type context
- Remove duplicate renameLhs/substFvar from ProcedureInlining
- Extract captureFreevars helper in StatementEval
- Refine getVars to exclude formal parameters for funcDecl
- Add type checking test for funcDecl
- Add WFfuncDeclProp structure in WF.lean checking input parameter uniqueness
- Add LFunc.type_inputs_nodup theorem in Factory.lean
- Add Function.typeCheck_inputs_nodup theorem in FunctionType.lean
- Add listMap_keys_map_snd helper lemma in StatementWF.lean
- Replace sorry in funcDecl case with complete proof
- Add funcDecl_statement operator to DDM Parse.lean
- Support function declarations within statement blocks
- Include proper scoping and inline attribute support
- Add compilation test to verify DDM syntax correctness
- Extends DDM to support the new .funcDecl statement type
The DDM doesn't actually support function declaration statements syntax yet.
The funcDecl_statement operator was added but the full parsing integration is not complete.
- Add case for .bvar with arguments to handle locally declared function calls
- Translates arguments and creates function application using .mkApp
- Remove @[scope(b)] annotation from funcDecl_statement body parameter to prevent function parameter leakage into global scope
- Add function to local freeVars for subsequent statement access
- Add test demonstrating function declaration statements work correctly
- Resolves translateExpr out-of-range bound variable errors
- Restore scope annotations in DDM parser for proper parameter access
- Fix translation layer to handle function calls correctly
- Isolate issue to function call translation, not declaration
@MikaelMayer MikaelMayer force-pushed the add-function-statements-ddm branch from 16716b7 to d415650 Compare February 5, 2026 18:56
- Fix function body translation to use only function parameters as bound variables
- Fix function call translation to convert out-of-range bound variables to function calls
- Handle case where parser treats function names as bound variables but translation needs them as free variables
- Resolves translateExpr out-of-range bound variable errors for function declarations in statements
Base automatically changed from add-func-decl-to-statements to main February 6, 2026 20:54
The funcDecl_statement translation was not correctly setting up bound
variables for the function body. Fixed by:
- Using LExpr.fvar with type information (like translateFunction does)
- Including the function name in boundVars for recursive calls
- Appending to existing boundVars to allow access to outer scope variables

This allows function bodies to reference their own parameters, the
function itself for recursion, and outer scope variables like procedure
parameters.

Note: SMT verification of locally declared functions is not yet supported
(function axioms are not generated). This is documented in the test file.
@MikaelMayer MikaelMayer changed the title Add DDM support for function statements and top-level statement commands Add DDM support for parsing functions that are not top-level + Strata Core support to parse function statements Feb 9, 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.

2 participants