authorgravatar for techatrix@mailbox.orgTechatrix <techatrix@mailbox.org> 2023-11-25 04:30:48+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-25 04:09:53-05:00
log18608223ef5e588598d21dfe71678dbc62f320e4
tree407e0a98f6786f55c998fa42b402d55292db293e
parente834e95d718fe3eacaec54034462c90fd10bfe76

convert `toType` and `toValue` to `Type.fromInterned` and `Value.fromInterned`


32 files changed, 1398 insertions(+), 1390 deletions(-)

src/Air.zig+6-6
......@@ -1221,7 +1221,7 @@ pub fn getMainBody(air: Air) []const Air.Inst.Index {
12211221
12221222pub fn typeOf(air: *const Air, inst: Air.Inst.Ref, ip: *const InternPool) Type {
12231223 if (refToInterned(inst)) |ip_index| {
1224 return ip.typeOf(ip_index).toType();
1224 return Type.fromInterned(ip.typeOf(ip_index));
12251225 } else {
12261226 return air.typeOfIndex(refToIndex(inst).?, ip);
12271227 }
......@@ -1438,7 +1438,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14381438
14391439 .call, .call_always_tail, .call_never_tail, .call_never_inline => {
14401440 const callee_ty = air.typeOf(datas[inst].pl_op.operand, ip);
1441 return ip.funcTypeReturnType(callee_ty.toIntern()).toType();
1441 return Type.fromInterned(ip.funcTypeReturnType(callee_ty.toIntern()));
14421442 },
14431443
14441444 .slice_elem_val, .ptr_elem_val, .array_elem_val => {
......@@ -1456,7 +1456,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14561456
14571457 .reduce, .reduce_optimized => {
14581458 const operand_ty = air.typeOf(datas[inst].reduce.operand, ip);
1459 return ip.indexToKey(operand_ty.ip_index).vector_type.child.toType();
1459 return Type.fromInterned(ip.indexToKey(operand_ty.ip_index).vector_type.child);
14601460 },
14611461
14621462 .mul_add => return air.typeOf(datas[inst].pl_op.operand, ip),
......@@ -1467,7 +1467,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14671467
14681468 .@"try" => {
14691469 const err_union_ty = air.typeOf(datas[inst].pl_op.operand, ip);
1470 return ip.indexToKey(err_union_ty.ip_index).error_union_type.payload_type.toType();
1470 return Type.fromInterned(ip.indexToKey(err_union_ty.ip_index).error_union_type.payload_type);
14711471 },
14721472
14731473 .work_item_id,
......@@ -1482,7 +1482,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14821482
14831483pub fn getRefType(air: Air, ref: Air.Inst.Ref) Type {
14841484 _ = air; // TODO: remove this parameter
1485 return refToInterned(ref).?.toType();
1485 return Type.fromInterned(refToInterned(ref).?);
14861486}
14871487
14881488/// Returns the requested data, as well as the new index which is at the start of the
......@@ -1561,7 +1561,7 @@ pub fn indexToRef(inst: Inst.Index) Inst.Ref {
15611561/// Returns `null` if runtime-known.
15621562pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {
15631563 if (refToInterned(inst)) |ip_index| {
1564 return ip_index.toValue();
1564 return Value.fromInterned(ip_index);
15651565 }
15661566 const index = refToIndex(inst).?;
15671567 return air.typeOfIndex(index, &mod.intern_pool).onePossibleValue(mod);
src/Autodoc.zig+1-1
......@@ -117,7 +117,7 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {
117117 // Not a real type, doesn't have a normal name
118118 try tmpbuf.writer().writeAll("(generic poison)");
119119 } else {
120 try ip_index.toType().fmt(self.comp_module).format("", .{}, tmpbuf.writer());
120 try @import("type.zig").Type.fromInterned(ip_index).fmt(self.comp_module).format("", .{}, tmpbuf.writer());
121121 }
122122 try self.types.append(
123123 self.arena,
src/InternPool.zig+2-15
......@@ -2096,19 +2096,6 @@ pub const Index = enum(u32) {
20962096 }
20972097 };
20982098
2099 pub fn toType(i: Index) @import("type.zig").Type {
2100 assert(i != .none);
2101 return .{ .ip_index = i };
2102 }
2103
2104 pub fn toValue(i: Index) @import("value.zig").Value {
2105 assert(i != .none);
2106 return .{
2107 .ip_index = i,
2108 .legacy = undefined,
2109 };
2110 }
2111
21122099 /// Used for a map of `Index` values to the index within a list of `Index` values.
21132100 const Adapter = struct {
21142101 indexes: []const Index,
......@@ -6145,8 +6132,8 @@ fn finishFuncInstance(
61456132 .src_line = fn_owner_decl.src_line,
61466133 .has_tv = true,
61476134 .owns_tv = true,
6148 .ty = func_ty.toType(),
6149 .val = func_index.toValue(),
6135 .ty = @import("type.zig").Type.fromInterned(func_ty),
6136 .val = @import("value.zig").Value.fromInterned(func_index),
61506137 .alignment = .none,
61516138 .@"linksection" = section,
61526139 .@"addrspace" = fn_owner_decl.@"addrspace",
src/Module.zig+61-61
......@@ -659,7 +659,7 @@ pub const Decl = struct {
659659 pub fn internValue(decl: *Decl, mod: *Module) Allocator.Error!InternPool.Index {
660660 assert(decl.has_tv);
661661 const ip_index = try decl.val.intern(decl.ty, mod);
662 decl.val = ip_index.toValue();
662 decl.val = Value.fromInterned(ip_index);
663663 return ip_index;
664664 }
665665
......@@ -3556,8 +3556,8 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
35563556 _ = try decl.internValue(mod);
35573557 }
35583558
3559 new_namespace.ty = struct_ty.toType();
3560 new_decl.val = struct_ty.toValue();
3559 new_namespace.ty = Type.fromInterned(struct_ty);
3560 new_decl.val = Value.fromInterned(struct_ty);
35613561 new_decl.has_tv = true;
35623562 new_decl.owns_tv = true;
35633563 new_decl.analysis = .complete;
......@@ -3711,7 +3711,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
37113711 return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)});
37123712 }
37133713
3714 decl.ty = InternPool.Index.type_type.toType();
3714 decl.ty = Type.fromInterned(InternPool.Index.type_type);
37153715 decl.val = ty.toValue();
37163716 decl.alignment = .none;
37173717 decl.@"linksection" = .none;
......@@ -3741,7 +3741,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
37413741 }
37423742
37433743 decl.ty = decl_tv.ty;
3744 decl.val = (try decl_tv.val.intern(decl_tv.ty, mod)).toValue();
3744 decl.val = Value.fromInterned((try decl_tv.val.intern(decl_tv.ty, mod)));
37453745 // linksection, align, and addrspace were already set by Sema
37463746 decl.has_tv = true;
37473747 decl.owns_tv = owns_tv;
......@@ -3794,7 +3794,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
37943794 }
37953795
37963796 decl.ty = decl_tv.ty;
3797 decl.val = (try decl_tv.val.intern(decl_tv.ty, mod)).toValue();
3797 decl.val = Value.fromInterned((try decl_tv.val.intern(decl_tv.ty, mod)));
37983798 decl.alignment = blk: {
37993799 const align_ref = decl.zirAlignRef(mod);
38003800 if (align_ref == .none) break :blk .none;
......@@ -4509,7 +4509,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
45094509 .owner_decl_index = decl_index,
45104510 .func_index = func_index,
45114511 .func_is_naked = fn_ty_info.cc == .Naked,
4512 .fn_ret_ty = fn_ty_info.return_type.toType(),
4512 .fn_ret_ty = Type.fromInterned(fn_ty_info.return_type),
45134513 .fn_ret_ty_ies = null,
45144514 .owner_func_index = func_index,
45154515 .branch_quota = @max(func.branchQuota(ip).*, Sema.default_branch_quota),
......@@ -4580,7 +4580,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
45804580 const param_ty = fn_ty_info.param_types.get(ip)[runtime_param_index];
45814581 runtime_param_index += 1;
45824582
4583 const opt_opv = sema.typeHasOnePossibleValue(param_ty.toType()) catch |err| switch (err) {
4583 const opt_opv = sema.typeHasOnePossibleValue(Type.fromInterned(param_ty)) catch |err| switch (err) {
45844584 error.NeededSourceLocation => unreachable,
45854585 error.GenericPoison => unreachable,
45864586 error.ComptimeReturn => unreachable,
......@@ -4707,7 +4707,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
47074707 // Similarly, resolve any queued up types that were requested to be resolved for
47084708 // the backends.
47094709 for (sema.types_to_resolve.keys()) |ty| {
4710 sema.resolveTypeFully(ty.toType()) catch |err| switch (err) {
4710 sema.resolveTypeFully(Type.fromInterned(ty)) catch |err| switch (err) {
47114711 error.NeededSourceLocation => unreachable,
47124712 error.GenericPoison => unreachable,
47134713 error.ComptimeReturn => unreachable,
......@@ -5392,10 +5392,10 @@ pub fn populateTestFunctions(
53925392 });
53935393 const test_name_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, .none, .{
53945394 .ty = test_name_decl_ty,
5395 .val = (try mod.intern(.{ .aggregate = .{
5395 .val = Value.fromInterned((try mod.intern(.{ .aggregate = .{
53965396 .ty = test_name_decl_ty.toIntern(),
53975397 .storage = .{ .bytes = test_decl_name },
5398 } })).toValue(),
5398 } }))),
53995399 });
54005400 break :n test_name_decl_index;
54015401 };
......@@ -5439,10 +5439,10 @@ pub fn populateTestFunctions(
54395439 });
54405440 const array_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, .none, .{
54415441 .ty = array_decl_ty,
5442 .val = (try mod.intern(.{ .aggregate = .{
5442 .val = Value.fromInterned((try mod.intern(.{ .aggregate = .{
54435443 .ty = array_decl_ty.toIntern(),
54445444 .storage = .{ .elems = test_fn_vals },
5445 } })).toValue(),
5445 } }))),
54465446 });
54475447
54485448 break :d array_decl_index;
......@@ -5548,7 +5548,7 @@ pub fn markReferencedDeclsAlive(mod: *Module, val: Value) Allocator.Error!void {
55485548 .func => |func| try mod.markDeclIndexAlive(func.owner_decl),
55495549 .error_union => |error_union| switch (error_union.val) {
55505550 .err_name => {},
5551 .payload => |payload| try mod.markReferencedDeclsAlive(payload.toValue()),
5551 .payload => |payload| try mod.markReferencedDeclsAlive(Value.fromInterned(payload)),
55525552 },
55535553 .ptr => |ptr| {
55545554 switch (ptr.addr) {
......@@ -5556,17 +5556,17 @@ pub fn markReferencedDeclsAlive(mod: *Module, val: Value) Allocator.Error!void {
55565556 .anon_decl => {},
55575557 .mut_decl => |mut_decl| try mod.markDeclIndexAlive(mut_decl.decl),
55585558 .int, .comptime_field => {},
5559 .eu_payload, .opt_payload => |parent| try mod.markReferencedDeclsAlive(parent.toValue()),
5560 .elem, .field => |base_index| try mod.markReferencedDeclsAlive(base_index.base.toValue()),
5559 .eu_payload, .opt_payload => |parent| try mod.markReferencedDeclsAlive(Value.fromInterned(parent)),
5560 .elem, .field => |base_index| try mod.markReferencedDeclsAlive(Value.fromInterned(base_index.base)),
55615561 }
5562 if (ptr.len != .none) try mod.markReferencedDeclsAlive(ptr.len.toValue());
5562 if (ptr.len != .none) try mod.markReferencedDeclsAlive(Value.fromInterned(ptr.len));
55635563 },
5564 .opt => |opt| if (opt.val != .none) try mod.markReferencedDeclsAlive(opt.val.toValue()),
5564 .opt => |opt| if (opt.val != .none) try mod.markReferencedDeclsAlive(Value.fromInterned(opt.val)),
55655565 .aggregate => |aggregate| for (aggregate.storage.values()) |elem|
5566 try mod.markReferencedDeclsAlive(elem.toValue()),
5566 try mod.markReferencedDeclsAlive(Value.fromInterned(elem)),
55675567 .un => |un| {
5568 if (un.tag != .none) try mod.markReferencedDeclsAlive(un.tag.toValue());
5569 try mod.markReferencedDeclsAlive(un.val.toValue());
5568 if (un.tag != .none) try mod.markReferencedDeclsAlive(Value.fromInterned(un.tag));
5569 try mod.markReferencedDeclsAlive(Value.fromInterned(un.val));
55705570 },
55715571 else => {},
55725572 }
......@@ -5653,14 +5653,14 @@ pub fn intern(mod: *Module, key: InternPool.Key) Allocator.Error!InternPool.Inde
56535653
56545654/// Shortcut for calling `intern_pool.getCoerced`.
56555655pub fn getCoerced(mod: *Module, val: Value, new_ty: Type) Allocator.Error!Value {
5656 return (try mod.intern_pool.getCoerced(mod.gpa, val.toIntern(), new_ty.toIntern())).toValue();
5656 return Value.fromInterned((try mod.intern_pool.getCoerced(mod.gpa, val.toIntern(), new_ty.toIntern())));
56575657}
56585658
56595659pub fn intType(mod: *Module, signedness: std.builtin.Signedness, bits: u16) Allocator.Error!Type {
5660 return (try intern(mod, .{ .int_type = .{
5660 return Type.fromInterned((try intern(mod, .{ .int_type = .{
56615661 .signedness = signedness,
56625662 .bits = bits,
5663 } })).toType();
5663 } })));
56645664}
56655665
56665666pub fn errorIntType(mod: *Module) std.mem.Allocator.Error!Type {
......@@ -5669,17 +5669,17 @@ pub fn errorIntType(mod: *Module) std.mem.Allocator.Error!Type {
56695669
56705670pub fn arrayType(mod: *Module, info: InternPool.Key.ArrayType) Allocator.Error!Type {
56715671 const i = try intern(mod, .{ .array_type = info });
5672 return i.toType();
5672 return Type.fromInterned(i);
56735673}
56745674
56755675pub fn vectorType(mod: *Module, info: InternPool.Key.VectorType) Allocator.Error!Type {
56765676 const i = try intern(mod, .{ .vector_type = info });
5677 return i.toType();
5677 return Type.fromInterned(i);
56785678}
56795679
56805680pub fn optionalType(mod: *Module, child_type: InternPool.Index) Allocator.Error!Type {
56815681 const i = try intern(mod, .{ .opt_type = child_type });
5682 return i.toType();
5682 return Type.fromInterned(i);
56835683}
56845684
56855685pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type {
......@@ -5692,7 +5692,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
56925692 // pointee type needs to be resolved more, that needs to be done before calling
56935693 // this ptr() function.
56945694 if (info.flags.alignment != .none and
5695 info.flags.alignment == info.child.toType().abiAlignment(mod))
5695 info.flags.alignment == Type.fromInterned(info.child).abiAlignment(mod))
56965696 {
56975697 canon_info.flags.alignment = .none;
56985698 }
......@@ -5702,7 +5702,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
57025702 // we change it to 0 here. If this causes an assertion trip, the pointee type
57035703 // needs to be resolved before calling this ptr() function.
57045704 .none => if (info.packed_offset.host_size != 0) {
5705 const elem_bit_size = info.child.toType().bitSize(mod);
5705 const elem_bit_size = Type.fromInterned(info.child).bitSize(mod);
57065706 assert(info.packed_offset.bit_offset + elem_bit_size <= info.packed_offset.host_size * 8);
57075707 if (info.packed_offset.host_size * 8 == elem_bit_size) {
57085708 canon_info.packed_offset.host_size = 0;
......@@ -5712,7 +5712,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
57125712 _ => assert(@intFromEnum(info.flags.vector_index) < info.packed_offset.host_size),
57135713 }
57145714
5715 return (try intern(mod, .{ .ptr_type = canon_info })).toType();
5715 return Type.fromInterned((try intern(mod, .{ .ptr_type = canon_info })));
57165716}
57175717
57185718pub fn singleMutPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {
......@@ -5745,26 +5745,26 @@ pub fn adjustPtrTypeChild(mod: *Module, ptr_ty: Type, new_child: Type) Allocator
57455745}
57465746
57475747pub fn funcType(mod: *Module, key: InternPool.GetFuncTypeKey) Allocator.Error!Type {
5748 return (try mod.intern_pool.getFuncType(mod.gpa, key)).toType();
5748 return Type.fromInterned((try mod.intern_pool.getFuncType(mod.gpa, key)));
57495749}
57505750
57515751/// Use this for `anyframe->T` only.
57525752/// For `anyframe`, use the `InternPool.Index.anyframe` tag directly.
57535753pub fn anyframeType(mod: *Module, payload_ty: Type) Allocator.Error!Type {
5754 return (try intern(mod, .{ .anyframe_type = payload_ty.toIntern() })).toType();
5754 return Type.fromInterned((try intern(mod, .{ .anyframe_type = payload_ty.toIntern() })));
57555755}
57565756
57575757pub fn errorUnionType(mod: *Module, error_set_ty: Type, payload_ty: Type) Allocator.Error!Type {
5758 return (try intern(mod, .{ .error_union_type = .{
5758 return Type.fromInterned((try intern(mod, .{ .error_union_type = .{
57595759 .error_set_type = error_set_ty.toIntern(),
57605760 .payload_type = payload_ty.toIntern(),
5761 } })).toType();
5761 } })));
57625762}
57635763
57645764pub fn singleErrorSetType(mod: *Module, name: InternPool.NullTerminatedString) Allocator.Error!Type {
57655765 const names: *const [1]InternPool.NullTerminatedString = &name;
57665766 const new_ty = try mod.intern_pool.getErrorSetType(mod.gpa, names);
5767 return new_ty.toType();
5767 return Type.fromInterned(new_ty);
57685768}
57695769
57705770/// Sorts `names` in place.
......@@ -5779,7 +5779,7 @@ pub fn errorSetFromUnsortedNames(
57795779 InternPool.NullTerminatedString.indexLessThan,
57805780 );
57815781 const new_ty = try mod.intern_pool.getErrorSetType(mod.gpa, names);
5782 return new_ty.toType();
5782 return Type.fromInterned(new_ty);
57835783}
57845784
57855785/// Supports only pointers, not pointer-like optionals.
......@@ -5789,7 +5789,7 @@ pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
57895789 .ty = ty.toIntern(),
57905790 .addr = .{ .int = (try mod.intValue_u64(Type.usize, x)).toIntern() },
57915791 } });
5792 return i.toValue();
5792 return Value.fromInterned(i);
57935793}
57945794
57955795/// Creates an enum tag value based on the integer tag value.
......@@ -5802,7 +5802,7 @@ pub fn enumValue(mod: *Module, ty: Type, tag_int: InternPool.Index) Allocator.Er
58025802 .ty = ty.toIntern(),
58035803 .int = tag_int,
58045804 } });
5805 return i.toValue();
5805 return Value.fromInterned(i);
58065806}
58075807
58085808/// Creates an enum tag value based on the field index according to source code
......@@ -5814,23 +5814,23 @@ pub fn enumValueFieldIndex(mod: *Module, ty: Type, field_index: u32) Allocator.E
58145814
58155815 if (enum_type.values.len == 0) {
58165816 // Auto-numbered fields.
5817 return (try ip.get(gpa, .{ .enum_tag = .{
5817 return Value.fromInterned((try ip.get(gpa, .{ .enum_tag = .{
58185818 .ty = ty.toIntern(),
58195819 .int = try ip.get(gpa, .{ .int = .{
58205820 .ty = enum_type.tag_ty,
58215821 .storage = .{ .u64 = field_index },
58225822 } }),
5823 } })).toValue();
5823 } })));
58245824 }
58255825
5826 return (try ip.get(gpa, .{ .enum_tag = .{
5826 return Value.fromInterned((try ip.get(gpa, .{ .enum_tag = .{
58275827 .ty = ty.toIntern(),
58285828 .int = enum_type.values.get(ip)[field_index],
5829 } })).toValue();
5829 } })));
58305830}
58315831
58325832pub fn undefValue(mod: *Module, ty: Type) Allocator.Error!Value {
5833 return (try mod.intern(.{ .undef = ty.toIntern() })).toValue();
5833 return Value.fromInterned((try mod.intern(.{ .undef = ty.toIntern() })));
58345834}
58355835
58365836pub fn undefRef(mod: *Module, ty: Type) Allocator.Error!Air.Inst.Ref {
......@@ -5854,7 +5854,7 @@ pub fn intValue_big(mod: *Module, ty: Type, x: BigIntConst) Allocator.Error!Valu
58545854 .ty = ty.toIntern(),
58555855 .storage = .{ .big_int = x },
58565856 } });
5857 return i.toValue();
5857 return Value.fromInterned(i);
58585858}
58595859
58605860pub fn intValue_u64(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
......@@ -5862,7 +5862,7 @@ pub fn intValue_u64(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
58625862 .ty = ty.toIntern(),
58635863 .storage = .{ .u64 = x },
58645864 } });
5865 return i.toValue();
5865 return Value.fromInterned(i);
58665866}
58675867
58685868pub fn intValue_i64(mod: *Module, ty: Type, x: i64) Allocator.Error!Value {
......@@ -5870,7 +5870,7 @@ pub fn intValue_i64(mod: *Module, ty: Type, x: i64) Allocator.Error!Value {
58705870 .ty = ty.toIntern(),
58715871 .storage = .{ .i64 = x },
58725872 } });
5873 return i.toValue();
5873 return Value.fromInterned(i);
58745874}
58755875
58765876pub fn unionValue(mod: *Module, union_ty: Type, tag: Value, val: Value) Allocator.Error!Value {
......@@ -5879,7 +5879,7 @@ pub fn unionValue(mod: *Module, union_ty: Type, tag: Value, val: Value) Allocato
58795879 .tag = tag.toIntern(),
58805880 .val = val.toIntern(),
58815881 } });
5882 return i.toValue();
5882 return Value.fromInterned(i);
58835883}
58845884
58855885/// This function casts the float representation down to the representation of the type, potentially
......@@ -5897,7 +5897,7 @@ pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
58975897 .ty = ty.toIntern(),
58985898 .storage = storage,
58995899 } });
5900 return i.toValue();
5900 return Value.fromInterned(i);
59015901}
59025902
59035903pub fn nullValue(mod: *Module, opt_ty: Type) Allocator.Error!Value {
......@@ -5907,7 +5907,7 @@ pub fn nullValue(mod: *Module, opt_ty: Type) Allocator.Error!Value {
59075907 .ty = opt_ty.toIntern(),
59085908 .val = .none,
59095909 } });
5910 return result.toValue();
5910 return Value.fromInterned(result);
59115911}
59125912
59135913pub fn smallestUnsignedInt(mod: *Module, max: u64) Allocator.Error!Type {
......@@ -5964,10 +5964,10 @@ pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 {
59645964 return @as(u16, @intCast(big.bitCountTwosComp()));
59655965 },
59665966 .lazy_align => |lazy_ty| {
5967 return Type.smallestUnsignedBits(lazy_ty.toType().abiAlignment(mod).toByteUnits(0)) + @intFromBool(sign);
5967 return Type.smallestUnsignedBits(Type.fromInterned(lazy_ty).abiAlignment(mod).toByteUnits(0)) + @intFromBool(sign);
59685968 },
59695969 .lazy_size => |lazy_ty| {
5970 return Type.smallestUnsignedBits(lazy_ty.toType().abiSize(mod)) + @intFromBool(sign);
5970 return Type.smallestUnsignedBits(Type.fromInterned(lazy_ty).abiSize(mod)) + @intFromBool(sign);
59715971 },
59725972 }
59735973}
......@@ -6252,14 +6252,14 @@ pub fn getUnionLayout(mod: *Module, u: InternPool.UnionType) UnionLayout {
62526252 var payload_size: u64 = 0;
62536253 var payload_align: Alignment = .@"1";
62546254 for (u.field_types.get(ip), 0..) |field_ty, i| {
6255 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
6255 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
62566256
62576257 const explicit_align = u.fieldAlign(ip, @intCast(i));
62586258 const field_align = if (explicit_align != .none)
62596259 explicit_align
62606260 else
6261 field_ty.toType().abiAlignment(mod);
6262 const field_size = field_ty.toType().abiSize(mod);
6261 Type.fromInterned(field_ty).abiAlignment(mod);
6262 const field_size = Type.fromInterned(field_ty).abiSize(mod);
62636263 if (field_size > payload_size) {
62646264 payload_size = field_size;
62656265 biggest_field = @intCast(i);
......@@ -6271,7 +6271,7 @@ pub fn getUnionLayout(mod: *Module, u: InternPool.UnionType) UnionLayout {
62716271 }
62726272 }
62736273 const have_tag = u.flagsPtr(ip).runtime_tag.hasTag();
6274 if (!have_tag or !u.enum_tag_ty.toType().hasRuntimeBits(mod)) {
6274 if (!have_tag or !Type.fromInterned(u.enum_tag_ty).hasRuntimeBits(mod)) {
62756275 return .{
62766276 .abi_size = payload_align.forward(payload_size),
62776277 .abi_align = payload_align,
......@@ -6286,8 +6286,8 @@ pub fn getUnionLayout(mod: *Module, u: InternPool.UnionType) UnionLayout {
62866286 };
62876287 }
62886288
6289 const tag_size = u.enum_tag_ty.toType().abiSize(mod);
6290 const tag_align = u.enum_tag_ty.toType().abiAlignment(mod).max(.@"1");
6289 const tag_size = Type.fromInterned(u.enum_tag_ty).abiSize(mod);
6290 const tag_align = Type.fromInterned(u.enum_tag_ty).abiAlignment(mod).max(.@"1");
62916291 return .{
62926292 .abi_size = u.size,
62936293 .abi_align = tag_align.max(payload_align),
......@@ -6311,9 +6311,9 @@ pub fn unionAbiAlignment(mod: *Module, u: InternPool.UnionType) Alignment {
63116311 const ip = &mod.intern_pool;
63126312 const have_tag = u.flagsPtr(ip).runtime_tag.hasTag();
63136313 var max_align: Alignment = .none;
6314 if (have_tag) max_align = u.enum_tag_ty.toType().abiAlignment(mod);
6314 if (have_tag) max_align = Type.fromInterned(u.enum_tag_ty).abiAlignment(mod);
63156315 for (u.field_types.get(ip), 0..) |field_ty, field_index| {
6316 if (!field_ty.toType().hasRuntimeBits(mod)) continue;
6316 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
63176317
63186318 const field_align = mod.unionFieldNormalAlignment(u, @intCast(field_index));
63196319 max_align = max_align.max(field_align);
......@@ -6328,7 +6328,7 @@ pub fn unionFieldNormalAlignment(mod: *Module, u: InternPool.UnionType, field_in
63286328 const ip = &mod.intern_pool;
63296329 const field_align = u.fieldAlign(ip, field_index);
63306330 if (field_align != .none) return field_align;
6331 const field_ty = u.field_types.get(ip)[field_index].toType();
6331 const field_ty = Type.fromInterned(u.field_types.get(ip)[field_index]);
63326332 return field_ty.abiAlignment(mod);
63336333}
63346334
......@@ -6396,7 +6396,7 @@ pub fn structPackedFieldBitOffset(
63966396 if (i == field_index) {
63976397 return @intCast(bit_sum);
63986398 }
6399 const field_ty = struct_type.field_types.get(ip)[i].toType();
6399 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
64006400 bit_sum += field_ty.bitSize(mod);
64016401 }
64026402 unreachable; // index out of bounds
src/RangeSet.zig+8-6
......@@ -3,6 +3,8 @@ const assert = std.debug.assert;
33const Order = std.math.Order;
44
55const InternPool = @import("InternPool.zig");
6const Type = @import("type.zig").Type;
7const Value = @import("value.zig").Value;
68const Module = @import("Module.zig");
79const RangeSet = @This();
810const SwitchProngSrc = @import("Module.zig").SwitchProngSrc;
......@@ -43,8 +45,8 @@ pub fn add(
4345 assert(ty == ip.typeOf(range.first));
4446 assert(ty == ip.typeOf(range.last));
4547
46 if (last.toValue().compareScalar(.gte, range.first.toValue(), ty.toType(), mod) and
47 first.toValue().compareScalar(.lte, range.last.toValue(), ty.toType(), mod))
48 if (Value.fromInterned(last).compareScalar(.gte, Value.fromInterned(range.first), Type.fromInterned(ty), mod) and
49 Value.fromInterned(first).compareScalar(.lte, Value.fromInterned(range.last), Type.fromInterned(ty), mod))
4850 {
4951 return range.src; // They overlap.
5052 }
......@@ -60,8 +62,8 @@ pub fn add(
6062
6163/// Assumes a and b do not overlap
6264fn lessThan(mod: *Module, a: Range, b: Range) bool {
63 const ty = mod.intern_pool.typeOf(a.first).toType();
64 return a.first.toValue().compareScalar(.lt, b.first.toValue(), ty, mod);
65 const ty = Type.fromInterned(mod.intern_pool.typeOf(a.first));
66 return Value.fromInterned(a.first).compareScalar(.lt, Value.fromInterned(b.first), ty, mod);
6567}
6668
6769pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) !bool {
......@@ -91,10 +93,10 @@ pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) !
9193 const prev = self.ranges.items[i];
9294
9395 // prev.last + 1 == cur.first
94 try counter.copy(prev.last.toValue().toBigInt(&space, mod));
96 try counter.copy(Value.fromInterned(prev.last).toBigInt(&space, mod));
9597 try counter.addScalar(&counter, 1);
9698
97 const cur_start_int = cur.first.toValue().toBigInt(&space, mod);
99 const cur_start_int = Value.fromInterned(cur.first).toBigInt(&space, mod);
98100 if (!cur_start_int.eql(counter.toConst())) {
99101 return false;
100102 }
src/Sema.zig+424-424
......@@ -2153,13 +2153,13 @@ fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Val
21532153 assert(inst != .none);
21542154 // First section of indexes correspond to a set number of constant values.
21552155 if (@intFromEnum(inst) < InternPool.static_len) {
2156 return @as(InternPool.Index, @enumFromInt(@intFromEnum(inst))).toValue();
2156 return Value.fromInterned(@as(InternPool.Index, @enumFromInt(@intFromEnum(inst))));
21572157 }
21582158
21592159 const air_tags = sema.air_instructions.items(.tag);
21602160 if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| {
21612161 if (Air.refToInterned(inst)) |ip_index| {
2162 const val = ip_index.toValue();
2162 const val = Value.fromInterned(ip_index);
21632163 if (val.getVariable(sema.mod) != null) return val;
21642164 }
21652165 return opv;
......@@ -2171,7 +2171,7 @@ fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Val
21712171 else => return null,
21722172 }
21732173 };
2174 const val = ip_index.toValue();
2174 const val = Value.fromInterned(ip_index);
21752175 if (val.isPtrToThreadLocal(sema.mod)) return null;
21762176 return val;
21772177}
......@@ -2364,7 +2364,7 @@ fn typeSupportsFieldAccess(mod: *const Module, ty: Type, field_name: InternPool.
23642364 const ptr_info = ty.ptrInfo(mod);
23652365 if (ptr_info.flags.size == .Slice) {
23662366 return ip.stringEqlSlice(field_name, "ptr") or ip.stringEqlSlice(field_name, "len");
2367 } else if (ptr_info.child.toType().zigTypeTag(mod) == .Array) {
2367 } else if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {
23682368 return ip.stringEqlSlice(field_name, "len");
23692369 } else return false;
23702370 },
......@@ -2752,8 +2752,8 @@ fn zirStructDecl(
27522752 //errdefer ip.remove(struct_ty);
27532753
27542754 new_decl.ty = Type.type;
2755 new_decl.val = struct_ty.toValue();
2756 new_namespace.ty = struct_ty.toType();
2755 new_decl.val = Value.fromInterned(struct_ty);
2756 new_namespace.ty = Type.fromInterned(struct_ty);
27572757
27582758 const decl_val = sema.analyzeDeclVal(block, src, new_decl_index);
27592759 try mod.finalizeAnonDecl(new_decl_index);
......@@ -2959,8 +2959,8 @@ fn zirEnumDecl(
29592959 //errdefer if (!done) mod.intern_pool.remove(incomplete_enum.index);
29602960
29612961 new_decl.ty = Type.type;
2962 new_decl.val = incomplete_enum.index.toValue();
2963 new_namespace.ty = incomplete_enum.index.toType();
2962 new_decl.val = Value.fromInterned(incomplete_enum.index);
2963 new_namespace.ty = Type.fromInterned(incomplete_enum.index);
29642964
29652965 const decl_val = try sema.analyzeDeclVal(block, src, new_decl_index);
29662966 try mod.finalizeAnonDecl(new_decl_index);
......@@ -3222,8 +3222,8 @@ fn zirUnionDecl(
32223222 //errdefer mod.intern_pool.remove(union_ty);
32233223
32243224 new_decl.ty = Type.type;
3225 new_decl.val = union_ty.toValue();
3226 new_namespace.ty = union_ty.toType();
3225 new_decl.val = Value.fromInterned(union_ty);
3226 new_namespace.ty = Type.fromInterned(union_ty);
32273227
32283228 _ = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl);
32293229
......@@ -3285,8 +3285,8 @@ fn zirOpaqueDecl(
32853285 //errdefer mod.intern_pool.remove(opaque_ty);
32863286
32873287 new_decl.ty = Type.type;
3288 new_decl.val = opaque_ty.toValue();
3289 new_namespace.ty = opaque_ty.toType();
3288 new_decl.val = Value.fromInterned(opaque_ty);
3289 new_namespace.ty = Type.fromInterned(opaque_ty);
32903290
32913291 extra_index = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl);
32923292
......@@ -3600,7 +3600,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
36003600 const alloc = try sema.resolveInst(inst_data.operand);
36013601 const alloc_ty = sema.typeOf(alloc);
36023602 const ptr_info = alloc_ty.ptrInfo(mod);
3603 const elem_ty = ptr_info.child.toType();
3603 const elem_ty = Type.fromInterned(ptr_info.child);
36043604
36053605 if (try sema.resolveComptimeKnownAllocValue(block, alloc, null)) |val| {
36063606 const new_mut_ptr = Air.internedToRef((try mod.intern(.{ .ptr = .{
......@@ -3652,7 +3652,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
36523652
36533653 const alloc_ty = resolved_alloc_ty orelse sema.typeOf(alloc);
36543654 const ptr_info = alloc_ty.ptrInfo(mod);
3655 const elem_ty = ptr_info.child.toType();
3655 const elem_ty = Type.fromInterned(ptr_info.child);
36563656
36573657 const alloc_inst = Air.refToIndex(alloc) orelse return null;
36583658 const comptime_info = sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return null;
......@@ -3803,7 +3803,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
38033803 .index = field_idx,
38043804 } },
38053805 } }),
3806 .elem => |elem_idx| (try decl_parent_ptr.toValue().elemPtr(new_ptr_ty.toType(), @intCast(elem_idx), mod)).toIntern(),
3806 .elem => |elem_idx| (try Value.fromInterned(decl_parent_ptr).elemPtr(Type.fromInterned(new_ptr_ty), @intCast(elem_idx), mod)).toIntern(),
38073807 };
38083808 try ptr_mapping.put(air_ptr, new_ptr);
38093809 }
......@@ -3823,7 +3823,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
38233823 if (try sema.typeHasOnePossibleValue(payload_ty)) |payload_val| {
38243824 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
38253825 const store_val = try mod.unionValue(union_ty, tag_val, payload_val);
3826 try sema.storePtrVal(block, .unneeded, new_ptr.toValue(), store_val, union_ty);
3826 try sema.storePtrVal(block, .unneeded, Value.fromInterned(new_ptr), store_val, union_ty);
38273827 }
38283828 },
38293829 .store, .store_safe => {
......@@ -3831,14 +3831,14 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
38313831 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;
38323832 const store_val = (try sema.resolveValue(bin_op.rhs)).?;
38333833 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
3834 try sema.storePtrVal(block, .unneeded, new_ptr.toValue(), store_val, mod.intern_pool.typeOf(store_val.toIntern()).toType());
3834 try sema.storePtrVal(block, .unneeded, Value.fromInterned(new_ptr), store_val, Type.fromInterned(mod.intern_pool.typeOf(store_val.toIntern())));
38353835 },
38363836 else => unreachable,
38373837 }
38383838 }
38393839
38403840 // The value is finalized - load it!
3841 const val = (try sema.pointerDeref(block, .unneeded, decl_ptr.toValue(), alloc_ty)).?.toIntern();
3841 const val = (try sema.pointerDeref(block, .unneeded, Value.fromInterned(decl_ptr), alloc_ty)).?.toIntern();
38423842 return sema.finishResolveComptimeKnownAllocValue(val, alloc_inst, comptime_info.value);
38433843}
38443844
......@@ -6757,8 +6757,8 @@ fn checkCallArgumentCount(
67576757 .Fn => break :func_ty callee_ty,
67586758 .Pointer => {
67596759 const ptr_info = callee_ty.ptrInfo(mod);
6760 if (ptr_info.flags.size == .One and ptr_info.child.toType().zigTypeTag(mod) == .Fn) {
6761 break :func_ty ptr_info.child.toType();
6760 if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn) {
6761 break :func_ty Type.fromInterned(ptr_info.child);
67626762 }
67636763 },
67646764 .Optional => {
......@@ -6831,8 +6831,8 @@ fn callBuiltin(
68316831 .Fn => break :func_ty callee_ty,
68326832 .Pointer => {
68336833 const ptr_info = callee_ty.ptrInfo(mod);
6834 if (ptr_info.flags.size == .One and ptr_info.child.toType().zigTypeTag(mod) == .Fn) {
6835 break :func_ty ptr_info.child.toType();
6834 if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn) {
6835 break :func_ty Type.fromInterned(ptr_info.child);
68366836 }
68376837 },
68386838 else => {},
......@@ -7179,14 +7179,14 @@ fn analyzeCall(
71797179 var is_comptime_call = block.is_comptime or modifier == .compile_time;
71807180 var comptime_reason: ?*const Block.ComptimeReason = null;
71817181 if (!is_comptime_call) {
7182 if (sema.typeRequiresComptime(func_ty_info.return_type.toType())) |ct| {
7182 if (sema.typeRequiresComptime(Type.fromInterned(func_ty_info.return_type))) |ct| {
71837183 is_comptime_call = ct;
71847184 if (ct) {
71857185 comptime_reason = &.{ .comptime_ret_ty = .{
71867186 .block = block,
71877187 .func = func,
71887188 .func_src = func_src,
7189 .return_ty = func_ty_info.return_type.toType(),
7189 .return_ty = Type.fromInterned(func_ty_info.return_type),
71907190 } };
71917191 }
71927192 } else |err| switch (err) {
......@@ -7234,7 +7234,7 @@ fn analyzeCall(
72347234 .block = block,
72357235 .func = func,
72367236 .func_src = func_src,
7237 .return_ty = func_ty_info.return_type.toType(),
7237 .return_ty = Type.fromInterned(func_ty_info.return_type),
72387238 } };
72397239 },
72407240 else => |e| return e,
......@@ -7431,10 +7431,10 @@ fn analyzeCall(
74317431 const ies = try sema.arena.create(InferredErrorSet);
74327432 ies.* = .{ .func = .none };
74337433 sema.fn_ret_ty_ies = ies;
7434 sema.fn_ret_ty = (try ip.get(gpa, .{ .error_union_type = .{
7434 sema.fn_ret_ty = Type.fromInterned((try ip.get(gpa, .{ .error_union_type = .{
74357435 .error_set_type = .adhoc_inferred_error_set_type,
74367436 .payload_type = sema.fn_ret_ty.toIntern(),
7437 } })).toType();
7437 } })));
74387438 }
74397439
74407440 // This `res2` is here instead of directly breaking from `res` due to a stage1
......@@ -7529,7 +7529,7 @@ fn analyzeCall(
75297529 if (new_ty != .none) {
75307530 // TODO: mutate in place the previous instruction if possible
75317531 // rather than adding a bitcast instruction.
7532 break :res2 try block.addBitCast(new_ty.toType(), result);
7532 break :res2 try block.addBitCast(Type.fromInterned(new_ty), result);
75337533 }
75347534
75357535 break :res2 result;
......@@ -7543,8 +7543,8 @@ fn analyzeCall(
75437543 for (args, 0..) |*arg_out, arg_idx| {
75447544 // Non-generic, so param types are already resolved
75457545 const param_ty = if (arg_idx < func_ty_info.param_types.len) ty: {
7546 break :ty func_ty_info.param_types.get(ip)[arg_idx].toType();
7547 } else InternPool.Index.var_args_param_type.toType();
7546 break :ty Type.fromInterned(func_ty_info.param_types.get(ip)[arg_idx]);
7547 } else Type.fromInterned(InternPool.Index.var_args_param_type);
75487548 assert(!param_ty.isGenericPoison());
75497549 arg_out.* = try args_info.analyzeArg(sema, block, arg_idx, param_ty, func_ty_info, func);
75507550 if (sema.typeOf(arg_out.*).zigTypeTag(mod) == .NoReturn) {
......@@ -7554,8 +7554,8 @@ fn analyzeCall(
75547554
75557555 if (call_dbg_node) |some| try sema.zirDbgStmt(block, some);
75567556
7557 try sema.queueFullTypeResolution(func_ty_info.return_type.toType());
7558 if (sema.owner_func_index != .none and func_ty_info.return_type.toType().isError(mod)) {
7557 try sema.queueFullTypeResolution(Type.fromInterned(func_ty_info.return_type));
7558 if (sema.owner_func_index != .none and Type.fromInterned(func_ty_info.return_type).isError(mod)) {
75597559 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;
75607560 }
75617561
......@@ -7670,12 +7670,12 @@ fn analyzeInlineCallArg(
76707670 break :param_ty param_ty.toIntern();
76717671 };
76727672 new_param_types[arg_i.*] = param_ty;
7673 const casted_arg = try args_info.analyzeArg(ics.caller(), arg_block, arg_i.*, param_ty.toType(), func_ty_info, func_inst);
7673 const casted_arg = try args_info.analyzeArg(ics.caller(), arg_block, arg_i.*, Type.fromInterned(param_ty), func_ty_info, func_inst);
76747674 if (ics.caller().typeOf(casted_arg).zigTypeTag(mod) == .NoReturn) {
76757675 return casted_arg;
76767676 }
76777677 const arg_src = args_info.argSrc(arg_block, arg_i.*);
7678 if (try ics.callee().typeRequiresComptime(param_ty.toType())) {
7678 if (try ics.callee().typeRequiresComptime(Type.fromInterned(param_ty))) {
76797679 _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{
76807680 .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known",
76817681 .block_comptime_reason = param_block.comptime_reason,
......@@ -7705,7 +7705,7 @@ fn analyzeInlineCallArg(
77057705 // when the hash function is called.
77067706 const resolved_arg_val = try ics.caller().resolveLazyValue(arg_val);
77077707 should_memoize.* = should_memoize.* and !resolved_arg_val.canMutateComptimeVarState(mod);
7708 memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(param_ty.toType(), mod);
7708 memoized_arg_values[arg_i.*] = try resolved_arg_val.intern(Type.fromInterned(param_ty), mod);
77097709 } else {
77107710 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg);
77117711 }
......@@ -7790,7 +7790,7 @@ fn instantiateGenericCall(
77907790 else => unreachable,
77917791 };
77927792 const generic_owner_func = mod.intern_pool.indexToKey(generic_owner).func;
7793 const generic_owner_ty_info = mod.typeToFunc(generic_owner_func.ty.toType()).?;
7793 const generic_owner_ty_info = mod.typeToFunc(Type.fromInterned(generic_owner_func.ty)).?;
77947794
77957795 // Even though there may already be a generic instantiation corresponding
77967796 // to this callsite, we must evaluate the expressions of the generic
......@@ -7862,7 +7862,7 @@ fn instantiateGenericCall(
78627862 const param_tag = fn_zir.instructions.items(.tag)[@intFromEnum(param_inst)];
78637863
78647864 const param_ty = switch (generic_owner_ty_info.param_types.get(ip)[arg_index]) {
7865 else => |ty| ty.toType(), // parameter is not generic, so type is already resolved
7865 else => |ty| Type.fromInterned(ty), // parameter is not generic, so type is already resolved
78667866 .generic_poison_type => param_ty: {
78677867 // We have every parameter before this one, so can resolve this parameter's type now.
78687868 // However, first check the param type, since it may be anytype.
......@@ -7998,12 +7998,12 @@ fn instantiateGenericCall(
79987998 try sema.addReferencedBy(block, call_src, callee.owner_decl);
79997999
80008000 // Make a runtime call to the new function, making sure to omit the comptime args.
8001 const func_ty = callee.ty.toType();
8001 const func_ty = Type.fromInterned(callee.ty);
80028002 const func_ty_info = mod.typeToFunc(func_ty).?;
80038003
80048004 // If the call evaluated to a return type that requires comptime, never mind
80058005 // our generic instantiation. Instead we need to perform a comptime call.
8006 if (try sema.typeRequiresComptime(func_ty_info.return_type.toType())) {
8006 if (try sema.typeRequiresComptime(Type.fromInterned(func_ty_info.return_type))) {
80078007 return error.ComptimeReturn;
80088008 }
80098009 // Similarly, if the call evaluated to a generic type we need to instead
......@@ -8012,12 +8012,12 @@ fn instantiateGenericCall(
80128012 return error.GenericPoison;
80138013 }
80148014
8015 try sema.queueFullTypeResolution(func_ty_info.return_type.toType());
8015 try sema.queueFullTypeResolution(Type.fromInterned(func_ty_info.return_type));
80168016
80178017 if (call_dbg_node) |some| try sema.zirDbgStmt(block, some);
80188018
80198019 if (sema.owner_func_index != .none and
8020 func_ty_info.return_type.toType().isError(mod))
8020 Type.fromInterned(func_ty_info.return_type).isError(mod))
80218021 {
80228022 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;
80238023 }
......@@ -8057,10 +8057,10 @@ fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type)
80578057 else => return,
80588058 };
80598059 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, field_val| {
8060 try sema.resolveTupleLazyValues(block, src, field_ty.toType());
8060 try sema.resolveTupleLazyValues(block, src, Type.fromInterned(field_ty));
80618061 if (field_val == .none) continue;
80628062 // TODO: mutate in intern pool
8063 _ = try sema.resolveLazyValue(field_val.toValue());
8063 _ = try sema.resolveLazyValue(Value.fromInterned(field_val));
80648064 }
80658065}
80668066
......@@ -9217,7 +9217,7 @@ fn funcCommon(
92179217 const cc_resolved = cc orelse .Unspecified;
92189218 var comptime_bits: u32 = 0;
92199219 for (block.params.items(.ty), block.params.items(.is_comptime), 0..) |param_ty_ip, param_is_comptime, i| {
9220 const param_ty = param_ty_ip.toType();
9220 const param_ty = Type.fromInterned(param_ty_ip);
92219221 const is_noalias = blk: {
92229222 const index = std.math.cast(u5, i) orelse break :blk false;
92239223 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;
......@@ -9529,7 +9529,7 @@ fn finishFunc(
95299529 const return_type: Type = if (opt_func_index == .none or ret_poison)
95309530 bare_return_type
95319531 else
9532 ip.funcTypeReturnType(ip.typeOf(opt_func_index)).toType();
9532 Type.fromInterned(ip.funcTypeReturnType(ip.typeOf(opt_func_index)));
95339533
95349534 if (!return_type.isValidReturnType(mod)) {
95359535 const opaque_str = if (return_type.zigTypeTag(mod) == .Opaque) "opaque " else "";
......@@ -10078,10 +10078,10 @@ fn intCast(
1007810078 // range to account for negative values.
1007910079 const dest_range_val = if (wanted_info.signedness == .signed) range_val: {
1008010080 const one_scalar = try mod.intValue(unsigned_scalar_operand_ty, 1);
10081 const one = if (is_vector) (try mod.intern(.{ .aggregate = .{
10081 const one = if (is_vector) Value.fromInterned((try mod.intern(.{ .aggregate = .{
1008210082 .ty = unsigned_operand_ty.toIntern(),
1008310083 .storage = .{ .repeated_elem = one_scalar.toIntern() },
10084 } })).toValue() else one_scalar;
10084 } }))) else one_scalar;
1008510085 const range_minus_one = try dest_max_val.shl(one, unsigned_operand_ty, sema.arena, mod);
1008610086 break :range_val try sema.intAdd(range_minus_one, one, unsigned_operand_ty, undefined);
1008710087 } else try mod.getCoerced(dest_max_val, unsigned_operand_ty);
......@@ -10734,7 +10734,7 @@ const SwitchProngAnalysis = struct {
1073410734 if (operand_ty.zigTypeTag(mod) == .Union) {
1073510735 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?);
1073610736 const union_obj = mod.typeToUnion(operand_ty).?;
10737 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
10737 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
1073810738 if (capture_byref) {
1073910739 const ptr_field_ty = try sema.ptrType(.{
1074010740 .child = field_ty.toIntern(),
......@@ -10790,7 +10790,7 @@ const SwitchProngAnalysis = struct {
1079010790 const first_item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
1079110791
1079210792 const first_field_index: u32 = mod.unionTagFieldIndex(union_obj, first_item_val).?;
10793 const first_field_ty = union_obj.field_types.get(ip)[first_field_index].toType();
10793 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_field_index]);
1079410794
1079510795 const field_indices = try sema.arena.alloc(u32, case_vals.len);
1079610796 for (case_vals, field_indices) |item, *field_idx| {
......@@ -10801,7 +10801,7 @@ const SwitchProngAnalysis = struct {
1080110801 // Fast path: if all the operands are the same type already, we don't need to hit
1080210802 // PTR! This will also allow us to emit simpler code.
1080310803 const same_types = for (field_indices[1..]) |field_idx| {
10804 const field_ty = union_obj.field_types.get(ip)[field_idx].toType();
10804 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
1080510805 if (!field_ty.eql(first_field_ty, sema.mod)) break false;
1080610806 } else true;
1080710807
......@@ -10809,7 +10809,7 @@ const SwitchProngAnalysis = struct {
1080910809 // We need values to run PTR on, so make a bunch of undef constants.
1081010810 const dummy_captures = try sema.arena.alloc(Air.Inst.Ref, case_vals.len);
1081110811 for (dummy_captures, field_indices) |*dummy, field_idx| {
10812 const field_ty = union_obj.field_types.get(ip)[field_idx].toType();
10812 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
1081310813 dummy.* = try mod.undefRef(field_ty);
1081410814 }
1081510815
......@@ -10857,7 +10857,7 @@ const SwitchProngAnalysis = struct {
1085710857 // pointer type is in-memory coercible to the capture pointer type.
1085810858 if (!same_types) {
1085910859 for (field_indices, 0..) |field_idx, i| {
10860 const field_ty = union_obj.field_types.get(ip)[field_idx].toType();
10860 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
1086110861 const field_ptr_ty = try sema.ptrType(.{
1086210862 .child = field_ty.toIntern(),
1086310863 .flags = .{
......@@ -10906,7 +10906,7 @@ const SwitchProngAnalysis = struct {
1090610906 if (try sema.resolveDefinedValue(block, operand_src, spa.operand)) |operand_val| {
1090710907 if (operand_val.isUndef(mod)) return mod.undefRef(capture_ty);
1090810908 const union_val = ip.indexToKey(operand_val.toIntern()).un;
10909 if (union_val.tag.toValue().isUndef(mod)) return mod.undefRef(capture_ty);
10909 if (Value.fromInterned(union_val.tag).isUndef(mod)) return mod.undefRef(capture_ty);
1091010910 const uncoerced = Air.internedToRef(union_val.val);
1091110911 return sema.coerce(block, capture_ty, uncoerced, operand_src);
1091210912 }
......@@ -10921,7 +10921,7 @@ const SwitchProngAnalysis = struct {
1092110921 // If we can, try to avoid that using in-memory coercions.
1092210922 const first_non_imc = in_mem: {
1092310923 for (field_indices, 0..) |field_idx, i| {
10924 const field_ty = union_obj.field_types.get(ip)[field_idx].toType();
10924 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
1092510925 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, sema.mod.getTarget(), .unneeded, .unneeded)) {
1092610926 break :in_mem i;
1092710927 }
......@@ -10944,7 +10944,7 @@ const SwitchProngAnalysis = struct {
1094410944 {
1094510945 const next = first_non_imc + 1;
1094610946 for (field_indices[next..], next..) |field_idx, i| {
10947 const field_ty = union_obj.field_types.get(ip)[field_idx].toType();
10947 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
1094810948 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, sema.mod.getTarget(), .unneeded, .unneeded)) {
1094910949 in_mem_coercible.unset(i);
1095010950 }
......@@ -10975,7 +10975,7 @@ const SwitchProngAnalysis = struct {
1097510975 defer coerce_block.instructions.deinit(sema.gpa);
1097610976
1097710977 const field_idx = field_indices[idx];
10978 const field_ty = union_obj.field_types.get(ip)[field_idx].toType();
10978 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_idx]);
1097910979 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, field_idx, field_ty);
1098010980 const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) {
1098110981 error.NeededSourceLocation => {
......@@ -11004,7 +11004,7 @@ const SwitchProngAnalysis = struct {
1100411004
1100511005 const first_imc_item_idx = in_mem_coercible.findFirstSet().?;
1100611006 const first_imc_field_idx = field_indices[first_imc_item_idx];
11007 const first_imc_field_ty = union_obj.field_types.get(ip)[first_imc_field_idx].toType();
11007 const first_imc_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[first_imc_field_idx]);
1100811008 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, first_imc_field_idx, first_imc_field_ty);
1100911009 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);
1101011010 _ = try coerce_block.addBr(capture_block_inst, coerced);
......@@ -12510,7 +12510,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
1251012510 for (seen_enum_fields, 0..) |seen_field, index| {
1251112511 if (seen_field != null) continue;
1251212512 const union_obj = mod.typeToUnion(maybe_union_ty).?;
12513 const field_ty = union_obj.field_types.get(ip)[index].toType();
12513 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[index]);
1251412514 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
1251512515 } else false
1251612516 else
......@@ -12609,7 +12609,7 @@ const RangeSetUnhandledIterator = struct {
1260912609 inline .u64, .i64 => |val_int| {
1261012610 const next_int = @addWithOverflow(val_int, 1);
1261112611 if (next_int[1] == 0)
12612 return (try it.mod.intValue(int.ty.toType(), next_int[0])).toIntern();
12612 return (try it.mod.intValue(Type.fromInterned(int.ty), next_int[0])).toIntern();
1261312613 },
1261412614 .big_int => {},
1261512615 .lazy_align, .lazy_size => unreachable,
......@@ -12625,7 +12625,7 @@ const RangeSetUnhandledIterator = struct {
1262512625 );
1262612626
1262712627 result_bigint.addScalar(val_bigint, 1);
12628 return (try it.mod.intValue_big(int.ty.toType(), result_bigint.toConst())).toIntern();
12628 return (try it.mod.intValue_big(Type.fromInterned(int.ty), result_bigint.toConst())).toIntern();
1262912629 }
1263012630
1263112631 fn next(it: *RangeSetUnhandledIterator) !?InternPool.Index {
......@@ -12704,7 +12704,7 @@ fn validateSwitchRange(
1270412704 const mod = sema.mod;
1270512705 const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, src_node_offset, switch_prong_src, .first);
1270612706 const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, src_node_offset, switch_prong_src, .last);
12707 if (try first.val.toValue().compareAll(.gt, last.val.toValue(), operand_ty, mod)) {
12707 if (try Value.fromInterned(first.val).compareAll(.gt, Value.fromInterned(last.val), operand_ty, mod)) {
1270812708 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), src_node_offset, .first);
1270912709 return sema.fail(block, src, "range start value is greater than the end value", .{});
1271012710 }
......@@ -12815,7 +12815,7 @@ fn validateSwitchItemBool(
1281512815) CompileError!Air.Inst.Ref {
1281612816 const mod = sema.mod;
1281712817 const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, src_node_offset, switch_prong_src, .none);
12818 if (item.val.toValue().toBool()) {
12818 if (Value.fromInterned(item.val).toBool()) {
1281912819 true_count.* += 1;
1282012820 } else {
1282112821 false_count.* += 1;
......@@ -13645,7 +13645,7 @@ fn analyzeTupleCat(
1364513645 try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty);
1364613646 }
1364713647
13648 return block.addAggregateInit(tuple_ty.toType(), element_refs);
13648 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);
1364913649}
1365013650
1365113651fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -13875,17 +13875,17 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
1387513875 .needed_comptime_reason = "slice value being concatenated must be comptime-known",
1387613876 });
1387713877 return Type.ArrayInfo{
13878 .elem_type = ptr_info.child.toType(),
13878 .elem_type = Type.fromInterned(ptr_info.child),
1387913879 .sentinel = switch (ptr_info.sentinel) {
1388013880 .none => null,
13881 else => ptr_info.sentinel.toValue(),
13881 else => Value.fromInterned(ptr_info.sentinel),
1388213882 },
1388313883 .len = val.sliceLen(mod),
1388413884 };
1388513885 },
1388613886 .One => {
13887 if (ptr_info.child.toType().zigTypeTag(mod) == .Array) {
13888 return ptr_info.child.toType().arrayInfo(mod);
13887 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {
13888 return Type.fromInterned(ptr_info.child).arrayInfo(mod);
1388913889 }
1389013890 },
1389113891 .C => {},
......@@ -13974,7 +13974,7 @@ fn analyzeTupleMul(
1397413974 @memcpy(element_refs[tuple_len * i ..][0..tuple_len], element_refs[0..tuple_len]);
1397513975 }
1397613976
13977 return block.addAggregateInit(tuple_ty.toType(), element_refs);
13977 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);
1397813978}
1397913979
1398013980fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -14972,10 +14972,10 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1497214972 .ComptimeInt, .Int => try mod.intValue(resolved_type.scalarType(mod), 0),
1497314973 else => unreachable,
1497414974 };
14975 const zero_val = if (is_vector) (try mod.intern(.{ .aggregate = .{
14975 const zero_val = if (is_vector) Value.fromInterned((try mod.intern(.{ .aggregate = .{
1497614976 .ty = resolved_type.toIntern(),
1497714977 .storage = .{ .repeated_elem = scalar_zero.toIntern() },
14978 } })).toValue() else scalar_zero;
14978 } }))) else scalar_zero;
1497914979 return Air.internedToRef(zero_val.toIntern());
1498014980 }
1498114981 } else if (lhs_scalar_ty.isSignedInt(mod)) {
......@@ -15058,10 +15058,10 @@ fn intRem(
1505815058 const rhs_elem = try rhs.elemValue(mod, i);
1505915059 scalar.* = try (try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod);
1506015060 }
15061 return (try mod.intern(.{ .aggregate = .{
15061 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
1506215062 .ty = ty.toIntern(),
1506315063 .storage = .{ .elems = result_data },
15064 } })).toValue();
15064 } })));
1506515065 }
1506615066 return sema.intRemScalar(lhs, rhs, ty);
1506715067}
......@@ -15335,7 +15335,7 @@ fn zirOverflowArithmetic(
1533515335 const maybe_rhs_val = try sema.resolveValue(rhs);
1533615336
1533715337 const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty);
15338 const overflow_ty = ip.indexToKey(tuple_ty.toIntern()).anon_struct_type.types.get(ip)[1].toType();
15338 const overflow_ty = Type.fromInterned(ip.indexToKey(tuple_ty.toIntern()).anon_struct_type.types.get(ip)[1]);
1533915339
1534015340 var result: struct {
1534115341 inst: Air.Inst.Ref = .none,
......@@ -15504,7 +15504,7 @@ fn splat(sema: *Sema, ty: Type, val: Value) !Value {
1550415504 .ty = ty.toIntern(),
1550515505 .storage = .{ .repeated_elem = val.toIntern() },
1550615506 } });
15507 return repeated.toValue();
15507 return Value.fromInterned(repeated);
1550815508}
1550915509
1551015510fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
......@@ -15522,7 +15522,7 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
1552215522 .values = &values,
1552315523 .names = &.{},
1552415524 });
15525 return tuple_ty.toType();
15525 return Type.fromInterned(tuple_ty);
1552615526}
1552715527
1552815528fn analyzeArithmetic(
......@@ -16036,7 +16036,7 @@ fn analyzePtrArithmetic(
1603616036 }
1603716037 // If the addend is not a comptime-known value we can still count on
1603816038 // it being a multiple of the type size.
16039 const elem_size = ptr_info.child.toType().abiSize(mod);
16039 const elem_size = Type.fromInterned(ptr_info.child).abiSize(mod);
1604016040 const addend = if (opt_off_val) |off_val| a: {
1604116041 const off_int = try sema.usizeCast(block, offset_src, off_val.toUnsignedInt(mod));
1604216042 break :a elem_size * off_int;
......@@ -16073,7 +16073,7 @@ fn analyzePtrArithmetic(
1607316073 const offset_int = try sema.usizeCast(block, offset_src, offset_val.toUnsignedInt(mod));
1607416074 if (offset_int == 0) return ptr;
1607516075 if (try ptr_val.getUnsignedIntAdvanced(mod, sema)) |addr| {
16076 const elem_size = ptr_info.child.toType().abiSize(mod);
16076 const elem_size = Type.fromInterned(ptr_info.child).abiSize(mod);
1607716077 const new_addr = switch (air_tag) {
1607816078 .ptr_add => addr + elem_size * offset_int,
1607916079 .ptr_sub => addr - elem_size * offset_int,
......@@ -16748,7 +16748,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1674816748
1674916749 assert(block.is_typeof);
1675016750 // We need a dummy runtime instruction with the correct type.
16751 return block.addTy(.alloc, capture_ty.toType());
16751 return block.addTy(.alloc, Type.fromInterned(capture_ty));
1675216752}
1675316753
1675416754fn zirRetAddr(
......@@ -17042,7 +17042,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1704217042 const alignment = if (info.flags.alignment.toByteUnitsOptional()) |alignment|
1704317043 try mod.intValue(Type.comptime_int, alignment)
1704417044 else
17045 try info.child.toType().lazyAbiAlignment(mod);
17045 try Type.fromInterned(info.child).lazyAbiAlignment(mod);
1704617046
1704717047 const addrspace_ty = try sema.getBuiltinType("AddressSpace");
1704817048 const pointer_ty = t: {
......@@ -17086,7 +17086,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1708617086 // sentinel: ?*const anyopaque,
1708717087 (try sema.optRefValue(switch (info.sentinel) {
1708817088 .none => null,
17089 else => info.sentinel.toValue(),
17089 else => Value.fromInterned(info.sentinel),
1709017090 })).toIntern(),
1709117091 };
1709217092 return Air.internedToRef((try mod.intern(.{ .un = .{
......@@ -17630,10 +17630,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1763017630 } });
1763117631 };
1763217632
17633 try sema.resolveTypeLayout(field_ty.toType());
17633 try sema.resolveTypeLayout(Type.fromInterned(field_ty));
1763417634
1763517635 const is_comptime = field_val != .none;
17636 const opt_default_val = if (is_comptime) field_val.toValue() else null;
17636 const opt_default_val = if (is_comptime) Value.fromInterned(field_val) else null;
1763717637 const default_val_ptr = try sema.optRefValue(opt_default_val);
1763817638 const struct_field_fields = .{
1763917639 // name: []const u8,
......@@ -17645,7 +17645,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1764517645 // is_comptime: bool,
1764617646 Value.makeBool(is_comptime).toIntern(),
1764717647 // alignment: comptime_int,
17648 (try mod.intValue(Type.comptime_int, field_ty.toType().abiAlignment(mod).toByteUnits(0))).toIntern(),
17648 (try mod.intValue(Type.comptime_int, Type.fromInterned(field_ty).abiAlignment(mod).toByteUnits(0))).toIntern(),
1764917649 };
1765017650 struct_field_val.* = try mod.intern(.{ .aggregate = .{
1765117651 .ty = struct_field_ty.toIntern(),
......@@ -17667,7 +17667,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1766717667 try sema.arena.dupe(u8, ip.stringToSlice(name_nts))
1766817668 else
1766917669 try std.fmt.allocPrintZ(sema.arena, "{d}", .{i});
17670 const field_ty = struct_type.field_types.get(ip)[i].toType();
17670 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
1767117671 const field_init = struct_type.fieldInit(ip, i);
1767217672 const field_is_comptime = struct_type.fieldIsComptime(ip, i);
1767317673 const name_val = v: {
......@@ -17689,7 +17689,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1768917689 } });
1769017690 };
1769117691
17692 const opt_default_val = if (field_init == .none) null else field_init.toValue();
17692 const opt_default_val = if (field_init == .none) null else Value.fromInterned(field_init);
1769317693 const default_val_ptr = try sema.optRefValue(opt_default_val);
1769417694 const alignment = switch (struct_type.layout) {
1769517695 .Packed => .none,
......@@ -17750,7 +17750,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1775017750 const backing_integer_val = try mod.intern(.{ .opt = .{
1775117751 .ty = (try mod.optionalType(.type_type)).toIntern(),
1775217752 .val = if (mod.typeToPackedStruct(ty)) |packed_struct| val: {
17753 assert(packed_struct.backingIntType(ip).toType().isInt(mod));
17753 assert(Type.fromInterned(packed_struct.backingIntType(ip).*).isInt(mod));
1775417754 break :val packed_struct.backingIntType(ip).*;
1775517755 } else .none,
1775617756 } });
......@@ -19145,7 +19145,7 @@ fn unionInit(
1914519145 const mod = sema.mod;
1914619146 const ip = &mod.intern_pool;
1914719147 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src);
19148 const field_ty = mod.typeToUnion(union_ty).?.field_types.get(ip)[field_index].toType();
19148 const field_ty = Type.fromInterned(mod.typeToUnion(union_ty).?.field_types.get(ip)[field_index]);
1914919149 const init = try sema.coerce(block, field_ty, uncasted_init, init_src);
1915019150
1915119151 if (try sema.resolveValue(init)) |init_val| {
......@@ -19256,7 +19256,7 @@ fn zirStructInit(
1925619256 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
1925719257 const tag_ty = resolved_ty.unionTagTypeHypothetical(mod);
1925819258 const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index);
19259 const field_ty = mod.typeToUnion(resolved_ty).?.field_types.get(ip)[field_index].toType();
19259 const field_ty = Type.fromInterned(mod.typeToUnion(resolved_ty).?.field_types.get(ip)[field_index]);
1926019260
1926119261 if (field_ty.zigTypeTag(mod) == .NoReturn) {
1926219262 return sema.failWithOwnedErrorMsg(block, msg: {
......@@ -19275,11 +19275,11 @@ fn zirStructInit(
1927519275 const init_inst = try sema.coerce(block, field_ty, uncoerced_init_inst, field_src);
1927619276
1927719277 if (try sema.resolveValue(init_inst)) |val| {
19278 const struct_val = (try mod.intern(.{ .un = .{
19278 const struct_val = Value.fromInterned((try mod.intern(.{ .un = .{
1927919279 .ty = resolved_ty.toIntern(),
1928019280 .tag = try tag_val.intern(tag_ty, mod),
1928119281 .val = try val.intern(field_ty, mod),
19282 } })).toValue();
19282 } })));
1928319283 const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val.toIntern()), src);
1928419284 const final_val = (try sema.resolveValue(final_val_inst)).?;
1928519285 return sema.addConstantMaybeRef(final_val.toIntern(), is_ref);
......@@ -19336,7 +19336,7 @@ fn finishStructInit(
1933619336 for (0..anon_struct.types.len) |i| {
1933719337 if (field_inits[i] != .none) {
1933819338 // Coerce the init value to the field type.
19339 const field_ty = anon_struct.types.get(ip)[i].toType();
19339 const field_ty = Type.fromInterned(anon_struct.types.get(ip)[i]);
1934019340 field_inits[i] = sema.coerce(block, field_ty, field_inits[i], .unneeded) catch |err| switch (err) {
1934119341 error.NeededSourceLocation => {
1934219342 const decl = mod.declPtr(block.src_decl);
......@@ -19378,7 +19378,7 @@ fn finishStructInit(
1937819378 for (0..struct_type.field_types.len) |i| {
1937919379 if (field_inits[i] != .none) {
1938019380 // Coerce the init value to the field type.
19381 const field_ty = struct_type.field_types.get(ip)[i].toType();
19381 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
1938219382 field_inits[i] = sema.coerce(block, field_ty, field_inits[i], init_src) catch |err| switch (err) {
1938319383 error.NeededSourceLocation => {
1938419384 const decl = mod.declPtr(block.src_decl);
......@@ -19548,20 +19548,20 @@ fn structInitAnon(
1954819548
1954919549 const init = try sema.resolveInst(item.data.init);
1955019550 field_ty.* = sema.typeOf(init).toIntern();
19551 if (field_ty.toType().zigTypeTag(mod) == .Opaque) {
19551 if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) {
1955219552 const msg = msg: {
1955319553 const decl = mod.declPtr(block.src_decl);
1955419554 const field_src = mod.initSrc(src.node_offset.x, decl, @intCast(i_usize));
1955519555 const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
1955619556 errdefer msg.destroy(sema.gpa);
1955719557
19558 try sema.addDeclaredHereNote(msg, field_ty.toType());
19558 try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*));
1955919559 break :msg msg;
1956019560 };
1956119561 return sema.failWithOwnedErrorMsg(block, msg);
1956219562 }
1956319563 if (try sema.resolveValue(init)) |init_val| {
19564 field_val.* = try init_val.intern(field_ty.toType(), mod);
19564 field_val.* = try init_val.intern(Type.fromInterned(field_ty.*), mod);
1956519565 } else {
1956619566 field_val.* = .none;
1956719567 runtime_index = @intCast(i_usize);
......@@ -19635,7 +19635,7 @@ fn structInitAnon(
1963519635 element_refs[i] = try sema.resolveInst(item.data.init);
1963619636 }
1963719637
19638 return block.addAggregateInit(tuple_ty.toType(), element_refs);
19638 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);
1963919639}
1964019640
1964119641fn zirArrayInit(
......@@ -19836,12 +19836,12 @@ fn arrayInitAnon(
1983619836 const operand_src = src; // TODO better source location
1983719837 const elem = try sema.resolveInst(operand);
1983819838 types[i] = sema.typeOf(elem).toIntern();
19839 if (types[i].toType().zigTypeTag(mod) == .Opaque) {
19839 if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) {
1984019840 const msg = msg: {
1984119841 const msg = try sema.errMsg(block, operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
1984219842 errdefer msg.destroy(gpa);
1984319843
19844 try sema.addDeclaredHereNote(msg, types[i].toType());
19844 try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i]));
1984519845 break :msg msg;
1984619846 };
1984719847 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -19899,7 +19899,7 @@ fn arrayInitAnon(
1989919899 element_refs[i] = try sema.resolveInst(operand);
1990019900 }
1990119901
19902 return block.addAggregateInit(tuple_ty.toType(), element_refs);
19902 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);
1990319903}
1990419904
1990519905fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.Inst.Ref {
......@@ -19979,7 +19979,7 @@ fn fieldType(
1997919979 .Optional => {
1998019980 // Struct/array init through optional requires the child type to not be a pointer.
1998119981 // If the child of .optional is a pointer it'll error on the next loop.
19982 cur_ty = ip.indexToKey(cur_ty.toIntern()).opt_type.toType();
19982 cur_ty = Type.fromInterned(ip.indexToKey(cur_ty.toIntern()).opt_type);
1998319983 continue;
1998419984 },
1998519985 .ErrorUnion => {
......@@ -20294,8 +20294,8 @@ fn zirReify(
2029420294 });
2029520295 const union_val = ip.indexToKey(val.toIntern()).un;
2029620296 const target = mod.getTarget();
20297 if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src);
20298 const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag.toValue(), mod).?;
20297 if (try Value.fromInterned(union_val.val).anyUndef(mod)) return sema.failWithUseOfUndef(block, src);
20298 const tag_index = type_info_ty.unionTagFieldIndex(Value.fromInterned(union_val.tag), mod).?;
2029920299 switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) {
2030020300 .Type => return .type_type,
2030120301 .Void => return .void_type,
......@@ -20309,11 +20309,11 @@ fn zirReify(
2030920309 .EnumLiteral => return .enum_literal_type,
2031020310 .Int => {
2031120311 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;
20312 const signedness_val = try union_val.val.toValue().fieldValue(
20312 const signedness_val = try Value.fromInterned(union_val.val).fieldValue(
2031320313 mod,
2031420314 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "signedness")).?,
2031520315 );
20316 const bits_val = try union_val.val.toValue().fieldValue(
20316 const bits_val = try Value.fromInterned(union_val.val).fieldValue(
2031720317 mod,
2031820318 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "bits")).?,
2031920319 );
......@@ -20325,11 +20325,11 @@ fn zirReify(
2032520325 },
2032620326 .Vector => {
2032720327 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;
20328 const len_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20328 const len_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2032920329 ip,
2033020330 try ip.getOrPutString(gpa, "len"),
2033120331 ).?);
20332 const child_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20332 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2033320333 ip,
2033420334 try ip.getOrPutString(gpa, "child"),
2033520335 ).?);
......@@ -20347,7 +20347,7 @@ fn zirReify(
2034720347 },
2034820348 .Float => {
2034920349 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;
20350 const bits_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20350 const bits_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2035120351 ip,
2035220352 try ip.getOrPutString(gpa, "bits"),
2035320353 ).?);
......@@ -20365,35 +20365,35 @@ fn zirReify(
2036520365 },
2036620366 .Pointer => {
2036720367 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;
20368 const size_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20368 const size_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2036920369 ip,
2037020370 try ip.getOrPutString(gpa, "size"),
2037120371 ).?);
20372 const is_const_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20372 const is_const_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2037320373 ip,
2037420374 try ip.getOrPutString(gpa, "is_const"),
2037520375 ).?);
20376 const is_volatile_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20376 const is_volatile_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2037720377 ip,
2037820378 try ip.getOrPutString(gpa, "is_volatile"),
2037920379 ).?);
20380 const alignment_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20380 const alignment_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2038120381 ip,
2038220382 try ip.getOrPutString(gpa, "alignment"),
2038320383 ).?);
20384 const address_space_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20384 const address_space_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2038520385 ip,
2038620386 try ip.getOrPutString(gpa, "address_space"),
2038720387 ).?);
20388 const child_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20388 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2038920389 ip,
2039020390 try ip.getOrPutString(gpa, "child"),
2039120391 ).?);
20392 const is_allowzero_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20392 const is_allowzero_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2039320393 ip,
2039420394 try ip.getOrPutString(gpa, "is_allowzero"),
2039520395 ).?);
20396 const sentinel_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20396 const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2039720397 ip,
2039820398 try ip.getOrPutString(gpa, "sentinel"),
2039920399 ).?);
......@@ -20477,15 +20477,15 @@ fn zirReify(
2047720477 },
2047820478 .Array => {
2047920479 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;
20480 const len_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20480 const len_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2048120481 ip,
2048220482 try ip.getOrPutString(gpa, "len"),
2048320483 ).?);
20484 const child_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20484 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2048520485 ip,
2048620486 try ip.getOrPutString(gpa, "child"),
2048720487 ).?);
20488 const sentinel_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20488 const sentinel_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2048920489 ip,
2049020490 try ip.getOrPutString(gpa, "sentinel"),
2049120491 ).?);
......@@ -20506,7 +20506,7 @@ fn zirReify(
2050620506 },
2050720507 .Optional => {
2050820508 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;
20509 const child_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20509 const child_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2051020510 ip,
2051120511 try ip.getOrPutString(gpa, "child"),
2051220512 ).?);
......@@ -20518,11 +20518,11 @@ fn zirReify(
2051820518 },
2051920519 .ErrorUnion => {
2052020520 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;
20521 const error_set_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20521 const error_set_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2052220522 ip,
2052320523 try ip.getOrPutString(gpa, "error_set"),
2052420524 ).?);
20525 const payload_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20525 const payload_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2052620526 ip,
2052720527 try ip.getOrPutString(gpa, "payload"),
2052820528 ).?);
......@@ -20538,7 +20538,7 @@ fn zirReify(
2053820538 return Air.internedToRef(ty.toIntern());
2053920539 },
2054020540 .ErrorSet => {
20541 const payload_val = union_val.val.toValue().optionalValue(mod) orelse
20541 const payload_val = Value.fromInterned(union_val.val).optionalValue(mod) orelse
2054220542 return Air.internedToRef(Type.anyerror.toIntern());
2054320543
2054420544 const len = try sema.usizeCast(block, src, payload_val.sliceLen(mod));
......@@ -20567,23 +20567,23 @@ fn zirReify(
2056720567 },
2056820568 .Struct => {
2056920569 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;
20570 const layout_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20570 const layout_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2057120571 ip,
2057220572 try ip.getOrPutString(gpa, "layout"),
2057320573 ).?);
20574 const backing_integer_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20574 const backing_integer_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2057520575 ip,
2057620576 try ip.getOrPutString(gpa, "backing_integer"),
2057720577 ).?);
20578 const fields_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20578 const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2057920579 ip,
2058020580 try ip.getOrPutString(gpa, "fields"),
2058120581 ).?);
20582 const decls_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20582 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2058320583 ip,
2058420584 try ip.getOrPutString(gpa, "decls"),
2058520585 ).?);
20586 const is_tuple_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20586 const is_tuple_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2058720587 ip,
2058820588 try ip.getOrPutString(gpa, "is_tuple"),
2058920589 ).?);
......@@ -20603,19 +20603,19 @@ fn zirReify(
2060320603 },
2060420604 .Enum => {
2060520605 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;
20606 const tag_type_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20606 const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2060720607 ip,
2060820608 try ip.getOrPutString(gpa, "tag_type"),
2060920609 ).?);
20610 const fields_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20610 const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2061120611 ip,
2061220612 try ip.getOrPutString(gpa, "fields"),
2061320613 ).?);
20614 const decls_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20614 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2061520615 ip,
2061620616 try ip.getOrPutString(gpa, "decls"),
2061720617 ).?);
20618 const is_exhaustive_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20618 const is_exhaustive_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2061920619 ip,
2062020620 try ip.getOrPutString(gpa, "is_exhaustive"),
2062120621 ).?);
......@@ -20662,7 +20662,7 @@ fn zirReify(
2066220662 //errdefer ip.remove(incomplete_enum.index);
2066320663
2066420664 new_decl.ty = Type.type;
20665 new_decl.val = incomplete_enum.index.toValue();
20665 new_decl.val = Value.fromInterned(incomplete_enum.index);
2066620666
2066720667 for (0..fields_len) |field_i| {
2066820668 const elem_val = try fields_val.elemValue(mod, field_i);
......@@ -20718,7 +20718,7 @@ fn zirReify(
2071820718 },
2071920719 .Opaque => {
2072020720 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;
20721 const decls_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20721 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2072220722 ip,
2072320723 try ip.getOrPutString(gpa, "decls"),
2072420724 ).?);
......@@ -20759,8 +20759,8 @@ fn zirReify(
2075920759 //errdefer ip.remove(opaque_ty);
2076020760
2076120761 new_decl.ty = Type.type;
20762 new_decl.val = opaque_ty.toValue();
20763 new_namespace.ty = opaque_ty.toType();
20762 new_decl.val = Value.fromInterned(opaque_ty);
20763 new_namespace.ty = Type.fromInterned(opaque_ty);
2076420764
2076520765 const decl_val = sema.analyzeDeclVal(block, src, new_decl_index);
2076620766 try mod.finalizeAnonDecl(new_decl_index);
......@@ -20768,19 +20768,19 @@ fn zirReify(
2076820768 },
2076920769 .Union => {
2077020770 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;
20771 const layout_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20771 const layout_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2077220772 ip,
2077320773 try ip.getOrPutString(gpa, "layout"),
2077420774 ).?);
20775 const tag_type_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20775 const tag_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2077620776 ip,
2077720777 try ip.getOrPutString(gpa, "tag_type"),
2077820778 ).?);
20779 const fields_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20779 const fields_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2078020780 ip,
2078120781 try ip.getOrPutString(gpa, "fields"),
2078220782 ).?);
20783 const decls_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
20783 const decls_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2078420784 ip,
2078520785 try ip.getOrPutString(gpa, "decls"),
2078620786 ).?);
......@@ -20847,10 +20847,10 @@ fn zirReify(
2084720847 const msg = msg: {
2084820848 const msg = try sema.errMsg(block, src, "no field named '{}' in enum '{}'", .{
2084920849 field_name.fmt(ip),
20850 enum_tag_ty.toType().fmt(mod),
20850 Type.fromInterned(enum_tag_ty).fmt(mod),
2085120851 });
2085220852 errdefer msg.destroy(gpa);
20853 try sema.addDeclaredHereNote(msg, enum_tag_ty.toType());
20853 try sema.addDeclaredHereNote(msg, Type.fromInterned(enum_tag_ty));
2085420854 break :msg msg;
2085520855 };
2085620856 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -20929,11 +20929,11 @@ fn zirReify(
2092920929
2093020930 for (tag_info.names.get(ip), 0..) |field_name, field_index| {
2093120931 if (explicit_tags_seen[field_index]) continue;
20932 try sema.addFieldErrNote(enum_tag_ty.toType(), field_index, msg, "field '{}' missing, declared here", .{
20932 try sema.addFieldErrNote(Type.fromInterned(enum_tag_ty), field_index, msg, "field '{}' missing, declared here", .{
2093320933 field_name.fmt(ip),
2093420934 });
2093520935 }
20936 try sema.addDeclaredHereNote(msg, enum_tag_ty.toType());
20936 try sema.addDeclaredHereNote(msg, Type.fromInterned(enum_tag_ty));
2093720937 break :msg msg;
2093820938 };
2093920939 return sema.failWithOwnedErrorMsg(block, msg);
......@@ -20993,8 +20993,8 @@ fn zirReify(
2099320993 });
2099420994
2099520995 new_decl.ty = Type.type;
20996 new_decl.val = union_ty.toValue();
20997 new_namespace.ty = union_ty.toType();
20996 new_decl.val = Value.fromInterned(union_ty);
20997 new_namespace.ty = Type.fromInterned(union_ty);
2099820998
2099920999 const decl_val = sema.analyzeDeclVal(block, src, new_decl_index);
2100021000 try mod.finalizeAnonDecl(new_decl_index);
......@@ -21002,27 +21002,27 @@ fn zirReify(
2100221002 },
2100321003 .Fn => {
2100421004 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;
21005 const calling_convention_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
21005 const calling_convention_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2100621006 ip,
2100721007 try ip.getOrPutString(gpa, "calling_convention"),
2100821008 ).?);
21009 const alignment_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
21009 const alignment_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2101021010 ip,
2101121011 try ip.getOrPutString(gpa, "alignment"),
2101221012 ).?);
21013 const is_generic_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
21013 const is_generic_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2101421014 ip,
2101521015 try ip.getOrPutString(gpa, "is_generic"),
2101621016 ).?);
21017 const is_var_args_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
21017 const is_var_args_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2101821018 ip,
2101921019 try ip.getOrPutString(gpa, "is_var_args"),
2102021020 ).?);
21021 const return_type_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
21021 const return_type_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2102221022 ip,
2102321023 try ip.getOrPutString(gpa, "return_type"),
2102421024 ).?);
21025 const params_val = try union_val.val.toValue().fieldValue(mod, struct_type.nameIndex(
21025 const params_val = try Value.fromInterned(union_val.val).fieldValue(mod, struct_type.nameIndex(
2102621026 ip,
2102721027 try ip.getOrPutString(gpa, "params"),
2102821028 ).?);
......@@ -21075,7 +21075,7 @@ fn zirReify(
2107521075 param_type.* = param_type_val.toIntern();
2107621076
2107721077 if (param_is_noalias_val.toBool()) {
21078 if (!param_type.toType().isPtrAtRuntime(mod)) {
21078 if (!Type.fromInterned(param_type.*).isPtrAtRuntime(mod)) {
2107921079 return sema.fail(block, src, "non-pointer parameter declared noalias", .{});
2108021080 }
2108121081 noalias_bits |= @as(u32, 1) << (std.math.cast(u5, i) orelse
......@@ -21158,7 +21158,7 @@ fn reifyStruct(
2115821158 const struct_type = ip.indexToKey(ty).struct_type;
2115921159
2116021160 new_decl.ty = Type.type;
21161 new_decl.val = ty.toValue();
21161 new_decl.val = Value.fromInterned(ty);
2116221162
2116321163 // Fields
2116421164 for (0..fields_len) |i| {
......@@ -21290,11 +21290,11 @@ fn reifyStruct(
2129021290
2129121291 if (layout == .Packed) {
2129221292 for (0..struct_type.field_types.len) |index| {
21293 const field_ty = struct_type.field_types.get(ip)[index].toType();
21293 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[index]);
2129421294 sema.resolveTypeLayout(field_ty) catch |err| switch (err) {
2129521295 error.AnalysisFail => {
2129621296 const msg = sema.err orelse return err;
21297 try sema.addFieldErrNote(ty.toType(), index, msg, "while checking this field", .{});
21297 try sema.addFieldErrNote(Type.fromInterned(ty), index, msg, "while checking this field", .{});
2129821298 return err;
2129921299 },
2130021300 else => return err,
......@@ -21303,7 +21303,7 @@ fn reifyStruct(
2130321303
2130421304 var fields_bit_sum: u64 = 0;
2130521305 for (0..struct_type.field_types.len) |i| {
21306 const field_ty = struct_type.field_types.get(ip)[i].toType();
21306 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
2130721307 fields_bit_sum += field_ty.bitSize(mod);
2130821308 }
2130921309
......@@ -21657,10 +21657,10 @@ fn ptrFromIntVal(
2165721657 return sema.fail(block, operand_src, "pointer type '{}' requires aligned address", .{ptr_ty.fmt(sema.mod)});
2165821658
2165921659 return switch (ptr_ty.zigTypeTag(mod)) {
21660 .Optional => (try mod.intern(.{ .opt = .{
21660 .Optional => Value.fromInterned((try mod.intern(.{ .opt = .{
2166121661 .ty = ptr_ty.toIntern(),
2166221662 .val = if (addr == 0) .none else (try mod.ptrIntValue(ptr_ty.childType(mod), addr)).toIntern(),
21663 } })).toValue(),
21663 } }))),
2166421664 .Pointer => try mod.ptrIntValue(ptr_ty, addr),
2166521665 else => unreachable,
2166621666 };
......@@ -21849,14 +21849,14 @@ fn ptrCastFull(
2184921849 const src_info = operand_ty.ptrInfo(mod);
2185021850 const dest_info = dest_ty.ptrInfo(mod);
2185121851
21852 try sema.resolveTypeLayout(src_info.child.toType());
21853 try sema.resolveTypeLayout(dest_info.child.toType());
21852 try sema.resolveTypeLayout(Type.fromInterned(src_info.child));
21853 try sema.resolveTypeLayout(Type.fromInterned(dest_info.child));
2185421854
2185521855 const src_slice_like = src_info.flags.size == .Slice or
21856 (src_info.flags.size == .One and src_info.child.toType().zigTypeTag(mod) == .Array);
21856 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array);
2185721857
2185821858 const dest_slice_like = dest_info.flags.size == .Slice or
21859 (dest_info.flags.size == .One and dest_info.child.toType().zigTypeTag(mod) == .Array);
21859 (dest_info.flags.size == .One and Type.fromInterned(dest_info.child).zigTypeTag(mod) == .Array);
2186021860
2186121861 if (dest_info.flags.size == .Slice and !src_slice_like) {
2186221862 return sema.fail(block, src, "illegal pointer cast to slice", .{});
......@@ -21864,12 +21864,12 @@ fn ptrCastFull(
2186421864
2186521865 if (dest_info.flags.size == .Slice) {
2186621866 const src_elem_size = switch (src_info.flags.size) {
21867 .Slice => src_info.child.toType().abiSize(mod),
21867 .Slice => Type.fromInterned(src_info.child).abiSize(mod),
2186821868 // pointer to array
21869 .One => src_info.child.toType().childType(mod).abiSize(mod),
21869 .One => Type.fromInterned(src_info.child).childType(mod).abiSize(mod),
2187021870 else => unreachable,
2187121871 };
21872 const dest_elem_size = dest_info.child.toType().abiSize(mod);
21872 const dest_elem_size = Type.fromInterned(dest_info.child).abiSize(mod);
2187321873 if (src_elem_size != dest_elem_size) {
2187421874 return sema.fail(block, src, "TODO: implement @ptrCast between slices changing the length", .{});
2187521875 }
......@@ -21891,7 +21891,7 @@ fn ptrCastFull(
2189121891 errdefer msg.destroy(sema.gpa);
2189221892 if (dest_info.flags.size == .Many and
2189321893 (src_info.flags.size == .Slice or
21894 (src_info.flags.size == .One and src_info.child.toType().zigTypeTag(mod) == .Array)))
21894 (src_info.flags.size == .One and Type.fromInterned(src_info.child).zigTypeTag(mod) == .Array)))
2189521895 {
2189621896 try sema.errNote(block, src, msg, "use 'ptr' field to convert slice to many pointer", .{});
2189721897 } else {
......@@ -21904,10 +21904,10 @@ fn ptrCastFull(
2190421904 check_child: {
2190521905 const src_child = if (dest_info.flags.size == .Slice and src_info.flags.size == .One) blk: {
2190621906 // *[n]T -> []T
21907 break :blk src_info.child.toType().childType(mod);
21908 } else src_info.child.toType();
21907 break :blk Type.fromInterned(src_info.child).childType(mod);
21908 } else Type.fromInterned(src_info.child);
2190921909
21910 const dest_child = dest_info.child.toType();
21910 const dest_child = Type.fromInterned(dest_info.child);
2191121911
2191221912 const imc_res = try sema.coerceInMemoryAllowed(
2191321913 block,
......@@ -21940,7 +21940,7 @@ fn ptrCastFull(
2194021940 }
2194121941 if (src_slice_like and src_info.flags.size == .One and dest_info.flags.size == .Slice) {
2194221942 // [*]nT -> []T
21943 const arr_ty = src_info.child.toType();
21943 const arr_ty = Type.fromInterned(src_info.child);
2194421944 if (arr_ty.sentinel(mod)) |src_sentinel| {
2194521945 const coerced_sent = try mod.intern_pool.getCoerced(sema.gpa, src_sentinel.toIntern(), dest_info.child);
2194621946 if (dest_info.sentinel == coerced_sent) break :check_sent;
......@@ -21949,12 +21949,12 @@ fn ptrCastFull(
2194921949 return sema.failWithOwnedErrorMsg(block, msg: {
2195021950 const msg = if (src_info.sentinel == .none) blk: {
2195121951 break :blk try sema.errMsg(block, src, "destination pointer requires '{}' sentinel", .{
21952 dest_info.sentinel.toValue().fmtValue(dest_info.child.toType(), mod),
21952 Value.fromInterned(dest_info.sentinel).fmtValue(Type.fromInterned(dest_info.child), mod),
2195321953 });
2195421954 } else blk: {
2195521955 break :blk try sema.errMsg(block, src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{
21956 src_info.sentinel.toValue().fmtValue(src_info.child.toType(), mod),
21957 dest_info.sentinel.toValue().fmtValue(dest_info.child.toType(), mod),
21956 Value.fromInterned(src_info.sentinel).fmtValue(Type.fromInterned(src_info.child), mod),
21957 Value.fromInterned(dest_info.sentinel).fmtValue(Type.fromInterned(dest_info.child), mod),
2195821958 });
2195921959 };
2196021960 errdefer msg.destroy(sema.gpa);
......@@ -22010,12 +22010,12 @@ fn ptrCastFull(
2201022010 const src_align = if (src_info.flags.alignment != .none)
2201122011 src_info.flags.alignment
2201222012 else
22013 src_info.child.toType().abiAlignment(mod);
22013 Type.fromInterned(src_info.child).abiAlignment(mod);
2201422014
2201522015 const dest_align = if (dest_info.flags.alignment != .none)
2201622016 dest_info.flags.alignment
2201722017 else
22018 dest_info.child.toType().abiAlignment(mod);
22018 Type.fromInterned(dest_info.child).abiAlignment(mod);
2201922019
2202022020 if (!flags.align_cast) {
2202122021 if (dest_align.compare(.gt, src_align)) {
......@@ -22123,7 +22123,7 @@ fn ptrCastFull(
2212322123 }
2212422124 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {
2212522125 if (ptr_val.isUndef(mod)) return mod.undefRef(dest_ty);
22126 const arr_len = try mod.intValue(Type.usize, src_info.child.toType().arrayLen(mod));
22126 const arr_len = try mod.intValue(Type.usize, Type.fromInterned(src_info.child).arrayLen(mod));
2212722127 return Air.internedToRef((try mod.intern(.{ .ptr = .{
2212822128 .ty = dest_ty.toIntern(),
2212922129 .addr = mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr.addr,
......@@ -22139,7 +22139,7 @@ fn ptrCastFull(
2213922139 try sema.requireRuntimeBlock(block, src, null);
2214022140
2214122141 if (block.wantSafety() and operand_ty.ptrAllowsZero(mod) and !dest_ty.ptrAllowsZero(mod) and
22142 (try sema.typeHasRuntimeBits(dest_info.child.toType()) or dest_info.child.toType().zigTypeTag(mod) == .Fn))
22142 (try sema.typeHasRuntimeBits(Type.fromInterned(dest_info.child)) or Type.fromInterned(dest_info.child).zigTypeTag(mod) == .Fn))
2214322143 {
2214422144 const ptr_int = try block.addUnOp(.int_from_ptr, ptr);
2214522145 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);
......@@ -22153,7 +22153,7 @@ fn ptrCastFull(
2215322153
2215422154 if (block.wantSafety() and
2215522155 dest_align.compare(.gt, src_align) and
22156 try sema.typeHasRuntimeBits(dest_info.child.toType()))
22156 try sema.typeHasRuntimeBits(Type.fromInterned(dest_info.child)))
2215722157 {
2215822158 const align_bytes_minus_1 = dest_align.toByteUnitsOptional().? - 1;
2215922159 const align_minus_1 = Air.internedToRef((try mod.intValue(Type.usize, align_bytes_minus_1)).toIntern());
......@@ -22196,7 +22196,7 @@ fn ptrCastFull(
2219622196 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {
2219722197 // We have to construct a slice using the operand's child's array length
2219822198 // Note that we know from the check at the start of the function that operand_ty is slice-like
22199 const arr_len = Air.internedToRef((try mod.intValue(Type.usize, src_info.child.toType().arrayLen(mod))).toIntern());
22199 const arr_len = Air.internedToRef((try mod.intValue(Type.usize, Type.fromInterned(src_info.child).arrayLen(mod))).toIntern());
2220022200 return block.addInst(.{
2220122201 .tag = .slice,
2220222202 .data = .{ .ty_pl = .{
......@@ -22549,7 +22549,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
2254922549 if (i == field_index) {
2255022550 return bit_sum;
2255122551 }
22552 const field_ty = struct_type.field_types.get(ip)[i].toType();
22552 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
2255322553 bit_sum += field_ty.bitSize(mod);
2255422554 } else unreachable;
2255522555 },
......@@ -23447,10 +23447,10 @@ fn analyzeShuffle(
2344723447
2344823448 if (a_len < b_len) {
2344923449 const undef = try mod.undefRef(a_ty);
23450 a = try sema.analyzeShuffle(block, src_node, elem_ty, a, undef, expand_mask.toValue(), @intCast(max_len));
23450 a = try sema.analyzeShuffle(block, src_node, elem_ty, a, undef, Value.fromInterned(expand_mask), @intCast(max_len));
2345123451 } else {
2345223452 const undef = try mod.undefRef(b_ty);
23453 b = try sema.analyzeShuffle(block, src_node, elem_ty, b, undef, expand_mask.toValue(), @intCast(max_len));
23453 b = try sema.analyzeShuffle(block, src_node, elem_ty, b, undef, Value.fromInterned(expand_mask), @intCast(max_len));
2345423454 }
2345523455 }
2345623456
......@@ -24546,10 +24546,10 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2454624546 const dest_elem_ty: Type = dest_elem_ty: {
2454724547 const ptr_info = dest_ptr_ty.ptrInfo(mod);
2454824548 switch (ptr_info.flags.size) {
24549 .Slice => break :dest_elem_ty ptr_info.child.toType(),
24549 .Slice => break :dest_elem_ty Type.fromInterned(ptr_info.child),
2455024550 .One => {
24551 if (ptr_info.child.toType().zigTypeTag(mod) == .Array) {
24552 break :dest_elem_ty ptr_info.child.toType().childType(mod);
24551 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {
24552 break :dest_elem_ty Type.fromInterned(ptr_info.child).childType(mod);
2455324553 }
2455424554 },
2455524555 .Many, .C => {},
......@@ -24583,10 +24583,10 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2458324583 .child = dest_elem_ty.toIntern(),
2458424584 .len = len_u64,
2458524585 });
24586 const array_val = (try mod.intern(.{ .aggregate = .{
24586 const array_val = Value.fromInterned((try mod.intern(.{ .aggregate = .{
2458724587 .ty = array_ty.toIntern(),
2458824588 .storage = .{ .repeated_elem = elem_val.toIntern() },
24589 } })).toValue();
24589 } })));
2459024590 const array_ptr_ty = ty: {
2459124591 var info = dest_ptr_ty.ptrInfo(mod);
2459224592 info.flags.size = .One;
......@@ -25227,7 +25227,7 @@ fn zirBuiltinExtern(
2522725227 // We only access this decl through the decl_ref with the correct type created
2522825228 // below, so this type doesn't matter
2522925229 new_decl.ty = ty;
25230 new_decl.val = new_var.toValue();
25230 new_decl.val = Value.fromInterned(new_var);
2523125231 new_decl.alignment = .none;
2523225232 new_decl.@"linksection" = .none;
2523325233 new_decl.has_tv = true;
......@@ -25237,14 +25237,14 @@ fn zirBuiltinExtern(
2523725237
2523825238 try sema.ensureDeclAnalyzed(new_decl_index);
2523925239
25240 return Air.internedToRef((try mod.getCoerced((try mod.intern(.{ .ptr = .{
25240 return Air.internedToRef((try mod.getCoerced(Value.fromInterned((try mod.intern(.{ .ptr = .{
2524125241 .ty = switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2524225242 .ptr_type => ty.toIntern(),
2524325243 .opt_type => |child_type| child_type,
2524425244 else => unreachable,
2524525245 },
2524625246 .addr = .{ .decl = new_decl_index },
25247 } })).toValue(), ty)).toIntern());
25247 } }))), ty)).toIntern());
2524825248}
2524925249
2525025250fn zirWorkItem(
......@@ -25430,7 +25430,7 @@ fn explainWhyTypeIsComptimeInner(
2543025430 .Inline => try mod.errNoteNonLazy(src_loc, msg, "function has inline calling convention", .{}),
2543125431 else => {},
2543225432 }
25433 if (fn_info.return_type.toType().comptimeOnly(mod)) {
25433 if (Type.fromInterned(fn_info.return_type).comptimeOnly(mod)) {
2543425434 try mod.errNoteNonLazy(src_loc, msg, "function has a comptime-only return type", .{});
2543525435 }
2543625436 return;
......@@ -25450,7 +25450,7 @@ fn explainWhyTypeIsComptimeInner(
2545025450
2545125451 if (mod.typeToStruct(ty)) |struct_type| {
2545225452 for (0..struct_type.field_types.len) |i| {
25453 const field_ty = struct_type.field_types.get(ip)[i].toType();
25453 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
2545425454 const field_src_loc = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{
2545525455 .index = i,
2545625456 .range = .type,
......@@ -25470,7 +25470,7 @@ fn explainWhyTypeIsComptimeInner(
2547025470
2547125471 if (mod.typeToUnion(ty)) |union_obj| {
2547225472 for (0..union_obj.field_types.len) |i| {
25473 const field_ty = union_obj.field_types.get(ip)[i].toType();
25473 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[i]);
2547425474 const field_src_loc = mod.fieldSrcLoc(union_obj.decl, .{
2547525475 .index = i,
2547625476 .range = .type,
......@@ -26096,7 +26096,7 @@ fn fieldVal(
2609626096 } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) {
2609726097 const ptr_info = object_ty.ptrInfo(mod);
2609826098 const result_ty = try sema.ptrType(.{
26099 .child = ptr_info.child.toType().childType(mod).toIntern(),
26099 .child = Type.fromInterned(ptr_info.child).childType(mod).toIntern(),
2610026100 .sentinel = if (inner_ty.sentinel(mod)) |s| s.toIntern() else .none,
2610126101 .flags = .{
2610226102 .size = .Many,
......@@ -26515,7 +26515,7 @@ fn fieldCallBind(
2651526515 if (mod.typeToStruct(concrete_ty)) |struct_type| {
2651626516 const field_index = struct_type.nameIndex(ip, field_name) orelse
2651726517 break :find_field;
26518 const field_ty = struct_type.field_types.get(ip)[field_index].toType();
26518 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
2651926519
2652026520 return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr);
2652126521 } else if (concrete_ty.isTuple(mod)) {
......@@ -26540,7 +26540,7 @@ fn fieldCallBind(
2654026540 try sema.resolveTypeFields(concrete_ty);
2654126541 const union_obj = mod.typeToUnion(concrete_ty).?;
2654226542 const field_index = union_obj.nameIndex(ip, field_name) orelse break :find_field;
26543 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
26543 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
2654426544
2654526545 return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr);
2654626546 },
......@@ -26563,7 +26563,7 @@ fn fieldCallBind(
2656326563 if (mod.typeToFunc(decl_type)) |func_type| f: {
2656426564 if (func_type.param_types.len == 0) break :f;
2656526565
26566 const first_param_type = func_type.param_types.get(ip)[0].toType();
26566 const first_param_type = Type.fromInterned(func_type.param_types.get(ip)[0]);
2656726567 // zig fmt: off
2656826568 if (first_param_type.isGenericPoison() or (
2656926569 first_param_type.zigTypeTag(mod) == .Pointer and
......@@ -26803,14 +26803,14 @@ fn structFieldPtrByIndex(
2680326803 const parent_align = if (struct_ptr_ty_info.flags.alignment != .none)
2680426804 struct_ptr_ty_info.flags.alignment
2680526805 else
26806 try sema.typeAbiAlignment(struct_ptr_ty_info.child.toType());
26806 try sema.typeAbiAlignment(Type.fromInterned(struct_ptr_ty_info.child));
2680726807
2680826808 if (struct_type.layout == .Packed) {
2680926809 comptime assert(Type.packed_struct_layout_version == 2);
2681026810
2681126811 var running_bits: u16 = 0;
2681226812 for (0..struct_type.field_types.len) |i| {
26813 const f_ty = struct_type.field_types.get(ip)[i].toType();
26813 const f_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
2681426814 if (!(try sema.typeHasRuntimeBits(f_ty))) continue;
2681526815
2681626816 if (i == field_index) {
......@@ -26840,8 +26840,8 @@ fn structFieldPtrByIndex(
2684026840 if (parent_align != .none and ptr_ty_data.packed_offset.bit_offset % 8 == 0 and
2684126841 target.cpu.arch.endian() == .little)
2684226842 {
26843 const elem_size_bytes = try sema.typeAbiSize(ptr_ty_data.child.toType());
26844 const elem_size_bits = ptr_ty_data.child.toType().bitSize(mod);
26843 const elem_size_bytes = try sema.typeAbiSize(Type.fromInterned(ptr_ty_data.child));
26844 const elem_size_bits = Type.fromInterned(ptr_ty_data.child).bitSize(mod);
2684526845 if (elem_size_bytes * 8 == elem_size_bits) {
2684626846 const byte_offset = ptr_ty_data.packed_offset.bit_offset / 8;
2684726847 const new_align: Alignment = @enumFromInt(@ctz(byte_offset | parent_align.toByteUnitsOptional().?));
......@@ -26863,7 +26863,7 @@ fn structFieldPtrByIndex(
2686326863 // Our alignment is capped at the field alignment.
2686426864 const field_align = try sema.structFieldAlignment(
2686526865 struct_type.fieldAlign(ip, field_index),
26866 field_ty.toType(),
26866 Type.fromInterned(field_ty),
2686726867 struct_type.layout,
2686826868 );
2686926869 ptr_ty_data.flags.alignment = if (struct_ptr_ty_info.flags.alignment == .none)
......@@ -26925,7 +26925,7 @@ fn structFieldVal(
2692526925 return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]);
2692626926 }
2692726927
26928 const field_ty = struct_type.field_types.get(ip)[field_index].toType();
26928 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
2692926929
2693026930 if (try sema.resolveValue(struct_byval)) |struct_val| {
2693126931 if (struct_val.isUndef(mod)) return mod.undefRef(field_ty);
......@@ -27013,8 +27013,8 @@ fn tupleFieldValByIndex(
2701327013 .undef => mod.undefRef(field_ty),
2701427014 .aggregate => |aggregate| Air.internedToRef(switch (aggregate.storage) {
2701527015 .bytes => |bytes| try mod.intValue(Type.u8, bytes[0]),
27016 .elems => |elems| elems[field_index].toValue(),
27017 .repeated_elem => |elem| elem.toValue(),
27016 .elems => |elems| Value.fromInterned(elems[field_index]),
27017 .repeated_elem => |elem| Value.fromInterned(elem),
2701827018 }.toIntern()),
2701927019 else => unreachable,
2702027020 };
......@@ -27049,7 +27049,7 @@ fn unionFieldPtr(
2704927049 try sema.resolveTypeFields(union_ty);
2705027050 const union_obj = mod.typeToUnion(union_ty).?;
2705127051 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
27052 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
27052 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
2705327053 const ptr_field_ty = try sema.ptrType(.{
2705427054 .child = field_ty.toIntern(),
2705527055 .flags = .{
......@@ -27067,7 +27067,7 @@ fn unionFieldPtr(
2706727067 },
2706827068 .packed_offset = union_ptr_info.packed_offset,
2706927069 });
27070 const enum_field_index: u32 = @intCast(union_obj.enum_tag_ty.toType().enumFieldIndex(field_name, mod).?);
27070 const enum_field_index: u32 = @intCast(Type.fromInterned(union_obj.enum_tag_ty).enumFieldIndex(field_name, mod).?);
2707127071
2707227072 if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) {
2707327073 const msg = msg: {
......@@ -27092,12 +27092,12 @@ fn unionFieldPtr(
2709227092 return sema.failWithUseOfUndef(block, src);
2709327093 }
2709427094 const un = ip.indexToKey(union_val.toIntern()).un;
27095 const field_tag = try mod.enumValueFieldIndex(union_obj.enum_tag_ty.toType(), enum_field_index);
27095 const field_tag = try mod.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
2709627096 const tag_matches = un.tag == field_tag.toIntern();
2709727097 if (!tag_matches) {
2709827098 const msg = msg: {
27099 const active_index = union_obj.enum_tag_ty.toType().enumTagFieldIndex(un.tag.toValue(), mod).?;
27100 const active_field_name = union_obj.enum_tag_ty.toType().enumFieldName(active_index, mod);
27099 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?;
27100 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod);
2710127101 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{
2710227102 field_name.fmt(ip),
2710327103 active_field_name.fmt(ip),
......@@ -27124,11 +27124,11 @@ fn unionFieldPtr(
2712427124 if (!initializing and union_obj.getLayout(ip) == .Auto and block.wantSafety() and
2712527125 union_ty.unionTagTypeSafety(mod) != null and union_obj.field_names.len > 1)
2712627126 {
27127 const wanted_tag_val = try mod.enumValueFieldIndex(union_obj.enum_tag_ty.toType(), enum_field_index);
27127 const wanted_tag_val = try mod.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
2712827128 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());
2712927129 // TODO would it be better if get_union_tag supported pointers to unions?
2713027130 const union_val = try block.addTyOp(.load, union_ty, union_ptr);
27131 const active_tag = try block.addTyOp(.get_union_tag, union_obj.enum_tag_ty.toType(), union_val);
27131 const active_tag = try block.addTyOp(.get_union_tag, Type.fromInterned(union_obj.enum_tag_ty), union_val);
2713227132 try sema.panicInactiveUnionField(block, src, active_tag, wanted_tag);
2713327133 }
2713427134 if (field_ty.zigTypeTag(mod) == .NoReturn) {
......@@ -27154,14 +27154,14 @@ fn unionFieldVal(
2715427154 try sema.resolveTypeFields(union_ty);
2715527155 const union_obj = mod.typeToUnion(union_ty).?;
2715627156 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
27157 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
27158 const enum_field_index: u32 = @intCast(union_obj.enum_tag_ty.toType().enumFieldIndex(field_name, mod).?);
27157 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
27158 const enum_field_index: u32 = @intCast(Type.fromInterned(union_obj.enum_tag_ty).enumFieldIndex(field_name, mod).?);
2715927159
2716027160 if (try sema.resolveValue(union_byval)) |union_val| {
2716127161 if (union_val.isUndef(mod)) return mod.undefRef(field_ty);
2716227162
2716327163 const un = ip.indexToKey(union_val.toIntern()).un;
27164 const field_tag = try mod.enumValueFieldIndex(union_obj.enum_tag_ty.toType(), enum_field_index);
27164 const field_tag = try mod.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
2716527165 const tag_matches = un.tag == field_tag.toIntern();
2716627166 switch (union_obj.getLayout(ip)) {
2716727167 .Auto => {
......@@ -27169,8 +27169,8 @@ fn unionFieldVal(
2716927169 return Air.internedToRef(un.val);
2717027170 } else {
2717127171 const msg = msg: {
27172 const active_index = union_obj.enum_tag_ty.toType().enumTagFieldIndex(un.tag.toValue(), mod).?;
27173 const active_field_name = union_obj.enum_tag_ty.toType().enumFieldName(active_index, mod);
27172 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?;
27173 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod);
2717427174 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{
2717527175 field_name.fmt(ip), active_field_name.fmt(ip),
2717627176 });
......@@ -27186,11 +27186,11 @@ fn unionFieldVal(
2718627186 return Air.internedToRef(un.val);
2718727187 } else {
2718827188 const old_ty = if (un.tag == .none)
27189 ip.typeOf(un.val).toType()
27189 Type.fromInterned(ip.typeOf(un.val))
2719027190 else
27191 union_ty.unionFieldType(un.tag.toValue(), mod).?;
27191 union_ty.unionFieldType(Value.fromInterned(un.tag), mod).?;
2719227192
27193 if (try sema.bitCastUnionFieldVal(block, src, un.val.toValue(), old_ty, field_ty, layout)) |new_val| {
27193 if (try sema.bitCastUnionFieldVal(block, src, Value.fromInterned(un.val), old_ty, field_ty, layout)) |new_val| {
2719427194 return Air.internedToRef(new_val.toIntern());
2719527195 }
2719627196 }
......@@ -27202,9 +27202,9 @@ fn unionFieldVal(
2720227202 if (union_obj.getLayout(ip) == .Auto and block.wantSafety() and
2720327203 union_ty.unionTagTypeSafety(mod) != null and union_obj.field_names.len > 1)
2720427204 {
27205 const wanted_tag_val = try mod.enumValueFieldIndex(union_obj.enum_tag_ty.toType(), enum_field_index);
27205 const wanted_tag_val = try mod.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
2720627206 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());
27207 const active_tag = try block.addTyOp(.get_union_tag, union_obj.enum_tag_ty.toType(), union_byval);
27207 const active_tag = try block.addTyOp(.get_union_tag, Type.fromInterned(union_obj.enum_tag_ty), union_byval);
2720827208 try sema.panicInactiveUnionField(block, src, active_tag, wanted_tag);
2720927209 }
2721027210 if (field_ty.zigTypeTag(mod) == .NoReturn) {
......@@ -27906,7 +27906,7 @@ fn coerceExtra(
2790627906 if (!inst_ty.isSinglePointer(mod)) break :single_item;
2790727907 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer;
2790827908 const ptr_elem_ty = inst_ty.childType(mod);
27909 const array_ty = dest_info.child.toType();
27909 const array_ty = Type.fromInterned(dest_info.child);
2791027910 if (array_ty.zigTypeTag(mod) != .Array) break :single_item;
2791127911 const array_elem_ty = array_ty.childType(mod);
2791227912 if (array_ty.arrayLen(mod) != 1) break :single_item;
......@@ -27927,7 +27927,7 @@ fn coerceExtra(
2792727927 const array_elem_type = array_ty.childType(mod);
2792827928 const dest_is_mut = !dest_info.flags.is_const;
2792927929
27930 const dst_elem_type = dest_info.child.toType();
27930 const dst_elem_type = Type.fromInterned(dest_info.child);
2793127931 const elem_res = try sema.coerceInMemoryAllowed(block, dst_elem_type, array_elem_type, dest_is_mut, target, dest_ty_src, inst_src);
2793227932 switch (elem_res) {
2793327933 .ok => {},
......@@ -27948,7 +27948,7 @@ fn coerceExtra(
2794827948 {
2794927949 in_memory_result = .{ .ptr_sentinel = .{
2795027950 .actual = inst_sent,
27951 .wanted = dest_info.sentinel.toValue(),
27951 .wanted = Value.fromInterned(dest_info.sentinel),
2795227952 .ty = dst_elem_type,
2795327953 } };
2795427954 break :src_array_ptr;
......@@ -27956,7 +27956,7 @@ fn coerceExtra(
2795627956 } else {
2795727957 in_memory_result = .{ .ptr_sentinel = .{
2795827958 .actual = Value.@"unreachable",
27959 .wanted = dest_info.sentinel.toValue(),
27959 .wanted = Value.fromInterned(dest_info.sentinel),
2796027960 .ty = dst_elem_type,
2796127961 } };
2796227962 break :src_array_ptr;
......@@ -27988,7 +27988,7 @@ fn coerceExtra(
2798827988 // could be null.
2798927989 const src_elem_ty = inst_ty.childType(mod);
2799027990 const dest_is_mut = !dest_info.flags.is_const;
27991 const dst_elem_type = dest_info.child.toType();
27991 const dst_elem_type = Type.fromInterned(dest_info.child);
2799227992 switch (try sema.coerceInMemoryAllowed(block, dst_elem_type, src_elem_ty, dest_is_mut, target, dest_ty_src, inst_src)) {
2799327993 .ok => {},
2799427994 else => break :src_c_ptr,
......@@ -28053,8 +28053,8 @@ fn coerceExtra(
2805328053 const inst_info = inst_ty.ptrInfo(mod);
2805428054 switch (try sema.coerceInMemoryAllowed(
2805528055 block,
28056 dest_info.child.toType(),
28057 inst_info.child.toType(),
28056 Type.fromInterned(dest_info.child),
28057 Type.fromInterned(inst_info.child),
2805828058 !dest_info.flags.is_const,
2805928059 target,
2806028060 dest_ty_src,
......@@ -28066,7 +28066,7 @@ fn coerceExtra(
2806628066 if (inst_info.flags.size == .Slice) {
2806728067 assert(dest_info.sentinel == .none);
2806828068 if (inst_info.sentinel == .none or
28069 inst_info.sentinel != (try mod.intValue(inst_info.child.toType(), 0)).toIntern())
28069 inst_info.sentinel != (try mod.intValue(Type.fromInterned(inst_info.child), 0)).toIntern())
2807028070 break :p;
2807128071
2807228072 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
......@@ -28076,7 +28076,7 @@ fn coerceExtra(
2807628076 },
2807728077 else => {},
2807828078 },
28079 .One => switch (dest_info.child.toType().zigTypeTag(mod)) {
28079 .One => switch (Type.fromInterned(dest_info.child).zigTypeTag(mod)) {
2808028080 .Union => {
2808128081 // pointer to anonymous struct to pointer to union
2808228082 if (inst_ty.isSinglePointer(mod) and
......@@ -28139,7 +28139,7 @@ fn coerceExtra(
2813928139 try mod.intern_pool.getCoercedInts(
2814028140 mod.gpa,
2814128141 mod.intern_pool.indexToKey(
28142 (try dest_info.child.toType().lazyAbiAlignment(mod)).toIntern(),
28142 (try Type.fromInterned(dest_info.child).lazyAbiAlignment(mod)).toIntern(),
2814328143 ).int,
2814428144 .usize_type,
2814528145 ) },
......@@ -28166,8 +28166,8 @@ fn coerceExtra(
2816628166
2816728167 switch (try sema.coerceInMemoryAllowed(
2816828168 block,
28169 dest_info.child.toType(),
28170 inst_info.child.toType(),
28169 Type.fromInterned(dest_info.child),
28170 Type.fromInterned(inst_info.child),
2817128171 !dest_info.flags.is_const,
2817228172 target,
2817328173 dest_ty_src,
......@@ -28179,7 +28179,7 @@ fn coerceExtra(
2817928179
2818028180 if (dest_info.sentinel == .none or inst_info.sentinel == .none or
2818128181 Air.internedToRef(dest_info.sentinel) !=
28182 try sema.coerceInMemory(inst_info.sentinel.toValue(), dest_info.child.toType()))
28182 try sema.coerceInMemory(Value.fromInterned(inst_info.sentinel), Type.fromInterned(dest_info.child)))
2818328183 break :p;
2818428184
2818528185 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
......@@ -29220,8 +29220,8 @@ fn coerceInMemoryAllowedFns(
2922029220 switch (src_info.return_type) {
2922129221 .noreturn_type, .generic_poison_type => {},
2922229222 else => {
29223 const dest_return_type = dest_info.return_type.toType();
29224 const src_return_type = src_info.return_type.toType();
29223 const dest_return_type = Type.fromInterned(dest_info.return_type);
29224 const src_return_type = Type.fromInterned(src_info.return_type);
2922529225 const rt = try sema.coerceInMemoryAllowed(block, dest_return_type, src_return_type, false, target, dest_src, src_src);
2922629226 if (rt != .ok) {
2922729227 return InMemoryCoercionResult{ .fn_return_type = .{
......@@ -29253,8 +29253,8 @@ fn coerceInMemoryAllowedFns(
2925329253 };
2925429254
2925529255 for (0..params_len) |param_i| {
29256 const dest_param_ty = dest_info.param_types.get(ip)[param_i].toType();
29257 const src_param_ty = src_info.param_types.get(ip)[param_i].toType();
29256 const dest_param_ty = Type.fromInterned(dest_info.param_types.get(ip)[param_i]);
29257 const src_param_ty = Type.fromInterned(src_info.param_types.get(ip)[param_i]);
2925829258
2925929259 const param_i_small: u5 = @intCast(param_i);
2926029260 if (dest_info.paramIsComptime(param_i_small) != src_info.paramIsComptime(param_i_small)) {
......@@ -29329,12 +29329,12 @@ fn coerceInMemoryAllowedPtrs(
2932929329 } };
2933029330 }
2933129331
29332 const child = try sema.coerceInMemoryAllowed(block, dest_info.child.toType(), src_info.child.toType(), !dest_info.flags.is_const, target, dest_src, src_src);
29332 const child = try sema.coerceInMemoryAllowed(block, Type.fromInterned(dest_info.child), Type.fromInterned(src_info.child), !dest_info.flags.is_const, target, dest_src, src_src);
2933329333 if (child != .ok) {
2933429334 return InMemoryCoercionResult{ .ptr_child = .{
2933529335 .child = try child.dupe(sema.arena),
29336 .actual = src_info.child.toType(),
29337 .wanted = dest_info.child.toType(),
29336 .actual = Type.fromInterned(src_info.child),
29337 .wanted = Type.fromInterned(dest_info.child),
2933829338 } };
2933929339 }
2934029340
......@@ -29369,13 +29369,13 @@ fn coerceInMemoryAllowedPtrs(
2936929369 return InMemoryCoercionResult{ .ptr_sentinel = .{
2937029370 .actual = switch (src_info.sentinel) {
2937129371 .none => Value.@"unreachable",
29372 else => src_info.sentinel.toValue(),
29372 else => Value.fromInterned(src_info.sentinel),
2937329373 },
2937429374 .wanted = switch (dest_info.sentinel) {
2937529375 .none => Value.@"unreachable",
29376 else => dest_info.sentinel.toValue(),
29376 else => Value.fromInterned(dest_info.sentinel),
2937729377 },
29378 .ty = dest_info.child.toType(),
29378 .ty = Type.fromInterned(dest_info.child),
2937929379 } };
2938029380 }
2938129381
......@@ -29389,12 +29389,12 @@ fn coerceInMemoryAllowedPtrs(
2938929389 const src_align = if (src_info.flags.alignment != .none)
2939029390 src_info.flags.alignment
2939129391 else
29392 try sema.typeAbiAlignment(src_info.child.toType());
29392 try sema.typeAbiAlignment(Type.fromInterned(src_info.child));
2939329393
2939429394 const dest_align = if (dest_info.flags.alignment != .none)
2939529395 dest_info.flags.alignment
2939629396 else
29397 try sema.typeAbiAlignment(dest_info.child.toType());
29397 try sema.typeAbiAlignment(Type.fromInterned(dest_info.child));
2939829398
2939929399 if (dest_align.compare(.gt, src_align)) {
2940029400 return InMemoryCoercionResult{ .ptr_alignment = .{
......@@ -29719,14 +29719,14 @@ fn storePtrVal(
2971929719 .opv => {},
2972029720 .direct => |val_ptr| {
2972129721 if (mut_kit.mut_decl.runtime_index == .comptime_field_ptr) {
29722 val_ptr.* = (try val_ptr.intern(operand_ty, mod)).toValue();
29722 val_ptr.* = Value.fromInterned((try val_ptr.intern(operand_ty, mod)));
2972329723 if (!operand_val.eql(val_ptr.*, operand_ty, mod)) {
2972429724 // TODO use failWithInvalidComptimeFieldStore
2972529725 return sema.fail(block, src, "value stored in comptime field does not match the default value of the field", .{});
2972629726 }
2972729727 return;
2972829728 }
29729 val_ptr.* = (try operand_val.intern(operand_ty, mod)).toValue();
29729 val_ptr.* = Value.fromInterned((try operand_val.intern(operand_ty, mod)));
2973029730 },
2973129731 .reinterpret => |reinterpret| {
2973229732 const abi_size = try sema.usizeCast(block, src, mut_kit.ty.abiSize(mod));
......@@ -29756,7 +29756,7 @@ fn storePtrVal(
2975629756 error.IllDefinedMemoryLayout => unreachable,
2975729757 error.Unimplemented => return sema.fail(block, src, "TODO: implement readFromMemory for type '{}'", .{mut_kit.ty.fmt(mod)}),
2975829758 };
29759 reinterpret.val_ptr.* = (try val.intern(mut_kit.ty, mod)).toValue();
29759 reinterpret.val_ptr.* = Value.fromInterned((try val.intern(mut_kit.ty, mod)));
2976029760 },
2976129761 .bad_decl_ty, .bad_ptr_ty => {
2976229762 // TODO show the decl declaration site in a note and explain whether the decl
......@@ -29817,15 +29817,15 @@ fn beginComptimePtrMutation(
2981729817 },
2981829818 .comptime_field => |comptime_field| {
2981929819 const duped = try sema.arena.create(Value);
29820 duped.* = comptime_field.toValue();
29821 return sema.beginComptimePtrMutationInner(block, src, mod.intern_pool.typeOf(comptime_field).toType(), duped, ptr_elem_ty, .{
29820 duped.* = Value.fromInterned(comptime_field);
29821 return sema.beginComptimePtrMutationInner(block, src, Type.fromInterned(mod.intern_pool.typeOf(comptime_field)), duped, ptr_elem_ty, .{
2982229822 .decl = undefined,
2982329823 .runtime_index = .comptime_field_ptr,
2982429824 });
2982529825 },
2982629826 .eu_payload => |eu_ptr| {
29827 const eu_ty = mod.intern_pool.typeOf(eu_ptr).toType().childType(mod);
29828 var parent = try sema.beginComptimePtrMutation(block, src, eu_ptr.toValue(), eu_ty);
29827 const eu_ty = Type.fromInterned(mod.intern_pool.typeOf(eu_ptr)).childType(mod);
29828 var parent = try sema.beginComptimePtrMutation(block, src, Value.fromInterned(eu_ptr), eu_ty);
2982929829 switch (parent.pointee) {
2983029830 .opv => unreachable,
2983129831 .direct => |val_ptr| {
......@@ -29844,7 +29844,7 @@ fn beginComptimePtrMutation(
2984429844 const payload = try sema.arena.create(Value.Payload.SubValue);
2984529845 payload.* = .{
2984629846 .base = .{ .tag = .eu_payload },
29847 .data = (try mod.intern(.{ .undef = payload_ty.toIntern() })).toValue(),
29847 .data = Value.fromInterned((try mod.intern(.{ .undef = payload_ty.toIntern() }))),
2984829848 };
2984929849
2985029850 val_ptr.* = Value.initPayload(&payload.base);
......@@ -29867,8 +29867,8 @@ fn beginComptimePtrMutation(
2986729867 }
2986829868 },
2986929869 .opt_payload => |opt_ptr| {
29870 const opt_ty = mod.intern_pool.typeOf(opt_ptr).toType().childType(mod);
29871 var parent = try sema.beginComptimePtrMutation(block, src, opt_ptr.toValue(), opt_ty);
29870 const opt_ty = Type.fromInterned(mod.intern_pool.typeOf(opt_ptr)).childType(mod);
29871 var parent = try sema.beginComptimePtrMutation(block, src, Value.fromInterned(opt_ptr), opt_ty);
2987229872 switch (parent.pointee) {
2987329873 .opv => unreachable,
2987429874 .direct => |val_ptr| {
......@@ -29896,7 +29896,7 @@ fn beginComptimePtrMutation(
2989629896 const payload = try sema.arena.create(Value.Payload.SubValue);
2989729897 payload.* = .{
2989829898 .base = .{ .tag = .opt_payload },
29899 .data = payload_val.toValue(),
29899 .data = Value.fromInterned(payload_val),
2990029900 };
2990129901
2990229902 val_ptr.* = Value.initPayload(&payload.base);
......@@ -29920,8 +29920,8 @@ fn beginComptimePtrMutation(
2992029920 }
2992129921 },
2992229922 .elem => |elem_ptr| {
29923 const base_elem_ty = mod.intern_pool.typeOf(elem_ptr.base).toType().elemType2(mod);
29924 var parent = try sema.beginComptimePtrMutation(block, src, elem_ptr.base.toValue(), base_elem_ty);
29923 const base_elem_ty = Type.fromInterned(mod.intern_pool.typeOf(elem_ptr.base)).elemType2(mod);
29924 var parent = try sema.beginComptimePtrMutation(block, src, Value.fromInterned(elem_ptr.base), base_elem_ty);
2992529925
2992629926 switch (parent.pointee) {
2992729927 .opv => unreachable,
......@@ -30017,7 +30017,7 @@ fn beginComptimePtrMutation(
3001730017 const array_len_including_sentinel =
3001830018 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));
3001930019 const elems = try arena.alloc(Value, array_len_including_sentinel);
30020 @memset(elems, repeated_val.toValue());
30020 @memset(elems, Value.fromInterned(repeated_val));
3002130021
3002230022 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
3002330023
......@@ -30054,7 +30054,7 @@ fn beginComptimePtrMutation(
3005430054 const array_len_including_sentinel =
3005530055 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));
3005630056 const elems = try arena.alloc(Value, array_len_including_sentinel);
30057 @memset(elems, (try mod.intern(.{ .undef = elem_ty.toIntern() })).toValue());
30057 @memset(elems, Value.fromInterned((try mod.intern(.{ .undef = elem_ty.toIntern() }))));
3005830058
3005930059 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
3006030060
......@@ -30117,10 +30117,10 @@ fn beginComptimePtrMutation(
3011730117 }
3011830118 },
3011930119 .field => |field_ptr| {
30120 const base_child_ty = mod.intern_pool.typeOf(field_ptr.base).toType().childType(mod);
30120 const base_child_ty = Type.fromInterned(mod.intern_pool.typeOf(field_ptr.base)).childType(mod);
3012130121 const field_index: u32 = @intCast(field_ptr.index);
3012230122
30123 var parent = try sema.beginComptimePtrMutation(block, src, field_ptr.base.toValue(), base_child_ty);
30123 var parent = try sema.beginComptimePtrMutation(block, src, Value.fromInterned(field_ptr.base), base_child_ty);
3012430124 switch (parent.pointee) {
3012530125 .opv => unreachable,
3012630126 .direct => |val_ptr| switch (val_ptr.ip_index) {
......@@ -30238,9 +30238,9 @@ fn beginComptimePtrMutation(
3023830238 switch (parent.ty.zigTypeTag(mod)) {
3023930239 .Struct => {
3024030240 const fields = try arena.alloc(Value, parent.ty.structFieldCount(mod));
30241 for (fields, 0..) |*field, i| field.* = (try mod.intern(.{
30241 for (fields, 0..) |*field, i| field.* = Value.fromInterned((try mod.intern(.{
3024230242 .undef = parent.ty.structFieldType(i, mod).toIntern(),
30243 })).toValue();
30243 })));
3024430244
3024530245 val_ptr.* = try Value.Tag.aggregate.create(arena, fields);
3024630246
......@@ -30260,7 +30260,7 @@ fn beginComptimePtrMutation(
3026030260 const payload_ty = parent.ty.structFieldType(field_index, mod);
3026130261 payload.* = .{ .data = .{
3026230262 .tag = try mod.enumValueFieldIndex(tag_ty, field_index),
30263 .val = (try mod.intern(.{ .undef = payload_ty.toIntern() })).toValue(),
30263 .val = Value.fromInterned((try mod.intern(.{ .undef = payload_ty.toIntern() }))),
3026430264 } };
3026530265
3026630266 val_ptr.* = Value.initPayload(&payload.base);
......@@ -30279,8 +30279,8 @@ fn beginComptimePtrMutation(
3027930279 assert(parent.ty.isSlice(mod));
3028030280 const ptr_ty = parent.ty.slicePtrFieldType(mod);
3028130281 val_ptr.* = try Value.Tag.slice.create(arena, .{
30282 .ptr = (try mod.intern(.{ .undef = ptr_ty.toIntern() })).toValue(),
30283 .len = (try mod.intern(.{ .undef = .usize_type })).toValue(),
30282 .ptr = Value.fromInterned((try mod.intern(.{ .undef = ptr_ty.toIntern() }))),
30283 .len = Value.fromInterned((try mod.intern(.{ .undef = .usize_type }))),
3028430284 });
3028530285
3028630286 switch (field_index) {
......@@ -30449,9 +30449,9 @@ fn beginComptimePtrLoad(
3044930449 },
3045030450 .anon_decl => |anon_decl| blk: {
3045130451 const decl_val = anon_decl.val;
30452 if (decl_val.toValue().getVariable(mod) != null) return error.RuntimeLoad;
30453 const decl_ty = ip.typeOf(decl_val).toType();
30454 const decl_tv: TypedValue = .{ .ty = decl_ty, .val = decl_val.toValue() };
30452 if (Value.fromInterned(decl_val).getVariable(mod) != null) return error.RuntimeLoad;
30453 const decl_ty = Type.fromInterned(ip.typeOf(decl_val));
30454 const decl_tv: TypedValue = .{ .ty = decl_ty, .val = Value.fromInterned(decl_val) };
3045530455 const layout_defined = decl_ty.hasWellDefinedLayout(mod);
3045630456 break :blk ComptimePtrLoadKit{
3045730457 .parent = if (layout_defined) .{ .tv = decl_tv, .byte_offset = 0 } else null,
......@@ -30462,13 +30462,13 @@ fn beginComptimePtrLoad(
3046230462 },
3046330463 .int => return error.RuntimeLoad,
3046430464 .eu_payload, .opt_payload => |container_ptr| blk: {
30465 const container_ty = ip.typeOf(container_ptr).toType().childType(mod);
30465 const container_ty = Type.fromInterned(ip.typeOf(container_ptr)).childType(mod);
3046630466 const payload_ty = switch (ptr.addr) {
3046730467 .eu_payload => container_ty.errorUnionPayload(mod),
3046830468 .opt_payload => container_ty.optionalChild(mod),
3046930469 else => unreachable,
3047030470 };
30471 var deref = try sema.beginComptimePtrLoad(block, src, container_ptr.toValue(), container_ty);
30471 var deref = try sema.beginComptimePtrLoad(block, src, Value.fromInterned(container_ptr), container_ty);
3047230472
3047330473 // eu_payload and opt_payload never have a well-defined layout
3047430474 if (deref.parent != null) {
......@@ -30484,7 +30484,7 @@ fn beginComptimePtrLoad(
3048430484 const payload_val = switch (tv.val.ip_index) {
3048530485 .none => tv.val.cast(Value.Payload.SubValue).?.data,
3048630486 .null_value => return sema.fail(block, src, "attempt to use null value", .{}),
30487 else => switch (ip.indexToKey(tv.val.toIntern())) {
30487 else => Value.fromInterned(switch (ip.indexToKey(tv.val.toIntern())) {
3048830488 .error_union => |error_union| switch (error_union.val) {
3048930489 .err_name => |err_name| return sema.fail(
3049030490 block,
......@@ -30499,7 +30499,7 @@ fn beginComptimePtrLoad(
3049930499 else => |payload| payload,
3050030500 },
3050130501 else => unreachable,
30502 }.toValue(),
30502 }),
3050330503 };
3050430504 tv.* = TypedValue{ .ty = payload_ty, .val = payload_val };
3050530505 break :blk deref;
......@@ -30509,24 +30509,24 @@ fn beginComptimePtrLoad(
3050930509 break :blk deref;
3051030510 },
3051130511 .comptime_field => |comptime_field| blk: {
30512 const field_ty = ip.typeOf(comptime_field).toType();
30512 const field_ty = Type.fromInterned(ip.typeOf(comptime_field));
3051330513 break :blk ComptimePtrLoadKit{
3051430514 .parent = null,
30515 .pointee = .{ .ty = field_ty, .val = comptime_field.toValue() },
30515 .pointee = .{ .ty = field_ty, .val = Value.fromInterned(comptime_field) },
3051630516 .is_mutable = false,
3051730517 .ty_without_well_defined_layout = field_ty,
3051830518 };
3051930519 },
3052030520 .elem => |elem_ptr| blk: {
30521 const elem_ty = ip.typeOf(elem_ptr.base).toType().elemType2(mod);
30522 var deref = try sema.beginComptimePtrLoad(block, src, elem_ptr.base.toValue(), null);
30521 const elem_ty = Type.fromInterned(ip.typeOf(elem_ptr.base)).elemType2(mod);
30522 var deref = try sema.beginComptimePtrLoad(block, src, Value.fromInterned(elem_ptr.base), null);
3052330523
3052430524 // This code assumes that elem_ptrs have been "flattened" in order for direct dereference
3052530525 // to succeed, meaning that elem ptrs of the same elem_ty are coalesced. Here we check that
3052630526 // our parent is not an elem_ptr with the same elem_ty, since that would be "unflattened"
3052730527 switch (ip.indexToKey(elem_ptr.base)) {
3052830528 .ptr => |base_ptr| switch (base_ptr.addr) {
30529 .elem => |base_elem| assert(!ip.typeOf(base_elem.base).toType().elemType2(mod).eql(elem_ty, mod)),
30529 .elem => |base_elem| assert(!Type.fromInterned(ip.typeOf(base_elem.base)).elemType2(mod).eql(elem_ty, mod)),
3053030530 else => {},
3053130531 },
3053230532 else => {},
......@@ -30598,8 +30598,8 @@ fn beginComptimePtrLoad(
3059830598 },
3059930599 .field => |field_ptr| blk: {
3060030600 const field_index: u32 = @intCast(field_ptr.index);
30601 const container_ty = ip.typeOf(field_ptr.base).toType().childType(mod);
30602 var deref = try sema.beginComptimePtrLoad(block, src, field_ptr.base.toValue(), container_ty);
30601 const container_ty = Type.fromInterned(ip.typeOf(field_ptr.base)).childType(mod);
30602 var deref = try sema.beginComptimePtrLoad(block, src, Value.fromInterned(field_ptr.base), container_ty);
3060330603
3060430604 if (container_ty.hasWellDefinedLayout(mod)) {
3060530605 const struct_obj = mod.typeToStruct(container_ty);
......@@ -30637,7 +30637,7 @@ fn beginComptimePtrLoad(
3063730637 },
3063830638 Value.slice_len_index => TypedValue{
3063930639 .ty = Type.usize,
30640 .val = ip.indexToKey(try tv.val.intern(tv.ty, mod)).ptr.len.toValue(),
30640 .val = Value.fromInterned(ip.indexToKey(try tv.val.intern(tv.ty, mod)).ptr.len),
3064130641 },
3064230642 else => unreachable,
3064330643 };
......@@ -30653,7 +30653,7 @@ fn beginComptimePtrLoad(
3065330653 },
3065430654 .opt => |opt| switch (opt.val) {
3065530655 .none => return sema.fail(block, src, "attempt to use null value", .{}),
30656 else => |payload| try sema.beginComptimePtrLoad(block, src, payload.toValue(), null),
30656 else => |payload| try sema.beginComptimePtrLoad(block, src, Value.fromInterned(payload), null),
3065730657 },
3065830658 else => unreachable,
3065930659 };
......@@ -30822,9 +30822,9 @@ fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_resul
3082230822 const mod = sema.mod;
3082330823 const dest_info = dest_ty.ptrInfo(mod);
3082430824 const inst_info = inst_ty.ptrInfo(mod);
30825 const len0 = (inst_info.child.toType().zigTypeTag(mod) == .Array and (inst_info.child.toType().arrayLenIncludingSentinel(mod) == 0 or
30826 (inst_info.child.toType().arrayLen(mod) == 0 and dest_info.sentinel == .none and dest_info.flags.size != .C and dest_info.flags.size != .Many))) or
30827 (inst_info.child.toType().isTuple(mod) and inst_info.child.toType().structFieldCount(mod) == 0);
30825 const len0 = (Type.fromInterned(inst_info.child).zigTypeTag(mod) == .Array and (Type.fromInterned(inst_info.child).arrayLenIncludingSentinel(mod) == 0 or
30826 (Type.fromInterned(inst_info.child).arrayLen(mod) == 0 and dest_info.sentinel == .none and dest_info.flags.size != .C and dest_info.flags.size != .Many))) or
30827 (Type.fromInterned(inst_info.child).isTuple(mod) and Type.fromInterned(inst_info.child).structFieldCount(mod) == 0);
3082830828
3082930829 const ok_cv_qualifiers =
3083030830 ((!inst_info.flags.is_const or dest_info.flags.is_const) or len0) and
......@@ -30852,12 +30852,12 @@ fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_resul
3085230852 const inst_align = if (inst_info.flags.alignment != .none)
3085330853 inst_info.flags.alignment
3085430854 else
30855 inst_info.child.toType().abiAlignment(mod);
30855 Type.fromInterned(inst_info.child).abiAlignment(mod);
3085630856
3085730857 const dest_align = if (dest_info.flags.alignment != .none)
3085830858 dest_info.flags.alignment
3085930859 else
30860 dest_info.child.toType().abiAlignment(mod);
30860 Type.fromInterned(dest_info.child).abiAlignment(mod);
3086130861
3086230862 if (dest_align.compare(.gt, inst_align)) {
3086330863 in_memory_result.* = .{ .ptr_alignment = .{
......@@ -30884,7 +30884,7 @@ fn coerceCompatiblePtrs(
3088430884 }
3088530885 // The comptime Value representation is compatible with both types.
3088630886 return Air.internedToRef(
30887 (try mod.getCoerced((try val.intern(inst_ty, mod)).toValue(), dest_ty)).toIntern(),
30887 (try mod.getCoerced(Value.fromInterned((try val.intern(inst_ty, mod))), dest_ty)).toIntern(),
3088830888 );
3088930889 }
3089030890 try sema.requireRuntimeBlock(block, inst_src, null);
......@@ -30950,7 +30950,7 @@ fn coerceEnumToUnion(
3095030950 };
3095130951
3095230952 const union_obj = mod.typeToUnion(union_ty).?;
30953 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
30953 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3095430954 try sema.resolveTypeFields(field_ty);
3095530955 if (field_ty.zigTypeTag(mod) == .NoReturn) {
3095630956 const msg = msg: {
......@@ -31007,7 +31007,7 @@ fn coerceEnumToUnion(
3100731007 errdefer if (msg) |some| some.destroy(sema.gpa);
3100831008
3100931009 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
31010 if (field_ty.toType().zigTypeTag(mod) == .NoReturn) {
31010 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .NoReturn) {
3101131011 const err_msg = msg orelse try sema.errMsg(
3101231012 block,
3101331013 inst_src,
......@@ -31042,7 +31042,7 @@ fn coerceEnumToUnion(
3104231042
3104331043 for (0..union_obj.field_names.len) |field_index| {
3104431044 const field_name = union_obj.field_names.get(ip)[field_index];
31045 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
31045 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3104631046 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
3104731047 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{
3104831048 field_name.fmt(ip),
......@@ -31320,7 +31320,7 @@ fn coerceTupleToArrayPtrs(
3132031320 const mod = sema.mod;
3132131321 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);
3132231322 const ptr_info = ptr_array_ty.ptrInfo(mod);
31323 const array_ty = ptr_info.child.toType();
31323 const array_ty = Type.fromInterned(ptr_info.child);
3132431324 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);
3132531325 if (ptr_info.flags.alignment != .none) {
3132631326 return sema.fail(block, array_ty_src, "TODO: override the alignment of the array decl we create here", .{});
......@@ -31372,7 +31372,7 @@ fn coerceTupleToStruct(
3137231372 else => unreachable,
3137331373 };
3137431374 const field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src);
31375 const field_ty = struct_type.field_types.get(ip)[field_index].toType();
31375 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
3137631376 const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, field_i);
3137731377 const coerced = try sema.coerce(block, field_ty, elem_ref, field_src);
3137831378 field_refs[field_index] = coerced;
......@@ -31383,7 +31383,7 @@ fn coerceTupleToStruct(
3138331383 });
3138431384 };
3138531385
31386 const field_init = struct_type.field_inits.get(ip)[field_index].toValue();
31386 const field_init = Value.fromInterned(struct_type.field_inits.get(ip)[field_index]);
3138731387 if (!init_val.eql(field_init, field_ty, sema.mod)) {
3138831388 return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i);
3138931389 }
......@@ -31502,7 +31502,7 @@ fn coerceTupleToTuple(
3150231502 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_src);
3150331503
3150431504 const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, field_i);
31505 const coerced = try sema.coerce(block, field_ty.toType(), elem_ref, field_src);
31505 const coerced = try sema.coerce(block, Type.fromInterned(field_ty), elem_ref, field_src);
3150631506 field_refs[field_index] = coerced;
3150731507 if (default_val != .none) {
3150831508 const init_val = (try sema.resolveValue(coerced)) orelse {
......@@ -31511,7 +31511,7 @@ fn coerceTupleToTuple(
3151131511 });
3151231512 };
3151331513
31514 if (!init_val.eql(default_val.toValue(), field_ty.toType(), sema.mod)) {
31514 if (!init_val.eql(Value.fromInterned(default_val), Type.fromInterned(field_ty), sema.mod)) {
3151531515 return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i);
3151631516 }
3151731517 }
......@@ -31658,13 +31658,13 @@ fn ensureFuncBodyAnalyzed(sema: *Sema, func: InternPool.Index) CompileError!void
3165831658fn optRefValue(sema: *Sema, opt_val: ?Value) !Value {
3165931659 const mod = sema.mod;
3166031660 const ptr_anyopaque_ty = try mod.singleConstPtrType(Type.anyopaque);
31661 return (try mod.intern(.{ .opt = .{
31661 return Value.fromInterned((try mod.intern(.{ .opt = .{
3166231662 .ty = (try mod.optionalType(ptr_anyopaque_ty.toIntern())).toIntern(),
3166331663 .val = if (opt_val) |val| (try mod.getCoerced(
31664 (try sema.refValue(val.toIntern())).toValue(),
31664 Value.fromInterned((try sema.refValue(val.toIntern()))),
3166531665 ptr_anyopaque_ty,
3166631666 )).toIntern() else .none,
31667 } })).toValue();
31667 } })));
3166831668}
3166931669
3167031670fn analyzeDeclRef(sema: *Sema, decl_index: Decl.Index) CompileError!Air.Inst.Ref {
......@@ -32378,7 +32378,7 @@ fn analyzeSlice(
3237832378
3237932379 if (!new_ptr_val.isUndef(mod)) {
3238032380 return Air.internedToRef((try mod.getCoerced(
32381 (try new_ptr_val.intern(new_ptr_ty, mod)).toValue(),
32381 Value.fromInterned((try new_ptr_val.intern(new_ptr_ty, mod))),
3238232382 return_ty,
3238332383 )).toIntern());
3238432384 }
......@@ -33362,10 +33362,10 @@ fn resolvePeerTypesInner(
3336233362 ty_ptr.* = ty.errorUnionPayload(mod);
3336333363 if (val_ptr.*) |eu_val| switch (ip.indexToKey(eu_val.toIntern())) {
3336433364 .error_union => |eu| switch (eu.val) {
33365 .payload => |payload_ip| val_ptr.* = payload_ip.toValue(),
33365 .payload => |payload_ip| val_ptr.* = Value.fromInterned(payload_ip),
3336633366 .err_name => val_ptr.* = null,
3336733367 },
33368 .undef => val_ptr.* = (try sema.mod.intern(.{ .undef = ty_ptr.*.?.toIntern() })).toValue(),
33368 .undef => val_ptr.* = Value.fromInterned((try sema.mod.intern(.{ .undef = ty_ptr.*.?.toIntern() }))),
3336933369 else => unreachable,
3337033370 };
3337133371 break :blk set_ty;
......@@ -33606,7 +33606,7 @@ fn resolvePeerTypesInner(
3360633606 };
3360733607
3360833608 // Try peer -> cur, then cur -> peer
33609 ptr_info.child = ((try sema.resolvePairInMemoryCoercible(block, src, ptr_info.child.toType(), peer_info.child.toType())) orelse {
33609 ptr_info.child = ((try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) orelse {
3361033610 return .{ .conflict = .{
3361133611 .peer_idx_a = first_idx,
3361233612 .peer_idx_b = i,
......@@ -33630,12 +33630,12 @@ fn resolvePeerTypesInner(
3363033630 if (ptr_info.flags.alignment != .none)
3363133631 ptr_info.flags.alignment
3363233632 else
33633 ptr_info.child.toType().abiAlignment(mod),
33633 Type.fromInterned(ptr_info.child).abiAlignment(mod),
3363433634
3363533635 if (peer_info.flags.alignment != .none)
3363633636 peer_info.flags.alignment
3363733637 else
33638 peer_info.child.toType().abiAlignment(mod),
33638 Type.fromInterned(peer_info.child).abiAlignment(mod),
3363933639 );
3364033640 if (ptr_info.flags.address_space != peer_info.flags.address_space) {
3364133641 return .{ .conflict = .{
......@@ -33714,12 +33714,12 @@ fn resolvePeerTypesInner(
3371433714 if (ptr_info.flags.alignment != .none)
3371533715 ptr_info.flags.alignment
3371633716 else
33717 try sema.typeAbiAlignment(ptr_info.child.toType()),
33717 try sema.typeAbiAlignment(Type.fromInterned(ptr_info.child)),
3371833718
3371933719 if (peer_info.flags.alignment != .none)
3372033720 peer_info.flags.alignment
3372133721 else
33722 try sema.typeAbiAlignment(peer_info.child.toType()),
33722 try sema.typeAbiAlignment(Type.fromInterned(peer_info.child)),
3372333723 );
3372433724
3372533725 if (ptr_info.flags.address_space != peer_info.flags.address_space) {
......@@ -33754,8 +33754,8 @@ fn resolvePeerTypesInner(
3375433754 };
3375533755
3375633756 // We abstract array handling slightly so that tuple pointers can work like array pointers
33757 const peer_pointee_array = sema.typeIsArrayLike(peer_info.child.toType());
33758 const cur_pointee_array = sema.typeIsArrayLike(ptr_info.child.toType());
33757 const peer_pointee_array = sema.typeIsArrayLike(Type.fromInterned(peer_info.child));
33758 const cur_pointee_array = sema.typeIsArrayLike(Type.fromInterned(ptr_info.child));
3375933759
3376033760 // This switch is just responsible for deciding the size and pointee (not including
3376133761 // single-pointer array sentinel).
......@@ -33763,7 +33763,7 @@ fn resolvePeerTypesInner(
3376333763 switch (peer_info.flags.size) {
3376433764 .One => switch (ptr_info.flags.size) {
3376533765 .One => {
33766 if (try sema.resolvePairInMemoryCoercible(block, src, ptr_info.child.toType(), peer_info.child.toType())) |pointee| {
33766 if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) |pointee| {
3376733767 ptr_info.child = pointee.toIntern();
3376833768 break :good;
3376933769 }
......@@ -33805,7 +33805,7 @@ fn resolvePeerTypesInner(
3380533805 .Many => {
3380633806 // Only works for *[n]T + [*]T -> [*]T
3380733807 const arr = peer_pointee_array orelse return generic_err;
33808 if (try sema.resolvePairInMemoryCoercible(block, src, ptr_info.child.toType(), arr.elem_ty)) |pointee| {
33808 if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), arr.elem_ty)) |pointee| {
3380933809 ptr_info.child = pointee.toIntern();
3381033810 break :good;
3381133811 }
......@@ -33818,7 +33818,7 @@ fn resolvePeerTypesInner(
3381833818 .Slice => {
3381933819 // Only works for *[n]T + []T -> []T
3382033820 const arr = peer_pointee_array orelse return generic_err;
33821 if (try sema.resolvePairInMemoryCoercible(block, src, ptr_info.child.toType(), arr.elem_ty)) |pointee| {
33821 if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), arr.elem_ty)) |pointee| {
3382233822 ptr_info.child = pointee.toIntern();
3382333823 break :good;
3382433824 }
......@@ -33834,7 +33834,7 @@ fn resolvePeerTypesInner(
3383433834 .One => {
3383533835 // Only works for [*]T + *[n]T -> [*]T
3383633836 const arr = cur_pointee_array orelse return generic_err;
33837 if (try sema.resolvePairInMemoryCoercible(block, src, arr.elem_ty, peer_info.child.toType())) |pointee| {
33837 if (try sema.resolvePairInMemoryCoercible(block, src, arr.elem_ty, Type.fromInterned(peer_info.child))) |pointee| {
3383833838 ptr_info.flags.size = .Many;
3383933839 ptr_info.child = pointee.toIntern();
3384033840 break :good;
......@@ -33848,7 +33848,7 @@ fn resolvePeerTypesInner(
3384833848 return generic_err;
3384933849 },
3385033850 .Many => {
33851 if (try sema.resolvePairInMemoryCoercible(block, src, ptr_info.child.toType(), peer_info.child.toType())) |pointee| {
33851 if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) |pointee| {
3385233852 ptr_info.child = pointee.toIntern();
3385333853 break :good;
3385433854 }
......@@ -33863,7 +33863,7 @@ fn resolvePeerTypesInner(
3386333863 } };
3386433864 }
3386533865 // Okay, then works for [*]T + "[]T" -> [*]T
33866 if (try sema.resolvePairInMemoryCoercible(block, src, ptr_info.child.toType(), peer_info.child.toType())) |pointee| {
33866 if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) |pointee| {
3386733867 ptr_info.flags.size = .Many;
3386833868 ptr_info.child = pointee.toIntern();
3386933869 break :good;
......@@ -33876,7 +33876,7 @@ fn resolvePeerTypesInner(
3387633876 .One => {
3387733877 // Only works for []T + *[n]T -> []T
3387833878 const arr = cur_pointee_array orelse return generic_err;
33879 if (try sema.resolvePairInMemoryCoercible(block, src, arr.elem_ty, peer_info.child.toType())) |pointee| {
33879 if (try sema.resolvePairInMemoryCoercible(block, src, arr.elem_ty, Type.fromInterned(peer_info.child))) |pointee| {
3388033880 ptr_info.flags.size = .Slice;
3388133881 ptr_info.child = pointee.toIntern();
3388233882 break :good;
......@@ -33894,7 +33894,7 @@ fn resolvePeerTypesInner(
3389433894 return generic_err;
3389533895 },
3389633896 .Slice => {
33897 if (try sema.resolvePairInMemoryCoercible(block, src, ptr_info.child.toType(), peer_info.child.toType())) |pointee| {
33897 if (try sema.resolvePairInMemoryCoercible(block, src, Type.fromInterned(ptr_info.child), Type.fromInterned(peer_info.child))) |pointee| {
3389833898 ptr_info.child = pointee.toIntern();
3389933899 break :good;
3390033900 }
......@@ -34331,7 +34331,7 @@ fn resolvePeerTypesInner(
3433134331 break;
3433234332 };
3433334333 const uncoerced_field = Air.internedToRef(uncoerced_field_val.toIntern());
34334 const coerced_inst = sema.coerceExtra(block, field_ty.toType(), uncoerced_field, src, .{ .report_err = false }) catch |err| switch (err) {
34334 const coerced_inst = sema.coerceExtra(block, Type.fromInterned(field_ty.*), uncoerced_field, src, .{ .report_err = false }) catch |err| switch (err) {
3433534335 // It's possible for PTR to give false positives. Just give up on making this a comptime field, we'll get an error later anyway
3433634336 error.NotCoercible => {
3433734337 comptime_val = null;
......@@ -34344,7 +34344,7 @@ fn resolvePeerTypesInner(
3434434344 comptime_val = coerced_val;
3434534345 continue;
3434634346 };
34347 if (!coerced_val.eql(existing, field_ty.toType(), mod)) {
34347 if (!coerced_val.eql(existing, Type.fromInterned(field_ty.*), mod)) {
3434834348 comptime_val = null;
3434934349 break;
3435034350 }
......@@ -34359,7 +34359,7 @@ fn resolvePeerTypesInner(
3435934359 .values = field_vals,
3436034360 });
3436134361
34362 return .{ .success = final_ty.toType() };
34362 return .{ .success = Type.fromInterned(final_ty) };
3436334363 },
3436434364
3436534365 .exact => {
......@@ -34460,15 +34460,15 @@ pub fn resolveFnTypes(sema: *Sema, fn_ty: Type) CompileError!void {
3446034460 const ip = &mod.intern_pool;
3446134461 const fn_ty_info = mod.typeToFunc(fn_ty).?;
3446234462
34463 try sema.resolveTypeFully(fn_ty_info.return_type.toType());
34463 try sema.resolveTypeFully(Type.fromInterned(fn_ty_info.return_type));
3446434464
34465 if (mod.comp.bin_file.options.error_return_tracing and fn_ty_info.return_type.toType().isError(mod)) {
34465 if (mod.comp.bin_file.options.error_return_tracing and Type.fromInterned(fn_ty_info.return_type).isError(mod)) {
3446634466 // Ensure the type exists so that backends can assume that.
3446734467 _ = try sema.getBuiltinType("StackTrace");
3446834468 }
3446934469
3447034470 for (0..fn_ty_info.param_types.len) |i| {
34471 try sema.resolveTypeFully(fn_ty_info.param_types.get(ip)[i].toType());
34471 try sema.resolveTypeFully(Type.fromInterned(fn_ty_info.param_types.get(ip)[i]));
3447234472 }
3447334473}
3447434474
......@@ -34480,20 +34480,20 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {
3448034480 .int => |int| switch (int.storage) {
3448134481 .u64, .i64, .big_int => return val,
3448234482 .lazy_align, .lazy_size => return mod.intValue(
34483 int.ty.toType(),
34483 Type.fromInterned(int.ty),
3448434484 (try val.getUnsignedIntAdvanced(mod, sema)).?,
3448534485 ),
3448634486 },
3448734487 .ptr => |ptr| {
3448834488 const resolved_len = switch (ptr.len) {
3448934489 .none => .none,
34490 else => (try sema.resolveLazyValue(ptr.len.toValue())).toIntern(),
34490 else => (try sema.resolveLazyValue(Value.fromInterned(ptr.len))).toIntern(),
3449134491 };
3449234492 switch (ptr.addr) {
3449334493 .decl, .mut_decl, .anon_decl => return if (resolved_len == ptr.len)
3449434494 val
3449534495 else
34496 (try mod.intern(.{ .ptr = .{
34496 Value.fromInterned((try mod.intern(.{ .ptr = .{
3449734497 .ty = ptr.ty,
3449834498 .addr = switch (ptr.addr) {
3449934499 .decl => |decl| .{ .decl = decl },
......@@ -34502,36 +34502,36 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {
3450234502 else => unreachable,
3450334503 },
3450434504 .len = resolved_len,
34505 } })).toValue(),
34505 } }))),
3450634506 .comptime_field => |field_val| {
3450734507 const resolved_field_val =
34508 (try sema.resolveLazyValue(field_val.toValue())).toIntern();
34508 (try sema.resolveLazyValue(Value.fromInterned(field_val))).toIntern();
3450934509 return if (resolved_field_val == field_val and resolved_len == ptr.len)
3451034510 val
3451134511 else
34512 (try mod.intern(.{ .ptr = .{
34512 Value.fromInterned((try mod.intern(.{ .ptr = .{
3451334513 .ty = ptr.ty,
3451434514 .addr = .{ .comptime_field = resolved_field_val },
3451534515 .len = resolved_len,
34516 } })).toValue();
34516 } })));
3451734517 },
3451834518 .int => |int| {
34519 const resolved_int = (try sema.resolveLazyValue(int.toValue())).toIntern();
34519 const resolved_int = (try sema.resolveLazyValue(Value.fromInterned(int))).toIntern();
3452034520 return if (resolved_int == int and resolved_len == ptr.len)
3452134521 val
3452234522 else
34523 (try mod.intern(.{ .ptr = .{
34523 Value.fromInterned((try mod.intern(.{ .ptr = .{
3452434524 .ty = ptr.ty,
3452534525 .addr = .{ .int = resolved_int },
3452634526 .len = resolved_len,
34527 } })).toValue();
34527 } })));
3452834528 },
3452934529 .eu_payload, .opt_payload => |base| {
34530 const resolved_base = (try sema.resolveLazyValue(base.toValue())).toIntern();
34530 const resolved_base = (try sema.resolveLazyValue(Value.fromInterned(base))).toIntern();
3453134531 return if (resolved_base == base and resolved_len == ptr.len)
3453234532 val
3453334533 else
34534 (try mod.intern(.{ .ptr = .{
34534 Value.fromInterned((try mod.intern(.{ .ptr = .{
3453534535 .ty = ptr.ty,
3453634536 .addr = switch (ptr.addr) {
3453734537 .eu_payload => .{ .eu_payload = resolved_base },
......@@ -34539,14 +34539,14 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {
3453934539 else => unreachable,
3454034540 },
3454134541 .len = ptr.len,
34542 } })).toValue();
34542 } })));
3454334543 },
3454434544 .elem, .field => |base_index| {
34545 const resolved_base = (try sema.resolveLazyValue(base_index.base.toValue())).toIntern();
34545 const resolved_base = (try sema.resolveLazyValue(Value.fromInterned(base_index.base))).toIntern();
3454634546 return if (resolved_base == base_index.base and resolved_len == ptr.len)
3454734547 val
3454834548 else
34549 (try mod.intern(.{ .ptr = .{
34549 Value.fromInterned((try mod.intern(.{ .ptr = .{
3455034550 .ty = ptr.ty,
3455134551 .addr = switch (ptr.addr) {
3455234552 .elem => .{ .elem = .{
......@@ -34560,7 +34560,7 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {
3456034560 else => unreachable,
3456134561 },
3456234562 .len = ptr.len,
34563 } })).toValue();
34563 } })));
3456434564 },
3456534565 }
3456634566 },
......@@ -34569,37 +34569,37 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {
3456934569 .elems => |elems| {
3457034570 var resolved_elems: []InternPool.Index = &.{};
3457134571 for (elems, 0..) |elem, i| {
34572 const resolved_elem = (try sema.resolveLazyValue(elem.toValue())).toIntern();
34572 const resolved_elem = (try sema.resolveLazyValue(Value.fromInterned(elem))).toIntern();
3457334573 if (resolved_elems.len == 0 and resolved_elem != elem) {
3457434574 resolved_elems = try sema.arena.alloc(InternPool.Index, elems.len);
3457534575 @memcpy(resolved_elems[0..i], elems[0..i]);
3457634576 }
3457734577 if (resolved_elems.len > 0) resolved_elems[i] = resolved_elem;
3457834578 }
34579 return if (resolved_elems.len == 0) val else (try mod.intern(.{ .aggregate = .{
34579 return if (resolved_elems.len == 0) val else Value.fromInterned((try mod.intern(.{ .aggregate = .{
3458034580 .ty = aggregate.ty,
3458134581 .storage = .{ .elems = resolved_elems },
34582 } })).toValue();
34582 } })));
3458334583 },
3458434584 .repeated_elem => |elem| {
34585 const resolved_elem = (try sema.resolveLazyValue(elem.toValue())).toIntern();
34586 return if (resolved_elem == elem) val else (try mod.intern(.{ .aggregate = .{
34585 const resolved_elem = (try sema.resolveLazyValue(Value.fromInterned(elem))).toIntern();
34586 return if (resolved_elem == elem) val else Value.fromInterned((try mod.intern(.{ .aggregate = .{
3458734587 .ty = aggregate.ty,
3458834588 .storage = .{ .repeated_elem = resolved_elem },
34589 } })).toValue();
34589 } })));
3459034590 },
3459134591 },
3459234592 .un => |un| {
34593 const resolved_tag = (try sema.resolveLazyValue(un.tag.toValue())).toIntern();
34594 const resolved_val = (try sema.resolveLazyValue(un.val.toValue())).toIntern();
34593 const resolved_tag = (try sema.resolveLazyValue(Value.fromInterned(un.tag))).toIntern();
34594 const resolved_val = (try sema.resolveLazyValue(Value.fromInterned(un.val))).toIntern();
3459534595 return if (resolved_tag == un.tag and resolved_val == un.val)
3459634596 val
3459734597 else
34598 (try mod.intern(.{ .un = .{
34598 Value.fromInterned((try mod.intern(.{ .un = .{
3459934599 .ty = un.ty,
3460034600 .tag = resolved_tag,
3460134601 .val = resolved_val,
34602 } })).toValue();
34602 } })));
3460334603 },
3460434604 else => return val,
3460534605 }
......@@ -34641,9 +34641,9 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void {
3464134641 const ip = &mod.intern_pool;
3464234642 for (0..info.param_types.len) |i| {
3464334643 const param_ty = info.param_types.get(ip)[i];
34644 try sema.resolveTypeLayout(param_ty.toType());
34644 try sema.resolveTypeLayout(Type.fromInterned(param_ty));
3464534645 }
34646 try sema.resolveTypeLayout(info.return_type.toType());
34646 try sema.resolveTypeLayout(Type.fromInterned(info.return_type));
3464734647 },
3464834648 else => {},
3464934649 }
......@@ -34689,7 +34689,7 @@ pub fn resolveStructAlignment(
3468934689 var result: Alignment = .@"1";
3469034690
3469134691 for (0..struct_type.field_types.len) |i| {
34692 const field_ty = struct_type.field_types.get(ip)[i].toType();
34692 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
3469334693 if (struct_type.fieldIsComptime(ip, i) or try sema.typeRequiresComptime(field_ty))
3469434694 continue;
3469534695 const field_align = try sema.structFieldAlignment(
......@@ -34736,7 +34736,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3473634736 var big_align: Alignment = .@"1";
3473734737
3473834738 for (aligns, sizes, 0..) |*field_align, *field_size, i| {
34739 const field_ty = struct_type.field_types.get(ip)[i].toType();
34739 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
3474034740 if (struct_type.fieldIsComptime(ip, i) or try sema.typeRequiresComptime(field_ty)) {
3474134741 struct_type.offsets.get(ip)[i] = 0;
3474234742 field_size.* = 0;
......@@ -34786,7 +34786,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
3478634786 const runtime_order = struct_type.runtime_order.get(ip);
3478734787
3478834788 for (runtime_order, 0..) |*ro, i| {
34789 const field_ty = struct_type.field_types.get(ip)[i].toType();
34789 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
3479034790 if (struct_type.fieldIsComptime(ip, i) or try sema.typeRequiresComptime(field_ty)) {
3479134791 ro.* = .omitted;
3479234792 } else {
......@@ -34892,7 +34892,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp
3489234892 const fields_bit_sum = blk: {
3489334893 var accumulator: u64 = 0;
3489434894 for (0..struct_type.field_types.len) |i| {
34895 const field_ty = struct_type.field_types.get(ip)[i].toType();
34895 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
3489634896 accumulator += try field_ty.bitSizeAdvanced(mod, &sema);
3489734897 }
3489834898 break :blk accumulator;
......@@ -35018,7 +35018,7 @@ pub fn resolveUnionAlignment(
3501835018 const union_obj = ip.loadUnionType(union_type);
3501935019 var max_align: Alignment = .@"1";
3502035020 for (0..union_obj.field_names.len) |field_index| {
35021 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
35021 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3502235022 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
3502335023
3502435024 const explicit_align = union_obj.fieldAlign(ip, @intCast(field_index));
......@@ -35067,7 +35067,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3506735067 var max_size: u64 = 0;
3506835068 var max_align: Alignment = .@"1";
3506935069 for (0..union_obj.field_names.len) |field_index| {
35070 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
35070 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3507135071 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
3507235072
3507335073 max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) {
......@@ -35089,9 +35089,9 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3508935089 }
3509035090
3509135091 const flags = union_obj.flagsPtr(ip);
35092 const has_runtime_tag = flags.runtime_tag.hasTag() and try sema.typeHasRuntimeBits(union_obj.enum_tag_ty.toType());
35092 const has_runtime_tag = flags.runtime_tag.hasTag() and try sema.typeHasRuntimeBits(Type.fromInterned(union_obj.enum_tag_ty));
3509335093 const size, const alignment, const padding = if (has_runtime_tag) layout: {
35094 const enum_tag_type = union_obj.enum_tag_ty.toType();
35094 const enum_tag_type = Type.fromInterned(union_obj.enum_tag_ty);
3509535095 const tag_align = try sema.typeAbiAlignment(enum_tag_type);
3509635096 const tag_size = try sema.typeAbiSize(enum_tag_type);
3509735097
......@@ -35161,7 +35161,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {
3516135161 .struct_type => return sema.resolveStructFully(ty),
3516235162 .anon_struct_type => |tuple| {
3516335163 for (tuple.types.get(ip)) |field_ty| {
35164 try sema.resolveTypeFully(field_ty.toType());
35164 try sema.resolveTypeFully(Type.fromInterned(field_ty));
3516535165 }
3516635166 },
3516735167 .simple_type => |simple_type| try sema.resolveSimpleType(simple_type),
......@@ -35182,9 +35182,9 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {
3518235182 }
3518335183 for (0..info.param_types.len) |i| {
3518435184 const param_ty = info.param_types.get(ip)[i];
35185 try sema.resolveTypeFully(param_ty.toType());
35185 try sema.resolveTypeFully(Type.fromInterned(param_ty));
3518635186 }
35187 try sema.resolveTypeFully(info.return_type.toType());
35187 try sema.resolveTypeFully(Type.fromInterned(info.return_type));
3518835188 },
3518935189 else => {},
3519035190 }
......@@ -35205,7 +35205,7 @@ fn resolveStructFully(sema: *Sema, ty: Type) CompileError!void {
3520535205 // See also similar code for unions.
3520635206
3520735207 for (0..struct_type.field_types.len) |i| {
35208 const field_ty = struct_type.field_types.get(ip)[i].toType();
35208 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
3520935209 try sema.resolveTypeFully(field_ty);
3521035210 }
3521135211}
......@@ -35230,7 +35230,7 @@ fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void {
3523035230
3523135231 union_obj.flagsPtr(ip).status = .fully_resolved_wip;
3523235232 for (0..union_obj.field_types.len) |field_index| {
35233 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
35233 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3523435234 try sema.resolveTypeFully(field_ty);
3523535235 }
3523635236 union_obj.flagsPtr(ip).status = .fully_resolved;
......@@ -35333,7 +35333,7 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!void {
3533335333 .type_struct_packed_inits,
3533435334 => try sema.resolveTypeFieldsStruct(ty_ip, ip.indexToKey(ty_ip).struct_type),
3533535335
35336 .type_union => try sema.resolveTypeFieldsUnion(ty_ip.toType(), ip.indexToKey(ty_ip).union_type),
35336 .type_union => try sema.resolveTypeFieldsUnion(Type.fromInterned(ty_ip), ip.indexToKey(ty_ip).union_type),
3533735337 .simple_type => try sema.resolveSimpleType(ip.indexToKey(ty_ip).simple_type),
3533835338 else => {},
3533935339 },
......@@ -35392,7 +35392,7 @@ pub fn resolveTypeFieldsStruct(
3539235392 sema.gpa,
3539335393 mod.declPtr(owner_decl).srcLoc(mod),
3539435394 "struct '{}' depends on itself",
35395 .{ty.toType().fmt(mod)},
35395 .{Type.fromInterned(ty).fmt(mod)},
3539635396 );
3539735397 return sema.failWithOwnedErrorMsg(null, msg);
3539835398 }
......@@ -36042,7 +36042,7 @@ fn semaStructFieldInits(
3604236042 // In init bodies, the zir index of the struct itself is used
3604336043 // to refer to the current field type.
3604436044
36045 const field_ty = struct_type.field_types.get(ip)[field_i].toType();
36045 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_i]);
3604636046 const type_ref = Air.internedToRef(field_ty.toIntern());
3604736047 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index});
3604836048 sema.inst_map.putAssumeCapacity(zir_index, type_ref);
......@@ -36368,10 +36368,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3636836368 .range = .type,
3636936369 }).lazy;
3637036370 const msg = try sema.errMsg(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{
36371 field_name.fmt(ip), union_type.tagTypePtr(ip).toType().fmt(mod),
36371 field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod),
3637236372 });
3637336373 errdefer msg.destroy(sema.gpa);
36374 try sema.addDeclaredHereNote(msg, union_type.tagTypePtr(ip).toType());
36374 try sema.addDeclaredHereNote(msg, Type.fromInterned(union_type.tagTypePtr(ip).*));
3637536375 break :msg msg;
3637636376 };
3637736377 return sema.failWithOwnedErrorMsg(&block_scope, msg);
......@@ -36483,11 +36483,11 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3648336483
3648436484 for (tag_info.names.get(ip), 0..) |field_name, field_index| {
3648536485 if (explicit_tags_seen[field_index]) continue;
36486 try sema.addFieldErrNote(union_type.tagTypePtr(ip).toType(), field_index, msg, "field '{}' missing, declared here", .{
36486 try sema.addFieldErrNote(Type.fromInterned(union_type.tagTypePtr(ip).*), field_index, msg, "field '{}' missing, declared here", .{
3648736487 field_name.fmt(ip),
3648836488 });
3648936489 }
36490 try sema.addDeclaredHereNote(msg, union_type.tagTypePtr(ip).toType());
36490 try sema.addDeclaredHereNote(msg, Type.fromInterned(union_type.tagTypePtr(ip).*));
3649136491 break :msg msg;
3649236492 };
3649336493 return sema.failWithOwnedErrorMsg(&block_scope, msg);
......@@ -36548,7 +36548,7 @@ fn generateUnionTagTypeNumbered(
3654836548 });
3654936549
3655036550 new_decl.ty = Type.type;
36551 new_decl.val = enum_ty.toValue();
36551 new_decl.val = Value.fromInterned(enum_ty);
3655236552
3655336553 try mod.finalizeAnonDecl(new_decl_index);
3655436554 return enum_ty;
......@@ -36600,7 +36600,7 @@ fn generateUnionTagTypeSimple(
3660036600 const new_decl = mod.declPtr(new_decl_index);
3660136601 new_decl.owns_tv = true;
3660236602 new_decl.ty = Type.type;
36603 new_decl.val = enum_ty.toValue();
36603 new_decl.val = Value.fromInterned(enum_ty);
3660436604
3660536605 try mod.finalizeAnonDecl(new_decl_index);
3660636606 return enum_ty;
......@@ -36869,16 +36869,16 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3686936869 => switch (ip.indexToKey(ty.toIntern())) {
3687036870 inline .array_type, .vector_type => |seq_type, seq_tag| {
3687136871 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;
36872 if (seq_type.len + @intFromBool(has_sentinel) == 0) return (try mod.intern(.{ .aggregate = .{
36872 if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3687336873 .ty = ty.toIntern(),
3687436874 .storage = .{ .elems = &.{} },
36875 } })).toValue();
36875 } })));
3687636876
36877 if (try sema.typeHasOnePossibleValue(seq_type.child.toType())) |opv| {
36878 return (try mod.intern(.{ .aggregate = .{
36877 if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| {
36878 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3687936879 .ty = ty.toIntern(),
3688036880 .storage = .{ .repeated_elem = opv.toIntern() },
36881 } })).toValue();
36881 } })));
3688236882 }
3688336883 return null;
3688436884 },
......@@ -36889,10 +36889,10 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3688936889 if (struct_type.field_types.len == 0) {
3689036890 // In this case the struct has no fields at all and
3689136891 // therefore has one possible value.
36892 return (try mod.intern(.{ .aggregate = .{
36892 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3689336893 .ty = ty.toIntern(),
3689436894 .storage = .{ .elems = &.{} },
36895 } })).toValue();
36895 } })));
3689636896 }
3689736897
3689836898 const field_vals = try sema.arena.alloc(
......@@ -36905,7 +36905,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3690536905 field_val.* = struct_type.field_inits.get(ip)[i];
3690636906 continue;
3690736907 }
36908 const field_ty = struct_type.field_types.get(ip)[i].toType();
36908 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
3690936909 if (field_ty.eql(ty, mod)) {
3691036910 const msg = try Module.ErrorMsg.create(
3691136911 sema.gpa,
......@@ -36923,10 +36923,10 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3692336923
3692436924 // In this case the struct has no runtime-known fields and
3692536925 // therefore has one possible value.
36926 return (try mod.intern(.{ .aggregate = .{
36926 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3692736927 .ty = ty.toIntern(),
3692836928 .storage = .{ .elems = field_vals },
36929 } })).toValue();
36929 } })));
3693036930 },
3693136931
3693236932 .anon_struct_type => |tuple| {
......@@ -36936,22 +36936,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3693636936 // In this case the struct has all comptime-known fields and
3693736937 // therefore has one possible value.
3693836938 // TODO: write something like getCoercedInts to avoid needing to dupe
36939 return (try mod.intern(.{ .aggregate = .{
36939 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3694036940 .ty = ty.toIntern(),
3694136941 .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) },
36942 } })).toValue();
36942 } })));
3694336943 },
3694436944
3694536945 .union_type => |union_type| {
3694636946 try sema.resolveTypeFields(ty);
3694736947 const union_obj = ip.loadUnionType(union_type);
36948 const tag_val = (try sema.typeHasOnePossibleValue(union_obj.enum_tag_ty.toType())) orelse
36948 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.enum_tag_ty))) orelse
3694936949 return null;
3695036950 if (union_obj.field_types.len == 0) {
3695136951 const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() });
36952 return only.toValue();
36952 return Value.fromInterned(only);
3695336953 }
36954 const only_field_ty = union_obj.field_types.get(ip)[0].toType();
36954 const only_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);
3695536955 if (only_field_ty.eql(ty, mod)) {
3695636956 const msg = try Module.ErrorMsg.create(
3695736957 sema.gpa,
......@@ -36969,32 +36969,32 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3696936969 .tag = tag_val.toIntern(),
3697036970 .val = val_val.toIntern(),
3697136971 } });
36972 return only.toValue();
36972 return Value.fromInterned(only);
3697336973 },
3697436974
3697536975 .enum_type => |enum_type| switch (enum_type.tag_mode) {
3697636976 .nonexhaustive => {
3697736977 if (enum_type.tag_ty == .comptime_int_type) return null;
3697836978
36979 if (try sema.typeHasOnePossibleValue(enum_type.tag_ty.toType())) |int_opv| {
36979 if (try sema.typeHasOnePossibleValue(Type.fromInterned(enum_type.tag_ty))) |int_opv| {
3698036980 const only = try mod.intern(.{ .enum_tag = .{
3698136981 .ty = ty.toIntern(),
3698236982 .int = int_opv.toIntern(),
3698336983 } });
36984 return only.toValue();
36984 return Value.fromInterned(only);
3698536985 }
3698636986
3698736987 return null;
3698836988 },
3698936989 .auto, .explicit => {
36990 if (enum_type.tag_ty.toType().hasRuntimeBits(mod)) return null;
36990 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(mod)) return null;
3699136991
36992 return switch (enum_type.names.len) {
36992 return Value.fromInterned(switch (enum_type.names.len) {
3699336993 0 => try mod.intern(.{ .empty_enum_value = ty.toIntern() }),
3699436994 1 => try mod.intern(.{ .enum_tag = .{
3699536995 .ty = ty.toIntern(),
3699636996 .int = if (enum_type.values.len == 0)
36997 (try mod.intValue(enum_type.tag_ty.toType(), 0)).toIntern()
36997 (try mod.intValue(Type.fromInterned(enum_type.tag_ty), 0)).toIntern()
3699836998 else
3699936999 try mod.intern_pool.getCoercedInts(
3700037000 mod.gpa,
......@@ -37003,7 +37003,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3700337003 ),
3700437004 } }),
3700537005 else => return null,
37006 }.toValue();
37006 });
3700737007 },
3700837008 },
3700937009
......@@ -37092,7 +37092,7 @@ fn analyzeComptimeAlloc(
3709237092 // There will be stores before the first load, but they may be to sub-elements or
3709337093 // sub-fields. So we need to initialize with undef to allow the mechanism to expand
3709437094 // into fields/elements and have those overridden with stored values.
37095 (try mod.intern(.{ .undef = var_type.toIntern() })).toValue(),
37095 Value.fromInterned((try mod.intern(.{ .undef = var_type.toIntern() }))),
3709637096 alignment,
3709737097 );
3709837098 const decl = mod.declPtr(decl_index);
......@@ -37226,7 +37226,7 @@ fn pointerDerefExtra(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value
3722637226 // Move mutable decl values to the InternPool and assert other decls are already in
3722737227 // the InternPool.
3722837228 const uncoerced_val = if (deref.is_mutable) try tv.val.intern(tv.ty, mod) else tv.val.toIntern();
37229 const coerced_val = try mod.getCoerced(uncoerced_val.toValue(), load_ty);
37229 const coerced_val = try mod.getCoerced(Value.fromInterned(uncoerced_val), load_ty);
3723037230 return .{ .val = coerced_val };
3723137231 }
3723237232 }
......@@ -37284,7 +37284,7 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
3728437284 if (ptr_type.flags.is_allowzero) return null;
3728537285
3728637286 // optionals of zero sized types behave like bools, not pointers
37287 const payload_ty = opt_child.toType();
37287 const payload_ty = Type.fromInterned(opt_child);
3728837288 if ((try sema.typeHasOnePossibleValue(payload_ty)) != null) {
3728937289 return null;
3729037290 }
......@@ -37328,7 +37328,7 @@ fn unionFieldAlignment(sema: *Sema, u: InternPool.UnionType, field_index: u32) !
3732837328 const ip = &mod.intern_pool;
3732937329 const field_align = u.fieldAlign(ip, field_index);
3733037330 if (field_align != .none) return field_align;
37331 const field_ty = u.field_types.get(ip)[field_index].toType();
37331 const field_ty = Type.fromInterned(u.field_types.get(ip)[field_index]);
3733237332 if (field_ty.isNoReturn(sema.mod)) return .none;
3733337333 return sema.typeAbiAlignment(field_ty);
3733437334}
......@@ -37458,10 +37458,10 @@ fn intAddInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usi
3745837458 };
3745937459 scalar.* = try val.intern(scalar_ty, mod);
3746037460 }
37461 return (try mod.intern(.{ .aggregate = .{
37461 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3746237462 .ty = ty.toIntern(),
3746337463 .storage = .{ .elems = result_data },
37464 } })).toValue();
37464 } })));
3746537465 }
3746637466 return sema.intAddScalar(lhs, rhs, ty);
3746737467}
......@@ -37548,10 +37548,10 @@ fn intSubInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usi
3754837548 };
3754937549 scalar.* = try val.intern(scalar_ty, mod);
3755037550 }
37551 return (try mod.intern(.{ .aggregate = .{
37551 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3755237552 .ty = ty.toIntern(),
3755337553 .storage = .{ .elems = result_data },
37554 } })).toValue();
37554 } })));
3755537555 }
3755637556 return sema.intSubScalar(lhs, rhs, ty);
3755737557}
......@@ -37620,14 +37620,14 @@ fn intSubWithOverflow(
3762037620 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
3762137621 }
3762237622 return Value.OverflowArithmeticResult{
37623 .overflow_bit = (try mod.intern(.{ .aggregate = .{
37623 .overflow_bit = Value.fromInterned((try mod.intern(.{ .aggregate = .{
3762437624 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),
3762537625 .storage = .{ .elems = overflowed_data },
37626 } })).toValue(),
37627 .wrapped_result = (try mod.intern(.{ .aggregate = .{
37626 } }))),
37627 .wrapped_result = Value.fromInterned((try mod.intern(.{ .aggregate = .{
3762837628 .ty = ty.toIntern(),
3762937629 .storage = .{ .elems = result_data },
37630 } })).toValue(),
37630 } }))),
3763137631 };
3763237632 }
3763337633 return sema.intSubWithOverflowScalar(lhs, rhs, ty);
......@@ -37679,10 +37679,10 @@ fn intFromFloat(
3767937679 const elem_val = try val.elemValue(sema.mod, i);
3768037680 scalar.* = try (try sema.intFromFloatScalar(block, src, elem_val, elem_ty, int_ty.scalarType(mod), mode)).intern(scalar_ty, mod);
3768137681 }
37682 return (try mod.intern(.{ .aggregate = .{
37682 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3768337683 .ty = int_ty.toIntern(),
3768437684 .storage = .{ .elems = result_data },
37685 } })).toValue();
37685 } })));
3768637686 }
3768737687 return sema.intFromFloatScalar(block, src, val, float_ty, int_ty, mode);
3768837688}
......@@ -37792,7 +37792,7 @@ fn intFitsInType(
3779237792 const max_needed_bits = @as(u16, 16) + @intFromBool(info.signedness == .signed);
3779337793 // If it is u16 or bigger we know the alignment fits without resolving it.
3779437794 if (info.bits >= max_needed_bits) return true;
37795 const x = try sema.typeAbiAlignment(lazy_ty.toType());
37795 const x = try sema.typeAbiAlignment(Type.fromInterned(lazy_ty));
3779637796 if (x == .none) return true;
3779737797 const actual_needed_bits = @as(usize, x.toLog2Units()) + 1 + @intFromBool(info.signedness == .signed);
3779837798 return info.bits >= actual_needed_bits;
......@@ -37801,7 +37801,7 @@ fn intFitsInType(
3780137801 const max_needed_bits = @as(u16, 64) + @intFromBool(info.signedness == .signed);
3780237802 // If it is u64 or bigger we know the size fits without resolving it.
3780337803 if (info.bits >= max_needed_bits) return true;
37804 const x = try sema.typeAbiSize(lazy_ty.toType());
37804 const x = try sema.typeAbiSize(Type.fromInterned(lazy_ty));
3780537805 if (x == 0) return true;
3780637806 const actual_needed_bits = std.math.log2(x) + 1 + @intFromBool(info.signedness == .signed);
3780737807 return info.bits >= actual_needed_bits;
......@@ -37822,7 +37822,7 @@ fn intFitsInType(
3782237822 .elems => |elems| elems,
3782337823 .repeated_elem => |elem| @as(*const [1]InternPool.Index, &elem),
3782437824 }, 0..) |elem, i| {
37825 if (try sema.intFitsInType(elem.toValue(), ty.scalarType(mod), null)) continue;
37825 if (try sema.intFitsInType(Value.fromInterned(elem), ty.scalarType(mod), null)) continue;
3782637826 if (vector_index) |vi| vi.* = i;
3782737827 break false;
3782837828 } else true,
......@@ -37848,8 +37848,8 @@ fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {
3784837848 assert(enum_type.tag_mode != .nonexhaustive);
3784937849 // The `tagValueIndex` function call below relies on the type being the integer tag type.
3785037850 // `getCoerced` assumes the value will fit the new type.
37851 if (!(try sema.intFitsInType(int, enum_type.tag_ty.toType(), null))) return false;
37852 const int_coerced = try mod.getCoerced(int, enum_type.tag_ty.toType());
37851 if (!(try sema.intFitsInType(int, Type.fromInterned(enum_type.tag_ty), null))) return false;
37852 const int_coerced = try mod.getCoerced(int, Type.fromInterned(enum_type.tag_ty));
3785337853
3785437854 return enum_type.tagValueIndex(&mod.intern_pool, int_coerced.toIntern()) != null;
3785537855}
......@@ -37874,14 +37874,14 @@ fn intAddWithOverflow(
3787437874 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
3787537875 }
3787637876 return Value.OverflowArithmeticResult{
37877 .overflow_bit = (try mod.intern(.{ .aggregate = .{
37877 .overflow_bit = Value.fromInterned((try mod.intern(.{ .aggregate = .{
3787837878 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),
3787937879 .storage = .{ .elems = overflowed_data },
37880 } })).toValue(),
37881 .wrapped_result = (try mod.intern(.{ .aggregate = .{
37880 } }))),
37881 .wrapped_result = Value.fromInterned((try mod.intern(.{ .aggregate = .{
3788237882 .ty = ty.toIntern(),
3788337883 .storage = .{ .elems = result_data },
37884 } })).toValue(),
37884 } }))),
3788537885 };
3788637886 }
3788737887 return sema.intAddWithOverflowScalar(lhs, rhs, ty);
......@@ -37983,10 +37983,10 @@ fn compareVector(
3798337983 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod));
3798437984 scalar.* = try Value.makeBool(res_bool).intern(Type.bool, mod);
3798537985 }
37986 return (try mod.intern(.{ .aggregate = .{
37986 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3798737987 .ty = (try mod.vectorType(.{ .len = ty.vectorLen(mod), .child = .bool_type })).toIntern(),
3798837988 .storage = .{ .elems = result_data },
37989 } })).toValue();
37989 } })));
3799037990}
3799137991
3799237992/// Returns the type of a pointer to an element.
......@@ -38102,7 +38102,7 @@ fn isKnownZigType(sema: *Sema, ref: Air.Inst.Ref, tag: std.builtin.TypeId) bool
3810238102
3810338103fn ptrType(sema: *Sema, info: InternPool.Key.PtrType) CompileError!Type {
3810438104 if (info.flags.alignment != .none) {
38105 _ = try sema.typeAbiAlignment(info.child.toType());
38105 _ = try sema.typeAbiAlignment(Type.fromInterned(info.child));
3810638106 }
3810738107 return sema.mod.ptrType(info);
3810838108}
src/TypedValue.zig+25-25
......@@ -89,7 +89,7 @@ pub fn print(
8989
9090 if (payload.tag) |tag| {
9191 try print(.{
92 .ty = ip.indexToKey(ty.toIntern()).union_type.enum_tag_ty.toType(),
92 .ty = Type.fromInterned(ip.indexToKey(ty.toIntern()).union_type.enum_tag_ty),
9393 .val = tag,
9494 }, writer, level - 1, mod);
9595 try writer.writeAll(" = ");
......@@ -222,10 +222,10 @@ pub fn print(
222222 .int => |int| switch (int.storage) {
223223 inline .u64, .i64, .big_int => |x| return writer.print("{}", .{x}),
224224 .lazy_align => |lazy_ty| return writer.print("{d}", .{
225 lazy_ty.toType().abiAlignment(mod),
225 Type.fromInterned(lazy_ty).abiAlignment(mod),
226226 }),
227227 .lazy_size => |lazy_ty| return writer.print("{d}", .{
228 lazy_ty.toType().abiSize(mod),
228 Type.fromInterned(lazy_ty).abiSize(mod),
229229 }),
230230 },
231231 .err => |err| return writer.print("error.{}", .{
......@@ -236,7 +236,7 @@ pub fn print(
236236 err_name.fmt(ip),
237237 }),
238238 .payload => |payload| {
239 val = payload.toValue();
239 val = Value.fromInterned(payload);
240240 ty = ty.errorUnionPayload(mod);
241241 },
242242 },
......@@ -254,8 +254,8 @@ pub fn print(
254254 }
255255 try writer.writeAll("@enumFromInt(");
256256 try print(.{
257 .ty = ip.typeOf(enum_tag.int).toType(),
258 .val = enum_tag.int.toValue(),
257 .ty = Type.fromInterned(ip.typeOf(enum_tag.int)),
258 .val = Value.fromInterned(enum_tag.int),
259259 }, writer, level - 1, mod);
260260 try writer.writeAll(")");
261261 return;
......@@ -280,8 +280,8 @@ pub fn print(
280280 if (level == 0) {
281281 return writer.writeAll(".{ ... }");
282282 }
283 const elem_ty = ptr_ty.child.toType();
284 const len = ptr.len.toValue().toUnsignedInt(mod);
283 const elem_ty = Type.fromInterned(ptr_ty.child);
284 const len = Value.fromInterned(ptr.len).toUnsignedInt(mod);
285285 if (elem_ty.eql(Type.u8, mod)) str: {
286286 const max_len = @min(len, max_string_len);
287287 var buf: [max_string_len]u8 = undefined;
......@@ -326,8 +326,8 @@ pub fn print(
326326 @intFromEnum(decl_val),
327327 });
328328 return print(.{
329 .ty = ip.typeOf(decl_val).toType(),
330 .val = decl_val.toValue(),
329 .ty = Type.fromInterned(ip.typeOf(decl_val)),
330 .val = Value.fromInterned(decl_val),
331331 }, writer, level - 1, mod);
332332 },
333333 .mut_decl => |mut_decl| {
......@@ -340,38 +340,38 @@ pub fn print(
340340 },
341341 .comptime_field => |field_val_ip| {
342342 return print(.{
343 .ty = ip.typeOf(field_val_ip).toType(),
344 .val = field_val_ip.toValue(),
343 .ty = Type.fromInterned(ip.typeOf(field_val_ip)),
344 .val = Value.fromInterned(field_val_ip),
345345 }, writer, level - 1, mod);
346346 },
347347 .int => unreachable,
348348 .eu_payload => |eu_ip| {
349349 try writer.writeAll("(payload of ");
350350 try print(.{
351 .ty = ip.typeOf(eu_ip).toType(),
352 .val = eu_ip.toValue(),
351 .ty = Type.fromInterned(ip.typeOf(eu_ip)),
352 .val = Value.fromInterned(eu_ip),
353353 }, writer, level - 1, mod);
354354 try writer.writeAll(")");
355355 },
356356 .opt_payload => |opt_ip| {
357357 try print(.{
358 .ty = ip.typeOf(opt_ip).toType(),
359 .val = opt_ip.toValue(),
358 .ty = Type.fromInterned(ip.typeOf(opt_ip)),
359 .val = Value.fromInterned(opt_ip),
360360 }, writer, level - 1, mod);
361361 try writer.writeAll(".?");
362362 },
363363 .elem => |elem| {
364364 try print(.{
365 .ty = ip.typeOf(elem.base).toType(),
366 .val = elem.base.toValue(),
365 .ty = Type.fromInterned(ip.typeOf(elem.base)),
366 .val = Value.fromInterned(elem.base),
367367 }, writer, level - 1, mod);
368368 try writer.print("[{}]", .{elem.index});
369369 },
370370 .field => |field| {
371 const ptr_container_ty = ip.typeOf(field.base).toType();
371 const ptr_container_ty = Type.fromInterned(ip.typeOf(field.base));
372372 try print(.{
373373 .ty = ptr_container_ty,
374 .val = field.base.toValue(),
374 .val = Value.fromInterned(field.base),
375375 }, writer, level - 1, mod);
376376
377377 const container_ty = ptr_container_ty.childType(mod);
......@@ -404,7 +404,7 @@ pub fn print(
404404 .opt => |opt| switch (opt.val) {
405405 .none => return writer.writeAll("null"),
406406 else => |payload| {
407 val = payload.toValue();
407 val = Value.fromInterned(payload);
408408 ty = ty.optionalChild(mod);
409409 },
410410 },
......@@ -426,20 +426,20 @@ pub fn print(
426426 if (un.tag != .none) {
427427 try print(.{
428428 .ty = ty.unionTagTypeHypothetical(mod),
429 .val = un.tag.toValue(),
429 .val = Value.fromInterned(un.tag),
430430 }, writer, level - 1, mod);
431431 try writer.writeAll(" = ");
432 const field_ty = ty.unionFieldType(un.tag.toValue(), mod).?;
432 const field_ty = ty.unionFieldType(Value.fromInterned(un.tag), mod).?;
433433 try print(.{
434434 .ty = field_ty,
435 .val = un.val.toValue(),
435 .val = Value.fromInterned(un.val),
436436 }, writer, level - 1, mod);
437437 } else {
438438 try writer.writeAll("(unknown tag) = ");
439439 const backing_ty = try ty.unionBackingType(mod);
440440 try print(.{
441441 .ty = backing_ty,
442 .val = un.val.toValue(),
442 .val = Value.fromInterned(un.val),
443443 }, writer, level - 1, mod);
444444 }
445445 } else try writer.writeAll("...");
src/arch/aarch64/CodeGen.zig+7-7
......@@ -6245,7 +6245,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62456245 }
62466246
62476247 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
6248 const param_size = @as(u32, @intCast(ty.toType().abiSize(mod)));
6248 const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(mod)));
62496249 if (param_size == 0) {
62506250 result_arg.* = .{ .none = {} };
62516251 continue;
......@@ -6253,14 +6253,14 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62536253
62546254 // We round up NCRN only for non-Apple platforms which allow the 16-byte aligned
62556255 // values to spread across odd-numbered registers.
6256 if (ty.toType().abiAlignment(mod) == .@"16" and !self.target.isDarwin()) {
6256 if (Type.fromInterned(ty).abiAlignment(mod) == .@"16" and !self.target.isDarwin()) {
62576257 // Round up NCRN to the next even number
62586258 ncrn += ncrn % 2;
62596259 }
62606260
62616261 if (std.math.divCeil(u32, param_size, 8) catch unreachable <= 8 - ncrn) {
62626262 if (param_size <= 8) {
6263 result_arg.* = .{ .register = self.registerAlias(c_abi_int_param_regs[ncrn], ty.toType()) };
6263 result_arg.* = .{ .register = self.registerAlias(c_abi_int_param_regs[ncrn], Type.fromInterned(ty)) };
62646264 ncrn += 1;
62656265 } else {
62666266 return self.fail("TODO MCValues with multiple registers", .{});
......@@ -6271,7 +6271,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62716271 ncrn = 8;
62726272 // TODO Apple allows the arguments on the stack to be non-8-byte aligned provided
62736273 // that the entire stack space consumed by the arguments is 8-byte aligned.
6274 if (ty.toType().abiAlignment(mod) == .@"8") {
6274 if (Type.fromInterned(ty).abiAlignment(mod) == .@"8") {
62756275 if (nsaa % 8 != 0) {
62766276 nsaa += 8 - (nsaa % 8);
62776277 }
......@@ -6310,9 +6310,9 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
63106310 var stack_offset: u32 = 0;
63116311
63126312 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
6313 if (ty.toType().abiSize(mod) > 0) {
6314 const param_size: u32 = @intCast(ty.toType().abiSize(mod));
6315 const param_alignment = ty.toType().abiAlignment(mod);
6313 if (Type.fromInterned(ty).abiSize(mod) > 0) {
6314 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(mod));
6315 const param_alignment = Type.fromInterned(ty).abiAlignment(mod);
63166316
63176317 stack_offset = @intCast(param_alignment.forward(stack_offset));
63186318 result_arg.* = .{ .stack_argument_offset = stack_offset };
src/arch/aarch64/abi.zig+2-2
......@@ -83,7 +83,7 @@ fn countFloats(ty: Type, mod: *Module, maybe_float_bits: *?u16) u8 {
8383 const union_obj = mod.typeToUnion(ty).?;
8484 var max_count: u8 = 0;
8585 for (union_obj.field_types.get(ip)) |field_ty| {
86 const field_count = countFloats(field_ty.toType(), mod, maybe_float_bits);
86 const field_count = countFloats(Type.fromInterned(field_ty), mod, maybe_float_bits);
8787 if (field_count == invalid) return invalid;
8888 if (field_count > max_count) max_count = field_count;
8989 if (max_count > sret_float_count) return invalid;
......@@ -122,7 +122,7 @@ pub fn getFloatArrayType(ty: Type, mod: *Module) ?Type {
122122 .Union => {
123123 const union_obj = mod.typeToUnion(ty).?;
124124 for (union_obj.field_types.get(ip)) |field_ty| {
125 if (getFloatArrayType(field_ty.toType(), mod)) |some| return some;
125 if (getFloatArrayType(Type.fromInterned(field_ty), mod)) |some| return some;
126126 }
127127 return null;
128128 },
src/arch/arm/CodeGen.zig+6-6
......@@ -6209,10 +6209,10 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62096209 }
62106210
62116211 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
6212 if (ty.toType().abiAlignment(mod) == .@"8")
6212 if (Type.fromInterned(ty).abiAlignment(mod) == .@"8")
62136213 ncrn = std.mem.alignForward(usize, ncrn, 2);
62146214
6215 const param_size = @as(u32, @intCast(ty.toType().abiSize(mod)));
6215 const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(mod)));
62166216 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {
62176217 if (param_size <= 4) {
62186218 result_arg.* = .{ .register = c_abi_int_param_regs[ncrn] };
......@@ -6224,7 +6224,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62246224 return self.fail("TODO MCValues split between registers and stack", .{});
62256225 } else {
62266226 ncrn = 4;
6227 if (ty.toType().abiAlignment(mod) == .@"8")
6227 if (Type.fromInterned(ty).abiAlignment(mod) == .@"8")
62286228 nsaa = std.mem.alignForward(u32, nsaa, 8);
62296229
62306230 result_arg.* = .{ .stack_argument_offset = nsaa };
......@@ -6259,9 +6259,9 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62596259 var stack_offset: u32 = 0;
62606260
62616261 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
6262 if (ty.toType().abiSize(mod) > 0) {
6263 const param_size: u32 = @intCast(ty.toType().abiSize(mod));
6264 const param_alignment = ty.toType().abiAlignment(mod);
6262 if (Type.fromInterned(ty).abiSize(mod) > 0) {
6263 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(mod));
6264 const param_alignment = Type.fromInterned(ty).abiAlignment(mod);
62656265
62666266 stack_offset = @intCast(param_alignment.forward(stack_offset));
62676267 result_arg.* = .{ .stack_argument_offset = stack_offset };
src/arch/arm/abi.zig+2-2
......@@ -65,7 +65,7 @@ pub fn classifyType(ty: Type, mod: *Module, ctx: Context) Class {
6565 if (float_count <= byval_float_count) return .byval;
6666
6767 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
68 if (field_ty.toType().bitSize(mod) > 32 or
68 if (Type.fromInterned(field_ty).bitSize(mod) > 32 or
6969 mod.unionFieldNormalAlignment(union_obj, @intCast(field_index)).compare(.gt, .@"32"))
7070 {
7171 return Class.arrSize(bit_size, 64);
......@@ -129,7 +129,7 @@ fn countFloats(ty: Type, mod: *Module, maybe_float_bits: *?u16) u32 {
129129 const union_obj = mod.typeToUnion(ty).?;
130130 var max_count: u32 = 0;
131131 for (union_obj.field_types.get(ip)) |field_ty| {
132 const field_count = countFloats(field_ty.toType(), mod, maybe_float_bits);
132 const field_count = countFloats(Type.fromInterned(field_ty), mod, maybe_float_bits);
133133 if (field_count == invalid) return invalid;
134134 if (field_count > max_count) max_count = field_count;
135135 if (max_count > byval_float_count) return invalid;
src/arch/riscv64/CodeGen.zig+1-1
......@@ -2656,7 +2656,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
26562656 const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 };
26572657
26582658 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
2659 const param_size = @as(u32, @intCast(ty.toType().abiSize(mod)));
2659 const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(mod)));
26602660 if (param_size <= 8) {
26612661 if (next_register < argument_registers.len) {
26622662 result_arg.* = .{ .register = argument_registers[next_register] };
src/arch/sparc64/CodeGen.zig+1-1
......@@ -4493,7 +4493,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
44934493 };
44944494
44954495 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
4496 const param_size = @as(u32, @intCast(ty.toType().abiSize(mod)));
4496 const param_size = @as(u32, @intCast(Type.fromInterned(ty).abiSize(mod)));
44974497 if (param_size <= 8) {
44984498 if (next_register < argument_registers.len) {
44994499 result_arg.* = .{ .register = argument_registers[next_register] };
src/arch/wasm/CodeGen.zig+42-42
......@@ -1009,7 +1009,7 @@ fn typeToValtype(ty: Type, mod: *Module) wasm.Valtype {
10091009 },
10101010 .Struct => {
10111011 if (mod.typeToPackedStruct(ty)) |packed_struct| {
1012 return typeToValtype(packed_struct.backingIntType(ip).toType(), mod);
1012 return typeToValtype(Type.fromInterned(packed_struct.backingIntType(ip).*), mod);
10131013 } else {
10141014 return wasm.Valtype.i32;
10151015 }
......@@ -1171,7 +1171,7 @@ fn genFunctype(
11711171
11721172 // param types
11731173 for (params) |param_type_ip| {
1174 const param_type = param_type_ip.toType();
1174 const param_type = Type.fromInterned(param_type_ip);
11751175 if (!param_type.hasRuntimeBitsIgnoreComptime(mod)) continue;
11761176
11771177 switch (cc) {
......@@ -1240,7 +1240,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
12401240 const mod = func.bin_file.base.options.module.?;
12411241 const ip = &mod.intern_pool;
12421242 const fn_info = mod.typeToFunc(func.decl.ty).?;
1243 var func_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types.get(ip), fn_info.return_type.toType(), mod);
1243 var func_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types.get(ip), Type.fromInterned(fn_info.return_type), mod);
12441244 defer func_type.deinit(func.gpa);
12451245 _ = try func.bin_file.storeDeclType(func.decl_index, func_type);
12461246
......@@ -1363,7 +1363,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
13631363
13641364 // Check if we store the result as a pointer to the stack rather than
13651365 // by value
1366 if (firstParamSRet(fn_info.cc, fn_info.return_type.toType(), mod)) {
1366 if (firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), mod)) {
13671367 // the sret arg will be passed as first argument, therefore we
13681368 // set the `return_value` before allocating locals for regular args.
13691369 result.return_value = .{ .local = .{ .value = func.local_index, .references = 1 } };
......@@ -1373,7 +1373,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
13731373 switch (cc) {
13741374 .Unspecified => {
13751375 for (fn_info.param_types.get(ip)) |ty| {
1376 if (!ty.toType().hasRuntimeBitsIgnoreComptime(mod)) {
1376 if (!Type.fromInterned(ty).hasRuntimeBitsIgnoreComptime(mod)) {
13771377 continue;
13781378 }
13791379
......@@ -1383,7 +1383,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
13831383 },
13841384 .C => {
13851385 for (fn_info.param_types.get(ip)) |ty| {
1386 const ty_classes = abi.classifyType(ty.toType(), mod);
1386 const ty_classes = abi.classifyType(Type.fromInterned(ty), mod);
13871387 for (ty_classes) |class| {
13881388 if (class == .none) continue;
13891389 try args.append(.{ .local = .{ .value = func.local_index, .references = 1 } });
......@@ -1748,7 +1748,7 @@ fn isByRef(ty: Type, mod: *Module) bool {
17481748 },
17491749 .Struct => {
17501750 if (mod.typeToPackedStruct(ty)) |packed_struct| {
1751 return isByRef(packed_struct.backingIntType(ip).toType(), mod);
1751 return isByRef(Type.fromInterned(packed_struct.backingIntType(ip).*), mod);
17521752 }
17531753 return ty.hasRuntimeBitsIgnoreComptime(mod);
17541754 },
......@@ -2097,7 +2097,7 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
20972097 const un_op = func.air.instructions.items(.data)[inst].un_op;
20982098 const operand = try func.resolveInst(un_op);
20992099 const fn_info = mod.typeToFunc(func.decl.ty).?;
2100 const ret_ty = fn_info.return_type.toType();
2100 const ret_ty = Type.fromInterned(fn_info.return_type);
21012101
21022102 // result must be stored in the stack and we return a pointer
21032103 // to the stack instead
......@@ -2145,7 +2145,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21452145 }
21462146
21472147 const fn_info = mod.typeToFunc(func.decl.ty).?;
2148 if (firstParamSRet(fn_info.cc, fn_info.return_type.toType(), mod)) {
2148 if (firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), mod)) {
21492149 break :result func.return_value;
21502150 }
21512151
......@@ -2166,7 +2166,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21662166 if (ret_ty.isError(mod)) {
21672167 try func.addImm32(0);
21682168 }
2169 } else if (!firstParamSRet(fn_info.cc, fn_info.return_type.toType(), mod)) {
2169 } else if (!firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), mod)) {
21702170 // leave on the stack
21712171 _ = try func.load(operand, ret_ty, 0);
21722172 }
......@@ -2192,7 +2192,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
21922192 };
21932193 const ret_ty = fn_ty.fnReturnType(mod);
21942194 const fn_info = mod.typeToFunc(fn_ty).?;
2195 const first_param_sret = firstParamSRet(fn_info.cc, fn_info.return_type.toType(), mod);
2195 const first_param_sret = firstParamSRet(fn_info.cc, Type.fromInterned(fn_info.return_type), mod);
21962196
21972197 const callee: ?Decl.Index = blk: {
21982198 const func_val = (try func.air.value(pl_op.operand, mod)) orelse break :blk null;
......@@ -2203,7 +2203,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
22032203 } else if (func_val.getExternFunc(mod)) |extern_func| {
22042204 const ext_decl = mod.declPtr(extern_func.decl);
22052205 const ext_info = mod.typeToFunc(ext_decl.ty).?;
2206 var func_type = try genFunctype(func.gpa, ext_info.cc, ext_info.param_types.get(ip), ext_info.return_type.toType(), mod);
2206 var func_type = try genFunctype(func.gpa, ext_info.cc, ext_info.param_types.get(ip), Type.fromInterned(ext_info.return_type), mod);
22072207 defer func_type.deinit(func.gpa);
22082208 const atom_index = try func.bin_file.getOrCreateAtomForDecl(extern_func.decl);
22092209 const atom = func.bin_file.getAtomPtr(atom_index);
......@@ -2253,7 +2253,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
22532253 const operand = try func.resolveInst(pl_op.operand);
22542254 try func.emitWValue(operand);
22552255
2256 var fn_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types.get(ip), fn_info.return_type.toType(), mod);
2256 var fn_type = try genFunctype(func.gpa, fn_info.cc, fn_info.param_types.get(ip), Type.fromInterned(fn_info.return_type), mod);
22572257 defer fn_type.deinit(func.gpa);
22582258
22592259 const fn_type_index = try func.bin_file.putOrGetFuncType(fn_type);
......@@ -3081,24 +3081,24 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
30813081 return func.lowerParentPtrDecl(ptr_val, decl_index, offset);
30823082 },
30833083 .eu_payload => |tag| return func.fail("TODO: Implement lowerParentPtr for {}", .{tag}),
3084 .int => |base| return func.lowerConstant(base.toValue(), Type.usize),
3085 .opt_payload => |base_ptr| return func.lowerParentPtr(base_ptr.toValue(), offset),
3084 .int => |base| return func.lowerConstant(Value.fromInterned(base), Type.usize),
3085 .opt_payload => |base_ptr| return func.lowerParentPtr(Value.fromInterned(base_ptr), offset),
30863086 .comptime_field => unreachable,
30873087 .elem => |elem| {
30883088 const index = elem.index;
3089 const elem_type = mod.intern_pool.typeOf(elem.base).toType().elemType2(mod);
3089 const elem_type = Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod);
30903090 const elem_offset = index * elem_type.abiSize(mod);
3091 return func.lowerParentPtr(elem.base.toValue(), @as(u32, @intCast(elem_offset + offset)));
3091 return func.lowerParentPtr(Value.fromInterned(elem.base), @as(u32, @intCast(elem_offset + offset)));
30923092 },
30933093 .field => |field| {
3094 const parent_ptr_ty = mod.intern_pool.typeOf(field.base).toType();
3094 const parent_ptr_ty = Type.fromInterned(mod.intern_pool.typeOf(field.base));
30953095 const parent_ty = parent_ptr_ty.childType(mod);
30963096 const field_index: u32 = @intCast(field.index);
30973097
30983098 const field_offset = switch (parent_ty.zigTypeTag(mod)) {
30993099 .Struct => blk: {
31003100 if (mod.typeToPackedStruct(parent_ty)) |struct_type| {
3101 if (ptr.ty.toType().ptrInfo(mod).packed_offset.host_size == 0)
3101 if (Type.fromInterned(ptr.ty).ptrInfo(mod).packed_offset.host_size == 0)
31023102 break :blk @divExact(mod.structPackedFieldBitOffset(struct_type, field_index) + parent_ptr_ty.ptrInfo(mod).packed_offset.bit_offset, 8)
31033103 else
31043104 break :blk 0;
......@@ -3126,7 +3126,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
31263126 },
31273127 else => unreachable,
31283128 };
3129 return func.lowerParentPtr(field.base.toValue(), @as(u32, @intCast(offset + field_offset)));
3129 return func.lowerParentPtr(Value.fromInterned(field.base), @as(u32, @intCast(offset + field_offset)));
31303130 },
31313131 }
31323132}
......@@ -3146,7 +3146,7 @@ fn lowerAnonDeclRef(
31463146) InnerError!WValue {
31473147 const mod = func.bin_file.base.options.module.?;
31483148 const decl_val = anon_decl.val;
3149 const ty = mod.intern_pool.typeOf(decl_val).toType();
3149 const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val));
31503150
31513151 const is_fn_body = ty.zigTypeTag(mod) == .Fn;
31523152 if (!is_fn_body and !ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -3301,10 +3301,10 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33013301 const err_tv: TypedValue = switch (error_union.val) {
33023302 .err_name => |err_name| .{
33033303 .ty = ty.errorUnionSet(mod),
3304 .val = (try mod.intern(.{ .err = .{
3304 .val = Value.fromInterned((try mod.intern(.{ .err = .{
33053305 .ty = ty.errorUnionSet(mod).toIntern(),
33063306 .name = err_name,
3307 } })).toValue(),
3307 } }))),
33083308 },
33093309 .payload => .{
33103310 .ty = err_int_ty,
......@@ -3321,7 +3321,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33213321 },
33223322 .enum_tag => |enum_tag| {
33233323 const int_tag_ty = ip.typeOf(enum_tag.int);
3324 return func.lowerConstant(enum_tag.int.toValue(), int_tag_ty.toType());
3324 return func.lowerConstant(Value.fromInterned(enum_tag.int), Type.fromInterned(int_tag_ty));
33253325 },
33263326 .float => |float| switch (float.storage) {
33273327 .f16 => |f16_val| return WValue{ .imm32 = @as(u16, @bitCast(f16_val)) },
......@@ -3332,7 +3332,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33323332 .ptr => |ptr| switch (ptr.addr) {
33333333 .decl => |decl| return func.lowerDeclRefValue(.{ .ty = ty, .val = val }, decl, 0),
33343334 .mut_decl => |mut_decl| return func.lowerDeclRefValue(.{ .ty = ty, .val = val }, mut_decl.decl, 0),
3335 .int => |int| return func.lowerConstant(int.toValue(), ip.typeOf(int).toType()),
3335 .int => |int| return func.lowerConstant(Value.fromInterned(int), Type.fromInterned(ip.typeOf(int))),
33363336 .opt_payload, .elem, .field => return func.lowerParentPtr(val, 0),
33373337 .anon_decl => |ad| return func.lowerAnonDeclRef(ad, 0),
33383338 else => return func.fail("Wasm TODO: lowerConstant for other const addr tag {}", .{ptr.addr}),
......@@ -3361,7 +3361,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33613361 assert(struct_type.layout == .Packed);
33623362 var buf: [8]u8 = .{0} ** 8; // zero the buffer so we do not read 0xaa as integer
33633363 val.writeToPackedMemory(ty, mod, &buf, 0) catch unreachable;
3364 const backing_int_ty = struct_type.backingIntType(ip).toType();
3364 const backing_int_ty = Type.fromInterned(struct_type.backingIntType(ip).*);
33653365 const int_val = try mod.intValue(
33663366 backing_int_ty,
33673367 mem.readInt(u64, &buf, .little),
......@@ -3376,10 +3376,10 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33763376 try ty.unionBackingType(mod)
33773377 else field_ty: {
33783378 const union_obj = mod.typeToUnion(ty).?;
3379 const field_index = mod.unionTagFieldIndex(union_obj, un.tag.toValue()).?;
3380 break :field_ty union_obj.field_types.get(ip)[field_index].toType();
3379 const field_index = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
3380 break :field_ty Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
33813381 };
3382 return func.lowerConstant(un.val.toValue(), constant_ty);
3382 return func.lowerConstant(Value.fromInterned(un.val), constant_ty);
33833383 },
33843384 .memoized_call => unreachable,
33853385 }
......@@ -3426,7 +3426,7 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
34263426 },
34273427 .Struct => {
34283428 const packed_struct = mod.typeToPackedStruct(ty).?;
3429 return func.emitUndefined(packed_struct.backingIntType(ip).toType());
3429 return func.emitUndefined(Type.fromInterned(packed_struct.backingIntType(ip).*));
34303430 },
34313431 else => return func.fail("Wasm TODO: emitUndefined for type: {}\n", .{ty.zigTypeTag(mod)}),
34323432 }
......@@ -3466,8 +3466,8 @@ fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 {
34663466 .i64 => |x| @as(i32, @intCast(x)),
34673467 .u64 => |x| @as(i32, @bitCast(@as(u32, @intCast(x)))),
34683468 .big_int => unreachable,
3469 .lazy_align => |ty| @as(i32, @bitCast(@as(u32, @intCast(ty.toType().abiAlignment(mod).toByteUnits(0))))),
3470 .lazy_size => |ty| @as(i32, @bitCast(@as(u32, @intCast(ty.toType().abiSize(mod))))),
3469 .lazy_align => |ty| @as(i32, @bitCast(@as(u32, @intCast(Type.fromInterned(ty).abiAlignment(mod).toByteUnits(0))))),
3470 .lazy_size => |ty| @as(i32, @bitCast(@as(u32, @intCast(Type.fromInterned(ty).abiSize(mod))))),
34713471 };
34723472}
34733473
......@@ -3930,7 +3930,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
39303930 .Struct => result: {
39313931 const packed_struct = mod.typeToPackedStruct(struct_ty).?;
39323932 const offset = mod.structPackedFieldBitOffset(packed_struct, field_index);
3933 const backing_ty = packed_struct.backingIntType(ip).toType();
3933 const backing_ty = Type.fromInterned(packed_struct.backingIntType(ip).*);
39343934 const wasm_bits = toWasmBits(backing_ty.intInfo(mod).bits) orelse {
39353935 return func.fail("TODO: airStructFieldVal for packed structs larger than 128 bits", .{});
39363936 };
......@@ -5208,7 +5208,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52085208
52095209 const a = try func.resolveInst(extra.a);
52105210 const b = try func.resolveInst(extra.b);
5211 const mask = extra.mask.toValue();
5211 const mask = Value.fromInterned(extra.mask);
52125212 const mask_len = extra.mask_len;
52135213
52145214 const child_ty = inst_ty.childType(mod);
......@@ -5325,7 +5325,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53255325 }
53265326 const packed_struct = mod.typeToPackedStruct(result_ty).?;
53275327 const field_types = packed_struct.field_types;
5328 const backing_type = packed_struct.backingIntType(ip).toType();
5328 const backing_type = Type.fromInterned(packed_struct.backingIntType(ip).*);
53295329
53305330 // ensure the result is zero'd
53315331 const result = try func.allocLocal(backing_type);
......@@ -5337,7 +5337,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53375337
53385338 var current_bit: u16 = 0;
53395339 for (elements, 0..) |elem, elem_index| {
5340 const field_ty = field_types.get(ip)[elem_index].toType();
5340 const field_ty = Type.fromInterned(field_types.get(ip)[elem_index]);
53415341 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
53425342
53435343 const shift_val = if (backing_type.bitSize(mod) <= 32)
......@@ -5409,7 +5409,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54095409 const union_ty = func.typeOfIndex(inst);
54105410 const layout = union_ty.unionGetLayout(mod);
54115411 const union_obj = mod.typeToUnion(union_ty).?;
5412 const field_ty = union_obj.field_types.get(ip)[extra.field_index].toType();
5412 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
54135413 const field_name = union_obj.field_names.get(ip)[extra.field_index];
54145414
54155415 const tag_int = blk: {
......@@ -5438,7 +5438,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54385438 }
54395439
54405440 if (layout.tag_size > 0) {
5441 try func.store(result_ptr, tag_int, union_obj.enum_tag_ty.toType(), 0);
5441 try func.store(result_ptr, tag_int, Type.fromInterned(union_obj.enum_tag_ty), 0);
54425442 }
54435443 } else {
54445444 try func.store(result_ptr, payload, field_ty, 0);
......@@ -5446,7 +5446,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54465446 try func.store(
54475447 result_ptr,
54485448 tag_int,
5449 union_obj.enum_tag_ty.toType(),
5449 Type.fromInterned(union_obj.enum_tag_ty),
54505450 @intCast(layout.payload_size),
54515451 );
54525452 }
......@@ -7173,8 +7173,8 @@ fn callIntrinsic(
71737173 // Lower all arguments to the stack before we call our function
71747174 for (args, 0..) |arg, arg_i| {
71757175 assert(!(want_sret_param and arg == .stack));
7176 assert(param_types[arg_i].toType().hasRuntimeBitsIgnoreComptime(mod));
7177 try func.lowerArg(.C, param_types[arg_i].toType(), arg);
7176 assert(Type.fromInterned(param_types[arg_i]).hasRuntimeBitsIgnoreComptime(mod));
7177 try func.lowerArg(.C, Type.fromInterned(param_types[arg_i]), arg);
71787178 }
71797179
71807180 // Actually call our intrinsic
......@@ -7260,7 +7260,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
72607260 .storage = .{ .bytes = tag_name },
72617261 } });
72627262 const tag_sym_index = try func.bin_file.lowerUnnamedConst(
7263 .{ .ty = name_ty, .val = name_val.toValue() },
7263 .{ .ty = name_ty, .val = Value.fromInterned(name_val) },
72647264 enum_decl_index,
72657265 );
72667266
src/arch/wasm/abi.zig+4-4
......@@ -37,7 +37,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class {
3737 // The struct type is non-scalar.
3838 return memory;
3939 }
40 const field_ty = struct_type.field_types.get(ip)[0].toType();
40 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[0]);
4141 const explicit_align = struct_type.fieldAlign(ip, 0);
4242 if (explicit_align != .none) {
4343 if (explicit_align.compareStrict(.gt, field_ty.abiAlignment(mod)))
......@@ -76,7 +76,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class {
7676 const layout = ty.unionGetLayout(mod);
7777 assert(layout.tag_size == 0);
7878 if (union_obj.field_names.len > 1) return memory;
79 const first_field_ty = union_obj.field_types.get(ip)[0].toType();
79 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);
8080 return classifyType(first_field_ty, mod);
8181 },
8282 .ErrorUnion,
......@@ -104,7 +104,7 @@ pub fn scalarType(ty: Type, mod: *Module) Type {
104104 switch (ty.zigTypeTag(mod)) {
105105 .Struct => {
106106 if (mod.typeToPackedStruct(ty)) |packed_struct| {
107 return scalarType(packed_struct.backingIntType(ip).toType(), mod);
107 return scalarType(Type.fromInterned(packed_struct.backingIntType(ip).*), mod);
108108 } else {
109109 assert(ty.structFieldCount(mod) == 1);
110110 return scalarType(ty.structFieldType(0, mod), mod);
......@@ -119,7 +119,7 @@ pub fn scalarType(ty: Type, mod: *Module) Type {
119119 }
120120 assert(union_obj.field_types.len == 1);
121121 }
122 const first_field_ty = union_obj.field_types.get(ip)[0].toType();
122 const first_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[0]);
123123 return scalarType(first_field_ty, mod);
124124 },
125125 else => return ty,
src/arch/x86_64/CodeGen.zig+11-11
......@@ -3044,7 +3044,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
30443044 .storage = .{ .repeated_elem = mask_val.ip_index },
30453045 } });
30463046
3047 const splat_mcv = try self.genTypedValue(.{ .ty = splat_ty, .val = splat_val.toValue() });
3047 const splat_mcv = try self.genTypedValue(.{ .ty = splat_ty, .val = Value.fromInterned(splat_val) });
30483048 const splat_addr_mcv: MCValue = switch (splat_mcv) {
30493049 .memory, .indirect, .load_frame => splat_mcv.address(),
30503050 else => .{ .register = try self.copyToTmpRegister(Type.usize, splat_mcv.address()) },
......@@ -3196,7 +3196,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
31963196 }
31973197 } else if (Air.refToInterned(dst_air)) |ip_index| {
31983198 var space: Value.BigIntSpace = undefined;
3199 const src_int = ip_index.toValue().toBigInt(&space, mod);
3199 const src_int = Value.fromInterned(ip_index).toBigInt(&space, mod);
32003200 return @as(u16, @intCast(src_int.bitCountTwosComp())) +
32013201 @intFromBool(src_int.positive and dst_info.signedness == .signed);
32023202 }
......@@ -4429,7 +4429,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
44294429 self.register_manager.unlockReg(lock);
44304430
44314431 const shift_imm =
4432 Immediate.u(@intCast(rhs_elem.toValue().toUnsignedInt(mod)));
4432 Immediate.u(@intCast(Value.fromInterned(rhs_elem).toUnsignedInt(mod)));
44334433 if (self.hasFeature(.avx)) try self.asmRegisterRegisterImmediate(
44344434 mir_tag,
44354435 registerAlias(dst_reg, abi_size),
......@@ -4477,14 +4477,14 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
44774477 const mask_ty = try mod.vectorType(.{ .len = 16, .child = .u8_type });
44784478 const mask_mcv = try self.genTypedValue(.{
44794479 .ty = mask_ty,
4480 .val = (try mod.intern(.{ .aggregate = .{
4480 .val = Value.fromInterned((try mod.intern(.{ .aggregate = .{
44814481 .ty = mask_ty.toIntern(),
44824482 .storage = .{ .elems = &([1]InternPool.Index{
44834483 (try rhs_ty.childType(mod).maxIntScalar(mod, Type.u8)).toIntern(),
44844484 } ++ [1]InternPool.Index{
44854485 (try mod.intValue(Type.u8, 0)).toIntern(),
44864486 } ** 15) },
4487 } })).toValue(),
4487 } }))),
44884488 });
44894489 const mask_addr_reg =
44904490 try self.copyToTmpRegister(Type.usize, mask_mcv.address());
......@@ -6714,7 +6714,7 @@ fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) Inn
67146714 const mod = self.bin_file.options.module.?;
67156715 const ptr_info = ptr_ty.ptrInfo(mod);
67166716
6717 const val_ty = ptr_info.child.toType();
6717 const val_ty = Type.fromInterned(ptr_info.child);
67186718 if (!val_ty.hasRuntimeBitsIgnoreComptime(mod)) return;
67196719 const val_abi_size: u32 = @intCast(val_ty.abiSize(mod));
67206720
......@@ -10759,7 +10759,7 @@ fn genCall(self: *Self, info: union(enum) {
1075910759 switch (call_info.return_value.long) {
1076010760 .none, .unreach => {},
1076110761 .indirect => |reg_off| {
10762 const ret_ty = fn_info.return_type.toType();
10762 const ret_ty = Type.fromInterned(fn_info.return_type);
1076310763 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ret_ty, mod));
1076410764 try self.genSetReg(reg_off.reg, Type.usize, .{
1076510765 .lea_frame = .{ .index = frame_index, .off = -reg_off.off },
......@@ -15343,7 +15343,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
1534315343
1534415344 const union_obj = mod.typeToUnion(union_ty).?;
1534515345 const field_name = union_obj.field_names.get(ip)[extra.field_index];
15346 const tag_ty = union_obj.enum_tag_ty.toType();
15346 const tag_ty = Type.fromInterned(union_obj.enum_tag_ty);
1534715347 const field_index = tag_ty.enumFieldIndex(field_name, mod).?;
1534815348 const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index);
1534915349 const tag_int_val = try tag_val.intFromEnum(tag_ty, mod);
......@@ -15812,7 +15812,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
1581215812 const ip_index = Air.refToInterned(ref).?;
1581315813 const gop = try self.const_tracking.getOrPut(self.gpa, ip_index);
1581415814 if (!gop.found_existing) gop.value_ptr.* = InstTracking.init(init: {
15815 const const_mcv = try self.genTypedValue(.{ .ty = ty, .val = ip_index.toValue() });
15815 const const_mcv = try self.genTypedValue(.{ .ty = ty, .val = Value.fromInterned(ip_index) });
1581615816 switch (const_mcv) {
1581715817 .lea_tlv => |tlv_sym| if (self.bin_file.cast(link.File.Elf)) |_| {
1581815818 if (self.bin_file.options.pic) {
......@@ -15921,7 +15921,7 @@ fn resolveCallingConventionValues(
1592115921 defer self.gpa.free(param_types);
1592215922
1592315923 for (param_types[0..fn_info.param_types.len], fn_info.param_types.get(ip)) |*dest, src| {
15924 dest.* = src.toType();
15924 dest.* = Type.fromInterned(src);
1592515925 }
1592615926 for (param_types[fn_info.param_types.len..], var_args) |*param_ty, arg_ty|
1592715927 param_ty.* = self.promoteVarArg(arg_ty);
......@@ -15937,7 +15937,7 @@ fn resolveCallingConventionValues(
1593715937 };
1593815938 errdefer self.gpa.free(result.args);
1593915939
15940 const ret_ty = fn_info.return_type.toType();
15940 const ret_ty = Type.fromInterned(fn_info.return_type);
1594115941
1594215942 const resolved_cc = abi.resolveCallingConvention(cc, self.target.*);
1594315943 switch (cc) {
src/arch/x86_64/abi.zig+3-3
......@@ -224,7 +224,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
224224 var result_i: usize = 0; // out of 8
225225 var byte_i: usize = 0; // out of 8
226226 for (struct_type.field_types.get(ip), 0..) |field_ty_ip, i| {
227 const field_ty = field_ty_ip.toType();
227 const field_ty = Type.fromInterned(field_ty_ip);
228228 const field_align = struct_type.fieldAlign(ip, i);
229229 if (field_align != .none and field_align.compare(.lt, field_ty.abiAlignment(mod)))
230230 return memory_class;
......@@ -342,12 +342,12 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
342342 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
343343 const field_align = union_obj.fieldAlign(ip, @intCast(field_index));
344344 if (field_align != .none and
345 field_align.compare(.lt, field_ty.toType().abiAlignment(mod)))
345 field_align.compare(.lt, Type.fromInterned(field_ty).abiAlignment(mod)))
346346 {
347347 return memory_class;
348348 }
349349 // Combine this field with the previous one.
350 const field_class = classifySystemV(field_ty.toType(), mod, .field);
350 const field_class = classifySystemV(Type.fromInterned(field_ty), mod, .field);
351351 for (&result, 0..) |*result_item, i| {
352352 const field_item = field_class[i];
353353 // "If both classes are equal, this is the resulting class."
src/codegen.zig+44-44
......@@ -259,10 +259,10 @@ pub fn generateSymbol(
259259 const begin = code.items.len;
260260 switch (try generateSymbol(bin_file, src_loc, .{
261261 .ty = payload_ty,
262 .val = switch (error_union.val) {
262 .val = Value.fromInterned(switch (error_union.val) {
263263 .err_name => try mod.intern(.{ .undef = payload_ty.toIntern() }),
264264 .payload => |payload| payload,
265 }.toValue(),
265 }),
266266 }, code, debug_output, reloc_info)) {
267267 .ok => {},
268268 .fail => |em| return .{ .fail = em },
......@@ -293,7 +293,7 @@ pub fn generateSymbol(
293293 const int_tag_ty = typed_value.ty.intTagType(mod);
294294 switch (try generateSymbol(bin_file, src_loc, .{
295295 .ty = int_tag_ty,
296 .val = try mod.getCoerced(enum_tag.int.toValue(), int_tag_ty),
296 .val = try mod.getCoerced(Value.fromInterned(enum_tag.int), int_tag_ty),
297297 }, code, debug_output, reloc_info)) {
298298 .ok => {},
299299 .fail => |em| return .{ .fail = em },
......@@ -323,7 +323,7 @@ pub fn generateSymbol(
323323 // generate len
324324 switch (try generateSymbol(bin_file, src_loc, .{
325325 .ty = Type.usize,
326 .val = ptr.len.toValue(),
326 .val = Value.fromInterned(ptr.len),
327327 }, code, debug_output, reloc_info)) {
328328 .ok => {},
329329 .fail => |em| return Result{ .fail = em },
......@@ -350,7 +350,7 @@ pub fn generateSymbol(
350350 } else {
351351 const padding = abi_size - (math.cast(usize, payload_type.abiSize(mod)) orelse return error.Overflow) - 1;
352352 if (payload_type.hasRuntimeBits(mod)) {
353 const value = payload_val orelse (try mod.intern(.{ .undef = payload_type.toIntern() })).toValue();
353 const value = payload_val orelse Value.fromInterned((try mod.intern(.{ .undef = payload_type.toIntern() })));
354354 switch (try generateSymbol(bin_file, src_loc, .{
355355 .ty = payload_type,
356356 .val = value,
......@@ -372,15 +372,15 @@ pub fn generateSymbol(
372372 array_type.len + @intFromBool(array_type.sentinel != .none);
373373 while (index < len_including_sentinel) : (index += 1) {
374374 switch (try generateSymbol(bin_file, src_loc, .{
375 .ty = array_type.child.toType(),
376 .val = switch (aggregate.storage) {
375 .ty = Type.fromInterned(array_type.child),
376 .val = Value.fromInterned(switch (aggregate.storage) {
377377 .bytes => unreachable,
378378 .elems => |elems| elems[@as(usize, @intCast(index))],
379379 .repeated_elem => |elem| if (index < array_type.len)
380380 elem
381381 else
382382 array_type.sentinel,
383 }.toValue(),
383 }),
384384 }, code, debug_output, reloc_info)) {
385385 .ok => {},
386386 .fail => |em| return .{ .fail = em },
......@@ -395,12 +395,12 @@ pub fn generateSymbol(
395395 var index: u64 = 0;
396396 while (index < vector_type.len) : (index += 1) {
397397 switch (try generateSymbol(bin_file, src_loc, .{
398 .ty = vector_type.child.toType(),
399 .val = switch (aggregate.storage) {
398 .ty = Type.fromInterned(vector_type.child),
399 .val = Value.fromInterned(switch (aggregate.storage) {
400400 .bytes => unreachable,
401401 .elems => |elems| elems[@as(usize, @intCast(index))],
402402 .repeated_elem => |elem| elem,
403 }.toValue(),
403 }),
404404 }, code, debug_output, reloc_info)) {
405405 .ok => {},
406406 .fail => |em| return .{ .fail = em },
......@@ -410,7 +410,7 @@ pub fn generateSymbol(
410410 }
411411
412412 const padding = math.cast(usize, typed_value.ty.abiSize(mod) -
413 (math.divCeil(u64, vector_type.child.toType().bitSize(mod) * vector_type.len, 8) catch |err| switch (err) {
413 (math.divCeil(u64, Type.fromInterned(vector_type.child).bitSize(mod) * vector_type.len, 8) catch |err| switch (err) {
414414 error.DivisionByZero => unreachable,
415415 else => |e| return e,
416416 })) orelse return error.Overflow;
......@@ -424,7 +424,7 @@ pub fn generateSymbol(
424424 0..,
425425 ) |field_ty, comptime_val, index| {
426426 if (comptime_val != .none) continue;
427 if (!field_ty.toType().hasRuntimeBits(mod)) continue;
427 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
428428
429429 const field_val = switch (aggregate.storage) {
430430 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{
......@@ -436,8 +436,8 @@ pub fn generateSymbol(
436436 };
437437
438438 switch (try generateSymbol(bin_file, src_loc, .{
439 .ty = field_ty.toType(),
440 .val = field_val.toValue(),
439 .ty = Type.fromInterned(field_ty),
440 .val = Value.fromInterned(field_val),
441441 }, code, debug_output, reloc_info)) {
442442 .ok => {},
443443 .fail => |em| return Result{ .fail = em },
......@@ -474,22 +474,22 @@ pub fn generateSymbol(
474474
475475 // pointer may point to a decl which must be marked used
476476 // but can also result in a relocation. Therefore we handle those separately.
477 if (field_ty.toType().zigTypeTag(mod) == .Pointer) {
478 const field_size = math.cast(usize, field_ty.toType().abiSize(mod)) orelse
477 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .Pointer) {
478 const field_size = math.cast(usize, Type.fromInterned(field_ty).abiSize(mod)) orelse
479479 return error.Overflow;
480480 var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size);
481481 defer tmp_list.deinit();
482482 switch (try generateSymbol(bin_file, src_loc, .{
483 .ty = field_ty.toType(),
484 .val = field_val.toValue(),
483 .ty = Type.fromInterned(field_ty),
484 .val = Value.fromInterned(field_val),
485485 }, &tmp_list, debug_output, reloc_info)) {
486486 .ok => @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items),
487487 .fail => |em| return Result{ .fail = em },
488488 }
489489 } else {
490 field_val.toValue().writeToPackedMemory(field_ty.toType(), mod, code.items[current_pos..], bits) catch unreachable;
490 Value.fromInterned(field_val).writeToPackedMemory(Type.fromInterned(field_ty), mod, code.items[current_pos..], bits) catch unreachable;
491491 }
492 bits += @as(u16, @intCast(field_ty.toType().bitSize(mod)));
492 bits += @as(u16, @intCast(Type.fromInterned(field_ty).bitSize(mod)));
493493 }
494494 },
495495 .Auto, .Extern => {
......@@ -500,7 +500,7 @@ pub fn generateSymbol(
500500 var it = struct_type.iterateRuntimeOrder(ip);
501501 while (it.next()) |field_index| {
502502 const field_ty = field_types[field_index];
503 if (!field_ty.toType().hasRuntimeBits(mod)) continue;
503 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
504504
505505 const field_val = switch (ip.indexToKey(typed_value.val.toIntern()).aggregate.storage) {
506506 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{
......@@ -518,8 +518,8 @@ pub fn generateSymbol(
518518 if (padding > 0) try code.appendNTimes(0, padding);
519519
520520 switch (try generateSymbol(bin_file, src_loc, .{
521 .ty = field_ty.toType(),
522 .val = field_val.toValue(),
521 .ty = Type.fromInterned(field_ty),
522 .val = Value.fromInterned(field_val),
523523 }, code, debug_output, reloc_info)) {
524524 .ok => {},
525525 .fail => |em| return Result{ .fail = em },
......@@ -545,7 +545,7 @@ pub fn generateSymbol(
545545 if (layout.payload_size == 0) {
546546 return generateSymbol(bin_file, src_loc, .{
547547 .ty = typed_value.ty.unionTagTypeSafety(mod).?,
548 .val = un.tag.toValue(),
548 .val = Value.fromInterned(un.tag),
549549 }, code, debug_output, reloc_info);
550550 }
551551
......@@ -553,7 +553,7 @@ pub fn generateSymbol(
553553 if (layout.tag_size > 0 and layout.tag_align.compare(.gte, layout.payload_align)) {
554554 switch (try generateSymbol(bin_file, src_loc, .{
555555 .ty = typed_value.ty.unionTagTypeSafety(mod).?,
556 .val = un.tag.toValue(),
556 .val = Value.fromInterned(un.tag),
557557 }, code, debug_output, reloc_info)) {
558558 .ok => {},
559559 .fail => |em| return Result{ .fail = em },
......@@ -562,14 +562,14 @@ pub fn generateSymbol(
562562
563563 const union_obj = mod.typeToUnion(typed_value.ty).?;
564564 if (un.tag != .none) {
565 const field_index = typed_value.ty.unionTagFieldIndex(un.tag.toValue(), mod).?;
566 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
565 const field_index = typed_value.ty.unionTagFieldIndex(Value.fromInterned(un.tag), mod).?;
566 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
567567 if (!field_ty.hasRuntimeBits(mod)) {
568568 try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow);
569569 } else {
570570 switch (try generateSymbol(bin_file, src_loc, .{
571571 .ty = field_ty,
572 .val = un.val.toValue(),
572 .val = Value.fromInterned(un.val),
573573 }, code, debug_output, reloc_info)) {
574574 .ok => {},
575575 .fail => |em| return Result{ .fail = em },
......@@ -582,8 +582,8 @@ pub fn generateSymbol(
582582 }
583583 } else {
584584 switch (try generateSymbol(bin_file, src_loc, .{
585 .ty = ip.typeOf(un.val).toType(),
586 .val = un.val.toValue(),
585 .ty = Type.fromInterned(ip.typeOf(un.val)),
586 .val = Value.fromInterned(un.val),
587587 }, code, debug_output, reloc_info)) {
588588 .ok => {},
589589 .fail => |em| return Result{ .fail = em },
......@@ -592,8 +592,8 @@ pub fn generateSymbol(
592592
593593 if (layout.tag_size > 0 and layout.tag_align.compare(.lt, layout.payload_align)) {
594594 switch (try generateSymbol(bin_file, src_loc, .{
595 .ty = union_obj.enum_tag_ty.toType(),
596 .val = un.tag.toValue(),
595 .ty = Type.fromInterned(union_obj.enum_tag_ty),
596 .val = Value.fromInterned(un.tag),
597597 }, code, debug_output, reloc_info)) {
598598 .ok => {},
599599 .fail => |em| return Result{ .fail = em },
......@@ -626,7 +626,7 @@ fn lowerParentPtr(
626626 .anon_decl => |ad| try lowerAnonDeclRef(bin_file, src_loc, ad, code, debug_output, reloc_info),
627627 .int => |int| try generateSymbol(bin_file, src_loc, .{
628628 .ty = Type.usize,
629 .val = int.toValue(),
629 .val = Value.fromInterned(int),
630630 }, code, debug_output, reloc_info),
631631 .eu_payload => |eu_payload| try lowerParentPtr(
632632 bin_file,
......@@ -635,7 +635,7 @@ fn lowerParentPtr(
635635 code,
636636 debug_output,
637637 reloc_info.offset(@as(u32, @intCast(errUnionPayloadOffset(
638 mod.intern_pool.typeOf(eu_payload).toType(),
638 Type.fromInterned(mod.intern_pool.typeOf(eu_payload)),
639639 mod,
640640 )))),
641641 ),
......@@ -654,7 +654,7 @@ fn lowerParentPtr(
654654 code,
655655 debug_output,
656656 reloc_info.offset(@as(u32, @intCast(elem.index *
657 mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).abiSize(mod)))),
657 Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod).abiSize(mod)))),
658658 ),
659659 .field => |field| {
660660 const base_type = mod.intern_pool.indexToKey(mod.intern_pool.typeOf(field.base)).ptr_type.child;
......@@ -676,12 +676,12 @@ fn lowerParentPtr(
676676 .struct_type,
677677 .anon_struct_type,
678678 .union_type,
679 => switch (base_type.toType().containerLayout(mod)) {
680 .Auto, .Extern => @intCast(base_type.toType().structFieldOffset(
679 => switch (Type.fromInterned(base_type).containerLayout(mod)) {
680 .Auto, .Extern => @intCast(Type.fromInterned(base_type).structFieldOffset(
681681 @intCast(field.index),
682682 mod,
683683 )),
684 .Packed => if (mod.typeToStruct(base_type.toType())) |struct_type|
684 .Packed => if (mod.typeToStruct(Type.fromInterned(base_type))) |struct_type|
685685 math.divExact(u16, mod.structPackedFieldBitOffset(
686686 struct_type,
687687 @intCast(field.index),
......@@ -723,7 +723,7 @@ fn lowerAnonDeclRef(
723723
724724 const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);
725725 const decl_val = anon_decl.val;
726 const decl_ty = mod.intern_pool.typeOf(decl_val).toType();
726 const decl_ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val));
727727 log.debug("lowerAnonDecl: ty = {}", .{decl_ty.fmt(mod)});
728728 const is_fn_body = decl_ty.zigTypeTag(mod) == .Fn;
729729 if (!is_fn_body and !decl_ty.hasRuntimeBits(mod)) {
......@@ -1056,8 +1056,8 @@ pub fn genTypedValue(
10561056 const enum_tag = mod.intern_pool.indexToKey(typed_value.val.toIntern()).enum_tag;
10571057 const int_tag_ty = mod.intern_pool.typeOf(enum_tag.int);
10581058 return genTypedValue(bin_file, src_loc, .{
1059 .ty = int_tag_ty.toType(),
1060 .val = enum_tag.int.toValue(),
1059 .ty = Type.fromInterned(int_tag_ty),
1060 .val = Value.fromInterned(enum_tag.int),
10611061 }, owner_decl_index);
10621062 },
10631063 .ErrorSet => {
......@@ -1074,10 +1074,10 @@ pub fn genTypedValue(
10741074 switch (mod.intern_pool.indexToKey(typed_value.val.toIntern()).error_union.val) {
10751075 .err_name => |err_name| return genTypedValue(bin_file, src_loc, .{
10761076 .ty = err_type,
1077 .val = (try mod.intern(.{ .err = .{
1077 .val = Value.fromInterned((try mod.intern(.{ .err = .{
10781078 .ty = err_type.toIntern(),
10791079 .name = err_name,
1080 } })).toValue(),
1080 } }))),
10811081 }, owner_decl_index),
10821082 .payload => return genTypedValue(bin_file, src_loc, .{
10831083 .ty = err_int_ty,
src/codegen/c.zig+71-71
......@@ -355,8 +355,8 @@ pub const Function = struct {
355355 switch (c_value) {
356356 .constant => |val| try f.object.dg.renderValue(
357357 w,
358 f.object.dg.module.intern_pool.typeOf(val).toType(),
359 val.toValue(),
358 Type.fromInterned(f.object.dg.module.intern_pool.typeOf(val)),
359 Value.fromInterned(val),
360360 location,
361361 ),
362362 .undef => |ty| try f.object.dg.renderValue(w, ty, Value.undef, location),
......@@ -370,8 +370,8 @@ pub const Function = struct {
370370 try w.writeAll("(*");
371371 try f.object.dg.renderValue(
372372 w,
373 f.object.dg.module.intern_pool.typeOf(val).toType(),
374 val.toValue(),
373 Type.fromInterned(f.object.dg.module.intern_pool.typeOf(val)),
374 Value.fromInterned(val),
375375 .Other,
376376 );
377377 try w.writeByte(')');
......@@ -385,8 +385,8 @@ pub const Function = struct {
385385 .constant => |val| {
386386 try f.object.dg.renderValue(
387387 w,
388 f.object.dg.module.intern_pool.typeOf(val).toType(),
389 val.toValue(),
388 Type.fromInterned(f.object.dg.module.intern_pool.typeOf(val)),
389 Value.fromInterned(val),
390390 .Other,
391391 );
392392 try w.writeByte('.');
......@@ -402,8 +402,8 @@ pub const Function = struct {
402402 try w.writeByte('(');
403403 try f.object.dg.renderValue(
404404 w,
405 f.object.dg.module.intern_pool.typeOf(val).toType(),
406 val.toValue(),
405 Type.fromInterned(f.object.dg.module.intern_pool.typeOf(val)),
406 Value.fromInterned(val),
407407 .Other,
408408 );
409409 try w.writeAll(")->");
......@@ -561,7 +561,7 @@ pub const DeclGen = struct {
561561 const mod = dg.module;
562562 const ip = &mod.intern_pool;
563563 const decl_val = anon_decl.val;
564 const decl_ty = ip.typeOf(decl_val).toType();
564 const decl_ty = Type.fromInterned(ip.typeOf(decl_val));
565565
566566 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
567567 if (ty.isPtrAtRuntime(mod) and !decl_ty.isFnOrHasRuntimeBits(mod)) {
......@@ -569,20 +569,20 @@ pub const DeclGen = struct {
569569 }
570570
571571 // Chase function values in order to be able to reference the original function.
572 if (decl_val.toValue().getFunction(mod)) |func| {
572 if (Value.fromInterned(decl_val).getFunction(mod)) |func| {
573573 _ = func;
574574 _ = ptr_val;
575575 _ = location;
576576 @panic("TODO");
577577 }
578 if (decl_val.toValue().getExternFunc(mod)) |extern_func| {
578 if (Value.fromInterned(decl_val).getExternFunc(mod)) |extern_func| {
579579 _ = extern_func;
580580 _ = ptr_val;
581581 _ = location;
582582 @panic("TODO");
583583 }
584584
585 assert(decl_val.toValue().getVariable(mod) == null);
585 assert(Value.fromInterned(decl_val).getVariable(mod) == null);
586586
587587 // We shouldn't cast C function pointers as this is UB (when you call
588588 // them). The analysis until now should ensure that the C function
......@@ -608,7 +608,7 @@ pub const DeclGen = struct {
608608 // alignment. If there is already an entry, keep the greater alignment.
609609 const explicit_alignment = ptr_type.flags.alignment;
610610 if (explicit_alignment != .none) {
611 const abi_alignment = ptr_type.child.toType().abiAlignment(mod);
611 const abi_alignment = Type.fromInterned(ptr_type.child).abiAlignment(mod);
612612 if (explicit_alignment.compareStrict(.gt, abi_alignment)) {
613613 const aligned_gop = try dg.aligned_anon_decls.getOrPut(dg.gpa, decl_val);
614614 aligned_gop.value_ptr.* = if (aligned_gop.found_existing)
......@@ -668,20 +668,20 @@ pub const DeclGen = struct {
668668 location: ValueRenderLocation,
669669 ) error{ OutOfMemory, AnalysisFail }!void {
670670 const mod = dg.module;
671 const ptr_ty = mod.intern_pool.typeOf(ptr_val).toType();
671 const ptr_ty = Type.fromInterned(mod.intern_pool.typeOf(ptr_val));
672672 const ptr_cty = try dg.typeToIndex(ptr_ty, .complete);
673673 const ptr = mod.intern_pool.indexToKey(ptr_val).ptr;
674674 switch (ptr.addr) {
675 .decl => |d| try dg.renderDeclValue(writer, ptr_ty, ptr_val.toValue(), d, location),
676 .mut_decl => |md| try dg.renderDeclValue(writer, ptr_ty, ptr_val.toValue(), md.decl, location),
677 .anon_decl => |anon_decl| try dg.renderAnonDeclValue(writer, ptr_ty, ptr_val.toValue(), anon_decl, location),
675 .decl => |d| try dg.renderDeclValue(writer, ptr_ty, Value.fromInterned(ptr_val), d, location),
676 .mut_decl => |md| try dg.renderDeclValue(writer, ptr_ty, Value.fromInterned(ptr_val), md.decl, location),
677 .anon_decl => |anon_decl| try dg.renderAnonDeclValue(writer, ptr_ty, Value.fromInterned(ptr_val), anon_decl, location),
678678 .int => |int| {
679679 try writer.writeByte('(');
680680 try dg.renderCType(writer, ptr_cty);
681 try writer.print("){x}", .{try dg.fmtIntLiteral(Type.usize, int.toValue(), .Other)});
681 try writer.print("){x}", .{try dg.fmtIntLiteral(Type.usize, Value.fromInterned(int), .Other)});
682682 },
683683 .eu_payload, .opt_payload => |base| {
684 const ptr_base_ty = mod.intern_pool.typeOf(base).toType();
684 const ptr_base_ty = Type.fromInterned(mod.intern_pool.typeOf(base));
685685 const base_ty = ptr_base_ty.childType(mod);
686686 // Ensure complete type definition is visible before accessing fields.
687687 _ = try dg.typeToIndex(base_ty, .complete);
......@@ -702,7 +702,7 @@ pub const DeclGen = struct {
702702 try writer.writeAll(")->payload");
703703 },
704704 .elem => |elem| {
705 const ptr_base_ty = mod.intern_pool.typeOf(elem.base).toType();
705 const ptr_base_ty = Type.fromInterned(mod.intern_pool.typeOf(elem.base));
706706 const elem_ty = ptr_base_ty.elemType2(mod);
707707 const ptr_elem_ty = try mod.adjustPtrTypeChild(ptr_base_ty, elem_ty);
708708 const ptr_elem_cty = try dg.typeToIndex(ptr_elem_ty, .complete);
......@@ -718,7 +718,7 @@ pub const DeclGen = struct {
718718 try writer.print(")[{d}]", .{elem.index});
719719 },
720720 .field => |field| {
721 const ptr_base_ty = mod.intern_pool.typeOf(field.base).toType();
721 const ptr_base_ty = Type.fromInterned(mod.intern_pool.typeOf(field.base));
722722 const base_ty = ptr_base_ty.childType(mod);
723723 // Ensure complete type definition is visible before accessing fields.
724724 _ = try dg.typeToIndex(base_ty, .complete);
......@@ -909,8 +909,8 @@ pub const DeclGen = struct {
909909 }
910910 const union_obj = mod.typeToUnion(ty).?;
911911 for (union_obj.field_types.get(ip)) |field_ty| {
912 if (!field_ty.toType().hasRuntimeBits(mod)) continue;
913 try dg.renderValue(writer, field_ty.toType(), val, initializer_type);
912 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
913 try dg.renderValue(writer, Type.fromInterned(field_ty), val, initializer_type);
914914 break;
915915 }
916916 if (ty.unionTagTypeSafety(mod)) |_| try writer.writeByte('}');
......@@ -1045,10 +1045,10 @@ pub const DeclGen = struct {
10451045 .err_name => |err_name| return dg.renderValue(
10461046 writer,
10471047 error_ty,
1048 (try mod.intern(.{ .err = .{
1048 Value.fromInterned((try mod.intern(.{ .err = .{
10491049 .ty = error_ty.toIntern(),
10501050 .name = err_name,
1051 } })).toValue(),
1051 } }))),
10521052 location,
10531053 ),
10541054 .payload => return dg.renderValue(
......@@ -1070,10 +1070,10 @@ pub const DeclGen = struct {
10701070 try dg.renderValue(
10711071 writer,
10721072 payload_ty,
1073 switch (error_union.val) {
1073 Value.fromInterned(switch (error_union.val) {
10741074 .err_name => try mod.intern(.{ .undef = payload_ty.ip_index }),
10751075 .payload => |payload| payload,
1076 }.toValue(),
1076 }),
10771077 initializer_type,
10781078 );
10791079 try writer.writeAll(", .error = ");
......@@ -1081,10 +1081,10 @@ pub const DeclGen = struct {
10811081 .err_name => |err_name| try dg.renderValue(
10821082 writer,
10831083 error_ty,
1084 (try mod.intern(.{ .err = .{
1084 Value.fromInterned((try mod.intern(.{ .err = .{
10851085 .ty = error_ty.toIntern(),
10861086 .name = err_name,
1087 } })).toValue(),
1087 } }))),
10881088 location,
10891089 ),
10901090 .payload => try dg.renderValue(
......@@ -1099,7 +1099,7 @@ pub const DeclGen = struct {
10991099 .enum_tag => {
11001100 const enum_tag = ip.indexToKey(val.ip_index).enum_tag;
11011101 const int_tag_ty = ip.typeOf(enum_tag.int);
1102 try dg.renderValue(writer, int_tag_ty.toType(), enum_tag.int.toValue(), location);
1102 try dg.renderValue(writer, Type.fromInterned(int_tag_ty), Value.fromInterned(enum_tag.int), location);
11031103 },
11041104 .float => {
11051105 const bits = ty.floatBits(target);
......@@ -1218,7 +1218,7 @@ pub const DeclGen = struct {
12181218 try writer.writeAll("((");
12191219 try dg.renderType(writer, ptr_ty);
12201220 try writer.print("){x})", .{
1221 try dg.fmtIntLiteral(Type.usize, int.toValue(), ptr_location),
1221 try dg.fmtIntLiteral(Type.usize, Value.fromInterned(int), ptr_location),
12221222 });
12231223 },
12241224 .eu_payload,
......@@ -1230,7 +1230,7 @@ pub const DeclGen = struct {
12301230 }
12311231 if (ptr.len != .none) {
12321232 try writer.writeAll(", ");
1233 try dg.renderValue(writer, Type.usize, ptr.len.toValue(), initializer_type);
1233 try dg.renderValue(writer, Type.usize, Value.fromInterned(ptr.len), initializer_type);
12341234 try writer.writeByte('}');
12351235 }
12361236 },
......@@ -1250,7 +1250,7 @@ pub const DeclGen = struct {
12501250 .Pointer => try mod.getCoerced(val, payload_ty),
12511251 else => unreachable,
12521252 },
1253 else => |payload| payload.toValue(),
1253 else => |payload| Value.fromInterned(payload),
12541254 },
12551255 location,
12561256 );
......@@ -1262,10 +1262,10 @@ pub const DeclGen = struct {
12621262 }
12631263
12641264 try writer.writeAll("{ .payload = ");
1265 try dg.renderValue(writer, payload_ty, switch (opt.val) {
1265 try dg.renderValue(writer, payload_ty, Value.fromInterned(switch (opt.val) {
12661266 .none => try mod.intern(.{ .undef = payload_ty.ip_index }),
12671267 else => |payload| payload,
1268 }.toValue(), initializer_type);
1268 }), initializer_type);
12691269 try writer.writeAll(", .is_null = ");
12701270 try dg.renderValue(writer, Type.bool, is_null_val, initializer_type);
12711271 try writer.writeAll(" }");
......@@ -1349,7 +1349,7 @@ pub const DeclGen = struct {
13491349 0..,
13501350 ) |field_ty, comptime_ty, field_i| {
13511351 if (comptime_ty != .none) continue;
1352 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
1352 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
13531353
13541354 if (!empty) try writer.writeByte(',');
13551355
......@@ -1361,7 +1361,7 @@ pub const DeclGen = struct {
13611361 .elems => |elems| elems[field_i],
13621362 .repeated_elem => |elem| elem,
13631363 };
1364 try dg.renderValue(writer, field_ty.toType(), field_val.toValue(), initializer_type);
1364 try dg.renderValue(writer, Type.fromInterned(field_ty), Value.fromInterned(field_val), initializer_type);
13651365
13661366 empty = false;
13671367 }
......@@ -1378,7 +1378,7 @@ pub const DeclGen = struct {
13781378 try writer.writeByte('{');
13791379 var empty = true;
13801380 for (0..struct_type.field_types.len) |field_i| {
1381 const field_ty = struct_type.field_types.get(ip)[field_i].toType();
1381 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_i]);
13821382 if (struct_type.fieldIsComptime(ip, field_i)) continue;
13831383 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
13841384
......@@ -1391,7 +1391,7 @@ pub const DeclGen = struct {
13911391 .elems => |elems| elems[field_i],
13921392 .repeated_elem => |elem| elem,
13931393 };
1394 try dg.renderValue(writer, field_ty, field_val.toValue(), initializer_type);
1394 try dg.renderValue(writer, field_ty, Value.fromInterned(field_val), initializer_type);
13951395
13961396 empty = false;
13971397 }
......@@ -1408,7 +1408,7 @@ pub const DeclGen = struct {
14081408 var eff_num_fields: usize = 0;
14091409
14101410 for (field_types) |field_ty| {
1411 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
1411 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
14121412 eff_num_fields += 1;
14131413 }
14141414
......@@ -1428,7 +1428,7 @@ pub const DeclGen = struct {
14281428 var eff_index: usize = 0;
14291429 var needs_closing_paren = false;
14301430 for (field_types, 0..) |field_ty, field_i| {
1431 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
1431 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
14321432
14331433 const field_val = switch (ip.indexToKey(val.ip_index).aggregate.storage) {
14341434 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{
......@@ -1438,24 +1438,24 @@ pub const DeclGen = struct {
14381438 .elems => |elems| elems[field_i],
14391439 .repeated_elem => |elem| elem,
14401440 };
1441 const cast_context = IntCastContext{ .value = .{ .value = field_val.toValue() } };
1441 const cast_context = IntCastContext{ .value = .{ .value = Value.fromInterned(field_val) } };
14421442 if (bit_offset != 0) {
14431443 try writer.writeAll("zig_shl_");
14441444 try dg.renderTypeForBuiltinFnName(writer, ty);
14451445 try writer.writeByte('(');
1446 try dg.renderIntCast(writer, ty, cast_context, field_ty.toType(), .FunctionArgument);
1446 try dg.renderIntCast(writer, ty, cast_context, Type.fromInterned(field_ty), .FunctionArgument);
14471447 try writer.writeAll(", ");
14481448 const bit_offset_val = try mod.intValue(bit_offset_ty, bit_offset);
14491449 try dg.renderValue(writer, bit_offset_ty, bit_offset_val, .FunctionArgument);
14501450 try writer.writeByte(')');
14511451 } else {
1452 try dg.renderIntCast(writer, ty, cast_context, field_ty.toType(), .FunctionArgument);
1452 try dg.renderIntCast(writer, ty, cast_context, Type.fromInterned(field_ty), .FunctionArgument);
14531453 }
14541454
14551455 if (needs_closing_paren) try writer.writeByte(')');
14561456 if (eff_index != eff_num_fields - 1) try writer.writeAll(", ");
14571457
1458 bit_offset += field_ty.toType().bitSize(mod);
1458 bit_offset += Type.fromInterned(field_ty).bitSize(mod);
14591459 needs_closing_paren = true;
14601460 eff_index += 1;
14611461 }
......@@ -1464,7 +1464,7 @@ pub const DeclGen = struct {
14641464 // a << a_off | b << b_off | c << c_off
14651465 var empty = true;
14661466 for (field_types, 0..) |field_ty, field_i| {
1467 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
1467 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
14681468
14691469 if (!empty) try writer.writeAll(" | ");
14701470 try writer.writeByte('(');
......@@ -1481,15 +1481,15 @@ pub const DeclGen = struct {
14811481 };
14821482
14831483 if (bit_offset != 0) {
1484 try dg.renderValue(writer, field_ty.toType(), field_val.toValue(), .Other);
1484 try dg.renderValue(writer, Type.fromInterned(field_ty), Value.fromInterned(field_val), .Other);
14851485 try writer.writeAll(" << ");
14861486 const bit_offset_val = try mod.intValue(bit_offset_ty, bit_offset);
14871487 try dg.renderValue(writer, bit_offset_ty, bit_offset_val, .FunctionArgument);
14881488 } else {
1489 try dg.renderValue(writer, field_ty.toType(), field_val.toValue(), .Other);
1489 try dg.renderValue(writer, Type.fromInterned(field_ty), Value.fromInterned(field_val), .Other);
14901490 }
14911491
1492 bit_offset += field_ty.toType().bitSize(mod);
1492 bit_offset += Type.fromInterned(field_ty).bitSize(mod);
14931493 empty = false;
14941494 }
14951495 try writer.writeByte(')');
......@@ -1509,7 +1509,7 @@ pub const DeclGen = struct {
15091509 try dg.renderType(writer, backing_ty);
15101510 try writer.writeByte(')');
15111511 }
1512 try dg.renderValue(writer, backing_ty, un.val.toValue(), initializer_type);
1512 try dg.renderValue(writer, backing_ty, Value.fromInterned(un.val), initializer_type);
15131513 },
15141514 .Extern => {
15151515 if (location == .StaticInitializer) {
......@@ -1522,7 +1522,7 @@ pub const DeclGen = struct {
15221522 try writer.writeAll(")(");
15231523 try dg.renderType(writer, backing_ty);
15241524 try writer.writeAll("){");
1525 try dg.renderValue(writer, backing_ty, un.val.toValue(), initializer_type);
1525 try dg.renderValue(writer, backing_ty, Value.fromInterned(un.val), initializer_type);
15261526 try writer.writeAll("})");
15271527 },
15281528 else => unreachable,
......@@ -1534,8 +1534,8 @@ pub const DeclGen = struct {
15341534 try writer.writeByte(')');
15351535 }
15361536
1537 const field_i = mod.unionTagFieldIndex(union_obj, un.tag.toValue()).?;
1538 const field_ty = union_obj.field_types.get(ip)[field_i].toType();
1537 const field_i = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
1538 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_i]);
15391539 const field_name = union_obj.field_names.get(ip)[field_i];
15401540 if (union_obj.getLayout(ip) == .Packed) {
15411541 if (field_ty.hasRuntimeBits(mod)) {
......@@ -1548,7 +1548,7 @@ pub const DeclGen = struct {
15481548 try dg.renderType(writer, ty);
15491549 try writer.writeByte(')');
15501550 }
1551 try dg.renderValue(writer, field_ty, un.val.toValue(), initializer_type);
1551 try dg.renderValue(writer, field_ty, Value.fromInterned(un.val), initializer_type);
15521552 } else {
15531553 try writer.writeAll("0");
15541554 }
......@@ -1560,7 +1560,7 @@ pub const DeclGen = struct {
15601560 const layout = mod.getUnionLayout(union_obj);
15611561 if (layout.tag_size != 0) {
15621562 try writer.writeAll(" .tag = ");
1563 try dg.renderValue(writer, tag_ty, un.tag.toValue(), initializer_type);
1563 try dg.renderValue(writer, tag_ty, Value.fromInterned(un.tag), initializer_type);
15641564 }
15651565 if (ty.unionHasAllZeroBitFieldTypes(mod)) return try writer.writeByte('}');
15661566 if (layout.tag_size != 0) try writer.writeByte(',');
......@@ -1568,11 +1568,11 @@ pub const DeclGen = struct {
15681568 }
15691569 if (field_ty.hasRuntimeBits(mod)) {
15701570 try writer.print(" .{ } = ", .{fmtIdent(ip.stringToSlice(field_name))});
1571 try dg.renderValue(writer, field_ty, un.val.toValue(), initializer_type);
1571 try dg.renderValue(writer, field_ty, Value.fromInterned(un.val), initializer_type);
15721572 try writer.writeByte(' ');
15731573 } else for (union_obj.field_types.get(ip)) |this_field_ty| {
1574 if (!this_field_ty.toType().hasRuntimeBits(mod)) continue;
1575 try dg.renderValue(writer, this_field_ty.toType(), Value.undef, initializer_type);
1574 if (!Type.fromInterned(this_field_ty).hasRuntimeBits(mod)) continue;
1575 try dg.renderValue(writer, Type.fromInterned(this_field_ty), Value.undef, initializer_type);
15761576 break;
15771577 }
15781578 if (ty.unionTagTypeSafety(mod)) |_| try writer.writeByte('}');
......@@ -2527,7 +2527,7 @@ pub fn genErrDecls(o: *Object) !void {
25272527 .ty = .anyerror_type,
25282528 .name = name_nts,
25292529 } });
2530 try o.dg.renderValue(writer, Type.anyerror, err_val.toValue(), .Other);
2530 try o.dg.renderValue(writer, Type.anyerror, Value.fromInterned(err_val), .Other);
25312531 try writer.print(" = {d}u,\n", .{value});
25322532 }
25332533 o.indent_writer.popIndent();
......@@ -2557,7 +2557,7 @@ pub fn genErrDecls(o: *Object) !void {
25572557 try writer.writeAll("static ");
25582558 try o.dg.renderTypeAndName(writer, name_ty, .{ .identifier = identifier }, Const, .none, .complete);
25592559 try writer.writeAll(" = ");
2560 try o.dg.renderValue(writer, name_ty, name_val.toValue(), .StaticInitializer);
2560 try o.dg.renderValue(writer, name_ty, Value.fromInterned(name_val), .StaticInitializer);
25612561 try writer.writeAll(";\n");
25622562 }
25632563
......@@ -2590,7 +2590,7 @@ fn genExports(o: *Object) !void {
25902590 const ip = &mod.intern_pool;
25912591 const decl_index = o.dg.pass.decl;
25922592 const decl = mod.declPtr(decl_index);
2593 const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() };
2593 const tv: TypedValue = .{ .ty = decl.ty, .val = Value.fromInterned((try decl.internValue(mod))) };
25942594 const fwd = o.dg.fwd_decl.writer();
25952595
25962596 const exports = mod.decl_exports.get(decl_index) orelse return;
......@@ -2677,7 +2677,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
26772677 });
26782678 try o.dg.renderTypeAndName(w, name_ty, .{ .identifier = "name" }, Const, .none, .complete);
26792679 try w.writeAll(" = ");
2680 try o.dg.renderValue(w, name_ty, name_val.toValue(), .Initializer);
2680 try o.dg.renderValue(w, name_ty, Value.fromInterned(name_val), .Initializer);
26812681 try w.writeAll(";\n return (");
26822682 try o.dg.renderType(w, name_slice_ty);
26832683 try w.print("){{{}, {}}};\n", .{
......@@ -2817,7 +2817,7 @@ pub fn genDecl(o: *Object) !void {
28172817 const mod = o.dg.module;
28182818 const decl_index = o.dg.pass.decl;
28192819 const decl = mod.declPtr(decl_index);
2820 const tv: TypedValue = .{ .ty = decl.ty, .val = (try decl.internValue(mod)).toValue() };
2820 const tv: TypedValue = .{ .ty = decl.ty, .val = Value.fromInterned((try decl.internValue(mod))) };
28212821
28222822 if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return;
28232823 if (tv.val.getExternFunc(mod)) |_| {
......@@ -2843,7 +2843,7 @@ pub fn genDecl(o: *Object) !void {
28432843 try o.dg.renderTypeAndName(w, tv.ty, decl_c_value, .{}, decl.alignment, .complete);
28442844 if (decl.@"linksection" != .none) try w.writeAll(", read, write)");
28452845 try w.writeAll(" = ");
2846 try o.dg.renderValue(w, tv.ty, variable.init.toValue(), .StaticInitializer);
2846 try o.dg.renderValue(w, tv.ty, Value.fromInterned(variable.init), .StaticInitializer);
28472847 try w.writeByte(';');
28482848 try o.indent_writer.insertNewline();
28492849 } else {
......@@ -3491,7 +3491,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
34913491 const ptr_ty = f.typeOf(ty_op.operand);
34923492 const ptr_scalar_ty = ptr_ty.scalarType(mod);
34933493 const ptr_info = ptr_scalar_ty.ptrInfo(mod);
3494 const src_ty = ptr_info.child.toType();
3494 const src_ty = Type.fromInterned(ptr_info.child);
34953495
34963496 if (!src_ty.hasRuntimeBitsIgnoreComptime(mod)) {
34973497 try reap(f, inst, &.{ty_op.operand});
......@@ -3767,7 +3767,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
37673767 try writer.writeAll("memset(");
37683768 try f.writeCValue(writer, ptr_val, .FunctionArgument);
37693769 try writer.writeAll(", 0xaa, sizeof(");
3770 try f.renderType(writer, ptr_info.child.toType());
3770 try f.renderType(writer, Type.fromInterned(ptr_info.child));
37713771 try writer.writeAll("));\n");
37723772 }
37733773 return .none;
......@@ -3777,7 +3777,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
37773777 ptr_info.flags.alignment.compare(.gte, src_ty.abiAlignment(mod))
37783778 else
37793779 true;
3780 const is_array = lowersToArray(ptr_info.child.toType(), mod);
3780 const is_array = lowersToArray(Type.fromInterned(ptr_info.child), mod);
37813781 const need_memcpy = !is_aligned or is_array;
37823782
37833783 const src_val = try f.resolveInst(bin_op.rhs);
......@@ -3789,7 +3789,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
37893789 if (need_memcpy) {
37903790 // For this memcpy to safely work we need the rhs to have the same
37913791 // underlying type as the lhs (i.e. they must both be arrays of the same underlying type).
3792 assert(src_ty.eql(ptr_info.child.toType(), f.object.dg.module));
3792 assert(src_ty.eql(Type.fromInterned(ptr_info.child), f.object.dg.module));
37933793
37943794 // If the source is a constant, writeCValue will emit a brace initialization
37953795 // so work around this by initializing into new local.
......@@ -5404,7 +5404,7 @@ fn fieldLocation(
54045404 const union_obj = mod.typeToUnion(container_ty).?;
54055405 return switch (union_obj.getLayout(ip)) {
54065406 .Auto, .Extern => {
5407 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
5407 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
54085408 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod))
54095409 return if (container_ty.unionTagTypeSafety(mod) != null and
54105410 !container_ty.unionHasAllZeroBitFieldTypes(mod))
......@@ -6754,7 +6754,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
67546754 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
67556755 const extra = f.air.extraData(Air.Shuffle, ty_pl.payload).data;
67566756
6757 const mask = extra.mask.toValue();
6757 const mask = Value.fromInterned(extra.mask);
67586758 const lhs = try f.resolveInst(extra.a);
67596759 const rhs = try f.resolveInst(extra.b);
67606760
......@@ -7947,7 +7947,7 @@ fn lowerFnRetTy(ret_ty: Type, mod: *Module) !Type {
79477947 .types = &types,
79487948 .values = &values,
79497949 });
7950 return interned.toType();
7950 return Type.fromInterned(interned);
79517951 }
79527952
79537953 return if (ret_ty.hasRuntimeBitsIgnoreComptime(mod)) ret_ty else Type.void;
src/codegen/c/type.zig+15-15
......@@ -1481,7 +1481,7 @@ pub const CType = extern union {
14811481 info.flags.vector_index == .none)
14821482 try mod.intType(.unsigned, info.packed_offset.host_size * 8)
14831483 else
1484 info.child.toType();
1484 Type.fromInterned(info.child);
14851485
14861486 if (try lookup.typeToIndex(pointee_ty, .forward)) |child_idx| {
14871487 self.storage = .{ .child = .{
......@@ -1496,7 +1496,7 @@ pub const CType = extern union {
14961496
14971497 .Struct, .Union => |zig_ty_tag| if (ty.containerLayout(mod) == .Packed) {
14981498 if (mod.typeToPackedStruct(ty)) |packed_struct| {
1499 try self.initType(packed_struct.backingIntType(ip).toType(), kind, lookup);
1499 try self.initType(Type.fromInterned(packed_struct.backingIntType(ip).*), kind, lookup);
15001500 } else {
15011501 const bits: u16 = @intCast(ty.bitSize(mod));
15021502 const int_ty = try mod.intType(.unsigned, bits);
......@@ -1736,10 +1736,10 @@ pub const CType = extern union {
17361736 .complete, .parameter, .global => .parameter,
17371737 .payload => unreachable,
17381738 };
1739 _ = try lookup.typeToIndex(info.return_type.toType(), param_kind);
1739 _ = try lookup.typeToIndex(Type.fromInterned(info.return_type), param_kind);
17401740 for (info.param_types.get(ip)) |param_type| {
1741 if (!param_type.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
1742 _ = try lookup.typeToIndex(param_type.toType(), param_kind);
1741 if (!Type.fromInterned(param_type).hasRuntimeBitsIgnoreComptime(mod)) continue;
1742 _ = try lookup.typeToIndex(Type.fromInterned(param_type), param_kind);
17431743 }
17441744 }
17451745 self.init(if (info.is_var_args) .varargs_function else .function);
......@@ -2033,21 +2033,21 @@ pub const CType = extern union {
20332033
20342034 var c_params_len: usize = 0;
20352035 for (info.param_types.get(ip)) |param_type| {
2036 if (!param_type.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
2036 if (!Type.fromInterned(param_type).hasRuntimeBitsIgnoreComptime(mod)) continue;
20372037 c_params_len += 1;
20382038 }
20392039
20402040 const params_pl = try arena.alloc(Index, c_params_len);
20412041 var c_param_i: usize = 0;
20422042 for (info.param_types.get(ip)) |param_type| {
2043 if (!param_type.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
2044 params_pl[c_param_i] = store.set.typeToIndex(param_type.toType(), mod, param_kind).?;
2043 if (!Type.fromInterned(param_type).hasRuntimeBitsIgnoreComptime(mod)) continue;
2044 params_pl[c_param_i] = store.set.typeToIndex(Type.fromInterned(param_type), mod, param_kind).?;
20452045 c_param_i += 1;
20462046 }
20472047
20482048 const fn_pl = try arena.create(Payload.Function);
20492049 fn_pl.* = .{ .base = .{ .tag = t }, .data = .{
2050 .return_type = store.set.typeToIndex(info.return_type.toType(), mod, param_kind).?,
2050 .return_type = store.set.typeToIndex(Type.fromInterned(info.return_type), mod, param_kind).?,
20512051 .param_types = params_pl,
20522052 } };
20532053 return initPayload(fn_pl);
......@@ -2167,18 +2167,18 @@ pub const CType = extern union {
21672167 .payload => unreachable,
21682168 };
21692169
2170 if (!self.eqlRecurse(info.return_type.toType(), data.return_type, param_kind))
2170 if (!self.eqlRecurse(Type.fromInterned(info.return_type), data.return_type, param_kind))
21712171 return false;
21722172
21732173 var c_param_i: usize = 0;
21742174 for (info.param_types.get(ip)) |param_type| {
2175 if (!param_type.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
2175 if (!Type.fromInterned(param_type).hasRuntimeBitsIgnoreComptime(mod)) continue;
21762176
21772177 if (c_param_i >= data.param_types.len) return false;
21782178 const param_cty = data.param_types[c_param_i];
21792179 c_param_i += 1;
21802180
2181 if (!self.eqlRecurse(param_type.toType(), param_cty, param_kind))
2181 if (!self.eqlRecurse(Type.fromInterned(param_type), param_cty, param_kind))
21822182 return false;
21832183 }
21842184 return c_param_i == data.param_types.len;
......@@ -2282,10 +2282,10 @@ pub const CType = extern union {
22822282 .payload => unreachable,
22832283 };
22842284
2285 self.updateHasherRecurse(hasher, info.return_type.toType(), param_kind);
2285 self.updateHasherRecurse(hasher, Type.fromInterned(info.return_type), param_kind);
22862286 for (info.param_types.get(ip)) |param_type| {
2287 if (!param_type.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
2288 self.updateHasherRecurse(hasher, param_type.toType(), param_kind);
2287 if (!Type.fromInterned(param_type).hasRuntimeBitsIgnoreComptime(mod)) continue;
2288 self.updateHasherRecurse(hasher, Type.fromInterned(param_type), param_kind);
22892289 }
22902290 },
22912291
src/codegen/llvm.zig+128-128
......@@ -1399,12 +1399,12 @@ pub const Object = struct {
13991399 break :param param;
14001400 } else .none;
14011401
1402 if (ccAbiPromoteInt(fn_info.cc, mod, fn_info.return_type.toType())) |s| switch (s) {
1402 if (ccAbiPromoteInt(fn_info.cc, mod, Type.fromInterned(fn_info.return_type))) |s| switch (s) {
14031403 .signed => try attributes.addRetAttr(.signext, &o.builder),
14041404 .unsigned => try attributes.addRetAttr(.zeroext, &o.builder),
14051405 };
14061406
1407 const err_return_tracing = fn_info.return_type.toType().isError(mod) and
1407 const err_return_tracing = Type.fromInterned(fn_info.return_type).isError(mod) and
14081408 mod.comp.bin_file.options.error_return_tracing;
14091409
14101410 const err_ret_trace: Builder.Value = if (err_return_tracing) param: {
......@@ -1430,7 +1430,7 @@ pub const Object = struct {
14301430 .byval => {
14311431 assert(!it.byval_attr);
14321432 const param_index = it.zig_index - 1;
1433 const param_ty = fn_info.param_types.get(ip)[param_index].toType();
1433 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
14341434 const param = wip.arg(llvm_arg_i);
14351435
14361436 if (isByRef(param_ty, mod)) {
......@@ -1447,7 +1447,7 @@ pub const Object = struct {
14471447 llvm_arg_i += 1;
14481448 },
14491449 .byref => {
1450 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1].toType();
1450 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
14511451 const param_llvm_ty = try o.lowerType(param_ty);
14521452 const param = wip.arg(llvm_arg_i);
14531453 const alignment = param_ty.abiAlignment(mod).toLlvm();
......@@ -1462,7 +1462,7 @@ pub const Object = struct {
14621462 }
14631463 },
14641464 .byref_mut => {
1465 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1].toType();
1465 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
14661466 const param_llvm_ty = try o.lowerType(param_ty);
14671467 const param = wip.arg(llvm_arg_i);
14681468 const alignment = param_ty.abiAlignment(mod).toLlvm();
......@@ -1478,7 +1478,7 @@ pub const Object = struct {
14781478 },
14791479 .abi_sized_int => {
14801480 assert(!it.byval_attr);
1481 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1].toType();
1481 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
14821482 const param = wip.arg(llvm_arg_i);
14831483 llvm_arg_i += 1;
14841484
......@@ -1494,7 +1494,7 @@ pub const Object = struct {
14941494 },
14951495 .slice => {
14961496 assert(!it.byval_attr);
1497 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1].toType();
1497 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
14981498 const ptr_info = param_ty.ptrInfo(mod);
14991499
15001500 if (math.cast(u5, it.zig_index - 1)) |i| {
......@@ -1511,7 +1511,7 @@ pub const Object = struct {
15111511 const elem_align = (if (ptr_info.flags.alignment != .none)
15121512 @as(InternPool.Alignment, ptr_info.flags.alignment)
15131513 else
1514 ptr_info.child.toType().abiAlignment(mod).max(.@"1")).toLlvm();
1514 Type.fromInterned(ptr_info.child).abiAlignment(mod).max(.@"1")).toLlvm();
15151515 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);
15161516 const ptr_param = wip.arg(llvm_arg_i);
15171517 llvm_arg_i += 1;
......@@ -1526,7 +1526,7 @@ pub const Object = struct {
15261526 .multiple_llvm_types => {
15271527 assert(!it.byval_attr);
15281528 const field_types = it.types_buffer[0..it.types_len];
1529 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1].toType();
1529 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
15301530 const param_llvm_ty = try o.lowerType(param_ty);
15311531 const param_alignment = param_ty.abiAlignment(mod).toLlvm();
15321532 const arg_ptr = try buildAllocaInner(&wip, false, param_llvm_ty, param_alignment, target);
......@@ -1553,7 +1553,7 @@ pub const Object = struct {
15531553 args.appendAssumeCapacity(try wip.cast(.bitcast, param, .half, ""));
15541554 },
15551555 .float_array => {
1556 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1].toType();
1556 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
15571557 const param_llvm_ty = try o.lowerType(param_ty);
15581558 const param = wip.arg(llvm_arg_i);
15591559 llvm_arg_i += 1;
......@@ -1568,7 +1568,7 @@ pub const Object = struct {
15681568 try wip.load(.normal, param_llvm_ty, arg_ptr, alignment, ""));
15691569 },
15701570 .i32_array, .i64_array => {
1571 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1].toType();
1571 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
15721572 const param_llvm_ty = try o.lowerType(param_ty);
15731573 const param = wip.arg(llvm_arg_i);
15741574 llvm_arg_i += 1;
......@@ -1819,7 +1819,7 @@ pub const Object = struct {
18191819 const llvm_addr_space = toLlvmAddressSpace(.generic, o.target);
18201820 const variable_index = try o.builder.addVariable(
18211821 main_exp_name,
1822 try o.lowerType(mod.intern_pool.typeOf(exported_value).toType()),
1822 try o.lowerType(Type.fromInterned(mod.intern_pool.typeOf(exported_value))),
18231823 llvm_addr_space,
18241824 );
18251825 const global_index = variable_index.ptrConst(&o.builder).global;
......@@ -1961,7 +1961,7 @@ pub const Object = struct {
19611961 resolve: DebugResolveStatus,
19621962 opt_fwd_decl: ?*llvm.DIType,
19631963 ) Allocator.Error!*llvm.DIType {
1964 const ty = gop.key_ptr.toType();
1964 const ty = Type.fromInterned(gop.key_ptr.*);
19651965 const gpa = o.gpa;
19661966 const target = o.target;
19671967 const dib = o.di_builder.?;
......@@ -2004,7 +2004,7 @@ pub const Object = struct {
20042004 const enumerators = try gpa.alloc(*llvm.DIEnumerator, enum_type.names.len);
20052005 defer gpa.free(enumerators);
20062006
2007 const int_ty = enum_type.tag_ty.toType();
2007 const int_ty = Type.fromInterned(enum_type.tag_ty);
20082008 const int_info = ty.intInfo(mod);
20092009 assert(int_info.bits != 0);
20102010
......@@ -2013,7 +2013,7 @@ pub const Object = struct {
20132013
20142014 var bigint_space: Value.BigIntSpace = undefined;
20152015 const bigint = if (enum_type.values.len != 0)
2016 enum_type.values.get(ip)[i].toValue().toBigInt(&bigint_space, mod)
2016 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, mod)
20172017 else
20182018 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
20192019
......@@ -2083,10 +2083,10 @@ pub const Object = struct {
20832083 ptr_info.flags.is_const or
20842084 ptr_info.flags.is_volatile or
20852085 ptr_info.flags.size == .Many or ptr_info.flags.size == .C or
2086 !ptr_info.child.toType().hasRuntimeBitsIgnoreComptime(mod))
2086 !Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(mod))
20872087 {
20882088 const bland_ptr_ty = try mod.ptrType(.{
2089 .child = if (!ptr_info.child.toType().hasRuntimeBitsIgnoreComptime(mod))
2089 .child = if (!Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(mod))
20902090 .anyopaque_type
20912091 else
20922092 ptr_info.child,
......@@ -2183,7 +2183,7 @@ pub const Object = struct {
21832183 return full_di_ty;
21842184 }
21852185
2186 const elem_di_ty = try o.lowerDebugType(ptr_info.child.toType(), .fwd);
2186 const elem_di_ty = try o.lowerDebugType(Type.fromInterned(ptr_info.child), .fwd);
21872187 const name = try o.allocTypeName(ty);
21882188 defer gpa.free(name);
21892189 const ptr_di_ty = dib.createPointerType(
......@@ -2456,7 +2456,7 @@ pub const Object = struct {
24562456 if (mod.typeToPackedStruct(ty)) |struct_type| {
24572457 const backing_int_ty = struct_type.backingIntType(ip).*;
24582458 if (backing_int_ty != .none) {
2459 const info = backing_int_ty.toType().intInfo(mod);
2459 const info = Type.fromInterned(backing_int_ty).intInfo(mod);
24602460 const dwarf_encoding: c_uint = switch (info.signedness) {
24612461 .signed => DW.ATE.signed,
24622462 .unsigned => DW.ATE.unsigned,
......@@ -2492,10 +2492,10 @@ pub const Object = struct {
24922492 var offset: u64 = 0;
24932493
24942494 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {
2495 if (field_val != .none or !field_ty.toType().hasRuntimeBits(mod)) continue;
2495 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
24962496
2497 const field_size = field_ty.toType().abiSize(mod);
2498 const field_align = field_ty.toType().abiAlignment(mod);
2497 const field_size = Type.fromInterned(field_ty).abiSize(mod);
2498 const field_align = Type.fromInterned(field_ty).abiAlignment(mod);
24992499 const field_offset = field_align.forward(offset);
25002500 offset = field_offset + field_size;
25012501
......@@ -2514,7 +2514,7 @@ pub const Object = struct {
25142514 field_align.toByteUnits(0) * 8, // align in bits
25152515 field_offset * 8, // offset in bits
25162516 0, // flags
2517 try o.lowerDebugType(field_ty.toType(), .full),
2517 try o.lowerDebugType(Type.fromInterned(field_ty), .full),
25182518 ));
25192519 }
25202520
......@@ -2579,7 +2579,7 @@ pub const Object = struct {
25792579 comptime assert(struct_layout_version == 2);
25802580 var it = struct_type.iterateRuntimeOrder(ip);
25812581 while (it.next()) |field_index| {
2582 const field_ty = struct_type.field_types.get(ip)[field_index].toType();
2582 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
25832583 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
25842584 const field_size = field_ty.abiSize(mod);
25852585 const field_align = mod.structFieldAlignment(
......@@ -2661,7 +2661,7 @@ pub const Object = struct {
26612661 const layout = mod.getUnionLayout(union_obj);
26622662
26632663 if (layout.payload_size == 0) {
2664 const tag_di_ty = try o.lowerDebugType(union_obj.enum_tag_ty.toType(), .full);
2664 const tag_di_ty = try o.lowerDebugType(Type.fromInterned(union_obj.enum_tag_ty), .full);
26652665 const di_fields = [_]*llvm.DIType{tag_di_ty};
26662666 const full_di_ty = dib.createStructType(
26672667 compile_unit_scope,
......@@ -2692,12 +2692,12 @@ pub const Object = struct {
26922692
26932693 for (0..union_obj.field_names.len) |field_index| {
26942694 const field_ty = union_obj.field_types.get(ip)[field_index];
2695 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
2695 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
26962696
2697 const field_size = field_ty.toType().abiSize(mod);
2697 const field_size = Type.fromInterned(field_ty).abiSize(mod);
26982698 const field_align = mod.unionFieldNormalAlignment(union_obj, @intCast(field_index));
26992699
2700 const field_di_ty = try o.lowerDebugType(field_ty.toType(), .full);
2700 const field_di_ty = try o.lowerDebugType(Type.fromInterned(field_ty), .full);
27012701 const field_name = union_obj.field_names.get(ip)[field_index];
27022702 di_fields.appendAssumeCapacity(dib.createMemberType(
27032703 fwd_decl.toScope(),
......@@ -2759,7 +2759,7 @@ pub const Object = struct {
27592759 layout.tag_align.toByteUnits(0) * 8,
27602760 tag_offset * 8, // offset in bits
27612761 0, // flags
2762 try o.lowerDebugType(union_obj.enum_tag_ty.toType(), .full),
2762 try o.lowerDebugType(Type.fromInterned(union_obj.enum_tag_ty), .full),
27632763 );
27642764
27652765 const payload_di = dib.createMemberType(
......@@ -2807,20 +2807,20 @@ pub const Object = struct {
28072807 defer param_di_types.deinit();
28082808
28092809 // Return type goes first.
2810 if (fn_info.return_type.toType().hasRuntimeBitsIgnoreComptime(mod)) {
2810 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(mod)) {
28112811 const sret = firstParamSRet(fn_info, mod);
2812 const di_ret_ty = if (sret) Type.void else fn_info.return_type.toType();
2812 const di_ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
28132813 try param_di_types.append(try o.lowerDebugType(di_ret_ty, .full));
28142814
28152815 if (sret) {
2816 const ptr_ty = try mod.singleMutPtrType(fn_info.return_type.toType());
2816 const ptr_ty = try mod.singleMutPtrType(Type.fromInterned(fn_info.return_type));
28172817 try param_di_types.append(try o.lowerDebugType(ptr_ty, .full));
28182818 }
28192819 } else {
28202820 try param_di_types.append(try o.lowerDebugType(Type.void, .full));
28212821 }
28222822
2823 if (fn_info.return_type.toType().isError(mod) and
2823 if (Type.fromInterned(fn_info.return_type).isError(mod) and
28242824 o.module.comp.bin_file.options.error_return_tracing)
28252825 {
28262826 const ptr_ty = try mod.singleMutPtrType(try o.getStackTraceType());
......@@ -2828,7 +2828,7 @@ pub const Object = struct {
28282828 }
28292829
28302830 for (0..fn_info.param_types.len) |i| {
2831 const param_ty = fn_info.param_types.get(ip)[i].toType();
2831 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]);
28322832 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
28332833
28342834 if (isByRef(param_ty, mod)) {
......@@ -2982,13 +2982,13 @@ pub const Object = struct {
29822982 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
29832983 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);
29842984
2985 const raw_llvm_ret_ty = try o.lowerType(fn_info.return_type.toType());
2985 const raw_llvm_ret_ty = try o.lowerType(Type.fromInterned(fn_info.return_type));
29862986 try attributes.addParamAttr(llvm_arg_i, .{ .sret = raw_llvm_ret_ty }, &o.builder);
29872987
29882988 llvm_arg_i += 1;
29892989 }
29902990
2991 const err_return_tracing = fn_info.return_type.toType().isError(mod) and
2991 const err_return_tracing = Type.fromInterned(fn_info.return_type).isError(mod) and
29922992 mod.comp.bin_file.options.error_return_tracing;
29932993
29942994 if (err_return_tracing) {
......@@ -3022,15 +3022,15 @@ pub const Object = struct {
30223022 while (try it.next()) |lowering| switch (lowering) {
30233023 .byval => {
30243024 const param_index = it.zig_index - 1;
3025 const param_ty = fn_info.param_types.get(ip)[param_index].toType();
3025 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
30263026 if (!isByRef(param_ty, mod)) {
30273027 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
30283028 }
30293029 },
30303030 .byref => {
3031 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1];
3032 const param_llvm_ty = try o.lowerType(param_ty.toType());
3033 const alignment = param_ty.toType().abiAlignment(mod);
3031 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
3032 const param_llvm_ty = try o.lowerType(param_ty);
3033 const alignment = param_ty.abiAlignment(mod);
30343034 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty);
30353035 },
30363036 .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder),
......@@ -3138,7 +3138,7 @@ pub const Object = struct {
31383138
31393139 const variable_index = try o.builder.addVariable(
31403140 try o.builder.fmt("__anon_{d}", .{@intFromEnum(decl_val)}),
3141 try o.lowerType(decl_ty.toType()),
3141 try o.lowerType(Type.fromInterned(decl_ty)),
31423142 llvm_addr_space,
31433143 );
31443144 gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
......@@ -3328,23 +3328,23 @@ pub const Object = struct {
33283328 },
33293329 .array_type => |array_type| o.builder.arrayType(
33303330 array_type.len + @intFromBool(array_type.sentinel != .none),
3331 try o.lowerType(array_type.child.toType()),
3331 try o.lowerType(Type.fromInterned(array_type.child)),
33323332 ),
33333333 .vector_type => |vector_type| o.builder.vectorType(
33343334 .normal,
33353335 vector_type.len,
3336 try o.lowerType(vector_type.child.toType()),
3336 try o.lowerType(Type.fromInterned(vector_type.child)),
33373337 ),
33383338 .opt_type => |child_ty| {
3339 if (!child_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) return .i8;
3339 if (!Type.fromInterned(child_ty).hasRuntimeBitsIgnoreComptime(mod)) return .i8;
33403340
3341 const payload_ty = try o.lowerType(child_ty.toType());
3341 const payload_ty = try o.lowerType(Type.fromInterned(child_ty));
33423342 if (t.optionalReprIsPayload(mod)) return payload_ty;
33433343
33443344 comptime assert(optional_layout_version == 3);
33453345 var fields: [3]Builder.Type = .{ payload_ty, .i8, undefined };
33463346 var fields_len: usize = 2;
3347 const offset = child_ty.toType().abiSize(mod) + 1;
3347 const offset = Type.fromInterned(child_ty).abiSize(mod) + 1;
33483348 const abi_size = t.abiSize(mod);
33493349 const padding_len = abi_size - offset;
33503350 if (padding_len > 0) {
......@@ -3356,15 +3356,15 @@ pub const Object = struct {
33563356 .anyframe_type => @panic("TODO implement lowerType for AnyFrame types"),
33573357 .error_union_type => |error_union_type| {
33583358 const error_type = try o.errorIntType();
3359 if (!error_union_type.payload_type.toType().hasRuntimeBitsIgnoreComptime(mod))
3359 if (!Type.fromInterned(error_union_type.payload_type).hasRuntimeBitsIgnoreComptime(mod))
33603360 return error_type;
3361 const payload_type = try o.lowerType(error_union_type.payload_type.toType());
3361 const payload_type = try o.lowerType(Type.fromInterned(error_union_type.payload_type));
33623362 const err_int_ty = try mod.errorIntType();
33633363
3364 const payload_align = error_union_type.payload_type.toType().abiAlignment(mod);
3364 const payload_align = Type.fromInterned(error_union_type.payload_type).abiAlignment(mod);
33653365 const error_align = err_int_ty.abiAlignment(mod);
33663366
3367 const payload_size = error_union_type.payload_type.toType().abiSize(mod);
3367 const payload_size = Type.fromInterned(error_union_type.payload_type).abiSize(mod);
33683368 const error_size = err_int_ty.abiSize(mod);
33693369
33703370 var fields: [3]Builder.Type = undefined;
......@@ -3398,7 +3398,7 @@ pub const Object = struct {
33983398 if (gop.found_existing) return gop.value_ptr.*;
33993399
34003400 if (struct_type.layout == .Packed) {
3401 const int_ty = try o.lowerType(struct_type.backingIntType(ip).toType());
3401 const int_ty = try o.lowerType(Type.fromInterned(struct_type.backingIntType(ip).*));
34023402 gop.value_ptr.* = int_ty;
34033403 return int_ty;
34043404 }
......@@ -3423,7 +3423,7 @@ pub const Object = struct {
34233423 // When we encounter a zero-bit field, we place it here so we know to map it to the next non-zero-bit field (if any).
34243424 var it = struct_type.iterateRuntimeOrder(ip);
34253425 while (it.next()) |field_index| {
3426 const field_ty = struct_type.field_types.get(ip)[field_index].toType();
3426 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
34273427 const field_align = mod.structFieldAlignment(
34283428 struct_type.fieldAlign(ip, field_index),
34293429 field_ty,
......@@ -3499,7 +3499,7 @@ pub const Object = struct {
34993499 ) |field_ty, field_val, field_index| {
35003500 if (field_val != .none) continue;
35013501
3502 const field_align = field_ty.toType().abiAlignment(mod);
3502 const field_align = Type.fromInterned(field_ty).abiAlignment(mod);
35033503 big_align = big_align.max(field_align);
35043504 const prev_offset = offset;
35053505 offset = field_align.forward(offset);
......@@ -3509,7 +3509,7 @@ pub const Object = struct {
35093509 o.gpa,
35103510 try o.builder.arrayType(padding_len, .i8),
35113511 );
3512 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) {
3512 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) {
35133513 // This is a zero-bit field. If there are runtime bits after this field,
35143514 // map to the next LLVM field (which we know exists): otherwise, don't
35153515 // map the field, indicating it's at the end of the struct.
......@@ -3525,9 +3525,9 @@ pub const Object = struct {
35253525 .struct_ty = t.toIntern(),
35263526 .field_index = @intCast(field_index),
35273527 }, @intCast(llvm_field_types.items.len));
3528 try llvm_field_types.append(o.gpa, try o.lowerType(field_ty.toType()));
3528 try llvm_field_types.append(o.gpa, try o.lowerType(Type.fromInterned(field_ty)));
35293529
3530 offset += field_ty.toType().abiSize(mod);
3530 offset += Type.fromInterned(field_ty).abiSize(mod);
35313531 }
35323532 {
35333533 const prev_offset = offset;
......@@ -3554,7 +3554,7 @@ pub const Object = struct {
35543554 }
35553555
35563556 if (layout.payload_size == 0) {
3557 const enum_tag_ty = try o.lowerType(union_obj.enum_tag_ty.toType());
3557 const enum_tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
35583558 gop.value_ptr.* = enum_tag_ty;
35593559 return enum_tag_ty;
35603560 }
......@@ -3565,7 +3565,7 @@ pub const Object = struct {
35653565 const ty = try o.builder.opaqueType(name);
35663566 gop.value_ptr.* = ty; // must be done before any recursive calls
35673567
3568 const aligned_field_ty = union_obj.field_types.get(ip)[layout.most_aligned_field].toType();
3568 const aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[layout.most_aligned_field]);
35693569 const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty);
35703570
35713571 const payload_ty = ty: {
......@@ -3589,7 +3589,7 @@ pub const Object = struct {
35893589 );
35903590 return ty;
35913591 }
3592 const enum_tag_ty = try o.lowerType(union_obj.enum_tag_ty.toType());
3592 const enum_tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
35933593
35943594 // Put the tag before or after the payload depending on which one's
35953595 // alignment is greater.
......@@ -3624,7 +3624,7 @@ pub const Object = struct {
36243624 }
36253625 return gop.value_ptr.*;
36263626 },
3627 .enum_type => |enum_type| try o.lowerType(enum_type.tag_ty.toType()),
3627 .enum_type => |enum_type| try o.lowerType(Type.fromInterned(enum_type.tag_ty)),
36283628 .func_type => |func_type| try o.lowerTypeFn(func_type),
36293629 .error_set_type, .inferred_error_set_type => try o.errorIntType(),
36303630 // values, not types
......@@ -3678,7 +3678,7 @@ pub const Object = struct {
36783678 try llvm_params.append(o.gpa, .ptr);
36793679 }
36803680
3681 if (fn_info.return_type.toType().isError(mod) and
3681 if (Type.fromInterned(fn_info.return_type).isError(mod) and
36823682 mod.comp.bin_file.options.error_return_tracing)
36833683 {
36843684 const ptr_ty = try mod.singleMutPtrType(try o.getStackTraceType());
......@@ -3689,20 +3689,20 @@ pub const Object = struct {
36893689 while (try it.next()) |lowering| switch (lowering) {
36903690 .no_bits => continue,
36913691 .byval => {
3692 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1].toType();
3692 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
36933693 try llvm_params.append(o.gpa, try o.lowerType(param_ty));
36943694 },
36953695 .byref, .byref_mut => {
36963696 try llvm_params.append(o.gpa, .ptr);
36973697 },
36983698 .abi_sized_int => {
3699 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1].toType();
3699 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
37003700 try llvm_params.append(o.gpa, try o.builder.intType(
37013701 @intCast(param_ty.abiSize(mod) * 8),
37023702 ));
37033703 },
37043704 .slice => {
3705 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1].toType();
3705 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
37063706 try llvm_params.appendSlice(o.gpa, &.{
37073707 try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(mod), target)),
37083708 try o.lowerType(Type.usize),
......@@ -3715,7 +3715,7 @@ pub const Object = struct {
37153715 try llvm_params.append(o.gpa, .i16);
37163716 },
37173717 .float_array => |count| {
3718 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1].toType();
3718 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
37193719 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(param_ty, mod).?);
37203720 try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty));
37213721 },
......@@ -3740,14 +3740,14 @@ pub const Object = struct {
37403740 const ip = &mod.intern_pool;
37413741 const target = mod.getTarget();
37423742
3743 const val = arg_val.toValue();
3743 const val = Value.fromInterned(arg_val);
37443744 const val_key = ip.indexToKey(val.toIntern());
37453745
37463746 if (val.isUndefDeep(mod)) {
3747 return o.builder.undefConst(try o.lowerType(val_key.typeOf().toType()));
3747 return o.builder.undefConst(try o.lowerType(Type.fromInterned(val_key.typeOf())));
37483748 }
37493749
3750 const ty = val_key.typeOf().toType();
3750 const ty = Type.fromInterned(val_key.typeOf());
37513751 return switch (val_key) {
37523752 .int_type,
37533753 .ptr_type,
......@@ -4064,9 +4064,9 @@ pub const Object = struct {
40644064 0..,
40654065 ) |field_ty, field_val, field_index| {
40664066 if (field_val != .none) continue;
4067 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
4067 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
40684068
4069 const field_align = field_ty.toType().abiAlignment(mod);
4069 const field_align = Type.fromInterned(field_ty).abiAlignment(mod);
40704070 big_align = big_align.max(field_align);
40714071 const prev_offset = offset;
40724072 offset = field_align.forward(offset);
......@@ -4088,7 +4088,7 @@ pub const Object = struct {
40884088 need_unnamed = true;
40894089 llvm_index += 1;
40904090
4091 offset += field_ty.toType().abiSize(mod);
4091 offset += Type.fromInterned(field_ty).abiSize(mod);
40924092 }
40934093 {
40944094 const prev_offset = offset;
......@@ -4116,14 +4116,14 @@ pub const Object = struct {
41164116 var running_int = try o.builder.intConst(struct_ty, 0);
41174117 var running_bits: u16 = 0;
41184118 for (struct_type.field_types.get(ip), 0..) |field_ty, field_index| {
4119 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
4119 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
41204120
41214121 const non_int_val =
41224122 try o.lowerValue((try val.fieldValue(mod, field_index)).toIntern());
4123 const ty_bit_size: u16 = @intCast(field_ty.toType().bitSize(mod));
4123 const ty_bit_size: u16 = @intCast(Type.fromInterned(field_ty).bitSize(mod));
41244124 const small_int_ty = try o.builder.intType(ty_bit_size);
41254125 const small_int_val = try o.builder.castConst(
4126 if (field_ty.toType().isPtrAtRuntime(mod)) .ptrtoint else .bitcast,
4126 if (Type.fromInterned(field_ty).isPtrAtRuntime(mod)) .ptrtoint else .bitcast,
41274127 non_int_val,
41284128 small_int_ty,
41294129 );
......@@ -4159,7 +4159,7 @@ pub const Object = struct {
41594159 var need_unnamed = false;
41604160 var field_it = struct_type.iterateRuntimeOrder(ip);
41614161 while (field_it.next()) |field_index| {
4162 const field_ty = struct_type.field_types.get(ip)[field_index].toType();
4162 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
41634163 const field_align = mod.structFieldAlignment(
41644164 struct_type.fieldAlign(ip, field_index),
41654165 field_ty,
......@@ -4225,8 +4225,8 @@ pub const Object = struct {
42254225
42264226 var need_unnamed = false;
42274227 const payload = if (un.tag != .none) p: {
4228 const field_index = mod.unionTagFieldIndex(union_obj, un.tag.toValue()).?;
4229 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
4228 const field_index = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
4229 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
42304230 if (container_layout == .Packed) {
42314231 if (!field_ty.hasRuntimeBits(mod)) return o.builder.intConst(union_ty, 0);
42324232 const small_int_val = try o.builder.castConst(
......@@ -4313,7 +4313,7 @@ pub const Object = struct {
43134313 .undef => return o.builder.undefConst(.ptr),
43144314 .int => {
43154315 var bigint_space: Value.BigIntSpace = undefined;
4316 const bigint = val.toValue().toBigInt(&bigint_space, mod);
4316 const bigint = Value.fromInterned(val).toBigInt(&bigint_space, mod);
43174317 const llvm_int = try lowerBigInt(o, Type.usize, bigint);
43184318 return o.builder.castConst(.inttoptr, llvm_int, .ptr);
43194319 },
......@@ -4345,12 +4345,12 @@ pub const Object = struct {
43454345 return switch (ptr.addr) {
43464346 .decl => |decl| try o.lowerParentPtrDecl(decl),
43474347 .mut_decl => |mut_decl| try o.lowerParentPtrDecl(mut_decl.decl),
4348 .anon_decl => |ad| try o.lowerAnonDeclRef(ad.orig_ty.toType(), ad),
4348 .anon_decl => |ad| try o.lowerAnonDeclRef(Type.fromInterned(ad.orig_ty), ad),
43494349 .int => |int| try o.lowerIntAsPtr(int),
43504350 .eu_payload => |eu_ptr| {
4351 const parent_ptr = try o.lowerParentPtr(eu_ptr.toValue());
4351 const parent_ptr = try o.lowerParentPtr(Value.fromInterned(eu_ptr));
43524352
4353 const eu_ty = ip.typeOf(eu_ptr).toType().childType(mod);
4353 const eu_ty = Type.fromInterned(ip.typeOf(eu_ptr)).childType(mod);
43544354 const payload_ty = eu_ty.errorUnionPayload(mod);
43554355 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
43564356 // In this case, we represent pointer to error union the same as pointer
......@@ -4367,9 +4367,9 @@ pub const Object = struct {
43674367 });
43684368 },
43694369 .opt_payload => |opt_ptr| {
4370 const parent_ptr = try o.lowerParentPtr(opt_ptr.toValue());
4370 const parent_ptr = try o.lowerParentPtr(Value.fromInterned(opt_ptr));
43714371
4372 const opt_ty = ip.typeOf(opt_ptr).toType().childType(mod);
4372 const opt_ty = Type.fromInterned(ip.typeOf(opt_ptr)).childType(mod);
43734373 const payload_ty = opt_ty.optionalChild(mod);
43744374 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod) or
43754375 payload_ty.optionalReprIsPayload(mod))
......@@ -4385,16 +4385,16 @@ pub const Object = struct {
43854385 },
43864386 .comptime_field => unreachable,
43874387 .elem => |elem_ptr| {
4388 const parent_ptr = try o.lowerParentPtr(elem_ptr.base.toValue());
4389 const elem_ty = ip.typeOf(elem_ptr.base).toType().elemType2(mod);
4388 const parent_ptr = try o.lowerParentPtr(Value.fromInterned(elem_ptr.base));
4389 const elem_ty = Type.fromInterned(ip.typeOf(elem_ptr.base)).elemType2(mod);
43904390
43914391 return o.builder.gepConst(.inbounds, try o.lowerType(elem_ty), parent_ptr, null, &.{
43924392 try o.builder.intConst(try o.lowerType(Type.usize), elem_ptr.index),
43934393 });
43944394 },
43954395 .field => |field_ptr| {
4396 const parent_ptr = try o.lowerParentPtr(field_ptr.base.toValue());
4397 const parent_ptr_ty = ip.typeOf(field_ptr.base).toType();
4396 const parent_ptr = try o.lowerParentPtr(Value.fromInterned(field_ptr.base));
4397 const parent_ptr_ty = Type.fromInterned(ip.typeOf(field_ptr.base));
43984398 const parent_ty = parent_ptr_ty.childType(mod);
43994399 const field_index: u32 = @intCast(field_ptr.index);
44004400 switch (parent_ty.zigTypeTag(mod)) {
......@@ -4420,7 +4420,7 @@ pub const Object = struct {
44204420 },
44214421 .Struct => {
44224422 if (mod.typeToPackedStruct(parent_ty)) |struct_type| {
4423 const ptr_info = ptr.ty.toType().ptrInfo(mod);
4423 const ptr_info = Type.fromInterned(ptr.ty).ptrInfo(mod);
44244424 if (ptr_info.packed_offset.host_size != 0) return parent_ptr;
44254425
44264426 const parent_ptr_info = parent_ptr_ty.ptrInfo(mod);
......@@ -4470,13 +4470,13 @@ pub const Object = struct {
44704470 const mod = o.module;
44714471 const ip = &mod.intern_pool;
44724472 const decl_val = anon_decl.val;
4473 const decl_ty = ip.typeOf(decl_val).toType();
4473 const decl_ty = Type.fromInterned(ip.typeOf(decl_val));
44744474 const target = mod.getTarget();
44754475
4476 if (decl_val.toValue().getFunction(mod)) |func| {
4476 if (Value.fromInterned(decl_val).getFunction(mod)) |func| {
44774477 _ = func;
44784478 @panic("TODO");
4479 } else if (decl_val.toValue().getExternFunc(mod)) |func| {
4479 } else if (Value.fromInterned(decl_val).getExternFunc(mod)) |func| {
44804480 _ = func;
44814481 @panic("TODO");
44824482 }
......@@ -4488,7 +4488,7 @@ pub const Object = struct {
44884488 if (is_fn_body)
44894489 @panic("TODO");
44904490
4491 const orig_ty = anon_decl.orig_ty.toType();
4491 const orig_ty = Type.fromInterned(anon_decl.orig_ty);
44924492 const llvm_addr_space = toLlvmAddressSpace(orig_ty.ptrAddressSpace(mod), target);
44934493 const alignment = orig_ty.ptrAlignment(mod);
44944494 const llvm_global = (try o.resolveGlobalAnonDecl(decl_val, llvm_addr_space, alignment)).ptrConst(&o.builder).global;
......@@ -4620,7 +4620,7 @@ pub const Object = struct {
46204620 const elem_align = if (ptr_info.flags.alignment != .none)
46214621 ptr_info.flags.alignment
46224622 else
4623 ptr_info.child.toType().abiAlignment(mod).max(.@"1");
4623 Type.fromInterned(ptr_info.child).abiAlignment(mod).max(.@"1");
46244624 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align.toLlvm() }, &o.builder);
46254625 } else if (ccAbiPromoteInt(fn_info.cc, mod, param_ty)) |s| switch (s) {
46264626 .signed => try attributes.addParamAttr(llvm_arg_i, .signext, &o.builder),
......@@ -4835,8 +4835,8 @@ pub const FuncGen = struct {
48354835 if (o.null_opt_usize == .no_init) {
48364836 const ty = try mod.intern(.{ .opt_type = .usize_type });
48374837 o.null_opt_usize = try self.resolveValue(.{
4838 .ty = ty.toType(),
4839 .val = (try mod.intern(.{ .opt = .{ .ty = ty, .val = .none } })).toValue(),
4838 .ty = Type.fromInterned(ty),
4839 .val = Value.fromInterned((try mod.intern(.{ .opt = .{ .ty = ty, .val = .none } }))),
48404840 });
48414841 }
48424842 return o.null_opt_usize;
......@@ -5116,7 +5116,7 @@ pub const FuncGen = struct {
51165116 else => unreachable,
51175117 };
51185118 const fn_info = mod.typeToFunc(zig_fn_ty).?;
5119 const return_type = fn_info.return_type.toType();
5119 const return_type = Type.fromInterned(fn_info.return_type);
51205120 const llvm_fn = try self.resolveInst(pl_op.operand);
51215121 const target = mod.getTarget();
51225122 const sret = firstParamSRet(fn_info, mod);
......@@ -5296,14 +5296,14 @@ pub const FuncGen = struct {
52965296 while (try it.next()) |lowering| switch (lowering) {
52975297 .byval => {
52985298 const param_index = it.zig_index - 1;
5299 const param_ty = fn_info.param_types.get(ip)[param_index].toType();
5299 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
53005300 if (!isByRef(param_ty, mod)) {
53015301 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
53025302 }
53035303 },
53045304 .byref => {
53055305 const param_index = it.zig_index - 1;
5306 const param_ty = fn_info.param_types.get(ip)[param_index].toType();
5306 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[param_index]);
53075307 const param_llvm_ty = try o.lowerType(param_ty);
53085308 const alignment = param_ty.abiAlignment(mod).toLlvm();
53095309 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);
......@@ -5321,7 +5321,7 @@ pub const FuncGen = struct {
53215321
53225322 .slice => {
53235323 assert(!it.byval_attr);
5324 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1].toType();
5324 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[it.zig_index - 1]);
53255325 const ptr_info = param_ty.ptrInfo(mod);
53265326 const llvm_arg_i = it.llvm_index - 2;
53275327
......@@ -5339,7 +5339,7 @@ pub const FuncGen = struct {
53395339 const elem_align = (if (ptr_info.flags.alignment != .none)
53405340 @as(InternPool.Alignment, ptr_info.flags.alignment)
53415341 else
5342 ptr_info.child.toType().abiAlignment(mod).max(.@"1")).toLlvm();
5342 Type.fromInterned(ptr_info.child).abiAlignment(mod).max(.@"1")).toLlvm();
53435343 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);
53445344 },
53455345 };
......@@ -5471,7 +5471,7 @@ pub const FuncGen = struct {
54715471 }
54725472 const fn_info = mod.typeToFunc(self.dg.decl.ty).?;
54735473 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
5474 if (fn_info.return_type.toType().isError(mod)) {
5474 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
54755475 // Functions with an empty error set are emitted with an error code
54765476 // return type and return zero so they can be function pointers coerced
54775477 // to functions that return anyerror.
......@@ -5513,7 +5513,7 @@ pub const FuncGen = struct {
55135513 const ret_ty = ptr_ty.childType(mod);
55145514 const fn_info = mod.typeToFunc(self.dg.decl.ty).?;
55155515 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
5516 if (fn_info.return_type.toType().isError(mod)) {
5516 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
55175517 // Functions with an empty error set are emitted with an error code
55185518 // return type and return zero so they can be function pointers coerced
55195519 // to functions that return anyerror.
......@@ -8866,7 +8866,7 @@ pub const FuncGen = struct {
88668866 const ptr = try fg.resolveInst(ty_op.operand);
88678867
88688868 elide: {
8869 if (!isByRef(ptr_info.child.toType(), mod)) break :elide;
8869 if (!isByRef(Type.fromInterned(ptr_info.child), mod)) break :elide;
88708870 if (!canElideLoad(fg, body_tail)) break :elide;
88718871 return ptr;
88728872 }
......@@ -9040,14 +9040,14 @@ pub const FuncGen = struct {
90409040 const ptr = try self.resolveInst(atomic_load.ptr);
90419041 const ptr_ty = self.typeOf(atomic_load.ptr);
90429042 const info = ptr_ty.ptrInfo(mod);
9043 const elem_ty = info.child.toType();
9043 const elem_ty = Type.fromInterned(info.child);
90449044 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;
90459045 const ordering = toLlvmAtomicOrdering(atomic_load.order);
90469046 const llvm_abi_ty = try o.getAtomicAbiType(elem_ty, false);
90479047 const ptr_alignment = (if (info.flags.alignment != .none)
90489048 @as(InternPool.Alignment, info.flags.alignment)
90499049 else
9050 info.child.toType().abiAlignment(mod)).toLlvm();
9050 Type.fromInterned(info.child).abiAlignment(mod)).toLlvm();
90519051 const access_kind: Builder.MemoryAccessKind =
90529052 if (info.flags.is_volatile) .@"volatile" else .normal;
90539053 const elem_llvm_ty = try o.lowerType(elem_ty);
......@@ -9500,7 +9500,7 @@ pub const FuncGen = struct {
95009500
95019501 const fqn = try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod);
95029502 const function_index = try o.builder.addFunction(
9503 try o.builder.fnType(.i1, &.{try o.lowerType(enum_type.tag_ty.toType())}, .normal),
9503 try o.builder.fnType(.i1, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
95049504 try o.builder.fmt("__zig_is_named_enum_value_{}", .{fqn.fmt(&mod.intern_pool)}),
95059505 toLlvmAddressSpace(.generic, mod.getTarget()),
95069506 );
......@@ -9573,7 +9573,7 @@ pub const FuncGen = struct {
95739573 const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0);
95749574 const fqn = try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod);
95759575 const function_index = try o.builder.addFunction(
9576 try o.builder.fnType(ret_ty, &.{try o.lowerType(enum_type.tag_ty.toType())}, .normal),
9576 try o.builder.fnType(ret_ty, &.{try o.lowerType(Type.fromInterned(enum_type.tag_ty))}, .normal),
95779577 try o.builder.fmt("__zig_tag_name_{}", .{fqn.fmt(ip)}),
95789578 toLlvmAddressSpace(.generic, mod.getTarget()),
95799579 );
......@@ -9692,7 +9692,7 @@ pub const FuncGen = struct {
96929692 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
96939693 const a = try self.resolveInst(extra.a);
96949694 const b = try self.resolveInst(extra.b);
9695 const mask = extra.mask.toValue();
9695 const mask = Value.fromInterned(extra.mask);
96969696 const mask_len = extra.mask_len;
96979697 const a_len = self.typeOf(extra.a).vectorLen(mod);
96989698
......@@ -9928,18 +9928,18 @@ pub const FuncGen = struct {
99289928 if (mod.typeToPackedStruct(result_ty)) |struct_type| {
99299929 const backing_int_ty = struct_type.backingIntType(ip).*;
99309930 assert(backing_int_ty != .none);
9931 const big_bits = backing_int_ty.toType().bitSize(mod);
9931 const big_bits = Type.fromInterned(backing_int_ty).bitSize(mod);
99329932 const int_ty = try o.builder.intType(@intCast(big_bits));
99339933 comptime assert(Type.packed_struct_layout_version == 2);
99349934 var running_int = try o.builder.intValue(int_ty, 0);
99359935 var running_bits: u16 = 0;
99369936 for (elements, struct_type.field_types.get(ip)) |elem, field_ty| {
9937 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;
9937 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
99389938
99399939 const non_int_val = try self.resolveInst(elem);
9940 const ty_bit_size: u16 = @intCast(field_ty.toType().bitSize(mod));
9940 const ty_bit_size: u16 = @intCast(Type.fromInterned(field_ty).bitSize(mod));
99419941 const small_int_ty = try o.builder.intType(ty_bit_size);
9942 const small_int_val = if (field_ty.toType().isPtrAtRuntime(mod))
9942 const small_int_val = if (Type.fromInterned(field_ty).isPtrAtRuntime(mod))
99439943 try self.wip.cast(.ptrtoint, non_int_val, small_int_ty, "")
99449944 else
99459945 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");
......@@ -10041,7 +10041,7 @@ pub const FuncGen = struct {
1004110041 if (union_obj.getLayout(ip) == .Packed) {
1004210042 const big_bits = union_ty.bitSize(mod);
1004310043 const int_llvm_ty = try o.builder.intType(@intCast(big_bits));
10044 const field_ty = union_obj.field_types.get(ip)[extra.field_index].toType();
10044 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
1004510045 const non_int_val = try self.resolveInst(extra.init);
1004610046 const small_int_ty = try o.builder.intType(@intCast(field_ty.bitSize(mod)));
1004710047 const small_int_val = if (field_ty.isPtrAtRuntime(mod))
......@@ -10074,7 +10074,7 @@ pub const FuncGen = struct {
1007410074 const alignment = layout.abi_align.toLlvm();
1007510075 const result_ptr = try self.buildAllocaWorkaround(union_ty, alignment);
1007610076 const llvm_payload = try self.resolveInst(extra.init);
10077 const field_ty = union_obj.field_types.get(ip)[extra.field_index].toType();
10077 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
1007810078 const field_llvm_ty = try o.lowerType(field_ty);
1007910079 const field_size = field_ty.abiSize(mod);
1008010080 const field_align = mod.unionFieldNormalAlignment(union_obj, extra.field_index);
......@@ -10097,7 +10097,7 @@ pub const FuncGen = struct {
1009710097 });
1009810098 };
1009910099 if (layout.tag_size == 0) break :t try o.builder.structType(.normal, &.{payload_ty});
10100 const tag_ty = try o.lowerType(union_obj.enum_tag_ty.toType());
10100 const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
1010110101 var fields: [3]Builder.Type = undefined;
1010210102 var fields_len: usize = 2;
1010310103 if (layout.tag_align.compare(.gte, layout.payload_align)) {
......@@ -10140,9 +10140,9 @@ pub const FuncGen = struct {
1014010140 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));
1014110141 const indices: [2]Builder.Value = .{ usize_zero, try o.builder.intValue(.i32, tag_index) };
1014210142 const field_ptr = try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, &indices, "");
10143 const tag_ty = try o.lowerType(union_obj.enum_tag_ty.toType());
10143 const tag_ty = try o.lowerType(Type.fromInterned(union_obj.enum_tag_ty));
1014410144 const llvm_tag = try o.builder.intValue(tag_ty, tag_int);
10145 const tag_alignment = union_obj.enum_tag_ty.toType().abiAlignment(mod).toLlvm();
10145 const tag_alignment = Type.fromInterned(union_obj.enum_tag_ty).abiAlignment(mod).toLlvm();
1014610146 _ = try self.wip.store(.normal, llvm_tag, field_ptr, tag_alignment);
1014710147 }
1014810148
......@@ -10514,7 +10514,7 @@ pub const FuncGen = struct {
1051410514 const o = self.dg.object;
1051510515 const mod = o.module;
1051610516 const info = ptr_ty.ptrInfo(mod);
10517 const elem_ty = info.child.toType();
10517 const elem_ty = Type.fromInterned(info.child);
1051810518 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;
1051910519
1052010520 const ptr_alignment = (if (info.flags.alignment != .none)
......@@ -10586,7 +10586,7 @@ pub const FuncGen = struct {
1058610586 const o = self.dg.object;
1058710587 const mod = o.module;
1058810588 const info = ptr_ty.ptrInfo(mod);
10589 const elem_ty = info.child.toType();
10589 const elem_ty = Type.fromInterned(info.child);
1059010590 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) {
1059110591 return;
1059210592 }
......@@ -10926,7 +10926,7 @@ fn toLlvmGlobalAddressSpace(wanted_address_space: std.builtin.AddressSpace, targ
1092610926}
1092710927
1092810928fn firstParamSRet(fn_info: InternPool.Key.FuncType, mod: *Module) bool {
10929 const return_type = fn_info.return_type.toType();
10929 const return_type = Type.fromInterned(fn_info.return_type);
1093010930 if (!return_type.hasRuntimeBitsIgnoreComptime(mod)) return false;
1093110931
1093210932 const target = mod.getTarget();
......@@ -10967,7 +10967,7 @@ fn firstParamSRetSystemV(ty: Type, mod: *Module) bool {
1096710967/// be effectively bitcasted to the actual return type.
1096810968fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
1096910969 const mod = o.module;
10970 const return_type = fn_info.return_type.toType();
10970 const return_type = Type.fromInterned(fn_info.return_type);
1097110971 if (!return_type.hasRuntimeBitsIgnoreComptime(mod)) {
1097210972 // If the return type is an error set or an error union, then we make this
1097310973 // anyerror return type instead, so that it can be coerced into a function
......@@ -11051,7 +11051,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
1105111051
1105211052fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
1105311053 const mod = o.module;
11054 const return_type = fn_info.return_type.toType();
11054 const return_type = Type.fromInterned(fn_info.return_type);
1105511055 switch (x86_64_abi.classifyWindows(return_type, mod)) {
1105611056 .integer => {
1105711057 if (isScalar(mod, return_type)) {
......@@ -11070,7 +11070,7 @@ fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Err
1107011070fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
1107111071 const mod = o.module;
1107211072 const ip = &mod.intern_pool;
11073 const return_type = fn_info.return_type.toType();
11073 const return_type = Type.fromInterned(fn_info.return_type);
1107411074 if (isScalar(mod, return_type)) {
1107511075 return o.lowerType(return_type);
1107611076 }
......@@ -11158,7 +11158,7 @@ const ParamTypeIterator = struct {
1115811158 const ip = &mod.intern_pool;
1115911159 const ty = it.fn_info.param_types.get(ip)[it.zig_index];
1116011160 it.byval_attr = false;
11161 return nextInner(it, ty.toType());
11161 return nextInner(it, Type.fromInterned(ty));
1116211162 }
1116311163
1116411164 /// `airCall` uses this instead of `next` so that it can take into account variadic functions.
......@@ -11172,7 +11172,7 @@ const ParamTypeIterator = struct {
1117211172 return nextInner(it, fg.typeOf(args[it.zig_index]));
1117311173 }
1117411174 } else {
11175 return nextInner(it, it.fn_info.param_types.get(ip)[it.zig_index].toType());
11175 return nextInner(it, Type.fromInterned(it.fn_info.param_types.get(ip)[it.zig_index]));
1117611176 }
1117711177 }
1117811178
......@@ -11503,11 +11503,11 @@ fn isByRef(ty: Type, mod: *Module) bool {
1150311503 .anon_struct_type => |tuple| {
1150411504 var count: usize = 0;
1150511505 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, field_val| {
11506 if (field_val != .none or !field_ty.toType().hasRuntimeBits(mod)) continue;
11506 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
1150711507
1150811508 count += 1;
1150911509 if (count > max_fields_byval) return true;
11510 if (isByRef(field_ty.toType(), mod)) return true;
11510 if (isByRef(Type.fromInterned(field_ty), mod)) return true;
1151111511 }
1151211512 return false;
1151311513 },
......@@ -11524,7 +11524,7 @@ fn isByRef(ty: Type, mod: *Module) bool {
1152411524 while (it.next()) |field_index| {
1152511525 count += 1;
1152611526 if (count > max_fields_byval) return true;
11527 const field_ty = field_types[field_index].toType();
11527 const field_ty = Type.fromInterned(field_types[field_index]);
1152811528 if (isByRef(field_ty, mod)) return true;
1152911529 }
1153011530 return false;
src/codegen/spirv.zig+47-47
......@@ -465,7 +465,7 @@ const DeclGen = struct {
465465 };
466466
467467 const mod = self.module;
468 const ty = mod.intern_pool.typeOf(val).toType();
468 const ty = Type.fromInterned(mod.intern_pool.typeOf(val));
469469 const ptr_ty_ref = try self.ptrType(ty, storage_class);
470470
471471 const var_id = self.spv.declPtr(spv_decl_index).result_id;
......@@ -515,7 +515,7 @@ const DeclGen = struct {
515515 });
516516 self.current_block_label = root_block_id;
517517
518 const val_id = try self.constant(ty, val.toValue(), .indirect);
518 const val_id = try self.constant(ty, Value.fromInterned(val), .indirect);
519519 try self.func.body.emit(self.spv.gpa, .OpStore, .{
520520 .pointer = var_id,
521521 .object = val_id,
......@@ -822,10 +822,10 @@ const DeclGen = struct {
822822 .payload => err_int_ty,
823823 };
824824 const err_val = switch (error_union.val) {
825 .err_name => |err_name| (try mod.intern(.{ .err = .{
825 .err_name => |err_name| Value.fromInterned((try mod.intern(.{ .err = .{
826826 .ty = ty.errorUnionSet(mod).toIntern(),
827827 .name = err_name,
828 } })).toValue(),
828 } }))),
829829 .payload => try mod.intValue(err_int_ty, 0),
830830 };
831831 const payload_ty = ty.errorUnionPayload(mod);
......@@ -835,10 +835,10 @@ const DeclGen = struct {
835835 return try self.constant(err_ty, err_val, .indirect);
836836 }
837837
838 const payload_val = switch (error_union.val) {
838 const payload_val = Value.fromInterned(switch (error_union.val) {
839839 .err_name => try mod.intern(.{ .undef = payload_ty.toIntern() }),
840840 .payload => |payload| payload,
841 }.toValue();
841 });
842842
843843 var constituents: [2]IdRef = undefined;
844844 var types: [2]Type = undefined;
......@@ -869,7 +869,7 @@ const DeclGen = struct {
869869 return ptr_id;
870870 }
871871
872 const len_id = try self.constant(Type.usize, ptr.len.toValue(), .indirect);
872 const len_id = try self.constant(Type.usize, Value.fromInterned(ptr.len), .indirect);
873873 return try self.constructStruct(
874874 ty,
875875 &.{ ptr_ty, Type.usize },
......@@ -909,7 +909,7 @@ const DeclGen = struct {
909909 },
910910 .aggregate => |aggregate| switch (ip.indexToKey(ty.ip_index)) {
911911 inline .array_type, .vector_type => |array_type, tag| {
912 const elem_ty = array_type.child.toType();
912 const elem_ty = Type.fromInterned(array_type.child);
913913 const elem_ty_ref = try self.resolveType(elem_ty, .indirect);
914914
915915 const constituents = try self.gpa.alloc(IdRef, @as(u32, @intCast(ty.arrayLenIncludingSentinel(mod))));
......@@ -925,11 +925,11 @@ const DeclGen = struct {
925925 },
926926 .elems => |elems| {
927927 for (0..@as(usize, @intCast(array_type.len))) |i| {
928 constituents[i] = try self.constant(elem_ty, elems[i].toValue(), .indirect);
928 constituents[i] = try self.constant(elem_ty, Value.fromInterned(elems[i]), .indirect);
929929 }
930930 },
931931 .repeated_elem => |elem| {
932 const val_id = try self.constant(elem_ty, elem.toValue(), .indirect);
932 const val_id = try self.constant(elem_ty, Value.fromInterned(elem), .indirect);
933933 for (0..@as(usize, @intCast(array_type.len))) |i| {
934934 constituents[i] = val_id;
935935 }
......@@ -938,7 +938,7 @@ const DeclGen = struct {
938938
939939 switch (tag) {
940940 inline .array_type => if (array_type.sentinel != .none) {
941 constituents[constituents.len - 1] = try self.constant(elem_ty, array_type.sentinel.toValue(), .indirect);
941 constituents[constituents.len - 1] = try self.constant(elem_ty, Value.fromInterned(array_type.sentinel), .indirect);
942942 },
943943 else => {},
944944 }
......@@ -959,7 +959,7 @@ const DeclGen = struct {
959959
960960 var it = struct_type.iterateRuntimeOrder(ip);
961961 while (it.next()) |field_index| {
962 const field_ty = struct_type.field_types.get(ip)[field_index].toType();
962 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
963963 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) {
964964 // This is a zero-bit field - we only needed it for the alignment.
965965 continue;
......@@ -979,11 +979,11 @@ const DeclGen = struct {
979979 else => unreachable,
980980 },
981981 .un => |un| {
982 const active_field = ty.unionTagFieldIndex(un.tag.toValue(), mod).?;
982 const active_field = ty.unionTagFieldIndex(Value.fromInterned(un.tag), mod).?;
983983 const union_obj = mod.typeToUnion(ty).?;
984 const field_ty = union_obj.field_types.get(ip)[active_field].toType();
984 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[active_field]);
985985 const payload = if (field_ty.hasRuntimeBitsIgnoreComptime(mod))
986 try self.constant(field_ty, un.val.toValue(), .direct)
986 try self.constant(field_ty, Value.fromInterned(un.val), .direct)
987987 else
988988 null;
989989 return try self.unionInit(ty, active_field, payload);
......@@ -1007,7 +1007,7 @@ const DeclGen = struct {
10071007 try self.func.body.emit(self.spv.gpa, .OpConvertUToPtr, .{
10081008 .id_result_type = self.typeId(result_ty_ref),
10091009 .id_result = ptr_id,
1010 .integer_value = try self.constant(Type.usize, int.toValue(), .direct),
1010 .integer_value = try self.constant(Type.usize, Value.fromInterned(int), .direct),
10111011 });
10121012 return ptr_id;
10131013 },
......@@ -1015,8 +1015,8 @@ const DeclGen = struct {
10151015 .opt_payload => unreachable, // TODO
10161016 .comptime_field => unreachable,
10171017 .elem => |elem_ptr| {
1018 const parent_ptr_ty = mod.intern_pool.typeOf(elem_ptr.base).toType();
1019 const parent_ptr_id = try self.constantPtr(parent_ptr_ty, elem_ptr.base.toValue());
1018 const parent_ptr_ty = Type.fromInterned(mod.intern_pool.typeOf(elem_ptr.base));
1019 const parent_ptr_id = try self.constantPtr(parent_ptr_ty, Value.fromInterned(elem_ptr.base));
10201020 const size_ty_ref = try self.sizeType();
10211021 const index_id = try self.constInt(size_ty_ref, elem_ptr.index);
10221022
......@@ -1040,8 +1040,8 @@ const DeclGen = struct {
10401040 return result_id;
10411041 },
10421042 .field => |field| {
1043 const base_ptr_ty = mod.intern_pool.typeOf(field.base).toType();
1044 const base_ptr = try self.constantPtr(base_ptr_ty, field.base.toValue());
1043 const base_ptr_ty = Type.fromInterned(mod.intern_pool.typeOf(field.base));
1044 const base_ptr = try self.constantPtr(base_ptr_ty, Value.fromInterned(field.base));
10451045 const field_index: u32 = @intCast(field.index);
10461046 return try self.structFieldPtr(ptr_ty, base_ptr_ty, base_ptr, field_index);
10471047 },
......@@ -1059,12 +1059,12 @@ const DeclGen = struct {
10591059 const ip = &mod.intern_pool;
10601060 const ty_ref = try self.resolveType(ty, .direct);
10611061 const decl_val = anon_decl.val;
1062 const decl_ty = ip.typeOf(decl_val).toType();
1062 const decl_ty = Type.fromInterned(ip.typeOf(decl_val));
10631063
1064 if (decl_val.toValue().getFunction(mod)) |func| {
1064 if (Value.fromInterned(decl_val).getFunction(mod)) |func| {
10651065 _ = func;
10661066 unreachable; // TODO
1067 } else if (decl_val.toValue().getExternFunc(mod)) |func| {
1067 } else if (Value.fromInterned(decl_val).getExternFunc(mod)) |func| {
10681068 _ = func;
10691069 unreachable;
10701070 }
......@@ -1267,7 +1267,7 @@ const DeclGen = struct {
12671267 const layout = self.unionLayout(ty);
12681268 if (!layout.has_payload) {
12691269 // No payload, so represent this as just the tag type.
1270 return try self.resolveType(union_obj.enum_tag_ty.toType(), .indirect);
1270 return try self.resolveType(Type.fromInterned(union_obj.enum_tag_ty), .indirect);
12711271 }
12721272
12731273 if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref;
......@@ -1278,7 +1278,7 @@ const DeclGen = struct {
12781278 const u8_ty_ref = try self.intType(.unsigned, 8); // TODO: What if Int8Type is not enabled?
12791279
12801280 if (layout.tag_size != 0) {
1281 const tag_ty_ref = try self.resolveType(union_obj.enum_tag_ty.toType(), .indirect);
1281 const tag_ty_ref = try self.resolveType(Type.fromInterned(union_obj.enum_tag_ty), .indirect);
12821282 member_types[layout.tag_index] = tag_ty_ref;
12831283 member_names[layout.tag_index] = try self.spv.resolveString("(tag)");
12841284 }
......@@ -1430,13 +1430,13 @@ const DeclGen = struct {
14301430 defer self.gpa.free(param_ty_refs);
14311431 var param_index: usize = 0;
14321432 for (fn_info.param_types.get(ip)) |param_ty_index| {
1433 const param_ty = param_ty_index.toType();
1433 const param_ty = Type.fromInterned(param_ty_index);
14341434 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
14351435
14361436 param_ty_refs[param_index] = try self.resolveType(param_ty, .direct);
14371437 param_index += 1;
14381438 }
1439 const return_ty_ref = try self.resolveFnReturnType(fn_info.return_type.toType());
1439 const return_ty_ref = try self.resolveFnReturnType(Type.fromInterned(fn_info.return_type));
14401440
14411441 const ty_ref = try self.spv.resolve(.{ .function_type = .{
14421442 .return_type = return_ty_ref,
......@@ -1459,7 +1459,7 @@ const DeclGen = struct {
14591459 // in ptrType()!
14601460
14611461 const storage_class = spvStorageClass(ptr_info.flags.address_space);
1462 const ptr_ty_ref = try self.ptrType(ptr_info.child.toType(), storage_class);
1462 const ptr_ty_ref = try self.ptrType(Type.fromInterned(ptr_info.child), storage_class);
14631463
14641464 if (ptr_info.flags.size != .Slice) {
14651465 return ptr_ty_ref;
......@@ -1494,9 +1494,9 @@ const DeclGen = struct {
14941494
14951495 var member_index: usize = 0;
14961496 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, field_val| {
1497 if (field_val != .none or !field_ty.toType().hasRuntimeBits(mod)) continue;
1497 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
14981498
1499 member_types[member_index] = try self.resolveType(field_ty.toType(), .indirect);
1499 member_types[member_index] = try self.resolveType(Type.fromInterned(field_ty), .indirect);
15001500 member_index += 1;
15011501 }
15021502
......@@ -1513,7 +1513,7 @@ const DeclGen = struct {
15131513 };
15141514
15151515 if (struct_type.layout == .Packed) {
1516 return try self.resolveType(struct_type.backingIntType(ip).toType(), .direct);
1516 return try self.resolveType(Type.fromInterned(struct_type.backingIntType(ip).*), .direct);
15171517 }
15181518
15191519 var member_types = std.ArrayList(CacheRef).init(self.gpa);
......@@ -1524,7 +1524,7 @@ const DeclGen = struct {
15241524
15251525 var it = struct_type.iterateRuntimeOrder(ip);
15261526 while (it.next()) |field_index| {
1527 const field_ty = struct_type.field_types.get(ip)[field_index].toType();
1527 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
15281528 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) {
15291529 // This is a zero-bit field - we only needed it for the alignment.
15301530 continue;
......@@ -1728,7 +1728,7 @@ const DeclGen = struct {
17281728
17291729 if (union_layout.has_payload) {
17301730 const most_aligned_field = layout.most_aligned_field;
1731 const most_aligned_field_ty = union_obj.field_types.get(ip)[most_aligned_field].toType();
1731 const most_aligned_field_ty = Type.fromInterned(union_obj.field_types.get(ip)[most_aligned_field]);
17321732 union_layout.payload_ty = most_aligned_field_ty;
17331733 union_layout.payload_size = @intCast(most_aligned_field_ty.abiSize(mod));
17341734 } else {
......@@ -1855,7 +1855,7 @@ const DeclGen = struct {
18551855 if (decl.val.getFunction(mod)) |_| {
18561856 assert(decl.ty.zigTypeTag(mod) == .Fn);
18571857 const fn_info = mod.typeToFunc(decl.ty).?;
1858 const return_ty_ref = try self.resolveFnReturnType(fn_info.return_type.toType());
1858 const return_ty_ref = try self.resolveFnReturnType(Type.fromInterned(fn_info.return_type));
18591859
18601860 const prototype_id = try self.resolveTypeId(decl.ty);
18611861 try self.func.prologue.emit(self.spv.gpa, .OpFunction, .{
......@@ -1867,7 +1867,7 @@ const DeclGen = struct {
18671867
18681868 try self.args.ensureUnusedCapacity(self.gpa, fn_info.param_types.len);
18691869 for (fn_info.param_types.get(ip)) |param_ty_index| {
1870 const param_ty = param_ty_index.toType();
1870 const param_ty = Type.fromInterned(param_ty_index);
18711871 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
18721872
18731873 const param_type_id = try self.resolveTypeId(param_ty);
......@@ -1914,7 +1914,7 @@ const DeclGen = struct {
19141914 }
19151915 } else {
19161916 const init_val = if (decl.val.getVariable(mod)) |payload|
1917 payload.init.toValue()
1917 Value.fromInterned(payload.init)
19181918 else
19191919 decl.val;
19201920
......@@ -2605,7 +2605,7 @@ const DeclGen = struct {
26052605 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
26062606 const a = try self.resolve(extra.a);
26072607 const b = try self.resolve(extra.b);
2608 const mask = extra.mask.toValue();
2608 const mask = Value.fromInterned(extra.mask);
26092609 const mask_len = extra.mask_len;
26102610 const a_len = self.typeOf(extra.a).vectorLen(mod);
26112611
......@@ -3239,11 +3239,11 @@ const DeclGen = struct {
32393239 .anon_struct_type => |tuple| {
32403240 for (tuple.types.get(ip), elements, 0..) |field_ty, element, i| {
32413241 if ((try result_ty.structFieldValueComptime(mod, i)) != null) continue;
3242 assert(field_ty.toType().hasRuntimeBits(mod));
3242 assert(Type.fromInterned(field_ty).hasRuntimeBits(mod));
32433243
32443244 const id = try self.resolve(element);
3245 types[index] = field_ty.toType();
3246 constituents[index] = try self.convertToIndirect(field_ty.toType(), id);
3245 types[index] = Type.fromInterned(field_ty);
3246 constituents[index] = try self.convertToIndirect(Type.fromInterned(field_ty), id);
32473247 index += 1;
32483248 }
32493249 },
......@@ -3252,7 +3252,7 @@ const DeclGen = struct {
32523252 for (elements, 0..) |element, i| {
32533253 const field_index = it.next().?;
32543254 if ((try result_ty.structFieldValueComptime(mod, i)) != null) continue;
3255 const field_ty = struct_type.field_types.get(ip)[field_index].toType();
3255 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
32563256 assert(field_ty.hasRuntimeBitsIgnoreComptime(mod));
32573257
32583258 const id = try self.resolve(element);
......@@ -3527,7 +3527,7 @@ const DeclGen = struct {
35273527 try self.store(maybe_tag_ty.?, ptr_id, tag_id, .{});
35283528 }
35293529
3530 const payload_ty = union_ty.field_types.get(ip)[active_field].toType();
3530 const payload_ty = Type.fromInterned(union_ty.field_types.get(ip)[active_field]);
35313531 if (payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
35323532 const pl_ptr_ty_ref = try self.ptrType(layout.payload_ty, .Function);
35333533 const pl_ptr_id = try self.accessChain(pl_ptr_ty_ref, tmp_id, &.{layout.payload_index});
......@@ -3560,7 +3560,7 @@ const DeclGen = struct {
35603560 const ty = self.typeOfIndex(inst);
35613561
35623562 const union_obj = mod.typeToUnion(ty).?;
3563 const field_ty = union_obj.field_types.get(ip)[extra.field_index].toType();
3563 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
35643564 const payload = if (field_ty.hasRuntimeBitsIgnoreComptime(mod))
35653565 try self.resolve(extra.init)
35663566 else
......@@ -4223,7 +4223,7 @@ const DeclGen = struct {
42234223 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
42244224 const decl = mod.declPtr(self.decl_index);
42254225 const fn_info = mod.typeToFunc(decl.ty).?;
4226 if (fn_info.return_type.toType().isError(mod)) {
4226 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
42274227 // Functions with an empty error set are emitted with an error code
42284228 // return type and return zero so they can be function pointers coerced
42294229 // to functions that return anyerror.
......@@ -4248,7 +4248,7 @@ const DeclGen = struct {
42484248 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
42494249 const decl = mod.declPtr(self.decl_index);
42504250 const fn_info = mod.typeToFunc(decl.ty).?;
4251 if (fn_info.return_type.toType().isError(mod)) {
4251 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
42524252 // Functions with an empty error set are emitted with an error code
42534253 // return type and return zero so they can be function pointers coerced
42544254 // to functions that return anyerror.
......@@ -4913,7 +4913,7 @@ const DeclGen = struct {
49134913 const fn_info = mod.typeToFunc(zig_fn_ty).?;
49144914 const return_type = fn_info.return_type;
49154915
4916 const result_type_ref = try self.resolveFnReturnType(return_type.toType());
4916 const result_type_ref = try self.resolveFnReturnType(Type.fromInterned(return_type));
49174917 const result_id = self.spv.allocId();
49184918 const callee_id = try self.resolve(pl_op.operand);
49194919
......@@ -4944,7 +4944,7 @@ const DeclGen = struct {
49444944 try self.func.body.emit(self.spv.gpa, .OpUnreachable, {});
49454945 }
49464946
4947 if (self.liveness.isUnused(inst) or !return_type.toType().hasRuntimeBitsIgnoreComptime(mod)) {
4947 if (self.liveness.isUnused(inst) or !Type.fromInterned(return_type).hasRuntimeBitsIgnoreComptime(mod)) {
49484948 return null;
49494949 }
49504950
src/link/C.zig+3-2
......@@ -13,6 +13,7 @@ const codegen = @import("../codegen/c.zig");
1313const link = @import("../link.zig");
1414const trace = @import("../tracy.zig").trace;
1515const Type = @import("../type.zig").Type;
16const Value = @import("../value.zig").Value;
1617const Air = @import("../Air.zig");
1718const Liveness = @import("../Liveness.zig");
1819
......@@ -254,8 +255,8 @@ fn updateAnonDecl(self: *C, module: *Module, i: usize) !void {
254255 }
255256
256257 const tv: @import("../TypedValue.zig") = .{
257 .ty = module.intern_pool.typeOf(anon_decl).toType(),
258 .val = anon_decl.toValue(),
258 .ty = Type.fromInterned(module.intern_pool.typeOf(anon_decl)),
259 .val = Value.fromInterned(anon_decl),
259260 };
260261 const c_value: codegen.CValue = .{ .constant = anon_decl };
261262 const alignment: Alignment = self.aligned_anon_decls.get(anon_decl) orelse .none;
src/link/Coff.zig+4-3
......@@ -1189,7 +1189,7 @@ pub fn updateDecl(
11891189 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
11901190 defer code_buffer.deinit();
11911191
1192 const decl_val = if (decl.val.getVariable(mod)) |variable| variable.init.toValue() else decl.val;
1192 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
11931193 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
11941194 .ty = decl.ty,
11951195 .val = decl_val,
......@@ -1794,7 +1794,7 @@ pub fn lowerAnonDecl(
17941794) !codegen.Result {
17951795 const gpa = self.base.allocator;
17961796 const mod = self.base.options.module.?;
1797 const ty = mod.intern_pool.typeOf(decl_val).toType();
1797 const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val));
17981798 const decl_alignment = switch (explicit_alignment) {
17991799 .none => ty.abiAlignment(mod),
18001800 else => explicit_alignment,
......@@ -1805,7 +1805,7 @@ pub fn lowerAnonDecl(
18051805 return .ok;
18061806 }
18071807
1808 const val = decl_val.toValue();
1808 const val = Value.fromInterned(decl_val);
18091809 const tv = TypedValue{ .ty = ty, .val = val };
18101810 var name_buf: [32]u8 = undefined;
18111811 const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{
......@@ -2669,6 +2669,7 @@ const Relocation = @import("Coff/Relocation.zig");
26692669const TableSection = @import("table_section.zig").TableSection;
26702670const StringTable = @import("StringTable.zig");
26712671const Type = @import("../type.zig").Type;
2672const Value = @import("../value.zig").Value;
26722673const TypedValue = @import("../TypedValue.zig");
26732674
26742675pub const base_tag: link.File.Tag = .coff;
src/link/Dwarf.zig+9-9
......@@ -305,7 +305,7 @@ pub const DeclState = struct {
305305 // DW.AT.type, DW.FORM.ref4
306306 const index = dbg_info_buffer.items.len;
307307 try dbg_info_buffer.resize(index + 4);
308 try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index));
308 try self.addTypeRelocGlobal(atom_index, Type.fromInterned(field_ty), @intCast(index));
309309 // DW.AT.data_member_location, DW.FORM.udata
310310 const field_off = ty.structFieldOffset(field_index, mod);
311311 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);
......@@ -323,7 +323,7 @@ pub const DeclState = struct {
323323
324324 if (struct_type.isTuple(ip)) {
325325 for (struct_type.field_types.get(ip), struct_type.offsets.get(ip), 0..) |field_ty, field_off, field_index| {
326 if (!field_ty.toType().hasRuntimeBits(mod)) continue;
326 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
327327 // DW.AT.member
328328 try dbg_info_buffer.append(@intFromEnum(AbbrevKind.struct_member));
329329 // DW.AT.name, DW.FORM.string
......@@ -331,7 +331,7 @@ pub const DeclState = struct {
331331 // DW.AT.type, DW.FORM.ref4
332332 const index = dbg_info_buffer.items.len;
333333 try dbg_info_buffer.resize(index + 4);
334 try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index));
334 try self.addTypeRelocGlobal(atom_index, Type.fromInterned(field_ty), @intCast(index));
335335 // DW.AT.data_member_location, DW.FORM.udata
336336 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);
337337 }
......@@ -341,7 +341,7 @@ pub const DeclState = struct {
341341 struct_type.field_types.get(ip),
342342 struct_type.offsets.get(ip),
343343 ) |field_name_ip, field_ty, field_off| {
344 if (!field_ty.toType().hasRuntimeBits(mod)) continue;
344 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
345345 const field_name = ip.stringToSlice(field_name_ip);
346346 // DW.AT.member
347347 try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2);
......@@ -352,7 +352,7 @@ pub const DeclState = struct {
352352 // DW.AT.type, DW.FORM.ref4
353353 const index = dbg_info_buffer.items.len;
354354 try dbg_info_buffer.resize(index + 4);
355 try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index));
355 try self.addTypeRelocGlobal(atom_index, Type.fromInterned(field_ty), @intCast(index));
356356 // DW.AT.data_member_location, DW.FORM.udata
357357 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);
358358 }
......@@ -389,7 +389,7 @@ pub const DeclState = struct {
389389 const value = enum_type.values.get(ip)[field_i];
390390 // TODO do not assume a 64bit enum value - could be bigger.
391391 // See https://github.com/ziglang/zig/issues/645
392 const field_int_val = try value.toValue().intFromEnum(ty, mod);
392 const field_int_val = try Value.fromInterned(value).intFromEnum(ty, mod);
393393 break :value @bitCast(field_int_val.toSignedInt(mod));
394394 };
395395 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), value, target_endian);
......@@ -443,7 +443,7 @@ pub const DeclState = struct {
443443 }
444444
445445 for (union_obj.field_types.get(ip), union_obj.field_names.get(ip)) |field_ty, field_name| {
446 if (!field_ty.toType().hasRuntimeBits(mod)) continue;
446 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
447447 // DW.AT.member
448448 try dbg_info_buffer.append(@intFromEnum(AbbrevKind.struct_member));
449449 // DW.AT.name, DW.FORM.string
......@@ -452,7 +452,7 @@ pub const DeclState = struct {
452452 // DW.AT.type, DW.FORM.ref4
453453 const index = dbg_info_buffer.items.len;
454454 try dbg_info_buffer.resize(index + 4);
455 try self.addTypeRelocGlobal(atom_index, field_ty.toType(), @intCast(index));
455 try self.addTypeRelocGlobal(atom_index, Type.fromInterned(field_ty), @intCast(index));
456456 // DW.AT.data_member_location, DW.FORM.udata
457457 try dbg_info_buffer.append(0);
458458 }
......@@ -469,7 +469,7 @@ pub const DeclState = struct {
469469 // DW.AT.type, DW.FORM.ref4
470470 const index = dbg_info_buffer.items.len;
471471 try dbg_info_buffer.resize(index + 4);
472 try self.addTypeRelocGlobal(atom_index, union_obj.enum_tag_ty.toType(), @intCast(index));
472 try self.addTypeRelocGlobal(atom_index, Type.fromInterned(union_obj.enum_tag_ty), @intCast(index));
473473 // DW.AT.data_member_location, DW.FORM.udata
474474 try leb128.writeULEB128(dbg_info_buffer.writer(), tag_offset);
475475
src/link/Elf/ZigObject.zig+6-4
......@@ -660,7 +660,7 @@ pub fn lowerAnonDecl(
660660) !codegen.Result {
661661 const gpa = elf_file.base.allocator;
662662 const mod = elf_file.base.options.module.?;
663 const ty = mod.intern_pool.typeOf(decl_val).toType();
663 const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val));
664664 const decl_alignment = switch (explicit_alignment) {
665665 .none => ty.abiAlignment(mod),
666666 else => explicit_alignment,
......@@ -671,7 +671,7 @@ pub fn lowerAnonDecl(
671671 return .ok;
672672 }
673673
674 const val = decl_val.toValue();
674 const val = Value.fromInterned(decl_val);
675675 const tv = TypedValue{ .ty = ty, .val = val };
676676 var name_buf: [32]u8 = undefined;
677677 const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{
......@@ -835,7 +835,7 @@ fn getDeclShdrIndex(
835835 });
836836 }
837837 if (variable.is_const) break :blk elf_file.zig_data_rel_ro_section_index.?;
838 if (variable.init.toValue().isUndefDeep(mod)) {
838 if (Value.fromInterned(variable.init).isUndefDeep(mod)) {
839839 const mode = elf_file.base.options.optimize_mode;
840840 if (mode == .Debug or mode == .ReleaseSafe) break :blk elf_file.zig_data_section_index.?;
841841 break :blk elf_file.zig_bss_section_index.?;
......@@ -1114,7 +1114,7 @@ pub fn updateDecl(
11141114 defer if (decl_state) |*ds| ds.deinit();
11151115
11161116 // TODO implement .debug_info for global variables
1117 const decl_val = if (decl.val.getVariable(mod)) |variable| variable.init.toValue() else decl.val;
1117 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
11181118 const res = if (decl_state) |*ds|
11191119 try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{
11201120 .ty = decl.ty,
......@@ -1613,5 +1613,7 @@ const Module = @import("../../Module.zig");
16131613const Object = @import("Object.zig");
16141614const Symbol = @import("Symbol.zig");
16151615const StringTable = @import("../StringTable.zig");
1616const Type = @import("../../type.zig").Type;
1617const Value = @import("../../value.zig").Value;
16161618const TypedValue = @import("../../TypedValue.zig");
16171619const ZigObject = @This();
src/link/MachO.zig+4-4
......@@ -2400,7 +2400,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo
24002400 null;
24012401 defer if (decl_state) |*ds| ds.deinit();
24022402
2403 const decl_val = if (decl.val.getVariable(mod)) |variable| variable.init.toValue() else decl.val;
2403 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
24042404 const res = if (decl_state) |*ds|
24052405 try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
24062406 .ty = decl.ty,
......@@ -2569,7 +2569,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D
25692569
25702570 const decl = module.declPtr(decl_index);
25712571 const decl_metadata = self.decls.get(decl_index).?;
2572 const decl_val = decl.val.getVariable(mod).?.init.toValue();
2572 const decl_val = Value.fromInterned(decl.val.getVariable(mod).?.init);
25732573 const res = if (decl_state) |*ds|
25742574 try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
25752575 .ty = decl.ty,
......@@ -2995,7 +2995,7 @@ pub fn lowerAnonDecl(
29952995) !codegen.Result {
29962996 const gpa = self.base.allocator;
29972997 const mod = self.base.options.module.?;
2998 const ty = mod.intern_pool.typeOf(decl_val).toType();
2998 const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val));
29992999 const decl_alignment = switch (explicit_alignment) {
30003000 .none => ty.abiAlignment(mod),
30013001 else => explicit_alignment,
......@@ -3006,7 +3006,7 @@ pub fn lowerAnonDecl(
30063006 return .ok;
30073007 }
30083008
3009 const val = decl_val.toValue();
3009 const val = Value.fromInterned(decl_val);
30103010 const tv = TypedValue{ .ty = ty, .val = val };
30113011 var name_buf: [32]u8 = undefined;
30123012 const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{
src/link/Plan9.zig+5-3
......@@ -13,6 +13,8 @@ const File = link.File;
1313const build_options = @import("build_options");
1414const Air = @import("../Air.zig");
1515const Liveness = @import("../Liveness.zig");
16const Type = @import("../type.zig").Type;
17const Value = @import("../value.zig").Value;
1618const TypedValue = @import("../TypedValue.zig");
1719
1820const std = @import("std");
......@@ -517,7 +519,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !vo
517519
518520 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
519521 defer code_buffer.deinit();
520 const decl_val = if (decl.val.getVariable(mod)) |variable| variable.init.toValue() else decl.val;
522 const decl_val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
521523 // TODO we need the symbol index for symbol in the table of locals for the containing atom
522524 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
523525 .ty = decl.ty,
......@@ -1492,8 +1494,8 @@ pub fn lowerAnonDecl(self: *Plan9, decl_val: InternPool.Index, src_loc: Module.S
14921494 const gop = try self.anon_decls.getOrPut(gpa, decl_val);
14931495 const mod = self.base.options.module.?;
14941496 if (!gop.found_existing) {
1495 const ty = mod.intern_pool.typeOf(decl_val).toType();
1496 const val = decl_val.toValue();
1497 const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val));
1498 const val = Value.fromInterned(decl_val);
14971499 const tv = TypedValue{ .ty = ty, .val = val };
14981500 const name = try std.fmt.allocPrint(gpa, "__anon_{d}", .{@intFromEnum(decl_val)});
14991501
src/link/Wasm.zig+7-6
......@@ -23,6 +23,7 @@ const build_options = @import("build_options");
2323const wasi_libc = @import("../wasi_libc.zig");
2424const Cache = std.Build.Cache;
2525const Type = @import("../type.zig").Type;
26const Value = @import("../value.zig").Value;
2627const TypedValue = @import("../TypedValue.zig");
2728const LlvmObject = @import("../codegen/llvm.zig").Object;
2829const Air = @import("../Air.zig");
......@@ -1452,7 +1453,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi
14521453 const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name);
14531454 return wasm.addOrUpdateImport(name, atom.sym_index, lib_name, null);
14541455 }
1455 const val = if (decl.val.getVariable(mod)) |variable| variable.init.toValue() else decl.val;
1456 const val = if (decl.val.getVariable(mod)) |variable| Value.fromInterned(variable.init) else decl.val;
14561457
14571458 var code_writer = std.ArrayList(u8).init(wasm.base.allocator);
14581459 defer code_writer.deinit();
......@@ -1719,8 +1720,8 @@ pub fn lowerAnonDecl(
17191720 const gop = try wasm.anon_decls.getOrPut(wasm.base.allocator, decl_val);
17201721 if (!gop.found_existing) {
17211722 const mod = wasm.base.options.module.?;
1722 const ty = mod.intern_pool.typeOf(decl_val).toType();
1723 const tv: TypedValue = .{ .ty = ty, .val = decl_val.toValue() };
1723 const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val));
1724 const tv: TypedValue = .{ .ty = ty, .val = Value.fromInterned(decl_val) };
17241725 var name_buf: [32]u8 = undefined;
17251726 const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{
17261727 @intFromEnum(decl_val),
......@@ -1751,7 +1752,7 @@ pub fn getAnonDeclVAddr(wasm: *Wasm, decl_val: InternPool.Index, reloc_info: lin
17511752 const parent_atom = wasm.getAtomPtr(parent_atom_index);
17521753 const is_wasm32 = wasm.base.options.target.cpu.arch == .wasm32;
17531754 const mod = wasm.base.options.module.?;
1754 const ty = mod.intern_pool.typeOf(decl_val).toType();
1755 const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val));
17551756 if (ty.zigTypeTag(mod) == .Fn) {
17561757 assert(reloc_info.addend == 0); // addend not allowed for function relocations
17571758 // We found a function pointer, so add it to our table,
......@@ -3533,7 +3534,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
35333534 } else if (decl.getOwnedVariable(mod)) |variable| {
35343535 if (variable.is_const) {
35353536 try wasm.parseAtom(atom_index, .{ .data = .read_only });
3536 } else if (variable.init.toValue().isUndefDeep(mod)) {
3537 } else if (Value.fromInterned(variable.init).isUndefDeep(mod)) {
35373538 // for safe build modes, we store the atom in the data segment,
35383539 // whereas for unsafe build modes we store it in bss.
35393540 const is_initialized = wasm.base.options.optimize_mode == .Debug or
......@@ -3558,7 +3559,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
35583559 }
35593560 // parse anonymous declarations
35603561 for (wasm.anon_decls.keys(), wasm.anon_decls.values()) |decl_val, atom_index| {
3561 const ty = mod.intern_pool.typeOf(decl_val).toType();
3562 const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val));
35623563 if (ty.zigTypeTag(mod) == .Fn) {
35633564 try wasm.parseAtom(atom_index, .function);
35643565 } else {
src/print_air.zig+2-2
......@@ -940,10 +940,10 @@ const Writer = struct {
940940 return s.print("@{}", .{operand});
941941 } else if (Air.refToInterned(operand)) |ip_index| {
942942 const mod = w.module;
943 const ty = mod.intern_pool.indexToKey(ip_index).typeOf().toType();
943 const ty = Type.fromInterned(mod.intern_pool.indexToKey(ip_index).typeOf());
944944 try s.print("<{}, {}>", .{
945945 ty.fmt(mod),
946 ip_index.toValue().fmtValue(ty, mod),
946 Value.fromInterned(ip_index).fmtValue(ty, mod),
947947 });
948948 } else {
949949 return w.writeInstIndex(s, Air.refToIndex(operand).?, dies);
src/type.zig+163-158
......@@ -185,8 +185,8 @@ pub const Type = struct {
185185
186186 if (info.sentinel != .none) switch (info.flags.size) {
187187 .One, .C => unreachable,
188 .Many => try writer.print("[*:{}]", .{info.sentinel.toValue().fmtValue(info.child.toType(), mod)}),
189 .Slice => try writer.print("[:{}]", .{info.sentinel.toValue().fmtValue(info.child.toType(), mod)}),
188 .Many => try writer.print("[*:{}]", .{Value.fromInterned(info.sentinel).fmtValue(Type.fromInterned(info.child), mod)}),
189 .Slice => try writer.print("[:{}]", .{Value.fromInterned(info.sentinel).fmtValue(Type.fromInterned(info.child), mod)}),
190190 } else switch (info.flags.size) {
191191 .One => try writer.writeAll("*"),
192192 .Many => try writer.writeAll("[*]"),
......@@ -200,7 +200,7 @@ pub const Type = struct {
200200 const alignment = if (info.flags.alignment != .none)
201201 info.flags.alignment
202202 else
203 info.child.toType().abiAlignment(mod);
203 Type.fromInterned(info.child).abiAlignment(mod);
204204 try writer.print("align({d}", .{alignment.toByteUnits(0)});
205205
206206 if (info.packed_offset.bit_offset != 0 or info.packed_offset.host_size != 0) {
......@@ -222,36 +222,36 @@ pub const Type = struct {
222222 if (info.flags.is_volatile) try writer.writeAll("volatile ");
223223 if (info.flags.is_allowzero and info.flags.size != .C) try writer.writeAll("allowzero ");
224224
225 try print(info.child.toType(), writer, mod);
225 try print(Type.fromInterned(info.child), writer, mod);
226226 return;
227227 },
228228 .array_type => |array_type| {
229229 if (array_type.sentinel == .none) {
230230 try writer.print("[{d}]", .{array_type.len});
231 try print(array_type.child.toType(), writer, mod);
231 try print(Type.fromInterned(array_type.child), writer, mod);
232232 } else {
233233 try writer.print("[{d}:{}]", .{
234234 array_type.len,
235 array_type.sentinel.toValue().fmtValue(array_type.child.toType(), mod),
235 Value.fromInterned(array_type.sentinel).fmtValue(Type.fromInterned(array_type.child), mod),
236236 });
237 try print(array_type.child.toType(), writer, mod);
237 try print(Type.fromInterned(array_type.child), writer, mod);
238238 }
239239 return;
240240 },
241241 .vector_type => |vector_type| {
242242 try writer.print("@Vector({d}, ", .{vector_type.len});
243 try print(vector_type.child.toType(), writer, mod);
243 try print(Type.fromInterned(vector_type.child), writer, mod);
244244 try writer.writeAll(")");
245245 return;
246246 },
247247 .opt_type => |child| {
248248 try writer.writeByte('?');
249 return print(child.toType(), writer, mod);
249 return print(Type.fromInterned(child), writer, mod);
250250 },
251251 .error_union_type => |error_union_type| {
252 try print(error_union_type.error_set_type.toType(), writer, mod);
252 try print(Type.fromInterned(error_union_type.error_set_type), writer, mod);
253253 try writer.writeByte('!');
254 try print(error_union_type.payload_type.toType(), writer, mod);
254 try print(Type.fromInterned(error_union_type.payload_type), writer, mod);
255255 return;
256256 },
257257 .inferred_error_set_type => |func_index| {
......@@ -342,10 +342,10 @@ pub const Type = struct {
342342 try writer.print("{}: ", .{anon_struct.names.get(ip)[i].fmt(&mod.intern_pool)});
343343 }
344344
345 try print(field_ty.toType(), writer, mod);
345 try print(Type.fromInterned(field_ty), writer, mod);
346346
347347 if (val != .none) {
348 try writer.print(" = {}", .{val.toValue().fmtValue(field_ty.toType(), mod)});
348 try writer.print(" = {}", .{Value.fromInterned(val).fmtValue(Type.fromInterned(field_ty), mod)});
349349 }
350350 }
351351 try writer.writeAll("}");
......@@ -382,7 +382,7 @@ pub const Type = struct {
382382 if (param_ty == .generic_poison_type) {
383383 try writer.writeAll("anytype");
384384 } else {
385 try print(param_ty.toType(), writer, mod);
385 try print(Type.fromInterned(param_ty), writer, mod);
386386 }
387387 }
388388 if (fn_info.is_var_args) {
......@@ -403,13 +403,13 @@ pub const Type = struct {
403403 if (fn_info.return_type == .generic_poison_type) {
404404 try writer.writeAll("anytype");
405405 } else {
406 try print(fn_info.return_type.toType(), writer, mod);
406 try print(Type.fromInterned(fn_info.return_type), writer, mod);
407407 }
408408 },
409409 .anyframe_type => |child| {
410410 if (child == .none) return writer.writeAll("anyframe");
411411 try writer.writeAll("anyframe->");
412 return print(child.toType(), writer, mod);
412 return print(Type.fromInterned(child), writer, mod);
413413 },
414414
415415 // values, not types
......@@ -435,13 +435,18 @@ pub const Type = struct {
435435 }
436436 }
437437
438 pub fn fromInterned(i: InternPool.Index) Type {
439 assert(i != .none);
440 return .{ .ip_index = i };
441 }
442
438443 pub fn toIntern(ty: Type) InternPool.Index {
439444 assert(ty.ip_index != .none);
440445 return ty.ip_index;
441446 }
442447
443448 pub fn toValue(self: Type) Value {
444 return self.toIntern().toValue();
449 return Value.fromInterned(self.toIntern());
445450 }
446451
447452 const RuntimeBitsError = Module.CompileError || error{NeedLazy};
......@@ -482,18 +487,18 @@ pub const Type = struct {
482487 .anyframe_type => true,
483488 .array_type => |array_type| {
484489 if (array_type.sentinel != .none) {
485 return array_type.child.toType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
490 return Type.fromInterned(array_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
486491 } else {
487492 return array_type.len > 0 and
488 try array_type.child.toType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
493 try Type.fromInterned(array_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
489494 }
490495 },
491496 .vector_type => |vector_type| {
492497 return vector_type.len > 0 and
493 try vector_type.child.toType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
498 try Type.fromInterned(vector_type.child).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
494499 },
495500 .opt_type => |child| {
496 const child_ty = child.toType();
501 const child_ty = Type.fromInterned(child);
497502 if (child_ty.isNoReturn(mod)) {
498503 // Then the optional is comptime-known to be null.
499504 return false;
......@@ -577,7 +582,7 @@ pub const Type = struct {
577582 }
578583 for (0..struct_type.field_types.len) |i| {
579584 if (struct_type.comptime_bits.getBit(ip, i)) continue;
580 const field_ty = struct_type.field_types.get(ip)[i].toType();
585 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
581586 if (try field_ty.hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat))
582587 return true;
583588 } else {
......@@ -587,7 +592,7 @@ pub const Type = struct {
587592 .anon_struct_type => |tuple| {
588593 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {
589594 if (val != .none) continue; // comptime field
590 if (try field_ty.toType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat)) return true;
595 if (try Type.fromInterned(field_ty).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat)) return true;
591596 }
592597 return false;
593598 },
......@@ -607,7 +612,7 @@ pub const Type = struct {
607612 // tag_ty will be `none` if this union's tag type is not resolved yet,
608613 // in which case we want control flow to continue down below.
609614 if (tag_ty != .none and
610 try tag_ty.toType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat))
615 try Type.fromInterned(tag_ty).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat))
611616 {
612617 return true;
613618 }
......@@ -621,7 +626,7 @@ pub const Type = struct {
621626 }
622627 const union_obj = ip.loadUnionType(union_type);
623628 for (0..union_obj.field_types.len) |field_index| {
624 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
629 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
625630 if (try field_ty.hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat))
626631 return true;
627632 } else {
......@@ -630,7 +635,7 @@ pub const Type = struct {
630635 },
631636
632637 .opaque_type => true,
633 .enum_type => |enum_type| enum_type.tag_ty.toType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat),
638 .enum_type => |enum_type| Type.fromInterned(enum_type.tag_ty).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat),
634639
635640 // values, not types
636641 .undef,
......@@ -676,7 +681,7 @@ pub const Type = struct {
676681 .func_type,
677682 => false,
678683
679 .array_type => |array_type| array_type.child.toType().hasWellDefinedLayout(mod),
684 .array_type => |array_type| Type.fromInterned(array_type.child).hasWellDefinedLayout(mod),
680685 .opt_type => ty.isPtrLikeOptional(mod),
681686 .ptr_type => |ptr_type| ptr_type.flags.size != .Slice,
682687
......@@ -783,7 +788,7 @@ pub const Type = struct {
783788 if (fn_info.is_generic) return false;
784789 if (fn_info.is_var_args) return true;
785790 if (fn_info.cc == .Inline) return false;
786 return !try fn_info.return_type.toType().comptimeOnlyAdvanced(mod, opt_sema);
791 return !try Type.fromInterned(fn_info.return_type).comptimeOnlyAdvanced(mod, opt_sema);
787792 }
788793
789794 pub fn isFnOrHasRuntimeBits(ty: Type, mod: *Module) bool {
......@@ -817,13 +822,13 @@ pub const Type = struct {
817822 return ptr_type.flags.alignment;
818823
819824 if (opt_sema) |sema| {
820 const res = try ptr_type.child.toType().abiAlignmentAdvanced(mod, .{ .sema = sema });
825 const res = try Type.fromInterned(ptr_type.child).abiAlignmentAdvanced(mod, .{ .sema = sema });
821826 return res.scalar;
822827 }
823828
824 return (ptr_type.child.toType().abiAlignmentAdvanced(mod, .eager) catch unreachable).scalar;
829 return (Type.fromInterned(ptr_type.child).abiAlignmentAdvanced(mod, .eager) catch unreachable).scalar;
825830 },
826 .opt_type => |child| child.toType().ptrAlignmentAdvanced(mod, opt_sema),
831 .opt_type => |child| Type.fromInterned(child).ptrAlignmentAdvanced(mod, opt_sema),
827832 else => unreachable,
828833 };
829834 }
......@@ -891,10 +896,10 @@ pub const Type = struct {
891896 return .{ .scalar = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8)) };
892897 },
893898 .array_type => |array_type| {
894 return array_type.child.toType().abiAlignmentAdvanced(mod, strat);
899 return Type.fromInterned(array_type.child).abiAlignmentAdvanced(mod, strat);
895900 },
896901 .vector_type => |vector_type| {
897 const bits_u64 = try bitSizeAdvanced(vector_type.child.toType(), mod, opt_sema);
902 const bits_u64 = try bitSizeAdvanced(Type.fromInterned(vector_type.child), mod, opt_sema);
898903 const bits: u32 = @intCast(bits_u64);
899904 const bytes = ((bits * vector_type.len) + 7) / 8;
900905 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);
......@@ -902,7 +907,7 @@ pub const Type = struct {
902907 },
903908
904909 .opt_type => return abiAlignmentAdvancedOptional(ty, mod, strat),
905 .error_union_type => |info| return abiAlignmentAdvancedErrorUnion(ty, mod, strat, info.payload_type.toType()),
910 .error_union_type => |info| return abiAlignmentAdvancedErrorUnion(ty, mod, strat, Type.fromInterned(info.payload_type)),
906911
907912 .error_set_type, .inferred_error_set_type => {
908913 const bits = mod.errorSetBits();
......@@ -992,14 +997,14 @@ pub const Type = struct {
992997 switch (strat) {
993998 .sema => |sema| try sema.resolveTypeLayout(ty),
994999 .lazy => if (struct_type.backingIntType(ip).* == .none) return .{
995 .val = (try mod.intern(.{ .int = .{
1000 .val = Value.fromInterned((try mod.intern(.{ .int = .{
9961001 .ty = .comptime_int_type,
9971002 .storage = .{ .lazy_align = ty.toIntern() },
998 } })).toValue(),
1003 } }))),
9991004 },
10001005 .eager => {},
10011006 }
1002 return .{ .scalar = struct_type.backingIntType(ip).toType().abiAlignment(mod) };
1007 return .{ .scalar = Type.fromInterned(struct_type.backingIntType(ip).*).abiAlignment(mod) };
10031008 }
10041009
10051010 const flags = struct_type.flagsPtr(ip).*;
......@@ -1010,25 +1015,25 @@ pub const Type = struct {
10101015 .sema => |sema| .{
10111016 .scalar = try sema.resolveStructAlignment(ty.toIntern(), struct_type),
10121017 },
1013 .lazy => .{ .val = (try mod.intern(.{ .int = .{
1018 .lazy => .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
10141019 .ty = .comptime_int_type,
10151020 .storage = .{ .lazy_align = ty.toIntern() },
1016 } })).toValue() },
1021 } }))) },
10171022 };
10181023 },
10191024 .anon_struct_type => |tuple| {
10201025 var big_align: Alignment = .@"1";
10211026 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {
10221027 if (val != .none) continue; // comptime field
1023 switch (try field_ty.toType().abiAlignmentAdvanced(mod, strat)) {
1028 switch (try Type.fromInterned(field_ty).abiAlignmentAdvanced(mod, strat)) {
10241029 .scalar => |field_align| big_align = big_align.max(field_align),
10251030 .val => switch (strat) {
10261031 .eager => unreachable, // field type alignment not resolved
10271032 .sema => unreachable, // passed to abiAlignmentAdvanced above
1028 .lazy => return .{ .val = (try mod.intern(.{ .int = .{
1033 .lazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
10291034 .ty = .comptime_int_type,
10301035 .storage = .{ .lazy_align = ty.toIntern() },
1031 } })).toValue() },
1036 } }))) },
10321037 },
10331038 }
10341039 }
......@@ -1041,17 +1046,17 @@ pub const Type = struct {
10411046 if (!union_type.haveLayout(ip)) switch (strat) {
10421047 .eager => unreachable, // union layout not resolved
10431048 .sema => |sema| return .{ .scalar = try sema.resolveUnionAlignment(ty, union_type) },
1044 .lazy => return .{ .val = (try mod.intern(.{ .int = .{
1049 .lazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
10451050 .ty = .comptime_int_type,
10461051 .storage = .{ .lazy_align = ty.toIntern() },
1047 } })).toValue() },
1052 } }))) },
10481053 };
10491054
10501055 return .{ .scalar = union_type.flagsPtr(ip).alignment };
10511056 },
10521057 .opaque_type => return .{ .scalar = .@"1" },
10531058 .enum_type => |enum_type| return .{
1054 .scalar = enum_type.tag_ty.toType().abiAlignment(mod),
1059 .scalar = Type.fromInterned(enum_type.tag_ty).abiAlignment(mod),
10551060 },
10561061
10571062 // values, not types
......@@ -1090,10 +1095,10 @@ pub const Type = struct {
10901095 switch (strat) {
10911096 .eager, .sema => {
10921097 if (!(payload_ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) {
1093 error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{
1098 error.NeedLazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
10941099 .ty = .comptime_int_type,
10951100 .storage = .{ .lazy_align = ty.toIntern() },
1096 } })).toValue() },
1101 } }))) },
10971102 else => |e| return e,
10981103 })) {
10991104 return .{ .scalar = code_align };
......@@ -1107,10 +1112,10 @@ pub const Type = struct {
11071112 .scalar => |payload_align| return .{ .scalar = code_align.max(payload_align) },
11081113 .val => {},
11091114 }
1110 return .{ .val = (try mod.intern(.{ .int = .{
1115 return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
11111116 .ty = .comptime_int_type,
11121117 .storage = .{ .lazy_align = ty.toIntern() },
1113 } })).toValue() };
1118 } }))) };
11141119 },
11151120 }
11161121 }
......@@ -1135,10 +1140,10 @@ pub const Type = struct {
11351140 switch (strat) {
11361141 .eager, .sema => {
11371142 if (!(child_type.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) {
1138 error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{
1143 error.NeedLazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
11391144 .ty = .comptime_int_type,
11401145 .storage = .{ .lazy_align = ty.toIntern() },
1141 } })).toValue() },
1146 } }))) },
11421147 else => |e| return e,
11431148 })) {
11441149 return .{ .scalar = .@"1" };
......@@ -1147,10 +1152,10 @@ pub const Type = struct {
11471152 },
11481153 .lazy => switch (try child_type.abiAlignmentAdvanced(mod, strat)) {
11491154 .scalar => |x| return .{ .scalar = x.max(.@"1") },
1150 .val => return .{ .val = (try mod.intern(.{ .int = .{
1155 .val => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
11511156 .ty = .comptime_int_type,
11521157 .storage = .{ .lazy_align = ty.toIntern() },
1153 } })).toValue() },
1158 } }))) },
11541159 },
11551160 }
11561161 }
......@@ -1205,14 +1210,14 @@ pub const Type = struct {
12051210 .array_type => |array_type| {
12061211 const len = array_type.len + @intFromBool(array_type.sentinel != .none);
12071212 if (len == 0) return .{ .scalar = 0 };
1208 switch (try array_type.child.toType().abiSizeAdvanced(mod, strat)) {
1213 switch (try Type.fromInterned(array_type.child).abiSizeAdvanced(mod, strat)) {
12091214 .scalar => |elem_size| return .{ .scalar = len * elem_size },
12101215 .val => switch (strat) {
12111216 .sema, .eager => unreachable,
1212 .lazy => return .{ .val = (try mod.intern(.{ .int = .{
1217 .lazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
12131218 .ty = .comptime_int_type,
12141219 .storage = .{ .lazy_size = ty.toIntern() },
1215 } })).toValue() },
1220 } }))) },
12161221 },
12171222 }
12181223 },
......@@ -1220,20 +1225,20 @@ pub const Type = struct {
12201225 const opt_sema = switch (strat) {
12211226 .sema => |sema| sema,
12221227 .eager => null,
1223 .lazy => return .{ .val = (try mod.intern(.{ .int = .{
1228 .lazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
12241229 .ty = .comptime_int_type,
12251230 .storage = .{ .lazy_size = ty.toIntern() },
1226 } })).toValue() },
1231 } }))) },
12271232 };
1228 const elem_bits = try vector_type.child.toType().bitSizeAdvanced(mod, opt_sema);
1233 const elem_bits = try Type.fromInterned(vector_type.child).bitSizeAdvanced(mod, opt_sema);
12291234 const total_bits = elem_bits * vector_type.len;
12301235 const total_bytes = (total_bits + 7) / 8;
12311236 const alignment = switch (try ty.abiAlignmentAdvanced(mod, strat)) {
12321237 .scalar => |x| x,
1233 .val => return .{ .val = (try mod.intern(.{ .int = .{
1238 .val => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
12341239 .ty = .comptime_int_type,
12351240 .storage = .{ .lazy_size = ty.toIntern() },
1236 } })).toValue() },
1241 } }))) },
12371242 };
12381243 return AbiSizeAdvanced{ .scalar = alignment.forward(total_bytes) };
12391244 },
......@@ -1247,15 +1252,15 @@ pub const Type = struct {
12471252 },
12481253
12491254 .error_union_type => |error_union_type| {
1250 const payload_ty = error_union_type.payload_type.toType();
1255 const payload_ty = Type.fromInterned(error_union_type.payload_type);
12511256 // This code needs to be kept in sync with the equivalent switch prong
12521257 // in abiAlignmentAdvanced.
12531258 const code_size = abiSize(Type.anyerror, mod);
12541259 if (!(payload_ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) {
1255 error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{
1260 error.NeedLazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
12561261 .ty = .comptime_int_type,
12571262 .storage = .{ .lazy_size = ty.toIntern() },
1258 } })).toValue() },
1263 } }))) },
12591264 else => |e| return e,
12601265 })) {
12611266 // Same as anyerror.
......@@ -1268,10 +1273,10 @@ pub const Type = struct {
12681273 .val => switch (strat) {
12691274 .sema => unreachable,
12701275 .eager => unreachable,
1271 .lazy => return .{ .val = (try mod.intern(.{ .int = .{
1276 .lazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
12721277 .ty = .comptime_int_type,
12731278 .storage = .{ .lazy_size = ty.toIntern() },
1274 } })).toValue() },
1279 } }))) },
12751280 },
12761281 };
12771282
......@@ -1358,18 +1363,18 @@ pub const Type = struct {
13581363 .lazy => switch (struct_type.layout) {
13591364 .Packed => {
13601365 if (struct_type.backingIntType(ip).* == .none) return .{
1361 .val = (try mod.intern(.{ .int = .{
1366 .val = Value.fromInterned((try mod.intern(.{ .int = .{
13621367 .ty = .comptime_int_type,
13631368 .storage = .{ .lazy_size = ty.toIntern() },
1364 } })).toValue(),
1369 } }))),
13651370 };
13661371 },
13671372 .Auto, .Extern => {
13681373 if (!struct_type.haveLayout(ip)) return .{
1369 .val = (try mod.intern(.{ .int = .{
1374 .val = Value.fromInterned((try mod.intern(.{ .int = .{
13701375 .ty = .comptime_int_type,
13711376 .storage = .{ .lazy_size = ty.toIntern() },
1372 } })).toValue(),
1377 } }))),
13731378 };
13741379 },
13751380 },
......@@ -1377,7 +1382,7 @@ pub const Type = struct {
13771382 }
13781383 return switch (struct_type.layout) {
13791384 .Packed => .{
1380 .scalar = struct_type.backingIntType(ip).toType().abiSize(mod),
1385 .scalar = Type.fromInterned(struct_type.backingIntType(ip).*).abiSize(mod),
13811386 },
13821387 .Auto, .Extern => .{ .scalar = struct_type.size(ip).* },
13831388 };
......@@ -1398,10 +1403,10 @@ pub const Type = struct {
13981403 switch (strat) {
13991404 .sema => |sema| try sema.resolveTypeLayout(ty),
14001405 .lazy => if (!union_type.flagsPtr(ip).status.haveLayout()) return .{
1401 .val = (try mod.intern(.{ .int = .{
1406 .val = Value.fromInterned((try mod.intern(.{ .int = .{
14021407 .ty = .comptime_int_type,
14031408 .storage = .{ .lazy_size = ty.toIntern() },
1404 } })).toValue(),
1409 } }))),
14051410 },
14061411 .eager => {},
14071412 }
......@@ -1409,7 +1414,7 @@ pub const Type = struct {
14091414 return .{ .scalar = union_type.size(ip).* };
14101415 },
14111416 .opaque_type => unreachable, // no size available
1412 .enum_type => |enum_type| return AbiSizeAdvanced{ .scalar = enum_type.tag_ty.toType().abiSize(mod) },
1417 .enum_type => |enum_type| return AbiSizeAdvanced{ .scalar = Type.fromInterned(enum_type.tag_ty).abiSize(mod) },
14131418
14141419 // values, not types
14151420 .undef,
......@@ -1447,10 +1452,10 @@ pub const Type = struct {
14471452 }
14481453
14491454 if (!(child_ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) {
1450 error.NeedLazy => return .{ .val = (try mod.intern(.{ .int = .{
1455 error.NeedLazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
14511456 .ty = .comptime_int_type,
14521457 .storage = .{ .lazy_size = ty.toIntern() },
1453 } })).toValue() },
1458 } }))) },
14541459 else => |e| return e,
14551460 })) return AbiSizeAdvanced{ .scalar = 1 };
14561461
......@@ -1463,10 +1468,10 @@ pub const Type = struct {
14631468 .val => switch (strat) {
14641469 .sema => unreachable,
14651470 .eager => unreachable,
1466 .lazy => return .{ .val = (try mod.intern(.{ .int = .{
1471 .lazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
14671472 .ty = .comptime_int_type,
14681473 .storage = .{ .lazy_size = ty.toIntern() },
1469 } })).toValue() },
1474 } }))) },
14701475 },
14711476 };
14721477
......@@ -1518,7 +1523,7 @@ pub const Type = struct {
15181523 .array_type => |array_type| {
15191524 const len = array_type.len + @intFromBool(array_type.sentinel != .none);
15201525 if (len == 0) return 0;
1521 const elem_ty = array_type.child.toType();
1526 const elem_ty = Type.fromInterned(array_type.child);
15221527 const elem_size = @max(
15231528 (try elem_ty.abiAlignmentAdvanced(mod, strat)).scalar.toByteUnits(0),
15241529 (try elem_ty.abiSizeAdvanced(mod, strat)).scalar,
......@@ -1528,7 +1533,7 @@ pub const Type = struct {
15281533 return (len - 1) * 8 * elem_size + elem_bit_size;
15291534 },
15301535 .vector_type => |vector_type| {
1531 const child_ty = vector_type.child.toType();
1536 const child_ty = Type.fromInterned(vector_type.child);
15321537 const elem_bit_size = try bitSizeAdvanced(child_ty, mod, opt_sema);
15331538 return elem_bit_size * vector_type.len;
15341539 },
......@@ -1600,7 +1605,7 @@ pub const Type = struct {
16001605 .struct_type => |struct_type| {
16011606 if (struct_type.layout == .Packed) {
16021607 if (opt_sema) |sema| try sema.resolveTypeLayout(ty);
1603 return try struct_type.backingIntType(ip).*.toType().bitSizeAdvanced(mod, opt_sema);
1608 return try Type.fromInterned(struct_type.backingIntType(ip).*).bitSizeAdvanced(mod, opt_sema);
16041609 }
16051610 return (try ty.abiSizeAdvanced(mod, strat)).scalar * 8;
16061611 },
......@@ -1625,13 +1630,13 @@ pub const Type = struct {
16251630 var size: u64 = 0;
16261631 for (0..union_obj.field_types.len) |field_index| {
16271632 const field_ty = union_obj.field_types.get(ip)[field_index];
1628 size = @max(size, try bitSizeAdvanced(field_ty.toType(), mod, opt_sema));
1633 size = @max(size, try bitSizeAdvanced(Type.fromInterned(field_ty), mod, opt_sema));
16291634 }
16301635
16311636 return size;
16321637 },
16331638 .opaque_type => unreachable,
1634 .enum_type => |enum_type| return bitSizeAdvanced(enum_type.tag_ty.toType(), mod, opt_sema),
1639 .enum_type => |enum_type| return bitSizeAdvanced(Type.fromInterned(enum_type.tag_ty), mod, opt_sema),
16351640
16361641 // values, not types
16371642 .undef,
......@@ -1665,10 +1670,10 @@ pub const Type = struct {
16651670 .union_type => |union_type| union_type.haveLayout(ip),
16661671 .array_type => |array_type| {
16671672 if ((array_type.len + @intFromBool(array_type.sentinel != .none)) == 0) return true;
1668 return array_type.child.toType().layoutIsResolved(mod);
1673 return Type.fromInterned(array_type.child).layoutIsResolved(mod);
16691674 },
1670 .opt_type => |child| child.toType().layoutIsResolved(mod),
1671 .error_union_type => |k| k.payload_type.toType().layoutIsResolved(mod),
1675 .opt_type => |child| Type.fromInterned(child).layoutIsResolved(mod),
1676 .error_union_type => |k| Type.fromInterned(k.payload_type).layoutIsResolved(mod),
16721677 else => true,
16731678 };
16741679 }
......@@ -1701,7 +1706,7 @@ pub const Type = struct {
17011706 }
17021707
17031708 pub fn slicePtrFieldType(ty: Type, mod: *const Module) Type {
1704 return mod.intern_pool.slicePtrType(ty.toIntern()).toType();
1709 return Type.fromInterned(mod.intern_pool.slicePtrType(ty.toIntern()));
17051710 }
17061711
17071712 pub fn isConstPtr(ty: Type, mod: *const Module) bool {
......@@ -1801,7 +1806,7 @@ pub const Type = struct {
18011806 }
18021807
18031808 pub fn childTypeIp(ty: Type, ip: *const InternPool) Type {
1804 return ip.childType(ty.toIntern()).toType();
1809 return Type.fromInterned(ip.childType(ty.toIntern()));
18051810 }
18061811
18071812 /// For *[N]T, returns T.
......@@ -1816,16 +1821,16 @@ pub const Type = struct {
18161821 pub fn elemType2(ty: Type, mod: *const Module) Type {
18171822 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
18181823 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
1819 .One => ptr_type.child.toType().shallowElemType(mod),
1820 .Many, .C, .Slice => ptr_type.child.toType(),
1824 .One => Type.fromInterned(ptr_type.child).shallowElemType(mod),
1825 .Many, .C, .Slice => Type.fromInterned(ptr_type.child),
18211826 },
18221827 .anyframe_type => |child| {
18231828 assert(child != .none);
1824 return child.toType();
1829 return Type.fromInterned(child);
18251830 },
1826 .vector_type => |vector_type| vector_type.child.toType(),
1827 .array_type => |array_type| array_type.child.toType(),
1828 .opt_type => |child| mod.intern_pool.childType(child).toType(),
1831 .vector_type => |vector_type| Type.fromInterned(vector_type.child),
1832 .array_type => |array_type| Type.fromInterned(array_type.child),
1833 .opt_type => |child| Type.fromInterned(mod.intern_pool.childType(child)),
18291834 else => unreachable,
18301835 };
18311836 }
......@@ -1849,7 +1854,7 @@ pub const Type = struct {
18491854 /// Note that for C pointers this returns the type unmodified.
18501855 pub fn optionalChild(ty: Type, mod: *const Module) Type {
18511856 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1852 .opt_type => |child| child.toType(),
1857 .opt_type => |child| Type.fromInterned(child),
18531858 .ptr_type => |ptr_type| b: {
18541859 assert(ptr_type.flags.size == .C);
18551860 break :b ty;
......@@ -1866,7 +1871,7 @@ pub const Type = struct {
18661871 .union_type => |union_type| switch (union_type.flagsPtr(ip).runtime_tag) {
18671872 .tagged => {
18681873 assert(union_type.flagsPtr(ip).status.haveFieldTypes());
1869 return union_type.enum_tag_ty.toType();
1874 return Type.fromInterned(union_type.enum_tag_ty);
18701875 },
18711876 else => null,
18721877 },
......@@ -1882,7 +1887,7 @@ pub const Type = struct {
18821887 .union_type => |union_type| {
18831888 if (!union_type.hasTag(ip)) return null;
18841889 assert(union_type.haveFieldTypes(ip));
1885 return union_type.enum_tag_ty.toType();
1890 return Type.fromInterned(union_type.enum_tag_ty);
18861891 },
18871892 else => null,
18881893 };
......@@ -1892,7 +1897,7 @@ pub const Type = struct {
18921897 /// not be stored at runtime.
18931898 pub fn unionTagTypeHypothetical(ty: Type, mod: *Module) Type {
18941899 const union_obj = mod.typeToUnion(ty).?;
1895 return union_obj.enum_tag_ty.toType();
1900 return Type.fromInterned(union_obj.enum_tag_ty);
18961901 }
18971902
18981903 pub fn unionFieldType(ty: Type, enum_tag: Value, mod: *Module) ?Type {
......@@ -1900,7 +1905,7 @@ pub const Type = struct {
19001905 const union_obj = mod.typeToUnion(ty).?;
19011906 const union_fields = union_obj.field_types.get(ip);
19021907 const index = mod.unionTagFieldIndex(union_obj, enum_tag) orelse return null;
1903 return union_fields[index].toType();
1908 return Type.fromInterned(union_fields[index]);
19041909 }
19051910
19061911 pub fn unionTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 {
......@@ -1912,7 +1917,7 @@ pub const Type = struct {
19121917 const ip = &mod.intern_pool;
19131918 const union_obj = mod.typeToUnion(ty).?;
19141919 for (union_obj.field_types.get(ip)) |field_ty| {
1915 if (field_ty.toType().hasRuntimeBits(mod)) return false;
1920 if (Type.fromInterned(field_ty).hasRuntimeBits(mod)) return false;
19161921 }
19171922 return true;
19181923 }
......@@ -1946,12 +1951,12 @@ pub const Type = struct {
19461951
19471952 /// Asserts that the type is an error union.
19481953 pub fn errorUnionPayload(ty: Type, mod: *Module) Type {
1949 return mod.intern_pool.indexToKey(ty.toIntern()).error_union_type.payload_type.toType();
1954 return Type.fromInterned(mod.intern_pool.indexToKey(ty.toIntern()).error_union_type.payload_type);
19501955 }
19511956
19521957 /// Asserts that the type is an error union.
19531958 pub fn errorUnionSet(ty: Type, mod: *Module) Type {
1954 return mod.intern_pool.errorUnionSet(ty.toIntern()).toType();
1959 return Type.fromInterned(mod.intern_pool.errorUnionSet(ty.toIntern()));
19551960 }
19561961
19571962 /// Returns false for unresolved inferred error sets.
......@@ -2077,8 +2082,8 @@ pub const Type = struct {
20772082 .anon_struct_type,
20782083 => null,
20792084
2080 .array_type => |t| if (t.sentinel != .none) t.sentinel.toValue() else null,
2081 .ptr_type => |t| if (t.sentinel != .none) t.sentinel.toValue() else null,
2085 .array_type => |t| if (t.sentinel != .none) Value.fromInterned(t.sentinel) else null,
2086 .ptr_type => |t| if (t.sentinel != .none) Value.fromInterned(t.sentinel) else null,
20822087
20832088 else => unreachable,
20842089 };
......@@ -2146,9 +2151,9 @@ pub const Type = struct {
21462151 .c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) },
21472152 else => switch (ip.indexToKey(ty.toIntern())) {
21482153 .int_type => |int_type| return int_type,
2149 .struct_type => |t| ty = t.backingIntType(ip).*.toType(),
2150 .enum_type => |enum_type| ty = enum_type.tag_ty.toType(),
2151 .vector_type => |vector_type| ty = vector_type.child.toType(),
2154 .struct_type => |t| ty = Type.fromInterned(t.backingIntType(ip).*),
2155 .enum_type => |enum_type| ty = Type.fromInterned(enum_type.tag_ty),
2156 .vector_type => |vector_type| ty = Type.fromInterned(vector_type.child),
21522157
21532158 .error_set_type, .inferred_error_set_type => {
21542159 return .{ .signedness = .unsigned, .bits = mod.errorSetBits() };
......@@ -2259,7 +2264,7 @@ pub const Type = struct {
22592264
22602265 /// Asserts the type is a function or a function pointer.
22612266 pub fn fnReturnType(ty: Type, mod: *Module) Type {
2262 return mod.intern_pool.funcTypeReturnType(ty.toIntern()).toType();
2267 return Type.fromInterned(mod.intern_pool.funcTypeReturnType(ty.toIntern()));
22632268 }
22642269
22652270 /// Asserts the type is a function.
......@@ -2343,15 +2348,15 @@ pub const Type = struct {
23432348
23442349 inline .array_type, .vector_type => |seq_type, seq_tag| {
23452350 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;
2346 if (seq_type.len + @intFromBool(has_sentinel) == 0) return (try mod.intern(.{ .aggregate = .{
2351 if (seq_type.len + @intFromBool(has_sentinel) == 0) return Value.fromInterned((try mod.intern(.{ .aggregate = .{
23472352 .ty = ty.toIntern(),
23482353 .storage = .{ .elems = &.{} },
2349 } })).toValue();
2350 if (try seq_type.child.toType().onePossibleValue(mod)) |opv| {
2351 return (try mod.intern(.{ .aggregate = .{
2354 } })));
2355 if (try Type.fromInterned(seq_type.child).onePossibleValue(mod)) |opv| {
2356 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
23522357 .ty = ty.toIntern(),
23532358 .storage = .{ .repeated_elem = opv.toIntern() },
2354 } })).toValue();
2359 } })));
23552360 }
23562361 return null;
23572362 },
......@@ -2422,7 +2427,7 @@ pub const Type = struct {
24222427 field_val.* = struct_type.field_inits.get(ip)[i];
24232428 continue;
24242429 }
2425 const field_ty = struct_type.field_types.get(ip)[i].toType();
2430 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
24262431 if (try field_ty.onePossibleValue(mod)) |field_opv| {
24272432 field_val.* = try field_opv.intern(field_ty, mod);
24282433 } else return null;
......@@ -2430,10 +2435,10 @@ pub const Type = struct {
24302435
24312436 // In this case the struct has no runtime-known fields and
24322437 // therefore has one possible value.
2433 return (try mod.intern(.{ .aggregate = .{
2438 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
24342439 .ty = ty.toIntern(),
24352440 .storage = .{ .elems = field_vals },
2436 } })).toValue();
2441 } })));
24372442 },
24382443
24392444 .anon_struct_type => |tuple| {
......@@ -2445,52 +2450,52 @@ pub const Type = struct {
24452450 // TODO: write something like getCoercedInts to avoid needing to dupe
24462451 const duped_values = try mod.gpa.dupe(InternPool.Index, tuple.values.get(ip));
24472452 defer mod.gpa.free(duped_values);
2448 return (try mod.intern(.{ .aggregate = .{
2453 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
24492454 .ty = ty.toIntern(),
24502455 .storage = .{ .elems = duped_values },
2451 } })).toValue();
2456 } })));
24522457 },
24532458
24542459 .union_type => |union_type| {
24552460 const union_obj = ip.loadUnionType(union_type);
2456 const tag_val = (try union_obj.enum_tag_ty.toType().onePossibleValue(mod)) orelse
2461 const tag_val = (try Type.fromInterned(union_obj.enum_tag_ty).onePossibleValue(mod)) orelse
24572462 return null;
24582463 if (union_obj.field_names.len == 0) {
24592464 const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() });
2460 return only.toValue();
2465 return Value.fromInterned(only);
24612466 }
24622467 const only_field_ty = union_obj.field_types.get(ip)[0];
2463 const val_val = (try only_field_ty.toType().onePossibleValue(mod)) orelse
2468 const val_val = (try Type.fromInterned(only_field_ty).onePossibleValue(mod)) orelse
24642469 return null;
24652470 const only = try mod.intern(.{ .un = .{
24662471 .ty = ty.toIntern(),
24672472 .tag = tag_val.toIntern(),
24682473 .val = val_val.toIntern(),
24692474 } });
2470 return only.toValue();
2475 return Value.fromInterned(only);
24712476 },
24722477 .opaque_type => return null,
24732478 .enum_type => |enum_type| switch (enum_type.tag_mode) {
24742479 .nonexhaustive => {
24752480 if (enum_type.tag_ty == .comptime_int_type) return null;
24762481
2477 if (try enum_type.tag_ty.toType().onePossibleValue(mod)) |int_opv| {
2482 if (try Type.fromInterned(enum_type.tag_ty).onePossibleValue(mod)) |int_opv| {
24782483 const only = try mod.intern(.{ .enum_tag = .{
24792484 .ty = ty.toIntern(),
24802485 .int = int_opv.toIntern(),
24812486 } });
2482 return only.toValue();
2487 return Value.fromInterned(only);
24832488 }
24842489
24852490 return null;
24862491 },
24872492 .auto, .explicit => {
2488 if (enum_type.tag_ty.toType().hasRuntimeBits(mod)) return null;
2493 if (Type.fromInterned(enum_type.tag_ty).hasRuntimeBits(mod)) return null;
24892494
24902495 switch (enum_type.names.len) {
24912496 0 => {
24922497 const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() });
2493 return only.toValue();
2498 return Value.fromInterned(only);
24942499 },
24952500 1 => {
24962501 if (enum_type.values.len == 0) {
......@@ -2501,9 +2506,9 @@ pub const Type = struct {
25012506 .storage = .{ .u64 = 0 },
25022507 } }),
25032508 } });
2504 return only.toValue();
2509 return Value.fromInterned(only);
25052510 } else {
2506 return enum_type.values.get(ip)[0].toValue();
2511 return Value.fromInterned(enum_type.values.get(ip)[0]);
25072512 }
25082513 },
25092514 else => return null,
......@@ -2552,7 +2557,7 @@ pub const Type = struct {
25522557 else => switch (ip.indexToKey(ty.toIntern())) {
25532558 .int_type => false,
25542559 .ptr_type => |ptr_type| {
2555 const child_ty = ptr_type.child.toType();
2560 const child_ty = Type.fromInterned(ptr_type.child);
25562561 switch (child_ty.zigTypeTag(mod)) {
25572562 .Fn => return !try child_ty.fnHasRuntimeBitsAdvanced(mod, opt_sema),
25582563 .Opaque => return false,
......@@ -2561,12 +2566,12 @@ pub const Type = struct {
25612566 },
25622567 .anyframe_type => |child| {
25632568 if (child == .none) return false;
2564 return child.toType().comptimeOnlyAdvanced(mod, opt_sema);
2569 return Type.fromInterned(child).comptimeOnlyAdvanced(mod, opt_sema);
25652570 },
2566 .array_type => |array_type| return array_type.child.toType().comptimeOnlyAdvanced(mod, opt_sema),
2567 .vector_type => |vector_type| return vector_type.child.toType().comptimeOnlyAdvanced(mod, opt_sema),
2568 .opt_type => |child| return child.toType().comptimeOnlyAdvanced(mod, opt_sema),
2569 .error_union_type => |error_union_type| return error_union_type.payload_type.toType().comptimeOnlyAdvanced(mod, opt_sema),
2571 .array_type => |array_type| return Type.fromInterned(array_type.child).comptimeOnlyAdvanced(mod, opt_sema),
2572 .vector_type => |vector_type| return Type.fromInterned(vector_type.child).comptimeOnlyAdvanced(mod, opt_sema),
2573 .opt_type => |child| return Type.fromInterned(child).comptimeOnlyAdvanced(mod, opt_sema),
2574 .error_union_type => |error_union_type| return Type.fromInterned(error_union_type.payload_type).comptimeOnlyAdvanced(mod, opt_sema),
25702575
25712576 .error_set_type,
25722577 .inferred_error_set_type,
......@@ -2647,7 +2652,7 @@ pub const Type = struct {
26472652 const i: u32 = @intCast(i_usize);
26482653 if (struct_type.fieldIsComptime(ip, i)) continue;
26492654 const field_ty = struct_type.field_types.get(ip)[i];
2650 if (try field_ty.toType().comptimeOnlyAdvanced(mod, opt_sema)) {
2655 if (try Type.fromInterned(field_ty).comptimeOnlyAdvanced(mod, opt_sema)) {
26512656 // Note that this does not cause the layout to
26522657 // be considered resolved. Comptime-only types
26532658 // still maintain a layout of their
......@@ -2666,7 +2671,7 @@ pub const Type = struct {
26662671 .anon_struct_type => |tuple| {
26672672 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {
26682673 const have_comptime_val = val != .none;
2669 if (!have_comptime_val and try field_ty.toType().comptimeOnlyAdvanced(mod, opt_sema)) return true;
2674 if (!have_comptime_val and try Type.fromInterned(field_ty).comptimeOnlyAdvanced(mod, opt_sema)) return true;
26702675 }
26712676 return false;
26722677 },
......@@ -2689,7 +2694,7 @@ pub const Type = struct {
26892694 const union_obj = ip.loadUnionType(union_type);
26902695 for (0..union_obj.field_types.len) |field_idx| {
26912696 const field_ty = union_obj.field_types.get(ip)[field_idx];
2692 if (try field_ty.toType().comptimeOnlyAdvanced(mod, opt_sema)) {
2697 if (try Type.fromInterned(field_ty).comptimeOnlyAdvanced(mod, opt_sema)) {
26932698 union_obj.flagsPtr(ip).requires_comptime = .yes;
26942699 return true;
26952700 }
......@@ -2702,7 +2707,7 @@ pub const Type = struct {
27022707
27032708 .opaque_type => false,
27042709
2705 .enum_type => |enum_type| return enum_type.tag_ty.toType().comptimeOnlyAdvanced(mod, opt_sema),
2710 .enum_type => |enum_type| return Type.fromInterned(enum_type.tag_ty).comptimeOnlyAdvanced(mod, opt_sema),
27062711
27072712 // values, not types
27082713 .undef,
......@@ -2792,10 +2797,10 @@ pub const Type = struct {
27922797 // Works for vectors and vectors of integers.
27932798 pub fn minInt(ty: Type, mod: *Module, dest_ty: Type) !Value {
27942799 const scalar = try minIntScalar(ty.scalarType(mod), mod, dest_ty.scalarType(mod));
2795 return if (ty.zigTypeTag(mod) == .Vector) (try mod.intern(.{ .aggregate = .{
2800 return if (ty.zigTypeTag(mod) == .Vector) Value.fromInterned((try mod.intern(.{ .aggregate = .{
27962801 .ty = dest_ty.toIntern(),
27972802 .storage = .{ .repeated_elem = scalar.toIntern() },
2798 } })).toValue() else scalar;
2803 } }))) else scalar;
27992804 }
28002805
28012806 /// Asserts that the type is an integer.
......@@ -2821,10 +2826,10 @@ pub const Type = struct {
28212826 /// The returned Value will have type dest_ty.
28222827 pub fn maxInt(ty: Type, mod: *Module, dest_ty: Type) !Value {
28232828 const scalar = try maxIntScalar(ty.scalarType(mod), mod, dest_ty.scalarType(mod));
2824 return if (ty.zigTypeTag(mod) == .Vector) (try mod.intern(.{ .aggregate = .{
2829 return if (ty.zigTypeTag(mod) == .Vector) Value.fromInterned((try mod.intern(.{ .aggregate = .{
28252830 .ty = dest_ty.toIntern(),
28262831 .storage = .{ .repeated_elem = scalar.toIntern() },
2827 } })).toValue() else scalar;
2832 } }))) else scalar;
28282833 }
28292834
28302835 /// The returned Value will have type dest_ty.
......@@ -2865,8 +2870,8 @@ pub const Type = struct {
28652870 /// Asserts the type is an enum or a union.
28662871 pub fn intTagType(ty: Type, mod: *Module) Type {
28672872 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2868 .union_type => |union_type| union_type.enum_tag_ty.toType().intTagType(mod),
2869 .enum_type => |enum_type| enum_type.tag_ty.toType(),
2873 .union_type => |union_type| Type.fromInterned(union_type.enum_tag_ty).intTagType(mod),
2874 .enum_type => |enum_type| Type.fromInterned(enum_type.tag_ty),
28702875 else => unreachable,
28712876 };
28722877 }
......@@ -2965,12 +2970,12 @@ pub const Type = struct {
29652970 pub fn structFieldType(ty: Type, index: usize, mod: *Module) Type {
29662971 const ip = &mod.intern_pool;
29672972 return switch (ip.indexToKey(ty.toIntern())) {
2968 .struct_type => |struct_type| struct_type.field_types.get(ip)[index].toType(),
2973 .struct_type => |struct_type| Type.fromInterned(struct_type.field_types.get(ip)[index]),
29692974 .union_type => |union_type| {
29702975 const union_obj = ip.loadUnionType(union_type);
2971 return union_obj.field_types.get(ip)[index].toType();
2976 return Type.fromInterned(union_obj.field_types.get(ip)[index]);
29722977 },
2973 .anon_struct_type => |anon_struct| anon_struct.types.get(ip)[index].toType(),
2978 .anon_struct_type => |anon_struct| Type.fromInterned(anon_struct.types.get(ip)[index]),
29742979 else => unreachable,
29752980 };
29762981 }
......@@ -2981,11 +2986,11 @@ pub const Type = struct {
29812986 .struct_type => |struct_type| {
29822987 assert(struct_type.layout != .Packed);
29832988 const explicit_align = struct_type.fieldAlign(ip, index);
2984 const field_ty = struct_type.field_types.get(ip)[index].toType();
2989 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[index]);
29852990 return mod.structFieldAlignment(explicit_align, field_ty, struct_type.layout);
29862991 },
29872992 .anon_struct_type => |anon_struct| {
2988 return anon_struct.types.get(ip)[index].toType().abiAlignment(mod);
2993 return Type.fromInterned(anon_struct.types.get(ip)[index]).abiAlignment(mod);
29892994 },
29902995 .union_type => |union_type| {
29912996 const union_obj = ip.loadUnionType(union_type);
......@@ -3002,13 +3007,13 @@ pub const Type = struct {
30023007 const val = struct_type.fieldInit(ip, index);
30033008 // TODO: avoid using `unreachable` to indicate this.
30043009 if (val == .none) return Value.@"unreachable";
3005 return val.toValue();
3010 return Value.fromInterned(val);
30063011 },
30073012 .anon_struct_type => |anon_struct| {
30083013 const val = anon_struct.values.get(ip)[index];
30093014 // TODO: avoid using `unreachable` to indicate this.
30103015 if (val == .none) return Value.@"unreachable";
3011 return val.toValue();
3016 return Value.fromInterned(val);
30123017 },
30133018 else => unreachable,
30143019 }
......@@ -3020,17 +3025,17 @@ pub const Type = struct {
30203025 .struct_type => |struct_type| {
30213026 assert(struct_type.haveFieldInits(ip));
30223027 if (struct_type.fieldIsComptime(ip, index)) {
3023 return struct_type.field_inits.get(ip)[index].toValue();
3028 return Value.fromInterned(struct_type.field_inits.get(ip)[index]);
30243029 } else {
3025 return struct_type.field_types.get(ip)[index].toType().onePossibleValue(mod);
3030 return Type.fromInterned(struct_type.field_types.get(ip)[index]).onePossibleValue(mod);
30263031 }
30273032 },
30283033 .anon_struct_type => |tuple| {
30293034 const val = tuple.values.get(ip)[index];
30303035 if (val == .none) {
3031 return tuple.types.get(ip)[index].toType().onePossibleValue(mod);
3036 return Type.fromInterned(tuple.types.get(ip)[index]).onePossibleValue(mod);
30323037 } else {
3033 return val.toValue();
3038 return Value.fromInterned(val);
30343039 }
30353040 },
30363041 else => unreachable,
......@@ -3066,17 +3071,17 @@ pub const Type = struct {
30663071 var big_align: Alignment = .none;
30673072
30683073 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {
3069 if (field_val != .none or !field_ty.toType().hasRuntimeBits(mod)) {
3074 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(mod)) {
30703075 // comptime field
30713076 if (i == index) return offset;
30723077 continue;
30733078 }
30743079
3075 const field_align = field_ty.toType().abiAlignment(mod);
3080 const field_align = Type.fromInterned(field_ty).abiAlignment(mod);
30763081 big_align = big_align.max(field_align);
30773082 offset = field_align.forward(offset);
30783083 if (i == index) return offset;
3079 offset += field_ty.toType().abiSize(mod);
3084 offset += Type.fromInterned(field_ty).abiSize(mod);
30803085 }
30813086 offset = big_align.max(.@"1").forward(offset);
30823087 return offset;
src/value.zig+284-277
......@@ -196,13 +196,13 @@ pub const Value = struct {
196196 .enum_literal => |enum_literal| enum_literal,
197197 .ptr => |ptr| switch (ptr.len) {
198198 .none => unreachable,
199 else => try arrayToIpString(val, ptr.len.toValue().toUnsignedInt(mod), mod),
199 else => try arrayToIpString(val, Value.fromInterned(ptr.len).toUnsignedInt(mod), mod),
200200 },
201201 .aggregate => |aggregate| switch (aggregate.storage) {
202202 .bytes => |bytes| try ip.getOrPutString(mod.gpa, bytes),
203203 .elems => try arrayToIpString(val, ty.arrayLen(mod), mod),
204204 .repeated_elem => |elem| {
205 const byte = @as(u8, @intCast(elem.toValue().toUnsignedInt(mod)));
205 const byte = @as(u8, @intCast(Value.fromInterned(elem).toUnsignedInt(mod)));
206206 const len = @as(usize, @intCast(ty.arrayLen(mod)));
207207 try ip.string_bytes.appendNTimes(mod.gpa, byte, len);
208208 return ip.getOrPutTrailingString(mod.gpa, len);
......@@ -219,13 +219,13 @@ pub const Value = struct {
219219 .enum_literal => |enum_literal| allocator.dupe(u8, mod.intern_pool.stringToSlice(enum_literal)),
220220 .ptr => |ptr| switch (ptr.len) {
221221 .none => unreachable,
222 else => try arrayToAllocatedBytes(val, ptr.len.toValue().toUnsignedInt(mod), allocator, mod),
222 else => try arrayToAllocatedBytes(val, Value.fromInterned(ptr.len).toUnsignedInt(mod), allocator, mod),
223223 },
224224 .aggregate => |aggregate| switch (aggregate.storage) {
225225 .bytes => |bytes| try allocator.dupe(u8, bytes),
226226 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),
227227 .repeated_elem => |elem| {
228 const byte = @as(u8, @intCast(elem.toValue().toUnsignedInt(mod)));
228 const byte = @as(u8, @intCast(Value.fromInterned(elem).toUnsignedInt(mod)));
229229 const result = try allocator.alloc(u8, @as(usize, @intCast(ty.arrayLen(mod))));
230230 @memset(result, byte);
231231 return result;
......@@ -316,8 +316,8 @@ pub const Value = struct {
316316 for (new_elems, old_elems, 0..) |*new_elem, old_elem, field_i|
317317 new_elem.* = try old_elem.intern(switch (ty_key) {
318318 .struct_type => ty.structFieldType(field_i, mod),
319 .anon_struct_type => |info| info.types.get(ip)[field_i].toType(),
320 inline .array_type, .vector_type => |info| info.child.toType(),
319 .anon_struct_type => |info| Type.fromInterned(info.types.get(ip)[field_i]),
320 inline .array_type, .vector_type => |info| Type.fromInterned(info.child),
321321 else => unreachable,
322322 }, mod);
323323 return mod.intern(.{ .aggregate = .{
......@@ -378,42 +378,50 @@ pub const Value = struct {
378378
379379 .error_union => |error_union| switch (error_union.val) {
380380 .err_name => val,
381 .payload => |payload| Tag.eu_payload.create(arena, payload.toValue()),
381 .payload => |payload| Tag.eu_payload.create(arena, Value.fromInterned(payload)),
382382 },
383383
384384 .ptr => |ptr| switch (ptr.len) {
385385 .none => val,
386386 else => |len| Tag.slice.create(arena, .{
387387 .ptr = val.slicePtr(mod),
388 .len = len.toValue(),
388 .len = Value.fromInterned(len),
389389 }),
390390 },
391391
392392 .opt => |opt| switch (opt.val) {
393393 .none => val,
394 else => |payload| Tag.opt_payload.create(arena, payload.toValue()),
394 else => |payload| Tag.opt_payload.create(arena, Value.fromInterned(payload)),
395395 },
396396
397397 .aggregate => |aggregate| switch (aggregate.storage) {
398398 .bytes => |bytes| Tag.bytes.create(arena, try arena.dupe(u8, bytes)),
399399 .elems => |old_elems| {
400400 const new_elems = try arena.alloc(Value, old_elems.len);
401 for (new_elems, old_elems) |*new_elem, old_elem| new_elem.* = old_elem.toValue();
401 for (new_elems, old_elems) |*new_elem, old_elem| new_elem.* = Value.fromInterned(old_elem);
402402 return Tag.aggregate.create(arena, new_elems);
403403 },
404 .repeated_elem => |elem| Tag.repeated.create(arena, elem.toValue()),
404 .repeated_elem => |elem| Tag.repeated.create(arena, Value.fromInterned(elem)),
405405 },
406406
407407 .un => |un| Tag.@"union".create(arena, .{
408408 // toValue asserts that the value cannot be .none which is valid on unions.
409 .tag = if (un.tag == .none) null else un.tag.toValue(),
410 .val = un.val.toValue(),
409 .tag = if (un.tag == .none) null else Value.fromInterned(un.tag),
410 .val = Value.fromInterned(un.val),
411411 }),
412412
413413 .memoized_call => unreachable,
414414 };
415415 }
416416
417 pub fn fromInterned(i: InternPool.Index) Value {
418 assert(i != .none);
419 return .{
420 .ip_index = i,
421 .legacy = undefined,
422 };
423 }
424
417425 pub fn toIntern(val: Value) InternPool.Index {
418426 assert(val.ip_index != .none);
419427 return val.ip_index;
......@@ -421,7 +429,7 @@ pub const Value = struct {
421429
422430 /// Asserts that the value is representable as a type.
423431 pub fn toType(self: Value) Type {
424 return self.toIntern().toType();
432 return Type.fromInterned(self.toIntern());
425433 }
426434
427435 pub fn intFromEnum(val: Value, ty: Type, mod: *Module) Allocator.Error!Value {
......@@ -435,13 +443,13 @@ pub const Value = struct {
435443 // Assume it is already an integer and return it directly.
436444 .simple_type, .int_type => val,
437445 .enum_type => |enum_type| if (enum_type.values.len != 0)
438 enum_type.values.get(ip)[field_index].toValue()
446 Value.fromInterned(enum_type.values.get(ip)[field_index])
439447 else // Field index and integer values are the same.
440 mod.intValue(enum_type.tag_ty.toType(), field_index),
448 mod.intValue(Type.fromInterned(enum_type.tag_ty), field_index),
441449 else => unreachable,
442450 };
443451 },
444 .enum_type => |enum_type| try mod.getCoerced(val, enum_type.tag_ty.toType()),
452 .enum_type => |enum_type| try mod.getCoerced(val, Type.fromInterned(enum_type.tag_ty)),
445453 else => unreachable,
446454 };
447455 }
......@@ -466,16 +474,16 @@ pub const Value = struct {
466474 .int => |int| switch (int.storage) {
467475 .u64, .i64, .big_int => int.storage.toBigInt(space),
468476 .lazy_align, .lazy_size => |ty| {
469 if (opt_sema) |sema| try sema.resolveTypeLayout(ty.toType());
477 if (opt_sema) |sema| try sema.resolveTypeLayout(Type.fromInterned(ty));
470478 const x = switch (int.storage) {
471479 else => unreachable,
472 .lazy_align => ty.toType().abiAlignment(mod).toByteUnits(0),
473 .lazy_size => ty.toType().abiSize(mod),
480 .lazy_align => Type.fromInterned(ty).abiAlignment(mod).toByteUnits(0),
481 .lazy_size => Type.fromInterned(ty).abiSize(mod),
474482 };
475483 return BigIntMutable.init(&space.limbs, x).toConst();
476484 },
477485 },
478 .enum_tag => |enum_tag| enum_tag.int.toValue().toBigIntAdvanced(space, mod, opt_sema),
486 .enum_tag => |enum_tag| Value.fromInterned(enum_tag.int).toBigIntAdvanced(space, mod, opt_sema),
479487 .opt, .ptr => BigIntMutable.init(
480488 &space.limbs,
481489 (try val.getUnsignedIntAdvanced(mod, opt_sema)).?,
......@@ -530,24 +538,24 @@ pub const Value = struct {
530538 .u64 => |x| x,
531539 .i64 => |x| std.math.cast(u64, x),
532540 .lazy_align => |ty| if (opt_sema) |sema|
533 (try ty.toType().abiAlignmentAdvanced(mod, .{ .sema = sema })).scalar.toByteUnits(0)
541 (try Type.fromInterned(ty).abiAlignmentAdvanced(mod, .{ .sema = sema })).scalar.toByteUnits(0)
534542 else
535 ty.toType().abiAlignment(mod).toByteUnits(0),
543 Type.fromInterned(ty).abiAlignment(mod).toByteUnits(0),
536544 .lazy_size => |ty| if (opt_sema) |sema|
537 (try ty.toType().abiSizeAdvanced(mod, .{ .sema = sema })).scalar
545 (try Type.fromInterned(ty).abiSizeAdvanced(mod, .{ .sema = sema })).scalar
538546 else
539 ty.toType().abiSize(mod),
547 Type.fromInterned(ty).abiSize(mod),
540548 },
541549 .ptr => |ptr| switch (ptr.addr) {
542 .int => |int| int.toValue().getUnsignedIntAdvanced(mod, opt_sema),
550 .int => |int| Value.fromInterned(int).getUnsignedIntAdvanced(mod, opt_sema),
543551 .elem => |elem| {
544 const base_addr = (try elem.base.toValue().getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;
545 const elem_ty = mod.intern_pool.typeOf(elem.base).toType().elemType2(mod);
552 const base_addr = (try Value.fromInterned(elem.base).getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;
553 const elem_ty = Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod);
546554 return base_addr + elem.index * elem_ty.abiSize(mod);
547555 },
548556 .field => |field| {
549 const base_addr = (try field.base.toValue().getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;
550 const struct_ty = mod.intern_pool.typeOf(field.base).toType().childType(mod);
557 const base_addr = (try Value.fromInterned(field.base).getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;
558 const struct_ty = Type.fromInterned(mod.intern_pool.typeOf(field.base)).childType(mod);
551559 if (opt_sema) |sema| try sema.resolveTypeLayout(struct_ty);
552560 return base_addr + struct_ty.structFieldOffset(@as(usize, @intCast(field.index)), mod);
553561 },
......@@ -555,7 +563,7 @@ pub const Value = struct {
555563 },
556564 .opt => |opt| switch (opt.val) {
557565 .none => 0,
558 else => |payload| payload.toValue().getUnsignedIntAdvanced(mod, opt_sema),
566 else => |payload| Value.fromInterned(payload).getUnsignedIntAdvanced(mod, opt_sema),
559567 },
560568 else => null,
561569 },
......@@ -577,8 +585,8 @@ pub const Value = struct {
577585 .big_int => |big_int| big_int.to(i64) catch unreachable,
578586 .i64 => |x| x,
579587 .u64 => |x| @intCast(x),
580 .lazy_align => |ty| @intCast(ty.toType().abiAlignment(mod).toByteUnits(0)),
581 .lazy_size => |ty| @intCast(ty.toType().abiSize(mod)),
588 .lazy_align => |ty| @intCast(Type.fromInterned(ty).abiAlignment(mod).toByteUnits(0)),
589 .lazy_size => |ty| @intCast(Type.fromInterned(ty).abiSize(mod)),
582590 },
583591 else => unreachable,
584592 },
......@@ -598,8 +606,8 @@ pub const Value = struct {
598606 while (true) switch (mod.intern_pool.indexToKey(check.toIntern())) {
599607 .ptr => |ptr| switch (ptr.addr) {
600608 .decl, .mut_decl, .comptime_field, .anon_decl => return true,
601 .eu_payload, .opt_payload => |base| check = base.toValue(),
602 .elem, .field => |base_index| check = base_index.base.toValue(),
609 .eu_payload, .opt_payload => |base| check = Value.fromInterned(base),
610 .elem, .field => |base_index| check = Value.fromInterned(base_index.base),
603611 .int => return false,
604612 },
605613 else => return false,
......@@ -680,16 +688,16 @@ pub const Value = struct {
680688 .repeated => val.castTag(.repeated).?.data,
681689 else => unreachable,
682690 },
683 else => switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
691 else => Value.fromInterned(switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
684692 .bytes => |bytes| {
685693 buffer[off] = bytes[i];
686694 continue;
687695 },
688696 .elems => |elems| elems[i],
689697 .repeated_elem => |elem| elem,
690 }.toValue(),
698 }),
691699 };
692 const field_ty = struct_type.field_types.get(ip)[i].toType();
700 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
693701 try writeToMemory(field_val, field_ty, mod, buffer[off..]);
694702 },
695703 .Packed => {
......@@ -720,7 +728,7 @@ pub const Value = struct {
720728 if (val.unionTag(mod)) |union_tag| {
721729 const union_obj = mod.typeToUnion(ty).?;
722730 const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?;
723 const field_type = union_obj.field_types.get(&mod.intern_pool)[field_index].toType();
731 const field_type = Type.fromInterned(union_obj.field_types.get(&mod.intern_pool)[field_index]);
724732 const field_val = try val.fieldValue(mod, field_index);
725733 const byte_count = @as(usize, @intCast(field_type.abiSize(mod)));
726734 return writeToMemory(field_val, field_type, mod, buffer[0..byte_count]);
......@@ -829,14 +837,14 @@ pub const Value = struct {
829837 var bits: u16 = 0;
830838 const storage = ip.indexToKey(val.toIntern()).aggregate.storage;
831839 for (0..struct_type.field_types.len) |i| {
832 const field_ty = struct_type.field_types.get(ip)[i].toType();
840 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
833841 const field_bits: u16 = @intCast(field_ty.bitSize(mod));
834842 const field_val = switch (storage) {
835843 .bytes => unreachable,
836844 .elems => |elems| elems[i],
837845 .repeated_elem => |elem| elem,
838846 };
839 try field_val.toValue().writeToPackedMemory(field_ty, mod, buffer, bit_offset + bits);
847 try Value.fromInterned(field_val).writeToPackedMemory(field_ty, mod, buffer, bit_offset + bits);
840848 bits += field_bits;
841849 }
842850 },
......@@ -847,7 +855,7 @@ pub const Value = struct {
847855 .Packed => {
848856 if (val.unionTag(mod)) |union_tag| {
849857 const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?;
850 const field_type = union_obj.field_types.get(ip)[field_index].toType();
858 const field_type = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
851859 const field_val = try val.fieldValue(mod, field_index);
852860 return field_val.writeToPackedMemory(field_type, mod, buffer, bit_offset);
853861 } else {
......@@ -934,7 +942,7 @@ pub const Value = struct {
934942 return mod.getCoerced(try mod.intValue_big(int_ty, bigint.toConst()), ty);
935943 }
936944 },
937 .Float => return (try mod.intern(.{ .float = .{
945 .Float => return Value.fromInterned((try mod.intern(.{ .float = .{
938946 .ty = ty.toIntern(),
939947 .storage = switch (ty.floatBits(target)) {
940948 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readInt(u16, buffer[0..2], endian))) },
......@@ -944,7 +952,7 @@ pub const Value = struct {
944952 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readInt(u128, buffer[0..16], endian))) },
945953 else => unreachable,
946954 },
947 } })).toValue(),
955 } }))),
948956 .Array => {
949957 const elem_ty = ty.childType(mod);
950958 const elem_size = elem_ty.abiSize(mod);
......@@ -954,10 +962,10 @@ pub const Value = struct {
954962 elem.* = try (try readFromMemory(elem_ty, mod, buffer[offset..], arena)).intern(elem_ty, mod);
955963 offset += @as(usize, @intCast(elem_size));
956964 }
957 return (try mod.intern(.{ .aggregate = .{
965 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
958966 .ty = ty.toIntern(),
959967 .storage = .{ .elems = elems },
960 } })).toValue();
968 } })));
961969 },
962970 .Vector => {
963971 // We use byte_count instead of abi_size here, so that any padding bytes
......@@ -973,15 +981,15 @@ pub const Value = struct {
973981 const field_types = struct_type.field_types;
974982 const field_vals = try arena.alloc(InternPool.Index, field_types.len);
975983 for (field_vals, 0..) |*field_val, i| {
976 const field_ty = field_types.get(ip)[i].toType();
984 const field_ty = Type.fromInterned(field_types.get(ip)[i]);
977985 const off: usize = @intCast(ty.structFieldOffset(i, mod));
978986 const sz: usize = @intCast(field_ty.abiSize(mod));
979987 field_val.* = try (try readFromMemory(field_ty, mod, buffer[off..(off + sz)], arena)).intern(field_ty, mod);
980988 }
981 return (try mod.intern(.{ .aggregate = .{
989 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
982990 .ty = ty.toIntern(),
983991 .storage = .{ .elems = field_vals },
984 } })).toValue();
992 } })));
985993 },
986994 .Packed => {
987995 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;
......@@ -996,10 +1004,10 @@ pub const Value = struct {
9961004 const index = (int << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));
9971005 const name = mod.global_error_set.keys()[@intCast(index)];
9981006
999 return (try mod.intern(.{ .err = .{
1007 return Value.fromInterned((try mod.intern(.{ .err = .{
10001008 .ty = ty.toIntern(),
10011009 .name = name,
1002 } })).toValue();
1010 } })));
10031011 },
10041012 .Union => switch (ty.containerLayout(mod)) {
10051013 .Auto => return error.IllDefinedMemoryLayout,
......@@ -1007,11 +1015,11 @@ pub const Value = struct {
10071015 const union_size = ty.abiSize(mod);
10081016 const array_ty = try mod.arrayType(.{ .len = union_size, .child = .u8_type });
10091017 const val = try (try readFromMemory(array_ty, mod, buffer, arena)).intern(array_ty, mod);
1010 return (try mod.intern(.{ .un = .{
1018 return Value.fromInterned((try mod.intern(.{ .un = .{
10111019 .ty = ty.toIntern(),
10121020 .tag = .none,
10131021 .val = val,
1014 } })).toValue();
1022 } })));
10151023 },
10161024 .Packed => {
10171025 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;
......@@ -1021,23 +1029,23 @@ pub const Value = struct {
10211029 .Pointer => {
10221030 assert(!ty.isSlice(mod)); // No well defined layout.
10231031 const int_val = try readFromMemory(Type.usize, mod, buffer, arena);
1024 return (try mod.intern(.{ .ptr = .{
1032 return Value.fromInterned((try mod.intern(.{ .ptr = .{
10251033 .ty = ty.toIntern(),
10261034 .addr = .{ .int = int_val.toIntern() },
1027 } })).toValue();
1035 } })));
10281036 },
10291037 .Optional => {
10301038 assert(ty.isPtrLikeOptional(mod));
10311039 const child_ty = ty.optionalChild(mod);
10321040 const child_val = try readFromMemory(child_ty, mod, buffer, arena);
1033 return (try mod.intern(.{ .opt = .{
1041 return Value.fromInterned((try mod.intern(.{ .opt = .{
10341042 .ty = ty.toIntern(),
10351043 .val = switch (child_val.orderAgainstZero(mod)) {
10361044 .lt => unreachable,
10371045 .eq => .none,
10381046 .gt => child_val.toIntern(),
10391047 },
1040 } })).toValue();
1048 } })));
10411049 },
10421050 else => return error.Unimplemented,
10431051 }
......@@ -1108,7 +1116,7 @@ pub const Value = struct {
11081116 bigint.readPackedTwosComplement(buffer, bit_offset, bits, endian, int_info.signedness);
11091117 return mod.intValue_big(ty, bigint.toConst());
11101118 },
1111 .Float => return (try mod.intern(.{ .float = .{
1119 .Float => return Value.fromInterned((try mod.intern(.{ .float = .{
11121120 .ty = ty.toIntern(),
11131121 .storage = switch (ty.floatBits(target)) {
11141122 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readPackedInt(u16, buffer, bit_offset, endian))) },
......@@ -1118,7 +1126,7 @@ pub const Value = struct {
11181126 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readPackedInt(u128, buffer, bit_offset, endian))) },
11191127 else => unreachable,
11201128 },
1121 } })).toValue(),
1129 } }))),
11221130 .Vector => {
11231131 const elem_ty = ty.childType(mod);
11241132 const elems = try arena.alloc(InternPool.Index, @as(usize, @intCast(ty.arrayLen(mod))));
......@@ -1131,10 +1139,10 @@ pub const Value = struct {
11311139 elems[tgt_elem_i] = try (try readFromPackedMemory(elem_ty, mod, buffer, bit_offset + bits, arena)).intern(elem_ty, mod);
11321140 bits += elem_bit_size;
11331141 }
1134 return (try mod.intern(.{ .aggregate = .{
1142 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
11351143 .ty = ty.toIntern(),
11361144 .storage = .{ .elems = elems },
1137 } })).toValue();
1145 } })));
11381146 },
11391147 .Struct => {
11401148 // Sema is supposed to have emitted a compile error already for Auto layout structs,
......@@ -1143,26 +1151,26 @@ pub const Value = struct {
11431151 var bits: u16 = 0;
11441152 const field_vals = try arena.alloc(InternPool.Index, struct_type.field_types.len);
11451153 for (field_vals, 0..) |*field_val, i| {
1146 const field_ty = struct_type.field_types.get(ip)[i].toType();
1154 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
11471155 const field_bits: u16 = @intCast(field_ty.bitSize(mod));
11481156 field_val.* = try (try readFromPackedMemory(field_ty, mod, buffer, bit_offset + bits, arena)).intern(field_ty, mod);
11491157 bits += field_bits;
11501158 }
1151 return (try mod.intern(.{ .aggregate = .{
1159 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
11521160 .ty = ty.toIntern(),
11531161 .storage = .{ .elems = field_vals },
1154 } })).toValue();
1162 } })));
11551163 },
11561164 .Union => switch (ty.containerLayout(mod)) {
11571165 .Auto, .Extern => unreachable, // Handled by non-packed readFromMemory
11581166 .Packed => {
11591167 const backing_ty = try ty.unionBackingType(mod);
11601168 const val = (try readFromPackedMemory(backing_ty, mod, buffer, bit_offset, arena)).toIntern();
1161 return (try mod.intern(.{ .un = .{
1169 return Value.fromInterned((try mod.intern(.{ .un = .{
11621170 .ty = ty.toIntern(),
11631171 .tag = .none,
11641172 .val = val,
1165 } })).toValue();
1173 } })));
11661174 },
11671175 },
11681176 .Pointer => {
......@@ -1189,8 +1197,8 @@ pub const Value = struct {
11891197 }
11901198 return @floatFromInt(x);
11911199 },
1192 .lazy_align => |ty| @floatFromInt(ty.toType().abiAlignment(mod).toByteUnits(0)),
1193 .lazy_size => |ty| @floatFromInt(ty.toType().abiSize(mod)),
1200 .lazy_align => |ty| @floatFromInt(Type.fromInterned(ty).abiAlignment(mod).toByteUnits(0)),
1201 .lazy_size => |ty| @floatFromInt(Type.fromInterned(ty).abiSize(mod)),
11941202 },
11951203 .float => |float| switch (float.storage) {
11961204 inline else => |x| @floatCast(x),
......@@ -1283,7 +1291,7 @@ pub const Value = struct {
12831291 /// Caller can find out by equality checking the result against the operand.
12841292 pub fn floatCast(self: Value, dest_ty: Type, mod: *Module) !Value {
12851293 const target = mod.getTarget();
1286 return (try mod.intern(.{ .float = .{
1294 return Value.fromInterned((try mod.intern(.{ .float = .{
12871295 .ty = dest_ty.toIntern(),
12881296 .storage = switch (dest_ty.floatBits(target)) {
12891297 16 => .{ .f16 = self.toFloat(f16, mod) },
......@@ -1293,7 +1301,7 @@ pub const Value = struct {
12931301 128 => .{ .f128 = self.toFloat(f128, mod) },
12941302 else => unreachable,
12951303 },
1296 } })).toValue();
1304 } })));
12971305 }
12981306
12991307 /// Asserts the value is a float
......@@ -1321,8 +1329,8 @@ pub const Value = struct {
13211329 else => switch (mod.intern_pool.indexToKey(lhs.toIntern())) {
13221330 .ptr => |ptr| switch (ptr.addr) {
13231331 .decl, .mut_decl, .comptime_field => .gt,
1324 .int => |int| int.toValue().orderAgainstZeroAdvanced(mod, opt_sema),
1325 .elem => |elem| switch (try elem.base.toValue().orderAgainstZeroAdvanced(mod, opt_sema)) {
1332 .int => |int| Value.fromInterned(int).orderAgainstZeroAdvanced(mod, opt_sema),
1333 .elem => |elem| switch (try Value.fromInterned(elem.base).orderAgainstZeroAdvanced(mod, opt_sema)) {
13261334 .lt => unreachable,
13271335 .gt => .gt,
13281336 .eq => if (elem.index == 0) .eq else .gt,
......@@ -1333,7 +1341,7 @@ pub const Value = struct {
13331341 .big_int => |big_int| big_int.orderAgainstScalar(0),
13341342 inline .u64, .i64 => |x| std.math.order(x, 0),
13351343 .lazy_align => .gt, // alignment is never 0
1336 .lazy_size => |ty| return if (ty.toType().hasRuntimeBitsAdvanced(
1344 .lazy_size => |ty| return if (Type.fromInterned(ty).hasRuntimeBitsAdvanced(
13371345 mod,
13381346 false,
13391347 if (opt_sema) |sema| .{ .sema = sema } else .eager,
......@@ -1342,7 +1350,7 @@ pub const Value = struct {
13421350 else => |e| return e,
13431351 }) .gt else .eq,
13441352 },
1345 .enum_tag => |enum_tag| enum_tag.int.toValue().orderAgainstZeroAdvanced(mod, opt_sema),
1353 .enum_tag => |enum_tag| Value.fromInterned(enum_tag.int).orderAgainstZeroAdvanced(mod, opt_sema),
13461354 .float => |float| switch (float.storage) {
13471355 inline else => |x| std.math.order(x, 0),
13481356 },
......@@ -1494,9 +1502,9 @@ pub const Value = struct {
14941502 if (!std.math.order(byte, 0).compare(op)) break false;
14951503 } else true,
14961504 .elems => |elems| for (elems) |elem| {
1497 if (!try elem.toValue().compareAllWithZeroAdvancedExtra(op, mod, opt_sema)) break false;
1505 if (!try Value.fromInterned(elem).compareAllWithZeroAdvancedExtra(op, mod, opt_sema)) break false;
14981506 } else true,
1499 .repeated_elem => |elem| elem.toValue().compareAllWithZeroAdvancedExtra(op, mod, opt_sema),
1507 .repeated_elem => |elem| Value.fromInterned(elem).compareAllWithZeroAdvancedExtra(op, mod, opt_sema),
15001508 },
15011509 else => {},
15021510 }
......@@ -1513,8 +1521,8 @@ pub const Value = struct {
15131521 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
15141522 .ptr => |ptr| switch (ptr.addr) {
15151523 .mut_decl, .comptime_field => true,
1516 .eu_payload, .opt_payload => |base_ptr| base_ptr.toValue().isComptimeMutablePtr(mod),
1517 .elem, .field => |base_index| base_index.base.toValue().isComptimeMutablePtr(mod),
1524 .eu_payload, .opt_payload => |base_ptr| Value.fromInterned(base_ptr).isComptimeMutablePtr(mod),
1525 .elem, .field => |base_index| Value.fromInterned(base_index.base).isComptimeMutablePtr(mod),
15181526 else => false,
15191527 },
15201528 else => false,
......@@ -1526,20 +1534,20 @@ pub const Value = struct {
15261534 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
15271535 .error_union => |error_union| switch (error_union.val) {
15281536 .err_name => false,
1529 .payload => |payload| payload.toValue().canMutateComptimeVarState(mod),
1537 .payload => |payload| Value.fromInterned(payload).canMutateComptimeVarState(mod),
15301538 },
15311539 .ptr => |ptr| switch (ptr.addr) {
1532 .eu_payload, .opt_payload => |base| base.toValue().canMutateComptimeVarState(mod),
1540 .eu_payload, .opt_payload => |base| Value.fromInterned(base).canMutateComptimeVarState(mod),
15331541 else => false,
15341542 },
15351543 .opt => |opt| switch (opt.val) {
15361544 .none => false,
1537 else => |payload| payload.toValue().canMutateComptimeVarState(mod),
1545 else => |payload| Value.fromInterned(payload).canMutateComptimeVarState(mod),
15381546 },
15391547 .aggregate => |aggregate| for (aggregate.storage.values()) |elem| {
1540 if (elem.toValue().canMutateComptimeVarState(mod)) break true;
1548 if (Value.fromInterned(elem).canMutateComptimeVarState(mod)) break true;
15411549 } else false,
1542 .un => |un| un.val.toValue().canMutateComptimeVarState(mod),
1550 .un => |un| Value.fromInterned(un.val).canMutateComptimeVarState(mod),
15431551 else => false,
15441552 },
15451553 };
......@@ -1566,7 +1574,7 @@ pub const Value = struct {
15661574 pub const slice_len_index = 1;
15671575
15681576 pub fn slicePtr(val: Value, mod: *Module) Value {
1569 return mod.intern_pool.slicePtr(val.toIntern()).toValue();
1577 return Value.fromInterned(mod.intern_pool.slicePtr(val.toIntern()));
15701578 }
15711579
15721580 pub fn sliceLen(val: Value, mod: *Module) u64 {
......@@ -1583,7 +1591,7 @@ pub const Value = struct {
15831591 .array_type => |array_type| array_type.len,
15841592 else => 1,
15851593 },
1586 else => ptr.len.toValue().toUnsignedInt(mod),
1594 else => Value.fromInterned(ptr.len).toUnsignedInt(mod),
15871595 };
15881596 }
15891597
......@@ -1604,37 +1612,36 @@ pub const Value = struct {
16041612 else => null,
16051613 },
16061614 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
1607 .undef => |ty| (try mod.intern(.{
1608 .undef = ty.toType().elemType2(mod).toIntern(),
1609 })).toValue(),
1615 .undef => |ty| Value.fromInterned((try mod.intern(.{
1616 .undef = Type.fromInterned(ty).elemType2(mod).toIntern(),
1617 }))),
16101618 .ptr => |ptr| switch (ptr.addr) {
16111619 .decl => |decl| mod.declPtr(decl).val.maybeElemValue(mod, index),
1612 .anon_decl => |anon_decl| anon_decl.val.toValue().maybeElemValue(mod, index),
1613 .mut_decl => |mut_decl| (try mod.declPtr(mut_decl.decl).internValue(mod))
1614 .toValue().maybeElemValue(mod, index),
1620 .anon_decl => |anon_decl| Value.fromInterned(anon_decl.val).maybeElemValue(mod, index),
1621 .mut_decl => |mut_decl| Value.fromInterned((try mod.declPtr(mut_decl.decl).internValue(mod))).maybeElemValue(mod, index),
16151622 .int, .eu_payload => null,
1616 .opt_payload => |base| base.toValue().maybeElemValue(mod, index),
1617 .comptime_field => |field_val| field_val.toValue().maybeElemValue(mod, index),
1618 .elem => |elem| elem.base.toValue().maybeElemValue(mod, index + @as(usize, @intCast(elem.index))),
1619 .field => |field| if (field.base.toValue().pointerDecl(mod)) |decl_index| {
1623 .opt_payload => |base| Value.fromInterned(base).maybeElemValue(mod, index),
1624 .comptime_field => |field_val| Value.fromInterned(field_val).maybeElemValue(mod, index),
1625 .elem => |elem| Value.fromInterned(elem.base).maybeElemValue(mod, index + @as(usize, @intCast(elem.index))),
1626 .field => |field| if (Value.fromInterned(field.base).pointerDecl(mod)) |decl_index| {
16201627 const base_decl = mod.declPtr(decl_index);
16211628 const field_val = try base_decl.val.fieldValue(mod, @as(usize, @intCast(field.index)));
16221629 return field_val.maybeElemValue(mod, index);
16231630 } else null,
16241631 },
1625 .opt => |opt| opt.val.toValue().maybeElemValue(mod, index),
1632 .opt => |opt| Value.fromInterned(opt.val).maybeElemValue(mod, index),
16261633 .aggregate => |aggregate| {
16271634 const len = mod.intern_pool.aggregateTypeLen(aggregate.ty);
1628 if (index < len) return switch (aggregate.storage) {
1635 if (index < len) return Value.fromInterned(switch (aggregate.storage) {
16291636 .bytes => |bytes| try mod.intern(.{ .int = .{
16301637 .ty = .u8_type,
16311638 .storage = .{ .u64 = bytes[index] },
16321639 } }),
16331640 .elems => |elems| elems[index],
16341641 .repeated_elem => |elem| elem,
1635 }.toValue();
1642 });
16361643 assert(index == len);
1637 return mod.intern_pool.indexToKey(aggregate.ty).array_type.sentinel.toValue();
1644 return Value.fromInterned(mod.intern_pool.indexToKey(aggregate.ty).array_type.sentinel);
16381645 },
16391646 else => null,
16401647 },
......@@ -1681,15 +1688,15 @@ pub const Value = struct {
16811688 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
16821689 .ptr => |ptr| switch (ptr.addr) {
16831690 .decl => |decl| try mod.declPtr(decl).val.sliceArray(mod, arena, start, end),
1684 .mut_decl => |mut_decl| (try mod.declPtr(mut_decl.decl).internValue(mod)).toValue()
1691 .mut_decl => |mut_decl| Value.fromInterned((try mod.declPtr(mut_decl.decl).internValue(mod)))
16851692 .sliceArray(mod, arena, start, end),
1686 .comptime_field => |comptime_field| comptime_field.toValue()
1693 .comptime_field => |comptime_field| Value.fromInterned(comptime_field)
16871694 .sliceArray(mod, arena, start, end),
1688 .elem => |elem| elem.base.toValue()
1695 .elem => |elem| Value.fromInterned(elem.base)
16891696 .sliceArray(mod, arena, start + @as(usize, @intCast(elem.index)), end + @as(usize, @intCast(elem.index))),
16901697 else => unreachable,
16911698 },
1692 .aggregate => |aggregate| (try mod.intern(.{ .aggregate = .{
1699 .aggregate => |aggregate| Value.fromInterned((try mod.intern(.{ .aggregate = .{
16931700 .ty = switch (mod.intern_pool.indexToKey(mod.intern_pool.typeOf(val.toIntern()))) {
16941701 .array_type => |array_type| try mod.arrayType(.{
16951702 .len = @as(u32, @intCast(end - start)),
......@@ -1707,7 +1714,7 @@ pub const Value = struct {
17071714 .elems => .{ .elems = try arena.dupe(InternPool.Index, mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage.elems[start..end]) },
17081715 .repeated_elem => |elem| .{ .repeated_elem = elem },
17091716 },
1710 } })).toValue(),
1717 } }))),
17111718 else => unreachable,
17121719 },
17131720 };
......@@ -1728,19 +1735,19 @@ pub const Value = struct {
17281735 else => unreachable,
17291736 },
17301737 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
1731 .undef => |ty| (try mod.intern(.{
1732 .undef = ty.toType().structFieldType(index, mod).toIntern(),
1733 })).toValue(),
1734 .aggregate => |aggregate| switch (aggregate.storage) {
1738 .undef => |ty| Value.fromInterned((try mod.intern(.{
1739 .undef = Type.fromInterned(ty).structFieldType(index, mod).toIntern(),
1740 }))),
1741 .aggregate => |aggregate| Value.fromInterned(switch (aggregate.storage) {
17351742 .bytes => |bytes| try mod.intern(.{ .int = .{
17361743 .ty = .u8_type,
17371744 .storage = .{ .u64 = bytes[index] },
17381745 } }),
17391746 .elems => |elems| elems[index],
17401747 .repeated_elem => |elem| elem,
1741 }.toValue(),
1748 }),
17421749 // TODO assert the tag is correct
1743 .un => |un| un.val.toValue(),
1750 .un => |un| Value.fromInterned(un.val),
17441751 else => unreachable,
17451752 },
17461753 };
......@@ -1750,7 +1757,7 @@ pub const Value = struct {
17501757 if (val.ip_index == .none) return val.castTag(.@"union").?.data.tag;
17511758 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
17521759 .undef, .enum_tag => val,
1753 .un => |un| if (un.tag != .none) un.tag.toValue() else return null,
1760 .un => |un| if (un.tag != .none) Value.fromInterned(un.tag) else return null,
17541761 else => unreachable,
17551762 };
17561763 }
......@@ -1758,7 +1765,7 @@ pub const Value = struct {
17581765 pub fn unionValue(val: Value, mod: *Module) Value {
17591766 if (val.ip_index == .none) return val.castTag(.@"union").?.data.val;
17601767 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1761 .un => |un| un.val.toValue(),
1768 .un => |un| Value.fromInterned(un.val),
17621769 else => unreachable,
17631770 };
17641771 }
......@@ -1774,14 +1781,14 @@ pub const Value = struct {
17741781 const ptr_val = switch (mod.intern_pool.indexToKey(val.toIntern())) {
17751782 .ptr => |ptr| ptr: {
17761783 switch (ptr.addr) {
1777 .elem => |elem| if (mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).eql(elem_ty, mod))
1778 return (try mod.intern(.{ .ptr = .{
1784 .elem => |elem| if (Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod).eql(elem_ty, mod))
1785 return Value.fromInterned((try mod.intern(.{ .ptr = .{
17791786 .ty = elem_ptr_ty.toIntern(),
17801787 .addr = .{ .elem = .{
17811788 .base = elem.base,
17821789 .index = elem.index + index,
17831790 } },
1784 } })).toValue(),
1791 } }))),
17851792 else => {},
17861793 }
17871794 break :ptr switch (ptr.len) {
......@@ -1794,13 +1801,13 @@ pub const Value = struct {
17941801 var ptr_ty_key = mod.intern_pool.indexToKey(elem_ptr_ty.toIntern()).ptr_type;
17951802 assert(ptr_ty_key.flags.size != .Slice);
17961803 ptr_ty_key.flags.size = .Many;
1797 return (try mod.intern(.{ .ptr = .{
1804 return Value.fromInterned((try mod.intern(.{ .ptr = .{
17981805 .ty = elem_ptr_ty.toIntern(),
17991806 .addr = .{ .elem = .{
18001807 .base = (try mod.getCoerced(ptr_val, try mod.ptrType(ptr_ty_key))).toIntern(),
18011808 .index = index,
18021809 } },
1803 } })).toValue();
1810 } })));
18041811 }
18051812
18061813 pub fn isUndef(val: Value, mod: *Module) bool {
......@@ -1824,13 +1831,13 @@ pub const Value = struct {
18241831 .simple_value => |v| v == .undefined,
18251832 .ptr => |ptr| switch (ptr.len) {
18261833 .none => false,
1827 else => for (0..@as(usize, @intCast(ptr.len.toValue().toUnsignedInt(mod)))) |index| {
1834 else => for (0..@as(usize, @intCast(Value.fromInterned(ptr.len).toUnsignedInt(mod)))) |index| {
18281835 if (try (try val.elemValue(mod, index)).anyUndef(mod)) break true;
18291836 } else false,
18301837 },
18311838 .aggregate => |aggregate| for (0..aggregate.storage.values().len) |i| {
18321839 const elem = mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage.values()[i];
1833 if (try anyUndef(elem.toValue(), mod)) break true;
1840 if (try anyUndef(Value.fromInterned(elem), mod)) break true;
18341841 } else false,
18351842 else => false,
18361843 },
......@@ -1889,7 +1896,7 @@ pub const Value = struct {
18891896 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
18901897 .opt => |opt| switch (opt.val) {
18911898 .none => null,
1892 else => |payload| payload.toValue(),
1899 else => |payload| Value.fromInterned(payload),
18931900 },
18941901 .ptr => val,
18951902 else => unreachable,
......@@ -1923,10 +1930,10 @@ pub const Value = struct {
19231930 const elem_val = try val.elemValue(mod, i);
19241931 scalar.* = try (try floatFromIntScalar(elem_val, scalar_ty, mod, opt_sema)).intern(scalar_ty, mod);
19251932 }
1926 return (try mod.intern(.{ .aggregate = .{
1933 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
19271934 .ty = float_ty.toIntern(),
19281935 .storage = .{ .elems = result_data },
1929 } })).toValue();
1936 } })));
19301937 }
19311938 return floatFromIntScalar(val, float_ty, mod, opt_sema);
19321939 }
......@@ -1941,14 +1948,14 @@ pub const Value = struct {
19411948 },
19421949 inline .u64, .i64 => |x| floatFromIntInner(x, float_ty, mod),
19431950 .lazy_align => |ty| if (opt_sema) |sema| {
1944 return floatFromIntInner((try ty.toType().abiAlignmentAdvanced(mod, .{ .sema = sema })).scalar.toByteUnits(0), float_ty, mod);
1951 return floatFromIntInner((try Type.fromInterned(ty).abiAlignmentAdvanced(mod, .{ .sema = sema })).scalar.toByteUnits(0), float_ty, mod);
19451952 } else {
1946 return floatFromIntInner(ty.toType().abiAlignment(mod).toByteUnits(0), float_ty, mod);
1953 return floatFromIntInner(Type.fromInterned(ty).abiAlignment(mod).toByteUnits(0), float_ty, mod);
19471954 },
19481955 .lazy_size => |ty| if (opt_sema) |sema| {
1949 return floatFromIntInner((try ty.toType().abiSizeAdvanced(mod, .{ .sema = sema })).scalar, float_ty, mod);
1956 return floatFromIntInner((try Type.fromInterned(ty).abiSizeAdvanced(mod, .{ .sema = sema })).scalar, float_ty, mod);
19501957 } else {
1951 return floatFromIntInner(ty.toType().abiSize(mod), float_ty, mod);
1958 return floatFromIntInner(Type.fromInterned(ty).abiSize(mod), float_ty, mod);
19521959 },
19531960 },
19541961 else => unreachable,
......@@ -1965,10 +1972,10 @@ pub const Value = struct {
19651972 128 => .{ .f128 = @floatFromInt(x) },
19661973 else => unreachable,
19671974 };
1968 return (try mod.intern(.{ .float = .{
1975 return Value.fromInterned((try mod.intern(.{ .float = .{
19691976 .ty = dest_ty.toIntern(),
19701977 .storage = storage,
1971 } })).toValue();
1978 } })));
19721979 }
19731980
19741981 fn calcLimbLenFloat(scalar: anytype) usize {
......@@ -2001,10 +2008,10 @@ pub const Value = struct {
20012008 const rhs_elem = try rhs.elemValue(mod, i);
20022009 scalar.* = try (try intAddSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
20032010 }
2004 return (try mod.intern(.{ .aggregate = .{
2011 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
20052012 .ty = ty.toIntern(),
20062013 .storage = .{ .elems = result_data },
2007 } })).toValue();
2014 } })));
20082015 }
20092016 return intAddSatScalar(lhs, rhs, ty, arena, mod);
20102017 }
......@@ -2051,10 +2058,10 @@ pub const Value = struct {
20512058 const rhs_elem = try rhs.elemValue(mod, i);
20522059 scalar.* = try (try intSubSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
20532060 }
2054 return (try mod.intern(.{ .aggregate = .{
2061 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
20552062 .ty = ty.toIntern(),
20562063 .storage = .{ .elems = result_data },
2057 } })).toValue();
2064 } })));
20582065 }
20592066 return intSubSatScalar(lhs, rhs, ty, arena, mod);
20602067 }
......@@ -2105,14 +2112,14 @@ pub const Value = struct {
21052112 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
21062113 }
21072114 return OverflowArithmeticResult{
2108 .overflow_bit = (try mod.intern(.{ .aggregate = .{
2115 .overflow_bit = Value.fromInterned((try mod.intern(.{ .aggregate = .{
21092116 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),
21102117 .storage = .{ .elems = overflowed_data },
2111 } })).toValue(),
2112 .wrapped_result = (try mod.intern(.{ .aggregate = .{
2118 } }))),
2119 .wrapped_result = Value.fromInterned((try mod.intern(.{ .aggregate = .{
21132120 .ty = ty.toIntern(),
21142121 .storage = .{ .elems = result_data },
2115 } })).toValue(),
2122 } }))),
21162123 };
21172124 }
21182125 return intMulWithOverflowScalar(lhs, rhs, ty, arena, mod);
......@@ -2169,10 +2176,10 @@ pub const Value = struct {
21692176 const rhs_elem = try rhs.elemValue(mod, i);
21702177 scalar.* = try (try numberMulWrapScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
21712178 }
2172 return (try mod.intern(.{ .aggregate = .{
2179 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
21732180 .ty = ty.toIntern(),
21742181 .storage = .{ .elems = result_data },
2175 } })).toValue();
2182 } })));
21762183 }
21772184 return numberMulWrapScalar(lhs, rhs, ty, arena, mod);
21782185 }
......@@ -2215,10 +2222,10 @@ pub const Value = struct {
22152222 const rhs_elem = try rhs.elemValue(mod, i);
22162223 scalar.* = try (try intMulSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
22172224 }
2218 return (try mod.intern(.{ .aggregate = .{
2225 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
22192226 .ty = ty.toIntern(),
22202227 .storage = .{ .elems = result_data },
2221 } })).toValue();
2228 } })));
22222229 }
22232230 return intMulSatScalar(lhs, rhs, ty, arena, mod);
22242231 }
......@@ -2291,17 +2298,17 @@ pub const Value = struct {
22912298 const elem_val = try val.elemValue(mod, i);
22922299 scalar.* = try (try bitwiseNotScalar(elem_val, scalar_ty, arena, mod)).intern(scalar_ty, mod);
22932300 }
2294 return (try mod.intern(.{ .aggregate = .{
2301 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
22952302 .ty = ty.toIntern(),
22962303 .storage = .{ .elems = result_data },
2297 } })).toValue();
2304 } })));
22982305 }
22992306 return bitwiseNotScalar(val, ty, arena, mod);
23002307 }
23012308
23022309 /// operands must be integers; handles undefined.
23032310 pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
2304 if (val.isUndef(mod)) return (try mod.intern(.{ .undef = ty.toIntern() })).toValue();
2311 if (val.isUndef(mod)) return Value.fromInterned((try mod.intern(.{ .undef = ty.toIntern() })));
23052312 if (ty.toIntern() == .bool_type) return makeBool(!val.toBool());
23062313
23072314 const info = ty.intInfo(mod);
......@@ -2334,17 +2341,17 @@ pub const Value = struct {
23342341 const rhs_elem = try rhs.elemValue(mod, i);
23352342 scalar.* = try (try bitwiseAndScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
23362343 }
2337 return (try mod.intern(.{ .aggregate = .{
2344 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
23382345 .ty = ty.toIntern(),
23392346 .storage = .{ .elems = result_data },
2340 } })).toValue();
2347 } })));
23412348 }
23422349 return bitwiseAndScalar(lhs, rhs, ty, allocator, mod);
23432350 }
23442351
23452352 /// operands must be integers; handles undefined.
23462353 pub fn bitwiseAndScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
2347 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return (try mod.intern(.{ .undef = ty.toIntern() })).toValue();
2354 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.fromInterned((try mod.intern(.{ .undef = ty.toIntern() })));
23482355 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() and rhs.toBool());
23492356
23502357 // TODO is this a performance issue? maybe we should try the operation without
......@@ -2373,17 +2380,17 @@ pub const Value = struct {
23732380 const rhs_elem = try rhs.elemValue(mod, i);
23742381 scalar.* = try (try bitwiseNandScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
23752382 }
2376 return (try mod.intern(.{ .aggregate = .{
2383 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
23772384 .ty = ty.toIntern(),
23782385 .storage = .{ .elems = result_data },
2379 } })).toValue();
2386 } })));
23802387 }
23812388 return bitwiseNandScalar(lhs, rhs, ty, arena, mod);
23822389 }
23832390
23842391 /// operands must be integers; handles undefined.
23852392 pub fn bitwiseNandScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
2386 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return (try mod.intern(.{ .undef = ty.toIntern() })).toValue();
2393 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.fromInterned((try mod.intern(.{ .undef = ty.toIntern() })));
23872394 if (ty.toIntern() == .bool_type) return makeBool(!(lhs.toBool() and rhs.toBool()));
23882395
23892396 const anded = try bitwiseAnd(lhs, rhs, ty, arena, mod);
......@@ -2401,17 +2408,17 @@ pub const Value = struct {
24012408 const rhs_elem = try rhs.elemValue(mod, i);
24022409 scalar.* = try (try bitwiseOrScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
24032410 }
2404 return (try mod.intern(.{ .aggregate = .{
2411 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
24052412 .ty = ty.toIntern(),
24062413 .storage = .{ .elems = result_data },
2407 } })).toValue();
2414 } })));
24082415 }
24092416 return bitwiseOrScalar(lhs, rhs, ty, allocator, mod);
24102417 }
24112418
24122419 /// operands must be integers; handles undefined.
24132420 pub fn bitwiseOrScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
2414 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return (try mod.intern(.{ .undef = ty.toIntern() })).toValue();
2421 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.fromInterned((try mod.intern(.{ .undef = ty.toIntern() })));
24152422 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() or rhs.toBool());
24162423
24172424 // TODO is this a performance issue? maybe we should try the operation without
......@@ -2439,17 +2446,17 @@ pub const Value = struct {
24392446 const rhs_elem = try rhs.elemValue(mod, i);
24402447 scalar.* = try (try bitwiseXorScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
24412448 }
2442 return (try mod.intern(.{ .aggregate = .{
2449 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
24432450 .ty = ty.toIntern(),
24442451 .storage = .{ .elems = result_data },
2445 } })).toValue();
2452 } })));
24462453 }
24472454 return bitwiseXorScalar(lhs, rhs, ty, allocator, mod);
24482455 }
24492456
24502457 /// operands must be integers; handles undefined.
24512458 pub fn bitwiseXorScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
2452 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return (try mod.intern(.{ .undef = ty.toIntern() })).toValue();
2459 if (lhs.isUndef(mod) or rhs.isUndef(mod)) return Value.fromInterned((try mod.intern(.{ .undef = ty.toIntern() })));
24532460 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() != rhs.toBool());
24542461
24552462 // TODO is this a performance issue? maybe we should try the operation without
......@@ -2505,10 +2512,10 @@ pub const Value = struct {
25052512 };
25062513 scalar.* = try val.intern(scalar_ty, mod);
25072514 }
2508 return (try mod.intern(.{ .aggregate = .{
2515 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
25092516 .ty = ty.toIntern(),
25102517 .storage = .{ .elems = result_data },
2511 } })).toValue();
2518 } })));
25122519 }
25132520 return intDivScalar(lhs, rhs, ty, allocator, mod);
25142521 }
......@@ -2553,10 +2560,10 @@ pub const Value = struct {
25532560 const rhs_elem = try rhs.elemValue(mod, i);
25542561 scalar.* = try (try intDivFloorScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
25552562 }
2556 return (try mod.intern(.{ .aggregate = .{
2563 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
25572564 .ty = ty.toIntern(),
25582565 .storage = .{ .elems = result_data },
2559 } })).toValue();
2566 } })));
25602567 }
25612568 return intDivFloorScalar(lhs, rhs, ty, allocator, mod);
25622569 }
......@@ -2595,10 +2602,10 @@ pub const Value = struct {
25952602 const rhs_elem = try rhs.elemValue(mod, i);
25962603 scalar.* = try (try intModScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
25972604 }
2598 return (try mod.intern(.{ .aggregate = .{
2605 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
25992606 .ty = ty.toIntern(),
26002607 .storage = .{ .elems = result_data },
2601 } })).toValue();
2608 } })));
26022609 }
26032610 return intModScalar(lhs, rhs, ty, allocator, mod);
26042611 }
......@@ -2669,10 +2676,10 @@ pub const Value = struct {
26692676 const rhs_elem = try rhs.elemValue(mod, i);
26702677 scalar.* = try (try floatRemScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
26712678 }
2672 return (try mod.intern(.{ .aggregate = .{
2679 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
26732680 .ty = float_type.toIntern(),
26742681 .storage = .{ .elems = result_data },
2675 } })).toValue();
2682 } })));
26762683 }
26772684 return floatRemScalar(lhs, rhs, float_type, mod);
26782685 }
......@@ -2687,10 +2694,10 @@ pub const Value = struct {
26872694 128 => .{ .f128 = @rem(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },
26882695 else => unreachable,
26892696 };
2690 return (try mod.intern(.{ .float = .{
2697 return Value.fromInterned((try mod.intern(.{ .float = .{
26912698 .ty = float_type.toIntern(),
26922699 .storage = storage,
2693 } })).toValue();
2700 } })));
26942701 }
26952702
26962703 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -2702,10 +2709,10 @@ pub const Value = struct {
27022709 const rhs_elem = try rhs.elemValue(mod, i);
27032710 scalar.* = try (try floatModScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
27042711 }
2705 return (try mod.intern(.{ .aggregate = .{
2712 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
27062713 .ty = float_type.toIntern(),
27072714 .storage = .{ .elems = result_data },
2708 } })).toValue();
2715 } })));
27092716 }
27102717 return floatModScalar(lhs, rhs, float_type, mod);
27112718 }
......@@ -2720,10 +2727,10 @@ pub const Value = struct {
27202727 128 => .{ .f128 = @mod(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },
27212728 else => unreachable,
27222729 };
2723 return (try mod.intern(.{ .float = .{
2730 return Value.fromInterned((try mod.intern(.{ .float = .{
27242731 .ty = float_type.toIntern(),
27252732 .storage = storage,
2726 } })).toValue();
2733 } })));
27272734 }
27282735
27292736 /// If the value overflowed the type, returns a comptime_int (or vector thereof) instead, setting
......@@ -2763,10 +2770,10 @@ pub const Value = struct {
27632770 };
27642771 scalar.* = try val.intern(scalar_ty, mod);
27652772 }
2766 return (try mod.intern(.{ .aggregate = .{
2773 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
27672774 .ty = ty.toIntern(),
27682775 .storage = .{ .elems = result_data },
2769 } })).toValue();
2776 } })));
27702777 }
27712778 return intMulScalar(lhs, rhs, ty, allocator, mod);
27722779 }
......@@ -2805,10 +2812,10 @@ pub const Value = struct {
28052812 const elem_val = try val.elemValue(mod, i);
28062813 scalar.* = try (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, bits, mod)).intern(scalar_ty, mod);
28072814 }
2808 return (try mod.intern(.{ .aggregate = .{
2815 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
28092816 .ty = ty.toIntern(),
28102817 .storage = .{ .elems = result_data },
2811 } })).toValue();
2818 } })));
28122819 }
28132820 return intTruncScalar(val, ty, allocator, signedness, bits, mod);
28142821 }
......@@ -2830,10 +2837,10 @@ pub const Value = struct {
28302837 const bits_elem = try bits.elemValue(mod, i);
28312838 scalar.* = try (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @as(u16, @intCast(bits_elem.toUnsignedInt(mod))), mod)).intern(scalar_ty, mod);
28322839 }
2833 return (try mod.intern(.{ .aggregate = .{
2840 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
28342841 .ty = ty.toIntern(),
28352842 .storage = .{ .elems = result_data },
2836 } })).toValue();
2843 } })));
28372844 }
28382845 return intTruncScalar(val, ty, allocator, signedness, @as(u16, @intCast(bits.toUnsignedInt(mod))), mod);
28392846 }
......@@ -2870,10 +2877,10 @@ pub const Value = struct {
28702877 const rhs_elem = try rhs.elemValue(mod, i);
28712878 scalar.* = try (try shlScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
28722879 }
2873 return (try mod.intern(.{ .aggregate = .{
2880 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
28742881 .ty = ty.toIntern(),
28752882 .storage = .{ .elems = result_data },
2876 } })).toValue();
2883 } })));
28772884 }
28782885 return shlScalar(lhs, rhs, ty, allocator, mod);
28792886 }
......@@ -2922,14 +2929,14 @@ pub const Value = struct {
29222929 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
29232930 }
29242931 return OverflowArithmeticResult{
2925 .overflow_bit = (try mod.intern(.{ .aggregate = .{
2932 .overflow_bit = Value.fromInterned((try mod.intern(.{ .aggregate = .{
29262933 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),
29272934 .storage = .{ .elems = overflowed_data },
2928 } })).toValue(),
2929 .wrapped_result = (try mod.intern(.{ .aggregate = .{
2935 } }))),
2936 .wrapped_result = Value.fromInterned((try mod.intern(.{ .aggregate = .{
29302937 .ty = ty.toIntern(),
29312938 .storage = .{ .elems = result_data },
2932 } })).toValue(),
2939 } }))),
29332940 };
29342941 }
29352942 return shlWithOverflowScalar(lhs, rhs, ty, allocator, mod);
......@@ -2981,10 +2988,10 @@ pub const Value = struct {
29812988 const rhs_elem = try rhs.elemValue(mod, i);
29822989 scalar.* = try (try shlSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
29832990 }
2984 return (try mod.intern(.{ .aggregate = .{
2991 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
29852992 .ty = ty.toIntern(),
29862993 .storage = .{ .elems = result_data },
2987 } })).toValue();
2994 } })));
29882995 }
29892996 return shlSatScalar(lhs, rhs, ty, arena, mod);
29902997 }
......@@ -3031,10 +3038,10 @@ pub const Value = struct {
30313038 const rhs_elem = try rhs.elemValue(mod, i);
30323039 scalar.* = try (try shlTruncScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
30333040 }
3034 return (try mod.intern(.{ .aggregate = .{
3041 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
30353042 .ty = ty.toIntern(),
30363043 .storage = .{ .elems = result_data },
3037 } })).toValue();
3044 } })));
30383045 }
30393046 return shlTruncScalar(lhs, rhs, ty, arena, mod);
30403047 }
......@@ -3061,10 +3068,10 @@ pub const Value = struct {
30613068 const rhs_elem = try rhs.elemValue(mod, i);
30623069 scalar.* = try (try shrScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
30633070 }
3064 return (try mod.intern(.{ .aggregate = .{
3071 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
30653072 .ty = ty.toIntern(),
30663073 .storage = .{ .elems = result_data },
3067 } })).toValue();
3074 } })));
30683075 }
30693076 return shrScalar(lhs, rhs, ty, allocator, mod);
30703077 }
......@@ -3113,10 +3120,10 @@ pub const Value = struct {
31133120 const elem_val = try val.elemValue(mod, i);
31143121 scalar.* = try (try floatNegScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
31153122 }
3116 return (try mod.intern(.{ .aggregate = .{
3123 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
31173124 .ty = float_type.toIntern(),
31183125 .storage = .{ .elems = result_data },
3119 } })).toValue();
3126 } })));
31203127 }
31213128 return floatNegScalar(val, float_type, mod);
31223129 }
......@@ -3135,10 +3142,10 @@ pub const Value = struct {
31353142 128 => .{ .f128 = -val.toFloat(f128, mod) },
31363143 else => unreachable,
31373144 };
3138 return (try mod.intern(.{ .float = .{
3145 return Value.fromInterned((try mod.intern(.{ .float = .{
31393146 .ty = float_type.toIntern(),
31403147 .storage = storage,
3141 } })).toValue();
3148 } })));
31423149 }
31433150
31443151 pub fn floatAdd(
......@@ -3156,10 +3163,10 @@ pub const Value = struct {
31563163 const rhs_elem = try rhs.elemValue(mod, i);
31573164 scalar.* = try (try floatAddScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
31583165 }
3159 return (try mod.intern(.{ .aggregate = .{
3166 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
31603167 .ty = float_type.toIntern(),
31613168 .storage = .{ .elems = result_data },
3162 } })).toValue();
3169 } })));
31633170 }
31643171 return floatAddScalar(lhs, rhs, float_type, mod);
31653172 }
......@@ -3179,10 +3186,10 @@ pub const Value = struct {
31793186 128 => .{ .f128 = lhs.toFloat(f128, mod) + rhs.toFloat(f128, mod) },
31803187 else => unreachable,
31813188 };
3182 return (try mod.intern(.{ .float = .{
3189 return Value.fromInterned((try mod.intern(.{ .float = .{
31833190 .ty = float_type.toIntern(),
31843191 .storage = storage,
3185 } })).toValue();
3192 } })));
31863193 }
31873194
31883195 pub fn floatSub(
......@@ -3200,10 +3207,10 @@ pub const Value = struct {
32003207 const rhs_elem = try rhs.elemValue(mod, i);
32013208 scalar.* = try (try floatSubScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
32023209 }
3203 return (try mod.intern(.{ .aggregate = .{
3210 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
32043211 .ty = float_type.toIntern(),
32053212 .storage = .{ .elems = result_data },
3206 } })).toValue();
3213 } })));
32073214 }
32083215 return floatSubScalar(lhs, rhs, float_type, mod);
32093216 }
......@@ -3223,10 +3230,10 @@ pub const Value = struct {
32233230 128 => .{ .f128 = lhs.toFloat(f128, mod) - rhs.toFloat(f128, mod) },
32243231 else => unreachable,
32253232 };
3226 return (try mod.intern(.{ .float = .{
3233 return Value.fromInterned((try mod.intern(.{ .float = .{
32273234 .ty = float_type.toIntern(),
32283235 .storage = storage,
3229 } })).toValue();
3236 } })));
32303237 }
32313238
32323239 pub fn floatDiv(
......@@ -3244,10 +3251,10 @@ pub const Value = struct {
32443251 const rhs_elem = try rhs.elemValue(mod, i);
32453252 scalar.* = try (try floatDivScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
32463253 }
3247 return (try mod.intern(.{ .aggregate = .{
3254 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
32483255 .ty = float_type.toIntern(),
32493256 .storage = .{ .elems = result_data },
3250 } })).toValue();
3257 } })));
32513258 }
32523259 return floatDivScalar(lhs, rhs, float_type, mod);
32533260 }
......@@ -3267,10 +3274,10 @@ pub const Value = struct {
32673274 128 => .{ .f128 = lhs.toFloat(f128, mod) / rhs.toFloat(f128, mod) },
32683275 else => unreachable,
32693276 };
3270 return (try mod.intern(.{ .float = .{
3277 return Value.fromInterned((try mod.intern(.{ .float = .{
32713278 .ty = float_type.toIntern(),
32723279 .storage = storage,
3273 } })).toValue();
3280 } })));
32743281 }
32753282
32763283 pub fn floatDivFloor(
......@@ -3288,10 +3295,10 @@ pub const Value = struct {
32883295 const rhs_elem = try rhs.elemValue(mod, i);
32893296 scalar.* = try (try floatDivFloorScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
32903297 }
3291 return (try mod.intern(.{ .aggregate = .{
3298 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
32923299 .ty = float_type.toIntern(),
32933300 .storage = .{ .elems = result_data },
3294 } })).toValue();
3301 } })));
32953302 }
32963303 return floatDivFloorScalar(lhs, rhs, float_type, mod);
32973304 }
......@@ -3311,10 +3318,10 @@ pub const Value = struct {
33113318 128 => .{ .f128 = @divFloor(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },
33123319 else => unreachable,
33133320 };
3314 return (try mod.intern(.{ .float = .{
3321 return Value.fromInterned((try mod.intern(.{ .float = .{
33153322 .ty = float_type.toIntern(),
33163323 .storage = storage,
3317 } })).toValue();
3324 } })));
33183325 }
33193326
33203327 pub fn floatDivTrunc(
......@@ -3332,10 +3339,10 @@ pub const Value = struct {
33323339 const rhs_elem = try rhs.elemValue(mod, i);
33333340 scalar.* = try (try floatDivTruncScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
33343341 }
3335 return (try mod.intern(.{ .aggregate = .{
3342 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
33363343 .ty = float_type.toIntern(),
33373344 .storage = .{ .elems = result_data },
3338 } })).toValue();
3345 } })));
33393346 }
33403347 return floatDivTruncScalar(lhs, rhs, float_type, mod);
33413348 }
......@@ -3355,10 +3362,10 @@ pub const Value = struct {
33553362 128 => .{ .f128 = @divTrunc(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },
33563363 else => unreachable,
33573364 };
3358 return (try mod.intern(.{ .float = .{
3365 return Value.fromInterned((try mod.intern(.{ .float = .{
33593366 .ty = float_type.toIntern(),
33603367 .storage = storage,
3361 } })).toValue();
3368 } })));
33623369 }
33633370
33643371 pub fn floatMul(
......@@ -3376,10 +3383,10 @@ pub const Value = struct {
33763383 const rhs_elem = try rhs.elemValue(mod, i);
33773384 scalar.* = try (try floatMulScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
33783385 }
3379 return (try mod.intern(.{ .aggregate = .{
3386 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
33803387 .ty = float_type.toIntern(),
33813388 .storage = .{ .elems = result_data },
3382 } })).toValue();
3389 } })));
33833390 }
33843391 return floatMulScalar(lhs, rhs, float_type, mod);
33853392 }
......@@ -3399,10 +3406,10 @@ pub const Value = struct {
33993406 128 => .{ .f128 = lhs.toFloat(f128, mod) * rhs.toFloat(f128, mod) },
34003407 else => unreachable,
34013408 };
3402 return (try mod.intern(.{ .float = .{
3409 return Value.fromInterned((try mod.intern(.{ .float = .{
34033410 .ty = float_type.toIntern(),
34043411 .storage = storage,
3405 } })).toValue();
3412 } })));
34063413 }
34073414
34083415 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3413,10 +3420,10 @@ pub const Value = struct {
34133420 const elem_val = try val.elemValue(mod, i);
34143421 scalar.* = try (try sqrtScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
34153422 }
3416 return (try mod.intern(.{ .aggregate = .{
3423 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
34173424 .ty = float_type.toIntern(),
34183425 .storage = .{ .elems = result_data },
3419 } })).toValue();
3426 } })));
34203427 }
34213428 return sqrtScalar(val, float_type, mod);
34223429 }
......@@ -3431,10 +3438,10 @@ pub const Value = struct {
34313438 128 => .{ .f128 = @sqrt(val.toFloat(f128, mod)) },
34323439 else => unreachable,
34333440 };
3434 return (try mod.intern(.{ .float = .{
3441 return Value.fromInterned((try mod.intern(.{ .float = .{
34353442 .ty = float_type.toIntern(),
34363443 .storage = storage,
3437 } })).toValue();
3444 } })));
34383445 }
34393446
34403447 pub fn sin(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3445,10 +3452,10 @@ pub const Value = struct {
34453452 const elem_val = try val.elemValue(mod, i);
34463453 scalar.* = try (try sinScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
34473454 }
3448 return (try mod.intern(.{ .aggregate = .{
3455 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
34493456 .ty = float_type.toIntern(),
34503457 .storage = .{ .elems = result_data },
3451 } })).toValue();
3458 } })));
34523459 }
34533460 return sinScalar(val, float_type, mod);
34543461 }
......@@ -3463,10 +3470,10 @@ pub const Value = struct {
34633470 128 => .{ .f128 = @sin(val.toFloat(f128, mod)) },
34643471 else => unreachable,
34653472 };
3466 return (try mod.intern(.{ .float = .{
3473 return Value.fromInterned((try mod.intern(.{ .float = .{
34673474 .ty = float_type.toIntern(),
34683475 .storage = storage,
3469 } })).toValue();
3476 } })));
34703477 }
34713478
34723479 pub fn cos(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3477,10 +3484,10 @@ pub const Value = struct {
34773484 const elem_val = try val.elemValue(mod, i);
34783485 scalar.* = try (try cosScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
34793486 }
3480 return (try mod.intern(.{ .aggregate = .{
3487 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
34813488 .ty = float_type.toIntern(),
34823489 .storage = .{ .elems = result_data },
3483 } })).toValue();
3490 } })));
34843491 }
34853492 return cosScalar(val, float_type, mod);
34863493 }
......@@ -3495,10 +3502,10 @@ pub const Value = struct {
34953502 128 => .{ .f128 = @cos(val.toFloat(f128, mod)) },
34963503 else => unreachable,
34973504 };
3498 return (try mod.intern(.{ .float = .{
3505 return Value.fromInterned((try mod.intern(.{ .float = .{
34993506 .ty = float_type.toIntern(),
35003507 .storage = storage,
3501 } })).toValue();
3508 } })));
35023509 }
35033510
35043511 pub fn tan(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3509,10 +3516,10 @@ pub const Value = struct {
35093516 const elem_val = try val.elemValue(mod, i);
35103517 scalar.* = try (try tanScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
35113518 }
3512 return (try mod.intern(.{ .aggregate = .{
3519 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
35133520 .ty = float_type.toIntern(),
35143521 .storage = .{ .elems = result_data },
3515 } })).toValue();
3522 } })));
35163523 }
35173524 return tanScalar(val, float_type, mod);
35183525 }
......@@ -3527,10 +3534,10 @@ pub const Value = struct {
35273534 128 => .{ .f128 = @tan(val.toFloat(f128, mod)) },
35283535 else => unreachable,
35293536 };
3530 return (try mod.intern(.{ .float = .{
3537 return Value.fromInterned((try mod.intern(.{ .float = .{
35313538 .ty = float_type.toIntern(),
35323539 .storage = storage,
3533 } })).toValue();
3540 } })));
35343541 }
35353542
35363543 pub fn exp(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3541,10 +3548,10 @@ pub const Value = struct {
35413548 const elem_val = try val.elemValue(mod, i);
35423549 scalar.* = try (try expScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
35433550 }
3544 return (try mod.intern(.{ .aggregate = .{
3551 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
35453552 .ty = float_type.toIntern(),
35463553 .storage = .{ .elems = result_data },
3547 } })).toValue();
3554 } })));
35483555 }
35493556 return expScalar(val, float_type, mod);
35503557 }
......@@ -3559,10 +3566,10 @@ pub const Value = struct {
35593566 128 => .{ .f128 = @exp(val.toFloat(f128, mod)) },
35603567 else => unreachable,
35613568 };
3562 return (try mod.intern(.{ .float = .{
3569 return Value.fromInterned((try mod.intern(.{ .float = .{
35633570 .ty = float_type.toIntern(),
35643571 .storage = storage,
3565 } })).toValue();
3572 } })));
35663573 }
35673574
35683575 pub fn exp2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3573,10 +3580,10 @@ pub const Value = struct {
35733580 const elem_val = try val.elemValue(mod, i);
35743581 scalar.* = try (try exp2Scalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
35753582 }
3576 return (try mod.intern(.{ .aggregate = .{
3583 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
35773584 .ty = float_type.toIntern(),
35783585 .storage = .{ .elems = result_data },
3579 } })).toValue();
3586 } })));
35803587 }
35813588 return exp2Scalar(val, float_type, mod);
35823589 }
......@@ -3591,10 +3598,10 @@ pub const Value = struct {
35913598 128 => .{ .f128 = @exp2(val.toFloat(f128, mod)) },
35923599 else => unreachable,
35933600 };
3594 return (try mod.intern(.{ .float = .{
3601 return Value.fromInterned((try mod.intern(.{ .float = .{
35953602 .ty = float_type.toIntern(),
35963603 .storage = storage,
3597 } })).toValue();
3604 } })));
35983605 }
35993606
36003607 pub fn log(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3605,10 +3612,10 @@ pub const Value = struct {
36053612 const elem_val = try val.elemValue(mod, i);
36063613 scalar.* = try (try logScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
36073614 }
3608 return (try mod.intern(.{ .aggregate = .{
3615 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
36093616 .ty = float_type.toIntern(),
36103617 .storage = .{ .elems = result_data },
3611 } })).toValue();
3618 } })));
36123619 }
36133620 return logScalar(val, float_type, mod);
36143621 }
......@@ -3623,10 +3630,10 @@ pub const Value = struct {
36233630 128 => .{ .f128 = @log(val.toFloat(f128, mod)) },
36243631 else => unreachable,
36253632 };
3626 return (try mod.intern(.{ .float = .{
3633 return Value.fromInterned((try mod.intern(.{ .float = .{
36273634 .ty = float_type.toIntern(),
36283635 .storage = storage,
3629 } })).toValue();
3636 } })));
36303637 }
36313638
36323639 pub fn log2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3637,10 +3644,10 @@ pub const Value = struct {
36373644 const elem_val = try val.elemValue(mod, i);
36383645 scalar.* = try (try log2Scalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
36393646 }
3640 return (try mod.intern(.{ .aggregate = .{
3647 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
36413648 .ty = float_type.toIntern(),
36423649 .storage = .{ .elems = result_data },
3643 } })).toValue();
3650 } })));
36443651 }
36453652 return log2Scalar(val, float_type, mod);
36463653 }
......@@ -3655,10 +3662,10 @@ pub const Value = struct {
36553662 128 => .{ .f128 = @log2(val.toFloat(f128, mod)) },
36563663 else => unreachable,
36573664 };
3658 return (try mod.intern(.{ .float = .{
3665 return Value.fromInterned((try mod.intern(.{ .float = .{
36593666 .ty = float_type.toIntern(),
36603667 .storage = storage,
3661 } })).toValue();
3668 } })));
36623669 }
36633670
36643671 pub fn log10(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3669,10 +3676,10 @@ pub const Value = struct {
36693676 const elem_val = try val.elemValue(mod, i);
36703677 scalar.* = try (try log10Scalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
36713678 }
3672 return (try mod.intern(.{ .aggregate = .{
3679 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
36733680 .ty = float_type.toIntern(),
36743681 .storage = .{ .elems = result_data },
3675 } })).toValue();
3682 } })));
36763683 }
36773684 return log10Scalar(val, float_type, mod);
36783685 }
......@@ -3687,10 +3694,10 @@ pub const Value = struct {
36873694 128 => .{ .f128 = @log10(val.toFloat(f128, mod)) },
36883695 else => unreachable,
36893696 };
3690 return (try mod.intern(.{ .float = .{
3697 return Value.fromInterned((try mod.intern(.{ .float = .{
36913698 .ty = float_type.toIntern(),
36923699 .storage = storage,
3693 } })).toValue();
3700 } })));
36943701 }
36953702
36963703 pub fn abs(val: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3701,10 +3708,10 @@ pub const Value = struct {
37013708 const elem_val = try val.elemValue(mod, i);
37023709 scalar.* = try (try absScalar(elem_val, scalar_ty, mod, arena)).intern(scalar_ty, mod);
37033710 }
3704 return (try mod.intern(.{ .aggregate = .{
3711 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37053712 .ty = ty.toIntern(),
37063713 .storage = .{ .elems = result_data },
3707 } })).toValue();
3714 } })));
37083715 }
37093716 return absScalar(val, ty, mod, arena);
37103717 }
......@@ -3735,10 +3742,10 @@ pub const Value = struct {
37353742 128 => .{ .f128 = @abs(val.toFloat(f128, mod)) },
37363743 else => unreachable,
37373744 };
3738 return (try mod.intern(.{ .float = .{
3745 return Value.fromInterned((try mod.intern(.{ .float = .{
37393746 .ty = ty.toIntern(),
37403747 .storage = storage,
3741 } })).toValue();
3748 } })));
37423749 },
37433750 else => unreachable,
37443751 }
......@@ -3752,10 +3759,10 @@ pub const Value = struct {
37523759 const elem_val = try val.elemValue(mod, i);
37533760 scalar.* = try (try floorScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
37543761 }
3755 return (try mod.intern(.{ .aggregate = .{
3762 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37563763 .ty = float_type.toIntern(),
37573764 .storage = .{ .elems = result_data },
3758 } })).toValue();
3765 } })));
37593766 }
37603767 return floorScalar(val, float_type, mod);
37613768 }
......@@ -3770,10 +3777,10 @@ pub const Value = struct {
37703777 128 => .{ .f128 = @floor(val.toFloat(f128, mod)) },
37713778 else => unreachable,
37723779 };
3773 return (try mod.intern(.{ .float = .{
3780 return Value.fromInterned((try mod.intern(.{ .float = .{
37743781 .ty = float_type.toIntern(),
37753782 .storage = storage,
3776 } })).toValue();
3783 } })));
37773784 }
37783785
37793786 pub fn ceil(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3784,10 +3791,10 @@ pub const Value = struct {
37843791 const elem_val = try val.elemValue(mod, i);
37853792 scalar.* = try (try ceilScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
37863793 }
3787 return (try mod.intern(.{ .aggregate = .{
3794 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37883795 .ty = float_type.toIntern(),
37893796 .storage = .{ .elems = result_data },
3790 } })).toValue();
3797 } })));
37913798 }
37923799 return ceilScalar(val, float_type, mod);
37933800 }
......@@ -3802,10 +3809,10 @@ pub const Value = struct {
38023809 128 => .{ .f128 = @ceil(val.toFloat(f128, mod)) },
38033810 else => unreachable,
38043811 };
3805 return (try mod.intern(.{ .float = .{
3812 return Value.fromInterned((try mod.intern(.{ .float = .{
38063813 .ty = float_type.toIntern(),
38073814 .storage = storage,
3808 } })).toValue();
3815 } })));
38093816 }
38103817
38113818 pub fn round(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3816,10 +3823,10 @@ pub const Value = struct {
38163823 const elem_val = try val.elemValue(mod, i);
38173824 scalar.* = try (try roundScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
38183825 }
3819 return (try mod.intern(.{ .aggregate = .{
3826 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
38203827 .ty = float_type.toIntern(),
38213828 .storage = .{ .elems = result_data },
3822 } })).toValue();
3829 } })));
38233830 }
38243831 return roundScalar(val, float_type, mod);
38253832 }
......@@ -3834,10 +3841,10 @@ pub const Value = struct {
38343841 128 => .{ .f128 = @round(val.toFloat(f128, mod)) },
38353842 else => unreachable,
38363843 };
3837 return (try mod.intern(.{ .float = .{
3844 return Value.fromInterned((try mod.intern(.{ .float = .{
38383845 .ty = float_type.toIntern(),
38393846 .storage = storage,
3840 } })).toValue();
3847 } })));
38413848 }
38423849
38433850 pub fn trunc(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
......@@ -3848,10 +3855,10 @@ pub const Value = struct {
38483855 const elem_val = try val.elemValue(mod, i);
38493856 scalar.* = try (try truncScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
38503857 }
3851 return (try mod.intern(.{ .aggregate = .{
3858 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
38523859 .ty = float_type.toIntern(),
38533860 .storage = .{ .elems = result_data },
3854 } })).toValue();
3861 } })));
38553862 }
38563863 return truncScalar(val, float_type, mod);
38573864 }
......@@ -3866,10 +3873,10 @@ pub const Value = struct {
38663873 128 => .{ .f128 = @trunc(val.toFloat(f128, mod)) },
38673874 else => unreachable,
38683875 };
3869 return (try mod.intern(.{ .float = .{
3876 return Value.fromInterned((try mod.intern(.{ .float = .{
38703877 .ty = float_type.toIntern(),
38713878 .storage = storage,
3872 } })).toValue();
3879 } })));
38733880 }
38743881
38753882 pub fn mulAdd(
......@@ -3889,10 +3896,10 @@ pub const Value = struct {
38893896 const addend_elem = try addend.elemValue(mod, i);
38903897 scalar.* = try (try mulAddScalar(scalar_ty, mulend1_elem, mulend2_elem, addend_elem, mod)).intern(scalar_ty, mod);
38913898 }
3892 return (try mod.intern(.{ .aggregate = .{
3899 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
38933900 .ty = float_type.toIntern(),
38943901 .storage = .{ .elems = result_data },
3895 } })).toValue();
3902 } })));
38963903 }
38973904 return mulAddScalar(float_type, mulend1, mulend2, addend, mod);
38983905 }
......@@ -3913,10 +3920,10 @@ pub const Value = struct {
39133920 128 => .{ .f128 = @mulAdd(f128, mulend1.toFloat(f128, mod), mulend2.toFloat(f128, mod), addend.toFloat(f128, mod)) },
39143921 else => unreachable,
39153922 };
3916 return (try mod.intern(.{ .float = .{
3923 return Value.fromInterned((try mod.intern(.{ .float = .{
39173924 .ty = float_type.toIntern(),
39183925 .storage = storage,
3919 } })).toValue();
3926 } })));
39203927 }
39213928
39223929 /// If the value is represented in-memory as a series of bytes that all
......@@ -3958,8 +3965,8 @@ pub const Value = struct {
39583965 const ty = mod.intern_pool.typeOf(val.toIntern());
39593966 if (ty == .comptime_int_type) return null;
39603967 return .{
3961 try ty.toType().minInt(mod, ty.toType()),
3962 try ty.toType().maxInt(mod, ty.toType()),
3968 try Type.fromInterned(ty).minInt(mod, Type.fromInterned(ty)),
3969 try Type.fromInterned(ty).maxInt(mod, Type.fromInterned(ty)),
39633970 };
39643971 }
39653972