Commit 267cce2
authored
proof(L2): TypingL2.v + Modality.v skeleton — Linear⇒Affine weakening Qed (#168)
## Summary
Layer 2 of the four-layer preservation redesign
(`PRESERVATION-DESIGN.md` §5). Encodes the modality as a judgment
parameter and ships the **headline §5 weakening lemma** `weaken_modality
: Linear ⇒ Affine` as Qed. Mirrors
`echo-types/proofs/agda/EchoLinear.agda`'s `weaken` at the
typing-derivation layer.
## What's in this PR
### `formal/Modality.v`
| Item | Kind |
|---|---|
| `Modality = {Linear, Affine}` | inductive |
| `modality_le` thin-poset at sort Type | inductive |
| `modality_le_refl` / `modality_le_trans` / `modality_le_prop` | Qed,
**all K-free** |
### `formal/TypingL2.v`
| Item | Kind |
|---|---|
| `has_type_l2 : Modality → region_env → ctx → expr → ty → region_env →
ctx → Type` | inductive (1 constructor in this skeleton) |
| `L2_lift_l1` | the single constructor: any L1 derivation lifts to L2
at either mode |
| `lift_l1_to_linear` / `lift_l1_to_affine` | convenience entry points |
| `project_l2_to_l1` | inverse projection (no info loss) |
| **`weaken_modality`** — the §5 headline | **Qed** |
| `weaken_modality_le` — general modality-poset weakening | Definition |
| `weaken_modality_le_id_linear` / `_id_affine` /
`_strict_is_weaken_modality` | Qed |
## Axiom status
**Every lemma in this PR is closed under the global context** — zero K,
zero UIP, zero new axioms. Verified via `Print Assumptions` on
`modality_le_trans`, `modality_le_prop`, `weaken_modality`,
`weaken_modality_le`, `weaken_modality_le_strict_is_weaken_modality`.
Note: this is *cleaner* than L3 Phase 1's `Mode` poset in `Echo.v`,
which uses `dependent destruction` for `mode_le_trans` and
`degrade_mode_comp` (documented K proof-debt). L2's `modality_le_trans`
uses the K-free motive trick from the start; the L3.K cleanup task (#6
in session tracker) can mirror this pattern.
## What's NOT in this PR (forward-looking, separate PRs)
- **Mode-specific `T_Lam_*_L2`** — Linear requires `(T1, true)` on body
output; Affine permits `(T1, true_or_unused)`. Adding these introduces
mode-switch cases in `weaken_modality`'s proof.
- **Mode-specific `T_Drop_*_L2`** — Linear: obligation-discharge;
Affine: implicit drop with `LEcho Affine` residue (cross-layer with L3;
see `Echo.v`'s `no_section_collapse_to_residue` for why the residue is
structurally well-defined).
- **Branch-meet for `T_Case_*_L2` / `T_If_*_L2`** — Linear exact `(R',
G')` match vs Affine thin-poset meet.
- **Top-level closure constraint** — Linear: `G = G' = []`; Affine: `G'
may carry unused linear bindings`.
- **No-leak / no-duplicate / resource-exact /
garbage-residue-inhabited** proof obligations (§5 table).
- **Effect-typed `TFun`** — resolves L1's lambda-rigidity gap per §4.8.
## Cross-layer dependency note
L1's `S_App_Step2` / `S_Pair_Step2` admits in `preservation_l1` are
explicitly L2/L3-gated by `Semantics_L1.v`'s design notes (§4.8). The L2
mode-specific `T_Lam_*_L2` constructors are the mechanism that closes
them in a follow-up.
## Branch base
Stacked off `proof/l1-region-threading-design` (PR #153, currently
auto-merge-armed pending governance CI rerun). Will rebase to `main`
once #153 lands.
## Test plan
- [x] `coqc 8.18.0` builds `Modality.v` + `TypingL2.v` cleanly, 0 admits
- [x] Clean full-project rebuild passes — 9 .v files
- [x] `Print Assumptions weaken_modality` returns `Closed under the
global context` — headline result is K-free, zero axioms
- [x] No new axioms introduced beyond what L1/L3 already document
- [ ] CI green
- [ ] Review: judgment shape matches §5; the single-constructor skeleton
is appropriate as a "first slice" parallel to L3's #166; the
mode-specific rules are correctly out of scope
Refs `PRESERVATION-DESIGN.md` §5,
`echo-types/proofs/agda/EchoLinear.agda`, PR #153, PR #166, PR #167.
🤖 Generated with [Claude Code](https://claude.com/claude-code)1 parent ff9b0e3 commit 267cce2
3 files changed
Lines changed: 308 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
| 14 | + | |
| 15 | + | |
0 commit comments