aboutsummaryrefslogtreecommitdiff
path: root/src/InternPool.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-06-20 13:44:24 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2023-06-20 14:02:09 -0400
commitd7bd4f339c90b9ce07283600cb7ef129912ceef3 (patch)
treeff3d181923df575edd51562397f60c93eff8d8e7 /src/InternPool.zig
parent6b56f4ff0bf9ac9c5e0b4a11cf0536472447bc4a (diff)
downloadzig-d7bd4f339c90b9ce07283600cb7ef129912ceef3.tar.gz
zig-d7bd4f339c90b9ce07283600cb7ef129912ceef3.zip
Sema: optimize value resolution
Diffstat (limited to 'src/InternPool.zig')
-rw-r--r--src/InternPool.zig33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig
index bece6dbc4a..f93539daf8 100644
--- a/src/InternPool.zig
+++ b/src/InternPool.zig
@@ -622,6 +622,8 @@ pub const Key = union(enum) {
len: Index = .none,
pub const Addr = union(enum) {
+ const Tag = @typeInfo(Addr).Union.tag_type.?;
+
decl: Module.Decl.Index,
mut_decl: MutDecl,
comptime_field: Index,
@@ -5702,10 +5704,18 @@ pub fn isNoReturn(ip: *const InternPool, ty: Index) bool {
};
}
+pub fn isUndef(ip: *const InternPool, val: Index) bool {
+ return val == .undef or ip.items.items(.tag)[@intFromEnum(val)] == .undef;
+}
+
pub fn isRuntimeValue(ip: *const InternPool, val: Index) bool {
return ip.items.items(.tag)[@intFromEnum(val)] == .runtime_value;
}
+pub fn isVariable(ip: *const InternPool, val: Index) bool {
+ return ip.items.items(.tag)[@intFromEnum(val)] == .variable;
+}
+
pub fn getBackingDecl(ip: *const InternPool, val: Index) Module.Decl.OptionalIndex {
var base = @intFromEnum(val);
while (true) {
@@ -5730,6 +5740,29 @@ pub fn getBackingDecl(ip: *const InternPool, val: Index) Module.Decl.OptionalInd
}
}
+pub fn getBackingAddrTag(ip: *const InternPool, val: Index) ?Key.Ptr.Addr.Tag {
+ var base = @intFromEnum(val);
+ while (true) {
+ switch (ip.items.items(.tag)[base]) {
+ .ptr_decl => return .decl,
+ .ptr_mut_decl => return .mut_decl,
+ .ptr_comptime_field => return .comptime_field,
+ .ptr_int => return .int,
+ inline .ptr_eu_payload,
+ .ptr_opt_payload,
+ .ptr_elem,
+ .ptr_field,
+ => |tag| base = ip.extra.items[
+ ip.items.items(.data)[base] + std.meta.fieldIndex(tag.Payload(), "base").?
+ ],
+ inline .ptr_slice => |tag| base = ip.extra.items[
+ ip.items.items(.data)[base] + std.meta.fieldIndex(tag.Payload(), "ptr").?
+ ],
+ else => return null,
+ }
+ }
+}
+
/// This is a particularly hot function, so we operate directly on encodings
/// rather than the more straightforward implementation of calling `indexToKey`.
pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPoison}!std.builtin.TypeId {