Skip to content

t27b: an untyped list local that the code indexes is a Zig tuple: constant indices, and run-time ones only at compile time #8050

Closed

Description

@gHashTag

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 gen drops the literal's type and prints const 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

  1. 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.
  2. 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.
  3. 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 str field.
  • 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 names ExprIndex(tuple).
  • FR-005: The new conformance spec specs/tri/t27b/conformance/tuple_local_index.t27 MUST cover typed-const elements, struct elements with a str field, constant-index calls, and a loop-indexed invariant.

Success Criteria

  • t27c test specs/tri/t27b/conformance/tuple_local_index.t27 exits with exit 0 and reports 2/2 tests passing, 6 runtime asserts, 0 vacuous.
  • t27c test specs/isa/ternary_gates.t27 exits with exit 0 (previously blocked on ExprArrayLiteral).
  • t27c test specs/port/scripts/ultra_engine_v70_ultimate.t27 exits with exit 0 (previously blocked on ExprArrayLiteral).
  • t27c gen-rust specs/tri/t27b/conformance/tuple_local_index.t27 produces 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

Activity

  1. added 10 commits that reference this issue on Oct 9, 2026
    2cfebc2
    3e5f119
    9199e4f
    6c9cf6b
    122d9ab
    036e494
    d7486a5
    7cee5dc
    004890e
    c0b90a8
  2. added 3 commits that reference this issue on Oct 9, 2026
    b9e6216
    c6b5ced
    d6073bc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions