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!
59375937
59385938pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type {
59395939 var canon_info = info;
5940 const have_elem_layout = info.child.toType().layoutIsResolved(mod);
59415940
59425941 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
59455944 // type, we change it to 0 here. If this causes an assertion trip because the
59465945 // pointee type needs to be resolved more, that needs to be done before calling
59475946 // this ptr() function.
5948 if (info.flags.alignment != .none and have_elem_layout and
5947 if (info.flags.alignment != .none and
59495948 info.flags.alignment == info.child.toType().abiAlignment(mod))
59505949 {
59515950 canon_info.flags.alignment = .none;
......@@ -5955,7 +5954,7 @@ pub fn ptrType(mod: *Module, info: InternPool.Key.PtrType) Allocator.Error!Type
59555954 // Canonicalize host_size. If it matches the bit size of the pointee type,
59565955 // we change it to 0 here. If this causes an assertion trip, the pointee type
59575956 // 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) {
59595958 const elem_bit_size = info.child.toType().bitSize(mod);
59605959 assert(info.packed_offset.bit_offset + elem_bit_size <= info.packed_offset.host_size * 8);
59615960 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
26292629 defer trash_block.instructions.deinit(sema.gpa);
26302630 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(.{
26332633 .child = pointee_ty.toIntern(),
26342634 .flags = .{
26352635 .alignment = ia1.alignment,
......@@ -2660,7 +2660,7 @@ fn zirCoerceResultPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileE
26602660 if (alignment != .none) {
26612661 try sema.resolveTypeLayout(pointee_ty);
26622662 }
2663 const ptr_ty = try mod.ptrType(.{
2663 const ptr_ty = try sema.ptrType(.{
26642664 .child = pointee_ty.toIntern(),
26652665 .flags = .{
26662666 .alignment = alignment,
......@@ -2730,7 +2730,7 @@ fn coerceResultPtr(
27302730 }
27312731 }
27322732
2733 const ptr_ty = try mod.ptrType(.{
2733 const ptr_ty = try sema.ptrType(.{
27342734 .child = pointee_ty.toIntern(),
27352735 .flags = .{ .address_space = addr_space },
27362736 });
......@@ -2759,7 +2759,7 @@ fn coerceResultPtr(
27592759 // Array coerced to Vector where element size is not equal but coercible.
27602760 .aggregate_init => {
27612761 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(.{
27632763 .child = (try sema.analyzeAsType(block, src, ty_pl.ty)).toIntern(),
27642764 .flags = .{ .address_space = addr_space },
27652765 });
......@@ -2773,7 +2773,7 @@ fn coerceResultPtr(
27732773 .bitcast => {
27742774 const ty_op = air_datas[trash_inst].ty_op;
27752775 const operand_ty = sema.typeOf(ty_op.operand);
2776 const ptr_operand_ty = try mod.ptrType(.{
2776 const ptr_operand_ty = try sema.ptrType(.{
27772777 .child = operand_ty.toIntern(),
27782778 .flags = .{ .address_space = addr_space },
27792779 });
......@@ -3508,7 +3508,7 @@ fn zirRetPtr(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
35083508 }
35093509
35103510 const target = sema.mod.getTarget();
3511 const ptr_type = try sema.mod.ptrType(.{
3511 const ptr_type = try sema.ptrType(.{
35123512 .child = sema.fn_ret_ty.toIntern(),
35133513 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
35143514 });
......@@ -3711,7 +3711,7 @@ fn zirAllocExtended(
37113711 }
37123712 const target = sema.mod.getTarget();
37133713 try sema.resolveTypeLayout(var_ty);
3714 const ptr_type = try sema.mod.ptrType(.{
3714 const ptr_type = try sema.ptrType(.{
37153715 .child = var_ty.toIntern(),
37163716 .flags = .{
37173717 .alignment = alignment,
......@@ -3820,7 +3820,7 @@ fn makePtrConst(sema: *Sema, block: *Block, alloc: Air.Inst.Ref) CompileError!Ai
38203820
38213821 var ptr_info = alloc_ty.ptrInfo(mod);
38223822 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
38253825 // Detect if a comptime value simply needs to have its type changed.
38263826 if (try sema.resolveMaybeUndefVal(alloc)) |val| {
......@@ -3862,7 +3862,7 @@ fn zirAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.I
38623862 return sema.analyzeComptimeAlloc(block, var_ty, .none);
38633863 }
38643864 const target = sema.mod.getTarget();
3865 const ptr_type = try sema.mod.ptrType(.{
3865 const ptr_type = try sema.ptrType(.{
38663866 .child = var_ty.toIntern(),
38673867 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
38683868 });
......@@ -3882,7 +3882,7 @@ fn zirAllocMut(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
38823882 }
38833883 try sema.validateVarType(block, ty_src, var_ty, false);
38843884 const target = sema.mod.getTarget();
3885 const ptr_type = try sema.mod.ptrType(.{
3885 const ptr_type = try sema.ptrType(.{
38863886 .child = var_ty.toIntern(),
38873887 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
38883888 });
......@@ -3948,7 +3948,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
39483948 const decl = mod.declPtr(decl_index);
39493949 if (iac.is_const) _ = try decl.internValue(mod);
39503950 const final_elem_ty = decl.ty;
3951 const final_ptr_ty = try mod.ptrType(.{
3951 const final_ptr_ty = try sema.ptrType(.{
39523952 .child = final_elem_ty.toIntern(),
39533953 .flags = .{
39543954 .is_const = false,
......@@ -3981,7 +3981,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
39813981 const peer_inst_list = ia2.prongs.items(.stored_inst);
39823982 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(.{
39853985 .child = final_elem_ty.toIntern(),
39863986 .flags = .{
39873987 .alignment = ia1.alignment,
......@@ -4103,7 +4103,7 @@ fn zirResolveInferredAlloc(sema: *Sema, block: *Block, inst: Zir.Inst.Index) Com
41034103 trash_block.is_comptime = false;
41044104 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(.{
41074107 .child = final_elem_ty.toIntern(),
41084108 .flags = .{
41094109 .alignment = ia1.alignment,
......@@ -8650,7 +8650,7 @@ fn analyzeOptionalPayloadPtr(
86508650 }
86518651
86528652 const child_type = opt_type.optionalChild(mod);
8653 const child_pointer = try mod.ptrType(.{
8653 const child_pointer = try sema.ptrType(.{
86548654 .child = child_type.toIntern(),
86558655 .flags = .{
86568656 .is_const = optional_ptr_ty.isConstPtr(mod),
......@@ -8719,7 +8719,7 @@ fn zirOptionalPayload(
87198719 // TODO https://github.com/ziglang/zig/issues/6597
87208720 if (true) break :t operand_ty;
87218721 const ptr_info = operand_ty.ptrInfo(mod);
8722 break :t try mod.ptrType(.{
8722 break :t try sema.ptrType(.{
87238723 .child = ptr_info.child,
87248724 .flags = .{
87258725 .alignment = ptr_info.flags.alignment,
......@@ -8837,7 +8837,7 @@ fn analyzeErrUnionPayloadPtr(
88378837
88388838 const err_union_ty = operand_ty.childType(mod);
88398839 const payload_ty = err_union_ty.errorUnionPayload(mod);
8840 const operand_pointer_ty = try mod.ptrType(.{
8840 const operand_pointer_ty = try sema.ptrType(.{
88418841 .child = payload_ty.toIntern(),
88428842 .flags = .{
88438843 .is_const = operand_ty.isConstPtr(mod),
......@@ -10692,7 +10692,7 @@ const SwitchProngAnalysis = struct {
1069210692 const union_obj = mod.typeToUnion(operand_ty).?;
1069310693 const field_ty = union_obj.field_types.get(ip)[field_index].toType();
1069410694 if (capture_byref) {
10695 const ptr_field_ty = try mod.ptrType(.{
10695 const ptr_field_ty = try sema.ptrType(.{
1069610696 .child = field_ty.toIntern(),
1069710697 .flags = .{
1069810698 .is_const = !operand_ptr_ty.ptrIsMutable(mod),
......@@ -10798,7 +10798,7 @@ const SwitchProngAnalysis = struct {
1079810798 // By-reference captures have some further restrictions which make them easier to emit
1079910799 if (capture_byref) {
1080010800 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(.{
1080210802 .child = capture_ty.toIntern(),
1080310803 .flags = .{
1080410804 // TODO: alignment!
......@@ -10812,7 +10812,7 @@ const SwitchProngAnalysis = struct {
1081210812 // pointer type is in-memory coercible to the capture pointer type.
1081310813 if (!same_types) {
1081410814 for (field_tys, 0..) |field_ty, i| {
10815 const field_ptr_ty = try mod.ptrType(.{
10815 const field_ptr_ty = try sema.ptrType(.{
1081610816 .child = field_ty.toIntern(),
1081710817 .flags = .{
1081810818 // TODO: alignment!
......@@ -13776,12 +13776,12 @@ fn zirArrayCat(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1377613776 try sema.requireRuntimeBlock(block, src, runtime_src);
1377713777
1377813778 if (ptr_addrspace) |ptr_as| {
13779 const alloc_ty = try mod.ptrType(.{
13779 const alloc_ty = try sema.ptrType(.{
1378013780 .child = result_ty.toIntern(),
1378113781 .flags = .{ .address_space = ptr_as },
1378213782 });
1378313783 const alloc = try block.addTy(.alloc, alloc_ty);
13784 const elem_ptr_ty = try mod.ptrType(.{
13784 const elem_ptr_ty = try sema.ptrType(.{
1378513785 .child = resolved_elem_ty.toIntern(),
1378613786 .flags = .{ .address_space = ptr_as },
1378713787 });
......@@ -14041,12 +14041,12 @@ fn zirArrayMul(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1404114041 try sema.requireRuntimeBlock(block, src, lhs_src);
1404214042
1404314043 if (ptr_addrspace) |ptr_as| {
14044 const alloc_ty = try mod.ptrType(.{
14044 const alloc_ty = try sema.ptrType(.{
1404514045 .child = result_ty.toIntern(),
1404614046 .flags = .{ .address_space = ptr_as },
1404714047 });
1404814048 const alloc = try block.addTy(.alloc, alloc_ty);
14049 const elem_ptr_ty = try mod.ptrType(.{
14049 const elem_ptr_ty = try sema.ptrType(.{
1405014050 .child = lhs_info.elem_type.toIntern(),
1405114051 .flags = .{ .address_space = ptr_as },
1405214052 });
......@@ -15988,7 +15988,7 @@ fn analyzePtrArithmetic(
1598815988 ));
1598915989 assert(new_align != .none);
1599015990
15991 break :t try mod.ptrType(.{
15991 break :t try sema.ptrType(.{
1599215992 .child = ptr_info.child,
1599315993 .sentinel = ptr_info.sentinel,
1599415994 .flags = .{
......@@ -16891,7 +16891,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1689116891 .none, // default alignment
1689216892 );
1689316893 break :v try mod.intern(.{ .ptr = .{
16894 .ty = (try mod.ptrType(.{
16894 .ty = (try sema.ptrType(.{
1689516895 .child = param_info_ty.toIntern(),
1689616896 .flags = .{
1689716897 .size = .Slice,
......@@ -17210,7 +17210,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1721017210 };
1721117211
1721217212 // Build our ?[]const Error value
17213 const slice_errors_ty = try mod.ptrType(.{
17213 const slice_errors_ty = try sema.ptrType(.{
1721417214 .child = error_field_ty.toIntern(),
1721517215 .flags = .{
1721617216 .size = .Slice,
......@@ -17359,7 +17359,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1735917359 .none, // default alignment
1736017360 );
1736117361 break :v try mod.intern(.{ .ptr = .{
17362 .ty = (try mod.ptrType(.{
17362 .ty = (try sema.ptrType(.{
1736317363 .child = enum_field_ty.toIntern(),
1736417364 .flags = .{
1736517365 .size = .Slice,
......@@ -17503,7 +17503,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1750317503 .none, // default alignment
1750417504 );
1750517505 break :v try mod.intern(.{ .ptr = .{
17506 .ty = (try mod.ptrType(.{
17506 .ty = (try sema.ptrType(.{
1750717507 .child = union_field_ty.toIntern(),
1750817508 .flags = .{
1750917509 .size = .Slice,
......@@ -17731,7 +17731,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1773117731 .none, // default alignment
1773217732 );
1773317733 break :v try mod.intern(.{ .ptr = .{
17734 .ty = (try mod.ptrType(.{
17734 .ty = (try sema.ptrType(.{
1773517735 .child = struct_field_ty.toIntern(),
1773617736 .flags = .{
1773717737 .size = .Slice,
......@@ -17877,7 +17877,7 @@ fn typeInfoDecls(
1787717877 .none, // default alignment
1787817878 );
1787917879 return try mod.intern(.{ .ptr = .{
17880 .ty = (try mod.ptrType(.{
17880 .ty = (try sema.ptrType(.{
1788117881 .child = declaration_ty.toIntern(),
1788217882 .flags = .{
1788317883 .size = .Slice,
......@@ -18447,7 +18447,7 @@ fn zirTryPtr(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileErr
1844718447
1844818448 const operand_ty = sema.typeOf(operand);
1844918449 const ptr_info = operand_ty.ptrInfo(mod);
18450 const res_ty = try mod.ptrType(.{
18450 const res_ty = try sema.ptrType(.{
1845118451 .child = err_union_ty.errorUnionPayload(mod).toIntern(),
1845218452 .flags = .{
1845318453 .is_const = ptr_info.flags.is_const,
......@@ -19001,7 +19001,7 @@ fn zirPtrType(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air
1900119001 }
1900219002 }
1900319003
19004 const ty = try mod.ptrType(.{
19004 const ty = try sema.ptrType(.{
1900519005 .child = elem_ty.toIntern(),
1900619006 .sentinel = sentinel,
1900719007 .flags = .{
......@@ -19239,7 +19239,7 @@ fn zirStructInit(
1923919239
1924019240 if (is_ref) {
1924119241 const target = mod.getTarget();
19242 const alloc_ty = try mod.ptrType(.{
19242 const alloc_ty = try sema.ptrType(.{
1924319243 .child = resolved_ty.toIntern(),
1924419244 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
1924519245 });
......@@ -19363,7 +19363,7 @@ fn finishStructInit(
1936319363 if (is_ref) {
1936419364 try sema.resolveStructLayout(struct_ty);
1936519365 const target = sema.mod.getTarget();
19366 const alloc_ty = try mod.ptrType(.{
19366 const alloc_ty = try sema.ptrType(.{
1936719367 .child = struct_ty.toIntern(),
1936819368 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
1936919369 });
......@@ -19516,7 +19516,7 @@ fn structInitAnon(
1951619516
1951719517 if (is_ref) {
1951819518 const target = mod.getTarget();
19519 const alloc_ty = try mod.ptrType(.{
19519 const alloc_ty = try sema.ptrType(.{
1952019520 .child = tuple_ty,
1952119521 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
1952219522 });
......@@ -19530,7 +19530,7 @@ fn structInitAnon(
1953019530 };
1953119531 extra_index = item.end;
1953219532
19533 const field_ptr_ty = try mod.ptrType(.{
19533 const field_ptr_ty = try sema.ptrType(.{
1953419534 .child = field_ty,
1953519535 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
1953619536 });
......@@ -19654,7 +19654,7 @@ fn zirArrayInit(
1965419654
1965519655 if (is_ref) {
1965619656 const target = mod.getTarget();
19657 const alloc_ty = try mod.ptrType(.{
19657 const alloc_ty = try sema.ptrType(.{
1965819658 .child = array_ty.toIntern(),
1965919659 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
1966019660 });
......@@ -19662,7 +19662,7 @@ fn zirArrayInit(
1966219662
1966319663 if (array_ty.isTuple(mod)) {
1966419664 for (resolved_args, 0..) |arg, i| {
19665 const elem_ptr_ty = try mod.ptrType(.{
19665 const elem_ptr_ty = try sema.ptrType(.{
1966619666 .child = array_ty.structFieldType(i, mod).toIntern(),
1966719667 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
1966819668 });
......@@ -19675,7 +19675,7 @@ fn zirArrayInit(
1967519675 return sema.makePtrConst(block, alloc);
1967619676 }
1967719677
19678 const elem_ptr_ty = try mod.ptrType(.{
19678 const elem_ptr_ty = try sema.ptrType(.{
1967919679 .child = array_ty.elemType2(mod).toIntern(),
1968019680 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
1968119681 });
......@@ -19763,14 +19763,14 @@ fn arrayInitAnon(
1976319763
1976419764 if (is_ref) {
1976519765 const target = sema.mod.getTarget();
19766 const alloc_ty = try mod.ptrType(.{
19766 const alloc_ty = try sema.ptrType(.{
1976719767 .child = tuple_ty,
1976819768 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
1976919769 });
1977019770 const alloc = try block.addTy(.alloc, alloc_ty);
1977119771 for (operands, 0..) |operand, i_usize| {
1977219772 const i: u32 = @intCast(i_usize);
19773 const field_ptr_ty = try mod.ptrType(.{
19773 const field_ptr_ty = try sema.ptrType(.{
1977419774 .child = types[i],
1977519775 .flags = .{ .address_space = target_util.defaultAddressSpace(target, .local) },
1977619776 });
......@@ -20332,7 +20332,7 @@ fn zirReify(
2033220332 }
2033320333 }
2033420334
20335 const ty = try mod.ptrType(.{
20335 const ty = try sema.ptrType(.{
2033620336 .child = elem_ty.toIntern(),
2033720337 .sentinel = actual_sentinel,
2033820338 .flags = .{
......@@ -21936,7 +21936,7 @@ fn ptrCastFull(
2193621936 // Only convert to a many-pointer at first
2193721937 var info = dest_info;
2193821938 info.flags.size = .Many;
21939 const ty = try mod.ptrType(info);
21939 const ty = try sema.ptrType(info);
2194021940 if (dest_ty.zigTypeTag(mod) == .Optional) {
2194121941 break :blk try mod.optionalType(ty.toIntern());
2194221942 } else {
......@@ -22015,7 +22015,7 @@ fn ptrCastFull(
2201522015 // We can't change address spaces with a bitcast, so this requires two instructions
2201622016 var intermediate_info = src_info;
2201722017 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);
2201922019 const intermediate_ty = if (dest_ptr_ty.zigTypeTag(mod) == .Optional) blk: {
2202022020 break :blk try mod.optionalType(intermediate_ptr_ty.toIntern());
2202122021 } else intermediate_ptr_ty;
......@@ -22071,7 +22071,7 @@ fn zirPtrCastNoDest(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
2207122071 var ptr_info = operand_ty.ptrInfo(mod);
2207222072 if (flags.const_cast) ptr_info.flags.is_const = false;
2207322073 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
2207622076 if (try sema.resolveMaybeUndefVal(operand)) |operand_val| {
2207722077 return Air.internedToRef((try mod.getCoerced(operand_val, dest_ty)).toIntern());
......@@ -22606,7 +22606,7 @@ fn checkAtomicPtrOperand(
2260622606 const ptr_data = switch (try ptr_ty.zigTypeTagOrPoison(mod)) {
2260722607 .Pointer => ptr_ty.ptrInfo(mod),
2260822608 else => {
22609 const wanted_ptr_ty = try mod.ptrType(wanted_ptr_data);
22609 const wanted_ptr_ty = try sema.ptrType(wanted_ptr_data);
2261022610 _ = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);
2261122611 unreachable;
2261222612 },
......@@ -22616,7 +22616,7 @@ fn checkAtomicPtrOperand(
2261622616 wanted_ptr_data.flags.is_allowzero = ptr_data.flags.is_allowzero;
2261722617 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);
2262022620 const casted_ptr = try sema.coerce(block, wanted_ptr_ty, ptr, ptr_src);
2262122621
2262222622 return casted_ptr;
......@@ -23798,11 +23798,11 @@ fn zirFieldParentPtr(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileEr
2379823798 };
2379923799 }
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);
2380223802 const casted_field_ptr = try sema.coerce(block, actual_field_ptr_ty, field_ptr, ptr_src);
2380323803
2380423804 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
2380723807 if (try sema.resolveDefinedValue(block, src, casted_field_ptr)) |field_ptr_val| {
2380823808 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
2413324133 // Already an array pointer.
2413424134 return ptr;
2413524135 }
24136 const new_ty = try mod.ptrType(.{
24136 const new_ty = try sema.ptrType(.{
2413724137 .child = (try mod.arrayType(.{
2413824138 .len = len,
2413924139 .sentinel = info.sentinel,
......@@ -24337,7 +24337,7 @@ fn zirMemcpy(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!void
2433724337 assert(dest_manyptr_ty_key.flags.size == .One);
2433824338 dest_manyptr_ty_key.child = dest_elem_ty.toIntern();
2433924339 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);
2434124341 } else new_dest_ptr;
2434224342
2434324343 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
2434824348 assert(src_manyptr_ty_key.flags.size == .One);
2434924349 src_manyptr_ty_key.child = src_elem_ty.toIntern();
2435024350 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);
2435224352 } else new_src_ptr;
2435324353
2435424354 // ok1: dest >= src + len
......@@ -25579,7 +25579,7 @@ fn prepareSimplePanic(sema: *Sema, block: *Block) !void {
2557925579 const stack_trace_ty = try sema.getBuiltinType("StackTrace");
2558025580 try sema.resolveTypeFields(stack_trace_ty);
2558125581 const target = mod.getTarget();
25582 const ptr_stack_trace_ty = try mod.ptrType(.{
25582 const ptr_stack_trace_ty = try sema.ptrType(.{
2558325583 .child = stack_trace_ty.toIntern(),
2558425584 .flags = .{
2558525585 .address_space = target_util.defaultAddressSpace(target, .global_constant),
......@@ -25931,7 +25931,7 @@ fn fieldVal(
2593125931 return Air.internedToRef((try mod.intValue(Type.usize, inner_ty.arrayLen(mod))).toIntern());
2593225932 } else if (ip.stringEqlSlice(field_name, "ptr") and is_pointer_to) {
2593325933 const ptr_info = object_ty.ptrInfo(mod);
25934 const result_ty = try mod.ptrType(.{
25934 const result_ty = try sema.ptrType(.{
2593525935 .child = ptr_info.child.toType().childType(mod).toIntern(),
2593625936 .sentinel = ptr_info.sentinel,
2593725937 .flags = .{
......@@ -26150,7 +26150,7 @@ fn fieldPtr(
2615026150 if (ip.stringEqlSlice(field_name, "ptr")) {
2615126151 const slice_ptr_ty = inner_ty.slicePtrFieldType(mod);
2615226152
26153 const result_ty = try mod.ptrType(.{
26153 const result_ty = try sema.ptrType(.{
2615426154 .child = slice_ptr_ty.toIntern(),
2615526155 .flags = .{
2615626156 .is_const = !attr_ptr_ty.ptrIsMutable(mod),
......@@ -26172,7 +26172,7 @@ fn fieldPtr(
2617226172
2617326173 return block.addTyOp(.ptr_slice_ptr_ptr, result_ty, inner_ptr);
2617426174 } else if (ip.stringEqlSlice(field_name, "len")) {
26175 const result_ty = try mod.ptrType(.{
26175 const result_ty = try sema.ptrType(.{
2617626176 .child = .usize_type,
2617726177 .flags = .{
2617826178 .is_const = !attr_ptr_ty.ptrIsMutable(mod),
......@@ -26497,7 +26497,7 @@ fn finishFieldCallBind(
2649726497 object_ptr: Air.Inst.Ref,
2649826498) CompileError!ResolvedFieldCallee {
2649926499 const mod = sema.mod;
26500 const ptr_field_ty = try mod.ptrType(.{
26500 const ptr_field_ty = try sema.ptrType(.{
2650126501 .child = field_ty.toIntern(),
2650226502 .flags = .{
2650326503 .is_const = !ptr_ty.ptrIsMutable(mod),
......@@ -26715,7 +26715,7 @@ fn structFieldPtrByIndex(
2671526715 ptr_ty_data.flags.alignment = field_align.min(parent_align);
2671626716 }
2671726717
26718 const ptr_field_ty = try mod.ptrType(ptr_ty_data);
26718 const ptr_field_ty = try sema.ptrType(ptr_ty_data);
2671926719
2672026720 if (struct_type.fieldIsComptime(ip, field_index)) {
2672126721 const val = try mod.intern(.{ .ptr = .{
......@@ -26888,7 +26888,7 @@ fn unionFieldPtr(
2688826888 const union_obj = mod.typeToUnion(union_ty).?;
2688926889 const field_index = try sema.unionFieldIndex(block, union_ty, field_name, field_name_src);
2689026890 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(.{
2689226892 .child = field_ty.toIntern(),
2689326893 .flags = .{
2689426894 .is_const = union_ptr_info.flags.is_const,
......@@ -27269,7 +27269,7 @@ fn tupleFieldPtr(
2726927269 }
2727027270
2727127271 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(.{
2727327273 .child = field_ty.toIntern(),
2727427274 .flags = .{
2727527275 .is_const = !tuple_ptr_ty.ptrIsMutable(mod),
......@@ -31309,7 +31309,7 @@ fn analyzeDeclRefInner(sema: *Sema, decl_index: Decl.Index, analyze_fn_body: boo
3130931309
3131031310 const decl = mod.declPtr(decl_index);
3131131311 const decl_tv = try decl.typedValue();
31312 const ptr_ty = try mod.ptrType(.{
31312 const ptr_ty = try sema.ptrType(.{
3131331313 .child = decl_tv.ty.toIntern(),
3131431314 .flags = .{
3131531315 .alignment = decl.alignment,
......@@ -31363,14 +31363,14 @@ fn analyzeRef(
3136331363
3136431364 try sema.requireRuntimeBlock(block, src, null);
3136531365 const address_space = target_util.defaultAddressSpace(mod.getTarget(), .local);
31366 const ptr_type = try mod.ptrType(.{
31366 const ptr_type = try sema.ptrType(.{
3136731367 .child = operand_ty.toIntern(),
3136831368 .flags = .{
3136931369 .is_const = true,
3137031370 .address_space = address_space,
3137131371 },
3137231372 });
31373 const mut_ptr_type = try mod.ptrType(.{
31373 const mut_ptr_type = try sema.ptrType(.{
3137431374 .child = operand_ty.toIntern(),
3137531375 .flags = .{ .address_space = address_space },
3137631376 });
......@@ -31742,7 +31742,7 @@ fn analyzeSlice(
3174231742 assert(manyptr_ty_key.flags.size == .One);
3174331743 manyptr_ty_key.child = elem_ty.toIntern();
3174431744 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);
3174631746 } else ptr_or_slice;
3174731747
3174831748 const start = try sema.coerce(block, Type.usize, uncasted_start, start_src);
......@@ -31965,7 +31965,7 @@ fn analyzeSlice(
3196531965 if (opt_new_len_val) |new_len_val| {
3196631966 const new_len_int = new_len_val.toUnsignedInt(mod);
3196731967
31968 const return_ty = try mod.ptrType(.{
31968 const return_ty = try sema.ptrType(.{
3196931969 .child = (try mod.arrayType(.{
3197031970 .len = new_len_int,
3197131971 .sentinel = if (sentinel) |s| s.toIntern() else .none,
......@@ -32026,7 +32026,7 @@ fn analyzeSlice(
3202632026 return sema.fail(block, src, "non-zero length slice of undefined pointer", .{});
3202732027 }
3202832028
32029 const return_ty = try mod.ptrType(.{
32029 const return_ty = try sema.ptrType(.{
3203032030 .child = elem_ty.toIntern(),
3203132031 .sentinel = if (sentinel) |s| s.toIntern() else .none,
3203232032 .flags = .{
......@@ -33293,7 +33293,7 @@ fn resolvePeerTypesInner(
3329333293
3329433294 opt_ptr_info = ptr_info;
3329533295 }
33296 return .{ .success = try mod.ptrType(opt_ptr_info.?) };
33296 return .{ .success = try sema.ptrType(opt_ptr_info.?) };
3329733297 },
3329833298
3329933299 .ptr => {
......@@ -33603,7 +33603,7 @@ fn resolvePeerTypesInner(
3360333603 },
3360433604 }
3360533605
33606 return .{ .success = try mod.ptrType(opt_ptr_info.?) };
33606 return .{ .success = try sema.ptrType(opt_ptr_info.?) };
3360733607 },
3360833608
3360933609 .func => {
......@@ -36418,7 +36418,7 @@ fn analyzeComptimeAlloc(
3641836418 // Needed to make an anon decl with type `var_type` (the `finish()` call below).
3641936419 _ = try sema.typeHasOnePossibleValue(var_type);
3642036420
36421 const ptr_type = try mod.ptrType(.{
36421 const ptr_type = try sema.ptrType(.{
3642236422 .child = var_type.toIntern(),
3642336423 .flags = .{
3642436424 .alignment = alignment,
......@@ -37576,7 +37576,7 @@ fn elemPtrType(sema: *Sema, ptr_ty: Type, offset: ?usize) !Type {
3757637576 assert(new_align != .none);
3757737577 break :a new_align;
3757837578 };
37579 return mod.ptrType(.{
37579 return sema.ptrType(.{
3758037580 .child = elem_ty.toIntern(),
3758137581 .flags = .{
3758237582 .alignment = alignment,
......@@ -37631,3 +37631,10 @@ fn isKnownZigType(sema: *Sema, ref: Air.Inst.Ref, tag: std.builtin.TypeId) bool
3763137631 };
3763237632 return sema.typeOf(ref).zigTypeTag(sema.mod) == tag;
3763337633}
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}