wcc/ww: mangle imported symbols on dotted import path (#22 M1, #32)

Switch symbol mangling from the import leaf clause to the full dotted import path for directory packages; single-file imports keep package-clause mangling (isdir-gate: imported<=>directory-import). The root build unit's fn main stays bare, every other top-level decl mangles, closing #31's duplicate-main hazard by construction (#32). Both stages, byte-identical.

Single commit, not split: the bare rename (f244af3) is red on its own because it unmasks cross-module resolution gaps that do not reproduce pre-M1, so the fixes are intrinsic to making the rename correct. Included: wwstage fnret/fnparamslookupmod map import alias->path (#199b cross-module union-variant scrutinee resolved the wrong fn's union); cstage use_path prefers the referencing module's import for an ambiguous leaf alias (sha256 crypto.math vs strconv math). Tests table-driven: 989_m1mangle_run/_sym, 989_m1union_run (gate-visible per-arm exit codes + cs==ww byte-id).
This commit is contained in:
2026-06-15 17:37:18 +09:00
parent 64d6c15e41
commit f308818b4b
30 changed files with 1851 additions and 241 deletions

View File

@@ -4306,10 +4306,10 @@ fn cgdot(c: *cgen, n: *node) void = {
// lhs.str is the explicit module hint so a same-leaf
// def in another module (head of c.fnrets) can't shadow
// the explicit qualifier (#17 N_DOT-arm omission audit).
let frt: *node = fnretlookupmod(c, fld, lhs.str);
let frt: *node = fnretlookupmod(c, fld, usehint(c, lhs.str));
if (frt != nil) {
emitline("\tLEAQ\t");
emitfnname(c, fld, lhs.str);
emitfnname(c, fld, usehint(c, lhs.str));
emitline("(SB), AX\n");
return;
};
@@ -4321,7 +4321,7 @@ fn cgdot(c: *cgen, n: *node) void = {
// the explicit module hint — a 3rd-module qualifier
// `alpha.MSG` from gamma needs alpha (not c.curmod)
// to beat a head-of-c.defs beta.MSG collision (#11).
let drhs: *node = deflookuprhsmod(c, fld, lhs.str);
let drhs: *node = deflookuprhsmod(c, fld, usehint(c, lhs.str));
if (drhs != nil) {
if (drhs.kind == nkind.N_STRLIT) {
let bytes: str = drhs.str;
@@ -4342,11 +4342,11 @@ fn cgdot(c: *cgen, n: *node) void = {
// threads lhs.str via emitfnname.
if (streq(mqop, "MOVQ")) {
emitline("\tMOVQ\t");
emitsymnamehint(c, fld, lhs.str);
emitsymnamehint(c, fld, usehint(c, lhs.str));
emitline("(SB), AX\n");
} else {
emitline("\tLEAQ\t");
emitsymnamehint(c, fld, lhs.str);
emitsymnamehint(c, fld, usehint(c, lhs.str));
emitline("(SB), CX\n");
emitline("\t");
emitline(mqop);
@@ -5226,10 +5226,10 @@ fn cgun(c: *cgen, n: *node) void = {
// pre-#149 gap (file as #150-family).
if (!isletvar(c, basenm) && !deflookup(c, basenm)) {
let fld: str = opnd.str;
let frt: *node = fnretlookupmod(c, fld, basenm);
let frt: *node = fnretlookupmod(c, fld, usehint(c, basenm));
if (frt != nil) {
emitline("\tLEAQ\t");
emitfnname(c, fld, basenm);
emitfnname(c, fld, usehint(c, basenm));
emitline("(SB), AX\n");
return;
};
@@ -5238,7 +5238,7 @@ fn cgun(c: *cgen, n: *node) void = {
// &aa.v takes aa's global, not a
// same-leaf collision.
emitline("\tLEAQ\t");
emitsymnamehint(c, fld, basenm);
emitsymnamehint(c, fld, usehint(c, basenm));
emitline("(SB), AX\n");
return;
};
@@ -8227,7 +8227,7 @@ fn cgcall(c: *cgen, n: *node) void = {
hint.len = 0;
if (callee.lhs != nil) {
if (callee.lhs.kind == nkind.N_IDENT) {
hint = callee.lhs.str;
hint = usehint(c, callee.lhs.str);
};
};
emitfnname(c, calleename, hint);