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 {...@@ -49,6 +49,10 @@ pub const Loc = struct {
49 column: usize,49 column: usize,
50 /// Does not include the trailing newline.50 /// Does not include the trailing newline.
51 source_line: []const u8,51 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 }
52};56};
5357
54pub fn findLineColumn(source: []const u8, byte_offset: usize) Loc {58pub fn findLineColumn(source: []const u8, byte_offset: usize) Loc {
src/Compilation.zig+8-8
...@@ -505,6 +505,9 @@ pub const AllErrors = struct {...@@ -505,6 +505,9 @@ pub const AllErrors = struct {
505 Message.HashContext,505 Message.HashContext,
506 std.hash_map.default_max_load_percentage,506 std.hash_map.default_max_load_percentage,
507 ).init(allocator);507 ).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
509 for (module_err_msg.notes) |module_note| {512 for (module_err_msg.notes) |module_note| {
510 const source = try module_note.src_loc.file_scope.getSource(module.gpa);513 const source = try module_note.src_loc.file_scope.getSource(module.gpa);
...@@ -519,7 +522,7 @@ pub const AllErrors = struct {...@@ -519,7 +522,7 @@ pub const AllErrors = struct {
519 .byte_offset = byte_offset,522 .byte_offset = byte_offset,
520 .line = @intCast(u32, loc.line),523 .line = @intCast(u32, loc.line),
521 .column = @intCast(u32, loc.column),524 .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),
523 },526 },
524 };527 };
525 const gop = try seen_notes.getOrPut(note);528 const gop = try seen_notes.getOrPut(note);
...@@ -537,19 +540,16 @@ pub const AllErrors = struct {...@@ -537,19 +540,16 @@ pub const AllErrors = struct {
537 });540 });
538 return;541 return;
539 }542 }
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);
543 const file_path = try module_err_msg.src_loc.file_scope.fullPath(allocator);543 const file_path = try module_err_msg.src_loc.file_scope.fullPath(allocator);
544 try errors.append(.{544 try errors.append(.{
545 .src = .{545 .src = .{
546 .src_path = file_path,546 .src_path = file_path,
547 .msg = try allocator.dupe(u8, module_err_msg.msg),547 .msg = try allocator.dupe(u8, module_err_msg.msg),
548 .byte_offset = byte_offset,548 .byte_offset = err_byte_offset,
549 .line = @intCast(u32, loc.line),549 .line = @intCast(u32, err_loc.line),
550 .column = @intCast(u32, loc.column),550 .column = @intCast(u32, err_loc.column),
551 .notes = notes_buf[0..note_i],551 .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),
553 },553 },
554 });554 });
555 }555 }