cli: reject non-value operands without aborting lowering

This commit is contained in:
dev committed 2026-10-08 12:17:15 +03:00
1 parent bc5412dadd
commit dcd5f1f702
83 files changed
+1042 -38

No files matched your search

+2
View File
@@ -162,3 +162,5 @@ Q-043 dynamic owning-array content (cl100k): Quick Reference stays 8,948; other
Q-045 inferred array literals (cl100k): Quick Reference stays 8,948; other source docs 66,827 → 66,906 (+79), full source 75,775 → 75,854 (+0.10%). o200k groups are 8,984 / 67,110 / 76,094; Qwen2.5 9,226 / 68,550 / 77,776. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Existing member-position and Copy-repetition rules now reject invalid inferred elements before AIR, at the offending value. Lists retain explicit linear transfers; repeated borrows retain E7006 invalid_literal. No new concept, syntax, code, reason, feature or verifier/runtime state is added. Invalid-source diagnostic codes/priority may change; accepted canonical AIR is preserved. No empirical MCC benefit is claimed.
Q-046 inferred constructor content (cl100k): Quick Reference stays 8,948; other source docs 66,906 → 67,074 (+168), full source 75,854 → 76,022 (+0.22%). o200k groups are 8,984 / 67,279 / 76,263; Qwen2.5 9,226 / 68,724 / 77,950. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Existing value/Copy/borrow restrictions now reject at constructor arguments, including generic templates, before malformed AIR or null-block failure. Complete linear packing and recovery remain valid; graph/endpoint feature diagnostics keep their existing precedence. No new concept, syntax, code/reason, feature or verifier/runtime state is added. Accepted canonical AIR is preserved; invalid-source diagnostics may change. No empirical MCC benefit is claimed.
Q-047 non-value operands (cl100k): Quick Reference stays 8,948; other source docs 67,074 → 67,258 (+184), full source 76,022 → 76,206 (+0.24%). o200k groups are 8,984 / 67,461 / 76,445; Qwen2.5 9,226 / 68,912 / 78,138. AIR remains 184,628 bytes / 47,445 cl100k tokens; library/std.md is unchanged. Typed operation inputs reject never before subsequent emission; divergent returns/branches/statements and variable receivers retain their control flow, and frame receivers skip writes. Store values remain required. Invalid-source diagnostic order may change; accepted canonical AIR is preserved. No new concept, syntax, code/reason, feature or verifier/runtime state is added. No empirical MCC benefit is claimed.
+8
View File
@@ -346,3 +346,11 @@ Audit each constructor against its own existing content/position/property rules
Q-046 review identified other uses of `never` that reach lowering with no current block. Independently reproduced: `module test.never_operand fn stop() -> never effects [] { trap; } fn main() -> u64 effects [] { return 1u64 + stop(); }` aborts while `Lowerer.binary` calls `def`/`emit` after `stop()` terminated the block. Review also reproduced ordinary call arguments and struct fields; their exact scope remains unverified. Q-046 guards constructor content only.
Audit non-value operands in ordinary calls, operators and aggregates against spec 15 before emission. Distinguish value-requiring positions from valid void statements and never-returning control flow. Add source rejection/acceptance and CLI tests, preserving evaluation order, explicit transfers, diagnostics and canonical AIR for valid source. A source program MUST NOT cause a lowering panic; do not infer a new divergence/coercion rule from implementation behavior.
**Resolved (spec 15 §10):** typed operation inputs reject never with E7005 at the operand (`expected`, `found: never`) before subsequent inputs/emission, while ordinary void mismatches retain their diagnostics. Calls, operators, fields/payloads, conditions, ranges/indices, sizes, atomics, channels and place-store values use this rule. `select` checks a divergent send value before endpoint borrows. Return/tail/statement/branch divergence and existing SSA variable receivers remain valid; divergent assignment by name or `var` initialization in frame storage now performs no store. Binding/annotation checks still precede those receivers. Place writes through `*`, fields or indices require a value; rejecting never before target evaluation prevents formerly invalid targets from being accepted. Unknown target types use `expected: a stored value`, so earlier E7002 can become E7005 at the RHS. `let` retains its existing no-value error. Emission into a terminated block returns E7006 unreachable rather than aborting; a state-machine unit test preserves the terminated block and diagnostic span. AIR acceptance, ownership/lifetime rules, effect/capability contracts, normal-path execution and accepted-source canonical AIR are unchanged. Programs that previously aborted now reject or, for valid variable receivers, diverge normally. Q-048 records a separate store-mode gap.
## Q-048 — Source place-store access modes
Q-047 review independently reproduced `fn update(p: ref<u64>) -> void effects [] { *p = 1u64; }`: it reaches AIR E1001 (`expected: mut<T>`, `found: ref<u64>`) instead of frontend E7xxx, although the mode is determined by source types (spec 15 §10). Review also observed accepted writes to fields of a `let` aggregate. An immutable binding does not necessarily imply immutable owned content; whether that behavior disagrees with the specification remains unverified and MUST NOT be guessed from the binding's `mutable` flag.
Audit existing place modes and referents against spec 15 §4/§5 and AIR borrow/store rules. Reject fully type-decided incompatibilities at the source, preserving ownership, aliasing/lifetime diagnostics, evaluation order and canonical AIR for valid source. Determine the binding/content distinction from governing text before proposing any semantic restriction.
+8
View File
@@ -269,3 +269,11 @@ Q-046/spec 15 §10 validates inferred content before forming constructor results
The preserved invariants are that second-class borrows cannot become owned content and Copy-only allocation cannot hide or destroy a linear value. AIR independently enforces the same type, property and ownership rules. Allocation authority/budgets, ok/err payloads, explicit release, resource recovery, runtime state and deterministic interpreter behavior are unchanged. Positive runs release linear contents and distinguish successful/failed packing; rejected tests cover nonvalues, borrows, owners, nominal values and tasks. No new syntax, code/reason, feature, verifier state or evaluation input changes. Source bundle growth is recorded in docs/agent/README.md; P6-2 remains open, with the separate Q-044 property-query cost audit outstanding.
Validation: full conformance passes 1,422/1,422, units and Zig formatting pass. The 58 new conformance fixtures pass with collection before every instruction; the new CLI suite passes 302 checks across diagnostic commands, exact fields/locations, imported generic templates, source/AIR/hosted runs and formatter fidelity. Existing owning-array, literal and linear CLI suites pass 119, 152 and 49 checks. The formatter corpus passes 4,862 checks on 1,134 public files (1,126 parsed, eight existing syntax errors, 657 identical successful AIR outputs); the two final graph regression fixtures additionally preserve formatted AIR in CLI checks. Independent read-only review by Claude confirmed the constructor-specific rules and identified the existing feature-dependent graph diagnostic, covered by paired fixtures. Comparison with the previous compiler on 1,078 existing public sources changes one invalid region allocation from E1001 to E7005; accepted programs retain byte-identical AIR. The former compiler successfully lowered 642 of these sources, including that invalid program. Source coverage remains 121/121.
## P6-2 non-value operands (2026-10-08)
Q-047/spec 15 §10 distinguishes typed operation inputs from divergent control flow. Never-valued operands reject E7005 at the operand with expected/found fields before later inputs or instruction emission; existing void mismatches remain unchanged. This covers calls, operators, aggregate inputs, conditions, ranges/indices, sizes, atomics, channels and stored values. `select` checks send values before endpoint borrows. Return/tail/statement/branch divergence remains valid. Variable assignment by name and var initialization retain ordinary binding/annotation checks; divergence skips a frame store just as it already did an SSA update. Place writes require a value: accepting a divergent RHS would otherwise bypass target checks, a regression found and corrected during independent read-only review with Claude. Attempted emission after unconditional divergence reports E7006 unreachable; a unit test verifies that the terminated block remains intact.
The preserved invariants are that no missing value becomes an operand or store and no write/borrow is emitted after control flow terminates. AIR independently retains its type, ownership, lifetime and effect/capability rules. Runtime cleanup, abnormal-path resource handling, deterministic execution and accepted-source canonical AIR are unchanged. Positive cases cover variable receivers in SSA/frame storage, normal/trapping branch paths, ownership and returned views; rejected cases cover non-value inputs and malformed place targets. Former compiler aborts now produce a diagnostic or valid variable-receiver divergence. Invalid diagnostic order may change, including place RHS errors before unknown targets. No new syntax, diagnostic code/reason, feature, verifier/runtime state or evaluation input changes. Source bundle growth is recorded in docs/agent/README.md. P6-2 remains open; Q-048 is the separately reproduced store-mode gap, and Q-044 remains an implementation-cost audit.
Validation: full conformance passes 1,497/1,497; unit tests and Zig formatting pass. The 75 new fixtures pass with collection before every instruction and the CLI suite passes 635 checks, including exact positions/fields across diagnostic commands, source/AIR/hosted trap/return parity, formatting and imported generic reachability. Existing constructor/literal/owning-array/linear CLI suites pass 302/152/119/49 checks. Final comparison on 1,136 preceding public sources (659 successful old lowerings) has zero changed check or canonical lower outputs. The formatter corpus passes 5,098 checks on the first 1,200 public files (1,192 parsed, eight existing syntax errors, 676 identical AIR outputs); CLI formatting covers all 75 new fixtures, including the eleven later additions. Source coverage remains 121/121.
+1
View File
@@ -406,6 +406,7 @@ A byte string or array used where a `slice<u8>` is expected is materialized in f
- Copy content of `own_array<T>` and the repeated value of `own.array`; an invalid content type is E7005 at that annotation/value, with `constraint: Copy` and `type_constructor: own_array`. Known linear content in unused generic signatures and static contracts MUST reject; unknown type parameters are checked after substitution.
- Inferred array literal elements MUST satisfy the existing member-position rules. Borrowed elements reject E7006 `invalid_literal`; other invalid constructors reject E7005 at the element with `position: member` and `type_constructor`. Lists preserve explicit linear transfers; repetitions MUST satisfy Copy.
- Inferred content of `own.new`, `own.pack`, `region.new`, `region.array`, `mutex.make`, `island.create`, `island.alloc` and `arc.new` MUST be a value: `void`/`never` reject E7005 at the content argument, with `position: member` and `type_constructor`. `own.new` and region storage MUST require Copy (E7005 with `constraint: Copy` and `operation`); `own.pack` MUST reject borrowed content (E7005 with `position: member` and `type_constructor`) while preserving complete linear transfers and failure recovery. These checks follow ordinary explicit-move checks and precede allocation authority checks. Graph-content properties, reserved transfers and concurrency checks otherwise retain their verifier diagnostics; `own.array` retains its Copy diagnostic above.
- A typed operand needed by an operation MUST yield a value: `never` rejects E7005 at that operand with `expected` and `found: never`, before later operands or instruction emission. This includes calls, operators, aggregate inputs, conditions, ranges, indices, sizes and the value stored through `*`, a field or an index. For a place store this check precedes borrowing/evaluating the target; an unknown target type uses `expected: a stored value`. Existing void/type mismatches retain their diagnostics. Divergence in returns, tails, statements and if/match arms remains valid. Assignment to a variable by name and `var` initialization MAY diverge after the ordinary binding/annotation checks; no store is emitted for either SSA or frame storage. `let` still requires a value. Expressions emitted after unconditional divergence MUST reject E7006 `unreachable`, never abort the compiler.
Source type annotations MUST satisfy the existing AIR type-position rules (spec 07 §8.3/§8.8), including nested constructors. An invalid constructor is E7005 at its annotation, with `position` and `type_constructor` fields. Known constructors in unused generic signatures and static function contracts MUST be checked; restrictions depending on a type parameter are checked after substitution. Graph-content properties and feature gates for otherwise correctly positioned types retain their verifier diagnostics.