aboutsummaryrefslogtreecommitdiff
path: root/src/InternPool.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2023-05-20 18:24:42 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-06-10 20:47:54 -0700
commitcbf304d8c3f7f1e1746a98dcad979ecf79ed16b5 (patch)
tree73a9f0ed31ee0f1df66215d494f8d32cb640e828 /src/InternPool.zig
parent25cd4bb3c9220e308cae9956dc4f579c66bf175a (diff)
downloadzig-cbf304d8c3f7f1e1746a98dcad979ecf79ed16b5.tar.gz
zig-cbf304d8c3f7f1e1746a98dcad979ecf79ed16b5.zip
InternPool: fix coersion issues
Diffstat (limited to 'src/InternPool.zig')
-rw-r--r--src/InternPool.zig16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig
index 5a7500cafd..837dc96daf 100644
--- a/src/InternPool.zig
+++ b/src/InternPool.zig
@@ -2584,9 +2584,9 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
.extern_func => @panic("TODO"),
- .ptr => |ptr| switch (ip.items.items(.tag)[@enumToInt(ptr.ty)]) {
- .type_pointer => {
- assert(ptr.len == .none);
+ .ptr => |ptr| switch (ptr.len) {
+ .none => {
+ assert(ip.indexToKey(ptr.ty).ptr_type.size != .Slice);
switch (ptr.addr) {
.@"var" => |@"var"| ip.items.appendAssumeCapacity(.{
.tag = .ptr_var,
@@ -2626,11 +2626,12 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
}),
}
},
- .type_slice => {
- assert(ptr.len != .none);
+ else => {
+ assert(ip.indexToKey(ptr.ty).ptr_type.size == .Slice);
var new_key = key;
- new_key.ptr.ty = @intToEnum(Index, ip.items.items(.data)[@enumToInt(ptr.ty)]);
+ new_key.ptr.ty = ip.slicePtrType(ptr.ty);
new_key.ptr.len = .none;
+ assert(ip.indexToKey(new_key.ptr.ty).ptr_type.size == .Many);
const ptr_index = try get(ip, gpa, new_key);
try ip.items.ensureUnusedCapacity(gpa, 1);
ip.items.appendAssumeCapacity(.{
@@ -2641,7 +2642,6 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
}),
});
},
- else => unreachable,
},
.opt => |opt| {
@@ -3465,10 +3465,12 @@ pub fn sliceLen(ip: InternPool, i: Index) Index {
/// Given an existing value, returns the same value but with the supplied type.
/// Only some combinations are allowed:
+/// * identity coercion
/// * int <=> int
/// * int <=> enum
/// * ptr <=> ptr
pub fn getCoerced(ip: *InternPool, gpa: Allocator, val: Index, new_ty: Index) Allocator.Error!Index {
+ if (ip.typeOf(val) == new_ty) return val;
switch (ip.indexToKey(val)) {
.int => |int| switch (ip.indexToKey(new_ty)) {
.enum_type => return ip.get(gpa, .{ .enum_tag = .{