docs: refine checked-type properties and invariant audit inventory
This commit is contained in:
1 parent
4cda44823d
commit
8df6cacf12
7 files changed
+155
-9
No files matched your search
@@ -1,6 +1,6 @@
|
||||
# Contract source elaboration and rooted module-state candidate
|
||||
|
||||
Non-normative continuation of [RFC 0039](../rfcs/0039-verifier-visible-contracts.md), [checked representations](contract-invariant-boundaries.md) and [proof/report rules](contract-proof-and-report.md), at `8260d35`. This proposal adds no implemented syntax, feature or normative rule. It preserves full P6-6, including type/module claims and all four statuses. Hidden globals, visibility, property/ABI auditing, diagnostics/dispatch integration, adoption and vertical delivery are not established here.
|
||||
Non-normative continuation of [RFC 0039](../rfcs/0039-verifier-visible-contracts.md), [checked representations](contract-invariant-boundaries.md) and [proof/report rules](contract-proof-and-report.md), initially at `8260d35`, with the property/inventory refinement verified against `4cda448`. This proposal adds no implemented syntax, feature or normative rule. It preserves full P6-6, including type/module claims and all four statuses. Hidden globals, visibility, diagnostics/dispatch integration, adoption and vertical delivery are not established here.
|
||||
|
||||
## Module invariant and identity
|
||||
|
||||
@@ -23,7 +23,7 @@ Two invariant names with the same resolved R and p denote the same type. Distinc
|
||||
|
||||
Resolve these bindings before equality, property tests and specialization-key construction. The canonical type key spells `checked<canonical-R,fn canonical-function-identity>`; an alias spelling does not create a different container specialization. Existing type/function keys are unchanged. Imports retain direct-import lookup; no module name is inferred from AIR mangling. Alias-resolution cycles fail with a stable E7006 reason; expansion depth, specialization count and key bytes use the existing 64/4096/16384 compiler bounds. Nominal representation references stop alias expansion; ordinary recursive-layout validation remains independent.
|
||||
|
||||
Every concrete declaration must reach AIR type verification even when no value is constructed. Candidate lowering emits a generated identity witness `fn @w(%value: checked<R,@p>) -> checked<R,@p> effects [] { ret %value }`. It is never implicitly invoked, holds no global state and validates the type/predicate through its signature. Linear values transfer on its ordinary ret. Its declaration appears in canonical AIR and the report's ordinary functions list, with no calls or check rows. Generic witnesses are emitted for concrete specializations; known template restrictions still check before substitution. This needs a complete representation/type-position audit: the witness must not invent an invalid parameter/return position for a type otherwise admitted by the final checked feature.
|
||||
Every concrete declaration must reach AIR type verification even when no value is constructed. Candidate lowering emits a generated identity witness `fn @w(%value: checked<R,@p>) -> checked<R,@p> effects [] { ret %value }`. It is never implicitly invoked, holds no global state and validates the type/predicate through its signature. Linear values transfer on its ordinary ret. Its declaration appears in canonical AIR and the report's ordinary functions list, with no calls or check rows. Generic witnesses are emitted for concrete specializations; known template restrictions still check before substitution. The representation/type-position rules below require parameter/return admissibility, so this witness does not impose an additional position restriction on an otherwise valid checked type.
|
||||
|
||||
## Source grammar and explicit operations
|
||||
|
||||
@@ -75,11 +75,58 @@ Post helpers receive the snapshot record and result only when needed, alongside
|
||||
|
||||
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.
|
||||
|
||||
## Representation, properties and positions
|
||||
|
||||
Candidate R validity requires ordinary well-formedness, a complete value, and admissibility as a function parameter and return. Borrow/storage/function-bound content is forbidden along the same content edges as aggregate-member checking, including inside owners, buffers and nested checked types. This combines the shallow `types.complete` test with recursive member validity; `complete` alone is insufficient. Void/never, local, ref/mut/slices, task/scope/shield and guard cannot be wrapped to bypass their ordinary position or transfer rules. An iref is an opaque content leaf; its referent still needs ordinary type validity. Ownership cycles through R retain E1003 and existing stage order. R is not restricted to Copy or Data: borrowed linear-state updates are a required use case.
|
||||
|
||||
The checked feature itself need not depend on linear_aggregates solely because R is a linear complete value. R's own features remain required, and placing a linear checked value in a field/payload/array or individual own content retains the ordinary linear_aggregates gate. This is a proposed dependency choice, not an allocated feature. All checks repeat after generic substitution; a template is rejected early only for a restriction invalid under every substitution.
|
||||
|
||||
| Property/query on checked<R,p> | Candidate rule |
|
||||
|---|---|
|
||||
| Copy / linear | exactly R's Copy / linear classification |
|
||||
| Send / Share / Local | exactly R's corresponding structural property |
|
||||
| IslandSafe / ArcSafe / Freeze | exactly R's corresponding property; the latter two still equal IslandSafe in format 0 |
|
||||
| Data | exactly when R is Data; predicate identity is not a value/member |
|
||||
| Zeroable | false, including constant-true predicates and zeroable R |
|
||||
| Accounted size | size(R), with no predicate-handle charge |
|
||||
| Forbidden content / endpoints / capability kinds | traverse R using each existing query's own edge rules |
|
||||
| Type height / bounded syntax | one checked constructor edge followed by R; predicate identity contributes no edge |
|
||||
| Ownership/layout cycle traversal | enter R; an iref edge remains non-owning |
|
||||
|
||||
Zeroability cannot depend on evaluating p at compile time: zero/local.zero/region zero-fill cannot manufacture a checked claim. Accounted size is not ABI layout. Anonymous checked edges preserve Q-058's nominal-edge size depth, while the separate type-height query counts the constructor. Size/property scans must stay total before type validation, including invalid cycles; use the accounting candidate's fixed-point linearity rather than module-free `Type.isLinear` for representation-dependent answers.
|
||||
|
||||
Keep `Type.inner()`'s storage/borrow/element meaning unchanged. Introduce a dedicated representation accessor and explicit checked cases in equality, canonical type keys, property caches/dependency edges, feature/position checks, finite-layout validation, size, source forbidden witnesses, capability inventory and runtime value traversal. A query that currently has an `else` default needs the same audit as an exhaustive switch. Do not make an ordinary borrow or integer operation accept checked content through a generic inner accessor.
|
||||
|
||||
| Position/operation | Candidate restriction |
|
||||
|---|---|
|
||||
| SSA, parameter, return, block parameter | complete checked value; ordinary linear consumption/edge rules |
|
||||
| Struct/enum/fixed array, individual own | existing linear-member/content feature gate; no new partial moves |
|
||||
| Frame local, region content, repeated own_array content | Copy checked values only; zero initialization remains forbidden |
|
||||
| Buffer | existing complete-member rules and explicit drain obligations |
|
||||
| Channel element / mutex content | Send and existing recursive endpoint/forbidden-content checks through R; channel_transfer is not bypassed |
|
||||
| Island/frozen/arc content | existing graph-content property, inherited from R |
|
||||
| Borrow/slice of checked | ordinary ancestry/alias/loan rules; shared representation access only through checked.view |
|
||||
| Task argument/result | existing Send/Share and transfer rules |
|
||||
| Main parameter | checked is not a capability and cannot receive a grant |
|
||||
| AtomicScalar, arithmetic/casts, field/tag projection | checked remains a distinct type; extract/view R explicitly, then apply ordinary rules |
|
||||
|
||||
A whole checked Copy value may be loaded/stored; a linear one uses complete exchange/transfer. Ordinary struct literals, struct.get/unpack, enum.take and borrow.field cannot expose the capsule's R directly. `checked.take` relinquishes only this outer claim, preserving nested checked claims. These restrictions apply in AIR as well as source. Pure/stable closures may view checked roots and take Copy Data content; make/modify remain excluded, and the initial proof normal form still excludes checked extraction.
|
||||
|
||||
No ABI layout or foreign transparency is granted by size(R). Current FFI declarations are illustrative/unsupported; this refinement claims no FFI implementation. A future FFI feature must prevent foreign construction/writes from publishing checked values without validation. An ordinary foreign adapter should transport R and validate through make on re-entry; any unsafe promise needs its own explicit obligation and compatibility rules. Casts or serialization cannot confer checked identity.
|
||||
|
||||
Propose that canonical run-result rendering recursively renders R, without a checked tag, predicate identity or re-evaluation. Nested struct fields, enum payloads and arrays follow their existing order; opaque values retain their existing rendering. This is output serialization, not an Aji value conversion or validation bypass. Copies/transfers/GC visit the representation exactly as needed for its ordinary values and resource identities; predicate identity remains compile-time metadata with no allocation, refcount or destructor.
|
||||
|
||||
## Declared claims in the report
|
||||
|
||||
Make/modify rows alone omit a library invariant whose type has no construction site. Propose an additional contracts field `types` after rows/totals: distinct checked identities in first structural occurrence order across declarations, signatures, blocks and typed instruction operands. Traverse wrappers/member graphs once with visited identities; do not expand occurrences exponentially or parse a module name out of a generated symbol. The identity witness ensures concrete unused source declarations are represented. Its ordinary return is not an extra invariant-check row.
|
||||
Make/modify rows alone omit a library invariant whose type has no construction site. Append `types` after `rows,totals` in the proposed contracts object; emit an empty array when no checked identity occurs. Contract-free report bytes remain unchanged. Enumerate distinct checked identities in first structural occurrence order: type declarations and members/payloads, then functions in textual order (parameters, return, each block's parameters and instruction type operands). Each walk is preorder, visiting checked identity before R, and follows ordinary type-parameter edges even for phantom iref targets. Visit each nominal declaration once globally and each checked identity once for inventory output; predicate identity is not a traversal edge. Ordinary resolved graph references are required, not string parsing or expansion of shared paths. This is an inventory walk, not the ownership-cycle query. The identity witness ensures concrete unused source declarations are represented. Its ordinary return is not an extra invariant-check row.
|
||||
|
||||
For each identity record the canonical checked type, predicate, status, proof, enforcement and supplied declaration provenance. Proposal: classify p universally over one shared R observation, using the same closed normal form as a pre (B=1, n=1, D=O=0). Predicate truth is not inferred from a successful make. Proven yields PROVEN_STATICALLY, otherwise CHECKED_AT_RUNTIME with runtime enforcement by construction/update; type invariants have no assumed/documented mode. Instance sites retain their own classifications, so a universally unproved Range predicate can coexist with a proven constant make. Type records do not contribute to row totals and have no separate status totals initially. Concrete universal-root term identity, canonical inventory schema/provenance order and property/ABI rules remain integration gates; this is not today's report output.
|
||||
Type-record field order is `type,predicate,status,proof,enforcement,declarations`. Type spells `checked<R, @p>` with one space after the comma and ordinary recursive AIR spelling for R; predicate is the resolved function name without @. Proof uses the existing `result,reason,cost,limit` object. Enforcement is always `construction_update`: ordinary copies/transfers do not rerun p. Type invariants have no assume/document mode. Records contribute neither rows nor row totals, and have no separate totals.
|
||||
|
||||
Classify p over one universally unconstrained shared R observation (B=1, n=1, D=O=0). The universal root term is keyed by resolved checked identity and root parameter ordinal 0; ordinary field paths append resolved nominal declaration/field ordinals. It represents all raw R values, not only those already satisfying p or seen at make sites. Scalar/Data loads retain the existing eligibility rules, including alongside linear fields. A literal-true ref<R> predicate has H=3,N=1,C=5 and is proven. The Range predicate in the baseline vectors has H=17,N=5,C=23; distinct lo/hi terms leave it not_established. A constant {0,5} make can independently be proven at C=28. Unsupported helpers/bindings and budgets use the same closed fallback order. Proof never eliminates runtime evaluation or promises termination.
|
||||
|
||||
Declarations contain supplied source provenance only: ordered objects `name,witness,source`, where name is the canonical source declaration/specialization name, witness is the AIR function name without @, and source is the existing `{file,line,col}` or null. A frontend may supply these records only for its concrete identity witnesses. Before attaching one, require a verified witness with exactly one parameter of this checked type, the same return type, effects [], no trusted/prefix metadata, and one block containing only ret of that parameter. Omit mismatched records; never infer names/modules from mangled symbols. Order by witness function order, then supplied declaration order, deduplicating identical records. AIR-only input has declarations []; missing maps do not suppress a checked identity or alter proof/status. These names/positions make no independent semantic claim. Clearing declarations and other source fields must recover identical semantic reports for identical verified AIR.
|
||||
|
||||
The [report vector](contract-report-vector.json) now includes a constant Range make and three inventory identities, one with no construction site. The unused identity still has its universal proof; the modify identity uses an unsupported predicate and remains runtime. This component is proposed research data, not today's CLI output.
|
||||
|
||||
Valid target: a module exports State holding two correlated counters; unrelated imported code can share it, exchange it, or update it through a callback, and the persistent relation survives every successful update. An in-place update of a borrowed linear buffer representation needs no replacement allocation. Rejected targets: public field writes into State; callback returning a borrow from R; overlapping update arguments; predicate with mutable atomic observations; zero construction; an invariant declaration with wrong predicate signature even when unused. A boundary relation over separate mutable roots remains valid only at its explicit pre/post boundaries.
|
||||
|
||||
@@ -87,7 +134,7 @@ Valid target: a module exports State holding two correlated counters; unrelated
|
||||
|
||||
No new AIR header/type-declaration kind is used. Identity witnesses use ordinary function declarations; checked type operands and operations retain the unknown-constructor/opcode E0004 path, subject to Q-055's dependent-error audit. The evidence below pins complete current spellings without claiming full format-0 compatibility. Source item/header, reserved expression and reserved type positions have the separately recorded E7001/E7002 transitions; existing ordinary identifiers/namespaces are preserved. Wrong static selections/argument types and invalid type positions follow existing E7002/E7005 rules; new source-context conflicts need stable E7006 reasons, not message parsing.
|
||||
|
||||
Costs: one narrow named declaration, clause groups, contextual result/old, four explicit checked operations, capture/snapshot elaboration, identity witnesses and type-level audit records. No module-global instance, hidden checking constructor, general alias system, new runtime function values or boundary-group verifier state is introduced. Compare this against inline checked types and nominal checked-struct syntax before adoption. Measure final Quick Reference/source/AIR growth; this research is outside the bundles. Remaining gates include exact alias/property/ABI/mangling/schema rules, source/semantic diagnostic order, traps and pending dispatch, RFC 0040, owner model selection and full source/AIR/package/generic/GC/schedule validation.
|
||||
Costs: one narrow named declaration, clause groups, contextual result/old, four explicit checked operations, capture/snapshot elaboration, identity witnesses and type-level audit records. No module-global instance, hidden checking constructor, general alias system, new runtime function values or boundary-group verifier state is introduced. Compare this against inline checked types and nominal checked-struct syntax before adoption. Measure final Quick Reference/source/AIR growth; this research is outside the bundles. Remaining gates include exact mangling/source-map integration, source/semantic diagnostic order, traps and pending dispatch, RFC 0040, Q-055 compatibility, owner model selection and full source/AIR/package/generic/GC/schedule validation. Property/position/rendering and inventory rules above are candidate resolutions, not an accepted feature or completed implementation.
|
||||
|
||||
## Verified source compatibility constraints
|
||||
|
||||
@@ -110,3 +157,5 @@ Nineteen current-language probes at `8260d35` contain no implemented contracts.
|
||||
| Same 65 values packed into 64/1 leaf records and a two-field root | accepts; returns last value 64 |
|
||||
|
||||
The reserved-prefix choice is justified by inability to bind its first component, not by assuming every type position is a syntax rejection. The proposed type form changes an E7002 rejection to acceptance; the expression/item/header forms change E7001 rejections. Existing module checked and generic checked types must keep their meaning. Witness acceptance on ordinary R does not prove all checked type/property positions valid. Claude independently read the recorded results and reviewed name/capture/snapshot rules; no language feature or owner policy is adopted.
|
||||
|
||||
At `4cda448`, all twelve previously recorded property probes retain their exit status/code lists: scalar, linear-record, capability, atomic, mutex and buffer identity accept; guard/task/shield transfers reject E0006, borrowed member and linear own_array content reject E1001, and graph resource content rejects E2111. Eight additional [reproducible property vectors](contract-property-vectors.json) verify region/endpoint identity, recursive endpoint gates in channel/mutex, nonzeroable Copy capability, rejected nominal AtomicScalar, E0004 for a complete checked witness, and the ordinary Range predicate returning true with fuel 10,000. Concatenate header/body lines, then run the listed command (run uses the listed fuel). They validate current-language constraints, not the proposed checked feature, universal proofs or inventory output. The property rules incorporate Claude's earlier read-only audit; this refinement has not received a fresh Claude review because the live Herdr channel is unavailable.
|
||||
Reference in new issue
Block a user