Skip to content

Commit c17b2ee

Browse files
Phase 1b foundation: store typing (StoreWellTyped + lemmas) (#112)
## What Adds the **store-typing relation** that bridges the static `TypeEnv` and the runtime `Env` — the invariant every statement-execution preservation theorem is stated against — plus the three lemmas the statement dynamics rest on. ```lean def StoreWellTyped (Γ : TypeEnv) (ρ : Env) : Prop := ∀ x t, Γ x = some t → ∃ v, ρ x = some v ∧ HasType emptyTypeEnv (.lit v) t ``` | Lemma | Statement | |---|---| | `store_wellTyped_empty` | the empty store types against the empty context | | `store_wellTyped_lookup` | a typed variable resolves to a value of its type | | `store_wellTyped_extend` | extending context+store in lockstep (exactly a `varDecl`) preserves store typing | ## Why this, and why now Per the agreed sequencing rule — *land the lowest-complexity, safe, **complete** unit first* — this is the foundational piece of **roadmap Phase 1b (statement dynamics)**. The statement-*execution* relation itself is the next, higher-complexity step: the expression `Step` is closed-term-only, so variable resolution needs design. That lands in a follow-up; this store-typing layer is the stable base it builds on (notably `store_wellTyped_extend` is the key step for `varDecl` preservation). ## Verification - `lean docs/proofs/verification/WokeLang.lean` exits 0 (Lean 4.30.0, Mathlib-free, single-file). - Hole-free: `#print axioms` reports **`propext`** only for `store_wellTyped_empty`, and **no axioms** for `store_wellTyped_lookup` / `store_wellTyped_extend`. No `sorryAx`, no project-specific assumptions. ## Scope `docs/proofs/verification/WokeLang.lean` (the three lemmas + the `StoreWellTyped` def) and a Progress entry in `docs/proofs/VERIFICATION-ROADMAP.md`. No changes to existing proofs or to the shipping implementation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_015oyMquf4daB6hMhmqB1wAL --- _Generated by [Claude Code](https://claude.ai/code/session_015oyMquf4daB6hMhmqB1wAL)_ Co-authored-by: Claude <noreply@anthropic.com>
1 parent cb54027 commit c17b2ee

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

docs/proofs/VERIFICATION-ROADMAP.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,15 @@ unlock Phases 1c / 3a / 4a.
136136
reduction entangles with statement *execution* and belongs with **Phase 1b** (statement
137137
dynamics), not this step. There is also no `index` constructor, so `[T-Index]` requires an
138138
AST extension. Roadmap refined accordingly.
139-
- [ ] Phase 1 (cont.: `[T-Call]` after 1b), 1b, 1c — type-safety + operational metatheory.
139+
- [~] **Phase 1b (foundation)****store typing** (`StoreWellTyped`) bridging the
140+
static `TypeEnv` and the runtime `Env`, with the three lemmas the statement-execution
141+
preservation proofs rest on: `store_wellTyped_empty` (empty store types against the
142+
empty context), `store_wellTyped_lookup` (a typed variable resolves to a value of its
143+
type), and `store_wellTyped_extend` (extending context+store in lockstep — exactly a
144+
`varDecl` — preserves store typing). Hole-free (axiom `propext` only). The statement
145+
*execution* relation itself is the next, higher-complexity step (the expression `Step`
146+
is closed-term-only, so variable resolution needs design); this foundation lands first.
147+
- [ ] Phase 1 (cont.: `[T-Call]` after 1b), 1b (exec relation + stmt preservation), 1c — type-safety + operational metatheory.
140148
- [ ] Phase 2b, 2c — consent + capability state machines.
141149
- [ ] Phase 3a (+3b) — HM inference.
142150
- [ ] Phase 4a–4c — compiler / parser / WASM.

docs/proofs/verification/WokeLang.lean

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,42 @@ theorem subst_preserves_typing {x : String} {v : Value} {tx : WokeType} :
14731473
simp only [subst]
14741474
exact .tArrayVal _ _ _ (fun w hw => by simpa only [subst] using ih w hw hΔ hv)
14751475

1476+
-- =========================================================================
1477+
-- 7c. Store typing (roadmap Phase 1b foundation)
1478+
-- =========================================================================
1479+
1480+
/-- **Store typing.** The runtime store `ρ` agrees with the type context `Γ`:
1481+
every variable `Γ` types is bound in `ρ` to a value of that type. This is the
1482+
bridge between the static `TypeEnv` and the dynamic `Env`, and the invariant every
1483+
statement-execution preservation theorem is stated against. -/
1484+
def StoreWellTyped (Γ : TypeEnv) (ρ : Env) : Prop :=
1485+
∀ x t, Γ x = some t → ∃ v, ρ x = some v ∧ HasType emptyTypeEnv (.lit v) t
1486+
1487+
/-- The empty store is well typed against the empty context. -/
1488+
theorem store_wellTyped_empty : StoreWellTyped emptyTypeEnv emptyEnv := by
1489+
intro x t h; simp [emptyTypeEnv] at h
1490+
1491+
/-- Looking up a typed variable in a well-typed store yields a value of that type. -/
1492+
theorem store_wellTyped_lookup {Γ : TypeEnv} {ρ : Env} {x : String} {t : WokeType}
1493+
(hs : StoreWellTyped Γ ρ) (hx : Γ x = some t) :
1494+
∃ v, ρ x = some v ∧ HasType emptyTypeEnv (.lit v) t := hs x t hx
1495+
1496+
/-- **Store-extension lemma.** Extending the context and the store in lockstep with
1497+
a value of the declared type preserves store typing. This is exactly what a
1498+
`varDecl` statement does to the runtime, and the key step for its preservation. -/
1499+
theorem store_wellTyped_extend {Γ : TypeEnv} {ρ : Env} {x : String} {t : WokeType}
1500+
{v : Value} (hs : StoreWellTyped Γ ρ) (hv : HasType emptyTypeEnv (.lit v) t) :
1501+
StoreWellTyped (extendTypeEnv x t Γ) (extendEnv x v ρ) := by
1502+
intro y ty hy
1503+
simp only [extendTypeEnv] at hy
1504+
by_cases hxy : (x == y) = true
1505+
· rw [if_pos hxy] at hy; injection hy with hty; subst hty
1506+
exact ⟨v, by simp only [extendEnv]; rw [if_pos hxy], hv⟩
1507+
· rw [if_neg hxy] at hy
1508+
obtain ⟨v', hv', hvt⟩ := hs y ty hy
1509+
refine ⟨v', ?_, hvt⟩
1510+
simp only [extendEnv]; rw [if_neg hxy]; exact hv'
1511+
14761512
-- =========================================================================
14771513
-- 8. TODO Stubs
14781514
-- =========================================================================

0 commit comments

Comments
 (0)