diff --git a/docs/design/contract-compatibility-vectors.json b/docs/design/contract-compatibility-vectors.json new file mode 100644 index 0000000..1e4783e --- /dev/null +++ b/docs/design/contract-compatibility-vectors.json @@ -0,0 +1,409 @@ +{ + "purpose": "Executed current-language rejection baselines, not implemented-contract conformance or proof of format-0 compatibility. File labels removed; all other emitted diagnostic fields retained.", + "compiler": "c633f23", + "command": "aji check FILE.air", + "cases": [ + { + "case": "pre_unknown", + "source": [ + "module contract.compatibility", + "air 0", + "lang 0.1", + "features [effects]", + "fn @f(%x: u64) -> u64", + "effects []", + "entry:", + " contract.pre @p(%x)", + " ret %x", + "fn @p(%v: u64) -> bool", + "effects []", + "entry:", + " %b = const.bool true", + " ret %b" + ], + "exit": 1, + "diagnostics": [ + { + "code": "E0004", + "kind": "parse.unknown_name", + "severity": "error", + "line": 8, + "col": 2, + "name": "contract.pre", + "message": "unknown opcode" + } + ] + }, + { + "case": "old_post_unknown", + "source": [ + "module contract.compatibility", + "air 0", + "lang 0.1", + "features [effects]", + "fn @f(%x: u64) -> u64", + "effects []", + "entry:", + " %old = contract.old @snapshot(%x)", + " contract.post @post(%old, result)", + " ret %x", + "fn @p(%v: u64) -> bool", + "effects []", + "entry:", + " %b = const.bool true", + " ret %b", + "fn @snapshot(%v: u64) -> u64", + "effects []", + "entry:", + " ret %v", + "fn @post(%before: u64, %after: u64) -> bool", + "effects []", + "entry:", + " %b = const.bool true", + " ret %b" + ], + "exit": 1, + "diagnostics": [ + { + "code": "E0004", + "kind": "parse.unknown_name", + "severity": "error", + "line": 8, + "col": 9, + "name": "contract.old", + "message": "unknown opcode" + }, + { + "code": "E0004", + "kind": "parse.unknown_name", + "severity": "error", + "line": 9, + "col": 2, + "name": "contract.post", + "message": "unknown opcode" + } + ] + }, + { + "case": "old_body_escape", + "source": [ + "module contract.compatibility", + "air 0", + "lang 0.1", + "features [effects]", + "fn @f(%x: u64) -> u64", + "effects []", + "entry:", + " %old = contract.old @snapshot(%x)", + " %v = add.checked.u64 %old, %x", + " ret %v", + "fn @p(%v: u64) -> bool", + "effects []", + "entry:", + " %b = const.bool true", + " ret %b", + "fn @snapshot(%v: u64) -> u64", + "effects []", + "entry:", + " ret %v" + ], + "exit": 1, + "diagnostics": [ + { + "code": "E0004", + "kind": "parse.unknown_name", + "severity": "error", + "line": 8, + "col": 9, + "name": "contract.old", + "message": "unknown opcode" + }, + { + "code": "E5001", + "kind": "air.invalid_ssa", + "severity": "error", + "line": 9, + "col": 23, + "function": "f", + "value": "%old", + "message": "value used but never defined" + } + ] + }, + { + "case": "pre_unrelated_undefined", + "source": [ + "module contract.compatibility", + "air 0", + "lang 0.1", + "features [effects]", + "fn @f(%x: u64) -> u64", + "effects []", + "entry:", + " contract.pre @p(%x)", + " %v = add.checked.u64 %missing, %x", + " ret %v", + "fn @p(%v: u64) -> bool", + "effects []", + "entry:", + " %b = const.bool true", + " ret %b" + ], + "exit": 1, + "diagnostics": [ + { + "code": "E0004", + "kind": "parse.unknown_name", + "severity": "error", + "line": 8, + "col": 2, + "name": "contract.pre", + "message": "unknown opcode" + }, + { + "code": "E5001", + "kind": "air.invalid_ssa", + "severity": "error", + "line": 9, + "col": 23, + "function": "f", + "value": "%missing", + "message": "value used but never defined" + } + ] + }, + { + "case": "old_body_and_unrelated_undefined", + "source": [ + "module contract.compatibility", + "air 0", + "lang 0.1", + "features [effects]", + "fn @f(%x: u64) -> u64", + "effects []", + "entry:", + " %old = contract.old @snapshot(%x)", + " %v = add.checked.u64 %old, %missing", + " ret %v", + "fn @p(%v: u64) -> bool", + "effects []", + "entry:", + " %b = const.bool true", + " ret %b", + "fn @snapshot(%v: u64) -> u64", + "effects []", + "entry:", + " ret %v" + ], + "exit": 1, + "diagnostics": [ + { + "code": "E0004", + "kind": "parse.unknown_name", + "severity": "error", + "line": 8, + "col": 9, + "name": "contract.old", + "message": "unknown opcode" + }, + { + "code": "E5001", + "kind": "air.invalid_ssa", + "severity": "error", + "line": 9, + "col": 23, + "function": "f", + "value": "%old", + "message": "value used but never defined" + }, + { + "code": "E5001", + "kind": "air.invalid_ssa", + "severity": "error", + "line": 9, + "col": 29, + "function": "f", + "value": "%missing", + "message": "value used but never defined" + } + ] + }, + { + "case": "checked_make_used", + "source": [ + "module contract.compatibility", + "air 0", + "lang 0.1", + "features [effects, ownership]", + "fn @f(%x: u64) -> u64", + "effects []", + "entry:", + " %s = checked.make checked, %x", + " %r = checked.take %s", + " ret %r", + "fn @p(%v: ref) -> bool", + "effects []", + "entry:", + " %b = const.bool true", + " ret %b" + ], + "exit": 1, + "diagnostics": [ + { + "code": "E0004", + "kind": "parse.unknown_name", + "severity": "error", + "line": 8, + "col": 7, + "name": "checked.make", + "message": "unknown opcode" + }, + { + "code": "E0004", + "kind": "parse.unknown_name", + "severity": "error", + "line": 9, + "col": 7, + "name": "checked.take", + "message": "unknown opcode" + }, + { + "code": "E5001", + "kind": "air.invalid_ssa", + "severity": "error", + "line": 10, + "col": 6, + "function": "f", + "value": "%r", + "message": "value used but never defined" + } + ] + }, + { + "case": "checked_type_signature", + "source": [ + "module contract.compatibility", + "air 0", + "lang 0.1", + "features [effects, ownership]", + "fn @f(%x: checked) -> checked", + "effects []", + "entry:", + " ret %x", + "fn @p(%v: ref) -> bool", + "effects []", + "entry:", + " %b = const.bool true", + " ret %b" + ], + "exit": 1, + "diagnostics": [ + { + "code": "E0004", + "kind": "parse.unknown_name", + "severity": "error", + "line": 5, + "col": 11, + "name": "checked", + "message": "unknown type" + } + ] + }, + { + "case": "contract_header", + "source": [ + "module contract.compatibility", + "air 0", + "lang 0.1", + "features [effects]", + "fn @f(%x: u64) -> u64", + "effects []", + "requires @p(%x)", + "entry:", + " ret %x", + "fn @p(%v: u64) -> bool", + "effects []", + "entry:", + " %b = const.bool true", + " ret %b" + ], + "exit": 1, + "diagnostics": [ + { + "code": "E0001", + "kind": "parse.unexpected_token", + "severity": "error", + "line": 7, + "col": 10, + "expected": "`:`", + "found": "p", + "message": "expected `:`" + } + ] + }, + { + "case": "ordinary_undefined", + "source": [ + "module contract.compatibility", + "air 0", + "lang 0.1", + "features [effects]", + "fn @f(%x: u64) -> u64", + "effects []", + "entry:", + " %v = add.checked.u64 %missing, %x", + " ret %v", + "fn @p(%v: u64) -> bool", + "effects []", + "entry:", + " %b = const.bool true", + " ret %b" + ], + "exit": 1, + "diagnostics": [ + { + "code": "E5001", + "kind": "air.invalid_ssa", + "severity": "error", + "line": 8, + "col": 23, + "function": "f", + "value": "%missing", + "message": "value used but never defined" + } + ] + }, + { + "case": "unknown_feature", + "source": [ + "module contract.compatibility", + "air 0", + "lang 0.1", + "features [contracts, effects]", + "fn @f(%x: u64) -> u64", + "effects []", + "entry:", + " contract.pre @p(%x)", + " ret %x", + "fn @p(%v: u64) -> bool", + "effects []", + "entry:", + " %b = const.bool true", + " ret %b" + ], + "exit": 1, + "diagnostics": [ + { + "code": "E0006", + "kind": "module.unsupported_feature", + "severity": "error", + "line": 4, + "col": 1, + "reason": "unknown_feature", + "feature": "contracts", + "message": "feature cannot be used" + } + ] + } + ] +} diff --git a/docs/design/contract-source-errors-and-compatibility.md b/docs/design/contract-source-errors-and-compatibility.md new file mode 100644 index 0000000..17b4bdf --- /dev/null +++ b/docs/design/contract-source-errors-and-compatibility.md @@ -0,0 +1,61 @@ +# Contract source errors and AIR compatibility audit + +Non-normative completion of the source rejection map for [RFC 0039](../rfcs/0039-verifier-visible-contracts.md), following [source elaboration](contract-source-and-module-state.md), [AIR bindings](contract-air-bindings.md) and [runtime context](contract-runtime-and-context.md). No reason, code, feature or language rule is allocated here. This candidate does not authorize implementation or resolve Q-055. + +## Source rejection map + +Keep spec 15 §10's frontend/verifier division. Syntax and source-resolvable type/name errors stop before AIR; independently verified access, ownership, purity, stability and status obligations retain their AIR codes and independently mapped positions. A source type mismatch must not become E1001 from a generated helper. New E7006 reasons below are proposed additions to the existing stable registry; existing reasons keep their meaning. No message parsing or parallel `contract_reason` vocabulary is needed. + +| Source fact | Candidate code / reason | Primary position | +|---|---|---| +| Malformed/empty clause group, missing terminator, misplaced group or unsupported mode spelling | E7001 with ordinary expected/found | offending token | +| Unknown value/function/type, including a body local absent from the clause environment | E7002 | unresolved name | +| Header parameter or clause binder named result when ensures exists | E7006 / contract_result_conflict | conflicting binder | +| Snapshot-shaped unqualified old call also resolves to a visible function/parameter/binder | E7006 / contract_old_conflict | call target old | +| Inline return in a clause or old expression | E7006 / contract_return | return keyword | +| Nested old inside executable/documented old expression | E7006 / contract_old_nested | inner old call target | +| result referenced inside old expression | E7006 / contract_old_result | result occurrence | +| old expression refers to a known enclosing clause-local binder rather than an original header root or its own scratch local | E7006 / contract_old_capture | captured name | +| Documented old has no structurally equal executable capture | E7006 / contract_document_old | documented old call target | +| Checked alias-resolution cycle | E7006 / invariant_cycle | reference that closes the active resolution chain | +| Non-bool clause; non-Data old value; result on void; any ensures group on never | E7005 with expected/found | clause expression; old argument; result occurrence; ensures keyword, respectively | +| Wrong checked predicate/callback signature or static argument kind | E7005 with existing static-signature fields where applicable | supplied fn/type argument | +| Wrong runtime operand type/mode, including mutable projection through a checked representation | E7005 with expected/found | operand/place | +| State { ... } attempts to construct a checked alias as a struct | E7005 | literal's type name | +| zero State or zero of a containing non-zeroable type | E7006 / zero_not_zeroable | zero expression | +| break/continue outside a loop within the inline expression | E7006 / loop_control_outside_loop | control keyword | +| Existing explicit transfer, borrow-binding, duplicate declaration or static-function restriction | existing source code/reason | existing position | +| Source alias/specialization depth, instance count or key-byte bound | E7006 / implementation_limit | existing expansion/application position | +| Generated helper exceeds AIR argument, frame, value or virtual-boundary bounds | E5101, mapped through generation provenance | offending root/clause/declaration mapping | + +There are eight proposed reason additions, all for newly introduced constructs. Ordinary unknown names remain E7002 even inside old. The special capture reason requires a resolved enclosing clause-local identity; it must not be guessed from spelling. Unqualified old recognition remains exactly the source candidate's one-argument ensures form. Qualified old calls, old outside ensures and body bindings named result retain ordinary rules. + +Check conflicts before binding the special result/old forms; classify nested old and result within old before checking snapshot value type or document matching. Type-check a documented expression before searching for an equal executable capture. A matching capture is still eager work, not proof that its expression terminates. Alias-cycle detection uses the active resolved alias identities; an ordinary nominal representation reference stops alias expansion, while finite-layout validation remains a separate obligation. + +Existing global/signature phase stops, first body error per source declaration, generic-template skipping, limit 32 and code/location dedup remain in force. These rules do not make malformed or type-invalid clauses reach the AIR verifier to collect extra purity errors. Once typed lowering succeeds, P membership precedes S membership, and ordinary access errors remain factual access errors. Generated headers, deduplicated roots, snapshot projections and actual source helper instructions use the already specified provenance map; no generated-name parsing or fabricated source binder is introduced. + +The table is a delivery checklist, not compiler output. Vertical tests must pair every new rejection with a valid neighbor: ordinary body result; qualified old; inner scratch rather than outer capture; own loop rather than outer break; Data old rather than non-Data; executable/documented matching versus mismatch; nominal recursion versus alias cycles. Existing E7006 reasons and contract-free CLI records must remain unchanged. + +## Executed format-0 rejection baselines + +[Ten current-language vectors](contract-compatibility-vectors.json) at c633f23 retain complete source and emitted diagnostic fields except the physical file label. All are `aji check` calls, exit 1; no runtime/model experiment is involved. Relevant helper declarations are included so their absence does not explain a future rejection. The old parser has not been executed. + +| Case | Current codes | Audit obligation | +|---|---|---| +| Unknown pre; unknown checked signature | E0004 each | named opcode/type exception candidate | +| Unknown old/post | E0004, E0004 | independently classify both registered names | +| Old snapshot used in ordinary body | E0004, E5001(%old) | still invalid under the proposal; a transition to snapshot_escape changes the code list | +| Pre plus unrelated undefined operand | E0004, E5001(%missing) | recognizing pre cannot erase the independent SSA defect | +| Old body escape plus unrelated undefined operand | E0004, E5001(%old), E5001(%missing) | identical codes conceal different causes; retain value identities and positions | +| Checked make/take, returned take result | E0004, E0004, E5001(%r) | ordinary use of a newly defined result is not the forbidden snapshot escape | +| New requires header | E0001 | outside the named-opcode/type exception | +| Ordinary undefined operand | E5001 | no extension-related cause | +| Unknown contracts feature | E0006 / unknown_feature | current header stop, not evidence for future construct validation | + +The checked make/take example is intended to become valid with the proposed feature and pure predicate; the old body escape is intended to remain invalid. Neither result is implemented or claimed by these baselines. Comparing only acceptance, the first code or aggregate code frequencies misses the rejection-compatibility question. + +Spec 07 §8.7 requires preservation of accepted behavior/canonical form and rejected codes, with an exception for names formerly rejected E0004/E0006. It does not explicitly decide whether the exception includes dependent undefined-result diagnostics in a mixed list. A possible **owner policy**, not adopted here, would restrict that exception to the newly recognized construct and facts causally dependent on it, preserving unrelated invalid operands. It would need an explicit normative rule and a complete parser/stage audit, not a blanket waiver whenever E0004 occurs. Alternatively, an RFC can introduce AIR1 while retaining AIR0 unchanged. Header E0001 is a distinct issue; these opcode probes cannot legitimize it. + +## Remaining adoption and delivery gates + +The source rejection map and runtime schemas are now concrete candidates. Owner decisions remain: rooted caller-owned state versus another module-invariant abstraction; Q-055's version/compatibility policy; and adoption of the RFC 0039/0040 representations. They are not resolved by continued probe collection. Once chosen, integrate complete normative/reference rules, register features/codes/reasons, and deliver verifier/interpreter/frontend/formatter/report/Quick Reference changes with positive and negative AIR/source fixtures, GC and schedule coverage, contract-free compatibility checks and measured bundle growth. Full P6-6 still includes module/type claims and all four statuses. RFC 0039 remains Draft. diff --git a/docs/design/open-questions.md b/docs/design/open-questions.md index 591be5e..0d2330d 100644 --- a/docs/design/open-questions.md +++ b/docs/design/open-questions.md @@ -419,6 +419,8 @@ The [runtime/context candidate](contract-runtime-and-context.md) gives concrete ## Q-055 — Feature-gated AIR headers and frozen rejection codes +2026-10-09: [ten executed rejection vectors](contract-source-errors-and-compatibility.md#executed-format-0-rejection-baselines) distinguish snapshot body escape, ordinary checked-result use and independent missing operands, retaining complete diagnostic identities/positions. The same E5001 code can represent either a dependent or unrelated defect. The candidate lists a narrowly causal policy and AIR1 as owner alternatives; neither is adopted, and the historical parser is still unexecuted. Complete feature/parser compatibility remains open. + 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. Resolve this compatibility policy before using `trusted` as a precedent for new contract headers (Q-054). Preserving legacy E0001 parsing conflicts with §8.1's E0006 for an undeclared construct; replacing E0001 conflicts with §8.7. Instructions whose old rejection is E0004 or a new AIR version avoid this header conflict. Amending either rule is an owner decision, not implied by the implementation. No existing parser, diagnostic or stability rule changes here; other historical syntax extensions remain unaudited. diff --git a/docs/plan/phase-6-source-language.md b/docs/plan/phase-6-source-language.md index 1392082..f8569b2 100644 --- a/docs/plan/phase-6-source-language.md +++ b/docs/plan/phase-6-source-language.md @@ -366,3 +366,5 @@ The [naming/provenance candidate](../design/contract-source-and-module-state.md# The [AIR binding candidate](../design/contract-air-bindings.md) supplies prefix/type/operation grammar, explicit root/form identity, exact shared adaptation, snapshot-use checks and proposed E8001 reasons/fields. Eighteen current-language probes verify view/alias/never-call constraints and isolated E0004 rejection of complete candidate prefixes. Claude independently reproduced all eighteen and the nine descriptor hashes/order cases; review clarified linear checked root access, repeated Copy-place budgets, SSA/root priority, source dedup positions and stable return-fact ordering. This is non-normative design evidence, with no implementation or registry change. Source reasons, trap/dispatch schema, compatibility, owner adoption and vertical tests remain gates; RFC 0039 stays Draft and P6-6 remains doing. The [runtime/context candidate](../design/contract-runtime-and-context.md) specifies frame continuations, normal completion only after validation, free normalization before quantum checks, depth/fuel precedence, traced pending roots and exact additive failure context. Six ordinary groups pass 16 CLI runs at quantum 1; nine fixture variants pass GC-every-step record comparison (13 schedule cases, 26 interpreter runs). Six hypothetical schema components are explicitly unimplemented. Claude independently reproduced the CLI records and reviewed the rules; corrections fixed old/make/modify modes, race context and AIR-only byte-identity exploration. No normative/compiler/registry/bundle changes are made. Source reasons, compatibility/model adoption, RFC 0040 observations and full vertical runtime tests remain gates; RFC 0039 stays Draft and full P6-6 remains doing. + +The [source rejection/compatibility audit](../design/contract-source-errors-and-compatibility.md) proposes eight new E7006 reasons and retains existing source type/name/transfer codes, error collection and mapped verifier obligations. Ten executed current-language AIR0 probes preserve full diagnostics and distinguish dependent undefined results from independent SSA errors; neither the historical parser nor contract semantics is executed. Owner selection of the module-state model, Q-055 compatibility/version policy and RFC representations remains necessary before normative integration and vertical implementation. No fresh Claude review was available for this increment. RFC 0039 remains Draft; P6-6 remains doing. diff --git a/docs/rfcs/0039-verifier-visible-contracts.md b/docs/rfcs/0039-verifier-visible-contracts.md index f5c98ca..1c9fdd1 100644 --- a/docs/rfcs/0039-verifier-visible-contracts.md +++ b/docs/rfcs/0039-verifier-visible-contracts.md @@ -165,6 +165,8 @@ Remaining decisions: shared observation coverage (Q-057) and invariant-evaluatio ## Compatibility and integration +The [source rejection/compatibility audit](../design/contract-source-errors-and-compatibility.md) proposes eight precise E7006 reason additions while retaining ordinary source type/name/transfer errors and mapped verifier facts. Ten executed AIR0 rejection vectors distinguish dependent undefined results, unrelated SSA defects and the separate header E0001 issue. They do not settle Q-055: a causal exception policy or AIR1 requires an owner decision. Source reasons and runtime schemas are concrete candidates; adoption and complete vertical delivery remain open. + An AIR0 implementation must preserve all earlier accepted behavior, canonical bytes and rejected codes (spec 07 §8.7). Isolated candidate function operations and the snapshot/post prefix currently reject only E0004; registering them may produce E0006 when their feature is undeclared, matching the named-opcode exception and §8.1. The body-use probe also reports E5001 because the unknown instruction does not define `%old`. That shape remains invalid under the candidate's snapshot restriction; the audit concerns its rejection-code transition, not acceptance of this escape. Establish whether §8.7 covers those dependent errors, and preserve independently invalid cases; precedent alone does not settle that interpretation (Q-055). Full dependency closure and syntax audits are still required. The prefix avoids the header-specific E0001 conflict without changing compatibility policy. New type/module metadata must independently satisfy compatibility or use AIR1. On acceptance integrate spec 13 §1, spec 08 §8, spec 10 §6.1, spec 11 §7, spec 07/07a, spec 15, grammar, feature/error registries and the Quick Reference together. Delivery requires source/AIR positive and negative coverage, bypass attempts, generic/package/worker cases, borrow/loan/snapshot failures, deterministic profiles/schedules and independently verified audit statuses. No implementation is authorized by this Draft alone.