selfhost: aliaslookup mod-filter for pkg.-qualified type refs
This commit is contained in:
@@ -15342,6 +15342,7 @@ use cgendecl;
|
|||||||
|
|
||||||
type aliasent = struct {
|
type aliasent = struct {
|
||||||
aname: str,
|
aname: str,
|
||||||
|
amod: str, // originating module (`// MODULE: foo`), or empty
|
||||||
target: *node, // the rhs type expr
|
target: *node, // the rhs type expr
|
||||||
aanext: *aliasent,
|
aanext: *aliasent,
|
||||||
};
|
};
|
||||||
@@ -15354,8 +15355,9 @@ fn collectaliases(c: *cgen, file: *node) void = {
|
|||||||
let body: *node = d.lhs;
|
let body: *node = d.lhs;
|
||||||
if (body != nil) {
|
if (body != nil) {
|
||||||
if (body.kind != nkind.N_TSTRUCT) {
|
if (body.kind != nkind.N_TSTRUCT) {
|
||||||
let a: *aliasent = amalloc(c.a, 32u64): *aliasent;
|
let a: *aliasent = amalloc(c.a, 64u64): *aliasent;
|
||||||
a.aname = d.str;
|
a.aname = d.str;
|
||||||
|
a.amod = d.module;
|
||||||
a.target = body;
|
a.target = body;
|
||||||
a.aanext = c.aliases;
|
a.aanext = c.aliases;
|
||||||
c.aliases = a;
|
c.aliases = a;
|
||||||
@@ -15373,19 +15375,27 @@ fn aliaslookup(c: *cgen, name: str) *node = {
|
|||||||
if (streq(an, name)) { return a.target; };
|
if (streq(an, name)) { return a.target; };
|
||||||
a = a.aanext;
|
a = a.aanext;
|
||||||
};
|
};
|
||||||
// Module-qualified form: `pkg.alias` → try the bare leaf so a
|
// Module-qualified form: `pkg.alias` → match the leaf name
|
||||||
// cross-module reference resolves the same way bare access does
|
// scoped to its originating module. Mirrors check.c's module-
|
||||||
// after driver concatenation. Mirrors the check.c module-
|
// qualified type resolution; requiring `amod == pkg` is what
|
||||||
// qualified type resolution.
|
// prevents two modules with same-leaf-name aliases from
|
||||||
|
// collapsing into whichever entry appears first in the chain.
|
||||||
let i: i32 = name.len - 1;
|
let i: i32 = name.len - 1;
|
||||||
for (i >= 0) {
|
for (i >= 0) {
|
||||||
if (name[i] == 46u8) { // '.'
|
if (name[i] == 46u8) { // '.'
|
||||||
|
let pkg: str;
|
||||||
|
pkg.ptr = name.ptr;
|
||||||
|
pkg.len = i;
|
||||||
let leaf: str;
|
let leaf: str;
|
||||||
leaf.ptr = name.ptr + ((i + 1): u64);
|
leaf.ptr = name.ptr + ((i + 1): u64);
|
||||||
leaf.len = name.len - (i + 1);
|
leaf.len = name.len - (i + 1);
|
||||||
let b: *aliasent = c.aliases;
|
let b: *aliasent = c.aliases;
|
||||||
for (b != nil) {
|
for (b != nil) {
|
||||||
if (streq(b.aname, leaf)) { return b.target; };
|
if (streq(b.aname, leaf)) {
|
||||||
|
if (streq(b.amod, pkg)) {
|
||||||
|
return b.target;
|
||||||
|
};
|
||||||
|
};
|
||||||
b = b.aanext;
|
b = b.aanext;
|
||||||
};
|
};
|
||||||
i = -1;
|
i = -1;
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ use cgendecl;
|
|||||||
|
|
||||||
type aliasent = struct {
|
type aliasent = struct {
|
||||||
aname: str,
|
aname: str,
|
||||||
|
amod: str, // originating module (`// MODULE: foo`), or empty
|
||||||
target: *node, // the rhs type expr
|
target: *node, // the rhs type expr
|
||||||
aanext: *aliasent,
|
aanext: *aliasent,
|
||||||
};
|
};
|
||||||
@@ -58,8 +59,9 @@ fn collectaliases(c: *cgen, file: *node) void = {
|
|||||||
let body: *node = d.lhs;
|
let body: *node = d.lhs;
|
||||||
if (body != nil) {
|
if (body != nil) {
|
||||||
if (body.kind != nkind.N_TSTRUCT) {
|
if (body.kind != nkind.N_TSTRUCT) {
|
||||||
let a: *aliasent = amalloc(c.a, 32u64): *aliasent;
|
let a: *aliasent = amalloc(c.a, 64u64): *aliasent;
|
||||||
a.aname = d.str;
|
a.aname = d.str;
|
||||||
|
a.amod = d.module;
|
||||||
a.target = body;
|
a.target = body;
|
||||||
a.aanext = c.aliases;
|
a.aanext = c.aliases;
|
||||||
c.aliases = a;
|
c.aliases = a;
|
||||||
@@ -77,19 +79,27 @@ fn aliaslookup(c: *cgen, name: str) *node = {
|
|||||||
if (streq(an, name)) { return a.target; };
|
if (streq(an, name)) { return a.target; };
|
||||||
a = a.aanext;
|
a = a.aanext;
|
||||||
};
|
};
|
||||||
// Module-qualified form: `pkg.alias` → try the bare leaf so a
|
// Module-qualified form: `pkg.alias` → match the leaf name
|
||||||
// cross-module reference resolves the same way bare access does
|
// scoped to its originating module. Mirrors check.c's module-
|
||||||
// after driver concatenation. Mirrors the check.c module-
|
// qualified type resolution; requiring `amod == pkg` is what
|
||||||
// qualified type resolution.
|
// prevents two modules with same-leaf-name aliases from
|
||||||
|
// collapsing into whichever entry appears first in the chain.
|
||||||
let i: i32 = name.len - 1;
|
let i: i32 = name.len - 1;
|
||||||
for (i >= 0) {
|
for (i >= 0) {
|
||||||
if (name[i] == 46u8) { // '.'
|
if (name[i] == 46u8) { // '.'
|
||||||
|
let pkg: str;
|
||||||
|
pkg.ptr = name.ptr;
|
||||||
|
pkg.len = i;
|
||||||
let leaf: str;
|
let leaf: str;
|
||||||
leaf.ptr = name.ptr + ((i + 1): u64);
|
leaf.ptr = name.ptr + ((i + 1): u64);
|
||||||
leaf.len = name.len - (i + 1);
|
leaf.len = name.len - (i + 1);
|
||||||
let b: *aliasent = c.aliases;
|
let b: *aliasent = c.aliases;
|
||||||
for (b != nil) {
|
for (b != nil) {
|
||||||
if (streq(b.aname, leaf)) { return b.target; };
|
if (streq(b.aname, leaf)) {
|
||||||
|
if (streq(b.amod, pkg)) {
|
||||||
|
return b.target;
|
||||||
|
};
|
||||||
|
};
|
||||||
b = b.aanext;
|
b = b.aanext;
|
||||||
};
|
};
|
||||||
i = -1;
|
i = -1;
|
||||||
|
|||||||
@@ -15342,6 +15342,7 @@ use cgendecl;
|
|||||||
|
|
||||||
type aliasent = struct {
|
type aliasent = struct {
|
||||||
aname: str,
|
aname: str,
|
||||||
|
amod: str, // originating module (`// MODULE: foo`), or empty
|
||||||
target: *node, // the rhs type expr
|
target: *node, // the rhs type expr
|
||||||
aanext: *aliasent,
|
aanext: *aliasent,
|
||||||
};
|
};
|
||||||
@@ -15354,8 +15355,9 @@ fn collectaliases(c: *cgen, file: *node) void = {
|
|||||||
let body: *node = d.lhs;
|
let body: *node = d.lhs;
|
||||||
if (body != nil) {
|
if (body != nil) {
|
||||||
if (body.kind != nkind.N_TSTRUCT) {
|
if (body.kind != nkind.N_TSTRUCT) {
|
||||||
let a: *aliasent = amalloc(c.a, 32u64): *aliasent;
|
let a: *aliasent = amalloc(c.a, 64u64): *aliasent;
|
||||||
a.aname = d.str;
|
a.aname = d.str;
|
||||||
|
a.amod = d.module;
|
||||||
a.target = body;
|
a.target = body;
|
||||||
a.aanext = c.aliases;
|
a.aanext = c.aliases;
|
||||||
c.aliases = a;
|
c.aliases = a;
|
||||||
@@ -15373,19 +15375,27 @@ fn aliaslookup(c: *cgen, name: str) *node = {
|
|||||||
if (streq(an, name)) { return a.target; };
|
if (streq(an, name)) { return a.target; };
|
||||||
a = a.aanext;
|
a = a.aanext;
|
||||||
};
|
};
|
||||||
// Module-qualified form: `pkg.alias` → try the bare leaf so a
|
// Module-qualified form: `pkg.alias` → match the leaf name
|
||||||
// cross-module reference resolves the same way bare access does
|
// scoped to its originating module. Mirrors check.c's module-
|
||||||
// after driver concatenation. Mirrors the check.c module-
|
// qualified type resolution; requiring `amod == pkg` is what
|
||||||
// qualified type resolution.
|
// prevents two modules with same-leaf-name aliases from
|
||||||
|
// collapsing into whichever entry appears first in the chain.
|
||||||
let i: i32 = name.len - 1;
|
let i: i32 = name.len - 1;
|
||||||
for (i >= 0) {
|
for (i >= 0) {
|
||||||
if (name[i] == 46u8) { // '.'
|
if (name[i] == 46u8) { // '.'
|
||||||
|
let pkg: str;
|
||||||
|
pkg.ptr = name.ptr;
|
||||||
|
pkg.len = i;
|
||||||
let leaf: str;
|
let leaf: str;
|
||||||
leaf.ptr = name.ptr + ((i + 1): u64);
|
leaf.ptr = name.ptr + ((i + 1): u64);
|
||||||
leaf.len = name.len - (i + 1);
|
leaf.len = name.len - (i + 1);
|
||||||
let b: *aliasent = c.aliases;
|
let b: *aliasent = c.aliases;
|
||||||
for (b != nil) {
|
for (b != nil) {
|
||||||
if (streq(b.aname, leaf)) { return b.target; };
|
if (streq(b.aname, leaf)) {
|
||||||
|
if (streq(b.amod, pkg)) {
|
||||||
|
return b.target;
|
||||||
|
};
|
||||||
|
};
|
||||||
b = b.aanext;
|
b = b.aanext;
|
||||||
};
|
};
|
||||||
i = -1;
|
i = -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user