wwstage: accept module-level const/let slice-from-arrlit (#28)

wwstage rejected a module-level `const/let []T = [arrlit]` global with "let: not assignable"; cstage accepts (textbook Hare, ref/hare/path/stack.ha:30). The arrlit->slice admission in checkletassign was gated local-only; lift it to module scope too, aligning wwstage UP to cstage's arrlit_init_fits (check.c:3406-3409, slice arm 519-520). cstage unchanged.

Two guards the un-gating requires: the n.rhs.lhs=arr stash stays local-only (a module decl keeps its raw N_ARRLIT for DATA emit, so stashing would leave an untyped count node for the pass-3 asserttyped walker); and tuple-element slice globals are excluded at module scope, because the synthesis delegates element checks to isassignable which lacks a strict tuple arm (#38) -- a [](str,*fn) table would over-accept a sig-mismatched &fn that cstage's strict type_assignable rejects (#124) -- so they stay on the existing typeeqast path.

Closes two divergences 944_alias_emit_b7 pinned: Group A (cstage-runs/ww-rejects) migrates to test/lang/slice_global_arg_test.ww (promoted from _runonly, now cs==ww byte-id); Group B converges to a shared emit_slice_data reject with the identical diagnostic.
This commit is contained in:
2026-06-26 23:16:19 +09:00
parent f476797a47
commit e60297085d
4 changed files with 172 additions and 92 deletions

View File

@@ -1,52 +0,0 @@
// slice_global_arg_runonly_test — #148 (D2): a module-global slice passed BY
// VALUE as a slice arg must arrive with a real header, not garbage. Migrated
// from test/wcc/953_globalslice_arg_run.c.
//
// _runonly: CSTAGE-ONLY. wwstage's checker rejects a module-level `const []T`
// global ("let: not assignable", filed task #28), so this file does not compile
// under w6c_ww and is excluded from the T2 byte-id corpus. test-lang runs it
// through the cstage `ww test` only.
//
// Pre-fix the slice-ident call-arg fast path emitted BP-relative pushes for a
// global (localfind→0), reading saved-BP/RIP garbage instead of the global's
// header at name(SB). The fix mirrors the N_SLICE arm's isglobal dispatch. The
// callee reads .len AND a byte, so a wrong header is observable; u32_global
// pins the path is element-width-agnostic; direct_read + local_arg lock the
// in-place read and the off!=0 local arm against regression.
package slice_global_arg_runonly_test;
const dotdot: []u8 = ['.', '.'];
const dot: []u8 = ['.'];
const g: []u32 = [7u32, 8u32, 9u32];
const d: []u32 = [11u32, 22u32];
fn seen_u8(bs: []u8) i32 = {
return bs.len: i32 * 1000 + bs[0]: i32;
};
fn seen_u32(xs: []u32) i32 = {
return xs.len: i32 * 100 + xs[0]: i32 + xs[2]: i32;
};
@test fn u8_dotdot() void = {
assert(seen_u8(dotdot) == 2046);
};
@test fn u8_dot() void = {
assert(seen_u8(dot) == 1046);
};
@test fn u32_global() void = {
assert(seen_u32(g) == 316);
};
@test fn direct_read() void = {
assert(d.len: i32 * 100 + d[0]: i32 + d[1]: i32 == 233);
};
@test fn u8_local_arg() void = {
let a: [2]u8 = ['.', '.'];
let s: []u8 = a[0:2];
assert(seen_u8(s) == 2046);
};

View File

@@ -0,0 +1,116 @@
// slice_global_arg_test — module-global slice/array constants, two folded
// concerns that share these globals:
//
// #148 (D2): a module-global slice passed BY VALUE as a slice arg must arrive
// with a real header, not garbage. Migrated from test/wcc/953_globalslice_arg_run.c.
// Pre-fix the slice-ident call-arg fast path emitted BP-relative pushes for a
// global (localfind→0), reading saved-BP/RIP garbage instead of the global's
// header at name(SB). The fix mirrors the N_SLICE arm's isglobal dispatch.
//
// #28: wwstage's checker REJECTED a module-level `const/let []T = [..]`
// ("let: not assignable") while cstage accepted — the slice-from-arrlit
// admission was gated local-only. const dotdot/dot/g/d below are the exact
// shape (ref/hare/path/stack.ha:30 `const dotdot: []u8 = ['.', '.'];`). This
// file was a `_runonly` (cstage-only) carrier until that fix; promoting it
// drops the suffix and re-arms the cs==ww byte-id net over the slice globals.
//
// The element values discriminate a real header from garbage; u32_global pins
// the path element-width-agnostic; the const/let/[_] table-driven readbacks pin
// the #28 admission across const, mutable let, and the inferred-array form.
package slice_global_arg_test;
type my64 = i64;
type my64b = my64;
const dotdot: []u8 = ['.', '.'];
const dot: []u8 = ['.'];
const g: []u32 = [7u32, 8u32, 9u32];
const d: []u32 = [11u32, 22u32];
// #28: a wider-element slice global, and a 2-level-alias element type — both
// converged from cstage-only (was test/wcc/944 Group A slc_plain_ctl / slc_2lvl,
// where wwstage rejected at the let checker) to cs==ww byte-id once the
// module-scope slice-from-arrlit admission landed.
let gi64: []i64 = [5, 6, 7];
let galias: []my64b = [5, 6, 7];
// #28: a MUTABLE `let` slice global must be accepted identically to `const`
// (shared decl path; the pre-fix error said "let:" even for const).
let lu8: []u8 = [10u8, 20u8, 30u8];
// #28 subtlety 2: rune-lit elements coerce into u8 via the SAME per-element
// path; `[_]u8` is the inferred-length ARRAY form, not a slice.
const carr: [_]u8 = ['a', 'b'];
fn seen_u8(bs: []u8) i32 = {
return bs.len: i32 * 1000 + bs[0]: i32;
};
fn seen_u32(xs: []u32) i32 = {
return xs.len: i32 * 100 + xs[0]: i32 + xs[2]: i32;
};
@test fn u8_dotdot() void = {
assert(seen_u8(dotdot) == 2046);
};
@test fn u8_dot() void = {
assert(seen_u8(dot) == 1046);
};
@test fn u32_global() void = {
assert(seen_u32(g) == 316);
};
@test fn direct_read() void = {
assert(d.len: i32 * 100 + d[0]: i32 + d[1]: i32 == 233);
};
@test fn u8_local_arg() void = {
let a: [2]u8 = ['.', '.'];
let s: []u8 = a[0:2];
assert(seen_u8(s) == 2046);
};
// #28: const []u8 element readback, table-driven over the declared elements.
@test fn const_slice_elems() void = {
let want: [2]u8 = [46u8, 46u8];
assert(dotdot.len == 2);
let i: i32 = 0;
for (i < dotdot.len: i32) {
assert(dotdot[i] == want[i]);
i += 1;
};
};
// #28: mutable `let []u8` global — accept + element readback.
@test fn let_slice_elems() void = {
let want: [3]u8 = [10u8, 20u8, 30u8];
assert(lu8.len == 3);
let i: i32 = 0;
for (i < lu8.len: i32) {
assert(lu8[i] == want[i]);
i += 1;
};
};
// #28: const [_]u8 rune-lit array form — accept + element readback.
@test fn const_array_elems() void = {
let want: [2]u8 = [97u8, 98u8];
assert(carr.len == 2);
let i: i32 = 0;
for (i < carr.len: i32) {
assert(carr[i] == want[i]);
i += 1;
};
};
// #28: wider-element ([]i64) and 2-level-alias-element ([]my64b) slice globals
// (ex test/wcc/944 Group A) — accept + element readback.
@test fn wide_and_alias_slice() void = {
assert(gi64.len == 3);
assert(gi64[0] + gi64[1] + gi64[2] == 18);
assert(galias.len == 3);
assert(galias[0] + galias[1] + galias[2] == 18);
};

View File

@@ -4,19 +4,24 @@
* symmetric K_BUILDERR rejects (slcstr_plain_ctl, slcslc_2lvl) to
* test/wcc/data/alias_{slcstr_plain,slcslc}/case.ww runww //ww:error.
*
* What survives here are the 4 IRREDUCIBLE per-stage rows neither in-language
* surface can host (ken's emit_slice_data observation cells — load-bearing
* codegen pins, MUST NOT move):
* • slc_2lvl / slc_plain_ctl (Group A): cstage builds+RUNS exit 0; wwstage
* LOUD-REJECTS at the let checker ("let: not assignable"). cstage emits the
* []my64b / []i64 slice-literal global DATA and runs; the ww checker
* rejects every slice-literal global (the #120/#29-kin acceptance
* divergence, ken-d2-oracle; pre-slim #66-R2/#29). @test needs ww to
* build, //ww:error needs cs to fail — neither fits.
* • slcstr_2lvl / slctag_2lvl (Group B): BOTH reject but with DIFFERENT
* diagnostics (cs at emit_slice_data 3-way "static-init unsupported"; ww at
* the let checker "not assignable") — a held cs!=ww divergence; the two
* messages ARE the pin, so each stage's own substring is asserted.
* What survives here are the 2 IRREDUCIBLE both-stage emit-reject rows neither
* in-language surface can host (ken's emit_slice_data observation cells —
* load-bearing codegen pins, MUST NOT move):
* • slcstr_2lvl / slctag_2lvl: a slice-of-{str,tagged} literal GLOBAL is
* admitted by BOTH checkers and then LOUD-REJECTED at emit_slice_data
* ("slice-of-{str,slice,tagged} literal static-init unsupported", a rule-7
* deferred #10 follow-up) in BOTH stages with the IDENTICAL message. @test
* needs a build, runww //ww:error drives one path — a dual-stage emit
* reject fits neither, so each stage's reject is asserted directly here.
*
* HISTORY (#28): Group A (slc_2lvl []my64b / slc_plain_ctl []i64, cstage-runs /
* wwstage-checker-rejects) and Group B's old wwstage HALF (the ww checker
* rejected EVERY slice-literal global at "let: not assignable") were both that
* pre-#28 divergence. Once the module-scope slice-from-arrlit admission landed
* (selfhost check.ww checkletassign), wwstage admits these globals at the
* checker exactly as cstage does: Group A converged to cs==ww build+run and
* migrated to test/lang/slice_global_arg_test.ww; Group B converged to the
* shared emit_slice_data reject below.
*/
#include <stdio.h>
#include <stdlib.h>
@@ -105,24 +110,6 @@ run_row(const char *bin, const struct row *r, int i)
}
static const struct row rows[] = {
{ "slc_2lvl",
"package main;\n"
"type my64 = i64;\n"
"type my64b = my64;\n"
"let G: []my64b = [5, 6, 7];\n"
"export fn main() i32 = {\n"
" if (G[0] + G[1] + G[2] != 18) { return 1; };\n"
" if (len(G) != 3) { return 2; };\n"
" return 0;\n"
"};\n", M_CSRUN_WWERR, NULL, "let: not assignable" },
{ "slc_plain_ctl",
"package main;\n"
"let G: []i64 = [5, 6, 7];\n"
"export fn main() i32 = {\n"
" if (G[0] + G[1] + G[2] != 18) { return 1; };\n"
" if (len(G) != 3) { return 2; };\n"
" return 0;\n"
"};\n", M_CSRUN_WWERR, NULL, "let: not assignable" },
{ "slcstr_2lvl",
"package main;\n"
"type ms0 = str;\n"
@@ -133,7 +120,7 @@ static const struct row rows[] = {
" return 0;\n"
"};\n", M_BOTHERR,
"slice-of-{str,slice,tagged} literal static-init unsupported",
"let: not assignable" },
"slice-of-{str,slice,tagged} literal static-init unsupported" },
{ "slctag_2lvl",
"package main;\n"
"type u0 = (void | i64);\n"
@@ -144,7 +131,7 @@ static const struct row rows[] = {
" return 0;\n"
"};\n", M_BOTHERR,
"slice-of-{str,slice,tagged} literal static-init unsupported",
"let: not assignable" },
"slice-of-{str,slice,tagged} literal static-init unsupported" },
};
int