authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-05-04 20:30:25-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-06-10 20:42:27-07:00
log5e636643d2a36c777a607b65cfd1abbb1822ad1e
tree500ec74bd5cc60bb8a4db95ab5f5e90fcfb222aa
parent9d422bff18dbb92d3a6b8705c3dae7404a34bba6

stage2: move many Type encodings to InternPool

Notably, `vector`. Additionally, all alternate encodings of `pointer`, `optional`, and `array`.

25 files changed, 1834 insertions(+), 2771 deletions(-)

src/Air.zig+8-5
......@@ -1375,7 +1375,7 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: InternPool) Type {
13751375
13761376 .bool_to_int => return Type.u1,
13771377
1378 .tag_name, .error_name => return Type.initTag(.const_slice_u8_sentinel_0),
1378 .tag_name, .error_name => return Type.const_slice_u8_sentinel_0,
13791379
13801380 .call, .call_always_tail, .call_never_tail, .call_never_inline => {
13811381 const callee_ty = air.typeOf(datas[inst].pl_op.operand, ip);
......@@ -1384,18 +1384,21 @@ pub fn typeOfIndex(air: Air, inst: Air.Inst.Index, ip: InternPool) Type {
13841384
13851385 .slice_elem_val, .ptr_elem_val, .array_elem_val => {
13861386 const ptr_ty = air.typeOf(datas[inst].bin_op.lhs, ip);
1387 return ptr_ty.elemType();
1387 return ptr_ty.childTypeIp(ip);
13881388 },
13891389 .atomic_load => {
13901390 const ptr_ty = air.typeOf(datas[inst].atomic_load.ptr, ip);
1391 return ptr_ty.elemType();
1391 return ptr_ty.childTypeIp(ip);
13921392 },
13931393 .atomic_rmw => {
13941394 const ptr_ty = air.typeOf(datas[inst].pl_op.operand, ip);
1395 return ptr_ty.elemType();
1395 return ptr_ty.childTypeIp(ip);
13961396 },
13971397
1398 .reduce, .reduce_optimized => return air.typeOf(datas[inst].reduce.operand, ip).childType(),
1398 .reduce, .reduce_optimized => {
1399 const operand_ty = air.typeOf(datas[inst].reduce.operand, ip);
1400 return ip.indexToKey(operand_ty.ip_index).vector_type.child.toType();
1401 },
13991402
14001403 .mul_add => return air.typeOf(datas[inst].pl_op.operand, ip),
14011404 .select => {
src/InternPool.zig+63-29
......@@ -31,28 +31,10 @@ const KeyAdapter = struct {
3131
3232pub const Key = union(enum) {
3333 int_type: IntType,
34 ptr_type: struct {
35 elem_type: Index,
36 sentinel: Index = .none,
37 alignment: u16 = 0,
38 size: std.builtin.Type.Pointer.Size,
39 is_const: bool = false,
40 is_volatile: bool = false,
41 is_allowzero: bool = false,
42 address_space: std.builtin.AddressSpace = .generic,
43 },
44 array_type: struct {
45 len: u64,
46 child: Index,
47 sentinel: Index,
48 },
49 vector_type: struct {
50 len: u32,
51 child: Index,
52 },
53 optional_type: struct {
54 payload_type: Index,
55 },
34 ptr_type: PtrType,
35 array_type: ArrayType,
36 vector_type: VectorType,
37 opt_type: Index,
5638 error_union_type: struct {
5739 error_set_type: Index,
5840 payload_type: Index,
......@@ -87,6 +69,47 @@ pub const Key = union(enum) {
8769
8870 pub const IntType = std.builtin.Type.Int;
8971
72 pub const PtrType = struct {
73 elem_type: Index,
74 sentinel: Index = .none,
75 /// If zero use pointee_type.abiAlignment()
76 /// When creating pointer types, if alignment is equal to pointee type
77 /// abi alignment, this value should be set to 0 instead.
78 alignment: u16 = 0,
79 /// If this is non-zero it means the pointer points to a sub-byte
80 /// range of data, which is backed by a "host integer" with this
81 /// number of bytes.
82 /// When host_size=pointee_abi_size and bit_offset=0, this must be
83 /// represented with host_size=0 instead.
84 host_size: u16 = 0,
85 bit_offset: u16 = 0,
86 vector_index: VectorIndex = .none,
87 size: std.builtin.Type.Pointer.Size = .One,
88 is_const: bool = false,
89 is_volatile: bool = false,
90 is_allowzero: bool = false,
91 /// See src/target.zig defaultAddressSpace function for how to obtain
92 /// an appropriate value for this field.
93 address_space: std.builtin.AddressSpace = .generic,
94
95 pub const VectorIndex = enum(u32) {
96 none = std.math.maxInt(u32),
97 runtime = std.math.maxInt(u32) - 1,
98 _,
99 };
100 };
101
102 pub const ArrayType = struct {
103 len: u64,
104 child: Index,
105 sentinel: Index,
106 };
107
108 pub const VectorType = struct {
109 len: u32,
110 child: Index,
111 };
112
90113 pub fn hash32(key: Key) u32 {
91114 return @truncate(u32, key.hash64());
92115 }
......@@ -106,7 +129,7 @@ pub const Key = union(enum) {
106129 .ptr_type,
107130 .array_type,
108131 .vector_type,
109 .optional_type,
132 .opt_type,
110133 .error_union_type,
111134 .simple_type,
112135 .simple_value,
......@@ -159,8 +182,8 @@ pub const Key = union(enum) {
159182 const b_info = b.vector_type;
160183 return std.meta.eql(a_info, b_info);
161184 },
162 .optional_type => |a_info| {
163 const b_info = b.optional_type;
185 .opt_type => |a_info| {
186 const b_info = b.opt_type;
164187 return std.meta.eql(a_info, b_info);
165188 },
166189 .error_union_type => |a_info| {
......@@ -220,7 +243,7 @@ pub const Key = union(enum) {
220243 .ptr_type,
221244 .array_type,
222245 .vector_type,
223 .optional_type,
246 .opt_type,
224247 .error_union_type,
225248 .simple_type,
226249 .struct_type,
......@@ -630,6 +653,7 @@ pub const Tag = enum(u8) {
630653 /// data is payload to Vector.
631654 type_vector,
632655 /// A fully explicitly specified pointer type.
656 /// TODO actually this is missing some stuff like bit_offset
633657 /// data is payload to Pointer.
634658 type_pointer,
635659 /// An optional type.
......@@ -893,7 +917,7 @@ pub fn indexToKey(ip: InternPool, index: Index) Key {
893917 } };
894918 },
895919
896 .type_optional => .{ .optional_type = .{ .payload_type = @intToEnum(Index, data) } },
920 .type_optional => .{ .opt_type = @intToEnum(Index, data) },
897921
898922 .type_error_union => @panic("TODO"),
899923 .type_enum_simple => @panic("TODO"),
......@@ -971,10 +995,10 @@ pub fn get(ip: *InternPool, gpa: Allocator, key: Key) Allocator.Error!Index {
971995 }),
972996 });
973997 },
974 .optional_type => |optional_type| {
998 .opt_type => |opt_type| {
975999 ip.items.appendAssumeCapacity(.{
9761000 .tag = .type_optional,
977 .data = @enumToInt(optional_type.payload_type),
1001 .data = @enumToInt(opt_type),
9781002 });
9791003 },
9801004 .error_union_type => |error_union_type| {
......@@ -1192,3 +1216,13 @@ test "basic usage" {
11921216 } });
11931217 try std.testing.expect(another_array_i32 == array_i32);
11941218}
1219
1220pub fn childType(ip: InternPool, i: Index) Index {
1221 return switch (ip.indexToKey(i)) {
1222 .ptr_type => |ptr_type| ptr_type.elem_type,
1223 .vector_type => |vector_type| vector_type.child,
1224 .array_type => |array_type| array_type.child,
1225 .opt_type => |child| child,
1226 else => unreachable,
1227 };
1228}
src/Liveness.zig+5-3
......@@ -225,6 +225,7 @@ pub fn categorizeOperand(
225225 air: Air,
226226 inst: Air.Inst.Index,
227227 operand: Air.Inst.Index,
228 ip: InternPool,
228229) OperandCategory {
229230 const air_tags = air.instructions.items(.tag);
230231 const air_datas = air.instructions.items(.data);
......@@ -534,7 +535,7 @@ pub fn categorizeOperand(
534535 .aggregate_init => {
535536 const ty_pl = air_datas[inst].ty_pl;
536537 const aggregate_ty = air.getRefType(ty_pl.ty);
537 const len = @intCast(usize, aggregate_ty.arrayLen());
538 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip));
538539 const elements = @ptrCast([]const Air.Inst.Ref, air.extra[ty_pl.payload..][0..len]);
539540
540541 if (elements.len <= bpi - 1) {
......@@ -625,7 +626,7 @@ pub fn categorizeOperand(
625626
626627 var operand_live: bool = true;
627628 for (air.extra[cond_extra.end..][0..2]) |cond_inst| {
628 if (l.categorizeOperand(air, cond_inst, operand) == .tomb)
629 if (l.categorizeOperand(air, cond_inst, operand, ip) == .tomb)
629630 operand_live = false;
630631
631632 switch (air_tags[cond_inst]) {
......@@ -872,6 +873,7 @@ fn analyzeInst(
872873 data: *LivenessPassData(pass),
873874 inst: Air.Inst.Index,
874875) Allocator.Error!void {
876 const ip = a.intern_pool;
875877 const inst_tags = a.air.instructions.items(.tag);
876878 const inst_datas = a.air.instructions.items(.data);
877879
......@@ -1140,7 +1142,7 @@ fn analyzeInst(
11401142 .aggregate_init => {
11411143 const ty_pl = inst_datas[inst].ty_pl;
11421144 const aggregate_ty = a.air.getRefType(ty_pl.ty);
1143 const len = @intCast(usize, aggregate_ty.arrayLen());
1145 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip.*));
11441146 const elements = @ptrCast([]const Air.Inst.Ref, a.air.extra[ty_pl.payload..][0..len]);
11451147
11461148 if (elements.len <= bpi - 1) {
src/Liveness/Verify.zig+1-1
......@@ -325,7 +325,7 @@ fn verifyBody(self: *Verify, body: []const Air.Inst.Index) Error!void {
325325 .aggregate_init => {
326326 const ty_pl = data[inst].ty_pl;
327327 const aggregate_ty = self.air.getRefType(ty_pl.ty);
328 const len = @intCast(usize, aggregate_ty.arrayLen());
328 const len = @intCast(usize, aggregate_ty.arrayLenIp(ip.*));
329329 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
330330
331331 var bt = self.liveness.iterateBigTomb(inst);
src/Module.zig+37-4
......@@ -5805,7 +5805,7 @@ pub fn analyzeFnBody(mod: *Module, func: *Fn, arena: Allocator) SemaError!Air {
58055805 // is unused so it just has to be a no-op.
58065806 sema.air_instructions.set(ptr_inst.*, .{
58075807 .tag = .alloc,
5808 .data = .{ .ty = Type.initTag(.single_const_pointer_to_comptime_int) },
5808 .data = .{ .ty = Type.single_const_pointer_to_comptime_int },
58095809 });
58105810 }
58115811 }
......@@ -6545,7 +6545,7 @@ pub fn populateTestFunctions(
65456545 }
65466546 const decl = mod.declPtr(decl_index);
65476547 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
6548 const tmp_test_fn_ty = decl.ty.slicePtrFieldType(&buf).elemType();
6548 const tmp_test_fn_ty = decl.ty.slicePtrFieldType(&buf).childType(mod);
65496549
65506550 const array_decl_index = d: {
65516551 // Add mod.test_functions to an array decl then make the test_functions
......@@ -6575,7 +6575,7 @@ pub fn populateTestFunctions(
65756575 errdefer name_decl_arena.deinit();
65766576 const bytes = try name_decl_arena.allocator().dupe(u8, test_name_slice);
65776577 const test_name_decl_index = try mod.createAnonymousDeclFromDecl(array_decl, array_decl.src_namespace, null, .{
6578 .ty = try Type.Tag.array_u8.create(name_decl_arena.allocator(), bytes.len),
6578 .ty = try Type.array(name_decl_arena.allocator(), bytes.len, null, Type.u8, mod),
65796579 .val = try Value.Tag.bytes.create(name_decl_arena.allocator(), bytes),
65806580 });
65816581 try mod.declPtr(test_name_decl_index).finalizeNewArena(&name_decl_arena);
......@@ -6609,7 +6609,12 @@ pub fn populateTestFunctions(
66096609
66106610 {
66116611 // This copy accesses the old Decl Type/Value so it must be done before `clearValues`.
6612 const new_ty = try Type.Tag.const_slice.create(arena, try tmp_test_fn_ty.copy(arena));
6612 const new_ty = try Type.ptr(arena, mod, .{
6613 .size = .Slice,
6614 .pointee_type = try tmp_test_fn_ty.copy(arena),
6615 .mutable = false,
6616 .@"addrspace" = .generic,
6617 });
66136618 const new_var = try gpa.create(Var);
66146619 errdefer gpa.destroy(new_var);
66156620 new_var.* = decl.val.castTag(.variable).?.data.*;
......@@ -6819,6 +6824,34 @@ pub fn intType(mod: *Module, signedness: std.builtin.Signedness, bits: u16) Allo
68196824 return i.toType();
68206825}
68216826
6827pub fn arrayType(mod: *Module, info: InternPool.Key.ArrayType) Allocator.Error!Type {
6828 const i = try intern(mod, .{ .array_type = info });
6829 return i.toType();
6830}
6831
6832pub fn vectorType(mod: *Module, info: InternPool.Key.VectorType) Allocator.Error!Type {
6833 const i = try intern(mod, .{ .vector_type = info });
6834 return i.toType();
6835}
6836
6837pub fn optionalType(mod: *Module, child_type: InternPool.Index) Allocator.Error!Type {
6838 const i = try intern(mod, .{ .opt_type = child_type });
6839 return i.toType();
6840}
6841
6842pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type {
6843 const i = try intern(mod, .{ .ptr_type = info });
6844 return i.toType();
6845}
6846
6847pub fn singleMutPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {
6848 return ptrType(mod, .{ .elem_type = child_type.ip_index });
6849}
6850
6851pub fn singleConstPtrType(mod: *Module, child_type: Type) Allocator.Error!Type {
6852 return ptrType(mod, .{ .elem_type = child_type.ip_index, .is_const = true });
6853}
6854
68226855pub fn smallestUnsignedInt(mod: *Module, max: u64) Allocator.Error!Type {
68236856 return intType(mod, .unsigned, Type.smallestUnsignedBits(max));
68246857}
src/Sema.zig+519-556
......@@ -585,13 +585,18 @@ pub const Block = struct {
585585 }
586586
587587 fn addCmpVector(block: *Block, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref, cmp_op: std.math.CompareOperator) !Air.Inst.Ref {
588 const sema = block.sema;
589 const mod = sema.mod;
588590 return block.addInst(.{
589591 .tag = if (block.float_mode == .Optimized) .cmp_vector_optimized else .cmp_vector,
590592 .data = .{ .ty_pl = .{
591 .ty = try block.sema.addType(
592 try Type.vector(block.sema.arena, block.sema.typeOf(lhs).vectorLen(), Type.bool),
593 .ty = try sema.addType(
594 try mod.vectorType(.{
595 .len = sema.typeOf(lhs).vectorLen(mod),
596 .child = .bool_type,
597 }),
593598 ),
594 .payload = try block.sema.addExtra(Air.VectorCmp{
599 .payload = try sema.addExtra(Air.VectorCmp{
595600 .lhs = lhs,
596601 .rhs = rhs,
597602 .op = Air.VectorCmp.encodeOp(cmp_op),
......@@ -1760,7 +1765,7 @@ pub fn resolveConstString(
17601765 reason: []const u8,
17611766) ![]u8 {
17621767 const air_inst = try sema.resolveInst(zir_ref);
1763 const wanted_type = Type.initTag(.const_slice_u8);
1768 const wanted_type = Type.const_slice_u8;
17641769 const coerced_inst = try sema.coerce(block, wanted_type, air_inst, src);
17651770 const val = try sema.resolveConstValue(block, src, coerced_inst, reason);
17661771 return val.toAllocatedBytes(wanted_type, sema.arena, sema.mod);
......@@ -1788,7 +1793,8 @@ fn analyzeAsType(
17881793}
17891794
17901795pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize) !void {
1791 if (!sema.mod.backendSupportsFeature(.error_return_trace)) return;
1796 const mod = sema.mod;
1797 if (!mod.backendSupportsFeature(.error_return_trace)) return;
17921798
17931799 assert(!block.is_comptime);
17941800 var err_trace_block = block.makeSubBlock();
......@@ -1798,13 +1804,13 @@ pub fn setupErrorReturnTrace(sema: *Sema, block: *Block, last_arg_index: usize)
17981804
17991805 // var addrs: [err_return_trace_addr_count]usize = undefined;
18001806 const err_return_trace_addr_count = 32;
1801 const addr_arr_ty = try Type.array(sema.arena, err_return_trace_addr_count, null, Type.usize, sema.mod);
1802 const addrs_ptr = try err_trace_block.addTy(.alloc, try Type.Tag.single_mut_pointer.create(sema.arena, addr_arr_ty));
1807 const addr_arr_ty = try Type.array(sema.arena, err_return_trace_addr_count, null, Type.usize, mod);
1808 const addrs_ptr = try err_trace_block.addTy(.alloc, try mod.singleMutPtrType(addr_arr_ty));
18031809
18041810 // var st: StackTrace = undefined;
18051811 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
18061812 const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty);
1807 const st_ptr = try err_trace_block.addTy(.alloc, try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty));
1813 const st_ptr = try err_trace_block.addTy(.alloc, try mod.singleMutPtrType(stack_trace_ty));
18081814
18091815 // st.instruction_addresses = &addrs;
18101816 const addr_field_ptr = try sema.fieldPtr(&err_trace_block, src, st_ptr, "instruction_addresses", src, true);
......@@ -2101,11 +2107,10 @@ fn failWithUseOfAsync(sema: *Sema, block: *Block, src: LazySrcLoc) CompileError
21012107
21022108fn failWithInvalidFieldAccess(sema: *Sema, block: *Block, src: LazySrcLoc, object_ty: Type, field_name: []const u8) CompileError {
21032109 const mod = sema.mod;
2104 const inner_ty = if (object_ty.isSinglePointer(mod)) object_ty.childType() else object_ty;
2110 const inner_ty = if (object_ty.isSinglePointer(mod)) object_ty.childType(mod) else object_ty;
21052111
21062112 if (inner_ty.zigTypeTag(mod) == .Optional) opt: {
2107 var buf: Type.Payload.ElemType = undefined;
2108 const child_ty = inner_ty.optionalChild(&buf);
2113 const child_ty = inner_ty.optionalChild(mod);
21092114 if (!typeSupportsFieldAccess(mod, child_ty, field_name)) break :opt;
21102115 const msg = msg: {
21112116 const msg = try sema.errMsg(block, src, "optional type '{}' does not support field access", .{object_ty.fmt(sema.mod)});
......@@ -2132,7 +2137,7 @@ fn typeSupportsFieldAccess(mod: *const Module, ty: Type, field_name: []const u8)
21322137 switch (ty.zigTypeTag(mod)) {
21332138 .Array => return mem.eql(u8, field_name, "len"),
21342139 .Pointer => {
2135 const ptr_info = ty.ptrInfo().data;
2140 const ptr_info = ty.ptrInfo(mod);
21362141 if (ptr_info.size == .Slice) {
21372142 return mem.eql(u8, field_name, "ptr") or mem.eql(u8, field_name, "len");
21382143 } else if (ptr_info.pointee_type.zigTypeTag(mod) == .Array) {
......@@ -2504,6 +2509,7 @@ fn coerceResultPtr(
25042509 dummy_operand: Air.Inst.Ref,
25052510 trash_block: *Block,
25062511) CompileError!Air.Inst.Ref {
2512 const mod = sema.mod;
25072513 const target = sema.mod.getTarget();
25082514 const addr_space = target_util.defaultAddressSpace(target, .local);
25092515 const pointee_ty = sema.typeOf(dummy_operand);
......@@ -2547,7 +2553,7 @@ fn coerceResultPtr(
25472553 return sema.addConstant(ptr_ty, ptr_val);
25482554 }
25492555 if (pointee_ty.eql(Type.null, sema.mod)) {
2550 const opt_ty = sema.typeOf(new_ptr).childType();
2556 const opt_ty = sema.typeOf(new_ptr).childType(mod);
25512557 const null_inst = try sema.addConstant(opt_ty, Value.null);
25522558 _ = try block.addBinOp(.store, new_ptr, null_inst);
25532559 return Air.Inst.Ref.void_value;
......@@ -3394,7 +3400,7 @@ fn zirEnsureErrUnionPayloadVoid(sema: *Sema, block: *Block, inst: Zir.Inst.Index
33943400 const operand = try sema.resolveInst(inst_data.operand);
33953401 const operand_ty = sema.typeOf(operand);
33963402 const err_union_ty = if (operand_ty.zigTypeTag(mod) == .Pointer)
3397 operand_ty.childType()
3403 operand_ty.childType(mod)
33983404 else
33993405 operand_ty;
34003406 if (err_union_ty.zigTypeTag(mod) != .ErrorUnion) return;
......@@ -3430,7 +3436,7 @@ fn indexablePtrLen(
34303436 const mod = sema.mod;
34313437 const object_ty = sema.typeOf(object);
34323438 const is_pointer_to = object_ty.isSinglePointer(mod);
3433 const indexable_ty = if (is_pointer_to) object_ty.childType() else object_ty;
3439 const indexable_ty = if (is_pointer_to) object_ty.childType(mod) else object_ty;
34343440 try checkIndexable(sema, block, src, indexable_ty);
34353441 return sema.fieldVal(block, src, object, "len", src);
34363442}
......@@ -3441,9 +3447,10 @@ fn indexablePtrLenOrNone(
34413447 src: LazySrcLoc,
34423448 operand: Air.Inst.Ref,
34433449) CompileError!Air.Inst.Ref {
3450 const mod = sema.mod;
34443451 const operand_ty = sema.typeOf(operand);
34453452 try checkMemOperand(sema, block, src, operand_ty);
3446 if (operand_ty.ptrSize() == .Many) return .none;
3453 if (operand_ty.ptrSize(mod) == .Many) return .none;
34473454 return sema.fieldVal(block, src, operand, "len", src);
34483455}
34493456
......@@ -3529,11 +3536,12 @@ fn zirAllocComptime(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
35293536}
35303537
35313538fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
3539 const mod = sema.mod;
35323540 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
35333541 const alloc = try sema.resolveInst(inst_data.operand);
35343542 const alloc_ty = sema.typeOf(alloc);
35353543
3536 var ptr_info = alloc_ty.ptrInfo().data;
3544 var ptr_info = alloc_ty.ptrInfo(mod);
35373545 const elem_ty = ptr_info.pointee_type;
35383546
35393547 // Detect if all stores to an `.alloc` were comptime-known.
......@@ -3589,9 +3597,10 @@ fn zirMakePtrConst(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
35893597}
35903598
35913599fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Air.Inst.Ref {
3600 const mod = sema.mod;
35923601 const alloc_ty = sema.typeOf(alloc);
35933602
3594 var ptr_info = alloc_ty.ptrInfo().data;
3603 var ptr_info = alloc_ty.ptrInfo(mod);
35953604 ptr_info.mutable = false;
35963605 const const_ptr_ty = try Type.ptr(sema.arena, sema.mod, ptr_info);
35973606
......@@ -3947,13 +3956,13 @@ fn zirArrayBasePtr(
39473956
39483957 const start_ptr = try sema.resolveInst(inst_data.operand);
39493958 var base_ptr = start_ptr;
3950 while (true) switch (sema.typeOf(base_ptr).childType().zigTypeTag(mod)) {
3959 while (true) switch (sema.typeOf(base_ptr).childType(mod).zigTypeTag(mod)) {
39513960 .ErrorUnion => base_ptr = try sema.analyzeErrUnionPayloadPtr(block, src, base_ptr, false, true),
39523961 .Optional => base_ptr = try sema.analyzeOptionalPayloadPtr(block, src, base_ptr, false, true),
39533962 else => break,
39543963 };
39553964
3956 const elem_ty = sema.typeOf(base_ptr).childType();
3965 const elem_ty = sema.typeOf(base_ptr).childType(mod);
39573966 switch (elem_ty.zigTypeTag(mod)) {
39583967 .Array, .Vector => return base_ptr,
39593968 .Struct => if (elem_ty.isTuple()) {
......@@ -3962,7 +3971,7 @@ fn zirArrayBasePtr(
39623971 },
39633972 else => {},
39643973 }
3965 return sema.failWithArrayInitNotSupported(block, src, sema.typeOf(start_ptr).childType());
3974 return sema.failWithArrayInitNotSupported(block, src, sema.typeOf(start_ptr).childType(mod));
39663975}
39673976
39683977fn zirFieldBasePtr(
......@@ -3976,18 +3985,18 @@ fn zirFieldBasePtr(
39763985
39773986 const start_ptr = try sema.resolveInst(inst_data.operand);
39783987 var base_ptr = start_ptr;
3979 while (true) switch (sema.typeOf(base_ptr).childType().zigTypeTag(mod)) {
3988 while (true) switch (sema.typeOf(base_ptr).childType(mod).zigTypeTag(mod)) {
39803989 .ErrorUnion => base_ptr = try sema.analyzeErrUnionPayloadPtr(block, src, base_ptr, false, true),
39813990 .Optional => base_ptr = try sema.analyzeOptionalPayloadPtr(block, src, base_ptr, false, true),
39823991 else => break,
39833992 };
39843993
3985 const elem_ty = sema.typeOf(base_ptr).childType();
3994 const elem_ty = sema.typeOf(base_ptr).childType(mod);
39863995 switch (elem_ty.zigTypeTag(mod)) {
39873996 .Struct, .Union => return base_ptr,
39883997 else => {},
39893998 }
3990 return sema.failWithStructInitNotSupported(block, src, sema.typeOf(start_ptr).childType());
3999 return sema.failWithStructInitNotSupported(block, src, sema.typeOf(start_ptr).childType(mod));
39914000}
39924001
39934002fn zirForLen(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
......@@ -4129,7 +4138,7 @@ fn validateArrayInitTy(
41294138
41304139 switch (ty.zigTypeTag(mod)) {
41314140 .Array => {
4132 const array_len = ty.arrayLen();
4141 const array_len = ty.arrayLen(mod);
41334142 if (extra.init_count != array_len) {
41344143 return sema.fail(block, src, "expected {d} array elements; found {d}", .{
41354144 array_len, extra.init_count,
......@@ -4138,7 +4147,7 @@ fn validateArrayInitTy(
41384147 return;
41394148 },
41404149 .Vector => {
4141 const array_len = ty.arrayLen();
4150 const array_len = ty.arrayLen(mod);
41424151 if (extra.init_count != array_len) {
41434152 return sema.fail(block, src, "expected {d} vector elements; found {d}", .{
41444153 array_len, extra.init_count,
......@@ -4148,7 +4157,7 @@ fn validateArrayInitTy(
41484157 },
41494158 .Struct => if (ty.isTuple()) {
41504159 _ = try sema.resolveTypeFields(ty);
4151 const array_len = ty.arrayLen();
4160 const array_len = ty.arrayLen(mod);
41524161 if (extra.init_count > array_len) {
41534162 return sema.fail(block, src, "expected at most {d} tuple fields; found {d}", .{
41544163 array_len, extra.init_count,
......@@ -4194,7 +4203,7 @@ fn zirValidateStructInit(
41944203 const field_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;
41954204 const field_ptr_extra = sema.code.extraData(Zir.Inst.Field, field_ptr_data.payload_index).data;
41964205 const object_ptr = try sema.resolveInst(field_ptr_extra.lhs);
4197 const agg_ty = sema.typeOf(object_ptr).childType();
4206 const agg_ty = sema.typeOf(object_ptr).childType(mod);
41984207 switch (agg_ty.zigTypeTag(mod)) {
41994208 .Struct => return sema.validateStructInit(
42004209 block,
......@@ -4350,6 +4359,7 @@ fn validateStructInit(
43504359 init_src: LazySrcLoc,
43514360 instrs: []const Zir.Inst.Index,
43524361) CompileError!void {
4362 const mod = sema.mod;
43534363 const gpa = sema.gpa;
43544364
43554365 // Maps field index to field_ptr index of where it was already initialized.
......@@ -4425,14 +4435,13 @@ fn validateStructInit(
44254435 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(u32, i), true)
44264436 else
44274437 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(u32, i), field_src, struct_ty, true);
4428 const field_ty = sema.typeOf(default_field_ptr).childType();
4438 const field_ty = sema.typeOf(default_field_ptr).childType(mod);
44294439 const init = try sema.addConstant(field_ty, default_val);
44304440 try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store);
44314441 }
44324442
44334443 if (root_msg) |msg| {
44344444 if (struct_ty.castTag(.@"struct")) |struct_obj| {
4435 const mod = sema.mod;
44364445 const fqn = try struct_obj.data.getFullyQualifiedName(mod);
44374446 defer gpa.free(fqn);
44384447 try mod.errNoteNonLazy(
......@@ -4605,7 +4614,7 @@ fn validateStructInit(
46054614 try sema.tupleFieldPtr(block, init_src, struct_ptr, field_src, @intCast(u32, i), true)
46064615 else
46074616 try sema.structFieldPtrByIndex(block, init_src, struct_ptr, @intCast(u32, i), field_src, struct_ty, true);
4608 const field_ty = sema.typeOf(default_field_ptr).childType();
4617 const field_ty = sema.typeOf(default_field_ptr).childType(mod);
46094618 const init = try sema.addConstant(field_ty, field_values[i]);
46104619 try sema.storePtr2(block, init_src, default_field_ptr, init_src, init, field_src, .store);
46114620 }
......@@ -4624,8 +4633,8 @@ fn zirValidateArrayInit(
46244633 const first_elem_ptr_data = sema.code.instructions.items(.data)[instrs[0]].pl_node;
46254634 const elem_ptr_extra = sema.code.extraData(Zir.Inst.ElemPtrImm, first_elem_ptr_data.payload_index).data;
46264635 const array_ptr = try sema.resolveInst(elem_ptr_extra.ptr);
4627 const array_ty = sema.typeOf(array_ptr).childType();
4628 const array_len = array_ty.arrayLen();
4636 const array_ty = sema.typeOf(array_ptr).childType(mod);
4637 const array_len = array_ty.arrayLen(mod);
46294638
46304639 if (instrs.len != array_len) switch (array_ty.zigTypeTag(mod)) {
46314640 .Struct => {
......@@ -4670,10 +4679,10 @@ fn zirValidateArrayInit(
46704679 // at comptime so we have almost nothing to do here. However, in case of a
46714680 // sentinel-terminated array, the sentinel will not have been populated by
46724681 // any ZIR instructions at comptime; we need to do that here.
4673 if (array_ty.sentinel()) |sentinel_val| {
4682 if (array_ty.sentinel(mod)) |sentinel_val| {
46744683 const array_len_ref = try sema.addIntUnsigned(Type.usize, array_len);
46754684 const sentinel_ptr = try sema.elemPtrArray(block, init_src, init_src, array_ptr, init_src, array_len_ref, true, true);
4676 const sentinel = try sema.addConstant(array_ty.childType(), sentinel_val);
4685 const sentinel = try sema.addConstant(array_ty.childType(mod), sentinel_val);
46774686 try sema.storePtr2(block, init_src, sentinel_ptr, init_src, sentinel, init_src, .store);
46784687 }
46794688 return;
......@@ -4685,7 +4694,7 @@ fn zirValidateArrayInit(
46854694
46864695 // Collect the comptime element values in case the array literal ends up
46874696 // being comptime-known.
4688 const array_len_s = try sema.usizeCast(block, init_src, array_ty.arrayLenIncludingSentinel());
4697 const array_len_s = try sema.usizeCast(block, init_src, array_ty.arrayLenIncludingSentinel(mod));
46894698 const element_vals = try sema.arena.alloc(Value, array_len_s);
46904699 const opt_opv = try sema.typeHasOnePossibleValue(array_ty);
46914700 const air_tags = sema.air_instructions.items(.tag);
......@@ -4784,7 +4793,7 @@ fn zirValidateArrayInit(
47844793 // Our task is to delete all the `elem_ptr` and `store` instructions, and insert
47854794 // instead a single `store` to the array_ptr with a comptime struct value.
47864795 // Also to populate the sentinel value, if any.
4787 if (array_ty.sentinel()) |sentinel_val| {
4796 if (array_ty.sentinel(mod)) |sentinel_val| {
47884797 element_vals[instrs.len] = sentinel_val;
47894798 }
47904799
......@@ -4806,13 +4815,13 @@ fn zirValidateDeref(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
48064815
48074816 if (operand_ty.zigTypeTag(mod) != .Pointer) {
48084817 return sema.fail(block, src, "cannot dereference non-pointer type '{}'", .{operand_ty.fmt(sema.mod)});
4809 } else switch (operand_ty.ptrSize()) {
4818 } else switch (operand_ty.ptrSize(mod)) {
48104819 .One, .C => {},
48114820 .Many => return sema.fail(block, src, "index syntax required for unknown-length pointer type '{}'", .{operand_ty.fmt(sema.mod)}),
48124821 .Slice => return sema.fail(block, src, "index syntax required for slice type '{}'", .{operand_ty.fmt(sema.mod)}),
48134822 }
48144823
4815 if ((try sema.typeHasOnePossibleValue(operand_ty.childType())) != null) {
4824 if ((try sema.typeHasOnePossibleValue(operand_ty.childType(mod))) != null) {
48164825 // No need to validate the actual pointer value, we don't need it!
48174826 return;
48184827 }
......@@ -5132,7 +5141,7 @@ fn addStrLit(sema: *Sema, block: *Block, zir_bytes: []const u8) CompileError!Air
51325141 defer anon_decl.deinit();
51335142
51345143 const decl_index = try anon_decl.finish(
5135 try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), gop.key_ptr.len),
5144 try Type.array(anon_decl.arena(), gop.key_ptr.len, Value.zero, Type.u8, mod),
51365145 try Value.Tag.str_lit.create(anon_decl.arena(), gop.key_ptr.*),
51375146 0, // default alignment
51385147 );
......@@ -6003,10 +6012,11 @@ fn addDbgVar(
60036012 air_tag: Air.Inst.Tag,
60046013 name: []const u8,
60056014) CompileError!void {
6015 const mod = sema.mod;
60066016 const operand_ty = sema.typeOf(operand);
60076017 switch (air_tag) {
60086018 .dbg_var_ptr => {
6009 if (!(try sema.typeHasRuntimeBits(operand_ty.childType()))) return;
6019 if (!(try sema.typeHasRuntimeBits(operand_ty.childType(mod)))) return;
60106020 },
60116021 .dbg_var_val => {
60126022 if (!(try sema.typeHasRuntimeBits(operand_ty))) return;
......@@ -6238,7 +6248,7 @@ fn popErrorReturnTrace(
62386248
62396249 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
62406250 const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty);
6241 const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty);
6251 const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty);
62426252 const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty);
62436253 const field_ptr = try sema.structFieldPtr(block, src, err_return_trace, "index", src, stack_trace_ty, true);
62446254 try sema.storePtr2(block, src, field_ptr, src, saved_error_trace_index, src, .store);
......@@ -6263,7 +6273,7 @@ fn popErrorReturnTrace(
62636273 // If non-error, then pop the error return trace by restoring the index.
62646274 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
62656275 const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty);
6266 const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty);
6276 const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty);
62676277 const err_return_trace = try then_block.addTy(.err_return_trace, ptr_stack_trace_ty);
62686278 const field_ptr = try sema.structFieldPtr(&then_block, src, err_return_trace, "index", src, stack_trace_ty, true);
62696279 try sema.storePtr2(&then_block, src, field_ptr, src, saved_error_trace_index, src, .store);
......@@ -6456,16 +6466,15 @@ fn checkCallArgumentCount(
64566466 switch (callee_ty.zigTypeTag(mod)) {
64576467 .Fn => break :func_ty callee_ty,
64586468 .Pointer => {
6459 const ptr_info = callee_ty.ptrInfo().data;
6469 const ptr_info = callee_ty.ptrInfo(mod);
64606470 if (ptr_info.size == .One and ptr_info.pointee_type.zigTypeTag(mod) == .Fn) {
64616471 break :func_ty ptr_info.pointee_type;
64626472 }
64636473 },
64646474 .Optional => {
6465 var buf: Type.Payload.ElemType = undefined;
6466 const opt_child = callee_ty.optionalChild(&buf);
6475 const opt_child = callee_ty.optionalChild(mod);
64676476 if (opt_child.zigTypeTag(mod) == .Fn or (opt_child.isSinglePointer(mod) and
6468 opt_child.childType().zigTypeTag(mod) == .Fn))
6477 opt_child.childType(mod).zigTypeTag(mod) == .Fn))
64696478 {
64706479 const msg = msg: {
64716480 const msg = try sema.errMsg(block, func_src, "cannot call optional type '{}'", .{
......@@ -6529,7 +6538,7 @@ fn callBuiltin(
65296538 switch (callee_ty.zigTypeTag(mod)) {
65306539 .Fn => break :func_ty callee_ty,
65316540 .Pointer => {
6532 const ptr_info = callee_ty.ptrInfo().data;
6541 const ptr_info = callee_ty.ptrInfo(mod);
65336542 if (ptr_info.size == .One and ptr_info.pointee_type.zigTypeTag(mod) == .Fn) {
65346543 break :func_ty ptr_info.pointee_type;
65356544 }
......@@ -7929,7 +7938,7 @@ fn zirOptionalType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErro
79297938 } else if (child_type.zigTypeTag(mod) == .Null) {
79307939 return sema.fail(block, operand_src, "type '{}' cannot be optional", .{child_type.fmt(sema.mod)});
79317940 }
7932 const opt_type = try Type.optional(sema.arena, child_type);
7941 const opt_type = try Type.optional(sema.arena, child_type, mod);
79337942
79347943 return sema.addType(opt_type);
79357944}
......@@ -7949,16 +7958,17 @@ fn zirElemTypeIndex(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileErr
79497958}
79507959
79517960fn zirVectorType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
7961 const mod = sema.mod;
79527962 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
79537963 const elem_type_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
79547964 const len_src: LazySrcLoc = .{ .node_offset_builtin_call_arg1 = inst_data.src_node };
79557965 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
7956 const len = try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector length must be comptime-known");
7966 const len = @intCast(u32, try sema.resolveInt(block, len_src, extra.lhs, Type.u32, "vector length must be comptime-known"));
79577967 const elem_type = try sema.resolveType(block, elem_type_src, extra.rhs);
79587968 try sema.checkVectorElemType(block, elem_type_src, elem_type);
7959 const vector_type = try Type.Tag.vector.create(sema.arena, .{
7960 .len = @intCast(u32, len),
7961 .elem_type = elem_type,
7969 const vector_type = try mod.vectorType(.{
7970 .len = len,
7971 .child = elem_type.ip_index,
79627972 });
79637973 return sema.addType(vector_type);
79647974}
......@@ -8377,16 +8387,16 @@ fn analyzeOptionalPayloadPtr(
83778387 const optional_ptr_ty = sema.typeOf(optional_ptr);
83788388 assert(optional_ptr_ty.zigTypeTag(mod) == .Pointer);
83798389
8380 const opt_type = optional_ptr_ty.elemType();
8390 const opt_type = optional_ptr_ty.childType(mod);
83818391 if (opt_type.zigTypeTag(mod) != .Optional) {
83828392 return sema.fail(block, src, "expected optional type, found '{}'", .{opt_type.fmt(sema.mod)});
83838393 }
83848394
8385 const child_type = try opt_type.optionalChildAlloc(sema.arena);
8395 const child_type = opt_type.optionalChild(mod);
83868396 const child_pointer = try Type.ptr(sema.arena, sema.mod, .{
83878397 .pointee_type = child_type,
83888398 .mutable = !optional_ptr_ty.isConstPtr(),
8389 .@"addrspace" = optional_ptr_ty.ptrAddressSpace(),
8399 .@"addrspace" = optional_ptr_ty.ptrAddressSpace(mod),
83908400 });
83918401
83928402 if (try sema.resolveDefinedValue(block, src, optional_ptr)) |ptr_val| {
......@@ -8401,7 +8411,7 @@ fn analyzeOptionalPayloadPtr(
84018411 child_pointer,
84028412 try Value.Tag.opt_payload_ptr.create(sema.arena, .{
84038413 .container_ptr = ptr_val,
8404 .container_ty = optional_ptr_ty.childType(),
8414 .container_ty = optional_ptr_ty.childType(mod),
84058415 }),
84068416 );
84078417 }
......@@ -8414,7 +8424,7 @@ fn analyzeOptionalPayloadPtr(
84148424 child_pointer,
84158425 try Value.Tag.opt_payload_ptr.create(sema.arena, .{
84168426 .container_ptr = ptr_val,
8417 .container_ty = optional_ptr_ty.childType(),
8427 .container_ty = optional_ptr_ty.childType(mod),
84188428 }),
84198429 );
84208430 }
......@@ -8448,14 +8458,14 @@ fn zirOptionalPayload(
84488458 const operand = try sema.resolveInst(inst_data.operand);
84498459 const operand_ty = sema.typeOf(operand);
84508460 const result_ty = switch (operand_ty.zigTypeTag(mod)) {
8451 .Optional => try operand_ty.optionalChildAlloc(sema.arena),
8461 .Optional => operand_ty.optionalChild(mod),
84528462 .Pointer => t: {
8453 if (operand_ty.ptrSize() != .C) {
8463 if (operand_ty.ptrSize(mod) != .C) {
84548464 return sema.failWithExpectedOptionalType(block, src, operand_ty);
84558465 }
84568466 // TODO https://github.com/ziglang/zig/issues/6597
84578467 if (true) break :t operand_ty;
8458 const ptr_info = operand_ty.ptrInfo().data;
8468 const ptr_info = operand_ty.ptrInfo(mod);
84598469 break :t try Type.ptr(sema.arena, sema.mod, .{
84608470 .pointee_type = try ptr_info.pointee_type.copy(sema.arena),
84618471 .@"align" = ptr_info.@"align",
......@@ -8569,18 +8579,18 @@ fn analyzeErrUnionPayloadPtr(
85698579 const operand_ty = sema.typeOf(operand);
85708580 assert(operand_ty.zigTypeTag(mod) == .Pointer);
85718581
8572 if (operand_ty.elemType().zigTypeTag(mod) != .ErrorUnion) {
8582 if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) {
85738583 return sema.fail(block, src, "expected error union type, found '{}'", .{
8574 operand_ty.elemType().fmt(sema.mod),
8584 operand_ty.childType(mod).fmt(sema.mod),
85758585 });
85768586 }
85778587
8578 const err_union_ty = operand_ty.elemType();
8588 const err_union_ty = operand_ty.childType(mod);
85798589 const payload_ty = err_union_ty.errorUnionPayload();
85808590 const operand_pointer_ty = try Type.ptr(sema.arena, sema.mod, .{
85818591 .pointee_type = payload_ty,
85828592 .mutable = !operand_ty.isConstPtr(),
8583 .@"addrspace" = operand_ty.ptrAddressSpace(),
8593 .@"addrspace" = operand_ty.ptrAddressSpace(mod),
85848594 });
85858595
85868596 if (try sema.resolveDefinedValue(block, src, operand)) |ptr_val| {
......@@ -8596,7 +8606,7 @@ fn analyzeErrUnionPayloadPtr(
85968606 operand_pointer_ty,
85978607 try Value.Tag.eu_payload_ptr.create(sema.arena, .{
85988608 .container_ptr = ptr_val,
8599 .container_ty = operand_ty.elemType(),
8609 .container_ty = operand_ty.childType(mod),
86008610 }),
86018611 );
86028612 }
......@@ -8609,7 +8619,7 @@ fn analyzeErrUnionPayloadPtr(
86098619 operand_pointer_ty,
86108620 try Value.Tag.eu_payload_ptr.create(sema.arena, .{
86118621 .container_ptr = ptr_val,
8612 .container_ty = operand_ty.elemType(),
8622 .container_ty = operand_ty.childType(mod),
86138623 }),
86148624 );
86158625 }
......@@ -8674,13 +8684,13 @@ fn zirErrUnionCodePtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
86748684 const operand_ty = sema.typeOf(operand);
86758685 assert(operand_ty.zigTypeTag(mod) == .Pointer);
86768686
8677 if (operand_ty.elemType().zigTypeTag(mod) != .ErrorUnion) {
8687 if (operand_ty.childType(mod).zigTypeTag(mod) != .ErrorUnion) {
86788688 return sema.fail(block, src, "expected error union type, found '{}'", .{
8679 operand_ty.elemType().fmt(sema.mod),
8689 operand_ty.childType(mod).fmt(sema.mod),
86808690 });
86818691 }
86828692
8683 const result_ty = operand_ty.elemType().errorUnionSet();
8693 const result_ty = operand_ty.childType(mod).errorUnionSet();
86848694
86858695 if (try sema.resolveDefinedValue(block, src, operand)) |pointer_val| {
86868696 if (try sema.pointerDeref(block, src, pointer_val, operand_ty)) |val| {
......@@ -10119,7 +10129,7 @@ fn zirSwitchCapture(
1011910129 const operand_is_ref = cond_tag == .switch_cond_ref;
1012010130 const operand_ptr = try sema.resolveInst(cond_info.operand);
1012110131 const operand_ptr_ty = sema.typeOf(operand_ptr);
10122 const operand_ty = if (operand_is_ref) operand_ptr_ty.childType() else operand_ptr_ty;
10132 const operand_ty = if (operand_is_ref) operand_ptr_ty.childType(mod) else operand_ptr_ty;
1012310133
1012410134 if (block.inline_case_capture != .none) {
1012510135 const item_val = sema.resolveConstValue(block, .unneeded, block.inline_case_capture, undefined) catch unreachable;
......@@ -10131,9 +10141,9 @@ fn zirSwitchCapture(
1013110141 if (is_ref) {
1013210142 const ptr_field_ty = try Type.ptr(sema.arena, sema.mod, .{
1013310143 .pointee_type = field_ty,
10134 .mutable = operand_ptr_ty.ptrIsMutable(),
10144 .mutable = operand_ptr_ty.ptrIsMutable(mod),
1013510145 .@"volatile" = operand_ptr_ty.isVolatilePtr(),
10136 .@"addrspace" = operand_ptr_ty.ptrAddressSpace(),
10146 .@"addrspace" = operand_ptr_ty.ptrAddressSpace(mod),
1013710147 });
1013810148 return sema.addConstant(
1013910149 ptr_field_ty,
......@@ -10150,9 +10160,9 @@ fn zirSwitchCapture(
1015010160 if (is_ref) {
1015110161 const ptr_field_ty = try Type.ptr(sema.arena, sema.mod, .{
1015210162 .pointee_type = field_ty,
10153 .mutable = operand_ptr_ty.ptrIsMutable(),
10163 .mutable = operand_ptr_ty.ptrIsMutable(mod),
1015410164 .@"volatile" = operand_ptr_ty.isVolatilePtr(),
10155 .@"addrspace" = operand_ptr_ty.ptrAddressSpace(),
10165 .@"addrspace" = operand_ptr_ty.ptrAddressSpace(mod),
1015610166 });
1015710167 return block.addStructFieldPtr(operand_ptr, field_index, ptr_field_ty);
1015810168 } else {
......@@ -10235,7 +10245,7 @@ fn zirSwitchCapture(
1023510245 const field_ty_ptr = try Type.ptr(sema.arena, sema.mod, .{
1023610246 .pointee_type = first_field.ty,
1023710247 .@"addrspace" = .generic,
10238 .mutable = operand_ptr_ty.ptrIsMutable(),
10248 .mutable = operand_ptr_ty.ptrIsMutable(mod),
1023910249 });
1024010250
1024110251 if (try sema.resolveDefinedValue(block, operand_src, operand_ptr)) |op_ptr_val| {
......@@ -10311,7 +10321,7 @@ fn zirSwitchCaptureTag(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Compile
1031110321 const cond_data = zir_datas[Zir.refToIndex(inst_data.operand).?].un_node;
1031210322 const operand_ptr = try sema.resolveInst(cond_data.operand);
1031310323 const operand_ptr_ty = sema.typeOf(operand_ptr);
10314 const operand_ty = if (is_ref) operand_ptr_ty.childType() else operand_ptr_ty;
10324 const operand_ty = if (is_ref) operand_ptr_ty.childType(mod) else operand_ptr_ty;
1031510325
1031610326 if (operand_ty.zigTypeTag(mod) != .Union) {
1031710327 const msg = msg: {
......@@ -10448,7 +10458,7 @@ fn zirSwitchBlock(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError
1044810458 const cond_index = Zir.refToIndex(extra.data.operand).?;
1044910459 const raw_operand = sema.resolveInst(zir_data[cond_index].un_node.operand) catch unreachable;
1045010460 const target_ty = sema.typeOf(raw_operand);
10451 break :blk if (zir_tags[cond_index] == .switch_cond_ref) target_ty.elemType() else target_ty;
10461 break :blk if (zir_tags[cond_index] == .switch_cond_ref) target_ty.childType(mod) else target_ty;
1045210462 };
1045310463 const union_originally = maybe_union_ty.zigTypeTag(mod) == .Union;
1045410464
......@@ -12132,7 +12142,7 @@ fn zirEmbedFile(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
1213212142 // into the final binary, and never loads the data into memory.
1213312143 // - When a Decl is destroyed, it can free the `*Module.EmbedFile`.
1213412144 embed_file.owner_decl = try anon_decl.finish(
12135 try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), embed_file.bytes.len),
12145 try Type.array(anon_decl.arena(), embed_file.bytes.len, Value.zero, Type.u8, mod),
1213612146 try Value.Tag.bytes.create(anon_decl.arena(), bytes_including_null),
1213712147 0, // default alignment
1213812148 );
......@@ -12200,7 +12210,7 @@ fn zirShl(
1220012210 const bit_value = Value.initPayload(&bits_payload.base);
1220112211 if (rhs_ty.zigTypeTag(mod) == .Vector) {
1220212212 var i: usize = 0;
12203 while (i < rhs_ty.vectorLen()) : (i += 1) {
12213 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
1220412214 var elem_value_buf: Value.ElemValueBuffer = undefined;
1220512215 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
1220612216 if (rhs_elem.compareHetero(.gte, bit_value, mod)) {
......@@ -12220,7 +12230,7 @@ fn zirShl(
1222012230 }
1222112231 if (rhs_ty.zigTypeTag(mod) == .Vector) {
1222212232 var i: usize = 0;
12223 while (i < rhs_ty.vectorLen()) : (i += 1) {
12233 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
1222412234 var elem_value_buf: Value.ElemValueBuffer = undefined;
1222512235 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
1222612236 if (rhs_elem.compareHetero(.lt, Value.zero, mod)) {
......@@ -12388,7 +12398,7 @@ fn zirShr(
1238812398 const bit_value = Value.initPayload(&bits_payload.base);
1238912399 if (rhs_ty.zigTypeTag(mod) == .Vector) {
1239012400 var i: usize = 0;
12391 while (i < rhs_ty.vectorLen()) : (i += 1) {
12401 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
1239212402 var elem_value_buf: Value.ElemValueBuffer = undefined;
1239312403 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
1239412404 if (rhs_elem.compareHetero(.gte, bit_value, mod)) {
......@@ -12408,7 +12418,7 @@ fn zirShr(
1240812418 }
1240912419 if (rhs_ty.zigTypeTag(mod) == .Vector) {
1241012420 var i: usize = 0;
12411 while (i < rhs_ty.vectorLen()) : (i += 1) {
12421 while (i < rhs_ty.vectorLen(mod)) : (i += 1) {
1241212422 var elem_value_buf: Value.ElemValueBuffer = undefined;
1241312423 const rhs_elem = rhs_val.elemValueBuffer(sema.mod, i, &elem_value_buf);
1241412424 if (rhs_elem.compareHetero(.lt, Value.zero, mod)) {
......@@ -12571,7 +12581,7 @@ fn zirBitNot(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1257112581 if (val.isUndef()) {
1257212582 return sema.addConstUndef(operand_type);
1257312583 } else if (operand_type.zigTypeTag(mod) == .Vector) {
12574 const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen());
12584 const vec_len = try sema.usizeCast(block, operand_src, operand_type.vectorLen(mod));
1257512585 var elem_val_buf: Value.ElemValueBuffer = undefined;
1257612586 const elems = try sema.arena.alloc(Value, vec_len);
1257712587 for (elems, 0..) |*elem, i| {
......@@ -12768,8 +12778,8 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1276812778 const result_ty = try Type.array(sema.arena, result_len, res_sent_val, resolved_elem_ty, sema.mod);
1276912779 const mod = sema.mod;
1277012780 const ptr_addrspace = p: {
12771 if (lhs_ty.zigTypeTag(mod) == .Pointer) break :p lhs_ty.ptrAddressSpace();
12772 if (rhs_ty.zigTypeTag(mod) == .Pointer) break :p rhs_ty.ptrAddressSpace();
12781 if (lhs_ty.zigTypeTag(mod) == .Pointer) break :p lhs_ty.ptrAddressSpace(mod);
12782 if (rhs_ty.zigTypeTag(mod) == .Pointer) break :p rhs_ty.ptrAddressSpace(mod);
1277312783 break :p null;
1277412784 };
1277512785
......@@ -12883,9 +12893,9 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
1288312893 const mod = sema.mod;
1288412894 const operand_ty = sema.typeOf(operand);
1288512895 switch (operand_ty.zigTypeTag(mod)) {
12886 .Array => return operand_ty.arrayInfo(),
12896 .Array => return operand_ty.arrayInfo(mod),
1288712897 .Pointer => {
12888 const ptr_info = operand_ty.ptrInfo().data;
12898 const ptr_info = operand_ty.ptrInfo(mod);
1288912899 switch (ptr_info.size) {
1289012900 // TODO: in the Many case here this should only work if the type
1289112901 // has a sentinel, and this code should compute the length based
......@@ -12900,7 +12910,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
1290012910 },
1290112911 .One => {
1290212912 if (ptr_info.pointee_type.zigTypeTag(mod) == .Array) {
12903 return ptr_info.pointee_type.arrayInfo();
12913 return ptr_info.pointee_type.arrayInfo(mod);
1290412914 }
1290512915 },
1290612916 .C => {},
......@@ -12912,7 +12922,7 @@ fn getArrayCatInfo(sema: *Sema, block: *Block, src: LazySrcLoc, operand: Air.Ins
1291212922 return .{
1291312923 .elem_type = peer_ty.elemType2(mod),
1291412924 .sentinel = null,
12915 .len = operand_ty.arrayLen(),
12925 .len = operand_ty.arrayLen(mod),
1291612926 };
1291712927 }
1291812928 },
......@@ -13035,7 +13045,7 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1303513045
1303613046 const result_ty = try Type.array(sema.arena, result_len, lhs_info.sentinel, lhs_info.elem_type, sema.mod);
1303713047
13038 const ptr_addrspace = if (lhs_ty.zigTypeTag(mod) == .Pointer) lhs_ty.ptrAddressSpace() else null;
13048 const ptr_addrspace = if (lhs_ty.zigTypeTag(mod) == .Pointer) lhs_ty.ptrAddressSpace(mod) else null;
1303913049 const lhs_len = try sema.usizeCast(block, lhs_src, lhs_info.len);
1304013050
1304113051 if (try sema.resolveDefinedValue(block, lhs_src, lhs)) |lhs_val| {
......@@ -14022,7 +14032,7 @@ fn intRem(
1402214032) CompileError!Value {
1402314033 const mod = sema.mod;
1402414034 if (ty.zigTypeTag(mod) == .Vector) {
14025 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
14035 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
1402614036 for (result_data, 0..) |*scalar, i| {
1402714037 var lhs_buf: Value.ElemValueBuffer = undefined;
1402814038 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -14484,7 +14494,10 @@ fn maybeRepeated(sema: *Sema, ty: Type, val: Value) !Value {
1448414494
1448514495fn overflowArithmeticTupleType(sema: *Sema, ty: Type) !Type {
1448614496 const mod = sema.mod;
14487 const ov_ty = if (ty.zigTypeTag(mod) == .Vector) try Type.vector(sema.arena, ty.vectorLen(), Type.u1) else Type.u1;
14497 const ov_ty = if (ty.zigTypeTag(mod) == .Vector) try mod.vectorType(.{
14498 .len = ty.vectorLen(mod),
14499 .child = .u1_type,
14500 }) else Type.u1;
1448814501
1448914502 const types = try sema.arena.alloc(Type, 2);
1449014503 const values = try sema.arena.alloc(Value, 2);
......@@ -14520,7 +14533,7 @@ fn analyzeArithmetic(
1452014533 const rhs_zig_ty_tag = try rhs_ty.zigTypeTagOrPoison(mod);
1452114534 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
1452214535
14523 if (lhs_zig_ty_tag == .Pointer) switch (lhs_ty.ptrSize()) {
14536 if (lhs_zig_ty_tag == .Pointer) switch (lhs_ty.ptrSize(mod)) {
1452414537 .One, .Slice => {},
1452514538 .Many, .C => {
1452614539 const air_tag: Air.Inst.Tag = switch (zir_tag) {
......@@ -14993,9 +15006,9 @@ fn analyzePtrArithmetic(
1499315006 const opt_ptr_val = try sema.resolveMaybeUndefVal(ptr);
1499415007 const opt_off_val = try sema.resolveDefinedValue(block, offset_src, offset);
1499515008 const ptr_ty = sema.typeOf(ptr);
14996 const ptr_info = ptr_ty.ptrInfo().data;
15009 const ptr_info = ptr_ty.ptrInfo(mod);
1499715010 const elem_ty = if (ptr_info.size == .One and ptr_info.pointee_type.zigTypeTag(mod) == .Array)
14998 ptr_info.pointee_type.childType()
15011 ptr_info.pointee_type.childType(mod)
1499915012 else
1500015013 ptr_info.pointee_type;
1500115014
......@@ -15466,7 +15479,10 @@ fn cmpSelf(
1546615479 if (rhs_val.isUndef()) return sema.addConstUndef(Type.bool);
1546715480
1546815481 if (resolved_type.zigTypeTag(mod) == .Vector) {
15469 const result_ty = try Type.vector(sema.arena, resolved_type.vectorLen(), Type.bool);
15482 const result_ty = try mod.vectorType(.{
15483 .len = resolved_type.vectorLen(mod),
15484 .child = .bool_type,
15485 });
1547015486 const cmp_val = try sema.compareVector(lhs_val, op, rhs_val, resolved_type);
1547115487 return sema.addConstant(result_ty, cmp_val);
1547215488 }
......@@ -15767,6 +15783,7 @@ fn zirBuiltinSrc(
1576715783 const tracy = trace(@src());
1576815784 defer tracy.end();
1576915785
15786 const mod = sema.mod;
1577015787 const extra = sema.code.extraData(Zir.Inst.Src, extended.operand).data;
1577115788 const src = LazySrcLoc.nodeOffset(extra.node);
1577215789 const func = sema.func orelse return sema.fail(block, src, "@src outside function", .{});
......@@ -15778,7 +15795,7 @@ fn zirBuiltinSrc(
1577815795 const name = std.mem.span(fn_owner_decl.name);
1577915796 const bytes = try anon_decl.arena().dupe(u8, name[0 .. name.len + 1]);
1578015797 const new_decl = try anon_decl.finish(
15781 try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), bytes.len - 1),
15798 try Type.array(anon_decl.arena(), bytes.len - 1, Value.zero, Type.u8, mod),
1578215799 try Value.Tag.bytes.create(anon_decl.arena(), bytes),
1578315800 0, // default alignment
1578415801 );
......@@ -15791,7 +15808,7 @@ fn zirBuiltinSrc(
1579115808 // The compiler must not call realpath anywhere.
1579215809 const name = try fn_owner_decl.getFileScope().fullPathZ(anon_decl.arena());
1579315810 const new_decl = try anon_decl.finish(
15794 try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), name.len),
15811 try Type.array(anon_decl.arena(), name.len, Value.zero, Type.u8, mod),
1579515812 try Value.Tag.bytes.create(anon_decl.arena(), name[0 .. name.len + 1]),
1579615813 0, // default alignment
1579715814 );
......@@ -16024,7 +16041,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1602416041 );
1602516042 },
1602616043 .Pointer => {
16027 const info = ty.ptrInfo().data;
16044 const info = ty.ptrInfo(mod);
1602816045 const alignment = if (info.@"align" != 0)
1602916046 try Value.Tag.int_u64.create(sema.arena, info.@"align")
1603016047 else
......@@ -16059,7 +16076,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1605916076 );
1606016077 },
1606116078 .Array => {
16062 const info = ty.arrayInfo();
16079 const info = ty.arrayInfo(mod);
1606316080 const field_values = try sema.arena.alloc(Value, 3);
1606416081 // len: comptime_int,
1606516082 field_values[0] = try Value.Tag.int_u64.create(sema.arena, info.len);
......@@ -16077,7 +16094,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1607716094 );
1607816095 },
1607916096 .Vector => {
16080 const info = ty.arrayInfo();
16097 const info = ty.arrayInfo(mod);
1608116098 const field_values = try sema.arena.alloc(Value, 2);
1608216099 // len: comptime_int,
1608316100 field_values[0] = try Value.Tag.int_u64.create(sema.arena, info.len);
......@@ -16095,7 +16112,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1609516112 .Optional => {
1609616113 const field_values = try sema.arena.alloc(Value, 1);
1609716114 // child: type,
16098 field_values[0] = try Value.Tag.ty.create(sema.arena, try ty.optionalChildAlloc(sema.arena));
16115 field_values[0] = try Value.Tag.ty.create(sema.arena, ty.optionalChild(mod));
1609916116
1610016117 return sema.addConstant(
1610116118 type_info_ty,
......@@ -16141,7 +16158,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1614116158 defer anon_decl.deinit();
1614216159 const bytes = try anon_decl.arena().dupeZ(u8, name);
1614316160 const new_decl = try anon_decl.finish(
16144 try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), bytes.len),
16161 try Type.array(anon_decl.arena(), bytes.len, Value.zero, Type.u8, mod),
1614516162 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
1614616163 0, // default alignment
1614716164 );
......@@ -16250,7 +16267,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1625016267 defer anon_decl.deinit();
1625116268 const bytes = try anon_decl.arena().dupeZ(u8, name);
1625216269 const new_decl = try anon_decl.finish(
16253 try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), bytes.len),
16270 try Type.array(anon_decl.arena(), bytes.len, Value.zero, Type.u8, mod),
1625416271 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
1625516272 0, // default alignment
1625616273 );
......@@ -16338,7 +16355,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1633816355 defer anon_decl.deinit();
1633916356 const bytes = try anon_decl.arena().dupeZ(u8, name);
1634016357 const new_decl = try anon_decl.finish(
16341 try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), bytes.len),
16358 try Type.array(anon_decl.arena(), bytes.len, Value.zero, Type.u8, mod),
1634216359 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
1634316360 0, // default alignment
1634416361 );
......@@ -16448,7 +16465,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1644816465 else
1644916466 try std.fmt.allocPrintZ(anon_decl.arena(), "{d}", .{i});
1645016467 const new_decl = try anon_decl.finish(
16451 try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), bytes.len),
16468 try Type.array(anon_decl.arena(), bytes.len, Value.zero, Type.u8, mod),
1645216469 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
1645316470 0, // default alignment
1645416471 );
......@@ -16490,7 +16507,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1649016507 defer anon_decl.deinit();
1649116508 const bytes = try anon_decl.arena().dupeZ(u8, name);
1649216509 const new_decl = try anon_decl.finish(
16493 try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), bytes.len),
16510 try Type.array(anon_decl.arena(), bytes.len, Value.zero, Type.u8, mod),
1649416511 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
1649516512 0, // default alignment
1649616513 );
......@@ -16666,14 +16683,15 @@ fn typeInfoNamespaceDecls(
1666616683 decl_vals: *std.ArrayList(Value),
1666716684 seen_namespaces: *std.AutoHashMap(*Namespace, void),
1666816685) !void {
16686 const mod = sema.mod;
1666916687 const gop = try seen_namespaces.getOrPut(namespace);
1667016688 if (gop.found_existing) return;
1667116689 const decls = namespace.decls.keys();
1667216690 for (decls) |decl_index| {
16673 const decl = sema.mod.declPtr(decl_index);
16691 const decl = mod.declPtr(decl_index);
1667416692 if (decl.kind == .@"usingnamespace") {
1667516693 if (decl.analysis == .in_progress) continue;
16676 try sema.mod.ensureDeclAnalyzed(decl_index);
16694 try mod.ensureDeclAnalyzed(decl_index);
1667716695 const new_ns = decl.val.toType().getNamespace().?;
1667816696 try sema.typeInfoNamespaceDecls(block, decls_anon_decl, new_ns, decl_vals, seen_namespaces);
1667916697 continue;
......@@ -16684,7 +16702,7 @@ fn typeInfoNamespaceDecls(
1668416702 defer anon_decl.deinit();
1668516703 const bytes = try anon_decl.arena().dupeZ(u8, mem.sliceTo(decl.name, 0));
1668616704 const new_decl = try anon_decl.finish(
16687 try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), bytes.len),
16705 try Type.array(anon_decl.arena(), bytes.len, Value.zero, Type.u8, mod),
1668816706 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
1668916707 0, // default alignment
1669016708 );
......@@ -16770,9 +16788,9 @@ fn log2IntType(sema: *Sema, block: *Block, operand: Type, src: LazySrcLoc) Compi
1677016788 .Vector => {
1677116789 const elem_ty = operand.elemType2(mod);
1677216790 const log2_elem_ty = try sema.log2IntType(block, elem_ty, src);
16773 return Type.Tag.vector.create(sema.arena, .{
16774 .len = operand.vectorLen(),
16775 .elem_type = log2_elem_ty,
16791 return mod.vectorType(.{
16792 .len = operand.vectorLen(mod),
16793 .child = log2_elem_ty.ip_index,
1677616794 });
1677716795 },
1677816796 else => {},
......@@ -17207,7 +17225,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1720717225 _ = try sema.analyzeBodyInner(&sub_block, body);
1720817226
1720917227 const operand_ty = sema.typeOf(operand);
17210 const ptr_info = operand_ty.ptrInfo().data;
17228 const ptr_info = operand_ty.ptrInfo(mod);
1721117229 const res_ty = try Type.ptr(sema.arena, sema.mod, .{
1721217230 .pointee_type = err_union_ty.errorUnionPayload(),
1721317231 .@"addrspace" = ptr_info.@"addrspace",
......@@ -17398,6 +17416,7 @@ fn retWithErrTracing(
1739817416 ret_tag: Air.Inst.Tag,
1739917417 operand: Air.Inst.Ref,
1740017418) CompileError!Zir.Inst.Index {
17419 const mod = sema.mod;
1740117420 const need_check = switch (is_non_err) {
1740217421 .bool_true => {
1740317422 _ = try block.addUnOp(ret_tag, operand);
......@@ -17409,7 +17428,7 @@ fn retWithErrTracing(
1740917428 const gpa = sema.gpa;
1741017429 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
1741117430 const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty);
17412 const ptr_stack_trace_ty = try Type.Tag.single_mut_pointer.create(sema.arena, stack_trace_ty);
17431 const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty);
1741317432 const err_return_trace = try block.addTy(.err_return_trace, ptr_stack_trace_ty);
1741417433 const return_err_fn = try sema.getBuiltin("returnError");
1741517434 const args: [1]Air.Inst.Ref = .{err_return_trace};
......@@ -17755,7 +17774,7 @@ fn structInitEmpty(
1775517774
1775617775fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) CompileError!Air.Inst.Ref {
1775717776 const mod = sema.mod;
17758 const arr_len = obj_ty.arrayLen();
17777 const arr_len = obj_ty.arrayLen(mod);
1775917778 if (arr_len != 0) {
1776017779 if (obj_ty.zigTypeTag(mod) == .Array) {
1776117780 return sema.fail(block, src, "expected {d} array elements; found 0", .{arr_len});
......@@ -17763,7 +17782,7 @@ fn arrayInitEmpty(sema: *Sema, block: *Block, src: LazySrcLoc, obj_ty: Type) Com
1776317782 return sema.fail(block, src, "expected {d} vector elements; found 0", .{arr_len});
1776417783 }
1776517784 }
17766 if (obj_ty.sentinel()) |sentinel| {
17785 if (obj_ty.sentinel(mod)) |sentinel| {
1776717786 const val = try Value.Tag.empty_array_sentinel.create(sema.arena, sentinel);
1776817787 return sema.addConstant(obj_ty, val);
1776917788 } else {
......@@ -18199,6 +18218,7 @@ fn zirArrayInit(
1819918218 inst: Zir.Inst.Index,
1820018219 is_ref: bool,
1820118220) CompileError!Air.Inst.Ref {
18221 const mod = sema.mod;
1820218222 const gpa = sema.gpa;
1820318223 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
1820418224 const src = inst_data.src();
......@@ -18208,8 +18228,7 @@ fn zirArrayInit(
1820818228 assert(args.len >= 2); // array_ty + at least one element
1820918229
1821018230 const array_ty = try sema.resolveType(block, src, args[0]);
18211 const sentinel_val = array_ty.sentinel();
18212 const mod = sema.mod;
18231 const sentinel_val = array_ty.sentinel(mod);
1821318232
1821418233 const resolved_args = try gpa.alloc(Air.Inst.Ref, args.len - 1 + @boolToInt(sentinel_val != null));
1821518234 defer gpa.free(resolved_args);
......@@ -18489,14 +18508,16 @@ fn zirErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
1848918508}
1849018509
1849118510fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
18511 const mod = sema.mod;
1849218512 const unresolved_stack_trace_ty = try sema.getBuiltinType("StackTrace");
1849318513 const stack_trace_ty = try sema.resolveTypeFields(unresolved_stack_trace_ty);
18494 const opt_ptr_stack_trace_ty = try Type.Tag.optional_single_mut_pointer.create(sema.arena, stack_trace_ty);
18514 const ptr_stack_trace_ty = try mod.singleMutPtrType(stack_trace_ty);
18515 const opt_ptr_stack_trace_ty = try Type.optional(sema.arena, ptr_stack_trace_ty, mod);
1849518516
1849618517 if (sema.owner_func != null and
1849718518 sema.owner_func.?.calls_or_awaits_errorable_fn and
18498 sema.mod.comp.bin_file.options.error_return_tracing and
18499 sema.mod.backendSupportsFeature(.error_return_trace))
18519 mod.comp.bin_file.options.error_return_tracing and
18520 mod.backendSupportsFeature(.error_return_trace))
1850018521 {
1850118522 return block.addTy(.err_return_trace, opt_ptr_stack_trace_ty);
1850218523 }
......@@ -18585,8 +18606,11 @@ fn zirUnaryMath(
1858518606 switch (operand_ty.zigTypeTag(mod)) {
1858618607 .Vector => {
1858718608 const scalar_ty = operand_ty.scalarType(mod);
18588 const vec_len = operand_ty.vectorLen();
18589 const result_ty = try Type.vector(sema.arena, vec_len, scalar_ty);
18609 const vec_len = operand_ty.vectorLen(mod);
18610 const result_ty = try mod.vectorType(.{
18611 .len = vec_len,
18612 .child = scalar_ty.ip_index,
18613 });
1859018614 if (try sema.resolveMaybeUndefVal(operand)) |val| {
1859118615 if (val.isUndef())
1859218616 return sema.addConstUndef(result_ty);
......@@ -18730,12 +18754,15 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1873018754 const len_val = struct_val[0];
1873118755 const child_val = struct_val[1];
1873218756
18733 const len = len_val.toUnsignedInt(mod);
18757 const len = @intCast(u32, len_val.toUnsignedInt(mod));
1873418758 const child_ty = child_val.toType();
1873518759
1873618760 try sema.checkVectorElemType(block, src, child_ty);
1873718761
18738 const ty = try Type.vector(sema.arena, len, try child_ty.copy(sema.arena));
18762 const ty = try mod.vectorType(.{
18763 .len = len,
18764 .child = child_ty.ip_index,
18765 });
1873918766 return sema.addType(ty);
1874018767 },
1874118768 .Float => {
......@@ -18872,7 +18899,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1887218899
1887318900 const child_ty = try child_val.toType().copy(sema.arena);
1887418901
18875 const ty = try Type.optional(sema.arena, child_ty);
18902 const ty = try Type.optional(sema.arena, child_ty, mod);
1887618903 return sema.addType(ty);
1887718904 },
1887818905 .ErrorUnion => {
......@@ -18912,7 +18939,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1891218939 // TODO use reflection instead of magic numbers here
1891318940 // error_set: type,
1891418941 const name_val = struct_val[0];
18915 const name_str = try name_val.toAllocatedBytes(Type.initTag(.const_slice_u8), sema.arena, sema.mod);
18942 const name_str = try name_val.toAllocatedBytes(Type.const_slice_u8, sema.arena, sema.mod);
1891618943
1891718944 const kv = try mod.getErrorValue(name_str);
1891818945 const gop = names.getOrPutAssumeCapacity(kv.key);
......@@ -19038,7 +19065,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1903819065 const value_val = field_struct_val[1];
1903919066
1904019067 const field_name = try name_val.toAllocatedBytes(
19041 Type.initTag(.const_slice_u8),
19068 Type.const_slice_u8,
1904219069 new_decl_arena_allocator,
1904319070 sema.mod,
1904419071 );
......@@ -19215,7 +19242,7 @@ fn zirReify(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData, in
1921519242 const alignment_val = field_struct_val[2];
1921619243
1921719244 const field_name = try name_val.toAllocatedBytes(
19218 Type.initTag(.const_slice_u8),
19245 Type.const_slice_u8,
1921919246 new_decl_arena_allocator,
1922019247 sema.mod,
1922119248 );
......@@ -19482,7 +19509,7 @@ fn reifyStruct(
1948219509 }
1948319510
1948419511 const field_name = try name_val.toAllocatedBytes(
19485 Type.initTag(.const_slice_u8),
19512 Type.const_slice_u8,
1948619513 new_decl_arena_allocator,
1948719514 mod,
1948819515 );
......@@ -19626,7 +19653,7 @@ fn zirAddrSpaceCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
1962619653
1962719654 try sema.checkPtrOperand(block, ptr_src, ptr_ty);
1962819655
19629 var ptr_info = ptr_ty.ptrInfo().data;
19656 var ptr_info = ptr_ty.ptrInfo(mod);
1963019657 const src_addrspace = ptr_info.@"addrspace";
1963119658 if (!target_util.addrSpaceCastIsValid(sema.mod.getTarget(), src_addrspace, dest_addrspace)) {
1963219659 const msg = msg: {
......@@ -19641,7 +19668,7 @@ fn zirAddrSpaceCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
1964119668 ptr_info.@"addrspace" = dest_addrspace;
1964219669 const dest_ptr_ty = try Type.ptr(sema.arena, sema.mod, ptr_info);
1964319670 const dest_ty = if (ptr_ty.zigTypeTag(mod) == .Optional)
19644 try Type.optional(sema.arena, dest_ptr_ty)
19671 try Type.optional(sema.arena, dest_ptr_ty, mod)
1964519672 else
1964619673 dest_ptr_ty;
1964719674
......@@ -19731,6 +19758,7 @@ fn zirCVaStart(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
1973119758}
1973219759
1973319760fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
19761 const mod = sema.mod;
1973419762 const inst_data = sema.code.instructions.items(.data)[inst].un_node;
1973519763 const ty_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = inst_data.src_node };
1973619764 const ty = try sema.resolveType(block, ty_src, inst_data.operand);
......@@ -19738,10 +19766,10 @@ fn zirTypeName(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1973819766 var anon_decl = try block.startAnonDecl();
1973919767 defer anon_decl.deinit();
1974019768
19741 const bytes = try ty.nameAllocArena(anon_decl.arena(), sema.mod);
19769 const bytes = try ty.nameAllocArena(anon_decl.arena(), mod);
1974219770
1974319771 const new_decl = try anon_decl.finish(
19744 try Type.Tag.array_u8_sentinel_0.create(anon_decl.arena(), bytes.len),
19772 try Type.array(anon_decl.arena(), bytes.len, Value.zero, Type.u8, mod),
1974519773 try Value.Tag.bytes.create(anon_decl.arena(), bytes[0 .. bytes.len + 1]),
1974619774 0, // default alignment
1974719775 );
......@@ -19842,7 +19870,7 @@ fn zirIntToPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1984219870 const elem_ty = ptr_ty.elemType2(mod);
1984319871 const ptr_align = try ptr_ty.ptrAlignmentAdvanced(mod, sema);
1984419872
19845 if (ptr_ty.isSlice()) {
19873 if (ptr_ty.isSlice(mod)) {
1984619874 const msg = msg: {
1984719875 const msg = try sema.errMsg(block, type_src, "integer cannot be converted to slice type '{}'", .{ptr_ty.fmt(sema.mod)});
1984819876 errdefer msg.destroy(sema.gpa);
......@@ -19987,8 +20015,8 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1998720015 try sema.checkPtrType(block, dest_ty_src, dest_ty);
1998820016 try sema.checkPtrOperand(block, operand_src, operand_ty);
1998920017
19990 const operand_info = operand_ty.ptrInfo().data;
19991 const dest_info = dest_ty.ptrInfo().data;
20018 const operand_info = operand_ty.ptrInfo(mod);
20019 const dest_info = dest_ty.ptrInfo(mod);
1999220020 if (!operand_info.mutable and dest_info.mutable) {
1999320021 const msg = msg: {
1999420022 const msg = try sema.errMsg(block, src, "cast discards const qualifier", .{});
......@@ -20042,12 +20070,11 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2004220070 const aligned_dest_ty = if (operand_align <= dest_align) dest_ty else blk: {
2004320071 // Unwrap the pointer (or pointer-like optional) type, set alignment, and re-wrap into result
2004420072 if (dest_ty.zigTypeTag(mod) == .Optional) {
20045 var buf: Type.Payload.ElemType = undefined;
20046 var dest_ptr_info = dest_ty.optionalChild(&buf).ptrInfo().data;
20073 var dest_ptr_info = dest_ty.optionalChild(mod).ptrInfo(mod);
2004720074 dest_ptr_info.@"align" = operand_align;
20048 break :blk try Type.optional(sema.arena, try Type.ptr(sema.arena, sema.mod, dest_ptr_info));
20075 break :blk try Type.optional(sema.arena, try Type.ptr(sema.arena, sema.mod, dest_ptr_info), mod);
2004920076 } else {
20050 var dest_ptr_info = dest_ty.ptrInfo().data;
20077 var dest_ptr_info = dest_ty.ptrInfo(mod);
2005120078 dest_ptr_info.@"align" = operand_align;
2005220079 break :blk try Type.ptr(sema.arena, sema.mod, dest_ptr_info);
2005320080 }
......@@ -20110,6 +20137,7 @@ fn zirPtrCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2011020137}
2011120138
2011220139fn zirConstCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
20140 const mod = sema.mod;
2011320141 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
2011420142 const src = LazySrcLoc.nodeOffset(extra.node);
2011520143 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
......@@ -20117,7 +20145,7 @@ fn zirConstCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2011720145 const operand_ty = sema.typeOf(operand);
2011820146 try sema.checkPtrOperand(block, operand_src, operand_ty);
2011920147
20120 var ptr_info = operand_ty.ptrInfo().data;
20148 var ptr_info = operand_ty.ptrInfo(mod);
2012120149 ptr_info.mutable = true;
2012220150 const dest_ty = try Type.ptr(sema.arena, sema.mod, ptr_info);
2012320151
......@@ -20130,6 +20158,7 @@ fn zirConstCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData
2013020158}
2013120159
2013220160fn zirVolatileCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!Air.Inst.Ref {
20161 const mod = sema.mod;
2013320162 const extra = sema.code.extraData(Zir.Inst.UnNode, extended.operand).data;
2013420163 const src = LazySrcLoc.nodeOffset(extra.node);
2013520164 const operand_src: LazySrcLoc = .{ .node_offset_builtin_call_arg0 = extra.node };
......@@ -20137,7 +20166,7 @@ fn zirVolatileCast(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
2013720166 const operand_ty = sema.typeOf(operand);
2013820167 try sema.checkPtrOperand(block, operand_src, operand_ty);
2013920168
20140 var ptr_info = operand_ty.ptrInfo().data;
20169 var ptr_info = operand_ty.ptrInfo(mod);
2014120170 ptr_info.@"volatile" = false;
2014220171 const dest_ty = try Type.ptr(sema.arena, sema.mod, ptr_info);
2014320172
......@@ -20163,7 +20192,10 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2016320192 const operand_scalar_ty = try sema.checkIntOrVectorAllowComptime(block, operand_ty, operand_src);
2016420193 const is_vector = operand_ty.zigTypeTag(mod) == .Vector;
2016520194 const dest_ty = if (is_vector)
20166 try Type.vector(sema.arena, operand_ty.vectorLen(), dest_scalar_ty)
20195 try mod.vectorType(.{
20196 .len = operand_ty.vectorLen(mod),
20197 .child = dest_scalar_ty.ip_index,
20198 })
2016720199 else
2016820200 dest_scalar_ty;
2016920201
......@@ -20218,7 +20250,7 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2021820250 );
2021920251 }
2022020252 var elem_buf: Value.ElemValueBuffer = undefined;
20221 const elems = try sema.arena.alloc(Value, operand_ty.vectorLen());
20253 const elems = try sema.arena.alloc(Value, operand_ty.vectorLen(mod));
2022220254 for (elems, 0..) |*elem, i| {
2022320255 const elem_val = val.elemValueBuffer(sema.mod, i, &elem_buf);
2022420256 elem.* = try elem_val.intTrunc(operand_scalar_ty, sema.arena, dest_info.signedness, dest_info.bits, sema.mod);
......@@ -20245,7 +20277,7 @@ fn zirAlignCast(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2024520277
2024620278 try sema.checkPtrOperand(block, ptr_src, ptr_ty);
2024720279
20248 var ptr_info = ptr_ty.ptrInfo().data;
20280 var ptr_info = ptr_ty.ptrInfo(mod);
2024920281 ptr_info.@"align" = dest_align;
2025020282 var dest_ty = try Type.ptr(sema.arena, sema.mod, ptr_info);
2025120283 if (ptr_ty.zigTypeTag(mod) == .Optional) {
......@@ -20314,8 +20346,11 @@ fn zirBitCount(
2031420346 const result_scalar_ty = try mod.smallestUnsignedInt(bits);
2031520347 switch (operand_ty.zigTypeTag(mod)) {
2031620348 .Vector => {
20317 const vec_len = operand_ty.vectorLen();
20318 const result_ty = try Type.vector(sema.arena, vec_len, result_scalar_ty);
20349 const vec_len = operand_ty.vectorLen(mod);
20350 const result_ty = try mod.vectorType(.{
20351 .len = vec_len,
20352 .child = result_scalar_ty.ip_index,
20353 });
2031920354 if (try sema.resolveMaybeUndefVal(operand)) |val| {
2032020355 if (val.isUndef()) return sema.addConstUndef(result_ty);
2032120356
......@@ -20388,7 +20423,7 @@ fn zirByteSwap(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
2038820423 if (val.isUndef())
2038920424 return sema.addConstUndef(operand_ty);
2039020425
20391 const vec_len = operand_ty.vectorLen();
20426 const vec_len = operand_ty.vectorLen(mod);
2039220427 var elem_buf: Value.ElemValueBuffer = undefined;
2039320428 const elems = try sema.arena.alloc(Value, vec_len);
2039420429 for (elems, 0..) |*elem, i| {
......@@ -20437,7 +20472,7 @@ fn zirBitReverse(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!
2043720472 if (val.isUndef())
2043820473 return sema.addConstUndef(operand_ty);
2043920474
20440 const vec_len = operand_ty.vectorLen();
20475 const vec_len = operand_ty.vectorLen(mod);
2044120476 var elem_buf: Value.ElemValueBuffer = undefined;
2044220477 const elems = try sema.arena.alloc(Value, vec_len);
2044320478 for (elems, 0..) |*elem, i| {
......@@ -20546,7 +20581,7 @@ fn checkInvalidPtrArithmetic(
2054620581) CompileError!void {
2054720582 const mod = sema.mod;
2054820583 switch (try ty.zigTypeTagOrPoison(mod)) {
20549 .Pointer => switch (ty.ptrSize()) {
20584 .Pointer => switch (ty.ptrSize(mod)) {
2055020585 .One, .Slice => return,
2055120586 .Many, .C => return sema.fail(
2055220587 block,
......@@ -20676,7 +20711,7 @@ fn checkNumericType(
2067620711 const mod = sema.mod;
2067720712 switch (ty.zigTypeTag(mod)) {
2067820713 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},
20679 .Vector => switch (ty.childType().zigTypeTag(mod)) {
20714 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
2068020715 .ComptimeFloat, .Float, .ComptimeInt, .Int => {},
2068120716 else => |t| return sema.fail(block, ty_src, "expected number, found '{}'", .{t}),
2068220717 },
......@@ -20726,7 +20761,7 @@ fn checkAtomicPtrOperand(
2072620761
2072720762 const ptr_ty = sema.typeOf(ptr);
2072820763 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(mod)) {
20729 .Pointer => ptr_ty.ptrInfo().data,
20764 .Pointer => ptr_ty.ptrInfo(mod),
2073020765 else => {
2073120766 const wanted_ptr_ty = try Type.ptr(sema.arena, sema.mod, wanted_ptr_data);
2073220767 _ = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);
......@@ -20797,7 +20832,7 @@ fn checkIntOrVector(
2079720832 switch (try operand_ty.zigTypeTagOrPoison(mod)) {
2079820833 .Int => return operand_ty,
2079920834 .Vector => {
20800 const elem_ty = operand_ty.childType();
20835 const elem_ty = operand_ty.childType(mod);
2080120836 switch (try elem_ty.zigTypeTagOrPoison(mod)) {
2080220837 .Int => return elem_ty,
2080320838 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{
......@@ -20821,7 +20856,7 @@ fn checkIntOrVectorAllowComptime(
2082120856 switch (try operand_ty.zigTypeTagOrPoison(mod)) {
2082220857 .Int, .ComptimeInt => return operand_ty,
2082320858 .Vector => {
20824 const elem_ty = operand_ty.childType();
20859 const elem_ty = operand_ty.childType(mod);
2082520860 switch (try elem_ty.zigTypeTagOrPoison(mod)) {
2082620861 .Int, .ComptimeInt => return elem_ty,
2082720862 else => return sema.fail(block, operand_src, "expected vector of integers; found vector of '{}'", .{
......@@ -20870,7 +20905,7 @@ fn checkSimdBinOp(
2087020905 const rhs_ty = sema.typeOf(uncasted_rhs);
2087120906
2087220907 try sema.checkVectorizableBinaryOperands(block, src, lhs_ty, rhs_ty, lhs_src, rhs_src);
20873 var vec_len: ?usize = if (lhs_ty.zigTypeTag(mod) == .Vector) lhs_ty.vectorLen() else null;
20908 var vec_len: ?usize = if (lhs_ty.zigTypeTag(mod) == .Vector) lhs_ty.vectorLen(mod) else null;
2087420909 const result_ty = try sema.resolvePeerTypes(block, src, &.{ uncasted_lhs, uncasted_rhs }, .{
2087520910 .override = &[_]?LazySrcLoc{ lhs_src, rhs_src },
2087620911 });
......@@ -20912,8 +20947,8 @@ fn checkVectorizableBinaryOperands(
2091220947 };
2091320948
2091420949 if (lhs_is_vector and rhs_is_vector) {
20915 const lhs_len = lhs_ty.arrayLen();
20916 const rhs_len = rhs_ty.arrayLen();
20950 const lhs_len = lhs_ty.arrayLen(mod);
20951 const rhs_len = rhs_ty.arrayLen(mod);
2091720952 if (lhs_len != rhs_len) {
2091820953 const msg = msg: {
2091920954 const msg = try sema.errMsg(block, src, "vector length mismatch", .{});
......@@ -20966,7 +21001,7 @@ fn resolveExportOptions(
2096621001
2096721002 const name_operand = try sema.fieldVal(block, src, options, "name", name_src);
2096821003 const name_val = try sema.resolveConstValue(block, name_src, name_operand, "name of exported value must be comptime-known");
20969 const name_ty = Type.initTag(.const_slice_u8);
21004 const name_ty = Type.const_slice_u8;
2097021005 const name = try name_val.toAllocatedBytes(name_ty, sema.arena, mod);
2097121006
2097221007 const linkage_operand = try sema.fieldVal(block, src, options, "linkage", linkage_src);
......@@ -20975,7 +21010,7 @@ fn resolveExportOptions(
2097521010
2097621011 const section_operand = try sema.fieldVal(block, src, options, "section", section_src);
2097721012 const section_opt_val = try sema.resolveConstValue(block, section_src, section_operand, "linksection of exported value must be comptime-known");
20978 const section_ty = Type.initTag(.const_slice_u8);
21013 const section_ty = Type.const_slice_u8;
2097921014 const section = if (section_opt_val.optionalValue(mod)) |section_val|
2098021015 try section_val.toAllocatedBytes(section_ty, sema.arena, mod)
2098121016 else
......@@ -21087,7 +21122,7 @@ fn zirCmpxchg(
2108721122 return sema.fail(block, failure_order_src, "failure atomic ordering must not be Release or AcqRel", .{});
2108821123 }
2108921124
21090 const result_ty = try Type.optional(sema.arena, elem_ty);
21125 const result_ty = try Type.optional(sema.arena, elem_ty, mod);
2109121126
2109221127 // special case zero bit types
2109321128 if ((try sema.typeHasOnePossibleValue(elem_ty)) != null) {
......@@ -21133,6 +21168,7 @@ fn zirCmpxchg(
2113321168}
2113421169
2113521170fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.Inst.Ref {
21171 const mod = sema.mod;
2113621172 const inst_data = sema.code.instructions.items(.data)[inst].pl_node;
2113721173 const extra = sema.code.extraData(Zir.Inst.Bin, inst_data.payload_index).data;
2113821174 const len_src: LazySrcLoc = .{ .node_offset_bin_lhs = inst_data.src_node };
......@@ -21141,9 +21177,9 @@ fn zirSplat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
2114121177 const scalar = try sema.resolveInst(extra.rhs);
2114221178 const scalar_ty = sema.typeOf(scalar);
2114321179 try sema.checkVectorElemType(block, scalar_src, scalar_ty);
21144 const vector_ty = try Type.Tag.vector.create(sema.arena, .{
21180 const vector_ty = try mod.vectorType(.{
2114521181 .len = len,
21146 .elem_type = scalar_ty,
21182 .child = scalar_ty.ip_index,
2114721183 });
2114821184 if (try sema.resolveMaybeUndefVal(scalar)) |scalar_val| {
2114921185 if (scalar_val.isUndef()) return sema.addConstUndef(vector_ty);
......@@ -21172,7 +21208,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2117221208 return sema.fail(block, operand_src, "expected vector, found '{}'", .{operand_ty.fmt(mod)});
2117321209 }
2117421210
21175 const scalar_ty = operand_ty.childType();
21211 const scalar_ty = operand_ty.childType(mod);
2117621212
2117721213 // Type-check depending on operation.
2117821214 switch (operation) {
......@@ -21190,7 +21226,7 @@ fn zirReduce(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
2119021226 },
2119121227 }
2119221228
21193 const vec_len = operand_ty.vectorLen();
21229 const vec_len = operand_ty.vectorLen(mod);
2119421230 if (vec_len == 0) {
2119521231 // TODO re-evaluate if we should introduce a "neutral value" for some operations,
2119621232 // e.g. zero for add and one for mul.
......@@ -21243,12 +21279,12 @@ fn zirShuffle(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
2124321279 var mask_ty = sema.typeOf(mask);
2124421280
2124521281 const mask_len = switch (sema.typeOf(mask).zigTypeTag(mod)) {
21246 .Array, .Vector => sema.typeOf(mask).arrayLen(),
21282 .Array, .Vector => sema.typeOf(mask).arrayLen(mod),
2124721283 else => return sema.fail(block, mask_src, "expected vector or array, found '{}'", .{sema.typeOf(mask).fmt(sema.mod)}),
2124821284 };
21249 mask_ty = try Type.Tag.vector.create(sema.arena, .{
21250 .len = mask_len,
21251 .elem_type = Type.i32,
21285 mask_ty = try mod.vectorType(.{
21286 .len = @intCast(u32, mask_len),
21287 .child = .i32_type,
2125221288 });
2125321289 mask = try sema.coerce(block, mask_ty, mask, mask_src);
2125421290 const mask_val = try sema.resolveConstMaybeUndefVal(block, mask_src, mask, "shuffle mask must be comptime-known");
......@@ -21272,13 +21308,13 @@ fn analyzeShuffle(
2127221308 var a = a_arg;
2127321309 var b = b_arg;
2127421310
21275 const res_ty = try Type.Tag.vector.create(sema.arena, .{
21311 const res_ty = try mod.vectorType(.{
2127621312 .len = mask_len,
21277 .elem_type = elem_ty,
21313 .child = elem_ty.ip_index,
2127821314 });
2127921315
2128021316 var maybe_a_len = switch (sema.typeOf(a).zigTypeTag(mod)) {
21281 .Array, .Vector => sema.typeOf(a).arrayLen(),
21317 .Array, .Vector => sema.typeOf(a).arrayLen(mod),
2128221318 .Undefined => null,
2128321319 else => return sema.fail(block, a_src, "expected vector or array with element type '{}', found '{}'", .{
2128421320 elem_ty.fmt(sema.mod),
......@@ -21286,7 +21322,7 @@ fn analyzeShuffle(
2128621322 }),
2128721323 };
2128821324 var maybe_b_len = switch (sema.typeOf(b).zigTypeTag(mod)) {
21289 .Array, .Vector => sema.typeOf(b).arrayLen(),
21325 .Array, .Vector => sema.typeOf(b).arrayLen(mod),
2129021326 .Undefined => null,
2129121327 else => return sema.fail(block, b_src, "expected vector or array with element type '{}', found '{}'", .{
2129221328 elem_ty.fmt(sema.mod),
......@@ -21296,16 +21332,16 @@ fn analyzeShuffle(
2129621332 if (maybe_a_len == null and maybe_b_len == null) {
2129721333 return sema.addConstUndef(res_ty);
2129821334 }
21299 const a_len = maybe_a_len orelse maybe_b_len.?;
21300 const b_len = maybe_b_len orelse a_len;
21335 const a_len = @intCast(u32, maybe_a_len orelse maybe_b_len.?);
21336 const b_len = @intCast(u32, maybe_b_len orelse a_len);
2130121337
21302 const a_ty = try Type.Tag.vector.create(sema.arena, .{
21338 const a_ty = try mod.vectorType(.{
2130321339 .len = a_len,
21304 .elem_type = elem_ty,
21340 .child = elem_ty.ip_index,
2130521341 });
21306 const b_ty = try Type.Tag.vector.create(sema.arena, .{
21342 const b_ty = try mod.vectorType(.{
2130721343 .len = b_len,
21308 .elem_type = elem_ty,
21344 .child = elem_ty.ip_index,
2130921345 });
2131021346
2131121347 if (maybe_a_len == null) a = try sema.addConstUndef(a_ty) else a = try sema.coerce(block, a_ty, a, a_src);
......@@ -21437,15 +21473,21 @@ fn zirSelect(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) C
2143721473 const pred_ty = sema.typeOf(pred_uncoerced);
2143821474
2143921475 const vec_len_u64 = switch (try pred_ty.zigTypeTagOrPoison(mod)) {
21440 .Vector, .Array => pred_ty.arrayLen(),
21476 .Vector, .Array => pred_ty.arrayLen(mod),
2144121477 else => return sema.fail(block, pred_src, "expected vector or array, found '{}'", .{pred_ty.fmt(sema.mod)}),
2144221478 };
21443 const vec_len = try sema.usizeCast(block, pred_src, vec_len_u64);
21479 const vec_len = @intCast(u32, try sema.usizeCast(block, pred_src, vec_len_u64));
2144421480
21445 const bool_vec_ty = try Type.vector(sema.arena, vec_len, Type.bool);
21481 const bool_vec_ty = try mod.vectorType(.{
21482 .len = vec_len,
21483 .child = .bool_type,
21484 });
2144621485 const pred = try sema.coerce(block, bool_vec_ty, pred_uncoerced, pred_src);
2144721486
21448 const vec_ty = try Type.vector(sema.arena, vec_len, elem_ty);
21487 const vec_ty = try mod.vectorType(.{
21488 .len = vec_len,
21489 .child = elem_ty.ip_index,
21490 });
2144921491 const a = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.a), a_src);
2145021492 const b = try sema.coerce(block, vec_ty, try sema.resolveInst(extra.b), b_src);
2145121493
......@@ -21854,7 +21896,7 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
2185421896 }
2185521897
2185621898 try sema.checkPtrOperand(block, ptr_src, field_ptr_ty);
21857 const field_ptr_ty_info = field_ptr_ty.ptrInfo().data;
21899 const field_ptr_ty_info = field_ptr_ty.ptrInfo(mod);
2185821900
2185921901 var ptr_ty_data: Type.Payload.Pointer.Data = .{
2186021902 .pointee_type = parent_ty.structFieldType(field_index),
......@@ -22052,8 +22094,8 @@ fn analyzeMinMax(
2205222094 }
2205322095
2205422096 const refined_ty = if (orig_ty.zigTypeTag(mod) == .Vector) blk: {
22055 const elem_ty = orig_ty.childType();
22056 const len = orig_ty.vectorLen();
22097 const elem_ty = orig_ty.childType(mod);
22098 const len = orig_ty.vectorLen(mod);
2205722099
2205822100 if (len == 0) break :blk orig_ty;
2205922101 if (elem_ty.isAnyFloat()) break :blk orig_ty; // can't refine floats
......@@ -22068,7 +22110,10 @@ fn analyzeMinMax(
2206822110 }
2206922111
2207022112 const refined_elem_ty = try mod.intFittingRange(cur_min, cur_max);
22071 break :blk try Type.vector(sema.arena, len, refined_elem_ty);
22113 break :blk try mod.vectorType(.{
22114 .len = len,
22115 .child = refined_elem_ty.ip_index,
22116 });
2207222117 } else blk: {
2207322118 if (orig_ty.isAnyFloat()) break :blk orig_ty; // can't refine floats
2207422119 if (val.isUndef()) break :blk orig_ty; // can't refine undef
......@@ -22129,8 +22174,8 @@ fn analyzeMinMax(
2212922174 if (known_undef) break :refine; // can't refine undef
2213022175 const unrefined_ty = sema.typeOf(cur_minmax.?);
2213122176 const is_vector = unrefined_ty.zigTypeTag(mod) == .Vector;
22132 const comptime_elem_ty = if (is_vector) comptime_ty.childType() else comptime_ty;
22133 const unrefined_elem_ty = if (is_vector) unrefined_ty.childType() else unrefined_ty;
22177 const comptime_elem_ty = if (is_vector) comptime_ty.childType(mod) else comptime_ty;
22178 const unrefined_elem_ty = if (is_vector) unrefined_ty.childType(mod) else unrefined_ty;
2213422179
2213522180 if (unrefined_elem_ty.isAnyFloat()) break :refine; // we can't refine floats
2213622181
......@@ -22150,7 +22195,10 @@ fn analyzeMinMax(
2215022195 const final_elem_ty = try mod.intFittingRange(min_val, max_val);
2215122196
2215222197 const final_ty = if (is_vector)
22153 try Type.vector(sema.arena, unrefined_ty.vectorLen(), final_elem_ty)
22198 try mod.vectorType(.{
22199 .len = unrefined_ty.vectorLen(mod),
22200 .child = final_elem_ty.ip_index,
22201 })
2215422202 else
2215522203 final_elem_ty;
2215622204
......@@ -22165,7 +22213,7 @@ fn analyzeMinMax(
2216522213
2216622214fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !Air.Inst.Ref {
2216722215 const mod = sema.mod;
22168 const info = sema.typeOf(ptr).ptrInfo().data;
22216 const info = sema.typeOf(ptr).ptrInfo(mod);
2216922217 if (info.size == .One) {
2217022218 // Already an array pointer.
2217122219 return ptr;
......@@ -22659,7 +22707,7 @@ fn zirFuncFancy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!A
2265922707 const body = sema.code.extra[extra_index..][0..body_len];
2266022708 extra_index += body.len;
2266122709
22662 const ty = Type.initTag(.const_slice_u8);
22710 const ty = Type.const_slice_u8;
2266322711 const val = try sema.resolveGenericBody(block, section_src, body, inst, ty, "linksection must be comptime-known");
2266422712 if (val.isGenericPoison()) {
2266522713 break :blk FuncLinkSection{ .generic = {} };
......@@ -22943,7 +22991,7 @@ fn resolveExternOptions(
2294322991
2294422992 const name_ref = try sema.fieldVal(block, src, options, "name", name_src);
2294522993 const name_val = try sema.resolveConstValue(block, name_src, name_ref, "name of the extern symbol must be comptime-known");
22946 const name = try name_val.toAllocatedBytes(Type.initTag(.const_slice_u8), sema.arena, mod);
22994 const name = try name_val.toAllocatedBytes(Type.const_slice_u8, sema.arena, mod);
2294722995
2294822996 const library_name_inst = try sema.fieldVal(block, src, options, "library_name", library_src);
2294922997 const library_name_val = try sema.resolveConstValue(block, library_src, library_name_inst, "library in which extern symbol is must be comptime-known");
......@@ -22957,7 +23005,7 @@ fn resolveExternOptions(
2295723005
2295823006 const library_name = if (!library_name_val.isNull(mod)) blk: {
2295923007 const payload = library_name_val.castTag(.opt_payload).?.data;
22960 const library_name = try payload.toAllocatedBytes(Type.initTag(.const_slice_u8), sema.arena, mod);
23008 const library_name = try payload.toAllocatedBytes(Type.const_slice_u8, sema.arena, mod);
2296123009 if (library_name.len == 0) {
2296223010 return sema.fail(block, library_src, "library name cannot be empty", .{});
2296323011 }
......@@ -22994,7 +23042,7 @@ fn zirBuiltinExtern(
2299423042 if (!ty.isPtrAtRuntime(mod)) {
2299523043 return sema.fail(block, ty_src, "expected (optional) pointer", .{});
2299623044 }
22997 if (!try sema.validateExternType(ty.childType(), .other)) {
23045 if (!try sema.validateExternType(ty.childType(mod), .other)) {
2299823046 const msg = msg: {
2299923047 const msg = try sema.errMsg(block, ty_src, "extern symbol cannot have type '{}'", .{ty.fmt(mod)});
2300023048 errdefer msg.destroy(sema.gpa);
......@@ -23014,7 +23062,7 @@ fn zirBuiltinExtern(
2301423062 };
2301523063
2301623064 if (options.linkage == .Weak and !ty.ptrAllowsZero(mod)) {
23017 ty = try Type.optional(sema.arena, ty);
23065 ty = try Type.optional(sema.arena, ty, mod);
2301823066 }
2301923067
2302023068 // TODO check duplicate extern
......@@ -23194,7 +23242,7 @@ fn validateRunTimeType(
2319423242 => return false,
2319523243
2319623244 .Pointer => {
23197 const elem_ty = ty.childType();
23245 const elem_ty = ty.childType(mod);
2319823246 switch (elem_ty.zigTypeTag(mod)) {
2319923247 .Opaque => return true,
2320023248 .Fn => return elem_ty.isFnOrHasRuntimeBits(mod),
......@@ -23204,11 +23252,10 @@ fn validateRunTimeType(
2320423252 .Opaque => return is_extern,
2320523253
2320623254 .Optional => {
23207 var buf: Type.Payload.ElemType = undefined;
23208 const child_ty = ty.optionalChild(&buf);
23255 const child_ty = ty.optionalChild(mod);
2320923256 return sema.validateRunTimeType(child_ty, is_extern);
2321023257 },
23211 .Array, .Vector => ty = ty.elemType(),
23258 .Array, .Vector => ty = ty.childType(mod),
2321223259
2321323260 .ErrorUnion => ty = ty.errorUnionPayload(),
2321423261
......@@ -23277,7 +23324,7 @@ fn explainWhyTypeIsComptimeInner(
2327723324 },
2327823325
2327923326 .Array, .Vector => {
23280 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.elemType(), type_set);
23327 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.childType(mod), type_set);
2328123328 },
2328223329 .Pointer => {
2328323330 const elem_ty = ty.elemType2(mod);
......@@ -23295,12 +23342,11 @@ fn explainWhyTypeIsComptimeInner(
2329523342 }
2329623343 return;
2329723344 }
23298 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.elemType(), type_set);
23345 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.childType(mod), type_set);
2329923346 },
2330023347
2330123348 .Optional => {
23302 var buf: Type.Payload.ElemType = undefined;
23303 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.optionalChild(&buf), type_set);
23349 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.optionalChild(mod), type_set);
2330423350 },
2330523351 .ErrorUnion => {
2330623352 try sema.explainWhyTypeIsComptimeInner(msg, src_loc, ty.errorUnionPayload(), type_set);
......@@ -23451,7 +23497,7 @@ fn explainWhyTypeIsNotExtern(
2345123497 if (ty.isSlice(mod)) {
2345223498 try mod.errNoteNonLazy(src_loc, msg, "slices have no guaranteed in-memory representation", .{});
2345323499 } else {
23454 const pointee_ty = ty.childType();
23500 const pointee_ty = ty.childType(mod);
2345523501 try mod.errNoteNonLazy(src_loc, msg, "pointer to comptime-only type '{}'", .{pointee_ty.fmt(sema.mod)});
2345623502 try sema.explainWhyTypeIsComptime(msg, src_loc, pointee_ty);
2345723503 }
......@@ -23698,7 +23744,7 @@ fn panicWithMsg(
2369823744 .@"addrspace" = target_util.defaultAddressSpace(target, .global_constant), // TODO might need a place that is more dynamic
2369923745 });
2370023746 const null_stack_trace = try sema.addConstant(
23701 try Type.optional(arena, ptr_stack_trace_ty),
23747 try Type.optional(arena, ptr_stack_trace_ty, mod),
2370223748 Value.null,
2370323749 );
2370423750 const args: [3]Air.Inst.Ref = .{ msg_inst, null_stack_trace, .null_value };
......@@ -23927,7 +23973,7 @@ fn fieldVal(
2392723973 const is_pointer_to = object_ty.isSinglePointer(mod);
2392823974
2392923975 const inner_ty = if (is_pointer_to)
23930 object_ty.childType()
23976 object_ty.childType(mod)
2393123977 else
2393223978 object_ty;
2393323979
......@@ -23936,12 +23982,12 @@ fn fieldVal(
2393623982 if (mem.eql(u8, field_name, "len")) {
2393723983 return sema.addConstant(
2393823984 Type.usize,
23939 try Value.Tag.int_u64.create(arena, inner_ty.arrayLen()),
23985 try Value.Tag.int_u64.create(arena, inner_ty.arrayLen(mod)),
2394023986 );
2394123987 } else if (mem.eql(u8, field_name, "ptr") and is_pointer_to) {
23942 const ptr_info = object_ty.ptrInfo().data;
23988 const ptr_info = object_ty.ptrInfo(mod);
2394323989 const result_ty = try Type.ptr(sema.arena, sema.mod, .{
23944 .pointee_type = ptr_info.pointee_type.childType(),
23990 .pointee_type = ptr_info.pointee_type.childType(mod),
2394523991 .sentinel = ptr_info.sentinel,
2394623992 .@"align" = ptr_info.@"align",
2394723993 .@"addrspace" = ptr_info.@"addrspace",
......@@ -23964,7 +24010,7 @@ fn fieldVal(
2396424010 }
2396524011 },
2396624012 .Pointer => {
23967 const ptr_info = inner_ty.ptrInfo().data;
24013 const ptr_info = inner_ty.ptrInfo(mod);
2396824014 if (ptr_info.size == .Slice) {
2396924015 if (mem.eql(u8, field_name, "ptr")) {
2397024016 const slice = if (is_pointer_to)
......@@ -24107,7 +24153,7 @@ fn fieldPtr(
2410724153 const object_ptr_src = src; // TODO better source location
2410824154 const object_ptr_ty = sema.typeOf(object_ptr);
2410924155 const object_ty = switch (object_ptr_ty.zigTypeTag(mod)) {
24110 .Pointer => object_ptr_ty.elemType(),
24156 .Pointer => object_ptr_ty.childType(mod),
2411124157 else => return sema.fail(block, object_ptr_src, "expected pointer, found '{}'", .{object_ptr_ty.fmt(sema.mod)}),
2411224158 };
2411324159
......@@ -24117,7 +24163,7 @@ fn fieldPtr(
2411724163 const is_pointer_to = object_ty.isSinglePointer(mod);
2411824164
2411924165 const inner_ty = if (is_pointer_to)
24120 object_ty.childType()
24166 object_ty.childType(mod)
2412124167 else
2412224168 object_ty;
2412324169
......@@ -24128,7 +24174,7 @@ fn fieldPtr(
2412824174 defer anon_decl.deinit();
2412924175 return sema.analyzeDeclRef(try anon_decl.finish(
2413024176 Type.usize,
24131 try Value.Tag.int_u64.create(anon_decl.arena(), inner_ty.arrayLen()),
24177 try Value.Tag.int_u64.create(anon_decl.arena(), inner_ty.arrayLen(mod)),
2413224178 0, // default alignment
2413324179 ));
2413424180 } else {
......@@ -24154,9 +24200,9 @@ fn fieldPtr(
2415424200
2415524201 const result_ty = try Type.ptr(sema.arena, sema.mod, .{
2415624202 .pointee_type = slice_ptr_ty,
24157 .mutable = attr_ptr_ty.ptrIsMutable(),
24203 .mutable = attr_ptr_ty.ptrIsMutable(mod),
2415824204 .@"volatile" = attr_ptr_ty.isVolatilePtr(),
24159 .@"addrspace" = attr_ptr_ty.ptrAddressSpace(),
24205 .@"addrspace" = attr_ptr_ty.ptrAddressSpace(mod),
2416024206 });
2416124207
2416224208 if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| {
......@@ -24175,9 +24221,9 @@ fn fieldPtr(
2417524221 } else if (mem.eql(u8, field_name, "len")) {
2417624222 const result_ty = try Type.ptr(sema.arena, sema.mod, .{
2417724223 .pointee_type = Type.usize,
24178 .mutable = attr_ptr_ty.ptrIsMutable(),
24224 .mutable = attr_ptr_ty.ptrIsMutable(mod),
2417924225 .@"volatile" = attr_ptr_ty.isVolatilePtr(),
24180 .@"addrspace" = attr_ptr_ty.ptrAddressSpace(),
24226 .@"addrspace" = attr_ptr_ty.ptrAddressSpace(mod),
2418124227 });
2418224228
2418324229 if (try sema.resolveDefinedValue(block, object_ptr_src, inner_ptr)) |val| {
......@@ -24329,14 +24375,14 @@ fn fieldCallBind(
2432924375 const mod = sema.mod;
2433024376 const raw_ptr_src = src; // TODO better source location
2433124377 const raw_ptr_ty = sema.typeOf(raw_ptr);
24332 const inner_ty = if (raw_ptr_ty.zigTypeTag(mod) == .Pointer and (raw_ptr_ty.ptrSize() == .One or raw_ptr_ty.ptrSize() == .C))
24333 raw_ptr_ty.childType()
24378 const inner_ty = if (raw_ptr_ty.zigTypeTag(mod) == .Pointer and (raw_ptr_ty.ptrSize(mod) == .One or raw_ptr_ty.ptrSize(mod) == .C))
24379 raw_ptr_ty.childType(mod)
2433424380 else
2433524381 return sema.fail(block, raw_ptr_src, "expected single pointer, found '{}'", .{raw_ptr_ty.fmt(sema.mod)});
2433624382
2433724383 // Optionally dereference a second pointer to get the concrete type.
24338 const is_double_ptr = inner_ty.zigTypeTag(mod) == .Pointer and inner_ty.ptrSize() == .One;
24339 const concrete_ty = if (is_double_ptr) inner_ty.childType() else inner_ty;
24384 const is_double_ptr = inner_ty.zigTypeTag(mod) == .Pointer and inner_ty.ptrSize(mod) == .One;
24385 const concrete_ty = if (is_double_ptr) inner_ty.childType(mod) else inner_ty;
2434024386 const ptr_ty = if (is_double_ptr) inner_ty else raw_ptr_ty;
2434124387 const object_ptr = if (is_double_ptr)
2434224388 try sema.analyzeLoad(block, src, raw_ptr, src)
......@@ -24404,9 +24450,9 @@ fn fieldCallBind(
2440424450 // zig fmt: off
2440524451 if (first_param_type.isGenericPoison() or (
2440624452 first_param_type.zigTypeTag(mod) == .Pointer and
24407 (first_param_type.ptrSize() == .One or
24408 first_param_type.ptrSize() == .C) and
24409 first_param_type.childType().eql(concrete_ty, sema.mod)))
24453 (first_param_type.ptrSize(mod) == .One or
24454 first_param_type.ptrSize(mod) == .C) and
24455 first_param_type.childType(mod).eql(concrete_ty, sema.mod)))
2441024456 {
2441124457 // zig fmt: on
2441224458 // Note that if the param type is generic poison, we know that it must
......@@ -24425,8 +24471,7 @@ fn fieldCallBind(
2442524471 .arg0_inst = deref,
2442624472 } };
2442724473 } else if (first_param_type.zigTypeTag(mod) == .Optional) {
24428 var opt_buf: Type.Payload.ElemType = undefined;
24429 const child = first_param_type.optionalChild(&opt_buf);
24474 const child = first_param_type.optionalChild(mod);
2443024475 if (child.eql(concrete_ty, sema.mod)) {
2443124476 const deref = try sema.analyzeLoad(block, src, object_ptr, src);
2443224477 return .{ .method = .{
......@@ -24434,8 +24479,8 @@ fn fieldCallBind(
2443424479 .arg0_inst = deref,
2443524480 } };
2443624481 } else if (child.zigTypeTag(mod) == .Pointer and
24437 child.ptrSize() == .One and
24438 child.childType().eql(concrete_ty, sema.mod))
24482 child.ptrSize(mod) == .One and
24483 child.childType(mod).eql(concrete_ty, sema.mod))
2443924484 {
2444024485 return .{ .method = .{
2444124486 .func_inst = decl_val,
......@@ -24482,15 +24527,15 @@ fn finishFieldCallBind(
2448224527 field_index: u32,
2448324528 object_ptr: Air.Inst.Ref,
2448424529) CompileError!ResolvedFieldCallee {
24530 const mod = sema.mod;
2448524531 const arena = sema.arena;
2448624532 const ptr_field_ty = try Type.ptr(arena, sema.mod, .{
2448724533 .pointee_type = field_ty,
24488 .mutable = ptr_ty.ptrIsMutable(),
24489 .@"addrspace" = ptr_ty.ptrAddressSpace(),
24534 .mutable = ptr_ty.ptrIsMutable(mod),
24535 .@"addrspace" = ptr_ty.ptrAddressSpace(mod),
2449024536 });
2449124537
24492 const mod = sema.mod;
24493 const container_ty = ptr_ty.childType();
24538 const container_ty = ptr_ty.childType(mod);
2449424539 if (container_ty.zigTypeTag(mod) == .Struct) {
2449524540 if (container_ty.structFieldValueComptime(mod, field_index)) |default_val| {
2449624541 return .{ .direct = try sema.addConstant(field_ty, default_val) };
......@@ -24618,7 +24663,7 @@ fn structFieldPtrByIndex(
2461824663 const struct_obj = struct_ty.castTag(.@"struct").?.data;
2461924664 const field = struct_obj.fields.values()[field_index];
2462024665 const struct_ptr_ty = sema.typeOf(struct_ptr);
24621 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo().data;
24666 const struct_ptr_ty_info = struct_ptr_ty.ptrInfo(mod);
2462224667
2462324668 var ptr_ty_data: Type.Payload.Pointer.Data = .{
2462424669 .pointee_type = field.ty,
......@@ -24696,7 +24741,7 @@ fn structFieldPtrByIndex(
2469624741 ptr_field_ty,
2469724742 try Value.Tag.field_ptr.create(sema.arena, .{
2469824743 .container_ptr = struct_ptr_val,
24699 .container_ty = struct_ptr_ty.childType(),
24744 .container_ty = struct_ptr_ty.childType(mod),
2470024745 .field_index = field_index,
2470124746 }),
2470224747 );
......@@ -24846,9 +24891,9 @@ fn unionFieldPtr(
2484624891 const field = union_obj.fields.values()[field_index];
2484724892 const ptr_field_ty = try Type.ptr(arena, sema.mod, .{
2484824893 .pointee_type = field.ty,
24849 .mutable = union_ptr_ty.ptrIsMutable(),
24894 .mutable = union_ptr_ty.ptrIsMutable(mod),
2485024895 .@"volatile" = union_ptr_ty.isVolatilePtr(),
24851 .@"addrspace" = union_ptr_ty.ptrAddressSpace(),
24896 .@"addrspace" = union_ptr_ty.ptrAddressSpace(mod),
2485224897 });
2485324898 const enum_field_index = @intCast(u32, union_obj.tag_ty.enumFieldIndex(field_name).?);
2485424899
......@@ -25009,7 +25054,7 @@ fn elemPtr(
2500925054 const indexable_ptr_ty = sema.typeOf(indexable_ptr);
2501025055
2501125056 const indexable_ty = switch (indexable_ptr_ty.zigTypeTag(mod)) {
25012 .Pointer => indexable_ptr_ty.elemType(),
25057 .Pointer => indexable_ptr_ty.childType(mod),
2501325058 else => return sema.fail(block, indexable_ptr_src, "expected pointer, found '{}'", .{indexable_ptr_ty.fmt(sema.mod)}),
2501425059 };
2501525060 try checkIndexable(sema, block, src, indexable_ty);
......@@ -25046,7 +25091,7 @@ fn elemPtrOneLayerOnly(
2504625091
2504725092 try checkIndexable(sema, block, src, indexable_ty);
2504825093
25049 switch (indexable_ty.ptrSize()) {
25094 switch (indexable_ty.ptrSize(mod)) {
2505025095 .Slice => return sema.elemPtrSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety),
2505125096 .Many, .C => {
2505225097 const maybe_ptr_val = try sema.resolveDefinedValue(block, indexable_src, indexable);
......@@ -25065,7 +25110,7 @@ fn elemPtrOneLayerOnly(
2506525110 return block.addPtrElemPtr(indexable, elem_index, result_ty);
2506625111 },
2506725112 .One => {
25068 assert(indexable_ty.childType().zigTypeTag(mod) == .Array); // Guaranteed by checkIndexable
25113 assert(indexable_ty.childType(mod).zigTypeTag(mod) == .Array); // Guaranteed by checkIndexable
2506925114 return sema.elemPtrArray(block, src, indexable_src, indexable, elem_index_src, elem_index, init, oob_safety);
2507025115 },
2507125116 }
......@@ -25091,7 +25136,7 @@ fn elemVal(
2509125136 const elem_index = try sema.coerce(block, Type.usize, elem_index_uncasted, elem_index_src);
2509225137
2509325138 switch (indexable_ty.zigTypeTag(mod)) {
25094 .Pointer => switch (indexable_ty.ptrSize()) {
25139 .Pointer => switch (indexable_ty.ptrSize(mod)) {
2509525140 .Slice => return sema.elemValSlice(block, src, indexable_src, indexable, elem_index_src, elem_index, oob_safety),
2509625141 .Many, .C => {
2509725142 const maybe_indexable_val = try sema.resolveDefinedValue(block, indexable_src, indexable);
......@@ -25112,7 +25157,7 @@ fn elemVal(
2511225157 return block.addBinOp(.ptr_elem_val, indexable, elem_index);
2511325158 },
2511425159 .One => {
25115 assert(indexable_ty.childType().zigTypeTag(mod) == .Array); // Guaranteed by checkIndexable
25160 assert(indexable_ty.childType(mod).zigTypeTag(mod) == .Array); // Guaranteed by checkIndexable
2511625161 const elem_ptr = try sema.elemPtr(block, indexable_src, indexable, elem_index, elem_index_src, false, oob_safety);
2511725162 return sema.analyzeLoad(block, indexable_src, elem_ptr, elem_index_src);
2511825163 },
......@@ -25171,7 +25216,7 @@ fn tupleFieldPtr(
2517125216) CompileError!Air.Inst.Ref {
2517225217 const mod = sema.mod;
2517325218 const tuple_ptr_ty = sema.typeOf(tuple_ptr);
25174 const tuple_ty = tuple_ptr_ty.childType();
25219 const tuple_ty = tuple_ptr_ty.childType(mod);
2517525220 _ = try sema.resolveTypeFields(tuple_ty);
2517625221 const field_count = tuple_ty.structFieldCount();
2517725222
......@@ -25188,9 +25233,9 @@ fn tupleFieldPtr(
2518825233 const field_ty = tuple_ty.structFieldType(field_index);
2518925234 const ptr_field_ty = try Type.ptr(sema.arena, sema.mod, .{
2519025235 .pointee_type = field_ty,
25191 .mutable = tuple_ptr_ty.ptrIsMutable(),
25236 .mutable = tuple_ptr_ty.ptrIsMutable(mod),
2519225237 .@"volatile" = tuple_ptr_ty.isVolatilePtr(),
25193 .@"addrspace" = tuple_ptr_ty.ptrAddressSpace(),
25238 .@"addrspace" = tuple_ptr_ty.ptrAddressSpace(mod),
2519425239 });
2519525240
2519625241 if (tuple_ty.structFieldValueComptime(mod, field_index)) |default_val| {
......@@ -25271,10 +25316,10 @@ fn elemValArray(
2527125316) CompileError!Air.Inst.Ref {
2527225317 const mod = sema.mod;
2527325318 const array_ty = sema.typeOf(array);
25274 const array_sent = array_ty.sentinel();
25275 const array_len = array_ty.arrayLen();
25319 const array_sent = array_ty.sentinel(mod);
25320 const array_len = array_ty.arrayLen(mod);
2527625321 const array_len_s = array_len + @boolToInt(array_sent != null);
25277 const elem_ty = array_ty.childType();
25322 const elem_ty = array_ty.childType(mod);
2527825323
2527925324 if (array_len_s == 0) {
2528025325 return sema.fail(block, array_src, "indexing into empty array is not allowed", .{});
......@@ -25335,9 +25380,9 @@ fn elemPtrArray(
2533525380) CompileError!Air.Inst.Ref {
2533625381 const mod = sema.mod;
2533725382 const array_ptr_ty = sema.typeOf(array_ptr);
25338 const array_ty = array_ptr_ty.childType();
25339 const array_sent = array_ty.sentinel() != null;
25340 const array_len = array_ty.arrayLen();
25383 const array_ty = array_ptr_ty.childType(mod);
25384 const array_sent = array_ty.sentinel(mod) != null;
25385 const array_len = array_ty.arrayLen(mod);
2534125386 const array_len_s = array_len + @boolToInt(array_sent);
2534225387
2534325388 if (array_len_s == 0) {
......@@ -25396,7 +25441,7 @@ fn elemValSlice(
2539625441) CompileError!Air.Inst.Ref {
2539725442 const mod = sema.mod;
2539825443 const slice_ty = sema.typeOf(slice);
25399 const slice_sent = slice_ty.sentinel() != null;
25444 const slice_sent = slice_ty.sentinel(mod) != null;
2540025445 const elem_ty = slice_ty.elemType2(mod);
2540125446 var runtime_src = slice_src;
2540225447
......@@ -25453,7 +25498,7 @@ fn elemPtrSlice(
2545325498) CompileError!Air.Inst.Ref {
2545425499 const mod = sema.mod;
2545525500 const slice_ty = sema.typeOf(slice);
25456 const slice_sent = slice_ty.sentinel() != null;
25501 const slice_sent = slice_ty.sentinel(mod) != null;
2545725502
2545825503 const maybe_undef_slice_val = try sema.resolveMaybeUndefVal(slice);
2545925504 // The index must not be undefined since it can be out of bounds.
......@@ -25614,7 +25659,7 @@ fn coerceExtra(
2561425659 }
2561525660
2561625661 // T to ?T
25617 const child_type = try dest_ty.optionalChildAlloc(sema.arena);
25662 const child_type = dest_ty.optionalChild(mod);
2561825663 const intermediate = sema.coerceExtra(block, child_type, inst, inst_src, .{ .report_err = false }) catch |err| switch (err) {
2561925664 error.NotCoercible => {
2562025665 if (in_memory_result == .no_match) {
......@@ -25628,7 +25673,7 @@ fn coerceExtra(
2562825673 return try sema.wrapOptional(block, dest_ty, intermediate, inst_src);
2562925674 },
2563025675 .Pointer => pointer: {
25631 const dest_info = dest_ty.ptrInfo().data;
25676 const dest_info = dest_ty.ptrInfo(mod);
2563225677
2563325678 // Function body to function pointer.
2563425679 if (inst_ty.zigTypeTag(mod) == .Fn) {
......@@ -25643,11 +25688,11 @@ fn coerceExtra(
2564325688 if (dest_info.size != .One) break :single_item;
2564425689 if (!inst_ty.isSinglePointer(mod)) break :single_item;
2564525690 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer;
25646 const ptr_elem_ty = inst_ty.childType();
25691 const ptr_elem_ty = inst_ty.childType(mod);
2564725692 const array_ty = dest_info.pointee_type;
2564825693 if (array_ty.zigTypeTag(mod) != .Array) break :single_item;
25649 const array_elem_ty = array_ty.childType();
25650 if (array_ty.arrayLen() != 1) break :single_item;
25694 const array_elem_ty = array_ty.childType(mod);
25695 if (array_ty.arrayLen(mod) != 1) break :single_item;
2565125696 const dest_is_mut = dest_info.mutable;
2565225697 switch (try sema.coerceInMemoryAllowed(block, array_elem_ty, ptr_elem_ty, dest_is_mut, target, dest_ty_src, inst_src)) {
2565325698 .ok => {},
......@@ -25660,9 +25705,9 @@ fn coerceExtra(
2566025705 src_array_ptr: {
2566125706 if (!inst_ty.isSinglePointer(mod)) break :src_array_ptr;
2566225707 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :pointer;
25663 const array_ty = inst_ty.childType();
25708 const array_ty = inst_ty.childType(mod);
2566425709 if (array_ty.zigTypeTag(mod) != .Array) break :src_array_ptr;
25665 const array_elem_type = array_ty.childType();
25710 const array_elem_type = array_ty.childType(mod);
2566625711 const dest_is_mut = dest_info.mutable;
2566725712
2566825713 const dst_elem_type = dest_info.pointee_type;
......@@ -25680,7 +25725,7 @@ fn coerceExtra(
2568025725 }
2568125726
2568225727 if (dest_info.sentinel) |dest_sent| {
25683 if (array_ty.sentinel()) |inst_sent| {
25728 if (array_ty.sentinel(mod)) |inst_sent| {
2568425729 if (!dest_sent.eql(inst_sent, dst_elem_type, sema.mod)) {
2568525730 in_memory_result = .{ .ptr_sentinel = .{
2568625731 .actual = inst_sent,
......@@ -25721,7 +25766,7 @@ fn coerceExtra(
2572125766 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :src_c_ptr;
2572225767 // In this case we must add a safety check because the C pointer
2572325768 // could be null.
25724 const src_elem_ty = inst_ty.childType();
25769 const src_elem_ty = inst_ty.childType(mod);
2572525770 const dest_is_mut = dest_info.mutable;
2572625771 const dst_elem_type = dest_info.pointee_type;
2572725772 switch (try sema.coerceInMemoryAllowed(block, dst_elem_type, src_elem_ty, dest_is_mut, target, dest_ty_src, inst_src)) {
......@@ -25784,7 +25829,7 @@ fn coerceExtra(
2578425829 },
2578525830 .Pointer => p: {
2578625831 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :p;
25787 const inst_info = inst_ty.ptrInfo().data;
25832 const inst_info = inst_ty.ptrInfo(mod);
2578825833 switch (try sema.coerceInMemoryAllowed(
2578925834 block,
2579025835 dest_info.pointee_type,
......@@ -25814,7 +25859,7 @@ fn coerceExtra(
2581425859 .Union => {
2581525860 // pointer to anonymous struct to pointer to union
2581625861 if (inst_ty.isSinglePointer(mod) and
25817 inst_ty.childType().isAnonStruct() and
25862 inst_ty.childType(mod).isAnonStruct() and
2581825863 sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result))
2581925864 {
2582025865 return sema.coerceAnonStructToUnionPtrs(block, dest_ty, dest_ty_src, inst, inst_src);
......@@ -25823,7 +25868,7 @@ fn coerceExtra(
2582325868 .Struct => {
2582425869 // pointer to anonymous struct to pointer to struct
2582525870 if (inst_ty.isSinglePointer(mod) and
25826 inst_ty.childType().isAnonStruct() and
25871 inst_ty.childType(mod).isAnonStruct() and
2582725872 sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result))
2582825873 {
2582925874 return sema.coerceAnonStructToStructPtrs(block, dest_ty, dest_ty_src, inst, inst_src) catch |err| switch (err) {
......@@ -25835,7 +25880,7 @@ fn coerceExtra(
2583525880 .Array => {
2583625881 // pointer to tuple to pointer to array
2583725882 if (inst_ty.isSinglePointer(mod) and
25838 inst_ty.childType().isTuple() and
25883 inst_ty.childType(mod).isTuple() and
2583925884 sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result))
2584025885 {
2584125886 return sema.coerceTupleToArrayPtrs(block, dest_ty, dest_ty_src, inst, inst_src);
......@@ -25854,7 +25899,7 @@ fn coerceExtra(
2585425899 }
2585525900
2585625901 if (!inst_ty.isSinglePointer(mod)) break :to_slice;
25857 const inst_child_ty = inst_ty.childType();
25902 const inst_child_ty = inst_ty.childType(mod);
2585825903 if (!inst_child_ty.isTuple()) break :to_slice;
2585925904
2586025905 // empty tuple to zero-length slice
......@@ -25887,7 +25932,7 @@ fn coerceExtra(
2588725932 .Many => p: {
2588825933 if (!inst_ty.isSlice(mod)) break :p;
2588925934 if (!sema.checkPtrAttributes(dest_ty, inst_ty, &in_memory_result)) break :p;
25890 const inst_info = inst_ty.ptrInfo().data;
25935 const inst_info = inst_ty.ptrInfo(mod);
2589125936
2589225937 switch (try sema.coerceInMemoryAllowed(
2589325938 block,
......@@ -26196,9 +26241,8 @@ fn coerceExtra(
2619626241 }
2619726242
2619826243 // ?T to T
26199 var buf: Type.Payload.ElemType = undefined;
2620026244 if (inst_ty.zigTypeTag(mod) == .Optional and
26201 (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(&buf), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)
26245 (try sema.coerceInMemoryAllowed(block, inst_ty.optionalChild(mod), dest_ty, false, target, dest_ty_src, inst_src)) == .ok)
2620226246 {
2620326247 try sema.errNote(block, inst_src, msg, "cannot convert optional to payload type", .{});
2620426248 try sema.errNote(block, inst_src, msg, "consider using '.?', 'orelse', or 'if'", .{});
......@@ -26399,10 +26443,8 @@ const InMemoryCoercionResult = union(enum) {
2639926443 cur = pair.child;
2640026444 },
2640126445 .optional_shape => |pair| {
26402 var buf_actual: Type.Payload.ElemType = undefined;
26403 var buf_wanted: Type.Payload.ElemType = undefined;
2640426446 try sema.errNote(block, src, msg, "optional type child '{}' cannot cast into optional type child '{}'", .{
26405 pair.actual.optionalChild(&buf_actual).fmt(sema.mod), pair.wanted.optionalChild(&buf_wanted).fmt(sema.mod),
26447 pair.actual.optionalChild(mod).fmt(sema.mod), pair.wanted.optionalChild(mod).fmt(sema.mod),
2640626448 });
2640726449 break;
2640826450 },
......@@ -26640,10 +26682,8 @@ fn coerceInMemoryAllowed(
2664026682 }
2664126683
2664226684 // Pointers / Pointer-like Optionals
26643 var dest_buf: Type.Payload.ElemType = undefined;
26644 var src_buf: Type.Payload.ElemType = undefined;
26645 const maybe_dest_ptr_ty = try sema.typePtrOrOptionalPtrTy(dest_ty, &dest_buf);
26646 const maybe_src_ptr_ty = try sema.typePtrOrOptionalPtrTy(src_ty, &src_buf);
26685 const maybe_dest_ptr_ty = try sema.typePtrOrOptionalPtrTy(dest_ty);
26686 const maybe_src_ptr_ty = try sema.typePtrOrOptionalPtrTy(src_ty);
2664726687 if (maybe_dest_ptr_ty) |dest_ptr_ty| {
2664826688 if (maybe_src_ptr_ty) |src_ptr_ty| {
2664926689 return try sema.coerceInMemoryAllowedPtrs(block, dest_ty, src_ty, dest_ptr_ty, src_ptr_ty, dest_is_mut, target, dest_src, src_src);
......@@ -26685,8 +26725,8 @@ fn coerceInMemoryAllowed(
2668526725
2668626726 // Arrays
2668726727 if (dest_tag == .Array and src_tag == .Array) {
26688 const dest_info = dest_ty.arrayInfo();
26689 const src_info = src_ty.arrayInfo();
26728 const dest_info = dest_ty.arrayInfo(mod);
26729 const src_info = src_ty.arrayInfo(mod);
2669026730 if (dest_info.len != src_info.len) {
2669126731 return InMemoryCoercionResult{ .array_len = .{
2669226732 .actual = src_info.len,
......@@ -26717,8 +26757,8 @@ fn coerceInMemoryAllowed(
2671726757
2671826758 // Vectors
2671926759 if (dest_tag == .Vector and src_tag == .Vector) {
26720 const dest_len = dest_ty.vectorLen();
26721 const src_len = src_ty.vectorLen();
26760 const dest_len = dest_ty.vectorLen(mod);
26761 const src_len = src_ty.vectorLen(mod);
2672226762 if (dest_len != src_len) {
2672326763 return InMemoryCoercionResult{ .vector_len = .{
2672426764 .actual = src_len,
......@@ -26748,8 +26788,8 @@ fn coerceInMemoryAllowed(
2674826788 .wanted = dest_ty,
2674926789 } };
2675026790 }
26751 const dest_child_type = dest_ty.optionalChild(&dest_buf);
26752 const src_child_type = src_ty.optionalChild(&src_buf);
26791 const dest_child_type = dest_ty.optionalChild(mod);
26792 const src_child_type = src_ty.optionalChild(mod);
2675326793
2675426794 const child = try sema.coerceInMemoryAllowed(block, dest_child_type, src_child_type, dest_is_mut, target, dest_src, src_src);
2675526795 if (child != .ok) {
......@@ -27019,8 +27059,8 @@ fn coerceInMemoryAllowedPtrs(
2701927059 src_src: LazySrcLoc,
2702027060) !InMemoryCoercionResult {
2702127061 const mod = sema.mod;
27022 const dest_info = dest_ptr_ty.ptrInfo().data;
27023 const src_info = src_ptr_ty.ptrInfo().data;
27062 const dest_info = dest_ptr_ty.ptrInfo(mod);
27063 const src_info = src_ptr_ty.ptrInfo(mod);
2702427064
2702527065 const ok_ptr_size = src_info.size == dest_info.size or
2702627066 src_info.size == .C or dest_info.size == .C;
......@@ -27206,11 +27246,12 @@ fn storePtr2(
2720627246 operand_src: LazySrcLoc,
2720727247 air_tag: Air.Inst.Tag,
2720827248) CompileError!void {
27249 const mod = sema.mod;
2720927250 const ptr_ty = sema.typeOf(ptr);
2721027251 if (ptr_ty.isConstPtr())
2721127252 return sema.fail(block, ptr_src, "cannot assign to constant", .{});
2721227253
27213 const elem_ty = ptr_ty.childType();
27254 const elem_ty = ptr_ty.childType(mod);
2721427255
2721527256 // To generate better code for tuples, we detect a tuple operand here, and
2721627257 // analyze field loads and stores directly. This avoids an extra allocation + memcpy
......@@ -27221,7 +27262,6 @@ fn storePtr2(
2722127262 // this code does not handle tuple-to-struct coercion which requires dealing with missing
2722227263 // fields.
2722327264 const operand_ty = sema.typeOf(uncasted_operand);
27224 const mod = sema.mod;
2722527265 if (operand_ty.isTuple() and elem_ty.zigTypeTag(mod) == .Array) {
2722627266 const field_count = operand_ty.structFieldCount();
2722727267 var i: u32 = 0;
......@@ -27247,7 +27287,7 @@ fn storePtr2(
2724727287 // as well as working around an LLVM bug:
2724827288 // https://github.com/ziglang/zig/issues/11154
2724927289 if (sema.obtainBitCastedVectorPtr(ptr)) |vector_ptr| {
27250 const vector_ty = sema.typeOf(vector_ptr).childType();
27290 const vector_ty = sema.typeOf(vector_ptr).childType(mod);
2725127291 const vector = sema.coerceExtra(block, vector_ty, uncasted_operand, operand_src, .{ .is_ret = is_ret }) catch |err| switch (err) {
2725227292 error.NotCoercible => unreachable,
2725327293 else => |e| return e,
......@@ -27288,7 +27328,7 @@ fn storePtr2(
2728827328 try sema.requireRuntimeBlock(block, src, runtime_src);
2728927329 try sema.queueFullTypeResolution(elem_ty);
2729027330
27291 if (ptr_ty.ptrInfo().data.vector_index == .runtime) {
27331 if (ptr_ty.ptrInfo(mod).vector_index == .runtime) {
2729227332 const ptr_inst = Air.refToIndex(ptr).?;
2729327333 const air_tags = sema.air_instructions.items(.tag);
2729427334 if (air_tags[ptr_inst] == .ptr_elem_ptr) {
......@@ -27322,8 +27362,8 @@ fn storePtr2(
2732227362/// pointer. Only if the final element type matches the vector element type, and the
2732327363/// lengths match.
2732427364fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
27325 const array_ty = sema.typeOf(ptr).childType();
2732627365 const mod = sema.mod;
27366 const array_ty = sema.typeOf(ptr).childType(mod);
2732727367 if (array_ty.zigTypeTag(mod) != .Array) return null;
2732827368 var ptr_inst = Air.refToIndex(ptr) orelse return null;
2732927369 const air_datas = sema.air_instructions.items(.data);
......@@ -27332,7 +27372,6 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
2733227372 const prev_ptr = air_datas[ptr_inst].ty_op.operand;
2733327373 const prev_ptr_ty = sema.typeOf(prev_ptr);
2733427374 const prev_ptr_child_ty = switch (prev_ptr_ty.tag()) {
27335 .single_mut_pointer => prev_ptr_ty.castTag(.single_mut_pointer).?.data,
2733627375 .pointer => prev_ptr_ty.castTag(.pointer).?.data.pointee_type,
2733727376 else => return null,
2733827377 };
......@@ -27342,9 +27381,9 @@ fn obtainBitCastedVectorPtr(sema: *Sema, ptr: Air.Inst.Ref) ?Air.Inst.Ref {
2734227381
2734327382 // We have a pointer-to-array and a pointer-to-vector. If the elements and
2734427383 // lengths match, return the result.
27345 const vector_ty = sema.typeOf(prev_ptr).childType();
27346 if (array_ty.childType().eql(vector_ty.childType(), sema.mod) and
27347 array_ty.arrayLen() == vector_ty.vectorLen())
27384 const vector_ty = sema.typeOf(prev_ptr).childType(mod);
27385 if (array_ty.childType(mod).eql(vector_ty.childType(mod), sema.mod) and
27386 array_ty.arrayLen(mod) == vector_ty.vectorLen(mod))
2734827387 {
2734927388 return prev_ptr;
2735027389 } else {
......@@ -27476,14 +27515,14 @@ fn beginComptimePtrMutation(
2747627515 switch (parent.pointee) {
2747727516 .direct => |val_ptr| switch (parent.ty.zigTypeTag(mod)) {
2747827517 .Array, .Vector => {
27479 const check_len = parent.ty.arrayLenIncludingSentinel();
27518 const check_len = parent.ty.arrayLenIncludingSentinel(mod);
2748027519 if (elem_ptr.index >= check_len) {
2748127520 // TODO have the parent include the decl so we can say "declared here"
2748227521 return sema.fail(block, src, "comptime store of index {d} out of bounds of array length {d}", .{
2748327522 elem_ptr.index, check_len,
2748427523 });
2748527524 }
27486 const elem_ty = parent.ty.childType();
27525 const elem_ty = parent.ty.childType(mod);
2748727526
2748827527 // We might have a pointer to multiple elements of the array (e.g. a pointer
2748927528 // to a sub-array). In this case, we just have to reinterpret the relevant
......@@ -27510,7 +27549,7 @@ fn beginComptimePtrMutation(
2751027549 defer parent.finishArena(sema.mod);
2751127550
2751227551 const array_len_including_sentinel =
27513 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel());
27552 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));
2751427553 const elems = try arena.alloc(Value, array_len_including_sentinel);
2751527554 @memset(elems, Value.undef);
2751627555
......@@ -27536,7 +27575,7 @@ fn beginComptimePtrMutation(
2753627575 defer parent.finishArena(sema.mod);
2753727576
2753827577 const bytes = val_ptr.castTag(.bytes).?.data;
27539 const dest_len = parent.ty.arrayLenIncludingSentinel();
27578 const dest_len = parent.ty.arrayLenIncludingSentinel(mod);
2754027579 // bytes.len may be one greater than dest_len because of the case when
2754127580 // assigning `[N:S]T` to `[N]T`. This is allowed; the sentinel is omitted.
2754227581 assert(bytes.len >= dest_len);
......@@ -27567,13 +27606,13 @@ fn beginComptimePtrMutation(
2756727606 defer parent.finishArena(sema.mod);
2756827607
2756927608 const str_lit = val_ptr.castTag(.str_lit).?.data;
27570 const dest_len = parent.ty.arrayLenIncludingSentinel();
27609 const dest_len = parent.ty.arrayLenIncludingSentinel(mod);
2757127610 const bytes = sema.mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
2757227611 const elems = try arena.alloc(Value, @intCast(usize, dest_len));
2757327612 for (bytes, 0..) |byte, i| {
2757427613 elems[i] = try Value.Tag.int_u64.create(arena, byte);
2757527614 }
27576 if (parent.ty.sentinel()) |sent_val| {
27615 if (parent.ty.sentinel(mod)) |sent_val| {
2757727616 assert(elems.len == bytes.len + 1);
2757827617 elems[bytes.len] = sent_val;
2757927618 }
......@@ -27603,7 +27642,7 @@ fn beginComptimePtrMutation(
2760327642
2760427643 const repeated_val = try val_ptr.castTag(.repeated).?.data.copy(arena);
2760527644 const array_len_including_sentinel =
27606 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel());
27645 try sema.usizeCast(block, src, parent.ty.arrayLenIncludingSentinel(mod));
2760727646 const elems = try arena.alloc(Value, array_len_including_sentinel);
2760827647 if (elems.len > 0) elems[0] = repeated_val;
2760927648 for (elems[1..]) |*elem| {
......@@ -27906,12 +27945,12 @@ fn beginComptimePtrMutation(
2790627945 },
2790727946 .opt_payload_ptr => {
2790827947 const opt_ptr = if (ptr_val.castTag(.opt_payload_ptr)) |some| some.data else {
27909 return sema.beginComptimePtrMutation(block, src, ptr_val, try ptr_elem_ty.optionalChildAlloc(sema.arena));
27948 return sema.beginComptimePtrMutation(block, src, ptr_val, ptr_elem_ty.optionalChild(mod));
2791027949 };
2791127950 var parent = try sema.beginComptimePtrMutation(block, src, opt_ptr.container_ptr, opt_ptr.container_ty);
2791227951 switch (parent.pointee) {
2791327952 .direct => |val_ptr| {
27914 const payload_ty = try parent.ty.optionalChildAlloc(sema.arena);
27953 const payload_ty = parent.ty.optionalChild(mod);
2791527954 switch (val_ptr.tag()) {
2791627955 .undef, .null_value => {
2791727956 // An optional has been initialized to undefined at comptime and now we
......@@ -27984,7 +28023,7 @@ fn beginComptimePtrMutationInner(
2798428023
2798528024 // Handle the case that the decl is an array and we're actually trying to point to an element.
2798628025 if (decl_ty.isArrayOrVector(mod)) {
27987 const decl_elem_ty = decl_ty.childType();
28026 const decl_elem_ty = decl_ty.childType(mod);
2798828027 if ((try sema.coerceInMemoryAllowed(block, ptr_elem_ty, decl_elem_ty, true, target, src, src)) == .ok) {
2798928028 return ComptimePtrMutationKit{
2799028029 .decl_ref_mut = decl_ref_mut,
......@@ -28105,7 +28144,7 @@ fn beginComptimePtrLoad(
2810528144 // If we're loading an elem_ptr that was derived from a different type
2810628145 // than the true type of the underlying decl, we cannot deref directly
2810728146 const ty_matches = if (deref.pointee != null and deref.pointee.?.ty.isArrayOrVector(mod)) x: {
28108 const deref_elem_ty = deref.pointee.?.ty.childType();
28147 const deref_elem_ty = deref.pointee.?.ty.childType(mod);
2810928148 break :x (try sema.coerceInMemoryAllowed(block, deref_elem_ty, elem_ty, false, target, src, src)) == .ok or
2811028149 (try sema.coerceInMemoryAllowed(block, elem_ty, deref_elem_ty, false, target, src, src)) == .ok;
2811128150 } else false;
......@@ -28115,12 +28154,12 @@ fn beginComptimePtrLoad(
2811528154 }
2811628155
2811728156 var array_tv = deref.pointee.?;
28118 const check_len = array_tv.ty.arrayLenIncludingSentinel();
28157 const check_len = array_tv.ty.arrayLenIncludingSentinel(mod);
2811928158 if (maybe_array_ty) |load_ty| {
2812028159 // It's possible that we're loading a [N]T, in which case we'd like to slice
2812128160 // the pointee array directly from our parent array.
28122 if (load_ty.isArrayOrVector(mod) and load_ty.childType().eql(elem_ty, sema.mod)) {
28123 const N = try sema.usizeCast(block, src, load_ty.arrayLenIncludingSentinel());
28161 if (load_ty.isArrayOrVector(mod) and load_ty.childType(mod).eql(elem_ty, sema.mod)) {
28162 const N = try sema.usizeCast(block, src, load_ty.arrayLenIncludingSentinel(mod));
2812428163 deref.pointee = if (elem_ptr.index + N <= check_len) TypedValue{
2812528164 .ty = try Type.array(sema.arena, N, null, elem_ty, sema.mod),
2812628165 .val = try array_tv.val.sliceArray(sema.mod, sema.arena, elem_ptr.index, elem_ptr.index + N),
......@@ -28134,7 +28173,7 @@ fn beginComptimePtrLoad(
2813428173 break :blk deref;
2813528174 }
2813628175 if (elem_ptr.index == check_len - 1) {
28137 if (array_tv.ty.sentinel()) |sent| {
28176 if (array_tv.ty.sentinel(mod)) |sent| {
2813828177 deref.pointee = TypedValue{
2813928178 .ty = elem_ty,
2814028179 .val = sent,
......@@ -28226,7 +28265,7 @@ fn beginComptimePtrLoad(
2822628265 const payload_ptr = ptr_val.cast(Value.Payload.PayloadPtr).?.data;
2822728266 const payload_ty = switch (ptr_val.tag()) {
2822828267 .eu_payload_ptr => payload_ptr.container_ty.errorUnionPayload(),
28229 .opt_payload_ptr => try payload_ptr.container_ty.optionalChildAlloc(sema.arena),
28268 .opt_payload_ptr => payload_ptr.container_ty.optionalChild(mod),
2823028269 else => unreachable,
2823128270 };
2823228271 var deref = try sema.beginComptimePtrLoad(block, src, payload_ptr.container_ptr, payload_ptr.container_ty);
......@@ -28357,12 +28396,13 @@ fn coerceArrayPtrToSlice(
2835728396 inst: Air.Inst.Ref,
2835828397 inst_src: LazySrcLoc,
2835928398) CompileError!Air.Inst.Ref {
28399 const mod = sema.mod;
2836028400 if (try sema.resolveMaybeUndefVal(inst)) |val| {
2836128401 const ptr_array_ty = sema.typeOf(inst);
28362 const array_ty = ptr_array_ty.childType();
28402 const array_ty = ptr_array_ty.childType(mod);
2836328403 const slice_val = try Value.Tag.slice.create(sema.arena, .{
2836428404 .ptr = val,
28365 .len = try Value.Tag.int_u64.create(sema.arena, array_ty.arrayLen()),
28405 .len = try Value.Tag.int_u64.create(sema.arena, array_ty.arrayLen(mod)),
2836628406 });
2836728407 return sema.addConstant(dest_ty, slice_val);
2836828408 }
......@@ -28371,11 +28411,11 @@ fn coerceArrayPtrToSlice(
2837128411}
2837228412
2837328413fn checkPtrAttributes(sema: *Sema, dest_ty: Type, inst_ty: Type, in_memory_result: *InMemoryCoercionResult) bool {
28374 const dest_info = dest_ty.ptrInfo().data;
28375 const inst_info = inst_ty.ptrInfo().data;
2837628414 const mod = sema.mod;
28377 const len0 = (inst_info.pointee_type.zigTypeTag(mod) == .Array and (inst_info.pointee_type.arrayLenIncludingSentinel() == 0 or
28378 (inst_info.pointee_type.arrayLen() == 0 and dest_info.sentinel == null and dest_info.size != .C and dest_info.size != .Many))) or
28415 const dest_info = dest_ty.ptrInfo(mod);
28416 const inst_info = inst_ty.ptrInfo(mod);
28417 const len0 = (inst_info.pointee_type.zigTypeTag(mod) == .Array and (inst_info.pointee_type.arrayLenIncludingSentinel(mod) == 0 or
28418 (inst_info.pointee_type.arrayLen(mod) == 0 and dest_info.sentinel == null and dest_info.size != .C and dest_info.size != .Many))) or
2837928419 (inst_info.pointee_type.isTuple() and inst_info.pointee_type.structFieldCount() == 0);
2838028420
2838128421 const ok_cv_qualifiers =
......@@ -28647,7 +28687,8 @@ fn coerceAnonStructToUnionPtrs(
2864728687 ptr_anon_struct: Air.Inst.Ref,
2864828688 anon_struct_src: LazySrcLoc,
2864928689) !Air.Inst.Ref {
28650 const union_ty = ptr_union_ty.childType();
28690 const mod = sema.mod;
28691 const union_ty = ptr_union_ty.childType(mod);
2865128692 const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src);
2865228693 const union_inst = try sema.coerceAnonStructToUnion(block, union_ty, union_ty_src, anon_struct, anon_struct_src);
2865328694 return sema.analyzeRef(block, union_ty_src, union_inst);
......@@ -28661,7 +28702,8 @@ fn coerceAnonStructToStructPtrs(
2866128702 ptr_anon_struct: Air.Inst.Ref,
2866228703 anon_struct_src: LazySrcLoc,
2866328704) !Air.Inst.Ref {
28664 const struct_ty = ptr_struct_ty.childType();
28705 const mod = sema.mod;
28706 const struct_ty = ptr_struct_ty.childType(mod);
2866528707 const anon_struct = try sema.analyzeLoad(block, anon_struct_src, ptr_anon_struct, anon_struct_src);
2866628708 const struct_inst = try sema.coerceTupleToStruct(block, struct_ty, anon_struct, anon_struct_src);
2866728709 return sema.analyzeRef(block, struct_ty_src, struct_inst);
......@@ -28676,15 +28718,16 @@ fn coerceArrayLike(
2867628718 inst: Air.Inst.Ref,
2867728719 inst_src: LazySrcLoc,
2867828720) !Air.Inst.Ref {
28721 const mod = sema.mod;
2867928722 const inst_ty = sema.typeOf(inst);
28680 const inst_len = inst_ty.arrayLen();
28681 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen());
28682 const target = sema.mod.getTarget();
28723 const inst_len = inst_ty.arrayLen(mod);
28724 const dest_len = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLen(mod));
28725 const target = mod.getTarget();
2868328726
2868428727 if (dest_len != inst_len) {
2868528728 const msg = msg: {
2868628729 const msg = try sema.errMsg(block, inst_src, "expected type '{}', found '{}'", .{
28687 dest_ty.fmt(sema.mod), inst_ty.fmt(sema.mod),
28730 dest_ty.fmt(mod), inst_ty.fmt(mod),
2868828731 });
2868928732 errdefer msg.destroy(sema.gpa);
2869028733 try sema.errNote(block, dest_ty_src, msg, "destination has length {d}", .{dest_len});
......@@ -28694,8 +28737,8 @@ fn coerceArrayLike(
2869428737 return sema.failWithOwnedErrorMsg(msg);
2869528738 }
2869628739
28697 const dest_elem_ty = dest_ty.childType();
28698 const inst_elem_ty = inst_ty.childType();
28740 const dest_elem_ty = dest_ty.childType(mod);
28741 const inst_elem_ty = inst_ty.childType(mod);
2869928742 const in_memory_result = try sema.coerceInMemoryAllowed(block, dest_elem_ty, inst_elem_ty, false, target, dest_ty_src, inst_src);
2870028743 if (in_memory_result == .ok) {
2870128744 if (try sema.resolveMaybeUndefVal(inst)) |inst_val| {
......@@ -28749,9 +28792,10 @@ fn coerceTupleToArray(
2874928792 inst: Air.Inst.Ref,
2875028793 inst_src: LazySrcLoc,
2875128794) !Air.Inst.Ref {
28795 const mod = sema.mod;
2875228796 const inst_ty = sema.typeOf(inst);
28753 const inst_len = inst_ty.arrayLen();
28754 const dest_len = dest_ty.arrayLen();
28797 const inst_len = inst_ty.arrayLen(mod);
28798 const dest_len = dest_ty.arrayLen(mod);
2875528799
2875628800 if (dest_len != inst_len) {
2875728801 const msg = msg: {
......@@ -28766,16 +28810,16 @@ fn coerceTupleToArray(
2876628810 return sema.failWithOwnedErrorMsg(msg);
2876728811 }
2876828812
28769 const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLenIncludingSentinel());
28813 const dest_elems = try sema.usizeCast(block, dest_ty_src, dest_ty.arrayLenIncludingSentinel(mod));
2877028814 const element_vals = try sema.arena.alloc(Value, dest_elems);
2877128815 const element_refs = try sema.arena.alloc(Air.Inst.Ref, dest_elems);
28772 const dest_elem_ty = dest_ty.childType();
28816 const dest_elem_ty = dest_ty.childType(mod);
2877328817
2877428818 var runtime_src: ?LazySrcLoc = null;
2877528819 for (element_vals, 0..) |*elem, i_usize| {
2877628820 const i = @intCast(u32, i_usize);
2877728821 if (i_usize == inst_len) {
28778 elem.* = dest_ty.sentinel().?;
28822 elem.* = dest_ty.sentinel(mod).?;
2877928823 element_refs[i] = try sema.addConstant(dest_elem_ty, elem.*);
2878028824 break;
2878128825 }
......@@ -28812,9 +28856,10 @@ fn coerceTupleToSlicePtrs(
2881228856 ptr_tuple: Air.Inst.Ref,
2881328857 tuple_src: LazySrcLoc,
2881428858) !Air.Inst.Ref {
28815 const tuple_ty = sema.typeOf(ptr_tuple).childType();
28859 const mod = sema.mod;
28860 const tuple_ty = sema.typeOf(ptr_tuple).childType(mod);
2881628861 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);
28817 const slice_info = slice_ty.ptrInfo().data;
28862 const slice_info = slice_ty.ptrInfo(mod);
2881828863 const array_ty = try Type.array(sema.arena, tuple_ty.structFieldCount(), slice_info.sentinel, slice_info.pointee_type, sema.mod);
2881928864 const array_inst = try sema.coerceTupleToArray(block, array_ty, slice_ty_src, tuple, tuple_src);
2882028865 if (slice_info.@"align" != 0) {
......@@ -28833,8 +28878,9 @@ fn coerceTupleToArrayPtrs(
2883328878 ptr_tuple: Air.Inst.Ref,
2883428879 tuple_src: LazySrcLoc,
2883528880) !Air.Inst.Ref {
28881 const mod = sema.mod;
2883628882 const tuple = try sema.analyzeLoad(block, tuple_src, ptr_tuple, tuple_src);
28837 const ptr_info = ptr_array_ty.ptrInfo().data;
28883 const ptr_info = ptr_array_ty.ptrInfo(mod);
2883828884 const array_ty = ptr_info.pointee_type;
2883928885 const array_inst = try sema.coerceTupleToArray(block, array_ty, array_ty_src, tuple, tuple_src);
2884028886 if (ptr_info.@"align" != 0) {
......@@ -29231,7 +29277,7 @@ fn analyzeLoad(
2923129277 const mod = sema.mod;
2923229278 const ptr_ty = sema.typeOf(ptr);
2923329279 const elem_ty = switch (ptr_ty.zigTypeTag(mod)) {
29234 .Pointer => ptr_ty.childType(),
29280 .Pointer => ptr_ty.childType(mod),
2923529281 else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ty.fmt(sema.mod)}),
2923629282 };
2923729283
......@@ -29245,7 +29291,7 @@ fn analyzeLoad(
2924529291 }
2924629292 }
2924729293
29248 if (ptr_ty.ptrInfo().data.vector_index == .runtime) {
29294 if (ptr_ty.ptrInfo(mod).vector_index == .runtime) {
2924929295 const ptr_inst = Air.refToIndex(ptr).?;
2925029296 const air_tags = sema.air_instructions.items(.tag);
2925129297 if (air_tags[ptr_inst] == .ptr_elem_ptr) {
......@@ -29318,8 +29364,7 @@ fn analyzeIsNull(
2931829364
2931929365 const inverted_non_null_res = if (invert_logic) Air.Inst.Ref.bool_true else Air.Inst.Ref.bool_false;
2932029366 const operand_ty = sema.typeOf(operand);
29321 var buf: Type.Payload.ElemType = undefined;
29322 if (operand_ty.zigTypeTag(mod) == .Optional and operand_ty.optionalChild(&buf).zigTypeTag(mod) == .NoReturn) {
29367 if (operand_ty.zigTypeTag(mod) == .Optional and operand_ty.optionalChild(mod).zigTypeTag(mod) == .NoReturn) {
2932329368 return inverted_non_null_res;
2932429369 }
2932529370 if (operand_ty.zigTypeTag(mod) != .Optional and !operand_ty.isPtrLikeOptional(mod)) {
......@@ -29339,7 +29384,7 @@ fn analyzePtrIsNonErrComptimeOnly(
2933929384 const mod = sema.mod;
2934029385 const ptr_ty = sema.typeOf(operand);
2934129386 assert(ptr_ty.zigTypeTag(mod) == .Pointer);
29342 const child_ty = ptr_ty.childType();
29387 const child_ty = ptr_ty.childType(mod);
2934329388
2934429389 const child_tag = child_ty.zigTypeTag(mod);
2934529390 if (child_tag != .ErrorSet and child_tag != .ErrorUnion) return Air.Inst.Ref.bool_true;
......@@ -29495,7 +29540,7 @@ fn analyzeSlice(
2949529540 // the slice operand to be a pointer. In the case of a non-array, it will be a double pointer.
2949629541 const ptr_ptr_ty = sema.typeOf(ptr_ptr);
2949729542 const ptr_ptr_child_ty = switch (ptr_ptr_ty.zigTypeTag(mod)) {
29498 .Pointer => ptr_ptr_ty.elemType(),
29543 .Pointer => ptr_ptr_ty.childType(mod),
2949929544 else => return sema.fail(block, ptr_src, "expected pointer, found '{}'", .{ptr_ptr_ty.fmt(sema.mod)}),
2950029545 };
2950129546
......@@ -29506,30 +29551,30 @@ fn analyzeSlice(
2950629551 var ptr_sentinel: ?Value = null;
2950729552 switch (ptr_ptr_child_ty.zigTypeTag(mod)) {
2950829553 .Array => {
29509 ptr_sentinel = ptr_ptr_child_ty.sentinel();
29510 elem_ty = ptr_ptr_child_ty.childType();
29554 ptr_sentinel = ptr_ptr_child_ty.sentinel(mod);
29555 elem_ty = ptr_ptr_child_ty.childType(mod);
2951129556 },
29512 .Pointer => switch (ptr_ptr_child_ty.ptrSize()) {
29557 .Pointer => switch (ptr_ptr_child_ty.ptrSize(mod)) {
2951329558 .One => {
29514 const double_child_ty = ptr_ptr_child_ty.childType();
29559 const double_child_ty = ptr_ptr_child_ty.childType(mod);
2951529560 if (double_child_ty.zigTypeTag(mod) == .Array) {
29516 ptr_sentinel = double_child_ty.sentinel();
29561 ptr_sentinel = double_child_ty.sentinel(mod);
2951729562 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);
2951829563 slice_ty = ptr_ptr_child_ty;
2951929564 array_ty = double_child_ty;
29520 elem_ty = double_child_ty.childType();
29565 elem_ty = double_child_ty.childType(mod);
2952129566 } else {
2952229567 return sema.fail(block, src, "slice of single-item pointer", .{});
2952329568 }
2952429569 },
2952529570 .Many, .C => {
29526 ptr_sentinel = ptr_ptr_child_ty.sentinel();
29571 ptr_sentinel = ptr_ptr_child_ty.sentinel(mod);
2952729572 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);
2952829573 slice_ty = ptr_ptr_child_ty;
2952929574 array_ty = ptr_ptr_child_ty;
29530 elem_ty = ptr_ptr_child_ty.childType();
29575 elem_ty = ptr_ptr_child_ty.childType(mod);
2953129576
29532 if (ptr_ptr_child_ty.ptrSize() == .C) {
29577 if (ptr_ptr_child_ty.ptrSize(mod) == .C) {
2953329578 if (try sema.resolveDefinedValue(block, ptr_src, ptr_or_slice)) |ptr_val| {
2953429579 if (ptr_val.isNull(mod)) {
2953529580 return sema.fail(block, src, "slice of null pointer", .{});
......@@ -29538,11 +29583,11 @@ fn analyzeSlice(
2953829583 }
2953929584 },
2954029585 .Slice => {
29541 ptr_sentinel = ptr_ptr_child_ty.sentinel();
29586 ptr_sentinel = ptr_ptr_child_ty.sentinel(mod);
2954229587 ptr_or_slice = try sema.analyzeLoad(block, src, ptr_ptr, ptr_src);
2954329588 slice_ty = ptr_ptr_child_ty;
2954429589 array_ty = ptr_ptr_child_ty;
29545 elem_ty = ptr_ptr_child_ty.childType();
29590 elem_ty = ptr_ptr_child_ty.childType(mod);
2954629591 },
2954729592 },
2954829593 else => return sema.fail(block, src, "slice of non-array type '{}'", .{ptr_ptr_child_ty.fmt(mod)}),
......@@ -29563,7 +29608,7 @@ fn analyzeSlice(
2956329608 var end_is_len = uncasted_end_opt == .none;
2956429609 const end = e: {
2956529610 if (array_ty.zigTypeTag(mod) == .Array) {
29566 const len_val = try Value.Tag.int_u64.create(sema.arena, array_ty.arrayLen());
29611 const len_val = try Value.Tag.int_u64.create(sema.arena, array_ty.arrayLen(mod));
2956729612
2956829613 if (!end_is_len) {
2956929614 const end = if (by_length) end: {
......@@ -29574,10 +29619,10 @@ fn analyzeSlice(
2957429619 if (try sema.resolveMaybeUndefVal(end)) |end_val| {
2957529620 const len_s_val = try Value.Tag.int_u64.create(
2957629621 sema.arena,
29577 array_ty.arrayLenIncludingSentinel(),
29622 array_ty.arrayLenIncludingSentinel(mod),
2957829623 );
2957929624 if (!(try sema.compareAll(end_val, .lte, len_s_val, Type.usize))) {
29580 const sentinel_label: []const u8 = if (array_ty.sentinel() != null)
29625 const sentinel_label: []const u8 = if (array_ty.sentinel(mod) != null)
2958129626 " +1 (sentinel)"
2958229627 else
2958329628 "";
......@@ -29617,7 +29662,7 @@ fn analyzeSlice(
2961729662 if (slice_val.isUndef()) {
2961829663 return sema.fail(block, src, "slice of undefined", .{});
2961929664 }
29620 const has_sentinel = slice_ty.sentinel() != null;
29665 const has_sentinel = slice_ty.sentinel(mod) != null;
2962129666 var int_payload: Value.Payload.U64 = .{
2962229667 .base = .{ .tag = .int_u64 },
2962329668 .data = slice_val.sliceLen(mod) + @boolToInt(has_sentinel),
......@@ -29751,8 +29796,8 @@ fn analyzeSlice(
2975129796 try sema.analyzeArithmetic(block, .sub, end, start, src, end_src, start_src, false);
2975229797 const opt_new_len_val = try sema.resolveDefinedValue(block, src, new_len);
2975329798
29754 const new_ptr_ty_info = sema.typeOf(new_ptr).ptrInfo().data;
29755 const new_allowzero = new_ptr_ty_info.@"allowzero" and sema.typeOf(ptr).ptrSize() != .C;
29799 const new_ptr_ty_info = sema.typeOf(new_ptr).ptrInfo(mod);
29800 const new_allowzero = new_ptr_ty_info.@"allowzero" and sema.typeOf(ptr).ptrSize(mod) != .C;
2975629801
2975729802 if (opt_new_len_val) |new_len_val| {
2975829803 const new_len_int = new_len_val.toUnsignedInt(mod);
......@@ -29780,7 +29825,7 @@ fn analyzeSlice(
2978029825
2978129826 if (slice_ty.isSlice(mod)) {
2978229827 const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice);
29783 const actual_len = if (slice_ty.sentinel() == null)
29828 const actual_len = if (slice_ty.sentinel(mod) == null)
2978429829 slice_len_inst
2978529830 else
2978629831 try sema.analyzeArithmetic(block, .add, slice_len_inst, .one, src, end_src, end_src, true);
......@@ -29839,7 +29884,7 @@ fn analyzeSlice(
2983929884
2984029885 // requirement: end <= len
2984129886 const opt_len_inst = if (array_ty.zigTypeTag(mod) == .Array)
29842 try sema.addIntUnsigned(Type.usize, array_ty.arrayLenIncludingSentinel())
29887 try sema.addIntUnsigned(Type.usize, array_ty.arrayLenIncludingSentinel(mod))
2984329888 else if (slice_ty.isSlice(mod)) blk: {
2984429889 if (try sema.resolveDefinedValue(block, src, ptr_or_slice)) |slice_val| {
2984529890 // we don't need to add one for sentinels because the
......@@ -29848,7 +29893,7 @@ fn analyzeSlice(
2984829893 }
2984929894
2985029895 const slice_len_inst = try block.addTyOp(.slice_len, Type.usize, ptr_or_slice);
29851 if (slice_ty.sentinel() == null) break :blk slice_len_inst;
29896 if (slice_ty.sentinel(mod) == null) break :blk slice_len_inst;
2985229897
2985329898 // we have to add one because slice lengths don't include the sentinel
2985429899 break :blk try sema.analyzeArithmetic(block, .add, slice_len_inst, .one, src, end_src, end_src, true);
......@@ -30284,7 +30329,10 @@ fn cmpVector(
3028430329 const casted_lhs = try sema.coerce(block, resolved_ty, lhs, lhs_src);
3028530330 const casted_rhs = try sema.coerce(block, resolved_ty, rhs, rhs_src);
3028630331
30287 const result_ty = try Type.vector(sema.arena, lhs_ty.vectorLen(), Type.bool);
30332 const result_ty = try mod.vectorType(.{
30333 .len = lhs_ty.vectorLen(mod),
30334 .child = .bool_type,
30335 });
3028830336
3028930337 const runtime_src: LazySrcLoc = src: {
3029030338 if (try sema.resolveMaybeUndefVal(casted_lhs)) |lhs_val| {
......@@ -30484,12 +30532,12 @@ fn resolvePeerTypes(
3048430532 }
3048530533 continue;
3048630534 },
30487 .Pointer => if (chosen_ty.ptrSize() == .C) continue,
30535 .Pointer => if (chosen_ty.ptrSize(mod) == .C) continue,
3048830536 else => {},
3048930537 },
3049030538 .ComptimeInt => switch (chosen_ty_tag) {
3049130539 .Int, .Float, .ComptimeFloat => continue,
30492 .Pointer => if (chosen_ty.ptrSize() == .C) continue,
30540 .Pointer => if (chosen_ty.ptrSize(mod) == .C) continue,
3049330541 else => {},
3049430542 },
3049530543 .Float => switch (chosen_ty_tag) {
......@@ -30654,10 +30702,10 @@ fn resolvePeerTypes(
3065430702 },
3065530703 },
3065630704 .Pointer => {
30657 const cand_info = candidate_ty.ptrInfo().data;
30705 const cand_info = candidate_ty.ptrInfo(mod);
3065830706 switch (chosen_ty_tag) {
3065930707 .Pointer => {
30660 const chosen_info = chosen_ty.ptrInfo().data;
30708 const chosen_info = chosen_ty.ptrInfo(mod);
3066130709
3066230710 seen_const = seen_const or !chosen_info.mutable or !cand_info.mutable;
3066330711
......@@ -30690,8 +30738,8 @@ fn resolvePeerTypes(
3069030738 chosen_info.pointee_type.zigTypeTag(mod) == .Array and
3069130739 cand_info.pointee_type.zigTypeTag(mod) == .Array)
3069230740 {
30693 const chosen_elem_ty = chosen_info.pointee_type.childType();
30694 const cand_elem_ty = cand_info.pointee_type.childType();
30741 const chosen_elem_ty = chosen_info.pointee_type.childType(mod);
30742 const cand_elem_ty = cand_info.pointee_type.childType(mod);
3069530743
3069630744 const chosen_ok = .ok == try sema.coerceInMemoryAllowed(block, chosen_elem_ty, cand_elem_ty, chosen_info.mutable, target, src, src);
3069730745 if (chosen_ok) {
......@@ -30757,10 +30805,9 @@ fn resolvePeerTypes(
3075730805 }
3075830806 },
3075930807 .Optional => {
30760 var opt_child_buf: Type.Payload.ElemType = undefined;
30761 const chosen_ptr_ty = chosen_ty.optionalChild(&opt_child_buf);
30808 const chosen_ptr_ty = chosen_ty.optionalChild(mod);
3076230809 if (chosen_ptr_ty.zigTypeTag(mod) == .Pointer) {
30763 const chosen_info = chosen_ptr_ty.ptrInfo().data;
30810 const chosen_info = chosen_ptr_ty.ptrInfo(mod);
3076430811
3076530812 seen_const = seen_const or !chosen_info.mutable or !cand_info.mutable;
3076630813
......@@ -30777,7 +30824,7 @@ fn resolvePeerTypes(
3077730824 .ErrorUnion => {
3077830825 const chosen_ptr_ty = chosen_ty.errorUnionPayload();
3077930826 if (chosen_ptr_ty.zigTypeTag(mod) == .Pointer) {
30780 const chosen_info = chosen_ptr_ty.ptrInfo().data;
30827 const chosen_info = chosen_ptr_ty.ptrInfo(mod);
3078130828
3078230829 seen_const = seen_const or !chosen_info.mutable or !cand_info.mutable;
3078330830
......@@ -30802,8 +30849,7 @@ fn resolvePeerTypes(
3080230849 }
3080330850 },
3080430851 .Optional => {
30805 var opt_child_buf: Type.Payload.ElemType = undefined;
30806 const opt_child_ty = candidate_ty.optionalChild(&opt_child_buf);
30852 const opt_child_ty = candidate_ty.optionalChild(mod);
3080730853 if ((try sema.coerceInMemoryAllowed(block, chosen_ty, opt_child_ty, false, target, src, src)) == .ok) {
3080830854 seen_const = seen_const or opt_child_ty.isConstPtr();
3080930855 any_are_null = true;
......@@ -30818,13 +30864,13 @@ fn resolvePeerTypes(
3081830864 },
3081930865 .Vector => switch (chosen_ty_tag) {
3082030866 .Vector => {
30821 const chosen_len = chosen_ty.vectorLen();
30822 const candidate_len = candidate_ty.vectorLen();
30867 const chosen_len = chosen_ty.vectorLen(mod);
30868 const candidate_len = candidate_ty.vectorLen(mod);
3082330869 if (chosen_len != candidate_len)
3082430870 continue;
3082530871
30826 const chosen_child_ty = chosen_ty.childType();
30827 const candidate_child_ty = candidate_ty.childType();
30872 const chosen_child_ty = chosen_ty.childType(mod);
30873 const candidate_child_ty = candidate_ty.childType(mod);
3082830874 if (chosen_child_ty.zigTypeTag(mod) == .Int and candidate_child_ty.zigTypeTag(mod) == .Int) {
3082930875 const chosen_info = chosen_child_ty.intInfo(mod);
3083030876 const candidate_info = candidate_child_ty.intInfo(mod);
......@@ -30853,8 +30899,8 @@ fn resolvePeerTypes(
3085330899 .Vector => continue,
3085430900 else => {},
3085530901 },
30856 .Fn => if (chosen_ty.isSinglePointer(mod) and chosen_ty.isConstPtr() and chosen_ty.childType().zigTypeTag(mod) == .Fn) {
30857 if (.ok == try sema.coerceInMemoryAllowedFns(block, chosen_ty.childType(), candidate_ty, target, src, src)) {
30902 .Fn => if (chosen_ty.isSinglePointer(mod) and chosen_ty.isConstPtr() and chosen_ty.childType(mod).zigTypeTag(mod) == .Fn) {
30903 if (.ok == try sema.coerceInMemoryAllowedFns(block, chosen_ty.childType(mod), candidate_ty, target, src, src)) {
3085830904 continue;
3085930905 }
3086030906 },
......@@ -30874,8 +30920,7 @@ fn resolvePeerTypes(
3087430920 continue;
3087530921 },
3087630922 .Optional => {
30877 var opt_child_buf: Type.Payload.ElemType = undefined;
30878 const opt_child_ty = chosen_ty.optionalChild(&opt_child_buf);
30923 const opt_child_ty = chosen_ty.optionalChild(mod);
3087930924 if ((try sema.coerceInMemoryAllowed(block, opt_child_ty, candidate_ty, false, target, src, src)) == .ok) {
3088030925 continue;
3088130926 }
......@@ -30949,16 +30994,16 @@ fn resolvePeerTypes(
3094930994
3095030995 if (convert_to_slice) {
3095130996 // turn *[N]T => []T
30952 const chosen_child_ty = chosen_ty.childType();
30953 var info = chosen_ty.ptrInfo();
30954 info.data.sentinel = chosen_child_ty.sentinel();
30955 info.data.size = .Slice;
30956 info.data.mutable = !(seen_const or chosen_child_ty.isConstPtr());
30957 info.data.pointee_type = chosen_child_ty.elemType2(mod);
30958
30959 const new_ptr_ty = try Type.ptr(sema.arena, mod, info.data);
30997 const chosen_child_ty = chosen_ty.childType(mod);
30998 var info = chosen_ty.ptrInfo(mod);
30999 info.sentinel = chosen_child_ty.sentinel(mod);
31000 info.size = .Slice;
31001 info.mutable = !(seen_const or chosen_child_ty.isConstPtr());
31002 info.pointee_type = chosen_child_ty.elemType2(mod);
31003
31004 const new_ptr_ty = try Type.ptr(sema.arena, mod, info);
3096031005 const opt_ptr_ty = if (any_are_null)
30961 try Type.optional(sema.arena, new_ptr_ty)
31006 try Type.optional(sema.arena, new_ptr_ty, mod)
3096231007 else
3096331008 new_ptr_ty;
3096431009 const set_ty = err_set_ty orelse return opt_ptr_ty;
......@@ -30970,22 +31015,22 @@ fn resolvePeerTypes(
3097031015 switch (chosen_ty.zigTypeTag(mod)) {
3097131016 .ErrorUnion => {
3097231017 const ptr_ty = chosen_ty.errorUnionPayload();
30973 var info = ptr_ty.ptrInfo();
30974 info.data.mutable = false;
30975 const new_ptr_ty = try Type.ptr(sema.arena, mod, info.data);
31018 var info = ptr_ty.ptrInfo(mod);
31019 info.mutable = false;
31020 const new_ptr_ty = try Type.ptr(sema.arena, mod, info);
3097631021 const opt_ptr_ty = if (any_are_null)
30977 try Type.optional(sema.arena, new_ptr_ty)
31022 try Type.optional(sema.arena, new_ptr_ty, mod)
3097831023 else
3097931024 new_ptr_ty;
3098031025 const set_ty = err_set_ty orelse chosen_ty.errorUnionSet();
3098131026 return try Type.errorUnion(sema.arena, set_ty, opt_ptr_ty, mod);
3098231027 },
3098331028 .Pointer => {
30984 var info = chosen_ty.ptrInfo();
30985 info.data.mutable = false;
30986 const new_ptr_ty = try Type.ptr(sema.arena, mod, info.data);
31029 var info = chosen_ty.ptrInfo(mod);
31030 info.mutable = false;
31031 const new_ptr_ty = try Type.ptr(sema.arena, mod, info);
3098731032 const opt_ptr_ty = if (any_are_null)
30988 try Type.optional(sema.arena, new_ptr_ty)
31033 try Type.optional(sema.arena, new_ptr_ty, mod)
3098931034 else
3099031035 new_ptr_ty;
3099131036 const set_ty = err_set_ty orelse return opt_ptr_ty;
......@@ -30998,7 +31043,7 @@ fn resolvePeerTypes(
3099831043 if (any_are_null) {
3099931044 const opt_ty = switch (chosen_ty.zigTypeTag(mod)) {
3100031045 .Null, .Optional => chosen_ty,
31001 else => try Type.optional(sema.arena, chosen_ty),
31046 else => try Type.optional(sema.arena, chosen_ty, mod),
3100231047 };
3100331048 const set_ty = err_set_ty orelse return opt_ty;
3100431049 return try Type.errorUnion(sema.arena, set_ty, opt_ty, mod);
......@@ -31077,13 +31122,12 @@ pub fn resolveTypeLayout(sema: *Sema, ty: Type) CompileError!void {
3107731122 .Struct => return sema.resolveStructLayout(ty),
3107831123 .Union => return sema.resolveUnionLayout(ty),
3107931124 .Array => {
31080 if (ty.arrayLenIncludingSentinel() == 0) return;
31081 const elem_ty = ty.childType();
31125 if (ty.arrayLenIncludingSentinel(mod) == 0) return;
31126 const elem_ty = ty.childType(mod);
3108231127 return sema.resolveTypeLayout(elem_ty);
3108331128 },
3108431129 .Optional => {
31085 var buf: Type.Payload.ElemType = undefined;
31086 const payload_ty = ty.optionalChild(&buf);
31130 const payload_ty = ty.optionalChild(mod);
3108731131 // In case of querying the ABI alignment of this optional, we will ask
3108831132 // for hasRuntimeBits() of the payload type, so we need "requires comptime"
3108931133 // to be known already before this function returns.
......@@ -31343,10 +31387,10 @@ fn checkIndexable(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
3134331387fn checkMemOperand(sema: *Sema, block: *Block, src: LazySrcLoc, ty: Type) !void {
3134431388 const mod = sema.mod;
3134531389 if (ty.zigTypeTag(mod) == .Pointer) {
31346 switch (ty.ptrSize()) {
31390 switch (ty.ptrSize(mod)) {
3134731391 .Slice, .Many, .C => return,
3134831392 .One => {
31349 const elem_ty = ty.childType();
31393 const elem_ty = ty.childType(mod);
3135031394 if (elem_ty.zigTypeTag(mod) == .Array) return;
3135131395 // TODO https://github.com/ziglang/zig/issues/15479
3135231396 // if (elem_ty.isTuple()) return;
......@@ -31418,8 +31462,8 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3141831462 .int_type => false,
3141931463 .ptr_type => @panic("TODO"),
3142031464 .array_type => @panic("TODO"),
31421 .vector_type => @panic("TODO"),
31422 .optional_type => @panic("TODO"),
31465 .vector_type => |vector_type| return sema.resolveTypeRequiresComptime(vector_type.child.toType()),
31466 .opt_type => @panic("TODO"),
3142331467 .error_union_type => @panic("TODO"),
3142431468 .simple_type => |t| switch (t) {
3142531469 .f16,
......@@ -31478,12 +31522,6 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3147831522 };
3147931523
3148031524 return switch (ty.tag()) {
31481 .manyptr_u8,
31482 .manyptr_const_u8,
31483 .manyptr_const_u8_sentinel_0,
31484 .const_slice_u8,
31485 .const_slice_u8_sentinel_0,
31486 .anyerror_void_error_union,
3148731525 .empty_struct_literal,
3148831526 .empty_struct,
3148931527 .error_set,
......@@ -31491,34 +31529,20 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3149131529 .error_set_inferred,
3149231530 .error_set_merged,
3149331531 .@"opaque",
31494 .array_u8,
31495 .array_u8_sentinel_0,
3149631532 .enum_simple,
3149731533 => false,
3149831534
31499 .single_const_pointer_to_comptime_int,
31500 .function,
31501 => true,
31535 .function => true,
3150231536
3150331537 .inferred_alloc_mut => unreachable,
3150431538 .inferred_alloc_const => unreachable,
3150531539
3150631540 .array,
3150731541 .array_sentinel,
31508 .vector,
31509 => return sema.resolveTypeRequiresComptime(ty.childType()),
31542 => return sema.resolveTypeRequiresComptime(ty.childType(mod)),
3151031543
31511 .pointer,
31512 .single_const_pointer,
31513 .single_mut_pointer,
31514 .many_const_pointer,
31515 .many_mut_pointer,
31516 .c_const_pointer,
31517 .c_mut_pointer,
31518 .const_slice,
31519 .mut_slice,
31520 => {
31521 const child_ty = ty.childType();
31544 .pointer => {
31545 const child_ty = ty.childType(mod);
3152231546 if (child_ty.zigTypeTag(mod) == .Fn) {
3152331547 return child_ty.fnInfo().is_generic;
3152431548 } else {
......@@ -31526,12 +31550,8 @@ pub fn resolveTypeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3152631550 }
3152731551 },
3152831552
31529 .optional,
31530 .optional_single_mut_pointer,
31531 .optional_single_const_pointer,
31532 => {
31533 var buf: Type.Payload.ElemType = undefined;
31534 return sema.resolveTypeRequiresComptime(ty.optionalChild(&buf));
31553 .optional => {
31554 return sema.resolveTypeRequiresComptime(ty.optionalChild(mod));
3153531555 },
3153631556
3153731557 .tuple, .anon_struct => {
......@@ -31609,7 +31629,7 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {
3160931629 const mod = sema.mod;
3161031630 switch (ty.zigTypeTag(mod)) {
3161131631 .Pointer => {
31612 const child_ty = try sema.resolveTypeFields(ty.childType());
31632 const child_ty = try sema.resolveTypeFields(ty.childType(mod));
3161331633 return sema.resolveTypeFully(child_ty);
3161431634 },
3161531635 .Struct => switch (ty.tag()) {
......@@ -31624,10 +31644,9 @@ pub fn resolveTypeFully(sema: *Sema, ty: Type) CompileError!void {
3162431644 else => {},
3162531645 },
3162631646 .Union => return sema.resolveUnionFully(ty),
31627 .Array => return sema.resolveTypeFully(ty.childType()),
31647 .Array => return sema.resolveTypeFully(ty.childType(mod)),
3162831648 .Optional => {
31629 var buf: Type.Payload.ElemType = undefined;
31630 return sema.resolveTypeFully(ty.optionalChild(&buf));
31649 return sema.resolveTypeFully(ty.optionalChild(mod));
3163131650 },
3163231651 .ErrorUnion => return sema.resolveTypeFully(ty.errorUnionPayload()),
3163331652 .Fn => {
......@@ -32897,10 +32916,14 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3289732916 return null;
3289832917 }
3289932918 },
32900 .ptr_type => @panic("TODO"),
32919 .ptr_type => return null,
3290132920 .array_type => @panic("TODO"),
32902 .vector_type => @panic("TODO"),
32903 .optional_type => @panic("TODO"),
32921 .vector_type => |vector_type| {
32922 if (vector_type.len == 0) return Value.initTag(.empty_array);
32923 if (try sema.typeHasOnePossibleValue(vector_type.child.toType())) |v| return v;
32924 return null;
32925 },
32926 .opt_type => @panic("TODO"),
3290432927 .error_union_type => @panic("TODO"),
3290532928 .simple_type => |t| switch (t) {
3290632929 .f16,
......@@ -32963,34 +32986,15 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3296332986 .error_set_merged,
3296432987 .error_union,
3296532988 .function,
32966 .single_const_pointer_to_comptime_int,
3296732989 .array_sentinel,
32968 .array_u8_sentinel_0,
32969 .const_slice_u8,
32970 .const_slice_u8_sentinel_0,
32971 .const_slice,
32972 .mut_slice,
32973 .optional_single_mut_pointer,
32974 .optional_single_const_pointer,
32975 .anyerror_void_error_union,
3297632990 .error_set_inferred,
3297732991 .@"opaque",
32978 .manyptr_u8,
32979 .manyptr_const_u8,
32980 .manyptr_const_u8_sentinel_0,
3298132992 .anyframe_T,
32982 .many_const_pointer,
32983 .many_mut_pointer,
32984 .c_const_pointer,
32985 .c_mut_pointer,
32986 .single_const_pointer,
32987 .single_mut_pointer,
3298832993 .pointer,
3298932994 => return null,
3299032995
3299132996 .optional => {
32992 var buf: Type.Payload.ElemType = undefined;
32993 const child_ty = ty.optionalChild(&buf);
32997 const child_ty = ty.optionalChild(mod);
3299432998 if (child_ty.isNoReturn()) {
3299532999 return Value.null;
3299633000 } else {
......@@ -33111,10 +33115,10 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3311133115
3311233116 .empty_struct, .empty_struct_literal => return Value.initTag(.empty_struct_value),
3311333117
33114 .vector, .array, .array_u8 => {
33115 if (ty.arrayLen() == 0)
33118 .array => {
33119 if (ty.arrayLen(mod) == 0)
3311633120 return Value.initTag(.empty_array);
33117 if ((try sema.typeHasOnePossibleValue(ty.elemType())) != null) {
33121 if ((try sema.typeHasOnePossibleValue(ty.childType(mod))) != null) {
3311833122 return Value.initTag(.the_only_possible_value);
3311933123 }
3312033124 return null;
......@@ -33147,20 +33151,13 @@ pub fn addType(sema: *Sema, ty: Type) !Air.Inst.Ref {
3314733151 .data = .{ .interned = ty.ip_index },
3314833152 });
3314933153 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
33154 } else {
33155 try sema.air_instructions.append(sema.gpa, .{
33156 .tag = .const_ty,
33157 .data = .{ .ty = ty },
33158 });
33159 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
3315033160 }
33151 switch (ty.tag()) {
33152 .manyptr_u8 => return .manyptr_u8_type,
33153 .manyptr_const_u8 => return .manyptr_const_u8_type,
33154 .single_const_pointer_to_comptime_int => return .single_const_pointer_to_comptime_int_type,
33155 .const_slice_u8 => return .const_slice_u8_type,
33156 .anyerror_void_error_union => return .anyerror_void_error_union_type,
33157 else => {},
33158 }
33159 try sema.air_instructions.append(sema.gpa, .{
33160 .tag = .const_ty,
33161 .data = .{ .ty = ty },
33162 });
33163 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
3316433161}
3316533162
3316633163fn addIntUnsigned(sema: *Sema, ty: Type, int: u64) CompileError!Air.Inst.Ref {
......@@ -33173,6 +33170,15 @@ fn addConstUndef(sema: *Sema, ty: Type) CompileError!Air.Inst.Ref {
3317333170
3317433171pub fn addConstant(sema: *Sema, ty: Type, val: Value) SemaError!Air.Inst.Ref {
3317533172 const gpa = sema.gpa;
33173 if (val.ip_index != .none) {
33174 if (@enumToInt(val.ip_index) < Air.ref_start_index)
33175 return @intToEnum(Air.Inst.Ref, @enumToInt(val.ip_index));
33176 try sema.air_instructions.append(gpa, .{
33177 .tag = .interned,
33178 .data = .{ .interned = val.ip_index },
33179 });
33180 return Air.indexToRef(@intCast(u32, sema.air_instructions.len - 1));
33181 }
3317633182 const ty_inst = try sema.addType(ty);
3317733183 try sema.air_values.append(gpa, val);
3317833184 try sema.air_instructions.append(gpa, .{
......@@ -33331,7 +33337,8 @@ pub fn analyzeAddressSpace(
3333133337/// Asserts the value is a pointer and dereferences it.
3333233338/// Returns `null` if the pointer contents cannot be loaded at comptime.
3333333339fn pointerDeref(sema: *Sema, block: *Block, src: LazySrcLoc, ptr_val: Value, ptr_ty: Type) CompileError!?Value {
33334 const load_ty = ptr_ty.childType();
33340 const mod = sema.mod;
33341 const load_ty = ptr_ty.childType(mod);
3333533342 const res = try sema.pointerDerefExtra(block, src, ptr_val, load_ty, true);
3333633343 switch (res) {
3333733344 .runtime_load => return null,
......@@ -33422,11 +33429,7 @@ fn usizeCast(sema: *Sema, block: *Block, src: LazySrcLoc, int: u64) CompileError
3342233429/// This can return `error.AnalysisFail` because it sometimes requires resolving whether
3342333430/// a type has zero bits, which can cause a "foo depends on itself" compile error.
3342433431/// This logic must be kept in sync with `Type.isPtrLikeOptional`.
33425fn typePtrOrOptionalPtrTy(
33426 sema: *Sema,
33427 ty: Type,
33428 buf: *Type.Payload.ElemType,
33429) !?Type {
33432fn typePtrOrOptionalPtrTy(sema: *Sema, ty: Type) !?Type {
3343033433 const mod = sema.mod;
3343133434
3343233435 if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {
......@@ -33435,14 +33438,14 @@ fn typePtrOrOptionalPtrTy(
3343533438 .C => return ptr_type.elem_type.toType(),
3343633439 .One, .Many => return ty,
3343733440 },
33438 .optional_type => |o| switch (mod.intern_pool.indexToKey(o.payload_type)) {
33441 .opt_type => |opt_child| switch (mod.intern_pool.indexToKey(opt_child)) {
3343933442 .ptr_type => |ptr_type| switch (ptr_type.size) {
3344033443 .Slice, .C => return null,
3344133444 .Many, .One => {
3344233445 if (ptr_type.is_allowzero) return null;
3344333446
3344433447 // optionals of zero sized types behave like bools, not pointers
33445 const payload_ty = o.payload_type.toType();
33448 const payload_ty = opt_child.toType();
3344633449 if ((try sema.typeHasOnePossibleValue(payload_ty)) != null) {
3344733450 return null;
3344833451 }
......@@ -33456,25 +33459,9 @@ fn typePtrOrOptionalPtrTy(
3345633459 };
3345733460
3345833461 switch (ty.tag()) {
33459 .optional_single_const_pointer,
33460 .optional_single_mut_pointer,
33461 .c_const_pointer,
33462 .c_mut_pointer,
33463 => return ty.optionalChild(buf),
33464
33465 .single_const_pointer_to_comptime_int,
33466 .single_const_pointer,
33467 .single_mut_pointer,
33468 .many_const_pointer,
33469 .many_mut_pointer,
33470 .manyptr_u8,
33471 .manyptr_const_u8,
33472 .manyptr_const_u8_sentinel_0,
33473 => return ty,
33474
33475 .pointer => switch (ty.ptrSize()) {
33462 .pointer => switch (ty.ptrSize(mod)) {
3347633463 .Slice => return null,
33477 .C => return ty.optionalChild(buf),
33464 .C => return ty.optionalChild(mod),
3347833465 else => return ty,
3347933466 },
3348033467
......@@ -33482,10 +33469,10 @@ fn typePtrOrOptionalPtrTy(
3348233469 .inferred_alloc_mut => unreachable,
3348333470
3348433471 .optional => {
33485 const child_type = ty.optionalChild(buf);
33472 const child_type = ty.optionalChild(mod);
3348633473 if (child_type.zigTypeTag(mod) != .Pointer) return null;
3348733474
33488 const info = child_type.ptrInfo().data;
33475 const info = child_type.ptrInfo(mod);
3348933476 switch (info.size) {
3349033477 .Slice, .C => return null,
3349133478 .Many, .One => {
......@@ -33518,8 +33505,8 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3351833505 .int_type => return false,
3351933506 .ptr_type => @panic("TODO"),
3352033507 .array_type => @panic("TODO"),
33521 .vector_type => @panic("TODO"),
33522 .optional_type => @panic("TODO"),
33508 .vector_type => |vector_type| return sema.typeRequiresComptime(vector_type.child.toType()),
33509 .opt_type => @panic("TODO"),
3352333510 .error_union_type => @panic("TODO"),
3352433511 .simple_type => |t| return switch (t) {
3352533512 .f16,
......@@ -33578,12 +33565,6 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3357833565 }
3357933566 }
3358033567 return switch (ty.tag()) {
33581 .manyptr_u8,
33582 .manyptr_const_u8,
33583 .manyptr_const_u8_sentinel_0,
33584 .const_slice_u8,
33585 .const_slice_u8_sentinel_0,
33586 .anyerror_void_error_union,
3358733568 .empty_struct_literal,
3358833569 .empty_struct,
3358933570 .error_set,
......@@ -33591,34 +33572,20 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3359133572 .error_set_inferred,
3359233573 .error_set_merged,
3359333574 .@"opaque",
33594 .array_u8,
33595 .array_u8_sentinel_0,
3359633575 .enum_simple,
3359733576 => false,
3359833577
33599 .single_const_pointer_to_comptime_int,
33600 .function,
33601 => true,
33578 .function => true,
3360233579
3360333580 .inferred_alloc_mut => unreachable,
3360433581 .inferred_alloc_const => unreachable,
3360533582
3360633583 .array,
3360733584 .array_sentinel,
33608 .vector,
33609 => return sema.typeRequiresComptime(ty.childType()),
33585 => return sema.typeRequiresComptime(ty.childType(mod)),
3361033586
33611 .pointer,
33612 .single_const_pointer,
33613 .single_mut_pointer,
33614 .many_const_pointer,
33615 .many_mut_pointer,
33616 .c_const_pointer,
33617 .c_mut_pointer,
33618 .const_slice,
33619 .mut_slice,
33620 => {
33621 const child_ty = ty.childType();
33587 .pointer => {
33588 const child_ty = ty.childType(mod);
3362233589 if (child_ty.zigTypeTag(mod) == .Fn) {
3362333590 return child_ty.fnInfo().is_generic;
3362433591 } else {
......@@ -33626,12 +33593,8 @@ pub fn typeRequiresComptime(sema: *Sema, ty: Type) CompileError!bool {
3362633593 }
3362733594 },
3362833595
33629 .optional,
33630 .optional_single_mut_pointer,
33631 .optional_single_const_pointer,
33632 => {
33633 var buf: Type.Payload.ElemType = undefined;
33634 return sema.typeRequiresComptime(ty.optionalChild(&buf));
33596 .optional => {
33597 return sema.typeRequiresComptime(ty.optionalChild(mod));
3363533598 },
3363633599
3363733600 .tuple, .anon_struct => {
......@@ -33814,7 +33777,7 @@ fn queueFullTypeResolution(sema: *Sema, ty: Type) !void {
3381433777fn intAdd(sema: *Sema, lhs: Value, rhs: Value, ty: Type) !Value {
3381533778 const mod = sema.mod;
3381633779 if (ty.zigTypeTag(mod) == .Vector) {
33817 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
33780 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
3381833781 for (result_data, 0..) |*scalar, i| {
3381933782 var lhs_buf: Value.ElemValueBuffer = undefined;
3382033783 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -33874,7 +33837,7 @@ fn intSub(
3387433837) !Value {
3387533838 const mod = sema.mod;
3387633839 if (ty.zigTypeTag(mod) == .Vector) {
33877 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
33840 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
3387833841 for (result_data, 0..) |*scalar, i| {
3387933842 var lhs_buf: Value.ElemValueBuffer = undefined;
3388033843 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -33934,7 +33897,7 @@ fn floatAdd(
3393433897) !Value {
3393533898 const mod = sema.mod;
3393633899 if (float_type.zigTypeTag(mod) == .Vector) {
33937 const result_data = try sema.arena.alloc(Value, float_type.vectorLen());
33900 const result_data = try sema.arena.alloc(Value, float_type.vectorLen(mod));
3393833901 for (result_data, 0..) |*scalar, i| {
3393933902 var lhs_buf: Value.ElemValueBuffer = undefined;
3394033903 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -33992,7 +33955,7 @@ fn floatSub(
3399233955) !Value {
3399333956 const mod = sema.mod;
3399433957 if (float_type.zigTypeTag(mod) == .Vector) {
33995 const result_data = try sema.arena.alloc(Value, float_type.vectorLen());
33958 const result_data = try sema.arena.alloc(Value, float_type.vectorLen(mod));
3399633959 for (result_data, 0..) |*scalar, i| {
3399733960 var lhs_buf: Value.ElemValueBuffer = undefined;
3399833961 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -34050,8 +34013,8 @@ fn intSubWithOverflow(
3405034013) !Value.OverflowArithmeticResult {
3405134014 const mod = sema.mod;
3405234015 if (ty.zigTypeTag(mod) == .Vector) {
34053 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen());
34054 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
34016 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
34017 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
3405534018 for (result_data, 0..) |*scalar, i| {
3405634019 var lhs_buf: Value.ElemValueBuffer = undefined;
3405734020 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -34105,8 +34068,8 @@ fn floatToInt(
3410534068) CompileError!Value {
3410634069 const mod = sema.mod;
3410734070 if (float_ty.zigTypeTag(mod) == .Vector) {
34108 const elem_ty = float_ty.childType();
34109 const result_data = try sema.arena.alloc(Value, float_ty.vectorLen());
34071 const elem_ty = float_ty.childType(mod);
34072 const result_data = try sema.arena.alloc(Value, float_ty.vectorLen(mod));
3411034073 for (result_data, 0..) |*scalar, i| {
3411134074 var buf: Value.ElemValueBuffer = undefined;
3411234075 const elem_val = val.elemValueBuffer(sema.mod, i, &buf);
......@@ -34383,8 +34346,8 @@ fn intAddWithOverflow(
3438334346) !Value.OverflowArithmeticResult {
3438434347 const mod = sema.mod;
3438534348 if (ty.zigTypeTag(mod) == .Vector) {
34386 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen());
34387 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
34349 const overflowed_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
34350 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
3438834351 for (result_data, 0..) |*scalar, i| {
3438934352 var lhs_buf: Value.ElemValueBuffer = undefined;
3439034353 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -34442,7 +34405,7 @@ fn compareAll(
3444234405 const mod = sema.mod;
3444334406 if (ty.zigTypeTag(mod) == .Vector) {
3444434407 var i: usize = 0;
34445 while (i < ty.vectorLen()) : (i += 1) {
34408 while (i < ty.vectorLen(mod)) : (i += 1) {
3444634409 var lhs_buf: Value.ElemValueBuffer = undefined;
3444734410 var rhs_buf: Value.ElemValueBuffer = undefined;
3444834411 const lhs_elem = lhs.elemValueBuffer(sema.mod, i, &lhs_buf);
......@@ -34490,7 +34453,7 @@ fn compareVector(
3449034453) !Value {
3449134454 const mod = sema.mod;
3449234455 assert(ty.zigTypeTag(mod) == .Vector);
34493 const result_data = try sema.arena.alloc(Value, ty.vectorLen());
34456 const result_data = try sema.arena.alloc(Value, ty.vectorLen(mod));
3449434457 for (result_data, 0..) |*scalar, i| {
3449534458 var lhs_buf: Value.ElemValueBuffer = undefined;
3449634459 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -34511,10 +34474,10 @@ fn compareVector(
3451134474/// This code is duplicated in `analyzePtrArithmetic`.
3451234475fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
3451334476 const mod = sema.mod;
34514 const ptr_info = ptr_ty.ptrInfo().data;
34477 const ptr_info = ptr_ty.ptrInfo(mod);
3451534478 const elem_ty = ptr_ty.elemType2(mod);
3451634479 const allow_zero = ptr_info.@"allowzero" and (offset orelse 0) == 0;
34517 const parent_ty = ptr_ty.childType();
34480 const parent_ty = ptr_ty.childType(mod);
3451834481
3451934482 const VI = Type.Payload.Pointer.Data.VectorIndex;
3452034483
......@@ -34522,14 +34485,14 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
3452234485 host_size: u16 = 0,
3452334486 alignment: u32 = 0,
3452434487 vector_index: VI = .none,
34525 } = if (parent_ty.tag() == .vector and ptr_info.size == .One) blk: {
34488 } = if (parent_ty.isVector(mod) and ptr_info.size == .One) blk: {
3452634489 const elem_bits = elem_ty.bitSize(mod);
3452734490 if (elem_bits == 0) break :blk .{};
3452834491 const is_packed = elem_bits < 8 or !std.math.isPowerOfTwo(elem_bits);
3452934492 if (!is_packed) break :blk .{};
3453034493
3453134494 break :blk .{
34532 .host_size = @intCast(u16, parent_ty.arrayLen()),
34495 .host_size = @intCast(u16, parent_ty.arrayLen(mod)),
3453334496 .alignment = @intCast(u16, parent_ty.abiAlignment(mod)),
3453434497 .vector_index = if (offset) |some| @intToEnum(VI, some) else .runtime,
3453534498 };
src/TypedValue.zig+6-26
......@@ -77,15 +77,6 @@ pub fn print(
7777 return writer.writeAll("(variable)");
7878
7979 while (true) switch (val.tag()) {
80 .single_const_pointer_to_comptime_int_type => return writer.writeAll("*const comptime_int"),
81 .const_slice_u8_type => return writer.writeAll("[]const u8"),
82 .const_slice_u8_sentinel_0_type => return writer.writeAll("[:0]const u8"),
83 .anyerror_void_error_union_type => return writer.writeAll("anyerror!void"),
84
85 .manyptr_u8_type => return writer.writeAll("[*]u8"),
86 .manyptr_const_u8_type => return writer.writeAll("[*]const u8"),
87 .manyptr_const_u8_sentinel_0_type => return writer.writeAll("[*:0]const u8"),
88
8980 .empty_struct_value, .aggregate => {
9081 if (level == 0) {
9182 return writer.writeAll(".{ ... }");
......@@ -112,7 +103,7 @@ pub fn print(
112103 return writer.writeAll("}");
113104 } else {
114105 const elem_ty = ty.elemType2(mod);
115 const len = ty.arrayLen();
106 const len = ty.arrayLen(mod);
116107
117108 if (elem_ty.eql(Type.u8, mod)) str: {
118109 const max_len = @intCast(usize, std.math.min(len, max_string_len));
......@@ -288,7 +279,7 @@ pub fn print(
288279 .ty = ty.elemType2(mod),
289280 .val = val.castTag(.repeated).?.data,
290281 };
291 const len = ty.arrayLen();
282 const len = ty.arrayLen(mod);
292283 const max_len = std.math.min(len, max_aggregate_items);
293284 while (i < max_len) : (i += 1) {
294285 if (i != 0) try writer.writeAll(", ");
......@@ -306,7 +297,7 @@ pub fn print(
306297 try writer.writeAll(".{ ");
307298 try print(.{
308299 .ty = ty.elemType2(mod),
309 .val = ty.sentinel().?,
300 .val = ty.sentinel(mod).?,
310301 }, writer, level - 1, mod);
311302 return writer.writeAll(" }");
312303 },
......@@ -364,8 +355,7 @@ pub fn print(
364355 },
365356 .opt_payload => {
366357 val = val.castTag(.opt_payload).?.data;
367 var buf: Type.Payload.ElemType = undefined;
368 ty = ty.optionalChild(&buf);
358 ty = ty.optionalChild(mod);
369359 return print(.{ .ty = ty, .val = val }, writer, level, mod);
370360 },
371361 .eu_payload_ptr => {
......@@ -386,13 +376,8 @@ pub fn print(
386376
387377 try writer.writeAll(", &(payload of ");
388378
389 var ptr_ty: Type.Payload.ElemType = .{
390 .base = .{ .tag = .single_mut_pointer },
391 .data = data.container_ty,
392 };
393
394379 try print(.{
395 .ty = Type.initPayload(&ptr_ty.base),
380 .ty = mod.singleMutPtrType(data.container_ty) catch @panic("OOM"),
396381 .val = data.container_ptr,
397382 }, writer, level - 1, mod);
398383
......@@ -415,13 +400,8 @@ pub fn print(
415400
416401 try writer.writeAll(", &(payload of ");
417402
418 var ptr_ty: Type.Payload.ElemType = .{
419 .base = .{ .tag = .single_mut_pointer },
420 .data = data.container_ty,
421 };
422
423403 try print(.{
424 .ty = Type.initPayload(&ptr_ty.base),
404 .ty = mod.singleMutPtrType(data.container_ty) catch @panic("OOM"),
425405 .val = data.container_ptr,
426406 }, writer, level - 1, mod);
427407
src/arch/aarch64/CodeGen.zig+32-48
......@@ -1030,7 +1030,7 @@ fn allocMem(
10301030/// Use a pointer instruction as the basis for allocating stack memory.
10311031fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
10321032 const mod = self.bin_file.options.module.?;
1033 const elem_ty = self.typeOfIndex(inst).elemType();
1033 const elem_ty = self.typeOfIndex(inst).childType(mod);
10341034
10351035 if (!elem_ty.hasRuntimeBits(mod)) {
10361036 // return the stack offset 0. Stack offset 0 will be where all
......@@ -1140,17 +1140,14 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void {
11401140}
11411141
11421142fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
1143 const mod = self.bin_file.options.module.?;
11431144 const result: MCValue = switch (self.ret_mcv) {
11441145 .none, .register => .{ .ptr_stack_offset = try self.allocMemPtr(inst) },
11451146 .stack_offset => blk: {
11461147 // self.ret_mcv is an address to where this function
11471148 // should store its result into
11481149 const ret_ty = self.fn_type.fnReturnType();
1149 var ptr_ty_payload: Type.Payload.ElemType = .{
1150 .base = .{ .tag = .single_mut_pointer },
1151 .data = ret_ty,
1152 };
1153 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
1150 const ptr_ty = try mod.singleMutPtrType(ret_ty);
11541151
11551152 // addr_reg will contain the address of where to store the
11561153 // result into
......@@ -2406,9 +2403,9 @@ fn ptrArithmetic(
24062403 assert(rhs_ty.eql(Type.usize, mod));
24072404
24082405 const ptr_ty = lhs_ty;
2409 const elem_ty = switch (ptr_ty.ptrSize()) {
2410 .One => ptr_ty.childType().childType(), // ptr to array, so get array element type
2411 else => ptr_ty.childType(),
2406 const elem_ty = switch (ptr_ty.ptrSize(mod)) {
2407 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
2408 else => ptr_ty.childType(mod),
24122409 };
24132410 const elem_size = elem_ty.abiSize(mod);
24142411
......@@ -3024,8 +3021,7 @@ fn airOptionalPayload(self: *Self, inst: Air.Inst.Index) !void {
30243021
30253022fn optionalPayload(self: *Self, inst: Air.Inst.Index, mcv: MCValue, optional_ty: Type) !MCValue {
30263023 const mod = self.bin_file.options.module.?;
3027 var opt_buf: Type.Payload.ElemType = undefined;
3028 const payload_ty = optional_ty.optionalChild(&opt_buf);
3024 const payload_ty = optional_ty.optionalChild(mod);
30293025 if (!payload_ty.hasRuntimeBits(mod)) return MCValue.none;
30303026 if (optional_ty.isPtrLikeOptional(mod)) {
30313027 // TODO should we reuse the operand here?
......@@ -3459,7 +3455,7 @@ fn ptrElemVal(
34593455 maybe_inst: ?Air.Inst.Index,
34603456) !MCValue {
34613457 const mod = self.bin_file.options.module.?;
3462 const elem_ty = ptr_ty.childType();
3458 const elem_ty = ptr_ty.childType(mod);
34633459 const elem_size = @intCast(u32, elem_ty.abiSize(mod));
34643460
34653461 // TODO optimize for elem_sizes of 1, 2, 4, 8
......@@ -3617,7 +3613,7 @@ fn reuseOperand(
36173613
36183614fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
36193615 const mod = self.bin_file.options.module.?;
3620 const elem_ty = ptr_ty.elemType();
3616 const elem_ty = ptr_ty.childType(mod);
36213617 const elem_size = elem_ty.abiSize(mod);
36223618
36233619 switch (ptr) {
......@@ -3773,7 +3769,7 @@ fn genInlineMemset(
37733769) !void {
37743770 const dst_reg = switch (dst) {
37753771 .register => |r| r,
3776 else => try self.copyToTmpRegister(Type.initTag(.manyptr_u8), dst),
3772 else => try self.copyToTmpRegister(Type.manyptr_u8, dst),
37773773 };
37783774 const dst_reg_lock = self.register_manager.lockReg(dst_reg);
37793775 defer if (dst_reg_lock) |lock| self.register_manager.unlockReg(lock);
......@@ -4096,7 +4092,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
40964092 const mod = self.bin_file.options.module.?;
40974093 const mcv = try self.resolveInst(operand);
40984094 const ptr_ty = self.typeOf(operand);
4099 const struct_ty = ptr_ty.childType();
4095 const struct_ty = ptr_ty.childType(mod);
41004096 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));
41014097 switch (mcv) {
41024098 .ptr_stack_offset => |off| {
......@@ -4173,7 +4169,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
41734169 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
41744170 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
41754171 const field_ptr = try self.resolveInst(extra.field_ptr);
4176 const struct_ty = self.air.getRefType(ty_pl.ty).childType();
4172 const struct_ty = self.air.getRefType(ty_pl.ty).childType(mod);
41774173 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(extra.field_index, mod));
41784174 switch (field_ptr) {
41794175 .ptr_stack_offset => |off| {
......@@ -4254,7 +4250,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42544250
42554251 const fn_ty = switch (ty.zigTypeTag(mod)) {
42564252 .Fn => ty,
4257 .Pointer => ty.childType(),
4253 .Pointer => ty.childType(mod),
42584254 else => unreachable,
42594255 };
42604256
......@@ -4280,11 +4276,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42804276
42814277 const ret_ptr_reg = self.registerAlias(.x0, Type.usize);
42824278
4283 var ptr_ty_payload: Type.Payload.ElemType = .{
4284 .base = .{ .tag = .single_mut_pointer },
4285 .data = ret_ty,
4286 };
4287 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
4279 const ptr_ty = try mod.singleMutPtrType(ret_ty);
42884280 try self.register_manager.getReg(ret_ptr_reg, null);
42894281 try self.genSetReg(ptr_ty, ret_ptr_reg, .{ .ptr_stack_offset = stack_offset });
42904282
......@@ -4453,11 +4445,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44534445 //
44544446 // self.ret_mcv is an address to where this function
44554447 // should store its result into
4456 var ptr_ty_payload: Type.Payload.ElemType = .{
4457 .base = .{ .tag = .single_mut_pointer },
4458 .data = ret_ty,
4459 };
4460 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
4448 const ptr_ty = try mod.singleMutPtrType(ret_ty);
44614449 try self.store(self.ret_mcv, operand, ptr_ty, ret_ty);
44624450 },
44634451 else => unreachable,
......@@ -4533,8 +4521,7 @@ fn cmp(
45334521 const mod = self.bin_file.options.module.?;
45344522 const int_ty = switch (lhs_ty.zigTypeTag(mod)) {
45354523 .Optional => blk: {
4536 var opt_buffer: Type.Payload.ElemType = undefined;
4537 const payload_ty = lhs_ty.optionalChild(&opt_buffer);
4524 const payload_ty = lhs_ty.optionalChild(mod);
45384525 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
45394526 break :blk Type.u1;
45404527 } else if (lhs_ty.isPtrLikeOptional(mod)) {
......@@ -4850,8 +4837,7 @@ fn airCondBr(self: *Self, inst: Air.Inst.Index) !void {
48504837fn isNull(self: *Self, operand_bind: ReadArg.Bind, operand_ty: Type) !MCValue {
48514838 const mod = self.bin_file.options.module.?;
48524839 const sentinel: struct { ty: Type, bind: ReadArg.Bind } = if (!operand_ty.isPtrLikeOptional(mod)) blk: {
4853 var buf: Type.Payload.ElemType = undefined;
4854 const payload_ty = operand_ty.optionalChild(&buf);
4840 const payload_ty = operand_ty.optionalChild(mod);
48554841 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod))
48564842 break :blk .{ .ty = operand_ty, .bind = operand_bind };
48574843
......@@ -4947,11 +4933,12 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
49474933}
49484934
49494935fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4936 const mod = self.bin_file.options.module.?;
49504937 const un_op = self.air.instructions.items(.data)[inst].un_op;
49514938 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49524939 const operand_ptr = try self.resolveInst(un_op);
49534940 const ptr_ty = self.typeOf(un_op);
4954 const elem_ty = ptr_ty.elemType();
4941 const elem_ty = ptr_ty.childType(mod);
49554942
49564943 const operand = try self.allocRegOrMem(elem_ty, true, null);
49574944 try self.load(operand, operand_ptr, ptr_ty);
......@@ -4973,11 +4960,12 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
49734960}
49744961
49754962fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4963 const mod = self.bin_file.options.module.?;
49764964 const un_op = self.air.instructions.items(.data)[inst].un_op;
49774965 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49784966 const operand_ptr = try self.resolveInst(un_op);
49794967 const ptr_ty = self.typeOf(un_op);
4980 const elem_ty = ptr_ty.elemType();
4968 const elem_ty = ptr_ty.childType(mod);
49814969
49824970 const operand = try self.allocRegOrMem(elem_ty, true, null);
49834971 try self.load(operand, operand_ptr, ptr_ty);
......@@ -4999,11 +4987,12 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
49994987}
50004988
50014989fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
4990 const mod = self.bin_file.options.module.?;
50024991 const un_op = self.air.instructions.items(.data)[inst].un_op;
50034992 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
50044993 const operand_ptr = try self.resolveInst(un_op);
50054994 const ptr_ty = self.typeOf(un_op);
5006 const elem_ty = ptr_ty.elemType();
4995 const elem_ty = ptr_ty.childType(mod);
50074996
50084997 const operand = try self.allocRegOrMem(elem_ty, true, null);
50094998 try self.load(operand, operand_ptr, ptr_ty);
......@@ -5025,11 +5014,12 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
50255014}
50265015
50275016fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
5017 const mod = self.bin_file.options.module.?;
50285018 const un_op = self.air.instructions.items(.data)[inst].un_op;
50295019 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
50305020 const operand_ptr = try self.resolveInst(un_op);
50315021 const ptr_ty = self.typeOf(un_op);
5032 const elem_ty = ptr_ty.elemType();
5022 const elem_ty = ptr_ty.childType(mod);
50335023
50345024 const operand = try self.allocRegOrMem(elem_ty, true, null);
50355025 try self.load(operand, operand_ptr, ptr_ty);
......@@ -5511,11 +5501,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
55115501 const reg = try self.copyToTmpRegister(ty, mcv);
55125502 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
55135503 } else {
5514 var ptr_ty_payload: Type.Payload.ElemType = .{
5515 .base = .{ .tag = .single_mut_pointer },
5516 .data = ty,
5517 };
5518 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
5504 const ptr_ty = try mod.singleMutPtrType(ty);
55195505
55205506 // TODO call extern memcpy
55215507 const regs = try self.register_manager.allocRegs(5, .{ null, null, null, null, null }, gp);
......@@ -5833,11 +5819,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
58335819 const reg = try self.copyToTmpRegister(ty, mcv);
58345820 return self.genSetStackArgument(ty, stack_offset, MCValue{ .register = reg });
58355821 } else {
5836 var ptr_ty_payload: Type.Payload.ElemType = .{
5837 .base = .{ .tag = .single_mut_pointer },
5838 .data = ty,
5839 };
5840 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
5822 const ptr_ty = try mod.singleMutPtrType(ty);
58415823
58425824 // TODO call extern memcpy
58435825 const regs = try self.register_manager.allocRegs(5, .{ null, null, null, null, null }, gp);
......@@ -5957,12 +5939,13 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
59575939}
59585940
59595941fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
5942 const mod = self.bin_file.options.module.?;
59605943 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
59615944 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
59625945 const ptr_ty = self.typeOf(ty_op.operand);
59635946 const ptr = try self.resolveInst(ty_op.operand);
5964 const array_ty = ptr_ty.childType();
5965 const array_len = @intCast(u32, array_ty.arrayLen());
5947 const array_ty = ptr_ty.childType(mod);
5948 const array_len = @intCast(u32, array_ty.arrayLen(mod));
59665949
59675950 const ptr_bits = self.target.ptrBitWidth();
59685951 const ptr_bytes = @divExact(ptr_bits, 8);
......@@ -6079,8 +6062,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
60796062}
60806063
60816064fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
6065 const mod = self.bin_file.options.module.?;
60826066 const vector_ty = self.typeOfIndex(inst);
6083 const len = vector_ty.vectorLen();
6067 const len = vector_ty.vectorLen(mod);
60846068 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
60856069 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
60866070 const result: MCValue = res: {
src/arch/arm/CodeGen.zig+33-50
......@@ -1010,7 +1010,7 @@ fn allocMem(
10101010/// Use a pointer instruction as the basis for allocating stack memory.
10111011fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
10121012 const mod = self.bin_file.options.module.?;
1013 const elem_ty = self.typeOfIndex(inst).elemType();
1013 const elem_ty = self.typeOfIndex(inst).childType(mod);
10141014
10151015 if (!elem_ty.hasRuntimeBits(mod)) {
10161016 // As this stack item will never be dereferenced at runtime,
......@@ -1117,17 +1117,14 @@ fn airAlloc(self: *Self, inst: Air.Inst.Index) !void {
11171117}
11181118
11191119fn airRetPtr(self: *Self, inst: Air.Inst.Index) !void {
1120 const mod = self.bin_file.options.module.?;
11201121 const result: MCValue = switch (self.ret_mcv) {
11211122 .none, .register => .{ .ptr_stack_offset = try self.allocMemPtr(inst) },
11221123 .stack_offset => blk: {
11231124 // self.ret_mcv is an address to where this function
11241125 // should store its result into
11251126 const ret_ty = self.fn_type.fnReturnType();
1126 var ptr_ty_payload: Type.Payload.ElemType = .{
1127 .base = .{ .tag = .single_mut_pointer },
1128 .data = ret_ty,
1129 };
1130 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
1127 const ptr_ty = try mod.singleMutPtrType(ret_ty);
11311128
11321129 // addr_reg will contain the address of where to store the
11331130 // result into
......@@ -2372,8 +2369,8 @@ fn ptrElemVal(
23722369 ptr_ty: Type,
23732370 maybe_inst: ?Air.Inst.Index,
23742371) !MCValue {
2375 const elem_ty = ptr_ty.childType();
23762372 const mod = self.bin_file.options.module.?;
2373 const elem_ty = ptr_ty.childType(mod);
23772374 const elem_size = @intCast(u32, elem_ty.abiSize(mod));
23782375
23792376 switch (elem_size) {
......@@ -2474,7 +2471,8 @@ fn arrayElemVal(
24742471 array_ty: Type,
24752472 maybe_inst: ?Air.Inst.Index,
24762473) InnerError!MCValue {
2477 const elem_ty = array_ty.childType();
2474 const mod = self.bin_file.options.module.?;
2475 const elem_ty = array_ty.childType(mod);
24782476
24792477 const mcv = try array_bind.resolveToMcv(self);
24802478 switch (mcv) {
......@@ -2508,11 +2506,7 @@ fn arrayElemVal(
25082506
25092507 const base_bind: ReadArg.Bind = .{ .mcv = ptr_to_mcv };
25102508
2511 var ptr_ty_payload: Type.Payload.ElemType = .{
2512 .base = .{ .tag = .single_mut_pointer },
2513 .data = elem_ty,
2514 };
2515 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
2509 const ptr_ty = try mod.singleMutPtrType(elem_ty);
25162510
25172511 return try self.ptrElemVal(base_bind, index_bind, ptr_ty, maybe_inst);
25182512 },
......@@ -2659,8 +2653,8 @@ fn reuseOperand(
26592653}
26602654
26612655fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
2662 const elem_ty = ptr_ty.elemType();
26632656 const mod = self.bin_file.options.module.?;
2657 const elem_ty = ptr_ty.childType(mod);
26642658 const elem_size = @intCast(u32, elem_ty.abiSize(mod));
26652659
26662660 switch (ptr) {
......@@ -2888,7 +2882,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
28882882 const mod = self.bin_file.options.module.?;
28892883 const mcv = try self.resolveInst(operand);
28902884 const ptr_ty = self.typeOf(operand);
2891 const struct_ty = ptr_ty.childType();
2885 const struct_ty = ptr_ty.childType(mod);
28922886 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));
28932887 switch (mcv) {
28942888 .ptr_stack_offset => |off| {
......@@ -3004,7 +2998,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
30042998 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
30052999 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
30063000 const field_ptr = try self.resolveInst(extra.field_ptr);
3007 const struct_ty = self.air.getRefType(ty_pl.ty).childType();
3001 const struct_ty = self.air.getRefType(ty_pl.ty).childType(mod);
30083002
30093003 if (struct_ty.zigTypeTag(mod) == .Union) {
30103004 return self.fail("TODO implement @fieldParentPtr codegen for unions", .{});
......@@ -3898,9 +3892,9 @@ fn ptrArithmetic(
38983892 assert(rhs_ty.eql(Type.usize, mod));
38993893
39003894 const ptr_ty = lhs_ty;
3901 const elem_ty = switch (ptr_ty.ptrSize()) {
3902 .One => ptr_ty.childType().childType(), // ptr to array, so get array element type
3903 else => ptr_ty.childType(),
3895 const elem_ty = switch (ptr_ty.ptrSize(mod)) {
3896 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
3897 else => ptr_ty.childType(mod),
39043898 };
39053899 const elem_size = @intCast(u32, elem_ty.abiSize(mod));
39063900
......@@ -4079,7 +4073,7 @@ fn genInlineMemset(
40794073) !void {
40804074 const dst_reg = switch (dst) {
40814075 .register => |r| r,
4082 else => try self.copyToTmpRegister(Type.initTag(.manyptr_u8), dst),
4076 else => try self.copyToTmpRegister(Type.manyptr_u8, dst),
40834077 };
40844078 const dst_reg_lock = self.register_manager.lockReg(dst_reg);
40854079 defer if (dst_reg_lock) |lock| self.register_manager.unlockReg(lock);
......@@ -4229,7 +4223,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42294223
42304224 const fn_ty = switch (ty.zigTypeTag(mod)) {
42314225 .Fn => ty,
4232 .Pointer => ty.childType(),
4226 .Pointer => ty.childType(mod),
42334227 else => unreachable,
42344228 };
42354229
......@@ -4259,11 +4253,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
42594253 const ret_abi_align = @intCast(u32, ret_ty.abiAlignment(mod));
42604254 const stack_offset = try self.allocMem(ret_abi_size, ret_abi_align, inst);
42614255
4262 var ptr_ty_payload: Type.Payload.ElemType = .{
4263 .base = .{ .tag = .single_mut_pointer },
4264 .data = ret_ty,
4265 };
4266 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
4256 const ptr_ty = try mod.singleMutPtrType(ret_ty);
42674257 try self.register_manager.getReg(.r0, null);
42684258 try self.genSetReg(ptr_ty, .r0, .{ .ptr_stack_offset = stack_offset });
42694259
......@@ -4401,11 +4391,7 @@ fn airRet(self: *Self, inst: Air.Inst.Index) !void {
44014391 //
44024392 // self.ret_mcv is an address to where this function
44034393 // should store its result into
4404 var ptr_ty_payload: Type.Payload.ElemType = .{
4405 .base = .{ .tag = .single_mut_pointer },
4406 .data = ret_ty,
4407 };
4408 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
4394 const ptr_ty = try mod.singleMutPtrType(ret_ty);
44094395 try self.store(self.ret_mcv, operand, ptr_ty, ret_ty);
44104396 },
44114397 else => unreachable, // invalid return result
......@@ -4482,8 +4468,7 @@ fn cmp(
44824468 const mod = self.bin_file.options.module.?;
44834469 const int_ty = switch (lhs_ty.zigTypeTag(mod)) {
44844470 .Optional => blk: {
4485 var opt_buffer: Type.Payload.ElemType = undefined;
4486 const payload_ty = lhs_ty.optionalChild(&opt_buffer);
4471 const payload_ty = lhs_ty.optionalChild(mod);
44874472 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
44884473 break :blk Type.u1;
44894474 } else if (lhs_ty.isPtrLikeOptional(mod)) {
......@@ -4837,11 +4822,12 @@ fn airIsNull(self: *Self, inst: Air.Inst.Index) !void {
48374822}
48384823
48394824fn airIsNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4825 const mod = self.bin_file.options.module.?;
48404826 const un_op = self.air.instructions.items(.data)[inst].un_op;
48414827 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
48424828 const operand_ptr = try self.resolveInst(un_op);
48434829 const ptr_ty = self.typeOf(un_op);
4844 const elem_ty = ptr_ty.elemType();
4830 const elem_ty = ptr_ty.childType(mod);
48454831
48464832 const operand = try self.allocRegOrMem(elem_ty, true, null);
48474833 try self.load(operand, operand_ptr, ptr_ty);
......@@ -4863,11 +4849,12 @@ fn airIsNonNull(self: *Self, inst: Air.Inst.Index) !void {
48634849}
48644850
48654851fn airIsNonNullPtr(self: *Self, inst: Air.Inst.Index) !void {
4852 const mod = self.bin_file.options.module.?;
48664853 const un_op = self.air.instructions.items(.data)[inst].un_op;
48674854 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
48684855 const operand_ptr = try self.resolveInst(un_op);
48694856 const ptr_ty = self.typeOf(un_op);
4870 const elem_ty = ptr_ty.elemType();
4857 const elem_ty = ptr_ty.childType(mod);
48714858
48724859 const operand = try self.allocRegOrMem(elem_ty, true, null);
48734860 try self.load(operand, operand_ptr, ptr_ty);
......@@ -4924,11 +4911,12 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
49244911}
49254912
49264913fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
4914 const mod = self.bin_file.options.module.?;
49274915 const un_op = self.air.instructions.items(.data)[inst].un_op;
49284916 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49294917 const operand_ptr = try self.resolveInst(un_op);
49304918 const ptr_ty = self.typeOf(un_op);
4931 const elem_ty = ptr_ty.elemType();
4919 const elem_ty = ptr_ty.childType(mod);
49324920
49334921 const operand = try self.allocRegOrMem(elem_ty, true, null);
49344922 try self.load(operand, operand_ptr, ptr_ty);
......@@ -4950,11 +4938,12 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
49504938}
49514939
49524940fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
4941 const mod = self.bin_file.options.module.?;
49534942 const un_op = self.air.instructions.items(.data)[inst].un_op;
49544943 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
49554944 const operand_ptr = try self.resolveInst(un_op);
49564945 const ptr_ty = self.typeOf(un_op);
4957 const elem_ty = ptr_ty.elemType();
4946 const elem_ty = ptr_ty.childType(mod);
49584947
49594948 const operand = try self.allocRegOrMem(elem_ty, true, null);
49604949 try self.load(operand, operand_ptr, ptr_ty);
......@@ -5455,11 +5444,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
54555444 const reg = try self.copyToTmpRegister(ty, mcv);
54565445 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
54575446 } else {
5458 var ptr_ty_payload: Type.Payload.ElemType = .{
5459 .base = .{ .tag = .single_mut_pointer },
5460 .data = ty,
5461 };
5462 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
5447 const ptr_ty = try mod.singleMutPtrType(ty);
54635448
54645449 // TODO call extern memcpy
54655450 const regs = try self.register_manager.allocRegs(5, .{ null, null, null, null, null }, gp);
......@@ -5816,11 +5801,7 @@ fn genSetStackArgument(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) I
58165801 const reg = try self.copyToTmpRegister(ty, mcv);
58175802 return self.genSetStackArgument(ty, stack_offset, MCValue{ .register = reg });
58185803 } else {
5819 var ptr_ty_payload: Type.Payload.ElemType = .{
5820 .base = .{ .tag = .single_mut_pointer },
5821 .data = ty,
5822 };
5823 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
5804 const ptr_ty = try mod.singleMutPtrType(ty);
58245805
58255806 // TODO call extern memcpy
58265807 const regs = try self.register_manager.allocRegs(5, .{ null, null, null, null, null }, gp);
......@@ -5908,12 +5889,13 @@ fn airBitCast(self: *Self, inst: Air.Inst.Index) !void {
59085889}
59095890
59105891fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
5892 const mod = self.bin_file.options.module.?;
59115893 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
59125894 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
59135895 const ptr_ty = self.typeOf(ty_op.operand);
59145896 const ptr = try self.resolveInst(ty_op.operand);
5915 const array_ty = ptr_ty.childType();
5916 const array_len = @intCast(u32, array_ty.arrayLen());
5897 const array_ty = ptr_ty.childType(mod);
5898 const array_len = @intCast(u32, array_ty.arrayLen(mod));
59175899
59185900 const stack_offset = try self.allocMem(8, 8, inst);
59195901 try self.genSetStack(ptr_ty, stack_offset, ptr);
......@@ -6026,8 +6008,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
60266008}
60276009
60286010fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
6011 const mod = self.bin_file.options.module.?;
60296012 const vector_ty = self.typeOfIndex(inst);
6030 const len = vector_ty.vectorLen();
6013 const len = vector_ty.vectorLen(mod);
60316014 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
60326015 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
60336016 const result: MCValue = res: {
src/arch/riscv64/CodeGen.zig+8-6
......@@ -807,7 +807,7 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: u32) !u
807807/// Use a pointer instruction as the basis for allocating stack memory.
808808fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
809809 const mod = self.bin_file.options.module.?;
810 const elem_ty = self.typeOfIndex(inst).elemType();
810 const elem_ty = self.typeOfIndex(inst).childType(mod);
811811 const abi_size = math.cast(u32, elem_ty.abiSize(mod)) orelse {
812812 return self.fail("type '{}' too big to fit into stack frame", .{elem_ty.fmt(mod)});
813813 };
......@@ -1099,9 +1099,9 @@ fn binOp(
10991099 switch (lhs_ty.zigTypeTag(mod)) {
11001100 .Pointer => {
11011101 const ptr_ty = lhs_ty;
1102 const elem_ty = switch (ptr_ty.ptrSize()) {
1103 .One => ptr_ty.childType().childType(), // ptr to array, so get array element type
1104 else => ptr_ty.childType(),
1102 const elem_ty = switch (ptr_ty.ptrSize(mod)) {
1103 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
1104 else => ptr_ty.childType(mod),
11051105 };
11061106 const elem_size = elem_ty.abiSize(mod);
11071107
......@@ -1502,7 +1502,8 @@ fn reuseOperand(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, op_ind
15021502}
15031503
15041504fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
1505 const elem_ty = ptr_ty.elemType();
1505 const mod = self.bin_file.options.module.?;
1506 const elem_ty = ptr_ty.childType(mod);
15061507 switch (ptr) {
15071508 .none => unreachable,
15081509 .undef => unreachable,
......@@ -2496,8 +2497,9 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
24962497}
24972498
24982499fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
2500 const mod = self.bin_file.options.module.?;
24992501 const vector_ty = self.typeOfIndex(inst);
2500 const len = vector_ty.vectorLen();
2502 const len = vector_ty.vectorLen(mod);
25012503 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
25022504 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
25032505 const result: MCValue = res: {
src/arch/sparc64/CodeGen.zig+17-20
......@@ -838,8 +838,9 @@ fn airAddSubWithOverflow(self: *Self, inst: Air.Inst.Index) !void {
838838}
839839
840840fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
841 const mod = self.bin_file.options.module.?;
841842 const vector_ty = self.typeOfIndex(inst);
842 const len = vector_ty.vectorLen();
843 const len = vector_ty.vectorLen(mod);
843844 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
844845 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
845846 const result: MCValue = res: {
......@@ -871,12 +872,13 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
871872}
872873
873874fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
875 const mod = self.bin_file.options.module.?;
874876 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
875877 const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: {
876878 const ptr_ty = self.typeOf(ty_op.operand);
877879 const ptr = try self.resolveInst(ty_op.operand);
878 const array_ty = ptr_ty.childType();
879 const array_len = @intCast(u32, array_ty.arrayLen());
880 const array_ty = ptr_ty.childType(mod);
881 const array_len = @intCast(u32, array_ty.arrayLen(mod));
880882
881883 const ptr_bits = self.target.ptrBitWidth();
882884 const ptr_bytes = @divExact(ptr_bits, 8);
......@@ -1300,7 +1302,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
13001302 const mod = self.bin_file.options.module.?;
13011303 const fn_ty = switch (ty.zigTypeTag(mod)) {
13021304 .Fn => ty,
1303 .Pointer => ty.childType(),
1305 .Pointer => ty.childType(mod),
13041306 else => unreachable,
13051307 };
13061308
......@@ -1440,8 +1442,7 @@ fn airCmp(self: *Self, inst: Air.Inst.Index, op: math.CompareOperator) !void {
14401442 .Pointer => Type.usize,
14411443 .ErrorSet => Type.u16,
14421444 .Optional => blk: {
1443 var opt_buffer: Type.Payload.ElemType = undefined;
1444 const payload_ty = lhs_ty.optionalChild(&opt_buffer);
1445 const payload_ty = lhs_ty.optionalChild(mod);
14451446 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
14461447 break :blk Type.u1;
14471448 } else if (lhs_ty.isPtrLikeOptional(mod)) {
......@@ -2447,6 +2448,7 @@ fn airSlice(self: *Self, inst: Air.Inst.Index) !void {
24472448}
24482449
24492450fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
2451 const mod = self.bin_file.options.module.?;
24502452 const is_volatile = false; // TODO
24512453 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
24522454
......@@ -2456,8 +2458,7 @@ fn airSliceElemVal(self: *Self, inst: Air.Inst.Index) !void {
24562458 const index_mcv = try self.resolveInst(bin_op.rhs);
24572459
24582460 const slice_ty = self.typeOf(bin_op.lhs);
2459 const elem_ty = slice_ty.childType();
2460 const mod = self.bin_file.options.module.?;
2461 const elem_ty = slice_ty.childType(mod);
24612462 const elem_size = elem_ty.abiSize(mod);
24622463
24632464 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
......@@ -2797,7 +2798,7 @@ fn allocMem(self: *Self, inst: Air.Inst.Index, abi_size: u32, abi_align: u32) !u
27972798/// Use a pointer instruction as the basis for allocating stack memory.
27982799fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !u32 {
27992800 const mod = self.bin_file.options.module.?;
2800 const elem_ty = self.typeOfIndex(inst).elemType();
2801 const elem_ty = self.typeOfIndex(inst).childType(mod);
28012802
28022803 if (!elem_ty.hasRuntimeBits(mod)) {
28032804 // As this stack item will never be dereferenced at runtime,
......@@ -3001,9 +3002,9 @@ fn binOp(
30013002 switch (lhs_ty.zigTypeTag(mod)) {
30023003 .Pointer => {
30033004 const ptr_ty = lhs_ty;
3004 const elem_ty = switch (ptr_ty.ptrSize()) {
3005 .One => ptr_ty.childType().childType(), // ptr to array, so get array element type
3006 else => ptr_ty.childType(),
3005 const elem_ty = switch (ptr_ty.ptrSize(mod)) {
3006 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
3007 else => ptr_ty.childType(mod),
30073008 };
30083009 const elem_size = elem_ty.abiSize(mod);
30093010
......@@ -3019,7 +3020,7 @@ fn binOp(
30193020 // multiplying it with elem_size
30203021
30213022 const offset = try self.binOp(.mul, rhs, .{ .immediate = elem_size }, Type.usize, Type.usize, null);
3022 const addr = try self.binOp(tag, lhs, offset, Type.initTag(.manyptr_u8), Type.usize, null);
3023 const addr = try self.binOp(tag, lhs, offset, Type.manyptr_u8, Type.usize, null);
30233024 return addr;
30243025 }
30253026 },
......@@ -4042,11 +4043,7 @@ fn genSetStack(self: *Self, ty: Type, stack_offset: u32, mcv: MCValue) InnerErro
40424043 const reg = try self.copyToTmpRegister(ty, mcv);
40434044 return self.genSetStack(ty, stack_offset, MCValue{ .register = reg });
40444045 } else {
4045 var ptr_ty_payload: Type.Payload.ElemType = .{
4046 .base = .{ .tag = .single_mut_pointer },
4047 .data = ty,
4048 };
4049 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
4046 const ptr_ty = try mod.singleMutPtrType(ty);
40504047
40514048 const regs = try self.register_manager.allocRegs(4, .{ null, null, null, null }, gp);
40524049 const regs_locks = self.register_manager.lockRegsAssumeUnused(4, regs);
......@@ -4269,7 +4266,7 @@ fn jump(self: *Self, inst: Mir.Inst.Index) !void {
42694266
42704267fn load(self: *Self, dst_mcv: MCValue, ptr: MCValue, ptr_ty: Type) InnerError!void {
42714268 const mod = self.bin_file.options.module.?;
4272 const elem_ty = ptr_ty.elemType();
4269 const elem_ty = ptr_ty.childType(mod);
42734270 const elem_size = elem_ty.abiSize(mod);
42744271
42754272 switch (ptr) {
......@@ -4729,7 +4726,7 @@ fn structFieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, inde
47294726 const mod = self.bin_file.options.module.?;
47304727 const mcv = try self.resolveInst(operand);
47314728 const ptr_ty = self.typeOf(operand);
4732 const struct_ty = ptr_ty.childType();
4729 const struct_ty = ptr_ty.childType(mod);
47334730 const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(index, mod));
47344731 switch (mcv) {
47354732 .ptr_stack_offset => |off| {
src/arch/wasm/CodeGen.zig+80-88
......@@ -1542,7 +1542,7 @@ fn allocStack(func: *CodeGen, ty: Type) !WValue {
15421542fn allocStackPtr(func: *CodeGen, inst: Air.Inst.Index) !WValue {
15431543 const mod = func.bin_file.base.options.module.?;
15441544 const ptr_ty = func.typeOfIndex(inst);
1545 const pointee_ty = ptr_ty.childType();
1545 const pointee_ty = ptr_ty.childType(mod);
15461546
15471547 if (func.initial_stack_value == .none) {
15481548 try func.initializeStack();
......@@ -1766,8 +1766,7 @@ fn isByRef(ty: Type, mod: *const Module) bool {
17661766 },
17671767 .Optional => {
17681768 if (ty.isPtrLikeOptional(mod)) return false;
1769 var buf: Type.Payload.ElemType = undefined;
1770 const pl_type = ty.optionalChild(&buf);
1769 const pl_type = ty.optionalChild(mod);
17711770 if (pl_type.zigTypeTag(mod) == .ErrorSet) return false;
17721771 return pl_type.hasRuntimeBitsIgnoreComptime(mod);
17731772 },
......@@ -2139,7 +2138,7 @@ fn airRet(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21392138
21402139fn airRetPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21412140 const mod = func.bin_file.base.options.module.?;
2142 const child_type = func.typeOfIndex(inst).childType();
2141 const child_type = func.typeOfIndex(inst).childType(mod);
21432142
21442143 var result = result: {
21452144 if (!child_type.isFnOrHasRuntimeBitsIgnoreComptime(mod)) {
......@@ -2161,7 +2160,7 @@ fn airRetLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
21612160 const mod = func.bin_file.base.options.module.?;
21622161 const un_op = func.air.instructions.items(.data)[inst].un_op;
21632162 const operand = try func.resolveInst(un_op);
2164 const ret_ty = func.typeOf(un_op).childType();
2163 const ret_ty = func.typeOf(un_op).childType(mod);
21652164
21662165 const fn_info = func.decl.ty.fnInfo();
21672166 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -2188,7 +2187,7 @@ fn airCall(func: *CodeGen, inst: Air.Inst.Index, modifier: std.builtin.CallModif
21882187 const mod = func.bin_file.base.options.module.?;
21892188 const fn_ty = switch (ty.zigTypeTag(mod)) {
21902189 .Fn => ty,
2191 .Pointer => ty.childType(),
2190 .Pointer => ty.childType(mod),
21922191 else => unreachable,
21932192 };
21942193 const ret_ty = fn_ty.fnReturnType();
......@@ -2301,8 +2300,8 @@ fn airStore(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
23012300 const lhs = try func.resolveInst(bin_op.lhs);
23022301 const rhs = try func.resolveInst(bin_op.rhs);
23032302 const ptr_ty = func.typeOf(bin_op.lhs);
2304 const ptr_info = ptr_ty.ptrInfo().data;
2305 const ty = ptr_ty.childType();
2303 const ptr_info = ptr_ty.ptrInfo(mod);
2304 const ty = ptr_ty.childType(mod);
23062305
23072306 if (ptr_info.host_size == 0) {
23082307 try func.store(lhs, rhs, ty, 0);
......@@ -2360,8 +2359,7 @@ fn store(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, offset: u32) InnerE
23602359 if (ty.isPtrLikeOptional(mod)) {
23612360 return func.store(lhs, rhs, Type.usize, 0);
23622361 }
2363 var buf: Type.Payload.ElemType = undefined;
2364 const pl_ty = ty.optionalChild(&buf);
2362 const pl_ty = ty.optionalChild(mod);
23652363 if (!pl_ty.hasRuntimeBitsIgnoreComptime(mod)) {
23662364 return func.store(lhs, rhs, Type.u8, 0);
23672365 }
......@@ -2454,7 +2452,7 @@ fn airLoad(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
24542452 const operand = try func.resolveInst(ty_op.operand);
24552453 const ty = func.air.getRefType(ty_op.ty);
24562454 const ptr_ty = func.typeOf(ty_op.operand);
2457 const ptr_info = ptr_ty.ptrInfo().data;
2455 const ptr_info = ptr_ty.ptrInfo(mod);
24582456
24592457 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) return func.finishAir(inst, .none, &.{ty_op.operand});
24602458
......@@ -2971,7 +2969,7 @@ fn lowerParentPtr(func: *CodeGen, ptr_val: Value, offset: u32) InnerError!WValue
29712969 break :blk field_offset;
29722970 },
29732971 },
2974 .Pointer => switch (parent_ty.ptrSize()) {
2972 .Pointer => switch (parent_ty.ptrSize(mod)) {
29752973 .Slice => switch (field_ptr.field_index) {
29762974 0 => 0,
29772975 1 => func.ptrSize(),
......@@ -3001,11 +2999,7 @@ fn lowerParentPtrDecl(func: *CodeGen, ptr_val: Value, decl_index: Module.Decl.In
30012999 const mod = func.bin_file.base.options.module.?;
30023000 const decl = mod.declPtr(decl_index);
30033001 mod.markDeclAlive(decl);
3004 var ptr_ty_payload: Type.Payload.ElemType = .{
3005 .base = .{ .tag = .single_mut_pointer },
3006 .data = decl.ty,
3007 };
3008 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
3002 const ptr_ty = try mod.singleMutPtrType(decl.ty);
30093003 return func.lowerDeclRefValue(.{ .ty = ptr_ty, .val = ptr_val }, decl_index, offset);
30103004}
30113005
......@@ -3145,8 +3139,7 @@ fn lowerConstant(func: *CodeGen, arg_val: Value, ty: Type) InnerError!WValue {
31453139 return func.fail("Wasm TODO: lowerConstant error union with non-zero-bit payload type", .{});
31463140 },
31473141 .Optional => if (ty.optionalReprIsPayload(mod)) {
3148 var buf: Type.Payload.ElemType = undefined;
3149 const pl_ty = ty.optionalChild(&buf);
3142 const pl_ty = ty.optionalChild(mod);
31503143 if (val.castTag(.opt_payload)) |payload| {
31513144 return func.lowerConstant(payload.data, pl_ty);
31523145 } else if (val.isNull(mod)) {
......@@ -3217,8 +3210,7 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
32173210 else => unreachable,
32183211 },
32193212 .Optional => {
3220 var buf: Type.Payload.ElemType = undefined;
3221 const pl_ty = ty.optionalChild(&buf);
3213 const pl_ty = ty.optionalChild(mod);
32223214 if (ty.optionalReprIsPayload(mod)) {
32233215 return func.emitUndefined(pl_ty);
32243216 }
......@@ -3403,8 +3395,7 @@ fn cmp(func: *CodeGen, lhs: WValue, rhs: WValue, ty: Type, op: std.math.CompareO
34033395 assert(!(lhs != .stack and rhs == .stack));
34043396 const mod = func.bin_file.base.options.module.?;
34053397 if (ty.zigTypeTag(mod) == .Optional and !ty.optionalReprIsPayload(mod)) {
3406 var buf: Type.Payload.ElemType = undefined;
3407 const payload_ty = ty.optionalChild(&buf);
3398 const payload_ty = ty.optionalChild(mod);
34083399 if (payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
34093400 // When we hit this case, we must check the value of optionals
34103401 // that are not pointers. This means first checking against non-null for
......@@ -3609,19 +3600,21 @@ fn bitcast(func: *CodeGen, wanted_ty: Type, given_ty: Type, operand: WValue) Inn
36093600}
36103601
36113602fn airStructFieldPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3603 const mod = func.bin_file.base.options.module.?;
36123604 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
36133605 const extra = func.air.extraData(Air.StructField, ty_pl.payload);
36143606
36153607 const struct_ptr = try func.resolveInst(extra.data.struct_operand);
3616 const struct_ty = func.typeOf(extra.data.struct_operand).childType();
3608 const struct_ty = func.typeOf(extra.data.struct_operand).childType(mod);
36173609 const result = try func.structFieldPtr(inst, extra.data.struct_operand, struct_ptr, struct_ty, extra.data.field_index);
36183610 func.finishAir(inst, result, &.{extra.data.struct_operand});
36193611}
36203612
36213613fn airStructFieldPtrIndex(func: *CodeGen, inst: Air.Inst.Index, index: u32) InnerError!void {
3614 const mod = func.bin_file.base.options.module.?;
36223615 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
36233616 const struct_ptr = try func.resolveInst(ty_op.operand);
3624 const struct_ty = func.typeOf(ty_op.operand).childType();
3617 const struct_ty = func.typeOf(ty_op.operand).childType(mod);
36253618
36263619 const result = try func.structFieldPtr(inst, ty_op.operand, struct_ptr, struct_ty, index);
36273620 func.finishAir(inst, result, &.{ty_op.operand});
......@@ -3640,7 +3633,7 @@ fn structFieldPtr(
36403633 const offset = switch (struct_ty.containerLayout()) {
36413634 .Packed => switch (struct_ty.zigTypeTag(mod)) {
36423635 .Struct => offset: {
3643 if (result_ty.ptrInfo().data.host_size != 0) {
3636 if (result_ty.ptrInfo(mod).host_size != 0) {
36443637 break :offset @as(u32, 0);
36453638 }
36463639 break :offset struct_ty.packedStructFieldByteOffset(index, mod);
......@@ -3981,7 +3974,7 @@ fn airUnwrapErrUnionPayload(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: boo
39813974
39823975 const operand = try func.resolveInst(ty_op.operand);
39833976 const op_ty = func.typeOf(ty_op.operand);
3984 const err_ty = if (op_is_ptr) op_ty.childType() else op_ty;
3977 const err_ty = if (op_is_ptr) op_ty.childType(mod) else op_ty;
39853978 const payload_ty = err_ty.errorUnionPayload();
39863979
39873980 const result = result: {
......@@ -4009,7 +4002,7 @@ fn airUnwrapErrUnionError(func: *CodeGen, inst: Air.Inst.Index, op_is_ptr: bool)
40094002
40104003 const operand = try func.resolveInst(ty_op.operand);
40114004 const op_ty = func.typeOf(ty_op.operand);
4012 const err_ty = if (op_is_ptr) op_ty.childType() else op_ty;
4005 const err_ty = if (op_is_ptr) op_ty.childType(mod) else op_ty;
40134006 const payload_ty = err_ty.errorUnionPayload();
40144007
40154008 const result = result: {
......@@ -4156,11 +4149,12 @@ fn intcast(func: *CodeGen, operand: WValue, given: Type, wanted: Type) InnerErro
41564149}
41574150
41584151fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind: enum { value, ptr }) InnerError!void {
4152 const mod = func.bin_file.base.options.module.?;
41594153 const un_op = func.air.instructions.items(.data)[inst].un_op;
41604154 const operand = try func.resolveInst(un_op);
41614155
41624156 const op_ty = func.typeOf(un_op);
4163 const optional_ty = if (op_kind == .ptr) op_ty.childType() else op_ty;
4157 const optional_ty = if (op_kind == .ptr) op_ty.childType(mod) else op_ty;
41644158 const is_null = try func.isNull(operand, optional_ty, opcode);
41654159 const result = try is_null.toLocal(func, optional_ty);
41664160 func.finishAir(inst, result, &.{un_op});
......@@ -4171,8 +4165,7 @@ fn airIsNull(func: *CodeGen, inst: Air.Inst.Index, opcode: wasm.Opcode, op_kind:
41714165fn isNull(func: *CodeGen, operand: WValue, optional_ty: Type, opcode: wasm.Opcode) InnerError!WValue {
41724166 const mod = func.bin_file.base.options.module.?;
41734167 try func.emitWValue(operand);
4174 var buf: Type.Payload.ElemType = undefined;
4175 const payload_ty = optional_ty.optionalChild(&buf);
4168 const payload_ty = optional_ty.optionalChild(mod);
41764169 if (!optional_ty.optionalReprIsPayload(mod)) {
41774170 // When payload is zero-bits, we can treat operand as a value, rather than
41784171 // a pointer to the stack value
......@@ -4221,14 +4214,13 @@ fn airOptionalPayload(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
42214214}
42224215
42234216fn airOptionalPayloadPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4217 const mod = func.bin_file.base.options.module.?;
42244218 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
42254219 const operand = try func.resolveInst(ty_op.operand);
4226 const opt_ty = func.typeOf(ty_op.operand).childType();
4220 const opt_ty = func.typeOf(ty_op.operand).childType(mod);
42274221
4228 const mod = func.bin_file.base.options.module.?;
42294222 const result = result: {
4230 var buf: Type.Payload.ElemType = undefined;
4231 const payload_ty = opt_ty.optionalChild(&buf);
4223 const payload_ty = opt_ty.optionalChild(mod);
42324224 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod) or opt_ty.optionalReprIsPayload(mod)) {
42334225 break :result func.reuseOperand(ty_op.operand, operand);
42344226 }
......@@ -4242,9 +4234,8 @@ fn airOptionalPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
42424234 const mod = func.bin_file.base.options.module.?;
42434235 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
42444236 const operand = try func.resolveInst(ty_op.operand);
4245 const opt_ty = func.typeOf(ty_op.operand).childType();
4246 var buf: Type.Payload.ElemType = undefined;
4247 const payload_ty = opt_ty.optionalChild(&buf);
4237 const opt_ty = func.typeOf(ty_op.operand).childType(mod);
4238 const payload_ty = opt_ty.optionalChild(mod);
42484239 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
42494240 return func.fail("TODO: Implement OptionalPayloadPtrSet for optional with zero-sized type {}", .{payload_ty.fmtDebug()});
42504241 }
......@@ -4325,13 +4316,13 @@ fn airSliceLen(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43254316}
43264317
43274318fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4319 const mod = func.bin_file.base.options.module.?;
43284320 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
43294321
43304322 const slice_ty = func.typeOf(bin_op.lhs);
43314323 const slice = try func.resolveInst(bin_op.lhs);
43324324 const index = try func.resolveInst(bin_op.rhs);
4333 const elem_ty = slice_ty.childType();
4334 const mod = func.bin_file.base.options.module.?;
4325 const elem_ty = slice_ty.childType(mod);
43354326 const elem_size = elem_ty.abiSize(mod);
43364327
43374328 // load pointer onto stack
......@@ -4355,11 +4346,11 @@ fn airSliceElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
43554346}
43564347
43574348fn airSliceElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4349 const mod = func.bin_file.base.options.module.?;
43584350 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
43594351 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
43604352
4361 const elem_ty = func.air.getRefType(ty_pl.ty).childType();
4362 const mod = func.bin_file.base.options.module.?;
4353 const elem_ty = func.air.getRefType(ty_pl.ty).childType(mod);
43634354 const elem_size = elem_ty.abiSize(mod);
43644355
43654356 const slice = try func.resolveInst(bin_op.lhs);
......@@ -4436,7 +4427,7 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44364427 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
44374428
44384429 const operand = try func.resolveInst(ty_op.operand);
4439 const array_ty = func.typeOf(ty_op.operand).childType();
4430 const array_ty = func.typeOf(ty_op.operand).childType(mod);
44404431 const slice_ty = func.air.getRefType(ty_op.ty);
44414432
44424433 // create a slice on the stack
......@@ -4448,7 +4439,7 @@ fn airArrayToSlice(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44484439 }
44494440
44504441 // store the length of the array in the slice
4451 const len = WValue{ .imm32 = @intCast(u32, array_ty.arrayLen()) };
4442 const len = WValue{ .imm32 = @intCast(u32, array_ty.arrayLen(mod)) };
44524443 try func.store(slice_local, len, Type.usize, func.ptrSize());
44534444
44544445 func.finishAir(inst, slice_local, &.{ty_op.operand});
......@@ -4470,13 +4461,13 @@ fn airPtrToInt(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
44704461}
44714462
44724463fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4464 const mod = func.bin_file.base.options.module.?;
44734465 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
44744466
44754467 const ptr_ty = func.typeOf(bin_op.lhs);
44764468 const ptr = try func.resolveInst(bin_op.lhs);
44774469 const index = try func.resolveInst(bin_op.rhs);
4478 const elem_ty = ptr_ty.childType();
4479 const mod = func.bin_file.base.options.module.?;
4470 const elem_ty = ptr_ty.childType(mod);
44804471 const elem_size = elem_ty.abiSize(mod);
44814472
44824473 // load pointer onto the stack
......@@ -4507,12 +4498,12 @@ fn airPtrElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
45074498}
45084499
45094500fn airPtrElemPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4501 const mod = func.bin_file.base.options.module.?;
45104502 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
45114503 const bin_op = func.air.extraData(Air.Bin, ty_pl.payload).data;
45124504
45134505 const ptr_ty = func.typeOf(bin_op.lhs);
4514 const elem_ty = func.air.getRefType(ty_pl.ty).childType();
4515 const mod = func.bin_file.base.options.module.?;
4506 const elem_ty = func.air.getRefType(ty_pl.ty).childType(mod);
45164507 const elem_size = elem_ty.abiSize(mod);
45174508
45184509 const ptr = try func.resolveInst(bin_op.lhs);
......@@ -4544,9 +4535,9 @@ fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
45444535 const ptr = try func.resolveInst(bin_op.lhs);
45454536 const offset = try func.resolveInst(bin_op.rhs);
45464537 const ptr_ty = func.typeOf(bin_op.lhs);
4547 const pointee_ty = switch (ptr_ty.ptrSize()) {
4548 .One => ptr_ty.childType().childType(), // ptr to array, so get array element type
4549 else => ptr_ty.childType(),
4538 const pointee_ty = switch (ptr_ty.ptrSize(mod)) {
4539 .One => ptr_ty.childType(mod).childType(mod), // ptr to array, so get array element type
4540 else => ptr_ty.childType(mod),
45504541 };
45514542
45524543 const valtype = typeToValtype(Type.usize, mod);
......@@ -4565,6 +4556,7 @@ fn airPtrBinOp(func: *CodeGen, inst: Air.Inst.Index, op: Op) InnerError!void {
45654556}
45664557
45674558fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void {
4559 const mod = func.bin_file.base.options.module.?;
45684560 if (safety) {
45694561 // TODO if the value is undef, write 0xaa bytes to dest
45704562 } else {
......@@ -4575,16 +4567,16 @@ fn airMemset(func: *CodeGen, inst: Air.Inst.Index, safety: bool) InnerError!void
45754567 const ptr = try func.resolveInst(bin_op.lhs);
45764568 const ptr_ty = func.typeOf(bin_op.lhs);
45774569 const value = try func.resolveInst(bin_op.rhs);
4578 const len = switch (ptr_ty.ptrSize()) {
4570 const len = switch (ptr_ty.ptrSize(mod)) {
45794571 .Slice => try func.sliceLen(ptr),
4580 .One => @as(WValue, .{ .imm32 = @intCast(u32, ptr_ty.childType().arrayLen()) }),
4572 .One => @as(WValue, .{ .imm32 = @intCast(u32, ptr_ty.childType(mod).arrayLen(mod)) }),
45814573 .C, .Many => unreachable,
45824574 };
45834575
4584 const elem_ty = if (ptr_ty.ptrSize() == .One)
4585 ptr_ty.childType().childType()
4576 const elem_ty = if (ptr_ty.ptrSize(mod) == .One)
4577 ptr_ty.childType(mod).childType(mod)
45864578 else
4587 ptr_ty.childType();
4579 ptr_ty.childType(mod);
45884580
45894581 const dst_ptr = try func.sliceOrArrayPtr(ptr, ptr_ty);
45904582 try func.memset(elem_ty, dst_ptr, len, value);
......@@ -4686,13 +4678,13 @@ fn memset(func: *CodeGen, elem_ty: Type, ptr: WValue, len: WValue, value: WValue
46864678}
46874679
46884680fn airArrayElemVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
4681 const mod = func.bin_file.base.options.module.?;
46894682 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
46904683
46914684 const array_ty = func.typeOf(bin_op.lhs);
46924685 const array = try func.resolveInst(bin_op.lhs);
46934686 const index = try func.resolveInst(bin_op.rhs);
4694 const elem_ty = array_ty.childType();
4695 const mod = func.bin_file.base.options.module.?;
4687 const elem_ty = array_ty.childType(mod);
46964688 const elem_size = elem_ty.abiSize(mod);
46974689
46984690 if (isByRef(array_ty, mod)) {
......@@ -4810,7 +4802,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48104802 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
48114803 const operand = try func.resolveInst(ty_op.operand);
48124804 const ty = func.typeOfIndex(inst);
4813 const elem_ty = ty.childType();
4805 const elem_ty = ty.childType(mod);
48144806
48154807 if (determineSimdStoreStrategy(ty, mod) == .direct) blk: {
48164808 switch (operand) {
......@@ -4859,7 +4851,7 @@ fn airSplat(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48594851 }
48604852 }
48614853 const elem_size = elem_ty.bitSize(mod);
4862 const vector_len = @intCast(usize, ty.vectorLen());
4854 const vector_len = @intCast(usize, ty.vectorLen(mod));
48634855 if ((!std.math.isPowerOfTwo(elem_size) or elem_size % 8 != 0) and vector_len > 1) {
48644856 return func.fail("TODO: WebAssembly `@splat` for arbitrary element bitsize {d}", .{elem_size});
48654857 }
......@@ -4895,7 +4887,7 @@ fn airShuffle(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
48954887 const mask = func.air.values[extra.mask];
48964888 const mask_len = extra.mask_len;
48974889
4898 const child_ty = inst_ty.childType();
4890 const child_ty = inst_ty.childType(mod);
48994891 const elem_size = child_ty.abiSize(mod);
49004892
49014893 // TODO: One of them could be by ref; handle in loop
......@@ -4959,16 +4951,16 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
49594951 const mod = func.bin_file.base.options.module.?;
49604952 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
49614953 const result_ty = func.typeOfIndex(inst);
4962 const len = @intCast(usize, result_ty.arrayLen());
4954 const len = @intCast(usize, result_ty.arrayLen(mod));
49634955 const elements = @ptrCast([]const Air.Inst.Ref, func.air.extra[ty_pl.payload..][0..len]);
49644956
49654957 const result: WValue = result_value: {
49664958 switch (result_ty.zigTypeTag(mod)) {
49674959 .Array => {
49684960 const result = try func.allocStack(result_ty);
4969 const elem_ty = result_ty.childType();
4961 const elem_ty = result_ty.childType(mod);
49704962 const elem_size = @intCast(u32, elem_ty.abiSize(mod));
4971 const sentinel = if (result_ty.sentinel()) |sent| blk: {
4963 const sentinel = if (result_ty.sentinel(mod)) |sent| blk: {
49724964 break :blk try func.lowerConstant(sent, elem_ty);
49734965 } else null;
49744966
......@@ -5190,8 +5182,7 @@ fn cmpOptionals(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op:
51905182 const mod = func.bin_file.base.options.module.?;
51915183 assert(operand_ty.hasRuntimeBitsIgnoreComptime(mod));
51925184 assert(op == .eq or op == .neq);
5193 var buf: Type.Payload.ElemType = undefined;
5194 const payload_ty = operand_ty.optionalChild(&buf);
5185 const payload_ty = operand_ty.optionalChild(mod);
51955186
51965187 // We store the final result in here that will be validated
51975188 // if the optional is truly equal.
......@@ -5268,7 +5259,7 @@ fn cmpBigInt(func: *CodeGen, lhs: WValue, rhs: WValue, operand_ty: Type, op: std
52685259fn airSetUnionTag(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
52695260 const mod = func.bin_file.base.options.module.?;
52705261 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
5271 const un_ty = func.typeOf(bin_op.lhs).childType();
5262 const un_ty = func.typeOf(bin_op.lhs).childType(mod);
52725263 const tag_ty = func.typeOf(bin_op.rhs);
52735264 const layout = un_ty.unionGetLayout(mod);
52745265 if (layout.tag_size == 0) return func.finishAir(inst, .none, &.{ bin_op.lhs, bin_op.rhs });
......@@ -5398,7 +5389,7 @@ fn airErrUnionPayloadPtrSet(func: *CodeGen, inst: Air.Inst.Index) InnerError!voi
53985389 const mod = func.bin_file.base.options.module.?;
53995390 const ty_op = func.air.instructions.items(.data)[inst].ty_op;
54005391
5401 const err_set_ty = func.typeOf(ty_op.operand).childType();
5392 const err_set_ty = func.typeOf(ty_op.operand).childType(mod);
54025393 const payload_ty = err_set_ty.errorUnionPayload();
54035394 const operand = try func.resolveInst(ty_op.operand);
54045395
......@@ -5426,7 +5417,7 @@ fn airFieldParentPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54265417 const extra = func.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
54275418
54285419 const field_ptr = try func.resolveInst(extra.field_ptr);
5429 const parent_ty = func.air.getRefType(ty_pl.ty).childType();
5420 const parent_ty = func.air.getRefType(ty_pl.ty).childType(mod);
54305421 const field_offset = parent_ty.structFieldOffset(extra.field_index, mod);
54315422
54325423 const result = if (field_offset != 0) result: {
......@@ -5455,10 +5446,10 @@ fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54555446 const bin_op = func.air.instructions.items(.data)[inst].bin_op;
54565447 const dst = try func.resolveInst(bin_op.lhs);
54575448 const dst_ty = func.typeOf(bin_op.lhs);
5458 const ptr_elem_ty = dst_ty.childType();
5449 const ptr_elem_ty = dst_ty.childType(mod);
54595450 const src = try func.resolveInst(bin_op.rhs);
54605451 const src_ty = func.typeOf(bin_op.rhs);
5461 const len = switch (dst_ty.ptrSize()) {
5452 const len = switch (dst_ty.ptrSize(mod)) {
54625453 .Slice => blk: {
54635454 const slice_len = try func.sliceLen(dst);
54645455 if (ptr_elem_ty.abiSize(mod) != 1) {
......@@ -5470,7 +5461,7 @@ fn airMemcpy(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
54705461 break :blk slice_len;
54715462 },
54725463 .One => @as(WValue, .{
5473 .imm32 = @intCast(u32, ptr_elem_ty.arrayLen() * ptr_elem_ty.childType().abiSize(mod)),
5464 .imm32 = @intCast(u32, ptr_elem_ty.arrayLen(mod) * ptr_elem_ty.childType(mod).abiSize(mod)),
54745465 }),
54755466 .C, .Many => unreachable,
54765467 };
......@@ -5551,7 +5542,7 @@ fn airErrorName(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
55515542 // As the names are global and the slice elements are constant, we do not have
55525543 // to make a copy of the ptr+value but can point towards them directly.
55535544 const error_table_symbol = try func.bin_file.getErrorTableSymbol();
5554 const name_ty = Type.initTag(.const_slice_u8_sentinel_0);
5545 const name_ty = Type.const_slice_u8_sentinel_0;
55555546 const mod = func.bin_file.base.options.module.?;
55565547 const abi_size = name_ty.abiSize(mod);
55575548
......@@ -5857,7 +5848,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58575848 try func.addLabel(.local_set, overflow_bit.local.value);
58585849 break :blk try func.wrapOperand(bin_op, lhs_ty);
58595850 } else if (int_info.bits == 64 and int_info.signedness == .unsigned) blk: {
5860 const new_ty = Type.initTag(.u128);
5851 const new_ty = Type.u128;
58615852 var lhs_upcast = try (try func.intcast(lhs, lhs_ty, new_ty)).toLocal(func, lhs_ty);
58625853 defer lhs_upcast.free(func);
58635854 var rhs_upcast = try (try func.intcast(rhs, lhs_ty, new_ty)).toLocal(func, lhs_ty);
......@@ -5878,7 +5869,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
58785869 const bin_op = try func.callIntrinsic(
58795870 "__multi3",
58805871 &[_]Type{Type.i64} ** 4,
5881 Type.initTag(.i128),
5872 Type.i128,
58825873 &.{ lhs, lhs_shifted, rhs, rhs_shifted },
58835874 );
58845875 const res = try func.allocLocal(lhs_ty);
......@@ -5902,19 +5893,19 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59025893 const mul1 = try func.callIntrinsic(
59035894 "__multi3",
59045895 &[_]Type{Type.i64} ** 4,
5905 Type.initTag(.i128),
5896 Type.i128,
59065897 &.{ lhs_lsb, zero, rhs_msb, zero },
59075898 );
59085899 const mul2 = try func.callIntrinsic(
59095900 "__multi3",
59105901 &[_]Type{Type.i64} ** 4,
5911 Type.initTag(.i128),
5902 Type.i128,
59125903 &.{ rhs_lsb, zero, lhs_msb, zero },
59135904 );
59145905 const mul3 = try func.callIntrinsic(
59155906 "__multi3",
59165907 &[_]Type{Type.i64} ** 4,
5917 Type.initTag(.i128),
5908 Type.i128,
59185909 &.{ lhs_msb, zero, rhs_msb, zero },
59195910 );
59205911
......@@ -5942,7 +5933,7 @@ fn airMulWithOverflow(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
59425933 _ = try func.binOp(lsb_or, mul_add_lt, Type.bool, .@"or");
59435934 try func.addLabel(.local_set, overflow_bit.local.value);
59445935
5945 const tmp_result = try func.allocStack(Type.initTag(.u128));
5936 const tmp_result = try func.allocStack(Type.u128);
59465937 try func.emitWValue(tmp_result);
59475938 const mul3_msb = try func.load(mul3, Type.u64, 0);
59485939 try func.store(.stack, mul3_msb, Type.u64, tmp_result.offset());
......@@ -6191,11 +6182,12 @@ fn airTry(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
61916182}
61926183
61936184fn airTryPtr(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
6185 const mod = func.bin_file.base.options.module.?;
61946186 const ty_pl = func.air.instructions.items(.data)[inst].ty_pl;
61956187 const extra = func.air.extraData(Air.TryPtr, ty_pl.payload);
61966188 const err_union_ptr = try func.resolveInst(extra.data.ptr);
61976189 const body = func.air.extra[extra.end..][0..extra.data.body_len];
6198 const err_union_ty = func.typeOf(extra.data.ptr).childType();
6190 const err_union_ty = func.typeOf(extra.data.ptr).childType(mod);
61996191 const result = try lowerTry(func, inst, err_union_ptr, body, err_union_ty, true);
62006192 func.finishAir(inst, result, &.{extra.data.ptr});
62016193}
......@@ -6845,11 +6837,11 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
68456837 for (enum_ty.enumFields().keys(), 0..) |tag_name, field_index| {
68466838 // for each tag name, create an unnamed const,
68476839 // and then get a pointer to its value.
6848 var name_ty_payload: Type.Payload.Len = .{
6849 .base = .{ .tag = .array_u8_sentinel_0 },
6850 .data = @intCast(u64, tag_name.len),
6851 };
6852 const name_ty = Type.initPayload(&name_ty_payload.base);
6840 const name_ty = try mod.arrayType(.{
6841 .len = tag_name.len,
6842 .child = .u8_type,
6843 .sentinel = .zero_u8,
6844 });
68536845 const string_bytes = &mod.string_literal_bytes;
68546846 try string_bytes.ensureUnusedCapacity(mod.gpa, tag_name.len);
68556847 const gop = try mod.string_literal_table.getOrPutContextAdapted(mod.gpa, tag_name, Module.StringLiteralAdapter{
......@@ -6972,7 +6964,7 @@ fn getTagNameFunction(func: *CodeGen, enum_ty: Type) InnerError!u32 {
69726964 // finish function body
69736965 try writer.writeByte(std.wasm.opcode(.end));
69746966
6975 const slice_ty = Type.initTag(.const_slice_u8_sentinel_0);
6967 const slice_ty = Type.const_slice_u8_sentinel_0;
69766968 const func_type = try genFunctype(arena, .Unspecified, &.{int_tag_ty}, slice_ty, mod);
69776969 return func.bin_file.createFunction(func_name, func_type, &body_list, &relocs);
69786970}
......@@ -7068,7 +7060,7 @@ fn airCmpxchg(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
70687060 const extra = func.air.extraData(Air.Cmpxchg, ty_pl.payload).data;
70697061
70707062 const ptr_ty = func.typeOf(extra.ptr);
7071 const ty = ptr_ty.childType();
7063 const ty = ptr_ty.childType(mod);
70727064 const result_ty = func.typeOfIndex(inst);
70737065
70747066 const ptr_operand = try func.resolveInst(extra.ptr);
......@@ -7355,7 +7347,7 @@ fn airAtomicStore(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
73557347 const ptr = try func.resolveInst(bin_op.lhs);
73567348 const operand = try func.resolveInst(bin_op.rhs);
73577349 const ptr_ty = func.typeOf(bin_op.lhs);
7358 const ty = ptr_ty.childType();
7350 const ty = ptr_ty.childType(mod);
73597351
73607352 if (func.useAtomicFeature()) {
73617353 const tag: wasm.AtomicsOpcode = switch (ty.abiSize(mod)) {
src/arch/x86_64/CodeGen.zig+153-161
......@@ -2259,7 +2259,7 @@ fn allocFrameIndex(self: *Self, alloc: FrameAlloc) !FrameIndex {
22592259fn allocMemPtr(self: *Self, inst: Air.Inst.Index) !FrameIndex {
22602260 const mod = self.bin_file.options.module.?;
22612261 const ptr_ty = self.typeOfIndex(inst);
2262 const val_ty = ptr_ty.childType();
2262 const val_ty = ptr_ty.childType(mod);
22632263 return self.allocFrameIndex(FrameAlloc.init(.{
22642264 .size = math.cast(u32, val_ty.abiSize(mod)) orelse {
22652265 return self.fail("type '{}' too big to fit into stack frame", .{val_ty.fmt(mod)});
......@@ -2289,8 +2289,8 @@ fn allocRegOrMemAdvanced(self: *Self, ty: Type, inst: ?Air.Inst.Index, reg_ok: b
22892289 80 => break :need_mem,
22902290 else => unreachable,
22912291 },
2292 .Vector => switch (ty.childType().zigTypeTag(mod)) {
2293 .Float => switch (ty.childType().floatBits(self.target.*)) {
2292 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
2293 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
22942294 16, 32, 64, 128 => if (self.hasFeature(.avx)) 32 else 16,
22952295 80 => break :need_mem,
22962296 else => unreachable,
......@@ -2727,12 +2727,12 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
27272727 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv);
27282728
27292729 if (dst_ty.zigTypeTag(mod) == .Vector) {
2730 assert(src_ty.zigTypeTag(mod) == .Vector and dst_ty.vectorLen() == src_ty.vectorLen());
2731 const dst_info = dst_ty.childType().intInfo(mod);
2732 const src_info = src_ty.childType().intInfo(mod);
2730 assert(src_ty.zigTypeTag(mod) == .Vector and dst_ty.vectorLen(mod) == src_ty.vectorLen(mod));
2731 const dst_info = dst_ty.childType(mod).intInfo(mod);
2732 const src_info = src_ty.childType(mod).intInfo(mod);
27332733 const mir_tag = if (@as(?Mir.Inst.FixedTag, switch (dst_info.bits) {
27342734 8 => switch (src_info.bits) {
2735 16 => switch (dst_ty.vectorLen()) {
2735 16 => switch (dst_ty.vectorLen(mod)) {
27362736 1...8 => if (self.hasFeature(.avx)) .{ .vp_b, .ackusw } else .{ .p_b, .ackusw },
27372737 9...16 => if (self.hasFeature(.avx2)) .{ .vp_b, .ackusw } else null,
27382738 else => null,
......@@ -2740,7 +2740,7 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
27402740 else => null,
27412741 },
27422742 16 => switch (src_info.bits) {
2743 32 => switch (dst_ty.vectorLen()) {
2743 32 => switch (dst_ty.vectorLen(mod)) {
27442744 1...4 => if (self.hasFeature(.avx))
27452745 .{ .vp_w, .ackusd }
27462746 else if (self.hasFeature(.sse4_1))
......@@ -2769,14 +2769,10 @@ fn airTrunc(self: *Self, inst: Air.Inst.Index) !void {
27692769 };
27702770 const splat_val = Value.initPayload(&splat_pl.base);
27712771
2772 var full_pl = Type.Payload.Array{
2773 .base = .{ .tag = .vector },
2774 .data = .{
2775 .len = @divExact(@as(u64, if (src_abi_size > 16) 256 else 128), src_info.bits),
2776 .elem_type = src_ty.childType(),
2777 },
2778 };
2779 const full_ty = Type.initPayload(&full_pl.base);
2772 const full_ty = try mod.vectorType(.{
2773 .len = @intCast(u32, @divExact(@as(u64, if (src_abi_size > 16) 256 else 128), src_info.bits)),
2774 .child = src_ty.childType(mod).ip_index,
2775 });
27802776 const full_abi_size = @intCast(u32, full_ty.abiSize(mod));
27812777
27822778 const splat_mcv = try self.genTypedValue(.{ .ty = full_ty, .val = splat_val });
......@@ -3587,7 +3583,7 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
35873583 const result = result: {
35883584 const dst_ty = self.typeOfIndex(inst);
35893585 const src_ty = self.typeOf(ty_op.operand);
3590 const opt_ty = src_ty.childType();
3586 const opt_ty = src_ty.childType(mod);
35913587 const src_mcv = try self.resolveInst(ty_op.operand);
35923588
35933589 if (opt_ty.optionalReprIsPayload(mod)) {
......@@ -3607,7 +3603,7 @@ fn airOptionalPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
36073603 else
36083604 try self.copyToRegisterWithInstTracking(inst, dst_ty, src_mcv);
36093605
3610 const pl_ty = dst_ty.childType();
3606 const pl_ty = dst_ty.childType(mod);
36113607 const pl_abi_size = @intCast(i32, pl_ty.abiSize(mod));
36123608 try self.genSetMem(.{ .reg = dst_mcv.getReg().? }, pl_abi_size, Type.bool, .{ .immediate = 1 });
36133609 break :result if (self.liveness.isUnused(inst)) .unreach else dst_mcv;
......@@ -3737,7 +3733,7 @@ fn airUnwrapErrUnionErrPtr(self: *Self, inst: Air.Inst.Index) !void {
37373733 const dst_lock = self.register_manager.lockRegAssumeUnused(dst_reg);
37383734 defer self.register_manager.unlockReg(dst_lock);
37393735
3740 const eu_ty = src_ty.childType();
3736 const eu_ty = src_ty.childType(mod);
37413737 const pl_ty = eu_ty.errorUnionPayload();
37423738 const err_ty = eu_ty.errorUnionSet();
37433739 const err_off = @intCast(i32, errUnionErrorOffset(pl_ty, mod));
......@@ -3777,7 +3773,7 @@ fn airUnwrapErrUnionPayloadPtr(self: *Self, inst: Air.Inst.Index) !void {
37773773 const dst_lock = self.register_manager.lockReg(dst_reg);
37783774 defer if (dst_lock) |lock| self.register_manager.unlockReg(lock);
37793775
3780 const eu_ty = src_ty.childType();
3776 const eu_ty = src_ty.childType(mod);
37813777 const pl_ty = eu_ty.errorUnionPayload();
37823778 const pl_off = @intCast(i32, errUnionPayloadOffset(pl_ty, mod));
37833779 const dst_abi_size = @intCast(u32, dst_ty.abiSize(mod));
......@@ -3803,7 +3799,7 @@ fn airErrUnionPayloadPtrSet(self: *Self, inst: Air.Inst.Index) !void {
38033799 const src_lock = self.register_manager.lockRegAssumeUnused(src_reg);
38043800 defer self.register_manager.unlockReg(src_lock);
38053801
3806 const eu_ty = src_ty.childType();
3802 const eu_ty = src_ty.childType(mod);
38073803 const pl_ty = eu_ty.errorUnionPayload();
38083804 const err_ty = eu_ty.errorUnionSet();
38093805 const err_off = @intCast(i32, errUnionErrorOffset(pl_ty, mod));
......@@ -4057,7 +4053,7 @@ fn genSliceElemPtr(self: *Self, lhs: Air.Inst.Ref, rhs: Air.Inst.Ref) !MCValue {
40574053 };
40584054 defer if (slice_mcv_lock) |lock| self.register_manager.unlockReg(lock);
40594055
4060 const elem_ty = slice_ty.childType();
4056 const elem_ty = slice_ty.childType(mod);
40614057 const elem_size = elem_ty.abiSize(mod);
40624058 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
40634059 const slice_ptr_field_type = slice_ty.slicePtrFieldType(&buf);
......@@ -4116,7 +4112,7 @@ fn airArrayElemVal(self: *Self, inst: Air.Inst.Index) !void {
41164112 };
41174113 defer if (array_lock) |lock| self.register_manager.unlockReg(lock);
41184114
4119 const elem_ty = array_ty.childType();
4115 const elem_ty = array_ty.childType(mod);
41204116 const elem_abi_size = elem_ty.abiSize(mod);
41214117
41224118 const index_ty = self.typeOf(bin_op.rhs);
......@@ -4253,7 +4249,7 @@ fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
42534249 const mod = self.bin_file.options.module.?;
42544250 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
42554251 const ptr_union_ty = self.typeOf(bin_op.lhs);
4256 const union_ty = ptr_union_ty.childType();
4252 const union_ty = ptr_union_ty.childType(mod);
42574253 const tag_ty = self.typeOf(bin_op.rhs);
42584254 const layout = union_ty.unionGetLayout(mod);
42594255
......@@ -4287,7 +4283,9 @@ fn airSetUnionTag(self: *Self, inst: Air.Inst.Index) !void {
42874283 break :blk MCValue{ .register = reg };
42884284 } else ptr;
42894285
4290 var ptr_tag_pl = ptr_union_ty.ptrInfo();
4286 var ptr_tag_pl: Type.Payload.Pointer = .{
4287 .data = ptr_union_ty.ptrInfo(mod),
4288 };
42914289 ptr_tag_pl.data.pointee_type = tag_ty;
42924290 const ptr_tag_ty = Type.initPayload(&ptr_tag_pl.base);
42934291 try self.store(ptr_tag_ty, adjusted_ptr, tag);
......@@ -4924,14 +4922,11 @@ fn airFloatSign(self: *Self, inst: Air.Inst.Index) !void {
49244922 var stack align(@alignOf(ExpectedContents)) =
49254923 std.heap.stackFallback(@sizeOf(ExpectedContents), arena.allocator());
49264924
4927 var vec_pl = Type.Payload.Array{
4928 .base = .{ .tag = .vector },
4929 .data = .{
4930 .len = @divExact(abi_size * 8, scalar_bits),
4931 .elem_type = try mod.intType(.signed, scalar_bits),
4932 },
4933 };
4934 const vec_ty = Type.initPayload(&vec_pl.base);
4925 const vec_ty = try mod.vectorType(.{
4926 .len = @divExact(abi_size * 8, scalar_bits),
4927 .child = (try mod.intType(.signed, scalar_bits)).ip_index,
4928 });
4929
49354930 const sign_val = switch (tag) {
49364931 .neg => try vec_ty.minInt(stack.get(), mod),
49374932 .fabs => try vec_ty.maxInt(stack.get(), mod),
......@@ -5034,15 +5029,15 @@ fn genRound(self: *Self, ty: Type, dst_reg: Register, src_mcv: MCValue, mode: u4
50345029 16, 80, 128 => null,
50355030 else => unreachable,
50365031 },
5037 .Vector => switch (ty.childType().zigTypeTag(mod)) {
5038 .Float => switch (ty.childType().floatBits(self.target.*)) {
5039 32 => switch (ty.vectorLen()) {
5032 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
5033 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
5034 32 => switch (ty.vectorLen(mod)) {
50405035 1 => if (self.hasFeature(.avx)) .{ .v_ss, .round } else .{ ._ss, .round },
50415036 2...4 => if (self.hasFeature(.avx)) .{ .v_ps, .round } else .{ ._ps, .round },
50425037 5...8 => if (self.hasFeature(.avx)) .{ .v_ps, .round } else null,
50435038 else => null,
50445039 },
5045 64 => switch (ty.vectorLen()) {
5040 64 => switch (ty.vectorLen(mod)) {
50465041 1 => if (self.hasFeature(.avx)) .{ .v_sd, .round } else .{ ._sd, .round },
50475042 2 => if (self.hasFeature(.avx)) .{ .v_pd, .round } else .{ ._pd, .round },
50485043 3...4 => if (self.hasFeature(.avx)) .{ .v_pd, .round } else null,
......@@ -5131,9 +5126,9 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
51315126 80, 128 => null,
51325127 else => unreachable,
51335128 },
5134 .Vector => switch (ty.childType().zigTypeTag(mod)) {
5135 .Float => switch (ty.childType().floatBits(self.target.*)) {
5136 16 => if (self.hasFeature(.f16c)) switch (ty.vectorLen()) {
5129 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
5130 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
5131 16 => if (self.hasFeature(.f16c)) switch (ty.vectorLen(mod)) {
51375132 1 => {
51385133 try self.asmRegisterRegister(
51395134 .{ .v_ps, .cvtph2 },
......@@ -5184,13 +5179,13 @@ fn airSqrt(self: *Self, inst: Air.Inst.Index) !void {
51845179 },
51855180 else => null,
51865181 } else null,
5187 32 => switch (ty.vectorLen()) {
5182 32 => switch (ty.vectorLen(mod)) {
51885183 1 => if (self.hasFeature(.avx)) .{ .v_ss, .sqrt } else .{ ._ss, .sqrt },
51895184 2...4 => if (self.hasFeature(.avx)) .{ .v_ps, .sqrt } else .{ ._ps, .sqrt },
51905185 5...8 => if (self.hasFeature(.avx)) .{ .v_ps, .sqrt } else null,
51915186 else => null,
51925187 },
5193 64 => switch (ty.vectorLen()) {
5188 64 => switch (ty.vectorLen(mod)) {
51945189 1 => if (self.hasFeature(.avx)) .{ .v_sd, .sqrt } else .{ ._sd, .sqrt },
51955190 2 => if (self.hasFeature(.avx)) .{ .v_pd, .sqrt } else .{ ._pd, .sqrt },
51965191 3...4 => if (self.hasFeature(.avx)) .{ .v_pd, .sqrt } else null,
......@@ -5292,7 +5287,7 @@ fn reuseOperandAdvanced(
52925287
52935288fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerError!void {
52945289 const mod = self.bin_file.options.module.?;
5295 const ptr_info = ptr_ty.ptrInfo().data;
5290 const ptr_info = ptr_ty.ptrInfo(mod);
52965291
52975292 const val_ty = ptr_info.pointee_type;
52985293 const val_abi_size = @intCast(u32, val_ty.abiSize(mod));
......@@ -5365,7 +5360,8 @@ fn packedLoad(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) Inn
53655360}
53665361
53675362fn load(self: *Self, dst_mcv: MCValue, ptr_ty: Type, ptr_mcv: MCValue) InnerError!void {
5368 const dst_ty = ptr_ty.childType();
5363 const mod = self.bin_file.options.module.?;
5364 const dst_ty = ptr_ty.childType(mod);
53695365 switch (ptr_mcv) {
53705366 .none,
53715367 .unreach,
......@@ -5424,7 +5420,7 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
54245420 else
54255421 try self.allocRegOrMem(inst, true);
54265422
5427 if (ptr_ty.ptrInfo().data.host_size > 0) {
5423 if (ptr_ty.ptrInfo(mod).host_size > 0) {
54285424 try self.packedLoad(dst_mcv, ptr_ty, ptr_mcv);
54295425 } else {
54305426 try self.load(dst_mcv, ptr_ty, ptr_mcv);
......@@ -5436,8 +5432,8 @@ fn airLoad(self: *Self, inst: Air.Inst.Index) !void {
54365432
54375433fn packedStore(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) InnerError!void {
54385434 const mod = self.bin_file.options.module.?;
5439 const ptr_info = ptr_ty.ptrInfo().data;
5440 const src_ty = ptr_ty.childType();
5435 const ptr_info = ptr_ty.ptrInfo(mod);
5436 const src_ty = ptr_ty.childType(mod);
54415437
54425438 const limb_abi_size: u16 = @min(ptr_info.host_size, 8);
54435439 const limb_abi_bits = limb_abi_size * 8;
......@@ -5509,7 +5505,8 @@ fn packedStore(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) In
55095505}
55105506
55115507fn store(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) InnerError!void {
5512 const src_ty = ptr_ty.childType();
5508 const mod = self.bin_file.options.module.?;
5509 const src_ty = ptr_ty.childType(mod);
55135510 switch (ptr_mcv) {
55145511 .none,
55155512 .unreach,
......@@ -5544,6 +5541,7 @@ fn store(self: *Self, ptr_ty: Type, ptr_mcv: MCValue, src_mcv: MCValue) InnerErr
55445541}
55455542
55465543fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
5544 const mod = self.bin_file.options.module.?;
55475545 if (safety) {
55485546 // TODO if the value is undef, write 0xaa bytes to dest
55495547 } else {
......@@ -5553,7 +5551,7 @@ fn airStore(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
55535551 const ptr_mcv = try self.resolveInst(bin_op.lhs);
55545552 const ptr_ty = self.typeOf(bin_op.lhs);
55555553 const src_mcv = try self.resolveInst(bin_op.rhs);
5556 if (ptr_ty.ptrInfo().data.host_size > 0) {
5554 if (ptr_ty.ptrInfo(mod).host_size > 0) {
55575555 try self.packedStore(ptr_ty, ptr_mcv, src_mcv);
55585556 } else {
55595557 try self.store(ptr_ty, ptr_mcv, src_mcv);
......@@ -5578,11 +5576,11 @@ fn fieldPtr(self: *Self, inst: Air.Inst.Index, operand: Air.Inst.Ref, index: u32
55785576 const mod = self.bin_file.options.module.?;
55795577 const ptr_field_ty = self.typeOfIndex(inst);
55805578 const ptr_container_ty = self.typeOf(operand);
5581 const container_ty = ptr_container_ty.childType();
5579 const container_ty = ptr_container_ty.childType(mod);
55825580 const field_offset = @intCast(i32, switch (container_ty.containerLayout()) {
55835581 .Auto, .Extern => container_ty.structFieldOffset(index, mod),
55845582 .Packed => if (container_ty.zigTypeTag(mod) == .Struct and
5585 ptr_field_ty.ptrInfo().data.host_size == 0)
5583 ptr_field_ty.ptrInfo(mod).host_size == 0)
55865584 container_ty.packedStructFieldByteOffset(index, mod)
55875585 else
55885586 0,
......@@ -5760,7 +5758,7 @@ fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void {
57605758 const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
57615759
57625760 const inst_ty = self.typeOfIndex(inst);
5763 const parent_ty = inst_ty.childType();
5761 const parent_ty = inst_ty.childType(mod);
57645762 const field_offset = @intCast(i32, parent_ty.structFieldOffset(extra.field_index, mod));
57655763
57665764 const src_mcv = try self.resolveInst(extra.field_ptr);
......@@ -6680,10 +6678,10 @@ fn genBinOp(
66806678 80, 128 => null,
66816679 else => unreachable,
66826680 },
6683 .Vector => switch (lhs_ty.childType().zigTypeTag(mod)) {
6681 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
66846682 else => null,
6685 .Int => switch (lhs_ty.childType().intInfo(mod).bits) {
6686 8 => switch (lhs_ty.vectorLen()) {
6683 .Int => switch (lhs_ty.childType(mod).intInfo(mod).bits) {
6684 8 => switch (lhs_ty.vectorLen(mod)) {
66876685 1...16 => switch (air_tag) {
66886686 .add,
66896687 .addwrap,
......@@ -6694,7 +6692,7 @@ fn genBinOp(
66946692 .bit_and => if (self.hasFeature(.avx)) .{ .vp_, .@"and" } else .{ .p_, .@"and" },
66956693 .bit_or => if (self.hasFeature(.avx)) .{ .vp_, .@"or" } else .{ .p_, .@"or" },
66966694 .xor => if (self.hasFeature(.avx)) .{ .vp_, .xor } else .{ .p_, .xor },
6697 .min => switch (lhs_ty.childType().intInfo(mod).signedness) {
6695 .min => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
66986696 .signed => if (self.hasFeature(.avx))
66996697 .{ .vp_b, .mins }
67006698 else if (self.hasFeature(.sse4_1))
......@@ -6708,7 +6706,7 @@ fn genBinOp(
67086706 else
67096707 null,
67106708 },
6711 .max => switch (lhs_ty.childType().intInfo(mod).signedness) {
6709 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
67126710 .signed => if (self.hasFeature(.avx))
67136711 .{ .vp_b, .maxs }
67146712 else if (self.hasFeature(.sse4_1))
......@@ -6734,11 +6732,11 @@ fn genBinOp(
67346732 .bit_and => if (self.hasFeature(.avx2)) .{ .vp_, .@"and" } else null,
67356733 .bit_or => if (self.hasFeature(.avx2)) .{ .vp_, .@"or" } else null,
67366734 .xor => if (self.hasFeature(.avx2)) .{ .vp_, .xor } else null,
6737 .min => switch (lhs_ty.childType().intInfo(mod).signedness) {
6735 .min => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
67386736 .signed => if (self.hasFeature(.avx2)) .{ .vp_b, .mins } else null,
67396737 .unsigned => if (self.hasFeature(.avx)) .{ .vp_b, .minu } else null,
67406738 },
6741 .max => switch (lhs_ty.childType().intInfo(mod).signedness) {
6739 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
67426740 .signed => if (self.hasFeature(.avx2)) .{ .vp_b, .maxs } else null,
67436741 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_b, .maxu } else null,
67446742 },
......@@ -6746,7 +6744,7 @@ fn genBinOp(
67466744 },
67476745 else => null,
67486746 },
6749 16 => switch (lhs_ty.vectorLen()) {
6747 16 => switch (lhs_ty.vectorLen(mod)) {
67506748 1...8 => switch (air_tag) {
67516749 .add,
67526750 .addwrap,
......@@ -6760,7 +6758,7 @@ fn genBinOp(
67606758 .bit_and => if (self.hasFeature(.avx)) .{ .vp_, .@"and" } else .{ .p_, .@"and" },
67616759 .bit_or => if (self.hasFeature(.avx)) .{ .vp_, .@"or" } else .{ .p_, .@"or" },
67626760 .xor => if (self.hasFeature(.avx)) .{ .vp_, .xor } else .{ .p_, .xor },
6763 .min => switch (lhs_ty.childType().intInfo(mod).signedness) {
6761 .min => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
67646762 .signed => if (self.hasFeature(.avx))
67656763 .{ .vp_w, .mins }
67666764 else
......@@ -6770,7 +6768,7 @@ fn genBinOp(
67706768 else
67716769 .{ .p_w, .minu },
67726770 },
6773 .max => switch (lhs_ty.childType().intInfo(mod).signedness) {
6771 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
67746772 .signed => if (self.hasFeature(.avx))
67756773 .{ .vp_w, .maxs }
67766774 else
......@@ -6795,11 +6793,11 @@ fn genBinOp(
67956793 .bit_and => if (self.hasFeature(.avx2)) .{ .vp_, .@"and" } else null,
67966794 .bit_or => if (self.hasFeature(.avx2)) .{ .vp_, .@"or" } else null,
67976795 .xor => if (self.hasFeature(.avx2)) .{ .vp_, .xor } else null,
6798 .min => switch (lhs_ty.childType().intInfo(mod).signedness) {
6796 .min => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
67996797 .signed => if (self.hasFeature(.avx2)) .{ .vp_w, .mins } else null,
68006798 .unsigned => if (self.hasFeature(.avx)) .{ .vp_w, .minu } else null,
68016799 },
6802 .max => switch (lhs_ty.childType().intInfo(mod).signedness) {
6800 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
68036801 .signed => if (self.hasFeature(.avx2)) .{ .vp_w, .maxs } else null,
68046802 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_w, .maxu } else null,
68056803 },
......@@ -6807,7 +6805,7 @@ fn genBinOp(
68076805 },
68086806 else => null,
68096807 },
6810 32 => switch (lhs_ty.vectorLen()) {
6808 32 => switch (lhs_ty.vectorLen(mod)) {
68116809 1...4 => switch (air_tag) {
68126810 .add,
68136811 .addwrap,
......@@ -6826,7 +6824,7 @@ fn genBinOp(
68266824 .bit_and => if (self.hasFeature(.avx)) .{ .vp_, .@"and" } else .{ .p_, .@"and" },
68276825 .bit_or => if (self.hasFeature(.avx)) .{ .vp_, .@"or" } else .{ .p_, .@"or" },
68286826 .xor => if (self.hasFeature(.avx)) .{ .vp_, .xor } else .{ .p_, .xor },
6829 .min => switch (lhs_ty.childType().intInfo(mod).signedness) {
6827 .min => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
68306828 .signed => if (self.hasFeature(.avx))
68316829 .{ .vp_d, .mins }
68326830 else if (self.hasFeature(.sse4_1))
......@@ -6840,7 +6838,7 @@ fn genBinOp(
68406838 else
68416839 null,
68426840 },
6843 .max => switch (lhs_ty.childType().intInfo(mod).signedness) {
6841 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
68446842 .signed => if (self.hasFeature(.avx))
68456843 .{ .vp_d, .maxs }
68466844 else if (self.hasFeature(.sse4_1))
......@@ -6869,11 +6867,11 @@ fn genBinOp(
68696867 .bit_and => if (self.hasFeature(.avx2)) .{ .vp_, .@"and" } else null,
68706868 .bit_or => if (self.hasFeature(.avx2)) .{ .vp_, .@"or" } else null,
68716869 .xor => if (self.hasFeature(.avx2)) .{ .vp_, .xor } else null,
6872 .min => switch (lhs_ty.childType().intInfo(mod).signedness) {
6870 .min => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
68736871 .signed => if (self.hasFeature(.avx2)) .{ .vp_d, .mins } else null,
68746872 .unsigned => if (self.hasFeature(.avx)) .{ .vp_d, .minu } else null,
68756873 },
6876 .max => switch (lhs_ty.childType().intInfo(mod).signedness) {
6874 .max => switch (lhs_ty.childType(mod).intInfo(mod).signedness) {
68776875 .signed => if (self.hasFeature(.avx2)) .{ .vp_d, .maxs } else null,
68786876 .unsigned => if (self.hasFeature(.avx2)) .{ .vp_d, .maxu } else null,
68796877 },
......@@ -6881,7 +6879,7 @@ fn genBinOp(
68816879 },
68826880 else => null,
68836881 },
6884 64 => switch (lhs_ty.vectorLen()) {
6882 64 => switch (lhs_ty.vectorLen(mod)) {
68856883 1...2 => switch (air_tag) {
68866884 .add,
68876885 .addwrap,
......@@ -6910,8 +6908,8 @@ fn genBinOp(
69106908 },
69116909 else => null,
69126910 },
6913 .Float => switch (lhs_ty.childType().floatBits(self.target.*)) {
6914 16 => if (self.hasFeature(.f16c)) switch (lhs_ty.vectorLen()) {
6911 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
6912 16 => if (self.hasFeature(.f16c)) switch (lhs_ty.vectorLen(mod)) {
69156913 1 => {
69166914 const tmp_reg = (try self.register_manager.allocReg(null, sse)).to128();
69176915 const tmp_lock = self.register_manager.lockRegAssumeUnused(tmp_reg);
......@@ -7086,7 +7084,7 @@ fn genBinOp(
70867084 },
70877085 else => null,
70887086 } else null,
7089 32 => switch (lhs_ty.vectorLen()) {
7087 32 => switch (lhs_ty.vectorLen(mod)) {
70907088 1 => switch (air_tag) {
70917089 .add => if (self.hasFeature(.avx)) .{ .v_ss, .add } else .{ ._ss, .add },
70927090 .sub => if (self.hasFeature(.avx)) .{ .v_ss, .sub } else .{ ._ss, .sub },
......@@ -7124,7 +7122,7 @@ fn genBinOp(
71247122 } else null,
71257123 else => null,
71267124 },
7127 64 => switch (lhs_ty.vectorLen()) {
7125 64 => switch (lhs_ty.vectorLen(mod)) {
71287126 1 => switch (air_tag) {
71297127 .add => if (self.hasFeature(.avx)) .{ .v_sd, .add } else .{ ._sd, .add },
71307128 .sub => if (self.hasFeature(.avx)) .{ .v_sd, .sub } else .{ ._sd, .sub },
......@@ -7236,14 +7234,14 @@ fn genBinOp(
72367234 16, 80, 128 => null,
72377235 else => unreachable,
72387236 },
7239 .Vector => switch (lhs_ty.childType().zigTypeTag(mod)) {
7240 .Float => switch (lhs_ty.childType().floatBits(self.target.*)) {
7241 32 => switch (lhs_ty.vectorLen()) {
7237 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
7238 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
7239 32 => switch (lhs_ty.vectorLen(mod)) {
72427240 1 => .{ .v_ss, .cmp },
72437241 2...8 => .{ .v_ps, .cmp },
72447242 else => null,
72457243 },
7246 64 => switch (lhs_ty.vectorLen()) {
7244 64 => switch (lhs_ty.vectorLen(mod)) {
72477245 1 => .{ .v_sd, .cmp },
72487246 2...4 => .{ .v_pd, .cmp },
72497247 else => null,
......@@ -7270,13 +7268,13 @@ fn genBinOp(
72707268 16, 80, 128 => null,
72717269 else => unreachable,
72727270 },
7273 .Vector => switch (lhs_ty.childType().zigTypeTag(mod)) {
7274 .Float => switch (lhs_ty.childType().floatBits(self.target.*)) {
7275 32 => switch (lhs_ty.vectorLen()) {
7271 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
7272 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
7273 32 => switch (lhs_ty.vectorLen(mod)) {
72767274 1...8 => .{ .v_ps, .blendv },
72777275 else => null,
72787276 },
7279 64 => switch (lhs_ty.vectorLen()) {
7277 64 => switch (lhs_ty.vectorLen(mod)) {
72807278 1...4 => .{ .v_pd, .blendv },
72817279 else => null,
72827280 },
......@@ -7304,14 +7302,14 @@ fn genBinOp(
73047302 16, 80, 128 => null,
73057303 else => unreachable,
73067304 },
7307 .Vector => switch (lhs_ty.childType().zigTypeTag(mod)) {
7308 .Float => switch (lhs_ty.childType().floatBits(self.target.*)) {
7309 32 => switch (lhs_ty.vectorLen()) {
7305 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
7306 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
7307 32 => switch (lhs_ty.vectorLen(mod)) {
73107308 1 => .{ ._ss, .cmp },
73117309 2...4 => .{ ._ps, .cmp },
73127310 else => null,
73137311 },
7314 64 => switch (lhs_ty.vectorLen()) {
7312 64 => switch (lhs_ty.vectorLen(mod)) {
73157313 1 => .{ ._sd, .cmp },
73167314 2 => .{ ._pd, .cmp },
73177315 else => null,
......@@ -7337,13 +7335,13 @@ fn genBinOp(
73377335 16, 80, 128 => null,
73387336 else => unreachable,
73397337 },
7340 .Vector => switch (lhs_ty.childType().zigTypeTag(mod)) {
7341 .Float => switch (lhs_ty.childType().floatBits(self.target.*)) {
7342 32 => switch (lhs_ty.vectorLen()) {
7338 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
7339 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
7340 32 => switch (lhs_ty.vectorLen(mod)) {
73437341 1...4 => .{ ._ps, .blendv },
73447342 else => null,
73457343 },
7346 64 => switch (lhs_ty.vectorLen()) {
7344 64 => switch (lhs_ty.vectorLen(mod)) {
73477345 1...2 => .{ ._pd, .blendv },
73487346 else => null,
73497347 },
......@@ -7368,13 +7366,13 @@ fn genBinOp(
73687366 16, 80, 128 => null,
73697367 else => unreachable,
73707368 },
7371 .Vector => switch (lhs_ty.childType().zigTypeTag(mod)) {
7372 .Float => switch (lhs_ty.childType().floatBits(self.target.*)) {
7373 32 => switch (lhs_ty.vectorLen()) {
7369 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
7370 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
7371 32 => switch (lhs_ty.vectorLen(mod)) {
73747372 1...4 => .{ ._ps, .@"and" },
73757373 else => null,
73767374 },
7377 64 => switch (lhs_ty.vectorLen()) {
7375 64 => switch (lhs_ty.vectorLen(mod)) {
73787376 1...2 => .{ ._pd, .@"and" },
73797377 else => null,
73807378 },
......@@ -7398,13 +7396,13 @@ fn genBinOp(
73987396 16, 80, 128 => null,
73997397 else => unreachable,
74007398 },
7401 .Vector => switch (lhs_ty.childType().zigTypeTag(mod)) {
7402 .Float => switch (lhs_ty.childType().floatBits(self.target.*)) {
7403 32 => switch (lhs_ty.vectorLen()) {
7399 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
7400 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
7401 32 => switch (lhs_ty.vectorLen(mod)) {
74047402 1...4 => .{ ._ps, .andn },
74057403 else => null,
74067404 },
7407 64 => switch (lhs_ty.vectorLen()) {
7405 64 => switch (lhs_ty.vectorLen(mod)) {
74087406 1...2 => .{ ._pd, .andn },
74097407 else => null,
74107408 },
......@@ -7428,13 +7426,13 @@ fn genBinOp(
74287426 16, 80, 128 => null,
74297427 else => unreachable,
74307428 },
7431 .Vector => switch (lhs_ty.childType().zigTypeTag(mod)) {
7432 .Float => switch (lhs_ty.childType().floatBits(self.target.*)) {
7433 32 => switch (lhs_ty.vectorLen()) {
7429 .Vector => switch (lhs_ty.childType(mod).zigTypeTag(mod)) {
7430 .Float => switch (lhs_ty.childType(mod).floatBits(self.target.*)) {
7431 32 => switch (lhs_ty.vectorLen(mod)) {
74347432 1...4 => .{ ._ps, .@"or" },
74357433 else => null,
74367434 },
7437 64 => switch (lhs_ty.vectorLen()) {
7435 64 => switch (lhs_ty.vectorLen(mod)) {
74387436 1...2 => .{ ._pd, .@"or" },
74397437 else => null,
74407438 },
......@@ -7586,11 +7584,7 @@ fn genBinOpMir(
75867584 .load_got,
75877585 .load_tlv,
75887586 => {
7589 var ptr_pl = Type.Payload.ElemType{
7590 .base = .{ .tag = .single_const_pointer },
7591 .data = ty,
7592 };
7593 const ptr_ty = Type.initPayload(&ptr_pl.base);
7587 const ptr_ty = try mod.singleConstPtrType(ty);
75947588 const addr_reg = try self.copyToTmpRegister(ptr_ty, src_mcv.address());
75957589 return self.genBinOpMir(mir_tag, ty, dst_mcv, .{
75967590 .indirect = .{ .reg = addr_reg },
......@@ -8058,7 +8052,7 @@ fn airCall(self: *Self, inst: Air.Inst.Index, modifier: std.builtin.CallModifier
80588052
80598053 const fn_ty = switch (ty.zigTypeTag(mod)) {
80608054 .Fn => ty,
8061 .Pointer => ty.childType(),
8055 .Pointer => ty.childType(mod),
80628056 else => unreachable,
80638057 };
80648058
......@@ -8506,10 +8500,11 @@ fn airTry(self: *Self, inst: Air.Inst.Index) !void {
85068500}
85078501
85088502fn airTryPtr(self: *Self, inst: Air.Inst.Index) !void {
8503 const mod = self.bin_file.options.module.?;
85098504 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
85108505 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
85118506 const body = self.air.extra[extra.end..][0..extra.data.body_len];
8512 const err_union_ty = self.typeOf(extra.data.ptr).childType();
8507 const err_union_ty = self.typeOf(extra.data.ptr).childType(mod);
85138508 const result = try self.genTry(inst, extra.data.ptr, body, err_union_ty, true);
85148509 return self.finishAir(inst, result, .{ .none, .none, .none });
85158510}
......@@ -8683,8 +8678,7 @@ fn isNull(self: *Self, inst: Air.Inst.Index, opt_ty: Type, opt_mcv: MCValue) !MC
86838678 try self.spillEflagsIfOccupied();
86848679 self.eflags_inst = inst;
86858680
8686 var pl_buf: Type.Payload.ElemType = undefined;
8687 const pl_ty = opt_ty.optionalChild(&pl_buf);
8681 const pl_ty = opt_ty.optionalChild(mod);
86888682
86898683 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;
86908684 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))
......@@ -8775,9 +8769,8 @@ fn isNullPtr(self: *Self, inst: Air.Inst.Index, ptr_ty: Type, ptr_mcv: MCValue)
87758769 try self.spillEflagsIfOccupied();
87768770 self.eflags_inst = inst;
87778771
8778 const opt_ty = ptr_ty.childType();
8779 var pl_buf: Type.Payload.ElemType = undefined;
8780 const pl_ty = opt_ty.optionalChild(&pl_buf);
8772 const opt_ty = ptr_ty.childType(mod);
8773 const pl_ty = opt_ty.optionalChild(mod);
87818774
87828775 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;
87838776 const some_info: struct { off: i32, ty: Type } = if (opt_ty.optionalReprIsPayload(mod))
......@@ -8919,6 +8912,7 @@ fn airIsErr(self: *Self, inst: Air.Inst.Index) !void {
89198912}
89208913
89218914fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
8915 const mod = self.bin_file.options.module.?;
89228916 const un_op = self.air.instructions.items(.data)[inst].un_op;
89238917
89248918 const operand_ptr = try self.resolveInst(un_op);
......@@ -8939,7 +8933,7 @@ fn airIsErrPtr(self: *Self, inst: Air.Inst.Index) !void {
89398933 const ptr_ty = self.typeOf(un_op);
89408934 try self.load(operand, ptr_ty, operand_ptr);
89418935
8942 const result = try self.isErr(inst, ptr_ty.childType(), operand);
8936 const result = try self.isErr(inst, ptr_ty.childType(mod), operand);
89438937
89448938 return self.finishAir(inst, result, .{ un_op, .none, .none });
89458939}
......@@ -8953,6 +8947,7 @@ fn airIsNonErr(self: *Self, inst: Air.Inst.Index) !void {
89538947}
89548948
89558949fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
8950 const mod = self.bin_file.options.module.?;
89568951 const un_op = self.air.instructions.items(.data)[inst].un_op;
89578952
89588953 const operand_ptr = try self.resolveInst(un_op);
......@@ -8973,7 +8968,7 @@ fn airIsNonErrPtr(self: *Self, inst: Air.Inst.Index) !void {
89738968 const ptr_ty = self.typeOf(un_op);
89748969 try self.load(operand, ptr_ty, operand_ptr);
89758970
8976 const result = try self.isNonErr(inst, ptr_ty.childType(), operand);
8971 const result = try self.isNonErr(inst, ptr_ty.childType(mod), operand);
89778972
89788973 return self.finishAir(inst, result, .{ un_op, .none, .none });
89798974}
......@@ -9452,9 +9447,9 @@ fn moveStrategy(self: *Self, ty: Type, aligned: bool) !MoveStrategy {
94529447 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
94539448 else => {},
94549449 },
9455 .Vector => switch (ty.childType().zigTypeTag(mod)) {
9456 .Int => switch (ty.childType().intInfo(mod).bits) {
9457 8 => switch (ty.vectorLen()) {
9450 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
9451 .Int => switch (ty.childType(mod).intInfo(mod).bits) {
9452 8 => switch (ty.vectorLen(mod)) {
94589453 1 => if (self.hasFeature(.avx)) return .{ .vex_insert_extract = .{
94599454 .insert = .{ .vp_b, .insr },
94609455 .extract = .{ .vp_b, .extr },
......@@ -9484,7 +9479,7 @@ fn moveStrategy(self: *Self, ty: Type, aligned: bool) !MoveStrategy {
94849479 return .{ .move = if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu } },
94859480 else => {},
94869481 },
9487 16 => switch (ty.vectorLen()) {
9482 16 => switch (ty.vectorLen(mod)) {
94889483 1 => return if (self.hasFeature(.avx)) .{ .vex_insert_extract = .{
94899484 .insert = .{ .vp_w, .insr },
94909485 .extract = .{ .vp_w, .extr },
......@@ -9507,7 +9502,7 @@ fn moveStrategy(self: *Self, ty: Type, aligned: bool) !MoveStrategy {
95079502 return .{ .move = if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu } },
95089503 else => {},
95099504 },
9510 32 => switch (ty.vectorLen()) {
9505 32 => switch (ty.vectorLen(mod)) {
95119506 1 => return .{ .move = if (self.hasFeature(.avx))
95129507 .{ .v_d, .mov }
95139508 else
......@@ -9523,7 +9518,7 @@ fn moveStrategy(self: *Self, ty: Type, aligned: bool) !MoveStrategy {
95239518 return .{ .move = if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu } },
95249519 else => {},
95259520 },
9526 64 => switch (ty.vectorLen()) {
9521 64 => switch (ty.vectorLen(mod)) {
95279522 1 => return .{ .move = if (self.hasFeature(.avx))
95289523 .{ .v_q, .mov }
95299524 else
......@@ -9535,7 +9530,7 @@ fn moveStrategy(self: *Self, ty: Type, aligned: bool) !MoveStrategy {
95359530 return .{ .move = if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu } },
95369531 else => {},
95379532 },
9538 128 => switch (ty.vectorLen()) {
9533 128 => switch (ty.vectorLen(mod)) {
95399534 1 => return .{ .move = if (self.hasFeature(.avx))
95409535 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
95419536 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
......@@ -9543,15 +9538,15 @@ fn moveStrategy(self: *Self, ty: Type, aligned: bool) !MoveStrategy {
95439538 return .{ .move = if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu } },
95449539 else => {},
95459540 },
9546 256 => switch (ty.vectorLen()) {
9541 256 => switch (ty.vectorLen(mod)) {
95479542 1 => if (self.hasFeature(.avx))
95489543 return .{ .move = if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu } },
95499544 else => {},
95509545 },
95519546 else => {},
95529547 },
9553 .Float => switch (ty.childType().floatBits(self.target.*)) {
9554 16 => switch (ty.vectorLen()) {
9548 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
9549 16 => switch (ty.vectorLen(mod)) {
95559550 1 => return if (self.hasFeature(.avx)) .{ .vex_insert_extract = .{
95569551 .insert = .{ .vp_w, .insr },
95579552 .extract = .{ .vp_w, .extr },
......@@ -9574,7 +9569,7 @@ fn moveStrategy(self: *Self, ty: Type, aligned: bool) !MoveStrategy {
95749569 return .{ .move = if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu } },
95759570 else => {},
95769571 },
9577 32 => switch (ty.vectorLen()) {
9572 32 => switch (ty.vectorLen(mod)) {
95789573 1 => return .{ .move = if (self.hasFeature(.avx))
95799574 .{ .v_ss, .mov }
95809575 else
......@@ -9590,7 +9585,7 @@ fn moveStrategy(self: *Self, ty: Type, aligned: bool) !MoveStrategy {
95909585 return .{ .move = if (aligned) .{ .v_ps, .mova } else .{ .v_ps, .movu } },
95919586 else => {},
95929587 },
9593 64 => switch (ty.vectorLen()) {
9588 64 => switch (ty.vectorLen(mod)) {
95949589 1 => return .{ .move = if (self.hasFeature(.avx))
95959590 .{ .v_sd, .mov }
95969591 else
......@@ -9602,7 +9597,7 @@ fn moveStrategy(self: *Self, ty: Type, aligned: bool) !MoveStrategy {
96029597 return .{ .move = if (aligned) .{ .v_pd, .mova } else .{ .v_pd, .movu } },
96039598 else => {},
96049599 },
9605 128 => switch (ty.vectorLen()) {
9600 128 => switch (ty.vectorLen(mod)) {
96069601 1 => return .{ .move = if (self.hasFeature(.avx))
96079602 if (aligned) .{ .v_, .movdqa } else .{ .v_, .movdqu }
96089603 else if (aligned) .{ ._, .movdqa } else .{ ._, .movdqu } },
......@@ -10248,8 +10243,8 @@ fn airArrayToSlice(self: *Self, inst: Air.Inst.Index) !void {
1024810243 const slice_ty = self.typeOfIndex(inst);
1024910244 const ptr_ty = self.typeOf(ty_op.operand);
1025010245 const ptr = try self.resolveInst(ty_op.operand);
10251 const array_ty = ptr_ty.childType();
10252 const array_len = array_ty.arrayLen();
10246 const array_ty = ptr_ty.childType(mod);
10247 const array_len = array_ty.arrayLen(mod);
1025310248
1025410249 const frame_index = try self.allocFrameIndex(FrameAlloc.initType(slice_ty, mod));
1025510250 try self.genSetMem(.{ .frame = frame_index }, 0, ptr_ty, ptr);
......@@ -10790,16 +10785,16 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1079010785 const elem_abi_size = @intCast(u31, elem_ty.abiSize(mod));
1079110786
1079210787 if (elem_abi_size == 1) {
10793 const ptr: MCValue = switch (dst_ptr_ty.ptrSize()) {
10788 const ptr: MCValue = switch (dst_ptr_ty.ptrSize(mod)) {
1079410789 // TODO: this only handles slices stored in the stack
1079510790 .Slice => dst_ptr,
1079610791 .One => dst_ptr,
1079710792 .C, .Many => unreachable,
1079810793 };
10799 const len: MCValue = switch (dst_ptr_ty.ptrSize()) {
10794 const len: MCValue = switch (dst_ptr_ty.ptrSize(mod)) {
1080010795 // TODO: this only handles slices stored in the stack
1080110796 .Slice => dst_ptr.address().offset(8).deref(),
10802 .One => .{ .immediate = dst_ptr_ty.childType().arrayLen() },
10797 .One => .{ .immediate = dst_ptr_ty.childType(mod).arrayLen(mod) },
1080310798 .C, .Many => unreachable,
1080410799 };
1080510800 const len_lock: ?RegisterLock = switch (len) {
......@@ -10815,7 +10810,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1081510810 // Store the first element, and then rely on memcpy copying forwards.
1081610811 // Length zero requires a runtime check - so we handle arrays specially
1081710812 // here to elide it.
10818 switch (dst_ptr_ty.ptrSize()) {
10813 switch (dst_ptr_ty.ptrSize(mod)) {
1081910814 .Slice => {
1082010815 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
1082110816 const slice_ptr_ty = dst_ptr_ty.slicePtrFieldType(&buf);
......@@ -10858,13 +10853,9 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1085810853 try self.performReloc(skip_reloc);
1085910854 },
1086010855 .One => {
10861 var elem_ptr_pl = Type.Payload.ElemType{
10862 .base = .{ .tag = .single_mut_pointer },
10863 .data = elem_ty,
10864 };
10865 const elem_ptr_ty = Type.initPayload(&elem_ptr_pl.base);
10856 const elem_ptr_ty = try mod.singleMutPtrType(elem_ty);
1086610857
10867 const len = dst_ptr_ty.childType().arrayLen();
10858 const len = dst_ptr_ty.childType(mod).arrayLen(mod);
1086810859
1086910860 assert(len != 0); // prevented by Sema
1087010861 try self.store(elem_ptr_ty, dst_ptr, src_val);
......@@ -10889,6 +10880,7 @@ fn airMemset(self: *Self, inst: Air.Inst.Index, safety: bool) !void {
1088910880}
1089010881
1089110882fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
10883 const mod = self.bin_file.options.module.?;
1089210884 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
1089310885
1089410886 const dst_ptr = try self.resolveInst(bin_op.lhs);
......@@ -10906,9 +10898,9 @@ fn airMemcpy(self: *Self, inst: Air.Inst.Index) !void {
1090610898 };
1090710899 defer if (src_ptr_lock) |lock| self.register_manager.unlockReg(lock);
1090810900
10909 const len: MCValue = switch (dst_ptr_ty.ptrSize()) {
10901 const len: MCValue = switch (dst_ptr_ty.ptrSize(mod)) {
1091010902 .Slice => dst_ptr.address().offset(8).deref(),
10911 .One => .{ .immediate = dst_ptr_ty.childType().arrayLen() },
10903 .One => .{ .immediate = dst_ptr_ty.childType(mod).arrayLen(mod) },
1091210904 .C, .Many => unreachable,
1091310905 };
1091410906 const len_lock: ?RegisterLock = switch (len) {
......@@ -11059,7 +11051,7 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
1105911051 switch (scalar_ty.zigTypeTag(mod)) {
1106011052 else => {},
1106111053 .Float => switch (scalar_ty.floatBits(self.target.*)) {
11062 32 => switch (vector_ty.vectorLen()) {
11054 32 => switch (vector_ty.vectorLen(mod)) {
1106311055 1 => {
1106411056 if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) break :result src_mcv;
1106511057 const dst_reg = try self.register_manager.allocReg(inst, dst_rc);
......@@ -11139,7 +11131,7 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
1113911131 },
1114011132 else => {},
1114111133 },
11142 64 => switch (vector_ty.vectorLen()) {
11134 64 => switch (vector_ty.vectorLen(mod)) {
1114311135 1 => {
1114411136 if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) break :result src_mcv;
1114511137 const dst_reg = try self.register_manager.allocReg(inst, dst_rc);
......@@ -11205,7 +11197,7 @@ fn airSplat(self: *Self, inst: Air.Inst.Index) !void {
1120511197 },
1120611198 else => {},
1120711199 },
11208 128 => switch (vector_ty.vectorLen()) {
11200 128 => switch (vector_ty.vectorLen(mod)) {
1120911201 1 => {
1121011202 if (self.reuseOperand(inst, ty_op.operand, 0, src_mcv)) break :result src_mcv;
1121111203 const dst_reg = try self.register_manager.allocReg(inst, dst_rc);
......@@ -11271,7 +11263,7 @@ fn airReduce(self: *Self, inst: Air.Inst.Index) !void {
1127111263fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1127211264 const mod = self.bin_file.options.module.?;
1127311265 const result_ty = self.typeOfIndex(inst);
11274 const len = @intCast(usize, result_ty.arrayLen());
11266 const len = @intCast(usize, result_ty.arrayLen(mod));
1127511267 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
1127611268 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
1127711269 const result: MCValue = result: {
......@@ -11375,7 +11367,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1137511367 .Array => {
1137611368 const frame_index =
1137711369 try self.allocFrameIndex(FrameAlloc.initType(result_ty, mod));
11378 const elem_ty = result_ty.childType();
11370 const elem_ty = result_ty.childType(mod);
1137911371 const elem_size = @intCast(u32, elem_ty.abiSize(mod));
1138011372
1138111373 for (elements, 0..) |elem, elem_i| {
......@@ -11387,7 +11379,7 @@ fn airAggregateInit(self: *Self, inst: Air.Inst.Index) !void {
1138711379 const elem_off = @intCast(i32, elem_size * elem_i);
1138811380 try self.genSetMem(.{ .frame = frame_index }, elem_off, elem_ty, mat_elem_mcv);
1138911381 }
11390 if (result_ty.sentinel()) |sentinel| try self.genSetMem(
11382 if (result_ty.sentinel(mod)) |sentinel| try self.genSetMem(
1139111383 .{ .frame = frame_index },
1139211384 @intCast(i32, elem_size * elements.len),
1139311385 elem_ty,
......@@ -11512,14 +11504,14 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1151211504 16, 80, 128 => null,
1151311505 else => unreachable,
1151411506 },
11515 .Vector => switch (ty.childType().zigTypeTag(mod)) {
11516 .Float => switch (ty.childType().floatBits(self.target.*)) {
11517 32 => switch (ty.vectorLen()) {
11507 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
11508 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
11509 32 => switch (ty.vectorLen(mod)) {
1151811510 1 => .{ .v_ss, .fmadd132 },
1151911511 2...8 => .{ .v_ps, .fmadd132 },
1152011512 else => null,
1152111513 },
11522 64 => switch (ty.vectorLen()) {
11514 64 => switch (ty.vectorLen(mod)) {
1152311515 1 => .{ .v_sd, .fmadd132 },
1152411516 2...4 => .{ .v_pd, .fmadd132 },
1152511517 else => null,
......@@ -11539,14 +11531,14 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1153911531 16, 80, 128 => null,
1154011532 else => unreachable,
1154111533 },
11542 .Vector => switch (ty.childType().zigTypeTag(mod)) {
11543 .Float => switch (ty.childType().floatBits(self.target.*)) {
11544 32 => switch (ty.vectorLen()) {
11534 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
11535 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
11536 32 => switch (ty.vectorLen(mod)) {
1154511537 1 => .{ .v_ss, .fmadd213 },
1154611538 2...8 => .{ .v_ps, .fmadd213 },
1154711539 else => null,
1154811540 },
11549 64 => switch (ty.vectorLen()) {
11541 64 => switch (ty.vectorLen(mod)) {
1155011542 1 => .{ .v_sd, .fmadd213 },
1155111543 2...4 => .{ .v_pd, .fmadd213 },
1155211544 else => null,
......@@ -11566,14 +11558,14 @@ fn airMulAdd(self: *Self, inst: Air.Inst.Index) !void {
1156611558 16, 80, 128 => null,
1156711559 else => unreachable,
1156811560 },
11569 .Vector => switch (ty.childType().zigTypeTag(mod)) {
11570 .Float => switch (ty.childType().floatBits(self.target.*)) {
11571 32 => switch (ty.vectorLen()) {
11561 .Vector => switch (ty.childType(mod).zigTypeTag(mod)) {
11562 .Float => switch (ty.childType(mod).floatBits(self.target.*)) {
11563 32 => switch (ty.vectorLen(mod)) {
1157211564 1 => .{ .v_ss, .fmadd231 },
1157311565 2...8 => .{ .v_ps, .fmadd231 },
1157411566 else => null,
1157511567 },
11576 64 => switch (ty.vectorLen()) {
11568 64 => switch (ty.vectorLen(mod)) {
1157711569 1 => .{ .v_sd, .fmadd231 },
1157811570 2...4 => .{ .v_pd, .fmadd231 },
1157911571 else => null,
src/arch/x86_64/abi.zig+3-3
......@@ -76,7 +76,7 @@ pub fn classifySystemV(ty: Type, mod: *const Module, ctx: Context) [8]Class {
7676 };
7777 var result = [1]Class{.none} ** 8;
7878 switch (ty.zigTypeTag(mod)) {
79 .Pointer => switch (ty.ptrSize()) {
79 .Pointer => switch (ty.ptrSize(mod)) {
8080 .Slice => {
8181 result[0] = .integer;
8282 result[1] = .integer;
......@@ -158,8 +158,8 @@ pub fn classifySystemV(ty: Type, mod: *const Module, ctx: Context) [8]Class {
158158 else => unreachable,
159159 },
160160 .Vector => {
161 const elem_ty = ty.childType();
162 const bits = elem_ty.bitSize(mod) * ty.arrayLen();
161 const elem_ty = ty.childType(mod);
162 const bits = elem_ty.bitSize(mod) * ty.arrayLen(mod);
163163 if (bits <= 64) return .{
164164 .sse, .none, .none, .none,
165165 .none, .none, .none, .none,
src/codegen.zig+17-19
......@@ -230,7 +230,7 @@ pub fn generateSymbol(
230230 .Array => switch (typed_value.val.tag()) {
231231 .bytes => {
232232 const bytes = typed_value.val.castTag(.bytes).?.data;
233 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());
233 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel(mod));
234234 // The bytes payload already includes the sentinel, if any
235235 try code.ensureUnusedCapacity(len);
236236 code.appendSliceAssumeCapacity(bytes[0..len]);
......@@ -241,7 +241,7 @@ pub fn generateSymbol(
241241 const bytes = mod.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
242242 try code.ensureUnusedCapacity(bytes.len + 1);
243243 code.appendSliceAssumeCapacity(bytes);
244 if (typed_value.ty.sentinel()) |sent_val| {
244 if (typed_value.ty.sentinel(mod)) |sent_val| {
245245 const byte = @intCast(u8, sent_val.toUnsignedInt(mod));
246246 code.appendAssumeCapacity(byte);
247247 }
......@@ -249,8 +249,8 @@ pub fn generateSymbol(
249249 },
250250 .aggregate => {
251251 const elem_vals = typed_value.val.castTag(.aggregate).?.data;
252 const elem_ty = typed_value.ty.elemType();
253 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel());
252 const elem_ty = typed_value.ty.childType(mod);
253 const len = @intCast(usize, typed_value.ty.arrayLenIncludingSentinel(mod));
254254 for (elem_vals[0..len]) |elem_val| {
255255 switch (try generateSymbol(bin_file, src_loc, .{
256256 .ty = elem_ty,
......@@ -264,9 +264,9 @@ pub fn generateSymbol(
264264 },
265265 .repeated => {
266266 const array = typed_value.val.castTag(.repeated).?.data;
267 const elem_ty = typed_value.ty.childType();
268 const sentinel = typed_value.ty.sentinel();
269 const len = typed_value.ty.arrayLen();
267 const elem_ty = typed_value.ty.childType(mod);
268 const sentinel = typed_value.ty.sentinel(mod);
269 const len = typed_value.ty.arrayLen(mod);
270270
271271 var index: u64 = 0;
272272 while (index < len) : (index += 1) {
......@@ -292,8 +292,8 @@ pub fn generateSymbol(
292292 return Result.ok;
293293 },
294294 .empty_array_sentinel => {
295 const elem_ty = typed_value.ty.childType();
296 const sentinel_val = typed_value.ty.sentinel().?;
295 const elem_ty = typed_value.ty.childType(mod);
296 const sentinel_val = typed_value.ty.sentinel(mod).?;
297297 switch (try generateSymbol(bin_file, src_loc, .{
298298 .ty = elem_ty,
299299 .val = sentinel_val,
......@@ -618,8 +618,7 @@ pub fn generateSymbol(
618618 return Result.ok;
619619 },
620620 .Optional => {
621 var opt_buf: Type.Payload.ElemType = undefined;
622 const payload_type = typed_value.ty.optionalChild(&opt_buf);
621 const payload_type = typed_value.ty.optionalChild(mod);
623622 const is_pl = !typed_value.val.isNull(mod);
624623 const abi_size = math.cast(usize, typed_value.ty.abiSize(mod)) orelse return error.Overflow;
625624
......@@ -751,7 +750,7 @@ pub fn generateSymbol(
751750 .Vector => switch (typed_value.val.tag()) {
752751 .bytes => {
753752 const bytes = typed_value.val.castTag(.bytes).?.data;
754 const len = math.cast(usize, typed_value.ty.arrayLen()) orelse return error.Overflow;
753 const len = math.cast(usize, typed_value.ty.arrayLen(mod)) orelse return error.Overflow;
755754 const padding = math.cast(usize, typed_value.ty.abiSize(mod) - len) orelse
756755 return error.Overflow;
757756 try code.ensureUnusedCapacity(len + padding);
......@@ -761,8 +760,8 @@ pub fn generateSymbol(
761760 },
762761 .aggregate => {
763762 const elem_vals = typed_value.val.castTag(.aggregate).?.data;
764 const elem_ty = typed_value.ty.elemType();
765 const len = math.cast(usize, typed_value.ty.arrayLen()) orelse return error.Overflow;
763 const elem_ty = typed_value.ty.childType(mod);
764 const len = math.cast(usize, typed_value.ty.arrayLen(mod)) orelse return error.Overflow;
766765 const padding = math.cast(usize, typed_value.ty.abiSize(mod) -
767766 (math.divCeil(u64, elem_ty.bitSize(mod) * len, 8) catch |err| switch (err) {
768767 error.DivisionByZero => unreachable,
......@@ -782,8 +781,8 @@ pub fn generateSymbol(
782781 },
783782 .repeated => {
784783 const array = typed_value.val.castTag(.repeated).?.data;
785 const elem_ty = typed_value.ty.childType();
786 const len = typed_value.ty.arrayLen();
784 const elem_ty = typed_value.ty.childType(mod);
785 const len = typed_value.ty.arrayLen(mod);
787786 const padding = math.cast(usize, typed_value.ty.abiSize(mod) -
788787 (math.divCeil(u64, elem_ty.bitSize(mod) * len, 8) catch |err| switch (err) {
789788 error.DivisionByZero => unreachable,
......@@ -1188,7 +1187,7 @@ pub fn genTypedValue(
11881187
11891188 switch (typed_value.ty.zigTypeTag(mod)) {
11901189 .Void => return GenResult.mcv(.none),
1191 .Pointer => switch (typed_value.ty.ptrSize()) {
1190 .Pointer => switch (typed_value.ty.ptrSize(mod)) {
11921191 .Slice => {},
11931192 else => {
11941193 switch (typed_value.val.tag()) {
......@@ -1219,9 +1218,8 @@ pub fn genTypedValue(
12191218 if (typed_value.ty.isPtrLikeOptional(mod)) {
12201219 if (typed_value.val.tag() == .null_value) return GenResult.mcv(.{ .immediate = 0 });
12211220
1222 var buf: Type.Payload.ElemType = undefined;
12231221 return genTypedValue(bin_file, src_loc, .{
1224 .ty = typed_value.ty.optionalChild(&buf),
1222 .ty = typed_value.ty.optionalChild(mod),
12251223 .val = if (typed_value.val.castTag(.opt_payload)) |pl| pl.data else typed_value.val,
12261224 }, owner_decl_index);
12271225 } else if (typed_value.ty.abiSize(mod) == 1) {
src/codegen/c.zig+106-97
......@@ -625,7 +625,9 @@ pub const DeclGen = struct {
625625 // Ensure complete type definition is visible before accessing fields.
626626 _ = try dg.typeToIndex(field_ptr.container_ty, .complete);
627627
628 var container_ptr_pl = ptr_ty.ptrInfo();
628 var container_ptr_pl: Type.Payload.Pointer = .{
629 .data = ptr_ty.ptrInfo(mod),
630 };
629631 container_ptr_pl.data.pointee_type = field_ptr.container_ty;
630632 const container_ptr_ty = Type.initPayload(&container_ptr_pl.base);
631633
......@@ -653,7 +655,9 @@ pub const DeclGen = struct {
653655 try dg.writeCValue(writer, field);
654656 },
655657 .byte_offset => |byte_offset| {
656 var u8_ptr_pl = ptr_ty.ptrInfo();
658 var u8_ptr_pl: Type.Payload.Pointer = .{
659 .data = ptr_ty.ptrInfo(mod),
660 };
657661 u8_ptr_pl.data.pointee_type = Type.u8;
658662 const u8_ptr_ty = Type.initPayload(&u8_ptr_pl.base);
659663
......@@ -692,11 +696,10 @@ pub const DeclGen = struct {
692696 },
693697 .elem_ptr => {
694698 const elem_ptr = ptr_val.castTag(.elem_ptr).?.data;
695 var elem_ptr_ty_pl: Type.Payload.ElemType = .{
696 .base = .{ .tag = .c_mut_pointer },
697 .data = elem_ptr.elem_ty,
698 };
699 const elem_ptr_ty = Type.initPayload(&elem_ptr_ty_pl.base);
699 const elem_ptr_ty = try mod.ptrType(.{
700 .size = .C,
701 .elem_type = elem_ptr.elem_ty.ip_index,
702 });
700703
701704 try writer.writeAll("&(");
702705 try dg.renderParentPtr(writer, elem_ptr.array_ptr, elem_ptr_ty, location);
......@@ -704,11 +707,10 @@ pub const DeclGen = struct {
704707 },
705708 .opt_payload_ptr, .eu_payload_ptr => {
706709 const payload_ptr = ptr_val.cast(Value.Payload.PayloadPtr).?.data;
707 var container_ptr_ty_pl: Type.Payload.ElemType = .{
708 .base = .{ .tag = .c_mut_pointer },
709 .data = payload_ptr.container_ty,
710 };
711 const container_ptr_ty = Type.initPayload(&container_ptr_ty_pl.base);
710 const container_ptr_ty = try mod.ptrType(.{
711 .elem_type = payload_ptr.container_ty.ip_index,
712 .size = .C,
713 });
712714
713715 // Ensure complete type definition is visible before accessing fields.
714716 _ = try dg.typeToIndex(payload_ptr.container_ty, .complete);
......@@ -794,8 +796,7 @@ pub const DeclGen = struct {
794796 return writer.print("){x})", .{try dg.fmtIntLiteral(Type.usize, val, .Other)});
795797 },
796798 .Optional => {
797 var opt_buf: Type.Payload.ElemType = undefined;
798 const payload_ty = ty.optionalChild(&opt_buf);
799 const payload_ty = ty.optionalChild(mod);
799800
800801 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
801802 return dg.renderValue(writer, Type.bool, val, location);
......@@ -889,11 +890,11 @@ pub const DeclGen = struct {
889890 return writer.writeAll(" }");
890891 },
891892 .Array, .Vector => {
892 const ai = ty.arrayInfo();
893 const ai = ty.arrayInfo(mod);
893894 if (ai.elem_type.eql(Type.u8, dg.module)) {
894895 var literal = stringLiteral(writer);
895896 try literal.start();
896 const c_len = ty.arrayLenIncludingSentinel();
897 const c_len = ty.arrayLenIncludingSentinel(mod);
897898 var index: u64 = 0;
898899 while (index < c_len) : (index += 1)
899900 try literal.writeChar(0xaa);
......@@ -906,11 +907,11 @@ pub const DeclGen = struct {
906907 }
907908
908909 try writer.writeByte('{');
909 const c_len = ty.arrayLenIncludingSentinel();
910 const c_len = ty.arrayLenIncludingSentinel(mod);
910911 var index: u64 = 0;
911912 while (index < c_len) : (index += 1) {
912913 if (index > 0) try writer.writeAll(", ");
913 try dg.renderValue(writer, ty.childType(), val, initializer_type);
914 try dg.renderValue(writer, ty.childType(mod), val, initializer_type);
914915 }
915916 return writer.writeByte('}');
916917 }
......@@ -1110,7 +1111,7 @@ pub const DeclGen = struct {
11101111 // First try specific tag representations for more efficiency.
11111112 switch (val.tag()) {
11121113 .undef, .empty_struct_value, .empty_array => {
1113 const ai = ty.arrayInfo();
1114 const ai = ty.arrayInfo(mod);
11141115 try writer.writeByte('{');
11151116 if (ai.sentinel) |s| {
11161117 try dg.renderValue(writer, ai.elem_type, s, initializer_type);
......@@ -1128,9 +1129,9 @@ pub const DeclGen = struct {
11281129 },
11291130 else => unreachable,
11301131 };
1131 const sentinel = if (ty.sentinel()) |sentinel| @intCast(u8, sentinel.toUnsignedInt(mod)) else null;
1132 const sentinel = if (ty.sentinel(mod)) |sentinel| @intCast(u8, sentinel.toUnsignedInt(mod)) else null;
11321133 try writer.print("{s}", .{
1133 fmtStringLiteral(bytes[0..@intCast(usize, ty.arrayLen())], sentinel),
1134 fmtStringLiteral(bytes[0..@intCast(usize, ty.arrayLen(mod))], sentinel),
11341135 });
11351136 },
11361137 else => {
......@@ -1142,7 +1143,7 @@ pub const DeclGen = struct {
11421143 // MSVC throws C2078 if an array of size 65536 or greater is initialized with a string literal
11431144 const max_string_initializer_len = 65535;
11441145
1145 const ai = ty.arrayInfo();
1146 const ai = ty.arrayInfo(mod);
11461147 if (ai.elem_type.eql(Type.u8, dg.module)) {
11471148 if (ai.len <= max_string_initializer_len) {
11481149 var literal = stringLiteral(writer);
......@@ -1198,8 +1199,7 @@ pub const DeclGen = struct {
11981199 }
11991200 },
12001201 .Optional => {
1201 var opt_buf: Type.Payload.ElemType = undefined;
1202 const payload_ty = ty.optionalChild(&opt_buf);
1202 const payload_ty = ty.optionalChild(mod);
12031203
12041204 const is_null_val = Value.makeBool(val.tag() == .null_value);
12051205 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod))
......@@ -2410,12 +2410,13 @@ pub fn genGlobalAsm(mod: *Module, writer: anytype) !void {
24102410}
24112411
24122412pub fn genErrDecls(o: *Object) !void {
2413 const mod = o.dg.module;
24132414 const writer = o.writer();
24142415
24152416 try writer.writeAll("enum {\n");
24162417 o.indent_writer.pushIndent();
24172418 var max_name_len: usize = 0;
2418 for (o.dg.module.error_name_list.items, 0..) |name, value| {
2419 for (mod.error_name_list.items, 0..) |name, value| {
24192420 max_name_len = std.math.max(name.len, max_name_len);
24202421 var err_pl = Value.Payload.Error{ .data = .{ .name = name } };
24212422 try o.dg.renderValue(writer, Type.anyerror, Value.initPayload(&err_pl.base), .Other);
......@@ -2430,12 +2431,15 @@ pub fn genErrDecls(o: *Object) !void {
24302431 defer o.dg.gpa.free(name_buf);
24312432
24322433 @memcpy(name_buf[0..name_prefix.len], name_prefix);
2433 for (o.dg.module.error_name_list.items) |name| {
2434 for (mod.error_name_list.items) |name| {
24342435 @memcpy(name_buf[name_prefix.len..][0..name.len], name);
24352436 const identifier = name_buf[0 .. name_prefix.len + name.len];
24362437
2437 var name_ty_pl = Type.Payload.Len{ .base = .{ .tag = .array_u8_sentinel_0 }, .data = name.len };
2438 const name_ty = Type.initPayload(&name_ty_pl.base);
2438 const name_ty = try mod.arrayType(.{
2439 .len = name.len,
2440 .child = .u8_type,
2441 .sentinel = .zero_u8,
2442 });
24392443
24402444 var name_pl = Value.Payload.Bytes{ .base = .{ .tag = .bytes }, .data = name };
24412445 const name_val = Value.initPayload(&name_pl.base);
......@@ -2448,15 +2452,15 @@ pub fn genErrDecls(o: *Object) !void {
24482452 }
24492453
24502454 var name_array_ty_pl = Type.Payload.Array{ .base = .{ .tag = .array }, .data = .{
2451 .len = o.dg.module.error_name_list.items.len,
2452 .elem_type = Type.initTag(.const_slice_u8_sentinel_0),
2455 .len = mod.error_name_list.items.len,
2456 .elem_type = Type.const_slice_u8_sentinel_0,
24532457 } };
24542458 const name_array_ty = Type.initPayload(&name_array_ty_pl.base);
24552459
24562460 try writer.writeAll("static ");
24572461 try o.dg.renderTypeAndName(writer, name_array_ty, .{ .identifier = array_identifier }, Const, 0, .complete);
24582462 try writer.writeAll(" = {");
2459 for (o.dg.module.error_name_list.items, 0..) |name, value| {
2463 for (mod.error_name_list.items, 0..) |name, value| {
24602464 if (value != 0) try writer.writeByte(',');
24612465
24622466 var len_pl = Value.Payload.U64{ .base = .{ .tag = .int_u64 }, .data = name.len };
......@@ -2487,6 +2491,7 @@ fn genExports(o: *Object) !void {
24872491}
24882492
24892493pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
2494 const mod = o.dg.module;
24902495 const w = o.writer();
24912496 const key = lazy_fn.key_ptr.*;
24922497 const val = lazy_fn.value_ptr;
......@@ -2495,7 +2500,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
24952500 .tag_name => {
24962501 const enum_ty = val.data.tag_name;
24972502
2498 const name_slice_ty = Type.initTag(.const_slice_u8_sentinel_0);
2503 const name_slice_ty = Type.const_slice_u8_sentinel_0;
24992504
25002505 try w.writeAll("static ");
25012506 try o.dg.renderType(w, name_slice_ty);
......@@ -2514,11 +2519,11 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
25142519 var int_pl: Value.Payload.U64 = undefined;
25152520 const int_val = tag_val.enumToInt(enum_ty, &int_pl);
25162521
2517 var name_ty_pl = Type.Payload.Len{
2518 .base = .{ .tag = .array_u8_sentinel_0 },
2519 .data = name.len,
2520 };
2521 const name_ty = Type.initPayload(&name_ty_pl.base);
2522 const name_ty = try mod.arrayType(.{
2523 .len = name.len,
2524 .child = .u8_type,
2525 .sentinel = .zero_u8,
2526 });
25222527
25232528 var name_pl = Value.Payload.Bytes{ .base = .{ .tag = .bytes }, .data = name };
25242529 const name_val = Value.initPayload(&name_pl.base);
......@@ -2547,7 +2552,7 @@ pub fn genLazyFn(o: *Object, lazy_fn: LazyFnMap.Entry) !void {
25472552 try w.writeAll("}\n");
25482553 },
25492554 .never_tail, .never_inline => |fn_decl_index| {
2550 const fn_decl = o.dg.module.declPtr(fn_decl_index);
2555 const fn_decl = mod.declPtr(fn_decl_index);
25512556 const fn_cty = try o.dg.typeToCType(fn_decl.ty, .complete);
25522557 const fn_info = fn_cty.cast(CType.Payload.Function).?.data;
25532558
......@@ -3150,7 +3155,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
31503155
31513156 const inst_ty = f.typeOfIndex(inst);
31523157 const ptr_ty = f.typeOf(bin_op.lhs);
3153 const elem_ty = ptr_ty.childType();
3158 const elem_ty = ptr_ty.childType(mod);
31543159 const elem_has_bits = elem_ty.hasRuntimeBitsIgnoreComptime(mod);
31553160
31563161 const ptr = try f.resolveInst(bin_op.lhs);
......@@ -3166,7 +3171,7 @@ fn airPtrElemPtr(f: *Function, inst: Air.Inst.Index) !CValue {
31663171 try f.renderType(writer, inst_ty);
31673172 try writer.writeByte(')');
31683173 if (elem_has_bits) try writer.writeByte('&');
3169 if (elem_has_bits and ptr_ty.ptrSize() == .One) {
3174 if (elem_has_bits and ptr_ty.ptrSize(mod) == .One) {
31703175 // It's a pointer to an array, so we need to de-reference.
31713176 try f.writeCValueDeref(writer, ptr);
31723177 } else try f.writeCValue(writer, ptr, .Other);
......@@ -3264,7 +3269,7 @@ fn airArrayElemVal(f: *Function, inst: Air.Inst.Index) !CValue {
32643269fn airAlloc(f: *Function, inst: Air.Inst.Index) !CValue {
32653270 const mod = f.object.dg.module;
32663271 const inst_ty = f.typeOfIndex(inst);
3267 const elem_type = inst_ty.elemType();
3272 const elem_type = inst_ty.childType(mod);
32683273 if (!elem_type.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return .{ .undef = inst_ty };
32693274
32703275 const local = try f.allocLocalValue(
......@@ -3280,7 +3285,7 @@ fn airAlloc(f: *Function, inst: Air.Inst.Index) !CValue {
32803285fn airRetPtr(f: *Function, inst: Air.Inst.Index) !CValue {
32813286 const mod = f.object.dg.module;
32823287 const inst_ty = f.typeOfIndex(inst);
3283 const elem_ty = inst_ty.elemType();
3288 const elem_ty = inst_ty.childType(mod);
32843289 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return .{ .undef = inst_ty };
32853290
32863291 const local = try f.allocLocalValue(
......@@ -3323,7 +3328,7 @@ fn airLoad(f: *Function, inst: Air.Inst.Index) !CValue {
33233328
33243329 const ptr_ty = f.typeOf(ty_op.operand);
33253330 const ptr_scalar_ty = ptr_ty.scalarType(mod);
3326 const ptr_info = ptr_scalar_ty.ptrInfo().data;
3331 const ptr_info = ptr_scalar_ty.ptrInfo(mod);
33273332 const src_ty = ptr_info.pointee_type;
33283333
33293334 if (!src_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -3412,7 +3417,7 @@ fn airRet(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValue {
34123417 const writer = f.object.writer();
34133418 const op_inst = Air.refToIndex(un_op);
34143419 const op_ty = f.typeOf(un_op);
3415 const ret_ty = if (is_ptr) op_ty.childType() else op_ty;
3420 const ret_ty = if (is_ptr) op_ty.childType(mod) else op_ty;
34163421 var lowered_ret_buf: LowerFnRetTyBuffer = undefined;
34173422 const lowered_ret_ty = lowerFnRetTy(ret_ty, &lowered_ret_buf, mod);
34183423
......@@ -3601,7 +3606,7 @@ fn airStore(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
36013606
36023607 const ptr_ty = f.typeOf(bin_op.lhs);
36033608 const ptr_scalar_ty = ptr_ty.scalarType(mod);
3604 const ptr_info = ptr_scalar_ty.ptrInfo().data;
3609 const ptr_info = ptr_scalar_ty.ptrInfo(mod);
36053610
36063611 const ptr_val = try f.resolveInst(bin_op.lhs);
36073612 const src_ty = f.typeOf(bin_op.rhs);
......@@ -4156,7 +4161,7 @@ fn airCall(
41564161 const callee_ty = f.typeOf(pl_op.operand);
41574162 const fn_ty = switch (callee_ty.zigTypeTag(mod)) {
41584163 .Fn => callee_ty,
4159 .Pointer => callee_ty.childType(),
4164 .Pointer => callee_ty.childType(mod),
41604165 else => unreachable,
41614166 };
41624167
......@@ -4331,10 +4336,11 @@ fn airTry(f: *Function, inst: Air.Inst.Index) !CValue {
43314336}
43324337
43334338fn airTryPtr(f: *Function, inst: Air.Inst.Index) !CValue {
4339 const mod = f.object.dg.module;
43344340 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
43354341 const extra = f.air.extraData(Air.TryPtr, ty_pl.payload);
43364342 const body = f.air.extra[extra.end..][0..extra.data.body_len];
4337 const err_union_ty = f.typeOf(extra.data.ptr).childType();
4343 const err_union_ty = f.typeOf(extra.data.ptr).childType(mod);
43384344 return lowerTry(f, inst, extra.data.ptr, body, err_union_ty, true);
43394345}
43404346
......@@ -4826,7 +4832,7 @@ fn airAsm(f: *Function, inst: Air.Inst.Index) !CValue {
48264832
48274833 const is_reg = constraint[1] == '{';
48284834 if (is_reg) {
4829 const output_ty = if (output == .none) inst_ty else f.typeOf(output).childType();
4835 const output_ty = if (output == .none) inst_ty else f.typeOf(output).childType(mod);
48304836 try writer.writeAll("register ");
48314837 const alignment = 0;
48324838 const local_value = try f.allocLocalValue(output_ty, alignment);
......@@ -5061,9 +5067,8 @@ fn airIsNull(
50615067 }
50625068
50635069 const operand_ty = f.typeOf(un_op);
5064 const optional_ty = if (is_ptr) operand_ty.childType() else operand_ty;
5065 var payload_buf: Type.Payload.ElemType = undefined;
5066 const payload_ty = optional_ty.optionalChild(&payload_buf);
5070 const optional_ty = if (is_ptr) operand_ty.childType(mod) else operand_ty;
5071 const payload_ty = optional_ty.optionalChild(mod);
50675072 var slice_ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;
50685073
50695074 const rhs = if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod))
......@@ -5097,8 +5102,7 @@ fn airOptionalPayload(f: *Function, inst: Air.Inst.Index) !CValue {
50975102 try reap(f, inst, &.{ty_op.operand});
50985103 const opt_ty = f.typeOf(ty_op.operand);
50995104
5100 var buf: Type.Payload.ElemType = undefined;
5101 const payload_ty = opt_ty.optionalChild(&buf);
5105 const payload_ty = opt_ty.optionalChild(mod);
51025106
51035107 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
51045108 return .none;
......@@ -5132,10 +5136,10 @@ fn airOptionalPayloadPtr(f: *Function, inst: Air.Inst.Index) !CValue {
51325136 const operand = try f.resolveInst(ty_op.operand);
51335137 try reap(f, inst, &.{ty_op.operand});
51345138 const ptr_ty = f.typeOf(ty_op.operand);
5135 const opt_ty = ptr_ty.childType();
5139 const opt_ty = ptr_ty.childType(mod);
51365140 const inst_ty = f.typeOfIndex(inst);
51375141
5138 if (!inst_ty.childType().hasRuntimeBitsIgnoreComptime(mod)) {
5142 if (!inst_ty.childType(mod).hasRuntimeBitsIgnoreComptime(mod)) {
51395143 return .{ .undef = inst_ty };
51405144 }
51415145
......@@ -5163,7 +5167,7 @@ fn airOptionalPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
51635167 try reap(f, inst, &.{ty_op.operand});
51645168 const operand_ty = f.typeOf(ty_op.operand);
51655169
5166 const opt_ty = operand_ty.elemType();
5170 const opt_ty = operand_ty.childType(mod);
51675171
51685172 const inst_ty = f.typeOfIndex(inst);
51695173
......@@ -5221,7 +5225,7 @@ fn fieldLocation(
52215225 else
52225226 .{ .identifier = container_ty.structFieldName(next_field_index) } };
52235227 } else if (container_ty.hasRuntimeBitsIgnoreComptime(mod)) .end else .begin,
5224 .Packed => if (field_ptr_ty.ptrInfo().data.host_size == 0)
5228 .Packed => if (field_ptr_ty.ptrInfo(mod).host_size == 0)
52255229 .{ .byte_offset = container_ty.packedStructFieldByteOffset(field_index, mod) }
52265230 else
52275231 .begin,
......@@ -5243,7 +5247,7 @@ fn fieldLocation(
52435247 },
52445248 .Packed => .begin,
52455249 },
5246 .Pointer => switch (container_ty.ptrSize()) {
5250 .Pointer => switch (container_ty.ptrSize(mod)) {
52475251 .Slice => switch (field_index) {
52485252 0 => .{ .field = .{ .identifier = "ptr" } },
52495253 1 => .{ .field = .{ .identifier = "len" } },
......@@ -5280,7 +5284,7 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
52805284 const extra = f.air.extraData(Air.FieldParentPtr, ty_pl.payload).data;
52815285
52825286 const container_ptr_ty = f.typeOfIndex(inst);
5283 const container_ty = container_ptr_ty.childType();
5287 const container_ty = container_ptr_ty.childType(mod);
52845288
52855289 const field_ptr_ty = f.typeOf(extra.field_ptr);
52865290 const field_ptr_val = try f.resolveInst(extra.field_ptr);
......@@ -5296,7 +5300,9 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
52965300 switch (fieldLocation(container_ty, field_ptr_ty, extra.field_index, mod)) {
52975301 .begin => try f.writeCValue(writer, field_ptr_val, .Initializer),
52985302 .field => |field| {
5299 var u8_ptr_pl = field_ptr_ty.ptrInfo();
5303 var u8_ptr_pl: Type.Payload.Pointer = .{
5304 .data = field_ptr_ty.ptrInfo(mod),
5305 };
53005306 u8_ptr_pl.data.pointee_type = Type.u8;
53015307 const u8_ptr_ty = Type.initPayload(&u8_ptr_pl.base);
53025308
......@@ -5311,7 +5317,9 @@ fn airFieldParentPtr(f: *Function, inst: Air.Inst.Index) !CValue {
53115317 try writer.writeAll("))");
53125318 },
53135319 .byte_offset => |byte_offset| {
5314 var u8_ptr_pl = field_ptr_ty.ptrInfo();
5320 var u8_ptr_pl: Type.Payload.Pointer = .{
5321 .data = field_ptr_ty.ptrInfo(mod),
5322 };
53155323 u8_ptr_pl.data.pointee_type = Type.u8;
53165324 const u8_ptr_ty = Type.initPayload(&u8_ptr_pl.base);
53175325
......@@ -5345,7 +5353,7 @@ fn fieldPtr(
53455353 field_index: u32,
53465354) !CValue {
53475355 const mod = f.object.dg.module;
5348 const container_ty = container_ptr_ty.elemType();
5356 const container_ty = container_ptr_ty.childType(mod);
53495357 const field_ptr_ty = f.typeOfIndex(inst);
53505358
53515359 // Ensure complete type definition is visible before accessing fields.
......@@ -5365,7 +5373,9 @@ fn fieldPtr(
53655373 try f.writeCValueDerefMember(writer, container_ptr_val, field);
53665374 },
53675375 .byte_offset => |byte_offset| {
5368 var u8_ptr_pl = field_ptr_ty.ptrInfo();
5376 var u8_ptr_pl: Type.Payload.Pointer = .{
5377 .data = field_ptr_ty.ptrInfo(mod),
5378 };
53695379 u8_ptr_pl.data.pointee_type = Type.u8;
53705380 const u8_ptr_ty = Type.initPayload(&u8_ptr_pl.base);
53715381
......@@ -5532,7 +5542,7 @@ fn airUnwrapErrUnionErr(f: *Function, inst: Air.Inst.Index) !CValue {
55325542 try reap(f, inst, &.{ty_op.operand});
55335543
55345544 const operand_is_ptr = operand_ty.zigTypeTag(mod) == .Pointer;
5535 const error_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
5545 const error_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
55365546 const error_ty = error_union_ty.errorUnionSet();
55375547 const payload_ty = error_union_ty.errorUnionPayload();
55385548 const local = try f.allocLocal(inst, inst_ty);
......@@ -5569,7 +5579,7 @@ fn airUnwrapErrUnionPay(f: *Function, inst: Air.Inst.Index, is_ptr: bool) !CValu
55695579 const operand = try f.resolveInst(ty_op.operand);
55705580 try reap(f, inst, &.{ty_op.operand});
55715581 const operand_ty = f.typeOf(ty_op.operand);
5572 const error_union_ty = if (is_ptr) operand_ty.childType() else operand_ty;
5582 const error_union_ty = if (is_ptr) operand_ty.childType(mod) else operand_ty;
55735583
55745584 const writer = f.object.writer();
55755585 if (!error_union_ty.errorUnionPayload().hasRuntimeBits(mod)) {
......@@ -5673,7 +5683,7 @@ fn airErrUnionPayloadPtrSet(f: *Function, inst: Air.Inst.Index) !CValue {
56735683 const writer = f.object.writer();
56745684 const ty_op = f.air.instructions.items(.data)[inst].ty_op;
56755685 const operand = try f.resolveInst(ty_op.operand);
5676 const error_union_ty = f.typeOf(ty_op.operand).childType();
5686 const error_union_ty = f.typeOf(ty_op.operand).childType(mod);
56775687
56785688 const error_ty = error_union_ty.errorUnionSet();
56795689 const payload_ty = error_union_ty.errorUnionPayload();
......@@ -5761,7 +5771,7 @@ fn airIsErr(f: *Function, inst: Air.Inst.Index, is_ptr: bool, operator: []const
57615771 try reap(f, inst, &.{un_op});
57625772 const operand_ty = f.typeOf(un_op);
57635773 const local = try f.allocLocal(inst, Type.bool);
5764 const err_union_ty = if (is_ptr) operand_ty.childType() else operand_ty;
5774 const err_union_ty = if (is_ptr) operand_ty.childType(mod) else operand_ty;
57655775 const payload_ty = err_union_ty.errorUnionPayload();
57665776 const error_ty = err_union_ty.errorUnionSet();
57675777
......@@ -5795,7 +5805,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
57955805 const inst_ty = f.typeOfIndex(inst);
57965806 const writer = f.object.writer();
57975807 const local = try f.allocLocal(inst, inst_ty);
5798 const array_ty = f.typeOf(ty_op.operand).childType();
5808 const array_ty = f.typeOf(ty_op.operand).childType(mod);
57995809
58005810 try f.writeCValueMember(writer, local, .{ .identifier = "ptr" });
58015811 try writer.writeAll(" = ");
......@@ -5811,7 +5821,7 @@ fn airArrayToSlice(f: *Function, inst: Air.Inst.Index) !CValue {
58115821 } else try f.writeCValue(writer, operand, .Initializer);
58125822 try writer.writeAll("; ");
58135823
5814 const array_len = array_ty.arrayLen();
5824 const array_len = array_ty.arrayLen(mod);
58155825 var len_pl: Value.Payload.U64 = .{ .base = .{ .tag = .int_u64 }, .data = array_len };
58165826 const len_val = Value.initPayload(&len_pl.base);
58175827 try f.writeCValueMember(writer, local, .{ .identifier = "len" });
......@@ -6050,7 +6060,7 @@ fn airCmpxchg(f: *Function, inst: Air.Inst.Index, flavor: [*:0]const u8) !CValue
60506060 const expected_value = try f.resolveInst(extra.expected_value);
60516061 const new_value = try f.resolveInst(extra.new_value);
60526062 const ptr_ty = f.typeOf(extra.ptr);
6053 const ty = ptr_ty.childType();
6063 const ty = ptr_ty.childType(mod);
60546064
60556065 const writer = f.object.writer();
60566066 const new_value_mat = try Materialize.start(f, inst, writer, ty, new_value);
......@@ -6152,7 +6162,7 @@ fn airAtomicRmw(f: *Function, inst: Air.Inst.Index) !CValue {
61526162 const extra = f.air.extraData(Air.AtomicRmw, pl_op.payload).data;
61536163 const inst_ty = f.typeOfIndex(inst);
61546164 const ptr_ty = f.typeOf(pl_op.operand);
6155 const ty = ptr_ty.childType();
6165 const ty = ptr_ty.childType(mod);
61566166 const ptr = try f.resolveInst(pl_op.operand);
61576167 const operand = try f.resolveInst(extra.operand);
61586168
......@@ -6207,7 +6217,7 @@ fn airAtomicLoad(f: *Function, inst: Air.Inst.Index) !CValue {
62076217 const ptr = try f.resolveInst(atomic_load.ptr);
62086218 try reap(f, inst, &.{atomic_load.ptr});
62096219 const ptr_ty = f.typeOf(atomic_load.ptr);
6210 const ty = ptr_ty.childType();
6220 const ty = ptr_ty.childType(mod);
62116221
62126222 const repr_ty = if (ty.isRuntimeFloat())
62136223 mod.intType(.unsigned, @intCast(u16, ty.abiSize(mod) * 8)) catch unreachable
......@@ -6241,7 +6251,7 @@ fn airAtomicStore(f: *Function, inst: Air.Inst.Index, order: [*:0]const u8) !CVa
62416251 const mod = f.object.dg.module;
62426252 const bin_op = f.air.instructions.items(.data)[inst].bin_op;
62436253 const ptr_ty = f.typeOf(bin_op.lhs);
6244 const ty = ptr_ty.childType();
6254 const ty = ptr_ty.childType(mod);
62456255 const ptr = try f.resolveInst(bin_op.lhs);
62466256 const element = try f.resolveInst(bin_op.rhs);
62476257
......@@ -6299,7 +6309,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
62996309 }
63006310
63016311 try writer.writeAll("memset(");
6302 switch (dest_ty.ptrSize()) {
6312 switch (dest_ty.ptrSize(mod)) {
63036313 .Slice => {
63046314 try f.writeCValueMember(writer, dest_slice, .{ .identifier = "ptr" });
63056315 try writer.writeAll(", 0xaa, ");
......@@ -6311,8 +6321,8 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
63116321 }
63126322 },
63136323 .One => {
6314 const array_ty = dest_ty.childType();
6315 const len = array_ty.arrayLen() * elem_abi_size;
6324 const array_ty = dest_ty.childType(mod);
6325 const len = array_ty.arrayLen(mod) * elem_abi_size;
63166326
63176327 try f.writeCValue(writer, dest_slice, .FunctionArgument);
63186328 try writer.print(", 0xaa, {d});\n", .{len});
......@@ -6327,11 +6337,10 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
63276337 // For the assignment in this loop, the array pointer needs to get
63286338 // casted to a regular pointer, otherwise an error like this occurs:
63296339 // error: array type 'uint32_t[20]' (aka 'unsigned int[20]') is not assignable
6330 var elem_ptr_ty_pl: Type.Payload.ElemType = .{
6331 .base = .{ .tag = .c_mut_pointer },
6332 .data = elem_ty,
6333 };
6334 const elem_ptr_ty = Type.initPayload(&elem_ptr_ty_pl.base);
6340 const elem_ptr_ty = try mod.ptrType(.{
6341 .size = .C,
6342 .elem_type = elem_ty.ip_index,
6343 });
63356344
63366345 const index = try f.allocLocal(inst, Type.usize);
63376346
......@@ -6342,13 +6351,13 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
63426351 try writer.writeAll("; ");
63436352 try f.writeCValue(writer, index, .Other);
63446353 try writer.writeAll(" != ");
6345 switch (dest_ty.ptrSize()) {
6354 switch (dest_ty.ptrSize(mod)) {
63466355 .Slice => {
63476356 try f.writeCValueMember(writer, dest_slice, .{ .identifier = "len" });
63486357 },
63496358 .One => {
6350 const array_ty = dest_ty.childType();
6351 try writer.print("{d}", .{array_ty.arrayLen()});
6359 const array_ty = dest_ty.childType(mod);
6360 try writer.print("{d}", .{array_ty.arrayLen(mod)});
63526361 },
63536362 .Many, .C => unreachable,
63546363 }
......@@ -6377,7 +6386,7 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
63776386 const bitcasted = try bitcast(f, Type.u8, value, elem_ty);
63786387
63796388 try writer.writeAll("memset(");
6380 switch (dest_ty.ptrSize()) {
6389 switch (dest_ty.ptrSize(mod)) {
63816390 .Slice => {
63826391 try f.writeCValueMember(writer, dest_slice, .{ .identifier = "ptr" });
63836392 try writer.writeAll(", ");
......@@ -6387,8 +6396,8 @@ fn airMemset(f: *Function, inst: Air.Inst.Index, safety: bool) !CValue {
63876396 try writer.writeAll(");\n");
63886397 },
63896398 .One => {
6390 const array_ty = dest_ty.childType();
6391 const len = array_ty.arrayLen() * elem_abi_size;
6399 const array_ty = dest_ty.childType(mod);
6400 const len = array_ty.arrayLen(mod) * elem_abi_size;
63926401
63936402 try f.writeCValue(writer, dest_slice, .FunctionArgument);
63946403 try writer.writeAll(", ");
......@@ -6416,9 +6425,9 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {
64166425 try writer.writeAll(", ");
64176426 try writeSliceOrPtr(f, writer, src_ptr, src_ty);
64186427 try writer.writeAll(", ");
6419 switch (dest_ty.ptrSize()) {
6428 switch (dest_ty.ptrSize(mod)) {
64206429 .Slice => {
6421 const elem_ty = dest_ty.childType();
6430 const elem_ty = dest_ty.childType(mod);
64226431 const elem_abi_size = elem_ty.abiSize(mod);
64236432 try f.writeCValueMember(writer, dest_ptr, .{ .identifier = "len" });
64246433 if (elem_abi_size > 1) {
......@@ -6428,10 +6437,10 @@ fn airMemcpy(f: *Function, inst: Air.Inst.Index) !CValue {
64286437 }
64296438 },
64306439 .One => {
6431 const array_ty = dest_ty.childType();
6432 const elem_ty = array_ty.childType();
6440 const array_ty = dest_ty.childType(mod);
6441 const elem_ty = array_ty.childType(mod);
64336442 const elem_abi_size = elem_ty.abiSize(mod);
6434 const len = array_ty.arrayLen() * elem_abi_size;
6443 const len = array_ty.arrayLen(mod) * elem_abi_size;
64356444 try writer.print("{d});\n", .{len});
64366445 },
64376446 .Many, .C => unreachable,
......@@ -6448,7 +6457,7 @@ fn airSetUnionTag(f: *Function, inst: Air.Inst.Index) !CValue {
64486457 const new_tag = try f.resolveInst(bin_op.rhs);
64496458 try reap(f, inst, &.{ bin_op.lhs, bin_op.rhs });
64506459
6451 const union_ty = f.typeOf(bin_op.lhs).childType();
6460 const union_ty = f.typeOf(bin_op.lhs).childType(mod);
64526461 const layout = union_ty.unionGetLayout(mod);
64536462 if (layout.tag_size == 0) return .none;
64546463 const tag_ty = union_ty.unionTagTypeSafety().?;
......@@ -6777,7 +6786,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
67776786 const mod = f.object.dg.module;
67786787 const ty_pl = f.air.instructions.items(.data)[inst].ty_pl;
67796788 const inst_ty = f.typeOfIndex(inst);
6780 const len = @intCast(usize, inst_ty.arrayLen());
6789 const len = @intCast(usize, inst_ty.arrayLen(mod));
67816790 const elements = @ptrCast([]const Air.Inst.Ref, f.air.extra[ty_pl.payload..][0..len]);
67826791 const gpa = f.object.dg.gpa;
67836792 const resolved_elements = try gpa.alloc(CValue, elements.len);
......@@ -6796,7 +6805,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
67966805 const local = try f.allocLocal(inst, inst_ty);
67976806 switch (inst_ty.zigTypeTag(mod)) {
67986807 .Array, .Vector => {
6799 const elem_ty = inst_ty.childType();
6808 const elem_ty = inst_ty.childType(mod);
68006809 const a = try Assignment.init(f, elem_ty);
68016810 for (resolved_elements, 0..) |element, i| {
68026811 try a.restart(f, writer);
......@@ -6806,7 +6815,7 @@ fn airAggregateInit(f: *Function, inst: Air.Inst.Index) !CValue {
68066815 try f.writeCValue(writer, element, .Other);
68076816 try a.end(f, writer);
68086817 }
6809 if (inst_ty.sentinel()) |sentinel| {
6818 if (inst_ty.sentinel(mod)) |sentinel| {
68106819 try a.restart(f, writer);
68116820 try f.writeCValue(writer, local, .Other);
68126821 try writer.print("[{d}]", .{resolved_elements.len});
......@@ -7708,7 +7717,7 @@ const Vectorize = struct {
77087717 pub fn start(f: *Function, inst: Air.Inst.Index, writer: anytype, ty: Type) !Vectorize {
77097718 const mod = f.object.dg.module;
77107719 return if (ty.zigTypeTag(mod) == .Vector) index: {
7711 var len_pl = Value.Payload.U64{ .base = .{ .tag = .int_u64 }, .data = ty.vectorLen() };
7720 var len_pl = Value.Payload.U64{ .base = .{ .tag = .int_u64 }, .data = ty.vectorLen(mod) };
77127721
77137722 const local = try f.allocLocal(inst, Type.usize);
77147723
src/codegen/c/type.zig+4-5
......@@ -1423,7 +1423,7 @@ pub const CType = extern union {
14231423 }),
14241424
14251425 .Pointer => {
1426 const info = ty.ptrInfo().data;
1426 const info = ty.ptrInfo(mod);
14271427 switch (info.size) {
14281428 .Slice => {
14291429 if (switch (kind) {
......@@ -1625,9 +1625,9 @@ pub const CType = extern union {
16251625 .Vector => .vector,
16261626 else => unreachable,
16271627 };
1628 if (try lookup.typeToIndex(ty.childType(), kind)) |child_idx| {
1628 if (try lookup.typeToIndex(ty.childType(mod), kind)) |child_idx| {
16291629 self.storage = .{ .seq = .{ .base = .{ .tag = t }, .data = .{
1630 .len = ty.arrayLenIncludingSentinel(),
1630 .len = ty.arrayLenIncludingSentinel(mod),
16311631 .elem_type = child_idx,
16321632 } } };
16331633 self.value = .{ .cty = initPayload(&self.storage.seq) };
......@@ -1639,8 +1639,7 @@ pub const CType = extern union {
16391639 },
16401640
16411641 .Optional => {
1642 var buf: Type.Payload.ElemType = undefined;
1643 const payload_ty = ty.optionalChild(&buf);
1642 const payload_ty = ty.optionalChild(mod);
16441643 if (payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
16451644 if (ty.optionalReprIsPayload(mod)) {
16461645 try self.initType(payload_ty, kind, lookup);
src/codegen/llvm.zig+144-182
......@@ -597,7 +597,7 @@ pub const Object = struct {
597597 llvm_usize_ty,
598598 };
599599 const llvm_slice_ty = self.context.structType(&type_fields, type_fields.len, .False);
600 const slice_ty = Type.initTag(.const_slice_u8_sentinel_0);
600 const slice_ty = Type.const_slice_u8_sentinel_0;
601601 const slice_alignment = slice_ty.abiAlignment(mod);
602602
603603 const error_name_list = mod.error_name_list.items;
......@@ -1071,7 +1071,7 @@ pub const Object = struct {
10711071 .slice => {
10721072 assert(!it.byval_attr);
10731073 const param_ty = fn_info.param_types[it.zig_index - 1];
1074 const ptr_info = param_ty.ptrInfo().data;
1074 const ptr_info = param_ty.ptrInfo(mod);
10751075
10761076 if (math.cast(u5, it.zig_index - 1)) |i| {
10771077 if (@truncate(u1, fn_info.noalias_bits >> i) != 0) {
......@@ -1596,7 +1596,7 @@ pub const Object = struct {
15961596 },
15971597 .Pointer => {
15981598 // Normalize everything that the debug info does not represent.
1599 const ptr_info = ty.ptrInfo().data;
1599 const ptr_info = ty.ptrInfo(mod);
16001600
16011601 if (ptr_info.sentinel != null or
16021602 ptr_info.@"addrspace" != .generic or
......@@ -1755,8 +1755,8 @@ pub const Object = struct {
17551755 const array_di_ty = dib.createArrayType(
17561756 ty.abiSize(mod) * 8,
17571757 ty.abiAlignment(mod) * 8,
1758 try o.lowerDebugType(ty.childType(), .full),
1759 @intCast(c_int, ty.arrayLen()),
1758 try o.lowerDebugType(ty.childType(mod), .full),
1759 @intCast(c_int, ty.arrayLen(mod)),
17601760 );
17611761 // The recursive call to `lowerDebugType` means we can't use `gop` anymore.
17621762 try o.di_type_map.putContext(gpa, ty, AnnotatedDITypePtr.initFull(array_di_ty), .{ .mod = o.module });
......@@ -1781,14 +1781,14 @@ pub const Object = struct {
17811781 break :blk dib.createBasicType(name, info.bits, dwarf_encoding);
17821782 },
17831783 .Bool => dib.createBasicType("bool", 1, DW.ATE.boolean),
1784 else => try o.lowerDebugType(ty.childType(), .full),
1784 else => try o.lowerDebugType(ty.childType(mod), .full),
17851785 };
17861786
17871787 const vector_di_ty = dib.createVectorType(
17881788 ty.abiSize(mod) * 8,
17891789 ty.abiAlignment(mod) * 8,
17901790 elem_di_type,
1791 ty.vectorLen(),
1791 ty.vectorLen(mod),
17921792 );
17931793 // The recursive call to `lowerDebugType` means we can't use `gop` anymore.
17941794 try o.di_type_map.putContext(gpa, ty, AnnotatedDITypePtr.initFull(vector_di_ty), .{ .mod = o.module });
......@@ -1797,8 +1797,7 @@ pub const Object = struct {
17971797 .Optional => {
17981798 const name = try ty.nameAlloc(gpa, o.module);
17991799 defer gpa.free(name);
1800 var buf: Type.Payload.ElemType = undefined;
1801 const child_ty = ty.optionalChild(&buf);
1800 const child_ty = ty.optionalChild(mod);
18021801 if (!child_ty.hasRuntimeBitsIgnoreComptime(mod)) {
18031802 const di_bits = 8; // lldb cannot handle non-byte sized types
18041803 const di_ty = dib.createBasicType(name, di_bits, DW.ATE.boolean);
......@@ -2350,11 +2349,7 @@ pub const Object = struct {
23502349 try param_di_types.append(try o.lowerDebugType(di_ret_ty, .full));
23512350
23522351 if (sret) {
2353 var ptr_ty_payload: Type.Payload.ElemType = .{
2354 .base = .{ .tag = .single_mut_pointer },
2355 .data = fn_info.return_type,
2356 };
2357 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
2352 const ptr_ty = try mod.singleMutPtrType(fn_info.return_type);
23582353 try param_di_types.append(try o.lowerDebugType(ptr_ty, .full));
23592354 }
23602355 } else {
......@@ -2364,11 +2359,7 @@ pub const Object = struct {
23642359 if (fn_info.return_type.isError(mod) and
23652360 o.module.comp.bin_file.options.error_return_tracing)
23662361 {
2367 var ptr_ty_payload: Type.Payload.ElemType = .{
2368 .base = .{ .tag = .single_mut_pointer },
2369 .data = o.getStackTraceType(),
2370 };
2371 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
2362 const ptr_ty = try mod.singleMutPtrType(o.getStackTraceType());
23722363 try param_di_types.append(try o.lowerDebugType(ptr_ty, .full));
23732364 }
23742365
......@@ -2376,11 +2367,7 @@ pub const Object = struct {
23762367 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
23772368
23782369 if (isByRef(param_ty, mod)) {
2379 var ptr_ty_payload: Type.Payload.ElemType = .{
2380 .base = .{ .tag = .single_mut_pointer },
2381 .data = param_ty,
2382 };
2383 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
2370 const ptr_ty = try mod.singleMutPtrType(param_ty);
23842371 try param_di_types.append(try o.lowerDebugType(ptr_ty, .full));
23852372 } else {
23862373 try param_di_types.append(try o.lowerDebugType(param_ty, .full));
......@@ -2843,7 +2830,7 @@ pub const DeclGen = struct {
28432830 };
28442831 return dg.context.structType(&fields, fields.len, .False);
28452832 }
2846 const ptr_info = t.ptrInfo().data;
2833 const ptr_info = t.ptrInfo(mod);
28472834 const llvm_addrspace = toLlvmAddressSpace(ptr_info.@"addrspace", target);
28482835 return dg.context.pointerType(llvm_addrspace);
28492836 },
......@@ -2866,19 +2853,18 @@ pub const DeclGen = struct {
28662853 return llvm_struct_ty;
28672854 },
28682855 .Array => {
2869 const elem_ty = t.childType();
2856 const elem_ty = t.childType(mod);
28702857 assert(elem_ty.onePossibleValue(mod) == null);
28712858 const elem_llvm_ty = try dg.lowerType(elem_ty);
2872 const total_len = t.arrayLen() + @boolToInt(t.sentinel() != null);
2859 const total_len = t.arrayLen(mod) + @boolToInt(t.sentinel(mod) != null);
28732860 return elem_llvm_ty.arrayType(@intCast(c_uint, total_len));
28742861 },
28752862 .Vector => {
2876 const elem_type = try dg.lowerType(t.childType());
2877 return elem_type.vectorType(t.vectorLen());
2863 const elem_type = try dg.lowerType(t.childType(mod));
2864 return elem_type.vectorType(t.vectorLen(mod));
28782865 },
28792866 .Optional => {
2880 var buf: Type.Payload.ElemType = undefined;
2881 const child_ty = t.optionalChild(&buf);
2867 const child_ty = t.optionalChild(mod);
28822868 if (!child_ty.hasRuntimeBitsIgnoreComptime(mod)) {
28832869 return dg.context.intType(8);
28842870 }
......@@ -3173,11 +3159,7 @@ pub const DeclGen = struct {
31733159 if (fn_info.return_type.isError(mod) and
31743160 mod.comp.bin_file.options.error_return_tracing)
31753161 {
3176 var ptr_ty_payload: Type.Payload.ElemType = .{
3177 .base = .{ .tag = .single_mut_pointer },
3178 .data = dg.object.getStackTraceType(),
3179 };
3180 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
3162 const ptr_ty = try mod.singleMutPtrType(dg.object.getStackTraceType());
31813163 try llvm_params.append(try dg.lowerType(ptr_ty));
31823164 }
31833165
......@@ -3199,9 +3181,8 @@ pub const DeclGen = struct {
31993181 .slice => {
32003182 const param_ty = fn_info.param_types[it.zig_index - 1];
32013183 var buf: Type.SlicePtrFieldTypeBuffer = undefined;
3202 var opt_buf: Type.Payload.ElemType = undefined;
32033184 const ptr_ty = if (param_ty.zigTypeTag(mod) == .Optional)
3204 param_ty.optionalChild(&opt_buf).slicePtrFieldType(&buf)
3185 param_ty.optionalChild(mod).slicePtrFieldType(&buf)
32053186 else
32063187 param_ty.slicePtrFieldType(&buf);
32073188 const ptr_llvm_ty = try dg.lowerType(ptr_ty);
......@@ -3247,7 +3228,7 @@ pub const DeclGen = struct {
32473228 const lower_elem_ty = switch (elem_ty.zigTypeTag(mod)) {
32483229 .Opaque => true,
32493230 .Fn => !elem_ty.fnInfo().is_generic,
3250 .Array => elem_ty.childType().hasRuntimeBitsIgnoreComptime(mod),
3231 .Array => elem_ty.childType(mod).hasRuntimeBitsIgnoreComptime(mod),
32513232 else => elem_ty.hasRuntimeBitsIgnoreComptime(mod),
32523233 };
32533234 const llvm_elem_ty = if (lower_elem_ty)
......@@ -3417,7 +3398,7 @@ pub const DeclGen = struct {
34173398 return llvm_int.constIntToPtr(try dg.lowerType(tv.ty));
34183399 },
34193400 .field_ptr, .opt_payload_ptr, .eu_payload_ptr, .elem_ptr => {
3420 return dg.lowerParentPtr(tv.val, tv.ty.ptrInfo().data.bit_offset % 8 == 0);
3401 return dg.lowerParentPtr(tv.val, tv.ty.ptrInfo(mod).bit_offset % 8 == 0);
34213402 },
34223403 .null_value, .zero => {
34233404 const llvm_type = try dg.lowerType(tv.ty);
......@@ -3425,7 +3406,7 @@ pub const DeclGen = struct {
34253406 },
34263407 .opt_payload => {
34273408 const payload = tv.val.castTag(.opt_payload).?.data;
3428 return dg.lowerParentPtr(payload, tv.ty.ptrInfo().data.bit_offset % 8 == 0);
3409 return dg.lowerParentPtr(payload, tv.ty.ptrInfo(mod).bit_offset % 8 == 0);
34293410 },
34303411 else => |tag| return dg.todo("implement const of pointer type '{}' ({})", .{
34313412 tv.ty.fmtDebug(), tag,
......@@ -3436,14 +3417,14 @@ pub const DeclGen = struct {
34363417 const bytes = tv.val.castTag(.bytes).?.data;
34373418 return dg.context.constString(
34383419 bytes.ptr,
3439 @intCast(c_uint, tv.ty.arrayLenIncludingSentinel()),
3420 @intCast(c_uint, tv.ty.arrayLenIncludingSentinel(mod)),
34403421 .True, // Don't null terminate. Bytes has the sentinel, if any.
34413422 );
34423423 },
34433424 .str_lit => {
34443425 const str_lit = tv.val.castTag(.str_lit).?.data;
34453426 const bytes = dg.module.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
3446 if (tv.ty.sentinel()) |sent_val| {
3427 if (tv.ty.sentinel(mod)) |sent_val| {
34473428 const byte = @intCast(u8, sent_val.toUnsignedInt(mod));
34483429 if (byte == 0 and bytes.len > 0) {
34493430 return dg.context.constString(
......@@ -3472,9 +3453,9 @@ pub const DeclGen = struct {
34723453 },
34733454 .aggregate => {
34743455 const elem_vals = tv.val.castTag(.aggregate).?.data;
3475 const elem_ty = tv.ty.elemType();
3456 const elem_ty = tv.ty.childType(mod);
34763457 const gpa = dg.gpa;
3477 const len = @intCast(usize, tv.ty.arrayLenIncludingSentinel());
3458 const len = @intCast(usize, tv.ty.arrayLenIncludingSentinel(mod));
34783459 const llvm_elems = try gpa.alloc(*llvm.Value, len);
34793460 defer gpa.free(llvm_elems);
34803461 var need_unnamed = false;
......@@ -3498,9 +3479,9 @@ pub const DeclGen = struct {
34983479 },
34993480 .repeated => {
35003481 const val = tv.val.castTag(.repeated).?.data;
3501 const elem_ty = tv.ty.elemType();
3502 const sentinel = tv.ty.sentinel();
3503 const len = @intCast(usize, tv.ty.arrayLen());
3482 const elem_ty = tv.ty.childType(mod);
3483 const sentinel = tv.ty.sentinel(mod);
3484 const len = @intCast(usize, tv.ty.arrayLen(mod));
35043485 const len_including_sent = len + @boolToInt(sentinel != null);
35053486 const gpa = dg.gpa;
35063487 const llvm_elems = try gpa.alloc(*llvm.Value, len_including_sent);
......@@ -3534,8 +3515,8 @@ pub const DeclGen = struct {
35343515 }
35353516 },
35363517 .empty_array_sentinel => {
3537 const elem_ty = tv.ty.elemType();
3538 const sent_val = tv.ty.sentinel().?;
3518 const elem_ty = tv.ty.childType(mod);
3519 const sent_val = tv.ty.sentinel(mod).?;
35393520 const sentinel = try dg.lowerValue(.{ .ty = elem_ty, .val = sent_val });
35403521 const llvm_elems: [1]*llvm.Value = .{sentinel};
35413522 const need_unnamed = dg.isUnnamedType(elem_ty, llvm_elems[0]);
......@@ -3550,8 +3531,7 @@ pub const DeclGen = struct {
35503531 },
35513532 .Optional => {
35523533 comptime assert(optional_layout_version == 3);
3553 var buf: Type.Payload.ElemType = undefined;
3554 const payload_ty = tv.ty.optionalChild(&buf);
3534 const payload_ty = tv.ty.optionalChild(mod);
35553535
35563536 const llvm_i8 = dg.context.intType(8);
35573537 const is_pl = !tv.val.isNull(mod);
......@@ -3897,10 +3877,10 @@ pub const DeclGen = struct {
38973877 .bytes => {
38983878 // Note, sentinel is not stored even if the type has a sentinel.
38993879 const bytes = tv.val.castTag(.bytes).?.data;
3900 const vector_len = @intCast(usize, tv.ty.arrayLen());
3880 const vector_len = @intCast(usize, tv.ty.arrayLen(mod));
39013881 assert(vector_len == bytes.len or vector_len + 1 == bytes.len);
39023882
3903 const elem_ty = tv.ty.elemType();
3883 const elem_ty = tv.ty.childType(mod);
39043884 const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len);
39053885 defer dg.gpa.free(llvm_elems);
39063886 for (llvm_elems, 0..) |*elem, i| {
......@@ -3923,9 +3903,9 @@ pub const DeclGen = struct {
39233903 // Note, sentinel is not stored even if the type has a sentinel.
39243904 // The value includes the sentinel in those cases.
39253905 const elem_vals = tv.val.castTag(.aggregate).?.data;
3926 const vector_len = @intCast(usize, tv.ty.arrayLen());
3906 const vector_len = @intCast(usize, tv.ty.arrayLen(mod));
39273907 assert(vector_len == elem_vals.len or vector_len + 1 == elem_vals.len);
3928 const elem_ty = tv.ty.elemType();
3908 const elem_ty = tv.ty.childType(mod);
39293909 const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len);
39303910 defer dg.gpa.free(llvm_elems);
39313911 for (llvm_elems, 0..) |*elem, i| {
......@@ -3939,8 +3919,8 @@ pub const DeclGen = struct {
39393919 .repeated => {
39403920 // Note, sentinel is not stored even if the type has a sentinel.
39413921 const val = tv.val.castTag(.repeated).?.data;
3942 const elem_ty = tv.ty.elemType();
3943 const len = @intCast(usize, tv.ty.arrayLen());
3922 const elem_ty = tv.ty.childType(mod);
3923 const len = @intCast(usize, tv.ty.arrayLen(mod));
39443924 const llvm_elems = try dg.gpa.alloc(*llvm.Value, len);
39453925 defer dg.gpa.free(llvm_elems);
39463926 for (llvm_elems) |*elem| {
......@@ -3955,10 +3935,10 @@ pub const DeclGen = struct {
39553935 // Note, sentinel is not stored
39563936 const str_lit = tv.val.castTag(.str_lit).?.data;
39573937 const bytes = dg.module.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
3958 const vector_len = @intCast(usize, tv.ty.arrayLen());
3938 const vector_len = @intCast(usize, tv.ty.arrayLen(mod));
39593939 assert(vector_len == bytes.len);
39603940
3961 const elem_ty = tv.ty.elemType();
3941 const elem_ty = tv.ty.childType(mod);
39623942 const llvm_elems = try dg.gpa.alloc(*llvm.Value, vector_len);
39633943 defer dg.gpa.free(llvm_elems);
39643944 for (llvm_elems, 0..) |*elem, i| {
......@@ -4006,13 +3986,10 @@ pub const DeclGen = struct {
40063986 ptr_val: Value,
40073987 decl_index: Module.Decl.Index,
40083988 ) Error!*llvm.Value {
4009 const decl = dg.module.declPtr(decl_index);
4010 dg.module.markDeclAlive(decl);
4011 var ptr_ty_payload: Type.Payload.ElemType = .{
4012 .base = .{ .tag = .single_mut_pointer },
4013 .data = decl.ty,
4014 };
4015 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
3989 const mod = dg.module;
3990 const decl = mod.declPtr(decl_index);
3991 mod.markDeclAlive(decl);
3992 const ptr_ty = try mod.singleMutPtrType(decl.ty);
40163993 return try dg.lowerDeclRefValue(.{ .ty = ptr_ty, .val = ptr_val }, decl_index);
40173994 }
40183995
......@@ -4135,9 +4112,8 @@ pub const DeclGen = struct {
41354112 .opt_payload_ptr => {
41364113 const opt_payload_ptr = ptr_val.castTag(.opt_payload_ptr).?.data;
41374114 const parent_llvm_ptr = try dg.lowerParentPtr(opt_payload_ptr.container_ptr, true);
4138 var buf: Type.Payload.ElemType = undefined;
41394115
4140 const payload_ty = opt_payload_ptr.container_ty.optionalChild(&buf);
4116 const payload_ty = opt_payload_ptr.container_ty.optionalChild(mod);
41414117 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod) or
41424118 payload_ty.optionalReprIsPayload(mod))
41434119 {
......@@ -4251,7 +4227,8 @@ pub const DeclGen = struct {
42514227 }
42524228
42534229 fn lowerPtrToVoid(dg: *DeclGen, ptr_ty: Type) !*llvm.Value {
4254 const alignment = ptr_ty.ptrInfo().data.@"align";
4230 const mod = dg.module;
4231 const alignment = ptr_ty.ptrInfo(mod).@"align";
42554232 // Even though we are pointing at something which has zero bits (e.g. `void`),
42564233 // Pointers are defined to have bits. So we must return something here.
42574234 // The value cannot be undefined, because we use the `nonnull` annotation
......@@ -4374,7 +4351,7 @@ pub const DeclGen = struct {
43744351 ) void {
43754352 const mod = dg.module;
43764353 if (param_ty.isPtrAtRuntime(mod)) {
4377 const ptr_info = param_ty.ptrInfo().data;
4354 const ptr_info = param_ty.ptrInfo(mod);
43784355 if (math.cast(u5, param_index)) |i| {
43794356 if (@truncate(u1, fn_info.noalias_bits >> i) != 0) {
43804357 dg.addArgAttr(llvm_fn, llvm_arg_i, "noalias");
......@@ -4786,7 +4763,7 @@ pub const FuncGen = struct {
47864763 const mod = self.dg.module;
47874764 const zig_fn_ty = switch (callee_ty.zigTypeTag(mod)) {
47884765 .Fn => callee_ty,
4789 .Pointer => callee_ty.childType(),
4766 .Pointer => callee_ty.childType(mod),
47904767 else => unreachable,
47914768 };
47924769 const fn_info = zig_fn_ty.fnInfo();
......@@ -5014,7 +4991,7 @@ pub const FuncGen = struct {
50144991 .slice => {
50154992 assert(!it.byval_attr);
50164993 const param_ty = fn_info.param_types[it.zig_index - 1];
5017 const ptr_info = param_ty.ptrInfo().data;
4994 const ptr_info = param_ty.ptrInfo(mod);
50184995 const llvm_arg_i = it.llvm_index - 2;
50194996
50204997 if (math.cast(u5, it.zig_index - 1)) |i| {
......@@ -5098,11 +5075,7 @@ pub const FuncGen = struct {
50985075 const ret_ty = self.typeOf(un_op);
50995076 if (self.ret_ptr) |ret_ptr| {
51005077 const operand = try self.resolveInst(un_op);
5101 var ptr_ty_payload: Type.Payload.ElemType = .{
5102 .base = .{ .tag = .single_mut_pointer },
5103 .data = ret_ty,
5104 };
5105 const ptr_ty = Type.initPayload(&ptr_ty_payload.base);
5078 const ptr_ty = try mod.singleMutPtrType(ret_ty);
51065079 try self.store(ret_ptr, ptr_ty, operand, .NotAtomic);
51075080 _ = self.builder.buildRetVoid();
51085081 return null;
......@@ -5150,11 +5123,11 @@ pub const FuncGen = struct {
51505123 }
51515124
51525125 fn airRetLoad(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
5126 const mod = self.dg.module;
51535127 const un_op = self.air.instructions.items(.data)[inst].un_op;
51545128 const ptr_ty = self.typeOf(un_op);
5155 const ret_ty = ptr_ty.childType();
5129 const ret_ty = ptr_ty.childType(mod);
51565130 const fn_info = self.dg.decl.ty.fnInfo();
5157 const mod = self.dg.module;
51585131 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
51595132 if (fn_info.return_type.isError(mod)) {
51605133 // Functions with an empty error set are emitted with an error code
......@@ -5301,15 +5274,13 @@ pub const FuncGen = struct {
53015274 operand_ty: Type,
53025275 op: math.CompareOperator,
53035276 ) Allocator.Error!*llvm.Value {
5304 var opt_buffer: Type.Payload.ElemType = undefined;
5305
53065277 const mod = self.dg.module;
53075278 const scalar_ty = operand_ty.scalarType(mod);
53085279 const int_ty = switch (scalar_ty.zigTypeTag(mod)) {
53095280 .Enum => scalar_ty.intTagType(),
53105281 .Int, .Bool, .Pointer, .ErrorSet => scalar_ty,
53115282 .Optional => blk: {
5312 const payload_ty = operand_ty.optionalChild(&opt_buffer);
5283 const payload_ty = operand_ty.optionalChild(mod);
53135284 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod) or
53145285 operand_ty.optionalReprIsPayload(mod))
53155286 {
......@@ -5506,11 +5477,12 @@ pub const FuncGen = struct {
55065477 }
55075478
55085479 fn airTryPtr(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
5480 const mod = self.dg.module;
55095481 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
55105482 const extra = self.air.extraData(Air.TryPtr, ty_pl.payload);
55115483 const err_union_ptr = try self.resolveInst(extra.data.ptr);
55125484 const body = self.air.extra[extra.end..][0..extra.data.body_len];
5513 const err_union_ty = self.typeOf(extra.data.ptr).childType();
5485 const err_union_ty = self.typeOf(extra.data.ptr).childType(mod);
55145486 const is_unused = self.liveness.isUnused(inst);
55155487 return lowerTry(self, err_union_ptr, body, err_union_ty, true, true, is_unused);
55165488 }
......@@ -5661,9 +5633,9 @@ pub const FuncGen = struct {
56615633 const mod = self.dg.module;
56625634 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
56635635 const operand_ty = self.typeOf(ty_op.operand);
5664 const array_ty = operand_ty.childType();
5636 const array_ty = operand_ty.childType(mod);
56655637 const llvm_usize = try self.dg.lowerType(Type.usize);
5666 const len = llvm_usize.constInt(array_ty.arrayLen(), .False);
5638 const len = llvm_usize.constInt(array_ty.arrayLen(mod), .False);
56675639 const slice_llvm_ty = try self.dg.lowerType(self.typeOfIndex(inst));
56685640 const operand = try self.resolveInst(ty_op.operand);
56695641 if (!array_ty.hasRuntimeBitsIgnoreComptime(mod)) {
......@@ -5806,20 +5778,20 @@ pub const FuncGen = struct {
58065778 const mod = fg.dg.module;
58075779 const target = mod.getTarget();
58085780 const llvm_usize_ty = fg.context.intType(target.ptrBitWidth());
5809 switch (ty.ptrSize()) {
5781 switch (ty.ptrSize(mod)) {
58105782 .Slice => {
58115783 const len = fg.builder.buildExtractValue(ptr, 1, "");
5812 const elem_ty = ty.childType();
5784 const elem_ty = ty.childType(mod);
58135785 const abi_size = elem_ty.abiSize(mod);
58145786 if (abi_size == 1) return len;
58155787 const abi_size_llvm_val = llvm_usize_ty.constInt(abi_size, .False);
58165788 return fg.builder.buildMul(len, abi_size_llvm_val, "");
58175789 },
58185790 .One => {
5819 const array_ty = ty.childType();
5820 const elem_ty = array_ty.childType();
5791 const array_ty = ty.childType(mod);
5792 const elem_ty = array_ty.childType(mod);
58215793 const abi_size = elem_ty.abiSize(mod);
5822 return llvm_usize_ty.constInt(array_ty.arrayLen() * abi_size, .False);
5794 return llvm_usize_ty.constInt(array_ty.arrayLen(mod) * abi_size, .False);
58235795 },
58245796 .Many, .C => unreachable,
58255797 }
......@@ -5832,10 +5804,11 @@ pub const FuncGen = struct {
58325804 }
58335805
58345806 fn airPtrSliceFieldPtr(self: *FuncGen, inst: Air.Inst.Index, index: c_uint) !?*llvm.Value {
5807 const mod = self.dg.module;
58355808 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
58365809 const slice_ptr = try self.resolveInst(ty_op.operand);
58375810 const slice_ptr_ty = self.typeOf(ty_op.operand);
5838 const slice_llvm_ty = try self.dg.lowerPtrElemTy(slice_ptr_ty.childType());
5811 const slice_llvm_ty = try self.dg.lowerPtrElemTy(slice_ptr_ty.childType(mod));
58395812
58405813 return self.builder.buildStructGEP(slice_llvm_ty, slice_ptr, index, "");
58415814 }
......@@ -5847,7 +5820,7 @@ pub const FuncGen = struct {
58475820 const slice_ty = self.typeOf(bin_op.lhs);
58485821 const slice = try self.resolveInst(bin_op.lhs);
58495822 const index = try self.resolveInst(bin_op.rhs);
5850 const elem_ty = slice_ty.childType();
5823 const elem_ty = slice_ty.childType(mod);
58515824 const llvm_elem_ty = try self.dg.lowerPtrElemTy(elem_ty);
58525825 const base_ptr = self.builder.buildExtractValue(slice, 0, "");
58535826 const indices: [1]*llvm.Value = .{index};
......@@ -5863,13 +5836,14 @@ pub const FuncGen = struct {
58635836 }
58645837
58655838 fn airSliceElemPtr(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
5839 const mod = self.dg.module;
58665840 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
58675841 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
58685842 const slice_ty = self.typeOf(bin_op.lhs);
58695843
58705844 const slice = try self.resolveInst(bin_op.lhs);
58715845 const index = try self.resolveInst(bin_op.rhs);
5872 const llvm_elem_ty = try self.dg.lowerPtrElemTy(slice_ty.childType());
5846 const llvm_elem_ty = try self.dg.lowerPtrElemTy(slice_ty.childType(mod));
58735847 const base_ptr = self.builder.buildExtractValue(slice, 0, "");
58745848 const indices: [1]*llvm.Value = .{index};
58755849 return self.builder.buildInBoundsGEP(llvm_elem_ty, base_ptr, &indices, indices.len, "");
......@@ -5884,7 +5858,7 @@ pub const FuncGen = struct {
58845858 const array_llvm_val = try self.resolveInst(bin_op.lhs);
58855859 const rhs = try self.resolveInst(bin_op.rhs);
58865860 const array_llvm_ty = try self.dg.lowerType(array_ty);
5887 const elem_ty = array_ty.childType();
5861 const elem_ty = array_ty.childType(mod);
58885862 if (isByRef(array_ty, mod)) {
58895863 const indices: [2]*llvm.Value = .{ self.context.intType(32).constNull(), rhs };
58905864 if (isByRef(elem_ty, mod)) {
......@@ -5923,7 +5897,7 @@ pub const FuncGen = struct {
59235897 const inst = body_tail[0];
59245898 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
59255899 const ptr_ty = self.typeOf(bin_op.lhs);
5926 const elem_ty = ptr_ty.childType();
5900 const elem_ty = ptr_ty.childType(mod);
59275901 const llvm_elem_ty = try self.dg.lowerPtrElemTy(elem_ty);
59285902 const base_ptr = try self.resolveInst(bin_op.lhs);
59295903 const rhs = try self.resolveInst(bin_op.rhs);
......@@ -5951,14 +5925,14 @@ pub const FuncGen = struct {
59515925 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
59525926 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
59535927 const ptr_ty = self.typeOf(bin_op.lhs);
5954 const elem_ty = ptr_ty.childType();
5928 const elem_ty = ptr_ty.childType(mod);
59555929 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return self.dg.lowerPtrToVoid(ptr_ty);
59565930
59575931 const base_ptr = try self.resolveInst(bin_op.lhs);
59585932 const rhs = try self.resolveInst(bin_op.rhs);
59595933
59605934 const elem_ptr = self.air.getRefType(ty_pl.ty);
5961 if (elem_ptr.ptrInfo().data.vector_index != .none) return base_ptr;
5935 if (elem_ptr.ptrInfo(mod).vector_index != .none) return base_ptr;
59625936
59635937 const llvm_elem_ty = try self.dg.lowerPtrElemTy(elem_ty);
59645938 if (ptr_ty.isSinglePointer(mod)) {
......@@ -6098,7 +6072,7 @@ pub const FuncGen = struct {
60986072 const field_ptr = try self.resolveInst(extra.field_ptr);
60996073
61006074 const target = self.dg.module.getTarget();
6101 const parent_ty = self.air.getRefType(ty_pl.ty).childType();
6075 const parent_ty = self.air.getRefType(ty_pl.ty).childType(mod);
61026076 const field_offset = parent_ty.structFieldOffset(extra.field_index, mod);
61036077
61046078 const res_ty = try self.dg.lowerType(self.air.getRefType(ty_pl.ty));
......@@ -6232,6 +6206,7 @@ pub const FuncGen = struct {
62326206 }
62336207
62346208 fn airDbgVarPtr(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
6209 const mod = self.dg.module;
62356210 const dib = self.dg.object.di_builder orelse return null;
62366211 const pl_op = self.air.instructions.items(.data)[inst].pl_op;
62376212 const operand = try self.resolveInst(pl_op.operand);
......@@ -6243,7 +6218,7 @@ pub const FuncGen = struct {
62436218 name.ptr,
62446219 self.di_file.?,
62456220 self.prev_dbg_line,
6246 try self.dg.object.lowerDebugType(ptr_ty.childType(), .full),
6221 try self.dg.object.lowerDebugType(ptr_ty.childType(mod), .full),
62476222 true, // always preserve
62486223 0, // flags
62496224 );
......@@ -6365,7 +6340,7 @@ pub const FuncGen = struct {
63656340 const output_inst = try self.resolveInst(output);
63666341 const output_ty = self.typeOf(output);
63676342 assert(output_ty.zigTypeTag(mod) == .Pointer);
6368 const elem_llvm_ty = try self.dg.lowerPtrElemTy(output_ty.childType());
6343 const elem_llvm_ty = try self.dg.lowerPtrElemTy(output_ty.childType(mod));
63696344
63706345 if (llvm_ret_indirect[i]) {
63716346 // Pass the result by reference as an indirect output (e.g. "=*m")
......@@ -6466,7 +6441,7 @@ pub const FuncGen = struct {
64666441 // an elementtype(<ty>) attribute.
64676442 if (constraint[0] == '*') {
64686443 llvm_param_attrs[llvm_param_i] = llvm_elem_ty orelse
6469 try self.dg.lowerPtrElemTy(arg_ty.childType());
6444 try self.dg.lowerPtrElemTy(arg_ty.childType(mod));
64706445 } else {
64716446 llvm_param_attrs[llvm_param_i] = null;
64726447 }
......@@ -6657,14 +6632,13 @@ pub const FuncGen = struct {
66576632 operand_is_ptr: bool,
66586633 pred: llvm.IntPredicate,
66596634 ) !?*llvm.Value {
6635 const mod = self.dg.module;
66606636 const un_op = self.air.instructions.items(.data)[inst].un_op;
66616637 const operand = try self.resolveInst(un_op);
66626638 const operand_ty = self.typeOf(un_op);
6663 const optional_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
6639 const optional_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
66646640 const optional_llvm_ty = try self.dg.lowerType(optional_ty);
6665 var buf: Type.Payload.ElemType = undefined;
6666 const payload_ty = optional_ty.optionalChild(&buf);
6667 const mod = self.dg.module;
6641 const payload_ty = optional_ty.optionalChild(mod);
66686642 if (optional_ty.optionalReprIsPayload(mod)) {
66696643 const loaded = if (operand_is_ptr)
66706644 self.builder.buildLoad(optional_llvm_ty, operand, "")
......@@ -6709,7 +6683,7 @@ pub const FuncGen = struct {
67096683 const un_op = self.air.instructions.items(.data)[inst].un_op;
67106684 const operand = try self.resolveInst(un_op);
67116685 const operand_ty = self.typeOf(un_op);
6712 const err_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
6686 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
67136687 const payload_ty = err_union_ty.errorUnionPayload();
67146688 const err_set_ty = try self.dg.lowerType(Type.anyerror);
67156689 const zero = err_set_ty.constNull();
......@@ -6748,9 +6722,8 @@ pub const FuncGen = struct {
67486722 const mod = self.dg.module;
67496723 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
67506724 const operand = try self.resolveInst(ty_op.operand);
6751 const optional_ty = self.typeOf(ty_op.operand).childType();
6752 var buf: Type.Payload.ElemType = undefined;
6753 const payload_ty = optional_ty.optionalChild(&buf);
6725 const optional_ty = self.typeOf(ty_op.operand).childType(mod);
6726 const payload_ty = optional_ty.optionalChild(mod);
67546727 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
67556728 // We have a pointer to a zero-bit value and we need to return
67566729 // a pointer to a zero-bit value.
......@@ -6770,9 +6743,8 @@ pub const FuncGen = struct {
67706743 const mod = self.dg.module;
67716744 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
67726745 const operand = try self.resolveInst(ty_op.operand);
6773 const optional_ty = self.typeOf(ty_op.operand).childType();
6774 var buf: Type.Payload.ElemType = undefined;
6775 const payload_ty = optional_ty.optionalChild(&buf);
6746 const optional_ty = self.typeOf(ty_op.operand).childType(mod);
6747 const payload_ty = optional_ty.optionalChild(mod);
67766748 const non_null_bit = self.context.intType(8).constInt(1, .False);
67776749 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
67786750 // We have a pointer to a i8. We need to set it to 1 and then return the same pointer.
......@@ -6827,9 +6799,9 @@ pub const FuncGen = struct {
68276799 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
68286800 const operand = try self.resolveInst(ty_op.operand);
68296801 const operand_ty = self.typeOf(ty_op.operand);
6830 const err_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
6802 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
68316803 const result_ty = self.typeOfIndex(inst);
6832 const payload_ty = if (operand_is_ptr) result_ty.childType() else result_ty;
6804 const payload_ty = if (operand_is_ptr) result_ty.childType(mod) else result_ty;
68336805
68346806 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
68356807 return if (operand_is_ptr) operand else null;
......@@ -6862,7 +6834,7 @@ pub const FuncGen = struct {
68626834 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
68636835 const operand = try self.resolveInst(ty_op.operand);
68646836 const operand_ty = self.typeOf(ty_op.operand);
6865 const err_union_ty = if (operand_is_ptr) operand_ty.childType() else operand_ty;
6837 const err_union_ty = if (operand_is_ptr) operand_ty.childType(mod) else operand_ty;
68666838 if (err_union_ty.errorUnionSet().errorSetIsEmpty(mod)) {
68676839 const err_llvm_ty = try self.dg.lowerType(Type.anyerror);
68686840 if (operand_is_ptr) {
......@@ -6895,7 +6867,7 @@ pub const FuncGen = struct {
68956867 const mod = self.dg.module;
68966868 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
68976869 const operand = try self.resolveInst(ty_op.operand);
6898 const err_union_ty = self.typeOf(ty_op.operand).childType();
6870 const err_union_ty = self.typeOf(ty_op.operand).childType(mod);
68996871
69006872 const payload_ty = err_union_ty.errorUnionPayload();
69016873 const non_error_val = try self.dg.lowerValue(.{ .ty = Type.anyerror, .val = Value.zero });
......@@ -6961,11 +6933,7 @@ pub const FuncGen = struct {
69616933 if (isByRef(optional_ty, mod)) {
69626934 const optional_ptr = self.buildAlloca(llvm_optional_ty, optional_ty.abiAlignment(mod));
69636935 const payload_ptr = self.builder.buildStructGEP(llvm_optional_ty, optional_ptr, 0, "");
6964 var ptr_ty_payload: Type.Payload.ElemType = .{
6965 .base = .{ .tag = .single_mut_pointer },
6966 .data = payload_ty,
6967 };
6968 const payload_ptr_ty = Type.initPayload(&ptr_ty_payload.base);
6936 const payload_ptr_ty = try mod.singleMutPtrType(payload_ty);
69696937 try self.store(payload_ptr, payload_ptr_ty, operand, .NotAtomic);
69706938 const non_null_ptr = self.builder.buildStructGEP(llvm_optional_ty, optional_ptr, 1, "");
69716939 _ = self.builder.buildStore(non_null_bit, non_null_ptr);
......@@ -6995,11 +6963,7 @@ pub const FuncGen = struct {
69956963 const store_inst = self.builder.buildStore(ok_err_code, err_ptr);
69966964 store_inst.setAlignment(Type.anyerror.abiAlignment(mod));
69976965 const payload_ptr = self.builder.buildStructGEP(err_un_llvm_ty, result_ptr, payload_offset, "");
6998 var ptr_ty_payload: Type.Payload.ElemType = .{
6999 .base = .{ .tag = .single_mut_pointer },
7000 .data = payload_ty,
7001 };
7002 const payload_ptr_ty = Type.initPayload(&ptr_ty_payload.base);
6966 const payload_ptr_ty = try mod.singleMutPtrType(payload_ty);
70036967 try self.store(payload_ptr, payload_ptr_ty, operand, .NotAtomic);
70046968 return result_ptr;
70056969 }
......@@ -7027,11 +6991,7 @@ pub const FuncGen = struct {
70276991 const store_inst = self.builder.buildStore(operand, err_ptr);
70286992 store_inst.setAlignment(Type.anyerror.abiAlignment(mod));
70296993 const payload_ptr = self.builder.buildStructGEP(err_un_llvm_ty, result_ptr, payload_offset, "");
7030 var ptr_ty_payload: Type.Payload.ElemType = .{
7031 .base = .{ .tag = .single_mut_pointer },
7032 .data = payload_ty,
7033 };
7034 const payload_ptr_ty = Type.initPayload(&ptr_ty_payload.base);
6994 const payload_ptr_ty = try mod.singleMutPtrType(payload_ty);
70356995 // TODO store undef to payload_ptr
70366996 _ = payload_ptr;
70376997 _ = payload_ptr_ty;
......@@ -7076,7 +7036,7 @@ pub const FuncGen = struct {
70767036 const operand = try self.resolveInst(extra.rhs);
70777037
70787038 const loaded_vector = blk: {
7079 const elem_llvm_ty = try self.dg.lowerType(vector_ptr_ty.childType());
7039 const elem_llvm_ty = try self.dg.lowerType(vector_ptr_ty.childType(mod));
70807040 const load_inst = self.builder.buildLoad(elem_llvm_ty, vector_ptr, "");
70817041 load_inst.setAlignment(vector_ptr_ty.ptrAlignment(mod));
70827042 load_inst.setVolatile(llvm.Bool.fromBool(vector_ptr_ty.isVolatilePtr()));
......@@ -7287,7 +7247,7 @@ pub const FuncGen = struct {
72877247 const inst_llvm_ty = try self.dg.lowerType(inst_ty);
72887248 const scalar_bit_size_minus_one = scalar_ty.bitSize(mod) - 1;
72897249 const bit_size_minus_one = if (inst_ty.zigTypeTag(mod) == .Vector) const_vector: {
7290 const vec_len = inst_ty.vectorLen();
7250 const vec_len = inst_ty.vectorLen(mod);
72917251 const scalar_llvm_ty = try self.dg.lowerType(scalar_ty);
72927252
72937253 const shifts = try self.gpa.alloc(*llvm.Value, vec_len);
......@@ -7361,7 +7321,7 @@ pub const FuncGen = struct {
73617321 if (scalar_ty.isSignedInt(mod)) {
73627322 const scalar_bit_size_minus_one = scalar_ty.bitSize(mod) - 1;
73637323 const bit_size_minus_one = if (inst_ty.zigTypeTag(mod) == .Vector) const_vector: {
7364 const vec_len = inst_ty.vectorLen();
7324 const vec_len = inst_ty.vectorLen(mod);
73657325 const scalar_llvm_ty = try self.dg.lowerType(scalar_ty);
73667326
73677327 const shifts = try self.gpa.alloc(*llvm.Value, vec_len);
......@@ -7384,13 +7344,14 @@ pub const FuncGen = struct {
73847344 }
73857345
73867346 fn airPtrAdd(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
7347 const mod = self.dg.module;
73877348 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
73887349 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
73897350 const ptr = try self.resolveInst(bin_op.lhs);
73907351 const offset = try self.resolveInst(bin_op.rhs);
73917352 const ptr_ty = self.typeOf(bin_op.lhs);
7392 const llvm_elem_ty = try self.dg.lowerPtrElemTy(ptr_ty.childType());
7393 switch (ptr_ty.ptrSize()) {
7353 const llvm_elem_ty = try self.dg.lowerPtrElemTy(ptr_ty.childType(mod));
7354 switch (ptr_ty.ptrSize(mod)) {
73947355 .One => {
73957356 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
73967357 const indices: [2]*llvm.Value = .{ self.context.intType(32).constNull(), offset };
......@@ -7409,14 +7370,15 @@ pub const FuncGen = struct {
74097370 }
74107371
74117372 fn airPtrSub(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
7373 const mod = self.dg.module;
74127374 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
74137375 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
74147376 const ptr = try self.resolveInst(bin_op.lhs);
74157377 const offset = try self.resolveInst(bin_op.rhs);
74167378 const negative_offset = self.builder.buildNeg(offset, "");
74177379 const ptr_ty = self.typeOf(bin_op.lhs);
7418 const llvm_elem_ty = try self.dg.lowerPtrElemTy(ptr_ty.childType());
7419 switch (ptr_ty.ptrSize()) {
7380 const llvm_elem_ty = try self.dg.lowerPtrElemTy(ptr_ty.childType(mod));
7381 switch (ptr_ty.ptrSize(mod)) {
74207382 .One => {
74217383 // It's a pointer to an array, so according to LLVM we need an extra GEP index.
74227384 const indices: [2]*llvm.Value = .{
......@@ -7587,7 +7549,7 @@ pub const FuncGen = struct {
75877549 };
75887550
75897551 if (ty.zigTypeTag(mod) == .Vector) {
7590 const vec_len = ty.vectorLen();
7552 const vec_len = ty.vectorLen(mod);
75917553 const vector_result_ty = llvm_i32.vectorType(vec_len);
75927554
75937555 var result = vector_result_ty.getUndef();
......@@ -7672,8 +7634,8 @@ pub const FuncGen = struct {
76727634 const shift_amt = int_llvm_ty.constInt(float_bits - 1, .False);
76737635 const sign_mask = one.constShl(shift_amt);
76747636 const result = if (ty.zigTypeTag(mod) == .Vector) blk: {
7675 const splat_sign_mask = self.builder.buildVectorSplat(ty.vectorLen(), sign_mask, "");
7676 const cast_ty = int_llvm_ty.vectorType(ty.vectorLen());
7637 const splat_sign_mask = self.builder.buildVectorSplat(ty.vectorLen(mod), sign_mask, "");
7638 const cast_ty = int_llvm_ty.vectorType(ty.vectorLen(mod));
76777639 const bitcasted_operand = self.builder.buildBitCast(params[0], cast_ty, "");
76787640 break :blk self.builder.buildXor(bitcasted_operand, splat_sign_mask, "");
76797641 } else blk: {
......@@ -7720,7 +7682,7 @@ pub const FuncGen = struct {
77207682 const libc_fn = self.getLibcFunction(fn_name, param_types[0..params.len], scalar_llvm_ty);
77217683 if (ty.zigTypeTag(mod) == .Vector) {
77227684 const result = llvm_ty.getUndef();
7723 return self.buildElementwiseCall(libc_fn, &params, result, ty.vectorLen());
7685 return self.buildElementwiseCall(libc_fn, &params, result, ty.vectorLen(mod));
77247686 }
77257687
77267688 break :b libc_fn;
......@@ -7887,7 +7849,7 @@ pub const FuncGen = struct {
78877849 const bits = lhs_scalar_llvm_ty.constInt(lhs_bits, .False);
78887850 const lhs_max = lhs_scalar_llvm_ty.constAllOnes();
78897851 if (rhs_ty.zigTypeTag(mod) == .Vector) {
7890 const vec_len = rhs_ty.vectorLen();
7852 const vec_len = rhs_ty.vectorLen(mod);
78917853 const bits_vec = self.builder.buildVectorSplat(vec_len, bits, "");
78927854 const lhs_max_vec = self.builder.buildVectorSplat(vec_len, lhs_max, "");
78937855 const in_range = self.builder.buildICmp(.ULT, rhs, bits_vec, "");
......@@ -8059,7 +8021,7 @@ pub const FuncGen = struct {
80598021 }
80608022
80618023 if (operand_ty.zigTypeTag(mod) == .Vector and inst_ty.zigTypeTag(mod) == .Array) {
8062 const elem_ty = operand_ty.childType();
8024 const elem_ty = operand_ty.childType(mod);
80638025 if (!result_is_ref) {
80648026 return self.dg.todo("implement bitcast vector to non-ref array", .{});
80658027 }
......@@ -8074,7 +8036,7 @@ pub const FuncGen = struct {
80748036 const llvm_usize = try self.dg.lowerType(Type.usize);
80758037 const llvm_u32 = self.context.intType(32);
80768038 const zero = llvm_usize.constNull();
8077 const vector_len = operand_ty.arrayLen();
8039 const vector_len = operand_ty.arrayLen(mod);
80788040 var i: u64 = 0;
80798041 while (i < vector_len) : (i += 1) {
80808042 const index_usize = llvm_usize.constInt(i, .False);
......@@ -8087,7 +8049,7 @@ pub const FuncGen = struct {
80878049 }
80888050 return array_ptr;
80898051 } else if (operand_ty.zigTypeTag(mod) == .Array and inst_ty.zigTypeTag(mod) == .Vector) {
8090 const elem_ty = operand_ty.childType();
8052 const elem_ty = operand_ty.childType(mod);
80918053 const llvm_vector_ty = try self.dg.lowerType(inst_ty);
80928054 if (!operand_is_ref) {
80938055 return self.dg.todo("implement bitcast non-ref array to vector", .{});
......@@ -8108,7 +8070,7 @@ pub const FuncGen = struct {
81088070 const llvm_usize = try self.dg.lowerType(Type.usize);
81098071 const llvm_u32 = self.context.intType(32);
81108072 const zero = llvm_usize.constNull();
8111 const vector_len = operand_ty.arrayLen();
8073 const vector_len = operand_ty.arrayLen(mod);
81128074 var vector = llvm_vector_ty.getUndef();
81138075 var i: u64 = 0;
81148076 while (i < vector_len) : (i += 1) {
......@@ -8207,7 +8169,7 @@ pub const FuncGen = struct {
82078169 fn airAlloc(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
82088170 const mod = self.dg.module;
82098171 const ptr_ty = self.typeOfIndex(inst);
8210 const pointee_type = ptr_ty.childType();
8172 const pointee_type = ptr_ty.childType(mod);
82118173 if (!pointee_type.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return self.dg.lowerPtrToVoid(ptr_ty);
82128174
82138175 const pointee_llvm_ty = try self.dg.lowerType(pointee_type);
......@@ -8218,7 +8180,7 @@ pub const FuncGen = struct {
82188180 fn airRetPtr(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
82198181 const mod = self.dg.module;
82208182 const ptr_ty = self.typeOfIndex(inst);
8221 const ret_ty = ptr_ty.childType();
8183 const ret_ty = ptr_ty.childType(mod);
82228184 if (!ret_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return self.dg.lowerPtrToVoid(ptr_ty);
82238185 if (self.ret_ptr) |ret_ptr| return ret_ptr;
82248186 const ret_llvm_ty = try self.dg.lowerType(ret_ty);
......@@ -8232,11 +8194,11 @@ pub const FuncGen = struct {
82328194 }
82338195
82348196 fn airStore(self: *FuncGen, inst: Air.Inst.Index, safety: bool) !?*llvm.Value {
8197 const mod = self.dg.module;
82358198 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
82368199 const dest_ptr = try self.resolveInst(bin_op.lhs);
82378200 const ptr_ty = self.typeOf(bin_op.lhs);
8238 const operand_ty = ptr_ty.childType();
8239 const mod = self.dg.module;
8201 const operand_ty = ptr_ty.childType(mod);
82408202
82418203 const val_is_undef = if (self.air.value(bin_op.rhs, mod)) |val| val.isUndefDeep() else false;
82428204 if (val_is_undef) {
......@@ -8271,8 +8233,10 @@ pub const FuncGen = struct {
82718233 ///
82728234 /// The first instruction of `body_tail` is the one whose copy we want to elide.
82738235 fn canElideLoad(fg: *FuncGen, body_tail: []const Air.Inst.Index) bool {
8236 const mod = fg.dg.module;
8237 const ip = &mod.intern_pool;
82748238 for (body_tail[1..]) |body_inst| {
8275 switch (fg.liveness.categorizeOperand(fg.air, body_inst, body_tail[0])) {
8239 switch (fg.liveness.categorizeOperand(fg.air, body_inst, body_tail[0], ip.*)) {
82768240 .none => continue,
82778241 .write, .noret, .complex => return false,
82788242 .tomb => return true,
......@@ -8288,7 +8252,7 @@ pub const FuncGen = struct {
82888252 const inst = body_tail[0];
82898253 const ty_op = fg.air.instructions.items(.data)[inst].ty_op;
82908254 const ptr_ty = fg.typeOf(ty_op.operand);
8291 const ptr_info = ptr_ty.ptrInfo().data;
8255 const ptr_info = ptr_ty.ptrInfo(mod);
82928256 const ptr = try fg.resolveInst(ty_op.operand);
82938257
82948258 elide: {
......@@ -8363,7 +8327,7 @@ pub const FuncGen = struct {
83638327 const ptr = try self.resolveInst(extra.ptr);
83648328 var expected_value = try self.resolveInst(extra.expected_value);
83658329 var new_value = try self.resolveInst(extra.new_value);
8366 const operand_ty = self.typeOf(extra.ptr).elemType();
8330 const operand_ty = self.typeOf(extra.ptr).childType(mod);
83678331 const opt_abi_ty = self.dg.getAtomicAbiType(operand_ty, false);
83688332 if (opt_abi_ty) |abi_ty| {
83698333 // operand needs widening and truncating
......@@ -8409,7 +8373,7 @@ pub const FuncGen = struct {
84098373 const extra = self.air.extraData(Air.AtomicRmw, pl_op.payload).data;
84108374 const ptr = try self.resolveInst(pl_op.operand);
84118375 const ptr_ty = self.typeOf(pl_op.operand);
8412 const operand_ty = ptr_ty.elemType();
8376 const operand_ty = ptr_ty.childType(mod);
84138377 const operand = try self.resolveInst(extra.operand);
84148378 const is_signed_int = operand_ty.isSignedInt(mod);
84158379 const is_float = operand_ty.isRuntimeFloat();
......@@ -8464,7 +8428,7 @@ pub const FuncGen = struct {
84648428 const atomic_load = self.air.instructions.items(.data)[inst].atomic_load;
84658429 const ptr = try self.resolveInst(atomic_load.ptr);
84668430 const ptr_ty = self.typeOf(atomic_load.ptr);
8467 const ptr_info = ptr_ty.ptrInfo().data;
8431 const ptr_info = ptr_ty.ptrInfo(mod);
84688432 const elem_ty = ptr_info.pointee_type;
84698433 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod))
84708434 return null;
......@@ -8497,7 +8461,7 @@ pub const FuncGen = struct {
84978461 const mod = self.dg.module;
84988462 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
84998463 const ptr_ty = self.typeOf(bin_op.lhs);
8500 const operand_ty = ptr_ty.childType();
8464 const operand_ty = ptr_ty.childType(mod);
85018465 if (!operand_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) return null;
85028466 const ptr = try self.resolveInst(bin_op.lhs);
85038467 var element = try self.resolveInst(bin_op.rhs);
......@@ -8595,9 +8559,9 @@ pub const FuncGen = struct {
85958559 const end_block = self.context.appendBasicBlock(self.llvm_func, "InlineMemsetEnd");
85968560
85978561 const llvm_usize_ty = self.context.intType(target.ptrBitWidth());
8598 const len = switch (ptr_ty.ptrSize()) {
8562 const len = switch (ptr_ty.ptrSize(mod)) {
85998563 .Slice => self.builder.buildExtractValue(dest_slice, 1, ""),
8600 .One => llvm_usize_ty.constInt(ptr_ty.childType().arrayLen(), .False),
8564 .One => llvm_usize_ty.constInt(ptr_ty.childType(mod).arrayLen(mod), .False),
86018565 .Many, .C => unreachable,
86028566 };
86038567 const elem_llvm_ty = try self.dg.lowerType(elem_ty);
......@@ -8665,7 +8629,7 @@ pub const FuncGen = struct {
86658629 fn airSetUnionTag(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
86668630 const mod = self.dg.module;
86678631 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
8668 const un_ty = self.typeOf(bin_op.lhs).childType();
8632 const un_ty = self.typeOf(bin_op.lhs).childType(mod);
86698633 const layout = un_ty.unionGetLayout(mod);
86708634 if (layout.tag_size == 0) return null;
86718635 const union_ptr = try self.resolveInst(bin_op.lhs);
......@@ -8791,7 +8755,7 @@ pub const FuncGen = struct {
87918755 // The truncated result at the end will be the correct bswap
87928756 const scalar_llvm_ty = self.context.intType(bits + 8);
87938757 if (operand_ty.zigTypeTag(mod) == .Vector) {
8794 const vec_len = operand_ty.vectorLen();
8758 const vec_len = operand_ty.vectorLen(mod);
87958759 operand_llvm_ty = scalar_llvm_ty.vectorType(vec_len);
87968760
87978761 const shifts = try self.gpa.alloc(*llvm.Value, vec_len);
......@@ -8980,7 +8944,7 @@ pub const FuncGen = struct {
89808944 defer self.gpa.free(fqn);
89818945 const llvm_fn_name = try std.fmt.allocPrintZ(arena, "__zig_tag_name_{s}", .{fqn});
89828946
8983 const slice_ty = Type.initTag(.const_slice_u8_sentinel_0);
8947 const slice_ty = Type.const_slice_u8_sentinel_0;
89848948 const llvm_ret_ty = try self.dg.lowerType(slice_ty);
89858949 const usize_llvm_ty = try self.dg.lowerType(Type.usize);
89868950 const slice_alignment = slice_ty.abiAlignment(mod);
......@@ -9097,10 +9061,11 @@ pub const FuncGen = struct {
90979061 }
90989062
90999063 fn airSplat(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
9064 const mod = self.dg.module;
91009065 const ty_op = self.air.instructions.items(.data)[inst].ty_op;
91019066 const scalar = try self.resolveInst(ty_op.operand);
91029067 const vector_ty = self.typeOfIndex(inst);
9103 const len = vector_ty.vectorLen();
9068 const len = vector_ty.vectorLen(mod);
91049069 return self.builder.buildVectorSplat(len, scalar, "");
91059070 }
91069071
......@@ -9122,7 +9087,7 @@ pub const FuncGen = struct {
91229087 const b = try self.resolveInst(extra.b);
91239088 const mask = self.air.values[extra.mask];
91249089 const mask_len = extra.mask_len;
9125 const a_len = self.typeOf(extra.a).vectorLen();
9090 const a_len = self.typeOf(extra.a).vectorLen(mod);
91269091
91279092 // LLVM uses integers larger than the length of the first array to
91289093 // index into the second array. This was deemed unnecessarily fragile
......@@ -9298,14 +9263,14 @@ pub const FuncGen = struct {
92989263 .ty = scalar_ty,
92999264 .val = Value.initPayload(&init_value_payload.base),
93009265 });
9301 return self.buildReducedCall(libc_fn, operand, operand_ty.vectorLen(), init_value);
9266 return self.buildReducedCall(libc_fn, operand, operand_ty.vectorLen(mod), init_value);
93029267 }
93039268
93049269 fn airAggregateInit(self: *FuncGen, inst: Air.Inst.Index) !?*llvm.Value {
93059270 const mod = self.dg.module;
93069271 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
93079272 const result_ty = self.typeOfIndex(inst);
9308 const len = @intCast(usize, result_ty.arrayLen());
9273 const len = @intCast(usize, result_ty.arrayLen(mod));
93099274 const elements = @ptrCast([]const Air.Inst.Ref, self.air.extra[ty_pl.payload..][0..len]);
93109275 const llvm_result_ty = try self.dg.lowerType(result_ty);
93119276
......@@ -9400,7 +9365,7 @@ pub const FuncGen = struct {
94009365 const llvm_usize = try self.dg.lowerType(Type.usize);
94019366 const alloca_inst = self.buildAlloca(llvm_result_ty, result_ty.abiAlignment(mod));
94029367
9403 const array_info = result_ty.arrayInfo();
9368 const array_info = result_ty.arrayInfo(mod);
94049369 var elem_ptr_payload: Type.Payload.Pointer = .{
94059370 .data = .{
94069371 .pointee_type = array_info.elem_type,
......@@ -9720,7 +9685,7 @@ pub const FuncGen = struct {
97209685 }
97219686
97229687 const mod = self.dg.module;
9723 const slice_ty = Type.initTag(.const_slice_u8_sentinel_0);
9688 const slice_ty = Type.const_slice_u8_sentinel_0;
97249689 const slice_alignment = slice_ty.abiAlignment(mod);
97259690 const llvm_slice_ptr_ty = self.context.pointerType(0); // TODO: Address space
97269691
......@@ -9763,9 +9728,8 @@ pub const FuncGen = struct {
97639728 opt_ty: Type,
97649729 can_elide_load: bool,
97659730 ) !*llvm.Value {
9766 var buf: Type.Payload.ElemType = undefined;
9767 const payload_ty = opt_ty.optionalChild(&buf);
97689731 const mod = fg.dg.module;
9732 const payload_ty = opt_ty.optionalChild(mod);
97699733
97709734 if (isByRef(opt_ty, mod)) {
97719735 // We have a pointer and we need to return a pointer to the first field.
......@@ -9827,13 +9791,13 @@ pub const FuncGen = struct {
98279791 struct_ptr_ty: Type,
98289792 field_index: u32,
98299793 ) !?*llvm.Value {
9830 const struct_ty = struct_ptr_ty.childType();
98319794 const mod = self.dg.module;
9795 const struct_ty = struct_ptr_ty.childType(mod);
98329796 switch (struct_ty.zigTypeTag(mod)) {
98339797 .Struct => switch (struct_ty.containerLayout()) {
98349798 .Packed => {
98359799 const result_ty = self.typeOfIndex(inst);
9836 const result_ty_info = result_ty.ptrInfo().data;
9800 const result_ty_info = result_ty.ptrInfo(mod);
98379801
98389802 if (result_ty_info.host_size != 0) {
98399803 // From LLVM's perspective, a pointer to a packed struct and a pointer
......@@ -9919,7 +9883,7 @@ pub const FuncGen = struct {
99199883 /// For isByRef=false types, it creates a load instruction and returns it.
99209884 fn load(self: *FuncGen, ptr: *llvm.Value, ptr_ty: Type) !?*llvm.Value {
99219885 const mod = self.dg.module;
9922 const info = ptr_ty.ptrInfo().data;
9886 const info = ptr_ty.ptrInfo(mod);
99239887 if (!info.pointee_type.hasRuntimeBitsIgnoreComptime(mod)) return null;
99249888
99259889 const ptr_alignment = info.alignment(mod);
......@@ -9954,7 +9918,7 @@ pub const FuncGen = struct {
99549918 containing_int.setAlignment(ptr_alignment);
99559919 containing_int.setVolatile(ptr_volatile);
99569920
9957 const elem_bits = @intCast(c_uint, ptr_ty.elemType().bitSize(mod));
9921 const elem_bits = @intCast(c_uint, ptr_ty.childType(mod).bitSize(mod));
99589922 const shift_amt = containing_int.typeOf().constInt(info.bit_offset, .False);
99599923 const shifted_value = self.builder.buildLShr(containing_int, shift_amt, "");
99609924 const elem_llvm_ty = try self.dg.lowerType(info.pointee_type);
......@@ -9992,9 +9956,9 @@ pub const FuncGen = struct {
99929956 elem: *llvm.Value,
99939957 ordering: llvm.AtomicOrdering,
99949958 ) !void {
9995 const info = ptr_ty.ptrInfo().data;
9996 const elem_ty = info.pointee_type;
99979959 const mod = self.dg.module;
9960 const info = ptr_ty.ptrInfo(mod);
9961 const elem_ty = info.pointee_type;
99989962 if (!elem_ty.isFnOrHasRuntimeBitsIgnoreComptime(mod)) {
99999963 return;
100009964 }
......@@ -10026,7 +9990,7 @@ pub const FuncGen = struct {
100269990 assert(ordering == .NotAtomic);
100279991 containing_int.setAlignment(ptr_alignment);
100289992 containing_int.setVolatile(ptr_volatile);
10029 const elem_bits = @intCast(c_uint, ptr_ty.elemType().bitSize(mod));
9993 const elem_bits = @intCast(c_uint, ptr_ty.childType(mod).bitSize(mod));
100309994 const containing_int_ty = containing_int.typeOf();
100319995 const shift_amt = containing_int_ty.constInt(info.bit_offset, .False);
100329996 // Convert to equally-sized integer type in order to perform the bit
......@@ -10864,8 +10828,7 @@ const ParamTypeIterator = struct {
1086410828 .Unspecified, .Inline => {
1086510829 it.zig_index += 1;
1086610830 it.llvm_index += 1;
10867 var buf: Type.Payload.ElemType = undefined;
10868 if (ty.isSlice(mod) or (ty.zigTypeTag(mod) == .Optional and ty.optionalChild(&buf).isSlice(mod))) {
10831 if (ty.isSlice(mod) or (ty.zigTypeTag(mod) == .Optional and ty.optionalChild(mod).isSlice(mod))) {
1086910832 it.llvm_index += 1;
1087010833 return .slice;
1087110834 } else if (isByRef(ty, mod)) {
......@@ -11185,8 +11148,7 @@ fn isByRef(ty: Type, mod: *const Module) bool {
1118511148 return true;
1118611149 },
1118711150 .Optional => {
11188 var buf: Type.Payload.ElemType = undefined;
11189 const payload_ty = ty.optionalChild(&buf);
11151 const payload_ty = ty.optionalChild(mod);
1119011152 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
1119111153 return false;
1119211154 }
src/codegen/spirv.zig+33-31
......@@ -625,20 +625,20 @@ pub const DeclGen = struct {
625625 .Array => switch (val.tag()) {
626626 .aggregate => {
627627 const elem_vals = val.castTag(.aggregate).?.data;
628 const elem_ty = ty.elemType();
629 const len = @intCast(u32, ty.arrayLenIncludingSentinel()); // TODO: limit spir-v to 32 bit arrays in a more elegant way.
628 const elem_ty = ty.childType(mod);
629 const len = @intCast(u32, ty.arrayLenIncludingSentinel(mod)); // TODO: limit spir-v to 32 bit arrays in a more elegant way.
630630 for (elem_vals[0..len]) |elem_val| {
631631 try self.lower(elem_ty, elem_val);
632632 }
633633 },
634634 .repeated => {
635635 const elem_val = val.castTag(.repeated).?.data;
636 const elem_ty = ty.elemType();
637 const len = @intCast(u32, ty.arrayLen());
636 const elem_ty = ty.childType(mod);
637 const len = @intCast(u32, ty.arrayLen(mod));
638638 for (0..len) |_| {
639639 try self.lower(elem_ty, elem_val);
640640 }
641 if (ty.sentinel()) |sentinel| {
641 if (ty.sentinel(mod)) |sentinel| {
642642 try self.lower(elem_ty, sentinel);
643643 }
644644 },
......@@ -646,7 +646,7 @@ pub const DeclGen = struct {
646646 const str_lit = val.castTag(.str_lit).?.data;
647647 const bytes = dg.module.string_literal_bytes.items[str_lit.index..][0..str_lit.len];
648648 try self.addBytes(bytes);
649 if (ty.sentinel()) |sentinel| {
649 if (ty.sentinel(mod)) |sentinel| {
650650 try self.addByte(@intCast(u8, sentinel.toUnsignedInt(mod)));
651651 }
652652 },
......@@ -706,8 +706,7 @@ pub const DeclGen = struct {
706706 }
707707 },
708708 .Optional => {
709 var opt_buf: Type.Payload.ElemType = undefined;
710 const payload_ty = ty.optionalChild(&opt_buf);
709 const payload_ty = ty.optionalChild(mod);
711710 const has_payload = !val.isNull(mod);
712711 const abi_size = ty.abiSize(mod);
713712
......@@ -1216,10 +1215,10 @@ pub const DeclGen = struct {
12161215 return try self.spv.resolve(.{ .float_type = .{ .bits = bits } });
12171216 },
12181217 .Array => {
1219 const elem_ty = ty.childType();
1218 const elem_ty = ty.childType(mod);
12201219 const elem_ty_ref = try self.resolveType(elem_ty, .direct);
1221 const total_len = std.math.cast(u32, ty.arrayLenIncludingSentinel()) orelse {
1222 return self.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel()});
1220 const total_len = std.math.cast(u32, ty.arrayLenIncludingSentinel(mod)) orelse {
1221 return self.fail("array type of {} elements is too large", .{ty.arrayLenIncludingSentinel(mod)});
12231222 };
12241223 return self.spv.arrayType(total_len, elem_ty_ref);
12251224 },
......@@ -1248,7 +1247,7 @@ pub const DeclGen = struct {
12481247 },
12491248 },
12501249 .Pointer => {
1251 const ptr_info = ty.ptrInfo().data;
1250 const ptr_info = ty.ptrInfo(mod);
12521251
12531252 const storage_class = spvStorageClass(ptr_info.@"addrspace");
12541253 const child_ty_ref = try self.resolveType(ptr_info.pointee_type, .indirect);
......@@ -1280,8 +1279,8 @@ pub const DeclGen = struct {
12801279 // TODO: Properly verify sizes and child type.
12811280
12821281 return try self.spv.resolve(.{ .vector_type = .{
1283 .component_type = try self.resolveType(ty.elemType(), repr),
1284 .component_count = @intCast(u32, ty.vectorLen()),
1282 .component_type = try self.resolveType(ty.childType(mod), repr),
1283 .component_count = @intCast(u32, ty.vectorLen(mod)),
12851284 } });
12861285 },
12871286 .Struct => {
......@@ -1335,8 +1334,7 @@ pub const DeclGen = struct {
13351334 } });
13361335 },
13371336 .Optional => {
1338 var buf: Type.Payload.ElemType = undefined;
1339 const payload_ty = ty.optionalChild(&buf);
1337 const payload_ty = ty.optionalChild(mod);
13401338 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
13411339 // Just use a bool.
13421340 // Note: Always generate the bool with indirect format, to save on some sanity
......@@ -1685,7 +1683,8 @@ pub const DeclGen = struct {
16851683 }
16861684
16871685 fn load(self: *DeclGen, ptr_ty: Type, ptr_id: IdRef) !IdRef {
1688 const value_ty = ptr_ty.childType();
1686 const mod = self.module;
1687 const value_ty = ptr_ty.childType(mod);
16891688 const indirect_value_ty_ref = try self.resolveType(value_ty, .indirect);
16901689 const result_id = self.spv.allocId();
16911690 const access = spec.MemoryAccess.Extended{
......@@ -1701,7 +1700,8 @@ pub const DeclGen = struct {
17011700 }
17021701
17031702 fn store(self: *DeclGen, ptr_ty: Type, ptr_id: IdRef, value_id: IdRef) !void {
1704 const value_ty = ptr_ty.childType();
1703 const mod = self.module;
1704 const value_ty = ptr_ty.childType(mod);
17051705 const indirect_value_id = try self.convertToIndirect(value_ty, value_id);
17061706 const access = spec.MemoryAccess.Extended{
17071707 .Volatile = ptr_ty.isVolatilePtr(),
......@@ -2072,7 +2072,7 @@ pub const DeclGen = struct {
20722072 const b = try self.resolve(extra.b);
20732073 const mask = self.air.values[extra.mask];
20742074 const mask_len = extra.mask_len;
2075 const a_len = self.typeOf(extra.a).vectorLen();
2075 const a_len = self.typeOf(extra.a).vectorLen(mod);
20762076
20772077 const result_id = self.spv.allocId();
20782078 const result_type_id = try self.resolveTypeId(ty);
......@@ -2138,9 +2138,10 @@ pub const DeclGen = struct {
21382138 }
21392139
21402140 fn ptrAdd(self: *DeclGen, result_ty: Type, ptr_ty: Type, ptr_id: IdRef, offset_id: IdRef) !IdRef {
2141 const mod = self.module;
21412142 const result_ty_ref = try self.resolveType(result_ty, .direct);
21422143
2143 switch (ptr_ty.ptrSize()) {
2144 switch (ptr_ty.ptrSize(mod)) {
21442145 .One => {
21452146 // Pointer to array
21462147 // TODO: Is this correct?
......@@ -2498,7 +2499,7 @@ pub const DeclGen = struct {
24982499 // Construct new pointer type for the resulting pointer
24992500 const elem_ty = ptr_ty.elemType2(mod); // use elemType() so that we get T for *[N]T.
25002501 const elem_ty_ref = try self.resolveType(elem_ty, .direct);
2501 const elem_ptr_ty_ref = try self.spv.ptrType(elem_ty_ref, spvStorageClass(ptr_ty.ptrAddressSpace()));
2502 const elem_ptr_ty_ref = try self.spv.ptrType(elem_ty_ref, spvStorageClass(ptr_ty.ptrAddressSpace(mod)));
25022503 if (ptr_ty.isSinglePointer(mod)) {
25032504 // Pointer-to-array. In this case, the resulting pointer is not of the same type
25042505 // as the ptr_ty (we want a *T, not a *[N]T), and hence we need to use accessChain.
......@@ -2516,7 +2517,7 @@ pub const DeclGen = struct {
25162517 const ty_pl = self.air.instructions.items(.data)[inst].ty_pl;
25172518 const bin_op = self.air.extraData(Air.Bin, ty_pl.payload).data;
25182519 const ptr_ty = self.typeOf(bin_op.lhs);
2519 const elem_ty = ptr_ty.childType();
2520 const elem_ty = ptr_ty.childType(mod);
25202521 // TODO: Make this return a null ptr or something
25212522 if (!elem_ty.hasRuntimeBitsIgnoreComptime(mod)) return null;
25222523
......@@ -2526,6 +2527,7 @@ pub const DeclGen = struct {
25262527 }
25272528
25282529 fn airPtrElemVal(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
2530 const mod = self.module;
25292531 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
25302532 const ptr_ty = self.typeOf(bin_op.lhs);
25312533 const ptr_id = try self.resolve(bin_op.lhs);
......@@ -2536,9 +2538,9 @@ pub const DeclGen = struct {
25362538 // If we have a pointer-to-array, construct an element pointer to use with load()
25372539 // If we pass ptr_ty directly, it will attempt to load the entire array rather than
25382540 // just an element.
2539 var elem_ptr_info = ptr_ty.ptrInfo();
2540 elem_ptr_info.data.size = .One;
2541 const elem_ptr_ty = Type.initPayload(&elem_ptr_info.base);
2541 var elem_ptr_info = ptr_ty.ptrInfo(mod);
2542 elem_ptr_info.size = .One;
2543 const elem_ptr_ty = try Type.ptr(undefined, mod, elem_ptr_info);
25422544
25432545 return try self.load(elem_ptr_ty, elem_ptr_id);
25442546 }
......@@ -2586,7 +2588,7 @@ pub const DeclGen = struct {
25862588 field_index: u32,
25872589 ) !?IdRef {
25882590 const mod = self.module;
2589 const object_ty = object_ptr_ty.childType();
2591 const object_ty = object_ptr_ty.childType(mod);
25902592 switch (object_ty.zigTypeTag(mod)) {
25912593 .Struct => switch (object_ty.containerLayout()) {
25922594 .Packed => unreachable, // TODO
......@@ -2662,9 +2664,10 @@ pub const DeclGen = struct {
26622664
26632665 fn airAlloc(self: *DeclGen, inst: Air.Inst.Index) !?IdRef {
26642666 if (self.liveness.isUnused(inst)) return null;
2667 const mod = self.module;
26652668 const ptr_ty = self.typeOfIndex(inst);
2666 assert(ptr_ty.ptrAddressSpace() == .generic);
2667 const child_ty = ptr_ty.childType();
2669 assert(ptr_ty.ptrAddressSpace(mod) == .generic);
2670 const child_ty = ptr_ty.childType(mod);
26682671 const child_ty_ref = try self.resolveType(child_ty, .indirect);
26692672 return try self.alloc(child_ty_ref, null);
26702673 }
......@@ -2834,7 +2837,7 @@ pub const DeclGen = struct {
28342837 const mod = self.module;
28352838 const un_op = self.air.instructions.items(.data)[inst].un_op;
28362839 const ptr_ty = self.typeOf(un_op);
2837 const ret_ty = ptr_ty.childType();
2840 const ret_ty = ptr_ty.childType(mod);
28382841
28392842 if (!ret_ty.hasRuntimeBitsIgnoreComptime(mod)) {
28402843 try self.func.body.emit(self.spv.gpa, .OpReturn, {});
......@@ -2971,8 +2974,7 @@ pub const DeclGen = struct {
29712974 const operand_id = try self.resolve(un_op);
29722975 const optional_ty = self.typeOf(un_op);
29732976
2974 var buf: Type.Payload.ElemType = undefined;
2975 const payload_ty = optional_ty.optionalChild(&buf);
2977 const payload_ty = optional_ty.optionalChild(mod);
29762978
29772979 const bool_ty_ref = try self.resolveType(Type.bool, .direct);
29782980
src/codegen/spirv/Module.zig+2-1
......@@ -11,7 +11,8 @@ const std = @import("std");
1111const Allocator = std.mem.Allocator;
1212const assert = std.debug.assert;
1313
14const ZigDecl = @import("../../Module.zig").Decl;
14const ZigModule = @import("../../Module.zig");
15const ZigDecl = ZigModule.Decl;
1516
1617const spec = @import("spec.zig");
1718const Word = spec.Word;
src/link/Dwarf.zig+5-6
......@@ -219,8 +219,7 @@ pub const DeclState = struct {
219219 try dbg_info_buffer.writer().print("{}\x00", .{ty.fmt(mod)});
220220 } else {
221221 // Non-pointer optionals are structs: struct { .maybe = *, .val = * }
222 var buf = try arena.create(Type.Payload.ElemType);
223 const payload_ty = ty.optionalChild(buf);
222 const payload_ty = ty.optionalChild(mod);
224223 // DW.AT.structure_type
225224 try dbg_info_buffer.append(@enumToInt(AbbrevKind.struct_type));
226225 // DW.AT.byte_size, DW.FORM.udata
......@@ -304,7 +303,7 @@ pub const DeclState = struct {
304303 // DW.AT.type, DW.FORM.ref4
305304 const index = dbg_info_buffer.items.len;
306305 try dbg_info_buffer.resize(index + 4);
307 try self.addTypeRelocGlobal(atom_index, ty.childType(), @intCast(u32, index));
306 try self.addTypeRelocGlobal(atom_index, ty.childType(mod), @intCast(u32, index));
308307 }
309308 },
310309 .Array => {
......@@ -315,7 +314,7 @@ pub const DeclState = struct {
315314 // DW.AT.type, DW.FORM.ref4
316315 var index = dbg_info_buffer.items.len;
317316 try dbg_info_buffer.resize(index + 4);
318 try self.addTypeRelocGlobal(atom_index, ty.childType(), @intCast(u32, index));
317 try self.addTypeRelocGlobal(atom_index, ty.childType(mod), @intCast(u32, index));
319318 // DW.AT.subrange_type
320319 try dbg_info_buffer.append(@enumToInt(AbbrevKind.array_dim));
321320 // DW.AT.type, DW.FORM.ref4
......@@ -323,7 +322,7 @@ pub const DeclState = struct {
323322 try dbg_info_buffer.resize(index + 4);
324323 try self.addTypeRelocGlobal(atom_index, Type.usize, @intCast(u32, index));
325324 // DW.AT.count, DW.FORM.udata
326 const len = ty.arrayLenIncludingSentinel();
325 const len = ty.arrayLenIncludingSentinel(mod);
327326 try leb128.writeULEB128(dbg_info_buffer.writer(), len);
328327 // DW.AT.array_type delimit children
329328 try dbg_info_buffer.append(0);
......@@ -688,7 +687,7 @@ pub const DeclState = struct {
688687 const mod = self.mod;
689688 const target = mod.getTarget();
690689 const endian = target.cpu.arch.endian();
691 const child_ty = if (is_ptr) ty.childType() else ty;
690 const child_ty = if (is_ptr) ty.childType(mod) else ty;
692691
693692 switch (loc) {
694693 .register => |reg| {
src/link/Wasm.zig+2-2
......@@ -2931,7 +2931,7 @@ pub fn getErrorTableSymbol(wasm: *Wasm) !u32 {
29312931
29322932 const atom_index = try wasm.createAtom();
29332933 const atom = wasm.getAtomPtr(atom_index);
2934 const slice_ty = Type.initTag(.const_slice_u8_sentinel_0);
2934 const slice_ty = Type.const_slice_u8_sentinel_0;
29352935 const mod = wasm.base.options.module.?;
29362936 atom.alignment = slice_ty.abiAlignment(mod);
29372937 const sym_index = atom.sym_index;
......@@ -2988,7 +2988,7 @@ fn populateErrorNameTable(wasm: *Wasm) !void {
29882988 for (mod.error_name_list.items) |error_name| {
29892989 const len = @intCast(u32, error_name.len + 1); // names are 0-termianted
29902990
2991 const slice_ty = Type.initTag(.const_slice_u8_sentinel_0);
2991 const slice_ty = Type.const_slice_u8_sentinel_0;
29922992 const offset = @intCast(u32, atom.code.items.len);
29932993 // first we create the data for the slice of the name
29942994 try atom.code.appendNTimes(wasm.base.allocator, 0, 4); // ptr to name, will be relocated
src/print_air.zig+4-2
......@@ -433,9 +433,10 @@ const Writer = struct {
433433 }
434434
435435 fn writeAggregateInit(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
436 const mod = w.module;
436437 const ty_pl = w.air.instructions.items(.data)[inst].ty_pl;
437438 const vector_ty = w.air.getRefType(ty_pl.ty);
438 const len = @intCast(usize, vector_ty.arrayLen());
439 const len = @intCast(usize, vector_ty.arrayLen(mod));
439440 const elements = @ptrCast([]const Air.Inst.Ref, w.air.extra[ty_pl.payload..][0..len]);
440441
441442 try w.writeType(s, vector_ty);
......@@ -512,10 +513,11 @@ const Writer = struct {
512513 }
513514
514515 fn writeSelect(w: *Writer, s: anytype, inst: Air.Inst.Index) @TypeOf(s).Error!void {
516 const mod = w.module;
515517 const pl_op = w.air.instructions.items(.data)[inst].pl_op;
516518 const extra = w.air.extraData(Air.Bin, pl_op.payload).data;
517519
518 const elem_ty = w.typeOfIndex(inst).childType();
520 const elem_ty = w.typeOfIndex(inst).childType(mod);
519521 try w.writeType(s, elem_ty);
520522 try s.writeAll(", ");
521523 try w.writeOperand(s, inst, 0, pl_op.operand);
src/type.zig+472-1298
......@@ -40,7 +40,7 @@ pub const Type = struct {
4040 .ptr_type => return .Pointer,
4141 .array_type => return .Array,
4242 .vector_type => return .Vector,
43 .optional_type => return .Optional,
43 .opt_type => return .Optional,
4444 .error_union_type => return .ErrorUnion,
4545 .struct_type => return .Struct,
4646 .union_type => return .Union,
......@@ -118,38 +118,17 @@ pub const Type = struct {
118118 .function => return .Fn,
119119
120120 .array,
121 .array_u8_sentinel_0,
122 .array_u8,
123121 .array_sentinel,
124122 => return .Array,
125123
126 .vector => return .Vector,
127
128 .single_const_pointer_to_comptime_int,
129 .const_slice_u8,
130 .const_slice_u8_sentinel_0,
131 .single_const_pointer,
132 .single_mut_pointer,
133 .many_const_pointer,
134 .many_mut_pointer,
135 .c_const_pointer,
136 .c_mut_pointer,
137 .const_slice,
138 .mut_slice,
139124 .pointer,
140125 .inferred_alloc_const,
141126 .inferred_alloc_mut,
142 .manyptr_u8,
143 .manyptr_const_u8,
144 .manyptr_const_u8_sentinel_0,
145127 => return .Pointer,
146128
147 .optional,
148 .optional_single_const_pointer,
149 .optional_single_mut_pointer,
150 => return .Optional,
129 .optional => return .Optional,
151130
152 .anyerror_void_error_union, .error_union => return .ErrorUnion,
131 .error_union => return .ErrorUnion,
153132
154133 .anyframe_T => return .AnyFrame,
155134
......@@ -177,8 +156,7 @@ pub const Type = struct {
177156 return switch (self.zigTypeTag(mod)) {
178157 .ErrorUnion => self.errorUnionPayload().baseZigTypeTag(mod),
179158 .Optional => {
180 var buf: Payload.ElemType = undefined;
181 return self.optionalChild(&buf).baseZigTypeTag(mod);
159 return self.optionalChild(mod).baseZigTypeTag(mod);
182160 },
183161 else => |t| t,
184162 };
......@@ -218,8 +196,7 @@ pub const Type = struct {
218196 .Pointer => !ty.isSlice(mod) and (is_equality_cmp or ty.isCPtr()),
219197 .Optional => {
220198 if (!is_equality_cmp) return false;
221 var buf: Payload.ElemType = undefined;
222 return ty.optionalChild(&buf).isSelfComparable(mod, is_equality_cmp);
199 return ty.optionalChild(mod).isSelfComparable(mod, is_equality_cmp);
223200 },
224201 };
225202 }
......@@ -275,9 +252,8 @@ pub const Type = struct {
275252 }
276253
277254 pub fn castTag(self: Type, comptime t: Tag) ?*t.Type() {
278 if (self.ip_index != .none) {
279 return null;
280 }
255 assert(self.ip_index == .none);
256
281257 if (@enumToInt(self.legacy.tag_if_small_enough) < Tag.no_payload_count)
282258 return null;
283259
......@@ -287,281 +263,61 @@ pub const Type = struct {
287263 return null;
288264 }
289265
290 pub fn castPointer(self: Type) ?*Payload.ElemType {
291 return switch (self.tag()) {
292 .single_const_pointer,
293 .single_mut_pointer,
294 .many_const_pointer,
295 .many_mut_pointer,
296 .c_const_pointer,
297 .c_mut_pointer,
298 .const_slice,
299 .mut_slice,
300 .optional_single_const_pointer,
301 .optional_single_mut_pointer,
302 .manyptr_u8,
303 .manyptr_const_u8,
304 .manyptr_const_u8_sentinel_0,
305 => self.cast(Payload.ElemType),
306
307 .inferred_alloc_const => unreachable,
308 .inferred_alloc_mut => unreachable,
309
310 else => null,
311 };
312 }
313
314266 /// If it is a function pointer, returns the function type. Otherwise returns null.
315267 pub fn castPtrToFn(ty: Type, mod: *const Module) ?Type {
316268 if (ty.zigTypeTag(mod) != .Pointer) return null;
317 const elem_ty = ty.childType();
269 const elem_ty = ty.childType(mod);
318270 if (elem_ty.zigTypeTag(mod) != .Fn) return null;
319271 return elem_ty;
320272 }
321273
322 pub fn ptrIsMutable(ty: Type) bool {
323 return switch (ty.tag()) {
324 .single_const_pointer_to_comptime_int,
325 .const_slice_u8,
326 .const_slice_u8_sentinel_0,
327 .single_const_pointer,
328 .many_const_pointer,
329 .manyptr_const_u8,
330 .manyptr_const_u8_sentinel_0,
331 .c_const_pointer,
332 .const_slice,
333 => false,
334
335 .single_mut_pointer,
336 .many_mut_pointer,
337 .manyptr_u8,
338 .c_mut_pointer,
339 .mut_slice,
340 => true,
341
342 .pointer => ty.castTag(.pointer).?.data.mutable,
343
344 else => unreachable,
274 pub fn ptrIsMutable(ty: Type, mod: *const Module) bool {
275 return switch (ty.ip_index) {
276 .none => switch (ty.tag()) {
277 .pointer => ty.castTag(.pointer).?.data.mutable,
278 else => unreachable,
279 },
280 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
281 .ptr_type => |ptr_type| !ptr_type.is_const,
282 else => unreachable,
283 },
345284 };
346285 }
347286
348 pub const ArrayInfo = struct { elem_type: Type, sentinel: ?Value = null, len: u64 };
349 pub fn arrayInfo(self: Type) ArrayInfo {
287 pub const ArrayInfo = struct {
288 elem_type: Type,
289 sentinel: ?Value = null,
290 len: u64,
291 };
292
293 pub fn arrayInfo(self: Type, mod: *const Module) ArrayInfo {
350294 return .{
351 .len = self.arrayLen(),
352 .sentinel = self.sentinel(),
353 .elem_type = self.elemType(),
295 .len = self.arrayLen(mod),
296 .sentinel = self.sentinel(mod),
297 .elem_type = self.childType(mod),
354298 };
355299 }
356300
357 pub fn ptrInfo(self: Type) Payload.Pointer {
358 switch (self.ip_index) {
359 .none => switch (self.tag()) {
360 .single_const_pointer_to_comptime_int => return .{ .data = .{
361 .pointee_type = Type.comptime_int,
362 .sentinel = null,
363 .@"align" = 0,
364 .@"addrspace" = .generic,
365 .bit_offset = 0,
366 .host_size = 0,
367 .@"allowzero" = false,
368 .mutable = false,
369 .@"volatile" = false,
370 .size = .One,
371 } },
372 .const_slice_u8 => return .{ .data = .{
373 .pointee_type = Type.u8,
374 .sentinel = null,
375 .@"align" = 0,
376 .@"addrspace" = .generic,
377 .bit_offset = 0,
378 .host_size = 0,
379 .@"allowzero" = false,
380 .mutable = false,
381 .@"volatile" = false,
382 .size = .Slice,
383 } },
384 .const_slice_u8_sentinel_0 => return .{ .data = .{
385 .pointee_type = Type.u8,
386 .sentinel = Value.zero,
387 .@"align" = 0,
388 .@"addrspace" = .generic,
389 .bit_offset = 0,
390 .host_size = 0,
391 .@"allowzero" = false,
392 .mutable = false,
393 .@"volatile" = false,
394 .size = .Slice,
395 } },
396 .single_const_pointer => return .{ .data = .{
397 .pointee_type = self.castPointer().?.data,
398 .sentinel = null,
399 .@"align" = 0,
400 .@"addrspace" = .generic,
401 .bit_offset = 0,
402 .host_size = 0,
403 .@"allowzero" = false,
404 .mutable = false,
405 .@"volatile" = false,
406 .size = .One,
407 } },
408 .single_mut_pointer => return .{ .data = .{
409 .pointee_type = self.castPointer().?.data,
410 .sentinel = null,
411 .@"align" = 0,
412 .@"addrspace" = .generic,
413 .bit_offset = 0,
414 .host_size = 0,
415 .@"allowzero" = false,
416 .mutable = true,
417 .@"volatile" = false,
418 .size = .One,
419 } },
420 .many_const_pointer => return .{ .data = .{
421 .pointee_type = self.castPointer().?.data,
422 .sentinel = null,
423 .@"align" = 0,
424 .@"addrspace" = .generic,
425 .bit_offset = 0,
426 .host_size = 0,
427 .@"allowzero" = false,
428 .mutable = false,
429 .@"volatile" = false,
430 .size = .Many,
431 } },
432 .manyptr_const_u8 => return .{ .data = .{
433 .pointee_type = Type.u8,
434 .sentinel = null,
435 .@"align" = 0,
436 .@"addrspace" = .generic,
437 .bit_offset = 0,
438 .host_size = 0,
439 .@"allowzero" = false,
440 .mutable = false,
441 .@"volatile" = false,
442 .size = .Many,
443 } },
444 .manyptr_const_u8_sentinel_0 => return .{ .data = .{
445 .pointee_type = Type.u8,
446 .sentinel = Value.zero,
447 .@"align" = 0,
448 .@"addrspace" = .generic,
449 .bit_offset = 0,
450 .host_size = 0,
451 .@"allowzero" = false,
452 .mutable = false,
453 .@"volatile" = false,
454 .size = .Many,
455 } },
456 .many_mut_pointer => return .{ .data = .{
457 .pointee_type = self.castPointer().?.data,
458 .sentinel = null,
459 .@"align" = 0,
460 .@"addrspace" = .generic,
461 .bit_offset = 0,
462 .host_size = 0,
463 .@"allowzero" = false,
464 .mutable = true,
465 .@"volatile" = false,
466 .size = .Many,
467 } },
468 .manyptr_u8 => return .{ .data = .{
469 .pointee_type = Type.u8,
470 .sentinel = null,
471 .@"align" = 0,
472 .@"addrspace" = .generic,
473 .bit_offset = 0,
474 .host_size = 0,
475 .@"allowzero" = false,
476 .mutable = true,
477 .@"volatile" = false,
478 .size = .Many,
479 } },
480 .c_const_pointer => return .{ .data = .{
481 .pointee_type = self.castPointer().?.data,
482 .sentinel = null,
483 .@"align" = 0,
484 .@"addrspace" = .generic,
485 .bit_offset = 0,
486 .host_size = 0,
487 .@"allowzero" = true,
488 .mutable = false,
489 .@"volatile" = false,
490 .size = .C,
491 } },
492 .c_mut_pointer => return .{ .data = .{
493 .pointee_type = self.castPointer().?.data,
494 .sentinel = null,
495 .@"align" = 0,
496 .@"addrspace" = .generic,
497 .bit_offset = 0,
498 .host_size = 0,
499 .@"allowzero" = true,
500 .mutable = true,
501 .@"volatile" = false,
502 .size = .C,
503 } },
504 .const_slice => return .{ .data = .{
505 .pointee_type = self.castPointer().?.data,
506 .sentinel = null,
507 .@"align" = 0,
508 .@"addrspace" = .generic,
509 .bit_offset = 0,
510 .host_size = 0,
511 .@"allowzero" = false,
512 .mutable = false,
513 .@"volatile" = false,
514 .size = .Slice,
515 } },
516 .mut_slice => return .{ .data = .{
517 .pointee_type = self.castPointer().?.data,
518 .sentinel = null,
519 .@"align" = 0,
520 .@"addrspace" = .generic,
521 .bit_offset = 0,
522 .host_size = 0,
523 .@"allowzero" = false,
524 .mutable = true,
525 .@"volatile" = false,
526 .size = .Slice,
527 } },
528
529 .pointer => return self.castTag(.pointer).?.*,
530
531 .optional_single_mut_pointer => return .{ .data = .{
532 .pointee_type = self.castPointer().?.data,
533 .sentinel = null,
534 .@"align" = 0,
535 .@"addrspace" = .generic,
536 .bit_offset = 0,
537 .host_size = 0,
538 .@"allowzero" = false,
539 .mutable = true,
540 .@"volatile" = false,
541 .size = .One,
542 } },
543 .optional_single_const_pointer => return .{ .data = .{
544 .pointee_type = self.castPointer().?.data,
545 .sentinel = null,
546 .@"align" = 0,
547 .@"addrspace" = .generic,
548 .bit_offset = 0,
549 .host_size = 0,
550 .@"allowzero" = false,
551 .mutable = false,
552 .@"volatile" = false,
553 .size = .One,
554 } },
555 .optional => {
556 var buf: Payload.ElemType = undefined;
557 const child_type = self.optionalChild(&buf);
558 return child_type.ptrInfo();
301 pub fn ptrInfo(ty: Type, mod: *const Module) Payload.Pointer.Data {
302 return switch (ty.ip_index) {
303 .none => switch (ty.tag()) {
304 .pointer => ty.castTag(.pointer).?.data,
305 .optional => b: {
306 const child_type = ty.optionalChild(mod);
307 break :b child_type.ptrInfo(mod);
559308 },
560309
561310 else => unreachable,
562311 },
563 else => @panic("TODO"),
564 }
312 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
313 .ptr_type => |p| Payload.Pointer.Data.fromKey(p),
314 .opt_type => |child| switch (mod.intern_pool.indexToKey(child)) {
315 .ptr_type => |p| Payload.Pointer.Data.fromKey(p),
316 else => unreachable,
317 },
318 else => unreachable,
319 },
320 };
565321 }
566322
567323 pub fn eql(a: Type, b: Type, mod: *Module) bool {
......@@ -658,20 +414,17 @@ pub const Type = struct {
658414 },
659415
660416 .array,
661 .array_u8_sentinel_0,
662 .array_u8,
663417 .array_sentinel,
664 .vector,
665418 => {
666419 if (a.zigTypeTag(mod) != b.zigTypeTag(mod)) return false;
667420
668 if (a.arrayLen() != b.arrayLen())
421 if (a.arrayLen(mod) != b.arrayLen(mod))
669422 return false;
670 const elem_ty = a.elemType();
671 if (!elem_ty.eql(b.elemType(), mod))
423 const elem_ty = a.childType(mod);
424 if (!elem_ty.eql(b.childType(mod), mod))
672425 return false;
673 const sentinel_a = a.sentinel();
674 const sentinel_b = b.sentinel();
426 const sentinel_a = a.sentinel(mod);
427 const sentinel_b = b.sentinel(mod);
675428 if (sentinel_a) |sa| {
676429 if (sentinel_b) |sb| {
677430 return sa.eql(sb, elem_ty, mod);
......@@ -683,28 +436,14 @@ pub const Type = struct {
683436 }
684437 },
685438
686 .single_const_pointer_to_comptime_int,
687 .const_slice_u8,
688 .const_slice_u8_sentinel_0,
689 .single_const_pointer,
690 .single_mut_pointer,
691 .many_const_pointer,
692 .many_mut_pointer,
693 .c_const_pointer,
694 .c_mut_pointer,
695 .const_slice,
696 .mut_slice,
697439 .pointer,
698440 .inferred_alloc_const,
699441 .inferred_alloc_mut,
700 .manyptr_u8,
701 .manyptr_const_u8,
702 .manyptr_const_u8_sentinel_0,
703442 => {
704443 if (b.zigTypeTag(mod) != .Pointer) return false;
705444
706 const info_a = a.ptrInfo().data;
707 const info_b = b.ptrInfo().data;
445 const info_a = a.ptrInfo(mod);
446 const info_b = b.ptrInfo(mod);
708447 if (!info_a.pointee_type.eql(info_b.pointee_type, mod))
709448 return false;
710449 if (info_a.@"align" != info_b.@"align")
......@@ -743,18 +482,13 @@ pub const Type = struct {
743482 return true;
744483 },
745484
746 .optional,
747 .optional_single_const_pointer,
748 .optional_single_mut_pointer,
749 => {
485 .optional => {
750486 if (b.zigTypeTag(mod) != .Optional) return false;
751487
752 var buf_a: Payload.ElemType = undefined;
753 var buf_b: Payload.ElemType = undefined;
754 return a.optionalChild(&buf_a).eql(b.optionalChild(&buf_b), mod);
488 return a.optionalChild(mod).eql(b.optionalChild(mod), mod);
755489 },
756490
757 .anyerror_void_error_union, .error_union => {
491 .error_union => {
758492 if (b.zigTypeTag(mod) != .ErrorUnion) return false;
759493
760494 const a_set = a.errorUnionSet();
......@@ -947,47 +681,23 @@ pub const Type = struct {
947681 },
948682
949683 .array,
950 .array_u8_sentinel_0,
951 .array_u8,
952684 .array_sentinel,
953685 => {
954686 std.hash.autoHash(hasher, std.builtin.TypeId.Array);
955687
956 const elem_ty = ty.elemType();
957 std.hash.autoHash(hasher, ty.arrayLen());
688 const elem_ty = ty.childType(mod);
689 std.hash.autoHash(hasher, ty.arrayLen(mod));
958690 hashWithHasher(elem_ty, hasher, mod);
959 hashSentinel(ty.sentinel(), elem_ty, hasher, mod);
691 hashSentinel(ty.sentinel(mod), elem_ty, hasher, mod);
960692 },
961693
962 .vector => {
963 std.hash.autoHash(hasher, std.builtin.TypeId.Vector);
964
965 const elem_ty = ty.elemType();
966 std.hash.autoHash(hasher, ty.vectorLen());
967 hashWithHasher(elem_ty, hasher, mod);
968 },
969
970 .single_const_pointer_to_comptime_int,
971 .const_slice_u8,
972 .const_slice_u8_sentinel_0,
973 .single_const_pointer,
974 .single_mut_pointer,
975 .many_const_pointer,
976 .many_mut_pointer,
977 .c_const_pointer,
978 .c_mut_pointer,
979 .const_slice,
980 .mut_slice,
981694 .pointer,
982695 .inferred_alloc_const,
983696 .inferred_alloc_mut,
984 .manyptr_u8,
985 .manyptr_const_u8,
986 .manyptr_const_u8_sentinel_0,
987697 => {
988698 std.hash.autoHash(hasher, std.builtin.TypeId.Pointer);
989699
990 const info = ty.ptrInfo().data;
700 const info = ty.ptrInfo(mod);
991701 hashWithHasher(info.pointee_type, hasher, mod);
992702 hashSentinel(info.sentinel, info.pointee_type, hasher, mod);
993703 std.hash.autoHash(hasher, info.@"align");
......@@ -1001,17 +711,13 @@ pub const Type = struct {
1001711 std.hash.autoHash(hasher, info.size);
1002712 },
1003713
1004 .optional,
1005 .optional_single_const_pointer,
1006 .optional_single_mut_pointer,
1007 => {
714 .optional => {
1008715 std.hash.autoHash(hasher, std.builtin.TypeId.Optional);
1009716
1010 var buf: Payload.ElemType = undefined;
1011 hashWithHasher(ty.optionalChild(&buf), hasher, mod);
717 hashWithHasher(ty.optionalChild(mod), hasher, mod);
1012718 },
1013719
1014 .anyerror_void_error_union, .error_union => {
720 .error_union => {
1015721 std.hash.autoHash(hasher, std.builtin.TypeId.ErrorUnion);
1016722
1017723 const set_ty = ty.errorUnionSet();
......@@ -1023,7 +729,7 @@ pub const Type = struct {
1023729
1024730 .anyframe_T => {
1025731 std.hash.autoHash(hasher, std.builtin.TypeId.AnyFrame);
1026 hashWithHasher(ty.childType(), hasher, mod);
732 hashWithHasher(ty.childType(mod), hasher, mod);
1027733 },
1028734
1029735 .empty_struct => {
......@@ -1129,33 +835,12 @@ pub const Type = struct {
1129835 .legacy = .{ .tag_if_small_enough = self.legacy.tag_if_small_enough },
1130836 };
1131837 } else switch (self.legacy.ptr_otherwise.tag) {
1132 .single_const_pointer_to_comptime_int,
1133 .const_slice_u8,
1134 .const_slice_u8_sentinel_0,
1135 .anyerror_void_error_union,
1136838 .inferred_alloc_const,
1137839 .inferred_alloc_mut,
1138840 .empty_struct_literal,
1139 .manyptr_u8,
1140 .manyptr_const_u8,
1141 .manyptr_const_u8_sentinel_0,
1142841 => unreachable,
1143842
1144 .array_u8,
1145 .array_u8_sentinel_0,
1146 => return self.copyPayloadShallow(allocator, Payload.Len),
1147
1148 .single_const_pointer,
1149 .single_mut_pointer,
1150 .many_const_pointer,
1151 .many_mut_pointer,
1152 .c_const_pointer,
1153 .c_mut_pointer,
1154 .const_slice,
1155 .mut_slice,
1156843 .optional,
1157 .optional_single_mut_pointer,
1158 .optional_single_const_pointer,
1159844 .anyframe_T,
1160845 => {
1161846 const payload = self.cast(Payload.ElemType).?;
......@@ -1170,13 +855,6 @@ pub const Type = struct {
1170855 };
1171856 },
1172857
1173 .vector => {
1174 const payload = self.castTag(.vector).?.data;
1175 return Tag.vector.create(allocator, .{
1176 .len = payload.len,
1177 .elem_type = try payload.elem_type.copy(allocator),
1178 });
1179 },
1180858 .array => {
1181859 const payload = self.castTag(.array).?.data;
1182860 return Tag.array.create(allocator, .{
......@@ -1408,13 +1086,6 @@ pub const Type = struct {
14081086 });
14091087 },
14101088
1411 .anyerror_void_error_union => return writer.writeAll("anyerror!void"),
1412 .const_slice_u8 => return writer.writeAll("[]const u8"),
1413 .const_slice_u8_sentinel_0 => return writer.writeAll("[:0]const u8"),
1414 .single_const_pointer_to_comptime_int => return writer.writeAll("*const comptime_int"),
1415 .manyptr_u8 => return writer.writeAll("[*]u8"),
1416 .manyptr_const_u8 => return writer.writeAll("[*]const u8"),
1417 .manyptr_const_u8_sentinel_0 => return writer.writeAll("[*:0]const u8"),
14181089 .function => {
14191090 const payload = ty.castTag(.function).?.data;
14201091 try writer.writeAll("fn(");
......@@ -1447,20 +1118,6 @@ pub const Type = struct {
14471118 ty = return_type;
14481119 continue;
14491120 },
1450 .array_u8 => {
1451 const len = ty.castTag(.array_u8).?.data;
1452 return writer.print("[{d}]u8", .{len});
1453 },
1454 .array_u8_sentinel_0 => {
1455 const len = ty.castTag(.array_u8_sentinel_0).?.data;
1456 return writer.print("[{d}:0]u8", .{len});
1457 },
1458 .vector => {
1459 const payload = ty.castTag(.vector).?.data;
1460 try writer.print("@Vector({d}, ", .{payload.len});
1461 try payload.elem_type.dump("", .{}, writer);
1462 return writer.writeAll(")");
1463 },
14641121 .array => {
14651122 const payload = ty.castTag(.array).?.data;
14661123 try writer.print("[{d}]", .{payload.len});
......@@ -1512,72 +1169,12 @@ pub const Type = struct {
15121169 try writer.writeAll("}");
15131170 return;
15141171 },
1515 .single_const_pointer => {
1516 const pointee_type = ty.castTag(.single_const_pointer).?.data;
1517 try writer.writeAll("*const ");
1518 ty = pointee_type;
1519 continue;
1520 },
1521 .single_mut_pointer => {
1522 const pointee_type = ty.castTag(.single_mut_pointer).?.data;
1523 try writer.writeAll("*");
1524 ty = pointee_type;
1525 continue;
1526 },
1527 .many_const_pointer => {
1528 const pointee_type = ty.castTag(.many_const_pointer).?.data;
1529 try writer.writeAll("[*]const ");
1530 ty = pointee_type;
1531 continue;
1532 },
1533 .many_mut_pointer => {
1534 const pointee_type = ty.castTag(.many_mut_pointer).?.data;
1535 try writer.writeAll("[*]");
1536 ty = pointee_type;
1537 continue;
1538 },
1539 .c_const_pointer => {
1540 const pointee_type = ty.castTag(.c_const_pointer).?.data;
1541 try writer.writeAll("[*c]const ");
1542 ty = pointee_type;
1543 continue;
1544 },
1545 .c_mut_pointer => {
1546 const pointee_type = ty.castTag(.c_mut_pointer).?.data;
1547 try writer.writeAll("[*c]");
1548 ty = pointee_type;
1549 continue;
1550 },
1551 .const_slice => {
1552 const pointee_type = ty.castTag(.const_slice).?.data;
1553 try writer.writeAll("[]const ");
1554 ty = pointee_type;
1555 continue;
1556 },
1557 .mut_slice => {
1558 const pointee_type = ty.castTag(.mut_slice).?.data;
1559 try writer.writeAll("[]");
1560 ty = pointee_type;
1561 continue;
1562 },
15631172 .optional => {
15641173 const child_type = ty.castTag(.optional).?.data;
15651174 try writer.writeByte('?');
15661175 ty = child_type;
15671176 continue;
15681177 },
1569 .optional_single_const_pointer => {
1570 const pointee_type = ty.castTag(.optional_single_const_pointer).?.data;
1571 try writer.writeAll("?*const ");
1572 ty = pointee_type;
1573 continue;
1574 },
1575 .optional_single_mut_pointer => {
1576 const pointee_type = ty.castTag(.optional_single_mut_pointer).?.data;
1577 try writer.writeAll("?*");
1578 ty = pointee_type;
1579 continue;
1580 },
15811178
15821179 .pointer => {
15831180 const payload = ty.castTag(.pointer).?.data;
......@@ -1680,7 +1277,7 @@ pub const Type = struct {
16801277 .ptr_type => @panic("TODO"),
16811278 .array_type => @panic("TODO"),
16821279 .vector_type => @panic("TODO"),
1683 .optional_type => @panic("TODO"),
1280 .opt_type => @panic("TODO"),
16841281 .error_union_type => @panic("TODO"),
16851282 .simple_type => |s| return writer.writeAll(@tagName(s)),
16861283 .struct_type => @panic("TODO"),
......@@ -1733,14 +1330,6 @@ pub const Type = struct {
17331330 try decl.renderFullyQualifiedName(mod, writer);
17341331 },
17351332
1736 .anyerror_void_error_union => try writer.writeAll("anyerror!void"),
1737 .const_slice_u8 => try writer.writeAll("[]const u8"),
1738 .const_slice_u8_sentinel_0 => try writer.writeAll("[:0]const u8"),
1739 .single_const_pointer_to_comptime_int => try writer.writeAll("*const comptime_int"),
1740 .manyptr_u8 => try writer.writeAll("[*]u8"),
1741 .manyptr_const_u8 => try writer.writeAll("[*]const u8"),
1742 .manyptr_const_u8_sentinel_0 => try writer.writeAll("[*:0]const u8"),
1743
17441333 .error_set_inferred => {
17451334 const func = ty.castTag(.error_set_inferred).?.data.func;
17461335
......@@ -1799,20 +1388,6 @@ pub const Type = struct {
17991388 try print(error_union.payload, writer, mod);
18001389 },
18011390
1802 .array_u8 => {
1803 const len = ty.castTag(.array_u8).?.data;
1804 try writer.print("[{d}]u8", .{len});
1805 },
1806 .array_u8_sentinel_0 => {
1807 const len = ty.castTag(.array_u8_sentinel_0).?.data;
1808 try writer.print("[{d}:0]u8", .{len});
1809 },
1810 .vector => {
1811 const payload = ty.castTag(.vector).?.data;
1812 try writer.print("@Vector({d}, ", .{payload.len});
1813 try print(payload.elem_type, writer, mod);
1814 try writer.writeAll(")");
1815 },
18161391 .array => {
18171392 const payload = ty.castTag(.array).?.data;
18181393 try writer.print("[{d}]", .{payload.len});
......@@ -1865,17 +1440,8 @@ pub const Type = struct {
18651440 try writer.writeAll("}");
18661441 },
18671442
1868 .pointer,
1869 .single_const_pointer,
1870 .single_mut_pointer,
1871 .many_const_pointer,
1872 .many_mut_pointer,
1873 .c_const_pointer,
1874 .c_mut_pointer,
1875 .const_slice,
1876 .mut_slice,
1877 => {
1878 const info = ty.ptrInfo().data;
1443 .pointer => {
1444 const info = ty.ptrInfo(mod);
18791445
18801446 if (info.sentinel) |s| switch (info.size) {
18811447 .One, .C => unreachable,
......@@ -1920,16 +1486,6 @@ pub const Type = struct {
19201486 try writer.writeByte('?');
19211487 try print(child_type, writer, mod);
19221488 },
1923 .optional_single_mut_pointer => {
1924 const pointee_type = ty.castTag(.optional_single_mut_pointer).?.data;
1925 try writer.writeAll("?*");
1926 try print(pointee_type, writer, mod);
1927 },
1928 .optional_single_const_pointer => {
1929 const pointee_type = ty.castTag(.optional_single_const_pointer).?.data;
1930 try writer.writeAll("?*const ");
1931 try print(pointee_type, writer, mod);
1932 },
19331489 .anyframe_T => {
19341490 const return_type = ty.castTag(.anyframe_T).?.data;
19351491 try writer.print("anyframe->", .{});
......@@ -1963,12 +1519,6 @@ pub const Type = struct {
19631519 pub fn toValue(self: Type, allocator: Allocator) Allocator.Error!Value {
19641520 if (self.ip_index != .none) return self.ip_index.toValue();
19651521 switch (self.tag()) {
1966 .single_const_pointer_to_comptime_int => return Value{ .ip_index = .single_const_pointer_to_comptime_int_type, .legacy = undefined },
1967 .const_slice_u8 => return Value{ .ip_index = .const_slice_u8_type, .legacy = undefined },
1968 .const_slice_u8_sentinel_0 => return Value{ .ip_index = .const_slice_u8_sentinel_0_type, .legacy = undefined },
1969 .manyptr_u8 => return Value{ .ip_index = .manyptr_u8_type, .legacy = undefined },
1970 .manyptr_const_u8 => return Value{ .ip_index = .manyptr_const_u8_type, .legacy = undefined },
1971 .manyptr_const_u8_sentinel_0 => return Value{ .ip_index = .manyptr_const_u8_sentinel_0_type, .legacy = undefined },
19721522 .inferred_alloc_const => unreachable,
19731523 .inferred_alloc_mut => unreachable,
19741524 else => return Value.Tag.ty.create(allocator, self),
......@@ -1996,10 +1546,41 @@ pub const Type = struct {
19961546 ) RuntimeBitsError!bool {
19971547 if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {
19981548 .int_type => |int_type| return int_type.bits != 0,
1999 .ptr_type => @panic("TODO"),
2000 .array_type => @panic("TODO"),
2001 .vector_type => @panic("TODO"),
2002 .optional_type => @panic("TODO"),
1549 .ptr_type => |ptr_type| {
1550 // Pointers to zero-bit types still have a runtime address; however, pointers
1551 // to comptime-only types do not, with the exception of function pointers.
1552 if (ignore_comptime_only) return true;
1553 const child_ty = ptr_type.elem_type.toType();
1554 if (child_ty.zigTypeTag(mod) == .Fn) return !child_ty.fnInfo().is_generic;
1555 if (strat == .sema) return !(try strat.sema.typeRequiresComptime(ty));
1556 return !comptimeOnly(ty, mod);
1557 },
1558 .array_type => |array_type| {
1559 if (array_type.sentinel != .none) {
1560 return array_type.child.toType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
1561 } else {
1562 return array_type.len > 0 and
1563 try array_type.child.toType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
1564 }
1565 },
1566 .vector_type => |vector_type| {
1567 return vector_type.len > 0 and
1568 try vector_type.child.toType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat);
1569 },
1570 .opt_type => |child| {
1571 const child_ty = child.toType();
1572 if (child_ty.isNoReturn()) {
1573 // Then the optional is comptime-known to be null.
1574 return false;
1575 }
1576 if (ignore_comptime_only) {
1577 return true;
1578 } else if (strat == .sema) {
1579 return !(try strat.sema.typeRequiresComptime(child_ty));
1580 } else {
1581 return !comptimeOnly(child_ty, mod);
1582 }
1583 },
20031584 .error_union_type => @panic("TODO"),
20041585 .simple_type => |t| return switch (t) {
20051586 .f16,
......@@ -2058,14 +1639,7 @@ pub const Type = struct {
20581639 .enum_tag => unreachable, // it's a value, not a type
20591640 };
20601641 switch (ty.tag()) {
2061 .const_slice_u8,
2062 .const_slice_u8_sentinel_0,
2063 .array_u8_sentinel_0,
2064 .anyerror_void_error_union,
20651642 .error_set_inferred,
2066 .manyptr_u8,
2067 .manyptr_const_u8,
2068 .manyptr_const_u8_sentinel_0,
20691643
20701644 .@"opaque",
20711645 .error_set_single,
......@@ -2077,22 +1651,12 @@ pub const Type = struct {
20771651 // Pointers to zero-bit types still have a runtime address; however, pointers
20781652 // to comptime-only types do not, with the exception of function pointers.
20791653 .anyframe_T,
2080 .optional_single_mut_pointer,
2081 .optional_single_const_pointer,
2082 .single_const_pointer,
2083 .single_mut_pointer,
2084 .many_const_pointer,
2085 .many_mut_pointer,
2086 .c_const_pointer,
2087 .c_mut_pointer,
2088 .const_slice,
2089 .mut_slice,
20901654 .pointer,
20911655 => {
20921656 if (ignore_comptime_only) {
20931657 return true;
2094 } else if (ty.childType().zigTypeTag(mod) == .Fn) {
2095 return !ty.childType().fnInfo().is_generic;
1658 } else if (ty.childType(mod).zigTypeTag(mod) == .Fn) {
1659 return !ty.childType(mod).fnInfo().is_generic;
20961660 } else if (strat == .sema) {
20971661 return !(try strat.sema.typeRequiresComptime(ty));
20981662 } else {
......@@ -2101,7 +1665,6 @@ pub const Type = struct {
21011665 },
21021666
21031667 // These are false because they are comptime-only types.
2104 .single_const_pointer_to_comptime_int,
21051668 .empty_struct,
21061669 .empty_struct_literal,
21071670 // These are function *bodies*, not pointers.
......@@ -2111,8 +1674,7 @@ pub const Type = struct {
21111674 => return false,
21121675
21131676 .optional => {
2114 var buf: Payload.ElemType = undefined;
2115 const child_ty = ty.optionalChild(&buf);
1677 const child_ty = ty.optionalChild(mod);
21161678 if (child_ty.isNoReturn()) {
21171679 // Then the optional is comptime-known to be null.
21181680 return false;
......@@ -2200,10 +1762,9 @@ pub const Type = struct {
22001762 }
22011763 },
22021764
2203 .array, .vector => return ty.arrayLen() != 0 and
2204 try ty.elemType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat),
2205 .array_u8 => return ty.arrayLen() != 0,
2206 .array_sentinel => return ty.childType().hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat),
1765 .array => return ty.arrayLen(mod) != 0 and
1766 try ty.childType(mod).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat),
1767 .array_sentinel => return ty.childType(mod).hasRuntimeBitsAdvanced(mod, ignore_comptime_only, strat),
22071768
22081769 .tuple, .anon_struct => {
22091770 const tuple = ty.tupleFields();
......@@ -2224,14 +1785,14 @@ pub const Type = struct {
22241785 /// readFrom/writeToMemory are supported only for types with a well-
22251786 /// defined memory layout
22261787 pub fn hasWellDefinedLayout(ty: Type, mod: *const Module) bool {
2227 if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {
2228 .int_type => return true,
2229 .ptr_type => @panic("TODO"),
2230 .array_type => @panic("TODO"),
2231 .vector_type => @panic("TODO"),
2232 .optional_type => @panic("TODO"),
2233 .error_union_type => @panic("TODO"),
2234 .simple_type => |t| return switch (t) {
1788 if (ty.ip_index != .none) return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
1789 .int_type => true,
1790 .ptr_type => true,
1791 .array_type => |array_type| array_type.child.toType().hasWellDefinedLayout(mod),
1792 .vector_type => true,
1793 .opt_type => |child| child.toType().isPtrLikeOptional(mod),
1794 .error_union_type => false,
1795 .simple_type => |t| switch (t) {
22351796 .f16,
22361797 .f32,
22371798 .f64,
......@@ -2287,23 +1848,8 @@ pub const Type = struct {
22871848 .enum_tag => unreachable, // it's a value, not a type
22881849 };
22891850 return switch (ty.tag()) {
2290 .manyptr_u8,
2291 .manyptr_const_u8,
2292 .manyptr_const_u8_sentinel_0,
2293 .array_u8,
2294 .array_u8_sentinel_0,
22951851 .pointer,
2296 .single_const_pointer,
2297 .single_mut_pointer,
2298 .many_const_pointer,
2299 .many_mut_pointer,
2300 .c_const_pointer,
2301 .c_mut_pointer,
2302 .single_const_pointer_to_comptime_int,
23031852 .enum_numbered,
2304 .vector,
2305 .optional_single_mut_pointer,
2306 .optional_single_const_pointer,
23071853 => true,
23081854
23091855 .error_set,
......@@ -2313,13 +1859,8 @@ pub const Type = struct {
23131859 .@"opaque",
23141860 // These are function bodies, not function pointers.
23151861 .function,
2316 .const_slice_u8,
2317 .const_slice_u8_sentinel_0,
2318 .const_slice,
2319 .mut_slice,
23201862 .enum_simple,
23211863 .error_union,
2322 .anyerror_void_error_union,
23231864 .anyframe_T,
23241865 .tuple,
23251866 .anon_struct,
......@@ -2336,7 +1877,7 @@ pub const Type = struct {
23361877
23371878 .array,
23381879 .array_sentinel,
2339 => ty.childType().hasWellDefinedLayout(mod),
1880 => ty.childType(mod).hasWellDefinedLayout(mod),
23401881
23411882 .optional => ty.isPtrLikeOptional(mod),
23421883 .@"struct" => ty.castTag(.@"struct").?.data.layout != .Auto,
......@@ -2417,76 +1958,36 @@ pub const Type = struct {
24171958 }
24181959
24191960 pub fn ptrAlignmentAdvanced(ty: Type, mod: *const Module, opt_sema: ?*Sema) !u32 {
2420 switch (ty.tag()) {
2421 .single_const_pointer,
2422 .single_mut_pointer,
2423 .many_const_pointer,
2424 .many_mut_pointer,
2425 .c_const_pointer,
2426 .c_mut_pointer,
2427 .const_slice,
2428 .mut_slice,
2429 .optional_single_const_pointer,
2430 .optional_single_mut_pointer,
2431 => {
2432 const child_type = ty.cast(Payload.ElemType).?.data;
2433 if (opt_sema) |sema| {
2434 const res = try child_type.abiAlignmentAdvanced(mod, .{ .sema = sema });
2435 return res.scalar;
2436 }
2437 return (child_type.abiAlignmentAdvanced(mod, .eager) catch unreachable).scalar;
2438 },
2439
2440 .manyptr_u8,
2441 .manyptr_const_u8,
2442 .manyptr_const_u8_sentinel_0,
2443 .const_slice_u8,
2444 .const_slice_u8_sentinel_0,
2445 => return 1,
1961 switch (ty.ip_index) {
1962 .none => switch (ty.tag()) {
1963 .pointer => {
1964 const ptr_info = ty.castTag(.pointer).?.data;
1965 if (ptr_info.@"align" != 0) {
1966 return ptr_info.@"align";
1967 } else if (opt_sema) |sema| {
1968 const res = try ptr_info.pointee_type.abiAlignmentAdvanced(mod, .{ .sema = sema });
1969 return res.scalar;
1970 } else {
1971 return (ptr_info.pointee_type.abiAlignmentAdvanced(mod, .eager) catch unreachable).scalar;
1972 }
1973 },
1974 .optional => return ty.castTag(.optional).?.data.ptrAlignmentAdvanced(mod, opt_sema),
24461975
2447 .pointer => {
2448 const ptr_info = ty.castTag(.pointer).?.data;
2449 if (ptr_info.@"align" != 0) {
2450 return ptr_info.@"align";
2451 } else if (opt_sema) |sema| {
2452 const res = try ptr_info.pointee_type.abiAlignmentAdvanced(mod, .{ .sema = sema });
2453 return res.scalar;
2454 } else {
2455 return (ptr_info.pointee_type.abiAlignmentAdvanced(mod, .eager) catch unreachable).scalar;
2456 }
1976 else => unreachable,
1977 },
1978 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
1979 else => @panic("TODO"),
24571980 },
2458 .optional => return ty.castTag(.optional).?.data.ptrAlignmentAdvanced(mod, opt_sema),
2459
2460 else => unreachable,
24611981 }
24621982 }
24631983
2464 pub fn ptrAddressSpace(self: Type) std.builtin.AddressSpace {
1984 pub fn ptrAddressSpace(self: Type, mod: *const Module) std.builtin.AddressSpace {
24651985 return switch (self.tag()) {
2466 .single_const_pointer_to_comptime_int,
2467 .const_slice_u8,
2468 .const_slice_u8_sentinel_0,
2469 .single_const_pointer,
2470 .single_mut_pointer,
2471 .many_const_pointer,
2472 .many_mut_pointer,
2473 .c_const_pointer,
2474 .c_mut_pointer,
2475 .const_slice,
2476 .mut_slice,
2477 .inferred_alloc_const,
2478 .inferred_alloc_mut,
2479 .manyptr_u8,
2480 .manyptr_const_u8,
2481 .manyptr_const_u8_sentinel_0,
2482 => .generic,
2483
24841986 .pointer => self.castTag(.pointer).?.data.@"addrspace",
24851987
24861988 .optional => {
2487 var buf: Payload.ElemType = undefined;
2488 const child_type = self.optionalChild(&buf);
2489 return child_type.ptrAddressSpace();
1989 const child_type = self.optionalChild(mod);
1990 return child_type.ptrAddressSpace(mod);
24901991 },
24911992
24921993 else => unreachable,
......@@ -2530,15 +2031,31 @@ pub const Type = struct {
25302031 ) Module.CompileError!AbiAlignmentAdvanced {
25312032 const target = mod.getTarget();
25322033
2034 const opt_sema = switch (strat) {
2035 .sema => |sema| sema,
2036 else => null,
2037 };
2038
25332039 if (ty.ip_index != .none) switch (mod.intern_pool.indexToKey(ty.ip_index)) {
25342040 .int_type => |int_type| {
25352041 if (int_type.bits == 0) return AbiAlignmentAdvanced{ .scalar = 0 };
25362042 return AbiAlignmentAdvanced{ .scalar = intAbiAlignment(int_type.bits, target) };
25372043 },
2538 .ptr_type => @panic("TODO"),
2539 .array_type => @panic("TODO"),
2540 .vector_type => @panic("TODO"),
2541 .optional_type => @panic("TODO"),
2044 .ptr_type => {
2045 return AbiAlignmentAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) };
2046 },
2047 .array_type => |array_type| {
2048 return array_type.child.toType().abiAlignmentAdvanced(mod, strat);
2049 },
2050 .vector_type => |vector_type| {
2051 const bits_u64 = try bitSizeAdvanced(vector_type.child.toType(), mod, opt_sema);
2052 const bits = @intCast(u32, bits_u64);
2053 const bytes = ((bits * vector_type.len) + 7) / 8;
2054 const alignment = std.math.ceilPowerOfTwoAssert(u32, bytes);
2055 return AbiAlignmentAdvanced{ .scalar = alignment };
2056 },
2057
2058 .opt_type => @panic("TODO"),
25422059 .error_union_type => @panic("TODO"),
25432060 .simple_type => |t| switch (t) {
25442061 .bool,
......@@ -2617,15 +2134,8 @@ pub const Type = struct {
26172134 .enum_tag => unreachable, // it's a value, not a type
26182135 };
26192136
2620 const opt_sema = switch (strat) {
2621 .sema => |sema| sema,
2622 else => null,
2623 };
26242137 switch (ty.tag()) {
2625 .array_u8_sentinel_0,
2626 .array_u8,
2627 .@"opaque",
2628 => return AbiAlignmentAdvanced{ .scalar = 1 },
2138 .@"opaque" => return AbiAlignmentAdvanced{ .scalar = 1 },
26292139
26302140 // represents machine code; not a pointer
26312141 .function => {
......@@ -2634,47 +2144,21 @@ pub const Type = struct {
26342144 return AbiAlignmentAdvanced{ .scalar = target_util.defaultFunctionAlignment(target) };
26352145 },
26362146
2637 .single_const_pointer_to_comptime_int,
2638 .const_slice_u8,
2639 .const_slice_u8_sentinel_0,
2640 .single_const_pointer,
2641 .single_mut_pointer,
2642 .many_const_pointer,
2643 .many_mut_pointer,
2644 .c_const_pointer,
2645 .c_mut_pointer,
2646 .const_slice,
2647 .mut_slice,
2648 .optional_single_const_pointer,
2649 .optional_single_mut_pointer,
26502147 .pointer,
2651 .manyptr_u8,
2652 .manyptr_const_u8,
2653 .manyptr_const_u8_sentinel_0,
26542148 .anyframe_T,
26552149 => return AbiAlignmentAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
26562150
26572151 // TODO revisit this when we have the concept of the error tag type
2658 .anyerror_void_error_union,
26592152 .error_set_inferred,
26602153 .error_set_single,
26612154 .error_set,
26622155 .error_set_merged,
26632156 => return AbiAlignmentAdvanced{ .scalar = 2 },
26642157
2665 .array, .array_sentinel => return ty.elemType().abiAlignmentAdvanced(mod, strat),
2666
2667 .vector => {
2668 const len = ty.arrayLen();
2669 const bits = try bitSizeAdvanced(ty.elemType(), mod, opt_sema);
2670 const bytes = ((bits * len) + 7) / 8;
2671 const alignment = std.math.ceilPowerOfTwoAssert(u64, bytes);
2672 return AbiAlignmentAdvanced{ .scalar = @intCast(u32, alignment) };
2673 },
2158 .array, .array_sentinel => return ty.childType(mod).abiAlignmentAdvanced(mod, strat),
26742159
26752160 .optional => {
2676 var buf: Payload.ElemType = undefined;
2677 const child_type = ty.optionalChild(&buf);
2161 const child_type = ty.optionalChild(mod);
26782162
26792163 switch (child_type.zigTypeTag(mod)) {
26802164 .Pointer => return AbiAlignmentAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
......@@ -2933,8 +2417,29 @@ pub const Type = struct {
29332417 },
29342418 .ptr_type => @panic("TODO"),
29352419 .array_type => @panic("TODO"),
2936 .vector_type => @panic("TODO"),
2937 .optional_type => @panic("TODO"),
2420 .vector_type => |vector_type| {
2421 const opt_sema = switch (strat) {
2422 .sema => |sema| sema,
2423 .eager => null,
2424 .lazy => |arena| return AbiSizeAdvanced{
2425 .val = try Value.Tag.lazy_size.create(arena, ty),
2426 },
2427 };
2428 const elem_bits_u64 = try vector_type.child.toType().bitSizeAdvanced(mod, opt_sema);
2429 const elem_bits = @intCast(u32, elem_bits_u64);
2430 const total_bits = elem_bits * vector_type.len;
2431 const total_bytes = (total_bits + 7) / 8;
2432 const alignment = switch (try ty.abiAlignmentAdvanced(mod, strat)) {
2433 .scalar => |x| x,
2434 .val => return AbiSizeAdvanced{
2435 .val = try Value.Tag.lazy_size.create(strat.lazy, ty),
2436 },
2437 };
2438 const result = std.mem.alignForwardGeneric(u32, total_bytes, alignment);
2439 return AbiSizeAdvanced{ .scalar = result };
2440 },
2441
2442 .opt_type => @panic("TODO"),
29382443 .error_union_type => @panic("TODO"),
29392444 .simple_type => |t| switch (t) {
29402445 .bool,
......@@ -3014,7 +2519,6 @@ pub const Type = struct {
30142519 .inferred_alloc_const => unreachable,
30152520 .inferred_alloc_mut => unreachable,
30162521
3017 .single_const_pointer_to_comptime_int,
30182522 .empty_struct_literal,
30192523 .empty_struct,
30202524 => return AbiSizeAdvanced{ .scalar = 0 },
......@@ -3068,8 +2572,6 @@ pub const Type = struct {
30682572 return abiSizeAdvancedUnion(ty, mod, strat, union_obj, true);
30692573 },
30702574
3071 .array_u8 => return AbiSizeAdvanced{ .scalar = ty.castTag(.array_u8).?.data },
3072 .array_u8_sentinel_0 => return AbiSizeAdvanced{ .scalar = ty.castTag(.array_u8_sentinel_0).?.data + 1 },
30732575 .array => {
30742576 const payload = ty.castTag(.array).?.data;
30752577 switch (try payload.elem_type.abiSizeAdvanced(mod, strat)) {
......@@ -3093,47 +2595,7 @@ pub const Type = struct {
30932595 }
30942596 },
30952597
3096 .vector => {
3097 const payload = ty.castTag(.vector).?.data;
3098 const opt_sema = switch (strat) {
3099 .sema => |sema| sema,
3100 .eager => null,
3101 .lazy => |arena| return AbiSizeAdvanced{
3102 .val = try Value.Tag.lazy_size.create(arena, ty),
3103 },
3104 };
3105 const elem_bits = try payload.elem_type.bitSizeAdvanced(mod, opt_sema);
3106 const total_bits = elem_bits * payload.len;
3107 const total_bytes = (total_bits + 7) / 8;
3108 const alignment = switch (try ty.abiAlignmentAdvanced(mod, strat)) {
3109 .scalar => |x| x,
3110 .val => return AbiSizeAdvanced{
3111 .val = try Value.Tag.lazy_size.create(strat.lazy, ty),
3112 },
3113 };
3114 const result = std.mem.alignForwardGeneric(u64, total_bytes, alignment);
3115 return AbiSizeAdvanced{ .scalar = result };
3116 },
3117
3118 .anyframe_T,
3119 .optional_single_const_pointer,
3120 .optional_single_mut_pointer,
3121 .single_const_pointer,
3122 .single_mut_pointer,
3123 .many_const_pointer,
3124 .many_mut_pointer,
3125 .c_const_pointer,
3126 .c_mut_pointer,
3127 .manyptr_u8,
3128 .manyptr_const_u8,
3129 .manyptr_const_u8_sentinel_0,
3130 => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
3131
3132 .const_slice,
3133 .mut_slice,
3134 .const_slice_u8,
3135 .const_slice_u8_sentinel_0,
3136 => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) * 2 },
2598 .anyframe_T => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) },
31372599
31382600 .pointer => switch (ty.castTag(.pointer).?.data.size) {
31392601 .Slice => return AbiSizeAdvanced{ .scalar = @divExact(target.ptrBitWidth(), 8) * 2 },
......@@ -3141,7 +2603,6 @@ pub const Type = struct {
31412603 },
31422604
31432605 // TODO revisit this when we have the concept of the error tag type
3144 .anyerror_void_error_union,
31452606 .error_set_inferred,
31462607 .error_set,
31472608 .error_set_merged,
......@@ -3149,8 +2610,7 @@ pub const Type = struct {
31492610 => return AbiSizeAdvanced{ .scalar = 2 },
31502611
31512612 .optional => {
3152 var buf: Payload.ElemType = undefined;
3153 const child_type = ty.optionalChild(&buf);
2613 const child_type = ty.optionalChild(mod);
31542614
31552615 if (child_type.isNoReturn()) {
31562616 return AbiSizeAdvanced{ .scalar = 0 };
......@@ -3272,8 +2732,12 @@ pub const Type = struct {
32722732 .int_type => |int_type| return int_type.bits,
32732733 .ptr_type => @panic("TODO"),
32742734 .array_type => @panic("TODO"),
3275 .vector_type => @panic("TODO"),
3276 .optional_type => @panic("TODO"),
2735 .vector_type => |vector_type| {
2736 const child_ty = vector_type.child.toType();
2737 const elem_bit_size = try bitSizeAdvanced(child_ty, mod, opt_sema);
2738 return elem_bit_size * vector_type.len;
2739 },
2740 .opt_type => @panic("TODO"),
32772741 .error_union_type => @panic("TODO"),
32782742 .simple_type => |t| switch (t) {
32792743 .f16 => return 16,
......@@ -3339,7 +2803,6 @@ pub const Type = struct {
33392803
33402804 switch (ty.tag()) {
33412805 .function => unreachable, // represents machine code; not a pointer
3342 .single_const_pointer_to_comptime_int => unreachable,
33432806 .empty_struct => unreachable,
33442807 .empty_struct_literal => unreachable,
33452808 .inferred_alloc_const => unreachable,
......@@ -3388,13 +2851,6 @@ pub const Type = struct {
33882851 return size;
33892852 },
33902853
3391 .vector => {
3392 const payload = ty.castTag(.vector).?.data;
3393 const elem_bit_size = try bitSizeAdvanced(payload.elem_type, mod, opt_sema);
3394 return elem_bit_size * payload.len;
3395 },
3396 .array_u8 => return 8 * ty.castTag(.array_u8).?.data,
3397 .array_u8_sentinel_0 => return 8 * (ty.castTag(.array_u8_sentinel_0).?.data + 1),
33982854 .array => {
33992855 const payload = ty.castTag(.array).?.data;
34002856 const elem_size = std.math.max(payload.elem_type.abiAlignment(mod), payload.elem_type.abiSize(mod));
......@@ -3415,43 +2871,13 @@ pub const Type = struct {
34152871
34162872 .anyframe_T => return target.ptrBitWidth(),
34172873
3418 .const_slice,
3419 .mut_slice,
3420 => return target.ptrBitWidth() * 2,
3421
3422 .const_slice_u8,
3423 .const_slice_u8_sentinel_0,
3424 => return target.ptrBitWidth() * 2,
3425
3426 .optional_single_const_pointer,
3427 .optional_single_mut_pointer,
3428 => {
3429 return target.ptrBitWidth();
3430 },
3431
3432 .single_const_pointer,
3433 .single_mut_pointer,
3434 .many_const_pointer,
3435 .many_mut_pointer,
3436 .c_const_pointer,
3437 .c_mut_pointer,
3438 => {
3439 return target.ptrBitWidth();
3440 },
3441
34422874 .pointer => switch (ty.castTag(.pointer).?.data.size) {
34432875 .Slice => return target.ptrBitWidth() * 2,
34442876 else => return target.ptrBitWidth(),
34452877 },
34462878
3447 .manyptr_u8,
3448 .manyptr_const_u8,
3449 .manyptr_const_u8_sentinel_0,
3450 => return target.ptrBitWidth(),
3451
34522879 .error_set,
34532880 .error_set_single,
3454 .anyerror_void_error_union,
34552881 .error_set_inferred,
34562882 .error_set_merged,
34572883 => return 16, // TODO revisit this when we have the concept of the error tag type
......@@ -3481,12 +2907,11 @@ pub const Type = struct {
34812907 return true;
34822908 },
34832909 .Array => {
3484 if (ty.arrayLenIncludingSentinel() == 0) return true;
3485 return ty.childType().layoutIsResolved(mod);
2910 if (ty.arrayLenIncludingSentinel(mod) == 0) return true;
2911 return ty.childType(mod).layoutIsResolved(mod);
34862912 },
34872913 .Optional => {
3488 var buf: Type.Payload.ElemType = undefined;
3489 const payload_ty = ty.optionalChild(&buf);
2914 const payload_ty = ty.optionalChild(mod);
34902915 return payload_ty.layoutIsResolved(mod);
34912916 },
34922917 .ErrorUnion => {
......@@ -3500,9 +2925,6 @@ pub const Type = struct {
35002925 pub fn isSinglePointer(ty: Type, mod: *const Module) bool {
35012926 switch (ty.ip_index) {
35022927 .none => return switch (ty.tag()) {
3503 .single_const_pointer,
3504 .single_mut_pointer,
3505 .single_const_pointer_to_comptime_int,
35062928 .inferred_alloc_const,
35072929 .inferred_alloc_mut,
35082930 => true,
......@@ -3519,54 +2941,33 @@ pub const Type = struct {
35192941 }
35202942
35212943 /// Asserts `ty` is a pointer.
3522 pub fn ptrSize(ty: Type) std.builtin.Type.Pointer.Size {
3523 return ptrSizeOrNull(ty).?;
2944 pub fn ptrSize(ty: Type, mod: *const Module) std.builtin.Type.Pointer.Size {
2945 return ptrSizeOrNull(ty, mod).?;
35242946 }
35252947
35262948 /// Returns `null` if `ty` is not a pointer.
3527 pub fn ptrSizeOrNull(ty: Type) ?std.builtin.Type.Pointer.Size {
3528 return switch (ty.tag()) {
3529 .const_slice,
3530 .mut_slice,
3531 .const_slice_u8,
3532 .const_slice_u8_sentinel_0,
3533 => .Slice,
3534
3535 .many_const_pointer,
3536 .many_mut_pointer,
3537 .manyptr_u8,
3538 .manyptr_const_u8,
3539 .manyptr_const_u8_sentinel_0,
3540 => .Many,
3541
3542 .c_const_pointer,
3543 .c_mut_pointer,
3544 => .C,
3545
3546 .single_const_pointer,
3547 .single_mut_pointer,
3548 .single_const_pointer_to_comptime_int,
3549 .inferred_alloc_const,
3550 .inferred_alloc_mut,
3551 => .One,
2949 pub fn ptrSizeOrNull(ty: Type, mod: *const Module) ?std.builtin.Type.Pointer.Size {
2950 return switch (ty.ip_index) {
2951 .none => switch (ty.tag()) {
2952 .inferred_alloc_const,
2953 .inferred_alloc_mut,
2954 => .One,
35522955
3553 .pointer => ty.castTag(.pointer).?.data.size,
2956 .pointer => ty.castTag(.pointer).?.data.size,
35542957
3555 else => null,
2958 else => null,
2959 },
2960 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
2961 .ptr_type => |ptr_info| ptr_info.size,
2962 else => null,
2963 },
35562964 };
35572965 }
35582966
35592967 pub fn isSlice(ty: Type, mod: *const Module) bool {
35602968 return switch (ty.ip_index) {
35612969 .none => switch (ty.tag()) {
3562 .const_slice,
3563 .mut_slice,
3564 .const_slice_u8,
3565 .const_slice_u8_sentinel_0,
3566 => true,
3567
35682970 .pointer => ty.castTag(.pointer).?.data.size == .Slice,
3569
35702971 else => false,
35712972 },
35722973 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
......@@ -3583,78 +2984,28 @@ pub const Type = struct {
35832984
35842985 pub fn slicePtrFieldType(self: Type, buffer: *SlicePtrFieldTypeBuffer) Type {
35852986 switch (self.tag()) {
3586 .const_slice_u8 => return Type.initTag(.manyptr_const_u8),
3587 .const_slice_u8_sentinel_0 => return Type.initTag(.manyptr_const_u8_sentinel_0),
3588
3589 .const_slice => {
3590 const elem_type = self.castTag(.const_slice).?.data;
3591 buffer.* = .{
3592 .elem_type = .{
3593 .base = .{ .tag = .many_const_pointer },
3594 .data = elem_type,
3595 },
3596 };
3597 return Type.initPayload(&buffer.elem_type.base);
3598 },
3599 .mut_slice => {
3600 const elem_type = self.castTag(.mut_slice).?.data;
3601 buffer.* = .{
3602 .elem_type = .{
3603 .base = .{ .tag = .many_mut_pointer },
3604 .data = elem_type,
3605 },
3606 };
3607 return Type.initPayload(&buffer.elem_type.base);
3608 },
3609
36102987 .pointer => {
36112988 const payload = self.castTag(.pointer).?.data;
36122989 assert(payload.size == .Slice);
36132990
3614 if (payload.sentinel != null or
3615 payload.@"align" != 0 or
3616 payload.@"addrspace" != .generic or
3617 payload.bit_offset != 0 or
3618 payload.host_size != 0 or
3619 payload.vector_index != .none or
3620 payload.@"allowzero" or
3621 payload.@"volatile")
3622 {
3623 buffer.* = .{
3624 .pointer = .{
3625 .data = .{
3626 .pointee_type = payload.pointee_type,
3627 .sentinel = payload.sentinel,
3628 .@"align" = payload.@"align",
3629 .@"addrspace" = payload.@"addrspace",
3630 .bit_offset = payload.bit_offset,
3631 .host_size = payload.host_size,
3632 .vector_index = payload.vector_index,
3633 .@"allowzero" = payload.@"allowzero",
3634 .mutable = payload.mutable,
3635 .@"volatile" = payload.@"volatile",
3636 .size = .Many,
3637 },
3638 },
3639 };
3640 return Type.initPayload(&buffer.pointer.base);
3641 } else if (payload.mutable) {
3642 buffer.* = .{
3643 .elem_type = .{
3644 .base = .{ .tag = .many_mut_pointer },
3645 .data = payload.pointee_type,
3646 },
3647 };
3648 return Type.initPayload(&buffer.elem_type.base);
3649 } else {
3650 buffer.* = .{
3651 .elem_type = .{
3652 .base = .{ .tag = .many_const_pointer },
3653 .data = payload.pointee_type,
2991 buffer.* = .{
2992 .pointer = .{
2993 .data = .{
2994 .pointee_type = payload.pointee_type,
2995 .sentinel = payload.sentinel,
2996 .@"align" = payload.@"align",
2997 .@"addrspace" = payload.@"addrspace",
2998 .bit_offset = payload.bit_offset,
2999 .host_size = payload.host_size,
3000 .vector_index = payload.vector_index,
3001 .@"allowzero" = payload.@"allowzero",
3002 .mutable = payload.mutable,
3003 .@"volatile" = payload.@"volatile",
3004 .size = .Many,
36543005 },
3655 };
3656 return Type.initPayload(&buffer.elem_type.base);
3657 }
3006 },
3007 };
3008 return Type.initPayload(&buffer.pointer.base);
36583009 },
36593010
36603011 else => unreachable,
......@@ -3663,19 +3014,7 @@ pub const Type = struct {
36633014
36643015 pub fn isConstPtr(self: Type) bool {
36653016 return switch (self.tag()) {
3666 .single_const_pointer,
3667 .many_const_pointer,
3668 .c_const_pointer,
3669 .single_const_pointer_to_comptime_int,
3670 .const_slice_u8,
3671 .const_slice_u8_sentinel_0,
3672 .const_slice,
3673 .manyptr_const_u8,
3674 .manyptr_const_u8_sentinel_0,
3675 => true,
3676
36773017 .pointer => !self.castTag(.pointer).?.data.mutable,
3678
36793018 else => false,
36803019 };
36813020 }
......@@ -3702,49 +3041,46 @@ pub const Type = struct {
37023041
37033042 pub fn isCPtr(self: Type) bool {
37043043 return switch (self.tag()) {
3705 .c_const_pointer,
3706 .c_mut_pointer,
3707 => return true,
3708
37093044 .pointer => self.castTag(.pointer).?.data.size == .C,
37103045
37113046 else => return false,
37123047 };
37133048 }
37143049
3715 pub fn isPtrAtRuntime(self: Type, mod: *const Module) bool {
3716 switch (self.tag()) {
3717 .c_const_pointer,
3718 .c_mut_pointer,
3719 .many_const_pointer,
3720 .many_mut_pointer,
3721 .manyptr_const_u8,
3722 .manyptr_const_u8_sentinel_0,
3723 .manyptr_u8,
3724 .optional_single_const_pointer,
3725 .optional_single_mut_pointer,
3726 .single_const_pointer,
3727 .single_const_pointer_to_comptime_int,
3728 .single_mut_pointer,
3729 => return true,
3050 pub fn isPtrAtRuntime(ty: Type, mod: *const Module) bool {
3051 switch (ty.ip_index) {
3052 .none => switch (ty.tag()) {
3053 .pointer => switch (ty.castTag(.pointer).?.data.size) {
3054 .Slice => return false,
3055 .One, .Many, .C => return true,
3056 },
37303057
3731 .pointer => switch (self.castTag(.pointer).?.data.size) {
3732 .Slice => return false,
3733 .One, .Many, .C => return true,
3734 },
3058 .optional => {
3059 const child_type = ty.optionalChild(mod);
3060 if (child_type.zigTypeTag(mod) != .Pointer) return false;
3061 const info = child_type.ptrInfo(mod);
3062 switch (info.size) {
3063 .Slice, .C => return false,
3064 .Many, .One => return !info.@"allowzero",
3065 }
3066 },
37353067
3736 .optional => {
3737 var buf: Payload.ElemType = undefined;
3738 const child_type = self.optionalChild(&buf);
3739 if (child_type.zigTypeTag(mod) != .Pointer) return false;
3740 const info = child_type.ptrInfo().data;
3741 switch (info.size) {
3742 .Slice, .C => return false,
3743 .Many, .One => return !info.@"allowzero",
3744 }
3068 else => return false,
3069 },
3070 else => return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
3071 .ptr_type => |ptr_type| switch (ptr_type.size) {
3072 .Slice => false,
3073 .One, .Many, .C => true,
3074 },
3075 .opt_type => |child| switch (mod.intern_pool.indexToKey(child)) {
3076 .ptr_type => |p| switch (p.size) {
3077 .Slice, .C => false,
3078 .Many, .One => !p.is_allowzero,
3079 },
3080 else => false,
3081 },
3082 else => false,
37453083 },
3746
3747 else => return false,
37483084 }
37493085 }
37503086
......@@ -3754,23 +3090,17 @@ pub const Type = struct {
37543090 if (ty.isPtrLikeOptional(mod)) {
37553091 return true;
37563092 }
3757 return ty.ptrInfo().data.@"allowzero";
3093 return ty.ptrInfo(mod).@"allowzero";
37583094 }
37593095
37603096 /// See also `isPtrLikeOptional`.
37613097 pub fn optionalReprIsPayload(ty: Type, mod: *const Module) bool {
37623098 switch (ty.tag()) {
3763 .optional_single_const_pointer,
3764 .optional_single_mut_pointer,
3765 .c_const_pointer,
3766 .c_mut_pointer,
3767 => return true,
3768
37693099 .optional => {
37703100 const child_ty = ty.castTag(.optional).?.data;
37713101 switch (child_ty.zigTypeTag(mod)) {
37723102 .Pointer => {
3773 const info = child_ty.ptrInfo().data;
3103 const info = child_ty.ptrInfo(mod);
37743104 switch (info.size) {
37753105 .C => return false,
37763106 .Slice, .Many, .One => return !info.@"allowzero",
......@@ -3793,7 +3123,7 @@ pub const Type = struct {
37933123 pub fn isPtrLikeOptional(ty: Type, mod: *const Module) bool {
37943124 if (ty.ip_index != .none) return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
37953125 .ptr_type => |ptr_type| ptr_type.size == .C,
3796 .optional_type => |o| switch (mod.intern_pool.indexToKey(o.payload_type)) {
3126 .opt_type => |child| switch (mod.intern_pool.indexToKey(child)) {
37973127 .ptr_type => |ptr_type| switch (ptr_type.size) {
37983128 .Slice, .C => false,
37993129 .Many, .One => !ptr_type.is_allowzero,
......@@ -3803,16 +3133,10 @@ pub const Type = struct {
38033133 else => false,
38043134 };
38053135 switch (ty.tag()) {
3806 .optional_single_const_pointer,
3807 .optional_single_mut_pointer,
3808 .c_const_pointer,
3809 .c_mut_pointer,
3810 => return true,
3811
38123136 .optional => {
38133137 const child_ty = ty.castTag(.optional).?.data;
38143138 if (child_ty.zigTypeTag(mod) != .Pointer) return false;
3815 const info = child_ty.ptrInfo().data;
3139 const info = child_ty.ptrInfo(mod);
38163140 switch (info.size) {
38173141 .Slice, .C => return false,
38183142 .Many, .One => return !info.@"allowzero",
......@@ -3828,43 +3152,24 @@ pub const Type = struct {
38283152 /// For *[N]T, returns [N]T.
38293153 /// For *T, returns T.
38303154 /// For [*]T, returns T.
3831 pub fn childType(ty: Type) Type {
3832 return switch (ty.tag()) {
3833 .vector => ty.castTag(.vector).?.data.elem_type,
3834 .array => ty.castTag(.array).?.data.elem_type,
3835 .array_sentinel => ty.castTag(.array_sentinel).?.data.elem_type,
3836 .optional_single_mut_pointer,
3837 .optional_single_const_pointer,
3838 .single_const_pointer,
3839 .single_mut_pointer,
3840 .many_const_pointer,
3841 .many_mut_pointer,
3842 .c_const_pointer,
3843 .c_mut_pointer,
3844 .const_slice,
3845 .mut_slice,
3846 => ty.castPointer().?.data,
3847
3848 .array_u8,
3849 .array_u8_sentinel_0,
3850 .const_slice_u8,
3851 .const_slice_u8_sentinel_0,
3852 .manyptr_u8,
3853 .manyptr_const_u8,
3854 .manyptr_const_u8_sentinel_0,
3855 => Type.u8,
3856
3857 .single_const_pointer_to_comptime_int => Type.comptime_int,
3858 .pointer => ty.castTag(.pointer).?.data.pointee_type,
3155 pub fn childType(ty: Type, mod: *const Module) Type {
3156 return childTypeIp(ty, mod.intern_pool);
3157 }
38593158
3860 else => unreachable,
3159 pub fn childTypeIp(ty: Type, ip: InternPool) Type {
3160 return switch (ty.ip_index) {
3161 .none => switch (ty.tag()) {
3162 .array => ty.castTag(.array).?.data.elem_type,
3163 .array_sentinel => ty.castTag(.array_sentinel).?.data.elem_type,
3164
3165 .pointer => ty.castTag(.pointer).?.data.pointee_type,
3166
3167 else => unreachable,
3168 },
3169 else => ip.childType(ty.ip_index).toType(),
38613170 };
38623171 }
38633172
3864 /// Asserts the type is a pointer or array type.
3865 /// TODO this is deprecated in favor of `childType`.
3866 pub const elemType = childType;
3867
38683173 /// For *[N]T, returns T.
38693174 /// For ?*T, returns T.
38703175 /// For ?*[N]T, returns T.
......@@ -3875,54 +3180,42 @@ pub const Type = struct {
38753180 /// For []T, returns T.
38763181 /// For anyframe->T, returns T.
38773182 pub fn elemType2(ty: Type, mod: *const Module) Type {
3878 return switch (ty.tag()) {
3879 .vector => ty.castTag(.vector).?.data.elem_type,
3880 .array => ty.castTag(.array).?.data.elem_type,
3881 .array_sentinel => ty.castTag(.array_sentinel).?.data.elem_type,
3882 .many_const_pointer,
3883 .many_mut_pointer,
3884 .c_const_pointer,
3885 .c_mut_pointer,
3886 .const_slice,
3887 .mut_slice,
3888 => ty.castPointer().?.data,
3889
3890 .single_const_pointer,
3891 .single_mut_pointer,
3892 => ty.castPointer().?.data.shallowElemType(mod),
3893
3894 .array_u8,
3895 .array_u8_sentinel_0,
3896 .const_slice_u8,
3897 .const_slice_u8_sentinel_0,
3898 .manyptr_u8,
3899 .manyptr_const_u8,
3900 .manyptr_const_u8_sentinel_0,
3901 => Type.u8,
3902
3903 .single_const_pointer_to_comptime_int => Type.comptime_int,
3904 .pointer => {
3905 const info = ty.castTag(.pointer).?.data;
3906 const child_ty = info.pointee_type;
3907 if (info.size == .One) {
3908 return child_ty.shallowElemType(mod);
3909 } else {
3910 return child_ty;
3911 }
3912 },
3913 .optional => ty.castTag(.optional).?.data.childType(),
3914 .optional_single_mut_pointer => ty.castPointer().?.data,
3915 .optional_single_const_pointer => ty.castPointer().?.data,
3183 return switch (ty.ip_index) {
3184 .none => switch (ty.tag()) {
3185 .array => ty.castTag(.array).?.data.elem_type,
3186 .array_sentinel => ty.castTag(.array_sentinel).?.data.elem_type,
3187
3188 .pointer => {
3189 const info = ty.castTag(.pointer).?.data;
3190 const child_ty = info.pointee_type;
3191 if (info.size == .One) {
3192 return child_ty.shallowElemType(mod);
3193 } else {
3194 return child_ty;
3195 }
3196 },
3197 .optional => ty.castTag(.optional).?.data.childType(mod),
39163198
3917 .anyframe_T => ty.castTag(.anyframe_T).?.data,
3199 .anyframe_T => ty.castTag(.anyframe_T).?.data,
39183200
3919 else => unreachable,
3201 else => unreachable,
3202 },
3203 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
3204 .ptr_type => |ptr_type| switch (ptr_type.size) {
3205 .One => ptr_type.elem_type.toType().shallowElemType(mod),
3206 .Many, .C, .Slice => ptr_type.elem_type.toType(),
3207 },
3208 .vector_type => |vector_type| vector_type.child.toType(),
3209 .array_type => |array_type| array_type.child.toType(),
3210 .opt_type => |child| mod.intern_pool.childType(child).toType(),
3211 else => unreachable,
3212 },
39203213 };
39213214 }
39223215
39233216 fn shallowElemType(child_ty: Type, mod: *const Module) Type {
39243217 return switch (child_ty.zigTypeTag(mod)) {
3925 .Array, .Vector => child_ty.childType(),
3218 .Array, .Vector => child_ty.childType(mod),
39263219 else => child_ty,
39273220 };
39283221 }
......@@ -3930,7 +3223,7 @@ pub const Type = struct {
39303223 /// For vectors, returns the element type. Otherwise returns self.
39313224 pub fn scalarType(ty: Type, mod: *const Module) Type {
39323225 return switch (ty.zigTypeTag(mod)) {
3933 .Vector => ty.childType(),
3226 .Vector => ty.childType(mod),
39343227 else => ty,
39353228 };
39363229 }
......@@ -3938,51 +3231,25 @@ pub const Type = struct {
39383231 /// Asserts that the type is an optional.
39393232 /// Resulting `Type` will have inner memory referencing `buf`.
39403233 /// Note that for C pointers this returns the type unmodified.
3941 pub fn optionalChild(ty: Type, buf: *Payload.ElemType) Type {
3942 return switch (ty.tag()) {
3943 .optional => ty.castTag(.optional).?.data,
3944 .optional_single_mut_pointer => {
3945 buf.* = .{
3946 .base = .{ .tag = .single_mut_pointer },
3947 .data = ty.castPointer().?.data,
3948 };
3949 return Type.initPayload(&buf.base);
3950 },
3951 .optional_single_const_pointer => {
3952 buf.* = .{
3953 .base = .{ .tag = .single_const_pointer },
3954 .data = ty.castPointer().?.data,
3955 };
3956 return Type.initPayload(&buf.base);
3957 },
3234 pub fn optionalChild(ty: Type, mod: *const Module) Type {
3235 return switch (ty.ip_index) {
3236 .none => switch (ty.tag()) {
3237 .optional => ty.castTag(.optional).?.data,
39583238
3959 .pointer, // here we assume it is a C pointer
3960 .c_const_pointer,
3961 .c_mut_pointer,
3962 => return ty,
3239 .pointer, // here we assume it is a C pointer
3240 => return ty,
39633241
3964 else => unreachable,
3965 };
3966 }
3967
3968 /// Asserts that the type is an optional.
3969 /// Same as `optionalChild` but allocates the buffer if needed.
3970 pub fn optionalChildAlloc(ty: Type, allocator: Allocator) !Type {
3971 switch (ty.tag()) {
3972 .optional => return ty.castTag(.optional).?.data,
3973 .optional_single_mut_pointer => {
3974 return Tag.single_mut_pointer.create(allocator, ty.castPointer().?.data);
3242 else => unreachable,
39753243 },
3976 .optional_single_const_pointer => {
3977 return Tag.single_const_pointer.create(allocator, ty.castPointer().?.data);
3244 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
3245 .opt_type => |child| child.toType(),
3246 .ptr_type => |ptr_type| b: {
3247 assert(ptr_type.size == .C);
3248 break :b ty;
3249 },
3250 else => unreachable,
39783251 },
3979 .pointer, // here we assume it is a C pointer
3980 .c_const_pointer,
3981 .c_mut_pointer,
3982 => return ty,
3983
3984 else => unreachable,
3985 }
3252 };
39863253 }
39873254
39883255 /// Returns the tag type of a union, if the type is a union and it has a tag type.
......@@ -4071,19 +3338,25 @@ pub const Type = struct {
40713338 }
40723339
40733340 /// Asserts that the type is an error union.
4074 pub fn errorUnionPayload(self: Type) Type {
4075 return switch (self.tag()) {
4076 .anyerror_void_error_union => Type.void,
4077 .error_union => self.castTag(.error_union).?.data.payload,
4078 else => unreachable,
3341 pub fn errorUnionPayload(ty: Type) Type {
3342 return switch (ty.ip_index) {
3343 .anyerror_void_error_union_type => Type.void,
3344 .none => switch (ty.tag()) {
3345 .error_union => ty.castTag(.error_union).?.data.payload,
3346 else => unreachable,
3347 },
3348 else => @panic("TODO"),
40793349 };
40803350 }
40813351
4082 pub fn errorUnionSet(self: Type) Type {
4083 return switch (self.tag()) {
4084 .anyerror_void_error_union => Type.anyerror,
4085 .error_union => self.castTag(.error_union).?.data.error_set,
4086 else => unreachable,
3352 pub fn errorUnionSet(ty: Type) Type {
3353 return switch (ty.ip_index) {
3354 .anyerror_void_error_union_type => Type.anyerror,
3355 .none => switch (ty.tag()) {
3356 .error_union => ty.castTag(.error_union).?.data.error_set,
3357 else => unreachable,
3358 },
3359 else => @panic("TODO"),
40873360 };
40883361 }
40893362
......@@ -4168,67 +3441,73 @@ pub const Type = struct {
41683441 }
41693442
41703443 /// Asserts the type is an array or vector or struct.
4171 pub fn arrayLen(ty: Type) u64 {
4172 return switch (ty.tag()) {
4173 .vector => ty.castTag(.vector).?.data.len,
4174 .array => ty.castTag(.array).?.data.len,
4175 .array_sentinel => ty.castTag(.array_sentinel).?.data.len,
4176 .array_u8 => ty.castTag(.array_u8).?.data,
4177 .array_u8_sentinel_0 => ty.castTag(.array_u8_sentinel_0).?.data,
4178 .tuple => ty.castTag(.tuple).?.data.types.len,
4179 .anon_struct => ty.castTag(.anon_struct).?.data.types.len,
4180 .@"struct" => ty.castTag(.@"struct").?.data.fields.count(),
4181 .empty_struct, .empty_struct_literal => 0,
3444 pub fn arrayLen(ty: Type, mod: *const Module) u64 {
3445 return arrayLenIp(ty, mod.intern_pool);
3446 }
41823447
4183 else => unreachable,
3448 pub fn arrayLenIp(ty: Type, ip: InternPool) u64 {
3449 return switch (ty.ip_index) {
3450 .none => switch (ty.tag()) {
3451 .array => ty.castTag(.array).?.data.len,
3452 .array_sentinel => ty.castTag(.array_sentinel).?.data.len,
3453 .tuple => ty.castTag(.tuple).?.data.types.len,
3454 .anon_struct => ty.castTag(.anon_struct).?.data.types.len,
3455 .@"struct" => ty.castTag(.@"struct").?.data.fields.count(),
3456 .empty_struct, .empty_struct_literal => 0,
3457
3458 else => unreachable,
3459 },
3460 else => switch (ip.indexToKey(ty.ip_index)) {
3461 .vector_type => |vector_type| vector_type.len,
3462 .array_type => |array_type| array_type.len,
3463 else => unreachable,
3464 },
41843465 };
41853466 }
41863467
4187 pub fn arrayLenIncludingSentinel(ty: Type) u64 {
4188 return ty.arrayLen() + @boolToInt(ty.sentinel() != null);
3468 pub fn arrayLenIncludingSentinel(ty: Type, mod: *const Module) u64 {
3469 return ty.arrayLen(mod) + @boolToInt(ty.sentinel(mod) != null);
41893470 }
41903471
4191 pub fn vectorLen(ty: Type) u32 {
4192 return switch (ty.tag()) {
4193 .vector => @intCast(u32, ty.castTag(.vector).?.data.len),
4194 .tuple => @intCast(u32, ty.castTag(.tuple).?.data.types.len),
4195 .anon_struct => @intCast(u32, ty.castTag(.anon_struct).?.data.types.len),
4196 else => unreachable,
3472 pub fn vectorLen(ty: Type, mod: *const Module) u32 {
3473 return switch (ty.ip_index) {
3474 .none => switch (ty.tag()) {
3475 .tuple => @intCast(u32, ty.castTag(.tuple).?.data.types.len),
3476 .anon_struct => @intCast(u32, ty.castTag(.anon_struct).?.data.types.len),
3477 else => unreachable,
3478 },
3479 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
3480 .vector_type => |vector_type| vector_type.len,
3481 else => unreachable,
3482 },
41973483 };
41983484 }
41993485
42003486 /// Asserts the type is an array, pointer or vector.
4201 pub fn sentinel(self: Type) ?Value {
4202 return switch (self.tag()) {
4203 .single_const_pointer,
4204 .single_mut_pointer,
4205 .many_const_pointer,
4206 .many_mut_pointer,
4207 .c_const_pointer,
4208 .c_mut_pointer,
4209 .single_const_pointer_to_comptime_int,
4210 .vector,
4211 .array,
4212 .array_u8,
4213 .manyptr_u8,
4214 .manyptr_const_u8,
4215 .const_slice_u8,
4216 .const_slice,
4217 .mut_slice,
4218 .tuple,
4219 .empty_struct_literal,
4220 .@"struct",
4221 => return null,
3487 pub fn sentinel(ty: Type, mod: *const Module) ?Value {
3488 return switch (ty.ip_index) {
3489 .none => switch (ty.tag()) {
3490 .array,
3491 .tuple,
3492 .empty_struct_literal,
3493 .@"struct",
3494 => null,
42223495
4223 .pointer => return self.castTag(.pointer).?.data.sentinel,
4224 .array_sentinel => return self.castTag(.array_sentinel).?.data.sentinel,
3496 .pointer => ty.castTag(.pointer).?.data.sentinel,
3497 .array_sentinel => ty.castTag(.array_sentinel).?.data.sentinel,
42253498
4226 .array_u8_sentinel_0,
4227 .const_slice_u8_sentinel_0,
4228 .manyptr_const_u8_sentinel_0,
4229 => return Value.zero,
3499 else => unreachable,
3500 },
3501 else => switch (mod.intern_pool.indexToKey(ty.ip_index)) {
3502 .vector_type,
3503 .struct_type,
3504 => null,
42303505
4231 else => unreachable,
3506 .array_type => |t| if (t.sentinel != .none) t.sentinel.toValue() else null,
3507 .ptr_type => |t| if (t.sentinel != .none) t.sentinel.toValue() else null,
3508
3509 else => unreachable,
3510 },
42323511 };
42333512 }
42343513
......@@ -4292,8 +3571,6 @@ pub const Type = struct {
42923571 return .{ .signedness = .unsigned, .bits = 16 };
42933572 },
42943573
4295 .vector => ty = ty.castTag(.vector).?.data.elem_type,
4296
42973574 .@"struct" => {
42983575 const struct_obj = ty.castTag(.@"struct").?.data;
42993576 assert(struct_obj.layout == .Packed);
......@@ -4321,8 +3598,9 @@ pub const Type = struct {
43213598 .int_type => |int_type| return int_type,
43223599 .ptr_type => unreachable,
43233600 .array_type => unreachable,
4324 .vector_type => @panic("TODO"),
4325 .optional_type => unreachable,
3601 .vector_type => |vector_type| ty = vector_type.child.toType(),
3602
3603 .opt_type => unreachable,
43263604 .error_union_type => unreachable,
43273605 .simple_type => unreachable, // handled via Index enum tag above
43283606 .struct_type => @panic("TODO"),
......@@ -4426,7 +3704,11 @@ pub const Type = struct {
44263704
44273705 /// Asserts the type is a function or a function pointer.
44283706 pub fn fnReturnType(ty: Type) Type {
4429 const fn_ty = if (ty.castPointer()) |p| p.data else ty;
3707 const fn_ty = switch (ty.tag()) {
3708 .pointer => ty.castTag(.pointer).?.data.pointee_type,
3709 .function => ty,
3710 else => unreachable,
3711 };
44303712 return fn_ty.castTag(.function).?.data.return_type;
44313713 }
44323714
......@@ -4516,8 +3798,12 @@ pub const Type = struct {
45163798 },
45173799 .ptr_type => @panic("TODO"),
45183800 .array_type => @panic("TODO"),
4519 .vector_type => @panic("TODO"),
4520 .optional_type => @panic("TODO"),
3801 .vector_type => |vector_type| {
3802 if (vector_type.len == 0) return Value.initTag(.empty_array);
3803 if (vector_type.child.toType().onePossibleValue(mod)) |v| return v;
3804 return null;
3805 },
3806 .opt_type => @panic("TODO"),
45213807 .error_union_type => @panic("TODO"),
45223808 .simple_type => |t| switch (t) {
45233809 .f16,
......@@ -4580,34 +3866,15 @@ pub const Type = struct {
45803866 .error_set,
45813867 .error_set_merged,
45823868 .function,
4583 .single_const_pointer_to_comptime_int,
45843869 .array_sentinel,
4585 .array_u8_sentinel_0,
4586 .const_slice_u8,
4587 .const_slice_u8_sentinel_0,
4588 .const_slice,
4589 .mut_slice,
4590 .optional_single_mut_pointer,
4591 .optional_single_const_pointer,
4592 .anyerror_void_error_union,
45933870 .error_set_inferred,
45943871 .@"opaque",
4595 .manyptr_u8,
4596 .manyptr_const_u8,
4597 .manyptr_const_u8_sentinel_0,
45983872 .anyframe_T,
4599 .many_const_pointer,
4600 .many_mut_pointer,
4601 .c_const_pointer,
4602 .c_mut_pointer,
4603 .single_const_pointer,
4604 .single_mut_pointer,
46053873 .pointer,
46063874 => return null,
46073875
46083876 .optional => {
4609 var buf: Payload.ElemType = undefined;
4610 const child_ty = ty.optionalChild(&buf);
3877 const child_ty = ty.optionalChild(mod);
46113878 if (child_ty.isNoReturn()) {
46123879 return Value.null;
46133880 } else {
......@@ -4690,10 +3957,10 @@ pub const Type = struct {
46903957
46913958 .empty_struct, .empty_struct_literal => return Value.initTag(.empty_struct_value),
46923959
4693 .vector, .array, .array_u8 => {
4694 if (ty.arrayLen() == 0)
3960 .array => {
3961 if (ty.arrayLen(mod) == 0)
46953962 return Value.initTag(.empty_array);
4696 if (ty.elemType().onePossibleValue(mod) != null)
3963 if (ty.childType(mod).onePossibleValue(mod) != null)
46973964 return Value.initTag(.the_only_possible_value);
46983965 return null;
46993966 },
......@@ -4711,9 +3978,9 @@ pub const Type = struct {
47113978 if (ty.ip_index != .none) return switch (mod.intern_pool.indexToKey(ty.ip_index)) {
47123979 .int_type => false,
47133980 .ptr_type => @panic("TODO"),
4714 .array_type => @panic("TODO"),
4715 .vector_type => @panic("TODO"),
4716 .optional_type => @panic("TODO"),
3981 .array_type => |array_type| return array_type.child.toType().comptimeOnly(mod),
3982 .vector_type => |vector_type| return vector_type.child.toType().comptimeOnly(mod),
3983 .opt_type => @panic("TODO"),
47173984 .error_union_type => @panic("TODO"),
47183985 .simple_type => |t| switch (t) {
47193986 .f16,
......@@ -4772,12 +4039,6 @@ pub const Type = struct {
47724039 };
47734040
47744041 return switch (ty.tag()) {
4775 .manyptr_u8,
4776 .manyptr_const_u8,
4777 .manyptr_const_u8_sentinel_0,
4778 .const_slice_u8,
4779 .const_slice_u8_sentinel_0,
4780 .anyerror_void_error_union,
47814042 .empty_struct_literal,
47824043 .empty_struct,
47834044 .error_set,
......@@ -4785,35 +4046,21 @@ pub const Type = struct {
47854046 .error_set_inferred,
47864047 .error_set_merged,
47874048 .@"opaque",
4788 .array_u8,
4789 .array_u8_sentinel_0,
47904049 .enum_simple,
47914050 => false,
47924051
4793 .single_const_pointer_to_comptime_int,
47944052 // These are function bodies, not function pointers.
4795 .function,
4796 => true,
4053 .function => true,
47974054
47984055 .inferred_alloc_mut => unreachable,
47994056 .inferred_alloc_const => unreachable,
48004057
48014058 .array,
48024059 .array_sentinel,
4803 .vector,
4804 => return ty.childType().comptimeOnly(mod),
4060 => return ty.childType(mod).comptimeOnly(mod),
48054061
4806 .pointer,
4807 .single_const_pointer,
4808 .single_mut_pointer,
4809 .many_const_pointer,
4810 .many_mut_pointer,
4811 .c_const_pointer,
4812 .c_mut_pointer,
4813 .const_slice,
4814 .mut_slice,
4815 => {
4816 const child_ty = ty.childType();
4062 .pointer => {
4063 const child_ty = ty.childType(mod);
48174064 if (child_ty.zigTypeTag(mod) == .Fn) {
48184065 return false;
48194066 } else {
......@@ -4821,12 +4068,8 @@ pub const Type = struct {
48214068 }
48224069 },
48234070
4824 .optional,
4825 .optional_single_mut_pointer,
4826 .optional_single_const_pointer,
4827 => {
4828 var buf: Type.Payload.ElemType = undefined;
4829 return ty.optionalChild(&buf).comptimeOnly(mod);
4071 .optional => {
4072 return ty.optionalChild(mod).comptimeOnly(mod);
48304073 },
48314074
48324075 .tuple, .anon_struct => {
......@@ -4882,6 +4125,10 @@ pub const Type = struct {
48824125 };
48834126 }
48844127
4128 pub fn isVector(ty: Type, mod: *const Module) bool {
4129 return ty.zigTypeTag(mod) == .Vector;
4130 }
4131
48854132 pub fn isArrayOrVector(ty: Type, mod: *const Module) bool {
48864133 return switch (ty.zigTypeTag(mod)) {
48874134 .Array, .Vector => true,
......@@ -4892,9 +4139,9 @@ pub const Type = struct {
48924139 pub fn isIndexable(ty: Type, mod: *const Module) bool {
48934140 return switch (ty.zigTypeTag(mod)) {
48944141 .Array, .Vector => true,
4895 .Pointer => switch (ty.ptrSize()) {
4142 .Pointer => switch (ty.ptrSize(mod)) {
48964143 .Slice, .Many, .C => true,
4897 .One => ty.elemType().zigTypeTag(mod) == .Array,
4144 .One => ty.childType(mod).zigTypeTag(mod) == .Array,
48984145 },
48994146 .Struct => ty.isTuple(),
49004147 else => false,
......@@ -4904,10 +4151,10 @@ pub const Type = struct {
49044151 pub fn indexableHasLen(ty: Type, mod: *const Module) bool {
49054152 return switch (ty.zigTypeTag(mod)) {
49064153 .Array, .Vector => true,
4907 .Pointer => switch (ty.ptrSize()) {
4154 .Pointer => switch (ty.ptrSize(mod)) {
49084155 .Many, .C => false,
49094156 .Slice => true,
4910 .One => ty.elemType().zigTypeTag(mod) == .Array,
4157 .One => ty.childType(mod).zigTypeTag(mod) == .Array,
49114158 },
49124159 .Struct => ty.isTuple(),
49134160 else => false,
......@@ -5527,14 +4774,6 @@ pub const Type = struct {
55274774 /// with different enum tags, because the the former requires more payload data than the latter.
55284775 /// See `zigTypeTag` for the function that corresponds to `std.builtin.TypeId`.
55294776 pub const Tag = enum(usize) {
5530 // The first section of this enum are tags that require no payload.
5531 manyptr_u8,
5532 manyptr_const_u8,
5533 manyptr_const_u8_sentinel_0,
5534 single_const_pointer_to_comptime_int,
5535 const_slice_u8,
5536 const_slice_u8_sentinel_0,
5537 anyerror_void_error_union,
55384777 /// Same as `empty_struct` except it has an empty namespace.
55394778 empty_struct_literal,
55404779 /// This is a special value that tracks a set of types that have been stored
......@@ -5545,28 +4784,15 @@ pub const Type = struct {
55454784 inferred_alloc_const, // See last_no_payload_tag below.
55464785 // After this, the tag requires a payload.
55474786
5548 array_u8,
5549 array_u8_sentinel_0,
55504787 array,
55514788 array_sentinel,
5552 vector,
55534789 /// Possible Value tags for this: @"struct"
55544790 tuple,
55554791 /// Possible Value tags for this: @"struct"
55564792 anon_struct,
55574793 pointer,
5558 single_const_pointer,
5559 single_mut_pointer,
5560 many_const_pointer,
5561 many_mut_pointer,
5562 c_const_pointer,
5563 c_mut_pointer,
5564 const_slice,
5565 mut_slice,
55664794 function,
55674795 optional,
5568 optional_single_mut_pointer,
5569 optional_single_const_pointer,
55704796 error_union,
55714797 anyframe_T,
55724798 error_set,
......@@ -5590,33 +4816,12 @@ pub const Type = struct {
55904816
55914817 pub fn Type(comptime t: Tag) type {
55924818 return switch (t) {
5593 .single_const_pointer_to_comptime_int,
5594 .anyerror_void_error_union,
5595 .const_slice_u8,
5596 .const_slice_u8_sentinel_0,
55974819 .inferred_alloc_const,
55984820 .inferred_alloc_mut,
55994821 .empty_struct_literal,
5600 .manyptr_u8,
5601 .manyptr_const_u8,
5602 .manyptr_const_u8_sentinel_0,
56034822 => @compileError("Type Tag " ++ @tagName(t) ++ " has no payload"),
56044823
5605 .array_u8,
5606 .array_u8_sentinel_0,
5607 => Payload.Len,
5608
5609 .single_const_pointer,
5610 .single_mut_pointer,
5611 .many_const_pointer,
5612 .many_mut_pointer,
5613 .c_const_pointer,
5614 .c_mut_pointer,
5615 .const_slice,
5616 .mut_slice,
56174824 .optional,
5618 .optional_single_mut_pointer,
5619 .optional_single_const_pointer,
56204825 .anyframe_T,
56214826 => Payload.ElemType,
56224827
......@@ -5624,7 +4829,7 @@ pub const Type = struct {
56244829 .error_set_inferred => Payload.ErrorSetInferred,
56254830 .error_set_merged => Payload.ErrorSetMerged,
56264831
5627 .array, .vector => Payload.Array,
4832 .array => Payload.Array,
56284833 .array_sentinel => Payload.ArraySentinel,
56294834 .pointer => Payload.Pointer,
56304835 .function => Payload.Function,
......@@ -5847,15 +5052,28 @@ pub const Type = struct {
58475052 @"volatile": bool = false,
58485053 size: std.builtin.Type.Pointer.Size = .One,
58495054
5850 pub const VectorIndex = enum(u32) {
5851 none = std.math.maxInt(u32),
5852 runtime = std.math.maxInt(u32) - 1,
5853 _,
5854 };
5055 pub const VectorIndex = InternPool.Key.PtrType.VectorIndex;
5056
58555057 pub fn alignment(data: Data, mod: *const Module) u32 {
58565058 if (data.@"align" != 0) return data.@"align";
58575059 return abiAlignment(data.pointee_type, mod);
58585060 }
5061
5062 pub fn fromKey(p: InternPool.Key.PtrType) Data {
5063 return .{
5064 .pointee_type = p.elem_type.toType(),
5065 .sentinel = if (p.sentinel != .none) p.sentinel.toValue() else null,
5066 .@"align" = p.alignment,
5067 .@"addrspace" = p.address_space,
5068 .bit_offset = p.bit_offset,
5069 .host_size = p.host_size,
5070 .vector_index = p.vector_index,
5071 .@"allowzero" = p.is_allowzero,
5072 .mutable = !p.is_const,
5073 .@"volatile" = p.is_volatile,
5074 .size = p.size,
5075 };
5076 }
58595077 };
58605078 };
58615079
......@@ -5986,6 +5204,17 @@ pub const Type = struct {
59865204 pub const @"c_ulonglong": Type = .{ .ip_index = .c_ulonglong_type, .legacy = undefined };
59875205 pub const @"c_longdouble": Type = .{ .ip_index = .c_longdouble_type, .legacy = undefined };
59885206
5207 pub const const_slice_u8: Type = .{ .ip_index = .const_slice_u8_type, .legacy = undefined };
5208 pub const manyptr_u8: Type = .{ .ip_index = .manyptr_u8_type, .legacy = undefined };
5209 pub const single_const_pointer_to_comptime_int: Type = .{
5210 .ip_index = .single_const_pointer_to_comptime_int_type,
5211 .legacy = undefined,
5212 };
5213 pub const const_slice_u8_sentinel_0: Type = .{
5214 .ip_index = .const_slice_u8_sentinel_0_type,
5215 .legacy = undefined,
5216 };
5217
59895218 pub const generic_poison: Type = .{ .ip_index = .generic_poison_type, .legacy = undefined };
59905219
59915220 pub const err_int = Type.u16;
......@@ -6019,50 +5248,6 @@ pub const Type = struct {
60195248 }
60205249 }
60215250
6022 if (d.@"align" == 0 and d.@"addrspace" == .generic and
6023 d.bit_offset == 0 and d.host_size == 0 and d.vector_index == .none and
6024 !d.@"allowzero" and !d.@"volatile")
6025 {
6026 if (d.sentinel) |sent| {
6027 if (!d.mutable and d.pointee_type.eql(Type.u8, mod)) {
6028 switch (d.size) {
6029 .Slice => {
6030 if (sent.compareAllWithZero(.eq, mod)) {
6031 return Type.initTag(.const_slice_u8_sentinel_0);
6032 }
6033 },
6034 .Many => {
6035 if (sent.compareAllWithZero(.eq, mod)) {
6036 return Type.initTag(.manyptr_const_u8_sentinel_0);
6037 }
6038 },
6039 else => {},
6040 }
6041 }
6042 } else if (!d.mutable and d.pointee_type.eql(Type.u8, mod)) {
6043 switch (d.size) {
6044 .Slice => return Type.initTag(.const_slice_u8),
6045 .Many => return Type.initTag(.manyptr_const_u8),
6046 else => {},
6047 }
6048 } else {
6049 const T = Type.Tag;
6050 const type_payload = try arena.create(Type.Payload.ElemType);
6051 type_payload.* = .{
6052 .base = .{
6053 .tag = switch (d.size) {
6054 .One => if (d.mutable) T.single_mut_pointer else T.single_const_pointer,
6055 .Many => if (d.mutable) T.many_mut_pointer else T.many_const_pointer,
6056 .C => if (d.mutable) T.c_mut_pointer else T.c_const_pointer,
6057 .Slice => if (d.mutable) T.mut_slice else T.const_slice,
6058 },
6059 },
6060 .data = d.pointee_type,
6061 };
6062 return Type.initPayload(&type_payload.base);
6063 }
6064 }
6065
60665251 return Type.Tag.pointer.create(arena, d);
60675252 }
60685253
......@@ -6073,13 +5258,21 @@ pub const Type = struct {
60735258 elem_type: Type,
60745259 mod: *Module,
60755260 ) Allocator.Error!Type {
6076 if (elem_type.eql(Type.u8, mod)) {
6077 if (sent) |some| {
6078 if (some.eql(Value.zero, elem_type, mod)) {
6079 return Tag.array_u8_sentinel_0.create(arena, len);
5261 if (elem_type.ip_index != .none) {
5262 if (sent) |s| {
5263 if (s.ip_index != .none) {
5264 return mod.arrayType(.{
5265 .len = len,
5266 .child = elem_type.ip_index,
5267 .sentinel = s.ip_index,
5268 });
60805269 }
60815270 } else {
6082 return Tag.array_u8.create(arena, len);
5271 return mod.arrayType(.{
5272 .len = len,
5273 .child = elem_type.ip_index,
5274 .sentinel = .none,
5275 });
60835276 }
60845277 }
60855278
......@@ -6097,24 +5290,11 @@ pub const Type = struct {
60975290 });
60985291 }
60995292
6100 pub fn vector(arena: Allocator, len: u64, elem_type: Type) Allocator.Error!Type {
6101 return Tag.vector.create(arena, .{
6102 .len = len,
6103 .elem_type = elem_type,
6104 });
6105 }
6106
6107 pub fn optional(arena: Allocator, child_type: Type) Allocator.Error!Type {
6108 switch (child_type.tag()) {
6109 .single_const_pointer => return Type.Tag.optional_single_const_pointer.create(
6110 arena,
6111 child_type.elemType(),
6112 ),
6113 .single_mut_pointer => return Type.Tag.optional_single_mut_pointer.create(
6114 arena,
6115 child_type.elemType(),
6116 ),
6117 else => return Type.Tag.optional.create(arena, child_type),
5293 pub fn optional(arena: Allocator, child_type: Type, mod: *Module) Allocator.Error!Type {
5294 if (child_type.ip_index != .none) {
5295 return mod.optionalType(child_type.ip_index);
5296 } else {
5297 return Type.Tag.optional.create(arena, child_type);
61185298 }
61195299 }
61205300
......@@ -6125,12 +5305,6 @@ pub const Type = struct {
61255305 mod: *Module,
61265306 ) Allocator.Error!Type {
61275307 assert(error_set.zigTypeTag(mod) == .ErrorSet);
6128 if (error_set.eql(Type.anyerror, mod) and
6129 payload.eql(Type.void, mod))
6130 {
6131 return Type.initTag(.anyerror_void_error_union);
6132 }
6133
61345308 return Type.Tag.error_union.create(arena, .{
61355309 .error_set = error_set,
61365310 .payload = payload,
src/value.zig+80-128
......@@ -33,14 +33,6 @@ pub const Value = struct {
3333 // Keep in sync with tools/stage2_pretty_printers_common.py
3434 pub const Tag = enum(usize) {
3535 // The first section of this enum are tags that require no payload.
36 manyptr_u8_type,
37 manyptr_const_u8_type,
38 manyptr_const_u8_sentinel_0_type,
39 single_const_pointer_to_comptime_int_type,
40 const_slice_u8_type,
41 const_slice_u8_sentinel_0_type,
42 anyerror_void_error_union_type,
43
4436 undef,
4537 zero,
4638 one,
......@@ -140,11 +132,6 @@ pub const Value = struct {
140132
141133 pub fn Type(comptime t: Tag) type {
142134 return switch (t) {
143 .single_const_pointer_to_comptime_int_type,
144 .const_slice_u8_type,
145 .const_slice_u8_sentinel_0_type,
146 .anyerror_void_error_union_type,
147
148135 .undef,
149136 .zero,
150137 .one,
......@@ -153,9 +140,6 @@ pub const Value = struct {
153140 .empty_struct_value,
154141 .empty_array,
155142 .null_value,
156 .manyptr_u8_type,
157 .manyptr_const_u8_type,
158 .manyptr_const_u8_sentinel_0_type,
159143 => @compileError("Value Tag " ++ @tagName(t) ++ " has no payload"),
160144
161145 .int_big_positive,
......@@ -280,9 +264,7 @@ pub const Value = struct {
280264 }
281265
282266 pub fn castTag(self: Value, comptime t: Tag) ?*t.Type() {
283 if (self.ip_index != .none) {
284 return null;
285 }
267 assert(self.ip_index == .none);
286268
287269 if (@enumToInt(self.legacy.tag_if_small_enough) < Tag.no_payload_count)
288270 return null;
......@@ -305,11 +287,6 @@ pub const Value = struct {
305287 .legacy = .{ .tag_if_small_enough = self.legacy.tag_if_small_enough },
306288 };
307289 } else switch (self.legacy.ptr_otherwise.tag) {
308 .single_const_pointer_to_comptime_int_type,
309 .const_slice_u8_type,
310 .const_slice_u8_sentinel_0_type,
311 .anyerror_void_error_union_type,
312
313290 .undef,
314291 .zero,
315292 .one,
......@@ -318,9 +295,6 @@ pub const Value = struct {
318295 .empty_array,
319296 .null_value,
320297 .empty_struct_value,
321 .manyptr_u8_type,
322 .manyptr_const_u8_type,
323 .manyptr_const_u8_sentinel_0_type,
324298 => unreachable,
325299
326300 .ty, .lazy_align, .lazy_size => {
......@@ -553,14 +527,6 @@ pub const Value = struct {
553527 }
554528 var val = start_val;
555529 while (true) switch (val.tag()) {
556 .single_const_pointer_to_comptime_int_type => return out_stream.writeAll("*const comptime_int"),
557 .const_slice_u8_type => return out_stream.writeAll("[]const u8"),
558 .const_slice_u8_sentinel_0_type => return out_stream.writeAll("[:0]const u8"),
559 .anyerror_void_error_union_type => return out_stream.writeAll("anyerror!void"),
560 .manyptr_u8_type => return out_stream.writeAll("[*]u8"),
561 .manyptr_const_u8_type => return out_stream.writeAll("[*]const u8"),
562 .manyptr_const_u8_sentinel_0_type => return out_stream.writeAll("[*:0]const u8"),
563
564530 .empty_struct_value => return out_stream.writeAll("struct {}{}"),
565531 .aggregate => {
566532 return out_stream.writeAll("(aggregate)");
......@@ -674,7 +640,7 @@ pub const Value = struct {
674640 switch (val.tag()) {
675641 .bytes => {
676642 const bytes = val.castTag(.bytes).?.data;
677 const adjusted_len = bytes.len - @boolToInt(ty.sentinel() != null);
643 const adjusted_len = bytes.len - @boolToInt(ty.sentinel(mod) != null);
678644 const adjusted_bytes = bytes[0..adjusted_len];
679645 return allocator.dupe(u8, adjusted_bytes);
680646 },
......@@ -686,7 +652,7 @@ pub const Value = struct {
686652 .enum_literal => return allocator.dupe(u8, val.castTag(.enum_literal).?.data),
687653 .repeated => {
688654 const byte = @intCast(u8, val.castTag(.repeated).?.data.toUnsignedInt(mod));
689 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen()));
655 const result = try allocator.alloc(u8, @intCast(usize, ty.arrayLen(mod)));
690656 @memset(result, byte);
691657 return result;
692658 },
......@@ -701,7 +667,7 @@ pub const Value = struct {
701667 const slice = val.castTag(.slice).?.data;
702668 return arrayToAllocatedBytes(slice.ptr, slice.len.toUnsignedInt(mod), allocator, mod);
703669 },
704 else => return arrayToAllocatedBytes(val, ty.arrayLen(), allocator, mod),
670 else => return arrayToAllocatedBytes(val, ty.arrayLen(mod), allocator, mod),
705671 }
706672 }
707673
......@@ -720,13 +686,6 @@ pub const Value = struct {
720686 if (self.ip_index != .none) return self.ip_index.toType();
721687 return switch (self.tag()) {
722688 .ty => self.castTag(.ty).?.data,
723 .single_const_pointer_to_comptime_int_type => Type.initTag(.single_const_pointer_to_comptime_int),
724 .const_slice_u8_type => Type.initTag(.const_slice_u8),
725 .const_slice_u8_sentinel_0_type => Type.initTag(.const_slice_u8_sentinel_0),
726 .anyerror_void_error_union_type => Type.initTag(.anyerror_void_error_union),
727 .manyptr_u8_type => Type.initTag(.manyptr_u8),
728 .manyptr_const_u8_type => Type.initTag(.manyptr_const_u8),
729 .manyptr_const_u8_sentinel_0_type => Type.initTag(.manyptr_const_u8_sentinel_0),
730689
731690 else => unreachable,
732691 };
......@@ -1096,8 +1055,8 @@ pub const Value = struct {
10961055 else => unreachable,
10971056 },
10981057 .Array => {
1099 const len = ty.arrayLen();
1100 const elem_ty = ty.childType();
1058 const len = ty.arrayLen(mod);
1059 const elem_ty = ty.childType(mod);
11011060 const elem_size = @intCast(usize, elem_ty.abiSize(mod));
11021061 var elem_i: usize = 0;
11031062 var elem_value_buf: ElemValueBuffer = undefined;
......@@ -1150,8 +1109,7 @@ pub const Value = struct {
11501109 },
11511110 .Optional => {
11521111 if (!ty.isPtrLikeOptional(mod)) return error.IllDefinedMemoryLayout;
1153 var buf: Type.Payload.ElemType = undefined;
1154 const child = ty.optionalChild(&buf);
1112 const child = ty.optionalChild(mod);
11551113 const opt_val = val.optionalValue(mod);
11561114 if (opt_val) |some| {
11571115 return some.writeToMemory(child, mod, buffer);
......@@ -1220,9 +1178,9 @@ pub const Value = struct {
12201178 else => unreachable,
12211179 },
12221180 .Vector => {
1223 const elem_ty = ty.childType();
1181 const elem_ty = ty.childType(mod);
12241182 const elem_bit_size = @intCast(u16, elem_ty.bitSize(mod));
1225 const len = @intCast(usize, ty.arrayLen());
1183 const len = @intCast(usize, ty.arrayLen(mod));
12261184
12271185 var bits: u16 = 0;
12281186 var elem_i: usize = 0;
......@@ -1267,8 +1225,7 @@ pub const Value = struct {
12671225 },
12681226 .Optional => {
12691227 assert(ty.isPtrLikeOptional(mod));
1270 var buf: Type.Payload.ElemType = undefined;
1271 const child = ty.optionalChild(&buf);
1228 const child = ty.optionalChild(mod);
12721229 const opt_val = val.optionalValue(mod);
12731230 if (opt_val) |some| {
12741231 return some.writeToPackedMemory(child, mod, buffer, bit_offset);
......@@ -1335,9 +1292,9 @@ pub const Value = struct {
13351292 else => unreachable,
13361293 },
13371294 .Array => {
1338 const elem_ty = ty.childType();
1295 const elem_ty = ty.childType(mod);
13391296 const elem_size = elem_ty.abiSize(mod);
1340 const elems = try arena.alloc(Value, @intCast(usize, ty.arrayLen()));
1297 const elems = try arena.alloc(Value, @intCast(usize, ty.arrayLen(mod)));
13411298 var offset: usize = 0;
13421299 for (elems) |*elem| {
13431300 elem.* = try readFromMemory(elem_ty, mod, buffer[offset..], arena);
......@@ -1386,8 +1343,7 @@ pub const Value = struct {
13861343 },
13871344 .Optional => {
13881345 assert(ty.isPtrLikeOptional(mod));
1389 var buf: Type.Payload.ElemType = undefined;
1390 const child = ty.optionalChild(&buf);
1346 const child = ty.optionalChild(mod);
13911347 return readFromMemory(child, mod, buffer, arena);
13921348 },
13931349 else => @panic("TODO implement readFromMemory for more types"),
......@@ -1449,8 +1405,8 @@ pub const Value = struct {
14491405 else => unreachable,
14501406 },
14511407 .Vector => {
1452 const elem_ty = ty.childType();
1453 const elems = try arena.alloc(Value, @intCast(usize, ty.arrayLen()));
1408 const elem_ty = ty.childType(mod);
1409 const elems = try arena.alloc(Value, @intCast(usize, ty.arrayLen(mod)));
14541410
14551411 var bits: u16 = 0;
14561412 const elem_bit_size = @intCast(u16, elem_ty.bitSize(mod));
......@@ -1483,8 +1439,7 @@ pub const Value = struct {
14831439 },
14841440 .Optional => {
14851441 assert(ty.isPtrLikeOptional(mod));
1486 var buf: Type.Payload.ElemType = undefined;
1487 const child = ty.optionalChild(&buf);
1442 const child = ty.optionalChild(mod);
14881443 return readFromPackedMemory(child, mod, buffer, bit_offset, arena);
14891444 },
14901445 else => @panic("TODO implement readFromPackedMemory for more types"),
......@@ -1956,7 +1911,7 @@ pub const Value = struct {
19561911 pub fn compareAll(lhs: Value, op: std.math.CompareOperator, rhs: Value, ty: Type, mod: *Module) bool {
19571912 if (ty.zigTypeTag(mod) == .Vector) {
19581913 var i: usize = 0;
1959 while (i < ty.vectorLen()) : (i += 1) {
1914 while (i < ty.vectorLen(mod)) : (i += 1) {
19601915 var lhs_buf: Value.ElemValueBuffer = undefined;
19611916 var rhs_buf: Value.ElemValueBuffer = undefined;
19621917 const lhs_elem = lhs.elemValueBuffer(mod, i, &lhs_buf);
......@@ -2092,8 +2047,7 @@ pub const Value = struct {
20922047 .opt_payload => {
20932048 const a_payload = a.castTag(.opt_payload).?.data;
20942049 const b_payload = b.castTag(.opt_payload).?.data;
2095 var buffer: Type.Payload.ElemType = undefined;
2096 const payload_ty = ty.optionalChild(&buffer);
2050 const payload_ty = ty.optionalChild(mod);
20972051 return eqlAdvanced(a_payload, payload_ty, b_payload, payload_ty, mod, opt_sema);
20982052 },
20992053 .slice => {
......@@ -2175,7 +2129,7 @@ pub const Value = struct {
21752129 return true;
21762130 }
21772131
2178 const elem_ty = ty.childType();
2132 const elem_ty = ty.childType(mod);
21792133 for (a_field_vals, 0..) |a_elem, i| {
21802134 const b_elem = b_field_vals[i];
21812135
......@@ -2239,8 +2193,8 @@ pub const Value = struct {
22392193 return eqlAdvanced(a_val, int_ty, b_val, int_ty, mod, opt_sema);
22402194 },
22412195 .Array, .Vector => {
2242 const len = ty.arrayLen();
2243 const elem_ty = ty.childType();
2196 const len = ty.arrayLen(mod);
2197 const elem_ty = ty.childType(mod);
22442198 var i: usize = 0;
22452199 var a_buf: ElemValueBuffer = undefined;
22462200 var b_buf: ElemValueBuffer = undefined;
......@@ -2253,11 +2207,11 @@ pub const Value = struct {
22532207 }
22542208 return true;
22552209 },
2256 .Pointer => switch (ty.ptrSize()) {
2210 .Pointer => switch (ty.ptrSize(mod)) {
22572211 .Slice => {
2258 const a_len = switch (a_ty.ptrSize()) {
2212 const a_len = switch (a_ty.ptrSize(mod)) {
22592213 .Slice => a.sliceLen(mod),
2260 .One => a_ty.childType().arrayLen(),
2214 .One => a_ty.childType(mod).arrayLen(mod),
22612215 else => unreachable,
22622216 };
22632217 if (a_len != b.sliceLen(mod)) {
......@@ -2266,7 +2220,7 @@ pub const Value = struct {
22662220
22672221 var ptr_buf: Type.SlicePtrFieldTypeBuffer = undefined;
22682222 const ptr_ty = ty.slicePtrFieldType(&ptr_buf);
2269 const a_ptr = switch (a_ty.ptrSize()) {
2223 const a_ptr = switch (a_ty.ptrSize(mod)) {
22702224 .Slice => a.slicePtr(),
22712225 .One => a,
22722226 else => unreachable,
......@@ -2412,8 +2366,8 @@ pub const Value = struct {
24122366 else => return hashPtr(val, hasher, mod),
24132367 },
24142368 .Array, .Vector => {
2415 const len = ty.arrayLen();
2416 const elem_ty = ty.childType();
2369 const len = ty.arrayLen(mod);
2370 const elem_ty = ty.childType(mod);
24172371 var index: usize = 0;
24182372 var elem_value_buf: ElemValueBuffer = undefined;
24192373 while (index < len) : (index += 1) {
......@@ -2438,8 +2392,7 @@ pub const Value = struct {
24382392 if (val.castTag(.opt_payload)) |payload| {
24392393 std.hash.autoHash(hasher, true); // non-null
24402394 const sub_val = payload.data;
2441 var buffer: Type.Payload.ElemType = undefined;
2442 const sub_ty = ty.optionalChild(&buffer);
2395 const sub_ty = ty.optionalChild(mod);
24432396 sub_val.hash(sub_ty, hasher, mod);
24442397 } else {
24452398 std.hash.autoHash(hasher, false); // null
......@@ -2534,8 +2487,8 @@ pub const Value = struct {
25342487 else => val.hashPtr(hasher, mod),
25352488 },
25362489 .Array, .Vector => {
2537 const len = ty.arrayLen();
2538 const elem_ty = ty.childType();
2490 const len = ty.arrayLen(mod);
2491 const elem_ty = ty.childType(mod);
25392492 var index: usize = 0;
25402493 var elem_value_buf: ElemValueBuffer = undefined;
25412494 while (index < len) : (index += 1) {
......@@ -2544,8 +2497,7 @@ pub const Value = struct {
25442497 }
25452498 },
25462499 .Optional => if (val.castTag(.opt_payload)) |payload| {
2547 var buf: Type.Payload.ElemType = undefined;
2548 const child_ty = ty.optionalChild(&buf);
2500 const child_ty = ty.optionalChild(mod);
25492501 payload.data.hashUncoerced(child_ty, hasher, mod);
25502502 } else std.hash.autoHash(hasher, std.builtin.TypeId.Null),
25512503 .ErrorSet, .ErrorUnion => if (val.getError()) |err| hasher.update(err) else {
......@@ -2720,7 +2672,7 @@ pub const Value = struct {
27202672 const decl_index = val.castTag(.decl_ref).?.data;
27212673 const decl = mod.declPtr(decl_index);
27222674 if (decl.ty.zigTypeTag(mod) == .Array) {
2723 return decl.ty.arrayLen();
2675 return decl.ty.arrayLen(mod);
27242676 } else {
27252677 return 1;
27262678 }
......@@ -2729,7 +2681,7 @@ pub const Value = struct {
27292681 const decl_index = val.castTag(.decl_ref_mut).?.data.decl_index;
27302682 const decl = mod.declPtr(decl_index);
27312683 if (decl.ty.zigTypeTag(mod) == .Array) {
2732 return decl.ty.arrayLen();
2684 return decl.ty.arrayLen(mod);
27332685 } else {
27342686 return 1;
27352687 }
......@@ -2737,7 +2689,7 @@ pub const Value = struct {
27372689 .comptime_field_ptr => {
27382690 const payload = val.castTag(.comptime_field_ptr).?.data;
27392691 if (payload.field_ty.zigTypeTag(mod) == .Array) {
2740 return payload.field_ty.arrayLen();
2692 return payload.field_ty.arrayLen(mod);
27412693 } else {
27422694 return 1;
27432695 }
......@@ -3137,7 +3089,7 @@ pub const Value = struct {
31373089
31383090 pub fn intToFloatAdvanced(val: Value, arena: Allocator, int_ty: Type, float_ty: Type, mod: *Module, opt_sema: ?*Sema) !Value {
31393091 if (int_ty.zigTypeTag(mod) == .Vector) {
3140 const result_data = try arena.alloc(Value, int_ty.vectorLen());
3092 const result_data = try arena.alloc(Value, int_ty.vectorLen(mod));
31413093 for (result_data, 0..) |*scalar, i| {
31423094 var buf: Value.ElemValueBuffer = undefined;
31433095 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -3250,7 +3202,7 @@ pub const Value = struct {
32503202 mod: *Module,
32513203 ) !Value {
32523204 if (ty.zigTypeTag(mod) == .Vector) {
3253 const result_data = try arena.alloc(Value, ty.vectorLen());
3205 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
32543206 for (result_data, 0..) |*scalar, i| {
32553207 var lhs_buf: Value.ElemValueBuffer = undefined;
32563208 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3298,7 +3250,7 @@ pub const Value = struct {
32983250 mod: *Module,
32993251 ) !Value {
33003252 if (ty.zigTypeTag(mod) == .Vector) {
3301 const result_data = try arena.alloc(Value, ty.vectorLen());
3253 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
33023254 for (result_data, 0..) |*scalar, i| {
33033255 var lhs_buf: Value.ElemValueBuffer = undefined;
33043256 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3345,8 +3297,8 @@ pub const Value = struct {
33453297 mod: *Module,
33463298 ) !OverflowArithmeticResult {
33473299 if (ty.zigTypeTag(mod) == .Vector) {
3348 const overflowed_data = try arena.alloc(Value, ty.vectorLen());
3349 const result_data = try arena.alloc(Value, ty.vectorLen());
3300 const overflowed_data = try arena.alloc(Value, ty.vectorLen(mod));
3301 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
33503302 for (result_data, 0..) |*scalar, i| {
33513303 var lhs_buf: Value.ElemValueBuffer = undefined;
33523304 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3408,7 +3360,7 @@ pub const Value = struct {
34083360 mod: *Module,
34093361 ) !Value {
34103362 if (ty.zigTypeTag(mod) == .Vector) {
3411 const result_data = try arena.alloc(Value, ty.vectorLen());
3363 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
34123364 for (result_data, 0..) |*scalar, i| {
34133365 var lhs_buf: Value.ElemValueBuffer = undefined;
34143366 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3452,7 +3404,7 @@ pub const Value = struct {
34523404 mod: *Module,
34533405 ) !Value {
34543406 if (ty.zigTypeTag(mod) == .Vector) {
3455 const result_data = try arena.alloc(Value, ty.vectorLen());
3407 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
34563408 for (result_data, 0..) |*scalar, i| {
34573409 var lhs_buf: Value.ElemValueBuffer = undefined;
34583410 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3527,7 +3479,7 @@ pub const Value = struct {
35273479 /// operands must be (vectors of) integers; handles undefined scalars.
35283480 pub fn bitwiseNot(val: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
35293481 if (ty.zigTypeTag(mod) == .Vector) {
3530 const result_data = try arena.alloc(Value, ty.vectorLen());
3482 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
35313483 for (result_data, 0..) |*scalar, i| {
35323484 var buf: Value.ElemValueBuffer = undefined;
35333485 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -3565,7 +3517,7 @@ pub const Value = struct {
35653517 /// operands must be (vectors of) integers; handles undefined scalars.
35663518 pub fn bitwiseAnd(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
35673519 if (ty.zigTypeTag(mod) == .Vector) {
3568 const result_data = try allocator.alloc(Value, ty.vectorLen());
3520 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
35693521 for (result_data, 0..) |*scalar, i| {
35703522 var lhs_buf: Value.ElemValueBuffer = undefined;
35713523 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3601,7 +3553,7 @@ pub const Value = struct {
36013553 /// operands must be (vectors of) integers; handles undefined scalars.
36023554 pub fn bitwiseNand(lhs: Value, rhs: Value, ty: Type, arena: Allocator, mod: *Module) !Value {
36033555 if (ty.zigTypeTag(mod) == .Vector) {
3604 const result_data = try arena.alloc(Value, ty.vectorLen());
3556 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
36053557 for (result_data, 0..) |*scalar, i| {
36063558 var lhs_buf: Value.ElemValueBuffer = undefined;
36073559 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3631,7 +3583,7 @@ pub const Value = struct {
36313583 /// operands must be (vectors of) integers; handles undefined scalars.
36323584 pub fn bitwiseOr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
36333585 if (ty.zigTypeTag(mod) == .Vector) {
3634 const result_data = try allocator.alloc(Value, ty.vectorLen());
3586 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
36353587 for (result_data, 0..) |*scalar, i| {
36363588 var lhs_buf: Value.ElemValueBuffer = undefined;
36373589 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3666,7 +3618,7 @@ pub const Value = struct {
36663618 /// operands must be (vectors of) integers; handles undefined scalars.
36673619 pub fn bitwiseXor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
36683620 if (ty.zigTypeTag(mod) == .Vector) {
3669 const result_data = try allocator.alloc(Value, ty.vectorLen());
3621 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
36703622 for (result_data, 0..) |*scalar, i| {
36713623 var lhs_buf: Value.ElemValueBuffer = undefined;
36723624 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3701,7 +3653,7 @@ pub const Value = struct {
37013653
37023654 pub fn intDiv(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
37033655 if (ty.zigTypeTag(mod) == .Vector) {
3704 const result_data = try allocator.alloc(Value, ty.vectorLen());
3656 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
37053657 for (result_data, 0..) |*scalar, i| {
37063658 var lhs_buf: Value.ElemValueBuffer = undefined;
37073659 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3741,7 +3693,7 @@ pub const Value = struct {
37413693
37423694 pub fn intDivFloor(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
37433695 if (ty.zigTypeTag(mod) == .Vector) {
3744 const result_data = try allocator.alloc(Value, ty.vectorLen());
3696 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
37453697 for (result_data, 0..) |*scalar, i| {
37463698 var lhs_buf: Value.ElemValueBuffer = undefined;
37473699 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3781,7 +3733,7 @@ pub const Value = struct {
37813733
37823734 pub fn intMod(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
37833735 if (ty.zigTypeTag(mod) == .Vector) {
3784 const result_data = try allocator.alloc(Value, ty.vectorLen());
3736 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
37853737 for (result_data, 0..) |*scalar, i| {
37863738 var lhs_buf: Value.ElemValueBuffer = undefined;
37873739 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3857,7 +3809,7 @@ pub const Value = struct {
38573809 pub fn floatRem(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
38583810 const target = mod.getTarget();
38593811 if (float_type.zigTypeTag(mod) == .Vector) {
3860 const result_data = try arena.alloc(Value, float_type.vectorLen());
3812 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
38613813 for (result_data, 0..) |*scalar, i| {
38623814 var lhs_buf: Value.ElemValueBuffer = undefined;
38633815 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3904,7 +3856,7 @@ pub const Value = struct {
39043856 pub fn floatMod(lhs: Value, rhs: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
39053857 const target = mod.getTarget();
39063858 if (float_type.zigTypeTag(mod) == .Vector) {
3907 const result_data = try arena.alloc(Value, float_type.vectorLen());
3859 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
39083860 for (result_data, 0..) |*scalar, i| {
39093861 var lhs_buf: Value.ElemValueBuffer = undefined;
39103862 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3950,7 +3902,7 @@ pub const Value = struct {
39503902
39513903 pub fn intMul(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
39523904 if (ty.zigTypeTag(mod) == .Vector) {
3953 const result_data = try allocator.alloc(Value, ty.vectorLen());
3905 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
39543906 for (result_data, 0..) |*scalar, i| {
39553907 var lhs_buf: Value.ElemValueBuffer = undefined;
39563908 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -3986,7 +3938,7 @@ pub const Value = struct {
39863938
39873939 pub fn intTrunc(val: Value, ty: Type, allocator: Allocator, signedness: std.builtin.Signedness, bits: u16, mod: *Module) !Value {
39883940 if (ty.zigTypeTag(mod) == .Vector) {
3989 const result_data = try allocator.alloc(Value, ty.vectorLen());
3941 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
39903942 for (result_data, 0..) |*scalar, i| {
39913943 var buf: Value.ElemValueBuffer = undefined;
39923944 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4007,7 +3959,7 @@ pub const Value = struct {
40073959 mod: *Module,
40083960 ) !Value {
40093961 if (ty.zigTypeTag(mod) == .Vector) {
4010 const result_data = try allocator.alloc(Value, ty.vectorLen());
3962 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
40113963 for (result_data, 0..) |*scalar, i| {
40123964 var buf: Value.ElemValueBuffer = undefined;
40133965 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4038,7 +3990,7 @@ pub const Value = struct {
40383990
40393991 pub fn shl(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
40403992 if (ty.zigTypeTag(mod) == .Vector) {
4041 const result_data = try allocator.alloc(Value, ty.vectorLen());
3993 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
40423994 for (result_data, 0..) |*scalar, i| {
40433995 var lhs_buf: Value.ElemValueBuffer = undefined;
40443996 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -4078,8 +4030,8 @@ pub const Value = struct {
40784030 mod: *Module,
40794031 ) !OverflowArithmeticResult {
40804032 if (ty.zigTypeTag(mod) == .Vector) {
4081 const overflowed_data = try allocator.alloc(Value, ty.vectorLen());
4082 const result_data = try allocator.alloc(Value, ty.vectorLen());
4033 const overflowed_data = try allocator.alloc(Value, ty.vectorLen(mod));
4034 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
40834035 for (result_data, 0..) |*scalar, i| {
40844036 var lhs_buf: Value.ElemValueBuffer = undefined;
40854037 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -4136,7 +4088,7 @@ pub const Value = struct {
41364088 mod: *Module,
41374089 ) !Value {
41384090 if (ty.zigTypeTag(mod) == .Vector) {
4139 const result_data = try arena.alloc(Value, ty.vectorLen());
4091 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
41404092 for (result_data, 0..) |*scalar, i| {
41414093 var lhs_buf: Value.ElemValueBuffer = undefined;
41424094 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -4184,7 +4136,7 @@ pub const Value = struct {
41844136 mod: *Module,
41854137 ) !Value {
41864138 if (ty.zigTypeTag(mod) == .Vector) {
4187 const result_data = try arena.alloc(Value, ty.vectorLen());
4139 const result_data = try arena.alloc(Value, ty.vectorLen(mod));
41884140 for (result_data, 0..) |*scalar, i| {
41894141 var lhs_buf: Value.ElemValueBuffer = undefined;
41904142 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -4212,7 +4164,7 @@ pub const Value = struct {
42124164
42134165 pub fn shr(lhs: Value, rhs: Value, ty: Type, allocator: Allocator, mod: *Module) !Value {
42144166 if (ty.zigTypeTag(mod) == .Vector) {
4215 const result_data = try allocator.alloc(Value, ty.vectorLen());
4167 const result_data = try allocator.alloc(Value, ty.vectorLen(mod));
42164168 for (result_data, 0..) |*scalar, i| {
42174169 var lhs_buf: Value.ElemValueBuffer = undefined;
42184170 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -4264,7 +4216,7 @@ pub const Value = struct {
42644216 ) !Value {
42654217 const target = mod.getTarget();
42664218 if (float_type.zigTypeTag(mod) == .Vector) {
4267 const result_data = try arena.alloc(Value, float_type.vectorLen());
4219 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
42684220 for (result_data, 0..) |*scalar, i| {
42694221 var buf: Value.ElemValueBuffer = undefined;
42704222 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4300,7 +4252,7 @@ pub const Value = struct {
43004252 ) !Value {
43014253 const target = mod.getTarget();
43024254 if (float_type.zigTypeTag(mod) == .Vector) {
4303 const result_data = try arena.alloc(Value, float_type.vectorLen());
4255 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
43044256 for (result_data, 0..) |*scalar, i| {
43054257 var lhs_buf: Value.ElemValueBuffer = undefined;
43064258 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -4359,7 +4311,7 @@ pub const Value = struct {
43594311 ) !Value {
43604312 const target = mod.getTarget();
43614313 if (float_type.zigTypeTag(mod) == .Vector) {
4362 const result_data = try arena.alloc(Value, float_type.vectorLen());
4314 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
43634315 for (result_data, 0..) |*scalar, i| {
43644316 var lhs_buf: Value.ElemValueBuffer = undefined;
43654317 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -4418,7 +4370,7 @@ pub const Value = struct {
44184370 ) !Value {
44194371 const target = mod.getTarget();
44204372 if (float_type.zigTypeTag(mod) == .Vector) {
4421 const result_data = try arena.alloc(Value, float_type.vectorLen());
4373 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
44224374 for (result_data, 0..) |*scalar, i| {
44234375 var lhs_buf: Value.ElemValueBuffer = undefined;
44244376 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -4477,7 +4429,7 @@ pub const Value = struct {
44774429 ) !Value {
44784430 const target = mod.getTarget();
44794431 if (float_type.zigTypeTag(mod) == .Vector) {
4480 const result_data = try arena.alloc(Value, float_type.vectorLen());
4432 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
44814433 for (result_data, 0..) |*scalar, i| {
44824434 var lhs_buf: Value.ElemValueBuffer = undefined;
44834435 var rhs_buf: Value.ElemValueBuffer = undefined;
......@@ -4530,7 +4482,7 @@ pub const Value = struct {
45304482 pub fn sqrt(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
45314483 const target = mod.getTarget();
45324484 if (float_type.zigTypeTag(mod) == .Vector) {
4533 const result_data = try arena.alloc(Value, float_type.vectorLen());
4485 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
45344486 for (result_data, 0..) |*scalar, i| {
45354487 var buf: Value.ElemValueBuffer = undefined;
45364488 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4570,7 +4522,7 @@ pub const Value = struct {
45704522 pub fn sin(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
45714523 const target = mod.getTarget();
45724524 if (float_type.zigTypeTag(mod) == .Vector) {
4573 const result_data = try arena.alloc(Value, float_type.vectorLen());
4525 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
45744526 for (result_data, 0..) |*scalar, i| {
45754527 var buf: Value.ElemValueBuffer = undefined;
45764528 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4610,7 +4562,7 @@ pub const Value = struct {
46104562 pub fn cos(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
46114563 const target = mod.getTarget();
46124564 if (float_type.zigTypeTag(mod) == .Vector) {
4613 const result_data = try arena.alloc(Value, float_type.vectorLen());
4565 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
46144566 for (result_data, 0..) |*scalar, i| {
46154567 var buf: Value.ElemValueBuffer = undefined;
46164568 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4650,7 +4602,7 @@ pub const Value = struct {
46504602 pub fn tan(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
46514603 const target = mod.getTarget();
46524604 if (float_type.zigTypeTag(mod) == .Vector) {
4653 const result_data = try arena.alloc(Value, float_type.vectorLen());
4605 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
46544606 for (result_data, 0..) |*scalar, i| {
46554607 var buf: Value.ElemValueBuffer = undefined;
46564608 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4690,7 +4642,7 @@ pub const Value = struct {
46904642 pub fn exp(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
46914643 const target = mod.getTarget();
46924644 if (float_type.zigTypeTag(mod) == .Vector) {
4693 const result_data = try arena.alloc(Value, float_type.vectorLen());
4645 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
46944646 for (result_data, 0..) |*scalar, i| {
46954647 var buf: Value.ElemValueBuffer = undefined;
46964648 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4730,7 +4682,7 @@ pub const Value = struct {
47304682 pub fn exp2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
47314683 const target = mod.getTarget();
47324684 if (float_type.zigTypeTag(mod) == .Vector) {
4733 const result_data = try arena.alloc(Value, float_type.vectorLen());
4685 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
47344686 for (result_data, 0..) |*scalar, i| {
47354687 var buf: Value.ElemValueBuffer = undefined;
47364688 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4770,7 +4722,7 @@ pub const Value = struct {
47704722 pub fn log(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
47714723 const target = mod.getTarget();
47724724 if (float_type.zigTypeTag(mod) == .Vector) {
4773 const result_data = try arena.alloc(Value, float_type.vectorLen());
4725 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
47744726 for (result_data, 0..) |*scalar, i| {
47754727 var buf: Value.ElemValueBuffer = undefined;
47764728 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4810,7 +4762,7 @@ pub const Value = struct {
48104762 pub fn log2(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
48114763 const target = mod.getTarget();
48124764 if (float_type.zigTypeTag(mod) == .Vector) {
4813 const result_data = try arena.alloc(Value, float_type.vectorLen());
4765 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
48144766 for (result_data, 0..) |*scalar, i| {
48154767 var buf: Value.ElemValueBuffer = undefined;
48164768 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4850,7 +4802,7 @@ pub const Value = struct {
48504802 pub fn log10(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
48514803 const target = mod.getTarget();
48524804 if (float_type.zigTypeTag(mod) == .Vector) {
4853 const result_data = try arena.alloc(Value, float_type.vectorLen());
4805 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
48544806 for (result_data, 0..) |*scalar, i| {
48554807 var buf: Value.ElemValueBuffer = undefined;
48564808 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4890,7 +4842,7 @@ pub const Value = struct {
48904842 pub fn fabs(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
48914843 const target = mod.getTarget();
48924844 if (float_type.zigTypeTag(mod) == .Vector) {
4893 const result_data = try arena.alloc(Value, float_type.vectorLen());
4845 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
48944846 for (result_data, 0..) |*scalar, i| {
48954847 var buf: Value.ElemValueBuffer = undefined;
48964848 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4930,7 +4882,7 @@ pub const Value = struct {
49304882 pub fn floor(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
49314883 const target = mod.getTarget();
49324884 if (float_type.zigTypeTag(mod) == .Vector) {
4933 const result_data = try arena.alloc(Value, float_type.vectorLen());
4885 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
49344886 for (result_data, 0..) |*scalar, i| {
49354887 var buf: Value.ElemValueBuffer = undefined;
49364888 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -4970,7 +4922,7 @@ pub const Value = struct {
49704922 pub fn ceil(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
49714923 const target = mod.getTarget();
49724924 if (float_type.zigTypeTag(mod) == .Vector) {
4973 const result_data = try arena.alloc(Value, float_type.vectorLen());
4925 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
49744926 for (result_data, 0..) |*scalar, i| {
49754927 var buf: Value.ElemValueBuffer = undefined;
49764928 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -5010,7 +4962,7 @@ pub const Value = struct {
50104962 pub fn round(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
50114963 const target = mod.getTarget();
50124964 if (float_type.zigTypeTag(mod) == .Vector) {
5013 const result_data = try arena.alloc(Value, float_type.vectorLen());
4965 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
50144966 for (result_data, 0..) |*scalar, i| {
50154967 var buf: Value.ElemValueBuffer = undefined;
50164968 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -5050,7 +5002,7 @@ pub const Value = struct {
50505002 pub fn trunc(val: Value, float_type: Type, arena: Allocator, mod: *Module) !Value {
50515003 const target = mod.getTarget();
50525004 if (float_type.zigTypeTag(mod) == .Vector) {
5053 const result_data = try arena.alloc(Value, float_type.vectorLen());
5005 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
50545006 for (result_data, 0..) |*scalar, i| {
50555007 var buf: Value.ElemValueBuffer = undefined;
50565008 const elem_val = val.elemValueBuffer(mod, i, &buf);
......@@ -5097,7 +5049,7 @@ pub const Value = struct {
50975049 ) !Value {
50985050 const target = mod.getTarget();
50995051 if (float_type.zigTypeTag(mod) == .Vector) {
5100 const result_data = try arena.alloc(Value, float_type.vectorLen());
5052 const result_data = try arena.alloc(Value, float_type.vectorLen(mod));
51015053 for (result_data, 0..) |*scalar, i| {
51025054 var mulend1_buf: Value.ElemValueBuffer = undefined;
51035055 const mulend1_elem = mulend1.elemValueBuffer(mod, i, &mulend1_buf);