authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-10 16:58:25+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-10 23:47:56+03:00
loge644a2ab6a99951ac8d367f7a6bac985cf16f9cc
tree3bfad1118dd5eb8c370df60ddd8ea004d7deff9b
parent34fe2b4f4be29efa8f4ba4b9f32b22373fdddc22

Compilation: do not repeat same source line for notes


2 files changed, 12 insertions(+), 8 deletions(-)

lib/std/zig.zig+4
......@@ -49,6 +49,10 @@ pub const Loc = struct {
4949 column: usize,
5050 /// Does not include the trailing newline.
5151 source_line: []const u8,
52
53 pub fn eql(a: Loc, b: Loc) bool {
54 return a.line == b.line and a.column == b.column and std.mem.eql(u8, a.source_line, b.source_line);
55 }
5256};
5357
5458pub fn findLineColumn(source: []const u8, byte_offset: usize) Loc {
src/Compilation.zig+8-8
......@@ -505,6 +505,9 @@ pub const AllErrors = struct {
505505 Message.HashContext,
506506 std.hash_map.default_max_load_percentage,
507507 ).init(allocator);
508 const err_source = try module_err_msg.src_loc.file_scope.getSource(module.gpa);
509 const err_byte_offset = try module_err_msg.src_loc.byteOffset(module.gpa);
510 const err_loc = std.zig.findLineColumn(err_source.bytes, err_byte_offset);
508511
509512 for (module_err_msg.notes) |module_note| {
510513 const source = try module_note.src_loc.file_scope.getSource(module.gpa);
......@@ -519,7 +522,7 @@ pub const AllErrors = struct {
519522 .byte_offset = byte_offset,
520523 .line = @intCast(u32, loc.line),
521524 .column = @intCast(u32, loc.column),
522 .source_line = try allocator.dupe(u8, loc.source_line),
525 .source_line = if (err_loc.eql(loc)) null else try allocator.dupe(u8, loc.source_line),
523526 },
524527 };
525528 const gop = try seen_notes.getOrPut(note);
......@@ -537,19 +540,16 @@ pub const AllErrors = struct {
537540 });
538541 return;
539542 }
540 const source = try module_err_msg.src_loc.file_scope.getSource(module.gpa);
541 const byte_offset = try module_err_msg.src_loc.byteOffset(module.gpa);
542 const loc = std.zig.findLineColumn(source.bytes, byte_offset);
543543 const file_path = try module_err_msg.src_loc.file_scope.fullPath(allocator);
544544 try errors.append(.{
545545 .src = .{
546546 .src_path = file_path,
547547 .msg = try allocator.dupe(u8, module_err_msg.msg),
548 .byte_offset = byte_offset,
549 .line = @intCast(u32, loc.line),
550 .column = @intCast(u32, loc.column),
548 .byte_offset = err_byte_offset,
549 .line = @intCast(u32, err_loc.line),
550 .column = @intCast(u32, err_loc.column),
551551 .notes = notes_buf[0..note_i],
552 .source_line = try allocator.dupe(u8, loc.source_line),
552 .source_line = try allocator.dupe(u8, err_loc.source_line),
553553 },
554554 });
555555 }