wcc/ww: scopelookuptype prefers the current module's symbol
A type lookup in a bundled build resolved to the newest-installed same-leaf symbol from ANY module; prefer the current module first (mirror cstage sym.c:131; the prior attempt's failure was its own u64-vs-i32 guard bug, not a deeper layer — probe-proven). Also adds the rule-7 #58 notes at the latent varianterr/scruttype pair and rewrites the stale deferral block to closing cites. Report item [5].
This commit is contained in:
@@ -103,7 +103,7 @@ export fn scopelookup(s: *scope, name: str) *sym = {
|
||||
return nil;
|
||||
};
|
||||
|
||||
// scopelookuptype — find an SK_TYPE entry by name regardless of mod.
|
||||
// scopelookuptype — find an SK_TYPE entry by name, same-module preferred.
|
||||
//
|
||||
// Same FNV bucket + hashnext chain + parent walk as scopelookup, with
|
||||
// an `skind == SK_TYPE` filter. Used to disambiguate the bare-TNAME
|
||||
@@ -111,23 +111,43 @@ export fn scopelookup(s: *scope, name: str) *sym = {
|
||||
// SK_USE sym for a leaf that ALSO names a type (e.g. `tok` struct
|
||||
// declared in lib/ww/lex/tok.ww with `package lex;` while
|
||||
// `import tok;` registers a same-name SK_USE), the resolver needs
|
||||
// the type entry regardless of its declared package — the struct's
|
||||
// mod may differ from the leaf (lex/tok pair) so
|
||||
// scopelookupinmodule(c, leaf, leaf) won't find it.
|
||||
// the type entry — the struct's mod may differ from the leaf (lex/tok
|
||||
// pair) so scopelookupinmodule(c, leaf, leaf) won't find it.
|
||||
//
|
||||
// Mirrors the bare-vs-qualified disambiguation pattern from task #57.
|
||||
export fn scopelookuptype(s: *scope, name: str) *sym = {
|
||||
for (s != nil) {
|
||||
// #58/#50: within each scope, Pass-1 prefers an SK_TYPE whose `sym.mod`
|
||||
// matches `mod`; Pass-2 falls back to the first SK_TYPE regardless of
|
||||
// mod (chain-first, the prior behavior). scopedefineinmodule PREPENDS,
|
||||
// so chain-first = last-registered — when two modules export the same
|
||||
// type leaf the bare walk silently picked the newest-installed one,
|
||||
// install-order-dependent, while cstage is deterministic on cur_mod.
|
||||
// Mirrors cstage cmd/wcc/sym.c scope_lookup_type(s, mod, name) (the
|
||||
// kind-filtered + mod-preferring single walk); sole caller passes
|
||||
// c.curmod. i32-correct: streq throughout, only `.len > 0` guards (the
|
||||
// reverted attempt compared str.len as u64 — str.len is i32).
|
||||
export fn scopelookuptype(s: *scope, mod: str, name: str) *sym = {
|
||||
let p: *scope = s;
|
||||
for (p != nil) {
|
||||
let h: u64 = hashstr(name);
|
||||
let bi: i32 = (h % (s.nbuckets: u64)): i32;
|
||||
let b: *sym = s.buckets[bi];
|
||||
let bi: i32 = (h % (p.nbuckets: u64)): i32;
|
||||
let b: *sym = p.buckets[bi];
|
||||
let fallback: *sym = nil;
|
||||
for (b != nil) {
|
||||
if (streq(b.name, name)) {
|
||||
if (b.skind == skind.SK_TYPE) { return b; };
|
||||
if (b.skind == skind.SK_TYPE) {
|
||||
if (mod.len > 0) {
|
||||
if (b.mod.len > 0) {
|
||||
if (streq(b.mod, mod)) {
|
||||
return b;
|
||||
};
|
||||
};
|
||||
};
|
||||
if (fallback == nil) { fallback = b; };
|
||||
};
|
||||
};
|
||||
b = b.hashnext;
|
||||
};
|
||||
s = s.parent;
|
||||
if (fallback != nil) { return fallback; };
|
||||
p = p.parent;
|
||||
};
|
||||
return nil;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user