From 5ed0d86e364b59760274ce18085cab70c538b2f3 Mon Sep 17 00:00:00 2001 From: "A.Shakhmatov" Date: Fri, 9 Oct 2026 16:44:08 +0300 Subject: [PATCH] docs: specify contract names and diagnostic witnesses --- docs/design/contract-accounting-and-status.md | 20 +- docs/design/contract-diagnostic-vectors.json | 273 ++++++++++++++++++ docs/design/contract-naming-vectors.json | 145 ++++++++++ .../contract-source-and-module-state.md | 29 +- docs/design/open-questions.md | 2 + docs/plan/phase-6-source-language.md | 2 + docs/rfcs/0039-verifier-visible-contracts.md | 4 +- 7 files changed, 472 insertions(+), 3 deletions(-) create mode 100644 docs/design/contract-diagnostic-vectors.json create mode 100644 docs/design/contract-naming-vectors.json diff --git a/docs/design/contract-accounting-and-status.md b/docs/design/contract-accounting-and-status.md index 9c3afa2..6407ced 100644 --- a/docs/design/contract-accounting-and-status.md +++ b/docs/design/contract-accounting-and-status.md @@ -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. diff --git a/docs/design/contract-diagnostic-vectors.json b/docs/design/contract-diagnostic-vectors.json new file mode 100644 index 0000000..d4a002b --- /dev/null +++ b/docs/design/contract-diagnostic-vectors.json @@ -0,0 +1,273 @@ +{ + "purpose": "Non-normative diagnostics research: return baselines are current CLI results; graph/witness cases describe an unimplemented contract closure.", + "compiler": "8df6cac", + "return_baselines": [ + { + "case": "wrong_origin_with_leak", + "codes": ["E2102"], + "source": [ + "module contract.return_baseline", + "air 0", + "lang 0.1", + "features [capabilities, effects, heap, ownership, resources]", + "fn @f(%a: ref, %b: ref, %owner: own) -> ref from %a", + "effects []", + "entry:", + " %view = borrow.ref %b", + " ret %view" + ] + }, + { + "case": "valid_origin_with_leak", + "codes": ["E3002"], + "source": [ + "module contract.return_baseline", + "air 0", + "lang 0.1", + "features [capabilities, effects, heap, ownership, resources]", + "fn @f(%a: ref, %owner: own) -> ref from %a", + "effects []", + "entry:", + " %view = borrow.ref %a", + " ret %view" + ] + }, + { + "case": "scalar_return_with_leak", + "codes": ["E3002"], + "source": [ + "module contract.return_baseline", + "air 0", + "lang 0.1", + "features [capabilities, effects, heap, ownership, resources]", + "fn @f(%owner: own) -> u64", + "effects []", + "entry:", + " %zero = const.u64 0", + " ret %zero" + ] + }, + { + "case": "consumed_return", + "codes": ["E2002"], + "source": [ + "module contract.return_baseline", + "air 0", + "lang 0.1", + "features [capabilities, effects, heap, ownership, resources]", + "fn @f(%owner: own) -> own", + "effects []", + "entry:", + " %plain = own.take %owner", + " ret %owner" + ] + }, + { + "case": "owner_return_with_live_view", + "codes": ["E2101", "E2105"], + "source": [ + "module contract.return_baseline", + "air 0", + "lang 0.1", + "features [capabilities, effects, heap, ownership, resources]", + "fn @f(%owner: own) -> own", + "effects []", + "entry:", + " %view = borrow.ref %owner", + " ret %owner" + ] + } + ], + "graph_cases": [ + { + "case": "recursive_admitted", + "entry": "a", + "calls": { + "a": ["b"], + "b": ["a"] + }, + "seeds": {}, + "expected": {"admitted": true} + }, + { + "case": "recursive_reaches_seed", + "entry": "root", + "calls": { + "root": ["a"], + "a": ["b"], + "b": ["a", "bad"], + "bad": [] + }, + "seeds": {"bad": "operation"}, + "expected": { + "admitted": false, + "witness": { + "call_count": 3, + "prefix": [ + {"function": "root", "block": "entry", "inst": 0, "callee": "a", "source": null}, + {"function": "a", "block": "entry", "inst": 0, "callee": "b", "source": null}, + {"function": "b", "block": "entry", "inst": 1, "callee": "bad", "source": null} + ], + "suffix": [], + "omitted_calls": 0, + "terminal": {"function": "bad", "block": "entry", "inst": 0, "reason": "operation", "type": null, "operation": "task.cancelled", "source": null} + } + } + }, + { + "case": "shortest_before_textual", + "entry": "root", + "calls": { + "root": ["long", "bad"], + "long": ["bad"], + "bad": [] + }, + "seeds": {"bad": "operation"}, + "expected": { + "admitted": false, + "witness": { + "call_count": 1, + "prefix": [ + {"function": "root", "block": "entry", "inst": 1, "callee": "bad", "source": null} + ], + "suffix": [], + "omitted_calls": 0, + "terminal": {"function": "bad", "block": "entry", "inst": 0, "reason": "operation", "type": null, "operation": "task.cancelled", "source": null} + } + } + }, + { + "case": "textual_tie", + "entry": "root", + "calls": { + "root": ["z", "a"], + "z": [], + "a": [] + }, + "seeds": {"z": "operation", "a": "type"}, + "expected": { + "admitted": false, + "witness": { + "call_count": 1, + "prefix": [ + {"function": "root", "block": "entry", "inst": 0, "callee": "z", "source": null} + ], + "suffix": [], + "omitted_calls": 0, + "terminal": {"function": "z", "block": "entry", "inst": 0, "reason": "operation", "type": null, "operation": "task.cancelled", "source": null} + } + } + }, + { + "case": "local_seed_before_calls", + "entry": "root", + "calls": { + "root": ["bad"], + "bad": [] + }, + "seeds": {"root": "effects", "bad": "operation"}, + "expected": { + "admitted": false, + "witness": { + "call_count": 0, + "prefix": [], + "suffix": [], + "omitted_calls": 0, + "terminal": {"function": "root", "block": null, "inst": null, "reason": "effects", "type": null, "operation": null, "source": null} + } + } + }, + { + "case": "long_path", + "entry": "f0", + "calls": { + "f0": ["f1"], + "f1": ["f2"], + "f2": ["f3"], + "f3": ["f4"], + "f4": ["f5"], + "f5": ["f6"], + "f6": ["f7"], + "f7": ["f8"], + "f8": ["f9"], + "f9": ["f10"], + "f10": ["f11"], + "f11": ["f12"], + "f12": ["f13"], + "f13": ["f14"], + "f14": ["f15"], + "f15": ["f16"], + "f16": ["f17"], + "f17": ["f18"], + "f18": ["f19"], + "f19": ["f20"], + "f20": ["f21"], + "f21": ["f22"], + "f22": ["f23"], + "f23": ["f24"], + "f24": ["f25"], + "f25": ["f26"], + "f26": ["f27"], + "f27": ["f28"], + "f28": ["f29"], + "f29": ["f30"], + "f30": ["f31"], + "f31": ["f32"], + "f32": ["f33"], + "f33": ["f34"], + "f34": ["f35"], + "f35": ["f36"], + "f36": ["f37"], + "f37": ["f38"], + "f38": ["f39"], + "f39": ["f40"], + "f40": [] + }, + "seeds": {"f40": "operation"}, + "expected": { + "admitted": false, + "witness": { + "call_count": 40, + "prefix": [ + {"function": "f0", "block": "entry", "inst": 0, "callee": "f1", "source": null}, + {"function": "f1", "block": "entry", "inst": 0, "callee": "f2", "source": null}, + {"function": "f2", "block": "entry", "inst": 0, "callee": "f3", "source": null}, + {"function": "f3", "block": "entry", "inst": 0, "callee": "f4", "source": null}, + {"function": "f4", "block": "entry", "inst": 0, "callee": "f5", "source": null}, + {"function": "f5", "block": "entry", "inst": 0, "callee": "f6", "source": null}, + {"function": "f6", "block": "entry", "inst": 0, "callee": "f7", "source": null}, + {"function": "f7", "block": "entry", "inst": 0, "callee": "f8", "source": null}, + {"function": "f8", "block": "entry", "inst": 0, "callee": "f9", "source": null}, + {"function": "f9", "block": "entry", "inst": 0, "callee": "f10", "source": null}, + {"function": "f10", "block": "entry", "inst": 0, "callee": "f11", "source": null}, + {"function": "f11", "block": "entry", "inst": 0, "callee": "f12", "source": null}, + {"function": "f12", "block": "entry", "inst": 0, "callee": "f13", "source": null}, + {"function": "f13", "block": "entry", "inst": 0, "callee": "f14", "source": null}, + {"function": "f14", "block": "entry", "inst": 0, "callee": "f15", "source": null}, + {"function": "f15", "block": "entry", "inst": 0, "callee": "f16", "source": null} + ], + "suffix": [ + {"function": "f24", "block": "entry", "inst": 0, "callee": "f25", "source": null}, + {"function": "f25", "block": "entry", "inst": 0, "callee": "f26", "source": null}, + {"function": "f26", "block": "entry", "inst": 0, "callee": "f27", "source": null}, + {"function": "f27", "block": "entry", "inst": 0, "callee": "f28", "source": null}, + {"function": "f28", "block": "entry", "inst": 0, "callee": "f29", "source": null}, + {"function": "f29", "block": "entry", "inst": 0, "callee": "f30", "source": null}, + {"function": "f30", "block": "entry", "inst": 0, "callee": "f31", "source": null}, + {"function": "f31", "block": "entry", "inst": 0, "callee": "f32", "source": null}, + {"function": "f32", "block": "entry", "inst": 0, "callee": "f33", "source": null}, + {"function": "f33", "block": "entry", "inst": 0, "callee": "f34", "source": null}, + {"function": "f34", "block": "entry", "inst": 0, "callee": "f35", "source": null}, + {"function": "f35", "block": "entry", "inst": 0, "callee": "f36", "source": null}, + {"function": "f36", "block": "entry", "inst": 0, "callee": "f37", "source": null}, + {"function": "f37", "block": "entry", "inst": 0, "callee": "f38", "source": null}, + {"function": "f38", "block": "entry", "inst": 0, "callee": "f39", "source": null}, + {"function": "f39", "block": "entry", "inst": 0, "callee": "f40", "source": null} + ], + "omitted_calls": 8, + "terminal": {"function": "f40", "block": "entry", "inst": 0, "reason": "operation", "type": null, "operation": "task.cancelled", "source": null} + } + } + } + ] +} diff --git a/docs/design/contract-naming-vectors.json b/docs/design/contract-naming-vectors.json new file mode 100644 index 0000000..7297836 --- /dev/null +++ b/docs/design/contract-naming-vectors.json @@ -0,0 +1,145 @@ +{ + "purpose": "Non-normative naming vectors: current-language baselines are executed; proposed contract descriptors are not implemented compiler output.", + "compiler": "8df6cac", + "baseline_cli_checks": 10, + "current_language": [ + { + "case": "generic_collision_and_positions", + "key": "fn:contract.names.id", + "generated_name": "__aji_g_44149b3201451c67d8b3f9c9666ff1821b489ed944cfef2fe6f2e8153d62726d_2", + "value": 42, + "source": [ + "module contract.names", + "fn id(x: T) -> T effects [] { return x; }", + "fn __aji_g_44149b3201451c67d8b3f9c9666ff1821b489ed944cfef2fe6f2e8153d62726d() -> u64 effects [] { return 0u64; }", + "fn __aji_g_44149b3201451c67d8b3f9c9666ff1821b489ed944cfef2fe6f2e8153d62726d_1() -> u64 effects [] { return 0u64; }", + "fn main() -> u64 effects [] { return id::(42u64); }" + ] + }, + { + "case": "static_identity_reuse_and_file_label", + "key": "fn:contract.names.apply", + "generated_name": "__aji_g_097a92c7dfcc67ab0d19bd87c3a3a83c38d883f8defb6350b50030f524b11c22", + "calls": 2, + "value": 42, + "source": [ + "module contract.names", + "fn keep(x: u64) -> u64 effects [] { return x; }", + "fn apply T effects []>(x: T) -> T effects [] { return F(move x); }", + "fn main() -> u64 effects [] {", + " let one = apply::(20u64);", + " let two = apply::(22u64);", + " return one + two;", + "}" + ] + }, + { + "case": "module_flatten_collision_order_and_path", + "allocated": [ + "__aji_app_a_b_c_2", + "__aji_app_a_b_c_3" + ], + "value": 42, + "entry": [ + "module app.entry", + "import app.a;", + "import app.a_b;", + "fn __aji_app_a_b_c() -> u64 effects [] { return 0u64; }", + "fn __aji_app_a_b_c_1() -> u64 effects [] { return 0u64; }", + "fn main() -> u64 effects [] { return app.a.b_c() + app.a_b.c(); }" + ], + "modules": { + "app.a": [ + "module app.a", + "fn b_c() -> u64 effects [] { return 20u64; }" + ], + "app.a_b": [ + "module app.a_b", + "fn c() -> u64 effects [] { return 22u64; }" + ] + } + } + ], + "proposed": [ + { + "kind": "pre", + "owner": "fn:app.work.bump", + "ordinal": 0, + "level": 0, + "group": 0, + "encoding": "aji.contract/1\npre\n16:fn:app.work.bump\n0\n0\n0\n", + "digest": "1359541cfa11c597fd0b86cac844724f07d4a07f6ce3b36116eacc8c39669338", + "occupied": [], + "allocated": "__aji_contract_1359541cfa11c597fd0b86cac844724f07d4a07f6ce3b36116eacc8c39669338" + }, + { + "kind": "pre", + "owner": "fn:app.work.bump", + "ordinal": 1, + "level": 0, + "group": 0, + "encoding": "aji.contract/1\npre\n16:fn:app.work.bump\n1\n0\n0\n", + "digest": "4020cdfe37495ff036b0ac25e49f38b515b84384b41e63832f59aebe4cd2d1eb", + "occupied": [], + "allocated": "__aji_contract_4020cdfe37495ff036b0ac25e49f38b515b84384b41e63832f59aebe4cd2d1eb" + }, + { + "kind": "post", + "owner": "fn:app.work.bump", + "ordinal": 0, + "level": 0, + "group": 0, + "encoding": "aji.contract/1\npost\n16:fn:app.work.bump\n0\n0\n0\n", + "digest": "cf71b816e97c5befd170bcae4de1150754d805ad0875a96a6f0c76d26932237a", + "occupied": [], + "allocated": "__aji_contract_cf71b816e97c5befd170bcae4de1150754d805ad0875a96a6f0c76d26932237a" + }, + { + "kind": "old", + "owner": "fn:app.work.bump", + "ordinal": 0, + "level": 0, + "group": 0, + "encoding": "aji.contract/1\nold\n16:fn:app.work.bump\n0\n0\n0\n", + "digest": "a0fcd7d0ec09f4bca91e7feac53ad2fba281e9d5928baf83acf8ccb972063ca3", + "occupied": [], + "allocated": "__aji_contract_a0fcd7d0ec09f4bca91e7feac53ad2fba281e9d5928baf83acf8ccb972063ca3" + }, + { + "kind": "snapshot", + "owner": "fn:app.work.bump", + "ordinal": 0, + "level": 0, + "group": 1, + "encoding": "aji.contract/1\nsnapshot\n16:fn:app.work.bump\n0\n0\n1\n", + "digest": "af4bb0b4bc123bf822bc3eaf6c99ac985391dda522d190273e963371547abc4a", + "occupied": [], + "allocated": "__aji_contract_af4bb0b4bc123bf822bc3eaf6c99ac985391dda522d190273e963371547abc4a" + }, + { + "kind": "witness", + "owner": "invariant:app.state.State", + "ordinal": 0, + "level": 0, + "group": 0, + "encoding": "aji.contract/1\nwitness\n30:invariant:app.state.State\n0\n0\n0\n", + "digest": "70f85479ae7feb61ae4e622908c19addb48d69ad46fbb2b86d82bd8e669b2094", + "occupied": [], + "allocated": "__aji_contract_70f85479ae7feb61ae4e622908c19addb48d69ad46fbb2b86d82bd8e669b2094" + }, + { + "kind": "pre", + "owner": "fn:app.work.bump", + "ordinal": 0, + "level": 0, + "group": 0, + "encoding": "aji.contract/1\npre\n16:fn:app.work.bump\n0\n0\n0\n", + "digest": "1359541cfa11c597fd0b86cac844724f07d4a07f6ce3b36116eacc8c39669338", + "occupied": [ + "__aji_contract_1359541cfa11c597fd0b86cac844724f07d4a07f6ce3b36116eacc8c39669338", + "__aji_contract_1359541cfa11c597fd0b86cac844724f07d4a07f6ce3b36116eacc8c39669338_1" + ], + "allocated": "__aji_contract_1359541cfa11c597fd0b86cac844724f07d4a07f6ce3b36116eacc8c39669338_2" + } + ] +} diff --git a/docs/design/contract-source-and-module-state.md b/docs/design/contract-source-and-module-state.md index a0f2dbc..79938fe 100644 --- a/docs/design/contract-source-and-module-state.md +++ b/docs/design/contract-source-and-module-state.md @@ -73,7 +73,34 @@ A documented old(expr) must refer to an equal executable capture already present Post helpers receive the snapshot record and result only when needed, alongside original roots. Snapshot field projection happens inside the helper. Original body SSA never enters the prefix binding list. Parameter-free predicates remain possible on main. Generic/static/package calls, recursive calls and spawned workers use the callee's same prefix; returns, implicit tails and ordinary cleanup lead to the same enforced post boundary. Source loan/cleanup machinery must retain required original roots without extending loans past ret or resurrecting consumed values; exact integration tests remain mandatory. -Generated helper/witness/snapshot names use collision-free deterministic keys containing the defining function/declaration identity, concrete specialization and clause/old ordinal. Original/generated names are reserved before choosing the smallest free suffix, and the emitted generated declarations are sorted by their keys. Existing contract-free specialization ordering/bytes stay unchanged. Exact mangling tags/serializer placement still need integration with spec 15 §15. +## Generated names and source provenance + +First discover all ordinary declarations/specializations needed by bodies and clauses, resolving alias arguments before their existing specialization keys. Allocate their AIR names by today's linking/monomorphization rules, then reserve those names in both declaration categories. Contract artifacts cannot change an ordinary symbol's collision suffix. They are a separate final generation pass; visiting a clause before another body cannot allocate its public/helper names early. + +An artifact has the full tuple `(kind,owner,ordinal,level,group)`. Kind is pre, post, old, witness or snapshot. Owner is the existing canonical `fn:` specialization key, or `fn:` plus the full defining-module/function path for a monomorphic function. A witness uses `invariant:` plus the defining-module/declaration path and its ordered canonical arguments when specialized. Its owner retains the declaration identity even if another alias denotes the same checked type. Physical source paths, file labels, spans, diagnostic order and predicate results contribute no key bytes. Owner keys have the existing 16,384-byte compiler-input bound, including these new monomorphic descriptors. The ordinal/level/group are unsigned u32 values in canonical decimal. + +Pre/post ordinal counts every clause expression in its class in lexical order across groups, including assume/document. Mode is metadata, not a helper-name component. There is one old collector per function; old and witness use zero ordinal/level/group. Snapshot uses ordinal 0 and the packing algorithm's zero-based level/group. Pre/post use level/group 0. Distinct executable old occurrences retain their separate slots inside the one collector; documents do not add slots. Helpers for documented clauses are still emitted for independent typing/P validation, though they have no executable call edge. + +Encode a tuple as these UTF-8 bytes, with LF at every indicated line end: + +```text +aji.contract/1\n +KIND\n +OWNER_BYTE_LENGTH:OWNER\n +ORDINAL\n +LEVEL\n +GROUP\n +``` + +The owner length is canonical decimal and counts bytes. The length prefix makes components unambiguous; full tuples/bytes, not digests, determine identity and reuse. The descriptor adds bounded fixed overhead to its bounded owner; it does not tighten the existing ordinary specialization-key limit. The AIR base is `__aji_contract_` plus lowercase SHA-256 of these bytes. Sort artifacts lexicographically by complete encoding bytes, then allocate the smallest unused positive `_1`, `_2`, ... suffix when the base is occupied. Reserve each allocation immediately; handle a digest collision identically to an original-name collision. No user identifier prefix is reserved. + +Emit ordinary types followed by snapshot types in artifact order, then ordinary functions followed by helper/witness functions in artifact order; each category retains today's original/generic ordering. Ordinary specialization counters retain their meaning, including specialized invariant declarations; helpers/snapshot records are not additional generic instantiations. All emitted types/functions/instructions/arguments count toward the ordinary AIR limits, including documented helpers and unused witnesses. No new unbounded generation exemption or private runtime storage is introduced. A contract-free input creates no descriptors and keeps today's canonical bytes. + +Use the defining declaration/clause map rather than reversing a mangled name. The witness header/ret map to its invariant declaration. A pre/post prefix site maps to its bool expression; the old prefix/collector header map to the first executable old occurrence. Predicate/collector instructions preserve each original expression/subexpression span. Snapshot struct declarations and packing/projection operations map to the first old slot they represent. Explicit checked operations map to the source operation; implicit/tail returns retain today's return/tail span. Helper call/parameter adaptation maps to the source argument/root that caused it, not the surrounding generated name. Repeated generic specializations retain template spans; supplied static/type argument errors retain application spans. In a clause helper, its header/parameter facts map to that clause expression; a named external helper retains its own header and body spans. + +The lowering output carries a separate typed declaration map `(canonical source declaration name, witness function identity, declaration span)` for inventory provenance. It is not parsed from comments or consumed as semantic evidence; verified signature/body/type identity still controls the inventory record. Runtime dispatch retains both the installing site and evaluated boundary, so a post failure reports its clause plus the actual ret separately. Missing exact mappings use the existing primary fallback; related positions omit source coordinates instead of borrowing another mapping. Complete dispatch/trap schema and AIR0 compatibility remain separate gates. + +[Naming vectors](contract-naming-vectors.json) retain three current-language source groups at `8df6cac` (ten CLI checks): a generic base plus _1 collision allocates _2, two calls with the same static-function key reuse one specialization, and flattened module-name collisions allocate _2/_3 in canonical module order. Runs return 42 with fuel 10,000. Tested comment/position changes, path changes and import/mapping permutations preserve AIR bytes. Seven proposed artifact descriptors separately pin encoding, digest and collision allocation; hashlib and sha256sum agree. They are design vectors, not implemented contract-helper output. ## Representation, properties and positions diff --git a/docs/design/open-questions.md b/docs/design/open-questions.md index 1ddb597..b4235f8 100644 --- a/docs/design/open-questions.md +++ b/docs/design/open-questions.md @@ -411,6 +411,8 @@ P6-6 requires contracts and their four audit statuses, but spec 13 §1/spec 08 The [property/inventory refinement](contract-source-and-module-state.md#representation-properties-and-positions) provides candidate inherited-property, complete-position, zeroability, recursive transfer-gate and ABI/rendering rules. Its exact inventory separates universal raw-representation proof from site proof and source provenance. Twelve prior probes match `4cda448`; eight additional reproducible current-language vectors constrain identity/content rules and predicate shape. The updated report component's totals, ordering and proof costs are independently checked. These refine the Draft, not the normative language. Source-map/mangling, diagnostic/dispatch, Q-055 compatibility, owner model selection and vertical delivery remain open; no contract implementation is claimed. +The next candidate fixes contract artifact name encoding/order and typed declaration maps, with three naming groups (ten CLI checks) and seven hash/collision vectors. Global P-before-S subpasses, bounded shortest-call witnesses and isolated return/post collection now have concrete rules; five current-language return probes preserve existing leak/early-return code lists and six graph vectors validate proposed witness selection. These remain unimplemented research constraints. Complete binding/diagnostic/trap schemas, compatibility, model adoption and vertical delivery remain open. + ## 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 2a1013e..be28dce 100644 --- a/docs/plan/phase-6-source-language.md +++ b/docs/plan/phase-6-source-language.md @@ -360,3 +360,5 @@ The [module/source candidate](../design/contract-source-and-module-state.md) dev The property/type-position audit exposed a pre-existing accounted-size defect ([Q-058](../design/open-questions.md#q-058--finite-anonymous-types-truncated-by-the-size-cycle-guard)): anonymous array/atomic/mutex edges incorrectly consumed a nominal-cycle depth budget. Corrected finite type sizes now enforce existing value/frame and allocation quotas. AIR/source boundary and rejection fixtures, a named-record heap quota pair and cached/uncached/cyclic unit checks cover the fix; a separate unverified native-recursion concern is recorded as Q-059. This correction adds no contract syntax, feature or adoption decision; checked properties and the remaining full P6-6 gates stay open. The [property/inventory refinement](../design/contract-source-and-module-state.md#representation-properties-and-positions) specifies candidate complete representation/position checks, inherited properties, recursive endpoint gates, dedicated representation traversal, forbidden zero manufacture, size versus ABI and representation-only result rendering. The inventory's universal raw-R proof is distinct from construction-site proofs and supplied declaration provenance. Twelve prior property baselines match `4cda448`; eight new reproducible vectors verify ordinary identity/content restrictions and the Range predicate. The report research component includes six sites, seven boundaries and three checked identities with distinct type/site proofs. These are current-language/design checks, not implemented contracts. Claude's earlier property audit is incorporated; the live Herdr channel is unavailable for fresh review. Mangling/source-map, diagnostics/dispatch, compatibility and owner model selection remain gates; RFC 0039 stays Draft and full P6-6 remains doing. + +The [naming/provenance candidate](../design/contract-source-and-module-state.md#generated-names-and-source-provenance) fixes full descriptor bytes, ordinary-first collision allocation, emission categories and clause/witness maps. Three current-language naming groups pass ten CLI checks; seven proposed descriptors agree under two SHA-256 implementations. The [diagnostic refinement](../design/contract-accounting-and-status.md#collection-at-returns) preserves ordinary return/leak facts while isolating virtual post checks, orders required P/S subpasses, and bounds shortest real-call witnesses. Five executed return baselines and six graph vectors independently verify current constraints and proposed selection. No semantic/code/registry change is made; the vectors are not new-contract conformance. Binding/source-reason/trap schemas, Q-055 compatibility, owner adoption and full vertical implementation remain gates; RFC 0039 stays Draft and full P6-6 remains doing. diff --git a/docs/rfcs/0039-verifier-visible-contracts.md b/docs/rfcs/0039-verifier-visible-contracts.md index 904fc06..32428fd 100644 --- a/docs/rfcs/0039-verifier-visible-contracts.md +++ b/docs/rfcs/0039-verifier-visible-contracts.md @@ -155,7 +155,9 @@ Module invariants need a definition of their roots and observation boundaries. S The candidate distinguishes a persistent checked state root owning correlated values from a boundary relation over separately owned roots and an explicit function set. Their audit scopes and coverage claims must differ. The [module/source refinement](../design/contract-source-and-module-state.md) proposes a narrow named binding for caller-owned checked state, collision-safe type.checked syntax, independent type-level audit claims and eager snapshot/capture rules. Its property/position refinement preserves representation properties and recursive transfer gates, prohibits zero manufacture, keeps accounted size separate from ABI and proposes representation-only JSON rendering. The exact type inventory classifies predicates over raw universal representations, separately from make sites and source provenance. Twenty current-language property baselines constrain these rules; no checked feature, type proof or inventory is implemented. It adds no boundary-group or hidden-global abstraction. Rooted state as the module-invariant model remains an owner decision; source-map/mangling, diagnostics/dispatch and vertical integration remain open. Ordinary pre/post reuse alone must not silently redefine module invariants. -Remaining decisions: shared observation coverage (Q-057) and invariant-evaluation interactions; source clause elaboration and complete AIR binding grammar; purity/snapshot diagnostics and ordering; proof and assumption modes; invariant boundaries and metadata representation; traps/report schema and tested pending-return dispatch. The RFC stays Draft until these have concrete rules and counterexamples. +The source refinement also fixes descriptor encodings, collision order, emission categories and exact clause/witness maps; three current-language naming groups and seven proposed descriptors constrain the candidate. The accounting refinement specifies global P-before-S diagnostic subpasses, shortest real-call witnesses with bounded head/tail facts, and isolated post/ordinary-return collection preserving legacy leak and early-return lists. Five current-language return probes and six independent graph vectors check those constraints. This is design evidence; neither new diagnostics nor contract dispatch are implemented. + +Remaining decisions: shared observation coverage (Q-057) and invariant-evaluation interactions; complete AIR binding grammar and source diagnostic reason allocations; purity/snapshot diagnostic schemas and format-0 compatibility; final feature/status policy adoption; invariant/module model adoption; traps/run-record schema and tested pending-return dispatch. The RFC stays Draft until these have concrete rules and counterexamples, followed by full vertical delivery. ## Compatibility and integration