From e644a2ab6a99951ac8d367f7a6bac985cf16f9cc Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Sun, 10 Jul 2022 16:58:25 +0300 Subject: Compilation: do not repeat same source line for notes --- src/Compilation.zig | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index b00f135813..48a287d40b 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -505,6 +505,9 @@ pub const AllErrors = struct { Message.HashContext, std.hash_map.default_max_load_percentage, ).init(allocator); + const err_source = try module_err_msg.src_loc.file_scope.getSource(module.gpa); + const err_byte_offset = try module_err_msg.src_loc.byteOffset(module.gpa); + const err_loc = std.zig.findLineColumn(err_source.bytes, err_byte_offset); for (module_err_msg.notes) |module_note| { const source = try module_note.src_loc.file_scope.getSource(module.gpa); @@ -519,7 +522,7 @@ pub const AllErrors = struct { .byte_offset = byte_offset, .line = @intCast(u32, loc.line), .column = @intCast(u32, loc.column), - .source_line = try allocator.dupe(u8, loc.source_line), + .source_line = if (err_loc.eql(loc)) null else try allocator.dupe(u8, loc.source_line), }, }; const gop = try seen_notes.getOrPut(note); @@ -537,19 +540,16 @@ pub const AllErrors = struct { }); return; } - const source = try module_err_msg.src_loc.file_scope.getSource(module.gpa); - const byte_offset = try module_err_msg.src_loc.byteOffset(module.gpa); - const loc = std.zig.findLineColumn(source.bytes, byte_offset); const file_path = try module_err_msg.src_loc.file_scope.fullPath(allocator); try errors.append(.{ .src = .{ .src_path = file_path, .msg = try allocator.dupe(u8, module_err_msg.msg), - .byte_offset = byte_offset, - .line = @intCast(u32, loc.line), - .column = @intCast(u32, loc.column), + .byte_offset = err_byte_offset, + .line = @intCast(u32, err_loc.line), + .column = @intCast(u32, err_loc.column), .notes = notes_buf[0..note_i], - .source_line = try allocator.dupe(u8, loc.source_line), + .source_line = try allocator.dupe(u8, err_loc.source_line), }, }); } -- cgit v1.2.3 From 2a41b1449b724aa10290b9ec735c89405b627960 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Mon, 11 Jul 2022 14:10:25 +0300 Subject: Compilation: do not repeat AstGen error source line for notes --- src/Compilation.zig | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/Compilation.zig') diff --git a/src/Compilation.zig b/src/Compilation.zig index 48a287d40b..9678bc27b9 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -572,6 +572,16 @@ pub const AllErrors = struct { while (item_i < items_len) : (item_i += 1) { const item = file.zir.extraData(Zir.Inst.CompileErrors.Item, extra_index); extra_index = item.end; + const err_byte_offset = blk: { + const token_starts = file.tree.tokens.items(.start); + if (item.data.node != 0) { + const main_tokens = file.tree.nodes.items(.main_token); + const main_token = main_tokens[item.data.node]; + break :blk token_starts[main_token]; + } + break :blk token_starts[item.data.token] + item.data.byte_offset; + }; + const err_loc = std.zig.findLineColumn(file.source, err_byte_offset); var notes: []Message = &[0]Message{}; if (item.data.notes != 0) { @@ -600,33 +610,22 @@ pub const AllErrors = struct { .line = @intCast(u32, loc.line), .column = @intCast(u32, loc.column), .notes = &.{}, // TODO rework this function to be recursive - .source_line = try arena.dupe(u8, loc.source_line), + .source_line = if (loc.eql(err_loc)) null else try arena.dupe(u8, loc.source_line), }, }; } } const msg = file.zir.nullTerminatedString(item.data.msg); - const byte_offset = blk: { - const token_starts = file.tree.tokens.items(.start); - if (item.data.node != 0) { - const main_tokens = file.tree.nodes.items(.main_token); - const main_token = main_tokens[item.data.node]; - break :blk token_starts[main_token]; - } - break :blk token_starts[item.data.token] + item.data.byte_offset; - }; - const loc = std.zig.findLineColumn(file.source, byte_offset); - try errors.append(.{ .src = .{ .src_path = try file.fullPath(arena), .msg = try arena.dupe(u8, msg), - .byte_offset = byte_offset, - .line = @intCast(u32, loc.line), - .column = @intCast(u32, loc.column), + .byte_offset = err_byte_offset, + .line = @intCast(u32, err_loc.line), + .column = @intCast(u32, err_loc.column), .notes = notes, - .source_line = try arena.dupe(u8, loc.source_line), + .source_line = try arena.dupe(u8, err_loc.source_line), }, }); } -- cgit v1.2.3