Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
229 commits
Select commit Hold shift + click to select a range
7e34b04
Improve Laurel printer
keyboardDrummer May 26, 2026
f246686
Introduce transparency pass
keyboardDrummer May 26, 2026
b11e042
Fixes
keyboardDrummer May 26, 2026
9e4ee85
Refactoring
keyboardDrummer May 26, 2026
7408103
Remove pack multiple outputs pass
keyboardDrummer May 26, 2026
4e8fa8b
Add error file
keyboardDrummer May 26, 2026
2d19629
Update tests
keyboardDrummer May 26, 2026
c9fd151
Add sources to lift phase
keyboardDrummer May 26, 2026
19987e8
Update tests and improve errors
keyboardDrummer May 26, 2026
24c3983
Update comment
keyboardDrummer May 26, 2026
3c23531
Trigger CI
keyboardDrummer May 26, 2026
6046381
Trigger CI
keyboardDrummer May 26, 2026
86962e4
Trigger CI
keyboardDrummer May 26, 2026
d192346
Replace panic with safe access
keyboardDrummer May 27, 2026
7a04e66
Move proof skipping logic from LaurelToCore translator to transparenc…
keyboardDrummer May 28, 2026
a45f8f0
Small refactoring
keyboardDrummer May 28, 2026
96b2686
Merge branch 'formatting-and-debugging-improvements' into transparenc…
keyboardDrummer May 28, 2026
d0fdd35
Cleanup
keyboardDrummer May 28, 2026
2e0d7e1
Merge branch 'transparency-pass-only' of github.com:keyboardDrummer/S…
keyboardDrummer May 28, 2026
c62cfb4
Add contract pass
keyboardDrummer May 28, 2026
a95da10
Cleanup
keyboardDrummer May 28, 2026
49255b4
Fixes
keyboardDrummer May 28, 2026
10640f7
Fixes
keyboardDrummer May 28, 2026
8c15c16
Do not run the contract pass for functions yet
keyboardDrummer May 28, 2026
573a36b
Reduce id changes
keyboardDrummer May 28, 2026
74ec111
Fixes
keyboardDrummer May 28, 2026
800f6c4
Test fixes
keyboardDrummer May 28, 2026
e56cb20
Fix test
keyboardDrummer May 28, 2026
a352b47
Fix test
keyboardDrummer May 28, 2026
65c92f4
Fix test
keyboardDrummer May 28, 2026
4a8c667
Remove unused files
keyboardDrummer May 28, 2026
d7d7205
Undo Python test changes
keyboardDrummer May 28, 2026
60c9ca3
Fixes
keyboardDrummer May 28, 2026
a526dad
Add missing bindings for PrimitiveOp
keyboardDrummer May 28, 2026
ace39ca
Improve comment
keyboardDrummer May 28, 2026
2e94fc5
Add missing bindings for PrimitiveOp
keyboardDrummer May 28, 2026
200e828
Improve comment
keyboardDrummer May 28, 2026
8875ffd
Merge branch 'transparency-pass-only' into issue-924-contract-and-pro…
keyboardDrummer May 28, 2026
9400328
Generate separate $pre and $post procedures for each condition
keyboardDrummer-bot May 28, 2026
65ab6ae
Rename SepFormat.semicolon to SepFormat.semicolonNewline
keyboardDrummer-bot May 28, 2026
6c0c39c
Fix contract pass: preserve postconditions in Opaque/Abstract bodies
keyboardDrummer-bot May 28, 2026
d6bff50
Fix contract pass: make postcondition helpers functional
keyboardDrummer-bot May 28, 2026
2cae5e0
Update golden-file expected outputs for changed label counters
keyboardDrummer-bot May 28, 2026
5c0a458
Extract emitCoreDiagnostic helper to reduce repetition
keyboardDrummer-bot May 28, 2026
ff09522
Code review
keyboardDrummer Jun 1, 2026
afaf9a2
Stop dropping source location from callee
keyboardDrummer Jun 1, 2026
9f65463
Code review
keyboardDrummer Jun 1, 2026
d143eeb
Merge remote-tracking branch 'origin/formatting-and-debugging-improve…
keyboardDrummer Jun 1, 2026
35d7d75
Merge commit 'a995388cb~1' into transparency-pass-only
keyboardDrummer Jun 1, 2026
fc62415
Merge commit 'a995388cb' into transparency-pass-only
keyboardDrummer Jun 1, 2026
e1caee4
Trigger CI
keyboardDrummer Jun 1, 2026
3e76abc
Fix nit
keyboardDrummer Jun 1, 2026
6f0d365
Use HashSet for asFunctionNames and add isDestructorName/isTesterName…
keyboardDrummer-bot Jun 1, 2026
80f22a6
Merge branch 'transparency-pass-only' of github.com:keyboardDrummer/S…
keyboardDrummer Jun 1, 2026
1e9710b
Fix warning
keyboardDrummer Jun 1, 2026
944ffbd
Merge branch 'transparency-pass-only' into issue-924-contract-and-pro…
keyboardDrummer Jun 1, 2026
20225bd
Trigger CI
keyboardDrummer Jun 2, 2026
b52f50b
Trigger CI
keyboardDrummer Jun 2, 2026
b6f0f64
Don't generate intermediate files
keyboardDrummer Jun 2, 2026
6ee3c7e
Exclude hidden files from the lake cache hash
keyboardDrummer Jun 2, 2026
4b44fbf
Exclude hidden files from the lake cache hash
keyboardDrummer Jun 2, 2026
1c5a9e1
Add polymorphism comment and recursive transparent procedure test
keyboardDrummer-bot Jun 2, 2026
81b558c
Fixes
keyboardDrummer Jun 2, 2026
ac0fdb1
Update recursive test to use procedures
keyboardDrummer Jun 3, 2026
cf29a09
Delete recursive transparent
keyboardDrummer Jun 3, 2026
780cbee
Merge branch 'main2' into transparency-pass-only
keyboardDrummer Jun 3, 2026
3dc9527
Add a test-case
keyboardDrummer Jun 3, 2026
74d532a
Merge upstream/main2 into transparency-pass-only
keyboardDrummer-bot Jun 4, 2026
e9887a6
Merge branch 'transparency-pass-only' into issue-924-contract-and-pro…
keyboardDrummer Jun 4, 2026
70cb26e
Fixes
keyboardDrummer Jun 4, 2026
17c1d84
Fix test after merge
keyboardDrummer Jun 4, 2026
68cec09
Fix test expectation
keyboardDrummer Jun 4, 2026
dbfcb95
Remove unused module
keyboardDrummer Jun 4, 2026
2f8eb11
Fix bug in Resolution.lean
keyboardDrummer Jun 4, 2026
85ddf71
Remove isFunctional property from Laurel.Procedure
keyboardDrummer Jun 9, 2026
c3b10e9
Remove 'function' from Laurel tests
keyboardDrummer Jun 9, 2026
179951f
update library files
keyboardDrummer Jun 9, 2026
6e945c7
add missing implementation for resolveUnorderedCore
keyboardDrummer Jun 9, 2026
23e07cc
Fixes. AssertFalse passes
keyboardDrummer Jun 9, 2026
4158558
Test fixes
keyboardDrummer Jun 9, 2026
f6e53f0
Update tests
keyboardDrummer Jun 10, 2026
389e214
Merge branch 'transparency-pass-only' into issue-924-contract-and-pro…
keyboardDrummer Jun 10, 2026
d141467
Merge commit 'a364a70a~1' into issue-924-contract-and-proof-pass
keyboardDrummer Jun 10, 2026
87d7214
Merge commit 'a364a70a' into issue-924-contract-and-proof-pass
keyboardDrummer Jun 10, 2026
61c2e83
Address quality follow-ups from review
keyboardDrummer-bot Jun 11, 2026
9ca5c77
Add test and fix for counter created by contract pass
keyboardDrummer Jun 11, 2026
b4938f0
Update Strata/Languages/Laurel/ContractPass.lean
keyboardDrummer Jun 11, 2026
3c0e745
Merge branch 'issue-924-contract-and-proof-pass' of github.com:keyboa…
keyboardDrummer Jun 11, 2026
9c9ace9
Update Strata/Languages/Laurel/EliminateValuesInReturns.lean
keyboardDrummer Jun 11, 2026
d8d9b96
Merge branch 'issue-924-contract-and-proof-pass' of github.com:keyboa…
keyboardDrummer Jun 11, 2026
bef6885
Cleanup
keyboardDrummer Jun 11, 2026
96982e3
Merge remote-tracking branch 'fork/quality-followups-from-fabiomadge'…
keyboardDrummer Jun 11, 2026
551e699
partial
keyboardDrummer Jun 11, 2026
67f43bf
Simplify termination proof
keyboardDrummer Jun 11, 2026
ba8524a
Merge branch 'main2' into issue-924-contract-and-proof-pass
keyboardDrummer Jun 11, 2026
e1d21e7
Merge branch 'issue-924-contract-and-proof-pass' into removeFunctions
keyboardDrummer Jun 11, 2026
fc214a3
Test fixes
keyboardDrummer Jun 11, 2026
ac0b6be
Fix test
keyboardDrummer Jun 11, 2026
bfbf99a
Fix ControlFlowError test
keyboardDrummer Jun 11, 2026
31e9007
Merge branch 'noHiddenFilesInHash' into issue-924-contract-and-proof-…
keyboardDrummer Jun 11, 2026
cbb1b07
Improve error message
keyboardDrummer Jun 11, 2026
d2b7b23
Update if-then-else formatting
keyboardDrummer Jun 11, 2026
a8bfb80
Fix bug related to assert/assume lifting when they are in conditions
keyboardDrummer Jun 11, 2026
7ae018f
Add missing test to T2
keyboardDrummer Jun 11, 2026
7cb5fee
Refactoring lifting pass
keyboardDrummer Jun 12, 2026
7eef859
Code review changes
keyboardDrummer Jun 12, 2026
4b8ef55
Merge remote-tracking branch 'origin/main2' into issue-924-contract-a…
keyboardDrummer Jun 12, 2026
237eabe
Pass tweaks
keyboardDrummer Jun 12, 2026
4ffc62f
Fixes
keyboardDrummer Jun 12, 2026
5178451
More pass refactoring changes
keyboardDrummer Jun 12, 2026
0ba057d
Fixes
keyboardDrummer Jun 12, 2026
1627ce4
Fixes
keyboardDrummer Jun 12, 2026
816a738
Include final pass in the all pass list
keyboardDrummer Jun 13, 2026
8470d93
Fixes
keyboardDrummer Jun 13, 2026
aebe44c
Merge remote-tracking branch 'origin/reviewed-kbd-will-merge-to-main'…
keyboardDrummer Jun 13, 2026
b7508d7
Fix test
keyboardDrummer Jun 13, 2026
f1507d1
Update Laurel docs
keyboardDrummer Jun 13, 2026
1077979
Change text
keyboardDrummer Jun 13, 2026
b30f4cb
Fix invokeOn axiom: guard with preconditions + reject output-referenc…
keyboardDrummer-bot Jun 13, 2026
6dd545a
Fix if-then-else prepend duplication in LiftImperativeExpressions
keyboardDrummer-bot Jun 13, 2026
d1f9d6c
Merge remote-tracking branch 'origin/reviewed-kbd-will-merge-to-main'…
keyboardDrummer Jun 16, 2026
0322796
Fix test
keyboardDrummer Jun 16, 2026
10b20e5
Merge branch 'issue-924-contract-and-proof-pass' into removeFunctions
keyboardDrummer Jun 16, 2026
efafe43
Fixes
keyboardDrummer Jun 16, 2026
878f325
Code review
keyboardDrummer Jun 16, 2026
e0c8b68
Fix early return
keyboardDrummer Jun 16, 2026
a63384a
Fix lifting bug
keyboardDrummer Jun 16, 2026
02ad82c
Merge remote-tracking branch 'origin/reviewed-kbd-will-merge-to-main'…
keyboardDrummer Jun 16, 2026
edbfda1
Merge branch 'issue-924-contract-and-proof-pass' into removeFunctions
keyboardDrummer Jun 16, 2026
16f57e6
Add comment
keyboardDrummer Jun 16, 2026
799f167
Merge remote-tracking branch 'origin/reviewed-kbd-will-merge-to-main'…
keyboardDrummer Jun 16, 2026
ced5837
Fixes
keyboardDrummer Jun 17, 2026
952a8e6
Fixes
keyboardDrummer Jun 17, 2026
ceeb050
Fix to contract pass and test expectations
keyboardDrummer Jun 17, 2026
f7eef03
Fix in lifting pass
keyboardDrummer Jun 17, 2026
6767211
Fix tests
keyboardDrummer Jun 17, 2026
2df41be
Add extra test to T2_ImpureExpressions
keyboardDrummer Jun 17, 2026
3459035
update test
keyboardDrummer Jun 17, 2026
5c87a7f
Drop info output in tests
keyboardDrummer Jun 17, 2026
6c78979
Fixes
keyboardDrummer Jun 17, 2026
e98598f
Add test-case to T2
keyboardDrummer Jun 17, 2026
1c78fe1
Fix to lift pass
keyboardDrummer Jun 17, 2026
bcdef57
Add local variable inlining pass
keyboardDrummer Jun 17, 2026
6f7b93d
Remove tmp file
keyboardDrummer Jun 17, 2026
23eca53
Merge branch 'issue-924-contract-and-proof-pass' into removeFunctions
keyboardDrummer Jun 17, 2026
f82910a
Remove more info output
keyboardDrummer Jun 17, 2026
7ab0725
Update Python files
keyboardDrummer Jun 17, 2026
5c4a0b6
update for Python
keyboardDrummer Jun 17, 2026
83e793b
Port fixes to lifting pass
keyboardDrummer Jun 18, 2026
6e0ce93
Merge branch 'reviewed-kbd-will-merge-to-main' into issue-924-contrac…
keyboardDrummer Jun 18, 2026
e1fc044
Merge remote-tracking branch 'origin/reviewed-kbd-will-merge-to-main'…
keyboardDrummer Jun 18, 2026
dcfb0e9
Some fixes for resolution during phases
keyboardDrummer Jun 18, 2026
a0ec015
Fixes to resolution so it throws fewer errors during passes
keyboardDrummer Jun 18, 2026
25f1d5d
Emit resolution errors during passes
keyboardDrummer Jun 18, 2026
fa7f844
Source fix
keyboardDrummer Jun 18, 2026
441ec1e
Improve well-formedness of the 3 heap passes
keyboardDrummer Jun 18, 2026
cf706b2
Fix for type hierarchy
keyboardDrummer Jun 18, 2026
66589c5
Refactoring
keyboardDrummer Jun 18, 2026
903f89e
Allow dangling addition in blocks
keyboardDrummer Jun 18, 2026
1a0e8ae
Fix diagnostic and test
keyboardDrummer Jun 18, 2026
018939b
Remove function return type expectation check
keyboardDrummer Jun 18, 2026
8d34b32
Update resolver check to use procedure instead of function
keyboardDrummer Jun 18, 2026
d9b39ac
Small improvements
keyboardDrummer Jun 18, 2026
a24cc86
Merge branch 'issue-924-contract-and-proof-pass' of github.com:keyboa…
keyboardDrummer Jun 18, 2026
c438d8c
Merge branch 'fixResolutionErrorsDuringPhases' into issue-924-contrac…
keyboardDrummer Jun 18, 2026
fcb3903
Fix merge
keyboardDrummer Jun 18, 2026
4efaebd
Remove obsolete test
keyboardDrummer Jun 18, 2026
8ce6fc6
Add multi output test-case to ImpureExpressions
keyboardDrummer Jun 19, 2026
157ec6b
Merge remote-tracking branch 'origin/reviewed-kbd-will-merge-to-main'…
keyboardDrummer Jun 19, 2026
d7a4c3c
Refactor liftImperative
keyboardDrummer Jun 19, 2026
0b03bff
Simplify lift pass
keyboardDrummer Jun 19, 2026
97e3146
Bring back test
keyboardDrummer Jun 19, 2026
ffcc39d
Recursion proof refactoring
keyboardDrummer Jun 19, 2026
1ef148f
Fix proofs
keyboardDrummer Jun 19, 2026
a279ff7
Merge remote-tracking branch 'origin/reviewed-kbd-will-merge-to-main'…
keyboardDrummer Jun 22, 2026
34c850f
Cleanup
keyboardDrummer Jun 22, 2026
12b5e59
Fix
keyboardDrummer Jun 22, 2026
bfc0b6c
Fix test
keyboardDrummer Jun 22, 2026
2e2a7b3
Fix tests
keyboardDrummer Jun 22, 2026
5f46178
Update expect file
keyboardDrummer Jun 22, 2026
98b76bc
Merge branch 'issue-924-contract-and-proof-pass' into removeFunctions
keyboardDrummer Jun 23, 2026
f1cb6c4
returnLabel match_pattern
keyboardDrummer Jun 23, 2026
4e9173a
Fix warning
keyboardDrummer Jun 23, 2026
ed51271
Fixes
keyboardDrummer Jun 23, 2026
bfd1750
Fixes
keyboardDrummer Jun 23, 2026
823add6
Test fixes
keyboardDrummer Jun 23, 2026
d4aba94
Fix to lift pass
keyboardDrummer Jun 23, 2026
16be9b5
Merge remote-tracking branch 'origin/reviewed-kbd-will-merge-to-main'…
keyboardDrummer Jun 23, 2026
97870a3
Undo added test and fix related to that
keyboardDrummer Jun 23, 2026
7abd32d
Merge branch 'issue-924-contract-and-proof-pass' into removeFunctions
keyboardDrummer Jun 24, 2026
04da456
Fixes
keyboardDrummer Jun 24, 2026
01f0f75
Fixes
keyboardDrummer Jun 24, 2026
5270ab1
Mute overly verbose test
keyboardDrummer Jun 24, 2026
090aa9c
Merge commit '49c3e1aac6' into removeFunctions
keyboardDrummer Jun 24, 2026
7c653f7
While related fixes
keyboardDrummer Jun 24, 2026
89051e1
Add test and fix for lift imperative pass
keyboardDrummer Jun 24, 2026
8d765fa
Improve Python debugging
keyboardDrummer Jun 24, 2026
c76ffd9
Fix IncrDecr lift test
keyboardDrummer Jun 24, 2026
2b66b97
Fix py_interpret failures after removing isFunctional
keyboardDrummer-bot Jun 24, 2026
a3345b6
Attempted fix
keyboardDrummer Jun 26, 2026
b75d3ad
Update some expect files
keyboardDrummer Jun 26, 2026
805d546
Merge remote-tracking branch 'origin/reviewed-kbd-will-merge-to-main'…
keyboardDrummer Jun 26, 2026
4ef42d2
Add missing save
keyboardDrummer Jun 26, 2026
1e6dae6
Fix merge
keyboardDrummer Jun 26, 2026
39a29e4
Fix contract pass asserting free postconditions in body
keyboardDrummer-bot Jun 26, 2026
1f2543b
Turn the alwaysCallFunctions flag on again for Python
keyboardDrummer Jun 27, 2026
8c5e13d
mapConst changes
keyboardDrummer Jun 29, 2026
620593f
Fixes
keyboardDrummer Jun 29, 2026
0221896
Fix T2c/T2d test failures: disable alwaysCallCoreFunctions for array-…
keyboardDrummer-bot Jun 29, 2026
816382a
Revert "Fix T2c/T2d test failures: disable alwaysCallCoreFunctions fo…
keyboardDrummer Jun 29, 2026
2bcd810
Fix T2c/T2d test failures: exclude heap-output procs from function re…
keyboardDrummer-bot Jun 29, 2026
f897209
Revert "Fix T2c/T2d test failures: exclude heap-output procs from fun…
keyboardDrummer Jun 29, 2026
b3cac0b
Call procedure when interpreting
keyboardDrummer Jun 29, 2026
9349000
Fix return in PythonToLaurel, and related things
keyboardDrummer Jun 29, 2026
dc8d8f4
Get rid of bodyLabel
keyboardDrummer Jun 29, 2026
fce801d
Test updates
keyboardDrummer Jun 29, 2026
9320e88
More test changes
keyboardDrummer Jun 29, 2026
7205c4c
Remove bad bodylabel reference
keyboardDrummer Jun 29, 2026
07a4dab
Fix modifiesClauses
keyboardDrummer Jun 29, 2026
d149221
Update tests
keyboardDrummer Jun 29, 2026
3c5b8c5
Update test
keyboardDrummer Jun 29, 2026
d3e7594
Fix
keyboardDrummer Jun 29, 2026
582937b
Revert "Fix"
keyboardDrummer Jun 29, 2026
d6be6e8
Fix related to holes and Core's behavior around empty procedures
keyboardDrummer Jun 29, 2026
1f5b8f2
Fix warning
keyboardDrummer Jun 29, 2026
b1fb519
Update expect files
keyboardDrummer Jun 29, 2026
b46ab22
Fix run_py_interpret.sh: use wildcard assertion IDs in expected files
keyboardDrummer-bot Jun 29, 2026
6fb74b3
Support 4-6 argument function applications in GOTO backend
keyboardDrummer-bot Jun 29, 2026
f529339
Fix CBMC tests: always emit guard field in GOTO instruction JSON
keyboardDrummer-bot Jun 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions Strata/Backends/CBMC/GOTO/InstToJson.lean
Original file line number Diff line number Diff line change
Expand Up @@ -236,9 +236,8 @@ def instructionToJson (inst : Instruction) : Except String Json := do
("instructionId", Json.str (toString inst.type)),
("locationNumber", Json.num inst.locationNum)
]
let guardField ← if inst.type == .GOTO || !Expr.beq inst.guard Expr.true then do
let guardField ← do
pure [("guard", ← exprToJsonWithNamedFields inst.guard)]
else pure []
let codeField ← if inst.code == Code.skip then pure [] else do
pure [("code", ← codeToJson inst.code)]
let targetsField := match inst.type, inst.target with
Expand Down
65 changes: 65 additions & 0 deletions Strata/Backends/CBMC/GOTO/LambdaToCProverGOTO.lean
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,36 @@ def LExprT.toGotoExpr {TBase: LExprParamsT} [ToString TBase.base.IDMeta] (e : LE
let e1g ← toGotoExpr e1
let e2g ← toGotoExpr e2
return { id := .binary .Equal, type := .Boolean, operands := [e1g, e2g] }
-- Quaternary Functions (4 arguments)
| .app m (.app _ (.app _ (.app _ (.op _ fn _) e1) e2) e3) e4 =>
let op ← fnToGotoID (toString fn)
let gty ← m.type.toGotoType
let e1g ← toGotoExpr e1
let e2g ← toGotoExpr e2
let e3g ← toGotoExpr e3
let e4g ← toGotoExpr e4
return { id := op, type := gty, operands := [e1g, e2g, e3g, e4g] }
-- Quinary Functions (5 arguments)
| .app m (.app _ (.app _ (.app _ (.app _ (.op _ fn _) e1) e2) e3) e4) e5 =>
let op ← fnToGotoID (toString fn)
let gty ← m.type.toGotoType
let e1g ← toGotoExpr e1
let e2g ← toGotoExpr e2
let e3g ← toGotoExpr e3
let e4g ← toGotoExpr e4
let e5g ← toGotoExpr e5
return { id := op, type := gty, operands := [e1g, e2g, e3g, e4g, e5g] }
-- Senary Functions (6 arguments)
| .app m (.app _ (.app _ (.app _ (.app _ (.app _ (.op _ fn _) e1) e2) e3) e4) e5) e6 =>
let op ← fnToGotoID (toString fn)
let gty ← m.type.toGotoType
let e1g ← toGotoExpr e1
let e2g ← toGotoExpr e2
let e3g ← toGotoExpr e3
let e4g ← toGotoExpr e4
let e5g ← toGotoExpr e5
let e6g ← toGotoExpr e6
return { id := op, type := gty, operands := [e1g, e2g, e3g, e4g, e5g, e6g] }
| _ => .error f!"[toGotoExpr] Not yet implemented: {e}"

/--
Expand Down Expand Up @@ -354,6 +384,41 @@ def LExpr.toGotoExprCtx {TBase: LExprParams} [ToString $ LExpr TBase.mono]
let tg ← toGotoExprCtx bvars t
let eg ← toGotoExprCtx bvars e
return (Expr.ite cg tg eg)
-- N-ary Functions (4+ arguments) — handles function applications with more
-- than 3 arguments that aren't caught by the ternary/binary/unary cases.
-- Pattern: .app _ (.app _ (.app _ (.app _ (.op _ fn ty) e1) e2) e3) e4
| .app _ (.app _ (.app _ (.app _ (.op _ fn (some ty)) e1) e2) e3) e4 =>
let op ← fnToGotoID (toString fn)
let retty := ty.destructArrow.getLast!
let gty ← retty.toGotoType
let e1g ← toGotoExprCtx bvars e1
let e2g ← toGotoExprCtx bvars e2
let e3g ← toGotoExprCtx bvars e3
let e4g ← toGotoExprCtx bvars e4
return { id := op, type := gty, operands := [e1g, e2g, e3g, e4g] }
-- Quinary (5 arguments)
| .app _ (.app _ (.app _ (.app _ (.app _ (.op _ fn (some ty)) e1) e2) e3) e4) e5 =>
let op ← fnToGotoID (toString fn)
let retty := ty.destructArrow.getLast!
let gty ← retty.toGotoType
let e1g ← toGotoExprCtx bvars e1
let e2g ← toGotoExprCtx bvars e2
let e3g ← toGotoExprCtx bvars e3
let e4g ← toGotoExprCtx bvars e4
let e5g ← toGotoExprCtx bvars e5
return { id := op, type := gty, operands := [e1g, e2g, e3g, e4g, e5g] }
-- Senary (6 arguments)
| .app _ (.app _ (.app _ (.app _ (.app _ (.app _ (.op _ fn (some ty)) e1) e2) e3) e4) e5) e6 =>
let op ← fnToGotoID (toString fn)
let retty := ty.destructArrow.getLast!
let gty ← retty.toGotoType
let e1g ← toGotoExprCtx bvars e1
let e2g ← toGotoExprCtx bvars e2
let e3g ← toGotoExprCtx bvars e3
let e4g ← toGotoExprCtx bvars e4
let e5g ← toGotoExprCtx bvars e5
let e6g ← toGotoExprCtx bvars e6
return { id := op, type := gty, operands := [e1g, e2g, e3g, e4g, e5g, e6g] }
| _ => .error f!"[toGotoExprCtx] Not yet implemented: {toString e}"

/--
Expand Down
4 changes: 3 additions & 1 deletion Strata/Cli/VerifyOptions.lean
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,9 @@ def parseVerifyOptions (pflags : ParsedFlags)
def laurelTranslateFlags : List Flag := [
{ name := "keep-all-files",
help := "Store intermediate Laurel and Core programs in <dir>.",
takesArg := .arg "dir" }
takesArg := .arg "dir" },
{ name := "always-call-core-functions",
help := "Redirect calls to single-output procedures to their pure $asFunction versions (keeps them constant-foldable during symbolic evaluation)." }
]

