compiler: rename AnalSubject to AnalUnit

I meant to call it this originally, I just got mixed up -- sorry!
This commit is contained in:
mlugg 2024-06-27 23:21:44 +01:00
parent d9f1a952b8
commit bc8cd13598
No known key found for this signature in database
GPG Key ID: 3F5B7DCCBF4AF02E
4 changed files with 54 additions and 54 deletions

View File

@ -3494,7 +3494,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
.{@errorName(err)},
));
decl.analysis = .codegen_failure;
try module.retryable_failures.append(gpa, InternPool.AnalSubject.wrap(.{ .decl = decl_index }));
try module.retryable_failures.append(gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }));
};
},
.analyze_mod => |pkg| {

View File

@ -81,7 +81,7 @@ namespace_name_deps: std.AutoArrayHashMapUnmanaged(NamespaceNameKey, DepEntry.In
/// Given a `Depender`, points to an entry in `dep_entries` whose `depender`
/// matches. The `next_dependee` field can be used to iterate all such entries
/// and remove them from the corresponding lists.
first_dependency: std.AutoArrayHashMapUnmanaged(AnalSubject, DepEntry.Index) = .{},
first_dependency: std.AutoArrayHashMapUnmanaged(AnalUnit, DepEntry.Index) = .{},
/// Stores dependency information. The hashmaps declared above are used to look
/// up entries in this list as required. This is not stored in `extra` so that
@ -132,36 +132,36 @@ pub fn trackZir(ip: *InternPool, gpa: Allocator, file: *Module.File, inst: Zir.I
return @enumFromInt(gop.index);
}
/// Analysis Subject. Represents a single entity which undergoes semantic analysis.
/// Analysis Unit. Represents a single entity which undergoes semantic analysis.
/// This is either a `Decl` (in future `Cau`) or a runtime function.
/// The LSB is used as a tag bit.
/// This is the "source" of an incremental dependency edge.
pub const AnalSubject = packed struct(u32) {
pub const AnalUnit = packed struct(u32) {
kind: enum(u1) { decl, func },
index: u31,
pub const Unwrapped = union(enum) {
decl: DeclIndex,
func: InternPool.Index,
};
pub fn unwrap(as: AnalSubject) Unwrapped {
pub fn unwrap(as: AnalUnit) Unwrapped {
return switch (as.kind) {
.decl => .{ .decl = @enumFromInt(as.index) },
.func => .{ .func = @enumFromInt(as.index) },
};
}
pub fn wrap(raw: Unwrapped) AnalSubject {
pub fn wrap(raw: Unwrapped) AnalUnit {
return switch (raw) {
.decl => |decl| .{ .kind = .decl, .index = @intCast(@intFromEnum(decl)) },
.func => |func| .{ .kind = .func, .index = @intCast(@intFromEnum(func)) },
};
}
pub fn toOptional(as: AnalSubject) Optional {
pub fn toOptional(as: AnalUnit) Optional {
return @enumFromInt(@as(u32, @bitCast(as)));
}
pub const Optional = enum(u32) {
none = std.math.maxInt(u32),
_,
pub fn unwrap(opt: Optional) ?AnalSubject {
pub fn unwrap(opt: Optional) ?AnalUnit {
return switch (opt) {
.none => null,
_ => @bitCast(@intFromEnum(opt)),
@ -178,7 +178,7 @@ pub const Dependee = union(enum) {
namespace_name: NamespaceNameKey,
};
pub fn removeDependenciesForDepender(ip: *InternPool, gpa: Allocator, depender: AnalSubject) void {
pub fn removeDependenciesForDepender(ip: *InternPool, gpa: Allocator, depender: AnalUnit) void {
var opt_idx = (ip.first_dependency.fetchSwapRemove(depender) orelse return).value.toOptional();
while (opt_idx.unwrap()) |idx| {
@ -207,7 +207,7 @@ pub fn removeDependenciesForDepender(ip: *InternPool, gpa: Allocator, depender:
pub const DependencyIterator = struct {
ip: *const InternPool,
next_entry: DepEntry.Index.Optional,
pub fn next(it: *DependencyIterator) ?AnalSubject {
pub fn next(it: *DependencyIterator) ?AnalUnit {
const idx = it.next_entry.unwrap() orelse return null;
const entry = it.ip.dep_entries.items[@intFromEnum(idx)];
it.next_entry = entry.next;
@ -236,7 +236,7 @@ pub fn dependencyIterator(ip: *const InternPool, dependee: Dependee) DependencyI
};
}
pub fn addDependency(ip: *InternPool, gpa: Allocator, depender: AnalSubject, dependee: Dependee) Allocator.Error!void {
pub fn addDependency(ip: *InternPool, gpa: Allocator, depender: AnalUnit, dependee: Dependee) Allocator.Error!void {
const first_depender_dep: DepEntry.Index.Optional = if (ip.first_dependency.get(depender)) |idx| dep: {
// The entry already exists, so there is capacity to overwrite it later.
break :dep idx.toOptional();
@ -300,7 +300,7 @@ pub const DepEntry = extern struct {
/// the first and only entry in one of `intern_pool.*_deps`, and does not
/// appear in any list by `first_dependency`, but is not in
/// `free_dep_entries` since `*_deps` stores a reference to it.
depender: AnalSubject.Optional,
depender: AnalUnit.Optional,
/// Index into `dep_entries` forming a doubly linked list of all dependencies on this dependee.
/// Used to iterate all dependers for a given dependee during an update.
/// null if this is the end of the list.

View File

@ -2735,12 +2735,12 @@ fn maybeRemoveOutdatedType(sema: *Sema, ty: InternPool.Index) !bool {
if (!zcu.comp.debug_incremental) return false;
const decl_index = Type.fromInterned(ty).getOwnerDecl(zcu);
const decl_as_depender = InternPool.AnalSubject.wrap(.{ .decl = decl_index });
const decl_as_depender = InternPool.AnalUnit.wrap(.{ .decl = decl_index });
const was_outdated = zcu.outdated.swapRemove(decl_as_depender) or
zcu.potentially_outdated.swapRemove(decl_as_depender);
if (!was_outdated) return false;
_ = zcu.outdated_ready.swapRemove(decl_as_depender);
zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, InternPool.AnalSubject.wrap(.{ .decl = decl_index }));
zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }));
zcu.intern_pool.remove(ty);
zcu.declPtr(decl_index).analysis = .dependency_failure;
try zcu.markDependeeOutdated(.{ .decl_val = decl_index });
@ -2834,7 +2834,7 @@ fn zirStructDecl(
if (sema.mod.comp.debug_incremental) {
try ip.addDependency(
sema.gpa,
InternPool.AnalSubject.wrap(.{ .decl = new_decl_index }),
InternPool.AnalUnit.wrap(.{ .decl = new_decl_index }),
.{ .src_hash = try ip.trackZir(sema.gpa, block.getFileScope(mod), inst) },
);
}
@ -3068,7 +3068,7 @@ fn zirEnumDecl(
if (sema.mod.comp.debug_incremental) {
try mod.intern_pool.addDependency(
sema.gpa,
InternPool.AnalSubject.wrap(.{ .decl = new_decl_index }),
InternPool.AnalUnit.wrap(.{ .decl = new_decl_index }),
.{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
);
}
@ -3334,7 +3334,7 @@ fn zirUnionDecl(
if (sema.mod.comp.debug_incremental) {
try mod.intern_pool.addDependency(
sema.gpa,
InternPool.AnalSubject.wrap(.{ .decl = new_decl_index }),
InternPool.AnalUnit.wrap(.{ .decl = new_decl_index }),
.{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
);
}
@ -3422,7 +3422,7 @@ fn zirOpaqueDecl(
if (sema.mod.comp.debug_incremental) {
try ip.addDependency(
gpa,
InternPool.AnalSubject.wrap(.{ .decl = new_decl_index }),
InternPool.AnalUnit.wrap(.{ .decl = new_decl_index }),
.{ .src_hash = try ip.trackZir(gpa, block.getFileScope(mod), inst) },
);
}
@ -38362,7 +38362,7 @@ pub fn declareDependency(sema: *Sema, dependee: InternPool.Dependee) !void {
return;
}
const depender = InternPool.AnalSubject.wrap(
const depender = InternPool.AnalUnit.wrap(
if (sema.owner_func_index != .none)
.{ .func = sema.owner_func_index }
else

View File

@ -139,26 +139,26 @@ global_error_set: GlobalErrorSet = .{},
/// Maximum amount of distinct error values, set by --error-limit
error_limit: ErrorInt,
/// Value is the number of PO or outdated Decls which this AnalSubject depends on.
potentially_outdated: std.AutoArrayHashMapUnmanaged(InternPool.AnalSubject, u32) = .{},
/// Value is the number of PO or outdated Decls which this AnalSubject depends on.
/// Once this value drops to 0, the AnalSubject is a candidate for re-analysis.
outdated: std.AutoArrayHashMapUnmanaged(InternPool.AnalSubject, u32) = .{},
/// This contains all `AnalSubject`s in `outdated` whose PO dependency count is 0.
/// Such `AnalSubject`s are ready for immediate re-analysis.
/// Value is the number of PO or outdated Decls which this AnalUnit depends on.
potentially_outdated: std.AutoArrayHashMapUnmanaged(InternPool.AnalUnit, u32) = .{},
/// Value is the number of PO or outdated Decls which this AnalUnit depends on.
/// Once this value drops to 0, the AnalUnit is a candidate for re-analysis.
outdated: std.AutoArrayHashMapUnmanaged(InternPool.AnalUnit, u32) = .{},
/// This contains all `AnalUnit`s in `outdated` whose PO dependency count is 0.
/// Such `AnalUnit`s are ready for immediate re-analysis.
/// See `findOutdatedToAnalyze` for details.
outdated_ready: std.AutoArrayHashMapUnmanaged(InternPool.AnalSubject, void) = .{},
outdated_ready: std.AutoArrayHashMapUnmanaged(InternPool.AnalUnit, void) = .{},
/// This contains a set of Decls which may not be in `outdated`, but are the
/// root Decls of files which have updated source and thus must be re-analyzed.
/// If such a Decl is only in this set, the struct type index may be preserved
/// (only the namespace might change). If such a Decl is also `outdated`, the
/// struct type index must be recreated.
outdated_file_root: std.AutoArrayHashMapUnmanaged(Decl.Index, void) = .{},
/// This contains a list of AnalSubject whose analysis or codegen failed, but the
/// This contains a list of AnalUnit whose analysis or codegen failed, but the
/// failure was something like running out of disk space, and trying again may
/// succeed. On the next update, we will flush this list, marking all members of
/// it as outdated.
retryable_failures: std.ArrayListUnmanaged(InternPool.AnalSubject) = .{},
retryable_failures: std.ArrayListUnmanaged(InternPool.AnalUnit) = .{},
stage1_flags: packed struct {
have_winmain: bool = false,
@ -3137,9 +3137,9 @@ fn markPoDependeeUpToDate(zcu: *Zcu, dependee: InternPool.Dependee) !void {
}
}
/// Given a AnalSubject which is newly outdated or PO, mark all AnalSubjects which may
/// in turn be PO, due to a dependency on the original AnalSubject's tyval or IES.
fn markTransitiveDependersPotentiallyOutdated(zcu: *Zcu, maybe_outdated: InternPool.AnalSubject) !void {
/// Given a AnalUnit which is newly outdated or PO, mark all AnalUnits which may
/// in turn be PO, due to a dependency on the original AnalUnit's tyval or IES.
fn markTransitiveDependersPotentiallyOutdated(zcu: *Zcu, maybe_outdated: InternPool.AnalUnit) !void {
var it = zcu.intern_pool.dependencyIterator(switch (maybe_outdated.unwrap()) {
.decl => |decl_index| .{ .decl_val = decl_index }, // TODO: also `decl_ref` deps when introduced
.func => |func_index| .{ .func_ies = func_index },
@ -3161,12 +3161,12 @@ fn markTransitiveDependersPotentiallyOutdated(zcu: *Zcu, maybe_outdated: InternP
continue;
}
try zcu.potentially_outdated.putNoClobber(zcu.gpa, po, 1);
// This AnalSubject was not already PO, so we must recursively mark its dependers as also PO.
// This AnalUnit was not already PO, so we must recursively mark its dependers as also PO.
try zcu.markTransitiveDependersPotentiallyOutdated(po);
}
}
pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.AnalSubject {
pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.AnalUnit {
if (!zcu.comp.debug_incremental) return null;
if (zcu.outdated.count() == 0 and zcu.potentially_outdated.count() == 0) {
@ -3174,8 +3174,8 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.AnalSubject
return null;
}
// Our goal is to find an outdated AnalSubject which itself has no outdated or
// PO dependencies. Most of the time, such an AnalSubject will exist - we track
// Our goal is to find an outdated AnalUnit which itself has no outdated or
// PO dependencies. Most of the time, such an AnalUnit will exist - we track
// them in the `outdated_ready` set for efficiency. However, this is not
// necessarily the case, since the Decl dependency graph may contain loops
// via mutually recursive definitions:
@ -3197,7 +3197,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.AnalSubject
// `outdated`. This set will be small (number of files changed in this
// update), so it's alright for us to just iterate here.
for (zcu.outdated_file_root.keys()) |file_decl| {
const decl_depender = InternPool.AnalSubject.wrap(.{ .decl = file_decl });
const decl_depender = InternPool.AnalUnit.wrap(.{ .decl = file_decl });
if (zcu.outdated.contains(decl_depender)) {
// Since we didn't hit this in the first loop, this Decl must have
// pending dependencies, so is ineligible.
@ -3213,7 +3213,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.AnalSubject
return decl_depender;
}
// There is no single AnalSubject which is ready for re-analysis. Instead, we
// There is no single AnalUnit which is ready for re-analysis. Instead, we
// must assume that some Decl with PO dependencies is outdated - e.g. in the
// above example we arbitrarily pick one of A or B. We should select a Decl,
// since a Decl is definitely responsible for the loop in the dependency
@ -3221,7 +3221,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.AnalSubject
// The choice of this Decl could have a big impact on how much total
// analysis we perform, since if analysis concludes its tyval is unchanged,
// then other PO AnalSubject may be resolved as up-to-date. To hopefully avoid
// then other PO AnalUnit may be resolved as up-to-date. To hopefully avoid
// doing too much work, let's find a Decl which the most things depend on -
// the idea is that this will resolve a lot of loops (but this is only a
// heuristic).
@ -3271,7 +3271,7 @@ pub fn findOutdatedToAnalyze(zcu: *Zcu) Allocator.Error!?InternPool.AnalSubject
chosen_decl_dependers,
});
return InternPool.AnalSubject.wrap(.{ .decl = chosen_decl_idx.? });
return InternPool.AnalUnit.wrap(.{ .decl = chosen_decl_idx.? });
}
/// During an incremental update, before semantic analysis, call this to flush all values from
@ -3281,12 +3281,12 @@ pub fn flushRetryableFailures(zcu: *Zcu) !void {
for (zcu.retryable_failures.items) |depender| {
if (zcu.outdated.contains(depender)) continue;
if (zcu.potentially_outdated.fetchSwapRemove(depender)) |kv| {
// This AnalSubject was already PO, but we now consider it outdated.
// This AnalUnit was already PO, but we now consider it outdated.
// Any transitive dependencies are already marked PO.
try zcu.outdated.put(gpa, depender, kv.value);
continue;
}
// This AnalSubject was not marked PO, but is now outdated. Mark it as
// This AnalUnit was not marked PO, but is now outdated. Mark it as
// such, then recursively mark transitive dependencies as PO.
try zcu.outdated.put(gpa, depender, 0);
try zcu.markTransitiveDependersPotentiallyOutdated(depender);
@ -3456,7 +3456,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
// which tries to limit re-analysis to Decls whose previously listed
// dependencies are all up-to-date.
const decl_as_depender = InternPool.AnalSubject.wrap(.{ .decl = decl_index });
const decl_as_depender = InternPool.AnalUnit.wrap(.{ .decl = decl_index });
const decl_was_outdated = mod.outdated.swapRemove(decl_as_depender) or
mod.potentially_outdated.swapRemove(decl_as_depender);
@ -3522,7 +3522,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
else => |e| {
decl.analysis = .sema_failure;
try mod.failed_decls.ensureUnusedCapacity(mod.gpa, 1);
try mod.retryable_failures.append(mod.gpa, InternPool.AnalSubject.wrap(.{ .decl = decl_index }));
try mod.retryable_failures.append(mod.gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }));
mod.failed_decls.putAssumeCapacityNoClobber(decl_index, try ErrorMsg.create(
mod.gpa,
decl.navSrcLoc(mod).upgrade(mod),
@ -3581,7 +3581,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
// that's the case, we should remove this function from the binary.
if (decl.val.ip_index != func_index) {
try zcu.markDependeeOutdated(.{ .func_ies = func_index });
ip.removeDependenciesForDepender(gpa, InternPool.AnalSubject.wrap(.{ .func = func_index }));
ip.removeDependenciesForDepender(gpa, InternPool.AnalUnit.wrap(.{ .func = func_index }));
ip.remove(func_index);
@panic("TODO: remove orphaned function from binary");
}
@ -3607,7 +3607,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
.complete => {},
}
const func_as_depender = InternPool.AnalSubject.wrap(.{ .func = func_index });
const func_as_depender = InternPool.AnalUnit.wrap(.{ .func = func_index });
const was_outdated = zcu.outdated.swapRemove(func_as_depender) or
zcu.potentially_outdated.swapRemove(func_as_depender);
@ -3728,7 +3728,7 @@ pub fn ensureFuncBodyAnalyzed(zcu: *Zcu, maybe_coerced_func_index: InternPool.In
.{@errorName(err)},
));
func.analysis(ip).state = .codegen_failure;
try zcu.retryable_failures.append(zcu.gpa, InternPool.AnalSubject.wrap(.{ .func = func_index }));
try zcu.retryable_failures.append(zcu.gpa, InternPool.AnalUnit.wrap(.{ .func = func_index }));
},
};
} else if (zcu.llvm_object) |llvm_object| {
@ -3773,7 +3773,7 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index)
assert(decl.has_tv);
const func_as_depender = InternPool.AnalSubject.wrap(.{ .func = func_index });
const func_as_depender = InternPool.AnalUnit.wrap(.{ .func = func_index });
const is_outdated = mod.outdated.contains(func_as_depender) or
mod.potentially_outdated.contains(func_as_depender);
@ -3857,7 +3857,7 @@ fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespa
if (zcu.comp.debug_incremental) {
try ip.addDependency(
gpa,
InternPool.AnalSubject.wrap(.{ .decl = decl_index }),
InternPool.AnalUnit.wrap(.{ .decl = decl_index }),
.{ .src_hash = tracked_inst },
);
}
@ -3906,7 +3906,7 @@ fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool {
if (type_outdated) {
// Invalidate the existing type, reusing the decl and namespace.
zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, InternPool.AnalSubject.wrap(.{ .decl = file.root_decl.unwrap().? }));
zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, InternPool.AnalUnit.wrap(.{ .decl = file.root_decl.unwrap().? }));
zcu.intern_pool.remove(decl.val.toIntern());
decl.val = undefined;
_ = try zcu.getFileRootStruct(file.root_decl.unwrap().?, decl.src_namespace, file);
@ -4097,7 +4097,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
break :ip_index .none;
};
mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.AnalSubject.wrap(.{ .decl = decl_index }));
mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }));
decl.analysis = .in_progress;
@ -4323,7 +4323,7 @@ fn semaAnonOwnerDecl(zcu: *Zcu, decl_index: Decl.Index) !SemaDeclResult {
// with a new Decl.
//
// Yes, this does mean that any type owner Decl has a constant value for its entire lifetime.
zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, InternPool.AnalSubject.wrap(.{ .decl = decl_index }));
zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }));
zcu.intern_pool.remove(decl.val.toIntern());
decl.analysis = .dependency_failure;
return .{
@ -5026,7 +5026,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
const decl_prog_node = mod.sema_prog_node.start((try decl.fullyQualifiedName(mod)).toSlice(ip), 0);
defer decl_prog_node.end();
mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.AnalSubject.wrap(.{ .func = func_index }));
mod.intern_pool.removeDependenciesForDepender(gpa, InternPool.AnalUnit.wrap(.{ .func = func_index }));
var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
defer comptime_err_ret_trace.deinit();
@ -5627,7 +5627,7 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {
.{@errorName(err)},
));
decl.analysis = .codegen_failure;
try zcu.retryable_failures.append(zcu.gpa, InternPool.AnalSubject.wrap(.{ .decl = decl_index }));
try zcu.retryable_failures.append(zcu.gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }));
},
};
} else if (zcu.llvm_object) |llvm_object| {