This commit is contained in:
agra
2026-03-06 10:46:28 +02:00
parent f9dda972d2
commit 69934592d8
8 changed files with 113 additions and 14 deletions

View File

@@ -23,6 +23,7 @@ pub const Compilation = struct {
root: ?*Node = null,
resolved_root: ?*Node = null,
import_sources: std.StringHashMap([:0]const u8),
module_scopes: std.StringHashMap(std.StringHashMap(void)),
sema_result: ?sema.SemaResult = null,
ir_emitter: ?ir.LLVMEmitter = null,
@@ -34,6 +35,7 @@ pub const Compilation = struct {
.source = source,
.diagnostics = errors.DiagnosticList.init(allocator, source, file_path),
.import_sources = std.StringHashMap([:0]const u8).init(allocator),
.module_scopes = std.StringHashMap(std.StringHashMap(void)).init(allocator),
.target_config = target_config,
};
}
@@ -66,6 +68,13 @@ pub const Compilation = struct {
&self.diagnostics,
) catch return error.CompileError;
// Preserve per-module visibility scopes for C import access checking
self.module_scopes.put(self.file_path, mod.scope) catch {};
var cache_it = cache.iterator();
while (cache_it.next()) |entry| {
self.module_scopes.put(entry.key_ptr.*, entry.value_ptr.scope) catch {};
}
// Store main file source in import_sources so error reporting can find it
self.import_sources.put(self.file_path, self.source) catch {};
@@ -143,6 +152,7 @@ pub const Compilation = struct {
lowering.resolved_root = root;
lowering.target_config = self.target_config;
lowering.diagnostics = &self.diagnostics;
lowering.module_scopes = &self.module_scopes;
lowering.lowerRoot(root);
if (self.diagnostics.hasErrors()) return error.CompileError;
return module;