Repository navigation
t27b: @intCast as an array index or a slice bound takes Zig's usize result type (specs/numeric/ocp_mx.t27) #7902
Description
Part of #6063 (t27b coverage), item C10 of #6488.
What ocp_mx.t27 needs
specs/numeric/ocp_mx.t27 passes the reference (49 of 49 tests) and t27b refuses it: t27b test --blockers (master bbb77f0) names ExprCall(@intCast) at 42 sites, every one an array index, as in POW2[@intCast(e - 1)] and KIND_TOP[@intCast(kind)]. #7627 lowers @intCast only where the context names an integer type (@as, a typed binding, a parameter, a return). An index is not one of those contexts in t27b today, so the call has no result type there and is refused.
What the reference does
gen-zig prints POW2[@intCast(e - 1)] as written. In Zig 0.16 an index, and each bound of a slice, has the result type usize, so a[@intCast(k)] converts k exactly as @as(usize, @intCast(k)) would:
- an i64 or an i32 operand is checked, and a negative value is a safety panic in a Debug build (a failed test);
- a u8 or a u32 widens; a usize is kept;
- a literal folds, and a negative literal is a compile error.
The index is then bounds-checked as any index is.
Plan
specs/tri/t27b/int_cast_plan.t27names the result type an index and a slice bound give (INDEX_TYPE,usize). Its tests showplan's answers there: an i64 is checked and traps when negative, a u8 widens, a usize is kept, a literal folds or is refused.- The glue lowers an
@intCastindex or slice bound through the existingint_castwith that type. It adds no new decision. - A conformance spec in ocp_mx's shapes:
specs/tri/t27b/conformance/int_cast_index.t27. The trap case (a negative index) joinscli/t27b/tests/int_cast_traps.t27.
Acceptance criteria
t27b test --blockers specs/numeric/ocp_mx.t27names noExprCall(@intCast).- The conformance spec passes under
t27c test-reportwith 0 vacuous tests, and the same tests pass under t27b. - The lab corpus receipt compare gives IMPROVED_ONLY, EQUIVALENT or NEUTRAL.
User Scenarios
- Given
specs/numeric/ocp_mx.t27contains array index expressions using@intCastsuch asPOW2[@intCast(e - 1)], whent27b test --blockers specs/numeric/ocp_mx.t27runs, then it names noExprCall(@intCast)blockers. - Given a conformance spec
specs/tri/t27b/conformance/int_cast_index.t27covering index and slice-bound@intCastwith i64, u8, usize, and literal operands, whent27c test-reportruns that spec, then it passes with 0 vacuous tests and the same tests pass under t27b. - Given a negative i64 index used as
@intCastin an array access, when the generated Zig runs in a Debug build, then it triggers a safety panic (trap) consistent withcli/t27b/tests/int_cast_traps.t27.
Requirements
- FR-001: The t27b lowering for
@intCastwhen used as an array index or slice bound MUST assign the result typeusize(theINDEX_TYPEfromspecs/tri/t27b/int_cast_plan.t27). - FR-002: The lowering MUST reuse the existing
int_castlowering path with thatusizeresult type; no new lowering decision logic is introduced. - FR-003: The conformance spec
specs/tri/t27b/conformance/int_cast_index.t27MUST cover widening (u8→usize), preservation (usize→usize), checked conversion with trap on negative (i64→usize), literal folding, and negative literal rejection. - FR-004: The trap behavior for negative index values MUST be exercised by
cli/t27b/tests/int_cast_traps.t27and pass under t27b. - FR-005: After the change,
t27b test --blockers specs/numeric/ocp_mx.t27MUST report zeroExprCall(@intCast)sites.
Boundary
- specs/numeric/ocp_mx.t27
- specs/tri/t27b/int_cast_plan.t27
- specs/tri/t27b/conformance/int_cast_index.t27
- cli/t27b/tests/int_cast_traps.t27
Activity
Merge master 76836e2 into t27b-int-cast-index-7902 (Closes #7902)
Merge master e87e790 into t27b-int-cast-index-7902 (Closes #7902)
Merge master 430c522 into t27b-int-cast-index-7902 (Closes #7902)
Merge master 408d740 into t27b-int-cast-index-7902 (Closes #7902)
Merge master e66473f into t27b-int-cast-index-7902 (Closes #7902)
Merge master 4270760 into t27b-int-cast-index-7902 (Closes #7902)
Merge master 2dfe978 into t27b-int-cast-index-7902 (Closes #7902)
Merge master 6b6386e into t27b-int-cast-index-7902 (Closes #7902)
Merge master 09ffc2f into t27b-int-cast-index-7902 (Closes #7902)
Merge master 12ee225 into t27b-int-cast-index-7902 (Closes #7902)
Merge master 6cd8fba into t27b-int-cast-index-7902 (Closes #7902)
Merge master 35e6996 into t27b-int-cast-index-7902 (Closes #7902)
Merge master a97cb9e into t27b-int-cast-index-7902 (Closes #7902)
Merge master f21a0b3 into t27b-int-cast-index-7902; can_widen_from is…
Merge master cde548e into t27b-int-cast-index-7902; no hand lines add…
Merge master b9d22d0 into t27b-int-cast-index-7902; no hand lines add…
Merge master 3ac8bef into t27b-int-cast-index-7902; no hand lines add…
Merge master 325b0b1 into t27b-int-cast-index-7902; no hand lines add…
Merge master ab5b3b7 into t27b-int-cast-index-7902; no hand lines add…
Merge master 54f3c14 into t27b-int-cast-index-7902; no hand lines add…
Merge master e4338f4 into t27b-int-cast-index-7902; no hand lines add…