generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 24
Add DDM support for parsing functions that are not top-level + Strata Core support to parse function statements #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
99ba9b8
Add support for function declarations within statement blocks
MikaelMayer 6b1cdc2
Fix Factory_wf proof using rotate_left to reorder goals
MikaelMayer a8a4a0c
Remove unnecessary Lambda namespace opening in Statement.lean
MikaelMayer b8ec252
Remove unnecessary Lambda namespace opening in Program.lean
MikaelMayer d666882
Restore proper function body formatting by adding ToFormat instance f…
MikaelMayer ed1f8ac
Remove B3 .gitignore (moved to .git/info/exclude for local use)
MikaelMayer c6ede80
Clean up: revert ProcedureWF.lean to main, remove unnecessary comment
MikaelMayer 77eb4fa
Merge main into add-func-decl-to-statements
MikaelMayer 62a5f70
Fix merge: add missing funcDecl cases in ProcedureInlining and apply …
MikaelMayer 5f65da9
Update funcDecl test to demonstrate variable capture semantics
MikaelMayer a13b470
Merge branch 'main' into add-func-decl-to-statements
MikaelMayer 6797599
Fix merge: convert Format to String for EvalError.Misc
MikaelMayer 5ceddf3
Implement value capture for funcDecl: substitute free variables at de…
MikaelMayer 86f6c90
Fix merge: convert Format errors to DiagnosticModel in funcDecl type …
MikaelMayer 776a87d
Merge branch 'main' into add-func-decl-to-statements
shigoel dbfe96e
Add polymorphic function test for funcDecl with evaluation verification
MikaelMayer ebbab10
Update semantics and proofs for FuncContext parameter in EvalStmt/Eva…
MikaelMayer 494dedc
Merge branch 'main' into add-func-decl-to-statements
MikaelMayer c588f0c
Fix eval_stmts_set_comm proof after FuncContext refactor
MikaelMayer 93914c6
Thread δ through semantics instead of FuncContext
MikaelMayer 95a3386
Merge branch 'main' into add-func-decl-to-statements
MikaelMayer dfd9dcc
Address PR review comments: refactor Func, fix type checking, remove …
MikaelMayer a86b658
Fix getVarsTrans to exclude formal parameters for funcDecl
MikaelMayer 92ab1f8
Fix funcDecl_sem case in EvalStmtRefinesContract theorem
MikaelMayer dc17906
Update comment: funcDecl WF checks are TODO, not always true
MikaelMayer 117aeab
Add well-formedness checks for funcDecl in StatementWF
MikaelMayer e673135
Add extendEval parameter to DetToNondetCorrect theorems
MikaelMayer e1ce657
Merge main into add-func-decl-to-statements
MikaelMayer 049bff4
Fix FactoryWF.lean to use LFuncWF instead of FuncWF after merge
MikaelMayer 3183890
Merge branch 'main' into add-func-decl-to-statements
MikaelMayer 80c1833
Fix unused section variable warning in LFunc.type_inputs_nodup
MikaelMayer a8e9809
Add DDM support for function declaration statements
MikaelMayer b05a3b4
Remove incorrect test file
MikaelMayer e188726
Fix DDM translateExpr to support bound function calls with arguments
MikaelMayer c0e5d13
Fix function declaration statement bound variable scoping
MikaelMayer d415650
Fix bound variable issue in function declaration translation
MikaelMayer f630000
Fix function declaration DDM transform bound variable issues
MikaelMayer b52d16f
Fix function declaration statement parsing in DDM transform
MikaelMayer 34ccb82
Merge main into add-function-statements-ddm
MikaelMayer a7c50c1
Merge branch 'main' into add-function-statements-ddm
MikaelMayer 8455248
Remove trivial EvalCmd_eval_cst theorem
MikaelMayer 6cacee5
Add support for parsing top-level blocks directly
MikaelMayer 117b3fd
Refactor: merge duplicate bvar handling cases
MikaelMayer f7088a8
Fix: use func.opExpr for correct function type in fvar translation
MikaelMayer 47281aa
Merge branch 'main' into add-function-statements-ddm
MikaelMayer 5c81605
Merge branch 'main' into add-function-statements-ddm
MikaelMayer 54b591f
Add DDM test for scoped function declarations
MikaelMayer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| /- | ||
| Copyright Strata Contributors | ||
|
|
||
| SPDX-License-Identifier: Apache-2.0 OR MIT | ||
| -/ | ||
|
|
||
| import Strata.DDM.Integration.Lean | ||
|
|
||
| /-! | ||
| # Tests for Scoped Function Declarations in DDM | ||
|
|
||
| Tests that function declarations within blocks are properly scoped | ||
| using the `@[declareFn]` annotation combined with `@[scope]`. | ||
|
|
||
| This tests the DDM scoping mechanism independently of the Strata Core language. | ||
| -/ | ||
|
|
||
| #dialect | ||
| dialect TestScopedFn; | ||
|
|
||
| type bool; | ||
| type int; | ||
|
|
||
| fn trueExpr : bool => "true"; | ||
| fn falseExpr : bool => "false"; | ||
| fn intLit (n : Num) : int => n; | ||
| fn add (a : int, b : int) : int => @[prec(25), leftassoc] a "+" b; | ||
|
|
||
| category Binding; | ||
| @[declare(name, tp)] | ||
| op mkBinding (name : Ident, tp : TypeP) : Binding => @[prec(40)] name ":" tp; | ||
|
|
||
| category Bindings; | ||
| @[scope(bindings)] | ||
| op mkBindings (bindings : CommaSepBy Binding) : Bindings => "(" bindings ")"; | ||
|
|
||
| category VarDecl; | ||
| @[declare(name, tp)] | ||
| op varDecl (name : Ident, tp : Type) : VarDecl => name ":" tp; | ||
|
|
||
| category Statement; | ||
| category Block; | ||
|
|
||
| op var_statement (v : VarDecl) : Statement => "var " v ";\n"; | ||
|
|
||
| @[declare(name, tp)] | ||
| op init_statement (name : Ident, tp : Type, e : tp) : Statement => | ||
| "var " name " : " tp " := " e ";\n"; | ||
|
|
||
| op assign_statement (tp : Type, v : Ident, e : tp) : Statement => | ||
| v " := " e ";\n"; | ||
|
|
||
| op assert_statement (e : bool) : Statement => "assert " e ";\n"; | ||
|
|
||
| @[declareFn(name, b, r)] | ||
| op funcDecl_statement (name : Ident, | ||
| b : Bindings, | ||
| r : Type, | ||
| @[scope(b)] body : r) : Statement => | ||
| "function " name b " : " r " { " body " }"; | ||
|
|
||
| @[scope(stmts)] | ||
| op block (stmts : Seq Statement) : Block => "{\n" indent(2, stmts) "}\n"; | ||
|
|
||
| op command_block (b : Block) : Command => b; | ||
|
|
||
| #end | ||
|
|
||
| --------------------------------------------------------------------- | ||
| -- Test 1: Function declaration in block, called in subsequent statement | ||
| --------------------------------------------------------------------- | ||
|
|
||
| def funcInBlockPgm := | ||
| #strata | ||
| program TestScopedFn; | ||
| { | ||
| function double(x : int) : int { x + x } | ||
| var result : int := double(5); | ||
| assert true; | ||
| } | ||
| #end | ||
|
|
||
| /-- | ||
| info: program TestScopedFn; | ||
| { | ||
| function double(x:int) : int { x+x }var result : int := double(5); | ||
| assert true; | ||
| } | ||
| -/ | ||
| #guard_msgs in | ||
| #eval IO.println funcInBlockPgm | ||
|
|
||
| --------------------------------------------------------------------- | ||
| -- Test 2: Multiple function declarations in sequence | ||
| --------------------------------------------------------------------- | ||
|
|
||
| def multipleFuncsPgm := | ||
| #strata | ||
| program TestScopedFn; | ||
| { | ||
| function inc(x : int) : int { x + 1 } | ||
| function dec(x : int) : int { x + 0 } | ||
| var a : int := inc(5); | ||
| var b : int := dec(a); | ||
| assert true; | ||
| } | ||
| #end | ||
|
|
||
| /-- | ||
| info: program TestScopedFn; | ||
| { | ||
| function inc(x:int) : int { x+1 }function dec(x:int) : int { x+0 }var a : int := inc(5); | ||
| var b : int := dec(a); | ||
| assert true; | ||
| } | ||
| -/ | ||
| #guard_msgs in | ||
| #eval IO.println multipleFuncsPgm | ||
|
|
||
| --------------------------------------------------------------------- | ||
| -- Test 3: Function with multiple parameters | ||
| --------------------------------------------------------------------- | ||
|
|
||
| def multiParamFuncPgm := | ||
| #strata | ||
| program TestScopedFn; | ||
| { | ||
| function sum(a : int, b : int) : int { a + b } | ||
| var result : int := sum(3, 4); | ||
| assert true; | ||
| } | ||
| #end | ||
|
|
||
| /-- | ||
| info: program TestScopedFn; | ||
| { | ||
| function sum(a:int, b:int) : int { a+b }var result : int := sum(3, 4); | ||
| assert true; | ||
| } | ||
| -/ | ||
| #guard_msgs in | ||
| #eval IO.println multiParamFuncPgm | ||
|
|
||
| --------------------------------------------------------------------- | ||
| -- Test 4: Nested function calls | ||
| --------------------------------------------------------------------- | ||
|
|
||
| def nestedCallsPgm := | ||
| #strata | ||
| program TestScopedFn; | ||
| { | ||
| function double(x : int) : int { x + x } | ||
| function quadruple(x : int) : int { double(double(x)) } | ||
| var result : int := quadruple(2); | ||
| assert true; | ||
| } | ||
| #end | ||
|
|
||
| /-- | ||
| info: program TestScopedFn; | ||
| { | ||
| function double(x:int) : int { x+x }function quadruple(x:int) : int { double(double(x)) }var result : int := quadruple(2); | ||
| assert true; | ||
| } | ||
| -/ | ||
| #guard_msgs in | ||
| #eval IO.println nestedCallsPgm | ||
|
|
||
| --------------------------------------------------------------------- |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.