Skip to content

Commit 157f282

Browse files
committed
docs(P-037): G-V4 closed over write-capable aliasing — the ref-local hole
Arbiter follow-up on the G-V4 amendment (REQUEST CHANGES, one narrow P1): the "cheapest sound test" was written as a list of direct write spellings, and C# ref-locals walk around lists — `ref bool a = ref g; a = !a;` mutates `g` with `g` never on the left of an assignment, never passed ref/out, and no capture in sight. A literal implementation would have judged g stable, kept the id edge, and fabricated the exact must G-V4 exists to forbid; the self-null variant (`ref Stream a = ref q; a = replacement;`) would dispose a different object than the caller's argument. G-V4 is now defined over the ABSENCE OF WRITE-CAPABLE ALIASING/EXPOSURE, with the spellings as instances, not the definition: direct writes; byref exposure (ref/out passing; writable ref-local creation or ref-assignment — creation ALONE disqualifies, fail-closed, no alias tracking); captures; and any address/byref escape the extractor cannot prove read-only (in / ref readonly stay eligible only where provably no writable alias arises — no presumption of good behavior for unrecognized shapes). §8: row 18 gains the alias twin as variant (b); new row 19 pins the writably-aliased self-null resource; the closing note names the three independent negative-control families the discharge matrix must carry (own-body writes vs election; wrapper write/alias vs id/neg; self-null write/alias vs G-S3). §9 wall updated (no alias tracking); status note records the follow-up round. Refs #304. Addresses the arbiter's ref-alias P1 on #307. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015de4MezSeUnZBoWq1fFU5M
1 parent 9c6c652 commit 157f282

1 file changed

Lines changed: 52 additions & 32 deletions

File tree

