aboutsummaryrefslogtreecommitdiff
path: root/src/codegen/llvm.zig
diff options
context:
space:
mode:
authorMatthew Lugg <mlugg@mlugg.co.uk>2025-05-20 03:25:19 +0100
committerGitHub <noreply@github.com>2025-05-20 03:25:19 +0100
commit23c817548bbd3988a5fd224b590a4f6102dbe5db (patch)
tree5448478794cb493b456de356c2e29fb100e81cfb /src/codegen/llvm.zig
parentf2077f57ae03ef21f1bfee6e4e041c5f466fc3be (diff)
parent37a9a4e0f16c1df8de3a4add3a9566b24f024a95 (diff)
downloadzig-23c817548bbd3988a5fd224b590a4f6102dbe5db.tar.gz
zig-23c817548bbd3988a5fd224b590a4f6102dbe5db.zip
Merge pull request #23836 from mlugg/incr-fixes
Incremental fixes, refactor `Zcu.File`
Diffstat (limited to 'src/codegen/llvm.zig')
-rw-r--r--src/codegen/llvm.zig47
1 files changed, 17 insertions, 30 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index 6a18b49e33..e6926e8468 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -587,13 +587,8 @@ pub const Object = struct {
// into the garbage can by converting into absolute paths. What
// a terrible tragedy.
const compile_unit_dir = blk: {
- if (comp.zcu) |zcu| m: {
- const d = try zcu.main_mod.root.joinString(arena, "");
- if (d.len == 0) break :m;
- if (std.fs.path.isAbsolute(d)) break :blk d;
- break :blk std.fs.realpathAlloc(arena, d) catch break :blk d;
- }
- break :blk try std.process.getCwdAlloc(arena);
+ const zcu = comp.zcu orelse break :blk comp.dirs.cwd;
+ break :blk try zcu.main_mod.root.toAbsolute(comp.dirs, arena);
};
const debug_file = try builder.debugFile(
@@ -1135,7 +1130,7 @@ pub const Object = struct {
const func = zcu.funcInfo(func_index);
const nav = ip.getNav(func.owner_nav);
const file_scope = zcu.navFileScopeIndex(func.owner_nav);
- const owner_mod = zcu.fileByIndex(file_scope).mod;
+ const owner_mod = zcu.fileByIndex(file_scope).mod.?;
const fn_ty = Type.fromInterned(func.ty);
const fn_info = zcu.typeToFunc(fn_ty).?;
const target = owner_mod.resolved_target.result;
@@ -1735,20 +1730,14 @@ pub const Object = struct {
const gop = try o.debug_file_map.getOrPut(gpa, file_index);
errdefer assert(o.debug_file_map.remove(file_index));
if (gop.found_existing) return gop.value_ptr.*;
- const file = o.pt.zcu.fileByIndex(file_index);
+ const zcu = o.pt.zcu;
+ const path = zcu.fileByIndex(file_index).path;
+ const abs_path = try path.toAbsolute(zcu.comp.dirs, gpa);
+ defer gpa.free(abs_path);
+
gop.value_ptr.* = try o.builder.debugFile(
- try o.builder.metadataString(std.fs.path.basename(file.sub_file_path)),
- dir_path: {
- const sub_path = std.fs.path.dirname(file.sub_file_path) orelse "";
- const dir_path = try file.mod.root.joinString(gpa, sub_path);
- defer gpa.free(dir_path);
- if (std.fs.path.isAbsolute(dir_path))
- break :dir_path try o.builder.metadataString(dir_path);
- var abs_buffer: [std.fs.max_path_bytes]u8 = undefined;
- const abs_path = std.fs.realpath(dir_path, &abs_buffer) catch
- break :dir_path try o.builder.metadataString(dir_path);
- break :dir_path try o.builder.metadataString(abs_path);
- },
+ try o.builder.metadataString(std.fs.path.basename(abs_path)),
+ try o.builder.metadataString(std.fs.path.dirname(abs_path) orelse ""),
);
return gop.value_ptr.*;
}
@@ -2646,11 +2635,9 @@ pub const Object = struct {
const zcu = pt.zcu;
const ip = &zcu.intern_pool;
- const std_mod = zcu.std_mod;
- const std_file_imported = pt.importPkg(std_mod) catch unreachable;
-
+ const std_file_index = zcu.module_roots.get(zcu.std_mod).?.unwrap().?;
const builtin_str = try ip.getOrPutString(zcu.gpa, pt.tid, "builtin", .no_embedded_nulls);
- const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_imported.file_index));
+ const std_file_root_type = Type.fromInterned(zcu.fileRootType(std_file_index));
const std_namespace = ip.namespacePtr(std_file_root_type.getNamespaceIndex(zcu));
const builtin_nav = std_namespace.pub_decls.getKeyAdapted(builtin_str, Zcu.Namespace.NameAdapter{ .zcu = zcu }).?;
@@ -2683,7 +2670,7 @@ pub const Object = struct {
const ip = &zcu.intern_pool;
const gpa = o.gpa;
const nav = ip.getNav(nav_index);
- const owner_mod = zcu.navFileScope(nav_index).mod;
+ const owner_mod = zcu.navFileScope(nav_index).mod.?;
const ty: Type = .fromInterned(nav.typeOf(ip));
const gop = try o.nav_map.getOrPut(gpa, nav_index);
if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function;
@@ -3013,7 +3000,7 @@ pub const Object = struct {
if (is_extern) {
variable_index.setLinkage(.external, &o.builder);
variable_index.setUnnamedAddr(.default, &o.builder);
- if (is_threadlocal and !zcu.navFileScope(nav_index).mod.single_threaded)
+ if (is_threadlocal and !zcu.navFileScope(nav_index).mod.?.single_threaded)
variable_index.setThreadLocal(.generaldynamic, &o.builder);
if (is_weak_linkage) variable_index.setLinkage(.extern_weak, &o.builder);
if (is_dll_import) variable_index.setDllStorageClass(.dllimport, &o.builder);
@@ -4514,7 +4501,7 @@ pub const NavGen = struct {
err_msg: ?*Zcu.ErrorMsg,
fn ownerModule(ng: NavGen) *Package.Module {
- return ng.object.pt.zcu.navFileScope(ng.nav_index).mod;
+ return ng.object.pt.zcu.navFileScope(ng.nav_index).mod.?;
}
fn todo(ng: *NavGen, comptime format: []const u8, args: anytype) Error {
@@ -4557,7 +4544,7 @@ pub const NavGen = struct {
}, &o.builder);
const file_scope = zcu.navFileScopeIndex(nav_index);
- const mod = zcu.fileByIndex(file_scope).mod;
+ const mod = zcu.fileByIndex(file_scope).mod.?;
if (is_threadlocal and !mod.single_threaded)
variable_index.setThreadLocal(.generaldynamic, &o.builder);
@@ -5121,7 +5108,7 @@ pub const FuncGen = struct {
const func = zcu.funcInfo(inline_func);
const nav = ip.getNav(func.owner_nav);
const file_scope = zcu.navFileScopeIndex(func.owner_nav);
- const mod = zcu.fileByIndex(file_scope).mod;
+ const mod = zcu.fileByIndex(file_scope).mod.?;
self.file = try o.getDebugFile(file_scope);