Commit 84ec7da
Remove global variables and modifies clauses from Core, replace returns with out/inout parameters (#759)
This changes
(1) the Core procedure declaration syntax from separate
input/output parameter lists (`procedure P(x: int) returns (y: int)`)
to a unified parameter list with `out`/`inout` modifiers
(`procedure P(x: int, out y: int)`),
(2) removes the `modifies` clause from procedure specification,
(3) removes global variables from Core, and
(4) changes the syntax of call `call lhs := f(args)` to `call f(x, out
lhs, inout ...)`.
**AST changes (summary: Procedure Header -> none, Decl -> global var
removal, Call -> has list of in/inout/out args)**
- `Procedure.Header.inputs` and `Procedure.Header.outputs` are still
there.
- CST->AST: partition unified bindings into inputs/outputs based on
modifiers (`inout` appears in both inputs and outputs lists)
- AST->CST: detect `inout` by comparing input/output name overlap,
emit `out`/`inout` prefixes instead of `returns` clause
Two new functions on `Procedure.Header` (in `Procedure.lean`)
classify parameters by their role:
- `Procedure.Header.getInoutParams`: returns parameters that appear
in both `inputs` and `outputs` (the intersection). These are the
parameters for which `old x` snapshots are meaningful.
- `Procedure.Header.getOutputOnlyParams`: returns output parameters
that do NOT appear in `inputs`. These are output-only parameters
that have no pre-state.
- Remove `ioDisjoint` from `WFProcedureProp` (inputs and outputs may
now overlap for inout parameters).
**Removal of Decl.var (global variables)**
- Remove `Decl.var` from `Core.Decl` and `DeclKind.var` from
`Core.DeclKind`. Global variables no longer exist in the Core AST.
- Remove `Program.getVar?`, `Program.getVarTy?`, `Program.getVarInit?`,
`Decl.getVar?`, `Decl.getVar`, and related accessors.
- Remove `WFVarProp` from well-formedness definitions and drop the
`.var` case from `WFDeclProp`.
- `ProcedureType.typeCheck`: old-variable bindings for postconditions
are now added only for inout parameters (`getInoutParams`), not for
all program-level globals.
- `StatementType.typeCheckCmd`: add `areInoutArgsValid` check ensuring
that inout call arguments are simple variable references with the
same name as the formal parameter.
- `CollectSymbols.lean`: remove `collectGlobalSymbols` (always empty).
- `ProcedureEval.lean`: old-substitution now only covers input
parameters that also appear as outputs (inout), not program globals.
- `ProgramEval.lean`, `Core.lean`: remove `.var` evaluation case and
statistics counting.
**Old-expression rules**
- `old(expr)` now applies only to inout parameters (those appearing in
both inputs and outputs). For input-only parameters, `old x = x` so
the `old` prefix is not emitted.
**Boole dialect updates (`Verify.lean`)**
The new syntax of Core (`procedure`/`call` with `out`/`inout` params) is
rejected,
to unchange the Core syntax. A new `procedure_signatures.lean` test
covers
accepted and rejected procedure declaration and call statement forms.
Global variables in Boole are translated into `inout` parameters of
procedures
(constant globals to plain parameters).
- Modified globals (`modifies g`) become inout parameters (in both
`allInputs` and `allOutputs`) via `translateProcedureDecl`.
- Pre-pass collects global variable types into
`TranslateState.globalVarTypes` and per-procedure modifies info into
`TranslateState.modifiesMap` via `collectModifiesFromSpec`.
- Read-only globals (referenced but not in `modifies`) become
input-only parameters so they remain in scope.
- `oldifyExpr` takes `currentInoutNames` and only applies `old` prefix
to inout variables. For read-only globals, `old g` simplifies to `g`.
**Pass updates**
- `ProcBodyVerify.lean`: prefix is now
`inputInits ++ outputOnlyInits ++ oldInoutInits ++ assumes`.
- `ProcBodyVerifyCorrect.lean`: full proof rewrite for the new prefix
structure. Added helper lemmas about `getInoutParams` /
`getOutputOnlyParams` (subset, disjointness, nodup). All proofs
complete with zero sorries.
- `CallElim.lean`: old-variable type lookup no longer falls back to
program-level globals.
**Other changes**
- Update all .core.st examples, expected outputs, and test files
- Add `CoreIdent.mkOld_injective` lemma (Identifiers.lean)
- Add `ioNotOld` to `WFProcedureProp` (no IO var is old-prefixed)
- Editor syntax highlights updated for `out`/`inout` keywords
---------
Co-authored-by: Juneyoung Lee <lebjuney@amazon.com>
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-authored-by: Juneyoung Lee <136006969+aqjune-aws@users.noreply.github.com>
Co-authored-by: Shilpi Goel <shigoel@gmail.com>1 parent 786e03b commit 84ec7da
165 files changed
Lines changed: 2358 additions & 2321 deletions
File tree
- Examples
- expected
- StrataTest
- Backends/CBMC
- GOTO
- SimpleAdd
- contracts
- DL/Imperative
- Languages
- Boole
- FeatureRequests
- C_Simp/Examples
- Core
- Examples
- Tests
- Transform
- Strata
- Backends/CBMC
- GOTO
- tests
- Languages
- Boole
- C_Simp
- Core
- DDMTransform
- Laurel
- Python
- Transform
- Tools/BoogieToStrata
- Source
- Tests
- docs/verso
- editors
- emacs
- vscode/syntaxes
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
73 | | - | |
| 73 | + | |
74 | 74 | | |
75 | 75 | | |
76 | 76 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
| 16 | + | |
| 17 | + | |
18 | 18 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| |||
68 | 67 | | |
69 | 68 | | |
70 | 69 | | |
71 | | - | |
| 70 | + | |
72 | 71 | | |
73 | 72 | | |
74 | 73 | | |
| |||
120 | 119 | | |
121 | 120 | | |
122 | 121 | | |
123 | | - | |
| 122 | + | |
124 | 123 | | |
125 | 124 | | |
126 | 125 | | |
| |||
190 | 189 | | |
191 | 190 | | |
192 | 191 | | |
193 | | - | |
| 192 | + | |
194 | 193 | | |
195 | | - | |
196 | | - | |
197 | 194 | | |
198 | 195 | | |
199 | 196 | | |
| |||
211 | 208 | | |
212 | 209 | | |
213 | 210 | | |
214 | | - | |
| 211 | + | |
215 | 212 | | |
216 | 213 | | |
217 | 214 | | |
| |||
221 | 218 | | |
222 | 219 | | |
223 | 220 | | |
224 | | - | |
| 221 | + | |
225 | 222 | | |
226 | 223 | | |
227 | 224 | | |
| |||
233 | 230 | | |
234 | 231 | | |
235 | 232 | | |
236 | | - | |
| 233 | + | |
237 | 234 | | |
238 | 235 | | |
239 | 236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
| 18 | + | |
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
| 18 | + | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
24 | | - | |
25 | 22 | | |
26 | 23 | | |
27 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| |||
0 commit comments