w6c_ww: tinfo re-key of the cgdot N_INDEX-base arm (F7/F10)

The wwstage `arr[i].field` read arm was syntactic where cstage is
type-table-driven: element typing keyed on tnode KINDs (N_TSLICE/
N_TARRAY/N_TPTR) with an N_TNAME element resolved by structlookup
NAME — any base typed via an alias (`type result = []capture`,
p11b/F10) missed every gate and died at the interim C2 loud guard
(pre-C2: fell silently to the SB fallback). Re-key the arm onto the
checker-stamped tinfo (lhs.type_ element / idxbase.type_ base, NAMED
peeled), mirroring cstage cgen.c case N_DOT's N_INDEX-lhs arm 1:1 —
the #209/#211 name-keyed->tinfo-SSoT cluster. Emission sequence is
unchanged; the C2 "C3/task #8" guard retires with the arm wired
(task #37's ptr-chain guard is untouched). Global classification
mirrors cstage let_islet || def_isarraydef via isletvar /
defvartnode-N_TARRAY (the cgplaceaddr C2 pattern).

F7/FA5/FA3-ww/FA6 (non-ident idxbase shapes, task #17's ww halves)
were already closed by C2's read-resolver recursion; p7_composed,
pA5, pA9 run exit-0 byte-id and are pinned as rows here. Task #29's
asserttyped bail (strings.frombytes over a slice-expr in the
composed context) no longer reproduces at HEAD — dissolved during
the C1.25->C2 arc; p7_composed builds clean on w6c_ww, runs 0,
byte-id.

Behind the retired guard three alias-blind NON-cgdot sites surface
(`let l: wlist = []` checker reject / alias-array global emits no
DATA / alias-array arrlit-init under-copies 8B per element, cs!=ww
runtime): filed as task #38, same name-keyed class, separate sites.

test/805: +5 rows — alias-slice field-kind matrix, alias-array +
viaptr-element bases, p11b-essence let-bound alias reads (the
task-#14 `?` factored out), the composed p7 match/compound hot
shape, and the pA9 free()-operand acceptance row (FA6).

Task #8; the last cgen gate before regex tranche B.
This commit is contained in:
2026-06-04 11:34:16 +09:00
parent 76994a8279
commit 074e68f05d
4 changed files with 665 additions and 468 deletions

View File

@@ -35,9 +35,17 @@
* offset-0 scalars worked by coincidence). TK_AMP's silent tail is the
* same resolver-or-loud (`&threads[0].cap` used to SEGFAULT on deref,
* reviewer-A route). The C1.25 raw-byte readbacks graduate to typed
* depth-2 reads below. wwstage cgdot/cgun mirror symmetrically; its
* name-keyed ident-indexed arm gap stays LOUD (C3/task #8 re-key), as
* does the ptr-chained global-root remainder (task #37).
* depth-2 reads below. wwstage cgdot/cgun mirror symmetrically; the
* ptr-chained global-root remainder stays LOUD (task #37).
*
* C3 (F7+F10, task #8): wwstage's cgdot N_INDEX-base arm re-keyed from
* tnode KINDs + structlookup-by-name onto the checker-stamped tinfo
* (#209/#211 name-keyed→tinfo-SSoT cluster), mirroring cstage's arm
* 1:1. Pre-C3 a base typed via an N_TNAME alias (`type result =
* []capture`) missed the name-keyed arm and died at the interim C2
* loud guard (and pre-C2, fell silently into the SB fallback). The
* c3_* rows below pin the alias-typed base class plus the composed
* regex hot shape and the free()-operand consumption (FA6).
*
* row | shape | want
* --------------------+----------------------------------------+------
@@ -86,6 +94,17 @@
* reject_assign_callbs| mk()[0].pc = (assign-tail text keeps | BUILD_FAIL
* | its carrier post arr_field_idx_store) |
* reject_addrof_callbs| &mk()[0].pc (TK_AMP loud tail) | BUILD_FAIL
* c3_alias_slice_reads| F10: alias-slice base l[i].f — narrow | 65
* | signed/unsigned, i64, f64, str, []T, |
* | [N]T-field-then-index |
* c3_alias_arr_viaptr | F10: alias [2]S base + alias []*S | 66
* | (viaptr element) reads |
* c3_letbound_alias | p11b essence sans task-#14 `?`: let | 67
* | m: result = f(); m[i].field reads |
* c3_composed_match | F7: match(re.insts[(*ts)[i].pc]) + | 68
* | (*ts)[i] compound/store (p7 hot shape) |
* c3_free_operand | FA6: free((*ts)[i].slicefield) reads | 69
* | through the operand (pA9) |
*
* BUILD_FAIL rows also assert the diagnostic TEXT (stderr substring,
* both stages) — a build that fails for any other reason (parse error,
@@ -911,6 +930,190 @@ static const struct row rows[] = {
"\treturn (*p): i32;\n"
"};\n",
BUILD_FAIL, "unsupported address-of shape" },
/* C3 (task #8) F10 class: the index BASE is typed via an N_TNAME
* alias — pre-C3 wwstage's name-keyed arm missed it (interim C2
* loud guard). Field-kind matrix mirrors the cstage arm's
* dispatch: narrow signed/unsigned, 8B, float, str header, slice
* header, [N]T field as outer-index base (#270-1a). Construction
* goes through DIRECT-typed locals: the alias-typed `= []` /
* arrlit-init/global-DATA sites are a separate filed family
* (unmasked behind C3, not cgdot). */
{ "c3_alias_slice_reads",
"package main;\n"
"type wide = struct { b: u8, w: i16, d: u32, q: i64, f: f64,\n"
"\ts: str, xs: []size, m: [2]u32 };\n"
"type wlist = []wide;\n"
"fn mkw(k: i64) wide = {\n"
"\tlet xs: []size = [];\n"
"\tlet x0: size = (10 + k): size;\n"
"\tlet x1: size = (20 + k): size;\n"
"\tappend(xs, x0);\n"
"\tappend(xs, x1);\n"
"\tlet m0: u32 = (40 + k): u32;\n"
"\tlet m1: u32 = (50 + k): u32;\n"
"\treturn wide { b = (k + 1): u8, w = (0 - k): i16,\n"
"\t\td = (100 + k): u32, q = k, f = 2.5f64, s = \"ab\",\n"
"\t\txs = xs, m = [m0, m1] };\n"
"};\n"
"export fn main() i32 = {\n"
"\tlet l0: []wide = [];\n"
"\tlet w1: wide = mkw(1);\n"
"\tlet w2: wide = mkw(2);\n"
"\tappend(l0, w1);\n"
"\tappend(l0, w2);\n"
"\tlet l: wlist = l0;\n"
"\tif (l[0].b != 2u8) { return 1; };\n"
"\tif (l[0].w != -1i16) { return 2; };\n"
"\tif (l[1].d != 102u32) { return 3; };\n"
"\tif (l[1].q != 2i64) { return 4; };\n"
"\tif (l[0].f != 2.5f64) { return 5; };\n"
"\tif (l[0].s.len != 2) { return 6; };\n"
"\tif (l[1].xs[1] != (22: size)) { return 7; };\n"
"\tif (l[0].m[1] != 51u32) { return 8; };\n"
"\treturn 65;\n"
"};\n",
65, NULL },
/* F10 sibling bases: alias-typed [2]S array (local), and an
* alias-typed []*S whose ELEMENT is a pointer (the arm's viaptr
* deref hop). */
{ "c3_alias_arr_viaptr",
"package main;\n"
"type wide = struct { b: u8, q: i64, xs: []size };\n"
"type warr = [2]wide;\n"
"type pw = *wide;\n"
"type plist = []pw;\n"
"fn mkw(k: i64) wide = {\n"
"\tlet xs: []size = [];\n"
"\tlet x0: size = (10 + k): size;\n"
"\tappend(xs, x0);\n"
"\treturn wide { b = (k + 1): u8, q = k, xs = xs };\n"
"};\n"
"export fn main() i32 = {\n"
"\tlet w3: wide = mkw(3);\n"
"\tlet w4: wide = mkw(4);\n"
"\tlet a0: [2]wide = [w3, w4];\n"
"\tlet a: warr = a0;\n"
"\tif (a[0].q != 3i64) { return 1; };\n"
"\tif (a[1].b != 5u8) { return 2; };\n"
"\tlet w5: wide = mkw(5);\n"
"\tlet ps0: []pw = [];\n"
"\tappend(ps0, &w5);\n"
"\tlet ps: plist = ps0;\n"
"\tif (ps[0].q != 5i64) { return 3; };\n"
"\tif (ps[0].b != 6u8) { return 4; };\n"
"\tif (ps[0].xs[0] != (15: size)) { return 5; };\n"
"\treturn 66;\n"
"};\n",
66, NULL },
/* p11b's F10 essence with the task-#14-gated `?` factored out: a
* let bound from a fn returning the alias, indexed-field reads off
* it (m's tnode is the N_TNAME alias `result`). */
{ "c3_letbound_alias",
"package main;\n"
"type capture = struct { content: str, start: size, end: size };\n"
"type result = []capture;\n"
"fn mk() result = {\n"
"\tlet caps: []capture = [];\n"
"\tappend(caps, capture { content = \"xy\", start = 1, end = 3 });\n"
"\tappend(caps, capture { content = \"z\", start = 4, end = 5 });\n"
"\treturn caps;\n"
"};\n"
"export fn main() i32 = {\n"
"\tlet m: result = mk();\n"
"\tif (len(m) != 2) { return 1; };\n"
"\tif (m[0].start != 1) { return 2; };\n"
"\tif (m[0].content.len != 2) { return 3; };\n"
"\tif (m[1].end != 5) { return 4; };\n"
"\treturn 67;\n"
"};\n",
67, NULL },
/* F7: the composed regex run_thread hot shape — a tagged-slice
* field indexed by a deref-index-field chain, match-dispatched,
* plus compound/store back through the same spine (p7_composed
* core; the strings.frombytes tail lives with task #29). */
{ "c3_composed_match",
"package main;\n"
"type inst_lit = rune;\n"
"type inst_any = void;\n"
"type inst_match = bool;\n"
"type inst = (inst_lit | inst_any | inst_match);\n"
"type re_t = struct { insts: []inst, n_reps: size };\n"
"type capture = struct { content: str, start: size, end: size };\n"
"type thread = struct { pc: size, root_capture: capture, failed: bool };\n"
"fn step(re: *re_t, ts: *[]thread, i: size) i32 = {\n"
"\tmatch (re.insts[(*ts)[i].pc]) {\n"
"\tcase let lt: inst_lit => {\n"
"\t\t(*ts)[i].root_capture = capture { content = \"hit\", start = 2, end = 4 };\n"
"\t\t(*ts)[i].pc += 1;\n"
"\t\treturn 1;\n"
"\t};\n"
"\tcase inst_any => {\n"
"\t\t(*ts)[i].failed = true;\n"
"\t\treturn 2;\n"
"\t};\n"
"\tcase let m: inst_match => {\n"
"\t\t(*ts)[i].pc += 2;\n"
"\t\treturn 3;\n"
"\t};\n"
"\t};\n"
"\treturn 9;\n"
"};\n"
"export fn main() i32 = {\n"
"\tlet insts: []inst = [];\n"
"\tappend(insts, ('a': inst_lit));\n"
"\tlet av: inst_any;\n"
"\tlet v: inst = av;\n"
"\tappend(insts, v);\n"
"\tappend(insts, (true: inst_match));\n"
"\tlet re: re_t = re_t { insts = insts, n_reps = 0 };\n"
"\tlet ts: []thread = [];\n"
"\tlet z: capture = capture { content = \"\", start = 0, end = 0 };\n"
"\tappend(ts, thread { pc = 0, root_capture = z, failed = false });\n"
"\tif (step(&re, &ts, 0) != 1) { return 1; };\n"
"\tif (ts[0].pc != 1) { return 2; };\n"
"\tif (ts[0].root_capture.start != 2) { return 3; };\n"
"\tif (step(&re, &ts, 0) != 2) { return 4; };\n"
"\tif (!ts[0].failed) { return 5; };\n"
"\tlet p: *[]thread = &ts;\n"
"\t(*p)[0].pc += 1;\n"
"\tif (ts[0].pc != 2) { return 6; };\n"
"\tif (step(&re, &ts, 0) != 3) { return 7; };\n"
"\tif (ts[0].pc != 4) { return 8; };\n"
"\treturn 68;\n"
"};\n",
68, NULL },
/* FA6 (pA9): free() consumes its operand via cgexpr — the
* deref-index-field reads inside the operand are C3's reads, the
* free arm itself is sound. Pure acceptance row. */
{ "c3_free_operand",
"package main;\n"
"type capture = struct { content: str, start: size };\n"
"type thread = struct { pc: size, captures: []capture,\n"
"\trep_counters: []size };\n"
"fn delete_thread(i: size, threads: *[]thread) void = {\n"
"\tfree((*threads)[i].captures);\n"
"\tfree((*threads)[i].rep_counters);\n"
"\tdelete((*threads)[i]);\n"
"};\n"
"export fn main() i32 = {\n"
"\tlet z: []capture;\n"
"\tlet zr: []size;\n"
"\tlet xs: []thread = [];\n"
"\tappend(xs, thread { pc = 1, captures = z, rep_counters = zr });\n"
"\tappend(xs, thread { pc = 2, captures = z, rep_counters = zr });\n"
"\tappend(xs, thread { pc = 3, captures = z, rep_counters = zr });\n"
"\tdelete_thread(1, &xs);\n"
"\tif (len(xs) != 2) { return 1; };\n"
"\tif (xs[0].pc != 1) { return 2; };\n"
"\tif (xs[1].pc != 3) { return 3; };\n"
"\treturn 69;\n"
"};\n",
69, NULL },
};
/* errlog_has — the build-failure stderr must carry the row's expected