Skip to content

Commit d2baf75

Browse files
hyperpolymathclaude
andcommitted
proof(L2): complete L2-modality migration of L1 preservation development
The L2-modality commit (4e87a05) added the `modality` index to `has_type_l1` and split Lam/Case/If into `_Linear`/`_Affine` variants in TypingL1.v, but never migrated Semantics_L1.v — leaving the entire 1515-line L1 preservation development (and Counterexample.v) broken. This completes that migration so the development compiles again. TypingL1.v: - Replace the free-floating `T_Forget_Affine_L1` rule (which prepended an extra binding to the output context, falsifying `typing_preserves_length_l1` and `value_R_G_preserving_l1`) with proper per-binder mode splits: `T_Let_L1_Linear`/`_Affine` and `T_LetLin_L1_Linear`/`_Affine`, mirroring the existing Lam/Case treatment. Affine variants relax the bound-var output flag to any `u` (the affine "implicit drop"); all rules stay length-preserving. Semantics_L1.v: - Quantify every lemma over an explicit modality `m` (a Section variable fails: `induction Htype` generalises the index, severing cross-references to other m-dependent lemmas). - Make the structural lemmas case-count-robust. - Thread `m` and the mode-split through region-shrink, shift, subst, and the 33-case preservation dispatch (econstructor auto-selects the mode variant in congruence-step cases). - The 4 affine-β subcases (Let/LetLin-Val, Case-Inl/Inr) are admitted with documentation: they need a generalised affine substitution lemma, tracked as L2 follow-up — distinct from the pre-existing linear App/Pair/region-liveness soundness gaps. Counterexample.v: - `bad_input_untypable_l1` / `t_loc_l1_R_preserving` now quantify over `m`: the bad input is untypable in every modality. Full development builds clean from scratch (coqc 8.18, all 6 modules). Legacy `Semantics.v` untouched. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 4e87a05 commit d2baf75

3 files changed

Lines changed: 432 additions & 280 deletions

File tree

formal/Counterexample.v

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,30 +164,31 @@ Section L1Fix.
164164
(** Helper: T_Loc_L1 has [R_out = R_in], [G_out = G_in]. By inversion. *)
165165

166166
Lemma t_loc_l1_R_preserving :
167-
forall R G l r R' G' T,
168-
has_type_l1 R G (ELoc l r) T R' G' ->
167+
forall m R G l r R' G' T,
168+
has_type_l1 m R G (ELoc l r) T R' G' ->
169169
R' = R /\ G' = G.
170170
Proof.
171-
intros R G l r R' G' T H.
171+
intros m R G l r R' G' T H.
172172
inversion H; subst; split; reflexivity.
173173
Qed.
174174

175-
(** The L1 regression theorem. *)
175+
(** The L1 regression theorem: the bad input is untypable in EVERY
176+
modality (linear and affine alike). *)
176177
Lemma bad_input_untypable_l1 :
177-
forall R_out G_out,
178-
~ has_type_l1 (r0 :: r1 :: nil) nil e_bad T_bad R_out G_out.
178+
forall m R_out G_out,
179+
~ has_type_l1 m (r0 :: r1 :: nil) nil e_bad T_bad R_out G_out.
179180
Proof.
180-
intros R_out G_out Htype.
181+
intros m R_out G_out Htype.
181182
unfold e_bad, T_bad in Htype.
182183
(* Invert T_Pair_L1; only rule matching EPair. *)
183184
inversion Htype; subst.
184185
(* Hte1 = typing of (ERegion r1 (ELoc l0 r0)); Hte2 = typing of (ELoc l1 r1). *)
185186
match goal with
186-
| [ H : has_type_l1 _ _ (ERegion r1 (ELoc l0 r0)) _ ?R1 _ |- _ ] =>
187+
| [ H : has_type_l1 _ _ _ (ERegion r1 (ELoc l0 r0)) _ ?R1 _ |- _ ] =>
187188
rename H into Hte1; rename R1 into R1_e1
188189
end.
189190
match goal with
190-
| [ H : has_type_l1 _ _ (ELoc l1 r1) _ _ _ |- _ ] =>
191+
| [ H : has_type_l1 _ _ _ (ELoc l1 r1) _ _ _ |- _ ] =>
191192
rename H into Hte2
192193
end.
193194
(* From Hte2 = T_Loc_L1: In r1 R1_e1. *)
@@ -204,7 +205,7 @@ Section L1Fix.
204205
- (* T_Region_Active_L1: body ([ELoc l0 r0]) is a value; t_loc_l1_R_preserving
205206
gives body's R_out = R_in = [r0; r1]. Hence R1_e1 = remove_first_L1 r1 [r0; r1]. *)
206207
match goal with
207-
| [ Hbody : has_type_l1 _ _ (ELoc _ _) _ ?Rbody _ |- _ ] =>
208+
| [ Hbody : has_type_l1 _ _ _ (ELoc _ _) _ ?Rbody _ |- _ ] =>
208209
assert (HRb : Rbody = r0 :: r1 :: nil)
209210
by (eapply t_loc_l1_R_preserving; eassumption)
210211
end.

0 commit comments

Comments
 (0)