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 {
400400 /// A comptime-known value. Uses the `ty_pl` field, payload is index of
401401 /// `values` array.
402402 constant,
403 /// A comptime-known type. Uses the `ty` field.
404 const_ty,
405403 /// A comptime-known value via an index into the InternPool.
406404 /// Uses the `interned` field.
407405 interned,
......@@ -1257,8 +1255,6 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: InternPool) Type {
12571255 .error_set_has_value,
12581256 => return Type.bool,
12591257
1260 .const_ty => return Type.type,
1261
12621258 .alloc,
12631259 .ret_ptr,
12641260 .err_return_trace,
......@@ -1435,7 +1431,6 @@ pub fn getRefType(air: Air, ref: Air.Inst.Ref) Type {
14351431 const air_tags = air.instructions.items(.tag);
14361432 const air_datas = air.instructions.items(.data);
14371433 return switch (air_tags[inst_index]) {
1438 .const_ty => air_datas[inst_index].ty,
14391434 .interned => air_datas[inst_index].interned.toType(),
14401435 else => unreachable,
14411436 };
......@@ -1501,7 +1496,6 @@ pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {
15011496 const air_datas = air.instructions.items(.data);
15021497 switch (air.instructions.items(.tag)[inst_index]) {
15031498 .constant => return air.values[air_datas[inst_index].ty_pl.payload],
1504 .const_ty => unreachable,
15051499 .interned => return air_datas[inst_index].interned.toValue(),
15061500 else => return air.typeOfIndex(inst_index, mod.intern_pool).onePossibleValue(mod),
15071501 }
......@@ -1658,7 +1652,6 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: InternPool) bool {
16581652 .cmp_vector,
16591653 .cmp_vector_optimized,
16601654 .constant,
1661 .const_ty,
16621655 .interned,
16631656 .is_null,
16641657 .is_non_null,
src/InternPool.zig+40-20
......@@ -553,10 +553,10 @@ pub const Key = union(enum) {
553553 pub const Addr = union(enum) {
554554 decl: Module.Decl.Index,
555555 mut_decl: MutDecl,
556 comptime_field: Index,
556557 int: Index,
557558 eu_payload: Index,
558559 opt_payload: Index,
559 comptime_field: Index,
560560 elem: BaseIndex,
561561 field: BaseIndex,
562562
......@@ -703,24 +703,27 @@ pub const Key = union(enum) {
703703 .aggregate => |aggregate| {
704704 std.hash.autoHash(hasher, aggregate.ty);
705705 switch (ip.indexToKey(aggregate.ty)) {
706 .array_type => |array_type| if (array_type.child == .u8_type) switch (aggregate.storage) {
707 .bytes => |bytes| for (bytes) |byte| std.hash.autoHash(hasher, byte),
708 .elems => |elems| {
709 var buffer: Key.Int.Storage.BigIntSpace = undefined;
710 for (elems) |elem| std.hash.autoHash(
711 hasher,
712 ip.indexToKey(elem).int.storage.toBigInt(&buffer).to(u8) catch
713 unreachable,
714 );
715 },
716 .repeated_elem => |elem| {
717 const len = ip.aggregateTypeLen(aggregate.ty);
718 var buffer: Key.Int.Storage.BigIntSpace = undefined;
719 const byte = ip.indexToKey(elem).int.storage.toBigInt(&buffer).to(u8) catch
720 unreachable;
721 var i: u64 = 0;
722 while (i < len) : (i += 1) std.hash.autoHash(hasher, byte);
723 },
706 .array_type => |array_type| if (array_type.child == .u8_type) {
707 switch (aggregate.storage) {
708 .bytes => |bytes| for (bytes) |byte| std.hash.autoHash(hasher, byte),
709 .elems => |elems| {
710 var buffer: Key.Int.Storage.BigIntSpace = undefined;
711 for (elems) |elem| std.hash.autoHash(
712 hasher,
713 ip.indexToKey(elem).int.storage.toBigInt(&buffer).to(u8) catch
714 unreachable,
715 );
716 },
717 .repeated_elem => |elem| {
718 const len = ip.aggregateTypeLen(aggregate.ty);
719 var buffer: Key.Int.Storage.BigIntSpace = undefined;
720 const byte = ip.indexToKey(elem).int.storage.toBigInt(&buffer).to(u8) catch
721 unreachable;
722 var i: u64 = 0;
723 while (i < len) : (i += 1) std.hash.autoHash(hasher, byte);
724 },
725 }
726 return;
724727 },
725728 else => {},
726729 }
......@@ -2860,6 +2863,7 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
28602863 },
28612864 .array_type => |array_type| {
28622865 assert(array_type.child != .none);
2866 assert(array_type.sentinel == .none or ip.typeOf(array_type.sentinel) == array_type.child);
28632867
28642868 if (std.math.cast(u32, array_type.len)) |len| {
28652869 if (array_type.sentinel == .none) {
......@@ -3230,7 +3234,23 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
32303234 },
32313235
32323236 .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 }
32343254 switch (int.storage) {
32353255 .u64, .i64, .big_int => {},
32363256 .lazy_align, .lazy_size => |lazy_ty| {
src/Liveness.zig+3-5
......@@ -323,7 +323,6 @@ pub fn categorizeOperand(
323323 .alloc,
324324 .ret_ptr,
325325 .constant,
326 .const_ty,
327326 .interned,
328327 .trap,
329328 .breakpoint,
......@@ -975,7 +974,6 @@ fn analyzeInst(
975974 => return analyzeOperands(a, pass, data, inst, .{ .none, .none, .none }),
976975
977976 .constant,
978 .const_ty,
979977 .interned,
980978 => unreachable,
981979
......@@ -1272,7 +1270,7 @@ fn analyzeOperands(
12721270
12731271 // Don't compute any liveness for constants
12741272 switch (inst_tags[operand]) {
1275 .constant, .const_ty, .interned => continue,
1273 .constant, .interned => continue,
12761274 else => {},
12771275 }
12781276
......@@ -1308,7 +1306,7 @@ fn analyzeOperands(
13081306
13091307 // Don't compute any liveness for constants
13101308 switch (inst_tags[operand]) {
1311 .constant, .const_ty, .interned => continue,
1309 .constant, .interned => continue,
13121310 else => {},
13131311 }
13141312
......@@ -1842,7 +1840,7 @@ fn AnalyzeBigOperands(comptime pass: LivenessPass) type {
18421840 // Don't compute any liveness for constants
18431841 const inst_tags = big.a.air.instructions.items(.tag);
18441842 switch (inst_tags[operand]) {
1845 .constant, .const_ty, .interned => return,
1843 .constant, .interned => return,
18461844 else => {},
18471845 }
18481846
src/Liveness/Verify.zig+2-3
......@@ -43,7 +43,6 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
4343 .alloc,
4444 .ret_ptr,
4545 .constant,
46 .const_ty,
4746 .interned,
4847 .breakpoint,
4948 .dbg_stmt,
......@@ -557,7 +556,7 @@ fn verifyDeath(self: *Verify, inst: Air.Inst.Index, operand: Air.Inst.Index) Err
557556fn verifyOperand(self: *Verify, inst: Air.Inst.Index, op_ref: Air.Inst.Ref, dies: bool) Error!void {
558557 const operand = Air.refToIndexAllowNone(op_ref) orelse return;
559558 switch (self.air.instructions.items(.tag)[operand]) {
560 .constant, .const_ty, .interned => {},
559 .constant, .interned => {},
561560 else => {
562561 if (dies) {
563562 if (!self.live.remove(operand)) return invalid("%{}: dead operand %{} reused and killed again", .{ inst, operand });
......@@ -579,7 +578,7 @@ fn verifyInst(
579578 }
580579 const tag = self.air.instructions.items(.tag);
581580 switch (tag[inst]) {
582 .constant, .const_ty, .interned => unreachable,
581 .constant, .interned => unreachable,
583582 else => {
584583 if (self.liveness.isUnused(inst)) {
585584 assert(!self.live.contains(inst));
src/Module.zig+106-160
......@@ -85,20 +85,13 @@ import_table: std.StringArrayHashMapUnmanaged(*File) = .{},
8585/// Keys are fully resolved file paths. This table owns the keys and values.
8686embed_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
9988/// Stores all Type and Value objects; periodically garbage collected.
10089intern_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
10295/// The set of all the generic function instantiations. This is used so that when a generic
10396/// function is called twice with the same comptime parameter arguments, both calls dispatch
10497/// to the same function.
......@@ -208,39 +201,6 @@ pub const CImportError = struct {
208201 }
209202};
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
244204const MonomorphedFuncsSet = std.HashMapUnmanaged(
245205 Fn.Index,
246206 void,
......@@ -660,14 +620,8 @@ pub const Decl = struct {
660620 }
661621 mod.destroyFunc(func);
662622 }
623 _ = mod.memoized_decls.remove(decl.val.ip_index);
663624 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 }
671625 value_arena.deinit(gpa);
672626 decl.value_arena = null;
673627 decl.has_tv = false;
......@@ -834,7 +788,7 @@ pub const Decl = struct {
834788 pub fn getStructIndex(decl: Decl, mod: *Module) Struct.OptionalIndex {
835789 if (!decl.owns_tv) return .none;
836790 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());
838792 }
839793
840794 /// If the Decl has a value and it is a union, return it,
......@@ -875,7 +829,7 @@ pub const Decl = struct {
875829 return switch (decl.val.ip_index) {
876830 .empty_struct_type => .none,
877831 .none => .none,
878 else => switch (mod.intern_pool.indexToKey(decl.val.ip_index)) {
832 else => switch (mod.intern_pool.indexToKey(decl.val.toIntern())) {
879833 .opaque_type => |opaque_type| opaque_type.namespace.toOptional(),
880834 .struct_type => |struct_type| struct_type.namespace,
881835 .union_type => |union_type| mod.unionPtr(union_type.index).namespace.toOptional(),
......@@ -919,7 +873,7 @@ pub const Decl = struct {
919873
920874 pub fn isExtern(decl: Decl, mod: *Module) bool {
921875 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())) {
923877 .variable => |variable| variable.is_extern,
924878 .extern_func => true,
925879 else => false,
......@@ -1577,11 +1531,11 @@ pub const Fn = struct {
15771531 ip: *InternPool,
15781532 gpa: Allocator,
15791533 ) !void {
1580 switch (err_set_ty.ip_index) {
1534 switch (err_set_ty.toIntern()) {
15811535 .anyerror_type => {
15821536 self.is_anyerror = true;
15831537 },
1584 else => switch (ip.indexToKey(err_set_ty.ip_index)) {
1538 else => switch (ip.indexToKey(err_set_ty.toIntern())) {
15851539 .error_set_type => |error_set_type| {
15861540 for (error_set_type.names) |name| {
15871541 try self.errors.put(gpa, name, {});
......@@ -3396,8 +3350,7 @@ pub fn deinit(mod: *Module) void {
33963350 mod.namespaces_free_list.deinit(gpa);
33973351 mod.allocated_namespaces.deinit(gpa);
33983352
3399 mod.string_literal_table.deinit(gpa);
3400 mod.string_literal_bytes.deinit(gpa);
3353 mod.memoized_decls.deinit(gpa);
34013354
34023355 mod.intern_pool.deinit(gpa);
34033356}
......@@ -4702,7 +4655,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
47024655 return true;
47034656 }
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| {
47064659 const func = mod.funcPtr(func_index);
47074660 const owns_tv = func.owner_decl == decl_index;
47084661 if (owns_tv) {
......@@ -4749,10 +4702,10 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
47494702 decl.owns_tv = false;
47504703 var queue_linker_work = false;
47514704 var is_extern = false;
4752 switch (decl_tv.val.ip_index) {
4705 switch (decl_tv.val.toIntern()) {
47534706 .generic_poison => unreachable,
47544707 .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())) {
47564709 .variable => |variable| if (variable.decl == decl_index) {
47574710 decl.owns_tv = true;
47584711 queue_linker_work = true;
......@@ -4792,7 +4745,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
47924745 break :blk (try decl_arena_allocator.dupeZ(u8, bytes)).ptr;
47934746 };
47944747 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())) {
47964749 .variable => .variable,
47974750 .extern_func, .func => .function,
47984751 else => .constant,
......@@ -6497,40 +6450,33 @@ pub fn populateTestFunctions(
64976450 const array_decl_index = d: {
64986451 // Add mod.test_functions to an array decl then make the test_functions
64996452 // decl reference it as a slice.
6500 var new_decl_arena = std.heap.ArenaAllocator.init(gpa);
6501 errdefer new_decl_arena.deinit();
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);
6453 const test_fn_vals = try gpa.alloc(InternPool.Index, mod.test_functions.count());
6454 defer gpa.free(test_fn_vals);
65146455
65156456 // 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| {
65196462 const test_decl = mod.declPtr(test_decl_index);
6520 const test_name_slice = mem.sliceTo(test_decl.name, 0);
65216463 const test_name_decl_index = n: {
6522 var name_decl_arena = std.heap.ArenaAllocator.init(gpa);
6523 errdefer name_decl_arena.deinit();
6524 const bytes = try name_decl_arena.allocator().dupe(u8, test_name_slice);
6525 const test_name_decl_index = try mod.createAnonymousDeclFromDecl(array_decl, array_decl.src_namespace, null, .{
6526 .ty = try mod.arrayType(.{ .len = bytes.len, .child = .u8_type }),
6527 .val = try Value.Tag.bytes.create(name_decl_arena.allocator(), bytes),
6464 const test_decl_name = mem.span(test_decl.name);
6465 const test_name_decl_ty = try mod.arrayType(.{
6466 .len = test_decl_name.len,
6467 .child = .u8_type,
6468 });
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(),
65286475 });
6529 try mod.declPtr(test_name_decl_index).finalizeNewArena(&name_decl_arena);
65306476 break :n test_name_decl_index;
65316477 };
6532 array_decl.dependencies.putAssumeCapacityNoClobber(test_decl_index, .normal);
6533 array_decl.dependencies.putAssumeCapacityNoClobber(test_name_decl_index, .normal);
6478 array_decl_dependencies.appendAssumeCapacity(test_decl_index);
6479 array_decl_dependencies.appendAssumeCapacity(test_name_decl_index);
65346480 try mod.linkerUpdateDecl(test_name_decl_index);
65356481
65366482 const test_fn_fields = .{
......@@ -6541,36 +6487,51 @@ pub fn populateTestFunctions(
65416487 } }),
65426488 // func
65436489 try mod.intern(.{ .ptr = .{
6544 .ty = test_decl.ty.ip_index,
6490 .ty = test_decl.ty.toIntern(),
65456491 .addr = .{ .decl = test_decl_index },
65466492 } }),
65476493 // async_frame_size
65486494 null_usize,
65496495 };
6550 test_fn_vals[i] = (try mod.intern(.{ .aggregate = .{
6551 .ty = test_fn_ty.ip_index,
6496 test_fn_val.* = try mod.intern(.{ .aggregate = .{
6497 .ty = test_fn_ty.toIntern(),
65526498 .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);
65546516 }
65556517
6556 try array_decl.finalizeNewArena(&new_decl_arena);
65576518 break :d array_decl_index;
65586519 };
65596520 try mod.linkerUpdateDecl(array_decl_index);
65606521
65616522 {
65626523 const new_ty = try mod.ptrType(.{
6563 .elem_type = test_fn_ty.ip_index,
6524 .elem_type = test_fn_ty.toIntern(),
65646525 .is_const = true,
65656526 .size = .Slice,
65666527 });
65676528 const new_val = decl.val;
65686529 const new_init = try mod.intern(.{ .ptr = .{
6569 .ty = new_ty.ip_index,
6530 .ty = new_ty.toIntern(),
65706531 .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(),
65726533 } });
6573 mod.intern_pool.mutateVarInit(decl.val.ip_index, new_init);
6534 mod.intern_pool.mutateVarInit(decl.val.toIntern(), new_init);
65746535
65756536 // Since we are replacing the Decl's value we must perform cleanup on the
65766537 // previous value.
......@@ -6650,47 +6611,32 @@ fn reportRetryableFileError(
66506611}
66516612
66526613pub fn markReferencedDeclsAlive(mod: *Module, val: Value) void {
6653 switch (val.ip_index) {
6654 .none => switch (val.tag()) {
6655 .aggregate => {
6656 for (val.castTag(.aggregate).?.data) |field_val| {
6657 mod.markReferencedDeclsAlive(field_val);
6658 }
6659 },
6660 .@"union" => {
6661 const data = val.castTag(.@"union").?.data;
6662 mod.markReferencedDeclsAlive(data.tag);
6663 mod.markReferencedDeclsAlive(data.val);
6664 },
6665 else => {},
6614 switch (mod.intern_pool.indexToKey(val.toIntern())) {
6615 .variable => |variable| mod.markDeclIndexAlive(variable.decl),
6616 .extern_func => |extern_func| mod.markDeclIndexAlive(extern_func.decl),
6617 .func => |func| mod.markDeclIndexAlive(mod.funcPtr(func.index).owner_decl),
6618 .error_union => |error_union| switch (error_union.val) {
6619 .err_name => {},
6620 .payload => |payload| mod.markReferencedDeclsAlive(payload.toValue()),
66666621 },
6667 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
6668 .variable => |variable| mod.markDeclIndexAlive(variable.decl),
6669 .extern_func => |extern_func| mod.markDeclIndexAlive(extern_func.decl),
6670 .func => |func| mod.markDeclIndexAlive(mod.funcPtr(func.index).owner_decl),
6671 .error_union => |error_union| switch (error_union.val) {
6672 .err_name => {},
6673 .payload => |payload| mod.markReferencedDeclsAlive(payload.toValue()),
6674 },
6675 .ptr => |ptr| {
6676 switch (ptr.addr) {
6677 .decl => |decl| mod.markDeclIndexAlive(decl),
6678 .mut_decl => |mut_decl| mod.markDeclIndexAlive(mut_decl.decl),
6679 .int, .comptime_field => {},
6680 .eu_payload, .opt_payload => |parent| mod.markReferencedDeclsAlive(parent.toValue()),
6681 .elem, .field => |base_index| mod.markReferencedDeclsAlive(base_index.base.toValue()),
6682 }
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 => {},
6622 .ptr => |ptr| {
6623 switch (ptr.addr) {
6624 .decl => |decl| mod.markDeclIndexAlive(decl),
6625 .mut_decl => |mut_decl| mod.markDeclIndexAlive(mut_decl.decl),
6626 .int, .comptime_field => {},
6627 .eu_payload, .opt_payload => |parent| mod.markReferencedDeclsAlive(parent.toValue()),
6628 .elem, .field => |base_index| mod.markReferencedDeclsAlive(base_index.base.toValue()),
6629 }
6630 if (ptr.len != .none) mod.markReferencedDeclsAlive(ptr.len.toValue());
6631 },
6632 .opt => |opt| if (opt.val != .none) mod.markReferencedDeclsAlive(opt.val.toValue()),
6633 .aggregate => |aggregate| for (aggregate.storage.values()) |elem|
6634 mod.markReferencedDeclsAlive(elem.toValue()),
6635 .un => |un| {
6636 mod.markReferencedDeclsAlive(un.tag.toValue());
6637 mod.markReferencedDeclsAlive(un.val.toValue());
66936638 },
6639 else => {},
66946640 }
66956641}
66966642
......@@ -6796,11 +6742,11 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
67966742}
67976743
67986744pub 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() });
68006746}
68016747
68026748pub 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 });
68046750}
68056751
68066752pub fn adjustPtrTypeChild(mod: *Module, ptr_ty: Type, new_child: Type) Allocator.Error!Type {
......@@ -6871,9 +6817,9 @@ pub fn errorSetFromUnsortedNames(
68716817pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
68726818 if (ty.isPtrLikeOptional(mod)) {
68736819 const i = try intern(mod, .{ .opt = .{
6874 .ty = ty.ip_index,
6820 .ty = ty.toIntern(),
68756821 .val = try intern(mod, .{ .ptr = .{
6876 .ty = ty.childType(mod).ip_index,
6822 .ty = ty.childType(mod).toIntern(),
68776823 .addr = .{ .int = try intern(mod, .{ .int = .{
68786824 .ty = .usize_type,
68796825 .storage = .{ .u64 = x },
......@@ -6890,7 +6836,7 @@ pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
68906836pub fn ptrIntValue_ptronly(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
68916837 assert(ty.zigTypeTag(mod) == .Pointer);
68926838 const i = try intern(mod, .{ .ptr = .{
6893 .ty = ty.ip_index,
6839 .ty = ty.toIntern(),
68946840 .addr = .{ .int = try intern(mod, .{ .int = .{
68956841 .ty = .usize_type,
68966842 .storage = .{ .u64 = x },
......@@ -6906,7 +6852,7 @@ pub fn enumValue(mod: *Module, ty: Type, tag_int: InternPool.Index) Allocator.Er
69066852 assert(tag == .Enum);
69076853 }
69086854 const i = try intern(mod, .{ .enum_tag = .{
6909 .ty = ty.ip_index,
6855 .ty = ty.toIntern(),
69106856 .int = tag_int,
69116857 } });
69126858 return i.toValue();
......@@ -6917,12 +6863,12 @@ pub fn enumValue(mod: *Module, ty: Type, tag_int: InternPool.Index) Allocator.Er
69176863pub fn enumValueFieldIndex(mod: *Module, ty: Type, field_index: u32) Allocator.Error!Value {
69186864 const ip = &mod.intern_pool;
69196865 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
69226868 if (enum_type.values.len == 0) {
69236869 // Auto-numbered fields.
69246870 return (try ip.get(gpa, .{ .enum_tag = .{
6925 .ty = ty.ip_index,
6871 .ty = ty.toIntern(),
69266872 .int = try ip.get(gpa, .{ .int = .{
69276873 .ty = enum_type.tag_ty,
69286874 .storage = .{ .u64 = field_index },
......@@ -6931,7 +6877,7 @@ pub fn enumValueFieldIndex(mod: *Module, ty: Type, field_index: u32) Allocator.E
69316877 }
69326878
69336879 return (try ip.get(gpa, .{ .enum_tag = .{
6934 .ty = ty.ip_index,
6880 .ty = ty.toIntern(),
69356881 .int = enum_type.values[field_index],
69366882 } })).toValue();
69376883}
......@@ -6950,7 +6896,7 @@ pub fn intValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
69506896
69516897pub fn intValue_big(mod: *Module, ty: Type, x: BigIntConst) Allocator.Error!Value {
69526898 const i = try intern(mod, .{ .int = .{
6953 .ty = ty.ip_index,
6899 .ty = ty.toIntern(),
69546900 .storage = .{ .big_int = x },
69556901 } });
69566902 return i.toValue();
......@@ -6958,7 +6904,7 @@ pub fn intValue_big(mod: *Module, ty: Type, x: BigIntConst) Allocator.Error!Valu
69586904
69596905pub fn intValue_u64(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
69606906 const i = try intern(mod, .{ .int = .{
6961 .ty = ty.ip_index,
6907 .ty = ty.toIntern(),
69626908 .storage = .{ .u64 = x },
69636909 } });
69646910 return i.toValue();
......@@ -6966,7 +6912,7 @@ pub fn intValue_u64(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
69666912
69676913pub fn intValue_i64(mod: *Module, ty: Type, x: i64) Allocator.Error!Value {
69686914 const i = try intern(mod, .{ .int = .{
6969 .ty = ty.ip_index,
6915 .ty = ty.toIntern(),
69706916 .storage = .{ .i64 = x },
69716917 } });
69726918 return i.toValue();
......@@ -6974,9 +6920,9 @@ pub fn intValue_i64(mod: *Module, ty: Type, x: i64) Allocator.Error!Value {
69746920
69756921pub fn unionValue(mod: *Module, union_ty: Type, tag: Value, val: Value) Allocator.Error!Value {
69766922 const i = try intern(mod, .{ .un = .{
6977 .ty = union_ty.ip_index,
6978 .tag = tag.ip_index,
6979 .val = val.ip_index,
6923 .ty = union_ty.toIntern(),
6924 .tag = tag.toIntern(),
6925 .val = val.toIntern(),
69806926 } });
69816927 return i.toValue();
69826928}
......@@ -6993,7 +6939,7 @@ pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
69936939 else => unreachable,
69946940 };
69956941 const i = try intern(mod, .{ .float = .{
6996 .ty = ty.ip_index,
6942 .ty = ty.toIntern(),
69976943 .storage = storage,
69986944 } });
69996945 return i.toValue();
......@@ -7001,9 +6947,9 @@ pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
70016947
70026948pub fn nullValue(mod: *Module, opt_ty: Type) Allocator.Error!Value {
70036949 const ip = &mod.intern_pool;
7004 assert(ip.isOptionalType(opt_ty.ip_index));
6950 assert(ip.isOptionalType(opt_ty.toIntern()));
70056951 const result = try ip.get(mod.gpa, .{ .opt = .{
7006 .ty = opt_ty.ip_index,
6952 .ty = opt_ty.toIntern(),
70076953 .val = .none,
70086954 } });
70096955 return result.toValue();
......@@ -7042,7 +6988,7 @@ pub fn intFittingRange(mod: *Module, min: Value, max: Value) !Type {
70426988pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 {
70436989 assert(!val.isUndef(mod));
70446990
7045 const key = mod.intern_pool.indexToKey(val.ip_index);
6991 const key = mod.intern_pool.indexToKey(val.toIntern());
70466992 switch (key.int.storage) {
70476993 .i64 => |x| {
70486994 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
72217167/// * Not a struct.
72227168pub fn typeToStruct(mod: *Module, ty: Type) ?*Struct {
72237169 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;
72257171 return mod.structPtr(struct_index);
72267172}
72277173
72287174pub fn typeToUnion(mod: *Module, ty: Type) ?*Union {
72297175 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;
72317177 return mod.unionPtr(union_index);
72327178}
72337179
72347180pub fn typeToFunc(mod: *Module, ty: Type) ?InternPool.Key.FuncType {
72357181 if (ty.ip_index == .none) return null;
7236 return mod.intern_pool.indexToFuncType(ty.ip_index);
7182 return mod.intern_pool.indexToFuncType(ty.toIntern());
72377183}
72387184
72397185pub fn typeToInferredErrorSet(mod: *Module, ty: Type) ?*Fn.InferredErrorSet {
......@@ -7243,7 +7189,7 @@ pub fn typeToInferredErrorSet(mod: *Module, ty: Type) ?*Fn.InferredErrorSet {
72437189
72447190pub fn typeToInferredErrorSetIndex(mod: *Module, ty: Type) Fn.InferredErrorSet.OptionalIndex {
72457191 if (ty.ip_index == .none) return .none;
7246 return mod.intern_pool.indexToInferredErrorSetType(ty.ip_index);
7192 return mod.intern_pool.indexToInferredErrorSetType(ty.toIntern());
72477193}
72487194
72497195pub 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
72687214}
72697215
72707216pub 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());
72727218}
src/Sema.zig+1318-1180
......@@ -1866,9 +1866,9 @@ fn resolveConstMaybeUndefVal(
18661866 reason: []const u8,
18671867) CompileError!Value {
18681868 if (try sema.resolveMaybeUndefValAllowVariables(inst)) |val| {
1869 switch (val.ip_index) {
1869 switch (val.toIntern()) {
18701870 .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())) {
18721872 .variable => return sema.failWithNeededComptime(block, src, reason),
18731873 else => return val,
18741874 },
......@@ -1887,10 +1887,10 @@ fn resolveConstValue(
18871887 reason: []const u8,
18881888) CompileError!Value {
18891889 if (try sema.resolveMaybeUndefValAllowVariables(air_ref)) |val| {
1890 switch (val.ip_index) {
1890 switch (val.toIntern()) {
18911891 .generic_poison => return error.GenericPoison,
18921892 .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())) {
18941894 .undef => return sema.failWithUseOfUndef(block, src),
18951895 .variable => return sema.failWithNeededComptime(block, src, reason),
18961896 else => return val,
......@@ -1930,7 +1930,7 @@ fn resolveMaybeUndefVal(
19301930 switch (val.ip_index) {
19311931 .generic_poison => return error.GenericPoison,
19321932 .none => return val,
1933 else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) {
1933 else => switch (sema.mod.intern_pool.indexToKey(val.toIntern())) {
19341934 .variable => return null,
19351935 else => return val,
19361936 },
......@@ -1950,7 +1950,7 @@ fn resolveMaybeUndefValIntable(
19501950 while (true) switch (check.ip_index) {
19511951 .generic_poison => return error.GenericPoison,
19521952 .none => break,
1953 else => switch (sema.mod.intern_pool.indexToKey(check.ip_index)) {
1953 else => switch (sema.mod.intern_pool.indexToKey(check.toIntern())) {
19541954 .variable => return null,
19551955 .ptr => |ptr| switch (ptr.addr) {
19561956 .decl, .mut_decl, .comptime_field => return null,
......@@ -2007,7 +2007,6 @@ fn resolveMaybeUndefValAllowVariablesMaybeRuntime(
20072007 if (val.isPtrToThreadLocal(sema.mod)) make_runtime.* = true;
20082008 return val;
20092009 },
2010 .const_ty => return air_datas[i].ty.toValue(),
20112010 .interned => return air_datas[i].interned.toValue(),
20122011 else => return null,
20132012 }
......@@ -2490,7 +2489,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
24902489 });
24912490 try sema.maybeQueueFuncBodyAnalysis(iac.data.decl_index);
24922491 return sema.addConstant(ptr_ty, (try sema.mod.intern(.{ .ptr = .{
2493 .ty = ptr_ty.ip_index,
2492 .ty = ptr_ty.toIntern(),
24942493 .addr = .{ .mut_decl = .{
24952494 .decl = iac.data.decl_index,
24962495 .runtime_index = block.runtime_index,
......@@ -2988,7 +2987,7 @@ fn zirEnumDecl(
29882987 if (ty.zigTypeTag(mod) != .Int and ty.zigTypeTag(mod) != .ComptimeInt) {
29892988 return sema.fail(block, tag_ty_src, "expected integer tag type, found '{}'", .{ty.fmt(sema.mod)});
29902989 }
2991 incomplete_enum.setTagType(&mod.intern_pool, ty.ip_index);
2990 incomplete_enum.setTagType(&mod.intern_pool, ty.toIntern());
29922991 break :ty ty;
29932992 } else if (fields_len == 0) {
29942993 break :ty try mod.intType(.unsigned, 0);
......@@ -2998,7 +2997,7 @@ fn zirEnumDecl(
29982997 }
29992998 };
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) {
30023001 if (fields_len > 1 and std.math.log2_int(u64, fields_len) == int_tag_ty.bitSize(mod)) {
30033002 return sema.fail(block, src, "non-exhaustive enum specifies every value", .{});
30043003 }
......@@ -3051,7 +3050,7 @@ fn zirEnumDecl(
30513050 else => |e| return e,
30523051 };
30533052 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| {
30553054 const value_src = mod.fieldSrcLoc(new_decl_index, .{
30563055 .index = field_i,
30573056 .range = .value,
......@@ -3071,7 +3070,7 @@ fn zirEnumDecl(
30713070 else
30723071 try mod.intValue(int_tag_ty, 0);
30733072 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| {
30753074 const field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = field_i }).lazy;
30763075 const other_field_src = mod.fieldSrcLoc(new_decl_index, .{ .index = other_index }).lazy;
30773076 const msg = msg: {
......@@ -3742,7 +3741,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
37423741
37433742 try sema.maybeQueueFuncBodyAnalysis(decl_index);
37443743 sema.air_values.items[value_index] = (try sema.mod.intern(.{ .ptr = .{
3745 .ty = final_ptr_ty.ip_index,
3744 .ty = final_ptr_ty.toIntern(),
37463745 .addr = if (var_is_mut) .{ .mut_decl = .{
37473746 .decl = decl_index,
37483747 .runtime_index = block.runtime_index,
......@@ -3842,7 +3841,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
38423841 block.instructions.shrinkRetainingCapacity(search_index);
38433842 try sema.maybeQueueFuncBodyAnalysis(new_decl_index);
38443843 sema.air_values.items[value_index] = (try sema.mod.intern(.{ .ptr = .{
3845 .ty = final_elem_ty.ip_index,
3844 .ty = final_elem_ty.toIntern(),
38463845 .addr = .{ .decl = new_decl_index },
38473846 } })).toValue();
38483847 // if bitcast ty ref needs to be made const, make_ptr_const
......@@ -4341,12 +4340,12 @@ fn validateUnionInit(
43414340 block.instructions.shrinkRetainingCapacity(first_block_index);
43424341
43434342 var union_val = try mod.intern(.{ .un = .{
4344 .ty = union_ty.ip_index,
4345 .tag = tag_val.ip_index,
4346 .val = val.ip_index,
4343 .ty = union_ty.toIntern(),
4344 .tag = tag_val.toIntern(),
4345 .val = val.toIntern(),
43474346 } });
43484347 if (make_runtime) union_val = try mod.intern(.{ .runtime_value = .{
4349 .ty = union_ty.ip_index,
4348 .ty = union_ty.toIntern(),
43504349 .val = union_val,
43514350 } });
43524351 const union_init = try sema.addConstant(union_ty, union_val.toValue());
......@@ -4417,7 +4416,7 @@ fn validateStructInit(
44174416 if (field_ptr != 0) continue;
44184417
44194418 const default_val = struct_ty.structFieldDefaultValue(i, mod);
4420 if (default_val.ip_index == .unreachable_value) {
4419 if (default_val.toIntern() == .unreachable_value) {
44214420 if (struct_ty.isTuple(mod)) {
44224421 const template = "missing tuple field with index {d}";
44234422 if (root_msg) |msg| {
......@@ -4476,15 +4475,14 @@ fn validateStructInit(
44764475
44774476 // We collect the comptime field values in case the struct initialization
44784477 // ends up being comptime-known.
4479 const field_values = try sema.gpa.alloc(InternPool.Index, struct_ty.structFieldCount(mod));
4480 defer sema.gpa.free(field_values);
4478 const field_values = try sema.arena.alloc(InternPool.Index, struct_ty.structFieldCount(mod));
44814479
44824480 field: for (found_fields, 0..) |field_ptr, i| {
44834481 if (field_ptr != 0) {
44844482 // Determine whether the value stored to this pointer is comptime-known.
44854483 const field_ty = struct_ty.structFieldType(i, mod);
44864484 if (try sema.typeHasOnePossibleValue(field_ty)) |opv| {
4487 field_values[i] = opv.ip_index;
4485 field_values[i] = opv.toIntern();
44884486 continue;
44894487 }
44904488
......@@ -4549,7 +4547,7 @@ fn validateStructInit(
45494547 first_block_index = @min(first_block_index, block_index);
45504548 }
45514549 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {
4552 field_values[i] = val.ip_index;
4550 field_values[i] = val.toIntern();
45534551 } else if (require_comptime) {
45544552 const field_ptr_data = sema.code.instructions.items(.data)[field_ptr].pl_node;
45554553 return sema.failWithNeededComptime(block, field_ptr_data.src(), "initializer of comptime only struct must be comptime-known");
......@@ -4563,7 +4561,7 @@ fn validateStructInit(
45634561 }
45644562
45654563 const default_val = struct_ty.structFieldDefaultValue(i, mod);
4566 if (default_val.ip_index == .unreachable_value) {
4564 if (default_val.toIntern() == .unreachable_value) {
45674565 if (struct_ty.isTuple(mod)) {
45684566 const template = "missing tuple field with index {d}";
45694567 if (root_msg) |msg| {
......@@ -4583,7 +4581,7 @@ fn validateStructInit(
45834581 }
45844582 continue;
45854583 }
4586 field_values[i] = default_val.ip_index;
4584 field_values[i] = default_val.toIntern();
45874585 }
45884586
45894587 if (root_msg) |msg| {
......@@ -4607,11 +4605,11 @@ fn validateStructInit(
46074605
46084606 block.instructions.shrinkRetainingCapacity(first_block_index);
46094607 var struct_val = try mod.intern(.{ .aggregate = .{
4610 .ty = struct_ty.ip_index,
4608 .ty = struct_ty.toIntern(),
46114609 .storage = .{ .elems = field_values },
46124610 } });
46134611 if (make_runtime) struct_val = try mod.intern(.{ .runtime_value = .{
4614 .ty = struct_ty.ip_index,
4612 .ty = struct_ty.toIntern(),
46154613 .val = struct_val,
46164614 } });
46174615 const struct_init = try sema.addConstant(struct_ty, struct_val.toValue());
......@@ -4659,7 +4657,7 @@ fn zirValidateArrayInit(
46594657 var i = instrs.len;
46604658 while (i < array_len) : (i += 1) {
46614659 const default_val = array_ty.structFieldDefaultValue(i, mod);
4662 if (default_val.ip_index == .unreachable_value) {
4660 if (default_val.toIntern() == .unreachable_value) {
46634661 const template = "missing tuple field with index {d}";
46644662 if (root_msg) |msg| {
46654663 try sema.errNote(block, init_src, msg, template, .{i});
......@@ -4710,8 +4708,7 @@ fn zirValidateArrayInit(
47104708 // Collect the comptime element values in case the array literal ends up
47114709 // being comptime-known.
47124710 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);
4714 defer sema.gpa.free(element_vals);
4711 const element_vals = try sema.arena.alloc(InternPool.Index, array_len_s);
47154712 const opt_opv = try sema.typeHasOnePossibleValue(array_ty);
47164713 const air_tags = sema.air_instructions.items(.tag);
47174714 const air_datas = sema.air_instructions.items(.data);
......@@ -4721,13 +4718,13 @@ fn zirValidateArrayInit(
47214718
47224719 if (array_ty.isTuple(mod)) {
47234720 if (try array_ty.structFieldValueComptime(mod, i)) |opv| {
4724 element_vals[i] = opv.ip_index;
4721 element_vals[i] = opv.toIntern();
47254722 continue;
47264723 }
47274724 } else {
47284725 // Array has one possible value, so value is always comptime-known
47294726 if (opt_opv) |opv| {
4730 element_vals[i] = opv.ip_index;
4727 element_vals[i] = opv.toIntern();
47314728 continue;
47324729 }
47334730 }
......@@ -4788,7 +4785,7 @@ fn zirValidateArrayInit(
47884785 first_block_index = @min(first_block_index, block_index);
47894786 }
47904787 if (try sema.resolveMaybeUndefValAllowVariablesMaybeRuntime(bin_op.rhs, &make_runtime)) |val| {
4791 element_vals[i] = val.ip_index;
4788 element_vals[i] = val.toIntern();
47924789 } else {
47934790 array_is_comptime = false;
47944791 }
......@@ -4800,7 +4797,7 @@ fn zirValidateArrayInit(
48004797
48014798 if (array_is_comptime) {
48024799 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())) {
48044801 .ptr => |ptr| switch (ptr.addr) {
48054802 .comptime_field => return, // This store was validated by the individual elem ptrs.
48064803 else => {},
......@@ -4813,17 +4810,17 @@ fn zirValidateArrayInit(
48134810 // instead a single `store` to the array_ptr with a comptime struct value.
48144811 // Also to populate the sentinel value, if any.
48154812 if (array_ty.sentinel(mod)) |sentinel_val| {
4816 element_vals[instrs.len] = sentinel_val.ip_index;
4813 element_vals[instrs.len] = sentinel_val.toIntern();
48174814 }
48184815
48194816 block.instructions.shrinkRetainingCapacity(first_block_index);
48204817
48214818 var array_val = try mod.intern(.{ .aggregate = .{
4822 .ty = array_ty.ip_index,
4819 .ty = array_ty.toIntern(),
48234820 .storage = .{ .elems = element_vals },
48244821 } });
48254822 if (make_runtime) array_val = try mod.intern(.{ .runtime_value = .{
4826 .ty = array_ty.ip_index,
4823 .ty = array_ty.toIntern(),
48274824 .val = array_val,
48284825 } });
48294826 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
51445141 // expression of a variable declaration.
51455142 const mod = sema.mod;
51465143 const gpa = sema.gpa;
5147 const string_bytes = &mod.string_literal_bytes;
5148 const StringLiteralAdapter = Module.StringLiteralAdapter;
5149 const StringLiteralContext = Module.StringLiteralContext;
5150 try string_bytes.ensureUnusedCapacity(gpa, zir_bytes.len);
5151 const gop = try mod.string_literal_table.getOrPutContextAdapted(gpa, zir_bytes, StringLiteralAdapter{
5152 .bytes = string_bytes,
5153 }, StringLiteralContext{
5154 .bytes = string_bytes,
5144 const ty = try mod.arrayType(.{
5145 .len = zir_bytes.len,
5146 .child = .u8_type,
5147 .sentinel = .zero_u8,
51555148 });
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);
51565154 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: {
51655155 var anon_decl = try block.startAnonDecl();
51665156 defer anon_decl.deinit();
51675157
5168 const decl_index = try anon_decl.finish(
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;
5158 const decl_index = try anon_decl.finish(ty, val.toValue(), 0);
51775159
5178 gop.value_ptr.* = decl_index.toOptional();
5179 break :di decl_index;
5180 };
5181 return sema.analyzeDeclRef(decl_index);
5160 gop.key_ptr.* = val;
5161 gop.value_ptr.* = decl_index;
5162 }
5163 return sema.analyzeDeclRef(gop.value_ptr.*);
51825164}
51835165
51845166fn 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 {
62186200 const mod = sema.mod;
62196201 const func_val = (try sema.resolveMaybeUndefVal(func_inst)) orelse return null;
62206202 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())) {
62226204 .extern_func => |extern_func| extern_func.decl,
62236205 .func => |func| mod.funcPtr(func.index).owner_decl,
62246206 .ptr => |ptr| switch (ptr.addr) {
......@@ -6792,7 +6774,7 @@ fn analyzeCall(
67926774 if (err == error.AnalysisFail and comptime_reason != null) try comptime_reason.?.explain(sema, sema.err);
67936775 return err;
67946776 };
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())) {
67966778 .extern_func => return sema.fail(block, call_src, "{s} call of extern function", .{
67976779 @as([]const u8, if (is_comptime_call) "comptime" else "inline"),
67986780 }),
......@@ -6996,7 +6978,7 @@ fn analyzeCall(
69966978 }
69976979 break :blk bare_return_type;
69986980 };
6999 new_fn_info.return_type = fn_ret_ty.ip_index;
6981 new_fn_info.return_type = fn_ret_ty.toIntern();
70006982 const parent_fn_ret_ty = sema.fn_ret_ty;
70016983 sema.fn_ret_ty = fn_ret_ty;
70026984 defer sema.fn_ret_ty = parent_fn_ret_ty;
......@@ -7289,7 +7271,7 @@ fn analyzeInlineCallArg(
72897271 if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(sema, sema.err);
72907272 return err;
72917273 };
7292 switch (arg_val.ip_index) {
7274 switch (arg_val.toIntern()) {
72937275 .generic_poison, .generic_poison_type => {
72947276 // This function is currently evaluated as part of an as-of-yet unresolvable
72957277 // parameter or return type.
......@@ -7328,7 +7310,7 @@ fn analyzeInlineCallArg(
73287310 if (err == error.AnalysisFail and param_block.comptime_reason != null) try param_block.comptime_reason.?.explain(sema, sema.err);
73297311 return err;
73307312 };
7331 switch (arg_val.ip_index) {
7313 switch (arg_val.toIntern()) {
73327314 .generic_poison, .generic_poison_type => {
73337315 // This function is currently evaluated as part of an as-of-yet unresolvable
73347316 // parameter or return type.
......@@ -7426,7 +7408,7 @@ fn instantiateGenericCall(
74267408 const gpa = sema.gpa;
74277409
74287410 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())) {
74307412 .func => |function| function.index,
74317413 .ptr => |ptr| mod.declPtr(ptr.addr.decl).getFunctionIndex(mod).unwrap().?,
74327414 else => unreachable,
......@@ -7911,7 +7893,7 @@ fn resolveGenericInstantiationType(
79117893 }
79127894
79137895 new_decl.val = (try mod.intern(.{ .func = .{
7914 .ty = new_decl.ty.ip_index,
7896 .ty = new_decl.ty.toIntern(),
79157897 .index = new_func,
79167898 } })).toValue();
79177899 new_decl.@"align" = 0;
......@@ -7932,7 +7914,7 @@ fn resolveGenericInstantiationType(
79327914
79337915fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileError!void {
79347916 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())) {
79367918 .anon_struct_type => |tuple| tuple,
79377919 else => return,
79387920 };
......@@ -7957,7 +7939,7 @@ fn emitDbgInline(
79577939 if (old_func == new_func) return;
79587940
79597941 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(),
79617943 .index = new_func,
79627944 } })).toValue());
79637945 _ = try block.addInst(.{
......@@ -8019,7 +8001,7 @@ fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
80198001 try sema.checkVectorElemType(block, elem_type_src, elem_type);
80208002 const vector_type = try mod.vectorType(.{
80218003 .len = len,
8022 .child = elem_type.ip_index,
8004 .child = elem_type.toIntern(),
80238005 });
80248006 return sema.addType(vector_type);
80258007}
......@@ -8129,7 +8111,7 @@ fn zirErrorValue(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
81298111 const kv = try sema.mod.getErrorValue(name);
81308112 const error_set_type = try mod.singleErrorSetType(kv.key);
81318113 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
8132 .ty = error_set_type.ip_index,
8114 .ty = error_set_type.toIntern(),
81338115 .name = try mod.intern_pool.getOrPutString(sema.gpa, kv.key),
81348116 } })).toValue());
81358117}
......@@ -8149,7 +8131,7 @@ fn zirErrorToInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
81498131 if (val.isUndef(mod)) {
81508132 return sema.addConstUndef(Type.err_int);
81518133 }
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;
81538135 return sema.addConstant(Type.err_int, try mod.intValue(
81548136 Type.err_int,
81558137 (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
82408222 return sema.fail(block, rhs_src, "expected error set type, found '{}'", .{rhs_ty.fmt(sema.mod)});
82418223
82428224 // 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) {
82448226 return Air.Inst.Ref.anyerror_type;
82458227 }
82468228
......@@ -8445,8 +8427,8 @@ fn analyzeOptionalPayloadPtr(
84458427 _ = try block.addTyOp(.optional_payload_ptr_set, child_pointer, optional_ptr);
84468428 }
84478429 return sema.addConstant(child_pointer, (try mod.intern(.{ .ptr = .{
8448 .ty = child_pointer.ip_index,
8449 .addr = .{ .opt_payload = ptr_val.ip_index },
8430 .ty = child_pointer.toIntern(),
8431 .addr = .{ .opt_payload = ptr_val.toIntern() },
84508432 } })).toValue());
84518433 }
84528434 if (try sema.pointerDeref(block, src, ptr_val, optional_ptr_ty)) |val| {
......@@ -8455,8 +8437,8 @@ fn analyzeOptionalPayloadPtr(
84558437 }
84568438 // The same Value represents the pointer to the optional and the payload.
84578439 return sema.addConstant(child_pointer, (try mod.intern(.{ .ptr = .{
8458 .ty = child_pointer.ip_index,
8459 .addr = .{ .opt_payload = ptr_val.ip_index },
8440 .ty = child_pointer.toIntern(),
8441 .addr = .{ .opt_payload = ptr_val.toIntern() },
84608442 } })).toValue());
84618443 }
84628444 }
......@@ -8565,7 +8547,7 @@ fn analyzeErrUnionPayload(
85658547 }
85668548 return sema.addConstant(
85678549 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(),
85698551 );
85708552 }
85718553
......@@ -8633,8 +8615,8 @@ fn analyzeErrUnionPayloadPtr(
86338615 _ = try block.addTyOp(.errunion_payload_ptr_set, operand_pointer_ty, operand);
86348616 }
86358617 return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{
8636 .ty = operand_pointer_ty.ip_index,
8637 .addr = .{ .eu_payload = ptr_val.ip_index },
8618 .ty = operand_pointer_ty.toIntern(),
8619 .addr = .{ .eu_payload = ptr_val.toIntern() },
86388620 } })).toValue());
86398621 }
86408622 if (try sema.pointerDeref(block, src, ptr_val, operand_ty)) |val| {
......@@ -8642,8 +8624,8 @@ fn analyzeErrUnionPayloadPtr(
86428624 return sema.fail(block, src, "caught unexpected error '{s}'", .{name});
86438625 }
86448626 return sema.addConstant(operand_pointer_ty, (try mod.intern(.{ .ptr = .{
8645 .ty = operand_pointer_ty.ip_index,
8646 .addr = .{ .eu_payload = ptr_val.ip_index },
8627 .ty = operand_pointer_ty.toIntern(),
8628 .addr = .{ .eu_payload = ptr_val.toIntern() },
86478629 } })).toValue());
86488630 }
86498631 }
......@@ -8828,7 +8810,7 @@ fn resolveGenericBody(
88288810 };
88298811 switch (err) {
88308812 error.GenericPoison => {
8831 if (dest_ty.ip_index == .type_type) {
8813 if (dest_ty.toIntern() == .type_type) {
88328814 return Value.generic_poison_type;
88338815 } else {
88348816 return Value.generic_poison;
......@@ -9183,7 +9165,7 @@ fn funcCommon(
91839165
91849166 if (is_extern) {
91859167 return sema.addConstant(fn_ty, (try mod.intern(.{ .extern_func = .{
9186 .ty = fn_ty.ip_index,
9168 .ty = fn_ty.toIntern(),
91879169 .decl = sema.owner_decl_index,
91889170 .lib_name = if (opt_lib_name) |lib_name| (try mod.intern_pool.getOrPutString(
91899171 gpa,
......@@ -9223,7 +9205,7 @@ fn funcCommon(
92239205 .is_noinline = is_noinline,
92249206 };
92259207 return sema.addConstant(fn_ty, (try mod.intern(.{ .func = .{
9226 .ty = fn_ty.ip_index,
9208 .ty = fn_ty.toIntern(),
92279209 .index = new_func_index,
92289210 } })).toValue());
92299211}
......@@ -10151,16 +10133,16 @@ fn zirSwitchCapture(
1015110133 .@"addrspace" = operand_ptr_ty.ptrAddressSpace(mod),
1015210134 });
1015310135 return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{
10154 .ty = ptr_field_ty.ip_index,
10136 .ty = ptr_field_ty.toIntern(),
1015510137 .addr = .{ .field = .{
10156 .base = union_val.ip_index,
10138 .base = union_val.toIntern(),
1015710139 .index = field_index,
1015810140 } },
1015910141 } })).toValue());
1016010142 }
1016110143 return sema.addConstant(
1016210144 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(),
1016410146 );
1016510147 }
1016610148 if (is_ref) {
......@@ -10256,9 +10238,9 @@ fn zirSwitchCapture(
1025610238
1025710239 if (try sema.resolveDefinedValue(block, operand_src, operand_ptr)) |op_ptr_val| {
1025810240 return sema.addConstant(field_ty_ptr, (try mod.intern(.{ .ptr = .{
10259 .ty = field_ty_ptr.ip_index,
10241 .ty = field_ty_ptr.toIntern(),
1026010242 .addr = .{ .field = .{
10261 .base = op_ptr_val.ip_index,
10243 .base = op_ptr_val.toIntern(),
1026210244 .index = first_field_index,
1026310245 } },
1026410246 } })).toValue());
......@@ -11502,7 +11484,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1150211484 cases_len += 1;
1150311485
1150411486 const item_val = try mod.intern(.{ .err = .{
11505 .ty = operand_ty.ip_index,
11487 .ty = operand_ty.toIntern(),
1150611488 .name = error_name_ip,
1150711489 } });
1150811490 const item_ref = try sema.addConstant(operand_ty, item_val.toValue());
......@@ -11802,7 +11784,7 @@ fn validateSwitchItemError(
1180211784 const ip = &sema.mod.intern_pool;
1180311785 const item_tv = try sema.resolveSwitchItemVal(block, item_ref, src_node_offset, switch_prong_src, .none);
1180411786 // 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);
1180611788 const maybe_prev_src = if (try seen_errors.fetchPut(error_name, switch_prong_src)) |prev|
1180711789 prev.value
1180811790 else
......@@ -12035,7 +12017,7 @@ fn zirHasField(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1203512017 const ip = &mod.intern_pool;
1203612018
1203712019 const has_field = hf: {
12038 switch (ip.indexToKey(ty.ip_index)) {
12020 switch (ip.indexToKey(ty.toIntern())) {
1203912021 .ptr_type => |ptr_type| switch (ptr_type.size) {
1204012022 .Slice => {
1204112023 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
1216012142 var anon_decl = try block.startAnonDecl();
1216112143 defer anon_decl.deinit();
1216212144
12163 const bytes_including_null = embed_file.bytes[0 .. embed_file.bytes.len + 1];
12164
12165 // TODO instead of using `Value.Tag.bytes`, create a new value tag for pointing at
12145 // TODO instead of using `.bytes`, create a new value tag for pointing at
1216612146 // a `*Module.EmbedFile`. The purpose of this would be:
1216712147 // - If only the length is read and the bytes are not inspected by comptime code,
1216812148 // there can be an optimization where the codegen backend does a copy_file_range
1216912149 // into the final binary, and never loads the data into memory.
1217012150 // - 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 });
1217112156 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),
12173 try Value.Tag.bytes.create(anon_decl.arena(), bytes_including_null),
12157 ty,
12158 (try mod.intern(.{ .aggregate = .{
12159 .ty = ty.toIntern(),
12160 .storage = .{ .bytes = embed_file.bytes },
12161 } })).toValue(),
1217412162 0, // default alignment
1217512163 );
1217612164
......@@ -12186,7 +12174,7 @@ fn zirRetErrValueCode(sema: *Sema, inst: Zir.Inst.Index) CompileError!Air.Inst.R
1218612174 const kv = try mod.getErrorValue(err_name);
1218712175 const error_set_type = try mod.singleErrorSetType(kv.key);
1218812176 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
12189 .ty = error_set_type.ip_index,
12177 .ty = error_set_type.toIntern(),
1219012178 .name = mod.intern_pool.getString(kv.key).unwrap().?,
1219112179 } })).toValue());
1219212180}
......@@ -12597,15 +12585,15 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1259712585 return sema.addConstUndef(operand_type);
1259812586 } else if (operand_type.zigTypeTag(mod) == .Vector) {
1259912587 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);
1260112589 for (elems, 0..) |*elem, i| {
1260212590 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);
1260412592 }
12605 return sema.addConstant(
12606 operand_type,
12607 try Value.Tag.aggregate.create(sema.arena, elems),
12608 );
12593 return sema.addConstant(operand_type, (try mod.intern(.{ .aggregate = .{
12594 .ty = operand_type.toIntern(),
12595 .storage = .{ .elems = elems },
12596 } })).toValue());
1260912597 } else {
1261012598 const result_val = try val.bitwiseNot(operand_type, sema.arena, sema.mod);
1261112599 return sema.addConstant(operand_type, result_val);
......@@ -12652,22 +12640,22 @@ fn analyzeTupleCat(
1265212640 var runtime_src: ?LazySrcLoc = null;
1265312641 var i: u32 = 0;
1265412642 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();
1265612644 const default_val = lhs_ty.structFieldDefaultValue(i, mod);
12657 values[i] = default_val.ip_index;
12645 values[i] = default_val.toIntern();
1265812646 const operand_src = lhs_src; // TODO better source location
12659 if (default_val.ip_index == .unreachable_value) {
12647 if (default_val.toIntern() == .unreachable_value) {
1266012648 runtime_src = operand_src;
1266112649 values[i] = .none;
1266212650 }
1266312651 }
1266412652 i = 0;
1266512653 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();
1266712655 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();
1266912657 const operand_src = rhs_src; // TODO better source location
12670 if (default_val.ip_index == .unreachable_value) {
12658 if (default_val.toIntern() == .unreachable_value) {
1267112659 runtime_src = operand_src;
1267212660 values[i + lhs_len] = .none;
1267312661 }
......@@ -12824,34 +12812,32 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1282412812 else
1282512813 rhs_val;
1282612814
12827 const final_len_including_sent = result_len + @boolToInt(res_sent_val != null);
12828 const element_vals = try sema.arena.alloc(Value, final_len_including_sent);
12815 const element_vals = try sema.arena.alloc(InternPool.Index, result_len);
1282912816 var elem_i: usize = 0;
1283012817 while (elem_i < lhs_len) : (elem_i += 1) {
1283112818 const lhs_elem_i = elem_i;
1283212819 const elem_ty = if (lhs_is_tuple) lhs_ty.structFieldType(lhs_elem_i, mod) else lhs_info.elem_type;
1283312820 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;
1283512822 const elem_val_inst = try sema.addConstant(elem_ty, elem_val);
1283612823 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
1283712824 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);
1283912826 }
1284012827 while (elem_i < result_len) : (elem_i += 1) {
1284112828 const rhs_elem_i = elem_i - lhs_len;
1284212829 const elem_ty = if (rhs_is_tuple) rhs_ty.structFieldType(rhs_elem_i, mod) else rhs_info.elem_type;
1284312830 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;
1284512832 const elem_val_inst = try sema.addConstant(elem_ty, elem_val);
1284612833 const coerced_elem_val_inst = try sema.coerce(block, resolved_elem_ty, elem_val_inst, .unneeded);
1284712834 const coerced_elem_val = try sema.resolveConstMaybeUndefVal(block, .unneeded, coerced_elem_val_inst, "");
12848 element_vals[elem_i] = coerced_elem_val;
12849 }
12850 if (res_sent_val) |sent_val| {
12851 element_vals[result_len] = sent_val;
12835 element_vals[elem_i] = try coerced_elem_val.intern(resolved_elem_ty, mod);
1285212836 }
12853 const val = try Value.Tag.aggregate.create(sema.arena, element_vals);
12854 return sema.addConstantMaybeRef(block, result_ty, val, ptr_addrspace != null);
12837 return sema.addConstantMaybeRef(block, result_ty, (try mod.intern(.{ .aggregate = .{
12838 .ty = result_ty.toIntern(),
12839 .storage = .{ .elems = element_vals },
12840 } })).toValue(), ptr_addrspace != null);
1285512841 } else break :rs rhs_src;
1285612842 } else lhs_src;
1285712843
......@@ -12978,8 +12964,8 @@ fn analyzeTupleMul(
1297812964 const opt_runtime_src = rs: {
1297912965 var runtime_src: ?LazySrcLoc = null;
1298012966 for (0..tuple_len) |i| {
12981 types[i] = operand_ty.structFieldType(i, mod).ip_index;
12982 values[i] = operand_ty.structFieldDefaultValue(i, mod).ip_index;
12967 types[i] = operand_ty.structFieldType(i, mod).toIntern();
12968 values[i] = operand_ty.structFieldDefaultValue(i, mod).toIntern();
1298312969 const operand_src = lhs_src; // TODO better source location
1298412970 if (values[i] == .unreachable_value) {
1298512971 runtime_src = operand_src;
......@@ -13086,8 +13072,8 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1308613072 if (lhs_len == 1) {
1308713073 const elem_val = try lhs_sub_val.elemValue(mod, 0);
1308813074 break :v try mod.intern(.{ .aggregate = .{
13089 .ty = result_ty.ip_index,
13090 .storage = .{ .repeated_elem = elem_val.ip_index },
13075 .ty = result_ty.toIntern(),
13076 .storage = .{ .repeated_elem = elem_val.toIntern() },
1309113077 } });
1309213078 }
1309313079
......@@ -13097,16 +13083,15 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1309713083 var lhs_i: usize = 0;
1309813084 while (lhs_i < lhs_len) : (lhs_i += 1) {
1309913085 const elem_val = try lhs_sub_val.elemValue(mod, lhs_i);
13100 assert(elem_val.ip_index != .none);
13101 element_vals[elem_i] = elem_val.ip_index;
13086 element_vals[elem_i] = elem_val.toIntern();
1310213087 elem_i += 1;
1310313088 }
1310413089 }
1310513090 if (lhs_info.sentinel) |sent_val| {
13106 element_vals[result_len] = sent_val.ip_index;
13091 element_vals[result_len] = sent_val.toIntern();
1310713092 }
1310813093 break :v try mod.intern(.{ .aggregate = .{
13109 .ty = result_ty.ip_index,
13094 .ty = result_ty.toIntern(),
1311013095 .storage = .{ .elems = element_vals },
1311113096 } });
1311213097 };
......@@ -13998,8 +13983,8 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1399813983 else => unreachable,
1399913984 };
1400013985 const zero_val = if (is_vector) (try mod.intern(.{ .aggregate = .{
14001 .ty = resolved_type.ip_index,
14002 .storage = .{ .repeated_elem = scalar_zero.ip_index },
13986 .ty = resolved_type.toIntern(),
13987 .storage = .{ .repeated_elem = scalar_zero.toIntern() },
1400313988 } })).toValue() else scalar_zero;
1400413989 return sema.addConstant(resolved_type, zero_val);
1400513990 }
......@@ -14079,14 +14064,17 @@ fn intRem(
1407914064) CompileError!Value {
1408014065 const mod = sema.mod;
1408114066 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));
1408314068 const scalar_ty = ty.scalarType(mod);
1408414069 for (result_data, 0..) |*scalar, i| {
1408514070 const lhs_elem = try lhs.elemValue(sema.mod, i);
1408614071 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);
1408814073 }
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();
1409014078 }
1409114079 return sema.intRemScalar(lhs, rhs, ty);
1409214080}
......@@ -14517,11 +14505,13 @@ fn zirOverflowArithmetic(
1451714505 }
1451814506
1451914507 if (result.inst == .none) {
14520 const values = try sema.arena.alloc(Value, 2);
14521 values[0] = result.wrapped;
14522 values[1] = result.overflow_bit;
14523 const tuple_val = try Value.Tag.aggregate.create(sema.arena, values);
14524 return sema.addConstant(tuple_ty, tuple_val);
14508 return sema.addConstant(tuple_ty, (try mod.intern(.{ .aggregate = .{
14509 .ty = tuple_ty.toIntern(),
14510 .storage = .{ .elems = &.{
14511 result.wrapped.toIntern(),
14512 result.overflow_bit.toIntern(),
14513 } },
14514 } })).toValue());
1452514515 }
1452614516
1452714517 const element_refs = try sema.arena.alloc(Air.Inst.Ref, 2);
......@@ -14534,8 +14524,8 @@ fn splat(sema: *Sema, ty: Type, val: Value) !Value {
1453414524 const mod = sema.mod;
1453514525 if (ty.zigTypeTag(mod) != .Vector) return val;
1453614526 const repeated = try mod.intern(.{ .aggregate = .{
14537 .ty = ty.ip_index,
14538 .storage = .{ .repeated_elem = val.ip_index },
14527 .ty = ty.toIntern(),
14528 .storage = .{ .repeated_elem = val.toIntern() },
1453914529 } });
1454014530 return repeated.toValue();
1454114531}
......@@ -14547,7 +14537,7 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
1454714537 .child = .u1_type,
1454814538 }) 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() };
1455114541 const values = [2]InternPool.Index{ .none, .none };
1455214542 const tuple_ty = try mod.intern(.{ .anon_struct_type = .{
1455314543 .types = &types,
......@@ -15731,7 +15721,7 @@ fn zirClosureGet(
1573115721 scope = scope.parent.?;
1573215722 };
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) {
1573515725 const msg = msg: {
1573615726 const name = name: {
1573715727 const file = sema.owner_decl.getFileScope(mod);
......@@ -15759,7 +15749,7 @@ fn zirClosureGet(
1575915749 return sema.failWithOwnedErrorMsg(msg);
1576015750 }
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) {
1576315753 const msg = msg: {
1576415754 const name = name: {
1576515755 const file = sema.owner_decl.getFileScope(mod);
......@@ -15789,7 +15779,7 @@ fn zirClosureGet(
1578915779 return sema.failWithOwnedErrorMsg(msg);
1579015780 }
1579115781
15792 if (tv.val.ip_index == .unreachable_value) {
15782 if (tv.val.toIntern() == .unreachable_value) {
1579315783 assert(block.is_typeof);
1579415784 // We need a dummy runtime instruction with the correct type.
1579515785 return block.addTy(.alloc, tv.ty);
......@@ -15840,10 +15830,17 @@ fn zirBuiltinSrc(
1584015830 var anon_decl = try block.startAnonDecl();
1584115831 defer anon_decl.deinit();
1584215832 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 });
1584415838 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),
15846 try Value.Tag.bytes.create(anon_decl.arena(), bytes),
15839 new_decl_ty,
15840 (try mod.intern(.{ .aggregate = .{
15841 .ty = new_decl_ty.toIntern(),
15842 .storage = .{ .bytes = name },
15843 } })).toValue(),
1584715844 0, // default alignment
1584815845 );
1584915846 break :blk try mod.intern(.{ .ptr = .{
......@@ -15857,9 +15854,17 @@ fn zirBuiltinSrc(
1585715854 defer anon_decl.deinit();
1585815855 // The compiler must not call realpath anywhere.
1585915856 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 });
1586015862 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),
15862 try Value.Tag.bytes.create(anon_decl.arena(), name[0 .. name.len + 1]),
15863 new_decl_ty,
15864 (try mod.intern(.{ .aggregate = .{
15865 .ty = new_decl_ty.toIntern(),
15866 .storage = .{ .bytes = name },
15867 } })).toValue(),
1586315868 0, // default alignment
1586415869 );
1586515870 break :blk try mod.intern(.{ .ptr = .{
......@@ -15877,13 +15882,13 @@ fn zirBuiltinSrc(
1587715882 // line: u32,
1587815883 try mod.intern(.{ .runtime_value = .{
1587915884 .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(),
1588115886 } }),
1588215887 // column: u32,
15883 (try mod.intValue(Type.u32, extra.column + 1)).ip_index,
15888 (try mod.intValue(Type.u32, extra.column + 1)).toIntern(),
1588415889 };
1588515890 return sema.addConstant(src_loc_ty, (try mod.intern(.{ .aggregate = .{
15886 .ty = src_loc_ty.ip_index,
15891 .ty = src_loc_ty.toIntern(),
1588715892 .storage = .{ .elems = &fields },
1588815893 } })).toValue());
1588915894}
......@@ -15908,8 +15913,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1590815913 .Null,
1590915914 .EnumLiteral,
1591015915 => |type_info_tag| return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
15911 .ty = type_info_ty.ip_index,
15912 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(type_info_tag))).ip_index,
15916 .ty = type_info_ty.toIntern(),
15917 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(type_info_tag))).toIntern(),
1591315918 .val = .void_value,
1591415919 } })).toValue()),
1591515920 .Fn => {
......@@ -15941,8 +15946,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1594115946 const param_info_decl = mod.declPtr(param_info_decl_index);
1594215947 const param_info_ty = param_info_decl.val.toType();
1594315948
15944 const param_vals = try gpa.alloc(InternPool.Index, info.param_types.len);
15945 defer gpa.free(param_vals);
15949 const param_vals = try sema.arena.alloc(InternPool.Index, info.param_types.len);
1594615950 for (param_vals, info.param_types, 0..) |*param_val, param_ty, i| {
1594715951 const is_generic = param_ty == .generic_poison_type;
1594815952 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
1595715961
1595815962 const param_fields = .{
1595915963 // is_generic: bool,
15960 Value.makeBool(is_generic).ip_index,
15964 Value.makeBool(is_generic).toIntern(),
1596115965 // is_noalias: bool,
15962 Value.makeBool(is_noalias).ip_index,
15966 Value.makeBool(is_noalias).toIntern(),
1596315967 // type: ?type,
1596415968 param_ty_val,
1596515969 };
1596615970 param_val.* = try mod.intern(.{ .aggregate = .{
15967 .ty = param_info_ty.ip_index,
15971 .ty = param_info_ty.toIntern(),
1596815972 .storage = .{ .elems = &param_fields },
1596915973 } });
1597015974 }
1597115975
1597215976 const args_val = v: {
1597315977 const args_slice_ty = try mod.ptrType(.{
15974 .elem_type = param_info_ty.ip_index,
15978 .elem_type = param_info_ty.toIntern(),
1597515979 .size = .Slice,
1597615980 .is_const = true,
1597715981 });
1597815982 const new_decl = try params_anon_decl.finish(
1597915983 try mod.arrayType(.{
1598015984 .len = param_vals.len,
15981 .child = param_info_ty.ip_index,
15985 .child = param_info_ty.toIntern(),
1598215986 .sentinel = .none,
1598315987 }),
1598415988 (try mod.intern(.{ .aggregate = .{
15985 .ty = args_slice_ty.ip_index,
15989 .ty = args_slice_ty.toIntern(),
1598615990 .storage = .{ .elems = param_vals },
1598715991 } })).toValue(),
1598815992 0, // default alignment
1598915993 );
1599015994 break :v try mod.intern(.{ .ptr = .{
15991 .ty = args_slice_ty.ip_index,
15995 .ty = args_slice_ty.toIntern(),
1599215996 .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(),
1599415998 } });
1599515999 };
1599616000
......@@ -16003,43 +16007,55 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1600316007
1600416008 const field_values = .{
1600516009 // calling_convention: CallingConvention,
16006 (try mod.enumValueFieldIndex(callconv_ty, @enumToInt(info.cc))).ip_index,
16010 (try mod.enumValueFieldIndex(callconv_ty, @enumToInt(info.cc))).toIntern(),
1600716011 // 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(),
1600916013 // is_generic: bool,
16010 Value.makeBool(info.is_generic).ip_index,
16014 Value.makeBool(info.is_generic).toIntern(),
1601116015 // is_var_args: bool,
16012 Value.makeBool(info.is_var_args).ip_index,
16016 Value.makeBool(info.is_var_args).toIntern(),
1601316017 // return_type: ?type,
1601416018 ret_ty_opt,
1601516019 // args: []const Fn.Param,
1601616020 args_val,
1601716021 };
1601816022 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16019 .ty = type_info_ty.ip_index,
16020 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Fn))).ip_index,
16023 .ty = type_info_ty.toIntern(),
16024 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Fn))).toIntern(),
1602116025 .val = try mod.intern(.{ .aggregate = .{
16022 .ty = fn_info_ty.ip_index,
16026 .ty = fn_info_ty.toIntern(),
1602316027 .storage = .{ .elems = &field_values },
1602416028 } }),
1602516029 } })).toValue());
1602616030 },
1602716031 .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
1602816043 const signedness_ty = try sema.getBuiltinType("Signedness");
1602916044 const info = ty.intInfo(mod);
16030 const field_values = try sema.arena.alloc(Value, 2);
16031 // signedness: Signedness,
16032 field_values[0] = try mod.enumValueFieldIndex(signedness_ty, @enumToInt(info.signedness));
16033 // bits: u16,
16034 field_values[1] = try mod.intValue(Type.u16, info.bits);
16035
16036 return sema.addConstant(
16037 type_info_ty,
16038 try Value.Tag.@"union".create(sema.arena, .{
16039 .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Int)),
16040 .val = try Value.Tag.aggregate.create(sema.arena, field_values),
16041 }),
16042 );
16045 const field_values = .{
16046 // signedness: Signedness,
16047 try (try mod.enumValueFieldIndex(signedness_ty, @enumToInt(info.signedness))).intern(signedness_ty, mod),
16048 // bits: u16,
16049 (try mod.intValue(Type.u16, info.bits)).toIntern(),
16050 };
16051 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16052 .ty = type_info_ty.toIntern(),
16053 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Int))).toIntern(),
16054 .val = try mod.intern(.{ .aggregate = .{
16055 .ty = int_info_ty.toIntern(),
16056 .storage = .{ .elems = &field_values },
16057 } }),
16058 } })).toValue());
1604316059 },
1604416060 .Float => {
1604516061 const float_info_decl_index = (try sema.namespaceLookup(
......@@ -16051,17 +16067,17 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1605116067 try mod.declareDeclDependency(sema.owner_decl_index, float_info_decl_index);
1605216068 try sema.ensureDeclAnalyzed(float_info_decl_index);
1605316069 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
1605616072 const field_vals = .{
1605716073 // bits: u16,
16058 (try mod.intValue(Type.u16, ty.bitSize(mod))).ip_index,
16074 (try mod.intValue(Type.u16, ty.bitSize(mod))).toIntern(),
1605916075 };
1606016076 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16061 .ty = type_info_ty.ip_index,
16062 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Float))).ip_index,
16077 .ty = type_info_ty.toIntern(),
16078 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Float))).toIntern(),
1606316079 .val = try mod.intern(.{ .aggregate = .{
16064 .ty = float_ty.ip_index,
16080 .ty = float_info_ty.toIntern(),
1606516081 .storage = .{ .elems = &field_vals },
1606616082 } }),
1606716083 } })).toValue());
......@@ -16099,80 +16115,121 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1609916115 break :t decl.val.toType();
1610016116 };
1610116117
16102 const field_values = try sema.arena.create([8]Value);
16103 field_values.* = .{
16118 const field_values = .{
1610416119 // 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),
1610616121 // is_const: bool,
16107 Value.makeBool(!info.mutable),
16122 Value.makeBool(!info.mutable).toIntern(),
1610816123 // is_volatile: bool,
16109 Value.makeBool(info.@"volatile"),
16124 Value.makeBool(info.@"volatile").toIntern(),
1611016125 // alignment: comptime_int,
16111 alignment,
16126 alignment.toIntern(),
1611216127 // 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),
1611416129 // child: type,
16115 info.pointee_type.toValue(),
16130 info.pointee_type.toIntern(),
1611616131 // is_allowzero: bool,
16117 Value.makeBool(info.@"allowzero"),
16132 Value.makeBool(info.@"allowzero").toIntern(),
1611816133 // sentinel: ?*const anyopaque,
16119 try sema.optRefValue(block, info.pointee_type, info.sentinel),
16134 (try sema.optRefValue(block, info.pointee_type, info.sentinel)).toIntern(),
1612016135 };
16121
16122 return sema.addConstant(
16123 type_info_ty,
16124 try Value.Tag.@"union".create(sema.arena, .{
16125 .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Pointer)),
16126 .val = try Value.Tag.aggregate.create(sema.arena, field_values),
16127 }),
16128 );
16136 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16137 .ty = type_info_ty.toIntern(),
16138 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Pointer))).toIntern(),
16139 .val = try mod.intern(.{ .aggregate = .{
16140 .ty = pointer_ty.toIntern(),
16141 .storage = .{ .elems = &field_values },
16142 } }),
16143 } })).toValue());
1612916144 },
1613016145 .Array => {
16131 const info = ty.arrayInfo(mod);
16132 const field_values = try sema.arena.alloc(Value, 3);
16133 // len: comptime_int,
16134 field_values[0] = try mod.intValue(Type.comptime_int, info.len);
16135 // child: type,
16136 field_values[1] = info.elem_type.toValue();
16137 // sentinel: ?*const anyopaque,
16138 field_values[2] = try sema.optRefValue(block, info.elem_type, info.sentinel);
16146 const array_field_ty = t: {
16147 const array_field_ty_decl_index = (try sema.namespaceLookup(
16148 block,
16149 src,
16150 type_info_ty.getNamespaceIndex(mod).unwrap().?,
16151 "Array",
16152 )).?;
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(
16141 type_info_ty,
16142 try Value.Tag.@"union".create(sema.arena, .{
16143 .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Array)),
16144 .val = try Value.Tag.aggregate.create(sema.arena, field_values),
16145 }),
16146 );
16159 const info = ty.arrayInfo(mod);
16160 const field_values = .{
16161 // len: comptime_int,
16162 (try mod.intValue(Type.comptime_int, info.len)).toIntern(),
16163 // child: type,
16164 info.elem_type.toIntern(),
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());
1614716176 },
1614816177 .Vector => {
16149 const info = ty.arrayInfo(mod);
16150 const field_values = try sema.arena.alloc(Value, 2);
16151 // len: comptime_int,
16152 field_values[0] = try mod.intValue(Type.comptime_int, info.len);
16153 // child: type,
16154 field_values[1] = info.elem_type.toValue();
16178 const vector_field_ty = t: {
16179 const vector_field_ty_decl_index = (try sema.namespaceLookup(
16180 block,
16181 src,
16182 type_info_ty.getNamespaceIndex(mod).unwrap().?,
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(
16157 type_info_ty,
16158 try Value.Tag.@"union".create(sema.arena, .{
16159 .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Vector)),
16160 .val = try Value.Tag.aggregate.create(sema.arena, field_values),
16161 }),
16162 );
16191 const info = ty.arrayInfo(mod);
16192 const field_values = .{
16193 // len: comptime_int,
16194 (try mod.intValue(Type.comptime_int, info.len)).toIntern(),
16195 // child: type,
16196 info.elem_type.toIntern(),
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());
1616316206 },
1616416207 .Optional => {
16165 const field_values = try sema.arena.alloc(Value, 1);
16166 // child: type,
16167 field_values[0] = ty.optionalChild(mod).toValue();
16208 const optional_field_ty = t: {
16209 const optional_field_ty_decl_index = (try sema.namespaceLookup(
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(
16170 type_info_ty,
16171 try Value.Tag.@"union".create(sema.arena, .{
16172 .tag = try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Optional)),
16173 .val = try Value.Tag.aggregate.create(sema.arena, field_values),
16174 }),
16175 );
16221 const field_values = .{
16222 // child: type,
16223 ty.optionalChild(mod).toIntern(),
16224 };
16225 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16226 .ty = type_info_ty.toIntern(),
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());
1617616233 },
1617716234 .ErrorSet => {
1617816235 var fields_anon_decl = try block.startAnonDecl();
......@@ -16202,21 +16259,27 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1620216259 // Value can be zero-length slice otherwise
1620316260 const error_field_vals = if (ty.isAnyError(mod)) null else blk: {
1620416261 const names = ty.errorSetNames(mod);
16205 const vals = try gpa.alloc(InternPool.Index, names.len);
16206 defer gpa.free(vals);
16262 const vals = try sema.arena.alloc(InternPool.Index, names.len);
1620716263 for (vals, names) |*field_val, name_ip| {
1620816264 const name = mod.intern_pool.stringToSlice(name_ip);
1620916265 const name_val = v: {
1621016266 var anon_decl = try block.startAnonDecl();
1621116267 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 });
1621316273 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),
16215 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
16274 new_decl_ty,
16275 (try mod.intern(.{ .aggregate = .{
16276 .ty = new_decl_ty.toIntern(),
16277 .storage = .{ .bytes = name },
16278 } })).toValue(),
1621616279 0, // default alignment
1621716280 );
1621816281 break :v try mod.intern(.{ .ptr = .{
16219 .ty = .slice_const_u8_type,
16282 .ty = .slice_const_u8_sentinel_0_type,
1622016283 .addr = .{ .decl = new_decl },
1622116284 } });
1622216285 };
......@@ -16226,7 +16289,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1622616289 name_val,
1622716290 };
1622816291 field_val.* = try mod.intern(.{ .aggregate = .{
16229 .ty = error_field_ty.ip_index,
16292 .ty = error_field_ty.toIntern(),
1623016293 .storage = .{ .elems = &error_field_fields },
1623116294 } });
1623216295 }
......@@ -16236,39 +16299,39 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1623616299
1623716300 // Build our ?[]const Error value
1623816301 const slice_errors_ty = try mod.ptrType(.{
16239 .elem_type = error_field_ty.ip_index,
16302 .elem_type = error_field_ty.toIntern(),
1624016303 .size = .Slice,
1624116304 .is_const = true,
1624216305 });
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());
1624416307 const errors_payload_val: InternPool.Index = if (error_field_vals) |vals| v: {
1624516308 const array_errors_ty = try mod.arrayType(.{
1624616309 .len = vals.len,
16247 .child = error_field_ty.ip_index,
16310 .child = error_field_ty.toIntern(),
1624816311 .sentinel = .none,
1624916312 });
1625016313 const new_decl = try fields_anon_decl.finish(
1625116314 array_errors_ty,
1625216315 (try mod.intern(.{ .aggregate = .{
16253 .ty = array_errors_ty.ip_index,
16316 .ty = array_errors_ty.toIntern(),
1625416317 .storage = .{ .elems = vals },
1625516318 } })).toValue(),
1625616319 0, // default alignment
1625716320 );
1625816321 break :v try mod.intern(.{ .ptr = .{
16259 .ty = slice_errors_ty.ip_index,
16322 .ty = slice_errors_ty.toIntern(),
1626016323 .addr = .{ .decl = new_decl },
1626116324 } });
1626216325 } else .none;
1626316326 const errors_val = try mod.intern(.{ .opt = .{
16264 .ty = opt_slice_errors_ty.ip_index,
16327 .ty = opt_slice_errors_ty.toIntern(),
1626516328 .val = errors_payload_val,
1626616329 } });
1626716330
1626816331 // Construct Type{ .ErrorSet = errors_val }
1626916332 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16270 .ty = type_info_ty.ip_index,
16271 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorSet))).ip_index,
16333 .ty = type_info_ty.toIntern(),
16334 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorSet))).toIntern(),
1627216335 .val = errors_val,
1627316336 } })).toValue());
1627416337 },
......@@ -16288,22 +16351,22 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1628816351
1628916352 const field_values = .{
1629016353 // error_set: type,
16291 ty.errorUnionSet(mod).ip_index,
16354 ty.errorUnionSet(mod).toIntern(),
1629216355 // payload: type,
16293 ty.errorUnionPayload(mod).ip_index,
16356 ty.errorUnionPayload(mod).toIntern(),
1629416357 };
1629516358 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16296 .ty = type_info_ty.ip_index,
16297 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorUnion))).ip_index,
16359 .ty = type_info_ty.toIntern(),
16360 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.ErrorUnion))).toIntern(),
1629816361 .val = try mod.intern(.{ .aggregate = .{
16299 .ty = error_union_field_ty.ip_index,
16362 .ty = error_union_field_ty.toIntern(),
1630016363 .storage = .{ .elems = &field_values },
1630116364 } }),
1630216365 } })).toValue());
1630316366 },
1630416367 .Enum => {
1630516368 // 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
1630816371 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
1632316386 break :t enum_field_ty_decl.val.toType();
1632416387 };
1632516388
16326 const enum_field_vals = try gpa.alloc(InternPool.Index, enum_type.names.len);
16327 defer gpa.free(enum_field_vals);
16328
16389 const enum_field_vals = try sema.arena.alloc(InternPool.Index, enum_type.names.len);
1632916390 for (enum_field_vals, 0..) |*field_val, i| {
1633016391 const name_ip = enum_type.names[i];
1633116392 const name = mod.intern_pool.stringToSlice(name_ip);
1633216393 const name_val = v: {
1633316394 var anon_decl = try block.startAnonDecl();
1633416395 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 });
1633616401 const new_decl = try anon_decl.finish(
16337 try Type.array(anon_decl.arena(), bytes.len, Value.zero_u8, Type.u8, mod),
16338 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
16402 new_decl_ty,
16403 (try mod.intern(.{ .aggregate = .{
16404 .ty = new_decl_ty.toIntern(),
16405 .storage = .{ .bytes = name },
16406 } })).toValue(),
1633916407 0, // default alignment
1634016408 );
1634116409 break :v try mod.intern(.{ .ptr = .{
16342 .ty = .slice_const_u8_type,
16410 .ty = .slice_const_u8_sentinel_0_type,
1634316411 .addr = .{ .decl = new_decl },
1634416412 } });
1634516413 };
......@@ -16348,10 +16416,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1634816416 // name: []const u8,
1634916417 name_val,
1635016418 // value: comptime_int,
16351 (try mod.intValue(Type.comptime_int, i)).ip_index,
16419 (try mod.intValue(Type.comptime_int, i)).toIntern(),
1635216420 };
1635316421 field_val.* = try mod.intern(.{ .aggregate = .{
16354 .ty = enum_field_ty.ip_index,
16422 .ty = enum_field_ty.toIntern(),
1635516423 .storage = .{ .elems = &enum_field_fields },
1635616424 } });
1635716425 }
......@@ -16359,23 +16427,23 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1635916427 const fields_val = v: {
1636016428 const fields_array_ty = try mod.arrayType(.{
1636116429 .len = enum_field_vals.len,
16362 .child = enum_field_ty.ip_index,
16430 .child = enum_field_ty.toIntern(),
1636316431 .sentinel = .none,
1636416432 });
1636516433 const new_decl = try fields_anon_decl.finish(
1636616434 fields_array_ty,
1636716435 (try mod.intern(.{ .aggregate = .{
16368 .ty = fields_array_ty.ip_index,
16436 .ty = fields_array_ty.toIntern(),
1636916437 .storage = .{ .elems = enum_field_vals },
1637016438 } })).toValue(),
1637116439 0, // default alignment
1637216440 );
1637316441 break :v try mod.intern(.{ .ptr = .{
1637416442 .ty = (try mod.ptrType(.{
16375 .elem_type = enum_field_ty.ip_index,
16443 .elem_type = enum_field_ty.toIntern(),
1637616444 .size = .Slice,
1637716445 .is_const = true,
16378 })).ip_index,
16446 })).toIntern(),
1637916447 .addr = .{ .decl = new_decl },
1638016448 } });
1638116449 };
......@@ -16403,13 +16471,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1640316471 // decls: []const Declaration,
1640416472 decls_val,
1640516473 // is_exhaustive: bool,
16406 is_exhaustive.ip_index,
16474 is_exhaustive.toIntern(),
1640716475 };
1640816476 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16409 .ty = type_info_ty.ip_index,
16410 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Enum))).ip_index,
16477 .ty = type_info_ty.toIntern(),
16478 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Enum))).toIntern(),
1641116479 .val = try mod.intern(.{ .aggregate = .{
16412 .ty = type_enum_ty.ip_index,
16480 .ty = type_enum_ty.toIntern(),
1641316481 .storage = .{ .elems = &field_values },
1641416482 } }),
1641516483 } })).toValue());
......@@ -16460,14 +16528,21 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1646016528 const name_val = v: {
1646116529 var anon_decl = try block.startAnonDecl();
1646216530 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 });
1646416536 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),
16466 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
16537 new_decl_ty,
16538 (try mod.intern(.{ .aggregate = .{
16539 .ty = new_decl_ty.toIntern(),
16540 .storage = .{ .bytes = name },
16541 } })).toValue(),
1646716542 0, // default alignment
1646816543 );
1646916544 break :v try mod.intern(.{ .ptr = .{
16470 .ty = .slice_const_u8_type,
16545 .ty = .slice_const_u8_sentinel_0_type,
1647116546 .addr = .{ .decl = new_decl },
1647216547 } });
1647316548 };
......@@ -16481,12 +16556,12 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1648116556 // name: []const u8,
1648216557 name_val,
1648316558 // type: type,
16484 field.ty.ip_index,
16559 field.ty.toIntern(),
1648516560 // alignment: comptime_int,
16486 (try mod.intValue(Type.comptime_int, alignment)).ip_index,
16561 (try mod.intValue(Type.comptime_int, alignment)).toIntern(),
1648716562 };
1648816563 field_val.* = try mod.intern(.{ .aggregate = .{
16489 .ty = union_field_ty.ip_index,
16564 .ty = union_field_ty.toIntern(),
1649016565 .storage = .{ .elems = &union_field_fields },
1649116566 } });
1649216567 }
......@@ -16494,33 +16569,33 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1649416569 const fields_val = v: {
1649516570 const array_fields_ty = try mod.arrayType(.{
1649616571 .len = union_field_vals.len,
16497 .child = union_field_ty.ip_index,
16572 .child = union_field_ty.toIntern(),
1649816573 .sentinel = .none,
1649916574 });
1650016575 const new_decl = try fields_anon_decl.finish(
1650116576 array_fields_ty,
1650216577 (try mod.intern(.{ .aggregate = .{
16503 .ty = array_fields_ty.ip_index,
16578 .ty = array_fields_ty.toIntern(),
1650416579 .storage = .{ .elems = union_field_vals },
1650516580 } })).toValue(),
1650616581 0, // default alignment
1650716582 );
1650816583 break :v try mod.intern(.{ .ptr = .{
1650916584 .ty = (try mod.ptrType(.{
16510 .elem_type = union_field_ty.ip_index,
16585 .elem_type = union_field_ty.toIntern(),
1651116586 .size = .Slice,
1651216587 .is_const = true,
16513 })).ip_index,
16588 })).toIntern(),
1651416589 .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(),
1651616591 } });
1651716592 };
1651816593
1651916594 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, union_ty.getNamespaceIndex(mod));
1652016595
1652116596 const enum_tag_ty_val = try mod.intern(.{ .opt = .{
16522 .ty = (try mod.optionalType(.type_type)).ip_index,
16523 .val = if (union_ty.unionTagType(mod)) |tag_ty| tag_ty.ip_index else .none,
16597 .ty = (try mod.optionalType(.type_type)).toIntern(),
16598 .val = if (union_ty.unionTagType(mod)) |tag_ty| tag_ty.toIntern() else .none,
1652416599 } });
1652516600
1652616601 const container_layout_ty = t: {
......@@ -16538,7 +16613,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1653816613
1653916614 const field_values = .{
1654016615 // layout: ContainerLayout,
16541 (try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout))).ip_index,
16616 (try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout))).toIntern(),
1654216617
1654316618 // tag_type: ?type,
1654416619 enum_tag_ty_val,
......@@ -16548,10 +16623,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1654816623 decls_val,
1654916624 };
1655016625 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16551 .ty = type_info_ty.ip_index,
16552 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Union))).ip_index,
16626 .ty = type_info_ty.toIntern(),
16627 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Union))).toIntern(),
1655316628 .val = try mod.intern(.{ .aggregate = .{
16554 .ty = type_union_ty.ip_index,
16629 .ty = type_union_ty.toIntern(),
1655516630 .storage = .{ .elems = &field_values },
1655616631 } }),
1655716632 } })).toValue());
......@@ -16595,7 +16670,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1659516670 var struct_field_vals: []InternPool.Index = &.{};
1659616671 defer gpa.free(struct_field_vals);
1659716672 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())) {
1659916674 .anon_struct_type => |tuple| {
1660016675 struct_field_vals = try gpa.alloc(InternPool.Index, tuple.types.len);
1660116676 for (
......@@ -16611,16 +16686,24 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1661116686 // https://github.com/ziglang/zig/issues/15709
1661216687 @as([]const u8, mod.intern_pool.stringToSlice(tuple.names[i]))
1661316688 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 });
1661516695 const new_decl = try anon_decl.finish(
16616 try Type.array(anon_decl.arena(), bytes.len, Value.zero_u8, Type.u8, mod),
16617 try Value.Tag.bytes.create(anon_decl.arena(), bytes.ptr[0 .. bytes.len + 1]),
16696 new_decl_ty,
16697 (try mod.intern(.{ .aggregate = .{
16698 .ty = new_decl_ty.toIntern(),
16699 .storage = .{ .bytes = bytes },
16700 } })).toValue(),
1661816701 0, // default alignment
1661916702 );
1662016703 break :v try mod.intern(.{ .ptr = .{
16621 .ty = .slice_const_u8_type,
16704 .ty = .slice_const_u8_sentinel_0_type,
1662216705 .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(),
1662416707 } });
1662516708 };
1662616709
......@@ -16633,14 +16716,14 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1663316716 // type: type,
1663416717 field_ty,
1663516718 // default_value: ?*const anyopaque,
16636 default_val_ptr.ip_index,
16719 default_val_ptr.toIntern(),
1663716720 // is_comptime: bool,
16638 Value.makeBool(is_comptime).ip_index,
16721 Value.makeBool(is_comptime).toIntern(),
1663916722 // 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(),
1664116724 };
1664216725 struct_field_val.* = try mod.intern(.{ .aggregate = .{
16643 .ty = struct_field_ty.ip_index,
16726 .ty = struct_field_ty.toIntern(),
1664416727 .storage = .{ .elems = &struct_field_fields },
1664516728 } });
1664616729 }
......@@ -16660,20 +16743,27 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1666016743 const name_val = v: {
1666116744 var anon_decl = try block.startAnonDecl();
1666216745 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 });
1666416751 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),
16666 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
16752 new_decl_ty,
16753 (try mod.intern(.{ .aggregate = .{
16754 .ty = new_decl_ty.toIntern(),
16755 .storage = .{ .bytes = name },
16756 } })).toValue(),
1666716757 0, // default alignment
1666816758 );
1666916759 break :v try mod.intern(.{ .ptr = .{
16670 .ty = .slice_const_u8_type,
16760 .ty = .slice_const_u8_sentinel_0_type,
1667116761 .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(),
1667316763 } });
1667416764 };
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)
1667716767 null
1667816768 else
1667916769 field.default_val;
......@@ -16684,16 +16774,16 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1668416774 // name: []const u8,
1668516775 name_val,
1668616776 // type: type,
16687 field.ty.ip_index,
16777 field.ty.toIntern(),
1668816778 // default_value: ?*const anyopaque,
16689 default_val_ptr.ip_index,
16779 default_val_ptr.toIntern(),
1669016780 // is_comptime: bool,
16691 Value.makeBool(field.is_comptime).ip_index,
16781 Value.makeBool(field.is_comptime).toIntern(),
1669216782 // alignment: comptime_int,
16693 (try mod.intValue(Type.comptime_int, alignment)).ip_index,
16783 (try mod.intValue(Type.comptime_int, alignment)).toIntern(),
1669416784 };
1669516785 field_val.* = try mod.intern(.{ .aggregate = .{
16696 .ty = struct_field_ty.ip_index,
16786 .ty = struct_field_ty.toIntern(),
1669716787 .storage = .{ .elems = &struct_field_fields },
1669816788 } });
1669916789 }
......@@ -16702,37 +16792,37 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1670216792 const fields_val = v: {
1670316793 const array_fields_ty = try mod.arrayType(.{
1670416794 .len = struct_field_vals.len,
16705 .child = struct_field_ty.ip_index,
16795 .child = struct_field_ty.toIntern(),
1670616796 .sentinel = .none,
1670716797 });
1670816798 const new_decl = try fields_anon_decl.finish(
1670916799 array_fields_ty,
1671016800 (try mod.intern(.{ .aggregate = .{
16711 .ty = array_fields_ty.ip_index,
16801 .ty = array_fields_ty.toIntern(),
1671216802 .storage = .{ .elems = struct_field_vals },
1671316803 } })).toValue(),
1671416804 0, // default alignment
1671516805 );
1671616806 break :v try mod.intern(.{ .ptr = .{
1671716807 .ty = (try mod.ptrType(.{
16718 .elem_type = struct_field_ty.ip_index,
16808 .elem_type = struct_field_ty.toIntern(),
1671916809 .size = .Slice,
1672016810 .is_const = true,
16721 })).ip_index,
16811 })).toIntern(),
1672216812 .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(),
1672416814 } });
1672516815 };
1672616816
1672716817 const decls_val = try sema.typeInfoDecls(block, src, type_info_ty, struct_ty.getNamespaceIndex(mod));
1672816818
1672916819 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(),
1673116821 .val = if (layout == .Packed) val: {
1673216822 const struct_obj = mod.typeToStruct(struct_ty).?;
1673316823 assert(struct_obj.haveLayout());
1673416824 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();
1673616826 } else .none,
1673716827 } });
1673816828
......@@ -16751,7 +16841,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1675116841
1675216842 const field_values = [_]InternPool.Index{
1675316843 // layout: ContainerLayout,
16754 (try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout))).ip_index,
16844 (try mod.enumValueFieldIndex(container_layout_ty, @enumToInt(layout))).toIntern(),
1675516845 // backing_integer: ?type,
1675616846 backing_integer_val,
1675716847 // fields: []const StructField,
......@@ -16759,13 +16849,13 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1675916849 // decls: []const Declaration,
1676016850 decls_val,
1676116851 // is_tuple: bool,
16762 Value.makeBool(struct_ty.isTuple(mod)).ip_index,
16852 Value.makeBool(struct_ty.isTuple(mod)).toIntern(),
1676316853 };
1676416854 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16765 .ty = type_info_ty.ip_index,
16766 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Struct))).ip_index,
16855 .ty = type_info_ty.toIntern(),
16856 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Struct))).toIntern(),
1676716857 .val = try mod.intern(.{ .aggregate = .{
16768 .ty = type_struct_ty.ip_index,
16858 .ty = type_struct_ty.toIntern(),
1676916859 .storage = .{ .elems = &field_values },
1677016860 } }),
1677116861 } })).toValue());
......@@ -16794,10 +16884,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1679416884 decls_val,
1679516885 };
1679616886 return sema.addConstant(type_info_ty, (try mod.intern(.{ .un = .{
16797 .ty = type_info_ty.ip_index,
16798 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Opaque))).ip_index,
16887 .ty = type_info_ty.toIntern(),
16888 .tag = (try mod.enumValueFieldIndex(type_info_tag_ty, @enumToInt(std.builtin.TypeId.Opaque))).toIntern(),
1679916889 .val = try mod.intern(.{ .aggregate = .{
16800 .ty = type_opaque_ty.ip_index,
16890 .ty = type_opaque_ty.toIntern(),
1680116891 .storage = .{ .elems = &field_values },
1680216892 } }),
1680316893 } })).toValue());
......@@ -16845,25 +16935,25 @@ fn typeInfoDecls(
1684516935
1684616936 const array_decl_ty = try mod.arrayType(.{
1684716937 .len = decl_vals.items.len,
16848 .child = declaration_ty.ip_index,
16938 .child = declaration_ty.toIntern(),
1684916939 .sentinel = .none,
1685016940 });
1685116941 const new_decl = try decls_anon_decl.finish(
1685216942 array_decl_ty,
1685316943 (try mod.intern(.{ .aggregate = .{
16854 .ty = array_decl_ty.ip_index,
16944 .ty = array_decl_ty.toIntern(),
1685516945 .storage = .{ .elems = decl_vals.items },
1685616946 } })).toValue(),
1685716947 0, // default alignment
1685816948 );
1685916949 return try mod.intern(.{ .ptr = .{
1686016950 .ty = (try mod.ptrType(.{
16861 .elem_type = declaration_ty.ip_index,
16951 .elem_type = declaration_ty.toIntern(),
1686216952 .size = .Slice,
1686316953 .is_const = true,
16864 })).ip_index,
16954 })).toIntern(),
1686516955 .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(),
1686716957 } });
1686816958}
1686916959
......@@ -16892,16 +16982,24 @@ fn typeInfoNamespaceDecls(
1689216982 const name_val = v: {
1689316983 var anon_decl = try block.startAnonDecl();
1689416984 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 });
1689616991 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),
16898 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
16992 new_decl_ty,
16993 (try mod.intern(.{ .aggregate = .{
16994 .ty = new_decl_ty.toIntern(),
16995 .storage = .{ .bytes = name },
16996 } })).toValue(),
1689916997 0, // default alignment
1690016998 );
1690116999 break :v try mod.intern(.{ .ptr = .{
16902 .ty = .slice_const_u8_type,
17000 .ty = .slice_const_u8_sentinel_0_type,
1690317001 .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(),
1690517003 } });
1690617004 };
1690717005
......@@ -16909,10 +17007,10 @@ fn typeInfoNamespaceDecls(
1690917007 //name: []const u8,
1691017008 name_val,
1691117009 //is_pub: bool,
16912 Value.makeBool(decl.is_pub).ip_index,
17010 Value.makeBool(decl.is_pub).toIntern(),
1691317011 };
1691417012 try decl_vals.append(try mod.intern(.{ .aggregate = .{
16915 .ty = declaration_ty.ip_index,
17013 .ty = declaration_ty.toIntern(),
1691617014 .storage = .{ .elems = &fields },
1691717015 } }));
1691817016 }
......@@ -16985,7 +17083,7 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
1698517083 const log2_elem_ty = try sema.log2IntType(block, elem_ty, src);
1698617084 return mod.vectorType(.{
1698717085 .len = operand.vectorLen(mod),
16988 .child = log2_elem_ty.ip_index,
17086 .child = log2_elem_ty.toIntern(),
1698917087 });
1699017088 },
1699117089 else => {},
......@@ -17527,7 +17625,7 @@ fn zirRetErrValue(
1752717625 const kv = try mod.getErrorValue(err_name);
1752817626 const error_set_type = try mod.singleErrorSetType(err_name);
1752917627 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(),
1753117629 .name = try mod.intern_pool.getOrPutString(sema.gpa, kv.key),
1753217630 } })).toValue());
1753317631 return sema.analyzeRet(block, result_inst, src);
......@@ -17854,9 +17952,9 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1785417952 const val = try sema.resolveConstValue(block, align_src, coerced, "pointer alignment must be comptime-known");
1785517953 // Check if this happens to be the lazy alignment of our element type, in
1785617954 // 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())) {
1785817956 .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,
1786017958 else => {},
1786117959 },
1786217960 else => {},
......@@ -17985,7 +18083,7 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com
1798518083 }
1798618084 }
1798718085 return sema.addConstant(obj_ty, (try mod.intern(.{ .aggregate = .{
17988 .ty = obj_ty.ip_index,
18086 .ty = obj_ty.toIntern(),
1798918087 .storage = .{ .elems = &.{} },
1799018088 } })).toValue());
1799118089}
......@@ -18021,10 +18119,11 @@ fn unionInit(
1802118119 const tag_ty = union_ty.unionTagTypeHypothetical(mod);
1802218120 const enum_field_index = @intCast(u32, tag_ty.enumFieldIndex(field_name, mod).?);
1802318121 const tag_val = try mod.enumValueFieldIndex(tag_ty, enum_field_index);
18024 return sema.addConstant(union_ty, try Value.Tag.@"union".create(sema.arena, .{
18025 .tag = tag_val,
18026 .val = init_val,
18027 }));
18122 return sema.addConstant(union_ty, (try mod.intern(.{ .un = .{
18123 .ty = union_ty.toIntern(),
18124 .tag = try tag_val.intern(tag_ty, mod),
18125 .val = try init_val.intern(field.ty, mod),
18126 } })).toValue());
1802818127 }
1802918128
1803018129 try sema.requireRuntimeBlock(block, init_src, null);
......@@ -18125,12 +18224,12 @@ fn zirStructInit(
1812518224
1812618225 const init_inst = try sema.resolveInst(item.data.init);
1812718226 if (try sema.resolveMaybeUndefVal(init_inst)) |val| {
18128 return sema.addConstantMaybeRef(
18129 block,
18130 resolved_ty,
18131 try Value.Tag.@"union".create(sema.arena, .{ .tag = tag_val, .val = val }),
18132 is_ref,
18133 );
18227 const field = resolved_ty.unionFields(mod).values()[field_index];
18228 return sema.addConstantMaybeRef(block, resolved_ty, (try mod.intern(.{ .un = .{
18229 .ty = resolved_ty.toIntern(),
18230 .tag = try tag_val.intern(tag_ty, mod),
18231 .val = try val.intern(field.ty, mod),
18232 } })).toValue(), is_ref);
1813418233 }
1813518234
1813618235 if (is_ref) {
......@@ -18171,7 +18270,7 @@ fn finishStructInit(
1817118270 var root_msg: ?*Module.ErrorMsg = null;
1817218271 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())) {
1817518274 .anon_struct_type => |anon_struct| {
1817618275 for (anon_struct.types, anon_struct.values, 0..) |field_ty, default_val, i| {
1817718276 if (field_inits[i] != .none) continue;
......@@ -18204,7 +18303,7 @@ fn finishStructInit(
1820418303 for (struct_obj.fields.values(), 0..) |field, i| {
1820518304 if (field_inits[i] != .none) continue;
1820618305
18207 if (field.default_val.ip_index == .unreachable_value) {
18306 if (field.default_val.toIntern() == .unreachable_value) {
1820818307 const field_name = struct_obj.fields.keys()[i];
1820918308 const template = "missing struct field: {s}";
1821018309 const args = .{field_name};
......@@ -18250,7 +18349,7 @@ fn finishStructInit(
1825018349 .intern(struct_ty.structFieldType(field_i, mod), mod);
1825118350 }
1825218351 const struct_val = try mod.intern(.{ .aggregate = .{
18253 .ty = struct_ty.ip_index,
18352 .ty = struct_ty.toIntern(),
1825418353 .storage = .{ .elems = elems },
1825518354 } });
1825618355 return sema.addConstantMaybeRef(block, struct_ty, struct_val.toValue(), is_ref);
......@@ -18331,7 +18430,7 @@ fn zirStructInitAnon(
1833118430 gop.value_ptr.* = i;
1833218431
1833318432 const init = try sema.resolveInst(item.data.init);
18334 field_ty.* = sema.typeOf(init).ip_index;
18433 field_ty.* = sema.typeOf(init).toIntern();
1833518434 if (field_ty.toType().zigTypeTag(mod) == .Opaque) {
1833618435 const msg = msg: {
1833718436 const decl = sema.mod.declPtr(block.src_decl);
......@@ -18464,15 +18563,19 @@ fn zirArrayInit(
1846418563 } else null;
1846518564
1846618565 const runtime_index = opt_runtime_index orelse {
18467 const elem_vals = try sema.arena.alloc(Value, resolved_args.len);
18468
18469 for (resolved_args, 0..) |arg, i| {
18566 const elem_vals = try sema.arena.alloc(InternPool.Index, resolved_args.len);
18567 for (elem_vals, resolved_args, 0..) |*val, 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);
1847018572 // 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);
1847218574 }
18473
18474 const array_val = try Value.Tag.aggregate.create(sema.arena, elem_vals);
18475 return sema.addConstantMaybeRef(block, array_ty, array_val, is_ref);
18575 return sema.addConstantMaybeRef(block, array_ty, (try mod.intern(.{ .aggregate = .{
18576 .ty = array_ty.toIntern(),
18577 .storage = .{ .elems = elem_vals },
18578 } })).toValue(), is_ref);
1847618579 };
1847718580
1847818581 sema.requireRuntimeBlock(block, .unneeded, null) catch |err| switch (err) {
......@@ -18548,7 +18651,7 @@ fn zirArrayInitAnon(
1854818651 for (operands, 0..) |operand, i| {
1854918652 const operand_src = src; // TODO better source location
1855018653 const elem = try sema.resolveInst(operand);
18551 types[i] = sema.typeOf(elem).ip_index;
18654 types[i] = sema.typeOf(elem).toIntern();
1855218655 if (types[i].toType().zigTypeTag(mod) == .Opaque) {
1855318656 const msg = msg: {
1855418657 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(
1856018663 return sema.failWithOwnedErrorMsg(msg);
1856118664 }
1856218665 if (try sema.resolveMaybeUndefVal(elem)) |val| {
18563 values[i] = val.ip_index;
18666 values[i] = val.toIntern();
1856418667 } else {
1856518668 values[i] = .none;
1856618669 runtime_src = operand_src;
......@@ -18676,7 +18779,7 @@ fn fieldType(
1867618779 const resolved_ty = try sema.resolveTypeFields(cur_ty);
1867718780 cur_ty = resolved_ty;
1867818781 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())) {
1868018783 .anon_struct_type => |anon_struct| {
1868118784 const field_index = try sema.anonStructFieldIndex(block, cur_ty, field_name, field_src);
1868218785 return sema.addType(anon_struct.types[field_index].toType());
......@@ -18698,7 +18801,7 @@ fn fieldType(
1869818801 .Optional => {
1869918802 // Struct/array init through optional requires the child type to not be a pointer.
1870018803 // 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();
1870218805 continue;
1870318806 },
1870418807 .ErrorUnion => {
......@@ -18776,7 +18879,7 @@ fn zirErrorName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1877618879 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1877718880
1877818881 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;
1878018883 const bytes = sema.mod.intern_pool.stringToSlice(err_name);
1878118884 return sema.addStrLit(block, bytes);
1878218885 }
......@@ -18820,21 +18923,21 @@ fn zirUnaryMath(
1882018923 const vec_len = operand_ty.vectorLen(mod);
1882118924 const result_ty = try mod.vectorType(.{
1882218925 .len = vec_len,
18823 .child = scalar_ty.ip_index,
18926 .child = scalar_ty.toIntern(),
1882418927 });
1882518928 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1882618929 if (val.isUndef(mod))
1882718930 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);
1883018933 for (elems, 0..) |*elem, i| {
1883118934 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);
1883318936 }
18834 return sema.addConstant(
18835 result_ty,
18836 try Value.Tag.aggregate.create(sema.arena, elems),
18837 );
18937 return sema.addConstant(result_ty, (try mod.intern(.{ .aggregate = .{
18938 .ty = result_ty.toIntern(),
18939 .storage = .{ .elems = elems },
18940 } })).toValue());
1883818941 }
1883918942
1884018943 try sema.requireRuntimeBlock(block, operand_src, null);
......@@ -18867,7 +18970,7 @@ fn zirTagName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1886718970 const enum_ty = switch (operand_ty.zigTypeTag(mod)) {
1886818971 .EnumLiteral => {
1886918972 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;
1887118974 const bytes = mod.intern_pool.stringToSlice(tag_name);
1887218975 return sema.addStrLit(block, bytes);
1887318976 },
......@@ -18956,7 +19059,7 @@ fn zirReify(
1895619059 .AnyFrame => return sema.failWithUseOfAsync(block, src),
1895719060 .EnumLiteral => return Air.Inst.Ref.enum_literal_type,
1895819061 .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);
1896019063 const signedness_val = try union_val.val.fieldValue(mod, fields.getIndex("signedness").?);
1896119064 const bits_val = try union_val.val.fieldValue(mod, fields.getIndex("bits").?);
1896219065
......@@ -18966,7 +19069,7 @@ fn zirReify(
1896619069 return sema.addType(ty);
1896719070 },
1896819071 .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);
1897019073 const len_val = try union_val.val.fieldValue(mod, fields.getIndex("len").?);
1897119074 const child_val = try union_val.val.fieldValue(mod, fields.getIndex("child").?);
1897219075
......@@ -18977,12 +19080,12 @@ fn zirReify(
1897719080
1897819081 const ty = try mod.vectorType(.{
1897919082 .len = len,
18980 .child = child_ty.ip_index,
19083 .child = child_ty.toIntern(),
1898119084 });
1898219085 return sema.addType(ty);
1898319086 },
1898419087 .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);
1898619089 const bits_val = try union_val.val.fieldValue(mod, fields.getIndex("bits").?);
1898719090
1898819091 const bits = @intCast(u16, bits_val.toUnsignedInt(mod));
......@@ -18997,7 +19100,7 @@ fn zirReify(
1899719100 return sema.addType(ty);
1899819101 },
1899919102 .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);
1900119104 const size_val = try union_val.val.fieldValue(mod, fields.getIndex("size").?);
1900219105 const is_const_val = try union_val.val.fieldValue(mod, fields.getIndex("is_const").?);
1900319106 const is_volatile_val = try union_val.val.fieldValue(mod, fields.getIndex("is_volatile").?);
......@@ -19088,7 +19191,7 @@ fn zirReify(
1908819191 return sema.addType(ty);
1908919192 },
1909019193 .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);
1909219195 const len_val = try union_val.val.fieldValue(mod, fields.getIndex("len").?);
1909319196 const child_val = try union_val.val.fieldValue(mod, fields.getIndex("child").?);
1909419197 const sentinel_val = try union_val.val.fieldValue(mod, fields.getIndex("sentinel").?);
......@@ -19107,7 +19210,7 @@ fn zirReify(
1910719210 return sema.addType(ty);
1910819211 },
1910919212 .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);
1911119214 const child_val = try union_val.val.fieldValue(mod, fields.getIndex("child").?);
1911219215
1911319216 const child_ty = child_val.toType();
......@@ -19116,7 +19219,7 @@ fn zirReify(
1911619219 return sema.addType(ty);
1911719220 },
1911819221 .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);
1912019223 const error_set_val = try union_val.val.fieldValue(mod, fields.getIndex("error_set").?);
1912119224 const payload_val = try union_val.val.fieldValue(mod, fields.getIndex("payload").?);
1912219225
......@@ -19155,7 +19258,7 @@ fn zirReify(
1915519258 return sema.addType(ty);
1915619259 },
1915719260 .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);
1915919262 const layout_val = try union_val.val.fieldValue(mod, fields.getIndex("layout").?);
1916019263 const backing_integer_val = try union_val.val.fieldValue(mod, fields.getIndex("backing_integer").?);
1916119264 const fields_val = try union_val.val.fieldValue(mod, fields.getIndex("fields").?);
......@@ -19176,7 +19279,7 @@ fn zirReify(
1917619279 return try sema.reifyStruct(block, inst, src, layout, backing_integer_val, fields_val, name_strategy, is_tuple_val.toBool(mod));
1917719280 },
1917819281 .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);
1918019283 const tag_type_val = try union_val.val.fieldValue(mod, fields.getIndex("tag_type").?);
1918119284 const fields_val = try union_val.val.fieldValue(mod, fields.getIndex("fields").?);
1918219285 const decls_val = try union_val.val.fieldValue(mod, fields.getIndex("decls").?);
......@@ -19517,7 +19620,7 @@ fn zirReify(
1951719620 return sema.analyzeDeclVal(block, src, new_decl_index);
1951819621 },
1951919622 .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);
1952119624 const calling_convention_val = try union_val.val.fieldValue(mod, fields.getIndex("calling_convention").?);
1952219625 const alignment_val = try union_val.val.fieldValue(mod, fields.getIndex("alignment").?);
1952319626 const is_generic_val = try union_val.val.fieldValue(mod, fields.getIndex("is_generic").?);
......@@ -19571,7 +19674,7 @@ fn zirReify(
1957119674
1957219675 const param_type_val = param_type_opt_val.optionalValue(mod) orelse
1957319676 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
1957619679 if (arg_is_noalias) {
1957719680 if (!param_type.toType().isPtrAtRuntime(mod)) {
......@@ -19733,7 +19836,7 @@ fn reifyStruct(
1973319836 opt_val;
1973419837 break :blk try payload_val.copy(new_decl_arena_allocator);
1973519838 } 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) {
1973719840 return sema.fail(block, src, "comptime field without default initialization value", .{});
1973819841 }
1973919842
......@@ -19956,9 +20059,17 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1995620059
1995720060 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 });
1995920067 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),
19961 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
20068 decl_ty,
20069 (try mod.intern(.{ .aggregate = .{
20070 .ty = decl_ty.toIntern(),
20071 .storage = .{ .bytes = bytes },
20072 } })).toValue(),
1996220073 0, // default alignment
1996320074 );
1996420075
......@@ -20125,8 +20236,8 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
2012520236 break :disjoint false;
2012620237 }
2012720238
20128 if (!ip.isInferredErrorSetType(dest_ty.ip_index) and
20129 !ip.isInferredErrorSetType(operand_ty.ip_index))
20239 if (!ip.isInferredErrorSetType(dest_ty.toIntern()) and
20240 !ip.isInferredErrorSetType(operand_ty.toIntern()))
2013020241 {
2013120242 break :disjoint true;
2013220243 }
......@@ -20157,7 +20268,7 @@ fn zirErrSetCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstDat
2015720268
2015820269 if (maybe_operand_val) |val| {
2015920270 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);
2016120272 if (!dest_ty.errorSetHasField(error_name, mod)) {
2016220273 const msg = msg: {
2016320274 const msg = try sema.errMsg(
......@@ -20257,11 +20368,11 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2025720368 if (dest_ty.zigTypeTag(mod) == .Optional) {
2025820369 var dest_ptr_info = dest_ty.optionalChild(mod).ptrInfo(mod);
2025920370 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);
2026120372 } else {
2026220373 var dest_ptr_info = dest_ty.ptrInfo(mod);
2026320374 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);
2026520376 }
2026620377 };
2026720378
......@@ -20279,10 +20390,10 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2027920390 errdefer msg.destroy(sema.gpa);
2028020391
2028120392 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,
2028320394 });
2028420395 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,
2028620397 });
2028720398
2028820399 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
2029620407 return sema.failWithUseOfUndef(block, operand_src);
2029720408 }
2029820409 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)});
2030020411 }
2030120412 if (dest_ty.zigTypeTag(mod) == .Optional and sema.typeOf(ptr).zigTypeTag(mod) != .Optional) {
2030220413 return sema.addConstant(dest_ty, (try mod.intern(.{ .opt = .{
20303 .ty = dest_ty.ip_index,
20414 .ty = dest_ty.toIntern(),
2030420415 .val = operand_val.toIntern(),
2030520416 } })).toValue());
2030620417 }
......@@ -20335,7 +20446,7 @@ fn zirConstCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2033520446
2033620447 var ptr_info = operand_ty.ptrInfo(mod);
2033720448 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
2034020451 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
2034120452 return sema.addConstant(dest_ty, operand_val);
......@@ -20356,7 +20467,7 @@ fn zirVolatileCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
2035620467
2035720468 var ptr_info = operand_ty.ptrInfo(mod);
2035820469 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
2036120472 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
2036220473 return sema.addConstant(dest_ty, operand_val);
......@@ -20382,7 +20493,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2038220493 const dest_ty = if (is_vector)
2038320494 try mod.vectorType(.{
2038420495 .len = operand_ty.vectorLen(mod),
20385 .child = dest_scalar_ty.ip_index,
20496 .child = dest_scalar_ty.toIntern(),
2038620497 })
2038720498 else
2038820499 dest_scalar_ty;
......@@ -20405,7 +20516,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2040520516
2040620517 if (operand_info.signedness != dest_info.signedness) {
2040720518 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),
2040920520 });
2041020521 }
2041120522 if (operand_info.bits < dest_info.bits) {
......@@ -20414,7 +20525,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2041420525 block,
2041520526 src,
2041620527 "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) },
2041820529 );
2041920530 errdefer msg.destroy(sema.gpa);
2042020531 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
2043420545 if (!is_vector) {
2043520546 return sema.addConstant(
2043620547 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),
2043820549 );
2043920550 }
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));
2044120552 for (elems, 0..) |*elem, i| {
20442 const elem_val = try val.elemValue(sema.mod, i);
20443 elem.* = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod);
20553 const elem_val = try val.elemValue(mod, i);
20554 elem.* = try (try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, mod)).intern(dest_scalar_ty, mod);
2044420555 }
20445 return sema.addConstant(
20446 dest_ty,
20447 try Value.Tag.aggregate.create(sema.arena, elems),
20448 );
20556 return sema.addConstant(dest_ty, (try mod.intern(.{ .aggregate = .{
20557 .ty = dest_ty.toIntern(),
20558 .storage = .{ .elems = elems },
20559 } })).toValue());
2044920560 }
2045020561
2045120562 try sema.requireRuntimeBlock(block, src, operand_src);
......@@ -20466,7 +20577,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2046620577
2046720578 var ptr_info = ptr_ty.ptrInfo(mod);
2046820579 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);
2047020581 if (ptr_ty.zigTypeTag(mod) == .Optional) {
2047120582 dest_ty = try mod.optionalType(dest_ty.toIntern());
2047220583 }
......@@ -20531,22 +20642,22 @@ fn zirBitCount(
2053120642 const vec_len = operand_ty.vectorLen(mod);
2053220643 const result_ty = try mod.vectorType(.{
2053320644 .len = vec_len,
20534 .child = result_scalar_ty.ip_index,
20645 .child = result_scalar_ty.toIntern(),
2053520646 });
2053620647 if (try sema.resolveMaybeUndefVal(operand)) |val| {
2053720648 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);
2054020651 const scalar_ty = operand_ty.scalarType(mod);
2054120652 for (elems, 0..) |*elem, i| {
20542 const elem_val = try val.elemValue(sema.mod, i);
20653 const elem_val = try val.elemValue(mod, i);
2054320654 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();
2054520656 }
20546 return sema.addConstant(
20547 result_ty,
20548 try Value.Tag.aggregate.create(sema.arena, elems),
20549 );
20657 return sema.addConstant(result_ty, (try mod.intern(.{ .aggregate = .{
20658 .ty = result_ty.toIntern(),
20659 .storage = .{ .elems = elems },
20660 } })).toValue());
2055020661 } else {
2055120662 try sema.requireRuntimeBlock(block, src, operand_src);
2055220663 return block.addTyOp(air_tag, result_ty, operand);
......@@ -20580,7 +20691,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2058020691 block,
2058120692 operand_src,
2058220693 "@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 },
2058420695 );
2058520696 }
2058620697
......@@ -20605,15 +20716,15 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2060520716 return sema.addConstUndef(operand_ty);
2060620717
2060720718 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);
2060920720 for (elems, 0..) |*elem, i| {
20610 const elem_val = try val.elemValue(sema.mod, i);
20611 elem.* = try elem_val.byteSwap(operand_ty, mod, sema.arena);
20721 const elem_val = try val.elemValue(mod, i);
20722 elem.* = try (try elem_val.byteSwap(operand_ty, mod, sema.arena)).intern(scalar_ty, mod);
2061220723 }
20613 return sema.addConstant(
20614 operand_ty,
20615 try Value.Tag.aggregate.create(sema.arena, elems),
20616 );
20724 return sema.addConstant(operand_ty, (try mod.intern(.{ .aggregate = .{
20725 .ty = operand_ty.toIntern(),
20726 .storage = .{ .elems = elems },
20727 } })).toValue());
2061720728 } else operand_src;
2061820729
2061920730 try sema.requireRuntimeBlock(block, src, runtime_src);
......@@ -20653,15 +20764,15 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2065320764 return sema.addConstUndef(operand_ty);
2065420765
2065520766 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);
2065720768 for (elems, 0..) |*elem, i| {
20658 const elem_val = try val.elemValue(sema.mod, i);
20659 elem.* = try elem_val.bitReverse(scalar_ty, mod, sema.arena);
20769 const elem_val = try val.elemValue(mod, i);
20770 elem.* = try (try elem_val.bitReverse(scalar_ty, mod, sema.arena)).intern(scalar_ty, mod);
2066020771 }
20661 return sema.addConstant(
20662 operand_ty,
20663 try Value.Tag.aggregate.create(sema.arena, elems),
20664 );
20772 return sema.addConstant(operand_ty, (try mod.intern(.{ .aggregate = .{
20773 .ty = operand_ty.toIntern(),
20774 .storage = .{ .elems = elems },
20775 } })).toValue());
2066520776 } else operand_src;
2066620777
2066720778 try sema.requireRuntimeBlock(block, src, runtime_src);
......@@ -20699,7 +20810,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
2069920810 .Struct => {},
2070020811 else => {
2070120812 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)});
2070320814 errdefer msg.destroy(sema.gpa);
2070420815 try sema.addDeclaredHereNote(msg, ty);
2070520816 break :msg msg;
......@@ -20738,7 +20849,7 @@ fn checkNamespaceType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Com
2073820849 const mod = sema.mod;
2073920850 switch (ty.zigTypeTag(mod)) {
2074020851 .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)}),
2074220853 }
2074320854}
2074420855
......@@ -20748,7 +20859,7 @@ fn checkIntType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) CompileEr
2074820859 switch (try ty.zigTypeTagOrPoison(mod)) {
2074920860 .ComptimeInt => return true,
2075020861 .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)}),
2075220863 }
2075320864}
2075420865
......@@ -20807,7 +20918,7 @@ fn checkPtrOperand(
2080720918 block,
2080820919 ty_src,
2080920920 "expected pointer, found '{}'",
20810 .{ty.fmt(sema.mod)},
20921 .{ty.fmt(mod)},
2081120922 );
2081220923 errdefer msg.destroy(sema.gpa);
2081320924
......@@ -20820,7 +20931,7 @@ fn checkPtrOperand(
2082020931 .Optional => if (ty.isPtrLikeOptional(mod)) return,
2082120932 else => {},
2082220933 }
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)});
2082420935}
2082520936
2082620937fn checkPtrType(
......@@ -20838,7 +20949,7 @@ fn checkPtrType(
2083820949 block,
2083920950 ty_src,
2084020951 "expected pointer type, found '{}'",
20841 .{ty.fmt(sema.mod)},
20952 .{ty.fmt(mod)},
2084220953 );
2084320954 errdefer msg.destroy(sema.gpa);
2084420955
......@@ -20851,7 +20962,7 @@ fn checkPtrType(
2085120962 .Optional => if (ty.isPtrLikeOptional(mod)) return,
2085220963 else => {},
2085320964 }
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)});
2085520966}
2085620967
2085720968fn checkVectorElemType(
......@@ -20865,7 +20976,7 @@ fn checkVectorElemType(
2086520976 .Int, .Float, .Bool => return,
2086620977 else => if (ty.isPtrAtRuntime(mod)) return,
2086720978 }
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)});
2086920980}
2087020981
2087120982fn checkFloatType(
......@@ -20877,7 +20988,7 @@ fn checkFloatType(
2087720988 const mod = sema.mod;
2087820989 switch (ty.zigTypeTag(mod)) {
2087920990 .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)}),
2088120992 }
2088220993}
2088320994
......@@ -20894,7 +21005,7 @@ fn checkNumericType(
2089421005 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},
2089521006 else => |t| return sema.fail(block, ty_src, "expected number, found '{}'", .{t}),
2089621007 },
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)}),
2089821009 }
2089921010}
2090021011
......@@ -20928,7 +21039,7 @@ fn checkAtomicPtrOperand(
2092821039 block,
2092921040 elem_ty_src,
2093021041 "expected bool, integer, float, enum, or pointer type; found '{}'",
20931 .{elem_ty.fmt(sema.mod)},
21042 .{elem_ty.fmt(mod)},
2093221043 ),
2093321044 };
2093421045
......@@ -20943,7 +21054,7 @@ fn checkAtomicPtrOperand(
2094321054 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(mod)) {
2094421055 .Pointer => ptr_ty.ptrInfo(mod),
2094521056 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);
2094721058 _ = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);
2094821059 unreachable;
2094921060 },
......@@ -20953,7 +21064,7 @@ fn checkAtomicPtrOperand(
2095321064 wanted_ptr_data.@"allowzero" = ptr_data.@"allowzero";
2095421065 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);
2095721068 const casted_ptr = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);
2095821069
2095921070 return casted_ptr;
......@@ -21016,12 +21127,12 @@ fn checkIntOrVector(
2101621127 switch (try elem_ty.zigTypeTagOrPoison(mod)) {
2101721128 .Int => return elem_ty,
2101821129 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),
2102021131 }),
2102121132 }
2102221133 },
2102321134 else => return sema.fail(block, operand_src, "expected integer or vector, found '{}'", .{
21024 operand_ty.fmt(sema.mod),
21135 operand_ty.fmt(mod),
2102521136 }),
2102621137 }
2102721138}
......@@ -21040,12 +21151,12 @@ fn checkIntOrVectorAllowComptime(
2104021151 switch (try elem_ty.zigTypeTagOrPoison(mod)) {
2104121152 .Int, .ComptimeInt => return elem_ty,
2104221153 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),
2104421155 }),
2104521156 }
2104621157 },
2104721158 else => return sema.fail(block, operand_src, "expected integer or vector, found '{}'", .{
21048 operand_ty.fmt(sema.mod),
21159 operand_ty.fmt(mod),
2104921160 }),
2105021161 }
2105121162}
......@@ -21054,7 +21165,7 @@ fn checkErrorSetType(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) Comp
2105421165 const mod = sema.mod;
2105521166 switch (ty.zigTypeTag(mod)) {
2105621167 .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)}),
2105821169 }
2105921170}
2106021171
......@@ -21142,7 +21253,7 @@ fn checkVectorizableBinaryOperands(
2114221253 } else {
2114321254 const msg = msg: {
2114421255 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),
2114621257 });
2114721258 errdefer msg.destroy(sema.gpa);
2114821259 if (lhs_is_vector) {
......@@ -21161,7 +21272,7 @@ fn checkVectorizableBinaryOperands(
2116121272fn maybeOptionsSrc(sema: *Sema, block: *Block, base_src: LazySrcLoc, wanted: []const u8) LazySrcLoc {
2116221273 if (base_src == .unneeded) return .unneeded;
2116321274 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);
2116521276}
2116621277
2116721278fn resolveExportOptions(
......@@ -21282,7 +21393,7 @@ fn zirCmpxchg(
2128221393 block,
2128321394 elem_ty_src,
2128421395 "expected bool, integer, enum, or pointer type; found '{}'",
21285 .{elem_ty.fmt(sema.mod)},
21396 .{elem_ty.fmt(mod)},
2128621397 );
2128721398 }
2128821399 const uncasted_ptr = try sema.resolveInst(extra.ptr);
......@@ -21322,8 +21433,8 @@ fn zirCmpxchg(
2132221433 const ptr_ty = sema.typeOf(ptr);
2132321434 const stored_val = (try sema.pointerDeref(block, ptr_src, ptr_val, ptr_ty)) orelse break :rs ptr_src;
2132421435 const result_val = try mod.intern(.{ .opt = .{
21325 .ty = result_ty.ip_index,
21326 .val = if (stored_val.eql(expected_val, elem_ty, sema.mod)) blk: {
21436 .ty = result_ty.toIntern(),
21437 .val = if (stored_val.eql(expected_val, elem_ty, mod)) blk: {
2132721438 try sema.storePtr(block, src, ptr, new_value);
2132821439 break :blk .none;
2132921440 } else stored_val.toIntern(),
......@@ -21363,7 +21474,7 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2136321474 try sema.checkVectorElemType(block, scalar_src, scalar_ty);
2136421475 const vector_ty = try mod.vectorType(.{
2136521476 .len = len,
21366 .child = scalar_ty.ip_index,
21477 .child = scalar_ty.toIntern(),
2136721478 });
2136821479 if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| {
2136921480 if (scalar_val.isUndef(mod)) return sema.addConstUndef(vector_ty);
......@@ -21489,7 +21600,7 @@ fn analyzeShuffle(
2148921600
2149021601 const res_ty = try mod.vectorType(.{
2149121602 .len = mask_len,
21492 .child = elem_ty.ip_index,
21603 .child = elem_ty.toIntern(),
2149321604 });
2149421605
2149521606 var maybe_a_len = switch (sema.typeOf(a).zigTypeTag(mod)) {
......@@ -21516,11 +21627,11 @@ fn analyzeShuffle(
2151621627
2151721628 const a_ty = try mod.vectorType(.{
2151821629 .len = a_len,
21519 .child = elem_ty.ip_index,
21630 .child = elem_ty.toIntern(),
2152021631 });
2152121632 const b_ty = try mod.vectorType(.{
2152221633 .len = b_len,
21523 .child = elem_ty.ip_index,
21634 .child = elem_ty.toIntern(),
2152421635 });
2152521636
2152621637 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(
2156721678
2156821679 if (try sema.resolveMaybeUndefVal(a)) |a_val| {
2156921680 if (try sema.resolveMaybeUndefVal(b)) |b_val| {
21570 const values = try sema.arena.alloc(Value, mask_len);
21571
21572 i = 0;
21573 while (i < mask_len) : (i += 1) {
21681 const values = try sema.arena.alloc(InternPool.Index, mask_len);
21682 for (values) |*value| {
2157421683 const mask_elem_val = try mask.elemValue(sema.mod, i);
2157521684 if (mask_elem_val.isUndef(mod)) {
21576 values[i] = Value.undef;
21685 value.* = try mod.intern(.{ .undef = elem_ty.toIntern() });
2157721686 continue;
2157821687 }
2157921688 const int = mask_elem_val.toSignedInt(mod);
2158021689 const unsigned = if (int >= 0) @intCast(u32, int) else @intCast(u32, ~int);
21581 if (int >= 0) {
21582 values[i] = try a_val.elemValue(sema.mod, unsigned);
21583 } else {
21584 values[i] = try b_val.elemValue(sema.mod, unsigned);
21585 }
21690 values[i] = try (try (if (int >= 0) a_val else b_val).elemValue(mod, unsigned)).intern(elem_ty, mod);
2158621691 }
21587 const res_val = try Value.Tag.aggregate.create(sema.arena, values);
21588 return sema.addConstant(res_ty, res_val);
21692 return sema.addConstant(res_ty, (try mod.intern(.{ .aggregate = .{
21693 .ty = res_ty.toIntern(),
21694 .storage = .{ .elems = values },
21695 } })).toValue());
2158921696 }
2159021697 }
2159121698
......@@ -21599,22 +21706,25 @@ fn analyzeShuffle(
2159921706 const max_src = if (a_len > b_len) a_src else b_src;
2160021707 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);
2160321710 i = 0;
2160421711 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();
2160621713 }
2160721714 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();
2160921716 }
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
2161221722 if (a_len < b_len) {
2161321723 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));
2161521725 } else {
2161621726 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));
2161821728 }
2161921729 }
2162021730
......@@ -21651,7 +21761,7 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2165121761
2165221762 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison(mod)) {
2165321763 .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)}),
2165521765 };
2165621766 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
2166321773
2166421774 const vec_ty = try mod.vectorType(.{
2166521775 .len = vec_len,
21666 .child = elem_ty.ip_index,
21776 .child = elem_ty.toIntern(),
2166721777 });
2166821778 const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src);
2166921779 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
2168121791 if (maybe_b) |b_val| {
2168221792 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);
2168521795 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);
2168721797 const should_choose_a = pred_elem_val.toBool(mod);
21688 if (should_choose_a) {
21689 elem.* = try a_val.elemValue(sema.mod, i);
21690 } else {
21691 elem.* = try b_val.elemValue(sema.mod, i);
21692 }
21798 elem.* = try (try (if (should_choose_a) a_val else b_val).elemValue(mod, i)).intern(elem_ty, mod);
2169321799 }
2169421800
21695 return sema.addConstant(
21696 vec_ty,
21697 try Value.Tag.aggregate.create(sema.arena, elems),
21698 );
21801 return sema.addConstant(vec_ty, (try mod.intern(.{ .aggregate = .{
21802 .ty = vec_ty.toIntern(),
21803 .storage = .{ .elems = elems },
21804 } })).toValue());
2169921805 } else {
2170021806 break :rs b_src;
2170121807 }
......@@ -22019,7 +22125,7 @@ fn zirBuiltinCall(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
2201922125 const args = try sema.resolveInst(extra.args);
2202022126
2202122127 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) {
2202322129 return sema.fail(block, args_src, "expected a tuple, found '{}'", .{args_ty.fmt(sema.mod)});
2202422130 }
2202522131
......@@ -22102,7 +22208,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
2210222208 const result_ptr = try Type.ptr(sema.arena, sema.mod, ptr_ty_data);
2210322209
2210422210 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())) {
2210622212 .ptr => |ptr| switch (ptr.addr) {
2210722213 .field => |field| field,
2210822214 else => null,
......@@ -22244,16 +22350,16 @@ fn analyzeMinMax(
2224422350 cur_minmax = try sema.addConstant(simd_op.result_ty, result_val);
2224522351 continue;
2224622352 };
22247 const elems = try sema.arena.alloc(Value, vec_len);
22353 const elems = try sema.arena.alloc(InternPool.Index, vec_len);
2224822354 for (elems, 0..) |*elem, i| {
2224922355 const lhs_elem_val = try cur_val.elemValue(mod, i);
2225022356 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);
2225222358 }
22253 cur_minmax = try sema.addConstant(
22254 simd_op.result_ty,
22255 try Value.Tag.aggregate.create(sema.arena, elems),
22256 );
22359 cur_minmax = try sema.addConstant(simd_op.result_ty, (try mod.intern(.{ .aggregate = .{
22360 .ty = simd_op.result_ty.toIntern(),
22361 .storage = .{ .elems = elems },
22362 } })).toValue());
2225722363 } else {
2225822364 runtime_known.unset(operand_idx);
2225922365 cur_minmax = try sema.addConstant(sema.typeOf(operand), uncasted_operand_val);
......@@ -22292,7 +22398,7 @@ fn analyzeMinMax(
2229222398 const refined_elem_ty = try mod.intFittingRange(cur_min, cur_max);
2229322399 break :blk try mod.vectorType(.{
2229422400 .len = len,
22295 .child = refined_elem_ty.ip_index,
22401 .child = refined_elem_ty.toIntern(),
2229622402 });
2229722403 } else blk: {
2229822404 if (orig_ty.isAnyFloat()) break :blk orig_ty; // can't refine floats
......@@ -22377,7 +22483,7 @@ fn analyzeMinMax(
2237722483 const final_ty = if (is_vector)
2237822484 try mod.vectorType(.{
2237922485 .len = unrefined_ty.vectorLen(mod),
22380 .child = final_elem_ty.ip_index,
22486 .child = final_elem_ty.toIntern(),
2238122487 })
2238222488 else
2238322489 final_elem_ty;
......@@ -22765,7 +22871,7 @@ fn zirVarExtended(
2276522871 try sema.validateVarType(block, ty_src, var_ty, small.is_extern);
2276622872
2276722873 return sema.addConstant(var_ty, (try mod.intern(.{ .variable = .{
22768 .ty = var_ty.ip_index,
22874 .ty = var_ty.toIntern(),
2276922875 .init = init_val.toIntern(),
2277022876 .decl = sema.owner_decl_index,
2277122877 .lib_name = if (lib_name) |lname| (try mod.intern_pool.getOrPutString(
......@@ -23239,7 +23345,7 @@ fn zirBuiltinExtern(
2323923345
2324023346 {
2324123347 const new_var = try mod.intern(.{ .variable = .{
23242 .ty = ty.ip_index,
23348 .ty = ty.toIntern(),
2324323349 .init = .none,
2324423350 .decl = sema.owner_decl_index,
2324523351 .is_extern = true,
......@@ -23264,7 +23370,7 @@ fn zirBuiltinExtern(
2326423370 try sema.ensureDeclAnalyzed(new_decl_index);
2326523371
2326623372 const ref = try mod.intern(.{ .ptr = .{
23267 .ty = (try mod.singleConstPtrType(ty)).ip_index,
23373 .ty = (try mod.singleConstPtrType(ty)).toIntern(),
2326823374 .addr = .{ .decl = new_decl_index },
2326923375 } });
2327023376 return sema.addConstant(ty, ref.toValue());
......@@ -24207,7 +24313,7 @@ fn fieldVal(
2420724313 switch (try child_type.zigTypeTagOrPoison(mod)) {
2420824314 .ErrorSet => {
2420924315 const name = try ip.getOrPutString(gpa, field_name);
24210 switch (ip.indexToKey(child_type.ip_index)) {
24316 switch (ip.indexToKey(child_type.toIntern())) {
2421124317 .error_set_type => |error_set_type| blk: {
2421224318 if (error_set_type.nameIndex(ip, name) != null) break :blk;
2421324319 const msg = msg: {
......@@ -24232,7 +24338,7 @@ fn fieldVal(
2423224338 else
2423324339 try mod.singleErrorSetTypeNts(name);
2423424340 return sema.addConstant(error_set_type, (try mod.intern(.{ .err = .{
24235 .ty = error_set_type.ip_index,
24341 .ty = error_set_type.toIntern(),
2423624342 .name = name,
2423724343 } })).toValue());
2423824344 },
......@@ -24376,9 +24482,9 @@ fn fieldPtr(
2437624482
2437724483 if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| {
2437824484 return sema.addConstant(result_ty, (try mod.intern(.{ .ptr = .{
24379 .ty = result_ty.ip_index,
24485 .ty = result_ty.toIntern(),
2438024486 .addr = .{ .field = .{
24381 .base = val.ip_index,
24487 .base = val.toIntern(),
2438224488 .index = Value.slice_ptr_index,
2438324489 } },
2438424490 } })).toValue());
......@@ -24396,9 +24502,9 @@ fn fieldPtr(
2439624502
2439724503 if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| {
2439824504 return sema.addConstant(result_ty, (try mod.intern(.{ .ptr = .{
24399 .ty = result_ty.ip_index,
24505 .ty = result_ty.toIntern(),
2440024506 .addr = .{ .field = .{
24401 .base = val.ip_index,
24507 .base = val.toIntern(),
2440224508 .index = Value.slice_len_index,
2440324509 } },
2440424510 } })).toValue());
......@@ -24429,7 +24535,7 @@ fn fieldPtr(
2442924535 switch (child_type.zigTypeTag(mod)) {
2443024536 .ErrorSet => {
2443124537 const name = try ip.getOrPutString(gpa, field_name);
24432 switch (ip.indexToKey(child_type.ip_index)) {
24538 switch (ip.indexToKey(child_type.toIntern())) {
2443324539 .error_set_type => |error_set_type| blk: {
2443424540 if (error_set_type.nameIndex(ip, name) != null) {
2443524541 break :blk;
......@@ -24454,7 +24560,7 @@ fn fieldPtr(
2445424560 return sema.analyzeDeclRef(try anon_decl.finish(
2445524561 error_set_type,
2445624562 (try mod.intern(.{ .err = .{
24457 .ty = error_set_type.ip_index,
24563 .ty = error_set_type.toIntern(),
2445824564 .name = name,
2445924565 } })).toValue(),
2446024566 0, // default alignment
......@@ -24722,9 +24828,9 @@ fn finishFieldCallBind(
2472224828
2472324829 if (try sema.resolveDefinedValue(block, src, object_ptr)) |struct_ptr_val| {
2472424830 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(),
2472624832 .addr = .{ .field = .{
24727 .base = struct_ptr_val.ip_index,
24833 .base = struct_ptr_val.toIntern(),
2472824834 .index = field_index,
2472924835 } },
2473024836 } })).toValue());
......@@ -24908,7 +25014,7 @@ fn structFieldPtrByIndex(
2490825014
2490925015 if (field.is_comptime) {
2491025016 const val = try mod.intern(.{ .ptr = .{
24911 .ty = ptr_field_ty.ip_index,
25017 .ty = ptr_field_ty.toIntern(),
2491225018 .addr = .{ .comptime_field = try field.default_val.intern(field.ty, mod) },
2491325019 } });
2491425020 return sema.addConstant(ptr_field_ty, val.toValue());
......@@ -24916,7 +25022,7 @@ fn structFieldPtrByIndex(
2491625022
2491725023 if (try sema.resolveDefinedValue(block, src, struct_ptr)) |struct_ptr_val| {
2491825024 const val = try mod.intern(.{ .ptr = .{
24919 .ty = ptr_field_ty.ip_index,
25025 .ty = ptr_field_ty.toIntern(),
2492025026 .addr = .{ .field = .{
2492125027 .base = try struct_ptr_val.intern(struct_ptr_ty, mod),
2492225028 .index = field_index,
......@@ -24942,7 +25048,7 @@ fn structFieldVal(
2494225048 assert(unresolved_struct_ty.zigTypeTag(mod) == .Struct);
2494325049
2494425050 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())) {
2494625052 .struct_type => |struct_type| {
2494725053 const struct_obj = mod.structPtrUnwrap(struct_type.index).?;
2494825054 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(
2511625222 .Packed, .Extern => {},
2511725223 }
2511825224 return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{
25119 .ty = ptr_field_ty.ip_index,
25225 .ty = ptr_field_ty.toIntern(),
2512025226 .addr = .{ .field = .{
25121 .base = union_ptr_val.ip_index,
25227 .base = union_ptr_val.toIntern(),
2512225228 .index = field_index,
2512325229 } },
2512425230 } })).toValue());
......@@ -25413,16 +25519,16 @@ fn tupleFieldPtr(
2541325519
2541425520 if (try tuple_ty.structFieldValueComptime(mod, field_index)) |default_val| {
2541525521 return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{
25416 .ty = ptr_field_ty.ip_index,
25417 .addr = .{ .comptime_field = default_val.ip_index },
25522 .ty = ptr_field_ty.toIntern(),
25523 .addr = .{ .comptime_field = default_val.toIntern() },
2541825524 } })).toValue());
2541925525 }
2542025526
2542125527 if (try sema.resolveMaybeUndefVal(tuple_ptr)) |tuple_ptr_val| {
2542225528 return sema.addConstant(ptr_field_ty, (try mod.intern(.{ .ptr = .{
25423 .ty = ptr_field_ty.ip_index,
25529 .ty = ptr_field_ty.toIntern(),
2542425530 .addr = .{ .field = .{
25425 .base = tuple_ptr_val.ip_index,
25531 .base = tuple_ptr_val.toIntern(),
2542625532 .index = field_index,
2542725533 } },
2542825534 } })).toValue());
......@@ -25787,11 +25893,11 @@ fn coerceExtra(
2578725893 var in_memory_result = try sema.coerceInMemoryAllowed(block, dest_ty, inst_ty, false, target, dest_ty_src, inst_src);
2578825894 if (in_memory_result == .ok) {
2578925895 if (maybe_inst_val) |val| {
25790 if (val.ip_index == .none or val.ip_index == .null_value) {
25896 if (val.ip_index == .none) {
2579125897 // Keep the comptime Value representation; take the new type.
2579225898 return sema.addConstant(dest_ty, val);
2579325899 } 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());
2579525901 return sema.addConstant(dest_ty, new_val.toValue());
2579625902 }
2579725903 }
......@@ -25816,7 +25922,7 @@ fn coerceExtra(
2581625922 // cast from ?*T and ?[*]T to ?*anyopaque
2581725923 // but don't do it if the source type is a double pointer
2581825924 if (dest_ty.isPtrLikeOptional(mod) and
25819 dest_ty.elemType2(mod).ip_index == .anyopaque_type and
25925 dest_ty.elemType2(mod).toIntern() == .anyopaque_type and
2582025926 inst_ty.isPtrAtRuntime(mod))
2582125927 anyopaque_check: {
2582225928 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :optional;
......@@ -25954,7 +26060,7 @@ fn coerceExtra(
2595426060
2595526061 // cast from *T and [*]T to *anyopaque
2595626062 // 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: {
2595826064 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer;
2595926065 const elem_ty = inst_ty.elemType2(mod);
2596026066 if (elem_ty.zigTypeTag(mod) == .Pointer or elem_ty.isPtrLikeOptional(mod)) {
......@@ -26084,12 +26190,12 @@ fn coerceExtra(
2608426190 // Optional slice is represented with a null pointer so
2608526191 // we use a dummy pointer value with the required alignment.
2608626192 return sema.addConstant(dest_ty, (try mod.intern(.{ .ptr = .{
26087 .ty = dest_ty.ip_index,
26193 .ty = dest_ty.toIntern(),
2608826194 .addr = .{ .int = (if (dest_info.@"align" != 0)
2608926195 try mod.intValue(Type.usize, dest_info.@"align")
2609026196 else
26091 try dest_info.pointee_type.lazyAbiAlignment(mod)).ip_index },
26092 .len = (try mod.intValue(Type.usize, 0)).ip_index,
26197 try dest_info.pointee_type.lazyAbiAlignment(mod)).toIntern() },
26198 .len = (try mod.intValue(Type.usize, 0)).toIntern(),
2609326199 } })).toValue());
2609426200 }
2609526201
......@@ -26166,7 +26272,7 @@ fn coerceExtra(
2616626272 if (!opts.report_err) return error.NotCoercible;
2616726273 return sema.fail(block, inst_src, "type '{}' cannot represent integer value '{}'", .{ dest_ty.fmt(sema.mod), val.fmtValue(inst_ty, sema.mod) });
2616826274 }
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());
2617026276 return try sema.addConstant(dest_ty, new_val.toValue());
2617126277 }
2617226278 if (dest_ty.zigTypeTag(mod) == .ComptimeInt) {
......@@ -26258,7 +26364,7 @@ fn coerceExtra(
2625826364 .EnumLiteral => {
2625926365 // enum literal to enum
2626026366 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;
2626226368 const bytes = mod.intern_pool.stringToSlice(string);
2626326369 const field_index = dest_ty.enumFieldIndex(bytes, mod) orelse {
2626426370 const msg = msg: {
......@@ -26294,14 +26400,14 @@ fn coerceExtra(
2629426400 .ErrorUnion => switch (inst_ty.zigTypeTag(mod)) {
2629526401 .ErrorUnion => eu: {
2629626402 if (maybe_inst_val) |inst_val| {
26297 switch (inst_val.ip_index) {
26403 switch (inst_val.toIntern()) {
2629826404 .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())) {
2630026406 .error_union => |error_union| switch (error_union.val) {
2630126407 .err_name => |err_name| {
2630226408 const error_set_ty = inst_ty.errorUnionSet(mod);
2630326409 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(),
2630526411 .name = err_name,
2630626412 } })).toValue());
2630726413 return sema.wrapErrorUnionSet(block, dest_ty, error_set_val, inst_src);
......@@ -26597,7 +26703,7 @@ const InMemoryCoercionResult = union(enum) {
2659726703 break;
2659826704 },
2659926705 .array_sentinel => |sentinel| {
26600 if (sentinel.actual.ip_index != .unreachable_value) {
26706 if (sentinel.actual.toIntern() != .unreachable_value) {
2660126707 try sema.errNote(block, src, msg, "array sentinel '{}' cannot cast into array sentinel '{}'", .{
2660226708 sentinel.actual.fmtValue(sentinel.ty, sema.mod), sentinel.wanted.fmtValue(sentinel.ty, sema.mod),
2660326709 });
......@@ -26724,7 +26830,7 @@ const InMemoryCoercionResult = union(enum) {
2672426830 break;
2672526831 },
2672626832 .ptr_sentinel => |sentinel| {
26727 if (sentinel.actual.ip_index != .unreachable_value) {
26833 if (sentinel.actual.toIntern() != .unreachable_value) {
2672826834 try sema.errNote(block, src, msg, "pointer sentinel '{}' cannot cast into pointer sentinel '{}'", .{
2672926835 sentinel.actual.fmtValue(sentinel.ty, sema.mod), sentinel.wanted.fmtValue(sentinel.ty, sema.mod),
2673026836 });
......@@ -27016,9 +27122,9 @@ fn coerceInMemoryAllowedErrorSets(
2701627122 const dst_ies = mod.inferredErrorSetPtr(dst_ies_index);
2701727123 // We will make an effort to return `ok` without resolving either error set, to
2701827124 // avoid unnecessary "unable to resolve error set" dependency loop errors.
27019 switch (src_ty.ip_index) {
27125 switch (src_ty.toIntern()) {
2702027126 .anyerror_type => {},
27021 else => switch (ip.indexToKey(src_ty.ip_index)) {
27127 else => switch (ip.indexToKey(src_ty.toIntern())) {
2702227128 .inferred_error_set_type => |src_index| {
2702327129 // If both are inferred error sets of functions, and
2702427130 // the dest includes the source function, the coercion is OK.
......@@ -27054,15 +27160,15 @@ fn coerceInMemoryAllowedErrorSets(
2705427160 var missing_error_buf = std.ArrayList(InternPool.NullTerminatedString).init(gpa);
2705527161 defer missing_error_buf.deinit();
2705627162
27057 switch (src_ty.ip_index) {
27058 .anyerror_type => switch (ip.indexToKey(dest_ty.ip_index)) {
27163 switch (src_ty.toIntern()) {
27164 .anyerror_type => switch (ip.indexToKey(dest_ty.toIntern())) {
2705927165 .inferred_error_set_type => unreachable, // Caught by dest_ty.isAnyError(mod) above.
2706027166 .simple_type => unreachable, // filtered out above
2706127167 .error_set_type => return .from_anyerror,
2706227168 else => unreachable,
2706327169 },
2706427170
27065 else => switch (ip.indexToKey(src_ty.ip_index)) {
27171 else => switch (ip.indexToKey(src_ty.toIntern())) {
2706627172 .inferred_error_set_type => |src_index| {
2706727173 const src_data = mod.inferredErrorSetPtr(src_index);
2706827174
......@@ -27520,9 +27626,9 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
2752027626 // allocations is relevant to this function, or why it would have
2752127627 // different behavior depending on whether the types were inferred.
2752227628 // Something seems wrong here.
27523 if (prev_ptr_ty.ip_index == .none) {
27524 if (prev_ptr_ty.ip_index == .inferred_alloc_mut_type) return null;
27525 if (prev_ptr_ty.ip_index == .inferred_alloc_const_type) return null;
27629 switch (prev_ptr_ty.ip_index) {
27630 .inferred_alloc_mut_type, .inferred_alloc_const_type => return null,
27631 else => {},
2752627632 }
2752727633
2752827634 const prev_ptr_child_ty = prev_ptr_ty.childType(mod);
......@@ -27554,11 +27660,11 @@ fn storePtrVal(
2755427660) !void {
2755527661 const mod = sema.mod;
2755627662 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
2755927665 switch (mut_kit.pointee) {
2756027666 .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) {
2756227668 if (!operand_val.eql(val_ptr.*, operand_ty, sema.mod)) {
2756327669 // TODO use failWithInvalidComptimeFieldStore
2756427670 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(
2760127707}
2760227708
2760327709const ComptimePtrMutationKit = struct {
27604 decl_ref_mut: InternPool.Key.Ptr.Addr.MutDecl,
27710 mut_decl: InternPool.Key.Ptr.Addr.MutDecl,
2760527711 pointee: union(enum) {
2760627712 /// The pointer type matches the actual comptime Value so a direct
2760727713 /// modification is possible.
......@@ -27627,12 +27733,12 @@ const ComptimePtrMutationKit = struct {
2762727733 decl_arena: std.heap.ArenaAllocator = undefined,
2762827734
2762927735 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);
2763127737 return decl.value_arena.?.acquire(mod.gpa, &self.decl_arena);
2763227738 }
2763327739
2763427740 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);
2763627742 decl.value_arena.?.release(&self.decl_arena);
2763727743 self.decl_arena = undefined;
2763827744 }
......@@ -27645,99 +27751,85 @@ fn beginComptimePtrMutation(
2764527751 ptr_val: Value,
2764627752 ptr_elem_ty: Type,
2764727753) CompileError!ComptimePtrMutationKit {
27648 if (true) unreachable;
2764927754 const mod = sema.mod;
27650 switch (ptr_val.tag()) {
27651 .decl_ref_mut => {
27652 const decl_ref_mut = ptr_val.castTag(.decl_ref_mut).?.data;
27653 const decl = sema.mod.declPtr(decl_ref_mut.decl_index);
27654 return sema.beginComptimePtrMutationInner(block, src, decl.ty, &decl.val, ptr_elem_ty, decl_ref_mut);
27755 const ptr = mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr;
27756 switch (ptr.addr) {
27757 .decl => unreachable, // isComptimeMutablePtr has been checked already
27758 .mut_decl => |mut_decl| {
27759 const decl = mod.declPtr(mut_decl.decl);
27760 return sema.beginComptimePtrMutationInner(block, src, decl.ty, &decl.val, ptr_elem_ty, mut_decl);
2765527761 },
27656 .comptime_field_ptr => {
27657 const payload = ptr_val.castTag(.comptime_field_ptr).?.data;
27762 .comptime_field => |comptime_field| {
2765827763 const duped = try sema.arena.create(Value);
27659 duped.* = payload.field_val;
27660 return sema.beginComptimePtrMutationInner(block, src, payload.field_ty, duped, ptr_elem_ty, .{
27661 .decl_index = @intToEnum(Module.Decl.Index, 0),
27764 duped.* = comptime_field.toValue();
27765 return sema.beginComptimePtrMutationInner(block, src, mod.intern_pool.typeOf(ptr_val.toIntern()).toType(), duped, ptr_elem_ty, .{
27766 .decl = undefined,
2766227767 .runtime_index = .comptime_field_ptr,
2766327768 });
2766427769 },
27665 .elem_ptr => {
27666 const elem_ptr = ptr_val.castTag(.elem_ptr).?.data;
27667 var parent = try sema.beginComptimePtrMutation(block, src, elem_ptr.array_ptr, elem_ptr.elem_ty);
27668
27669 switch (parent.pointee) {
27670 .direct => |val_ptr| switch (parent.ty.zigTypeTag(mod)) {
27671 .Array, .Vector => {
27672 const check_len = parent.ty.arrayLenIncludingSentinel(mod);
27673 if (elem_ptr.index >= check_len) {
27674 // TODO have the parent include the decl so we can say "declared here"
27675 return sema.fail(block, src, "comptime store of index {d} out of bounds of array length {d}", .{
27676 elem_ptr.index, check_len,
27677 });
27678 }
27679 const elem_ty = parent.ty.childType(mod);
27680
27681 // We might have a pointer to multiple elements of the array (e.g. a pointer
27682 // to a sub-array). In this case, we just have to reinterpret the relevant
27683 // bytes of the whole array rather than any single element.
27684 const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty);
27685 if (elem_abi_size_u64 < try sema.typeAbiSize(ptr_elem_ty)) {
27686 const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);
27687 return .{
27688 .decl_ref_mut = parent.decl_ref_mut,
27689 .pointee = .{ .reinterpret = .{
27690 .val_ptr = val_ptr,
27691 .byte_offset = elem_abi_size * elem_ptr.index,
27692 } },
27693 .ty = parent.ty,
27694 };
27695 }
27696
27697 switch (val_ptr.ip_index) {
27698 .undef => {
27699 // An array has been initialized to undefined at comptime and now we
27700 // are for the first time setting an element. We must change the representation
27701 // of the array from `undef` to `array`.
27702 const arena = parent.beginArena(sema.mod);
27703 defer parent.finishArena(sema.mod);
27704
27705 const array_len_including_sentinel =
27706 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));
27707 const elems = try arena.alloc(Value, array_len_including_sentinel);
27708 @memset(elems, Value.undef);
27709
27710 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
27770 else => unreachable,
27771 }
27772 if (true) unreachable;
27773 switch (ptr_val.toIntern()) {
27774 .none => switch (ptr_val.tag()) {
27775 .decl_ref_mut => {
27776 const decl_ref_mut = ptr_val.castTag(.decl_ref_mut).?.data;
27777 const decl = sema.mod.declPtr(decl_ref_mut.decl_index);
27778 return sema.beginComptimePtrMutationInner(block, src, decl.ty, &decl.val, ptr_elem_ty, decl_ref_mut);
27779 },
27780 .comptime_field_ptr => {
27781 const payload = ptr_val.castTag(.comptime_field_ptr).?.data;
27782 const duped = try sema.arena.create(Value);
27783 duped.* = payload.field_val;
27784 return sema.beginComptimePtrMutationInner(block, src, payload.field_ty, duped, ptr_elem_ty, .{
27785 .decl_index = @intToEnum(Module.Decl.Index, 0),
27786 .runtime_index = .comptime_field_ptr,
27787 });
27788 },
27789 .elem_ptr => {
27790 const elem_ptr = ptr_val.castTag(.elem_ptr).?.data;
27791 var parent = try sema.beginComptimePtrMutation(block, src, elem_ptr.array_ptr, elem_ptr.elem_ty);
27792
27793 switch (parent.pointee) {
27794 .direct => |val_ptr| switch (parent.ty.zigTypeTag(mod)) {
27795 .Array, .Vector => {
27796 const check_len = parent.ty.arrayLenIncludingSentinel(mod);
27797 if (elem_ptr.index >= check_len) {
27798 // TODO have the parent include the decl so we can say "declared here"
27799 return sema.fail(block, src, "comptime store of index {d} out of bounds of array length {d}", .{
27800 elem_ptr.index, check_len,
27801 });
27802 }
27803 const elem_ty = parent.ty.childType(mod);
27804
27805 // We might have a pointer to multiple elements of the array (e.g. a pointer
27806 // to a sub-array). In this case, we just have to reinterpret the relevant
27807 // bytes of the whole array rather than any single element.
27808 const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty);
27809 if (elem_abi_size_u64 < try sema.typeAbiSize(ptr_elem_ty)) {
27810 const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);
27811 return .{
27812 .decl_ref_mut = parent.decl_ref_mut,
27813 .pointee = .{ .reinterpret = .{
27814 .val_ptr = val_ptr,
27815 .byte_offset = elem_abi_size * elem_ptr.index,
27816 } },
27817 .ty = parent.ty,
27818 };
27819 }
2771127820
27712 return beginComptimePtrMutationInner(
27713 sema,
27714 block,
27715 src,
27716 elem_ty,
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.
27821 switch (val_ptr.toIntern()) {
27822 .undef => {
27823 // An array has been initialized to undefined at comptime and now we
27824 // are for the first time setting an element. We must change the representation
27825 // of the array from `undef` to `array`.
2772927826 const arena = parent.beginArena(sema.mod);
2773027827 defer parent.finishArena(sema.mod);
2773127828
27732 const bytes = val_ptr.castTag(.bytes).?.data;
27733 const dest_len = parent.ty.arrayLenIncludingSentinel(mod);
27734 // bytes.len may be one greater than dest_len because of the case when
27735 // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted.
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 }
27829 const array_len_including_sentinel =
27830 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));
27831 const elems = try arena.alloc(Value, array_len_including_sentinel);
27832 @memset(elems, Value.undef);
2774127833
2774227834 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
2774327835
......@@ -27751,392 +27843,383 @@ fn beginComptimePtrMutation(
2775127843 parent.decl_ref_mut,
2775227844 );
2775327845 },
27754 .str_lit => {
27755 // An array is memory-optimized to store a slice of bytes, but we are about
27756 // to modify an individual field and the representation has to change.
27757 // If we wanted to avoid this, there would need to be special detection
27758 // elsewhere to identify when writing a value to an array element that is stored
27759 // using the `str_lit` tag, and handle it without making a call to this function.
27760 const arena = parent.beginArena(sema.mod);
27761 defer parent.finishArena(sema.mod);
27762
27763 const str_lit = val_ptr.castTag(.str_lit).?.data;
27764 const dest_len = parent.ty.arrayLenIncludingSentinel(mod);
27765 const bytes = sema.mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
27766 const elems = try arena.alloc(Value, @intCast(usize, dest_len));
27767 for (bytes, 0..) |byte, i| {
27768 elems[i] = try mod.intValue(elem_ty, byte);
27769 }
27770 if (parent.ty.sentinel(mod)) |sent_val| {
27771 assert(elems.len == bytes.len + 1);
27772 elems[bytes.len] = sent_val;
27773 }
27774
27775 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
27776
27777 return beginComptimePtrMutationInner(
27846 .none => switch (val_ptr.tag()) {
27847 .bytes => {
27848 // An array is memory-optimized to store a slice of bytes, but we are about
27849 // to modify an individual field and the representation has to change.
27850 // If we wanted to avoid this, there would need to be special detection
27851 // elsewhere to identify when writing a value to an array element that is stored
27852 // using the `bytes` tag, and handle it without making a call to this function.
27853 const arena = parent.beginArena(sema.mod);
27854 defer parent.finishArena(sema.mod);
27855
27856 const bytes = val_ptr.castTag(.bytes).?.data;
27857 const dest_len = parent.ty.arrayLenIncludingSentinel(mod);
27858 // bytes.len may be one greater than dest_len because of the case when
27859 // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted.
27860 assert(bytes.len >= dest_len);
27861 const elems = try arena.alloc(Value, @intCast(usize, dest_len));
27862 for (elems, 0..) |*elem, i| {
27863 elem.* = try mod.intValue(elem_ty, bytes[i]);
27864 }
27865
27866 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
27867
27868 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(
2777827945 sema,
2777927946 block,
2778027947 src,
2778127948 elem_ty,
27782 &elems[elem_ptr.index],
27949 &val_ptr.castTag(.aggregate).?.data[elem_ptr.index],
2778327950 ptr_elem_ty,
2778427951 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,
2778627969 },
27787 .repeated => {
27788 // An array is memory-optimized to store only a single element value, and
27789 // that value is understood to be the same for the entire length of the array.
27790 // However, now we want to modify an individual field and so the
27791 // representation has to change. If we wanted to avoid this, there would
27792 // need to be special detection elsewhere to identify when writing a value to an
27793 // array element that is stored using the `repeated` tag, and handle it
27794 // without making a call to this function.
27795 const arena = parent.beginArena(sema.mod);
27796 defer parent.finishArena(sema.mod);
27970 else => unreachable,
27971 }
27972 },
27973 else => {
27974 if (elem_ptr.index != 0) {
27975 // TODO include a "declared here" note for the decl
27976 return sema.fail(block, src, "out of bounds comptime store of index {d}", .{
27977 elem_ptr.index,
27978 });
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);
27799 const array_len_including_sentinel =
27800 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));
27801 const elems = try arena.alloc(Value, array_len_including_sentinel);
27802 if (elems.len > 0) elems[0] = repeated_val;
27803 for (elems[1..]) |*elem| {
27804 elem.* = try repeated_val.copy(arena);
27805 }
28002 const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty);
28003 const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);
28004 return ComptimePtrMutationKit{
28005 .decl_ref_mut = parent.decl_ref_mut,
28006 .pointee = .{ .reinterpret = .{
28007 .val_ptr = reinterpret.val_ptr,
28008 .byte_offset = reinterpret.byte_offset + elem_abi_size * elem_ptr.index,
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
2780928037 return beginComptimePtrMutationInner(
2781028038 sema,
2781128039 block,
2781228040 src,
27813 elem_ty,
27814 &elems[elem_ptr.index],
28041 parent.ty.structFieldType(field_index, mod),
28042 &fields[field_index],
2781528043 ptr_elem_ty,
2781628044 parent.decl_ref_mut,
2781728045 );
2781828046 },
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(
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 ),
28055 val_ptr.* = Value.initPayload(&payload.base);
2782928056
27830 .the_only_possible_value => {
27831 const duped = try sema.arena.create(Value);
27832 duped.* = Value.initTag(.the_only_possible_value);
2783328057 return beginComptimePtrMutationInner(
2783428058 sema,
2783528059 block,
2783628060 src,
27837 elem_ty,
27838 duped,
28061 parent.ty.structFieldType(field_index, mod),
28062 &payload.data.val,
2783928063 ptr_elem_ty,
2784028064 parent.decl_ref_mut,
2784128065 );
2784228066 },
27843
28067 .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 },
2784428097 else => unreachable,
27845 },
27846 else => unreachable,
27847 }
27848 },
27849 else => {
27850 if (elem_ptr.index != 0) {
27851 // TODO include a "declared here" note for the decl
27852 return sema.fail(block, src, "out of bounds comptime store of index {d}", .{
27853 elem_ptr.index,
27854 });
27855 }
27856 return beginComptimePtrMutationInner(
27857 sema,
27858 block,
27859 src,
27860 parent.ty,
27861 val_ptr,
27862 ptr_elem_ty,
27863 parent.decl_ref_mut,
27864 );
27865 },
27866 },
27867 .reinterpret => |reinterpret| {
27868 if (!elem_ptr.elem_ty.hasWellDefinedLayout(mod)) {
27869 // Even though the parent value type has well-defined memory layout, our
27870 // pointer type does not.
27871 return ComptimePtrMutationKit{
27872 .decl_ref_mut = parent.decl_ref_mut,
27873 .pointee = .bad_ptr_ty,
27874 .ty = elem_ptr.elem_ty,
27875 };
27876 }
28098 }
28099 },
28100 .empty_struct => {
28101 const duped = try sema.arena.create(Value);
28102 duped.* = Value.initTag(.the_only_possible_value);
28103 return beginComptimePtrMutationInner(
28104 sema,
28105 block,
28106 src,
28107 parent.ty.structFieldType(field_index, mod),
28108 duped,
28109 ptr_elem_ty,
28110 parent.decl_ref_mut,
28111 );
28112 },
28113 .none => switch (val_ptr.tag()) {
28114 .aggregate => return beginComptimePtrMutationInner(
28115 sema,
28116 block,
28117 src,
28118 parent.ty.structFieldType(field_index, mod),
28119 &val_ptr.castTag(.aggregate).?.data[field_index],
28120 ptr_elem_ty,
28121 parent.decl_ref_mut,
28122 ),
28123 .repeated => {
28124 const arena = parent.beginArena(sema.mod);
28125 defer parent.finishArena(sema.mod);
2787728126
27878 const elem_abi_size_u64 = try sema.typeAbiSize(elem_ptr.elem_ty);
27879 const elem_abi_size = try sema.usizeCast(block, src, elem_abi_size_u64);
27880 return ComptimePtrMutationKit{
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);
28127 const elems = try arena.alloc(Value, parent.ty.structFieldCount(mod));
28128 @memset(elems, val_ptr.castTag(.repeated).?.data);
28129 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
2791228130
2791328131 return beginComptimePtrMutationInner(
2791428132 sema,
2791528133 block,
2791628134 src,
2791728135 parent.ty.structFieldType(field_index, mod),
27918 &fields[field_index],
28136 &elems[field_index],
2791928137 ptr_elem_ty,
2792028138 parent.decl_ref_mut,
2792128139 );
2792228140 },
27923 .Union => {
27924 const payload = try arena.create(Value.Payload.Union);
27925 const tag_ty = parent.ty.unionTagTypeHypothetical(mod);
27926 payload.* = .{ .data = .{
27927 .tag = try mod.enumValueFieldIndex(tag_ty, field_index),
27928 .val = Value.undef,
27929 } };
28141 .@"union" => {
28142 // We need to set the active field of the union.
28143 const union_tag_ty = field_ptr.container_ty.unionTagTypeHypothetical(mod);
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
2793328148 return beginComptimePtrMutationInner(
2793428149 sema,
2793528150 block,
2793628151 src,
2793728152 parent.ty.structFieldType(field_index, mod),
27938 &payload.data.val,
28153 &payload.val,
2793928154 ptr_elem_ty,
2794028155 parent.decl_ref_mut,
2794128156 );
2794228157 },
27943 .Pointer => {
27944 assert(parent.ty.isSlice(mod));
27945 val_ptr.* = try Value.Tag.slice.create(arena, .{
27946 .ptr = Value.undef,
27947 .len = Value.undef,
27948 });
28158 .slice => switch (field_index) {
28159 Value.Payload.Slice.ptr_index => return beginComptimePtrMutationInner(
28160 sema,
28161 block,
28162 src,
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) {
27951 Value.Payload.Slice.ptr_index => return beginComptimePtrMutationInner(
27952 sema,
27953 block,
27954 src,
27955 parent.ty.slicePtrFieldType(mod),
27956 &val_ptr.castTag(.slice).?.data.ptr,
27957 ptr_elem_ty,
27958 parent.decl_ref_mut,
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 ),
28169 Value.Payload.Slice.len_index => return beginComptimePtrMutationInner(
28170 sema,
28171 block,
28172 src,
28173 Type.usize,
28174 &val_ptr.castTag(.slice).?.data.len,
28175 ptr_elem_ty,
28176 parent.decl_ref_mut,
28177 ),
2796928178
27970 else => unreachable,
27971 }
28179 else => unreachable,
2797228180 },
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
2805528182 else => unreachable,
2805628183 },
28057
2805828184 else => unreachable,
2805928185 },
28060 else => unreachable,
28061 },
28062 .reinterpret => |reinterpret| {
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
28186 .reinterpret => |reinterpret| {
28187 const field_offset_u64 = field_ptr.container_ty.structFieldOffset(field_index, mod);
28188 const field_offset = try sema.usizeCast(block, src, field_offset_u64);
2810428189 return ComptimePtrMutationKit{
2810528190 .decl_ref_mut = parent.decl_ref_mut,
28106 .pointee = .{ .direct = &payload.data },
28107 .ty = payload_ty,
28191 .pointee = .{ .reinterpret = .{
28192 .val_ptr = reinterpret.val_ptr,
28193 .byte_offset = reinterpret.byte_offset + field_offset,
28194 } },
28195 .ty = parent.ty,
2810828196 };
28109 }
28110 },
28111 .bad_decl_ty, .bad_ptr_ty => return parent,
28112 // Even though the parent value type has well-defined memory layout, our
28113 // pointer type does not.
28114 .reinterpret => return ComptimePtrMutationKit{
28115 .decl_ref_mut = parent.decl_ref_mut,
28116 .pointee = .bad_ptr_ty,
28117 .ty = eu_ptr.container_ty,
28118 },
28119 }
28120 },
28121 .opt_payload_ptr => {
28122 const opt_ptr = if (ptr_val.castTag(.opt_payload_ptr)) |some| some.data else {
28123 return sema.beginComptimePtrMutation(block, src, ptr_val, ptr_elem_ty.optionalChild(mod));
28124 };
28125 var parent = try sema.beginComptimePtrMutation(block, src, opt_ptr.container_ptr, opt_ptr.container_ty);
28126 switch (parent.pointee) {
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
28197 },
28198 .bad_decl_ty, .bad_ptr_ty => return parent,
28199 }
28200 },
28201 .eu_payload_ptr => {
28202 const eu_ptr = ptr_val.castTag(.eu_payload_ptr).?.data;
28203 var parent = try sema.beginComptimePtrMutation(block, src, eu_ptr.container_ptr, eu_ptr.container_ty);
28204 switch (parent.pointee) {
28205 .direct => |val_ptr| {
28206 const payload_ty = parent.ty.errorUnionPayload(mod);
28207 if (val_ptr.ip_index == .none and val_ptr.tag() == .eu_payload) {
28208 return ComptimePtrMutationKit{
28209 .decl_ref_mut = parent.decl_ref_mut,
28210 .pointee = .{ .direct = &val_ptr.castTag(.eu_payload).?.data },
28211 .ty = payload_ty,
28212 };
28213 } else {
28214 // An error union has been initialized to undefined at comptime and now we
2813228215 // 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`.
2813428217 const arena = parent.beginArena(sema.mod);
2813528218 defer parent.finishArena(sema.mod);
2813628219
2813728220 const payload = try arena.create(Value.Payload.SubValue);
2813828221 payload.* = .{
28139 .base = .{ .tag = .opt_payload },
28222 .base = .{ .tag = .eu_payload },
2814028223 .data = Value.undef,
2814128224 };
2814228225
......@@ -28147,39 +28230,84 @@ fn beginComptimePtrMutation(
2814728230 .pointee = .{ .direct = &payload.data },
2814828231 .ty = payload_ty,
2814928232 };
28150 },
28151 .none => switch (val_ptr.tag()) {
28152 .opt_payload => return ComptimePtrMutationKit{
28153 .decl_ref_mut = parent.decl_ref_mut,
28154 .pointee = .{ .direct = &val_ptr.castTag(.opt_payload).?.data },
28155 .ty = payload_ty,
28233 }
28234 },
28235 .bad_decl_ty, .bad_ptr_ty => return parent,
28236 // Even though the parent value type has well-defined memory layout, our
28237 // pointer type does not.
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 };
2815628274 },
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 },
2815828288 else => return ComptimePtrMutationKit{
2815928289 .decl_ref_mut = parent.decl_ref_mut,
2816028290 .pointee = .{ .direct = val_ptr },
2816128291 .ty = payload_ty,
2816228292 },
28163 },
28164 else => return ComptimePtrMutationKit{
28165 .decl_ref_mut = parent.decl_ref_mut,
28166 .pointee = .{ .direct = val_ptr },
28167 .ty = payload_ty,
28168 },
28169 }
28170 },
28171 .bad_decl_ty, .bad_ptr_ty => return parent,
28172 // Even though the parent value type has well-defined memory layout, our
28173 // pointer type does not.
28174 .reinterpret => return ComptimePtrMutationKit{
28175 .decl_ref_mut = parent.decl_ref_mut,
28176 .pointee = .bad_ptr_ty,
28177 .ty = opt_ptr.container_ty,
28178 },
28179 }
28293 }
28294 },
28295 .bad_decl_ty, .bad_ptr_ty => return parent,
28296 // Even though the parent value type has well-defined memory layout, our
28297 // pointer type does not.
28298 .reinterpret => return ComptimePtrMutationKit{
28299 .decl_ref_mut = parent.decl_ref_mut,
28300 .pointee = .bad_ptr_ty,
28301 .ty = opt_ptr.container_ty,
28302 },
28303 }
28304 },
28305 .decl_ref => unreachable, // isComptimeMutablePtr has been checked already
28306 else => unreachable,
28307 },
28308 else => switch (mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr) {
28309 else => unreachable,
2818028310 },
28181 .decl_ref => unreachable, // isComptimeMutablePtr has been checked already
28182 else => unreachable,
2818328311 }
2818428312}
2818528313
......@@ -28190,13 +28318,13 @@ fn beginComptimePtrMutationInner(
2819028318 decl_ty: Type,
2819128319 decl_val: *Value,
2819228320 ptr_elem_ty: Type,
28193 decl_ref_mut: Value.Payload.DeclRefMut.Data,
28321 mut_decl: InternPool.Key.Ptr.Addr.MutDecl,
2819428322) CompileError!ComptimePtrMutationKit {
2819528323 const mod = sema.mod;
2819628324 const target = mod.getTarget();
2819728325 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);
2820028328 var decl_arena: std.heap.ArenaAllocator = undefined;
2820128329 const allocator = decl.value_arena.?.acquire(sema.gpa, &decl_arena);
2820228330 defer decl.value_arena.?.release(&decl_arena);
......@@ -28204,7 +28332,7 @@ fn beginComptimePtrMutationInner(
2820428332
2820528333 if (coerce_ok) {
2820628334 return ComptimePtrMutationKit{
28207 .decl_ref_mut = decl_ref_mut,
28335 .mut_decl = mut_decl,
2820828336 .pointee = .{ .direct = decl_val },
2820928337 .ty = decl_ty,
2821028338 };
......@@ -28215,7 +28343,7 @@ fn beginComptimePtrMutationInner(
2821528343 const decl_elem_ty = decl_ty.childType(mod);
2821628344 if ((try sema.coerceInMemoryAllowed(block, ptr_elem_ty, decl_elem_ty, true, target, src, src)) == .ok) {
2821728345 return ComptimePtrMutationKit{
28218 .decl_ref_mut = decl_ref_mut,
28346 .mut_decl = mut_decl,
2821928347 .pointee = .{ .direct = decl_val },
2822028348 .ty = decl_ty,
2822128349 };
......@@ -28224,20 +28352,20 @@ fn beginComptimePtrMutationInner(
2822428352
2822528353 if (!decl_ty.hasWellDefinedLayout(mod)) {
2822628354 return ComptimePtrMutationKit{
28227 .decl_ref_mut = decl_ref_mut,
28228 .pointee = .{ .bad_decl_ty = {} },
28355 .mut_decl = mut_decl,
28356 .pointee = .bad_decl_ty,
2822928357 .ty = decl_ty,
2823028358 };
2823128359 }
2823228360 if (!ptr_elem_ty.hasWellDefinedLayout(mod)) {
2823328361 return ComptimePtrMutationKit{
28234 .decl_ref_mut = decl_ref_mut,
28235 .pointee = .{ .bad_ptr_ty = {} },
28362 .mut_decl = mut_decl,
28363 .pointee = .bad_ptr_ty,
2823628364 .ty = ptr_elem_ty,
2823728365 };
2823828366 }
2823928367 return ComptimePtrMutationKit{
28240 .decl_ref_mut = decl_ref_mut,
28368 .mut_decl = mut_decl,
2824128369 .pointee = .{ .reinterpret = .{
2824228370 .val_ptr = decl_val,
2824328371 .byte_offset = 0,
......@@ -28282,7 +28410,7 @@ fn beginComptimePtrLoad(
2828228410 const mod = sema.mod;
2828328411 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())) {
2828628414 .ptr => |ptr| switch (ptr.addr) {
2828728415 .decl, .mut_decl => blk: {
2828828416 const decl_index = switch (ptr.addr) {
......@@ -28319,7 +28447,7 @@ fn beginComptimePtrLoad(
2831928447 (try sema.coerceInMemoryAllowed(block, container_ty, tv.ty, false, target, src, src)) == .ok or
2832028448 (try sema.coerceInMemoryAllowed(block, tv.ty, container_ty, false, target, src, src)) == .ok;
2832128449 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())) {
2832328451 .error_union => |error_union| switch (error_union.val) {
2832428452 .err_name => |err_name| return sema.fail(block, src, "attempt to unwrap error: {s}", .{mod.intern_pool.stringToSlice(err_name)}),
2832528453 .payload => |payload| payload,
......@@ -28462,7 +28590,7 @@ fn beginComptimePtrLoad(
2846228590 },
2846328591 Value.slice_len_index => TypedValue{
2846428592 .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(),
2846628594 },
2846728595 else => unreachable,
2846828596 };
......@@ -28565,9 +28693,9 @@ fn coerceArrayPtrToSlice(
2856528693 const ptr_array_ty = sema.typeOf(inst);
2856628694 const array_ty = ptr_array_ty.childType(mod);
2856728695 const slice_val = try mod.intern(.{ .ptr = .{
28568 .ty = dest_ty.ip_index,
28569 .addr = mod.intern_pool.indexToKey(val.ip_index).ptr.addr,
28570 .len = (try mod.intValue(Type.usize, array_ty.arrayLen(mod))).ip_index,
28696 .ty = dest_ty.toIntern(),
28697 .addr = mod.intern_pool.indexToKey(val.toIntern()).ptr.addr,
28698 .len = (try mod.intValue(Type.usize, array_ty.arrayLen(mod))).toIntern(),
2857128699 } });
2857228700 return sema.addConstant(dest_ty, slice_val.toValue());
2857328701 }
......@@ -28643,7 +28771,7 @@ fn coerceCompatiblePtrs(
2864328771 return sema.addConstant(dest_ty, (try mod.intern_pool.getCoerced(
2864428772 sema.gpa,
2864528773 try val.intern(inst_ty, mod),
28646 dest_ty.ip_index,
28774 dest_ty.toIntern(),
2864728775 )).toValue());
2864828776 }
2864928777 try sema.requireRuntimeBlock(block, inst_src, null);
......@@ -28840,7 +28968,7 @@ fn coerceAnonStructToUnion(
2884028968 return sema.failWithOwnedErrorMsg(msg);
2884128969 }
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;
2884428972 const field_name = mod.intern_pool.stringToSlice(anon_struct.names[0]);
2884528973 const init = try sema.structFieldVal(block, inst_src, inst, field_name, inst_src, inst_ty);
2884628974 return sema.unionInit(block, init, inst_src, union_ty, union_ty_src, field_name, inst_src);
......@@ -28916,23 +29044,20 @@ fn coerceArrayLike(
2891629044 return block.addBitCast(dest_ty, inst);
2891729045 }
2891829046
28919 const element_vals = try sema.arena.alloc(Value, dest_len);
29047 const element_vals = try sema.arena.alloc(InternPool.Index, dest_len);
2892029048 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_len);
2892129049 var runtime_src: ?LazySrcLoc = null;
2892229050
28923 for (element_vals, 0..) |*elem, i| {
28924 const index_ref = try sema.addConstant(
28925 Type.usize,
28926 try mod.intValue(Type.usize, i),
28927 );
29051 for (element_vals, element_refs, 0..) |*val, *ref, i| {
29052 const index_ref = try sema.addConstant(Type.usize, try mod.intValue(Type.usize, i));
2892829053 const src = inst_src; // TODO better source location
2892929054 const elem_src = inst_src; // TODO better source location
2893029055 const elem_ref = try sema.elemValArray(block, src, inst_src, inst, elem_src, index_ref, true);
2893129056 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);
28932 element_refs[i] = coerced;
29057 ref.* = coerced;
2893329058 if (runtime_src == null) {
2893429059 if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| {
28935 elem.* = elem_val;
29060 val.* = try elem_val.intern(dest_elem_ty, mod);
2893629061 } else {
2893729062 runtime_src = elem_src;
2893829063 }
......@@ -28944,10 +29069,10 @@ fn coerceArrayLike(
2894429069 return block.addAggregateInit(dest_ty, element_refs);
2894529070 }
2894629071
28947 return sema.addConstant(
28948 dest_ty,
28949 try Value.Tag.aggregate.create(sema.arena, element_vals),
28950 );
29072 return sema.addConstant(dest_ty, (try mod.intern(.{ .aggregate = .{
29073 .ty = dest_ty.toIntern(),
29074 .storage = .{ .elems = element_vals },
29075 } })).toValue());
2895129076}
2895229077
2895329078/// If the lengths match, coerces element-wise.
......@@ -28978,25 +29103,26 @@ fn coerceTupleToArray(
2897829103 }
2897929104
2898029105 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);
2898229107 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems);
2898329108 const dest_elem_ty = dest_ty.childType(mod);
2898429109
2898529110 var runtime_src: ?LazySrcLoc = null;
28986 for (element_vals, 0..) |*elem, i_usize| {
29111 for (element_vals, element_refs, 0..) |*val, *ref, i_usize| {
2898729112 const i = @intCast(u32, i_usize);
2898829113 if (i_usize == inst_len) {
28989 elem.* = dest_ty.sentinel(mod).?;
28990 element_refs[i] = try sema.addConstant(dest_elem_ty, elem.*);
29114 const sentinel_val = dest_ty.sentinel(mod).?;
29115 val.* = sentinel_val.toIntern();
29116 ref.* = try sema.addConstant(dest_elem_ty, sentinel_val);
2899129117 break;
2899229118 }
2899329119 const elem_src = inst_src; // TODO better source location
2899429120 const elem_ref = try sema.tupleField(block, inst_src, inst, elem_src, i);
2899529121 const coerced = try sema.coerce(block, dest_elem_ty, elem_ref, elem_src);
28996 element_refs[i] = coerced;
29122 ref.* = coerced;
2899729123 if (runtime_src == null) {
2899829124 if (try sema.resolveMaybeUndefVal(coerced)) |elem_val| {
28999 elem.* = elem_val;
29125 val.* = try elem_val.intern(dest_elem_ty, mod);
2900029126 } else {
2900129127 runtime_src = elem_src;
2900229128 }
......@@ -29008,10 +29134,10 @@ fn coerceTupleToArray(
2900829134 return block.addAggregateInit(dest_ty, element_refs);
2900929135 }
2901029136
29011 return sema.addConstant(
29012 dest_ty,
29013 try Value.Tag.aggregate.create(sema.arena, element_vals),
29014 );
29137 return sema.addConstant(dest_ty, (try mod.intern(.{ .aggregate = .{
29138 .ty = dest_ty.toIntern(),
29139 .storage = .{ .elems = element_vals },
29140 } })).toValue());
2901529141}
2901629142
2901729143/// If the lengths match, coerces element-wise.
......@@ -29079,7 +29205,7 @@ fn coerceTupleToStruct(
2907929205 @memset(field_refs, .none);
2908029206
2908129207 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;
2908329209 var runtime_src: ?LazySrcLoc = null;
2908429210 for (0..anon_struct.types.len) |field_index_usize| {
2908529211 const field_i = @intCast(u32, field_index_usize);
......@@ -29105,8 +29231,7 @@ fn coerceTupleToStruct(
2910529231 }
2910629232 if (runtime_src == null) {
2910729233 if (try sema.resolveMaybeUndefVal(coerced)) |field_val| {
29108 assert(field_val.ip_index != .none);
29109 field_vals[field_index] = field_val.ip_index;
29234 field_vals[field_index] = field_val.toIntern();
2911029235 } else {
2911129236 runtime_src = field_src;
2911229237 }
......@@ -29123,7 +29248,7 @@ fn coerceTupleToStruct(
2912329248 const field_name = fields.keys()[i];
2912429249 const field = fields.values()[i];
2912529250 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) {
2912729252 const template = "missing struct field: {s}";
2912829253 const args = .{field_name};
2912929254 if (root_msg) |msg| {
......@@ -29134,8 +29259,7 @@ fn coerceTupleToStruct(
2913429259 continue;
2913529260 }
2913629261 if (runtime_src == null) {
29137 assert(field.default_val.ip_index != .none);
29138 field_vals[i] = field.default_val.ip_index;
29262 field_vals[i] = field.default_val.toIntern();
2913929263 } else {
2914029264 field_ref.* = try sema.addConstant(field.ty, field.default_val);
2914129265 }
......@@ -29152,9 +29276,8 @@ fn coerceTupleToStruct(
2915229276 return block.addAggregateInit(struct_ty, field_refs);
2915329277 }
2915429278
29155 assert(struct_ty.ip_index != .none);
2915629279 const struct_val = try mod.intern(.{ .aggregate = .{
29157 .ty = struct_ty.ip_index,
29280 .ty = struct_ty.toIntern(),
2915829281 .storage = .{ .elems = field_vals },
2915929282 } });
2916029283 errdefer mod.intern_pool.remove(struct_val);
......@@ -29170,13 +29293,13 @@ fn coerceTupleToTuple(
2917029293 inst_src: LazySrcLoc,
2917129294) !Air.Inst.Ref {
2917229295 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;
2917429297 const field_vals = try sema.arena.alloc(InternPool.Index, dest_tuple.types.len);
2917529298 const field_refs = try sema.arena.alloc(Air.Inst.Ref, field_vals.len);
2917629299 @memset(field_refs, .none);
2917729300
2917829301 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;
2918029303 if (src_tuple.types.len > dest_tuple.types.len) return error.NotCoercible;
2918129304
2918229305 var runtime_src: ?LazySrcLoc = null;
......@@ -29209,7 +29332,7 @@ fn coerceTupleToTuple(
2920929332 }
2921029333 if (runtime_src == null) {
2921129334 if (try sema.resolveMaybeUndefVal(coerced)) |field_val| {
29212 field_vals[field_index] = field_val.ip_index;
29335 field_vals[field_index] = field_val.toIntern();
2921329336 } else {
2921429337 runtime_src = field_src;
2921529338 }
......@@ -29269,7 +29392,7 @@ fn coerceTupleToTuple(
2926929392 return sema.addConstant(
2927029393 tuple_ty,
2927129394 (try mod.intern(.{ .aggregate = .{
29272 .ty = tuple_ty.ip_index,
29395 .ty = tuple_ty.toIntern(),
2927329396 .storage = .{ .elems = field_vals },
2927429397 } })).toValue(),
2927529398 );
......@@ -29349,7 +29472,7 @@ fn refValue(sema: *Sema, block: *Block, ty: Type, val: Value) !Value {
2934929472 try sema.maybeQueueFuncBodyAnalysis(decl);
2935029473 try mod.declareDeclDependency(sema.owner_decl_index, decl);
2935129474 const result = try mod.intern(.{ .ptr = .{
29352 .ty = (try mod.singleConstPtrType(ty)).ip_index,
29475 .ty = (try mod.singleConstPtrType(ty)).toIntern(),
2935329476 .addr = .{ .decl = decl },
2935429477 } });
2935529478 return result.toValue();
......@@ -29360,8 +29483,8 @@ fn optRefValue(sema: *Sema, block: *Block, ty: Type, opt_val: ?Value) !Value {
2936029483 const val = opt_val orelse return Value.null;
2936129484 const ptr_val = try sema.refValue(block, ty, val);
2936229485 const result = try mod.intern(.{ .opt = .{
29363 .ty = (try mod.optionalType((try mod.singleConstPtrType(ty)).ip_index)).ip_index,
29364 .val = ptr_val.ip_index,
29486 .ty = (try mod.optionalType((try mod.singleConstPtrType(ty)).toIntern())).toIntern(),
29487 .val = ptr_val.toIntern(),
2936529488 } });
2936629489 return result.toValue();
2936729490}
......@@ -29382,7 +29505,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo
2938229505 const decl = mod.declPtr(decl_index);
2938329506 const decl_tv = try decl.typedValue();
2938429507 const ptr_ty = try mod.ptrType(.{
29385 .elem_type = decl_tv.ty.ip_index,
29508 .elem_type = decl_tv.ty.toIntern(),
2938629509 .alignment = InternPool.Alignment.fromByteUnits(decl.@"align"),
2938729510 .is_const = if (decl.getVariable(mod)) |variable| variable.is_const else false,
2938829511 .address_space = decl.@"addrspace",
......@@ -29391,7 +29514,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo
2939129514 try sema.maybeQueueFuncBodyAnalysis(decl_index);
2939229515 }
2939329516 return sema.addConstant(ptr_ty, (try mod.intern(.{ .ptr = .{
29394 .ty = ptr_ty.ip_index,
29517 .ty = ptr_ty.toIntern(),
2939529518 .addr = .{ .decl = decl_index },
2939629519 } })).toValue());
2939729520}
......@@ -29415,13 +29538,10 @@ fn analyzeRef(
2941529538 const operand_ty = sema.typeOf(operand);
2941629539
2941729540 if (try sema.resolveMaybeUndefVal(operand)) |val| {
29418 switch (val.ip_index) {
29419 .none => {},
29420 else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) {
29421 .extern_func => |extern_func| return sema.analyzeDeclRef(extern_func.decl),
29422 .func => |func| return sema.analyzeDeclRef(sema.mod.funcPtr(func.index).owner_decl),
29423 else => {},
29424 },
29541 switch (sema.mod.intern_pool.indexToKey(val.toIntern())) {
29542 .extern_func => |extern_func| return sema.analyzeDeclRef(extern_func.decl),
29543 .func => |func| return sema.analyzeDeclRef(sema.mod.funcPtr(func.index).owner_decl),
29544 else => {},
2942529545 }
2942629546 var anon_decl = try block.startAnonDecl();
2942729547 defer anon_decl.deinit();
......@@ -29617,9 +29737,9 @@ fn analyzeIsNonErrComptimeOnly(
2961729737 // exception if the error union error set is known to be empty,
2961829738 // we allow the comparison but always make it comptime-known.
2961929739 const set_ty = operand_ty.errorUnionSet(mod);
29620 switch (set_ty.ip_index) {
29740 switch (set_ty.toIntern()) {
2962129741 .anyerror_type => {},
29622 else => switch (mod.intern_pool.indexToKey(set_ty.ip_index)) {
29742 else => switch (mod.intern_pool.indexToKey(set_ty.toIntern())) {
2962329743 .error_set_type => |error_set_type| {
2962429744 if (error_set_type.names.len == 0) return Air.Inst.Ref.bool_true;
2962529745 },
......@@ -30027,7 +30147,7 @@ fn analyzeSlice(
3002730147 return sema.addConstant(return_ty, (try mod.intern_pool.getCoerced(
3002830148 sema.gpa,
3002930149 try new_ptr_val.intern(new_ptr_ty, mod),
30030 return_ty.ip_index,
30150 return_ty.toIntern(),
3003130151 )).toValue());
3003230152 }
3003330153
......@@ -30546,8 +30666,8 @@ fn wrapOptional(
3054630666) !Air.Inst.Ref {
3054730667 if (try sema.resolveMaybeUndefVal(inst)) |val| {
3054830668 return sema.addConstant(dest_ty, (try sema.mod.intern(.{ .opt = .{
30549 .ty = dest_ty.ip_index,
30550 .val = val.ip_index,
30669 .ty = dest_ty.toIntern(),
30670 .val = val.toIntern(),
3055130671 } })).toValue());
3055230672 }
3055330673
......@@ -30567,8 +30687,8 @@ fn wrapErrorUnionPayload(
3056730687 const coerced = try sema.coerceExtra(block, dest_payload_ty, inst, inst_src, .{ .report_err = false });
3056830688 if (try sema.resolveMaybeUndefVal(coerced)) |val| {
3056930689 return sema.addConstant(dest_ty, (try mod.intern(.{ .error_union = .{
30570 .ty = dest_ty.ip_index,
30571 .val = .{ .payload = val.ip_index },
30690 .ty = dest_ty.toIntern(),
30691 .val = .{ .payload = val.toIntern() },
3057230692 } })).toValue());
3057330693 }
3057430694 try sema.requireRuntimeBlock(block, inst_src, null);
......@@ -30588,17 +30708,17 @@ fn wrapErrorUnionSet(
3058830708 const inst_ty = sema.typeOf(inst);
3058930709 const dest_err_set_ty = dest_ty.errorUnionSet(mod);
3059030710 if (try sema.resolveMaybeUndefVal(inst)) |val| {
30591 switch (dest_err_set_ty.ip_index) {
30711 switch (dest_err_set_ty.toIntern()) {
3059230712 .anyerror_type => {},
30593 else => switch (ip.indexToKey(dest_err_set_ty.ip_index)) {
30713 else => switch (ip.indexToKey(dest_err_set_ty.toIntern())) {
3059430714 .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;
3059630716 if (error_set_type.nameIndex(ip, expected_name) != null) break :ok;
3059730717 return sema.failWithErrorSetCodeMissing(block, inst_src, dest_err_set_ty, inst_ty);
3059830718 },
3059930719 .inferred_error_set_type => |ies_index| ok: {
3060030720 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
3060330723 // We carefully do this in an order that avoids unnecessarily
3060430724 // resolving the destination error set type.
......@@ -31252,34 +31372,31 @@ pub fn resolveFnTypes(sema: *Sema, fn_info: InternPool.Key.FuncType) CompileErro
3125231372/// Make it so that calling hash() and eql() on `val` will not assert due
3125331373/// to a type not having its layout resolved.
3125431374fn resolveLazyValue(sema: *Sema, val: Value) CompileError!void {
31255 switch (val.ip_index) {
31256 .none => {},
31257 else => switch (sema.mod.intern_pool.indexToKey(val.ip_index)) {
31258 .int => |int| switch (int.storage) {
31259 .u64, .i64, .big_int => {},
31260 .lazy_align, .lazy_size => |lazy_ty| try sema.resolveTypeLayout(lazy_ty.toType()),
31261 },
31262 .ptr => |ptr| {
31263 switch (ptr.addr) {
31264 .decl, .mut_decl => {},
31265 .int => |int| try sema.resolveLazyValue(int.toValue()),
31266 .eu_payload, .opt_payload => |base| try sema.resolveLazyValue(base.toValue()),
31267 .comptime_field => |comptime_field| try sema.resolveLazyValue(comptime_field.toValue()),
31268 .elem, .field => |base_index| try sema.resolveLazyValue(base_index.base.toValue()),
31269 }
31270 if (ptr.len != .none) try sema.resolveLazyValue(ptr.len.toValue());
31271 },
31272 .aggregate => |aggregate| switch (aggregate.storage) {
31273 .bytes => {},
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 => {},
31375 switch (sema.mod.intern_pool.indexToKey(val.toIntern())) {
31376 .int => |int| switch (int.storage) {
31377 .u64, .i64, .big_int => {},
31378 .lazy_align, .lazy_size => |lazy_ty| try sema.resolveTypeLayout(lazy_ty.toType()),
31379 },
31380 .ptr => |ptr| {
31381 switch (ptr.addr) {
31382 .decl, .mut_decl => {},
31383 .int => |int| try sema.resolveLazyValue(int.toValue()),
31384 .eu_payload, .opt_payload => |base| try sema.resolveLazyValue(base.toValue()),
31385 .comptime_field => |comptime_field| try sema.resolveLazyValue(comptime_field.toValue()),
31386 .elem, .field => |base_index| try sema.resolveLazyValue(base_index.base.toValue()),
31387 }
31388 if (ptr.len != .none) try sema.resolveLazyValue(ptr.len.toValue());
31389 },
31390 .aggregate => |aggregate| switch (aggregate.storage) {
31391 .bytes => {},
31392 .elems => |elems| for (elems) |elem| try sema.resolveLazyValue(elem.toValue()),
31393 .repeated_elem => |elem| try sema.resolveLazyValue(elem.toValue()),
3128231394 },
31395 .un => |un| {
31396 try sema.resolveLazyValue(un.tag.toValue());
31397 try sema.resolveLazyValue(un.val.toValue());
31398 },
31399 else => {},
3128331400 }
3128431401}
3128531402
......@@ -31617,9 +31734,9 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3161731734pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3161831735 const mod = sema.mod;
3161931736
31620 return switch (ty.ip_index) {
31737 return switch (ty.toIntern()) {
3162131738 .empty_struct_type => false,
31622 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
31739 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
3162331740 .int_type => false,
3162431741 .ptr_type => |ptr_type| {
3162531742 const child_ty = ptr_type.elem_type.toType();
......@@ -31776,7 +31893,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {
3177631893 const child_ty = try sema.resolveTypeFields(ty.childType(mod));
3177731894 return sema.resolveTypeFully(child_ty);
3177831895 },
31779 .Struct => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
31896 .Struct => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
3178031897 .struct_type => return sema.resolveStructFully(ty),
3178131898 .anon_struct_type => |tuple| {
3178231899 for (tuple.types) |field_ty| {
......@@ -31869,7 +31986,7 @@ fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void {
3186931986pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {
3187031987 const mod = sema.mod;
3187131988
31872 switch (ty.ip_index) {
31989 switch (ty.toIntern()) {
3187331990 .var_args_param_type => unreachable,
3187431991
3187531992 .none => unreachable,
......@@ -31960,7 +32077,7 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!Type {
3196032077 .call_modifier_type => return sema.getBuiltinType("CallModifier"),
3196132078 .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())) {
3196432081 .struct_type => |struct_type| {
3196532082 const struct_obj = mod.structPtrUnwrap(struct_type.index) orelse return ty;
3196632083 try sema.resolveTypeFieldsStruct(ty, struct_obj);
......@@ -32605,7 +32722,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3260532722 } else {
3260632723 // The provided type is the enum tag type.
3260732724 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())) {
3260932726 .enum_type => |x| x,
3261032727 else => return sema.fail(&block_scope, tag_ty_src, "expected enum tag type, found '{}'", .{union_obj.tag_ty.fmt(mod)}),
3261132728 };
......@@ -32698,7 +32815,7 @@ fn semaUnionFields(mod: *Module, union_obj: *Module.Union) CompileError!void {
3269832815
3269932816 break :blk val;
3270032817 };
32701 enum_field_vals[field_i] = copied_val.ip_index;
32818 enum_field_vals[field_i] = copied_val.toIntern();
3270232819 const gop = enum_field_vals_map.getOrPutAssumeCapacityContext(copied_val, .{
3270332820 .ty = int_tag_ty,
3270432821 .mod = mod,
......@@ -32960,7 +33077,7 @@ fn generateUnionTagTypeSimple(
3296033077 .tag_ty = if (enum_field_names.len == 0)
3296133078 .noreturn_type
3296233079 else
32963 (try mod.smallestUnsignedInt(enum_field_names.len - 1)).ip_index,
33080 (try mod.smallestUnsignedInt(enum_field_names.len - 1)).toIntern(),
3296433081 .names = enum_field_names,
3296533082 .values = &.{},
3296633083 .tag_mode = .auto,
......@@ -33053,9 +33170,9 @@ fn getBuiltinType(sema: *Sema, name: []const u8) CompileError!Type {
3305333170/// TODO assert the return value matches `ty.onePossibleValue`
3305433171pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3305533172 const mod = sema.mod;
33056 return switch (ty.ip_index) {
33173 return switch (ty.toIntern()) {
3305733174 .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())) {
3305933176 .int_type => |int_type| {
3306033177 if (int_type.bits == 0) {
3306133178 return try mod.intValue(ty, 0);
......@@ -33074,13 +33191,13 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3307433191
3307533192 inline .array_type, .vector_type => |seq_type| {
3307633193 if (seq_type.len == 0) return (try mod.intern(.{ .aggregate = .{
33077 .ty = ty.ip_index,
33194 .ty = ty.toIntern(),
3307833195 .storage = .{ .elems = &.{} },
3307933196 } })).toValue();
3308033197 if (try sema.typeHasOnePossibleValue(seq_type.child.toType())) |opv| {
3308133198 return (try mod.intern(.{ .aggregate = .{
33082 .ty = ty.ip_index,
33083 .storage = .{ .repeated_elem = opv.ip_index },
33199 .ty = ty.toIntern(),
33200 .storage = .{ .repeated_elem = opv.toIntern() },
3308433201 } })).toValue();
3308533202 }
3308633203 return null;
......@@ -33169,7 +33286,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3316933286 // This TODO is repeated in the redundant implementation of
3317033287 // one-possible-value in type.zig.
3317133288 const empty = try mod.intern(.{ .aggregate = .{
33172 .ty = ty.ip_index,
33289 .ty = ty.toIntern(),
3317333290 .storage = .{ .elems = &.{} },
3317433291 } });
3317533292 return empty.toValue();
......@@ -33182,7 +33299,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3318233299 // In this case the struct has all comptime-known fields and
3318333300 // therefore has one possible value.
3318433301 return (try mod.intern(.{ .aggregate = .{
33185 .ty = ty.ip_index,
33302 .ty = ty.toIntern(),
3318633303 .storage = .{ .elems = tuple.values },
3318733304 } })).toValue();
3318833305 },
......@@ -33208,9 +33325,9 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3320833325 const val_val = (try sema.typeHasOnePossibleValue(only_field.ty)) orelse
3320933326 return null;
3321033327 const only = try mod.intern(.{ .un = .{
33211 .ty = resolved_ty.ip_index,
33212 .tag = tag_val.ip_index,
33213 .val = val_val.ip_index,
33328 .ty = resolved_ty.toIntern(),
33329 .tag = tag_val.toIntern(),
33330 .val = val_val.toIntern(),
3321433331 } });
3321533332 return only.toValue();
3321633333 },
......@@ -33221,8 +33338,8 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3322133338
3322233339 if (try sema.typeHasOnePossibleValue(enum_type.tag_ty.toType())) |int_opv| {
3322333340 const only = try mod.intern(.{ .enum_tag = .{
33224 .ty = ty.ip_index,
33225 .int = int_opv.ip_index,
33341 .ty = ty.toIntern(),
33342 .int = int_opv.toIntern(),
3322633343 } });
3322733344 return only.toValue();
3322833345 }
......@@ -33234,7 +33351,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3323433351 1 => {
3323533352 if (enum_type.values.len == 0) {
3323633353 const only = try mod.intern(.{ .enum_tag = .{
33237 .ty = ty.ip_index,
33354 .ty = ty.toIntern(),
3323833355 .int = try mod.intern(.{ .int = .{
3323933356 .ty = enum_type.tag_ty,
3324033357 .storage = .{ .u64 = 0 },
......@@ -33285,21 +33402,13 @@ pub fn getTmpAir(sema: Sema) Air {
3328533402}
3328633403
3328733404pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
33288 if (ty.ip_index != .none) {
33289 if (@enumToInt(ty.ip_index) < Air.ref_start_index)
33290 return @intToEnum(Air.Inst.Ref, @enumToInt(ty.ip_index));
33291 try sema.air_instructions.append(sema.gpa, .{
33292 .tag = .interned,
33293 .data = .{ .interned = ty.ip_index },
33294 });
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 }
33405 if (@enumToInt(ty.toIntern()) < Air.ref_start_index)
33406 return @intToEnum(Air.Inst.Ref, @enumToInt(ty.toIntern()));
33407 try sema.air_instructions.append(sema.gpa, .{
33408 .tag = .interned,
33409 .data = .{ .interned = ty.toIntern() },
33410 });
33411 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
3330333412}
3330433413
3330533414fn 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 {
3331333422
3331433423pub fn addConstant(sema: *Sema, ty: Type, val: Value) SemaError!Air.Inst.Ref {
3331533424 const gpa = sema.gpa;
33316 if (val.ip_index != .none and val.ip_index != .null_value) {
33317 if (@enumToInt(val.ip_index) < Air.ref_start_index)
33318 return @intToEnum(Air.Inst.Ref, @enumToInt(val.ip_index));
33425 if (val.ip_index != .none) {
33426 if (@enumToInt(val.toIntern()) < Air.ref_start_index)
33427 return @intToEnum(Air.Inst.Ref, @enumToInt(val.toIntern()));
3331933428 try sema.air_instructions.append(gpa, .{
3332033429 .tag = .interned,
33321 .data = .{ .interned = val.ip_index },
33430 .data = .{ .interned = val.toIntern() },
3332233431 });
3332333432 const result = Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
3332433433 // This assertion can be removed when the `ty` parameter is removed from
......@@ -33417,7 +33526,7 @@ fn analyzeComptimeAlloc(
3341733526
3341833527 try sema.mod.declareDeclDependency(sema.owner_decl_index, decl_index);
3341933528 return sema.addConstant(ptr_type, (try sema.mod.intern(.{ .ptr = .{
33420 .ty = ptr_type.ip_index,
33529 .ty = ptr_type.toIntern(),
3342133530 .addr = .{ .mut_decl = .{
3342233531 .decl = decl_index,
3342333532 .runtime_index = block.runtime_index,
......@@ -33589,7 +33698,7 @@ fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError
3358933698/// This logic must be kept in sync with `Type.isPtrLikeOptional`.
3359033699fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
3359133700 const mod = sema.mod;
33592 return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
33701 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
3359333702 .ptr_type => |ptr_type| switch (ptr_type.size) {
3359433703 .Slice => null,
3359533704 .C => ptr_type.elem_type.toType(),
......@@ -33624,10 +33733,10 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
3362433733/// elsewhere in value.zig
3362533734pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3362633735 const mod = sema.mod;
33627 return switch (ty.ip_index) {
33736 return switch (ty.toIntern()) {
3362833737 .empty_struct_type => false,
3362933738
33630 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
33739 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
3363133740 .int_type => return false,
3363233741 .ptr_type => |ptr_type| {
3363333742 const child_ty = ptr_type.elem_type.toType();
......@@ -33873,7 +33982,7 @@ fn anonStructFieldIndex(
3387333982 field_src: LazySrcLoc,
3387433983) !u32 {
3387533984 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;
3387733986 for (anon_struct.names, 0..) |name, i| {
3387833987 if (mem.eql(u8, mod.intern_pool.stringToSlice(name), field_name)) {
3387933988 return @intCast(u32, i);
......@@ -33891,14 +34000,17 @@ fn queueFullTypeResolution(sema: *Sema, ty: Type) !void {
3389134000fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {
3389234001 const mod = sema.mod;
3389334002 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));
3389534004 const scalar_ty = ty.scalarType(mod);
3389634005 for (result_data, 0..) |*scalar, i| {
3389734006 const lhs_elem = try lhs.elemValue(mod, i);
3389834007 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);
3390034009 }
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();
3390234014 }
3390334015 return sema.intAddScalar(lhs, rhs, ty);
3390434016}
......@@ -33945,14 +34057,17 @@ fn numberAddWrapScalar(
3394534057fn intSub(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {
3394634058 const mod = sema.mod;
3394734059 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));
3394934061 const scalar_ty = ty.scalarType(mod);
3395034062 for (result_data, 0..) |*scalar, i| {
3395134063 const lhs_elem = try lhs.elemValue(sema.mod, i);
3395234064 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);
3395434066 }
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();
3395634071 }
3395734072 return sema.intSubScalar(lhs, rhs, ty);
3395834073}
......@@ -34004,18 +34119,26 @@ fn intSubWithOverflow(
3400434119) !Value.OverflowArithmeticResult {
3400534120 const mod = sema.mod;
3400634121 if (ty.zigTypeTag(mod) == .Vector) {
34007 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
34008 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
34009 for (result_data, 0..) |*scalar, i| {
34122 const vec_len = ty.vectorLen(mod);
34123 const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len);
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| {
3401034127 const lhs_elem = try lhs.elemValue(sema.mod, i);
3401134128 const rhs_elem = try rhs.elemValue(sema.mod, i);
34012 const of_math_result = try sema.intSubWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(mod));
34013 overflowed_data[i] = of_math_result.overflow_bit;
34014 scalar.* = of_math_result.wrapped_result;
34129 const of_math_result = try sema.intSubWithOverflowScalar(lhs_elem, rhs_elem, scalar_ty);
34130 of.* = try of_math_result.overflow_bit.intern(Type.bool, mod);
34131 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
3401534132 }
3401634133 return Value.OverflowArithmeticResult{
34017 .overflow_bit = try Value.Tag.aggregate.create(sema.arena, overflowed_data),
34018 .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data),
34134 .overflow_bit = (try mod.intern(.{ .aggregate = .{
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(),
3401934142 };
3402034143 }
3402134144 return sema.intSubWithOverflowScalar(lhs, rhs, ty);
......@@ -34057,13 +34180,17 @@ fn floatToInt(
3405734180) CompileError!Value {
3405834181 const mod = sema.mod;
3405934182 if (float_ty.zigTypeTag(mod) == .Vector) {
34060 const elem_ty = float_ty.childType(mod);
34061 const result_data = try sema.arena.alloc(Value, float_ty.vectorLen(mod));
34183 const elem_ty = float_ty.scalarType(mod);
34184 const result_data = try sema.arena.alloc(InternPool.Index, float_ty.vectorLen(mod));
34185 const scalar_ty = int_ty.scalarType(mod);
3406234186 for (result_data, 0..) |*scalar, i| {
3406334187 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);
3406534189 }
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();
3406734194 }
3406834195 return sema.floatToIntScalar(block, src, val, float_ty, int_ty);
3406934196}
......@@ -34139,16 +34266,16 @@ fn intFitsInType(
3413934266 vector_index: ?*usize,
3414034267) CompileError!bool {
3414134268 const mod = sema.mod;
34142 if (ty.ip_index == .comptime_int_type) return true;
34269 if (ty.toIntern() == .comptime_int_type) return true;
3414334270 const info = ty.intInfo(mod);
34144 switch (val.ip_index) {
34271 switch (val.toIntern()) {
3414534272 .undef,
3414634273 .zero,
3414734274 .zero_usize,
3414834275 .zero_u8,
3414934276 => return true,
3415034277
34151 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
34278 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
3415234279 .variable, .extern_func, .func, .ptr => {
3415334280 const target = mod.getTarget();
3415434281 const ptr_bits = target.ptrBitWidth();
......@@ -34219,12 +34346,12 @@ fn intInRange(sema: *Sema, tag_ty: Type, int_val: Value, end: usize) !bool {
3421934346/// Asserts the type is an enum.
3422034347fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {
3422134348 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;
3422334350 assert(enum_type.tag_mode != .nonexhaustive);
3422434351 // The `tagValueIndex` function call below relies on the type being the integer tag type.
3422534352 // `getCoerced` assumes the value will fit the new type.
3422634353 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
3422934356 return enum_type.tagValueIndex(&mod.intern_pool, int_coerced) != null;
3423034357}
......@@ -34237,18 +34364,26 @@ fn intAddWithOverflow(
3423734364) !Value.OverflowArithmeticResult {
3423834365 const mod = sema.mod;
3423934366 if (ty.zigTypeTag(mod) == .Vector) {
34240 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
34241 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
34242 for (result_data, 0..) |*scalar, i| {
34367 const vec_len = ty.vectorLen(mod);
34368 const overflowed_data = try sema.arena.alloc(InternPool.Index, vec_len);
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| {
3424334372 const lhs_elem = try lhs.elemValue(sema.mod, i);
3424434373 const rhs_elem = try rhs.elemValue(sema.mod, i);
34245 const of_math_result = try sema.intAddWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(mod));
34246 overflowed_data[i] = of_math_result.overflow_bit;
34247 scalar.* = of_math_result.wrapped_result;
34374 const of_math_result = try sema.intAddWithOverflowScalar(lhs_elem, rhs_elem, scalar_ty);
34375 of.* = try of_math_result.overflow_bit.intern(Type.bool, mod);
34376 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
3424834377 }
3424934378 return Value.OverflowArithmeticResult{
34250 .overflow_bit = try Value.Tag.aggregate.create(sema.arena, overflowed_data),
34251 .wrapped_result = try Value.Tag.aggregate.create(sema.arena, result_data),
34379 .overflow_bit = (try mod.intern(.{ .aggregate = .{
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(),
3425234387 };
3425334388 }
3425434389 return sema.intAddWithOverflowScalar(lhs, rhs, ty);
......@@ -34340,14 +34475,17 @@ fn compareVector(
3434034475) !Value {
3434134476 const mod = sema.mod;
3434234477 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));
3434434479 for (result_data, 0..) |*scalar, i| {
3434534480 const lhs_elem = try lhs.elemValue(sema.mod, i);
3434634481 const rhs_elem = try rhs.elemValue(sema.mod, i);
3434734482 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);
3434934484 }
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();
3435134489}
3435234490
3435334491/// Returns the type of a pointer to an element.
src/TypedValue.zig+20-4
......@@ -103,10 +103,26 @@ pub fn print(
103103 return writer.writeAll(" }");
104104 },
105105 .bytes => return writer.print("\"{}\"", .{std.zig.fmtEscapes(val.castTag(.bytes).?.data)}),
106 .str_lit => {
107 const str_lit = val.castTag(.str_lit).?.data;
108 const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
109 return writer.print("\"{}\"", .{std.zig.fmtEscapes(bytes)});
106 .repeated => {
107 if (level == 0) {
108 return writer.writeAll(".{ ... }");
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(" }");
110126 },
111127 // TODO these should not appear in this function
112128 .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 {
846846 .ptr_elem_ptr => try self.airPtrElemPtr(inst),
847847
848848 .constant => unreachable, // excluded from function bodies
849 .const_ty => unreachable, // excluded from function bodies
850849 .interned => unreachable, // excluded from function bodies
851850 .unreach => self.finishAirBookkeeping(),
852851
......@@ -6169,7 +6168,6 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
61696168 }
61706169 return gop.value_ptr.*;
61716170 },
6172 .const_ty => unreachable,
61736171 else => return self.getResolvedInstValue(inst_index),
61746172 }
61756173}
src/arch/arm/CodeGen.zig-2
......@@ -830,7 +830,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
830830 .ptr_elem_ptr => try self.airPtrElemPtr(inst),
831831
832832 .constant => unreachable, // excluded from function bodies
833 .const_ty => unreachable, // excluded from function bodies
834833 .interned => unreachable, // excluded from function bodies
835834 .unreach => self.finishAirBookkeeping(),
836835
......@@ -6117,7 +6116,6 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
61176116 }
61186117 return gop.value_ptr.*;
61196118 },
6120 .const_ty => unreachable,
61216119 else => return self.getResolvedInstValue(inst_index),
61226120 }
61236121}
src/arch/riscv64/CodeGen.zig-2
......@@ -660,7 +660,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
660660 .ptr_elem_ptr => try self.airPtrElemPtr(inst),
661661
662662 .constant => unreachable, // excluded from function bodies
663 .const_ty => unreachable, // excluded from function bodies
664663 .interned => unreachable, // excluded from function bodies
665664 .unreach => self.finishAirBookkeeping(),
666665
......@@ -2571,7 +2570,6 @@ fn resolveInst(self: *Self, inst: Air.Inst.Ref) InnerError!MCValue {
25712570 }
25722571 return gop.value_ptr.*;
25732572 },
2574 .const_ty => unreachable,
25752573 else => return self.getResolvedInstValue(inst_index),
25762574 }
25772575}
src/arch/sparc64/CodeGen.zig-2
......@@ -680,7 +680,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
680680 .ptr_elem_ptr => try self.airPtrElemPtr(inst),
681681
682682 .constant => unreachable, // excluded from function bodies
683 .const_ty => unreachable, // excluded from function bodies
684683 .interned => unreachable, // excluded from function bodies
685684 .unreach => self.finishAirBookkeeping(),
686685
......@@ -4567,7 +4566,6 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
45674566 }
45684567 return gop.value_ptr.*;
45694568 },
4570 .const_ty => unreachable,
45714569 else => return self.getResolvedInstValue(inst),
45724570 }
45734571 }
src/arch/wasm/CodeGen.zig+5-22
......@@ -1833,7 +1833,6 @@ fn genInst(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
18331833 const air_tags = func.air.instructions.items(.tag);
18341834 return switch (air_tags[inst]) {
18351835 .constant => unreachable,
1836 .const_ty => unreachable,
18371836 .interned => unreachable,
18381837
18391838 .add => func.airBinOp(inst, .add),
......@@ -6903,28 +6902,12 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
69036902 .child = .u8_type,
69046903 .sentinel = .zero_u8,
69056904 });
6906 const string_bytes = &mod.string_literal_bytes;
6907 try string_bytes.ensureUnusedCapacity(mod.gpa, tag_name.len);
6908 const gop = try mod.string_literal_table.getOrPutContextAdapted(mod.gpa, @as([]const u8, tag_name), Module.StringLiteralAdapter{
6909 .bytes = string_bytes,
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);
6905 const name_val = try mod.intern(.{ .aggregate = .{
6906 .ty = name_ty.toIntern(),
6907 .storage = .{ .bytes = tag_name },
6908 } });
69266909 const tag_sym_index = try func.bin_file.lowerUnnamedConst(
6927 .{ .ty = name_ty, .val = name_val },
6910 .{ .ty = name_ty, .val = name_val.toValue() },
69286911 enum_decl_index,
69296912 );
69306913
src/arch/x86_64/CodeGen.zig+1-4
......@@ -1923,7 +1923,6 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
19231923 .ptr_elem_ptr => try self.airPtrElemPtr(inst),
19241924
19251925 .constant => unreachable, // excluded from function bodies
1926 .const_ty => unreachable, // excluded from function bodies
19271926 .interned => unreachable, // excluded from function bodies
19281927 .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 {
20992098/// Asserts there is already capacity to insert into top branch inst_table.
21002099fn processDeath(self: *Self, inst: Air.Inst.Index) void {
21012100 switch (self.air.instructions.items(.tag)[inst]) {
2102 .constant, .const_ty => unreachable,
2101 .constant => unreachable,
21032102 else => self.inst_tracking.getPtr(inst).?.die(self, inst),
21042103 }
21052104}
......@@ -11593,7 +11592,6 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
1159311592 }));
1159411593 break :tracking gop.value_ptr;
1159511594 },
11596 .const_ty => unreachable,
1159711595 else => self.inst_tracking.getPtr(inst).?,
1159811596 }.short;
1159911597 switch (mcv) {
......@@ -11608,7 +11606,6 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
1160811606fn getResolvedInstValue(self: *Self, inst: Air.Inst.Index) *InstTracking {
1160911607 const tracking = switch (self.air.instructions.items(.tag)[inst]) {
1161011608 .constant => &self.const_tracking,
11611 .const_ty => unreachable,
1161211609 else => &self.inst_tracking,
1161311610 }.getPtr(inst).?;
1161411611 return switch (tracking.short) {
src/codegen.zig-144
......@@ -204,150 +204,6 @@ pub fn generateSymbol(
204204 return .ok;
205205 }
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
351207 switch (mod.intern_pool.indexToKey(typed_value.val.ip_index)) {
352208 .int_type,
353209 .ptr_type,
src/codegen/c.zig+1-20
......@@ -870,7 +870,7 @@ pub const DeclGen = struct {
870870 }
871871
872872 // First try specific tag representations for more efficiency.
873 switch (val.ip_index) {
873 switch (val.toIntern()) {
874874 .undef => {
875875 const ai = ty.arrayInfo(mod);
876876 try writer.writeByte('{');
......@@ -893,24 +893,6 @@ pub const DeclGen = struct {
893893 try writer.writeByte('}');
894894 return;
895895 },
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 },
914896 else => {},
915897 }
916898 // Fall back to generic implementation.
......@@ -2909,7 +2891,6 @@ fn genBodyInner(f: *Function, body: []const Air.Inst.Index) error{ AnalysisFail,
29092891 const result_value = switch (air_tags[inst]) {
29102892 // zig fmt: off
29112893 .constant => unreachable, // excluded from function bodies
2912 .const_ty => unreachable, // excluded from function bodies
29132894 .interned => unreachable, // excluded from function bodies
29142895
29152896 .arg => try airArg(f, inst),
src/codegen/llvm.zig+24-302
......@@ -1501,7 +1501,7 @@ pub const Object = struct {
15011501 }
15021502
15031503 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
15061506 const enumerators = try gpa.alloc(*llvm.DIEnumerator, enum_type.names.len);
15071507 defer gpa.free(enumerators);
......@@ -1697,7 +1697,7 @@ pub const Object = struct {
16971697 return ptr_di_ty;
16981698 },
16991699 .Opaque => {
1700 if (ty.ip_index == .anyopaque_type) {
1700 if (ty.toIntern() == .anyopaque_type) {
17011701 const di_ty = dib.createBasicType("anyopaque", 0, DW.ATE.signed);
17021702 gop.value_ptr.* = AnnotatedDITypePtr.initFull(di_ty);
17031703 return di_ty;
......@@ -1981,7 +1981,7 @@ pub const Object = struct {
19811981 break :blk fwd_decl;
19821982 };
19831983
1984 switch (mod.intern_pool.indexToKey(ty.ip_index)) {
1984 switch (mod.intern_pool.indexToKey(ty.toIntern())) {
19851985 .anon_struct_type => |tuple| {
19861986 var di_fields: std.ArrayListUnmanaged(*llvm.DIType) = .{};
19871987 defer di_fields.deinit(gpa);
......@@ -2466,7 +2466,7 @@ pub const DeclGen = struct {
24662466 global.setGlobalConstant(.True);
24672467 break :init_val decl.val;
24682468 };
2469 if (init_val.ip_index != .unreachable_value) {
2469 if (init_val.toIntern() != .unreachable_value) {
24702470 const llvm_init = try dg.lowerValue(.{ .ty = decl.ty, .val = init_val });
24712471 if (global.globalGetValueType() == llvm_init.typeOf()) {
24722472 global.setInitializer(llvm_init);
......@@ -2802,12 +2802,12 @@ pub const DeclGen = struct {
28022802 return dg.context.pointerType(llvm_addrspace);
28032803 },
28042804 .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
28072807 const gop = try dg.object.type_map.getOrPut(gpa, t.toIntern());
28082808 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;
28112811 const name = try mod.opaqueFullyQualifiedName(opaque_type);
28122812 defer gpa.free(name);
28132813
......@@ -2897,7 +2897,7 @@ pub const DeclGen = struct {
28972897 const gop = try dg.object.type_map.getOrPut(gpa, t.toIntern());
28982898 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())) {
29012901 .anon_struct_type => |tuple| {
29022902 const llvm_struct_ty = dg.context.structCreateNamed("");
29032903 gop.value_ptr.* = llvm_struct_ty; // must be done before any recursive calls
......@@ -3199,7 +3199,7 @@ pub const DeclGen = struct {
31993199 const mod = dg.module;
32003200 const target = mod.getTarget();
32013201 var tv = arg_tv;
3202 switch (mod.intern_pool.indexToKey(tv.val.ip_index)) {
3202 switch (mod.intern_pool.indexToKey(tv.val.toIntern())) {
32033203 .runtime_value => |rt| tv.val = rt.val.toValue(),
32043204 else => {},
32053205 }
......@@ -3208,284 +3208,7 @@ pub const DeclGen = struct {
32083208 return llvm_type.getUndef();
32093209 }
32103210
3211 if (tv.val.ip_index == .none) switch (tv.ty.zigTypeTag(mod)) {
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)) {
3211 switch (mod.intern_pool.indexToKey(tv.val.toIntern())) {
34893212 .int_type,
34903213 .ptr_type,
34913214 .array_type,
......@@ -3553,7 +3276,7 @@ pub const DeclGen = struct {
35533276 const llvm_payload_value = try dg.lowerValue(.{
35543277 .ty = payload_type,
35553278 .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() }),
35573280 .payload => |payload| payload,
35583281 }.toValue(),
35593282 });
......@@ -3700,7 +3423,7 @@ pub const DeclGen = struct {
37003423 fields_buf[0] = try dg.lowerValue(.{
37013424 .ty = payload_ty,
37023425 .val = switch (opt.val) {
3703 .none => try mod.intern(.{ .undef = payload_ty.ip_index }),
3426 .none => try mod.intern(.{ .undef = payload_ty.toIntern() }),
37043427 else => |payload| payload,
37053428 }.toValue(),
37063429 });
......@@ -3711,7 +3434,7 @@ pub const DeclGen = struct {
37113434 }
37123435 return dg.context.constStruct(&fields_buf, llvm_field_count, .False);
37133436 },
3714 .aggregate => |aggregate| switch (mod.intern_pool.indexToKey(tv.ty.ip_index)) {
3437 .aggregate => |aggregate| switch (mod.intern_pool.indexToKey(tv.ty.toIntern())) {
37153438 .array_type => switch (aggregate.storage) {
37163439 .bytes => |bytes| return dg.context.constString(
37173440 bytes.ptr,
......@@ -3802,7 +3525,7 @@ pub const DeclGen = struct {
38023525 const llvm_struct_ty = try dg.lowerType(tv.ty);
38033526 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())) {
38063529 .anon_struct_type => |tuple| {
38073530 var llvm_fields: std.ArrayListUnmanaged(*llvm.Value) = .{};
38083531 defer llvm_fields.deinit(gpa);
......@@ -3967,9 +3690,9 @@ pub const DeclGen = struct {
39673690 },
39683691 .un => {
39693692 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()) {
39713694 .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())) {
39733696 .un => |un| .{ .tag = un.tag.toValue(), .val = un.val.toValue() },
39743697 else => unreachable,
39753698 },
......@@ -4107,7 +3830,7 @@ pub const DeclGen = struct {
41073830 fn lowerParentPtr(dg: *DeclGen, ptr_val: Value, byte_aligned: bool) Error!*llvm.Value {
41083831 const mod = dg.module;
41093832 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())) {
41113834 .int => |int| dg.lowerIntAsPtr(int),
41123835 .ptr => |ptr| switch (ptr.addr) {
41133836 .decl => |decl| dg.lowerParentPtrDecl(ptr_val, decl),
......@@ -4799,7 +4522,6 @@ pub const FuncGen = struct {
47994522 .vector_store_elem => try self.airVectorStoreElem(inst),
48004523
48014524 .constant => unreachable,
4802 .const_ty => unreachable,
48034525 .interned => unreachable,
48044526
48054527 .unreach => self.airUnreach(inst),
......@@ -6108,7 +5830,7 @@ pub const FuncGen = struct {
61085830 const struct_llvm_ty = try self.dg.lowerType(struct_ty);
61095831 const field_ptr = self.builder.buildStructGEP(struct_llvm_ty, struct_llvm_val, llvm_field.index, "");
61105832 const field_ptr_ty = try mod.ptrType(.{
6111 .elem_type = llvm_field.ty.ip_index,
5833 .elem_type = llvm_field.ty.toIntern(),
61125834 .alignment = InternPool.Alignment.fromNonzeroByteUnits(llvm_field.alignment),
61135835 });
61145836 if (isByRef(field_ty, mod)) {
......@@ -6984,7 +6706,7 @@ pub const FuncGen = struct {
69846706 const struct_llvm_ty = try self.dg.lowerType(struct_ty);
69856707 const field_ptr = self.builder.buildStructGEP(struct_llvm_ty, self.err_ret_trace.?, llvm_field.index, "");
69866708 const field_ptr_ty = try mod.ptrType(.{
6987 .elem_type = llvm_field.ty.ip_index,
6709 .elem_type = llvm_field.ty.toIntern(),
69886710 .alignment = InternPool.Alignment.fromNonzeroByteUnits(llvm_field.alignment),
69896711 });
69906712 return self.load(field_ptr, field_ptr_ty);
......@@ -8915,7 +8637,7 @@ pub const FuncGen = struct {
89158637
89168638 fn getIsNamedEnumValueFunction(self: *FuncGen, enum_ty: Type) !*llvm.Value {
89178639 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
89208642 // TODO: detect when the type changes and re-emit this function.
89218643 const gop = try self.dg.object.named_enum_map.getOrPut(self.dg.gpa, enum_type.decl);
......@@ -8988,7 +8710,7 @@ pub const FuncGen = struct {
89888710
89898711 fn getEnumTagNameFunction(self: *FuncGen, enum_ty: Type) !*llvm.Value {
89908712 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
89938715 // TODO: detect when the type changes and re-emit this function.
89948716 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 {
1052910251 var offset: u64 = 0;
1053010252 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())) {
1053310255 .anon_struct_type => |tuple| {
1053410256 var llvm_field_index: c_uint = 0;
1053510257 for (tuple.types, tuple.values, 0..) |field_ty, field_val, i| {
......@@ -10927,7 +10649,7 @@ const ParamTypeIterator = struct {
1092710649 .riscv32, .riscv64 => {
1092810650 it.zig_index += 1;
1092910651 it.llvm_index += 1;
10930 if (ty.ip_index == .f16_type) {
10652 if (ty.toIntern() == .f16_type) {
1093110653 return .as_u16;
1093210654 }
1093310655 switch (riscv_c_abi.classifyType(ty, mod)) {
......@@ -11146,7 +10868,7 @@ fn isByRef(ty: Type, mod: *Module) bool {
1114610868 .Struct => {
1114710869 // Packed structs are represented to LLVM as integers.
1114810870 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())) {
1115010872 .anon_struct_type => |tuple| {
1115110873 var count: usize = 0;
1115210874 for (tuple.types, tuple.values) |field_ty, field_val| {
......@@ -11261,7 +10983,7 @@ fn backendSupportsF128(target: std.Target) bool {
1126110983/// LLVM does not support all relevant intrinsics for all targets, so we
1126210984/// may need to manually generate a libc call
1126310985fn intrinsicsAllowed(scalar_ty: Type, target: std.Target) bool {
11264 return switch (scalar_ty.ip_index) {
10986 return switch (scalar_ty.toIntern()) {
1126510987 .f16_type => backendSupportsF16(target),
1126610988 .f80_type => (target.c_type_bit_size(.longdouble) == 80) and backendSupportsF80(target),
1126710989 .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 {
616616 const mod = dg.module;
617617
618618 var val = arg_val;
619 switch (mod.intern_pool.indexToKey(val.ip_index)) {
619 switch (mod.intern_pool.indexToKey(val.toIntern())) {
620620 .runtime_value => |rt| val = rt.val.toValue(),
621621 else => {},
622622 }
......@@ -626,75 +626,7 @@ pub const DeclGen = struct {
626626 return try self.addUndef(size);
627627 }
628628
629 if (val.ip_index == .none) switch (ty.zigTypeTag(mod)) {
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)) {
629 switch (mod.intern_pool.indexToKey(val.toIntern())) {
698630 .int_type,
699631 .ptr_type,
700632 .array_type,
......@@ -1876,7 +1808,6 @@ pub const DeclGen = struct {
18761808 .breakpoint => return,
18771809 .cond_br => return self.airCondBr(inst),
18781810 .constant => unreachable,
1879 .const_ty => unreachable,
18801811 .dbg_stmt => return self.airDbgStmt(inst),
18811812 .loop => return self.airLoop(inst),
18821813 .ret => return self.airRet(inst),
src/print_air.zig+1-2
......@@ -95,7 +95,7 @@ const Writer = struct {
9595 for (w.air.instructions.items(.tag), 0..) |tag, i| {
9696 const inst = @intCast(Air.Inst.Index, i);
9797 switch (tag) {
98 .constant, .const_ty, .interned => {
98 .constant, .interned => {
9999 try w.writeInst(s, inst);
100100 try s.writeByte('\n');
101101 },
......@@ -226,7 +226,6 @@ const Writer = struct {
226226 .save_err_return_trace_index,
227227 => try w.writeNoOp(s, inst),
228228
229 .const_ty,
230229 .alloc,
231230 .ret_ptr,
232231 .err_return_trace,
src/value.zig+540-439
......@@ -37,8 +37,9 @@ pub const Value = struct {
3737
3838 /// A slice of u8 whose memory is managed externally.
3939 bytes,
40 /// Similar to bytes however it stores an index relative to `Module.string_literal_bytes`.
41 str_lit,
40 /// This value is repeated some number of times. The amount of times to repeat
41 /// is stored externally.
42 repeated,
4243 /// An instance of a struct, array, or vector.
4344 /// Each element/field stored as a `Value`.
4445 /// In the case of sentinel-terminated arrays, the sentinel value *is* stored,
......@@ -57,9 +58,9 @@ pub const Value = struct {
5758
5859 pub fn Type(comptime t: Tag) type {
5960 return switch (t) {
60 .bytes => Payload.Bytes,
61 .repeated => Payload.SubValue,
6162
62 .str_lit => Payload.StrLit,
63 .bytes => Payload.Bytes,
6364
6465 .inferred_alloc => Payload.InferredAlloc,
6566 .inferred_alloc_comptime => Payload.InferredAllocComptime,
......@@ -171,7 +172,18 @@ pub const Value = struct {
171172 .legacy = .{ .ptr_otherwise = &new_payload.base },
172173 };
173174 },
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 },
175187 .aggregate => {
176188 const payload = self.castTag(.aggregate).?;
177189 const new_payload = try arena.create(Payload.Aggregate);
......@@ -187,7 +199,6 @@ pub const Value = struct {
187199 .legacy = .{ .ptr_otherwise = &new_payload.base },
188200 };
189201 },
190
191202 .@"union" => {
192203 const tag_and_val = self.castTag(.@"union").?.data;
193204 const new_payload = try arena.create(Payload.Union);
......@@ -203,7 +214,6 @@ pub const Value = struct {
203214 .legacy = .{ .ptr_otherwise = &new_payload.base },
204215 };
205216 },
206
207217 .inferred_alloc => unreachable,
208218 .inferred_alloc_comptime => unreachable,
209219 }
......@@ -237,7 +247,7 @@ pub const Value = struct {
237247 ) !void {
238248 comptime assert(fmt.len == 0);
239249 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()});
241251 return;
242252 }
243253 var val = start_val;
......@@ -249,11 +259,9 @@ pub const Value = struct {
249259 return out_stream.writeAll("(union value)");
250260 },
251261 .bytes => return out_stream.print("\"{}\"", .{std.zig.fmtEscapes(val.castTag(.bytes).?.data)}),
252 .str_lit => {
253 const str_lit = val.castTag(.str_lit).?.data;
254 return out_stream.print("(.str_lit index={d} len={d})", .{
255 str_lit.index, str_lit.len,
256 });
262 .repeated => {
263 try out_stream.writeAll("(repeated) ");
264 val = val.castTag(.repeated).?.data;
257265 },
258266 .inferred_alloc => return out_stream.writeAll("(inferred allocation value)"),
259267 .inferred_alloc_comptime => return out_stream.writeAll("(inferred comptime allocation value)"),
......@@ -274,40 +282,24 @@ pub const Value = struct {
274282 /// Asserts that the value is representable as an array of bytes.
275283 /// Copies the value into a freshly allocated slice of memory, which is owned by the caller.
276284 pub fn toAllocatedBytes(val: Value, ty: Type, allocator: Allocator, mod: *Module) ![]u8 {
277 switch (val.ip_index) {
278 .none => switch (val.tag()) {
279 .bytes => {
280 const bytes = val.castTag(.bytes).?.data;
281 const adjusted_len = bytes.len - @boolToInt(ty.sentinel(mod) != null);
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),
285 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
286 .enum_literal => |enum_literal| allocator.dupe(u8, mod.intern_pool.stringToSlice(enum_literal)),
287 .ptr => |ptr| switch (ptr.len) {
288 .none => unreachable,
289 else => arrayToAllocatedBytes(val, ptr.len.toValue().toUnsignedInt(mod), allocator, mod),
291290 },
292 else => return switch (mod.intern_pool.indexToKey(val.ip_index)) {
293 .enum_literal => |enum_literal| allocator.dupe(u8, mod.intern_pool.stringToSlice(enum_literal)),
294 .ptr => |ptr| switch (ptr.len) {
295 .none => unreachable,
296 else => arrayToAllocatedBytes(val, ptr.len.toValue().toUnsignedInt(mod), allocator, mod),
297 },
298 .aggregate => |aggregate| switch (aggregate.storage) {
299 .bytes => |bytes| try allocator.dupe(u8, bytes),
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 },
291 .aggregate => |aggregate| switch (aggregate.storage) {
292 .bytes => |bytes| try allocator.dupe(u8, bytes),
293 .elems => arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),
294 .repeated_elem => |elem| {
295 const byte = @intCast(u8, elem.toValue().toUnsignedInt(mod));
296 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen(mod)));
297 @memset(result, byte);
298 return result;
307299 },
308 else => unreachable,
309300 },
310 }
301 else => unreachable,
302 };
311303 }
312304
313305 fn arrayToAllocatedBytes(val: Value, len: u64, allocator: Allocator, mod: *Module) ![]u8 {
......@@ -320,13 +312,13 @@ pub const Value = struct {
320312 }
321313
322314 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());
324316 switch (val.tag()) {
325317 .aggregate => {
326318 const old_elems = val.castTag(.aggregate).?.data;
327319 const new_elems = try mod.gpa.alloc(InternPool.Index, old_elems.len);
328320 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());
330322 for (new_elems, old_elems, 0..) |*new_elem, old_elem, field_i|
331323 new_elem.* = try old_elem.intern(switch (ty_key) {
332324 .struct_type => ty.structFieldType(field_i, mod),
......@@ -335,14 +327,14 @@ pub const Value = struct {
335327 else => unreachable,
336328 }, mod);
337329 return mod.intern(.{ .aggregate = .{
338 .ty = ty.ip_index,
330 .ty = ty.toIntern(),
339331 .storage = .{ .elems = new_elems },
340332 } });
341333 },
342334 .@"union" => {
343335 const pl = val.castTag(.@"union").?.data;
344336 return mod.intern(.{ .un = .{
345 .ty = ty.ip_index,
337 .ty = ty.toIntern(),
346338 .tag = try pl.tag.intern(ty.unionTagTypeHypothetical(mod), mod),
347339 .val = try pl.val.intern(ty.unionFieldType(pl.tag, mod), mod),
348340 } });
......@@ -353,13 +345,15 @@ pub const Value = struct {
353345
354346 pub fn unintern(val: Value, arena: Allocator, mod: *Module) Allocator.Error!Value {
355347 if (val.ip_index == .none) return val;
356 switch (mod.intern_pool.indexToKey(val.ip_index)) {
348 switch (mod.intern_pool.indexToKey(val.toIntern())) {
357349 .aggregate => |aggregate| switch (aggregate.storage) {
350 .bytes => |bytes| return Tag.bytes.create(arena, try arena.dupe(u8, bytes)),
358351 .elems => |old_elems| {
359352 const new_elems = try arena.alloc(Value, old_elems.len);
360353 for (new_elems, old_elems) |*new_elem, old_elem| new_elem.* = old_elem.toValue();
361354 return Tag.aggregate.create(arena, new_elems);
362355 },
356 .repeated_elem => |elem| return Tag.repeated.create(arena, elem.toValue()),
363357 },
364358 else => return val,
365359 }
......@@ -372,40 +366,38 @@ pub const Value = struct {
372366
373367 /// Asserts that the value is representable as a type.
374368 pub fn toType(self: Value) Type {
375 return self.ip_index.toType();
369 return self.toIntern().toType();
376370 }
377371
378372 pub fn enumToInt(val: Value, ty: Type, mod: *Module) Allocator.Error!Value {
379373 const ip = &mod.intern_pool;
380 switch (val.ip_index) {
381 else => return switch (ip.indexToKey(ip.typeOf(val.ip_index))) {
382 // Assume it is already an integer and return it directly.
383 .simple_type, .int_type => val,
384 .enum_literal => |enum_literal| {
385 const field_index = ty.enumFieldIndex(ip.stringToSlice(enum_literal), mod).?;
386 return switch (ip.indexToKey(ty.ip_index)) {
387 // Assume it is already an integer and return it directly.
388 .simple_type, .int_type => val,
389 .enum_type => |enum_type| if (enum_type.values.len != 0)
390 enum_type.values[field_index].toValue()
391 else // Field index and integer values are the same.
392 mod.intValue(enum_type.tag_ty.toType(), field_index),
393 else => unreachable,
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,
374 return switch (ip.indexToKey(ip.typeOf(val.toIntern()))) {
375 // Assume it is already an integer and return it directly.
376 .simple_type, .int_type => val,
377 .enum_literal => |enum_literal| {
378 const field_index = ty.enumFieldIndex(ip.stringToSlice(enum_literal), mod).?;
379 return switch (ip.indexToKey(ty.toIntern())) {
380 // Assume it is already an integer and return it directly.
381 .simple_type, .int_type => val,
382 .enum_type => |enum_type| if (enum_type.values.len != 0)
383 enum_type.values[field_index].toValue()
384 else // Field index and integer values are the same.
385 mod.intValue(enum_type.tag_ty.toType(), field_index),
386 else => unreachable,
387 };
402388 },
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 };
404396 }
405397
406398 pub fn tagName(val: Value, mod: *Module) []const u8 {
407399 const ip = &mod.intern_pool;
408 const enum_tag = switch (ip.indexToKey(val.ip_index)) {
400 const enum_tag = switch (ip.indexToKey(val.toIntern())) {
409401 .un => |un| ip.indexToKey(un.tag).enum_tag,
410402 .enum_tag => |x| x,
411403 .enum_literal => |name| return ip.stringToSlice(name),
......@@ -413,7 +405,7 @@ pub const Value = struct {
413405 };
414406 const enum_type = ip.indexToKey(enum_tag.ty).enum_type;
415407 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()).?;
417409 break :field_index @intCast(u32, field_index);
418410 };
419411 const field_name = enum_type.names[field_index];
......@@ -432,12 +424,12 @@ pub const Value = struct {
432424 mod: *Module,
433425 opt_sema: ?*Sema,
434426 ) Module.CompileError!BigIntConst {
435 return switch (val.ip_index) {
427 return switch (val.toIntern()) {
436428 .bool_false => BigIntMutable.init(&space.limbs, 0).toConst(),
437429 .bool_true => BigIntMutable.init(&space.limbs, 1).toConst(),
438430 .undef => unreachable,
439431 .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())) {
441433 .runtime_value => |runtime_value| runtime_value.val.toValue().toBigIntAdvanced(space, mod, opt_sema),
442434 .int => |int| switch (int.storage) {
443435 .u64, .i64, .big_int => int.storage.toBigInt(space),
......@@ -475,18 +467,18 @@ pub const Value = struct {
475467 }
476468
477469 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;
479471 }
480472
481473 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())) {
483475 .extern_func => |extern_func| extern_func,
484476 else => null,
485477 } else null;
486478 }
487479
488480 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())) {
490482 .variable => |variable| variable,
491483 else => null,
492484 } else null;
......@@ -501,11 +493,11 @@ pub const Value = struct {
501493 /// If the value fits in a u64, return it, otherwise null.
502494 /// Asserts not undefined.
503495 pub fn getUnsignedIntAdvanced(val: Value, mod: *Module, opt_sema: ?*Sema) !?u64 {
504 return switch (val.ip_index) {
496 return switch (val.toIntern()) {
505497 .bool_false => 0,
506498 .bool_true => 1,
507499 .undef => unreachable,
508 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
500 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
509501 .int => |int| switch (int.storage) {
510502 .big_int => |big_int| big_int.to(u64) catch null,
511503 .u64 => |x| x,
......@@ -531,11 +523,11 @@ pub const Value = struct {
531523
532524 /// Asserts the value is an integer and it fits in a i64
533525 pub fn toSignedInt(val: Value, mod: *Module) i64 {
534 return switch (val.ip_index) {
526 return switch (val.toIntern()) {
535527 .bool_false => 0,
536528 .bool_true => 1,
537529 .undef => unreachable,
538 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
530 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
539531 .int => |int| switch (int.storage) {
540532 .big_int => |big_int| big_int.to(i64) catch unreachable,
541533 .i64 => |x| x,
......@@ -549,7 +541,7 @@ pub const Value = struct {
549541 }
550542
551543 pub fn toBool(val: Value, _: *const Module) bool {
552 return switch (val.ip_index) {
544 return switch (val.toIntern()) {
553545 .bool_true => true,
554546 .bool_false => false,
555547 else => unreachable,
......@@ -558,7 +550,7 @@ pub const Value = struct {
558550
559551 fn isDeclRef(val: Value, mod: *Module) bool {
560552 var check = val;
561 while (true) switch (mod.intern_pool.indexToKey(check.ip_index)) {
553 while (true) switch (mod.intern_pool.indexToKey(check.toIntern())) {
562554 .ptr => |ptr| switch (ptr.addr) {
563555 .decl, .mut_decl, .comptime_field => return true,
564556 .eu_payload, .opt_payload => |index| check = index.toValue(),
......@@ -644,7 +636,7 @@ pub const Value = struct {
644636 .ErrorSet => {
645637 // TODO revisit this when we have the concept of the error tag type
646638 const Int = u16;
647 const name = switch (mod.intern_pool.indexToKey(val.ip_index)) {
639 const name = switch (mod.intern_pool.indexToKey(val.toIntern())) {
648640 .err => |err| err.name,
649641 .error_union => |error_union| error_union.val.err_name,
650642 else => unreachable,
......@@ -718,7 +710,7 @@ pub const Value = struct {
718710
719711 if (abi_size == 0) return;
720712 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());
722714 const int: u64 = switch (ip_key.int.storage) {
723715 .u64 => |x| x,
724716 .i64 => |x| @bitCast(u64, x),
......@@ -847,7 +839,7 @@ pub const Value = struct {
847839 }
848840 },
849841 .Float => return (try mod.intern(.{ .float = .{
850 .ty = ty.ip_index,
842 .ty = ty.toIntern(),
851843 .storage = switch (ty.floatBits(target)) {
852844 16 => .{ .f16 = @bitCast(f16, std.mem.readInt(u16, buffer[0..2], endian)) },
853845 32 => .{ .f32 = @bitCast(f32, std.mem.readInt(u32, buffer[0..4], endian)) },
......@@ -860,13 +852,16 @@ pub const Value = struct {
860852 .Array => {
861853 const elem_ty = ty.childType(mod);
862854 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)));
864856 var offset: usize = 0;
865857 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);
867859 offset += @intCast(usize, elem_size);
868860 }
869 return Tag.aggregate.create(arena, elems);
861 return (try mod.intern(.{ .aggregate = .{
862 .ty = ty.toIntern(),
863 .storage = .{ .elems = elems },
864 } })).toValue();
870865 },
871866 .Vector => {
872867 // We use byte_count instead of abi_size here, so that any padding bytes
......@@ -878,13 +873,16 @@ pub const Value = struct {
878873 .Auto => unreachable, // Sema is supposed to have emitted a compile error already
879874 .Extern => {
880875 const fields = ty.structFields(mod).values();
881 const field_vals = try arena.alloc(Value, fields.len);
882 for (fields, 0..) |field, i| {
876 const field_vals = try arena.alloc(InternPool.Index, fields.len);
877 for (field_vals, fields, 0..) |*field_val, field, i| {
883878 const off = @intCast(usize, ty.structFieldOffset(i, mod));
884 const sz = @intCast(usize, ty.structFieldType(i, mod).abiSize(mod));
885 field_vals[i] = try readFromMemory(field.ty, mod, buffer[off..(off + sz)], arena);
879 const sz = @intCast(usize, field.ty.abiSize(mod));
880 field_val.* = try (try readFromMemory(field.ty, mod, buffer[off..(off + sz)], arena)).intern(field.ty, mod);
886881 }
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();
888886 },
889887 .Packed => {
890888 const byte_count = (@intCast(usize, ty.bitSize(mod)) + 7) / 8;
......@@ -897,7 +895,7 @@ pub const Value = struct {
897895 const int = std.mem.readInt(Int, buffer[0..@sizeOf(Int)], endian);
898896 const name = mod.error_name_list.items[@intCast(usize, int)];
899897 return (try mod.intern(.{ .err = .{
900 .ty = ty.ip_index,
898 .ty = ty.toIntern(),
901899 .name = mod.intern_pool.getString(name).unwrap().?,
902900 } })).toValue();
903901 },
......@@ -961,7 +959,7 @@ pub const Value = struct {
961959 }
962960 },
963961 .Float => return (try mod.intern(.{ .float = .{
964 .ty = ty.ip_index,
962 .ty = ty.toIntern(),
965963 .storage = switch (ty.floatBits(target)) {
966964 16 => .{ .f16 = @bitCast(f16, std.mem.readPackedInt(u16, buffer, bit_offset, endian)) },
967965 32 => .{ .f32 = @bitCast(f32, std.mem.readPackedInt(u32, buffer, bit_offset, endian)) },
......@@ -973,17 +971,20 @@ pub const Value = struct {
973971 } })).toValue(),
974972 .Vector => {
975973 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
978976 var bits: u16 = 0;
979977 const elem_bit_size = @intCast(u16, elem_ty.bitSize(mod));
980978 for (elems, 0..) |_, i| {
981979 // On big-endian systems, LLVM reverses the element order of vectors by default
982980 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);
984982 bits += elem_bit_size;
985983 }
986 return Tag.aggregate.create(arena, elems);
984 return (try mod.intern(.{ .aggregate = .{
985 .ty = ty.toIntern(),
986 .storage = .{ .elems = elems },
987 } })).toValue();
987988 },
988989 .Struct => switch (ty.containerLayout(mod)) {
989990 .Auto => unreachable, // Sema is supposed to have emitted a compile error already
......@@ -991,13 +992,16 @@ pub const Value = struct {
991992 .Packed => {
992993 var bits: u16 = 0;
993994 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);
995996 for (fields, 0..) |field, i| {
996997 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);
998999 bits += field_bits;
9991000 }
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();
10011005 },
10021006 },
10031007 .Pointer => {
......@@ -1015,7 +1019,7 @@ pub const Value = struct {
10151019
10161020 /// Asserts that the value is a float or an integer.
10171021 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())) {
10191023 .int => |int| switch (int.storage) {
10201024 .big_int => |big_int| @floatCast(T, bigIntToFloat(big_int.limbs, big_int.positive)),
10211025 inline .u64, .i64 => |x| {
......@@ -1119,7 +1123,7 @@ pub const Value = struct {
11191123 pub fn floatCast(self: Value, dest_ty: Type, mod: *Module) !Value {
11201124 const target = mod.getTarget();
11211125 return (try mod.intern(.{ .float = .{
1122 .ty = dest_ty.ip_index,
1126 .ty = dest_ty.toIntern(),
11231127 .storage = switch (dest_ty.floatBits(target)) {
11241128 16 => .{ .f16 = self.toFloat(f16, mod) },
11251129 32 => .{ .f32 = self.toFloat(f32, mod) },
......@@ -1133,7 +1137,7 @@ pub const Value = struct {
11331137
11341138 /// Asserts the value is a float
11351139 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())) {
11371141 .float => |float| switch (float.storage) {
11381142 inline else => |x| @rem(x, 1) != 0,
11391143 },
......@@ -1150,10 +1154,10 @@ pub const Value = struct {
11501154 mod: *Module,
11511155 opt_sema: ?*Sema,
11521156 ) Module.CompileError!std.math.Order {
1153 return switch (lhs.ip_index) {
1157 return switch (lhs.toIntern()) {
11541158 .bool_false => .eq,
11551159 .bool_true => .gt,
1156 else => switch (mod.intern_pool.indexToKey(lhs.ip_index)) {
1160 else => switch (mod.intern_pool.indexToKey(lhs.toIntern())) {
11571161 .ptr => |ptr| switch (ptr.addr) {
11581162 .decl, .mut_decl, .comptime_field => .gt,
11591163 .int => |int| int.toValue().orderAgainstZeroAdvanced(mod, opt_sema),
......@@ -1212,8 +1216,8 @@ pub const Value = struct {
12121216 const lhs_tag = lhs.tag();
12131217 const rhs_tag = rhs.tag();
12141218 if (lhs_tag == rhs_tag) {
1215 const lhs_storage = mod.intern_pool.indexToKey(lhs.ip_index).float.storage;
1216 const rhs_storage = mod.intern_pool.indexToKey(rhs.ip_index).float.storage;
1219 const lhs_storage = mod.intern_pool.indexToKey(lhs.toIntern()).float.storage;
1220 const rhs_storage = mod.intern_pool.indexToKey(rhs.toIntern()).float.storage;
12171221 const lhs128: f128 = switch (lhs_storage) {
12181222 inline else => |x| x,
12191223 };
......@@ -1336,46 +1340,20 @@ pub const Value = struct {
13361340 }
13371341 }
13381342
1339 switch (lhs.ip_index) {
1340 .none => switch (lhs.tag()) {
1341 .aggregate => {
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 => {},
1343 switch (mod.intern_pool.indexToKey(lhs.toIntern())) {
1344 .float => |float| switch (float.storage) {
1345 inline else => |x| if (std.math.isNan(x)) return op == .neq,
13631346 },
1364 else => switch (mod.intern_pool.indexToKey(lhs.ip_index)) {
1365 .float => |float| switch (float.storage) {
1366 inline else => |x| if (std.math.isNan(x)) return op == .neq,
1367 },
1368 .aggregate => |aggregate| return switch (aggregate.storage) {
1369 .bytes => |bytes| for (bytes) |byte| {
1370 if (!std.math.order(byte, 0).compare(op)) break false;
1371 } else true,
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 => {},
1347 .aggregate => |aggregate| return switch (aggregate.storage) {
1348 .bytes => |bytes| for (bytes) |byte| {
1349 if (!std.math.order(byte, 0).compare(op)) break false;
1350 } else true,
1351 .elems => |elems| for (elems) |elem| {
1352 if (!try elem.toValue().compareAllWithZeroAdvancedExtra(op, mod, opt_sema)) break false;
1353 } else true,
1354 .repeated_elem => |elem| elem.toValue().compareAllWithZeroAdvancedExtra(op, mod, opt_sema),
13781355 },
1356 else => {},
13791357 }
13801358 return (try orderAgainstZeroAdvanced(lhs, mod, opt_sema)).compare(op);
13811359 }
......@@ -1412,7 +1390,7 @@ pub const Value = struct {
14121390 const b_field_vals = b.castTag(.aggregate).?.data;
14131391 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())) {
14161394 .anon_struct_type => |anon_struct| {
14171395 assert(anon_struct.types.len == a_field_vals.len);
14181396 for (anon_struct.types, 0..) |field_ty, i| {
......@@ -1577,7 +1555,7 @@ pub const Value = struct {
15771555 // The InternPool data structure hashes based on Key to make interned objects
15781556 // unique. An Index can be treated simply as u32 value for the
15791557 // purpose of Type/Value hashing and equality.
1580 std.hash.autoHash(hasher, val.ip_index);
1558 std.hash.autoHash(hasher, val.toIntern());
15811559 return;
15821560 }
15831561 const zig_ty_tag = ty.zigTypeTag(mod);
......@@ -1663,7 +1641,7 @@ pub const Value = struct {
16631641 // The InternPool data structure hashes based on Key to make interned objects
16641642 // unique. An Index can be treated simply as u32 value for the
16651643 // purpose of Type/Value hashing and equality.
1666 std.hash.autoHash(hasher, val.ip_index);
1644 std.hash.autoHash(hasher, val.toIntern());
16671645 return;
16681646 }
16691647
......@@ -1703,7 +1681,7 @@ pub const Value = struct {
17031681 },
17041682 .Union => {
17051683 hasher.update(val.tagName(mod));
1706 switch (mod.intern_pool.indexToKey(val.ip_index)) {
1684 switch (mod.intern_pool.indexToKey(val.toIntern())) {
17071685 .un => |un| {
17081686 const active_field_ty = ty.unionFieldType(un.tag.toValue(), mod);
17091687 un.val.toValue().hashUncoerced(active_field_ty, hasher, mod);
......@@ -1746,7 +1724,7 @@ pub const Value = struct {
17461724 };
17471725
17481726 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())) {
17501728 .ptr => |ptr| switch (ptr.addr) {
17511729 .mut_decl, .comptime_field => true,
17521730 .eu_payload, .opt_payload => |base_ptr| base_ptr.toValue().isComptimeMutablePtr(mod),
......@@ -1758,8 +1736,8 @@ pub const Value = struct {
17581736 }
17591737
17601738 pub fn canMutateComptimeVarState(val: Value, mod: *Module) bool {
1761 return val.isComptimeMutablePtr(mod) or switch (val.ip_index) {
1762 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
1739 return val.isComptimeMutablePtr(mod) or switch (val.toIntern()) {
1740 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
17631741 .error_union => |error_union| switch (error_union.val) {
17641742 .err_name => false,
17651743 .payload => |payload| payload.toValue().canMutateComptimeVarState(mod),
......@@ -1785,7 +1763,7 @@ pub const Value = struct {
17851763 /// to a decl, or if it points to some part of a decl (like field_ptr or element_ptr),
17861764 /// this function returns null.
17871765 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())) {
17891767 .variable => |variable| variable.decl,
17901768 .extern_func => |extern_func| extern_func.decl,
17911769 .func => |func| mod.funcPtr(func.index).owner_decl,
......@@ -1811,35 +1789,19 @@ pub const Value = struct {
18111789 pub const slice_len_index = 1;
18121790
18131791 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();
18151793 }
18161794
18171795 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);
18191797 }
18201798
18211799 /// Asserts the value is a single-item pointer to an array, or an array,
18221800 /// or an unknown-length pointer, and returns the element value at the index.
18231801 pub fn elemValue(val: Value, mod: *Module, index: usize) Allocator.Error!Value {
1824 switch (val.ip_index) {
1802 switch (val.toIntern()) {
18251803 .undef => return Value.undef,
1826 .none => switch (val.tag()) {
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)) {
1804 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {
18431805 .ptr => |ptr| switch (ptr.addr) {
18441806 .decl => |decl| mod.declPtr(decl).val.elemValue(mod, index),
18451807 .mut_decl => |mut_decl| mod.declPtr(mut_decl.decl).val.elemValue(mod, index),
......@@ -1871,26 +1833,26 @@ pub const Value = struct {
18711833 }
18721834
18731835 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())) {
18751837 .int => |int| int.storage == .lazy_align,
18761838 else => false,
18771839 };
18781840 }
18791841
18801842 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())) {
18821844 .int => |int| int.storage == .lazy_size,
18831845 else => false,
18841846 };
18851847 }
18861848
18871849 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;
18891851 }
18901852
18911853 /// Returns true if a Value is backed by a variable
18921854 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())) {
18941856 .variable => true,
18951857 .ptr => |ptr| switch (ptr.addr) {
18961858 .decl => |decl_index| {
......@@ -1913,7 +1875,7 @@ pub const Value = struct {
19131875 }
19141876
19151877 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())) {
19171879 .variable => |variable| variable.is_threadlocal,
19181880 .ptr => |ptr| switch (ptr.addr) {
19191881 .decl => |decl_index| {
......@@ -1943,55 +1905,30 @@ pub const Value = struct {
19431905 start: usize,
19441906 end: usize,
19451907 ) error{OutOfMemory}!Value {
1946 return switch (val.ip_index) {
1947 .none => switch (val.tag()) {
1948 .bytes => Tag.bytes.create(arena, val.castTag(.bytes).?.data[start..end]),
1949 .str_lit => {
1950 const str_lit = val.castTag(.str_lit).?.data;
1951 return Tag.str_lit.create(arena, .{
1952 .index = @intCast(u32, str_lit.index + start),
1953 .len = @intCast(u32, end - start),
1954 });
1955 },
1908 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1909 .ptr => |ptr| switch (ptr.addr) {
1910 .decl => |decl| try mod.declPtr(decl).val.sliceArray(mod, arena, start, end),
1911 .mut_decl => |mut_decl| try mod.declPtr(mut_decl.decl).val.sliceArray(mod, arena, start, end),
1912 .comptime_field => |comptime_field| try comptime_field.toValue().sliceArray(mod, arena, start, end),
1913 .elem => |elem| try elem.base.toValue().sliceArray(mod, arena, start + elem.index, end + elem.index),
19561914 else => unreachable,
19571915 },
1958 else => switch (mod.intern_pool.indexToKey(val.ip_index)) {
1959 .ptr => |ptr| switch (ptr.addr) {
1960 .decl => |decl| try mod.declPtr(decl).val.sliceArray(mod, arena, start, end),
1961 .mut_decl => |mut_decl| try mod.declPtr(mut_decl.decl).val.sliceArray(mod, arena, start, end),
1962 .comptime_field => |comptime_field| try comptime_field.toValue().sliceArray(mod, arena, start, end),
1963 .elem => |elem| try elem.base.toValue().sliceArray(mod, arena, start + elem.index, end + elem.index),
1964 else => unreachable,
1916 .aggregate => |aggregate| (try mod.intern(.{ .aggregate = .{
1917 .ty = mod.intern_pool.typeOf(val.toIntern()),
1918 .storage = switch (aggregate.storage) {
1919 .bytes => |bytes| .{ .bytes = bytes[start..end] },
1920 .elems => |elems| .{ .elems = elems[start..end] },
1921 .repeated_elem => |elem| .{ .repeated_elem = elem },
19651922 },
1966 .aggregate => |aggregate| (try mod.intern(.{ .aggregate = .{
1967 .ty = mod.intern_pool.typeOf(val.ip_index),
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 },
1923 } })).toValue(),
1924 else => unreachable,
19761925 };
19771926 }
19781927
19791928 pub fn fieldValue(val: Value, mod: *Module, index: usize) !Value {
1980 switch (val.ip_index) {
1929 switch (val.toIntern()) {
19811930 .undef => return Value.undef,
1982 .none => switch (val.tag()) {
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)) {
1931 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {
19951932 .aggregate => |aggregate| switch (aggregate.storage) {
19961933 .bytes => |bytes| try mod.intern(.{ .int = .{
19971934 .ty = .u8_type,
......@@ -2000,6 +1937,8 @@ pub const Value = struct {
20001937 .elems => |elems| elems[index],
20011938 .repeated_elem => |elem| elem,
20021939 }.toValue(),
1940 // TODO assert the tag is correct
1941 .un => |un| un.val.toValue(),
20031942 else => unreachable,
20041943 },
20051944 }
......@@ -2007,7 +1946,7 @@ pub const Value = struct {
20071946
20081947 pub fn unionTag(val: Value, mod: *Module) Value {
20091948 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())) {
20111950 .undef, .enum_tag => val,
20121951 .un => |un| un.tag.toValue(),
20131952 else => unreachable,
......@@ -2022,12 +1961,12 @@ pub const Value = struct {
20221961 mod: *Module,
20231962 ) Allocator.Error!Value {
20241963 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())) {
20261965 .ptr => |ptr| ptr: {
20271966 switch (ptr.addr) {
20281967 .elem => |elem| if (mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).eql(elem_ty, mod))
20291968 return (try mod.intern(.{ .ptr = .{
2030 .ty = ty.ip_index,
1969 .ty = ty.toIntern(),
20311970 .addr = .{ .elem = .{
20321971 .base = elem.base,
20331972 .index = elem.index + index,
......@@ -2043,9 +1982,9 @@ pub const Value = struct {
20431982 else => val,
20441983 };
20451984 return (try mod.intern(.{ .ptr = .{
2046 .ty = ty.ip_index,
1985 .ty = ty.toIntern(),
20471986 .addr = .{ .elem = .{
2048 .base = ptr_val.ip_index,
1987 .base = ptr_val.toIntern(),
20491988 .index = index,
20501989 } },
20511990 } })).toValue();
......@@ -2053,7 +1992,7 @@ pub const Value = struct {
20531992
20541993 pub fn isUndef(val: Value, mod: *Module) bool {
20551994 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())) {
20571996 .undef => true,
20581997 .simple_value => |v| v == .undefined,
20591998 else => false,
......@@ -2070,15 +2009,9 @@ pub const Value = struct {
20702009 /// Returns true if any value contained in `self` is undefined.
20712010 pub fn anyUndef(val: Value, mod: *Module) !bool {
20722011 if (val.ip_index == .none) return false;
2073 return switch (val.ip_index) {
2012 return switch (val.toIntern()) {
20742013 .undef => true,
2075 .none => switch (val.tag()) {
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)) {
2014 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
20822015 .undef => true,
20832016 .simple_value => |v| v == .undefined,
20842017 .ptr => |ptr| switch (ptr.len) {
......@@ -2098,13 +2031,13 @@ pub const Value = struct {
20982031 /// Asserts the value is not undefined and not unreachable.
20992032 /// Integer value 0 is considered null because of C pointers.
21002033 pub fn isNull(val: Value, mod: *Module) bool {
2101 return switch (val.ip_index) {
2034 return switch (val.toIntern()) {
21022035 .undef => unreachable,
21032036 .unreachable_value => unreachable,
21042037
21052038 .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())) {
21082041 .int => {
21092042 var buf: BigIntSpace = undefined;
21102043 return val.toBigInt(&buf, mod).eqZero();
......@@ -2120,7 +2053,7 @@ pub const Value = struct {
21202053 /// something is an error or not because it works without having to figure out the
21212054 /// string.
21222055 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())) {
21242057 .err => |err| err.name.toOptional(),
21252058 .error_union => |error_union| switch (error_union.val) {
21262059 .err_name => |err_name| err_name.toOptional(),
......@@ -2133,12 +2066,12 @@ pub const Value = struct {
21332066 /// Assumes the type is an error union. Returns true if and only if the value is
21342067 /// the error union payload, not an error.
21352068 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;
21372070 }
21382071
21392072 /// Value of the optional, null if optional has no payload.
21402073 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) {
21422075 .none => null,
21432076 else => |index| index.toValue(),
21442077 };
......@@ -2146,14 +2079,9 @@ pub const Value = struct {
21462079
21472080 /// Valid for all types. Asserts the value is not undefined.
21482081 pub fn isFloat(self: Value, mod: *const Module) bool {
2149 return switch (self.ip_index) {
2082 return switch (self.toIntern()) {
21502083 .undef => unreachable,
2151 .none => switch (self.tag()) {
2152 .inferred_alloc => unreachable,
2153 .inferred_alloc_comptime => unreachable,
2154 else => false,
2155 },
2156 else => switch (mod.intern_pool.indexToKey(self.ip_index)) {
2084 else => switch (mod.intern_pool.indexToKey(self.toIntern())) {
21572085 .float => true,
21582086 else => false,
21592087 },
......@@ -2169,21 +2097,24 @@ pub const Value = struct {
21692097
21702098 pub fn intToFloatAdvanced(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, mod: *Module, opt_sema: ?*Sema) !Value {
21712099 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));
21732101 const scalar_ty = float_ty.scalarType(mod);
21742102 for (result_data, 0..) |*scalar, i| {
21752103 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);
21772105 }
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();
21792110 }
21802111 return intToFloatScalar(val, float_ty, mod, opt_sema);
21812112 }
21822113
21832114 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()) {
21852116 .undef => val,
2186 else => return switch (mod.intern_pool.indexToKey(val.ip_index)) {
2117 else => return switch (mod.intern_pool.indexToKey(val.toIntern())) {
21872118 .int => |int| switch (int.storage) {
21882119 .big_int => |big_int| {
21892120 const float = bigIntToFloat(big_int.limbs, big_int.positive);
......@@ -2217,7 +2148,7 @@ pub const Value = struct {
22172148 else => unreachable,
22182149 };
22192150 return (try mod.intern(.{ .float = .{
2220 .ty = dest_ty.ip_index,
2151 .ty = dest_ty.toIntern(),
22212152 .storage = storage,
22222153 } })).toValue();
22232154 }
......@@ -2245,14 +2176,17 @@ pub const Value = struct {
22452176 mod: *Module,
22462177 ) !Value {
22472178 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));
22492180 const scalar_ty = ty.scalarType(mod);
22502181 for (result_data, 0..) |*scalar, i| {
22512182 const lhs_elem = try lhs.elemValue(mod, i);
22522183 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);
22542185 }
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();
22562190 }
22572191 return intAddSatScalar(lhs, rhs, ty, arena, mod);
22582192 }
......@@ -2292,14 +2226,17 @@ pub const Value = struct {
22922226 mod: *Module,
22932227 ) !Value {
22942228 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));
22962230 const scalar_ty = ty.scalarType(mod);
22972231 for (result_data, 0..) |*scalar, i| {
22982232 const lhs_elem = try lhs.elemValue(mod, i);
22992233 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);
23012235 }
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();
23032240 }
23042241 return intSubSatScalar(lhs, rhs, ty, arena, mod);
23052242 }
......@@ -2338,19 +2275,26 @@ pub const Value = struct {
23382275 mod: *Module,
23392276 ) !OverflowArithmeticResult {
23402277 if (ty.zigTypeTag(mod) == .Vector) {
2341 const overflowed_data = try arena.alloc(Value, ty.vectorLen(mod));
2342 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
2278 const vec_len = 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);
23432281 const scalar_ty = ty.scalarType(mod);
2344 for (result_data, 0..) |*scalar, i| {
2282 for (overflowed_data, result_data, 0..) |*of, *scalar, i| {
23452283 const lhs_elem = try lhs.elemValue(mod, i);
23462284 const rhs_elem = try rhs.elemValue(mod, i);
23472285 const of_math_result = try intMulWithOverflowScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod);
2348 overflowed_data[i] = of_math_result.overflow_bit;
2349 scalar.* = of_math_result.wrapped_result;
2286 of.* = try of_math_result.overflow_bit.intern(Type.bool, mod);
2287 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
23502288 }
23512289 return OverflowArithmeticResult{
2352 .overflow_bit = try Value.Tag.aggregate.create(arena, overflowed_data),
2353 .wrapped_result = try Value.Tag.aggregate.create(arena, result_data),
2290 .overflow_bit = (try mod.intern(.{ .aggregate = .{
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(),
23542298 };
23552299 }
23562300 return intMulWithOverflowScalar(lhs, rhs, ty, arena, mod);
......@@ -2400,13 +2344,17 @@ pub const Value = struct {
24002344 mod: *Module,
24012345 ) !Value {
24022346 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);
24042349 for (result_data, 0..) |*scalar, i| {
24052350 const lhs_elem = try lhs.elemValue(mod, i);
24062351 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);
24082353 }
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();
24102358 }
24112359 return numberMulWrapScalar(lhs, rhs, ty, arena, mod);
24122360 }
......@@ -2442,13 +2390,17 @@ pub const Value = struct {
24422390 mod: *Module,
24432391 ) !Value {
24442392 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);
24462395 for (result_data, 0..) |*scalar, i| {
24472396 const lhs_elem = try lhs.elemValue(mod, i);
24482397 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);
24502399 }
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();
24522404 }
24532405 return intMulSatScalar(lhs, rhs, ty, arena, mod);
24542406 }
......@@ -2515,12 +2467,16 @@ pub const Value = struct {
25152467 /// operands must be (vectors of) integers; handles undefined scalars.
25162468 pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
25172469 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);
25192472 for (result_data, 0..) |*scalar, i| {
25202473 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);
25222475 }
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();
25242480 }
25252481 return bitwiseNotScalar(val, ty, arena, mod);
25262482 }
......@@ -2552,13 +2508,17 @@ pub const Value = struct {
25522508 /// operands must be (vectors of) integers; handles undefined scalars.
25532509 pub fn bitwiseAnd(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
25542510 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);
25562513 for (result_data, 0..) |*scalar, i| {
25572514 const lhs_elem = try lhs.elemValue(mod, i);
25582515 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);
25602517 }
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();
25622522 }
25632523 return bitwiseAndScalar(lhs, rhs, ty, allocator, mod);
25642524 }
......@@ -2586,13 +2546,17 @@ pub const Value = struct {
25862546 /// operands must be (vectors of) integers; handles undefined scalars.
25872547 pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
25882548 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);
25902551 for (result_data, 0..) |*scalar, i| {
25912552 const lhs_elem = try lhs.elemValue(mod, i);
25922553 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);
25942555 }
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();
25962560 }
25972561 return bitwiseNandScalar(lhs, rhs, ty, arena, mod);
25982562 }
......@@ -2609,13 +2573,17 @@ pub const Value = struct {
26092573 /// operands must be (vectors of) integers; handles undefined scalars.
26102574 pub fn bitwiseOr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
26112575 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);
26132578 for (result_data, 0..) |*scalar, i| {
26142579 const lhs_elem = try lhs.elemValue(mod, i);
26152580 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);
26172582 }
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();
26192587 }
26202588 return bitwiseOrScalar(lhs, rhs, ty, allocator, mod);
26212589 }
......@@ -2642,14 +2610,17 @@ pub const Value = struct {
26422610 /// operands must be (vectors of) integers; handles undefined scalars.
26432611 pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
26442612 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));
26462614 const scalar_ty = ty.scalarType(mod);
26472615 for (result_data, 0..) |*scalar, i| {
26482616 const lhs_elem = try lhs.elemValue(mod, i);
26492617 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);
26512619 }
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();
26532624 }
26542625 return bitwiseXorScalar(lhs, rhs, ty, allocator, mod);
26552626 }
......@@ -2676,14 +2647,17 @@ pub const Value = struct {
26762647
26772648 pub fn intDiv(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
26782649 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));
26802651 const scalar_ty = ty.scalarType(mod);
26812652 for (result_data, 0..) |*scalar, i| {
26822653 const lhs_elem = try lhs.elemValue(mod, i);
26832654 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);
26852656 }
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();
26872661 }
26882662 return intDivScalar(lhs, rhs, ty, allocator, mod);
26892663 }
......@@ -2715,14 +2689,17 @@ pub const Value = struct {
27152689
27162690 pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
27172691 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));
27192693 const scalar_ty = ty.scalarType(mod);
27202694 for (result_data, 0..) |*scalar, i| {
27212695 const lhs_elem = try lhs.elemValue(mod, i);
27222696 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);
27242698 }
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();
27262703 }
27272704 return intDivFloorScalar(lhs, rhs, ty, allocator, mod);
27282705 }
......@@ -2754,14 +2731,17 @@ pub const Value = struct {
27542731
27552732 pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
27562733 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));
27582735 const scalar_ty = ty.scalarType(mod);
27592736 for (result_data, 0..) |*scalar, i| {
27602737 const lhs_elem = try lhs.elemValue(mod, i);
27612738 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);
27632740 }
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();
27652745 }
27662746 return intModScalar(lhs, rhs, ty, allocator, mod);
27672747 }
......@@ -2794,7 +2774,7 @@ pub const Value = struct {
27942774 /// Returns true if the value is a floating point type and is NaN. Returns false otherwise.
27952775 pub fn isNan(val: Value, mod: *const Module) bool {
27962776 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())) {
27982778 .float => |float| switch (float.storage) {
27992779 inline else => |x| std.math.isNan(x),
28002780 },
......@@ -2805,7 +2785,7 @@ pub const Value = struct {
28052785 /// Returns true if the value is a floating point type and is infinite. Returns false otherwise.
28062786 pub fn isInf(val: Value, mod: *const Module) bool {
28072787 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())) {
28092789 .float => |float| switch (float.storage) {
28102790 inline else => |x| std.math.isInf(x),
28112791 },
......@@ -2815,7 +2795,7 @@ pub const Value = struct {
28152795
28162796 pub fn isNegativeInf(val: Value, mod: *const Module) bool {
28172797 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())) {
28192799 .float => |float| switch (float.storage) {
28202800 inline else => |x| std.math.isNegativeInf(x),
28212801 },
......@@ -2825,13 +2805,17 @@ pub const Value = struct {
28252805
28262806 pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
28272807 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);
28292810 for (result_data, 0..) |*scalar, i| {
28302811 const lhs_elem = try lhs.elemValue(mod, i);
28312812 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);
28332814 }
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();
28352819 }
28362820 return floatRemScalar(lhs, rhs, float_type, mod);
28372821 }
......@@ -2847,20 +2831,24 @@ pub const Value = struct {
28472831 else => unreachable,
28482832 };
28492833 return (try mod.intern(.{ .float = .{
2850 .ty = float_type.ip_index,
2834 .ty = float_type.toIntern(),
28512835 .storage = storage,
28522836 } })).toValue();
28532837 }
28542838
28552839 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
28562840 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);
28582843 for (result_data, 0..) |*scalar, i| {
28592844 const lhs_elem = try lhs.elemValue(mod, i);
28602845 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);
28622847 }
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();
28642852 }
28652853 return floatModScalar(lhs, rhs, float_type, mod);
28662854 }
......@@ -2876,21 +2864,24 @@ pub const Value = struct {
28762864 else => unreachable,
28772865 };
28782866 return (try mod.intern(.{ .float = .{
2879 .ty = float_type.ip_index,
2867 .ty = float_type.toIntern(),
28802868 .storage = storage,
28812869 } })).toValue();
28822870 }
28832871
28842872 pub fn intMul(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
28852873 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));
28872875 const scalar_ty = ty.scalarType(mod);
28882876 for (result_data, 0..) |*scalar, i| {
28892877 const lhs_elem = try lhs.elemValue(mod, i);
28902878 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);
28922880 }
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();
28942885 }
28952886 return intMulScalar(lhs, rhs, ty, allocator, mod);
28962887 }
......@@ -2918,13 +2909,16 @@ pub const Value = struct {
29182909
29192910 pub fn intTrunc(val: Value, ty: Type, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, mod: *Module) !Value {
29202911 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));
29222913 const scalar_ty = ty.scalarType(mod);
29232914 for (result_data, 0..) |*scalar, i| {
29242915 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);
29262917 }
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();
29282922 }
29292923 return intTruncScalar(val, ty, allocator, signedness, bits, mod);
29302924 }
......@@ -2939,14 +2933,17 @@ pub const Value = struct {
29392933 mod: *Module,
29402934 ) !Value {
29412935 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));
29432937 const scalar_ty = ty.scalarType(mod);
29442938 for (result_data, 0..) |*scalar, i| {
29452939 const elem_val = try val.elemValue(mod, i);
29462940 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);
29482942 }
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();
29502947 }
29512948 return intTruncScalar(val, ty, allocator, signedness, @intCast(u16, bits.toUnsignedInt(mod)), mod);
29522949 }
......@@ -2976,14 +2973,17 @@ pub const Value = struct {
29762973
29772974 pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
29782975 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));
29802977 const scalar_ty = ty.scalarType(mod);
29812978 for (result_data, 0..) |*scalar, i| {
29822979 const lhs_elem = try lhs.elemValue(mod, i);
29832980 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);
29852982 }
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();
29872987 }
29882988 return shlScalar(lhs, rhs, ty, allocator, mod);
29892989 }
......@@ -3015,18 +3015,26 @@ pub const Value = struct {
30153015 mod: *Module,
30163016 ) !OverflowArithmeticResult {
30173017 if (ty.zigTypeTag(mod) == .Vector) {
3018 const overflowed_data = try allocator.alloc(Value, ty.vectorLen(mod));
3019 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
3020 for (result_data, 0..) |*scalar, i| {
3018 const vec_len = ty.vectorLen(mod);
3019 const overflowed_data = try allocator.alloc(InternPool.Index, vec_len);
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| {
30213023 const lhs_elem = try lhs.elemValue(mod, i);
30223024 const rhs_elem = try rhs.elemValue(mod, i);
3023 const of_math_result = try shlWithOverflowScalar(lhs_elem, rhs_elem, ty.scalarType(mod), allocator, mod);
3024 overflowed_data[i] = of_math_result.overflow_bit;
3025 scalar.* = of_math_result.wrapped_result;
3025 const of_math_result = try shlWithOverflowScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod);
3026 of.* = try of_math_result.overflow_bit.intern(Type.bool, mod);
3027 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
30263028 }
30273029 return OverflowArithmeticResult{
3028 .overflow_bit = try Value.Tag.aggregate.create(allocator, overflowed_data),
3029 .wrapped_result = try Value.Tag.aggregate.create(allocator, result_data),
3030 .overflow_bit = (try mod.intern(.{ .aggregate = .{
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(),
30303038 };
30313039 }
30323040 return shlWithOverflowScalar(lhs, rhs, ty, allocator, mod);
......@@ -3071,13 +3079,17 @@ pub const Value = struct {
30713079 mod: *Module,
30723080 ) !Value {
30733081 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);
30753084 for (result_data, 0..) |*scalar, i| {
30763085 const lhs_elem = try lhs.elemValue(mod, i);
30773086 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);
30793088 }
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();
30813093 }
30823094 return shlSatScalar(lhs, rhs, ty, arena, mod);
30833095 }
......@@ -3117,13 +3129,17 @@ pub const Value = struct {
31173129 mod: *Module,
31183130 ) !Value {
31193131 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);
31213134 for (result_data, 0..) |*scalar, i| {
31223135 const lhs_elem = try lhs.elemValue(mod, i);
31233136 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);
31253138 }
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();
31273143 }
31283144 return shlTruncScalar(lhs, rhs, ty, arena, mod);
31293145 }
......@@ -3143,14 +3159,17 @@ pub const Value = struct {
31433159
31443160 pub fn shr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
31453161 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));
31473163 const scalar_ty = ty.scalarType(mod);
31483164 for (result_data, 0..) |*scalar, i| {
31493165 const lhs_elem = try lhs.elemValue(mod, i);
31503166 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);
31523168 }
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();
31543173 }
31553174 return shrScalar(lhs, rhs, ty, allocator, mod);
31563175 }
......@@ -3193,12 +3212,16 @@ pub const Value = struct {
31933212 mod: *Module,
31943213 ) !Value {
31953214 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);
31973217 for (result_data, 0..) |*scalar, i| {
31983218 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);
32003220 }
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();
32023225 }
32033226 return floatNegScalar(val, float_type, mod);
32043227 }
......@@ -3218,7 +3241,7 @@ pub const Value = struct {
32183241 else => unreachable,
32193242 };
32203243 return (try mod.intern(.{ .float = .{
3221 .ty = float_type.ip_index,
3244 .ty = float_type.toIntern(),
32223245 .storage = storage,
32233246 } })).toValue();
32243247 }
......@@ -3231,13 +3254,17 @@ pub const Value = struct {
32313254 mod: *Module,
32323255 ) !Value {
32333256 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);
32353259 for (result_data, 0..) |*scalar, i| {
32363260 const lhs_elem = try lhs.elemValue(mod, i);
32373261 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);
32393263 }
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();
32413268 }
32423269 return floatAddScalar(lhs, rhs, float_type, mod);
32433270 }
......@@ -3258,7 +3285,7 @@ pub const Value = struct {
32583285 else => unreachable,
32593286 };
32603287 return (try mod.intern(.{ .float = .{
3261 .ty = float_type.ip_index,
3288 .ty = float_type.toIntern(),
32623289 .storage = storage,
32633290 } })).toValue();
32643291 }
......@@ -3271,13 +3298,17 @@ pub const Value = struct {
32713298 mod: *Module,
32723299 ) !Value {
32733300 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);
32753303 for (result_data, 0..) |*scalar, i| {
32763304 const lhs_elem = try lhs.elemValue(mod, i);
32773305 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);
32793307 }
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();
32813312 }
32823313 return floatSubScalar(lhs, rhs, float_type, mod);
32833314 }
......@@ -3298,7 +3329,7 @@ pub const Value = struct {
32983329 else => unreachable,
32993330 };
33003331 return (try mod.intern(.{ .float = .{
3301 .ty = float_type.ip_index,
3332 .ty = float_type.toIntern(),
33023333 .storage = storage,
33033334 } })).toValue();
33043335 }
......@@ -3311,13 +3342,17 @@ pub const Value = struct {
33113342 mod: *Module,
33123343 ) !Value {
33133344 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);
33153347 for (result_data, 0..) |*scalar, i| {
33163348 const lhs_elem = try lhs.elemValue(mod, i);
33173349 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);
33193351 }
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();
33213356 }
33223357 return floatDivScalar(lhs, rhs, float_type, mod);
33233358 }
......@@ -3338,7 +3373,7 @@ pub const Value = struct {
33383373 else => unreachable,
33393374 };
33403375 return (try mod.intern(.{ .float = .{
3341 .ty = float_type.ip_index,
3376 .ty = float_type.toIntern(),
33423377 .storage = storage,
33433378 } })).toValue();
33443379 }
......@@ -3351,13 +3386,17 @@ pub const Value = struct {
33513386 mod: *Module,
33523387 ) !Value {
33533388 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);
33553391 for (result_data, 0..) |*scalar, i| {
33563392 const lhs_elem = try lhs.elemValue(mod, i);
33573393 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);
33593395 }
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();
33613400 }
33623401 return floatDivFloorScalar(lhs, rhs, float_type, mod);
33633402 }
......@@ -3378,7 +3417,7 @@ pub const Value = struct {
33783417 else => unreachable,
33793418 };
33803419 return (try mod.intern(.{ .float = .{
3381 .ty = float_type.ip_index,
3420 .ty = float_type.toIntern(),
33823421 .storage = storage,
33833422 } })).toValue();
33843423 }
......@@ -3391,13 +3430,17 @@ pub const Value = struct {
33913430 mod: *Module,
33923431 ) !Value {
33933432 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);
33953435 for (result_data, 0..) |*scalar, i| {
33963436 const lhs_elem = try lhs.elemValue(mod, i);
33973437 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);
33993439 }
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();
34013444 }
34023445 return floatDivTruncScalar(lhs, rhs, float_type, mod);
34033446 }
......@@ -3418,7 +3461,7 @@ pub const Value = struct {
34183461 else => unreachable,
34193462 };
34203463 return (try mod.intern(.{ .float = .{
3421 .ty = float_type.ip_index,
3464 .ty = float_type.toIntern(),
34223465 .storage = storage,
34233466 } })).toValue();
34243467 }
......@@ -3431,13 +3474,17 @@ pub const Value = struct {
34313474 mod: *Module,
34323475 ) !Value {
34333476 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);
34353479 for (result_data, 0..) |*scalar, i| {
34363480 const lhs_elem = try lhs.elemValue(mod, i);
34373481 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);
34393483 }
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();
34413488 }
34423489 return floatMulScalar(lhs, rhs, float_type, mod);
34433490 }
......@@ -3458,19 +3505,23 @@ pub const Value = struct {
34583505 else => unreachable,
34593506 };
34603507 return (try mod.intern(.{ .float = .{
3461 .ty = float_type.ip_index,
3508 .ty = float_type.toIntern(),
34623509 .storage = storage,
34633510 } })).toValue();
34643511 }
34653512
34663513 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
34673514 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);
34693517 for (result_data, 0..) |*scalar, i| {
34703518 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);
34723520 }
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();
34743525 }
34753526 return sqrtScalar(val, float_type, mod);
34763527 }
......@@ -3486,19 +3537,23 @@ pub const Value = struct {
34863537 else => unreachable,
34873538 };
34883539 return (try mod.intern(.{ .float = .{
3489 .ty = float_type.ip_index,
3540 .ty = float_type.toIntern(),
34903541 .storage = storage,
34913542 } })).toValue();
34923543 }
34933544
34943545 pub fn sin(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
34953546 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);
34973549 for (result_data, 0..) |*scalar, i| {
34983550 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);
35003552 }
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();
35023557 }
35033558 return sinScalar(val, float_type, mod);
35043559 }
......@@ -3514,19 +3569,23 @@ pub const Value = struct {
35143569 else => unreachable,
35153570 };
35163571 return (try mod.intern(.{ .float = .{
3517 .ty = float_type.ip_index,
3572 .ty = float_type.toIntern(),
35183573 .storage = storage,
35193574 } })).toValue();
35203575 }
35213576
35223577 pub fn cos(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
35233578 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);
35253581 for (result_data, 0..) |*scalar, i| {
35263582 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);
35283584 }
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();
35303589 }
35313590 return cosScalar(val, float_type, mod);
35323591 }
......@@ -3542,19 +3601,23 @@ pub const Value = struct {
35423601 else => unreachable,
35433602 };
35443603 return (try mod.intern(.{ .float = .{
3545 .ty = float_type.ip_index,
3604 .ty = float_type.toIntern(),
35463605 .storage = storage,
35473606 } })).toValue();
35483607 }
35493608
35503609 pub fn tan(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
35513610 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);
35533613 for (result_data, 0..) |*scalar, i| {
35543614 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);
35563616 }
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();
35583621 }
35593622 return tanScalar(val, float_type, mod);
35603623 }
......@@ -3570,19 +3633,23 @@ pub const Value = struct {
35703633 else => unreachable,
35713634 };
35723635 return (try mod.intern(.{ .float = .{
3573 .ty = float_type.ip_index,
3636 .ty = float_type.toIntern(),
35743637 .storage = storage,
35753638 } })).toValue();
35763639 }
35773640
35783641 pub fn exp(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
35793642 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);
35813645 for (result_data, 0..) |*scalar, i| {
35823646 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);
35843648 }
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();
35863653 }
35873654 return expScalar(val, float_type, mod);
35883655 }
......@@ -3598,19 +3665,23 @@ pub const Value = struct {
35983665 else => unreachable,
35993666 };
36003667 return (try mod.intern(.{ .float = .{
3601 .ty = float_type.ip_index,
3668 .ty = float_type.toIntern(),
36023669 .storage = storage,
36033670 } })).toValue();
36043671 }
36053672
36063673 pub fn exp2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
36073674 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);
36093677 for (result_data, 0..) |*scalar, i| {
36103678 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);
36123680 }
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();
36143685 }
36153686 return exp2Scalar(val, float_type, mod);
36163687 }
......@@ -3626,19 +3697,23 @@ pub const Value = struct {
36263697 else => unreachable,
36273698 };
36283699 return (try mod.intern(.{ .float = .{
3629 .ty = float_type.ip_index,
3700 .ty = float_type.toIntern(),
36303701 .storage = storage,
36313702 } })).toValue();
36323703 }
36333704
36343705 pub fn log(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
36353706 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);
36373709 for (result_data, 0..) |*scalar, i| {
36383710 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);
36403712 }
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();
36423717 }
36433718 return logScalar(val, float_type, mod);
36443719 }
......@@ -3654,19 +3729,23 @@ pub const Value = struct {
36543729 else => unreachable,
36553730 };
36563731 return (try mod.intern(.{ .float = .{
3657 .ty = float_type.ip_index,
3732 .ty = float_type.toIntern(),
36583733 .storage = storage,
36593734 } })).toValue();
36603735 }
36613736
36623737 pub fn log2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
36633738 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);
36653741 for (result_data, 0..) |*scalar, i| {
36663742 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);
36683744 }
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();
36703749 }
36713750 return log2Scalar(val, float_type, mod);
36723751 }
......@@ -3682,19 +3761,23 @@ pub const Value = struct {
36823761 else => unreachable,
36833762 };
36843763 return (try mod.intern(.{ .float = .{
3685 .ty = float_type.ip_index,
3764 .ty = float_type.toIntern(),
36863765 .storage = storage,
36873766 } })).toValue();
36883767 }
36893768
36903769 pub fn log10(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
36913770 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);
36933773 for (result_data, 0..) |*scalar, i| {
36943774 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);
36963776 }
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();
36983781 }
36993782 return log10Scalar(val, float_type, mod);
37003783 }
......@@ -3710,19 +3793,23 @@ pub const Value = struct {
37103793 else => unreachable,
37113794 };
37123795 return (try mod.intern(.{ .float = .{
3713 .ty = float_type.ip_index,
3796 .ty = float_type.toIntern(),
37143797 .storage = storage,
37153798 } })).toValue();
37163799 }
37173800
37183801 pub fn fabs(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
37193802 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);
37213805 for (result_data, 0..) |*scalar, i| {
37223806 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);
37243808 }
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();
37263813 }
37273814 return fabsScalar(val, float_type, mod);
37283815 }
......@@ -3738,19 +3825,23 @@ pub const Value = struct {
37383825 else => unreachable,
37393826 };
37403827 return (try mod.intern(.{ .float = .{
3741 .ty = float_type.ip_index,
3828 .ty = float_type.toIntern(),
37423829 .storage = storage,
37433830 } })).toValue();
37443831 }
37453832
37463833 pub fn floor(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
37473834 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);
37493837 for (result_data, 0..) |*scalar, i| {
37503838 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);
37523840 }
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();
37543845 }
37553846 return floorScalar(val, float_type, mod);
37563847 }
......@@ -3766,19 +3857,23 @@ pub const Value = struct {
37663857 else => unreachable,
37673858 };
37683859 return (try mod.intern(.{ .float = .{
3769 .ty = float_type.ip_index,
3860 .ty = float_type.toIntern(),
37703861 .storage = storage,
37713862 } })).toValue();
37723863 }
37733864
37743865 pub fn ceil(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
37753866 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);
37773869 for (result_data, 0..) |*scalar, i| {
37783870 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);
37803872 }
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();
37823877 }
37833878 return ceilScalar(val, float_type, mod);
37843879 }
......@@ -3794,19 +3889,23 @@ pub const Value = struct {
37943889 else => unreachable,
37953890 };
37963891 return (try mod.intern(.{ .float = .{
3797 .ty = float_type.ip_index,
3892 .ty = float_type.toIntern(),
37983893 .storage = storage,
37993894 } })).toValue();
38003895 }
38013896
38023897 pub fn round(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
38033898 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);
38053901 for (result_data, 0..) |*scalar, i| {
38063902 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);
38083904 }
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();
38103909 }
38113910 return roundScalar(val, float_type, mod);
38123911 }
......@@ -3822,19 +3921,23 @@ pub const Value = struct {
38223921 else => unreachable,
38233922 };
38243923 return (try mod.intern(.{ .float = .{
3825 .ty = float_type.ip_index,
3924 .ty = float_type.toIntern(),
38263925 .storage = storage,
38273926 } })).toValue();
38283927 }
38293928
38303929 pub fn trunc(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
38313930 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);
38333933 for (result_data, 0..) |*scalar, i| {
38343934 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);
38363936 }
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();
38383941 }
38393942 return truncScalar(val, float_type, mod);
38403943 }
......@@ -3850,7 +3953,7 @@ pub const Value = struct {
38503953 else => unreachable,
38513954 };
38523955 return (try mod.intern(.{ .float = .{
3853 .ty = float_type.ip_index,
3956 .ty = float_type.toIntern(),
38543957 .storage = storage,
38553958 } })).toValue();
38563959 }
......@@ -3864,20 +3967,18 @@ pub const Value = struct {
38643967 mod: *Module,
38653968 ) !Value {
38663969 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);
38683972 for (result_data, 0..) |*scalar, i| {
38693973 const mulend1_elem = try mulend1.elemValue(mod, i);
38703974 const mulend2_elem = try mulend2.elemValue(mod, i);
38713975 const addend_elem = try addend.elemValue(mod, i);
3872 scalar.* = try mulAddScalar(
3873 float_type.scalarType(mod),
3874 mulend1_elem,
3875 mulend2_elem,
3876 addend_elem,
3877 mod,
3878 );
3976 scalar.* = try (try mulAddScalar(scalar_ty, mulend1_elem, mulend2_elem, addend_elem, mod)).intern(scalar_ty, mod);
38793977 }
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();
38813982 }
38823983 return mulAddScalar(float_type, mulend1, mulend2, addend, mod);
38833984 }
......@@ -3899,7 +4000,7 @@ pub const Value = struct {
38994000 else => unreachable,
39004001 };
39014002 return (try mod.intern(.{ .float = .{
3902 .ty = float_type.ip_index,
4003 .ty = float_type.toIntern(),
39034004 .storage = storage,
39044005 } })).toValue();
39054006 }
......@@ -3931,22 +4032,22 @@ pub const Value = struct {
39314032 }
39324033
39334034 pub fn isGenericPoison(val: Value) bool {
3934 return val.ip_index == .generic_poison;
4035 return val.toIntern() == .generic_poison;
39354036 }
39364037
39374038 /// This type is not copyable since it may contain pointers to its inner data.
39384039 pub const Payload = struct {
39394040 tag: Tag,
39404041
3941 pub const Bytes = struct {
4042 pub const SubValue = struct {
39424043 base: Payload,
3943 /// Includes the sentinel, if any.
3944 data: []const u8,
4044 data: Value,
39454045 };
39464046
3947 pub const StrLit = struct {
4047 pub const Bytes = struct {
39484048 base: Payload,
3949 data: Module.StringLiteralContext.Key,
4049 /// Includes the sentinel, if any.
4050 data: []const u8,
39504051 };
39514052
39524053 pub const Aggregate = struct {