aboutsummaryrefslogtreecommitdiff
path: root/src/InternPool.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-08-15 15:20:21 -0700
committerGitHub <noreply@github.com>2023-08-15 15:20:21 -0700
commit340a45683ca8e0b23e95f5fb86bd9c827970e6e8 (patch)
tree222c5820345cb119a2c6262855ad372cd1d19aaa /src/InternPool.zig
parentfdce18cd30a5f20688e582386b802ed8e9a46312 (diff)
parent083ee8e0e28ed0d1c4e1df6b5aa12f2709731b50 (diff)
downloadzig-340a45683ca8e0b23e95f5fb86bd9c827970e6e8.tar.gz
zig-340a45683ca8e0b23e95f5fb86bd9c827970e6e8.zip
Merge pull request #16815 from mlugg/internpool-same-resolved-index
InternPool: preserve indices of builtin types when resolved
Diffstat (limited to 'src/InternPool.zig')
-rw-r--r--src/InternPool.zig30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig
index 178bc6870c..bde6c11256 100644
--- a/src/InternPool.zig
+++ b/src/InternPool.zig
@@ -7176,3 +7176,33 @@ fn unwrapCoercedFunc(ip: *const InternPool, i: Index) Index {
else => unreachable,
};
}
+
+/// Having resolved a builtin type to a real struct/union/enum (which is now at `resolverd_index`),
+/// make `want_index` refer to this type instead. This invalidates `resolved_index`, so must be
+/// called only when it is guaranteed that no reference to `resolved_index` exists.
+pub fn resolveBuiltinType(ip: *InternPool, want_index: Index, resolved_index: Index) void {
+ assert(@intFromEnum(want_index) >= @intFromEnum(Index.first_type));
+ assert(@intFromEnum(want_index) <= @intFromEnum(Index.last_type));
+
+ // Make sure the type isn't already resolved!
+ assert(ip.indexToKey(want_index) == .simple_type);
+
+ // Make sure it's the same kind of type
+ assert((ip.zigTypeTagOrPoison(want_index) catch unreachable) ==
+ (ip.zigTypeTagOrPoison(resolved_index) catch unreachable));
+
+ // Copy the data
+ const item = ip.items.get(@intFromEnum(resolved_index));
+ ip.items.set(@intFromEnum(want_index), item);
+
+ if (std.debug.runtime_safety) {
+ // Make the value unreachable - this is a weird value which will make (incorrect) existing
+ // references easier to spot
+ ip.items.set(@intFromEnum(resolved_index), .{
+ .tag = .simple_value,
+ .data = @intFromEnum(SimpleValue.@"unreachable"),
+ });
+ } else {
+ // TODO: add the index to a free-list for reuse
+ }
+}