/-- All CLI flags accepted by Laurel verify commands. -/
Expand Down
2 changes: 1 addition & 1 deletion Strata/Languages/Core/CoreOp.lean
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ inductive MapOpKind where
deriving Repr, DecidableEq, Inhabited, BEq, Hashable

def MapOpKind.names : List (MapOpKind × String) :=
[(.Const, "const"), (.Select, "select"), (.Update, "update")]
[(.Const, "mapConst"), (.Select, "select"), (.Update, "update")]

def MapOpKind.toString (k : MapOpKind) : String := lookupName names k
instance : ToString MapOpKind := ⟨MapOpKind.toString⟩
Expand Down
23 changes: 20 additions & 3 deletions Strata/Languages/Core/DDMTransform/FormatCore.lean
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,26 @@ partial def lappToExpr {M} [Inhabited M]
: ToCSTM M (CoreDDM.Expr M) := do
let (head, args) := Lambda.getLFuncCall e
match head with
| .op _ fn _ =>
let argExprs ← args.mapM (lexprToExpr · qLevel)
lopToExpr fn.name argExprs
| .op _ fn ty =>
-- `mapConst` (the constant-map builtin) has no inferable key type, so it is
-- emitted with an explicit key-type annotation `mapConst<K>(v)`. Recover `K`
-- from the op's function type `V → Map K V`.
if fn.name == "mapConst" then
match args with
| [valArg] =>
let valCST ← lexprToExpr valArg qLevel
let kCST ← match ty with
| some (.tcons "arrow" [_, .tcons "Map" [k, _]]) => lmonoTyToCoreType k
| some (.tcons "Map" [k, _]) => lmonoTyToCoreType k
| _ => pure (CoreType.tvar default unknownTypeVar)
-- The value type is inferred from `v` on re-parse, so a placeholder is fine.
pure (.map_const default kCST (CoreType.tvar default unknownTypeVar) valCST)
| _ =>
let argExprs ← args.mapM (lexprToExpr · qLevel)
lopToExpr fn.name argExprs
else
let argExprs ← args.mapM (lexprToExpr · qLevel)
lopToExpr fn.name argExprs
| .app _ fn arg =>
-- getLFuncCall couldn't decompose further (fn is not .app or .op)
let fnCST ← lexprToExpr fn qLevel
Expand Down
4 changes: 4 additions & 0 deletions Strata/Languages/Core/DDMTransform/Grammar.lean
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ fn old (tp : Type, v : tp) : tp => "old " v;
fn map_get (K : Type, V : Type, m : Map K V, k : K) : V => m "[" k "]";
fn map_set (K : Type, V : Type, m : Map K V, k : K, v : V) : Map K V =>
m "[" k ":=" v "]";
// map_const uses explicit key-type annotation syntax: the key type cannot be
// inferred from the single value argument, so it is written `mapConst<K>(v)`.
// The value type V is inferred from `v`.
fn map_const (K : Type, V : Type, v : V) : Map K V => "mapConst" "<" K ">" "(" v ")";

