selfhost+test: route convenience-wrapper N_DOT probes via fnretlookupmod (#17)

Structural close of the #4-trio convenience-wrapper audit. Session-6's
#4-trio + #11/#16 graduated individual lookup helpers (fnret/fnparams/
enum/struct/def) to same-module-first via *mod variants. The close
didn't enumerate every cgcall-context callsite — convenience wrappers
that take a *node callee and probe its return shape via bare-leaf
fnretlookup stripped the N_DOT module hint, same wedge shape as #16
(callee_variadic_param, d9b0c90) through a different family of
consumers.

Eight LATENT sites in selfhost/cmd/wcc fixed (each mirrors #34's
nodeisslice two-arm route — N_IDENT uses cmod=c.curmod, N_DOT uses
cmod=callee.lhs.str, terminal call routes through fnretlookupmod):

- cgenstmt.ww  cgreturn forwardtagged probe
- cgenstmt.ww  cgmlet tuple-return shape probe
- cgenexpr.ww  cgdot fn-rvalue probe (mod.fn LEAQ)
- cgenexpr.ww  cgtryprop succisstr probe
- cgenexpr.ww  cgtryunw  succisstr probe
- cgenutil.ww  callsretsize (sret arg-prep)
- cgenutil.ww  inferletcalltype (let x = f()? tnode)
- cgenutil.ww  rhstaggedabicall N_CALL branch

cstage carries no sister bug: cmd/w6c/cgen.c reads every callee
return shape from the typed n->lhs->type per TY_FN sig. Mirror of
#4d/#28/#31/#34/#16 cstage no-sister notes.

753_convwrap_audit: table-driven sentinel exercising cgmlet's tuple-
shape probe. alpha exports foo() (i64, str); beta exports foo()
(i64, i64); main calls beta.foo() — source order puts alpha LAST so
alpha.foo prepends to head of c.fnrets, pre-fix bare walk picks
alpha's str-branch dispatch for beta's call. Post-fix routes to
beta.foo via fnretlookupmod. Asserts MOVQ\\tCX, absent in main.run
TEXT (no str.len store; would fire pre-fix). Remaining 7 sites
covered structurally by shape-mirror — single wedge shape, single
exercise.

make test 127/127; ww2==ww3==ww4 byte-id holds via 995_self_rebuild.
This commit is contained in:
2026-05-19 10:44:16 +09:00
parent 23fccee4a0
commit 006df414aa
7 changed files with 560 additions and 66 deletions

View File

@@ -156,10 +156,22 @@ fn cgtryprop(c: *cgen, n: *node) void = {
if (callee != nil) {
let cname: str;
cname.ptr = nil; cname.len = 0;
if (callee.kind == nkind.N_IDENT) { cname = callee.str; };
if (callee.kind == nkind.N_DOT) { cname = callee.str; };
let cmod: str;
cmod.ptr = nil; cmod.len = 0;
if (callee.kind == nkind.N_IDENT) {
cname = callee.str;
cmod = c.curmod;
};
if (callee.kind == nkind.N_DOT) {
cname = callee.str;
if (callee.lhs != nil) {
if (callee.lhs.kind == nkind.N_IDENT) {
cmod = callee.lhs.str;
};
};
};
if (cname.len > 0) {
let rt: *node = fnretlookup(c, cname);
let rt: *node = fnretlookupmod(c, cname, cmod);
if (rt != nil) {
if (rt.kind == nkind.N_TTAGGED) {
let first: *node = rt.list;
@@ -200,10 +212,22 @@ fn cgtryunw(c: *cgen, n: *node) void = {
if (callee != nil) {
let cname: str;
cname.ptr = nil; cname.len = 0;
if (callee.kind == nkind.N_IDENT) { cname = callee.str; };
if (callee.kind == nkind.N_DOT) { cname = callee.str; };
let cmod: str;
cmod.ptr = nil; cmod.len = 0;
if (callee.kind == nkind.N_IDENT) {
cname = callee.str;
cmod = c.curmod;
};
if (callee.kind == nkind.N_DOT) {
cname = callee.str;
if (callee.lhs != nil) {
if (callee.lhs.kind == nkind.N_IDENT) {
cmod = callee.lhs.str;
};
};
};
if (cname.len > 0) {
let rt: *node = fnretlookup(c, cname);
let rt: *node = fnretlookupmod(c, cname, cmod);
if (rt != nil) {
if (rt.kind == nkind.N_TTAGGED) {
let first: *node = rt.list;
@@ -1733,7 +1757,10 @@ fn cgdot(c: *cgen, n: *node) void = {
// Without this the MOVQ leaf(SB) fallback below would
// load 8 bytes of fn-prologue code into AX instead of
// the fn address.
let frt: *node = fnretlookup(c, fld);
// 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);
if (frt != nil) {
emitline("\tLEAQ\t");
emitfnname(c, fld, lhs.str);