test: migrate defdim len/cap family to test/lang @test, retire C twins (fold-2)

Continue fold-2: migrate drew's Family 2 (def-dimensioned array len/cap/slice
resolution) from bespoke build+run C twins to test/lang @test, retiring each
twin in the same commit. Runtime coverage MOVES from $(TESTS) to test-lang (T1
runs+asserts via `ww test`) + test-lang-byteid (T2 keeps cs==ww .s byte-id);
coverage is preserved, the $(TESTS) headline drops 3 (425->422). All asserts are
primitive int comparisons (no fmt/strconv in the assert path); the defcap rows
poison cap != len and assert both words so a dropped cap word FAILS.

  989_defdim_field_run.c    -> defdim_field_test.ww    (`.len` field-read on a def-dim [MAX]T resolves from the type table: local/let-global/def cgdot arms + sum)
  989_defdim_slice_run.c    -> defdim_slice_test.ww    (slicing a def-dim [MAX]T resolves len AND cap from the type table: default-hi + cgbasecap, local+global)
  989_defdim_argslice_run.c -> defdim_argslice_test.ww (def-dim slice passed as a call arg resolves default-hi len in the N_SLICE arg-push arms; litctrl pins the N_INTLIT path)

Bump LANGBYTEID_EXPECTED_MIN 31->34 to ratchet the new corpus floor.
This commit is contained in:
2026-06-22 12:04:03 +09:00
parent 438efab8c6
commit a367bf984e
7 changed files with 120 additions and 546 deletions

View File

@@ -0,0 +1,47 @@
// defdim_slice_test — slicing an array whose dimension is a `def` constant
// (`[MAX]T`) must resolve the length AND the capacity from the type table, not
// the AST dimension node, migrated from test/wcc/989_defdim_slice_run.c (#21).
// A `def MAX` dim arrives as a non-literal node; wwstage's cgslice default-hi
// fell to MOVQ $0 (len 0 -> underflow, exit 255) and cgbasecap returned false
// (cap fell back to len). The fix reads alen from the stamped array tinfo
// (rule-13) in both the local and global arms of both helpers. cstage reads the
// resolved bu->alen and was always correct; the defcap rows poison cap != len
// so a stage that drops the cap word FAILS. T2 keeps the cs==ww net.
//
// Two def constants (MAX4/MAX6) and two globals (g4/g6) since one package
// cannot redeclare `def MAX`; the def-dim path is exercised regardless of name.
package defdim_slice_test;
def MAX4: i32 = 4;
def MAX6: i32 = 6;
let g4: [MAX4]u8 = [10, 20, 30, 40];
let g6: [MAX6]u8 = [1, 2, 3, 4, 5, 6];
@test fn deflen_local() void = {
// local default-hi: cgslice reads N=4 from tinfo; buf[1:].len = 4-1 = 3.
let buf: [MAX4]u8 = [10, 20, 30, 40];
let s: []u8 = buf[1:];
assert(s.len: i32 == 3);
};
@test fn deflen_global() void = {
// global default-hi: g4[1:].len = 4-1 = 3.
let s: []u8 = g4[1:];
assert(s.len: i32 == 3);
};
@test fn defcap_local() void = {
// cgbasecap local: buf[2:4] over [6]u8 -> len 2, cap = 6-2 = 4 (cap != len).
let buf: [MAX6]u8 = [1, 2, 3, 4, 5, 6];
let s: []u8 = buf[2:4];
assert(s.len: i32 == 2);
assert(s.cap: i32 == 4);
};
@test fn defcap_global() void = {
// cgbasecap global: g6[2:4] -> len 2, cap = 6-2 = 4.
let s: []u8 = g6[2:4];
assert(s.len: i32 == 2);
assert(s.cap: i32 == 4);
};