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 {...@@ -1221,7 +1221,7 @@ pub fn getMainBody(air: Air) []const Air.Inst.Index {
12211221
1222pub fn typeOf(air: *const Air, inst: Air.Inst.Ref, ip: *const InternPool) Type {1222pub fn typeOf(air: *const Air, inst: Air.Inst.Ref, ip: *const InternPool) Type {
1223 if (refToInterned(inst)) |ip_index| {1223 if (refToInterned(inst)) |ip_index| {
1224 return ip.typeOf(ip_index).toType();1224 return Type.fromInterned(ip.typeOf(ip_index));
1225 } else {1225 } else {
1226 return air.typeOfIndex(refToIndex(inst).?, ip);1226 return air.typeOfIndex(refToIndex(inst).?, ip);
1227 }1227 }
...@@ -1438,7 +1438,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1438,7 +1438,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14381438
1439 .call, .call_always_tail, .call_never_tail, .call_never_inline => {1439 .call, .call_always_tail, .call_never_tail, .call_never_inline => {
1440 const callee_ty = air.typeOf(datas[inst].pl_op.operand, ip);1440 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()));
1442 },1442 },
14431443
1444 .slice_elem_val, .ptr_elem_val, .array_elem_val => {1444 .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)...@@ -1456,7 +1456,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14561456
1457 .reduce, .reduce_optimized => {1457 .reduce, .reduce_optimized => {
1458 const operand_ty = air.typeOf(datas[inst].reduce.operand, ip);1458 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);
1460 },1460 },
14611461
1462 .mul_add => return air.typeOf(datas[inst].pl_op.operand, ip),1462 .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)...@@ -1467,7 +1467,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14671467
1468 .@"try" => {1468 .@"try" => {
1469 const err_union_ty = air.typeOf(datas[inst].pl_op.operand, ip);1469 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);
1471 },1471 },
14721472
1473 .work_item_id,1473 .work_item_id,
...@@ -1482,7 +1482,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)...@@ -1482,7 +1482,7 @@ pub fn typeOfIndex(air: *const Air, inst: Air.Inst.Index, ip: *const InternPool)
14821482
1483pub fn getRefType(air: Air, ref: Air.Inst.Ref) Type {1483pub fn getRefType(air: Air, ref: Air.Inst.Ref) Type {
1484 _ = air; // TODO: remove this parameter1484 _ = air; // TODO: remove this parameter
1485 return refToInterned(ref).?.toType();1485 return Type.fromInterned(refToInterned(ref).?);
1486}1486}
14871487
1488/// Returns the requested data, as well as the new index which is at the start of the1488/// 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 {...@@ -1561,7 +1561,7 @@ pub fn indexToRef(inst: Inst.Index) Inst.Ref {
1561/// Returns `null` if runtime-known.1561/// Returns `null` if runtime-known.
1562pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {1562pub fn value(air: Air, inst: Inst.Ref, mod: *Module) !?Value {
1563 if (refToInterned(inst)) |ip_index| {1563 if (refToInterned(inst)) |ip_index| {
1564 return ip_index.toValue();1564 return Value.fromInterned(ip_index);
1565 }1565 }
1566 const index = refToIndex(inst).?;1566 const index = refToIndex(inst).?;
1567 return air.typeOfIndex(index, &mod.intern_pool).onePossibleValue(mod);1567 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 {...@@ -117,7 +117,7 @@ fn generateZirData(self: *Autodoc, output_dir: std.fs.Dir) !void {
117 // Not a real type, doesn't have a normal name117 // Not a real type, doesn't have a normal name
118 try tmpbuf.writer().writeAll("(generic poison)");118 try tmpbuf.writer().writeAll("(generic poison)");
119 } else {119 } 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());
121 }121 }
122 try self.types.append(122 try self.types.append(
123 self.arena,123 self.arena,
src/InternPool.zig+2-15
...@@ -2096,19 +2096,6 @@ pub const Index = enum(u32) {...@@ -2096,19 +2096,6 @@ pub const Index = enum(u32) {
2096 }2096 }
2097 };2097 };
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
2112 /// Used for a map of `Index` values to the index within a list of `Index` values.2099 /// Used for a map of `Index` values to the index within a list of `Index` values.
2113 const Adapter = struct {2100 const Adapter = struct {
2114 indexes: []const Index,2101 indexes: []const Index,
...@@ -6145,8 +6132,8 @@ fn finishFuncInstance(...@@ -6145,8 +6132,8 @@ fn finishFuncInstance(
6145 .src_line = fn_owner_decl.src_line,6132 .src_line = fn_owner_decl.src_line,
6146 .has_tv = true,6133 .has_tv = true,
6147 .owns_tv = true,6134 .owns_tv = true,
6148 .ty = func_ty.toType(),6135 .ty = @import("type.zig").Type.fromInterned(func_ty),
6149 .val = func_index.toValue(),6136 .val = @import("value.zig").Value.fromInterned(func_index),
6150 .alignment = .none,6137 .alignment = .none,
6151 .@"linksection" = section,6138 .@"linksection" = section,
6152 .@"addrspace" = fn_owner_decl.@"addrspace",6139 .@"addrspace" = fn_owner_decl.@"addrspace",
src/Module.zig+61-61
...@@ -659,7 +659,7 @@ pub const Decl = struct {...@@ -659,7 +659,7 @@ pub const Decl = struct {
659 pub fn internValue(decl: *Decl, mod: *Module) Allocator.Error!InternPool.Index {659 pub fn internValue(decl: *Decl, mod: *Module) Allocator.Error!InternPool.Index {
660 assert(decl.has_tv);660 assert(decl.has_tv);
661 const ip_index = try decl.val.intern(decl.ty, mod);661 const ip_index = try decl.val.intern(decl.ty, mod);
662 decl.val = ip_index.toValue();662 decl.val = Value.fromInterned(ip_index);
663 return ip_index;663 return ip_index;
664 }664 }
665665
...@@ -3556,8 +3556,8 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {...@@ -3556,8 +3556,8 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
3556 _ = try decl.internValue(mod);3556 _ = try decl.internValue(mod);
3557 }3557 }
35583558
3559 new_namespace.ty = struct_ty.toType();3559 new_namespace.ty = Type.fromInterned(struct_ty);
3560 new_decl.val = struct_ty.toValue();3560 new_decl.val = Value.fromInterned(struct_ty);
3561 new_decl.has_tv = true;3561 new_decl.has_tv = true;
3562 new_decl.owns_tv = true;3562 new_decl.owns_tv = true;
3563 new_decl.analysis = .complete;3563 new_decl.analysis = .complete;
...@@ -3711,7 +3711,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -3711,7 +3711,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
3711 return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)});3711 return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)});
3712 }3712 }
37133713
3714 decl.ty = InternPool.Index.type_type.toType();3714 decl.ty = Type.fromInterned(InternPool.Index.type_type);
3715 decl.val = ty.toValue();3715 decl.val = ty.toValue();
3716 decl.alignment = .none;3716 decl.alignment = .none;
3717 decl.@"linksection" = .none;3717 decl.@"linksection" = .none;
...@@ -3741,7 +3741,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -3741,7 +3741,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
3741 }3741 }
37423742
3743 decl.ty = decl_tv.ty;3743 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)));
3745 // linksection, align, and addrspace were already set by Sema3745 // linksection, align, and addrspace were already set by Sema
3746 decl.has_tv = true;3746 decl.has_tv = true;
3747 decl.owns_tv = owns_tv;3747 decl.owns_tv = owns_tv;
...@@ -3794,7 +3794,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {...@@ -3794,7 +3794,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !bool {
3794 }3794 }
37953795
3796 decl.ty = decl_tv.ty;3796 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)));
3798 decl.alignment = blk: {3798 decl.alignment = blk: {
3799 const align_ref = decl.zirAlignRef(mod);3799 const align_ref = decl.zirAlignRef(mod);
3800 if (align_ref == .none) break :blk .none;3800 if (align_ref == .none) break :blk .none;
...@@ -4509,7 +4509,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4509,7 +4509,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4509 .owner_decl_index = decl_index,4509 .owner_decl_index = decl_index,
4510 .func_index = func_index,4510 .func_index = func_index,
4511 .func_is_naked = fn_ty_info.cc == .Naked,4511 .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),
4513 .fn_ret_ty_ies = null,4513 .fn_ret_ty_ies = null,
4514 .owner_func_index = func_index,4514 .owner_func_index = func_index,
4515 .branch_quota = @max(func.branchQuota(ip).*, Sema.default_branch_quota),4515 .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...@@ -4580,7 +4580,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4580 const param_ty = fn_ty_info.param_types.get(ip)[runtime_param_index];4580 const param_ty = fn_ty_info.param_types.get(ip)[runtime_param_index];
4581 runtime_param_index += 1;4581 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) {
4584 error.NeededSourceLocation => unreachable,4584 error.NeededSourceLocation => unreachable,
4585 error.GenericPoison => unreachable,4585 error.GenericPoison => unreachable,
4586 error.ComptimeReturn => unreachable,4586 error.ComptimeReturn => unreachable,
...@@ -4707,7 +4707,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato...@@ -4707,7 +4707,7 @@ pub fn analyzeFnBody(mod: *Module, func_index: InternPool.Index, arena: Allocato
4707 // Similarly, resolve any queued up types that were requested to be resolved for4707 // Similarly, resolve any queued up types that were requested to be resolved for
4708 // the backends.4708 // the backends.
4709 for (sema.types_to_resolve.keys()) |ty| {4709 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) {
4711 error.NeededSourceLocation => unreachable,4711 error.NeededSourceLocation => unreachable,
4712 error.GenericPoison => unreachable,4712 error.GenericPoison => unreachable,
4713 error.ComptimeReturn => unreachable,4713 error.ComptimeReturn => unreachable,
...@@ -5392,10 +5392,10 @@ pub fn populateTestFunctions(...@@ -5392,10 +5392,10 @@ pub fn populateTestFunctions(
5392 });5392 });
5393 const test_name_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, .none, .{5393 const test_name_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, .none, .{
5394 .ty = test_name_decl_ty,5394 .ty = test_name_decl_ty,
5395 .val = (try mod.intern(.{ .aggregate = .{5395 .val = Value.fromInterned((try mod.intern(.{ .aggregate = .{
5396 .ty = test_name_decl_ty.toIntern(),5396 .ty = test_name_decl_ty.toIntern(),
5397 .storage = .{ .bytes = test_decl_name },5397 .storage = .{ .bytes = test_decl_name },
5398 } })).toValue(),5398 } }))),
5399 });5399 });
5400 break :n test_name_decl_index;5400 break :n test_name_decl_index;
5401 };5401 };
...@@ -5439,10 +5439,10 @@ pub fn populateTestFunctions(...@@ -5439,10 +5439,10 @@ pub fn populateTestFunctions(
5439 });5439 });
5440 const array_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, .none, .{5440 const array_decl_index = try mod.createAnonymousDeclFromDecl(decl, decl.src_namespace, .none, .{
5441 .ty = array_decl_ty,5441 .ty = array_decl_ty,
5442 .val = (try mod.intern(.{ .aggregate = .{5442 .val = Value.fromInterned((try mod.intern(.{ .aggregate = .{
5443 .ty = array_decl_ty.toIntern(),5443 .ty = array_decl_ty.toIntern(),
5444 .storage = .{ .elems = test_fn_vals },5444 .storage = .{ .elems = test_fn_vals },
5445 } })).toValue(),5445 } }))),
5446 });5446 });
54475447
5448 break :d array_decl_index;5448 break :d array_decl_index;
...@@ -5548,7 +5548,7 @@ pub fn markReferencedDeclsAlive(mod: *Module, val: Value) Allocator.Error!void {...@@ -5548,7 +5548,7 @@ pub fn markReferencedDeclsAlive(mod: *Module, val: Value) Allocator.Error!void {
5548 .func => |func| try mod.markDeclIndexAlive(func.owner_decl),5548 .func => |func| try mod.markDeclIndexAlive(func.owner_decl),
5549 .error_union => |error_union| switch (error_union.val) {5549 .error_union => |error_union| switch (error_union.val) {
5550 .err_name => {},5550 .err_name => {},
5551 .payload => |payload| try mod.markReferencedDeclsAlive(payload.toValue()),5551 .payload => |payload| try mod.markReferencedDeclsAlive(Value.fromInterned(payload)),
5552 },5552 },
5553 .ptr => |ptr| {5553 .ptr => |ptr| {
5554 switch (ptr.addr) {5554 switch (ptr.addr) {
...@@ -5556,17 +5556,17 @@ pub fn markReferencedDeclsAlive(mod: *Module, val: Value) Allocator.Error!void {...@@ -5556,17 +5556,17 @@ pub fn markReferencedDeclsAlive(mod: *Module, val: Value) Allocator.Error!void {
5556 .anon_decl => {},5556 .anon_decl => {},
5557 .mut_decl => |mut_decl| try mod.markDeclIndexAlive(mut_decl.decl),5557 .mut_decl => |mut_decl| try mod.markDeclIndexAlive(mut_decl.decl),
5558 .int, .comptime_field => {},5558 .int, .comptime_field => {},
5559 .eu_payload, .opt_payload => |parent| try mod.markReferencedDeclsAlive(parent.toValue()),5559 .eu_payload, .opt_payload => |parent| try mod.markReferencedDeclsAlive(Value.fromInterned(parent)),
5560 .elem, .field => |base_index| try mod.markReferencedDeclsAlive(base_index.base.toValue()),5560 .elem, .field => |base_index| try mod.markReferencedDeclsAlive(Value.fromInterned(base_index.base)),
5561 }5561 }
5562 if (ptr.len != .none) try mod.markReferencedDeclsAlive(ptr.len.toValue());5562 if (ptr.len != .none) try mod.markReferencedDeclsAlive(Value.fromInterned(ptr.len));
5563 },5563 },
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)),
5565 .aggregate => |aggregate| for (aggregate.storage.values()) |elem|5565 .aggregate => |aggregate| for (aggregate.storage.values()) |elem|
5566 try mod.markReferencedDeclsAlive(elem.toValue()),5566 try mod.markReferencedDeclsAlive(Value.fromInterned(elem)),
5567 .un => |un| {5567 .un => |un| {
5568 if (un.tag != .none) try mod.markReferencedDeclsAlive(un.tag.toValue());5568 if (un.tag != .none) try mod.markReferencedDeclsAlive(Value.fromInterned(un.tag));
5569 try mod.markReferencedDeclsAlive(un.val.toValue());5569 try mod.markReferencedDeclsAlive(Value.fromInterned(un.val));
5570 },5570 },
5571 else => {},5571 else => {},
5572 }5572 }
...@@ -5653,14 +5653,14 @@ pub fn intern(mod: *Module, key: InternPool.Key) Allocator.Error!InternPool.Inde...@@ -5653,14 +5653,14 @@ pub fn intern(mod: *Module, key: InternPool.Key) Allocator.Error!InternPool.Inde
56535653
5654/// Shortcut for calling `intern_pool.getCoerced`.5654/// Shortcut for calling `intern_pool.getCoerced`.
5655pub fn getCoerced(mod: *Module, val: Value, new_ty: Type) Allocator.Error!Value {5655pub 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())));
5657}5657}
56585658
5659pub fn intType(mod: *Module, signedness: std.builtin.Signedness, bits: u16) Allocator.Error!Type {5659pub 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 = .{
5661 .signedness = signedness,5661 .signedness = signedness,
5662 .bits = bits,5662 .bits = bits,
5663 } })).toType();5663 } })));
5664}5664}
56655665
5666pub fn errorIntType(mod: *Module) std.mem.Allocator.Error!Type {5666pub fn errorIntType(mod: *Module) std.mem.Allocator.Error!Type {
...@@ -5669,17 +5669,17 @@ pub fn errorIntType(mod: *Module) std.mem.Allocator.Error!Type {...@@ -5669,17 +5669,17 @@ pub fn errorIntType(mod: *Module) std.mem.Allocator.Error!Type {
56695669
5670pub fn arrayType(mod: *Module, info: InternPool.Key.ArrayType) Allocator.Error!Type {5670pub fn arrayType(mod: *Module, info: InternPool.Key.ArrayType) Allocator.Error!Type {
5671 const i = try intern(mod, .{ .array_type = info });5671 const i = try intern(mod, .{ .array_type = info });
5672 return i.toType();5672 return Type.fromInterned(i);
5673}5673}
56745674
5675pub fn vectorType(mod: *Module, info: InternPool.Key.VectorType) Allocator.Error!Type {5675pub fn vectorType(mod: *Module, info: InternPool.Key.VectorType) Allocator.Error!Type {
5676 const i = try intern(mod, .{ .vector_type = info });5676 const i = try intern(mod, .{ .vector_type = info });
5677 return i.toType();5677 return Type.fromInterned(i);
5678}5678}
56795679
5680pub fn optionalType(mod: *Module, child_type: InternPool.Index) Allocator.Error!Type {5680pub fn optionalType(mod: *Module, child_type: InternPool.Index) Allocator.Error!Type {
5681 const i = try intern(mod, .{ .opt_type = child_type });5681 const i = try intern(mod, .{ .opt_type = child_type });
5682 return i.toType();5682 return Type.fromInterned(i);
5683}5683}
56845684
5685pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type {5685pub 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...@@ -5692,7 +5692,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
5692 // pointee type needs to be resolved more, that needs to be done before calling5692 // pointee type needs to be resolved more, that needs to be done before calling
5693 // this ptr() function.5693 // this ptr() function.
5694 if (info.flags.alignment != .none and5694 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))
5696 {5696 {
5697 canon_info.flags.alignment = .none;5697 canon_info.flags.alignment = .none;
5698 }5698 }
...@@ -5702,7 +5702,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type...@@ -5702,7 +5702,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
5702 // we change it to 0 here. If this causes an assertion trip, the pointee type5702 // we change it to 0 here. If this causes an assertion trip, the pointee type
5703 // needs to be resolved before calling this ptr() function.5703 // needs to be resolved before calling this ptr() function.
5704 .none => if (info.packed_offset.host_size != 0) {5704 .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);
5706 assert(info.packed_offset.bit_offset + elem_bit_size <= info.packed_offset.host_size * 8);5706 assert(info.packed_offset.bit_offset + elem_bit_size <= info.packed_offset.host_size * 8);
5707 if (info.packed_offset.host_size * 8 == elem_bit_size) {5707 if (info.packed_offset.host_size * 8 == elem_bit_size) {
5708 canon_info.packed_offset.host_size = 0;5708 canon_info.packed_offset.host_size = 0;
...@@ -5712,7 +5712,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type...@@ -5712,7 +5712,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
5712 _ => assert(@intFromEnum(info.flags.vector_index) < info.packed_offset.host_size),5712 _ => assert(@intFromEnum(info.flags.vector_index) < info.packed_offset.host_size),
5713 }5713 }
57145714
5715 return (try intern(mod, .{ .ptr_type = canon_info })).toType();5715 return Type.fromInterned((try intern(mod, .{ .ptr_type = canon_info })));
5716}5716}
57175717
5718pub fn singleMutPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {5718pub 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...@@ -5745,26 +5745,26 @@ pub fn adjustPtrTypeChild(mod: *Module, ptr_ty: Type, new_child: Type) Allocator
5745}5745}
57465746
5747pub fn funcType(mod: *Module, key: InternPool.GetFuncTypeKey) Allocator.Error!Type {5747pub 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)));
5749}5749}
57505750
5751/// Use this for `anyframe->T` only.5751/// Use this for `anyframe->T` only.
5752/// For `anyframe`, use the `InternPool.Index.anyframe` tag directly.5752/// For `anyframe`, use the `InternPool.Index.anyframe` tag directly.
5753pub fn anyframeType(mod: *Module, payload_ty: Type) Allocator.Error!Type {5753pub 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() })));
5755}5755}
57565756
5757pub fn errorUnionType(mod: *Module, error_set_ty: Type, payload_ty: Type) Allocator.Error!Type {5757pub 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 = .{
5759 .error_set_type = error_set_ty.toIntern(),5759 .error_set_type = error_set_ty.toIntern(),
5760 .payload_type = payload_ty.toIntern(),5760 .payload_type = payload_ty.toIntern(),
5761 } })).toType();5761 } })));
5762}5762}
57635763
5764pub fn singleErrorSetType(mod: *Module, name: InternPool.NullTerminatedString) Allocator.Error!Type {5764pub fn singleErrorSetType(mod: *Module, name: InternPool.NullTerminatedString) Allocator.Error!Type {
5765 const names: *const [1]InternPool.NullTerminatedString = &name;5765 const names: *const [1]InternPool.NullTerminatedString = &name;
5766 const new_ty = try mod.intern_pool.getErrorSetType(mod.gpa, names);5766 const new_ty = try mod.intern_pool.getErrorSetType(mod.gpa, names);
5767 return new_ty.toType();5767 return Type.fromInterned(new_ty);
5768}5768}
57695769
5770/// Sorts `names` in place.5770/// Sorts `names` in place.
...@@ -5779,7 +5779,7 @@ pub fn errorSetFromUnsortedNames(...@@ -5779,7 +5779,7 @@ pub fn errorSetFromUnsortedNames(
5779 InternPool.NullTerminatedString.indexLessThan,5779 InternPool.NullTerminatedString.indexLessThan,
5780 );5780 );
5781 const new_ty = try mod.intern_pool.getErrorSetType(mod.gpa, names);5781 const new_ty = try mod.intern_pool.getErrorSetType(mod.gpa, names);
5782 return new_ty.toType();5782 return Type.fromInterned(new_ty);
5783}5783}
57845784
5785/// Supports only pointers, not pointer-like optionals.5785/// Supports only pointers, not pointer-like optionals.
...@@ -5789,7 +5789,7 @@ pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {...@@ -5789,7 +5789,7 @@ pub fn ptrIntValue(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
5789 .ty = ty.toIntern(),5789 .ty = ty.toIntern(),
5790 .addr = .{ .int = (try mod.intValue_u64(Type.usize, x)).toIntern() },5790 .addr = .{ .int = (try mod.intValue_u64(Type.usize, x)).toIntern() },
5791 } });5791 } });
5792 return i.toValue();5792 return Value.fromInterned(i);
5793}5793}
57945794
5795/// Creates an enum tag value based on the integer tag value.5795/// 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...@@ -5802,7 +5802,7 @@ pub fn enumValue(mod: *Module, ty: Type, tag_int: InternPool.Index) Allocator.Er
5802 .ty = ty.toIntern(),5802 .ty = ty.toIntern(),
5803 .int = tag_int,5803 .int = tag_int,
5804 } });5804 } });
5805 return i.toValue();5805 return Value.fromInterned(i);
5806}5806}
58075807
5808/// Creates an enum tag value based on the field index according to source code5808/// 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...@@ -5814,23 +5814,23 @@ pub fn enumValueFieldIndex(mod: *Module, ty: Type, field_index: u32) Allocator.E
58145814
5815 if (enum_type.values.len == 0) {5815 if (enum_type.values.len == 0) {
5816 // Auto-numbered fields.5816 // Auto-numbered fields.
5817 return (try ip.get(gpa, .{ .enum_tag = .{5817 return Value.fromInterned((try ip.get(gpa, .{ .enum_tag = .{
5818 .ty = ty.toIntern(),5818 .ty = ty.toIntern(),
5819 .int = try ip.get(gpa, .{ .int = .{5819 .int = try ip.get(gpa, .{ .int = .{
5820 .ty = enum_type.tag_ty,5820 .ty = enum_type.tag_ty,
5821 .storage = .{ .u64 = field_index },5821 .storage = .{ .u64 = field_index },
5822 } }),5822 } }),
5823 } })).toValue();5823 } })));
5824 }5824 }
58255825
5826 return (try ip.get(gpa, .{ .enum_tag = .{5826 return Value.fromInterned((try ip.get(gpa, .{ .enum_tag = .{
5827 .ty = ty.toIntern(),5827 .ty = ty.toIntern(),
5828 .int = enum_type.values.get(ip)[field_index],5828 .int = enum_type.values.get(ip)[field_index],
5829 } })).toValue();5829 } })));
5830}5830}
58315831
5832pub fn undefValue(mod: *Module, ty: Type) Allocator.Error!Value {5832pub 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() })));
5834}5834}
58355835
5836pub fn undefRef(mod: *Module, ty: Type) Allocator.Error!Air.Inst.Ref {5836pub 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...@@ -5854,7 +5854,7 @@ pub fn intValue_big(mod: *Module, ty: Type, x: BigIntConst) Allocator.Error!Valu
5854 .ty = ty.toIntern(),5854 .ty = ty.toIntern(),
5855 .storage = .{ .big_int = x },5855 .storage = .{ .big_int = x },
5856 } });5856 } });
5857 return i.toValue();5857 return Value.fromInterned(i);
5858}5858}
58595859
5860pub fn intValue_u64(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {5860pub 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 {...@@ -5862,7 +5862,7 @@ pub fn intValue_u64(mod: *Module, ty: Type, x: u64) Allocator.Error!Value {
5862 .ty = ty.toIntern(),5862 .ty = ty.toIntern(),
5863 .storage = .{ .u64 = x },5863 .storage = .{ .u64 = x },
5864 } });5864 } });
5865 return i.toValue();5865 return Value.fromInterned(i);
5866}5866}
58675867
5868pub fn intValue_i64(mod: *Module, ty: Type, x: i64) Allocator.Error!Value {5868pub 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 {...@@ -5870,7 +5870,7 @@ pub fn intValue_i64(mod: *Module, ty: Type, x: i64) Allocator.Error!Value {
5870 .ty = ty.toIntern(),5870 .ty = ty.toIntern(),
5871 .storage = .{ .i64 = x },5871 .storage = .{ .i64 = x },
5872 } });5872 } });
5873 return i.toValue();5873 return Value.fromInterned(i);
5874}5874}
58755875
5876pub fn unionValue(mod: *Module, union_ty: Type, tag: Value, val: Value) Allocator.Error!Value {5876pub 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...@@ -5879,7 +5879,7 @@ pub fn unionValue(mod: *Module, union_ty: Type, tag: Value, val: Value) Allocato
5879 .tag = tag.toIntern(),5879 .tag = tag.toIntern(),
5880 .val = val.toIntern(),5880 .val = val.toIntern(),
5881 } });5881 } });
5882 return i.toValue();5882 return Value.fromInterned(i);
5883}5883}
58845884
5885/// This function casts the float representation down to the representation of the type, potentially5885/// 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 {...@@ -5897,7 +5897,7 @@ pub fn floatValue(mod: *Module, ty: Type, x: anytype) Allocator.Error!Value {
5897 .ty = ty.toIntern(),5897 .ty = ty.toIntern(),
5898 .storage = storage,5898 .storage = storage,
5899 } });5899 } });
5900 return i.toValue();5900 return Value.fromInterned(i);
5901}5901}
59025902
5903pub fn nullValue(mod: *Module, opt_ty: Type) Allocator.Error!Value {5903pub 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 {...@@ -5907,7 +5907,7 @@ pub fn nullValue(mod: *Module, opt_ty: Type) Allocator.Error!Value {
5907 .ty = opt_ty.toIntern(),5907 .ty = opt_ty.toIntern(),
5908 .val = .none,5908 .val = .none,
5909 } });5909 } });
5910 return result.toValue();5910 return Value.fromInterned(result);
5911}5911}
59125912
5913pub fn smallestUnsignedInt(mod: *Module, max: u64) Allocator.Error!Type {5913pub fn smallestUnsignedInt(mod: *Module, max: u64) Allocator.Error!Type {
...@@ -5964,10 +5964,10 @@ pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 {...@@ -5964,10 +5964,10 @@ pub fn intBitsForValue(mod: *Module, val: Value, sign: bool) u16 {
5964 return @as(u16, @intCast(big.bitCountTwosComp()));5964 return @as(u16, @intCast(big.bitCountTwosComp()));
5965 },5965 },
5966 .lazy_align => |lazy_ty| {5966 .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);
5968 },5968 },
5969 .lazy_size => |lazy_ty| {5969 .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);
5971 },5971 },
5972 }5972 }
5973}5973}
...@@ -6252,14 +6252,14 @@ pub fn getUnionLayout(mod: *Module, u: InternPool.UnionType) UnionLayout {...@@ -6252,14 +6252,14 @@ pub fn getUnionLayout(mod: *Module, u: InternPool.UnionType) UnionLayout {
6252 var payload_size: u64 = 0;6252 var payload_size: u64 = 0;
6253 var payload_align: Alignment = .@"1";6253 var payload_align: Alignment = .@"1";
6254 for (u.field_types.get(ip), 0..) |field_ty, i| {6254 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
6257 const explicit_align = u.fieldAlign(ip, @intCast(i));6257 const explicit_align = u.fieldAlign(ip, @intCast(i));
6258 const field_align = if (explicit_align != .none)6258 const field_align = if (explicit_align != .none)
6259 explicit_align6259 explicit_align
6260 else6260 else
6261 field_ty.toType().abiAlignment(mod);6261 Type.fromInterned(field_ty).abiAlignment(mod);
6262 const field_size = field_ty.toType().abiSize(mod);6262 const field_size = Type.fromInterned(field_ty).abiSize(mod);
6263 if (field_size > payload_size) {6263 if (field_size > payload_size) {
6264 payload_size = field_size;6264 payload_size = field_size;
6265 biggest_field = @intCast(i);6265 biggest_field = @intCast(i);
...@@ -6271,7 +6271,7 @@ pub fn getUnionLayout(mod: *Module, u: InternPool.UnionType) UnionLayout {...@@ -6271,7 +6271,7 @@ pub fn getUnionLayout(mod: *Module, u: InternPool.UnionType) UnionLayout {
6271 }6271 }
6272 }6272 }
6273 const have_tag = u.flagsPtr(ip).runtime_tag.hasTag();6273 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)) {
6275 return .{6275 return .{
6276 .abi_size = payload_align.forward(payload_size),6276 .abi_size = payload_align.forward(payload_size),
6277 .abi_align = payload_align,6277 .abi_align = payload_align,
...@@ -6286,8 +6286,8 @@ pub fn getUnionLayout(mod: *Module, u: InternPool.UnionType) UnionLayout {...@@ -6286,8 +6286,8 @@ pub fn getUnionLayout(mod: *Module, u: InternPool.UnionType) UnionLayout {
6286 };6286 };
6287 }6287 }
62886288
6289 const tag_size = u.enum_tag_ty.toType().abiSize(mod);6289 const tag_size = Type.fromInterned(u.enum_tag_ty).abiSize(mod);
6290 const tag_align = u.enum_tag_ty.toType().abiAlignment(mod).max(.@"1");6290 const tag_align = Type.fromInterned(u.enum_tag_ty).abiAlignment(mod).max(.@"1");
6291 return .{6291 return .{
6292 .abi_size = u.size,6292 .abi_size = u.size,
6293 .abi_align = tag_align.max(payload_align),6293 .abi_align = tag_align.max(payload_align),
...@@ -6311,9 +6311,9 @@ pub fn unionAbiAlignment(mod: *Module, u: InternPool.UnionType) Alignment {...@@ -6311,9 +6311,9 @@ pub fn unionAbiAlignment(mod: *Module, u: InternPool.UnionType) Alignment {
6311 const ip = &mod.intern_pool;6311 const ip = &mod.intern_pool;
6312 const have_tag = u.flagsPtr(ip).runtime_tag.hasTag();6312 const have_tag = u.flagsPtr(ip).runtime_tag.hasTag();
6313 var max_align: Alignment = .none;6313 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);
6315 for (u.field_types.get(ip), 0..) |field_ty, field_index| {6315 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
6318 const field_align = mod.unionFieldNormalAlignment(u, @intCast(field_index));6318 const field_align = mod.unionFieldNormalAlignment(u, @intCast(field_index));
6319 max_align = max_align.max(field_align);6319 max_align = max_align.max(field_align);
...@@ -6328,7 +6328,7 @@ pub fn unionFieldNormalAlignment(mod: *Module, u: InternPool.UnionType, field_in...@@ -6328,7 +6328,7 @@ pub fn unionFieldNormalAlignment(mod: *Module, u: InternPool.UnionType, field_in
6328 const ip = &mod.intern_pool;6328 const ip = &mod.intern_pool;
6329 const field_align = u.fieldAlign(ip, field_index);6329 const field_align = u.fieldAlign(ip, field_index);
6330 if (field_align != .none) return field_align;6330 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]);
6332 return field_ty.abiAlignment(mod);6332 return field_ty.abiAlignment(mod);
6333}6333}
63346334
...@@ -6396,7 +6396,7 @@ pub fn structPackedFieldBitOffset(...@@ -6396,7 +6396,7 @@ pub fn structPackedFieldBitOffset(
6396 if (i == field_index) {6396 if (i == field_index) {
6397 return @intCast(bit_sum);6397 return @intCast(bit_sum);
6398 }6398 }
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]);
6400 bit_sum += field_ty.bitSize(mod);6400 bit_sum += field_ty.bitSize(mod);
6401 }6401 }
6402 unreachable; // index out of bounds6402 unreachable; // index out of bounds
src/RangeSet.zig+8-6
...@@ -3,6 +3,8 @@ const assert = std.debug.assert;...@@ -3,6 +3,8 @@ const assert = std.debug.assert;
3const Order = std.math.Order;3const Order = std.math.Order;
44
5const InternPool = @import("InternPool.zig");5const InternPool = @import("InternPool.zig");
6const Type = @import("type.zig").Type;
7const Value = @import("value.zig").Value;
6const Module = @import("Module.zig");8const Module = @import("Module.zig");
7const RangeSet = @This();9const RangeSet = @This();
8const SwitchProngSrc = @import("Module.zig").SwitchProngSrc;10const SwitchProngSrc = @import("Module.zig").SwitchProngSrc;
...@@ -43,8 +45,8 @@ pub fn add(...@@ -43,8 +45,8 @@ pub fn add(
43 assert(ty == ip.typeOf(range.first));45 assert(ty == ip.typeOf(range.first));
44 assert(ty == ip.typeOf(range.last));46 assert(ty == ip.typeOf(range.last));
4547
46 if (last.toValue().compareScalar(.gte, range.first.toValue(), ty.toType(), mod) and48 if (Value.fromInterned(last).compareScalar(.gte, Value.fromInterned(range.first), Type.fromInterned(ty), mod) and
47 first.toValue().compareScalar(.lte, range.last.toValue(), ty.toType(), mod))49 Value.fromInterned(first).compareScalar(.lte, Value.fromInterned(range.last), Type.fromInterned(ty), mod))
48 {50 {
49 return range.src; // They overlap.51 return range.src; // They overlap.
50 }52 }
...@@ -60,8 +62,8 @@ pub fn add(...@@ -60,8 +62,8 @@ pub fn add(
6062
61/// Assumes a and b do not overlap63/// Assumes a and b do not overlap
62fn lessThan(mod: *Module, a: Range, b: Range) bool {64fn lessThan(mod: *Module, a: Range, b: Range) bool {
63 const ty = mod.intern_pool.typeOf(a.first).toType();65 const ty = Type.fromInterned(mod.intern_pool.typeOf(a.first));
64 return a.first.toValue().compareScalar(.lt, b.first.toValue(), ty, mod);66 return Value.fromInterned(a.first).compareScalar(.lt, Value.fromInterned(b.first), ty, mod);
65}67}
6668
67pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) !bool {69pub 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) !...@@ -91,10 +93,10 @@ pub fn spans(self: *RangeSet, first: InternPool.Index, last: InternPool.Index) !
91 const prev = self.ranges.items[i];93 const prev = self.ranges.items[i];
9294
93 // prev.last + 1 == cur.first95 // 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));
95 try counter.addScalar(&counter, 1);97 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);
98 if (!cur_start_int.eql(counter.toConst())) {100 if (!cur_start_int.eql(counter.toConst())) {
99 return false;101 return false;
100 }102 }
src/Sema.zig+424-424
...@@ -2153,13 +2153,13 @@ fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Val...@@ -2153,13 +2153,13 @@ fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Val
2153 assert(inst != .none);2153 assert(inst != .none);
2154 // First section of indexes correspond to a set number of constant values.2154 // First section of indexes correspond to a set number of constant values.
2155 if (@intFromEnum(inst) < InternPool.static_len) {2155 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))));
2157 }2157 }
21582158
2159 const air_tags = sema.air_instructions.items(.tag);2159 const air_tags = sema.air_instructions.items(.tag);
2160 if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| {2160 if (try sema.typeHasOnePossibleValue(sema.typeOf(inst))) |opv| {
2161 if (Air.refToInterned(inst)) |ip_index| {2161 if (Air.refToInterned(inst)) |ip_index| {
2162 const val = ip_index.toValue();2162 const val = Value.fromInterned(ip_index);
2163 if (val.getVariable(sema.mod) != null) return val;2163 if (val.getVariable(sema.mod) != null) return val;
2164 }2164 }
2165 return opv;2165 return opv;
...@@ -2171,7 +2171,7 @@ fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Val...@@ -2171,7 +2171,7 @@ fn resolveValueAllowVariables(sema: *Sema, inst: Air.Inst.Ref) CompileError!?Val
2171 else => return null,2171 else => return null,
2172 }2172 }
2173 };2173 };
2174 const val = ip_index.toValue();2174 const val = Value.fromInterned(ip_index);
2175 if (val.isPtrToThreadLocal(sema.mod)) return null;2175 if (val.isPtrToThreadLocal(sema.mod)) return null;
2176 return val;2176 return val;
2177}2177}
...@@ -2364,7 +2364,7 @@ fn typeSupportsFieldAccess(mod: *const Module, ty: Type, field_name: InternPool....@@ -2364,7 +2364,7 @@ fn typeSupportsFieldAccess(mod: *const Module, ty: Type, field_name: InternPool.
2364 const ptr_info = ty.ptrInfo(mod);2364 const ptr_info = ty.ptrInfo(mod);
2365 if (ptr_info.flags.size == .Slice) {2365 if (ptr_info.flags.size == .Slice) {
2366 return ip.stringEqlSlice(field_name, "ptr") or ip.stringEqlSlice(field_name, "len");2366 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) {
2368 return ip.stringEqlSlice(field_name, "len");2368 return ip.stringEqlSlice(field_name, "len");
2369 } else return false;2369 } else return false;
2370 },2370 },
...@@ -2752,8 +2752,8 @@ fn zirStructDecl(...@@ -2752,8 +2752,8 @@ fn zirStructDecl(
2752 //errdefer ip.remove(struct_ty);2752 //errdefer ip.remove(struct_ty);
27532753
2754 new_decl.ty = Type.type;2754 new_decl.ty = Type.type;
2755 new_decl.val = struct_ty.toValue();2755 new_decl.val = Value.fromInterned(struct_ty);
2756 new_namespace.ty = struct_ty.toType();2756 new_namespace.ty = Type.fromInterned(struct_ty);
27572757
2758 const decl_val = sema.analyzeDeclVal(block, src, new_decl_index);2758 const decl_val = sema.analyzeDeclVal(block, src, new_decl_index);
2759 try mod.finalizeAnonDecl(new_decl_index);2759 try mod.finalizeAnonDecl(new_decl_index);
...@@ -2959,8 +2959,8 @@ fn zirEnumDecl(...@@ -2959,8 +2959,8 @@ fn zirEnumDecl(
2959 //errdefer if (!done) mod.intern_pool.remove(incomplete_enum.index);2959 //errdefer if (!done) mod.intern_pool.remove(incomplete_enum.index);
29602960
2961 new_decl.ty = Type.type;2961 new_decl.ty = Type.type;
2962 new_decl.val = incomplete_enum.index.toValue();2962 new_decl.val = Value.fromInterned(incomplete_enum.index);
2963 new_namespace.ty = incomplete_enum.index.toType();2963 new_namespace.ty = Type.fromInterned(incomplete_enum.index);
29642964
2965 const decl_val = try sema.analyzeDeclVal(block, src, new_decl_index);2965 const decl_val = try sema.analyzeDeclVal(block, src, new_decl_index);
2966 try mod.finalizeAnonDecl(new_decl_index);2966 try mod.finalizeAnonDecl(new_decl_index);
...@@ -3222,8 +3222,8 @@ fn zirUnionDecl(...@@ -3222,8 +3222,8 @@ fn zirUnionDecl(
3222 //errdefer mod.intern_pool.remove(union_ty);3222 //errdefer mod.intern_pool.remove(union_ty);
32233223
3224 new_decl.ty = Type.type;3224 new_decl.ty = Type.type;
3225 new_decl.val = union_ty.toValue();3225 new_decl.val = Value.fromInterned(union_ty);
3226 new_namespace.ty = union_ty.toType();3226 new_namespace.ty = Type.fromInterned(union_ty);
32273227
3228 _ = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl);3228 _ = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl);
32293229
...@@ -3285,8 +3285,8 @@ fn zirOpaqueDecl(...@@ -3285,8 +3285,8 @@ fn zirOpaqueDecl(
3285 //errdefer mod.intern_pool.remove(opaque_ty);3285 //errdefer mod.intern_pool.remove(opaque_ty);
32863286
3287 new_decl.ty = Type.type;3287 new_decl.ty = Type.type;
3288 new_decl.val = opaque_ty.toValue();3288 new_decl.val = Value.fromInterned(opaque_ty);
3289 new_namespace.ty = opaque_ty.toType();3289 new_namespace.ty = Type.fromInterned(opaque_ty);
32903290
3291 extra_index = try mod.scanNamespace(new_namespace_index, extra_index, decls_len, new_decl);3291 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...@@ -3600,7 +3600,7 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
3600 const alloc = try sema.resolveInst(inst_data.operand);3600 const alloc = try sema.resolveInst(inst_data.operand);
3601 const alloc_ty = sema.typeOf(alloc);3601 const alloc_ty = sema.typeOf(alloc);
3602 const ptr_info = alloc_ty.ptrInfo(mod);3602 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
3605 if (try sema.resolveComptimeKnownAllocValue(block, alloc, null)) |val| {3605 if (try sema.resolveComptimeKnownAllocValue(block, alloc, null)) |val| {
3606 const new_mut_ptr = Air.internedToRef((try mod.intern(.{ .ptr = .{3606 const new_mut_ptr = Air.internedToRef((try mod.intern(.{ .ptr = .{
...@@ -3652,7 +3652,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re...@@ -3652,7 +3652,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
36523652
3653 const alloc_ty = resolved_alloc_ty orelse sema.typeOf(alloc);3653 const alloc_ty = resolved_alloc_ty orelse sema.typeOf(alloc);
3654 const ptr_info = alloc_ty.ptrInfo(mod);3654 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
3657 const alloc_inst = Air.refToIndex(alloc) orelse return null;3657 const alloc_inst = Air.refToIndex(alloc) orelse return null;
3658 const comptime_info = sema.maybe_comptime_allocs.fetchRemove(alloc_inst) orelse return null;3658 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...@@ -3803,7 +3803,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
3803 .index = field_idx,3803 .index = field_idx,
3804 } },3804 } },
3805 } }),3805 } }),
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(),
3807 };3807 };
3808 try ptr_mapping.put(air_ptr, new_ptr);3808 try ptr_mapping.put(air_ptr, new_ptr);
3809 }3809 }
...@@ -3823,7 +3823,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re...@@ -3823,7 +3823,7 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
3823 if (try sema.typeHasOnePossibleValue(payload_ty)) |payload_val| {3823 if (try sema.typeHasOnePossibleValue(payload_ty)) |payload_val| {
3824 const new_ptr = ptr_mapping.get(air_ptr_inst).?;3824 const new_ptr = ptr_mapping.get(air_ptr_inst).?;
3825 const store_val = try mod.unionValue(union_ty, tag_val, payload_val);3825 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);
3827 }3827 }
3828 },3828 },
3829 .store, .store_safe => {3829 .store, .store_safe => {
...@@ -3831,14 +3831,14 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re...@@ -3831,14 +3831,14 @@ fn resolveComptimeKnownAllocValue(sema: *Sema, block: *Block, alloc: Air.Inst.Re
3831 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;3831 const air_ptr_inst = Air.refToIndex(bin_op.lhs).?;
3832 const store_val = (try sema.resolveValue(bin_op.rhs)).?;3832 const store_val = (try sema.resolveValue(bin_op.rhs)).?;
3833 const new_ptr = ptr_mapping.get(air_ptr_inst).?;3833 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())));
3835 },3835 },
3836 else => unreachable,3836 else => unreachable,
3837 }3837 }
3838 }3838 }
38393839
3840 // The value is finalized - load it!3840 // 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();
3842 return sema.finishResolveComptimeKnownAllocValue(val, alloc_inst, comptime_info.value);3842 return sema.finishResolveComptimeKnownAllocValue(val, alloc_inst, comptime_info.value);
3843}3843}
38443844
...@@ -6757,8 +6757,8 @@ fn checkCallArgumentCount(...@@ -6757,8 +6757,8 @@ fn checkCallArgumentCount(
6757 .Fn => break :func_ty callee_ty,6757 .Fn => break :func_ty callee_ty,
6758 .Pointer => {6758 .Pointer => {
6759 const ptr_info = callee_ty.ptrInfo(mod);6759 const ptr_info = callee_ty.ptrInfo(mod);
6760 if (ptr_info.flags.size == .One and ptr_info.child.toType().zigTypeTag(mod) == .Fn) {6760 if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn) {
6761 break :func_ty ptr_info.child.toType();6761 break :func_ty Type.fromInterned(ptr_info.child);
6762 }6762 }
6763 },6763 },
6764 .Optional => {6764 .Optional => {
...@@ -6831,8 +6831,8 @@ fn callBuiltin(...@@ -6831,8 +6831,8 @@ fn callBuiltin(
6831 .Fn => break :func_ty callee_ty,6831 .Fn => break :func_ty callee_ty,
6832 .Pointer => {6832 .Pointer => {
6833 const ptr_info = callee_ty.ptrInfo(mod);6833 const ptr_info = callee_ty.ptrInfo(mod);
6834 if (ptr_info.flags.size == .One and ptr_info.child.toType().zigTypeTag(mod) == .Fn) {6834 if (ptr_info.flags.size == .One and Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Fn) {
6835 break :func_ty ptr_info.child.toType();6835 break :func_ty Type.fromInterned(ptr_info.child);
6836 }6836 }
6837 },6837 },
6838 else => {},6838 else => {},
...@@ -7179,14 +7179,14 @@ fn analyzeCall(...@@ -7179,14 +7179,14 @@ fn analyzeCall(
7179 var is_comptime_call = block.is_comptime or modifier == .compile_time;7179 var is_comptime_call = block.is_comptime or modifier == .compile_time;
7180 var comptime_reason: ?*const Block.ComptimeReason = null;7180 var comptime_reason: ?*const Block.ComptimeReason = null;
7181 if (!is_comptime_call) {7181 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| {
7183 is_comptime_call = ct;7183 is_comptime_call = ct;
7184 if (ct) {7184 if (ct) {
7185 comptime_reason = &.{ .comptime_ret_ty = .{7185 comptime_reason = &.{ .comptime_ret_ty = .{
7186 .block = block,7186 .block = block,
7187 .func = func,7187 .func = func,
7188 .func_src = func_src,7188 .func_src = func_src,
7189 .return_ty = func_ty_info.return_type.toType(),7189 .return_ty = Type.fromInterned(func_ty_info.return_type),
7190 } };7190 } };
7191 }7191 }
7192 } else |err| switch (err) {7192 } else |err| switch (err) {
...@@ -7234,7 +7234,7 @@ fn analyzeCall(...@@ -7234,7 +7234,7 @@ fn analyzeCall(
7234 .block = block,7234 .block = block,
7235 .func = func,7235 .func = func,
7236 .func_src = func_src,7236 .func_src = func_src,
7237 .return_ty = func_ty_info.return_type.toType(),7237 .return_ty = Type.fromInterned(func_ty_info.return_type),
7238 } };7238 } };
7239 },7239 },
7240 else => |e| return e,7240 else => |e| return e,
...@@ -7431,10 +7431,10 @@ fn analyzeCall(...@@ -7431,10 +7431,10 @@ fn analyzeCall(
7431 const ies = try sema.arena.create(InferredErrorSet);7431 const ies = try sema.arena.create(InferredErrorSet);
7432 ies.* = .{ .func = .none };7432 ies.* = .{ .func = .none };
7433 sema.fn_ret_ty_ies = ies;7433 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 = .{
7435 .error_set_type = .adhoc_inferred_error_set_type,7435 .error_set_type = .adhoc_inferred_error_set_type,
7436 .payload_type = sema.fn_ret_ty.toIntern(),7436 .payload_type = sema.fn_ret_ty.toIntern(),
7437 } })).toType();7437 } })));
7438 }7438 }
74397439
7440 // This `res2` is here instead of directly breaking from `res` due to a stage17440 // This `res2` is here instead of directly breaking from `res` due to a stage1
...@@ -7529,7 +7529,7 @@ fn analyzeCall(...@@ -7529,7 +7529,7 @@ fn analyzeCall(
7529 if (new_ty != .none) {7529 if (new_ty != .none) {
7530 // TODO: mutate in place the previous instruction if possible7530 // TODO: mutate in place the previous instruction if possible
7531 // rather than adding a bitcast instruction.7531 // 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);
7533 }7533 }
75347534
7535 break :res2 result;7535 break :res2 result;
...@@ -7543,8 +7543,8 @@ fn analyzeCall(...@@ -7543,8 +7543,8 @@ fn analyzeCall(
7543 for (args, 0..) |*arg_out, arg_idx| {7543 for (args, 0..) |*arg_out, arg_idx| {
7544 // Non-generic, so param types are already resolved7544 // Non-generic, so param types are already resolved
7545 const param_ty = if (arg_idx < func_ty_info.param_types.len) ty: {7545 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();7546 break :ty Type.fromInterned(func_ty_info.param_types.get(ip)[arg_idx]);
7547 } else InternPool.Index.var_args_param_type.toType();7547 } else Type.fromInterned(InternPool.Index.var_args_param_type);
7548 assert(!param_ty.isGenericPoison());7548 assert(!param_ty.isGenericPoison());
7549 arg_out.* = try args_info.analyzeArg(sema, block, arg_idx, param_ty, func_ty_info, func);7549 arg_out.* = try args_info.analyzeArg(sema, block, arg_idx, param_ty, func_ty_info, func);
7550 if (sema.typeOf(arg_out.*).zigTypeTag(mod) == .NoReturn) {7550 if (sema.typeOf(arg_out.*).zigTypeTag(mod) == .NoReturn) {
...@@ -7554,8 +7554,8 @@ fn analyzeCall(...@@ -7554,8 +7554,8 @@ fn analyzeCall(
75547554
7555 if (call_dbg_node) |some| try sema.zirDbgStmt(block, some);7555 if (call_dbg_node) |some| try sema.zirDbgStmt(block, some);
75567556
7557 try sema.queueFullTypeResolution(func_ty_info.return_type.toType());7557 try sema.queueFullTypeResolution(Type.fromInterned(func_ty_info.return_type));
7558 if (sema.owner_func_index != .none and func_ty_info.return_type.toType().isError(mod)) {7558 if (sema.owner_func_index != .none and Type.fromInterned(func_ty_info.return_type).isError(mod)) {
7559 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;7559 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;
7560 }7560 }
75617561
...@@ -7670,12 +7670,12 @@ fn analyzeInlineCallArg(...@@ -7670,12 +7670,12 @@ fn analyzeInlineCallArg(
7670 break :param_ty param_ty.toIntern();7670 break :param_ty param_ty.toIntern();
7671 };7671 };
7672 new_param_types[arg_i.*] = param_ty;7672 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);
7674 if (ics.caller().typeOf(casted_arg).zigTypeTag(mod) == .NoReturn) {7674 if (ics.caller().typeOf(casted_arg).zigTypeTag(mod) == .NoReturn) {
7675 return casted_arg;7675 return casted_arg;
7676 }7676 }
7677 const arg_src = args_info.argSrc(arg_block, arg_i.*);7677 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))) {
7679 _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{7679 _ = try ics.caller().resolveConstValue(arg_block, arg_src, casted_arg, .{
7680 .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known",7680 .needed_comptime_reason = "argument to parameter with comptime-only type must be comptime-known",
7681 .block_comptime_reason = param_block.comptime_reason,7681 .block_comptime_reason = param_block.comptime_reason,
...@@ -7705,7 +7705,7 @@ fn analyzeInlineCallArg(...@@ -7705,7 +7705,7 @@ fn analyzeInlineCallArg(
7705 // when the hash function is called.7705 // when the hash function is called.
7706 const resolved_arg_val = try ics.caller().resolveLazyValue(arg_val);7706 const resolved_arg_val = try ics.caller().resolveLazyValue(arg_val);
7707 should_memoize.* = should_memoize.* and !resolved_arg_val.canMutateComptimeVarState(mod);7707 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);
7709 } else {7709 } else {
7710 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg);7710 ics.callee().inst_map.putAssumeCapacityNoClobber(inst, casted_arg);
7711 }7711 }
...@@ -7790,7 +7790,7 @@ fn instantiateGenericCall(...@@ -7790,7 +7790,7 @@ fn instantiateGenericCall(
7790 else => unreachable,7790 else => unreachable,
7791 };7791 };
7792 const generic_owner_func = mod.intern_pool.indexToKey(generic_owner).func;7792 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
7795 // Even though there may already be a generic instantiation corresponding7795 // Even though there may already be a generic instantiation corresponding
7796 // to this callsite, we must evaluate the expressions of the generic7796 // to this callsite, we must evaluate the expressions of the generic
...@@ -7862,7 +7862,7 @@ fn instantiateGenericCall(...@@ -7862,7 +7862,7 @@ fn instantiateGenericCall(
7862 const param_tag = fn_zir.instructions.items(.tag)[@intFromEnum(param_inst)];7862 const param_tag = fn_zir.instructions.items(.tag)[@intFromEnum(param_inst)];
78637863
7864 const param_ty = switch (generic_owner_ty_info.param_types.get(ip)[arg_index]) {7864 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 resolved7865 else => |ty| Type.fromInterned(ty), // parameter is not generic, so type is already resolved
7866 .generic_poison_type => param_ty: {7866 .generic_poison_type => param_ty: {
7867 // We have every parameter before this one, so can resolve this parameter's type now.7867 // We have every parameter before this one, so can resolve this parameter's type now.
7868 // However, first check the param type, since it may be anytype.7868 // However, first check the param type, since it may be anytype.
...@@ -7998,12 +7998,12 @@ fn instantiateGenericCall(...@@ -7998,12 +7998,12 @@ fn instantiateGenericCall(
7998 try sema.addReferencedBy(block, call_src, callee.owner_decl);7998 try sema.addReferencedBy(block, call_src, callee.owner_decl);
79997999
8000 // Make a runtime call to the new function, making sure to omit the comptime args.8000 // 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);
8002 const func_ty_info = mod.typeToFunc(func_ty).?;8002 const func_ty_info = mod.typeToFunc(func_ty).?;
80038003
8004 // If the call evaluated to a return type that requires comptime, never mind8004 // If the call evaluated to a return type that requires comptime, never mind
8005 // our generic instantiation. Instead we need to perform a comptime call.8005 // 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))) {
8007 return error.ComptimeReturn;8007 return error.ComptimeReturn;
8008 }8008 }
8009 // Similarly, if the call evaluated to a generic type we need to instead8009 // Similarly, if the call evaluated to a generic type we need to instead
...@@ -8012,12 +8012,12 @@ fn instantiateGenericCall(...@@ -8012,12 +8012,12 @@ fn instantiateGenericCall(
8012 return error.GenericPoison;8012 return error.GenericPoison;
8013 }8013 }
80148014
8015 try sema.queueFullTypeResolution(func_ty_info.return_type.toType());8015 try sema.queueFullTypeResolution(Type.fromInterned(func_ty_info.return_type));
80168016
8017 if (call_dbg_node) |some| try sema.zirDbgStmt(block, some);8017 if (call_dbg_node) |some| try sema.zirDbgStmt(block, some);
80188018
8019 if (sema.owner_func_index != .none and8019 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))
8021 {8021 {
8022 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;8022 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;
8023 }8023 }
...@@ -8057,10 +8057,10 @@ fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type)...@@ -8057,10 +8057,10 @@ fn resolveTupleLazyValues(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type)
8057 else => return,8057 else => return,
8058 };8058 };
8059 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, field_val| {8059 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));
8061 if (field_val == .none) continue;8061 if (field_val == .none) continue;
8062 // TODO: mutate in intern pool8062 // TODO: mutate in intern pool
8063 _ = try sema.resolveLazyValue(field_val.toValue());8063 _ = try sema.resolveLazyValue(Value.fromInterned(field_val));
8064 }8064 }
8065}8065}
80668066
...@@ -9217,7 +9217,7 @@ fn funcCommon(...@@ -9217,7 +9217,7 @@ fn funcCommon(
9217 const cc_resolved = cc orelse .Unspecified;9217 const cc_resolved = cc orelse .Unspecified;
9218 var comptime_bits: u32 = 0;9218 var comptime_bits: u32 = 0;
9219 for (block.params.items(.ty), block.params.items(.is_comptime), 0..) |param_ty_ip, param_is_comptime, i| {9219 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);
9221 const is_noalias = blk: {9221 const is_noalias = blk: {
9222 const index = std.math.cast(u5, i) orelse break :blk false;9222 const index = std.math.cast(u5, i) orelse break :blk false;
9223 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;9223 break :blk @as(u1, @truncate(noalias_bits >> index)) != 0;
...@@ -9529,7 +9529,7 @@ fn finishFunc(...@@ -9529,7 +9529,7 @@ fn finishFunc(
9529 const return_type: Type = if (opt_func_index == .none or ret_poison)9529 const return_type: Type = if (opt_func_index == .none or ret_poison)
9530 bare_return_type9530 bare_return_type
9531 else9531 else
9532 ip.funcTypeReturnType(ip.typeOf(opt_func_index)).toType();9532 Type.fromInterned(ip.funcTypeReturnType(ip.typeOf(opt_func_index)));
95339533
9534 if (!return_type.isValidReturnType(mod)) {9534 if (!return_type.isValidReturnType(mod)) {
9535 const opaque_str = if (return_type.zigTypeTag(mod) == .Opaque) "opaque " else "";9535 const opaque_str = if (return_type.zigTypeTag(mod) == .Opaque) "opaque " else "";
...@@ -10078,10 +10078,10 @@ fn intCast(...@@ -10078,10 +10078,10 @@ fn intCast(
10078 // range to account for negative values.10078 // range to account for negative values.
10079 const dest_range_val = if (wanted_info.signedness == .signed) range_val: {10079 const dest_range_val = if (wanted_info.signedness == .signed) range_val: {
10080 const one_scalar = try mod.intValue(unsigned_scalar_operand_ty, 1);10080 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 = .{
10082 .ty = unsigned_operand_ty.toIntern(),10082 .ty = unsigned_operand_ty.toIntern(),
10083 .storage = .{ .repeated_elem = one_scalar.toIntern() },10083 .storage = .{ .repeated_elem = one_scalar.toIntern() },
10084 } })).toValue() else one_scalar;10084 } }))) else one_scalar;
10085 const range_minus_one = try dest_max_val.shl(one, unsigned_operand_ty, sema.arena, mod);10085 const range_minus_one = try dest_max_val.shl(one, unsigned_operand_ty, sema.arena, mod);
10086 break :range_val try sema.intAdd(range_minus_one, one, unsigned_operand_ty, undefined);10086 break :range_val try sema.intAdd(range_minus_one, one, unsigned_operand_ty, undefined);
10087 } else try mod.getCoerced(dest_max_val, unsigned_operand_ty);10087 } else try mod.getCoerced(dest_max_val, unsigned_operand_ty);
...@@ -10734,7 +10734,7 @@ const SwitchProngAnalysis = struct {...@@ -10734,7 +10734,7 @@ const SwitchProngAnalysis = struct {
10734 if (operand_ty.zigTypeTag(mod) == .Union) {10734 if (operand_ty.zigTypeTag(mod) == .Union) {
10735 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?);10735 const field_index: u32 = @intCast(operand_ty.unionTagFieldIndex(item_val, mod).?);
10736 const union_obj = mod.typeToUnion(operand_ty).?;10736 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]);
10738 if (capture_byref) {10738 if (capture_byref) {
10739 const ptr_field_ty = try sema.ptrType(.{10739 const ptr_field_ty = try sema.ptrType(.{
10740 .child = field_ty.toIntern(),10740 .child = field_ty.toIntern(),
...@@ -10790,7 +10790,7 @@ const SwitchProngAnalysis = struct {...@@ -10790,7 +10790,7 @@ const SwitchProngAnalysis = struct {
10790 const first_item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;10790 const first_item_val = sema.resolveConstDefinedValue(block, .unneeded, case_vals[0], undefined) catch unreachable;
1079110791
10792 const first_field_index: u32 = mod.unionTagFieldIndex(union_obj, first_item_val).?;10792 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
10795 const field_indices = try sema.arena.alloc(u32, case_vals.len);10795 const field_indices = try sema.arena.alloc(u32, case_vals.len);
10796 for (case_vals, field_indices) |item, *field_idx| {10796 for (case_vals, field_indices) |item, *field_idx| {
...@@ -10801,7 +10801,7 @@ const SwitchProngAnalysis = struct {...@@ -10801,7 +10801,7 @@ const SwitchProngAnalysis = struct {
10801 // Fast path: if all the operands are the same type already, we don't need to hit10801 // Fast path: if all the operands are the same type already, we don't need to hit
10802 // PTR! This will also allow us to emit simpler code.10802 // PTR! This will also allow us to emit simpler code.
10803 const same_types = for (field_indices[1..]) |field_idx| {10803 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]);
10805 if (!field_ty.eql(first_field_ty, sema.mod)) break false;10805 if (!field_ty.eql(first_field_ty, sema.mod)) break false;
10806 } else true;10806 } else true;
1080710807
...@@ -10809,7 +10809,7 @@ const SwitchProngAnalysis = struct {...@@ -10809,7 +10809,7 @@ const SwitchProngAnalysis = struct {
10809 // We need values to run PTR on, so make a bunch of undef constants.10809 // We need values to run PTR on, so make a bunch of undef constants.
10810 const dummy_captures = try sema.arena.alloc(Air.Inst.Ref, case_vals.len);10810 const dummy_captures = try sema.arena.alloc(Air.Inst.Ref, case_vals.len);
10811 for (dummy_captures, field_indices) |*dummy, field_idx| {10811 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]);
10813 dummy.* = try mod.undefRef(field_ty);10813 dummy.* = try mod.undefRef(field_ty);
10814 }10814 }
1081510815
...@@ -10857,7 +10857,7 @@ const SwitchProngAnalysis = struct {...@@ -10857,7 +10857,7 @@ const SwitchProngAnalysis = struct {
10857 // pointer type is in-memory coercible to the capture pointer type.10857 // pointer type is in-memory coercible to the capture pointer type.
10858 if (!same_types) {10858 if (!same_types) {
10859 for (field_indices, 0..) |field_idx, i| {10859 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]);
10861 const field_ptr_ty = try sema.ptrType(.{10861 const field_ptr_ty = try sema.ptrType(.{
10862 .child = field_ty.toIntern(),10862 .child = field_ty.toIntern(),
10863 .flags = .{10863 .flags = .{
...@@ -10906,7 +10906,7 @@ const SwitchProngAnalysis = struct {...@@ -10906,7 +10906,7 @@ const SwitchProngAnalysis = struct {
10906 if (try sema.resolveDefinedValue(block, operand_src, spa.operand)) |operand_val| {10906 if (try sema.resolveDefinedValue(block, operand_src, spa.operand)) |operand_val| {
10907 if (operand_val.isUndef(mod)) return mod.undefRef(capture_ty);10907 if (operand_val.isUndef(mod)) return mod.undefRef(capture_ty);
10908 const union_val = ip.indexToKey(operand_val.toIntern()).un;10908 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);
10910 const uncoerced = Air.internedToRef(union_val.val);10910 const uncoerced = Air.internedToRef(union_val.val);
10911 return sema.coerce(block, capture_ty, uncoerced, operand_src);10911 return sema.coerce(block, capture_ty, uncoerced, operand_src);
10912 }10912 }
...@@ -10921,7 +10921,7 @@ const SwitchProngAnalysis = struct {...@@ -10921,7 +10921,7 @@ const SwitchProngAnalysis = struct {
10921 // If we can, try to avoid that using in-memory coercions.10921 // If we can, try to avoid that using in-memory coercions.
10922 const first_non_imc = in_mem: {10922 const first_non_imc = in_mem: {
10923 for (field_indices, 0..) |field_idx, i| {10923 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]);
10925 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, sema.mod.getTarget(), .unneeded, .unneeded)) {10925 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, sema.mod.getTarget(), .unneeded, .unneeded)) {
10926 break :in_mem i;10926 break :in_mem i;
10927 }10927 }
...@@ -10944,7 +10944,7 @@ const SwitchProngAnalysis = struct {...@@ -10944,7 +10944,7 @@ const SwitchProngAnalysis = struct {
10944 {10944 {
10945 const next = first_non_imc + 1;10945 const next = first_non_imc + 1;
10946 for (field_indices[next..], next..) |field_idx, i| {10946 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]);
10948 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, sema.mod.getTarget(), .unneeded, .unneeded)) {10948 if (.ok != try sema.coerceInMemoryAllowed(block, capture_ty, field_ty, false, sema.mod.getTarget(), .unneeded, .unneeded)) {
10949 in_mem_coercible.unset(i);10949 in_mem_coercible.unset(i);
10950 }10950 }
...@@ -10975,7 +10975,7 @@ const SwitchProngAnalysis = struct {...@@ -10975,7 +10975,7 @@ const SwitchProngAnalysis = struct {
10975 defer coerce_block.instructions.deinit(sema.gpa);10975 defer coerce_block.instructions.deinit(sema.gpa);
1097610976
10977 const field_idx = field_indices[idx];10977 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]);
10979 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, field_idx, field_ty);10979 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, field_idx, field_ty);
10980 const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) {10980 const coerced = sema.coerce(&coerce_block, capture_ty, uncoerced, .unneeded) catch |err| switch (err) {
10981 error.NeededSourceLocation => {10981 error.NeededSourceLocation => {
...@@ -11004,7 +11004,7 @@ const SwitchProngAnalysis = struct {...@@ -11004,7 +11004,7 @@ const SwitchProngAnalysis = struct {
1100411004
11005 const first_imc_item_idx = in_mem_coercible.findFirstSet().?;11005 const first_imc_item_idx = in_mem_coercible.findFirstSet().?;
11006 const first_imc_field_idx = field_indices[first_imc_item_idx];11006 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]);
11008 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, first_imc_field_idx, first_imc_field_ty);11008 const uncoerced = try coerce_block.addStructFieldVal(spa.operand, first_imc_field_idx, first_imc_field_ty);
11009 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);11009 const coerced = try coerce_block.addBitCast(capture_ty, uncoerced);
11010 _ = try coerce_block.addBr(capture_block_inst, coerced);11010 _ = 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...@@ -12510,7 +12510,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index, operand_is_r
12510 for (seen_enum_fields, 0..) |seen_field, index| {12510 for (seen_enum_fields, 0..) |seen_field, index| {
12511 if (seen_field != null) continue;12511 if (seen_field != null) continue;
12512 const union_obj = mod.typeToUnion(maybe_union_ty).?;12512 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]);
12514 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;12514 if (field_ty.zigTypeTag(mod) != .NoReturn) break true;
12515 } else false12515 } else false
12516 else12516 else
...@@ -12609,7 +12609,7 @@ const RangeSetUnhandledIterator = struct {...@@ -12609,7 +12609,7 @@ const RangeSetUnhandledIterator = struct {
12609 inline .u64, .i64 => |val_int| {12609 inline .u64, .i64 => |val_int| {
12610 const next_int = @addWithOverflow(val_int, 1);12610 const next_int = @addWithOverflow(val_int, 1);
12611 if (next_int[1] == 0)12611 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();
12613 },12613 },
12614 .big_int => {},12614 .big_int => {},
12615 .lazy_align, .lazy_size => unreachable,12615 .lazy_align, .lazy_size => unreachable,
...@@ -12625,7 +12625,7 @@ const RangeSetUnhandledIterator = struct {...@@ -12625,7 +12625,7 @@ const RangeSetUnhandledIterator = struct {
12625 );12625 );
1262612626
12627 result_bigint.addScalar(val_bigint, 1);12627 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();
12629 }12629 }
1263012630
12631 fn next(it: *RangeSetUnhandledIterator) !?InternPool.Index {12631 fn next(it: *RangeSetUnhandledIterator) !?InternPool.Index {
...@@ -12704,7 +12704,7 @@ fn validateSwitchRange(...@@ -12704,7 +12704,7 @@ fn validateSwitchRange(
12704 const mod = sema.mod;12704 const mod = sema.mod;
12705 const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, src_node_offset, switch_prong_src, .first);12705 const first = try sema.resolveSwitchItemVal(block, first_ref, operand_ty, src_node_offset, switch_prong_src, .first);
12706 const last = try sema.resolveSwitchItemVal(block, last_ref, operand_ty, src_node_offset, switch_prong_src, .last);12706 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)) {
12708 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), src_node_offset, .first);12708 const src = switch_prong_src.resolve(mod, mod.declPtr(block.src_decl), src_node_offset, .first);
12709 return sema.fail(block, src, "range start value is greater than the end value", .{});12709 return sema.fail(block, src, "range start value is greater than the end value", .{});
12710 }12710 }
...@@ -12815,7 +12815,7 @@ fn validateSwitchItemBool(...@@ -12815,7 +12815,7 @@ fn validateSwitchItemBool(
12815) CompileError!Air.Inst.Ref {12815) CompileError!Air.Inst.Ref {
12816 const mod = sema.mod;12816 const mod = sema.mod;
12817 const item = try sema.resolveSwitchItemVal(block, item_ref, Type.bool, src_node_offset, switch_prong_src, .none);12817 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()) {
12819 true_count.* += 1;12819 true_count.* += 1;
12820 } else {12820 } else {
12821 false_count.* += 1;12821 false_count.* += 1;
...@@ -13645,7 +13645,7 @@ fn analyzeTupleCat(...@@ -13645,7 +13645,7 @@ fn analyzeTupleCat(
13645 try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty);13645 try sema.tupleFieldValByIndex(block, operand_src, rhs, i, rhs_ty);
13646 }13646 }
1364713647
13648 return block.addAggregateInit(tuple_ty.toType(), element_refs);13648 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);
13649}13649}
1365013650
13651fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {13651fn 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...@@ -13875,17 +13875,17 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
13875 .needed_comptime_reason = "slice value being concatenated must be comptime-known",13875 .needed_comptime_reason = "slice value being concatenated must be comptime-known",
13876 });13876 });
13877 return Type.ArrayInfo{13877 return Type.ArrayInfo{
13878 .elem_type = ptr_info.child.toType(),13878 .elem_type = Type.fromInterned(ptr_info.child),
13879 .sentinel = switch (ptr_info.sentinel) {13879 .sentinel = switch (ptr_info.sentinel) {
13880 .none => null,13880 .none => null,
13881 else => ptr_info.sentinel.toValue(),13881 else => Value.fromInterned(ptr_info.sentinel),
13882 },13882 },
13883 .len = val.sliceLen(mod),13883 .len = val.sliceLen(mod),
13884 };13884 };
13885 },13885 },
13886 .One => {13886 .One => {
13887 if (ptr_info.child.toType().zigTypeTag(mod) == .Array) {13887 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {
13888 return ptr_info.child.toType().arrayInfo(mod);13888 return Type.fromInterned(ptr_info.child).arrayInfo(mod);
13889 }13889 }
13890 },13890 },
13891 .C => {},13891 .C => {},
...@@ -13974,7 +13974,7 @@ fn analyzeTupleMul(...@@ -13974,7 +13974,7 @@ fn analyzeTupleMul(
13974 @memcpy(element_refs[tuple_len * i ..][0..tuple_len], element_refs[0..tuple_len]);13974 @memcpy(element_refs[tuple_len * i ..][0..tuple_len], element_refs[0..tuple_len]);
13975 }13975 }
1397613976
13977 return block.addAggregateInit(tuple_ty.toType(), element_refs);13977 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);
13978}13978}
1397913979
13980fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {13980fn 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....@@ -14972,10 +14972,10 @@ fn zirModRem(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
14972 .ComptimeInt, .Int => try mod.intValue(resolved_type.scalarType(mod), 0),14972 .ComptimeInt, .Int => try mod.intValue(resolved_type.scalarType(mod), 0),
14973 else => unreachable,14973 else => unreachable,
14974 };14974 };
14975 const zero_val = if (is_vector) (try mod.intern(.{ .aggregate = .{14975 const zero_val = if (is_vector) Value.fromInterned((try mod.intern(.{ .aggregate = .{
14976 .ty = resolved_type.toIntern(),14976 .ty = resolved_type.toIntern(),
14977 .storage = .{ .repeated_elem = scalar_zero.toIntern() },14977 .storage = .{ .repeated_elem = scalar_zero.toIntern() },
14978 } })).toValue() else scalar_zero;14978 } }))) else scalar_zero;
14979 return Air.internedToRef(zero_val.toIntern());14979 return Air.internedToRef(zero_val.toIntern());
14980 }14980 }
14981 } else if (lhs_scalar_ty.isSignedInt(mod)) {14981 } else if (lhs_scalar_ty.isSignedInt(mod)) {
...@@ -15058,10 +15058,10 @@ fn intRem(...@@ -15058,10 +15058,10 @@ fn intRem(
15058 const rhs_elem = try rhs.elemValue(mod, i);15058 const rhs_elem = try rhs.elemValue(mod, i);
15059 scalar.* = try (try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod);15059 scalar.* = try (try sema.intRemScalar(lhs_elem, rhs_elem, scalar_ty)).intern(scalar_ty, mod);
15060 }15060 }
15061 return (try mod.intern(.{ .aggregate = .{15061 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
15062 .ty = ty.toIntern(),15062 .ty = ty.toIntern(),
15063 .storage = .{ .elems = result_data },15063 .storage = .{ .elems = result_data },
15064 } })).toValue();15064 } })));
15065 }15065 }
15066 return sema.intRemScalar(lhs, rhs, ty);15066 return sema.intRemScalar(lhs, rhs, ty);
15067}15067}
...@@ -15335,7 +15335,7 @@ fn zirOverflowArithmetic(...@@ -15335,7 +15335,7 @@ fn zirOverflowArithmetic(
15335 const maybe_rhs_val = try sema.resolveValue(rhs);15335 const maybe_rhs_val = try sema.resolveValue(rhs);
1533615336
15337 const tuple_ty = try sema.overflowArithmeticTupleType(dest_ty);15337 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
15340 var result: struct {15340 var result: struct {
15341 inst: Air.Inst.Ref = .none,15341 inst: Air.Inst.Ref = .none,
...@@ -15504,7 +15504,7 @@ fn splat(sema: *Sema, ty: Type, val: Value) !Value {...@@ -15504,7 +15504,7 @@ fn splat(sema: *Sema, ty: Type, val: Value) !Value {
15504 .ty = ty.toIntern(),15504 .ty = ty.toIntern(),
15505 .storage = .{ .repeated_elem = val.toIntern() },15505 .storage = .{ .repeated_elem = val.toIntern() },
15506 } });15506 } });
15507 return repeated.toValue();15507 return Value.fromInterned(repeated);
15508}15508}
1550915509
15510fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {15510fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
...@@ -15522,7 +15522,7 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {...@@ -15522,7 +15522,7 @@ fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
15522 .values = &values,15522 .values = &values,
15523 .names = &.{},15523 .names = &.{},
15524 });15524 });
15525 return tuple_ty.toType();15525 return Type.fromInterned(tuple_ty);
15526}15526}
1552715527
15528fn analyzeArithmetic(15528fn analyzeArithmetic(
...@@ -16036,7 +16036,7 @@ fn analyzePtrArithmetic(...@@ -16036,7 +16036,7 @@ fn analyzePtrArithmetic(
16036 }16036 }
16037 // If the addend is not a comptime-known value we can still count on16037 // If the addend is not a comptime-known value we can still count on
16038 // it being a multiple of the type size.16038 // 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);
16040 const addend = if (opt_off_val) |off_val| a: {16040 const addend = if (opt_off_val) |off_val| a: {
16041 const off_int = try sema.usizeCast(block, offset_src, off_val.toUnsignedInt(mod));16041 const off_int = try sema.usizeCast(block, offset_src, off_val.toUnsignedInt(mod));
16042 break :a elem_size * off_int;16042 break :a elem_size * off_int;
...@@ -16073,7 +16073,7 @@ fn analyzePtrArithmetic(...@@ -16073,7 +16073,7 @@ fn analyzePtrArithmetic(
16073 const offset_int = try sema.usizeCast(block, offset_src, offset_val.toUnsignedInt(mod));16073 const offset_int = try sema.usizeCast(block, offset_src, offset_val.toUnsignedInt(mod));
16074 if (offset_int == 0) return ptr;16074 if (offset_int == 0) return ptr;
16075 if (try ptr_val.getUnsignedIntAdvanced(mod, sema)) |addr| {16075 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);
16077 const new_addr = switch (air_tag) {16077 const new_addr = switch (air_tag) {
16078 .ptr_add => addr + elem_size * offset_int,16078 .ptr_add => addr + elem_size * offset_int,
16079 .ptr_sub => addr - elem_size * offset_int,16079 .ptr_sub => addr - elem_size * offset_int,
...@@ -16748,7 +16748,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!...@@ -16748,7 +16748,7 @@ fn zirClosureGet(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
1674816748
16749 assert(block.is_typeof);16749 assert(block.is_typeof);
16750 // We need a dummy runtime instruction with the correct type.16750 // 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));
16752}16752}
1675316753
16754fn zirRetAddr(16754fn zirRetAddr(
...@@ -17042,7 +17042,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17042,7 +17042,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17042 const alignment = if (info.flags.alignment.toByteUnitsOptional()) |alignment|17042 const alignment = if (info.flags.alignment.toByteUnitsOptional()) |alignment|
17043 try mod.intValue(Type.comptime_int, alignment)17043 try mod.intValue(Type.comptime_int, alignment)
17044 else17044 else
17045 try info.child.toType().lazyAbiAlignment(mod);17045 try Type.fromInterned(info.child).lazyAbiAlignment(mod);
1704617046
17047 const addrspace_ty = try sema.getBuiltinType("AddressSpace");17047 const addrspace_ty = try sema.getBuiltinType("AddressSpace");
17048 const pointer_ty = t: {17048 const pointer_ty = t: {
...@@ -17086,7 +17086,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17086,7 +17086,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17086 // sentinel: ?*const anyopaque,17086 // sentinel: ?*const anyopaque,
17087 (try sema.optRefValue(switch (info.sentinel) {17087 (try sema.optRefValue(switch (info.sentinel) {
17088 .none => null,17088 .none => null,
17089 else => info.sentinel.toValue(),17089 else => Value.fromInterned(info.sentinel),
17090 })).toIntern(),17090 })).toIntern(),
17091 };17091 };
17092 return Air.internedToRef((try mod.intern(.{ .un = .{17092 return Air.internedToRef((try mod.intern(.{ .un = .{
...@@ -17630,10 +17630,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17630,10 +17630,10 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17630 } });17630 } });
17631 };17631 };
1763217632
17633 try sema.resolveTypeLayout(field_ty.toType());17633 try sema.resolveTypeLayout(Type.fromInterned(field_ty));
1763417634
17635 const is_comptime = field_val != .none;17635 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;
17637 const default_val_ptr = try sema.optRefValue(opt_default_val);17637 const default_val_ptr = try sema.optRefValue(opt_default_val);
17638 const struct_field_fields = .{17638 const struct_field_fields = .{
17639 // name: []const u8,17639 // name: []const u8,
...@@ -17645,7 +17645,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17645,7 +17645,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17645 // is_comptime: bool,17645 // is_comptime: bool,
17646 Value.makeBool(is_comptime).toIntern(),17646 Value.makeBool(is_comptime).toIntern(),
17647 // alignment: comptime_int,17647 // 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(),
17649 };17649 };
17650 struct_field_val.* = try mod.intern(.{ .aggregate = .{17650 struct_field_val.* = try mod.intern(.{ .aggregate = .{
17651 .ty = struct_field_ty.toIntern(),17651 .ty = struct_field_ty.toIntern(),
...@@ -17667,7 +17667,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17667,7 +17667,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17667 try sema.arena.dupe(u8, ip.stringToSlice(name_nts))17667 try sema.arena.dupe(u8, ip.stringToSlice(name_nts))
17668 else17668 else
17669 try std.fmt.allocPrintZ(sema.arena, "{d}", .{i});17669 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]);
17671 const field_init = struct_type.fieldInit(ip, i);17671 const field_init = struct_type.fieldInit(ip, i);
17672 const field_is_comptime = struct_type.fieldIsComptime(ip, i);17672 const field_is_comptime = struct_type.fieldIsComptime(ip, i);
17673 const name_val = v: {17673 const name_val = v: {
...@@ -17689,7 +17689,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17689,7 +17689,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17689 } });17689 } });
17690 };17690 };
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);
17693 const default_val_ptr = try sema.optRefValue(opt_default_val);17693 const default_val_ptr = try sema.optRefValue(opt_default_val);
17694 const alignment = switch (struct_type.layout) {17694 const alignment = switch (struct_type.layout) {
17695 .Packed => .none,17695 .Packed => .none,
...@@ -17750,7 +17750,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17750,7 +17750,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17750 const backing_integer_val = try mod.intern(.{ .opt = .{17750 const backing_integer_val = try mod.intern(.{ .opt = .{
17751 .ty = (try mod.optionalType(.type_type)).toIntern(),17751 .ty = (try mod.optionalType(.type_type)).toIntern(),
17752 .val = if (mod.typeToPackedStruct(ty)) |packed_struct| val: {17752 .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));
17754 break :val packed_struct.backingIntType(ip).*;17754 break :val packed_struct.backingIntType(ip).*;
17755 } else .none,17755 } else .none,
17756 } });17756 } });
...@@ -19145,7 +19145,7 @@ fn unionInit(...@@ -19145,7 +19145,7 @@ fn unionInit(
19145 const mod = sema.mod;19145 const mod = sema.mod;
19146 const ip = &mod.intern_pool;19146 const ip = &mod.intern_pool;
19147 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_src);19147 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]);
19149 const init = try sema.coerce(block, field_ty, uncasted_init, init_src);19149 const init = try sema.coerce(block, field_ty, uncasted_init, init_src);
1915019150
19151 if (try sema.resolveValue(init)) |init_val| {19151 if (try sema.resolveValue(init)) |init_val| {
...@@ -19256,7 +19256,7 @@ fn zirStructInit(...@@ -19256,7 +19256,7 @@ fn zirStructInit(
19256 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);19256 const field_index = try sema.unionFieldIndex(block, resolved_ty, field_name, field_src);
19257 const tag_ty = resolved_ty.unionTagTypeHypothetical(mod);19257 const tag_ty = resolved_ty.unionTagTypeHypothetical(mod);
19258 const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index);19258 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
19261 if (field_ty.zigTypeTag(mod) == .NoReturn) {19261 if (field_ty.zigTypeTag(mod) == .NoReturn) {
19262 return sema.failWithOwnedErrorMsg(block, msg: {19262 return sema.failWithOwnedErrorMsg(block, msg: {
...@@ -19275,11 +19275,11 @@ fn zirStructInit(...@@ -19275,11 +19275,11 @@ fn zirStructInit(
19275 const init_inst = try sema.coerce(block, field_ty, uncoerced_init_inst, field_src);19275 const init_inst = try sema.coerce(block, field_ty, uncoerced_init_inst, field_src);
1927619276
19277 if (try sema.resolveValue(init_inst)) |val| {19277 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 = .{
19279 .ty = resolved_ty.toIntern(),19279 .ty = resolved_ty.toIntern(),
19280 .tag = try tag_val.intern(tag_ty, mod),19280 .tag = try tag_val.intern(tag_ty, mod),
19281 .val = try val.intern(field_ty, mod),19281 .val = try val.intern(field_ty, mod),
19282 } })).toValue();19282 } })));
19283 const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val.toIntern()), src);19283 const final_val_inst = try sema.coerce(block, result_ty, Air.internedToRef(struct_val.toIntern()), src);
19284 const final_val = (try sema.resolveValue(final_val_inst)).?;19284 const final_val = (try sema.resolveValue(final_val_inst)).?;
19285 return sema.addConstantMaybeRef(final_val.toIntern(), is_ref);19285 return sema.addConstantMaybeRef(final_val.toIntern(), is_ref);
...@@ -19336,7 +19336,7 @@ fn finishStructInit(...@@ -19336,7 +19336,7 @@ fn finishStructInit(
19336 for (0..anon_struct.types.len) |i| {19336 for (0..anon_struct.types.len) |i| {
19337 if (field_inits[i] != .none) {19337 if (field_inits[i] != .none) {
19338 // Coerce the init value to the field type.19338 // 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]);
19340 field_inits[i] = sema.coerce(block, field_ty, field_inits[i], .unneeded) catch |err| switch (err) {19340 field_inits[i] = sema.coerce(block, field_ty, field_inits[i], .unneeded) catch |err| switch (err) {
19341 error.NeededSourceLocation => {19341 error.NeededSourceLocation => {
19342 const decl = mod.declPtr(block.src_decl);19342 const decl = mod.declPtr(block.src_decl);
...@@ -19378,7 +19378,7 @@ fn finishStructInit(...@@ -19378,7 +19378,7 @@ fn finishStructInit(
19378 for (0..struct_type.field_types.len) |i| {19378 for (0..struct_type.field_types.len) |i| {
19379 if (field_inits[i] != .none) {19379 if (field_inits[i] != .none) {
19380 // Coerce the init value to the field type.19380 // 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]);
19382 field_inits[i] = sema.coerce(block, field_ty, field_inits[i], init_src) catch |err| switch (err) {19382 field_inits[i] = sema.coerce(block, field_ty, field_inits[i], init_src) catch |err| switch (err) {
19383 error.NeededSourceLocation => {19383 error.NeededSourceLocation => {
19384 const decl = mod.declPtr(block.src_decl);19384 const decl = mod.declPtr(block.src_decl);
...@@ -19548,20 +19548,20 @@ fn structInitAnon(...@@ -19548,20 +19548,20 @@ fn structInitAnon(
1954819548
19549 const init = try sema.resolveInst(item.data.init);19549 const init = try sema.resolveInst(item.data.init);
19550 field_ty.* = sema.typeOf(init).toIntern();19550 field_ty.* = sema.typeOf(init).toIntern();
19551 if (field_ty.toType().zigTypeTag(mod) == .Opaque) {19551 if (Type.fromInterned(field_ty.*).zigTypeTag(mod) == .Opaque) {
19552 const msg = msg: {19552 const msg = msg: {
19553 const decl = mod.declPtr(block.src_decl);19553 const decl = mod.declPtr(block.src_decl);
19554 const field_src = mod.initSrc(src.node_offset.x, decl, @intCast(i_usize));19554 const field_src = mod.initSrc(src.node_offset.x, decl, @intCast(i_usize));
19555 const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});19555 const msg = try sema.errMsg(block, field_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
19556 errdefer msg.destroy(sema.gpa);19556 errdefer msg.destroy(sema.gpa);
1955719557
19558 try sema.addDeclaredHereNote(msg, field_ty.toType());19558 try sema.addDeclaredHereNote(msg, Type.fromInterned(field_ty.*));
19559 break :msg msg;19559 break :msg msg;
19560 };19560 };
19561 return sema.failWithOwnedErrorMsg(block, msg);19561 return sema.failWithOwnedErrorMsg(block, msg);
19562 }19562 }
19563 if (try sema.resolveValue(init)) |init_val| {19563 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);
19565 } else {19565 } else {
19566 field_val.* = .none;19566 field_val.* = .none;
19567 runtime_index = @intCast(i_usize);19567 runtime_index = @intCast(i_usize);
...@@ -19635,7 +19635,7 @@ fn structInitAnon(...@@ -19635,7 +19635,7 @@ fn structInitAnon(
19635 element_refs[i] = try sema.resolveInst(item.data.init);19635 element_refs[i] = try sema.resolveInst(item.data.init);
19636 }19636 }
1963719637
19638 return block.addAggregateInit(tuple_ty.toType(), element_refs);19638 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);
19639}19639}
1964019640
19641fn zirArrayInit(19641fn zirArrayInit(
...@@ -19836,12 +19836,12 @@ fn arrayInitAnon(...@@ -19836,12 +19836,12 @@ fn arrayInitAnon(
19836 const operand_src = src; // TODO better source location19836 const operand_src = src; // TODO better source location
19837 const elem = try sema.resolveInst(operand);19837 const elem = try sema.resolveInst(operand);
19838 types[i] = sema.typeOf(elem).toIntern();19838 types[i] = sema.typeOf(elem).toIntern();
19839 if (types[i].toType().zigTypeTag(mod) == .Opaque) {19839 if (Type.fromInterned(types[i]).zigTypeTag(mod) == .Opaque) {
19840 const msg = msg: {19840 const msg = msg: {
19841 const msg = try sema.errMsg(block, operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});19841 const msg = try sema.errMsg(block, operand_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
19842 errdefer msg.destroy(gpa);19842 errdefer msg.destroy(gpa);
1984319843
19844 try sema.addDeclaredHereNote(msg, types[i].toType());19844 try sema.addDeclaredHereNote(msg, Type.fromInterned(types[i]));
19845 break :msg msg;19845 break :msg msg;
19846 };19846 };
19847 return sema.failWithOwnedErrorMsg(block, msg);19847 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -19899,7 +19899,7 @@ fn arrayInitAnon(...@@ -19899,7 +19899,7 @@ fn arrayInitAnon(
19899 element_refs[i] = try sema.resolveInst(operand);19899 element_refs[i] = try sema.resolveInst(operand);
19900 }19900 }
1990119901
19902 return block.addAggregateInit(tuple_ty.toType(), element_refs);19902 return block.addAggregateInit(Type.fromInterned(tuple_ty), element_refs);
19903}19903}
1990419904
19905fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.Inst.Ref {19905fn addConstantMaybeRef(sema: *Sema, val: InternPool.Index, is_ref: bool) !Air.Inst.Ref {
...@@ -19979,7 +19979,7 @@ fn fieldType(...@@ -19979,7 +19979,7 @@ fn fieldType(
19979 .Optional => {19979 .Optional => {
19980 // Struct/array init through optional requires the child type to not be a pointer.19980 // Struct/array init through optional requires the child type to not be a pointer.
19981 // If the child of .optional is a pointer it'll error on the next loop.19981 // 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);
19983 continue;19983 continue;
19984 },19984 },
19985 .ErrorUnion => {19985 .ErrorUnion => {
...@@ -20294,8 +20294,8 @@ fn zirReify(...@@ -20294,8 +20294,8 @@ fn zirReify(
20294 });20294 });
20295 const union_val = ip.indexToKey(val.toIntern()).un;20295 const union_val = ip.indexToKey(val.toIntern()).un;
20296 const target = mod.getTarget();20296 const target = mod.getTarget();
20297 if (try union_val.val.toValue().anyUndef(mod)) return sema.failWithUseOfUndef(block, src);20297 if (try Value.fromInterned(union_val.val).anyUndef(mod)) return sema.failWithUseOfUndef(block, src);
20298 const tag_index = type_info_ty.unionTagFieldIndex(union_val.tag.toValue(), mod).?;20298 const tag_index = type_info_ty.unionTagFieldIndex(Value.fromInterned(union_val.tag), mod).?;
20299 switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) {20299 switch (@as(std.builtin.TypeId, @enumFromInt(tag_index))) {
20300 .Type => return .type_type,20300 .Type => return .type_type,
20301 .Void => return .void_type,20301 .Void => return .void_type,
...@@ -20309,11 +20309,11 @@ fn zirReify(...@@ -20309,11 +20309,11 @@ fn zirReify(
20309 .EnumLiteral => return .enum_literal_type,20309 .EnumLiteral => return .enum_literal_type,
20310 .Int => {20310 .Int => {
20311 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;20311 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(
20313 mod,20313 mod,
20314 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "signedness")).?,20314 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "signedness")).?,
20315 );20315 );
20316 const bits_val = try union_val.val.toValue().fieldValue(20316 const bits_val = try Value.fromInterned(union_val.val).fieldValue(
20317 mod,20317 mod,
20318 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "bits")).?,20318 struct_type.nameIndex(ip, try ip.getOrPutString(gpa, "bits")).?,
20319 );20319 );
...@@ -20325,11 +20325,11 @@ fn zirReify(...@@ -20325,11 +20325,11 @@ fn zirReify(
20325 },20325 },
20326 .Vector => {20326 .Vector => {
20327 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;20327 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(
20329 ip,20329 ip,
20330 try ip.getOrPutString(gpa, "len"),20330 try ip.getOrPutString(gpa, "len"),
20331 ).?);20331 ).?);
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(
20333 ip,20333 ip,
20334 try ip.getOrPutString(gpa, "child"),20334 try ip.getOrPutString(gpa, "child"),
20335 ).?);20335 ).?);
...@@ -20347,7 +20347,7 @@ fn zirReify(...@@ -20347,7 +20347,7 @@ fn zirReify(
20347 },20347 },
20348 .Float => {20348 .Float => {
20349 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;20349 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(
20351 ip,20351 ip,
20352 try ip.getOrPutString(gpa, "bits"),20352 try ip.getOrPutString(gpa, "bits"),
20353 ).?);20353 ).?);
...@@ -20365,35 +20365,35 @@ fn zirReify(...@@ -20365,35 +20365,35 @@ fn zirReify(
20365 },20365 },
20366 .Pointer => {20366 .Pointer => {
20367 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;20367 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(
20369 ip,20369 ip,
20370 try ip.getOrPutString(gpa, "size"),20370 try ip.getOrPutString(gpa, "size"),
20371 ).?);20371 ).?);
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(
20373 ip,20373 ip,
20374 try ip.getOrPutString(gpa, "is_const"),20374 try ip.getOrPutString(gpa, "is_const"),
20375 ).?);20375 ).?);
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(
20377 ip,20377 ip,
20378 try ip.getOrPutString(gpa, "is_volatile"),20378 try ip.getOrPutString(gpa, "is_volatile"),
20379 ).?);20379 ).?);
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(
20381 ip,20381 ip,
20382 try ip.getOrPutString(gpa, "alignment"),20382 try ip.getOrPutString(gpa, "alignment"),
20383 ).?);20383 ).?);
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(
20385 ip,20385 ip,
20386 try ip.getOrPutString(gpa, "address_space"),20386 try ip.getOrPutString(gpa, "address_space"),
20387 ).?);20387 ).?);
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(
20389 ip,20389 ip,
20390 try ip.getOrPutString(gpa, "child"),20390 try ip.getOrPutString(gpa, "child"),
20391 ).?);20391 ).?);
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(
20393 ip,20393 ip,
20394 try ip.getOrPutString(gpa, "is_allowzero"),20394 try ip.getOrPutString(gpa, "is_allowzero"),
20395 ).?);20395 ).?);
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(
20397 ip,20397 ip,
20398 try ip.getOrPutString(gpa, "sentinel"),20398 try ip.getOrPutString(gpa, "sentinel"),
20399 ).?);20399 ).?);
...@@ -20477,15 +20477,15 @@ fn zirReify(...@@ -20477,15 +20477,15 @@ fn zirReify(
20477 },20477 },
20478 .Array => {20478 .Array => {
20479 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;20479 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(
20481 ip,20481 ip,
20482 try ip.getOrPutString(gpa, "len"),20482 try ip.getOrPutString(gpa, "len"),
20483 ).?);20483 ).?);
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(
20485 ip,20485 ip,
20486 try ip.getOrPutString(gpa, "child"),20486 try ip.getOrPutString(gpa, "child"),
20487 ).?);20487 ).?);
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(
20489 ip,20489 ip,
20490 try ip.getOrPutString(gpa, "sentinel"),20490 try ip.getOrPutString(gpa, "sentinel"),
20491 ).?);20491 ).?);
...@@ -20506,7 +20506,7 @@ fn zirReify(...@@ -20506,7 +20506,7 @@ fn zirReify(
20506 },20506 },
20507 .Optional => {20507 .Optional => {
20508 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;20508 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(
20510 ip,20510 ip,
20511 try ip.getOrPutString(gpa, "child"),20511 try ip.getOrPutString(gpa, "child"),
20512 ).?);20512 ).?);
...@@ -20518,11 +20518,11 @@ fn zirReify(...@@ -20518,11 +20518,11 @@ fn zirReify(
20518 },20518 },
20519 .ErrorUnion => {20519 .ErrorUnion => {
20520 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;20520 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(
20522 ip,20522 ip,
20523 try ip.getOrPutString(gpa, "error_set"),20523 try ip.getOrPutString(gpa, "error_set"),
20524 ).?);20524 ).?);
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(
20526 ip,20526 ip,
20527 try ip.getOrPutString(gpa, "payload"),20527 try ip.getOrPutString(gpa, "payload"),
20528 ).?);20528 ).?);
...@@ -20538,7 +20538,7 @@ fn zirReify(...@@ -20538,7 +20538,7 @@ fn zirReify(
20538 return Air.internedToRef(ty.toIntern());20538 return Air.internedToRef(ty.toIntern());
20539 },20539 },
20540 .ErrorSet => {20540 .ErrorSet => {
20541 const payload_val = union_val.val.toValue().optionalValue(mod) orelse20541 const payload_val = Value.fromInterned(union_val.val).optionalValue(mod) orelse
20542 return Air.internedToRef(Type.anyerror.toIntern());20542 return Air.internedToRef(Type.anyerror.toIntern());
2054320543
20544 const len = try sema.usizeCast(block, src, payload_val.sliceLen(mod));20544 const len = try sema.usizeCast(block, src, payload_val.sliceLen(mod));
...@@ -20567,23 +20567,23 @@ fn zirReify(...@@ -20567,23 +20567,23 @@ fn zirReify(
20567 },20567 },
20568 .Struct => {20568 .Struct => {
20569 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;20569 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(
20571 ip,20571 ip,
20572 try ip.getOrPutString(gpa, "layout"),20572 try ip.getOrPutString(gpa, "layout"),
20573 ).?);20573 ).?);
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(
20575 ip,20575 ip,
20576 try ip.getOrPutString(gpa, "backing_integer"),20576 try ip.getOrPutString(gpa, "backing_integer"),
20577 ).?);20577 ).?);
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(
20579 ip,20579 ip,
20580 try ip.getOrPutString(gpa, "fields"),20580 try ip.getOrPutString(gpa, "fields"),
20581 ).?);20581 ).?);
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(
20583 ip,20583 ip,
20584 try ip.getOrPutString(gpa, "decls"),20584 try ip.getOrPutString(gpa, "decls"),
20585 ).?);20585 ).?);
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(
20587 ip,20587 ip,
20588 try ip.getOrPutString(gpa, "is_tuple"),20588 try ip.getOrPutString(gpa, "is_tuple"),
20589 ).?);20589 ).?);
...@@ -20603,19 +20603,19 @@ fn zirReify(...@@ -20603,19 +20603,19 @@ fn zirReify(
20603 },20603 },
20604 .Enum => {20604 .Enum => {
20605 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;20605 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(
20607 ip,20607 ip,
20608 try ip.getOrPutString(gpa, "tag_type"),20608 try ip.getOrPutString(gpa, "tag_type"),
20609 ).?);20609 ).?);
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(
20611 ip,20611 ip,
20612 try ip.getOrPutString(gpa, "fields"),20612 try ip.getOrPutString(gpa, "fields"),
20613 ).?);20613 ).?);
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(
20615 ip,20615 ip,
20616 try ip.getOrPutString(gpa, "decls"),20616 try ip.getOrPutString(gpa, "decls"),
20617 ).?);20617 ).?);
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(
20619 ip,20619 ip,
20620 try ip.getOrPutString(gpa, "is_exhaustive"),20620 try ip.getOrPutString(gpa, "is_exhaustive"),
20621 ).?);20621 ).?);
...@@ -20662,7 +20662,7 @@ fn zirReify(...@@ -20662,7 +20662,7 @@ fn zirReify(
20662 //errdefer ip.remove(incomplete_enum.index);20662 //errdefer ip.remove(incomplete_enum.index);
2066320663
20664 new_decl.ty = Type.type;20664 new_decl.ty = Type.type;
20665 new_decl.val = incomplete_enum.index.toValue();20665 new_decl.val = Value.fromInterned(incomplete_enum.index);
2066620666
20667 for (0..fields_len) |field_i| {20667 for (0..fields_len) |field_i| {
20668 const elem_val = try fields_val.elemValue(mod, field_i);20668 const elem_val = try fields_val.elemValue(mod, field_i);
...@@ -20718,7 +20718,7 @@ fn zirReify(...@@ -20718,7 +20718,7 @@ fn zirReify(
20718 },20718 },
20719 .Opaque => {20719 .Opaque => {
20720 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;20720 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(
20722 ip,20722 ip,
20723 try ip.getOrPutString(gpa, "decls"),20723 try ip.getOrPutString(gpa, "decls"),
20724 ).?);20724 ).?);
...@@ -20759,8 +20759,8 @@ fn zirReify(...@@ -20759,8 +20759,8 @@ fn zirReify(
20759 //errdefer ip.remove(opaque_ty);20759 //errdefer ip.remove(opaque_ty);
2076020760
20761 new_decl.ty = Type.type;20761 new_decl.ty = Type.type;
20762 new_decl.val = opaque_ty.toValue();20762 new_decl.val = Value.fromInterned(opaque_ty);
20763 new_namespace.ty = opaque_ty.toType();20763 new_namespace.ty = Type.fromInterned(opaque_ty);
2076420764
20765 const decl_val = sema.analyzeDeclVal(block, src, new_decl_index);20765 const decl_val = sema.analyzeDeclVal(block, src, new_decl_index);
20766 try mod.finalizeAnonDecl(new_decl_index);20766 try mod.finalizeAnonDecl(new_decl_index);
...@@ -20768,19 +20768,19 @@ fn zirReify(...@@ -20768,19 +20768,19 @@ fn zirReify(
20768 },20768 },
20769 .Union => {20769 .Union => {
20770 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;20770 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(
20772 ip,20772 ip,
20773 try ip.getOrPutString(gpa, "layout"),20773 try ip.getOrPutString(gpa, "layout"),
20774 ).?);20774 ).?);
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(
20776 ip,20776 ip,
20777 try ip.getOrPutString(gpa, "tag_type"),20777 try ip.getOrPutString(gpa, "tag_type"),
20778 ).?);20778 ).?);
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(
20780 ip,20780 ip,
20781 try ip.getOrPutString(gpa, "fields"),20781 try ip.getOrPutString(gpa, "fields"),
20782 ).?);20782 ).?);
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(
20784 ip,20784 ip,
20785 try ip.getOrPutString(gpa, "decls"),20785 try ip.getOrPutString(gpa, "decls"),
20786 ).?);20786 ).?);
...@@ -20847,10 +20847,10 @@ fn zirReify(...@@ -20847,10 +20847,10 @@ fn zirReify(
20847 const msg = msg: {20847 const msg = msg: {
20848 const msg = try sema.errMsg(block, src, "no field named '{}' in enum '{}'", .{20848 const msg = try sema.errMsg(block, src, "no field named '{}' in enum '{}'", .{
20849 field_name.fmt(ip),20849 field_name.fmt(ip),
20850 enum_tag_ty.toType().fmt(mod),20850 Type.fromInterned(enum_tag_ty).fmt(mod),
20851 });20851 });
20852 errdefer msg.destroy(gpa);20852 errdefer msg.destroy(gpa);
20853 try sema.addDeclaredHereNote(msg, enum_tag_ty.toType());20853 try sema.addDeclaredHereNote(msg, Type.fromInterned(enum_tag_ty));
20854 break :msg msg;20854 break :msg msg;
20855 };20855 };
20856 return sema.failWithOwnedErrorMsg(block, msg);20856 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -20929,11 +20929,11 @@ fn zirReify(...@@ -20929,11 +20929,11 @@ fn zirReify(
2092920929
20930 for (tag_info.names.get(ip), 0..) |field_name, field_index| {20930 for (tag_info.names.get(ip), 0..) |field_name, field_index| {
20931 if (explicit_tags_seen[field_index]) continue;20931 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", .{
20933 field_name.fmt(ip),20933 field_name.fmt(ip),
20934 });20934 });
20935 }20935 }
20936 try sema.addDeclaredHereNote(msg, enum_tag_ty.toType());20936 try sema.addDeclaredHereNote(msg, Type.fromInterned(enum_tag_ty));
20937 break :msg msg;20937 break :msg msg;
20938 };20938 };
20939 return sema.failWithOwnedErrorMsg(block, msg);20939 return sema.failWithOwnedErrorMsg(block, msg);
...@@ -20993,8 +20993,8 @@ fn zirReify(...@@ -20993,8 +20993,8 @@ fn zirReify(
20993 });20993 });
2099420994
20995 new_decl.ty = Type.type;20995 new_decl.ty = Type.type;
20996 new_decl.val = union_ty.toValue();20996 new_decl.val = Value.fromInterned(union_ty);
20997 new_namespace.ty = union_ty.toType();20997 new_namespace.ty = Type.fromInterned(union_ty);
2099820998
20999 const decl_val = sema.analyzeDeclVal(block, src, new_decl_index);20999 const decl_val = sema.analyzeDeclVal(block, src, new_decl_index);
21000 try mod.finalizeAnonDecl(new_decl_index);21000 try mod.finalizeAnonDecl(new_decl_index);
...@@ -21002,27 +21002,27 @@ fn zirReify(...@@ -21002,27 +21002,27 @@ fn zirReify(
21002 },21002 },
21003 .Fn => {21003 .Fn => {
21004 const struct_type = ip.indexToKey(ip.typeOf(union_val.val)).struct_type;21004 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(
21006 ip,21006 ip,
21007 try ip.getOrPutString(gpa, "calling_convention"),21007 try ip.getOrPutString(gpa, "calling_convention"),
21008 ).?);21008 ).?);
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(
21010 ip,21010 ip,
21011 try ip.getOrPutString(gpa, "alignment"),21011 try ip.getOrPutString(gpa, "alignment"),
21012 ).?);21012 ).?);
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(
21014 ip,21014 ip,
21015 try ip.getOrPutString(gpa, "is_generic"),21015 try ip.getOrPutString(gpa, "is_generic"),
21016 ).?);21016 ).?);
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(
21018 ip,21018 ip,
21019 try ip.getOrPutString(gpa, "is_var_args"),21019 try ip.getOrPutString(gpa, "is_var_args"),
21020 ).?);21020 ).?);
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(
21022 ip,21022 ip,
21023 try ip.getOrPutString(gpa, "return_type"),21023 try ip.getOrPutString(gpa, "return_type"),
21024 ).?);21024 ).?);
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(
21026 ip,21026 ip,
21027 try ip.getOrPutString(gpa, "params"),21027 try ip.getOrPutString(gpa, "params"),
21028 ).?);21028 ).?);
...@@ -21075,7 +21075,7 @@ fn zirReify(...@@ -21075,7 +21075,7 @@ fn zirReify(
21075 param_type.* = param_type_val.toIntern();21075 param_type.* = param_type_val.toIntern();
2107621076
21077 if (param_is_noalias_val.toBool()) {21077 if (param_is_noalias_val.toBool()) {
21078 if (!param_type.toType().isPtrAtRuntime(mod)) {21078 if (!Type.fromInterned(param_type.*).isPtrAtRuntime(mod)) {
21079 return sema.fail(block, src, "non-pointer parameter declared noalias", .{});21079 return sema.fail(block, src, "non-pointer parameter declared noalias", .{});
21080 }21080 }
21081 noalias_bits |= @as(u32, 1) << (std.math.cast(u5, i) orelse21081 noalias_bits |= @as(u32, 1) << (std.math.cast(u5, i) orelse
...@@ -21158,7 +21158,7 @@ fn reifyStruct(...@@ -21158,7 +21158,7 @@ fn reifyStruct(
21158 const struct_type = ip.indexToKey(ty).struct_type;21158 const struct_type = ip.indexToKey(ty).struct_type;
2115921159
21160 new_decl.ty = Type.type;21160 new_decl.ty = Type.type;
21161 new_decl.val = ty.toValue();21161 new_decl.val = Value.fromInterned(ty);
2116221162
21163 // Fields21163 // Fields
21164 for (0..fields_len) |i| {21164 for (0..fields_len) |i| {
...@@ -21290,11 +21290,11 @@ fn reifyStruct(...@@ -21290,11 +21290,11 @@ fn reifyStruct(
2129021290
21291 if (layout == .Packed) {21291 if (layout == .Packed) {
21292 for (0..struct_type.field_types.len) |index| {21292 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]);
21294 sema.resolveTypeLayout(field_ty) catch |err| switch (err) {21294 sema.resolveTypeLayout(field_ty) catch |err| switch (err) {
21295 error.AnalysisFail => {21295 error.AnalysisFail => {
21296 const msg = sema.err orelse return err;21296 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", .{});
21298 return err;21298 return err;
21299 },21299 },
21300 else => return err,21300 else => return err,
...@@ -21303,7 +21303,7 @@ fn reifyStruct(...@@ -21303,7 +21303,7 @@ fn reifyStruct(
2130321303
21304 var fields_bit_sum: u64 = 0;21304 var fields_bit_sum: u64 = 0;
21305 for (0..struct_type.field_types.len) |i| {21305 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]);
21307 fields_bit_sum += field_ty.bitSize(mod);21307 fields_bit_sum += field_ty.bitSize(mod);
21308 }21308 }
2130921309
...@@ -21657,10 +21657,10 @@ fn ptrFromIntVal(...@@ -21657,10 +21657,10 @@ fn ptrFromIntVal(
21657 return sema.fail(block, operand_src, "pointer type '{}' requires aligned address", .{ptr_ty.fmt(sema.mod)});21657 return sema.fail(block, operand_src, "pointer type '{}' requires aligned address", .{ptr_ty.fmt(sema.mod)});
2165821658
21659 return switch (ptr_ty.zigTypeTag(mod)) {21659 return switch (ptr_ty.zigTypeTag(mod)) {
21660 .Optional => (try mod.intern(.{ .opt = .{21660 .Optional => Value.fromInterned((try mod.intern(.{ .opt = .{
21661 .ty = ptr_ty.toIntern(),21661 .ty = ptr_ty.toIntern(),
21662 .val = if (addr == 0) .none else (try mod.ptrIntValue(ptr_ty.childType(mod), addr)).toIntern(),21662 .val = if (addr == 0) .none else (try mod.ptrIntValue(ptr_ty.childType(mod), addr)).toIntern(),
21663 } })).toValue(),21663 } }))),
21664 .Pointer => try mod.ptrIntValue(ptr_ty, addr),21664 .Pointer => try mod.ptrIntValue(ptr_ty, addr),
21665 else => unreachable,21665 else => unreachable,
21666 };21666 };
...@@ -21849,14 +21849,14 @@ fn ptrCastFull(...@@ -21849,14 +21849,14 @@ fn ptrCastFull(
21849 const src_info = operand_ty.ptrInfo(mod);21849 const src_info = operand_ty.ptrInfo(mod);
21850 const dest_info = dest_ty.ptrInfo(mod);21850 const dest_info = dest_ty.ptrInfo(mod);
2185121851
21852 try sema.resolveTypeLayout(src_info.child.toType());21852 try sema.resolveTypeLayout(Type.fromInterned(src_info.child));
21853 try sema.resolveTypeLayout(dest_info.child.toType());21853 try sema.resolveTypeLayout(Type.fromInterned(dest_info.child));
2185421854
21855 const src_slice_like = src_info.flags.size == .Slice or21855 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
21858 const dest_slice_like = dest_info.flags.size == .Slice or21858 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
21861 if (dest_info.flags.size == .Slice and !src_slice_like) {21861 if (dest_info.flags.size == .Slice and !src_slice_like) {
21862 return sema.fail(block, src, "illegal pointer cast to slice", .{});21862 return sema.fail(block, src, "illegal pointer cast to slice", .{});
...@@ -21864,12 +21864,12 @@ fn ptrCastFull(...@@ -21864,12 +21864,12 @@ fn ptrCastFull(
2186421864
21865 if (dest_info.flags.size == .Slice) {21865 if (dest_info.flags.size == .Slice) {
21866 const src_elem_size = switch (src_info.flags.size) {21866 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),
21868 // pointer to array21868 // pointer to array
21869 .One => src_info.child.toType().childType(mod).abiSize(mod),21869 .One => Type.fromInterned(src_info.child).childType(mod).abiSize(mod),
21870 else => unreachable,21870 else => unreachable,
21871 };21871 };
21872 const dest_elem_size = dest_info.child.toType().abiSize(mod);21872 const dest_elem_size = Type.fromInterned(dest_info.child).abiSize(mod);
21873 if (src_elem_size != dest_elem_size) {21873 if (src_elem_size != dest_elem_size) {
21874 return sema.fail(block, src, "TODO: implement @ptrCast between slices changing the length", .{});21874 return sema.fail(block, src, "TODO: implement @ptrCast between slices changing the length", .{});
21875 }21875 }
...@@ -21891,7 +21891,7 @@ fn ptrCastFull(...@@ -21891,7 +21891,7 @@ fn ptrCastFull(
21891 errdefer msg.destroy(sema.gpa);21891 errdefer msg.destroy(sema.gpa);
21892 if (dest_info.flags.size == .Many and21892 if (dest_info.flags.size == .Many and
21893 (src_info.flags.size == .Slice or21893 (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)))
21895 {21895 {
21896 try sema.errNote(block, src, msg, "use 'ptr' field to convert slice to many pointer", .{});21896 try sema.errNote(block, src, msg, "use 'ptr' field to convert slice to many pointer", .{});
21897 } else {21897 } else {
...@@ -21904,10 +21904,10 @@ fn ptrCastFull(...@@ -21904,10 +21904,10 @@ fn ptrCastFull(
21904 check_child: {21904 check_child: {
21905 const src_child = if (dest_info.flags.size == .Slice and src_info.flags.size == .One) blk: {21905 const src_child = if (dest_info.flags.size == .Slice and src_info.flags.size == .One) blk: {
21906 // *[n]T -> []T21906 // *[n]T -> []T
21907 break :blk src_info.child.toType().childType(mod);21907 break :blk Type.fromInterned(src_info.child).childType(mod);
21908 } else src_info.child.toType();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
21912 const imc_res = try sema.coerceInMemoryAllowed(21912 const imc_res = try sema.coerceInMemoryAllowed(
21913 block,21913 block,
...@@ -21940,7 +21940,7 @@ fn ptrCastFull(...@@ -21940,7 +21940,7 @@ fn ptrCastFull(
21940 }21940 }
21941 if (src_slice_like and src_info.flags.size == .One and dest_info.flags.size == .Slice) {21941 if (src_slice_like and src_info.flags.size == .One and dest_info.flags.size == .Slice) {
21942 // [*]nT -> []T21942 // [*]nT -> []T
21943 const arr_ty = src_info.child.toType();21943 const arr_ty = Type.fromInterned(src_info.child);
21944 if (arr_ty.sentinel(mod)) |src_sentinel| {21944 if (arr_ty.sentinel(mod)) |src_sentinel| {
21945 const coerced_sent = try mod.intern_pool.getCoerced(sema.gpa, src_sentinel.toIntern(), dest_info.child);21945 const coerced_sent = try mod.intern_pool.getCoerced(sema.gpa, src_sentinel.toIntern(), dest_info.child);
21946 if (dest_info.sentinel == coerced_sent) break :check_sent;21946 if (dest_info.sentinel == coerced_sent) break :check_sent;
...@@ -21949,12 +21949,12 @@ fn ptrCastFull(...@@ -21949,12 +21949,12 @@ fn ptrCastFull(
21949 return sema.failWithOwnedErrorMsg(block, msg: {21949 return sema.failWithOwnedErrorMsg(block, msg: {
21950 const msg = if (src_info.sentinel == .none) blk: {21950 const msg = if (src_info.sentinel == .none) blk: {
21951 break :blk try sema.errMsg(block, src, "destination pointer requires '{}' sentinel", .{21951 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),
21953 });21953 });
21954 } else blk: {21954 } else blk: {
21955 break :blk try sema.errMsg(block, src, "pointer sentinel '{}' cannot coerce into pointer sentinel '{}'", .{21955 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),21956 Value.fromInterned(src_info.sentinel).fmtValue(Type.fromInterned(src_info.child), mod),
21957 dest_info.sentinel.toValue().fmtValue(dest_info.child.toType(), mod),21957 Value.fromInterned(dest_info.sentinel).fmtValue(Type.fromInterned(dest_info.child), mod),
21958 });21958 });
21959 };21959 };
21960 errdefer msg.destroy(sema.gpa);21960 errdefer msg.destroy(sema.gpa);
...@@ -22010,12 +22010,12 @@ fn ptrCastFull(...@@ -22010,12 +22010,12 @@ fn ptrCastFull(
22010 const src_align = if (src_info.flags.alignment != .none)22010 const src_align = if (src_info.flags.alignment != .none)
22011 src_info.flags.alignment22011 src_info.flags.alignment
22012 else22012 else
22013 src_info.child.toType().abiAlignment(mod);22013 Type.fromInterned(src_info.child).abiAlignment(mod);
2201422014
22015 const dest_align = if (dest_info.flags.alignment != .none)22015 const dest_align = if (dest_info.flags.alignment != .none)
22016 dest_info.flags.alignment22016 dest_info.flags.alignment
22017 else22017 else
22018 dest_info.child.toType().abiAlignment(mod);22018 Type.fromInterned(dest_info.child).abiAlignment(mod);
2201922019
22020 if (!flags.align_cast) {22020 if (!flags.align_cast) {
22021 if (dest_align.compare(.gt, src_align)) {22021 if (dest_align.compare(.gt, src_align)) {
...@@ -22123,7 +22123,7 @@ fn ptrCastFull(...@@ -22123,7 +22123,7 @@ fn ptrCastFull(
22123 }22123 }
22124 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {22124 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {
22125 if (ptr_val.isUndef(mod)) return mod.undefRef(dest_ty);22125 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));
22127 return Air.internedToRef((try mod.intern(.{ .ptr = .{22127 return Air.internedToRef((try mod.intern(.{ .ptr = .{
22128 .ty = dest_ty.toIntern(),22128 .ty = dest_ty.toIntern(),
22129 .addr = mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr.addr,22129 .addr = mod.intern_pool.indexToKey(ptr_val.toIntern()).ptr.addr,
...@@ -22139,7 +22139,7 @@ fn ptrCastFull(...@@ -22139,7 +22139,7 @@ fn ptrCastFull(
22139 try sema.requireRuntimeBlock(block, src, null);22139 try sema.requireRuntimeBlock(block, src, null);
2214022140
22141 if (block.wantSafety() and operand_ty.ptrAllowsZero(mod) and !dest_ty.ptrAllowsZero(mod) and22141 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))
22143 {22143 {
22144 const ptr_int = try block.addUnOp(.int_from_ptr, ptr);22144 const ptr_int = try block.addUnOp(.int_from_ptr, ptr);
22145 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);22145 const is_non_zero = try block.addBinOp(.cmp_neq, ptr_int, .zero_usize);
...@@ -22153,7 +22153,7 @@ fn ptrCastFull(...@@ -22153,7 +22153,7 @@ fn ptrCastFull(
2215322153
22154 if (block.wantSafety() and22154 if (block.wantSafety() and
22155 dest_align.compare(.gt, src_align) and22155 dest_align.compare(.gt, src_align) and
22156 try sema.typeHasRuntimeBits(dest_info.child.toType()))22156 try sema.typeHasRuntimeBits(Type.fromInterned(dest_info.child)))
22157 {22157 {
22158 const align_bytes_minus_1 = dest_align.toByteUnitsOptional().? - 1;22158 const align_bytes_minus_1 = dest_align.toByteUnitsOptional().? - 1;
22159 const align_minus_1 = Air.internedToRef((try mod.intValue(Type.usize, align_bytes_minus_1)).toIntern());22159 const align_minus_1 = Air.internedToRef((try mod.intValue(Type.usize, align_bytes_minus_1)).toIntern());
...@@ -22196,7 +22196,7 @@ fn ptrCastFull(...@@ -22196,7 +22196,7 @@ fn ptrCastFull(
22196 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {22196 if (dest_info.flags.size == .Slice and src_info.flags.size != .Slice) {
22197 // We have to construct a slice using the operand's child's array length22197 // We have to construct a slice using the operand's child's array length
22198 // Note that we know from the check at the start of the function that operand_ty is slice-like22198 // 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());
22200 return block.addInst(.{22200 return block.addInst(.{
22201 .tag = .slice,22201 .tag = .slice,
22202 .data = .{ .ty_pl = .{22202 .data = .{ .ty_pl = .{
...@@ -22549,7 +22549,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6...@@ -22549,7 +22549,7 @@ fn bitOffsetOf(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!u6
22549 if (i == field_index) {22549 if (i == field_index) {
22550 return bit_sum;22550 return bit_sum;
22551 }22551 }
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]);
22553 bit_sum += field_ty.bitSize(mod);22553 bit_sum += field_ty.bitSize(mod);
22554 } else unreachable;22554 } else unreachable;
22555 },22555 },
...@@ -23447,10 +23447,10 @@ fn analyzeShuffle(...@@ -23447,10 +23447,10 @@ fn analyzeShuffle(
2344723447
23448 if (a_len < b_len) {23448 if (a_len < b_len) {
23449 const undef = try mod.undefRef(a_ty);23449 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));
23451 } else {23451 } else {
23452 const undef = try mod.undefRef(b_ty);23452 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));
23454 }23454 }
23455 }23455 }
2345623456
...@@ -24546,10 +24546,10 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -24546,10 +24546,10 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
24546 const dest_elem_ty: Type = dest_elem_ty: {24546 const dest_elem_ty: Type = dest_elem_ty: {
24547 const ptr_info = dest_ptr_ty.ptrInfo(mod);24547 const ptr_info = dest_ptr_ty.ptrInfo(mod);
24548 switch (ptr_info.flags.size) {24548 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),
24550 .One => {24550 .One => {
24551 if (ptr_info.child.toType().zigTypeTag(mod) == .Array) {24551 if (Type.fromInterned(ptr_info.child).zigTypeTag(mod) == .Array) {
24552 break :dest_elem_ty ptr_info.child.toType().childType(mod);24552 break :dest_elem_ty Type.fromInterned(ptr_info.child).childType(mod);
24553 }24553 }
24554 },24554 },
24555 .Many, .C => {},24555 .Many, .C => {},
...@@ -24583,10 +24583,10 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -24583,10 +24583,10 @@ fn zirMemset(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
24583 .child = dest_elem_ty.toIntern(),24583 .child = dest_elem_ty.toIntern(),
24584 .len = len_u64,24584 .len = len_u64,
24585 });24585 });
24586 const array_val = (try mod.intern(.{ .aggregate = .{24586 const array_val = Value.fromInterned((try mod.intern(.{ .aggregate = .{
24587 .ty = array_ty.toIntern(),24587 .ty = array_ty.toIntern(),
24588 .storage = .{ .repeated_elem = elem_val.toIntern() },24588 .storage = .{ .repeated_elem = elem_val.toIntern() },
24589 } })).toValue();24589 } })));
24590 const array_ptr_ty = ty: {24590 const array_ptr_ty = ty: {
24591 var info = dest_ptr_ty.ptrInfo(mod);24591 var info = dest_ptr_ty.ptrInfo(mod);
24592 info.flags.size = .One;24592 info.flags.size = .One;
...@@ -25227,7 +25227,7 @@ fn zirBuiltinExtern(...@@ -25227,7 +25227,7 @@ fn zirBuiltinExtern(
25227 // We only access this decl through the decl_ref with the correct type created25227 // We only access this decl through the decl_ref with the correct type created
25228 // below, so this type doesn't matter25228 // below, so this type doesn't matter
25229 new_decl.ty = ty;25229 new_decl.ty = ty;
25230 new_decl.val = new_var.toValue();25230 new_decl.val = Value.fromInterned(new_var);
25231 new_decl.alignment = .none;25231 new_decl.alignment = .none;
25232 new_decl.@"linksection" = .none;25232 new_decl.@"linksection" = .none;
25233 new_decl.has_tv = true;25233 new_decl.has_tv = true;
...@@ -25237,14 +25237,14 @@ fn zirBuiltinExtern(...@@ -25237,14 +25237,14 @@ fn zirBuiltinExtern(
2523725237
25238 try sema.ensureDeclAnalyzed(new_decl_index);25238 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 = .{
25241 .ty = switch (mod.intern_pool.indexToKey(ty.toIntern())) {25241 .ty = switch (mod.intern_pool.indexToKey(ty.toIntern())) {
25242 .ptr_type => ty.toIntern(),25242 .ptr_type => ty.toIntern(),
25243 .opt_type => |child_type| child_type,25243 .opt_type => |child_type| child_type,
25244 else => unreachable,25244 else => unreachable,
25245 },25245 },
25246 .addr = .{ .decl = new_decl_index },25246 .addr = .{ .decl = new_decl_index },
25247 } })).toValue(), ty)).toIntern());25247 } }))), ty)).toIntern());
25248}25248}
2524925249
25250fn zirWorkItem(25250fn zirWorkItem(
...@@ -25430,7 +25430,7 @@ fn explainWhyTypeIsComptimeInner(...@@ -25430,7 +25430,7 @@ fn explainWhyTypeIsComptimeInner(
25430 .Inline => try mod.errNoteNonLazy(src_loc, msg, "function has inline calling convention", .{}),25430 .Inline => try mod.errNoteNonLazy(src_loc, msg, "function has inline calling convention", .{}),
25431 else => {},25431 else => {},
25432 }25432 }
25433 if (fn_info.return_type.toType().comptimeOnly(mod)) {25433 if (Type.fromInterned(fn_info.return_type).comptimeOnly(mod)) {
25434 try mod.errNoteNonLazy(src_loc, msg, "function has a comptime-only return type", .{});25434 try mod.errNoteNonLazy(src_loc, msg, "function has a comptime-only return type", .{});
25435 }25435 }
25436 return;25436 return;
...@@ -25450,7 +25450,7 @@ fn explainWhyTypeIsComptimeInner(...@@ -25450,7 +25450,7 @@ fn explainWhyTypeIsComptimeInner(
2545025450
25451 if (mod.typeToStruct(ty)) |struct_type| {25451 if (mod.typeToStruct(ty)) |struct_type| {
25452 for (0..struct_type.field_types.len) |i| {25452 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]);
25454 const field_src_loc = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{25454 const field_src_loc = mod.fieldSrcLoc(struct_type.decl.unwrap().?, .{
25455 .index = i,25455 .index = i,
25456 .range = .type,25456 .range = .type,
...@@ -25470,7 +25470,7 @@ fn explainWhyTypeIsComptimeInner(...@@ -25470,7 +25470,7 @@ fn explainWhyTypeIsComptimeInner(
2547025470
25471 if (mod.typeToUnion(ty)) |union_obj| {25471 if (mod.typeToUnion(ty)) |union_obj| {
25472 for (0..union_obj.field_types.len) |i| {25472 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]);
25474 const field_src_loc = mod.fieldSrcLoc(union_obj.decl, .{25474 const field_src_loc = mod.fieldSrcLoc(union_obj.decl, .{
25475 .index = i,25475 .index = i,
25476 .range = .type,25476 .range = .type,
...@@ -26096,7 +26096,7 @@ fn fieldVal(...@@ -26096,7 +26096,7 @@ fn fieldVal(
26096 } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) {26096 } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) {
26097 const ptr_info = object_ty.ptrInfo(mod);26097 const ptr_info = object_ty.ptrInfo(mod);
26098 const result_ty = try sema.ptrType(.{26098 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(),
26100 .sentinel = if (inner_ty.sentinel(mod)) |s| s.toIntern() else .none,26100 .sentinel = if (inner_ty.sentinel(mod)) |s| s.toIntern() else .none,
26101 .flags = .{26101 .flags = .{
26102 .size = .Many,26102 .size = .Many,
...@@ -26515,7 +26515,7 @@ fn fieldCallBind(...@@ -26515,7 +26515,7 @@ fn fieldCallBind(
26515 if (mod.typeToStruct(concrete_ty)) |struct_type| {26515 if (mod.typeToStruct(concrete_ty)) |struct_type| {
26516 const field_index = struct_type.nameIndex(ip, field_name) orelse26516 const field_index = struct_type.nameIndex(ip, field_name) orelse
26517 break :find_field;26517 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
26520 return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr);26520 return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr);
26521 } else if (concrete_ty.isTuple(mod)) {26521 } else if (concrete_ty.isTuple(mod)) {
...@@ -26540,7 +26540,7 @@ fn fieldCallBind(...@@ -26540,7 +26540,7 @@ fn fieldCallBind(
26540 try sema.resolveTypeFields(concrete_ty);26540 try sema.resolveTypeFields(concrete_ty);
26541 const union_obj = mod.typeToUnion(concrete_ty).?;26541 const union_obj = mod.typeToUnion(concrete_ty).?;
26542 const field_index = union_obj.nameIndex(ip, field_name) orelse break :find_field;26542 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
26545 return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr);26545 return sema.finishFieldCallBind(block, src, ptr_ty, field_ty, field_index, object_ptr);
26546 },26546 },
...@@ -26563,7 +26563,7 @@ fn fieldCallBind(...@@ -26563,7 +26563,7 @@ fn fieldCallBind(
26563 if (mod.typeToFunc(decl_type)) |func_type| f: {26563 if (mod.typeToFunc(decl_type)) |func_type| f: {
26564 if (func_type.param_types.len == 0) break :f;26564 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]);
26567 // zig fmt: off26567 // zig fmt: off
26568 if (first_param_type.isGenericPoison() or (26568 if (first_param_type.isGenericPoison() or (
26569 first_param_type.zigTypeTag(mod) == .Pointer and26569 first_param_type.zigTypeTag(mod) == .Pointer and
...@@ -26803,14 +26803,14 @@ fn structFieldPtrByIndex(...@@ -26803,14 +26803,14 @@ fn structFieldPtrByIndex(
26803 const parent_align = if (struct_ptr_ty_info.flags.alignment != .none)26803 const parent_align = if (struct_ptr_ty_info.flags.alignment != .none)
26804 struct_ptr_ty_info.flags.alignment26804 struct_ptr_ty_info.flags.alignment
26805 else26805 else
26806 try sema.typeAbiAlignment(struct_ptr_ty_info.child.toType());26806 try sema.typeAbiAlignment(Type.fromInterned(struct_ptr_ty_info.child));
2680726807
26808 if (struct_type.layout == .Packed) {26808 if (struct_type.layout == .Packed) {
26809 comptime assert(Type.packed_struct_layout_version == 2);26809 comptime assert(Type.packed_struct_layout_version == 2);
2681026810
26811 var running_bits: u16 = 0;26811 var running_bits: u16 = 0;
26812 for (0..struct_type.field_types.len) |i| {26812 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]);
26814 if (!(try sema.typeHasRuntimeBits(f_ty))) continue;26814 if (!(try sema.typeHasRuntimeBits(f_ty))) continue;
2681526815
26816 if (i == field_index) {26816 if (i == field_index) {
...@@ -26840,8 +26840,8 @@ fn structFieldPtrByIndex(...@@ -26840,8 +26840,8 @@ fn structFieldPtrByIndex(
26840 if (parent_align != .none and ptr_ty_data.packed_offset.bit_offset % 8 == 0 and26840 if (parent_align != .none and ptr_ty_data.packed_offset.bit_offset % 8 == 0 and
26841 target.cpu.arch.endian() == .little)26841 target.cpu.arch.endian() == .little)
26842 {26842 {
26843 const elem_size_bytes = try sema.typeAbiSize(ptr_ty_data.child.toType());26843 const elem_size_bytes = try sema.typeAbiSize(Type.fromInterned(ptr_ty_data.child));
26844 const elem_size_bits = ptr_ty_data.child.toType().bitSize(mod);26844 const elem_size_bits = Type.fromInterned(ptr_ty_data.child).bitSize(mod);
26845 if (elem_size_bytes * 8 == elem_size_bits) {26845 if (elem_size_bytes * 8 == elem_size_bits) {
26846 const byte_offset = ptr_ty_data.packed_offset.bit_offset / 8;26846 const byte_offset = ptr_ty_data.packed_offset.bit_offset / 8;
26847 const new_align: Alignment = @enumFromInt(@ctz(byte_offset | parent_align.toByteUnitsOptional().?));26847 const new_align: Alignment = @enumFromInt(@ctz(byte_offset | parent_align.toByteUnitsOptional().?));
...@@ -26863,7 +26863,7 @@ fn structFieldPtrByIndex(...@@ -26863,7 +26863,7 @@ fn structFieldPtrByIndex(
26863 // Our alignment is capped at the field alignment.26863 // Our alignment is capped at the field alignment.
26864 const field_align = try sema.structFieldAlignment(26864 const field_align = try sema.structFieldAlignment(
26865 struct_type.fieldAlign(ip, field_index),26865 struct_type.fieldAlign(ip, field_index),
26866 field_ty.toType(),26866 Type.fromInterned(field_ty),
26867 struct_type.layout,26867 struct_type.layout,
26868 );26868 );
26869 ptr_ty_data.flags.alignment = if (struct_ptr_ty_info.flags.alignment == .none)26869 ptr_ty_data.flags.alignment = if (struct_ptr_ty_info.flags.alignment == .none)
...@@ -26925,7 +26925,7 @@ fn structFieldVal(...@@ -26925,7 +26925,7 @@ fn structFieldVal(
26925 return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]);26925 return Air.internedToRef(struct_type.field_inits.get(ip)[field_index]);
26926 }26926 }
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
26930 if (try sema.resolveValue(struct_byval)) |struct_val| {26930 if (try sema.resolveValue(struct_byval)) |struct_val| {
26931 if (struct_val.isUndef(mod)) return mod.undefRef(field_ty);26931 if (struct_val.isUndef(mod)) return mod.undefRef(field_ty);
...@@ -27013,8 +27013,8 @@ fn tupleFieldValByIndex(...@@ -27013,8 +27013,8 @@ fn tupleFieldValByIndex(
27013 .undef => mod.undefRef(field_ty),27013 .undef => mod.undefRef(field_ty),
27014 .aggregate => |aggregate| Air.internedToRef(switch (aggregate.storage) {27014 .aggregate => |aggregate| Air.internedToRef(switch (aggregate.storage) {
27015 .bytes => |bytes| try mod.intValue(Type.u8, bytes[0]),27015 .bytes => |bytes| try mod.intValue(Type.u8, bytes[0]),
27016 .elems => |elems| elems[field_index].toValue(),27016 .elems => |elems| Value.fromInterned(elems[field_index]),
27017 .repeated_elem => |elem| elem.toValue(),27017 .repeated_elem => |elem| Value.fromInterned(elem),
27018 }.toIntern()),27018 }.toIntern()),
27019 else => unreachable,27019 else => unreachable,
27020 };27020 };
...@@ -27049,7 +27049,7 @@ fn unionFieldPtr(...@@ -27049,7 +27049,7 @@ fn unionFieldPtr(
27049 try sema.resolveTypeFields(union_ty);27049 try sema.resolveTypeFields(union_ty);
27050 const union_obj = mod.typeToUnion(union_ty).?;27050 const union_obj = mod.typeToUnion(union_ty).?;
27051 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);27051 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]);
27053 const ptr_field_ty = try sema.ptrType(.{27053 const ptr_field_ty = try sema.ptrType(.{
27054 .child = field_ty.toIntern(),27054 .child = field_ty.toIntern(),
27055 .flags = .{27055 .flags = .{
...@@ -27067,7 +27067,7 @@ fn unionFieldPtr(...@@ -27067,7 +27067,7 @@ fn unionFieldPtr(
27067 },27067 },
27068 .packed_offset = union_ptr_info.packed_offset,27068 .packed_offset = union_ptr_info.packed_offset,
27069 });27069 });
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
27072 if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) {27072 if (initializing and field_ty.zigTypeTag(mod) == .NoReturn) {
27073 const msg = msg: {27073 const msg = msg: {
...@@ -27092,12 +27092,12 @@ fn unionFieldPtr(...@@ -27092,12 +27092,12 @@ fn unionFieldPtr(
27092 return sema.failWithUseOfUndef(block, src);27092 return sema.failWithUseOfUndef(block, src);
27093 }27093 }
27094 const un = ip.indexToKey(union_val.toIntern()).un;27094 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);
27096 const tag_matches = un.tag == field_tag.toIntern();27096 const tag_matches = un.tag == field_tag.toIntern();
27097 if (!tag_matches) {27097 if (!tag_matches) {
27098 const msg = msg: {27098 const msg = msg: {
27099 const active_index = union_obj.enum_tag_ty.toType().enumTagFieldIndex(un.tag.toValue(), mod).?;27099 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?;
27100 const active_field_name = union_obj.enum_tag_ty.toType().enumFieldName(active_index, mod);27100 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod);
27101 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{27101 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{
27102 field_name.fmt(ip),27102 field_name.fmt(ip),
27103 active_field_name.fmt(ip),27103 active_field_name.fmt(ip),
...@@ -27124,11 +27124,11 @@ fn unionFieldPtr(...@@ -27124,11 +27124,11 @@ fn unionFieldPtr(
27124 if (!initializing and union_obj.getLayout(ip) == .Auto and block.wantSafety() and27124 if (!initializing and union_obj.getLayout(ip) == .Auto and block.wantSafety() and
27125 union_ty.unionTagTypeSafety(mod) != null and union_obj.field_names.len > 1)27125 union_ty.unionTagTypeSafety(mod) != null and union_obj.field_names.len > 1)
27126 {27126 {
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);
27128 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());27128 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());
27129 // TODO would it be better if get_union_tag supported pointers to unions?27129 // TODO would it be better if get_union_tag supported pointers to unions?
27130 const union_val = try block.addTyOp(.load, union_ty, union_ptr);27130 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);
27132 try sema.panicInactiveUnionField(block, src, active_tag, wanted_tag);27132 try sema.panicInactiveUnionField(block, src, active_tag, wanted_tag);
27133 }27133 }
27134 if (field_ty.zigTypeTag(mod) == .NoReturn) {27134 if (field_ty.zigTypeTag(mod) == .NoReturn) {
...@@ -27154,14 +27154,14 @@ fn unionFieldVal(...@@ -27154,14 +27154,14 @@ fn unionFieldVal(
27154 try sema.resolveTypeFields(union_ty);27154 try sema.resolveTypeFields(union_ty);
27155 const union_obj = mod.typeToUnion(union_ty).?;27155 const union_obj = mod.typeToUnion(union_ty).?;
27156 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);27156 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();27157 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
27158 const enum_field_index: u32 = @intCast(union_obj.enum_tag_ty.toType().enumFieldIndex(field_name, mod).?);27158 const enum_field_index: u32 = @intCast(Type.fromInterned(union_obj.enum_tag_ty).enumFieldIndex(field_name, mod).?);
2715927159
27160 if (try sema.resolveValue(union_byval)) |union_val| {27160 if (try sema.resolveValue(union_byval)) |union_val| {
27161 if (union_val.isUndef(mod)) return mod.undefRef(field_ty);27161 if (union_val.isUndef(mod)) return mod.undefRef(field_ty);
2716227162
27163 const un = ip.indexToKey(union_val.toIntern()).un;27163 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);
27165 const tag_matches = un.tag == field_tag.toIntern();27165 const tag_matches = un.tag == field_tag.toIntern();
27166 switch (union_obj.getLayout(ip)) {27166 switch (union_obj.getLayout(ip)) {
27167 .Auto => {27167 .Auto => {
...@@ -27169,8 +27169,8 @@ fn unionFieldVal(...@@ -27169,8 +27169,8 @@ fn unionFieldVal(
27169 return Air.internedToRef(un.val);27169 return Air.internedToRef(un.val);
27170 } else {27170 } else {
27171 const msg = msg: {27171 const msg = msg: {
27172 const active_index = union_obj.enum_tag_ty.toType().enumTagFieldIndex(un.tag.toValue(), mod).?;27172 const active_index = Type.fromInterned(union_obj.enum_tag_ty).enumTagFieldIndex(Value.fromInterned(un.tag), mod).?;
27173 const active_field_name = union_obj.enum_tag_ty.toType().enumFieldName(active_index, mod);27173 const active_field_name = Type.fromInterned(union_obj.enum_tag_ty).enumFieldName(active_index, mod);
27174 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{27174 const msg = try sema.errMsg(block, src, "access of union field '{}' while field '{}' is active", .{
27175 field_name.fmt(ip), active_field_name.fmt(ip),27175 field_name.fmt(ip), active_field_name.fmt(ip),
27176 });27176 });
...@@ -27186,11 +27186,11 @@ fn unionFieldVal(...@@ -27186,11 +27186,11 @@ fn unionFieldVal(
27186 return Air.internedToRef(un.val);27186 return Air.internedToRef(un.val);
27187 } else {27187 } else {
27188 const old_ty = if (un.tag == .none)27188 const old_ty = if (un.tag == .none)
27189 ip.typeOf(un.val).toType()27189 Type.fromInterned(ip.typeOf(un.val))
27190 else27190 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| {
27194 return Air.internedToRef(new_val.toIntern());27194 return Air.internedToRef(new_val.toIntern());
27195 }27195 }
27196 }27196 }
...@@ -27202,9 +27202,9 @@ fn unionFieldVal(...@@ -27202,9 +27202,9 @@ fn unionFieldVal(
27202 if (union_obj.getLayout(ip) == .Auto and block.wantSafety() and27202 if (union_obj.getLayout(ip) == .Auto and block.wantSafety() and
27203 union_ty.unionTagTypeSafety(mod) != null and union_obj.field_names.len > 1)27203 union_ty.unionTagTypeSafety(mod) != null and union_obj.field_names.len > 1)
27204 {27204 {
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);
27206 const wanted_tag = Air.internedToRef(wanted_tag_val.toIntern());27206 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);
27208 try sema.panicInactiveUnionField(block, src, active_tag, wanted_tag);27208 try sema.panicInactiveUnionField(block, src, active_tag, wanted_tag);
27209 }27209 }
27210 if (field_ty.zigTypeTag(mod) == .NoReturn) {27210 if (field_ty.zigTypeTag(mod) == .NoReturn) {
...@@ -27906,7 +27906,7 @@ fn coerceExtra(...@@ -27906,7 +27906,7 @@ fn coerceExtra(
27906 if (!inst_ty.isSinglePointer(mod)) break :single_item;27906 if (!inst_ty.isSinglePointer(mod)) break :single_item;
27907 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer;27907 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer;
27908 const ptr_elem_ty = inst_ty.childType(mod);27908 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);
27910 if (array_ty.zigTypeTag(mod) != .Array) break :single_item;27910 if (array_ty.zigTypeTag(mod) != .Array) break :single_item;
27911 const array_elem_ty = array_ty.childType(mod);27911 const array_elem_ty = array_ty.childType(mod);
27912 if (array_ty.arrayLen(mod) != 1) break :single_item;27912 if (array_ty.arrayLen(mod) != 1) break :single_item;
...@@ -27927,7 +27927,7 @@ fn coerceExtra(...@@ -27927,7 +27927,7 @@ fn coerceExtra(
27927 const array_elem_type = array_ty.childType(mod);27927 const array_elem_type = array_ty.childType(mod);
27928 const dest_is_mut = !dest_info.flags.is_const;27928 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);
27931 const elem_res = try sema.coerceInMemoryAllowed(block, dst_elem_type, array_elem_type, dest_is_mut, target, dest_ty_src, inst_src);27931 const elem_res = try sema.coerceInMemoryAllowed(block, dst_elem_type, array_elem_type, dest_is_mut, target, dest_ty_src, inst_src);
27932 switch (elem_res) {27932 switch (elem_res) {
27933 .ok => {},27933 .ok => {},
...@@ -27948,7 +27948,7 @@ fn coerceExtra(...@@ -27948,7 +27948,7 @@ fn coerceExtra(
27948 {27948 {
27949 in_memory_result = .{ .ptr_sentinel = .{27949 in_memory_result = .{ .ptr_sentinel = .{
27950 .actual = inst_sent,27950 .actual = inst_sent,
27951 .wanted = dest_info.sentinel.toValue(),27951 .wanted = Value.fromInterned(dest_info.sentinel),
27952 .ty = dst_elem_type,27952 .ty = dst_elem_type,
27953 } };27953 } };
27954 break :src_array_ptr;27954 break :src_array_ptr;
...@@ -27956,7 +27956,7 @@ fn coerceExtra(...@@ -27956,7 +27956,7 @@ fn coerceExtra(
27956 } else {27956 } else {
27957 in_memory_result = .{ .ptr_sentinel = .{27957 in_memory_result = .{ .ptr_sentinel = .{
27958 .actual = Value.@"unreachable",27958 .actual = Value.@"unreachable",
27959 .wanted = dest_info.sentinel.toValue(),27959 .wanted = Value.fromInterned(dest_info.sentinel),
27960 .ty = dst_elem_type,27960 .ty = dst_elem_type,
27961 } };27961 } };
27962 break :src_array_ptr;27962 break :src_array_ptr;
...@@ -27988,7 +27988,7 @@ fn coerceExtra(...@@ -27988,7 +27988,7 @@ fn coerceExtra(
27988 // could be null.27988 // could be null.
27989 const src_elem_ty = inst_ty.childType(mod);27989 const src_elem_ty = inst_ty.childType(mod);
27990 const dest_is_mut = !dest_info.flags.is_const;27990 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);
27992 switch (try sema.coerceInMemoryAllowed(block, dst_elem_type, src_elem_ty, dest_is_mut, target, dest_ty_src, inst_src)) {27992 switch (try sema.coerceInMemoryAllowed(block, dst_elem_type, src_elem_ty, dest_is_mut, target, dest_ty_src, inst_src)) {
27993 .ok => {},27993 .ok => {},
27994 else => break :src_c_ptr,27994 else => break :src_c_ptr,
...@@ -28053,8 +28053,8 @@ fn coerceExtra(...@@ -28053,8 +28053,8 @@ fn coerceExtra(
28053 const inst_info = inst_ty.ptrInfo(mod);28053 const inst_info = inst_ty.ptrInfo(mod);
28054 switch (try sema.coerceInMemoryAllowed(28054 switch (try sema.coerceInMemoryAllowed(
28055 block,28055 block,
28056 dest_info.child.toType(),28056 Type.fromInterned(dest_info.child),
28057 inst_info.child.toType(),28057 Type.fromInterned(inst_info.child),
28058 !dest_info.flags.is_const,28058 !dest_info.flags.is_const,
28059 target,28059 target,
28060 dest_ty_src,28060 dest_ty_src,
...@@ -28066,7 +28066,7 @@ fn coerceExtra(...@@ -28066,7 +28066,7 @@ fn coerceExtra(
28066 if (inst_info.flags.size == .Slice) {28066 if (inst_info.flags.size == .Slice) {
28067 assert(dest_info.sentinel == .none);28067 assert(dest_info.sentinel == .none);
28068 if (inst_info.sentinel == .none or28068 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())
28070 break :p;28070 break :p;
2807128071
28072 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);28072 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
...@@ -28076,7 +28076,7 @@ fn coerceExtra(...@@ -28076,7 +28076,7 @@ fn coerceExtra(
28076 },28076 },
28077 else => {},28077 else => {},
28078 },28078 },
28079 .One => switch (dest_info.child.toType().zigTypeTag(mod)) {28079 .One => switch (Type.fromInterned(dest_info.child).zigTypeTag(mod)) {
28080 .Union => {28080 .Union => {
28081 // pointer to anonymous struct to pointer to union28081 // pointer to anonymous struct to pointer to union
28082 if (inst_ty.isSinglePointer(mod) and28082 if (inst_ty.isSinglePointer(mod) and
...@@ -28139,7 +28139,7 @@ fn coerceExtra(...@@ -28139,7 +28139,7 @@ fn coerceExtra(
28139 try mod.intern_pool.getCoercedInts(28139 try mod.intern_pool.getCoercedInts(
28140 mod.gpa,28140 mod.gpa,
28141 mod.intern_pool.indexToKey(28141 mod.intern_pool.indexToKey(
28142 (try dest_info.child.toType().lazyAbiAlignment(mod)).toIntern(),28142 (try Type.fromInterned(dest_info.child).lazyAbiAlignment(mod)).toIntern(),
28143 ).int,28143 ).int,
28144 .usize_type,28144 .usize_type,
28145 ) },28145 ) },
...@@ -28166,8 +28166,8 @@ fn coerceExtra(...@@ -28166,8 +28166,8 @@ fn coerceExtra(
2816628166
28167 switch (try sema.coerceInMemoryAllowed(28167 switch (try sema.coerceInMemoryAllowed(
28168 block,28168 block,
28169 dest_info.child.toType(),28169 Type.fromInterned(dest_info.child),
28170 inst_info.child.toType(),28170 Type.fromInterned(inst_info.child),
28171 !dest_info.flags.is_const,28171 !dest_info.flags.is_const,
28172 target,28172 target,
28173 dest_ty_src,28173 dest_ty_src,
...@@ -28179,7 +28179,7 @@ fn coerceExtra(...@@ -28179,7 +28179,7 @@ fn coerceExtra(
2817928179
28180 if (dest_info.sentinel == .none or inst_info.sentinel == .none or28180 if (dest_info.sentinel == .none or inst_info.sentinel == .none or
28181 Air.internedToRef(dest_info.sentinel) !=28181 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)))
28183 break :p;28183 break :p;
2818428184
28185 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);28185 const slice_ptr = try sema.analyzeSlicePtr(block, inst_src, inst, inst_ty);
...@@ -29220,8 +29220,8 @@ fn coerceInMemoryAllowedFns(...@@ -29220,8 +29220,8 @@ fn coerceInMemoryAllowedFns(
29220 switch (src_info.return_type) {29220 switch (src_info.return_type) {
29221 .noreturn_type, .generic_poison_type => {},29221 .noreturn_type, .generic_poison_type => {},
29222 else => {29222 else => {
29223 const dest_return_type = dest_info.return_type.toType();29223 const dest_return_type = Type.fromInterned(dest_info.return_type);
29224 const src_return_type = src_info.return_type.toType();29224 const src_return_type = Type.fromInterned(src_info.return_type);
29225 const rt = try sema.coerceInMemoryAllowed(block, dest_return_type, src_return_type, false, target, dest_src, src_src);29225 const rt = try sema.coerceInMemoryAllowed(block, dest_return_type, src_return_type, false, target, dest_src, src_src);
29226 if (rt != .ok) {29226 if (rt != .ok) {
29227 return InMemoryCoercionResult{ .fn_return_type = .{29227 return InMemoryCoercionResult{ .fn_return_type = .{
...@@ -29253,8 +29253,8 @@ fn coerceInMemoryAllowedFns(...@@ -29253,8 +29253,8 @@ fn coerceInMemoryAllowedFns(
29253 };29253 };
2925429254
29255 for (0..params_len) |param_i| {29255 for (0..params_len) |param_i| {
29256 const dest_param_ty = dest_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 = src_info.param_types.get(ip)[param_i].toType();29257 const src_param_ty = Type.fromInterned(src_info.param_types.get(ip)[param_i]);
2925829258
29259 const param_i_small: u5 = @intCast(param_i);29259 const param_i_small: u5 = @intCast(param_i);
29260 if (dest_info.paramIsComptime(param_i_small) != src_info.paramIsComptime(param_i_small)) {29260 if (dest_info.paramIsComptime(param_i_small) != src_info.paramIsComptime(param_i_small)) {
...@@ -29329,12 +29329,12 @@ fn coerceInMemoryAllowedPtrs(...@@ -29329,12 +29329,12 @@ fn coerceInMemoryAllowedPtrs(
29329 } };29329 } };
29330 }29330 }
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);
29333 if (child != .ok) {29333 if (child != .ok) {
29334 return InMemoryCoercionResult{ .ptr_child = .{29334 return InMemoryCoercionResult{ .ptr_child = .{
29335 .child = try child.dupe(sema.arena),29335 .child = try child.dupe(sema.arena),
29336 .actual = src_info.child.toType(),29336 .actual = Type.fromInterned(src_info.child),
29337 .wanted = dest_info.child.toType(),29337 .wanted = Type.fromInterned(dest_info.child),
29338 } };29338 } };
29339 }29339 }
2934029340
...@@ -29369,13 +29369,13 @@ fn coerceInMemoryAllowedPtrs(...@@ -29369,13 +29369,13 @@ fn coerceInMemoryAllowedPtrs(
29369 return InMemoryCoercionResult{ .ptr_sentinel = .{29369 return InMemoryCoercionResult{ .ptr_sentinel = .{
29370 .actual = switch (src_info.sentinel) {29370 .actual = switch (src_info.sentinel) {
29371 .none => Value.@"unreachable",29371 .none => Value.@"unreachable",
29372 else => src_info.sentinel.toValue(),29372 else => Value.fromInterned(src_info.sentinel),
29373 },29373 },
29374 .wanted = switch (dest_info.sentinel) {29374 .wanted = switch (dest_info.sentinel) {
29375 .none => Value.@"unreachable",29375 .none => Value.@"unreachable",
29376 else => dest_info.sentinel.toValue(),29376 else => Value.fromInterned(dest_info.sentinel),
29377 },29377 },
29378 .ty = dest_info.child.toType(),29378 .ty = Type.fromInterned(dest_info.child),
29379 } };29379 } };
29380 }29380 }
2938129381
...@@ -29389,12 +29389,12 @@ fn coerceInMemoryAllowedPtrs(...@@ -29389,12 +29389,12 @@ fn coerceInMemoryAllowedPtrs(
29389 const src_align = if (src_info.flags.alignment != .none)29389 const src_align = if (src_info.flags.alignment != .none)
29390 src_info.flags.alignment29390 src_info.flags.alignment
29391 else29391 else
29392 try sema.typeAbiAlignment(src_info.child.toType());29392 try sema.typeAbiAlignment(Type.fromInterned(src_info.child));
2939329393
29394 const dest_align = if (dest_info.flags.alignment != .none)29394 const dest_align = if (dest_info.flags.alignment != .none)
29395 dest_info.flags.alignment29395 dest_info.flags.alignment
29396 else29396 else
29397 try sema.typeAbiAlignment(dest_info.child.toType());29397 try sema.typeAbiAlignment(Type.fromInterned(dest_info.child));
2939829398
29399 if (dest_align.compare(.gt, src_align)) {29399 if (dest_align.compare(.gt, src_align)) {
29400 return InMemoryCoercionResult{ .ptr_alignment = .{29400 return InMemoryCoercionResult{ .ptr_alignment = .{
...@@ -29719,14 +29719,14 @@ fn storePtrVal(...@@ -29719,14 +29719,14 @@ fn storePtrVal(
29719 .opv => {},29719 .opv => {},
29720 .direct => |val_ptr| {29720 .direct => |val_ptr| {
29721 if (mut_kit.mut_decl.runtime_index == .comptime_field_ptr) {29721 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)));
29723 if (!operand_val.eql(val_ptr.*, operand_ty, mod)) {29723 if (!operand_val.eql(val_ptr.*, operand_ty, mod)) {
29724 // TODO use failWithInvalidComptimeFieldStore29724 // TODO use failWithInvalidComptimeFieldStore
29725 return sema.fail(block, src, "value stored in comptime field does not match the default value of the field", .{});29725 return sema.fail(block, src, "value stored in comptime field does not match the default value of the field", .{});
29726 }29726 }
29727 return;29727 return;
29728 }29728 }
29729 val_ptr.* = (try operand_val.intern(operand_ty, mod)).toValue();29729 val_ptr.* = Value.fromInterned((try operand_val.intern(operand_ty, mod)));
29730 },29730 },
29731 .reinterpret => |reinterpret| {29731 .reinterpret => |reinterpret| {
29732 const abi_size = try sema.usizeCast(block, src, mut_kit.ty.abiSize(mod));29732 const abi_size = try sema.usizeCast(block, src, mut_kit.ty.abiSize(mod));
...@@ -29756,7 +29756,7 @@ fn storePtrVal(...@@ -29756,7 +29756,7 @@ fn storePtrVal(
29756 error.IllDefinedMemoryLayout => unreachable,29756 error.IllDefinedMemoryLayout => unreachable,
29757 error.Unimplemented => return sema.fail(block, src, "TODO: implement readFromMemory for type '{}'", .{mut_kit.ty.fmt(mod)}),29757 error.Unimplemented => return sema.fail(block, src, "TODO: implement readFromMemory for type '{}'", .{mut_kit.ty.fmt(mod)}),
29758 };29758 };
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)));
29760 },29760 },
29761 .bad_decl_ty, .bad_ptr_ty => {29761 .bad_decl_ty, .bad_ptr_ty => {
29762 // TODO show the decl declaration site in a note and explain whether the decl29762 // TODO show the decl declaration site in a note and explain whether the decl
...@@ -29817,15 +29817,15 @@ fn beginComptimePtrMutation(...@@ -29817,15 +29817,15 @@ fn beginComptimePtrMutation(
29817 },29817 },
29818 .comptime_field => |comptime_field| {29818 .comptime_field => |comptime_field| {
29819 const duped = try sema.arena.create(Value);29819 const duped = try sema.arena.create(Value);
29820 duped.* = comptime_field.toValue();29820 duped.* = Value.fromInterned(comptime_field);
29821 return sema.beginComptimePtrMutationInner(block, src, mod.intern_pool.typeOf(comptime_field).toType(), duped, ptr_elem_ty, .{29821 return sema.beginComptimePtrMutationInner(block, src, Type.fromInterned(mod.intern_pool.typeOf(comptime_field)), duped, ptr_elem_ty, .{
29822 .decl = undefined,29822 .decl = undefined,
29823 .runtime_index = .comptime_field_ptr,29823 .runtime_index = .comptime_field_ptr,
29824 });29824 });
29825 },29825 },
29826 .eu_payload => |eu_ptr| {29826 .eu_payload => |eu_ptr| {
29827 const eu_ty = mod.intern_pool.typeOf(eu_ptr).toType().childType(mod);29827 const eu_ty = Type.fromInterned(mod.intern_pool.typeOf(eu_ptr)).childType(mod);
29828 var parent = try sema.beginComptimePtrMutation(block, src, eu_ptr.toValue(), eu_ty);29828 var parent = try sema.beginComptimePtrMutation(block, src, Value.fromInterned(eu_ptr), eu_ty);
29829 switch (parent.pointee) {29829 switch (parent.pointee) {
29830 .opv => unreachable,29830 .opv => unreachable,
29831 .direct => |val_ptr| {29831 .direct => |val_ptr| {
...@@ -29844,7 +29844,7 @@ fn beginComptimePtrMutation(...@@ -29844,7 +29844,7 @@ fn beginComptimePtrMutation(
29844 const payload = try sema.arena.create(Value.Payload.SubValue);29844 const payload = try sema.arena.create(Value.Payload.SubValue);
29845 payload.* = .{29845 payload.* = .{
29846 .base = .{ .tag = .eu_payload },29846 .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() }))),
29848 };29848 };
2984929849
29850 val_ptr.* = Value.initPayload(&payload.base);29850 val_ptr.* = Value.initPayload(&payload.base);
...@@ -29867,8 +29867,8 @@ fn beginComptimePtrMutation(...@@ -29867,8 +29867,8 @@ fn beginComptimePtrMutation(
29867 }29867 }
29868 },29868 },
29869 .opt_payload => |opt_ptr| {29869 .opt_payload => |opt_ptr| {
29870 const opt_ty = mod.intern_pool.typeOf(opt_ptr).toType().childType(mod);29870 const opt_ty = Type.fromInterned(mod.intern_pool.typeOf(opt_ptr)).childType(mod);
29871 var parent = try sema.beginComptimePtrMutation(block, src, opt_ptr.toValue(), opt_ty);29871 var parent = try sema.beginComptimePtrMutation(block, src, Value.fromInterned(opt_ptr), opt_ty);
29872 switch (parent.pointee) {29872 switch (parent.pointee) {
29873 .opv => unreachable,29873 .opv => unreachable,
29874 .direct => |val_ptr| {29874 .direct => |val_ptr| {
...@@ -29896,7 +29896,7 @@ fn beginComptimePtrMutation(...@@ -29896,7 +29896,7 @@ fn beginComptimePtrMutation(
29896 const payload = try sema.arena.create(Value.Payload.SubValue);29896 const payload = try sema.arena.create(Value.Payload.SubValue);
29897 payload.* = .{29897 payload.* = .{
29898 .base = .{ .tag = .opt_payload },29898 .base = .{ .tag = .opt_payload },
29899 .data = payload_val.toValue(),29899 .data = Value.fromInterned(payload_val),
29900 };29900 };
2990129901
29902 val_ptr.* = Value.initPayload(&payload.base);29902 val_ptr.* = Value.initPayload(&payload.base);
...@@ -29920,8 +29920,8 @@ fn beginComptimePtrMutation(...@@ -29920,8 +29920,8 @@ fn beginComptimePtrMutation(
29920 }29920 }
29921 },29921 },
29922 .elem => |elem_ptr| {29922 .elem => |elem_ptr| {
29923 const base_elem_ty = mod.intern_pool.typeOf(elem_ptr.base).toType().elemType2(mod);29923 const base_elem_ty = Type.fromInterned(mod.intern_pool.typeOf(elem_ptr.base)).elemType2(mod);
29924 var parent = try sema.beginComptimePtrMutation(block, src, elem_ptr.base.toValue(), base_elem_ty);29924 var parent = try sema.beginComptimePtrMutation(block, src, Value.fromInterned(elem_ptr.base), base_elem_ty);
2992529925
29926 switch (parent.pointee) {29926 switch (parent.pointee) {
29927 .opv => unreachable,29927 .opv => unreachable,
...@@ -30017,7 +30017,7 @@ fn beginComptimePtrMutation(...@@ -30017,7 +30017,7 @@ fn beginComptimePtrMutation(
30017 const array_len_including_sentinel =30017 const array_len_including_sentinel =
30018 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));30018 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));
30019 const elems = try arena.alloc(Value, array_len_including_sentinel);30019 const elems = try arena.alloc(Value, array_len_including_sentinel);
30020 @memset(elems, repeated_val.toValue());30020 @memset(elems, Value.fromInterned(repeated_val));
3002130021
30022 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);30022 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
3002330023
...@@ -30054,7 +30054,7 @@ fn beginComptimePtrMutation(...@@ -30054,7 +30054,7 @@ fn beginComptimePtrMutation(
30054 const array_len_including_sentinel =30054 const array_len_including_sentinel =
30055 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));30055 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));
30056 const elems = try arena.alloc(Value, array_len_including_sentinel);30056 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
30059 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);30059 val_ptr.* = try Value.Tag.aggregate.create(arena, elems);
3006030060
...@@ -30117,10 +30117,10 @@ fn beginComptimePtrMutation(...@@ -30117,10 +30117,10 @@ fn beginComptimePtrMutation(
30117 }30117 }
30118 },30118 },
30119 .field => |field_ptr| {30119 .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);
30121 const field_index: u32 = @intCast(field_ptr.index);30121 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);
30124 switch (parent.pointee) {30124 switch (parent.pointee) {
30125 .opv => unreachable,30125 .opv => unreachable,
30126 .direct => |val_ptr| switch (val_ptr.ip_index) {30126 .direct => |val_ptr| switch (val_ptr.ip_index) {
...@@ -30238,9 +30238,9 @@ fn beginComptimePtrMutation(...@@ -30238,9 +30238,9 @@ fn beginComptimePtrMutation(
30238 switch (parent.ty.zigTypeTag(mod)) {30238 switch (parent.ty.zigTypeTag(mod)) {
30239 .Struct => {30239 .Struct => {
30240 const fields = try arena.alloc(Value, parent.ty.structFieldCount(mod));30240 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(.{
30242 .undef = parent.ty.structFieldType(i, mod).toIntern(),30242 .undef = parent.ty.structFieldType(i, mod).toIntern(),
30243 })).toValue();30243 })));
3024430244
30245 val_ptr.* = try Value.Tag.aggregate.create(arena, fields);30245 val_ptr.* = try Value.Tag.aggregate.create(arena, fields);
3024630246
...@@ -30260,7 +30260,7 @@ fn beginComptimePtrMutation(...@@ -30260,7 +30260,7 @@ fn beginComptimePtrMutation(
30260 const payload_ty = parent.ty.structFieldType(field_index, mod);30260 const payload_ty = parent.ty.structFieldType(field_index, mod);
30261 payload.* = .{ .data = .{30261 payload.* = .{ .data = .{
30262 .tag = try mod.enumValueFieldIndex(tag_ty, field_index),30262 .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() }))),
30264 } };30264 } };
3026530265
30266 val_ptr.* = Value.initPayload(&payload.base);30266 val_ptr.* = Value.initPayload(&payload.base);
...@@ -30279,8 +30279,8 @@ fn beginComptimePtrMutation(...@@ -30279,8 +30279,8 @@ fn beginComptimePtrMutation(
30279 assert(parent.ty.isSlice(mod));30279 assert(parent.ty.isSlice(mod));
30280 const ptr_ty = parent.ty.slicePtrFieldType(mod);30280 const ptr_ty = parent.ty.slicePtrFieldType(mod);
30281 val_ptr.* = try Value.Tag.slice.create(arena, .{30281 val_ptr.* = try Value.Tag.slice.create(arena, .{
30282 .ptr = (try mod.intern(.{ .undef = ptr_ty.toIntern() })).toValue(),30282 .ptr = Value.fromInterned((try mod.intern(.{ .undef = ptr_ty.toIntern() }))),
30283 .len = (try mod.intern(.{ .undef = .usize_type })).toValue(),30283 .len = Value.fromInterned((try mod.intern(.{ .undef = .usize_type }))),
30284 });30284 });
3028530285
30286 switch (field_index) {30286 switch (field_index) {
...@@ -30449,9 +30449,9 @@ fn beginComptimePtrLoad(...@@ -30449,9 +30449,9 @@ fn beginComptimePtrLoad(
30449 },30449 },
30450 .anon_decl => |anon_decl| blk: {30450 .anon_decl => |anon_decl| blk: {
30451 const decl_val = anon_decl.val;30451 const decl_val = anon_decl.val;
30452 if (decl_val.toValue().getVariable(mod) != null) return error.RuntimeLoad;30452 if (Value.fromInterned(decl_val).getVariable(mod) != null) return error.RuntimeLoad;
30453 const decl_ty = ip.typeOf(decl_val).toType();30453 const decl_ty = Type.fromInterned(ip.typeOf(decl_val));
30454 const decl_tv: TypedValue = .{ .ty = decl_ty, .val = decl_val.toValue() };30454 const decl_tv: TypedValue = .{ .ty = decl_ty, .val = Value.fromInterned(decl_val) };
30455 const layout_defined = decl_ty.hasWellDefinedLayout(mod);30455 const layout_defined = decl_ty.hasWellDefinedLayout(mod);
30456 break :blk ComptimePtrLoadKit{30456 break :blk ComptimePtrLoadKit{
30457 .parent = if (layout_defined) .{ .tv = decl_tv, .byte_offset = 0 } else null,30457 .parent = if (layout_defined) .{ .tv = decl_tv, .byte_offset = 0 } else null,
...@@ -30462,13 +30462,13 @@ fn beginComptimePtrLoad(...@@ -30462,13 +30462,13 @@ fn beginComptimePtrLoad(
30462 },30462 },
30463 .int => return error.RuntimeLoad,30463 .int => return error.RuntimeLoad,
30464 .eu_payload, .opt_payload => |container_ptr| blk: {30464 .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);
30466 const payload_ty = switch (ptr.addr) {30466 const payload_ty = switch (ptr.addr) {
30467 .eu_payload => container_ty.errorUnionPayload(mod),30467 .eu_payload => container_ty.errorUnionPayload(mod),
30468 .opt_payload => container_ty.optionalChild(mod),30468 .opt_payload => container_ty.optionalChild(mod),
30469 else => unreachable,30469 else => unreachable,
30470 };30470 };
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
30473 // eu_payload and opt_payload never have a well-defined layout30473 // eu_payload and opt_payload never have a well-defined layout
30474 if (deref.parent != null) {30474 if (deref.parent != null) {
...@@ -30484,7 +30484,7 @@ fn beginComptimePtrLoad(...@@ -30484,7 +30484,7 @@ fn beginComptimePtrLoad(
30484 const payload_val = switch (tv.val.ip_index) {30484 const payload_val = switch (tv.val.ip_index) {
30485 .none => tv.val.cast(Value.Payload.SubValue).?.data,30485 .none => tv.val.cast(Value.Payload.SubValue).?.data,
30486 .null_value => return sema.fail(block, src, "attempt to use null value", .{}),30486 .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())) {
30488 .error_union => |error_union| switch (error_union.val) {30488 .error_union => |error_union| switch (error_union.val) {
30489 .err_name => |err_name| return sema.fail(30489 .err_name => |err_name| return sema.fail(
30490 block,30490 block,
...@@ -30499,7 +30499,7 @@ fn beginComptimePtrLoad(...@@ -30499,7 +30499,7 @@ fn beginComptimePtrLoad(
30499 else => |payload| payload,30499 else => |payload| payload,
30500 },30500 },
30501 else => unreachable,30501 else => unreachable,
30502 }.toValue(),30502 }),
30503 };30503 };
30504 tv.* = TypedValue{ .ty = payload_ty, .val = payload_val };30504 tv.* = TypedValue{ .ty = payload_ty, .val = payload_val };
30505 break :blk deref;30505 break :blk deref;
...@@ -30509,24 +30509,24 @@ fn beginComptimePtrLoad(...@@ -30509,24 +30509,24 @@ fn beginComptimePtrLoad(
30509 break :blk deref;30509 break :blk deref;
30510 },30510 },
30511 .comptime_field => |comptime_field| blk: {30511 .comptime_field => |comptime_field| blk: {
30512 const field_ty = ip.typeOf(comptime_field).toType();30512 const field_ty = Type.fromInterned(ip.typeOf(comptime_field));
30513 break :blk ComptimePtrLoadKit{30513 break :blk ComptimePtrLoadKit{
30514 .parent = null,30514 .parent = null,
30515 .pointee = .{ .ty = field_ty, .val = comptime_field.toValue() },30515 .pointee = .{ .ty = field_ty, .val = Value.fromInterned(comptime_field) },
30516 .is_mutable = false,30516 .is_mutable = false,
30517 .ty_without_well_defined_layout = field_ty,30517 .ty_without_well_defined_layout = field_ty,
30518 };30518 };
30519 },30519 },
30520 .elem => |elem_ptr| blk: {30520 .elem => |elem_ptr| blk: {
30521 const elem_ty = ip.typeOf(elem_ptr.base).toType().elemType2(mod);30521 const elem_ty = Type.fromInterned(ip.typeOf(elem_ptr.base)).elemType2(mod);
30522 var deref = try sema.beginComptimePtrLoad(block, src, elem_ptr.base.toValue(), null);30522 var deref = try sema.beginComptimePtrLoad(block, src, Value.fromInterned(elem_ptr.base), null);
3052330523
30524 // This code assumes that elem_ptrs have been "flattened" in order for direct dereference30524 // This code assumes that elem_ptrs have been "flattened" in order for direct dereference
30525 // to succeed, meaning that elem ptrs of the same elem_ty are coalesced. Here we check that30525 // to succeed, meaning that elem ptrs of the same elem_ty are coalesced. Here we check that
30526 // our parent is not an elem_ptr with the same elem_ty, since that would be "unflattened"30526 // our parent is not an elem_ptr with the same elem_ty, since that would be "unflattened"
30527 switch (ip.indexToKey(elem_ptr.base)) {30527 switch (ip.indexToKey(elem_ptr.base)) {
30528 .ptr => |base_ptr| switch (base_ptr.addr) {30528 .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)),
30530 else => {},30530 else => {},
30531 },30531 },
30532 else => {},30532 else => {},
...@@ -30598,8 +30598,8 @@ fn beginComptimePtrLoad(...@@ -30598,8 +30598,8 @@ fn beginComptimePtrLoad(
30598 },30598 },
30599 .field => |field_ptr| blk: {30599 .field => |field_ptr| blk: {
30600 const field_index: u32 = @intCast(field_ptr.index);30600 const field_index: u32 = @intCast(field_ptr.index);
30601 const container_ty = ip.typeOf(field_ptr.base).toType().childType(mod);30601 const container_ty = Type.fromInterned(ip.typeOf(field_ptr.base)).childType(mod);
30602 var deref = try sema.beginComptimePtrLoad(block, src, field_ptr.base.toValue(), container_ty);30602 var deref = try sema.beginComptimePtrLoad(block, src, Value.fromInterned(field_ptr.base), container_ty);
3060330603
30604 if (container_ty.hasWellDefinedLayout(mod)) {30604 if (container_ty.hasWellDefinedLayout(mod)) {
30605 const struct_obj = mod.typeToStruct(container_ty);30605 const struct_obj = mod.typeToStruct(container_ty);
...@@ -30637,7 +30637,7 @@ fn beginComptimePtrLoad(...@@ -30637,7 +30637,7 @@ fn beginComptimePtrLoad(
30637 },30637 },
30638 Value.slice_len_index => TypedValue{30638 Value.slice_len_index => TypedValue{
30639 .ty = Type.usize,30639 .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),
30641 },30641 },
30642 else => unreachable,30642 else => unreachable,
30643 };30643 };
...@@ -30653,7 +30653,7 @@ fn beginComptimePtrLoad(...@@ -30653,7 +30653,7 @@ fn beginComptimePtrLoad(
30653 },30653 },
30654 .opt => |opt| switch (opt.val) {30654 .opt => |opt| switch (opt.val) {
30655 .none => return sema.fail(block, src, "attempt to use null value", .{}),30655 .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),
30657 },30657 },
30658 else => unreachable,30658 else => unreachable,
30659 };30659 };
...@@ -30822,9 +30822,9 @@ fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_resul...@@ -30822,9 +30822,9 @@ fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_resul
30822 const mod = sema.mod;30822 const mod = sema.mod;
30823 const dest_info = dest_ty.ptrInfo(mod);30823 const dest_info = dest_ty.ptrInfo(mod);
30824 const inst_info = inst_ty.ptrInfo(mod);30824 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 or30825 const len0 = (Type.fromInterned(inst_info.child).zigTypeTag(mod) == .Array and (Type.fromInterned(inst_info.child).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))) or30826 (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 (inst_info.child.toType().isTuple(mod) and inst_info.child.toType().structFieldCount(mod) == 0);30827 (Type.fromInterned(inst_info.child).isTuple(mod) and Type.fromInterned(inst_info.child).structFieldCount(mod) == 0);
3082830828
30829 const ok_cv_qualifiers =30829 const ok_cv_qualifiers =
30830 ((!inst_info.flags.is_const or dest_info.flags.is_const) or len0) and30830 ((!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...@@ -30852,12 +30852,12 @@ fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_resul
30852 const inst_align = if (inst_info.flags.alignment != .none)30852 const inst_align = if (inst_info.flags.alignment != .none)
30853 inst_info.flags.alignment30853 inst_info.flags.alignment
30854 else30854 else
30855 inst_info.child.toType().abiAlignment(mod);30855 Type.fromInterned(inst_info.child).abiAlignment(mod);
3085630856
30857 const dest_align = if (dest_info.flags.alignment != .none)30857 const dest_align = if (dest_info.flags.alignment != .none)
30858 dest_info.flags.alignment30858 dest_info.flags.alignment
30859 else30859 else
30860 dest_info.child.toType().abiAlignment(mod);30860 Type.fromInterned(dest_info.child).abiAlignment(mod);
3086130861
30862 if (dest_align.compare(.gt, inst_align)) {30862 if (dest_align.compare(.gt, inst_align)) {
30863 in_memory_result.* = .{ .ptr_alignment = .{30863 in_memory_result.* = .{ .ptr_alignment = .{
...@@ -30884,7 +30884,7 @@ fn coerceCompatiblePtrs(...@@ -30884,7 +30884,7 @@ fn coerceCompatiblePtrs(
30884 }30884 }
30885 // The comptime Value representation is compatible with both types.30885 // The comptime Value representation is compatible with both types.
30886 return Air.internedToRef(30886 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(),
30888 );30888 );
30889 }30889 }
30890 try sema.requireRuntimeBlock(block, inst_src, null);30890 try sema.requireRuntimeBlock(block, inst_src, null);
...@@ -30950,7 +30950,7 @@ fn coerceEnumToUnion(...@@ -30950,7 +30950,7 @@ fn coerceEnumToUnion(
30950 };30950 };
3095130951
30952 const union_obj = mod.typeToUnion(union_ty).?;30952 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]);
30954 try sema.resolveTypeFields(field_ty);30954 try sema.resolveTypeFields(field_ty);
30955 if (field_ty.zigTypeTag(mod) == .NoReturn) {30955 if (field_ty.zigTypeTag(mod) == .NoReturn) {
30956 const msg = msg: {30956 const msg = msg: {
...@@ -31007,7 +31007,7 @@ fn coerceEnumToUnion(...@@ -31007,7 +31007,7 @@ fn coerceEnumToUnion(
31007 errdefer if (msg) |some| some.destroy(sema.gpa);31007 errdefer if (msg) |some| some.destroy(sema.gpa);
3100831008
31009 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {31009 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) {
31011 const err_msg = msg orelse try sema.errMsg(31011 const err_msg = msg orelse try sema.errMsg(
31012 block,31012 block,
31013 inst_src,31013 inst_src,
...@@ -31042,7 +31042,7 @@ fn coerceEnumToUnion(...@@ -31042,7 +31042,7 @@ fn coerceEnumToUnion(
3104231042
31043 for (0..union_obj.field_names.len) |field_index| {31043 for (0..union_obj.field_names.len) |field_index| {
31044 const field_name = union_obj.field_names.get(ip)[field_index];31044 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]);
31046 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;31046 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
31047 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{31047 try sema.addFieldErrNote(union_ty, field_index, msg, "field '{}' has type '{}'", .{
31048 field_name.fmt(ip),31048 field_name.fmt(ip),
...@@ -31320,7 +31320,7 @@ fn coerceTupleToArrayPtrs(...@@ -31320,7 +31320,7 @@ fn coerceTupleToArrayPtrs(
31320 const mod = sema.mod;31320 const mod = sema.mod;
31321 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);31321 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);
31322 const ptr_info = ptr_array_ty.ptrInfo(mod);31322 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);
31324 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);31324 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);
31325 if (ptr_info.flags.alignment != .none) {31325 if (ptr_info.flags.alignment != .none) {
31326 return sema.fail(block, array_ty_src, "TODO: override the alignment of the array decl we create here", .{});31326 return sema.fail(block, array_ty_src, "TODO: override the alignment of the array decl we create here", .{});
...@@ -31372,7 +31372,7 @@ fn coerceTupleToStruct(...@@ -31372,7 +31372,7 @@ fn coerceTupleToStruct(
31372 else => unreachable,31372 else => unreachable,
31373 };31373 };
31374 const field_index = try sema.structFieldIndex(block, struct_ty, field_name, field_src);31374 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]);
31376 const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, field_i);31376 const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, field_i);
31377 const coerced = try sema.coerce(block, field_ty, elem_ref, field_src);31377 const coerced = try sema.coerce(block, field_ty, elem_ref, field_src);
31378 field_refs[field_index] = coerced;31378 field_refs[field_index] = coerced;
...@@ -31383,7 +31383,7 @@ fn coerceTupleToStruct(...@@ -31383,7 +31383,7 @@ fn coerceTupleToStruct(
31383 });31383 });
31384 };31384 };
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]);
31387 if (!init_val.eql(field_init, field_ty, sema.mod)) {31387 if (!init_val.eql(field_init, field_ty, sema.mod)) {
31388 return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i);31388 return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i);
31389 }31389 }
...@@ -31502,7 +31502,7 @@ fn coerceTupleToTuple(...@@ -31502,7 +31502,7 @@ fn coerceTupleToTuple(
31502 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_src);31502 const field_index = try sema.tupleFieldIndex(block, tuple_ty, field_name, field_src);
3150331503
31504 const elem_ref = try sema.tupleField(block, inst_src, inst, field_src, field_i);31504 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);
31506 field_refs[field_index] = coerced;31506 field_refs[field_index] = coerced;
31507 if (default_val != .none) {31507 if (default_val != .none) {
31508 const init_val = (try sema.resolveValue(coerced)) orelse {31508 const init_val = (try sema.resolveValue(coerced)) orelse {
...@@ -31511,7 +31511,7 @@ fn coerceTupleToTuple(...@@ -31511,7 +31511,7 @@ fn coerceTupleToTuple(
31511 });31511 });
31512 };31512 };
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)) {
31515 return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i);31515 return sema.failWithInvalidComptimeFieldStore(block, field_src, inst_ty, field_i);
31516 }31516 }
31517 }31517 }
...@@ -31658,13 +31658,13 @@ fn ensureFuncBodyAnalyzed(sema: *Sema, func: InternPool.Index) CompileError!void...@@ -31658,13 +31658,13 @@ fn ensureFuncBodyAnalyzed(sema: *Sema, func: InternPool.Index) CompileError!void
31658fn optRefValue(sema: *Sema, opt_val: ?Value) !Value {31658fn optRefValue(sema: *Sema, opt_val: ?Value) !Value {
31659 const mod = sema.mod;31659 const mod = sema.mod;
31660 const ptr_anyopaque_ty = try mod.singleConstPtrType(Type.anyopaque);31660 const ptr_anyopaque_ty = try mod.singleConstPtrType(Type.anyopaque);
31661 return (try mod.intern(.{ .opt = .{31661 return Value.fromInterned((try mod.intern(.{ .opt = .{
31662 .ty = (try mod.optionalType(ptr_anyopaque_ty.toIntern())).toIntern(),31662 .ty = (try mod.optionalType(ptr_anyopaque_ty.toIntern())).toIntern(),
31663 .val = if (opt_val) |val| (try mod.getCoerced(31663 .val = if (opt_val) |val| (try mod.getCoerced(
31664 (try sema.refValue(val.toIntern())).toValue(),31664 Value.fromInterned((try sema.refValue(val.toIntern()))),
31665 ptr_anyopaque_ty,31665 ptr_anyopaque_ty,
31666 )).toIntern() else .none,31666 )).toIntern() else .none,
31667 } })).toValue();31667 } })));
31668}31668}
3166931669
31670fn analyzeDeclRef(sema: *Sema, decl_index: Decl.Index) CompileError!Air.Inst.Ref {31670fn analyzeDeclRef(sema: *Sema, decl_index: Decl.Index) CompileError!Air.Inst.Ref {
...@@ -32378,7 +32378,7 @@ fn analyzeSlice(...@@ -32378,7 +32378,7 @@ fn analyzeSlice(
3237832378
32379 if (!new_ptr_val.isUndef(mod)) {32379 if (!new_ptr_val.isUndef(mod)) {
32380 return Air.internedToRef((try mod.getCoerced(32380 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))),
32382 return_ty,32382 return_ty,
32383 )).toIntern());32383 )).toIntern());
32384 }32384 }
...@@ -33362,10 +33362,10 @@ fn resolvePeerTypesInner(...@@ -33362,10 +33362,10 @@ fn resolvePeerTypesInner(
33362 ty_ptr.* = ty.errorUnionPayload(mod);33362 ty_ptr.* = ty.errorUnionPayload(mod);
33363 if (val_ptr.*) |eu_val| switch (ip.indexToKey(eu_val.toIntern())) {33363 if (val_ptr.*) |eu_val| switch (ip.indexToKey(eu_val.toIntern())) {
33364 .error_union => |eu| switch (eu.val) {33364 .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),
33366 .err_name => val_ptr.* = null,33366 .err_name => val_ptr.* = null,
33367 },33367 },
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() }))),
33369 else => unreachable,33369 else => unreachable,
33370 };33370 };
33371 break :blk set_ty;33371 break :blk set_ty;
...@@ -33606,7 +33606,7 @@ fn resolvePeerTypesInner(...@@ -33606,7 +33606,7 @@ fn resolvePeerTypesInner(
33606 };33606 };
3360733607
33608 // Try peer -> cur, then cur -> peer33608 // 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 {
33610 return .{ .conflict = .{33610 return .{ .conflict = .{
33611 .peer_idx_a = first_idx,33611 .peer_idx_a = first_idx,
33612 .peer_idx_b = i,33612 .peer_idx_b = i,
...@@ -33630,12 +33630,12 @@ fn resolvePeerTypesInner(...@@ -33630,12 +33630,12 @@ fn resolvePeerTypesInner(
33630 if (ptr_info.flags.alignment != .none)33630 if (ptr_info.flags.alignment != .none)
33631 ptr_info.flags.alignment33631 ptr_info.flags.alignment
33632 else33632 else
33633 ptr_info.child.toType().abiAlignment(mod),33633 Type.fromInterned(ptr_info.child).abiAlignment(mod),
3363433634
33635 if (peer_info.flags.alignment != .none)33635 if (peer_info.flags.alignment != .none)
33636 peer_info.flags.alignment33636 peer_info.flags.alignment
33637 else33637 else
33638 peer_info.child.toType().abiAlignment(mod),33638 Type.fromInterned(peer_info.child).abiAlignment(mod),
33639 );33639 );
33640 if (ptr_info.flags.address_space != peer_info.flags.address_space) {33640 if (ptr_info.flags.address_space != peer_info.flags.address_space) {
33641 return .{ .conflict = .{33641 return .{ .conflict = .{
...@@ -33714,12 +33714,12 @@ fn resolvePeerTypesInner(...@@ -33714,12 +33714,12 @@ fn resolvePeerTypesInner(
33714 if (ptr_info.flags.alignment != .none)33714 if (ptr_info.flags.alignment != .none)
33715 ptr_info.flags.alignment33715 ptr_info.flags.alignment
33716 else33716 else
33717 try sema.typeAbiAlignment(ptr_info.child.toType()),33717 try sema.typeAbiAlignment(Type.fromInterned(ptr_info.child)),
3371833718
33719 if (peer_info.flags.alignment != .none)33719 if (peer_info.flags.alignment != .none)
33720 peer_info.flags.alignment33720 peer_info.flags.alignment
33721 else33721 else
33722 try sema.typeAbiAlignment(peer_info.child.toType()),33722 try sema.typeAbiAlignment(Type.fromInterned(peer_info.child)),
33723 );33723 );
3372433724
33725 if (ptr_info.flags.address_space != peer_info.flags.address_space) {33725 if (ptr_info.flags.address_space != peer_info.flags.address_space) {
...@@ -33754,8 +33754,8 @@ fn resolvePeerTypesInner(...@@ -33754,8 +33754,8 @@ fn resolvePeerTypesInner(
33754 };33754 };
3375533755
33756 // We abstract array handling slightly so that tuple pointers can work like array pointers33756 // 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());33757 const peer_pointee_array = sema.typeIsArrayLike(Type.fromInterned(peer_info.child));
33758 const cur_pointee_array = sema.typeIsArrayLike(ptr_info.child.toType());33758 const cur_pointee_array = sema.typeIsArrayLike(Type.fromInterned(ptr_info.child));
3375933759
33760 // This switch is just responsible for deciding the size and pointee (not including33760 // This switch is just responsible for deciding the size and pointee (not including
33761 // single-pointer array sentinel).33761 // single-pointer array sentinel).
...@@ -33763,7 +33763,7 @@ fn resolvePeerTypesInner(...@@ -33763,7 +33763,7 @@ fn resolvePeerTypesInner(
33763 switch (peer_info.flags.size) {33763 switch (peer_info.flags.size) {
33764 .One => switch (ptr_info.flags.size) {33764 .One => switch (ptr_info.flags.size) {
33765 .One => {33765 .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| {
33767 ptr_info.child = pointee.toIntern();33767 ptr_info.child = pointee.toIntern();
33768 break :good;33768 break :good;
33769 }33769 }
...@@ -33805,7 +33805,7 @@ fn resolvePeerTypesInner(...@@ -33805,7 +33805,7 @@ fn resolvePeerTypesInner(
33805 .Many => {33805 .Many => {
33806 // Only works for *[n]T + [*]T -> [*]T33806 // Only works for *[n]T + [*]T -> [*]T
33807 const arr = peer_pointee_array orelse return generic_err;33807 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| {
33809 ptr_info.child = pointee.toIntern();33809 ptr_info.child = pointee.toIntern();
33810 break :good;33810 break :good;
33811 }33811 }
...@@ -33818,7 +33818,7 @@ fn resolvePeerTypesInner(...@@ -33818,7 +33818,7 @@ fn resolvePeerTypesInner(
33818 .Slice => {33818 .Slice => {
33819 // Only works for *[n]T + []T -> []T33819 // Only works for *[n]T + []T -> []T
33820 const arr = peer_pointee_array orelse return generic_err;33820 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| {
33822 ptr_info.child = pointee.toIntern();33822 ptr_info.child = pointee.toIntern();
33823 break :good;33823 break :good;
33824 }33824 }
...@@ -33834,7 +33834,7 @@ fn resolvePeerTypesInner(...@@ -33834,7 +33834,7 @@ fn resolvePeerTypesInner(
33834 .One => {33834 .One => {
33835 // Only works for [*]T + *[n]T -> [*]T33835 // Only works for [*]T + *[n]T -> [*]T
33836 const arr = cur_pointee_array orelse return generic_err;33836 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| {
33838 ptr_info.flags.size = .Many;33838 ptr_info.flags.size = .Many;
33839 ptr_info.child = pointee.toIntern();33839 ptr_info.child = pointee.toIntern();
33840 break :good;33840 break :good;
...@@ -33848,7 +33848,7 @@ fn resolvePeerTypesInner(...@@ -33848,7 +33848,7 @@ fn resolvePeerTypesInner(
33848 return generic_err;33848 return generic_err;
33849 },33849 },
33850 .Many => {33850 .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| {
33852 ptr_info.child = pointee.toIntern();33852 ptr_info.child = pointee.toIntern();
33853 break :good;33853 break :good;
33854 }33854 }
...@@ -33863,7 +33863,7 @@ fn resolvePeerTypesInner(...@@ -33863,7 +33863,7 @@ fn resolvePeerTypesInner(
33863 } };33863 } };
33864 }33864 }
33865 // Okay, then works for [*]T + "[]T" -> [*]T33865 // 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| {
33867 ptr_info.flags.size = .Many;33867 ptr_info.flags.size = .Many;
33868 ptr_info.child = pointee.toIntern();33868 ptr_info.child = pointee.toIntern();
33869 break :good;33869 break :good;
...@@ -33876,7 +33876,7 @@ fn resolvePeerTypesInner(...@@ -33876,7 +33876,7 @@ fn resolvePeerTypesInner(
33876 .One => {33876 .One => {
33877 // Only works for []T + *[n]T -> []T33877 // Only works for []T + *[n]T -> []T
33878 const arr = cur_pointee_array orelse return generic_err;33878 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| {
33880 ptr_info.flags.size = .Slice;33880 ptr_info.flags.size = .Slice;
33881 ptr_info.child = pointee.toIntern();33881 ptr_info.child = pointee.toIntern();
33882 break :good;33882 break :good;
...@@ -33894,7 +33894,7 @@ fn resolvePeerTypesInner(...@@ -33894,7 +33894,7 @@ fn resolvePeerTypesInner(
33894 return generic_err;33894 return generic_err;
33895 },33895 },
33896 .Slice => {33896 .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| {
33898 ptr_info.child = pointee.toIntern();33898 ptr_info.child = pointee.toIntern();
33899 break :good;33899 break :good;
33900 }33900 }
...@@ -34331,7 +34331,7 @@ fn resolvePeerTypesInner(...@@ -34331,7 +34331,7 @@ fn resolvePeerTypesInner(
34331 break;34331 break;
34332 };34332 };
34333 const uncoerced_field = Air.internedToRef(uncoerced_field_val.toIntern());34333 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) {
34335 // It's possible for PTR to give false positives. Just give up on making this a comptime field, we'll get an error later anyway34335 // 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
34336 error.NotCoercible => {34336 error.NotCoercible => {
34337 comptime_val = null;34337 comptime_val = null;
...@@ -34344,7 +34344,7 @@ fn resolvePeerTypesInner(...@@ -34344,7 +34344,7 @@ fn resolvePeerTypesInner(
34344 comptime_val = coerced_val;34344 comptime_val = coerced_val;
34345 continue;34345 continue;
34346 };34346 };
34347 if (!coerced_val.eql(existing, field_ty.toType(), mod)) {34347 if (!coerced_val.eql(existing, Type.fromInterned(field_ty.*), mod)) {
34348 comptime_val = null;34348 comptime_val = null;
34349 break;34349 break;
34350 }34350 }
...@@ -34359,7 +34359,7 @@ fn resolvePeerTypesInner(...@@ -34359,7 +34359,7 @@ fn resolvePeerTypesInner(
34359 .values = field_vals,34359 .values = field_vals,
34360 });34360 });
3436134361
34362 return .{ .success = final_ty.toType() };34362 return .{ .success = Type.fromInterned(final_ty) };
34363 },34363 },
3436434364
34365 .exact => {34365 .exact => {
...@@ -34460,15 +34460,15 @@ pub fn resolveFnTypes(sema: *Sema, fn_ty: Type) CompileError!void {...@@ -34460,15 +34460,15 @@ pub fn resolveFnTypes(sema: *Sema, fn_ty: Type) CompileError!void {
34460 const ip = &mod.intern_pool;34460 const ip = &mod.intern_pool;
34461 const fn_ty_info = mod.typeToFunc(fn_ty).?;34461 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)) {
34466 // Ensure the type exists so that backends can assume that.34466 // Ensure the type exists so that backends can assume that.
34467 _ = try sema.getBuiltinType("StackTrace");34467 _ = try sema.getBuiltinType("StackTrace");
34468 }34468 }
3446934469
34470 for (0..fn_ty_info.param_types.len) |i| {34470 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]));
34472 }34472 }
34473}34473}
3447434474
...@@ -34480,20 +34480,20 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {...@@ -34480,20 +34480,20 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {
34480 .int => |int| switch (int.storage) {34480 .int => |int| switch (int.storage) {
34481 .u64, .i64, .big_int => return val,34481 .u64, .i64, .big_int => return val,
34482 .lazy_align, .lazy_size => return mod.intValue(34482 .lazy_align, .lazy_size => return mod.intValue(
34483 int.ty.toType(),34483 Type.fromInterned(int.ty),
34484 (try val.getUnsignedIntAdvanced(mod, sema)).?,34484 (try val.getUnsignedIntAdvanced(mod, sema)).?,
34485 ),34485 ),
34486 },34486 },
34487 .ptr => |ptr| {34487 .ptr => |ptr| {
34488 const resolved_len = switch (ptr.len) {34488 const resolved_len = switch (ptr.len) {
34489 .none => .none,34489 .none => .none,
34490 else => (try sema.resolveLazyValue(ptr.len.toValue())).toIntern(),34490 else => (try sema.resolveLazyValue(Value.fromInterned(ptr.len))).toIntern(),
34491 };34491 };
34492 switch (ptr.addr) {34492 switch (ptr.addr) {
34493 .decl, .mut_decl, .anon_decl => return if (resolved_len == ptr.len)34493 .decl, .mut_decl, .anon_decl => return if (resolved_len == ptr.len)
34494 val34494 val
34495 else34495 else
34496 (try mod.intern(.{ .ptr = .{34496 Value.fromInterned((try mod.intern(.{ .ptr = .{
34497 .ty = ptr.ty,34497 .ty = ptr.ty,
34498 .addr = switch (ptr.addr) {34498 .addr = switch (ptr.addr) {
34499 .decl => |decl| .{ .decl = decl },34499 .decl => |decl| .{ .decl = decl },
...@@ -34502,36 +34502,36 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {...@@ -34502,36 +34502,36 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {
34502 else => unreachable,34502 else => unreachable,
34503 },34503 },
34504 .len = resolved_len,34504 .len = resolved_len,
34505 } })).toValue(),34505 } }))),
34506 .comptime_field => |field_val| {34506 .comptime_field => |field_val| {
34507 const resolved_field_val =34507 const resolved_field_val =
34508 (try sema.resolveLazyValue(field_val.toValue())).toIntern();34508 (try sema.resolveLazyValue(Value.fromInterned(field_val))).toIntern();
34509 return if (resolved_field_val == field_val and resolved_len == ptr.len)34509 return if (resolved_field_val == field_val and resolved_len == ptr.len)
34510 val34510 val
34511 else34511 else
34512 (try mod.intern(.{ .ptr = .{34512 Value.fromInterned((try mod.intern(.{ .ptr = .{
34513 .ty = ptr.ty,34513 .ty = ptr.ty,
34514 .addr = .{ .comptime_field = resolved_field_val },34514 .addr = .{ .comptime_field = resolved_field_val },
34515 .len = resolved_len,34515 .len = resolved_len,
34516 } })).toValue();34516 } })));
34517 },34517 },
34518 .int => |int| {34518 .int => |int| {
34519 const resolved_int = (try sema.resolveLazyValue(int.toValue())).toIntern();34519 const resolved_int = (try sema.resolveLazyValue(Value.fromInterned(int))).toIntern();
34520 return if (resolved_int == int and resolved_len == ptr.len)34520 return if (resolved_int == int and resolved_len == ptr.len)
34521 val34521 val
34522 else34522 else
34523 (try mod.intern(.{ .ptr = .{34523 Value.fromInterned((try mod.intern(.{ .ptr = .{
34524 .ty = ptr.ty,34524 .ty = ptr.ty,
34525 .addr = .{ .int = resolved_int },34525 .addr = .{ .int = resolved_int },
34526 .len = resolved_len,34526 .len = resolved_len,
34527 } })).toValue();34527 } })));
34528 },34528 },
34529 .eu_payload, .opt_payload => |base| {34529 .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();
34531 return if (resolved_base == base and resolved_len == ptr.len)34531 return if (resolved_base == base and resolved_len == ptr.len)
34532 val34532 val
34533 else34533 else
34534 (try mod.intern(.{ .ptr = .{34534 Value.fromInterned((try mod.intern(.{ .ptr = .{
34535 .ty = ptr.ty,34535 .ty = ptr.ty,
34536 .addr = switch (ptr.addr) {34536 .addr = switch (ptr.addr) {
34537 .eu_payload => .{ .eu_payload = resolved_base },34537 .eu_payload => .{ .eu_payload = resolved_base },
...@@ -34539,14 +34539,14 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {...@@ -34539,14 +34539,14 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {
34539 else => unreachable,34539 else => unreachable,
34540 },34540 },
34541 .len = ptr.len,34541 .len = ptr.len,
34542 } })).toValue();34542 } })));
34543 },34543 },
34544 .elem, .field => |base_index| {34544 .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();
34546 return if (resolved_base == base_index.base and resolved_len == ptr.len)34546 return if (resolved_base == base_index.base and resolved_len == ptr.len)
34547 val34547 val
34548 else34548 else
34549 (try mod.intern(.{ .ptr = .{34549 Value.fromInterned((try mod.intern(.{ .ptr = .{
34550 .ty = ptr.ty,34550 .ty = ptr.ty,
34551 .addr = switch (ptr.addr) {34551 .addr = switch (ptr.addr) {
34552 .elem => .{ .elem = .{34552 .elem => .{ .elem = .{
...@@ -34560,7 +34560,7 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {...@@ -34560,7 +34560,7 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {
34560 else => unreachable,34560 else => unreachable,
34561 },34561 },
34562 .len = ptr.len,34562 .len = ptr.len,
34563 } })).toValue();34563 } })));
34564 },34564 },
34565 }34565 }
34566 },34566 },
...@@ -34569,37 +34569,37 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {...@@ -34569,37 +34569,37 @@ fn resolveLazyValue(sema: *Sema, val: Value) CompileError!Value {
34569 .elems => |elems| {34569 .elems => |elems| {
34570 var resolved_elems: []InternPool.Index = &.{};34570 var resolved_elems: []InternPool.Index = &.{};
34571 for (elems, 0..) |elem, i| {34571 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();
34573 if (resolved_elems.len == 0 and resolved_elem != elem) {34573 if (resolved_elems.len == 0 and resolved_elem != elem) {
34574 resolved_elems = try sema.arena.alloc(InternPool.Index, elems.len);34574 resolved_elems = try sema.arena.alloc(InternPool.Index, elems.len);
34575 @memcpy(resolved_elems[0..i], elems[0..i]);34575 @memcpy(resolved_elems[0..i], elems[0..i]);
34576 }34576 }
34577 if (resolved_elems.len > 0) resolved_elems[i] = resolved_elem;34577 if (resolved_elems.len > 0) resolved_elems[i] = resolved_elem;
34578 }34578 }
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 = .{
34580 .ty = aggregate.ty,34580 .ty = aggregate.ty,
34581 .storage = .{ .elems = resolved_elems },34581 .storage = .{ .elems = resolved_elems },
34582 } })).toValue();34582 } })));
34583 },34583 },
34584 .repeated_elem => |elem| {34584 .repeated_elem => |elem| {
34585 const resolved_elem = (try sema.resolveLazyValue(elem.toValue())).toIntern();34585 const resolved_elem = (try sema.resolveLazyValue(Value.fromInterned(elem))).toIntern();
34586 return if (resolved_elem == elem) val else (try mod.intern(.{ .aggregate = .{34586 return if (resolved_elem == elem) val else Value.fromInterned((try mod.intern(.{ .aggregate = .{
34587 .ty = aggregate.ty,34587 .ty = aggregate.ty,
34588 .storage = .{ .repeated_elem = resolved_elem },34588 .storage = .{ .repeated_elem = resolved_elem },
34589 } })).toValue();34589 } })));
34590 },34590 },
34591 },34591 },
34592 .un => |un| {34592 .un => |un| {
34593 const resolved_tag = (try sema.resolveLazyValue(un.tag.toValue())).toIntern();34593 const resolved_tag = (try sema.resolveLazyValue(Value.fromInterned(un.tag))).toIntern();
34594 const resolved_val = (try sema.resolveLazyValue(un.val.toValue())).toIntern();34594 const resolved_val = (try sema.resolveLazyValue(Value.fromInterned(un.val))).toIntern();
34595 return if (resolved_tag == un.tag and resolved_val == un.val)34595 return if (resolved_tag == un.tag and resolved_val == un.val)
34596 val34596 val
34597 else34597 else
34598 (try mod.intern(.{ .un = .{34598 Value.fromInterned((try mod.intern(.{ .un = .{
34599 .ty = un.ty,34599 .ty = un.ty,
34600 .tag = resolved_tag,34600 .tag = resolved_tag,
34601 .val = resolved_val,34601 .val = resolved_val,
34602 } })).toValue();34602 } })));
34603 },34603 },
34604 else => return val,34604 else => return val,
34605 }34605 }
...@@ -34641,9 +34641,9 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -34641,9 +34641,9 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void {
34641 const ip = &mod.intern_pool;34641 const ip = &mod.intern_pool;
34642 for (0..info.param_types.len) |i| {34642 for (0..info.param_types.len) |i| {
34643 const param_ty = info.param_types.get(ip)[i];34643 const param_ty = info.param_types.get(ip)[i];
34644 try sema.resolveTypeLayout(param_ty.toType());34644 try sema.resolveTypeLayout(Type.fromInterned(param_ty));
34645 }34645 }
34646 try sema.resolveTypeLayout(info.return_type.toType());34646 try sema.resolveTypeLayout(Type.fromInterned(info.return_type));
34647 },34647 },
34648 else => {},34648 else => {},
34649 }34649 }
...@@ -34689,7 +34689,7 @@ pub fn resolveStructAlignment(...@@ -34689,7 +34689,7 @@ pub fn resolveStructAlignment(
34689 var result: Alignment = .@"1";34689 var result: Alignment = .@"1";
3469034690
34691 for (0..struct_type.field_types.len) |i| {34691 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]);
34693 if (struct_type.fieldIsComptime(ip, i) or try sema.typeRequiresComptime(field_ty))34693 if (struct_type.fieldIsComptime(ip, i) or try sema.typeRequiresComptime(field_ty))
34694 continue;34694 continue;
34695 const field_align = try sema.structFieldAlignment(34695 const field_align = try sema.structFieldAlignment(
...@@ -34736,7 +34736,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -34736,7 +34736,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
34736 var big_align: Alignment = .@"1";34736 var big_align: Alignment = .@"1";
3473734737
34738 for (aligns, sizes, 0..) |*field_align, *field_size, i| {34738 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]);
34740 if (struct_type.fieldIsComptime(ip, i) or try sema.typeRequiresComptime(field_ty)) {34740 if (struct_type.fieldIsComptime(ip, i) or try sema.typeRequiresComptime(field_ty)) {
34741 struct_type.offsets.get(ip)[i] = 0;34741 struct_type.offsets.get(ip)[i] = 0;
34742 field_size.* = 0;34742 field_size.* = 0;
...@@ -34786,7 +34786,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -34786,7 +34786,7 @@ fn resolveStructLayout(sema: *Sema, ty: Type) CompileError!void {
34786 const runtime_order = struct_type.runtime_order.get(ip);34786 const runtime_order = struct_type.runtime_order.get(ip);
3478734787
34788 for (runtime_order, 0..) |*ro, i| {34788 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]);
34790 if (struct_type.fieldIsComptime(ip, i) or try sema.typeRequiresComptime(field_ty)) {34790 if (struct_type.fieldIsComptime(ip, i) or try sema.typeRequiresComptime(field_ty)) {
34791 ro.* = .omitted;34791 ro.* = .omitted;
34792 } else {34792 } else {
...@@ -34892,7 +34892,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp...@@ -34892,7 +34892,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.Key.StructType) Comp
34892 const fields_bit_sum = blk: {34892 const fields_bit_sum = blk: {
34893 var accumulator: u64 = 0;34893 var accumulator: u64 = 0;
34894 for (0..struct_type.field_types.len) |i| {34894 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]);
34896 accumulator += try field_ty.bitSizeAdvanced(mod, &sema);34896 accumulator += try field_ty.bitSizeAdvanced(mod, &sema);
34897 }34897 }
34898 break :blk accumulator;34898 break :blk accumulator;
...@@ -35018,7 +35018,7 @@ pub fn resolveUnionAlignment(...@@ -35018,7 +35018,7 @@ pub fn resolveUnionAlignment(
35018 const union_obj = ip.loadUnionType(union_type);35018 const union_obj = ip.loadUnionType(union_type);
35019 var max_align: Alignment = .@"1";35019 var max_align: Alignment = .@"1";
35020 for (0..union_obj.field_names.len) |field_index| {35020 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]);
35022 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;35022 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
3502335023
35024 const explicit_align = union_obj.fieldAlign(ip, @intCast(field_index));35024 const explicit_align = union_obj.fieldAlign(ip, @intCast(field_index));
...@@ -35067,7 +35067,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {...@@ -35067,7 +35067,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35067 var max_size: u64 = 0;35067 var max_size: u64 = 0;
35068 var max_align: Alignment = .@"1";35068 var max_align: Alignment = .@"1";
35069 for (0..union_obj.field_names.len) |field_index| {35069 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]);
35071 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;35071 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
3507235072
35073 max_size = @max(max_size, sema.typeAbiSize(field_ty) catch |err| switch (err) {35073 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 {...@@ -35089,9 +35089,9 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
35089 }35089 }
3509035090
35091 const flags = union_obj.flagsPtr(ip);35091 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));
35093 const size, const alignment, const padding = if (has_runtime_tag) layout: {35093 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);
35095 const tag_align = try sema.typeAbiAlignment(enum_tag_type);35095 const tag_align = try sema.typeAbiAlignment(enum_tag_type);
35096 const tag_size = try sema.typeAbiSize(enum_tag_type);35096 const tag_size = try sema.typeAbiSize(enum_tag_type);
3509735097
...@@ -35161,7 +35161,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {...@@ -35161,7 +35161,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {
35161 .struct_type => return sema.resolveStructFully(ty),35161 .struct_type => return sema.resolveStructFully(ty),
35162 .anon_struct_type => |tuple| {35162 .anon_struct_type => |tuple| {
35163 for (tuple.types.get(ip)) |field_ty| {35163 for (tuple.types.get(ip)) |field_ty| {
35164 try sema.resolveTypeFully(field_ty.toType());35164 try sema.resolveTypeFully(Type.fromInterned(field_ty));
35165 }35165 }
35166 },35166 },
35167 .simple_type => |simple_type| try sema.resolveSimpleType(simple_type),35167 .simple_type => |simple_type| try sema.resolveSimpleType(simple_type),
...@@ -35182,9 +35182,9 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {...@@ -35182,9 +35182,9 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {
35182 }35182 }
35183 for (0..info.param_types.len) |i| {35183 for (0..info.param_types.len) |i| {
35184 const param_ty = info.param_types.get(ip)[i];35184 const param_ty = info.param_types.get(ip)[i];
35185 try sema.resolveTypeFully(param_ty.toType());35185 try sema.resolveTypeFully(Type.fromInterned(param_ty));
35186 }35186 }
35187 try sema.resolveTypeFully(info.return_type.toType());35187 try sema.resolveTypeFully(Type.fromInterned(info.return_type));
35188 },35188 },
35189 else => {},35189 else => {},
35190 }35190 }
...@@ -35205,7 +35205,7 @@ fn resolveStructFully(sema: *Sema, ty: Type) CompileError!void {...@@ -35205,7 +35205,7 @@ fn resolveStructFully(sema: *Sema, ty: Type) CompileError!void {
35205 // See also similar code for unions.35205 // See also similar code for unions.
3520635206
35207 for (0..struct_type.field_types.len) |i| {35207 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]);
35209 try sema.resolveTypeFully(field_ty);35209 try sema.resolveTypeFully(field_ty);
35210 }35210 }
35211}35211}
...@@ -35230,7 +35230,7 @@ fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void {...@@ -35230,7 +35230,7 @@ fn resolveUnionFully(sema: *Sema, ty: Type) CompileError!void {
3523035230
35231 union_obj.flagsPtr(ip).status = .fully_resolved_wip;35231 union_obj.flagsPtr(ip).status = .fully_resolved_wip;
35232 for (0..union_obj.field_types.len) |field_index| {35232 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]);
35234 try sema.resolveTypeFully(field_ty);35234 try sema.resolveTypeFully(field_ty);
35235 }35235 }
35236 union_obj.flagsPtr(ip).status = .fully_resolved;35236 union_obj.flagsPtr(ip).status = .fully_resolved;
...@@ -35333,7 +35333,7 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!void {...@@ -35333,7 +35333,7 @@ pub fn resolveTypeFields(sema: *Sema, ty: Type) CompileError!void {
35333 .type_struct_packed_inits,35333 .type_struct_packed_inits,
35334 => try sema.resolveTypeFieldsStruct(ty_ip, ip.indexToKey(ty_ip).struct_type),35334 => 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),
35337 .simple_type => try sema.resolveSimpleType(ip.indexToKey(ty_ip).simple_type),35337 .simple_type => try sema.resolveSimpleType(ip.indexToKey(ty_ip).simple_type),
35338 else => {},35338 else => {},
35339 },35339 },
...@@ -35392,7 +35392,7 @@ pub fn resolveTypeFieldsStruct(...@@ -35392,7 +35392,7 @@ pub fn resolveTypeFieldsStruct(
35392 sema.gpa,35392 sema.gpa,
35393 mod.declPtr(owner_decl).srcLoc(mod),35393 mod.declPtr(owner_decl).srcLoc(mod),
35394 "struct '{}' depends on itself",35394 "struct '{}' depends on itself",
35395 .{ty.toType().fmt(mod)},35395 .{Type.fromInterned(ty).fmt(mod)},
35396 );35396 );
35397 return sema.failWithOwnedErrorMsg(null, msg);35397 return sema.failWithOwnedErrorMsg(null, msg);
35398 }35398 }
...@@ -36042,7 +36042,7 @@ fn semaStructFieldInits(...@@ -36042,7 +36042,7 @@ fn semaStructFieldInits(
36042 // In init bodies, the zir index of the struct itself is used36042 // In init bodies, the zir index of the struct itself is used
36043 // to refer to the current field type.36043 // 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]);
36046 const type_ref = Air.internedToRef(field_ty.toIntern());36046 const type_ref = Air.internedToRef(field_ty.toIntern());
36047 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index});36047 try sema.inst_map.ensureSpaceForInstructions(sema.gpa, &.{zir_index});
36048 sema.inst_map.putAssumeCapacity(zir_index, type_ref);36048 sema.inst_map.putAssumeCapacity(zir_index, type_ref);
...@@ -36368,10 +36368,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un...@@ -36368,10 +36368,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
36368 .range = .type,36368 .range = .type,
36369 }).lazy;36369 }).lazy;
36370 const msg = try sema.errMsg(&block_scope, ty_src, "no field named '{}' in enum '{}'", .{36370 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),
36372 });36372 });
36373 errdefer msg.destroy(sema.gpa);36373 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).*));
36375 break :msg msg;36375 break :msg msg;
36376 };36376 };
36377 return sema.failWithOwnedErrorMsg(&block_scope, msg);36377 return sema.failWithOwnedErrorMsg(&block_scope, msg);
...@@ -36483,11 +36483,11 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un...@@ -36483,11 +36483,11 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Key.Un
3648336483
36484 for (tag_info.names.get(ip), 0..) |field_name, field_index| {36484 for (tag_info.names.get(ip), 0..) |field_name, field_index| {
36485 if (explicit_tags_seen[field_index]) continue;36485 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", .{
36487 field_name.fmt(ip),36487 field_name.fmt(ip),
36488 });36488 });
36489 }36489 }
36490 try sema.addDeclaredHereNote(msg, union_type.tagTypePtr(ip).toType());36490 try sema.addDeclaredHereNote(msg, Type.fromInterned(union_type.tagTypePtr(ip).*));
36491 break :msg msg;36491 break :msg msg;
36492 };36492 };
36493 return sema.failWithOwnedErrorMsg(&block_scope, msg);36493 return sema.failWithOwnedErrorMsg(&block_scope, msg);
...@@ -36548,7 +36548,7 @@ fn generateUnionTagTypeNumbered(...@@ -36548,7 +36548,7 @@ fn generateUnionTagTypeNumbered(
36548 });36548 });
3654936549
36550 new_decl.ty = Type.type;36550 new_decl.ty = Type.type;
36551 new_decl.val = enum_ty.toValue();36551 new_decl.val = Value.fromInterned(enum_ty);
3655236552
36553 try mod.finalizeAnonDecl(new_decl_index);36553 try mod.finalizeAnonDecl(new_decl_index);
36554 return enum_ty;36554 return enum_ty;
...@@ -36600,7 +36600,7 @@ fn generateUnionTagTypeSimple(...@@ -36600,7 +36600,7 @@ fn generateUnionTagTypeSimple(
36600 const new_decl = mod.declPtr(new_decl_index);36600 const new_decl = mod.declPtr(new_decl_index);
36601 new_decl.owns_tv = true;36601 new_decl.owns_tv = true;
36602 new_decl.ty = Type.type;36602 new_decl.ty = Type.type;
36603 new_decl.val = enum_ty.toValue();36603 new_decl.val = Value.fromInterned(enum_ty);
3660436604
36605 try mod.finalizeAnonDecl(new_decl_index);36605 try mod.finalizeAnonDecl(new_decl_index);
36606 return enum_ty;36606 return enum_ty;
...@@ -36869,16 +36869,16 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36869,16 +36869,16 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36869 => switch (ip.indexToKey(ty.toIntern())) {36869 => switch (ip.indexToKey(ty.toIntern())) {
36870 inline .array_type, .vector_type => |seq_type, seq_tag| {36870 inline .array_type, .vector_type => |seq_type, seq_tag| {
36871 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;36871 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 = .{
36873 .ty = ty.toIntern(),36873 .ty = ty.toIntern(),
36874 .storage = .{ .elems = &.{} },36874 .storage = .{ .elems = &.{} },
36875 } })).toValue();36875 } })));
3687636876
36877 if (try sema.typeHasOnePossibleValue(seq_type.child.toType())) |opv| {36877 if (try sema.typeHasOnePossibleValue(Type.fromInterned(seq_type.child))) |opv| {
36878 return (try mod.intern(.{ .aggregate = .{36878 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
36879 .ty = ty.toIntern(),36879 .ty = ty.toIntern(),
36880 .storage = .{ .repeated_elem = opv.toIntern() },36880 .storage = .{ .repeated_elem = opv.toIntern() },
36881 } })).toValue();36881 } })));
36882 }36882 }
36883 return null;36883 return null;
36884 },36884 },
...@@ -36889,10 +36889,10 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36889,10 +36889,10 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36889 if (struct_type.field_types.len == 0) {36889 if (struct_type.field_types.len == 0) {
36890 // In this case the struct has no fields at all and36890 // In this case the struct has no fields at all and
36891 // therefore has one possible value.36891 // therefore has one possible value.
36892 return (try mod.intern(.{ .aggregate = .{36892 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
36893 .ty = ty.toIntern(),36893 .ty = ty.toIntern(),
36894 .storage = .{ .elems = &.{} },36894 .storage = .{ .elems = &.{} },
36895 } })).toValue();36895 } })));
36896 }36896 }
3689736897
36898 const field_vals = try sema.arena.alloc(36898 const field_vals = try sema.arena.alloc(
...@@ -36905,7 +36905,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36905,7 +36905,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36905 field_val.* = struct_type.field_inits.get(ip)[i];36905 field_val.* = struct_type.field_inits.get(ip)[i];
36906 continue;36906 continue;
36907 }36907 }
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]);
36909 if (field_ty.eql(ty, mod)) {36909 if (field_ty.eql(ty, mod)) {
36910 const msg = try Module.ErrorMsg.create(36910 const msg = try Module.ErrorMsg.create(
36911 sema.gpa,36911 sema.gpa,
...@@ -36923,10 +36923,10 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36923,10 +36923,10 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3692336923
36924 // In this case the struct has no runtime-known fields and36924 // In this case the struct has no runtime-known fields and
36925 // therefore has one possible value.36925 // therefore has one possible value.
36926 return (try mod.intern(.{ .aggregate = .{36926 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
36927 .ty = ty.toIntern(),36927 .ty = ty.toIntern(),
36928 .storage = .{ .elems = field_vals },36928 .storage = .{ .elems = field_vals },
36929 } })).toValue();36929 } })));
36930 },36930 },
3693136931
36932 .anon_struct_type => |tuple| {36932 .anon_struct_type => |tuple| {
...@@ -36936,22 +36936,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36936,22 +36936,22 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36936 // In this case the struct has all comptime-known fields and36936 // In this case the struct has all comptime-known fields and
36937 // therefore has one possible value.36937 // therefore has one possible value.
36938 // TODO: write something like getCoercedInts to avoid needing to dupe36938 // TODO: write something like getCoercedInts to avoid needing to dupe
36939 return (try mod.intern(.{ .aggregate = .{36939 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
36940 .ty = ty.toIntern(),36940 .ty = ty.toIntern(),
36941 .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) },36941 .storage = .{ .elems = try sema.arena.dupe(InternPool.Index, tuple.values.get(ip)) },
36942 } })).toValue();36942 } })));
36943 },36943 },
3694436944
36945 .union_type => |union_type| {36945 .union_type => |union_type| {
36946 try sema.resolveTypeFields(ty);36946 try sema.resolveTypeFields(ty);
36947 const union_obj = ip.loadUnionType(union_type);36947 const union_obj = ip.loadUnionType(union_type);
36948 const tag_val = (try sema.typeHasOnePossibleValue(union_obj.enum_tag_ty.toType())) orelse36948 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.enum_tag_ty))) orelse
36949 return null;36949 return null;
36950 if (union_obj.field_types.len == 0) {36950 if (union_obj.field_types.len == 0) {
36951 const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() });36951 const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() });
36952 return only.toValue();36952 return Value.fromInterned(only);
36953 }36953 }
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]);
36955 if (only_field_ty.eql(ty, mod)) {36955 if (only_field_ty.eql(ty, mod)) {
36956 const msg = try Module.ErrorMsg.create(36956 const msg = try Module.ErrorMsg.create(
36957 sema.gpa,36957 sema.gpa,
...@@ -36969,32 +36969,32 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -36969,32 +36969,32 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
36969 .tag = tag_val.toIntern(),36969 .tag = tag_val.toIntern(),
36970 .val = val_val.toIntern(),36970 .val = val_val.toIntern(),
36971 } });36971 } });
36972 return only.toValue();36972 return Value.fromInterned(only);
36973 },36973 },
3697436974
36975 .enum_type => |enum_type| switch (enum_type.tag_mode) {36975 .enum_type => |enum_type| switch (enum_type.tag_mode) {
36976 .nonexhaustive => {36976 .nonexhaustive => {
36977 if (enum_type.tag_ty == .comptime_int_type) return null;36977 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| {
36980 const only = try mod.intern(.{ .enum_tag = .{36980 const only = try mod.intern(.{ .enum_tag = .{
36981 .ty = ty.toIntern(),36981 .ty = ty.toIntern(),
36982 .int = int_opv.toIntern(),36982 .int = int_opv.toIntern(),
36983 } });36983 } });
36984 return only.toValue();36984 return Value.fromInterned(only);
36985 }36985 }
3698636986
36987 return null;36987 return null;
36988 },36988 },
36989 .auto, .explicit => {36989 .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) {
36993 0 => try mod.intern(.{ .empty_enum_value = ty.toIntern() }),36993 0 => try mod.intern(.{ .empty_enum_value = ty.toIntern() }),
36994 1 => try mod.intern(.{ .enum_tag = .{36994 1 => try mod.intern(.{ .enum_tag = .{
36995 .ty = ty.toIntern(),36995 .ty = ty.toIntern(),
36996 .int = if (enum_type.values.len == 0)36996 .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()
36998 else36998 else
36999 try mod.intern_pool.getCoercedInts(36999 try mod.intern_pool.getCoercedInts(
37000 mod.gpa,37000 mod.gpa,
...@@ -37003,7 +37003,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37003,7 +37003,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37003 ),37003 ),
37004 } }),37004 } }),
37005 else => return null,37005 else => return null,
37006 }.toValue();37006 });
37007 },37007 },
37008 },37008 },
3700937009
...@@ -37092,7 +37092,7 @@ fn analyzeComptimeAlloc(...@@ -37092,7 +37092,7 @@ fn analyzeComptimeAlloc(
37092 // There will be stores before the first load, but they may be to sub-elements or37092 // There will be stores before the first load, but they may be to sub-elements or
37093 // sub-fields. So we need to initialize with undef to allow the mechanism to expand37093 // sub-fields. So we need to initialize with undef to allow the mechanism to expand
37094 // into fields/elements and have those overridden with stored values.37094 // 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() }))),
37096 alignment,37096 alignment,
37097 );37097 );
37098 const decl = mod.declPtr(decl_index);37098 const decl = mod.declPtr(decl_index);
...@@ -37226,7 +37226,7 @@ fn pointerDerefExtra(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value...@@ -37226,7 +37226,7 @@ fn pointerDerefExtra(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value
37226 // Move mutable decl values to the InternPool and assert other decls are already in37226 // Move mutable decl values to the InternPool and assert other decls are already in
37227 // the InternPool.37227 // the InternPool.
37228 const uncoerced_val = if (deref.is_mutable) try tv.val.intern(tv.ty, mod) else tv.val.toIntern();37228 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);
37230 return .{ .val = coerced_val };37230 return .{ .val = coerced_val };
37231 }37231 }
37232 }37232 }
...@@ -37284,7 +37284,7 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {...@@ -37284,7 +37284,7 @@ fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
37284 if (ptr_type.flags.is_allowzero) return null;37284 if (ptr_type.flags.is_allowzero) return null;
3728537285
37286 // optionals of zero sized types behave like bools, not pointers37286 // 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);
37288 if ((try sema.typeHasOnePossibleValue(payload_ty)) != null) {37288 if ((try sema.typeHasOnePossibleValue(payload_ty)) != null) {
37289 return null;37289 return null;
37290 }37290 }
...@@ -37328,7 +37328,7 @@ fn unionFieldAlignment(sema: *Sema, u: InternPool.UnionType, field_index: u32) !...@@ -37328,7 +37328,7 @@ fn unionFieldAlignment(sema: *Sema, u: InternPool.UnionType, field_index: u32) !
37328 const ip = &mod.intern_pool;37328 const ip = &mod.intern_pool;
37329 const field_align = u.fieldAlign(ip, field_index);37329 const field_align = u.fieldAlign(ip, field_index);
37330 if (field_align != .none) return field_align;37330 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]);
37332 if (field_ty.isNoReturn(sema.mod)) return .none;37332 if (field_ty.isNoReturn(sema.mod)) return .none;
37333 return sema.typeAbiAlignment(field_ty);37333 return sema.typeAbiAlignment(field_ty);
37334}37334}
...@@ -37458,10 +37458,10 @@ fn intAddInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usi...@@ -37458,10 +37458,10 @@ fn intAddInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usi
37458 };37458 };
37459 scalar.* = try val.intern(scalar_ty, mod);37459 scalar.* = try val.intern(scalar_ty, mod);
37460 }37460 }
37461 return (try mod.intern(.{ .aggregate = .{37461 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37462 .ty = ty.toIntern(),37462 .ty = ty.toIntern(),
37463 .storage = .{ .elems = result_data },37463 .storage = .{ .elems = result_data },
37464 } })).toValue();37464 } })));
37465 }37465 }
37466 return sema.intAddScalar(lhs, rhs, ty);37466 return sema.intAddScalar(lhs, rhs, ty);
37467}37467}
...@@ -37548,10 +37548,10 @@ fn intSubInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usi...@@ -37548,10 +37548,10 @@ fn intSubInner(sema: *Sema, lhs: Value, rhs: Value, ty: Type, overflow_idx: *usi
37548 };37548 };
37549 scalar.* = try val.intern(scalar_ty, mod);37549 scalar.* = try val.intern(scalar_ty, mod);
37550 }37550 }
37551 return (try mod.intern(.{ .aggregate = .{37551 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37552 .ty = ty.toIntern(),37552 .ty = ty.toIntern(),
37553 .storage = .{ .elems = result_data },37553 .storage = .{ .elems = result_data },
37554 } })).toValue();37554 } })));
37555 }37555 }
37556 return sema.intSubScalar(lhs, rhs, ty);37556 return sema.intSubScalar(lhs, rhs, ty);
37557}37557}
...@@ -37620,14 +37620,14 @@ fn intSubWithOverflow(...@@ -37620,14 +37620,14 @@ fn intSubWithOverflow(
37620 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);37620 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
37621 }37621 }
37622 return Value.OverflowArithmeticResult{37622 return Value.OverflowArithmeticResult{
37623 .overflow_bit = (try mod.intern(.{ .aggregate = .{37623 .overflow_bit = Value.fromInterned((try mod.intern(.{ .aggregate = .{
37624 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),37624 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),
37625 .storage = .{ .elems = overflowed_data },37625 .storage = .{ .elems = overflowed_data },
37626 } })).toValue(),37626 } }))),
37627 .wrapped_result = (try mod.intern(.{ .aggregate = .{37627 .wrapped_result = Value.fromInterned((try mod.intern(.{ .aggregate = .{
37628 .ty = ty.toIntern(),37628 .ty = ty.toIntern(),
37629 .storage = .{ .elems = result_data },37629 .storage = .{ .elems = result_data },
37630 } })).toValue(),37630 } }))),
37631 };37631 };
37632 }37632 }
37633 return sema.intSubWithOverflowScalar(lhs, rhs, ty);37633 return sema.intSubWithOverflowScalar(lhs, rhs, ty);
...@@ -37679,10 +37679,10 @@ fn intFromFloat(...@@ -37679,10 +37679,10 @@ fn intFromFloat(
37679 const elem_val = try val.elemValue(sema.mod, i);37679 const elem_val = try val.elemValue(sema.mod, i);
37680 scalar.* = try (try sema.intFromFloatScalar(block, src, elem_val, elem_ty, int_ty.scalarType(mod), mode)).intern(scalar_ty, mod);37680 scalar.* = try (try sema.intFromFloatScalar(block, src, elem_val, elem_ty, int_ty.scalarType(mod), mode)).intern(scalar_ty, mod);
37681 }37681 }
37682 return (try mod.intern(.{ .aggregate = .{37682 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37683 .ty = int_ty.toIntern(),37683 .ty = int_ty.toIntern(),
37684 .storage = .{ .elems = result_data },37684 .storage = .{ .elems = result_data },
37685 } })).toValue();37685 } })));
37686 }37686 }
37687 return sema.intFromFloatScalar(block, src, val, float_ty, int_ty, mode);37687 return sema.intFromFloatScalar(block, src, val, float_ty, int_ty, mode);
37688}37688}
...@@ -37792,7 +37792,7 @@ fn intFitsInType(...@@ -37792,7 +37792,7 @@ fn intFitsInType(
37792 const max_needed_bits = @as(u16, 16) + @intFromBool(info.signedness == .signed);37792 const max_needed_bits = @as(u16, 16) + @intFromBool(info.signedness == .signed);
37793 // If it is u16 or bigger we know the alignment fits without resolving it.37793 // If it is u16 or bigger we know the alignment fits without resolving it.
37794 if (info.bits >= max_needed_bits) return true;37794 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));
37796 if (x == .none) return true;37796 if (x == .none) return true;
37797 const actual_needed_bits = @as(usize, x.toLog2Units()) + 1 + @intFromBool(info.signedness == .signed);37797 const actual_needed_bits = @as(usize, x.toLog2Units()) + 1 + @intFromBool(info.signedness == .signed);
37798 return info.bits >= actual_needed_bits;37798 return info.bits >= actual_needed_bits;
...@@ -37801,7 +37801,7 @@ fn intFitsInType(...@@ -37801,7 +37801,7 @@ fn intFitsInType(
37801 const max_needed_bits = @as(u16, 64) + @intFromBool(info.signedness == .signed);37801 const max_needed_bits = @as(u16, 64) + @intFromBool(info.signedness == .signed);
37802 // If it is u64 or bigger we know the size fits without resolving it.37802 // If it is u64 or bigger we know the size fits without resolving it.
37803 if (info.bits >= max_needed_bits) return true;37803 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));
37805 if (x == 0) return true;37805 if (x == 0) return true;
37806 const actual_needed_bits = std.math.log2(x) + 1 + @intFromBool(info.signedness == .signed);37806 const actual_needed_bits = std.math.log2(x) + 1 + @intFromBool(info.signedness == .signed);
37807 return info.bits >= actual_needed_bits;37807 return info.bits >= actual_needed_bits;
...@@ -37822,7 +37822,7 @@ fn intFitsInType(...@@ -37822,7 +37822,7 @@ fn intFitsInType(
37822 .elems => |elems| elems,37822 .elems => |elems| elems,
37823 .repeated_elem => |elem| @as(*const [1]InternPool.Index, &elem),37823 .repeated_elem => |elem| @as(*const [1]InternPool.Index, &elem),
37824 }, 0..) |elem, i| {37824 }, 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;
37826 if (vector_index) |vi| vi.* = i;37826 if (vector_index) |vi| vi.* = i;
37827 break false;37827 break false;
37828 } else true,37828 } else true,
...@@ -37848,8 +37848,8 @@ fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {...@@ -37848,8 +37848,8 @@ fn enumHasInt(sema: *Sema, ty: Type, int: Value) CompileError!bool {
37848 assert(enum_type.tag_mode != .nonexhaustive);37848 assert(enum_type.tag_mode != .nonexhaustive);
37849 // The `tagValueIndex` function call below relies on the type being the integer tag type.37849 // The `tagValueIndex` function call below relies on the type being the integer tag type.
37850 // `getCoerced` assumes the value will fit the new type.37850 // `getCoerced` assumes the value will fit the new type.
37851 if (!(try sema.intFitsInType(int, enum_type.tag_ty.toType(), null))) return false;37851 if (!(try sema.intFitsInType(int, Type.fromInterned(enum_type.tag_ty), null))) return false;
37852 const int_coerced = try mod.getCoerced(int, enum_type.tag_ty.toType());37852 const int_coerced = try mod.getCoerced(int, Type.fromInterned(enum_type.tag_ty));
3785337853
37854 return enum_type.tagValueIndex(&mod.intern_pool, int_coerced.toIntern()) != null;37854 return enum_type.tagValueIndex(&mod.intern_pool, int_coerced.toIntern()) != null;
37855}37855}
...@@ -37874,14 +37874,14 @@ fn intAddWithOverflow(...@@ -37874,14 +37874,14 @@ fn intAddWithOverflow(
37874 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);37874 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
37875 }37875 }
37876 return Value.OverflowArithmeticResult{37876 return Value.OverflowArithmeticResult{
37877 .overflow_bit = (try mod.intern(.{ .aggregate = .{37877 .overflow_bit = Value.fromInterned((try mod.intern(.{ .aggregate = .{
37878 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),37878 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),
37879 .storage = .{ .elems = overflowed_data },37879 .storage = .{ .elems = overflowed_data },
37880 } })).toValue(),37880 } }))),
37881 .wrapped_result = (try mod.intern(.{ .aggregate = .{37881 .wrapped_result = Value.fromInterned((try mod.intern(.{ .aggregate = .{
37882 .ty = ty.toIntern(),37882 .ty = ty.toIntern(),
37883 .storage = .{ .elems = result_data },37883 .storage = .{ .elems = result_data },
37884 } })).toValue(),37884 } }))),
37885 };37885 };
37886 }37886 }
37887 return sema.intAddWithOverflowScalar(lhs, rhs, ty);37887 return sema.intAddWithOverflowScalar(lhs, rhs, ty);
...@@ -37983,10 +37983,10 @@ fn compareVector(...@@ -37983,10 +37983,10 @@ fn compareVector(
37983 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod));37983 const res_bool = try sema.compareScalar(lhs_elem, op, rhs_elem, ty.scalarType(mod));
37984 scalar.* = try Value.makeBool(res_bool).intern(Type.bool, mod);37984 scalar.* = try Value.makeBool(res_bool).intern(Type.bool, mod);
37985 }37985 }
37986 return (try mod.intern(.{ .aggregate = .{37986 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
37987 .ty = (try mod.vectorType(.{ .len = ty.vectorLen(mod), .child = .bool_type })).toIntern(),37987 .ty = (try mod.vectorType(.{ .len = ty.vectorLen(mod), .child = .bool_type })).toIntern(),
37988 .storage = .{ .elems = result_data },37988 .storage = .{ .elems = result_data },
37989 } })).toValue();37989 } })));
37990}37990}
3799137991
37992/// Returns the type of a pointer to an element.37992/// 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...@@ -38102,7 +38102,7 @@ fn isKnownZigType(sema: *Sema, ref: Air.Inst.Ref, tag: std.builtin.TypeId) bool
3810238102
38103fn ptrType(sema: *Sema, info: InternPool.Key.PtrType) CompileError!Type {38103fn ptrType(sema: *Sema, info: InternPool.Key.PtrType) CompileError!Type {
38104 if (info.flags.alignment != .none) {38104 if (info.flags.alignment != .none) {
38105 _ = try sema.typeAbiAlignment(info.child.toType());38105 _ = try sema.typeAbiAlignment(Type.fromInterned(info.child));
38106 }38106 }
38107 return sema.mod.ptrType(info);38107 return sema.mod.ptrType(info);
38108}38108}
src/TypedValue.zig+25-25
...@@ -89,7 +89,7 @@ pub fn print(...@@ -89,7 +89,7 @@ pub fn print(
8989
90 if (payload.tag) |tag| {90 if (payload.tag) |tag| {
91 try print(.{91 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),
93 .val = tag,93 .val = tag,
94 }, writer, level - 1, mod);94 }, writer, level - 1, mod);
95 try writer.writeAll(" = ");95 try writer.writeAll(" = ");
...@@ -222,10 +222,10 @@ pub fn print(...@@ -222,10 +222,10 @@ pub fn print(
222 .int => |int| switch (int.storage) {222 .int => |int| switch (int.storage) {
223 inline .u64, .i64, .big_int => |x| return writer.print("{}", .{x}),223 inline .u64, .i64, .big_int => |x| return writer.print("{}", .{x}),
224 .lazy_align => |lazy_ty| return writer.print("{d}", .{224 .lazy_align => |lazy_ty| return writer.print("{d}", .{
225 lazy_ty.toType().abiAlignment(mod),225 Type.fromInterned(lazy_ty).abiAlignment(mod),
226 }),226 }),
227 .lazy_size => |lazy_ty| return writer.print("{d}", .{227 .lazy_size => |lazy_ty| return writer.print("{d}", .{
228 lazy_ty.toType().abiSize(mod),228 Type.fromInterned(lazy_ty).abiSize(mod),
229 }),229 }),
230 },230 },
231 .err => |err| return writer.print("error.{}", .{231 .err => |err| return writer.print("error.{}", .{
...@@ -236,7 +236,7 @@ pub fn print(...@@ -236,7 +236,7 @@ pub fn print(
236 err_name.fmt(ip),236 err_name.fmt(ip),
237 }),237 }),
238 .payload => |payload| {238 .payload => |payload| {
239 val = payload.toValue();239 val = Value.fromInterned(payload);
240 ty = ty.errorUnionPayload(mod);240 ty = ty.errorUnionPayload(mod);
241 },241 },
242 },242 },
...@@ -254,8 +254,8 @@ pub fn print(...@@ -254,8 +254,8 @@ pub fn print(
254 }254 }
255 try writer.writeAll("@enumFromInt(");255 try writer.writeAll("@enumFromInt(");
256 try print(.{256 try print(.{
257 .ty = ip.typeOf(enum_tag.int).toType(),257 .ty = Type.fromInterned(ip.typeOf(enum_tag.int)),
258 .val = enum_tag.int.toValue(),258 .val = Value.fromInterned(enum_tag.int),
259 }, writer, level - 1, mod);259 }, writer, level - 1, mod);
260 try writer.writeAll(")");260 try writer.writeAll(")");
261 return;261 return;
...@@ -280,8 +280,8 @@ pub fn print(...@@ -280,8 +280,8 @@ pub fn print(
280 if (level == 0) {280 if (level == 0) {
281 return writer.writeAll(".{ ... }");281 return writer.writeAll(".{ ... }");
282 }282 }
283 const elem_ty = ptr_ty.child.toType();283 const elem_ty = Type.fromInterned(ptr_ty.child);
284 const len = ptr.len.toValue().toUnsignedInt(mod);284 const len = Value.fromInterned(ptr.len).toUnsignedInt(mod);
285 if (elem_ty.eql(Type.u8, mod)) str: {285 if (elem_ty.eql(Type.u8, mod)) str: {
286 const max_len = @min(len, max_string_len);286 const max_len = @min(len, max_string_len);
287 var buf: [max_string_len]u8 = undefined;287 var buf: [max_string_len]u8 = undefined;
...@@ -326,8 +326,8 @@ pub fn print(...@@ -326,8 +326,8 @@ pub fn print(
326 @intFromEnum(decl_val),326 @intFromEnum(decl_val),
327 });327 });
328 return print(.{328 return print(.{
329 .ty = ip.typeOf(decl_val).toType(),329 .ty = Type.fromInterned(ip.typeOf(decl_val)),
330 .val = decl_val.toValue(),330 .val = Value.fromInterned(decl_val),
331 }, writer, level - 1, mod);331 }, writer, level - 1, mod);
332 },332 },
333 .mut_decl => |mut_decl| {333 .mut_decl => |mut_decl| {
...@@ -340,38 +340,38 @@ pub fn print(...@@ -340,38 +340,38 @@ pub fn print(
340 },340 },
341 .comptime_field => |field_val_ip| {341 .comptime_field => |field_val_ip| {
342 return print(.{342 return print(.{
343 .ty = ip.typeOf(field_val_ip).toType(),343 .ty = Type.fromInterned(ip.typeOf(field_val_ip)),
344 .val = field_val_ip.toValue(),344 .val = Value.fromInterned(field_val_ip),
345 }, writer, level - 1, mod);345 }, writer, level - 1, mod);
346 },346 },
347 .int => unreachable,347 .int => unreachable,
348 .eu_payload => |eu_ip| {348 .eu_payload => |eu_ip| {
349 try writer.writeAll("(payload of ");349 try writer.writeAll("(payload of ");
350 try print(.{350 try print(.{
351 .ty = ip.typeOf(eu_ip).toType(),351 .ty = Type.fromInterned(ip.typeOf(eu_ip)),
352 .val = eu_ip.toValue(),352 .val = Value.fromInterned(eu_ip),
353 }, writer, level - 1, mod);353 }, writer, level - 1, mod);
354 try writer.writeAll(")");354 try writer.writeAll(")");
355 },355 },
356 .opt_payload => |opt_ip| {356 .opt_payload => |opt_ip| {
357 try print(.{357 try print(.{
358 .ty = ip.typeOf(opt_ip).toType(),358 .ty = Type.fromInterned(ip.typeOf(opt_ip)),
359 .val = opt_ip.toValue(),359 .val = Value.fromInterned(opt_ip),
360 }, writer, level - 1, mod);360 }, writer, level - 1, mod);
361 try writer.writeAll(".?");361 try writer.writeAll(".?");
362 },362 },
363 .elem => |elem| {363 .elem => |elem| {
364 try print(.{364 try print(.{
365 .ty = ip.typeOf(elem.base).toType(),365 .ty = Type.fromInterned(ip.typeOf(elem.base)),
366 .val = elem.base.toValue(),366 .val = Value.fromInterned(elem.base),
367 }, writer, level - 1, mod);367 }, writer, level - 1, mod);
368 try writer.print("[{}]", .{elem.index});368 try writer.print("[{}]", .{elem.index});
369 },369 },
370 .field => |field| {370 .field => |field| {
371 const ptr_container_ty = ip.typeOf(field.base).toType();371 const ptr_container_ty = Type.fromInterned(ip.typeOf(field.base));
372 try print(.{372 try print(.{
373 .ty = ptr_container_ty,373 .ty = ptr_container_ty,
374 .val = field.base.toValue(),374 .val = Value.fromInterned(field.base),
375 }, writer, level - 1, mod);375 }, writer, level - 1, mod);
376376
377 const container_ty = ptr_container_ty.childType(mod);377 const container_ty = ptr_container_ty.childType(mod);
...@@ -404,7 +404,7 @@ pub fn print(...@@ -404,7 +404,7 @@ pub fn print(
404 .opt => |opt| switch (opt.val) {404 .opt => |opt| switch (opt.val) {
405 .none => return writer.writeAll("null"),405 .none => return writer.writeAll("null"),
406 else => |payload| {406 else => |payload| {
407 val = payload.toValue();407 val = Value.fromInterned(payload);
408 ty = ty.optionalChild(mod);408 ty = ty.optionalChild(mod);
409 },409 },
410 },410 },
...@@ -426,20 +426,20 @@ pub fn print(...@@ -426,20 +426,20 @@ pub fn print(
426 if (un.tag != .none) {426 if (un.tag != .none) {
427 try print(.{427 try print(.{
428 .ty = ty.unionTagTypeHypothetical(mod),428 .ty = ty.unionTagTypeHypothetical(mod),
429 .val = un.tag.toValue(),429 .val = Value.fromInterned(un.tag),
430 }, writer, level - 1, mod);430 }, writer, level - 1, mod);
431 try writer.writeAll(" = ");431 try writer.writeAll(" = ");
432 const field_ty = ty.unionFieldType(un.tag.toValue(), mod).?;432 const field_ty = ty.unionFieldType(Value.fromInterned(un.tag), mod).?;
433 try print(.{433 try print(.{
434 .ty = field_ty,434 .ty = field_ty,
435 .val = un.val.toValue(),435 .val = Value.fromInterned(un.val),
436 }, writer, level - 1, mod);436 }, writer, level - 1, mod);
437 } else {437 } else {
438 try writer.writeAll("(unknown tag) = ");438 try writer.writeAll("(unknown tag) = ");
439 const backing_ty = try ty.unionBackingType(mod);439 const backing_ty = try ty.unionBackingType(mod);
440 try print(.{440 try print(.{
441 .ty = backing_ty,441 .ty = backing_ty,
442 .val = un.val.toValue(),442 .val = Value.fromInterned(un.val),
443 }, writer, level - 1, mod);443 }, writer, level - 1, mod);
444 }444 }
445 } else try writer.writeAll("...");445 } else try writer.writeAll("...");
src/arch/aarch64/CodeGen.zig+7-7
...@@ -6245,7 +6245,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6245,7 +6245,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6245 }6245 }
62466246
6247 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {6247 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)));
6249 if (param_size == 0) {6249 if (param_size == 0) {
6250 result_arg.* = .{ .none = {} };6250 result_arg.* = .{ .none = {} };
6251 continue;6251 continue;
...@@ -6253,14 +6253,14 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6253,14 +6253,14 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
62536253
6254 // We round up NCRN only for non-Apple platforms which allow the 16-byte aligned6254 // We round up NCRN only for non-Apple platforms which allow the 16-byte aligned
6255 // values to spread across odd-numbered registers.6255 // 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()) {
6257 // Round up NCRN to the next even number6257 // Round up NCRN to the next even number
6258 ncrn += ncrn % 2;6258 ncrn += ncrn % 2;
6259 }6259 }
62606260
6261 if (std.math.divCeil(u32, param_size, 8) catch unreachable <= 8 - ncrn) {6261 if (std.math.divCeil(u32, param_size, 8) catch unreachable <= 8 - ncrn) {
6262 if (param_size <= 8) {6262 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)) };
6264 ncrn += 1;6264 ncrn += 1;
6265 } else {6265 } else {
6266 return self.fail("TODO MCValues with multiple registers", .{});6266 return self.fail("TODO MCValues with multiple registers", .{});
...@@ -6271,7 +6271,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6271,7 +6271,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6271 ncrn = 8;6271 ncrn = 8;
6272 // TODO Apple allows the arguments on the stack to be non-8-byte aligned provided6272 // TODO Apple allows the arguments on the stack to be non-8-byte aligned provided
6273 // that the entire stack space consumed by the arguments is 8-byte aligned.6273 // 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") {
6275 if (nsaa % 8 != 0) {6275 if (nsaa % 8 != 0) {
6276 nsaa += 8 - (nsaa % 8);6276 nsaa += 8 - (nsaa % 8);
6277 }6277 }
...@@ -6310,9 +6310,9 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6310,9 +6310,9 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6310 var stack_offset: u32 = 0;6310 var stack_offset: u32 = 0;
63116311
6312 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {6312 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
6313 if (ty.toType().abiSize(mod) > 0) {6313 if (Type.fromInterned(ty).abiSize(mod) > 0) {
6314 const param_size: u32 = @intCast(ty.toType().abiSize(mod));6314 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(mod));
6315 const param_alignment = ty.toType().abiAlignment(mod);6315 const param_alignment = Type.fromInterned(ty).abiAlignment(mod);
63166316
6317 stack_offset = @intCast(param_alignment.forward(stack_offset));6317 stack_offset = @intCast(param_alignment.forward(stack_offset));
6318 result_arg.* = .{ .stack_argument_offset = stack_offset };6318 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 {...@@ -83,7 +83,7 @@ fn countFloats(ty: Type, mod: *Module, maybe_float_bits: *?u16) u8 {
83 const union_obj = mod.typeToUnion(ty).?;83 const union_obj = mod.typeToUnion(ty).?;
84 var max_count: u8 = 0;84 var max_count: u8 = 0;
85 for (union_obj.field_types.get(ip)) |field_ty| {85 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);
87 if (field_count == invalid) return invalid;87 if (field_count == invalid) return invalid;
88 if (field_count > max_count) max_count = field_count;88 if (field_count > max_count) max_count = field_count;
89 if (max_count > sret_float_count) return invalid;89 if (max_count > sret_float_count) return invalid;
...@@ -122,7 +122,7 @@ pub fn getFloatArrayType(ty: Type, mod: *Module) ?Type {...@@ -122,7 +122,7 @@ pub fn getFloatArrayType(ty: Type, mod: *Module) ?Type {
122 .Union => {122 .Union => {
123 const union_obj = mod.typeToUnion(ty).?;123 const union_obj = mod.typeToUnion(ty).?;
124 for (union_obj.field_types.get(ip)) |field_ty| {124 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;
126 }126 }
127 return null;127 return null;
128 },128 },
src/arch/arm/CodeGen.zig+6-6
...@@ -6209,10 +6209,10 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6209,10 +6209,10 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6209 }6209 }
62106210
6211 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {6211 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")
6213 ncrn = std.mem.alignForward(usize, ncrn, 2);6213 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)));
6216 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {6216 if (std.math.divCeil(u32, param_size, 4) catch unreachable <= 4 - ncrn) {
6217 if (param_size <= 4) {6217 if (param_size <= 4) {
6218 result_arg.* = .{ .register = c_abi_int_param_regs[ncrn] };6218 result_arg.* = .{ .register = c_abi_int_param_regs[ncrn] };
...@@ -6224,7 +6224,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6224,7 +6224,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6224 return self.fail("TODO MCValues split between registers and stack", .{});6224 return self.fail("TODO MCValues split between registers and stack", .{});
6225 } else {6225 } else {
6226 ncrn = 4;6226 ncrn = 4;
6227 if (ty.toType().abiAlignment(mod) == .@"8")6227 if (Type.fromInterned(ty).abiAlignment(mod) == .@"8")
6228 nsaa = std.mem.alignForward(u32, nsaa, 8);6228 nsaa = std.mem.alignForward(u32, nsaa, 8);
62296229
6230 result_arg.* = .{ .stack_argument_offset = nsaa };6230 result_arg.* = .{ .stack_argument_offset = nsaa };
...@@ -6259,9 +6259,9 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {...@@ -6259,9 +6259,9 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
6259 var stack_offset: u32 = 0;6259 var stack_offset: u32 = 0;
62606260
6261 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {6261 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {
6262 if (ty.toType().abiSize(mod) > 0) {6262 if (Type.fromInterned(ty).abiSize(mod) > 0) {
6263 const param_size: u32 = @intCast(ty.toType().abiSize(mod));6263 const param_size: u32 = @intCast(Type.fromInterned(ty).abiSize(mod));
6264 const param_alignment = ty.toType().abiAlignment(mod);6264 const param_alignment = Type.fromInterned(ty).abiAlignment(mod);
62656265
6266 stack_offset = @intCast(param_alignment.forward(stack_offset));6266 stack_offset = @intCast(param_alignment.forward(stack_offset));
6267 result_arg.* = .{ .stack_argument_offset = stack_offset };6267 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 {...@@ -65,7 +65,7 @@ pub fn classifyType(ty: Type, mod: *Module, ctx: Context) Class {
65 if (float_count <= byval_float_count) return .byval;65 if (float_count <= byval_float_count) return .byval;
6666
67 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {67 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
68 if (field_ty.toType().bitSize(mod) > 32 or68 if (Type.fromInterned(field_ty).bitSize(mod) > 32 or
69 mod.unionFieldNormalAlignment(union_obj, @intCast(field_index)).compare(.gt, .@"32"))69 mod.unionFieldNormalAlignment(union_obj, @intCast(field_index)).compare(.gt, .@"32"))
70 {70 {
71 return Class.arrSize(bit_size, 64);71 return Class.arrSize(bit_size, 64);
...@@ -129,7 +129,7 @@ fn countFloats(ty: Type, mod: *Module, maybe_float_bits: *?u16) u32 {...@@ -129,7 +129,7 @@ fn countFloats(ty: Type, mod: *Module, maybe_float_bits: *?u16) u32 {
129 const union_obj = mod.typeToUnion(ty).?;129 const union_obj = mod.typeToUnion(ty).?;
130 var max_count: u32 = 0;130 var max_count: u32 = 0;
131 for (union_obj.field_types.get(ip)) |field_ty| {131 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);
133 if (field_count == invalid) return invalid;133 if (field_count == invalid) return invalid;
134 if (field_count > max_count) max_count = field_count;134 if (field_count > max_count) max_count = field_count;
135 if (max_count > byval_float_count) return invalid;135 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 {...@@ -2656,7 +2656,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type) !CallMCValues {
2656 const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 };2656 const argument_registers = [_]Register{ .a0, .a1, .a2, .a3, .a4, .a5, .a6, .a7 };
26572657
2658 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {2658 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)));
2660 if (param_size <= 8) {2660 if (param_size <= 8) {
2661 if (next_register < argument_registers.len) {2661 if (next_register < argument_registers.len) {
2662 result_arg.* = .{ .register = argument_registers[next_register] };2662 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)...@@ -4493,7 +4493,7 @@ fn resolveCallingConventionValues(self: *Self, fn_ty: Type, role: RegisterView)
4493 };4493 };
44944494
4495 for (fn_info.param_types.get(ip), result.args) |ty, *result_arg| {4495 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)));
4497 if (param_size <= 8) {4497 if (param_size <= 8) {
4498 if (next_register < argument_registers.len) {4498 if (next_register < argument_registers.len) {
4499 result_arg.* = .{ .register = argument_registers[next_register] };4499 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 {...@@ -1009,7 +1009,7 @@ fn typeToValtype(ty: Type, mod: *Module) wasm.Valtype {
1009 },1009 },
1010 .Struct => {1010 .Struct => {
1011 if (mod.typeToPackedStruct(ty)) |packed_struct| {1011 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);
1013 } else {1013 } else {
1014 return wasm.Valtype.i32;1014 return wasm.Valtype.i32;
1015 }1015 }
...@@ -1171,7 +1171,7 @@ fn genFunctype(...@@ -1171,7 +1171,7 @@ fn genFunctype(
11711171
1172 // param types1172 // param types
1173 for (params) |param_type_ip| {1173 for (params) |param_type_ip| {
1174 const param_type = param_type_ip.toType();1174 const param_type = Type.fromInterned(param_type_ip);
1175 if (!param_type.hasRuntimeBitsIgnoreComptime(mod)) continue;1175 if (!param_type.hasRuntimeBitsIgnoreComptime(mod)) continue;
11761176
1177 switch (cc) {1177 switch (cc) {
...@@ -1240,7 +1240,7 @@ fn genFunc(func: *CodeGen) InnerError!void {...@@ -1240,7 +1240,7 @@ fn genFunc(func: *CodeGen) InnerError!void {
1240 const mod = func.bin_file.base.options.module.?;1240 const mod = func.bin_file.base.options.module.?;
1241 const ip = &mod.intern_pool;1241 const ip = &mod.intern_pool;
1242 const fn_info = mod.typeToFunc(func.decl.ty).?;1242 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);
1244 defer func_type.deinit(func.gpa);1244 defer func_type.deinit(func.gpa);
1245 _ = try func.bin_file.storeDeclType(func.decl_index, func_type);1245 _ = try func.bin_file.storeDeclType(func.decl_index, func_type);
12461246
...@@ -1363,7 +1363,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV...@@ -1363,7 +1363,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
13631363
1364 // Check if we store the result as a pointer to the stack rather than1364 // Check if we store the result as a pointer to the stack rather than
1365 // by value1365 // 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)) {
1367 // the sret arg will be passed as first argument, therefore we1367 // the sret arg will be passed as first argument, therefore we
1368 // set the `return_value` before allocating locals for regular args.1368 // set the `return_value` before allocating locals for regular args.
1369 result.return_value = .{ .local = .{ .value = func.local_index, .references = 1 } };1369 result.return_value = .{ .local = .{ .value = func.local_index, .references = 1 } };
...@@ -1373,7 +1373,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV...@@ -1373,7 +1373,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
1373 switch (cc) {1373 switch (cc) {
1374 .Unspecified => {1374 .Unspecified => {
1375 for (fn_info.param_types.get(ip)) |ty| {1375 for (fn_info.param_types.get(ip)) |ty| {
1376 if (!ty.toType().hasRuntimeBitsIgnoreComptime(mod)) {1376 if (!Type.fromInterned(ty).hasRuntimeBitsIgnoreComptime(mod)) {
1377 continue;1377 continue;
1378 }1378 }
13791379
...@@ -1383,7 +1383,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV...@@ -1383,7 +1383,7 @@ fn resolveCallingConventionValues(func: *CodeGen, fn_ty: Type) InnerError!CallWV
1383 },1383 },
1384 .C => {1384 .C => {
1385 for (fn_info.param_types.get(ip)) |ty| {1385 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);
1387 for (ty_classes) |class| {1387 for (ty_classes) |class| {
1388 if (class == .none) continue;1388 if (class == .none) continue;
1389 try args.append(.{ .local = .{ .value = func.local_index, .references = 1 } });1389 try args.append(.{ .local = .{ .value = func.local_index, .references = 1 } });
...@@ -1748,7 +1748,7 @@ fn isByRef(ty: Type, mod: *Module) bool {...@@ -1748,7 +1748,7 @@ fn isByRef(ty: Type, mod: *Module) bool {
1748 },1748 },
1749 .Struct => {1749 .Struct => {
1750 if (mod.typeToPackedStruct(ty)) |packed_struct| {1750 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);
1752 }1752 }
1753 return ty.hasRuntimeBitsIgnoreComptime(mod);1753 return ty.hasRuntimeBitsIgnoreComptime(mod);
1754 },1754 },
...@@ -2097,7 +2097,7 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2097,7 +2097,7 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2097 const un_op = func.air.instructions.items(.data)[inst].un_op;2097 const un_op = func.air.instructions.items(.data)[inst].un_op;
2098 const operand = try func.resolveInst(un_op);2098 const operand = try func.resolveInst(un_op);
2099 const fn_info = mod.typeToFunc(func.decl.ty).?;2099 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
2102 // result must be stored in the stack and we return a pointer2102 // result must be stored in the stack and we return a pointer
2103 // to the stack instead2103 // to the stack instead
...@@ -2145,7 +2145,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2145,7 +2145,7 @@ fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2145 }2145 }
21462146
2147 const fn_info = mod.typeToFunc(func.decl.ty).?;2147 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)) {
2149 break :result func.return_value;2149 break :result func.return_value;
2150 }2150 }
21512151
...@@ -2166,7 +2166,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -2166,7 +2166,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
2166 if (ret_ty.isError(mod)) {2166 if (ret_ty.isError(mod)) {
2167 try func.addImm32(0);2167 try func.addImm32(0);
2168 }2168 }
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)) {
2170 // leave on the stack2170 // leave on the stack
2171 _ = try func.load(operand, ret_ty, 0);2171 _ = try func.load(operand, ret_ty, 0);
2172 }2172 }
...@@ -2192,7 +2192,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -2192,7 +2192,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
2192 };2192 };
2193 const ret_ty = fn_ty.fnReturnType(mod);2193 const ret_ty = fn_ty.fnReturnType(mod);
2194 const fn_info = mod.typeToFunc(fn_ty).?;2194 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
2197 const callee: ?Decl.Index = blk: {2197 const callee: ?Decl.Index = blk: {
2198 const func_val = (try func.air.value(pl_op.operand, mod)) orelse break :blk null;2198 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...@@ -2203,7 +2203,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
2203 } else if (func_val.getExternFunc(mod)) |extern_func| {2203 } else if (func_val.getExternFunc(mod)) |extern_func| {
2204 const ext_decl = mod.declPtr(extern_func.decl);2204 const ext_decl = mod.declPtr(extern_func.decl);
2205 const ext_info = mod.typeToFunc(ext_decl.ty).?;2205 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);
2207 defer func_type.deinit(func.gpa);2207 defer func_type.deinit(func.gpa);
2208 const atom_index = try func.bin_file.getOrCreateAtomForDecl(extern_func.decl);2208 const atom_index = try func.bin_file.getOrCreateAtomForDecl(extern_func.decl);
2209 const atom = func.bin_file.getAtomPtr(atom_index);2209 const atom = func.bin_file.getAtomPtr(atom_index);
...@@ -2253,7 +2253,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif...@@ -2253,7 +2253,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
2253 const operand = try func.resolveInst(pl_op.operand);2253 const operand = try func.resolveInst(pl_op.operand);
2254 try func.emitWValue(operand);2254 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);
2257 defer fn_type.deinit(func.gpa);2257 defer fn_type.deinit(func.gpa);
22582258
2259 const fn_type_index = try func.bin_file.putOrGetFuncType(fn_type);2259 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...@@ -3081,24 +3081,24 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
3081 return func.lowerParentPtrDecl(ptr_val, decl_index, offset);3081 return func.lowerParentPtrDecl(ptr_val, decl_index, offset);
3082 },3082 },
3083 .eu_payload => |tag| return func.fail("TODO: Implement lowerParentPtr for {}", .{tag}),3083 .eu_payload => |tag| return func.fail("TODO: Implement lowerParentPtr for {}", .{tag}),
3084 .int => |base| return func.lowerConstant(base.toValue(), Type.usize),3084 .int => |base| return func.lowerConstant(Value.fromInterned(base), Type.usize),
3085 .opt_payload => |base_ptr| return func.lowerParentPtr(base_ptr.toValue(), offset),3085 .opt_payload => |base_ptr| return func.lowerParentPtr(Value.fromInterned(base_ptr), offset),
3086 .comptime_field => unreachable,3086 .comptime_field => unreachable,
3087 .elem => |elem| {3087 .elem => |elem| {
3088 const index = elem.index;3088 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);
3090 const elem_offset = index * elem_type.abiSize(mod);3090 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)));
3092 },3092 },
3093 .field => |field| {3093 .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));
3095 const parent_ty = parent_ptr_ty.childType(mod);3095 const parent_ty = parent_ptr_ty.childType(mod);
3096 const field_index: u32 = @intCast(field.index);3096 const field_index: u32 = @intCast(field.index);
30973097
3098 const field_offset = switch (parent_ty.zigTypeTag(mod)) {3098 const field_offset = switch (parent_ty.zigTypeTag(mod)) {
3099 .Struct => blk: {3099 .Struct => blk: {
3100 if (mod.typeToPackedStruct(parent_ty)) |struct_type| {3100 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)
3102 break :blk @divExact(mod.structPackedFieldBitOffset(struct_type, field_index) + parent_ptr_ty.ptrInfo(mod).packed_offset.bit_offset, 8)3102 break :blk @divExact(mod.structPackedFieldBitOffset(struct_type, field_index) + parent_ptr_ty.ptrInfo(mod).packed_offset.bit_offset, 8)
3103 else3103 else
3104 break :blk 0;3104 break :blk 0;
...@@ -3126,7 +3126,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue...@@ -3126,7 +3126,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
3126 },3126 },
3127 else => unreachable,3127 else => unreachable,
3128 };3128 };
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)));
3130 },3130 },
3131 }3131 }
3132}3132}
...@@ -3146,7 +3146,7 @@ fn lowerAnonDeclRef(...@@ -3146,7 +3146,7 @@ fn lowerAnonDeclRef(
3146) InnerError!WValue {3146) InnerError!WValue {
3147 const mod = func.bin_file.base.options.module.?;3147 const mod = func.bin_file.base.options.module.?;
3148 const decl_val = anon_decl.val;3148 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
3151 const is_fn_body = ty.zigTypeTag(mod) == .Fn;3151 const is_fn_body = ty.zigTypeTag(mod) == .Fn;
3152 if (!is_fn_body and !ty.hasRuntimeBitsIgnoreComptime(mod)) {3152 if (!is_fn_body and !ty.hasRuntimeBitsIgnoreComptime(mod)) {
...@@ -3301,10 +3301,10 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {...@@ -3301,10 +3301,10 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3301 const err_tv: TypedValue = switch (error_union.val) {3301 const err_tv: TypedValue = switch (error_union.val) {
3302 .err_name => |err_name| .{3302 .err_name => |err_name| .{
3303 .ty = ty.errorUnionSet(mod),3303 .ty = ty.errorUnionSet(mod),
3304 .val = (try mod.intern(.{ .err = .{3304 .val = Value.fromInterned((try mod.intern(.{ .err = .{
3305 .ty = ty.errorUnionSet(mod).toIntern(),3305 .ty = ty.errorUnionSet(mod).toIntern(),
3306 .name = err_name,3306 .name = err_name,
3307 } })).toValue(),3307 } }))),
3308 },3308 },
3309 .payload => .{3309 .payload => .{
3310 .ty = err_int_ty,3310 .ty = err_int_ty,
...@@ -3321,7 +3321,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {...@@ -3321,7 +3321,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3321 },3321 },
3322 .enum_tag => |enum_tag| {3322 .enum_tag => |enum_tag| {
3323 const int_tag_ty = ip.typeOf(enum_tag.int);3323 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));
3325 },3325 },
3326 .float => |float| switch (float.storage) {3326 .float => |float| switch (float.storage) {
3327 .f16 => |f16_val| return WValue{ .imm32 = @as(u16, @bitCast(f16_val)) },3327 .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 {...@@ -3332,7 +3332,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3332 .ptr => |ptr| switch (ptr.addr) {3332 .ptr => |ptr| switch (ptr.addr) {
3333 .decl => |decl| return func.lowerDeclRefValue(.{ .ty = ty, .val = val }, decl, 0),3333 .decl => |decl| return func.lowerDeclRefValue(.{ .ty = ty, .val = val }, decl, 0),
3334 .mut_decl => |mut_decl| return func.lowerDeclRefValue(.{ .ty = ty, .val = val }, mut_decl.decl, 0),3334 .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))),
3336 .opt_payload, .elem, .field => return func.lowerParentPtr(val, 0),3336 .opt_payload, .elem, .field => return func.lowerParentPtr(val, 0),
3337 .anon_decl => |ad| return func.lowerAnonDeclRef(ad, 0),3337 .anon_decl => |ad| return func.lowerAnonDeclRef(ad, 0),
3338 else => return func.fail("Wasm TODO: lowerConstant for other const addr tag {}", .{ptr.addr}),3338 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 {...@@ -3361,7 +3361,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3361 assert(struct_type.layout == .Packed);3361 assert(struct_type.layout == .Packed);
3362 var buf: [8]u8 = .{0} ** 8; // zero the buffer so we do not read 0xaa as integer3362 var buf: [8]u8 = .{0} ** 8; // zero the buffer so we do not read 0xaa as integer
3363 val.writeToPackedMemory(ty, mod, &buf, 0) catch unreachable;3363 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).*);
3365 const int_val = try mod.intValue(3365 const int_val = try mod.intValue(
3366 backing_int_ty,3366 backing_int_ty,
3367 mem.readInt(u64, &buf, .little),3367 mem.readInt(u64, &buf, .little),
...@@ -3376,10 +3376,10 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {...@@ -3376,10 +3376,10 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3376 try ty.unionBackingType(mod)3376 try ty.unionBackingType(mod)
3377 else field_ty: {3377 else field_ty: {
3378 const union_obj = mod.typeToUnion(ty).?;3378 const union_obj = mod.typeToUnion(ty).?;
3379 const field_index = mod.unionTagFieldIndex(union_obj, un.tag.toValue()).?;3379 const field_index = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
3380 break :field_ty union_obj.field_types.get(ip)[field_index].toType();3380 break :field_ty Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3381 };3381 };
3382 return func.lowerConstant(un.val.toValue(), constant_ty);3382 return func.lowerConstant(Value.fromInterned(un.val), constant_ty);
3383 },3383 },
3384 .memoized_call => unreachable,3384 .memoized_call => unreachable,
3385 }3385 }
...@@ -3426,7 +3426,7 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {...@@ -3426,7 +3426,7 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
3426 },3426 },
3427 .Struct => {3427 .Struct => {
3428 const packed_struct = mod.typeToPackedStruct(ty).?;3428 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).*));
3430 },3430 },
3431 else => return func.fail("Wasm TODO: emitUndefined for type: {}\n", .{ty.zigTypeTag(mod)}),3431 else => return func.fail("Wasm TODO: emitUndefined for type: {}\n", .{ty.zigTypeTag(mod)}),
3432 }3432 }
...@@ -3466,8 +3466,8 @@ fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 {...@@ -3466,8 +3466,8 @@ fn intStorageAsI32(storage: InternPool.Key.Int.Storage, mod: *Module) i32 {
3466 .i64 => |x| @as(i32, @intCast(x)),3466 .i64 => |x| @as(i32, @intCast(x)),
3467 .u64 => |x| @as(i32, @bitCast(@as(u32, @intCast(x)))),3467 .u64 => |x| @as(i32, @bitCast(@as(u32, @intCast(x)))),
3468 .big_int => unreachable,3468 .big_int => unreachable,
3469 .lazy_align => |ty| @as(i32, @bitCast(@as(u32, @intCast(ty.toType().abiAlignment(mod).toByteUnits(0))))),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(ty.toType().abiSize(mod))))),3470 .lazy_size => |ty| @as(i32, @bitCast(@as(u32, @intCast(Type.fromInterned(ty).abiSize(mod))))),
3471 };3471 };
3472}3472}
34733473
...@@ -3930,7 +3930,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3930,7 +3930,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3930 .Struct => result: {3930 .Struct => result: {
3931 const packed_struct = mod.typeToPackedStruct(struct_ty).?;3931 const packed_struct = mod.typeToPackedStruct(struct_ty).?;
3932 const offset = mod.structPackedFieldBitOffset(packed_struct, field_index);3932 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).*);
3934 const wasm_bits = toWasmBits(backing_ty.intInfo(mod).bits) orelse {3934 const wasm_bits = toWasmBits(backing_ty.intInfo(mod).bits) orelse {
3935 return func.fail("TODO: airStructFieldVal for packed structs larger than 128 bits", .{});3935 return func.fail("TODO: airStructFieldVal for packed structs larger than 128 bits", .{});
3936 };3936 };
...@@ -5208,7 +5208,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5208,7 +5208,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52085208
5209 const a = try func.resolveInst(extra.a);5209 const a = try func.resolveInst(extra.a);
5210 const b = try func.resolveInst(extra.b);5210 const b = try func.resolveInst(extra.b);
5211 const mask = extra.mask.toValue();5211 const mask = Value.fromInterned(extra.mask);
5212 const mask_len = extra.mask_len;5212 const mask_len = extra.mask_len;
52135213
5214 const child_ty = inst_ty.childType(mod);5214 const child_ty = inst_ty.childType(mod);
...@@ -5325,7 +5325,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5325,7 +5325,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5325 }5325 }
5326 const packed_struct = mod.typeToPackedStruct(result_ty).?;5326 const packed_struct = mod.typeToPackedStruct(result_ty).?;
5327 const field_types = packed_struct.field_types;5327 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
5330 // ensure the result is zero'd5330 // ensure the result is zero'd
5331 const result = try func.allocLocal(backing_type);5331 const result = try func.allocLocal(backing_type);
...@@ -5337,7 +5337,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5337,7 +5337,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53375337
5338 var current_bit: u16 = 0;5338 var current_bit: u16 = 0;
5339 for (elements, 0..) |elem, elem_index| {5339 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]);
5341 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;5341 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
53425342
5343 const shift_val = if (backing_type.bitSize(mod) <= 32)5343 const shift_val = if (backing_type.bitSize(mod) <= 32)
...@@ -5409,7 +5409,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5409,7 +5409,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5409 const union_ty = func.typeOfIndex(inst);5409 const union_ty = func.typeOfIndex(inst);
5410 const layout = union_ty.unionGetLayout(mod);5410 const layout = union_ty.unionGetLayout(mod);
5411 const union_obj = mod.typeToUnion(union_ty).?;5411 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]);
5413 const field_name = union_obj.field_names.get(ip)[extra.field_index];5413 const field_name = union_obj.field_names.get(ip)[extra.field_index];
54145414
5415 const tag_int = blk: {5415 const tag_int = blk: {
...@@ -5438,7 +5438,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5438,7 +5438,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5438 }5438 }
54395439
5440 if (layout.tag_size > 0) {5440 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);
5442 }5442 }
5443 } else {5443 } else {
5444 try func.store(result_ptr, payload, field_ty, 0);5444 try func.store(result_ptr, payload, field_ty, 0);
...@@ -5446,7 +5446,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5446,7 +5446,7 @@ fn airUnionInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5446 try func.store(5446 try func.store(
5447 result_ptr,5447 result_ptr,
5448 tag_int,5448 tag_int,
5449 union_obj.enum_tag_ty.toType(),5449 Type.fromInterned(union_obj.enum_tag_ty),
5450 @intCast(layout.payload_size),5450 @intCast(layout.payload_size),
5451 );5451 );
5452 }5452 }
...@@ -7173,8 +7173,8 @@ fn callIntrinsic(...@@ -7173,8 +7173,8 @@ fn callIntrinsic(
7173 // Lower all arguments to the stack before we call our function7173 // Lower all arguments to the stack before we call our function
7174 for (args, 0..) |arg, arg_i| {7174 for (args, 0..) |arg, arg_i| {
7175 assert(!(want_sret_param and arg == .stack));7175 assert(!(want_sret_param and arg == .stack));
7176 assert(param_types[arg_i].toType().hasRuntimeBitsIgnoreComptime(mod));7176 assert(Type.fromInterned(param_types[arg_i]).hasRuntimeBitsIgnoreComptime(mod));
7177 try func.lowerArg(.C, param_types[arg_i].toType(), arg);7177 try func.lowerArg(.C, Type.fromInterned(param_types[arg_i]), arg);
7178 }7178 }
71797179
7180 // Actually call our intrinsic7180 // Actually call our intrinsic
...@@ -7260,7 +7260,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {...@@ -7260,7 +7260,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
7260 .storage = .{ .bytes = tag_name },7260 .storage = .{ .bytes = tag_name },
7261 } });7261 } });
7262 const tag_sym_index = try func.bin_file.lowerUnnamedConst(7262 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) },
7264 enum_decl_index,7264 enum_decl_index,
7265 );7265 );
72667266
src/arch/wasm/abi.zig+4-4
...@@ -37,7 +37,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class {...@@ -37,7 +37,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class {
37 // The struct type is non-scalar.37 // The struct type is non-scalar.
38 return memory;38 return memory;
39 }39 }
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]);
41 const explicit_align = struct_type.fieldAlign(ip, 0);41 const explicit_align = struct_type.fieldAlign(ip, 0);
42 if (explicit_align != .none) {42 if (explicit_align != .none) {
43 if (explicit_align.compareStrict(.gt, field_ty.abiAlignment(mod)))43 if (explicit_align.compareStrict(.gt, field_ty.abiAlignment(mod)))
...@@ -76,7 +76,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class {...@@ -76,7 +76,7 @@ pub fn classifyType(ty: Type, mod: *Module) [2]Class {
76 const layout = ty.unionGetLayout(mod);76 const layout = ty.unionGetLayout(mod);
77 assert(layout.tag_size == 0);77 assert(layout.tag_size == 0);
78 if (union_obj.field_names.len > 1) return memory;78 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]);
80 return classifyType(first_field_ty, mod);80 return classifyType(first_field_ty, mod);
81 },81 },
82 .ErrorUnion,82 .ErrorUnion,
...@@ -104,7 +104,7 @@ pub fn scalarType(ty: Type, mod: *Module) Type {...@@ -104,7 +104,7 @@ pub fn scalarType(ty: Type, mod: *Module) Type {
104 switch (ty.zigTypeTag(mod)) {104 switch (ty.zigTypeTag(mod)) {
105 .Struct => {105 .Struct => {
106 if (mod.typeToPackedStruct(ty)) |packed_struct| {106 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);
108 } else {108 } else {
109 assert(ty.structFieldCount(mod) == 1);109 assert(ty.structFieldCount(mod) == 1);
110 return scalarType(ty.structFieldType(0, mod), mod);110 return scalarType(ty.structFieldType(0, mod), mod);
...@@ -119,7 +119,7 @@ pub fn scalarType(ty: Type, mod: *Module) Type {...@@ -119,7 +119,7 @@ pub fn scalarType(ty: Type, mod: *Module) Type {
119 }119 }
120 assert(union_obj.field_types.len == 1);120 assert(union_obj.field_types.len == 1);
121 }121 }
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]);
123 return scalarType(first_field_ty, mod);123 return scalarType(first_field_ty, mod);
124 },124 },
125 else => return ty,125 else => return ty,
src/arch/x86_64/CodeGen.zig+11-11
...@@ -3044,7 +3044,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {...@@ -3044,7 +3044,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
3044 .storage = .{ .repeated_elem = mask_val.ip_index },3044 .storage = .{ .repeated_elem = mask_val.ip_index },
3045 } });3045 } });
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) });
3048 const splat_addr_mcv: MCValue = switch (splat_mcv) {3048 const splat_addr_mcv: MCValue = switch (splat_mcv) {
3049 .memory, .indirect, .load_frame => splat_mcv.address(),3049 .memory, .indirect, .load_frame => splat_mcv.address(),
3050 else => .{ .register = try self.copyToTmpRegister(Type.usize, splat_mcv.address()) },3050 else => .{ .register = try self.copyToTmpRegister(Type.usize, splat_mcv.address()) },
...@@ -3196,7 +3196,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {...@@ -3196,7 +3196,7 @@ fn activeIntBits(self: *Self, dst_air: Air.Inst.Ref) u16 {
3196 }3196 }
3197 } else if (Air.refToInterned(dst_air)) |ip_index| {3197 } else if (Air.refToInterned(dst_air)) |ip_index| {
3198 var space: Value.BigIntSpace = undefined;3198 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);
3200 return @as(u16, @intCast(src_int.bitCountTwosComp())) +3200 return @as(u16, @intCast(src_int.bitCountTwosComp())) +
3201 @intFromBool(src_int.positive and dst_info.signedness == .signed);3201 @intFromBool(src_int.positive and dst_info.signedness == .signed);
3202 }3202 }
...@@ -4429,7 +4429,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -4429,7 +4429,7 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
4429 self.register_manager.unlockReg(lock);4429 self.register_manager.unlockReg(lock);
44304430
4431 const shift_imm =4431 const shift_imm =
4432 Immediate.u(@intCast(rhs_elem.toValue().toUnsignedInt(mod)));4432 Immediate.u(@intCast(Value.fromInterned(rhs_elem).toUnsignedInt(mod)));
4433 if (self.hasFeature(.avx)) try self.asmRegisterRegisterImmediate(4433 if (self.hasFeature(.avx)) try self.asmRegisterRegisterImmediate(
4434 mir_tag,4434 mir_tag,
4435 registerAlias(dst_reg, abi_size),4435 registerAlias(dst_reg, abi_size),
...@@ -4477,14 +4477,14 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {...@@ -4477,14 +4477,14 @@ fn airShlShrBinOp(self: *Self, inst: Air.Inst.Index) !void {
4477 const mask_ty = try mod.vectorType(.{ .len = 16, .child = .u8_type });4477 const mask_ty = try mod.vectorType(.{ .len = 16, .child = .u8_type });
4478 const mask_mcv = try self.genTypedValue(.{4478 const mask_mcv = try self.genTypedValue(.{
4479 .ty = mask_ty,4479 .ty = mask_ty,
4480 .val = (try mod.intern(.{ .aggregate = .{4480 .val = Value.fromInterned((try mod.intern(.{ .aggregate = .{
4481 .ty = mask_ty.toIntern(),4481 .ty = mask_ty.toIntern(),
4482 .storage = .{ .elems = &([1]InternPool.Index{4482 .storage = .{ .elems = &([1]InternPool.Index{
4483 (try rhs_ty.childType(mod).maxIntScalar(mod, Type.u8)).toIntern(),4483 (try rhs_ty.childType(mod).maxIntScalar(mod, Type.u8)).toIntern(),
4484 } ++ [1]InternPool.Index{4484 } ++ [1]InternPool.Index{
4485 (try mod.intValue(Type.u8, 0)).toIntern(),4485 (try mod.intValue(Type.u8, 0)).toIntern(),
4486 } ** 15) },4486 } ** 15) },
4487 } })).toValue(),4487 } }))),
4488 });4488 });
4489 const mask_addr_reg =4489 const mask_addr_reg =
4490 try self.copyToTmpRegister(Type.usize, mask_mcv.address());4490 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...@@ -6714,7 +6714,7 @@ fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) Inn
6714 const mod = self.bin_file.options.module.?;6714 const mod = self.bin_file.options.module.?;
6715 const ptr_info = ptr_ty.ptrInfo(mod);6715 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);
6718 if (!val_ty.hasRuntimeBitsIgnoreComptime(mod)) return;6718 if (!val_ty.hasRuntimeBitsIgnoreComptime(mod)) return;
6719 const val_abi_size: u32 = @intCast(val_ty.abiSize(mod));6719 const val_abi_size: u32 = @intCast(val_ty.abiSize(mod));
67206720
...@@ -10759,7 +10759,7 @@ fn genCall(self: *Self, info: union(enum) {...@@ -10759,7 +10759,7 @@ fn genCall(self: *Self, info: union(enum) {
10759 switch (call_info.return_value.long) {10759 switch (call_info.return_value.long) {
10760 .none, .unreach => {},10760 .none, .unreach => {},
10761 .indirect => |reg_off| {10761 .indirect => |reg_off| {
10762 const ret_ty = fn_info.return_type.toType();10762 const ret_ty = Type.fromInterned(fn_info.return_type);
10763 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ret_ty, mod));10763 const frame_index = try self.allocFrameIndex(FrameAlloc.initSpill(ret_ty, mod));
10764 try self.genSetReg(reg_off.reg, Type.usize, .{10764 try self.genSetReg(reg_off.reg, Type.usize, .{
10765 .lea_frame = .{ .index = frame_index, .off = -reg_off.off },10765 .lea_frame = .{ .index = frame_index, .off = -reg_off.off },
...@@ -15343,7 +15343,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {...@@ -15343,7 +15343,7 @@ fn airUnionInit(self: *Self, inst: Air.Inst.Index) !void {
1534315343
15344 const union_obj = mod.typeToUnion(union_ty).?;15344 const union_obj = mod.typeToUnion(union_ty).?;
15345 const field_name = union_obj.field_names.get(ip)[extra.field_index];15345 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);
15347 const field_index = tag_ty.enumFieldIndex(field_name, mod).?;15347 const field_index = tag_ty.enumFieldIndex(field_name, mod).?;
15348 const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index);15348 const tag_val = try mod.enumValueFieldIndex(tag_ty, field_index);
15349 const tag_int_val = try tag_val.intFromEnum(tag_ty, mod);15349 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 {...@@ -15812,7 +15812,7 @@ fn resolveInst(self: *Self, ref: Air.Inst.Ref) InnerError!MCValue {
15812 const ip_index = Air.refToInterned(ref).?;15812 const ip_index = Air.refToInterned(ref).?;
15813 const gop = try self.const_tracking.getOrPut(self.gpa, ip_index);15813 const gop = try self.const_tracking.getOrPut(self.gpa, ip_index);
15814 if (!gop.found_existing) gop.value_ptr.* = InstTracking.init(init: {15814 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) });
15816 switch (const_mcv) {15816 switch (const_mcv) {
15817 .lea_tlv => |tlv_sym| if (self.bin_file.cast(link.File.Elf)) |_| {15817 .lea_tlv => |tlv_sym| if (self.bin_file.cast(link.File.Elf)) |_| {
15818 if (self.bin_file.options.pic) {15818 if (self.bin_file.options.pic) {
...@@ -15921,7 +15921,7 @@ fn resolveCallingConventionValues(...@@ -15921,7 +15921,7 @@ fn resolveCallingConventionValues(
15921 defer self.gpa.free(param_types);15921 defer self.gpa.free(param_types);
1592215922
15923 for (param_types[0..fn_info.param_types.len], fn_info.param_types.get(ip)) |*dest, src| {15923 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);
15925 }15925 }
15926 for (param_types[fn_info.param_types.len..], var_args) |*param_ty, arg_ty|15926 for (param_types[fn_info.param_types.len..], var_args) |*param_ty, arg_ty|
15927 param_ty.* = self.promoteVarArg(arg_ty);15927 param_ty.* = self.promoteVarArg(arg_ty);
...@@ -15937,7 +15937,7 @@ fn resolveCallingConventionValues(...@@ -15937,7 +15937,7 @@ fn resolveCallingConventionValues(
15937 };15937 };
15938 errdefer self.gpa.free(result.args);15938 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
15942 const resolved_cc = abi.resolveCallingConvention(cc, self.target.*);15942 const resolved_cc = abi.resolveCallingConvention(cc, self.target.*);
15943 switch (cc) {15943 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 {...@@ -224,7 +224,7 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
224 var result_i: usize = 0; // out of 8224 var result_i: usize = 0; // out of 8
225 var byte_i: usize = 0; // out of 8225 var byte_i: usize = 0; // out of 8
226 for (struct_type.field_types.get(ip), 0..) |field_ty_ip, i| {226 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);
228 const field_align = struct_type.fieldAlign(ip, i);228 const field_align = struct_type.fieldAlign(ip, i);
229 if (field_align != .none and field_align.compare(.lt, field_ty.abiAlignment(mod)))229 if (field_align != .none and field_align.compare(.lt, field_ty.abiAlignment(mod)))
230 return memory_class;230 return memory_class;
...@@ -342,12 +342,12 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {...@@ -342,12 +342,12 @@ pub fn classifySystemV(ty: Type, mod: *Module, ctx: Context) [8]Class {
342 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {342 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
343 const field_align = union_obj.fieldAlign(ip, @intCast(field_index));343 const field_align = union_obj.fieldAlign(ip, @intCast(field_index));
344 if (field_align != .none and344 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)))
346 {346 {
347 return memory_class;347 return memory_class;
348 }348 }
349 // Combine this field with the previous one.349 // 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);
351 for (&result, 0..) |*result_item, i| {351 for (&result, 0..) |*result_item, i| {
352 const field_item = field_class[i];352 const field_item = field_class[i];
353 // "If both classes are equal, this is the resulting class."353 // "If both classes are equal, this is the resulting class."
src/codegen.zig+44-44
...@@ -259,10 +259,10 @@ pub fn generateSymbol(...@@ -259,10 +259,10 @@ pub fn generateSymbol(
259 const begin = code.items.len;259 const begin = code.items.len;
260 switch (try generateSymbol(bin_file, src_loc, .{260 switch (try generateSymbol(bin_file, src_loc, .{
261 .ty = payload_ty,261 .ty = payload_ty,
262 .val = switch (error_union.val) {262 .val = Value.fromInterned(switch (error_union.val) {
263 .err_name => try mod.intern(.{ .undef = payload_ty.toIntern() }),263 .err_name => try mod.intern(.{ .undef = payload_ty.toIntern() }),
264 .payload => |payload| payload,264 .payload => |payload| payload,
265 }.toValue(),265 }),
266 }, code, debug_output, reloc_info)) {266 }, code, debug_output, reloc_info)) {
267 .ok => {},267 .ok => {},
268 .fail => |em| return .{ .fail = em },268 .fail => |em| return .{ .fail = em },
...@@ -293,7 +293,7 @@ pub fn generateSymbol(...@@ -293,7 +293,7 @@ pub fn generateSymbol(
293 const int_tag_ty = typed_value.ty.intTagType(mod);293 const int_tag_ty = typed_value.ty.intTagType(mod);
294 switch (try generateSymbol(bin_file, src_loc, .{294 switch (try generateSymbol(bin_file, src_loc, .{
295 .ty = int_tag_ty,295 .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),
297 }, code, debug_output, reloc_info)) {297 }, code, debug_output, reloc_info)) {
298 .ok => {},298 .ok => {},
299 .fail => |em| return .{ .fail = em },299 .fail => |em| return .{ .fail = em },
...@@ -323,7 +323,7 @@ pub fn generateSymbol(...@@ -323,7 +323,7 @@ pub fn generateSymbol(
323 // generate len323 // generate len
324 switch (try generateSymbol(bin_file, src_loc, .{324 switch (try generateSymbol(bin_file, src_loc, .{
325 .ty = Type.usize,325 .ty = Type.usize,
326 .val = ptr.len.toValue(),326 .val = Value.fromInterned(ptr.len),
327 }, code, debug_output, reloc_info)) {327 }, code, debug_output, reloc_info)) {
328 .ok => {},328 .ok => {},
329 .fail => |em| return Result{ .fail = em },329 .fail => |em| return Result{ .fail = em },
...@@ -350,7 +350,7 @@ pub fn generateSymbol(...@@ -350,7 +350,7 @@ pub fn generateSymbol(
350 } else {350 } else {
351 const padding = abi_size - (math.cast(usize, payload_type.abiSize(mod)) orelse return error.Overflow) - 1;351 const padding = abi_size - (math.cast(usize, payload_type.abiSize(mod)) orelse return error.Overflow) - 1;
352 if (payload_type.hasRuntimeBits(mod)) {352 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() })));
354 switch (try generateSymbol(bin_file, src_loc, .{354 switch (try generateSymbol(bin_file, src_loc, .{
355 .ty = payload_type,355 .ty = payload_type,
356 .val = value,356 .val = value,
...@@ -372,15 +372,15 @@ pub fn generateSymbol(...@@ -372,15 +372,15 @@ pub fn generateSymbol(
372 array_type.len + @intFromBool(array_type.sentinel != .none);372 array_type.len + @intFromBool(array_type.sentinel != .none);
373 while (index < len_including_sentinel) : (index += 1) {373 while (index < len_including_sentinel) : (index += 1) {
374 switch (try generateSymbol(bin_file, src_loc, .{374 switch (try generateSymbol(bin_file, src_loc, .{
375 .ty = array_type.child.toType(),375 .ty = Type.fromInterned(array_type.child),
376 .val = switch (aggregate.storage) {376 .val = Value.fromInterned(switch (aggregate.storage) {
377 .bytes => unreachable,377 .bytes => unreachable,
378 .elems => |elems| elems[@as(usize, @intCast(index))],378 .elems => |elems| elems[@as(usize, @intCast(index))],
379 .repeated_elem => |elem| if (index < array_type.len)379 .repeated_elem => |elem| if (index < array_type.len)
380 elem380 elem
381 else381 else
382 array_type.sentinel,382 array_type.sentinel,
383 }.toValue(),383 }),
384 }, code, debug_output, reloc_info)) {384 }, code, debug_output, reloc_info)) {
385 .ok => {},385 .ok => {},
386 .fail => |em| return .{ .fail = em },386 .fail => |em| return .{ .fail = em },
...@@ -395,12 +395,12 @@ pub fn generateSymbol(...@@ -395,12 +395,12 @@ pub fn generateSymbol(
395 var index: u64 = 0;395 var index: u64 = 0;
396 while (index < vector_type.len) : (index += 1) {396 while (index < vector_type.len) : (index += 1) {
397 switch (try generateSymbol(bin_file, src_loc, .{397 switch (try generateSymbol(bin_file, src_loc, .{
398 .ty = vector_type.child.toType(),398 .ty = Type.fromInterned(vector_type.child),
399 .val = switch (aggregate.storage) {399 .val = Value.fromInterned(switch (aggregate.storage) {
400 .bytes => unreachable,400 .bytes => unreachable,
401 .elems => |elems| elems[@as(usize, @intCast(index))],401 .elems => |elems| elems[@as(usize, @intCast(index))],
402 .repeated_elem => |elem| elem,402 .repeated_elem => |elem| elem,
403 }.toValue(),403 }),
404 }, code, debug_output, reloc_info)) {404 }, code, debug_output, reloc_info)) {
405 .ok => {},405 .ok => {},
406 .fail => |em| return .{ .fail = em },406 .fail => |em| return .{ .fail = em },
...@@ -410,7 +410,7 @@ pub fn generateSymbol(...@@ -410,7 +410,7 @@ pub fn generateSymbol(
410 }410 }
411411
412 const padding = math.cast(usize, typed_value.ty.abiSize(mod) -412 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) {
414 error.DivisionByZero => unreachable,414 error.DivisionByZero => unreachable,
415 else => |e| return e,415 else => |e| return e,
416 })) orelse return error.Overflow;416 })) orelse return error.Overflow;
...@@ -424,7 +424,7 @@ pub fn generateSymbol(...@@ -424,7 +424,7 @@ pub fn generateSymbol(
424 0..,424 0..,
425 ) |field_ty, comptime_val, index| {425 ) |field_ty, comptime_val, index| {
426 if (comptime_val != .none) continue;426 if (comptime_val != .none) continue;
427 if (!field_ty.toType().hasRuntimeBits(mod)) continue;427 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
428428
429 const field_val = switch (aggregate.storage) {429 const field_val = switch (aggregate.storage) {
430 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{430 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{
...@@ -436,8 +436,8 @@ pub fn generateSymbol(...@@ -436,8 +436,8 @@ pub fn generateSymbol(
436 };436 };
437437
438 switch (try generateSymbol(bin_file, src_loc, .{438 switch (try generateSymbol(bin_file, src_loc, .{
439 .ty = field_ty.toType(),439 .ty = Type.fromInterned(field_ty),
440 .val = field_val.toValue(),440 .val = Value.fromInterned(field_val),
441 }, code, debug_output, reloc_info)) {441 }, code, debug_output, reloc_info)) {
442 .ok => {},442 .ok => {},
443 .fail => |em| return Result{ .fail = em },443 .fail => |em| return Result{ .fail = em },
...@@ -474,22 +474,22 @@ pub fn generateSymbol(...@@ -474,22 +474,22 @@ pub fn generateSymbol(
474474
475 // pointer may point to a decl which must be marked used475 // pointer may point to a decl which must be marked used
476 // but can also result in a relocation. Therefore we handle those separately.476 // but can also result in a relocation. Therefore we handle those separately.
477 if (field_ty.toType().zigTypeTag(mod) == .Pointer) {477 if (Type.fromInterned(field_ty).zigTypeTag(mod) == .Pointer) {
478 const field_size = math.cast(usize, field_ty.toType().abiSize(mod)) orelse478 const field_size = math.cast(usize, Type.fromInterned(field_ty).abiSize(mod)) orelse
479 return error.Overflow;479 return error.Overflow;
480 var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size);480 var tmp_list = try std.ArrayList(u8).initCapacity(code.allocator, field_size);
481 defer tmp_list.deinit();481 defer tmp_list.deinit();
482 switch (try generateSymbol(bin_file, src_loc, .{482 switch (try generateSymbol(bin_file, src_loc, .{
483 .ty = field_ty.toType(),483 .ty = Type.fromInterned(field_ty),
484 .val = field_val.toValue(),484 .val = Value.fromInterned(field_val),
485 }, &tmp_list, debug_output, reloc_info)) {485 }, &tmp_list, debug_output, reloc_info)) {
486 .ok => @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items),486 .ok => @memcpy(code.items[current_pos..][0..tmp_list.items.len], tmp_list.items),
487 .fail => |em| return Result{ .fail = em },487 .fail => |em| return Result{ .fail = em },
488 }488 }
489 } else {489 } 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;
491 }491 }
492 bits += @as(u16, @intCast(field_ty.toType().bitSize(mod)));492 bits += @as(u16, @intCast(Type.fromInterned(field_ty).bitSize(mod)));
493 }493 }
494 },494 },
495 .Auto, .Extern => {495 .Auto, .Extern => {
...@@ -500,7 +500,7 @@ pub fn generateSymbol(...@@ -500,7 +500,7 @@ pub fn generateSymbol(
500 var it = struct_type.iterateRuntimeOrder(ip);500 var it = struct_type.iterateRuntimeOrder(ip);
501 while (it.next()) |field_index| {501 while (it.next()) |field_index| {
502 const field_ty = field_types[field_index];502 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
505 const field_val = switch (ip.indexToKey(typed_value.val.toIntern()).aggregate.storage) {505 const field_val = switch (ip.indexToKey(typed_value.val.toIntern()).aggregate.storage) {
506 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{506 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{
...@@ -518,8 +518,8 @@ pub fn generateSymbol(...@@ -518,8 +518,8 @@ pub fn generateSymbol(
518 if (padding > 0) try code.appendNTimes(0, padding);518 if (padding > 0) try code.appendNTimes(0, padding);
519519
520 switch (try generateSymbol(bin_file, src_loc, .{520 switch (try generateSymbol(bin_file, src_loc, .{
521 .ty = field_ty.toType(),521 .ty = Type.fromInterned(field_ty),
522 .val = field_val.toValue(),522 .val = Value.fromInterned(field_val),
523 }, code, debug_output, reloc_info)) {523 }, code, debug_output, reloc_info)) {
524 .ok => {},524 .ok => {},
525 .fail => |em| return Result{ .fail = em },525 .fail => |em| return Result{ .fail = em },
...@@ -545,7 +545,7 @@ pub fn generateSymbol(...@@ -545,7 +545,7 @@ pub fn generateSymbol(
545 if (layout.payload_size == 0) {545 if (layout.payload_size == 0) {
546 return generateSymbol(bin_file, src_loc, .{546 return generateSymbol(bin_file, src_loc, .{
547 .ty = typed_value.ty.unionTagTypeSafety(mod).?,547 .ty = typed_value.ty.unionTagTypeSafety(mod).?,
548 .val = un.tag.toValue(),548 .val = Value.fromInterned(un.tag),
549 }, code, debug_output, reloc_info);549 }, code, debug_output, reloc_info);
550 }550 }
551551
...@@ -553,7 +553,7 @@ pub fn generateSymbol(...@@ -553,7 +553,7 @@ pub fn generateSymbol(
553 if (layout.tag_size > 0 and layout.tag_align.compare(.gte, layout.payload_align)) {553 if (layout.tag_size > 0 and layout.tag_align.compare(.gte, layout.payload_align)) {
554 switch (try generateSymbol(bin_file, src_loc, .{554 switch (try generateSymbol(bin_file, src_loc, .{
555 .ty = typed_value.ty.unionTagTypeSafety(mod).?,555 .ty = typed_value.ty.unionTagTypeSafety(mod).?,
556 .val = un.tag.toValue(),556 .val = Value.fromInterned(un.tag),
557 }, code, debug_output, reloc_info)) {557 }, code, debug_output, reloc_info)) {
558 .ok => {},558 .ok => {},
559 .fail => |em| return Result{ .fail = em },559 .fail => |em| return Result{ .fail = em },
...@@ -562,14 +562,14 @@ pub fn generateSymbol(...@@ -562,14 +562,14 @@ pub fn generateSymbol(
562562
563 const union_obj = mod.typeToUnion(typed_value.ty).?;563 const union_obj = mod.typeToUnion(typed_value.ty).?;
564 if (un.tag != .none) {564 if (un.tag != .none) {
565 const field_index = typed_value.ty.unionTagFieldIndex(un.tag.toValue(), mod).?;565 const field_index = typed_value.ty.unionTagFieldIndex(Value.fromInterned(un.tag), mod).?;
566 const field_ty = union_obj.field_types.get(ip)[field_index].toType();566 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
567 if (!field_ty.hasRuntimeBits(mod)) {567 if (!field_ty.hasRuntimeBits(mod)) {
568 try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow);568 try code.appendNTimes(0xaa, math.cast(usize, layout.payload_size) orelse return error.Overflow);
569 } else {569 } else {
570 switch (try generateSymbol(bin_file, src_loc, .{570 switch (try generateSymbol(bin_file, src_loc, .{
571 .ty = field_ty,571 .ty = field_ty,
572 .val = un.val.toValue(),572 .val = Value.fromInterned(un.val),
573 }, code, debug_output, reloc_info)) {573 }, code, debug_output, reloc_info)) {
574 .ok => {},574 .ok => {},
575 .fail => |em| return Result{ .fail = em },575 .fail => |em| return Result{ .fail = em },
...@@ -582,8 +582,8 @@ pub fn generateSymbol(...@@ -582,8 +582,8 @@ pub fn generateSymbol(
582 }582 }
583 } else {583 } else {
584 switch (try generateSymbol(bin_file, src_loc, .{584 switch (try generateSymbol(bin_file, src_loc, .{
585 .ty = ip.typeOf(un.val).toType(),585 .ty = Type.fromInterned(ip.typeOf(un.val)),
586 .val = un.val.toValue(),586 .val = Value.fromInterned(un.val),
587 }, code, debug_output, reloc_info)) {587 }, code, debug_output, reloc_info)) {
588 .ok => {},588 .ok => {},
589 .fail => |em| return Result{ .fail = em },589 .fail => |em| return Result{ .fail = em },
...@@ -592,8 +592,8 @@ pub fn generateSymbol(...@@ -592,8 +592,8 @@ pub fn generateSymbol(
592592
593 if (layout.tag_size > 0 and layout.tag_align.compare(.lt, layout.payload_align)) {593 if (layout.tag_size > 0 and layout.tag_align.compare(.lt, layout.payload_align)) {
594 switch (try generateSymbol(bin_file, src_loc, .{594 switch (try generateSymbol(bin_file, src_loc, .{
595 .ty = union_obj.enum_tag_ty.toType(),595 .ty = Type.fromInterned(union_obj.enum_tag_ty),
596 .val = un.tag.toValue(),596 .val = Value.fromInterned(un.tag),
597 }, code, debug_output, reloc_info)) {597 }, code, debug_output, reloc_info)) {
598 .ok => {},598 .ok => {},
599 .fail => |em| return Result{ .fail = em },599 .fail => |em| return Result{ .fail = em },
...@@ -626,7 +626,7 @@ fn lowerParentPtr(...@@ -626,7 +626,7 @@ fn lowerParentPtr(
626 .anon_decl => |ad| try lowerAnonDeclRef(bin_file, src_loc, ad, code, debug_output, reloc_info),626 .anon_decl => |ad| try lowerAnonDeclRef(bin_file, src_loc, ad, code, debug_output, reloc_info),
627 .int => |int| try generateSymbol(bin_file, src_loc, .{627 .int => |int| try generateSymbol(bin_file, src_loc, .{
628 .ty = Type.usize,628 .ty = Type.usize,
629 .val = int.toValue(),629 .val = Value.fromInterned(int),
630 }, code, debug_output, reloc_info),630 }, code, debug_output, reloc_info),
631 .eu_payload => |eu_payload| try lowerParentPtr(631 .eu_payload => |eu_payload| try lowerParentPtr(
632 bin_file,632 bin_file,
...@@ -635,7 +635,7 @@ fn lowerParentPtr(...@@ -635,7 +635,7 @@ fn lowerParentPtr(
635 code,635 code,
636 debug_output,636 debug_output,
637 reloc_info.offset(@as(u32, @intCast(errUnionPayloadOffset(637 reloc_info.offset(@as(u32, @intCast(errUnionPayloadOffset(
638 mod.intern_pool.typeOf(eu_payload).toType(),638 Type.fromInterned(mod.intern_pool.typeOf(eu_payload)),
639 mod,639 mod,
640 )))),640 )))),
641 ),641 ),
...@@ -654,7 +654,7 @@ fn lowerParentPtr(...@@ -654,7 +654,7 @@ fn lowerParentPtr(
654 code,654 code,
655 debug_output,655 debug_output,
656 reloc_info.offset(@as(u32, @intCast(elem.index *656 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)))),
658 ),658 ),
659 .field => |field| {659 .field => |field| {
660 const base_type = mod.intern_pool.indexToKey(mod.intern_pool.typeOf(field.base)).ptr_type.child;660 const base_type = mod.intern_pool.indexToKey(mod.intern_pool.typeOf(field.base)).ptr_type.child;
...@@ -676,12 +676,12 @@ fn lowerParentPtr(...@@ -676,12 +676,12 @@ fn lowerParentPtr(
676 .struct_type,676 .struct_type,
677 .anon_struct_type,677 .anon_struct_type,
678 .union_type,678 .union_type,
679 => switch (base_type.toType().containerLayout(mod)) {679 => switch (Type.fromInterned(base_type).containerLayout(mod)) {
680 .Auto, .Extern => @intCast(base_type.toType().structFieldOffset(680 .Auto, .Extern => @intCast(Type.fromInterned(base_type).structFieldOffset(
681 @intCast(field.index),681 @intCast(field.index),
682 mod,682 mod,
683 )),683 )),
684 .Packed => if (mod.typeToStruct(base_type.toType())) |struct_type|684 .Packed => if (mod.typeToStruct(Type.fromInterned(base_type))) |struct_type|
685 math.divExact(u16, mod.structPackedFieldBitOffset(685 math.divExact(u16, mod.structPackedFieldBitOffset(
686 struct_type,686 struct_type,
687 @intCast(field.index),687 @intCast(field.index),
...@@ -723,7 +723,7 @@ fn lowerAnonDeclRef(...@@ -723,7 +723,7 @@ fn lowerAnonDeclRef(
723723
724 const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);724 const ptr_width_bytes = @divExact(target.ptrBitWidth(), 8);
725 const decl_val = anon_decl.val;725 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));
727 log.debug("lowerAnonDecl: ty = {}", .{decl_ty.fmt(mod)});727 log.debug("lowerAnonDecl: ty = {}", .{decl_ty.fmt(mod)});
728 const is_fn_body = decl_ty.zigTypeTag(mod) == .Fn;728 const is_fn_body = decl_ty.zigTypeTag(mod) == .Fn;
729 if (!is_fn_body and !decl_ty.hasRuntimeBits(mod)) {729 if (!is_fn_body and !decl_ty.hasRuntimeBits(mod)) {
...@@ -1056,8 +1056,8 @@ pub fn genTypedValue(...@@ -1056,8 +1056,8 @@ pub fn genTypedValue(
1056 const enum_tag = mod.intern_pool.indexToKey(typed_value.val.toIntern()).enum_tag;1056 const enum_tag = mod.intern_pool.indexToKey(typed_value.val.toIntern()).enum_tag;
1057 const int_tag_ty = mod.intern_pool.typeOf(enum_tag.int);1057 const int_tag_ty = mod.intern_pool.typeOf(enum_tag.int);
1058 return genTypedValue(bin_file, src_loc, .{1058 return genTypedValue(bin_file, src_loc, .{
1059 .ty = int_tag_ty.toType(),1059 .ty = Type.fromInterned(int_tag_ty),
1060 .val = enum_tag.int.toValue(),1060 .val = Value.fromInterned(enum_tag.int),
1061 }, owner_decl_index);1061 }, owner_decl_index);
1062 },1062 },
1063 .ErrorSet => {1063 .ErrorSet => {
...@@ -1074,10 +1074,10 @@ pub fn genTypedValue(...@@ -1074,10 +1074,10 @@ pub fn genTypedValue(
1074 switch (mod.intern_pool.indexToKey(typed_value.val.toIntern()).error_union.val) {1074 switch (mod.intern_pool.indexToKey(typed_value.val.toIntern()).error_union.val) {
1075 .err_name => |err_name| return genTypedValue(bin_file, src_loc, .{1075 .err_name => |err_name| return genTypedValue(bin_file, src_loc, .{
1076 .ty = err_type,1076 .ty = err_type,
1077 .val = (try mod.intern(.{ .err = .{1077 .val = Value.fromInterned((try mod.intern(.{ .err = .{
1078 .ty = err_type.toIntern(),1078 .ty = err_type.toIntern(),
1079 .name = err_name,1079 .name = err_name,
1080 } })).toValue(),1080 } }))),
1081 }, owner_decl_index),1081 }, owner_decl_index),
1082 .payload => return genTypedValue(bin_file, src_loc, .{1082 .payload => return genTypedValue(bin_file, src_loc, .{
1083 .ty = err_int_ty,1083 .ty = err_int_ty,
src/codegen/c.zig+71-71
...@@ -355,8 +355,8 @@ pub const Function = struct {...@@ -355,8 +355,8 @@ pub const Function = struct {
355 switch (c_value) {355 switch (c_value) {
356 .constant => |val| try f.object.dg.renderValue(356 .constant => |val| try f.object.dg.renderValue(
357 w,357 w,
358 f.object.dg.module.intern_pool.typeOf(val).toType(),358 Type.fromInterned(f.object.dg.module.intern_pool.typeOf(val)),
359 val.toValue(),359 Value.fromInterned(val),
360 location,360 location,
361 ),361 ),
362 .undef => |ty| try f.object.dg.renderValue(w, ty, Value.undef, location),362 .undef => |ty| try f.object.dg.renderValue(w, ty, Value.undef, location),
...@@ -370,8 +370,8 @@ pub const Function = struct {...@@ -370,8 +370,8 @@ pub const Function = struct {
370 try w.writeAll("(*");370 try w.writeAll("(*");
371 try f.object.dg.renderValue(371 try f.object.dg.renderValue(
372 w,372 w,
373 f.object.dg.module.intern_pool.typeOf(val).toType(),373 Type.fromInterned(f.object.dg.module.intern_pool.typeOf(val)),
374 val.toValue(),374 Value.fromInterned(val),
375 .Other,375 .Other,
376 );376 );
377 try w.writeByte(')');377 try w.writeByte(')');
...@@ -385,8 +385,8 @@ pub const Function = struct {...@@ -385,8 +385,8 @@ pub const Function = struct {
385 .constant => |val| {385 .constant => |val| {
386 try f.object.dg.renderValue(386 try f.object.dg.renderValue(
387 w,387 w,
388 f.object.dg.module.intern_pool.typeOf(val).toType(),388 Type.fromInterned(f.object.dg.module.intern_pool.typeOf(val)),
389 val.toValue(),389 Value.fromInterned(val),
390 .Other,390 .Other,
391 );391 );
392 try w.writeByte('.');392 try w.writeByte('.');
...@@ -402,8 +402,8 @@ pub const Function = struct {...@@ -402,8 +402,8 @@ pub const Function = struct {
402 try w.writeByte('(');402 try w.writeByte('(');
403 try f.object.dg.renderValue(403 try f.object.dg.renderValue(
404 w,404 w,
405 f.object.dg.module.intern_pool.typeOf(val).toType(),405 Type.fromInterned(f.object.dg.module.intern_pool.typeOf(val)),
406 val.toValue(),406 Value.fromInterned(val),
407 .Other,407 .Other,
408 );408 );
409 try w.writeAll(")->");409 try w.writeAll(")->");
...@@ -561,7 +561,7 @@ pub const DeclGen = struct {...@@ -561,7 +561,7 @@ pub const DeclGen = struct {
561 const mod = dg.module;561 const mod = dg.module;
562 const ip = &mod.intern_pool;562 const ip = &mod.intern_pool;
563 const decl_val = anon_decl.val;563 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
566 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.566 // Render an undefined pointer if we have a pointer to a zero-bit or comptime type.
567 if (ty.isPtrAtRuntime(mod) and !decl_ty.isFnOrHasRuntimeBits(mod)) {567 if (ty.isPtrAtRuntime(mod) and !decl_ty.isFnOrHasRuntimeBits(mod)) {
...@@ -569,20 +569,20 @@ pub const DeclGen = struct {...@@ -569,20 +569,20 @@ pub const DeclGen = struct {
569 }569 }
570570
571 // Chase function values in order to be able to reference the original function.571 // 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| {
573 _ = func;573 _ = func;
574 _ = ptr_val;574 _ = ptr_val;
575 _ = location;575 _ = location;
576 @panic("TODO");576 @panic("TODO");
577 }577 }
578 if (decl_val.toValue().getExternFunc(mod)) |extern_func| {578 if (Value.fromInterned(decl_val).getExternFunc(mod)) |extern_func| {
579 _ = extern_func;579 _ = extern_func;
580 _ = ptr_val;580 _ = ptr_val;
581 _ = location;581 _ = location;
582 @panic("TODO");582 @panic("TODO");
583 }583 }
584584
585 assert(decl_val.toValue().getVariable(mod) == null);585 assert(Value.fromInterned(decl_val).getVariable(mod) == null);
586586
587 // We shouldn't cast C function pointers as this is UB (when you call587 // We shouldn't cast C function pointers as this is UB (when you call
588 // them). The analysis until now should ensure that the C function588 // them). The analysis until now should ensure that the C function
...@@ -608,7 +608,7 @@ pub const DeclGen = struct {...@@ -608,7 +608,7 @@ pub const DeclGen = struct {
608 // alignment. If there is already an entry, keep the greater alignment.608 // alignment. If there is already an entry, keep the greater alignment.
609 const explicit_alignment = ptr_type.flags.alignment;609 const explicit_alignment = ptr_type.flags.alignment;
610 if (explicit_alignment != .none) {610 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);
612 if (explicit_alignment.compareStrict(.gt, abi_alignment)) {612 if (explicit_alignment.compareStrict(.gt, abi_alignment)) {
613 const aligned_gop = try dg.aligned_anon_decls.getOrPut(dg.gpa, decl_val);613 const aligned_gop = try dg.aligned_anon_decls.getOrPut(dg.gpa, decl_val);
614 aligned_gop.value_ptr.* = if (aligned_gop.found_existing)614 aligned_gop.value_ptr.* = if (aligned_gop.found_existing)
...@@ -668,20 +668,20 @@ pub const DeclGen = struct {...@@ -668,20 +668,20 @@ pub const DeclGen = struct {
668 location: ValueRenderLocation,668 location: ValueRenderLocation,
669 ) error{ OutOfMemory, AnalysisFail }!void {669 ) error{ OutOfMemory, AnalysisFail }!void {
670 const mod = dg.module;670 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));
672 const ptr_cty = try dg.typeToIndex(ptr_ty, .complete);672 const ptr_cty = try dg.typeToIndex(ptr_ty, .complete);
673 const ptr = mod.intern_pool.indexToKey(ptr_val).ptr;673 const ptr = mod.intern_pool.indexToKey(ptr_val).ptr;
674 switch (ptr.addr) {674 switch (ptr.addr) {
675 .decl => |d| try dg.renderDeclValue(writer, ptr_ty, ptr_val.toValue(), d, 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, ptr_val.toValue(), md.decl, 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, ptr_val.toValue(), anon_decl, location),677 .anon_decl => |anon_decl| try dg.renderAnonDeclValue(writer, ptr_ty, Value.fromInterned(ptr_val), anon_decl, location),
678 .int => |int| {678 .int => |int| {
679 try writer.writeByte('(');679 try writer.writeByte('(');
680 try dg.renderCType(writer, ptr_cty);680 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)});
682 },682 },
683 .eu_payload, .opt_payload => |base| {683 .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));
685 const base_ty = ptr_base_ty.childType(mod);685 const base_ty = ptr_base_ty.childType(mod);
686 // Ensure complete type definition is visible before accessing fields.686 // Ensure complete type definition is visible before accessing fields.
687 _ = try dg.typeToIndex(base_ty, .complete);687 _ = try dg.typeToIndex(base_ty, .complete);
...@@ -702,7 +702,7 @@ pub const DeclGen = struct {...@@ -702,7 +702,7 @@ pub const DeclGen = struct {
702 try writer.writeAll(")->payload");702 try writer.writeAll(")->payload");
703 },703 },
704 .elem => |elem| {704 .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));
706 const elem_ty = ptr_base_ty.elemType2(mod);706 const elem_ty = ptr_base_ty.elemType2(mod);
707 const ptr_elem_ty = try mod.adjustPtrTypeChild(ptr_base_ty, elem_ty);707 const ptr_elem_ty = try mod.adjustPtrTypeChild(ptr_base_ty, elem_ty);
708 const ptr_elem_cty = try dg.typeToIndex(ptr_elem_ty, .complete);708 const ptr_elem_cty = try dg.typeToIndex(ptr_elem_ty, .complete);
...@@ -718,7 +718,7 @@ pub const DeclGen = struct {...@@ -718,7 +718,7 @@ pub const DeclGen = struct {
718 try writer.print(")[{d}]", .{elem.index});718 try writer.print(")[{d}]", .{elem.index});
719 },719 },
720 .field => |field| {720 .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));
722 const base_ty = ptr_base_ty.childType(mod);722 const base_ty = ptr_base_ty.childType(mod);
723 // Ensure complete type definition is visible before accessing fields.723 // Ensure complete type definition is visible before accessing fields.
724 _ = try dg.typeToIndex(base_ty, .complete);724 _ = try dg.typeToIndex(base_ty, .complete);
...@@ -909,8 +909,8 @@ pub const DeclGen = struct {...@@ -909,8 +909,8 @@ pub const DeclGen = struct {
909 }909 }
910 const union_obj = mod.typeToUnion(ty).?;910 const union_obj = mod.typeToUnion(ty).?;
911 for (union_obj.field_types.get(ip)) |field_ty| {911 for (union_obj.field_types.get(ip)) |field_ty| {
912 if (!field_ty.toType().hasRuntimeBits(mod)) continue;912 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
913 try dg.renderValue(writer, field_ty.toType(), val, initializer_type);913 try dg.renderValue(writer, Type.fromInterned(field_ty), val, initializer_type);
914 break;914 break;
915 }915 }
916 if (ty.unionTagTypeSafety(mod)) |_| try writer.writeByte('}');916 if (ty.unionTagTypeSafety(mod)) |_| try writer.writeByte('}');
...@@ -1045,10 +1045,10 @@ pub const DeclGen = struct {...@@ -1045,10 +1045,10 @@ pub const DeclGen = struct {
1045 .err_name => |err_name| return dg.renderValue(1045 .err_name => |err_name| return dg.renderValue(
1046 writer,1046 writer,
1047 error_ty,1047 error_ty,
1048 (try mod.intern(.{ .err = .{1048 Value.fromInterned((try mod.intern(.{ .err = .{
1049 .ty = error_ty.toIntern(),1049 .ty = error_ty.toIntern(),
1050 .name = err_name,1050 .name = err_name,
1051 } })).toValue(),1051 } }))),
1052 location,1052 location,
1053 ),1053 ),
1054 .payload => return dg.renderValue(1054 .payload => return dg.renderValue(
...@@ -1070,10 +1070,10 @@ pub const DeclGen = struct {...@@ -1070,10 +1070,10 @@ pub const DeclGen = struct {
1070 try dg.renderValue(1070 try dg.renderValue(
1071 writer,1071 writer,
1072 payload_ty,1072 payload_ty,
1073 switch (error_union.val) {1073 Value.fromInterned(switch (error_union.val) {
1074 .err_name => try mod.intern(.{ .undef = payload_ty.ip_index }),1074 .err_name => try mod.intern(.{ .undef = payload_ty.ip_index }),
1075 .payload => |payload| payload,1075 .payload => |payload| payload,
1076 }.toValue(),1076 }),
1077 initializer_type,1077 initializer_type,
1078 );1078 );
1079 try writer.writeAll(", .error = ");1079 try writer.writeAll(", .error = ");
...@@ -1081,10 +1081,10 @@ pub const DeclGen = struct {...@@ -1081,10 +1081,10 @@ pub const DeclGen = struct {
1081 .err_name => |err_name| try dg.renderValue(1081 .err_name => |err_name| try dg.renderValue(
1082 writer,1082 writer,
1083 error_ty,1083 error_ty,
1084 (try mod.intern(.{ .err = .{1084 Value.fromInterned((try mod.intern(.{ .err = .{
1085 .ty = error_ty.toIntern(),1085 .ty = error_ty.toIntern(),
1086 .name = err_name,1086 .name = err_name,
1087 } })).toValue(),1087 } }))),
1088 location,1088 location,
1089 ),1089 ),
1090 .payload => try dg.renderValue(1090 .payload => try dg.renderValue(
...@@ -1099,7 +1099,7 @@ pub const DeclGen = struct {...@@ -1099,7 +1099,7 @@ pub const DeclGen = struct {
1099 .enum_tag => {1099 .enum_tag => {
1100 const enum_tag = ip.indexToKey(val.ip_index).enum_tag;1100 const enum_tag = ip.indexToKey(val.ip_index).enum_tag;
1101 const int_tag_ty = ip.typeOf(enum_tag.int);1101 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);
1103 },1103 },
1104 .float => {1104 .float => {
1105 const bits = ty.floatBits(target);1105 const bits = ty.floatBits(target);
...@@ -1218,7 +1218,7 @@ pub const DeclGen = struct {...@@ -1218,7 +1218,7 @@ pub const DeclGen = struct {
1218 try writer.writeAll("((");1218 try writer.writeAll("((");
1219 try dg.renderType(writer, ptr_ty);1219 try dg.renderType(writer, ptr_ty);
1220 try writer.print("){x})", .{1220 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),
1222 });1222 });
1223 },1223 },
1224 .eu_payload,1224 .eu_payload,
...@@ -1230,7 +1230,7 @@ pub const DeclGen = struct {...@@ -1230,7 +1230,7 @@ pub const DeclGen = struct {
1230 }1230 }
1231 if (ptr.len != .none) {1231 if (ptr.len != .none) {
1232 try writer.writeAll(", ");1232 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);
1234 try writer.writeByte('}');1234 try writer.writeByte('}');
1235 }1235 }
1236 },1236 },
...@@ -1250,7 +1250,7 @@ pub const DeclGen = struct {...@@ -1250,7 +1250,7 @@ pub const DeclGen = struct {
1250 .Pointer => try mod.getCoerced(val, payload_ty),1250 .Pointer => try mod.getCoerced(val, payload_ty),
1251 else => unreachable,1251 else => unreachable,
1252 },1252 },
1253 else => |payload| payload.toValue(),1253 else => |payload| Value.fromInterned(payload),
1254 },1254 },
1255 location,1255 location,
1256 );1256 );
...@@ -1262,10 +1262,10 @@ pub const DeclGen = struct {...@@ -1262,10 +1262,10 @@ pub const DeclGen = struct {
1262 }1262 }
12631263
1264 try writer.writeAll("{ .payload = ");1264 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) {
1266 .none => try mod.intern(.{ .undef = payload_ty.ip_index }),1266 .none => try mod.intern(.{ .undef = payload_ty.ip_index }),
1267 else => |payload| payload,1267 else => |payload| payload,
1268 }.toValue(), initializer_type);1268 }), initializer_type);
1269 try writer.writeAll(", .is_null = ");1269 try writer.writeAll(", .is_null = ");
1270 try dg.renderValue(writer, Type.bool, is_null_val, initializer_type);1270 try dg.renderValue(writer, Type.bool, is_null_val, initializer_type);
1271 try writer.writeAll(" }");1271 try writer.writeAll(" }");
...@@ -1349,7 +1349,7 @@ pub const DeclGen = struct {...@@ -1349,7 +1349,7 @@ pub const DeclGen = struct {
1349 0..,1349 0..,
1350 ) |field_ty, comptime_ty, field_i| {1350 ) |field_ty, comptime_ty, field_i| {
1351 if (comptime_ty != .none) continue;1351 if (comptime_ty != .none) continue;
1352 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;1352 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
13531353
1354 if (!empty) try writer.writeByte(',');1354 if (!empty) try writer.writeByte(',');
13551355
...@@ -1361,7 +1361,7 @@ pub const DeclGen = struct {...@@ -1361,7 +1361,7 @@ pub const DeclGen = struct {
1361 .elems => |elems| elems[field_i],1361 .elems => |elems| elems[field_i],
1362 .repeated_elem => |elem| elem,1362 .repeated_elem => |elem| elem,
1363 };1363 };
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
1366 empty = false;1366 empty = false;
1367 }1367 }
...@@ -1378,7 +1378,7 @@ pub const DeclGen = struct {...@@ -1378,7 +1378,7 @@ pub const DeclGen = struct {
1378 try writer.writeByte('{');1378 try writer.writeByte('{');
1379 var empty = true;1379 var empty = true;
1380 for (0..struct_type.field_types.len) |field_i| {1380 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]);
1382 if (struct_type.fieldIsComptime(ip, field_i)) continue;1382 if (struct_type.fieldIsComptime(ip, field_i)) continue;
1383 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;1383 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
13841384
...@@ -1391,7 +1391,7 @@ pub const DeclGen = struct {...@@ -1391,7 +1391,7 @@ pub const DeclGen = struct {
1391 .elems => |elems| elems[field_i],1391 .elems => |elems| elems[field_i],
1392 .repeated_elem => |elem| elem,1392 .repeated_elem => |elem| elem,
1393 };1393 };
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
1396 empty = false;1396 empty = false;
1397 }1397 }
...@@ -1408,7 +1408,7 @@ pub const DeclGen = struct {...@@ -1408,7 +1408,7 @@ pub const DeclGen = struct {
1408 var eff_num_fields: usize = 0;1408 var eff_num_fields: usize = 0;
14091409
1410 for (field_types) |field_ty| {1410 for (field_types) |field_ty| {
1411 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;1411 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
1412 eff_num_fields += 1;1412 eff_num_fields += 1;
1413 }1413 }
14141414
...@@ -1428,7 +1428,7 @@ pub const DeclGen = struct {...@@ -1428,7 +1428,7 @@ pub const DeclGen = struct {
1428 var eff_index: usize = 0;1428 var eff_index: usize = 0;
1429 var needs_closing_paren = false;1429 var needs_closing_paren = false;
1430 for (field_types, 0..) |field_ty, field_i| {1430 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
1433 const field_val = switch (ip.indexToKey(val.ip_index).aggregate.storage) {1433 const field_val = switch (ip.indexToKey(val.ip_index).aggregate.storage) {
1434 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{1434 .bytes => |bytes| try ip.get(mod.gpa, .{ .int = .{
...@@ -1438,24 +1438,24 @@ pub const DeclGen = struct {...@@ -1438,24 +1438,24 @@ pub const DeclGen = struct {
1438 .elems => |elems| elems[field_i],1438 .elems => |elems| elems[field_i],
1439 .repeated_elem => |elem| elem,1439 .repeated_elem => |elem| elem,
1440 };1440 };
1441 const cast_context = IntCastContext{ .value = .{ .value = field_val.toValue() } };1441 const cast_context = IntCastContext{ .value = .{ .value = Value.fromInterned(field_val) } };
1442 if (bit_offset != 0) {1442 if (bit_offset != 0) {
1443 try writer.writeAll("zig_shl_");1443 try writer.writeAll("zig_shl_");
1444 try dg.renderTypeForBuiltinFnName(writer, ty);1444 try dg.renderTypeForBuiltinFnName(writer, ty);
1445 try writer.writeByte('(');1445 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);
1447 try writer.writeAll(", ");1447 try writer.writeAll(", ");
1448 const bit_offset_val = try mod.intValue(bit_offset_ty, bit_offset);1448 const bit_offset_val = try mod.intValue(bit_offset_ty, bit_offset);
1449 try dg.renderValue(writer, bit_offset_ty, bit_offset_val, .FunctionArgument);1449 try dg.renderValue(writer, bit_offset_ty, bit_offset_val, .FunctionArgument);
1450 try writer.writeByte(')');1450 try writer.writeByte(')');
1451 } else {1451 } 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);
1453 }1453 }
14541454
1455 if (needs_closing_paren) try writer.writeByte(')');1455 if (needs_closing_paren) try writer.writeByte(')');
1456 if (eff_index != eff_num_fields - 1) try writer.writeAll(", ");1456 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);
1459 needs_closing_paren = true;1459 needs_closing_paren = true;
1460 eff_index += 1;1460 eff_index += 1;
1461 }1461 }
...@@ -1464,7 +1464,7 @@ pub const DeclGen = struct {...@@ -1464,7 +1464,7 @@ pub const DeclGen = struct {
1464 // a << a_off | b << b_off | c << c_off1464 // a << a_off | b << b_off | c << c_off
1465 var empty = true;1465 var empty = true;
1466 for (field_types, 0..) |field_ty, field_i| {1466 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
1469 if (!empty) try writer.writeAll(" | ");1469 if (!empty) try writer.writeAll(" | ");
1470 try writer.writeByte('(');1470 try writer.writeByte('(');
...@@ -1481,15 +1481,15 @@ pub const DeclGen = struct {...@@ -1481,15 +1481,15 @@ pub const DeclGen = struct {
1481 };1481 };
14821482
1483 if (bit_offset != 0) {1483 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);
1485 try writer.writeAll(" << ");1485 try writer.writeAll(" << ");
1486 const bit_offset_val = try mod.intValue(bit_offset_ty, bit_offset);1486 const bit_offset_val = try mod.intValue(bit_offset_ty, bit_offset);
1487 try dg.renderValue(writer, bit_offset_ty, bit_offset_val, .FunctionArgument);1487 try dg.renderValue(writer, bit_offset_ty, bit_offset_val, .FunctionArgument);
1488 } else {1488 } 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);
1490 }1490 }
14911491
1492 bit_offset += field_ty.toType().bitSize(mod);1492 bit_offset += Type.fromInterned(field_ty).bitSize(mod);
1493 empty = false;1493 empty = false;
1494 }1494 }
1495 try writer.writeByte(')');1495 try writer.writeByte(')');
...@@ -1509,7 +1509,7 @@ pub const DeclGen = struct {...@@ -1509,7 +1509,7 @@ pub const DeclGen = struct {
1509 try dg.renderType(writer, backing_ty);1509 try dg.renderType(writer, backing_ty);
1510 try writer.writeByte(')');1510 try writer.writeByte(')');
1511 }1511 }
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);
1513 },1513 },
1514 .Extern => {1514 .Extern => {
1515 if (location == .StaticInitializer) {1515 if (location == .StaticInitializer) {
...@@ -1522,7 +1522,7 @@ pub const DeclGen = struct {...@@ -1522,7 +1522,7 @@ pub const DeclGen = struct {
1522 try writer.writeAll(")(");1522 try writer.writeAll(")(");
1523 try dg.renderType(writer, backing_ty);1523 try dg.renderType(writer, backing_ty);
1524 try writer.writeAll("){");1524 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);
1526 try writer.writeAll("})");1526 try writer.writeAll("})");
1527 },1527 },
1528 else => unreachable,1528 else => unreachable,
...@@ -1534,8 +1534,8 @@ pub const DeclGen = struct {...@@ -1534,8 +1534,8 @@ pub const DeclGen = struct {
1534 try writer.writeByte(')');1534 try writer.writeByte(')');
1535 }1535 }
15361536
1537 const field_i = mod.unionTagFieldIndex(union_obj, un.tag.toValue()).?;1537 const field_i = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
1538 const field_ty = union_obj.field_types.get(ip)[field_i].toType();1538 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_i]);
1539 const field_name = union_obj.field_names.get(ip)[field_i];1539 const field_name = union_obj.field_names.get(ip)[field_i];
1540 if (union_obj.getLayout(ip) == .Packed) {1540 if (union_obj.getLayout(ip) == .Packed) {
1541 if (field_ty.hasRuntimeBits(mod)) {1541 if (field_ty.hasRuntimeBits(mod)) {
...@@ -1548,7 +1548,7 @@ pub const DeclGen = struct {...@@ -1548,7 +1548,7 @@ pub const DeclGen = struct {
1548 try dg.renderType(writer, ty);1548 try dg.renderType(writer, ty);
1549 try writer.writeByte(')');1549 try writer.writeByte(')');
1550 }1550 }
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);
1552 } else {1552 } else {
1553 try writer.writeAll("0");1553 try writer.writeAll("0");
1554 }1554 }
...@@ -1560,7 +1560,7 @@ pub const DeclGen = struct {...@@ -1560,7 +1560,7 @@ pub const DeclGen = struct {
1560 const layout = mod.getUnionLayout(union_obj);1560 const layout = mod.getUnionLayout(union_obj);
1561 if (layout.tag_size != 0) {1561 if (layout.tag_size != 0) {
1562 try writer.writeAll(" .tag = ");1562 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);
1564 }1564 }
1565 if (ty.unionHasAllZeroBitFieldTypes(mod)) return try writer.writeByte('}');1565 if (ty.unionHasAllZeroBitFieldTypes(mod)) return try writer.writeByte('}');
1566 if (layout.tag_size != 0) try writer.writeByte(',');1566 if (layout.tag_size != 0) try writer.writeByte(',');
...@@ -1568,11 +1568,11 @@ pub const DeclGen = struct {...@@ -1568,11 +1568,11 @@ pub const DeclGen = struct {
1568 }1568 }
1569 if (field_ty.hasRuntimeBits(mod)) {1569 if (field_ty.hasRuntimeBits(mod)) {
1570 try writer.print(" .{ } = ", .{fmtIdent(ip.stringToSlice(field_name))});1570 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);
1572 try writer.writeByte(' ');1572 try writer.writeByte(' ');
1573 } else for (union_obj.field_types.get(ip)) |this_field_ty| {1573 } else for (union_obj.field_types.get(ip)) |this_field_ty| {
1574 if (!this_field_ty.toType().hasRuntimeBits(mod)) continue;1574 if (!Type.fromInterned(this_field_ty).hasRuntimeBits(mod)) continue;
1575 try dg.renderValue(writer, this_field_ty.toType(), Value.undef, initializer_type);1575 try dg.renderValue(writer, Type.fromInterned(this_field_ty), Value.undef, initializer_type);
1576 break;1576 break;
1577 }1577 }
1578 if (ty.unionTagTypeSafety(mod)) |_| try writer.writeByte('}');1578 if (ty.unionTagTypeSafety(mod)) |_| try writer.writeByte('}');
...@@ -2527,7 +2527,7 @@ pub fn genErrDecls(o: *Object) !void {...@@ -2527,7 +2527,7 @@ pub fn genErrDecls(o: *Object) !void {
2527 .ty = .anyerror_type,2527 .ty = .anyerror_type,
2528 .name = name_nts,2528 .name = name_nts,
2529 } });2529 } });
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);
2531 try writer.print(" = {d}u,\n", .{value});2531 try writer.print(" = {d}u,\n", .{value});
2532 }2532 }
2533 o.indent_writer.popIndent();2533 o.indent_writer.popIndent();
...@@ -2557,7 +2557,7 @@ pub fn genErrDecls(o: *Object) !void {...@@ -2557,7 +2557,7 @@ pub fn genErrDecls(o: *Object) !void {
2557 try writer.writeAll("static ");2557 try writer.writeAll("static ");
2558 try o.dg.renderTypeAndName(writer, name_ty, .{ .identifier = identifier }, Const, .none, .complete);2558 try o.dg.renderTypeAndName(writer, name_ty, .{ .identifier = identifier }, Const, .none, .complete);
2559 try writer.writeAll(" = ");2559 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);
2561 try writer.writeAll(";\n");2561 try writer.writeAll(";\n");
2562 }2562 }
25632563
...@@ -2590,7 +2590,7 @@ fn genExports(o: *Object) !void {...@@ -2590,7 +2590,7 @@ fn genExports(o: *Object) !void {
2590 const ip = &mod.intern_pool;2590 const ip = &mod.intern_pool;
2591 const decl_index = o.dg.pass.decl;2591 const decl_index = o.dg.pass.decl;
2592 const decl = mod.declPtr(decl_index);2592 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))) };
2594 const fwd = o.dg.fwd_decl.writer();2594 const fwd = o.dg.fwd_decl.writer();
25952595
2596 const exports = mod.decl_exports.get(decl_index) orelse return;2596 const exports = mod.decl_exports.get(decl_index) orelse return;
...@@ -2677,7 +2677,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {...@@ -2677,7 +2677,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
2677 });2677 });
2678 try o.dg.renderTypeAndName(w, name_ty, .{ .identifier = "name" }, Const, .none, .complete);2678 try o.dg.renderTypeAndName(w, name_ty, .{ .identifier = "name" }, Const, .none, .complete);
2679 try w.writeAll(" = ");2679 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);
2681 try w.writeAll(";\n return (");2681 try w.writeAll(";\n return (");
2682 try o.dg.renderType(w, name_slice_ty);2682 try o.dg.renderType(w, name_slice_ty);
2683 try w.print("){{{}, {}}};\n", .{2683 try w.print("){{{}, {}}};\n", .{
...@@ -2817,7 +2817,7 @@ pub fn genDecl(o: *Object) !void {...@@ -2817,7 +2817,7 @@ pub fn genDecl(o: *Object) !void {
2817 const mod = o.dg.module;2817 const mod = o.dg.module;
2818 const decl_index = o.dg.pass.decl;2818 const decl_index = o.dg.pass.decl;
2819 const decl = mod.declPtr(decl_index);2819 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
2822 if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return;2822 if (!tv.ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return;
2823 if (tv.val.getExternFunc(mod)) |_| {2823 if (tv.val.getExternFunc(mod)) |_| {
...@@ -2843,7 +2843,7 @@ pub fn genDecl(o: *Object) !void {...@@ -2843,7 +2843,7 @@ pub fn genDecl(o: *Object) !void {
2843 try o.dg.renderTypeAndName(w, tv.ty, decl_c_value, .{}, decl.alignment, .complete);2843 try o.dg.renderTypeAndName(w, tv.ty, decl_c_value, .{}, decl.alignment, .complete);
2844 if (decl.@"linksection" != .none) try w.writeAll(", read, write)");2844 if (decl.@"linksection" != .none) try w.writeAll(", read, write)");
2845 try w.writeAll(" = ");2845 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);
2847 try w.writeByte(';');2847 try w.writeByte(';');
2848 try o.indent_writer.insertNewline();2848 try o.indent_writer.insertNewline();
2849 } else {2849 } else {
...@@ -3491,7 +3491,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -3491,7 +3491,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
3491 const ptr_ty = f.typeOf(ty_op.operand);3491 const ptr_ty = f.typeOf(ty_op.operand);
3492 const ptr_scalar_ty = ptr_ty.scalarType(mod);3492 const ptr_scalar_ty = ptr_ty.scalarType(mod);
3493 const ptr_info = ptr_scalar_ty.ptrInfo(mod);3493 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
3496 if (!src_ty.hasRuntimeBitsIgnoreComptime(mod)) {3496 if (!src_ty.hasRuntimeBitsIgnoreComptime(mod)) {
3497 try reap(f, inst, &.{ty_op.operand});3497 try reap(f, inst, &.{ty_op.operand});
...@@ -3767,7 +3767,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -3767,7 +3767,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
3767 try writer.writeAll("memset(");3767 try writer.writeAll("memset(");
3768 try f.writeCValue(writer, ptr_val, .FunctionArgument);3768 try f.writeCValue(writer, ptr_val, .FunctionArgument);
3769 try writer.writeAll(", 0xaa, sizeof(");3769 try writer.writeAll(", 0xaa, sizeof(");
3770 try f.renderType(writer, ptr_info.child.toType());3770 try f.renderType(writer, Type.fromInterned(ptr_info.child));
3771 try writer.writeAll("));\n");3771 try writer.writeAll("));\n");
3772 }3772 }
3773 return .none;3773 return .none;
...@@ -3777,7 +3777,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -3777,7 +3777,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
3777 ptr_info.flags.alignment.compare(.gte, src_ty.abiAlignment(mod))3777 ptr_info.flags.alignment.compare(.gte, src_ty.abiAlignment(mod))
3778 else3778 else
3779 true;3779 true;
3780 const is_array = lowersToArray(ptr_info.child.toType(), mod);3780 const is_array = lowersToArray(Type.fromInterned(ptr_info.child), mod);
3781 const need_memcpy = !is_aligned or is_array;3781 const need_memcpy = !is_aligned or is_array;
37823782
3783 const src_val = try f.resolveInst(bin_op.rhs);3783 const src_val = try f.resolveInst(bin_op.rhs);
...@@ -3789,7 +3789,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {...@@ -3789,7 +3789,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
3789 if (need_memcpy) {3789 if (need_memcpy) {
3790 // For this memcpy to safely work we need the rhs to have the same3790 // For this memcpy to safely work we need the rhs to have the same
3791 // underlying type as the lhs (i.e. they must both be arrays of the same underlying type).3791 // 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
3794 // If the source is a constant, writeCValue will emit a brace initialization3794 // If the source is a constant, writeCValue will emit a brace initialization
3795 // so work around this by initializing into new local.3795 // so work around this by initializing into new local.
...@@ -5404,7 +5404,7 @@ fn fieldLocation(...@@ -5404,7 +5404,7 @@ fn fieldLocation(
5404 const union_obj = mod.typeToUnion(container_ty).?;5404 const union_obj = mod.typeToUnion(container_ty).?;
5405 return switch (union_obj.getLayout(ip)) {5405 return switch (union_obj.getLayout(ip)) {
5406 .Auto, .Extern => {5406 .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]);
5408 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod))5408 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod))
5409 return if (container_ty.unionTagTypeSafety(mod) != null and5409 return if (container_ty.unionTagTypeSafety(mod) != null and
5410 !container_ty.unionHasAllZeroBitFieldTypes(mod))5410 !container_ty.unionHasAllZeroBitFieldTypes(mod))
...@@ -6754,7 +6754,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -6754,7 +6754,7 @@ fn airShuffle(f: *Function, inst: Air.Inst.Index) !CValue {
6754 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;6754 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
6755 const extra = f.air.extraData(Air.Shuffle, ty_pl.payload).data;6755 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);
6758 const lhs = try f.resolveInst(extra.a);6758 const lhs = try f.resolveInst(extra.a);
6759 const rhs = try f.resolveInst(extra.b);6759 const rhs = try f.resolveInst(extra.b);
67606760
...@@ -7947,7 +7947,7 @@ fn lowerFnRetTy(ret_ty: Type, mod: *Module) !Type {...@@ -7947,7 +7947,7 @@ fn lowerFnRetTy(ret_ty: Type, mod: *Module) !Type {
7947 .types = &types,7947 .types = &types,
7948 .values = &values,7948 .values = &values,
7949 });7949 });
7950 return interned.toType();7950 return Type.fromInterned(interned);
7951 }7951 }
79527952
7953 return if (ret_ty.hasRuntimeBitsIgnoreComptime(mod)) ret_ty else Type.void;7953 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 {...@@ -1481,7 +1481,7 @@ pub const CType = extern union {
1481 info.flags.vector_index == .none)1481 info.flags.vector_index == .none)
1482 try mod.intType(.unsigned, info.packed_offset.host_size * 8)1482 try mod.intType(.unsigned, info.packed_offset.host_size * 8)
1483 else1483 else
1484 info.child.toType();1484 Type.fromInterned(info.child);
14851485
1486 if (try lookup.typeToIndex(pointee_ty, .forward)) |child_idx| {1486 if (try lookup.typeToIndex(pointee_ty, .forward)) |child_idx| {
1487 self.storage = .{ .child = .{1487 self.storage = .{ .child = .{
...@@ -1496,7 +1496,7 @@ pub const CType = extern union {...@@ -1496,7 +1496,7 @@ pub const CType = extern union {
14961496
1497 .Struct, .Union => |zig_ty_tag| if (ty.containerLayout(mod) == .Packed) {1497 .Struct, .Union => |zig_ty_tag| if (ty.containerLayout(mod) == .Packed) {
1498 if (mod.typeToPackedStruct(ty)) |packed_struct| {1498 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);
1500 } else {1500 } else {
1501 const bits: u16 = @intCast(ty.bitSize(mod));1501 const bits: u16 = @intCast(ty.bitSize(mod));
1502 const int_ty = try mod.intType(.unsigned, bits);1502 const int_ty = try mod.intType(.unsigned, bits);
...@@ -1736,10 +1736,10 @@ pub const CType = extern union {...@@ -1736,10 +1736,10 @@ pub const CType = extern union {
1736 .complete, .parameter, .global => .parameter,1736 .complete, .parameter, .global => .parameter,
1737 .payload => unreachable,1737 .payload => unreachable,
1738 };1738 };
1739 _ = try lookup.typeToIndex(info.return_type.toType(), param_kind);1739 _ = try lookup.typeToIndex(Type.fromInterned(info.return_type), param_kind);
1740 for (info.param_types.get(ip)) |param_type| {1740 for (info.param_types.get(ip)) |param_type| {
1741 if (!param_type.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;1741 if (!Type.fromInterned(param_type).hasRuntimeBitsIgnoreComptime(mod)) continue;
1742 _ = try lookup.typeToIndex(param_type.toType(), param_kind);1742 _ = try lookup.typeToIndex(Type.fromInterned(param_type), param_kind);
1743 }1743 }
1744 }1744 }
1745 self.init(if (info.is_var_args) .varargs_function else .function);1745 self.init(if (info.is_var_args) .varargs_function else .function);
...@@ -2033,21 +2033,21 @@ pub const CType = extern union {...@@ -2033,21 +2033,21 @@ pub const CType = extern union {
20332033
2034 var c_params_len: usize = 0;2034 var c_params_len: usize = 0;
2035 for (info.param_types.get(ip)) |param_type| {2035 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;
2037 c_params_len += 1;2037 c_params_len += 1;
2038 }2038 }
20392039
2040 const params_pl = try arena.alloc(Index, c_params_len);2040 const params_pl = try arena.alloc(Index, c_params_len);
2041 var c_param_i: usize = 0;2041 var c_param_i: usize = 0;
2042 for (info.param_types.get(ip)) |param_type| {2042 for (info.param_types.get(ip)) |param_type| {
2043 if (!param_type.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;2043 if (!Type.fromInterned(param_type).hasRuntimeBitsIgnoreComptime(mod)) continue;
2044 params_pl[c_param_i] = store.set.typeToIndex(param_type.toType(), mod, param_kind).?;2044 params_pl[c_param_i] = store.set.typeToIndex(Type.fromInterned(param_type), mod, param_kind).?;
2045 c_param_i += 1;2045 c_param_i += 1;
2046 }2046 }
20472047
2048 const fn_pl = try arena.create(Payload.Function);2048 const fn_pl = try arena.create(Payload.Function);
2049 fn_pl.* = .{ .base = .{ .tag = t }, .data = .{2049 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).?,
2051 .param_types = params_pl,2051 .param_types = params_pl,
2052 } };2052 } };
2053 return initPayload(fn_pl);2053 return initPayload(fn_pl);
...@@ -2167,18 +2167,18 @@ pub const CType = extern union {...@@ -2167,18 +2167,18 @@ pub const CType = extern union {
2167 .payload => unreachable,2167 .payload => unreachable,
2168 };2168 };
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))
2171 return false;2171 return false;
21722172
2173 var c_param_i: usize = 0;2173 var c_param_i: usize = 0;
2174 for (info.param_types.get(ip)) |param_type| {2174 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
2177 if (c_param_i >= data.param_types.len) return false;2177 if (c_param_i >= data.param_types.len) return false;
2178 const param_cty = data.param_types[c_param_i];2178 const param_cty = data.param_types[c_param_i];
2179 c_param_i += 1;2179 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))
2182 return false;2182 return false;
2183 }2183 }
2184 return c_param_i == data.param_types.len;2184 return c_param_i == data.param_types.len;
...@@ -2282,10 +2282,10 @@ pub const CType = extern union {...@@ -2282,10 +2282,10 @@ pub const CType = extern union {
2282 .payload => unreachable,2282 .payload => unreachable,
2283 };2283 };
22842284
2285 self.updateHasherRecurse(hasher, info.return_type.toType(), param_kind);2285 self.updateHasherRecurse(hasher, Type.fromInterned(info.return_type), param_kind);
2286 for (info.param_types.get(ip)) |param_type| {2286 for (info.param_types.get(ip)) |param_type| {
2287 if (!param_type.toType().hasRuntimeBitsIgnoreComptime(mod)) continue;2287 if (!Type.fromInterned(param_type).hasRuntimeBitsIgnoreComptime(mod)) continue;
2288 self.updateHasherRecurse(hasher, param_type.toType(), param_kind);2288 self.updateHasherRecurse(hasher, Type.fromInterned(param_type), param_kind);
2289 }2289 }
2290 },2290 },
22912291
src/codegen/llvm.zig+128-128
...@@ -1399,12 +1399,12 @@ pub const Object = struct {...@@ -1399,12 +1399,12 @@ pub const Object = struct {
1399 break :param param;1399 break :param param;
1400 } else .none;1400 } 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) {
1403 .signed => try attributes.addRetAttr(.signext, &o.builder),1403 .signed => try attributes.addRetAttr(.signext, &o.builder),
1404 .unsigned => try attributes.addRetAttr(.zeroext, &o.builder),1404 .unsigned => try attributes.addRetAttr(.zeroext, &o.builder),
1405 };1405 };
14061406
1407 const err_return_tracing = fn_info.return_type.toType().isError(mod) and1407 const err_return_tracing = Type.fromInterned(fn_info.return_type).isError(mod) and
1408 mod.comp.bin_file.options.error_return_tracing;1408 mod.comp.bin_file.options.error_return_tracing;
14091409
1410 const err_ret_trace: Builder.Value = if (err_return_tracing) param: {1410 const err_ret_trace: Builder.Value = if (err_return_tracing) param: {
...@@ -1430,7 +1430,7 @@ pub const Object = struct {...@@ -1430,7 +1430,7 @@ pub const Object = struct {
1430 .byval => {1430 .byval => {
1431 assert(!it.byval_attr);1431 assert(!it.byval_attr);
1432 const param_index = it.zig_index - 1;1432 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]);
1434 const param = wip.arg(llvm_arg_i);1434 const param = wip.arg(llvm_arg_i);
14351435
1436 if (isByRef(param_ty, mod)) {1436 if (isByRef(param_ty, mod)) {
...@@ -1447,7 +1447,7 @@ pub const Object = struct {...@@ -1447,7 +1447,7 @@ pub const Object = struct {
1447 llvm_arg_i += 1;1447 llvm_arg_i += 1;
1448 },1448 },
1449 .byref => {1449 .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]);
1451 const param_llvm_ty = try o.lowerType(param_ty);1451 const param_llvm_ty = try o.lowerType(param_ty);
1452 const param = wip.arg(llvm_arg_i);1452 const param = wip.arg(llvm_arg_i);
1453 const alignment = param_ty.abiAlignment(mod).toLlvm();1453 const alignment = param_ty.abiAlignment(mod).toLlvm();
...@@ -1462,7 +1462,7 @@ pub const Object = struct {...@@ -1462,7 +1462,7 @@ pub const Object = struct {
1462 }1462 }
1463 },1463 },
1464 .byref_mut => {1464 .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]);
1466 const param_llvm_ty = try o.lowerType(param_ty);1466 const param_llvm_ty = try o.lowerType(param_ty);
1467 const param = wip.arg(llvm_arg_i);1467 const param = wip.arg(llvm_arg_i);
1468 const alignment = param_ty.abiAlignment(mod).toLlvm();1468 const alignment = param_ty.abiAlignment(mod).toLlvm();
...@@ -1478,7 +1478,7 @@ pub const Object = struct {...@@ -1478,7 +1478,7 @@ pub const Object = struct {
1478 },1478 },
1479 .abi_sized_int => {1479 .abi_sized_int => {
1480 assert(!it.byval_attr);1480 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]);
1482 const param = wip.arg(llvm_arg_i);1482 const param = wip.arg(llvm_arg_i);
1483 llvm_arg_i += 1;1483 llvm_arg_i += 1;
14841484
...@@ -1494,7 +1494,7 @@ pub const Object = struct {...@@ -1494,7 +1494,7 @@ pub const Object = struct {
1494 },1494 },
1495 .slice => {1495 .slice => {
1496 assert(!it.byval_attr);1496 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]);
1498 const ptr_info = param_ty.ptrInfo(mod);1498 const ptr_info = param_ty.ptrInfo(mod);
14991499
1500 if (math.cast(u5, it.zig_index - 1)) |i| {1500 if (math.cast(u5, it.zig_index - 1)) |i| {
...@@ -1511,7 +1511,7 @@ pub const Object = struct {...@@ -1511,7 +1511,7 @@ pub const Object = struct {
1511 const elem_align = (if (ptr_info.flags.alignment != .none)1511 const elem_align = (if (ptr_info.flags.alignment != .none)
1512 @as(InternPool.Alignment, ptr_info.flags.alignment)1512 @as(InternPool.Alignment, ptr_info.flags.alignment)
1513 else1513 else
1514 ptr_info.child.toType().abiAlignment(mod).max(.@"1")).toLlvm();1514 Type.fromInterned(ptr_info.child).abiAlignment(mod).max(.@"1")).toLlvm();
1515 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);1515 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);
1516 const ptr_param = wip.arg(llvm_arg_i);1516 const ptr_param = wip.arg(llvm_arg_i);
1517 llvm_arg_i += 1;1517 llvm_arg_i += 1;
...@@ -1526,7 +1526,7 @@ pub const Object = struct {...@@ -1526,7 +1526,7 @@ pub const Object = struct {
1526 .multiple_llvm_types => {1526 .multiple_llvm_types => {
1527 assert(!it.byval_attr);1527 assert(!it.byval_attr);
1528 const field_types = it.types_buffer[0..it.types_len];1528 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]);
1530 const param_llvm_ty = try o.lowerType(param_ty);1530 const param_llvm_ty = try o.lowerType(param_ty);
1531 const param_alignment = param_ty.abiAlignment(mod).toLlvm();1531 const param_alignment = param_ty.abiAlignment(mod).toLlvm();
1532 const arg_ptr = try buildAllocaInner(&wip, false, param_llvm_ty, param_alignment, target);1532 const arg_ptr = try buildAllocaInner(&wip, false, param_llvm_ty, param_alignment, target);
...@@ -1553,7 +1553,7 @@ pub const Object = struct {...@@ -1553,7 +1553,7 @@ pub const Object = struct {
1553 args.appendAssumeCapacity(try wip.cast(.bitcast, param, .half, ""));1553 args.appendAssumeCapacity(try wip.cast(.bitcast, param, .half, ""));
1554 },1554 },
1555 .float_array => {1555 .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]);
1557 const param_llvm_ty = try o.lowerType(param_ty);1557 const param_llvm_ty = try o.lowerType(param_ty);
1558 const param = wip.arg(llvm_arg_i);1558 const param = wip.arg(llvm_arg_i);
1559 llvm_arg_i += 1;1559 llvm_arg_i += 1;
...@@ -1568,7 +1568,7 @@ pub const Object = struct {...@@ -1568,7 +1568,7 @@ pub const Object = struct {
1568 try wip.load(.normal, param_llvm_ty, arg_ptr, alignment, ""));1568 try wip.load(.normal, param_llvm_ty, arg_ptr, alignment, ""));
1569 },1569 },
1570 .i32_array, .i64_array => {1570 .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]);
1572 const param_llvm_ty = try o.lowerType(param_ty);1572 const param_llvm_ty = try o.lowerType(param_ty);
1573 const param = wip.arg(llvm_arg_i);1573 const param = wip.arg(llvm_arg_i);
1574 llvm_arg_i += 1;1574 llvm_arg_i += 1;
...@@ -1819,7 +1819,7 @@ pub const Object = struct {...@@ -1819,7 +1819,7 @@ pub const Object = struct {
1819 const llvm_addr_space = toLlvmAddressSpace(.generic, o.target);1819 const llvm_addr_space = toLlvmAddressSpace(.generic, o.target);
1820 const variable_index = try o.builder.addVariable(1820 const variable_index = try o.builder.addVariable(
1821 main_exp_name,1821 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))),
1823 llvm_addr_space,1823 llvm_addr_space,
1824 );1824 );
1825 const global_index = variable_index.ptrConst(&o.builder).global;1825 const global_index = variable_index.ptrConst(&o.builder).global;
...@@ -1961,7 +1961,7 @@ pub const Object = struct {...@@ -1961,7 +1961,7 @@ pub const Object = struct {
1961 resolve: DebugResolveStatus,1961 resolve: DebugResolveStatus,
1962 opt_fwd_decl: ?*llvm.DIType,1962 opt_fwd_decl: ?*llvm.DIType,
1963 ) Allocator.Error!*llvm.DIType {1963 ) Allocator.Error!*llvm.DIType {
1964 const ty = gop.key_ptr.toType();1964 const ty = Type.fromInterned(gop.key_ptr.*);
1965 const gpa = o.gpa;1965 const gpa = o.gpa;
1966 const target = o.target;1966 const target = o.target;
1967 const dib = o.di_builder.?;1967 const dib = o.di_builder.?;
...@@ -2004,7 +2004,7 @@ pub const Object = struct {...@@ -2004,7 +2004,7 @@ pub const Object = struct {
2004 const enumerators = try gpa.alloc(*llvm.DIEnumerator, enum_type.names.len);2004 const enumerators = try gpa.alloc(*llvm.DIEnumerator, enum_type.names.len);
2005 defer gpa.free(enumerators);2005 defer gpa.free(enumerators);
20062006
2007 const int_ty = enum_type.tag_ty.toType();2007 const int_ty = Type.fromInterned(enum_type.tag_ty);
2008 const int_info = ty.intInfo(mod);2008 const int_info = ty.intInfo(mod);
2009 assert(int_info.bits != 0);2009 assert(int_info.bits != 0);
20102010
...@@ -2013,7 +2013,7 @@ pub const Object = struct {...@@ -2013,7 +2013,7 @@ pub const Object = struct {
20132013
2014 var bigint_space: Value.BigIntSpace = undefined;2014 var bigint_space: Value.BigIntSpace = undefined;
2015 const bigint = if (enum_type.values.len != 0)2015 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)
2017 else2017 else
2018 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();2018 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
20192019
...@@ -2083,10 +2083,10 @@ pub const Object = struct {...@@ -2083,10 +2083,10 @@ pub const Object = struct {
2083 ptr_info.flags.is_const or2083 ptr_info.flags.is_const or
2084 ptr_info.flags.is_volatile or2084 ptr_info.flags.is_volatile or
2085 ptr_info.flags.size == .Many or ptr_info.flags.size == .C or2085 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))
2087 {2087 {
2088 const bland_ptr_ty = try mod.ptrType(.{2088 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))
2090 .anyopaque_type2090 .anyopaque_type
2091 else2091 else
2092 ptr_info.child,2092 ptr_info.child,
...@@ -2183,7 +2183,7 @@ pub const Object = struct {...@@ -2183,7 +2183,7 @@ pub const Object = struct {
2183 return full_di_ty;2183 return full_di_ty;
2184 }2184 }
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);
2187 const name = try o.allocTypeName(ty);2187 const name = try o.allocTypeName(ty);
2188 defer gpa.free(name);2188 defer gpa.free(name);
2189 const ptr_di_ty = dib.createPointerType(2189 const ptr_di_ty = dib.createPointerType(
...@@ -2456,7 +2456,7 @@ pub const Object = struct {...@@ -2456,7 +2456,7 @@ pub const Object = struct {
2456 if (mod.typeToPackedStruct(ty)) |struct_type| {2456 if (mod.typeToPackedStruct(ty)) |struct_type| {
2457 const backing_int_ty = struct_type.backingIntType(ip).*;2457 const backing_int_ty = struct_type.backingIntType(ip).*;
2458 if (backing_int_ty != .none) {2458 if (backing_int_ty != .none) {
2459 const info = backing_int_ty.toType().intInfo(mod);2459 const info = Type.fromInterned(backing_int_ty).intInfo(mod);
2460 const dwarf_encoding: c_uint = switch (info.signedness) {2460 const dwarf_encoding: c_uint = switch (info.signedness) {
2461 .signed => DW.ATE.signed,2461 .signed => DW.ATE.signed,
2462 .unsigned => DW.ATE.unsigned,2462 .unsigned => DW.ATE.unsigned,
...@@ -2492,10 +2492,10 @@ pub const Object = struct {...@@ -2492,10 +2492,10 @@ pub const Object = struct {
2492 var offset: u64 = 0;2492 var offset: u64 = 0;
24932493
2494 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {2494 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);2497 const field_size = Type.fromInterned(field_ty).abiSize(mod);
2498 const field_align = field_ty.toType().abiAlignment(mod);2498 const field_align = Type.fromInterned(field_ty).abiAlignment(mod);
2499 const field_offset = field_align.forward(offset);2499 const field_offset = field_align.forward(offset);
2500 offset = field_offset + field_size;2500 offset = field_offset + field_size;
25012501
...@@ -2514,7 +2514,7 @@ pub const Object = struct {...@@ -2514,7 +2514,7 @@ pub const Object = struct {
2514 field_align.toByteUnits(0) * 8, // align in bits2514 field_align.toByteUnits(0) * 8, // align in bits
2515 field_offset * 8, // offset in bits2515 field_offset * 8, // offset in bits
2516 0, // flags2516 0, // flags
2517 try o.lowerDebugType(field_ty.toType(), .full),2517 try o.lowerDebugType(Type.fromInterned(field_ty), .full),
2518 ));2518 ));
2519 }2519 }
25202520
...@@ -2579,7 +2579,7 @@ pub const Object = struct {...@@ -2579,7 +2579,7 @@ pub const Object = struct {
2579 comptime assert(struct_layout_version == 2);2579 comptime assert(struct_layout_version == 2);
2580 var it = struct_type.iterateRuntimeOrder(ip);2580 var it = struct_type.iterateRuntimeOrder(ip);
2581 while (it.next()) |field_index| {2581 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]);
2583 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;2583 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
2584 const field_size = field_ty.abiSize(mod);2584 const field_size = field_ty.abiSize(mod);
2585 const field_align = mod.structFieldAlignment(2585 const field_align = mod.structFieldAlignment(
...@@ -2661,7 +2661,7 @@ pub const Object = struct {...@@ -2661,7 +2661,7 @@ pub const Object = struct {
2661 const layout = mod.getUnionLayout(union_obj);2661 const layout = mod.getUnionLayout(union_obj);
26622662
2663 if (layout.payload_size == 0) {2663 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);
2665 const di_fields = [_]*llvm.DIType{tag_di_ty};2665 const di_fields = [_]*llvm.DIType{tag_di_ty};
2666 const full_di_ty = dib.createStructType(2666 const full_di_ty = dib.createStructType(
2667 compile_unit_scope,2667 compile_unit_scope,
...@@ -2692,12 +2692,12 @@ pub const Object = struct {...@@ -2692,12 +2692,12 @@ pub const Object = struct {
26922692
2693 for (0..union_obj.field_names.len) |field_index| {2693 for (0..union_obj.field_names.len) |field_index| {
2694 const field_ty = union_obj.field_types.get(ip)[field_index];2694 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);
2698 const field_align = mod.unionFieldNormalAlignment(union_obj, @intCast(field_index));2698 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);
2701 const field_name = union_obj.field_names.get(ip)[field_index];2701 const field_name = union_obj.field_names.get(ip)[field_index];
2702 di_fields.appendAssumeCapacity(dib.createMemberType(2702 di_fields.appendAssumeCapacity(dib.createMemberType(
2703 fwd_decl.toScope(),2703 fwd_decl.toScope(),
...@@ -2759,7 +2759,7 @@ pub const Object = struct {...@@ -2759,7 +2759,7 @@ pub const Object = struct {
2759 layout.tag_align.toByteUnits(0) * 8,2759 layout.tag_align.toByteUnits(0) * 8,
2760 tag_offset * 8, // offset in bits2760 tag_offset * 8, // offset in bits
2761 0, // flags2761 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),
2763 );2763 );
27642764
2765 const payload_di = dib.createMemberType(2765 const payload_di = dib.createMemberType(
...@@ -2807,20 +2807,20 @@ pub const Object = struct {...@@ -2807,20 +2807,20 @@ pub const Object = struct {
2807 defer param_di_types.deinit();2807 defer param_di_types.deinit();
28082808
2809 // Return type goes first.2809 // Return type goes first.
2810 if (fn_info.return_type.toType().hasRuntimeBitsIgnoreComptime(mod)) {2810 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(mod)) {
2811 const sret = firstParamSRet(fn_info, mod);2811 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);
2813 try param_di_types.append(try o.lowerDebugType(di_ret_ty, .full));2813 try param_di_types.append(try o.lowerDebugType(di_ret_ty, .full));
28142814
2815 if (sret) {2815 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));
2817 try param_di_types.append(try o.lowerDebugType(ptr_ty, .full));2817 try param_di_types.append(try o.lowerDebugType(ptr_ty, .full));
2818 }2818 }
2819 } else {2819 } else {
2820 try param_di_types.append(try o.lowerDebugType(Type.void, .full));2820 try param_di_types.append(try o.lowerDebugType(Type.void, .full));
2821 }2821 }
28222822
2823 if (fn_info.return_type.toType().isError(mod) and2823 if (Type.fromInterned(fn_info.return_type).isError(mod) and
2824 o.module.comp.bin_file.options.error_return_tracing)2824 o.module.comp.bin_file.options.error_return_tracing)
2825 {2825 {
2826 const ptr_ty = try mod.singleMutPtrType(try o.getStackTraceType());2826 const ptr_ty = try mod.singleMutPtrType(try o.getStackTraceType());
...@@ -2828,7 +2828,7 @@ pub const Object = struct {...@@ -2828,7 +2828,7 @@ pub const Object = struct {
2828 }2828 }
28292829
2830 for (0..fn_info.param_types.len) |i| {2830 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]);
2832 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;2832 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
28332833
2834 if (isByRef(param_ty, mod)) {2834 if (isByRef(param_ty, mod)) {
...@@ -2982,13 +2982,13 @@ pub const Object = struct {...@@ -2982,13 +2982,13 @@ pub const Object = struct {
2982 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);2982 try attributes.addParamAttr(llvm_arg_i, .nonnull, &o.builder);
2983 try attributes.addParamAttr(llvm_arg_i, .@"noalias", &o.builder);2983 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));
2986 try attributes.addParamAttr(llvm_arg_i, .{ .sret = raw_llvm_ret_ty }, &o.builder);2986 try attributes.addParamAttr(llvm_arg_i, .{ .sret = raw_llvm_ret_ty }, &o.builder);
29872987
2988 llvm_arg_i += 1;2988 llvm_arg_i += 1;
2989 }2989 }
29902990
2991 const err_return_tracing = fn_info.return_type.toType().isError(mod) and2991 const err_return_tracing = Type.fromInterned(fn_info.return_type).isError(mod) and
2992 mod.comp.bin_file.options.error_return_tracing;2992 mod.comp.bin_file.options.error_return_tracing;
29932993
2994 if (err_return_tracing) {2994 if (err_return_tracing) {
...@@ -3022,15 +3022,15 @@ pub const Object = struct {...@@ -3022,15 +3022,15 @@ pub const Object = struct {
3022 while (try it.next()) |lowering| switch (lowering) {3022 while (try it.next()) |lowering| switch (lowering) {
3023 .byval => {3023 .byval => {
3024 const param_index = it.zig_index - 1;3024 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]);
3026 if (!isByRef(param_ty, mod)) {3026 if (!isByRef(param_ty, mod)) {
3027 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);3027 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
3028 }3028 }
3029 },3029 },
3030 .byref => {3030 .byref => {
3031 const param_ty = fn_info.param_types.get(ip)[it.zig_index - 1];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.toType());3032 const param_llvm_ty = try o.lowerType(param_ty);
3033 const alignment = param_ty.toType().abiAlignment(mod);3033 const alignment = param_ty.abiAlignment(mod);
3034 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty);3034 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment.toLlvm(), it.byval_attr, param_llvm_ty);
3035 },3035 },
3036 .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder),3036 .byref_mut => try attributes.addParamAttr(it.llvm_index - 1, .noundef, &o.builder),
...@@ -3138,7 +3138,7 @@ pub const Object = struct {...@@ -3138,7 +3138,7 @@ pub const Object = struct {
31383138
3139 const variable_index = try o.builder.addVariable(3139 const variable_index = try o.builder.addVariable(
3140 try o.builder.fmt("__anon_{d}", .{@intFromEnum(decl_val)}),3140 try o.builder.fmt("__anon_{d}", .{@intFromEnum(decl_val)}),
3141 try o.lowerType(decl_ty.toType()),3141 try o.lowerType(Type.fromInterned(decl_ty)),
3142 llvm_addr_space,3142 llvm_addr_space,
3143 );3143 );
3144 gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;3144 gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
...@@ -3328,23 +3328,23 @@ pub const Object = struct {...@@ -3328,23 +3328,23 @@ pub const Object = struct {
3328 },3328 },
3329 .array_type => |array_type| o.builder.arrayType(3329 .array_type => |array_type| o.builder.arrayType(
3330 array_type.len + @intFromBool(array_type.sentinel != .none),3330 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)),
3332 ),3332 ),
3333 .vector_type => |vector_type| o.builder.vectorType(3333 .vector_type => |vector_type| o.builder.vectorType(
3334 .normal,3334 .normal,
3335 vector_type.len,3335 vector_type.len,
3336 try o.lowerType(vector_type.child.toType()),3336 try o.lowerType(Type.fromInterned(vector_type.child)),
3337 ),3337 ),
3338 .opt_type => |child_ty| {3338 .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));
3342 if (t.optionalReprIsPayload(mod)) return payload_ty;3342 if (t.optionalReprIsPayload(mod)) return payload_ty;
33433343
3344 comptime assert(optional_layout_version == 3);3344 comptime assert(optional_layout_version == 3);
3345 var fields: [3]Builder.Type = .{ payload_ty, .i8, undefined };3345 var fields: [3]Builder.Type = .{ payload_ty, .i8, undefined };
3346 var fields_len: usize = 2;3346 var fields_len: usize = 2;
3347 const offset = child_ty.toType().abiSize(mod) + 1;3347 const offset = Type.fromInterned(child_ty).abiSize(mod) + 1;
3348 const abi_size = t.abiSize(mod);3348 const abi_size = t.abiSize(mod);
3349 const padding_len = abi_size - offset;3349 const padding_len = abi_size - offset;
3350 if (padding_len > 0) {3350 if (padding_len > 0) {
...@@ -3356,15 +3356,15 @@ pub const Object = struct {...@@ -3356,15 +3356,15 @@ pub const Object = struct {
3356 .anyframe_type => @panic("TODO implement lowerType for AnyFrame types"),3356 .anyframe_type => @panic("TODO implement lowerType for AnyFrame types"),
3357 .error_union_type => |error_union_type| {3357 .error_union_type => |error_union_type| {
3358 const error_type = try o.errorIntType();3358 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))
3360 return error_type;3360 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));
3362 const err_int_ty = try mod.errorIntType();3362 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);
3365 const error_align = err_int_ty.abiAlignment(mod);3365 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);
3368 const error_size = err_int_ty.abiSize(mod);3368 const error_size = err_int_ty.abiSize(mod);
33693369
3370 var fields: [3]Builder.Type = undefined;3370 var fields: [3]Builder.Type = undefined;
...@@ -3398,7 +3398,7 @@ pub const Object = struct {...@@ -3398,7 +3398,7 @@ pub const Object = struct {
3398 if (gop.found_existing) return gop.value_ptr.*;3398 if (gop.found_existing) return gop.value_ptr.*;
33993399
3400 if (struct_type.layout == .Packed) {3400 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).*));
3402 gop.value_ptr.* = int_ty;3402 gop.value_ptr.* = int_ty;
3403 return int_ty;3403 return int_ty;
3404 }3404 }
...@@ -3423,7 +3423,7 @@ pub const Object = struct {...@@ -3423,7 +3423,7 @@ pub const Object = struct {
3423 // 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).3423 // 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).
3424 var it = struct_type.iterateRuntimeOrder(ip);3424 var it = struct_type.iterateRuntimeOrder(ip);
3425 while (it.next()) |field_index| {3425 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]);
3427 const field_align = mod.structFieldAlignment(3427 const field_align = mod.structFieldAlignment(
3428 struct_type.fieldAlign(ip, field_index),3428 struct_type.fieldAlign(ip, field_index),
3429 field_ty,3429 field_ty,
...@@ -3499,7 +3499,7 @@ pub const Object = struct {...@@ -3499,7 +3499,7 @@ pub const Object = struct {
3499 ) |field_ty, field_val, field_index| {3499 ) |field_ty, field_val, field_index| {
3500 if (field_val != .none) continue;3500 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);
3503 big_align = big_align.max(field_align);3503 big_align = big_align.max(field_align);
3504 const prev_offset = offset;3504 const prev_offset = offset;
3505 offset = field_align.forward(offset);3505 offset = field_align.forward(offset);
...@@ -3509,7 +3509,7 @@ pub const Object = struct {...@@ -3509,7 +3509,7 @@ pub const Object = struct {
3509 o.gpa,3509 o.gpa,
3510 try o.builder.arrayType(padding_len, .i8),3510 try o.builder.arrayType(padding_len, .i8),
3511 );3511 );
3512 if (!field_ty.toType().hasRuntimeBitsIgnoreComptime(mod)) {3512 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) {
3513 // This is a zero-bit field. If there are runtime bits after this field,3513 // This is a zero-bit field. If there are runtime bits after this field,
3514 // map to the next LLVM field (which we know exists): otherwise, don't3514 // map to the next LLVM field (which we know exists): otherwise, don't
3515 // map the field, indicating it's at the end of the struct.3515 // map the field, indicating it's at the end of the struct.
...@@ -3525,9 +3525,9 @@ pub const Object = struct {...@@ -3525,9 +3525,9 @@ pub const Object = struct {
3525 .struct_ty = t.toIntern(),3525 .struct_ty = t.toIntern(),
3526 .field_index = @intCast(field_index),3526 .field_index = @intCast(field_index),
3527 }, @intCast(llvm_field_types.items.len));3527 }, @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);
3531 }3531 }
3532 {3532 {
3533 const prev_offset = offset;3533 const prev_offset = offset;
...@@ -3554,7 +3554,7 @@ pub const Object = struct {...@@ -3554,7 +3554,7 @@ pub const Object = struct {
3554 }3554 }
35553555
3556 if (layout.payload_size == 0) {3556 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));
3558 gop.value_ptr.* = enum_tag_ty;3558 gop.value_ptr.* = enum_tag_ty;
3559 return enum_tag_ty;3559 return enum_tag_ty;
3560 }3560 }
...@@ -3565,7 +3565,7 @@ pub const Object = struct {...@@ -3565,7 +3565,7 @@ pub const Object = struct {
3565 const ty = try o.builder.opaqueType(name);3565 const ty = try o.builder.opaqueType(name);
3566 gop.value_ptr.* = ty; // must be done before any recursive calls3566 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]);
3569 const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty);3569 const aligned_field_llvm_ty = try o.lowerType(aligned_field_ty);
35703570
3571 const payload_ty = ty: {3571 const payload_ty = ty: {
...@@ -3589,7 +3589,7 @@ pub const Object = struct {...@@ -3589,7 +3589,7 @@ pub const Object = struct {
3589 );3589 );
3590 return ty;3590 return ty;
3591 }3591 }
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
3594 // Put the tag before or after the payload depending on which one's3594 // Put the tag before or after the payload depending on which one's
3595 // alignment is greater.3595 // alignment is greater.
...@@ -3624,7 +3624,7 @@ pub const Object = struct {...@@ -3624,7 +3624,7 @@ pub const Object = struct {
3624 }3624 }
3625 return gop.value_ptr.*;3625 return gop.value_ptr.*;
3626 },3626 },
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)),
3628 .func_type => |func_type| try o.lowerTypeFn(func_type),3628 .func_type => |func_type| try o.lowerTypeFn(func_type),
3629 .error_set_type, .inferred_error_set_type => try o.errorIntType(),3629 .error_set_type, .inferred_error_set_type => try o.errorIntType(),
3630 // values, not types3630 // values, not types
...@@ -3678,7 +3678,7 @@ pub const Object = struct {...@@ -3678,7 +3678,7 @@ pub const Object = struct {
3678 try llvm_params.append(o.gpa, .ptr);3678 try llvm_params.append(o.gpa, .ptr);
3679 }3679 }
36803680
3681 if (fn_info.return_type.toType().isError(mod) and3681 if (Type.fromInterned(fn_info.return_type).isError(mod) and
3682 mod.comp.bin_file.options.error_return_tracing)3682 mod.comp.bin_file.options.error_return_tracing)
3683 {3683 {
3684 const ptr_ty = try mod.singleMutPtrType(try o.getStackTraceType());3684 const ptr_ty = try mod.singleMutPtrType(try o.getStackTraceType());
...@@ -3689,20 +3689,20 @@ pub const Object = struct {...@@ -3689,20 +3689,20 @@ pub const Object = struct {
3689 while (try it.next()) |lowering| switch (lowering) {3689 while (try it.next()) |lowering| switch (lowering) {
3690 .no_bits => continue,3690 .no_bits => continue,
3691 .byval => {3691 .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]);
3693 try llvm_params.append(o.gpa, try o.lowerType(param_ty));3693 try llvm_params.append(o.gpa, try o.lowerType(param_ty));
3694 },3694 },
3695 .byref, .byref_mut => {3695 .byref, .byref_mut => {
3696 try llvm_params.append(o.gpa, .ptr);3696 try llvm_params.append(o.gpa, .ptr);
3697 },3697 },
3698 .abi_sized_int => {3698 .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]);
3700 try llvm_params.append(o.gpa, try o.builder.intType(3700 try llvm_params.append(o.gpa, try o.builder.intType(
3701 @intCast(param_ty.abiSize(mod) * 8),3701 @intCast(param_ty.abiSize(mod) * 8),
3702 ));3702 ));
3703 },3703 },
3704 .slice => {3704 .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]);
3706 try llvm_params.appendSlice(o.gpa, &.{3706 try llvm_params.appendSlice(o.gpa, &.{
3707 try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(mod), target)),3707 try o.builder.ptrType(toLlvmAddressSpace(param_ty.ptrAddressSpace(mod), target)),
3708 try o.lowerType(Type.usize),3708 try o.lowerType(Type.usize),
...@@ -3715,7 +3715,7 @@ pub const Object = struct {...@@ -3715,7 +3715,7 @@ pub const Object = struct {
3715 try llvm_params.append(o.gpa, .i16);3715 try llvm_params.append(o.gpa, .i16);
3716 },3716 },
3717 .float_array => |count| {3717 .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]);
3719 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(param_ty, mod).?);3719 const float_ty = try o.lowerType(aarch64_c_abi.getFloatArrayType(param_ty, mod).?);
3720 try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty));3720 try llvm_params.append(o.gpa, try o.builder.arrayType(count, float_ty));
3721 },3721 },
...@@ -3740,14 +3740,14 @@ pub const Object = struct {...@@ -3740,14 +3740,14 @@ pub const Object = struct {
3740 const ip = &mod.intern_pool;3740 const ip = &mod.intern_pool;
3741 const target = mod.getTarget();3741 const target = mod.getTarget();
37423742
3743 const val = arg_val.toValue();3743 const val = Value.fromInterned(arg_val);
3744 const val_key = ip.indexToKey(val.toIntern());3744 const val_key = ip.indexToKey(val.toIntern());
37453745
3746 if (val.isUndefDeep(mod)) {3746 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())));
3748 }3748 }
37493749
3750 const ty = val_key.typeOf().toType();3750 const ty = Type.fromInterned(val_key.typeOf());
3751 return switch (val_key) {3751 return switch (val_key) {
3752 .int_type,3752 .int_type,
3753 .ptr_type,3753 .ptr_type,
...@@ -4064,9 +4064,9 @@ pub const Object = struct {...@@ -4064,9 +4064,9 @@ pub const Object = struct {
4064 0..,4064 0..,
4065 ) |field_ty, field_val, field_index| {4065 ) |field_ty, field_val, field_index| {
4066 if (field_val != .none) continue;4066 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);
4070 big_align = big_align.max(field_align);4070 big_align = big_align.max(field_align);
4071 const prev_offset = offset;4071 const prev_offset = offset;
4072 offset = field_align.forward(offset);4072 offset = field_align.forward(offset);
...@@ -4088,7 +4088,7 @@ pub const Object = struct {...@@ -4088,7 +4088,7 @@ pub const Object = struct {
4088 need_unnamed = true;4088 need_unnamed = true;
4089 llvm_index += 1;4089 llvm_index += 1;
40904090
4091 offset += field_ty.toType().abiSize(mod);4091 offset += Type.fromInterned(field_ty).abiSize(mod);
4092 }4092 }
4093 {4093 {
4094 const prev_offset = offset;4094 const prev_offset = offset;
...@@ -4116,14 +4116,14 @@ pub const Object = struct {...@@ -4116,14 +4116,14 @@ pub const Object = struct {
4116 var running_int = try o.builder.intConst(struct_ty, 0);4116 var running_int = try o.builder.intConst(struct_ty, 0);
4117 var running_bits: u16 = 0;4117 var running_bits: u16 = 0;
4118 for (struct_type.field_types.get(ip), 0..) |field_ty, field_index| {4118 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
4121 const non_int_val =4121 const non_int_val =
4122 try o.lowerValue((try val.fieldValue(mod, field_index)).toIntern());4122 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));
4124 const small_int_ty = try o.builder.intType(ty_bit_size);4124 const small_int_ty = try o.builder.intType(ty_bit_size);
4125 const small_int_val = try o.builder.castConst(4125 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,
4127 non_int_val,4127 non_int_val,
4128 small_int_ty,4128 small_int_ty,
4129 );4129 );
...@@ -4159,7 +4159,7 @@ pub const Object = struct {...@@ -4159,7 +4159,7 @@ pub const Object = struct {
4159 var need_unnamed = false;4159 var need_unnamed = false;
4160 var field_it = struct_type.iterateRuntimeOrder(ip);4160 var field_it = struct_type.iterateRuntimeOrder(ip);
4161 while (field_it.next()) |field_index| {4161 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]);
4163 const field_align = mod.structFieldAlignment(4163 const field_align = mod.structFieldAlignment(
4164 struct_type.fieldAlign(ip, field_index),4164 struct_type.fieldAlign(ip, field_index),
4165 field_ty,4165 field_ty,
...@@ -4225,8 +4225,8 @@ pub const Object = struct {...@@ -4225,8 +4225,8 @@ pub const Object = struct {
42254225
4226 var need_unnamed = false;4226 var need_unnamed = false;
4227 const payload = if (un.tag != .none) p: {4227 const payload = if (un.tag != .none) p: {
4228 const field_index = mod.unionTagFieldIndex(union_obj, un.tag.toValue()).?;4228 const field_index = mod.unionTagFieldIndex(union_obj, Value.fromInterned(un.tag)).?;
4229 const field_ty = union_obj.field_types.get(ip)[field_index].toType();4229 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
4230 if (container_layout == .Packed) {4230 if (container_layout == .Packed) {
4231 if (!field_ty.hasRuntimeBits(mod)) return o.builder.intConst(union_ty, 0);4231 if (!field_ty.hasRuntimeBits(mod)) return o.builder.intConst(union_ty, 0);
4232 const small_int_val = try o.builder.castConst(4232 const small_int_val = try o.builder.castConst(
...@@ -4313,7 +4313,7 @@ pub const Object = struct {...@@ -4313,7 +4313,7 @@ pub const Object = struct {
4313 .undef => return o.builder.undefConst(.ptr),4313 .undef => return o.builder.undefConst(.ptr),
4314 .int => {4314 .int => {
4315 var bigint_space: Value.BigIntSpace = undefined;4315 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);
4317 const llvm_int = try lowerBigInt(o, Type.usize, bigint);4317 const llvm_int = try lowerBigInt(o, Type.usize, bigint);
4318 return o.builder.castConst(.inttoptr, llvm_int, .ptr);4318 return o.builder.castConst(.inttoptr, llvm_int, .ptr);
4319 },4319 },
...@@ -4345,12 +4345,12 @@ pub const Object = struct {...@@ -4345,12 +4345,12 @@ pub const Object = struct {
4345 return switch (ptr.addr) {4345 return switch (ptr.addr) {
4346 .decl => |decl| try o.lowerParentPtrDecl(decl),4346 .decl => |decl| try o.lowerParentPtrDecl(decl),
4347 .mut_decl => |mut_decl| try o.lowerParentPtrDecl(mut_decl.decl),4347 .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),
4349 .int => |int| try o.lowerIntAsPtr(int),4349 .int => |int| try o.lowerIntAsPtr(int),
4350 .eu_payload => |eu_ptr| {4350 .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);
4354 const payload_ty = eu_ty.errorUnionPayload(mod);4354 const payload_ty = eu_ty.errorUnionPayload(mod);
4355 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {4355 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
4356 // In this case, we represent pointer to error union the same as pointer4356 // In this case, we represent pointer to error union the same as pointer
...@@ -4367,9 +4367,9 @@ pub const Object = struct {...@@ -4367,9 +4367,9 @@ pub const Object = struct {
4367 });4367 });
4368 },4368 },
4369 .opt_payload => |opt_ptr| {4369 .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);
4373 const payload_ty = opt_ty.optionalChild(mod);4373 const payload_ty = opt_ty.optionalChild(mod);
4374 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod) or4374 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod) or
4375 payload_ty.optionalReprIsPayload(mod))4375 payload_ty.optionalReprIsPayload(mod))
...@@ -4385,16 +4385,16 @@ pub const Object = struct {...@@ -4385,16 +4385,16 @@ pub const Object = struct {
4385 },4385 },
4386 .comptime_field => unreachable,4386 .comptime_field => unreachable,
4387 .elem => |elem_ptr| {4387 .elem => |elem_ptr| {
4388 const parent_ptr = try o.lowerParentPtr(elem_ptr.base.toValue());4388 const parent_ptr = try o.lowerParentPtr(Value.fromInterned(elem_ptr.base));
4389 const elem_ty = ip.typeOf(elem_ptr.base).toType().elemType2(mod);4389 const elem_ty = Type.fromInterned(ip.typeOf(elem_ptr.base)).elemType2(mod);
43904390
4391 return o.builder.gepConst(.inbounds, try o.lowerType(elem_ty), parent_ptr, null, &.{4391 return o.builder.gepConst(.inbounds, try o.lowerType(elem_ty), parent_ptr, null, &.{
4392 try o.builder.intConst(try o.lowerType(Type.usize), elem_ptr.index),4392 try o.builder.intConst(try o.lowerType(Type.usize), elem_ptr.index),
4393 });4393 });
4394 },4394 },
4395 .field => |field_ptr| {4395 .field => |field_ptr| {
4396 const parent_ptr = try o.lowerParentPtr(field_ptr.base.toValue());4396 const parent_ptr = try o.lowerParentPtr(Value.fromInterned(field_ptr.base));
4397 const parent_ptr_ty = ip.typeOf(field_ptr.base).toType();4397 const parent_ptr_ty = Type.fromInterned(ip.typeOf(field_ptr.base));
4398 const parent_ty = parent_ptr_ty.childType(mod);4398 const parent_ty = parent_ptr_ty.childType(mod);
4399 const field_index: u32 = @intCast(field_ptr.index);4399 const field_index: u32 = @intCast(field_ptr.index);
4400 switch (parent_ty.zigTypeTag(mod)) {4400 switch (parent_ty.zigTypeTag(mod)) {
...@@ -4420,7 +4420,7 @@ pub const Object = struct {...@@ -4420,7 +4420,7 @@ pub const Object = struct {
4420 },4420 },
4421 .Struct => {4421 .Struct => {
4422 if (mod.typeToPackedStruct(parent_ty)) |struct_type| {4422 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);
4424 if (ptr_info.packed_offset.host_size != 0) return parent_ptr;4424 if (ptr_info.packed_offset.host_size != 0) return parent_ptr;
44254425
4426 const parent_ptr_info = parent_ptr_ty.ptrInfo(mod);4426 const parent_ptr_info = parent_ptr_ty.ptrInfo(mod);
...@@ -4470,13 +4470,13 @@ pub const Object = struct {...@@ -4470,13 +4470,13 @@ pub const Object = struct {
4470 const mod = o.module;4470 const mod = o.module;
4471 const ip = &mod.intern_pool;4471 const ip = &mod.intern_pool;
4472 const decl_val = anon_decl.val;4472 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));
4474 const target = mod.getTarget();4474 const target = mod.getTarget();
44754475
4476 if (decl_val.toValue().getFunction(mod)) |func| {4476 if (Value.fromInterned(decl_val).getFunction(mod)) |func| {
4477 _ = func;4477 _ = func;
4478 @panic("TODO");4478 @panic("TODO");
4479 } else if (decl_val.toValue().getExternFunc(mod)) |func| {4479 } else if (Value.fromInterned(decl_val).getExternFunc(mod)) |func| {
4480 _ = func;4480 _ = func;
4481 @panic("TODO");4481 @panic("TODO");
4482 }4482 }
...@@ -4488,7 +4488,7 @@ pub const Object = struct {...@@ -4488,7 +4488,7 @@ pub const Object = struct {
4488 if (is_fn_body)4488 if (is_fn_body)
4489 @panic("TODO");4489 @panic("TODO");
44904490
4491 const orig_ty = anon_decl.orig_ty.toType();4491 const orig_ty = Type.fromInterned(anon_decl.orig_ty);
4492 const llvm_addr_space = toLlvmAddressSpace(orig_ty.ptrAddressSpace(mod), target);4492 const llvm_addr_space = toLlvmAddressSpace(orig_ty.ptrAddressSpace(mod), target);
4493 const alignment = orig_ty.ptrAlignment(mod);4493 const alignment = orig_ty.ptrAlignment(mod);
4494 const llvm_global = (try o.resolveGlobalAnonDecl(decl_val, llvm_addr_space, alignment)).ptrConst(&o.builder).global;4494 const llvm_global = (try o.resolveGlobalAnonDecl(decl_val, llvm_addr_space, alignment)).ptrConst(&o.builder).global;
...@@ -4620,7 +4620,7 @@ pub const Object = struct {...@@ -4620,7 +4620,7 @@ pub const Object = struct {
4620 const elem_align = if (ptr_info.flags.alignment != .none)4620 const elem_align = if (ptr_info.flags.alignment != .none)
4621 ptr_info.flags.alignment4621 ptr_info.flags.alignment
4622 else4622 else
4623 ptr_info.child.toType().abiAlignment(mod).max(.@"1");4623 Type.fromInterned(ptr_info.child).abiAlignment(mod).max(.@"1");
4624 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align.toLlvm() }, &o.builder);4624 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align.toLlvm() }, &o.builder);
4625 } else if (ccAbiPromoteInt(fn_info.cc, mod, param_ty)) |s| switch (s) {4625 } else if (ccAbiPromoteInt(fn_info.cc, mod, param_ty)) |s| switch (s) {
4626 .signed => try attributes.addParamAttr(llvm_arg_i, .signext, &o.builder),4626 .signed => try attributes.addParamAttr(llvm_arg_i, .signext, &o.builder),
...@@ -4835,8 +4835,8 @@ pub const FuncGen = struct {...@@ -4835,8 +4835,8 @@ pub const FuncGen = struct {
4835 if (o.null_opt_usize == .no_init) {4835 if (o.null_opt_usize == .no_init) {
4836 const ty = try mod.intern(.{ .opt_type = .usize_type });4836 const ty = try mod.intern(.{ .opt_type = .usize_type });
4837 o.null_opt_usize = try self.resolveValue(.{4837 o.null_opt_usize = try self.resolveValue(.{
4838 .ty = ty.toType(),4838 .ty = Type.fromInterned(ty),
4839 .val = (try mod.intern(.{ .opt = .{ .ty = ty, .val = .none } })).toValue(),4839 .val = Value.fromInterned((try mod.intern(.{ .opt = .{ .ty = ty, .val = .none } }))),
4840 });4840 });
4841 }4841 }
4842 return o.null_opt_usize;4842 return o.null_opt_usize;
...@@ -5116,7 +5116,7 @@ pub const FuncGen = struct {...@@ -5116,7 +5116,7 @@ pub const FuncGen = struct {
5116 else => unreachable,5116 else => unreachable,
5117 };5117 };
5118 const fn_info = mod.typeToFunc(zig_fn_ty).?;5118 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);
5120 const llvm_fn = try self.resolveInst(pl_op.operand);5120 const llvm_fn = try self.resolveInst(pl_op.operand);
5121 const target = mod.getTarget();5121 const target = mod.getTarget();
5122 const sret = firstParamSRet(fn_info, mod);5122 const sret = firstParamSRet(fn_info, mod);
...@@ -5296,14 +5296,14 @@ pub const FuncGen = struct {...@@ -5296,14 +5296,14 @@ pub const FuncGen = struct {
5296 while (try it.next()) |lowering| switch (lowering) {5296 while (try it.next()) |lowering| switch (lowering) {
5297 .byval => {5297 .byval => {
5298 const param_index = it.zig_index - 1;5298 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]);
5300 if (!isByRef(param_ty, mod)) {5300 if (!isByRef(param_ty, mod)) {
5301 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);5301 try o.addByValParamAttrs(&attributes, param_ty, param_index, fn_info, it.llvm_index - 1);
5302 }5302 }
5303 },5303 },
5304 .byref => {5304 .byref => {
5305 const param_index = it.zig_index - 1;5305 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]);
5307 const param_llvm_ty = try o.lowerType(param_ty);5307 const param_llvm_ty = try o.lowerType(param_ty);
5308 const alignment = param_ty.abiAlignment(mod).toLlvm();5308 const alignment = param_ty.abiAlignment(mod).toLlvm();
5309 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);5309 try o.addByRefParamAttrs(&attributes, it.llvm_index - 1, alignment, it.byval_attr, param_llvm_ty);
...@@ -5321,7 +5321,7 @@ pub const FuncGen = struct {...@@ -5321,7 +5321,7 @@ pub const FuncGen = struct {
53215321
5322 .slice => {5322 .slice => {
5323 assert(!it.byval_attr);5323 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]);
5325 const ptr_info = param_ty.ptrInfo(mod);5325 const ptr_info = param_ty.ptrInfo(mod);
5326 const llvm_arg_i = it.llvm_index - 2;5326 const llvm_arg_i = it.llvm_index - 2;
53275327
...@@ -5339,7 +5339,7 @@ pub const FuncGen = struct {...@@ -5339,7 +5339,7 @@ pub const FuncGen = struct {
5339 const elem_align = (if (ptr_info.flags.alignment != .none)5339 const elem_align = (if (ptr_info.flags.alignment != .none)
5340 @as(InternPool.Alignment, ptr_info.flags.alignment)5340 @as(InternPool.Alignment, ptr_info.flags.alignment)
5341 else5341 else
5342 ptr_info.child.toType().abiAlignment(mod).max(.@"1")).toLlvm();5342 Type.fromInterned(ptr_info.child).abiAlignment(mod).max(.@"1")).toLlvm();
5343 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);5343 try attributes.addParamAttr(llvm_arg_i, .{ .@"align" = elem_align }, &o.builder);
5344 },5344 },
5345 };5345 };
...@@ -5471,7 +5471,7 @@ pub const FuncGen = struct {...@@ -5471,7 +5471,7 @@ pub const FuncGen = struct {
5471 }5471 }
5472 const fn_info = mod.typeToFunc(self.dg.decl.ty).?;5472 const fn_info = mod.typeToFunc(self.dg.decl.ty).?;
5473 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {5473 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
5474 if (fn_info.return_type.toType().isError(mod)) {5474 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
5475 // Functions with an empty error set are emitted with an error code5475 // Functions with an empty error set are emitted with an error code
5476 // return type and return zero so they can be function pointers coerced5476 // return type and return zero so they can be function pointers coerced
5477 // to functions that return anyerror.5477 // to functions that return anyerror.
...@@ -5513,7 +5513,7 @@ pub const FuncGen = struct {...@@ -5513,7 +5513,7 @@ pub const FuncGen = struct {
5513 const ret_ty = ptr_ty.childType(mod);5513 const ret_ty = ptr_ty.childType(mod);
5514 const fn_info = mod.typeToFunc(self.dg.decl.ty).?;5514 const fn_info = mod.typeToFunc(self.dg.decl.ty).?;
5515 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {5515 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
5516 if (fn_info.return_type.toType().isError(mod)) {5516 if (Type.fromInterned(fn_info.return_type).isError(mod)) {
5517 // Functions with an empty error set are emitted with an error code5517 // Functions with an empty error set are emitted with an error code
5518 // return type and return zero so they can be function pointers coerced5518 // return type and return zero so they can be function pointers coerced
5519 // to functions that return anyerror.5519 // to functions that return anyerror.
...@@ -8866,7 +8866,7 @@ pub const FuncGen = struct {...@@ -8866,7 +8866,7 @@ pub const FuncGen = struct {
8866 const ptr = try fg.resolveInst(ty_op.operand);8866 const ptr = try fg.resolveInst(ty_op.operand);
88678867
8868 elide: {8868 elide: {
8869 if (!isByRef(ptr_info.child.toType(), mod)) break :elide;8869 if (!isByRef(Type.fromInterned(ptr_info.child), mod)) break :elide;
8870 if (!canElideLoad(fg, body_tail)) break :elide;8870 if (!canElideLoad(fg, body_tail)) break :elide;
8871 return ptr;8871 return ptr;
8872 }8872 }
...@@ -9040,14 +9040,14 @@ pub const FuncGen = struct {...@@ -9040,14 +9040,14 @@ pub const FuncGen = struct {
9040 const ptr = try self.resolveInst(atomic_load.ptr);9040 const ptr = try self.resolveInst(atomic_load.ptr);
9041 const ptr_ty = self.typeOf(atomic_load.ptr);9041 const ptr_ty = self.typeOf(atomic_load.ptr);
9042 const info = ptr_ty.ptrInfo(mod);9042 const info = ptr_ty.ptrInfo(mod);
9043 const elem_ty = info.child.toType();9043 const elem_ty = Type.fromInterned(info.child);
9044 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;9044 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;
9045 const ordering = toLlvmAtomicOrdering(atomic_load.order);9045 const ordering = toLlvmAtomicOrdering(atomic_load.order);
9046 const llvm_abi_ty = try o.getAtomicAbiType(elem_ty, false);9046 const llvm_abi_ty = try o.getAtomicAbiType(elem_ty, false);
9047 const ptr_alignment = (if (info.flags.alignment != .none)9047 const ptr_alignment = (if (info.flags.alignment != .none)
9048 @as(InternPool.Alignment, info.flags.alignment)9048 @as(InternPool.Alignment, info.flags.alignment)
9049 else9049 else
9050 info.child.toType().abiAlignment(mod)).toLlvm();9050 Type.fromInterned(info.child).abiAlignment(mod)).toLlvm();
9051 const access_kind: Builder.MemoryAccessKind =9051 const access_kind: Builder.MemoryAccessKind =
9052 if (info.flags.is_volatile) .@"volatile" else .normal;9052 if (info.flags.is_volatile) .@"volatile" else .normal;
9053 const elem_llvm_ty = try o.lowerType(elem_ty);9053 const elem_llvm_ty = try o.lowerType(elem_ty);
...@@ -9500,7 +9500,7 @@ pub const FuncGen = struct {...@@ -9500,7 +9500,7 @@ pub const FuncGen = struct {
95009500
9501 const fqn = try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod);9501 const fqn = try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod);
9502 const function_index = try o.builder.addFunction(9502 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),
9504 try o.builder.fmt("__zig_is_named_enum_value_{}", .{fqn.fmt(&mod.intern_pool)}),9504 try o.builder.fmt("__zig_is_named_enum_value_{}", .{fqn.fmt(&mod.intern_pool)}),
9505 toLlvmAddressSpace(.generic, mod.getTarget()),9505 toLlvmAddressSpace(.generic, mod.getTarget()),
9506 );9506 );
...@@ -9573,7 +9573,7 @@ pub const FuncGen = struct {...@@ -9573,7 +9573,7 @@ pub const FuncGen = struct {
9573 const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0);9573 const ret_ty = try o.lowerType(Type.slice_const_u8_sentinel_0);
9574 const fqn = try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod);9574 const fqn = try mod.declPtr(enum_type.decl).getFullyQualifiedName(mod);
9575 const function_index = try o.builder.addFunction(9575 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),
9577 try o.builder.fmt("__zig_tag_name_{}", .{fqn.fmt(ip)}),9577 try o.builder.fmt("__zig_tag_name_{}", .{fqn.fmt(ip)}),
9578 toLlvmAddressSpace(.generic, mod.getTarget()),9578 toLlvmAddressSpace(.generic, mod.getTarget()),
9579 );9579 );
...@@ -9692,7 +9692,7 @@ pub const FuncGen = struct {...@@ -9692,7 +9692,7 @@ pub const FuncGen = struct {
9692 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;9692 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
9693 const a = try self.resolveInst(extra.a);9693 const a = try self.resolveInst(extra.a);
9694 const b = try self.resolveInst(extra.b);9694 const b = try self.resolveInst(extra.b);
9695 const mask = extra.mask.toValue();9695 const mask = Value.fromInterned(extra.mask);
9696 const mask_len = extra.mask_len;9696 const mask_len = extra.mask_len;
9697 const a_len = self.typeOf(extra.a).vectorLen(mod);9697 const a_len = self.typeOf(extra.a).vectorLen(mod);
96989698
...@@ -9928,18 +9928,18 @@ pub const FuncGen = struct {...@@ -9928,18 +9928,18 @@ pub const FuncGen = struct {
9928 if (mod.typeToPackedStruct(result_ty)) |struct_type| {9928 if (mod.typeToPackedStruct(result_ty)) |struct_type| {
9929 const backing_int_ty = struct_type.backingIntType(ip).*;9929 const backing_int_ty = struct_type.backingIntType(ip).*;
9930 assert(backing_int_ty != .none);9930 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);
9932 const int_ty = try o.builder.intType(@intCast(big_bits));9932 const int_ty = try o.builder.intType(@intCast(big_bits));
9933 comptime assert(Type.packed_struct_layout_version == 2);9933 comptime assert(Type.packed_struct_layout_version == 2);
9934 var running_int = try o.builder.intValue(int_ty, 0);9934 var running_int = try o.builder.intValue(int_ty, 0);
9935 var running_bits: u16 = 0;9935 var running_bits: u16 = 0;
9936 for (elements, struct_type.field_types.get(ip)) |elem, field_ty| {9936 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
9939 const non_int_val = try self.resolveInst(elem);9939 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));
9941 const small_int_ty = try o.builder.intType(ty_bit_size);9941 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))
9943 try self.wip.cast(.ptrtoint, non_int_val, small_int_ty, "")9943 try self.wip.cast(.ptrtoint, non_int_val, small_int_ty, "")
9944 else9944 else
9945 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");9945 try self.wip.cast(.bitcast, non_int_val, small_int_ty, "");
...@@ -10041,7 +10041,7 @@ pub const FuncGen = struct {...@@ -10041,7 +10041,7 @@ pub const FuncGen = struct {
10041 if (union_obj.getLayout(ip) == .Packed) {10041 if (union_obj.getLayout(ip) == .Packed) {
10042 const big_bits = union_ty.bitSize(mod);10042 const big_bits = union_ty.bitSize(mod);
10043 const int_llvm_ty = try o.builder.intType(@intCast(big_bits));10043 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]);
10045 const non_int_val = try self.resolveInst(extra.init);10045 const non_int_val = try self.resolveInst(extra.init);
10046 const small_int_ty = try o.builder.intType(@intCast(field_ty.bitSize(mod)));10046 const small_int_ty = try o.builder.intType(@intCast(field_ty.bitSize(mod)));
10047 const small_int_val = if (field_ty.isPtrAtRuntime(mod))10047 const small_int_val = if (field_ty.isPtrAtRuntime(mod))
...@@ -10074,7 +10074,7 @@ pub const FuncGen = struct {...@@ -10074,7 +10074,7 @@ pub const FuncGen = struct {
10074 const alignment = layout.abi_align.toLlvm();10074 const alignment = layout.abi_align.toLlvm();
10075 const result_ptr = try self.buildAllocaWorkaround(union_ty, alignment);10075 const result_ptr = try self.buildAllocaWorkaround(union_ty, alignment);
10076 const llvm_payload = try self.resolveInst(extra.init);10076 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]);
10078 const field_llvm_ty = try o.lowerType(field_ty);10078 const field_llvm_ty = try o.lowerType(field_ty);
10079 const field_size = field_ty.abiSize(mod);10079 const field_size = field_ty.abiSize(mod);
10080 const field_align = mod.unionFieldNormalAlignment(union_obj, extra.field_index);10080 const field_align = mod.unionFieldNormalAlignment(union_obj, extra.field_index);
...@@ -10097,7 +10097,7 @@ pub const FuncGen = struct {...@@ -10097,7 +10097,7 @@ pub const FuncGen = struct {
10097 });10097 });
10098 };10098 };
10099 if (layout.tag_size == 0) break :t try o.builder.structType(.normal, &.{payload_ty});10099 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));
10101 var fields: [3]Builder.Type = undefined;10101 var fields: [3]Builder.Type = undefined;
10102 var fields_len: usize = 2;10102 var fields_len: usize = 2;
10103 if (layout.tag_align.compare(.gte, layout.payload_align)) {10103 if (layout.tag_align.compare(.gte, layout.payload_align)) {
...@@ -10140,9 +10140,9 @@ pub const FuncGen = struct {...@@ -10140,9 +10140,9 @@ pub const FuncGen = struct {
10140 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));10140 const tag_index = @intFromBool(layout.tag_align.compare(.lt, layout.payload_align));
10141 const indices: [2]Builder.Value = .{ usize_zero, try o.builder.intValue(.i32, tag_index) };10141 const indices: [2]Builder.Value = .{ usize_zero, try o.builder.intValue(.i32, tag_index) };
10142 const field_ptr = try self.wip.gep(.inbounds, llvm_union_ty, result_ptr, &indices, "");10142 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));
10144 const llvm_tag = try o.builder.intValue(tag_ty, tag_int);10144 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();
10146 _ = try self.wip.store(.normal, llvm_tag, field_ptr, tag_alignment);10146 _ = try self.wip.store(.normal, llvm_tag, field_ptr, tag_alignment);
10147 }10147 }
1014810148
...@@ -10514,7 +10514,7 @@ pub const FuncGen = struct {...@@ -10514,7 +10514,7 @@ pub const FuncGen = struct {
10514 const o = self.dg.object;10514 const o = self.dg.object;
10515 const mod = o.module;10515 const mod = o.module;
10516 const info = ptr_ty.ptrInfo(mod);10516 const info = ptr_ty.ptrInfo(mod);
10517 const elem_ty = info.child.toType();10517 const elem_ty = Type.fromInterned(info.child);
10518 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;10518 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return .none;
1051910519
10520 const ptr_alignment = (if (info.flags.alignment != .none)10520 const ptr_alignment = (if (info.flags.alignment != .none)
...@@ -10586,7 +10586,7 @@ pub const FuncGen = struct {...@@ -10586,7 +10586,7 @@ pub const FuncGen = struct {
10586 const o = self.dg.object;10586 const o = self.dg.object;
10587 const mod = o.module;10587 const mod = o.module;
10588 const info = ptr_ty.ptrInfo(mod);10588 const info = ptr_ty.ptrInfo(mod);
10589 const elem_ty = info.child.toType();10589 const elem_ty = Type.fromInterned(info.child);
10590 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) {10590 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) {
10591 return;10591 return;
10592 }10592 }
...@@ -10926,7 +10926,7 @@ fn toLlvmGlobalAddressSpace(wanted_address_space: std.builtin.AddressSpace, targ...@@ -10926,7 +10926,7 @@ fn toLlvmGlobalAddressSpace(wanted_address_space: std.builtin.AddressSpace, targ
10926}10926}
1092710927
10928fn firstParamSRet(fn_info: InternPool.Key.FuncType, mod: *Module) bool {10928fn 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);
10930 if (!return_type.hasRuntimeBitsIgnoreComptime(mod)) return false;10930 if (!return_type.hasRuntimeBitsIgnoreComptime(mod)) return false;
1093110931
10932 const target = mod.getTarget();10932 const target = mod.getTarget();
...@@ -10967,7 +10967,7 @@ fn firstParamSRetSystemV(ty: Type, mod: *Module) bool {...@@ -10967,7 +10967,7 @@ fn firstParamSRetSystemV(ty: Type, mod: *Module) bool {
10967/// be effectively bitcasted to the actual return type.10967/// be effectively bitcasted to the actual return type.
10968fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {10968fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
10969 const mod = o.module;10969 const mod = o.module;
10970 const return_type = fn_info.return_type.toType();10970 const return_type = Type.fromInterned(fn_info.return_type);
10971 if (!return_type.hasRuntimeBitsIgnoreComptime(mod)) {10971 if (!return_type.hasRuntimeBitsIgnoreComptime(mod)) {
10972 // If the return type is an error set or an error union, then we make this10972 // If the return type is an error set or an error union, then we make this
10973 // anyerror return type instead, so that it can be coerced into a function10973 // 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...@@ -11051,7 +11051,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
1105111051
11052fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {11052fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
11053 const mod = o.module;11053 const mod = o.module;
11054 const return_type = fn_info.return_type.toType();11054 const return_type = Type.fromInterned(fn_info.return_type);
11055 switch (x86_64_abi.classifyWindows(return_type, mod)) {11055 switch (x86_64_abi.classifyWindows(return_type, mod)) {
11056 .integer => {11056 .integer => {
11057 if (isScalar(mod, return_type)) {11057 if (isScalar(mod, return_type)) {
...@@ -11070,7 +11070,7 @@ fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Err...@@ -11070,7 +11070,7 @@ fn lowerWin64FnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Err
11070fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {11070fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Builder.Type {
11071 const mod = o.module;11071 const mod = o.module;
11072 const ip = &mod.intern_pool;11072 const ip = &mod.intern_pool;
11073 const return_type = fn_info.return_type.toType();11073 const return_type = Type.fromInterned(fn_info.return_type);
11074 if (isScalar(mod, return_type)) {11074 if (isScalar(mod, return_type)) {
11075 return o.lowerType(return_type);11075 return o.lowerType(return_type);
11076 }11076 }
...@@ -11158,7 +11158,7 @@ const ParamTypeIterator = struct {...@@ -11158,7 +11158,7 @@ const ParamTypeIterator = struct {
11158 const ip = &mod.intern_pool;11158 const ip = &mod.intern_pool;
11159 const ty = it.fn_info.param_types.get(ip)[it.zig_index];11159 const ty = it.fn_info.param_types.get(ip)[it.zig_index];
11160 it.byval_attr = false;11160 it.byval_attr = false;
11161 return nextInner(it, ty.toType());11161 return nextInner(it, Type.fromInterned(ty));
11162 }11162 }
1116311163
11164 /// `airCall` uses this instead of `next` so that it can take into account variadic functions.11164 /// `airCall` uses this instead of `next` so that it can take into account variadic functions.
...@@ -11172,7 +11172,7 @@ const ParamTypeIterator = struct {...@@ -11172,7 +11172,7 @@ const ParamTypeIterator = struct {
11172 return nextInner(it, fg.typeOf(args[it.zig_index]));11172 return nextInner(it, fg.typeOf(args[it.zig_index]));
11173 }11173 }
11174 } else {11174 } 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]));
11176 }11176 }
11177 }11177 }
1117811178
...@@ -11503,11 +11503,11 @@ fn isByRef(ty: Type, mod: *Module) bool {...@@ -11503,11 +11503,11 @@ fn isByRef(ty: Type, mod: *Module) bool {
11503 .anon_struct_type => |tuple| {11503 .anon_struct_type => |tuple| {
11504 var count: usize = 0;11504 var count: usize = 0;
11505 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, field_val| {11505 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
11508 count += 1;11508 count += 1;
11509 if (count > max_fields_byval) return true;11509 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;
11511 }11511 }
11512 return false;11512 return false;
11513 },11513 },
...@@ -11524,7 +11524,7 @@ fn isByRef(ty: Type, mod: *Module) bool {...@@ -11524,7 +11524,7 @@ fn isByRef(ty: Type, mod: *Module) bool {
11524 while (it.next()) |field_index| {11524 while (it.next()) |field_index| {
11525 count += 1;11525 count += 1;
11526 if (count > max_fields_byval) return true;11526 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]);
11528 if (isByRef(field_ty, mod)) return true;11528 if (isByRef(field_ty, mod)) return true;
11529 }11529 }
11530 return false;11530 return false;
src/codegen/spirv.zig+47-47
...@@ -465,7 +465,7 @@ const DeclGen = struct {...@@ -465,7 +465,7 @@ const DeclGen = struct {
465 };465 };
466466
467 const mod = self.module;467 const mod = self.module;
468 const ty = mod.intern_pool.typeOf(val).toType();468 const ty = Type.fromInterned(mod.intern_pool.typeOf(val));
469 const ptr_ty_ref = try self.ptrType(ty, storage_class);469 const ptr_ty_ref = try self.ptrType(ty, storage_class);
470470
471 const var_id = self.spv.declPtr(spv_decl_index).result_id;471 const var_id = self.spv.declPtr(spv_decl_index).result_id;
...@@ -515,7 +515,7 @@ const DeclGen = struct {...@@ -515,7 +515,7 @@ const DeclGen = struct {
515 });515 });
516 self.current_block_label = root_block_id;516 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);
519 try self.func.body.emit(self.spv.gpa, .OpStore, .{519 try self.func.body.emit(self.spv.gpa, .OpStore, .{
520 .pointer = var_id,520 .pointer = var_id,
521 .object = val_id,521 .object = val_id,
...@@ -822,10 +822,10 @@ const DeclGen = struct {...@@ -822,10 +822,10 @@ const DeclGen = struct {
822 .payload => err_int_ty,822 .payload => err_int_ty,
823 };823 };
824 const err_val = switch (error_union.val) {824 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 = .{
826 .ty = ty.errorUnionSet(mod).toIntern(),826 .ty = ty.errorUnionSet(mod).toIntern(),
827 .name = err_name,827 .name = err_name,
828 } })).toValue(),828 } }))),
829 .payload => try mod.intValue(err_int_ty, 0),829 .payload => try mod.intValue(err_int_ty, 0),
830 };830 };
831 const payload_ty = ty.errorUnionPayload(mod);831 const payload_ty = ty.errorUnionPayload(mod);
...@@ -835,10 +835,10 @@ const DeclGen = struct {...@@ -835,10 +835,10 @@ const DeclGen = struct {
835 return try self.constant(err_ty, err_val, .indirect);835 return try self.constant(err_ty, err_val, .indirect);
836 }836 }
837837
838 const payload_val = switch (error_union.val) {838 const payload_val = Value.fromInterned(switch (error_union.val) {
839 .err_name => try mod.intern(.{ .undef = payload_ty.toIntern() }),839 .err_name => try mod.intern(.{ .undef = payload_ty.toIntern() }),
840 .payload => |payload| payload,840 .payload => |payload| payload,
841 }.toValue();841 });
842842
843 var constituents: [2]IdRef = undefined;843 var constituents: [2]IdRef = undefined;
844 var types: [2]Type = undefined;844 var types: [2]Type = undefined;
...@@ -869,7 +869,7 @@ const DeclGen = struct {...@@ -869,7 +869,7 @@ const DeclGen = struct {
869 return ptr_id;869 return ptr_id;
870 }870 }
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);
873 return try self.constructStruct(873 return try self.constructStruct(
874 ty,874 ty,
875 &.{ ptr_ty, Type.usize },875 &.{ ptr_ty, Type.usize },
...@@ -909,7 +909,7 @@ const DeclGen = struct {...@@ -909,7 +909,7 @@ const DeclGen = struct {
909 },909 },
910 .aggregate => |aggregate| switch (ip.indexToKey(ty.ip_index)) {910 .aggregate => |aggregate| switch (ip.indexToKey(ty.ip_index)) {
911 inline .array_type, .vector_type => |array_type, tag| {911 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);
913 const elem_ty_ref = try self.resolveType(elem_ty, .indirect);913 const elem_ty_ref = try self.resolveType(elem_ty, .indirect);
914914
915 const constituents = try self.gpa.alloc(IdRef, @as(u32, @intCast(ty.arrayLenIncludingSentinel(mod))));915 const constituents = try self.gpa.alloc(IdRef, @as(u32, @intCast(ty.arrayLenIncludingSentinel(mod))));
...@@ -925,11 +925,11 @@ const DeclGen = struct {...@@ -925,11 +925,11 @@ const DeclGen = struct {
925 },925 },
926 .elems => |elems| {926 .elems => |elems| {
927 for (0..@as(usize, @intCast(array_type.len))) |i| {927 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);
929 }929 }
930 },930 },
931 .repeated_elem => |elem| {931 .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);
933 for (0..@as(usize, @intCast(array_type.len))) |i| {933 for (0..@as(usize, @intCast(array_type.len))) |i| {
934 constituents[i] = val_id;934 constituents[i] = val_id;
935 }935 }
...@@ -938,7 +938,7 @@ const DeclGen = struct {...@@ -938,7 +938,7 @@ const DeclGen = struct {
938938
939 switch (tag) {939 switch (tag) {
940 inline .array_type => if (array_type.sentinel != .none) {940 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);
942 },942 },
943 else => {},943 else => {},
944 }944 }
...@@ -959,7 +959,7 @@ const DeclGen = struct {...@@ -959,7 +959,7 @@ const DeclGen = struct {
959959
960 var it = struct_type.iterateRuntimeOrder(ip);960 var it = struct_type.iterateRuntimeOrder(ip);
961 while (it.next()) |field_index| {961 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]);
963 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) {963 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) {
964 // This is a zero-bit field - we only needed it for the alignment.964 // This is a zero-bit field - we only needed it for the alignment.
965 continue;965 continue;
...@@ -979,11 +979,11 @@ const DeclGen = struct {...@@ -979,11 +979,11 @@ const DeclGen = struct {
979 else => unreachable,979 else => unreachable,
980 },980 },
981 .un => |un| {981 .un => |un| {
982 const active_field = ty.unionTagFieldIndex(un.tag.toValue(), mod).?;982 const active_field = ty.unionTagFieldIndex(Value.fromInterned(un.tag), mod).?;
983 const union_obj = mod.typeToUnion(ty).?;983 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]);
985 const payload = if (field_ty.hasRuntimeBitsIgnoreComptime(mod))985 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)
987 else987 else
988 null;988 null;
989 return try self.unionInit(ty, active_field, payload);989 return try self.unionInit(ty, active_field, payload);
...@@ -1007,7 +1007,7 @@ const DeclGen = struct {...@@ -1007,7 +1007,7 @@ const DeclGen = struct {
1007 try self.func.body.emit(self.spv.gpa, .OpConvertUToPtr, .{1007 try self.func.body.emit(self.spv.gpa, .OpConvertUToPtr, .{
1008 .id_result_type = self.typeId(result_ty_ref),1008 .id_result_type = self.typeId(result_ty_ref),
1009 .id_result = ptr_id,1009 .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),
1011 });1011 });
1012 return ptr_id;1012 return ptr_id;
1013 },1013 },
...@@ -1015,8 +1015,8 @@ const DeclGen = struct {...@@ -1015,8 +1015,8 @@ const DeclGen = struct {
1015 .opt_payload => unreachable, // TODO1015 .opt_payload => unreachable, // TODO
1016 .comptime_field => unreachable,1016 .comptime_field => unreachable,
1017 .elem => |elem_ptr| {1017 .elem => |elem_ptr| {
1018 const parent_ptr_ty = mod.intern_pool.typeOf(elem_ptr.base).toType();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, elem_ptr.base.toValue());1019 const parent_ptr_id = try self.constantPtr(parent_ptr_ty, Value.fromInterned(elem_ptr.base));
1020 const size_ty_ref = try self.sizeType();1020 const size_ty_ref = try self.sizeType();
1021 const index_id = try self.constInt(size_ty_ref, elem_ptr.index);1021 const index_id = try self.constInt(size_ty_ref, elem_ptr.index);
10221022
...@@ -1040,8 +1040,8 @@ const DeclGen = struct {...@@ -1040,8 +1040,8 @@ const DeclGen = struct {
1040 return result_id;1040 return result_id;
1041 },1041 },
1042 .field => |field| {1042 .field => |field| {
1043 const base_ptr_ty = mod.intern_pool.typeOf(field.base).toType();1043 const base_ptr_ty = Type.fromInterned(mod.intern_pool.typeOf(field.base));
1044 const base_ptr = try self.constantPtr(base_ptr_ty, field.base.toValue());1044 const base_ptr = try self.constantPtr(base_ptr_ty, Value.fromInterned(field.base));
1045 const field_index: u32 = @intCast(field.index);1045 const field_index: u32 = @intCast(field.index);
1046 return try self.structFieldPtr(ptr_ty, base_ptr_ty, base_ptr, field_index);1046 return try self.structFieldPtr(ptr_ty, base_ptr_ty, base_ptr, field_index);
1047 },1047 },
...@@ -1059,12 +1059,12 @@ const DeclGen = struct {...@@ -1059,12 +1059,12 @@ const DeclGen = struct {
1059 const ip = &mod.intern_pool;1059 const ip = &mod.intern_pool;
1060 const ty_ref = try self.resolveType(ty, .direct);1060 const ty_ref = try self.resolveType(ty, .direct);
1061 const decl_val = anon_decl.val;1061 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| {
1065 _ = func;1065 _ = func;
1066 unreachable; // TODO1066 unreachable; // TODO
1067 } else if (decl_val.toValue().getExternFunc(mod)) |func| {1067 } else if (Value.fromInterned(decl_val).getExternFunc(mod)) |func| {
1068 _ = func;1068 _ = func;
1069 unreachable;1069 unreachable;
1070 }1070 }
...@@ -1267,7 +1267,7 @@ const DeclGen = struct {...@@ -1267,7 +1267,7 @@ const DeclGen = struct {
1267 const layout = self.unionLayout(ty);1267 const layout = self.unionLayout(ty);
1268 if (!layout.has_payload) {1268 if (!layout.has_payload) {
1269 // No payload, so represent this as just the tag type.1269 // 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);
1271 }1271 }
12721272
1273 if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref;1273 if (self.type_map.get(ty.toIntern())) |info| return info.ty_ref;
...@@ -1278,7 +1278,7 @@ const DeclGen = struct {...@@ -1278,7 +1278,7 @@ const DeclGen = struct {
1278 const u8_ty_ref = try self.intType(.unsigned, 8); // TODO: What if Int8Type is not enabled?1278 const u8_ty_ref = try self.intType(.unsigned, 8); // TODO: What if Int8Type is not enabled?
12791279
1280 if (layout.tag_size != 0) {1280 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);
1282 member_types[layout.tag_index] = tag_ty_ref;1282 member_types[layout.tag_index] = tag_ty_ref;
1283 member_names[layout.tag_index] = try self.spv.resolveString("(tag)");1283 member_names[layout.tag_index] = try self.spv.resolveString("(tag)");
1284 }1284 }
...@@ -1430,13 +1430,13 @@ const DeclGen = struct {...@@ -1430,13 +1430,13 @@ const DeclGen = struct {
1430 defer self.gpa.free(param_ty_refs);1430 defer self.gpa.free(param_ty_refs);
1431 var param_index: usize = 0;1431 var param_index: usize = 0;
1432 for (fn_info.param_types.get(ip)) |param_ty_index| {1432 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);
1434 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;1434 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
14351435
1436 param_ty_refs[param_index] = try self.resolveType(param_ty, .direct);1436 param_ty_refs[param_index] = try self.resolveType(param_ty, .direct);
1437 param_index += 1;1437 param_index += 1;
1438 }1438 }
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
1441 const ty_ref = try self.spv.resolve(.{ .function_type = .{1441 const ty_ref = try self.spv.resolve(.{ .function_type = .{
1442 .return_type = return_ty_ref,1442 .return_type = return_ty_ref,
...@@ -1459,7 +1459,7 @@ const DeclGen = struct {...@@ -1459,7 +1459,7 @@ const DeclGen = struct {
1459 // in ptrType()!1459 // in ptrType()!
14601460
1461 const storage_class = spvStorageClass(ptr_info.flags.address_space);1461 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
1464 if (ptr_info.flags.size != .Slice) {1464 if (ptr_info.flags.size != .Slice) {
1465 return ptr_ty_ref;1465 return ptr_ty_ref;
...@@ -1494,9 +1494,9 @@ const DeclGen = struct {...@@ -1494,9 +1494,9 @@ const DeclGen = struct {
14941494
1495 var member_index: usize = 0;1495 var member_index: usize = 0;
1496 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, field_val| {1496 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);
1500 member_index += 1;1500 member_index += 1;
1501 }1501 }
15021502
...@@ -1513,7 +1513,7 @@ const DeclGen = struct {...@@ -1513,7 +1513,7 @@ const DeclGen = struct {
1513 };1513 };
15141514
1515 if (struct_type.layout == .Packed) {1515 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);
1517 }1517 }
15181518
1519 var member_types = std.ArrayList(CacheRef).init(self.gpa);1519 var member_types = std.ArrayList(CacheRef).init(self.gpa);
...@@ -1524,7 +1524,7 @@ const DeclGen = struct {...@@ -1524,7 +1524,7 @@ const DeclGen = struct {
15241524
1525 var it = struct_type.iterateRuntimeOrder(ip);1525 var it = struct_type.iterateRuntimeOrder(ip);
1526 while (it.next()) |field_index| {1526 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]);
1528 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) {1528 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) {
1529 // This is a zero-bit field - we only needed it for the alignment.1529 // This is a zero-bit field - we only needed it for the alignment.
1530 continue;1530 continue;
...@@ -1728,7 +1728,7 @@ const DeclGen = struct {...@@ -1728,7 +1728,7 @@ const DeclGen = struct {
17281728
1729 if (union_layout.has_payload) {1729 if (union_layout.has_payload) {
1730 const most_aligned_field = layout.most_aligned_field;1730 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]);
1732 union_layout.payload_ty = most_aligned_field_ty;1732 union_layout.payload_ty = most_aligned_field_ty;
1733 union_layout.payload_size = @intCast(most_aligned_field_ty.abiSize(mod));1733 union_layout.payload_size = @intCast(most_aligned_field_ty.abiSize(mod));
1734 } else {1734 } else {
...@@ -1855,7 +1855,7 @@ const DeclGen = struct {...@@ -1855,7 +1855,7 @@ const DeclGen = struct {
1855 if (decl.val.getFunction(mod)) |_| {1855 if (decl.val.getFunction(mod)) |_| {
1856 assert(decl.ty.zigTypeTag(mod) == .Fn);1856 assert(decl.ty.zigTypeTag(mod) == .Fn);
1857 const fn_info = mod.typeToFunc(decl.ty).?;1857 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
1860 const prototype_id = try self.resolveTypeId(decl.ty);1860 const prototype_id = try self.resolveTypeId(decl.ty);
1861 try self.func.prologue.emit(self.spv.gpa, .OpFunction, .{1861 try self.func.prologue.emit(self.spv.gpa, .OpFunction, .{
...@@ -1867,7 +1867,7 @@ const DeclGen = struct {...@@ -1867,7 +1867,7 @@ const DeclGen = struct {
18671867
1868 try self.args.ensureUnusedCapacity(self.gpa, fn_info.param_types.len);1868 try self.args.ensureUnusedCapacity(self.gpa, fn_info.param_types.len);
1869 for (fn_info.param_types.get(ip)) |param_ty_index| {1869 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);
1871 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;1871 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
18721872
1873 const param_type_id = try self.resolveTypeId(param_ty);1873 const param_type_id = try self.resolveTypeId(param_ty);
...@@ -1914,7 +1914,7 @@ const DeclGen = struct {...@@ -1914,7 +1914,7 @@ const DeclGen = struct {
1914 }1914 }
1915 } else {1915 } else {
1916 const init_val = if (decl.val.getVariable(mod)) |payload|1916 const init_val = if (decl.val.getVariable(mod)) |payload|
1917 payload.init.toValue()1917 Value.fromInterned(payload.init)
1918 else1918 else
1919 decl.val;1919 decl.val;
19201920
...@@ -2605,7 +2605,7 @@ const DeclGen = struct {...@@ -2605,7 +2605,7 @@ const DeclGen = struct {
2605 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;2605 const extra = self.air.extraData(Air.Shuffle, ty_pl.payload).data;
2606 const a = try self.resolve(extra.a);2606 const a = try self.resolve(extra.a);
2607 const b = try self.resolve(extra.b);2607 const b = try self.resolve(extra.b);
2608 const mask = extra.mask.toValue();2608 const mask = Value.fromInterned(extra.mask);
2609 const mask_len = extra.mask_len;2609 const mask_len = extra.mask_len;
2610 const a_len = self.typeOf(extra.a).vectorLen(mod);2610 const a_len = self.typeOf(extra.a).vectorLen(mod);
26112611
...@@ -3239,11 +3239,11 @@ const DeclGen = struct {...@@ -3239,11 +3239,11 @@ const DeclGen = struct {
3239 .anon_struct_type => |tuple| {3239 .anon_struct_type => |tuple| {
3240 for (tuple.types.get(ip), elements, 0..) |field_ty, element, i| {3240 for (tuple.types.get(ip), elements, 0..) |field_ty, element, i| {
3241 if ((try result_ty.structFieldValueComptime(mod, i)) != null) continue;3241 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
3244 const id = try self.resolve(element);3244 const id = try self.resolve(element);
3245 types[index] = field_ty.toType();3245 types[index] = Type.fromInterned(field_ty);
3246 constituents[index] = try self.convertToIndirect(field_ty.toType(), id);3246 constituents[index] = try self.convertToIndirect(Type.fromInterned(field_ty), id);
3247 index += 1;3247 index += 1;
3248 }3248 }
3249 },3249 },
...@@ -3252,7 +3252,7 @@ const DeclGen = struct {...@@ -3252,7 +3252,7 @@ const DeclGen = struct {
3252 for (elements, 0..) |element, i| {3252 for (elements, 0..) |element, i| {
3253 const field_index = it.next().?;3253 const field_index = it.next().?;
3254 if ((try result_ty.structFieldValueComptime(mod, i)) != null) continue;3254 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]);
3256 assert(field_ty.hasRuntimeBitsIgnoreComptime(mod));3256 assert(field_ty.hasRuntimeBitsIgnoreComptime(mod));
32573257
3258 const id = try self.resolve(element);3258 const id = try self.resolve(element);
...@@ -3527,7 +3527,7 @@ const DeclGen = struct {...@@ -3527,7 +3527,7 @@ const DeclGen = struct {
3527 try self.store(maybe_tag_ty.?, ptr_id, tag_id, .{});3527 try self.store(maybe_tag_ty.?, ptr_id, tag_id, .{});
3528 }3528 }
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]);
3531 if (payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {3531 if (payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
3532 const pl_ptr_ty_ref = try self.ptrType(layout.payload_ty, .Function);3532 const pl_ptr_ty_ref = try self.ptrType(layout.payload_ty, .Function);
3533 const pl_ptr_id = try self.accessChain(pl_ptr_ty_ref, tmp_id, &.{layout.payload_index});3533 const pl_ptr_id = try self.accessChain(pl_ptr_ty_ref, tmp_id, &.{layout.payload_index});
...@@ -3560,7 +3560,7 @@ const DeclGen = struct {...@@ -3560,7 +3560,7 @@ const DeclGen = struct {
3560 const ty = self.typeOfIndex(inst);3560 const ty = self.typeOfIndex(inst);
35613561
3562 const union_obj = mod.typeToUnion(ty).?;3562 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]);
3564 const payload = if (field_ty.hasRuntimeBitsIgnoreComptime(mod))3564 const payload = if (field_ty.hasRuntimeBitsIgnoreComptime(mod))
3565 try self.resolve(extra.init)3565 try self.resolve(extra.init)
3566 else3566 else
...@@ -4223,7 +4223,7 @@ const DeclGen = struct {...@@ -4223,7 +4223,7 @@ const DeclGen = struct {
4223 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {4223 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
4224 const decl = mod.declPtr(self.decl_index);4224 const decl = mod.declPtr(self.decl_index);
4225 const fn_info = mod.typeToFunc(decl.ty).?;4225 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)) {
4227 // Functions with an empty error set are emitted with an error code4227 // Functions with an empty error set are emitted with an error code
4228 // return type and return zero so they can be function pointers coerced4228 // return type and return zero so they can be function pointers coerced
4229 // to functions that return anyerror.4229 // to functions that return anyerror.
...@@ -4248,7 +4248,7 @@ const DeclGen = struct {...@@ -4248,7 +4248,7 @@ const DeclGen = struct {
4248 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {4248 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
4249 const decl = mod.declPtr(self.decl_index);4249 const decl = mod.declPtr(self.decl_index);
4250 const fn_info = mod.typeToFunc(decl.ty).?;4250 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)) {
4252 // Functions with an empty error set are emitted with an error code4252 // Functions with an empty error set are emitted with an error code
4253 // return type and return zero so they can be function pointers coerced4253 // return type and return zero so they can be function pointers coerced
4254 // to functions that return anyerror.4254 // to functions that return anyerror.
...@@ -4913,7 +4913,7 @@ const DeclGen = struct {...@@ -4913,7 +4913,7 @@ const DeclGen = struct {
4913 const fn_info = mod.typeToFunc(zig_fn_ty).?;4913 const fn_info = mod.typeToFunc(zig_fn_ty).?;
4914 const return_type = fn_info.return_type;4914 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));
4917 const result_id = self.spv.allocId();4917 const result_id = self.spv.allocId();
4918 const callee_id = try self.resolve(pl_op.operand);4918 const callee_id = try self.resolve(pl_op.operand);
49194919
...@@ -4944,7 +4944,7 @@ const DeclGen = struct {...@@ -4944,7 +4944,7 @@ const DeclGen = struct {
4944 try self.func.body.emit(self.spv.gpa, .OpUnreachable, {});4944 try self.func.body.emit(self.spv.gpa, .OpUnreachable, {});
4945 }4945 }
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)) {
4948 return null;4948 return null;
4949 }4949 }
49504950
src/link/C.zig+3-2
...@@ -13,6 +13,7 @@ const codegen = @import("../codegen/c.zig");...@@ -13,6 +13,7 @@ const codegen = @import("../codegen/c.zig");
13const link = @import("../link.zig");13const link = @import("../link.zig");
14const trace = @import("../tracy.zig").trace;14const trace = @import("../tracy.zig").trace;
15const Type = @import("../type.zig").Type;15const Type = @import("../type.zig").Type;
16const Value = @import("../value.zig").Value;
16const Air = @import("../Air.zig");17const Air = @import("../Air.zig");
17const Liveness = @import("../Liveness.zig");18const Liveness = @import("../Liveness.zig");
1819
...@@ -254,8 +255,8 @@ fn updateAnonDecl(self: *C, module: *Module, i: usize) !void {...@@ -254,8 +255,8 @@ fn updateAnonDecl(self: *C, module: *Module, i: usize) !void {
254 }255 }
255256
256 const tv: @import("../TypedValue.zig") = .{257 const tv: @import("../TypedValue.zig") = .{
257 .ty = module.intern_pool.typeOf(anon_decl).toType(),258 .ty = Type.fromInterned(module.intern_pool.typeOf(anon_decl)),
258 .val = anon_decl.toValue(),259 .val = Value.fromInterned(anon_decl),
259 };260 };
260 const c_value: codegen.CValue = .{ .constant = anon_decl };261 const c_value: codegen.CValue = .{ .constant = anon_decl };
261 const alignment: Alignment = self.aligned_anon_decls.get(anon_decl) orelse .none;262 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(...@@ -1189,7 +1189,7 @@ pub fn updateDecl(
1189 var code_buffer = std.ArrayList(u8).init(self.base.allocator);1189 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
1190 defer code_buffer.deinit();1190 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;
1193 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{1193 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
1194 .ty = decl.ty,1194 .ty = decl.ty,
1195 .val = decl_val,1195 .val = decl_val,
...@@ -1794,7 +1794,7 @@ pub fn lowerAnonDecl(...@@ -1794,7 +1794,7 @@ pub fn lowerAnonDecl(
1794) !codegen.Result {1794) !codegen.Result {
1795 const gpa = self.base.allocator;1795 const gpa = self.base.allocator;
1796 const mod = self.base.options.module.?;1796 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));
1798 const decl_alignment = switch (explicit_alignment) {1798 const decl_alignment = switch (explicit_alignment) {
1799 .none => ty.abiAlignment(mod),1799 .none => ty.abiAlignment(mod),
1800 else => explicit_alignment,1800 else => explicit_alignment,
...@@ -1805,7 +1805,7 @@ pub fn lowerAnonDecl(...@@ -1805,7 +1805,7 @@ pub fn lowerAnonDecl(
1805 return .ok;1805 return .ok;
1806 }1806 }
18071807
1808 const val = decl_val.toValue();1808 const val = Value.fromInterned(decl_val);
1809 const tv = TypedValue{ .ty = ty, .val = val };1809 const tv = TypedValue{ .ty = ty, .val = val };
1810 var name_buf: [32]u8 = undefined;1810 var name_buf: [32]u8 = undefined;
1811 const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{1811 const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{
...@@ -2669,6 +2669,7 @@ const Relocation = @import("Coff/Relocation.zig");...@@ -2669,6 +2669,7 @@ const Relocation = @import("Coff/Relocation.zig");
2669const TableSection = @import("table_section.zig").TableSection;2669const TableSection = @import("table_section.zig").TableSection;
2670const StringTable = @import("StringTable.zig");2670const StringTable = @import("StringTable.zig");
2671const Type = @import("../type.zig").Type;2671const Type = @import("../type.zig").Type;
2672const Value = @import("../value.zig").Value;
2672const TypedValue = @import("../TypedValue.zig");2673const TypedValue = @import("../TypedValue.zig");
26732674
2674pub const base_tag: link.File.Tag = .coff;2675pub const base_tag: link.File.Tag = .coff;
src/link/Dwarf.zig+9-9
...@@ -305,7 +305,7 @@ pub const DeclState = struct {...@@ -305,7 +305,7 @@ pub const DeclState = struct {
305 // DW.AT.type, DW.FORM.ref4305 // DW.AT.type, DW.FORM.ref4
306 const index = dbg_info_buffer.items.len;306 const index = dbg_info_buffer.items.len;
307 try dbg_info_buffer.resize(index + 4);307 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));
309 // DW.AT.data_member_location, DW.FORM.udata309 // DW.AT.data_member_location, DW.FORM.udata
310 const field_off = ty.structFieldOffset(field_index, mod);310 const field_off = ty.structFieldOffset(field_index, mod);
311 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);311 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);
...@@ -323,7 +323,7 @@ pub const DeclState = struct {...@@ -323,7 +323,7 @@ pub const DeclState = struct {
323323
324 if (struct_type.isTuple(ip)) {324 if (struct_type.isTuple(ip)) {
325 for (struct_type.field_types.get(ip), struct_type.offsets.get(ip), 0..) |field_ty, field_off, field_index| {325 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;
327 // DW.AT.member327 // DW.AT.member
328 try dbg_info_buffer.append(@intFromEnum(AbbrevKind.struct_member));328 try dbg_info_buffer.append(@intFromEnum(AbbrevKind.struct_member));
329 // DW.AT.name, DW.FORM.string329 // DW.AT.name, DW.FORM.string
...@@ -331,7 +331,7 @@ pub const DeclState = struct {...@@ -331,7 +331,7 @@ pub const DeclState = struct {
331 // DW.AT.type, DW.FORM.ref4331 // DW.AT.type, DW.FORM.ref4
332 const index = dbg_info_buffer.items.len;332 const index = dbg_info_buffer.items.len;
333 try dbg_info_buffer.resize(index + 4);333 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));
335 // DW.AT.data_member_location, DW.FORM.udata335 // DW.AT.data_member_location, DW.FORM.udata
336 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);336 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);
337 }337 }
...@@ -341,7 +341,7 @@ pub const DeclState = struct {...@@ -341,7 +341,7 @@ pub const DeclState = struct {
341 struct_type.field_types.get(ip),341 struct_type.field_types.get(ip),
342 struct_type.offsets.get(ip),342 struct_type.offsets.get(ip),
343 ) |field_name_ip, field_ty, field_off| {343 ) |field_name_ip, field_ty, field_off| {
344 if (!field_ty.toType().hasRuntimeBits(mod)) continue;344 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
345 const field_name = ip.stringToSlice(field_name_ip);345 const field_name = ip.stringToSlice(field_name_ip);
346 // DW.AT.member346 // DW.AT.member
347 try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2);347 try dbg_info_buffer.ensureUnusedCapacity(field_name.len + 2);
...@@ -352,7 +352,7 @@ pub const DeclState = struct {...@@ -352,7 +352,7 @@ pub const DeclState = struct {
352 // DW.AT.type, DW.FORM.ref4352 // DW.AT.type, DW.FORM.ref4
353 const index = dbg_info_buffer.items.len;353 const index = dbg_info_buffer.items.len;
354 try dbg_info_buffer.resize(index + 4);354 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));
356 // DW.AT.data_member_location, DW.FORM.udata356 // DW.AT.data_member_location, DW.FORM.udata
357 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);357 try leb128.writeULEB128(dbg_info_buffer.writer(), field_off);
358 }358 }
...@@ -389,7 +389,7 @@ pub const DeclState = struct {...@@ -389,7 +389,7 @@ pub const DeclState = struct {
389 const value = enum_type.values.get(ip)[field_i];389 const value = enum_type.values.get(ip)[field_i];
390 // TODO do not assume a 64bit enum value - could be bigger.390 // TODO do not assume a 64bit enum value - could be bigger.
391 // See https://github.com/ziglang/zig/issues/645391 // 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);
393 break :value @bitCast(field_int_val.toSignedInt(mod));393 break :value @bitCast(field_int_val.toSignedInt(mod));
394 };394 };
395 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), value, target_endian);395 mem.writeInt(u64, dbg_info_buffer.addManyAsArrayAssumeCapacity(8), value, target_endian);
...@@ -443,7 +443,7 @@ pub const DeclState = struct {...@@ -443,7 +443,7 @@ pub const DeclState = struct {
443 }443 }
444444
445 for (union_obj.field_types.get(ip), union_obj.field_names.get(ip)) |field_ty, field_name| {445 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;
447 // DW.AT.member447 // DW.AT.member
448 try dbg_info_buffer.append(@intFromEnum(AbbrevKind.struct_member));448 try dbg_info_buffer.append(@intFromEnum(AbbrevKind.struct_member));
449 // DW.AT.name, DW.FORM.string449 // DW.AT.name, DW.FORM.string
...@@ -452,7 +452,7 @@ pub const DeclState = struct {...@@ -452,7 +452,7 @@ pub const DeclState = struct {
452 // DW.AT.type, DW.FORM.ref4452 // DW.AT.type, DW.FORM.ref4
453 const index = dbg_info_buffer.items.len;453 const index = dbg_info_buffer.items.len;
454 try dbg_info_buffer.resize(index + 4);454 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));
456 // DW.AT.data_member_location, DW.FORM.udata456 // DW.AT.data_member_location, DW.FORM.udata
457 try dbg_info_buffer.append(0);457 try dbg_info_buffer.append(0);
458 }458 }
...@@ -469,7 +469,7 @@ pub const DeclState = struct {...@@ -469,7 +469,7 @@ pub const DeclState = struct {
469 // DW.AT.type, DW.FORM.ref4469 // DW.AT.type, DW.FORM.ref4
470 const index = dbg_info_buffer.items.len;470 const index = dbg_info_buffer.items.len;
471 try dbg_info_buffer.resize(index + 4);471 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));
473 // DW.AT.data_member_location, DW.FORM.udata473 // DW.AT.data_member_location, DW.FORM.udata
474 try leb128.writeULEB128(dbg_info_buffer.writer(), tag_offset);474 try leb128.writeULEB128(dbg_info_buffer.writer(), tag_offset);
475475
src/link/Elf/ZigObject.zig+6-4
...@@ -660,7 +660,7 @@ pub fn lowerAnonDecl(...@@ -660,7 +660,7 @@ pub fn lowerAnonDecl(
660) !codegen.Result {660) !codegen.Result {
661 const gpa = elf_file.base.allocator;661 const gpa = elf_file.base.allocator;
662 const mod = elf_file.base.options.module.?;662 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));
664 const decl_alignment = switch (explicit_alignment) {664 const decl_alignment = switch (explicit_alignment) {
665 .none => ty.abiAlignment(mod),665 .none => ty.abiAlignment(mod),
666 else => explicit_alignment,666 else => explicit_alignment,
...@@ -671,7 +671,7 @@ pub fn lowerAnonDecl(...@@ -671,7 +671,7 @@ pub fn lowerAnonDecl(
671 return .ok;671 return .ok;
672 }672 }
673673
674 const val = decl_val.toValue();674 const val = Value.fromInterned(decl_val);
675 const tv = TypedValue{ .ty = ty, .val = val };675 const tv = TypedValue{ .ty = ty, .val = val };
676 var name_buf: [32]u8 = undefined;676 var name_buf: [32]u8 = undefined;
677 const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{677 const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{
...@@ -835,7 +835,7 @@ fn getDeclShdrIndex(...@@ -835,7 +835,7 @@ fn getDeclShdrIndex(
835 });835 });
836 }836 }
837 if (variable.is_const) break :blk elf_file.zig_data_rel_ro_section_index.?;837 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)) {
839 const mode = elf_file.base.options.optimize_mode;839 const mode = elf_file.base.options.optimize_mode;
840 if (mode == .Debug or mode == .ReleaseSafe) break :blk elf_file.zig_data_section_index.?;840 if (mode == .Debug or mode == .ReleaseSafe) break :blk elf_file.zig_data_section_index.?;
841 break :blk elf_file.zig_bss_section_index.?;841 break :blk elf_file.zig_bss_section_index.?;
...@@ -1114,7 +1114,7 @@ pub fn updateDecl(...@@ -1114,7 +1114,7 @@ pub fn updateDecl(
1114 defer if (decl_state) |*ds| ds.deinit();1114 defer if (decl_state) |*ds| ds.deinit();
11151115
1116 // TODO implement .debug_info for global variables1116 // 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;
1118 const res = if (decl_state) |*ds|1118 const res = if (decl_state) |*ds|
1119 try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{1119 try codegen.generateSymbol(&elf_file.base, decl.srcLoc(mod), .{
1120 .ty = decl.ty,1120 .ty = decl.ty,
...@@ -1613,5 +1613,7 @@ const Module = @import("../../Module.zig");...@@ -1613,5 +1613,7 @@ const Module = @import("../../Module.zig");
1613const Object = @import("Object.zig");1613const Object = @import("Object.zig");
1614const Symbol = @import("Symbol.zig");1614const Symbol = @import("Symbol.zig");
1615const StringTable = @import("../StringTable.zig");1615const StringTable = @import("../StringTable.zig");
1616const Type = @import("../../type.zig").Type;
1617const Value = @import("../../value.zig").Value;
1616const TypedValue = @import("../../TypedValue.zig");1618const TypedValue = @import("../../TypedValue.zig");
1617const ZigObject = @This();1619const 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...@@ -2400,7 +2400,7 @@ pub fn updateDecl(self: *MachO, mod: *Module, decl_index: Module.Decl.Index) !vo
2400 null;2400 null;
2401 defer if (decl_state) |*ds| ds.deinit();2401 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;
2404 const res = if (decl_state) |*ds|2404 const res = if (decl_state) |*ds|
2405 try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{2405 try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
2406 .ty = decl.ty,2406 .ty = decl.ty,
...@@ -2569,7 +2569,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D...@@ -2569,7 +2569,7 @@ fn updateThreadlocalVariable(self: *MachO, module: *Module, decl_index: Module.D
25692569
2570 const decl = module.declPtr(decl_index);2570 const decl = module.declPtr(decl_index);
2571 const decl_metadata = self.decls.get(decl_index).?;2571 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);
2573 const res = if (decl_state) |*ds|2573 const res = if (decl_state) |*ds|
2574 try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{2574 try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
2575 .ty = decl.ty,2575 .ty = decl.ty,
...@@ -2995,7 +2995,7 @@ pub fn lowerAnonDecl(...@@ -2995,7 +2995,7 @@ pub fn lowerAnonDecl(
2995) !codegen.Result {2995) !codegen.Result {
2996 const gpa = self.base.allocator;2996 const gpa = self.base.allocator;
2997 const mod = self.base.options.module.?;2997 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));
2999 const decl_alignment = switch (explicit_alignment) {2999 const decl_alignment = switch (explicit_alignment) {
3000 .none => ty.abiAlignment(mod),3000 .none => ty.abiAlignment(mod),
3001 else => explicit_alignment,3001 else => explicit_alignment,
...@@ -3006,7 +3006,7 @@ pub fn lowerAnonDecl(...@@ -3006,7 +3006,7 @@ pub fn lowerAnonDecl(
3006 return .ok;3006 return .ok;
3007 }3007 }
30083008
3009 const val = decl_val.toValue();3009 const val = Value.fromInterned(decl_val);
3010 const tv = TypedValue{ .ty = ty, .val = val };3010 const tv = TypedValue{ .ty = ty, .val = val };
3011 var name_buf: [32]u8 = undefined;3011 var name_buf: [32]u8 = undefined;
3012 const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{3012 const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{
src/link/Plan9.zig+5-3
...@@ -13,6 +13,8 @@ const File = link.File;...@@ -13,6 +13,8 @@ const File = link.File;
13const build_options = @import("build_options");13const build_options = @import("build_options");
14const Air = @import("../Air.zig");14const Air = @import("../Air.zig");
15const Liveness = @import("../Liveness.zig");15const Liveness = @import("../Liveness.zig");
16const Type = @import("../type.zig").Type;
17const Value = @import("../value.zig").Value;
16const TypedValue = @import("../TypedValue.zig");18const TypedValue = @import("../TypedValue.zig");
1719
18const std = @import("std");20const std = @import("std");
...@@ -517,7 +519,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !vo...@@ -517,7 +519,7 @@ pub fn updateDecl(self: *Plan9, mod: *Module, decl_index: Module.Decl.Index) !vo
517519
518 var code_buffer = std.ArrayList(u8).init(self.base.allocator);520 var code_buffer = std.ArrayList(u8).init(self.base.allocator);
519 defer code_buffer.deinit();521 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;
521 // TODO we need the symbol index for symbol in the table of locals for the containing atom523 // TODO we need the symbol index for symbol in the table of locals for the containing atom
522 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{524 const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), .{
523 .ty = decl.ty,525 .ty = decl.ty,
...@@ -1492,8 +1494,8 @@ pub fn lowerAnonDecl(self: *Plan9, decl_val: InternPool.Index, src_loc: Module.S...@@ -1492,8 +1494,8 @@ pub fn lowerAnonDecl(self: *Plan9, decl_val: InternPool.Index, src_loc: Module.S
1492 const gop = try self.anon_decls.getOrPut(gpa, decl_val);1494 const gop = try self.anon_decls.getOrPut(gpa, decl_val);
1493 const mod = self.base.options.module.?;1495 const mod = self.base.options.module.?;
1494 if (!gop.found_existing) {1496 if (!gop.found_existing) {
1495 const ty = mod.intern_pool.typeOf(decl_val).toType();1497 const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val));
1496 const val = decl_val.toValue();1498 const val = Value.fromInterned(decl_val);
1497 const tv = TypedValue{ .ty = ty, .val = val };1499 const tv = TypedValue{ .ty = ty, .val = val };
1498 const name = try std.fmt.allocPrint(gpa, "__anon_{d}", .{@intFromEnum(decl_val)});1500 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");...@@ -23,6 +23,7 @@ const build_options = @import("build_options");
23const wasi_libc = @import("../wasi_libc.zig");23const wasi_libc = @import("../wasi_libc.zig");
24const Cache = std.Build.Cache;24const Cache = std.Build.Cache;
25const Type = @import("../type.zig").Type;25const Type = @import("../type.zig").Type;
26const Value = @import("../value.zig").Value;
26const TypedValue = @import("../TypedValue.zig");27const TypedValue = @import("../TypedValue.zig");
27const LlvmObject = @import("../codegen/llvm.zig").Object;28const LlvmObject = @import("../codegen/llvm.zig").Object;
28const Air = @import("../Air.zig");29const Air = @import("../Air.zig");
...@@ -1452,7 +1453,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi...@@ -1452,7 +1453,7 @@ pub fn updateDecl(wasm: *Wasm, mod: *Module, decl_index: Module.Decl.Index) !voi
1452 const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name);1453 const lib_name = mod.intern_pool.stringToSliceUnwrap(variable.lib_name);
1453 return wasm.addOrUpdateImport(name, atom.sym_index, lib_name, null);1454 return wasm.addOrUpdateImport(name, atom.sym_index, lib_name, null);
1454 }1455 }
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
1457 var code_writer = std.ArrayList(u8).init(wasm.base.allocator);1458 var code_writer = std.ArrayList(u8).init(wasm.base.allocator);
1458 defer code_writer.deinit();1459 defer code_writer.deinit();
...@@ -1719,8 +1720,8 @@ pub fn lowerAnonDecl(...@@ -1719,8 +1720,8 @@ pub fn lowerAnonDecl(
1719 const gop = try wasm.anon_decls.getOrPut(wasm.base.allocator, decl_val);1720 const gop = try wasm.anon_decls.getOrPut(wasm.base.allocator, decl_val);
1720 if (!gop.found_existing) {1721 if (!gop.found_existing) {
1721 const mod = wasm.base.options.module.?;1722 const mod = wasm.base.options.module.?;
1722 const ty = mod.intern_pool.typeOf(decl_val).toType();1723 const ty = Type.fromInterned(mod.intern_pool.typeOf(decl_val));
1723 const tv: TypedValue = .{ .ty = ty, .val = decl_val.toValue() };1724 const tv: TypedValue = .{ .ty = ty, .val = Value.fromInterned(decl_val) };
1724 var name_buf: [32]u8 = undefined;1725 var name_buf: [32]u8 = undefined;
1725 const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{1726 const name = std.fmt.bufPrint(&name_buf, "__anon_{d}", .{
1726 @intFromEnum(decl_val),1727 @intFromEnum(decl_val),
...@@ -1751,7 +1752,7 @@ pub fn getAnonDeclVAddr(wasm: *Wasm, decl_val: InternPool.Index, reloc_info: lin...@@ -1751,7 +1752,7 @@ pub fn getAnonDeclVAddr(wasm: *Wasm, decl_val: InternPool.Index, reloc_info: lin
1751 const parent_atom = wasm.getAtomPtr(parent_atom_index);1752 const parent_atom = wasm.getAtomPtr(parent_atom_index);
1752 const is_wasm32 = wasm.base.options.target.cpu.arch == .wasm32;1753 const is_wasm32 = wasm.base.options.target.cpu.arch == .wasm32;
1753 const mod = wasm.base.options.module.?;1754 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));
1755 if (ty.zigTypeTag(mod) == .Fn) {1756 if (ty.zigTypeTag(mod) == .Fn) {
1756 assert(reloc_info.addend == 0); // addend not allowed for function relocations1757 assert(reloc_info.addend == 0); // addend not allowed for function relocations
1757 // We found a function pointer, so add it to our table,1758 // 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...@@ -3533,7 +3534,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
3533 } else if (decl.getOwnedVariable(mod)) |variable| {3534 } else if (decl.getOwnedVariable(mod)) |variable| {
3534 if (variable.is_const) {3535 if (variable.is_const) {
3535 try wasm.parseAtom(atom_index, .{ .data = .read_only });3536 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)) {
3537 // for safe build modes, we store the atom in the data segment,3538 // for safe build modes, we store the atom in the data segment,
3538 // whereas for unsafe build modes we store it in bss.3539 // whereas for unsafe build modes we store it in bss.
3539 const is_initialized = wasm.base.options.optimize_mode == .Debug or3540 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...@@ -3558,7 +3559,7 @@ pub fn flushModule(wasm: *Wasm, comp: *Compilation, prog_node: *std.Progress.Nod
3558 }3559 }
3559 // parse anonymous declarations3560 // parse anonymous declarations
3560 for (wasm.anon_decls.keys(), wasm.anon_decls.values()) |decl_val, atom_index| {3561 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));
3562 if (ty.zigTypeTag(mod) == .Fn) {3563 if (ty.zigTypeTag(mod) == .Fn) {
3563 try wasm.parseAtom(atom_index, .function);3564 try wasm.parseAtom(atom_index, .function);
3564 } else {3565 } else {
src/print_air.zig+2-2
...@@ -940,10 +940,10 @@ const Writer = struct {...@@ -940,10 +940,10 @@ const Writer = struct {
940 return s.print("@{}", .{operand});940 return s.print("@{}", .{operand});
941 } else if (Air.refToInterned(operand)) |ip_index| {941 } else if (Air.refToInterned(operand)) |ip_index| {
942 const mod = w.module;942 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());
944 try s.print("<{}, {}>", .{944 try s.print("<{}, {}>", .{
945 ty.fmt(mod),945 ty.fmt(mod),
946 ip_index.toValue().fmtValue(ty, mod),946 Value.fromInterned(ip_index).fmtValue(ty, mod),
947 });947 });
948 } else {948 } else {
949 return w.writeInstIndex(s, Air.refToIndex(operand).?, dies);949 return w.writeInstIndex(s, Air.refToIndex(operand).?, dies);
src/type.zig+163-158
...@@ -185,8 +185,8 @@ pub const Type = struct {...@@ -185,8 +185,8 @@ pub const Type = struct {
185185
186 if (info.sentinel != .none) switch (info.flags.size) {186 if (info.sentinel != .none) switch (info.flags.size) {
187 .One, .C => unreachable,187 .One, .C => unreachable,
188 .Many => 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("[:{}]", .{info.sentinel.toValue().fmtValue(info.child.toType(), mod)}),189 .Slice => try writer.print("[:{}]", .{Value.fromInterned(info.sentinel).fmtValue(Type.fromInterned(info.child), mod)}),
190 } else switch (info.flags.size) {190 } else switch (info.flags.size) {
191 .One => try writer.writeAll("*"),191 .One => try writer.writeAll("*"),
192 .Many => try writer.writeAll("[*]"),192 .Many => try writer.writeAll("[*]"),
...@@ -200,7 +200,7 @@ pub const Type = struct {...@@ -200,7 +200,7 @@ pub const Type = struct {
200 const alignment = if (info.flags.alignment != .none)200 const alignment = if (info.flags.alignment != .none)
201 info.flags.alignment201 info.flags.alignment
202 else202 else
203 info.child.toType().abiAlignment(mod);203 Type.fromInterned(info.child).abiAlignment(mod);
204 try writer.print("align({d}", .{alignment.toByteUnits(0)});204 try writer.print("align({d}", .{alignment.toByteUnits(0)});
205205
206 if (info.packed_offset.bit_offset != 0 or info.packed_offset.host_size != 0) {206 if (info.packed_offset.bit_offset != 0 or info.packed_offset.host_size != 0) {
...@@ -222,36 +222,36 @@ pub const Type = struct {...@@ -222,36 +222,36 @@ pub const Type = struct {
222 if (info.flags.is_volatile) try writer.writeAll("volatile ");222 if (info.flags.is_volatile) try writer.writeAll("volatile ");
223 if (info.flags.is_allowzero and info.flags.size != .C) try writer.writeAll("allowzero ");223 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);
226 return;226 return;
227 },227 },
228 .array_type => |array_type| {228 .array_type => |array_type| {
229 if (array_type.sentinel == .none) {229 if (array_type.sentinel == .none) {
230 try writer.print("[{d}]", .{array_type.len});230 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);
232 } else {232 } else {
233 try writer.print("[{d}:{}]", .{233 try writer.print("[{d}:{}]", .{
234 array_type.len,234 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),
236 });236 });
237 try print(array_type.child.toType(), writer, mod);237 try print(Type.fromInterned(array_type.child), writer, mod);
238 }238 }
239 return;239 return;
240 },240 },
241 .vector_type => |vector_type| {241 .vector_type => |vector_type| {
242 try writer.print("@Vector({d}, ", .{vector_type.len});242 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);
244 try writer.writeAll(")");244 try writer.writeAll(")");
245 return;245 return;
246 },246 },
247 .opt_type => |child| {247 .opt_type => |child| {
248 try writer.writeByte('?');248 try writer.writeByte('?');
249 return print(child.toType(), writer, mod);249 return print(Type.fromInterned(child), writer, mod);
250 },250 },
251 .error_union_type => |error_union_type| {251 .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);
253 try writer.writeByte('!');253 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);
255 return;255 return;
256 },256 },
257 .inferred_error_set_type => |func_index| {257 .inferred_error_set_type => |func_index| {
...@@ -342,10 +342,10 @@ pub const Type = struct {...@@ -342,10 +342,10 @@ pub const Type = struct {
342 try writer.print("{}: ", .{anon_struct.names.get(ip)[i].fmt(&mod.intern_pool)});342 try writer.print("{}: ", .{anon_struct.names.get(ip)[i].fmt(&mod.intern_pool)});
343 }343 }
344344
345 try print(field_ty.toType(), writer, mod);345 try print(Type.fromInterned(field_ty), writer, mod);
346346
347 if (val != .none) {347 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)});
349 }349 }
350 }350 }
351 try writer.writeAll("}");351 try writer.writeAll("}");
...@@ -382,7 +382,7 @@ pub const Type = struct {...@@ -382,7 +382,7 @@ pub const Type = struct {
382 if (param_ty == .generic_poison_type) {382 if (param_ty == .generic_poison_type) {
383 try writer.writeAll("anytype");383 try writer.writeAll("anytype");
384 } else {384 } else {
385 try print(param_ty.toType(), writer, mod);385 try print(Type.fromInterned(param_ty), writer, mod);
386 }386 }
387 }387 }
388 if (fn_info.is_var_args) {388 if (fn_info.is_var_args) {
...@@ -403,13 +403,13 @@ pub const Type = struct {...@@ -403,13 +403,13 @@ pub const Type = struct {
403 if (fn_info.return_type == .generic_poison_type) {403 if (fn_info.return_type == .generic_poison_type) {
404 try writer.writeAll("anytype");404 try writer.writeAll("anytype");
405 } else {405 } else {
406 try print(fn_info.return_type.toType(), writer, mod);406 try print(Type.fromInterned(fn_info.return_type), writer, mod);
407 }407 }
408 },408 },
409 .anyframe_type => |child| {409 .anyframe_type => |child| {
410 if (child == .none) return writer.writeAll("anyframe");410 if (child == .none) return writer.writeAll("anyframe");
411 try writer.writeAll("anyframe->");411 try writer.writeAll("anyframe->");
412 return print(child.toType(), writer, mod);412 return print(Type.fromInterned(child), writer, mod);
413 },413 },
414414
415 // values, not types415 // values, not types
...@@ -435,13 +435,18 @@ pub const Type = struct {...@@ -435,13 +435,18 @@ pub const Type = struct {
435 }435 }
436 }436 }
437437
438 pub fn fromInterned(i: InternPool.Index) Type {
439 assert(i != .none);
440 return .{ .ip_index = i };
441 }
442
438 pub fn toIntern(ty: Type) InternPool.Index {443 pub fn toIntern(ty: Type) InternPool.Index {
439 assert(ty.ip_index != .none);444 assert(ty.ip_index != .none);
440 return ty.ip_index;445 return ty.ip_index;
441 }446 }
442447
443 pub fn toValue(self: Type) Value {448 pub fn toValue(self: Type) Value {
444 return self.toIntern().toValue();449 return Value.fromInterned(self.toIntern());
445 }450 }
446451
447 const RuntimeBitsError = Module.CompileError || error{NeedLazy};452 const RuntimeBitsError = Module.CompileError || error{NeedLazy};
...@@ -482,18 +487,18 @@ pub const Type = struct {...@@ -482,18 +487,18 @@ pub const Type = struct {
482 .anyframe_type => true,487 .anyframe_type => true,
483 .array_type => |array_type| {488 .array_type => |array_type| {
484 if (array_type.sentinel != .none) {489 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);
486 } else {491 } else {
487 return array_type.len > 0 and492 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);
489 }494 }
490 },495 },
491 .vector_type => |vector_type| {496 .vector_type => |vector_type| {
492 return vector_type.len > 0 and497 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);
494 },499 },
495 .opt_type => |child| {500 .opt_type => |child| {
496 const child_ty = child.toType();501 const child_ty = Type.fromInterned(child);
497 if (child_ty.isNoReturn(mod)) {502 if (child_ty.isNoReturn(mod)) {
498 // Then the optional is comptime-known to be null.503 // Then the optional is comptime-known to be null.
499 return false;504 return false;
...@@ -577,7 +582,7 @@ pub const Type = struct {...@@ -577,7 +582,7 @@ pub const Type = struct {
577 }582 }
578 for (0..struct_type.field_types.len) |i| {583 for (0..struct_type.field_types.len) |i| {
579 if (struct_type.comptime_bits.getBit(ip, i)) continue;584 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]);
581 if (try field_ty.hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat))586 if (try field_ty.hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat))
582 return true;587 return true;
583 } else {588 } else {
...@@ -587,7 +592,7 @@ pub const Type = struct {...@@ -587,7 +592,7 @@ pub const Type = struct {
587 .anon_struct_type => |tuple| {592 .anon_struct_type => |tuple| {
588 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {593 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {
589 if (val != .none) continue; // comptime field594 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;
591 }596 }
592 return false;597 return false;
593 },598 },
...@@ -607,7 +612,7 @@ pub const Type = struct {...@@ -607,7 +612,7 @@ pub const Type = struct {
607 // tag_ty will be `none` if this union's tag type is not resolved yet,612 // tag_ty will be `none` if this union's tag type is not resolved yet,
608 // in which case we want control flow to continue down below.613 // in which case we want control flow to continue down below.
609 if (tag_ty != .none and614 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))
611 {616 {
612 return true;617 return true;
613 }618 }
...@@ -621,7 +626,7 @@ pub const Type = struct {...@@ -621,7 +626,7 @@ pub const Type = struct {
621 }626 }
622 const union_obj = ip.loadUnionType(union_type);627 const union_obj = ip.loadUnionType(union_type);
623 for (0..union_obj.field_types.len) |field_index| {628 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]);
625 if (try field_ty.hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat))630 if (try field_ty.hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat))
626 return true;631 return true;
627 } else {632 } else {
...@@ -630,7 +635,7 @@ pub const Type = struct {...@@ -630,7 +635,7 @@ pub const Type = struct {
630 },635 },
631636
632 .opaque_type => true,637 .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
635 // values, not types640 // values, not types
636 .undef,641 .undef,
...@@ -676,7 +681,7 @@ pub const Type = struct {...@@ -676,7 +681,7 @@ pub const Type = struct {
676 .func_type,681 .func_type,
677 => false,682 => 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),
680 .opt_type => ty.isPtrLikeOptional(mod),685 .opt_type => ty.isPtrLikeOptional(mod),
681 .ptr_type => |ptr_type| ptr_type.flags.size != .Slice,686 .ptr_type => |ptr_type| ptr_type.flags.size != .Slice,
682687
...@@ -783,7 +788,7 @@ pub const Type = struct {...@@ -783,7 +788,7 @@ pub const Type = struct {
783 if (fn_info.is_generic) return false;788 if (fn_info.is_generic) return false;
784 if (fn_info.is_var_args) return true;789 if (fn_info.is_var_args) return true;
785 if (fn_info.cc == .Inline) return false;790 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);
787 }792 }
788793
789 pub fn isFnOrHasRuntimeBits(ty: Type, mod: *Module) bool {794 pub fn isFnOrHasRuntimeBits(ty: Type, mod: *Module) bool {
...@@ -817,13 +822,13 @@ pub const Type = struct {...@@ -817,13 +822,13 @@ pub const Type = struct {
817 return ptr_type.flags.alignment;822 return ptr_type.flags.alignment;
818823
819 if (opt_sema) |sema| {824 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 });
821 return res.scalar;826 return res.scalar;
822 }827 }
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;
825 },830 },
826 .opt_type => |child| child.toType().ptrAlignmentAdvanced(mod, opt_sema),831 .opt_type => |child| Type.fromInterned(child).ptrAlignmentAdvanced(mod, opt_sema),
827 else => unreachable,832 else => unreachable,
828 };833 };
829 }834 }
...@@ -891,10 +896,10 @@ pub const Type = struct {...@@ -891,10 +896,10 @@ pub const Type = struct {
891 return .{ .scalar = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8)) };896 return .{ .scalar = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8)) };
892 },897 },
893 .array_type => |array_type| {898 .array_type => |array_type| {
894 return array_type.child.toType().abiAlignmentAdvanced(mod, strat);899 return Type.fromInterned(array_type.child).abiAlignmentAdvanced(mod, strat);
895 },900 },
896 .vector_type => |vector_type| {901 .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);
898 const bits: u32 = @intCast(bits_u64);903 const bits: u32 = @intCast(bits_u64);
899 const bytes = ((bits * vector_type.len) + 7) / 8;904 const bytes = ((bits * vector_type.len) + 7) / 8;
900 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);905 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);
...@@ -902,7 +907,7 @@ pub const Type = struct {...@@ -902,7 +907,7 @@ pub const Type = struct {
902 },907 },
903908
904 .opt_type => return abiAlignmentAdvancedOptional(ty, mod, strat),909 .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
907 .error_set_type, .inferred_error_set_type => {912 .error_set_type, .inferred_error_set_type => {
908 const bits = mod.errorSetBits();913 const bits = mod.errorSetBits();
...@@ -992,14 +997,14 @@ pub const Type = struct {...@@ -992,14 +997,14 @@ pub const Type = struct {
992 switch (strat) {997 switch (strat) {
993 .sema => |sema| try sema.resolveTypeLayout(ty),998 .sema => |sema| try sema.resolveTypeLayout(ty),
994 .lazy => if (struct_type.backingIntType(ip).* == .none) return .{999 .lazy => if (struct_type.backingIntType(ip).* == .none) return .{
995 .val = (try mod.intern(.{ .int = .{1000 .val = Value.fromInterned((try mod.intern(.{ .int = .{
996 .ty = .comptime_int_type,1001 .ty = .comptime_int_type,
997 .storage = .{ .lazy_align = ty.toIntern() },1002 .storage = .{ .lazy_align = ty.toIntern() },
998 } })).toValue(),1003 } }))),
999 },1004 },
1000 .eager => {},1005 .eager => {},
1001 }1006 }
1002 return .{ .scalar = struct_type.backingIntType(ip).toType().abiAlignment(mod) };1007 return .{ .scalar = Type.fromInterned(struct_type.backingIntType(ip).*).abiAlignment(mod) };
1003 }1008 }
10041009
1005 const flags = struct_type.flagsPtr(ip).*;1010 const flags = struct_type.flagsPtr(ip).*;
...@@ -1010,25 +1015,25 @@ pub const Type = struct {...@@ -1010,25 +1015,25 @@ pub const Type = struct {
1010 .sema => |sema| .{1015 .sema => |sema| .{
1011 .scalar = try sema.resolveStructAlignment(ty.toIntern(), struct_type),1016 .scalar = try sema.resolveStructAlignment(ty.toIntern(), struct_type),
1012 },1017 },
1013 .lazy => .{ .val = (try mod.intern(.{ .int = .{1018 .lazy => .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
1014 .ty = .comptime_int_type,1019 .ty = .comptime_int_type,
1015 .storage = .{ .lazy_align = ty.toIntern() },1020 .storage = .{ .lazy_align = ty.toIntern() },
1016 } })).toValue() },1021 } }))) },
1017 };1022 };
1018 },1023 },
1019 .anon_struct_type => |tuple| {1024 .anon_struct_type => |tuple| {
1020 var big_align: Alignment = .@"1";1025 var big_align: Alignment = .@"1";
1021 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {1026 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {
1022 if (val != .none) continue; // comptime field1027 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)) {
1024 .scalar => |field_align| big_align = big_align.max(field_align),1029 .scalar => |field_align| big_align = big_align.max(field_align),
1025 .val => switch (strat) {1030 .val => switch (strat) {
1026 .eager => unreachable, // field type alignment not resolved1031 .eager => unreachable, // field type alignment not resolved
1027 .sema => unreachable, // passed to abiAlignmentAdvanced above1032 .sema => unreachable, // passed to abiAlignmentAdvanced above
1028 .lazy => return .{ .val = (try mod.intern(.{ .int = .{1033 .lazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
1029 .ty = .comptime_int_type,1034 .ty = .comptime_int_type,
1030 .storage = .{ .lazy_align = ty.toIntern() },1035 .storage = .{ .lazy_align = ty.toIntern() },
1031 } })).toValue() },1036 } }))) },
1032 },1037 },
1033 }1038 }
1034 }1039 }
...@@ -1041,17 +1046,17 @@ pub const Type = struct {...@@ -1041,17 +1046,17 @@ pub const Type = struct {
1041 if (!union_type.haveLayout(ip)) switch (strat) {1046 if (!union_type.haveLayout(ip)) switch (strat) {
1042 .eager => unreachable, // union layout not resolved1047 .eager => unreachable, // union layout not resolved
1043 .sema => |sema| return .{ .scalar = try sema.resolveUnionAlignment(ty, union_type) },1048 .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 = .{
1045 .ty = .comptime_int_type,1050 .ty = .comptime_int_type,
1046 .storage = .{ .lazy_align = ty.toIntern() },1051 .storage = .{ .lazy_align = ty.toIntern() },
1047 } })).toValue() },1052 } }))) },
1048 };1053 };
10491054
1050 return .{ .scalar = union_type.flagsPtr(ip).alignment };1055 return .{ .scalar = union_type.flagsPtr(ip).alignment };
1051 },1056 },
1052 .opaque_type => return .{ .scalar = .@"1" },1057 .opaque_type => return .{ .scalar = .@"1" },
1053 .enum_type => |enum_type| return .{1058 .enum_type => |enum_type| return .{
1054 .scalar = enum_type.tag_ty.toType().abiAlignment(mod),1059 .scalar = Type.fromInterned(enum_type.tag_ty).abiAlignment(mod),
1055 },1060 },
10561061
1057 // values, not types1062 // values, not types
...@@ -1090,10 +1095,10 @@ pub const Type = struct {...@@ -1090,10 +1095,10 @@ pub const Type = struct {
1090 switch (strat) {1095 switch (strat) {
1091 .eager, .sema => {1096 .eager, .sema => {
1092 if (!(payload_ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) {1097 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 = .{
1094 .ty = .comptime_int_type,1099 .ty = .comptime_int_type,
1095 .storage = .{ .lazy_align = ty.toIntern() },1100 .storage = .{ .lazy_align = ty.toIntern() },
1096 } })).toValue() },1101 } }))) },
1097 else => |e| return e,1102 else => |e| return e,
1098 })) {1103 })) {
1099 return .{ .scalar = code_align };1104 return .{ .scalar = code_align };
...@@ -1107,10 +1112,10 @@ pub const Type = struct {...@@ -1107,10 +1112,10 @@ pub const Type = struct {
1107 .scalar => |payload_align| return .{ .scalar = code_align.max(payload_align) },1112 .scalar => |payload_align| return .{ .scalar = code_align.max(payload_align) },
1108 .val => {},1113 .val => {},
1109 }1114 }
1110 return .{ .val = (try mod.intern(.{ .int = .{1115 return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
1111 .ty = .comptime_int_type,1116 .ty = .comptime_int_type,
1112 .storage = .{ .lazy_align = ty.toIntern() },1117 .storage = .{ .lazy_align = ty.toIntern() },
1113 } })).toValue() };1118 } }))) };
1114 },1119 },
1115 }1120 }
1116 }1121 }
...@@ -1135,10 +1140,10 @@ pub const Type = struct {...@@ -1135,10 +1140,10 @@ pub const Type = struct {
1135 switch (strat) {1140 switch (strat) {
1136 .eager, .sema => {1141 .eager, .sema => {
1137 if (!(child_type.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) {1142 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 = .{
1139 .ty = .comptime_int_type,1144 .ty = .comptime_int_type,
1140 .storage = .{ .lazy_align = ty.toIntern() },1145 .storage = .{ .lazy_align = ty.toIntern() },
1141 } })).toValue() },1146 } }))) },
1142 else => |e| return e,1147 else => |e| return e,
1143 })) {1148 })) {
1144 return .{ .scalar = .@"1" };1149 return .{ .scalar = .@"1" };
...@@ -1147,10 +1152,10 @@ pub const Type = struct {...@@ -1147,10 +1152,10 @@ pub const Type = struct {
1147 },1152 },
1148 .lazy => switch (try child_type.abiAlignmentAdvanced(mod, strat)) {1153 .lazy => switch (try child_type.abiAlignmentAdvanced(mod, strat)) {
1149 .scalar => |x| return .{ .scalar = x.max(.@"1") },1154 .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 = .{
1151 .ty = .comptime_int_type,1156 .ty = .comptime_int_type,
1152 .storage = .{ .lazy_align = ty.toIntern() },1157 .storage = .{ .lazy_align = ty.toIntern() },
1153 } })).toValue() },1158 } }))) },
1154 },1159 },
1155 }1160 }
1156 }1161 }
...@@ -1205,14 +1210,14 @@ pub const Type = struct {...@@ -1205,14 +1210,14 @@ pub const Type = struct {
1205 .array_type => |array_type| {1210 .array_type => |array_type| {
1206 const len = array_type.len + @intFromBool(array_type.sentinel != .none);1211 const len = array_type.len + @intFromBool(array_type.sentinel != .none);
1207 if (len == 0) return .{ .scalar = 0 };1212 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)) {
1209 .scalar => |elem_size| return .{ .scalar = len * elem_size },1214 .scalar => |elem_size| return .{ .scalar = len * elem_size },
1210 .val => switch (strat) {1215 .val => switch (strat) {
1211 .sema, .eager => unreachable,1216 .sema, .eager => unreachable,
1212 .lazy => return .{ .val = (try mod.intern(.{ .int = .{1217 .lazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
1213 .ty = .comptime_int_type,1218 .ty = .comptime_int_type,
1214 .storage = .{ .lazy_size = ty.toIntern() },1219 .storage = .{ .lazy_size = ty.toIntern() },
1215 } })).toValue() },1220 } }))) },
1216 },1221 },
1217 }1222 }
1218 },1223 },
...@@ -1220,20 +1225,20 @@ pub const Type = struct {...@@ -1220,20 +1225,20 @@ pub const Type = struct {
1220 const opt_sema = switch (strat) {1225 const opt_sema = switch (strat) {
1221 .sema => |sema| sema,1226 .sema => |sema| sema,
1222 .eager => null,1227 .eager => null,
1223 .lazy => return .{ .val = (try mod.intern(.{ .int = .{1228 .lazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
1224 .ty = .comptime_int_type,1229 .ty = .comptime_int_type,
1225 .storage = .{ .lazy_size = ty.toIntern() },1230 .storage = .{ .lazy_size = ty.toIntern() },
1226 } })).toValue() },1231 } }))) },
1227 };1232 };
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);
1229 const total_bits = elem_bits * vector_type.len;1234 const total_bits = elem_bits * vector_type.len;
1230 const total_bytes = (total_bits + 7) / 8;1235 const total_bytes = (total_bits + 7) / 8;
1231 const alignment = switch (try ty.abiAlignmentAdvanced(mod, strat)) {1236 const alignment = switch (try ty.abiAlignmentAdvanced(mod, strat)) {
1232 .scalar => |x| x,1237 .scalar => |x| x,
1233 .val => return .{ .val = (try mod.intern(.{ .int = .{1238 .val => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
1234 .ty = .comptime_int_type,1239 .ty = .comptime_int_type,
1235 .storage = .{ .lazy_size = ty.toIntern() },1240 .storage = .{ .lazy_size = ty.toIntern() },
1236 } })).toValue() },1241 } }))) },
1237 };1242 };
1238 return AbiSizeAdvanced{ .scalar = alignment.forward(total_bytes) };1243 return AbiSizeAdvanced{ .scalar = alignment.forward(total_bytes) };
1239 },1244 },
...@@ -1247,15 +1252,15 @@ pub const Type = struct {...@@ -1247,15 +1252,15 @@ pub const Type = struct {
1247 },1252 },
12481253
1249 .error_union_type => |error_union_type| {1254 .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);
1251 // This code needs to be kept in sync with the equivalent switch prong1256 // This code needs to be kept in sync with the equivalent switch prong
1252 // in abiAlignmentAdvanced.1257 // in abiAlignmentAdvanced.
1253 const code_size = abiSize(Type.anyerror, mod);1258 const code_size = abiSize(Type.anyerror, mod);
1254 if (!(payload_ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) {1259 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 = .{
1256 .ty = .comptime_int_type,1261 .ty = .comptime_int_type,
1257 .storage = .{ .lazy_size = ty.toIntern() },1262 .storage = .{ .lazy_size = ty.toIntern() },
1258 } })).toValue() },1263 } }))) },
1259 else => |e| return e,1264 else => |e| return e,
1260 })) {1265 })) {
1261 // Same as anyerror.1266 // Same as anyerror.
...@@ -1268,10 +1273,10 @@ pub const Type = struct {...@@ -1268,10 +1273,10 @@ pub const Type = struct {
1268 .val => switch (strat) {1273 .val => switch (strat) {
1269 .sema => unreachable,1274 .sema => unreachable,
1270 .eager => unreachable,1275 .eager => unreachable,
1271 .lazy => return .{ .val = (try mod.intern(.{ .int = .{1276 .lazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
1272 .ty = .comptime_int_type,1277 .ty = .comptime_int_type,
1273 .storage = .{ .lazy_size = ty.toIntern() },1278 .storage = .{ .lazy_size = ty.toIntern() },
1274 } })).toValue() },1279 } }))) },
1275 },1280 },
1276 };1281 };
12771282
...@@ -1358,18 +1363,18 @@ pub const Type = struct {...@@ -1358,18 +1363,18 @@ pub const Type = struct {
1358 .lazy => switch (struct_type.layout) {1363 .lazy => switch (struct_type.layout) {
1359 .Packed => {1364 .Packed => {
1360 if (struct_type.backingIntType(ip).* == .none) return .{1365 if (struct_type.backingIntType(ip).* == .none) return .{
1361 .val = (try mod.intern(.{ .int = .{1366 .val = Value.fromInterned((try mod.intern(.{ .int = .{
1362 .ty = .comptime_int_type,1367 .ty = .comptime_int_type,
1363 .storage = .{ .lazy_size = ty.toIntern() },1368 .storage = .{ .lazy_size = ty.toIntern() },
1364 } })).toValue(),1369 } }))),
1365 };1370 };
1366 },1371 },
1367 .Auto, .Extern => {1372 .Auto, .Extern => {
1368 if (!struct_type.haveLayout(ip)) return .{1373 if (!struct_type.haveLayout(ip)) return .{
1369 .val = (try mod.intern(.{ .int = .{1374 .val = Value.fromInterned((try mod.intern(.{ .int = .{
1370 .ty = .comptime_int_type,1375 .ty = .comptime_int_type,
1371 .storage = .{ .lazy_size = ty.toIntern() },1376 .storage = .{ .lazy_size = ty.toIntern() },
1372 } })).toValue(),1377 } }))),
1373 };1378 };
1374 },1379 },
1375 },1380 },
...@@ -1377,7 +1382,7 @@ pub const Type = struct {...@@ -1377,7 +1382,7 @@ pub const Type = struct {
1377 }1382 }
1378 return switch (struct_type.layout) {1383 return switch (struct_type.layout) {
1379 .Packed => .{1384 .Packed => .{
1380 .scalar = struct_type.backingIntType(ip).toType().abiSize(mod),1385 .scalar = Type.fromInterned(struct_type.backingIntType(ip).*).abiSize(mod),
1381 },1386 },
1382 .Auto, .Extern => .{ .scalar = struct_type.size(ip).* },1387 .Auto, .Extern => .{ .scalar = struct_type.size(ip).* },
1383 };1388 };
...@@ -1398,10 +1403,10 @@ pub const Type = struct {...@@ -1398,10 +1403,10 @@ pub const Type = struct {
1398 switch (strat) {1403 switch (strat) {
1399 .sema => |sema| try sema.resolveTypeLayout(ty),1404 .sema => |sema| try sema.resolveTypeLayout(ty),
1400 .lazy => if (!union_type.flagsPtr(ip).status.haveLayout()) return .{1405 .lazy => if (!union_type.flagsPtr(ip).status.haveLayout()) return .{
1401 .val = (try mod.intern(.{ .int = .{1406 .val = Value.fromInterned((try mod.intern(.{ .int = .{
1402 .ty = .comptime_int_type,1407 .ty = .comptime_int_type,
1403 .storage = .{ .lazy_size = ty.toIntern() },1408 .storage = .{ .lazy_size = ty.toIntern() },
1404 } })).toValue(),1409 } }))),
1405 },1410 },
1406 .eager => {},1411 .eager => {},
1407 }1412 }
...@@ -1409,7 +1414,7 @@ pub const Type = struct {...@@ -1409,7 +1414,7 @@ pub const Type = struct {
1409 return .{ .scalar = union_type.size(ip).* };1414 return .{ .scalar = union_type.size(ip).* };
1410 },1415 },
1411 .opaque_type => unreachable, // no size available1416 .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
1414 // values, not types1419 // values, not types
1415 .undef,1420 .undef,
...@@ -1447,10 +1452,10 @@ pub const Type = struct {...@@ -1447,10 +1452,10 @@ pub const Type = struct {
1447 }1452 }
14481453
1449 if (!(child_ty.hasRuntimeBitsAdvanced(mod, false, strat) catch |err| switch (err) {1454 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 = .{
1451 .ty = .comptime_int_type,1456 .ty = .comptime_int_type,
1452 .storage = .{ .lazy_size = ty.toIntern() },1457 .storage = .{ .lazy_size = ty.toIntern() },
1453 } })).toValue() },1458 } }))) },
1454 else => |e| return e,1459 else => |e| return e,
1455 })) return AbiSizeAdvanced{ .scalar = 1 };1460 })) return AbiSizeAdvanced{ .scalar = 1 };
14561461
...@@ -1463,10 +1468,10 @@ pub const Type = struct {...@@ -1463,10 +1468,10 @@ pub const Type = struct {
1463 .val => switch (strat) {1468 .val => switch (strat) {
1464 .sema => unreachable,1469 .sema => unreachable,
1465 .eager => unreachable,1470 .eager => unreachable,
1466 .lazy => return .{ .val = (try mod.intern(.{ .int = .{1471 .lazy => return .{ .val = Value.fromInterned((try mod.intern(.{ .int = .{
1467 .ty = .comptime_int_type,1472 .ty = .comptime_int_type,
1468 .storage = .{ .lazy_size = ty.toIntern() },1473 .storage = .{ .lazy_size = ty.toIntern() },
1469 } })).toValue() },1474 } }))) },
1470 },1475 },
1471 };1476 };
14721477
...@@ -1518,7 +1523,7 @@ pub const Type = struct {...@@ -1518,7 +1523,7 @@ pub const Type = struct {
1518 .array_type => |array_type| {1523 .array_type => |array_type| {
1519 const len = array_type.len + @intFromBool(array_type.sentinel != .none);1524 const len = array_type.len + @intFromBool(array_type.sentinel != .none);
1520 if (len == 0) return 0;1525 if (len == 0) return 0;
1521 const elem_ty = array_type.child.toType();1526 const elem_ty = Type.fromInterned(array_type.child);
1522 const elem_size = @max(1527 const elem_size = @max(
1523 (try elem_ty.abiAlignmentAdvanced(mod, strat)).scalar.toByteUnits(0),1528 (try elem_ty.abiAlignmentAdvanced(mod, strat)).scalar.toByteUnits(0),
1524 (try elem_ty.abiSizeAdvanced(mod, strat)).scalar,1529 (try elem_ty.abiSizeAdvanced(mod, strat)).scalar,
...@@ -1528,7 +1533,7 @@ pub const Type = struct {...@@ -1528,7 +1533,7 @@ pub const Type = struct {
1528 return (len - 1) * 8 * elem_size + elem_bit_size;1533 return (len - 1) * 8 * elem_size + elem_bit_size;
1529 },1534 },
1530 .vector_type => |vector_type| {1535 .vector_type => |vector_type| {
1531 const child_ty = vector_type.child.toType();1536 const child_ty = Type.fromInterned(vector_type.child);
1532 const elem_bit_size = try bitSizeAdvanced(child_ty, mod, opt_sema);1537 const elem_bit_size = try bitSizeAdvanced(child_ty, mod, opt_sema);
1533 return elem_bit_size * vector_type.len;1538 return elem_bit_size * vector_type.len;
1534 },1539 },
...@@ -1600,7 +1605,7 @@ pub const Type = struct {...@@ -1600,7 +1605,7 @@ pub const Type = struct {
1600 .struct_type => |struct_type| {1605 .struct_type => |struct_type| {
1601 if (struct_type.layout == .Packed) {1606 if (struct_type.layout == .Packed) {
1602 if (opt_sema) |sema| try sema.resolveTypeLayout(ty);1607 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);
1604 }1609 }
1605 return (try ty.abiSizeAdvanced(mod, strat)).scalar * 8;1610 return (try ty.abiSizeAdvanced(mod, strat)).scalar * 8;
1606 },1611 },
...@@ -1625,13 +1630,13 @@ pub const Type = struct {...@@ -1625,13 +1630,13 @@ pub const Type = struct {
1625 var size: u64 = 0;1630 var size: u64 = 0;
1626 for (0..union_obj.field_types.len) |field_index| {1631 for (0..union_obj.field_types.len) |field_index| {
1627 const field_ty = union_obj.field_types.get(ip)[field_index];1632 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));
1629 }1634 }
16301635
1631 return size;1636 return size;
1632 },1637 },
1633 .opaque_type => unreachable,1638 .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
1636 // values, not types1641 // values, not types
1637 .undef,1642 .undef,
...@@ -1665,10 +1670,10 @@ pub const Type = struct {...@@ -1665,10 +1670,10 @@ pub const Type = struct {
1665 .union_type => |union_type| union_type.haveLayout(ip),1670 .union_type => |union_type| union_type.haveLayout(ip),
1666 .array_type => |array_type| {1671 .array_type => |array_type| {
1667 if ((array_type.len + @intFromBool(array_type.sentinel != .none)) == 0) return true;1672 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);
1669 },1674 },
1670 .opt_type => |child| child.toType().layoutIsResolved(mod),1675 .opt_type => |child| Type.fromInterned(child).layoutIsResolved(mod),
1671 .error_union_type => |k| k.payload_type.toType().layoutIsResolved(mod),1676 .error_union_type => |k| Type.fromInterned(k.payload_type).layoutIsResolved(mod),
1672 else => true,1677 else => true,
1673 };1678 };
1674 }1679 }
...@@ -1701,7 +1706,7 @@ pub const Type = struct {...@@ -1701,7 +1706,7 @@ pub const Type = struct {
1701 }1706 }
17021707
1703 pub fn slicePtrFieldType(ty: Type, mod: *const Module) Type {1708 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()));
1705 }1710 }
17061711
1707 pub fn isConstPtr(ty: Type, mod: *const Module) bool {1712 pub fn isConstPtr(ty: Type, mod: *const Module) bool {
...@@ -1801,7 +1806,7 @@ pub const Type = struct {...@@ -1801,7 +1806,7 @@ pub const Type = struct {
1801 }1806 }
18021807
1803 pub fn childTypeIp(ty: Type, ip: *const InternPool) Type {1808 pub fn childTypeIp(ty: Type, ip: *const InternPool) Type {
1804 return ip.childType(ty.toIntern()).toType();1809 return Type.fromInterned(ip.childType(ty.toIntern()));
1805 }1810 }
18061811
1807 /// For *[N]T, returns T.1812 /// For *[N]T, returns T.
...@@ -1816,16 +1821,16 @@ pub const Type = struct {...@@ -1816,16 +1821,16 @@ pub const Type = struct {
1816 pub fn elemType2(ty: Type, mod: *const Module) Type {1821 pub fn elemType2(ty: Type, mod: *const Module) Type {
1817 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {1822 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1818 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {1823 .ptr_type => |ptr_type| switch (ptr_type.flags.size) {
1819 .One => ptr_type.child.toType().shallowElemType(mod),1824 .One => Type.fromInterned(ptr_type.child).shallowElemType(mod),
1820 .Many, .C, .Slice => ptr_type.child.toType(),1825 .Many, .C, .Slice => Type.fromInterned(ptr_type.child),
1821 },1826 },
1822 .anyframe_type => |child| {1827 .anyframe_type => |child| {
1823 assert(child != .none);1828 assert(child != .none);
1824 return child.toType();1829 return Type.fromInterned(child);
1825 },1830 },
1826 .vector_type => |vector_type| vector_type.child.toType(),1831 .vector_type => |vector_type| Type.fromInterned(vector_type.child),
1827 .array_type => |array_type| array_type.child.toType(),1832 .array_type => |array_type| Type.fromInterned(array_type.child),
1828 .opt_type => |child| mod.intern_pool.childType(child).toType(),1833 .opt_type => |child| Type.fromInterned(mod.intern_pool.childType(child)),
1829 else => unreachable,1834 else => unreachable,
1830 };1835 };
1831 }1836 }
...@@ -1849,7 +1854,7 @@ pub const Type = struct {...@@ -1849,7 +1854,7 @@ pub const Type = struct {
1849 /// Note that for C pointers this returns the type unmodified.1854 /// Note that for C pointers this returns the type unmodified.
1850 pub fn optionalChild(ty: Type, mod: *const Module) Type {1855 pub fn optionalChild(ty: Type, mod: *const Module) Type {
1851 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {1856 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
1852 .opt_type => |child| child.toType(),1857 .opt_type => |child| Type.fromInterned(child),
1853 .ptr_type => |ptr_type| b: {1858 .ptr_type => |ptr_type| b: {
1854 assert(ptr_type.flags.size == .C);1859 assert(ptr_type.flags.size == .C);
1855 break :b ty;1860 break :b ty;
...@@ -1866,7 +1871,7 @@ pub const Type = struct {...@@ -1866,7 +1871,7 @@ pub const Type = struct {
1866 .union_type => |union_type| switch (union_type.flagsPtr(ip).runtime_tag) {1871 .union_type => |union_type| switch (union_type.flagsPtr(ip).runtime_tag) {
1867 .tagged => {1872 .tagged => {
1868 assert(union_type.flagsPtr(ip).status.haveFieldTypes());1873 assert(union_type.flagsPtr(ip).status.haveFieldTypes());
1869 return union_type.enum_tag_ty.toType();1874 return Type.fromInterned(union_type.enum_tag_ty);
1870 },1875 },
1871 else => null,1876 else => null,
1872 },1877 },
...@@ -1882,7 +1887,7 @@ pub const Type = struct {...@@ -1882,7 +1887,7 @@ pub const Type = struct {
1882 .union_type => |union_type| {1887 .union_type => |union_type| {
1883 if (!union_type.hasTag(ip)) return null;1888 if (!union_type.hasTag(ip)) return null;
1884 assert(union_type.haveFieldTypes(ip));1889 assert(union_type.haveFieldTypes(ip));
1885 return union_type.enum_tag_ty.toType();1890 return Type.fromInterned(union_type.enum_tag_ty);
1886 },1891 },
1887 else => null,1892 else => null,
1888 };1893 };
...@@ -1892,7 +1897,7 @@ pub const Type = struct {...@@ -1892,7 +1897,7 @@ pub const Type = struct {
1892 /// not be stored at runtime.1897 /// not be stored at runtime.
1893 pub fn unionTagTypeHypothetical(ty: Type, mod: *Module) Type {1898 pub fn unionTagTypeHypothetical(ty: Type, mod: *Module) Type {
1894 const union_obj = mod.typeToUnion(ty).?;1899 const union_obj = mod.typeToUnion(ty).?;
1895 return union_obj.enum_tag_ty.toType();1900 return Type.fromInterned(union_obj.enum_tag_ty);
1896 }1901 }
18971902
1898 pub fn unionFieldType(ty: Type, enum_tag: Value, mod: *Module) ?Type {1903 pub fn unionFieldType(ty: Type, enum_tag: Value, mod: *Module) ?Type {
...@@ -1900,7 +1905,7 @@ pub const Type = struct {...@@ -1900,7 +1905,7 @@ pub const Type = struct {
1900 const union_obj = mod.typeToUnion(ty).?;1905 const union_obj = mod.typeToUnion(ty).?;
1901 const union_fields = union_obj.field_types.get(ip);1906 const union_fields = union_obj.field_types.get(ip);
1902 const index = mod.unionTagFieldIndex(union_obj, enum_tag) orelse return null;1907 const index = mod.unionTagFieldIndex(union_obj, enum_tag) orelse return null;
1903 return union_fields[index].toType();1908 return Type.fromInterned(union_fields[index]);
1904 }1909 }
19051910
1906 pub fn unionTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 {1911 pub fn unionTagFieldIndex(ty: Type, enum_tag: Value, mod: *Module) ?u32 {
...@@ -1912,7 +1917,7 @@ pub const Type = struct {...@@ -1912,7 +1917,7 @@ pub const Type = struct {
1912 const ip = &mod.intern_pool;1917 const ip = &mod.intern_pool;
1913 const union_obj = mod.typeToUnion(ty).?;1918 const union_obj = mod.typeToUnion(ty).?;
1914 for (union_obj.field_types.get(ip)) |field_ty| {1919 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;
1916 }1921 }
1917 return true;1922 return true;
1918 }1923 }
...@@ -1946,12 +1951,12 @@ pub const Type = struct {...@@ -1946,12 +1951,12 @@ pub const Type = struct {
19461951
1947 /// Asserts that the type is an error union.1952 /// Asserts that the type is an error union.
1948 pub fn errorUnionPayload(ty: Type, mod: *Module) Type {1953 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);
1950 }1955 }
19511956
1952 /// Asserts that the type is an error union.1957 /// Asserts that the type is an error union.
1953 pub fn errorUnionSet(ty: Type, mod: *Module) Type {1958 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()));
1955 }1960 }
19561961
1957 /// Returns false for unresolved inferred error sets.1962 /// Returns false for unresolved inferred error sets.
...@@ -2077,8 +2082,8 @@ pub const Type = struct {...@@ -2077,8 +2082,8 @@ pub const Type = struct {
2077 .anon_struct_type,2082 .anon_struct_type,
2078 => null,2083 => null,
20792084
2080 .array_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,
2081 .ptr_type => |t| if (t.sentinel != .none) t.sentinel.toValue() else null,2086 .ptr_type => |t| if (t.sentinel != .none) Value.fromInterned(t.sentinel) else null,
20822087
2083 else => unreachable,2088 else => unreachable,
2084 };2089 };
...@@ -2146,9 +2151,9 @@ pub const Type = struct {...@@ -2146,9 +2151,9 @@ pub const Type = struct {
2146 .c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) },2151 .c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) },
2147 else => switch (ip.indexToKey(ty.toIntern())) {2152 else => switch (ip.indexToKey(ty.toIntern())) {
2148 .int_type => |int_type| return int_type,2153 .int_type => |int_type| return int_type,
2149 .struct_type => |t| ty = t.backingIntType(ip).*.toType(),2154 .struct_type => |t| ty = Type.fromInterned(t.backingIntType(ip).*),
2150 .enum_type => |enum_type| ty = enum_type.tag_ty.toType(),2155 .enum_type => |enum_type| ty = Type.fromInterned(enum_type.tag_ty),
2151 .vector_type => |vector_type| ty = vector_type.child.toType(),2156 .vector_type => |vector_type| ty = Type.fromInterned(vector_type.child),
21522157
2153 .error_set_type, .inferred_error_set_type => {2158 .error_set_type, .inferred_error_set_type => {
2154 return .{ .signedness = .unsigned, .bits = mod.errorSetBits() };2159 return .{ .signedness = .unsigned, .bits = mod.errorSetBits() };
...@@ -2259,7 +2264,7 @@ pub const Type = struct {...@@ -2259,7 +2264,7 @@ pub const Type = struct {
22592264
2260 /// Asserts the type is a function or a function pointer.2265 /// Asserts the type is a function or a function pointer.
2261 pub fn fnReturnType(ty: Type, mod: *Module) Type {2266 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()));
2263 }2268 }
22642269
2265 /// Asserts the type is a function.2270 /// Asserts the type is a function.
...@@ -2343,15 +2348,15 @@ pub const Type = struct {...@@ -2343,15 +2348,15 @@ pub const Type = struct {
23432348
2344 inline .array_type, .vector_type => |seq_type, seq_tag| {2349 inline .array_type, .vector_type => |seq_type, seq_tag| {
2345 const has_sentinel = seq_tag == .array_type and seq_type.sentinel != .none;2350 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 = .{
2347 .ty = ty.toIntern(),2352 .ty = ty.toIntern(),
2348 .storage = .{ .elems = &.{} },2353 .storage = .{ .elems = &.{} },
2349 } })).toValue();2354 } })));
2350 if (try seq_type.child.toType().onePossibleValue(mod)) |opv| {2355 if (try Type.fromInterned(seq_type.child).onePossibleValue(mod)) |opv| {
2351 return (try mod.intern(.{ .aggregate = .{2356 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2352 .ty = ty.toIntern(),2357 .ty = ty.toIntern(),
2353 .storage = .{ .repeated_elem = opv.toIntern() },2358 .storage = .{ .repeated_elem = opv.toIntern() },
2354 } })).toValue();2359 } })));
2355 }2360 }
2356 return null;2361 return null;
2357 },2362 },
...@@ -2422,7 +2427,7 @@ pub const Type = struct {...@@ -2422,7 +2427,7 @@ pub const Type = struct {
2422 field_val.* = struct_type.field_inits.get(ip)[i];2427 field_val.* = struct_type.field_inits.get(ip)[i];
2423 continue;2428 continue;
2424 }2429 }
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]);
2426 if (try field_ty.onePossibleValue(mod)) |field_opv| {2431 if (try field_ty.onePossibleValue(mod)) |field_opv| {
2427 field_val.* = try field_opv.intern(field_ty, mod);2432 field_val.* = try field_opv.intern(field_ty, mod);
2428 } else return null;2433 } else return null;
...@@ -2430,10 +2435,10 @@ pub const Type = struct {...@@ -2430,10 +2435,10 @@ pub const Type = struct {
24302435
2431 // In this case the struct has no runtime-known fields and2436 // In this case the struct has no runtime-known fields and
2432 // therefore has one possible value.2437 // therefore has one possible value.
2433 return (try mod.intern(.{ .aggregate = .{2438 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2434 .ty = ty.toIntern(),2439 .ty = ty.toIntern(),
2435 .storage = .{ .elems = field_vals },2440 .storage = .{ .elems = field_vals },
2436 } })).toValue();2441 } })));
2437 },2442 },
24382443
2439 .anon_struct_type => |tuple| {2444 .anon_struct_type => |tuple| {
...@@ -2445,52 +2450,52 @@ pub const Type = struct {...@@ -2445,52 +2450,52 @@ pub const Type = struct {
2445 // TODO: write something like getCoercedInts to avoid needing to dupe2450 // TODO: write something like getCoercedInts to avoid needing to dupe
2446 const duped_values = try mod.gpa.dupe(InternPool.Index, tuple.values.get(ip));2451 const duped_values = try mod.gpa.dupe(InternPool.Index, tuple.values.get(ip));
2447 defer mod.gpa.free(duped_values);2452 defer mod.gpa.free(duped_values);
2448 return (try mod.intern(.{ .aggregate = .{2453 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2449 .ty = ty.toIntern(),2454 .ty = ty.toIntern(),
2450 .storage = .{ .elems = duped_values },2455 .storage = .{ .elems = duped_values },
2451 } })).toValue();2456 } })));
2452 },2457 },
24532458
2454 .union_type => |union_type| {2459 .union_type => |union_type| {
2455 const union_obj = ip.loadUnionType(union_type);2460 const union_obj = ip.loadUnionType(union_type);
2456 const tag_val = (try union_obj.enum_tag_ty.toType().onePossibleValue(mod)) orelse2461 const tag_val = (try Type.fromInterned(union_obj.enum_tag_ty).onePossibleValue(mod)) orelse
2457 return null;2462 return null;
2458 if (union_obj.field_names.len == 0) {2463 if (union_obj.field_names.len == 0) {
2459 const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() });2464 const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() });
2460 return only.toValue();2465 return Value.fromInterned(only);
2461 }2466 }
2462 const only_field_ty = union_obj.field_types.get(ip)[0];2467 const only_field_ty = union_obj.field_types.get(ip)[0];
2463 const val_val = (try only_field_ty.toType().onePossibleValue(mod)) orelse2468 const val_val = (try Type.fromInterned(only_field_ty).onePossibleValue(mod)) orelse
2464 return null;2469 return null;
2465 const only = try mod.intern(.{ .un = .{2470 const only = try mod.intern(.{ .un = .{
2466 .ty = ty.toIntern(),2471 .ty = ty.toIntern(),
2467 .tag = tag_val.toIntern(),2472 .tag = tag_val.toIntern(),
2468 .val = val_val.toIntern(),2473 .val = val_val.toIntern(),
2469 } });2474 } });
2470 return only.toValue();2475 return Value.fromInterned(only);
2471 },2476 },
2472 .opaque_type => return null,2477 .opaque_type => return null,
2473 .enum_type => |enum_type| switch (enum_type.tag_mode) {2478 .enum_type => |enum_type| switch (enum_type.tag_mode) {
2474 .nonexhaustive => {2479 .nonexhaustive => {
2475 if (enum_type.tag_ty == .comptime_int_type) return null;2480 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| {
2478 const only = try mod.intern(.{ .enum_tag = .{2483 const only = try mod.intern(.{ .enum_tag = .{
2479 .ty = ty.toIntern(),2484 .ty = ty.toIntern(),
2480 .int = int_opv.toIntern(),2485 .int = int_opv.toIntern(),
2481 } });2486 } });
2482 return only.toValue();2487 return Value.fromInterned(only);
2483 }2488 }
24842489
2485 return null;2490 return null;
2486 },2491 },
2487 .auto, .explicit => {2492 .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
2490 switch (enum_type.names.len) {2495 switch (enum_type.names.len) {
2491 0 => {2496 0 => {
2492 const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() });2497 const only = try mod.intern(.{ .empty_enum_value = ty.toIntern() });
2493 return only.toValue();2498 return Value.fromInterned(only);
2494 },2499 },
2495 1 => {2500 1 => {
2496 if (enum_type.values.len == 0) {2501 if (enum_type.values.len == 0) {
...@@ -2501,9 +2506,9 @@ pub const Type = struct {...@@ -2501,9 +2506,9 @@ pub const Type = struct {
2501 .storage = .{ .u64 = 0 },2506 .storage = .{ .u64 = 0 },
2502 } }),2507 } }),
2503 } });2508 } });
2504 return only.toValue();2509 return Value.fromInterned(only);
2505 } else {2510 } else {
2506 return enum_type.values.get(ip)[0].toValue();2511 return Value.fromInterned(enum_type.values.get(ip)[0]);
2507 }2512 }
2508 },2513 },
2509 else => return null,2514 else => return null,
...@@ -2552,7 +2557,7 @@ pub const Type = struct {...@@ -2552,7 +2557,7 @@ pub const Type = struct {
2552 else => switch (ip.indexToKey(ty.toIntern())) {2557 else => switch (ip.indexToKey(ty.toIntern())) {
2553 .int_type => false,2558 .int_type => false,
2554 .ptr_type => |ptr_type| {2559 .ptr_type => |ptr_type| {
2555 const child_ty = ptr_type.child.toType();2560 const child_ty = Type.fromInterned(ptr_type.child);
2556 switch (child_ty.zigTypeTag(mod)) {2561 switch (child_ty.zigTypeTag(mod)) {
2557 .Fn => return !try child_ty.fnHasRuntimeBitsAdvanced(mod, opt_sema),2562 .Fn => return !try child_ty.fnHasRuntimeBitsAdvanced(mod, opt_sema),
2558 .Opaque => return false,2563 .Opaque => return false,
...@@ -2561,12 +2566,12 @@ pub const Type = struct {...@@ -2561,12 +2566,12 @@ pub const Type = struct {
2561 },2566 },
2562 .anyframe_type => |child| {2567 .anyframe_type => |child| {
2563 if (child == .none) return false;2568 if (child == .none) return false;
2564 return child.toType().comptimeOnlyAdvanced(mod, opt_sema);2569 return Type.fromInterned(child).comptimeOnlyAdvanced(mod, opt_sema);
2565 },2570 },
2566 .array_type => |array_type| return array_type.child.toType().comptimeOnlyAdvanced(mod, opt_sema),2571 .array_type => |array_type| return Type.fromInterned(array_type.child).comptimeOnlyAdvanced(mod, opt_sema),
2567 .vector_type => |vector_type| return vector_type.child.toType().comptimeOnlyAdvanced(mod, opt_sema),2572 .vector_type => |vector_type| return Type.fromInterned(vector_type.child).comptimeOnlyAdvanced(mod, opt_sema),
2568 .opt_type => |child| return child.toType().comptimeOnlyAdvanced(mod, opt_sema),2573 .opt_type => |child| return Type.fromInterned(child).comptimeOnlyAdvanced(mod, opt_sema),
2569 .error_union_type => |error_union_type| return error_union_type.payload_type.toType().comptimeOnlyAdvanced(mod, opt_sema),2574 .error_union_type => |error_union_type| return Type.fromInterned(error_union_type.payload_type).comptimeOnlyAdvanced(mod, opt_sema),
25702575
2571 .error_set_type,2576 .error_set_type,
2572 .inferred_error_set_type,2577 .inferred_error_set_type,
...@@ -2647,7 +2652,7 @@ pub const Type = struct {...@@ -2647,7 +2652,7 @@ pub const Type = struct {
2647 const i: u32 = @intCast(i_usize);2652 const i: u32 = @intCast(i_usize);
2648 if (struct_type.fieldIsComptime(ip, i)) continue;2653 if (struct_type.fieldIsComptime(ip, i)) continue;
2649 const field_ty = struct_type.field_types.get(ip)[i];2654 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)) {
2651 // Note that this does not cause the layout to2656 // Note that this does not cause the layout to
2652 // be considered resolved. Comptime-only types2657 // be considered resolved. Comptime-only types
2653 // still maintain a layout of their2658 // still maintain a layout of their
...@@ -2666,7 +2671,7 @@ pub const Type = struct {...@@ -2666,7 +2671,7 @@ pub const Type = struct {
2666 .anon_struct_type => |tuple| {2671 .anon_struct_type => |tuple| {
2667 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {2672 for (tuple.types.get(ip), tuple.values.get(ip)) |field_ty, val| {
2668 const have_comptime_val = val != .none;2673 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;
2670 }2675 }
2671 return false;2676 return false;
2672 },2677 },
...@@ -2689,7 +2694,7 @@ pub const Type = struct {...@@ -2689,7 +2694,7 @@ pub const Type = struct {
2689 const union_obj = ip.loadUnionType(union_type);2694 const union_obj = ip.loadUnionType(union_type);
2690 for (0..union_obj.field_types.len) |field_idx| {2695 for (0..union_obj.field_types.len) |field_idx| {
2691 const field_ty = union_obj.field_types.get(ip)[field_idx];2696 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)) {
2693 union_obj.flagsPtr(ip).requires_comptime = .yes;2698 union_obj.flagsPtr(ip).requires_comptime = .yes;
2694 return true;2699 return true;
2695 }2700 }
...@@ -2702,7 +2707,7 @@ pub const Type = struct {...@@ -2702,7 +2707,7 @@ pub const Type = struct {
27022707
2703 .opaque_type => false,2708 .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
2707 // values, not types2712 // values, not types
2708 .undef,2713 .undef,
...@@ -2792,10 +2797,10 @@ pub const Type = struct {...@@ -2792,10 +2797,10 @@ pub const Type = struct {
2792 // Works for vectors and vectors of integers.2797 // Works for vectors and vectors of integers.
2793 pub fn minInt(ty: Type, mod: *Module, dest_ty: Type) !Value {2798 pub fn minInt(ty: Type, mod: *Module, dest_ty: Type) !Value {
2794 const scalar = try minIntScalar(ty.scalarType(mod), mod, dest_ty.scalarType(mod));2799 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 = .{
2796 .ty = dest_ty.toIntern(),2801 .ty = dest_ty.toIntern(),
2797 .storage = .{ .repeated_elem = scalar.toIntern() },2802 .storage = .{ .repeated_elem = scalar.toIntern() },
2798 } })).toValue() else scalar;2803 } }))) else scalar;
2799 }2804 }
28002805
2801 /// Asserts that the type is an integer.2806 /// Asserts that the type is an integer.
...@@ -2821,10 +2826,10 @@ pub const Type = struct {...@@ -2821,10 +2826,10 @@ pub const Type = struct {
2821 /// The returned Value will have type dest_ty.2826 /// The returned Value will have type dest_ty.
2822 pub fn maxInt(ty: Type, mod: *Module, dest_ty: Type) !Value {2827 pub fn maxInt(ty: Type, mod: *Module, dest_ty: Type) !Value {
2823 const scalar = try maxIntScalar(ty.scalarType(mod), mod, dest_ty.scalarType(mod));2828 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 = .{
2825 .ty = dest_ty.toIntern(),2830 .ty = dest_ty.toIntern(),
2826 .storage = .{ .repeated_elem = scalar.toIntern() },2831 .storage = .{ .repeated_elem = scalar.toIntern() },
2827 } })).toValue() else scalar;2832 } }))) else scalar;
2828 }2833 }
28292834
2830 /// The returned Value will have type dest_ty.2835 /// The returned Value will have type dest_ty.
...@@ -2865,8 +2870,8 @@ pub const Type = struct {...@@ -2865,8 +2870,8 @@ pub const Type = struct {
2865 /// Asserts the type is an enum or a union.2870 /// Asserts the type is an enum or a union.
2866 pub fn intTagType(ty: Type, mod: *Module) Type {2871 pub fn intTagType(ty: Type, mod: *Module) Type {
2867 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {2872 return switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2868 .union_type => |union_type| union_type.enum_tag_ty.toType().intTagType(mod),2873 .union_type => |union_type| Type.fromInterned(union_type.enum_tag_ty).intTagType(mod),
2869 .enum_type => |enum_type| enum_type.tag_ty.toType(),2874 .enum_type => |enum_type| Type.fromInterned(enum_type.tag_ty),
2870 else => unreachable,2875 else => unreachable,
2871 };2876 };
2872 }2877 }
...@@ -2965,12 +2970,12 @@ pub const Type = struct {...@@ -2965,12 +2970,12 @@ pub const Type = struct {
2965 pub fn structFieldType(ty: Type, index: usize, mod: *Module) Type {2970 pub fn structFieldType(ty: Type, index: usize, mod: *Module) Type {
2966 const ip = &mod.intern_pool;2971 const ip = &mod.intern_pool;
2967 return switch (ip.indexToKey(ty.toIntern())) {2972 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]),
2969 .union_type => |union_type| {2974 .union_type => |union_type| {
2970 const union_obj = ip.loadUnionType(union_type);2975 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]);
2972 },2977 },
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]),
2974 else => unreachable,2979 else => unreachable,
2975 };2980 };
2976 }2981 }
...@@ -2981,11 +2986,11 @@ pub const Type = struct {...@@ -2981,11 +2986,11 @@ pub const Type = struct {
2981 .struct_type => |struct_type| {2986 .struct_type => |struct_type| {
2982 assert(struct_type.layout != .Packed);2987 assert(struct_type.layout != .Packed);
2983 const explicit_align = struct_type.fieldAlign(ip, index);2988 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]);
2985 return mod.structFieldAlignment(explicit_align, field_ty, struct_type.layout);2990 return mod.structFieldAlignment(explicit_align, field_ty, struct_type.layout);
2986 },2991 },
2987 .anon_struct_type => |anon_struct| {2992 .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);
2989 },2994 },
2990 .union_type => |union_type| {2995 .union_type => |union_type| {
2991 const union_obj = ip.loadUnionType(union_type);2996 const union_obj = ip.loadUnionType(union_type);
...@@ -3002,13 +3007,13 @@ pub const Type = struct {...@@ -3002,13 +3007,13 @@ pub const Type = struct {
3002 const val = struct_type.fieldInit(ip, index);3007 const val = struct_type.fieldInit(ip, index);
3003 // TODO: avoid using `unreachable` to indicate this.3008 // TODO: avoid using `unreachable` to indicate this.
3004 if (val == .none) return Value.@"unreachable";3009 if (val == .none) return Value.@"unreachable";
3005 return val.toValue();3010 return Value.fromInterned(val);
3006 },3011 },
3007 .anon_struct_type => |anon_struct| {3012 .anon_struct_type => |anon_struct| {
3008 const val = anon_struct.values.get(ip)[index];3013 const val = anon_struct.values.get(ip)[index];
3009 // TODO: avoid using `unreachable` to indicate this.3014 // TODO: avoid using `unreachable` to indicate this.
3010 if (val == .none) return Value.@"unreachable";3015 if (val == .none) return Value.@"unreachable";
3011 return val.toValue();3016 return Value.fromInterned(val);
3012 },3017 },
3013 else => unreachable,3018 else => unreachable,
3014 }3019 }
...@@ -3020,17 +3025,17 @@ pub const Type = struct {...@@ -3020,17 +3025,17 @@ pub const Type = struct {
3020 .struct_type => |struct_type| {3025 .struct_type => |struct_type| {
3021 assert(struct_type.haveFieldInits(ip));3026 assert(struct_type.haveFieldInits(ip));
3022 if (struct_type.fieldIsComptime(ip, index)) {3027 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]);
3024 } else {3029 } 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);
3026 }3031 }
3027 },3032 },
3028 .anon_struct_type => |tuple| {3033 .anon_struct_type => |tuple| {
3029 const val = tuple.values.get(ip)[index];3034 const val = tuple.values.get(ip)[index];
3030 if (val == .none) {3035 if (val == .none) {
3031 return tuple.types.get(ip)[index].toType().onePossibleValue(mod);3036 return Type.fromInterned(tuple.types.get(ip)[index]).onePossibleValue(mod);
3032 } else {3037 } else {
3033 return val.toValue();3038 return Value.fromInterned(val);
3034 }3039 }
3035 },3040 },
3036 else => unreachable,3041 else => unreachable,
...@@ -3066,17 +3071,17 @@ pub const Type = struct {...@@ -3066,17 +3071,17 @@ pub const Type = struct {
3066 var big_align: Alignment = .none;3071 var big_align: Alignment = .none;
30673072
3068 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {3073 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)) {
3070 // comptime field3075 // comptime field
3071 if (i == index) return offset;3076 if (i == index) return offset;
3072 continue;3077 continue;
3073 }3078 }
30743079
3075 const field_align = field_ty.toType().abiAlignment(mod);3080 const field_align = Type.fromInterned(field_ty).abiAlignment(mod);
3076 big_align = big_align.max(field_align);3081 big_align = big_align.max(field_align);
3077 offset = field_align.forward(offset);3082 offset = field_align.forward(offset);
3078 if (i == index) return offset;3083 if (i == index) return offset;
3079 offset += field_ty.toType().abiSize(mod);3084 offset += Type.fromInterned(field_ty).abiSize(mod);
3080 }3085 }
3081 offset = big_align.max(.@"1").forward(offset);3086 offset = big_align.max(.@"1").forward(offset);
3082 return offset;3087 return offset;
src/value.zig+284-277
...@@ -196,13 +196,13 @@ pub const Value = struct {...@@ -196,13 +196,13 @@ pub const Value = struct {
196 .enum_literal => |enum_literal| enum_literal,196 .enum_literal => |enum_literal| enum_literal,
197 .ptr => |ptr| switch (ptr.len) {197 .ptr => |ptr| switch (ptr.len) {
198 .none => unreachable,198 .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),
200 },200 },
201 .aggregate => |aggregate| switch (aggregate.storage) {201 .aggregate => |aggregate| switch (aggregate.storage) {
202 .bytes => |bytes| try ip.getOrPutString(mod.gpa, bytes),202 .bytes => |bytes| try ip.getOrPutString(mod.gpa, bytes),
203 .elems => try arrayToIpString(val, ty.arrayLen(mod), mod),203 .elems => try arrayToIpString(val, ty.arrayLen(mod), mod),
204 .repeated_elem => |elem| {204 .repeated_elem => |elem| {
205 const byte = @as(u8, @intCast(elem.toValue().toUnsignedInt(mod)));205 const byte = @as(u8, @intCast(Value.fromInterned(elem).toUnsignedInt(mod)));
206 const len = @as(usize, @intCast(ty.arrayLen(mod)));206 const len = @as(usize, @intCast(ty.arrayLen(mod)));
207 try ip.string_bytes.appendNTimes(mod.gpa, byte, len);207 try ip.string_bytes.appendNTimes(mod.gpa, byte, len);
208 return ip.getOrPutTrailingString(mod.gpa, len);208 return ip.getOrPutTrailingString(mod.gpa, len);
...@@ -219,13 +219,13 @@ pub const Value = struct {...@@ -219,13 +219,13 @@ pub const Value = struct {
219 .enum_literal => |enum_literal| allocator.dupe(u8, mod.intern_pool.stringToSlice(enum_literal)),219 .enum_literal => |enum_literal| allocator.dupe(u8, mod.intern_pool.stringToSlice(enum_literal)),
220 .ptr => |ptr| switch (ptr.len) {220 .ptr => |ptr| switch (ptr.len) {
221 .none => unreachable,221 .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),
223 },223 },
224 .aggregate => |aggregate| switch (aggregate.storage) {224 .aggregate => |aggregate| switch (aggregate.storage) {
225 .bytes => |bytes| try allocator.dupe(u8, bytes),225 .bytes => |bytes| try allocator.dupe(u8, bytes),
226 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),226 .elems => try arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),
227 .repeated_elem => |elem| {227 .repeated_elem => |elem| {
228 const byte = @as(u8, @intCast(elem.toValue().toUnsignedInt(mod)));228 const byte = @as(u8, @intCast(Value.fromInterned(elem).toUnsignedInt(mod)));
229 const result = try allocator.alloc(u8, @as(usize, @intCast(ty.arrayLen(mod))));229 const result = try allocator.alloc(u8, @as(usize, @intCast(ty.arrayLen(mod))));
230 @memset(result, byte);230 @memset(result, byte);
231 return result;231 return result;
...@@ -316,8 +316,8 @@ pub const Value = struct {...@@ -316,8 +316,8 @@ pub const Value = struct {
316 for (new_elems, old_elems, 0..) |*new_elem, old_elem, field_i|316 for (new_elems, old_elems, 0..) |*new_elem, old_elem, field_i|
317 new_elem.* = try old_elem.intern(switch (ty_key) {317 new_elem.* = try old_elem.intern(switch (ty_key) {
318 .struct_type => ty.structFieldType(field_i, mod),318 .struct_type => ty.structFieldType(field_i, mod),
319 .anon_struct_type => |info| info.types.get(ip)[field_i].toType(),319 .anon_struct_type => |info| Type.fromInterned(info.types.get(ip)[field_i]),
320 inline .array_type, .vector_type => |info| info.child.toType(),320 inline .array_type, .vector_type => |info| Type.fromInterned(info.child),
321 else => unreachable,321 else => unreachable,
322 }, mod);322 }, mod);
323 return mod.intern(.{ .aggregate = .{323 return mod.intern(.{ .aggregate = .{
...@@ -378,42 +378,50 @@ pub const Value = struct {...@@ -378,42 +378,50 @@ pub const Value = struct {
378378
379 .error_union => |error_union| switch (error_union.val) {379 .error_union => |error_union| switch (error_union.val) {
380 .err_name => val,380 .err_name => val,
381 .payload => |payload| Tag.eu_payload.create(arena, payload.toValue()),381 .payload => |payload| Tag.eu_payload.create(arena, Value.fromInterned(payload)),
382 },382 },
383383
384 .ptr => |ptr| switch (ptr.len) {384 .ptr => |ptr| switch (ptr.len) {
385 .none => val,385 .none => val,
386 else => |len| Tag.slice.create(arena, .{386 else => |len| Tag.slice.create(arena, .{
387 .ptr = val.slicePtr(mod),387 .ptr = val.slicePtr(mod),
388 .len = len.toValue(),388 .len = Value.fromInterned(len),
389 }),389 }),
390 },390 },
391391
392 .opt => |opt| switch (opt.val) {392 .opt => |opt| switch (opt.val) {
393 .none => val,393 .none => val,
394 else => |payload| Tag.opt_payload.create(arena, payload.toValue()),394 else => |payload| Tag.opt_payload.create(arena, Value.fromInterned(payload)),
395 },395 },
396396
397 .aggregate => |aggregate| switch (aggregate.storage) {397 .aggregate => |aggregate| switch (aggregate.storage) {
398 .bytes => |bytes| Tag.bytes.create(arena, try arena.dupe(u8, bytes)),398 .bytes => |bytes| Tag.bytes.create(arena, try arena.dupe(u8, bytes)),
399 .elems => |old_elems| {399 .elems => |old_elems| {
400 const new_elems = try arena.alloc(Value, old_elems.len);400 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);
402 return Tag.aggregate.create(arena, new_elems);402 return Tag.aggregate.create(arena, new_elems);
403 },403 },
404 .repeated_elem => |elem| Tag.repeated.create(arena, elem.toValue()),404 .repeated_elem => |elem| Tag.repeated.create(arena, Value.fromInterned(elem)),
405 },405 },
406406
407 .un => |un| Tag.@"union".create(arena, .{407 .un => |un| Tag.@"union".create(arena, .{
408 // toValue asserts that the value cannot be .none which is valid on unions.408 // toValue asserts that the value cannot be .none which is valid on unions.
409 .tag = if (un.tag == .none) null else un.tag.toValue(),409 .tag = if (un.tag == .none) null else Value.fromInterned(un.tag),
410 .val = un.val.toValue(),410 .val = Value.fromInterned(un.val),
411 }),411 }),
412412
413 .memoized_call => unreachable,413 .memoized_call => unreachable,
414 };414 };
415 }415 }
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
417 pub fn toIntern(val: Value) InternPool.Index {425 pub fn toIntern(val: Value) InternPool.Index {
418 assert(val.ip_index != .none);426 assert(val.ip_index != .none);
419 return val.ip_index;427 return val.ip_index;
...@@ -421,7 +429,7 @@ pub const Value = struct {...@@ -421,7 +429,7 @@ pub const Value = struct {
421429
422 /// Asserts that the value is representable as a type.430 /// Asserts that the value is representable as a type.
423 pub fn toType(self: Value) Type {431 pub fn toType(self: Value) Type {
424 return self.toIntern().toType();432 return Type.fromInterned(self.toIntern());
425 }433 }
426434
427 pub fn intFromEnum(val: Value, ty: Type, mod: *Module) Allocator.Error!Value {435 pub fn intFromEnum(val: Value, ty: Type, mod: *Module) Allocator.Error!Value {
...@@ -435,13 +443,13 @@ pub const Value = struct {...@@ -435,13 +443,13 @@ pub const Value = struct {
435 // Assume it is already an integer and return it directly.443 // Assume it is already an integer and return it directly.
436 .simple_type, .int_type => val,444 .simple_type, .int_type => val,
437 .enum_type => |enum_type| if (enum_type.values.len != 0)445 .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])
439 else // Field index and integer values are the same.447 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),
441 else => unreachable,449 else => unreachable,
442 };450 };
443 },451 },
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)),
445 else => unreachable,453 else => unreachable,
446 };454 };
447 }455 }
...@@ -466,16 +474,16 @@ pub const Value = struct {...@@ -466,16 +474,16 @@ pub const Value = struct {
466 .int => |int| switch (int.storage) {474 .int => |int| switch (int.storage) {
467 .u64, .i64, .big_int => int.storage.toBigInt(space),475 .u64, .i64, .big_int => int.storage.toBigInt(space),
468 .lazy_align, .lazy_size => |ty| {476 .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));
470 const x = switch (int.storage) {478 const x = switch (int.storage) {
471 else => unreachable,479 else => unreachable,
472 .lazy_align => ty.toType().abiAlignment(mod).toByteUnits(0),480 .lazy_align => Type.fromInterned(ty).abiAlignment(mod).toByteUnits(0),
473 .lazy_size => ty.toType().abiSize(mod),481 .lazy_size => Type.fromInterned(ty).abiSize(mod),
474 };482 };
475 return BigIntMutable.init(&space.limbs, x).toConst();483 return BigIntMutable.init(&space.limbs, x).toConst();
476 },484 },
477 },485 },
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),
479 .opt, .ptr => BigIntMutable.init(487 .opt, .ptr => BigIntMutable.init(
480 &space.limbs,488 &space.limbs,
481 (try val.getUnsignedIntAdvanced(mod, opt_sema)).?,489 (try val.getUnsignedIntAdvanced(mod, opt_sema)).?,
...@@ -530,24 +538,24 @@ pub const Value = struct {...@@ -530,24 +538,24 @@ pub const Value = struct {
530 .u64 => |x| x,538 .u64 => |x| x,
531 .i64 => |x| std.math.cast(u64, x),539 .i64 => |x| std.math.cast(u64, x),
532 .lazy_align => |ty| if (opt_sema) |sema|540 .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)
534 else542 else
535 ty.toType().abiAlignment(mod).toByteUnits(0),543 Type.fromInterned(ty).abiAlignment(mod).toByteUnits(0),
536 .lazy_size => |ty| if (opt_sema) |sema|544 .lazy_size => |ty| if (opt_sema) |sema|
537 (try ty.toType().abiSizeAdvanced(mod, .{ .sema = sema })).scalar545 (try Type.fromInterned(ty).abiSizeAdvanced(mod, .{ .sema = sema })).scalar
538 else546 else
539 ty.toType().abiSize(mod),547 Type.fromInterned(ty).abiSize(mod),
540 },548 },
541 .ptr => |ptr| switch (ptr.addr) {549 .ptr => |ptr| switch (ptr.addr) {
542 .int => |int| int.toValue().getUnsignedIntAdvanced(mod, opt_sema),550 .int => |int| Value.fromInterned(int).getUnsignedIntAdvanced(mod, opt_sema),
543 .elem => |elem| {551 .elem => |elem| {
544 const base_addr = (try elem.base.toValue().getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;552 const base_addr = (try Value.fromInterned(elem.base).getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;
545 const elem_ty = mod.intern_pool.typeOf(elem.base).toType().elemType2(mod);553 const elem_ty = Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod);
546 return base_addr + elem.index * elem_ty.abiSize(mod);554 return base_addr + elem.index * elem_ty.abiSize(mod);
547 },555 },
548 .field => |field| {556 .field => |field| {
549 const base_addr = (try field.base.toValue().getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;557 const base_addr = (try Value.fromInterned(field.base).getUnsignedIntAdvanced(mod, opt_sema)) orelse return null;
550 const struct_ty = mod.intern_pool.typeOf(field.base).toType().childType(mod);558 const struct_ty = Type.fromInterned(mod.intern_pool.typeOf(field.base)).childType(mod);
551 if (opt_sema) |sema| try sema.resolveTypeLayout(struct_ty);559 if (opt_sema) |sema| try sema.resolveTypeLayout(struct_ty);
552 return base_addr + struct_ty.structFieldOffset(@as(usize, @intCast(field.index)), mod);560 return base_addr + struct_ty.structFieldOffset(@as(usize, @intCast(field.index)), mod);
553 },561 },
...@@ -555,7 +563,7 @@ pub const Value = struct {...@@ -555,7 +563,7 @@ pub const Value = struct {
555 },563 },
556 .opt => |opt| switch (opt.val) {564 .opt => |opt| switch (opt.val) {
557 .none => 0,565 .none => 0,
558 else => |payload| payload.toValue().getUnsignedIntAdvanced(mod, opt_sema),566 else => |payload| Value.fromInterned(payload).getUnsignedIntAdvanced(mod, opt_sema),
559 },567 },
560 else => null,568 else => null,
561 },569 },
...@@ -577,8 +585,8 @@ pub const Value = struct {...@@ -577,8 +585,8 @@ pub const Value = struct {
577 .big_int => |big_int| big_int.to(i64) catch unreachable,585 .big_int => |big_int| big_int.to(i64) catch unreachable,
578 .i64 => |x| x,586 .i64 => |x| x,
579 .u64 => |x| @intCast(x),587 .u64 => |x| @intCast(x),
580 .lazy_align => |ty| @intCast(ty.toType().abiAlignment(mod).toByteUnits(0)),588 .lazy_align => |ty| @intCast(Type.fromInterned(ty).abiAlignment(mod).toByteUnits(0)),
581 .lazy_size => |ty| @intCast(ty.toType().abiSize(mod)),589 .lazy_size => |ty| @intCast(Type.fromInterned(ty).abiSize(mod)),
582 },590 },
583 else => unreachable,591 else => unreachable,
584 },592 },
...@@ -598,8 +606,8 @@ pub const Value = struct {...@@ -598,8 +606,8 @@ pub const Value = struct {
598 while (true) switch (mod.intern_pool.indexToKey(check.toIntern())) {606 while (true) switch (mod.intern_pool.indexToKey(check.toIntern())) {
599 .ptr => |ptr| switch (ptr.addr) {607 .ptr => |ptr| switch (ptr.addr) {
600 .decl, .mut_decl, .comptime_field, .anon_decl => return true,608 .decl, .mut_decl, .comptime_field, .anon_decl => return true,
601 .eu_payload, .opt_payload => |base| check = base.toValue(),609 .eu_payload, .opt_payload => |base| check = Value.fromInterned(base),
602 .elem, .field => |base_index| check = base_index.base.toValue(),610 .elem, .field => |base_index| check = Value.fromInterned(base_index.base),
603 .int => return false,611 .int => return false,
604 },612 },
605 else => return false,613 else => return false,
...@@ -680,16 +688,16 @@ pub const Value = struct {...@@ -680,16 +688,16 @@ pub const Value = struct {
680 .repeated => val.castTag(.repeated).?.data,688 .repeated => val.castTag(.repeated).?.data,
681 else => unreachable,689 else => unreachable,
682 },690 },
683 else => switch (ip.indexToKey(val.toIntern()).aggregate.storage) {691 else => Value.fromInterned(switch (ip.indexToKey(val.toIntern()).aggregate.storage) {
684 .bytes => |bytes| {692 .bytes => |bytes| {
685 buffer[off] = bytes[i];693 buffer[off] = bytes[i];
686 continue;694 continue;
687 },695 },
688 .elems => |elems| elems[i],696 .elems => |elems| elems[i],
689 .repeated_elem => |elem| elem,697 .repeated_elem => |elem| elem,
690 }.toValue(),698 }),
691 };699 };
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]);
693 try writeToMemory(field_val, field_ty, mod, buffer[off..]);701 try writeToMemory(field_val, field_ty, mod, buffer[off..]);
694 },702 },
695 .Packed => {703 .Packed => {
...@@ -720,7 +728,7 @@ pub const Value = struct {...@@ -720,7 +728,7 @@ pub const Value = struct {
720 if (val.unionTag(mod)) |union_tag| {728 if (val.unionTag(mod)) |union_tag| {
721 const union_obj = mod.typeToUnion(ty).?;729 const union_obj = mod.typeToUnion(ty).?;
722 const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?;730 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]);
724 const field_val = try val.fieldValue(mod, field_index);732 const field_val = try val.fieldValue(mod, field_index);
725 const byte_count = @as(usize, @intCast(field_type.abiSize(mod)));733 const byte_count = @as(usize, @intCast(field_type.abiSize(mod)));
726 return writeToMemory(field_val, field_type, mod, buffer[0..byte_count]);734 return writeToMemory(field_val, field_type, mod, buffer[0..byte_count]);
...@@ -829,14 +837,14 @@ pub const Value = struct {...@@ -829,14 +837,14 @@ pub const Value = struct {
829 var bits: u16 = 0;837 var bits: u16 = 0;
830 const storage = ip.indexToKey(val.toIntern()).aggregate.storage;838 const storage = ip.indexToKey(val.toIntern()).aggregate.storage;
831 for (0..struct_type.field_types.len) |i| {839 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]);
833 const field_bits: u16 = @intCast(field_ty.bitSize(mod));841 const field_bits: u16 = @intCast(field_ty.bitSize(mod));
834 const field_val = switch (storage) {842 const field_val = switch (storage) {
835 .bytes => unreachable,843 .bytes => unreachable,
836 .elems => |elems| elems[i],844 .elems => |elems| elems[i],
837 .repeated_elem => |elem| elem,845 .repeated_elem => |elem| elem,
838 };846 };
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);
840 bits += field_bits;848 bits += field_bits;
841 }849 }
842 },850 },
...@@ -847,7 +855,7 @@ pub const Value = struct {...@@ -847,7 +855,7 @@ pub const Value = struct {
847 .Packed => {855 .Packed => {
848 if (val.unionTag(mod)) |union_tag| {856 if (val.unionTag(mod)) |union_tag| {
849 const field_index = mod.unionTagFieldIndex(union_obj, union_tag).?;857 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]);
851 const field_val = try val.fieldValue(mod, field_index);859 const field_val = try val.fieldValue(mod, field_index);
852 return field_val.writeToPackedMemory(field_type, mod, buffer, bit_offset);860 return field_val.writeToPackedMemory(field_type, mod, buffer, bit_offset);
853 } else {861 } else {
...@@ -934,7 +942,7 @@ pub const Value = struct {...@@ -934,7 +942,7 @@ pub const Value = struct {
934 return mod.getCoerced(try mod.intValue_big(int_ty, bigint.toConst()), ty);942 return mod.getCoerced(try mod.intValue_big(int_ty, bigint.toConst()), ty);
935 }943 }
936 },944 },
937 .Float => return (try mod.intern(.{ .float = .{945 .Float => return Value.fromInterned((try mod.intern(.{ .float = .{
938 .ty = ty.toIntern(),946 .ty = ty.toIntern(),
939 .storage = switch (ty.floatBits(target)) {947 .storage = switch (ty.floatBits(target)) {
940 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readInt(u16, buffer[0..2], endian))) },948 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readInt(u16, buffer[0..2], endian))) },
...@@ -944,7 +952,7 @@ pub const Value = struct {...@@ -944,7 +952,7 @@ pub const Value = struct {
944 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readInt(u128, buffer[0..16], endian))) },952 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readInt(u128, buffer[0..16], endian))) },
945 else => unreachable,953 else => unreachable,
946 },954 },
947 } })).toValue(),955 } }))),
948 .Array => {956 .Array => {
949 const elem_ty = ty.childType(mod);957 const elem_ty = ty.childType(mod);
950 const elem_size = elem_ty.abiSize(mod);958 const elem_size = elem_ty.abiSize(mod);
...@@ -954,10 +962,10 @@ pub const Value = struct {...@@ -954,10 +962,10 @@ pub const Value = struct {
954 elem.* = try (try readFromMemory(elem_ty, mod, buffer[offset..], arena)).intern(elem_ty, mod);962 elem.* = try (try readFromMemory(elem_ty, mod, buffer[offset..], arena)).intern(elem_ty, mod);
955 offset += @as(usize, @intCast(elem_size));963 offset += @as(usize, @intCast(elem_size));
956 }964 }
957 return (try mod.intern(.{ .aggregate = .{965 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
958 .ty = ty.toIntern(),966 .ty = ty.toIntern(),
959 .storage = .{ .elems = elems },967 .storage = .{ .elems = elems },
960 } })).toValue();968 } })));
961 },969 },
962 .Vector => {970 .Vector => {
963 // We use byte_count instead of abi_size here, so that any padding bytes971 // We use byte_count instead of abi_size here, so that any padding bytes
...@@ -973,15 +981,15 @@ pub const Value = struct {...@@ -973,15 +981,15 @@ pub const Value = struct {
973 const field_types = struct_type.field_types;981 const field_types = struct_type.field_types;
974 const field_vals = try arena.alloc(InternPool.Index, field_types.len);982 const field_vals = try arena.alloc(InternPool.Index, field_types.len);
975 for (field_vals, 0..) |*field_val, i| {983 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]);
977 const off: usize = @intCast(ty.structFieldOffset(i, mod));985 const off: usize = @intCast(ty.structFieldOffset(i, mod));
978 const sz: usize = @intCast(field_ty.abiSize(mod));986 const sz: usize = @intCast(field_ty.abiSize(mod));
979 field_val.* = try (try readFromMemory(field_ty, mod, buffer[off..(off + sz)], arena)).intern(field_ty, mod);987 field_val.* = try (try readFromMemory(field_ty, mod, buffer[off..(off + sz)], arena)).intern(field_ty, mod);
980 }988 }
981 return (try mod.intern(.{ .aggregate = .{989 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
982 .ty = ty.toIntern(),990 .ty = ty.toIntern(),
983 .storage = .{ .elems = field_vals },991 .storage = .{ .elems = field_vals },
984 } })).toValue();992 } })));
985 },993 },
986 .Packed => {994 .Packed => {
987 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;995 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;
...@@ -996,10 +1004,10 @@ pub const Value = struct {...@@ -996,10 +1004,10 @@ pub const Value = struct {
996 const index = (int << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));1004 const index = (int << @as(u6, @intCast(64 - bits))) >> @as(u6, @intCast(64 - bits));
997 const name = mod.global_error_set.keys()[@intCast(index)];1005 const name = mod.global_error_set.keys()[@intCast(index)];
9981006
999 return (try mod.intern(.{ .err = .{1007 return Value.fromInterned((try mod.intern(.{ .err = .{
1000 .ty = ty.toIntern(),1008 .ty = ty.toIntern(),
1001 .name = name,1009 .name = name,
1002 } })).toValue();1010 } })));
1003 },1011 },
1004 .Union => switch (ty.containerLayout(mod)) {1012 .Union => switch (ty.containerLayout(mod)) {
1005 .Auto => return error.IllDefinedMemoryLayout,1013 .Auto => return error.IllDefinedMemoryLayout,
...@@ -1007,11 +1015,11 @@ pub const Value = struct {...@@ -1007,11 +1015,11 @@ pub const Value = struct {
1007 const union_size = ty.abiSize(mod);1015 const union_size = ty.abiSize(mod);
1008 const array_ty = try mod.arrayType(.{ .len = union_size, .child = .u8_type });1016 const array_ty = try mod.arrayType(.{ .len = union_size, .child = .u8_type });
1009 const val = try (try readFromMemory(array_ty, mod, buffer, arena)).intern(array_ty, mod);1017 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 = .{
1011 .ty = ty.toIntern(),1019 .ty = ty.toIntern(),
1012 .tag = .none,1020 .tag = .none,
1013 .val = val,1021 .val = val,
1014 } })).toValue();1022 } })));
1015 },1023 },
1016 .Packed => {1024 .Packed => {
1017 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;1025 const byte_count = (@as(usize, @intCast(ty.bitSize(mod))) + 7) / 8;
...@@ -1021,23 +1029,23 @@ pub const Value = struct {...@@ -1021,23 +1029,23 @@ pub const Value = struct {
1021 .Pointer => {1029 .Pointer => {
1022 assert(!ty.isSlice(mod)); // No well defined layout.1030 assert(!ty.isSlice(mod)); // No well defined layout.
1023 const int_val = try readFromMemory(Type.usize, mod, buffer, arena);1031 const int_val = try readFromMemory(Type.usize, mod, buffer, arena);
1024 return (try mod.intern(.{ .ptr = .{1032 return Value.fromInterned((try mod.intern(.{ .ptr = .{
1025 .ty = ty.toIntern(),1033 .ty = ty.toIntern(),
1026 .addr = .{ .int = int_val.toIntern() },1034 .addr = .{ .int = int_val.toIntern() },
1027 } })).toValue();1035 } })));
1028 },1036 },
1029 .Optional => {1037 .Optional => {
1030 assert(ty.isPtrLikeOptional(mod));1038 assert(ty.isPtrLikeOptional(mod));
1031 const child_ty = ty.optionalChild(mod);1039 const child_ty = ty.optionalChild(mod);
1032 const child_val = try readFromMemory(child_ty, mod, buffer, arena);1040 const child_val = try readFromMemory(child_ty, mod, buffer, arena);
1033 return (try mod.intern(.{ .opt = .{1041 return Value.fromInterned((try mod.intern(.{ .opt = .{
1034 .ty = ty.toIntern(),1042 .ty = ty.toIntern(),
1035 .val = switch (child_val.orderAgainstZero(mod)) {1043 .val = switch (child_val.orderAgainstZero(mod)) {
1036 .lt => unreachable,1044 .lt => unreachable,
1037 .eq => .none,1045 .eq => .none,
1038 .gt => child_val.toIntern(),1046 .gt => child_val.toIntern(),
1039 },1047 },
1040 } })).toValue();1048 } })));
1041 },1049 },
1042 else => return error.Unimplemented,1050 else => return error.Unimplemented,
1043 }1051 }
...@@ -1108,7 +1116,7 @@ pub const Value = struct {...@@ -1108,7 +1116,7 @@ pub const Value = struct {
1108 bigint.readPackedTwosComplement(buffer, bit_offset, bits, endian, int_info.signedness);1116 bigint.readPackedTwosComplement(buffer, bit_offset, bits, endian, int_info.signedness);
1109 return mod.intValue_big(ty, bigint.toConst());1117 return mod.intValue_big(ty, bigint.toConst());
1110 },1118 },
1111 .Float => return (try mod.intern(.{ .float = .{1119 .Float => return Value.fromInterned((try mod.intern(.{ .float = .{
1112 .ty = ty.toIntern(),1120 .ty = ty.toIntern(),
1113 .storage = switch (ty.floatBits(target)) {1121 .storage = switch (ty.floatBits(target)) {
1114 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readPackedInt(u16, buffer, bit_offset, endian))) },1122 16 => .{ .f16 = @as(f16, @bitCast(std.mem.readPackedInt(u16, buffer, bit_offset, endian))) },
...@@ -1118,7 +1126,7 @@ pub const Value = struct {...@@ -1118,7 +1126,7 @@ pub const Value = struct {
1118 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readPackedInt(u128, buffer, bit_offset, endian))) },1126 128 => .{ .f128 = @as(f128, @bitCast(std.mem.readPackedInt(u128, buffer, bit_offset, endian))) },
1119 else => unreachable,1127 else => unreachable,
1120 },1128 },
1121 } })).toValue(),1129 } }))),
1122 .Vector => {1130 .Vector => {
1123 const elem_ty = ty.childType(mod);1131 const elem_ty = ty.childType(mod);
1124 const elems = try arena.alloc(InternPool.Index, @as(usize, @intCast(ty.arrayLen(mod))));1132 const elems = try arena.alloc(InternPool.Index, @as(usize, @intCast(ty.arrayLen(mod))));
...@@ -1131,10 +1139,10 @@ pub const Value = struct {...@@ -1131,10 +1139,10 @@ pub const Value = struct {
1131 elems[tgt_elem_i] = try (try readFromPackedMemory(elem_ty, mod, buffer, bit_offset + bits, arena)).intern(elem_ty, mod);1139 elems[tgt_elem_i] = try (try readFromPackedMemory(elem_ty, mod, buffer, bit_offset + bits, arena)).intern(elem_ty, mod);
1132 bits += elem_bit_size;1140 bits += elem_bit_size;
1133 }1141 }
1134 return (try mod.intern(.{ .aggregate = .{1142 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
1135 .ty = ty.toIntern(),1143 .ty = ty.toIntern(),
1136 .storage = .{ .elems = elems },1144 .storage = .{ .elems = elems },
1137 } })).toValue();1145 } })));
1138 },1146 },
1139 .Struct => {1147 .Struct => {
1140 // Sema is supposed to have emitted a compile error already for Auto layout structs,1148 // Sema is supposed to have emitted a compile error already for Auto layout structs,
...@@ -1143,26 +1151,26 @@ pub const Value = struct {...@@ -1143,26 +1151,26 @@ pub const Value = struct {
1143 var bits: u16 = 0;1151 var bits: u16 = 0;
1144 const field_vals = try arena.alloc(InternPool.Index, struct_type.field_types.len);1152 const field_vals = try arena.alloc(InternPool.Index, struct_type.field_types.len);
1145 for (field_vals, 0..) |*field_val, i| {1153 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]);
1147 const field_bits: u16 = @intCast(field_ty.bitSize(mod));1155 const field_bits: u16 = @intCast(field_ty.bitSize(mod));
1148 field_val.* = try (try readFromPackedMemory(field_ty, mod, buffer, bit_offset + bits, arena)).intern(field_ty, mod);1156 field_val.* = try (try readFromPackedMemory(field_ty, mod, buffer, bit_offset + bits, arena)).intern(field_ty, mod);
1149 bits += field_bits;1157 bits += field_bits;
1150 }1158 }
1151 return (try mod.intern(.{ .aggregate = .{1159 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
1152 .ty = ty.toIntern(),1160 .ty = ty.toIntern(),
1153 .storage = .{ .elems = field_vals },1161 .storage = .{ .elems = field_vals },
1154 } })).toValue();1162 } })));
1155 },1163 },
1156 .Union => switch (ty.containerLayout(mod)) {1164 .Union => switch (ty.containerLayout(mod)) {
1157 .Auto, .Extern => unreachable, // Handled by non-packed readFromMemory1165 .Auto, .Extern => unreachable, // Handled by non-packed readFromMemory
1158 .Packed => {1166 .Packed => {
1159 const backing_ty = try ty.unionBackingType(mod);1167 const backing_ty = try ty.unionBackingType(mod);
1160 const val = (try readFromPackedMemory(backing_ty, mod, buffer, bit_offset, arena)).toIntern();1168 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 = .{
1162 .ty = ty.toIntern(),1170 .ty = ty.toIntern(),
1163 .tag = .none,1171 .tag = .none,
1164 .val = val,1172 .val = val,
1165 } })).toValue();1173 } })));
1166 },1174 },
1167 },1175 },
1168 .Pointer => {1176 .Pointer => {
...@@ -1189,8 +1197,8 @@ pub const Value = struct {...@@ -1189,8 +1197,8 @@ pub const Value = struct {
1189 }1197 }
1190 return @floatFromInt(x);1198 return @floatFromInt(x);
1191 },1199 },
1192 .lazy_align => |ty| @floatFromInt(ty.toType().abiAlignment(mod).toByteUnits(0)),1200 .lazy_align => |ty| @floatFromInt(Type.fromInterned(ty).abiAlignment(mod).toByteUnits(0)),
1193 .lazy_size => |ty| @floatFromInt(ty.toType().abiSize(mod)),1201 .lazy_size => |ty| @floatFromInt(Type.fromInterned(ty).abiSize(mod)),
1194 },1202 },
1195 .float => |float| switch (float.storage) {1203 .float => |float| switch (float.storage) {
1196 inline else => |x| @floatCast(x),1204 inline else => |x| @floatCast(x),
...@@ -1283,7 +1291,7 @@ pub const Value = struct {...@@ -1283,7 +1291,7 @@ pub const Value = struct {
1283 /// Caller can find out by equality checking the result against the operand.1291 /// Caller can find out by equality checking the result against the operand.
1284 pub fn floatCast(self: Value, dest_ty: Type, mod: *Module) !Value {1292 pub fn floatCast(self: Value, dest_ty: Type, mod: *Module) !Value {
1285 const target = mod.getTarget();1293 const target = mod.getTarget();
1286 return (try mod.intern(.{ .float = .{1294 return Value.fromInterned((try mod.intern(.{ .float = .{
1287 .ty = dest_ty.toIntern(),1295 .ty = dest_ty.toIntern(),
1288 .storage = switch (dest_ty.floatBits(target)) {1296 .storage = switch (dest_ty.floatBits(target)) {
1289 16 => .{ .f16 = self.toFloat(f16, mod) },1297 16 => .{ .f16 = self.toFloat(f16, mod) },
...@@ -1293,7 +1301,7 @@ pub const Value = struct {...@@ -1293,7 +1301,7 @@ pub const Value = struct {
1293 128 => .{ .f128 = self.toFloat(f128, mod) },1301 128 => .{ .f128 = self.toFloat(f128, mod) },
1294 else => unreachable,1302 else => unreachable,
1295 },1303 },
1296 } })).toValue();1304 } })));
1297 }1305 }
12981306
1299 /// Asserts the value is a float1307 /// Asserts the value is a float
...@@ -1321,8 +1329,8 @@ pub const Value = struct {...@@ -1321,8 +1329,8 @@ pub const Value = struct {
1321 else => switch (mod.intern_pool.indexToKey(lhs.toIntern())) {1329 else => switch (mod.intern_pool.indexToKey(lhs.toIntern())) {
1322 .ptr => |ptr| switch (ptr.addr) {1330 .ptr => |ptr| switch (ptr.addr) {
1323 .decl, .mut_decl, .comptime_field => .gt,1331 .decl, .mut_decl, .comptime_field => .gt,
1324 .int => |int| int.toValue().orderAgainstZeroAdvanced(mod, opt_sema),1332 .int => |int| Value.fromInterned(int).orderAgainstZeroAdvanced(mod, opt_sema),
1325 .elem => |elem| switch (try elem.base.toValue().orderAgainstZeroAdvanced(mod, opt_sema)) {1333 .elem => |elem| switch (try Value.fromInterned(elem.base).orderAgainstZeroAdvanced(mod, opt_sema)) {
1326 .lt => unreachable,1334 .lt => unreachable,
1327 .gt => .gt,1335 .gt => .gt,
1328 .eq => if (elem.index == 0) .eq else .gt,1336 .eq => if (elem.index == 0) .eq else .gt,
...@@ -1333,7 +1341,7 @@ pub const Value = struct {...@@ -1333,7 +1341,7 @@ pub const Value = struct {
1333 .big_int => |big_int| big_int.orderAgainstScalar(0),1341 .big_int => |big_int| big_int.orderAgainstScalar(0),
1334 inline .u64, .i64 => |x| std.math.order(x, 0),1342 inline .u64, .i64 => |x| std.math.order(x, 0),
1335 .lazy_align => .gt, // alignment is never 01343 .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(
1337 mod,1345 mod,
1338 false,1346 false,
1339 if (opt_sema) |sema| .{ .sema = sema } else .eager,1347 if (opt_sema) |sema| .{ .sema = sema } else .eager,
...@@ -1342,7 +1350,7 @@ pub const Value = struct {...@@ -1342,7 +1350,7 @@ pub const Value = struct {
1342 else => |e| return e,1350 else => |e| return e,
1343 }) .gt else .eq,1351 }) .gt else .eq,
1344 },1352 },
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),
1346 .float => |float| switch (float.storage) {1354 .float => |float| switch (float.storage) {
1347 inline else => |x| std.math.order(x, 0),1355 inline else => |x| std.math.order(x, 0),
1348 },1356 },
...@@ -1494,9 +1502,9 @@ pub const Value = struct {...@@ -1494,9 +1502,9 @@ pub const Value = struct {
1494 if (!std.math.order(byte, 0).compare(op)) break false;1502 if (!std.math.order(byte, 0).compare(op)) break false;
1495 } else true,1503 } else true,
1496 .elems => |elems| for (elems) |elem| {1504 .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;
1498 } else true,1506 } 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),
1500 },1508 },
1501 else => {},1509 else => {},
1502 }1510 }
...@@ -1513,8 +1521,8 @@ pub const Value = struct {...@@ -1513,8 +1521,8 @@ pub const Value = struct {
1513 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1521 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1514 .ptr => |ptr| switch (ptr.addr) {1522 .ptr => |ptr| switch (ptr.addr) {
1515 .mut_decl, .comptime_field => true,1523 .mut_decl, .comptime_field => true,
1516 .eu_payload, .opt_payload => |base_ptr| base_ptr.toValue().isComptimeMutablePtr(mod),1524 .eu_payload, .opt_payload => |base_ptr| Value.fromInterned(base_ptr).isComptimeMutablePtr(mod),
1517 .elem, .field => |base_index| base_index.base.toValue().isComptimeMutablePtr(mod),1525 .elem, .field => |base_index| Value.fromInterned(base_index.base).isComptimeMutablePtr(mod),
1518 else => false,1526 else => false,
1519 },1527 },
1520 else => false,1528 else => false,
...@@ -1526,20 +1534,20 @@ pub const Value = struct {...@@ -1526,20 +1534,20 @@ pub const Value = struct {
1526 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {1534 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
1527 .error_union => |error_union| switch (error_union.val) {1535 .error_union => |error_union| switch (error_union.val) {
1528 .err_name => false,1536 .err_name => false,
1529 .payload => |payload| payload.toValue().canMutateComptimeVarState(mod),1537 .payload => |payload| Value.fromInterned(payload).canMutateComptimeVarState(mod),
1530 },1538 },
1531 .ptr => |ptr| switch (ptr.addr) {1539 .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),
1533 else => false,1541 else => false,
1534 },1542 },
1535 .opt => |opt| switch (opt.val) {1543 .opt => |opt| switch (opt.val) {
1536 .none => false,1544 .none => false,
1537 else => |payload| payload.toValue().canMutateComptimeVarState(mod),1545 else => |payload| Value.fromInterned(payload).canMutateComptimeVarState(mod),
1538 },1546 },
1539 .aggregate => |aggregate| for (aggregate.storage.values()) |elem| {1547 .aggregate => |aggregate| for (aggregate.storage.values()) |elem| {
1540 if (elem.toValue().canMutateComptimeVarState(mod)) break true;1548 if (Value.fromInterned(elem).canMutateComptimeVarState(mod)) break true;
1541 } else false,1549 } else false,
1542 .un => |un| un.val.toValue().canMutateComptimeVarState(mod),1550 .un => |un| Value.fromInterned(un.val).canMutateComptimeVarState(mod),
1543 else => false,1551 else => false,
1544 },1552 },
1545 };1553 };
...@@ -1566,7 +1574,7 @@ pub const Value = struct {...@@ -1566,7 +1574,7 @@ pub const Value = struct {
1566 pub const slice_len_index = 1;1574 pub const slice_len_index = 1;
15671575
1568 pub fn slicePtr(val: Value, mod: *Module) Value {1576 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()));
1570 }1578 }
15711579
1572 pub fn sliceLen(val: Value, mod: *Module) u64 {1580 pub fn sliceLen(val: Value, mod: *Module) u64 {
...@@ -1583,7 +1591,7 @@ pub const Value = struct {...@@ -1583,7 +1591,7 @@ pub const Value = struct {
1583 .array_type => |array_type| array_type.len,1591 .array_type => |array_type| array_type.len,
1584 else => 1,1592 else => 1,
1585 },1593 },
1586 else => ptr.len.toValue().toUnsignedInt(mod),1594 else => Value.fromInterned(ptr.len).toUnsignedInt(mod),
1587 };1595 };
1588 }1596 }
15891597
...@@ -1604,37 +1612,36 @@ pub const Value = struct {...@@ -1604,37 +1612,36 @@ pub const Value = struct {
1604 else => null,1612 else => null,
1605 },1613 },
1606 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {1614 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
1607 .undef => |ty| (try mod.intern(.{1615 .undef => |ty| Value.fromInterned((try mod.intern(.{
1608 .undef = ty.toType().elemType2(mod).toIntern(),1616 .undef = Type.fromInterned(ty).elemType2(mod).toIntern(),
1609 })).toValue(),1617 }))),
1610 .ptr => |ptr| switch (ptr.addr) {1618 .ptr => |ptr| switch (ptr.addr) {
1611 .decl => |decl| mod.declPtr(decl).val.maybeElemValue(mod, index),1619 .decl => |decl| mod.declPtr(decl).val.maybeElemValue(mod, index),
1612 .anon_decl => |anon_decl| anon_decl.val.toValue().maybeElemValue(mod, index),1620 .anon_decl => |anon_decl| Value.fromInterned(anon_decl.val).maybeElemValue(mod, index),
1613 .mut_decl => |mut_decl| (try mod.declPtr(mut_decl.decl).internValue(mod))1621 .mut_decl => |mut_decl| Value.fromInterned((try mod.declPtr(mut_decl.decl).internValue(mod))).maybeElemValue(mod, index),
1614 .toValue().maybeElemValue(mod, index),
1615 .int, .eu_payload => null,1622 .int, .eu_payload => null,
1616 .opt_payload => |base| base.toValue().maybeElemValue(mod, index),1623 .opt_payload => |base| Value.fromInterned(base).maybeElemValue(mod, index),
1617 .comptime_field => |field_val| field_val.toValue().maybeElemValue(mod, index),1624 .comptime_field => |field_val| Value.fromInterned(field_val).maybeElemValue(mod, index),
1618 .elem => |elem| elem.base.toValue().maybeElemValue(mod, index + @as(usize, @intCast(elem.index))),1625 .elem => |elem| Value.fromInterned(elem.base).maybeElemValue(mod, index + @as(usize, @intCast(elem.index))),
1619 .field => |field| if (field.base.toValue().pointerDecl(mod)) |decl_index| {1626 .field => |field| if (Value.fromInterned(field.base).pointerDecl(mod)) |decl_index| {
1620 const base_decl = mod.declPtr(decl_index);1627 const base_decl = mod.declPtr(decl_index);
1621 const field_val = try base_decl.val.fieldValue(mod, @as(usize, @intCast(field.index)));1628 const field_val = try base_decl.val.fieldValue(mod, @as(usize, @intCast(field.index)));
1622 return field_val.maybeElemValue(mod, index);1629 return field_val.maybeElemValue(mod, index);
1623 } else null,1630 } else null,
1624 },1631 },
1625 .opt => |opt| opt.val.toValue().maybeElemValue(mod, index),1632 .opt => |opt| Value.fromInterned(opt.val).maybeElemValue(mod, index),
1626 .aggregate => |aggregate| {1633 .aggregate => |aggregate| {
1627 const len = mod.intern_pool.aggregateTypeLen(aggregate.ty);1634 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) {
1629 .bytes => |bytes| try mod.intern(.{ .int = .{1636 .bytes => |bytes| try mod.intern(.{ .int = .{
1630 .ty = .u8_type,1637 .ty = .u8_type,
1631 .storage = .{ .u64 = bytes[index] },1638 .storage = .{ .u64 = bytes[index] },
1632 } }),1639 } }),
1633 .elems => |elems| elems[index],1640 .elems => |elems| elems[index],
1634 .repeated_elem => |elem| elem,1641 .repeated_elem => |elem| elem,
1635 }.toValue();1642 });
1636 assert(index == len);1643 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);
1638 },1645 },
1639 else => null,1646 else => null,
1640 },1647 },
...@@ -1681,15 +1688,15 @@ pub const Value = struct {...@@ -1681,15 +1688,15 @@ pub const Value = struct {
1681 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {1688 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
1682 .ptr => |ptr| switch (ptr.addr) {1689 .ptr => |ptr| switch (ptr.addr) {
1683 .decl => |decl| try mod.declPtr(decl).val.sliceArray(mod, arena, start, end),1690 .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)))
1685 .sliceArray(mod, arena, start, end),1692 .sliceArray(mod, arena, start, end),
1686 .comptime_field => |comptime_field| comptime_field.toValue()1693 .comptime_field => |comptime_field| Value.fromInterned(comptime_field)
1687 .sliceArray(mod, arena, start, end),1694 .sliceArray(mod, arena, start, end),
1688 .elem => |elem| elem.base.toValue()1695 .elem => |elem| Value.fromInterned(elem.base)
1689 .sliceArray(mod, arena, start + @as(usize, @intCast(elem.index)), end + @as(usize, @intCast(elem.index))),1696 .sliceArray(mod, arena, start + @as(usize, @intCast(elem.index)), end + @as(usize, @intCast(elem.index))),
1690 else => unreachable,1697 else => unreachable,
1691 },1698 },
1692 .aggregate => |aggregate| (try mod.intern(.{ .aggregate = .{1699 .aggregate => |aggregate| Value.fromInterned((try mod.intern(.{ .aggregate = .{
1693 .ty = switch (mod.intern_pool.indexToKey(mod.intern_pool.typeOf(val.toIntern()))) {1700 .ty = switch (mod.intern_pool.indexToKey(mod.intern_pool.typeOf(val.toIntern()))) {
1694 .array_type => |array_type| try mod.arrayType(.{1701 .array_type => |array_type| try mod.arrayType(.{
1695 .len = @as(u32, @intCast(end - start)),1702 .len = @as(u32, @intCast(end - start)),
...@@ -1707,7 +1714,7 @@ pub const Value = struct {...@@ -1707,7 +1714,7 @@ pub const Value = struct {
1707 .elems => .{ .elems = try arena.dupe(InternPool.Index, mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage.elems[start..end]) },1714 .elems => .{ .elems = try arena.dupe(InternPool.Index, mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage.elems[start..end]) },
1708 .repeated_elem => |elem| .{ .repeated_elem = elem },1715 .repeated_elem => |elem| .{ .repeated_elem = elem },
1709 },1716 },
1710 } })).toValue(),1717 } }))),
1711 else => unreachable,1718 else => unreachable,
1712 },1719 },
1713 };1720 };
...@@ -1728,19 +1735,19 @@ pub const Value = struct {...@@ -1728,19 +1735,19 @@ pub const Value = struct {
1728 else => unreachable,1735 else => unreachable,
1729 },1736 },
1730 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {1737 else => switch (mod.intern_pool.indexToKey(val.toIntern())) {
1731 .undef => |ty| (try mod.intern(.{1738 .undef => |ty| Value.fromInterned((try mod.intern(.{
1732 .undef = ty.toType().structFieldType(index, mod).toIntern(),1739 .undef = Type.fromInterned(ty).structFieldType(index, mod).toIntern(),
1733 })).toValue(),1740 }))),
1734 .aggregate => |aggregate| switch (aggregate.storage) {1741 .aggregate => |aggregate| Value.fromInterned(switch (aggregate.storage) {
1735 .bytes => |bytes| try mod.intern(.{ .int = .{1742 .bytes => |bytes| try mod.intern(.{ .int = .{
1736 .ty = .u8_type,1743 .ty = .u8_type,
1737 .storage = .{ .u64 = bytes[index] },1744 .storage = .{ .u64 = bytes[index] },
1738 } }),1745 } }),
1739 .elems => |elems| elems[index],1746 .elems => |elems| elems[index],
1740 .repeated_elem => |elem| elem,1747 .repeated_elem => |elem| elem,
1741 }.toValue(),1748 }),
1742 // TODO assert the tag is correct1749 // TODO assert the tag is correct
1743 .un => |un| un.val.toValue(),1750 .un => |un| Value.fromInterned(un.val),
1744 else => unreachable,1751 else => unreachable,
1745 },1752 },
1746 };1753 };
...@@ -1750,7 +1757,7 @@ pub const Value = struct {...@@ -1750,7 +1757,7 @@ pub const Value = struct {
1750 if (val.ip_index == .none) return val.castTag(.@"union").?.data.tag;1757 if (val.ip_index == .none) return val.castTag(.@"union").?.data.tag;
1751 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1758 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1752 .undef, .enum_tag => val,1759 .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,
1754 else => unreachable,1761 else => unreachable,
1755 };1762 };
1756 }1763 }
...@@ -1758,7 +1765,7 @@ pub const Value = struct {...@@ -1758,7 +1765,7 @@ pub const Value = struct {
1758 pub fn unionValue(val: Value, mod: *Module) Value {1765 pub fn unionValue(val: Value, mod: *Module) Value {
1759 if (val.ip_index == .none) return val.castTag(.@"union").?.data.val;1766 if (val.ip_index == .none) return val.castTag(.@"union").?.data.val;
1760 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1767 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1761 .un => |un| un.val.toValue(),1768 .un => |un| Value.fromInterned(un.val),
1762 else => unreachable,1769 else => unreachable,
1763 };1770 };
1764 }1771 }
...@@ -1774,14 +1781,14 @@ pub const Value = struct {...@@ -1774,14 +1781,14 @@ pub const Value = struct {
1774 const ptr_val = switch (mod.intern_pool.indexToKey(val.toIntern())) {1781 const ptr_val = switch (mod.intern_pool.indexToKey(val.toIntern())) {
1775 .ptr => |ptr| ptr: {1782 .ptr => |ptr| ptr: {
1776 switch (ptr.addr) {1783 switch (ptr.addr) {
1777 .elem => |elem| if (mod.intern_pool.typeOf(elem.base).toType().elemType2(mod).eql(elem_ty, mod))1784 .elem => |elem| if (Type.fromInterned(mod.intern_pool.typeOf(elem.base)).elemType2(mod).eql(elem_ty, mod))
1778 return (try mod.intern(.{ .ptr = .{1785 return Value.fromInterned((try mod.intern(.{ .ptr = .{
1779 .ty = elem_ptr_ty.toIntern(),1786 .ty = elem_ptr_ty.toIntern(),
1780 .addr = .{ .elem = .{1787 .addr = .{ .elem = .{
1781 .base = elem.base,1788 .base = elem.base,
1782 .index = elem.index + index,1789 .index = elem.index + index,
1783 } },1790 } },
1784 } })).toValue(),1791 } }))),
1785 else => {},1792 else => {},
1786 }1793 }
1787 break :ptr switch (ptr.len) {1794 break :ptr switch (ptr.len) {
...@@ -1794,13 +1801,13 @@ pub const Value = struct {...@@ -1794,13 +1801,13 @@ pub const Value = struct {
1794 var ptr_ty_key = mod.intern_pool.indexToKey(elem_ptr_ty.toIntern()).ptr_type;1801 var ptr_ty_key = mod.intern_pool.indexToKey(elem_ptr_ty.toIntern()).ptr_type;
1795 assert(ptr_ty_key.flags.size != .Slice);1802 assert(ptr_ty_key.flags.size != .Slice);
1796 ptr_ty_key.flags.size = .Many;1803 ptr_ty_key.flags.size = .Many;
1797 return (try mod.intern(.{ .ptr = .{1804 return Value.fromInterned((try mod.intern(.{ .ptr = .{
1798 .ty = elem_ptr_ty.toIntern(),1805 .ty = elem_ptr_ty.toIntern(),
1799 .addr = .{ .elem = .{1806 .addr = .{ .elem = .{
1800 .base = (try mod.getCoerced(ptr_val, try mod.ptrType(ptr_ty_key))).toIntern(),1807 .base = (try mod.getCoerced(ptr_val, try mod.ptrType(ptr_ty_key))).toIntern(),
1801 .index = index,1808 .index = index,
1802 } },1809 } },
1803 } })).toValue();1810 } })));
1804 }1811 }
18051812
1806 pub fn isUndef(val: Value, mod: *Module) bool {1813 pub fn isUndef(val: Value, mod: *Module) bool {
...@@ -1824,13 +1831,13 @@ pub const Value = struct {...@@ -1824,13 +1831,13 @@ pub const Value = struct {
1824 .simple_value => |v| v == .undefined,1831 .simple_value => |v| v == .undefined,
1825 .ptr => |ptr| switch (ptr.len) {1832 .ptr => |ptr| switch (ptr.len) {
1826 .none => false,1833 .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| {
1828 if (try (try val.elemValue(mod, index)).anyUndef(mod)) break true;1835 if (try (try val.elemValue(mod, index)).anyUndef(mod)) break true;
1829 } else false,1836 } else false,
1830 },1837 },
1831 .aggregate => |aggregate| for (0..aggregate.storage.values().len) |i| {1838 .aggregate => |aggregate| for (0..aggregate.storage.values().len) |i| {
1832 const elem = mod.intern_pool.indexToKey(val.toIntern()).aggregate.storage.values()[i];1839 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;
1834 } else false,1841 } else false,
1835 else => false,1842 else => false,
1836 },1843 },
...@@ -1889,7 +1896,7 @@ pub const Value = struct {...@@ -1889,7 +1896,7 @@ pub const Value = struct {
1889 return switch (mod.intern_pool.indexToKey(val.toIntern())) {1896 return switch (mod.intern_pool.indexToKey(val.toIntern())) {
1890 .opt => |opt| switch (opt.val) {1897 .opt => |opt| switch (opt.val) {
1891 .none => null,1898 .none => null,
1892 else => |payload| payload.toValue(),1899 else => |payload| Value.fromInterned(payload),
1893 },1900 },
1894 .ptr => val,1901 .ptr => val,
1895 else => unreachable,1902 else => unreachable,
...@@ -1923,10 +1930,10 @@ pub const Value = struct {...@@ -1923,10 +1930,10 @@ pub const Value = struct {
1923 const elem_val = try val.elemValue(mod, i);1930 const elem_val = try val.elemValue(mod, i);
1924 scalar.* = try (try floatFromIntScalar(elem_val, scalar_ty, mod, opt_sema)).intern(scalar_ty, mod);1931 scalar.* = try (try floatFromIntScalar(elem_val, scalar_ty, mod, opt_sema)).intern(scalar_ty, mod);
1925 }1932 }
1926 return (try mod.intern(.{ .aggregate = .{1933 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
1927 .ty = float_ty.toIntern(),1934 .ty = float_ty.toIntern(),
1928 .storage = .{ .elems = result_data },1935 .storage = .{ .elems = result_data },
1929 } })).toValue();1936 } })));
1930 }1937 }
1931 return floatFromIntScalar(val, float_ty, mod, opt_sema);1938 return floatFromIntScalar(val, float_ty, mod, opt_sema);
1932 }1939 }
...@@ -1941,14 +1948,14 @@ pub const Value = struct {...@@ -1941,14 +1948,14 @@ pub const Value = struct {
1941 },1948 },
1942 inline .u64, .i64 => |x| floatFromIntInner(x, float_ty, mod),1949 inline .u64, .i64 => |x| floatFromIntInner(x, float_ty, mod),
1943 .lazy_align => |ty| if (opt_sema) |sema| {1950 .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);
1945 } else {1952 } 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);
1947 },1954 },
1948 .lazy_size => |ty| if (opt_sema) |sema| {1955 .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);
1950 } else {1957 } else {
1951 return floatFromIntInner(ty.toType().abiSize(mod), float_ty, mod);1958 return floatFromIntInner(Type.fromInterned(ty).abiSize(mod), float_ty, mod);
1952 },1959 },
1953 },1960 },
1954 else => unreachable,1961 else => unreachable,
...@@ -1965,10 +1972,10 @@ pub const Value = struct {...@@ -1965,10 +1972,10 @@ pub const Value = struct {
1965 128 => .{ .f128 = @floatFromInt(x) },1972 128 => .{ .f128 = @floatFromInt(x) },
1966 else => unreachable,1973 else => unreachable,
1967 };1974 };
1968 return (try mod.intern(.{ .float = .{1975 return Value.fromInterned((try mod.intern(.{ .float = .{
1969 .ty = dest_ty.toIntern(),1976 .ty = dest_ty.toIntern(),
1970 .storage = storage,1977 .storage = storage,
1971 } })).toValue();1978 } })));
1972 }1979 }
19731980
1974 fn calcLimbLenFloat(scalar: anytype) usize {1981 fn calcLimbLenFloat(scalar: anytype) usize {
...@@ -2001,10 +2008,10 @@ pub const Value = struct {...@@ -2001,10 +2008,10 @@ pub const Value = struct {
2001 const rhs_elem = try rhs.elemValue(mod, i);2008 const rhs_elem = try rhs.elemValue(mod, i);
2002 scalar.* = try (try intAddSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);2009 scalar.* = try (try intAddSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2003 }2010 }
2004 return (try mod.intern(.{ .aggregate = .{2011 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2005 .ty = ty.toIntern(),2012 .ty = ty.toIntern(),
2006 .storage = .{ .elems = result_data },2013 .storage = .{ .elems = result_data },
2007 } })).toValue();2014 } })));
2008 }2015 }
2009 return intAddSatScalar(lhs, rhs, ty, arena, mod);2016 return intAddSatScalar(lhs, rhs, ty, arena, mod);
2010 }2017 }
...@@ -2051,10 +2058,10 @@ pub const Value = struct {...@@ -2051,10 +2058,10 @@ pub const Value = struct {
2051 const rhs_elem = try rhs.elemValue(mod, i);2058 const rhs_elem = try rhs.elemValue(mod, i);
2052 scalar.* = try (try intSubSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);2059 scalar.* = try (try intSubSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2053 }2060 }
2054 return (try mod.intern(.{ .aggregate = .{2061 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2055 .ty = ty.toIntern(),2062 .ty = ty.toIntern(),
2056 .storage = .{ .elems = result_data },2063 .storage = .{ .elems = result_data },
2057 } })).toValue();2064 } })));
2058 }2065 }
2059 return intSubSatScalar(lhs, rhs, ty, arena, mod);2066 return intSubSatScalar(lhs, rhs, ty, arena, mod);
2060 }2067 }
...@@ -2105,14 +2112,14 @@ pub const Value = struct {...@@ -2105,14 +2112,14 @@ pub const Value = struct {
2105 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);2112 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
2106 }2113 }
2107 return OverflowArithmeticResult{2114 return OverflowArithmeticResult{
2108 .overflow_bit = (try mod.intern(.{ .aggregate = .{2115 .overflow_bit = Value.fromInterned((try mod.intern(.{ .aggregate = .{
2109 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),2116 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),
2110 .storage = .{ .elems = overflowed_data },2117 .storage = .{ .elems = overflowed_data },
2111 } })).toValue(),2118 } }))),
2112 .wrapped_result = (try mod.intern(.{ .aggregate = .{2119 .wrapped_result = Value.fromInterned((try mod.intern(.{ .aggregate = .{
2113 .ty = ty.toIntern(),2120 .ty = ty.toIntern(),
2114 .storage = .{ .elems = result_data },2121 .storage = .{ .elems = result_data },
2115 } })).toValue(),2122 } }))),
2116 };2123 };
2117 }2124 }
2118 return intMulWithOverflowScalar(lhs, rhs, ty, arena, mod);2125 return intMulWithOverflowScalar(lhs, rhs, ty, arena, mod);
...@@ -2169,10 +2176,10 @@ pub const Value = struct {...@@ -2169,10 +2176,10 @@ pub const Value = struct {
2169 const rhs_elem = try rhs.elemValue(mod, i);2176 const rhs_elem = try rhs.elemValue(mod, i);
2170 scalar.* = try (try numberMulWrapScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);2177 scalar.* = try (try numberMulWrapScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2171 }2178 }
2172 return (try mod.intern(.{ .aggregate = .{2179 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2173 .ty = ty.toIntern(),2180 .ty = ty.toIntern(),
2174 .storage = .{ .elems = result_data },2181 .storage = .{ .elems = result_data },
2175 } })).toValue();2182 } })));
2176 }2183 }
2177 return numberMulWrapScalar(lhs, rhs, ty, arena, mod);2184 return numberMulWrapScalar(lhs, rhs, ty, arena, mod);
2178 }2185 }
...@@ -2215,10 +2222,10 @@ pub const Value = struct {...@@ -2215,10 +2222,10 @@ pub const Value = struct {
2215 const rhs_elem = try rhs.elemValue(mod, i);2222 const rhs_elem = try rhs.elemValue(mod, i);
2216 scalar.* = try (try intMulSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);2223 scalar.* = try (try intMulSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2217 }2224 }
2218 return (try mod.intern(.{ .aggregate = .{2225 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2219 .ty = ty.toIntern(),2226 .ty = ty.toIntern(),
2220 .storage = .{ .elems = result_data },2227 .storage = .{ .elems = result_data },
2221 } })).toValue();2228 } })));
2222 }2229 }
2223 return intMulSatScalar(lhs, rhs, ty, arena, mod);2230 return intMulSatScalar(lhs, rhs, ty, arena, mod);
2224 }2231 }
...@@ -2291,17 +2298,17 @@ pub const Value = struct {...@@ -2291,17 +2298,17 @@ pub const Value = struct {
2291 const elem_val = try val.elemValue(mod, i);2298 const elem_val = try val.elemValue(mod, i);
2292 scalar.* = try (try bitwiseNotScalar(elem_val, scalar_ty, arena, mod)).intern(scalar_ty, mod);2299 scalar.* = try (try bitwiseNotScalar(elem_val, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2293 }2300 }
2294 return (try mod.intern(.{ .aggregate = .{2301 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2295 .ty = ty.toIntern(),2302 .ty = ty.toIntern(),
2296 .storage = .{ .elems = result_data },2303 .storage = .{ .elems = result_data },
2297 } })).toValue();2304 } })));
2298 }2305 }
2299 return bitwiseNotScalar(val, ty, arena, mod);2306 return bitwiseNotScalar(val, ty, arena, mod);
2300 }2307 }
23012308
2302 /// operands must be integers; handles undefined.2309 /// operands must be integers; handles undefined.
2303 pub fn bitwiseNotScalar(val: Value, ty: Type, arena: Allocator, mod: *Module) !Value {2310 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() })));
2305 if (ty.toIntern() == .bool_type) return makeBool(!val.toBool());2312 if (ty.toIntern() == .bool_type) return makeBool(!val.toBool());
23062313
2307 const info = ty.intInfo(mod);2314 const info = ty.intInfo(mod);
...@@ -2334,17 +2341,17 @@ pub const Value = struct {...@@ -2334,17 +2341,17 @@ pub const Value = struct {
2334 const rhs_elem = try rhs.elemValue(mod, i);2341 const rhs_elem = try rhs.elemValue(mod, i);
2335 scalar.* = try (try bitwiseAndScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);2342 scalar.* = try (try bitwiseAndScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2336 }2343 }
2337 return (try mod.intern(.{ .aggregate = .{2344 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2338 .ty = ty.toIntern(),2345 .ty = ty.toIntern(),
2339 .storage = .{ .elems = result_data },2346 .storage = .{ .elems = result_data },
2340 } })).toValue();2347 } })));
2341 }2348 }
2342 return bitwiseAndScalar(lhs, rhs, ty, allocator, mod);2349 return bitwiseAndScalar(lhs, rhs, ty, allocator, mod);
2343 }2350 }
23442351
2345 /// operands must be integers; handles undefined.2352 /// operands must be integers; handles undefined.
2346 pub fn bitwiseAndScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {2353 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() })));
2348 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() and rhs.toBool());2355 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() and rhs.toBool());
23492356
2350 // TODO is this a performance issue? maybe we should try the operation without2357 // TODO is this a performance issue? maybe we should try the operation without
...@@ -2373,17 +2380,17 @@ pub const Value = struct {...@@ -2373,17 +2380,17 @@ pub const Value = struct {
2373 const rhs_elem = try rhs.elemValue(mod, i);2380 const rhs_elem = try rhs.elemValue(mod, i);
2374 scalar.* = try (try bitwiseNandScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);2381 scalar.* = try (try bitwiseNandScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2375 }2382 }
2376 return (try mod.intern(.{ .aggregate = .{2383 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2377 .ty = ty.toIntern(),2384 .ty = ty.toIntern(),
2378 .storage = .{ .elems = result_data },2385 .storage = .{ .elems = result_data },
2379 } })).toValue();2386 } })));
2380 }2387 }
2381 return bitwiseNandScalar(lhs, rhs, ty, arena, mod);2388 return bitwiseNandScalar(lhs, rhs, ty, arena, mod);
2382 }2389 }
23832390
2384 /// operands must be integers; handles undefined.2391 /// operands must be integers; handles undefined.
2385 pub fn bitwiseNandScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {2392 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() })));
2387 if (ty.toIntern() == .bool_type) return makeBool(!(lhs.toBool() and rhs.toBool()));2394 if (ty.toIntern() == .bool_type) return makeBool(!(lhs.toBool() and rhs.toBool()));
23882395
2389 const anded = try bitwiseAnd(lhs, rhs, ty, arena, mod);2396 const anded = try bitwiseAnd(lhs, rhs, ty, arena, mod);
...@@ -2401,17 +2408,17 @@ pub const Value = struct {...@@ -2401,17 +2408,17 @@ pub const Value = struct {
2401 const rhs_elem = try rhs.elemValue(mod, i);2408 const rhs_elem = try rhs.elemValue(mod, i);
2402 scalar.* = try (try bitwiseOrScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);2409 scalar.* = try (try bitwiseOrScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2403 }2410 }
2404 return (try mod.intern(.{ .aggregate = .{2411 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2405 .ty = ty.toIntern(),2412 .ty = ty.toIntern(),
2406 .storage = .{ .elems = result_data },2413 .storage = .{ .elems = result_data },
2407 } })).toValue();2414 } })));
2408 }2415 }
2409 return bitwiseOrScalar(lhs, rhs, ty, allocator, mod);2416 return bitwiseOrScalar(lhs, rhs, ty, allocator, mod);
2410 }2417 }
24112418
2412 /// operands must be integers; handles undefined.2419 /// operands must be integers; handles undefined.
2413 pub fn bitwiseOrScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {2420 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() })));
2415 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() or rhs.toBool());2422 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() or rhs.toBool());
24162423
2417 // TODO is this a performance issue? maybe we should try the operation without2424 // TODO is this a performance issue? maybe we should try the operation without
...@@ -2439,17 +2446,17 @@ pub const Value = struct {...@@ -2439,17 +2446,17 @@ pub const Value = struct {
2439 const rhs_elem = try rhs.elemValue(mod, i);2446 const rhs_elem = try rhs.elemValue(mod, i);
2440 scalar.* = try (try bitwiseXorScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);2447 scalar.* = try (try bitwiseXorScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2441 }2448 }
2442 return (try mod.intern(.{ .aggregate = .{2449 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2443 .ty = ty.toIntern(),2450 .ty = ty.toIntern(),
2444 .storage = .{ .elems = result_data },2451 .storage = .{ .elems = result_data },
2445 } })).toValue();2452 } })));
2446 }2453 }
2447 return bitwiseXorScalar(lhs, rhs, ty, allocator, mod);2454 return bitwiseXorScalar(lhs, rhs, ty, allocator, mod);
2448 }2455 }
24492456
2450 /// operands must be integers; handles undefined.2457 /// operands must be integers; handles undefined.
2451 pub fn bitwiseXorScalar(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {2458 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() })));
2453 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() != rhs.toBool());2460 if (ty.toIntern() == .bool_type) return makeBool(lhs.toBool() != rhs.toBool());
24542461
2455 // TODO is this a performance issue? maybe we should try the operation without2462 // TODO is this a performance issue? maybe we should try the operation without
...@@ -2505,10 +2512,10 @@ pub const Value = struct {...@@ -2505,10 +2512,10 @@ pub const Value = struct {
2505 };2512 };
2506 scalar.* = try val.intern(scalar_ty, mod);2513 scalar.* = try val.intern(scalar_ty, mod);
2507 }2514 }
2508 return (try mod.intern(.{ .aggregate = .{2515 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2509 .ty = ty.toIntern(),2516 .ty = ty.toIntern(),
2510 .storage = .{ .elems = result_data },2517 .storage = .{ .elems = result_data },
2511 } })).toValue();2518 } })));
2512 }2519 }
2513 return intDivScalar(lhs, rhs, ty, allocator, mod);2520 return intDivScalar(lhs, rhs, ty, allocator, mod);
2514 }2521 }
...@@ -2553,10 +2560,10 @@ pub const Value = struct {...@@ -2553,10 +2560,10 @@ pub const Value = struct {
2553 const rhs_elem = try rhs.elemValue(mod, i);2560 const rhs_elem = try rhs.elemValue(mod, i);
2554 scalar.* = try (try intDivFloorScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);2561 scalar.* = try (try intDivFloorScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2555 }2562 }
2556 return (try mod.intern(.{ .aggregate = .{2563 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2557 .ty = ty.toIntern(),2564 .ty = ty.toIntern(),
2558 .storage = .{ .elems = result_data },2565 .storage = .{ .elems = result_data },
2559 } })).toValue();2566 } })));
2560 }2567 }
2561 return intDivFloorScalar(lhs, rhs, ty, allocator, mod);2568 return intDivFloorScalar(lhs, rhs, ty, allocator, mod);
2562 }2569 }
...@@ -2595,10 +2602,10 @@ pub const Value = struct {...@@ -2595,10 +2602,10 @@ pub const Value = struct {
2595 const rhs_elem = try rhs.elemValue(mod, i);2602 const rhs_elem = try rhs.elemValue(mod, i);
2596 scalar.* = try (try intModScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);2603 scalar.* = try (try intModScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2597 }2604 }
2598 return (try mod.intern(.{ .aggregate = .{2605 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2599 .ty = ty.toIntern(),2606 .ty = ty.toIntern(),
2600 .storage = .{ .elems = result_data },2607 .storage = .{ .elems = result_data },
2601 } })).toValue();2608 } })));
2602 }2609 }
2603 return intModScalar(lhs, rhs, ty, allocator, mod);2610 return intModScalar(lhs, rhs, ty, allocator, mod);
2604 }2611 }
...@@ -2669,10 +2676,10 @@ pub const Value = struct {...@@ -2669,10 +2676,10 @@ pub const Value = struct {
2669 const rhs_elem = try rhs.elemValue(mod, i);2676 const rhs_elem = try rhs.elemValue(mod, i);
2670 scalar.* = try (try floatRemScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);2677 scalar.* = try (try floatRemScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
2671 }2678 }
2672 return (try mod.intern(.{ .aggregate = .{2679 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2673 .ty = float_type.toIntern(),2680 .ty = float_type.toIntern(),
2674 .storage = .{ .elems = result_data },2681 .storage = .{ .elems = result_data },
2675 } })).toValue();2682 } })));
2676 }2683 }
2677 return floatRemScalar(lhs, rhs, float_type, mod);2684 return floatRemScalar(lhs, rhs, float_type, mod);
2678 }2685 }
...@@ -2687,10 +2694,10 @@ pub const Value = struct {...@@ -2687,10 +2694,10 @@ pub const Value = struct {
2687 128 => .{ .f128 = @rem(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },2694 128 => .{ .f128 = @rem(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },
2688 else => unreachable,2695 else => unreachable,
2689 };2696 };
2690 return (try mod.intern(.{ .float = .{2697 return Value.fromInterned((try mod.intern(.{ .float = .{
2691 .ty = float_type.toIntern(),2698 .ty = float_type.toIntern(),
2692 .storage = storage,2699 .storage = storage,
2693 } })).toValue();2700 } })));
2694 }2701 }
26952702
2696 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {2703 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -2702,10 +2709,10 @@ pub const Value = struct {...@@ -2702,10 +2709,10 @@ pub const Value = struct {
2702 const rhs_elem = try rhs.elemValue(mod, i);2709 const rhs_elem = try rhs.elemValue(mod, i);
2703 scalar.* = try (try floatModScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);2710 scalar.* = try (try floatModScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
2704 }2711 }
2705 return (try mod.intern(.{ .aggregate = .{2712 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2706 .ty = float_type.toIntern(),2713 .ty = float_type.toIntern(),
2707 .storage = .{ .elems = result_data },2714 .storage = .{ .elems = result_data },
2708 } })).toValue();2715 } })));
2709 }2716 }
2710 return floatModScalar(lhs, rhs, float_type, mod);2717 return floatModScalar(lhs, rhs, float_type, mod);
2711 }2718 }
...@@ -2720,10 +2727,10 @@ pub const Value = struct {...@@ -2720,10 +2727,10 @@ pub const Value = struct {
2720 128 => .{ .f128 = @mod(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },2727 128 => .{ .f128 = @mod(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },
2721 else => unreachable,2728 else => unreachable,
2722 };2729 };
2723 return (try mod.intern(.{ .float = .{2730 return Value.fromInterned((try mod.intern(.{ .float = .{
2724 .ty = float_type.toIntern(),2731 .ty = float_type.toIntern(),
2725 .storage = storage,2732 .storage = storage,
2726 } })).toValue();2733 } })));
2727 }2734 }
27282735
2729 /// If the value overflowed the type, returns a comptime_int (or vector thereof) instead, setting2736 /// If the value overflowed the type, returns a comptime_int (or vector thereof) instead, setting
...@@ -2763,10 +2770,10 @@ pub const Value = struct {...@@ -2763,10 +2770,10 @@ pub const Value = struct {
2763 };2770 };
2764 scalar.* = try val.intern(scalar_ty, mod);2771 scalar.* = try val.intern(scalar_ty, mod);
2765 }2772 }
2766 return (try mod.intern(.{ .aggregate = .{2773 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2767 .ty = ty.toIntern(),2774 .ty = ty.toIntern(),
2768 .storage = .{ .elems = result_data },2775 .storage = .{ .elems = result_data },
2769 } })).toValue();2776 } })));
2770 }2777 }
2771 return intMulScalar(lhs, rhs, ty, allocator, mod);2778 return intMulScalar(lhs, rhs, ty, allocator, mod);
2772 }2779 }
...@@ -2805,10 +2812,10 @@ pub const Value = struct {...@@ -2805,10 +2812,10 @@ pub const Value = struct {
2805 const elem_val = try val.elemValue(mod, i);2812 const elem_val = try val.elemValue(mod, i);
2806 scalar.* = try (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, bits, mod)).intern(scalar_ty, mod);2813 scalar.* = try (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, bits, mod)).intern(scalar_ty, mod);
2807 }2814 }
2808 return (try mod.intern(.{ .aggregate = .{2815 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2809 .ty = ty.toIntern(),2816 .ty = ty.toIntern(),
2810 .storage = .{ .elems = result_data },2817 .storage = .{ .elems = result_data },
2811 } })).toValue();2818 } })));
2812 }2819 }
2813 return intTruncScalar(val, ty, allocator, signedness, bits, mod);2820 return intTruncScalar(val, ty, allocator, signedness, bits, mod);
2814 }2821 }
...@@ -2830,10 +2837,10 @@ pub const Value = struct {...@@ -2830,10 +2837,10 @@ pub const Value = struct {
2830 const bits_elem = try bits.elemValue(mod, i);2837 const bits_elem = try bits.elemValue(mod, i);
2831 scalar.* = try (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @as(u16, @intCast(bits_elem.toUnsignedInt(mod))), mod)).intern(scalar_ty, mod);2838 scalar.* = try (try intTruncScalar(elem_val, scalar_ty, allocator, signedness, @as(u16, @intCast(bits_elem.toUnsignedInt(mod))), mod)).intern(scalar_ty, mod);
2832 }2839 }
2833 return (try mod.intern(.{ .aggregate = .{2840 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2834 .ty = ty.toIntern(),2841 .ty = ty.toIntern(),
2835 .storage = .{ .elems = result_data },2842 .storage = .{ .elems = result_data },
2836 } })).toValue();2843 } })));
2837 }2844 }
2838 return intTruncScalar(val, ty, allocator, signedness, @as(u16, @intCast(bits.toUnsignedInt(mod))), mod);2845 return intTruncScalar(val, ty, allocator, signedness, @as(u16, @intCast(bits.toUnsignedInt(mod))), mod);
2839 }2846 }
...@@ -2870,10 +2877,10 @@ pub const Value = struct {...@@ -2870,10 +2877,10 @@ pub const Value = struct {
2870 const rhs_elem = try rhs.elemValue(mod, i);2877 const rhs_elem = try rhs.elemValue(mod, i);
2871 scalar.* = try (try shlScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);2878 scalar.* = try (try shlScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
2872 }2879 }
2873 return (try mod.intern(.{ .aggregate = .{2880 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2874 .ty = ty.toIntern(),2881 .ty = ty.toIntern(),
2875 .storage = .{ .elems = result_data },2882 .storage = .{ .elems = result_data },
2876 } })).toValue();2883 } })));
2877 }2884 }
2878 return shlScalar(lhs, rhs, ty, allocator, mod);2885 return shlScalar(lhs, rhs, ty, allocator, mod);
2879 }2886 }
...@@ -2922,14 +2929,14 @@ pub const Value = struct {...@@ -2922,14 +2929,14 @@ pub const Value = struct {
2922 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);2929 scalar.* = try of_math_result.wrapped_result.intern(scalar_ty, mod);
2923 }2930 }
2924 return OverflowArithmeticResult{2931 return OverflowArithmeticResult{
2925 .overflow_bit = (try mod.intern(.{ .aggregate = .{2932 .overflow_bit = Value.fromInterned((try mod.intern(.{ .aggregate = .{
2926 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),2933 .ty = (try mod.vectorType(.{ .len = vec_len, .child = .u1_type })).toIntern(),
2927 .storage = .{ .elems = overflowed_data },2934 .storage = .{ .elems = overflowed_data },
2928 } })).toValue(),2935 } }))),
2929 .wrapped_result = (try mod.intern(.{ .aggregate = .{2936 .wrapped_result = Value.fromInterned((try mod.intern(.{ .aggregate = .{
2930 .ty = ty.toIntern(),2937 .ty = ty.toIntern(),
2931 .storage = .{ .elems = result_data },2938 .storage = .{ .elems = result_data },
2932 } })).toValue(),2939 } }))),
2933 };2940 };
2934 }2941 }
2935 return shlWithOverflowScalar(lhs, rhs, ty, allocator, mod);2942 return shlWithOverflowScalar(lhs, rhs, ty, allocator, mod);
...@@ -2981,10 +2988,10 @@ pub const Value = struct {...@@ -2981,10 +2988,10 @@ pub const Value = struct {
2981 const rhs_elem = try rhs.elemValue(mod, i);2988 const rhs_elem = try rhs.elemValue(mod, i);
2982 scalar.* = try (try shlSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);2989 scalar.* = try (try shlSatScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
2983 }2990 }
2984 return (try mod.intern(.{ .aggregate = .{2991 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
2985 .ty = ty.toIntern(),2992 .ty = ty.toIntern(),
2986 .storage = .{ .elems = result_data },2993 .storage = .{ .elems = result_data },
2987 } })).toValue();2994 } })));
2988 }2995 }
2989 return shlSatScalar(lhs, rhs, ty, arena, mod);2996 return shlSatScalar(lhs, rhs, ty, arena, mod);
2990 }2997 }
...@@ -3031,10 +3038,10 @@ pub const Value = struct {...@@ -3031,10 +3038,10 @@ pub const Value = struct {
3031 const rhs_elem = try rhs.elemValue(mod, i);3038 const rhs_elem = try rhs.elemValue(mod, i);
3032 scalar.* = try (try shlTruncScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);3039 scalar.* = try (try shlTruncScalar(lhs_elem, rhs_elem, scalar_ty, arena, mod)).intern(scalar_ty, mod);
3033 }3040 }
3034 return (try mod.intern(.{ .aggregate = .{3041 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3035 .ty = ty.toIntern(),3042 .ty = ty.toIntern(),
3036 .storage = .{ .elems = result_data },3043 .storage = .{ .elems = result_data },
3037 } })).toValue();3044 } })));
3038 }3045 }
3039 return shlTruncScalar(lhs, rhs, ty, arena, mod);3046 return shlTruncScalar(lhs, rhs, ty, arena, mod);
3040 }3047 }
...@@ -3061,10 +3068,10 @@ pub const Value = struct {...@@ -3061,10 +3068,10 @@ pub const Value = struct {
3061 const rhs_elem = try rhs.elemValue(mod, i);3068 const rhs_elem = try rhs.elemValue(mod, i);
3062 scalar.* = try (try shrScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);3069 scalar.* = try (try shrScalar(lhs_elem, rhs_elem, scalar_ty, allocator, mod)).intern(scalar_ty, mod);
3063 }3070 }
3064 return (try mod.intern(.{ .aggregate = .{3071 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3065 .ty = ty.toIntern(),3072 .ty = ty.toIntern(),
3066 .storage = .{ .elems = result_data },3073 .storage = .{ .elems = result_data },
3067 } })).toValue();3074 } })));
3068 }3075 }
3069 return shrScalar(lhs, rhs, ty, allocator, mod);3076 return shrScalar(lhs, rhs, ty, allocator, mod);
3070 }3077 }
...@@ -3113,10 +3120,10 @@ pub const Value = struct {...@@ -3113,10 +3120,10 @@ pub const Value = struct {
3113 const elem_val = try val.elemValue(mod, i);3120 const elem_val = try val.elemValue(mod, i);
3114 scalar.* = try (try floatNegScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3121 scalar.* = try (try floatNegScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3115 }3122 }
3116 return (try mod.intern(.{ .aggregate = .{3123 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3117 .ty = float_type.toIntern(),3124 .ty = float_type.toIntern(),
3118 .storage = .{ .elems = result_data },3125 .storage = .{ .elems = result_data },
3119 } })).toValue();3126 } })));
3120 }3127 }
3121 return floatNegScalar(val, float_type, mod);3128 return floatNegScalar(val, float_type, mod);
3122 }3129 }
...@@ -3135,10 +3142,10 @@ pub const Value = struct {...@@ -3135,10 +3142,10 @@ pub const Value = struct {
3135 128 => .{ .f128 = -val.toFloat(f128, mod) },3142 128 => .{ .f128 = -val.toFloat(f128, mod) },
3136 else => unreachable,3143 else => unreachable,
3137 };3144 };
3138 return (try mod.intern(.{ .float = .{3145 return Value.fromInterned((try mod.intern(.{ .float = .{
3139 .ty = float_type.toIntern(),3146 .ty = float_type.toIntern(),
3140 .storage = storage,3147 .storage = storage,
3141 } })).toValue();3148 } })));
3142 }3149 }
31433150
3144 pub fn floatAdd(3151 pub fn floatAdd(
...@@ -3156,10 +3163,10 @@ pub const Value = struct {...@@ -3156,10 +3163,10 @@ pub const Value = struct {
3156 const rhs_elem = try rhs.elemValue(mod, i);3163 const rhs_elem = try rhs.elemValue(mod, i);
3157 scalar.* = try (try floatAddScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);3164 scalar.* = try (try floatAddScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
3158 }3165 }
3159 return (try mod.intern(.{ .aggregate = .{3166 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3160 .ty = float_type.toIntern(),3167 .ty = float_type.toIntern(),
3161 .storage = .{ .elems = result_data },3168 .storage = .{ .elems = result_data },
3162 } })).toValue();3169 } })));
3163 }3170 }
3164 return floatAddScalar(lhs, rhs, float_type, mod);3171 return floatAddScalar(lhs, rhs, float_type, mod);
3165 }3172 }
...@@ -3179,10 +3186,10 @@ pub const Value = struct {...@@ -3179,10 +3186,10 @@ pub const Value = struct {
3179 128 => .{ .f128 = lhs.toFloat(f128, mod) + rhs.toFloat(f128, mod) },3186 128 => .{ .f128 = lhs.toFloat(f128, mod) + rhs.toFloat(f128, mod) },
3180 else => unreachable,3187 else => unreachable,
3181 };3188 };
3182 return (try mod.intern(.{ .float = .{3189 return Value.fromInterned((try mod.intern(.{ .float = .{
3183 .ty = float_type.toIntern(),3190 .ty = float_type.toIntern(),
3184 .storage = storage,3191 .storage = storage,
3185 } })).toValue();3192 } })));
3186 }3193 }
31873194
3188 pub fn floatSub(3195 pub fn floatSub(
...@@ -3200,10 +3207,10 @@ pub const Value = struct {...@@ -3200,10 +3207,10 @@ pub const Value = struct {
3200 const rhs_elem = try rhs.elemValue(mod, i);3207 const rhs_elem = try rhs.elemValue(mod, i);
3201 scalar.* = try (try floatSubScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);3208 scalar.* = try (try floatSubScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
3202 }3209 }
3203 return (try mod.intern(.{ .aggregate = .{3210 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3204 .ty = float_type.toIntern(),3211 .ty = float_type.toIntern(),
3205 .storage = .{ .elems = result_data },3212 .storage = .{ .elems = result_data },
3206 } })).toValue();3213 } })));
3207 }3214 }
3208 return floatSubScalar(lhs, rhs, float_type, mod);3215 return floatSubScalar(lhs, rhs, float_type, mod);
3209 }3216 }
...@@ -3223,10 +3230,10 @@ pub const Value = struct {...@@ -3223,10 +3230,10 @@ pub const Value = struct {
3223 128 => .{ .f128 = lhs.toFloat(f128, mod) - rhs.toFloat(f128, mod) },3230 128 => .{ .f128 = lhs.toFloat(f128, mod) - rhs.toFloat(f128, mod) },
3224 else => unreachable,3231 else => unreachable,
3225 };3232 };
3226 return (try mod.intern(.{ .float = .{3233 return Value.fromInterned((try mod.intern(.{ .float = .{
3227 .ty = float_type.toIntern(),3234 .ty = float_type.toIntern(),
3228 .storage = storage,3235 .storage = storage,
3229 } })).toValue();3236 } })));
3230 }3237 }
32313238
3232 pub fn floatDiv(3239 pub fn floatDiv(
...@@ -3244,10 +3251,10 @@ pub const Value = struct {...@@ -3244,10 +3251,10 @@ pub const Value = struct {
3244 const rhs_elem = try rhs.elemValue(mod, i);3251 const rhs_elem = try rhs.elemValue(mod, i);
3245 scalar.* = try (try floatDivScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);3252 scalar.* = try (try floatDivScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
3246 }3253 }
3247 return (try mod.intern(.{ .aggregate = .{3254 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3248 .ty = float_type.toIntern(),3255 .ty = float_type.toIntern(),
3249 .storage = .{ .elems = result_data },3256 .storage = .{ .elems = result_data },
3250 } })).toValue();3257 } })));
3251 }3258 }
3252 return floatDivScalar(lhs, rhs, float_type, mod);3259 return floatDivScalar(lhs, rhs, float_type, mod);
3253 }3260 }
...@@ -3267,10 +3274,10 @@ pub const Value = struct {...@@ -3267,10 +3274,10 @@ pub const Value = struct {
3267 128 => .{ .f128 = lhs.toFloat(f128, mod) / rhs.toFloat(f128, mod) },3274 128 => .{ .f128 = lhs.toFloat(f128, mod) / rhs.toFloat(f128, mod) },
3268 else => unreachable,3275 else => unreachable,
3269 };3276 };
3270 return (try mod.intern(.{ .float = .{3277 return Value.fromInterned((try mod.intern(.{ .float = .{
3271 .ty = float_type.toIntern(),3278 .ty = float_type.toIntern(),
3272 .storage = storage,3279 .storage = storage,
3273 } })).toValue();3280 } })));
3274 }3281 }
32753282
3276 pub fn floatDivFloor(3283 pub fn floatDivFloor(
...@@ -3288,10 +3295,10 @@ pub const Value = struct {...@@ -3288,10 +3295,10 @@ pub const Value = struct {
3288 const rhs_elem = try rhs.elemValue(mod, i);3295 const rhs_elem = try rhs.elemValue(mod, i);
3289 scalar.* = try (try floatDivFloorScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);3296 scalar.* = try (try floatDivFloorScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
3290 }3297 }
3291 return (try mod.intern(.{ .aggregate = .{3298 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3292 .ty = float_type.toIntern(),3299 .ty = float_type.toIntern(),
3293 .storage = .{ .elems = result_data },3300 .storage = .{ .elems = result_data },
3294 } })).toValue();3301 } })));
3295 }3302 }
3296 return floatDivFloorScalar(lhs, rhs, float_type, mod);3303 return floatDivFloorScalar(lhs, rhs, float_type, mod);
3297 }3304 }
...@@ -3311,10 +3318,10 @@ pub const Value = struct {...@@ -3311,10 +3318,10 @@ pub const Value = struct {
3311 128 => .{ .f128 = @divFloor(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },3318 128 => .{ .f128 = @divFloor(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },
3312 else => unreachable,3319 else => unreachable,
3313 };3320 };
3314 return (try mod.intern(.{ .float = .{3321 return Value.fromInterned((try mod.intern(.{ .float = .{
3315 .ty = float_type.toIntern(),3322 .ty = float_type.toIntern(),
3316 .storage = storage,3323 .storage = storage,
3317 } })).toValue();3324 } })));
3318 }3325 }
33193326
3320 pub fn floatDivTrunc(3327 pub fn floatDivTrunc(
...@@ -3332,10 +3339,10 @@ pub const Value = struct {...@@ -3332,10 +3339,10 @@ pub const Value = struct {
3332 const rhs_elem = try rhs.elemValue(mod, i);3339 const rhs_elem = try rhs.elemValue(mod, i);
3333 scalar.* = try (try floatDivTruncScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);3340 scalar.* = try (try floatDivTruncScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
3334 }3341 }
3335 return (try mod.intern(.{ .aggregate = .{3342 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3336 .ty = float_type.toIntern(),3343 .ty = float_type.toIntern(),
3337 .storage = .{ .elems = result_data },3344 .storage = .{ .elems = result_data },
3338 } })).toValue();3345 } })));
3339 }3346 }
3340 return floatDivTruncScalar(lhs, rhs, float_type, mod);3347 return floatDivTruncScalar(lhs, rhs, float_type, mod);
3341 }3348 }
...@@ -3355,10 +3362,10 @@ pub const Value = struct {...@@ -3355,10 +3362,10 @@ pub const Value = struct {
3355 128 => .{ .f128 = @divTrunc(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },3362 128 => .{ .f128 = @divTrunc(lhs.toFloat(f128, mod), rhs.toFloat(f128, mod)) },
3356 else => unreachable,3363 else => unreachable,
3357 };3364 };
3358 return (try mod.intern(.{ .float = .{3365 return Value.fromInterned((try mod.intern(.{ .float = .{
3359 .ty = float_type.toIntern(),3366 .ty = float_type.toIntern(),
3360 .storage = storage,3367 .storage = storage,
3361 } })).toValue();3368 } })));
3362 }3369 }
33633370
3364 pub fn floatMul(3371 pub fn floatMul(
...@@ -3376,10 +3383,10 @@ pub const Value = struct {...@@ -3376,10 +3383,10 @@ pub const Value = struct {
3376 const rhs_elem = try rhs.elemValue(mod, i);3383 const rhs_elem = try rhs.elemValue(mod, i);
3377 scalar.* = try (try floatMulScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);3384 scalar.* = try (try floatMulScalar(lhs_elem, rhs_elem, scalar_ty, mod)).intern(scalar_ty, mod);
3378 }3385 }
3379 return (try mod.intern(.{ .aggregate = .{3386 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3380 .ty = float_type.toIntern(),3387 .ty = float_type.toIntern(),
3381 .storage = .{ .elems = result_data },3388 .storage = .{ .elems = result_data },
3382 } })).toValue();3389 } })));
3383 }3390 }
3384 return floatMulScalar(lhs, rhs, float_type, mod);3391 return floatMulScalar(lhs, rhs, float_type, mod);
3385 }3392 }
...@@ -3399,10 +3406,10 @@ pub const Value = struct {...@@ -3399,10 +3406,10 @@ pub const Value = struct {
3399 128 => .{ .f128 = lhs.toFloat(f128, mod) * rhs.toFloat(f128, mod) },3406 128 => .{ .f128 = lhs.toFloat(f128, mod) * rhs.toFloat(f128, mod) },
3400 else => unreachable,3407 else => unreachable,
3401 };3408 };
3402 return (try mod.intern(.{ .float = .{3409 return Value.fromInterned((try mod.intern(.{ .float = .{
3403 .ty = float_type.toIntern(),3410 .ty = float_type.toIntern(),
3404 .storage = storage,3411 .storage = storage,
3405 } })).toValue();3412 } })));
3406 }3413 }
34073414
3408 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3415 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3413,10 +3420,10 @@ pub const Value = struct {...@@ -3413,10 +3420,10 @@ pub const Value = struct {
3413 const elem_val = try val.elemValue(mod, i);3420 const elem_val = try val.elemValue(mod, i);
3414 scalar.* = try (try sqrtScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3421 scalar.* = try (try sqrtScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3415 }3422 }
3416 return (try mod.intern(.{ .aggregate = .{3423 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3417 .ty = float_type.toIntern(),3424 .ty = float_type.toIntern(),
3418 .storage = .{ .elems = result_data },3425 .storage = .{ .elems = result_data },
3419 } })).toValue();3426 } })));
3420 }3427 }
3421 return sqrtScalar(val, float_type, mod);3428 return sqrtScalar(val, float_type, mod);
3422 }3429 }
...@@ -3431,10 +3438,10 @@ pub const Value = struct {...@@ -3431,10 +3438,10 @@ pub const Value = struct {
3431 128 => .{ .f128 = @sqrt(val.toFloat(f128, mod)) },3438 128 => .{ .f128 = @sqrt(val.toFloat(f128, mod)) },
3432 else => unreachable,3439 else => unreachable,
3433 };3440 };
3434 return (try mod.intern(.{ .float = .{3441 return Value.fromInterned((try mod.intern(.{ .float = .{
3435 .ty = float_type.toIntern(),3442 .ty = float_type.toIntern(),
3436 .storage = storage,3443 .storage = storage,
3437 } })).toValue();3444 } })));
3438 }3445 }
34393446
3440 pub fn sin(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3447 pub fn sin(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3445,10 +3452,10 @@ pub const Value = struct {...@@ -3445,10 +3452,10 @@ pub const Value = struct {
3445 const elem_val = try val.elemValue(mod, i);3452 const elem_val = try val.elemValue(mod, i);
3446 scalar.* = try (try sinScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3453 scalar.* = try (try sinScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3447 }3454 }
3448 return (try mod.intern(.{ .aggregate = .{3455 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3449 .ty = float_type.toIntern(),3456 .ty = float_type.toIntern(),
3450 .storage = .{ .elems = result_data },3457 .storage = .{ .elems = result_data },
3451 } })).toValue();3458 } })));
3452 }3459 }
3453 return sinScalar(val, float_type, mod);3460 return sinScalar(val, float_type, mod);
3454 }3461 }
...@@ -3463,10 +3470,10 @@ pub const Value = struct {...@@ -3463,10 +3470,10 @@ pub const Value = struct {
3463 128 => .{ .f128 = @sin(val.toFloat(f128, mod)) },3470 128 => .{ .f128 = @sin(val.toFloat(f128, mod)) },
3464 else => unreachable,3471 else => unreachable,
3465 };3472 };
3466 return (try mod.intern(.{ .float = .{3473 return Value.fromInterned((try mod.intern(.{ .float = .{
3467 .ty = float_type.toIntern(),3474 .ty = float_type.toIntern(),
3468 .storage = storage,3475 .storage = storage,
3469 } })).toValue();3476 } })));
3470 }3477 }
34713478
3472 pub fn cos(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3479 pub fn cos(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3477,10 +3484,10 @@ pub const Value = struct {...@@ -3477,10 +3484,10 @@ pub const Value = struct {
3477 const elem_val = try val.elemValue(mod, i);3484 const elem_val = try val.elemValue(mod, i);
3478 scalar.* = try (try cosScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3485 scalar.* = try (try cosScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3479 }3486 }
3480 return (try mod.intern(.{ .aggregate = .{3487 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3481 .ty = float_type.toIntern(),3488 .ty = float_type.toIntern(),
3482 .storage = .{ .elems = result_data },3489 .storage = .{ .elems = result_data },
3483 } })).toValue();3490 } })));
3484 }3491 }
3485 return cosScalar(val, float_type, mod);3492 return cosScalar(val, float_type, mod);
3486 }3493 }
...@@ -3495,10 +3502,10 @@ pub const Value = struct {...@@ -3495,10 +3502,10 @@ pub const Value = struct {
3495 128 => .{ .f128 = @cos(val.toFloat(f128, mod)) },3502 128 => .{ .f128 = @cos(val.toFloat(f128, mod)) },
3496 else => unreachable,3503 else => unreachable,
3497 };3504 };
3498 return (try mod.intern(.{ .float = .{3505 return Value.fromInterned((try mod.intern(.{ .float = .{
3499 .ty = float_type.toIntern(),3506 .ty = float_type.toIntern(),
3500 .storage = storage,3507 .storage = storage,
3501 } })).toValue();3508 } })));
3502 }3509 }
35033510
3504 pub fn tan(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3511 pub fn tan(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3509,10 +3516,10 @@ pub const Value = struct {...@@ -3509,10 +3516,10 @@ pub const Value = struct {
3509 const elem_val = try val.elemValue(mod, i);3516 const elem_val = try val.elemValue(mod, i);
3510 scalar.* = try (try tanScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3517 scalar.* = try (try tanScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3511 }3518 }
3512 return (try mod.intern(.{ .aggregate = .{3519 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3513 .ty = float_type.toIntern(),3520 .ty = float_type.toIntern(),
3514 .storage = .{ .elems = result_data },3521 .storage = .{ .elems = result_data },
3515 } })).toValue();3522 } })));
3516 }3523 }
3517 return tanScalar(val, float_type, mod);3524 return tanScalar(val, float_type, mod);
3518 }3525 }
...@@ -3527,10 +3534,10 @@ pub const Value = struct {...@@ -3527,10 +3534,10 @@ pub const Value = struct {
3527 128 => .{ .f128 = @tan(val.toFloat(f128, mod)) },3534 128 => .{ .f128 = @tan(val.toFloat(f128, mod)) },
3528 else => unreachable,3535 else => unreachable,
3529 };3536 };
3530 return (try mod.intern(.{ .float = .{3537 return Value.fromInterned((try mod.intern(.{ .float = .{
3531 .ty = float_type.toIntern(),3538 .ty = float_type.toIntern(),
3532 .storage = storage,3539 .storage = storage,
3533 } })).toValue();3540 } })));
3534 }3541 }
35353542
3536 pub fn exp(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3543 pub fn exp(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3541,10 +3548,10 @@ pub const Value = struct {...@@ -3541,10 +3548,10 @@ pub const Value = struct {
3541 const elem_val = try val.elemValue(mod, i);3548 const elem_val = try val.elemValue(mod, i);
3542 scalar.* = try (try expScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3549 scalar.* = try (try expScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3543 }3550 }
3544 return (try mod.intern(.{ .aggregate = .{3551 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3545 .ty = float_type.toIntern(),3552 .ty = float_type.toIntern(),
3546 .storage = .{ .elems = result_data },3553 .storage = .{ .elems = result_data },
3547 } })).toValue();3554 } })));
3548 }3555 }
3549 return expScalar(val, float_type, mod);3556 return expScalar(val, float_type, mod);
3550 }3557 }
...@@ -3559,10 +3566,10 @@ pub const Value = struct {...@@ -3559,10 +3566,10 @@ pub const Value = struct {
3559 128 => .{ .f128 = @exp(val.toFloat(f128, mod)) },3566 128 => .{ .f128 = @exp(val.toFloat(f128, mod)) },
3560 else => unreachable,3567 else => unreachable,
3561 };3568 };
3562 return (try mod.intern(.{ .float = .{3569 return Value.fromInterned((try mod.intern(.{ .float = .{
3563 .ty = float_type.toIntern(),3570 .ty = float_type.toIntern(),
3564 .storage = storage,3571 .storage = storage,
3565 } })).toValue();3572 } })));
3566 }3573 }
35673574
3568 pub fn exp2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3575 pub fn exp2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3573,10 +3580,10 @@ pub const Value = struct {...@@ -3573,10 +3580,10 @@ pub const Value = struct {
3573 const elem_val = try val.elemValue(mod, i);3580 const elem_val = try val.elemValue(mod, i);
3574 scalar.* = try (try exp2Scalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3581 scalar.* = try (try exp2Scalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3575 }3582 }
3576 return (try mod.intern(.{ .aggregate = .{3583 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3577 .ty = float_type.toIntern(),3584 .ty = float_type.toIntern(),
3578 .storage = .{ .elems = result_data },3585 .storage = .{ .elems = result_data },
3579 } })).toValue();3586 } })));
3580 }3587 }
3581 return exp2Scalar(val, float_type, mod);3588 return exp2Scalar(val, float_type, mod);
3582 }3589 }
...@@ -3591,10 +3598,10 @@ pub const Value = struct {...@@ -3591,10 +3598,10 @@ pub const Value = struct {
3591 128 => .{ .f128 = @exp2(val.toFloat(f128, mod)) },3598 128 => .{ .f128 = @exp2(val.toFloat(f128, mod)) },
3592 else => unreachable,3599 else => unreachable,
3593 };3600 };
3594 return (try mod.intern(.{ .float = .{3601 return Value.fromInterned((try mod.intern(.{ .float = .{
3595 .ty = float_type.toIntern(),3602 .ty = float_type.toIntern(),
3596 .storage = storage,3603 .storage = storage,
3597 } })).toValue();3604 } })));
3598 }3605 }
35993606
3600 pub fn log(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3607 pub fn log(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3605,10 +3612,10 @@ pub const Value = struct {...@@ -3605,10 +3612,10 @@ pub const Value = struct {
3605 const elem_val = try val.elemValue(mod, i);3612 const elem_val = try val.elemValue(mod, i);
3606 scalar.* = try (try logScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3613 scalar.* = try (try logScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3607 }3614 }
3608 return (try mod.intern(.{ .aggregate = .{3615 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3609 .ty = float_type.toIntern(),3616 .ty = float_type.toIntern(),
3610 .storage = .{ .elems = result_data },3617 .storage = .{ .elems = result_data },
3611 } })).toValue();3618 } })));
3612 }3619 }
3613 return logScalar(val, float_type, mod);3620 return logScalar(val, float_type, mod);
3614 }3621 }
...@@ -3623,10 +3630,10 @@ pub const Value = struct {...@@ -3623,10 +3630,10 @@ pub const Value = struct {
3623 128 => .{ .f128 = @log(val.toFloat(f128, mod)) },3630 128 => .{ .f128 = @log(val.toFloat(f128, mod)) },
3624 else => unreachable,3631 else => unreachable,
3625 };3632 };
3626 return (try mod.intern(.{ .float = .{3633 return Value.fromInterned((try mod.intern(.{ .float = .{
3627 .ty = float_type.toIntern(),3634 .ty = float_type.toIntern(),
3628 .storage = storage,3635 .storage = storage,
3629 } })).toValue();3636 } })));
3630 }3637 }
36313638
3632 pub fn log2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3639 pub fn log2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3637,10 +3644,10 @@ pub const Value = struct {...@@ -3637,10 +3644,10 @@ pub const Value = struct {
3637 const elem_val = try val.elemValue(mod, i);3644 const elem_val = try val.elemValue(mod, i);
3638 scalar.* = try (try log2Scalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3645 scalar.* = try (try log2Scalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3639 }3646 }
3640 return (try mod.intern(.{ .aggregate = .{3647 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3641 .ty = float_type.toIntern(),3648 .ty = float_type.toIntern(),
3642 .storage = .{ .elems = result_data },3649 .storage = .{ .elems = result_data },
3643 } })).toValue();3650 } })));
3644 }3651 }
3645 return log2Scalar(val, float_type, mod);3652 return log2Scalar(val, float_type, mod);
3646 }3653 }
...@@ -3655,10 +3662,10 @@ pub const Value = struct {...@@ -3655,10 +3662,10 @@ pub const Value = struct {
3655 128 => .{ .f128 = @log2(val.toFloat(f128, mod)) },3662 128 => .{ .f128 = @log2(val.toFloat(f128, mod)) },
3656 else => unreachable,3663 else => unreachable,
3657 };3664 };
3658 return (try mod.intern(.{ .float = .{3665 return Value.fromInterned((try mod.intern(.{ .float = .{
3659 .ty = float_type.toIntern(),3666 .ty = float_type.toIntern(),
3660 .storage = storage,3667 .storage = storage,
3661 } })).toValue();3668 } })));
3662 }3669 }
36633670
3664 pub fn log10(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3671 pub fn log10(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3669,10 +3676,10 @@ pub const Value = struct {...@@ -3669,10 +3676,10 @@ pub const Value = struct {
3669 const elem_val = try val.elemValue(mod, i);3676 const elem_val = try val.elemValue(mod, i);
3670 scalar.* = try (try log10Scalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3677 scalar.* = try (try log10Scalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3671 }3678 }
3672 return (try mod.intern(.{ .aggregate = .{3679 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3673 .ty = float_type.toIntern(),3680 .ty = float_type.toIntern(),
3674 .storage = .{ .elems = result_data },3681 .storage = .{ .elems = result_data },
3675 } })).toValue();3682 } })));
3676 }3683 }
3677 return log10Scalar(val, float_type, mod);3684 return log10Scalar(val, float_type, mod);
3678 }3685 }
...@@ -3687,10 +3694,10 @@ pub const Value = struct {...@@ -3687,10 +3694,10 @@ pub const Value = struct {
3687 128 => .{ .f128 = @log10(val.toFloat(f128, mod)) },3694 128 => .{ .f128 = @log10(val.toFloat(f128, mod)) },
3688 else => unreachable,3695 else => unreachable,
3689 };3696 };
3690 return (try mod.intern(.{ .float = .{3697 return Value.fromInterned((try mod.intern(.{ .float = .{
3691 .ty = float_type.toIntern(),3698 .ty = float_type.toIntern(),
3692 .storage = storage,3699 .storage = storage,
3693 } })).toValue();3700 } })));
3694 }3701 }
36953702
3696 pub fn abs(val: Value, ty: Type, arena: Allocator, mod: *Module) !Value {3703 pub fn abs(val: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3701,10 +3708,10 @@ pub const Value = struct {...@@ -3701,10 +3708,10 @@ pub const Value = struct {
3701 const elem_val = try val.elemValue(mod, i);3708 const elem_val = try val.elemValue(mod, i);
3702 scalar.* = try (try absScalar(elem_val, scalar_ty, mod, arena)).intern(scalar_ty, mod);3709 scalar.* = try (try absScalar(elem_val, scalar_ty, mod, arena)).intern(scalar_ty, mod);
3703 }3710 }
3704 return (try mod.intern(.{ .aggregate = .{3711 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3705 .ty = ty.toIntern(),3712 .ty = ty.toIntern(),
3706 .storage = .{ .elems = result_data },3713 .storage = .{ .elems = result_data },
3707 } })).toValue();3714 } })));
3708 }3715 }
3709 return absScalar(val, ty, mod, arena);3716 return absScalar(val, ty, mod, arena);
3710 }3717 }
...@@ -3735,10 +3742,10 @@ pub const Value = struct {...@@ -3735,10 +3742,10 @@ pub const Value = struct {
3735 128 => .{ .f128 = @abs(val.toFloat(f128, mod)) },3742 128 => .{ .f128 = @abs(val.toFloat(f128, mod)) },
3736 else => unreachable,3743 else => unreachable,
3737 };3744 };
3738 return (try mod.intern(.{ .float = .{3745 return Value.fromInterned((try mod.intern(.{ .float = .{
3739 .ty = ty.toIntern(),3746 .ty = ty.toIntern(),
3740 .storage = storage,3747 .storage = storage,
3741 } })).toValue();3748 } })));
3742 },3749 },
3743 else => unreachable,3750 else => unreachable,
3744 }3751 }
...@@ -3752,10 +3759,10 @@ pub const Value = struct {...@@ -3752,10 +3759,10 @@ pub const Value = struct {
3752 const elem_val = try val.elemValue(mod, i);3759 const elem_val = try val.elemValue(mod, i);
3753 scalar.* = try (try floorScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3760 scalar.* = try (try floorScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3754 }3761 }
3755 return (try mod.intern(.{ .aggregate = .{3762 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3756 .ty = float_type.toIntern(),3763 .ty = float_type.toIntern(),
3757 .storage = .{ .elems = result_data },3764 .storage = .{ .elems = result_data },
3758 } })).toValue();3765 } })));
3759 }3766 }
3760 return floorScalar(val, float_type, mod);3767 return floorScalar(val, float_type, mod);
3761 }3768 }
...@@ -3770,10 +3777,10 @@ pub const Value = struct {...@@ -3770,10 +3777,10 @@ pub const Value = struct {
3770 128 => .{ .f128 = @floor(val.toFloat(f128, mod)) },3777 128 => .{ .f128 = @floor(val.toFloat(f128, mod)) },
3771 else => unreachable,3778 else => unreachable,
3772 };3779 };
3773 return (try mod.intern(.{ .float = .{3780 return Value.fromInterned((try mod.intern(.{ .float = .{
3774 .ty = float_type.toIntern(),3781 .ty = float_type.toIntern(),
3775 .storage = storage,3782 .storage = storage,
3776 } })).toValue();3783 } })));
3777 }3784 }
37783785
3779 pub fn ceil(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3786 pub fn ceil(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3784,10 +3791,10 @@ pub const Value = struct {...@@ -3784,10 +3791,10 @@ pub const Value = struct {
3784 const elem_val = try val.elemValue(mod, i);3791 const elem_val = try val.elemValue(mod, i);
3785 scalar.* = try (try ceilScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3792 scalar.* = try (try ceilScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3786 }3793 }
3787 return (try mod.intern(.{ .aggregate = .{3794 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3788 .ty = float_type.toIntern(),3795 .ty = float_type.toIntern(),
3789 .storage = .{ .elems = result_data },3796 .storage = .{ .elems = result_data },
3790 } })).toValue();3797 } })));
3791 }3798 }
3792 return ceilScalar(val, float_type, mod);3799 return ceilScalar(val, float_type, mod);
3793 }3800 }
...@@ -3802,10 +3809,10 @@ pub const Value = struct {...@@ -3802,10 +3809,10 @@ pub const Value = struct {
3802 128 => .{ .f128 = @ceil(val.toFloat(f128, mod)) },3809 128 => .{ .f128 = @ceil(val.toFloat(f128, mod)) },
3803 else => unreachable,3810 else => unreachable,
3804 };3811 };
3805 return (try mod.intern(.{ .float = .{3812 return Value.fromInterned((try mod.intern(.{ .float = .{
3806 .ty = float_type.toIntern(),3813 .ty = float_type.toIntern(),
3807 .storage = storage,3814 .storage = storage,
3808 } })).toValue();3815 } })));
3809 }3816 }
38103817
3811 pub fn round(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3818 pub fn round(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3816,10 +3823,10 @@ pub const Value = struct {...@@ -3816,10 +3823,10 @@ pub const Value = struct {
3816 const elem_val = try val.elemValue(mod, i);3823 const elem_val = try val.elemValue(mod, i);
3817 scalar.* = try (try roundScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3824 scalar.* = try (try roundScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3818 }3825 }
3819 return (try mod.intern(.{ .aggregate = .{3826 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3820 .ty = float_type.toIntern(),3827 .ty = float_type.toIntern(),
3821 .storage = .{ .elems = result_data },3828 .storage = .{ .elems = result_data },
3822 } })).toValue();3829 } })));
3823 }3830 }
3824 return roundScalar(val, float_type, mod);3831 return roundScalar(val, float_type, mod);
3825 }3832 }
...@@ -3834,10 +3841,10 @@ pub const Value = struct {...@@ -3834,10 +3841,10 @@ pub const Value = struct {
3834 128 => .{ .f128 = @round(val.toFloat(f128, mod)) },3841 128 => .{ .f128 = @round(val.toFloat(f128, mod)) },
3835 else => unreachable,3842 else => unreachable,
3836 };3843 };
3837 return (try mod.intern(.{ .float = .{3844 return Value.fromInterned((try mod.intern(.{ .float = .{
3838 .ty = float_type.toIntern(),3845 .ty = float_type.toIntern(),
3839 .storage = storage,3846 .storage = storage,
3840 } })).toValue();3847 } })));
3841 }3848 }
38423849
3843 pub fn trunc(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {3850 pub fn trunc(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
...@@ -3848,10 +3855,10 @@ pub const Value = struct {...@@ -3848,10 +3855,10 @@ pub const Value = struct {
3848 const elem_val = try val.elemValue(mod, i);3855 const elem_val = try val.elemValue(mod, i);
3849 scalar.* = try (try truncScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);3856 scalar.* = try (try truncScalar(elem_val, scalar_ty, mod)).intern(scalar_ty, mod);
3850 }3857 }
3851 return (try mod.intern(.{ .aggregate = .{3858 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3852 .ty = float_type.toIntern(),3859 .ty = float_type.toIntern(),
3853 .storage = .{ .elems = result_data },3860 .storage = .{ .elems = result_data },
3854 } })).toValue();3861 } })));
3855 }3862 }
3856 return truncScalar(val, float_type, mod);3863 return truncScalar(val, float_type, mod);
3857 }3864 }
...@@ -3866,10 +3873,10 @@ pub const Value = struct {...@@ -3866,10 +3873,10 @@ pub const Value = struct {
3866 128 => .{ .f128 = @trunc(val.toFloat(f128, mod)) },3873 128 => .{ .f128 = @trunc(val.toFloat(f128, mod)) },
3867 else => unreachable,3874 else => unreachable,
3868 };3875 };
3869 return (try mod.intern(.{ .float = .{3876 return Value.fromInterned((try mod.intern(.{ .float = .{
3870 .ty = float_type.toIntern(),3877 .ty = float_type.toIntern(),
3871 .storage = storage,3878 .storage = storage,
3872 } })).toValue();3879 } })));
3873 }3880 }
38743881
3875 pub fn mulAdd(3882 pub fn mulAdd(
...@@ -3889,10 +3896,10 @@ pub const Value = struct {...@@ -3889,10 +3896,10 @@ pub const Value = struct {
3889 const addend_elem = try addend.elemValue(mod, i);3896 const addend_elem = try addend.elemValue(mod, i);
3890 scalar.* = try (try mulAddScalar(scalar_ty, mulend1_elem, mulend2_elem, addend_elem, mod)).intern(scalar_ty, mod);3897 scalar.* = try (try mulAddScalar(scalar_ty, mulend1_elem, mulend2_elem, addend_elem, mod)).intern(scalar_ty, mod);
3891 }3898 }
3892 return (try mod.intern(.{ .aggregate = .{3899 return Value.fromInterned((try mod.intern(.{ .aggregate = .{
3893 .ty = float_type.toIntern(),3900 .ty = float_type.toIntern(),
3894 .storage = .{ .elems = result_data },3901 .storage = .{ .elems = result_data },
3895 } })).toValue();3902 } })));
3896 }3903 }
3897 return mulAddScalar(float_type, mulend1, mulend2, addend, mod);3904 return mulAddScalar(float_type, mulend1, mulend2, addend, mod);
3898 }3905 }
...@@ -3913,10 +3920,10 @@ pub const Value = struct {...@@ -3913,10 +3920,10 @@ pub const Value = struct {
3913 128 => .{ .f128 = @mulAdd(f128, mulend1.toFloat(f128, mod), mulend2.toFloat(f128, mod), addend.toFloat(f128, mod)) },3920 128 => .{ .f128 = @mulAdd(f128, mulend1.toFloat(f128, mod), mulend2.toFloat(f128, mod), addend.toFloat(f128, mod)) },
3914 else => unreachable,3921 else => unreachable,
3915 };3922 };
3916 return (try mod.intern(.{ .float = .{3923 return Value.fromInterned((try mod.intern(.{ .float = .{
3917 .ty = float_type.toIntern(),3924 .ty = float_type.toIntern(),
3918 .storage = storage,3925 .storage = storage,
3919 } })).toValue();3926 } })));
3920 }3927 }
39213928
3922 /// If the value is represented in-memory as a series of bytes that all3929 /// If the value is represented in-memory as a series of bytes that all
...@@ -3958,8 +3965,8 @@ pub const Value = struct {...@@ -3958,8 +3965,8 @@ pub const Value = struct {
3958 const ty = mod.intern_pool.typeOf(val.toIntern());3965 const ty = mod.intern_pool.typeOf(val.toIntern());
3959 if (ty == .comptime_int_type) return null;3966 if (ty == .comptime_int_type) return null;
3960 return .{3967 return .{
3961 try ty.toType().minInt(mod, ty.toType()),3968 try Type.fromInterned(ty).minInt(mod, Type.fromInterned(ty)),
3962 try ty.toType().maxInt(mod, ty.toType()),3969 try Type.fromInterned(ty).maxInt(mod, Type.fromInterned(ty)),
3963 };3970 };
3964 }3971 }
39653972