@@ -36,15 +36,47 @@ repo*, one Rust crate, one AST, two structural disciplines. **`ephapax-affine`
3636is not AffineScript.** When ambiguous, write "ephapax-affine sublanguage"
3737vs "AffineScript language".
3838
39- Canonical disambiguation:
39+ Canonical disambiguation (read this before applying any cross-repo
40+ lesson):
4041link:https://github.com/hyperpolymath/nextgen-languages/blob/main/docs/disambiguation/ephapax-vs-affinescript.md[nextgen-languages/docs/disambiguation/ephapax-vs-affinescript.md].
4142====
4243
43- A dyadic linear+affine type system for compile-time WebAssembly
44- memory safety. Resources are tracked through the type system so the
45- compiler can guarantee — without a garbage collector — that no value
46- is used after being freed, no resource is leaked, and region-scoped
47- allocations are deallocated in bulk at scope exit.
44+ [WARNING]
45+ .🔄 Foundational redesign in progress — read `STATUS.adoc` before opening any `.v` file
46+ ====
47+ On 2026-05-26 a verified Coq counterexample
48+ (link:formal/Counterexample.v[`formal/Counterexample.v`], 5 Qed
49+ lemmas) showed that preservation as stated in the legacy typing
50+ judgment is **provably false**. The repo is in the middle of a
51+ *four-layer principled redesign* (regions / modality / echo / dyadic
52+ mode) where preservation is *re-derived per layer* from explicit
53+ invariants rather than forced through the old judgment.
54+
55+ Anything in this README dated before 2026-05-26 that describes a
56+ "preservation closure plan" or counts "910 → 22 → 12 open goals" is
57+ **archaeology, not instructions**. The authoritative status is in
58+ link:STATUS.adoc[`STATUS.adoc`] (past / present / future map),
59+ link:formal/PRESERVATION-DESIGN.md[`formal/PRESERVATION-DESIGN.md`]
60+ (four-layer architecture), and link:PROOF-NEEDS.md[`PROOF-NEEDS.md`]
61+ (per-sublanguage proof debt with explicit do-not-do list).
62+
63+ Quick read: **L1** (region capabilities) substantially complete;
64+ **L2** (Linear/Affine modality) core landed with zero axioms; **L3**
65+ (echo / residue) calculus done locally, integration into the typing
66+ judgment is the next-block work; **L4** (dyadic mode) not started.
67+ ====
68+
69+ Ephapax is a research language for **principled handling of
70+ irreversible boundaries** (region exits, drops, key erasure, audit
71+ trails) in compile-time-memory-safe WebAssembly. Real systems are
72+ irreversible — operating systems deallocate, databases drop tables,
73+ security systems erase keys, compilers collapse high-level
74+ distinctions. Ephapax gives a disciplined, machine-checkable
75+ framework to handle those boundaries responsibly: the type system
76+ tracks not just *what is owned* but *what was lost when it was given
77+ up*, so reclamation can carry mandatory evidence where it matters
78+ (audit, compliance, cryptographic erasure) and degrade to free where
79+ it doesn't (inference loops, hot paths).
4880
4981The core calculus is mechanically formalised. Soundness theorems on
5082the dynamic side (Coq) and structural-safety theorems on the type
@@ -95,6 +127,94 @@ Ephapax is a programming language with:
95127 reference counting, no allocator-per-object metadata.
96128|===
97129
130+ == Three superpowers
131+
132+ The L3 echo / residue layer (Ephapax's contribution to the four-layer
133+ design) opens three things proper reversible programming struggles
134+ with:
135+
136+ [cols="1,3"]
137+ |===
138+ | Superpower | What it gives you
139+
140+ | **A. Accountability of irreversible reclamation**
141+ | You can free memory (`S_Region_Exit`, `S_Drop`) and the type system
142+ *knows* you lost the data — and tracks what depended on it. Under
143+ the Linear modality the reclamation event carries a mandatory
144+ evidence-bearing `Echo` value; under Affine you opt out for
145+ performance. Pairs cleanly with region-based memory management
146+ (deterministic bulk free) to deliver high-assurance reclamation
147+ that tracing GC cannot — by design, tracing GC *hides* the
148+ reclamation evidence.
149+
150+ | **B. Selective reversibility (thin-poset)**
151+ | Linear ≤ Affine is a two-point thin poset at the L2 modality. You
152+ pick per-region (or per-project) which discipline applies. Same
153+ code shape, different evidence obligations. Concrete examples:
154+ *Linear* during backpropagation (must keep the gradient residue);
155+ *Affine* during inference (drop the residue, save memory). You get
156+ the safety of reversibility where you need it, and the performance
157+ of irreversibility where you don't.
158+
159+ | **C. Debugging + provenance**
160+ | Attach Linear Echoes to critical state changes. The type system
161+ guarantees the receipt (preimage) of that state change was retained
162+ — so when a bug fires, the inputs that produced the error are
163+ recoverable by construction. In Affine mode you opt out of this
164+ debugging info, with the same code shape. The evidence is a
165+ *theorem-level guarantee*, not a runtime convention.
166+ |===
167+
168+ [CAUTION]
169+ .Echo Types are NOT a tracing-GC replacement
170+ ====
171+ Echo Types do **not** solve reachability or cycles. They are not a
172+ "fire-and-forget" automatic memory manager. Their strength is
173+ *accountability of irreversible reclamation* in systems that already
174+ know when and how to deallocate (regions, explicit drop, deterministic
175+ ownership). Treating them as competition for mark-and-sweep or
176+ generational GC is a category error.
177+
178+ The committed v1 direction is *Linear Echo + Region-Based Memory
179+ Management* (deterministic bulk free with mandatory certified
180+ evidence). A speculative future direction is an optional Linear
181+ discipline on deterministic Rust-style drop for critical resources
182+ (keys, sensitive buffers requiring provable erasure) — flagged but
183+ not committed.
184+ ====
185+
186+ == What this enables
187+
188+ The three superpowers translate to concrete use cases the type
189+ system can *prove* properties about:
190+
191+ * **Mandatory evidence for critical actions.** By making certain
192+ echoes Linear (mandatory observation), the type system guarantees
193+ that a region exit *always* emits an audit trail, or that a drop
194+ *always* triggers a required cleanup.
195+
196+ * **GDPR "right to be forgotten" with certified evidence of
197+ erasure.** Linear-echo discipline on the `S_Drop` of a personal-data
198+ resource is a type-level proof that erasure happened *and* that the
199+ required notification / log was produced. Auditors get a
200+ machine-checkable artefact instead of a process attestation.
201+
202+ * **Verified resource management for keys, secrets, and sensitive
203+ buffers.** Linear-echo on the deallocation of a key buffer
204+ guarantees provable erasure; the typing rule cannot be silenced.
205+
206+ * **Selective reversibility without redesigning your language.**
207+ The thin-poset means you don't redesign the runtime to be
208+ bijective. You add *one* type former (the fiber) and layer
209+ existing L2 modalities over it. Orthogonal and compositional.
210+
211+ * **Machine-checkable foundation for policy enforcement.** The
212+ thin-poset Linear ≤ Affine + the proven non-invertibility
213+ (`EchoResidue.no-section-collapse-to-residue`) gives sharp,
214+ proof-relevant reasoning: *weakening obligations is allowed*,
215+ *strengthening them back is impossible*. Clean logical foundation
216+ for compliance work.
217+
98218== What this isn't
99219
100220* **Not Rust.** Rust uses ownership + borrowing with a single discipline
@@ -226,25 +346,46 @@ Two complementary formalisations, both run on every push:
226346=== Coq (`formal/`)
227347
228348Operational semantics with small-step reduction over a substitution-
229- based calculus. Proves dynamic properties (no stuck states, region
230- exits free everything, substitution preserves typing).
231-
232- Currently `Qed`-closed: `no_leaks`, `subst_preserves_typing`,
233- `typing_ctx_transfer`, `region_env_perm_typing`, `region_add_typing`,
234- `region_shrink_preserves_typing`, plus 70+ supporting lemmas.
235-
236- Currently `Admitted`: `preservation`. **12 open goals remain** after
237- the reduction chain — down from **910** at the start of the campaign
238- (98.7% reduction across PRs #92 / #102 / #104 / #106 / #114 / #116 /
239- #117 / #121, 2026-05-20 → 2026-05-21). Phase 1 scaffold of the
240- closure plan (Lemma B `step_output_context_eq`) landed; per-case
241- discharges next. The remaining 12 are 11 congruence cases (blocked
242- on Lemma B's per-case proofs — linearity-context drift between IH
243- and sibling) + 1 `S_Region_Step + T_Region_Active` case (blocked on
244- region-env weakening for non-values). Canonical closure path:
245- **`ROADMAP.adoc` §"Preservation closure plan"** (5 phases, ~3
246- sessions of focused work). See also `formal/PRESERVATION-HANDOFF.md`
247- for the per-case diagnostic record.
349+ based calculus. Post-2026-05-26 the formalisation is layered:
350+
351+ * **Legacy** (`formal/Semantics.v`, `formal/Typing.v`) — the original
352+ pre-discovery judgment. `Theorem preservation` here is **provably
353+ false** (the counterexample at `formal/Counterexample.v` is 5 Qed
354+ lemmas proving it). The `Admitted.` is correct. **Do not extend.**
355+ Treat as archaeology — see link:STATUS.adoc[`STATUS.adoc`] for the
356+ pre-discovery PR list and the explicit do-not-do reasoning.
357+
358+ * **Layer 1 — region capabilities** (`formal/TypingL1.v`,
359+ `formal/Semantics_L1.v`). The new judgment is modality-indexed
360+ (`has_type_l1 m : ...`) and threads a capability environment `R`
361+ through compound rules. Judgment 100% (0 admits, 2 Qed); semantics
362+ carries 9 supporting-lemma admits that are *L2-integration debt*
363+ (bullet-structure rewrites for new Affine-only constructors), not
364+ legacy patching.
365+
366+ * **Layer 2 — structural modality** (`formal/Modality.v`). Linear
367+ vs Affine as a K-free thin-poset decoration. `linear_to_affine`
368+ is **Qed with zero axioms**. Landed via PRs #176 + #177.
369+
370+ * **Layer 3 — echo / residue** (`formal/Echo.v`). 12 Qed lemmas
371+ covering the fiber calculus, degrade map, and the
372+ `no-section-collapse-to-residue` irreversibility theorem (mirrors
373+ the upstream Agda development at
374+ https://github.com/hyperpolymath/echo-types[`hyperpolymath/echo-types`]).
375+ Calculus is done; *wiring into the typing rules* (`T_Observe`,
376+ collapse-function emission on irreversible steps,
377+ `G`-context threading) is the next-block work.
378+
379+ * **Layer 4 — dyadic interaction**. Design in
380+ link:formal/PRESERVATION-DESIGN.md[`formal/PRESERVATION-DESIGN.md §7`].
381+ Not started.
382+
383+ Per-sublanguage proof debt with explicit do-not-do list lives in
384+ link:PROOF-NEEDS.md[`PROOF-NEEDS.md`]. The four-layer architecture
385+ rationale is in
386+ link:formal/PRESERVATION-DESIGN.md[`formal/PRESERVATION-DESIGN.md`].
387+ The counterexample itself is
388+ link:formal/Counterexample.v[`formal/Counterexample.v`] (5 Qed).
248389
249390[source,bash]
250391----
@@ -379,9 +520,25 @@ generics, effects, traits, comptime, contracts) lives on
379520| ✅ Qed
380521|
381522
382- | Coq `preservation`
383- | 🟡 Admitted (22 open / 910 closed)
384- | Multi-day proof-engineering campaign in flight
523+ | Coq legacy `preservation`
524+ | 🛑 Admitted — provably false
525+ | Counterexample at `formal/Counterexample.v` (5 Qed). Not closable. Archaeology.
526+
527+ | Coq L1 (region capabilities)
528+ | ✅ Judgment 100%; 🟡 semantics 9 admits
529+ | 9 admits = L2-integration debt. See `PROOF-NEEDS.md`.
530+
531+ | Coq L2 (modality)
532+ | ✅ Core landed (PRs #176 + #177); 0 axioms
533+ | `linear_to_affine` Qed. Integration debt absorbed by L1 admits above.
534+
535+ | Coq L3 (echo / residue calculus)
536+ | ✅ 12 Qed, 0 admits
537+ | Calculus done locally; integration into typing rules pending.
538+
539+ | Coq L4 (dyadic interaction)
540+ | 🔲 Not started
541+ | Design in `formal/PRESERVATION-DESIGN.md §7`.
385542
386543| Idris2 region-linearity theorems
387544| ✅ Complete (zero unsafe)
@@ -405,21 +562,41 @@ generics, effects, traits, comptime, contracts) lives on
405562| link:README.adoc[README]
406563| You are here. Overview + quickstart.
407564
565+ | link:STATUS.adoc[STATUS.adoc]
566+ | **Past / present / future map.** Single page that answers "where
567+ are we?" Read this before any `.v` file or any PR comment dated
568+ before 2026-05-26.
569+
570+ | link:PROOF-NEEDS.md[PROOF-NEEDS.md]
571+ | Per-sublanguage proof debt audit. What's done (Qed), what's todo,
572+ what's banned (anti-pattern detector). Separated for ephapax-linear
573+ and ephapax-affine sublanguages.
574+
575+ | link:formal/PRESERVATION-DESIGN.md[formal/PRESERVATION-DESIGN.md]
576+ | **Canonical four-layer design doctrine.** Why the counterexample
577+ forced the redesign, the four orthogonal concerns, per-layer plans.
578+
579+ | link:formal/Counterexample.v[formal/Counterexample.v]
580+ | The 5 Qed lemmas that pin the soundness gap of the legacy judgment.
581+ Authoritative source of the gap; future proofs must coexist with it.
582+
583+ | link:CLAUDE.md[CLAUDE.md]
584+ | Agent guidance. Carries the 2026-05-27 owner directive,
585+ anti-pattern detector, escalation rule.
586+
408587| link:EXPLAINME.adoc[EXPLAINME.adoc]
409588| "Show me the receipts" — every claim in this README backed by a
410589 specific file, test, or proof.
411590
412591| link:ROADMAP.adoc[ROADMAP.adoc]
413- | Quantitative milestones (v0.1.0 → v1.0.0), per-version checklists,
414- current open work.
415-
416- | link:PROOF-NEEDS.md[PROOF-NEEDS.md]
417- | Outstanding proof obligations: what's `Admitted` / `covering` /
418- `partial` and why.
592+ | Milestones (v0.1.0 → v1.0.0), per-version checklists, current open
593+ work. Note: any pre-2026-05-26 closure-plan content is superseded
594+ by STATUS.adoc + PRESERVATION-DESIGN.md.
419595
420596| link:formal/PRESERVATION-HANDOFF.md[formal/PRESERVATION-HANDOFF.md]
421- | Per-case checklist for the 22 remaining preservation goals. Read
422- this if you're picking up the Coq proof work.
597+ | **Archaeology only** — historical diagnostic record of the
598+ pre-counterexample closure attempts. Reads as a closure plan; isn't
599+ one. Useful only for understanding *why* the redesign happened.
423600
424601| link:RUST-SPARK-STANCE.adoc[RUST-SPARK-STANCE.adoc]
425602| Stance on Rust + SPARK interop and where Ephapax fits.
0 commit comments