diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-06-30 03:00:07 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-07-04 21:01:41 +0100 |
| commit | ded5c759f83a4da355a128dd4d7f5e22cbd3cabe (patch) | |
| tree | b862bbdf36b892e9c39f472c6759f084c87d64b2 /src/link | |
| parent | 089bbd6588d82ccda0646e756006cf5787eadef2 (diff) | |
| download | zig-ded5c759f83a4da355a128dd4d7f5e22cbd3cabe.tar.gz zig-ded5c759f83a4da355a128dd4d7f5e22cbd3cabe.zip | |
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`.
Diffstat (limited to 'src/link')
| -rw-r--r-- | src/link/Coff.zig | 25 | ||||
| -rw-r--r-- | src/link/Elf.zig | 2 | ||||
| -rw-r--r-- | src/link/Elf/ZigObject.zig | 29 | ||||
| -rw-r--r-- | src/link/MachO.zig | 2 | ||||
| -rw-r--r-- | src/link/MachO/ZigObject.zig | 25 | ||||
| -rw-r--r-- | src/link/Plan9.zig | 19 | ||||
| -rw-r--r-- | src/link/Wasm.zig | 2 | ||||
| -rw-r--r-- | src/link/Wasm/ZigObject.zig | 14 |
8 files changed, 45 insertions, 73 deletions
diff --git a/src/link/Coff.zig b/src/link/Coff.zig index 94b9ca520e..366ba87509 100644 --- a/src/link/Coff.zig +++ b/src/link/Coff.zig @@ -1144,7 +1144,7 @@ pub fn updateFunc(self: *Coff, mod: *Module, func_index: InternPool.Index, air: const res = try codegen.generateFunction( &self.base, - decl.navSrcLoc(mod).upgrade(mod), + decl.navSrcLoc(mod), func_index, air, liveness, @@ -1179,7 +1179,7 @@ pub fn lowerUnnamedConst(self: *Coff, val: Value, decl_index: InternPool.DeclInd const sym_name = try std.fmt.allocPrint(gpa, "__unnamed_{}_{d}", .{ decl_name.fmt(&mod.intern_pool), index }); defer gpa.free(sym_name); const ty = val.typeOf(mod); - const atom_index = switch (try self.lowerConst(sym_name, val, ty.abiAlignment(mod), self.rdata_section_index.?, decl.navSrcLoc(mod).upgrade(mod))) { + const atom_index = switch (try self.lowerConst(sym_name, val, ty.abiAlignment(mod), self.rdata_section_index.?, decl.navSrcLoc(mod))) { .ok => |atom_index| atom_index, .fail => |em| { decl.analysis = .codegen_failure; @@ -1197,7 +1197,7 @@ const LowerConstResult = union(enum) { fail: *Module.ErrorMsg, }; -fn lowerConst(self: *Coff, name: []const u8, val: Value, required_alignment: InternPool.Alignment, sect_id: u16, src_loc: Module.SrcLoc) !LowerConstResult { +fn lowerConst(self: *Coff, name: []const u8, val: Value, required_alignment: InternPool.Alignment, sect_id: u16, src_loc: Module.LazySrcLoc) !LowerConstResult { const gpa = self.base.comp.gpa; var code_buffer = std.ArrayList(u8).init(gpa); @@ -1270,7 +1270,7 @@ pub fn updateDecl( defer code_buffer.deinit(); const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; - const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .none, .{ + const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod), decl_val, &code_buffer, .none, .{ .parent_atom_index = atom.getSymbolIndex().?, }); const code = switch (res) { @@ -1309,14 +1309,7 @@ fn updateLazySymbolAtom( const atom = self.getAtomPtr(atom_index); const local_sym_index = atom.getSymbolIndex().?; - const src = if (sym.ty.srcLocOrNull(mod)) |src| - src.upgrade(mod) - else - Module.SrcLoc{ - .file_scope = undefined, - .base_node = undefined, - .lazy = .unneeded, - }; + const src = sym.ty.srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded; const res = try codegen.generateLazySymbol( &self.base, src, @@ -1560,7 +1553,7 @@ pub fn updateExports( }, .value => |value| self.anon_decls.getPtr(value) orelse blk: { const first_exp = mod.all_exports.items[export_indices[0]]; - const res = try self.lowerAnonDecl(value, .none, first_exp.getSrcLoc(mod)); + const res = try self.lowerAnonDecl(value, .none, first_exp.src); switch (res) { .ok => {}, .fail => |em| { @@ -1585,7 +1578,7 @@ pub fn updateExports( if (!mem.eql(u8, section_name, ".text")) { try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create( gpa, - exp.getSrcLoc(mod), + exp.src, "Unimplemented: ExportOptions.section", .{}, )); @@ -1596,7 +1589,7 @@ pub fn updateExports( if (exp.opts.linkage == .link_once) { try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create( gpa, - exp.getSrcLoc(mod), + exp.src, "Unimplemented: GlobalLinkage.link_once", .{}, )); @@ -1867,7 +1860,7 @@ pub fn lowerAnonDecl( self: *Coff, decl_val: InternPool.Index, explicit_alignment: InternPool.Alignment, - src_loc: Module.SrcLoc, + src_loc: Module.LazySrcLoc, ) !codegen.Result { const gpa = self.base.comp.gpa; const mod = self.base.comp.module.?; diff --git a/src/link/Elf.zig b/src/link/Elf.zig index df8e6c0dd8..c1df153083 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -552,7 +552,7 @@ pub fn lowerAnonDecl( self: *Elf, decl_val: InternPool.Index, explicit_alignment: InternPool.Alignment, - src_loc: Module.SrcLoc, + src_loc: Module.LazySrcLoc, ) !codegen.Result { return self.zigObjectPtr().?.lowerAnonDecl(self, decl_val, explicit_alignment, src_loc); } diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index 74e2039f37..57fa610019 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -686,7 +686,7 @@ pub fn lowerAnonDecl( elf_file: *Elf, decl_val: InternPool.Index, explicit_alignment: InternPool.Alignment, - src_loc: Module.SrcLoc, + src_loc: Module.LazySrcLoc, ) !codegen.Result { const gpa = elf_file.base.comp.gpa; const mod = elf_file.base.comp.module.?; @@ -1074,7 +1074,7 @@ pub fn updateFunc( const res = if (decl_state) |*ds| try codegen.generateFunction( &elf_file.base, - decl.navSrcLoc(mod).upgrade(mod), + decl.navSrcLoc(mod), func_index, air, liveness, @@ -1084,7 +1084,7 @@ pub fn updateFunc( else try codegen.generateFunction( &elf_file.base, - decl.navSrcLoc(mod).upgrade(mod), + decl.navSrcLoc(mod), func_index, air, liveness, @@ -1156,13 +1156,13 @@ pub fn updateDecl( // TODO implement .debug_info for global variables const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; const res = if (decl_state) |*ds| - try codegen.generateSymbol(&elf_file.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .{ + try codegen.generateSymbol(&elf_file.base, decl.navSrcLoc(mod), decl_val, &code_buffer, .{ .dwarf = ds, }, .{ .parent_atom_index = sym_index, }) else - try codegen.generateSymbol(&elf_file.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .none, .{ + try codegen.generateSymbol(&elf_file.base, decl.navSrcLoc(mod), decl_val, &code_buffer, .none, .{ .parent_atom_index = sym_index, }); @@ -1217,14 +1217,7 @@ fn updateLazySymbol( break :blk try self.strtab.insert(gpa, name); }; - const src = if (sym.ty.srcLocOrNull(mod)) |src| - src.upgrade(mod) - else - Module.SrcLoc{ - .file_scope = undefined, - .base_node = undefined, - .lazy = .unneeded, - }; + const src = sym.ty.srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded; const res = try codegen.generateLazySymbol( &elf_file.base, src, @@ -1302,7 +1295,7 @@ pub fn lowerUnnamedConst( val, ty.abiAlignment(mod), elf_file.zig_data_rel_ro_section_index.?, - decl.navSrcLoc(mod).upgrade(mod), + decl.navSrcLoc(mod), )) { .ok => |sym_index| sym_index, .fail => |em| { @@ -1329,7 +1322,7 @@ fn lowerConst( val: Value, required_alignment: InternPool.Alignment, output_section_index: u32, - src_loc: Module.SrcLoc, + src_loc: Module.LazySrcLoc, ) !LowerConstResult { const gpa = elf_file.base.comp.gpa; @@ -1395,7 +1388,7 @@ pub fn updateExports( }, .value => |value| self.anon_decls.getPtr(value) orelse blk: { const first_exp = mod.all_exports.items[export_indices[0]]; - const res = try self.lowerAnonDecl(elf_file, value, .none, first_exp.getSrcLoc(mod)); + const res = try self.lowerAnonDecl(elf_file, value, .none, first_exp.src); switch (res) { .ok => {}, .fail => |em| { @@ -1421,7 +1414,7 @@ pub fn updateExports( try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1); mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Module.ErrorMsg.create( gpa, - exp.getSrcLoc(mod), + exp.src, "Unimplemented: ExportOptions.section", .{}, )); @@ -1436,7 +1429,7 @@ pub fn updateExports( try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1); mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Module.ErrorMsg.create( gpa, - exp.getSrcLoc(mod), + exp.src, "Unimplemented: GlobalLinkage.LinkOnce", .{}, )); diff --git a/src/link/MachO.zig b/src/link/MachO.zig index 3187ba528b..ed20a16abf 100644 --- a/src/link/MachO.zig +++ b/src/link/MachO.zig @@ -3228,7 +3228,7 @@ pub fn lowerAnonDecl( self: *MachO, decl_val: InternPool.Index, explicit_alignment: InternPool.Alignment, - src_loc: Module.SrcLoc, + src_loc: Module.LazySrcLoc, ) !codegen.Result { return self.getZigObject().?.lowerAnonDecl(self, decl_val, explicit_alignment, src_loc); } diff --git a/src/link/MachO/ZigObject.zig b/src/link/MachO/ZigObject.zig index ee5ab83b0a..861ced9214 100644 --- a/src/link/MachO/ZigObject.zig +++ b/src/link/MachO/ZigObject.zig @@ -572,7 +572,7 @@ pub fn lowerAnonDecl( macho_file: *MachO, decl_val: InternPool.Index, explicit_alignment: Atom.Alignment, - src_loc: Module.SrcLoc, + src_loc: Module.LazySrcLoc, ) !codegen.Result { const gpa = macho_file.base.comp.gpa; const mod = macho_file.base.comp.module.?; @@ -682,7 +682,7 @@ pub fn updateFunc( const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none; const res = try codegen.generateFunction( &macho_file.base, - decl.navSrcLoc(mod).upgrade(mod), + decl.navSrcLoc(mod), func_index, air, liveness, @@ -754,7 +754,7 @@ pub fn updateDecl( const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; const dio: codegen.DebugInfoOutput = if (decl_state) |*ds| .{ .dwarf = ds } else .none; - const res = try codegen.generateSymbol(&macho_file.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, dio, .{ + const res = try codegen.generateSymbol(&macho_file.base, decl.navSrcLoc(mod), decl_val, &code_buffer, dio, .{ .parent_atom_index = sym_index, }); @@ -1100,7 +1100,7 @@ pub fn lowerUnnamedConst( val, val.typeOf(mod).abiAlignment(mod), macho_file.zig_const_sect_index.?, - decl.navSrcLoc(mod).upgrade(mod), + decl.navSrcLoc(mod), )) { .ok => |sym_index| sym_index, .fail => |em| { @@ -1127,7 +1127,7 @@ fn lowerConst( val: Value, required_alignment: Atom.Alignment, output_section_index: u8, - src_loc: Module.SrcLoc, + src_loc: Module.LazySrcLoc, ) !LowerConstResult { const gpa = macho_file.base.comp.gpa; @@ -1196,7 +1196,7 @@ pub fn updateExports( }, .value => |value| self.anon_decls.getPtr(value) orelse blk: { const first_exp = mod.all_exports.items[export_indices[0]]; - const res = try self.lowerAnonDecl(macho_file, value, .none, first_exp.getSrcLoc(mod)); + const res = try self.lowerAnonDecl(macho_file, value, .none, first_exp.src); switch (res) { .ok => {}, .fail => |em| { @@ -1221,7 +1221,7 @@ pub fn updateExports( try mod.failed_exports.ensureUnusedCapacity(mod.gpa, 1); mod.failed_exports.putAssumeCapacityNoClobber(export_idx, try Module.ErrorMsg.create( gpa, - exp.getSrcLoc(mod), + exp.src, "Unimplemented: ExportOptions.section", .{}, )); @@ -1231,7 +1231,7 @@ pub fn updateExports( if (exp.opts.linkage == .link_once) { try mod.failed_exports.putNoClobber(mod.gpa, export_idx, try Module.ErrorMsg.create( gpa, - exp.getSrcLoc(mod), + exp.src, "Unimplemented: GlobalLinkage.link_once", .{}, )); @@ -1291,14 +1291,7 @@ fn updateLazySymbol( break :blk try self.strtab.insert(gpa, name); }; - const src = if (lazy_sym.ty.srcLocOrNull(mod)) |src| - src.upgrade(mod) - else - Module.SrcLoc{ - .file_scope = undefined, - .base_node = undefined, - .lazy = .unneeded, - }; + const src = lazy_sym.ty.srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded; const res = try codegen.generateLazySymbol( &macho_file.base, src, diff --git a/src/link/Plan9.zig b/src/link/Plan9.zig index d44da5c973..2efe569d98 100644 --- a/src/link/Plan9.zig +++ b/src/link/Plan9.zig @@ -439,7 +439,7 @@ pub fn updateFunc(self: *Plan9, mod: *Module, func_index: InternPool.Index, air: const res = try codegen.generateFunction( &self.base, - decl.navSrcLoc(mod).upgrade(mod), + decl.navSrcLoc(mod), func_index, air, liveness, @@ -505,7 +505,7 @@ pub fn lowerUnnamedConst(self: *Plan9, val: Value, decl_index: InternPool.DeclIn }; self.syms.items[info.sym_index.?] = sym; - const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod).upgrade(mod), val, &code_buffer, .{ + const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod), val, &code_buffer, .{ .none = {}, }, .{ .parent_atom_index = new_atom_idx, @@ -544,7 +544,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: InternPool.DeclIndex) defer code_buffer.deinit(); const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val; // TODO we need the symbol index for symbol in the table of locals for the containing atom - const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod).upgrade(mod), decl_val, &code_buffer, .{ .none = {} }, .{ + const res = try codegen.generateSymbol(&self.base, decl.navSrcLoc(mod), decl_val, &code_buffer, .{ .none = {} }, .{ .parent_atom_index = @as(Atom.Index, @intCast(atom_idx)), }); const code = switch (res) { @@ -1027,7 +1027,7 @@ fn addDeclExports( { try mod.failed_exports.put(mod.gpa, export_idx, try Module.ErrorMsg.create( gpa, - mod.declPtr(decl_index).navSrcLoc(mod).upgrade(mod), + mod.declPtr(decl_index).navSrcLoc(mod), "plan9 does not support extra sections", .{}, )); @@ -1225,14 +1225,7 @@ fn updateLazySymbolAtom(self: *Plan9, sym: File.LazySymbol, atom_index: Atom.Ind self.syms.items[self.getAtomPtr(atom_index).sym_index.?] = symbol; // generate the code - const src = if (sym.ty.srcLocOrNull(mod)) |src| - src.upgrade(mod) - else - Module.SrcLoc{ - .file_scope = undefined, - .base_node = undefined, - .lazy = .unneeded, - }; + const src = sym.ty.srcLocOrNull(mod) orelse Module.LazySrcLoc.unneeded; const res = try codegen.generateLazySymbol( &self.base, src, @@ -1553,7 +1546,7 @@ pub fn lowerAnonDecl( self: *Plan9, decl_val: InternPool.Index, explicit_alignment: InternPool.Alignment, - src_loc: Module.SrcLoc, + src_loc: Module.LazySrcLoc, ) !codegen.Result { _ = explicit_alignment; // This is basically the same as lowerUnnamedConst. diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 164ddbc118..3befedad89 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -1533,7 +1533,7 @@ pub fn lowerAnonDecl( wasm: *Wasm, decl_val: InternPool.Index, explicit_alignment: Alignment, - src_loc: Module.SrcLoc, + src_loc: Module.LazySrcLoc, ) !codegen.Result { return wasm.zigObjectPtr().?.lowerAnonDecl(wasm, decl_val, explicit_alignment, src_loc); } diff --git a/src/link/Wasm/ZigObject.zig b/src/link/Wasm/ZigObject.zig index 341d3a2fc8..ca950e5cef 100644 --- a/src/link/Wasm/ZigObject.zig +++ b/src/link/Wasm/ZigObject.zig @@ -269,7 +269,7 @@ pub fn updateDecl( const res = try codegen.generateSymbol( &wasm_file.base, - decl.navSrcLoc(mod).upgrade(mod), + decl.navSrcLoc(mod), val, &code_writer, .none, @@ -308,7 +308,7 @@ pub fn updateFunc( defer code_writer.deinit(); const result = try codegen.generateFunction( &wasm_file.base, - decl.navSrcLoc(mod).upgrade(mod), + decl.navSrcLoc(mod), func_index, air, liveness, @@ -439,7 +439,7 @@ pub fn lowerAnonDecl( wasm_file: *Wasm, decl_val: InternPool.Index, explicit_alignment: InternPool.Alignment, - src_loc: Module.SrcLoc, + src_loc: Module.LazySrcLoc, ) !codegen.Result { const gpa = wasm_file.base.comp.gpa; 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 else decl.navSrcLoc(mod); - switch (try zig_object.lowerConst(wasm_file, name, val, decl_src.upgrade(mod))) { + switch (try zig_object.lowerConst(wasm_file, name, val, decl_src)) { .ok => |atom_index| { try wasm_file.getAtomPtr(parent_atom_index).locals.append(gpa, atom_index); return @intFromEnum(wasm_file.getAtom(atom_index).sym_index); @@ -512,7 +512,7 @@ const LowerConstResult = union(enum) { fail: *Module.ErrorMsg, }; -fn lowerConst(zig_object: *ZigObject, wasm_file: *Wasm, name: []const u8, val: Value, src_loc: Module.SrcLoc) !LowerConstResult { +fn lowerConst(zig_object: *ZigObject, wasm_file: *Wasm, name: []const u8, val: Value, src_loc: Module.LazySrcLoc) !LowerConstResult { const gpa = wasm_file.base.comp.gpa; const mod = wasm_file.base.comp.module.?; @@ -882,7 +882,7 @@ pub fn updateExports( if (exp.opts.section.toSlice(&mod.intern_pool)) |section| { try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create( gpa, - decl.navSrcLoc(mod).upgrade(mod), + decl.navSrcLoc(mod), "Unimplemented: ExportOptions.section '{s}'", .{section}, )); @@ -915,7 +915,7 @@ pub fn updateExports( .link_once => { try mod.failed_exports.putNoClobber(gpa, export_idx, try Module.ErrorMsg.create( gpa, - decl.navSrcLoc(mod).upgrade(mod), + decl.navSrcLoc(mod), "Unimplemented: LinkOnce", .{}, )); |
