verifier: preserve resource obligations across CFG handoff

This commit is contained in:
dev committed 2026-10-08 17:17:08 +03:00
1 parent 0e98638bc6
commit 09fbf8a5bc
34 files changed
+1267 -67

No files matched your search

+3 -1
View File
@@ -169,4 +169,6 @@ Q-048 source access modes (cl100k): Quick Reference stays 8,948; other source do
DD-022 grammar surface (cl100k): Quick Reference stays 8,948; other source docs 67,343 → 68,219 (+876), full source 76,291 → 77,167 (+1.15%). o200k groups are 8,984 / 68,422 / 77,406; Qwen2.5 9,226 / 69,887 / 79,113. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Existing syntax and ordered parsing choices replace incomplete grammar descriptions. Empty qualified enum payload lists now reject E7001; accepted public-source canonical AIR is preserved. No new programming concept, feature, diagnostic code or verifier/runtime state is added. The grammar stays a reference read on demand; no empirical MCC benefit is claimed.
Q-051 source effect names (DD-023, cl100k): Quick Reference 8,948 → 8,955 (+7); other source docs 68,219 → 68,323 (+104), full source 77,167 → 77,278 (+0.14%). o200k groups are 8,991 / 68,526 / 77,517; Qwen2.5 9,233 / 69,994 / 79,227. AIR grows 47,445 → 47,458 (+13), 184,628 → 184,678 bytes, through the shared E7002 registry description; library/std.md is unchanged. Unknown effects use existing E7002 with structured `name`/`effect`, replacing erroneous source E7900 or E0006. Accepted canonical AIR and authority/effect semantics are preserved. No new concept, syntax, code/reason, feature or verifier/runtime state is added; no empirical MCC benefit is claimed.
Q-051 source effect names (DD-023, cl100k): Quick Reference 8,948 → 8,955 (+7); other source docs 68,219 → 68,323 (+104), full source 77,167 → 77,278 (+0.14%). o200k groups are 8,991 / 68,526 / 77,517; Qwen2.5 9,233 / 69,994 / 79,227. The AIR copy in the source bundle grows 47,445 → 47,458 (+13); canonical AIR bundle bytes grow 184,628 → 184,678, through the shared E7002 registry description; library/std.md is unchanged. Unknown effects use existing E7002 with structured `name`/`effect`, replacing erroneous source E7900 or E0006. Accepted canonical AIR and authority/effect semantics are preserved. No new concept, syntax, code/reason, feature or verifier/runtime state is added; no empirical MCC benefit is claimed.
Q-052 CFG resource provenance (DD-024): Quick Reference and other/full source docs remain 8,955 / 68,323 / 77,278 cl100k (o200k 8,991 / 68,526 / 77,517; Qwen2.5 9,233 / 69,994 / 79,227); std is unchanged. Canonical AIR grows 184,678 → 185,220 bytes and 47,385 → 47,476 cl100k (+91), 47,540 → 47,631 o200k (+91), 48,917 → 49,009 Qwen2.5 (+92). The separately wrapped source-bundle AIR copy grows 47,458 → 47,549 cl100k. The added sentences clarify preservation of existing task/scope, guard and shield obligations through block arguments. No new agent concept, syntax, feature or diagnostic is introduced. Sparse implementation relations replace incomplete SSA metadata; verifier acceptance now enforces existing safety rules. No empirical MCC benefit is claimed.
+12
View File
@@ -143,3 +143,15 @@ Q-050 corrects empty parentheses on qualified enum variants, contrary to spec 15
Q-051 validates ordinary effect names before body lowering using the existing closed registry. Templates/static contracts use the same E7002 with `name` and `effect`; legacy E0006 without a feature reason was incorrect. Function/template positions remain declaration starts, static contracts use their parameter start. Ordinary parameter/return/from checks retain priority; existing template/header ordering remains. Unknown effects cannot generate malformed AIR or E7900. AIR E0004 and its registry contract are unchanged.
Only invalid-source codes/priority/fields change. Registered effects, explicit authority, effect coverage, duplicate-list set semantics and static-contract uniqueness remain unchanged; no code, reason, syntax, AIR feature, verifier/runtime or ownership/concurrency state is added. Positive/rejected source tests and CLI/package tests cover headers, unused declarations, priority, missing-effect/capability diagnostics, formatting and source/AIR execution. Budget growth is measured in docs/agent/README.md. This completes this diagnostic correction, not P6-2 or an empirical MCC claim.
## DD-024 — Resource obligations survive SSA handoff
Q-052 corrects the verifier's loss of task loans/scopes, guard parents and shield order at block parameters. The preserved invariants are no ending or conflicting access to a loan before its task is joined, no live child at scope completion, no ending a mutex borrow while its guard lives, and properly nested shields. Spec 04 clarifies the already permitted function-local transfer; no AIR feature or new semantic restriction is introduced.
The verifier records static definition/consumption events, solves sparse relations over the CFG to a fixed point, then checks instructions in the existing diagnostic order. Edge transfer renames both positions simultaneously: a scope association follows the scope even if its task is not passed. This preserves correlated permutations of scopes and tasks; independent origin sets would reject valid code. Task/loan/guard alternatives join by union, while the existing shield-stack equality rule is checked separately. Definition sites retain diagnostic spawn positions. The collecting walk excludes relational error recovery; extra facts about subsequently rejected/dead resources are filtered by final liveness. Functions without these resource types retain one walk.
Valid: forward a task and its scope, join the renamed task, then end the renamed scope; end renamed shields inner first; unlock a renamed guard before ending its mutex borrow. Rejected: end the lent borrow or store through its exclusive loan before joining the forwarded task; end a forwarded scope with a live child; end the guard's parent borrow; end the outer forwarded shield first. Source/AIR conformance fixtures cover these cases, cancelled joins, joins with different loan origins, loops and correlated scope/task permutations.
Diagnostic impact: the existing E4302/E4101/E4301/E2102/E4305/E3002 rules now apply after handoff. A transferred live child reports E4301 in preference to E3002. E4302 identifies the current handle and the original spawn. Incompatible shield stacks report E3002 with a shield identity; a subsequent wrong end can also report E4305. New codes, reasons and repairs are unnecessary.
Runtime and deterministic interpreter behavior are unchanged: transfer already moves the same resource, and a cancelled join already returns the same task. Compatibility changes only for violations formerly accepted, or reported with a generic leak after provenance was lost; valid lowering remains unchanged. Counted rotation tests bound fixed-point visits, scheduler/collection tests cover execution, and CLI tests cover exact source/package/generic positions and canonical AIR. Bundle growth is recorded in docs/agent/README.md. This strengthens verification without claiming an empirical MCC improvement or completing P6-7.
+6
View File
@@ -374,3 +374,9 @@ The parser accepted `E::Empty()` and the corresponding match pattern, although s
An ordinary function declaring `effects [bogus.effect]` reaches AIR and reports E7900 with `air_code: E0004`; templates/static contracts reject the same known-invalid effect directly with E0006. Effect membership is determined entirely from source and the registry. A P6-2 task should align ordinary signature validation with the existing template contract, preserving effect/capability semantics and checking diagnostic priority/positions. No implementation is included in DD-022.
**Resolved (DD-023, spec 15 §9):** ordinary signatures validate the existing effect registry before body lowering; templates/static contracts replace the incorrect E0006 with E7002. Fields `name` and `effect` identify the atom without prose; locations retain declaration/parameter starts. Signature/type/from and template/header priority, accepted AIR, effect/capability semantics and AIR E0004 are preserved. Invalid-source diagnostics can change; no new code or reason.
## Q-052 — Resource provenance through CFG parameters
P6-7 rejection-twin work reproduced accepted source that returns the cancelled handle from an inner block, ends its lent borrow at that block's exit, then joins the renamed handle. Ordinary AIR `br` has the same defect: loans and creating scopes remain attached to the moved SSA value. Review also reproduced lost guard parents and shield order. These violate existing spec 04 §33–§34, §37.3 and §40; they are verifier bugs, not missing transfer semantics.
**Resolved (DD-024):** resource relations follow simultaneous edge renaming, with a finite worklist covering later predecessors and backedges. Loans retain the creating spawn; tasks retain scope associations even when only the scope is passed. Guard parents and ordered shield relations survive handoff. Task/guard facts merge by union; shield stacks retain their existing exact join requirement. Existing codes E4302/E4101/E4301/E2102/E4305/E3002 apply. Valid correlated scope/task permutations and joins remain accepted. Runtime, source lowering and AIR format-0 meanings are unchanged; previously accepted violations now reject.
+6
View File
@@ -303,3 +303,9 @@ Validation: units and Zig formatting pass; full conformance is 1,594/1,594, and
DD-023 resolves Q-051: ordinary effect declarations validate the existing registry after signature types/from and before body lowering. Templates/static contracts replace incorrect E0006 with E7002; `name` and `effect` identify the atom. Declaration/parameter positions and prior signature/template check order remain. Registered atoms, flat effect sets, static-contract uniqueness, effect coverage, explicit capabilities and AIR E0004 remain unchanged. No new code/reason, syntax, feature, verifier/runtime, ownership/concurrency or evaluation input changes.
Validation: units and Zig formatting pass; full conformance is 1,618/1,618, and all 24 new fixtures pass collection before every instruction. CLI integration passes 236 checks, including unused/package headers, diagnostic priority, formatter preservation, source/AIR execution, instantiation and independent AIR rejection. Existing generic/static-function/grammar suites pass 32/25/288 checks. Old/new comparison on 1,303 public sources (709 old lowerings) changes only the two corrected E0006 fixtures, preserving their primary positions and `name`; accepted AIR is byte-identical. Claude independently reviewed the change and ran units/fixtures and all 236 CLI checks. Bundle growth is recorded in docs/agent/README.md; P6-2 remains open.
## P6-7 CFG resource-provenance correction (2026-10-08)
Rejection-twin work exposed accepted source that ended a task loan after cancelled-handle transfer through a block parameter. DD-024 resolves Q-052: task loans/scopes, guard parents and shield order now follow simultaneous CFG transfers, with a fixed point for later predecessors and backedges. Existing concurrency invariants and diagnostic codes apply; interpreter behavior and valid source lowering are unchanged. This enforces existing AIR format-0 rules, with no new source concept, syntax or feature.
Validation: units and Zig formatting pass; full conformance is 1,642/1,642. All 24 new AIR/source fixtures pass schedule stress and collection before every instruction. A counted 63-handle rotation test verifies convergence and retained spawn provenance. CLI integration passes 146 checks, including exact source/package/generic positions, three loan rejection twins and both correlated scope/task permutations; existing related-location and lifetime suites pass 349/188 checks. Old/new comparison changes zero diagnostics on 1,327 existing public sources and 338 AIR files, preserving all 715 old source lowerings. Claude wrote independent regressions and reviewed the implementation with additional loop/permutation/cancellation probes. Source bundle size is unchanged; AIR growth is recorded in docs/agent/README.md. The exhaustive rejection-twin inventory and P6-7 remain open.
+6
View File
@@ -506,6 +506,8 @@ Depends on `ownership`.
**Function-bound.** A `scope` or `task<T>` may be passed between blocks of the function that created it (as a block argument) and used by `task.*`. It may not be a function parameter, a return type, an aggregate member, or stored in heap or region memory; those uses belong to the reserved feature `task_transfer` (`E0006` reason `feature_not_declared`). Keeping handles in their function keeps loans intraprocedural (invariant 6).
Passing block arguments MUST preserve each task's creating scope and outstanding loans; the creating spawn remains diagnostic context (§34). Arguments are transferred simultaneously: renaming a scope also renames its association with tasks that remain live. Verification covers every incoming edge, including backedges; SSA renaming does not discharge an obligation.
**Result type.** `task<T>` requires `T: Send`, and `T` must not transitively contain a borrow, a `scope` or a `task<…>`. A spawned function returning a borrow (for example one derived from a lent argument) belongs to the reserved feature `task_borrow_returns` (`E0006`): after `join`, whether the loan ends or continues as the returned borrow is deliberately left undefined in format 0.
### 33.2 Instructions
@@ -696,6 +698,8 @@ cancelled(%t2: task<u64>):
`shield` is linear, function-bound (§33.1) and `Local`. The stack of live shields is part of the verifier state and MUST be identical on every edge into a block (`E3002`); every shield is ended before `ret` (`E3002`). Shield depth is dynamic per task, so a function called inside a shield runs shielded.
Block-argument transfer preserves shield order.
```text
%a = task.shield.begin
%b = task.shield.begin
@@ -811,6 +815,8 @@ Decision record: RFC 0012. Depends on `cancellation`. `RwLock` is deferred (rese
No fairness is promised (§32). There is no poisoning and no implicit unlock; an unconsumed guard is `E3002`.
Block-argument transfer preserves the association between a live guard and the mutex borrow through which it was obtained.
`mutex<T>` is always linear and never copyable, whatever `T` is; `mutex.take` is the only way to dismantle it. It requires that no borrow of the mutex is live. A guard is a child of the `ref<mutex<T>>` it was locked through (ending that borrow while the guard lives is `E2102`), and a task waiting in `mutex.lock` holds such a borrow, so no guard and no waiter can exist at `mutex.take`. Afterwards the mutex is dead, by the ordinary rules for a dismantled linear value (as after `own.take`): a further use is `E3001` and a further consumption `E2002`.
## 41. The critical-section rule