Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ci/x86_64-linux-debug.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ stage3-debug/bin/zig build \

stage3-debug/bin/zig build test docs \
--maxrss 21000000000 \
-Dlldb=$HOME/deps/lldb-zig/Debug-bfeada333/bin/lldb \
-Dlldb=$HOME/deps/lldb-zig/Debug-e0a42bb34/bin/lldb \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
Expand Down
2 changes: 1 addition & 1 deletion ci/x86_64-linux-release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ stage3-release/bin/zig build \

stage3-release/bin/zig build test docs \
--maxrss 21000000000 \
-Dlldb=$HOME/deps/lldb-zig/Release-bfeada333/bin/lldb \
-Dlldb=$HOME/deps/lldb-zig/Release-e0a42bb34/bin/lldb \
-fqemu \
-fwasmtime \
-Dstatic-llvm \
Expand Down
4 changes: 4 additions & 0 deletions src/Compilation.zig
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ const Job = union(enum) {
/// Corresponds to the task in `link.Task`.
/// Only needed for backends that haven't yet been updated to not race against Sema.
codegen_type: InternPool.Index,
update_line_number: InternPool.TrackedInst.Index,
/// The `AnalUnit`, which is *not* a `func`, must be semantically analyzed.
/// This may be its first time being analyzed, or it may be outdated.
/// If the unit is a function, a `codegen_func` job will then be queued.
Expand Down Expand Up @@ -3718,6 +3719,9 @@ fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progre
.codegen_type => |ty| {
comp.dispatchCodegenTask(tid, .{ .codegen_type = ty });
},
.update_line_number => |ti| {
comp.dispatchCodegenTask(tid, .{ .update_line_number = ti });
},
.analyze_func => |func| {
const named_frame = tracy.namedFrame("analyze_func");
defer named_frame.end();
Expand Down
8 changes: 7 additions & 1 deletion src/InternPool.zig
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ pub const TrackedInst = extern struct {
_ => @enumFromInt(@intFromEnum(opt)),
};
}

const debug_state = InternPool.debug_state;
};

pub const Unwrapped = struct {
Expand All @@ -187,6 +189,8 @@ pub const TrackedInst = extern struct {
.index = @intFromEnum(tracked_inst_index) & ip.getIndexMask(u32),
};
}

const debug_state = InternPool.debug_state;
};
};

