refactor(stdlib/S1.2): delete module_fns; dissolve legacy_direct_any [additive]
Delete module_fns as a separate function-author fact source. Its authors already live in the module_decls raw facts, so lowerRetainedSameNameAuthors now reads function authors straight out of module_decls (filtered to *FnDecl via fnDeclOfRaw) — the same path → name → RawDeclRef store, fn-filtered. Remove imports.ModuleFns / FnIndex / indexModuleFns / buildModuleFns / fnDeclOf, the Compilation.module_fns field + its build + wiring, and ProgramIndex.module_fns. Remove VisibilityMode.legacy_direct_any (the quarantined own-scope-plus-full- import_graph mode): no production caller passed it, so the collectVisibleAuthors and isVisible switch arms that handled it are dead and go too, collapsing VisEdgeSet to the single flat-import walk. No semantic fallback is introduced; import_graph stays the transitive-visibility source for findVisibleImpls. Additive: the old maps stay active and lowering still consumes them — no lowering consumer is cut over to the DeclTable (that is S3), and no resolution behavior changes. Tests that drove the removed symbols are rerouted through module_decls / the flat-edge walk. Gate over the baseline-green corpus: zig build, zig build test (424/424), bash tests/run_examples.sh (540 passed) — all exit 0; single-author output byte-identical; multi-author 0722–0740 stdout/exit unchanged.
This commit is contained in:
@@ -1291,7 +1291,7 @@ fn countRealBodies(module: *ir_mod.Module, name: []const u8) usize {
|
||||
|
||||
// fix-0102b: two flat-imported modules each author `greet`. The first-wins merge
|
||||
// keeps a.sx's author in the merged decl list (the WINNER) and drops b.sx's,
|
||||
// which `module_fns` still retains (0102a). `main` itself can't bare-call `greet`
|
||||
// which the `module_decls` raw facts still retain (0102a). `main` itself can't bare-call `greet`
|
||||
// — under fix-0102c two flat authors make that ambiguous — so it calls a.sx's
|
||||
// `use_greet` wrapper, whose own-author call to `greet` binds a.sx's winner.
|
||||
// BEFORE the identity-addressable pass, only the winner has a real body — the
|
||||
@@ -1358,11 +1358,9 @@ test "lower: shadowed same-name author gets its own FuncId + real body (fix-0102
|
||||
while (cache_it.next()) |entry| {
|
||||
try module_scopes.put(entry.key_ptr.*, entry.value_ptr.scope);
|
||||
}
|
||||
var module_fns = imports.ModuleFns.init(alloc);
|
||||
try imports.buildModuleFns(alloc, main_path, mod, &cache, &module_fns);
|
||||
|
||||
// Phase A raw facts: `selectPlainCallableAuthor` (Phase C) collects authors
|
||||
// over `module_decls`, not `module_fns`. Wired exactly as `core.zig` does.
|
||||
// Phase A raw facts: both `selectPlainCallableAuthor` (Phase C) and
|
||||
// `lowerRetainedSameNameAuthors` read function authors out of `module_decls`.
|
||||
// Wired exactly as `core.zig` does.
|
||||
var facts = try imports.buildImportFacts(alloc, main_path, mod, &cache);
|
||||
|
||||
const resolved_root = try alloc.create(Node);
|
||||
@@ -1378,7 +1376,6 @@ test "lower: shadowed same-name author gets its own FuncId + real body (fix-0102
|
||||
lowering.program_index.module_scopes = &module_scopes;
|
||||
lowering.program_index.import_graph = &import_graph;
|
||||
lowering.program_index.flat_import_graph = &flat_import_graph;
|
||||
lowering.program_index.module_fns = &module_fns;
|
||||
lowering.program_index.module_decls = &facts.decls;
|
||||
|
||||
lowering.lowerRoot(resolved_root);
|
||||
@@ -1409,23 +1406,23 @@ test "lower: shadowed same-name author gets its own FuncId + real body (fix-0102
|
||||
|
||||
// F1 (attempt-2): the identity map must be keyed by the STABLE AST field
|
||||
// pointer for BOTH same-name authors — the exact pointers `fn_ast_map` and
|
||||
// `module_fns` carry — not a per-iteration switch-capture temporary. If the
|
||||
// winner were keyed by `&fd` (the scanDecls bug), this lookup by the stable
|
||||
// `fn_ast_map` pointer would miss (null). fix-0102c routes calls through
|
||||
// exactly these pointers, so the round-trip must hold here.
|
||||
// the `module_decls` raw facts carry — not a per-iteration switch-capture
|
||||
// temporary. If the winner were keyed by `&fd` (the scanDecls bug), this
|
||||
// lookup by the stable `fn_ast_map` pointer would miss (null). fix-0102c
|
||||
// routes calls through exactly these pointers, so the round-trip must hold.
|
||||
const winner_fd = lowering.program_index.fn_ast_map.get("greet").?;
|
||||
const winner_fid = lowering.fn_decl_fids.get(winner_fd);
|
||||
try std.testing.expect(winner_fid != null);
|
||||
// Round-trips to the first-wins winner FuncId (resolveFuncByName's pick).
|
||||
try std.testing.expectEqual(lowering.resolveFuncByName("greet").?, winner_fid.?);
|
||||
|
||||
// The shadowed author's stable pointer lives in `module_fns`; find the one
|
||||
// The shadowed author's stable pointer lives in `module_decls`; find the one
|
||||
// that is NOT the winner and confirm IT round-trips to a DISTINCT FuncId.
|
||||
var shadow_fd: ?*const ast.FnDecl = null;
|
||||
var mf_it = module_fns.iterator();
|
||||
while (mf_it.next()) |path_entry| {
|
||||
if (path_entry.value_ptr.get("greet")) |fd| {
|
||||
if (fd != winner_fd) shadow_fd = fd;
|
||||
var md_it = facts.decls.iterator();
|
||||
while (md_it.next()) |path_entry| {
|
||||
if (path_entry.value_ptr.names.get("greet")) |ref| {
|
||||
if (ref == .fn_decl and ref.fn_decl != winner_fd) shadow_fd = ref.fn_decl;
|
||||
}
|
||||
}
|
||||
try std.testing.expect(shadow_fd != null);
|
||||
@@ -1521,8 +1518,6 @@ test "lower: scan populates source-keyed caches per declaring source (E0)" {
|
||||
while (cache_it.next()) |entry| {
|
||||
try module_scopes.put(entry.key_ptr.*, entry.value_ptr.scope);
|
||||
}
|
||||
var module_fns = imports.ModuleFns.init(alloc);
|
||||
try imports.buildModuleFns(alloc, main_path, mod, &cache, &module_fns);
|
||||
var facts = try imports.buildImportFacts(alloc, main_path, mod, &cache);
|
||||
|
||||
const resolved_root = try alloc.create(Node);
|
||||
@@ -1538,7 +1533,6 @@ test "lower: scan populates source-keyed caches per declaring source (E0)" {
|
||||
lowering.program_index.module_scopes = &module_scopes;
|
||||
lowering.program_index.import_graph = &import_graph;
|
||||
lowering.program_index.flat_import_graph = &flat_import_graph;
|
||||
lowering.program_index.module_fns = &module_fns;
|
||||
lowering.program_index.module_decls = &facts.decls;
|
||||
|
||||
lowering.lowerRoot(resolved_root);
|
||||
|
||||
Reference in New Issue
Block a user