authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-06-30 03:00:07+01:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-07-04 21:01:41+01:00
logded5c759f83a4da355a128dd4d7f5e22cbd3cabe
treeb862bbdf36b892e9c39f472c6759f084c87d64b2
parent089bbd6588d82ccda0646e756006cf5787eadef2
signaturelock-open Commit is signed but in an unrecognized format.

Zcu: store `LazySrcLoc` in error messages

This change modifies `Zcu.ErrorMsg` to store a `Zcu.LazySrcLoc` rather than a `Zcu.SrcLoc`. Everything else is dominoes. The reason for this change is incremental compilation. If a failed `AnalUnit` is up-to-date on an update, we want to re-use the old error messages. However, the file containing the error location may have been modified, and `SrcLoc` cannot survive such a modification. `LazySrcLoc` is designed to be correct across incremental updates. Therefore, we defer source location resolution until `Compilation` gathers the compile errors into the `ErrorBundle`.

28 files changed, 162 insertions(+), 207 deletions(-)

src/Compilation.zig+47-44
...@@ -2629,22 +2629,24 @@ fn reportMultiModuleErrors(mod: *Module) !void {...@@ -2629,22 +2629,24 @@ fn reportMultiModuleErrors(mod: *Module) !void {
2629 for (notes[0..num_notes], file.references.items[0..num_notes], 0..) |*note, ref, i| {2629 for (notes[0..num_notes], file.references.items[0..num_notes], 0..) |*note, ref, i| {
2630 errdefer for (notes[0..i]) |*n| n.deinit(mod.gpa);2630 errdefer for (notes[0..i]) |*n| n.deinit(mod.gpa);
2631 note.* = switch (ref) {2631 note.* = switch (ref) {
2632 .import => |loc| blk: {2632 .import => |import| try Module.ErrorMsg.init(
2633 break :blk try Module.ErrorMsg.init(2633 mod.gpa,
2634 mod.gpa,2634 .{
2635 loc,2635 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, import.file, .main_struct_inst),
2636 "imported from module {s}",2636 .offset = .{ .token_abs = import.token },
2637 .{loc.file_scope.mod.fully_qualified_name},2637 },
2638 );2638 "imported from module {s}",
2639 },2639 .{import.file.mod.fully_qualified_name},
2640 .root => |pkg| blk: {2640 ),
2641 break :blk try Module.ErrorMsg.init(2641 .root => |pkg| try Module.ErrorMsg.init(
2642 mod.gpa,2642 mod.gpa,
2643 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },2643 .{
2644 "root of module {s}",2644 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, file, .main_struct_inst),
2645 .{pkg.fully_qualified_name},2645 .offset = .entire_file,
2646 );2646 },
2647 },2647 "root of module {s}",
2648 .{pkg.fully_qualified_name},
2649 ),
2648 };2650 };
2649 }2651 }
2650 errdefer for (notes[0..num_notes]) |*n| n.deinit(mod.gpa);2652 errdefer for (notes[0..num_notes]) |*n| n.deinit(mod.gpa);
...@@ -2652,7 +2654,10 @@ fn reportMultiModuleErrors(mod: *Module) !void {...@@ -2652,7 +2654,10 @@ fn reportMultiModuleErrors(mod: *Module) !void {
2652 if (omitted > 0) {2654 if (omitted > 0) {
2653 notes[num_notes] = try Module.ErrorMsg.init(2655 notes[num_notes] = try Module.ErrorMsg.init(
2654 mod.gpa,2656 mod.gpa,
2655 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },2657 .{
2658 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, file, .main_struct_inst),
2659 .offset = .entire_file,
2660 },
2656 "{} more references omitted",2661 "{} more references omitted",
2657 .{omitted},2662 .{omitted},
2658 );2663 );
...@@ -2661,7 +2666,10 @@ fn reportMultiModuleErrors(mod: *Module) !void {...@@ -2661,7 +2666,10 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26612666
2662 const err = try Module.ErrorMsg.create(2667 const err = try Module.ErrorMsg.create(
2663 mod.gpa,2668 mod.gpa,
2664 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },2669 .{
2670 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, file, .main_struct_inst),
2671 .offset = .entire_file,
2672 },
2665 "file exists in multiple modules",2673 "file exists in multiple modules",
2666 .{},2674 .{},
2667 );2675 );
...@@ -3060,7 +3068,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {...@@ -3060,7 +3068,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
30603068
3061 const values = zcu.compile_log_sources.values();3069 const values = zcu.compile_log_sources.values();
3062 // First one will be the error; subsequent ones will be notes.3070 // First one will be the error; subsequent ones will be notes.
3063 const src_loc = values[0].src().upgrade(zcu);3071 const src_loc = values[0].src();
3064 const err_msg: Module.ErrorMsg = .{3072 const err_msg: Module.ErrorMsg = .{
3065 .src_loc = src_loc,3073 .src_loc = src_loc,
3066 .msg = "found compile log statement",3074 .msg = "found compile log statement",
...@@ -3070,7 +3078,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {...@@ -3070,7 +3078,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
30703078
3071 for (values[1..], err_msg.notes) |src_info, *note| {3079 for (values[1..], err_msg.notes) |src_info, *note| {
3072 note.* = .{3080 note.* = .{
3073 .src_loc = src_info.src().upgrade(zcu),3081 .src_loc = src_info.src(),
3074 .msg = "also here",3082 .msg = "also here",
3075 };3083 };
3076 }3084 }
...@@ -3139,8 +3147,9 @@ pub fn addModuleErrorMsg(...@@ -3139,8 +3147,9 @@ pub fn addModuleErrorMsg(
3139) !void {3147) !void {
3140 const gpa = eb.gpa;3148 const gpa = eb.gpa;
3141 const ip = &mod.intern_pool;3149 const ip = &mod.intern_pool;
3142 const err_source = module_err_msg.src_loc.file_scope.getSource(gpa) catch |err| {3150 const err_src_loc = module_err_msg.src_loc.upgrade(mod);
3143 const file_path = try module_err_msg.src_loc.file_scope.fullPath(gpa);3151 const err_source = err_src_loc.file_scope.getSource(gpa) catch |err| {
3152 const file_path = try err_src_loc.file_scope.fullPath(gpa);
3144 defer gpa.free(file_path);3153 defer gpa.free(file_path);
3145 try eb.addRootErrorMessage(.{3154 try eb.addRootErrorMessage(.{
3146 .msg = try eb.printString("unable to load '{s}': {s}", .{3155 .msg = try eb.printString("unable to load '{s}': {s}", .{
...@@ -3149,9 +3158,9 @@ pub fn addModuleErrorMsg(...@@ -3149,9 +3158,9 @@ pub fn addModuleErrorMsg(
3149 });3158 });
3150 return;3159 return;
3151 };3160 };
3152 const err_span = try module_err_msg.src_loc.span(gpa);3161 const err_span = try err_src_loc.span(gpa);
3153 const err_loc = std.zig.findLineColumn(err_source.bytes, err_span.main);3162 const err_loc = std.zig.findLineColumn(err_source.bytes, err_span.main);
3154 const file_path = try module_err_msg.src_loc.file_scope.fullPath(gpa);3163 const file_path = try err_src_loc.file_scope.fullPath(gpa);
3155 defer gpa.free(file_path);3164 defer gpa.free(file_path);
31563165
3157 var ref_traces: std.ArrayListUnmanaged(ErrorBundle.ReferenceTrace) = .{};3166 var ref_traces: std.ArrayListUnmanaged(ErrorBundle.ReferenceTrace) = .{};
...@@ -3208,7 +3217,7 @@ pub fn addModuleErrorMsg(...@@ -3208,7 +3217,7 @@ pub fn addModuleErrorMsg(
3208 .span_end = err_span.end,3217 .span_end = err_span.end,
3209 .line = @intCast(err_loc.line),3218 .line = @intCast(err_loc.line),
3210 .column = @intCast(err_loc.column),3219 .column = @intCast(err_loc.column),
3211 .source_line = if (module_err_msg.src_loc.lazy == .entire_file)3220 .source_line = if (err_src_loc.lazy == .entire_file)
3212 03221 0
3213 else3222 else
3214 try eb.addString(err_loc.source_line),3223 try eb.addString(err_loc.source_line),
...@@ -3225,10 +3234,11 @@ pub fn addModuleErrorMsg(...@@ -3225,10 +3234,11 @@ pub fn addModuleErrorMsg(
3225 defer notes.deinit(gpa);3234 defer notes.deinit(gpa);
32263235
3227 for (module_err_msg.notes) |module_note| {3236 for (module_err_msg.notes) |module_note| {
3228 const source = try module_note.src_loc.file_scope.getSource(gpa);3237 const note_src_loc = module_note.src_loc.upgrade(mod);
3229 const span = try module_note.src_loc.span(gpa);3238 const source = try note_src_loc.file_scope.getSource(gpa);
3239 const span = try note_src_loc.span(gpa);
3230 const loc = std.zig.findLineColumn(source.bytes, span.main);3240 const loc = std.zig.findLineColumn(source.bytes, span.main);
3231 const note_file_path = try module_note.src_loc.file_scope.fullPath(gpa);3241 const note_file_path = try note_src_loc.file_scope.fullPath(gpa);
3232 defer gpa.free(note_file_path);3242 defer gpa.free(note_file_path);
32333243
3234 const gop = try notes.getOrPutContext(gpa, .{3244 const gop = try notes.getOrPutContext(gpa, .{
...@@ -3522,7 +3532,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo...@@ -3522,7 +3532,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
3522 InternPool.AnalUnit.wrap(.{ .decl = decl_index }),3532 InternPool.AnalUnit.wrap(.{ .decl = decl_index }),
3523 try Module.ErrorMsg.create(3533 try Module.ErrorMsg.create(
3524 gpa,3534 gpa,
3525 decl.navSrcLoc(module).upgrade(module),3535 decl.navSrcLoc(module),
3526 "unable to update line number: {s}",3536 "unable to update line number: {s}",
3527 .{@errorName(err)},3537 .{@errorName(err)},
3528 ),3538 ),
...@@ -4023,9 +4033,8 @@ fn workerAstGenFile(...@@ -4023,9 +4033,8 @@ fn workerAstGenFile(
4023 const res = mod.importFile(file, import_path) catch continue;4033 const res = mod.importFile(file, import_path) catch continue;
4024 if (!res.is_pkg) {4034 if (!res.is_pkg) {
4025 res.file.addReference(mod.*, .{ .import = .{4035 res.file.addReference(mod.*, .{ .import = .{
4026 .file_scope = file,4036 .file = file,
4027 .base_node = 0,4037 .token = item.data.token,
4028 .lazy = .{ .token_abs = item.data.token },
4029 } }) catch continue;4038 } }) catch continue;
4030 }4039 }
4031 break :blk res;4040 break :blk res;
...@@ -4398,20 +4407,14 @@ fn reportRetryableAstGenError(...@@ -4398,20 +4407,14 @@ fn reportRetryableAstGenError(
43984407
4399 file.status = .retryable_failure;4408 file.status = .retryable_failure;
44004409
4401 const src_loc: Module.SrcLoc = switch (src) {4410 const src_loc: Module.LazySrcLoc = switch (src) {
4402 .root => .{4411 .root => .{
4403 .file_scope = file,4412 .base_node_inst = try mod.intern_pool.trackZir(gpa, file, .main_struct_inst),
4404 .base_node = 0,4413 .offset = .entire_file,
4405 .lazy = .entire_file,
4406 },4414 },
4407 .import => |info| blk: {4415 .import => |info| .{
4408 const importing_file = info.importing_file;4416 .base_node_inst = try mod.intern_pool.trackZir(gpa, info.importing_file, .main_struct_inst),
44094417 .offset = .{ .token_abs = info.import_tok },
4410 break :blk .{
4411 .file_scope = importing_file,
4412 .base_node = 0,
4413 .lazy = .{ .token_abs = info.import_tok },
4414 };
4415 },4418 },
4416 };4419 };
44174420
src/Sema.zig+4-6
...@@ -2425,8 +2425,7 @@ pub fn errNote(...@@ -2425,8 +2425,7 @@ pub fn errNote(
2425 comptime format: []const u8,2425 comptime format: []const u8,
2426 args: anytype,2426 args: anytype,
2427) error{OutOfMemory}!void {2427) error{OutOfMemory}!void {
2428 const zcu = sema.mod;2428 return sema.mod.errNote(src, parent, format, args);
2429 return zcu.errNoteNonLazy(src.upgrade(zcu), parent, format, args);
2430}2429}
24312430
2432fn addFieldErrNote(2431fn addFieldErrNote(
...@@ -2454,7 +2453,7 @@ pub fn errMsg(...@@ -2454,7 +2453,7 @@ pub fn errMsg(
2454 args: anytype,2453 args: anytype,
2455) Allocator.Error!*Module.ErrorMsg {2454) Allocator.Error!*Module.ErrorMsg {
2456 assert(src.offset != .unneeded);2455 assert(src.offset != .unneeded);
2457 return Module.ErrorMsg.create(sema.gpa, src.upgrade(sema.mod), format, args);2456 return Module.ErrorMsg.create(sema.gpa, src, format, args);
2458}2457}
24592458
2460pub fn fail(2459pub fn fail(
...@@ -2542,7 +2541,6 @@ fn reparentOwnedErrorMsg(...@@ -2542,7 +2541,6 @@ fn reparentOwnedErrorMsg(
2542 args: anytype,2541 args: anytype,
2543) !void {2542) !void {
2544 const mod = sema.mod;2543 const mod = sema.mod;
2545 const resolved_src = src.upgrade(mod);
2546 const msg_str = try std.fmt.allocPrint(mod.gpa, format, args);2544 const msg_str = try std.fmt.allocPrint(mod.gpa, format, args);
25472545
2548 const orig_notes = msg.notes.len;2546 const orig_notes = msg.notes.len;
...@@ -2553,7 +2551,7 @@ fn reparentOwnedErrorMsg(...@@ -2553,7 +2551,7 @@ fn reparentOwnedErrorMsg(
2553 .msg = msg.msg,2551 .msg = msg.msg,
2554 };2552 };
25552553
2556 msg.src_loc = resolved_src;2554 msg.src_loc = src;
2557 msg.msg = msg_str;2555 msg.msg = msg_str;
2558}2556}
25592557
...@@ -13883,7 +13881,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -13883,7 +13881,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
13883 return sema.fail(block, operand_src, "file path name cannot be empty", .{});13881 return sema.fail(block, operand_src, "file path name cannot be empty", .{});
13884 }13882 }
1388513883
13886 const val = mod.embedFile(block.getFileScope(mod), name, operand_src.upgrade(mod)) catch |err| switch (err) {13884 const val = mod.embedFile(block.getFileScope(mod), name, operand_src) catch |err| switch (err) {
13887 error.ImportOutsideModulePath => {13885 error.ImportOutsideModulePath => {
13888 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});13886 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});
13889 },13887 },
src/Zcu.zig+30-48
...@@ -289,10 +289,6 @@ pub const Export = struct {...@@ -289,10 +289,6 @@ pub const Export = struct {
289 section: InternPool.OptionalNullTerminatedString = .none,289 section: InternPool.OptionalNullTerminatedString = .none,
290 visibility: std.builtin.SymbolVisibility = .default,290 visibility: std.builtin.SymbolVisibility = .default,
291 };291 };
292
293 pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc {
294 return exp.src.upgrade(mod);
295 }
296};292};
297293
298pub const Reference = struct {294pub const Reference = struct {
...@@ -746,7 +742,10 @@ pub const File = struct {...@@ -746,7 +742,10 @@ pub const File = struct {
746 /// A single reference to a file.742 /// A single reference to a file.
747 pub const Reference = union(enum) {743 pub const Reference = union(enum) {
748 /// The file is imported directly (i.e. not as a package) with @import.744 /// The file is imported directly (i.e. not as a package) with @import.
749 import: SrcLoc,745 import: struct {
746 file: *File,
747 token: Ast.TokenIndex,
748 },
750 /// The file is the root of a module.749 /// The file is the root of a module.
751 root: *Package.Module,750 root: *Package.Module,
752 };751 };
...@@ -900,7 +899,7 @@ pub const File = struct {...@@ -900,7 +899,7 @@ pub const File = struct {
900 }899 }
901900
902 /// Add a reference to this file during AstGen.901 /// Add a reference to this file during AstGen.
903 pub fn addReference(file: *File, mod: Module, ref: File.Reference) !void {902 pub fn addReference(file: *File, zcu: Zcu, ref: File.Reference) !void {
904 // Don't add the same module root twice. Note that since we always add module roots at the903 // Don't add the same module root twice. Note that since we always add module roots at the
905 // front of the references array (see below), this loop is actually O(1) on valid code.904 // front of the references array (see below), this loop is actually O(1) on valid code.
906 if (ref == .root) {905 if (ref == .root) {
...@@ -917,17 +916,17 @@ pub const File = struct {...@@ -917,17 +916,17 @@ pub const File = struct {
917 // to make multi-module errors more helpful (since "root-of" notes are generally more916 // to make multi-module errors more helpful (since "root-of" notes are generally more
918 // informative than "imported-from" notes). This path is hit very rarely, so the speed917 // informative than "imported-from" notes). This path is hit very rarely, so the speed
919 // of the insert operation doesn't matter too much.918 // of the insert operation doesn't matter too much.
920 .root => try file.references.insert(mod.gpa, 0, ref),919 .root => try file.references.insert(zcu.gpa, 0, ref),
921920
922 // Other references we'll just put at the end.921 // Other references we'll just put at the end.
923 else => try file.references.append(mod.gpa, ref),922 else => try file.references.append(zcu.gpa, ref),
924 }923 }
925924
926 const pkg = switch (ref) {925 const mod = switch (ref) {
927 .import => |loc| loc.file_scope.mod,926 .import => |import| import.file.mod,
928 .root => |pkg| pkg,927 .root => |mod| mod,
929 };928 };
930 if (pkg != file.mod) file.multi_pkg = true;929 if (mod != file.mod) file.multi_pkg = true;
931 }930 }
932931
933 /// Mark this file and every file referenced by it as multi_pkg and report an932 /// Mark this file and every file referenced by it as multi_pkg and report an
...@@ -967,30 +966,25 @@ pub const EmbedFile = struct {...@@ -967,30 +966,25 @@ pub const EmbedFile = struct {
967 owner: *Package.Module,966 owner: *Package.Module,
968 stat: Cache.File.Stat,967 stat: Cache.File.Stat,
969 val: InternPool.Index,968 val: InternPool.Index,
970 src_loc: SrcLoc,969 src_loc: LazySrcLoc,
971};970};
972971
973/// This struct holds data necessary to construct API-facing `AllErrors.Message`.972/// This struct holds data necessary to construct API-facing `AllErrors.Message`.
974/// Its memory is managed with the general purpose allocator so that they973/// Its memory is managed with the general purpose allocator so that they
975/// can be created and destroyed in response to incremental updates.974/// can be created and destroyed in response to incremental updates.
976pub const ErrorMsg = struct {975pub const ErrorMsg = struct {
977 src_loc: SrcLoc,976 src_loc: LazySrcLoc,
978 msg: []const u8,977 msg: []const u8,
979 notes: []ErrorMsg = &.{},978 notes: []ErrorMsg = &.{},
980 reference_trace_root: AnalUnit.Optional = .none,979 reference_trace_root: AnalUnit.Optional = .none,
981980
982 pub const Trace = struct {
983 decl: InternPool.NullTerminatedString,
984 src_loc: SrcLoc,
985 };
986
987 pub fn create(981 pub fn create(
988 gpa: Allocator,982 gpa: Allocator,
989 src_loc: SrcLoc,983 src_loc: LazySrcLoc,
990 comptime format: []const u8,984 comptime format: []const u8,
991 args: anytype,985 args: anytype,
992 ) !*ErrorMsg {986 ) !*ErrorMsg {
993 assert(src_loc.lazy != .unneeded);987 assert(src_loc.offset != .unneeded);
994 const err_msg = try gpa.create(ErrorMsg);988 const err_msg = try gpa.create(ErrorMsg);
995 errdefer gpa.destroy(err_msg);989 errdefer gpa.destroy(err_msg);
996 err_msg.* = try ErrorMsg.init(gpa, src_loc, format, args);990 err_msg.* = try ErrorMsg.init(gpa, src_loc, format, args);
...@@ -1006,7 +1000,7 @@ pub const ErrorMsg = struct {...@@ -1006,7 +1000,7 @@ pub const ErrorMsg = struct {
10061000
1007 pub fn init(1001 pub fn init(
1008 gpa: Allocator,1002 gpa: Allocator,
1009 src_loc: SrcLoc,1003 src_loc: LazySrcLoc,
1010 comptime format: []const u8,1004 comptime format: []const u8,
1011 args: anytype,1005 args: anytype,
1012 ) !ErrorMsg {1006 ) !ErrorMsg {
...@@ -1994,15 +1988,12 @@ pub const LazySrcLoc = struct {...@@ -1994,15 +1988,12 @@ pub const LazySrcLoc = struct {
1994 entire_file,1988 entire_file,
1995 /// The source location points to a byte offset within a source file,1989 /// The source location points to a byte offset within a source file,
1996 /// offset from 0. The source file is determined contextually.1990 /// offset from 0. The source file is determined contextually.
1997 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
1998 byte_abs: u32,1991 byte_abs: u32,
1999 /// The source location points to a token within a source file,1992 /// The source location points to a token within a source file,
2000 /// offset from 0. The source file is determined contextually.1993 /// offset from 0. The source file is determined contextually.
2001 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
2002 token_abs: u32,1994 token_abs: u32,
2003 /// The source location points to an AST node within a source file,1995 /// The source location points to an AST node within a source file,
2004 /// offset from 0. The source file is determined contextually.1996 /// offset from 0. The source file is determined contextually.
2005 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
2006 node_abs: u32,1997 node_abs: u32,
2007 /// The source location points to a byte offset within a source file,1998 /// The source location points to a byte offset within a source file,
2008 /// offset from the byte offset of the base node within the file.1999 /// offset from the byte offset of the base node within the file.
...@@ -2373,8 +2364,7 @@ pub const LazySrcLoc = struct {...@@ -2373,8 +2364,7 @@ pub const LazySrcLoc = struct {
2373 }2364 }
23742365
2375 /// Resolve the file and AST node of `base_node_inst` to get a resolved `SrcLoc`.2366 /// Resolve the file and AST node of `base_node_inst` to get a resolved `SrcLoc`.
2376 /// TODO: it is incorrect to store a `SrcLoc` anywhere due to incremental compilation.2367 /// The resulting `SrcLoc` should only be used ephemerally, as it is not correct across incremental updates.
2377 /// Probably the type should be removed entirely and this resolution performed on-the-fly when needed.
2378 pub fn upgrade(lazy: LazySrcLoc, zcu: *Zcu) SrcLoc {2368 pub fn upgrade(lazy: LazySrcLoc, zcu: *Zcu) SrcLoc {
2379 const file, const base_node = resolveBaseNode(lazy.base_node_inst, zcu);2369 const file, const base_node = resolveBaseNode(lazy.base_node_inst, zcu);
2380 return .{2370 return .{
...@@ -3478,7 +3468,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {...@@ -3478,7 +3468,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
3478 try mod.retryable_failures.append(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }));3468 try mod.retryable_failures.append(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }));
3479 mod.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try ErrorMsg.create(3469 mod.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try ErrorMsg.create(
3480 mod.gpa,3470 mod.gpa,
3481 decl.navSrcLoc(mod).upgrade(mod),3471 decl.navSrcLoc(mod),
3482 "unable to analyze: {s}",3472 "unable to analyze: {s}",
3483 .{@errorName(e)},3473 .{@errorName(e)},
3484 ));3474 ));
...@@ -3655,7 +3645,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In...@@ -3655,7 +3645,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
3655 AnalUnit.wrap(.{ .decl = decl_index }),3645 AnalUnit.wrap(.{ .decl = decl_index }),
3656 try Module.ErrorMsg.create(3646 try Module.ErrorMsg.create(
3657 gpa,3647 gpa,
3658 decl.navSrcLoc(zcu).upgrade(zcu),3648 decl.navSrcLoc(zcu),
3659 "invalid liveness: {s}",3649 "invalid liveness: {s}",
3660 .{@errorName(err)},3650 .{@errorName(err)},
3661 ),3651 ),
...@@ -3679,7 +3669,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In...@@ -3679,7 +3669,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
3679 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);3669 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
3680 zcu.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try Module.ErrorMsg.create(3670 zcu.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try Module.ErrorMsg.create(
3681 gpa,3671 gpa,
3682 decl.navSrcLoc(zcu).upgrade(zcu),3672 decl.navSrcLoc(zcu),
3683 "unable to codegen: {s}",3673 "unable to codegen: {s}",
3684 .{@errorName(err)},3674 .{@errorName(err)},
3685 ));3675 ));
...@@ -4480,7 +4470,7 @@ pub fn embedFile(...@@ -4480,7 +4470,7 @@ pub fn embedFile(
4480 mod: *Module,4470 mod: *Module,
4481 cur_file: *File,4471 cur_file: *File,
4482 import_string: []const u8,4472 import_string: []const u8,
4483 src_loc: SrcLoc,4473 src_loc: LazySrcLoc,
4484) !InternPool.Index {4474) !InternPool.Index {
4485 const gpa = mod.gpa;4475 const gpa = mod.gpa;
44864476
...@@ -4555,7 +4545,7 @@ fn newEmbedFile(...@@ -4555,7 +4545,7 @@ fn newEmbedFile(
4555 sub_file_path: []const u8,4545 sub_file_path: []const u8,
4556 resolved_path: []const u8,4546 resolved_path: []const u8,
4557 result: **EmbedFile,4547 result: **EmbedFile,
4558 src_loc: SrcLoc,4548 src_loc: LazySrcLoc,
4559) !InternPool.Index {4549) !InternPool.Index {
4560 const gpa = mod.gpa;4550 const gpa = mod.gpa;
4561 const ip = &mod.intern_pool;4551 const ip = &mod.intern_pool;
...@@ -5320,17 +5310,13 @@ pub fn initNewAnonDecl(...@@ -5320,17 +5310,13 @@ pub fn initNewAnonDecl(
5320 new_decl.analysis = .complete;5310 new_decl.analysis = .complete;
5321}5311}
53225312
5323pub fn errNoteNonLazy(5313pub fn errNote(
5324 mod: *Module,5314 mod: *Module,
5325 src_loc: SrcLoc,5315 src_loc: LazySrcLoc,
5326 parent: *ErrorMsg,5316 parent: *ErrorMsg,
5327 comptime format: []const u8,5317 comptime format: []const u8,
5328 args: anytype,5318 args: anytype,
5329) error{OutOfMemory}!void {5319) error{OutOfMemory}!void {
5330 if (src_loc.lazy == .unneeded) {
5331 assert(parent.src_loc.lazy == .unneeded);
5332 return;
5333 }
5334 const msg = try std.fmt.allocPrint(mod.gpa, format, args);5320 const msg = try std.fmt.allocPrint(mod.gpa, format, args);
5335 errdefer mod.gpa.free(msg);5321 errdefer mod.gpa.free(msg);
53365322
...@@ -5458,14 +5444,12 @@ fn processExportsInner(...@@ -5458,14 +5444,12 @@ fn processExportsInner(
5458 if (gop.found_existing) {5444 if (gop.found_existing) {
5459 new_export.status = .failed_retryable;5445 new_export.status = .failed_retryable;
5460 try zcu.failed_exports.ensureUnusedCapacity(gpa, 1);5446 try zcu.failed_exports.ensureUnusedCapacity(gpa, 1);
5461 const src_loc = new_export.getSrcLoc(zcu);5447 const msg = try ErrorMsg.create(gpa, new_export.src, "exported symbol collision: {}", .{
5462 const msg = try ErrorMsg.create(gpa, src_loc, "exported symbol collision: {}", .{
5463 new_export.opts.name.fmt(&zcu.intern_pool),5448 new_export.opts.name.fmt(&zcu.intern_pool),
5464 });5449 });
5465 errdefer msg.destroy(gpa);5450 errdefer msg.destroy(gpa);
5466 const other_export = zcu.all_exports.items[gop.value_ptr.*];5451 const other_export = zcu.all_exports.items[gop.value_ptr.*];
5467 const other_src_loc = other_export.getSrcLoc(zcu);5452 try zcu.errNote(other_export.src, msg, "other symbol here", .{});
5468 try zcu.errNoteNonLazy(other_src_loc, msg, "other symbol here", .{});
5469 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, msg);5453 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, msg);
5470 new_export.status = .failed;5454 new_export.status = .failed;
5471 } else {5455 } else {
...@@ -5493,8 +5477,7 @@ fn handleUpdateExports(...@@ -5493,8 +5477,7 @@ fn handleUpdateExports(
5493 const new_export = &zcu.all_exports.items[export_idx];5477 const new_export = &zcu.all_exports.items[export_idx];
5494 new_export.status = .failed_retryable;5478 new_export.status = .failed_retryable;
5495 try zcu.failed_exports.ensureUnusedCapacity(gpa, 1);5479 try zcu.failed_exports.ensureUnusedCapacity(gpa, 1);
5496 const src_loc = new_export.getSrcLoc(zcu);5480 const msg = try ErrorMsg.create(gpa, new_export.src, "unable to export: {s}", .{
5497 const msg = try ErrorMsg.create(gpa, src_loc, "unable to export: {s}", .{
5498 @errorName(err),5481 @errorName(err),
5499 });5482 });
5500 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, msg);5483 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, msg);
...@@ -5658,7 +5641,7 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {...@@ -5658,7 +5641,7 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {
5658 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);5641 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
5659 zcu.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try ErrorMsg.create(5642 zcu.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try ErrorMsg.create(
5660 gpa,5643 gpa,
5661 decl.navSrcLoc(zcu).upgrade(zcu),5644 decl.navSrcLoc(zcu),
5662 "unable to codegen: {s}",5645 "unable to codegen: {s}",
5663 .{@errorName(err)},5646 .{@errorName(err)},
5664 ));5647 ));
...@@ -5685,9 +5668,8 @@ fn reportRetryableFileError(...@@ -5685,9 +5668,8 @@ fn reportRetryableFileError(
5685 const err_msg = try ErrorMsg.create(5668 const err_msg = try ErrorMsg.create(
5686 mod.gpa,5669 mod.gpa,
5687 .{5670 .{
5688 .file_scope = file,5671 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, file, .main_struct_inst),
5689 .base_node = 0,5672 .offset = .entire_file,
5690 .lazy = .entire_file,
5691 },5673 },
5692 format,5674 format,
5693 args,5675 args,
src/arch/aarch64/CodeGen.zig+2-2
...@@ -59,7 +59,7 @@ args: []MCValue,...@@ -59,7 +59,7 @@ args: []MCValue,
59ret_mcv: MCValue,59ret_mcv: MCValue,
60fn_type: Type,60fn_type: Type,
61arg_index: u32,61arg_index: u32,
62src_loc: Module.SrcLoc,62src_loc: Module.LazySrcLoc,
63stack_align: u32,63stack_align: u32,
6464
65/// MIR Instructions65/// MIR Instructions
...@@ -331,7 +331,7 @@ const Self = @This();...@@ -331,7 +331,7 @@ const Self = @This();
331331
332pub fn generate(332pub fn generate(
333 lf: *link.File,333 lf: *link.File,
334 src_loc: Module.SrcLoc,334 src_loc: Module.LazySrcLoc,
335 func_index: InternPool.Index,335 func_index: InternPool.Index,
336 air: Air,336 air: Air,
337 liveness: Liveness,337 liveness: Liveness,
src/arch/aarch64/Emit.zig+1-1
...@@ -22,7 +22,7 @@ bin_file: *link.File,...@@ -22,7 +22,7 @@ bin_file: *link.File,
22debug_output: DebugInfoOutput,22debug_output: DebugInfoOutput,
23target: *const std.Target,23target: *const std.Target,
24err_msg: ?*ErrorMsg = null,24err_msg: ?*ErrorMsg = null,
25src_loc: Module.SrcLoc,25src_loc: Module.LazySrcLoc,
26code: *std.ArrayList(u8),26code: *std.ArrayList(u8),
2727
28prev_di_line: u32,28prev_di_line: u32,
src/arch/arm/CodeGen.zig+2-2
...@@ -59,7 +59,7 @@ args: []MCValue,...@@ -59,7 +59,7 @@ args: []MCValue,
59ret_mcv: MCValue,59ret_mcv: MCValue,
60fn_type: Type,60fn_type: Type,
61arg_index: u32,61arg_index: u32,
62src_loc: Module.SrcLoc,62src_loc: Module.LazySrcLoc,
63stack_align: u32,63stack_align: u32,
6464
65/// MIR Instructions65/// MIR Instructions
...@@ -338,7 +338,7 @@ const Self = @This();...@@ -338,7 +338,7 @@ const Self = @This();
338338
339pub fn generate(339pub fn generate(
340 lf: *link.File,340 lf: *link.File,
341 src_loc: Module.SrcLoc,341 src_loc: Module.LazySrcLoc,
342 func_index: InternPool.Index,342 func_index: InternPool.Index,
343 air: Air,343 air: Air,
344 liveness: Liveness,344 liveness: Liveness,
src/arch/arm/Emit.zig+1-1
...@@ -26,7 +26,7 @@ bin_file: *link.File,...@@ -26,7 +26,7 @@ bin_file: *link.File,
26debug_output: DebugInfoOutput,26debug_output: DebugInfoOutput,
27target: *const std.Target,27target: *const std.Target,
28err_msg: ?*ErrorMsg = null,28err_msg: ?*ErrorMsg = null,
29src_loc: Module.SrcLoc,29src_loc: Module.LazySrcLoc,
30code: *std.ArrayList(u8),30code: *std.ArrayList(u8),
3131
32prev_di_line: u32,32prev_di_line: u32,
src/arch/riscv64/CodeGen.zig+2-2
...@@ -59,7 +59,7 @@ args: []MCValue,...@@ -59,7 +59,7 @@ args: []MCValue,
59ret_mcv: InstTracking,59ret_mcv: InstTracking,
60fn_type: Type,60fn_type: Type,
61arg_index: usize,61arg_index: usize,
62src_loc: Zcu.SrcLoc,62src_loc: Zcu.LazySrcLoc,
6363
64/// MIR Instructions64/// MIR Instructions
65mir_instructions: std.MultiArrayList(Mir.Inst) = .{},65mir_instructions: std.MultiArrayList(Mir.Inst) = .{},
...@@ -696,7 +696,7 @@ const CallView = enum(u1) {...@@ -696,7 +696,7 @@ const CallView = enum(u1) {
696696
697pub fn generate(697pub fn generate(
698 bin_file: *link.File,698 bin_file: *link.File,
699 src_loc: Zcu.SrcLoc,699 src_loc: Zcu.LazySrcLoc,
700 func_index: InternPool.Index,700 func_index: InternPool.Index,
701 air: Air,701 air: Air,
702 liveness: Liveness,702 liveness: Liveness,
src/arch/riscv64/Lower.zig+1-1
...@@ -8,7 +8,7 @@ allocator: Allocator,...@@ -8,7 +8,7 @@ allocator: Allocator,
8mir: Mir,8mir: Mir,
9cc: std.builtin.CallingConvention,9cc: std.builtin.CallingConvention,
10err_msg: ?*ErrorMsg = null,10err_msg: ?*ErrorMsg = null,
11src_loc: Zcu.SrcLoc,11src_loc: Zcu.LazySrcLoc,
12result_insts_len: u8 = undefined,12result_insts_len: u8 = undefined,
13result_relocs_len: u8 = undefined,13result_relocs_len: u8 = undefined,
14result_insts: [14result_insts: [
src/arch/sparc64/CodeGen.zig+2-2
...@@ -64,7 +64,7 @@ args: []MCValue,...@@ -64,7 +64,7 @@ args: []MCValue,
64ret_mcv: MCValue,64ret_mcv: MCValue,
65fn_type: Type,65fn_type: Type,
66arg_index: usize,66arg_index: usize,
67src_loc: Module.SrcLoc,67src_loc: Module.LazySrcLoc,
68stack_align: Alignment,68stack_align: Alignment,
6969
70/// MIR Instructions70/// MIR Instructions
...@@ -263,7 +263,7 @@ const BigTomb = struct {...@@ -263,7 +263,7 @@ const BigTomb = struct {
263263
264pub fn generate(264pub fn generate(
265 lf: *link.File,265 lf: *link.File,
266 src_loc: Module.SrcLoc,266 src_loc: Module.LazySrcLoc,
267 func_index: InternPool.Index,267 func_index: InternPool.Index,
268 air: Air,268 air: Air,
269 liveness: Liveness,269 liveness: Liveness,
src/arch/sparc64/Emit.zig+1-1
...@@ -24,7 +24,7 @@ bin_file: *link.File,...@@ -24,7 +24,7 @@ bin_file: *link.File,
24debug_output: DebugInfoOutput,24debug_output: DebugInfoOutput,
25target: *const std.Target,25target: *const std.Target,
26err_msg: ?*ErrorMsg = null,26err_msg: ?*ErrorMsg = null,
27src_loc: Module.SrcLoc,27src_loc: Module.LazySrcLoc,
28code: *std.ArrayList(u8),28code: *std.ArrayList(u8),
2929
30prev_di_line: u32,30prev_di_line: u32,
src/arch/wasm/CodeGen.zig+3-3
...@@ -765,7 +765,7 @@ pub fn deinit(func: *CodeGen) void {...@@ -765,7 +765,7 @@ pub fn deinit(func: *CodeGen) void {
765/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig765/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig
766fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {766fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {
767 const mod = func.bin_file.base.comp.module.?;767 const mod = func.bin_file.base.comp.module.?;
768 const src_loc = func.decl.navSrcLoc(mod).upgrade(mod);768 const src_loc = func.decl.navSrcLoc(mod);
769 func.err_msg = try Zcu.ErrorMsg.create(func.gpa, src_loc, fmt, args);769 func.err_msg = try Zcu.ErrorMsg.create(func.gpa, src_loc, fmt, args);
770 return error.CodegenFail;770 return error.CodegenFail;
771}771}
...@@ -1202,7 +1202,7 @@ fn genFunctype(...@@ -1202,7 +1202,7 @@ fn genFunctype(
12021202
1203pub fn generate(1203pub fn generate(
1204 bin_file: *link.File,1204 bin_file: *link.File,
1205 src_loc: Zcu.SrcLoc,1205 src_loc: Zcu.LazySrcLoc,
1206 func_index: InternPool.Index,1206 func_index: InternPool.Index,
1207 air: Air,1207 air: Air,
1208 liveness: Liveness,1208 liveness: Liveness,
...@@ -3162,7 +3162,7 @@ fn lowerAnonDeclRef(...@@ -3162,7 +3162,7 @@ fn lowerAnonDeclRef(
3162 }3162 }
31633163
3164 const decl_align = mod.intern_pool.indexToKey(anon_decl.orig_ty).ptr_type.flags.alignment;3164 const decl_align = mod.intern_pool.indexToKey(anon_decl.orig_ty).ptr_type.flags.alignment;
3165 const res = try func.bin_file.lowerAnonDecl(decl_val, decl_align, func.decl.navSrcLoc(mod).upgrade(mod));3165 const res = try func.bin_file.lowerAnonDecl(decl_val, decl_align, func.decl.navSrcLoc(mod));
3166 switch (res) {3166 switch (res) {
3167 .ok => {},3167 .ok => {},
3168 .fail => |em| {3168 .fail => |em| {
src/arch/wasm/Emit.zig+1-1
...@@ -257,7 +257,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {...@@ -257,7 +257,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
257 const comp = emit.bin_file.base.comp;257 const comp = emit.bin_file.base.comp;
258 const zcu = comp.module.?;258 const zcu = comp.module.?;
259 const gpa = comp.gpa;259 const gpa = comp.gpa;
260 emit.error_msg = try Zcu.ErrorMsg.create(gpa, zcu.declPtr(emit.decl_index).navSrcLoc(zcu).upgrade(zcu), format, args);260 emit.error_msg = try Zcu.ErrorMsg.create(gpa, zcu.declPtr(emit.decl_index).navSrcLoc(zcu), format, args);
261 return error.EmitFail;261 return error.EmitFail;
262}262}
263263
src/arch/x86_64/CodeGen.zig+3-3
...@@ -74,7 +74,7 @@ va_info: union {...@@ -74,7 +74,7 @@ va_info: union {
74ret_mcv: InstTracking,74ret_mcv: InstTracking,
75fn_type: Type,75fn_type: Type,
76arg_index: u32,76arg_index: u32,
77src_loc: Module.SrcLoc,77src_loc: Module.LazySrcLoc,
7878
79eflags_inst: ?Air.Inst.Index = null,79eflags_inst: ?Air.Inst.Index = null,
8080
...@@ -795,7 +795,7 @@ const Self = @This();...@@ -795,7 +795,7 @@ const Self = @This();
795795
796pub fn generate(796pub fn generate(
797 bin_file: *link.File,797 bin_file: *link.File,
798 src_loc: Module.SrcLoc,798 src_loc: Module.LazySrcLoc,
799 func_index: InternPool.Index,799 func_index: InternPool.Index,
800 air: Air,800 air: Air,
801 liveness: Liveness,801 liveness: Liveness,
...@@ -971,7 +971,7 @@ pub fn generate(...@@ -971,7 +971,7 @@ pub fn generate(
971971
972pub fn generateLazy(972pub fn generateLazy(
973 bin_file: *link.File,973 bin_file: *link.File,
974 src_loc: Module.SrcLoc,974 src_loc: Module.LazySrcLoc,
975 lazy_sym: link.File.LazySymbol,975 lazy_sym: link.File.LazySymbol,
976 code: *std.ArrayList(u8),976 code: *std.ArrayList(u8),
977 debug_output: DebugInfoOutput,977 debug_output: DebugInfoOutput,
src/arch/x86_64/Lower.zig+1-1
...@@ -8,7 +8,7 @@ allocator: Allocator,...@@ -8,7 +8,7 @@ allocator: Allocator,
8mir: Mir,8mir: Mir,
9cc: std.builtin.CallingConvention,9cc: std.builtin.CallingConvention,
10err_msg: ?*ErrorMsg = null,10err_msg: ?*ErrorMsg = null,
11src_loc: Module.SrcLoc,11src_loc: Module.LazySrcLoc,
12result_insts_len: u8 = undefined,12result_insts_len: u8 = undefined,
13result_relocs_len: u8 = undefined,13result_relocs_len: u8 = undefined,
14result_insts: [14result_insts: [
src/codegen.zig+11-11
...@@ -47,7 +47,7 @@ pub const DebugInfoOutput = union(enum) {...@@ -47,7 +47,7 @@ pub const DebugInfoOutput = union(enum) {
4747
48pub fn generateFunction(48pub fn generateFunction(
49 lf: *link.File,49 lf: *link.File,
50 src_loc: Module.SrcLoc,50 src_loc: Module.LazySrcLoc,
51 func_index: InternPool.Index,51 func_index: InternPool.Index,
52 air: Air,52 air: Air,
53 liveness: Liveness,53 liveness: Liveness,
...@@ -79,7 +79,7 @@ pub fn generateFunction(...@@ -79,7 +79,7 @@ pub fn generateFunction(
7979
80pub fn generateLazyFunction(80pub fn generateLazyFunction(
81 lf: *link.File,81 lf: *link.File,
82 src_loc: Module.SrcLoc,82 src_loc: Module.LazySrcLoc,
83 lazy_sym: link.File.LazySymbol,83 lazy_sym: link.File.LazySymbol,
84 code: *std.ArrayList(u8),84 code: *std.ArrayList(u8),
85 debug_output: DebugInfoOutput,85 debug_output: DebugInfoOutput,
...@@ -105,7 +105,7 @@ fn writeFloat(comptime F: type, f: F, target: Target, endian: std.builtin.Endian...@@ -105,7 +105,7 @@ fn writeFloat(comptime F: type, f: F, target: Target, endian: std.builtin.Endian
105105
106pub fn generateLazySymbol(106pub fn generateLazySymbol(
107 bin_file: *link.File,107 bin_file: *link.File,
108 src_loc: Module.SrcLoc,108 src_loc: Module.LazySrcLoc,
109 lazy_sym: link.File.LazySymbol,109 lazy_sym: link.File.LazySymbol,
110 // TODO don't use an "out" parameter like this; put it in the result instead110 // TODO don't use an "out" parameter like this; put it in the result instead
111 alignment: *Alignment,111 alignment: *Alignment,
...@@ -171,7 +171,7 @@ pub fn generateLazySymbol(...@@ -171,7 +171,7 @@ pub fn generateLazySymbol(
171171
172pub fn generateSymbol(172pub fn generateSymbol(
173 bin_file: *link.File,173 bin_file: *link.File,
174 src_loc: Module.SrcLoc,174 src_loc: Module.LazySrcLoc,
175 val: Value,175 val: Value,
176 code: *std.ArrayList(u8),176 code: *std.ArrayList(u8),
177 debug_output: DebugInfoOutput,177 debug_output: DebugInfoOutput,
...@@ -618,7 +618,7 @@ pub fn generateSymbol(...@@ -618,7 +618,7 @@ pub fn generateSymbol(
618618
619fn lowerPtr(619fn lowerPtr(
620 bin_file: *link.File,620 bin_file: *link.File,
621 src_loc: Module.SrcLoc,621 src_loc: Module.LazySrcLoc,
622 ptr_val: InternPool.Index,622 ptr_val: InternPool.Index,
623 code: *std.ArrayList(u8),623 code: *std.ArrayList(u8),
624 debug_output: DebugInfoOutput,624 debug_output: DebugInfoOutput,
...@@ -683,7 +683,7 @@ const RelocInfo = struct {...@@ -683,7 +683,7 @@ const RelocInfo = struct {
683683
684fn lowerAnonDeclRef(684fn lowerAnonDeclRef(
685 lf: *link.File,685 lf: *link.File,
686 src_loc: Module.SrcLoc,686 src_loc: Module.LazySrcLoc,
687 anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl,687 anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl,
688 code: *std.ArrayList(u8),688 code: *std.ArrayList(u8),
689 debug_output: DebugInfoOutput,689 debug_output: DebugInfoOutput,
...@@ -730,7 +730,7 @@ fn lowerAnonDeclRef(...@@ -730,7 +730,7 @@ fn lowerAnonDeclRef(
730730
731fn lowerDeclRef(731fn lowerDeclRef(
732 lf: *link.File,732 lf: *link.File,
733 src_loc: Module.SrcLoc,733 src_loc: Module.LazySrcLoc,
734 decl_index: InternPool.DeclIndex,734 decl_index: InternPool.DeclIndex,
735 code: *std.ArrayList(u8),735 code: *std.ArrayList(u8),
736 debug_output: DebugInfoOutput,736 debug_output: DebugInfoOutput,
...@@ -814,7 +814,7 @@ pub const GenResult = union(enum) {...@@ -814,7 +814,7 @@ pub const GenResult = union(enum) {
814814
815 fn fail(815 fn fail(
816 gpa: Allocator,816 gpa: Allocator,
817 src_loc: Module.SrcLoc,817 src_loc: Module.LazySrcLoc,
818 comptime format: []const u8,818 comptime format: []const u8,
819 args: anytype,819 args: anytype,
820 ) Allocator.Error!GenResult {820 ) Allocator.Error!GenResult {
...@@ -825,7 +825,7 @@ pub const GenResult = union(enum) {...@@ -825,7 +825,7 @@ pub const GenResult = union(enum) {
825825
826fn genDeclRef(826fn genDeclRef(
827 lf: *link.File,827 lf: *link.File,
828 src_loc: Module.SrcLoc,828 src_loc: Module.LazySrcLoc,
829 val: Value,829 val: Value,
830 ptr_decl_index: InternPool.DeclIndex,830 ptr_decl_index: InternPool.DeclIndex,
831) CodeGenError!GenResult {831) CodeGenError!GenResult {
...@@ -931,7 +931,7 @@ fn genDeclRef(...@@ -931,7 +931,7 @@ fn genDeclRef(
931931
932fn genUnnamedConst(932fn genUnnamedConst(
933 lf: *link.File,933 lf: *link.File,
934 src_loc: Module.SrcLoc,934 src_loc: Module.LazySrcLoc,
935 val: Value,935 val: Value,
936 owner_decl_index: InternPool.DeclIndex,936 owner_decl_index: InternPool.DeclIndex,
937) CodeGenError!GenResult {937) CodeGenError!GenResult {
...@@ -970,7 +970,7 @@ fn genUnnamedConst(...@@ -970,7 +970,7 @@ fn genUnnamedConst(
970970
971pub fn genTypedValue(971pub fn genTypedValue(
972 lf: *link.File,972 lf: *link.File,
973 src_loc: Module.SrcLoc,973 src_loc: Module.LazySrcLoc,
974 val: Value,974 val: Value,
975 owner_decl_index: InternPool.DeclIndex,975 owner_decl_index: InternPool.DeclIndex,
976) CodeGenError!GenResult {976) CodeGenError!GenResult {
src/codegen/c.zig+1-1
...@@ -637,7 +637,7 @@ pub const DeclGen = struct {...@@ -637,7 +637,7 @@ pub const DeclGen = struct {
637 const zcu = dg.zcu;637 const zcu = dg.zcu;
638 const decl_index = dg.pass.decl;638 const decl_index = dg.pass.decl;
639 const decl = zcu.declPtr(decl_index);639 const decl = zcu.declPtr(decl_index);
640 const src_loc = decl.navSrcLoc(zcu).upgrade(zcu);640 const src_loc = decl.navSrcLoc(zcu);
641 dg.error_msg = try Zcu.ErrorMsg.create(dg.gpa, src_loc, format, args);641 dg.error_msg = try Zcu.ErrorMsg.create(dg.gpa, src_loc, format, args);
642 return error.AnalysisFail;642 return error.AnalysisFail;
643 }643 }
src/codegen/llvm.zig+1-1
...@@ -4644,7 +4644,7 @@ pub const DeclGen = struct {...@@ -4644,7 +4644,7 @@ pub const DeclGen = struct {
4644 const o = dg.object;4644 const o = dg.object;
4645 const gpa = o.gpa;4645 const gpa = o.gpa;
4646 const mod = o.module;4646 const mod = o.module;
4647 const src_loc = dg.decl.navSrcLoc(mod).upgrade(mod);4647 const src_loc = dg.decl.navSrcLoc(mod);
4648 dg.err_msg = try Module.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);4648 dg.err_msg = try Module.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);
4649 return error.CodegenFail;4649 return error.CodegenFail;
4650 }4650 }
src/codegen/spirv.zig+2-2
...@@ -415,7 +415,7 @@ const DeclGen = struct {...@@ -415,7 +415,7 @@ const DeclGen = struct {
415 pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {415 pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {
416 @setCold(true);416 @setCold(true);
417 const mod = self.module;417 const mod = self.module;
418 const src_loc = self.module.declPtr(self.decl_index).navSrcLoc(mod).upgrade(mod);418 const src_loc = self.module.declPtr(self.decl_index).navSrcLoc(mod);
419 assert(self.error_msg == null);419 assert(self.error_msg == null);
420 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args);420 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args);
421 return error.CodegenFail;421 return error.CodegenFail;
...@@ -6439,7 +6439,7 @@ const DeclGen = struct {...@@ -6439,7 +6439,7 @@ const DeclGen = struct {
6439 // TODO: Translate proper error locations.6439 // TODO: Translate proper error locations.
6440 assert(as.errors.items.len != 0);6440 assert(as.errors.items.len != 0);
6441 assert(self.error_msg == null);6441 assert(self.error_msg == null);
6442 const src_loc = self.module.declPtr(self.decl_index).navSrcLoc(mod).upgrade(mod);6442 const src_loc = self.module.declPtr(self.decl_index).navSrcLoc(mod);
6443 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});6443 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});
6444 const notes = try self.module.gpa.alloc(Module.ErrorMsg, as.errors.items.len);6444 const notes = try self.module.gpa.alloc(Module.ErrorMsg, as.errors.items.len);
64456445
src/link.zig+1-1
...@@ -646,7 +646,7 @@ pub const File = struct {...@@ -646,7 +646,7 @@ pub const File = struct {
646 base: *File,646 base: *File,
647 decl_val: InternPool.Index,647 decl_val: InternPool.Index,
648 decl_align: InternPool.Alignment,648 decl_align: InternPool.Alignment,
649 src_loc: Module.SrcLoc,649 src_loc: Module.LazySrcLoc,
650 ) !LowerResult {650 ) !LowerResult {
651 if (build_options.only_c) @compileError("unreachable");651 if (build_options.only_c) @compileError("unreachable");
652 switch (base.tag) {652 switch (base.tag) {
src/link/Coff.zig+9-16
...@@ -1144,7 +1144,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:...@@ -1144,7 +1144,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air:
11441144
1145 const res = try codegen.generateFunction(1145 const res = try codegen.generateFunction(
1146 &self.base,1146 &self.base,
1147 decl.navSrcLoc(mod).upgrade(mod),1147 decl.navSrcLoc(mod),
1148 func_index,1148 func_index,
1149 air,1149 air,
1150 liveness,1150 liveness,
...@@ -1179,7 +1179,7 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd...@@ -1179,7 +1179,7 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd
1179 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });1179 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
1180 defer gpa.free(sym_name);1180 defer gpa.free(sym_name);
1181 const ty = val.typeOf(mod);1181 const ty = val.typeOf(mod);
1182 const atom_index = switch (try self.lowerConst(sym_name, val, ty.abiAlignment(mod), self.rdata_section_index.?, decl.navSrcLoc(mod).upgrade(mod))) {1182 const atom_index = switch (try self.lowerConst(sym_name, val, ty.abiAlignment(mod), self.rdata_section_index.?, decl.navSrcLoc(mod))) {
1183 .ok => |atom_index| atom_index,1183 .ok => |atom_index| atom_index,
1184 .fail => |em| {1184 .fail => |em| {
1185 decl.analysis = .codegen_failure;1185 decl.analysis = .codegen_failure;
...@@ -1197,7 +1197,7 @@ const LowerConstResult = union(enum) {...@@ -1197,7 +1197,7 @@ const LowerConstResult = union(enum) {
1197 fail: *Module.ErrorMsg,1197 fail: *Module.ErrorMsg,
1198};1198};
11991199
1200fn lowerConst(self: *Coff, name: []const u8, val: Value, required_alignment: InternPool.Alignment, sect_id: u16, src_loc: Module.SrcLoc) !LowerConstResult {1200fn lowerConst(self: *Coff, name: []const u8, val: Value, required_alignment: InternPool.Alignment, sect_id: u16, src_loc: Module.LazySrcLoc) !LowerConstResult {
1201 const gpa = self.base.comp.gpa;1201 const gpa = self.base.comp.gpa;
12021202
1203 var code_buffer = std.ArrayList(u8).init(gpa);1203 var code_buffer = std.ArrayList(u8).init(gpa);
...@@ -1270,7 +1270,7 @@ pub fn updateDecl(...@@ -1270,7 +1270,7 @@ pub fn updateDecl(
1270 defer code_buffer.deinit();1270 defer code_buffer.deinit();
12711271
1272 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;1272 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
1273 const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .none, .{1273 const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod), decl_val, &code_buffer, .none, .{
1274 .parent_atom_index = atom.getSymbolIndex().?,1274 .parent_atom_index = atom.getSymbolIndex().?,
1275 });1275 });
1276 const code = switch (res) {1276 const code = switch (res) {
...@@ -1309,14 +1309,7 @@ fn updateLazySymbolAtom(...@@ -1309,14 +1309,7 @@ fn updateLazySymbolAtom(
1309 const atom = self.getAtomPtr(atom_index);1309 const atom = self.getAtomPtr(atom_index);
1310 const local_sym_index = atom.getSymbolIndex().?;1310 const local_sym_index = atom.getSymbolIndex().?;
13111311
1312 const src = if (sym.ty.srcLocOrNull(mod)) |src|1312 const src = sym.ty.srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded;
1313 src.upgrade(mod)
1314 else
1315 Module.SrcLoc{
1316 .file_scope = undefined,
1317 .base_node = undefined,
1318 .lazy = .unneeded,
1319 };
1320 const res = try codegen.generateLazySymbol(1313 const res = try codegen.generateLazySymbol(
1321 &self.base,1314 &self.base,
1322 src,1315 src,
...@@ -1560,7 +1553,7 @@ pub fn updateExports(...@@ -1560,7 +1553,7 @@ pub fn updateExports(
1560 },1553 },
1561 .value => |value| self.anon_decls.getPtr(value) orelse blk: {1554 .value => |value| self.anon_decls.getPtr(value) orelse blk: {
1562 const first_exp = mod.all_exports.items[export_indices[0]];1555 const first_exp = mod.all_exports.items[export_indices[0]];
1563 const res = try self.lowerAnonDecl(value, .none, first_exp.getSrcLoc(mod));1556 const res = try self.lowerAnonDecl(value, .none, first_exp.src);
1564 switch (res) {1557 switch (res) {
1565 .ok => {},1558 .ok => {},
1566 .fail => |em| {1559 .fail => |em| {
...@@ -1585,7 +1578,7 @@ pub fn updateExports(...@@ -1585,7 +1578,7 @@ pub fn updateExports(
1585 if (!mem.eql(u8, section_name, ".text")) {1578 if (!mem.eql(u8, section_name, ".text")) {
1586 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(1579 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(
1587 gpa,1580 gpa,
1588 exp.getSrcLoc(mod),1581 exp.src,
1589 "Unimplemented: ExportOptions.section",1582 "Unimplemented: ExportOptions.section",
1590 .{},1583 .{},
1591 ));1584 ));
...@@ -1596,7 +1589,7 @@ pub fn updateExports(...@@ -1596,7 +1589,7 @@ pub fn updateExports(
1596 if (exp.opts.linkage == .link_once) {1589 if (exp.opts.linkage == .link_once) {
1597 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(1590 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(
1598 gpa,1591 gpa,
1599 exp.getSrcLoc(mod),1592 exp.src,
1600 "Unimplemented: GlobalLinkage.link_once",1593 "Unimplemented: GlobalLinkage.link_once",
1601 .{},1594 .{},
1602 ));1595 ));
...@@ -1867,7 +1860,7 @@ pub fn lowerAnonDecl(...@@ -1867,7 +1860,7 @@ pub fn lowerAnonDecl(
1867 self: *Coff,1860 self: *Coff,
1868 decl_val: InternPool.Index,1861 decl_val: InternPool.Index,
1869 explicit_alignment: InternPool.Alignment,1862 explicit_alignment: InternPool.Alignment,
1870 src_loc: Module.SrcLoc,1863 src_loc: Module.LazySrcLoc,
1871) !codegen.Result {1864) !codegen.Result {
1872 const gpa = self.base.comp.gpa;1865 const gpa = self.base.comp.gpa;
1873 const mod = self.base.comp.module.?;1866 const mod = self.base.comp.module.?;
src/link/Elf.zig+1-1
...@@ -552,7 +552,7 @@ pub fn lowerAnonDecl(...@@ -552,7 +552,7 @@ pub fn lowerAnonDecl(
552 self: *Elf,552 self: *Elf,
553 decl_val: InternPool.Index,553 decl_val: InternPool.Index,
554 explicit_alignment: InternPool.Alignment,554 explicit_alignment: InternPool.Alignment,
555 src_loc: Module.SrcLoc,555 src_loc: Module.LazySrcLoc,
556) !codegen.Result {556) !codegen.Result {
557 return self.zigObjectPtr().?.lowerAnonDecl(self, decl_val, explicit_alignment, src_loc);557 return self.zigObjectPtr().?.lowerAnonDecl(self, decl_val, explicit_alignment, src_loc);
558}558}
src/link/Elf/ZigObject.zig+11-18
...@@ -686,7 +686,7 @@ pub fn lowerAnonDecl(...@@ -686,7 +686,7 @@ pub fn lowerAnonDecl(
686 elf_file: *Elf,686 elf_file: *Elf,
687 decl_val: InternPool.Index,687 decl_val: InternPool.Index,
688 explicit_alignment: InternPool.Alignment,688 explicit_alignment: InternPool.Alignment,
689 src_loc: Module.SrcLoc,689 src_loc: Module.LazySrcLoc,
690) !codegen.Result {690) !codegen.Result {
691 const gpa = elf_file.base.comp.gpa;691 const gpa = elf_file.base.comp.gpa;
692 const mod = elf_file.base.comp.module.?;692 const mod = elf_file.base.comp.module.?;
...@@ -1074,7 +1074,7 @@ pub fn updateFunc(...@@ -1074,7 +1074,7 @@ pub fn updateFunc(
1074 const res = if (decl_state) |*ds|1074 const res = if (decl_state) |*ds|
1075 try codegen.generateFunction(1075 try codegen.generateFunction(
1076 &elf_file.base,1076 &elf_file.base,
1077 decl.navSrcLoc(mod).upgrade(mod),1077 decl.navSrcLoc(mod),
1078 func_index,1078 func_index,
1079 air,1079 air,
1080 liveness,1080 liveness,
...@@ -1084,7 +1084,7 @@ pub fn updateFunc(...@@ -1084,7 +1084,7 @@ pub fn updateFunc(
1084 else1084 else
1085 try codegen.generateFunction(1085 try codegen.generateFunction(
1086 &elf_file.base,1086 &elf_file.base,
1087 decl.navSrcLoc(mod).upgrade(mod),1087 decl.navSrcLoc(mod),
1088 func_index,1088 func_index,
1089 air,1089 air,
1090 liveness,1090 liveness,
...@@ -1156,13 +1156,13 @@ pub fn updateDecl(...@@ -1156,13 +1156,13 @@ pub fn updateDecl(
1156 // TODO implement .debug_info for global variables1156 // TODO implement .debug_info for global variables
1157 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;1157 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
1158 const res = if (decl_state) |*ds|1158 const res = if (decl_state) |*ds|
1159 try codegen.generateSymbol(&elf_file.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .{1159 try codegen.generateSymbol(&elf_file.base, decl.navSrcLoc(mod), decl_val, &code_buffer, .{
1160 .dwarf = ds,1160 .dwarf = ds,
1161 }, .{1161 }, .{
1162 .parent_atom_index = sym_index,1162 .parent_atom_index = sym_index,
1163 })1163 })
1164 else1164 else
1165 try codegen.generateSymbol(&elf_file.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .none, .{1165 try codegen.generateSymbol(&elf_file.base, decl.navSrcLoc(mod), decl_val, &code_buffer, .none, .{
1166 .parent_atom_index = sym_index,1166 .parent_atom_index = sym_index,
1167 });1167 });
11681168
...@@ -1217,14 +1217,7 @@ fn updateLazySymbol(...@@ -1217,14 +1217,7 @@ fn updateLazySymbol(
1217 break :blk try self.strtab.insert(gpa, name);1217 break :blk try self.strtab.insert(gpa, name);
1218 };1218 };
12191219
1220 const src = if (sym.ty.srcLocOrNull(mod)) |src|1220 const src = sym.ty.srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded;
1221 src.upgrade(mod)
1222 else
1223 Module.SrcLoc{
1224 .file_scope = undefined,
1225 .base_node = undefined,
1226 .lazy = .unneeded,
1227 };
1228 const res = try codegen.generateLazySymbol(1221 const res = try codegen.generateLazySymbol(
1229 &elf_file.base,1222 &elf_file.base,
1230 src,1223 src,
...@@ -1302,7 +1295,7 @@ pub fn lowerUnnamedConst(...@@ -1302,7 +1295,7 @@ pub fn lowerUnnamedConst(
1302 val,1295 val,
1303 ty.abiAlignment(mod),1296 ty.abiAlignment(mod),
1304 elf_file.zig_data_rel_ro_section_index.?,1297 elf_file.zig_data_rel_ro_section_index.?,
1305 decl.navSrcLoc(mod).upgrade(mod),1298 decl.navSrcLoc(mod),
1306 )) {1299 )) {
1307 .ok => |sym_index| sym_index,1300 .ok => |sym_index| sym_index,
1308 .fail => |em| {1301 .fail => |em| {
...@@ -1329,7 +1322,7 @@ fn lowerConst(...@@ -1329,7 +1322,7 @@ fn lowerConst(
1329 val: Value,1322 val: Value,
1330 required_alignment: InternPool.Alignment,1323 required_alignment: InternPool.Alignment,
1331 output_section_index: u32,1324 output_section_index: u32,
1332 src_loc: Module.SrcLoc,1325 src_loc: Module.LazySrcLoc,
1333) !LowerConstResult {1326) !LowerConstResult {
1334 const gpa = elf_file.base.comp.gpa;1327 const gpa = elf_file.base.comp.gpa;
13351328
...@@ -1395,7 +1388,7 @@ pub fn updateExports(...@@ -1395,7 +1388,7 @@ pub fn updateExports(
1395 },1388 },
1396 .value => |value| self.anon_decls.getPtr(value) orelse blk: {1389 .value => |value| self.anon_decls.getPtr(value) orelse blk: {
1397 const first_exp = mod.all_exports.items[export_indices[0]];1390 const first_exp = mod.all_exports.items[export_indices[0]];
1398 const res = try self.lowerAnonDecl(elf_file, value, .none, first_exp.getSrcLoc(mod));1391 const res = try self.lowerAnonDecl(elf_file, value, .none, first_exp.src);
1399 switch (res) {1392 switch (res) {
1400 .ok => {},1393 .ok => {},
1401 .fail => |em| {1394 .fail => |em| {
...@@ -1421,7 +1414,7 @@ pub fn updateExports(...@@ -1421,7 +1414,7 @@ pub fn updateExports(
1421 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);1414 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1422 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Module.ErrorMsg.create(1415 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Module.ErrorMsg.create(
1423 gpa,1416 gpa,
1424 exp.getSrcLoc(mod),1417 exp.src,
1425 "Unimplemented: ExportOptions.section",1418 "Unimplemented: ExportOptions.section",
1426 .{},1419 .{},
1427 ));1420 ));
...@@ -1436,7 +1429,7 @@ pub fn updateExports(...@@ -1436,7 +1429,7 @@ pub fn updateExports(
1436 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);1429 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1437 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Module.ErrorMsg.create(1430 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Module.ErrorMsg.create(
1438 gpa,1431 gpa,
1439 exp.getSrcLoc(mod),1432 exp.src,
1440 "Unimplemented: GlobalLinkage.LinkOnce",1433 "Unimplemented: GlobalLinkage.LinkOnce",
1441 .{},1434 .{},
1442 ));1435 ));
src/link/MachO.zig+1-1
...@@ -3228,7 +3228,7 @@ pub fn lowerAnonDecl(...@@ -3228,7 +3228,7 @@ pub fn lowerAnonDecl(
3228 self: *MachO,3228 self: *MachO,
3229 decl_val: InternPool.Index,3229 decl_val: InternPool.Index,
3230 explicit_alignment: InternPool.Alignment,3230 explicit_alignment: InternPool.Alignment,
3231 src_loc: Module.SrcLoc,3231 src_loc: Module.LazySrcLoc,
3232) !codegen.Result {3232) !codegen.Result {
3233 return self.getZigObject().?.lowerAnonDecl(self, decl_val, explicit_alignment, src_loc);3233 return self.getZigObject().?.lowerAnonDecl(self, decl_val, explicit_alignment, src_loc);
3234}3234}
src/link/MachO/ZigObject.zig+9-16
...@@ -572,7 +572,7 @@ pub fn lowerAnonDecl(...@@ -572,7 +572,7 @@ pub fn lowerAnonDecl(
572 macho_file: *MachO,572 macho_file: *MachO,
573 decl_val: InternPool.Index,573 decl_val: InternPool.Index,
574 explicit_alignment: Atom.Alignment,574 explicit_alignment: Atom.Alignment,
575 src_loc: Module.SrcLoc,575 src_loc: Module.LazySrcLoc,
576) !codegen.Result {576) !codegen.Result {
577 const gpa = macho_file.base.comp.gpa;577 const gpa = macho_file.base.comp.gpa;
578 const mod = macho_file.base.comp.module.?;578 const mod = macho_file.base.comp.module.?;
...@@ -682,7 +682,7 @@ pub fn updateFunc(...@@ -682,7 +682,7 @@ pub fn updateFunc(
682 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;682 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
683 const res = try codegen.generateFunction(683 const res = try codegen.generateFunction(
684 &macho_file.base,684 &macho_file.base,
685 decl.navSrcLoc(mod).upgrade(mod),685 decl.navSrcLoc(mod),
686 func_index,686 func_index,
687 air,687 air,
688 liveness,688 liveness,
...@@ -754,7 +754,7 @@ pub fn updateDecl(...@@ -754,7 +754,7 @@ pub fn updateDecl(
754754
755 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;755 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
756 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;756 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
757 const res = try codegen.generateSymbol(&macho_file.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, dio, .{757 const res = try codegen.generateSymbol(&macho_file.base, decl.navSrcLoc(mod), decl_val, &code_buffer, dio, .{
758 .parent_atom_index = sym_index,758 .parent_atom_index = sym_index,
759 });759 });
760760
...@@ -1100,7 +1100,7 @@ pub fn lowerUnnamedConst(...@@ -1100,7 +1100,7 @@ pub fn lowerUnnamedConst(
1100 val,1100 val,
1101 val.typeOf(mod).abiAlignment(mod),1101 val.typeOf(mod).abiAlignment(mod),
1102 macho_file.zig_const_sect_index.?,1102 macho_file.zig_const_sect_index.?,
1103 decl.navSrcLoc(mod).upgrade(mod),1103 decl.navSrcLoc(mod),
1104 )) {1104 )) {
1105 .ok => |sym_index| sym_index,1105 .ok => |sym_index| sym_index,
1106 .fail => |em| {1106 .fail => |em| {
...@@ -1127,7 +1127,7 @@ fn lowerConst(...@@ -1127,7 +1127,7 @@ fn lowerConst(
1127 val: Value,1127 val: Value,
1128 required_alignment: Atom.Alignment,1128 required_alignment: Atom.Alignment,
1129 output_section_index: u8,1129 output_section_index: u8,
1130 src_loc: Module.SrcLoc,1130 src_loc: Module.LazySrcLoc,
1131) !LowerConstResult {1131) !LowerConstResult {
1132 const gpa = macho_file.base.comp.gpa;1132 const gpa = macho_file.base.comp.gpa;
11331133
...@@ -1196,7 +1196,7 @@ pub fn updateExports(...@@ -1196,7 +1196,7 @@ pub fn updateExports(
1196 },1196 },
1197 .value => |value| self.anon_decls.getPtr(value) orelse blk: {1197 .value => |value| self.anon_decls.getPtr(value) orelse blk: {
1198 const first_exp = mod.all_exports.items[export_indices[0]];1198 const first_exp = mod.all_exports.items[export_indices[0]];
1199 const res = try self.lowerAnonDecl(macho_file, value, .none, first_exp.getSrcLoc(mod));1199 const res = try self.lowerAnonDecl(macho_file, value, .none, first_exp.src);
1200 switch (res) {1200 switch (res) {
1201 .ok => {},1201 .ok => {},
1202 .fail => |em| {1202 .fail => |em| {
...@@ -1221,7 +1221,7 @@ pub fn updateExports(...@@ -1221,7 +1221,7 @@ pub fn updateExports(
1221 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);1221 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
1222 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Module.ErrorMsg.create(1222 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Module.ErrorMsg.create(
1223 gpa,1223 gpa,
1224 exp.getSrcLoc(mod),1224 exp.src,
1225 "Unimplemented: ExportOptions.section",1225 "Unimplemented: ExportOptions.section",
1226 .{},1226 .{},
1227 ));1227 ));
...@@ -1231,7 +1231,7 @@ pub fn updateExports(...@@ -1231,7 +1231,7 @@ pub fn updateExports(
1231 if (exp.opts.linkage == .link_once) {1231 if (exp.opts.linkage == .link_once) {
1232 try mod.failed_exports.putNoClobber(mod.gpa, export_idx, try Module.ErrorMsg.create(1232 try mod.failed_exports.putNoClobber(mod.gpa, export_idx, try Module.ErrorMsg.create(
1233 gpa,1233 gpa,
1234 exp.getSrcLoc(mod),1234 exp.src,
1235 "Unimplemented: GlobalLinkage.link_once",1235 "Unimplemented: GlobalLinkage.link_once",
1236 .{},1236 .{},
1237 ));1237 ));
...@@ -1291,14 +1291,7 @@ fn updateLazySymbol(...@@ -1291,14 +1291,7 @@ fn updateLazySymbol(
1291 break :blk try self.strtab.insert(gpa, name);1291 break :blk try self.strtab.insert(gpa, name);
1292 };1292 };
12931293
1294 const src = if (lazy_sym.ty.srcLocOrNull(mod)) |src|1294 const src = lazy_sym.ty.srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded;
1295 src.upgrade(mod)
1296 else
1297 Module.SrcLoc{
1298 .file_scope = undefined,
1299 .base_node = undefined,
1300 .lazy = .unneeded,
1301 };
1302 const res = try codegen.generateLazySymbol(1295 const res = try codegen.generateLazySymbol(
1303 &macho_file.base,1296 &macho_file.base,
1304 src,1297 src,
src/link/Plan9.zig+6-13
...@@ -439,7 +439,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air:...@@ -439,7 +439,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air:
439439
440 const res = try codegen.generateFunction(440 const res = try codegen.generateFunction(
441 &self.base,441 &self.base,
442 decl.navSrcLoc(mod).upgrade(mod),442 decl.navSrcLoc(mod),
443 func_index,443 func_index,
444 air,444 air,
445 liveness,445 liveness,
...@@ -505,7 +505,7 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn...@@ -505,7 +505,7 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn
505 };505 };
506 self.syms.items[info.sym_index.?] = sym;506 self.syms.items[info.sym_index.?] = sym;
507507
508 const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod).upgrade(mod), val, &code_buffer, .{508 const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod), val, &code_buffer, .{
509 .none = {},509 .none = {},
510 }, .{510 }, .{
511 .parent_atom_index = new_atom_idx,511 .parent_atom_index = new_atom_idx,
...@@ -544,7 +544,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)...@@ -544,7 +544,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)
544 defer code_buffer.deinit();544 defer code_buffer.deinit();
545 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;545 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
546 // TODO we need the symbol index for symbol in the table of locals for the containing atom546 // TODO we need the symbol index for symbol in the table of locals for the containing atom
547 const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .{ .none = {} }, .{547 const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod), decl_val, &code_buffer, .{ .none = {} }, .{
548 .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),548 .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),
549 });549 });
550 const code = switch (res) {550 const code = switch (res) {
...@@ -1027,7 +1027,7 @@ fn addDeclExports(...@@ -1027,7 +1027,7 @@ fn addDeclExports(
1027 {1027 {
1028 try mod.failed_exports.put(mod.gpa, export_idx, try Module.ErrorMsg.create(1028 try mod.failed_exports.put(mod.gpa, export_idx, try Module.ErrorMsg.create(
1029 gpa,1029 gpa,
1030 mod.declPtr(decl_index).navSrcLoc(mod).upgrade(mod),1030 mod.declPtr(decl_index).navSrcLoc(mod),
1031 "plan9 does not support extra sections",1031 "plan9 does not support extra sections",
1032 .{},1032 .{},
1033 ));1033 ));
...@@ -1225,14 +1225,7 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind...@@ -1225,14 +1225,7 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind
1225 self.syms.items[self.getAtomPtr(atom_index).sym_index.?] = symbol;1225 self.syms.items[self.getAtomPtr(atom_index).sym_index.?] = symbol;
12261226
1227 // generate the code1227 // generate the code
1228 const src = if (sym.ty.srcLocOrNull(mod)) |src|1228 const src = sym.ty.srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded;
1229 src.upgrade(mod)
1230 else
1231 Module.SrcLoc{
1232 .file_scope = undefined,
1233 .base_node = undefined,
1234 .lazy = .unneeded,
1235 };
1236 const res = try codegen.generateLazySymbol(1229 const res = try codegen.generateLazySymbol(
1237 &self.base,1230 &self.base,
1238 src,1231 src,
...@@ -1553,7 +1546,7 @@ pub fn lowerAnonDecl(...@@ -1553,7 +1546,7 @@ pub fn lowerAnonDecl(
1553 self: *Plan9,1546 self: *Plan9,
1554 decl_val: InternPool.Index,1547 decl_val: InternPool.Index,
1555 explicit_alignment: InternPool.Alignment,1548 explicit_alignment: InternPool.Alignment,
1556 src_loc: Module.SrcLoc,1549 src_loc: Module.LazySrcLoc,
1557) !codegen.Result {1550) !codegen.Result {
1558 _ = explicit_alignment;1551 _ = explicit_alignment;
1559 // This is basically the same as lowerUnnamedConst.1552 // This is basically the same as lowerUnnamedConst.
src/link/Wasm.zig+1-1
...@@ -1533,7 +1533,7 @@ pub fn lowerAnonDecl(...@@ -1533,7 +1533,7 @@ pub fn lowerAnonDecl(
1533 wasm: *Wasm,1533 wasm: *Wasm,
1534 decl_val: InternPool.Index,1534 decl_val: InternPool.Index,
1535 explicit_alignment: Alignment,1535 explicit_alignment: Alignment,
1536 src_loc: Module.SrcLoc,1536 src_loc: Module.LazySrcLoc,
1537) !codegen.Result {1537) !codegen.Result {
1538 return wasm.zigObjectPtr().?.lowerAnonDecl(wasm, decl_val, explicit_alignment, src_loc);1538 return wasm.zigObjectPtr().?.lowerAnonDecl(wasm, decl_val, explicit_alignment, src_loc);
1539}1539}
src/link/Wasm/ZigObject.zig+7-7
...@@ -269,7 +269,7 @@ pub fn updateDecl(...@@ -269,7 +269,7 @@ pub fn updateDecl(
269269
270 const res = try codegen.generateSymbol(270 const res = try codegen.generateSymbol(
271 &wasm_file.base,271 &wasm_file.base,
272 decl.navSrcLoc(mod).upgrade(mod),272 decl.navSrcLoc(mod),
273 val,273 val,
274 &code_writer,274 &code_writer,
275 .none,275 .none,
...@@ -308,7 +308,7 @@ pub fn updateFunc(...@@ -308,7 +308,7 @@ pub fn updateFunc(
308 defer code_writer.deinit();308 defer code_writer.deinit();
309 const result = try codegen.generateFunction(309 const result = try codegen.generateFunction(
310 &wasm_file.base,310 &wasm_file.base,
311 decl.navSrcLoc(mod).upgrade(mod),311 decl.navSrcLoc(mod),
312 func_index,312 func_index,
313 air,313 air,
314 liveness,314 liveness,
...@@ -439,7 +439,7 @@ pub fn lowerAnonDecl(...@@ -439,7 +439,7 @@ pub fn lowerAnonDecl(
439 wasm_file: *Wasm,439 wasm_file: *Wasm,
440 decl_val: InternPool.Index,440 decl_val: InternPool.Index,
441 explicit_alignment: InternPool.Alignment,441 explicit_alignment: InternPool.Alignment,
442 src_loc: Module.SrcLoc,442 src_loc: Module.LazySrcLoc,
443) !codegen.Result {443) !codegen.Result {
444 const gpa = wasm_file.base.comp.gpa;444 const gpa = wasm_file.base.comp.gpa;
445 const gop = try zig_object.anon_decls.getOrPut(gpa, decl_val);445 const gop = try zig_object.anon_decls.getOrPut(gpa, decl_val);
...@@ -494,7 +494,7 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d...@@ -494,7 +494,7 @@ pub fn lowerUnnamedConst(zig_object: *ZigObject, wasm_file: *Wasm, val: Value, d
494 else494 else
495 decl.navSrcLoc(mod);495 decl.navSrcLoc(mod);
496496
497 switch (try zig_object.lowerConst(wasm_file, name, val, decl_src.upgrade(mod))) {497 switch (try zig_object.lowerConst(wasm_file, name, val, decl_src)) {
498 .ok => |atom_index| {498 .ok => |atom_index| {
499 try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index);499 try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index);
500 return @intFromEnum(wasm_file.getAtom(atom_index).sym_index);500 return @intFromEnum(wasm_file.getAtom(atom_index).sym_index);
...@@ -512,7 +512,7 @@ const LowerConstResult = union(enum) {...@@ -512,7 +512,7 @@ const LowerConstResult = union(enum) {
512 fail: *Module.ErrorMsg,512 fail: *Module.ErrorMsg,
513};513};
514514
515fn lowerConst(zig_object: *ZigObject, wasm_file: *Wasm, name: []const u8, val: Value, src_loc: Module.SrcLoc) !LowerConstResult {515fn lowerConst(zig_object: *ZigObject, wasm_file: *Wasm, name: []const u8, val: Value, src_loc: Module.LazySrcLoc) !LowerConstResult {
516 const gpa = wasm_file.base.comp.gpa;516 const gpa = wasm_file.base.comp.gpa;
517 const mod = wasm_file.base.comp.module.?;517 const mod = wasm_file.base.comp.module.?;
518518
...@@ -882,7 +882,7 @@ pub fn updateExports(...@@ -882,7 +882,7 @@ pub fn updateExports(
882 if (exp.opts.section.toSlice(&mod.intern_pool)) |section| {882 if (exp.opts.section.toSlice(&mod.intern_pool)) |section| {
883 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(883 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(
884 gpa,884 gpa,
885 decl.navSrcLoc(mod).upgrade(mod),885 decl.navSrcLoc(mod),
886 "Unimplemented: ExportOptions.section '{s}'",886 "Unimplemented: ExportOptions.section '{s}'",
887 .{section},887 .{section},
888 ));888 ));
...@@ -915,7 +915,7 @@ pub fn updateExports(...@@ -915,7 +915,7 @@ pub fn updateExports(
915 .link_once => {915 .link_once => {
916 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(916 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(
917 gpa,917 gpa,
918 decl.navSrcLoc(mod).upgrade(mod),918 decl.navSrcLoc(mod),
919 "Unimplemented: LinkOnce",919 "Unimplemented: LinkOnce",
920 .{},920 .{},
921 ));921 ));