diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-07-04 20:12:05 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-04 20:12:05 -0400 |
| commit | 790b8428a26457e7ed9ea20485b9d3085011b989 (patch) | |
| tree | 3d27f81e31d73af526e8a972504325fa1cb0d9e1 /src/InternPool.zig | |
| parent | de61540c2d049b0774dd9c5e14aa8f65ed1c25ed (diff) | |
| parent | cda6f552d5d4a996df69981dac7c9d9b3c066537 (diff) | |
| download | zig-790b8428a26457e7ed9ea20485b9d3085011b989.tar.gz zig-790b8428a26457e7ed9ea20485b9d3085011b989.zip | |
Merge pull request #20494 from mlugg/the-great-decl-split
refactors ad infinitum
Diffstat (limited to 'src/InternPool.zig')
| -rw-r--r-- | src/InternPool.zig | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig index cf56550c25..c6b27acaf3 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(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. |
