From 065e10c95ccca509afecfecc849da9114e0000b2 Mon Sep 17 00:00:00 2001 From: mlugg Date: Wed, 1 Jan 2025 20:16:48 +0000 Subject: link: new incremental line number update API --- src/link.zig | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) (limited to 'src/link.zig') diff --git a/src/link.zig b/src/link.zig index 58c5cf35af..fd1ef7ce33 100644 --- a/src/link.zig +++ b/src/link.zig @@ -727,16 +727,22 @@ pub const File = struct { } } - pub fn updateNavLineNumber( - base: *File, - pt: Zcu.PerThread, - nav_index: InternPool.Nav.Index, - ) UpdateNavError!void { + /// 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 { + { + const ti = ti_id.resolveFull(&pt.zcu.intern_pool).?; + const file = pt.zcu.fileByIndex(ti.file); + assert(file.zir_loaded); + const inst = file.zir.instructions.get(@intFromEnum(ti.inst)); + assert(inst.tag == .declaration); + } + switch (base.tag) { .spirv, .nvptx => {}, inline else => |tag| { dev.check(tag.devFeature()); - return @as(*tag.Type(), @fieldParentPtr("base", base)).updateNavineNumber(pt, nav_index); + return @as(*tag.Type(), @fieldParentPtr("base", base)).updateLineNumber(pt, ti_id); }, } } @@ -1407,6 +1413,8 @@ pub const Task = union(enum) { codegen_func: CodegenFunc, codegen_type: InternPool.Index, + update_line_number: InternPool.TrackedInst.Index, + pub const CodegenFunc = struct { /// This will either be a non-generic `func_decl` or a `func_instance`. func: InternPool.Index, @@ -1558,6 +1566,13 @@ pub fn doTask(comp: *Compilation, tid: usize, task: Task) void { error.OutOfMemory => diags.setAllocFailure(), }; }, + .update_line_number => |ti| { + const pt: Zcu.PerThread = .activate(comp.zcu.?, @enumFromInt(tid)); + defer pt.deactivate(); + pt.linkerUpdateLineNumber(ti) catch |err| switch (err) { + error.OutOfMemory => diags.setAllocFailure(), + }; + }, } } -- cgit v1.2.3