aboutsummaryrefslogtreecommitdiff
path: root/src/InternPool.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-06-20 13:42:25 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2023-06-20 14:02:09 -0400
commit6b56f4ff0bf9ac9c5e0b4a11cf0536472447bc4a (patch)
tree033edcdf8ec8f2570d874f15040d4fc9258df71e /src/InternPool.zig
parentd69e324eae6d245a4b0c75c0a8ce91275dfcc938 (diff)
downloadzig-6b56f4ff0bf9ac9c5e0b4a11cf0536472447bc4a.tar.gz
zig-6b56f4ff0bf9ac9c5e0b4a11cf0536472447bc4a.zip
Value: optimize `isPtrToThreadLocal`
Diffstat (limited to 'src/InternPool.zig')
-rw-r--r--src/InternPool.zig24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig
index 7cddfef693..bece6dbc4a 100644
--- a/src/InternPool.zig
+++ b/src/InternPool.zig
@@ -5706,6 +5706,30 @@ pub fn isRuntimeValue(ip: *const InternPool, val: Index) bool {
return ip.items.items(.tag)[@intFromEnum(val)] == .runtime_value;
}
+pub fn getBackingDecl(ip: *const InternPool, val: Index) Module.Decl.OptionalIndex {
+ var base = @intFromEnum(val);
+ while (true) {
+ switch (ip.items.items(.tag)[base]) {
+ inline .ptr_decl,
+ .ptr_mut_decl,
+ => |tag| return @enumFromInt(Module.Decl.OptionalIndex, ip.extra.items[
+ ip.items.items(.data)[base] + std.meta.fieldIndex(tag.Payload(), "decl").?
+ ]),
+ 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 .none,
+ }
+ }
+}
+
/// 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 {