Commit 00dba7e
committed
feat(formal): real-lift R2 — structured conditionals (fuel-indexed wexec)
Third rung of the real lift (formal/REAL-LIFT.adoc). Adds structured
control to the real target IR and source core, and proves the
compiler-correctness simulation still holds across a conditional.
Target IR (RealWasm.v):
- new instr `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 means
`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: f1 on is1 then f2 on is2
gives f1+f2 on is1++is2 (the fuel-world replacement for wexec_seq);
* wexec_S_cons / wexec_ifelse — one-step unfold lemmas (by
reflexivity) used via rewrite to stop cbn over-reducing the
IfElse branch run.
Source core (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 the 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.
Whole formal/ track re-audited: zero axioms, no Admitted
(`Print Assumptions` closed under the global context for every closure).
Next sub-rung R2-loops (Loop/Br + while/for, reusing the fuel device;
settles the value-returning-tail question behind #601).
Refs REAL-LIFT.adoc, docs/PROOF-NEEDS.adoc (K-1 row).
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KPG9mEQXFyA3k7NWAzMNMr1 parent 15a2087 commit 00dba7e
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