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.
117 lines
3.7 KiB
Plaintext
117 lines
3.7 KiB
Plaintext
// 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);
|
|
};
|