// seq_empty uses explicit type annotation syntax since there are no value
// arguments to infer the type parameter from.
Expand Down
6 changes: 6 additions & 0 deletions Strata/Languages/Core/DDMTransform/Translate.lean
Original file line number Diff line number Diff line change
Expand Up @@ -977,6 +977,12 @@ partial def translateExpr (p : Program) (bindings : TransBindings) (arg : Arg) :
let i ← translateExpr p bindings ia
let x ← translateExpr p bindings xa
return .mkApp () fn [m, i, x]
| .fn _ q`Core.map_const, [_ktp, _vtp, va] =>
let kty ← translateLMonoTy bindings _ktp
let vty ← translateLMonoTy bindings _vtp
let fn : LExpr Core.CoreLParams.mono := (Core.coreOpExpr (.map .Const) (.some (LMonoTy.mkArrow vty [Core.mapTy kty vty])))
let v ← translateExpr p bindings va
return .mkApp () fn [v]
-- Seq operations
| .fn _ q`Core.seq_length, [_atp, sa] =>
let ety ← translateLMonoTy bindings _atp
Expand Down
11 changes: 7 additions & 4 deletions Strata/Languages/Core/Factory.lean
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,21 @@ def reNoneFunc : WFLFunc CoreLParams :=
nullaryUneval "Re.None" mty[regex]