‎docs/proposals/P-037-guarded-effect-summaries.md‎

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ Status: **accepted — design contract, frozen** (arbitrated and accepted at
55
and the P-022 verdict-changing freeze applies until then. A design re-review
66
is not required for implementation; the proof obligations of §7/§8 are
77
discharged by the implementation PR's tests). **Amended post-acceptance:**
8-
G-V4 entry-value stability (Codex P1 on #307, §2/§8 row 18) — a soundness
9-
*precondition* on guard eligibility and `id`/`neg` edges, closing the mutable-
10-
parameter hole; no architectural decision of the accepted contract changes.
8+
G-V4 entry-value stability (Codex P1 on #307 + the arbiter's ref-alias
9+
follow-up; §2, §8 rows 18–19) — a soundness *precondition* on guard
10+
eligibility, `id`/`neg` edges, and the self-null split, defined over the
11+
absence of write-capable aliasing/exposure (fail-closed on ref-local
12+
creation), closing the mutable-parameter hole; no architectural decision of
13+
the accepted contract changes.
1114

1215
Related work:
1316

@@ -89,29 +92,40 @@ without touching the precision floor.
8992
being summarized — never fields, locals, globals, or the caller's variables.
9093
A local initialized from a parameter is a local (the laundering case stays
9194
honest: no claim; cross-ref audit attack C).
92-
- **G-V4 (entry-value stability — a soundness precondition, Codex P1 on
93-
#307).** Guard semantics are defined over the parameter's **entry value**,
94-
but a C# parameter is a mutable local. Eligibility therefore requires
95-
provable stability, with the cheapest sound test — an assignment anywhere
96-
disqualifies:
97-
- a guard variable must be a **by-value parameter that is never assigned**
98-
in the body (no assignment, compound assignment, or increment; never
99-
passed `ref`/`out`; not mutated through a capture). A violated guard
100-
variable is **ineligible**: its literals elect nothing and actions under
101-
them derive as today (both cells);
102-
- the self-null split (G-S3) additionally requires the **resource parameter
103-
itself** to be unassigned — a reassigned `q` would make the summary's
104-
`must` claim dispose a *different* object than the caller's argument;
105-
- `id`/`neg` transforms (G-S5) are recognized only when the forwarded
106-
argument is the bare unassigned parameter (or a single `!` of one);
107-
anything else — including `g = !g; Inner(p, g);`, which is *syntactically*
108-
an identity forward of `g` — degrades the edge to `opaque`.
109-
Without this rule, `Outer(p, true) { g = !g; Inner(p, g); }` would select
110-
`Inner`'s positive cell while `Inner` actually receives `false` — a
111-
fabricated `must` that can suppress a real leak and charge false
112-
use-after-dispose, exactly what G-T1 forbids. Whole-body unassignment is
113-
deliberately coarser than entry-SSA tracking (§9): it can only lose
114-
precision, never soundness.
95+
- **G-V4 (entry-value stability — a soundness precondition; Codex P1 on
96+
#307, closed over write-capable aliasing in the arbiter's follow-up).**
97+
Guard semantics are defined over the parameter's **entry value**, but a C#
98+
parameter is a mutable local. Eligibility therefore requires that the
99+
parameter's storage is **never directly or indirectly writable after
100+
entry** — the test is the absence of *any write-capable alias or
101+
exposure*, not a list of assignment spellings. Disqualifiers:
102+
- **direct writes**: assignment, compound assignment, increment/decrement;
103+
- **byref exposure**: passing the parameter `ref`/`out`; creating a
104+
writable ref-local over it (`ref T alias = ref g;`) or ref-assigning one
105+
to it — a ref-local is an alias of its referent and a write through it
106+
writes the referent, so the alias's **creation alone** disqualifies
107+
(fail-closed; no alias tracking is attempted);
108+
- **captures**: mutation through a lambda / local-function capture;
109+
- **anything unproven**: an address/byref escape the extractor cannot
110+
prove read-only disqualifies. `in` / `ref readonly` forms remain
111+
eligible only where no writable alias provably arises; an unrecognized
112+
shape gets no presumption of good behavior.
113+
A disqualified guard variable is **ineligible**: its literals elect
114+
nothing and actions under them derive as today (both cells). The
115+
self-null split (G-S3) applies the same test to the **resource parameter
116+
itself** — a reassigned or writably-aliased `q` would make the summary's
117+
`must` claim dispose a *different* object than the caller's argument.
118+
`id`/`neg` transforms (G-S5) are recognized only when the forwarded
119+
argument is the bare *stable* parameter (or a single `!` of one);
120+
anything else — including `g = !g; Inner(p, g);` and its alias twin
121+
`ref bool a = ref g; a = !a; Inner(p, g);`, both *syntactically* identity
122+
forwards of `g` — degrades the edge to `opaque`.
123+
Without this rule either spelling would select `Inner`'s positive cell
124+
while `Inner` actually receives `false` — a fabricated `must` that can
125+
suppress a real leak and charge false use-after-dispose, exactly what
126+
G-T1 forbids. Whole-body write-exposure testing is deliberately coarser
127+
than entry-SSA / alias tracking (§9): it can only lose precision, never
128+
soundness.
115129

116130
## 3. The guarded-transfer lattice (G-L)
117131

@@ -466,13 +480,18 @@ Notation: `S = Split(g, pos, neg)`; call-site column shows the applied effect.
466480
| 15 | **overload/election ordering:** sig-keyed summary (roadmap stage 2) elects `Split`; the name-merged fallback group contains a differing election | G-F3: the merge collapses every side to `Uncond` first, then joins — deterministic, pre-solver; the precise `sig`-keyed summary keeps its split where the call carries a `sig` | `sig`-resolved site | per-cell verdicts; name-fallback site: today's behavior |
467481
| 16 | **forward-grounded residual ⊥:** `F(p, g){ if (g) MustSink(p); else F(p, g); }` | guarded lfp `(must, ⊥)` → fin `(must, no)` → collapse `may`; today `[forward MustSink, forward F, borrow]` → `may`. Equal — the residual-⊥ lemma's branch 2 pin (grounded forward on the other side; distinct from row 14's local-release shape) | unknown site | plain + OWN051; `F(p, true)` selects `must` → `consume` |
468482
| 17 | **`None`-coordinate refined through `const-pos`:** `Outer(Resource p){ Inner(p, true); }`, `Inner = Split(g, must, no)` | `Outer` elects `None` (its domain is plain `Transfer`) yet its `const-pos` edge reads `Inner`'s positive cell ⇒ `Outer = Uncond(must)`; today `may` forwards into `may`. The summary-refinement class reaching a split-free coordinate — pins that election does not bound where refinement can flow | any `Outer` site | `consume` |
469-
| 18 | **mutated guard (negative control, G-V4):** `Outer(Resource p, bool g){ g = !g; Inner(p, g); }`, `Inner = Split(g, must, no)` | `g` is assigned ⇒ not entry-value stable ⇒ the edge is `opaque`, reading `join(must, no) = may`; `Outer` gets today's behavior. Without G-V4 the *syntactic* identity forward would select the positive cell while `Inner` receives the negation — a fabricated `must` (the Codex P1). Same wall pins a reassigned self-null parameter | `Outer(p, true)` | plain + OWN051 (today) — never `consume` |
483+
| 18 | **mutated guard (negative controls, G-V4):** (a) `Outer(Resource p, bool g){ g = !g; Inner(p, g); }`; (b) the alias twin `Outer(Resource p, bool g){ ref bool a = ref g; a = !a; Inner(p, g); }` — `Inner = Split(g, must, no)` | (a) direct write, (b) writable ref-local creation — either disqualifies `g` ⇒ the edge is `opaque`, reading `join(must, no) = may`; `Outer` gets today's behavior. Without G-V4 both *syntactic* identity forwards would select the positive cell while `Inner` receives the negation — a fabricated `must` (the Codex P1 and its ref-alias twin) | `Outer(p, true)` | plain + OWN051 (today) — never `consume` |
484+
| 19 | **writably-aliased self-null resource (negative control, G-V4):** `Close(Stream q, Stream r){ ref Stream a = ref q; a = r; if (q != null) q.Dispose(); }` | no direct `q = …`, but the writable alias disqualifies `q` ⇒ no self-null split ⇒ today's derivation (`may`): the summary never claims `must` over the caller's argument while the body may dispose a *different* object | any | plain + OWN051 (today) — never `consume` |
470485

471486
Each row is a fixture family for #304's conformance vectors; rows 1–3 are the
472487
summary-level twins of the corpus cases #305 landed, and must agree with them;
473-
rows 11–18 pin the election lattice, both declared refinement classes
488+
rows 11–19 pin the election lattice, both declared refinement classes
474489
(application and summary), residual-⊥ lemma branches 1–2, and the G-V4
475-
stability wall. The discharge
490+
stability wall. The G-V4 discharge matrix must carry **three independent
491+
negative-control families**: (1) direct/compound/increment/capture writes —
492+
own-body election forbidden; (2) wrapper guard write or writable alias —
493+
`id`/`neg` forbidden (row 18 a/b); (3) reassigned or writably-aliased
494+
self-null resource — G-S3 forbidden (row 19). The discharge
476495
matrix must additionally carry a **dedicated machine-checked fixture for
477496
lemma branch 3** (the pure-ungrounded shape: both cells residual-⊥, today's
478497
solve residual-⊥, both finalize `no` identically) — an arbitration
@@ -489,9 +508,10 @@ cases stop being obvious after refactorings.
489508
importers wholesale (G-S1); recovering wrapper precision through per-edge
490509
provenance is a possible later refinement *behind the same lattice*, not
491510
part of this contract;
492-
- no SSA / entry-value tracking: G-V4 stability is the whole-body
493-
unassignment test — an assignment anywhere disqualifies the parameter,
494-
even when it happens after every guarded action; per-path or SSA-grade
511+
- no SSA / entry-value / alias tracking: G-V4 stability is the whole-body
512+
write-exposure test — a direct write, or the mere *creation* of a writable
513+
ref-alias, anywhere in the body disqualifies the parameter, even when it
514+
happens after every guarded action; per-path, SSA-grade, or alias-tracked
495515
stability is a later refinement behind the same rules;
496516
- no symbolic execution, no path conditions, no SMT;
497517
- no per-call-site summary specialization (the summary stays one object; only

0 commit comments

Comments
 (0)