| author | |
| committer | |
| log | 5769ed2d4428305e4478cf4e425f5df2469a7ffd |
| tree | cb36433e95ccf98a2bc97c930f46248250869837 |
| parent | b4692c9a7808caabdf474c2acc6d6d3754e5e2e4 |
Previously, compile log stored full SrcLoc info, which included absolute
AST node index. This becomes invalid after an incremental compilation.
To make it survive incremental compilation, store an offset from parent
Decl instead.3 files changed, 13 insertions(+), 6 deletions(-)
src/Compilation.zig+3-2| ... | @@ -1810,8 +1810,9 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { | ... | @@ -1810,8 +1810,9 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { |
| 1810 | const compile_log_items = module.compile_log_decls.items(); | 1810 | const compile_log_items = module.compile_log_decls.items(); |
| 1811 | if (errors.items.len == 0 and compile_log_items.len != 0) { | 1811 | if (errors.items.len == 0 and compile_log_items.len != 0) { |
| 1812 | // First one will be the error; subsequent ones will be notes. | 1812 | // First one will be the error; subsequent ones will be notes. |
| 1813 | const src_loc = compile_log_items[0].key.nodeOffsetSrcLoc(compile_log_items[0].value); | ||
| 1813 | const err_msg = Module.ErrorMsg{ | 1814 | const err_msg = Module.ErrorMsg{ |
| 1814 | .src_loc = compile_log_items[0].value, | 1815 | .src_loc = src_loc, |
| 1815 | .msg = "found compile log statement", | 1816 | .msg = "found compile log statement", |
| 1816 | .notes = try self.gpa.alloc(Module.ErrorMsg, compile_log_items.len - 1), | 1817 | .notes = try self.gpa.alloc(Module.ErrorMsg, compile_log_items.len - 1), |
| 1817 | }; | 1818 | }; |
| ... | @@ -1819,7 +1820,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { | ... | @@ -1819,7 +1820,7 @@ pub fn getAllErrorsAlloc(self: *Compilation) !AllErrors { |
| 1819 | 1820 | ||
| 1820 | for (compile_log_items[1..]) |entry, i| { | 1821 | for (compile_log_items[1..]) |entry, i| { |
| 1821 | err_msg.notes[i] = .{ | 1822 | err_msg.notes[i] = .{ |
| 1822 | .src_loc = entry.value, | 1823 | .src_loc = entry.key.nodeOffsetSrcLoc(entry.value), |
| 1823 | .msg = "also here", | 1824 | .msg = "also here", |
| 1824 | }; | 1825 | }; |
| 1825 | } | 1826 | } |
src/Module.zig+7-2| ... | @@ -64,7 +64,8 @@ import_table: std.StringArrayHashMapUnmanaged(*Scope.File) = .{}, | ... | @@ -64,7 +64,8 @@ import_table: std.StringArrayHashMapUnmanaged(*Scope.File) = .{}, |
| 64 | /// a Decl can have a failed_decls entry but have analysis status of success. | 64 | /// a Decl can have a failed_decls entry but have analysis status of success. |
| 65 | failed_decls: std.AutoArrayHashMapUnmanaged(*Decl, *ErrorMsg) = .{}, | 65 | failed_decls: std.AutoArrayHashMapUnmanaged(*Decl, *ErrorMsg) = .{}, |
| 66 | /// Keep track of one `@compileLog` callsite per owner Decl. | 66 | /// Keep track of one `@compileLog` callsite per owner Decl. |
| 67 | compile_log_decls: std.AutoArrayHashMapUnmanaged(*Decl, SrcLoc) = .{}, | 67 | /// The value is the AST node index offset from the Decl. |
| 68 | compile_log_decls: std.AutoArrayHashMapUnmanaged(*Decl, i32) = .{}, | ||
| 68 | /// Using a map here for consistency with the other fields here. | 69 | /// Using a map here for consistency with the other fields here. |
| 69 | /// The ErrorMsg memory is owned by the `Scope.File`, using Module's general purpose allocator. | 70 | /// The ErrorMsg memory is owned by the `Scope.File`, using Module's general purpose allocator. |
| 70 | failed_files: std.AutoArrayHashMapUnmanaged(*Scope.File, ?*ErrorMsg) = .{}, | 71 | failed_files: std.AutoArrayHashMapUnmanaged(*Scope.File, ?*ErrorMsg) = .{}, |
| ... | @@ -407,10 +408,14 @@ pub const Decl = struct { | ... | @@ -407,10 +408,14 @@ pub const Decl = struct { |
| 407 | } | 408 | } |
| 408 | 409 | ||
| 409 | pub fn srcLoc(decl: Decl) SrcLoc { | 410 | pub fn srcLoc(decl: Decl) SrcLoc { |
| 411 | return decl.nodeOffsetSrcLoc(0); | ||
| 412 | } | ||
| 413 | |||
| 414 | pub fn nodeOffsetSrcLoc(decl: Decl, node_offset: i32) SrcLoc { | ||
| 410 | return .{ | 415 | return .{ |
| 411 | .file_scope = decl.getFileScope(), | 416 | .file_scope = decl.getFileScope(), |
| 412 | .parent_decl_node = decl.src_node, | 417 | .parent_decl_node = decl.src_node, |
| 413 | .lazy = .{ .node_offset = 0 }, | 418 | .lazy = .{ .node_offset = node_offset }, |
| 414 | }; | 419 | }; |
| 415 | } | 420 | } |
| 416 | 421 |
src/Sema.zig+3-2| ... | @@ -1661,7 +1661,8 @@ fn zirCompileLog( | ... | @@ -1661,7 +1661,8 @@ fn zirCompileLog( |
| 1661 | const writer = managed.writer(); | 1661 | const writer = managed.writer(); |
| 1662 | 1662 | ||
| 1663 | const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand); | 1663 | const extra = sema.code.extraData(Zir.Inst.NodeMultiOp, extended.operand); |
| 1664 | const src: LazySrcLoc = .{ .node_offset = extra.data.src_node }; | 1664 | const src_node = extra.data.src_node; |
| 1665 | const src: LazySrcLoc = .{ .node_offset = src_node }; | ||
| 1665 | const args = sema.code.refSlice(extra.end, extended.small); | 1666 | const args = sema.code.refSlice(extra.end, extended.small); |
| 1666 | 1667 | ||
| 1667 | for (args) |arg_ref, i| { | 1668 | for (args) |arg_ref, i| { |
| ... | @@ -1678,7 +1679,7 @@ fn zirCompileLog( | ... | @@ -1678,7 +1679,7 @@ fn zirCompileLog( |
| 1678 | 1679 | ||
| 1679 | const gop = try sema.mod.compile_log_decls.getOrPut(sema.gpa, sema.owner_decl); | 1680 | const gop = try sema.mod.compile_log_decls.getOrPut(sema.gpa, sema.owner_decl); |
| 1680 | if (!gop.found_existing) { | 1681 | if (!gop.found_existing) { |
| 1681 | gop.entry.value = src.toSrcLoc(&block.base); | 1682 | gop.entry.value = src_node; |
| 1682 | } | 1683 | } |
| 1683 | return sema.mod.constInst(sema.arena, src, .{ | 1684 | return sema.mod.constInst(sema.arena, src, .{ |
| 1684 | .ty = Type.initTag(.void), | 1685 | .ty = Type.initTag(.void), |