fix merge conflicts with updating line numbers

This commit is contained in:
Andrew Kelley
2025-01-05 19:32:06 -08:00
parent b41b5fe529
commit 94648a0383
6 changed files with 54 additions and 24 deletions

View File

@@ -142,7 +142,7 @@ pub fn generateLazySymbol(
var string_index: u32 = @intCast(4 * (1 + err_names.len + @intFromBool(err_names.len > 0)));
try code.resize(gpa, offset_index + string_index);
mem.writeInt(u32, code.items[offset_index..][0..4], @intCast(err_names.len), endian);
if (err_names.len == 0) return .ok;
if (err_names.len == 0) return;
offset_index += 4;
for (err_names) |err_name_nts| {
const err_name = err_name_nts.toSlice(ip);

View File

@@ -738,9 +738,15 @@ pub const File = struct {
}
}
pub const UpdateLineNumberError = error{
OutOfMemory,
Overflow,
LinkFailure,
};
/// On an incremental update, fixup the line number of all `Nav`s at the given `TrackedInst`, because
/// its line number has changed. The ZIR instruction `ti_id` has tag `.declaration`.
pub fn updateLineNumber(base: *File, pt: Zcu.PerThread, ti_id: InternPool.TrackedInst.Index) UpdateNavError!void {
pub fn updateLineNumber(base: *File, pt: Zcu.PerThread, ti_id: InternPool.TrackedInst.Index) UpdateLineNumberError!void {
{
const ti = ti_id.resolveFull(&pt.zcu.intern_pool).?;
const file = pt.zcu.fileByIndex(ti.file);

View File

@@ -2661,19 +2661,7 @@ pub fn finishWipNav(
pt: Zcu.PerThread,
nav_index: InternPool.Nav.Index,
wip_nav: *WipNav,
) error{ OutOfMemory, CodegenFail }!void {
return finishWipNavInner(dwarf, pt, nav_index, wip_nav) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
else => |e| return pt.zcu.codegenFail(nav_index, "failed to finish dwarf: {s}", .{@errorName(e)}),
};
}
fn finishWipNavInner(
dwarf: *Dwarf,
pt: Zcu.PerThread,
nav_index: InternPool.Nav.Index,
wip_nav: *WipNav,
) !void {
) UpdateError!void {
const zcu = pt.zcu;
const ip = &zcu.intern_pool;
const nav = ip.getNav(nav_index);

View File

@@ -1465,7 +1465,8 @@ pub fn updateFunc(
break :blk .{ atom_ptr.value, atom_ptr.alignment };
};
if (debug_wip_nav) |*wip_nav| try self.dwarf.?.finishWipNavFunc(pt, func.owner_nav, code.len, wip_nav);
if (debug_wip_nav) |*wip_nav| self.dwarf.?.finishWipNavFunc(pt, func.owner_nav, code.len, wip_nav) catch |err|
return elf_file.base.cgFail(func.owner_nav, "failed to finish dwarf function: {s}", .{@errorName(err)});
// Exports will be updated by `Zcu.processExports` after the update.
@@ -1550,7 +1551,11 @@ pub fn updateNav(
if (self.dwarf) |*dwarf| dwarf: {
var debug_wip_nav = try dwarf.initWipNav(pt, nav_index, sym_index) orelse break :dwarf;
defer debug_wip_nav.deinit();
try dwarf.finishWipNav(pt, nav_index, &debug_wip_nav);
dwarf.finishWipNav(pt, nav_index, &debug_wip_nav) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.Overflow => return error.Overflow,
else => |e| return elf_file.base.cgFail(nav_index, "failed to finish dwarf nav: {s}", .{@errorName(e)}),
};
}
return;
},
@@ -1588,7 +1593,11 @@ pub fn updateNav(
else
try self.updateNavCode(elf_file, pt, nav_index, sym_index, shndx, code, elf.STT_OBJECT);
if (debug_wip_nav) |*wip_nav| try self.dwarf.?.finishWipNav(pt, nav_index, wip_nav);
if (debug_wip_nav) |*wip_nav| self.dwarf.?.finishWipNav(pt, nav_index, wip_nav) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.Overflow => return error.Overflow,
else => |e| return elf_file.base.cgFail(nav_index, "failed to finish dwarf nav: {s}", .{@errorName(e)}),
};
} else if (self.dwarf) |*dwarf| try dwarf.updateComptimeNav(pt, nav_index);
// Exports will be updated by `Zcu.processExports` after the update.
@@ -1836,7 +1845,13 @@ pub fn updateExports(
pub fn updateLineNumber(self: *ZigObject, pt: Zcu.PerThread, ti_id: InternPool.TrackedInst.Index) !void {
if (self.dwarf) |*dwarf| {
try dwarf.updateLineNumber(pt.zcu, ti_id);
const comp = dwarf.bin_file.comp;
const diags = &comp.link_diags;
dwarf.updateLineNumber(pt.zcu, ti_id) catch |err| switch (err) {
error.Overflow => return error.Overflow,
error.OutOfMemory => return error.OutOfMemory,
else => |e| return diags.fail("failed to update dwarf line numbers: {s}", .{@errorName(e)}),
};
}
}

View File

@@ -818,7 +818,8 @@ pub fn updateFunc(
break :blk .{ atom.value, atom.alignment };
};
if (debug_wip_nav) |*wip_nav| try self.dwarf.?.finishWipNavFunc(pt, func.owner_nav, code.len, wip_nav);
if (debug_wip_nav) |*wip_nav| self.dwarf.?.finishWipNavFunc(pt, func.owner_nav, code.len, wip_nav) catch |err|
return macho_file.base.cgFail(func.owner_nav, "falied to finish dwarf function: {s}", .{@errorName(err)});
// Exports will be updated by `Zcu.processExports` after the update.
if (old_rva != new_rva and old_rva > 0) {
@@ -889,7 +890,11 @@ pub fn updateNav(
if (self.dwarf) |*dwarf| dwarf: {
var debug_wip_nav = try dwarf.initWipNav(pt, nav_index, sym_index) orelse break :dwarf;
defer debug_wip_nav.deinit();
try dwarf.finishWipNav(pt, nav_index, &debug_wip_nav);
dwarf.finishWipNav(pt, nav_index, &debug_wip_nav) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.Overflow => return error.Overflow,
else => |e| return macho_file.base.cgFail(nav_index, "failed to finish dwarf nav: {s}", .{@errorName(e)}),
};
}
return;
},
@@ -922,7 +927,11 @@ pub fn updateNav(
else
try self.updateNavCode(macho_file, pt, nav_index, sym_index, sect_index, code);
if (debug_wip_nav) |*wip_nav| try self.dwarf.?.finishWipNav(pt, nav_index, wip_nav);
if (debug_wip_nav) |*wip_nav| self.dwarf.?.finishWipNav(pt, nav_index, wip_nav) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
error.Overflow => return error.Overflow,
else => |e| return macho_file.base.cgFail(nav_index, "failed to finish dwarf nav: {s}", .{@errorName(e)}),
};
} else if (self.dwarf) |*dwarf| try dwarf.updateComptimeNav(pt, nav_index);
// Exports will be updated by `Zcu.processExports` after the update.
@@ -1411,7 +1420,13 @@ fn updateLazySymbol(
pub fn updateLineNumber(self: *ZigObject, pt: Zcu.PerThread, ti_id: InternPool.TrackedInst.Index) !void {
if (self.dwarf) |*dwarf| {
try dwarf.updateLineNumber(pt.zcu, ti_id);
const comp = dwarf.bin_file.comp;
const diags = &comp.link_diags;
dwarf.updateLineNumber(pt.zcu, ti_id) catch |err| switch (err) {
error.Overflow => return error.Overflow,
error.OutOfMemory => return error.OutOfMemory,
else => |e| return diags.fail("failed to update dwarf line numbers: {s}", .{@errorName(e)}),
};
}
}

View File

@@ -3106,8 +3106,14 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index
}
pub fn updateLineNumber(wasm: *Wasm, pt: Zcu.PerThread, ti_id: InternPool.TrackedInst.Index) !void {
const comp = wasm.base.comp;
const diags = &comp.link_diags;
if (wasm.dwarf) |*dw| {
try dw.updateLineNumber(pt.zcu, ti_id);
dw.updateLineNumber(pt.zcu, ti_id) catch |err| switch (err) {
error.Overflow => return error.Overflow,
error.OutOfMemory => return error.OutOfMemory,
else => |e| return diags.fail("failed to update dwarf line numbers: {s}", .{@errorName(e)}),
};
}
}