Expand Down Expand Up @@ -508,7 +512,7 @@ pub const Nav = struct {
/// The fully-qualified name of this `Nav`.
fqn: NullTerminatedString,
/// This field is populated iff this `Nav` is resolved by semantic analysis.
/// If this is `null`, then `status == .resolved` always.
/// If this is `null`, then `status == .fully_resolved` always.
analysis: ?struct {
namespace: NamespaceIndex,
zir_index: TrackedInst.Index,
Expand Down Expand Up @@ -6631,6 +6635,8 @@ pub fn activate(ip: *const InternPool) void {
_ = OptionalString.debug_state;
_ = NullTerminatedString.debug_state;
_ = OptionalNullTerminatedString.debug_state;
_ = TrackedInst.Index.debug_state;
_ = TrackedInst.Index.Optional.debug_state;
_ = Nav.Index.debug_state;
_ = Nav.Index.Optional.debug_state;
std.debug.assert(debug_state.intern_pool == null);
Expand Down
31 changes: 25 additions & 6 deletions src/Zcu/PerThread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,7 @@ fn cleanupUpdatedFiles(gpa: Allocator, updated_files: *std.AutoArrayHashMapUnman
pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void {
assert(pt.tid == .main);
const zcu = pt.zcu;
const comp = zcu.comp;
const ip = &zcu.intern_pool;
const gpa = zcu.gpa;

Expand Down Expand Up @@ -435,8 +436,19 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void {

const old_zir = file.prev_zir.?.*;
const new_zir = file.zir;
const old_tag = old_zir.instructions.items(.tag);
const old_data = old_zir.instructions.items(.data);
const old_tag = old_zir.instructions.items(.tag)[@intFromEnum(old_inst)];
const old_data = old_zir.instructions.items(.data)[@intFromEnum(old_inst)];

switch (old_tag) {
.declaration => {
const old_line = old_zir.getDeclaration(old_inst).src_line;
const new_line = new_zir.getDeclaration(new_inst).src_line;
if (old_line != new_line) {
try comp.queueJob(.{ .update_line_number = tracked_inst_index });
}
},
else => {},
}

if (old_zir.getAssociatedSrcHash(old_inst)) |old_hash| hash_changed: {
if (new_zir.getAssociatedSrcHash(new_inst)) |new_hash| {
Expand All @@ -455,8 +467,8 @@ pub fn updateZirRefs(pt: Zcu.PerThread) Allocator.Error!void {
}

// If this is a `struct_decl` etc, we must invalidate any outdated namespace dependencies.
const has_namespace = switch (old_tag[@intFromEnum(old_inst)]) {
.extended => switch (old_data[@intFromEnum(old_inst)].extended.opcode) {
const has_namespace = switch (old_tag) {
.extended => switch (old_data.extended.opcode) {
.struct_decl, .union_decl, .opaque_decl, .enum_decl => true,
else => false,
},
Expand Down Expand Up @@ -2517,8 +2529,6 @@ const ScanDeclIter = struct {
);
try comp.queueJob(.{ .analyze_comptime_unit = unit });
}

// TODO: we used to do line number updates here, but this is an inappropriate place for this logic to live.
}
};

Expand Down Expand Up @@ -3152,6 +3162,15 @@ pub fn linkerUpdateContainerType(pt: Zcu.PerThread, ty: InternPool.Index) !void
}
}

pub fn linkerUpdateLineNumber(pt: Zcu.PerThread, ti: InternPool.TrackedInst.Index) !void {
if (pt.zcu.comp.bin_file) |lf| {
lf.updateLineNumber(pt, ti) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
else => |e| log.err("update line number failed: {s}", .{@errorName(e)}),
};
}
}

pub fn reportRetryableAstGenError(
pt: Zcu.PerThread,
src: Zcu.AstGenSrc,
Expand Down
27 changes: 21 additions & 6 deletions src/link.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
}
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(),
};
},
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/link/C.zig
Original file line number Diff line number Diff line change
Expand Up @@ -379,12 +379,12 @@ pub fn updateNav(self: *C, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) !
gop.value_ptr.fwd_decl = try self.addString(object.dg.fwd_decl.items);
}

pub fn updateNavLineNumber(self: *C, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index) !void {
pub fn updateLineNumber(self: *C, pt: Zcu.PerThread, ti_id: InternPool.TrackedInst.Index) !void {
// The C backend does not have the ability to fix line numbers without re-generating
// the entire Decl.
_ = self;
_ = pt;
_ = nav_index;
_ = ti_id;
}

pub fn flush(self: *C, arena: Allocator, tid: Zcu.PerThread.Id, prog_node: std.Progress.Node) !void {
Expand Down
6 changes: 3 additions & 3 deletions src/link/Coff.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2484,11 +2484,11 @@ pub fn getGlobalSymbol(coff: *Coff, name: []const u8, lib_name_name: ?[]const u8
return global_index;
}

pub fn updateDeclLineNumber(coff: *Coff, pt: Zcu.PerThread, decl_index: InternPool.DeclIndex) !void {
pub fn updateLineNumber(coff: *Coff, pt: Zcu.PerThread, ti_id: InternPool.TrackedInst.Index) !void {
_ = coff;
_ = pt;
_ = decl_index;
log.debug("TODO implement updateDeclLineNumber", .{});
_ = ti_id;
log.debug("TODO implement updateLineNumber", .{});
}

/// TODO: note if we need to rewrite base relocations by dirtying any of the entries in the global table
Expand Down
Loading
Loading