/- A constant `Map` constructor with type `∀k, v. v → Map k v`.
`const(d)` returns a map where every key maps to the value `d`. -/
`mapConst(d)` returns a map where every key maps to the value `d`.
Named `mapConst` (not `const`) to avoid colliding with the `const`
declaration keyword in the Core grammar, which would otherwise make
pretty-printed programs fail to re-parse. -/
def mapConstFunc : WFLFunc CoreLParams :=
polyUneval "const" ["k", "v"]
polyUneval "mapConst" ["k", "v"]
[("d", mty[%v])]
(mapTy mty[%k] mty[%v])
(axioms := [
esM[∀ (%v): -- %1 d
(∀ (%k): -- %0 kk
{(((~select : (Map %k %v) → %k → %v)
((~const : %v → (Map %k %v)) %1)) %0)}
((~mapConst : %v → (Map %k %v)) %1)) %0)}
(((~select : (Map %k %v) → %k → %v)
((~const : %v → (Map %k %v)) %1)) %0) == %1)]
((~mapConst : %v → (Map %k %v)) %1)) %0) == %1)]
])

/- A `Map` selection function with type `∀k, v. Map k v → k → v`. -/
Expand Down
21 changes: 7 additions & 14 deletions Strata/Languages/Laurel/ConstrainedTypeElim.lean
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ def constraintCallFor (ptMap : ConstrainedTypeMap) (ty : HighType)
(varName : Identifier) (src : Option FileRange := none) : Option StmtExprMd :=
constraintCallForExpr ptMap ty ⟨.Var (.Local varName), src⟩ src

