diff --git a/docs/design/contract-accounting-and-status.md b/docs/design/contract-accounting-and-status.md index 9cd13ce..0cb5da0 100644 --- a/docs/design/contract-accounting-and-status.md +++ b/docs/design/contract-accounting-and-status.md @@ -85,7 +85,7 @@ Decision rules are closed: compare typed constants with their declared signednes Examples: a Data identity function whose every return is x can prove `result == old(x)` when old merely captures x. A second return of y prevents that classification. A constant Range representation or `{lo:x, hi:x}` can prove lo <= hi through shared field inspection. A pre over unrelated lo/hi remains runtime. `x + 0 == x`, hashing and mutation-based restoration remain runtime even when mathematically true. -Classification also needs an exact work bound. Candidate logical cost per record is helper operand-position work, relevant old-helper work only when used, reachable result/representation-origin DAG work, and boundary_count times the helper's normalized node count. Pre has one boundary and no body-origin work; adding unrelated body instructions cannot make a pre proof exceed its budget. Post/make inspect only their required origin DAG, charging each reachable definition once per record, including shared definitions across return sites. An instruction contributes one plus its operand positions; a normalized instruction produces at most one node. The proposed bound is 1,048,576 per record. Exceeding it, arithmetic overflow or an unsupported form yields proof none with a structured reason, without rejecting or weakening mandatory runtime enforcement. Cache helpers/origin DAGs, but count this logical cost independently of cache hits. Exact operand/node conventions and conformance vectors remain an integration gate; do not claim toolchain-independent PROVEN output until that rule is fully specified. +The [proof/report candidate](contract-proof-and-report.md) refines the work bound with exact opcode/node charges, binding-substitution positions, checked u64 counters and ordered fallback reasons. Pre has one boundary and no body-origin work; adding unrelated body instructions cannot make a pre proof exceed its budget. Post/make charge each required origin definition once per record, including shared definitions across return sites. The proposed bound is 1,048,576 per record. Excess, overflow or unsupported forms yield proof none without rejecting or weakening runtime enforcement; logical costs are independent of cache hits. The concrete candidate and its vectors await adoption and implementation rather than an implementation-dependent prover choice. ## Diagnostics and report @@ -97,4 +97,4 @@ At ret, virtual clause checks run before ownership return transfer and leak chec 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. -Required tests include max/sum activation cases, invalid descriptors before SSA, argument/work limits, all four modes, mixed executable/documented snapshot use, unsafe/trap/fuel behavior, multi-return and trap-only coverage, proof-budget fallback, old/current mutation counterexamples, callback/GC pending values, exact rejection ordering and identical contract-free report bytes. Predicate/trap rows must survive generic/package/source mapping. Owner adoption, exact proof-cost/schema grammar, module-claim selection, RFC 0040 observations and full vertical implementation remain gates. This file changes no normative bundle. +Required tests include max/sum activation cases, invalid descriptors before SSA, argument/work limits, all four modes, mixed executable/documented snapshot use, unsafe/trap/fuel behavior, multi-return and trap-only coverage, proof-budget fallback, old/current mutation counterexamples, callback/GC pending values, exact rejection ordering and identical contract-free report bytes. Predicate/trap rows must survive generic/package/source mapping. The linked research supplies a concrete function/value report grammar and classifier; module-claim representation, owner adoption, RFC 0040 observations, diagnostic collection and full vertical implementation remain gates. This file changes no normative bundle. diff --git a/docs/design/contract-invariant-boundaries.md b/docs/design/contract-invariant-boundaries.md index 3c4f63c..e283338 100644 --- a/docs/design/contract-invariant-boundaries.md +++ b/docs/design/contract-invariant-boundaries.md @@ -29,7 +29,7 @@ The claim is: every exposed checked value/shared content view satisfies its pred | `checked.take %c` | checked → R; consume linear capsule, copy Copy content | output is ordinary R with no invariant claim; live views block consuming the root | | `checked.modify %m, @f(args)` | mut>; direct callback f receives a temporary lent mut first, then ordinary typed arguments | suspend capsule access, call f, end its temporary mutation view, run p on the resulting R, then expose f's result | -`make` needs an explicit new instruction-internal place for the complete R candidate, including Copy SSA values. Its predicate receives a dependent `ref` to that place, preserving R itself rather than unwrapping an owner root. The view and every child end before exposure of the result and cannot escape through bool. This adds no general AIR/source addressability for Copy SSA or partially initialized/linear frame locals. Use bounded activation storage, no program heap allocation; exact accounting and interaction with pending-result/local-frame budgets require integration. Existing `borrow.ref` on a Copy scalar or Copy struct SSA root rejects E1001; both baseline cases were independently verified. Their attempted `borrow.end` adds a dependent second E1001 because the invalid result has placeholder type void. +`make` needs an explicit new instruction-internal place for a complete Copy R candidate. Linear R is observed in its existing SSA cell, with no copy, move during validation or new frame local; only success transfers it into the capsule. Its predicate receives a dependent `ref` preserving R itself rather than unwrapping an owner root. The view and every child end before exposure of the result and cannot escape through bool. This adds no general AIR/source addressability for Copy SSA or partially initialized/linear frame locals. The [accounting candidate](contract-accounting-and-status.md) charges size(R) only for the Copy place and retains pending results as SSA; use bounded activation storage, no program heap allocation. Existing `borrow.ref` on a Copy scalar or Copy struct SSA root rejects E1001; both baseline cases were independently verified. Their attempted `borrow.end` adds a dependent second E1001 because the invalid result has placeholder type void. These are proposed operation contracts, not syntax sugar for optional assertions. Ordinary operations cannot project mutable R from a checked value. Interior changes through shared atomic/mutex/endpoint/arc interfaces do not affect the claim because their mutable observations are outside S below. Whole-value store/exchange replaces it with another checked value. Existing `local.alloc`, owners, regions, arrays, buffers, graph storage, channels and mutexes must transport the complete new type under their existing content restrictions; no field write can manufacture it from R. Nested checked values remain checked when an enclosing representation is extracted. A Copy `take` leaves the capsule and its claim intact, while its plain R copy carries no claim. diff --git a/docs/design/contract-proof-and-report.md b/docs/design/contract-proof-and-report.md new file mode 100644 index 0000000..3a0f6a4 --- /dev/null +++ b/docs/design/contract-proof-and-report.md @@ -0,0 +1,107 @@ +# Contract proof classification and report grammar candidate + +Non-normative continuation of [RFC 0039](../rfcs/0039-verifier-visible-contracts.md) and the [accounting/status candidate](contract-accounting-and-status.md), at `a4181f2`. These are proposed closed rules, not implemented verification or an accepted schema. All executable P predicates remain available; this classifier only distinguishes two runtime statuses. Module-claim metadata, source clause elaboration, diagnostic collection, adoption and vertical delivery remain part of full P6-6. + +## Eligible helper and terms + +Classification runs only after ordinary verification, P/S membership and virtual binding checks succeed. An eligible helper has exactly one block, ends in a value `ret`, and contains only the following well-typed operations. Its result is bool for a predicate or Data for old. All instructions, including unused definitions, must qualify. + +| Operation | Operand positions, including one instruction position | Logical node positions | +|---|---:|---:| +| `const.I`, `const.bool` | 1 | 1 | +| `copy` | 2 | 0 | +| Data `struct.make` with n fields | 1+n | 1 | +| Data `struct.get` | 2 | 1 | +| shared binding-derived `borrow.field` | 2 | 1 | +| `load` of Data from such a view or its root | 2 | 1 | +| `borrow.end` of an owned child view | 2 | 0 | +| `eq/ne.I`, `eq/ne.bool`, `lt/le/gt/ge.I` | 3 | 1 | +| `and/or/xor.bool` | 3 | 1 | +| value `ret` | 2 | 0 | + +I is an existing AIR integer type, including isize/usize. Constants are compared by their exact accepted mathematical values; classification assumes no target pointer width. No bool ordering, integer bitwise operations, array operations, calls, assertions, casts, arithmetic, checked extraction, owner/enum views or branch instructions qualify. The predicate may execute any of those permitted by P; it then remains runtime-classified. A helper's signature cannot contain mutable parameters under the boundary rules. A view is eligible only when its root is a helper's bound shared parameter and every edge is an ordinary struct-field projection. Loading a whole linear/authority value does not become eligible. + +Terms form a typed immutable DAG: constants; original Data parameter identities; opaque current Data SSA identities; field projections; Data records in declared field order; scalar comparisons; bool combinations. Copy aliases its input. Projection of a constructed record selects that field; projection of a parameter/opaque record appends the nominal field identity. Other records stay structural, with no expansion of arrays or repeated subtrees. Constant identity includes its type and exact mathematical value; field identity includes its resolved nominal declaration and ordinal. Paths are parent-linked nodes, not copied strings. + +Bindings substitute in parameter order. By-value Data and explicit ref of Copy Data use the same value terms. Shared observations of original Data parameters likewise use their immutable terms. A shared root originally typed `ref` is identified by its enclosing parameter ordinal and field path, independent of entry/return epoch. An original exclusive/owned root instead includes its observation boundary: entry for old/pre, the particular ret for post. The helper's temporary ref type does not make an exclusive/owned enclosing root stable. Slice operations and borrow-result observations are unsupported initially. Different parameter identities are never equated because a particular caller aliases them. + +Old is normalized once at entry, with its own bindings. Its result is substituted for a snapshot binding; it never contains a body SSA identity. Result/Copy make origins follow only const, copy, Data struct.make/get and original Data parameters. Every other Data value, including a block parameter or load, is an opaque identity containing function/value identity and this boundary. Traversal stops there; loops do not turn it into an entry term. Linear make representations are unsupported for proof initially, while their runtime construction remains fully supported. Modify is always runtime-classified. + +Terms of bool type evaluate to true, false or unknown. A constant supplies its value. A comparison evaluates typed constants exactly; identical scalar terms give true for eq/le/ge and false for ne/lt/gt. Otherwise it is unknown. A definitely true/false bool operand can be folded to its typed constant before eq/ne; two identical bool formula terms can still be equal when their truth is unknown. AND/OR use strong three-valued logic, XOR with unknown is unknown. No arithmetic identities, path facts, precondition facts, caller facts, commutative operand sorting or SMT are imported. A raw symbolic bool is unknown. Truth is proved only when the returned formula is definitely true. + +Runtime pre has one universal entry boundary. Post must be true at every syntactic ret, including unreachable blocks, and has no proof when there are zero ret sites. Make has one construction boundary. A constant false formula is reported as not proven; mandatory execution still handles its trap. Classification never rejects a module, eliminates a check, changes fuel or promises termination. + +Once published, this classification, its limits and reasons are frozen as part of the contracts feature's semantics (spec 07 §8.7 and the feature registry's published-feature immutability rule). Toolchain prover strength, cache strategy and optimizations cannot classify more or fewer rows as proven. Changing these rules needs a separately specified compatibility path through an RFC; adding a feature does not itself authorize changing existing format-0 constructs or report bytes. + +## Exact logical work and fallback + +For each runtime record independently, let H be the sum of the table's operand-position charges for its predicate and N the sum of logical node positions. These counts are before folding/interning, including unused definitions. Let n be the predicate binding count and B the prescribed boundary count. For a post using old, O is old helper's operand-position sum plus its binding count plus its logical node count; otherwise O=0. Let D be the operand-position cost of the union of origin-DAG-reachable result/make definitions, counted once per function/value identity for this record across every prescribed boundary, including CFG-unreachable blocks. Post has result-origin work exactly when a binding names result, even if that helper parameter is unused; otherwise D=0. + +Origin constants, copy and struct.make/get use the same position charges as the table. A terminal original Data parameter, block parameter or other opaque Data definition costs one; its operands are not traversed. Pre has D=0. Type/function/field metadata, result identifiers, literal digits, source positions and cache hits add no position. Shared origin definitions are charged once, whether or not an implementation had cached them earlier. + +```text +C = H + O + D + B * (n + N) +limit = 1,048,576 positions per record +``` + +Compute with checked unsigned 64-bit counters; overflow or C>limit gives no proof. C=limit is within budget. Under current structural limits C cannot overflow u64; that fallback is defensive, not a reachable current-module test. Helpers/origin DAGs may be cached but the logical charge is independent of cache state. This bounds classification positions, not elapsed time or every module analysis. Structural type/property scans retain their independent memoized bounds. Unrelated body instructions do not affect a pre's cost. + +Choose exactly one reason in this order, without sampling a run: + +1. Assume/document: `not_attempted`, with no cost or classifier invocation. +2. Modify: `update`, with no cost. +3. Post with zero returns: `no_normal_return`, with no cost. +4. Noneligible predicate: `unsupported_predicate`, with no cost. +5. Used noneligible old helper: `unsupported_old`, with no cost. +6. Unsupported binding/linear make: `unsupported_binding`, with no cost. +7. Overflow or over-budget C: `budget`, with cost `"overflow"` or the integer C. +8. Every boundary definitely true: `closed_scalar`, proof proven, cost C. +9. Otherwise: `not_established`, proof none, cost C. + +Eligibility checks do not follow arbitrary helper calls or execute predicates. Unsupported forms and budget fallback preserve acceptance and runtime enforcement. The report's reason is an explanation of the closed classifier, not a repair proposal or a frequency estimate. These exact charges refine the earlier accounting candidate's open node/operand conventions. + +Initially unsupported bindings are observations of a borrowed/slice result, or a linear make representation. Other verified bindings supply Data terms or shared view anchors, including unused slice/authority-containing anchors; an unsupported operation on an anchor already makes the helper noneligible. Runtime reasons other than closed_scalar have proof none. Only explicit assume/document has proof not_attempted. + +## Report rows and canonical form + +For modules declaring the proposed contracts feature, append a `contracts` object after existing `unsafe`. The proposed checked-type and assumption extensions depend on it, so their full declared dependency closure also triggers this section. Otherwise emit exactly today's report bytes. Its fixed field order is `rows`, `totals`. Feature-declared modules with no truth sites emit an empty rows array and four zero totals. Every new object has the field order specified below; no optional omissions, unknown keys, whitespace or floating-point numbers. Use the existing canonical-record string escaping. + +Rows iterate functions, blocks and instructions in textual module order, one per pre/post or make/modify operation. Old/view/take are not truth rows. Snapshot helper execution remains in the call graph. This gives stable declaration-site counts independent of callers, number of returns or invocations. + +Row field order: + +```text +site, kind, scope, predicate, callback, bindings, status, proof, enforcement, boundaries +``` + +`kind` is `pre`, `post`, `make` or `modify`. Scope is `boundary` for pre/post and `value` for make/modify: the latter establishes a persistent checked claim, rather than a relation that holds only at a function boundary. Predicate is the resolved AIR function name, without @. Callback is the resolved modify callback name, otherwise null. Checked identity still includes R and the resolved predicate; a later metadata integration must represent it without a source-only claim. + +Site and boundary-position object field order is `function`, `block`, `inst`, `source`. Function/block are AIR names without prefixes; inst is the existing zero-based instruction index. Input-text AIR line/col is omitted so comments/formatting do not affect semantic rows. Source is `{file,line,col}` from the supplied lowering map, or null, with one-based line/col. Use the mapping for that exact instruction; never guess a variable name or an enclosing block. No filesystem lookup, path rewriting or source hashing is performed by report generation. Borrowing truth or positions from a caller is forbidden. + +The source field requires an explicit adoption-time clarification to spec 10 §6.1: semantic report data depends only on verified AIR, while locations may use supplied frontend provenance. Currently the CLI passes only the module to report.write; implementing this field needs that provenance context. It changes no contract-free report. An AIR-only input has source null even if its AIR file happens to have a .aji-looking name. Equal verified AIR with different supplied source maps has equal semantic rows: replacing every source value with null gives identical bytes, while the original reports may differ. A generated helper's location is never substituted for the source clause/operation. + +Bindings are in helper parameter order, each `{kind,name,view}`. Kind is `parameter`, `snapshot`, `result` or `representation`; name is the actual AIR value name without % for parameter/snapshot/representation, null for result. View is `value` or `ref`. Pre/post retain their explicit bindings; make/modify have one implicit ref representation binding. Make names its R operand, modify names its capsule-borrow operand. A post's return operand is identified by the corresponding boundary position, not an invented entry result SSA name. + +Proof field order is `result`, `reason`, `cost`, `limit`; result is `proven`, `none` or `not_attempted`, reason is from the ordered list above, cost is null/integer/`"overflow"`, limit is always 1048576. Enforcement is `runtime`, `assumed_unsafe` or `documented`. Status is the corresponding uppercase spec 13 name; only runtime+proven yields PROVEN_STATICALLY. Assumed/documented use not_attempted regardless of formula truth. + +Boundaries are positions in textual order: the pre/make/modify site itself, or all ret positions for post. A zero-ret post has an empty list. Documented clauses retain their syntactic coverage even though no helper executes. Totals field order is PROVEN_STATICALLY, CHECKED_AT_RUNTIME, ASSUMED_UNSAFE, UNPROVEN; each counts rows of that status exactly once. A snapshot is not a fifth status or a truth guarantee. + +Module-state declarations and grouping of named module relations remain unresolved. Persistent checked state and pre/post relations already have distinct scopes here, but this row grammar does not manufacture missing module declarations, root mappings or coverage. Full P6-6 cannot close until those rules and their report representation are integrated. + +## Call/effect/check accounting + +At each executable pre/old/post site, add its helper to calls in instruction order, deduplicating with ordinary call sites. Executable includes runtime and assume, independently of backend elision. A post contributes one call edge at its declaration position, not one per ret; the edge denotes possible invocation, not execution order. Documented clauses add no executable edge. Make adds its predicate; modify adds callback then predicate. Adoption must extend spec 10's calls definition to named invocations of these gated operations, explicitly excluding document; contract-free meanings/bytes stay unchanged. The callback's declared/used effects propagate as for an ordinary call, including trusted-boundary discharge. P helpers have no declared effects but their ordinary call edges remain visible. + +Helper instructions contribute runtime_checks/proven_checks only in their own function rows. Do not copy their asserts, bounds checks or counts into each caller/return. Existing checks fields retain their instruction meanings; contract predicate tests appear in contracts rows rather than new assertion counts. A PROVEN contract still executes and does not increment proven_checks.bounds. Assume variants contribute a direct unsafe operation at their prefix site and unsafe used effect, independent of whether the helper is true. Document adds neither. Rejected modules produce diagnostics and no audit object. + +Required implementation vectors cover exact and one-over proof budgets, cache-independent costs, shared DAGs and many returns, unsupported unused instructions, typed signed/bool comparisons, mutated old/current roots, opaque loop origins, source maps and missing maps, explicit modes, empty feature sections, site totals versus coverage, snapshot-only call edges, callbacks/trusted effects, and unchanged contract-free bytes. The candidate allocates no code/feature and enters no normative/source bundle. + +## Research evidence + +Five current-language probes at `a4181f2` confirm byte-identical reports after AIR comments/whitespace changes, source versus its lowered AIR, and before/after an unsafe T0009 trap. A fourth verifies a shared Pair predicate using i8 limits -128/127, field views/load/end, copy/struct.make/get and bool eq/and/or/xor; it returns true, with the expected ordinary call edge. A fifth verifies the ordinary AIR helper/8,191-return structure used below, without any contract operation. Runs use fuel 10,000. These constrain compatibility and eligible operation shapes; no contract opcode or report section is implemented. + +[Fifteen scalar/cost vectors](contract-proof-vectors.json) pin the proposed arithmetic and truth rules. Symbols denote distinct u64 observations unless explicitly typed otherwise; repeat multiplies boundary count without duplicating the stored formula. The formula representation is research data, not an AIR encoding. Independent concrete evaluation checked 328,965 assignments from 0..255 and all 27 three-valued Boolean combinations/completions. Every classified-true formula held over the sampled assignments; each not_established example had a concrete counterexample. This finite check does not prove the full classifier or the verifier implementation sound. + +The exact-limit vector is attainable within ordinary structural bounds: a 63-parameter helper has 64 bool constants, a one-field Data struct.make, 30 copies and one ret (H=128, N=65). One post covers 8,191 syntactic returns, binds original parameters and has D=O=0, so C=1,048,576. Replacing one unused binding with result from an original parameter gives D=1 and budget fallback at 1,048,577, without changing truth or acceptance. These are proposed classifier vectors, not an executed new-contract test. Old-identity vectors use a two-position identity old helper plus one binding, O=3; Range field predicates have H=17, N=5. + +The [report component vector](contract-report-vector.json) pins field order and all four statuses, including a two-return post and a modify callback. It has five rows and six covered boundaries, with totals counting five sites. It is a proposed contracts component, formatted for inspection, not output captured from today's CLI. Its conceptual function f has pre sites 0..2, old at 3 and post at 4; left/right return different Data parameters, yielding the cost-16 vector above. Function g's modify row is runtime/update. No module-state declaration is implied. diff --git a/docs/design/contract-proof-vectors.json b/docs/design/contract-proof-vectors.json new file mode 100644 index 0000000..eea9cf9 --- /dev/null +++ b/docs/design/contract-proof-vectors.json @@ -0,0 +1,21 @@ +{ + "purpose": "non-normative scalar truth and logical-cost vectors; not implemented contract conformance", + "limit": 1048576, + "vectors": [ + {"case":"literal_true","H":3,"O":0,"D":0,"B":1,"n":0,"N":1,"boundaries":[true],"cost":4,"reason":"closed_scalar"}, + {"case":"universal_identity","H":5,"O":0,"D":0,"B":1,"n":1,"N":1,"boundaries":[["eq","x","x"]],"cost":7,"reason":"closed_scalar"}, + {"case":"unrelated_parameters","H":5,"O":0,"D":0,"B":1,"n":2,"N":1,"boundaries":[["eq","x","y"]],"cost":8,"reason":"not_established"}, + {"case":"old_identity_return","H":5,"O":3,"D":1,"B":1,"n":2,"N":1,"boundaries":[["eq","x","x"]],"cost":12,"reason":"closed_scalar"}, + {"case":"two_returns_same_origin","H":5,"O":3,"D":1,"B":2,"n":2,"N":1,"boundaries":[["eq","x","x"],["eq","x","x"]],"cost":15,"reason":"closed_scalar"}, + {"case":"second_return_other_origin","H":5,"O":3,"D":2,"B":2,"n":2,"N":1,"boundaries":[["eq","x","x"],["eq","y","x"]],"cost":16,"reason":"not_established"}, + {"case":"constant_range_make","H":17,"O":0,"D":5,"B":1,"n":1,"N":5,"boundaries":[["le",0,5]],"cost":28,"reason":"closed_scalar"}, + {"case":"equal_endpoints_make","H":17,"O":0,"D":4,"B":1,"n":1,"N":5,"boundaries":[["le","x","x"]],"cost":27,"reason":"closed_scalar"}, + {"case":"exclusive_old_current","H":11,"O":11,"D":0,"B":1,"n":2,"N":3,"boundaries":[["eq","entry.m.n","ret.m.n"]],"cost":27,"reason":"not_established"}, + {"case":"stable_shared_old_current","H":11,"O":11,"D":0,"B":1,"n":2,"N":3,"boundaries":[["eq","shared.r.n","shared.r.n"]],"cost":27,"reason":"closed_scalar"}, + {"case":"signed_constants","integer_type":"i8","H":7,"O":0,"D":0,"B":1,"n":0,"N":3,"boundaries":[["lt",-128,127]],"cost":10,"reason":"closed_scalar"}, + {"case":"identical_unknown_bool_formulas","H":8,"O":0,"D":0,"B":1,"n":2,"N":2,"boundaries":[["eq",["le","x","y"],["le","x","y"]]],"cost":12,"reason":"closed_scalar"}, + {"case":"true_or_unknown","H":9,"O":0,"D":0,"B":1,"n":2,"N":3,"boundaries":[["or",true,["lt","x","y"]]],"cost":14,"reason":"closed_scalar"}, + {"case":"exact_work_limit","H":128,"O":0,"D":0,"B":8191,"n":63,"N":65,"boundaries":[true],"repeat":8191,"cost":1048576,"reason":"closed_scalar"}, + {"case":"one_over_work_limit","H":128,"O":0,"D":1,"B":8191,"n":63,"N":65,"boundaries":[true],"repeat":8191,"cost":1048577,"reason":"budget"} + ] +} diff --git a/docs/design/contract-report-vector.json b/docs/design/contract-report-vector.json new file mode 100644 index 0000000..b0af948 --- /dev/null +++ b/docs/design/contract-report-vector.json @@ -0,0 +1,49 @@ +{ + "rows": [ + { + "site": {"function":"f","block":"entry","inst":0,"source":null}, + "kind": "pre", "scope": "boundary", "predicate": "always_true", "callback": null, + "bindings": [], "status": "PROVEN_STATICALLY", + "proof": {"result":"proven","reason":"closed_scalar","cost":4,"limit":1048576}, + "enforcement": "runtime", + "boundaries": [{"function":"f","block":"entry","inst":0,"source":null}] + }, + { + "site": {"function":"f","block":"entry","inst":1,"source":null}, + "kind": "pre", "scope": "boundary", "predicate": "positive", "callback": null, + "bindings": [{"kind":"parameter","name":"x","view":"value"}], + "status": "ASSUMED_UNSAFE", + "proof": {"result":"not_attempted","reason":"not_attempted","cost":null,"limit":1048576}, + "enforcement": "assumed_unsafe", + "boundaries": [{"function":"f","block":"entry","inst":1,"source":null}] + }, + { + "site": {"function":"f","block":"entry","inst":2,"source":null}, + "kind": "pre", "scope": "boundary", "predicate": "positive", "callback": null, + "bindings": [{"kind":"parameter","name":"y","view":"value"}], + "status": "UNPROVEN", + "proof": {"result":"not_attempted","reason":"not_attempted","cost":null,"limit":1048576}, + "enforcement": "documented", + "boundaries": [{"function":"f","block":"entry","inst":2,"source":null}] + }, + { + "site": {"function":"f","block":"entry","inst":4,"source":null}, + "kind": "post", "scope": "boundary", "predicate": "same", "callback": null, + "bindings": [{"kind":"snapshot","name":"old","view":"value"},{"kind":"result","name":null,"view":"value"}], + "status": "CHECKED_AT_RUNTIME", + "proof": {"result":"none","reason":"not_established","cost":16,"limit":1048576}, + "enforcement": "runtime", + "boundaries": [{"function":"f","block":"left","inst":0,"source":null},{"function":"f","block":"right","inst":0,"source":null}] + }, + { + "site": {"function":"g","block":"entry","inst":2,"source":null}, + "kind": "modify", "scope": "value", "predicate": "valid_state", "callback": "update_state", + "bindings": [{"kind":"representation","name":"state","view":"ref"}], + "status": "CHECKED_AT_RUNTIME", + "proof": {"result":"none","reason":"update","cost":null,"limit":1048576}, + "enforcement": "runtime", + "boundaries": [{"function":"g","block":"entry","inst":2,"source":null}] + } + ], + "totals": {"PROVEN_STATICALLY":1,"CHECKED_AT_RUNTIME":2,"ASSUMED_UNSAFE":1,"UNPROVEN":1} +} diff --git a/docs/design/open-questions.md b/docs/design/open-questions.md index 2db58e6..f380e5c 100644 --- a/docs/design/open-questions.md +++ b/docs/design/open-questions.md @@ -405,6 +405,8 @@ P6-6 requires contracts and their four audit statuses, but spec 13 §1/spec 08 [Accounting/status research](contract-accounting-and-status.md) proposes pre-SSA activation and virtual-binding bounds, a restricted proof classifier that preserves predicate execution, and explicit unsafe-assumed/documented modes. Nine current-language probes confirm frame/value separation and verifier-stage priority; four proposed mode opcodes reject E0004 alone, while existing unsafe `assume(false)` accepts and traps T0009. These fourteen cases constrain the candidate, not demonstrate contract implementation. Exact proof costs, diagnostic collection, report schema, source/module metadata and adoption remain open. +[Proof/report refinement](contract-proof-and-report.md) supplies a closed opcode normal form, cache-independent position charges and fallback precedence, plus canonical function/value rows and explicit source annotation/call-edge rules. Five current-language baselines verify report equivalence, eligible helper operations and the limit-vector structure; fifteen research vectors check cost/truth with a finite independent oracle. These do not implement contracts or close module metadata, source elaboration, diagnostic collection, owner adoption or vertical delivery. + ## Q-055 — Feature-gated AIR headers and frozen rejection codes Spec 07 §8.7 permits changes to earlier E0004/E0006 rejections, not E0001. Source inspection of the parser before commit `0086549` shows that an unfeatured `trusted "..."` header was parsed as a block label and failed while expecting `:`; current spec 13 §6.3 and the parser require E0006 `feature_not_declared`. RFC 0009 calls the header additive, although this diagnostic transition is outside the literal exception. The historical parser has not been executed in this audit. diff --git a/docs/plan/phase-6-source-language.md b/docs/plan/phase-6-source-language.md index 00c2685..181866c 100644 --- a/docs/plan/phase-6-source-language.md +++ b/docs/plan/phase-6-source-language.md @@ -351,3 +351,5 @@ Eight further compatibility probes independently reproduce Claude's findings: ex Final review identified the need for instruction-internal observation places: ordinary AIR borrow.ref rejects Copy scalar and Copy struct SSA roots with E1001 (two independently verified probes, fifteen total). The candidate states evaluation-scoped materialization without widening general addressability or frame-content rules; RFC 0039 Copy ref-bindings use the same requirement. Exact activation-slot accounting remains a gate. Copy extraction preserves the original checked claim but gives the plain copy no claim; shared interior-mutable interfaces remain outside stable observations. No implementation is authorized by the research. The [accounting/status candidate](../design/contract-accounting-and-status.md) proposes locals plus snapshot plus maximum simultaneous observation-place storage, separately bounded virtual return bindings, and a restricted proof classifier with unchanged predicate execution. Explicit assumed/documented modes retain ordinary legality checks; only assumptions require an unsafe boundary, and documentation grants no truth guarantee. Nine frame/stage baselines and five mode/unsafe baselines match the existing CLI (runs use fuel 10,000); none tests an implemented contract feature. Claude's independent review led to body-independent pre proof costs, explicit Copy/linear make accounting and total pre-types linearity queries, including invalid cycles. Exact proof-cost conventions, diagnostic collection, report/source/module schema and owner adoption remain gates. RFC 0039 stays Draft; P6-6 and its full four-status/invariant exit criterion remain open. + +The [proof/report refinement](../design/contract-proof-and-report.md) closes the candidate's opcode/node cost conventions and function/value row grammar, with deterministic fallback precedence and source metadata distinguished from AIR-derived truth. Fifteen research vectors and a finite independent truth oracle confirm their stated costs/results; five current-language CLI probes confirm canonical report equivalence, run independence, eligible scalar/view operations and the limit-vector structure (runs use fuel 10,000). A report component vector pins field order and site totals across four statuses. Claude independently checked the cost derivations, status/field ordering and feasibility; review corrected a target-width assumption and clarified unreachable origins and assumed-call accounting. These are design evidence, not implemented contract conformance. Module-claim metadata, source clause elaboration, diagnostic collection, owner adoption and full vertical delivery remain open; RFC 0039 stays Draft and P6-6 remains doing. diff --git a/docs/rfcs/0039-verifier-visible-contracts.md b/docs/rfcs/0039-verifier-visible-contracts.md index fcafb5c..10739ae 100644 --- a/docs/rfcs/0039-verifier-visible-contracts.md +++ b/docs/rfcs/0039-verifier-visible-contracts.md @@ -129,7 +129,7 @@ False pre/post conditions need distinct stable trap codes, not allocated here; a | ASSUMED_UNSAFE | an explicit unsafe assumption and its visible boundary; never inferred from an empty effect list | | UNPROVEN | no discharged obligation; no caller may rely on it as a fact | -The [status/accounting research](../design/contract-accounting-and-status.md) proposes a restricted automatic proof classifier, explicit assumed/documented clause modes and a staged diagnostic/report candidate. Proven runtime clauses still execute their predicates; assumption requires an unsafe boundary, documentation grants no truth guarantee, and checked value construction remains enforced. Exact proof-cost conventions, diagnostic collection, report schema and owner adoption remain gates. The audit table must identify clause, boundary, status and source/AIR position; existing assertion counts remain counts. Proposed E7xxx reason fields and new AIR/contract trap codes are not allocated by this draft. +The [status/accounting research](../design/contract-accounting-and-status.md) proposes a restricted automatic proof classifier, explicit assumed/documented clause modes and staged diagnostics. The [proof/report refinement](../design/contract-proof-and-report.md) supplies exact logical charges, fallback order, function/value rows, source-provenance rules and call/check accounting. Proven runtime clauses still execute their predicates; assumption requires an unsafe boundary, documentation grants no truth guarantee, and checked value construction remains enforced. Module metadata, diagnostic collection, adoption and implementation remain gates. Existing assertion counts remain counts. Proposed E7xxx reason fields and new AIR/contract trap codes are not allocated by this draft. Valid target example: a function with `requires { x > 0u64; }` and `ensures { result == old(x); }` returning x; a positive argument succeeds and zero traps at entry. Rejected target example: a postcondition dereferencing an owner consumed by the body; the existing availability rule must still reject it. These are design targets, not current conformance fixtures.