Skip to content

Commit 2eba201

Browse files
authored
wp: use named cases instead of positional rcases in the exec unfold lemmas (#128)
`exec_loop_cons_unfold`, `exec_block_cons` and `exec_iff_cons` destructure an `exec …` result with a positional constructor pattern (`⟨_,_⟩ | ⟨n,_,_⟩ | … `), which silently depends on the declaration order of `Continuation`'s constructors — reordering them would break these proofs in a confusing way. This switches each to a named `cases … with | Fallthrough .. | …` form. Purely internal to the tactic blocks; the theorem statements and the proof behaviour of every arm are unchanged.
1 parent 0535fb3 commit 2eba201

2 files changed

Lines changed: 51 additions & 29 deletions

File tree

interpreter/Interpreter/Wasm/Semantics/Lemmas.lean

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -400,15 +400,15 @@ theorem exec_block_cons
400400
{ s' with values := s'.values.take rs ++ s.values.drop ps } rest env
401401
| other => other) := by
402402
simp only [exec, execOne.eq_def]
403-
rcases exec fuel m st s body env with _ | ⟨n, _, _⟩ | _ | _ | _ | _ | _ | _
404-
· rfl
405-
· cases n <;> rfl
406-
· rfl
407-
· rfl
408-
· rfl
409-
· rfl
410-
· rfl
411-
· rfl
403+
cases exec fuel m st s body env with
404+
| Fallthrough _ _ => rfl
405+
| Break n _ _ => cases n <;> rfl
406+
| Return _ _ => rfl
407+
| Trap _ _ => rfl
408+
| Invalid _ => rfl
409+
| OutOfFuel => rfl
410+
| ReturnCall _ _ _ => rfl
411+
| Throwing _ _ _ _ => rfl
412412

413413
theorem exec_iff_cons
414414
{m : Module} {env : HostEnv α} {st : Store α} {s : Locals}
@@ -428,17 +428,26 @@ theorem exec_iff_cons
428428
| other => other) := by
429429
simp only [exec, execOne.eq_def, hStack]
430430
by_cases hc : c ≠ 0
431-
all_goals first
432-
| (simp only [if_pos hc]
433-
rcases exec fuel m st { s with values := vs } thn env with _ | ⟨n, _, _⟩ | _ | _ | _ | _
434-
· rfl
435-
· cases n <;> rfl
436-
all_goals rfl)
437-
| (simp only [if_neg hc]
438-
rcases exec fuel m st { s with values := vs } els env with _ | ⟨n, _, _⟩ | _ | _ | _ | _
439-
· rfl
440-
· cases n <;> rfl
441-
all_goals rfl)
431+
· simp only [if_pos hc]
432+
cases exec fuel m st { s with values := vs } thn env with
433+
| Fallthrough _ _ => rfl
434+
| Break n _ _ => cases n <;> rfl
435+
| Return _ _ => rfl
436+
| Trap _ _ => rfl
437+
| Invalid _ => rfl
438+
| OutOfFuel => rfl
439+
| ReturnCall _ _ _ => rfl
440+
| Throwing _ _ _ _ => rfl
441+
· simp only [if_neg hc]
442+
cases exec fuel m st { s with values := vs } els env with
443+
| Fallthrough _ _ => rfl
444+
| Break n _ _ => cases n <;> rfl
445+
| Return _ _ => rfl
446+
| Trap _ _ => rfl
447+
| Invalid _ => rfl
448+
| OutOfFuel => rfl
449+
| ReturnCall _ _ _ => rfl
450+
| Throwing _ _ _ _ => rfl
442451

443452
theorem exec_call_cons
444453
{m : Module} {env : HostEnv α} {st : Store α} {s : Locals}

interpreter/Interpreter/Wasm/Wp/Loop.lean

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,28 @@ private theorem exec_loop_cons_unfold {α : Type} (fuel : Nat) (m : Module)
3636
| .Break (k+1) st' s' => .Break k st' s'
3737
| other => other) := by
3838
simp only [exec, execOne_loop_succ]
39-
rcases hb : exec fuel m st s body env with
40-
⟨_, _⟩ | ⟨n, _, _⟩ | ⟨_, _⟩ | _ | _ | _ | ⟨_, _, _⟩ | ⟨_, _, _, _⟩
41-
· rfl
42-
· cases n
43-
· simp only
44-
rcases hk : execOne fuel _ _ _ (.loop ps rs body) env
45-
with ⟨_, _⟩ | ⟨_, _, _⟩ | ⟨_, _⟩ | _ | _ | _ | ⟨_, _, _⟩ | ⟨_, _, _, _⟩ <;> rfl
46-
· rfl
47-
all_goals rfl
39+
cases hb : exec fuel m st s body env with
40+
| Fallthrough _ _ => rfl
41+
| Break n _ _ =>
42+
cases n with
43+
| zero =>
44+
simp only
45+
cases hk : execOne fuel _ _ _ (.loop ps rs body) env with
46+
| Fallthrough _ _ => rfl
47+
| Break _ _ _ => rfl
48+
| Return _ _ => rfl
49+
| Trap _ _ => rfl
50+
| Invalid _ => rfl
51+
| OutOfFuel => rfl
52+
| ReturnCall _ _ _ => rfl
53+
| Throwing _ _ _ _ => rfl
54+
| succ _ => rfl
55+
| Return _ _ => rfl
56+
| Trap _ _ => rfl
57+
| Invalid _ => rfl
58+
| OutOfFuel => rfl
59+
| ReturnCall _ _ _ => rfl
60+
| Throwing _ _ _ _ => rfl
4861

4962
theorem wp_loop_cons {ps rs : Nat} {body rest : Program} {Q : Assertion α}
5063
(Inv : AssertionF α) (μ : Store α → Locals → Nat)

0 commit comments

Comments
 (0)