refactor(imports): retain dup same-name fn authors + build identity indexes [0102a]
First of four fix-0102 sub-steps. Purely additive: retains data that the flat/directory merge currently first-wins-drops and builds two identity indexes for later bare-name disambiguation (fix-0102c). No resolution change — the existing first-wins bare path still wins; suite unchanged. - mergeFlat + directory merge: stop dropping a same-name FUNCTION authored by a different module/file. Non-function decls keep first-wins dedup; node identity dedup is untouched. - flat_import_graph: a flat-only subset of import_graph, recording an edge only for a bare `#import` (imp.name == null), never a namespaced `ns :: #import`. Threaded through resolveImports/resolveDirectoryImport and into ProgramIndex. - module_fns (path -> name -> *const FnDecl): per-module authored-function index mirroring module_scopes, built in core.zig from the main module + cache. Same-name cross-module authors stay distinct under their own paths. - imports.test.zig: asserts both a.sx/b.sx greet authors are retained in module_fns and in the global flat list, and that flat_import_graph excludes the namespaced edge while import_graph includes it. Gate (this worktree): zig build, zig build test (398/398), bash tests/run_examples.sh (457 passed) all green.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
const std = @import("std");
|
||||
const ast = @import("../ast.zig");
|
||||
const imports = @import("../imports.zig");
|
||||
const types = @import("types.zig");
|
||||
const inst = @import("inst.zig");
|
||||
const errors = @import("../errors.zig");
|
||||
@@ -570,9 +571,10 @@ pub const GlobalInfo = struct { id: inst.GlobalId, ty: TypeId };
|
||||
/// `self.program_index.<field>`; later phases hand collaborator modules a
|
||||
/// `*ProgramIndex` instead of `*Lowering`.
|
||||
///
|
||||
/// OWNS the declaration maps below. BORROWS `module_scopes` / `import_graph`
|
||||
/// (pointers into maps owned by the compilation driver, `core.zig`) — those
|
||||
/// are read-only views and are never freed here.
|
||||
/// OWNS the declaration maps below. BORROWS `module_scopes` / `import_graph` /
|
||||
/// `flat_import_graph` / `module_fns` (pointers into maps owned by the
|
||||
/// compilation driver, `core.zig`) — those are read-only views and are never
|
||||
/// freed here.
|
||||
///
|
||||
/// Per-map allocators are preserved exactly as they were on `Lowering`:
|
||||
/// `import_flags` / `fn_ast_map` / `global_names` use the lowering allocator
|
||||
@@ -587,6 +589,16 @@ pub const ProgramIndex = struct {
|
||||
/// Module path → set of directly imported paths (param_impl visibility
|
||||
/// filter). Borrowed view.
|
||||
import_graph: ?*std.StringHashMap(std.StringHashMap(void)) = null,
|
||||
/// Module path → set of directly FLAT-imported paths — the subset of
|
||||
/// `import_graph` edges from a bare `#import` (never a namespaced
|
||||
/// `ns :: #import`). fix-0102c's bare-name disambiguation walks this to
|
||||
/// decide which same-name authors a flat importer can reach. Borrowed view.
|
||||
flat_import_graph: ?*std.StringHashMap(std.StringHashMap(void)) = null,
|
||||
/// Module path → (function name → authoring `*const FnDecl`), mirroring
|
||||
/// `module_scopes`. Retains every same-name author under its own path so
|
||||
/// fix-0102c can resolve a flat call to the right module's function.
|
||||
/// Borrowed view.
|
||||
module_fns: ?*imports.ModuleFns = null,
|
||||
|
||||
// ── Declaration maps ──
|
||||
/// Function name → AST decl.
|
||||
@@ -627,7 +639,8 @@ pub const ProgramIndex = struct {
|
||||
}
|
||||
|
||||
pub fn deinit(self: *ProgramIndex) void {
|
||||
// Owned maps only — module_scopes / import_graph are borrowed.
|
||||
// Owned maps only — module_scopes / import_graph / flat_import_graph /
|
||||
// module_fns are borrowed.
|
||||
self.import_flags.deinit();
|
||||
self.fn_ast_map.deinit();
|
||||
self.qualified_fn_source.deinit();
|
||||
|
||||
Reference in New Issue
Block a user