Commit a729eb7
## Summary
This PR introduces `Procedure.Body := .structured (List Statement) |
.cfg DetCFG` — a sum type letting a Strata Core procedure carry either a
structured statement-list body or a deterministic control-flow graph. It
includes the type infrastructure, consumer threading across the
verification pipeline, the DDM parser/translator support for the new
`cfg` syntax, and CFG example programs.
This PR is split out of
[#1196](#1196) as a
self-contained PR that can land independently on `main2`. It contributes
~714 LoC of additions vs `main2` (compared to ~5,567 LoC on
[#1196](#1196)). It is
**independent** of the companion split [#1341
(htd/unstructured-infra)](#1341)
— the two PRs touch disjoint files (only `ProcBodyVerifyCorrect.lean`
overlaps in different regions, mergeable cleanly).
This PR does **not** introduce the imperative-DL infrastructure
(metadata-bearing transfers, `EvalDetBlock` constructor renames, etc.) —
those live in the companion [#1341
`htd/unstructured-infra`](#1341)
PR. Without that, this PR's `CoreBodyExec` semantic relation has only
the `.structured` constructor; the `.cfg` constructor is added when both
branches merge.
## What's added
The 44 files modified group into 5 layers:
### Type infrastructure (`Procedure.lean`, ~110 LoC)
- `inductive Procedure.Body := .structured (List Statement) | .cfg
DetCFG` plus `Inhabited` instance
- `abbrev DetCFG := Imperative.CFG String (Imperative.DetBlock String
Command Expression)`
- 7 projection helpers: `getStructured`, `getCfg`, `getVars`,
`isAbstract`, `isStructured`, `isCfg`, `structuredLength`
- `HasVarsPure`/`HasVarsImp` instances on `Body` and `DetCFG`
- `DetCFG.eraseTypes`, `DetCFG.stripMetaData`
- `Procedure.body` field flips from `List Statement` to `Procedure.Body`
(default `.structured []`)
- `Procedure.eraseTypes`/`stripMetaData`/`getVars` retrofits
### WF predicate adaptation
- `WF.lean`: `wfstmts`/`wfloclnd`/`bodyExitsCovered` rewritten as `∀ ss,
body = .structured ss → ...`
- `ProcBodyVerifyCorrect.lean`: new `procToVerifyStmt_is_structured`
lemma bridging the sum type to the verification pipeline's `.structured`
requirement
### Semantic relation
- `StatementSemantics.lean`: `CoreBodyExec` with `.structured`
constructor; `EvalCommand.call_sem` updated to use it
- The `.cfg` constructor is left for
[#1196](#1196) since it depends
on `EvalDetBlock` from the companion infra PR
### Consumer threading (~150 LoC across 15 files)
**Real CFG handling** (cannot be safely stubbed):
- `CallGraph.lean`: traverses CFG arms to extract calls
- `ProcedureInlining.lean`: handles `.structured` arm with the existing
logic; throws on `.cfg`
**`.cfg`-arm stubs** (error/passthrough/throw, replaceable when
[#1196](#1196) merges):
- `StatementEval.lean`, `ProcedureType.lean`, `ProcedureEval.lean`,
`Verifier.lean`, `ObligationExtraction.lean`, `FormatCore.lean`
- `Transform/PrecondElim.lean`, `CoreTransform.lean`, `LoopElim.lean`,
`ANFEncoder.lean`, `TerminationCheck.lean`, `ProcBodyVerify.lean`,
`CoreSpecification.lean`
### DDM parser support (`DDMTransform/Grammar.lean`, ~54 LoC)
- New parser categories: `Transfer`, `CFGBlock`, `CFGBlocks`, `CFGBody`
- `command_cfg_procedure` operator parsing `procedure name ... cfg ENTRY
{ ... }` syntax
- Transfer commands: `transfer_goto`, `transfer_nondet_goto`,
`transfer_cond_goto` (using `branch (cond) goto LT else goto LF` to
avoid `if`-collision with structured syntax), `transfer_return`
### DDM translator (`DDMTransform/Translate.lean`, ~115 LoC)
- `translateCFGBlock`, `translateCFGBlocks`, `translateCFGBody`,
`translateTransfer` build `Procedure.Body.cfg` from parsed AST
- `translateProcedure`/`translateBlockCommand` updated to route
`.structured` vs `.cfg` body shapes
### Examples and tooling
- `Examples/CFGSimple.core.st` — sample procedure (`Max(x,y)` computing
maximum of two integers via CFG)
- `Examples/CFGNondet.core.st` — sample with nondeterministic transfer
- `docs/Architecture.md`, `docs/verso/IRTranslationPhilosophyDoc.lean` —
documentation updates
- `editors/emacs/core-st-mode.el`,
`editors/vscode/syntaxes/core-st.tmLanguage.json` — keyword highlighting
for `cfg`/`branch`/`goto`/`return` literals
## Comparison vs [#1196](#1196)
| Feature | This PR |
[#1196](#1196) |
|---|:---:|:---:|
| `Procedure.Body` sum type + `DetCFG` abbreviation + `body` field flip
| ✅ | ✅ |
| Body projection helpers (`getStructured`, `getVars`, etc.) | ✅ | ✅ |
| `WF.lean` adaptation for sum-type body | ✅ | ✅ |
| `procToVerifyStmt_is_structured` bridge lemma | ✅ | ✅ |
| `CoreBodyExec` (`.structured` arm) | ✅ | ✅ |
| `CoreBodyExec` (`.cfg` arm) | — (needs infra) | ✅ |
| `CallGraph.lean` CFG traversal | ✅ | ✅ |
| `ProcedureInlining.lean` sum-type handling | ✅ | ✅ |
| `.cfg`-arm stubs in 13 consumers | ✅ | ✅ replaced by full impl |
| Full `.cfg`-arm implementations (PrecondElim, ProcedureEval, etc.) | —
| ✅ |
| DDM `cfg ENTRY { ... }` parser syntax | ✅ | ✅ |
| DDM `translateCFG*` translator | ✅ | ✅ |
| CFG examples (`Examples/CFG{Simple,Nondet}.core.st`) | ✅ | ✅ |
| Editor/docs syntax-highlighting updates | ✅ | ✅ |
| Imperative DL: metadata-bearing transfers, `EvalDetBlock` rename | —
(in companion PR) | ✅ |
| Translator metadata propagation | — (in companion PR) | ✅ |
| GOTO backend CFG pipeline | — | ✅ |
| CFG-specific test suites | — | ✅ |
| Lambda framework theorems | — | ✅ (via main2 merges) |
## Build status
- `lake build`: green (490 jobs)
- `lake test --exclude Languages.Python`: green (modulo the pre-existing
CI-managed `ion-java-1.11.11.jar` test fixture)
- 0 sorries, 0 axioms across all modified files
## Test plan
- [x] `lake build` succeeds locally on a fresh worktree
- [x] `lake test --exclude Languages.Python` succeeds (the only failure
is the env-managed `ion-java` jar download which CI handles)
- [x] No new sorries or axioms in any file
- [x] Existing structured-procedure tests continue to pass (the `.body
:= .structured body` adapter at `Translate.lean:1683`/`1702` keeps
existing parsing/verification paths working)
- [ ] CI passes
- [ ] Pairs with the companion [#1341
`htd/unstructured-infra`](#1341)
PR — either can land first; see comparison table above
- [ ] After this and the infra PR land,
[#1196](#1196) can be rebased
to ~2,000 LoC of remaining CFG-pipeline-specific content (CFG test
suites, GOTO backend, full `.cfg`-arm implementations replacing stubs)
1 parent f090775 commit a729eb7
41 files changed
Lines changed: 684 additions & 147 deletions
File tree
- Examples
- StrataTest
- Backends/CBMC/GOTO
- Languages/Core
- Examples
- Tests
- Transform
- Strata
- Backends/CBMC
- GOTO
- Languages
- C_Simp
- Core
- DDMTransform
- Laurel
- Transform
- 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 | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
340 | 340 | | |
341 | 341 | | |
342 | 342 | | |
343 | | - | |
| 343 | + | |
| 344 | + | |
344 | 345 | | |
345 | 346 | | |
346 | 347 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
204 | 204 | | |
205 | 205 | | |
206 | 206 | | |
207 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
208 | 212 | | |
209 | 213 | | |
210 | 214 | | |
| |||
221 | 225 | | |
222 | 226 | | |
223 | 227 | | |
224 | | - | |
| 228 | + | |
225 | 229 | | |
226 | 230 | | |
227 | 231 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
52 | | - | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
53 | 58 | | |
54 | 59 | | |
55 | 60 | | |
| |||
60 | 65 | | |
61 | 66 | | |
62 | 67 | | |
63 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
64 | 71 | | |
65 | 72 | | |
66 | 73 | | |
| |||
106 | 113 | | |
107 | 114 | | |
108 | 115 | | |
109 | | - | |
| 116 | + | |
110 | 117 | | |
111 | 118 | | |
112 | 119 | | |
| |||
263 | 270 | | |
264 | 271 | | |
265 | 272 | | |
266 | | - | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
267 | 278 | | |
268 | 279 | | |
269 | 280 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
| 172 | + | |
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
233 | 239 | | |
234 | 240 | | |
235 | 241 | | |
236 | 242 | | |
237 | | - | |
238 | | - | |
| 243 | + | |
239 | 244 | | |
240 | 245 | | |
241 | 246 | | |
| |||
253 | 258 | | |
254 | 259 | | |
255 | 260 | | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
256 | 266 | | |
257 | 267 | | |
258 | | - | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
259 | 271 | | |
260 | 272 | | |
261 | 273 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
989 | 989 | | |
990 | 990 | | |
991 | 991 | | |
992 | | - | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
| 996 | + | |
| 997 | + | |
993 | 998 | | |
994 | 999 | | |
995 | 1000 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
| 27 | + | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| |||
469 | 469 | | |
470 | 470 | | |
471 | 471 | | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
472 | 525 | | |
473 | 526 | | |
474 | 527 | | |
| |||
0 commit comments