authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-05-25 05:47:25-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:47:54-07:00
log1a4626d2cf8b9985833f97b6fea6ea03011ada4e
tree1ca633e34a9b406ab48d5584db4159807941647e
parent6e0de1d11694a58745da76d601ebab7562feed09

InternPool: remove more legacy values

Reinstate some tags that will be needed for comptime init.

19 files changed, 2063 insertions(+), 2391 deletions(-)

src/Air.zig-7
...@@ -400,8 +400,6 @@ pub const Inst = struct {...@@ -400,8 +400,6 @@ pub const Inst = struct {
400 /// A comptime-known value. Uses the `ty_pl` field, payload is index of400 /// A comptime-known value. Uses the `ty_pl` field, payload is index of
401 /// `values` array.401 /// `values` array.
402 constant,402 constant,
403 /// A comptime-known type. Uses the `ty` field.
404 const_ty,
405 /// A comptime-known value via an index into the InternPool.403 /// A comptime-known value via an index into the InternPool.
406 /// Uses the `interned` field.404 /// Uses the `interned` field.
407 interned,405 interned,
...@@ -1257,8 +1255,6 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: InternPool) Type {...@@ -1257,8 +1255,6 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: InternPool) Type {
1257 .error_set_has_value,1255 .error_set_has_value,
1258 => return Type.bool,1256 => return Type.bool,
12591257
1260 .const_ty => return Type.type,
1261
1262 .alloc,1258 .alloc,
1263 .ret_ptr,1259 .ret_ptr,
1264 .err_return_trace,1260 .err_return_trace,
...@@ -1435,7 +1431,6 @@ pub fn getRefType(air: Air, ref: Air.Inst.Ref) Type {...@@ -1435,7 +1431,6 @@ pub fn getRefType(air: Air, ref: Air.Inst.Ref) Type {
1435 const air_tags = air.instructions.items(.tag);1431 const air_tags = air.instructions.items(.tag);
1436 const air_datas = air.instructions.items(.data);1432 const air_datas = air.instructions.items(.data);
1437 return switch (air_tags[inst_index]) {1433 return switch (air_tags[inst_index]) {
1438 .const_ty => air_datas[inst_index].ty,
1439 .interned => air_datas[inst_index].interned.toType(),1434 .interned => air_datas[inst_index].interned.toType(),
1440 else => unreachable,1435 else => unreachable,
1441 };1436 };
...@@ -1501,7 +1496,6 @@ pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {...@@ -1501,7 +1496,6 @@ pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {
1501 const air_datas = air.instructions.items(.data);1496 const air_datas = air.instructions.items(.data);
1502 switch (air.instructions.items(.tag)[inst_index]) {1497 switch (air.instructions.items(.tag)[inst_index]) {
1503 .constant => return air.values[air_datas[inst_index].ty_pl.payload],1498 .constant => return air.values[air_datas[inst_index].ty_pl.payload],
1504 .const_ty => unreachable,
1505 .interned => return air_datas[inst_index].interned.toValue(),1499 .interned => return air_datas[inst_index].interned.toValue(),
1506 else => return air.typeOfIndex(inst_index, mod.intern_pool).onePossibleValue(mod),1500 else => return air.typeOfIndex(inst_index, mod.intern_pool).onePossibleValue(mod),
1507 }1501 }
...@@ -1658,7 +1652,6 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: InternPool) bool {...@@ -1658,7 +1652,6 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: InternPool) bool {
1658 .cmp_vector,1652 .cmp_vector,
1659 .cmp_vector_optimized,1653 .cmp_vector_optimized,
1660 .constant,1654 .constant,
1661 .const_ty,
1662 .interned,1655 .interned,
1663 .is_null,1656 .is_null,
1664 .is_non_null,1657 .is_non_null,
src/InternPool.zig+40-20
...@@ -553,10 +553,10 @@ pub const Key = union(enum) {...@@ -553,10 +553,10 @@ pub const Key = union(enum) {
553 pub const Addr = union(enum) {553 pub const Addr = union(enum) {
554 decl: Module.Decl.Index,554 decl: Module.Decl.Index,
555 mut_decl: MutDecl,555 mut_decl: MutDecl,
556 comptime_field: Index,
556 int: Index,557 int: Index,
557 eu_payload: Index,558 eu_payload: Index,
558 opt_payload: Index,559 opt_payload: Index,
559 comptime_field: Index,
560 elem: BaseIndex,560 elem: BaseIndex,
561 field: BaseIndex,561 field: BaseIndex,
562562
...@@ -703,24 +703,27 @@ pub const Key = union(enum) {...@@ -703,24 +703,27 @@ pub const Key = union(enum) {
703 .aggregate => |aggregate| {703 .aggregate => |aggregate| {
704 std.hash.autoHash(hasher, aggregate.ty);704 std.hash.autoHash(hasher, aggregate.ty);
705 switch (ip.indexToKey(aggregate.ty)) {705 switch (ip.indexToKey(aggregate.ty)) {
706 .array_type => |array_type| if (array_type.child == .u8_type) switch (aggregate.storage) {706 .array_type => |array_type| if (array_type.child == .u8_type) {
707 .bytes => |bytes| for (bytes) |byte| std.hash.autoHash(hasher, byte),707 switch (aggregate.storage) {
708 .elems => |elems| {708 .bytes => |bytes| for (bytes) |byte| std.hash.autoHash(hasher, byte),
709 var buffer: Key.Int.Storage.BigIntSpace = undefined;709 .elems => |elems| {
710 for (elems) |elem| std.hash.autoHash(710 var buffer: Key.Int.Storage.BigIntSpace = undefined;
711 hasher,711 for (elems) |elem| std.hash.autoHash(
712 ip.indexToKey(elem).int.storage.toBigInt(&buffer).to(u8) catch712 hasher,
713 unreachable,713 ip.indexToKey(elem).int.storage.toBigInt(&buffer).to(u8) catch
714 );714 unreachable,
715 },715 );
716 .repeated_elem => |elem| {716 },
717 const len = ip.aggregateTypeLen(aggregate.ty);717 .repeated_elem => |elem| {
718 var buffer: Key.Int.Storage.BigIntSpace = undefined;718 const len = ip.aggregateTypeLen(aggregate.ty);
719 const byte = ip.indexToKey(elem).int.storage.toBigInt(&buffer).to(u8) catch719 var buffer: Key.Int.Storage.BigIntSpace = undefined;
720 unreachable;720 const byte = ip.indexToKey(elem).int.storage.toBigInt(&buffer).to(u8) catch
721 var i: u64 = 0;721 unreachable;
722 while (i < len) : (i += 1) std.hash.autoHash(hasher, byte);722 var i: u64 = 0;
723 },723 while (i < len) : (i += 1) std.hash.autoHash(hasher, byte);
724 },
725 }
726 return;
724 },727 },
725 else => {},728 else => {},
726 }729 }
...@@ -2860,6 +2863,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -2860,6 +2863,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
2860 },2863 },
2861 .array_type => |array_type| {2864 .array_type => |array_type| {
2862 assert(array_type.child != .none);2865 assert(array_type.child != .none);
2866 assert(array_type.sentinel == .none or ip.typeOf(array_type.sentinel) == array_type.child);
28632867
2864 if (std.math.cast(u32, array_type.len)) |len| {2868 if (std.math.cast(u32, array_type.len)) |len| {
2865 if (array_type.sentinel == .none) {2869 if (array_type.sentinel == .none) {
...@@ -3230,7 +3234,23 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {...@@ -3230,7 +3234,23 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
3230 },3234 },
32313235
3232 .int => |int| b: {3236 .int => |int| b: {
3233 assert(int.ty == .comptime_int_type or ip.indexToKey(int.ty) == .int_type);3237 switch (int.ty) {
3238 .usize_type,
3239 .isize_type,
3240 .c_char_type,
3241 .c_short_type,
3242 .c_ushort_type,
3243 .c_int_type,
3244 .c_uint_type,
3245 .c_long_type,
3246 .c_ulong_type,
3247 .c_longlong_type,
3248 .c_ulonglong_type,
3249 .c_longdouble_type,
3250 .comptime_int_type,
3251 => {},
3252 else => assert(ip.indexToKey(int.ty) == .int_type),
3253 }
3234 switch (int.storage) {3254 switch (int.storage) {
3235 .u64, .i64, .big_int => {},3255 .u64, .i64, .big_int => {},
3236 .lazy_align, .lazy_size => |lazy_ty| {3256 .lazy_align, .lazy_size => |lazy_ty| {
src/Liveness.zig+3-5
...@@ -323,7 +323,6 @@ pub fn categorizeOperand(...@@ -323,7 +323,6 @@ pub fn categorizeOperand(
323 .alloc,323 .alloc,
324 .ret_ptr,324 .ret_ptr,
325 .constant,325 .constant,
326 .const_ty,
327 .interned,326 .interned,
328 .trap,327 .trap,
329 .breakpoint,328 .breakpoint,
...@@ -975,7 +974,6 @@ fn analyzeInst(...@@ -975,7 +974,6 @@ fn analyzeInst(
975 => return analyzeOperands(a, pass, data, inst, .{ .none, .none, .none }),974 => return analyzeOperands(a, pass, data, inst, .{ .none, .none, .none }),
976975
977 .constant,976 .constant,
978 .const_ty,
979 .interned,977 .interned,
980 => unreachable,978 => unreachable,
981979
...@@ -1272,7 +1270,7 @@ fn analyzeOperands(...@@ -1272,7 +1270,7 @@ fn analyzeOperands(
12721270
1273 // Don't compute any liveness for constants1271 // Don't compute any liveness for constants
1274 switch (inst_tags[operand]) {1272 switch (inst_tags[operand]) {
1275 .constant, .const_ty, .interned => continue,1273 .constant, .interned => continue,
1276 else => {},1274 else => {},
1277 }1275 }
12781276
...@@ -1308,7 +1306,7 @@ fn analyzeOperands(...@@ -1308,7 +1306,7 @@ fn analyzeOperands(
13081306
1309 // Don't compute any liveness for constants1307 // Don't compute any liveness for constants
1310 switch (inst_tags[operand]) {1308 switch (inst_tags[operand]) {
1311 .constant, .const_ty, .interned => continue,1309 .constant, .interned => continue,
1312 else => {},1310 else => {},
1313 }1311 }
13141312
...@@ -1842,7 +1840,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {...@@ -1842,7 +1840,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
1842 // Don't compute any liveness for constants1840 // Don't compute any liveness for constants
1843 const inst_tags = big.a.air.instructions.items(.tag);1841 const inst_tags = big.a.air.instructions.items(.tag);
1844 switch (inst_tags[operand]) {1842 switch (inst_tags[operand]) {
1845 .constant, .const_ty, .interned => return,1843 .constant, .interned => return,
1846 else => {},1844 else => {},
1847 }1845 }
18481846
src/Liveness/Verify.zig+2-3
...@@ -43,7 +43,6 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {...@@ -43,7 +43,6 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
43 .alloc,43 .alloc,
44 .ret_ptr,44 .ret_ptr,
45 .constant,45 .constant,
46 .const_ty,
47 .interned,46 .interned,
48 .breakpoint,47 .breakpoint,
49 .dbg_stmt,48 .dbg_stmt,
...@@ -557,7 +556,7 @@ fn verifyDeath(self: *Verify, inst: Air.Inst.Index, operand: Air.Inst.Index) Err...@@ -557,7 +556,7 @@ fn verifyDeath(self: *Verify, inst: Air.Inst.Index, operand: Air.Inst.Index) Err
557fn verifyOperand(self: *Verify, inst: Air.Inst.Index, op_ref: Air.Inst.Ref, dies: bool) Error!void {556fn verifyOperand(self: *Verify, inst: Air.Inst.Index, op_ref: Air.Inst.Ref, dies: bool) Error!void {
558 const operand = Air.refToIndexAllowNone(op_ref) orelse return;557 const operand = Air.refToIndexAllowNone(op_ref) orelse return;
559 switch (self.air.instructions.items(.tag)[operand]) {558 switch (self.air.instructions.items(.tag)[operand]) {
560 .constant, .const_ty, .interned => {},559 .constant, .interned => {},
561 else => {560 else => {
562 if (dies) {561 if (dies) {
563 if (!self.live.remove(operand)) return invalid("%{}: dead operand %{} reused and killed again", .{ inst, operand });562 if (!self.live.remove(operand)) return invalid("%{}: dead operand %{} reused and killed again", .{ inst, operand });
...@@ -579,7 +578,7 @@ fn verifyInst(...@@ -579,7 +578,7 @@ fn verifyInst(
579 }578 }
580 const tag = self.air.instructions.items(.tag);579 const tag = self.air.instructions.items(.tag);
581 switch (tag[inst]) {580 switch (tag[inst]) {
582 .constant, .const_ty, .interned => unreachable,581 .constant, .interned => unreachable,
583 else => {582 else => {
584 if (self.liveness.isUnused(inst)) {583 if (self.liveness.isUnused(inst)) {
585 assert(!self.live.contains(inst));584 assert(!self.live.contains(inst));
src/Module.zig+106-160
...@@ -85,20 +85,13 @@ import_table: std.StringArrayHashMapUnmanaged(*File) = .{},...@@ -85,20 +85,13 @@ import_table: std.StringArrayHashMapUnmanaged(*File) = .{},
85/// Keys are fully resolved file paths. This table owns the keys and values.85/// Keys are fully resolved file paths. This table owns the keys and values.
86embed_table: std.StringHashMapUnmanaged(*EmbedFile) = .{},86embed_table: std.StringHashMapUnmanaged(*EmbedFile) = .{},
8787
88/// This is a temporary addition to stage2 in order to match legacy behavior,
89/// however the end-game once the lang spec is settled will be to use a global
90/// InternPool for comptime memoized objects, making this behavior consistent across all types,
91/// not only string literals. Or, we might decide to not guarantee string literals
92/// to have equal comptime pointers, in which case this field can be deleted (perhaps
93/// the commit that introduced it can simply be reverted).
94/// This table uses an optional index so that when a Decl is destroyed, the string literal
95/// is still reclaimable by a future Decl.
96string_literal_table: std.HashMapUnmanaged(StringLiteralContext.Key, Decl.OptionalIndex, StringLiteralContext, std.hash_map.default_max_load_percentage) = .{},
97string_literal_bytes: ArrayListUnmanaged(u8) = .{},
98
99/// Stores all Type and Value objects; periodically garbage collected.88/// Stores all Type and Value objects; periodically garbage collected.
100intern_pool: InternPool = .{},89intern_pool: InternPool = .{},
10190
91/// This is currently only used for string literals, however the end-game once the lang spec
92/// is settled will be to make this behavior consistent across all types.
93memoized_decls: std.AutoHashMapUnmanaged(InternPool.Index, Decl.Index) = .{},
94
102/// The set of all the generic function instantiations. This is used so that when a generic95/// The set of all the generic function instantiations. This is used so that when a generic
103/// function is called twice with the same comptime parameter arguments, both calls dispatch96/// function is called twice with the same comptime parameter arguments, both calls dispatch
104/// to the same function.97/// to the same function.
...@@ -208,39 +201,6 @@ pub const CImportError = struct {...@@ -208,39 +201,6 @@ pub const CImportError = struct {
208 }201 }
209};202};
210203
211pub const StringLiteralContext = struct {
212 bytes: *ArrayListUnmanaged(u8),
213
214 pub const Key = struct {
215 index: u32,
216 len: u32,
217 };
218
219 pub fn eql(self: @This(), a: Key, b: Key) bool {
220 _ = self;
221 return a.index == b.index and a.len == b.len;
222 }
223
224 pub fn hash(self: @This(), x: Key) u64 {
225 const x_slice = self.bytes.items[x.index..][0..x.len];
226 return std.hash_map.hashString(x_slice);
227 }
228};
229
230pub const StringLiteralAdapter = struct {
231 bytes: *ArrayListUnmanaged(u8),
232
233 pub fn eql(self: @This(), a_slice: []const u8, b: StringLiteralContext.Key) bool {
234 const b_slice = self.bytes.items[b.index..][0..b.len];
235 return mem.eql(u8, a_slice, b_slice);
236 }
237
238 pub fn hash(self: @This(), adapted_key: []const u8) u64 {
239 _ = self;
240 return std.hash_map.hashString(adapted_key);
241 }
242};
243
244const MonomorphedFuncsSet = std.HashMapUnmanaged(204const MonomorphedFuncsSet = std.HashMapUnmanaged(
245 Fn.Index,205 Fn.Index,
246 void,206 void,
...@@ -660,14 +620,8 @@ pub const Decl = struct {...@@ -660,14 +620,8 @@ pub const Decl = struct {
660 }620 }
661 mod.destroyFunc(func);621 mod.destroyFunc(func);
662 }622 }
623 _ = mod.memoized_decls.remove(decl.val.ip_index);
663 if (decl.value_arena) |value_arena| {624 if (decl.value_arena) |value_arena| {
664 if (decl.owns_tv) {
665 if (decl.val.castTag(.str_lit)) |str_lit| {
666 mod.string_literal_table.getPtrContext(str_lit.data, .{
667 .bytes = &mod.string_literal_bytes,
668 }).?.* = .none;
669 }
670 }
671 value_arena.deinit(gpa);625 value_arena.deinit(gpa);
672 decl.value_arena = null;626 decl.value_arena = null;
673 decl.has_tv = false;627 decl.has_tv = false;
...@@ -834,7 +788,7 @@ pub const Decl = struct {...@@ -834,7 +788,7 @@ pub const Decl = struct {
834 pub fn getStructIndex(decl: Decl, mod: *Module) Struct.OptionalIndex {788 pub fn getStructIndex(decl: Decl, mod: *Module) Struct.OptionalIndex {
835 if (!decl.owns_tv) return .none;789 if (!decl.owns_tv) return .none;
836 if (decl.val.ip_index == .none) return .none;790 if (decl.val.ip_index == .none) return .none;
837 return mod.intern_pool.indexToStructType(decl.val.ip_index);791 return mod.intern_pool.indexToStructType(decl.val.toIntern());
838 }792 }
839793
840 /// If the Decl has a value and it is a union, return it,794 /// If the Decl has a value and it is a union, return it,
...@@ -875,7 +829,7 @@ pub const Decl = struct {...@@ -875,7 +829,7 @@ pub const Decl = struct {
875 return switch (decl.val.ip_index) {829 return switch (decl.val.ip_index) {
876 .empty_struct_type => .none,830 .empty_struct_type => .none,
877 .none => .none,831 .none => .none,
878 else => switch (mod.intern_pool.indexToKey(decl.val.ip_index)) {832 else => switch (mod.intern_pool.indexToKey(decl.val.toIntern())) {
879 .opaque_type => |opaque_type| opaque_type.namespace.toOptional(),833 .opaque_type => |opaque_type| opaque_type.namespace.toOptional(),
880 .struct_type => |struct_type| struct_type.namespace,834 .struct_type => |struct_type| struct_type.namespace,
881 .union_type => |union_type| mod.unionPtr(union_type.index).namespace.toOptional(),835 .union_type => |union_type| mod.unionPtr(union_type.index).namespace.toOptional(),
...@@ -919,7 +873,7 @@ pub const Decl = struct {...@@ -919,7 +873,7 @@ pub const Decl = struct {
919873
920 pub fn isExtern(decl: Decl, mod: *Module) bool {874 pub fn isExtern(decl: Decl, mod: *Module) bool {
921 assert(decl.has_tv);875 assert(decl.has_tv);
922 return switch (mod.intern_pool.indexToKey(decl.val.ip_index)) {876 return switch (mod.intern_pool.indexToKey(decl.val.toIntern())) {
923 .variable => |variable| variable.is_extern,877 .variable => |variable| variable.is_extern,
924 .extern_func => true,878 .extern_func => true,
925 else => false,879 else => false,
...@@ -1577,11 +1531,11 @@ pub const Fn = struct {...@@ -1577,11 +1531,11 @@ pub const Fn = struct {
1577 ip: *InternPool,1531 ip: *InternPool,
1578 gpa: Allocator,1532 gpa: Allocator,
1579 ) !void {1533 ) !void {
1580 switch (err_set_ty.ip_index) {1534 switch (err_set_ty.toIntern()) {
1581 .anyerror_type => {1535 .anyerror_type => {
1582 self.is_anyerror = true;1536 self.is_anyerror = true;
1583 },1537 },
1584 else => switch (ip.indexToKey(err_set_ty.ip_index)) {1538 else => switch (ip.indexToKey(err_set_ty.toIntern())) {
1585 .error_set_type => |error_set_type| {1539 .error_set_type => |error_set_type| {
1586 for (error_set_type.names) |name| {1540 for (error_set_type.names) |name| {
1587 try self.errors.put(gpa, name, {});1541 try self.errors.put(gpa, name, {});
...@@ -3396,8 +3350,7 @@ pub fn deinit(mod: *Module) void {...@@ -3396,8 +3350,7 @@ pub fn deinit(mod: *Module) void {
3396 mod.namespaces_free_list.deinit(gpa);3350 mod.namespaces_free_list.deinit(gpa);
3397 mod.allocated_namespaces.deinit(gpa);3351 mod.allocated_namespaces.deinit(gpa);
33983352
3399 mod.string_literal_table.deinit(gpa);3353 mod.memoized_decls.deinit(gpa);
3400 mod.string_literal_bytes.deinit(gpa);
34013354
3402 mod.intern_pool.deinit(gpa);3355 mod.intern_pool.deinit(gpa);
3403}3356}
...@@ -4702,7 +4655,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4702,7 +4655,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4702 return true;4655 return true;
4703 }4656 }
47044657
4705 if (mod.intern_pool.indexToFunc(decl_tv.val.ip_index).unwrap()) |func_index| {4658 if (mod.intern_pool.indexToFunc(decl_tv.val.toIntern()).unwrap()) |func_index| {
4706 const func = mod.funcPtr(func_index);4659 const func = mod.funcPtr(func_index);
4707 const owns_tv = func.owner_decl == decl_index;4660 const owns_tv = func.owner_decl == decl_index;
4708 if (owns_tv) {4661 if (owns_tv) {
...@@ -4749,10 +4702,10 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4749,10 +4702,10 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4749 decl.owns_tv = false;4702 decl.owns_tv = false;
4750 var queue_linker_work = false;4703 var queue_linker_work = false;
4751 var is_extern = false;4704 var is_extern = false;
4752 switch (decl_tv.val.ip_index) {4705 switch (decl_tv.val.toIntern()) {
4753 .generic_poison => unreachable,4706 .generic_poison => unreachable,
4754 .unreachable_value => unreachable,4707 .unreachable_value => unreachable,
4755 else => switch (mod.intern_pool.indexToKey(decl_tv.val.ip_index)) {4708 else => switch (mod.intern_pool.indexToKey(decl_tv.val.toIntern())) {
4756 .variable => |variable| if (variable.decl == decl_index) {4709 .variable => |variable| if (variable.decl == decl_index) {
4757 decl.owns_tv = true;4710 decl.owns_tv = true;
4758 queue_linker_work = true;4711 queue_linker_work = true;
...@@ -4792,7 +4745,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -4792,7 +4745,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
4792 break :blk (try decl_arena_allocator.dupeZ(u8, bytes)).ptr;4745 break :blk (try decl_arena_allocator.dupeZ(u8, bytes)).ptr;
4793 };4746 };
4794 decl.@"addrspace" = blk: {4747 decl.@"addrspace" = blk: {
4795 const addrspace_ctx: Sema.AddressSpaceContext = switch (mod.intern_pool.indexToKey(decl_tv.val.ip_index)) {4748 const addrspace_ctx: Sema.AddressSpaceContext = switch (mod.intern_pool.indexToKey(decl_tv.val.toIntern())) {
4796 .variable => .variable,4749 .variable => .variable,
4797 .extern_func, .func => .function,4750 .extern_func, .func => .function,
4798 else => .constant,4751 else => .constant,
...@@ -6497,40 +6450,33 @@ pub fn populateTestFunctions(...@@ -6497,40 +6450,33 @@ pub fn populateTestFunctions(
6497 const array_decl_index = d: {6450 const array_decl_index = d: {
6498 // Add mod.test_functions to an array decl then make the test_functions6451 // Add mod.test_functions to an array decl then make the test_functions
6499 // decl reference it as a slice.6452 // decl reference it as a slice.
6500 var new_decl_arena = std.heap.ArenaAllocator.init(gpa);6453 const test_fn_vals = try gpa.alloc(InternPool.Index, mod.test_functions.count());
6501 errdefer new_decl_arena.deinit();6454 defer gpa.free(test_fn_vals);
6502 const arena = new_decl_arena.allocator();
6503
6504 const test_fn_vals = try arena.alloc(Value, mod.test_functions.count());
6505 const array_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, null, .{
6506 .ty = try mod.arrayType(.{
6507 .len = test_fn_vals.len,
6508 .child = test_fn_ty.ip_index,
6509 .sentinel = .none,
6510 }),
6511 .val = try Value.Tag.aggregate.create(arena, test_fn_vals),
6512 });
6513 const array_decl = mod.declPtr(array_decl_index);
65146455
6515 // Add a dependency on each test name and function pointer.6456 // Add a dependency on each test name and function pointer.
6516 try array_decl.dependencies.ensureUnusedCapacity(gpa, test_fn_vals.len * 2);6457 var array_decl_dependencies = std.ArrayListUnmanaged(Decl.Index){};
6458 defer array_decl_dependencies.deinit(gpa);
6459 try array_decl_dependencies.ensureUnusedCapacity(gpa, test_fn_vals.len * 2);
65176460
6518 for (mod.test_functions.keys(), 0..) |test_decl_index, i| {6461 for (test_fn_vals, mod.test_functions.keys()) |*test_fn_val, test_decl_index| {
6519 const test_decl = mod.declPtr(test_decl_index);6462 const test_decl = mod.declPtr(test_decl_index);
6520 const test_name_slice = mem.sliceTo(test_decl.name, 0);
6521 const test_name_decl_index = n: {6463 const test_name_decl_index = n: {
6522 var name_decl_arena = std.heap.ArenaAllocator.init(gpa);6464 const test_decl_name = mem.span(test_decl.name);
6523 errdefer name_decl_arena.deinit();6465 const test_name_decl_ty = try mod.arrayType(.{
6524 const bytes = try name_decl_arena.allocator().dupe(u8, test_name_slice);6466 .len = test_decl_name.len,
6525 const test_name_decl_index = try mod.createAnonymousDeclFromDecl(array_decl, array_decl.src_namespace, null, .{6467 .child = .u8_type,
6526 .ty = try mod.arrayType(.{ .len = bytes.len, .child = .u8_type }),6468 });
6527 .val = try Value.Tag.bytes.create(name_decl_arena.allocator(), bytes),6469 const test_name_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, null, .{
6470 .ty = test_name_decl_ty,
6471 .val = (try mod.intern(.{ .aggregate = .{
6472 .ty = test_name_decl_ty.toIntern(),
6473 .storage = .{ .bytes = test_decl_name },
6474 } })).toValue(),
6528 });6475 });
6529 try mod.declPtr(test_name_decl_index).finalizeNewArena(&name_decl_arena);
6530 break :n test_name_decl_index;6476 break :n test_name_decl_index;
6531 };6477 };
6532 array_decl.dependencies.putAssumeCapacityNoClobber(test_decl_index, .normal);6478 array_decl_dependencies.appendAssumeCapacity(test_decl_index);
6533 array_decl.dependencies.putAssumeCapacityNoClobber(test_name_decl_index, .normal);6479 array_decl_dependencies.appendAssumeCapacity(test_name_decl_index);
6534 try mod.linkerUpdateDecl(test_name_decl_index);6480 try mod.linkerUpdateDecl(test_name_decl_index);
65356481
6536 const test_fn_fields = .{6482 const test_fn_fields = .{
...@@ -6541,36 +6487,51 @@ pub fn populateTestFunctions(...@@ -6541,36 +6487,51 @@ pub fn populateTestFunctions(
6541 } }),6487 } }),
6542 // func6488 // func
6543 try mod.intern(.{ .ptr = .{6489 try mod.intern(.{ .ptr = .{
6544 .ty = test_decl.ty.ip_index,6490 .ty = test_decl.ty.toIntern(),
6545 .addr = .{ .decl = test_decl_index },6491 .addr = .{ .decl = test_decl_index },
6546 } }),6492 } }),
6547 // async_frame_size6493 // async_frame_size
6548 null_usize,6494 null_usize,
6549 };6495 };
6550 test_fn_vals[i] = (try mod.intern(.{ .aggregate = .{6496 test_fn_val.* = try mod.intern(.{ .aggregate = .{
6551 .ty = test_fn_ty.ip_index,6497 .ty = test_fn_ty.toIntern(),
6552 .storage = .{ .elems = &test_fn_fields },6498 .storage = .{ .elems = &test_fn_fields },
6553 } })).toValue();6499 } });
6500 }
6501
6502 const array_decl_ty = try mod.arrayType(.{
6503 .len = test_fn_vals.len,
6504 .child = test_fn_ty.toIntern(),
6505 .sentinel = .none,
6506 });
6507 const array_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, null, .{
6508 .ty = array_decl_ty,
6509 .val = (try mod.intern(.{ .aggregate = .{
6510 .ty = array_decl_ty.toIntern(),
6511 .storage = .{ .elems = test_fn_vals },
6512 } })).toValue(),
6513 });
6514 for (array_decl_dependencies.items) |array_decl_dependency| {
6515 try mod.declareDeclDependency(array_decl_index, array_decl_dependency);
6554 }6516 }
65556517
6556 try array_decl.finalizeNewArena(&new_decl_arena);
6557 break :d array_decl_index;6518 break :d array_decl_index;
6558 };6519 };
6559 try mod.linkerUpdateDecl(array_decl_index);6520 try mod.linkerUpdateDecl(array_decl_index);
65606521
6561 {6522 {
6562 const new_ty = try mod.ptrType(.{6523 const new_ty = try mod.ptrType(.{
6563 .elem_type = test_fn_ty.ip_index,6524 .elem_type = test_fn_ty.toIntern(),
6564 .is_const = true,6525 .is_const = true,
6565 .size = .Slice,6526 .size = .Slice,
6566 });6527 });
6567 const new_val = decl.val;6528 const new_val = decl.val;
6568 const new_init = try mod.intern(.{ .ptr = .{6529 const new_init = try mod.intern(.{ .ptr = .{
6569 .ty = new_ty.ip_index,6530 .ty = new_ty.toIntern(),
6570 .addr = .{ .decl = array_decl_index },6531 .addr = .{ .decl = array_decl_index },
6571 .len = (try mod.intValue(Type.usize, mod.test_functions.count())).ip_index,6532 .len = (try mod.intValue(Type.usize, mod.test_functions.count())).toIntern(),
6572 } });6533 } });
6573 mod.intern_pool.mutateVarInit(decl.val.ip_index, new_init);6534 mod.intern_pool.mutateVarInit(decl.val.toIntern(), new_init);
65746535
6575 // Since we are replacing the Decl's value we must perform cleanup on the6536 // Since we are replacing the Decl's value we must perform cleanup on the
6576 // previous value.6537 // previous value.
...@@ -6650,47 +6611,32 @@ fn reportRetryableFileError(...@@ -6650,47 +6611,32 @@ fn reportRetryableFileError(
6650}6611}
66516612
6652pub fn markReferencedDeclsAlive(mod: *Module, val: Value) void {6613pub fn markReferencedDeclsAlive(mod: *Module, val: Value) void {
6653 switch (val.ip_index) {6614 switch (mod.intern_pool.indexToKey(val.toIntern())) {
6654 .none => switch (val.tag()) {6615 .variable => |variable| mod.markDeclIndexAlive(variable.decl),
6655 .aggregate => {6616 .extern_func => |extern_func| mod.markDeclIndexAlive(extern_func.decl),
6656 for (val.castTag(.aggregate).?.data) |field_val| {6617 .func => |func| mod.markDeclIndexAlive(mod.funcPtr(func.index).owner_decl),
6657 mod.markReferencedDeclsAlive(field_val);6618 .error_union => |error_union| switch (error_union.val) {
6658 }6619 .err_name => {},
6659 },6620 .payload => |payload| mod.markReferencedDeclsAlive(payload.toValue()),
6660 .@"union" => {
6661 const data = val.castTag(.@"union").?.data;
6662 mod.markReferencedDeclsAlive(data.tag);
6663 mod.markReferencedDeclsAlive(data.val);
6664 },
6665 else => {},
6666 },6621 },
6667 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {6622 .ptr => |ptr| {
6668 .variable => |variable| mod.markDeclIndexAlive(variable.decl),6623 switch (ptr.addr) {
6669 .extern_func => |extern_func| mod.markDeclIndexAlive(extern_func.decl),6624 .decl => |decl| mod.markDeclIndexAlive(decl),
6670 .func => |func| mod.markDeclIndexAlive(mod.funcPtr(func.index).owner_decl),6625 .mut_decl => |mut_decl| mod.markDeclIndexAlive(mut_decl.decl),
6671 .error_union => |error_union| switch (error_union.val) {6626 .int, .comptime_field => {},
6672 .err_name => {},6627 .eu_payload, .opt_payload => |parent| mod.markReferencedDeclsAlive(parent.toValue()),
6673 .payload => |payload| mod.markReferencedDeclsAlive(payload.toValue()),6628 .elem, .field => |base_index| mod.markReferencedDeclsAlive(base_index.base.toValue()),
6674 },6629 }
6675 .ptr => |ptr| {6630 if (ptr.len != .none) mod.markReferencedDeclsAlive(ptr.len.toValue());
6676 switch (ptr.addr) {6631 },
6677 .decl => |decl| mod.markDeclIndexAlive(decl),6632 .opt => |opt| if (opt.val != .none) mod.markReferencedDeclsAlive(opt.val.toValue()),
6678 .mut_decl => |mut_decl| mod.markDeclIndexAlive(mut_decl.decl),6633 .aggregate => |aggregate| for (aggregate.storage.values()) |elem|
6679 .int, .comptime_field => {},6634 mod.markReferencedDeclsAlive(elem.toValue()),
6680 .eu_payload, .opt_payload => |parent| mod.markReferencedDeclsAlive(parent.toValue()),6635 .un => |un| {
6681 .elem, .field => |base_index| mod.markReferencedDeclsAlive(base_index.base.toValue()),6636 mod.markReferencedDeclsAlive(un.tag.toValue());
6682 }6637 mod.markReferencedDeclsAlive(un.val.toValue());
6683 if (ptr.len != .none) mod.markReferencedDeclsAlive(ptr.len.toValue());
6684 },
6685 .opt => |opt| if (opt.val != .none) mod.markReferencedDeclsAlive(opt.val.toValue()),
6686 .aggregate => |aggregate| for (aggregate.storage.values()) |elem|
6687 mod.markReferencedDeclsAlive(elem.toValue()),
6688 .un => |un| {
6689 mod.markReferencedDeclsAlive(un.tag.toValue());
6690 mod.markReferencedDeclsAlive(un.val.toValue());
6691 },
6692 else => {},
6693 },6638 },
6639 else => {},
6694 }6640 }
6695}6641}
66966642
...@@ -6796,11 +6742,11 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type...@@ -6796,11 +6742,11 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
6796}6742}
67976743
6798pub fn singleMutPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {6744pub fn singleMutPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {
6799 return ptrType(mod, .{ .elem_type = child_type.ip_index });6745 return ptrType(mod, .{ .elem_type = child_type.toIntern() });
6800}6746}
68016747
6802pub fn singleConstPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {6748pub fn singleConstPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {
6803 return ptrType(mod, .{ .elem_type = child_type.ip_index, .is_const = true });6749 return ptrType(mod, .{ .elem_type = child_type.toIntern(), .is_const = true });
6804}6750}
68056751
6806pub fn adjustPtrTypeChild(mod: *Module, ptr_ty: Type, new_child: Type) Allocator.Error!Type {6752pub fn adjustPtrTypeChild(mod: *Module, ptr_ty: Type, new_child: Type) Allocator.Error!Type {
...@@ -6871,9 +6817,9 @@ pub fn errorSetFromUnsortedNames(...@@ -6871,9 +6817,9 @@ pub fn errorSetFromUnsortedNames(
6871pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {6817pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
6872 if (ty.isPtrLikeOptional(mod)) {6818 if (ty.isPtrLikeOptional(mod)) {
6873 const i = try intern(mod, .{ .opt = .{6819 const i = try intern(mod, .{ .opt = .{
6874 .ty = ty.ip_index,6820 .ty = ty.toIntern(),
6875 .val = try intern(mod, .{ .ptr = .{6821 .val = try intern(mod, .{ .ptr = .{
6876 .ty = ty.childType(mod).ip_index,6822 .ty = ty.childType(mod).toIntern(),
6877 .addr = .{ .int = try intern(mod, .{ .int = .{6823 .addr = .{ .int = try intern(mod, .{ .int = .{
6878 .ty = .usize_type,6824 .ty = .usize_type,
6879 .storage = .{ .u64 = x },6825 .storage = .{ .u64 = x },
...@@ -6890,7 +6836,7 @@ pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {...@@ -6890,7 +6836,7 @@ pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
6890pub fn ptrIntValue_ptronly(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {6836pub fn ptrIntValue_ptronly(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
6891 assert(ty.zigTypeTag(mod) == .Pointer);6837 assert(ty.zigTypeTag(mod) == .Pointer);
6892 const i = try intern(mod, .{ .ptr = .{6838 const i = try intern(mod, .{ .ptr = .{
6893 .ty = ty.ip_index,6839 .ty = ty.toIntern(),
6894 .addr = .{ .int = try intern(mod, .{ .int = .{6840 .addr = .{ .int = try intern(mod, .{ .int = .{
6895 .ty = .usize_type,6841 .ty = .usize_type,
6896 .storage = .{ .u64 = x },6842 .storage = .{ .u64 = x },
...@@ -6906,7 +6852,7 @@ pub fn enumValue(mod: *Module, ty: Type, tag_int: InternPool.Index) Allocator.Er...@@ -6906,7 +6852,7 @@ pub fn enumValue(mod: *Module, ty: Type, tag_int: InternPool.Index) Allocator.Er
6906 assert(tag == .Enum);6852 assert(tag == .Enum);
6907 }6853 }
6908 const i = try intern(mod, .{ .enum_tag = .{6854 const i = try intern(mod, .{ .enum_tag = .{
6909 .ty = ty.ip_index,6855 .ty = ty.toIntern(),
6910 .int = tag_int,6856 .int = tag_int,
6911 } });6857 } });
6912 return i.toValue();6858 return i.toValue();
...@@ -6917,12 +6863,12 @@ pub fn enumValue(mod: *Module, ty: Type, tag_int: InternPool.Index) Allocator.Er...@@ -6917,12 +6863,12 @@ pub fn enumValue(mod: *Module, ty: Type, tag_int: InternPool.Index) Allocator.Er
6917pub fn enumValueFieldIndex(mod: *Module, ty: Type, field_index: u32) Allocator.Error!Value {6863pub fn enumValueFieldIndex(mod: *Module, ty: Type, field_index: u32) Allocator.Error!Value {
6918 const ip = &mod.intern_pool;6864 const ip = &mod.intern_pool;
6919 const gpa = mod.gpa;6865 const gpa = mod.gpa;
6920 const enum_type = ip.indexToKey(ty.ip_index).enum_type;6866 const enum_type = ip.indexToKey(ty.toIntern()).enum_type;
69216867
6922 if (enum_type.values.len == 0) {6868 if (enum_type.values.len == 0) {
6923 // Auto-numbered fields.6869 // Auto-numbered fields.
6924 return (try ip.get(gpa, .{ .enum_tag = .{6870 return (try ip.get(gpa, .{ .enum_tag = .{
6925 .ty = ty.ip_index,6871 .ty = ty.toIntern(),
6926 .int = try ip.get(gpa, .{ .int = .{6872 .int = try ip.get(gpa, .{ .int = .{
6927 .ty = enum_type.tag_ty,6873 .ty = enum_type.tag_ty,
6928 .storage = .{ .u64 = field_index },6874 .storage = .{ .u64 = field_index },
...@@ -6931,7 +6877,7 @@ pub fn enumValueFieldIndex(mod: *Module, ty: Type, field_index: u32) Allocator.E...@@ -6931,7 +6877,7 @@ pub fn enumValueFieldIndex(mod: *Module, ty: Type, field_index: u32) Allocator.E
6931 }6877 }
69326878
6933 return (try ip.get(gpa, .{ .enum_tag = .{6879 return (try ip.get(gpa, .{ .enum_tag = .{
6934 .ty = ty.ip_index,6880 .ty = ty.toIntern(),
6935 .int = enum_type.values[field_index],6881 .int = enum_type.values[field_index],
6936 } })).toValue();6882 } })).toValue();
6937}6883}
...@@ -6950,7 +6896,7 @@ pub fn intValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {...@@ -6950,7 +6896,7 @@ pub fn intValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
69506896
6951pub fn intValue_big(mod: *Module, ty: Type, x: BigIntConst) Allocator.Error!Value {6897pub fn intValue_big(mod: *Module, ty: Type, x: BigIntConst) Allocator.Error!Value {
6952 const i = try intern(mod, .{ .int = .{6898 const i = try intern(mod, .{ .int = .{
6953 .ty = ty.ip_index,6899 .ty = ty.toIntern(),
6954 .storage = .{ .big_int = x },6900 .storage = .{ .big_int = x },
6955 } });6901 } });
6956 return i.toValue();6902 return i.toValue();
...@@ -6958,7 +6904,7 @@ pub fn intValue_big(mod: *Module, ty: Type, x: BigIntConst) Allocator.Error!Valu...@@ -6958,7 +6904,7 @@ pub fn intValue_big(mod: *Module, ty: Type, x: BigIntConst) Allocator.Error!Valu
69586904
6959pub fn intValue_u64(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {6905pub fn intValue_u64(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
6960 const i = try intern(mod, .{ .int = .{6906 const i = try intern(mod, .{ .int = .{
6961 .ty = ty.ip_index,6907 .ty = ty.toIntern(),
6962 .storage = .{ .u64 = x },6908 .storage = .{ .u64 = x },
6963 } });6909 } });
6964 return i.toValue();6910 return i.toValue();
...@@ -6966,7 +6912,7 @@ pub fn intValue_u64(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {...@@ -6966,7 +6912,7 @@ pub fn intValue_u64(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
69666912
6967pub fn intValue_i64(mod: *Module, ty: Type, x: i64) Allocator.Error!Value {6913pub fn intValue_i64(mod: *Module, ty: Type, x: i64) Allocator.Error!Value {
6968 const i = try intern(mod, .{ .int = .{6914 const i = try intern(mod, .{ .int = .{
6969 .ty = ty.ip_index,6915 .ty = ty.toIntern(),
6970 .storage = .{ .i64 = x },6916 .storage = .{ .i64 = x },
6971 } });6917 } });
6972 return i.toValue();6918 return i.toValue();
...@@ -6974,9 +6920,9 @@ pub fn intValue_i64(mod: *Module, ty: Type, x: i64) Allocator.Error!Value {...@@ -6974,9 +6920,9 @@ pub fn intValue_i64(mod: *Module, ty: Type, x: i64) Allocator.Error!Value {
69746920
6975pub fn unionValue(mod: *Module, union_ty: Type, tag: Value, val: Value) Allocator.Error!Value {6921pub fn unionValue(mod: *Module, union_ty: Type, tag: Value, val: Value) Allocator.Error!Value {
6976 const i = try intern(mod, .{ .un = .{6922 const i = try intern(mod, .{ .un = .{
6977 .ty = union_ty.ip_index,6923 .ty = union_ty.toIntern(),
6978 .tag = tag.ip_index,6924 .tag = tag.toIntern(),
6979 .val = val.ip_index,6925 .val = val.toIntern(),
6980 } });6926 } });
6981 return i.toValue();6927 return i.toValue();
6982}6928}
...@@ -6993,7 +6939,7 @@ pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {...@@ -6993,7 +6939,7 @@ pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
6993 else => unreachable,6939 else => unreachable,
6994 };6940 };
6995 const i = try intern(mod, .{ .float = .{6941 const i = try intern(mod, .{ .float = .{
6996 .ty = ty.ip_index,6942 .ty = ty.toIntern(),
6997 .storage = storage,6943 .storage = storage,
6998 } });6944 } });
6999 return i.toValue();6945 return i.toValue();
...@@ -7001,9 +6947,9 @@ pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {...@@ -7001,9 +6947,9 @@ pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
70016947
7002pub fn nullValue(mod: *Module, opt_ty: Type) Allocator.Error!Value {6948pub fn nullValue(mod: *Module, opt_ty: Type) Allocator.Error!Value {
7003 const ip = &mod.intern_pool;6949 const ip = &mod.intern_pool;
7004 assert(ip.isOptionalType(opt_ty.ip_index));6950 assert(ip.isOptionalType(opt_ty.toIntern()));
7005 const result = try ip.get(mod.gpa, .{ .opt = .{6951 const result = try ip.get(mod.gpa, .{ .opt = .{
7006 .ty = opt_ty.ip_index,6952 .ty = opt_ty.toIntern(),
7007 .val = .none,6953 .val = .none,
7008 } });6954 } });
7009 return result.toValue();6955 return result.toValue();
...@@ -7042,7 +6988,7 @@ pub fn intFittingRange(mod: *Module, min: Value, max: Value) !Type {...@@ -7042,7 +6988,7 @@ pub fn intFittingRange(mod: *Module, min: Value, max: Value) !Type {
7042pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 {6988pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 {
7043 assert(!val.isUndef(mod));6989 assert(!val.isUndef(mod));
70446990
7045 const key = mod.intern_pool.indexToKey(val.ip_index);6991 const key = mod.intern_pool.indexToKey(val.toIntern());
7046 switch (key.int.storage) {6992 switch (key.int.storage) {
7047 .i64 => |x| {6993 .i64 => |x| {
7048 if (std.math.cast(u64, x)) |casted| return Type.smallestUnsignedBits(casted);6994 if (std.math.cast(u64, x)) |casted| return Type.smallestUnsignedBits(casted);
...@@ -7221,19 +7167,19 @@ pub fn namespaceDeclIndex(mod: *Module, namespace_index: Namespace.Index) Decl.I...@@ -7221,19 +7167,19 @@ pub fn namespaceDeclIndex(mod: *Module, namespace_index: Namespace.Index) Decl.I
7221/// * Not a struct.7167/// * Not a struct.
7222pub fn typeToStruct(mod: *Module, ty: Type) ?*Struct {7168pub fn typeToStruct(mod: *Module, ty: Type) ?*Struct {
7223 if (ty.ip_index == .none) return null;7169 if (ty.ip_index == .none) return null;
7224 const struct_index = mod.intern_pool.indexToStructType(ty.ip_index).unwrap() orelse return null;7170 const struct_index = mod.intern_pool.indexToStructType(ty.toIntern()).unwrap() orelse return null;
7225 return mod.structPtr(struct_index);7171 return mod.structPtr(struct_index);
7226}7172}
72277173
7228pub fn typeToUnion(mod: *Module, ty: Type) ?*Union {7174pub fn typeToUnion(mod: *Module, ty: Type) ?*Union {
7229 if (ty.ip_index == .none) return null;7175 if (ty.ip_index == .none) return null;
7230 const union_index = mod.intern_pool.indexToUnionType(ty.ip_index).unwrap() orelse return null;7176 const union_index = mod.intern_pool.indexToUnionType(ty.toIntern()).unwrap() orelse return null;
7231 return mod.unionPtr(union_index);7177 return mod.unionPtr(union_index);
7232}7178}
72337179
7234pub fn typeToFunc(mod: *Module, ty: Type) ?InternPool.Key.FuncType {7180pub fn typeToFunc(mod: *Module, ty: Type) ?InternPool.Key.FuncType {
7235 if (ty.ip_index == .none) return null;7181 if (ty.ip_index == .none) return null;
7236 return mod.intern_pool.indexToFuncType(ty.ip_index);7182 return mod.intern_pool.indexToFuncType(ty.toIntern());
7237}7183}
72387184
7239pub fn typeToInferredErrorSet(mod: *Module, ty: Type) ?*Fn.InferredErrorSet {7185pub fn typeToInferredErrorSet(mod: *Module, ty: Type) ?*Fn.InferredErrorSet {
...@@ -7243,7 +7189,7 @@ pub fn typeToInferredErrorSet(mod: *Module, ty: Type) ?*Fn.InferredErrorSet {...@@ -7243,7 +7189,7 @@ pub fn typeToInferredErrorSet(mod: *Module, ty: Type) ?*Fn.InferredErrorSet {
72437189
7244pub fn typeToInferredErrorSetIndex(mod: *Module, ty: Type) Fn.InferredErrorSet.OptionalIndex {7190pub fn typeToInferredErrorSetIndex(mod: *Module, ty: Type) Fn.InferredErrorSet.OptionalIndex {
7245 if (ty.ip_index == .none) return .none;7191 if (ty.ip_index == .none) return .none;
7246 return mod.intern_pool.indexToInferredErrorSetType(ty.ip_index);7192 return mod.intern_pool.indexToInferredErrorSetType(ty.toIntern());
7247}7193}
72487194
7249pub fn fieldSrcLoc(mod: *Module, owner_decl_index: Decl.Index, query: FieldSrcQuery) SrcLoc {7195pub fn fieldSrcLoc(mod: *Module, owner_decl_index: Decl.Index, query: FieldSrcQuery) SrcLoc {
...@@ -7268,5 +7214,5 @@ pub fn fieldSrcLoc(mod: *Module, owner_decl_index: Decl.Index, query: FieldSrcQu...@@ -7268,5 +7214,5 @@ pub fn fieldSrcLoc(mod: *Module, owner_decl_index: Decl.Index, query: FieldSrcQu
7268}7214}
72697215
7270pub fn toEnum(mod: *Module, comptime E: type, val: Value) E {7216pub fn toEnum(mod: *Module, comptime E: type, val: Value) E {
7271 return mod.intern_pool.toEnum(E, val.ip_index);7217 return mod.intern_pool.toEnum(E, val.toIntern());
7272}7218}
src/Sema.zig+1318-1180
...@@ -1866,9 +1866,9 @@ fn resolveConstMaybeUndefVal(...@@ -1866,9 +1866,9 @@ fn resolveConstMaybeUndefVal(
1866 reason: []const u8,1866 reason: []const u8,
1867) CompileError!Value {1867) CompileError!Value {
1868 if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| {1868 if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| {
1869 switch (val.ip_index) {1869 switch (val.toIntern()) {
1870 .generic_poison => return error.GenericPoison,1870 .generic_poison => return error.GenericPoison,
1871 else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) {1871 else => switch (sema.mod.intern_pool.indexToKey(val.toIntern())) {
1872 .variable => return sema.failWithNeededComptime(block, src, reason),1872 .variable => return sema.failWithNeededComptime(block, src, reason),
1873 else => return val,1873 else => return val,
1874 },1874 },
...@@ -1887,10 +1887,10 @@ fn resolveConstValue(...@@ -1887,10 +1887,10 @@ fn resolveConstValue(
1887 reason: []const u8,1887 reason: []const u8,
1888) CompileError!Value {1888) CompileError!Value {
1889 if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| {1889 if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| {
1890 switch (val.ip_index) {1890 switch (val.toIntern()) {
1891 .generic_poison => return error.GenericPoison,1891 .generic_poison => return error.GenericPoison,
1892 .undef => return sema.failWithUseOfUndef(block, src),1892 .undef => return sema.failWithUseOfUndef(block, src),
1893 else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) {1893 else => switch (sema.mod.intern_pool.indexToKey(val.toIntern())) {
1894 .undef => return sema.failWithUseOfUndef(block, src),1894 .undef => return sema.failWithUseOfUndef(block, src),
1895 .variable => return sema.failWithNeededComptime(block, src, reason),1895 .variable => return sema.failWithNeededComptime(block, src, reason),
1896 else => return val,1896 else => return val,
...@@ -1930,7 +1930,7 @@ fn resolveMaybeUndefVal(...@@ -1930,7 +1930,7 @@ fn resolveMaybeUndefVal(
1930 switch (val.ip_index) {1930 switch (val.ip_index) {
1931 .generic_poison => return error.GenericPoison,1931 .generic_poison => return error.GenericPoison,
1932 .none => return val,1932 .none => return val,
1933 else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) {1933 else => switch (sema.mod.intern_pool.indexToKey(val.toIntern())) {
1934 .variable => return null,1934 .variable => return null,
1935 else => return val,1935 else => return val,
1936 },1936 },
...@@ -1950,7 +1950,7 @@ fn resolveMaybeUndefValIntable(...@@ -1950,7 +1950,7 @@ fn resolveMaybeUndefValIntable(
1950 while (true) switch (check.ip_index) {1950 while (true) switch (check.ip_index) {
1951 .generic_poison => return error.GenericPoison,1951 .generic_poison => return error.GenericPoison,
1952 .none => break,1952 .none => break,
1953 else => switch (sema.mod.intern_pool.indexToKey(check.ip_index)) {1953 else => switch (sema.mod.intern_pool.indexToKey(check.toIntern())) {
1954 .variable => return null,1954 .variable => return null,
1955 .ptr => |ptr| switch (ptr.addr) {1955 .ptr => |ptr| switch (ptr.addr) {
1956 .decl, .mut_decl, .comptime_field => return null,1956 .decl, .mut_decl, .comptime_field => return null,
...@@ -2007,7 +2007,6 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(...@@ -2007,7 +2007,6 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
2007 if (val.isPtrToThreadLocal(sema.mod)) make_runtime.* = true;2007 if (val.isPtrToThreadLocal(sema.mod)) make_runtime.* = true;
2008 return val;2008 return val;
2009 },2009 },
2010 .const_ty => return air_datas[i].ty.toValue(),
2011 .interned => return air_datas[i].interned.toValue(),2010 .interned => return air_datas[i].interned.toValue(),
2012 else => return null,2011 else => return null,
2013 }2012 }
...@@ -2490,7 +2489,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -2490,7 +2489,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
2490 });2489 });
2491 try sema.maybeQueueFuncBodyAnalysis(iac.data.decl_index);2490 try sema.maybeQueueFuncBodyAnalysis(iac.data.decl_index);
2492 return sema.addConstant(ptr_ty, (try sema.mod.intern(.{ .ptr = .{2491 return sema.addConstant(ptr_ty, (try sema.mod.intern(.{ .ptr = .{
2493 .ty = ptr_ty.ip_index,2492 .ty = ptr_ty.toIntern(),
2494 .addr = .{ .mut_decl = .{2493 .addr = .{ .mut_decl = .{
2495 .decl = iac.data.decl_index,2494 .decl = iac.data.decl_index,
2496 .runtime_index = block.runtime_index,2495 .runtime_index = block.runtime_index,
...@@ -2988,7 +2987,7 @@ fn zirEnumDecl(...@@ -2988,7 +2987,7 @@ fn zirEnumDecl(
2988 if (ty.zigTypeTag(mod) != .Int and ty.zigTypeTag(mod) != .ComptimeInt) {2987 if (ty.zigTypeTag(mod) != .Int and ty.zigTypeTag(mod) != .ComptimeInt) {
2989 return sema.fail(block, tag_ty_src, "expected integer tag type, found '{}'", .{ty.fmt(sema.mod)});2988 return sema.fail(block, tag_ty_src, "expected integer tag type, found '{}'", .{ty.fmt(sema.mod)});
2990 }2989 }
2991 incomplete_enum.setTagType(&mod.intern_pool, ty.ip_index);2990 incomplete_enum.setTagType(&mod.intern_pool, ty.toIntern());
2992 break :ty ty;2991 break :ty ty;
2993 } else if (fields_len == 0) {2992 } else if (fields_len == 0) {
2994 break :ty try mod.intType(.unsigned, 0);2993 break :ty try mod.intType(.unsigned, 0);
...@@ -2998,7 +2997,7 @@ fn zirEnumDecl(...@@ -2998,7 +2997,7 @@ fn zirEnumDecl(
2998 }2997 }
2999 };2998 };
30002999
3001 if (small.nonexhaustive and int_tag_ty.ip_index != .comptime_int_type) {3000 if (small.nonexhaustive and int_tag_ty.toIntern() != .comptime_int_type) {
3002 if (fields_len > 1 and std.math.log2_int(u64, fields_len) == int_tag_ty.bitSize(mod)) {3001 if (fields_len > 1 and std.math.log2_int(u64, fields_len) == int_tag_ty.bitSize(mod)) {
3003 return sema.fail(block, src, "non-exhaustive enum specifies every value", .{});3002 return sema.fail(block, src, "non-exhaustive enum specifies every value", .{});
3004 }3003 }
...@@ -3051,7 +3050,7 @@ fn zirEnumDecl(...@@ -3051,7 +3050,7 @@ fn zirEnumDecl(
3051 else => |e| return e,3050 else => |e| return e,
3052 };3051 };
3053 last_tag_val = tag_val;3052 last_tag_val = tag_val;
3054 if (try incomplete_enum.addFieldValue(&mod.intern_pool, gpa, tag_val.ip_index)) |other_index| {3053 if (try incomplete_enum.addFieldValue(&mod.intern_pool, gpa, tag_val.toIntern())) |other_index| {
3055 const value_src = mod.fieldSrcLoc(new_decl_index, .{3054 const value_src = mod.fieldSrcLoc(new_decl_index, .{
3056 .index = field_i,3055 .index = field_i,
3057 .range = .value,3056 .range = .value,
...@@ -3071,7 +3070,7 @@ fn zirEnumDecl(...@@ -3071,7 +3070,7 @@ fn zirEnumDecl(
3071 else3070 else
3072 try mod.intValue(int_tag_ty, 0);3071 try mod.intValue(int_tag_ty, 0);
3073 last_tag_val = tag_val;3072 last_tag_val = tag_val;
3074 if (try incomplete_enum.addFieldValue(&mod.intern_pool, gpa, tag_val.ip_index)) |other_index| {3073 if (try incomplete_enum.addFieldValue(&mod.intern_pool, gpa, tag_val.toIntern())) |other_index| {
3075 const field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = field_i }).lazy;3074 const field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = field_i }).lazy;
3076 const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = other_index }).lazy;3075 const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = other_index }).lazy;
3077 const msg = msg: {3076 const msg = msg: {
...@@ -3742,7 +3741,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3742,7 +3741,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
37423741
3743 try sema.maybeQueueFuncBodyAnalysis(decl_index);3742 try sema.maybeQueueFuncBodyAnalysis(decl_index);
3744 sema.air_values.items[value_index] = (try sema.mod.intern(.{ .ptr = .{3743 sema.air_values.items[value_index] = (try sema.mod.intern(.{ .ptr = .{
3745 .ty = final_ptr_ty.ip_index,3744 .ty = final_ptr_ty.toIntern(),
3746 .addr = if (var_is_mut) .{ .mut_decl = .{3745 .addr = if (var_is_mut) .{ .mut_decl = .{
3747 .decl = decl_index,3746 .decl = decl_index,
3748 .runtime_index = block.runtime_index,3747 .runtime_index = block.runtime_index,
...@@ -3842,7 +3841,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3842,7 +3841,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
3842 block.instructions.shrinkRetainingCapacity(search_index);3841 block.instructions.shrinkRetainingCapacity(search_index);
3843 try sema.maybeQueueFuncBodyAnalysis(new_decl_index);3842 try sema.maybeQueueFuncBodyAnalysis(new_decl_index);
3844 sema.air_values.items[value_index] = (try sema.mod.intern(.{ .ptr = .{3843 sema.air_values.items[value_index] = (try sema.mod.intern(.{ .ptr = .{
3845 .ty = final_elem_ty.ip_index,3844 .ty = final_elem_ty.toIntern(),
3846 .addr = .{ .decl = new_decl_index },3845 .addr = .{ .decl = new_decl_index },
3847 } })).toValue();3846 } })).toValue();
3848 // if bitcast ty ref needs to be made const, make_ptr_const3847 // if bitcast ty ref needs to be made const, make_ptr_const
...@@ -4341,12 +4340,12 @@ fn validateUnionInit(...@@ -4341,12 +4340,12 @@ fn validateUnionInit(
4341 block.instructions.shrinkRetainingCapacity(first_block_index);4340 block.instructions.shrinkRetainingCapacity(first_block_index);
43424341
4343 var union_val = try mod.intern(.{ .un = .{4342 var union_val = try mod.intern(.{ .un = .{
4344 .ty = union_ty.ip_index,4343 .ty = union_ty.toIntern(),
4345 .tag = tag_val.ip_index,4344 .tag = tag_val.toIntern(),
4346 .val = val.ip_index,4345 .val = val.toIntern(),
4347 } });4346 } });
4348 if (make_runtime) union_val = try mod.intern(.{ .runtime_value = .{4347 if (make_runtime) union_val = try mod.intern(.{ .runtime_value = .{
4349 .ty = union_ty.ip_index,4348 .ty = union_ty.toIntern(),
4350 .val = union_val,4349 .val = union_val,
4351 } });4350 } });
4352 const union_init = try sema.addConstant(union_ty, union_val.toValue());4351 const union_init = try sema.addConstant(union_ty, union_val.toValue());
...@@ -4417,7 +4416,7 @@ fn validateStructInit(...@@ -4417,7 +4416,7 @@ fn validateStructInit(
4417 if (field_ptr != 0) continue;4416 if (field_ptr != 0) continue;
44184417
4419 const default_val = struct_ty.structFieldDefaultValue(i, mod);4418 const default_val = struct_ty.structFieldDefaultValue(i, mod);
4420 if (default_val.ip_index == .unreachable_value) {4419 if (default_val.toIntern() == .unreachable_value) {
4421 if (struct_ty.isTuple(mod)) {4420 if (struct_ty.isTuple(mod)) {
4422 const template = "missing tuple field with index {d}";4421 const template = "missing tuple field with index {d}";
4423 if (root_msg) |msg| {4422 if (root_msg) |msg| {
...@@ -4476,15 +4475,14 @@ fn validateStructInit(...@@ -4476,15 +4475,14 @@ fn validateStructInit(
44764475
4477 // We collect the comptime field values in case the struct initialization4476 // We collect the comptime field values in case the struct initialization
4478 // ends up being comptime-known.4477 // ends up being comptime-known.
4479 const field_values = try sema.gpa.alloc(InternPool.Index, struct_ty.structFieldCount(mod));4478 const field_values = try sema.arena.alloc(InternPool.Index, struct_ty.structFieldCount(mod));
4480 defer sema.gpa.free(field_values);
44814479
4482 field: for (found_fields, 0..) |field_ptr, i| {4480 field: for (found_fields, 0..) |field_ptr, i| {
4483 if (field_ptr != 0) {4481 if (field_ptr != 0) {
4484 // Determine whether the value stored to this pointer is comptime-known.4482 // Determine whether the value stored to this pointer is comptime-known.
4485 const field_ty = struct_ty.structFieldType(i, mod);4483 const field_ty = struct_ty.structFieldType(i, mod);
4486 if (try sema.typeHasOnePossibleValue(field_ty)) |opv| {4484 if (try sema.typeHasOnePossibleValue(field_ty)) |opv| {
4487 field_values[i] = opv.ip_index;4485 field_values[i] = opv.toIntern();
4488 continue;4486 continue;
4489 }4487 }
44904488
...@@ -4549,7 +4547,7 @@ fn validateStructInit(...@@ -4549,7 +4547,7 @@ fn validateStructInit(
4549 first_block_index = @min(first_block_index, block_index);4547 first_block_index = @min(first_block_index, block_index);
4550 }4548 }
4551 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {4549 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {
4552 field_values[i] = val.ip_index;4550 field_values[i] = val.toIntern();
4553 } else if (require_comptime) {4551 } else if (require_comptime) {
4554 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;4552 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
4555 return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only struct must be comptime-known");4553 return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only struct must be comptime-known");
...@@ -4563,7 +4561,7 @@ fn validateStructInit(...@@ -4563,7 +4561,7 @@ fn validateStructInit(
4563 }4561 }
45644562
4565 const default_val = struct_ty.structFieldDefaultValue(i, mod);4563 const default_val = struct_ty.structFieldDefaultValue(i, mod);
4566 if (default_val.ip_index == .unreachable_value) {4564 if (default_val.toIntern() == .unreachable_value) {
4567 if (struct_ty.isTuple(mod)) {4565 if (struct_ty.isTuple(mod)) {
4568 const template = "missing tuple field with index {d}";4566 const template = "missing tuple field with index {d}";
4569 if (root_msg) |msg| {4567 if (root_msg) |msg| {
...@@ -4583,7 +4581,7 @@ fn validateStructInit(...@@ -4583,7 +4581,7 @@ fn validateStructInit(
4583 }4581 }
4584 continue;4582 continue;
4585 }4583 }
4586 field_values[i] = default_val.ip_index;4584 field_values[i] = default_val.toIntern();
4587 }4585 }
45884586
4589 if (root_msg) |msg| {4587 if (root_msg) |msg| {
...@@ -4607,11 +4605,11 @@ fn validateStructInit(...@@ -4607,11 +4605,11 @@ fn validateStructInit(
46074605
4608 block.instructions.shrinkRetainingCapacity(first_block_index);4606 block.instructions.shrinkRetainingCapacity(first_block_index);
4609 var struct_val = try mod.intern(.{ .aggregate = .{4607 var struct_val = try mod.intern(.{ .aggregate = .{
4610 .ty = struct_ty.ip_index,4608 .ty = struct_ty.toIntern(),
4611 .storage = .{ .elems = field_values },4609 .storage = .{ .elems = field_values },
4612 } });4610 } });
4613 if (make_runtime) struct_val = try mod.intern(.{ .runtime_value = .{4611 if (make_runtime) struct_val = try mod.intern(.{ .runtime_value = .{
4614 .ty = struct_ty.ip_index,4612 .ty = struct_ty.toIntern(),
4615 .val = struct_val,4613 .val = struct_val,
4616 } });4614 } });
4617 const struct_init = try sema.addConstant(struct_ty, struct_val.toValue());4615 const struct_init = try sema.addConstant(struct_ty, struct_val.toValue());
...@@ -4659,7 +4657,7 @@ fn zirValidateArrayInit(...@@ -4659,7 +4657,7 @@ fn zirValidateArrayInit(
4659 var i = instrs.len;4657 var i = instrs.len;
4660 while (i < array_len) : (i += 1) {4658 while (i < array_len) : (i += 1) {
4661 const default_val = array_ty.structFieldDefaultValue(i, mod);4659 const default_val = array_ty.structFieldDefaultValue(i, mod);
4662 if (default_val.ip_index == .unreachable_value) {4660 if (default_val.toIntern() == .unreachable_value) {
4663 const template = "missing tuple field with index {d}";4661 const template = "missing tuple field with index {d}";
4664 if (root_msg) |msg| {4662 if (root_msg) |msg| {
4665 try sema.errNote(block, init_src, msg, template, .{i});4663 try sema.errNote(block, init_src, msg, template, .{i});
...@@ -4710,8 +4708,7 @@ fn zirValidateArrayInit(...@@ -4710,8 +4708,7 @@ fn zirValidateArrayInit(
4710 // Collect the comptime element values in case the array literal ends up4708 // Collect the comptime element values in case the array literal ends up
4711 // being comptime-known.4709 // being comptime-known.
4712 const array_len_s = try sema.usizeCast(block, init_src, array_ty.arrayLenIncludingSentinel(mod));4710 const array_len_s = try sema.usizeCast(block, init_src, array_ty.arrayLenIncludingSentinel(mod));
4713 const element_vals = try sema.gpa.alloc(InternPool.Index, array_len_s);4711 const element_vals = try sema.arena.alloc(InternPool.Index, array_len_s);
4714 defer sema.gpa.free(element_vals);
4715 const opt_opv = try sema.typeHasOnePossibleValue(array_ty);4712 const opt_opv = try sema.typeHasOnePossibleValue(array_ty);
4716 const air_tags = sema.air_instructions.items(.tag);4713 const air_tags = sema.air_instructions.items(.tag);
4717 const air_datas = sema.air_instructions.items(.data);4714 const air_datas = sema.air_instructions.items(.data);
...@@ -4721,13 +4718,13 @@ fn zirValidateArrayInit(...@@ -4721,13 +4718,13 @@ fn zirValidateArrayInit(
47214718
4722 if (array_ty.isTuple(mod)) {4719 if (array_ty.isTuple(mod)) {
4723 if (try array_ty.structFieldValueComptime(mod, i)) |opv| {4720 if (try array_ty.structFieldValueComptime(mod, i)) |opv| {
4724 element_vals[i] = opv.ip_index;4721 element_vals[i] = opv.toIntern();
4725 continue;4722 continue;
4726 }4723 }
4727 } else {4724 } else {
4728 // Array has one possible value, so value is always comptime-known4725 // Array has one possible value, so value is always comptime-known
4729 if (opt_opv) |opv| {4726 if (opt_opv) |opv| {
4730 element_vals[i] = opv.ip_index;4727 element_vals[i] = opv.toIntern();
4731 continue;4728 continue;
4732 }4729 }
4733 }4730 }
...@@ -4788,7 +4785,7 @@ fn zirValidateArrayInit(...@@ -4788,7 +4785,7 @@ fn zirValidateArrayInit(
4788 first_block_index = @min(first_block_index, block_index);4785 first_block_index = @min(first_block_index, block_index);
4789 }4786 }
4790 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {4787 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {
4791 element_vals[i] = val.ip_index;4788 element_vals[i] = val.toIntern();
4792 } else {4789 } else {
4793 array_is_comptime = false;4790 array_is_comptime = false;
4794 }4791 }
...@@ -4800,7 +4797,7 @@ fn zirValidateArrayInit(...@@ -4800,7 +4797,7 @@ fn zirValidateArrayInit(
48004797
4801 if (array_is_comptime) {4798 if (array_is_comptime) {
4802 if (try sema.resolveDefinedValue(block, init_src, array_ptr)) |ptr_val| {4799 if (try sema.resolveDefinedValue(block, init_src, array_ptr)) |ptr_val| {
4803 switch (mod.intern_pool.indexToKey(ptr_val.ip_index)) {4800 switch (mod.intern_pool.indexToKey(ptr_val.toIntern())) {
4804 .ptr => |ptr| switch (ptr.addr) {4801 .ptr => |ptr| switch (ptr.addr) {
4805 .comptime_field => return, // This store was validated by the individual elem ptrs.4802 .comptime_field => return, // This store was validated by the individual elem ptrs.
4806 else => {},4803 else => {},
...@@ -4813,17 +4810,17 @@ fn zirValidateArrayInit(...@@ -4813,17 +4810,17 @@ fn zirValidateArrayInit(
4813 // instead a single `store` to the array_ptr with a comptime struct value.4810 // instead a single `store` to the array_ptr with a comptime struct value.
4814 // Also to populate the sentinel value, if any.4811 // Also to populate the sentinel value, if any.
4815 if (array_ty.sentinel(mod)) |sentinel_val| {4812 if (array_ty.sentinel(mod)) |sentinel_val| {
4816 element_vals[instrs.len] = sentinel_val.ip_index;4813 element_vals[instrs.len] = sentinel_val.toIntern();
4817 }4814 }
48184815
4819 block.instructions.shrinkRetainingCapacity(first_block_index);4816 block.instructions.shrinkRetainingCapacity(first_block_index);
48204817
4821 var array_val = try mod.intern(.{ .aggregate = .{4818 var array_val = try mod.intern(.{ .aggregate = .{
4822 .ty = array_ty.ip_index,4819 .ty = array_ty.toIntern(),
4823 .storage = .{ .elems = element_vals },4820 .storage = .{ .elems = element_vals },
4824 } });4821 } });
4825 if (make_runtime) array_val = try mod.intern(.{ .runtime_value = .{4822 if (make_runtime) array_val = try mod.intern(.{ .runtime_value = .{
4826 .ty = array_ty.ip_index,4823 .ty = array_ty.toIntern(),
4827 .val = array_val,4824 .val = array_val,
4828 } });4825 } });
4829 const array_init = try sema.addConstant(array_ty, array_val.toValue());4826 const array_init = try sema.addConstant(array_ty, array_val.toValue());
...@@ -5144,41 +5141,26 @@ fn addStrLit(sema: *Sema, block: *Block, zir_bytes: []const u8) CompileError!Air...@@ -5144,41 +5141,26 @@ fn addStrLit(sema: *Sema, block: *Block, zir_bytes: []const u8) CompileError!Air
5144 // expression of a variable declaration.5141 // expression of a variable declaration.
5145 const mod = sema.mod;5142 const mod = sema.mod;
5146 const gpa = sema.gpa;5143 const gpa = sema.gpa;
5147 const string_bytes = &mod.string_literal_bytes;5144 const ty = try mod.arrayType(.{
5148 const StringLiteralAdapter = Module.StringLiteralAdapter;5145 .len = zir_bytes.len,
5149 const StringLiteralContext = Module.StringLiteralContext;5146 .child = .u8_type,
5150 try string_bytes.ensureUnusedCapacity(gpa, zir_bytes.len);5147 .sentinel = .zero_u8,
5151 const gop = try mod.string_literal_table.getOrPutContextAdapted(gpa, zir_bytes, StringLiteralAdapter{
5152 .bytes = string_bytes,
5153 }, StringLiteralContext{
5154 .bytes = string_bytes,
5155 });5148 });
5149 const val = try mod.intern(.{ .aggregate = .{
5150 .ty = ty.toIntern(),
5151 .storage = .{ .bytes = zir_bytes },
5152 } });
5153 const gop = try mod.memoized_decls.getOrPut(gpa, val);
5156 if (!gop.found_existing) {5154 if (!gop.found_existing) {
5157 gop.key_ptr.* = .{
5158 .index = @intCast(u32, string_bytes.items.len),
5159 .len = @intCast(u32, zir_bytes.len),
5160 };
5161 string_bytes.appendSliceAssumeCapacity(zir_bytes);
5162 gop.value_ptr.* = .none;
5163 }
5164 const decl_index = gop.value_ptr.unwrap() orelse di: {
5165 var anon_decl = try block.startAnonDecl();5155 var anon_decl = try block.startAnonDecl();
5166 defer anon_decl.deinit();5156 defer anon_decl.deinit();
51675157
5168 const decl_index = try anon_decl.finish(5158 const decl_index = try anon_decl.finish(ty, val.toValue(), 0);
5169 try Type.array(anon_decl.arena(), gop.key_ptr.len, try mod.intValue(Type.u8, 0), Type.u8, mod),
5170 try Value.Tag.str_lit.create(anon_decl.arena(), gop.key_ptr.*),
5171 0, // default alignment
5172 );
5173
5174 // Needed so that `Decl.clearValues` will additionally set the corresponding
5175 // string literal table value back to `Decl.OptionalIndex.none`.
5176 mod.declPtr(decl_index).owns_tv = true;
51775159
5178 gop.value_ptr.* = decl_index.toOptional();5160 gop.key_ptr.* = val;
5179 break :di decl_index;5161 gop.value_ptr.* = decl_index;
5180 };5162 }
5181 return sema.analyzeDeclRef(decl_index);5163 return sema.analyzeDeclRef(gop.value_ptr.*);
5182}5164}
51835165
5184fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {5166fn zirInt(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
...@@ -6218,7 +6200,7 @@ fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl {...@@ -6218,7 +6200,7 @@ fn funcDeclSrc(sema: *Sema, func_inst: Air.Inst.Ref) !?*Decl {
6218 const mod = sema.mod;6200 const mod = sema.mod;
6219 const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null;6201 const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null;
6220 if (func_val.isUndef(mod)) return null;6202 if (func_val.isUndef(mod)) return null;
6221 const owner_decl_index = switch (mod.intern_pool.indexToKey(func_val.ip_index)) {6203 const owner_decl_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
6222 .extern_func => |extern_func| extern_func.decl,6204 .extern_func => |extern_func| extern_func.decl,
6223 .func => |func| mod.funcPtr(func.index).owner_decl,6205 .func => |func| mod.funcPtr(func.index).owner_decl,
6224 .ptr => |ptr| switch (ptr.addr) {6206 .ptr => |ptr| switch (ptr.addr) {
...@@ -6792,7 +6774,7 @@ fn analyzeCall(...@@ -6792,7 +6774,7 @@ fn analyzeCall(
6792 if (err == error.AnalysisFail and comptime_reason != null) try comptime_reason.?.explain(sema, sema.err);6774 if (err == error.AnalysisFail and comptime_reason != null) try comptime_reason.?.explain(sema, sema.err);
6793 return err;6775 return err;
6794 };6776 };
6795 const module_fn_index = switch (mod.intern_pool.indexToKey(func_val.ip_index)) {6777 const module_fn_index = switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
6796 .extern_func => return sema.fail(block, call_src, "{s} call of extern function", .{6778 .extern_func => return sema.fail(block, call_src, "{s} call of extern function", .{
6797 @as([]const u8, if (is_comptime_call) "comptime" else "inline"),6779 @as([]const u8, if (is_comptime_call) "comptime" else "inline"),
6798 }),6780 }),
...@@ -6996,7 +6978,7 @@ fn analyzeCall(...@@ -6996,7 +6978,7 @@ fn analyzeCall(
6996 }6978 }
6997 break :blk bare_return_type;6979 break :blk bare_return_type;
6998 };6980 };
6999 new_fn_info.return_type = fn_ret_ty.ip_index;6981 new_fn_info.return_type = fn_ret_ty.toIntern();
7000 const parent_fn_ret_ty = sema.fn_ret_ty;6982 const parent_fn_ret_ty = sema.fn_ret_ty;
7001 sema.fn_ret_ty = fn_ret_ty;6983 sema.fn_ret_ty = fn_ret_ty;
7002 defer sema.fn_ret_ty = parent_fn_ret_ty;6984 defer sema.fn_ret_ty = parent_fn_ret_ty;
...@@ -7289,7 +7271,7 @@ fn analyzeInlineCallArg(...@@ -7289,7 +7271,7 @@ fn analyzeInlineCallArg(
7289 if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(sema, sema.err);7271 if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(sema, sema.err);
7290 return err;7272 return err;
7291 };7273 };
7292 switch (arg_val.ip_index) {7274 switch (arg_val.toIntern()) {
7293 .generic_poison, .generic_poison_type => {7275 .generic_poison, .generic_poison_type => {
7294 // This function is currently evaluated as part of an as-of-yet unresolvable7276 // This function is currently evaluated as part of an as-of-yet unresolvable
7295 // parameter or return type.7277 // parameter or return type.
...@@ -7328,7 +7310,7 @@ fn analyzeInlineCallArg(...@@ -7328,7 +7310,7 @@ fn analyzeInlineCallArg(
7328 if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(sema, sema.err);7310 if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(sema, sema.err);
7329 return err;7311 return err;
7330 };7312 };
7331 switch (arg_val.ip_index) {7313 switch (arg_val.toIntern()) {
7332 .generic_poison, .generic_poison_type => {7314 .generic_poison, .generic_poison_type => {
7333 // This function is currently evaluated as part of an as-of-yet unresolvable7315 // This function is currently evaluated as part of an as-of-yet unresolvable
7334 // parameter or return type.7316 // parameter or return type.
...@@ -7426,7 +7408,7 @@ fn instantiateGenericCall(...@@ -7426,7 +7408,7 @@ fn instantiateGenericCall(
7426 const gpa = sema.gpa;7408 const gpa = sema.gpa;
74277409
7428 const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known");7410 const func_val = try sema.resolveConstValue(block, func_src, func, "generic function being called must be comptime-known");
7429 const module_fn = mod.funcPtr(switch (mod.intern_pool.indexToKey(func_val.ip_index)) {7411 const module_fn = mod.funcPtr(switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
7430 .func => |function| function.index,7412 .func => |function| function.index,
7431 .ptr => |ptr| mod.declPtr(ptr.addr.decl).getFunctionIndex(mod).unwrap().?,7413 .ptr => |ptr| mod.declPtr(ptr.addr.decl).getFunctionIndex(mod).unwrap().?,
7432 else => unreachable,7414 else => unreachable,
...@@ -7911,7 +7893,7 @@ fn resolveGenericInstantiationType(...@@ -7911,7 +7893,7 @@ fn resolveGenericInstantiationType(
7911 }7893 }
79127894
7913 new_decl.val = (try mod.intern(.{ .func = .{7895 new_decl.val = (try mod.intern(.{ .func = .{
7914 .ty = new_decl.ty.ip_index,7896 .ty = new_decl.ty.toIntern(),
7915 .index = new_func,7897 .index = new_func,
7916 } })).toValue();7898 } })).toValue();
7917 new_decl.@"align" = 0;7899 new_decl.@"align" = 0;
...@@ -7932,7 +7914,7 @@ fn resolveGenericInstantiationType(...@@ -7932,7 +7914,7 @@ fn resolveGenericInstantiationType(
79327914
7933fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {7915fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {
7934 const mod = sema.mod;7916 const mod = sema.mod;
7935 const tuple = switch (mod.intern_pool.indexToKey(ty.ip_index)) {7917 const tuple = switch (mod.intern_pool.indexToKey(ty.toIntern())) {
7936 .anon_struct_type => |tuple| tuple,7918 .anon_struct_type => |tuple| tuple,
7937 else => return,7919 else => return,
7938 };7920 };
...@@ -7957,7 +7939,7 @@ fn emitDbgInline(...@@ -7957,7 +7939,7 @@ fn emitDbgInline(
7957 if (old_func == new_func) return;7939 if (old_func == new_func) return;
79587940
7959 try sema.air_values.append(sema.gpa, (try sema.mod.intern(.{ .func = .{7941 try sema.air_values.append(sema.gpa, (try sema.mod.intern(.{ .func = .{
7960 .ty = new_func_ty.ip_index,7942 .ty = new_func_ty.toIntern(),
7961 .index = new_func,7943 .index = new_func,
7962 } })).toValue());7944 } })).toValue());
7963 _ = try block.addInst(.{7945 _ = try block.addInst(.{
...@@ -8019,7 +8001,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -8019,7 +8001,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
8019 try sema.checkVectorElemType(block, elem_type_src, elem_type);8001 try sema.checkVectorElemType(block, elem_type_src, elem_type);
8020 const vector_type = try mod.vectorType(.{8002 const vector_type = try mod.vectorType(.{
8021 .len = len,8003 .len = len,
8022 .child = elem_type.ip_index,8004 .child = elem_type.toIntern(),
8023 });8005 });
8024 return sema.addType(vector_type);8006 return sema.addType(vector_type);
8025}8007}
...@@ -8129,7 +8111,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -8129,7 +8111,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
8129 const kv = try sema.mod.getErrorValue(name);8111 const kv = try sema.mod.getErrorValue(name);
8130 const error_set_type = try mod.singleErrorSetType(kv.key);8112 const error_set_type = try mod.singleErrorSetType(kv.key);
8131 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{8113 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
8132 .ty = error_set_type.ip_index,8114 .ty = error_set_type.toIntern(),
8133 .name = try mod.intern_pool.getOrPutString(sema.gpa, kv.key),8115 .name = try mod.intern_pool.getOrPutString(sema.gpa, kv.key),
8134 } })).toValue());8116 } })).toValue());
8135}8117}
...@@ -8149,7 +8131,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -8149,7 +8131,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
8149 if (val.isUndef(mod)) {8131 if (val.isUndef(mod)) {
8150 return sema.addConstUndef(Type.err_int);8132 return sema.addConstUndef(Type.err_int);
8151 }8133 }
8152 const err_name = mod.intern_pool.indexToKey(val.ip_index).err.name;8134 const err_name = mod.intern_pool.indexToKey(val.toIntern()).err.name;
8153 return sema.addConstant(Type.err_int, try mod.intValue(8135 return sema.addConstant(Type.err_int, try mod.intValue(
8154 Type.err_int,8136 Type.err_int,
8155 (try mod.getErrorValue(mod.intern_pool.stringToSlice(err_name))).value,8137 (try mod.getErrorValue(mod.intern_pool.stringToSlice(err_name))).value,
...@@ -8240,7 +8222,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -8240,7 +8222,7 @@ fn zirMergeErrorSets(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
8240 return sema.fail(block, rhs_src, "expected error set type, found '{}'", .{rhs_ty.fmt(sema.mod)});8222 return sema.fail(block, rhs_src, "expected error set type, found '{}'", .{rhs_ty.fmt(sema.mod)});
82418223
8242 // Anything merged with anyerror is anyerror.8224 // Anything merged with anyerror is anyerror.
8243 if (lhs_ty.ip_index == .anyerror_type or rhs_ty.ip_index == .anyerror_type) {8225 if (lhs_ty.toIntern() == .anyerror_type or rhs_ty.toIntern() == .anyerror_type) {
8244 return Air.Inst.Ref.anyerror_type;8226 return Air.Inst.Ref.anyerror_type;
8245 }8227 }
82468228
...@@ -8445,8 +8427,8 @@ fn analyzeOptionalPayloadPtr(...@@ -8445,8 +8427,8 @@ fn analyzeOptionalPayloadPtr(
8445 _ = try block.addTyOp(.optional_payload_ptr_set, child_pointer, optional_ptr);8427 _ = try block.addTyOp(.optional_payload_ptr_set, child_pointer, optional_ptr);
8446 }8428 }
8447 return sema.addConstant(child_pointer, (try mod.intern(.{ .ptr = .{8429 return sema.addConstant(child_pointer, (try mod.intern(.{ .ptr = .{
8448 .ty = child_pointer.ip_index,8430 .ty = child_pointer.toIntern(),
8449 .addr = .{ .opt_payload = ptr_val.ip_index },8431 .addr = .{ .opt_payload = ptr_val.toIntern() },
8450 } })).toValue());8432 } })).toValue());
8451 }8433 }
8452 if (try sema.pointerDeref(block, src, ptr_val, optional_ptr_ty)) |val| {8434 if (try sema.pointerDeref(block, src, ptr_val, optional_ptr_ty)) |val| {
...@@ -8455,8 +8437,8 @@ fn analyzeOptionalPayloadPtr(...@@ -8455,8 +8437,8 @@ fn analyzeOptionalPayloadPtr(
8455 }8437 }
8456 // The same Value represents the pointer to the optional and the payload.8438 // The same Value represents the pointer to the optional and the payload.
8457 return sema.addConstant(child_pointer, (try mod.intern(.{ .ptr = .{8439 return sema.addConstant(child_pointer, (try mod.intern(.{ .ptr = .{
8458 .ty = child_pointer.ip_index,8440 .ty = child_pointer.toIntern(),
8459 .addr = .{ .opt_payload = ptr_val.ip_index },8441 .addr = .{ .opt_payload = ptr_val.toIntern() },
8460 } })).toValue());8442 } })).toValue());
8461 }8443 }
8462 }8444 }
...@@ -8565,7 +8547,7 @@ fn analyzeErrUnionPayload(...@@ -8565,7 +8547,7 @@ fn analyzeErrUnionPayload(
8565 }8547 }
8566 return sema.addConstant(8548 return sema.addConstant(
8567 payload_ty,8549 payload_ty,
8568 mod.intern_pool.indexToKey(val.ip_index).error_union.val.payload.toValue(),8550 mod.intern_pool.indexToKey(val.toIntern()).error_union.val.payload.toValue(),
8569 );8551 );
8570 }8552 }
85718553
...@@ -8633,8 +8615,8 @@ fn analyzeErrUnionPayloadPtr(...@@ -8633,8 +8615,8 @@ fn analyzeErrUnionPayloadPtr(
8633 _ = try block.addTyOp(.errunion_payload_ptr_set, operand_pointer_ty, operand);8615 _ = try block.addTyOp(.errunion_payload_ptr_set, operand_pointer_ty, operand);
8634 }8616 }
8635 return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{8617 return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{
8636 .ty = operand_pointer_ty.ip_index,8618 .ty = operand_pointer_ty.toIntern(),
8637 .addr = .{ .eu_payload = ptr_val.ip_index },8619 .addr = .{ .eu_payload = ptr_val.toIntern() },
8638 } })).toValue());8620 } })).toValue());
8639 }8621 }
8640 if (try sema.pointerDeref(block, src, ptr_val, operand_ty)) |val| {8622 if (try sema.pointerDeref(block, src, ptr_val, operand_ty)) |val| {
...@@ -8642,8 +8624,8 @@ fn analyzeErrUnionPayloadPtr(...@@ -8642,8 +8624,8 @@ fn analyzeErrUnionPayloadPtr(
8642 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});8624 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});
8643 }8625 }
8644 return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{8626 return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{
8645 .ty = operand_pointer_ty.ip_index,8627 .ty = operand_pointer_ty.toIntern(),
8646 .addr = .{ .eu_payload = ptr_val.ip_index },8628 .addr = .{ .eu_payload = ptr_val.toIntern() },
8647 } })).toValue());8629 } })).toValue());
8648 }8630 }
8649 }8631 }
...@@ -8828,7 +8810,7 @@ fn resolveGenericBody(...@@ -8828,7 +8810,7 @@ fn resolveGenericBody(
8828 };8810 };
8829 switch (err) {8811 switch (err) {
8830 error.GenericPoison => {8812 error.GenericPoison => {
8831 if (dest_ty.ip_index == .type_type) {8813 if (dest_ty.toIntern() == .type_type) {
8832 return Value.generic_poison_type;8814 return Value.generic_poison_type;
8833 } else {8815 } else {
8834 return Value.generic_poison;8816 return Value.generic_poison;
...@@ -9183,7 +9165,7 @@ fn funcCommon(...@@ -9183,7 +9165,7 @@ fn funcCommon(
91839165
9184 if (is_extern) {9166 if (is_extern) {
9185 return sema.addConstant(fn_ty, (try mod.intern(.{ .extern_func = .{9167 return sema.addConstant(fn_ty, (try mod.intern(.{ .extern_func = .{
9186 .ty = fn_ty.ip_index,9168 .ty = fn_ty.toIntern(),
9187 .decl = sema.owner_decl_index,9169 .decl = sema.owner_decl_index,
9188 .lib_name = if (opt_lib_name) |lib_name| (try mod.intern_pool.getOrPutString(9170 .lib_name = if (opt_lib_name) |lib_name| (try mod.intern_pool.getOrPutString(
9189 gpa,9171 gpa,
...@@ -9223,7 +9205,7 @@ fn funcCommon(...@@ -9223,7 +9205,7 @@ fn funcCommon(
9223 .is_noinline = is_noinline,9205 .is_noinline = is_noinline,
9224 };9206 };
9225 return sema.addConstant(fn_ty, (try mod.intern(.{ .func = .{9207 return sema.addConstant(fn_ty, (try mod.intern(.{ .func = .{
9226 .ty = fn_ty.ip_index,9208 .ty = fn_ty.toIntern(),
9227 .index = new_func_index,9209 .index = new_func_index,
9228 } })).toValue());9210 } })).toValue());
9229}9211}
...@@ -10151,16 +10133,16 @@ fn zirSwitchCapture(...@@ -10151,16 +10133,16 @@ fn zirSwitchCapture(
10151 .@"addrspace" = operand_ptr_ty.ptrAddressSpace(mod),10133 .@"addrspace" = operand_ptr_ty.ptrAddressSpace(mod),
10152 });10134 });
10153 return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{10135 return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{
10154 .ty = ptr_field_ty.ip_index,10136 .ty = ptr_field_ty.toIntern(),
10155 .addr = .{ .field = .{10137 .addr = .{ .field = .{
10156 .base = union_val.ip_index,10138 .base = union_val.toIntern(),
10157 .index = field_index,10139 .index = field_index,
10158 } },10140 } },
10159 } })).toValue());10141 } })).toValue());
10160 }10142 }
10161 return sema.addConstant(10143 return sema.addConstant(
10162 field_ty,10144 field_ty,
10163 mod.intern_pool.indexToKey(union_val.ip_index).un.val.toValue(),10145 mod.intern_pool.indexToKey(union_val.toIntern()).un.val.toValue(),
10164 );10146 );
10165 }10147 }
10166 if (is_ref) {10148 if (is_ref) {
...@@ -10256,9 +10238,9 @@ fn zirSwitchCapture(...@@ -10256,9 +10238,9 @@ fn zirSwitchCapture(
1025610238
10257 if (try sema.resolveDefinedValue(block, operand_src, operand_ptr)) |op_ptr_val| {10239 if (try sema.resolveDefinedValue(block, operand_src, operand_ptr)) |op_ptr_val| {
10258 return sema.addConstant(field_ty_ptr, (try mod.intern(.{ .ptr = .{10240 return sema.addConstant(field_ty_ptr, (try mod.intern(.{ .ptr = .{
10259 .ty = field_ty_ptr.ip_index,10241 .ty = field_ty_ptr.toIntern(),
10260 .addr = .{ .field = .{10242 .addr = .{ .field = .{
10261 .base = op_ptr_val.ip_index,10243 .base = op_ptr_val.toIntern(),
10262 .index = first_field_index,10244 .index = first_field_index,
10263 } },10245 } },
10264 } })).toValue());10246 } })).toValue());
...@@ -11502,7 +11484,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -11502,7 +11484,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
11502 cases_len += 1;11484 cases_len += 1;
1150311485
11504 const item_val = try mod.intern(.{ .err = .{11486 const item_val = try mod.intern(.{ .err = .{
11505 .ty = operand_ty.ip_index,11487 .ty = operand_ty.toIntern(),
11506 .name = error_name_ip,11488 .name = error_name_ip,
11507 } });11489 } });
11508 const item_ref = try sema.addConstant(operand_ty, item_val.toValue());11490 const item_ref = try sema.addConstant(operand_ty, item_val.toValue());
...@@ -11802,7 +11784,7 @@ fn validateSwitchItemError(...@@ -11802,7 +11784,7 @@ fn validateSwitchItemError(
11802 const ip = &sema.mod.intern_pool;11784 const ip = &sema.mod.intern_pool;
11803 const item_tv = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none);11785 const item_tv = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none);
11804 // TODO: Do i need to typecheck here?11786 // TODO: Do i need to typecheck here?
11805 const error_name = ip.stringToSlice(ip.indexToKey(item_tv.val.ip_index).err.name);11787 const error_name = ip.stringToSlice(ip.indexToKey(item_tv.val.toIntern()).err.name);
11806 const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev|11788 const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev|
11807 prev.value11789 prev.value
11808 else11790 else
...@@ -12035,7 +12017,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -12035,7 +12017,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
12035 const ip = &mod.intern_pool;12017 const ip = &mod.intern_pool;
1203612018
12037 const has_field = hf: {12019 const has_field = hf: {
12038 switch (ip.indexToKey(ty.ip_index)) {12020 switch (ip.indexToKey(ty.toIntern())) {
12039 .ptr_type => |ptr_type| switch (ptr_type.size) {12021 .ptr_type => |ptr_type| switch (ptr_type.size) {
12040 .Slice => {12022 .Slice => {
12041 if (mem.eql(u8, field_name, "ptr")) break :hf true;12023 if (mem.eql(u8, field_name, "ptr")) break :hf true;
...@@ -12160,17 +12142,23 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -12160,17 +12142,23 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
12160 var anon_decl = try block.startAnonDecl();12142 var anon_decl = try block.startAnonDecl();
12161 defer anon_decl.deinit();12143 defer anon_decl.deinit();
1216212144
12163 const bytes_including_null = embed_file.bytes[0 .. embed_file.bytes.len + 1];12145 // TODO instead of using `.bytes`, create a new value tag for pointing at
12164
12165 // TODO instead of using `Value.Tag.bytes`, create a new value tag for pointing at
12166 // a `*Module.EmbedFile`. The purpose of this would be:12146 // a `*Module.EmbedFile`. The purpose of this would be:
12167 // - If only the length is read and the bytes are not inspected by comptime code,12147 // - If only the length is read and the bytes are not inspected by comptime code,
12168 // there can be an optimization where the codegen backend does a copy_file_range12148 // there can be an optimization where the codegen backend does a copy_file_range
12169 // into the final binary, and never loads the data into memory.12149 // into the final binary, and never loads the data into memory.
12170 // - When a Decl is destroyed, it can free the `*Module.EmbedFile`.12150 // - When a Decl is destroyed, it can free the `*Module.EmbedFile`.
12151 const ty = try mod.arrayType(.{
12152 .len = embed_file.bytes.len,
12153 .child = .u8_type,
12154 .sentinel = .zero_u8,
12155 });
12171 embed_file.owner_decl = try anon_decl.finish(12156 embed_file.owner_decl = try anon_decl.finish(
12172 try Type.array(anon_decl.arena(), embed_file.bytes.len, try mod.intValue(Type.u8, 0), Type.u8, mod),12157 ty,
12173 try Value.Tag.bytes.create(anon_decl.arena(), bytes_including_null),12158 (try mod.intern(.{ .aggregate = .{
12159 .ty = ty.toIntern(),
12160 .storage = .{ .bytes = embed_file.bytes },
12161 } })).toValue(),
12174 0, // default alignment12162 0, // default alignment
12175 );12163 );
1217612164
...@@ -12186,7 +12174,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R...@@ -12186,7 +12174,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R
12186 const kv = try mod.getErrorValue(err_name);12174 const kv = try mod.getErrorValue(err_name);
12187 const error_set_type = try mod.singleErrorSetType(kv.key);12175 const error_set_type = try mod.singleErrorSetType(kv.key);
12188 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{12176 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
12189 .ty = error_set_type.ip_index,12177 .ty = error_set_type.toIntern(),
12190 .name = mod.intern_pool.getString(kv.key).unwrap().?,12178 .name = mod.intern_pool.getString(kv.key).unwrap().?,
12191 } })).toValue());12179 } })).toValue());
12192}12180}
...@@ -12597,15 +12585,15 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -12597,15 +12585,15 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
12597 return sema.addConstUndef(operand_type);12585 return sema.addConstUndef(operand_type);
12598 } else if (operand_type.zigTypeTag(mod) == .Vector) {12586 } else if (operand_type.zigTypeTag(mod) == .Vector) {
12599 const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod));12587 const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod));
12600 const elems = try sema.arena.alloc(Value, vec_len);12588 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
12601 for (elems, 0..) |*elem, i| {12589 for (elems, 0..) |*elem, i| {
12602 const elem_val = try val.elemValue(sema.mod, i);12590 const elem_val = try val.elemValue(sema.mod, i);
12603 elem.* = try elem_val.bitwiseNot(scalar_type, sema.arena, sema.mod);12591 elem.* = try (try elem_val.bitwiseNot(scalar_type, sema.arena, sema.mod)).intern(scalar_type, mod);
12604 }12592 }
12605 return sema.addConstant(12593 return sema.addConstant(operand_type, (try mod.intern(.{ .aggregate = .{
12606 operand_type,12594 .ty = operand_type.toIntern(),
12607 try Value.Tag.aggregate.create(sema.arena, elems),12595 .storage = .{ .elems = elems },
12608 );12596 } })).toValue());
12609 } else {12597 } else {
12610 const result_val = try val.bitwiseNot(operand_type, sema.arena, sema.mod);12598 const result_val = try val.bitwiseNot(operand_type, sema.arena, sema.mod);
12611 return sema.addConstant(operand_type, result_val);12599 return sema.addConstant(operand_type, result_val);
...@@ -12652,22 +12640,22 @@ fn analyzeTupleCat(...@@ -12652,22 +12640,22 @@ fn analyzeTupleCat(
12652 var runtime_src: ?LazySrcLoc = null;12640 var runtime_src: ?LazySrcLoc = null;
12653 var i: u32 = 0;12641 var i: u32 = 0;
12654 while (i < lhs_len) : (i += 1) {12642 while (i < lhs_len) : (i += 1) {
12655 types[i] = lhs_ty.structFieldType(i, mod).ip_index;12643 types[i] = lhs_ty.structFieldType(i, mod).toIntern();
12656 const default_val = lhs_ty.structFieldDefaultValue(i, mod);12644 const default_val = lhs_ty.structFieldDefaultValue(i, mod);
12657 values[i] = default_val.ip_index;12645 values[i] = default_val.toIntern();
12658 const operand_src = lhs_src; // TODO better source location12646 const operand_src = lhs_src; // TODO better source location
12659 if (default_val.ip_index == .unreachable_value) {12647 if (default_val.toIntern() == .unreachable_value) {
12660 runtime_src = operand_src;12648 runtime_src = operand_src;
12661 values[i] = .none;12649 values[i] = .none;
12662 }12650 }
12663 }12651 }
12664 i = 0;12652 i = 0;
12665 while (i < rhs_len) : (i += 1) {12653 while (i < rhs_len) : (i += 1) {
12666 types[i + lhs_len] = rhs_ty.structFieldType(i, mod).ip_index;12654 types[i + lhs_len] = rhs_ty.structFieldType(i, mod).toIntern();
12667 const default_val = rhs_ty.structFieldDefaultValue(i, mod);12655 const default_val = rhs_ty.structFieldDefaultValue(i, mod);
12668 values[i + lhs_len] = default_val.ip_index;12656 values[i + lhs_len] = default_val.toIntern();
12669 const operand_src = rhs_src; // TODO better source location12657 const operand_src = rhs_src; // TODO better source location
12670 if (default_val.ip_index == .unreachable_value) {12658 if (default_val.toIntern() == .unreachable_value) {
12671 runtime_src = operand_src;12659 runtime_src = operand_src;
12672 values[i + lhs_len] = .none;12660 values[i + lhs_len] = .none;
12673 }12661 }
...@@ -12824,34 +12812,32 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -12824,34 +12812,32 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
12824 else12812 else
12825 rhs_val;12813 rhs_val;
1282612814
12827 const final_len_including_sent = result_len + @boolToInt(res_sent_val != null);12815 const element_vals = try sema.arena.alloc(InternPool.Index, result_len);
12828 const element_vals = try sema.arena.alloc(Value, final_len_including_sent);
12829 var elem_i: usize = 0;12816 var elem_i: usize = 0;
12830 while (elem_i < lhs_len) : (elem_i += 1) {12817 while (elem_i < lhs_len) : (elem_i += 1) {
12831 const lhs_elem_i = elem_i;12818 const lhs_elem_i = elem_i;
12832 const elem_ty = if (lhs_is_tuple) lhs_ty.structFieldType(lhs_elem_i, mod) else lhs_info.elem_type;12819 const elem_ty = if (lhs_is_tuple) lhs_ty.structFieldType(lhs_elem_i, mod) else lhs_info.elem_type;
12833 const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable";12820 const elem_default_val = if (lhs_is_tuple) lhs_ty.structFieldDefaultValue(lhs_elem_i, mod) else Value.@"unreachable";
12834 const elem_val = if (elem_default_val.ip_index == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;12821 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try lhs_sub_val.elemValue(mod, lhs_elem_i) else elem_default_val;
12835 const elem_val_inst = try sema.addConstant(elem_ty, elem_val);12822 const elem_val_inst = try sema.addConstant(elem_ty, elem_val);
12836 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);12823 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
12837 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, "");12824 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, "");
12838 element_vals[elem_i] = coerced_elem_val;12825 element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod);
12839 }12826 }
12840 while (elem_i < result_len) : (elem_i += 1) {12827 while (elem_i < result_len) : (elem_i += 1) {
12841 const rhs_elem_i = elem_i - lhs_len;12828 const rhs_elem_i = elem_i - lhs_len;
12842 const elem_ty = if (rhs_is_tuple) rhs_ty.structFieldType(rhs_elem_i, mod) else rhs_info.elem_type;12829 const elem_ty = if (rhs_is_tuple) rhs_ty.structFieldType(rhs_elem_i, mod) else rhs_info.elem_type;
12843 const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable";12830 const elem_default_val = if (rhs_is_tuple) rhs_ty.structFieldDefaultValue(rhs_elem_i, mod) else Value.@"unreachable";
12844 const elem_val = if (elem_default_val.ip_index == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;12831 const elem_val = if (elem_default_val.toIntern() == .unreachable_value) try rhs_sub_val.elemValue(mod, rhs_elem_i) else elem_default_val;
12845 const elem_val_inst = try sema.addConstant(elem_ty, elem_val);12832 const elem_val_inst = try sema.addConstant(elem_ty, elem_val);
12846 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);12833 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
12847 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, "");12834 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, "");
12848 element_vals[elem_i] = coerced_elem_val;12835 element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod);
12849 }
12850 if (res_sent_val) |sent_val| {
12851 element_vals[result_len] = sent_val;
12852 }12836 }
12853 const val = try Value.Tag.aggregate.create(sema.arena, element_vals);12837 return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{
12854 return sema.addConstantMaybeRef(block, result_ty, val, ptr_addrspace != null);12838 .ty = result_ty.toIntern(),
12839 .storage = .{ .elems = element_vals },
12840 } })).toValue(), ptr_addrspace != null);
12855 } else break :rs rhs_src;12841 } else break :rs rhs_src;
12856 } else lhs_src;12842 } else lhs_src;
1285712843
...@@ -12978,8 +12964,8 @@ fn analyzeTupleMul(...@@ -12978,8 +12964,8 @@ fn analyzeTupleMul(
12978 const opt_runtime_src = rs: {12964 const opt_runtime_src = rs: {
12979 var runtime_src: ?LazySrcLoc = null;12965 var runtime_src: ?LazySrcLoc = null;
12980 for (0..tuple_len) |i| {12966 for (0..tuple_len) |i| {
12981 types[i] = operand_ty.structFieldType(i, mod).ip_index;12967 types[i] = operand_ty.structFieldType(i, mod).toIntern();
12982 values[i] = operand_ty.structFieldDefaultValue(i, mod).ip_index;12968 values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern();
12983 const operand_src = lhs_src; // TODO better source location12969 const operand_src = lhs_src; // TODO better source location
12984 if (values[i] == .unreachable_value) {12970 if (values[i] == .unreachable_value) {
12985 runtime_src = operand_src;12971 runtime_src = operand_src;
...@@ -13086,8 +13072,8 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13086,8 +13072,8 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13086 if (lhs_len == 1) {13072 if (lhs_len == 1) {
13087 const elem_val = try lhs_sub_val.elemValue(mod, 0);13073 const elem_val = try lhs_sub_val.elemValue(mod, 0);
13088 break :v try mod.intern(.{ .aggregate = .{13074 break :v try mod.intern(.{ .aggregate = .{
13089 .ty = result_ty.ip_index,13075 .ty = result_ty.toIntern(),
13090 .storage = .{ .repeated_elem = elem_val.ip_index },13076 .storage = .{ .repeated_elem = elem_val.toIntern() },
13091 } });13077 } });
13092 }13078 }
1309313079
...@@ -13097,16 +13083,15 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13097,16 +13083,15 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13097 var lhs_i: usize = 0;13083 var lhs_i: usize = 0;
13098 while (lhs_i < lhs_len) : (lhs_i += 1) {13084 while (lhs_i < lhs_len) : (lhs_i += 1) {
13099 const elem_val = try lhs_sub_val.elemValue(mod, lhs_i);13085 const elem_val = try lhs_sub_val.elemValue(mod, lhs_i);
13100 assert(elem_val.ip_index != .none);13086 element_vals[elem_i] = elem_val.toIntern();
13101 element_vals[elem_i] = elem_val.ip_index;
13102 elem_i += 1;13087 elem_i += 1;
13103 }13088 }
13104 }13089 }
13105 if (lhs_info.sentinel) |sent_val| {13090 if (lhs_info.sentinel) |sent_val| {
13106 element_vals[result_len] = sent_val.ip_index;13091 element_vals[result_len] = sent_val.toIntern();
13107 }13092 }
13108 break :v try mod.intern(.{ .aggregate = .{13093 break :v try mod.intern(.{ .aggregate = .{
13109 .ty = result_ty.ip_index,13094 .ty = result_ty.toIntern(),
13110 .storage = .{ .elems = element_vals },13095 .storage = .{ .elems = element_vals },
13111 } });13096 } });
13112 };13097 };
...@@ -13998,8 +13983,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air....@@ -13998,8 +13983,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
13998 else => unreachable,13983 else => unreachable,
13999 };13984 };
14000 const zero_val = if (is_vector) (try mod.intern(.{ .aggregate = .{13985 const zero_val = if (is_vector) (try mod.intern(.{ .aggregate = .{
14001 .ty = resolved_type.ip_index,13986 .ty = resolved_type.toIntern(),
14002 .storage = .{ .repeated_elem = scalar_zero.ip_index },13987 .storage = .{ .repeated_elem = scalar_zero.toIntern() },
14003 } })).toValue() else scalar_zero;13988 } })).toValue() else scalar_zero;
14004 return sema.addConstant(resolved_type, zero_val);13989 return sema.addConstant(resolved_type, zero_val);
14005 }13990 }
...@@ -14079,14 +14064,17 @@ fn intRem(...@@ -14079,14 +14064,17 @@ fn intRem(
14079) CompileError!Value {14064) CompileError!Value {
14080 const mod = sema.mod;14065 const mod = sema.mod;
14081 if (ty.zigTypeTag(mod) == .Vector) {14066 if (ty.zigTypeTag(mod) == .Vector) {
14082 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));14067 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));
14083 const scalar_ty = ty.scalarType(mod);14068 const scalar_ty = ty.scalarType(mod);
14084 for (result_data, 0..) |*scalar, i| {14069 for (result_data, 0..) |*scalar, i| {
14085 const lhs_elem = try lhs.elemValue(sema.mod, i);14070 const lhs_elem = try lhs.elemValue(sema.mod, i);
14086 const rhs_elem = try rhs.elemValue(sema.mod, i);14071 const rhs_elem = try rhs.elemValue(sema.mod, i);
14087 scalar.* = try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty);14072 scalar.* = try (try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod);
14088 }14073 }
14089 return Value.Tag.aggregate.create(sema.arena, result_data);14074 return (try mod.intern(.{ .aggregate = .{
14075 .ty = ty.toIntern(),
14076 .storage = .{ .elems = result_data },
14077 } })).toValue();
14090 }14078 }
14091 return sema.intRemScalar(lhs, rhs, ty);14079 return sema.intRemScalar(lhs, rhs, ty);
14092}14080}
...@@ -14517,11 +14505,13 @@ fn zirOverflowArithmetic(...@@ -14517,11 +14505,13 @@ fn zirOverflowArithmetic(
14517 }14505 }
1451814506
14519 if (result.inst == .none) {14507 if (result.inst == .none) {
14520 const values = try sema.arena.alloc(Value, 2);14508 return sema.addConstant(tuple_ty, (try mod.intern(.{ .aggregate = .{
14521 values[0] = result.wrapped;14509 .ty = tuple_ty.toIntern(),
14522 values[1] = result.overflow_bit;14510 .storage = .{ .elems = &.{
14523 const tuple_val = try Value.Tag.aggregate.create(sema.arena, values);14511 result.wrapped.toIntern(),
14524 return sema.addConstant(tuple_ty, tuple_val);14512 result.overflow_bit.toIntern(),
14513 } },
14514 } })).toValue());
14525 }14515 }
1452614516
14527 const element_refs = try sema.arena.alloc(Air.Inst.Ref, 2);14517 const element_refs = try sema.arena.alloc(Air.Inst.Ref, 2);
...@@ -14534,8 +14524,8 @@ fn splat(sema: *Sema, ty: Type, val: Value) !Value {...@@ -14534,8 +14524,8 @@ fn splat(sema: *Sema, ty: Type, val: Value) !Value {
14534 const mod = sema.mod;14524 const mod = sema.mod;
14535 if (ty.zigTypeTag(mod) != .Vector) return val;14525 if (ty.zigTypeTag(mod) != .Vector) return val;
14536 const repeated = try mod.intern(.{ .aggregate = .{14526 const repeated = try mod.intern(.{ .aggregate = .{
14537 .ty = ty.ip_index,14527 .ty = ty.toIntern(),
14538 .storage = .{ .repeated_elem = val.ip_index },14528 .storage = .{ .repeated_elem = val.toIntern() },
14539 } });14529 } });
14540 return repeated.toValue();14530 return repeated.toValue();
14541}14531}
...@@ -14547,7 +14537,7 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {...@@ -14547,7 +14537,7 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
14547 .child = .u1_type,14537 .child = .u1_type,
14548 }) else Type.u1;14538 }) else Type.u1;
1454914539
14550 const types = [2]InternPool.Index{ ty.ip_index, ov_ty.ip_index };14540 const types = [2]InternPool.Index{ ty.toIntern(), ov_ty.toIntern() };
14551 const values = [2]InternPool.Index{ .none, .none };14541 const values = [2]InternPool.Index{ .none, .none };
14552 const tuple_ty = try mod.intern(.{ .anon_struct_type = .{14542 const tuple_ty = try mod.intern(.{ .anon_struct_type = .{
14553 .types = &types,14543 .types = &types,
...@@ -15731,7 +15721,7 @@ fn zirClosureGet(...@@ -15731,7 +15721,7 @@ fn zirClosureGet(
15731 scope = scope.parent.?;15721 scope = scope.parent.?;
15732 };15722 };
1573315723
15734 if (tv.val.ip_index == .unreachable_value and !block.is_typeof and sema.func_index == .none) {15724 if (tv.val.toIntern() == .unreachable_value and !block.is_typeof and sema.func_index == .none) {
15735 const msg = msg: {15725 const msg = msg: {
15736 const name = name: {15726 const name = name: {
15737 const file = sema.owner_decl.getFileScope(mod);15727 const file = sema.owner_decl.getFileScope(mod);
...@@ -15759,7 +15749,7 @@ fn zirClosureGet(...@@ -15759,7 +15749,7 @@ fn zirClosureGet(
15759 return sema.failWithOwnedErrorMsg(msg);15749 return sema.failWithOwnedErrorMsg(msg);
15760 }15750 }
1576115751
15762 if (tv.val.ip_index == .unreachable_value and !block.is_typeof and !block.is_comptime and sema.func_index != .none) {15752 if (tv.val.toIntern() == .unreachable_value and !block.is_typeof and !block.is_comptime and sema.func_index != .none) {
15763 const msg = msg: {15753 const msg = msg: {
15764 const name = name: {15754 const name = name: {
15765 const file = sema.owner_decl.getFileScope(mod);15755 const file = sema.owner_decl.getFileScope(mod);
...@@ -15789,7 +15779,7 @@ fn zirClosureGet(...@@ -15789,7 +15779,7 @@ fn zirClosureGet(
15789 return sema.failWithOwnedErrorMsg(msg);15779 return sema.failWithOwnedErrorMsg(msg);
15790 }15780 }
1579115781
15792 if (tv.val.ip_index == .unreachable_value) {15782 if (tv.val.toIntern() == .unreachable_value) {
15793 assert(block.is_typeof);15783 assert(block.is_typeof);
15794 // We need a dummy runtime instruction with the correct type.15784 // We need a dummy runtime instruction with the correct type.
15795 return block.addTy(.alloc, tv.ty);15785 return block.addTy(.alloc, tv.ty);
...@@ -15840,10 +15830,17 @@ fn zirBuiltinSrc(...@@ -15840,10 +15830,17 @@ fn zirBuiltinSrc(
15840 var anon_decl = try block.startAnonDecl();15830 var anon_decl = try block.startAnonDecl();
15841 defer anon_decl.deinit();15831 defer anon_decl.deinit();
15842 const name = mem.span(fn_owner_decl.name);15832 const name = mem.span(fn_owner_decl.name);
15843 const bytes = try anon_decl.arena().dupe(u8, name[0 .. name.len + 1]);15833 const new_decl_ty = try mod.arrayType(.{
15834 .len = name.len,
15835 .child = .u8_type,
15836 .sentinel = .zero_u8,
15837 });
15844 const new_decl = try anon_decl.finish(15838 const new_decl = try anon_decl.finish(
15845 try Type.array(anon_decl.arena(), bytes.len - 1, try mod.intValue(Type.u8, 0), Type.u8, mod),15839 new_decl_ty,
15846 try Value.Tag.bytes.create(anon_decl.arena(), bytes),15840 (try mod.intern(.{ .aggregate = .{
15841 .ty = new_decl_ty.toIntern(),
15842 .storage = .{ .bytes = name },
15843 } })).toValue(),
15847 0, // default alignment15844 0, // default alignment
15848 );15845 );
15849 break :blk try mod.intern(.{ .ptr = .{15846 break :blk try mod.intern(.{ .ptr = .{
...@@ -15857,9 +15854,17 @@ fn zirBuiltinSrc(...@@ -15857,9 +15854,17 @@ fn zirBuiltinSrc(
15857 defer anon_decl.deinit();15854 defer anon_decl.deinit();
15858 // The compiler must not call realpath anywhere.15855 // The compiler must not call realpath anywhere.
15859 const name = try fn_owner_decl.getFileScope(mod).fullPathZ(anon_decl.arena());15856 const name = try fn_owner_decl.getFileScope(mod).fullPathZ(anon_decl.arena());
15857 const new_decl_ty = try mod.arrayType(.{
15858 .len = name.len,
15859 .child = .u8_type,
15860 .sentinel = .zero_u8,
15861 });
15860 const new_decl = try anon_decl.finish(15862 const new_decl = try anon_decl.finish(
15861 try Type.array(anon_decl.arena(), name.len, try mod.intValue(Type.u8, 0), Type.u8, mod),15863 new_decl_ty,
15862 try Value.Tag.bytes.create(anon_decl.arena(), name[0 .. name.len + 1]),15864 (try mod.intern(.{ .aggregate = .{
15865 .ty = new_decl_ty.toIntern(),
15866 .storage = .{ .bytes = name },
15867 } })).toValue(),
15863 0, // default alignment15868 0, // default alignment
15864 );15869 );
15865 break :blk try mod.intern(.{ .ptr = .{15870 break :blk try mod.intern(.{ .ptr = .{
...@@ -15877,13 +15882,13 @@ fn zirBuiltinSrc(...@@ -15877,13 +15882,13 @@ fn zirBuiltinSrc(
15877 // line: u32,15882 // line: u32,
15878 try mod.intern(.{ .runtime_value = .{15883 try mod.intern(.{ .runtime_value = .{
15879 .ty = .u32_type,15884 .ty = .u32_type,
15880 .val = (try mod.intValue(Type.u32, extra.line + 1)).ip_index,15885 .val = (try mod.intValue(Type.u32, extra.line + 1)).toIntern(),
15881 } }),15886 } }),
15882 // column: u32,15887 // column: u32,
15883 (try mod.intValue(Type.u32, extra.column + 1)).ip_index,15888 (try mod.intValue(Type.u32, extra.column + 1)).toIntern(),
15884 };15889 };
15885 return sema.addConstant(src_loc_ty, (try mod.intern(.{ .aggregate = .{15890 return sema.addConstant(src_loc_ty, (try mod.intern(.{ .aggregate = .{
15886 .ty = src_loc_ty.ip_index,15891 .ty = src_loc_ty.toIntern(),
15887 .storage = .{ .elems = &fields },15892 .storage = .{ .elems = &fields },
15888 } })).toValue());15893 } })).toValue());
15889}15894}
...@@ -15908,8 +15913,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15908,8 +15913,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15908 .Null,15913 .Null,
15909 .EnumLiteral,15914 .EnumLiteral,
15910 => |type_info_tag| return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{15915 => |type_info_tag| return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
15911 .ty = type_info_ty.ip_index,15916 .ty = type_info_ty.toIntern(),
15912 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(type_info_tag))).ip_index,15917 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(type_info_tag))).toIntern(),
15913 .val = .void_value,15918 .val = .void_value,
15914 } })).toValue()),15919 } })).toValue()),
15915 .Fn => {15920 .Fn => {
...@@ -15941,8 +15946,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15941,8 +15946,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
15941 const param_info_decl = mod.declPtr(param_info_decl_index);15946 const param_info_decl = mod.declPtr(param_info_decl_index);
15942 const param_info_ty = param_info_decl.val.toType();15947 const param_info_ty = param_info_decl.val.toType();
1594315948
15944 const param_vals = try gpa.alloc(InternPool.Index, info.param_types.len);15949 const param_vals = try sema.arena.alloc(InternPool.Index, info.param_types.len);
15945 defer gpa.free(param_vals);
15946 for (param_vals, info.param_types, 0..) |*param_val, param_ty, i| {15950 for (param_vals, info.param_types, 0..) |*param_val, param_ty, i| {
15947 const is_generic = param_ty == .generic_poison_type;15951 const is_generic = param_ty == .generic_poison_type;
15948 const param_ty_val = try mod.intern_pool.get(gpa, .{ .opt = .{15952 const param_ty_val = try mod.intern_pool.get(gpa, .{ .opt = .{
...@@ -15957,40 +15961,40 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -15957,40 +15961,40 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1595715961
15958 const param_fields = .{15962 const param_fields = .{
15959 // is_generic: bool,15963 // is_generic: bool,
15960 Value.makeBool(is_generic).ip_index,15964 Value.makeBool(is_generic).toIntern(),
15961 // is_noalias: bool,15965 // is_noalias: bool,
15962 Value.makeBool(is_noalias).ip_index,15966 Value.makeBool(is_noalias).toIntern(),
15963 // type: ?type,15967 // type: ?type,
15964 param_ty_val,15968 param_ty_val,
15965 };15969 };
15966 param_val.* = try mod.intern(.{ .aggregate = .{15970 param_val.* = try mod.intern(.{ .aggregate = .{
15967 .ty = param_info_ty.ip_index,15971 .ty = param_info_ty.toIntern(),
15968 .storage = .{ .elems = &param_fields },15972 .storage = .{ .elems = &param_fields },
15969 } });15973 } });
15970 }15974 }
1597115975
15972 const args_val = v: {15976 const args_val = v: {
15973 const args_slice_ty = try mod.ptrType(.{15977 const args_slice_ty = try mod.ptrType(.{
15974 .elem_type = param_info_ty.ip_index,15978 .elem_type = param_info_ty.toIntern(),
15975 .size = .Slice,15979 .size = .Slice,
15976 .is_const = true,15980 .is_const = true,
15977 });15981 });
15978 const new_decl = try params_anon_decl.finish(15982 const new_decl = try params_anon_decl.finish(
15979 try mod.arrayType(.{15983 try mod.arrayType(.{
15980 .len = param_vals.len,15984 .len = param_vals.len,
15981 .child = param_info_ty.ip_index,15985 .child = param_info_ty.toIntern(),
15982 .sentinel = .none,15986 .sentinel = .none,
15983 }),15987 }),
15984 (try mod.intern(.{ .aggregate = .{15988 (try mod.intern(.{ .aggregate = .{
15985 .ty = args_slice_ty.ip_index,15989 .ty = args_slice_ty.toIntern(),
15986 .storage = .{ .elems = param_vals },15990 .storage = .{ .elems = param_vals },
15987 } })).toValue(),15991 } })).toValue(),
15988 0, // default alignment15992 0, // default alignment
15989 );15993 );
15990 break :v try mod.intern(.{ .ptr = .{15994 break :v try mod.intern(.{ .ptr = .{
15991 .ty = args_slice_ty.ip_index,15995 .ty = args_slice_ty.toIntern(),
15992 .addr = .{ .decl = new_decl },15996 .addr = .{ .decl = new_decl },
15993 .len = (try mod.intValue(Type.usize, param_vals.len)).ip_index,15997 .len = (try mod.intValue(Type.usize, param_vals.len)).toIntern(),
15994 } });15998 } });
15995 };15999 };
1599616000
...@@ -16003,43 +16007,55 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16003,43 +16007,55 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1600316007
16004 const field_values = .{16008 const field_values = .{
16005 // calling_convention: CallingConvention,16009 // calling_convention: CallingConvention,
16006 (try mod.enumValueFieldIndex(callconv_ty, @enumToInt(info.cc))).ip_index,16010 (try mod.enumValueFieldIndex(callconv_ty, @enumToInt(info.cc))).toIntern(),
16007 // alignment: comptime_int,16011 // alignment: comptime_int,
16008 (try mod.intValue(Type.comptime_int, ty.abiAlignment(mod))).ip_index,16012 (try mod.intValue(Type.comptime_int, ty.abiAlignment(mod))).toIntern(),
16009 // is_generic: bool,16013 // is_generic: bool,
16010 Value.makeBool(info.is_generic).ip_index,16014 Value.makeBool(info.is_generic).toIntern(),
16011 // is_var_args: bool,16015 // is_var_args: bool,
16012 Value.makeBool(info.is_var_args).ip_index,16016 Value.makeBool(info.is_var_args).toIntern(),
16013 // return_type: ?type,16017 // return_type: ?type,
16014 ret_ty_opt,16018 ret_ty_opt,
16015 // args: []const Fn.Param,16019 // args: []const Fn.Param,
16016 args_val,16020 args_val,
16017 };16021 };
16018 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{16022 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16019 .ty = type_info_ty.ip_index,16023 .ty = type_info_ty.toIntern(),
16020 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Fn))).ip_index,16024 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Fn))).toIntern(),
16021 .val = try mod.intern(.{ .aggregate = .{16025 .val = try mod.intern(.{ .aggregate = .{
16022 .ty = fn_info_ty.ip_index,16026 .ty = fn_info_ty.toIntern(),
16023 .storage = .{ .elems = &field_values },16027 .storage = .{ .elems = &field_values },
16024 } }),16028 } }),
16025 } })).toValue());16029 } })).toValue());
16026 },16030 },
16027 .Int => {16031 .Int => {
16032 const int_info_decl_index = (try sema.namespaceLookup(
16033 block,
16034 src,
16035 type_info_ty.getNamespaceIndex(mod).unwrap().?,
16036 "Int",
16037 )).?;
16038 try mod.declareDeclDependency(sema.owner_decl_index, int_info_decl_index);
16039 try sema.ensureDeclAnalyzed(int_info_decl_index);
16040 const int_info_decl = mod.declPtr(int_info_decl_index);
16041 const int_info_ty = int_info_decl.val.toType();
16042
16028 const signedness_ty = try sema.getBuiltinType("Signedness");16043 const signedness_ty = try sema.getBuiltinType("Signedness");
16029 const info = ty.intInfo(mod);16044 const info = ty.intInfo(mod);
16030 const field_values = try sema.arena.alloc(Value, 2);16045 const field_values = .{
16031 // signedness: Signedness,16046 // signedness: Signedness,
16032 field_values[0] = try mod.enumValueFieldIndex(signedness_ty, @enumToInt(info.signedness));16047 try (try mod.enumValueFieldIndex(signedness_ty, @enumToInt(info.signedness))).intern(signedness_ty, mod),
16033 // bits: u16,16048 // bits: u16,
16034 field_values[1] = try mod.intValue(Type.u16, info.bits);16049 (try mod.intValue(Type.u16, info.bits)).toIntern(),
1603516050 };
16036 return sema.addConstant(16051 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16037 type_info_ty,16052 .ty = type_info_ty.toIntern(),
16038 try Value.Tag.@"union".create(sema.arena, .{16053 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Int))).toIntern(),
16039 .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Int)),16054 .val = try mod.intern(.{ .aggregate = .{
16040 .val = try Value.Tag.aggregate.create(sema.arena, field_values),16055 .ty = int_info_ty.toIntern(),
16041 }),16056 .storage = .{ .elems = &field_values },
16042 );16057 } }),
16058 } })).toValue());
16043 },16059 },
16044 .Float => {16060 .Float => {
16045 const float_info_decl_index = (try sema.namespaceLookup(16061 const float_info_decl_index = (try sema.namespaceLookup(
...@@ -16051,17 +16067,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16051,17 +16067,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16051 try mod.declareDeclDependency(sema.owner_decl_index, float_info_decl_index);16067 try mod.declareDeclDependency(sema.owner_decl_index, float_info_decl_index);
16052 try sema.ensureDeclAnalyzed(float_info_decl_index);16068 try sema.ensureDeclAnalyzed(float_info_decl_index);
16053 const float_info_decl = mod.declPtr(float_info_decl_index);16069 const float_info_decl = mod.declPtr(float_info_decl_index);
16054 const float_ty = float_info_decl.val.toType();16070 const float_info_ty = float_info_decl.val.toType();
1605516071
16056 const field_vals = .{16072 const field_vals = .{
16057 // bits: u16,16073 // bits: u16,
16058 (try mod.intValue(Type.u16, ty.bitSize(mod))).ip_index,16074 (try mod.intValue(Type.u16, ty.bitSize(mod))).toIntern(),
16059 };16075 };
16060 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{16076 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16061 .ty = type_info_ty.ip_index,16077 .ty = type_info_ty.toIntern(),
16062 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Float))).ip_index,16078 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Float))).toIntern(),
16063 .val = try mod.intern(.{ .aggregate = .{16079 .val = try mod.intern(.{ .aggregate = .{
16064 .ty = float_ty.ip_index,16080 .ty = float_info_ty.toIntern(),
16065 .storage = .{ .elems = &field_vals },16081 .storage = .{ .elems = &field_vals },
16066 } }),16082 } }),
16067 } })).toValue());16083 } })).toValue());
...@@ -16099,80 +16115,121 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16099,80 +16115,121 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16099 break :t decl.val.toType();16115 break :t decl.val.toType();
16100 };16116 };
1610116117
16102 const field_values = try sema.arena.create([8]Value);16118 const field_values = .{
16103 field_values.* = .{
16104 // size: Size,16119 // size: Size,
16105 try mod.enumValueFieldIndex(ptr_size_ty, @enumToInt(info.size)),16120 try (try mod.enumValueFieldIndex(ptr_size_ty, @enumToInt(info.size))).intern(ptr_size_ty, mod),
16106 // is_const: bool,16121 // is_const: bool,
16107 Value.makeBool(!info.mutable),16122 Value.makeBool(!info.mutable).toIntern(),
16108 // is_volatile: bool,16123 // is_volatile: bool,
16109 Value.makeBool(info.@"volatile"),16124 Value.makeBool(info.@"volatile").toIntern(),
16110 // alignment: comptime_int,16125 // alignment: comptime_int,
16111 alignment,16126 alignment.toIntern(),
16112 // address_space: AddressSpace16127 // address_space: AddressSpace
16113 try mod.enumValueFieldIndex(addrspace_ty, @enumToInt(info.@"addrspace")),16128 try (try mod.enumValueFieldIndex(addrspace_ty, @enumToInt(info.@"addrspace"))).intern(addrspace_ty, mod),
16114 // child: type,16129 // child: type,
16115 info.pointee_type.toValue(),16130 info.pointee_type.toIntern(),
16116 // is_allowzero: bool,16131 // is_allowzero: bool,
16117 Value.makeBool(info.@"allowzero"),16132 Value.makeBool(info.@"allowzero").toIntern(),
16118 // sentinel: ?*const anyopaque,16133 // sentinel: ?*const anyopaque,
16119 try sema.optRefValue(block, info.pointee_type, info.sentinel),16134 (try sema.optRefValue(block, info.pointee_type, info.sentinel)).toIntern(),
16120 };16135 };
1612116136 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16122 return sema.addConstant(16137 .ty = type_info_ty.toIntern(),
16123 type_info_ty,16138 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Pointer))).toIntern(),
16124 try Value.Tag.@"union".create(sema.arena, .{16139 .val = try mod.intern(.{ .aggregate = .{
16125 .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Pointer)),16140 .ty = pointer_ty.toIntern(),
16126 .val = try Value.Tag.aggregate.create(sema.arena, field_values),16141 .storage = .{ .elems = &field_values },
16127 }),16142 } }),
16128 );16143 } })).toValue());
16129 },16144 },
16130 .Array => {16145 .Array => {
16131 const info = ty.arrayInfo(mod);16146 const array_field_ty = t: {
16132 const field_values = try sema.arena.alloc(Value, 3);16147 const array_field_ty_decl_index = (try sema.namespaceLookup(
16133 // len: comptime_int,16148 block,
16134 field_values[0] = try mod.intValue(Type.comptime_int, info.len);16149 src,
16135 // child: type,16150 type_info_ty.getNamespaceIndex(mod).unwrap().?,
16136 field_values[1] = info.elem_type.toValue();16151 "Array",
16137 // sentinel: ?*const anyopaque,16152 )).?;
16138 field_values[2] = try sema.optRefValue(block, info.elem_type, info.sentinel);16153 try mod.declareDeclDependency(sema.owner_decl_index, array_field_ty_decl_index);
16154 try sema.ensureDeclAnalyzed(array_field_ty_decl_index);
16155 const array_field_ty_decl = mod.declPtr(array_field_ty_decl_index);
16156 break :t array_field_ty_decl.val.toType();
16157 };
1613916158
16140 return sema.addConstant(16159 const info = ty.arrayInfo(mod);
16141 type_info_ty,16160 const field_values = .{
16142 try Value.Tag.@"union".create(sema.arena, .{16161 // len: comptime_int,
16143 .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Array)),16162 (try mod.intValue(Type.comptime_int, info.len)).toIntern(),
16144 .val = try Value.Tag.aggregate.create(sema.arena, field_values),16163 // child: type,
16145 }),16164 info.elem_type.toIntern(),
16146 );16165 // sentinel: ?*const anyopaque,
16166 (try sema.optRefValue(block, info.elem_type, info.sentinel)).toIntern(),
16167 };
16168 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16169 .ty = type_info_ty.toIntern(),
16170 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Array))).toIntern(),
16171 .val = try mod.intern(.{ .aggregate = .{
16172 .ty = array_field_ty.toIntern(),
16173 .storage = .{ .elems = &field_values },
16174 } }),
16175 } })).toValue());
16147 },16176 },
16148 .Vector => {16177 .Vector => {
16149 const info = ty.arrayInfo(mod);16178 const vector_field_ty = t: {
16150 const field_values = try sema.arena.alloc(Value, 2);16179 const vector_field_ty_decl_index = (try sema.namespaceLookup(
16151 // len: comptime_int,16180 block,
16152 field_values[0] = try mod.intValue(Type.comptime_int, info.len);16181 src,
16153 // child: type,16182 type_info_ty.getNamespaceIndex(mod).unwrap().?,
16154 field_values[1] = info.elem_type.toValue();16183 "Vector",
16184 )).?;
16185 try mod.declareDeclDependency(sema.owner_decl_index, vector_field_ty_decl_index);
16186 try sema.ensureDeclAnalyzed(vector_field_ty_decl_index);
16187 const vector_field_ty_decl = mod.declPtr(vector_field_ty_decl_index);
16188 break :t vector_field_ty_decl.val.toType();
16189 };
1615516190
16156 return sema.addConstant(16191 const info = ty.arrayInfo(mod);
16157 type_info_ty,16192 const field_values = .{
16158 try Value.Tag.@"union".create(sema.arena, .{16193 // len: comptime_int,
16159 .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Vector)),16194 (try mod.intValue(Type.comptime_int, info.len)).toIntern(),
16160 .val = try Value.Tag.aggregate.create(sema.arena, field_values),16195 // child: type,
16161 }),16196 info.elem_type.toIntern(),
16162 );16197 };
16198 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16199 .ty = type_info_ty.toIntern(),
16200 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Vector))).toIntern(),
16201 .val = try mod.intern(.{ .aggregate = .{
16202 .ty = vector_field_ty.toIntern(),
16203 .storage = .{ .elems = &field_values },
16204 } }),
16205 } })).toValue());
16163 },16206 },
16164 .Optional => {16207 .Optional => {
16165 const field_values = try sema.arena.alloc(Value, 1);16208 const optional_field_ty = t: {
16166 // child: type,16209 const optional_field_ty_decl_index = (try sema.namespaceLookup(
16167 field_values[0] = ty.optionalChild(mod).toValue();16210 block,
16211 src,
16212 type_info_ty.getNamespaceIndex(mod).unwrap().?,
16213 "Optional",
16214 )).?;
16215 try mod.declareDeclDependency(sema.owner_decl_index, optional_field_ty_decl_index);
16216 try sema.ensureDeclAnalyzed(optional_field_ty_decl_index);
16217 const optional_field_ty_decl = mod.declPtr(optional_field_ty_decl_index);
16218 break :t optional_field_ty_decl.val.toType();
16219 };
1616816220
16169 return sema.addConstant(16221 const field_values = .{
16170 type_info_ty,16222 // child: type,
16171 try Value.Tag.@"union".create(sema.arena, .{16223 ty.optionalChild(mod).toIntern(),
16172 .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Optional)),16224 };
16173 .val = try Value.Tag.aggregate.create(sema.arena, field_values),16225 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16174 }),16226 .ty = type_info_ty.toIntern(),
16175 );16227 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Vector))).toIntern(),
16228 .val = try mod.intern(.{ .aggregate = .{
16229 .ty = optional_field_ty.toIntern(),
16230 .storage = .{ .elems = &field_values },
16231 } }),
16232 } })).toValue());
16176 },16233 },
16177 .ErrorSet => {16234 .ErrorSet => {
16178 var fields_anon_decl = try block.startAnonDecl();16235 var fields_anon_decl = try block.startAnonDecl();
...@@ -16202,21 +16259,27 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16202,21 +16259,27 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16202 // Value can be zero-length slice otherwise16259 // Value can be zero-length slice otherwise
16203 const error_field_vals = if (ty.isAnyError(mod)) null else blk: {16260 const error_field_vals = if (ty.isAnyError(mod)) null else blk: {
16204 const names = ty.errorSetNames(mod);16261 const names = ty.errorSetNames(mod);
16205 const vals = try gpa.alloc(InternPool.Index, names.len);16262 const vals = try sema.arena.alloc(InternPool.Index, names.len);
16206 defer gpa.free(vals);
16207 for (vals, names) |*field_val, name_ip| {16263 for (vals, names) |*field_val, name_ip| {
16208 const name = mod.intern_pool.stringToSlice(name_ip);16264 const name = mod.intern_pool.stringToSlice(name_ip);
16209 const name_val = v: {16265 const name_val = v: {
16210 var anon_decl = try block.startAnonDecl();16266 var anon_decl = try block.startAnonDecl();
16211 defer anon_decl.deinit();16267 defer anon_decl.deinit();
16212 const bytes = try anon_decl.arena().dupeZ(u8, name);16268 const new_decl_ty = try mod.arrayType(.{
16269 .len = name.len,
16270 .child = .u8_type,
16271 .sentinel = .zero_u8,
16272 });
16213 const new_decl = try anon_decl.finish(16273 const new_decl = try anon_decl.finish(
16214 try Type.array(anon_decl.arena(), bytes.len, try mod.intValue(Type.u8, 0), Type.u8, mod),16274 new_decl_ty,
16215 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),16275 (try mod.intern(.{ .aggregate = .{
16276 .ty = new_decl_ty.toIntern(),
16277 .storage = .{ .bytes = name },
16278 } })).toValue(),
16216 0, // default alignment16279 0, // default alignment
16217 );16280 );
16218 break :v try mod.intern(.{ .ptr = .{16281 break :v try mod.intern(.{ .ptr = .{
16219 .ty = .slice_const_u8_type,16282 .ty = .slice_const_u8_sentinel_0_type,
16220 .addr = .{ .decl = new_decl },16283 .addr = .{ .decl = new_decl },
16221 } });16284 } });
16222 };16285 };
...@@ -16226,7 +16289,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16226,7 +16289,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16226 name_val,16289 name_val,
16227 };16290 };
16228 field_val.* = try mod.intern(.{ .aggregate = .{16291 field_val.* = try mod.intern(.{ .aggregate = .{
16229 .ty = error_field_ty.ip_index,16292 .ty = error_field_ty.toIntern(),
16230 .storage = .{ .elems = &error_field_fields },16293 .storage = .{ .elems = &error_field_fields },
16231 } });16294 } });
16232 }16295 }
...@@ -16236,39 +16299,39 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16236,39 +16299,39 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1623616299
16237 // Build our ?[]const Error value16300 // Build our ?[]const Error value
16238 const slice_errors_ty = try mod.ptrType(.{16301 const slice_errors_ty = try mod.ptrType(.{
16239 .elem_type = error_field_ty.ip_index,16302 .elem_type = error_field_ty.toIntern(),
16240 .size = .Slice,16303 .size = .Slice,
16241 .is_const = true,16304 .is_const = true,
16242 });16305 });
16243 const opt_slice_errors_ty = try mod.optionalType(slice_errors_ty.ip_index);16306 const opt_slice_errors_ty = try mod.optionalType(slice_errors_ty.toIntern());
16244 const errors_payload_val: InternPool.Index = if (error_field_vals) |vals| v: {16307 const errors_payload_val: InternPool.Index = if (error_field_vals) |vals| v: {
16245 const array_errors_ty = try mod.arrayType(.{16308 const array_errors_ty = try mod.arrayType(.{
16246 .len = vals.len,16309 .len = vals.len,
16247 .child = error_field_ty.ip_index,16310 .child = error_field_ty.toIntern(),
16248 .sentinel = .none,16311 .sentinel = .none,
16249 });16312 });
16250 const new_decl = try fields_anon_decl.finish(16313 const new_decl = try fields_anon_decl.finish(
16251 array_errors_ty,16314 array_errors_ty,
16252 (try mod.intern(.{ .aggregate = .{16315 (try mod.intern(.{ .aggregate = .{
16253 .ty = array_errors_ty.ip_index,16316 .ty = array_errors_ty.toIntern(),
16254 .storage = .{ .elems = vals },16317 .storage = .{ .elems = vals },
16255 } })).toValue(),16318 } })).toValue(),
16256 0, // default alignment16319 0, // default alignment
16257 );16320 );
16258 break :v try mod.intern(.{ .ptr = .{16321 break :v try mod.intern(.{ .ptr = .{
16259 .ty = slice_errors_ty.ip_index,16322 .ty = slice_errors_ty.toIntern(),
16260 .addr = .{ .decl = new_decl },16323 .addr = .{ .decl = new_decl },
16261 } });16324 } });
16262 } else .none;16325 } else .none;
16263 const errors_val = try mod.intern(.{ .opt = .{16326 const errors_val = try mod.intern(.{ .opt = .{
16264 .ty = opt_slice_errors_ty.ip_index,16327 .ty = opt_slice_errors_ty.toIntern(),
16265 .val = errors_payload_val,16328 .val = errors_payload_val,
16266 } });16329 } });
1626716330
16268 // Construct Type{ .ErrorSet = errors_val }16331 // Construct Type{ .ErrorSet = errors_val }
16269 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{16332 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16270 .ty = type_info_ty.ip_index,16333 .ty = type_info_ty.toIntern(),
16271 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorSet))).ip_index,16334 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorSet))).toIntern(),
16272 .val = errors_val,16335 .val = errors_val,
16273 } })).toValue());16336 } })).toValue());
16274 },16337 },
...@@ -16288,22 +16351,22 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16288,22 +16351,22 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1628816351
16289 const field_values = .{16352 const field_values = .{
16290 // error_set: type,16353 // error_set: type,
16291 ty.errorUnionSet(mod).ip_index,16354 ty.errorUnionSet(mod).toIntern(),
16292 // payload: type,16355 // payload: type,
16293 ty.errorUnionPayload(mod).ip_index,16356 ty.errorUnionPayload(mod).toIntern(),
16294 };16357 };
16295 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{16358 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16296 .ty = type_info_ty.ip_index,16359 .ty = type_info_ty.toIntern(),
16297 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorUnion))).ip_index,16360 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorUnion))).toIntern(),
16298 .val = try mod.intern(.{ .aggregate = .{16361 .val = try mod.intern(.{ .aggregate = .{
16299 .ty = error_union_field_ty.ip_index,16362 .ty = error_union_field_ty.toIntern(),
16300 .storage = .{ .elems = &field_values },16363 .storage = .{ .elems = &field_values },
16301 } }),16364 } }),
16302 } })).toValue());16365 } })).toValue());
16303 },16366 },
16304 .Enum => {16367 .Enum => {
16305 // TODO: look into memoizing this result.16368 // TODO: look into memoizing this result.
16306 const enum_type = mod.intern_pool.indexToKey(ty.ip_index).enum_type;16369 const enum_type = mod.intern_pool.indexToKey(ty.toIntern()).enum_type;
1630716370
16308 const is_exhaustive = Value.makeBool(enum_type.tag_mode != .nonexhaustive);16371 const is_exhaustive = Value.makeBool(enum_type.tag_mode != .nonexhaustive);
1630916372
...@@ -16323,23 +16386,28 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16323,23 +16386,28 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16323 break :t enum_field_ty_decl.val.toType();16386 break :t enum_field_ty_decl.val.toType();
16324 };16387 };
1632516388
16326 const enum_field_vals = try gpa.alloc(InternPool.Index, enum_type.names.len);16389 const enum_field_vals = try sema.arena.alloc(InternPool.Index, enum_type.names.len);
16327 defer gpa.free(enum_field_vals);
16328
16329 for (enum_field_vals, 0..) |*field_val, i| {16390 for (enum_field_vals, 0..) |*field_val, i| {
16330 const name_ip = enum_type.names[i];16391 const name_ip = enum_type.names[i];
16331 const name = mod.intern_pool.stringToSlice(name_ip);16392 const name = mod.intern_pool.stringToSlice(name_ip);
16332 const name_val = v: {16393 const name_val = v: {
16333 var anon_decl = try block.startAnonDecl();16394 var anon_decl = try block.startAnonDecl();
16334 defer anon_decl.deinit();16395 defer anon_decl.deinit();
16335 const bytes = try anon_decl.arena().dupeZ(u8, name);16396 const new_decl_ty = try mod.arrayType(.{
16397 .len = name.len,
16398 .child = .u8_type,
16399 .sentinel = .zero_u8,
16400 });
16336 const new_decl = try anon_decl.finish(16401 const new_decl = try anon_decl.finish(
16337 try Type.array(anon_decl.arena(), bytes.len, Value.zero_u8, Type.u8, mod),16402 new_decl_ty,
16338 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),16403 (try mod.intern(.{ .aggregate = .{
16404 .ty = new_decl_ty.toIntern(),
16405 .storage = .{ .bytes = name },
16406 } })).toValue(),
16339 0, // default alignment16407 0, // default alignment
16340 );16408 );
16341 break :v try mod.intern(.{ .ptr = .{16409 break :v try mod.intern(.{ .ptr = .{
16342 .ty = .slice_const_u8_type,16410 .ty = .slice_const_u8_sentinel_0_type,
16343 .addr = .{ .decl = new_decl },16411 .addr = .{ .decl = new_decl },
16344 } });16412 } });
16345 };16413 };
...@@ -16348,10 +16416,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16348,10 +16416,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16348 // name: []const u8,16416 // name: []const u8,
16349 name_val,16417 name_val,
16350 // value: comptime_int,16418 // value: comptime_int,
16351 (try mod.intValue(Type.comptime_int, i)).ip_index,16419 (try mod.intValue(Type.comptime_int, i)).toIntern(),
16352 };16420 };
16353 field_val.* = try mod.intern(.{ .aggregate = .{16421 field_val.* = try mod.intern(.{ .aggregate = .{
16354 .ty = enum_field_ty.ip_index,16422 .ty = enum_field_ty.toIntern(),
16355 .storage = .{ .elems = &enum_field_fields },16423 .storage = .{ .elems = &enum_field_fields },
16356 } });16424 } });
16357 }16425 }
...@@ -16359,23 +16427,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16359,23 +16427,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16359 const fields_val = v: {16427 const fields_val = v: {
16360 const fields_array_ty = try mod.arrayType(.{16428 const fields_array_ty = try mod.arrayType(.{
16361 .len = enum_field_vals.len,16429 .len = enum_field_vals.len,
16362 .child = enum_field_ty.ip_index,16430 .child = enum_field_ty.toIntern(),
16363 .sentinel = .none,16431 .sentinel = .none,
16364 });16432 });
16365 const new_decl = try fields_anon_decl.finish(16433 const new_decl = try fields_anon_decl.finish(
16366 fields_array_ty,16434 fields_array_ty,
16367 (try mod.intern(.{ .aggregate = .{16435 (try mod.intern(.{ .aggregate = .{
16368 .ty = fields_array_ty.ip_index,16436 .ty = fields_array_ty.toIntern(),
16369 .storage = .{ .elems = enum_field_vals },16437 .storage = .{ .elems = enum_field_vals },
16370 } })).toValue(),16438 } })).toValue(),
16371 0, // default alignment16439 0, // default alignment
16372 );16440 );
16373 break :v try mod.intern(.{ .ptr = .{16441 break :v try mod.intern(.{ .ptr = .{
16374 .ty = (try mod.ptrType(.{16442 .ty = (try mod.ptrType(.{
16375 .elem_type = enum_field_ty.ip_index,16443 .elem_type = enum_field_ty.toIntern(),
16376 .size = .Slice,16444 .size = .Slice,
16377 .is_const = true,16445 .is_const = true,
16378 })).ip_index,16446 })).toIntern(),
16379 .addr = .{ .decl = new_decl },16447 .addr = .{ .decl = new_decl },
16380 } });16448 } });
16381 };16449 };
...@@ -16403,13 +16471,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16403,13 +16471,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16403 // decls: []const Declaration,16471 // decls: []const Declaration,
16404 decls_val,16472 decls_val,
16405 // is_exhaustive: bool,16473 // is_exhaustive: bool,
16406 is_exhaustive.ip_index,16474 is_exhaustive.toIntern(),
16407 };16475 };
16408 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{16476 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16409 .ty = type_info_ty.ip_index,16477 .ty = type_info_ty.toIntern(),
16410 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Enum))).ip_index,16478 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Enum))).toIntern(),
16411 .val = try mod.intern(.{ .aggregate = .{16479 .val = try mod.intern(.{ .aggregate = .{
16412 .ty = type_enum_ty.ip_index,16480 .ty = type_enum_ty.toIntern(),
16413 .storage = .{ .elems = &field_values },16481 .storage = .{ .elems = &field_values },
16414 } }),16482 } }),
16415 } })).toValue());16483 } })).toValue());
...@@ -16460,14 +16528,21 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16460,14 +16528,21 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16460 const name_val = v: {16528 const name_val = v: {
16461 var anon_decl = try block.startAnonDecl();16529 var anon_decl = try block.startAnonDecl();
16462 defer anon_decl.deinit();16530 defer anon_decl.deinit();
16463 const bytes = try anon_decl.arena().dupeZ(u8, name);16531 const new_decl_ty = try mod.arrayType(.{
16532 .len = name.len,
16533 .child = .u8_type,
16534 .sentinel = .zero_u8,
16535 });
16464 const new_decl = try anon_decl.finish(16536 const new_decl = try anon_decl.finish(
16465 try Type.array(anon_decl.arena(), bytes.len, try mod.intValue(Type.u8, 0), Type.u8, mod),16537 new_decl_ty,
16466 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),16538 (try mod.intern(.{ .aggregate = .{
16539 .ty = new_decl_ty.toIntern(),
16540 .storage = .{ .bytes = name },
16541 } })).toValue(),
16467 0, // default alignment16542 0, // default alignment
16468 );16543 );
16469 break :v try mod.intern(.{ .ptr = .{16544 break :v try mod.intern(.{ .ptr = .{
16470 .ty = .slice_const_u8_type,16545 .ty = .slice_const_u8_sentinel_0_type,
16471 .addr = .{ .decl = new_decl },16546 .addr = .{ .decl = new_decl },
16472 } });16547 } });
16473 };16548 };
...@@ -16481,12 +16556,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16481,12 +16556,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16481 // name: []const u8,16556 // name: []const u8,
16482 name_val,16557 name_val,
16483 // type: type,16558 // type: type,
16484 field.ty.ip_index,16559 field.ty.toIntern(),
16485 // alignment: comptime_int,16560 // alignment: comptime_int,
16486 (try mod.intValue(Type.comptime_int, alignment)).ip_index,16561 (try mod.intValue(Type.comptime_int, alignment)).toIntern(),
16487 };16562 };
16488 field_val.* = try mod.intern(.{ .aggregate = .{16563 field_val.* = try mod.intern(.{ .aggregate = .{
16489 .ty = union_field_ty.ip_index,16564 .ty = union_field_ty.toIntern(),
16490 .storage = .{ .elems = &union_field_fields },16565 .storage = .{ .elems = &union_field_fields },
16491 } });16566 } });
16492 }16567 }
...@@ -16494,33 +16569,33 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16494,33 +16569,33 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16494 const fields_val = v: {16569 const fields_val = v: {
16495 const array_fields_ty = try mod.arrayType(.{16570 const array_fields_ty = try mod.arrayType(.{
16496 .len = union_field_vals.len,16571 .len = union_field_vals.len,
16497 .child = union_field_ty.ip_index,16572 .child = union_field_ty.toIntern(),
16498 .sentinel = .none,16573 .sentinel = .none,
16499 });16574 });
16500 const new_decl = try fields_anon_decl.finish(16575 const new_decl = try fields_anon_decl.finish(
16501 array_fields_ty,16576 array_fields_ty,
16502 (try mod.intern(.{ .aggregate = .{16577 (try mod.intern(.{ .aggregate = .{
16503 .ty = array_fields_ty.ip_index,16578 .ty = array_fields_ty.toIntern(),
16504 .storage = .{ .elems = union_field_vals },16579 .storage = .{ .elems = union_field_vals },
16505 } })).toValue(),16580 } })).toValue(),
16506 0, // default alignment16581 0, // default alignment
16507 );16582 );
16508 break :v try mod.intern(.{ .ptr = .{16583 break :v try mod.intern(.{ .ptr = .{
16509 .ty = (try mod.ptrType(.{16584 .ty = (try mod.ptrType(.{
16510 .elem_type = union_field_ty.ip_index,16585 .elem_type = union_field_ty.toIntern(),
16511 .size = .Slice,16586 .size = .Slice,
16512 .is_const = true,16587 .is_const = true,
16513 })).ip_index,16588 })).toIntern(),
16514 .addr = .{ .decl = new_decl },16589 .addr = .{ .decl = new_decl },
16515 .len = (try mod.intValue(Type.usize, union_field_vals.len)).ip_index,16590 .len = (try mod.intValue(Type.usize, union_field_vals.len)).toIntern(),
16516 } });16591 } });
16517 };16592 };
1651816593
16519 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, union_ty.getNamespaceIndex(mod));16594 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, union_ty.getNamespaceIndex(mod));
1652016595
16521 const enum_tag_ty_val = try mod.intern(.{ .opt = .{16596 const enum_tag_ty_val = try mod.intern(.{ .opt = .{
16522 .ty = (try mod.optionalType(.type_type)).ip_index,16597 .ty = (try mod.optionalType(.type_type)).toIntern(),
16523 .val = if (union_ty.unionTagType(mod)) |tag_ty| tag_ty.ip_index else .none,16598 .val = if (union_ty.unionTagType(mod)) |tag_ty| tag_ty.toIntern() else .none,
16524 } });16599 } });
1652516600
16526 const container_layout_ty = t: {16601 const container_layout_ty = t: {
...@@ -16538,7 +16613,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16538,7 +16613,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1653816613
16539 const field_values = .{16614 const field_values = .{
16540 // layout: ContainerLayout,16615 // layout: ContainerLayout,
16541 (try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout))).ip_index,16616 (try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout))).toIntern(),
1654216617
16543 // tag_type: ?type,16618 // tag_type: ?type,
16544 enum_tag_ty_val,16619 enum_tag_ty_val,
...@@ -16548,10 +16623,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16548,10 +16623,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16548 decls_val,16623 decls_val,
16549 };16624 };
16550 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{16625 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16551 .ty = type_info_ty.ip_index,16626 .ty = type_info_ty.toIntern(),
16552 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Union))).ip_index,16627 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Union))).toIntern(),
16553 .val = try mod.intern(.{ .aggregate = .{16628 .val = try mod.intern(.{ .aggregate = .{
16554 .ty = type_union_ty.ip_index,16629 .ty = type_union_ty.toIntern(),
16555 .storage = .{ .elems = &field_values },16630 .storage = .{ .elems = &field_values },
16556 } }),16631 } }),
16557 } })).toValue());16632 } })).toValue());
...@@ -16595,7 +16670,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16595,7 +16670,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16595 var struct_field_vals: []InternPool.Index = &.{};16670 var struct_field_vals: []InternPool.Index = &.{};
16596 defer gpa.free(struct_field_vals);16671 defer gpa.free(struct_field_vals);
16597 fv: {16672 fv: {
16598 const struct_type = switch (mod.intern_pool.indexToKey(struct_ty.ip_index)) {16673 const struct_type = switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) {
16599 .anon_struct_type => |tuple| {16674 .anon_struct_type => |tuple| {
16600 struct_field_vals = try gpa.alloc(InternPool.Index, tuple.types.len);16675 struct_field_vals = try gpa.alloc(InternPool.Index, tuple.types.len);
16601 for (16676 for (
...@@ -16611,16 +16686,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16611,16 +16686,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16611 // https://github.com/ziglang/zig/issues/1570916686 // https://github.com/ziglang/zig/issues/15709
16612 @as([]const u8, mod.intern_pool.stringToSlice(tuple.names[i]))16687 @as([]const u8, mod.intern_pool.stringToSlice(tuple.names[i]))
16613 else16688 else
16614 try std.fmt.allocPrintZ(anon_decl.arena(), "{d}", .{i});16689 try std.fmt.allocPrint(sema.arena, "{d}", .{i});
16690 const new_decl_ty = try mod.arrayType(.{
16691 .len = bytes.len,
16692 .child = .u8_type,
16693 .sentinel = .zero_u8,
16694 });
16615 const new_decl = try anon_decl.finish(16695 const new_decl = try anon_decl.finish(
16616 try Type.array(anon_decl.arena(), bytes.len, Value.zero_u8, Type.u8, mod),16696 new_decl_ty,
16617 try Value.Tag.bytes.create(anon_decl.arena(), bytes.ptr[0 .. bytes.len + 1]),16697 (try mod.intern(.{ .aggregate = .{
16698 .ty = new_decl_ty.toIntern(),
16699 .storage = .{ .bytes = bytes },
16700 } })).toValue(),
16618 0, // default alignment16701 0, // default alignment
16619 );16702 );
16620 break :v try mod.intern(.{ .ptr = .{16703 break :v try mod.intern(.{ .ptr = .{
16621 .ty = .slice_const_u8_type,16704 .ty = .slice_const_u8_sentinel_0_type,
16622 .addr = .{ .decl = new_decl },16705 .addr = .{ .decl = new_decl },
16623 .len = (try mod.intValue(Type.usize, bytes.len)).ip_index,16706 .len = (try mod.intValue(Type.usize, bytes.len)).toIntern(),
16624 } });16707 } });
16625 };16708 };
1662616709
...@@ -16633,14 +16716,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16633,14 +16716,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16633 // type: type,16716 // type: type,
16634 field_ty,16717 field_ty,
16635 // default_value: ?*const anyopaque,16718 // default_value: ?*const anyopaque,
16636 default_val_ptr.ip_index,16719 default_val_ptr.toIntern(),
16637 // is_comptime: bool,16720 // is_comptime: bool,
16638 Value.makeBool(is_comptime).ip_index,16721 Value.makeBool(is_comptime).toIntern(),
16639 // alignment: comptime_int,16722 // alignment: comptime_int,
16640 (try mod.intValue(Type.comptime_int, field_ty.toType().abiAlignment(mod))).ip_index,16723 (try mod.intValue(Type.comptime_int, field_ty.toType().abiAlignment(mod))).toIntern(),
16641 };16724 };
16642 struct_field_val.* = try mod.intern(.{ .aggregate = .{16725 struct_field_val.* = try mod.intern(.{ .aggregate = .{
16643 .ty = struct_field_ty.ip_index,16726 .ty = struct_field_ty.toIntern(),
16644 .storage = .{ .elems = &struct_field_fields },16727 .storage = .{ .elems = &struct_field_fields },
16645 } });16728 } });
16646 }16729 }
...@@ -16660,20 +16743,27 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16660,20 +16743,27 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16660 const name_val = v: {16743 const name_val = v: {
16661 var anon_decl = try block.startAnonDecl();16744 var anon_decl = try block.startAnonDecl();
16662 defer anon_decl.deinit();16745 defer anon_decl.deinit();
16663 const bytes = try anon_decl.arena().dupeZ(u8, name);16746 const new_decl_ty = try mod.arrayType(.{
16747 .len = name.len,
16748 .child = .u8_type,
16749 .sentinel = .zero_u8,
16750 });
16664 const new_decl = try anon_decl.finish(16751 const new_decl = try anon_decl.finish(
16665 try Type.array(anon_decl.arena(), bytes.len, try mod.intValue(Type.u8, 0), Type.u8, mod),16752 new_decl_ty,
16666 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),16753 (try mod.intern(.{ .aggregate = .{
16754 .ty = new_decl_ty.toIntern(),
16755 .storage = .{ .bytes = name },
16756 } })).toValue(),
16667 0, // default alignment16757 0, // default alignment
16668 );16758 );
16669 break :v try mod.intern(.{ .ptr = .{16759 break :v try mod.intern(.{ .ptr = .{
16670 .ty = .slice_const_u8_type,16760 .ty = .slice_const_u8_sentinel_0_type,
16671 .addr = .{ .decl = new_decl },16761 .addr = .{ .decl = new_decl },
16672 .len = (try mod.intValue(Type.usize, bytes.len)).ip_index,16762 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
16673 } });16763 } });
16674 };16764 };
1667516765
16676 const opt_default_val = if (field.default_val.ip_index == .unreachable_value)16766 const opt_default_val = if (field.default_val.toIntern() == .unreachable_value)
16677 null16767 null
16678 else16768 else
16679 field.default_val;16769 field.default_val;
...@@ -16684,16 +16774,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16684,16 +16774,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16684 // name: []const u8,16774 // name: []const u8,
16685 name_val,16775 name_val,
16686 // type: type,16776 // type: type,
16687 field.ty.ip_index,16777 field.ty.toIntern(),
16688 // default_value: ?*const anyopaque,16778 // default_value: ?*const anyopaque,
16689 default_val_ptr.ip_index,16779 default_val_ptr.toIntern(),
16690 // is_comptime: bool,16780 // is_comptime: bool,
16691 Value.makeBool(field.is_comptime).ip_index,16781 Value.makeBool(field.is_comptime).toIntern(),
16692 // alignment: comptime_int,16782 // alignment: comptime_int,
16693 (try mod.intValue(Type.comptime_int, alignment)).ip_index,16783 (try mod.intValue(Type.comptime_int, alignment)).toIntern(),
16694 };16784 };
16695 field_val.* = try mod.intern(.{ .aggregate = .{16785 field_val.* = try mod.intern(.{ .aggregate = .{
16696 .ty = struct_field_ty.ip_index,16786 .ty = struct_field_ty.toIntern(),
16697 .storage = .{ .elems = &struct_field_fields },16787 .storage = .{ .elems = &struct_field_fields },
16698 } });16788 } });
16699 }16789 }
...@@ -16702,37 +16792,37 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16702,37 +16792,37 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16702 const fields_val = v: {16792 const fields_val = v: {
16703 const array_fields_ty = try mod.arrayType(.{16793 const array_fields_ty = try mod.arrayType(.{
16704 .len = struct_field_vals.len,16794 .len = struct_field_vals.len,
16705 .child = struct_field_ty.ip_index,16795 .child = struct_field_ty.toIntern(),
16706 .sentinel = .none,16796 .sentinel = .none,
16707 });16797 });
16708 const new_decl = try fields_anon_decl.finish(16798 const new_decl = try fields_anon_decl.finish(
16709 array_fields_ty,16799 array_fields_ty,
16710 (try mod.intern(.{ .aggregate = .{16800 (try mod.intern(.{ .aggregate = .{
16711 .ty = array_fields_ty.ip_index,16801 .ty = array_fields_ty.toIntern(),
16712 .storage = .{ .elems = struct_field_vals },16802 .storage = .{ .elems = struct_field_vals },
16713 } })).toValue(),16803 } })).toValue(),
16714 0, // default alignment16804 0, // default alignment
16715 );16805 );
16716 break :v try mod.intern(.{ .ptr = .{16806 break :v try mod.intern(.{ .ptr = .{
16717 .ty = (try mod.ptrType(.{16807 .ty = (try mod.ptrType(.{
16718 .elem_type = struct_field_ty.ip_index,16808 .elem_type = struct_field_ty.toIntern(),
16719 .size = .Slice,16809 .size = .Slice,
16720 .is_const = true,16810 .is_const = true,
16721 })).ip_index,16811 })).toIntern(),
16722 .addr = .{ .decl = new_decl },16812 .addr = .{ .decl = new_decl },
16723 .len = (try mod.intValue(Type.usize, struct_field_vals.len)).ip_index,16813 .len = (try mod.intValue(Type.usize, struct_field_vals.len)).toIntern(),
16724 } });16814 } });
16725 };16815 };
1672616816
16727 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, struct_ty.getNamespaceIndex(mod));16817 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, struct_ty.getNamespaceIndex(mod));
1672816818
16729 const backing_integer_val = try mod.intern(.{ .opt = .{16819 const backing_integer_val = try mod.intern(.{ .opt = .{
16730 .ty = (try mod.optionalType(.type_type)).ip_index,16820 .ty = (try mod.optionalType(.type_type)).toIntern(),
16731 .val = if (layout == .Packed) val: {16821 .val = if (layout == .Packed) val: {
16732 const struct_obj = mod.typeToStruct(struct_ty).?;16822 const struct_obj = mod.typeToStruct(struct_ty).?;
16733 assert(struct_obj.haveLayout());16823 assert(struct_obj.haveLayout());
16734 assert(struct_obj.backing_int_ty.isInt(mod));16824 assert(struct_obj.backing_int_ty.isInt(mod));
16735 break :val struct_obj.backing_int_ty.ip_index;16825 break :val struct_obj.backing_int_ty.toIntern();
16736 } else .none,16826 } else .none,
16737 } });16827 } });
1673816828
...@@ -16751,7 +16841,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16751,7 +16841,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1675116841
16752 const field_values = [_]InternPool.Index{16842 const field_values = [_]InternPool.Index{
16753 // layout: ContainerLayout,16843 // layout: ContainerLayout,
16754 (try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout))).ip_index,16844 (try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout))).toIntern(),
16755 // backing_integer: ?type,16845 // backing_integer: ?type,
16756 backing_integer_val,16846 backing_integer_val,
16757 // fields: []const StructField,16847 // fields: []const StructField,
...@@ -16759,13 +16849,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16759,13 +16849,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16759 // decls: []const Declaration,16849 // decls: []const Declaration,
16760 decls_val,16850 decls_val,
16761 // is_tuple: bool,16851 // is_tuple: bool,
16762 Value.makeBool(struct_ty.isTuple(mod)).ip_index,16852 Value.makeBool(struct_ty.isTuple(mod)).toIntern(),
16763 };16853 };
16764 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{16854 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16765 .ty = type_info_ty.ip_index,16855 .ty = type_info_ty.toIntern(),
16766 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Struct))).ip_index,16856 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Struct))).toIntern(),
16767 .val = try mod.intern(.{ .aggregate = .{16857 .val = try mod.intern(.{ .aggregate = .{
16768 .ty = type_struct_ty.ip_index,16858 .ty = type_struct_ty.toIntern(),
16769 .storage = .{ .elems = &field_values },16859 .storage = .{ .elems = &field_values },
16770 } }),16860 } }),
16771 } })).toValue());16861 } })).toValue());
...@@ -16794,10 +16884,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16794,10 +16884,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16794 decls_val,16884 decls_val,
16795 };16885 };
16796 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{16886 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16797 .ty = type_info_ty.ip_index,16887 .ty = type_info_ty.toIntern(),
16798 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Opaque))).ip_index,16888 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Opaque))).toIntern(),
16799 .val = try mod.intern(.{ .aggregate = .{16889 .val = try mod.intern(.{ .aggregate = .{
16800 .ty = type_opaque_ty.ip_index,16890 .ty = type_opaque_ty.toIntern(),
16801 .storage = .{ .elems = &field_values },16891 .storage = .{ .elems = &field_values },
16802 } }),16892 } }),
16803 } })).toValue());16893 } })).toValue());
...@@ -16845,25 +16935,25 @@ fn typeInfoDecls(...@@ -16845,25 +16935,25 @@ fn typeInfoDecls(
1684516935
16846 const array_decl_ty = try mod.arrayType(.{16936 const array_decl_ty = try mod.arrayType(.{
16847 .len = decl_vals.items.len,16937 .len = decl_vals.items.len,
16848 .child = declaration_ty.ip_index,16938 .child = declaration_ty.toIntern(),
16849 .sentinel = .none,16939 .sentinel = .none,
16850 });16940 });
16851 const new_decl = try decls_anon_decl.finish(16941 const new_decl = try decls_anon_decl.finish(
16852 array_decl_ty,16942 array_decl_ty,
16853 (try mod.intern(.{ .aggregate = .{16943 (try mod.intern(.{ .aggregate = .{
16854 .ty = array_decl_ty.ip_index,16944 .ty = array_decl_ty.toIntern(),
16855 .storage = .{ .elems = decl_vals.items },16945 .storage = .{ .elems = decl_vals.items },
16856 } })).toValue(),16946 } })).toValue(),
16857 0, // default alignment16947 0, // default alignment
16858 );16948 );
16859 return try mod.intern(.{ .ptr = .{16949 return try mod.intern(.{ .ptr = .{
16860 .ty = (try mod.ptrType(.{16950 .ty = (try mod.ptrType(.{
16861 .elem_type = declaration_ty.ip_index,16951 .elem_type = declaration_ty.toIntern(),
16862 .size = .Slice,16952 .size = .Slice,
16863 .is_const = true,16953 .is_const = true,
16864 })).ip_index,16954 })).toIntern(),
16865 .addr = .{ .decl = new_decl },16955 .addr = .{ .decl = new_decl },
16866 .len = (try mod.intValue(Type.usize, decl_vals.items.len)).ip_index,16956 .len = (try mod.intValue(Type.usize, decl_vals.items.len)).toIntern(),
16867 } });16957 } });
16868}16958}
1686916959
...@@ -16892,16 +16982,24 @@ fn typeInfoNamespaceDecls(...@@ -16892,16 +16982,24 @@ fn typeInfoNamespaceDecls(
16892 const name_val = v: {16982 const name_val = v: {
16893 var anon_decl = try block.startAnonDecl();16983 var anon_decl = try block.startAnonDecl();
16894 defer anon_decl.deinit();16984 defer anon_decl.deinit();
16895 const bytes = try anon_decl.arena().dupeZ(u8, mem.sliceTo(decl.name, 0));16985 const name = mem.span(decl.name);
16986 const new_decl_ty = try mod.arrayType(.{
16987 .len = name.len,
16988 .child = .u8_type,
16989 .sentinel = .zero_u8,
16990 });
16896 const new_decl = try anon_decl.finish(16991 const new_decl = try anon_decl.finish(
16897 try Type.array(anon_decl.arena(), bytes.len, try mod.intValue(Type.u8, 0), Type.u8, mod),16992 new_decl_ty,
16898 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),16993 (try mod.intern(.{ .aggregate = .{
16994 .ty = new_decl_ty.toIntern(),
16995 .storage = .{ .bytes = name },
16996 } })).toValue(),
16899 0, // default alignment16997 0, // default alignment
16900 );16998 );
16901 break :v try mod.intern(.{ .ptr = .{16999 break :v try mod.intern(.{ .ptr = .{
16902 .ty = .slice_const_u8_type,17000 .ty = .slice_const_u8_sentinel_0_type,
16903 .addr = .{ .decl = new_decl },17001 .addr = .{ .decl = new_decl },
16904 .len = (try mod.intValue(Type.usize, bytes.len)).ip_index,17002 .len = (try mod.intValue(Type.usize, name.len)).toIntern(),
16905 } });17003 } });
16906 };17004 };
1690717005
...@@ -16909,10 +17007,10 @@ fn typeInfoNamespaceDecls(...@@ -16909,10 +17007,10 @@ fn typeInfoNamespaceDecls(
16909 //name: []const u8,17007 //name: []const u8,
16910 name_val,17008 name_val,
16911 //is_pub: bool,17009 //is_pub: bool,
16912 Value.makeBool(decl.is_pub).ip_index,17010 Value.makeBool(decl.is_pub).toIntern(),
16913 };17011 };
16914 try decl_vals.append(try mod.intern(.{ .aggregate = .{17012 try decl_vals.append(try mod.intern(.{ .aggregate = .{
16915 .ty = declaration_ty.ip_index,17013 .ty = declaration_ty.toIntern(),
16916 .storage = .{ .elems = &fields },17014 .storage = .{ .elems = &fields },
16917 } }));17015 } }));
16918 }17016 }
...@@ -16985,7 +17083,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi...@@ -16985,7 +17083,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
16985 const log2_elem_ty = try sema.log2IntType(block, elem_ty, src);17083 const log2_elem_ty = try sema.log2IntType(block, elem_ty, src);
16986 return mod.vectorType(.{17084 return mod.vectorType(.{
16987 .len = operand.vectorLen(mod),17085 .len = operand.vectorLen(mod),
16988 .child = log2_elem_ty.ip_index,17086 .child = log2_elem_ty.toIntern(),
16989 });17087 });
16990 },17088 },
16991 else => {},17089 else => {},
...@@ -17527,7 +17625,7 @@ fn zirRetErrValue(...@@ -17527,7 +17625,7 @@ fn zirRetErrValue(
17527 const kv = try mod.getErrorValue(err_name);17625 const kv = try mod.getErrorValue(err_name);
17528 const error_set_type = try mod.singleErrorSetType(err_name);17626 const error_set_type = try mod.singleErrorSetType(err_name);
17529 const result_inst = try sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{17627 const result_inst = try sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
17530 .ty = error_set_type.ip_index,17628 .ty = error_set_type.toIntern(),
17531 .name = try mod.intern_pool.getOrPutString(sema.gpa, kv.key),17629 .name = try mod.intern_pool.getOrPutString(sema.gpa, kv.key),
17532 } })).toValue());17630 } })).toValue());
17533 return sema.analyzeRet(block, result_inst, src);17631 return sema.analyzeRet(block, result_inst, src);
...@@ -17854,9 +17952,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -17854,9 +17952,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
17854 const val = try sema.resolveConstValue(block, align_src, coerced, "pointer alignment must be comptime-known");17952 const val = try sema.resolveConstValue(block, align_src, coerced, "pointer alignment must be comptime-known");
17855 // Check if this happens to be the lazy alignment of our element type, in17953 // Check if this happens to be the lazy alignment of our element type, in
17856 // which case we can make this 0 without resolving it.17954 // which case we can make this 0 without resolving it.
17857 switch (mod.intern_pool.indexToKey(val.ip_index)) {17955 switch (mod.intern_pool.indexToKey(val.toIntern())) {
17858 .int => |int| switch (int.storage) {17956 .int => |int| switch (int.storage) {
17859 .lazy_align => |lazy_ty| if (lazy_ty == elem_ty.ip_index) break :blk .none,17957 .lazy_align => |lazy_ty| if (lazy_ty == elem_ty.toIntern()) break :blk .none,
17860 else => {},17958 else => {},
17861 },17959 },
17862 else => {},17960 else => {},
...@@ -17985,7 +18083,7 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com...@@ -17985,7 +18083,7 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com
17985 }18083 }
17986 }18084 }
17987 return sema.addConstant(obj_ty, (try mod.intern(.{ .aggregate = .{18085 return sema.addConstant(obj_ty, (try mod.intern(.{ .aggregate = .{
17988 .ty = obj_ty.ip_index,18086 .ty = obj_ty.toIntern(),
17989 .storage = .{ .elems = &.{} },18087 .storage = .{ .elems = &.{} },
17990 } })).toValue());18088 } })).toValue());
17991}18089}
...@@ -18021,10 +18119,11 @@ fn unionInit(...@@ -18021,10 +18119,11 @@ fn unionInit(
18021 const tag_ty = union_ty.unionTagTypeHypothetical(mod);18119 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
18022 const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?);18120 const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?);
18023 const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);18121 const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);
18024 return sema.addConstant(union_ty, try Value.Tag.@"union".create(sema.arena, .{18122 return sema.addConstant(union_ty, (try mod.intern(.{ .un = .{
18025 .tag = tag_val,18123 .ty = union_ty.toIntern(),
18026 .val = init_val,18124 .tag = try tag_val.intern(tag_ty, mod),
18027 }));18125 .val = try init_val.intern(field.ty, mod),
18126 } })).toValue());
18028 }18127 }
1802918128
18030 try sema.requireRuntimeBlock(block, init_src, null);18129 try sema.requireRuntimeBlock(block, init_src, null);
...@@ -18125,12 +18224,12 @@ fn zirStructInit(...@@ -18125,12 +18224,12 @@ fn zirStructInit(
1812518224
18126 const init_inst = try sema.resolveInst(item.data.init);18225 const init_inst = try sema.resolveInst(item.data.init);
18127 if (try sema.resolveMaybeUndefVal(init_inst)) |val| {18226 if (try sema.resolveMaybeUndefVal(init_inst)) |val| {
18128 return sema.addConstantMaybeRef(18227 const field = resolved_ty.unionFields(mod).values()[field_index];
18129 block,18228 return sema.addConstantMaybeRef(block, resolved_ty, (try mod.intern(.{ .un = .{
18130 resolved_ty,18229 .ty = resolved_ty.toIntern(),
18131 try Value.Tag.@"union".create(sema.arena, .{ .tag = tag_val, .val = val }),18230 .tag = try tag_val.intern(tag_ty, mod),
18132 is_ref,18231 .val = try val.intern(field.ty, mod),
18133 );18232 } })).toValue(), is_ref);
18134 }18233 }
1813518234
18136 if (is_ref) {18235 if (is_ref) {
...@@ -18171,7 +18270,7 @@ fn finishStructInit(...@@ -18171,7 +18270,7 @@ fn finishStructInit(
18171 var root_msg: ?*Module.ErrorMsg = null;18270 var root_msg: ?*Module.ErrorMsg = null;
18172 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);18271 errdefer if (root_msg) |msg| msg.destroy(sema.gpa);
1817318272
18174 switch (mod.intern_pool.indexToKey(struct_ty.ip_index)) {18273 switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) {
18175 .anon_struct_type => |anon_struct| {18274 .anon_struct_type => |anon_struct| {
18176 for (anon_struct.types, anon_struct.values, 0..) |field_ty, default_val, i| {18275 for (anon_struct.types, anon_struct.values, 0..) |field_ty, default_val, i| {
18177 if (field_inits[i] != .none) continue;18276 if (field_inits[i] != .none) continue;
...@@ -18204,7 +18303,7 @@ fn finishStructInit(...@@ -18204,7 +18303,7 @@ fn finishStructInit(
18204 for (struct_obj.fields.values(), 0..) |field, i| {18303 for (struct_obj.fields.values(), 0..) |field, i| {
18205 if (field_inits[i] != .none) continue;18304 if (field_inits[i] != .none) continue;
1820618305
18207 if (field.default_val.ip_index == .unreachable_value) {18306 if (field.default_val.toIntern() == .unreachable_value) {
18208 const field_name = struct_obj.fields.keys()[i];18307 const field_name = struct_obj.fields.keys()[i];
18209 const template = "missing struct field: {s}";18308 const template = "missing struct field: {s}";
18210 const args = .{field_name};18309 const args = .{field_name};
...@@ -18250,7 +18349,7 @@ fn finishStructInit(...@@ -18250,7 +18349,7 @@ fn finishStructInit(
18250 .intern(struct_ty.structFieldType(field_i, mod), mod);18349 .intern(struct_ty.structFieldType(field_i, mod), mod);
18251 }18350 }
18252 const struct_val = try mod.intern(.{ .aggregate = .{18351 const struct_val = try mod.intern(.{ .aggregate = .{
18253 .ty = struct_ty.ip_index,18352 .ty = struct_ty.toIntern(),
18254 .storage = .{ .elems = elems },18353 .storage = .{ .elems = elems },
18255 } });18354 } });
18256 return sema.addConstantMaybeRef(block, struct_ty, struct_val.toValue(), is_ref);18355 return sema.addConstantMaybeRef(block, struct_ty, struct_val.toValue(), is_ref);
...@@ -18331,7 +18430,7 @@ fn zirStructInitAnon(...@@ -18331,7 +18430,7 @@ fn zirStructInitAnon(
18331 gop.value_ptr.* = i;18430 gop.value_ptr.* = i;
1833218431
18333 const init = try sema.resolveInst(item.data.init);18432 const init = try sema.resolveInst(item.data.init);
18334 field_ty.* = sema.typeOf(init).ip_index;18433 field_ty.* = sema.typeOf(init).toIntern();
18335 if (field_ty.toType().zigTypeTag(mod) == .Opaque) {18434 if (field_ty.toType().zigTypeTag(mod) == .Opaque) {
18336 const msg = msg: {18435 const msg = msg: {
18337 const decl = sema.mod.declPtr(block.src_decl);18436 const decl = sema.mod.declPtr(block.src_decl);
...@@ -18464,15 +18563,19 @@ fn zirArrayInit(...@@ -18464,15 +18563,19 @@ fn zirArrayInit(
18464 } else null;18563 } else null;
1846518564
18466 const runtime_index = opt_runtime_index orelse {18565 const runtime_index = opt_runtime_index orelse {
18467 const elem_vals = try sema.arena.alloc(Value, resolved_args.len);18566 const elem_vals = try sema.arena.alloc(InternPool.Index, resolved_args.len);
1846818567 for (elem_vals, resolved_args, 0..) |*val, arg, i| {
18469 for (resolved_args, 0..) |arg, i| {18568 const elem_ty = if (array_ty.zigTypeTag(mod) == .Struct)
18569 array_ty.structFieldType(i, mod)
18570 else
18571 array_ty.elemType2(mod);
18470 // We checked that all args are comptime above.18572 // We checked that all args are comptime above.
18471 elem_vals[i] = (sema.resolveMaybeUndefVal(arg) catch unreachable).?;18573 val.* = try ((sema.resolveMaybeUndefVal(arg) catch unreachable).?).intern(elem_ty, mod);
18472 }18574 }
1847318575 return sema.addConstantMaybeRef(block, array_ty, (try mod.intern(.{ .aggregate = .{
18474 const array_val = try Value.Tag.aggregate.create(sema.arena, elem_vals);18576 .ty = array_ty.toIntern(),
18475 return sema.addConstantMaybeRef(block, array_ty, array_val, is_ref);18577 .storage = .{ .elems = elem_vals },
18578 } })).toValue(), is_ref);
18476 };18579 };
1847718580
18478 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {18581 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
...@@ -18548,7 +18651,7 @@ fn zirArrayInitAnon(...@@ -18548,7 +18651,7 @@ fn zirArrayInitAnon(
18548 for (operands, 0..) |operand, i| {18651 for (operands, 0..) |operand, i| {
18549 const operand_src = src; // TODO better source location18652 const operand_src = src; // TODO better source location
18550 const elem = try sema.resolveInst(operand);18653 const elem = try sema.resolveInst(operand);
18551 types[i] = sema.typeOf(elem).ip_index;18654 types[i] = sema.typeOf(elem).toIntern();
18552 if (types[i].toType().zigTypeTag(mod) == .Opaque) {18655 if (types[i].toType().zigTypeTag(mod) == .Opaque) {
18553 const msg = msg: {18656 const msg = msg: {
18554 const msg = try sema.errMsg(block, operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});18657 const msg = try sema.errMsg(block, operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
...@@ -18560,7 +18663,7 @@ fn zirArrayInitAnon(...@@ -18560,7 +18663,7 @@ fn zirArrayInitAnon(
18560 return sema.failWithOwnedErrorMsg(msg);18663 return sema.failWithOwnedErrorMsg(msg);
18561 }18664 }
18562 if (try sema.resolveMaybeUndefVal(elem)) |val| {18665 if (try sema.resolveMaybeUndefVal(elem)) |val| {
18563 values[i] = val.ip_index;18666 values[i] = val.toIntern();
18564 } else {18667 } else {
18565 values[i] = .none;18668 values[i] = .none;
18566 runtime_src = operand_src;18669 runtime_src = operand_src;
...@@ -18676,7 +18779,7 @@ fn fieldType(...@@ -18676,7 +18779,7 @@ fn fieldType(
18676 const resolved_ty = try sema.resolveTypeFields(cur_ty);18779 const resolved_ty = try sema.resolveTypeFields(cur_ty);
18677 cur_ty = resolved_ty;18780 cur_ty = resolved_ty;
18678 switch (cur_ty.zigTypeTag(mod)) {18781 switch (cur_ty.zigTypeTag(mod)) {
18679 .Struct => switch (mod.intern_pool.indexToKey(cur_ty.ip_index)) {18782 .Struct => switch (mod.intern_pool.indexToKey(cur_ty.toIntern())) {
18680 .anon_struct_type => |anon_struct| {18783 .anon_struct_type => |anon_struct| {
18681 const field_index = try sema.anonStructFieldIndex(block, cur_ty, field_name, field_src);18784 const field_index = try sema.anonStructFieldIndex(block, cur_ty, field_name, field_src);
18682 return sema.addType(anon_struct.types[field_index].toType());18785 return sema.addType(anon_struct.types[field_index].toType());
...@@ -18698,7 +18801,7 @@ fn fieldType(...@@ -18698,7 +18801,7 @@ fn fieldType(
18698 .Optional => {18801 .Optional => {
18699 // Struct/array init through optional requires the child type to not be a pointer.18802 // Struct/array init through optional requires the child type to not be a pointer.
18700 // If the child of .optional is a pointer it'll error on the next loop.18803 // If the child of .optional is a pointer it'll error on the next loop.
18701 cur_ty = mod.intern_pool.indexToKey(cur_ty.ip_index).opt_type.toType();18804 cur_ty = mod.intern_pool.indexToKey(cur_ty.toIntern()).opt_type.toType();
18702 continue;18805 continue;
18703 },18806 },
18704 .ErrorUnion => {18807 .ErrorUnion => {
...@@ -18776,7 +18879,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -18776,7 +18879,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
18776 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };18879 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1877718880
18778 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {18881 if (try sema.resolveDefinedValue(block, operand_src, operand)) |val| {
18779 const err_name = sema.mod.intern_pool.indexToKey(val.ip_index).err.name;18882 const err_name = sema.mod.intern_pool.indexToKey(val.toIntern()).err.name;
18780 const bytes = sema.mod.intern_pool.stringToSlice(err_name);18883 const bytes = sema.mod.intern_pool.stringToSlice(err_name);
18781 return sema.addStrLit(block, bytes);18884 return sema.addStrLit(block, bytes);
18782 }18885 }
...@@ -18820,21 +18923,21 @@ fn zirUnaryMath(...@@ -18820,21 +18923,21 @@ fn zirUnaryMath(
18820 const vec_len = operand_ty.vectorLen(mod);18923 const vec_len = operand_ty.vectorLen(mod);
18821 const result_ty = try mod.vectorType(.{18924 const result_ty = try mod.vectorType(.{
18822 .len = vec_len,18925 .len = vec_len,
18823 .child = scalar_ty.ip_index,18926 .child = scalar_ty.toIntern(),
18824 });18927 });
18825 if (try sema.resolveMaybeUndefVal(operand)) |val| {18928 if (try sema.resolveMaybeUndefVal(operand)) |val| {
18826 if (val.isUndef(mod))18929 if (val.isUndef(mod))
18827 return sema.addConstUndef(result_ty);18930 return sema.addConstUndef(result_ty);
1882818931
18829 const elems = try sema.arena.alloc(Value, vec_len);18932 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
18830 for (elems, 0..) |*elem, i| {18933 for (elems, 0..) |*elem, i| {
18831 const elem_val = try val.elemValue(sema.mod, i);18934 const elem_val = try val.elemValue(sema.mod, i);
18832 elem.* = try eval(elem_val, scalar_ty, sema.arena, sema.mod);18935 elem.* = try (try eval(elem_val, scalar_ty, sema.arena, sema.mod)).intern(scalar_ty, mod);
18833 }18936 }
18834 return sema.addConstant(18937 return sema.addConstant(result_ty, (try mod.intern(.{ .aggregate = .{
18835 result_ty,18938 .ty = result_ty.toIntern(),
18836 try Value.Tag.aggregate.create(sema.arena, elems),18939 .storage = .{ .elems = elems },
18837 );18940 } })).toValue());
18838 }18941 }
1883918942
18840 try sema.requireRuntimeBlock(block, operand_src, null);18943 try sema.requireRuntimeBlock(block, operand_src, null);
...@@ -18867,7 +18970,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -18867,7 +18970,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
18867 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {18970 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {
18868 .EnumLiteral => {18971 .EnumLiteral => {
18869 const val = try sema.resolveConstValue(block, .unneeded, operand, "");18972 const val = try sema.resolveConstValue(block, .unneeded, operand, "");
18870 const tag_name = mod.intern_pool.indexToKey(val.ip_index).enum_literal;18973 const tag_name = mod.intern_pool.indexToKey(val.toIntern()).enum_literal;
18871 const bytes = mod.intern_pool.stringToSlice(tag_name);18974 const bytes = mod.intern_pool.stringToSlice(tag_name);
18872 return sema.addStrLit(block, bytes);18975 return sema.addStrLit(block, bytes);
18873 },18976 },
...@@ -18956,7 +19059,7 @@ fn zirReify(...@@ -18956,7 +19059,7 @@ fn zirReify(
18956 .AnyFrame => return sema.failWithUseOfAsync(block, src),19059 .AnyFrame => return sema.failWithUseOfAsync(block, src),
18957 .EnumLiteral => return Air.Inst.Ref.enum_literal_type,19060 .EnumLiteral => return Air.Inst.Ref.enum_literal_type,
18958 .Int => {19061 .Int => {
18959 const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod);19062 const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod);
18960 const signedness_val = try union_val.val.fieldValue(mod, fields.getIndex("signedness").?);19063 const signedness_val = try union_val.val.fieldValue(mod, fields.getIndex("signedness").?);
18961 const bits_val = try union_val.val.fieldValue(mod, fields.getIndex("bits").?);19064 const bits_val = try union_val.val.fieldValue(mod, fields.getIndex("bits").?);
1896219065
...@@ -18966,7 +19069,7 @@ fn zirReify(...@@ -18966,7 +19069,7 @@ fn zirReify(
18966 return sema.addType(ty);19069 return sema.addType(ty);
18967 },19070 },
18968 .Vector => {19071 .Vector => {
18969 const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod);19072 const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod);
18970 const len_val = try union_val.val.fieldValue(mod, fields.getIndex("len").?);19073 const len_val = try union_val.val.fieldValue(mod, fields.getIndex("len").?);
18971 const child_val = try union_val.val.fieldValue(mod, fields.getIndex("child").?);19074 const child_val = try union_val.val.fieldValue(mod, fields.getIndex("child").?);
1897219075
...@@ -18977,12 +19080,12 @@ fn zirReify(...@@ -18977,12 +19080,12 @@ fn zirReify(
1897719080
18978 const ty = try mod.vectorType(.{19081 const ty = try mod.vectorType(.{
18979 .len = len,19082 .len = len,
18980 .child = child_ty.ip_index,19083 .child = child_ty.toIntern(),
18981 });19084 });
18982 return sema.addType(ty);19085 return sema.addType(ty);
18983 },19086 },
18984 .Float => {19087 .Float => {
18985 const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod);19088 const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod);
18986 const bits_val = try union_val.val.fieldValue(mod, fields.getIndex("bits").?);19089 const bits_val = try union_val.val.fieldValue(mod, fields.getIndex("bits").?);
1898719090
18988 const bits = @intCast(u16, bits_val.toUnsignedInt(mod));19091 const bits = @intCast(u16, bits_val.toUnsignedInt(mod));
...@@ -18997,7 +19100,7 @@ fn zirReify(...@@ -18997,7 +19100,7 @@ fn zirReify(
18997 return sema.addType(ty);19100 return sema.addType(ty);
18998 },19101 },
18999 .Pointer => {19102 .Pointer => {
19000 const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod);19103 const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod);
19001 const size_val = try union_val.val.fieldValue(mod, fields.getIndex("size").?);19104 const size_val = try union_val.val.fieldValue(mod, fields.getIndex("size").?);
19002 const is_const_val = try union_val.val.fieldValue(mod, fields.getIndex("is_const").?);19105 const is_const_val = try union_val.val.fieldValue(mod, fields.getIndex("is_const").?);
19003 const is_volatile_val = try union_val.val.fieldValue(mod, fields.getIndex("is_volatile").?);19106 const is_volatile_val = try union_val.val.fieldValue(mod, fields.getIndex("is_volatile").?);
...@@ -19088,7 +19191,7 @@ fn zirReify(...@@ -19088,7 +19191,7 @@ fn zirReify(
19088 return sema.addType(ty);19191 return sema.addType(ty);
19089 },19192 },
19090 .Array => {19193 .Array => {
19091 const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod);19194 const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod);
19092 const len_val = try union_val.val.fieldValue(mod, fields.getIndex("len").?);19195 const len_val = try union_val.val.fieldValue(mod, fields.getIndex("len").?);
19093 const child_val = try union_val.val.fieldValue(mod, fields.getIndex("child").?);19196 const child_val = try union_val.val.fieldValue(mod, fields.getIndex("child").?);
19094 const sentinel_val = try union_val.val.fieldValue(mod, fields.getIndex("sentinel").?);19197 const sentinel_val = try union_val.val.fieldValue(mod, fields.getIndex("sentinel").?);
...@@ -19107,7 +19210,7 @@ fn zirReify(...@@ -19107,7 +19210,7 @@ fn zirReify(
19107 return sema.addType(ty);19210 return sema.addType(ty);
19108 },19211 },
19109 .Optional => {19212 .Optional => {
19110 const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod);19213 const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod);
19111 const child_val = try union_val.val.fieldValue(mod, fields.getIndex("child").?);19214 const child_val = try union_val.val.fieldValue(mod, fields.getIndex("child").?);
1911219215
19113 const child_ty = child_val.toType();19216 const child_ty = child_val.toType();
...@@ -19116,7 +19219,7 @@ fn zirReify(...@@ -19116,7 +19219,7 @@ fn zirReify(
19116 return sema.addType(ty);19219 return sema.addType(ty);
19117 },19220 },
19118 .ErrorUnion => {19221 .ErrorUnion => {
19119 const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod);19222 const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod);
19120 const error_set_val = try union_val.val.fieldValue(mod, fields.getIndex("error_set").?);19223 const error_set_val = try union_val.val.fieldValue(mod, fields.getIndex("error_set").?);
19121 const payload_val = try union_val.val.fieldValue(mod, fields.getIndex("payload").?);19224 const payload_val = try union_val.val.fieldValue(mod, fields.getIndex("payload").?);
1912219225
...@@ -19155,7 +19258,7 @@ fn zirReify(...@@ -19155,7 +19258,7 @@ fn zirReify(
19155 return sema.addType(ty);19258 return sema.addType(ty);
19156 },19259 },
19157 .Struct => {19260 .Struct => {
19158 const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod);19261 const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod);
19159 const layout_val = try union_val.val.fieldValue(mod, fields.getIndex("layout").?);19262 const layout_val = try union_val.val.fieldValue(mod, fields.getIndex("layout").?);
19160 const backing_integer_val = try union_val.val.fieldValue(mod, fields.getIndex("backing_integer").?);19263 const backing_integer_val = try union_val.val.fieldValue(mod, fields.getIndex("backing_integer").?);
19161 const fields_val = try union_val.val.fieldValue(mod, fields.getIndex("fields").?);19264 const fields_val = try union_val.val.fieldValue(mod, fields.getIndex("fields").?);
...@@ -19176,7 +19279,7 @@ fn zirReify(...@@ -19176,7 +19279,7 @@ fn zirReify(
19176 return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_val, name_strategy, is_tuple_val.toBool(mod));19279 return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_val, name_strategy, is_tuple_val.toBool(mod));
19177 },19280 },
19178 .Enum => {19281 .Enum => {
19179 const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod);19282 const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod);
19180 const tag_type_val = try union_val.val.fieldValue(mod, fields.getIndex("tag_type").?);19283 const tag_type_val = try union_val.val.fieldValue(mod, fields.getIndex("tag_type").?);
19181 const fields_val = try union_val.val.fieldValue(mod, fields.getIndex("fields").?);19284 const fields_val = try union_val.val.fieldValue(mod, fields.getIndex("fields").?);
19182 const decls_val = try union_val.val.fieldValue(mod, fields.getIndex("decls").?);19285 const decls_val = try union_val.val.fieldValue(mod, fields.getIndex("decls").?);
...@@ -19517,7 +19620,7 @@ fn zirReify(...@@ -19517,7 +19620,7 @@ fn zirReify(
19517 return sema.analyzeDeclVal(block, src, new_decl_index);19620 return sema.analyzeDeclVal(block, src, new_decl_index);
19518 },19621 },
19519 .Fn => {19622 .Fn => {
19520 const fields = ip.typeOf(union_val.val.ip_index).toType().structFields(mod);19623 const fields = ip.typeOf(union_val.val.toIntern()).toType().structFields(mod);
19521 const calling_convention_val = try union_val.val.fieldValue(mod, fields.getIndex("calling_convention").?);19624 const calling_convention_val = try union_val.val.fieldValue(mod, fields.getIndex("calling_convention").?);
19522 const alignment_val = try union_val.val.fieldValue(mod, fields.getIndex("alignment").?);19625 const alignment_val = try union_val.val.fieldValue(mod, fields.getIndex("alignment").?);
19523 const is_generic_val = try union_val.val.fieldValue(mod, fields.getIndex("is_generic").?);19626 const is_generic_val = try union_val.val.fieldValue(mod, fields.getIndex("is_generic").?);
...@@ -19571,7 +19674,7 @@ fn zirReify(...@@ -19571,7 +19674,7 @@ fn zirReify(
1957119674
19572 const param_type_val = param_type_opt_val.optionalValue(mod) orelse19675 const param_type_val = param_type_opt_val.optionalValue(mod) orelse
19573 return sema.fail(block, src, "Type.Fn.Param.arg_type must be non-null for @Type", .{});19676 return sema.fail(block, src, "Type.Fn.Param.arg_type must be non-null for @Type", .{});
19574 param_type.* = param_type_val.ip_index;19677 param_type.* = param_type_val.toIntern();
1957519678
19576 if (arg_is_noalias) {19679 if (arg_is_noalias) {
19577 if (!param_type.toType().isPtrAtRuntime(mod)) {19680 if (!param_type.toType().isPtrAtRuntime(mod)) {
...@@ -19733,7 +19836,7 @@ fn reifyStruct(...@@ -19733,7 +19836,7 @@ fn reifyStruct(
19733 opt_val;19836 opt_val;
19734 break :blk try payload_val.copy(new_decl_arena_allocator);19837 break :blk try payload_val.copy(new_decl_arena_allocator);
19735 } else Value.@"unreachable";19838 } else Value.@"unreachable";
19736 if (is_comptime_val.toBool(mod) and default_val.ip_index == .unreachable_value) {19839 if (is_comptime_val.toBool(mod) and default_val.toIntern() == .unreachable_value) {
19737 return sema.fail(block, src, "comptime field without default initialization value", .{});19840 return sema.fail(block, src, "comptime field without default initialization value", .{});
19738 }19841 }
1973919842
...@@ -19956,9 +20059,17 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -19956,9 +20059,17 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1995620059
19957 const bytes = try ty.nameAllocArena(anon_decl.arena(), mod);20060 const bytes = try ty.nameAllocArena(anon_decl.arena(), mod);
1995820061
20062 const decl_ty = try mod.arrayType(.{
20063 .len = bytes.len,
20064 .child = .u8_type,
20065 .sentinel = .zero_u8,
20066 });
19959 const new_decl = try anon_decl.finish(20067 const new_decl = try anon_decl.finish(
19960 try Type.array(anon_decl.arena(), bytes.len, try mod.intValue(Type.u8, 0), Type.u8, mod),20068 decl_ty,
19961 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),20069 (try mod.intern(.{ .aggregate = .{
20070 .ty = decl_ty.toIntern(),
20071 .storage = .{ .bytes = bytes },
20072 } })).toValue(),
19962 0, // default alignment20073 0, // default alignment
19963 );20074 );
1996420075
...@@ -20125,8 +20236,8 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -20125,8 +20236,8 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
20125 break :disjoint false;20236 break :disjoint false;
20126 }20237 }
2012720238
20128 if (!ip.isInferredErrorSetType(dest_ty.ip_index) and20239 if (!ip.isInferredErrorSetType(dest_ty.toIntern()) and
20129 !ip.isInferredErrorSetType(operand_ty.ip_index))20240 !ip.isInferredErrorSetType(operand_ty.toIntern()))
20130 {20241 {
20131 break :disjoint true;20242 break :disjoint true;
20132 }20243 }
...@@ -20157,7 +20268,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat...@@ -20157,7 +20268,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
2015720268
20158 if (maybe_operand_val) |val| {20269 if (maybe_operand_val) |val| {
20159 if (!dest_ty.isAnyError(mod)) {20270 if (!dest_ty.isAnyError(mod)) {
20160 const error_name = mod.intern_pool.stringToSlice(mod.intern_pool.indexToKey(val.ip_index).err.name);20271 const error_name = mod.intern_pool.stringToSlice(mod.intern_pool.indexToKey(val.toIntern()).err.name);
20161 if (!dest_ty.errorSetHasField(error_name, mod)) {20272 if (!dest_ty.errorSetHasField(error_name, mod)) {
20162 const msg = msg: {20273 const msg = msg: {
20163 const msg = try sema.errMsg(20274 const msg = try sema.errMsg(
...@@ -20257,11 +20368,11 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -20257,11 +20368,11 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
20257 if (dest_ty.zigTypeTag(mod) == .Optional) {20368 if (dest_ty.zigTypeTag(mod) == .Optional) {
20258 var dest_ptr_info = dest_ty.optionalChild(mod).ptrInfo(mod);20369 var dest_ptr_info = dest_ty.optionalChild(mod).ptrInfo(mod);
20259 dest_ptr_info.@"align" = operand_align;20370 dest_ptr_info.@"align" = operand_align;
20260 break :blk try Type.optional(sema.arena, try Type.ptr(sema.arena, sema.mod, dest_ptr_info), mod);20371 break :blk try Type.optional(sema.arena, try Type.ptr(sema.arena, mod, dest_ptr_info), mod);
20261 } else {20372 } else {
20262 var dest_ptr_info = dest_ty.ptrInfo(mod);20373 var dest_ptr_info = dest_ty.ptrInfo(mod);
20263 dest_ptr_info.@"align" = operand_align;20374 dest_ptr_info.@"align" = operand_align;
20264 break :blk try Type.ptr(sema.arena, sema.mod, dest_ptr_info);20375 break :blk try Type.ptr(sema.arena, mod, dest_ptr_info);
20265 }20376 }
20266 };20377 };
2026720378
...@@ -20279,10 +20390,10 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -20279,10 +20390,10 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
20279 errdefer msg.destroy(sema.gpa);20390 errdefer msg.destroy(sema.gpa);
2028020391
20281 try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{20392 try sema.errNote(block, operand_src, msg, "'{}' has alignment '{d}'", .{
20282 operand_ty.fmt(sema.mod), operand_align,20393 operand_ty.fmt(mod), operand_align,
20283 });20394 });
20284 try sema.errNote(block, dest_ty_src, msg, "'{}' has alignment '{d}'", .{20395 try sema.errNote(block, dest_ty_src, msg, "'{}' has alignment '{d}'", .{
20285 dest_ty.fmt(sema.mod), dest_align,20396 dest_ty.fmt(mod), dest_align,
20286 });20397 });
2028720398
20288 try sema.errNote(block, src, msg, "consider using '@alignCast'", .{});20399 try sema.errNote(block, src, msg, "consider using '@alignCast'", .{});
...@@ -20296,11 +20407,11 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -20296,11 +20407,11 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
20296 return sema.failWithUseOfUndef(block, operand_src);20407 return sema.failWithUseOfUndef(block, operand_src);
20297 }20408 }
20298 if (!dest_ty.ptrAllowsZero(mod) and operand_val.isNull(mod)) {20409 if (!dest_ty.ptrAllowsZero(mod) and operand_val.isNull(mod)) {
20299 return sema.fail(block, operand_src, "null pointer casted to type '{}'", .{dest_ty.fmt(sema.mod)});20410 return sema.fail(block, operand_src, "null pointer casted to type '{}'", .{dest_ty.fmt(mod)});
20300 }20411 }
20301 if (dest_ty.zigTypeTag(mod) == .Optional and sema.typeOf(ptr).zigTypeTag(mod) != .Optional) {20412 if (dest_ty.zigTypeTag(mod) == .Optional and sema.typeOf(ptr).zigTypeTag(mod) != .Optional) {
20302 return sema.addConstant(dest_ty, (try mod.intern(.{ .opt = .{20413 return sema.addConstant(dest_ty, (try mod.intern(.{ .opt = .{
20303 .ty = dest_ty.ip_index,20414 .ty = dest_ty.toIntern(),
20304 .val = operand_val.toIntern(),20415 .val = operand_val.toIntern(),
20305 } })).toValue());20416 } })).toValue());
20306 }20417 }
...@@ -20335,7 +20446,7 @@ fn zirConstCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData...@@ -20335,7 +20446,7 @@ fn zirConstCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2033520446
20336 var ptr_info = operand_ty.ptrInfo(mod);20447 var ptr_info = operand_ty.ptrInfo(mod);
20337 ptr_info.mutable = true;20448 ptr_info.mutable = true;
20338 const dest_ty = try Type.ptr(sema.arena, sema.mod, ptr_info);20449 const dest_ty = try Type.ptr(sema.arena, mod, ptr_info);
2033920450
20340 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {20451 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
20341 return sema.addConstant(dest_ty, operand_val);20452 return sema.addConstant(dest_ty, operand_val);
...@@ -20356,7 +20467,7 @@ fn zirVolatileCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD...@@ -20356,7 +20467,7 @@ fn zirVolatileCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
2035620467
20357 var ptr_info = operand_ty.ptrInfo(mod);20468 var ptr_info = operand_ty.ptrInfo(mod);
20358 ptr_info.@"volatile" = false;20469 ptr_info.@"volatile" = false;
20359 const dest_ty = try Type.ptr(sema.arena, sema.mod, ptr_info);20470 const dest_ty = try Type.ptr(sema.arena, mod, ptr_info);
2036020471
20361 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {20472 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
20362 return sema.addConstant(dest_ty, operand_val);20473 return sema.addConstant(dest_ty, operand_val);
...@@ -20382,7 +20493,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -20382,7 +20493,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
20382 const dest_ty = if (is_vector)20493 const dest_ty = if (is_vector)
20383 try mod.vectorType(.{20494 try mod.vectorType(.{
20384 .len = operand_ty.vectorLen(mod),20495 .len = operand_ty.vectorLen(mod),
20385 .child = dest_scalar_ty.ip_index,20496 .child = dest_scalar_ty.toIntern(),
20386 })20497 })
20387 else20498 else
20388 dest_scalar_ty;20499 dest_scalar_ty;
...@@ -20405,7 +20516,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -20405,7 +20516,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2040520516
20406 if (operand_info.signedness != dest_info.signedness) {20517 if (operand_info.signedness != dest_info.signedness) {
20407 return sema.fail(block, operand_src, "expected {s} integer type, found '{}'", .{20518 return sema.fail(block, operand_src, "expected {s} integer type, found '{}'", .{
20408 @tagName(dest_info.signedness), operand_ty.fmt(sema.mod),20519 @tagName(dest_info.signedness), operand_ty.fmt(mod),
20409 });20520 });
20410 }20521 }
20411 if (operand_info.bits < dest_info.bits) {20522 if (operand_info.bits < dest_info.bits) {
...@@ -20414,7 +20525,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -20414,7 +20525,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
20414 block,20525 block,
20415 src,20526 src,
20416 "destination type '{}' has more bits than source type '{}'",20527 "destination type '{}' has more bits than source type '{}'",
20417 .{ dest_ty.fmt(sema.mod), operand_ty.fmt(sema.mod) },20528 .{ dest_ty.fmt(mod), operand_ty.fmt(mod) },
20418 );20529 );
20419 errdefer msg.destroy(sema.gpa);20530 errdefer msg.destroy(sema.gpa);
20420 try sema.errNote(block, dest_ty_src, msg, "destination type has {d} bits", .{20531 try sema.errNote(block, dest_ty_src, msg, "destination type has {d} bits", .{
...@@ -20434,18 +20545,18 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -20434,18 +20545,18 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
20434 if (!is_vector) {20545 if (!is_vector) {
20435 return sema.addConstant(20546 return sema.addConstant(
20436 dest_ty,20547 dest_ty,
20437 try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod),20548 try val.intTrunc(operand_ty, sema.arena, dest_info.signedness, dest_info.bits, mod),
20438 );20549 );
20439 }20550 }
20440 const elems = try sema.arena.alloc(Value, operand_ty.vectorLen(mod));20551 const elems = try sema.arena.alloc(InternPool.Index, operand_ty.vectorLen(mod));
20441 for (elems, 0..) |*elem, i| {20552 for (elems, 0..) |*elem, i| {
20442 const elem_val = try val.elemValue(sema.mod, i);20553 const elem_val = try val.elemValue(mod, i);
20443 elem.* = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod);20554 elem.* = try (try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, mod)).intern(dest_scalar_ty, mod);
20444 }20555 }
20445 return sema.addConstant(20556 return sema.addConstant(dest_ty, (try mod.intern(.{ .aggregate = .{
20446 dest_ty,20557 .ty = dest_ty.toIntern(),
20447 try Value.Tag.aggregate.create(sema.arena, elems),20558 .storage = .{ .elems = elems },
20448 );20559 } })).toValue());
20449 }20560 }
2045020561
20451 try sema.requireRuntimeBlock(block, src, operand_src);20562 try sema.requireRuntimeBlock(block, src, operand_src);
...@@ -20466,7 +20577,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A...@@ -20466,7 +20577,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2046620577
20467 var ptr_info = ptr_ty.ptrInfo(mod);20578 var ptr_info = ptr_ty.ptrInfo(mod);
20468 ptr_info.@"align" = dest_align;20579 ptr_info.@"align" = dest_align;
20469 var dest_ty = try Type.ptr(sema.arena, sema.mod, ptr_info);20580 var dest_ty = try Type.ptr(sema.arena, mod, ptr_info);
20470 if (ptr_ty.zigTypeTag(mod) == .Optional) {20581 if (ptr_ty.zigTypeTag(mod) == .Optional) {
20471 dest_ty = try mod.optionalType(dest_ty.toIntern());20582 dest_ty = try mod.optionalType(dest_ty.toIntern());
20472 }20583 }
...@@ -20531,22 +20642,22 @@ fn zirBitCount(...@@ -20531,22 +20642,22 @@ fn zirBitCount(
20531 const vec_len = operand_ty.vectorLen(mod);20642 const vec_len = operand_ty.vectorLen(mod);
20532 const result_ty = try mod.vectorType(.{20643 const result_ty = try mod.vectorType(.{
20533 .len = vec_len,20644 .len = vec_len,
20534 .child = result_scalar_ty.ip_index,20645 .child = result_scalar_ty.toIntern(),
20535 });20646 });
20536 if (try sema.resolveMaybeUndefVal(operand)) |val| {20647 if (try sema.resolveMaybeUndefVal(operand)) |val| {
20537 if (val.isUndef(mod)) return sema.addConstUndef(result_ty);20648 if (val.isUndef(mod)) return sema.addConstUndef(result_ty);
2053820649
20539 const elems = try sema.arena.alloc(Value, vec_len);20650 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
20540 const scalar_ty = operand_ty.scalarType(mod);20651 const scalar_ty = operand_ty.scalarType(mod);
20541 for (elems, 0..) |*elem, i| {20652 for (elems, 0..) |*elem, i| {
20542 const elem_val = try val.elemValue(sema.mod, i);20653 const elem_val = try val.elemValue(mod, i);
20543 const count = comptimeOp(elem_val, scalar_ty, mod);20654 const count = comptimeOp(elem_val, scalar_ty, mod);
20544 elem.* = try mod.intValue(scalar_ty, count);20655 elem.* = (try mod.intValue(scalar_ty, count)).toIntern();
20545 }20656 }
20546 return sema.addConstant(20657 return sema.addConstant(result_ty, (try mod.intern(.{ .aggregate = .{
20547 result_ty,20658 .ty = result_ty.toIntern(),
20548 try Value.Tag.aggregate.create(sema.arena, elems),20659 .storage = .{ .elems = elems },
20549 );20660 } })).toValue());
20550 } else {20661 } else {
20551 try sema.requireRuntimeBlock(block, src, operand_src);20662 try sema.requireRuntimeBlock(block, src, operand_src);
20552 return block.addTyOp(air_tag, result_ty, operand);20663 return block.addTyOp(air_tag, result_ty, operand);
...@@ -20580,7 +20691,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -20580,7 +20691,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
20580 block,20691 block,
20581 operand_src,20692 operand_src,
20582 "@byteSwap requires the number of bits to be evenly divisible by 8, but {} has {} bits",20693 "@byteSwap requires the number of bits to be evenly divisible by 8, but {} has {} bits",
20583 .{ scalar_ty.fmt(sema.mod), bits },20694 .{ scalar_ty.fmt(mod), bits },
20584 );20695 );
20585 }20696 }
2058620697
...@@ -20605,15 +20716,15 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -20605,15 +20716,15 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
20605 return sema.addConstUndef(operand_ty);20716 return sema.addConstUndef(operand_ty);
2060620717
20607 const vec_len = operand_ty.vectorLen(mod);20718 const vec_len = operand_ty.vectorLen(mod);
20608 const elems = try sema.arena.alloc(Value, vec_len);20719 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
20609 for (elems, 0..) |*elem, i| {20720 for (elems, 0..) |*elem, i| {
20610 const elem_val = try val.elemValue(sema.mod, i);20721 const elem_val = try val.elemValue(mod, i);
20611 elem.* = try elem_val.byteSwap(operand_ty, mod, sema.arena);20722 elem.* = try (try elem_val.byteSwap(operand_ty, mod, sema.arena)).intern(scalar_ty, mod);
20612 }20723 }
20613 return sema.addConstant(20724 return sema.addConstant(operand_ty, (try mod.intern(.{ .aggregate = .{
20614 operand_ty,20725 .ty = operand_ty.toIntern(),
20615 try Value.Tag.aggregate.create(sema.arena, elems),20726 .storage = .{ .elems = elems },
20616 );20727 } })).toValue());
20617 } else operand_src;20728 } else operand_src;
2061820729
20619 try sema.requireRuntimeBlock(block, src, runtime_src);20730 try sema.requireRuntimeBlock(block, src, runtime_src);
...@@ -20653,15 +20764,15 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -20653,15 +20764,15 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
20653 return sema.addConstUndef(operand_ty);20764 return sema.addConstUndef(operand_ty);
2065420765
20655 const vec_len = operand_ty.vectorLen(mod);20766 const vec_len = operand_ty.vectorLen(mod);
20656 const elems = try sema.arena.alloc(Value, vec_len);20767 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
20657 for (elems, 0..) |*elem, i| {20768 for (elems, 0..) |*elem, i| {
20658 const elem_val = try val.elemValue(sema.mod, i);20769 const elem_val = try val.elemValue(mod, i);
20659 elem.* = try elem_val.bitReverse(scalar_ty, mod, sema.arena);20770 elem.* = try (try elem_val.bitReverse(scalar_ty, mod, sema.arena)).intern(scalar_ty, mod);
20660 }20771 }
20661 return sema.addConstant(20772 return sema.addConstant(operand_ty, (try mod.intern(.{ .aggregate = .{
20662 operand_ty,20773 .ty = operand_ty.toIntern(),
20663 try Value.Tag.aggregate.create(sema.arena, elems),20774 .storage = .{ .elems = elems },
20664 );20775 } })).toValue());
20665 } else operand_src;20776 } else operand_src;
2066620777
20667 try sema.requireRuntimeBlock(block, src, runtime_src);20778 try sema.requireRuntimeBlock(block, src, runtime_src);
...@@ -20699,7 +20810,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6...@@ -20699,7 +20810,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
20699 .Struct => {},20810 .Struct => {},
20700 else => {20811 else => {
20701 const msg = msg: {20812 const msg = msg: {
20702 const msg = try sema.errMsg(block, lhs_src, "expected struct type, found '{}'", .{ty.fmt(sema.mod)});20813 const msg = try sema.errMsg(block, lhs_src, "expected struct type, found '{}'", .{ty.fmt(mod)});
20703 errdefer msg.destroy(sema.gpa);20814 errdefer msg.destroy(sema.gpa);
20704 try sema.addDeclaredHereNote(msg, ty);20815 try sema.addDeclaredHereNote(msg, ty);
20705 break :msg msg;20816 break :msg msg;
...@@ -20738,7 +20849,7 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com...@@ -20738,7 +20849,7 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com
20738 const mod = sema.mod;20849 const mod = sema.mod;
20739 switch (ty.zigTypeTag(mod)) {20850 switch (ty.zigTypeTag(mod)) {
20740 .Struct, .Enum, .Union, .Opaque => return,20851 .Struct, .Enum, .Union, .Opaque => return,
20741 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{}'", .{ty.fmt(sema.mod)}),20852 else => return sema.fail(block, src, "expected struct, enum, union, or opaque; found '{}'", .{ty.fmt(mod)}),
20742 }20853 }
20743}20854}
2074420855
...@@ -20748,7 +20859,7 @@ fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileEr...@@ -20748,7 +20859,7 @@ fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileEr
20748 switch (try ty.zigTypeTagOrPoison(mod)) {20859 switch (try ty.zigTypeTagOrPoison(mod)) {
20749 .ComptimeInt => return true,20860 .ComptimeInt => return true,
20750 .Int => return false,20861 .Int => return false,
20751 else => return sema.fail(block, src, "expected integer type, found '{}'", .{ty.fmt(sema.mod)}),20862 else => return sema.fail(block, src, "expected integer type, found '{}'", .{ty.fmt(mod)}),
20752 }20863 }
20753}20864}
2075420865
...@@ -20807,7 +20918,7 @@ fn checkPtrOperand(...@@ -20807,7 +20918,7 @@ fn checkPtrOperand(
20807 block,20918 block,
20808 ty_src,20919 ty_src,
20809 "expected pointer, found '{}'",20920 "expected pointer, found '{}'",
20810 .{ty.fmt(sema.mod)},20921 .{ty.fmt(mod)},
20811 );20922 );
20812 errdefer msg.destroy(sema.gpa);20923 errdefer msg.destroy(sema.gpa);
2081320924
...@@ -20820,7 +20931,7 @@ fn checkPtrOperand(...@@ -20820,7 +20931,7 @@ fn checkPtrOperand(
20820 .Optional => if (ty.isPtrLikeOptional(mod)) return,20931 .Optional => if (ty.isPtrLikeOptional(mod)) return,
20821 else => {},20932 else => {},
20822 }20933 }
20823 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(sema.mod)});20934 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(mod)});
20824}20935}
2082520936
20826fn checkPtrType(20937fn checkPtrType(
...@@ -20838,7 +20949,7 @@ fn checkPtrType(...@@ -20838,7 +20949,7 @@ fn checkPtrType(
20838 block,20949 block,
20839 ty_src,20950 ty_src,
20840 "expected pointer type, found '{}'",20951 "expected pointer type, found '{}'",
20841 .{ty.fmt(sema.mod)},20952 .{ty.fmt(mod)},
20842 );20953 );
20843 errdefer msg.destroy(sema.gpa);20954 errdefer msg.destroy(sema.gpa);
2084420955
...@@ -20851,7 +20962,7 @@ fn checkPtrType(...@@ -20851,7 +20962,7 @@ fn checkPtrType(
20851 .Optional => if (ty.isPtrLikeOptional(mod)) return,20962 .Optional => if (ty.isPtrLikeOptional(mod)) return,
20852 else => {},20963 else => {},
20853 }20964 }
20854 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(sema.mod)});20965 return sema.fail(block, ty_src, "expected pointer type, found '{}'", .{ty.fmt(mod)});
20855}20966}
2085620967
20857fn checkVectorElemType(20968fn checkVectorElemType(
...@@ -20865,7 +20976,7 @@ fn checkVectorElemType(...@@ -20865,7 +20976,7 @@ fn checkVectorElemType(
20865 .Int, .Float, .Bool => return,20976 .Int, .Float, .Bool => return,
20866 else => if (ty.isPtrAtRuntime(mod)) return,20977 else => if (ty.isPtrAtRuntime(mod)) return,
20867 }20978 }
20868 return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{}'", .{ty.fmt(sema.mod)});20979 return sema.fail(block, ty_src, "expected integer, float, bool, or pointer for the vector element type; found '{}'", .{ty.fmt(mod)});
20869}20980}
2087020981
20871fn checkFloatType(20982fn checkFloatType(
...@@ -20877,7 +20988,7 @@ fn checkFloatType(...@@ -20877,7 +20988,7 @@ fn checkFloatType(
20877 const mod = sema.mod;20988 const mod = sema.mod;
20878 switch (ty.zigTypeTag(mod)) {20989 switch (ty.zigTypeTag(mod)) {
20879 .ComptimeInt, .ComptimeFloat, .Float => {},20990 .ComptimeInt, .ComptimeFloat, .Float => {},
20880 else => return sema.fail(block, ty_src, "expected float type, found '{}'", .{ty.fmt(sema.mod)}),20991 else => return sema.fail(block, ty_src, "expected float type, found '{}'", .{ty.fmt(mod)}),
20881 }20992 }
20882}20993}
2088320994
...@@ -20894,7 +21005,7 @@ fn checkNumericType(...@@ -20894,7 +21005,7 @@ fn checkNumericType(
20894 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},21005 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},
20895 else => |t| return sema.fail(block, ty_src, "expected number, found '{}'", .{t}),21006 else => |t| return sema.fail(block, ty_src, "expected number, found '{}'", .{t}),
20896 },21007 },
20897 else => return sema.fail(block, ty_src, "expected number, found '{}'", .{ty.fmt(sema.mod)}),21008 else => return sema.fail(block, ty_src, "expected number, found '{}'", .{ty.fmt(mod)}),
20898 }21009 }
20899}21010}
2090021011
...@@ -20928,7 +21039,7 @@ fn checkAtomicPtrOperand(...@@ -20928,7 +21039,7 @@ fn checkAtomicPtrOperand(
20928 block,21039 block,
20929 elem_ty_src,21040 elem_ty_src,
20930 "expected bool, integer, float, enum, or pointer type; found '{}'",21041 "expected bool, integer, float, enum, or pointer type; found '{}'",
20931 .{elem_ty.fmt(sema.mod)},21042 .{elem_ty.fmt(mod)},
20932 ),21043 ),
20933 };21044 };
2093421045
...@@ -20943,7 +21054,7 @@ fn checkAtomicPtrOperand(...@@ -20943,7 +21054,7 @@ fn checkAtomicPtrOperand(
20943 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(mod)) {21054 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(mod)) {
20944 .Pointer => ptr_ty.ptrInfo(mod),21055 .Pointer => ptr_ty.ptrInfo(mod),
20945 else => {21056 else => {
20946 const wanted_ptr_ty = try Type.ptr(sema.arena, sema.mod, wanted_ptr_data);21057 const wanted_ptr_ty = try Type.ptr(sema.arena, mod, wanted_ptr_data);
20947 _ = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);21058 _ = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);
20948 unreachable;21059 unreachable;
20949 },21060 },
...@@ -20953,7 +21064,7 @@ fn checkAtomicPtrOperand(...@@ -20953,7 +21064,7 @@ fn checkAtomicPtrOperand(
20953 wanted_ptr_data.@"allowzero" = ptr_data.@"allowzero";21064 wanted_ptr_data.@"allowzero" = ptr_data.@"allowzero";
20954 wanted_ptr_data.@"volatile" = ptr_data.@"volatile";21065 wanted_ptr_data.@"volatile" = ptr_data.@"volatile";
2095521066
20956 const wanted_ptr_ty = try Type.ptr(sema.arena, sema.mod, wanted_ptr_data);21067 const wanted_ptr_ty = try Type.ptr(sema.arena, mod, wanted_ptr_data);
20957 const casted_ptr = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);21068 const casted_ptr = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);
2095821069
20959 return casted_ptr;21070 return casted_ptr;
...@@ -21016,12 +21127,12 @@ fn checkIntOrVector(...@@ -21016,12 +21127,12 @@ fn checkIntOrVector(
21016 switch (try elem_ty.zigTypeTagOrPoison(mod)) {21127 switch (try elem_ty.zigTypeTagOrPoison(mod)) {
21017 .Int => return elem_ty,21128 .Int => return elem_ty,
21018 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{21129 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{
21019 elem_ty.fmt(sema.mod),21130 elem_ty.fmt(mod),
21020 }),21131 }),
21021 }21132 }
21022 },21133 },
21023 else => return sema.fail(block, operand_src, "expected integer or vector, found '{}'", .{21134 else => return sema.fail(block, operand_src, "expected integer or vector, found '{}'", .{
21024 operand_ty.fmt(sema.mod),21135 operand_ty.fmt(mod),
21025 }),21136 }),
21026 }21137 }
21027}21138}
...@@ -21040,12 +21151,12 @@ fn checkIntOrVectorAllowComptime(...@@ -21040,12 +21151,12 @@ fn checkIntOrVectorAllowComptime(
21040 switch (try elem_ty.zigTypeTagOrPoison(mod)) {21151 switch (try elem_ty.zigTypeTagOrPoison(mod)) {
21041 .Int, .ComptimeInt => return elem_ty,21152 .Int, .ComptimeInt => return elem_ty,
21042 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{21153 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{
21043 elem_ty.fmt(sema.mod),21154 elem_ty.fmt(mod),
21044 }),21155 }),
21045 }21156 }
21046 },21157 },
21047 else => return sema.fail(block, operand_src, "expected integer or vector, found '{}'", .{21158 else => return sema.fail(block, operand_src, "expected integer or vector, found '{}'", .{
21048 operand_ty.fmt(sema.mod),21159 operand_ty.fmt(mod),
21049 }),21160 }),
21050 }21161 }
21051}21162}
...@@ -21054,7 +21165,7 @@ fn checkErrorSetType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Comp...@@ -21054,7 +21165,7 @@ fn checkErrorSetType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Comp
21054 const mod = sema.mod;21165 const mod = sema.mod;
21055 switch (ty.zigTypeTag(mod)) {21166 switch (ty.zigTypeTag(mod)) {
21056 .ErrorSet => return,21167 .ErrorSet => return,
21057 else => return sema.fail(block, src, "expected error set type, found '{}'", .{ty.fmt(sema.mod)}),21168 else => return sema.fail(block, src, "expected error set type, found '{}'", .{ty.fmt(mod)}),
21058 }21169 }
21059}21170}
2106021171
...@@ -21142,7 +21253,7 @@ fn checkVectorizableBinaryOperands(...@@ -21142,7 +21253,7 @@ fn checkVectorizableBinaryOperands(
21142 } else {21253 } else {
21143 const msg = msg: {21254 const msg = msg: {
21144 const msg = try sema.errMsg(block, src, "mixed scalar and vector operands: '{}' and '{}'", .{21255 const msg = try sema.errMsg(block, src, "mixed scalar and vector operands: '{}' and '{}'", .{
21145 lhs_ty.fmt(sema.mod), rhs_ty.fmt(sema.mod),21256 lhs_ty.fmt(mod), rhs_ty.fmt(mod),
21146 });21257 });
21147 errdefer msg.destroy(sema.gpa);21258 errdefer msg.destroy(sema.gpa);
21148 if (lhs_is_vector) {21259 if (lhs_is_vector) {
...@@ -21161,7 +21272,7 @@ fn checkVectorizableBinaryOperands(...@@ -21161,7 +21272,7 @@ fn checkVectorizableBinaryOperands(
21161fn maybeOptionsSrc(sema: *Sema, block: *Block, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc {21272fn maybeOptionsSrc(sema: *Sema, block: *Block, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc {
21162 if (base_src == .unneeded) return .unneeded;21273 if (base_src == .unneeded) return .unneeded;
21163 const mod = sema.mod;21274 const mod = sema.mod;
21164 return mod.optionsSrc(sema.mod.declPtr(block.src_decl), base_src, wanted);21275 return mod.optionsSrc(mod.declPtr(block.src_decl), base_src, wanted);
21165}21276}
2116621277
21167fn resolveExportOptions(21278fn resolveExportOptions(
...@@ -21282,7 +21393,7 @@ fn zirCmpxchg(...@@ -21282,7 +21393,7 @@ fn zirCmpxchg(
21282 block,21393 block,
21283 elem_ty_src,21394 elem_ty_src,
21284 "expected bool, integer, enum, or pointer type; found '{}'",21395 "expected bool, integer, enum, or pointer type; found '{}'",
21285 .{elem_ty.fmt(sema.mod)},21396 .{elem_ty.fmt(mod)},
21286 );21397 );
21287 }21398 }
21288 const uncasted_ptr = try sema.resolveInst(extra.ptr);21399 const uncasted_ptr = try sema.resolveInst(extra.ptr);
...@@ -21322,8 +21433,8 @@ fn zirCmpxchg(...@@ -21322,8 +21433,8 @@ fn zirCmpxchg(
21322 const ptr_ty = sema.typeOf(ptr);21433 const ptr_ty = sema.typeOf(ptr);
21323 const stored_val = (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) orelse break :rs ptr_src;21434 const stored_val = (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) orelse break :rs ptr_src;
21324 const result_val = try mod.intern(.{ .opt = .{21435 const result_val = try mod.intern(.{ .opt = .{
21325 .ty = result_ty.ip_index,21436 .ty = result_ty.toIntern(),
21326 .val = if (stored_val.eql(expected_val, elem_ty, sema.mod)) blk: {21437 .val = if (stored_val.eql(expected_val, elem_ty, mod)) blk: {
21327 try sema.storePtr(block, src, ptr, new_value);21438 try sema.storePtr(block, src, ptr, new_value);
21328 break :blk .none;21439 break :blk .none;
21329 } else stored_val.toIntern(),21440 } else stored_val.toIntern(),
...@@ -21363,7 +21474,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -21363,7 +21474,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
21363 try sema.checkVectorElemType(block, scalar_src, scalar_ty);21474 try sema.checkVectorElemType(block, scalar_src, scalar_ty);
21364 const vector_ty = try mod.vectorType(.{21475 const vector_ty = try mod.vectorType(.{
21365 .len = len,21476 .len = len,
21366 .child = scalar_ty.ip_index,21477 .child = scalar_ty.toIntern(),
21367 });21478 });
21368 if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| {21479 if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| {
21369 if (scalar_val.isUndef(mod)) return sema.addConstUndef(vector_ty);21480 if (scalar_val.isUndef(mod)) return sema.addConstUndef(vector_ty);
...@@ -21489,7 +21600,7 @@ fn analyzeShuffle(...@@ -21489,7 +21600,7 @@ fn analyzeShuffle(
2148921600
21490 const res_ty = try mod.vectorType(.{21601 const res_ty = try mod.vectorType(.{
21491 .len = mask_len,21602 .len = mask_len,
21492 .child = elem_ty.ip_index,21603 .child = elem_ty.toIntern(),
21493 });21604 });
2149421605
21495 var maybe_a_len = switch (sema.typeOf(a).zigTypeTag(mod)) {21606 var maybe_a_len = switch (sema.typeOf(a).zigTypeTag(mod)) {
...@@ -21516,11 +21627,11 @@ fn analyzeShuffle(...@@ -21516,11 +21627,11 @@ fn analyzeShuffle(
2151621627
21517 const a_ty = try mod.vectorType(.{21628 const a_ty = try mod.vectorType(.{
21518 .len = a_len,21629 .len = a_len,
21519 .child = elem_ty.ip_index,21630 .child = elem_ty.toIntern(),
21520 });21631 });
21521 const b_ty = try mod.vectorType(.{21632 const b_ty = try mod.vectorType(.{
21522 .len = b_len,21633 .len = b_len,
21523 .child = elem_ty.ip_index,21634 .child = elem_ty.toIntern(),
21524 });21635 });
2152521636
21526 if (maybe_a_len == null) a = try sema.addConstUndef(a_ty) else a = try sema.coerce(block, a_ty, a, a_src);21637 if (maybe_a_len == null) a = try sema.addConstUndef(a_ty) else a = try sema.coerce(block, a_ty, a, a_src);
...@@ -21567,25 +21678,21 @@ fn analyzeShuffle(...@@ -21567,25 +21678,21 @@ fn analyzeShuffle(
2156721678
21568 if (try sema.resolveMaybeUndefVal(a)) |a_val| {21679 if (try sema.resolveMaybeUndefVal(a)) |a_val| {
21569 if (try sema.resolveMaybeUndefVal(b)) |b_val| {21680 if (try sema.resolveMaybeUndefVal(b)) |b_val| {
21570 const values = try sema.arena.alloc(Value, mask_len);21681 const values = try sema.arena.alloc(InternPool.Index, mask_len);
2157121682 for (values) |*value| {
21572 i = 0;
21573 while (i < mask_len) : (i += 1) {
21574 const mask_elem_val = try mask.elemValue(sema.mod, i);21683 const mask_elem_val = try mask.elemValue(sema.mod, i);
21575 if (mask_elem_val.isUndef(mod)) {21684 if (mask_elem_val.isUndef(mod)) {
21576 values[i] = Value.undef;21685 value.* = try mod.intern(.{ .undef = elem_ty.toIntern() });
21577 continue;21686 continue;
21578 }21687 }
21579 const int = mask_elem_val.toSignedInt(mod);21688 const int = mask_elem_val.toSignedInt(mod);
21580 const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int);21689 const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int);
21581 if (int >= 0) {21690 values[i] = try (try (if (int >= 0) a_val else b_val).elemValue(mod, unsigned)).intern(elem_ty, mod);
21582 values[i] = try a_val.elemValue(sema.mod, unsigned);
21583 } else {
21584 values[i] = try b_val.elemValue(sema.mod, unsigned);
21585 }
21586 }21691 }
21587 const res_val = try Value.Tag.aggregate.create(sema.arena, values);21692 return sema.addConstant(res_ty, (try mod.intern(.{ .aggregate = .{
21588 return sema.addConstant(res_ty, res_val);21693 .ty = res_ty.toIntern(),
21694 .storage = .{ .elems = values },
21695 } })).toValue());
21589 }21696 }
21590 }21697 }
2159121698
...@@ -21599,22 +21706,25 @@ fn analyzeShuffle(...@@ -21599,22 +21706,25 @@ fn analyzeShuffle(
21599 const max_src = if (a_len > b_len) a_src else b_src;21706 const max_src = if (a_len > b_len) a_src else b_src;
21600 const max_len = try sema.usizeCast(block, max_src, std.math.max(a_len, b_len));21707 const max_len = try sema.usizeCast(block, max_src, std.math.max(a_len, b_len));
2160121708
21602 const expand_mask_values = try sema.arena.alloc(Value, max_len);21709 const expand_mask_values = try sema.arena.alloc(InternPool.Index, max_len);
21603 i = 0;21710 i = 0;
21604 while (i < min_len) : (i += 1) {21711 while (i < min_len) : (i += 1) {
21605 expand_mask_values[i] = try mod.intValue(Type.comptime_int, i);21712 expand_mask_values[i] = (try mod.intValue(Type.comptime_int, i)).toIntern();
21606 }21713 }
21607 while (i < max_len) : (i += 1) {21714 while (i < max_len) : (i += 1) {
21608 expand_mask_values[i] = try mod.intValue(Type.comptime_int, -1);21715 expand_mask_values[i] = (try mod.intValue(Type.comptime_int, -1)).toIntern();
21609 }21716 }
21610 const expand_mask = try Value.Tag.aggregate.create(sema.arena, expand_mask_values);21717 const expand_mask = try mod.intern(.{ .aggregate = .{
21718 .ty = (try mod.vectorType(.{ .len = @intCast(u32, max_len), .child = .comptime_int_type })).toIntern(),
21719 .storage = .{ .elems = expand_mask_values },
21720 } });
2161121721
21612 if (a_len < b_len) {21722 if (a_len < b_len) {
21613 const undef = try sema.addConstUndef(a_ty);21723 const undef = try sema.addConstUndef(a_ty);
21614 a = try sema.analyzeShuffle(block, src_node, elem_ty, a, undef, expand_mask, @intCast(u32, max_len));21724 a = try sema.analyzeShuffle(block, src_node, elem_ty, a, undef, expand_mask.toValue(), @intCast(u32, max_len));
21615 } else {21725 } else {
21616 const undef = try sema.addConstUndef(b_ty);21726 const undef = try sema.addConstUndef(b_ty);
21617 b = try sema.analyzeShuffle(block, src_node, elem_ty, b, undef, expand_mask, @intCast(u32, max_len));21727 b = try sema.analyzeShuffle(block, src_node, elem_ty, b, undef, expand_mask.toValue(), @intCast(u32, max_len));
21618 }21728 }
21619 }21729 }
2162021730
...@@ -21651,7 +21761,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -21651,7 +21761,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2165121761
21652 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison(mod)) {21762 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison(mod)) {
21653 .Vector, .Array => pred_ty.arrayLen(mod),21763 .Vector, .Array => pred_ty.arrayLen(mod),
21654 else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(sema.mod)}),21764 else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(mod)}),
21655 };21765 };
21656 const vec_len = @intCast(u32, try sema.usizeCast(block, pred_src, vec_len_u64));21766 const vec_len = @intCast(u32, try sema.usizeCast(block, pred_src, vec_len_u64));
2165721767
...@@ -21663,7 +21773,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -21663,7 +21773,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2166321773
21664 const vec_ty = try mod.vectorType(.{21774 const vec_ty = try mod.vectorType(.{
21665 .len = vec_len,21775 .len = vec_len,
21666 .child = elem_ty.ip_index,21776 .child = elem_ty.toIntern(),
21667 });21777 });
21668 const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src);21778 const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src);
21669 const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src);21779 const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src);
...@@ -21681,21 +21791,17 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C...@@ -21681,21 +21791,17 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
21681 if (maybe_b) |b_val| {21791 if (maybe_b) |b_val| {
21682 if (b_val.isUndef(mod)) return sema.addConstUndef(vec_ty);21792 if (b_val.isUndef(mod)) return sema.addConstUndef(vec_ty);
2168321793
21684 const elems = try sema.gpa.alloc(Value, vec_len);21794 const elems = try sema.gpa.alloc(InternPool.Index, vec_len);
21685 for (elems, 0..) |*elem, i| {21795 for (elems, 0..) |*elem, i| {
21686 const pred_elem_val = try pred_val.elemValue(sema.mod, i);21796 const pred_elem_val = try pred_val.elemValue(mod, i);
21687 const should_choose_a = pred_elem_val.toBool(mod);21797 const should_choose_a = pred_elem_val.toBool(mod);
21688 if (should_choose_a) {21798 elem.* = try (try (if (should_choose_a) a_val else b_val).elemValue(mod, i)).intern(elem_ty, mod);
21689 elem.* = try a_val.elemValue(sema.mod, i);
21690 } else {
21691 elem.* = try b_val.elemValue(sema.mod, i);
21692 }
21693 }21799 }
2169421800
21695 return sema.addConstant(21801 return sema.addConstant(vec_ty, (try mod.intern(.{ .aggregate = .{
21696 vec_ty,21802 .ty = vec_ty.toIntern(),
21697 try Value.Tag.aggregate.create(sema.arena, elems),21803 .storage = .{ .elems = elems },
21698 );21804 } })).toValue());
21699 } else {21805 } else {
21700 break :rs b_src;21806 break :rs b_src;
21701 }21807 }
...@@ -22019,7 +22125,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError...@@ -22019,7 +22125,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
22019 const args = try sema.resolveInst(extra.args);22125 const args = try sema.resolveInst(extra.args);
2202022126
22021 const args_ty = sema.typeOf(args);22127 const args_ty = sema.typeOf(args);
22022 if (!args_ty.isTuple(mod) and args_ty.ip_index != .empty_struct_type) {22128 if (!args_ty.isTuple(mod) and args_ty.toIntern() != .empty_struct_type) {
22023 return sema.fail(block, args_src, "expected a tuple, found '{}'", .{args_ty.fmt(sema.mod)});22129 return sema.fail(block, args_src, "expected a tuple, found '{}'", .{args_ty.fmt(sema.mod)});
22024 }22130 }
2202522131
...@@ -22102,7 +22208,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -22102,7 +22208,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
22102 const result_ptr = try Type.ptr(sema.arena, sema.mod, ptr_ty_data);22208 const result_ptr = try Type.ptr(sema.arena, sema.mod, ptr_ty_data);
2210322209
22104 if (try sema.resolveDefinedValue(block, src, casted_field_ptr)) |field_ptr_val| {22210 if (try sema.resolveDefinedValue(block, src, casted_field_ptr)) |field_ptr_val| {
22105 const field = switch (mod.intern_pool.indexToKey(field_ptr_val.ip_index)) {22211 const field = switch (mod.intern_pool.indexToKey(field_ptr_val.toIntern())) {
22106 .ptr => |ptr| switch (ptr.addr) {22212 .ptr => |ptr| switch (ptr.addr) {
22107 .field => |field| field,22213 .field => |field| field,
22108 else => null,22214 else => null,
...@@ -22244,16 +22350,16 @@ fn analyzeMinMax(...@@ -22244,16 +22350,16 @@ fn analyzeMinMax(
22244 cur_minmax = try sema.addConstant(simd_op.result_ty, result_val);22350 cur_minmax = try sema.addConstant(simd_op.result_ty, result_val);
22245 continue;22351 continue;
22246 };22352 };
22247 const elems = try sema.arena.alloc(Value, vec_len);22353 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
22248 for (elems, 0..) |*elem, i| {22354 for (elems, 0..) |*elem, i| {
22249 const lhs_elem_val = try cur_val.elemValue(mod, i);22355 const lhs_elem_val = try cur_val.elemValue(mod, i);
22250 const rhs_elem_val = try operand_val.elemValue(mod, i);22356 const rhs_elem_val = try operand_val.elemValue(mod, i);
22251 elem.* = opFunc(lhs_elem_val, rhs_elem_val, mod);22357 elem.* = try opFunc(lhs_elem_val, rhs_elem_val, mod).intern(simd_op.scalar_ty, mod);
22252 }22358 }
22253 cur_minmax = try sema.addConstant(22359 cur_minmax = try sema.addConstant(simd_op.result_ty, (try mod.intern(.{ .aggregate = .{
22254 simd_op.result_ty,22360 .ty = simd_op.result_ty.toIntern(),
22255 try Value.Tag.aggregate.create(sema.arena, elems),22361 .storage = .{ .elems = elems },
22256 );22362 } })).toValue());
22257 } else {22363 } else {
22258 runtime_known.unset(operand_idx);22364 runtime_known.unset(operand_idx);
22259 cur_minmax = try sema.addConstant(sema.typeOf(operand), uncasted_operand_val);22365 cur_minmax = try sema.addConstant(sema.typeOf(operand), uncasted_operand_val);
...@@ -22292,7 +22398,7 @@ fn analyzeMinMax(...@@ -22292,7 +22398,7 @@ fn analyzeMinMax(
22292 const refined_elem_ty = try mod.intFittingRange(cur_min, cur_max);22398 const refined_elem_ty = try mod.intFittingRange(cur_min, cur_max);
22293 break :blk try mod.vectorType(.{22399 break :blk try mod.vectorType(.{
22294 .len = len,22400 .len = len,
22295 .child = refined_elem_ty.ip_index,22401 .child = refined_elem_ty.toIntern(),
22296 });22402 });
22297 } else blk: {22403 } else blk: {
22298 if (orig_ty.isAnyFloat()) break :blk orig_ty; // can't refine floats22404 if (orig_ty.isAnyFloat()) break :blk orig_ty; // can't refine floats
...@@ -22377,7 +22483,7 @@ fn analyzeMinMax(...@@ -22377,7 +22483,7 @@ fn analyzeMinMax(
22377 const final_ty = if (is_vector)22483 const final_ty = if (is_vector)
22378 try mod.vectorType(.{22484 try mod.vectorType(.{
22379 .len = unrefined_ty.vectorLen(mod),22485 .len = unrefined_ty.vectorLen(mod),
22380 .child = final_elem_ty.ip_index,22486 .child = final_elem_ty.toIntern(),
22381 })22487 })
22382 else22488 else
22383 final_elem_ty;22489 final_elem_ty;
...@@ -22765,7 +22871,7 @@ fn zirVarExtended(...@@ -22765,7 +22871,7 @@ fn zirVarExtended(
22765 try sema.validateVarType(block, ty_src, var_ty, small.is_extern);22871 try sema.validateVarType(block, ty_src, var_ty, small.is_extern);
2276622872
22767 return sema.addConstant(var_ty, (try mod.intern(.{ .variable = .{22873 return sema.addConstant(var_ty, (try mod.intern(.{ .variable = .{
22768 .ty = var_ty.ip_index,22874 .ty = var_ty.toIntern(),
22769 .init = init_val.toIntern(),22875 .init = init_val.toIntern(),
22770 .decl = sema.owner_decl_index,22876 .decl = sema.owner_decl_index,
22771 .lib_name = if (lib_name) |lname| (try mod.intern_pool.getOrPutString(22877 .lib_name = if (lib_name) |lname| (try mod.intern_pool.getOrPutString(
...@@ -23239,7 +23345,7 @@ fn zirBuiltinExtern(...@@ -23239,7 +23345,7 @@ fn zirBuiltinExtern(
2323923345
23240 {23346 {
23241 const new_var = try mod.intern(.{ .variable = .{23347 const new_var = try mod.intern(.{ .variable = .{
23242 .ty = ty.ip_index,23348 .ty = ty.toIntern(),
23243 .init = .none,23349 .init = .none,
23244 .decl = sema.owner_decl_index,23350 .decl = sema.owner_decl_index,
23245 .is_extern = true,23351 .is_extern = true,
...@@ -23264,7 +23370,7 @@ fn zirBuiltinExtern(...@@ -23264,7 +23370,7 @@ fn zirBuiltinExtern(
23264 try sema.ensureDeclAnalyzed(new_decl_index);23370 try sema.ensureDeclAnalyzed(new_decl_index);
2326523371
23266 const ref = try mod.intern(.{ .ptr = .{23372 const ref = try mod.intern(.{ .ptr = .{
23267 .ty = (try mod.singleConstPtrType(ty)).ip_index,23373 .ty = (try mod.singleConstPtrType(ty)).toIntern(),
23268 .addr = .{ .decl = new_decl_index },23374 .addr = .{ .decl = new_decl_index },
23269 } });23375 } });
23270 return sema.addConstant(ty, ref.toValue());23376 return sema.addConstant(ty, ref.toValue());
...@@ -24207,7 +24313,7 @@ fn fieldVal(...@@ -24207,7 +24313,7 @@ fn fieldVal(
24207 switch (try child_type.zigTypeTagOrPoison(mod)) {24313 switch (try child_type.zigTypeTagOrPoison(mod)) {
24208 .ErrorSet => {24314 .ErrorSet => {
24209 const name = try ip.getOrPutString(gpa, field_name);24315 const name = try ip.getOrPutString(gpa, field_name);
24210 switch (ip.indexToKey(child_type.ip_index)) {24316 switch (ip.indexToKey(child_type.toIntern())) {
24211 .error_set_type => |error_set_type| blk: {24317 .error_set_type => |error_set_type| blk: {
24212 if (error_set_type.nameIndex(ip, name) != null) break :blk;24318 if (error_set_type.nameIndex(ip, name) != null) break :blk;
24213 const msg = msg: {24319 const msg = msg: {
...@@ -24232,7 +24338,7 @@ fn fieldVal(...@@ -24232,7 +24338,7 @@ fn fieldVal(
24232 else24338 else
24233 try mod.singleErrorSetTypeNts(name);24339 try mod.singleErrorSetTypeNts(name);
24234 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{24340 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
24235 .ty = error_set_type.ip_index,24341 .ty = error_set_type.toIntern(),
24236 .name = name,24342 .name = name,
24237 } })).toValue());24343 } })).toValue());
24238 },24344 },
...@@ -24376,9 +24482,9 @@ fn fieldPtr(...@@ -24376,9 +24482,9 @@ fn fieldPtr(
2437624482
24377 if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| {24483 if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| {
24378 return sema.addConstant(result_ty, (try mod.intern(.{ .ptr = .{24484 return sema.addConstant(result_ty, (try mod.intern(.{ .ptr = .{
24379 .ty = result_ty.ip_index,24485 .ty = result_ty.toIntern(),
24380 .addr = .{ .field = .{24486 .addr = .{ .field = .{
24381 .base = val.ip_index,24487 .base = val.toIntern(),
24382 .index = Value.slice_ptr_index,24488 .index = Value.slice_ptr_index,
24383 } },24489 } },
24384 } })).toValue());24490 } })).toValue());
...@@ -24396,9 +24502,9 @@ fn fieldPtr(...@@ -24396,9 +24502,9 @@ fn fieldPtr(
2439624502
24397 if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| {24503 if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| {
24398 return sema.addConstant(result_ty, (try mod.intern(.{ .ptr = .{24504 return sema.addConstant(result_ty, (try mod.intern(.{ .ptr = .{
24399 .ty = result_ty.ip_index,24505 .ty = result_ty.toIntern(),
24400 .addr = .{ .field = .{24506 .addr = .{ .field = .{
24401 .base = val.ip_index,24507 .base = val.toIntern(),
24402 .index = Value.slice_len_index,24508 .index = Value.slice_len_index,
24403 } },24509 } },
24404 } })).toValue());24510 } })).toValue());
...@@ -24429,7 +24535,7 @@ fn fieldPtr(...@@ -24429,7 +24535,7 @@ fn fieldPtr(
24429 switch (child_type.zigTypeTag(mod)) {24535 switch (child_type.zigTypeTag(mod)) {
24430 .ErrorSet => {24536 .ErrorSet => {
24431 const name = try ip.getOrPutString(gpa, field_name);24537 const name = try ip.getOrPutString(gpa, field_name);
24432 switch (ip.indexToKey(child_type.ip_index)) {24538 switch (ip.indexToKey(child_type.toIntern())) {
24433 .error_set_type => |error_set_type| blk: {24539 .error_set_type => |error_set_type| blk: {
24434 if (error_set_type.nameIndex(ip, name) != null) {24540 if (error_set_type.nameIndex(ip, name) != null) {
24435 break :blk;24541 break :blk;
...@@ -24454,7 +24560,7 @@ fn fieldPtr(...@@ -24454,7 +24560,7 @@ fn fieldPtr(
24454 return sema.analyzeDeclRef(try anon_decl.finish(24560 return sema.analyzeDeclRef(try anon_decl.finish(
24455 error_set_type,24561 error_set_type,
24456 (try mod.intern(.{ .err = .{24562 (try mod.intern(.{ .err = .{
24457 .ty = error_set_type.ip_index,24563 .ty = error_set_type.toIntern(),
24458 .name = name,24564 .name = name,
24459 } })).toValue(),24565 } })).toValue(),
24460 0, // default alignment24566 0, // default alignment
...@@ -24722,9 +24828,9 @@ fn finishFieldCallBind(...@@ -24722,9 +24828,9 @@ fn finishFieldCallBind(
2472224828
24723 if (try sema.resolveDefinedValue(block, src, object_ptr)) |struct_ptr_val| {24829 if (try sema.resolveDefinedValue(block, src, object_ptr)) |struct_ptr_val| {
24724 const pointer = try sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{24830 const pointer = try sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{
24725 .ty = ptr_field_ty.ip_index,24831 .ty = ptr_field_ty.toIntern(),
24726 .addr = .{ .field = .{24832 .addr = .{ .field = .{
24727 .base = struct_ptr_val.ip_index,24833 .base = struct_ptr_val.toIntern(),
24728 .index = field_index,24834 .index = field_index,
24729 } },24835 } },
24730 } })).toValue());24836 } })).toValue());
...@@ -24908,7 +25014,7 @@ fn structFieldPtrByIndex(...@@ -24908,7 +25014,7 @@ fn structFieldPtrByIndex(
2490825014
24909 if (field.is_comptime) {25015 if (field.is_comptime) {
24910 const val = try mod.intern(.{ .ptr = .{25016 const val = try mod.intern(.{ .ptr = .{
24911 .ty = ptr_field_ty.ip_index,25017 .ty = ptr_field_ty.toIntern(),
24912 .addr = .{ .comptime_field = try field.default_val.intern(field.ty, mod) },25018 .addr = .{ .comptime_field = try field.default_val.intern(field.ty, mod) },
24913 } });25019 } });
24914 return sema.addConstant(ptr_field_ty, val.toValue());25020 return sema.addConstant(ptr_field_ty, val.toValue());
...@@ -24916,7 +25022,7 @@ fn structFieldPtrByIndex(...@@ -24916,7 +25022,7 @@ fn structFieldPtrByIndex(
2491625022
24917 if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| {25023 if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| {
24918 const val = try mod.intern(.{ .ptr = .{25024 const val = try mod.intern(.{ .ptr = .{
24919 .ty = ptr_field_ty.ip_index,25025 .ty = ptr_field_ty.toIntern(),
24920 .addr = .{ .field = .{25026 .addr = .{ .field = .{
24921 .base = try struct_ptr_val.intern(struct_ptr_ty, mod),25027 .base = try struct_ptr_val.intern(struct_ptr_ty, mod),
24922 .index = field_index,25028 .index = field_index,
...@@ -24942,7 +25048,7 @@ fn structFieldVal(...@@ -24942,7 +25048,7 @@ fn structFieldVal(
24942 assert(unresolved_struct_ty.zigTypeTag(mod) == .Struct);25048 assert(unresolved_struct_ty.zigTypeTag(mod) == .Struct);
2494325049
24944 const struct_ty = try sema.resolveTypeFields(unresolved_struct_ty);25050 const struct_ty = try sema.resolveTypeFields(unresolved_struct_ty);
24945 switch (mod.intern_pool.indexToKey(struct_ty.ip_index)) {25051 switch (mod.intern_pool.indexToKey(struct_ty.toIntern())) {
24946 .struct_type => |struct_type| {25052 .struct_type => |struct_type| {
24947 const struct_obj = mod.structPtrUnwrap(struct_type.index).?;25053 const struct_obj = mod.structPtrUnwrap(struct_type.index).?;
24948 if (struct_obj.is_tuple) return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty);25054 if (struct_obj.is_tuple) return sema.tupleFieldVal(block, src, struct_byval, field_name, field_name_src, struct_ty);
...@@ -25116,9 +25222,9 @@ fn unionFieldPtr(...@@ -25116,9 +25222,9 @@ fn unionFieldPtr(
25116 .Packed, .Extern => {},25222 .Packed, .Extern => {},
25117 }25223 }
25118 return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{25224 return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{
25119 .ty = ptr_field_ty.ip_index,25225 .ty = ptr_field_ty.toIntern(),
25120 .addr = .{ .field = .{25226 .addr = .{ .field = .{
25121 .base = union_ptr_val.ip_index,25227 .base = union_ptr_val.toIntern(),
25122 .index = field_index,25228 .index = field_index,
25123 } },25229 } },
25124 } })).toValue());25230 } })).toValue());
...@@ -25413,16 +25519,16 @@ fn tupleFieldPtr(...@@ -25413,16 +25519,16 @@ fn tupleFieldPtr(
2541325519
25414 if (try tuple_ty.structFieldValueComptime(mod, field_index)) |default_val| {25520 if (try tuple_ty.structFieldValueComptime(mod, field_index)) |default_val| {
25415 return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{25521 return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{
25416 .ty = ptr_field_ty.ip_index,25522 .ty = ptr_field_ty.toIntern(),
25417 .addr = .{ .comptime_field = default_val.ip_index },25523 .addr = .{ .comptime_field = default_val.toIntern() },
25418 } })).toValue());25524 } })).toValue());
25419 }25525 }
2542025526
25421 if (try sema.resolveMaybeUndefVal(tuple_ptr)) |tuple_ptr_val| {25527 if (try sema.resolveMaybeUndefVal(tuple_ptr)) |tuple_ptr_val| {
25422 return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{25528 return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{
25423 .ty = ptr_field_ty.ip_index,25529 .ty = ptr_field_ty.toIntern(),
25424 .addr = .{ .field = .{25530 .addr = .{ .field = .{
25425 .base = tuple_ptr_val.ip_index,25531 .base = tuple_ptr_val.toIntern(),
25426 .index = field_index,25532 .index = field_index,
25427 } },25533 } },
25428 } })).toValue());25534 } })).toValue());
...@@ -25787,11 +25893,11 @@ fn coerceExtra(...@@ -25787,11 +25893,11 @@ fn coerceExtra(
25787 var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src);25893 var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src);
25788 if (in_memory_result == .ok) {25894 if (in_memory_result == .ok) {
25789 if (maybe_inst_val) |val| {25895 if (maybe_inst_val) |val| {
25790 if (val.ip_index == .none or val.ip_index == .null_value) {25896 if (val.ip_index == .none) {
25791 // Keep the comptime Value representation; take the new type.25897 // Keep the comptime Value representation; take the new type.
25792 return sema.addConstant(dest_ty, val);25898 return sema.addConstant(dest_ty, val);
25793 } else {25899 } else {
25794 const new_val = try mod.intern_pool.getCoerced(sema.gpa, val.ip_index, dest_ty.ip_index);25900 const new_val = try mod.intern_pool.getCoerced(sema.gpa, val.toIntern(), dest_ty.toIntern());
25795 return sema.addConstant(dest_ty, new_val.toValue());25901 return sema.addConstant(dest_ty, new_val.toValue());
25796 }25902 }
25797 }25903 }
...@@ -25816,7 +25922,7 @@ fn coerceExtra(...@@ -25816,7 +25922,7 @@ fn coerceExtra(
25816 // cast from ?*T and ?[*]T to ?*anyopaque25922 // cast from ?*T and ?[*]T to ?*anyopaque
25817 // but don't do it if the source type is a double pointer25923 // but don't do it if the source type is a double pointer
25818 if (dest_ty.isPtrLikeOptional(mod) and25924 if (dest_ty.isPtrLikeOptional(mod) and
25819 dest_ty.elemType2(mod).ip_index == .anyopaque_type and25925 dest_ty.elemType2(mod).toIntern() == .anyopaque_type and
25820 inst_ty.isPtrAtRuntime(mod))25926 inst_ty.isPtrAtRuntime(mod))
25821 anyopaque_check: {25927 anyopaque_check: {
25822 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :optional;25928 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :optional;
...@@ -25954,7 +26060,7 @@ fn coerceExtra(...@@ -25954,7 +26060,7 @@ fn coerceExtra(
2595426060
25955 // cast from *T and [*]T to *anyopaque26061 // cast from *T and [*]T to *anyopaque
25956 // but don't do it if the source type is a double pointer26062 // but don't do it if the source type is a double pointer
25957 if (dest_info.pointee_type.ip_index == .anyopaque_type and inst_ty.zigTypeTag(mod) == .Pointer) to_anyopaque: {26063 if (dest_info.pointee_type.toIntern() == .anyopaque_type and inst_ty.zigTypeTag(mod) == .Pointer) to_anyopaque: {
25958 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer;26064 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer;
25959 const elem_ty = inst_ty.elemType2(mod);26065 const elem_ty = inst_ty.elemType2(mod);
25960 if (elem_ty.zigTypeTag(mod) == .Pointer or elem_ty.isPtrLikeOptional(mod)) {26066 if (elem_ty.zigTypeTag(mod) == .Pointer or elem_ty.isPtrLikeOptional(mod)) {
...@@ -26084,12 +26190,12 @@ fn coerceExtra(...@@ -26084,12 +26190,12 @@ fn coerceExtra(
26084 // Optional slice is represented with a null pointer so26190 // Optional slice is represented with a null pointer so
26085 // we use a dummy pointer value with the required alignment.26191 // we use a dummy pointer value with the required alignment.
26086 return sema.addConstant(dest_ty, (try mod.intern(.{ .ptr = .{26192 return sema.addConstant(dest_ty, (try mod.intern(.{ .ptr = .{
26087 .ty = dest_ty.ip_index,26193 .ty = dest_ty.toIntern(),
26088 .addr = .{ .int = (if (dest_info.@"align" != 0)26194 .addr = .{ .int = (if (dest_info.@"align" != 0)
26089 try mod.intValue(Type.usize, dest_info.@"align")26195 try mod.intValue(Type.usize, dest_info.@"align")
26090 else26196 else
26091 try dest_info.pointee_type.lazyAbiAlignment(mod)).ip_index },26197 try dest_info.pointee_type.lazyAbiAlignment(mod)).toIntern() },
26092 .len = (try mod.intValue(Type.usize, 0)).ip_index,26198 .len = (try mod.intValue(Type.usize, 0)).toIntern(),
26093 } })).toValue());26199 } })).toValue());
26094 }26200 }
2609526201
...@@ -26166,7 +26272,7 @@ fn coerceExtra(...@@ -26166,7 +26272,7 @@ fn coerceExtra(
26166 if (!opts.report_err) return error.NotCoercible;26272 if (!opts.report_err) return error.NotCoercible;
26167 return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(sema.mod), val.fmtValue(inst_ty, sema.mod) });26273 return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(sema.mod), val.fmtValue(inst_ty, sema.mod) });
26168 }26274 }
26169 const new_val = try mod.intern_pool.getCoerced(sema.gpa, val.ip_index, dest_ty.ip_index);26275 const new_val = try mod.intern_pool.getCoerced(sema.gpa, val.toIntern(), dest_ty.toIntern());
26170 return try sema.addConstant(dest_ty, new_val.toValue());26276 return try sema.addConstant(dest_ty, new_val.toValue());
26171 }26277 }
26172 if (dest_ty.zigTypeTag(mod) == .ComptimeInt) {26278 if (dest_ty.zigTypeTag(mod) == .ComptimeInt) {
...@@ -26258,7 +26364,7 @@ fn coerceExtra(...@@ -26258,7 +26364,7 @@ fn coerceExtra(
26258 .EnumLiteral => {26364 .EnumLiteral => {
26259 // enum literal to enum26365 // enum literal to enum
26260 const val = try sema.resolveConstValue(block, .unneeded, inst, "");26366 const val = try sema.resolveConstValue(block, .unneeded, inst, "");
26261 const string = mod.intern_pool.indexToKey(val.ip_index).enum_literal;26367 const string = mod.intern_pool.indexToKey(val.toIntern()).enum_literal;
26262 const bytes = mod.intern_pool.stringToSlice(string);26368 const bytes = mod.intern_pool.stringToSlice(string);
26263 const field_index = dest_ty.enumFieldIndex(bytes, mod) orelse {26369 const field_index = dest_ty.enumFieldIndex(bytes, mod) orelse {
26264 const msg = msg: {26370 const msg = msg: {
...@@ -26294,14 +26400,14 @@ fn coerceExtra(...@@ -26294,14 +26400,14 @@ fn coerceExtra(
26294 .ErrorUnion => switch (inst_ty.zigTypeTag(mod)) {26400 .ErrorUnion => switch (inst_ty.zigTypeTag(mod)) {
26295 .ErrorUnion => eu: {26401 .ErrorUnion => eu: {
26296 if (maybe_inst_val) |inst_val| {26402 if (maybe_inst_val) |inst_val| {
26297 switch (inst_val.ip_index) {26403 switch (inst_val.toIntern()) {
26298 .undef => return sema.addConstUndef(dest_ty),26404 .undef => return sema.addConstUndef(dest_ty),
26299 else => switch (mod.intern_pool.indexToKey(inst_val.ip_index)) {26405 else => switch (mod.intern_pool.indexToKey(inst_val.toIntern())) {
26300 .error_union => |error_union| switch (error_union.val) {26406 .error_union => |error_union| switch (error_union.val) {
26301 .err_name => |err_name| {26407 .err_name => |err_name| {
26302 const error_set_ty = inst_ty.errorUnionSet(mod);26408 const error_set_ty = inst_ty.errorUnionSet(mod);
26303 const error_set_val = try sema.addConstant(error_set_ty, (try mod.intern(.{ .err = .{26409 const error_set_val = try sema.addConstant(error_set_ty, (try mod.intern(.{ .err = .{
26304 .ty = error_set_ty.ip_index,26410 .ty = error_set_ty.toIntern(),
26305 .name = err_name,26411 .name = err_name,
26306 } })).toValue());26412 } })).toValue());
26307 return sema.wrapErrorUnionSet(block, dest_ty, error_set_val, inst_src);26413 return sema.wrapErrorUnionSet(block, dest_ty, error_set_val, inst_src);
...@@ -26597,7 +26703,7 @@ const InMemoryCoercionResult = union(enum) {...@@ -26597,7 +26703,7 @@ const InMemoryCoercionResult = union(enum) {
26597 break;26703 break;
26598 },26704 },
26599 .array_sentinel => |sentinel| {26705 .array_sentinel => |sentinel| {
26600 if (sentinel.actual.ip_index != .unreachable_value) {26706 if (sentinel.actual.toIntern() != .unreachable_value) {
26601 try sema.errNote(block, src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{26707 try sema.errNote(block, src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{
26602 sentinel.actual.fmtValue(sentinel.ty, sema.mod), sentinel.wanted.fmtValue(sentinel.ty, sema.mod),26708 sentinel.actual.fmtValue(sentinel.ty, sema.mod), sentinel.wanted.fmtValue(sentinel.ty, sema.mod),
26603 });26709 });
...@@ -26724,7 +26830,7 @@ const InMemoryCoercionResult = union(enum) {...@@ -26724,7 +26830,7 @@ const InMemoryCoercionResult = union(enum) {
26724 break;26830 break;
26725 },26831 },
26726 .ptr_sentinel => |sentinel| {26832 .ptr_sentinel => |sentinel| {
26727 if (sentinel.actual.ip_index != .unreachable_value) {26833 if (sentinel.actual.toIntern() != .unreachable_value) {
26728 try sema.errNote(block, src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{26834 try sema.errNote(block, src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{
26729 sentinel.actual.fmtValue(sentinel.ty, sema.mod), sentinel.wanted.fmtValue(sentinel.ty, sema.mod),26835 sentinel.actual.fmtValue(sentinel.ty, sema.mod), sentinel.wanted.fmtValue(sentinel.ty, sema.mod),
26730 });26836 });
...@@ -27016,9 +27122,9 @@ fn coerceInMemoryAllowedErrorSets(...@@ -27016,9 +27122,9 @@ fn coerceInMemoryAllowedErrorSets(
27016 const dst_ies = mod.inferredErrorSetPtr(dst_ies_index);27122 const dst_ies = mod.inferredErrorSetPtr(dst_ies_index);
27017 // We will make an effort to return `ok` without resolving either error set, to27123 // We will make an effort to return `ok` without resolving either error set, to
27018 // avoid unnecessary "unable to resolve error set" dependency loop errors.27124 // avoid unnecessary "unable to resolve error set" dependency loop errors.
27019 switch (src_ty.ip_index) {27125 switch (src_ty.toIntern()) {
27020 .anyerror_type => {},27126 .anyerror_type => {},
27021 else => switch (ip.indexToKey(src_ty.ip_index)) {27127 else => switch (ip.indexToKey(src_ty.toIntern())) {
27022 .inferred_error_set_type => |src_index| {27128 .inferred_error_set_type => |src_index| {
27023 // If both are inferred error sets of functions, and27129 // If both are inferred error sets of functions, and
27024 // the dest includes the source function, the coercion is OK.27130 // the dest includes the source function, the coercion is OK.
...@@ -27054,15 +27160,15 @@ fn coerceInMemoryAllowedErrorSets(...@@ -27054,15 +27160,15 @@ fn coerceInMemoryAllowedErrorSets(
27054 var missing_error_buf = std.ArrayList(InternPool.NullTerminatedString).init(gpa);27160 var missing_error_buf = std.ArrayList(InternPool.NullTerminatedString).init(gpa);
27055 defer missing_error_buf.deinit();27161 defer missing_error_buf.deinit();
2705627162
27057 switch (src_ty.ip_index) {27163 switch (src_ty.toIntern()) {
27058 .anyerror_type => switch (ip.indexToKey(dest_ty.ip_index)) {27164 .anyerror_type => switch (ip.indexToKey(dest_ty.toIntern())) {
27059 .inferred_error_set_type => unreachable, // Caught by dest_ty.isAnyError(mod) above.27165 .inferred_error_set_type => unreachable, // Caught by dest_ty.isAnyError(mod) above.
27060 .simple_type => unreachable, // filtered out above27166 .simple_type => unreachable, // filtered out above
27061 .error_set_type => return .from_anyerror,27167 .error_set_type => return .from_anyerror,
27062 else => unreachable,27168 else => unreachable,
27063 },27169 },
2706427170
27065 else => switch (ip.indexToKey(src_ty.ip_index)) {27171 else => switch (ip.indexToKey(src_ty.toIntern())) {
27066 .inferred_error_set_type => |src_index| {27172 .inferred_error_set_type => |src_index| {
27067 const src_data = mod.inferredErrorSetPtr(src_index);27173 const src_data = mod.inferredErrorSetPtr(src_index);
2706827174
...@@ -27520,9 +27626,9 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {...@@ -27520,9 +27626,9 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
27520 // allocations is relevant to this function, or why it would have27626 // allocations is relevant to this function, or why it would have
27521 // different behavior depending on whether the types were inferred.27627 // different behavior depending on whether the types were inferred.
27522 // Something seems wrong here.27628 // Something seems wrong here.
27523 if (prev_ptr_ty.ip_index == .none) {27629 switch (prev_ptr_ty.ip_index) {
27524 if (prev_ptr_ty.ip_index == .inferred_alloc_mut_type) return null;27630 .inferred_alloc_mut_type, .inferred_alloc_const_type => return null,
27525 if (prev_ptr_ty.ip_index == .inferred_alloc_const_type) return null;27631 else => {},
27526 }27632 }
2752727633
27528 const prev_ptr_child_ty = prev_ptr_ty.childType(mod);27634 const prev_ptr_child_ty = prev_ptr_ty.childType(mod);
...@@ -27554,11 +27660,11 @@ fn storePtrVal(...@@ -27554,11 +27660,11 @@ fn storePtrVal(
27554) !void {27660) !void {
27555 const mod = sema.mod;27661 const mod = sema.mod;
27556 var mut_kit = try sema.beginComptimePtrMutation(block, src, ptr_val, operand_ty);27662 var mut_kit = try sema.beginComptimePtrMutation(block, src, ptr_val, operand_ty);
27557 try sema.checkComptimeVarStore(block, src, mut_kit.decl_ref_mut);27663 try sema.checkComptimeVarStore(block, src, mut_kit.mut_decl);
2755827664
27559 switch (mut_kit.pointee) {27665 switch (mut_kit.pointee) {
27560 .direct => |val_ptr| {27666 .direct => |val_ptr| {
27561 if (mut_kit.decl_ref_mut.runtime_index == .comptime_field_ptr) {27667 if (mut_kit.mut_decl.runtime_index == .comptime_field_ptr) {
27562 if (!operand_val.eql(val_ptr.*, operand_ty, sema.mod)) {27668 if (!operand_val.eql(val_ptr.*, operand_ty, sema.mod)) {
27563 // TODO use failWithInvalidComptimeFieldStore27669 // TODO use failWithInvalidComptimeFieldStore
27564 return sema.fail(block, src, "value stored in comptime field does not match the default value of the field", .{});27670 return sema.fail(block, src, "value stored in comptime field does not match the default value of the field", .{});
...@@ -27601,7 +27707,7 @@ fn storePtrVal(...@@ -27601,7 +27707,7 @@ fn storePtrVal(
27601}27707}
2760227708
27603const ComptimePtrMutationKit = struct {27709const ComptimePtrMutationKit = struct {
27604 decl_ref_mut: InternPool.Key.Ptr.Addr.MutDecl,27710 mut_decl: InternPool.Key.Ptr.Addr.MutDecl,
27605 pointee: union(enum) {27711 pointee: union(enum) {
27606 /// The pointer type matches the actual comptime Value so a direct27712 /// The pointer type matches the actual comptime Value so a direct
27607 /// modification is possible.27713 /// modification is possible.
...@@ -27627,12 +27733,12 @@ const ComptimePtrMutationKit = struct {...@@ -27627,12 +27733,12 @@ const ComptimePtrMutationKit = struct {
27627 decl_arena: std.heap.ArenaAllocator = undefined,27733 decl_arena: std.heap.ArenaAllocator = undefined,
2762827734
27629 fn beginArena(self: *ComptimePtrMutationKit, mod: *Module) Allocator {27735 fn beginArena(self: *ComptimePtrMutationKit, mod: *Module) Allocator {
27630 const decl = mod.declPtr(self.decl_ref_mut.decl);27736 const decl = mod.declPtr(self.mut_decl.decl);
27631 return decl.value_arena.?.acquire(mod.gpa, &self.decl_arena);27737 return decl.value_arena.?.acquire(mod.gpa, &self.decl_arena);
27632 }27738 }
2763327739
27634 fn finishArena(self: *ComptimePtrMutationKit, mod: *Module) void {27740 fn finishArena(self: *ComptimePtrMutationKit, mod: *Module) void {
27635 const decl = mod.declPtr(self.decl_ref_mut.decl);27741 const decl = mod.declPtr(self.mut_decl.decl);
27636 decl.value_arena.?.release(&self.decl_arena);27742 decl.value_arena.?.release(&self.decl_arena);
27637 self.decl_arena = undefined;27743 self.decl_arena = undefined;
27638 }27744 }
...@@ -27645,99 +27751,85 @@ fn beginComptimePtrMutation(...@@ -27645,99 +27751,85 @@ fn beginComptimePtrMutation(
27645 ptr_val: Value,27751 ptr_val: Value,
27646 ptr_elem_ty: Type,27752 ptr_elem_ty: Type,
27647) CompileError!ComptimePtrMutationKit {27753) CompileError!ComptimePtrMutationKit {
27648 if (true) unreachable;
27649 const mod = sema.mod;27754 const mod = sema.mod;
27650 switch (ptr_val.tag()) {27755 const ptr = mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr;
27651 .decl_ref_mut => {27756 switch (ptr.addr) {
27652 const decl_ref_mut = ptr_val.castTag(.decl_ref_mut).?.data;27757 .decl => unreachable, // isComptimeMutablePtr has been checked already
27653 const decl = sema.mod.declPtr(decl_ref_mut.decl_index);27758 .mut_decl => |mut_decl| {
27654 return sema.beginComptimePtrMutationInner(block, src, decl.ty, &decl.val, ptr_elem_ty, decl_ref_mut);27759 const decl = mod.declPtr(mut_decl.decl);
27760 return sema.beginComptimePtrMutationInner(block, src, decl.ty, &decl.val, ptr_elem_ty, mut_decl);
27655 },27761 },
27656 .comptime_field_ptr => {27762 .comptime_field => |comptime_field| {
27657 const payload = ptr_val.castTag(.comptime_field_ptr).?.data;
27658 const duped = try sema.arena.create(Value);27763 const duped = try sema.arena.create(Value);
27659 duped.* = payload.field_val;27764 duped.* = comptime_field.toValue();
27660 return sema.beginComptimePtrMutationInner(block, src, payload.field_ty, duped, ptr_elem_ty, .{27765 return sema.beginComptimePtrMutationInner(block, src, mod.intern_pool.typeOf(ptr_val.toIntern()).toType(), duped, ptr_elem_ty, .{
27661 .decl_index = @intToEnum(Module.Decl.Index, 0),27766 .decl = undefined,
27662 .runtime_index = .comptime_field_ptr,27767 .runtime_index = .comptime_field_ptr,
27663 });27768 });
27664 },27769 },
27665 .elem_ptr => {27770 else => unreachable,
27666 const elem_ptr = ptr_val.castTag(.elem_ptr).?.data;27771 }
27667 var parent = try sema.beginComptimePtrMutation(block, src, elem_ptr.array_ptr, elem_ptr.elem_ty);27772 if (true) unreachable;
2766827773 switch (ptr_val.toIntern()) {
27669 switch (parent.pointee) {27774 .none => switch (ptr_val.tag()) {
27670 .direct => |val_ptr| switch (parent.ty.zigTypeTag(mod)) {27775 .decl_ref_mut => {
27671 .Array, .Vector => {27776 const decl_ref_mut = ptr_val.castTag(.decl_ref_mut).?.data;
27672 const check_len = parent.ty.arrayLenIncludingSentinel(mod);27777 const decl = sema.mod.declPtr(decl_ref_mut.decl_index);
27673 if (elem_ptr.index >= check_len) {27778 return sema.beginComptimePtrMutationInner(block, src, decl.ty, &decl.val, ptr_elem_ty, decl_ref_mut);
27674 // TODO have the parent include the decl so we can say "declared here"27779 },
27675 return sema.fail(block, src, "comptime store of index {d} out of bounds of array length {d}", .{27780 .comptime_field_ptr => {
27676 elem_ptr.index, check_len,27781 const payload = ptr_val.castTag(.comptime_field_ptr).?.data;
27677 });27782 const duped = try sema.arena.create(Value);
27678 }27783 duped.* = payload.field_val;
27679 const elem_ty = parent.ty.childType(mod);27784 return sema.beginComptimePtrMutationInner(block, src, payload.field_ty, duped, ptr_elem_ty, .{
2768027785 .decl_index = @intToEnum(Module.Decl.Index, 0),
27681 // We might have a pointer to multiple elements of the array (e.g. a pointer27786 .runtime_index = .comptime_field_ptr,
27682 // to a sub-array). In this case, we just have to reinterpret the relevant27787 });
27683 // bytes of the whole array rather than any single element.27788 },
27684 const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty);27789 .elem_ptr => {
27685 if (elem_abi_size_u64 < try sema.typeAbiSize(ptr_elem_ty)) {27790 const elem_ptr = ptr_val.castTag(.elem_ptr).?.data;
27686 const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);27791 var parent = try sema.beginComptimePtrMutation(block, src, elem_ptr.array_ptr, elem_ptr.elem_ty);
27687 return .{27792
27688 .decl_ref_mut = parent.decl_ref_mut,27793 switch (parent.pointee) {
27689 .pointee = .{ .reinterpret = .{27794 .direct => |val_ptr| switch (parent.ty.zigTypeTag(mod)) {
27690 .val_ptr = val_ptr,27795 .Array, .Vector => {
27691 .byte_offset = elem_abi_size * elem_ptr.index,27796 const check_len = parent.ty.arrayLenIncludingSentinel(mod);
27692 } },27797 if (elem_ptr.index >= check_len) {
27693 .ty = parent.ty,27798 // TODO have the parent include the decl so we can say "declared here"
27694 };27799 return sema.fail(block, src, "comptime store of index {d} out of bounds of array length {d}", .{
27695 }27800 elem_ptr.index, check_len,
2769627801 });
27697 switch (val_ptr.ip_index) {27802 }
27698 .undef => {27803 const elem_ty = parent.ty.childType(mod);
27699 // An array has been initialized to undefined at comptime and now we27804
27700 // are for the first time setting an element. We must change the representation27805 // We might have a pointer to multiple elements of the array (e.g. a pointer
27701 // of the array from `undef` to `array`.27806 // to a sub-array). In this case, we just have to reinterpret the relevant
27702 const arena = parent.beginArena(sema.mod);27807 // bytes of the whole array rather than any single element.
27703 defer parent.finishArena(sema.mod);27808 const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty);
2770427809 if (elem_abi_size_u64 < try sema.typeAbiSize(ptr_elem_ty)) {
27705 const array_len_including_sentinel =27810 const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);
27706 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));27811 return .{
27707 const elems = try arena.alloc(Value, array_len_including_sentinel);27812 .decl_ref_mut = parent.decl_ref_mut,
27708 @memset(elems, Value.undef);27813 .pointee = .{ .reinterpret = .{
2770927814 .val_ptr = val_ptr,
27710 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);27815 .byte_offset = elem_abi_size * elem_ptr.index,
27816 } },
27817 .ty = parent.ty,
27818 };
27819 }
2771127820
27712 return beginComptimePtrMutationInner(27821 switch (val_ptr.toIntern()) {
27713 sema,27822 .undef => {
27714 block,27823 // An array has been initialized to undefined at comptime and now we
27715 src,27824 // are for the first time setting an element. We must change the representation
27716 elem_ty,27825 // of the array from `undef` to `array`.
27717 &elems[elem_ptr.index],
27718 ptr_elem_ty,
27719 parent.decl_ref_mut,
27720 );
27721 },
27722 .none => switch (val_ptr.tag()) {
27723 .bytes => {
27724 // An array is memory-optimized to store a slice of bytes, but we are about
27725 // to modify an individual field and the representation has to change.
27726 // If we wanted to avoid this, there would need to be special detection
27727 // elsewhere to identify when writing a value to an array element that is stored
27728 // using the `bytes` tag, and handle it without making a call to this function.
27729 const arena = parent.beginArena(sema.mod);27826 const arena = parent.beginArena(sema.mod);
27730 defer parent.finishArena(sema.mod);27827 defer parent.finishArena(sema.mod);
2773127828
27732 const bytes = val_ptr.castTag(.bytes).?.data;27829 const array_len_including_sentinel =
27733 const dest_len = parent.ty.arrayLenIncludingSentinel(mod);27830 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));
27734 // bytes.len may be one greater than dest_len because of the case when27831 const elems = try arena.alloc(Value, array_len_including_sentinel);
27735 // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted.27832 @memset(elems, Value.undef);
27736 assert(bytes.len >= dest_len);
27737 const elems = try arena.alloc(Value, @intCast(usize, dest_len));
27738 for (elems, 0..) |*elem, i| {
27739 elem.* = try mod.intValue(elem_ty, bytes[i]);
27740 }
2774127833
27742 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);27834 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
2774327835
...@@ -27751,392 +27843,383 @@ fn beginComptimePtrMutation(...@@ -27751,392 +27843,383 @@ fn beginComptimePtrMutation(
27751 parent.decl_ref_mut,27843 parent.decl_ref_mut,
27752 );27844 );
27753 },27845 },
27754 .str_lit => {27846 .none => switch (val_ptr.tag()) {
27755 // An array is memory-optimized to store a slice of bytes, but we are about27847 .bytes => {
27756 // to modify an individual field and the representation has to change.27848 // An array is memory-optimized to store a slice of bytes, but we are about
27757 // If we wanted to avoid this, there would need to be special detection27849 // to modify an individual field and the representation has to change.
27758 // elsewhere to identify when writing a value to an array element that is stored27850 // If we wanted to avoid this, there would need to be special detection
27759 // using the `str_lit` tag, and handle it without making a call to this function.27851 // elsewhere to identify when writing a value to an array element that is stored
27760 const arena = parent.beginArena(sema.mod);27852 // using the `bytes` tag, and handle it without making a call to this function.
27761 defer parent.finishArena(sema.mod);27853 const arena = parent.beginArena(sema.mod);
2776227854 defer parent.finishArena(sema.mod);
27763 const str_lit = val_ptr.castTag(.str_lit).?.data;27855
27764 const dest_len = parent.ty.arrayLenIncludingSentinel(mod);27856 const bytes = val_ptr.castTag(.bytes).?.data;
27765 const bytes = sema.mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];27857 const dest_len = parent.ty.arrayLenIncludingSentinel(mod);
27766 const elems = try arena.alloc(Value, @intCast(usize, dest_len));27858 // bytes.len may be one greater than dest_len because of the case when
27767 for (bytes, 0..) |byte, i| {27859 // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted.
27768 elems[i] = try mod.intValue(elem_ty, byte);27860 assert(bytes.len >= dest_len);
27769 }27861 const elems = try arena.alloc(Value, @intCast(usize, dest_len));
27770 if (parent.ty.sentinel(mod)) |sent_val| {27862 for (elems, 0..) |*elem, i| {
27771 assert(elems.len == bytes.len + 1);27863 elem.* = try mod.intValue(elem_ty, bytes[i]);
27772 elems[bytes.len] = sent_val;27864 }
27773 }27865
2777427866 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
27775 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);27867
2777627868 return beginComptimePtrMutationInner(
27777 return beginComptimePtrMutationInner(27869 sema,
27870 block,
27871 src,
27872 elem_ty,
27873 &elems[elem_ptr.index],
27874 ptr_elem_ty,
27875 parent.decl_ref_mut,
27876 );
27877 },
27878 .str_lit => {
27879 // An array is memory-optimized to store a slice of bytes, but we are about
27880 // to modify an individual field and the representation has to change.
27881 // If we wanted to avoid this, there would need to be special detection
27882 // elsewhere to identify when writing a value to an array element that is stored
27883 // using the `str_lit` tag, and handle it without making a call to this function.
27884 const arena = parent.beginArena(sema.mod);
27885 defer parent.finishArena(sema.mod);
27886
27887 const str_lit = val_ptr.castTag(.str_lit).?.data;
27888 const dest_len = parent.ty.arrayLenIncludingSentinel(mod);
27889 const bytes = sema.mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
27890 const elems = try arena.alloc(Value, @intCast(usize, dest_len));
27891 for (bytes, 0..) |byte, i| {
27892 elems[i] = try mod.intValue(elem_ty, byte);
27893 }
27894 if (parent.ty.sentinel(mod)) |sent_val| {
27895 assert(elems.len == bytes.len + 1);
27896 elems[bytes.len] = sent_val;
27897 }
27898
27899 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
27900
27901 return beginComptimePtrMutationInner(
27902 sema,
27903 block,
27904 src,
27905 elem_ty,
27906 &elems[elem_ptr.index],
27907 ptr_elem_ty,
27908 parent.decl_ref_mut,
27909 );
27910 },
27911 .repeated => {
27912 // An array is memory-optimized to store only a single element value, and
27913 // that value is understood to be the same for the entire length of the array.
27914 // However, now we want to modify an individual field and so the
27915 // representation has to change. If we wanted to avoid this, there would
27916 // need to be special detection elsewhere to identify when writing a value to an
27917 // array element that is stored using the `repeated` tag, and handle it
27918 // without making a call to this function.
27919 const arena = parent.beginArena(sema.mod);
27920 defer parent.finishArena(sema.mod);
27921
27922 const repeated_val = try val_ptr.castTag(.repeated).?.data.copy(arena);
27923 const array_len_including_sentinel =
27924 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));
27925 const elems = try arena.alloc(Value, array_len_including_sentinel);
27926 if (elems.len > 0) elems[0] = repeated_val;
27927 for (elems[1..]) |*elem| {
27928 elem.* = try repeated_val.copy(arena);
27929 }
27930
27931 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
27932
27933 return beginComptimePtrMutationInner(
27934 sema,
27935 block,
27936 src,
27937 elem_ty,
27938 &elems[elem_ptr.index],
27939 ptr_elem_ty,
27940 parent.decl_ref_mut,
27941 );
27942 },
27943
27944 .aggregate => return beginComptimePtrMutationInner(
27778 sema,27945 sema,
27779 block,27946 block,
27780 src,27947 src,
27781 elem_ty,27948 elem_ty,
27782 &elems[elem_ptr.index],27949 &val_ptr.castTag(.aggregate).?.data[elem_ptr.index],
27783 ptr_elem_ty,27950 ptr_elem_ty,
27784 parent.decl_ref_mut,27951 parent.decl_ref_mut,
27785 );27952 ),
27953
27954 .the_only_possible_value => {
27955 const duped = try sema.arena.create(Value);
27956 duped.* = Value.initTag(.the_only_possible_value);
27957 return beginComptimePtrMutationInner(
27958 sema,
27959 block,
27960 src,
27961 elem_ty,
27962 duped,
27963 ptr_elem_ty,
27964 parent.decl_ref_mut,
27965 );
27966 },
27967
27968 else => unreachable,
27786 },27969 },
27787 .repeated => {27970 else => unreachable,
27788 // An array is memory-optimized to store only a single element value, and27971 }
27789 // that value is understood to be the same for the entire length of the array.27972 },
27790 // However, now we want to modify an individual field and so the27973 else => {
27791 // representation has to change. If we wanted to avoid this, there would27974 if (elem_ptr.index != 0) {
27792 // need to be special detection elsewhere to identify when writing a value to an27975 // TODO include a "declared here" note for the decl
27793 // array element that is stored using the `repeated` tag, and handle it27976 return sema.fail(block, src, "out of bounds comptime store of index {d}", .{
27794 // without making a call to this function.27977 elem_ptr.index,
27795 const arena = parent.beginArena(sema.mod);27978 });
27796 defer parent.finishArena(sema.mod);27979 }
27980 return beginComptimePtrMutationInner(
27981 sema,
27982 block,
27983 src,
27984 parent.ty,
27985 val_ptr,
27986 ptr_elem_ty,
27987 parent.decl_ref_mut,
27988 );
27989 },
27990 },
27991 .reinterpret => |reinterpret| {
27992 if (!elem_ptr.elem_ty.hasWellDefinedLayout(mod)) {
27993 // Even though the parent value type has well-defined memory layout, our
27994 // pointer type does not.
27995 return ComptimePtrMutationKit{
27996 .decl_ref_mut = parent.decl_ref_mut,
27997 .pointee = .bad_ptr_ty,
27998 .ty = elem_ptr.elem_ty,
27999 };
28000 }
2779728001
27798 const repeated_val = try val_ptr.castTag(.repeated).?.data.copy(arena);28002 const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty);
27799 const array_len_including_sentinel =28003 const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);
27800 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));28004 return ComptimePtrMutationKit{
27801 const elems = try arena.alloc(Value, array_len_including_sentinel);28005 .decl_ref_mut = parent.decl_ref_mut,
27802 if (elems.len > 0) elems[0] = repeated_val;28006 .pointee = .{ .reinterpret = .{
27803 for (elems[1..]) |*elem| {28007 .val_ptr = reinterpret.val_ptr,
27804 elem.* = try repeated_val.copy(arena);28008 .byte_offset = reinterpret.byte_offset + elem_abi_size * elem_ptr.index,
27805 }28009 } },
28010 .ty = parent.ty,
28011 };
28012 },
28013 .bad_decl_ty, .bad_ptr_ty => return parent,
28014 }
28015 },
28016 .field_ptr => {
28017 const field_ptr = ptr_val.castTag(.field_ptr).?.data;
28018 const field_index = @intCast(u32, field_ptr.field_index);
2780628019
27807 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);28020 var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.container_ptr, field_ptr.container_ty);
28021 switch (parent.pointee) {
28022 .direct => |val_ptr| switch (val_ptr.toIntern()) {
28023 .undef => {
28024 // A struct or union has been initialized to undefined at comptime and now we
28025 // are for the first time setting a field. We must change the representation
28026 // of the struct/union from `undef` to `struct`/`union`.
28027 const arena = parent.beginArena(sema.mod);
28028 defer parent.finishArena(sema.mod);
28029
28030 switch (parent.ty.zigTypeTag(mod)) {
28031 .Struct => {
28032 const fields = try arena.alloc(Value, parent.ty.structFieldCount(mod));
28033 @memset(fields, Value.undef);
28034
28035 val_ptr.* = try Value.Tag.aggregate.create(arena, fields);
2780828036
27809 return beginComptimePtrMutationInner(28037 return beginComptimePtrMutationInner(
27810 sema,28038 sema,
27811 block,28039 block,
27812 src,28040 src,
27813 elem_ty,28041 parent.ty.structFieldType(field_index, mod),
27814 &elems[elem_ptr.index],28042 &fields[field_index],
27815 ptr_elem_ty,28043 ptr_elem_ty,
27816 parent.decl_ref_mut,28044 parent.decl_ref_mut,
27817 );28045 );
27818 },28046 },
28047 .Union => {
28048 const payload = try arena.create(Value.Payload.Union);
28049 const tag_ty = parent.ty.unionTagTypeHypothetical(mod);
28050 payload.* = .{ .data = .{
28051 .tag = try mod.enumValueFieldIndex(tag_ty, field_index),
28052 .val = Value.undef,
28053 } };
2781928054
27820 .aggregate => return beginComptimePtrMutationInner(28055 val_ptr.* = Value.initPayload(&payload.base);
27821 sema,
27822 block,
27823 src,
27824 elem_ty,
27825 &val_ptr.castTag(.aggregate).?.data[elem_ptr.index],
27826 ptr_elem_ty,
27827 parent.decl_ref_mut,
27828 ),
2782928056
27830 .the_only_possible_value => {
27831 const duped = try sema.arena.create(Value);
27832 duped.* = Value.initTag(.the_only_possible_value);
27833 return beginComptimePtrMutationInner(28057 return beginComptimePtrMutationInner(
27834 sema,28058 sema,
27835 block,28059 block,
27836 src,28060 src,
27837 elem_ty,28061 parent.ty.structFieldType(field_index, mod),
27838 duped,28062 &payload.data.val,
27839 ptr_elem_ty,28063 ptr_elem_ty,
27840 parent.decl_ref_mut,28064 parent.decl_ref_mut,
27841 );28065 );
27842 },28066 },
2784328067 .Pointer => {
28068 assert(parent.ty.isSlice(mod));
28069 val_ptr.* = try Value.Tag.slice.create(arena, .{
28070 .ptr = Value.undef,
28071 .len = Value.undef,
28072 });
28073
28074 switch (field_index) {
28075 Value.Payload.Slice.ptr_index => return beginComptimePtrMutationInner(
28076 sema,
28077 block,
28078 src,
28079 parent.ty.slicePtrFieldType(mod),
28080 &val_ptr.castTag(.slice).?.data.ptr,
28081 ptr_elem_ty,
28082 parent.decl_ref_mut,
28083 ),
28084 Value.Payload.Slice.len_index => return beginComptimePtrMutationInner(
28085 sema,
28086 block,
28087 src,
28088 Type.usize,
28089 &val_ptr.castTag(.slice).?.data.len,
28090 ptr_elem_ty,
28091 parent.decl_ref_mut,
28092 ),
28093
28094 else => unreachable,
28095 }
28096 },
27844 else => unreachable,28097 else => unreachable,
27845 },28098 }
27846 else => unreachable,28099 },
27847 }28100 .empty_struct => {
27848 },28101 const duped = try sema.arena.create(Value);
27849 else => {28102 duped.* = Value.initTag(.the_only_possible_value);
27850 if (elem_ptr.index != 0) {28103 return beginComptimePtrMutationInner(
27851 // TODO include a "declared here" note for the decl28104 sema,
27852 return sema.fail(block, src, "out of bounds comptime store of index {d}", .{28105 block,
27853 elem_ptr.index,28106 src,
27854 });28107 parent.ty.structFieldType(field_index, mod),
27855 }28108 duped,
27856 return beginComptimePtrMutationInner(28109 ptr_elem_ty,
27857 sema,28110 parent.decl_ref_mut,
27858 block,28111 );
27859 src,28112 },
27860 parent.ty,28113 .none => switch (val_ptr.tag()) {
27861 val_ptr,28114 .aggregate => return beginComptimePtrMutationInner(
27862 ptr_elem_ty,28115 sema,
27863 parent.decl_ref_mut,28116 block,
27864 );28117 src,
27865 },28118 parent.ty.structFieldType(field_index, mod),
27866 },28119 &val_ptr.castTag(.aggregate).?.data[field_index],
27867 .reinterpret => |reinterpret| {28120 ptr_elem_ty,
27868 if (!elem_ptr.elem_ty.hasWellDefinedLayout(mod)) {28121 parent.decl_ref_mut,
27869 // Even though the parent value type has well-defined memory layout, our28122 ),
27870 // pointer type does not.28123 .repeated => {
27871 return ComptimePtrMutationKit{28124 const arena = parent.beginArena(sema.mod);
27872 .decl_ref_mut = parent.decl_ref_mut,28125 defer parent.finishArena(sema.mod);
27873 .pointee = .bad_ptr_ty,
27874 .ty = elem_ptr.elem_ty,
27875 };
27876 }
2787728126
27878 const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty);28127 const elems = try arena.alloc(Value, parent.ty.structFieldCount(mod));
27879 const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);28128 @memset(elems, val_ptr.castTag(.repeated).?.data);
27880 return ComptimePtrMutationKit{28129 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
27881 .decl_ref_mut = parent.decl_ref_mut,
27882 .pointee = .{ .reinterpret = .{
27883 .val_ptr = reinterpret.val_ptr,
27884 .byte_offset = reinterpret.byte_offset + elem_abi_size * elem_ptr.index,
27885 } },
27886 .ty = parent.ty,
27887 };
27888 },
27889 .bad_decl_ty, .bad_ptr_ty => return parent,
27890 }
27891 },
27892 .field_ptr => {
27893 const field_ptr = ptr_val.castTag(.field_ptr).?.data;
27894 const field_index = @intCast(u32, field_ptr.field_index);
27895
27896 var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.container_ptr, field_ptr.container_ty);
27897 switch (parent.pointee) {
27898 .direct => |val_ptr| switch (val_ptr.ip_index) {
27899 .undef => {
27900 // A struct or union has been initialized to undefined at comptime and now we
27901 // are for the first time setting a field. We must change the representation
27902 // of the struct/union from `undef` to `struct`/`union`.
27903 const arena = parent.beginArena(sema.mod);
27904 defer parent.finishArena(sema.mod);
27905
27906 switch (parent.ty.zigTypeTag(mod)) {
27907 .Struct => {
27908 const fields = try arena.alloc(Value, parent.ty.structFieldCount(mod));
27909 @memset(fields, Value.undef);
27910
27911 val_ptr.* = try Value.Tag.aggregate.create(arena, fields);
2791228130
27913 return beginComptimePtrMutationInner(28131 return beginComptimePtrMutationInner(
27914 sema,28132 sema,
27915 block,28133 block,
27916 src,28134 src,
27917 parent.ty.structFieldType(field_index, mod),28135 parent.ty.structFieldType(field_index, mod),
27918 &fields[field_index],28136 &elems[field_index],
27919 ptr_elem_ty,28137 ptr_elem_ty,
27920 parent.decl_ref_mut,28138 parent.decl_ref_mut,
27921 );28139 );
27922 },28140 },
27923 .Union => {28141 .@"union" => {
27924 const payload = try arena.create(Value.Payload.Union);28142 // We need to set the active field of the union.
27925 const tag_ty = parent.ty.unionTagTypeHypothetical(mod);28143 const union_tag_ty = field_ptr.container_ty.unionTagTypeHypothetical(mod);
27926 payload.* = .{ .data = .{
27927 .tag = try mod.enumValueFieldIndex(tag_ty, field_index),
27928 .val = Value.undef,
27929 } };
2793028144
27931 val_ptr.* = Value.initPayload(&payload.base);28145 const payload = &val_ptr.castTag(.@"union").?.data;
28146 payload.tag = try mod.enumValueFieldIndex(union_tag_ty, field_index);
2793228147
27933 return beginComptimePtrMutationInner(28148 return beginComptimePtrMutationInner(
27934 sema,28149 sema,
27935 block,28150 block,
27936 src,28151 src,
27937 parent.ty.structFieldType(field_index, mod),28152 parent.ty.structFieldType(field_index, mod),
27938 &payload.data.val,28153 &payload.val,
27939 ptr_elem_ty,28154 ptr_elem_ty,
27940 parent.decl_ref_mut,28155 parent.decl_ref_mut,
27941 );28156 );
27942 },28157 },
27943 .Pointer => {28158 .slice => switch (field_index) {
27944 assert(parent.ty.isSlice(mod));28159 Value.Payload.Slice.ptr_index => return beginComptimePtrMutationInner(
27945 val_ptr.* = try Value.Tag.slice.create(arena, .{28160 sema,
27946 .ptr = Value.undef,28161 block,
27947 .len = Value.undef,28162 src,
27948 });28163 parent.ty.slicePtrFieldType(mod),
28164 &val_ptr.castTag(.slice).?.data.ptr,
28165 ptr_elem_ty,
28166 parent.decl_ref_mut,
28167 ),
2794928168
27950 switch (field_index) {28169 Value.Payload.Slice.len_index => return beginComptimePtrMutationInner(
27951 Value.Payload.Slice.ptr_index => return beginComptimePtrMutationInner(28170 sema,
27952 sema,28171 block,
27953 block,28172 src,
27954 src,28173 Type.usize,
27955 parent.ty.slicePtrFieldType(mod),28174 &val_ptr.castTag(.slice).?.data.len,
27956 &val_ptr.castTag(.slice).?.data.ptr,28175 ptr_elem_ty,
27957 ptr_elem_ty,28176 parent.decl_ref_mut,
27958 parent.decl_ref_mut,28177 ),
27959 ),
27960 Value.Payload.Slice.len_index => return beginComptimePtrMutationInner(
27961 sema,
27962 block,
27963 src,
27964 Type.usize,
27965 &val_ptr.castTag(.slice).?.data.len,
27966 ptr_elem_ty,
27967 parent.decl_ref_mut,
27968 ),
2796928178
27970 else => unreachable,28179 else => unreachable,
27971 }
27972 },28180 },
27973 else => unreachable,
27974 }
27975 },
27976 .empty_struct => {
27977 const duped = try sema.arena.create(Value);
27978 duped.* = Value.initTag(.the_only_possible_value);
27979 return beginComptimePtrMutationInner(
27980 sema,
27981 block,
27982 src,
27983 parent.ty.structFieldType(field_index, mod),
27984 duped,
27985 ptr_elem_ty,
27986 parent.decl_ref_mut,
27987 );
27988 },
27989 .none => switch (val_ptr.tag()) {
27990 .aggregate => return beginComptimePtrMutationInner(
27991 sema,
27992 block,
27993 src,
27994 parent.ty.structFieldType(field_index, mod),
27995 &val_ptr.castTag(.aggregate).?.data[field_index],
27996 ptr_elem_ty,
27997 parent.decl_ref_mut,
27998 ),
27999 .repeated => {
28000 const arena = parent.beginArena(sema.mod);
28001 defer parent.finishArena(sema.mod);
28002
28003 const elems = try arena.alloc(Value, parent.ty.structFieldCount(mod));
28004 @memset(elems, val_ptr.castTag(.repeated).?.data);
28005 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
28006
28007 return beginComptimePtrMutationInner(
28008 sema,
28009 block,
28010 src,
28011 parent.ty.structFieldType(field_index, mod),
28012 &elems[field_index],
28013 ptr_elem_ty,
28014 parent.decl_ref_mut,
28015 );
28016 },
28017 .@"union" => {
28018 // We need to set the active field of the union.
28019 const union_tag_ty = field_ptr.container_ty.unionTagTypeHypothetical(mod);
28020
28021 const payload = &val_ptr.castTag(.@"union").?.data;
28022 payload.tag = try mod.enumValueFieldIndex(union_tag_ty, field_index);
28023
28024 return beginComptimePtrMutationInner(
28025 sema,
28026 block,
28027 src,
28028 parent.ty.structFieldType(field_index, mod),
28029 &payload.val,
28030 ptr_elem_ty,
28031 parent.decl_ref_mut,
28032 );
28033 },
28034 .slice => switch (field_index) {
28035 Value.Payload.Slice.ptr_index => return beginComptimePtrMutationInner(
28036 sema,
28037 block,
28038 src,
28039 parent.ty.slicePtrFieldType(mod),
28040 &val_ptr.castTag(.slice).?.data.ptr,
28041 ptr_elem_ty,
28042 parent.decl_ref_mut,
28043 ),
28044
28045 Value.Payload.Slice.len_index => return beginComptimePtrMutationInner(
28046 sema,
28047 block,
28048 src,
28049 Type.usize,
28050 &val_ptr.castTag(.slice).?.data.len,
28051 ptr_elem_ty,
28052 parent.decl_ref_mut,
28053 ),
2805428181
28055 else => unreachable,28182 else => unreachable,
28056 },28183 },
28057
28058 else => unreachable,28184 else => unreachable,
28059 },28185 },
28060 else => unreachable,28186 .reinterpret => |reinterpret| {
28061 },28187 const field_offset_u64 = field_ptr.container_ty.structFieldOffset(field_index, mod);
28062 .reinterpret => |reinterpret| {28188 const field_offset = try sema.usizeCast(block, src, field_offset_u64);
28063 const field_offset_u64 = field_ptr.container_ty.structFieldOffset(field_index, mod);
28064 const field_offset = try sema.usizeCast(block, src, field_offset_u64);
28065 return ComptimePtrMutationKit{
28066 .decl_ref_mut = parent.decl_ref_mut,
28067 .pointee = .{ .reinterpret = .{
28068 .val_ptr = reinterpret.val_ptr,
28069 .byte_offset = reinterpret.byte_offset + field_offset,
28070 } },
28071 .ty = parent.ty,
28072 };
28073 },
28074 .bad_decl_ty, .bad_ptr_ty => return parent,
28075 }
28076 },
28077 .eu_payload_ptr => {
28078 const eu_ptr = ptr_val.castTag(.eu_payload_ptr).?.data;
28079 var parent = try sema.beginComptimePtrMutation(block, src, eu_ptr.container_ptr, eu_ptr.container_ty);
28080 switch (parent.pointee) {
28081 .direct => |val_ptr| {
28082 const payload_ty = parent.ty.errorUnionPayload(mod);
28083 if (val_ptr.ip_index == .none and val_ptr.tag() == .eu_payload) {
28084 return ComptimePtrMutationKit{
28085 .decl_ref_mut = parent.decl_ref_mut,
28086 .pointee = .{ .direct = &val_ptr.castTag(.eu_payload).?.data },
28087 .ty = payload_ty,
28088 };
28089 } else {
28090 // An error union has been initialized to undefined at comptime and now we
28091 // are for the first time setting the payload. We must change the
28092 // representation of the error union from `undef` to `opt_payload`.
28093 const arena = parent.beginArena(sema.mod);
28094 defer parent.finishArena(sema.mod);
28095
28096 const payload = try arena.create(Value.Payload.SubValue);
28097 payload.* = .{
28098 .base = .{ .tag = .eu_payload },
28099 .data = Value.undef,
28100 };
28101
28102 val_ptr.* = Value.initPayload(&payload.base);
28103
28104 return ComptimePtrMutationKit{28189 return ComptimePtrMutationKit{
28105 .decl_ref_mut = parent.decl_ref_mut,28190 .decl_ref_mut = parent.decl_ref_mut,
28106 .pointee = .{ .direct = &payload.data },28191 .pointee = .{ .reinterpret = .{
28107 .ty = payload_ty,28192 .val_ptr = reinterpret.val_ptr,
28193 .byte_offset = reinterpret.byte_offset + field_offset,
28194 } },
28195 .ty = parent.ty,
28108 };28196 };
28109 }28197 },
28110 },28198 .bad_decl_ty, .bad_ptr_ty => return parent,
28111 .bad_decl_ty, .bad_ptr_ty => return parent,28199 }
28112 // Even though the parent value type has well-defined memory layout, our28200 },
28113 // pointer type does not.28201 .eu_payload_ptr => {
28114 .reinterpret => return ComptimePtrMutationKit{28202 const eu_ptr = ptr_val.castTag(.eu_payload_ptr).?.data;
28115 .decl_ref_mut = parent.decl_ref_mut,28203 var parent = try sema.beginComptimePtrMutation(block, src, eu_ptr.container_ptr, eu_ptr.container_ty);
28116 .pointee = .bad_ptr_ty,28204 switch (parent.pointee) {
28117 .ty = eu_ptr.container_ty,28205 .direct => |val_ptr| {
28118 },28206 const payload_ty = parent.ty.errorUnionPayload(mod);
28119 }28207 if (val_ptr.ip_index == .none and val_ptr.tag() == .eu_payload) {
28120 },28208 return ComptimePtrMutationKit{
28121 .opt_payload_ptr => {28209 .decl_ref_mut = parent.decl_ref_mut,
28122 const opt_ptr = if (ptr_val.castTag(.opt_payload_ptr)) |some| some.data else {28210 .pointee = .{ .direct = &val_ptr.castTag(.eu_payload).?.data },
28123 return sema.beginComptimePtrMutation(block, src, ptr_val, ptr_elem_ty.optionalChild(mod));28211 .ty = payload_ty,
28124 };28212 };
28125 var parent = try sema.beginComptimePtrMutation(block, src, opt_ptr.container_ptr, opt_ptr.container_ty);28213 } else {
28126 switch (parent.pointee) {28214 // An error union has been initialized to undefined at comptime and now we
28127 .direct => |val_ptr| {
28128 const payload_ty = parent.ty.optionalChild(mod);
28129 switch (val_ptr.ip_index) {
28130 .undef, .null_value => {
28131 // An optional has been initialized to undefined at comptime and now we
28132 // are for the first time setting the payload. We must change the28215 // are for the first time setting the payload. We must change the
28133 // representation of the optional from `undef` to `opt_payload`.28216 // representation of the error union from `undef` to `opt_payload`.
28134 const arena = parent.beginArena(sema.mod);28217 const arena = parent.beginArena(sema.mod);
28135 defer parent.finishArena(sema.mod);28218 defer parent.finishArena(sema.mod);
2813628219
28137 const payload = try arena.create(Value.Payload.SubValue);28220 const payload = try arena.create(Value.Payload.SubValue);
28138 payload.* = .{28221 payload.* = .{
28139 .base = .{ .tag = .opt_payload },28222 .base = .{ .tag = .eu_payload },
28140 .data = Value.undef,28223 .data = Value.undef,
28141 };28224 };
2814228225
...@@ -28147,39 +28230,84 @@ fn beginComptimePtrMutation(...@@ -28147,39 +28230,84 @@ fn beginComptimePtrMutation(
28147 .pointee = .{ .direct = &payload.data },28230 .pointee = .{ .direct = &payload.data },
28148 .ty = payload_ty,28231 .ty = payload_ty,
28149 };28232 };
28150 },28233 }
28151 .none => switch (val_ptr.tag()) {28234 },
28152 .opt_payload => return ComptimePtrMutationKit{28235 .bad_decl_ty, .bad_ptr_ty => return parent,
28153 .decl_ref_mut = parent.decl_ref_mut,28236 // Even though the parent value type has well-defined memory layout, our
28154 .pointee = .{ .direct = &val_ptr.castTag(.opt_payload).?.data },28237 // pointer type does not.
28155 .ty = payload_ty,28238 .reinterpret => return ComptimePtrMutationKit{
28239 .decl_ref_mut = parent.decl_ref_mut,
28240 .pointee = .bad_ptr_ty,
28241 .ty = eu_ptr.container_ty,
28242 },
28243 }
28244 },
28245 .opt_payload_ptr => {
28246 const opt_ptr = if (ptr_val.castTag(.opt_payload_ptr)) |some| some.data else {
28247 return sema.beginComptimePtrMutation(block, src, ptr_val, ptr_elem_ty.optionalChild(mod));
28248 };
28249 var parent = try sema.beginComptimePtrMutation(block, src, opt_ptr.container_ptr, opt_ptr.container_ty);
28250 switch (parent.pointee) {
28251 .direct => |val_ptr| {
28252 const payload_ty = parent.ty.optionalChild(mod);
28253 switch (val_ptr.toIntern()) {
28254 .undef, .null_value => {
28255 // An optional has been initialized to undefined at comptime and now we
28256 // are for the first time setting the payload. We must change the
28257 // representation of the optional from `undef` to `opt_payload`.
28258 const arena = parent.beginArena(sema.mod);
28259 defer parent.finishArena(sema.mod);
28260
28261 const payload = try arena.create(Value.Payload.SubValue);
28262 payload.* = .{
28263 .base = .{ .tag = .opt_payload },
28264 .data = Value.undef,
28265 };
28266
28267 val_ptr.* = Value.initPayload(&payload.base);
28268
28269 return ComptimePtrMutationKit{
28270 .decl_ref_mut = parent.decl_ref_mut,
28271 .pointee = .{ .direct = &payload.data },
28272 .ty = payload_ty,
28273 };
28156 },28274 },
28275 .none => switch (val_ptr.tag()) {
28276 .opt_payload => return ComptimePtrMutationKit{
28277 .decl_ref_mut = parent.decl_ref_mut,
28278 .pointee = .{ .direct = &val_ptr.castTag(.opt_payload).?.data },
28279 .ty = payload_ty,
28280 },
2815728281
28282 else => return ComptimePtrMutationKit{
28283 .decl_ref_mut = parent.decl_ref_mut,
28284 .pointee = .{ .direct = val_ptr },
28285 .ty = payload_ty,
28286 },
28287 },
28158 else => return ComptimePtrMutationKit{28288 else => return ComptimePtrMutationKit{
28159 .decl_ref_mut = parent.decl_ref_mut,28289 .decl_ref_mut = parent.decl_ref_mut,
28160 .pointee = .{ .direct = val_ptr },28290 .pointee = .{ .direct = val_ptr },
28161 .ty = payload_ty,28291 .ty = payload_ty,
28162 },28292 },
28163 },28293 }
28164 else => return ComptimePtrMutationKit{28294 },
28165 .decl_ref_mut = parent.decl_ref_mut,28295 .bad_decl_ty, .bad_ptr_ty => return parent,
28166 .pointee = .{ .direct = val_ptr },28296 // Even though the parent value type has well-defined memory layout, our
28167 .ty = payload_ty,28297 // pointer type does not.
28168 },28298 .reinterpret => return ComptimePtrMutationKit{
28169 }28299 .decl_ref_mut = parent.decl_ref_mut,
28170 },28300 .pointee = .bad_ptr_ty,
28171 .bad_decl_ty, .bad_ptr_ty => return parent,28301 .ty = opt_ptr.container_ty,
28172 // Even though the parent value type has well-defined memory layout, our28302 },
28173 // pointer type does not.28303 }
28174 .reinterpret => return ComptimePtrMutationKit{28304 },
28175 .decl_ref_mut = parent.decl_ref_mut,28305 .decl_ref => unreachable, // isComptimeMutablePtr has been checked already
28176 .pointee = .bad_ptr_ty,28306 else => unreachable,
28177 .ty = opt_ptr.container_ty,28307 },
28178 },28308 else => switch (mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr) {
28179 }28309 else => unreachable,
28180 },28310 },
28181 .decl_ref => unreachable, // isComptimeMutablePtr has been checked already
28182 else => unreachable,
28183 }28311 }
28184}28312}
2818528313
...@@ -28190,13 +28318,13 @@ fn beginComptimePtrMutationInner(...@@ -28190,13 +28318,13 @@ fn beginComptimePtrMutationInner(
28190 decl_ty: Type,28318 decl_ty: Type,
28191 decl_val: *Value,28319 decl_val: *Value,
28192 ptr_elem_ty: Type,28320 ptr_elem_ty: Type,
28193 decl_ref_mut: Value.Payload.DeclRefMut.Data,28321 mut_decl: InternPool.Key.Ptr.Addr.MutDecl,
28194) CompileError!ComptimePtrMutationKit {28322) CompileError!ComptimePtrMutationKit {
28195 const mod = sema.mod;28323 const mod = sema.mod;
28196 const target = mod.getTarget();28324 const target = mod.getTarget();
28197 const coerce_ok = (try sema.coerceInMemoryAllowed(block, ptr_elem_ty, decl_ty, true, target, src, src)) == .ok;28325 const coerce_ok = (try sema.coerceInMemoryAllowed(block, ptr_elem_ty, decl_ty, true, target, src, src)) == .ok;
2819828326
28199 const decl = mod.declPtr(decl_ref_mut.decl_index);28327 const decl = mod.declPtr(mut_decl.decl);
28200 var decl_arena: std.heap.ArenaAllocator = undefined;28328 var decl_arena: std.heap.ArenaAllocator = undefined;
28201 const allocator = decl.value_arena.?.acquire(sema.gpa, &decl_arena);28329 const allocator = decl.value_arena.?.acquire(sema.gpa, &decl_arena);
28202 defer decl.value_arena.?.release(&decl_arena);28330 defer decl.value_arena.?.release(&decl_arena);
...@@ -28204,7 +28332,7 @@ fn beginComptimePtrMutationInner(...@@ -28204,7 +28332,7 @@ fn beginComptimePtrMutationInner(
2820428332
28205 if (coerce_ok) {28333 if (coerce_ok) {
28206 return ComptimePtrMutationKit{28334 return ComptimePtrMutationKit{
28207 .decl_ref_mut = decl_ref_mut,28335 .mut_decl = mut_decl,
28208 .pointee = .{ .direct = decl_val },28336 .pointee = .{ .direct = decl_val },
28209 .ty = decl_ty,28337 .ty = decl_ty,
28210 };28338 };
...@@ -28215,7 +28343,7 @@ fn beginComptimePtrMutationInner(...@@ -28215,7 +28343,7 @@ fn beginComptimePtrMutationInner(
28215 const decl_elem_ty = decl_ty.childType(mod);28343 const decl_elem_ty = decl_ty.childType(mod);
28216 if ((try sema.coerceInMemoryAllowed(block, ptr_elem_ty, decl_elem_ty, true, target, src, src)) == .ok) {28344 if ((try sema.coerceInMemoryAllowed(block, ptr_elem_ty, decl_elem_ty, true, target, src, src)) == .ok) {
28217 return ComptimePtrMutationKit{28345 return ComptimePtrMutationKit{
28218 .decl_ref_mut = decl_ref_mut,28346 .mut_decl = mut_decl,
28219 .pointee = .{ .direct = decl_val },28347 .pointee = .{ .direct = decl_val },
28220 .ty = decl_ty,28348 .ty = decl_ty,
28221 };28349 };
...@@ -28224,20 +28352,20 @@ fn beginComptimePtrMutationInner(...@@ -28224,20 +28352,20 @@ fn beginComptimePtrMutationInner(
2822428352
28225 if (!decl_ty.hasWellDefinedLayout(mod)) {28353 if (!decl_ty.hasWellDefinedLayout(mod)) {
28226 return ComptimePtrMutationKit{28354 return ComptimePtrMutationKit{
28227 .decl_ref_mut = decl_ref_mut,28355 .mut_decl = mut_decl,
28228 .pointee = .{ .bad_decl_ty = {} },28356 .pointee = .bad_decl_ty,
28229 .ty = decl_ty,28357 .ty = decl_ty,
28230 };28358 };
28231 }28359 }
28232 if (!ptr_elem_ty.hasWellDefinedLayout(mod)) {28360 if (!ptr_elem_ty.hasWellDefinedLayout(mod)) {
28233 return ComptimePtrMutationKit{28361 return ComptimePtrMutationKit{
28234 .decl_ref_mut = decl_ref_mut,28362 .mut_decl = mut_decl,
28235 .pointee = .{ .bad_ptr_ty = {} },28363 .pointee = .bad_ptr_ty,
28236 .ty = ptr_elem_ty,28364 .ty = ptr_elem_ty,
28237 };28365 };
28238 }28366 }
28239 return ComptimePtrMutationKit{28367 return ComptimePtrMutationKit{
28240 .decl_ref_mut = decl_ref_mut,28368 .mut_decl = mut_decl,
28241 .pointee = .{ .reinterpret = .{28369 .pointee = .{ .reinterpret = .{
28242 .val_ptr = decl_val,28370 .val_ptr = decl_val,
28243 .byte_offset = 0,28371 .byte_offset = 0,
...@@ -28282,7 +28410,7 @@ fn beginComptimePtrLoad(...@@ -28282,7 +28410,7 @@ fn beginComptimePtrLoad(
28282 const mod = sema.mod;28410 const mod = sema.mod;
28283 const target = mod.getTarget();28411 const target = mod.getTarget();
2828428412
28285 var deref: ComptimePtrLoadKit = switch (mod.intern_pool.indexToKey(ptr_val.ip_index)) {28413 var deref: ComptimePtrLoadKit = switch (mod.intern_pool.indexToKey(ptr_val.toIntern())) {
28286 .ptr => |ptr| switch (ptr.addr) {28414 .ptr => |ptr| switch (ptr.addr) {
28287 .decl, .mut_decl => blk: {28415 .decl, .mut_decl => blk: {
28288 const decl_index = switch (ptr.addr) {28416 const decl_index = switch (ptr.addr) {
...@@ -28319,7 +28447,7 @@ fn beginComptimePtrLoad(...@@ -28319,7 +28447,7 @@ fn beginComptimePtrLoad(
28319 (try sema.coerceInMemoryAllowed(block, container_ty, tv.ty, false, target, src, src)) == .ok or28447 (try sema.coerceInMemoryAllowed(block, container_ty, tv.ty, false, target, src, src)) == .ok or
28320 (try sema.coerceInMemoryAllowed(block, tv.ty, container_ty, false, target, src, src)) == .ok;28448 (try sema.coerceInMemoryAllowed(block, tv.ty, container_ty, false, target, src, src)) == .ok;
28321 if (coerce_in_mem_ok) {28449 if (coerce_in_mem_ok) {
28322 const payload_val = switch (mod.intern_pool.indexToKey(tv.val.ip_index)) {28450 const payload_val = switch (mod.intern_pool.indexToKey(tv.val.toIntern())) {
28323 .error_union => |error_union| switch (error_union.val) {28451 .error_union => |error_union| switch (error_union.val) {
28324 .err_name => |err_name| return sema.fail(block, src, "attempt to unwrap error: {s}", .{mod.intern_pool.stringToSlice(err_name)}),28452 .err_name => |err_name| return sema.fail(block, src, "attempt to unwrap error: {s}", .{mod.intern_pool.stringToSlice(err_name)}),
28325 .payload => |payload| payload,28453 .payload => |payload| payload,
...@@ -28462,7 +28590,7 @@ fn beginComptimePtrLoad(...@@ -28462,7 +28590,7 @@ fn beginComptimePtrLoad(
28462 },28590 },
28463 Value.slice_len_index => TypedValue{28591 Value.slice_len_index => TypedValue{
28464 .ty = Type.usize,28592 .ty = Type.usize,
28465 .val = mod.intern_pool.indexToKey(tv.val.ip_index).ptr.len.toValue(),28593 .val = mod.intern_pool.indexToKey(tv.val.toIntern()).ptr.len.toValue(),
28466 },28594 },
28467 else => unreachable,28595 else => unreachable,
28468 };28596 };
...@@ -28565,9 +28693,9 @@ fn coerceArrayPtrToSlice(...@@ -28565,9 +28693,9 @@ fn coerceArrayPtrToSlice(
28565 const ptr_array_ty = sema.typeOf(inst);28693 const ptr_array_ty = sema.typeOf(inst);
28566 const array_ty = ptr_array_ty.childType(mod);28694 const array_ty = ptr_array_ty.childType(mod);
28567 const slice_val = try mod.intern(.{ .ptr = .{28695 const slice_val = try mod.intern(.{ .ptr = .{
28568 .ty = dest_ty.ip_index,28696 .ty = dest_ty.toIntern(),
28569 .addr = mod.intern_pool.indexToKey(val.ip_index).ptr.addr,28697 .addr = mod.intern_pool.indexToKey(val.toIntern()).ptr.addr,
28570 .len = (try mod.intValue(Type.usize, array_ty.arrayLen(mod))).ip_index,28698 .len = (try mod.intValue(Type.usize, array_ty.arrayLen(mod))).toIntern(),
28571 } });28699 } });
28572 return sema.addConstant(dest_ty, slice_val.toValue());28700 return sema.addConstant(dest_ty, slice_val.toValue());
28573 }28701 }
...@@ -28643,7 +28771,7 @@ fn coerceCompatiblePtrs(...@@ -28643,7 +28771,7 @@ fn coerceCompatiblePtrs(
28643 return sema.addConstant(dest_ty, (try mod.intern_pool.getCoerced(28771 return sema.addConstant(dest_ty, (try mod.intern_pool.getCoerced(
28644 sema.gpa,28772 sema.gpa,
28645 try val.intern(inst_ty, mod),28773 try val.intern(inst_ty, mod),
28646 dest_ty.ip_index,28774 dest_ty.toIntern(),
28647 )).toValue());28775 )).toValue());
28648 }28776 }
28649 try sema.requireRuntimeBlock(block, inst_src, null);28777 try sema.requireRuntimeBlock(block, inst_src, null);
...@@ -28840,7 +28968,7 @@ fn coerceAnonStructToUnion(...@@ -28840,7 +28968,7 @@ fn coerceAnonStructToUnion(
28840 return sema.failWithOwnedErrorMsg(msg);28968 return sema.failWithOwnedErrorMsg(msg);
28841 }28969 }
2884228970
28843 const anon_struct = mod.intern_pool.indexToKey(inst_ty.ip_index).anon_struct_type;28971 const anon_struct = mod.intern_pool.indexToKey(inst_ty.toIntern()).anon_struct_type;
28844 const field_name = mod.intern_pool.stringToSlice(anon_struct.names[0]);28972 const field_name = mod.intern_pool.stringToSlice(anon_struct.names[0]);
28845 const init = try sema.structFieldVal(block, inst_src, inst, field_name, inst_src, inst_ty);28973 const init = try sema.structFieldVal(block, inst_src, inst, field_name, inst_src, inst_ty);
28846 return sema.unionInit(block, init, inst_src, union_ty, union_ty_src, field_name, inst_src);28974 return sema.unionInit(block, init, inst_src, union_ty, union_ty_src, field_name, inst_src);
...@@ -28916,23 +29044,20 @@ fn coerceArrayLike(...@@ -28916,23 +29044,20 @@ fn coerceArrayLike(
28916 return block.addBitCast(dest_ty, inst);29044 return block.addBitCast(dest_ty, inst);
28917 }29045 }
2891829046
28919 const element_vals = try sema.arena.alloc(Value, dest_len);29047 const element_vals = try sema.arena.alloc(InternPool.Index, dest_len);
28920 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len);29048 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len);
28921 var runtime_src: ?LazySrcLoc = null;29049 var runtime_src: ?LazySrcLoc = null;
2892229050
28923 for (element_vals, 0..) |*elem, i| {29051 for (element_vals, element_refs, 0..) |*val, *ref, i| {
28924 const index_ref = try sema.addConstant(29052 const index_ref = try sema.addConstant(Type.usize, try mod.intValue(Type.usize, i));
28925 Type.usize,
28926 try mod.intValue(Type.usize, i),
28927 );
28928 const src = inst_src; // TODO better source location29053 const src = inst_src; // TODO better source location
28929 const elem_src = inst_src; // TODO better source location29054 const elem_src = inst_src; // TODO better source location
28930 const elem_ref = try sema.elemValArray(block, src, inst_src, inst, elem_src, index_ref, true);29055 const elem_ref = try sema.elemValArray(block, src, inst_src, inst, elem_src, index_ref, true);
28931 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);29056 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);
28932 element_refs[i] = coerced;29057 ref.* = coerced;
28933 if (runtime_src == null) {29058 if (runtime_src == null) {
28934 if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| {29059 if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| {
28935 elem.* = elem_val;29060 val.* = try elem_val.intern(dest_elem_ty, mod);
28936 } else {29061 } else {
28937 runtime_src = elem_src;29062 runtime_src = elem_src;
28938 }29063 }
...@@ -28944,10 +29069,10 @@ fn coerceArrayLike(...@@ -28944,10 +29069,10 @@ fn coerceArrayLike(
28944 return block.addAggregateInit(dest_ty, element_refs);29069 return block.addAggregateInit(dest_ty, element_refs);
28945 }29070 }
2894629071
28947 return sema.addConstant(29072 return sema.addConstant(dest_ty, (try mod.intern(.{ .aggregate = .{
28948 dest_ty,29073 .ty = dest_ty.toIntern(),
28949 try Value.Tag.aggregate.create(sema.arena, element_vals),29074 .storage = .{ .elems = element_vals },
28950 );29075 } })).toValue());
28951}29076}
2895229077
28953/// If the lengths match, coerces element-wise.29078/// If the lengths match, coerces element-wise.
...@@ -28978,25 +29103,26 @@ fn coerceTupleToArray(...@@ -28978,25 +29103,26 @@ fn coerceTupleToArray(
28978 }29103 }
2897929104
28980 const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLenIncludingSentinel(mod));29105 const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLenIncludingSentinel(mod));
28981 const element_vals = try sema.arena.alloc(Value, dest_elems);29106 const element_vals = try sema.arena.alloc(InternPool.Index, dest_elems);
28982 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems);29107 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems);
28983 const dest_elem_ty = dest_ty.childType(mod);29108 const dest_elem_ty = dest_ty.childType(mod);
2898429109
28985 var runtime_src: ?LazySrcLoc = null;29110 var runtime_src: ?LazySrcLoc = null;
28986 for (element_vals, 0..) |*elem, i_usize| {29111 for (element_vals, element_refs, 0..) |*val, *ref, i_usize| {
28987 const i = @intCast(u32, i_usize);29112 const i = @intCast(u32, i_usize);
28988 if (i_usize == inst_len) {29113 if (i_usize == inst_len) {
28989 elem.* = dest_ty.sentinel(mod).?;29114 const sentinel_val = dest_ty.sentinel(mod).?;
28990 element_refs[i] = try sema.addConstant(dest_elem_ty, elem.*);29115 val.* = sentinel_val.toIntern();
29116 ref.* = try sema.addConstant(dest_elem_ty, sentinel_val);
28991 break;29117 break;
28992 }29118 }
28993 const elem_src = inst_src; // TODO better source location29119 const elem_src = inst_src; // TODO better source location
28994 const elem_ref = try sema.tupleField(block, inst_src, inst, elem_src, i);29120 const elem_ref = try sema.tupleField(block, inst_src, inst, elem_src, i);
28995 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);29121 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);
28996 element_refs[i] = coerced;29122 ref.* = coerced;
28997 if (runtime_src == null) {29123 if (runtime_src == null) {
28998 if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| {29124 if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| {
28999 elem.* = elem_val;29125 val.* = try elem_val.intern(dest_elem_ty, mod);
29000 } else {29126 } else {
29001 runtime_src = elem_src;29127 runtime_src = elem_src;
29002 }29128 }
...@@ -29008,10 +29134,10 @@ fn coerceTupleToArray(...@@ -29008,10 +29134,10 @@ fn coerceTupleToArray(
29008 return block.addAggregateInit(dest_ty, element_refs);29134 return block.addAggregateInit(dest_ty, element_refs);
29009 }29135 }
2901029136
29011 return sema.addConstant(29137 return sema.addConstant(dest_ty, (try mod.intern(.{ .aggregate = .{
29012 dest_ty,29138 .ty = dest_ty.toIntern(),
29013 try Value.Tag.aggregate.create(sema.arena, element_vals),29139 .storage = .{ .elems = element_vals },
29014 );29140 } })).toValue());
29015}29141}
2901629142
29017/// If the lengths match, coerces element-wise.29143/// If the lengths match, coerces element-wise.
...@@ -29079,7 +29205,7 @@ fn coerceTupleToStruct(...@@ -29079,7 +29205,7 @@ fn coerceTupleToStruct(
29079 @memset(field_refs, .none);29205 @memset(field_refs, .none);
2908029206
29081 const inst_ty = sema.typeOf(inst);29207 const inst_ty = sema.typeOf(inst);
29082 const anon_struct = mod.intern_pool.indexToKey(inst_ty.ip_index).anon_struct_type;29208 const anon_struct = mod.intern_pool.indexToKey(inst_ty.toIntern()).anon_struct_type;
29083 var runtime_src: ?LazySrcLoc = null;29209 var runtime_src: ?LazySrcLoc = null;
29084 for (0..anon_struct.types.len) |field_index_usize| {29210 for (0..anon_struct.types.len) |field_index_usize| {
29085 const field_i = @intCast(u32, field_index_usize);29211 const field_i = @intCast(u32, field_index_usize);
...@@ -29105,8 +29231,7 @@ fn coerceTupleToStruct(...@@ -29105,8 +29231,7 @@ fn coerceTupleToStruct(
29105 }29231 }
29106 if (runtime_src == null) {29232 if (runtime_src == null) {
29107 if (try sema.resolveMaybeUndefVal(coerced)) |field_val| {29233 if (try sema.resolveMaybeUndefVal(coerced)) |field_val| {
29108 assert(field_val.ip_index != .none);29234 field_vals[field_index] = field_val.toIntern();
29109 field_vals[field_index] = field_val.ip_index;
29110 } else {29235 } else {
29111 runtime_src = field_src;29236 runtime_src = field_src;
29112 }29237 }
...@@ -29123,7 +29248,7 @@ fn coerceTupleToStruct(...@@ -29123,7 +29248,7 @@ fn coerceTupleToStruct(
29123 const field_name = fields.keys()[i];29248 const field_name = fields.keys()[i];
29124 const field = fields.values()[i];29249 const field = fields.values()[i];
29125 const field_src = inst_src; // TODO better source location29250 const field_src = inst_src; // TODO better source location
29126 if (field.default_val.ip_index == .unreachable_value) {29251 if (field.default_val.toIntern() == .unreachable_value) {
29127 const template = "missing struct field: {s}";29252 const template = "missing struct field: {s}";
29128 const args = .{field_name};29253 const args = .{field_name};
29129 if (root_msg) |msg| {29254 if (root_msg) |msg| {
...@@ -29134,8 +29259,7 @@ fn coerceTupleToStruct(...@@ -29134,8 +29259,7 @@ fn coerceTupleToStruct(
29134 continue;29259 continue;
29135 }29260 }
29136 if (runtime_src == null) {29261 if (runtime_src == null) {
29137 assert(field.default_val.ip_index != .none);29262 field_vals[i] = field.default_val.toIntern();
29138 field_vals[i] = field.default_val.ip_index;
29139 } else {29263 } else {
29140 field_ref.* = try sema.addConstant(field.ty, field.default_val);29264 field_ref.* = try sema.addConstant(field.ty, field.default_val);
29141 }29265 }
...@@ -29152,9 +29276,8 @@ fn coerceTupleToStruct(...@@ -29152,9 +29276,8 @@ fn coerceTupleToStruct(
29152 return block.addAggregateInit(struct_ty, field_refs);29276 return block.addAggregateInit(struct_ty, field_refs);
29153 }29277 }
2915429278
29155 assert(struct_ty.ip_index != .none);
29156 const struct_val = try mod.intern(.{ .aggregate = .{29279 const struct_val = try mod.intern(.{ .aggregate = .{
29157 .ty = struct_ty.ip_index,29280 .ty = struct_ty.toIntern(),
29158 .storage = .{ .elems = field_vals },29281 .storage = .{ .elems = field_vals },
29159 } });29282 } });
29160 errdefer mod.intern_pool.remove(struct_val);29283 errdefer mod.intern_pool.remove(struct_val);
...@@ -29170,13 +29293,13 @@ fn coerceTupleToTuple(...@@ -29170,13 +29293,13 @@ fn coerceTupleToTuple(
29170 inst_src: LazySrcLoc,29293 inst_src: LazySrcLoc,
29171) !Air.Inst.Ref {29294) !Air.Inst.Ref {
29172 const mod = sema.mod;29295 const mod = sema.mod;
29173 const dest_tuple = mod.intern_pool.indexToKey(tuple_ty.ip_index).anon_struct_type;29296 const dest_tuple = mod.intern_pool.indexToKey(tuple_ty.toIntern()).anon_struct_type;
29174 const field_vals = try sema.arena.alloc(InternPool.Index, dest_tuple.types.len);29297 const field_vals = try sema.arena.alloc(InternPool.Index, dest_tuple.types.len);
29175 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);29298 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);
29176 @memset(field_refs, .none);29299 @memset(field_refs, .none);
2917729300
29178 const inst_ty = sema.typeOf(inst);29301 const inst_ty = sema.typeOf(inst);
29179 const src_tuple = mod.intern_pool.indexToKey(inst_ty.ip_index).anon_struct_type;29302 const src_tuple = mod.intern_pool.indexToKey(inst_ty.toIntern()).anon_struct_type;
29180 if (src_tuple.types.len > dest_tuple.types.len) return error.NotCoercible;29303 if (src_tuple.types.len > dest_tuple.types.len) return error.NotCoercible;
2918129304
29182 var runtime_src: ?LazySrcLoc = null;29305 var runtime_src: ?LazySrcLoc = null;
...@@ -29209,7 +29332,7 @@ fn coerceTupleToTuple(...@@ -29209,7 +29332,7 @@ fn coerceTupleToTuple(
29209 }29332 }
29210 if (runtime_src == null) {29333 if (runtime_src == null) {
29211 if (try sema.resolveMaybeUndefVal(coerced)) |field_val| {29334 if (try sema.resolveMaybeUndefVal(coerced)) |field_val| {
29212 field_vals[field_index] = field_val.ip_index;29335 field_vals[field_index] = field_val.toIntern();
29213 } else {29336 } else {
29214 runtime_src = field_src;29337 runtime_src = field_src;
29215 }29338 }
...@@ -29269,7 +29392,7 @@ fn coerceTupleToTuple(...@@ -29269,7 +29392,7 @@ fn coerceTupleToTuple(
29269 return sema.addConstant(29392 return sema.addConstant(
29270 tuple_ty,29393 tuple_ty,
29271 (try mod.intern(.{ .aggregate = .{29394 (try mod.intern(.{ .aggregate = .{
29272 .ty = tuple_ty.ip_index,29395 .ty = tuple_ty.toIntern(),
29273 .storage = .{ .elems = field_vals },29396 .storage = .{ .elems = field_vals },
29274 } })).toValue(),29397 } })).toValue(),
29275 );29398 );
...@@ -29349,7 +29472,7 @@ fn refValue(sema: *Sema, block: *Block, ty: Type, val: Value) !Value {...@@ -29349,7 +29472,7 @@ fn refValue(sema: *Sema, block: *Block, ty: Type, val: Value) !Value {
29349 try sema.maybeQueueFuncBodyAnalysis(decl);29472 try sema.maybeQueueFuncBodyAnalysis(decl);
29350 try mod.declareDeclDependency(sema.owner_decl_index, decl);29473 try mod.declareDeclDependency(sema.owner_decl_index, decl);
29351 const result = try mod.intern(.{ .ptr = .{29474 const result = try mod.intern(.{ .ptr = .{
29352 .ty = (try mod.singleConstPtrType(ty)).ip_index,29475 .ty = (try mod.singleConstPtrType(ty)).toIntern(),
29353 .addr = .{ .decl = decl },29476 .addr = .{ .decl = decl },
29354 } });29477 } });
29355 return result.toValue();29478 return result.toValue();
...@@ -29360,8 +29483,8 @@ fn optRefValue(sema: *Sema, block: *Block, ty: Type, opt_val: ?Value) !Value {...@@ -29360,8 +29483,8 @@ fn optRefValue(sema: *Sema, block: *Block, ty: Type, opt_val: ?Value) !Value {
29360 const val = opt_val orelse return Value.null;29483 const val = opt_val orelse return Value.null;
29361 const ptr_val = try sema.refValue(block, ty, val);29484 const ptr_val = try sema.refValue(block, ty, val);
29362 const result = try mod.intern(.{ .opt = .{29485 const result = try mod.intern(.{ .opt = .{
29363 .ty = (try mod.optionalType((try mod.singleConstPtrType(ty)).ip_index)).ip_index,29486 .ty = (try mod.optionalType((try mod.singleConstPtrType(ty)).toIntern())).toIntern(),
29364 .val = ptr_val.ip_index,29487 .val = ptr_val.toIntern(),
29365 } });29488 } });
29366 return result.toValue();29489 return result.toValue();
29367}29490}
...@@ -29382,7 +29505,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo...@@ -29382,7 +29505,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo
29382 const decl = mod.declPtr(decl_index);29505 const decl = mod.declPtr(decl_index);
29383 const decl_tv = try decl.typedValue();29506 const decl_tv = try decl.typedValue();
29384 const ptr_ty = try mod.ptrType(.{29507 const ptr_ty = try mod.ptrType(.{
29385 .elem_type = decl_tv.ty.ip_index,29508 .elem_type = decl_tv.ty.toIntern(),
29386 .alignment = InternPool.Alignment.fromByteUnits(decl.@"align"),29509 .alignment = InternPool.Alignment.fromByteUnits(decl.@"align"),
29387 .is_const = if (decl.getVariable(mod)) |variable| variable.is_const else false,29510 .is_const = if (decl.getVariable(mod)) |variable| variable.is_const else false,
29388 .address_space = decl.@"addrspace",29511 .address_space = decl.@"addrspace",
...@@ -29391,7 +29514,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo...@@ -29391,7 +29514,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo
29391 try sema.maybeQueueFuncBodyAnalysis(decl_index);29514 try sema.maybeQueueFuncBodyAnalysis(decl_index);
29392 }29515 }
29393 return sema.addConstant(ptr_ty, (try mod.intern(.{ .ptr = .{29516 return sema.addConstant(ptr_ty, (try mod.intern(.{ .ptr = .{
29394 .ty = ptr_ty.ip_index,29517 .ty = ptr_ty.toIntern(),
29395 .addr = .{ .decl = decl_index },29518 .addr = .{ .decl = decl_index },
29396 } })).toValue());29519 } })).toValue());
29397}29520}
...@@ -29415,13 +29538,10 @@ fn analyzeRef(...@@ -29415,13 +29538,10 @@ fn analyzeRef(
29415 const operand_ty = sema.typeOf(operand);29538 const operand_ty = sema.typeOf(operand);
2941629539
29417 if (try sema.resolveMaybeUndefVal(operand)) |val| {29540 if (try sema.resolveMaybeUndefVal(operand)) |val| {
29418 switch (val.ip_index) {29541 switch (sema.mod.intern_pool.indexToKey(val.toIntern())) {
29419 .none => {},29542 .extern_func => |extern_func| return sema.analyzeDeclRef(extern_func.decl),
29420 else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) {29543 .func => |func| return sema.analyzeDeclRef(sema.mod.funcPtr(func.index).owner_decl),
29421 .extern_func => |extern_func| return sema.analyzeDeclRef(extern_func.decl),29544 else => {},
29422 .func => |func| return sema.analyzeDeclRef(sema.mod.funcPtr(func.index).owner_decl),
29423 else => {},
29424 },
29425 }29545 }
29426 var anon_decl = try block.startAnonDecl();29546 var anon_decl = try block.startAnonDecl();
29427 defer anon_decl.deinit();29547 defer anon_decl.deinit();
...@@ -29617,9 +29737,9 @@ fn analyzeIsNonErrComptimeOnly(...@@ -29617,9 +29737,9 @@ fn analyzeIsNonErrComptimeOnly(
29617 // exception if the error union error set is known to be empty,29737 // exception if the error union error set is known to be empty,
29618 // we allow the comparison but always make it comptime-known.29738 // we allow the comparison but always make it comptime-known.
29619 const set_ty = operand_ty.errorUnionSet(mod);29739 const set_ty = operand_ty.errorUnionSet(mod);
29620 switch (set_ty.ip_index) {29740 switch (set_ty.toIntern()) {
29621 .anyerror_type => {},29741 .anyerror_type => {},
29622 else => switch (mod.intern_pool.indexToKey(set_ty.ip_index)) {29742 else => switch (mod.intern_pool.indexToKey(set_ty.toIntern())) {
29623 .error_set_type => |error_set_type| {29743 .error_set_type => |error_set_type| {
29624 if (error_set_type.names.len == 0) return Air.Inst.Ref.bool_true;29744 if (error_set_type.names.len == 0) return Air.Inst.Ref.bool_true;
29625 },29745 },
...@@ -30027,7 +30147,7 @@ fn analyzeSlice(...@@ -30027,7 +30147,7 @@ fn analyzeSlice(
30027 return sema.addConstant(return_ty, (try mod.intern_pool.getCoerced(30147 return sema.addConstant(return_ty, (try mod.intern_pool.getCoerced(
30028 sema.gpa,30148 sema.gpa,
30029 try new_ptr_val.intern(new_ptr_ty, mod),30149 try new_ptr_val.intern(new_ptr_ty, mod),
30030 return_ty.ip_index,30150 return_ty.toIntern(),
30031 )).toValue());30151 )).toValue());
30032 }30152 }
3003330153
...@@ -30546,8 +30666,8 @@ fn wrapOptional(...@@ -30546,8 +30666,8 @@ fn wrapOptional(
30546) !Air.Inst.Ref {30666) !Air.Inst.Ref {
30547 if (try sema.resolveMaybeUndefVal(inst)) |val| {30667 if (try sema.resolveMaybeUndefVal(inst)) |val| {
30548 return sema.addConstant(dest_ty, (try sema.mod.intern(.{ .opt = .{30668 return sema.addConstant(dest_ty, (try sema.mod.intern(.{ .opt = .{
30549 .ty = dest_ty.ip_index,30669 .ty = dest_ty.toIntern(),
30550 .val = val.ip_index,30670 .val = val.toIntern(),
30551 } })).toValue());30671 } })).toValue());
30552 }30672 }
3055330673
...@@ -30567,8 +30687,8 @@ fn wrapErrorUnionPayload(...@@ -30567,8 +30687,8 @@ fn wrapErrorUnionPayload(
30567 const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false });30687 const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false });
30568 if (try sema.resolveMaybeUndefVal(coerced)) |val| {30688 if (try sema.resolveMaybeUndefVal(coerced)) |val| {
30569 return sema.addConstant(dest_ty, (try mod.intern(.{ .error_union = .{30689 return sema.addConstant(dest_ty, (try mod.intern(.{ .error_union = .{
30570 .ty = dest_ty.ip_index,30690 .ty = dest_ty.toIntern(),
30571 .val = .{ .payload = val.ip_index },30691 .val = .{ .payload = val.toIntern() },
30572 } })).toValue());30692 } })).toValue());
30573 }30693 }
30574 try sema.requireRuntimeBlock(block, inst_src, null);30694 try sema.requireRuntimeBlock(block, inst_src, null);
...@@ -30588,17 +30708,17 @@ fn wrapErrorUnionSet(...@@ -30588,17 +30708,17 @@ fn wrapErrorUnionSet(
30588 const inst_ty = sema.typeOf(inst);30708 const inst_ty = sema.typeOf(inst);
30589 const dest_err_set_ty = dest_ty.errorUnionSet(mod);30709 const dest_err_set_ty = dest_ty.errorUnionSet(mod);
30590 if (try sema.resolveMaybeUndefVal(inst)) |val| {30710 if (try sema.resolveMaybeUndefVal(inst)) |val| {
30591 switch (dest_err_set_ty.ip_index) {30711 switch (dest_err_set_ty.toIntern()) {
30592 .anyerror_type => {},30712 .anyerror_type => {},
30593 else => switch (ip.indexToKey(dest_err_set_ty.ip_index)) {30713 else => switch (ip.indexToKey(dest_err_set_ty.toIntern())) {
30594 .error_set_type => |error_set_type| ok: {30714 .error_set_type => |error_set_type| ok: {
30595 const expected_name = mod.intern_pool.indexToKey(val.ip_index).err.name;30715 const expected_name = mod.intern_pool.indexToKey(val.toIntern()).err.name;
30596 if (error_set_type.nameIndex(ip, expected_name) != null) break :ok;30716 if (error_set_type.nameIndex(ip, expected_name) != null) break :ok;
30597 return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty);30717 return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty);
30598 },30718 },
30599 .inferred_error_set_type => |ies_index| ok: {30719 .inferred_error_set_type => |ies_index| ok: {
30600 const ies = mod.inferredErrorSetPtr(ies_index);30720 const ies = mod.inferredErrorSetPtr(ies_index);
30601 const expected_name = mod.intern_pool.indexToKey(val.ip_index).err.name;30721 const expected_name = mod.intern_pool.indexToKey(val.toIntern()).err.name;
3060230722
30603 // We carefully do this in an order that avoids unnecessarily30723 // We carefully do this in an order that avoids unnecessarily
30604 // resolving the destination error set type.30724 // resolving the destination error set type.
...@@ -31252,34 +31372,31 @@ pub fn resolveFnTypes(sema: *Sema, fn_info: InternPool.Key.FuncType) CompileErro...@@ -31252,34 +31372,31 @@ pub fn resolveFnTypes(sema: *Sema, fn_info: InternPool.Key.FuncType) CompileErro
31252/// Make it so that calling hash() and eql() on `val` will not assert due31372/// Make it so that calling hash() and eql() on `val` will not assert due
31253/// to a type not having its layout resolved.31373/// to a type not having its layout resolved.
31254fn resolveLazyValue(sema: *Sema, val: Value) CompileError!void {31374fn resolveLazyValue(sema: *Sema, val: Value) CompileError!void {
31255 switch (val.ip_index) {31375 switch (sema.mod.intern_pool.indexToKey(val.toIntern())) {
31256 .none => {},31376 .int => |int| switch (int.storage) {
31257 else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) {31377 .u64, .i64, .big_int => {},
31258 .int => |int| switch (int.storage) {31378 .lazy_align, .lazy_size => |lazy_ty| try sema.resolveTypeLayout(lazy_ty.toType()),
31259 .u64, .i64, .big_int => {},31379 },
31260 .lazy_align, .lazy_size => |lazy_ty| try sema.resolveTypeLayout(lazy_ty.toType()),31380 .ptr => |ptr| {
31261 },31381 switch (ptr.addr) {
31262 .ptr => |ptr| {31382 .decl, .mut_decl => {},
31263 switch (ptr.addr) {31383 .int => |int| try sema.resolveLazyValue(int.toValue()),
31264 .decl, .mut_decl => {},31384 .eu_payload, .opt_payload => |base| try sema.resolveLazyValue(base.toValue()),
31265 .int => |int| try sema.resolveLazyValue(int.toValue()),31385 .comptime_field => |comptime_field| try sema.resolveLazyValue(comptime_field.toValue()),
31266 .eu_payload, .opt_payload => |base| try sema.resolveLazyValue(base.toValue()),31386 .elem, .field => |base_index| try sema.resolveLazyValue(base_index.base.toValue()),
31267 .comptime_field => |comptime_field| try sema.resolveLazyValue(comptime_field.toValue()),31387 }
31268 .elem, .field => |base_index| try sema.resolveLazyValue(base_index.base.toValue()),31388 if (ptr.len != .none) try sema.resolveLazyValue(ptr.len.toValue());
31269 }31389 },
31270 if (ptr.len != .none) try sema.resolveLazyValue(ptr.len.toValue());31390 .aggregate => |aggregate| switch (aggregate.storage) {
31271 },31391 .bytes => {},
31272 .aggregate => |aggregate| switch (aggregate.storage) {31392 .elems => |elems| for (elems) |elem| try sema.resolveLazyValue(elem.toValue()),
31273 .bytes => {},31393 .repeated_elem => |elem| try sema.resolveLazyValue(elem.toValue()),
31274 .elems => |elems| for (elems) |elem| try sema.resolveLazyValue(elem.toValue()),
31275 .repeated_elem => |elem| try sema.resolveLazyValue(elem.toValue()),
31276 },
31277 .un => |un| {
31278 try sema.resolveLazyValue(un.tag.toValue());
31279 try sema.resolveLazyValue(un.val.toValue());
31280 },
31281 else => {},
31282 },31394 },
31395 .un => |un| {
31396 try sema.resolveLazyValue(un.tag.toValue());
31397 try sema.resolveLazyValue(un.val.toValue());
31398 },
31399 else => {},
31283 }31400 }
31284}31401}
3128531402
...@@ -31617,9 +31734,9 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -31617,9 +31734,9 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
31617pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {31734pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
31618 const mod = sema.mod;31735 const mod = sema.mod;
3161931736
31620 return switch (ty.ip_index) {31737 return switch (ty.toIntern()) {
31621 .empty_struct_type => false,31738 .empty_struct_type => false,
31622 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {31739 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
31623 .int_type => false,31740 .int_type => false,
31624 .ptr_type => |ptr_type| {31741 .ptr_type => |ptr_type| {
31625 const child_ty = ptr_type.elem_type.toType();31742 const child_ty = ptr_type.elem_type.toType();
...@@ -31776,7 +31893,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {...@@ -31776,7 +31893,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {
31776 const child_ty = try sema.resolveTypeFields(ty.childType(mod));31893 const child_ty = try sema.resolveTypeFields(ty.childType(mod));
31777 return sema.resolveTypeFully(child_ty);31894 return sema.resolveTypeFully(child_ty);
31778 },31895 },
31779 .Struct => switch (mod.intern_pool.indexToKey(ty.ip_index)) {31896 .Struct => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
31780 .struct_type => return sema.resolveStructFully(ty),31897 .struct_type => return sema.resolveStructFully(ty),
31781 .anon_struct_type => |tuple| {31898 .anon_struct_type => |tuple| {
31782 for (tuple.types) |field_ty| {31899 for (tuple.types) |field_ty| {
...@@ -31869,7 +31986,7 @@ fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void {...@@ -31869,7 +31986,7 @@ fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void {
31869pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {31986pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {
31870 const mod = sema.mod;31987 const mod = sema.mod;
3187131988
31872 switch (ty.ip_index) {31989 switch (ty.toIntern()) {
31873 .var_args_param_type => unreachable,31990 .var_args_param_type => unreachable,
3187431991
31875 .none => unreachable,31992 .none => unreachable,
...@@ -31960,7 +32077,7 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {...@@ -31960,7 +32077,7 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {
31960 .call_modifier_type => return sema.getBuiltinType("CallModifier"),32077 .call_modifier_type => return sema.getBuiltinType("CallModifier"),
31961 .prefetch_options_type => return sema.getBuiltinType("PrefetchOptions"),32078 .prefetch_options_type => return sema.getBuiltinType("PrefetchOptions"),
3196232079
31963 _ => switch (mod.intern_pool.indexToKey(ty.ip_index)) {32080 _ => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
31964 .struct_type => |struct_type| {32081 .struct_type => |struct_type| {
31965 const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return ty;32082 const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return ty;
31966 try sema.resolveTypeFieldsStruct(ty, struct_obj);32083 try sema.resolveTypeFieldsStruct(ty, struct_obj);
...@@ -32605,7 +32722,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -32605,7 +32722,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
32605 } else {32722 } else {
32606 // The provided type is the enum tag type.32723 // The provided type is the enum tag type.
32607 union_obj.tag_ty = provided_ty;32724 union_obj.tag_ty = provided_ty;
32608 const enum_type = switch (mod.intern_pool.indexToKey(union_obj.tag_ty.ip_index)) {32725 const enum_type = switch (mod.intern_pool.indexToKey(union_obj.tag_ty.toIntern())) {
32609 .enum_type => |x| x,32726 .enum_type => |x| x,
32610 else => return sema.fail(&block_scope, tag_ty_src, "expected enum tag type, found '{}'", .{union_obj.tag_ty.fmt(mod)}),32727 else => return sema.fail(&block_scope, tag_ty_src, "expected enum tag type, found '{}'", .{union_obj.tag_ty.fmt(mod)}),
32611 };32728 };
...@@ -32698,7 +32815,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {...@@ -32698,7 +32815,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3269832815
32699 break :blk val;32816 break :blk val;
32700 };32817 };
32701 enum_field_vals[field_i] = copied_val.ip_index;32818 enum_field_vals[field_i] = copied_val.toIntern();
32702 const gop = enum_field_vals_map.getOrPutAssumeCapacityContext(copied_val, .{32819 const gop = enum_field_vals_map.getOrPutAssumeCapacityContext(copied_val, .{
32703 .ty = int_tag_ty,32820 .ty = int_tag_ty,
32704 .mod = mod,32821 .mod = mod,
...@@ -32960,7 +33077,7 @@ fn generateUnionTagTypeSimple(...@@ -32960,7 +33077,7 @@ fn generateUnionTagTypeSimple(
32960 .tag_ty = if (enum_field_names.len == 0)33077 .tag_ty = if (enum_field_names.len == 0)
32961 .noreturn_type33078 .noreturn_type
32962 else33079 else
32963 (try mod.smallestUnsignedInt(enum_field_names.len - 1)).ip_index,33080 (try mod.smallestUnsignedInt(enum_field_names.len - 1)).toIntern(),
32964 .names = enum_field_names,33081 .names = enum_field_names,
32965 .values = &.{},33082 .values = &.{},
32966 .tag_mode = .auto,33083 .tag_mode = .auto,
...@@ -33053,9 +33170,9 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {...@@ -33053,9 +33170,9 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
33053/// TODO assert the return value matches `ty.onePossibleValue`33170/// TODO assert the return value matches `ty.onePossibleValue`
33054pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {33171pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
33055 const mod = sema.mod;33172 const mod = sema.mod;
33056 return switch (ty.ip_index) {33173 return switch (ty.toIntern()) {
33057 .empty_struct_type => Value.empty_struct,33174 .empty_struct_type => Value.empty_struct,
33058 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {33175 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
33059 .int_type => |int_type| {33176 .int_type => |int_type| {
33060 if (int_type.bits == 0) {33177 if (int_type.bits == 0) {
33061 return try mod.intValue(ty, 0);33178 return try mod.intValue(ty, 0);
...@@ -33074,13 +33191,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -33074,13 +33191,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3307433191
33075 inline .array_type, .vector_type => |seq_type| {33192 inline .array_type, .vector_type => |seq_type| {
33076 if (seq_type.len == 0) return (try mod.intern(.{ .aggregate = .{33193 if (seq_type.len == 0) return (try mod.intern(.{ .aggregate = .{
33077 .ty = ty.ip_index,33194 .ty = ty.toIntern(),
33078 .storage = .{ .elems = &.{} },33195 .storage = .{ .elems = &.{} },
33079 } })).toValue();33196 } })).toValue();
33080 if (try sema.typeHasOnePossibleValue(seq_type.child.toType())) |opv| {33197 if (try sema.typeHasOnePossibleValue(seq_type.child.toType())) |opv| {
33081 return (try mod.intern(.{ .aggregate = .{33198 return (try mod.intern(.{ .aggregate = .{
33082 .ty = ty.ip_index,33199 .ty = ty.toIntern(),
33083 .storage = .{ .repeated_elem = opv.ip_index },33200 .storage = .{ .repeated_elem = opv.toIntern() },
33084 } })).toValue();33201 } })).toValue();
33085 }33202 }
33086 return null;33203 return null;
...@@ -33169,7 +33286,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -33169,7 +33286,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
33169 // This TODO is repeated in the redundant implementation of33286 // This TODO is repeated in the redundant implementation of
33170 // one-possible-value in type.zig.33287 // one-possible-value in type.zig.
33171 const empty = try mod.intern(.{ .aggregate = .{33288 const empty = try mod.intern(.{ .aggregate = .{
33172 .ty = ty.ip_index,33289 .ty = ty.toIntern(),
33173 .storage = .{ .elems = &.{} },33290 .storage = .{ .elems = &.{} },
33174 } });33291 } });
33175 return empty.toValue();33292 return empty.toValue();
...@@ -33182,7 +33299,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -33182,7 +33299,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
33182 // In this case the struct has all comptime-known fields and33299 // In this case the struct has all comptime-known fields and
33183 // therefore has one possible value.33300 // therefore has one possible value.
33184 return (try mod.intern(.{ .aggregate = .{33301 return (try mod.intern(.{ .aggregate = .{
33185 .ty = ty.ip_index,33302 .ty = ty.toIntern(),
33186 .storage = .{ .elems = tuple.values },33303 .storage = .{ .elems = tuple.values },
33187 } })).toValue();33304 } })).toValue();
33188 },33305 },
...@@ -33208,9 +33325,9 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -33208,9 +33325,9 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
33208 const val_val = (try sema.typeHasOnePossibleValue(only_field.ty)) orelse33325 const val_val = (try sema.typeHasOnePossibleValue(only_field.ty)) orelse
33209 return null;33326 return null;
33210 const only = try mod.intern(.{ .un = .{33327 const only = try mod.intern(.{ .un = .{
33211 .ty = resolved_ty.ip_index,33328 .ty = resolved_ty.toIntern(),
33212 .tag = tag_val.ip_index,33329 .tag = tag_val.toIntern(),
33213 .val = val_val.ip_index,33330 .val = val_val.toIntern(),
33214 } });33331 } });
33215 return only.toValue();33332 return only.toValue();
33216 },33333 },
...@@ -33221,8 +33338,8 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -33221,8 +33338,8 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3322133338
33222 if (try sema.typeHasOnePossibleValue(enum_type.tag_ty.toType())) |int_opv| {33339 if (try sema.typeHasOnePossibleValue(enum_type.tag_ty.toType())) |int_opv| {
33223 const only = try mod.intern(.{ .enum_tag = .{33340 const only = try mod.intern(.{ .enum_tag = .{
33224 .ty = ty.ip_index,33341 .ty = ty.toIntern(),
33225 .int = int_opv.ip_index,33342 .int = int_opv.toIntern(),
33226 } });33343 } });
33227 return only.toValue();33344 return only.toValue();
33228 }33345 }
...@@ -33234,7 +33351,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -33234,7 +33351,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
33234 1 => {33351 1 => {
33235 if (enum_type.values.len == 0) {33352 if (enum_type.values.len == 0) {
33236 const only = try mod.intern(.{ .enum_tag = .{33353 const only = try mod.intern(.{ .enum_tag = .{
33237 .ty = ty.ip_index,33354 .ty = ty.toIntern(),
33238 .int = try mod.intern(.{ .int = .{33355 .int = try mod.intern(.{ .int = .{
33239 .ty = enum_type.tag_ty,33356 .ty = enum_type.tag_ty,
33240 .storage = .{ .u64 = 0 },33357 .storage = .{ .u64 = 0 },
...@@ -33285,21 +33402,13 @@ pub fn getTmpAir(sema: Sema) Air {...@@ -33285,21 +33402,13 @@ pub fn getTmpAir(sema: Sema) Air {
33285}33402}
3328633403
33287pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {33404pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
33288 if (ty.ip_index != .none) {33405 if (@enumToInt(ty.toIntern()) < Air.ref_start_index)
33289 if (@enumToInt(ty.ip_index) < Air.ref_start_index)33406 return @intToEnum(Air.Inst.Ref, @enumToInt(ty.toIntern()));
33290 return @intToEnum(Air.Inst.Ref, @enumToInt(ty.ip_index));33407 try sema.air_instructions.append(sema.gpa, .{
33291 try sema.air_instructions.append(sema.gpa, .{33408 .tag = .interned,
33292 .tag = .interned,33409 .data = .{ .interned = ty.toIntern() },
33293 .data = .{ .interned = ty.ip_index },33410 });
33294 });33411 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
33295 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
33296 } else {
33297 try sema.air_instructions.append(sema.gpa, .{
33298 .tag = .const_ty,
33299 .data = .{ .ty = ty },
33300 });
33301 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
33302 }
33303}33412}
3330433413
33305fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref {33414fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref {
...@@ -33313,12 +33422,12 @@ fn addConstUndef(sema: *Sema, ty: Type) CompileError!Air.Inst.Ref {...@@ -33313,12 +33422,12 @@ fn addConstUndef(sema: *Sema, ty: Type) CompileError!Air.Inst.Ref {
3331333422
33314pub fn addConstant(sema: *Sema, ty: Type, val: Value) SemaError!Air.Inst.Ref {33423pub fn addConstant(sema: *Sema, ty: Type, val: Value) SemaError!Air.Inst.Ref {
33315 const gpa = sema.gpa;33424 const gpa = sema.gpa;
33316 if (val.ip_index != .none and val.ip_index != .null_value) {33425 if (val.ip_index != .none) {
33317 if (@enumToInt(val.ip_index) < Air.ref_start_index)33426 if (@enumToInt(val.toIntern()) < Air.ref_start_index)
33318 return @intToEnum(Air.Inst.Ref, @enumToInt(val.ip_index));33427 return @intToEnum(Air.Inst.Ref, @enumToInt(val.toIntern()));
33319 try sema.air_instructions.append(gpa, .{33428 try sema.air_instructions.append(gpa, .{
33320 .tag = .interned,33429 .tag = .interned,
33321 .data = .{ .interned = val.ip_index },33430 .data = .{ .interned = val.toIntern() },
33322 });33431 });
33323 const result = Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));33432 const result = Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
33324 // This assertion can be removed when the `ty` parameter is removed from33433 // This assertion can be removed when the `ty` parameter is removed from
...@@ -33417,7 +33526,7 @@ fn analyzeComptimeAlloc(...@@ -33417,7 +33526,7 @@ fn analyzeComptimeAlloc(
3341733526
33418 try sema.mod.declareDeclDependency(sema.owner_decl_index, decl_index);33527 try sema.mod.declareDeclDependency(sema.owner_decl_index, decl_index);
33419 return sema.addConstant(ptr_type, (try sema.mod.intern(.{ .ptr = .{33528 return sema.addConstant(ptr_type, (try sema.mod.intern(.{ .ptr = .{
33420 .ty = ptr_type.ip_index,33529 .ty = ptr_type.toIntern(),
33421 .addr = .{ .mut_decl = .{33530 .addr = .{ .mut_decl = .{
33422 .decl = decl_index,33531 .decl = decl_index,
33423 .runtime_index = block.runtime_index,33532 .runtime_index = block.runtime_index,
...@@ -33589,7 +33698,7 @@ fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError...@@ -33589,7 +33698,7 @@ fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError
33589/// This logic must be kept in sync with `Type.isPtrLikeOptional`.33698/// This logic must be kept in sync with `Type.isPtrLikeOptional`.
33590fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {33699fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
33591 const mod = sema.mod;33700 const mod = sema.mod;
33592 return switch (mod.intern_pool.indexToKey(ty.ip_index)) {33701 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
33593 .ptr_type => |ptr_type| switch (ptr_type.size) {33702 .ptr_type => |ptr_type| switch (ptr_type.size) {
33594 .Slice => null,33703 .Slice => null,
33595 .C => ptr_type.elem_type.toType(),33704 .C => ptr_type.elem_type.toType(),
...@@ -33624,10 +33733,10 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {...@@ -33624,10 +33733,10 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
33624/// elsewhere in value.zig33733/// elsewhere in value.zig
33625pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {33734pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
33626 const mod = sema.mod;33735 const mod = sema.mod;
33627 return switch (ty.ip_index) {33736 return switch (ty.toIntern()) {
33628 .empty_struct_type => false,33737 .empty_struct_type => false,
3362933738
33630 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {33739 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
33631 .int_type => return false,33740 .int_type => return false,
33632 .ptr_type => |ptr_type| {33741 .ptr_type => |ptr_type| {
33633 const child_ty = ptr_type.elem_type.toType();33742 const child_ty = ptr_type.elem_type.toType();
...@@ -33873,7 +33982,7 @@ fn anonStructFieldIndex(...@@ -33873,7 +33982,7 @@ fn anonStructFieldIndex(
33873 field_src: LazySrcLoc,33982 field_src: LazySrcLoc,
33874) !u32 {33983) !u32 {
33875 const mod = sema.mod;33984 const mod = sema.mod;
33876 const anon_struct = mod.intern_pool.indexToKey(struct_ty.ip_index).anon_struct_type;33985 const anon_struct = mod.intern_pool.indexToKey(struct_ty.toIntern()).anon_struct_type;
33877 for (anon_struct.names, 0..) |name, i| {33986 for (anon_struct.names, 0..) |name, i| {
33878 if (mem.eql(u8, mod.intern_pool.stringToSlice(name), field_name)) {33987 if (mem.eql(u8, mod.intern_pool.stringToSlice(name), field_name)) {
33879 return @intCast(u32, i);33988 return @intCast(u32, i);
...@@ -33891,14 +34000,17 @@ fn queueFullTypeResolution(sema: *Sema, ty: Type) !void {...@@ -33891,14 +34000,17 @@ fn queueFullTypeResolution(sema: *Sema, ty: Type) !void {
33891fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {34000fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {
33892 const mod = sema.mod;34001 const mod = sema.mod;
33893 if (ty.zigTypeTag(mod) == .Vector) {34002 if (ty.zigTypeTag(mod) == .Vector) {
33894 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));34003 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));
33895 const scalar_ty = ty.scalarType(mod);34004 const scalar_ty = ty.scalarType(mod);
33896 for (result_data, 0..) |*scalar, i| {34005 for (result_data, 0..) |*scalar, i| {
33897 const lhs_elem = try lhs.elemValue(mod, i);34006 const lhs_elem = try lhs.elemValue(mod, i);
33898 const rhs_elem = try rhs.elemValue(mod, i);34007 const rhs_elem = try rhs.elemValue(mod, i);
33899 scalar.* = try sema.intAddScalar(lhs_elem, rhs_elem, scalar_ty);34008 scalar.* = try (try sema.intAddScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod);
33900 }34009 }
33901 return Value.Tag.aggregate.create(sema.arena, result_data);34010 return (try mod.intern(.{ .aggregate = .{
34011 .ty = ty.toIntern(),
34012 .storage = .{ .elems = result_data },
34013 } })).toValue();
33902 }34014 }
33903 return sema.intAddScalar(lhs, rhs, ty);34015 return sema.intAddScalar(lhs, rhs, ty);
33904}34016}
...@@ -33945,14 +34057,17 @@ fn numberAddWrapScalar(...@@ -33945,14 +34057,17 @@ fn numberAddWrapScalar(
33945fn intSub(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {34057fn intSub(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {
33946 const mod = sema.mod;34058 const mod = sema.mod;
33947 if (ty.zigTypeTag(mod) == .Vector) {34059 if (ty.zigTypeTag(mod) == .Vector) {
33948 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));34060 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));
33949 const scalar_ty = ty.scalarType(mod);34061 const scalar_ty = ty.scalarType(mod);
33950 for (result_data, 0..) |*scalar, i| {34062 for (result_data, 0..) |*scalar, i| {
33951 const lhs_elem = try lhs.elemValue(sema.mod, i);34063 const lhs_elem = try lhs.elemValue(sema.mod, i);
33952 const rhs_elem = try rhs.elemValue(sema.mod, i);34064 const rhs_elem = try rhs.elemValue(sema.mod, i);
33953 scalar.* = try sema.intSubScalar(lhs_elem, rhs_elem, scalar_ty);34065 scalar.* = try (try sema.intSubScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod);
33954 }34066 }
33955 return Value.Tag.aggregate.create(sema.arena, result_data);34067 return (try mod.intern(.{ .aggregate = .{
34068 .ty = ty.toIntern(),
34069 .storage = .{ .elems = result_data },
34070 } })).toValue();
33956 }34071 }
33957 return sema.intSubScalar(lhs, rhs, ty);34072 return sema.intSubScalar(lhs, rhs, ty);
33958}34073}
...@@ -34004,18 +34119,26 @@ fn intSubWithOverflow(...@@ -34004,18 +34119,26 @@ fn intSubWithOverflow(
34004) !Value.OverflowArithmeticResult {34119) !Value.OverflowArithmeticResult {
34005 const mod = sema.mod;34120 const mod = sema.mod;
34006 if (ty.zigTypeTag(mod) == .Vector) {34121 if (ty.zigTypeTag(mod) == .Vector) {
34007 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen(mod));34122 const vec_len = ty.vectorLen(mod);
34008 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));34123 const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len);
34009 for (result_data, 0..) |*scalar, i| {34124 const result_data = try sema.arena.alloc(InternPool.Index, vec_len);
34125 const scalar_ty = ty.scalarType(mod);
34126 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
34010 const lhs_elem = try lhs.elemValue(sema.mod, i);34127 const lhs_elem = try lhs.elemValue(sema.mod, i);
34011 const rhs_elem = try rhs.elemValue(sema.mod, i);34128 const rhs_elem = try rhs.elemValue(sema.mod, i);
34012 const of_math_result = try sema.intSubWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(mod));34129 const of_math_result = try sema.intSubWithOverflowScalar(lhs_elem, rhs_elem, scalar_ty);
34013 overflowed_data[i] = of_math_result.overflow_bit;34130 of.* = try of_math_result.overflow_bit.intern(Type.bool, mod);
34014 scalar.* = of_math_result.wrapped_result;34131 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
34015 }34132 }
34016 return Value.OverflowArithmeticResult{34133 return Value.OverflowArithmeticResult{
34017 .overflow_bit = try Value.Tag.aggregate.create(sema.arena, overflowed_data),34134 .overflow_bit = (try mod.intern(.{ .aggregate = .{
34018 .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data),34135 .ty = ty.toIntern(),
34136 .storage = .{ .elems = overflowed_data },
34137 } })).toValue(),
34138 .wrapped_result = (try mod.intern(.{ .aggregate = .{
34139 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),
34140 .storage = .{ .elems = result_data },
34141 } })).toValue(),
34019 };34142 };
34020 }34143 }
34021 return sema.intSubWithOverflowScalar(lhs, rhs, ty);34144 return sema.intSubWithOverflowScalar(lhs, rhs, ty);
...@@ -34057,13 +34180,17 @@ fn floatToInt(...@@ -34057,13 +34180,17 @@ fn floatToInt(
34057) CompileError!Value {34180) CompileError!Value {
34058 const mod = sema.mod;34181 const mod = sema.mod;
34059 if (float_ty.zigTypeTag(mod) == .Vector) {34182 if (float_ty.zigTypeTag(mod) == .Vector) {
34060 const elem_ty = float_ty.childType(mod);34183 const elem_ty = float_ty.scalarType(mod);
34061 const result_data = try sema.arena.alloc(Value, float_ty.vectorLen(mod));34184 const result_data = try sema.arena.alloc(InternPool.Index, float_ty.vectorLen(mod));
34185 const scalar_ty = int_ty.scalarType(mod);
34062 for (result_data, 0..) |*scalar, i| {34186 for (result_data, 0..) |*scalar, i| {
34063 const elem_val = try val.elemValue(sema.mod, i);34187 const elem_val = try val.elemValue(sema.mod, i);
34064 scalar.* = try sema.floatToIntScalar(block, src, elem_val, elem_ty, int_ty.scalarType(mod));34188 scalar.* = try (try sema.floatToIntScalar(block, src, elem_val, elem_ty, int_ty.scalarType(mod))).intern(scalar_ty, mod);
34065 }34189 }
34066 return Value.Tag.aggregate.create(sema.arena, result_data);34190 return (try mod.intern(.{ .aggregate = .{
34191 .ty = int_ty.toIntern(),
34192 .storage = .{ .elems = result_data },
34193 } })).toValue();
34067 }34194 }
34068 return sema.floatToIntScalar(block, src, val, float_ty, int_ty);34195 return sema.floatToIntScalar(block, src, val, float_ty, int_ty);
34069}34196}
...@@ -34139,16 +34266,16 @@ fn intFitsInType(...@@ -34139,16 +34266,16 @@ fn intFitsInType(
34139 vector_index: ?*usize,34266 vector_index: ?*usize,
34140) CompileError!bool {34267) CompileError!bool {
34141 const mod = sema.mod;34268 const mod = sema.mod;
34142 if (ty.ip_index == .comptime_int_type) return true;34269 if (ty.toIntern() == .comptime_int_type) return true;
34143 const info = ty.intInfo(mod);34270 const info = ty.intInfo(mod);
34144 switch (val.ip_index) {34271 switch (val.toIntern()) {
34145 .undef,34272 .undef,
34146 .zero,34273 .zero,
34147 .zero_usize,34274 .zero_usize,
34148 .zero_u8,34275 .zero_u8,
34149 => return true,34276 => return true,
3415034277
34151 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {34278 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
34152 .variable, .extern_func, .func, .ptr => {34279 .variable, .extern_func, .func, .ptr => {
34153 const target = mod.getTarget();34280 const target = mod.getTarget();
34154 const ptr_bits = target.ptrBitWidth();34281 const ptr_bits = target.ptrBitWidth();
...@@ -34219,12 +34346,12 @@ fn intInRange(sema: *Sema, tag_ty: Type, int_val: Value, end: usize) !bool {...@@ -34219,12 +34346,12 @@ fn intInRange(sema: *Sema, tag_ty: Type, int_val: Value, end: usize) !bool {
34219/// Asserts the type is an enum.34346/// Asserts the type is an enum.
34220fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {34347fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {
34221 const mod = sema.mod;34348 const mod = sema.mod;
34222 const enum_type = mod.intern_pool.indexToKey(ty.ip_index).enum_type;34349 const enum_type = mod.intern_pool.indexToKey(ty.toIntern()).enum_type;
34223 assert(enum_type.tag_mode != .nonexhaustive);34350 assert(enum_type.tag_mode != .nonexhaustive);
34224 // The `tagValueIndex` function call below relies on the type being the integer tag type.34351 // The `tagValueIndex` function call below relies on the type being the integer tag type.
34225 // `getCoerced` assumes the value will fit the new type.34352 // `getCoerced` assumes the value will fit the new type.
34226 if (!(try sema.intFitsInType(int, enum_type.tag_ty.toType(), null))) return false;34353 if (!(try sema.intFitsInType(int, enum_type.tag_ty.toType(), null))) return false;
34227 const int_coerced = try mod.intern_pool.getCoerced(sema.gpa, int.ip_index, enum_type.tag_ty);34354 const int_coerced = try mod.intern_pool.getCoerced(sema.gpa, int.toIntern(), enum_type.tag_ty);
3422834355
34229 return enum_type.tagValueIndex(&mod.intern_pool, int_coerced) != null;34356 return enum_type.tagValueIndex(&mod.intern_pool, int_coerced) != null;
34230}34357}
...@@ -34237,18 +34364,26 @@ fn intAddWithOverflow(...@@ -34237,18 +34364,26 @@ fn intAddWithOverflow(
34237) !Value.OverflowArithmeticResult {34364) !Value.OverflowArithmeticResult {
34238 const mod = sema.mod;34365 const mod = sema.mod;
34239 if (ty.zigTypeTag(mod) == .Vector) {34366 if (ty.zigTypeTag(mod) == .Vector) {
34240 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen(mod));34367 const vec_len = ty.vectorLen(mod);
34241 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));34368 const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len);
34242 for (result_data, 0..) |*scalar, i| {34369 const result_data = try sema.arena.alloc(InternPool.Index, vec_len);
34370 const scalar_ty = ty.scalarType(mod);
34371 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
34243 const lhs_elem = try lhs.elemValue(sema.mod, i);34372 const lhs_elem = try lhs.elemValue(sema.mod, i);
34244 const rhs_elem = try rhs.elemValue(sema.mod, i);34373 const rhs_elem = try rhs.elemValue(sema.mod, i);
34245 const of_math_result = try sema.intAddWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(mod));34374 const of_math_result = try sema.intAddWithOverflowScalar(lhs_elem, rhs_elem, scalar_ty);
34246 overflowed_data[i] = of_math_result.overflow_bit;34375 of.* = try of_math_result.overflow_bit.intern(Type.bool, mod);
34247 scalar.* = of_math_result.wrapped_result;34376 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
34248 }34377 }
34249 return Value.OverflowArithmeticResult{34378 return Value.OverflowArithmeticResult{
34250 .overflow_bit = try Value.Tag.aggregate.create(sema.arena, overflowed_data),34379 .overflow_bit = (try mod.intern(.{ .aggregate = .{
34251 .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data),34380 .ty = ty.toIntern(),
34381 .storage = .{ .elems = overflowed_data },
34382 } })).toValue(),
34383 .wrapped_result = (try mod.intern(.{ .aggregate = .{
34384 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),
34385 .storage = .{ .elems = result_data },
34386 } })).toValue(),
34252 };34387 };
34253 }34388 }
34254 return sema.intAddWithOverflowScalar(lhs, rhs, ty);34389 return sema.intAddWithOverflowScalar(lhs, rhs, ty);
...@@ -34340,14 +34475,17 @@ fn compareVector(...@@ -34340,14 +34475,17 @@ fn compareVector(
34340) !Value {34475) !Value {
34341 const mod = sema.mod;34476 const mod = sema.mod;
34342 assert(ty.zigTypeTag(mod) == .Vector);34477 assert(ty.zigTypeTag(mod) == .Vector);
34343 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));34478 const result_data = try sema.arena.alloc(InternPool.Index, ty.vectorLen(mod));
34344 for (result_data, 0..) |*scalar, i| {34479 for (result_data, 0..) |*scalar, i| {
34345 const lhs_elem = try lhs.elemValue(sema.mod, i);34480 const lhs_elem = try lhs.elemValue(sema.mod, i);
34346 const rhs_elem = try rhs.elemValue(sema.mod, i);34481 const rhs_elem = try rhs.elemValue(sema.mod, i);
34347 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod));34482 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod));
34348 scalar.* = Value.makeBool(res_bool);34483 scalar.* = try Value.makeBool(res_bool).intern(Type.bool, mod);
34349 }34484 }
34350 return Value.Tag.aggregate.create(sema.arena, result_data);34485 return (try mod.intern(.{ .aggregate = .{
34486 .ty = (try mod.vectorType(.{ .len = ty.vectorLen(mod), .child = .u1_type })).toIntern(),
34487 .storage = .{ .elems = result_data },
34488 } })).toValue();
34351}34489}
3435234490
34353/// Returns the type of a pointer to an element.34491/// Returns the type of a pointer to an element.
src/TypedValue.zig+20-4
...@@ -103,10 +103,26 @@ pub fn print(...@@ -103,10 +103,26 @@ pub fn print(
103 return writer.writeAll(" }");103 return writer.writeAll(" }");
104 },104 },
105 .bytes => return writer.print("\"{}\"", .{std.zig.fmtEscapes(val.castTag(.bytes).?.data)}),105 .bytes => return writer.print("\"{}\"", .{std.zig.fmtEscapes(val.castTag(.bytes).?.data)}),
106 .str_lit => {106 .repeated => {
107 const str_lit = val.castTag(.str_lit).?.data;107 if (level == 0) {
108 const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];108 return writer.writeAll(".{ ... }");
109 return writer.print("\"{}\"", .{std.zig.fmtEscapes(bytes)});109 }
110 var i: u32 = 0;
111 try writer.writeAll(".{ ");
112 const elem_tv = TypedValue{
113 .ty = ty.elemType2(mod),
114 .val = val.castTag(.repeated).?.data,
115 };
116 const len = ty.arrayLen(mod);
117 const max_len = std.math.min(len, max_aggregate_items);
118 while (i < max_len) : (i += 1) {
119 if (i != 0) try writer.writeAll(", ");
120 try print(elem_tv, writer, level - 1, mod);
121 }
122 if (len > max_aggregate_items) {
123 try writer.writeAll(", ...");
124 }
125 return writer.writeAll(" }");
110 },126 },
111 // TODO these should not appear in this function127 // TODO these should not appear in this function
112 .inferred_alloc => return writer.writeAll("(inferred allocation value)"),128 .inferred_alloc => return writer.writeAll("(inferred allocation value)"),
src/arch/aarch64/CodeGen.zig-2
...@@ -846,7 +846,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -846,7 +846,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
846 .ptr_elem_ptr => try self.airPtrElemPtr(inst),846 .ptr_elem_ptr => try self.airPtrElemPtr(inst),
847847
848 .constant => unreachable, // excluded from function bodies848 .constant => unreachable, // excluded from function bodies
849 .const_ty => unreachable, // excluded from function bodies
850 .interned => unreachable, // excluded from function bodies849 .interned => unreachable, // excluded from function bodies
851 .unreach => self.finishAirBookkeeping(),850 .unreach => self.finishAirBookkeeping(),
852851
...@@ -6169,7 +6168,6 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {...@@ -6169,7 +6168,6 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
6169 }6168 }
6170 return gop.value_ptr.*;6169 return gop.value_ptr.*;
6171 },6170 },
6172 .const_ty => unreachable,
6173 else => return self.getResolvedInstValue(inst_index),6171 else => return self.getResolvedInstValue(inst_index),
6174 }6172 }
6175}6173}
src/arch/arm/CodeGen.zig-2
...@@ -830,7 +830,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -830,7 +830,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
830 .ptr_elem_ptr => try self.airPtrElemPtr(inst),830 .ptr_elem_ptr => try self.airPtrElemPtr(inst),
831831
832 .constant => unreachable, // excluded from function bodies832 .constant => unreachable, // excluded from function bodies
833 .const_ty => unreachable, // excluded from function bodies
834 .interned => unreachable, // excluded from function bodies833 .interned => unreachable, // excluded from function bodies
835 .unreach => self.finishAirBookkeeping(),834 .unreach => self.finishAirBookkeeping(),
836835
...@@ -6117,7 +6116,6 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {...@@ -6117,7 +6116,6 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
6117 }6116 }
6118 return gop.value_ptr.*;6117 return gop.value_ptr.*;
6119 },6118 },
6120 .const_ty => unreachable,
6121 else => return self.getResolvedInstValue(inst_index),6119 else => return self.getResolvedInstValue(inst_index),
6122 }6120 }
6123}6121}
src/arch/riscv64/CodeGen.zig-2
...@@ -660,7 +660,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -660,7 +660,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
660 .ptr_elem_ptr => try self.airPtrElemPtr(inst),660 .ptr_elem_ptr => try self.airPtrElemPtr(inst),
661661
662 .constant => unreachable, // excluded from function bodies662 .constant => unreachable, // excluded from function bodies
663 .const_ty => unreachable, // excluded from function bodies
664 .interned => unreachable, // excluded from function bodies663 .interned => unreachable, // excluded from function bodies
665 .unreach => self.finishAirBookkeeping(),664 .unreach => self.finishAirBookkeeping(),
666665
...@@ -2571,7 +2570,6 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {...@@ -2571,7 +2570,6 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
2571 }2570 }
2572 return gop.value_ptr.*;2571 return gop.value_ptr.*;
2573 },2572 },
2574 .const_ty => unreachable,
2575 else => return self.getResolvedInstValue(inst_index),2573 else => return self.getResolvedInstValue(inst_index),
2576 }2574 }
2577}2575}
src/arch/sparc64/CodeGen.zig-2
...@@ -680,7 +680,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -680,7 +680,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
680 .ptr_elem_ptr => try self.airPtrElemPtr(inst),680 .ptr_elem_ptr => try self.airPtrElemPtr(inst),
681681
682 .constant => unreachable, // excluded from function bodies682 .constant => unreachable, // excluded from function bodies
683 .const_ty => unreachable, // excluded from function bodies
684 .interned => unreachable, // excluded from function bodies683 .interned => unreachable, // excluded from function bodies
685 .unreach => self.finishAirBookkeeping(),684 .unreach => self.finishAirBookkeeping(),
686685
...@@ -4567,7 +4566,6 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {...@@ -4567,7 +4566,6 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
4567 }4566 }
4568 return gop.value_ptr.*;4567 return gop.value_ptr.*;
4569 },4568 },
4570 .const_ty => unreachable,
4571 else => return self.getResolvedInstValue(inst),4569 else => return self.getResolvedInstValue(inst),
4572 }4570 }
4573 }4571 }
src/arch/wasm/CodeGen.zig+5-22
...@@ -1833,7 +1833,6 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -1833,7 +1833,6 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
1833 const air_tags = func.air.instructions.items(.tag);1833 const air_tags = func.air.instructions.items(.tag);
1834 return switch (air_tags[inst]) {1834 return switch (air_tags[inst]) {
1835 .constant => unreachable,1835 .constant => unreachable,
1836 .const_ty => unreachable,
1837 .interned => unreachable,1836 .interned => unreachable,
18381837
1839 .add => func.airBinOp(inst, .add),1838 .add => func.airBinOp(inst, .add),
...@@ -6903,28 +6902,12 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -6903,28 +6902,12 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
6903 .child = .u8_type,6902 .child = .u8_type,
6904 .sentinel = .zero_u8,6903 .sentinel = .zero_u8,
6905 });6904 });
6906 const string_bytes = &mod.string_literal_bytes;6905 const name_val = try mod.intern(.{ .aggregate = .{
6907 try string_bytes.ensureUnusedCapacity(mod.gpa, tag_name.len);6906 .ty = name_ty.toIntern(),
6908 const gop = try mod.string_literal_table.getOrPutContextAdapted(mod.gpa, @as([]const u8, tag_name), Module.StringLiteralAdapter{6907 .storage = .{ .bytes = tag_name },
6909 .bytes = string_bytes,6908 } });
6910 }, Module.StringLiteralContext{
6911 .bytes = string_bytes,
6912 });
6913 if (!gop.found_existing) {
6914 gop.key_ptr.* = .{
6915 .index = @intCast(u32, string_bytes.items.len),
6916 .len = @intCast(u32, tag_name.len),
6917 };
6918 string_bytes.appendSliceAssumeCapacity(tag_name);
6919 gop.value_ptr.* = .none;
6920 }
6921 var name_val_payload: Value.Payload.StrLit = .{
6922 .base = .{ .tag = .str_lit },
6923 .data = gop.key_ptr.*,
6924 };
6925 const name_val = Value.initPayload(&name_val_payload.base);
6926 const tag_sym_index = try func.bin_file.lowerUnnamedConst(6909 const tag_sym_index = try func.bin_file.lowerUnnamedConst(
6927 .{ .ty = name_ty, .val = name_val },6910 .{ .ty = name_ty, .val = name_val.toValue() },
6928 enum_decl_index,6911 enum_decl_index,
6929 );6912 );
69306913
src/arch/x86_64/CodeGen.zig+1-4
...@@ -1923,7 +1923,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {...@@ -1923,7 +1923,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
1923 .ptr_elem_ptr => try self.airPtrElemPtr(inst),1923 .ptr_elem_ptr => try self.airPtrElemPtr(inst),
19241924
1925 .constant => unreachable, // excluded from function bodies1925 .constant => unreachable, // excluded from function bodies
1926 .const_ty => unreachable, // excluded from function bodies
1927 .interned => unreachable, // excluded from function bodies1926 .interned => unreachable, // excluded from function bodies
1928 .unreach => if (self.wantSafety()) try self.airTrap() else self.finishAirBookkeeping(),1927 .unreach => if (self.wantSafety()) try self.airTrap() else self.finishAirBookkeeping(),
19291928
...@@ -2099,7 +2098,7 @@ fn feed(self: *Self, bt: *Liveness.BigTomb, operand: Air.Inst.Ref) void {...@@ -2099,7 +2098,7 @@ fn feed(self: *Self, bt: *Liveness.BigTomb, operand: Air.Inst.Ref) void {
2099/// Asserts there is already capacity to insert into top branch inst_table.2098/// Asserts there is already capacity to insert into top branch inst_table.
2100fn processDeath(self: *Self, inst: Air.Inst.Index) void {2099fn processDeath(self: *Self, inst: Air.Inst.Index) void {
2101 switch (self.air.instructions.items(.tag)[inst]) {2100 switch (self.air.instructions.items(.tag)[inst]) {
2102 .constant, .const_ty => unreachable,2101 .constant => unreachable,
2103 else => self.inst_tracking.getPtr(inst).?.die(self, inst),2102 else => self.inst_tracking.getPtr(inst).?.die(self, inst),
2104 }2103 }
2105}2104}
...@@ -11593,7 +11592,6 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {...@@ -11593,7 +11592,6 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
11593 }));11592 }));
11594 break :tracking gop.value_ptr;11593 break :tracking gop.value_ptr;
11595 },11594 },
11596 .const_ty => unreachable,
11597 else => self.inst_tracking.getPtr(inst).?,11595 else => self.inst_tracking.getPtr(inst).?,
11598 }.short;11596 }.short;
11599 switch (mcv) {11597 switch (mcv) {
...@@ -11608,7 +11606,6 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {...@@ -11608,7 +11606,6 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
11608fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) *InstTracking {11606fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) *InstTracking {
11609 const tracking = switch (self.air.instructions.items(.tag)[inst]) {11607 const tracking = switch (self.air.instructions.items(.tag)[inst]) {
11610 .constant => &self.const_tracking,11608 .constant => &self.const_tracking,
11611 .const_ty => unreachable,
11612 else => &self.inst_tracking,11609 else => &self.inst_tracking,
11613 }.getPtr(inst).?;11610 }.getPtr(inst).?;
11614 return switch (tracking.short) {11611 return switch (tracking.short) {
src/codegen.zig-144
...@@ -204,150 +204,6 @@ pub fn generateSymbol(...@@ -204,150 +204,6 @@ pub fn generateSymbol(
204 return .ok;204 return .ok;
205 }205 }
206206
207 if (typed_value.val.ip_index == .none) switch (typed_value.ty.zigTypeTag(mod)) {
208 .Array => switch (typed_value.val.tag()) {
209 .bytes => {
210 const bytes = typed_value.val.castTag(.bytes).?.data;
211 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel(mod));
212 // The bytes payload already includes the sentinel, if any
213 try code.ensureUnusedCapacity(len);
214 code.appendSliceAssumeCapacity(bytes[0..len]);
215 return Result.ok;
216 },
217 .str_lit => {
218 const str_lit = typed_value.val.castTag(.str_lit).?.data;
219 const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
220 try code.ensureUnusedCapacity(bytes.len + 1);
221 code.appendSliceAssumeCapacity(bytes);
222 if (typed_value.ty.sentinel(mod)) |sent_val| {
223 const byte = @intCast(u8, sent_val.toUnsignedInt(mod));
224 code.appendAssumeCapacity(byte);
225 }
226 return Result.ok;
227 },
228 else => return Result{
229 .fail = try ErrorMsg.create(
230 bin_file.allocator,
231 src_loc,
232 "TODO implement generateSymbol for array type value: {s}",
233 .{@tagName(typed_value.val.tag())},
234 ),
235 },
236 },
237 .Struct => {
238 if (typed_value.ty.containerLayout(mod) == .Packed) {
239 const struct_obj = mod.typeToStruct(typed_value.ty).?;
240 const fields = struct_obj.fields.values();
241 const field_vals = typed_value.val.castTag(.aggregate).?.data;
242 const abi_size = math.cast(usize, typed_value.ty.abiSize(mod)) orelse return error.Overflow;
243 const current_pos = code.items.len;
244 try code.resize(current_pos + abi_size);
245 var bits: u16 = 0;
246
247 for (field_vals, 0..) |field_val, index| {
248 const field_ty = fields[index].ty;
249 // pointer may point to a decl which must be marked used
250 // but can also result in a relocation. Therefore we handle those seperately.
251 if (field_ty.zigTypeTag(mod) == .Pointer) {
252 const field_size = math.cast(usize, field_ty.abiSize(mod)) orelse return error.Overflow;
253 var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size);
254 defer tmp_list.deinit();
255 switch (try generateSymbol(bin_file, src_loc, .{
256 .ty = field_ty,
257 .val = field_val,
258 }, &tmp_list, debug_output, reloc_info)) {
259 .ok => @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items),
260 .fail => |em| return Result{ .fail = em },
261 }
262 } else {
263 field_val.writeToPackedMemory(field_ty, mod, code.items[current_pos..], bits) catch unreachable;
264 }
265 bits += @intCast(u16, field_ty.bitSize(mod));
266 }
267
268 return Result.ok;
269 }
270
271 const struct_begin = code.items.len;
272 const field_vals = typed_value.val.castTag(.aggregate).?.data;
273 for (field_vals, 0..) |field_val, index| {
274 const field_ty = typed_value.ty.structFieldType(index, mod);
275 if (!field_ty.hasRuntimeBits(mod)) continue;
276
277 switch (try generateSymbol(bin_file, src_loc, .{
278 .ty = field_ty,
279 .val = field_val,
280 }, code, debug_output, reloc_info)) {
281 .ok => {},
282 .fail => |em| return Result{ .fail = em },
283 }
284 const unpadded_field_end = code.items.len - struct_begin;
285
286 // Pad struct members if required
287 const padded_field_end = typed_value.ty.structFieldOffset(index + 1, mod);
288 const padding = math.cast(usize, padded_field_end - unpadded_field_end) orelse return error.Overflow;
289
290 if (padding > 0) {
291 try code.writer().writeByteNTimes(0, padding);
292 }
293 }
294
295 return Result.ok;
296 },
297 .Vector => switch (typed_value.val.tag()) {
298 .bytes => {
299 const bytes = typed_value.val.castTag(.bytes).?.data;
300 const len = math.cast(usize, typed_value.ty.arrayLen(mod)) orelse return error.Overflow;
301 const padding = math.cast(usize, typed_value.ty.abiSize(mod) - len) orelse
302 return error.Overflow;
303 try code.ensureUnusedCapacity(len + padding);
304 code.appendSliceAssumeCapacity(bytes[0..len]);
305 if (padding > 0) try code.writer().writeByteNTimes(0, padding);
306 return Result.ok;
307 },
308 .str_lit => {
309 const str_lit = typed_value.val.castTag(.str_lit).?.data;
310 const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
311 const padding = math.cast(usize, typed_value.ty.abiSize(mod) - str_lit.len) orelse
312 return error.Overflow;
313 try code.ensureUnusedCapacity(str_lit.len + padding);
314 code.appendSliceAssumeCapacity(bytes);
315 if (padding > 0) try code.writer().writeByteNTimes(0, padding);
316 return Result.ok;
317 },
318 else => unreachable,
319 },
320 .Frame,
321 .AnyFrame,
322 => return .{ .fail = try ErrorMsg.create(
323 bin_file.allocator,
324 src_loc,
325 "TODO generateSymbol for type {}",
326 .{typed_value.ty.fmt(mod)},
327 ) },
328 .Float,
329 .Union,
330 .Optional,
331 .ErrorUnion,
332 .ErrorSet,
333 .Int,
334 .Enum,
335 .Bool,
336 .Pointer,
337 => unreachable, // handled below
338 .Type,
339 .Void,
340 .NoReturn,
341 .ComptimeFloat,
342 .ComptimeInt,
343 .Undefined,
344 .Null,
345 .Opaque,
346 .EnumLiteral,
347 .Fn,
348 => unreachable, // comptime-only types
349 };
350
351 switch (mod.intern_pool.indexToKey(typed_value.val.ip_index)) {207 switch (mod.intern_pool.indexToKey(typed_value.val.ip_index)) {
352 .int_type,208 .int_type,
353 .ptr_type,209 .ptr_type,
src/codegen/c.zig+1-20
...@@ -870,7 +870,7 @@ pub const DeclGen = struct {...@@ -870,7 +870,7 @@ pub const DeclGen = struct {
870 }870 }
871871
872 // First try specific tag representations for more efficiency.872 // First try specific tag representations for more efficiency.
873 switch (val.ip_index) {873 switch (val.toIntern()) {
874 .undef => {874 .undef => {
875 const ai = ty.arrayInfo(mod);875 const ai = ty.arrayInfo(mod);
876 try writer.writeByte('{');876 try writer.writeByte('{');
...@@ -893,24 +893,6 @@ pub const DeclGen = struct {...@@ -893,24 +893,6 @@ pub const DeclGen = struct {
893 try writer.writeByte('}');893 try writer.writeByte('}');
894 return;894 return;
895 },895 },
896 .none => switch (val.tag()) {
897 .bytes, .str_lit => |t| {
898 const bytes = switch (t) {
899 .bytes => val.castTag(.bytes).?.data,
900 .str_lit => bytes: {
901 const str_lit = val.castTag(.str_lit).?.data;
902 break :bytes mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
903 },
904 else => unreachable,
905 };
906 const sentinel = if (ty.sentinel(mod)) |sentinel| @intCast(u8, sentinel.toUnsignedInt(mod)) else null;
907 try writer.print("{s}", .{
908 fmtStringLiteral(bytes[0..@intCast(usize, ty.arrayLen(mod))], sentinel),
909 });
910 return;
911 },
912 else => {},
913 },
914 else => {},896 else => {},
915 }897 }
916 // Fall back to generic implementation.898 // Fall back to generic implementation.
...@@ -2909,7 +2891,6 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,...@@ -2909,7 +2891,6 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
2909 const result_value = switch (air_tags[inst]) {2891 const result_value = switch (air_tags[inst]) {
2910 // zig fmt: off2892 // zig fmt: off
2911 .constant => unreachable, // excluded from function bodies2893 .constant => unreachable, // excluded from function bodies
2912 .const_ty => unreachable, // excluded from function bodies
2913 .interned => unreachable, // excluded from function bodies2894 .interned => unreachable, // excluded from function bodies
29142895
2915 .arg => try airArg(f, inst),2896 .arg => try airArg(f, inst),
src/codegen/llvm.zig+24-302
...@@ -1501,7 +1501,7 @@ pub const Object = struct {...@@ -1501,7 +1501,7 @@ pub const Object = struct {
1501 }1501 }
15021502
1503 const ip = &mod.intern_pool;1503 const ip = &mod.intern_pool;
1504 const enum_type = ip.indexToKey(ty.ip_index).enum_type;1504 const enum_type = ip.indexToKey(ty.toIntern()).enum_type;
15051505
1506 const enumerators = try gpa.alloc(*llvm.DIEnumerator, enum_type.names.len);1506 const enumerators = try gpa.alloc(*llvm.DIEnumerator, enum_type.names.len);
1507 defer gpa.free(enumerators);1507 defer gpa.free(enumerators);
...@@ -1697,7 +1697,7 @@ pub const Object = struct {...@@ -1697,7 +1697,7 @@ pub const Object = struct {
1697 return ptr_di_ty;1697 return ptr_di_ty;
1698 },1698 },
1699 .Opaque => {1699 .Opaque => {
1700 if (ty.ip_index == .anyopaque_type) {1700 if (ty.toIntern() == .anyopaque_type) {
1701 const di_ty = dib.createBasicType("anyopaque", 0, DW.ATE.signed);1701 const di_ty = dib.createBasicType("anyopaque", 0, DW.ATE.signed);
1702 gop.value_ptr.* = AnnotatedDITypePtr.initFull(di_ty);1702 gop.value_ptr.* = AnnotatedDITypePtr.initFull(di_ty);
1703 return di_ty;1703 return di_ty;
...@@ -1981,7 +1981,7 @@ pub const Object = struct {...@@ -1981,7 +1981,7 @@ pub const Object = struct {
1981 break :blk fwd_decl;1981 break :blk fwd_decl;
1982 };1982 };
19831983
1984 switch (mod.intern_pool.indexToKey(ty.ip_index)) {1984 switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1985 .anon_struct_type => |tuple| {1985 .anon_struct_type => |tuple| {
1986 var di_fields: std.ArrayListUnmanaged(*llvm.DIType) = .{};1986 var di_fields: std.ArrayListUnmanaged(*llvm.DIType) = .{};
1987 defer di_fields.deinit(gpa);1987 defer di_fields.deinit(gpa);
...@@ -2466,7 +2466,7 @@ pub const DeclGen = struct {...@@ -2466,7 +2466,7 @@ pub const DeclGen = struct {
2466 global.setGlobalConstant(.True);2466 global.setGlobalConstant(.True);
2467 break :init_val decl.val;2467 break :init_val decl.val;
2468 };2468 };
2469 if (init_val.ip_index != .unreachable_value) {2469 if (init_val.toIntern() != .unreachable_value) {
2470 const llvm_init = try dg.lowerValue(.{ .ty = decl.ty, .val = init_val });2470 const llvm_init = try dg.lowerValue(.{ .ty = decl.ty, .val = init_val });
2471 if (global.globalGetValueType() == llvm_init.typeOf()) {2471 if (global.globalGetValueType() == llvm_init.typeOf()) {
2472 global.setInitializer(llvm_init);2472 global.setInitializer(llvm_init);
...@@ -2802,12 +2802,12 @@ pub const DeclGen = struct {...@@ -2802,12 +2802,12 @@ pub const DeclGen = struct {
2802 return dg.context.pointerType(llvm_addrspace);2802 return dg.context.pointerType(llvm_addrspace);
2803 },2803 },
2804 .Opaque => {2804 .Opaque => {
2805 if (t.ip_index == .anyopaque_type) return dg.context.intType(8);2805 if (t.toIntern() == .anyopaque_type) return dg.context.intType(8);
28062806
2807 const gop = try dg.object.type_map.getOrPut(gpa, t.toIntern());2807 const gop = try dg.object.type_map.getOrPut(gpa, t.toIntern());
2808 if (gop.found_existing) return gop.value_ptr.*;2808 if (gop.found_existing) return gop.value_ptr.*;
28092809
2810 const opaque_type = mod.intern_pool.indexToKey(t.ip_index).opaque_type;2810 const opaque_type = mod.intern_pool.indexToKey(t.toIntern()).opaque_type;
2811 const name = try mod.opaqueFullyQualifiedName(opaque_type);2811 const name = try mod.opaqueFullyQualifiedName(opaque_type);
2812 defer gpa.free(name);2812 defer gpa.free(name);
28132813
...@@ -2897,7 +2897,7 @@ pub const DeclGen = struct {...@@ -2897,7 +2897,7 @@ pub const DeclGen = struct {
2897 const gop = try dg.object.type_map.getOrPut(gpa, t.toIntern());2897 const gop = try dg.object.type_map.getOrPut(gpa, t.toIntern());
2898 if (gop.found_existing) return gop.value_ptr.*;2898 if (gop.found_existing) return gop.value_ptr.*;
28992899
2900 const struct_type = switch (mod.intern_pool.indexToKey(t.ip_index)) {2900 const struct_type = switch (mod.intern_pool.indexToKey(t.toIntern())) {
2901 .anon_struct_type => |tuple| {2901 .anon_struct_type => |tuple| {
2902 const llvm_struct_ty = dg.context.structCreateNamed("");2902 const llvm_struct_ty = dg.context.structCreateNamed("");
2903 gop.value_ptr.* = llvm_struct_ty; // must be done before any recursive calls2903 gop.value_ptr.* = llvm_struct_ty; // must be done before any recursive calls
...@@ -3199,7 +3199,7 @@ pub const DeclGen = struct {...@@ -3199,7 +3199,7 @@ pub const DeclGen = struct {
3199 const mod = dg.module;3199 const mod = dg.module;
3200 const target = mod.getTarget();3200 const target = mod.getTarget();
3201 var tv = arg_tv;3201 var tv = arg_tv;
3202 switch (mod.intern_pool.indexToKey(tv.val.ip_index)) {3202 switch (mod.intern_pool.indexToKey(tv.val.toIntern())) {
3203 .runtime_value => |rt| tv.val = rt.val.toValue(),3203 .runtime_value => |rt| tv.val = rt.val.toValue(),
3204 else => {},3204 else => {},
3205 }3205 }
...@@ -3208,284 +3208,7 @@ pub const DeclGen = struct {...@@ -3208,284 +3208,7 @@ pub const DeclGen = struct {
3208 return llvm_type.getUndef();3208 return llvm_type.getUndef();
3209 }3209 }
32103210
3211 if (tv.val.ip_index == .none) switch (tv.ty.zigTypeTag(mod)) {3211 switch (mod.intern_pool.indexToKey(tv.val.toIntern())) {
3212 .Array => switch (tv.val.tag()) {
3213 .bytes => {
3214 const bytes = tv.val.castTag(.bytes).?.data;
3215 return dg.context.constString(
3216 bytes.ptr,
3217 @intCast(c_uint, tv.ty.arrayLenIncludingSentinel(mod)),
3218 .True, // Don't null terminate. Bytes has the sentinel, if any.
3219 );
3220 },
3221 .str_lit => {
3222 const str_lit = tv.val.castTag(.str_lit).?.data;
3223 const bytes = dg.module.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
3224 if (tv.ty.sentinel(mod)) |sent_val| {
3225 const byte = @intCast(u8, sent_val.toUnsignedInt(mod));
3226 if (byte == 0 and bytes.len > 0) {
3227 return dg.context.constString(
3228 bytes.ptr,
3229 @intCast(c_uint, bytes.len),
3230 .False, // Yes, null terminate.
3231 );
3232 }
3233 var array = std.ArrayList(u8).init(dg.gpa);
3234 defer array.deinit();
3235 try array.ensureUnusedCapacity(bytes.len + 1);
3236 array.appendSliceAssumeCapacity(bytes);
3237 array.appendAssumeCapacity(byte);
3238 return dg.context.constString(
3239 array.items.ptr,
3240 @intCast(c_uint, array.items.len),
3241 .True, // Don't null terminate.
3242 );
3243 } else {
3244 return dg.context.constString(
3245 bytes.ptr,
3246 @intCast(c_uint, bytes.len),
3247 .True, // Don't null terminate. `bytes` has the sentinel, if any.
3248 );
3249 }
3250 },
3251 else => unreachable,
3252 },
3253 .Struct => {
3254 const llvm_struct_ty = try dg.lowerType(tv.ty);
3255 const gpa = dg.gpa;
3256
3257 const struct_type = switch (mod.intern_pool.indexToKey(tv.ty.ip_index)) {
3258 .anon_struct_type => |tuple| {
3259 var llvm_fields: std.ArrayListUnmanaged(*llvm.Value) = .{};
3260 defer llvm_fields.deinit(gpa);
3261
3262 try llvm_fields.ensureUnusedCapacity(gpa, tuple.types.len);
3263
3264 comptime assert(struct_layout_version == 2);
3265 var offset: u64 = 0;
3266 var big_align: u32 = 0;
3267 var need_unnamed = false;
3268
3269 for (tuple.types, tuple.values, 0..) |field_ty, field_val, i| {
3270 if (field_val != .none) continue;
3271 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
3272
3273 const field_align = field_ty.toType().abiAlignment(mod);
3274 big_align = @max(big_align, field_align);
3275 const prev_offset = offset;
3276 offset = std.mem.alignForwardGeneric(u64, offset, field_align);
3277
3278 const padding_len = offset - prev_offset;
3279 if (padding_len > 0) {
3280 const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len));
3281 // TODO make this and all other padding elsewhere in debug
3282 // builds be 0xaa not undef.
3283 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
3284 }
3285
3286 const field_llvm_val = try dg.lowerValue(.{
3287 .ty = field_ty.toType(),
3288 .val = try tv.val.fieldValue(mod, i),
3289 });
3290
3291 need_unnamed = need_unnamed or dg.isUnnamedType(field_ty.toType(), field_llvm_val);
3292
3293 llvm_fields.appendAssumeCapacity(field_llvm_val);
3294
3295 offset += field_ty.toType().abiSize(mod);
3296 }
3297 {
3298 const prev_offset = offset;
3299 offset = std.mem.alignForwardGeneric(u64, offset, big_align);
3300 const padding_len = offset - prev_offset;
3301 if (padding_len > 0) {
3302 const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len));
3303 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
3304 }
3305 }
3306
3307 if (need_unnamed) {
3308 return dg.context.constStruct(
3309 llvm_fields.items.ptr,
3310 @intCast(c_uint, llvm_fields.items.len),
3311 .False,
3312 );
3313 } else {
3314 return llvm_struct_ty.constNamedStruct(
3315 llvm_fields.items.ptr,
3316 @intCast(c_uint, llvm_fields.items.len),
3317 );
3318 }
3319 },
3320 .struct_type => |struct_type| struct_type,
3321 else => unreachable,
3322 };
3323
3324 const struct_obj = mod.structPtrUnwrap(struct_type.index).?;
3325
3326 if (struct_obj.layout == .Packed) {
3327 assert(struct_obj.haveLayout());
3328 const big_bits = struct_obj.backing_int_ty.bitSize(mod);
3329 const int_llvm_ty = dg.context.intType(@intCast(c_uint, big_bits));
3330 const fields = struct_obj.fields.values();
3331 comptime assert(Type.packed_struct_layout_version == 2);
3332 var running_int: *llvm.Value = int_llvm_ty.constNull();
3333 var running_bits: u16 = 0;
3334 for (fields, 0..) |field, i| {
3335 if (!field.ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
3336
3337 const non_int_val = try dg.lowerValue(.{
3338 .ty = field.ty,
3339 .val = try tv.val.fieldValue(mod, i),
3340 });
3341 const ty_bit_size = @intCast(u16, field.ty.bitSize(mod));
3342 const small_int_ty = dg.context.intType(ty_bit_size);
3343 const small_int_val = if (field.ty.isPtrAtRuntime(mod))
3344 non_int_val.constPtrToInt(small_int_ty)
3345 else
3346 non_int_val.constBitCast(small_int_ty);
3347 const shift_rhs = int_llvm_ty.constInt(running_bits, .False);
3348 // If the field is as large as the entire packed struct, this
3349 // zext would go from, e.g. i16 to i16. This is legal with
3350 // constZExtOrBitCast but not legal with constZExt.
3351 const extended_int_val = small_int_val.constZExtOrBitCast(int_llvm_ty);
3352 const shifted = extended_int_val.constShl(shift_rhs);
3353 running_int = running_int.constOr(shifted);
3354 running_bits += ty_bit_size;
3355 }
3356 return running_int;
3357 }
3358
3359 const llvm_field_count = llvm_struct_ty.countStructElementTypes();
3360 var llvm_fields = try std.ArrayListUnmanaged(*llvm.Value).initCapacity(gpa, llvm_field_count);
3361 defer llvm_fields.deinit(gpa);
3362
3363 comptime assert(struct_layout_version == 2);
3364 var offset: u64 = 0;
3365 var big_align: u32 = 0;
3366 var need_unnamed = false;
3367
3368 var it = struct_obj.runtimeFieldIterator(mod);
3369 while (it.next()) |field_and_index| {
3370 const field = field_and_index.field;
3371 const field_align = field.alignment(mod, struct_obj.layout);
3372 big_align = @max(big_align, field_align);
3373 const prev_offset = offset;
3374 offset = std.mem.alignForwardGeneric(u64, offset, field_align);
3375
3376 const padding_len = offset - prev_offset;
3377 if (padding_len > 0) {
3378 const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len));
3379 // TODO make this and all other padding elsewhere in debug
3380 // builds be 0xaa not undef.
3381 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
3382 }
3383
3384 const field_llvm_val = try dg.lowerValue(.{
3385 .ty = field.ty,
3386 .val = try tv.val.fieldValue(mod, field_and_index.index),
3387 });
3388
3389 need_unnamed = need_unnamed or dg.isUnnamedType(field.ty, field_llvm_val);
3390
3391 llvm_fields.appendAssumeCapacity(field_llvm_val);
3392
3393 offset += field.ty.abiSize(mod);
3394 }
3395 {
3396 const prev_offset = offset;
3397 offset = std.mem.alignForwardGeneric(u64, offset, big_align);
3398 const padding_len = offset - prev_offset;
3399 if (padding_len > 0) {
3400 const llvm_array_ty = dg.context.intType(8).arrayType(@intCast(c_uint, padding_len));
3401 llvm_fields.appendAssumeCapacity(llvm_array_ty.getUndef());
3402 }
3403 }
3404
3405 if (need_unnamed) {
3406 return dg.context.constStruct(
3407 llvm_fields.items.ptr,
3408 @intCast(c_uint, llvm_fields.items.len),
3409 .False,
3410 );
3411 } else {
3412 return llvm_struct_ty.constNamedStruct(
3413 llvm_fields.items.ptr,
3414 @intCast(c_uint, llvm_fields.items.len),
3415 );
3416 }
3417 },
3418 .Vector => switch (tv.val.tag()) {
3419 .bytes => {
3420 // Note, sentinel is not stored even if the type has a sentinel.
3421 const bytes = tv.val.castTag(.bytes).?.data;
3422 const vector_len = @intCast(usize, tv.ty.arrayLen(mod));
3423 assert(vector_len == bytes.len or vector_len + 1 == bytes.len);
3424
3425 const elem_ty = tv.ty.childType(mod);
3426 const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len);
3427 defer dg.gpa.free(llvm_elems);
3428 for (llvm_elems, 0..) |*elem, i| {
3429 elem.* = try dg.lowerValue(.{
3430 .ty = elem_ty,
3431 .val = try mod.intValue(elem_ty, bytes[i]),
3432 });
3433 }
3434 return llvm.constVector(
3435 llvm_elems.ptr,
3436 @intCast(c_uint, llvm_elems.len),
3437 );
3438 },
3439 .str_lit => {
3440 // Note, sentinel is not stored
3441 const str_lit = tv.val.castTag(.str_lit).?.data;
3442 const bytes = dg.module.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
3443 const vector_len = @intCast(usize, tv.ty.arrayLen(mod));
3444 assert(vector_len == bytes.len);
3445
3446 const elem_ty = tv.ty.childType(mod);
3447 const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len);
3448 defer dg.gpa.free(llvm_elems);
3449 for (llvm_elems, 0..) |*elem, i| {
3450 elem.* = try dg.lowerValue(.{
3451 .ty = elem_ty,
3452 .val = try mod.intValue(elem_ty, bytes[i]),
3453 });
3454 }
3455 return llvm.constVector(
3456 llvm_elems.ptr,
3457 @intCast(c_uint, llvm_elems.len),
3458 );
3459 },
3460 else => unreachable,
3461 },
3462 .Float,
3463 .Union,
3464 .Optional,
3465 .ErrorUnion,
3466 .ErrorSet,
3467 .Int,
3468 .Enum,
3469 .Bool,
3470 .Pointer,
3471 => unreachable, // handled below
3472 .Frame,
3473 .AnyFrame,
3474 => return dg.todo("implement const of type '{}'", .{tv.ty.fmtDebug()}),
3475 .Type,
3476 .Void,
3477 .NoReturn,
3478 .ComptimeFloat,
3479 .ComptimeInt,
3480 .Undefined,
3481 .Null,
3482 .Opaque,
3483 .EnumLiteral,
3484 .Fn,
3485 => unreachable, // comptime-only types
3486 };
3487
3488 switch (mod.intern_pool.indexToKey(tv.val.ip_index)) {
3489 .int_type,3212 .int_type,
3490 .ptr_type,3213 .ptr_type,
3491 .array_type,3214 .array_type,
...@@ -3553,7 +3276,7 @@ pub const DeclGen = struct {...@@ -3553,7 +3276,7 @@ pub const DeclGen = struct {
3553 const llvm_payload_value = try dg.lowerValue(.{3276 const llvm_payload_value = try dg.lowerValue(.{
3554 .ty = payload_type,3277 .ty = payload_type,
3555 .val = switch (error_union.val) {3278 .val = switch (error_union.val) {
3556 .err_name => try mod.intern(.{ .undef = payload_type.ip_index }),3279 .err_name => try mod.intern(.{ .undef = payload_type.toIntern() }),
3557 .payload => |payload| payload,3280 .payload => |payload| payload,
3558 }.toValue(),3281 }.toValue(),
3559 });3282 });
...@@ -3700,7 +3423,7 @@ pub const DeclGen = struct {...@@ -3700,7 +3423,7 @@ pub const DeclGen = struct {
3700 fields_buf[0] = try dg.lowerValue(.{3423 fields_buf[0] = try dg.lowerValue(.{
3701 .ty = payload_ty,3424 .ty = payload_ty,
3702 .val = switch (opt.val) {3425 .val = switch (opt.val) {
3703 .none => try mod.intern(.{ .undef = payload_ty.ip_index }),3426 .none => try mod.intern(.{ .undef = payload_ty.toIntern() }),
3704 else => |payload| payload,3427 else => |payload| payload,
3705 }.toValue(),3428 }.toValue(),
3706 });3429 });
...@@ -3711,7 +3434,7 @@ pub const DeclGen = struct {...@@ -3711,7 +3434,7 @@ pub const DeclGen = struct {
3711 }3434 }
3712 return dg.context.constStruct(&fields_buf, llvm_field_count, .False);3435 return dg.context.constStruct(&fields_buf, llvm_field_count, .False);
3713 },3436 },
3714 .aggregate => |aggregate| switch (mod.intern_pool.indexToKey(tv.ty.ip_index)) {3437 .aggregate => |aggregate| switch (mod.intern_pool.indexToKey(tv.ty.toIntern())) {
3715 .array_type => switch (aggregate.storage) {3438 .array_type => switch (aggregate.storage) {
3716 .bytes => |bytes| return dg.context.constString(3439 .bytes => |bytes| return dg.context.constString(
3717 bytes.ptr,3440 bytes.ptr,
...@@ -3802,7 +3525,7 @@ pub const DeclGen = struct {...@@ -3802,7 +3525,7 @@ pub const DeclGen = struct {
3802 const llvm_struct_ty = try dg.lowerType(tv.ty);3525 const llvm_struct_ty = try dg.lowerType(tv.ty);
3803 const gpa = dg.gpa;3526 const gpa = dg.gpa;
38043527
3805 const struct_type = switch (mod.intern_pool.indexToKey(tv.ty.ip_index)) {3528 const struct_type = switch (mod.intern_pool.indexToKey(tv.ty.toIntern())) {
3806 .anon_struct_type => |tuple| {3529 .anon_struct_type => |tuple| {
3807 var llvm_fields: std.ArrayListUnmanaged(*llvm.Value) = .{};3530 var llvm_fields: std.ArrayListUnmanaged(*llvm.Value) = .{};
3808 defer llvm_fields.deinit(gpa);3531 defer llvm_fields.deinit(gpa);
...@@ -3967,9 +3690,9 @@ pub const DeclGen = struct {...@@ -3967,9 +3690,9 @@ pub const DeclGen = struct {
3967 },3690 },
3968 .un => {3691 .un => {
3969 const llvm_union_ty = try dg.lowerType(tv.ty);3692 const llvm_union_ty = try dg.lowerType(tv.ty);
3970 const tag_and_val: Value.Payload.Union.Data = switch (tv.val.ip_index) {3693 const tag_and_val: Value.Payload.Union.Data = switch (tv.val.toIntern()) {
3971 .none => tv.val.castTag(.@"union").?.data,3694 .none => tv.val.castTag(.@"union").?.data,
3972 else => switch (mod.intern_pool.indexToKey(tv.val.ip_index)) {3695 else => switch (mod.intern_pool.indexToKey(tv.val.toIntern())) {
3973 .un => |un| .{ .tag = un.tag.toValue(), .val = un.val.toValue() },3696 .un => |un| .{ .tag = un.tag.toValue(), .val = un.val.toValue() },
3974 else => unreachable,3697 else => unreachable,
3975 },3698 },
...@@ -4107,7 +3830,7 @@ pub const DeclGen = struct {...@@ -4107,7 +3830,7 @@ pub const DeclGen = struct {
4107 fn lowerParentPtr(dg: *DeclGen, ptr_val: Value, byte_aligned: bool) Error!*llvm.Value {3830 fn lowerParentPtr(dg: *DeclGen, ptr_val: Value, byte_aligned: bool) Error!*llvm.Value {
4108 const mod = dg.module;3831 const mod = dg.module;
4109 const target = mod.getTarget();3832 const target = mod.getTarget();
4110 return switch (mod.intern_pool.indexToKey(ptr_val.ip_index)) {3833 return switch (mod.intern_pool.indexToKey(ptr_val.toIntern())) {
4111 .int => |int| dg.lowerIntAsPtr(int),3834 .int => |int| dg.lowerIntAsPtr(int),
4112 .ptr => |ptr| switch (ptr.addr) {3835 .ptr => |ptr| switch (ptr.addr) {
4113 .decl => |decl| dg.lowerParentPtrDecl(ptr_val, decl),3836 .decl => |decl| dg.lowerParentPtrDecl(ptr_val, decl),
...@@ -4799,7 +4522,6 @@ pub const FuncGen = struct {...@@ -4799,7 +4522,6 @@ pub const FuncGen = struct {
4799 .vector_store_elem => try self.airVectorStoreElem(inst),4522 .vector_store_elem => try self.airVectorStoreElem(inst),
48004523
4801 .constant => unreachable,4524 .constant => unreachable,
4802 .const_ty => unreachable,
4803 .interned => unreachable,4525 .interned => unreachable,
48044526
4805 .unreach => self.airUnreach(inst),4527 .unreach => self.airUnreach(inst),
...@@ -6108,7 +5830,7 @@ pub const FuncGen = struct {...@@ -6108,7 +5830,7 @@ pub const FuncGen = struct {
6108 const struct_llvm_ty = try self.dg.lowerType(struct_ty);5830 const struct_llvm_ty = try self.dg.lowerType(struct_ty);
6109 const field_ptr = self.builder.buildStructGEP(struct_llvm_ty, struct_llvm_val, llvm_field.index, "");5831 const field_ptr = self.builder.buildStructGEP(struct_llvm_ty, struct_llvm_val, llvm_field.index, "");
6110 const field_ptr_ty = try mod.ptrType(.{5832 const field_ptr_ty = try mod.ptrType(.{
6111 .elem_type = llvm_field.ty.ip_index,5833 .elem_type = llvm_field.ty.toIntern(),
6112 .alignment = InternPool.Alignment.fromNonzeroByteUnits(llvm_field.alignment),5834 .alignment = InternPool.Alignment.fromNonzeroByteUnits(llvm_field.alignment),
6113 });5835 });
6114 if (isByRef(field_ty, mod)) {5836 if (isByRef(field_ty, mod)) {
...@@ -6984,7 +6706,7 @@ pub const FuncGen = struct {...@@ -6984,7 +6706,7 @@ pub const FuncGen = struct {
6984 const struct_llvm_ty = try self.dg.lowerType(struct_ty);6706 const struct_llvm_ty = try self.dg.lowerType(struct_ty);
6985 const field_ptr = self.builder.buildStructGEP(struct_llvm_ty, self.err_ret_trace.?, llvm_field.index, "");6707 const field_ptr = self.builder.buildStructGEP(struct_llvm_ty, self.err_ret_trace.?, llvm_field.index, "");
6986 const field_ptr_ty = try mod.ptrType(.{6708 const field_ptr_ty = try mod.ptrType(.{
6987 .elem_type = llvm_field.ty.ip_index,6709 .elem_type = llvm_field.ty.toIntern(),
6988 .alignment = InternPool.Alignment.fromNonzeroByteUnits(llvm_field.alignment),6710 .alignment = InternPool.Alignment.fromNonzeroByteUnits(llvm_field.alignment),
6989 });6711 });
6990 return self.load(field_ptr, field_ptr_ty);6712 return self.load(field_ptr, field_ptr_ty);
...@@ -8915,7 +8637,7 @@ pub const FuncGen = struct {...@@ -8915,7 +8637,7 @@ pub const FuncGen = struct {
89158637
8916 fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !*llvm.Value {8638 fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !*llvm.Value {
8917 const mod = self.dg.module;8639 const mod = self.dg.module;
8918 const enum_type = mod.intern_pool.indexToKey(enum_ty.ip_index).enum_type;8640 const enum_type = mod.intern_pool.indexToKey(enum_ty.toIntern()).enum_type;
89198641
8920 // TODO: detect when the type changes and re-emit this function.8642 // TODO: detect when the type changes and re-emit this function.
8921 const gop = try self.dg.object.named_enum_map.getOrPut(self.dg.gpa, enum_type.decl);8643 const gop = try self.dg.object.named_enum_map.getOrPut(self.dg.gpa, enum_type.decl);
...@@ -8988,7 +8710,7 @@ pub const FuncGen = struct {...@@ -8988,7 +8710,7 @@ pub const FuncGen = struct {
89888710
8989 fn getEnumTagNameFunction(self: *FuncGen, enum_ty: Type) !*llvm.Value {8711 fn getEnumTagNameFunction(self: *FuncGen, enum_ty: Type) !*llvm.Value {
8990 const mod = self.dg.module;8712 const mod = self.dg.module;
8991 const enum_type = mod.intern_pool.indexToKey(enum_ty.ip_index).enum_type;8713 const enum_type = mod.intern_pool.indexToKey(enum_ty.toIntern()).enum_type;
89928714
8993 // TODO: detect when the type changes and re-emit this function.8715 // TODO: detect when the type changes and re-emit this function.
8994 const gop = try self.dg.object.decl_map.getOrPut(self.dg.gpa, enum_type.decl);8716 const gop = try self.dg.object.decl_map.getOrPut(self.dg.gpa, enum_type.decl);
...@@ -10529,7 +10251,7 @@ fn llvmField(ty: Type, field_index: usize, mod: *Module) ?LlvmField {...@@ -10529,7 +10251,7 @@ fn llvmField(ty: Type, field_index: usize, mod: *Module) ?LlvmField {
10529 var offset: u64 = 0;10251 var offset: u64 = 0;
10530 var big_align: u32 = 0;10252 var big_align: u32 = 0;
1053110253
10532 const struct_type = switch (mod.intern_pool.indexToKey(ty.ip_index)) {10254 const struct_type = switch (mod.intern_pool.indexToKey(ty.toIntern())) {
10533 .anon_struct_type => |tuple| {10255 .anon_struct_type => |tuple| {
10534 var llvm_field_index: c_uint = 0;10256 var llvm_field_index: c_uint = 0;
10535 for (tuple.types, tuple.values, 0..) |field_ty, field_val, i| {10257 for (tuple.types, tuple.values, 0..) |field_ty, field_val, i| {
...@@ -10927,7 +10649,7 @@ const ParamTypeIterator = struct {...@@ -10927,7 +10649,7 @@ const ParamTypeIterator = struct {
10927 .riscv32, .riscv64 => {10649 .riscv32, .riscv64 => {
10928 it.zig_index += 1;10650 it.zig_index += 1;
10929 it.llvm_index += 1;10651 it.llvm_index += 1;
10930 if (ty.ip_index == .f16_type) {10652 if (ty.toIntern() == .f16_type) {
10931 return .as_u16;10653 return .as_u16;
10932 }10654 }
10933 switch (riscv_c_abi.classifyType(ty, mod)) {10655 switch (riscv_c_abi.classifyType(ty, mod)) {
...@@ -11146,7 +10868,7 @@ fn isByRef(ty: Type, mod: *Module) bool {...@@ -11146,7 +10868,7 @@ fn isByRef(ty: Type, mod: *Module) bool {
11146 .Struct => {10868 .Struct => {
11147 // Packed structs are represented to LLVM as integers.10869 // Packed structs are represented to LLVM as integers.
11148 if (ty.containerLayout(mod) == .Packed) return false;10870 if (ty.containerLayout(mod) == .Packed) return false;
11149 const struct_type = switch (mod.intern_pool.indexToKey(ty.ip_index)) {10871 const struct_type = switch (mod.intern_pool.indexToKey(ty.toIntern())) {
11150 .anon_struct_type => |tuple| {10872 .anon_struct_type => |tuple| {
11151 var count: usize = 0;10873 var count: usize = 0;
11152 for (tuple.types, tuple.values) |field_ty, field_val| {10874 for (tuple.types, tuple.values) |field_ty, field_val| {
...@@ -11261,7 +10983,7 @@ fn backendSupportsF128(target: std.Target) bool {...@@ -11261,7 +10983,7 @@ fn backendSupportsF128(target: std.Target) bool {
11261/// LLVM does not support all relevant intrinsics for all targets, so we10983/// LLVM does not support all relevant intrinsics for all targets, so we
11262/// may need to manually generate a libc call10984/// may need to manually generate a libc call
11263fn intrinsicsAllowed(scalar_ty: Type, target: std.Target) bool {10985fn intrinsicsAllowed(scalar_ty: Type, target: std.Target) bool {
11264 return switch (scalar_ty.ip_index) {10986 return switch (scalar_ty.toIntern()) {
11265 .f16_type => backendSupportsF16(target),10987 .f16_type => backendSupportsF16(target),
11266 .f80_type => (target.c_type_bit_size(.longdouble) == 80) and backendSupportsF80(target),10988 .f80_type => (target.c_type_bit_size(.longdouble) == 80) and backendSupportsF80(target),
11267 .f128_type => (target.c_type_bit_size(.longdouble) == 128) and backendSupportsF128(target),10989 .f128_type => (target.c_type_bit_size(.longdouble) == 128) and backendSupportsF128(target),
src/codegen/spirv.zig+2-71
...@@ -616,7 +616,7 @@ pub const DeclGen = struct {...@@ -616,7 +616,7 @@ pub const DeclGen = struct {
616 const mod = dg.module;616 const mod = dg.module;
617617
618 var val = arg_val;618 var val = arg_val;
619 switch (mod.intern_pool.indexToKey(val.ip_index)) {619 switch (mod.intern_pool.indexToKey(val.toIntern())) {
620 .runtime_value => |rt| val = rt.val.toValue(),620 .runtime_value => |rt| val = rt.val.toValue(),
621 else => {},621 else => {},
622 }622 }
...@@ -626,75 +626,7 @@ pub const DeclGen = struct {...@@ -626,75 +626,7 @@ pub const DeclGen = struct {
626 return try self.addUndef(size);626 return try self.addUndef(size);
627 }627 }
628628
629 if (val.ip_index == .none) switch (ty.zigTypeTag(mod)) {629 switch (mod.intern_pool.indexToKey(val.toIntern())) {
630 .Array => switch (val.tag()) {
631 .str_lit => {
632 const str_lit = val.castTag(.str_lit).?.data;
633 const bytes = dg.module.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
634 try self.addBytes(bytes);
635 if (ty.sentinel(mod)) |sentinel| {
636 try self.addByte(@intCast(u8, sentinel.toUnsignedInt(mod)));
637 }
638 },
639 .bytes => {
640 const bytes = val.castTag(.bytes).?.data;
641 try self.addBytes(bytes);
642 },
643 else => |tag| return dg.todo("indirect array constant with tag {s}", .{@tagName(tag)}),
644 },
645 .Struct => {
646 if (ty.isSimpleTupleOrAnonStruct(mod)) {
647 unreachable; // TODO
648 } else {
649 const struct_ty = mod.typeToStruct(ty).?;
650
651 if (struct_ty.layout == .Packed) {
652 return dg.todo("packed struct constants", .{});
653 }
654
655 const struct_begin = self.size;
656 const field_vals = val.castTag(.aggregate).?.data;
657 for (struct_ty.fields.values(), 0..) |field, i| {
658 if (field.is_comptime or !field.ty.hasRuntimeBits(mod)) continue;
659 try self.lower(field.ty, field_vals[i]);
660
661 // Add padding if required.
662 // TODO: Add to type generation as well?
663 const unpadded_field_end = self.size - struct_begin;
664 const padded_field_end = ty.structFieldOffset(i + 1, mod);
665 const padding = padded_field_end - unpadded_field_end;
666 try self.addUndef(padding);
667 }
668 }
669 },
670 .Vector,
671 .Frame,
672 .AnyFrame,
673 => return dg.todo("indirect constant of type {}", .{ty.fmt(mod)}),
674 .Float,
675 .Union,
676 .Optional,
677 .ErrorUnion,
678 .ErrorSet,
679 .Int,
680 .Enum,
681 .Bool,
682 .Pointer,
683 => unreachable, // handled below
684 .Type,
685 .Void,
686 .NoReturn,
687 .ComptimeFloat,
688 .ComptimeInt,
689 .Undefined,
690 .Null,
691 .Opaque,
692 .EnumLiteral,
693 .Fn,
694 => unreachable, // comptime-only types
695 };
696
697 switch (mod.intern_pool.indexToKey(val.ip_index)) {
698 .int_type,630 .int_type,
699 .ptr_type,631 .ptr_type,
700 .array_type,632 .array_type,
...@@ -1876,7 +1808,6 @@ pub const DeclGen = struct {...@@ -1876,7 +1808,6 @@ pub const DeclGen = struct {
1876 .breakpoint => return,1808 .breakpoint => return,
1877 .cond_br => return self.airCondBr(inst),1809 .cond_br => return self.airCondBr(inst),
1878 .constant => unreachable,1810 .constant => unreachable,
1879 .const_ty => unreachable,
1880 .dbg_stmt => return self.airDbgStmt(inst),1811 .dbg_stmt => return self.airDbgStmt(inst),
1881 .loop => return self.airLoop(inst),1812 .loop => return self.airLoop(inst),
1882 .ret => return self.airRet(inst),1813 .ret => return self.airRet(inst),
src/print_air.zig+1-2
...@@ -95,7 +95,7 @@ const Writer = struct {...@@ -95,7 +95,7 @@ const Writer = struct {
95 for (w.air.instructions.items(.tag), 0..) |tag, i| {95 for (w.air.instructions.items(.tag), 0..) |tag, i| {
96 const inst = @intCast(Air.Inst.Index, i);96 const inst = @intCast(Air.Inst.Index, i);
97 switch (tag) {97 switch (tag) {
98 .constant, .const_ty, .interned => {98 .constant, .interned => {
99 try w.writeInst(s, inst);99 try w.writeInst(s, inst);
100 try s.writeByte('\n');100 try s.writeByte('\n');
101 },101 },
...@@ -226,7 +226,6 @@ const Writer = struct {...@@ -226,7 +226,6 @@ const Writer = struct {
226 .save_err_return_trace_index,226 .save_err_return_trace_index,
227 => try w.writeNoOp(s, inst),227 => try w.writeNoOp(s, inst),
228228
229 .const_ty,
230 .alloc,229 .alloc,
231 .ret_ptr,230 .ret_ptr,
232 .err_return_trace,231 .err_return_trace,
src/value.zig+540-439
...@@ -37,8 +37,9 @@ pub const Value = struct {...@@ -37,8 +37,9 @@ pub const Value = struct {
3737
38 /// A slice of u8 whose memory is managed externally.38 /// A slice of u8 whose memory is managed externally.
39 bytes,39 bytes,
40 /// Similar to bytes however it stores an index relative to `Module.string_literal_bytes`.40 /// This value is repeated some number of times. The amount of times to repeat
41 str_lit,41 /// is stored externally.
42 repeated,
42 /// An instance of a struct, array, or vector.43 /// An instance of a struct, array, or vector.
43 /// Each element/field stored as a `Value`.44 /// Each element/field stored as a `Value`.
44 /// In the case of sentinel-terminated arrays, the sentinel value *is* stored,45 /// In the case of sentinel-terminated arrays, the sentinel value *is* stored,
...@@ -57,9 +58,9 @@ pub const Value = struct {...@@ -57,9 +58,9 @@ pub const Value = struct {
5758
58 pub fn Type(comptime t: Tag) type {59 pub fn Type(comptime t: Tag) type {
59 return switch (t) {60 return switch (t) {
60 .bytes => Payload.Bytes,61 .repeated => Payload.SubValue,
6162
62 .str_lit => Payload.StrLit,63 .bytes => Payload.Bytes,
6364
64 .inferred_alloc => Payload.InferredAlloc,65 .inferred_alloc => Payload.InferredAlloc,
65 .inferred_alloc_comptime => Payload.InferredAllocComptime,66 .inferred_alloc_comptime => Payload.InferredAllocComptime,
...@@ -171,7 +172,18 @@ pub const Value = struct {...@@ -171,7 +172,18 @@ pub const Value = struct {
171 .legacy = .{ .ptr_otherwise = &new_payload.base },172 .legacy = .{ .ptr_otherwise = &new_payload.base },
172 };173 };
173 },174 },
174 .str_lit => return self.copyPayloadShallow(arena, Payload.StrLit),175 .repeated => {
176 const payload = self.cast(Payload.SubValue).?;
177 const new_payload = try arena.create(Payload.SubValue);
178 new_payload.* = .{
179 .base = payload.base,
180 .data = try payload.data.copy(arena),
181 };
182 return Value{
183 .ip_index = .none,
184 .legacy = .{ .ptr_otherwise = &new_payload.base },
185 };
186 },
175 .aggregate => {187 .aggregate => {
176 const payload = self.castTag(.aggregate).?;188 const payload = self.castTag(.aggregate).?;
177 const new_payload = try arena.create(Payload.Aggregate);189 const new_payload = try arena.create(Payload.Aggregate);
...@@ -187,7 +199,6 @@ pub const Value = struct {...@@ -187,7 +199,6 @@ pub const Value = struct {
187 .legacy = .{ .ptr_otherwise = &new_payload.base },199 .legacy = .{ .ptr_otherwise = &new_payload.base },
188 };200 };
189 },201 },
190
191 .@"union" => {202 .@"union" => {
192 const tag_and_val = self.castTag(.@"union").?.data;203 const tag_and_val = self.castTag(.@"union").?.data;
193 const new_payload = try arena.create(Payload.Union);204 const new_payload = try arena.create(Payload.Union);
...@@ -203,7 +214,6 @@ pub const Value = struct {...@@ -203,7 +214,6 @@ pub const Value = struct {
203 .legacy = .{ .ptr_otherwise = &new_payload.base },214 .legacy = .{ .ptr_otherwise = &new_payload.base },
204 };215 };
205 },216 },
206
207 .inferred_alloc => unreachable,217 .inferred_alloc => unreachable,
208 .inferred_alloc_comptime => unreachable,218 .inferred_alloc_comptime => unreachable,
209 }219 }
...@@ -237,7 +247,7 @@ pub const Value = struct {...@@ -237,7 +247,7 @@ pub const Value = struct {
237 ) !void {247 ) !void {
238 comptime assert(fmt.len == 0);248 comptime assert(fmt.len == 0);
239 if (start_val.ip_index != .none) {249 if (start_val.ip_index != .none) {
240 try out_stream.print("(interned: {})", .{start_val.ip_index});250 try out_stream.print("(interned: {})", .{start_val.toIntern()});
241 return;251 return;
242 }252 }
243 var val = start_val;253 var val = start_val;
...@@ -249,11 +259,9 @@ pub const Value = struct {...@@ -249,11 +259,9 @@ pub const Value = struct {
249 return out_stream.writeAll("(union value)");259 return out_stream.writeAll("(union value)");
250 },260 },
251 .bytes => return out_stream.print("\"{}\"", .{std.zig.fmtEscapes(val.castTag(.bytes).?.data)}),261 .bytes => return out_stream.print("\"{}\"", .{std.zig.fmtEscapes(val.castTag(.bytes).?.data)}),
252 .str_lit => {262 .repeated => {
253 const str_lit = val.castTag(.str_lit).?.data;263 try out_stream.writeAll("(repeated) ");
254 return out_stream.print("(.str_lit index={d} len={d})", .{264 val = val.castTag(.repeated).?.data;
255 str_lit.index, str_lit.len,
256 });
257 },265 },
258 .inferred_alloc => return out_stream.writeAll("(inferred allocation value)"),266 .inferred_alloc => return out_stream.writeAll("(inferred allocation value)"),
259 .inferred_alloc_comptime => return out_stream.writeAll("(inferred comptime allocation value)"),267 .inferred_alloc_comptime => return out_stream.writeAll("(inferred comptime allocation value)"),
...@@ -274,40 +282,24 @@ pub const Value = struct {...@@ -274,40 +282,24 @@ pub const Value = struct {
274 /// Asserts that the value is representable as an array of bytes.282 /// Asserts that the value is representable as an array of bytes.
275 /// Copies the value into a freshly allocated slice of memory, which is owned by the caller.283 /// Copies the value into a freshly allocated slice of memory, which is owned by the caller.
276 pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, mod: *Module) ![]u8 {284 pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, mod: *Module) ![]u8 {
277 switch (val.ip_index) {285 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
278 .none => switch (val.tag()) {286 .enum_literal => |enum_literal| allocator.dupe(u8, mod.intern_pool.stringToSlice(enum_literal)),
279 .bytes => {287 .ptr => |ptr| switch (ptr.len) {
280 const bytes = val.castTag(.bytes).?.data;288 .none => unreachable,
281 const adjusted_len = bytes.len - @boolToInt(ty.sentinel(mod) != null);289 else => arrayToAllocatedBytes(val, ptr.len.toValue().toUnsignedInt(mod), allocator, mod),
282 const adjusted_bytes = bytes[0..adjusted_len];
283 return allocator.dupe(u8, adjusted_bytes);
284 },
285 .str_lit => {
286 const str_lit = val.castTag(.str_lit).?.data;
287 const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
288 return allocator.dupe(u8, bytes);
289 },
290 else => return arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),
291 },290 },
292 else => return switch (mod.intern_pool.indexToKey(val.ip_index)) {291 .aggregate => |aggregate| switch (aggregate.storage) {
293 .enum_literal => |enum_literal| allocator.dupe(u8, mod.intern_pool.stringToSlice(enum_literal)),292 .bytes => |bytes| try allocator.dupe(u8, bytes),
294 .ptr => |ptr| switch (ptr.len) {293 .elems => arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),
295 .none => unreachable,294 .repeated_elem => |elem| {
296 else => arrayToAllocatedBytes(val, ptr.len.toValue().toUnsignedInt(mod), allocator, mod),295 const byte = @intCast(u8, elem.toValue().toUnsignedInt(mod));
297 },296 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen(mod)));
298 .aggregate => |aggregate| switch (aggregate.storage) {297 @memset(result, byte);
299 .bytes => |bytes| try allocator.dupe(u8, bytes),298 return result;
300 .elems => arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),
301 .repeated_elem => |elem| {
302 const byte = @intCast(u8, elem.toValue().toUnsignedInt(mod));
303 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen(mod)));
304 @memset(result, byte);
305 return result;
306 },
307 },299 },
308 else => unreachable,
309 },300 },
310 }301 else => unreachable,
302 };
311 }303 }
312304
313 fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Module) ![]u8 {305 fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Module) ![]u8 {
...@@ -320,13 +312,13 @@ pub const Value = struct {...@@ -320,13 +312,13 @@ pub const Value = struct {
320 }312 }
321313
322 pub fn intern(val: Value, ty: Type, mod: *Module) Allocator.Error!InternPool.Index {314 pub fn intern(val: Value, ty: Type, mod: *Module) Allocator.Error!InternPool.Index {
323 if (val.ip_index != .none) return mod.intern_pool.getCoerced(mod.gpa, val.ip_index, ty.ip_index);315 if (val.ip_index != .none) return mod.intern_pool.getCoerced(mod.gpa, val.toIntern(), ty.toIntern());
324 switch (val.tag()) {316 switch (val.tag()) {
325 .aggregate => {317 .aggregate => {
326 const old_elems = val.castTag(.aggregate).?.data;318 const old_elems = val.castTag(.aggregate).?.data;
327 const new_elems = try mod.gpa.alloc(InternPool.Index, old_elems.len);319 const new_elems = try mod.gpa.alloc(InternPool.Index, old_elems.len);
328 defer mod.gpa.free(new_elems);320 defer mod.gpa.free(new_elems);
329 const ty_key = mod.intern_pool.indexToKey(ty.ip_index);321 const ty_key = mod.intern_pool.indexToKey(ty.toIntern());
330 for (new_elems, old_elems, 0..) |*new_elem, old_elem, field_i|322 for (new_elems, old_elems, 0..) |*new_elem, old_elem, field_i|
331 new_elem.* = try old_elem.intern(switch (ty_key) {323 new_elem.* = try old_elem.intern(switch (ty_key) {
332 .struct_type => ty.structFieldType(field_i, mod),324 .struct_type => ty.structFieldType(field_i, mod),
...@@ -335,14 +327,14 @@ pub const Value = struct {...@@ -335,14 +327,14 @@ pub const Value = struct {
335 else => unreachable,327 else => unreachable,
336 }, mod);328 }, mod);
337 return mod.intern(.{ .aggregate = .{329 return mod.intern(.{ .aggregate = .{
338 .ty = ty.ip_index,330 .ty = ty.toIntern(),
339 .storage = .{ .elems = new_elems },331 .storage = .{ .elems = new_elems },
340 } });332 } });
341 },333 },
342 .@"union" => {334 .@"union" => {
343 const pl = val.castTag(.@"union").?.data;335 const pl = val.castTag(.@"union").?.data;
344 return mod.intern(.{ .un = .{336 return mod.intern(.{ .un = .{
345 .ty = ty.ip_index,337 .ty = ty.toIntern(),
346 .tag = try pl.tag.intern(ty.unionTagTypeHypothetical(mod), mod),338 .tag = try pl.tag.intern(ty.unionTagTypeHypothetical(mod), mod),
347 .val = try pl.val.intern(ty.unionFieldType(pl.tag, mod), mod),339 .val = try pl.val.intern(ty.unionFieldType(pl.tag, mod), mod),
348 } });340 } });
...@@ -353,13 +345,15 @@ pub const Value = struct {...@@ -353,13 +345,15 @@ pub const Value = struct {
353345
354 pub fn unintern(val: Value, arena: Allocator, mod: *Module) Allocator.Error!Value {346 pub fn unintern(val: Value, arena: Allocator, mod: *Module) Allocator.Error!Value {
355 if (val.ip_index == .none) return val;347 if (val.ip_index == .none) return val;
356 switch (mod.intern_pool.indexToKey(val.ip_index)) {348 switch (mod.intern_pool.indexToKey(val.toIntern())) {
357 .aggregate => |aggregate| switch (aggregate.storage) {349 .aggregate => |aggregate| switch (aggregate.storage) {
350 .bytes => |bytes| return Tag.bytes.create(arena, try arena.dupe(u8, bytes)),
358 .elems => |old_elems| {351 .elems => |old_elems| {
359 const new_elems = try arena.alloc(Value, old_elems.len);352 const new_elems = try arena.alloc(Value, old_elems.len);
360 for (new_elems, old_elems) |*new_elem, old_elem| new_elem.* = old_elem.toValue();353 for (new_elems, old_elems) |*new_elem, old_elem| new_elem.* = old_elem.toValue();
361 return Tag.aggregate.create(arena, new_elems);354 return Tag.aggregate.create(arena, new_elems);
362 },355 },
356 .repeated_elem => |elem| return Tag.repeated.create(arena, elem.toValue()),
363 },357 },
364 else => return val,358 else => return val,
365 }359 }
...@@ -372,40 +366,38 @@ pub const Value = struct {...@@ -372,40 +366,38 @@ pub const Value = struct {
372366
373 /// Asserts that the value is representable as a type.367 /// Asserts that the value is representable as a type.
374 pub fn toType(self: Value) Type {368 pub fn toType(self: Value) Type {
375 return self.ip_index.toType();369 return self.toIntern().toType();
376 }370 }
377371
378 pub fn enumToInt(val: Value, ty: Type, mod: *Module) Allocator.Error!Value {372 pub fn enumToInt(val: Value, ty: Type, mod: *Module) Allocator.Error!Value {
379 const ip = &mod.intern_pool;373 const ip = &mod.intern_pool;
380 switch (val.ip_index) {374 return switch (ip.indexToKey(ip.typeOf(val.toIntern()))) {
381 else => return switch (ip.indexToKey(ip.typeOf(val.ip_index))) {375 // Assume it is already an integer and return it directly.
382 // Assume it is already an integer and return it directly.376 .simple_type, .int_type => val,
383 .simple_type, .int_type => val,377 .enum_literal => |enum_literal| {
384 .enum_literal => |enum_literal| {378 const field_index = ty.enumFieldIndex(ip.stringToSlice(enum_literal), mod).?;
385 const field_index = ty.enumFieldIndex(ip.stringToSlice(enum_literal), mod).?;379 return switch (ip.indexToKey(ty.toIntern())) {
386 return switch (ip.indexToKey(ty.ip_index)) {380 // Assume it is already an integer and return it directly.
387 // Assume it is already an integer and return it directly.381 .simple_type, .int_type => val,
388 .simple_type, .int_type => val,382 .enum_type => |enum_type| if (enum_type.values.len != 0)
389 .enum_type => |enum_type| if (enum_type.values.len != 0)383 enum_type.values[field_index].toValue()
390 enum_type.values[field_index].toValue()384 else // Field index and integer values are the same.
391 else // Field index and integer values are the same.385 mod.intValue(enum_type.tag_ty.toType(), field_index),
392 mod.intValue(enum_type.tag_ty.toType(), field_index),386 else => unreachable,
393 else => unreachable,387 };
394 };
395 },
396 .enum_type => |enum_type| (try ip.getCoerced(
397 mod.gpa,
398 val.ip_index,
399 enum_type.tag_ty,
400 )).toValue(),
401 else => unreachable,
402 },388 },
403 }389 .enum_type => |enum_type| (try ip.getCoerced(
390 mod.gpa,
391 val.toIntern(),
392 enum_type.tag_ty,
393 )).toValue(),
394 else => unreachable,
395 };
404 }396 }
405397
406 pub fn tagName(val: Value, mod: *Module) []const u8 {398 pub fn tagName(val: Value, mod: *Module) []const u8 {
407 const ip = &mod.intern_pool;399 const ip = &mod.intern_pool;
408 const enum_tag = switch (ip.indexToKey(val.ip_index)) {400 const enum_tag = switch (ip.indexToKey(val.toIntern())) {
409 .un => |un| ip.indexToKey(un.tag).enum_tag,401 .un => |un| ip.indexToKey(un.tag).enum_tag,
410 .enum_tag => |x| x,402 .enum_tag => |x| x,
411 .enum_literal => |name| return ip.stringToSlice(name),403 .enum_literal => |name| return ip.stringToSlice(name),
...@@ -413,7 +405,7 @@ pub const Value = struct {...@@ -413,7 +405,7 @@ pub const Value = struct {
413 };405 };
414 const enum_type = ip.indexToKey(enum_tag.ty).enum_type;406 const enum_type = ip.indexToKey(enum_tag.ty).enum_type;
415 const field_index = field_index: {407 const field_index = field_index: {
416 const field_index = enum_type.tagValueIndex(ip, val.ip_index).?;408 const field_index = enum_type.tagValueIndex(ip, val.toIntern()).?;
417 break :field_index @intCast(u32, field_index);409 break :field_index @intCast(u32, field_index);
418 };410 };
419 const field_name = enum_type.names[field_index];411 const field_name = enum_type.names[field_index];
...@@ -432,12 +424,12 @@ pub const Value = struct {...@@ -432,12 +424,12 @@ pub const Value = struct {
432 mod: *Module,424 mod: *Module,
433 opt_sema: ?*Sema,425 opt_sema: ?*Sema,
434 ) Module.CompileError!BigIntConst {426 ) Module.CompileError!BigIntConst {
435 return switch (val.ip_index) {427 return switch (val.toIntern()) {
436 .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(),428 .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(),
437 .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(),429 .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(),
438 .undef => unreachable,430 .undef => unreachable,
439 .null_value => BigIntMutable.init(&space.limbs, 0).toConst(),431 .null_value => BigIntMutable.init(&space.limbs, 0).toConst(),
440 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {432 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
441 .runtime_value => |runtime_value| runtime_value.val.toValue().toBigIntAdvanced(space, mod, opt_sema),433 .runtime_value => |runtime_value| runtime_value.val.toValue().toBigIntAdvanced(space, mod, opt_sema),
442 .int => |int| switch (int.storage) {434 .int => |int| switch (int.storage) {
443 .u64, .i64, .big_int => int.storage.toBigInt(space),435 .u64, .i64, .big_int => int.storage.toBigInt(space),
...@@ -475,18 +467,18 @@ pub const Value = struct {...@@ -475,18 +467,18 @@ pub const Value = struct {
475 }467 }
476468
477 pub fn getFunctionIndex(val: Value, mod: *Module) Module.Fn.OptionalIndex {469 pub fn getFunctionIndex(val: Value, mod: *Module) Module.Fn.OptionalIndex {
478 return if (val.ip_index != .none) mod.intern_pool.indexToFunc(val.ip_index) else .none;470 return if (val.ip_index != .none) mod.intern_pool.indexToFunc(val.toIntern()) else .none;
479 }471 }
480472
481 pub fn getExternFunc(val: Value, mod: *Module) ?InternPool.Key.ExternFunc {473 pub fn getExternFunc(val: Value, mod: *Module) ?InternPool.Key.ExternFunc {
482 return if (val.ip_index != .none) switch (mod.intern_pool.indexToKey(val.ip_index)) {474 return if (val.ip_index != .none) switch (mod.intern_pool.indexToKey(val.toIntern())) {
483 .extern_func => |extern_func| extern_func,475 .extern_func => |extern_func| extern_func,
484 else => null,476 else => null,
485 } else null;477 } else null;
486 }478 }
487479
488 pub fn getVariable(val: Value, mod: *Module) ?InternPool.Key.Variable {480 pub fn getVariable(val: Value, mod: *Module) ?InternPool.Key.Variable {
489 return if (val.ip_index != .none) switch (mod.intern_pool.indexToKey(val.ip_index)) {481 return if (val.ip_index != .none) switch (mod.intern_pool.indexToKey(val.toIntern())) {
490 .variable => |variable| variable,482 .variable => |variable| variable,
491 else => null,483 else => null,
492 } else null;484 } else null;
...@@ -501,11 +493,11 @@ pub const Value = struct {...@@ -501,11 +493,11 @@ pub const Value = struct {
501 /// If the value fits in a u64, return it, otherwise null.493 /// If the value fits in a u64, return it, otherwise null.
502 /// Asserts not undefined.494 /// Asserts not undefined.
503 pub fn getUnsignedIntAdvanced(val: Value, mod: *Module, opt_sema: ?*Sema) !?u64 {495 pub fn getUnsignedIntAdvanced(val: Value, mod: *Module, opt_sema: ?*Sema) !?u64 {
504 return switch (val.ip_index) {496 return switch (val.toIntern()) {
505 .bool_false => 0,497 .bool_false => 0,
506 .bool_true => 1,498 .bool_true => 1,
507 .undef => unreachable,499 .undef => unreachable,
508 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {500 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
509 .int => |int| switch (int.storage) {501 .int => |int| switch (int.storage) {
510 .big_int => |big_int| big_int.to(u64) catch null,502 .big_int => |big_int| big_int.to(u64) catch null,
511 .u64 => |x| x,503 .u64 => |x| x,
...@@ -531,11 +523,11 @@ pub const Value = struct {...@@ -531,11 +523,11 @@ pub const Value = struct {
531523
532 /// Asserts the value is an integer and it fits in a i64524 /// Asserts the value is an integer and it fits in a i64
533 pub fn toSignedInt(val: Value, mod: *Module) i64 {525 pub fn toSignedInt(val: Value, mod: *Module) i64 {
534 return switch (val.ip_index) {526 return switch (val.toIntern()) {
535 .bool_false => 0,527 .bool_false => 0,
536 .bool_true => 1,528 .bool_true => 1,
537 .undef => unreachable,529 .undef => unreachable,
538 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {530 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
539 .int => |int| switch (int.storage) {531 .int => |int| switch (int.storage) {
540 .big_int => |big_int| big_int.to(i64) catch unreachable,532 .big_int => |big_int| big_int.to(i64) catch unreachable,
541 .i64 => |x| x,533 .i64 => |x| x,
...@@ -549,7 +541,7 @@ pub const Value = struct {...@@ -549,7 +541,7 @@ pub const Value = struct {
549 }541 }
550542
551 pub fn toBool(val: Value, _: *const Module) bool {543 pub fn toBool(val: Value, _: *const Module) bool {
552 return switch (val.ip_index) {544 return switch (val.toIntern()) {
553 .bool_true => true,545 .bool_true => true,
554 .bool_false => false,546 .bool_false => false,
555 else => unreachable,547 else => unreachable,
...@@ -558,7 +550,7 @@ pub const Value = struct {...@@ -558,7 +550,7 @@ pub const Value = struct {
558550
559 fn isDeclRef(val: Value, mod: *Module) bool {551 fn isDeclRef(val: Value, mod: *Module) bool {
560 var check = val;552 var check = val;
561 while (true) switch (mod.intern_pool.indexToKey(check.ip_index)) {553 while (true) switch (mod.intern_pool.indexToKey(check.toIntern())) {
562 .ptr => |ptr| switch (ptr.addr) {554 .ptr => |ptr| switch (ptr.addr) {
563 .decl, .mut_decl, .comptime_field => return true,555 .decl, .mut_decl, .comptime_field => return true,
564 .eu_payload, .opt_payload => |index| check = index.toValue(),556 .eu_payload, .opt_payload => |index| check = index.toValue(),
...@@ -644,7 +636,7 @@ pub const Value = struct {...@@ -644,7 +636,7 @@ pub const Value = struct {
644 .ErrorSet => {636 .ErrorSet => {
645 // TODO revisit this when we have the concept of the error tag type637 // TODO revisit this when we have the concept of the error tag type
646 const Int = u16;638 const Int = u16;
647 const name = switch (mod.intern_pool.indexToKey(val.ip_index)) {639 const name = switch (mod.intern_pool.indexToKey(val.toIntern())) {
648 .err => |err| err.name,640 .err => |err| err.name,
649 .error_union => |error_union| error_union.val.err_name,641 .error_union => |error_union| error_union.val.err_name,
650 else => unreachable,642 else => unreachable,
...@@ -718,7 +710,7 @@ pub const Value = struct {...@@ -718,7 +710,7 @@ pub const Value = struct {
718710
719 if (abi_size == 0) return;711 if (abi_size == 0) return;
720 if (abi_size <= @sizeOf(u64)) {712 if (abi_size <= @sizeOf(u64)) {
721 const ip_key = mod.intern_pool.indexToKey(int_val.ip_index);713 const ip_key = mod.intern_pool.indexToKey(int_val.toIntern());
722 const int: u64 = switch (ip_key.int.storage) {714 const int: u64 = switch (ip_key.int.storage) {
723 .u64 => |x| x,715 .u64 => |x| x,
724 .i64 => |x| @bitCast(u64, x),716 .i64 => |x| @bitCast(u64, x),
...@@ -847,7 +839,7 @@ pub const Value = struct {...@@ -847,7 +839,7 @@ pub const Value = struct {
847 }839 }
848 },840 },
849 .Float => return (try mod.intern(.{ .float = .{841 .Float => return (try mod.intern(.{ .float = .{
850 .ty = ty.ip_index,842 .ty = ty.toIntern(),
851 .storage = switch (ty.floatBits(target)) {843 .storage = switch (ty.floatBits(target)) {
852 16 => .{ .f16 = @bitCast(f16, std.mem.readInt(u16, buffer[0..2], endian)) },844 16 => .{ .f16 = @bitCast(f16, std.mem.readInt(u16, buffer[0..2], endian)) },
853 32 => .{ .f32 = @bitCast(f32, std.mem.readInt(u32, buffer[0..4], endian)) },845 32 => .{ .f32 = @bitCast(f32, std.mem.readInt(u32, buffer[0..4], endian)) },
...@@ -860,13 +852,16 @@ pub const Value = struct {...@@ -860,13 +852,16 @@ pub const Value = struct {
860 .Array => {852 .Array => {
861 const elem_ty = ty.childType(mod);853 const elem_ty = ty.childType(mod);
862 const elem_size = elem_ty.abiSize(mod);854 const elem_size = elem_ty.abiSize(mod);
863 const elems = try arena.alloc(Value, @intCast(usize, ty.arrayLen(mod)));855 const elems = try arena.alloc(InternPool.Index, @intCast(usize, ty.arrayLen(mod)));
864 var offset: usize = 0;856 var offset: usize = 0;
865 for (elems) |*elem| {857 for (elems) |*elem| {
866 elem.* = try readFromMemory(elem_ty, mod, buffer[offset..], arena);858 elem.* = try (try readFromMemory(elem_ty, mod, buffer[offset..], arena)).intern(elem_ty, mod);
867 offset += @intCast(usize, elem_size);859 offset += @intCast(usize, elem_size);
868 }860 }
869 return Tag.aggregate.create(arena, elems);861 return (try mod.intern(.{ .aggregate = .{
862 .ty = ty.toIntern(),
863 .storage = .{ .elems = elems },
864 } })).toValue();
870 },865 },
871 .Vector => {866 .Vector => {
872 // We use byte_count instead of abi_size here, so that any padding bytes867 // We use byte_count instead of abi_size here, so that any padding bytes
...@@ -878,13 +873,16 @@ pub const Value = struct {...@@ -878,13 +873,16 @@ pub const Value = struct {
878 .Auto => unreachable, // Sema is supposed to have emitted a compile error already873 .Auto => unreachable, // Sema is supposed to have emitted a compile error already
879 .Extern => {874 .Extern => {
880 const fields = ty.structFields(mod).values();875 const fields = ty.structFields(mod).values();
881 const field_vals = try arena.alloc(Value, fields.len);876 const field_vals = try arena.alloc(InternPool.Index, fields.len);
882 for (fields, 0..) |field, i| {877 for (field_vals, fields, 0..) |*field_val, field, i| {
883 const off = @intCast(usize, ty.structFieldOffset(i, mod));878 const off = @intCast(usize, ty.structFieldOffset(i, mod));
884 const sz = @intCast(usize, ty.structFieldType(i, mod).abiSize(mod));879 const sz = @intCast(usize, field.ty.abiSize(mod));
885 field_vals[i] = try readFromMemory(field.ty, mod, buffer[off..(off + sz)], arena);880 field_val.* = try (try readFromMemory(field.ty, mod, buffer[off..(off + sz)], arena)).intern(field.ty, mod);
886 }881 }
887 return Tag.aggregate.create(arena, field_vals);882 return (try mod.intern(.{ .aggregate = .{
883 .ty = ty.toIntern(),
884 .storage = .{ .elems = field_vals },
885 } })).toValue();
888 },886 },
889 .Packed => {887 .Packed => {
890 const byte_count = (@intCast(usize, ty.bitSize(mod)) + 7) / 8;888 const byte_count = (@intCast(usize, ty.bitSize(mod)) + 7) / 8;
...@@ -897,7 +895,7 @@ pub const Value = struct {...@@ -897,7 +895,7 @@ pub const Value = struct {
897 const int = std.mem.readInt(Int, buffer[0..@sizeOf(Int)], endian);895 const int = std.mem.readInt(Int, buffer[0..@sizeOf(Int)], endian);
898 const name = mod.error_name_list.items[@intCast(usize, int)];896 const name = mod.error_name_list.items[@intCast(usize, int)];
899 return (try mod.intern(.{ .err = .{897 return (try mod.intern(.{ .err = .{
900 .ty = ty.ip_index,898 .ty = ty.toIntern(),
901 .name = mod.intern_pool.getString(name).unwrap().?,899 .name = mod.intern_pool.getString(name).unwrap().?,
902 } })).toValue();900 } })).toValue();
903 },901 },
...@@ -961,7 +959,7 @@ pub const Value = struct {...@@ -961,7 +959,7 @@ pub const Value = struct {
961 }959 }
962 },960 },
963 .Float => return (try mod.intern(.{ .float = .{961 .Float => return (try mod.intern(.{ .float = .{
964 .ty = ty.ip_index,962 .ty = ty.toIntern(),
965 .storage = switch (ty.floatBits(target)) {963 .storage = switch (ty.floatBits(target)) {
966 16 => .{ .f16 = @bitCast(f16, std.mem.readPackedInt(u16, buffer, bit_offset, endian)) },964 16 => .{ .f16 = @bitCast(f16, std.mem.readPackedInt(u16, buffer, bit_offset, endian)) },
967 32 => .{ .f32 = @bitCast(f32, std.mem.readPackedInt(u32, buffer, bit_offset, endian)) },965 32 => .{ .f32 = @bitCast(f32, std.mem.readPackedInt(u32, buffer, bit_offset, endian)) },
...@@ -973,17 +971,20 @@ pub const Value = struct {...@@ -973,17 +971,20 @@ pub const Value = struct {
973 } })).toValue(),971 } })).toValue(),
974 .Vector => {972 .Vector => {
975 const elem_ty = ty.childType(mod);973 const elem_ty = ty.childType(mod);
976 const elems = try arena.alloc(Value, @intCast(usize, ty.arrayLen(mod)));974 const elems = try arena.alloc(InternPool.Index, @intCast(usize, ty.arrayLen(mod)));
977975
978 var bits: u16 = 0;976 var bits: u16 = 0;
979 const elem_bit_size = @intCast(u16, elem_ty.bitSize(mod));977 const elem_bit_size = @intCast(u16, elem_ty.bitSize(mod));
980 for (elems, 0..) |_, i| {978 for (elems, 0..) |_, i| {
981 // On big-endian systems, LLVM reverses the element order of vectors by default979 // On big-endian systems, LLVM reverses the element order of vectors by default
982 const tgt_elem_i = if (endian == .Big) elems.len - i - 1 else i;980 const tgt_elem_i = if (endian == .Big) elems.len - i - 1 else i;
983 elems[tgt_elem_i] = try readFromPackedMemory(elem_ty, mod, buffer, bit_offset + bits, arena);981 elems[tgt_elem_i] = try (try readFromPackedMemory(elem_ty, mod, buffer, bit_offset + bits, arena)).intern(elem_ty, mod);
984 bits += elem_bit_size;982 bits += elem_bit_size;
985 }983 }
986 return Tag.aggregate.create(arena, elems);984 return (try mod.intern(.{ .aggregate = .{
985 .ty = ty.toIntern(),
986 .storage = .{ .elems = elems },
987 } })).toValue();
987 },988 },
988 .Struct => switch (ty.containerLayout(mod)) {989 .Struct => switch (ty.containerLayout(mod)) {
989 .Auto => unreachable, // Sema is supposed to have emitted a compile error already990 .Auto => unreachable, // Sema is supposed to have emitted a compile error already
...@@ -991,13 +992,16 @@ pub const Value = struct {...@@ -991,13 +992,16 @@ pub const Value = struct {
991 .Packed => {992 .Packed => {
992 var bits: u16 = 0;993 var bits: u16 = 0;
993 const fields = ty.structFields(mod).values();994 const fields = ty.structFields(mod).values();
994 const field_vals = try arena.alloc(Value, fields.len);995 const field_vals = try arena.alloc(InternPool.Index, fields.len);
995 for (fields, 0..) |field, i| {996 for (fields, 0..) |field, i| {
996 const field_bits = @intCast(u16, field.ty.bitSize(mod));997 const field_bits = @intCast(u16, field.ty.bitSize(mod));
997 field_vals[i] = try readFromPackedMemory(field.ty, mod, buffer, bit_offset + bits, arena);998 field_vals[i] = try (try readFromPackedMemory(field.ty, mod, buffer, bit_offset + bits, arena)).intern(field.ty, mod);
998 bits += field_bits;999 bits += field_bits;
999 }1000 }
1000 return Tag.aggregate.create(arena, field_vals);1001 return (try mod.intern(.{ .aggregate = .{
1002 .ty = ty.toIntern(),
1003 .storage = .{ .elems = field_vals },
1004 } })).toValue();
1001 },1005 },
1002 },1006 },
1003 .Pointer => {1007 .Pointer => {
...@@ -1015,7 +1019,7 @@ pub const Value = struct {...@@ -1015,7 +1019,7 @@ pub const Value = struct {
10151019
1016 /// Asserts that the value is a float or an integer.1020 /// Asserts that the value is a float or an integer.
1017 pub fn toFloat(val: Value, comptime T: type, mod: *Module) T {1021 pub fn toFloat(val: Value, comptime T: type, mod: *Module) T {
1018 return switch (mod.intern_pool.indexToKey(val.ip_index)) {1022 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1019 .int => |int| switch (int.storage) {1023 .int => |int| switch (int.storage) {
1020 .big_int => |big_int| @floatCast(T, bigIntToFloat(big_int.limbs, big_int.positive)),1024 .big_int => |big_int| @floatCast(T, bigIntToFloat(big_int.limbs, big_int.positive)),
1021 inline .u64, .i64 => |x| {1025 inline .u64, .i64 => |x| {
...@@ -1119,7 +1123,7 @@ pub const Value = struct {...@@ -1119,7 +1123,7 @@ pub const Value = struct {
1119 pub fn floatCast(self: Value, dest_ty: Type, mod: *Module) !Value {1123 pub fn floatCast(self: Value, dest_ty: Type, mod: *Module) !Value {
1120 const target = mod.getTarget();1124 const target = mod.getTarget();
1121 return (try mod.intern(.{ .float = .{1125 return (try mod.intern(.{ .float = .{
1122 .ty = dest_ty.ip_index,1126 .ty = dest_ty.toIntern(),
1123 .storage = switch (dest_ty.floatBits(target)) {1127 .storage = switch (dest_ty.floatBits(target)) {
1124 16 => .{ .f16 = self.toFloat(f16, mod) },1128 16 => .{ .f16 = self.toFloat(f16, mod) },
1125 32 => .{ .f32 = self.toFloat(f32, mod) },1129 32 => .{ .f32 = self.toFloat(f32, mod) },
...@@ -1133,7 +1137,7 @@ pub const Value = struct {...@@ -1133,7 +1137,7 @@ pub const Value = struct {
11331137
1134 /// Asserts the value is a float1138 /// Asserts the value is a float
1135 pub fn floatHasFraction(self: Value, mod: *const Module) bool {1139 pub fn floatHasFraction(self: Value, mod: *const Module) bool {
1136 return switch (mod.intern_pool.indexToKey(self.ip_index)) {1140 return switch (mod.intern_pool.indexToKey(self.toIntern())) {
1137 .float => |float| switch (float.storage) {1141 .float => |float| switch (float.storage) {
1138 inline else => |x| @rem(x, 1) != 0,1142 inline else => |x| @rem(x, 1) != 0,
1139 },1143 },
...@@ -1150,10 +1154,10 @@ pub const Value = struct {...@@ -1150,10 +1154,10 @@ pub const Value = struct {
1150 mod: *Module,1154 mod: *Module,
1151 opt_sema: ?*Sema,1155 opt_sema: ?*Sema,
1152 ) Module.CompileError!std.math.Order {1156 ) Module.CompileError!std.math.Order {
1153 return switch (lhs.ip_index) {1157 return switch (lhs.toIntern()) {
1154 .bool_false => .eq,1158 .bool_false => .eq,
1155 .bool_true => .gt,1159 .bool_true => .gt,
1156 else => switch (mod.intern_pool.indexToKey(lhs.ip_index)) {1160 else => switch (mod.intern_pool.indexToKey(lhs.toIntern())) {
1157 .ptr => |ptr| switch (ptr.addr) {1161 .ptr => |ptr| switch (ptr.addr) {
1158 .decl, .mut_decl, .comptime_field => .gt,1162 .decl, .mut_decl, .comptime_field => .gt,
1159 .int => |int| int.toValue().orderAgainstZeroAdvanced(mod, opt_sema),1163 .int => |int| int.toValue().orderAgainstZeroAdvanced(mod, opt_sema),
...@@ -1212,8 +1216,8 @@ pub const Value = struct {...@@ -1212,8 +1216,8 @@ pub const Value = struct {
1212 const lhs_tag = lhs.tag();1216 const lhs_tag = lhs.tag();
1213 const rhs_tag = rhs.tag();1217 const rhs_tag = rhs.tag();
1214 if (lhs_tag == rhs_tag) {1218 if (lhs_tag == rhs_tag) {
1215 const lhs_storage = mod.intern_pool.indexToKey(lhs.ip_index).float.storage;1219 const lhs_storage = mod.intern_pool.indexToKey(lhs.toIntern()).float.storage;
1216 const rhs_storage = mod.intern_pool.indexToKey(rhs.ip_index).float.storage;1220 const rhs_storage = mod.intern_pool.indexToKey(rhs.toIntern()).float.storage;
1217 const lhs128: f128 = switch (lhs_storage) {1221 const lhs128: f128 = switch (lhs_storage) {
1218 inline else => |x| x,1222 inline else => |x| x,
1219 };1223 };
...@@ -1336,46 +1340,20 @@ pub const Value = struct {...@@ -1336,46 +1340,20 @@ pub const Value = struct {
1336 }1340 }
1337 }1341 }
13381342
1339 switch (lhs.ip_index) {1343 switch (mod.intern_pool.indexToKey(lhs.toIntern())) {
1340 .none => switch (lhs.tag()) {1344 .float => |float| switch (float.storage) {
1341 .aggregate => {1345 inline else => |x| if (std.math.isNan(x)) return op == .neq,
1342 for (lhs.castTag(.aggregate).?.data) |elem_val| {
1343 if (!(try elem_val.compareAllWithZeroAdvancedExtra(op, mod, opt_sema))) return false;
1344 }
1345 return true;
1346 },
1347 .str_lit => {
1348 const str_lit = lhs.castTag(.str_lit).?.data;
1349 const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
1350 for (bytes) |byte| {
1351 if (!std.math.compare(byte, op, 0)) return false;
1352 }
1353 return true;
1354 },
1355 .bytes => {
1356 const bytes = lhs.castTag(.bytes).?.data;
1357 for (bytes) |byte| {
1358 if (!std.math.compare(byte, op, 0)) return false;
1359 }
1360 return true;
1361 },
1362 else => {},
1363 },1346 },
1364 else => switch (mod.intern_pool.indexToKey(lhs.ip_index)) {1347 .aggregate => |aggregate| return switch (aggregate.storage) {
1365 .float => |float| switch (float.storage) {1348 .bytes => |bytes| for (bytes) |byte| {
1366 inline else => |x| if (std.math.isNan(x)) return op == .neq,1349 if (!std.math.order(byte, 0).compare(op)) break false;
1367 },1350 } else true,
1368 .aggregate => |aggregate| return switch (aggregate.storage) {1351 .elems => |elems| for (elems) |elem| {
1369 .bytes => |bytes| for (bytes) |byte| {1352 if (!try elem.toValue().compareAllWithZeroAdvancedExtra(op, mod, opt_sema)) break false;
1370 if (!std.math.order(byte, 0).compare(op)) break false;1353 } else true,
1371 } else true,1354 .repeated_elem => |elem| elem.toValue().compareAllWithZeroAdvancedExtra(op, mod, opt_sema),
1372 .elems => |elems| for (elems) |elem| {
1373 if (!try elem.toValue().compareAllWithZeroAdvancedExtra(op, mod, opt_sema)) break false;
1374 } else true,
1375 .repeated_elem => |elem| elem.toValue().compareAllWithZeroAdvancedExtra(op, mod, opt_sema),
1376 },
1377 else => {},
1378 },1355 },
1356 else => {},
1379 }1357 }
1380 return (try orderAgainstZeroAdvanced(lhs, mod, opt_sema)).compare(op);1358 return (try orderAgainstZeroAdvanced(lhs, mod, opt_sema)).compare(op);
1381 }1359 }
...@@ -1412,7 +1390,7 @@ pub const Value = struct {...@@ -1412,7 +1390,7 @@ pub const Value = struct {
1412 const b_field_vals = b.castTag(.aggregate).?.data;1390 const b_field_vals = b.castTag(.aggregate).?.data;
1413 assert(a_field_vals.len == b_field_vals.len);1391 assert(a_field_vals.len == b_field_vals.len);
14141392
1415 switch (mod.intern_pool.indexToKey(ty.ip_index)) {1393 switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1416 .anon_struct_type => |anon_struct| {1394 .anon_struct_type => |anon_struct| {
1417 assert(anon_struct.types.len == a_field_vals.len);1395 assert(anon_struct.types.len == a_field_vals.len);
1418 for (anon_struct.types, 0..) |field_ty, i| {1396 for (anon_struct.types, 0..) |field_ty, i| {
...@@ -1577,7 +1555,7 @@ pub const Value = struct {...@@ -1577,7 +1555,7 @@ pub const Value = struct {
1577 // The InternPool data structure hashes based on Key to make interned objects1555 // The InternPool data structure hashes based on Key to make interned objects
1578 // unique. An Index can be treated simply as u32 value for the1556 // unique. An Index can be treated simply as u32 value for the
1579 // purpose of Type/Value hashing and equality.1557 // purpose of Type/Value hashing and equality.
1580 std.hash.autoHash(hasher, val.ip_index);1558 std.hash.autoHash(hasher, val.toIntern());
1581 return;1559 return;
1582 }1560 }
1583 const zig_ty_tag = ty.zigTypeTag(mod);1561 const zig_ty_tag = ty.zigTypeTag(mod);
...@@ -1663,7 +1641,7 @@ pub const Value = struct {...@@ -1663,7 +1641,7 @@ pub const Value = struct {
1663 // The InternPool data structure hashes based on Key to make interned objects1641 // The InternPool data structure hashes based on Key to make interned objects
1664 // unique. An Index can be treated simply as u32 value for the1642 // unique. An Index can be treated simply as u32 value for the
1665 // purpose of Type/Value hashing and equality.1643 // purpose of Type/Value hashing and equality.
1666 std.hash.autoHash(hasher, val.ip_index);1644 std.hash.autoHash(hasher, val.toIntern());
1667 return;1645 return;
1668 }1646 }
16691647
...@@ -1703,7 +1681,7 @@ pub const Value = struct {...@@ -1703,7 +1681,7 @@ pub const Value = struct {
1703 },1681 },
1704 .Union => {1682 .Union => {
1705 hasher.update(val.tagName(mod));1683 hasher.update(val.tagName(mod));
1706 switch (mod.intern_pool.indexToKey(val.ip_index)) {1684 switch (mod.intern_pool.indexToKey(val.toIntern())) {
1707 .un => |un| {1685 .un => |un| {
1708 const active_field_ty = ty.unionFieldType(un.tag.toValue(), mod);1686 const active_field_ty = ty.unionFieldType(un.tag.toValue(), mod);
1709 un.val.toValue().hashUncoerced(active_field_ty, hasher, mod);1687 un.val.toValue().hashUncoerced(active_field_ty, hasher, mod);
...@@ -1746,7 +1724,7 @@ pub const Value = struct {...@@ -1746,7 +1724,7 @@ pub const Value = struct {
1746 };1724 };
17471725
1748 pub fn isComptimeMutablePtr(val: Value, mod: *Module) bool {1726 pub fn isComptimeMutablePtr(val: Value, mod: *Module) bool {
1749 return switch (mod.intern_pool.indexToKey(val.ip_index)) {1727 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1750 .ptr => |ptr| switch (ptr.addr) {1728 .ptr => |ptr| switch (ptr.addr) {
1751 .mut_decl, .comptime_field => true,1729 .mut_decl, .comptime_field => true,
1752 .eu_payload, .opt_payload => |base_ptr| base_ptr.toValue().isComptimeMutablePtr(mod),1730 .eu_payload, .opt_payload => |base_ptr| base_ptr.toValue().isComptimeMutablePtr(mod),
...@@ -1758,8 +1736,8 @@ pub const Value = struct {...@@ -1758,8 +1736,8 @@ pub const Value = struct {
1758 }1736 }
17591737
1760 pub fn canMutateComptimeVarState(val: Value, mod: *Module) bool {1738 pub fn canMutateComptimeVarState(val: Value, mod: *Module) bool {
1761 return val.isComptimeMutablePtr(mod) or switch (val.ip_index) {1739 return val.isComptimeMutablePtr(mod) or switch (val.toIntern()) {
1762 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {1740 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
1763 .error_union => |error_union| switch (error_union.val) {1741 .error_union => |error_union| switch (error_union.val) {
1764 .err_name => false,1742 .err_name => false,
1765 .payload => |payload| payload.toValue().canMutateComptimeVarState(mod),1743 .payload => |payload| payload.toValue().canMutateComptimeVarState(mod),
...@@ -1785,7 +1763,7 @@ pub const Value = struct {...@@ -1785,7 +1763,7 @@ pub const Value = struct {
1785 /// to a decl, or if it points to some part of a decl (like field_ptr or element_ptr),1763 /// to a decl, or if it points to some part of a decl (like field_ptr or element_ptr),
1786 /// this function returns null.1764 /// this function returns null.
1787 pub fn pointerDecl(val: Value, mod: *Module) ?Module.Decl.Index {1765 pub fn pointerDecl(val: Value, mod: *Module) ?Module.Decl.Index {
1788 return switch (mod.intern_pool.indexToKey(val.ip_index)) {1766 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1789 .variable => |variable| variable.decl,1767 .variable => |variable| variable.decl,
1790 .extern_func => |extern_func| extern_func.decl,1768 .extern_func => |extern_func| extern_func.decl,
1791 .func => |func| mod.funcPtr(func.index).owner_decl,1769 .func => |func| mod.funcPtr(func.index).owner_decl,
...@@ -1811,35 +1789,19 @@ pub const Value = struct {...@@ -1811,35 +1789,19 @@ pub const Value = struct {
1811 pub const slice_len_index = 1;1789 pub const slice_len_index = 1;
18121790
1813 pub fn slicePtr(val: Value, mod: *Module) Value {1791 pub fn slicePtr(val: Value, mod: *Module) Value {
1814 return mod.intern_pool.slicePtr(val.ip_index).toValue();1792 return mod.intern_pool.slicePtr(val.toIntern()).toValue();
1815 }1793 }
18161794
1817 pub fn sliceLen(val: Value, mod: *Module) u64 {1795 pub fn sliceLen(val: Value, mod: *Module) u64 {
1818 return mod.intern_pool.sliceLen(val.ip_index).toValue().toUnsignedInt(mod);1796 return mod.intern_pool.sliceLen(val.toIntern()).toValue().toUnsignedInt(mod);
1819 }1797 }
18201798
1821 /// Asserts the value is a single-item pointer to an array, or an array,1799 /// Asserts the value is a single-item pointer to an array, or an array,
1822 /// or an unknown-length pointer, and returns the element value at the index.1800 /// or an unknown-length pointer, and returns the element value at the index.
1823 pub fn elemValue(val: Value, mod: *Module, index: usize) Allocator.Error!Value {1801 pub fn elemValue(val: Value, mod: *Module, index: usize) Allocator.Error!Value {
1824 switch (val.ip_index) {1802 switch (val.toIntern()) {
1825 .undef => return Value.undef,1803 .undef => return Value.undef,
1826 .none => switch (val.tag()) {1804 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1827 .bytes => {
1828 const byte = val.castTag(.bytes).?.data[index];
1829 return mod.intValue(Type.u8, byte);
1830 },
1831 .str_lit => {
1832 const str_lit = val.castTag(.str_lit).?.data;
1833 const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
1834 const byte = bytes[index];
1835 return mod.intValue(Type.u8, byte);
1836 },
1837
1838 .aggregate => return val.castTag(.aggregate).?.data[index],
1839
1840 else => unreachable,
1841 },
1842 else => return switch (mod.intern_pool.indexToKey(val.ip_index)) {
1843 .ptr => |ptr| switch (ptr.addr) {1805 .ptr => |ptr| switch (ptr.addr) {
1844 .decl => |decl| mod.declPtr(decl).val.elemValue(mod, index),1806 .decl => |decl| mod.declPtr(decl).val.elemValue(mod, index),
1845 .mut_decl => |mut_decl| mod.declPtr(mut_decl.decl).val.elemValue(mod, index),1807 .mut_decl => |mut_decl| mod.declPtr(mut_decl.decl).val.elemValue(mod, index),
...@@ -1871,26 +1833,26 @@ pub const Value = struct {...@@ -1871,26 +1833,26 @@ pub const Value = struct {
1871 }1833 }
18721834
1873 pub fn isLazyAlign(val: Value, mod: *Module) bool {1835 pub fn isLazyAlign(val: Value, mod: *Module) bool {
1874 return switch (mod.intern_pool.indexToKey(val.ip_index)) {1836 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1875 .int => |int| int.storage == .lazy_align,1837 .int => |int| int.storage == .lazy_align,
1876 else => false,1838 else => false,
1877 };1839 };
1878 }1840 }
18791841
1880 pub fn isLazySize(val: Value, mod: *Module) bool {1842 pub fn isLazySize(val: Value, mod: *Module) bool {
1881 return switch (mod.intern_pool.indexToKey(val.ip_index)) {1843 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1882 .int => |int| int.storage == .lazy_size,1844 .int => |int| int.storage == .lazy_size,
1883 else => false,1845 else => false,
1884 };1846 };
1885 }1847 }
18861848
1887 pub fn isRuntimeValue(val: Value, mod: *Module) bool {1849 pub fn isRuntimeValue(val: Value, mod: *Module) bool {
1888 return mod.intern_pool.indexToKey(val.ip_index) == .runtime_value;1850 return mod.intern_pool.indexToKey(val.toIntern()) == .runtime_value;
1889 }1851 }
18901852
1891 /// Returns true if a Value is backed by a variable1853 /// Returns true if a Value is backed by a variable
1892 pub fn isVariable(val: Value, mod: *Module) bool {1854 pub fn isVariable(val: Value, mod: *Module) bool {
1893 return switch (mod.intern_pool.indexToKey(val.ip_index)) {1855 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1894 .variable => true,1856 .variable => true,
1895 .ptr => |ptr| switch (ptr.addr) {1857 .ptr => |ptr| switch (ptr.addr) {
1896 .decl => |decl_index| {1858 .decl => |decl_index| {
...@@ -1913,7 +1875,7 @@ pub const Value = struct {...@@ -1913,7 +1875,7 @@ pub const Value = struct {
1913 }1875 }
19141876
1915 pub fn isPtrToThreadLocal(val: Value, mod: *Module) bool {1877 pub fn isPtrToThreadLocal(val: Value, mod: *Module) bool {
1916 return switch (mod.intern_pool.indexToKey(val.ip_index)) {1878 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1917 .variable => |variable| variable.is_threadlocal,1879 .variable => |variable| variable.is_threadlocal,
1918 .ptr => |ptr| switch (ptr.addr) {1880 .ptr => |ptr| switch (ptr.addr) {
1919 .decl => |decl_index| {1881 .decl => |decl_index| {
...@@ -1943,55 +1905,30 @@ pub const Value = struct {...@@ -1943,55 +1905,30 @@ pub const Value = struct {
1943 start: usize,1905 start: usize,
1944 end: usize,1906 end: usize,
1945 ) error{OutOfMemory}!Value {1907 ) error{OutOfMemory}!Value {
1946 return switch (val.ip_index) {1908 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1947 .none => switch (val.tag()) {1909 .ptr => |ptr| switch (ptr.addr) {
1948 .bytes => Tag.bytes.create(arena, val.castTag(.bytes).?.data[start..end]),1910 .decl => |decl| try mod.declPtr(decl).val.sliceArray(mod, arena, start, end),
1949 .str_lit => {1911 .mut_decl => |mut_decl| try mod.declPtr(mut_decl.decl).val.sliceArray(mod, arena, start, end),
1950 const str_lit = val.castTag(.str_lit).?.data;1912 .comptime_field => |comptime_field| try comptime_field.toValue().sliceArray(mod, arena, start, end),
1951 return Tag.str_lit.create(arena, .{1913 .elem => |elem| try elem.base.toValue().sliceArray(mod, arena, start + elem.index, end + elem.index),
1952 .index = @intCast(u32, str_lit.index + start),
1953 .len = @intCast(u32, end - start),
1954 });
1955 },
1956 else => unreachable,1914 else => unreachable,
1957 },1915 },
1958 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {1916 .aggregate => |aggregate| (try mod.intern(.{ .aggregate = .{
1959 .ptr => |ptr| switch (ptr.addr) {1917 .ty = mod.intern_pool.typeOf(val.toIntern()),
1960 .decl => |decl| try mod.declPtr(decl).val.sliceArray(mod, arena, start, end),1918 .storage = switch (aggregate.storage) {
1961 .mut_decl => |mut_decl| try mod.declPtr(mut_decl.decl).val.sliceArray(mod, arena, start, end),1919 .bytes => |bytes| .{ .bytes = bytes[start..end] },
1962 .comptime_field => |comptime_field| try comptime_field.toValue().sliceArray(mod, arena, start, end),1920 .elems => |elems| .{ .elems = elems[start..end] },
1963 .elem => |elem| try elem.base.toValue().sliceArray(mod, arena, start + elem.index, end + elem.index),1921 .repeated_elem => |elem| .{ .repeated_elem = elem },
1964 else => unreachable,
1965 },1922 },
1966 .aggregate => |aggregate| (try mod.intern(.{ .aggregate = .{1923 } })).toValue(),
1967 .ty = mod.intern_pool.typeOf(val.ip_index),1924 else => unreachable,
1968 .storage = switch (aggregate.storage) {
1969 .bytes => |bytes| .{ .bytes = bytes[start..end] },
1970 .elems => |elems| .{ .elems = elems[start..end] },
1971 .repeated_elem => |elem| .{ .repeated_elem = elem },
1972 },
1973 } })).toValue(),
1974 else => unreachable,
1975 },
1976 };1925 };
1977 }1926 }
19781927
1979 pub fn fieldValue(val: Value, mod: *Module, index: usize) !Value {1928 pub fn fieldValue(val: Value, mod: *Module, index: usize) !Value {
1980 switch (val.ip_index) {1929 switch (val.toIntern()) {
1981 .undef => return Value.undef,1930 .undef => return Value.undef,
1982 .none => switch (val.tag()) {1931 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1983 .aggregate => {
1984 const field_values = val.castTag(.aggregate).?.data;
1985 return field_values[index];
1986 },
1987 .@"union" => {
1988 const payload = val.castTag(.@"union").?.data;
1989 // TODO assert the tag is correct
1990 return payload.val;
1991 },
1992 else => unreachable,
1993 },
1994 else => return switch (mod.intern_pool.indexToKey(val.ip_index)) {
1995 .aggregate => |aggregate| switch (aggregate.storage) {1932 .aggregate => |aggregate| switch (aggregate.storage) {
1996 .bytes => |bytes| try mod.intern(.{ .int = .{1933 .bytes => |bytes| try mod.intern(.{ .int = .{
1997 .ty = .u8_type,1934 .ty = .u8_type,
...@@ -2000,6 +1937,8 @@ pub const Value = struct {...@@ -2000,6 +1937,8 @@ pub const Value = struct {
2000 .elems => |elems| elems[index],1937 .elems => |elems| elems[index],
2001 .repeated_elem => |elem| elem,1938 .repeated_elem => |elem| elem,
2002 }.toValue(),1939 }.toValue(),
1940 // TODO assert the tag is correct
1941 .un => |un| un.val.toValue(),
2003 else => unreachable,1942 else => unreachable,
2004 },1943 },
2005 }1944 }
...@@ -2007,7 +1946,7 @@ pub const Value = struct {...@@ -2007,7 +1946,7 @@ pub const Value = struct {
20071946
2008 pub fn unionTag(val: Value, mod: *Module) Value {1947 pub fn unionTag(val: Value, mod: *Module) Value {
2009 if (val.ip_index == .none) return val.castTag(.@"union").?.data.tag;1948 if (val.ip_index == .none) return val.castTag(.@"union").?.data.tag;
2010 return switch (mod.intern_pool.indexToKey(val.ip_index)) {1949 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2011 .undef, .enum_tag => val,1950 .undef, .enum_tag => val,
2012 .un => |un| un.tag.toValue(),1951 .un => |un| un.tag.toValue(),
2013 else => unreachable,1952 else => unreachable,
...@@ -2022,12 +1961,12 @@ pub const Value = struct {...@@ -2022,12 +1961,12 @@ pub const Value = struct {
2022 mod: *Module,1961 mod: *Module,
2023 ) Allocator.Error!Value {1962 ) Allocator.Error!Value {
2024 const elem_ty = ty.elemType2(mod);1963 const elem_ty = ty.elemType2(mod);
2025 const ptr_val = switch (mod.intern_pool.indexToKey(val.ip_index)) {1964 const ptr_val = switch (mod.intern_pool.indexToKey(val.toIntern())) {
2026 .ptr => |ptr| ptr: {1965 .ptr => |ptr| ptr: {
2027 switch (ptr.addr) {1966 switch (ptr.addr) {
2028 .elem => |elem| if (mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).eql(elem_ty, mod))1967 .elem => |elem| if (mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).eql(elem_ty, mod))
2029 return (try mod.intern(.{ .ptr = .{1968 return (try mod.intern(.{ .ptr = .{
2030 .ty = ty.ip_index,1969 .ty = ty.toIntern(),
2031 .addr = .{ .elem = .{1970 .addr = .{ .elem = .{
2032 .base = elem.base,1971 .base = elem.base,
2033 .index = elem.index + index,1972 .index = elem.index + index,
...@@ -2043,9 +1982,9 @@ pub const Value = struct {...@@ -2043,9 +1982,9 @@ pub const Value = struct {
2043 else => val,1982 else => val,
2044 };1983 };
2045 return (try mod.intern(.{ .ptr = .{1984 return (try mod.intern(.{ .ptr = .{
2046 .ty = ty.ip_index,1985 .ty = ty.toIntern(),
2047 .addr = .{ .elem = .{1986 .addr = .{ .elem = .{
2048 .base = ptr_val.ip_index,1987 .base = ptr_val.toIntern(),
2049 .index = index,1988 .index = index,
2050 } },1989 } },
2051 } })).toValue();1990 } })).toValue();
...@@ -2053,7 +1992,7 @@ pub const Value = struct {...@@ -2053,7 +1992,7 @@ pub const Value = struct {
20531992
2054 pub fn isUndef(val: Value, mod: *Module) bool {1993 pub fn isUndef(val: Value, mod: *Module) bool {
2055 if (val.ip_index == .none) return false;1994 if (val.ip_index == .none) return false;
2056 return switch (mod.intern_pool.indexToKey(val.ip_index)) {1995 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2057 .undef => true,1996 .undef => true,
2058 .simple_value => |v| v == .undefined,1997 .simple_value => |v| v == .undefined,
2059 else => false,1998 else => false,
...@@ -2070,15 +2009,9 @@ pub const Value = struct {...@@ -2070,15 +2009,9 @@ pub const Value = struct {
2070 /// Returns true if any value contained in `self` is undefined.2009 /// Returns true if any value contained in `self` is undefined.
2071 pub fn anyUndef(val: Value, mod: *Module) !bool {2010 pub fn anyUndef(val: Value, mod: *Module) !bool {
2072 if (val.ip_index == .none) return false;2011 if (val.ip_index == .none) return false;
2073 return switch (val.ip_index) {2012 return switch (val.toIntern()) {
2074 .undef => true,2013 .undef => true,
2075 .none => switch (val.tag()) {2014 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
2076 .aggregate => for (val.castTag(.aggregate).?.data) |field| {
2077 if (try field.anyUndef(mod)) break true;
2078 } else false,
2079 else => false,
2080 },
2081 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
2082 .undef => true,2015 .undef => true,
2083 .simple_value => |v| v == .undefined,2016 .simple_value => |v| v == .undefined,
2084 .ptr => |ptr| switch (ptr.len) {2017 .ptr => |ptr| switch (ptr.len) {
...@@ -2098,13 +2031,13 @@ pub const Value = struct {...@@ -2098,13 +2031,13 @@ pub const Value = struct {
2098 /// Asserts the value is not undefined and not unreachable.2031 /// Asserts the value is not undefined and not unreachable.
2099 /// Integer value 0 is considered null because of C pointers.2032 /// Integer value 0 is considered null because of C pointers.
2100 pub fn isNull(val: Value, mod: *Module) bool {2033 pub fn isNull(val: Value, mod: *Module) bool {
2101 return switch (val.ip_index) {2034 return switch (val.toIntern()) {
2102 .undef => unreachable,2035 .undef => unreachable,
2103 .unreachable_value => unreachable,2036 .unreachable_value => unreachable,
21042037
2105 .null_value => true,2038 .null_value => true,
21062039
2107 else => return switch (mod.intern_pool.indexToKey(val.ip_index)) {2040 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2108 .int => {2041 .int => {
2109 var buf: BigIntSpace = undefined;2042 var buf: BigIntSpace = undefined;
2110 return val.toBigInt(&buf, mod).eqZero();2043 return val.toBigInt(&buf, mod).eqZero();
...@@ -2120,7 +2053,7 @@ pub const Value = struct {...@@ -2120,7 +2053,7 @@ pub const Value = struct {
2120 /// something is an error or not because it works without having to figure out the2053 /// something is an error or not because it works without having to figure out the
2121 /// string.2054 /// string.
2122 pub fn getError(self: Value, mod: *const Module) ?[]const u8 {2055 pub fn getError(self: Value, mod: *const Module) ?[]const u8 {
2123 return mod.intern_pool.stringToSliceUnwrap(switch (mod.intern_pool.indexToKey(self.ip_index)) {2056 return mod.intern_pool.stringToSliceUnwrap(switch (mod.intern_pool.indexToKey(self.toIntern())) {
2124 .err => |err| err.name.toOptional(),2057 .err => |err| err.name.toOptional(),
2125 .error_union => |error_union| switch (error_union.val) {2058 .error_union => |error_union| switch (error_union.val) {
2126 .err_name => |err_name| err_name.toOptional(),2059 .err_name => |err_name| err_name.toOptional(),
...@@ -2133,12 +2066,12 @@ pub const Value = struct {...@@ -2133,12 +2066,12 @@ pub const Value = struct {
2133 /// Assumes the type is an error union. Returns true if and only if the value is2066 /// Assumes the type is an error union. Returns true if and only if the value is
2134 /// the error union payload, not an error.2067 /// the error union payload, not an error.
2135 pub fn errorUnionIsPayload(val: Value, mod: *const Module) bool {2068 pub fn errorUnionIsPayload(val: Value, mod: *const Module) bool {
2136 return mod.intern_pool.indexToKey(val.ip_index).error_union.val == .payload;2069 return mod.intern_pool.indexToKey(val.toIntern()).error_union.val == .payload;
2137 }2070 }
21382071
2139 /// Value of the optional, null if optional has no payload.2072 /// Value of the optional, null if optional has no payload.
2140 pub fn optionalValue(val: Value, mod: *const Module) ?Value {2073 pub fn optionalValue(val: Value, mod: *const Module) ?Value {
2141 return switch (mod.intern_pool.indexToKey(val.ip_index).opt.val) {2074 return switch (mod.intern_pool.indexToKey(val.toIntern()).opt.val) {
2142 .none => null,2075 .none => null,
2143 else => |index| index.toValue(),2076 else => |index| index.toValue(),
2144 };2077 };
...@@ -2146,14 +2079,9 @@ pub const Value = struct {...@@ -2146,14 +2079,9 @@ pub const Value = struct {
21462079
2147 /// Valid for all types. Asserts the value is not undefined.2080 /// Valid for all types. Asserts the value is not undefined.
2148 pub fn isFloat(self: Value, mod: *const Module) bool {2081 pub fn isFloat(self: Value, mod: *const Module) bool {
2149 return switch (self.ip_index) {2082 return switch (self.toIntern()) {
2150 .undef => unreachable,2083 .undef => unreachable,
2151 .none => switch (self.tag()) {2084 else => switch (mod.intern_pool.indexToKey(self.toIntern())) {
2152 .inferred_alloc => unreachable,
2153 .inferred_alloc_comptime => unreachable,
2154 else => false,
2155 },
2156 else => switch (mod.intern_pool.indexToKey(self.ip_index)) {
2157 .float => true,2085 .float => true,
2158 else => false,2086 else => false,
2159 },2087 },
...@@ -2169,21 +2097,24 @@ pub const Value = struct {...@@ -2169,21 +2097,24 @@ pub const Value = struct {
21692097
2170 pub fn intToFloatAdvanced(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, mod: *Module, opt_sema: ?*Sema) !Value {2098 pub fn intToFloatAdvanced(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, mod: *Module, opt_sema: ?*Sema) !Value {
2171 if (int_ty.zigTypeTag(mod) == .Vector) {2099 if (int_ty.zigTypeTag(mod) == .Vector) {
2172 const result_data = try arena.alloc(Value, int_ty.vectorLen(mod));2100 const result_data = try arena.alloc(InternPool.Index, int_ty.vectorLen(mod));
2173 const scalar_ty = float_ty.scalarType(mod);2101 const scalar_ty = float_ty.scalarType(mod);
2174 for (result_data, 0..) |*scalar, i| {2102 for (result_data, 0..) |*scalar, i| {
2175 const elem_val = try val.elemValue(mod, i);2103 const elem_val = try val.elemValue(mod, i);
2176 scalar.* = try intToFloatScalar(elem_val, scalar_ty, mod, opt_sema);2104 scalar.* = try (try intToFloatScalar(elem_val, scalar_ty, mod, opt_sema)).intern(scalar_ty, mod);
2177 }2105 }
2178 return Value.Tag.aggregate.create(arena, result_data);2106 return (try mod.intern(.{ .aggregate = .{
2107 .ty = float_ty.toIntern(),
2108 .storage = .{ .elems = result_data },
2109 } })).toValue();
2179 }2110 }
2180 return intToFloatScalar(val, float_ty, mod, opt_sema);2111 return intToFloatScalar(val, float_ty, mod, opt_sema);
2181 }2112 }
21822113
2183 pub fn intToFloatScalar(val: Value, float_ty: Type, mod: *Module, opt_sema: ?*Sema) !Value {2114 pub fn intToFloatScalar(val: Value, float_ty: Type, mod: *Module, opt_sema: ?*Sema) !Value {
2184 return switch (val.ip_index) {2115 return switch (val.toIntern()) {
2185 .undef => val,2116 .undef => val,
2186 else => return switch (mod.intern_pool.indexToKey(val.ip_index)) {2117 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2187 .int => |int| switch (int.storage) {2118 .int => |int| switch (int.storage) {
2188 .big_int => |big_int| {2119 .big_int => |big_int| {
2189 const float = bigIntToFloat(big_int.limbs, big_int.positive);2120 const float = bigIntToFloat(big_int.limbs, big_int.positive);
...@@ -2217,7 +2148,7 @@ pub const Value = struct {...@@ -2217,7 +2148,7 @@ pub const Value = struct {
2217 else => unreachable,2148 else => unreachable,
2218 };2149 };
2219 return (try mod.intern(.{ .float = .{2150 return (try mod.intern(.{ .float = .{
2220 .ty = dest_ty.ip_index,2151 .ty = dest_ty.toIntern(),
2221 .storage = storage,2152 .storage = storage,
2222 } })).toValue();2153 } })).toValue();
2223 }2154 }
...@@ -2245,14 +2176,17 @@ pub const Value = struct {...@@ -2245,14 +2176,17 @@ pub const Value = struct {
2245 mod: *Module,2176 mod: *Module,
2246 ) !Value {2177 ) !Value {
2247 if (ty.zigTypeTag(mod) == .Vector) {2178 if (ty.zigTypeTag(mod) == .Vector) {
2248 const result_data = try arena.alloc(Value, ty.vectorLen(mod));2179 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));
2249 const scalar_ty = ty.scalarType(mod);2180 const scalar_ty = ty.scalarType(mod);
2250 for (result_data, 0..) |*scalar, i| {2181 for (result_data, 0..) |*scalar, i| {
2251 const lhs_elem = try lhs.elemValue(mod, i);2182 const lhs_elem = try lhs.elemValue(mod, i);
2252 const rhs_elem = try rhs.elemValue(mod, i);2183 const rhs_elem = try rhs.elemValue(mod, i);
2253 scalar.* = try intAddSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod);2184 scalar.* = try (try intAddSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2254 }2185 }
2255 return Value.Tag.aggregate.create(arena, result_data);2186 return (try mod.intern(.{ .aggregate = .{
2187 .ty = ty.toIntern(),
2188 .storage = .{ .elems = result_data },
2189 } })).toValue();
2256 }2190 }
2257 return intAddSatScalar(lhs, rhs, ty, arena, mod);2191 return intAddSatScalar(lhs, rhs, ty, arena, mod);
2258 }2192 }
...@@ -2292,14 +2226,17 @@ pub const Value = struct {...@@ -2292,14 +2226,17 @@ pub const Value = struct {
2292 mod: *Module,2226 mod: *Module,
2293 ) !Value {2227 ) !Value {
2294 if (ty.zigTypeTag(mod) == .Vector) {2228 if (ty.zigTypeTag(mod) == .Vector) {
2295 const result_data = try arena.alloc(Value, ty.vectorLen(mod));2229 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));
2296 const scalar_ty = ty.scalarType(mod);2230 const scalar_ty = ty.scalarType(mod);
2297 for (result_data, 0..) |*scalar, i| {2231 for (result_data, 0..) |*scalar, i| {
2298 const lhs_elem = try lhs.elemValue(mod, i);2232 const lhs_elem = try lhs.elemValue(mod, i);
2299 const rhs_elem = try rhs.elemValue(mod, i);2233 const rhs_elem = try rhs.elemValue(mod, i);
2300 scalar.* = try intSubSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod);2234 scalar.* = try (try intSubSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2301 }2235 }
2302 return Value.Tag.aggregate.create(arena, result_data);2236 return (try mod.intern(.{ .aggregate = .{
2237 .ty = ty.toIntern(),
2238 .storage = .{ .elems = result_data },
2239 } })).toValue();
2303 }2240 }
2304 return intSubSatScalar(lhs, rhs, ty, arena, mod);2241 return intSubSatScalar(lhs, rhs, ty, arena, mod);
2305 }2242 }
...@@ -2338,19 +2275,26 @@ pub const Value = struct {...@@ -2338,19 +2275,26 @@ pub const Value = struct {
2338 mod: *Module,2275 mod: *Module,
2339 ) !OverflowArithmeticResult {2276 ) !OverflowArithmeticResult {
2340 if (ty.zigTypeTag(mod) == .Vector) {2277 if (ty.zigTypeTag(mod) == .Vector) {
2341 const overflowed_data = try arena.alloc(Value, ty.vectorLen(mod));2278 const vec_len = ty.vectorLen(mod);
2342 const result_data = try arena.alloc(Value, ty.vectorLen(mod));2279 const overflowed_data = try arena.alloc(InternPool.Index, vec_len);
2280 const result_data = try arena.alloc(InternPool.Index, vec_len);
2343 const scalar_ty = ty.scalarType(mod);2281 const scalar_ty = ty.scalarType(mod);
2344 for (result_data, 0..) |*scalar, i| {2282 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
2345 const lhs_elem = try lhs.elemValue(mod, i);2283 const lhs_elem = try lhs.elemValue(mod, i);
2346 const rhs_elem = try rhs.elemValue(mod, i);2284 const rhs_elem = try rhs.elemValue(mod, i);
2347 const of_math_result = try intMulWithOverflowScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod);2285 const of_math_result = try intMulWithOverflowScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod);
2348 overflowed_data[i] = of_math_result.overflow_bit;2286 of.* = try of_math_result.overflow_bit.intern(Type.bool, mod);
2349 scalar.* = of_math_result.wrapped_result;2287 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
2350 }2288 }
2351 return OverflowArithmeticResult{2289 return OverflowArithmeticResult{
2352 .overflow_bit = try Value.Tag.aggregate.create(arena, overflowed_data),2290 .overflow_bit = (try mod.intern(.{ .aggregate = .{
2353 .wrapped_result = try Value.Tag.aggregate.create(arena, result_data),2291 .ty = ty.toIntern(),
2292 .storage = .{ .elems = overflowed_data },
2293 } })).toValue(),
2294 .wrapped_result = (try mod.intern(.{ .aggregate = .{
2295 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),
2296 .storage = .{ .elems = result_data },
2297 } })).toValue(),
2354 };2298 };
2355 }2299 }
2356 return intMulWithOverflowScalar(lhs, rhs, ty, arena, mod);2300 return intMulWithOverflowScalar(lhs, rhs, ty, arena, mod);
...@@ -2400,13 +2344,17 @@ pub const Value = struct {...@@ -2400,13 +2344,17 @@ pub const Value = struct {
2400 mod: *Module,2344 mod: *Module,
2401 ) !Value {2345 ) !Value {
2402 if (ty.zigTypeTag(mod) == .Vector) {2346 if (ty.zigTypeTag(mod) == .Vector) {
2403 const result_data = try arena.alloc(Value, ty.vectorLen(mod));2347 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));
2348 const scalar_ty = ty.scalarType(mod);
2404 for (result_data, 0..) |*scalar, i| {2349 for (result_data, 0..) |*scalar, i| {
2405 const lhs_elem = try lhs.elemValue(mod, i);2350 const lhs_elem = try lhs.elemValue(mod, i);
2406 const rhs_elem = try rhs.elemValue(mod, i);2351 const rhs_elem = try rhs.elemValue(mod, i);
2407 scalar.* = try numberMulWrapScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);2352 scalar.* = try (try numberMulWrapScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2408 }2353 }
2409 return Value.Tag.aggregate.create(arena, result_data);2354 return (try mod.intern(.{ .aggregate = .{
2355 .ty = ty.toIntern(),
2356 .storage = .{ .elems = result_data },
2357 } })).toValue();
2410 }2358 }
2411 return numberMulWrapScalar(lhs, rhs, ty, arena, mod);2359 return numberMulWrapScalar(lhs, rhs, ty, arena, mod);
2412 }2360 }
...@@ -2442,13 +2390,17 @@ pub const Value = struct {...@@ -2442,13 +2390,17 @@ pub const Value = struct {
2442 mod: *Module,2390 mod: *Module,
2443 ) !Value {2391 ) !Value {
2444 if (ty.zigTypeTag(mod) == .Vector) {2392 if (ty.zigTypeTag(mod) == .Vector) {
2445 const result_data = try arena.alloc(Value, ty.vectorLen(mod));2393 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));
2394 const scalar_ty = ty.scalarType(mod);
2446 for (result_data, 0..) |*scalar, i| {2395 for (result_data, 0..) |*scalar, i| {
2447 const lhs_elem = try lhs.elemValue(mod, i);2396 const lhs_elem = try lhs.elemValue(mod, i);
2448 const rhs_elem = try rhs.elemValue(mod, i);2397 const rhs_elem = try rhs.elemValue(mod, i);
2449 scalar.* = try intMulSatScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);2398 scalar.* = try (try intMulSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2450 }2399 }
2451 return Value.Tag.aggregate.create(arena, result_data);2400 return (try mod.intern(.{ .aggregate = .{
2401 .ty = ty.toIntern(),
2402 .storage = .{ .elems = result_data },
2403 } })).toValue();
2452 }2404 }
2453 return intMulSatScalar(lhs, rhs, ty, arena, mod);2405 return intMulSatScalar(lhs, rhs, ty, arena, mod);
2454 }2406 }
...@@ -2515,12 +2467,16 @@ pub const Value = struct {...@@ -2515,12 +2467,16 @@ pub const Value = struct {
2515 /// operands must be (vectors of) integers; handles undefined scalars.2467 /// operands must be (vectors of) integers; handles undefined scalars.
2516 pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, mod: *Module) !Value {2468 pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
2517 if (ty.zigTypeTag(mod) == .Vector) {2469 if (ty.zigTypeTag(mod) == .Vector) {
2518 const result_data = try arena.alloc(Value, ty.vectorLen(mod));2470 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));
2471 const scalar_ty = ty.scalarType(mod);
2519 for (result_data, 0..) |*scalar, i| {2472 for (result_data, 0..) |*scalar, i| {
2520 const elem_val = try val.elemValue(mod, i);2473 const elem_val = try val.elemValue(mod, i);
2521 scalar.* = try bitwiseNotScalar(elem_val, ty.scalarType(mod), arena, mod);2474 scalar.* = try (try bitwiseNotScalar(elem_val, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2522 }2475 }
2523 return Value.Tag.aggregate.create(arena, result_data);2476 return (try mod.intern(.{ .aggregate = .{
2477 .ty = ty.toIntern(),
2478 .storage = .{ .elems = result_data },
2479 } })).toValue();
2524 }2480 }
2525 return bitwiseNotScalar(val, ty, arena, mod);2481 return bitwiseNotScalar(val, ty, arena, mod);
2526 }2482 }
...@@ -2552,13 +2508,17 @@ pub const Value = struct {...@@ -2552,13 +2508,17 @@ pub const Value = struct {
2552 /// operands must be (vectors of) integers; handles undefined scalars.2508 /// operands must be (vectors of) integers; handles undefined scalars.
2553 pub fn bitwiseAnd(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {2509 pub fn bitwiseAnd(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
2554 if (ty.zigTypeTag(mod) == .Vector) {2510 if (ty.zigTypeTag(mod) == .Vector) {
2555 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));2511 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2512 const scalar_ty = ty.scalarType(mod);
2556 for (result_data, 0..) |*scalar, i| {2513 for (result_data, 0..) |*scalar, i| {
2557 const lhs_elem = try lhs.elemValue(mod, i);2514 const lhs_elem = try lhs.elemValue(mod, i);
2558 const rhs_elem = try rhs.elemValue(mod, i);2515 const rhs_elem = try rhs.elemValue(mod, i);
2559 scalar.* = try bitwiseAndScalar(lhs_elem, rhs_elem, ty.scalarType(mod), allocator, mod);2516 scalar.* = try (try bitwiseAndScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2560 }2517 }
2561 return Value.Tag.aggregate.create(allocator, result_data);2518 return (try mod.intern(.{ .aggregate = .{
2519 .ty = ty.toIntern(),
2520 .storage = .{ .elems = result_data },
2521 } })).toValue();
2562 }2522 }
2563 return bitwiseAndScalar(lhs, rhs, ty, allocator, mod);2523 return bitwiseAndScalar(lhs, rhs, ty, allocator, mod);
2564 }2524 }
...@@ -2586,13 +2546,17 @@ pub const Value = struct {...@@ -2586,13 +2546,17 @@ pub const Value = struct {
2586 /// operands must be (vectors of) integers; handles undefined scalars.2546 /// operands must be (vectors of) integers; handles undefined scalars.
2587 pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {2547 pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
2588 if (ty.zigTypeTag(mod) == .Vector) {2548 if (ty.zigTypeTag(mod) == .Vector) {
2589 const result_data = try arena.alloc(Value, ty.vectorLen(mod));2549 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));
2550 const scalar_ty = ty.scalarType(mod);
2590 for (result_data, 0..) |*scalar, i| {2551 for (result_data, 0..) |*scalar, i| {
2591 const lhs_elem = try lhs.elemValue(mod, i);2552 const lhs_elem = try lhs.elemValue(mod, i);
2592 const rhs_elem = try rhs.elemValue(mod, i);2553 const rhs_elem = try rhs.elemValue(mod, i);
2593 scalar.* = try bitwiseNandScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);2554 scalar.* = try (try bitwiseNandScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2594 }2555 }
2595 return Value.Tag.aggregate.create(arena, result_data);2556 return (try mod.intern(.{ .aggregate = .{
2557 .ty = ty.toIntern(),
2558 .storage = .{ .elems = result_data },
2559 } })).toValue();
2596 }2560 }
2597 return bitwiseNandScalar(lhs, rhs, ty, arena, mod);2561 return bitwiseNandScalar(lhs, rhs, ty, arena, mod);
2598 }2562 }
...@@ -2609,13 +2573,17 @@ pub const Value = struct {...@@ -2609,13 +2573,17 @@ pub const Value = struct {
2609 /// operands must be (vectors of) integers; handles undefined scalars.2573 /// operands must be (vectors of) integers; handles undefined scalars.
2610 pub fn bitwiseOr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {2574 pub fn bitwiseOr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
2611 if (ty.zigTypeTag(mod) == .Vector) {2575 if (ty.zigTypeTag(mod) == .Vector) {
2612 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));2576 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2577 const scalar_ty = ty.scalarType(mod);
2613 for (result_data, 0..) |*scalar, i| {2578 for (result_data, 0..) |*scalar, i| {
2614 const lhs_elem = try lhs.elemValue(mod, i);2579 const lhs_elem = try lhs.elemValue(mod, i);
2615 const rhs_elem = try rhs.elemValue(mod, i);2580 const rhs_elem = try rhs.elemValue(mod, i);
2616 scalar.* = try bitwiseOrScalar(lhs_elem, rhs_elem, ty.scalarType(mod), allocator, mod);2581 scalar.* = try (try bitwiseOrScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2617 }2582 }
2618 return Value.Tag.aggregate.create(allocator, result_data);2583 return (try mod.intern(.{ .aggregate = .{
2584 .ty = ty.toIntern(),
2585 .storage = .{ .elems = result_data },
2586 } })).toValue();
2619 }2587 }
2620 return bitwiseOrScalar(lhs, rhs, ty, allocator, mod);2588 return bitwiseOrScalar(lhs, rhs, ty, allocator, mod);
2621 }2589 }
...@@ -2642,14 +2610,17 @@ pub const Value = struct {...@@ -2642,14 +2610,17 @@ pub const Value = struct {
2642 /// operands must be (vectors of) integers; handles undefined scalars.2610 /// operands must be (vectors of) integers; handles undefined scalars.
2643 pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {2611 pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
2644 if (ty.zigTypeTag(mod) == .Vector) {2612 if (ty.zigTypeTag(mod) == .Vector) {
2645 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));2613 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2646 const scalar_ty = ty.scalarType(mod);2614 const scalar_ty = ty.scalarType(mod);
2647 for (result_data, 0..) |*scalar, i| {2615 for (result_data, 0..) |*scalar, i| {
2648 const lhs_elem = try lhs.elemValue(mod, i);2616 const lhs_elem = try lhs.elemValue(mod, i);
2649 const rhs_elem = try rhs.elemValue(mod, i);2617 const rhs_elem = try rhs.elemValue(mod, i);
2650 scalar.* = try bitwiseXorScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);2618 scalar.* = try (try bitwiseXorScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2651 }2619 }
2652 return Value.Tag.aggregate.create(allocator, result_data);2620 return (try mod.intern(.{ .aggregate = .{
2621 .ty = ty.toIntern(),
2622 .storage = .{ .elems = result_data },
2623 } })).toValue();
2653 }2624 }
2654 return bitwiseXorScalar(lhs, rhs, ty, allocator, mod);2625 return bitwiseXorScalar(lhs, rhs, ty, allocator, mod);
2655 }2626 }
...@@ -2676,14 +2647,17 @@ pub const Value = struct {...@@ -2676,14 +2647,17 @@ pub const Value = struct {
26762647
2677 pub fn intDiv(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {2648 pub fn intDiv(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
2678 if (ty.zigTypeTag(mod) == .Vector) {2649 if (ty.zigTypeTag(mod) == .Vector) {
2679 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));2650 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2680 const scalar_ty = ty.scalarType(mod);2651 const scalar_ty = ty.scalarType(mod);
2681 for (result_data, 0..) |*scalar, i| {2652 for (result_data, 0..) |*scalar, i| {
2682 const lhs_elem = try lhs.elemValue(mod, i);2653 const lhs_elem = try lhs.elemValue(mod, i);
2683 const rhs_elem = try rhs.elemValue(mod, i);2654 const rhs_elem = try rhs.elemValue(mod, i);
2684 scalar.* = try intDivScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);2655 scalar.* = try (try intDivScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2685 }2656 }
2686 return Value.Tag.aggregate.create(allocator, result_data);2657 return (try mod.intern(.{ .aggregate = .{
2658 .ty = ty.toIntern(),
2659 .storage = .{ .elems = result_data },
2660 } })).toValue();
2687 }2661 }
2688 return intDivScalar(lhs, rhs, ty, allocator, mod);2662 return intDivScalar(lhs, rhs, ty, allocator, mod);
2689 }2663 }
...@@ -2715,14 +2689,17 @@ pub const Value = struct {...@@ -2715,14 +2689,17 @@ pub const Value = struct {
27152689
2716 pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {2690 pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
2717 if (ty.zigTypeTag(mod) == .Vector) {2691 if (ty.zigTypeTag(mod) == .Vector) {
2718 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));2692 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2719 const scalar_ty = ty.scalarType(mod);2693 const scalar_ty = ty.scalarType(mod);
2720 for (result_data, 0..) |*scalar, i| {2694 for (result_data, 0..) |*scalar, i| {
2721 const lhs_elem = try lhs.elemValue(mod, i);2695 const lhs_elem = try lhs.elemValue(mod, i);
2722 const rhs_elem = try rhs.elemValue(mod, i);2696 const rhs_elem = try rhs.elemValue(mod, i);
2723 scalar.* = try intDivFloorScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);2697 scalar.* = try (try intDivFloorScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2724 }2698 }
2725 return Value.Tag.aggregate.create(allocator, result_data);2699 return (try mod.intern(.{ .aggregate = .{
2700 .ty = ty.toIntern(),
2701 .storage = .{ .elems = result_data },
2702 } })).toValue();
2726 }2703 }
2727 return intDivFloorScalar(lhs, rhs, ty, allocator, mod);2704 return intDivFloorScalar(lhs, rhs, ty, allocator, mod);
2728 }2705 }
...@@ -2754,14 +2731,17 @@ pub const Value = struct {...@@ -2754,14 +2731,17 @@ pub const Value = struct {
27542731
2755 pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {2732 pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
2756 if (ty.zigTypeTag(mod) == .Vector) {2733 if (ty.zigTypeTag(mod) == .Vector) {
2757 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));2734 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2758 const scalar_ty = ty.scalarType(mod);2735 const scalar_ty = ty.scalarType(mod);
2759 for (result_data, 0..) |*scalar, i| {2736 for (result_data, 0..) |*scalar, i| {
2760 const lhs_elem = try lhs.elemValue(mod, i);2737 const lhs_elem = try lhs.elemValue(mod, i);
2761 const rhs_elem = try rhs.elemValue(mod, i);2738 const rhs_elem = try rhs.elemValue(mod, i);
2762 scalar.* = try intModScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);2739 scalar.* = try (try intModScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2763 }2740 }
2764 return Value.Tag.aggregate.create(allocator, result_data);2741 return (try mod.intern(.{ .aggregate = .{
2742 .ty = ty.toIntern(),
2743 .storage = .{ .elems = result_data },
2744 } })).toValue();
2765 }2745 }
2766 return intModScalar(lhs, rhs, ty, allocator, mod);2746 return intModScalar(lhs, rhs, ty, allocator, mod);
2767 }2747 }
...@@ -2794,7 +2774,7 @@ pub const Value = struct {...@@ -2794,7 +2774,7 @@ pub const Value = struct {
2794 /// Returns true if the value is a floating point type and is NaN. Returns false otherwise.2774 /// Returns true if the value is a floating point type and is NaN. Returns false otherwise.
2795 pub fn isNan(val: Value, mod: *const Module) bool {2775 pub fn isNan(val: Value, mod: *const Module) bool {
2796 if (val.ip_index == .none) return false;2776 if (val.ip_index == .none) return false;
2797 return switch (mod.intern_pool.indexToKey(val.ip_index)) {2777 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2798 .float => |float| switch (float.storage) {2778 .float => |float| switch (float.storage) {
2799 inline else => |x| std.math.isNan(x),2779 inline else => |x| std.math.isNan(x),
2800 },2780 },
...@@ -2805,7 +2785,7 @@ pub const Value = struct {...@@ -2805,7 +2785,7 @@ pub const Value = struct {
2805 /// Returns true if the value is a floating point type and is infinite. Returns false otherwise.2785 /// Returns true if the value is a floating point type and is infinite. Returns false otherwise.
2806 pub fn isInf(val: Value, mod: *const Module) bool {2786 pub fn isInf(val: Value, mod: *const Module) bool {
2807 if (val.ip_index == .none) return false;2787 if (val.ip_index == .none) return false;
2808 return switch (mod.intern_pool.indexToKey(val.ip_index)) {2788 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2809 .float => |float| switch (float.storage) {2789 .float => |float| switch (float.storage) {
2810 inline else => |x| std.math.isInf(x),2790 inline else => |x| std.math.isInf(x),
2811 },2791 },
...@@ -2815,7 +2795,7 @@ pub const Value = struct {...@@ -2815,7 +2795,7 @@ pub const Value = struct {
28152795
2816 pub fn isNegativeInf(val: Value, mod: *const Module) bool {2796 pub fn isNegativeInf(val: Value, mod: *const Module) bool {
2817 if (val.ip_index == .none) return false;2797 if (val.ip_index == .none) return false;
2818 return switch (mod.intern_pool.indexToKey(val.ip_index)) {2798 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
2819 .float => |float| switch (float.storage) {2799 .float => |float| switch (float.storage) {
2820 inline else => |x| std.math.isNegativeInf(x),2800 inline else => |x| std.math.isNegativeInf(x),
2821 },2801 },
...@@ -2825,13 +2805,17 @@ pub const Value = struct {...@@ -2825,13 +2805,17 @@ pub const Value = struct {
28252805
2826 pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {2806 pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
2827 if (float_type.zigTypeTag(mod) == .Vector) {2807 if (float_type.zigTypeTag(mod) == .Vector) {
2828 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));2808 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
2809 const scalar_ty = float_type.scalarType(mod);
2829 for (result_data, 0..) |*scalar, i| {2810 for (result_data, 0..) |*scalar, i| {
2830 const lhs_elem = try lhs.elemValue(mod, i);2811 const lhs_elem = try lhs.elemValue(mod, i);
2831 const rhs_elem = try rhs.elemValue(mod, i);2812 const rhs_elem = try rhs.elemValue(mod, i);
2832 scalar.* = try floatRemScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);2813 scalar.* = try (try floatRemScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
2833 }2814 }
2834 return Value.Tag.aggregate.create(arena, result_data);2815 return (try mod.intern(.{ .aggregate = .{
2816 .ty = float_type.toIntern(),
2817 .storage = .{ .elems = result_data },
2818 } })).toValue();
2835 }2819 }
2836 return floatRemScalar(lhs, rhs, float_type, mod);2820 return floatRemScalar(lhs, rhs, float_type, mod);
2837 }2821 }
...@@ -2847,20 +2831,24 @@ pub const Value = struct {...@@ -2847,20 +2831,24 @@ pub const Value = struct {
2847 else => unreachable,2831 else => unreachable,
2848 };2832 };
2849 return (try mod.intern(.{ .float = .{2833 return (try mod.intern(.{ .float = .{
2850 .ty = float_type.ip_index,2834 .ty = float_type.toIntern(),
2851 .storage = storage,2835 .storage = storage,
2852 } })).toValue();2836 } })).toValue();
2853 }2837 }
28542838
2855 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {2839 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
2856 if (float_type.zigTypeTag(mod) == .Vector) {2840 if (float_type.zigTypeTag(mod) == .Vector) {
2857 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));2841 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
2842 const scalar_ty = float_type.scalarType(mod);
2858 for (result_data, 0..) |*scalar, i| {2843 for (result_data, 0..) |*scalar, i| {
2859 const lhs_elem = try lhs.elemValue(mod, i);2844 const lhs_elem = try lhs.elemValue(mod, i);
2860 const rhs_elem = try rhs.elemValue(mod, i);2845 const rhs_elem = try rhs.elemValue(mod, i);
2861 scalar.* = try floatModScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);2846 scalar.* = try (try floatModScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
2862 }2847 }
2863 return Value.Tag.aggregate.create(arena, result_data);2848 return (try mod.intern(.{ .aggregate = .{
2849 .ty = float_type.toIntern(),
2850 .storage = .{ .elems = result_data },
2851 } })).toValue();
2864 }2852 }
2865 return floatModScalar(lhs, rhs, float_type, mod);2853 return floatModScalar(lhs, rhs, float_type, mod);
2866 }2854 }
...@@ -2876,21 +2864,24 @@ pub const Value = struct {...@@ -2876,21 +2864,24 @@ pub const Value = struct {
2876 else => unreachable,2864 else => unreachable,
2877 };2865 };
2878 return (try mod.intern(.{ .float = .{2866 return (try mod.intern(.{ .float = .{
2879 .ty = float_type.ip_index,2867 .ty = float_type.toIntern(),
2880 .storage = storage,2868 .storage = storage,
2881 } })).toValue();2869 } })).toValue();
2882 }2870 }
28832871
2884 pub fn intMul(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {2872 pub fn intMul(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
2885 if (ty.zigTypeTag(mod) == .Vector) {2873 if (ty.zigTypeTag(mod) == .Vector) {
2886 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));2874 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2887 const scalar_ty = ty.scalarType(mod);2875 const scalar_ty = ty.scalarType(mod);
2888 for (result_data, 0..) |*scalar, i| {2876 for (result_data, 0..) |*scalar, i| {
2889 const lhs_elem = try lhs.elemValue(mod, i);2877 const lhs_elem = try lhs.elemValue(mod, i);
2890 const rhs_elem = try rhs.elemValue(mod, i);2878 const rhs_elem = try rhs.elemValue(mod, i);
2891 scalar.* = try intMulScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);2879 scalar.* = try (try intMulScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2892 }2880 }
2893 return Value.Tag.aggregate.create(allocator, result_data);2881 return (try mod.intern(.{ .aggregate = .{
2882 .ty = ty.toIntern(),
2883 .storage = .{ .elems = result_data },
2884 } })).toValue();
2894 }2885 }
2895 return intMulScalar(lhs, rhs, ty, allocator, mod);2886 return intMulScalar(lhs, rhs, ty, allocator, mod);
2896 }2887 }
...@@ -2918,13 +2909,16 @@ pub const Value = struct {...@@ -2918,13 +2909,16 @@ pub const Value = struct {
29182909
2919 pub fn intTrunc(val: Value, ty: Type, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, mod: *Module) !Value {2910 pub fn intTrunc(val: Value, ty: Type, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, mod: *Module) !Value {
2920 if (ty.zigTypeTag(mod) == .Vector) {2911 if (ty.zigTypeTag(mod) == .Vector) {
2921 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));2912 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2922 const scalar_ty = ty.scalarType(mod);2913 const scalar_ty = ty.scalarType(mod);
2923 for (result_data, 0..) |*scalar, i| {2914 for (result_data, 0..) |*scalar, i| {
2924 const elem_val = try val.elemValue(mod, i);2915 const elem_val = try val.elemValue(mod, i);
2925 scalar.* = try intTruncScalar(elem_val, scalar_ty, allocator, signedness, bits, mod);2916 scalar.* = try (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, bits, mod)).intern(scalar_ty, mod);
2926 }2917 }
2927 return Value.Tag.aggregate.create(allocator, result_data);2918 return (try mod.intern(.{ .aggregate = .{
2919 .ty = ty.toIntern(),
2920 .storage = .{ .elems = result_data },
2921 } })).toValue();
2928 }2922 }
2929 return intTruncScalar(val, ty, allocator, signedness, bits, mod);2923 return intTruncScalar(val, ty, allocator, signedness, bits, mod);
2930 }2924 }
...@@ -2939,14 +2933,17 @@ pub const Value = struct {...@@ -2939,14 +2933,17 @@ pub const Value = struct {
2939 mod: *Module,2933 mod: *Module,
2940 ) !Value {2934 ) !Value {
2941 if (ty.zigTypeTag(mod) == .Vector) {2935 if (ty.zigTypeTag(mod) == .Vector) {
2942 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));2936 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2943 const scalar_ty = ty.scalarType(mod);2937 const scalar_ty = ty.scalarType(mod);
2944 for (result_data, 0..) |*scalar, i| {2938 for (result_data, 0..) |*scalar, i| {
2945 const elem_val = try val.elemValue(mod, i);2939 const elem_val = try val.elemValue(mod, i);
2946 const bits_elem = try bits.elemValue(mod, i);2940 const bits_elem = try bits.elemValue(mod, i);
2947 scalar.* = try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @intCast(u16, bits_elem.toUnsignedInt(mod)), mod);2941 scalar.* = try (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @intCast(u16, bits_elem.toUnsignedInt(mod)), mod)).intern(scalar_ty, mod);
2948 }2942 }
2949 return Value.Tag.aggregate.create(allocator, result_data);2943 return (try mod.intern(.{ .aggregate = .{
2944 .ty = ty.toIntern(),
2945 .storage = .{ .elems = result_data },
2946 } })).toValue();
2950 }2947 }
2951 return intTruncScalar(val, ty, allocator, signedness, @intCast(u16, bits.toUnsignedInt(mod)), mod);2948 return intTruncScalar(val, ty, allocator, signedness, @intCast(u16, bits.toUnsignedInt(mod)), mod);
2952 }2949 }
...@@ -2976,14 +2973,17 @@ pub const Value = struct {...@@ -2976,14 +2973,17 @@ pub const Value = struct {
29762973
2977 pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {2974 pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
2978 if (ty.zigTypeTag(mod) == .Vector) {2975 if (ty.zigTypeTag(mod) == .Vector) {
2979 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));2976 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
2980 const scalar_ty = ty.scalarType(mod);2977 const scalar_ty = ty.scalarType(mod);
2981 for (result_data, 0..) |*scalar, i| {2978 for (result_data, 0..) |*scalar, i| {
2982 const lhs_elem = try lhs.elemValue(mod, i);2979 const lhs_elem = try lhs.elemValue(mod, i);
2983 const rhs_elem = try rhs.elemValue(mod, i);2980 const rhs_elem = try rhs.elemValue(mod, i);
2984 scalar.* = try shlScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);2981 scalar.* = try (try shlScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2985 }2982 }
2986 return Value.Tag.aggregate.create(allocator, result_data);2983 return (try mod.intern(.{ .aggregate = .{
2984 .ty = ty.toIntern(),
2985 .storage = .{ .elems = result_data },
2986 } })).toValue();
2987 }2987 }
2988 return shlScalar(lhs, rhs, ty, allocator, mod);2988 return shlScalar(lhs, rhs, ty, allocator, mod);
2989 }2989 }
...@@ -3015,18 +3015,26 @@ pub const Value = struct {...@@ -3015,18 +3015,26 @@ pub const Value = struct {
3015 mod: *Module,3015 mod: *Module,
3016 ) !OverflowArithmeticResult {3016 ) !OverflowArithmeticResult {
3017 if (ty.zigTypeTag(mod) == .Vector) {3017 if (ty.zigTypeTag(mod) == .Vector) {
3018 const overflowed_data = try allocator.alloc(Value, ty.vectorLen(mod));3018 const vec_len = ty.vectorLen(mod);
3019 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));3019 const overflowed_data = try allocator.alloc(InternPool.Index, vec_len);
3020 for (result_data, 0..) |*scalar, i| {3020 const result_data = try allocator.alloc(InternPool.Index, vec_len);
3021 const scalar_ty = ty.scalarType(mod);
3022 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
3021 const lhs_elem = try lhs.elemValue(mod, i);3023 const lhs_elem = try lhs.elemValue(mod, i);
3022 const rhs_elem = try rhs.elemValue(mod, i);3024 const rhs_elem = try rhs.elemValue(mod, i);
3023 const of_math_result = try shlWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(mod), allocator, mod);3025 const of_math_result = try shlWithOverflowScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);
3024 overflowed_data[i] = of_math_result.overflow_bit;3026 of.* = try of_math_result.overflow_bit.intern(Type.bool, mod);
3025 scalar.* = of_math_result.wrapped_result;3027 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
3026 }3028 }
3027 return OverflowArithmeticResult{3029 return OverflowArithmeticResult{
3028 .overflow_bit = try Value.Tag.aggregate.create(allocator, overflowed_data),3030 .overflow_bit = (try mod.intern(.{ .aggregate = .{
3029 .wrapped_result = try Value.Tag.aggregate.create(allocator, result_data),3031 .ty = ty.toIntern(),
3032 .storage = .{ .elems = overflowed_data },
3033 } })).toValue(),
3034 .wrapped_result = (try mod.intern(.{ .aggregate = .{
3035 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),
3036 .storage = .{ .elems = result_data },
3037 } })).toValue(),
3030 };3038 };
3031 }3039 }
3032 return shlWithOverflowScalar(lhs, rhs, ty, allocator, mod);3040 return shlWithOverflowScalar(lhs, rhs, ty, allocator, mod);
...@@ -3071,13 +3079,17 @@ pub const Value = struct {...@@ -3071,13 +3079,17 @@ pub const Value = struct {
3071 mod: *Module,3079 mod: *Module,
3072 ) !Value {3080 ) !Value {
3073 if (ty.zigTypeTag(mod) == .Vector) {3081 if (ty.zigTypeTag(mod) == .Vector) {
3074 const result_data = try arena.alloc(Value, ty.vectorLen(mod));3082 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));
3083 const scalar_ty = ty.scalarType(mod);
3075 for (result_data, 0..) |*scalar, i| {3084 for (result_data, 0..) |*scalar, i| {
3076 const lhs_elem = try lhs.elemValue(mod, i);3085 const lhs_elem = try lhs.elemValue(mod, i);
3077 const rhs_elem = try rhs.elemValue(mod, i);3086 const rhs_elem = try rhs.elemValue(mod, i);
3078 scalar.* = try shlSatScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);3087 scalar.* = try (try shlSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
3079 }3088 }
3080 return Value.Tag.aggregate.create(arena, result_data);3089 return (try mod.intern(.{ .aggregate = .{
3090 .ty = ty.toIntern(),
3091 .storage = .{ .elems = result_data },
3092 } })).toValue();
3081 }3093 }
3082 return shlSatScalar(lhs, rhs, ty, arena, mod);3094 return shlSatScalar(lhs, rhs, ty, arena, mod);
3083 }3095 }
...@@ -3117,13 +3129,17 @@ pub const Value = struct {...@@ -3117,13 +3129,17 @@ pub const Value = struct {
3117 mod: *Module,3129 mod: *Module,
3118 ) !Value {3130 ) !Value {
3119 if (ty.zigTypeTag(mod) == .Vector) {3131 if (ty.zigTypeTag(mod) == .Vector) {
3120 const result_data = try arena.alloc(Value, ty.vectorLen(mod));3132 const result_data = try arena.alloc(InternPool.Index, ty.vectorLen(mod));
3133 const scalar_ty = ty.scalarType(mod);
3121 for (result_data, 0..) |*scalar, i| {3134 for (result_data, 0..) |*scalar, i| {
3122 const lhs_elem = try lhs.elemValue(mod, i);3135 const lhs_elem = try lhs.elemValue(mod, i);
3123 const rhs_elem = try rhs.elemValue(mod, i);3136 const rhs_elem = try rhs.elemValue(mod, i);
3124 scalar.* = try shlTruncScalar(lhs_elem, rhs_elem, ty.scalarType(mod), arena, mod);3137 scalar.* = try (try shlTruncScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
3125 }3138 }
3126 return Value.Tag.aggregate.create(arena, result_data);3139 return (try mod.intern(.{ .aggregate = .{
3140 .ty = ty.toIntern(),
3141 .storage = .{ .elems = result_data },
3142 } })).toValue();
3127 }3143 }
3128 return shlTruncScalar(lhs, rhs, ty, arena, mod);3144 return shlTruncScalar(lhs, rhs, ty, arena, mod);
3129 }3145 }
...@@ -3143,14 +3159,17 @@ pub const Value = struct {...@@ -3143,14 +3159,17 @@ pub const Value = struct {
31433159
3144 pub fn shr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {3160 pub fn shr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
3145 if (ty.zigTypeTag(mod) == .Vector) {3161 if (ty.zigTypeTag(mod) == .Vector) {
3146 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));3162 const result_data = try allocator.alloc(InternPool.Index, ty.vectorLen(mod));
3147 const scalar_ty = ty.scalarType(mod);3163 const scalar_ty = ty.scalarType(mod);
3148 for (result_data, 0..) |*scalar, i| {3164 for (result_data, 0..) |*scalar, i| {
3149 const lhs_elem = try lhs.elemValue(mod, i);3165 const lhs_elem = try lhs.elemValue(mod, i);
3150 const rhs_elem = try rhs.elemValue(mod, i);3166 const rhs_elem = try rhs.elemValue(mod, i);
3151 scalar.* = try shrScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);3167 scalar.* = try (try shrScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
3152 }3168 }
3153 return Value.Tag.aggregate.create(allocator, result_data);3169 return (try mod.intern(.{ .aggregate = .{
3170 .ty = ty.toIntern(),
3171 .storage = .{ .elems = result_data },
3172 } })).toValue();
3154 }3173 }
3155 return shrScalar(lhs, rhs, ty, allocator, mod);3174 return shrScalar(lhs, rhs, ty, allocator, mod);
3156 }3175 }
...@@ -3193,12 +3212,16 @@ pub const Value = struct {...@@ -3193,12 +3212,16 @@ pub const Value = struct {
3193 mod: *Module,3212 mod: *Module,
3194 ) !Value {3213 ) !Value {
3195 if (float_type.zigTypeTag(mod) == .Vector) {3214 if (float_type.zigTypeTag(mod) == .Vector) {
3196 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3215 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3216 const scalar_ty = float_type.scalarType(mod);
3197 for (result_data, 0..) |*scalar, i| {3217 for (result_data, 0..) |*scalar, i| {
3198 const elem_val = try val.elemValue(mod, i);3218 const elem_val = try val.elemValue(mod, i);
3199 scalar.* = try floatNegScalar(elem_val, float_type.scalarType(mod), mod);3219 scalar.* = try (try floatNegScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3200 }3220 }
3201 return Value.Tag.aggregate.create(arena, result_data);3221 return (try mod.intern(.{ .aggregate = .{
3222 .ty = float_type.toIntern(),
3223 .storage = .{ .elems = result_data },
3224 } })).toValue();
3202 }3225 }
3203 return floatNegScalar(val, float_type, mod);3226 return floatNegScalar(val, float_type, mod);
3204 }3227 }
...@@ -3218,7 +3241,7 @@ pub const Value = struct {...@@ -3218,7 +3241,7 @@ pub const Value = struct {
3218 else => unreachable,3241 else => unreachable,
3219 };3242 };
3220 return (try mod.intern(.{ .float = .{3243 return (try mod.intern(.{ .float = .{
3221 .ty = float_type.ip_index,3244 .ty = float_type.toIntern(),
3222 .storage = storage,3245 .storage = storage,
3223 } })).toValue();3246 } })).toValue();
3224 }3247 }
...@@ -3231,13 +3254,17 @@ pub const Value = struct {...@@ -3231,13 +3254,17 @@ pub const Value = struct {
3231 mod: *Module,3254 mod: *Module,
3232 ) !Value {3255 ) !Value {
3233 if (float_type.zigTypeTag(mod) == .Vector) {3256 if (float_type.zigTypeTag(mod) == .Vector) {
3234 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3257 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3258 const scalar_ty = float_type.scalarType(mod);
3235 for (result_data, 0..) |*scalar, i| {3259 for (result_data, 0..) |*scalar, i| {
3236 const lhs_elem = try lhs.elemValue(mod, i);3260 const lhs_elem = try lhs.elemValue(mod, i);
3237 const rhs_elem = try rhs.elemValue(mod, i);3261 const rhs_elem = try rhs.elemValue(mod, i);
3238 scalar.* = try floatAddScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);3262 scalar.* = try (try floatAddScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
3239 }3263 }
3240 return Value.Tag.aggregate.create(arena, result_data);3264 return (try mod.intern(.{ .aggregate = .{
3265 .ty = float_type.toIntern(),
3266 .storage = .{ .elems = result_data },
3267 } })).toValue();
3241 }3268 }
3242 return floatAddScalar(lhs, rhs, float_type, mod);3269 return floatAddScalar(lhs, rhs, float_type, mod);
3243 }3270 }
...@@ -3258,7 +3285,7 @@ pub const Value = struct {...@@ -3258,7 +3285,7 @@ pub const Value = struct {
3258 else => unreachable,3285 else => unreachable,
3259 };3286 };
3260 return (try mod.intern(.{ .float = .{3287 return (try mod.intern(.{ .float = .{
3261 .ty = float_type.ip_index,3288 .ty = float_type.toIntern(),
3262 .storage = storage,3289 .storage = storage,
3263 } })).toValue();3290 } })).toValue();
3264 }3291 }
...@@ -3271,13 +3298,17 @@ pub const Value = struct {...@@ -3271,13 +3298,17 @@ pub const Value = struct {
3271 mod: *Module,3298 mod: *Module,
3272 ) !Value {3299 ) !Value {
3273 if (float_type.zigTypeTag(mod) == .Vector) {3300 if (float_type.zigTypeTag(mod) == .Vector) {
3274 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3301 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3302 const scalar_ty = float_type.scalarType(mod);
3275 for (result_data, 0..) |*scalar, i| {3303 for (result_data, 0..) |*scalar, i| {
3276 const lhs_elem = try lhs.elemValue(mod, i);3304 const lhs_elem = try lhs.elemValue(mod, i);
3277 const rhs_elem = try rhs.elemValue(mod, i);3305 const rhs_elem = try rhs.elemValue(mod, i);
3278 scalar.* = try floatSubScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);3306 scalar.* = try (try floatSubScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
3279 }3307 }
3280 return Value.Tag.aggregate.create(arena, result_data);3308 return (try mod.intern(.{ .aggregate = .{
3309 .ty = float_type.toIntern(),
3310 .storage = .{ .elems = result_data },
3311 } })).toValue();
3281 }3312 }
3282 return floatSubScalar(lhs, rhs, float_type, mod);3313 return floatSubScalar(lhs, rhs, float_type, mod);
3283 }3314 }
...@@ -3298,7 +3329,7 @@ pub const Value = struct {...@@ -3298,7 +3329,7 @@ pub const Value = struct {
3298 else => unreachable,3329 else => unreachable,
3299 };3330 };
3300 return (try mod.intern(.{ .float = .{3331 return (try mod.intern(.{ .float = .{
3301 .ty = float_type.ip_index,3332 .ty = float_type.toIntern(),
3302 .storage = storage,3333 .storage = storage,
3303 } })).toValue();3334 } })).toValue();
3304 }3335 }
...@@ -3311,13 +3342,17 @@ pub const Value = struct {...@@ -3311,13 +3342,17 @@ pub const Value = struct {
3311 mod: *Module,3342 mod: *Module,
3312 ) !Value {3343 ) !Value {
3313 if (float_type.zigTypeTag(mod) == .Vector) {3344 if (float_type.zigTypeTag(mod) == .Vector) {
3314 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3345 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3346 const scalar_ty = float_type.scalarType(mod);
3315 for (result_data, 0..) |*scalar, i| {3347 for (result_data, 0..) |*scalar, i| {
3316 const lhs_elem = try lhs.elemValue(mod, i);3348 const lhs_elem = try lhs.elemValue(mod, i);
3317 const rhs_elem = try rhs.elemValue(mod, i);3349 const rhs_elem = try rhs.elemValue(mod, i);
3318 scalar.* = try floatDivScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);3350 scalar.* = try (try floatDivScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
3319 }3351 }
3320 return Value.Tag.aggregate.create(arena, result_data);3352 return (try mod.intern(.{ .aggregate = .{
3353 .ty = float_type.toIntern(),
3354 .storage = .{ .elems = result_data },
3355 } })).toValue();
3321 }3356 }
3322 return floatDivScalar(lhs, rhs, float_type, mod);3357 return floatDivScalar(lhs, rhs, float_type, mod);
3323 }3358 }
...@@ -3338,7 +3373,7 @@ pub const Value = struct {...@@ -3338,7 +3373,7 @@ pub const Value = struct {
3338 else => unreachable,3373 else => unreachable,
3339 };3374 };
3340 return (try mod.intern(.{ .float = .{3375 return (try mod.intern(.{ .float = .{
3341 .ty = float_type.ip_index,3376 .ty = float_type.toIntern(),
3342 .storage = storage,3377 .storage = storage,
3343 } })).toValue();3378 } })).toValue();
3344 }3379 }
...@@ -3351,13 +3386,17 @@ pub const Value = struct {...@@ -3351,13 +3386,17 @@ pub const Value = struct {
3351 mod: *Module,3386 mod: *Module,
3352 ) !Value {3387 ) !Value {
3353 if (float_type.zigTypeTag(mod) == .Vector) {3388 if (float_type.zigTypeTag(mod) == .Vector) {
3354 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3389 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3390 const scalar_ty = float_type.scalarType(mod);
3355 for (result_data, 0..) |*scalar, i| {3391 for (result_data, 0..) |*scalar, i| {
3356 const lhs_elem = try lhs.elemValue(mod, i);3392 const lhs_elem = try lhs.elemValue(mod, i);
3357 const rhs_elem = try rhs.elemValue(mod, i);3393 const rhs_elem = try rhs.elemValue(mod, i);
3358 scalar.* = try floatDivFloorScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);3394 scalar.* = try (try floatDivFloorScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
3359 }3395 }
3360 return Value.Tag.aggregate.create(arena, result_data);3396 return (try mod.intern(.{ .aggregate = .{
3397 .ty = float_type.toIntern(),
3398 .storage = .{ .elems = result_data },
3399 } })).toValue();
3361 }3400 }
3362 return floatDivFloorScalar(lhs, rhs, float_type, mod);3401 return floatDivFloorScalar(lhs, rhs, float_type, mod);
3363 }3402 }
...@@ -3378,7 +3417,7 @@ pub const Value = struct {...@@ -3378,7 +3417,7 @@ pub const Value = struct {
3378 else => unreachable,3417 else => unreachable,
3379 };3418 };
3380 return (try mod.intern(.{ .float = .{3419 return (try mod.intern(.{ .float = .{
3381 .ty = float_type.ip_index,3420 .ty = float_type.toIntern(),
3382 .storage = storage,3421 .storage = storage,
3383 } })).toValue();3422 } })).toValue();
3384 }3423 }
...@@ -3391,13 +3430,17 @@ pub const Value = struct {...@@ -3391,13 +3430,17 @@ pub const Value = struct {
3391 mod: *Module,3430 mod: *Module,
3392 ) !Value {3431 ) !Value {
3393 if (float_type.zigTypeTag(mod) == .Vector) {3432 if (float_type.zigTypeTag(mod) == .Vector) {
3394 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3433 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3434 const scalar_ty = float_type.scalarType(mod);
3395 for (result_data, 0..) |*scalar, i| {3435 for (result_data, 0..) |*scalar, i| {
3396 const lhs_elem = try lhs.elemValue(mod, i);3436 const lhs_elem = try lhs.elemValue(mod, i);
3397 const rhs_elem = try rhs.elemValue(mod, i);3437 const rhs_elem = try rhs.elemValue(mod, i);
3398 scalar.* = try floatDivTruncScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);3438 scalar.* = try (try floatDivTruncScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
3399 }3439 }
3400 return Value.Tag.aggregate.create(arena, result_data);3440 return (try mod.intern(.{ .aggregate = .{
3441 .ty = float_type.toIntern(),
3442 .storage = .{ .elems = result_data },
3443 } })).toValue();
3401 }3444 }
3402 return floatDivTruncScalar(lhs, rhs, float_type, mod);3445 return floatDivTruncScalar(lhs, rhs, float_type, mod);
3403 }3446 }
...@@ -3418,7 +3461,7 @@ pub const Value = struct {...@@ -3418,7 +3461,7 @@ pub const Value = struct {
3418 else => unreachable,3461 else => unreachable,
3419 };3462 };
3420 return (try mod.intern(.{ .float = .{3463 return (try mod.intern(.{ .float = .{
3421 .ty = float_type.ip_index,3464 .ty = float_type.toIntern(),
3422 .storage = storage,3465 .storage = storage,
3423 } })).toValue();3466 } })).toValue();
3424 }3467 }
...@@ -3431,13 +3474,17 @@ pub const Value = struct {...@@ -3431,13 +3474,17 @@ pub const Value = struct {
3431 mod: *Module,3474 mod: *Module,
3432 ) !Value {3475 ) !Value {
3433 if (float_type.zigTypeTag(mod) == .Vector) {3476 if (float_type.zigTypeTag(mod) == .Vector) {
3434 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3477 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3478 const scalar_ty = float_type.scalarType(mod);
3435 for (result_data, 0..) |*scalar, i| {3479 for (result_data, 0..) |*scalar, i| {
3436 const lhs_elem = try lhs.elemValue(mod, i);3480 const lhs_elem = try lhs.elemValue(mod, i);
3437 const rhs_elem = try rhs.elemValue(mod, i);3481 const rhs_elem = try rhs.elemValue(mod, i);
3438 scalar.* = try floatMulScalar(lhs_elem, rhs_elem, float_type.scalarType(mod), mod);3482 scalar.* = try (try floatMulScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
3439 }3483 }
3440 return Value.Tag.aggregate.create(arena, result_data);3484 return (try mod.intern(.{ .aggregate = .{
3485 .ty = float_type.toIntern(),
3486 .storage = .{ .elems = result_data },
3487 } })).toValue();
3441 }3488 }
3442 return floatMulScalar(lhs, rhs, float_type, mod);3489 return floatMulScalar(lhs, rhs, float_type, mod);
3443 }3490 }
...@@ -3458,19 +3505,23 @@ pub const Value = struct {...@@ -3458,19 +3505,23 @@ pub const Value = struct {
3458 else => unreachable,3505 else => unreachable,
3459 };3506 };
3460 return (try mod.intern(.{ .float = .{3507 return (try mod.intern(.{ .float = .{
3461 .ty = float_type.ip_index,3508 .ty = float_type.toIntern(),
3462 .storage = storage,3509 .storage = storage,
3463 } })).toValue();3510 } })).toValue();
3464 }3511 }
34653512
3466 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3513 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3467 if (float_type.zigTypeTag(mod) == .Vector) {3514 if (float_type.zigTypeTag(mod) == .Vector) {
3468 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3515 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3516 const scalar_ty = float_type.scalarType(mod);
3469 for (result_data, 0..) |*scalar, i| {3517 for (result_data, 0..) |*scalar, i| {
3470 const elem_val = try val.elemValue(mod, i);3518 const elem_val = try val.elemValue(mod, i);
3471 scalar.* = try sqrtScalar(elem_val, float_type.scalarType(mod), mod);3519 scalar.* = try (try sqrtScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3472 }3520 }
3473 return Value.Tag.aggregate.create(arena, result_data);3521 return (try mod.intern(.{ .aggregate = .{
3522 .ty = float_type.toIntern(),
3523 .storage = .{ .elems = result_data },
3524 } })).toValue();
3474 }3525 }
3475 return sqrtScalar(val, float_type, mod);3526 return sqrtScalar(val, float_type, mod);
3476 }3527 }
...@@ -3486,19 +3537,23 @@ pub const Value = struct {...@@ -3486,19 +3537,23 @@ pub const Value = struct {
3486 else => unreachable,3537 else => unreachable,
3487 };3538 };
3488 return (try mod.intern(.{ .float = .{3539 return (try mod.intern(.{ .float = .{
3489 .ty = float_type.ip_index,3540 .ty = float_type.toIntern(),
3490 .storage = storage,3541 .storage = storage,
3491 } })).toValue();3542 } })).toValue();
3492 }3543 }
34933544
3494 pub fn sin(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3545 pub fn sin(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3495 if (float_type.zigTypeTag(mod) == .Vector) {3546 if (float_type.zigTypeTag(mod) == .Vector) {
3496 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3547 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3548 const scalar_ty = float_type.scalarType(mod);
3497 for (result_data, 0..) |*scalar, i| {3549 for (result_data, 0..) |*scalar, i| {
3498 const elem_val = try val.elemValue(mod, i);3550 const elem_val = try val.elemValue(mod, i);
3499 scalar.* = try sinScalar(elem_val, float_type.scalarType(mod), mod);3551 scalar.* = try (try sinScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3500 }3552 }
3501 return Value.Tag.aggregate.create(arena, result_data);3553 return (try mod.intern(.{ .aggregate = .{
3554 .ty = float_type.toIntern(),
3555 .storage = .{ .elems = result_data },
3556 } })).toValue();
3502 }3557 }
3503 return sinScalar(val, float_type, mod);3558 return sinScalar(val, float_type, mod);
3504 }3559 }
...@@ -3514,19 +3569,23 @@ pub const Value = struct {...@@ -3514,19 +3569,23 @@ pub const Value = struct {
3514 else => unreachable,3569 else => unreachable,
3515 };3570 };
3516 return (try mod.intern(.{ .float = .{3571 return (try mod.intern(.{ .float = .{
3517 .ty = float_type.ip_index,3572 .ty = float_type.toIntern(),
3518 .storage = storage,3573 .storage = storage,
3519 } })).toValue();3574 } })).toValue();
3520 }3575 }
35213576
3522 pub fn cos(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3577 pub fn cos(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3523 if (float_type.zigTypeTag(mod) == .Vector) {3578 if (float_type.zigTypeTag(mod) == .Vector) {
3524 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3579 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3580 const scalar_ty = float_type.scalarType(mod);
3525 for (result_data, 0..) |*scalar, i| {3581 for (result_data, 0..) |*scalar, i| {
3526 const elem_val = try val.elemValue(mod, i);3582 const elem_val = try val.elemValue(mod, i);
3527 scalar.* = try cosScalar(elem_val, float_type.scalarType(mod), mod);3583 scalar.* = try (try cosScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3528 }3584 }
3529 return Value.Tag.aggregate.create(arena, result_data);3585 return (try mod.intern(.{ .aggregate = .{
3586 .ty = float_type.toIntern(),
3587 .storage = .{ .elems = result_data },
3588 } })).toValue();
3530 }3589 }
3531 return cosScalar(val, float_type, mod);3590 return cosScalar(val, float_type, mod);
3532 }3591 }
...@@ -3542,19 +3601,23 @@ pub const Value = struct {...@@ -3542,19 +3601,23 @@ pub const Value = struct {
3542 else => unreachable,3601 else => unreachable,
3543 };3602 };
3544 return (try mod.intern(.{ .float = .{3603 return (try mod.intern(.{ .float = .{
3545 .ty = float_type.ip_index,3604 .ty = float_type.toIntern(),
3546 .storage = storage,3605 .storage = storage,
3547 } })).toValue();3606 } })).toValue();
3548 }3607 }
35493608
3550 pub fn tan(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3609 pub fn tan(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3551 if (float_type.zigTypeTag(mod) == .Vector) {3610 if (float_type.zigTypeTag(mod) == .Vector) {
3552 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3611 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3612 const scalar_ty = float_type.scalarType(mod);
3553 for (result_data, 0..) |*scalar, i| {3613 for (result_data, 0..) |*scalar, i| {
3554 const elem_val = try val.elemValue(mod, i);3614 const elem_val = try val.elemValue(mod, i);
3555 scalar.* = try tanScalar(elem_val, float_type.scalarType(mod), mod);3615 scalar.* = try (try tanScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3556 }3616 }
3557 return Value.Tag.aggregate.create(arena, result_data);3617 return (try mod.intern(.{ .aggregate = .{
3618 .ty = float_type.toIntern(),
3619 .storage = .{ .elems = result_data },
3620 } })).toValue();
3558 }3621 }
3559 return tanScalar(val, float_type, mod);3622 return tanScalar(val, float_type, mod);
3560 }3623 }
...@@ -3570,19 +3633,23 @@ pub const Value = struct {...@@ -3570,19 +3633,23 @@ pub const Value = struct {
3570 else => unreachable,3633 else => unreachable,
3571 };3634 };
3572 return (try mod.intern(.{ .float = .{3635 return (try mod.intern(.{ .float = .{
3573 .ty = float_type.ip_index,3636 .ty = float_type.toIntern(),
3574 .storage = storage,3637 .storage = storage,
3575 } })).toValue();3638 } })).toValue();
3576 }3639 }
35773640
3578 pub fn exp(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3641 pub fn exp(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3579 if (float_type.zigTypeTag(mod) == .Vector) {3642 if (float_type.zigTypeTag(mod) == .Vector) {
3580 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3643 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3644 const scalar_ty = float_type.scalarType(mod);
3581 for (result_data, 0..) |*scalar, i| {3645 for (result_data, 0..) |*scalar, i| {
3582 const elem_val = try val.elemValue(mod, i);3646 const elem_val = try val.elemValue(mod, i);
3583 scalar.* = try expScalar(elem_val, float_type.scalarType(mod), mod);3647 scalar.* = try (try expScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3584 }3648 }
3585 return Value.Tag.aggregate.create(arena, result_data);3649 return (try mod.intern(.{ .aggregate = .{
3650 .ty = float_type.toIntern(),
3651 .storage = .{ .elems = result_data },
3652 } })).toValue();
3586 }3653 }
3587 return expScalar(val, float_type, mod);3654 return expScalar(val, float_type, mod);
3588 }3655 }
...@@ -3598,19 +3665,23 @@ pub const Value = struct {...@@ -3598,19 +3665,23 @@ pub const Value = struct {
3598 else => unreachable,3665 else => unreachable,
3599 };3666 };
3600 return (try mod.intern(.{ .float = .{3667 return (try mod.intern(.{ .float = .{
3601 .ty = float_type.ip_index,3668 .ty = float_type.toIntern(),
3602 .storage = storage,3669 .storage = storage,
3603 } })).toValue();3670 } })).toValue();
3604 }3671 }
36053672
3606 pub fn exp2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3673 pub fn exp2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3607 if (float_type.zigTypeTag(mod) == .Vector) {3674 if (float_type.zigTypeTag(mod) == .Vector) {
3608 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3675 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3676 const scalar_ty = float_type.scalarType(mod);
3609 for (result_data, 0..) |*scalar, i| {3677 for (result_data, 0..) |*scalar, i| {
3610 const elem_val = try val.elemValue(mod, i);3678 const elem_val = try val.elemValue(mod, i);
3611 scalar.* = try exp2Scalar(elem_val, float_type.scalarType(mod), mod);3679 scalar.* = try (try exp2Scalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3612 }3680 }
3613 return Value.Tag.aggregate.create(arena, result_data);3681 return (try mod.intern(.{ .aggregate = .{
3682 .ty = float_type.toIntern(),
3683 .storage = .{ .elems = result_data },
3684 } })).toValue();
3614 }3685 }
3615 return exp2Scalar(val, float_type, mod);3686 return exp2Scalar(val, float_type, mod);
3616 }3687 }
...@@ -3626,19 +3697,23 @@ pub const Value = struct {...@@ -3626,19 +3697,23 @@ pub const Value = struct {
3626 else => unreachable,3697 else => unreachable,
3627 };3698 };
3628 return (try mod.intern(.{ .float = .{3699 return (try mod.intern(.{ .float = .{
3629 .ty = float_type.ip_index,3700 .ty = float_type.toIntern(),
3630 .storage = storage,3701 .storage = storage,
3631 } })).toValue();3702 } })).toValue();
3632 }3703 }
36333704
3634 pub fn log(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3705 pub fn log(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3635 if (float_type.zigTypeTag(mod) == .Vector) {3706 if (float_type.zigTypeTag(mod) == .Vector) {
3636 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3707 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3708 const scalar_ty = float_type.scalarType(mod);
3637 for (result_data, 0..) |*scalar, i| {3709 for (result_data, 0..) |*scalar, i| {
3638 const elem_val = try val.elemValue(mod, i);3710 const elem_val = try val.elemValue(mod, i);
3639 scalar.* = try logScalar(elem_val, float_type.scalarType(mod), mod);3711 scalar.* = try (try logScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3640 }3712 }
3641 return Value.Tag.aggregate.create(arena, result_data);3713 return (try mod.intern(.{ .aggregate = .{
3714 .ty = float_type.toIntern(),
3715 .storage = .{ .elems = result_data },
3716 } })).toValue();
3642 }3717 }
3643 return logScalar(val, float_type, mod);3718 return logScalar(val, float_type, mod);
3644 }3719 }
...@@ -3654,19 +3729,23 @@ pub const Value = struct {...@@ -3654,19 +3729,23 @@ pub const Value = struct {
3654 else => unreachable,3729 else => unreachable,
3655 };3730 };
3656 return (try mod.intern(.{ .float = .{3731 return (try mod.intern(.{ .float = .{
3657 .ty = float_type.ip_index,3732 .ty = float_type.toIntern(),
3658 .storage = storage,3733 .storage = storage,
3659 } })).toValue();3734 } })).toValue();
3660 }3735 }
36613736
3662 pub fn log2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3737 pub fn log2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3663 if (float_type.zigTypeTag(mod) == .Vector) {3738 if (float_type.zigTypeTag(mod) == .Vector) {
3664 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3739 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3740 const scalar_ty = float_type.scalarType(mod);
3665 for (result_data, 0..) |*scalar, i| {3741 for (result_data, 0..) |*scalar, i| {
3666 const elem_val = try val.elemValue(mod, i);3742 const elem_val = try val.elemValue(mod, i);
3667 scalar.* = try log2Scalar(elem_val, float_type.scalarType(mod), mod);3743 scalar.* = try (try log2Scalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3668 }3744 }
3669 return Value.Tag.aggregate.create(arena, result_data);3745 return (try mod.intern(.{ .aggregate = .{
3746 .ty = float_type.toIntern(),
3747 .storage = .{ .elems = result_data },
3748 } })).toValue();
3670 }3749 }
3671 return log2Scalar(val, float_type, mod);3750 return log2Scalar(val, float_type, mod);
3672 }3751 }
...@@ -3682,19 +3761,23 @@ pub const Value = struct {...@@ -3682,19 +3761,23 @@ pub const Value = struct {
3682 else => unreachable,3761 else => unreachable,
3683 };3762 };
3684 return (try mod.intern(.{ .float = .{3763 return (try mod.intern(.{ .float = .{
3685 .ty = float_type.ip_index,3764 .ty = float_type.toIntern(),
3686 .storage = storage,3765 .storage = storage,
3687 } })).toValue();3766 } })).toValue();
3688 }3767 }
36893768
3690 pub fn log10(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3769 pub fn log10(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3691 if (float_type.zigTypeTag(mod) == .Vector) {3770 if (float_type.zigTypeTag(mod) == .Vector) {
3692 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3771 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3772 const scalar_ty = float_type.scalarType(mod);
3693 for (result_data, 0..) |*scalar, i| {3773 for (result_data, 0..) |*scalar, i| {
3694 const elem_val = try val.elemValue(mod, i);3774 const elem_val = try val.elemValue(mod, i);
3695 scalar.* = try log10Scalar(elem_val, float_type.scalarType(mod), mod);3775 scalar.* = try (try log10Scalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3696 }3776 }
3697 return Value.Tag.aggregate.create(arena, result_data);3777 return (try mod.intern(.{ .aggregate = .{
3778 .ty = float_type.toIntern(),
3779 .storage = .{ .elems = result_data },
3780 } })).toValue();
3698 }3781 }
3699 return log10Scalar(val, float_type, mod);3782 return log10Scalar(val, float_type, mod);
3700 }3783 }
...@@ -3710,19 +3793,23 @@ pub const Value = struct {...@@ -3710,19 +3793,23 @@ pub const Value = struct {
3710 else => unreachable,3793 else => unreachable,
3711 };3794 };
3712 return (try mod.intern(.{ .float = .{3795 return (try mod.intern(.{ .float = .{
3713 .ty = float_type.ip_index,3796 .ty = float_type.toIntern(),
3714 .storage = storage,3797 .storage = storage,
3715 } })).toValue();3798 } })).toValue();
3716 }3799 }
37173800
3718 pub fn fabs(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3801 pub fn fabs(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3719 if (float_type.zigTypeTag(mod) == .Vector) {3802 if (float_type.zigTypeTag(mod) == .Vector) {
3720 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3803 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3804 const scalar_ty = float_type.scalarType(mod);
3721 for (result_data, 0..) |*scalar, i| {3805 for (result_data, 0..) |*scalar, i| {
3722 const elem_val = try val.elemValue(mod, i);3806 const elem_val = try val.elemValue(mod, i);
3723 scalar.* = try fabsScalar(elem_val, float_type.scalarType(mod), mod);3807 scalar.* = try (try fabsScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3724 }3808 }
3725 return Value.Tag.aggregate.create(arena, result_data);3809 return (try mod.intern(.{ .aggregate = .{
3810 .ty = float_type.toIntern(),
3811 .storage = .{ .elems = result_data },
3812 } })).toValue();
3726 }3813 }
3727 return fabsScalar(val, float_type, mod);3814 return fabsScalar(val, float_type, mod);
3728 }3815 }
...@@ -3738,19 +3825,23 @@ pub const Value = struct {...@@ -3738,19 +3825,23 @@ pub const Value = struct {
3738 else => unreachable,3825 else => unreachable,
3739 };3826 };
3740 return (try mod.intern(.{ .float = .{3827 return (try mod.intern(.{ .float = .{
3741 .ty = float_type.ip_index,3828 .ty = float_type.toIntern(),
3742 .storage = storage,3829 .storage = storage,
3743 } })).toValue();3830 } })).toValue();
3744 }3831 }
37453832
3746 pub fn floor(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3833 pub fn floor(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3747 if (float_type.zigTypeTag(mod) == .Vector) {3834 if (float_type.zigTypeTag(mod) == .Vector) {
3748 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3835 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3836 const scalar_ty = float_type.scalarType(mod);
3749 for (result_data, 0..) |*scalar, i| {3837 for (result_data, 0..) |*scalar, i| {
3750 const elem_val = try val.elemValue(mod, i);3838 const elem_val = try val.elemValue(mod, i);
3751 scalar.* = try floorScalar(elem_val, float_type.scalarType(mod), mod);3839 scalar.* = try (try floorScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3752 }3840 }
3753 return Value.Tag.aggregate.create(arena, result_data);3841 return (try mod.intern(.{ .aggregate = .{
3842 .ty = float_type.toIntern(),
3843 .storage = .{ .elems = result_data },
3844 } })).toValue();
3754 }3845 }
3755 return floorScalar(val, float_type, mod);3846 return floorScalar(val, float_type, mod);
3756 }3847 }
...@@ -3766,19 +3857,23 @@ pub const Value = struct {...@@ -3766,19 +3857,23 @@ pub const Value = struct {
3766 else => unreachable,3857 else => unreachable,
3767 };3858 };
3768 return (try mod.intern(.{ .float = .{3859 return (try mod.intern(.{ .float = .{
3769 .ty = float_type.ip_index,3860 .ty = float_type.toIntern(),
3770 .storage = storage,3861 .storage = storage,
3771 } })).toValue();3862 } })).toValue();
3772 }3863 }
37733864
3774 pub fn ceil(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3865 pub fn ceil(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3775 if (float_type.zigTypeTag(mod) == .Vector) {3866 if (float_type.zigTypeTag(mod) == .Vector) {
3776 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3867 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3868 const scalar_ty = float_type.scalarType(mod);
3777 for (result_data, 0..) |*scalar, i| {3869 for (result_data, 0..) |*scalar, i| {
3778 const elem_val = try val.elemValue(mod, i);3870 const elem_val = try val.elemValue(mod, i);
3779 scalar.* = try ceilScalar(elem_val, float_type.scalarType(mod), mod);3871 scalar.* = try (try ceilScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3780 }3872 }
3781 return Value.Tag.aggregate.create(arena, result_data);3873 return (try mod.intern(.{ .aggregate = .{
3874 .ty = float_type.toIntern(),
3875 .storage = .{ .elems = result_data },
3876 } })).toValue();
3782 }3877 }
3783 return ceilScalar(val, float_type, mod);3878 return ceilScalar(val, float_type, mod);
3784 }3879 }
...@@ -3794,19 +3889,23 @@ pub const Value = struct {...@@ -3794,19 +3889,23 @@ pub const Value = struct {
3794 else => unreachable,3889 else => unreachable,
3795 };3890 };
3796 return (try mod.intern(.{ .float = .{3891 return (try mod.intern(.{ .float = .{
3797 .ty = float_type.ip_index,3892 .ty = float_type.toIntern(),
3798 .storage = storage,3893 .storage = storage,
3799 } })).toValue();3894 } })).toValue();
3800 }3895 }
38013896
3802 pub fn round(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3897 pub fn round(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3803 if (float_type.zigTypeTag(mod) == .Vector) {3898 if (float_type.zigTypeTag(mod) == .Vector) {
3804 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3899 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3900 const scalar_ty = float_type.scalarType(mod);
3805 for (result_data, 0..) |*scalar, i| {3901 for (result_data, 0..) |*scalar, i| {
3806 const elem_val = try val.elemValue(mod, i);3902 const elem_val = try val.elemValue(mod, i);
3807 scalar.* = try roundScalar(elem_val, float_type.scalarType(mod), mod);3903 scalar.* = try (try roundScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3808 }3904 }
3809 return Value.Tag.aggregate.create(arena, result_data);3905 return (try mod.intern(.{ .aggregate = .{
3906 .ty = float_type.toIntern(),
3907 .storage = .{ .elems = result_data },
3908 } })).toValue();
3810 }3909 }
3811 return roundScalar(val, float_type, mod);3910 return roundScalar(val, float_type, mod);
3812 }3911 }
...@@ -3822,19 +3921,23 @@ pub const Value = struct {...@@ -3822,19 +3921,23 @@ pub const Value = struct {
3822 else => unreachable,3921 else => unreachable,
3823 };3922 };
3824 return (try mod.intern(.{ .float = .{3923 return (try mod.intern(.{ .float = .{
3825 .ty = float_type.ip_index,3924 .ty = float_type.toIntern(),
3826 .storage = storage,3925 .storage = storage,
3827 } })).toValue();3926 } })).toValue();
3828 }3927 }
38293928
3830 pub fn trunc(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3929 pub fn trunc(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
3831 if (float_type.zigTypeTag(mod) == .Vector) {3930 if (float_type.zigTypeTag(mod) == .Vector) {
3832 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3931 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3932 const scalar_ty = float_type.scalarType(mod);
3833 for (result_data, 0..) |*scalar, i| {3933 for (result_data, 0..) |*scalar, i| {
3834 const elem_val = try val.elemValue(mod, i);3934 const elem_val = try val.elemValue(mod, i);
3835 scalar.* = try truncScalar(elem_val, float_type.scalarType(mod), mod);3935 scalar.* = try (try truncScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3836 }3936 }
3837 return Value.Tag.aggregate.create(arena, result_data);3937 return (try mod.intern(.{ .aggregate = .{
3938 .ty = float_type.toIntern(),
3939 .storage = .{ .elems = result_data },
3940 } })).toValue();
3838 }3941 }
3839 return truncScalar(val, float_type, mod);3942 return truncScalar(val, float_type, mod);
3840 }3943 }
...@@ -3850,7 +3953,7 @@ pub const Value = struct {...@@ -3850,7 +3953,7 @@ pub const Value = struct {
3850 else => unreachable,3953 else => unreachable,
3851 };3954 };
3852 return (try mod.intern(.{ .float = .{3955 return (try mod.intern(.{ .float = .{
3853 .ty = float_type.ip_index,3956 .ty = float_type.toIntern(),
3854 .storage = storage,3957 .storage = storage,
3855 } })).toValue();3958 } })).toValue();
3856 }3959 }
...@@ -3864,20 +3967,18 @@ pub const Value = struct {...@@ -3864,20 +3967,18 @@ pub const Value = struct {
3864 mod: *Module,3967 mod: *Module,
3865 ) !Value {3968 ) !Value {
3866 if (float_type.zigTypeTag(mod) == .Vector) {3969 if (float_type.zigTypeTag(mod) == .Vector) {
3867 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));3970 const result_data = try arena.alloc(InternPool.Index, float_type.vectorLen(mod));
3971 const scalar_ty = float_type.scalarType(mod);
3868 for (result_data, 0..) |*scalar, i| {3972 for (result_data, 0..) |*scalar, i| {
3869 const mulend1_elem = try mulend1.elemValue(mod, i);3973 const mulend1_elem = try mulend1.elemValue(mod, i);
3870 const mulend2_elem = try mulend2.elemValue(mod, i);3974 const mulend2_elem = try mulend2.elemValue(mod, i);
3871 const addend_elem = try addend.elemValue(mod, i);3975 const addend_elem = try addend.elemValue(mod, i);
3872 scalar.* = try mulAddScalar(3976 scalar.* = try (try mulAddScalar(scalar_ty, mulend1_elem, mulend2_elem, addend_elem, mod)).intern(scalar_ty, mod);
3873 float_type.scalarType(mod),
3874 mulend1_elem,
3875 mulend2_elem,
3876 addend_elem,
3877 mod,
3878 );
3879 }3977 }
3880 return Value.Tag.aggregate.create(arena, result_data);3978 return (try mod.intern(.{ .aggregate = .{
3979 .ty = float_type.toIntern(),
3980 .storage = .{ .elems = result_data },
3981 } })).toValue();
3881 }3982 }
3882 return mulAddScalar(float_type, mulend1, mulend2, addend, mod);3983 return mulAddScalar(float_type, mulend1, mulend2, addend, mod);
3883 }3984 }
...@@ -3899,7 +4000,7 @@ pub const Value = struct {...@@ -3899,7 +4000,7 @@ pub const Value = struct {
3899 else => unreachable,4000 else => unreachable,
3900 };4001 };
3901 return (try mod.intern(.{ .float = .{4002 return (try mod.intern(.{ .float = .{
3902 .ty = float_type.ip_index,4003 .ty = float_type.toIntern(),
3903 .storage = storage,4004 .storage = storage,
3904 } })).toValue();4005 } })).toValue();
3905 }4006 }
...@@ -3931,22 +4032,22 @@ pub const Value = struct {...@@ -3931,22 +4032,22 @@ pub const Value = struct {
3931 }4032 }
39324033
3933 pub fn isGenericPoison(val: Value) bool {4034 pub fn isGenericPoison(val: Value) bool {
3934 return val.ip_index == .generic_poison;4035 return val.toIntern() == .generic_poison;
3935 }4036 }
39364037
3937 /// This type is not copyable since it may contain pointers to its inner data.4038 /// This type is not copyable since it may contain pointers to its inner data.
3938 pub const Payload = struct {4039 pub const Payload = struct {
3939 tag: Tag,4040 tag: Tag,
39404041
3941 pub const Bytes = struct {4042 pub const SubValue = struct {
3942 base: Payload,4043 base: Payload,
3943 /// Includes the sentinel, if any.4044 data: Value,
3944 data: []const u8,
3945 };4045 };
39464046
3947 pub const StrLit = struct {4047 pub const Bytes = struct {
3948 base: Payload,4048 base: Payload,
3949 data: Module.StringLiteralContext.Key,4049 /// Includes the sentinel, if any.
4050 data: []const u8,
3950 };4051 };
39514052
3952 pub const Aggregate = struct {4053 pub const Aggregate = struct {