diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2025-01-01 20:16:48 +0000 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2025-01-05 02:20:56 +0000 |
| commit | 065e10c95ccca509afecfecc849da9114e0000b2 (patch) | |
| tree | bd1c4bee8e3da377fa1da9254b442900c538a45d /src/link.zig | |
| parent | 136c5a916ed7e421461ac5839cc0e4c289b80f16 (diff) | |
| download | zig-065e10c95ccca509afecfecc849da9114e0000b2.tar.gz zig-065e10c95ccca509afecfecc849da9114e0000b2.zip | |
link: new incremental line number update API
Diffstat (limited to 'src/link.zig')
| -rw-r--r-- | src/link.zig | 27 |
1 files changed, 21 insertions, 6 deletions
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(), + }; + }, } } |
