test: port 794_xmod_ident_prefer to collide_test; retire the carrier

The last bug-pinned C carrier. Its header documents both #55 halves;
with the cgen side fixed the STRONGER assertion set it deferred is
expressible: barevalue builds the 794 two-file program FLAT
(file-keyed import — a dir-keyed aa/ compiles aa as its own sep unit
where main.v is invisible and the collision cannot express), runs
exit 7 on BOTH drivers, and asserts the flat __root.s cs==ww
byte-identical (rule 10). defshadow pins the def-vs-fn arm-order
corner (foreign scalar def under a curmod fn: bare read 42, not
141), modqualfnval the qualified fn-value positive twin.

Carrier fleet 16 -> 15: 5 units / 6 bootstrap / 3 platform /
738_module_decl. Zero bug-pins remain.
This commit is contained in:
2026-08-08 17:13:23 +09:00
parent 9382eedbbb
commit 7631f4327c
2 changed files with 145 additions and 195 deletions

View File

@@ -132,3 +132,148 @@ fn textcount(s: str, sym: str) i32 = {
};
testenv.clean(td);
};
// barevalue (#55 cgen-side sibling) — the migrated 794 carrier
// (test/wcc/794_xmod_ident_prefer.c, retired with this row; its header
// documents both #55 halves). A bare VALUE ident read inside an
// imported module must be classified by the checker-stamped type, not
// a unit-wide leaf table: aa exports `v: i32 = 7` and getv() reads the
// bare `v`; the root declares a same-leaf `fn v() i64`. FLAT layout
// (file-keyed import) is REQUIRED — both files fold into one unit so
// the foreign fn lands in the leaf table; a dir-keyed aa/ compiles aa
// as its own sep unit where main.v is invisible and the collision
// cannot express. Pre-fix wwstage cgen took fnretlookup's leaf
// fallback and emitted `LEAQ aa.v(SB)` (fn address, no load) — the
// binary exited 0; cstage loads 7 (LEAQ+MOVSXD). Both drivers must
// build, run 7, and the flat __root.s must be cs==ww byte-identical
// (rule 10) — the stronger assertion set the carrier deferred while
// the cgen side was open.
@test fn barevalue() void = {
let td: str = testenv.fresh();
testenv.writefile(strings.concat(td, "/aa.ww"), strings.concat(
"package aa;\n",
"export let v: i32 = 7;\n",
"export fn getv() i32 = {\n",
" return v;\n",
"};\n"));
testenv.writefile(strings.concat(td, "/main.ww"), strings.concat(
"package main;\n",
"import aa;\n",
"fn v() i64 = { return 100; };\n",
"export fn main() i32 = {\n",
" return aa.getv();\n",
"};\n"));
let drvs: []str = ["ww", "ww_ww"];
let tags: []str = ["cs", "ww"];
let asms: []str = ["", ""];
let s: i32 = 0;
for (s < 2) {
let stem: str = strings.concat(td, "/prog.", tags[s]);
let av: []str = [testenv.driver(drvs[s]), "build", "-o", stem,
"-I", td, strings.concat(td, "/main.ww")];
if (runcode(td, strings.concat("build_", tags[s]), av) != 0) {
fail("barevalue", strings.concat(drvs[s], " build failed"));
};
let rav: []str = [stem];
if (runcode(td, strings.concat("run_", tags[s]), rav) != 7) {
fail("barevalue", strings.concat(drvs[s], " exit != 7 ",
"(bare v in aa.getv must LOAD aa.v, not take the ",
"foreign fn's address)"));
};
asms[s] = testenv.readfile(strings.concat(stem,
".sepwork/__root.s"));
s += 1;
};
if (!testenv.same(asms[0], asms[1])) {
fail("barevalue", "cs .s != ww .s (rule 10)");
};
testenv.clean(td);
};
// defshadow — corner (c) of the same class: a foreign scalar `def`
// leaf colliding with a curmod fn. The def arm ran BEFORE
// fn-classification in wwstage cgident (cstage checks TY_FN first),
// so the bare `MSG` fn value read `MOVQ main.MSG(SB)` data where
// cstage takes the fn address; the qualified `p5aa.MSG` data read hit
// the mirror corner (d) in cgdot. Runtime pre-fix: 141, want 42.
@test fn defshadow() void = {
let td: str = testenv.fresh();
testenv.writefile(strings.concat(td, "/p5aa.ww"), strings.concat(
"package p5aa;\n",
"export def MSG: i32 = 3;\n"));
testenv.writefile(strings.concat(td, "/main.ww"), strings.concat(
"package main;\n",
"import p5aa;\n",
"fn MSG(x: i32) i32 = { return x + 40; };\n",
"export fn main() i32 = {\n",
" let f = MSG;\n",
" return f(2) + p5aa.MSG - 3;\n",
"};\n"));
let drvs: []str = ["ww", "ww_ww"];
let tags: []str = ["cs", "ww"];
let asms: []str = ["", ""];
let s: i32 = 0;
for (s < 2) {
let stem: str = strings.concat(td, "/prog.", tags[s]);
let av: []str = [testenv.driver(drvs[s]), "build", "-o", stem,
"-I", td, strings.concat(td, "/main.ww")];
if (runcode(td, strings.concat("build_", tags[s]), av) != 0) {
fail("defshadow", strings.concat(drvs[s], " build failed"));
};
let rav: []str = [stem];
if (runcode(td, strings.concat("run_", tags[s]), rav) != 42) {
fail("defshadow", strings.concat(drvs[s], " exit != 42 ",
"(bare MSG is the curmod fn; p5aa.MSG is the ",
"foreign data def)"));
};
asms[s] = testenv.readfile(strings.concat(stem,
".sepwork/__root.s"));
s += 1;
};
if (!testenv.same(asms[0], asms[1])) {
fail("defshadow", "cs .s != ww .s (rule 10)");
};
testenv.clean(td);
};
// modqualfnval — corner (d) positive twin: a module-QUALIFIED fn used
// as a value must still take the address arm under the stamped-type
// gate (proves the checker stamps the N_DOT fn rvalue as TY_FN).
@test fn modqualfnval() void = {
let td: str = testenv.fresh();
testenv.writefile(strings.concat(td, "/p6aa.ww"), strings.concat(
"package p6aa;\n",
"export fn hit(x: i32) i32 = { return x + 40; };\n"));
testenv.writefile(strings.concat(td, "/main.ww"), strings.concat(
"package main;\n",
"import p6aa;\n",
"export fn main() i32 = {\n",
" let f = p6aa.hit;\n",
" return f(2);\n",
"};\n"));
let drvs: []str = ["ww", "ww_ww"];
let tags: []str = ["cs", "ww"];
let asms: []str = ["", ""];
let s: i32 = 0;
for (s < 2) {
let stem: str = strings.concat(td, "/prog.", tags[s]);
let av: []str = [testenv.driver(drvs[s]), "build", "-o", stem,
"-I", td, strings.concat(td, "/main.ww")];
if (runcode(td, strings.concat("build_", tags[s]), av) != 0) {
fail("modqualfnval", strings.concat(drvs[s],
" build failed"));
};
let rav: []str = [stem];
if (runcode(td, strings.concat("run_", tags[s]), rav) != 42) {
fail("modqualfnval", strings.concat(drvs[s],
" exit != 42"));
};
asms[s] = testenv.readfile(strings.concat(stem,
".sepwork/__root.s"));
s += 1;
};
if (!testenv.same(asms[0], asms[1])) {
fail("modqualfnval", "cs .s != ww .s (rule 10)");
};
testenv.clean(td);
};