authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-20 17:57:18-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-21 14:48:40-07:00
logd06bf707ed374ca42a580ee7acf1cecaab078d0d
tree09056238283ef9041bb2e3389d59522664088f76
parent51b1a2a6cb1a48260a37c407adbb4b796cf58a54

compiler: make pointer type canonicalization always work

Previously it would canonicalize or not depending on some volatile internal state of the compiler, now it forces resolution of the element type to determine the alignment if it needs to.

2 files changed, 79 insertions(+), 73 deletions(-)

src/Module.zig+2-3
...@@ -5937,7 +5937,6 @@ pub fn optionalType(mod: *Module, child_type: InternPool.Index) Allocator.Error!...@@ -5937,7 +5937,6 @@ pub fn optionalType(mod: *Module, child_type: InternPool.Index) Allocator.Error!
59375937
5938pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type {5938pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type {
5939 var canon_info = info;5939 var canon_info = info;
5940 const have_elem_layout = info.child.toType().layoutIsResolved(mod);
59415940
5942 if (info.flags.size == .C) canon_info.flags.is_allowzero = true;5941 if (info.flags.size == .C) canon_info.flags.is_allowzero = true;
59435942
...@@ -5945,7 +5944,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type...@@ -5945,7 +5944,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
5945 // type, we change it to 0 here. If this causes an assertion trip because the5944 // type, we change it to 0 here. If this causes an assertion trip because the
5946 // pointee type needs to be resolved more, that needs to be done before calling5945 // pointee type needs to be resolved more, that needs to be done before calling
5947 // this ptr() function.5946 // this ptr() function.
5948 if (info.flags.alignment != .none and have_elem_layout and5947 if (info.flags.alignment != .none and
5949 info.flags.alignment == info.child.toType().abiAlignment(mod))5948 info.flags.alignment == info.child.toType().abiAlignment(mod))
5950 {5949 {
5951 canon_info.flags.alignment = .none;5950 canon_info.flags.alignment = .none;
...@@ -5955,7 +5954,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type...@@ -5955,7 +5954,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
5955 // Canonicalize host_size. If it matches the bit size of the pointee type,5954 // Canonicalize host_size. If it matches the bit size of the pointee type,
5956 // we change it to 0 here. If this causes an assertion trip, the pointee type5955 // we change it to 0 here. If this causes an assertion trip, the pointee type
5957 // needs to be resolved before calling this ptr() function.5956 // needs to be resolved before calling this ptr() function.
5958 .none => if (have_elem_layout and info.packed_offset.host_size != 0) {5957 .none => if (info.packed_offset.host_size != 0) {
5959 const elem_bit_size = info.child.toType().bitSize(mod);5958 const elem_bit_size = info.child.toType().bitSize(mod);
5960 assert(info.packed_offset.bit_offset + elem_bit_size <= info.packed_offset.host_size * 8);5959 assert(info.packed_offset.bit_offset + elem_bit_size <= info.packed_offset.host_size * 8);
5961 if (info.packed_offset.host_size * 8 == elem_bit_size) {5960 if (info.packed_offset.host_size * 8 == elem_bit_size) {
src/Sema.zig+77-70
...@@ -2629,7 +2629,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -2629,7 +2629,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
2629 defer trash_block.instructions.deinit(sema.gpa);2629 defer trash_block.instructions.deinit(sema.gpa);
2630 const operand = try trash_block.addBitCast(pointee_ty, .void_value);2630 const operand = try trash_block.addBitCast(pointee_ty, .void_value);
26312631
2632 const ptr_ty = try mod.ptrType(.{2632 const ptr_ty = try sema.ptrType(.{
2633 .child = pointee_ty.toIntern(),2633 .child = pointee_ty.toIntern(),
2634 .flags = .{2634 .flags = .{
2635 .alignment = ia1.alignment,2635 .alignment = ia1.alignment,
...@@ -2660,7 +2660,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE...@@ -2660,7 +2660,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
2660 if (alignment != .none) {2660 if (alignment != .none) {
2661 try sema.resolveTypeLayout(pointee_ty);2661 try sema.resolveTypeLayout(pointee_ty);
2662 }2662 }
2663 const ptr_ty = try mod.ptrType(.{2663 const ptr_ty = try sema.ptrType(.{
2664 .child = pointee_ty.toIntern(),2664 .child = pointee_ty.toIntern(),
2665 .flags = .{2665 .flags = .{
2666 .alignment = alignment,2666 .alignment = alignment,
...@@ -2730,7 +2730,7 @@ fn coerceResultPtr(...@@ -2730,7 +2730,7 @@ fn coerceResultPtr(
2730 }2730 }
2731 }2731 }
27322732
2733 const ptr_ty = try mod.ptrType(.{2733 const ptr_ty = try sema.ptrType(.{
2734 .child = pointee_ty.toIntern(),2734 .child = pointee_ty.toIntern(),
2735 .flags = .{ .address_space = addr_space },2735 .flags = .{ .address_space = addr_space },
2736 });2736 });
...@@ -2759,7 +2759,7 @@ fn coerceResultPtr(...@@ -2759,7 +2759,7 @@ fn coerceResultPtr(
2759 // Array coerced to Vector where element size is not equal but coercible.2759 // Array coerced to Vector where element size is not equal but coercible.
2760 .aggregate_init => {2760 .aggregate_init => {
2761 const ty_pl = air_datas[trash_inst].ty_pl;2761 const ty_pl = air_datas[trash_inst].ty_pl;
2762 const ptr_operand_ty = try mod.ptrType(.{2762 const ptr_operand_ty = try sema.ptrType(.{
2763 .child = (try sema.analyzeAsType(block, src, ty_pl.ty)).toIntern(),2763 .child = (try sema.analyzeAsType(block, src, ty_pl.ty)).toIntern(),
2764 .flags = .{ .address_space = addr_space },2764 .flags = .{ .address_space = addr_space },
2765 });2765 });
...@@ -2773,7 +2773,7 @@ fn coerceResultPtr(...@@ -2773,7 +2773,7 @@ fn coerceResultPtr(
2773 .bitcast => {2773 .bitcast => {
2774 const ty_op = air_datas[trash_inst].ty_op;2774 const ty_op = air_datas[trash_inst].ty_op;
2775 const operand_ty = sema.typeOf(ty_op.operand);2775 const operand_ty = sema.typeOf(ty_op.operand);
2776 const ptr_operand_ty = try mod.ptrType(.{2776 const ptr_operand_ty = try sema.ptrType(.{
2777 .child = operand_ty.toIntern(),2777 .child = operand_ty.toIntern(),
2778 .flags = .{ .address_space = addr_space },2778 .flags = .{ .address_space = addr_space },
2779 });2779 });
...@@ -3508,7 +3508,7 @@ fn zirRetPtr(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {...@@ -3508,7 +3508,7 @@ fn zirRetPtr(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
3508 }3508 }
35093509
3510 const target = sema.mod.getTarget();3510 const target = sema.mod.getTarget();
3511 const ptr_type = try sema.mod.ptrType(.{3511 const ptr_type = try sema.ptrType(.{
3512 .child = sema.fn_ret_ty.toIntern(),3512 .child = sema.fn_ret_ty.toIntern(),
3513 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },3513 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
3514 });3514 });
...@@ -3711,7 +3711,7 @@ fn zirAllocExtended(...@@ -3711,7 +3711,7 @@ fn zirAllocExtended(
3711 }3711 }
3712 const target = sema.mod.getTarget();3712 const target = sema.mod.getTarget();
3713 try sema.resolveTypeLayout(var_ty);3713 try sema.resolveTypeLayout(var_ty);
3714 const ptr_type = try sema.mod.ptrType(.{3714 const ptr_type = try sema.ptrType(.{
3715 .child = var_ty.toIntern(),3715 .child = var_ty.toIntern(),
3716 .flags = .{3716 .flags = .{
3717 .alignment = alignment,3717 .alignment = alignment,
...@@ -3820,7 +3820,7 @@ fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Ai...@@ -3820,7 +3820,7 @@ fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Ai
38203820
3821 var ptr_info = alloc_ty.ptrInfo(mod);3821 var ptr_info = alloc_ty.ptrInfo(mod);
3822 ptr_info.flags.is_const = true;3822 ptr_info.flags.is_const = true;
3823 const const_ptr_ty = try mod.ptrType(ptr_info);3823 const const_ptr_ty = try sema.ptrType(ptr_info);
38243824
3825 // Detect if a comptime value simply needs to have its type changed.3825 // Detect if a comptime value simply needs to have its type changed.
3826 if (try sema.resolveMaybeUndefVal(alloc)) |val| {3826 if (try sema.resolveMaybeUndefVal(alloc)) |val| {
...@@ -3862,7 +3862,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I...@@ -3862,7 +3862,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
3862 return sema.analyzeComptimeAlloc(block, var_ty, .none);3862 return sema.analyzeComptimeAlloc(block, var_ty, .none);
3863 }3863 }
3864 const target = sema.mod.getTarget();3864 const target = sema.mod.getTarget();
3865 const ptr_type = try sema.mod.ptrType(.{3865 const ptr_type = try sema.ptrType(.{
3866 .child = var_ty.toIntern(),3866 .child = var_ty.toIntern(),
3867 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },3867 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
3868 });3868 });
...@@ -3882,7 +3882,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -3882,7 +3882,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
3882 }3882 }
3883 try sema.validateVarType(block, ty_src, var_ty, false);3883 try sema.validateVarType(block, ty_src, var_ty, false);
3884 const target = sema.mod.getTarget();3884 const target = sema.mod.getTarget();
3885 const ptr_type = try sema.mod.ptrType(.{3885 const ptr_type = try sema.ptrType(.{
3886 .child = var_ty.toIntern(),3886 .child = var_ty.toIntern(),
3887 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },3887 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
3888 });3888 });
...@@ -3948,7 +3948,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3948,7 +3948,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
3948 const decl = mod.declPtr(decl_index);3948 const decl = mod.declPtr(decl_index);
3949 if (iac.is_const) _ = try decl.internValue(mod);3949 if (iac.is_const) _ = try decl.internValue(mod);
3950 const final_elem_ty = decl.ty;3950 const final_elem_ty = decl.ty;
3951 const final_ptr_ty = try mod.ptrType(.{3951 const final_ptr_ty = try sema.ptrType(.{
3952 .child = final_elem_ty.toIntern(),3952 .child = final_elem_ty.toIntern(),
3953 .flags = .{3953 .flags = .{
3954 .is_const = false,3954 .is_const = false,
...@@ -3981,7 +3981,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -3981,7 +3981,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
3981 const peer_inst_list = ia2.prongs.items(.stored_inst);3981 const peer_inst_list = ia2.prongs.items(.stored_inst);
3982 const final_elem_ty = try sema.resolvePeerTypes(block, ty_src, peer_inst_list, .none);3982 const final_elem_ty = try sema.resolvePeerTypes(block, ty_src, peer_inst_list, .none);
39833983
3984 const final_ptr_ty = try mod.ptrType(.{3984 const final_ptr_ty = try sema.ptrType(.{
3985 .child = final_elem_ty.toIntern(),3985 .child = final_elem_ty.toIntern(),
3986 .flags = .{3986 .flags = .{
3987 .alignment = ia1.alignment,3987 .alignment = ia1.alignment,
...@@ -4103,7 +4103,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com...@@ -4103,7 +4103,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
4103 trash_block.is_comptime = false;4103 trash_block.is_comptime = false;
4104 defer trash_block.instructions.deinit(gpa);4104 defer trash_block.instructions.deinit(gpa);
41054105
4106 const mut_final_ptr_ty = try mod.ptrType(.{4106 const mut_final_ptr_ty = try sema.ptrType(.{
4107 .child = final_elem_ty.toIntern(),4107 .child = final_elem_ty.toIntern(),
4108 .flags = .{4108 .flags = .{
4109 .alignment = ia1.alignment,4109 .alignment = ia1.alignment,
...@@ -8650,7 +8650,7 @@ fn analyzeOptionalPayloadPtr(...@@ -8650,7 +8650,7 @@ fn analyzeOptionalPayloadPtr(
8650 }8650 }
86518651
8652 const child_type = opt_type.optionalChild(mod);8652 const child_type = opt_type.optionalChild(mod);
8653 const child_pointer = try mod.ptrType(.{8653 const child_pointer = try sema.ptrType(.{
8654 .child = child_type.toIntern(),8654 .child = child_type.toIntern(),
8655 .flags = .{8655 .flags = .{
8656 .is_const = optional_ptr_ty.isConstPtr(mod),8656 .is_const = optional_ptr_ty.isConstPtr(mod),
...@@ -8719,7 +8719,7 @@ fn zirOptionalPayload(...@@ -8719,7 +8719,7 @@ fn zirOptionalPayload(
8719 // TODO https://github.com/ziglang/zig/issues/65978719 // TODO https://github.com/ziglang/zig/issues/6597
8720 if (true) break :t operand_ty;8720 if (true) break :t operand_ty;
8721 const ptr_info = operand_ty.ptrInfo(mod);8721 const ptr_info = operand_ty.ptrInfo(mod);
8722 break :t try mod.ptrType(.{8722 break :t try sema.ptrType(.{
8723 .child = ptr_info.child,8723 .child = ptr_info.child,
8724 .flags = .{8724 .flags = .{
8725 .alignment = ptr_info.flags.alignment,8725 .alignment = ptr_info.flags.alignment,
...@@ -8837,7 +8837,7 @@ fn analyzeErrUnionPayloadPtr(...@@ -8837,7 +8837,7 @@ fn analyzeErrUnionPayloadPtr(
88378837
8838 const err_union_ty = operand_ty.childType(mod);8838 const err_union_ty = operand_ty.childType(mod);
8839 const payload_ty = err_union_ty.errorUnionPayload(mod);8839 const payload_ty = err_union_ty.errorUnionPayload(mod);
8840 const operand_pointer_ty = try mod.ptrType(.{8840 const operand_pointer_ty = try sema.ptrType(.{
8841 .child = payload_ty.toIntern(),8841 .child = payload_ty.toIntern(),
8842 .flags = .{8842 .flags = .{
8843 .is_const = operand_ty.isConstPtr(mod),8843 .is_const = operand_ty.isConstPtr(mod),
...@@ -10692,7 +10692,7 @@ const SwitchProngAnalysis = struct {...@@ -10692,7 +10692,7 @@ const SwitchProngAnalysis = struct {
10692 const union_obj = mod.typeToUnion(operand_ty).?;10692 const union_obj = mod.typeToUnion(operand_ty).?;
10693 const field_ty = union_obj.field_types.get(ip)[field_index].toType();10693 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
10694 if (capture_byref) {10694 if (capture_byref) {
10695 const ptr_field_ty = try mod.ptrType(.{10695 const ptr_field_ty = try sema.ptrType(.{
10696 .child = field_ty.toIntern(),10696 .child = field_ty.toIntern(),
10697 .flags = .{10697 .flags = .{
10698 .is_const = !operand_ptr_ty.ptrIsMutable(mod),10698 .is_const = !operand_ptr_ty.ptrIsMutable(mod),
...@@ -10798,7 +10798,7 @@ const SwitchProngAnalysis = struct {...@@ -10798,7 +10798,7 @@ const SwitchProngAnalysis = struct {
10798 // By-reference captures have some further restrictions which make them easier to emit10798 // By-reference captures have some further restrictions which make them easier to emit
10799 if (capture_byref) {10799 if (capture_byref) {
10800 const operand_ptr_info = operand_ptr_ty.ptrInfo(mod);10800 const operand_ptr_info = operand_ptr_ty.ptrInfo(mod);
10801 const capture_ptr_ty = try mod.ptrType(.{10801 const capture_ptr_ty = try sema.ptrType(.{
10802 .child = capture_ty.toIntern(),10802 .child = capture_ty.toIntern(),
10803 .flags = .{10803 .flags = .{
10804 // TODO: alignment!10804 // TODO: alignment!
...@@ -10812,7 +10812,7 @@ const SwitchProngAnalysis = struct {...@@ -10812,7 +10812,7 @@ const SwitchProngAnalysis = struct {
10812 // pointer type is in-memory coercible to the capture pointer type.10812 // pointer type is in-memory coercible to the capture pointer type.
10813 if (!same_types) {10813 if (!same_types) {
10814 for (field_tys, 0..) |field_ty, i| {10814 for (field_tys, 0..) |field_ty, i| {
10815 const field_ptr_ty = try mod.ptrType(.{10815 const field_ptr_ty = try sema.ptrType(.{
10816 .child = field_ty.toIntern(),10816 .child = field_ty.toIntern(),
10817 .flags = .{10817 .flags = .{
10818 // TODO: alignment!10818 // TODO: alignment!
...@@ -13776,12 +13776,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -13776,12 +13776,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
13776 try sema.requireRuntimeBlock(block, src, runtime_src);13776 try sema.requireRuntimeBlock(block, src, runtime_src);
1377713777
13778 if (ptr_addrspace) |ptr_as| {13778 if (ptr_addrspace) |ptr_as| {
13779 const alloc_ty = try mod.ptrType(.{13779 const alloc_ty = try sema.ptrType(.{
13780 .child = result_ty.toIntern(),13780 .child = result_ty.toIntern(),
13781 .flags = .{ .address_space = ptr_as },13781 .flags = .{ .address_space = ptr_as },
13782 });13782 });
13783 const alloc = try block.addTy(.alloc, alloc_ty);13783 const alloc = try block.addTy(.alloc, alloc_ty);
13784 const elem_ptr_ty = try mod.ptrType(.{13784 const elem_ptr_ty = try sema.ptrType(.{
13785 .child = resolved_elem_ty.toIntern(),13785 .child = resolved_elem_ty.toIntern(),
13786 .flags = .{ .address_space = ptr_as },13786 .flags = .{ .address_space = ptr_as },
13787 });13787 });
...@@ -14041,12 +14041,12 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -14041,12 +14041,12 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
14041 try sema.requireRuntimeBlock(block, src, lhs_src);14041 try sema.requireRuntimeBlock(block, src, lhs_src);
1404214042
14043 if (ptr_addrspace) |ptr_as| {14043 if (ptr_addrspace) |ptr_as| {
14044 const alloc_ty = try mod.ptrType(.{14044 const alloc_ty = try sema.ptrType(.{
14045 .child = result_ty.toIntern(),14045 .child = result_ty.toIntern(),
14046 .flags = .{ .address_space = ptr_as },14046 .flags = .{ .address_space = ptr_as },
14047 });14047 });
14048 const alloc = try block.addTy(.alloc, alloc_ty);14048 const alloc = try block.addTy(.alloc, alloc_ty);
14049 const elem_ptr_ty = try mod.ptrType(.{14049 const elem_ptr_ty = try sema.ptrType(.{
14050 .child = lhs_info.elem_type.toIntern(),14050 .child = lhs_info.elem_type.toIntern(),
14051 .flags = .{ .address_space = ptr_as },14051 .flags = .{ .address_space = ptr_as },
14052 });14052 });
...@@ -15988,7 +15988,7 @@ fn analyzePtrArithmetic(...@@ -15988,7 +15988,7 @@ fn analyzePtrArithmetic(
15988 ));15988 ));
15989 assert(new_align != .none);15989 assert(new_align != .none);
1599015990
15991 break :t try mod.ptrType(.{15991 break :t try sema.ptrType(.{
15992 .child = ptr_info.child,15992 .child = ptr_info.child,
15993 .sentinel = ptr_info.sentinel,15993 .sentinel = ptr_info.sentinel,
15994 .flags = .{15994 .flags = .{
...@@ -16891,7 +16891,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -16891,7 +16891,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
16891 .none, // default alignment16891 .none, // default alignment
16892 );16892 );
16893 break :v try mod.intern(.{ .ptr = .{16893 break :v try mod.intern(.{ .ptr = .{
16894 .ty = (try mod.ptrType(.{16894 .ty = (try sema.ptrType(.{
16895 .child = param_info_ty.toIntern(),16895 .child = param_info_ty.toIntern(),
16896 .flags = .{16896 .flags = .{
16897 .size = .Slice,16897 .size = .Slice,
...@@ -17210,7 +17210,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17210,7 +17210,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17210 };17210 };
1721117211
17212 // Build our ?[]const Error value17212 // Build our ?[]const Error value
17213 const slice_errors_ty = try mod.ptrType(.{17213 const slice_errors_ty = try sema.ptrType(.{
17214 .child = error_field_ty.toIntern(),17214 .child = error_field_ty.toIntern(),
17215 .flags = .{17215 .flags = .{
17216 .size = .Slice,17216 .size = .Slice,
...@@ -17359,7 +17359,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17359,7 +17359,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17359 .none, // default alignment17359 .none, // default alignment
17360 );17360 );
17361 break :v try mod.intern(.{ .ptr = .{17361 break :v try mod.intern(.{ .ptr = .{
17362 .ty = (try mod.ptrType(.{17362 .ty = (try sema.ptrType(.{
17363 .child = enum_field_ty.toIntern(),17363 .child = enum_field_ty.toIntern(),
17364 .flags = .{17364 .flags = .{
17365 .size = .Slice,17365 .size = .Slice,
...@@ -17503,7 +17503,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17503,7 +17503,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17503 .none, // default alignment17503 .none, // default alignment
17504 );17504 );
17505 break :v try mod.intern(.{ .ptr = .{17505 break :v try mod.intern(.{ .ptr = .{
17506 .ty = (try mod.ptrType(.{17506 .ty = (try sema.ptrType(.{
17507 .child = union_field_ty.toIntern(),17507 .child = union_field_ty.toIntern(),
17508 .flags = .{17508 .flags = .{
17509 .size = .Slice,17509 .size = .Slice,
...@@ -17731,7 +17731,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -17731,7 +17731,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
17731 .none, // default alignment17731 .none, // default alignment
17732 );17732 );
17733 break :v try mod.intern(.{ .ptr = .{17733 break :v try mod.intern(.{ .ptr = .{
17734 .ty = (try mod.ptrType(.{17734 .ty = (try sema.ptrType(.{
17735 .child = struct_field_ty.toIntern(),17735 .child = struct_field_ty.toIntern(),
17736 .flags = .{17736 .flags = .{
17737 .size = .Slice,17737 .size = .Slice,
...@@ -17877,7 +17877,7 @@ fn typeInfoDecls(...@@ -17877,7 +17877,7 @@ fn typeInfoDecls(
17877 .none, // default alignment17877 .none, // default alignment
17878 );17878 );
17879 return try mod.intern(.{ .ptr = .{17879 return try mod.intern(.{ .ptr = .{
17880 .ty = (try mod.ptrType(.{17880 .ty = (try sema.ptrType(.{
17881 .child = declaration_ty.toIntern(),17881 .child = declaration_ty.toIntern(),
17882 .flags = .{17882 .flags = .{
17883 .size = .Slice,17883 .size = .Slice,
...@@ -18447,7 +18447,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr...@@ -18447,7 +18447,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1844718447
18448 const operand_ty = sema.typeOf(operand);18448 const operand_ty = sema.typeOf(operand);
18449 const ptr_info = operand_ty.ptrInfo(mod);18449 const ptr_info = operand_ty.ptrInfo(mod);
18450 const res_ty = try mod.ptrType(.{18450 const res_ty = try sema.ptrType(.{
18451 .child = err_union_ty.errorUnionPayload(mod).toIntern(),18451 .child = err_union_ty.errorUnionPayload(mod).toIntern(),
18452 .flags = .{18452 .flags = .{
18453 .is_const = ptr_info.flags.is_const,18453 .is_const = ptr_info.flags.is_const,
...@@ -19001,7 +19001,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air...@@ -19001,7 +19001,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
19001 }19001 }
19002 }19002 }
1900319003
19004 const ty = try mod.ptrType(.{19004 const ty = try sema.ptrType(.{
19005 .child = elem_ty.toIntern(),19005 .child = elem_ty.toIntern(),
19006 .sentinel = sentinel,19006 .sentinel = sentinel,
19007 .flags = .{19007 .flags = .{
...@@ -19239,7 +19239,7 @@ fn zirStructInit(...@@ -19239,7 +19239,7 @@ fn zirStructInit(
1923919239
19240 if (is_ref) {19240 if (is_ref) {
19241 const target = mod.getTarget();19241 const target = mod.getTarget();
19242 const alloc_ty = try mod.ptrType(.{19242 const alloc_ty = try sema.ptrType(.{
19243 .child = resolved_ty.toIntern(),19243 .child = resolved_ty.toIntern(),
19244 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },19244 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
19245 });19245 });
...@@ -19363,7 +19363,7 @@ fn finishStructInit(...@@ -19363,7 +19363,7 @@ fn finishStructInit(
19363 if (is_ref) {19363 if (is_ref) {
19364 try sema.resolveStructLayout(struct_ty);19364 try sema.resolveStructLayout(struct_ty);
19365 const target = sema.mod.getTarget();19365 const target = sema.mod.getTarget();
19366 const alloc_ty = try mod.ptrType(.{19366 const alloc_ty = try sema.ptrType(.{
19367 .child = struct_ty.toIntern(),19367 .child = struct_ty.toIntern(),
19368 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },19368 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
19369 });19369 });
...@@ -19516,7 +19516,7 @@ fn structInitAnon(...@@ -19516,7 +19516,7 @@ fn structInitAnon(
1951619516
19517 if (is_ref) {19517 if (is_ref) {
19518 const target = mod.getTarget();19518 const target = mod.getTarget();
19519 const alloc_ty = try mod.ptrType(.{19519 const alloc_ty = try sema.ptrType(.{
19520 .child = tuple_ty,19520 .child = tuple_ty,
19521 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },19521 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
19522 });19522 });
...@@ -19530,7 +19530,7 @@ fn structInitAnon(...@@ -19530,7 +19530,7 @@ fn structInitAnon(
19530 };19530 };
19531 extra_index = item.end;19531 extra_index = item.end;
1953219532
19533 const field_ptr_ty = try mod.ptrType(.{19533 const field_ptr_ty = try sema.ptrType(.{
19534 .child = field_ty,19534 .child = field_ty,
19535 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },19535 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
19536 });19536 });
...@@ -19654,7 +19654,7 @@ fn zirArrayInit(...@@ -19654,7 +19654,7 @@ fn zirArrayInit(
1965419654
19655 if (is_ref) {19655 if (is_ref) {
19656 const target = mod.getTarget();19656 const target = mod.getTarget();
19657 const alloc_ty = try mod.ptrType(.{19657 const alloc_ty = try sema.ptrType(.{
19658 .child = array_ty.toIntern(),19658 .child = array_ty.toIntern(),
19659 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },19659 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
19660 });19660 });
...@@ -19662,7 +19662,7 @@ fn zirArrayInit(...@@ -19662,7 +19662,7 @@ fn zirArrayInit(
1966219662
19663 if (array_ty.isTuple(mod)) {19663 if (array_ty.isTuple(mod)) {
19664 for (resolved_args, 0..) |arg, i| {19664 for (resolved_args, 0..) |arg, i| {
19665 const elem_ptr_ty = try mod.ptrType(.{19665 const elem_ptr_ty = try sema.ptrType(.{
19666 .child = array_ty.structFieldType(i, mod).toIntern(),19666 .child = array_ty.structFieldType(i, mod).toIntern(),
19667 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },19667 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
19668 });19668 });
...@@ -19675,7 +19675,7 @@ fn zirArrayInit(...@@ -19675,7 +19675,7 @@ fn zirArrayInit(
19675 return sema.makePtrConst(block, alloc);19675 return sema.makePtrConst(block, alloc);
19676 }19676 }
1967719677
19678 const elem_ptr_ty = try mod.ptrType(.{19678 const elem_ptr_ty = try sema.ptrType(.{
19679 .child = array_ty.elemType2(mod).toIntern(),19679 .child = array_ty.elemType2(mod).toIntern(),
19680 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },19680 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
19681 });19681 });
...@@ -19763,14 +19763,14 @@ fn arrayInitAnon(...@@ -19763,14 +19763,14 @@ fn arrayInitAnon(
1976319763
19764 if (is_ref) {19764 if (is_ref) {
19765 const target = sema.mod.getTarget();19765 const target = sema.mod.getTarget();
19766 const alloc_ty = try mod.ptrType(.{19766 const alloc_ty = try sema.ptrType(.{
19767 .child = tuple_ty,19767 .child = tuple_ty,
19768 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },19768 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
19769 });19769 });
19770 const alloc = try block.addTy(.alloc, alloc_ty);19770 const alloc = try block.addTy(.alloc, alloc_ty);
19771 for (operands, 0..) |operand, i_usize| {19771 for (operands, 0..) |operand, i_usize| {
19772 const i: u32 = @intCast(i_usize);19772 const i: u32 = @intCast(i_usize);
19773 const field_ptr_ty = try mod.ptrType(.{19773 const field_ptr_ty = try sema.ptrType(.{
19774 .child = types[i],19774 .child = types[i],
19775 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },19775 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
19776 });19776 });
...@@ -20332,7 +20332,7 @@ fn zirReify(...@@ -20332,7 +20332,7 @@ fn zirReify(
20332 }20332 }
20333 }20333 }
2033420334
20335 const ty = try mod.ptrType(.{20335 const ty = try sema.ptrType(.{
20336 .child = elem_ty.toIntern(),20336 .child = elem_ty.toIntern(),
20337 .sentinel = actual_sentinel,20337 .sentinel = actual_sentinel,
20338 .flags = .{20338 .flags = .{
...@@ -21936,7 +21936,7 @@ fn ptrCastFull(...@@ -21936,7 +21936,7 @@ fn ptrCastFull(
21936 // Only convert to a many-pointer at first21936 // Only convert to a many-pointer at first
21937 var info = dest_info;21937 var info = dest_info;
21938 info.flags.size = .Many;21938 info.flags.size = .Many;
21939 const ty = try mod.ptrType(info);21939 const ty = try sema.ptrType(info);
21940 if (dest_ty.zigTypeTag(mod) == .Optional) {21940 if (dest_ty.zigTypeTag(mod) == .Optional) {
21941 break :blk try mod.optionalType(ty.toIntern());21941 break :blk try mod.optionalType(ty.toIntern());
21942 } else {21942 } else {
...@@ -22015,7 +22015,7 @@ fn ptrCastFull(...@@ -22015,7 +22015,7 @@ fn ptrCastFull(
22015 // We can't change address spaces with a bitcast, so this requires two instructions22015 // We can't change address spaces with a bitcast, so this requires two instructions
22016 var intermediate_info = src_info;22016 var intermediate_info = src_info;
22017 intermediate_info.flags.address_space = dest_info.flags.address_space;22017 intermediate_info.flags.address_space = dest_info.flags.address_space;
22018 const intermediate_ptr_ty = try mod.ptrType(intermediate_info);22018 const intermediate_ptr_ty = try sema.ptrType(intermediate_info);
22019 const intermediate_ty = if (dest_ptr_ty.zigTypeTag(mod) == .Optional) blk: {22019 const intermediate_ty = if (dest_ptr_ty.zigTypeTag(mod) == .Optional) blk: {
22020 break :blk try mod.optionalType(intermediate_ptr_ty.toIntern());22020 break :blk try mod.optionalType(intermediate_ptr_ty.toIntern());
22021 } else intermediate_ptr_ty;22021 } else intermediate_ptr_ty;
...@@ -22071,7 +22071,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst...@@ -22071,7 +22071,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
22071 var ptr_info = operand_ty.ptrInfo(mod);22071 var ptr_info = operand_ty.ptrInfo(mod);
22072 if (flags.const_cast) ptr_info.flags.is_const = false;22072 if (flags.const_cast) ptr_info.flags.is_const = false;
22073 if (flags.volatile_cast) ptr_info.flags.is_volatile = false;22073 if (flags.volatile_cast) ptr_info.flags.is_volatile = false;
22074 const dest_ty = try mod.ptrType(ptr_info);22074 const dest_ty = try sema.ptrType(ptr_info);
2207522075
22076 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {22076 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
22077 return Air.internedToRef((try mod.getCoerced(operand_val, dest_ty)).toIntern());22077 return Air.internedToRef((try mod.getCoerced(operand_val, dest_ty)).toIntern());
...@@ -22606,7 +22606,7 @@ fn checkAtomicPtrOperand(...@@ -22606,7 +22606,7 @@ fn checkAtomicPtrOperand(
22606 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(mod)) {22606 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(mod)) {
22607 .Pointer => ptr_ty.ptrInfo(mod),22607 .Pointer => ptr_ty.ptrInfo(mod),
22608 else => {22608 else => {
22609 const wanted_ptr_ty = try mod.ptrType(wanted_ptr_data);22609 const wanted_ptr_ty = try sema.ptrType(wanted_ptr_data);
22610 _ = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);22610 _ = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);
22611 unreachable;22611 unreachable;
22612 },22612 },
...@@ -22616,7 +22616,7 @@ fn checkAtomicPtrOperand(...@@ -22616,7 +22616,7 @@ fn checkAtomicPtrOperand(
22616 wanted_ptr_data.flags.is_allowzero = ptr_data.flags.is_allowzero;22616 wanted_ptr_data.flags.is_allowzero = ptr_data.flags.is_allowzero;
22617 wanted_ptr_data.flags.is_volatile = ptr_data.flags.is_volatile;22617 wanted_ptr_data.flags.is_volatile = ptr_data.flags.is_volatile;
2261822618
22619 const wanted_ptr_ty = try mod.ptrType(wanted_ptr_data);22619 const wanted_ptr_ty = try sema.ptrType(wanted_ptr_data);
22620 const casted_ptr = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);22620 const casted_ptr = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);
2262122621
22622 return casted_ptr;22622 return casted_ptr;
...@@ -23798,11 +23798,11 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr...@@ -23798,11 +23798,11 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
23798 };23798 };
23799 }23799 }
2380023800
23801 const actual_field_ptr_ty = try mod.ptrType(ptr_ty_data);23801 const actual_field_ptr_ty = try sema.ptrType(ptr_ty_data);
23802 const casted_field_ptr = try sema.coerce(block, actual_field_ptr_ty, field_ptr, ptr_src);23802 const casted_field_ptr = try sema.coerce(block, actual_field_ptr_ty, field_ptr, ptr_src);
2380323803
23804 ptr_ty_data.child = parent_ty.toIntern();23804 ptr_ty_data.child = parent_ty.toIntern();
23805 const result_ptr = try mod.ptrType(ptr_ty_data);23805 const result_ptr = try sema.ptrType(ptr_ty_data);
2380623806
23807 if (try sema.resolveDefinedValue(block, src, casted_field_ptr)) |field_ptr_val| {23807 if (try sema.resolveDefinedValue(block, src, casted_field_ptr)) |field_ptr_val| {
23808 const field = switch (ip.indexToKey(field_ptr_val.toIntern())) {23808 const field = switch (ip.indexToKey(field_ptr_val.toIntern())) {
...@@ -24133,7 +24133,7 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A...@@ -24133,7 +24133,7 @@ fn upgradeToArrayPtr(sema: *Sema, block: *Block, ptr: Air.Inst.Ref, len: u64) !A
24133 // Already an array pointer.24133 // Already an array pointer.
24134 return ptr;24134 return ptr;
24135 }24135 }
24136 const new_ty = try mod.ptrType(.{24136 const new_ty = try sema.ptrType(.{
24137 .child = (try mod.arrayType(.{24137 .child = (try mod.arrayType(.{
24138 .len = len,24138 .len = len,
24139 .sentinel = info.sentinel,24139 .sentinel = info.sentinel,
...@@ -24337,7 +24337,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -24337,7 +24337,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
24337 assert(dest_manyptr_ty_key.flags.size == .One);24337 assert(dest_manyptr_ty_key.flags.size == .One);
24338 dest_manyptr_ty_key.child = dest_elem_ty.toIntern();24338 dest_manyptr_ty_key.child = dest_elem_ty.toIntern();
24339 dest_manyptr_ty_key.flags.size = .Many;24339 dest_manyptr_ty_key.flags.size = .Many;
24340 break :ptr try sema.coerceCompatiblePtrs(block, try mod.ptrType(dest_manyptr_ty_key), new_dest_ptr, dest_src);24340 break :ptr try sema.coerceCompatiblePtrs(block, try sema.ptrType(dest_manyptr_ty_key), new_dest_ptr, dest_src);
24341 } else new_dest_ptr;24341 } else new_dest_ptr;
2434224342
24343 const new_src_ptr_ty = sema.typeOf(new_src_ptr);24343 const new_src_ptr_ty = sema.typeOf(new_src_ptr);
...@@ -24348,7 +24348,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void...@@ -24348,7 +24348,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
24348 assert(src_manyptr_ty_key.flags.size == .One);24348 assert(src_manyptr_ty_key.flags.size == .One);
24349 src_manyptr_ty_key.child = src_elem_ty.toIntern();24349 src_manyptr_ty_key.child = src_elem_ty.toIntern();
24350 src_manyptr_ty_key.flags.size = .Many;24350 src_manyptr_ty_key.flags.size = .Many;
24351 break :ptr try sema.coerceCompatiblePtrs(block, try mod.ptrType(src_manyptr_ty_key), new_src_ptr, src_src);24351 break :ptr try sema.coerceCompatiblePtrs(block, try sema.ptrType(src_manyptr_ty_key), new_src_ptr, src_src);
24352 } else new_src_ptr;24352 } else new_src_ptr;
2435324353
24354 // ok1: dest >= src + len24354 // ok1: dest >= src + len
...@@ -25579,7 +25579,7 @@ fn prepareSimplePanic(sema: *Sema, block: *Block) !void {...@@ -25579,7 +25579,7 @@ fn prepareSimplePanic(sema: *Sema, block: *Block) !void {
25579 const stack_trace_ty = try sema.getBuiltinType("StackTrace");25579 const stack_trace_ty = try sema.getBuiltinType("StackTrace");
25580 try sema.resolveTypeFields(stack_trace_ty);25580 try sema.resolveTypeFields(stack_trace_ty);
25581 const target = mod.getTarget();25581 const target = mod.getTarget();
25582 const ptr_stack_trace_ty = try mod.ptrType(.{25582 const ptr_stack_trace_ty = try sema.ptrType(.{
25583 .child = stack_trace_ty.toIntern(),25583 .child = stack_trace_ty.toIntern(),
25584 .flags = .{25584 .flags = .{
25585 .address_space = target_util.defaultAddressSpace(target, .global_constant),25585 .address_space = target_util.defaultAddressSpace(target, .global_constant),
...@@ -25931,7 +25931,7 @@ fn fieldVal(...@@ -25931,7 +25931,7 @@ fn fieldVal(
25931 return Air.internedToRef((try mod.intValue(Type.usize, inner_ty.arrayLen(mod))).toIntern());25931 return Air.internedToRef((try mod.intValue(Type.usize, inner_ty.arrayLen(mod))).toIntern());
25932 } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) {25932 } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) {
25933 const ptr_info = object_ty.ptrInfo(mod);25933 const ptr_info = object_ty.ptrInfo(mod);
25934 const result_ty = try mod.ptrType(.{25934 const result_ty = try sema.ptrType(.{
25935 .child = ptr_info.child.toType().childType(mod).toIntern(),25935 .child = ptr_info.child.toType().childType(mod).toIntern(),
25936 .sentinel = ptr_info.sentinel,25936 .sentinel = ptr_info.sentinel,
25937 .flags = .{25937 .flags = .{
...@@ -26150,7 +26150,7 @@ fn fieldPtr(...@@ -26150,7 +26150,7 @@ fn fieldPtr(
26150 if (ip.stringEqlSlice(field_name, "ptr")) {26150 if (ip.stringEqlSlice(field_name, "ptr")) {
26151 const slice_ptr_ty = inner_ty.slicePtrFieldType(mod);26151 const slice_ptr_ty = inner_ty.slicePtrFieldType(mod);
2615226152
26153 const result_ty = try mod.ptrType(.{26153 const result_ty = try sema.ptrType(.{
26154 .child = slice_ptr_ty.toIntern(),26154 .child = slice_ptr_ty.toIntern(),
26155 .flags = .{26155 .flags = .{
26156 .is_const = !attr_ptr_ty.ptrIsMutable(mod),26156 .is_const = !attr_ptr_ty.ptrIsMutable(mod),
...@@ -26172,7 +26172,7 @@ fn fieldPtr(...@@ -26172,7 +26172,7 @@ fn fieldPtr(
2617226172
26173 return block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr);26173 return block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr);
26174 } else if (ip.stringEqlSlice(field_name, "len")) {26174 } else if (ip.stringEqlSlice(field_name, "len")) {
26175 const result_ty = try mod.ptrType(.{26175 const result_ty = try sema.ptrType(.{
26176 .child = .usize_type,26176 .child = .usize_type,
26177 .flags = .{26177 .flags = .{
26178 .is_const = !attr_ptr_ty.ptrIsMutable(mod),26178 .is_const = !attr_ptr_ty.ptrIsMutable(mod),
...@@ -26497,7 +26497,7 @@ fn finishFieldCallBind(...@@ -26497,7 +26497,7 @@ fn finishFieldCallBind(
26497 object_ptr: Air.Inst.Ref,26497 object_ptr: Air.Inst.Ref,
26498) CompileError!ResolvedFieldCallee {26498) CompileError!ResolvedFieldCallee {
26499 const mod = sema.mod;26499 const mod = sema.mod;
26500 const ptr_field_ty = try mod.ptrType(.{26500 const ptr_field_ty = try sema.ptrType(.{
26501 .child = field_ty.toIntern(),26501 .child = field_ty.toIntern(),
26502 .flags = .{26502 .flags = .{
26503 .is_const = !ptr_ty.ptrIsMutable(mod),26503 .is_const = !ptr_ty.ptrIsMutable(mod),
...@@ -26715,7 +26715,7 @@ fn structFieldPtrByIndex(...@@ -26715,7 +26715,7 @@ fn structFieldPtrByIndex(
26715 ptr_ty_data.flags.alignment = field_align.min(parent_align);26715 ptr_ty_data.flags.alignment = field_align.min(parent_align);
26716 }26716 }
2671726717
26718 const ptr_field_ty = try mod.ptrType(ptr_ty_data);26718 const ptr_field_ty = try sema.ptrType(ptr_ty_data);
2671926719
26720 if (struct_type.fieldIsComptime(ip, field_index)) {26720 if (struct_type.fieldIsComptime(ip, field_index)) {
26721 const val = try mod.intern(.{ .ptr = .{26721 const val = try mod.intern(.{ .ptr = .{
...@@ -26888,7 +26888,7 @@ fn unionFieldPtr(...@@ -26888,7 +26888,7 @@ fn unionFieldPtr(
26888 const union_obj = mod.typeToUnion(union_ty).?;26888 const union_obj = mod.typeToUnion(union_ty).?;
26889 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);26889 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
26890 const field_ty = union_obj.field_types.get(ip)[field_index].toType();26890 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
26891 const ptr_field_ty = try mod.ptrType(.{26891 const ptr_field_ty = try sema.ptrType(.{
26892 .child = field_ty.toIntern(),26892 .child = field_ty.toIntern(),
26893 .flags = .{26893 .flags = .{
26894 .is_const = union_ptr_info.flags.is_const,26894 .is_const = union_ptr_info.flags.is_const,
...@@ -27269,7 +27269,7 @@ fn tupleFieldPtr(...@@ -27269,7 +27269,7 @@ fn tupleFieldPtr(
27269 }27269 }
2727027270
27271 const field_ty = tuple_ty.structFieldType(field_index, mod);27271 const field_ty = tuple_ty.structFieldType(field_index, mod);
27272 const ptr_field_ty = try mod.ptrType(.{27272 const ptr_field_ty = try sema.ptrType(.{
27273 .child = field_ty.toIntern(),27273 .child = field_ty.toIntern(),
27274 .flags = .{27274 .flags = .{
27275 .is_const = !tuple_ptr_ty.ptrIsMutable(mod),27275 .is_const = !tuple_ptr_ty.ptrIsMutable(mod),
...@@ -31309,7 +31309,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo...@@ -31309,7 +31309,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo
3130931309
31310 const decl = mod.declPtr(decl_index);31310 const decl = mod.declPtr(decl_index);
31311 const decl_tv = try decl.typedValue();31311 const decl_tv = try decl.typedValue();
31312 const ptr_ty = try mod.ptrType(.{31312 const ptr_ty = try sema.ptrType(.{
31313 .child = decl_tv.ty.toIntern(),31313 .child = decl_tv.ty.toIntern(),
31314 .flags = .{31314 .flags = .{
31315 .alignment = decl.alignment,31315 .alignment = decl.alignment,
...@@ -31363,14 +31363,14 @@ fn analyzeRef(...@@ -31363,14 +31363,14 @@ fn analyzeRef(
3136331363
31364 try sema.requireRuntimeBlock(block, src, null);31364 try sema.requireRuntimeBlock(block, src, null);
31365 const address_space = target_util.defaultAddressSpace(mod.getTarget(), .local);31365 const address_space = target_util.defaultAddressSpace(mod.getTarget(), .local);
31366 const ptr_type = try mod.ptrType(.{31366 const ptr_type = try sema.ptrType(.{
31367 .child = operand_ty.toIntern(),31367 .child = operand_ty.toIntern(),
31368 .flags = .{31368 .flags = .{
31369 .is_const = true,31369 .is_const = true,
31370 .address_space = address_space,31370 .address_space = address_space,
31371 },31371 },
31372 });31372 });
31373 const mut_ptr_type = try mod.ptrType(.{31373 const mut_ptr_type = try sema.ptrType(.{
31374 .child = operand_ty.toIntern(),31374 .child = operand_ty.toIntern(),
31375 .flags = .{ .address_space = address_space },31375 .flags = .{ .address_space = address_space },
31376 });31376 });
...@@ -31742,7 +31742,7 @@ fn analyzeSlice(...@@ -31742,7 +31742,7 @@ fn analyzeSlice(
31742 assert(manyptr_ty_key.flags.size == .One);31742 assert(manyptr_ty_key.flags.size == .One);
31743 manyptr_ty_key.child = elem_ty.toIntern();31743 manyptr_ty_key.child = elem_ty.toIntern();
31744 manyptr_ty_key.flags.size = .Many;31744 manyptr_ty_key.flags.size = .Many;
31745 break :ptr try sema.coerceCompatiblePtrs(block, try mod.ptrType(manyptr_ty_key), ptr_or_slice, ptr_src);31745 break :ptr try sema.coerceCompatiblePtrs(block, try sema.ptrType(manyptr_ty_key), ptr_or_slice, ptr_src);
31746 } else ptr_or_slice;31746 } else ptr_or_slice;
3174731747
31748 const start = try sema.coerce(block, Type.usize, uncasted_start, start_src);31748 const start = try sema.coerce(block, Type.usize, uncasted_start, start_src);
...@@ -31965,7 +31965,7 @@ fn analyzeSlice(...@@ -31965,7 +31965,7 @@ fn analyzeSlice(
31965 if (opt_new_len_val) |new_len_val| {31965 if (opt_new_len_val) |new_len_val| {
31966 const new_len_int = new_len_val.toUnsignedInt(mod);31966 const new_len_int = new_len_val.toUnsignedInt(mod);
3196731967
31968 const return_ty = try mod.ptrType(.{31968 const return_ty = try sema.ptrType(.{
31969 .child = (try mod.arrayType(.{31969 .child = (try mod.arrayType(.{
31970 .len = new_len_int,31970 .len = new_len_int,
31971 .sentinel = if (sentinel) |s| s.toIntern() else .none,31971 .sentinel = if (sentinel) |s| s.toIntern() else .none,
...@@ -32026,7 +32026,7 @@ fn analyzeSlice(...@@ -32026,7 +32026,7 @@ fn analyzeSlice(
32026 return sema.fail(block, src, "non-zero length slice of undefined pointer", .{});32026 return sema.fail(block, src, "non-zero length slice of undefined pointer", .{});
32027 }32027 }
3202832028
32029 const return_ty = try mod.ptrType(.{32029 const return_ty = try sema.ptrType(.{
32030 .child = elem_ty.toIntern(),32030 .child = elem_ty.toIntern(),
32031 .sentinel = if (sentinel) |s| s.toIntern() else .none,32031 .sentinel = if (sentinel) |s| s.toIntern() else .none,
32032 .flags = .{32032 .flags = .{
...@@ -33293,7 +33293,7 @@ fn resolvePeerTypesInner(...@@ -33293,7 +33293,7 @@ fn resolvePeerTypesInner(
3329333293
33294 opt_ptr_info = ptr_info;33294 opt_ptr_info = ptr_info;
33295 }33295 }
33296 return .{ .success = try mod.ptrType(opt_ptr_info.?) };33296 return .{ .success = try sema.ptrType(opt_ptr_info.?) };
33297 },33297 },
3329833298
33299 .ptr => {33299 .ptr => {
...@@ -33603,7 +33603,7 @@ fn resolvePeerTypesInner(...@@ -33603,7 +33603,7 @@ fn resolvePeerTypesInner(
33603 },33603 },
33604 }33604 }
3360533605
33606 return .{ .success = try mod.ptrType(opt_ptr_info.?) };33606 return .{ .success = try sema.ptrType(opt_ptr_info.?) };
33607 },33607 },
3360833608
33609 .func => {33609 .func => {
...@@ -36418,7 +36418,7 @@ fn analyzeComptimeAlloc(...@@ -36418,7 +36418,7 @@ fn analyzeComptimeAlloc(
36418 // Needed to make an anon decl with type `var_type` (the `finish()` call below).36418 // Needed to make an anon decl with type `var_type` (the `finish()` call below).
36419 _ = try sema.typeHasOnePossibleValue(var_type);36419 _ = try sema.typeHasOnePossibleValue(var_type);
3642036420
36421 const ptr_type = try mod.ptrType(.{36421 const ptr_type = try sema.ptrType(.{
36422 .child = var_type.toIntern(),36422 .child = var_type.toIntern(),
36423 .flags = .{36423 .flags = .{
36424 .alignment = alignment,36424 .alignment = alignment,
...@@ -37576,7 +37576,7 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {...@@ -37576,7 +37576,7 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
37576 assert(new_align != .none);37576 assert(new_align != .none);
37577 break :a new_align;37577 break :a new_align;
37578 };37578 };
37579 return mod.ptrType(.{37579 return sema.ptrType(.{
37580 .child = elem_ty.toIntern(),37580 .child = elem_ty.toIntern(),
37581 .flags = .{37581 .flags = .{
37582 .alignment = alignment,37582 .alignment = alignment,
...@@ -37631,3 +37631,10 @@ fn isKnownZigType(sema: *Sema, ref: Air.Inst.Ref, tag: std.builtin.TypeId) bool...@@ -37631,3 +37631,10 @@ fn isKnownZigType(sema: *Sema, ref: Air.Inst.Ref, tag: std.builtin.TypeId) bool
37631 };37631 };
37632 return sema.typeOf(ref).zigTypeTag(sema.mod) == tag;37632 return sema.typeOf(ref).zigTypeTag(sema.mod) == tag;
37633}37633}
37634
37635fn ptrType(sema: *Sema, info: InternPool.Key.PtrType) CompileError!Type {
37636 if (info.flags.alignment != .none) {
37637 _ = try sema.typeAbiAlignment(info.child.toType());
37638 }
37639 return sema.mod.ptrType(info);
37640}