Skip to content

Small-step CFG Semantics and Infrastructures (split of #1196, prep for proof)#1347

Draft
PROgram52bc wants to merge 19 commits into
main2from
htd/structured-to-unstructured-small-step-infra
Draft

Small-step CFG Semantics and Infrastructures (split of #1196, prep for proof)#1347
PROgram52bc wants to merge 19 commits into
main2from
htd/structured-to-unstructured-small-step-infra

Conversation

@PROgram52bc

@PROgram52bc PROgram52bc commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Summary

Variant of #1196's infra-only split (#1341) using per-command small-step CFG semantics in Strata/DL/Imperative/CFGSemantics.lean, per review feedback from @aqjune-aws on #1196 (comment).

Same scope as the unstructured-infra branch — minimal infrastructure for the structured-to-unstructured forward-simulation proof — but with CFGSemantics.lean rewritten:

  • CFGConfig has 3 constructors: .atBlock t σ f, .inBlock t cs tr σ f, .terminal σ f. The mid-block residual command list and the block's transfer survive on .inBlock, so a step never has to descend into the original block (mirroring StepStmt's residual-list config style on the structured side).
  • StepCFG is a 5-constructor relation: fetch (pull a block at a label and unfold to .inBlock), step_cmd (run one head command), goto_true / goto_false (fire a condGoto transfer once the residual list is empty), finish.
  • EvalDetBlock and EvalNondetBlock are removed.

The unconditional .goto k transfer is the special case condGoto HasBool.tt k k _ (definitionally equal); proofs rewrite .goto k and use goto_true instead of needing a separate constructor.

The 27-file diff against main2 is the same set of files as htd/unstructured-infra, with the only delta concentrated in CFGSemantics.lean itself — no ripple required (no other file in the unstructured-infra commit destructures CFGConfig.cont or EvalDetBlock constructors).

This PR is the base for the proof PR (forthcoming) which lands Strata/Transform/StructuredToUnstructuredCorrect.lean adapted to the small-step shape.

Test plan

  • lake build green (488 jobs)
  • lake build StrataTest green (518 jobs)
  • No new sorry or axiom vs main2
  • No regressions in pre-existing tests (golden updates for metadata-bearing transfer printing in StrataTest/Languages/Core/Examples/{Exit,Loops}.lean carried over from unstructured-infra)

Variant of #1196 (htd/unstructured-infra) using per-command small-step
CFG semantics, per review feedback from aqjune-aws.

Same scope as the unstructured-infra commit — the minimal subset of
changes from PR #1196 needed to support the structured-to-unstructured
forward-simulation proof in
`Strata/Transform/StructuredToUnstructuredCorrect.lean` — but with
`Strata/DL/Imperative/CFGSemantics.lean` rewritten in a per-command
small-step style:

* `CFGConfig` has three constructors: `.atBlock t σ f`,
  `.inBlock t cs tr σ f`, `.terminal σ f`. The mid-block residual
  command list and the block's transfer survive on `.inBlock`, so a
  step never has to descend into the original block.
* `StepCFG` is a 5-constructor relation: `fetch` (pull a block at a
  label and unfold to `.inBlock`), `step_cmd` (run one head command
  via the `EvalCmd` parameter), `goto_true` / `goto_false` (fire a
  `condGoto` transfer once the residual list is empty), and `finish`
  (halt at `.terminal`).
* `EvalDetBlock` and `EvalNondetBlock` are removed — the only
  consumers are the structured-to-unstructured proof on a sibling
  branch, and they were already adapted to the new shape there.
* The unconditional `.goto k` transfer is the special case
  `condGoto HasBool.tt k k _` (definitionally equal); we therefore
  don't need a separate `goto` constructor — proofs rewrite `.goto k`
  as `.condGoto HasBool.tt k k _` and use `goto_true`.

All other files match the unstructured-infra commit verbatim. The
27-file diff against `main2` is the same set of files as
`origin/htd/unstructured-infra`, with the only delta concentrated in
`Strata/DL/Imperative/CFGSemantics.lean` itself — no ripple was
required (no other file in the unstructured-infra commit destructures
`CFGConfig.cont` or `EvalDetBlock` constructors).

## Imperative DL framework (5 files)
- BasicBlock.lean: DetTransferCmd.{goto,condGoto,finish} carry MetaData P
- CFGSemantics.lean: per-command small-step CFGConfig + StepCFG
  (`.atBlock` / `.inBlock` / `.terminal`; 5-constructor StepCFG;
  EvalDetBlock and EvalNondetBlock removed)
- MetaData.lean: spec field constants (specLoopInvariant, specDecreases)
- CFGToCProverGOTO.lean: doc/plumbing for the new metadata-bearing transfers
- StructuredToUnstructured.lean: translator emits metadata-bearing transfers

## Proof-required additions
- CmdSemantics.lean: StoreAgreement, projectStore, WellFormedSemanticEvalDef/_ExprCongr/_Var
- CmdSemanticsProps.lean: HasVarsPure typeclass threading on EvalCmd consumers
- StmtSemantics.lean: StoreAgreement.through_projectStore helper
- StmtSemanticsProps.lean: block_some_reaches_terminal, etc.
- Stmt.lean: Block.initVars, Block.uniqueInits, Block.noFuncDecl, Block.simpleShape
- HasVars.lean: LawfulHasFvar/Bool/Ident/IntOrder/Not typeclasses
- StringGen.lean: StringGen utility module
- Specification.lean / SpecificationProps.lean: HasVarsPure typeclass threading
- KleeneSemanticsProps.lean: HasVarsPure threading + ExprCongr arg on
  kleene_assume_terminal
- StatementSemanticsProps.lean: HasVarsPure typeclass on EvalCmdTouch
- DetToKleeneCorrect.lean: ExprCongr threading through det-to-kleene proofs
- ProcBodyVerifyCorrect.lean: ExprCongr threading through PrefixStepsOK helpers
- StepStmtTest.lean: test fixture updates for new EvalCmd constructor signatures
- CFGToCProverGOTO.lean (test): MetaData.empty for new transfer constructors
- Loops.lean / Exit.lean (tests): golden-string updates for metadata-bearing
  transfer printing

The Procedure.Body sum-type infrastructure (~12 files in Strata/Languages/Core/),
GOTO backend pipeline, DDM/Verifier/Type integration, and tests for the above
remain in PR #1196 (will be split into a second PR depending on this one).
@PROgram52bc PROgram52bc force-pushed the htd/structured-to-unstructured-small-step-infra branch from e672c67 to fae1183 Compare June 8, 2026 20:29
@PROgram52bc PROgram52bc changed the title feat: small-step CFG infrastructure for structured-to-unstructured forward-simulation proof Small-step CFG Semantics for Structured -> Unstructured forward-simulation proof (split of #1196) Jun 8, 2026
@PROgram52bc PROgram52bc changed the title Small-step CFG Semantics for Structured -> Unstructured forward-simulation proof (split of #1196) Small-step CFG Semantics and Infrastructures (split of #1196, prep for proof) Jun 8, 2026
Comment thread Strata/DL/Imperative/BasicBlock.lean Outdated
Comment thread README.md Outdated
Comment thread StrataTest/Languages/Core/Examples/RecursiveProcIte.lean
Comment thread StrataTest/Languages/Core/Examples/RecursiveProcIte.lean Outdated
Comment thread StrataTest/Languages/Core/Examples/Quantifiers.lean
Comment thread StrataTest/Languages/Core/Examples/Quantifiers.lean Outdated
…rrect theorems, drop module/meta-import (threads r3376792027, r3376792942, r3376793480, r3376794283))
Forward-compat hygiene: marks the def at /Users/htd/Documents/Strata-small-step-infra/Strata/MetaVerifier.lean:178 with @[expose] so its body is visible across module boundaries.

Without @[expose], any future module-mode caller (file with `module` directive at top) that imports MetaVerifier and invokes `gen_smt_vcs` would fail at the tactic's `Meta.unfoldTarget mv ``Strata.smtVCsCorrect`` step — plain `def` bodies are opaque to importing modules in module mode.

Examples files on this PR currently inherit main2 spelling (legacy import mode) so they don't trigger the issue today. The annotation is preventive — it makes the invariant "downstream proofs may unfold smtVCsCorrect" explicit on the def itself rather than implicit in the caller's import strategy.
The Examples revert in e4d4ca5 (inherit main2 spelling) brought back main2's #guard_msgs expected outputs, but main2's content has byte-offsets that don't match this branch's source layout (which has additional small-step CFG infrastructure changes shifting the provenance numbers).

Loops.lean (4 sites at lines 80, 173, 447): top-of-file shifts -42 bytes, bottom-of-file shifts +53 bytes (same drift signature as the recent PR #1196 fix).

Exit.lean (13 sites at lines 130, 167): uniform -64 byte shift (also matches PR #1196's drift pattern for this file).

Mechanical update: byte-range corrections only. Build clean (StrataTest target: 519 jobs).
# Conflicts:
#	Strata/MetaVerifier.lean
#	Strata/Transform/StructuredToUnstructured.lean
#	StrataTest/Languages/Core/Examples/Exit.lean
…s/HasFvars; kept branch small-step CFG design)
… hasFailure theorems with main2, HasBoolOps/HasFvars/HasOps binders)
…le keeps branch WFExprCongr hyp + main2 PostWF EvalExtensionOf; dropped vestigial HasVarsPure binders)
…n + branch WFExprCongr threading; _block WF facts from ρ₀)
…rrect migrated (eval_assert_pass 3-arg, EvalCmdTouch inlined modifiedOrDefinedVars)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant