Skip to content

Commit 570ee45

Browse files
syntax(L2 Phase 2 / Phase D slice 1): add TFunEff effect-typed function constructor (#200)
## Summary - Adds `TFunEff T1 T2 R_in R_out` to `ty` in `Syntax.v`, paralleling the existing `TFun T1 T2` (which is preserved per CLAUDE.md owner directive — the legacy `TFun` + `preservation`'s falsity is load-bearing for `Counterexample.v`). - `TFunEff` exposes a lambda body's R-flow at the type level: required for closing the lambda-rigidity admit at `Semantics_L1.v:1694` and naturally unblocking the deferred Phase B Slice 1 + Phase C work. - Slice 1 of 4 — syntax-only landable shape, mirrors L3 wiring slice 1 + Phase A's docs-only PR #197. ## What changed - `Syntax.v` — `TFunEff : ty -> ty -> list region_name -> list region_name -> ty` constructor. - `Typing.v` `free_regions` — extends fixpoint with TFunEff case (union of argument/return free regions + R_in + R_out). - `is_linear_ty` (catch-all `_ => false`) — automatically false for TFunEff. No change needed. ## What's NOT in this PR - Typing rules `T_Lam_L1_*_Eff` / `T_App_L1_Eff` → slice 2 - Preservation closure for lambda-rigidity → slice 3 - Phase B + Phase C re-attempt → slice 4 ## Test plan - [x] `coqc 8.18.0` clean rebuild — 10/10 .v files Qed (no proof regressions) - [x] Zero new Admitted / Axiom (per CLAUDE.md directive) - [x] No legacy Semantics.v / Typing.v judgment patching (only fixpoint extended for new case) - [ ] Slice 2 to follow once this lands 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 7a64296 commit 570ee45

2 files changed

Lines changed: 36 additions & 10 deletions

File tree

formal/Syntax.v

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,28 @@ Inductive ty : Type :=
6060
Observation discipline is modality-dispatched at the typing-
6161
rule boundary, not encoded in the type — see
6262
[formal/PRESERVATION-DESIGN.md §6.3] and [formal/Echo.v]. *)
63-
| TEcho : ty -> ty.
63+
| TEcho : ty -> ty
64+
65+
(** L2 Phase 2 / Phase D slice 1 — Effect-typed function former.
66+
[TFunEff T1 T2 R_in R_out] is the type of a function from [T1]
67+
to [T2] whose body requires the region environment [R_in] on
68+
entry and produces [R_out] on exit. The legacy [TFun T1 T2] is
69+
preserved (per CLAUDE.md owner directive 2026-05-27 — its
70+
falsity in conjunction with `preservation` is load-bearing for
71+
`Counterexample.v`); new code uses [TFunEff] to expose lambda
72+
bodies' R-flow at the type level.
73+
74+
Closes the structural-blocker root cause: at function-call
75+
sites, the body's region requirements become visible to
76+
preservation reasoning, unblocking the lambda-rigidity admit
77+
at `Semantics_L1.v:1694` and naturally enabling
78+
body-input-shrinkage for the Phase C list-vs-multiset bridge.
79+
80+
Slice 1 (this PR): syntax-only landing. Typing rules
81+
(`T_Lam_L1_*_Eff` + `T_App_L1_Eff`) ship in slice 2. Per the
82+
L3 wiring playbook (slices 1→4) this is the lightest landable
83+
shape. *)
84+
| TFunEff : ty -> ty -> list region_name -> list region_name -> ty.
6485

6586
(** ** Expressions *)
6687

formal/Typing.v

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,20 @@ From Ephapax Require Import Syntax.
5454

5555
Fixpoint free_regions (T : ty) : list region_name :=
5656
match T with
57-
| TBase _ => []
58-
| TString r => [r]
59-
| TRef _ T' => free_regions T'
60-
| TFun T1 T2 => free_regions T1 ++ free_regions T2
61-
| TProd T1 T2 => free_regions T1 ++ free_regions T2
62-
| TSum T1 T2 => free_regions T1 ++ free_regions T2
63-
| TRegion r T' => r :: free_regions T'
64-
| TBorrow T' => free_regions T'
65-
| TEcho T' => free_regions T'
57+
| TBase _ => []
58+
| TString r => [r]
59+
| TRef _ T' => free_regions T'
60+
| TFun T1 T2 => free_regions T1 ++ free_regions T2
61+
| TProd T1 T2 => free_regions T1 ++ free_regions T2
62+
| TSum T1 T2 => free_regions T1 ++ free_regions T2
63+
| TRegion r T' => r :: free_regions T'
64+
| TBorrow T' => free_regions T'
65+
| TEcho T' => free_regions T'
66+
| TFunEff T1 T2 R_in R_out =>
67+
(** Phase D slice 1: free regions of [TFunEff] include those of
68+
the argument and return types AND the input/output region
69+
environments that annotate the body's R-flow. *)
70+
free_regions T1 ++ free_regions T2 ++ R_in ++ R_out
6671
end.
6772

6873
(* Note: We don't need a separate determinism lemma for free_regions

0 commit comments

Comments
 (0)