Repository navigation
t27b: an untyped list local that the code indexes is a Zig tuple: constant indices, and run-time ones only at compile time #8050
Copy link
Copy link
Closed
Labels
Description
Part of #6063 (t27b coverage), which is item C10 of #6488. Split off from the notes on #7735.
What blocks
Two specs pass in the reference, but t27b blocks them on ExprArrayLiteral with the detail "array literal with no result type":
| spec | the local | how it is read |
|---|---|---|
specs/isa/ternary_gates.t27 |
const vals = [_]i32{TRIT_NEG, TRIT_ZERO, TRIT_POS};, ten times |
vals[i] with a var i inside the invariants, and inside the benches |
specs/port/scripts/ultra_engine_v70_ultimate.t27 |
const targets = []PDGTarget{ PDGTarget{ name: "W_mass", ... }, ... }; |
targets[0].value in a test |
ternary_gates' second blocker, ExprCall(@setEvalBranchQuota), is gone on master since #7459. On master 2dfe978, ExprArrayLiteral is the only construct t27b reports for either file.
What the reference does
Measured with t27c test-report (zig 0.16.0, t27c lab):
t27c gendrops the literal's type and printsconst vals = .{ ... };. That is a Zig tuple whose fields have the element values' types, and which are comptime fields where the values are compile-time known.- A compile-time index works:
vals[0],ts[1].v. An assert on such a field is folded, so it is vacuous, unless a call reads it. - A run-time index in run-time code does not compile: "unable to resolve comptime value". This holds for typed consts, literals, struct elements, and inside a fn.
- A run-time index inside a
comptime {}block, which is how an invariant is printed, works, because the whole block runs at compile time. - A bench is an uncalled fn, so Zig never analyzes it.
The step
- A conformance spec first,
specs/tri/t27b/conformance/tuple_local_index.t27. It covers typed-const elements and struct elements with a str field, both at constant indices with calls reading them, and an invariant that indexes in a loop. Reference: 2/2, 6 runtime asserts, 0 vacuous. - The decisions go in a t27 plan through
t27c gen-rust:- Which locals are taken: the literal names its element type T, and every element is a struct literal of T or a module const declared as T.
- Where they live: read-only data, which folds constant reads as Zig's comptime fields do, or a constant aggregate where T holds a str.
- A run-time index outside an invariant, a bench or a fn no test reaches is refused by name as
ExprIndex(tuple), as Zig refuses it.
- Ledger: both specs move to pass.
User Scenarios
- Given a spec declares a const local as an untyped list literal with struct elements, and code reads it at a constant index inside a called function, When t27b compiles the spec, Then the read succeeds and the value is available at runtime.
- Given a spec declares a const local as an untyped list literal and an invariant indexes it with a loop variable inside a
comptime {}block, When t27b compiles the spec, Then the invariant runs at compile time and the indexing succeeds. - Given a spec declares a const local as an untyped list literal and a bench function indexes it with a runtime variable, When t27b compiles the spec, Then compilation fails with a clear error naming
ExprIndex(tuple)because runtime indexing of a tuple is not allowed.
Requirements
- FR-001: t27b MUST recognize an untyped list local as a tuple candidate when every element is a struct literal of the same declared type T or a module const declared as T.
- FR-002: t27b MUST lower such a local to read-only data that folds constant-index reads at compile time, or to a constant aggregate when T contains a
strfield. - FR-003: t27b MUST accept constant-index reads of the tuple in called functions and in
comptime {}blocks (invariants). - FR-004: t27b MUST reject runtime-index reads outside
comptime {}, benches, or unreached functions with an error that namesExprIndex(tuple). - FR-005: The new conformance spec
specs/tri/t27b/conformance/tuple_local_index.t27MUST cover typed-const elements, struct elements with astrfield, constant-index calls, and a loop-indexed invariant.
Success Criteria
t27c test specs/tri/t27b/conformance/tuple_local_index.t27exits withexit 0and reports 2/2 tests passing, 6 runtime asserts, 0 vacuous.t27c test specs/isa/ternary_gates.t27exits withexit 0(previously blocked onExprArrayLiteral).t27c test specs/port/scripts/ultra_engine_v70_ultimate.t27exits withexit 0(previously blocked onExprArrayLiteral).t27c gen-rust specs/tri/t27b/conformance/tuple_local_index.t27produces a plan that identifies the tuple locals and their read-only data placement.
Boundary
- specs/tri/t27b/conformance/tuple_local_index.t27
- specs/isa/ternary_gates.t27
- specs/port/scripts/ultra_engine_v70_ultimate.t27
- cli/t27b/src/lower/tuple.rs
- scripts/tri_loop/t27b.py
Reactions are currently unavailable
Activity
Merge master 09ffc2f into t27b-tuple-local-8050 (Closes #8050)
Merge master 12ee225 into t27b-tuple-local-8050 (Closes #8050)
Merge master 35e6996 into t27b-tuple-local-8050 (Closes #8050)
Merge master a97cb9e into t27b-tuple-local-8050 (Closes #8050)
Merge master a561d6d into t27b-tuple-local-8050 (Closes #8050)
t27b: port the tuple rules of lower/tuple.rs into tuple_local_plan.t2…
Merge master afc601f into t27b-tuple-local-8050 (Closes #8050)
Merge master e3b8c51 into t27b-tuple-local-8050 (Closes #8050)
Merge master 0fca4bd into t27b-tuple-local-8050 (Closes #8050)
Merge master d2b5fc1 into t27b-tuple-local-8050 (Closes #8050)
t27b: an untyped list local that the code indexes lowers as a tuple, …
Merge master b9d22d0 into the source-text port (Closes #8248)
Merge master b9d22d0 into the body-walk port (Closes #8249)