Commit bfa3c70
feat(formal): real-lift R2 — structured conditionals (fuel-indexed wexec) (#664)
Third rung of the real lift (`formal/REAL-LIFT.adoc`). Adds **structured
control** to the real target IR + source core, and shows the
compiler-correctness simulation still holds across a conditional.
Axiom-free throughout.
## What landed
**Target IR (`formal/RealWasm.v`)**
- New instruction `IfElse (thn els : list instr)` — `lib/wasm.ml`'s `If`
minus the `block_type` validation annotation.
- Because `instr` now nests `list instr`, a *structural* `wexec` is
rejected by Coq's guard checker ("cannot guess decreasing argument" —
the recursive call descends into a branch sub-list, not the tail). So
`wexec` becomes **fuel-indexed** (decreasing on a `nat`), exactly as
`REAL-LIFT.adoc` anticipated for R2. Fuel keeps *definitional*
computation, so `cbn` / `reflexivity` / the demos still evaluate.
- Fuel breaks the old one-line `wexec_seq` (per-cons decrement ⇒ `wexec
(is1++is2) ≠ wexec is2 ∘ wexec is1`). Recovered with:
- `wexec_le_S` / `wexec_mono` — more fuel never loses a `Some` result;
- `wexec_app_some` — additive sequencing: run `is1` with `f1`, then
`is2` with `f2`, get `is1++is2` with `f1+f2` (the fuel-world replacement
for `wexec_seq`);
- `wexec_S_cons` / `wexec_ifelse` — one-step unfold lemmas (by
`reflexivity`) used via `rewrite` so `cbn` doesn't over-reduce the
`IfElse` branch run.
**Source core (`formal/RealCompile.v`)**
- New `RIf (c thn els : rexpr)`; `eval` branches on `Z.eqb vc 0`;
`compile` emits `compile c ++ [IfElse (compile thn) (compile els)]`.
- `compile_correct` restated **existential-in-fuel**:
`exists fuel locals', wexec fuel (compile d e) locals st = Some
(locals', v :: st) /\ …`
(env↔locals agreement + low-slot preservation unchanged). The `RIf` case
opens with `change (compile d (RIf …)) with (… ++ [IfElse …])` to expose
the `++` while keeping inner compiles named, then discharges via
`wexec_app_some` + `wexec_le_S`.
- `wexec_sound` retired in this fuel refactor — it was a convenience
soundness restatement, not load-bearing for `compile_correct`.
## Verification
`coqc` 8.18, whole `formal/` track re-audited after rebasing onto
current `main` (incl. #648's now-wired `Rows.v`):
- **18 files compile**, **31 `Print Assumptions` reports**, every one
*"Closed under the global context"* — **zero axioms, no `Admitted`**.
## Docs
`formal/REAL-LIFT.adoc` (R2 row + nested-control section),
`formal/README.adoc` (RealWasm/RealCompile rows + "The real lift (R0 →
R2)"), `docs/PROOF-NEEDS.adoc` (K-1 row) updated. Conflict-resolved
cleanly against #648 (Rows.v / P-11) and #658 (licence normalisation).
## Next
Sub-rung **R2-loops** (`Loop`/`Br` + while/for, reusing the fuel device;
settles the value-returning-tail question behind #601), then R-mem /
R-float / R-str / … per `formal/REAL-LIFT.adoc`.
Refs `REAL-LIFT.adoc`, `docs/PROOF-NEEDS.adoc` (K-1 row).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr
---
_Generated by [Claude
Code](https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr)_
Co-authored-by: Claude <noreply@anthropic.com>1 parent 15a2087 commit bfa3c70
5 files changed
Lines changed: 283 additions & 201 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
84 | 84 | | |
85 | 85 | | |
86 | 86 | | |
87 | | - | |
88 | | - | |
89 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
| |||
236 | 237 | | |
237 | 238 | | |
238 | 239 | | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
247 | 249 | | |
248 | 250 | | |
249 | 251 | | |
| |||
415 | 417 | | |
416 | 418 | | |
417 | 419 | | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
422 | 425 | | |
423 | 426 | | |
424 | 427 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
96 | 96 | | |
97 | 97 | | |
98 | 98 | | |
99 | | - | |
100 | | - | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
104 | | - | |
105 | | - | |
106 | | - | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
107 | 108 | | |
108 | 109 | | |
109 | 110 | | |
| |||
231 | 232 | | |
232 | 233 | | |
233 | 234 | | |
234 | | - | |
| 235 | + | |
235 | 236 | | |
236 | 237 | | |
237 | 238 | | |
238 | | - | |
| 239 | + | |
239 | 240 | | |
240 | 241 | | |
241 | | - | |
242 | | - | |
| 242 | + | |
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
249 | | - | |
250 | | - | |
251 | | - | |
252 | | - | |
253 | | - | |
254 | | - | |
255 | | - | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
256 | 262 | | |
257 | 263 | | |
258 | 264 | | |
| |||
276 | 282 | | |
277 | 283 | | |
278 | 284 | | |
279 | | - | |
280 | | - | |
| 285 | + | |
| 286 | + | |
281 | 287 | | |
282 | 288 | | |
283 | 289 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
180 | 184 | | |
181 | 185 | | |
182 | 186 | | |
| |||
218 | 222 | | |
219 | 223 | | |
220 | 224 | | |
221 | | - | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
226 | 233 | | |
227 | 234 | | |
228 | 235 | | |
| |||
274 | 281 | | |
275 | 282 | | |
276 | 283 | | |
277 | | - | |
278 | | - | |
| 284 | + | |
| 285 | + | |
279 | 286 | | |
280 | 287 | | |
281 | 288 | | |
282 | 289 | | |
283 | | - | |
284 | | - | |
285 | | - | |
286 | | - | |
287 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
288 | 302 | | |
289 | 303 | | |
0 commit comments