/-- Generate a constraint function for a constrained type.
For nested types, the function calls the parent's constraint function. -/
def mkConstraintFunc (ptMap : ConstrainedTypeMap) (ct : ConstrainedType) : Procedure :=
/-- Generate a constraint procedure for a constrained type.
For nested types, the procedure calls the parent's constraint procedure. -/
def mkConstraintProc (ptMap : ConstrainedTypeMap) (ct : ConstrainedType) : Procedure :=
let baseType := resolveType ptMap ct.base
let bodyExpr: StmtExprMd := match ct.base.val with
| .UserDefined parent =>
Expand All @@ -90,7 +90,6 @@ def mkConstraintFunc (ptMap : ConstrainedTypeMap) (ct : ConstrainedType) : Proce
inputs := [{ name := ct.valueName, type := baseType }]
outputs := [{ name := mkId "result", type := { val := .TBool, source := none } }]
body := .Transparent { val := .Return bodyExpr, source := none }
isFunctional := true
decreases := none
preconditions := [] }

Expand Down Expand Up @@ -166,16 +165,15 @@ def elimProc (ptMap : ConstrainedTypeMap) (model : SemanticModel) (proc : Proced
let inputRequires : List Condition := proc.inputs.filterMap fun p =>
(constraintCallFor ptMap p.type.val p.name (src := p.type.source)).map
fun c => { condition := c }
let outputEnsures : List Condition := if proc.isFunctional then [] else proc.outputs.filterMap fun p =>
let outputEnsures : List Condition := proc.outputs.filterMap fun p =>
(constraintCallFor ptMap p.type.val p.name (src := p.type.source)).map
fun c => { condition := ⟨c.val, p.type.source⟩ }
let body' := match proc.body with
| .Transparent bodyExpr =>
let body := elimStmts ptMap model bodyExpr
if outputEnsures.isEmpty then .Transparent body
else
let retBody := if proc.isFunctional then ⟨.Return (some body), bodyExpr.source⟩ else body
.Opaque outputEnsures (some retBody) []
.Opaque outputEnsures (some body) []
| .Opaque postconds impl modif =>
let impl' := impl.map (elimStmts ptMap model)
.Opaque (postconds ++ outputEnsures) impl' modif
Expand Down Expand Up @@ -206,7 +204,6 @@ private def mkWitnessProc (ptMap : ConstrainedTypeMap) (ct : ConstrainedType) :
outputs := []
body := .Opaque [] (some ⟨.Block [witnessInit, assert] none, src⟩) []
preconditions := []
isFunctional := false
decreases := none }

/-- Eliminate constrained types within a composite type definition: resolve
Expand All @@ -227,21 +224,17 @@ public def constrainedTypeElim (model : SemanticModel) (program : Program)
let ptMap := buildConstrainedTypeMap program.types
if ptMap.isEmpty then (program, []) else
let constraintFuncs := program.types.filterMap fun
| .Constrained ct => some (mkConstraintFunc ptMap ct) | _ => none
| .Constrained ct => some (mkConstraintProc ptMap ct) | _ => none
let witnessProcedures := program.types.filterMap fun
| .Constrained ct => some (mkWitnessProc ptMap ct) | _ => none
let funcDiags := program.staticProcedures.foldl (init := []) fun acc proc =>
if proc.isFunctional && proc.outputs.any (fun p => isConstrainedType ptMap p.type.val) then
acc.cons (diagnosticFromSource proc.name.source "constrained return types on functions are not yet supported")
else acc
({ program with
staticProcedures := constraintFuncs ++ program.staticProcedures.map (elimProc ptMap model)
++ witnessProcedures
types := program.types.filterMap fun
| .Constrained _ => none
| .Composite ct => some (.Composite (elimCompositeType ptMap model ct))
| other => some other },
funcDiags)
[])

/-- Pipeline pass: constrained type elimination. -/
public def constrainedTypeElimPass : LoweringPass where
Expand Down
Loading
Loading