verifier: cache structural properties and nominal size queries

This commit is contained in:
dev committed 2026-10-08 13:33:24 +03:00
1 parent 41f3afbf05
commit 48b9b42fed
31 files changed
+1399 -166

No files matched your search

+2
View File
@@ -327,6 +327,8 @@ Q-043 review identified a separate existing cost in `Lowerer.linearAt`: repeated
Audit the existing classification/layout ordering and shared-query cost with counted tests, preserving structural ownership classes, graph/iref boundaries, source E1003 provenance, accepted-source canonical AIR and frozen AIR behavior. Avoid wall-clock timeout tests. This is an implementation audit, not a new recursion or memory rule.
**Resolved:** lowering reads structural linearity from a resolved nominal-property table after finite-layout checks. AIR verification rebuilds the same table before type checking, with a monotone dependency worklist for the existing predicates, depth-64 guard and source depth-32 witness pruning. The earlier budget stage memoizes sizes by nominal index and depth, preserving cutoff, overflow and E5101 precedence exactly. Checked modules retain immutable caches for subsequent queries. Counted diamond/cycle tests and differential small-graph tests cover all predicates, witness order, depth boundaries, sizes and caller-supplied cache rejection. Source/AIR diagnostics, ownership classes, valid canonical AIR and runtime semantics are unchanged; standalone uncached helpers remain available for small test oracles.
## Q-045 — Source array literals with second-class elements
Q-043 review reproduced `fn unused(p: ref<u64>) -> void effects [] { let a = [p, p]; }`: the source array literal reaches AIR type checking with E1001 because borrows cannot be stored as array elements. Q-042 validates annotations; an inferred literal has none. Q-043 now rejects that array as a repeated `own.array` value, but constructing it without that operation remains a separate source validation gap.
+4
View File
@@ -91,6 +91,10 @@ These hold for the whole toolchain, not only deterministic mode:
- `std.testing.allocator` in unit tests to catch leaks.
- No global mutable state; pass allocators and `std.Io` explicitly.
Structural queries share a per-module table over resolved nominal declarations. A reverse-dependency worklist computes the existing boolean predicates, saturated traversal height and nearest forbidden source-element depth; named queries then read that immutable table. Existential properties start false, universal properties true, height increases and witness distance decreases to their existing depth limits. Cycles therefore terminate without a traversal timeout; existing layout/type checks still decide rejection. The verifier rebuilds the table rather than trusting one supplied by a caller. Source lowering builds it after finite-layout checking, preserves diagnostic order and uses the same declaration snapshot. The witness search retains field order and its depth-32 boundary, pruning subtrees with no reachable witness. Tests count evaluations and compare the cached predicates against uncached derivations on small acyclic modules. This changes implementation cost, not AIR meaning, ownership classes or runtime behavior.
The budget stage separately memoizes accounted sizes by nominal index and depth. Including depth preserves the previous cutoff and overflow diagnostics exactly, with at most V × (V + 2) nominal states; shared paths no longer expand exponentially. Verification returns a module carrying read-only caches for subsequent report/interpreter queries. Replacing a module's declarations invalidates its caches. Standalone uncached property/size helpers retain their recursive derivations for small differential tests.
## Zig conventions
- Zig 0.17.0, formatted with `zig fmt`.
+6
View File
@@ -285,3 +285,9 @@ Q-048/spec 15 §10 rejects stores through shared borrows, and checks explicit `m
The preserved invariant is that explicit `mut` cannot create exclusive access from shared access. AIR independently enforces borrow/store modes, aliases, lifetimes and linear content/projection restrictions. No runtime state, allocation, cleanup, deterministic interpreter behavior, syntax, code/reason, feature or evaluation input changes. Positive source/AIR runs exercise scalar/field/index/range writes and owning content; rejected cases cover shared modes and retained verifier rules. Q-049 records the separate unresolved Copy-let frame-content policy. Bundle growth is recorded in docs/agent/README.md; P6-2 remains open.
Validation: full conformance passes 1,543/1,543; units and Zig formatting pass. The 46 new fixtures pass with collection before every instruction; CLI integration passes 348 checks, including exact fields/positions, diagnostic commands, formatting, imported generic templates and source/AIR/hosted execution. Existing array-argument/non-value/linear/borrow-return CLI suites pass 85/635/49/133 checks. Comparison on 1,211 preceding public sources (673 successful old lowerings) changes only the message of two rejected inputs; accepted AIR is byte-identical. All eleven new runtime fixtures also retain the previous compiler's AIR. The formatter corpus passes 5,289 checks on 1,257 public files (1,249 parsed, eight existing syntax errors, 686 identical AIR outputs); coverage remains 121/121. Independent read-only review by Claude approved the access-mode checks and confirmed the two diagnostic-message changes.
## P6-2 nominal query cost (2026-10-08)
Q-044 replaces repeated nominal walks with a shared property table and memoizes the earlier AIR accounted-size query by index/depth. The invariant is exact structural classification: existing tag rules, graph/iref boundaries, ownership classes, diagnostic ordering and depth guards remain. The verifier rebuilds caches rather than trusting callers; lowering classifies only after finite-layout checks. No verifier rule, AIR meaning, diagnostic/code/reason, source syntax, feature, interpreter state, allocation/cleanup behavior or bundle text changes. Nominal size states have the documented polynomial bound V × (V + 2), preserving the former depth-dependent calculation. Valid deep diamonds/phantom nodes and rejected cycles, oversized values, annotations and constraints have source/AIR fixtures; runtime allocation uses the checked cache.
Validation: units and Zig formatting pass; full conformance is 1,560/1,560, with all 17 new fixtures also passing collection before every instruction. Counted tests cover shared/cyclic queries, witness visits and layout rejection before classification; 256 small mixed graphs compare cached predicates, witnesses, depth guards and sizes against uncached derivations. CLI integration passes 110 checks, including source/AIR/hosted execution, actual allocation accounting, imported types and diagnostics. Existing generic/content/store-mode suites pass 32/302/348 checks. Old/new comparison changes zero outputs on 1,257 public sources (686 old lowerings) and 333 public AIR checks. Coverage remains 121/121. Claude independently ran units and approved review. P6-2 remains open; Q-049 is a separate owner-policy question.