docs: specify contract names and diagnostic witnesses

This commit is contained in:
dev committed 2026-10-09 16:44:08 +03:00
1 parent 8df6cacf12
commit 5ed0d86e36
7 files changed
+472 -3

No files matched your search

+19 -1
View File
@@ -93,7 +93,25 @@ Map the new rules into existing stages: limits first; prefix order/entry predece
Candidate new codes are E8001 `contract.invalid_binding` (snapshot escape/unused/document-only snapshot with stable reason), E8002 `contract.predicate_not_pure`, E8003 `contract.predicate_not_stable`, and T0011/T0012/T0013 for false runtime pre/post/invariant. None is allocated here; adopting E8xxx also requires a new family entry in spec 10 and the error registry. Existing signature/type errors use E1001, structural errors E5002, limits E5101 and missing unsafe boundary E6001. Source-decided errors follow spec 15 §10's E7xxx policy; semantic new codes retain source provenance. A purity witness must contain real helper/type/op facts, with bounded length and explicit truncation, not invented locations.
At ret, virtual clause checks run before ownership return transfer and leak checks. They cannot resurrect consumed inputs or inspect a parent frozen by an exclusive result. Errors from that stage retain the existing (line, col, code) order. Specify collection when both access and leak errors occur before treating this as a complete ordering rule; a sort key cannot recover a diagnostic suppressed by an early return.
### Collection at returns
For a contracted ret, retain the body state before return transfer. Run the ordinary return check on isolated working state, keeping its existing diagnostics and early-return/leak behavior. Track failure of the returned operand's availability, transfer access or declared borrow origin separately from resource/borrow leaks; do not infer that flag by parsing a diagnostic message. If return legality failed, suppress virtual post access checks at this ret: the invalid returned boundary is not a usable clause observation. Keep every ordinary diagnostic that today's return check would emit, and continue other independently valid returns.
Otherwise check every installed post in prefix order against the original pre-transfer body state, using isolated temporary view/state bookkeeping for each. Isolation includes borrow/loan state, transfer summaries and emitted verifier events; commit ordinary return facts/events only once, and discard synthetic temporary-view events after each virtual check. A failed clause cannot leave synthetic live borrows or suppress a later clause or the ordinary leak records. Type/P rules ensure these helpers cannot permanently mutate caller state, so successful sequential predicates have the same available roots. This is static legality collection, not runtime execution of later predicates after a trap. Runtime still stops at the first failing predicate. Finally merge ordinary and virtual facts using the existing AIR (line,col,code) order; source mapping retains existing one-per-code/source-location selection. Contract-free returns use today's path unchanged.
Current baselines at `8df6cac`: a wrong-origin borrow return with an unrelated live owner emits only E2102, while a valid-origin or scalar return retaining that owner emits E3002. Returning an already taken owner emits E2002. Returning an owner with a live child view emits both E2101 and E2105: the current return check kills the root after reporting its transfer conflict, then reports the view leak. Do not replace this with an invented first-error-only return contract. Future vectors must pair an otherwise valid ret's unavailable post root with an unrelated leak, proving both survive; a return-legality failure must preserve the baseline list and suppress dependent post errors. These are proposed collection rules, not an implemented post checker.
### Purity/stability witnesses
Complete ordinary type validation first. Compute P and then S membership once over the direct-call graph, including unreachable instruction/call sites. For each locally inadmissible function select its first seed in this fixed order: declared effects, trusted metadata, header/block-parameter types in declaration order, then instruction type operands/results before opcode in textual block/instruction order. Each seed names its real function/type/op position. Required predicate roots outside P report E8002; if any such root fails, stop the types stage before required S-root checks. Ordinary functions outside P do not reject unless a contract requires them. After all required P roots pass, S uses published stable classifications and required roots outside S report E8003. No source annotation or proof result substitutes for either closure.
Use a reverse-edge multi-source BFS to give each excluded function its minimum number of call edges to a local seed. Resolve ties after distances are known: select the first textual call site leading to distance minus one. A distance-zero function keeps its first local seed even if it also calls another invalid helper. Recursive components with no local failure remain admitted; a component reaching a seed is excluded. The selected witness edges strictly decrease distance, so a witness never loops. Propagate the terminal fact and bounded path summaries in increasing distance order. BFS/local scans cost O(F+C); retaining the first/last 16 edges per excluded function adds at most 32F position copies, not a fresh graph traversal per clause.
Candidate E8002/E8003 fields are `predicate,reason,witness`. Predicate is the referenced AIR name without @; reason is the terminal seed category, independently of prose. Witness field order is `call_count,prefix,suffix,omitted_calls,terminal`. For at most 32 calls, prefix contains every call and suffix is empty. For a longer path, prefix is its first 16 and suffix its last 16; omitted_calls is call_count minus 32 and represents the gap between them. Terminal is always retained. This bounds witness positions, not the size of arbitrary input names/type strings. A malformed/unreachable callee has already failed ordinary validation and is not an invented seed.
Each call record is `function,block,inst,callee,source`, in that order, with exact zero-based AIR instruction identity and source `{file,line,col}` or null. Terminal is `function,block,inst,reason,type,operation,source`; header seeds have null block/inst, unused fact fields are null, and reason is effects/trusted/type/operation. Operation is the actual canonical opcode, not a suggested repair. Source positions use the exact lowering map; missing maps stay null. The primary diagnostic belongs to the clause/checked-type use that requires the predicate. Witness positions identify the callee chain and terminal fact independently, preserving real imported/template locations. This is a candidate typed field extension; no code/field registry is allocated here.
The [diagnostic vectors](contract-diagnostic-vectors.json) retain the five executed return baselines and proposed graph cases for recursion, shortest-path/tie selection and a 40-edge witness with eight omitted calls. Graph/vector checks validate the candidate algorithm and metadata, not a new compiler diagnostic. Required vertical tests additionally cover several clauses sharing a seed, unreachable calls, duplicate source mappings, invalid types preceding purity, constant-true predicates with forbidden unused operations, and leak/access collection at several returns.
Emit the proposed additive `contracts` section only for modules declaring the relevant feature; contract-free canonical report bytes stay unchanged. Each row identifies function/block/instruction, helper, kind, scope (`boundary` or persistent `value`), status, proof and enforcement, plus covered return sites and positions. A pre row belongs to the callee declaration, not a selected caller. A type guarantee and a relation over listed functions require distinct scopes. Include per-status site totals; totals are not sums over executions or returned branches. Snapshot metadata is not itself a truth obligation. Rejected modules still produce diagnostics and no audit document.