docs: specify contract names and diagnostic witnesses

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

No files matched your search

@@ -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