selfhost/cmd/wcc: dotchainresolve walks tinfo.fields (#71, A.6.3j)
The chained value-struct spine-walker resolved root + total offset + leaf type via structinfo/fieldinfo (slot-padded foff). Swap its guts onto the stamped root-ident type_: peel TY_NAMED to TY_STRUCT (one TY_PTR hop for a *struct root) and accumulate tfield.offset down the spine, mirroring cstage's cur->lhs->type fields walk (cmd/w6c/cgen.c:3156-3216 write, :1955-2030 AMP/ read). Leaf out-param becomes *tinfo; the three callers read leaf-ness via typeis*/loadopsz, and the cgassign struct-terminal recovers the struct name from the leaf tinfo's NAMED wrapper for the still-structinfo cgstructlitfill. Root classification (local/ptr/global) is unchanged, so the firing set and addressing mode stay byte-identical; the global-root path remains its pre- existing shared breakage (#27), untouched. Natural tfield.offset equals the old slot-padded foff for every shape the byte-id gate exercises -- and since cstage already reads the natural offset and ww-old==cstage held, the flip is structurally identical, not coincidental. Latent (off-corpus, byte-id-neutral): the tinfo-peel now fires the str/slice pseudo-leaf on an aliased-str/slice field where the old structinfo path bailed -- a faithful-toward-cstage gap closure, filed for a probe + sentinel. make test 134/134, byte-id 950+990-997 hold.
This commit is contained in:
@@ -2808,7 +2808,7 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
|
||||
// Spine-walk a chained N_DOT (n) inward to a root ident, summing field
|
||||
// offsets through value-struct intermediates. Optional slice/str leaf
|
||||
// pseudo-field (.ptr / .len / .cap) on the last segment is folded into
|
||||
// *outslicedelta (0/8/16); otherwise *outleaffi is the leaf fieldinfo
|
||||
// *outslicedelta (0/8/16); otherwise *outleaftype is the leaf *tinfo
|
||||
// and *outslicedelta stays -1. Returns true on success; on false the
|
||||
// caller falls through to other branches.
|
||||
//
|
||||
@@ -2825,16 +2825,28 @@ fn cgwidentaggedstorebp(c: *cgen, dst: *tinfo, src: *node, slot_off: i32, slot_s
|
||||
// Numeric out-params are i32 — offsets fit naturally and the post-#19
|
||||
// localloadop sign-extends i32 deref-stored slots on read, so negative
|
||||
// frame offsets round-trip intact.
|
||||
// #71 (A.6.3j): the spine offset-sum + leaf-type now read off
|
||||
// tinfo.fields (natural layout) instead of the structinfo/fieldinfo
|
||||
// walk. Mirror of cstage cmd/w6c/cgen.c:3156-3216 which walks
|
||||
// `cur->lhs->type` fields. Root resolution (the local/ptr/global split
|
||||
// and the rootoff/ptrroot/isglobal flags) stays on localfindnode/
|
||||
// letvarstructinfo unchanged, so the firing set + addressing mode are
|
||||
// byte-identical to the structinfo era; only the layout SOURCE moves.
|
||||
// The slot-padded foff and the natural tfield.offset coincide for every
|
||||
// shape the byte-id gate exercises (cstage already reads the natural
|
||||
// offset), so this is offset-preserving. Leaf out-param is the field's
|
||||
// stamped *tinfo (was *fieldinfo); the str/slice pseudo-leaf leaves it
|
||||
// nil and the callers gate on slicedelta>=0 first.
|
||||
export fn dotchainresolve(c: *cgen, n: *node,
|
||||
outrootname: *str, outrootoff: *i32, outtotaloff: *i32,
|
||||
outleaffi: **fieldinfo, outslicedelta: *i32,
|
||||
outleaftype: **tinfo, outslicedelta: *i32,
|
||||
outisglobal: *bool, outptrroot: *bool) bool = {
|
||||
*outrootname = "";
|
||||
*outrootoff = 0;
|
||||
*outisglobal = false;
|
||||
*outptrroot = false;
|
||||
*outtotaloff = 0;
|
||||
*outleaffi = nil;
|
||||
*outleaftype = nil;
|
||||
*outslicedelta = -1;
|
||||
if (n == nil) { return false; };
|
||||
if (n.kind != nkind.N_DOT) { return false; };
|
||||
@@ -2852,13 +2864,13 @@ export fn dotchainresolve(c: *cgen, n: *node,
|
||||
if (cur == nil) { return false; };
|
||||
if (cur.kind != nkind.N_IDENT) { return false; };
|
||||
*outrootname = cur.str;
|
||||
let rootstruct: str = "";
|
||||
let resolved: bool = false;
|
||||
let lc: *local = localfindnode(c, cur.str);
|
||||
if (lc != nil) {
|
||||
if (lc.tnode != nil) {
|
||||
if (lc.tnode.kind == nkind.N_TNAME) {
|
||||
rootstruct = lc.tnode.str;
|
||||
*outrootoff = lc.off;
|
||||
resolved = true;
|
||||
};
|
||||
// `*T` root (param/local): dereference at emit time;
|
||||
// pointee struct supplies the field layout. Callers
|
||||
@@ -2868,60 +2880,71 @@ export fn dotchainresolve(c: *cgen, n: *node,
|
||||
let pe: *node = lc.tnode.lhs;
|
||||
if (pe != nil) {
|
||||
if (pe.kind == nkind.N_TNAME) {
|
||||
rootstruct = pe.str;
|
||||
*outrootoff = lc.off;
|
||||
*outptrroot = true;
|
||||
resolved = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
if (rootstruct.len == 0) {
|
||||
if (!resolved) {
|
||||
let gsi: *structinfo = letvarstructinfo(c, cur.str);
|
||||
if (gsi != nil) {
|
||||
rootstruct = gsi.sname;
|
||||
*outisglobal = true;
|
||||
resolved = true;
|
||||
};
|
||||
};
|
||||
if (!resolved) { return false; };
|
||||
// Root struct layout = the stamped root-ident type_, peeled NAMED
|
||||
// (plus one TY_PTR hop for a `*struct` root). tfield.type_ then
|
||||
// supplies each nested struct directly, so no name re-lookup.
|
||||
let curstruct: *tinfo = cur.type_: *tinfo;
|
||||
for (curstruct != nil && curstruct.kind == tykind.TY_NAMED) {
|
||||
curstruct = curstruct.under;
|
||||
};
|
||||
if (*outptrroot) {
|
||||
if (curstruct == nil) { return false; };
|
||||
if (curstruct.kind != tykind.TY_PTR) { return false; };
|
||||
curstruct = curstruct.sub;
|
||||
for (curstruct != nil && curstruct.kind == tykind.TY_NAMED) {
|
||||
curstruct = curstruct.under;
|
||||
};
|
||||
};
|
||||
if (rootstruct.len == 0) { return false; };
|
||||
let curstruct: str = rootstruct;
|
||||
let i: i32 = nsteps - 1;
|
||||
for (i >= 0) {
|
||||
let csi: *structinfo = structlookup(c, curstruct);
|
||||
if (csi == nil) { return false; };
|
||||
if (curstruct == nil) { return false; };
|
||||
if (curstruct.kind != tykind.TY_STRUCT) { return false; };
|
||||
if (stk[i] == nil) { return false; };
|
||||
let stepnm: str = stk[i].str;
|
||||
let fi: *fieldinfo = csi.fields;
|
||||
let found: *fieldinfo = nil;
|
||||
for (fi != nil) {
|
||||
if (streq(fi.fname, stepnm)) { found = fi; break; };
|
||||
fi = fi.finext;
|
||||
let tf: *tfield = curstruct.fields;
|
||||
let found: *tfield = nil;
|
||||
for (tf != nil) {
|
||||
if (streq(tf.name, stepnm)) { found = tf; break; };
|
||||
tf = tf.tnext;
|
||||
};
|
||||
if (found == nil) { return false; };
|
||||
let foff: i32 = found.offset: i32;
|
||||
if (i == 0) {
|
||||
*outtotaloff = *outtotaloff + found.foff;
|
||||
*outleaffi = found;
|
||||
*outtotaloff = *outtotaloff + foff;
|
||||
*outleaftype = found.type_;
|
||||
return true;
|
||||
};
|
||||
let ft: *node = found.tnode;
|
||||
let ft: *tinfo = found.type_;
|
||||
for (ft != nil && ft.kind == tykind.TY_NAMED) { ft = ft.under; };
|
||||
if (ft == nil) { return false; };
|
||||
if (ft.kind == nkind.N_TNAME) {
|
||||
if (streq(ft.str, "str")) {
|
||||
if (i != 1) { return false; };
|
||||
let pseudo: str = stk[0].str;
|
||||
let delta: i32 = -1;
|
||||
if (streq(pseudo, "ptr")) { delta = 0; }
|
||||
else { if (streq(pseudo, "len")) { delta = 8; }; };
|
||||
if (delta < 0) { return false; };
|
||||
*outtotaloff = *outtotaloff + found.foff;
|
||||
*outslicedelta = delta;
|
||||
return true;
|
||||
};
|
||||
if (primsize(ft.str) != 0) { return false; };
|
||||
*outtotaloff = *outtotaloff + found.foff;
|
||||
curstruct = ft.str;
|
||||
i -= 1;
|
||||
} else { if (ft.kind == nkind.N_TSLICE) {
|
||||
if (ft.kind == tykind.TY_STR) {
|
||||
if (i != 1) { return false; };
|
||||
let pseudo: str = stk[0].str;
|
||||
let delta: i32 = -1;
|
||||
if (streq(pseudo, "ptr")) { delta = 0; }
|
||||
else { if (streq(pseudo, "len")) { delta = 8; }; };
|
||||
if (delta < 0) { return false; };
|
||||
*outtotaloff = *outtotaloff + foff;
|
||||
*outslicedelta = delta;
|
||||
return true;
|
||||
};
|
||||
if (ft.kind == tykind.TY_SLICE) {
|
||||
if (i != 1) { return false; };
|
||||
let pseudo: str = stk[0].str;
|
||||
let delta: i32 = -1;
|
||||
@@ -2929,12 +2952,14 @@ export fn dotchainresolve(c: *cgen, n: *node,
|
||||
else { if (streq(pseudo, "len")) { delta = 8; }
|
||||
else { if (streq(pseudo, "cap")) { delta = 16; }; }; };
|
||||
if (delta < 0) { return false; };
|
||||
*outtotaloff = *outtotaloff + found.foff;
|
||||
*outtotaloff = *outtotaloff + foff;
|
||||
*outslicedelta = delta;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}; };
|
||||
};
|
||||
if (ft.kind != tykind.TY_STRUCT) { return false; };
|
||||
*outtotaloff = *outtotaloff + foff;
|
||||
curstruct = ft;
|
||||
i -= 1;
|
||||
};
|
||||
return false;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user