diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-06-24 15:40:23 +0100 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-06-26 05:28:04 +0100 |
| commit | 4cb5318088b2eb66891f0d83b76a2740644b4156 (patch) | |
| tree | 87e9ae619d448ae4252931ba20393198f47dddc0 /src/InternPool.zig | |
| parent | 5b523d04690d8a01cb5d97e4f5a35443cb0cbde8 (diff) | |
| download | zig-4cb5318088b2eb66891f0d83b76a2740644b4156.tar.gz zig-4cb5318088b2eb66891f0d83b76a2740644b4156.zip | |
InternPool: rename `Depender` to `AnalSubject`
This is essentially just a rename. I also changed the representation of
`AnalSubject` to use a `packed struct` rather than a non-exhaustive
enum, but that change is relatively trivial.
Diffstat (limited to 'src/InternPool.zig')
| -rw-r--r-- | src/InternPool.zig | 50 |
1 files changed, 25 insertions, 25 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig index 4268a84f37..cf56550c25 100644 --- a/src/InternPool.zig +++ b/src/InternPool.zig @@ -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(Depender, DepEntry.Index) = .{}, +first_dependency: std.AutoArrayHashMapUnmanaged(AnalSubject, 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,39 +132,39 @@ pub fn trackZir(ip: *InternPool, gpa: Allocator, file: *Module.File, inst: Zir.I return @enumFromInt(gop.index); } -/// Reperesents the "source" of a dependency edge, i.e. either a Decl or a -/// runtime function (represented as an InternPool index). -/// MSB is 0 for a Decl, 1 for a function. -pub const Depender = enum(u32) { - _, +/// Analysis Subject. 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) { + kind: enum(u1) { decl, func }, + index: u31, pub const Unwrapped = union(enum) { decl: DeclIndex, func: InternPool.Index, }; - pub fn unwrap(dep: Depender) Unwrapped { - const tag: u1 = @truncate(@intFromEnum(dep) >> 31); - const val: u31 = @truncate(@intFromEnum(dep)); - return switch (tag) { - 0 => .{ .decl = @enumFromInt(val) }, - 1 => .{ .func = @enumFromInt(val) }, + pub fn unwrap(as: AnalSubject) Unwrapped { + return switch (as.kind) { + .decl => .{ .decl = @enumFromInt(as.index) }, + .func => .{ .func = @enumFromInt(as.index) }, }; } - pub fn wrap(raw: Unwrapped) Depender { - return @enumFromInt(switch (raw) { - .decl => |decl| @intFromEnum(decl), - .func => |func| (1 << 31) | @intFromEnum(func), - }); + pub fn wrap(raw: Unwrapped) AnalSubject { + return switch (raw) { + .decl => |decl| .{ .kind = .decl, .index = @intCast(@intFromEnum(decl)) }, + .func => |func| .{ .kind = .func, .index = @intCast(@intFromEnum(func)) }, + }; } - pub fn toOptional(dep: Depender) Optional { - return @enumFromInt(@intFromEnum(dep)); + pub fn toOptional(as: AnalSubject) Optional { + return @enumFromInt(@as(u32, @bitCast(as))); } pub const Optional = enum(u32) { none = std.math.maxInt(u32), _, - pub fn unwrap(opt: Optional) ?Depender { + pub fn unwrap(opt: Optional) ?AnalSubject { return switch (opt) { .none => null, - _ => @enumFromInt(@intFromEnum(opt)), + _ => @bitCast(@intFromEnum(opt)), }; } }; @@ -178,7 +178,7 @@ pub const Dependee = union(enum) { namespace_name: NamespaceNameKey, }; -pub fn removeDependenciesForDepender(ip: *InternPool, gpa: Allocator, depender: Depender) void { +pub fn removeDependenciesForDepender(ip: *InternPool, gpa: Allocator, depender: AnalSubject) 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) ?Depender { + pub fn next(it: *DependencyIterator) ?AnalSubject { 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: Depender, dependee: Dependee) Allocator.Error!void { +pub fn addDependency(ip: *InternPool, gpa: Allocator, depender: AnalSubject, 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: Depender.Optional, + depender: AnalSubject.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. |
