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 {
26292629 for (notes[0..num_notes], file.references.items[0..num_notes], 0..) |*note, ref, i| {
26302630 errdefer for (notes[0..i]) |*n| n.deinit(mod.gpa);
26312631 note.* = switch (ref) {
2632 .import => |loc| blk: {
2633 break :blk try Module.ErrorMsg.init(
2634 mod.gpa,
2635 loc,
2636 "imported from module {s}",
2637 .{loc.file_scope.mod.fully_qualified_name},
2638 );
2639 },
2640 .root => |pkg| blk: {
2641 break :blk try Module.ErrorMsg.init(
2642 mod.gpa,
2643 .{ .file_scope = file, .base_node = 0, .lazy = .entire_file },
2644 "root of module {s}",
2645 .{pkg.fully_qualified_name},
2646 );
2647 },
2632 .import => |import| try Module.ErrorMsg.init(
2633 mod.gpa,
2634 .{
2635 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, import.file, .main_struct_inst),
2636 .offset = .{ .token_abs = import.token },
2637 },
2638 "imported from module {s}",
2639 .{import.file.mod.fully_qualified_name},
2640 ),
2641 .root => |pkg| try Module.ErrorMsg.init(
2642 mod.gpa,
2643 .{
2644 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, file, .main_struct_inst),
2645 .offset = .entire_file,
2646 },
2647 "root of module {s}",
2648 .{pkg.fully_qualified_name},
2649 ),
26482650 };
26492651 }
26502652 errdefer for (notes[0..num_notes]) |*n| n.deinit(mod.gpa);
......@@ -2652,7 +2654,10 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26522654 if (omitted > 0) {
26532655 notes[num_notes] = try Module.ErrorMsg.init(
26542656 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 },
26562661 "{} more references omitted",
26572662 .{omitted},
26582663 );
......@@ -2661,7 +2666,10 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26612666
26622667 const err = try Module.ErrorMsg.create(
26632668 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 },
26652673 "file exists in multiple modules",
26662674 .{},
26672675 );
......@@ -3060,7 +3068,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
30603068
30613069 const values = zcu.compile_log_sources.values();
30623070 // 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();
30643072 const err_msg: Module.ErrorMsg = .{
30653073 .src_loc = src_loc,
30663074 .msg = "found compile log statement",
......@@ -3070,7 +3078,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
30703078
30713079 for (values[1..], err_msg.notes) |src_info, *note| {
30723080 note.* = .{
3073 .src_loc = src_info.src().upgrade(zcu),
3081 .src_loc = src_info.src(),
30743082 .msg = "also here",
30753083 };
30763084 }
......@@ -3139,8 +3147,9 @@ pub fn addModuleErrorMsg(
31393147) !void {
31403148 const gpa = eb.gpa;
31413149 const ip = &mod.intern_pool;
3142 const err_source = module_err_msg.src_loc.file_scope.getSource(gpa) catch |err| {
3143 const file_path = try module_err_msg.src_loc.file_scope.fullPath(gpa);
3150 const err_src_loc = module_err_msg.src_loc.upgrade(mod);
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);
31443153 defer gpa.free(file_path);
31453154 try eb.addRootErrorMessage(.{
31463155 .msg = try eb.printString("unable to load '{s}': {s}", .{
......@@ -3149,9 +3158,9 @@ pub fn addModuleErrorMsg(
31493158 });
31503159 return;
31513160 };
3152 const err_span = try module_err_msg.src_loc.span(gpa);
3161 const err_span = try err_src_loc.span(gpa);
31533162 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);
31553164 defer gpa.free(file_path);
31563165
31573166 var ref_traces: std.ArrayListUnmanaged(ErrorBundle.ReferenceTrace) = .{};
......@@ -3208,7 +3217,7 @@ pub fn addModuleErrorMsg(
32083217 .span_end = err_span.end,
32093218 .line = @intCast(err_loc.line),
32103219 .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)
32123221 0
32133222 else
32143223 try eb.addString(err_loc.source_line),
......@@ -3225,10 +3234,11 @@ pub fn addModuleErrorMsg(
32253234 defer notes.deinit(gpa);
32263235
32273236 for (module_err_msg.notes) |module_note| {
3228 const source = try module_note.src_loc.file_scope.getSource(gpa);
3229 const span = try module_note.src_loc.span(gpa);
3237 const note_src_loc = module_note.src_loc.upgrade(mod);
3238 const source = try note_src_loc.file_scope.getSource(gpa);
3239 const span = try note_src_loc.span(gpa);
32303240 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);
32323242 defer gpa.free(note_file_path);
32333243
32343244 const gop = try notes.getOrPutContext(gpa, .{
......@@ -3522,7 +3532,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
35223532 InternPool.AnalUnit.wrap(.{ .decl = decl_index }),
35233533 try Module.ErrorMsg.create(
35243534 gpa,
3525 decl.navSrcLoc(module).upgrade(module),
3535 decl.navSrcLoc(module),
35263536 "unable to update line number: {s}",
35273537 .{@errorName(err)},
35283538 ),
......@@ -4023,9 +4033,8 @@ fn workerAstGenFile(
40234033 const res = mod.importFile(file, import_path) catch continue;
40244034 if (!res.is_pkg) {
40254035 res.file.addReference(mod.*, .{ .import = .{
4026 .file_scope = file,
4027 .base_node = 0,
4028 .lazy = .{ .token_abs = item.data.token },
4036 .file = file,
4037 .token = item.data.token,
40294038 } }) catch continue;
40304039 }
40314040 break :blk res;
......@@ -4398,20 +4407,14 @@ fn reportRetryableAstGenError(
43984407
43994408 file.status = .retryable_failure;
44004409
4401 const src_loc: Module.SrcLoc = switch (src) {
4410 const src_loc: Module.LazySrcLoc = switch (src) {
44024411 .root => .{
4403 .file_scope = file,
4404 .base_node = 0,
4405 .lazy = .entire_file,
4412 .base_node_inst = try mod.intern_pool.trackZir(gpa, file, .main_struct_inst),
4413 .offset = .entire_file,
44064414 },
4407 .import => |info| blk: {
4408 const importing_file = info.importing_file;
4409
4410 break :blk .{
4411 .file_scope = importing_file,
4412 .base_node = 0,
4413 .lazy = .{ .token_abs = info.import_tok },
4414 };
4415 .import => |info| .{
4416 .base_node_inst = try mod.intern_pool.trackZir(gpa, info.importing_file, .main_struct_inst),
4417 .offset = .{ .token_abs = info.import_tok },
44154418 },
44164419 };
44174420
src/Sema.zig+4-6
......@@ -2425,8 +2425,7 @@ pub fn errNote(
24252425 comptime format: []const u8,
24262426 args: anytype,
24272427) error{OutOfMemory}!void {
2428 const zcu = sema.mod;
2429 return zcu.errNoteNonLazy(src.upgrade(zcu), parent, format, args);
2428 return sema.mod.errNote(src, parent, format, args);
24302429}
24312430
24322431fn addFieldErrNote(
......@@ -2454,7 +2453,7 @@ pub fn errMsg(
24542453 args: anytype,
24552454) Allocator.Error!*Module.ErrorMsg {
24562455 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);
24582457}
24592458
24602459pub fn fail(
......@@ -2542,7 +2541,6 @@ fn reparentOwnedErrorMsg(
25422541 args: anytype,
25432542) !void {
25442543 const mod = sema.mod;
2545 const resolved_src = src.upgrade(mod);
25462544 const msg_str = try std.fmt.allocPrint(mod.gpa, format, args);
25472545
25482546 const orig_notes = msg.notes.len;
......@@ -2553,7 +2551,7 @@ fn reparentOwnedErrorMsg(
25532551 .msg = msg.msg,
25542552 };
25552553
2556 msg.src_loc = resolved_src;
2554 msg.src_loc = src;
25572555 msg.msg = msg_str;
25582556}
25592557
......@@ -13883,7 +13881,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1388313881 return sema.fail(block, operand_src, "file path name cannot be empty", .{});
1388413882 }
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) {
1388713885 error.ImportOutsideModulePath => {
1388813886 return sema.fail(block, operand_src, "embed of file outside package path: '{s}'", .{name});
1388913887 },
src/Zcu.zig+30-48
......@@ -289,10 +289,6 @@ pub const Export = struct {
289289 section: InternPool.OptionalNullTerminatedString = .none,
290290 visibility: std.builtin.SymbolVisibility = .default,
291291 };
292
293 pub fn getSrcLoc(exp: Export, mod: *Module) SrcLoc {
294 return exp.src.upgrade(mod);
295 }
296292};
297293
298294pub const Reference = struct {
......@@ -746,7 +742,10 @@ pub const File = struct {
746742 /// A single reference to a file.
747743 pub const Reference = union(enum) {
748744 /// 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 },
750749 /// The file is the root of a module.
751750 root: *Package.Module,
752751 };
......@@ -900,7 +899,7 @@ pub const File = struct {
900899 }
901900
902901 /// 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 {
904903 // Don't add the same module root twice. Note that since we always add module roots at the
905904 // front of the references array (see below), this loop is actually O(1) on valid code.
906905 if (ref == .root) {
......@@ -917,17 +916,17 @@ pub const File = struct {
917916 // to make multi-module errors more helpful (since "root-of" notes are generally more
918917 // informative than "imported-from" notes). This path is hit very rarely, so the speed
919918 // 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
922921 // 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),
924923 }
925924
926 const pkg = switch (ref) {
927 .import => |loc| loc.file_scope.mod,
928 .root => |pkg| pkg,
925 const mod = switch (ref) {
926 .import => |import| import.file.mod,
927 .root => |mod| mod,
929928 };
930 if (pkg != file.mod) file.multi_pkg = true;
929 if (mod != file.mod) file.multi_pkg = true;
931930 }
932931
933932 /// Mark this file and every file referenced by it as multi_pkg and report an
......@@ -967,30 +966,25 @@ pub const EmbedFile = struct {
967966 owner: *Package.Module,
968967 stat: Cache.File.Stat,
969968 val: InternPool.Index,
970 src_loc: SrcLoc,
969 src_loc: LazySrcLoc,
971970};
972971
973972/// This struct holds data necessary to construct API-facing `AllErrors.Message`.
974973/// Its memory is managed with the general purpose allocator so that they
975974/// can be created and destroyed in response to incremental updates.
976975pub const ErrorMsg = struct {
977 src_loc: SrcLoc,
976 src_loc: LazySrcLoc,
978977 msg: []const u8,
979978 notes: []ErrorMsg = &.{},
980979 reference_trace_root: AnalUnit.Optional = .none,
981980
982 pub const Trace = struct {
983 decl: InternPool.NullTerminatedString,
984 src_loc: SrcLoc,
985 };
986
987981 pub fn create(
988982 gpa: Allocator,
989 src_loc: SrcLoc,
983 src_loc: LazySrcLoc,
990984 comptime format: []const u8,
991985 args: anytype,
992986 ) !*ErrorMsg {
993 assert(src_loc.lazy != .unneeded);
987 assert(src_loc.offset != .unneeded);
994988 const err_msg = try gpa.create(ErrorMsg);
995989 errdefer gpa.destroy(err_msg);
996990 err_msg.* = try ErrorMsg.init(gpa, src_loc, format, args);
......@@ -1006,7 +1000,7 @@ pub const ErrorMsg = struct {
10061000
10071001 pub fn init(
10081002 gpa: Allocator,
1009 src_loc: SrcLoc,
1003 src_loc: LazySrcLoc,
10101004 comptime format: []const u8,
10111005 args: anytype,
10121006 ) !ErrorMsg {
......@@ -1994,15 +1988,12 @@ pub const LazySrcLoc = struct {
19941988 entire_file,
19951989 /// The source location points to a byte offset within a source file,
19961990 /// offset from 0. The source file is determined contextually.
1997 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
19981991 byte_abs: u32,
19991992 /// The source location points to a token within a source file,
20001993 /// offset from 0. The source file is determined contextually.
2001 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
20021994 token_abs: u32,
20031995 /// The source location points to an AST node within a source file,
20041996 /// offset from 0. The source file is determined contextually.
2005 /// Inside a `SrcLoc`, the `file_scope` union field will be active.
20061997 node_abs: u32,
20071998 /// The source location points to a byte offset within a source file,
20081999 /// offset from the byte offset of the base node within the file.
......@@ -2373,8 +2364,7 @@ pub const LazySrcLoc = struct {
23732364 }
23742365
23752366 /// 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.
2377 /// Probably the type should be removed entirely and this resolution performed on-the-fly when needed.
2367 /// The resulting `SrcLoc` should only be used ephemerally, as it is not correct across incremental updates.
23782368 pub fn upgrade(lazy: LazySrcLoc, zcu: *Zcu) SrcLoc {
23792369 const file, const base_node = resolveBaseNode(lazy.base_node_inst, zcu);
23802370 return .{
......@@ -3478,7 +3468,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
34783468 try mod.retryable_failures.append(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }));
34793469 mod.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try ErrorMsg.create(
34803470 mod.gpa,
3481 decl.navSrcLoc(mod).upgrade(mod),
3471 decl.navSrcLoc(mod),
34823472 "unable to analyze: {s}",
34833473 .{@errorName(e)},
34843474 ));
......@@ -3655,7 +3645,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
36553645 AnalUnit.wrap(.{ .decl = decl_index }),
36563646 try Module.ErrorMsg.create(
36573647 gpa,
3658 decl.navSrcLoc(zcu).upgrade(zcu),
3648 decl.navSrcLoc(zcu),
36593649 "invalid liveness: {s}",
36603650 .{@errorName(err)},
36613651 ),
......@@ -3679,7 +3669,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
36793669 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
36803670 zcu.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try Module.ErrorMsg.create(
36813671 gpa,
3682 decl.navSrcLoc(zcu).upgrade(zcu),
3672 decl.navSrcLoc(zcu),
36833673 "unable to codegen: {s}",
36843674 .{@errorName(err)},
36853675 ));
......@@ -4480,7 +4470,7 @@ pub fn embedFile(
44804470 mod: *Module,
44814471 cur_file: *File,
44824472 import_string: []const u8,
4483 src_loc: SrcLoc,
4473 src_loc: LazySrcLoc,
44844474) !InternPool.Index {
44854475 const gpa = mod.gpa;
44864476
......@@ -4555,7 +4545,7 @@ fn newEmbedFile(
45554545 sub_file_path: []const u8,
45564546 resolved_path: []const u8,
45574547 result: **EmbedFile,
4558 src_loc: SrcLoc,
4548 src_loc: LazySrcLoc,
45594549) !InternPool.Index {
45604550 const gpa = mod.gpa;
45614551 const ip = &mod.intern_pool;
......@@ -5320,17 +5310,13 @@ pub fn initNewAnonDecl(
53205310 new_decl.analysis = .complete;
53215311}
53225312
5323pub fn errNoteNonLazy(
5313pub fn errNote(
53245314 mod: *Module,
5325 src_loc: SrcLoc,
5315 src_loc: LazySrcLoc,
53265316 parent: *ErrorMsg,
53275317 comptime format: []const u8,
53285318 args: anytype,
53295319) error{OutOfMemory}!void {
5330 if (src_loc.lazy == .unneeded) {
5331 assert(parent.src_loc.lazy == .unneeded);
5332 return;
5333 }
53345320 const msg = try std.fmt.allocPrint(mod.gpa, format, args);
53355321 errdefer mod.gpa.free(msg);
53365322
......@@ -5458,14 +5444,12 @@ fn processExportsInner(
54585444 if (gop.found_existing) {
54595445 new_export.status = .failed_retryable;
54605446 try zcu.failed_exports.ensureUnusedCapacity(gpa, 1);
5461 const src_loc = new_export.getSrcLoc(zcu);
5462 const msg = try ErrorMsg.create(gpa, src_loc, "exported symbol collision: {}", .{
5447 const msg = try ErrorMsg.create(gpa, new_export.src, "exported symbol collision: {}", .{
54635448 new_export.opts.name.fmt(&zcu.intern_pool),
54645449 });
54655450 errdefer msg.destroy(gpa);
54665451 const other_export = zcu.all_exports.items[gop.value_ptr.*];
5467 const other_src_loc = other_export.getSrcLoc(zcu);
5468 try zcu.errNoteNonLazy(other_src_loc, msg, "other symbol here", .{});
5452 try zcu.errNote(other_export.src, msg, "other symbol here", .{});
54695453 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, msg);
54705454 new_export.status = .failed;
54715455 } else {
......@@ -5493,8 +5477,7 @@ fn handleUpdateExports(
54935477 const new_export = &zcu.all_exports.items[export_idx];
54945478 new_export.status = .failed_retryable;
54955479 try zcu.failed_exports.ensureUnusedCapacity(gpa, 1);
5496 const src_loc = new_export.getSrcLoc(zcu);
5497 const msg = try ErrorMsg.create(gpa, src_loc, "unable to export: {s}", .{
5480 const msg = try ErrorMsg.create(gpa, new_export.src, "unable to export: {s}", .{
54985481 @errorName(err),
54995482 });
55005483 zcu.failed_exports.putAssumeCapacityNoClobber(export_idx, msg);
......@@ -5658,7 +5641,7 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {
56585641 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
56595642 zcu.failed_analysis.putAssumeCapacityNoClobber(AnalUnit.wrap(.{ .decl = decl_index }), try ErrorMsg.create(
56605643 gpa,
5661 decl.navSrcLoc(zcu).upgrade(zcu),
5644 decl.navSrcLoc(zcu),
56625645 "unable to codegen: {s}",
56635646 .{@errorName(err)},
56645647 ));
......@@ -5685,9 +5668,8 @@ fn reportRetryableFileError(
56855668 const err_msg = try ErrorMsg.create(
56865669 mod.gpa,
56875670 .{
5688 .file_scope = file,
5689 .base_node = 0,
5690 .lazy = .entire_file,
5671 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, file, .main_struct_inst),
5672 .offset = .entire_file,
56915673 },
56925674 format,
56935675 args,
src/arch/aarch64/CodeGen.zig+2-2
......@@ -59,7 +59,7 @@ args: []MCValue,
5959ret_mcv: MCValue,
6060fn_type: Type,
6161arg_index: u32,
62src_loc: Module.SrcLoc,
62src_loc: Module.LazySrcLoc,
6363stack_align: u32,
6464
6565/// MIR Instructions
......@@ -331,7 +331,7 @@ const Self = @This();
331331
332332pub fn generate(
333333 lf: *link.File,
334 src_loc: Module.SrcLoc,
334 src_loc: Module.LazySrcLoc,
335335 func_index: InternPool.Index,
336336 air: Air,
337337 liveness: Liveness,
src/arch/aarch64/Emit.zig+1-1
......@@ -22,7 +22,7 @@ bin_file: *link.File,
2222debug_output: DebugInfoOutput,
2323target: *const std.Target,
2424err_msg: ?*ErrorMsg = null,
25src_loc: Module.SrcLoc,
25src_loc: Module.LazySrcLoc,
2626code: *std.ArrayList(u8),
2727
2828prev_di_line: u32,
src/arch/arm/CodeGen.zig+2-2
......@@ -59,7 +59,7 @@ args: []MCValue,
5959ret_mcv: MCValue,
6060fn_type: Type,
6161arg_index: u32,
62src_loc: Module.SrcLoc,
62src_loc: Module.LazySrcLoc,
6363stack_align: u32,
6464
6565/// MIR Instructions
......@@ -338,7 +338,7 @@ const Self = @This();
338338
339339pub fn generate(
340340 lf: *link.File,
341 src_loc: Module.SrcLoc,
341 src_loc: Module.LazySrcLoc,
342342 func_index: InternPool.Index,
343343 air: Air,
344344 liveness: Liveness,
src/arch/arm/Emit.zig+1-1
......@@ -26,7 +26,7 @@ bin_file: *link.File,
2626debug_output: DebugInfoOutput,
2727target: *const std.Target,
2828err_msg: ?*ErrorMsg = null,
29src_loc: Module.SrcLoc,
29src_loc: Module.LazySrcLoc,
3030code: *std.ArrayList(u8),
3131
3232prev_di_line: u32,
src/arch/riscv64/CodeGen.zig+2-2
......@@ -59,7 +59,7 @@ args: []MCValue,
5959ret_mcv: InstTracking,
6060fn_type: Type,
6161arg_index: usize,
62src_loc: Zcu.SrcLoc,
62src_loc: Zcu.LazySrcLoc,
6363
6464/// MIR Instructions
6565mir_instructions: std.MultiArrayList(Mir.Inst) = .{},
......@@ -696,7 +696,7 @@ const CallView = enum(u1) {
696696
697697pub fn generate(
698698 bin_file: *link.File,
699 src_loc: Zcu.SrcLoc,
699 src_loc: Zcu.LazySrcLoc,
700700 func_index: InternPool.Index,
701701 air: Air,
702702 liveness: Liveness,
src/arch/riscv64/Lower.zig+1-1
......@@ -8,7 +8,7 @@ allocator: Allocator,
88mir: Mir,
99cc: std.builtin.CallingConvention,
1010err_msg: ?*ErrorMsg = null,
11src_loc: Zcu.SrcLoc,
11src_loc: Zcu.LazySrcLoc,
1212result_insts_len: u8 = undefined,
1313result_relocs_len: u8 = undefined,
1414result_insts: [
src/arch/sparc64/CodeGen.zig+2-2
......@@ -64,7 +64,7 @@ args: []MCValue,
6464ret_mcv: MCValue,
6565fn_type: Type,
6666arg_index: usize,
67src_loc: Module.SrcLoc,
67src_loc: Module.LazySrcLoc,
6868stack_align: Alignment,
6969
7070/// MIR Instructions
......@@ -263,7 +263,7 @@ const BigTomb = struct {
263263
264264pub fn generate(
265265 lf: *link.File,
266 src_loc: Module.SrcLoc,
266 src_loc: Module.LazySrcLoc,
267267 func_index: InternPool.Index,
268268 air: Air,
269269 liveness: Liveness,
src/arch/sparc64/Emit.zig+1-1
......@@ -24,7 +24,7 @@ bin_file: *link.File,
2424debug_output: DebugInfoOutput,
2525target: *const std.Target,
2626err_msg: ?*ErrorMsg = null,
27src_loc: Module.SrcLoc,
27src_loc: Module.LazySrcLoc,
2828code: *std.ArrayList(u8),
2929
3030prev_di_line: u32,
src/arch/wasm/CodeGen.zig+3-3
......@@ -765,7 +765,7 @@ pub fn deinit(func: *CodeGen) void {
765765/// Sets `err_msg` on `CodeGen` and returns `error.CodegenFail` which is caught in link/Wasm.zig
766766fn fail(func: *CodeGen, comptime fmt: []const u8, args: anytype) InnerError {
767767 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);
769769 func.err_msg = try Zcu.ErrorMsg.create(func.gpa, src_loc, fmt, args);
770770 return error.CodegenFail;
771771}
......@@ -1202,7 +1202,7 @@ fn genFunctype(
12021202
12031203pub fn generate(
12041204 bin_file: *link.File,
1205 src_loc: Zcu.SrcLoc,
1205 src_loc: Zcu.LazySrcLoc,
12061206 func_index: InternPool.Index,
12071207 air: Air,
12081208 liveness: Liveness,
......@@ -3162,7 +3162,7 @@ fn lowerAnonDeclRef(
31623162 }
31633163
31643164 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));
31663166 switch (res) {
31673167 .ok => {},
31683168 .fail => |em| {
src/arch/wasm/Emit.zig+1-1
......@@ -257,7 +257,7 @@ fn fail(emit: *Emit, comptime format: []const u8, args: anytype) InnerError {
257257 const comp = emit.bin_file.base.comp;
258258 const zcu = comp.module.?;
259259 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);
261261 return error.EmitFail;
262262}
263263
src/arch/x86_64/CodeGen.zig+3-3
......@@ -74,7 +74,7 @@ va_info: union {
7474ret_mcv: InstTracking,
7575fn_type: Type,
7676arg_index: u32,
77src_loc: Module.SrcLoc,
77src_loc: Module.LazySrcLoc,
7878
7979eflags_inst: ?Air.Inst.Index = null,
8080
......@@ -795,7 +795,7 @@ const Self = @This();
795795
796796pub fn generate(
797797 bin_file: *link.File,
798 src_loc: Module.SrcLoc,
798 src_loc: Module.LazySrcLoc,
799799 func_index: InternPool.Index,
800800 air: Air,
801801 liveness: Liveness,
......@@ -971,7 +971,7 @@ pub fn generate(
971971
972972pub fn generateLazy(
973973 bin_file: *link.File,
974 src_loc: Module.SrcLoc,
974 src_loc: Module.LazySrcLoc,
975975 lazy_sym: link.File.LazySymbol,
976976 code: *std.ArrayList(u8),
977977 debug_output: DebugInfoOutput,
src/arch/x86_64/Lower.zig+1-1
......@@ -8,7 +8,7 @@ allocator: Allocator,
88mir: Mir,
99cc: std.builtin.CallingConvention,
1010err_msg: ?*ErrorMsg = null,
11src_loc: Module.SrcLoc,
11src_loc: Module.LazySrcLoc,
1212result_insts_len: u8 = undefined,
1313result_relocs_len: u8 = undefined,
1414result_insts: [
src/codegen.zig+11-11
......@@ -47,7 +47,7 @@ pub const DebugInfoOutput = union(enum) {
4747
4848pub fn generateFunction(
4949 lf: *link.File,
50 src_loc: Module.SrcLoc,
50 src_loc: Module.LazySrcLoc,
5151 func_index: InternPool.Index,
5252 air: Air,
5353 liveness: Liveness,
......@@ -79,7 +79,7 @@ pub fn generateFunction(
7979
8080pub fn generateLazyFunction(
8181 lf: *link.File,
82 src_loc: Module.SrcLoc,
82 src_loc: Module.LazySrcLoc,
8383 lazy_sym: link.File.LazySymbol,
8484 code: *std.ArrayList(u8),
8585 debug_output: DebugInfoOutput,
......@@ -105,7 +105,7 @@ fn writeFloat(comptime F: type, f: F, target: Target, endian: std.builtin.Endian
105105
106106pub fn generateLazySymbol(
107107 bin_file: *link.File,
108 src_loc: Module.SrcLoc,
108 src_loc: Module.LazySrcLoc,
109109 lazy_sym: link.File.LazySymbol,
110110 // TODO don't use an "out" parameter like this; put it in the result instead
111111 alignment: *Alignment,
......@@ -171,7 +171,7 @@ pub fn generateLazySymbol(
171171
172172pub fn generateSymbol(
173173 bin_file: *link.File,
174 src_loc: Module.SrcLoc,
174 src_loc: Module.LazySrcLoc,
175175 val: Value,
176176 code: *std.ArrayList(u8),
177177 debug_output: DebugInfoOutput,
......@@ -618,7 +618,7 @@ pub fn generateSymbol(
618618
619619fn lowerPtr(
620620 bin_file: *link.File,
621 src_loc: Module.SrcLoc,
621 src_loc: Module.LazySrcLoc,
622622 ptr_val: InternPool.Index,
623623 code: *std.ArrayList(u8),
624624 debug_output: DebugInfoOutput,
......@@ -683,7 +683,7 @@ const RelocInfo = struct {
683683
684684fn lowerAnonDeclRef(
685685 lf: *link.File,
686 src_loc: Module.SrcLoc,
686 src_loc: Module.LazySrcLoc,
687687 anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl,
688688 code: *std.ArrayList(u8),
689689 debug_output: DebugInfoOutput,
......@@ -730,7 +730,7 @@ fn lowerAnonDeclRef(
730730
731731fn lowerDeclRef(
732732 lf: *link.File,
733 src_loc: Module.SrcLoc,
733 src_loc: Module.LazySrcLoc,
734734 decl_index: InternPool.DeclIndex,
735735 code: *std.ArrayList(u8),
736736 debug_output: DebugInfoOutput,
......@@ -814,7 +814,7 @@ pub const GenResult = union(enum) {
814814
815815 fn fail(
816816 gpa: Allocator,
817 src_loc: Module.SrcLoc,
817 src_loc: Module.LazySrcLoc,
818818 comptime format: []const u8,
819819 args: anytype,
820820 ) Allocator.Error!GenResult {
......@@ -825,7 +825,7 @@ pub const GenResult = union(enum) {
825825
826826fn genDeclRef(
827827 lf: *link.File,
828 src_loc: Module.SrcLoc,
828 src_loc: Module.LazySrcLoc,
829829 val: Value,
830830 ptr_decl_index: InternPool.DeclIndex,
831831) CodeGenError!GenResult {
......@@ -931,7 +931,7 @@ fn genDeclRef(
931931
932932fn genUnnamedConst(
933933 lf: *link.File,
934 src_loc: Module.SrcLoc,
934 src_loc: Module.LazySrcLoc,
935935 val: Value,
936936 owner_decl_index: InternPool.DeclIndex,
937937) CodeGenError!GenResult {
......@@ -970,7 +970,7 @@ fn genUnnamedConst(
970970
971971pub fn genTypedValue(
972972 lf: *link.File,
973 src_loc: Module.SrcLoc,
973 src_loc: Module.LazySrcLoc,
974974 val: Value,
975975 owner_decl_index: InternPool.DeclIndex,
976976) CodeGenError!GenResult {
src/codegen/c.zig+1-1
......@@ -637,7 +637,7 @@ pub const DeclGen = struct {
637637 const zcu = dg.zcu;
638638 const decl_index = dg.pass.decl;
639639 const decl = zcu.declPtr(decl_index);
640 const src_loc = decl.navSrcLoc(zcu).upgrade(zcu);
640 const src_loc = decl.navSrcLoc(zcu);
641641 dg.error_msg = try Zcu.ErrorMsg.create(dg.gpa, src_loc, format, args);
642642 return error.AnalysisFail;
643643 }
src/codegen/llvm.zig+1-1
......@@ -4644,7 +4644,7 @@ pub const DeclGen = struct {
46444644 const o = dg.object;
46454645 const gpa = o.gpa;
46464646 const mod = o.module;
4647 const src_loc = dg.decl.navSrcLoc(mod).upgrade(mod);
4647 const src_loc = dg.decl.navSrcLoc(mod);
46484648 dg.err_msg = try Module.ErrorMsg.create(gpa, src_loc, "TODO (LLVM): " ++ format, args);
46494649 return error.CodegenFail;
46504650 }
src/codegen/spirv.zig+2-2
......@@ -415,7 +415,7 @@ const DeclGen = struct {
415415 pub fn fail(self: *DeclGen, comptime format: []const u8, args: anytype) Error {
416416 @setCold(true);
417417 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);
419419 assert(self.error_msg == null);
420420 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, format, args);
421421 return error.CodegenFail;
......@@ -6439,7 +6439,7 @@ const DeclGen = struct {
64396439 // TODO: Translate proper error locations.
64406440 assert(as.errors.items.len != 0);
64416441 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);
64436443 self.error_msg = try Module.ErrorMsg.create(self.module.gpa, src_loc, "failed to assemble SPIR-V inline assembly", .{});
64446444 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 {
646646 base: *File,
647647 decl_val: InternPool.Index,
648648 decl_align: InternPool.Alignment,
649 src_loc: Module.SrcLoc,
649 src_loc: Module.LazySrcLoc,
650650 ) !LowerResult {
651651 if (build_options.only_c) @compileError("unreachable");
652652 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:
11441144
11451145 const res = try codegen.generateFunction(
11461146 &self.base,
1147 decl.navSrcLoc(mod).upgrade(mod),
1147 decl.navSrcLoc(mod),
11481148 func_index,
11491149 air,
11501150 liveness,
......@@ -1179,7 +1179,7 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd
11791179 const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index });
11801180 defer gpa.free(sym_name);
11811181 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))) {
11831183 .ok => |atom_index| atom_index,
11841184 .fail => |em| {
11851185 decl.analysis = .codegen_failure;
......@@ -1197,7 +1197,7 @@ const LowerConstResult = union(enum) {
11971197 fail: *Module.ErrorMsg,
11981198};
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 {
12011201 const gpa = self.base.comp.gpa;
12021202
12031203 var code_buffer = std.ArrayList(u8).init(gpa);
......@@ -1270,7 +1270,7 @@ pub fn updateDecl(
12701270 defer code_buffer.deinit();
12711271
12721272 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, .{
12741274 .parent_atom_index = atom.getSymbolIndex().?,
12751275 });
12761276 const code = switch (res) {
......@@ -1309,14 +1309,7 @@ fn updateLazySymbolAtom(
13091309 const atom = self.getAtomPtr(atom_index);
13101310 const local_sym_index = atom.getSymbolIndex().?;
13111311
1312 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1313 src.upgrade(mod)
1314 else
1315 Module.SrcLoc{
1316 .file_scope = undefined,
1317 .base_node = undefined,
1318 .lazy = .unneeded,
1319 };
1312 const src = sym.ty.srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded;
13201313 const res = try codegen.generateLazySymbol(
13211314 &self.base,
13221315 src,
......@@ -1560,7 +1553,7 @@ pub fn updateExports(
15601553 },
15611554 .value => |value| self.anon_decls.getPtr(value) orelse blk: {
15621555 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);
15641557 switch (res) {
15651558 .ok => {},
15661559 .fail => |em| {
......@@ -1585,7 +1578,7 @@ pub fn updateExports(
15851578 if (!mem.eql(u8, section_name, ".text")) {
15861579 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(
15871580 gpa,
1588 exp.getSrcLoc(mod),
1581 exp.src,
15891582 "Unimplemented: ExportOptions.section",
15901583 .{},
15911584 ));
......@@ -1596,7 +1589,7 @@ pub fn updateExports(
15961589 if (exp.opts.linkage == .link_once) {
15971590 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(
15981591 gpa,
1599 exp.getSrcLoc(mod),
1592 exp.src,
16001593 "Unimplemented: GlobalLinkage.link_once",
16011594 .{},
16021595 ));
......@@ -1867,7 +1860,7 @@ pub fn lowerAnonDecl(
18671860 self: *Coff,
18681861 decl_val: InternPool.Index,
18691862 explicit_alignment: InternPool.Alignment,
1870 src_loc: Module.SrcLoc,
1863 src_loc: Module.LazySrcLoc,
18711864) !codegen.Result {
18721865 const gpa = self.base.comp.gpa;
18731866 const mod = self.base.comp.module.?;
src/link/Elf.zig+1-1
......@@ -552,7 +552,7 @@ pub fn lowerAnonDecl(
552552 self: *Elf,
553553 decl_val: InternPool.Index,
554554 explicit_alignment: InternPool.Alignment,
555 src_loc: Module.SrcLoc,
555 src_loc: Module.LazySrcLoc,
556556) !codegen.Result {
557557 return self.zigObjectPtr().?.lowerAnonDecl(self, decl_val, explicit_alignment, src_loc);
558558}
src/link/Elf/ZigObject.zig+11-18
......@@ -686,7 +686,7 @@ pub fn lowerAnonDecl(
686686 elf_file: *Elf,
687687 decl_val: InternPool.Index,
688688 explicit_alignment: InternPool.Alignment,
689 src_loc: Module.SrcLoc,
689 src_loc: Module.LazySrcLoc,
690690) !codegen.Result {
691691 const gpa = elf_file.base.comp.gpa;
692692 const mod = elf_file.base.comp.module.?;
......@@ -1074,7 +1074,7 @@ pub fn updateFunc(
10741074 const res = if (decl_state) |*ds|
10751075 try codegen.generateFunction(
10761076 &elf_file.base,
1077 decl.navSrcLoc(mod).upgrade(mod),
1077 decl.navSrcLoc(mod),
10781078 func_index,
10791079 air,
10801080 liveness,
......@@ -1084,7 +1084,7 @@ pub fn updateFunc(
10841084 else
10851085 try codegen.generateFunction(
10861086 &elf_file.base,
1087 decl.navSrcLoc(mod).upgrade(mod),
1087 decl.navSrcLoc(mod),
10881088 func_index,
10891089 air,
10901090 liveness,
......@@ -1156,13 +1156,13 @@ pub fn updateDecl(
11561156 // TODO implement .debug_info for global variables
11571157 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
11581158 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, .{
11601160 .dwarf = ds,
11611161 }, .{
11621162 .parent_atom_index = sym_index,
11631163 })
11641164 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, .{
11661166 .parent_atom_index = sym_index,
11671167 });
11681168
......@@ -1217,14 +1217,7 @@ fn updateLazySymbol(
12171217 break :blk try self.strtab.insert(gpa, name);
12181218 };
12191219
1220 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1221 src.upgrade(mod)
1222 else
1223 Module.SrcLoc{
1224 .file_scope = undefined,
1225 .base_node = undefined,
1226 .lazy = .unneeded,
1227 };
1220 const src = sym.ty.srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded;
12281221 const res = try codegen.generateLazySymbol(
12291222 &elf_file.base,
12301223 src,
......@@ -1302,7 +1295,7 @@ pub fn lowerUnnamedConst(
13021295 val,
13031296 ty.abiAlignment(mod),
13041297 elf_file.zig_data_rel_ro_section_index.?,
1305 decl.navSrcLoc(mod).upgrade(mod),
1298 decl.navSrcLoc(mod),
13061299 )) {
13071300 .ok => |sym_index| sym_index,
13081301 .fail => |em| {
......@@ -1329,7 +1322,7 @@ fn lowerConst(
13291322 val: Value,
13301323 required_alignment: InternPool.Alignment,
13311324 output_section_index: u32,
1332 src_loc: Module.SrcLoc,
1325 src_loc: Module.LazySrcLoc,
13331326) !LowerConstResult {
13341327 const gpa = elf_file.base.comp.gpa;
13351328
......@@ -1395,7 +1388,7 @@ pub fn updateExports(
13951388 },
13961389 .value => |value| self.anon_decls.getPtr(value) orelse blk: {
13971390 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);
13991392 switch (res) {
14001393 .ok => {},
14011394 .fail => |em| {
......@@ -1421,7 +1414,7 @@ pub fn updateExports(
14211414 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
14221415 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Module.ErrorMsg.create(
14231416 gpa,
1424 exp.getSrcLoc(mod),
1417 exp.src,
14251418 "Unimplemented: ExportOptions.section",
14261419 .{},
14271420 ));
......@@ -1436,7 +1429,7 @@ pub fn updateExports(
14361429 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
14371430 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Module.ErrorMsg.create(
14381431 gpa,
1439 exp.getSrcLoc(mod),
1432 exp.src,
14401433 "Unimplemented: GlobalLinkage.LinkOnce",
14411434 .{},
14421435 ));
src/link/MachO.zig+1-1
......@@ -3228,7 +3228,7 @@ pub fn lowerAnonDecl(
32283228 self: *MachO,
32293229 decl_val: InternPool.Index,
32303230 explicit_alignment: InternPool.Alignment,
3231 src_loc: Module.SrcLoc,
3231 src_loc: Module.LazySrcLoc,
32323232) !codegen.Result {
32333233 return self.getZigObject().?.lowerAnonDecl(self, decl_val, explicit_alignment, src_loc);
32343234}
src/link/MachO/ZigObject.zig+9-16
......@@ -572,7 +572,7 @@ pub fn lowerAnonDecl(
572572 macho_file: *MachO,
573573 decl_val: InternPool.Index,
574574 explicit_alignment: Atom.Alignment,
575 src_loc: Module.SrcLoc,
575 src_loc: Module.LazySrcLoc,
576576) !codegen.Result {
577577 const gpa = macho_file.base.comp.gpa;
578578 const mod = macho_file.base.comp.module.?;
......@@ -682,7 +682,7 @@ pub fn updateFunc(
682682 const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none;
683683 const res = try codegen.generateFunction(
684684 &macho_file.base,
685 decl.navSrcLoc(mod).upgrade(mod),
685 decl.navSrcLoc(mod),
686686 func_index,
687687 air,
688688 liveness,
......@@ -754,7 +754,7 @@ pub fn updateDecl(
754754
755755 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
756756 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, .{
758758 .parent_atom_index = sym_index,
759759 });
760760
......@@ -1100,7 +1100,7 @@ pub fn lowerUnnamedConst(
11001100 val,
11011101 val.typeOf(mod).abiAlignment(mod),
11021102 macho_file.zig_const_sect_index.?,
1103 decl.navSrcLoc(mod).upgrade(mod),
1103 decl.navSrcLoc(mod),
11041104 )) {
11051105 .ok => |sym_index| sym_index,
11061106 .fail => |em| {
......@@ -1127,7 +1127,7 @@ fn lowerConst(
11271127 val: Value,
11281128 required_alignment: Atom.Alignment,
11291129 output_section_index: u8,
1130 src_loc: Module.SrcLoc,
1130 src_loc: Module.LazySrcLoc,
11311131) !LowerConstResult {
11321132 const gpa = macho_file.base.comp.gpa;
11331133
......@@ -1196,7 +1196,7 @@ pub fn updateExports(
11961196 },
11971197 .value => |value| self.anon_decls.getPtr(value) orelse blk: {
11981198 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);
12001200 switch (res) {
12011201 .ok => {},
12021202 .fail => |em| {
......@@ -1221,7 +1221,7 @@ pub fn updateExports(
12211221 try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1);
12221222 mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Module.ErrorMsg.create(
12231223 gpa,
1224 exp.getSrcLoc(mod),
1224 exp.src,
12251225 "Unimplemented: ExportOptions.section",
12261226 .{},
12271227 ));
......@@ -1231,7 +1231,7 @@ pub fn updateExports(
12311231 if (exp.opts.linkage == .link_once) {
12321232 try mod.failed_exports.putNoClobber(mod.gpa, export_idx, try Module.ErrorMsg.create(
12331233 gpa,
1234 exp.getSrcLoc(mod),
1234 exp.src,
12351235 "Unimplemented: GlobalLinkage.link_once",
12361236 .{},
12371237 ));
......@@ -1291,14 +1291,7 @@ fn updateLazySymbol(
12911291 break :blk try self.strtab.insert(gpa, name);
12921292 };
12931293
1294 const src = if (lazy_sym.ty.srcLocOrNull(mod)) |src|
1295 src.upgrade(mod)
1296 else
1297 Module.SrcLoc{
1298 .file_scope = undefined,
1299 .base_node = undefined,
1300 .lazy = .unneeded,
1301 };
1294 const src = lazy_sym.ty.srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded;
13021295 const res = try codegen.generateLazySymbol(
13031296 &macho_file.base,
13041297 src,
src/link/Plan9.zig+6-13
......@@ -439,7 +439,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air:
439439
440440 const res = try codegen.generateFunction(
441441 &self.base,
442 decl.navSrcLoc(mod).upgrade(mod),
442 decl.navSrcLoc(mod),
443443 func_index,
444444 air,
445445 liveness,
......@@ -505,7 +505,7 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn
505505 };
506506 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, .{
509509 .none = {},
510510 }, .{
511511 .parent_atom_index = new_atom_idx,
......@@ -544,7 +544,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex)
544544 defer code_buffer.deinit();
545545 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
546546 // 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 = {} }, .{
548548 .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)),
549549 });
550550 const code = switch (res) {
......@@ -1027,7 +1027,7 @@ fn addDeclExports(
10271027 {
10281028 try mod.failed_exports.put(mod.gpa, export_idx, try Module.ErrorMsg.create(
10291029 gpa,
1030 mod.declPtr(decl_index).navSrcLoc(mod).upgrade(mod),
1030 mod.declPtr(decl_index).navSrcLoc(mod),
10311031 "plan9 does not support extra sections",
10321032 .{},
10331033 ));
......@@ -1225,14 +1225,7 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind
12251225 self.syms.items[self.getAtomPtr(atom_index).sym_index.?] = symbol;
12261226
12271227 // generate the code
1228 const src = if (sym.ty.srcLocOrNull(mod)) |src|
1229 src.upgrade(mod)
1230 else
1231 Module.SrcLoc{
1232 .file_scope = undefined,
1233 .base_node = undefined,
1234 .lazy = .unneeded,
1235 };
1228 const src = sym.ty.srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded;
12361229 const res = try codegen.generateLazySymbol(
12371230 &self.base,
12381231 src,
......@@ -1553,7 +1546,7 @@ pub fn lowerAnonDecl(
15531546 self: *Plan9,
15541547 decl_val: InternPool.Index,
15551548 explicit_alignment: InternPool.Alignment,
1556 src_loc: Module.SrcLoc,
1549 src_loc: Module.LazySrcLoc,
15571550) !codegen.Result {
15581551 _ = explicit_alignment;
15591552 // This is basically the same as lowerUnnamedConst.
src/link/Wasm.zig+1-1
......@@ -1533,7 +1533,7 @@ pub fn lowerAnonDecl(
15331533 wasm: *Wasm,
15341534 decl_val: InternPool.Index,
15351535 explicit_alignment: Alignment,
1536 src_loc: Module.SrcLoc,
1536 src_loc: Module.LazySrcLoc,
15371537) !codegen.Result {
15381538 return wasm.zigObjectPtr().?.lowerAnonDecl(wasm, decl_val, explicit_alignment, src_loc);
15391539}
src/link/Wasm/ZigObject.zig+7-7
......@@ -269,7 +269,7 @@ pub fn updateDecl(
269269
270270 const res = try codegen.generateSymbol(
271271 &wasm_file.base,
272 decl.navSrcLoc(mod).upgrade(mod),
272 decl.navSrcLoc(mod),
273273 val,
274274 &code_writer,
275275 .none,
......@@ -308,7 +308,7 @@ pub fn updateFunc(
308308 defer code_writer.deinit();
309309 const result = try codegen.generateFunction(
310310 &wasm_file.base,
311 decl.navSrcLoc(mod).upgrade(mod),
311 decl.navSrcLoc(mod),
312312 func_index,
313313 air,
314314 liveness,
......@@ -439,7 +439,7 @@ pub fn lowerAnonDecl(
439439 wasm_file: *Wasm,
440440 decl_val: InternPool.Index,
441441 explicit_alignment: InternPool.Alignment,
442 src_loc: Module.SrcLoc,
442 src_loc: Module.LazySrcLoc,
443443) !codegen.Result {
444444 const gpa = wasm_file.base.comp.gpa;
445445 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
494494 else
495495 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)) {
498498 .ok => |atom_index| {
499499 try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index);
500500 return @intFromEnum(wasm_file.getAtom(atom_index).sym_index);
......@@ -512,7 +512,7 @@ const LowerConstResult = union(enum) {
512512 fail: *Module.ErrorMsg,
513513};
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 {
516516 const gpa = wasm_file.base.comp.gpa;
517517 const mod = wasm_file.base.comp.module.?;
518518
......@@ -882,7 +882,7 @@ pub fn updateExports(
882882 if (exp.opts.section.toSlice(&mod.intern_pool)) |section| {
883883 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(
884884 gpa,
885 decl.navSrcLoc(mod).upgrade(mod),
885 decl.navSrcLoc(mod),
886886 "Unimplemented: ExportOptions.section '{s}'",
887887 .{section},
888888 ));
......@@ -915,7 +915,7 @@ pub fn updateExports(
915915 .link_once => {
916916 try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create(
917917 gpa,
918 decl.navSrcLoc(mod).upgrade(mod),
918 decl.navSrcLoc(mod),
919919 "Unimplemented: LinkOnce",
920920 .{},
921921 ));