aboutsummaryrefslogtreecommitdiff
path: root/src/InternPool.zig
diff options
context:
space:
mode:
authorJacob Young <jacobly0@users.noreply.github.com>2025-05-30 00:22:45 -0400
committerJacob Young <jacobly0@users.noreply.github.com>2025-05-31 18:54:28 -0400
commitb483defc5a5c2f93eb8a445974ab831ae4e4b321 (patch)
tree0fa6fa6721e8731b294f8aafed6ca8f02a0242ae /src/InternPool.zig
parentc1e9ef9eaabb2219a3762c5957b1c63ad20bf1ed (diff)
downloadzig-b483defc5a5c2f93eb8a445974ab831ae4e4b321.tar.gz
zig-b483defc5a5c2f93eb8a445974ab831ae4e4b321.zip
Legalize: implement scalarization of binary operations
Diffstat (limited to 'src/InternPool.zig')
-rw-r--r--src/InternPool.zig84
1 files changed, 60 insertions, 24 deletions
diff --git a/src/InternPool.zig b/src/InternPool.zig
index f5fb33ede9..44f19e3e29 100644
--- a/src/InternPool.zig
+++ b/src/InternPool.zig
@@ -4579,10 +4579,11 @@ pub const Index = enum(u32) {
undefined_type,
enum_literal_type,
+ ptr_usize_type,
+ ptr_const_comptime_int_type,
manyptr_u8_type,
manyptr_const_u8_type,
manyptr_const_u8_sentinel_0_type,
- single_const_pointer_to_comptime_int_type,
slice_const_u8_type,
slice_const_u8_sentinel_0_type,
@@ -4649,19 +4650,29 @@ pub const Index = enum(u32) {
/// `undefined` (untyped)
undef,
+ /// `@as(bool, undefined)`
+ undef_bool,
+ /// `@as(usize, undefined)`
+ undef_usize,
+ /// `@as(u1, undefined)`
+ undef_u1,
/// `0` (comptime_int)
zero,
- /// `0` (usize)
+ /// `@as(usize, 0)`
zero_usize,
- /// `0` (u8)
+ /// `@as(u1, 0)`
+ zero_u1,
+ /// `@as(u8, 0)`
zero_u8,
/// `1` (comptime_int)
one,
- /// `1` (usize)
+ /// `@as(usize, 1)`
one_usize,
- /// `1` (u8)
+ /// `@as(u1, 1)`
+ one_u1,
+ /// `@as(u8, 1)`
one_u8,
- /// `4` (u8)
+ /// `@as(u8, 4)`
four_u8,
/// `-1` (comptime_int)
negative_one,
@@ -5074,6 +5085,20 @@ pub const static_keys: [static_len]Key = .{
.{ .simple_type = .undefined },
.{ .simple_type = .enum_literal },
+ // *usize
+ .{ .ptr_type = .{
+ .child = .usize_type,
+ .flags = .{},
+ } },
+
+ // *const comptime_int
+ .{ .ptr_type = .{
+ .child = .comptime_int_type,
+ .flags = .{
+ .is_const = true,
+ },
+ } },
+
// [*]u8
.{ .ptr_type = .{
.child = .u8_type,
@@ -5101,15 +5126,6 @@ pub const static_keys: [static_len]Key = .{
},
} },
- // *const comptime_int
- .{ .ptr_type = .{
- .child = .comptime_int_type,
- .flags = .{
- .size = .one,
- .is_const = true,
- },
- } },
-
// []const u8
.{ .ptr_type = .{
.child = .u8_type,
@@ -5245,6 +5261,9 @@ pub const static_keys: [static_len]Key = .{
} },
.{ .simple_value = .undefined },
+ .{ .undef = .bool_type },
+ .{ .undef = .usize_type },
+ .{ .undef = .u1_type },
.{ .int = .{
.ty = .comptime_int_type,
@@ -5257,6 +5276,11 @@ pub const static_keys: [static_len]Key = .{
} },
.{ .int = .{
+ .ty = .u1_type,
+ .storage = .{ .u64 = 0 },
+ } },
+
+ .{ .int = .{
.ty = .u8_type,
.storage = .{ .u64 = 0 },
} },
@@ -5271,17 +5295,21 @@ pub const static_keys: [static_len]Key = .{
.storage = .{ .u64 = 1 },
} },
- // one_u8
+ .{ .int = .{
+ .ty = .u1_type,
+ .storage = .{ .u64 = 1 },
+ } },
+
.{ .int = .{
.ty = .u8_type,
.storage = .{ .u64 = 1 },
} },
- // four_u8
+
.{ .int = .{
.ty = .u8_type,
.storage = .{ .u64 = 4 },
} },
- // negative_one
+
.{ .int = .{
.ty = .comptime_int_type,
.storage = .{ .i64 = -1 },
@@ -10482,7 +10510,7 @@ pub fn getCoerced(
.base_addr = .int,
.byte_offset = 0,
} }),
- .len = try ip.get(gpa, tid, .{ .undef = .usize_type }),
+ .len = .undef_usize,
} }),
};
},
@@ -10601,7 +10629,7 @@ pub fn getCoerced(
.base_addr = .int,
.byte_offset = 0,
} }),
- .len = try ip.get(gpa, tid, .{ .undef = .usize_type }),
+ .len = .undef_usize,
} }),
},
else => |payload| try ip.getCoerced(gpa, tid, payload, new_ty),
@@ -11847,10 +11875,11 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
.null_type,
.undefined_type,
.enum_literal_type,
+ .ptr_usize_type,
+ .ptr_const_comptime_int_type,
.manyptr_u8_type,
.manyptr_const_u8_type,
.manyptr_const_u8_sentinel_0_type,
- .single_const_pointer_to_comptime_int_type,
.slice_const_u8_type,
.slice_const_u8_sentinel_0_type,
.vector_8_i8_type,
@@ -11909,12 +11938,13 @@ pub fn typeOf(ip: *const InternPool, index: Index) Index {
.undef => .undefined_type,
.zero, .one, .negative_one => .comptime_int_type,
- .zero_usize, .one_usize => .usize_type,
+ .undef_usize, .zero_usize, .one_usize => .usize_type,
+ .undef_u1, .zero_u1, .one_u1 => .u1_type,
.zero_u8, .one_u8, .four_u8 => .u8_type,
.void_value => .void_type,
.unreachable_value => .noreturn_type,
.null_value => .null_type,
- .bool_true, .bool_false => .bool_type,
+ .undef_bool, .bool_true, .bool_false => .bool_type,
.empty_tuple => .empty_tuple_type,
// This optimization on tags is needed so that indexToKey can call
@@ -12186,10 +12216,11 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
.undefined_type => .undefined,
.enum_literal_type => .enum_literal,
+ .ptr_usize_type,
+ .ptr_const_comptime_int_type,
.manyptr_u8_type,
.manyptr_const_u8_type,
.manyptr_const_u8_sentinel_0_type,
- .single_const_pointer_to_comptime_int_type,
.slice_const_u8_type,
.slice_const_u8_sentinel_0_type,
=> .pointer,
@@ -12251,11 +12282,16 @@ pub fn zigTypeTag(ip: *const InternPool, index: Index) std.builtin.TypeId {
// values, not types
.undef => unreachable,
+ .undef_bool => unreachable,
+ .undef_usize => unreachable,
+ .undef_u1 => unreachable,
.zero => unreachable,
.zero_usize => unreachable,
+ .zero_u1 => unreachable,
.zero_u8 => unreachable,
.one => unreachable,
.one_usize => unreachable,
+ .one_u1 => unreachable,
.one_u8 => unreachable,
.four_u8 => unreachable,
.negative_one => unreachable,