authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-11 19:16:57-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-15 15:11:35-08:00
logc96e23632f04c7bffc2257139a19cad82fbe7223
tree793a2a41d98d67c7a46d70384d7f732a636a91e9
parent26c38b2d42ca3d68a8964c83a86a7e69f0990019

frontend: add const to more Zcu pointers


3 files changed, 115 insertions(+), 88 deletions(-)

src/InternPool.zig+5-1
...@@ -3360,6 +3360,10 @@ pub const LoadedUnionType = struct {...@@ -3360,6 +3360,10 @@ pub const LoadedUnionType = struct {
3360 return flags.status == .field_types_wip;3360 return flags.status == .field_types_wip;
3361 }3361 }
33623362
3363 pub fn requiresComptime(u: LoadedUnionType, ip: *const InternPool) RequiresComptime {
3364 return u.flagsUnordered(ip).requires_comptime;
3365 }
3366
3363 pub fn setRequiresComptimeWip(u: LoadedUnionType, ip: *InternPool) RequiresComptime {3367 pub fn setRequiresComptimeWip(u: LoadedUnionType, ip: *InternPool) RequiresComptime {
3364 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;3368 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
3365 extra_mutex.lock();3369 extra_mutex.lock();
...@@ -4014,7 +4018,7 @@ pub const LoadedStructType = struct {...@@ -4014,7 +4018,7 @@ pub const LoadedStructType = struct {
4014 }4018 }
4015 }4019 }
40164020
4017 pub fn haveLayout(s: LoadedStructType, ip: *InternPool) bool {4021 pub fn haveLayout(s: LoadedStructType, ip: *const InternPool) bool {
4018 return switch (s.layout) {4022 return switch (s.layout) {
4019 .@"packed" => s.backingIntTypeUnordered(ip) != .none,4023 .@"packed" => s.backingIntTypeUnordered(ip) != .none,
4020 .auto, .@"extern" => s.flagsUnordered(ip).layout_resolved,4024 .auto, .@"extern" => s.flagsUnordered(ip).layout_resolved,
src/Type.zig+108-85
...@@ -441,7 +441,7 @@ pub fn toValue(self: Type) Value {...@@ -441,7 +441,7 @@ pub fn toValue(self: Type) Value {
441441
442const RuntimeBitsError = SemaError || error{NeedLazy};442const RuntimeBitsError = SemaError || error{NeedLazy};
443443
444pub fn hasRuntimeBits(ty: Type, zcu: *Zcu) bool {444pub fn hasRuntimeBits(ty: Type, zcu: *const Zcu) bool {
445 return hasRuntimeBitsInner(ty, false, .eager, zcu, {}) catch unreachable;445 return hasRuntimeBitsInner(ty, false, .eager, zcu, {}) catch unreachable;
446}446}
447447
...@@ -452,7 +452,7 @@ pub fn hasRuntimeBitsSema(ty: Type, pt: Zcu.PerThread) SemaError!bool {...@@ -452,7 +452,7 @@ pub fn hasRuntimeBitsSema(ty: Type, pt: Zcu.PerThread) SemaError!bool {
452 };452 };
453}453}
454454
455pub fn hasRuntimeBitsIgnoreComptime(ty: Type, zcu: *Zcu) bool {455pub fn hasRuntimeBitsIgnoreComptime(ty: Type, zcu: *const Zcu) bool {
456 return hasRuntimeBitsInner(ty, true, .eager, zcu, {}) catch unreachable;456 return hasRuntimeBitsInner(ty, true, .eager, zcu, {}) catch unreachable;
457}457}
458458
...@@ -471,7 +471,7 @@ pub fn hasRuntimeBitsInner(...@@ -471,7 +471,7 @@ pub fn hasRuntimeBitsInner(
471 ty: Type,471 ty: Type,
472 ignore_comptime_only: bool,472 ignore_comptime_only: bool,
473 comptime strat: ResolveStratLazy,473 comptime strat: ResolveStratLazy,
474 zcu: *Zcu,474 zcu: strat.ZcuPtr(),
475 tid: strat.Tid(),475 tid: strat.Tid(),
476) RuntimeBitsError!bool {476) RuntimeBitsError!bool {
477 const ip = &zcu.intern_pool;477 const ip = &zcu.intern_pool;
...@@ -560,7 +560,7 @@ pub fn hasRuntimeBitsInner(...@@ -560,7 +560,7 @@ pub fn hasRuntimeBitsInner(
560 },560 },
561 .struct_type => {561 .struct_type => {
562 const struct_type = ip.loadStructType(ty.toIntern());562 const struct_type = ip.loadStructType(ty.toIntern());
563 if (struct_type.assumeRuntimeBitsIfFieldTypesWip(ip)) {563 if (strat != .eager and struct_type.assumeRuntimeBitsIfFieldTypesWip(ip)) {
564 // In this case, we guess that hasRuntimeBits() for this type is true,564 // In this case, we guess that hasRuntimeBits() for this type is true,
565 // and then later if our guess was incorrect, we emit a compile error.565 // and then later if our guess was incorrect, we emit a compile error.
566 return true;566 return true;
...@@ -596,7 +596,7 @@ pub fn hasRuntimeBitsInner(...@@ -596,7 +596,7 @@ pub fn hasRuntimeBitsInner(
596 const union_type = ip.loadUnionType(ty.toIntern());596 const union_type = ip.loadUnionType(ty.toIntern());
597 const union_flags = union_type.flagsUnordered(ip);597 const union_flags = union_type.flagsUnordered(ip);
598 switch (union_flags.runtime_tag) {598 switch (union_flags.runtime_tag) {
599 .none => {599 .none => if (strat != .eager) {
600 // In this case, we guess that hasRuntimeBits() for this type is true,600 // In this case, we guess that hasRuntimeBits() for this type is true,
601 // and then later if our guess was incorrect, we emit a compile error.601 // and then later if our guess was incorrect, we emit a compile error.
602 if (union_type.assumeRuntimeBitsIfFieldTypesWip(ip)) return true;602 if (union_type.assumeRuntimeBitsIfFieldTypesWip(ip)) return true;
...@@ -774,7 +774,7 @@ pub fn fnHasRuntimeBitsSema(ty: Type, pt: Zcu.PerThread) SemaError!bool {...@@ -774,7 +774,7 @@ pub fn fnHasRuntimeBitsSema(ty: Type, pt: Zcu.PerThread) SemaError!bool {
774pub fn fnHasRuntimeBitsInner(774pub fn fnHasRuntimeBitsInner(
775 ty: Type,775 ty: Type,
776 comptime strat: ResolveStrat,776 comptime strat: ResolveStrat,
777 zcu: *Zcu,777 zcu: strat.ZcuPtr(),
778 tid: strat.Tid(),778 tid: strat.Tid(),
779) SemaError!bool {779) SemaError!bool {
780 const fn_info = zcu.typeToFunc(ty).?;780 const fn_info = zcu.typeToFunc(ty).?;
...@@ -815,7 +815,7 @@ pub fn ptrAlignmentSema(ty: Type, pt: Zcu.PerThread) SemaError!Alignment {...@@ -815,7 +815,7 @@ pub fn ptrAlignmentSema(ty: Type, pt: Zcu.PerThread) SemaError!Alignment {
815pub fn ptrAlignmentInner(815pub fn ptrAlignmentInner(
816 ty: Type,816 ty: Type,
817 comptime strat: ResolveStrat,817 comptime strat: ResolveStrat,
818 zcu: *Zcu,818 zcu: strat.ZcuPtr(),
819 tid: strat.Tid(),819 tid: strat.Tid(),
820) !Alignment {820) !Alignment {
821 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {821 return switch (zcu.intern_pool.indexToKey(ty.toIntern())) {
...@@ -868,14 +868,25 @@ pub const ResolveStratLazy = enum {...@@ -868,14 +868,25 @@ pub const ResolveStratLazy = enum {
868 /// This should typically be used from semantic analysis.868 /// This should typically be used from semantic analysis.
869 sema,869 sema,
870870
871 pub fn Tid(comptime strat: ResolveStratLazy) type {871 pub fn Tid(strat: ResolveStratLazy) type {
872 return switch (strat) {872 return switch (strat) {
873 .lazy, .sema => Zcu.PerThread.Id,873 .lazy, .sema => Zcu.PerThread.Id,
874 .eager => void,874 .eager => void,
875 };875 };
876 }876 }
877877
878 pub fn pt(comptime strat: ResolveStratLazy, zcu: *Zcu, tid: strat.Tid()) switch (strat) {878 pub fn ZcuPtr(strat: ResolveStratLazy) type {
879 return switch (strat) {
880 .eager => *const Zcu,
881 .sema, .lazy => *Zcu,
882 };
883 }
884
885 pub fn pt(
886 comptime strat: ResolveStratLazy,
887 zcu: strat.ZcuPtr(),
888 tid: strat.Tid(),
889 ) switch (strat) {
879 .lazy, .sema => Zcu.PerThread,890 .lazy, .sema => Zcu.PerThread,
880 .eager => void,891 .eager => void,
881 } {892 } {
...@@ -896,14 +907,21 @@ pub const ResolveStrat = enum {...@@ -896,14 +907,21 @@ pub const ResolveStrat = enum {
896 /// This should typically be used from semantic analysis.907 /// This should typically be used from semantic analysis.
897 sema,908 sema,
898909
899 pub fn Tid(comptime strat: ResolveStrat) type {910 pub fn Tid(strat: ResolveStrat) type {
900 return switch (strat) {911 return switch (strat) {
901 .sema => Zcu.PerThread.Id,912 .sema => Zcu.PerThread.Id,
902 .normal => void,913 .normal => void,
903 };914 };
904 }915 }
905916
906 pub fn pt(comptime strat: ResolveStrat, zcu: *Zcu, tid: strat.Tid()) switch (strat) {917 pub fn ZcuPtr(strat: ResolveStrat) type {
918 return switch (strat) {
919 .normal => *const Zcu,
920 .sema => *Zcu,
921 };
922 }
923
924 pub fn pt(comptime strat: ResolveStrat, zcu: strat.ZcuPtr(), tid: strat.Tid()) switch (strat) {
907 .sema => Zcu.PerThread,925 .sema => Zcu.PerThread,
908 .normal => void,926 .normal => void,
909 } {927 } {
...@@ -922,7 +940,7 @@ pub const ResolveStrat = enum {...@@ -922,7 +940,7 @@ pub const ResolveStrat = enum {
922};940};
923941
924/// Never returns `none`. Asserts that all necessary type resolution is already done.942/// Never returns `none`. Asserts that all necessary type resolution is already done.
925pub fn abiAlignment(ty: Type, zcu: *Zcu) Alignment {943pub fn abiAlignment(ty: Type, zcu: *const Zcu) Alignment {
926 return (ty.abiAlignmentInner(.eager, zcu, {}) catch unreachable).scalar;944 return (ty.abiAlignmentInner(.eager, zcu, {}) catch unreachable).scalar;
927}945}
928946
...@@ -939,7 +957,7 @@ pub fn abiAlignmentSema(ty: Type, pt: Zcu.PerThread) SemaError!Alignment {...@@ -939,7 +957,7 @@ pub fn abiAlignmentSema(ty: Type, pt: Zcu.PerThread) SemaError!Alignment {
939pub fn abiAlignmentInner(957pub fn abiAlignmentInner(
940 ty: Type,958 ty: Type,
941 comptime strat: ResolveStratLazy,959 comptime strat: ResolveStratLazy,
942 zcu: *Zcu,960 zcu: strat.ZcuPtr(),
943 tid: strat.Tid(),961 tid: strat.Tid(),
944) SemaError!AbiAlignmentInner {962) SemaError!AbiAlignmentInner {
945 const pt = strat.pt(zcu, tid);963 const pt = strat.pt(zcu, tid);
...@@ -1156,7 +1174,7 @@ pub fn abiAlignmentInner(...@@ -1156,7 +1174,7 @@ pub fn abiAlignmentInner(
1156fn abiAlignmentInnerErrorUnion(1174fn abiAlignmentInnerErrorUnion(
1157 ty: Type,1175 ty: Type,
1158 comptime strat: ResolveStratLazy,1176 comptime strat: ResolveStratLazy,
1159 zcu: *Zcu,1177 zcu: strat.ZcuPtr(),
1160 tid: strat.Tid(),1178 tid: strat.Tid(),
1161 payload_ty: Type,1179 payload_ty: Type,
1162) SemaError!AbiAlignmentInner {1180) SemaError!AbiAlignmentInner {
...@@ -1198,7 +1216,7 @@ fn abiAlignmentInnerErrorUnion(...@@ -1198,7 +1216,7 @@ fn abiAlignmentInnerErrorUnion(
1198fn abiAlignmentInnerOptional(1216fn abiAlignmentInnerOptional(
1199 ty: Type,1217 ty: Type,
1200 comptime strat: ResolveStratLazy,1218 comptime strat: ResolveStratLazy,
1201 zcu: *Zcu,1219 zcu: strat.ZcuPtr(),
1202 tid: strat.Tid(),1220 tid: strat.Tid(),
1203) SemaError!AbiAlignmentInner {1221) SemaError!AbiAlignmentInner {
1204 const pt = strat.pt(zcu, tid);1222 const pt = strat.pt(zcu, tid);
...@@ -1244,7 +1262,7 @@ const AbiSizeInner = union(enum) {...@@ -1244,7 +1262,7 @@ const AbiSizeInner = union(enum) {
12441262
1245/// Asserts the type has the ABI size already resolved.1263/// Asserts the type has the ABI size already resolved.
1246/// Types that return false for hasRuntimeBits() return 0.1264/// Types that return false for hasRuntimeBits() return 0.
1247pub fn abiSize(ty: Type, zcu: *Zcu) u64 {1265pub fn abiSize(ty: Type, zcu: *const Zcu) u64 {
1248 return (abiSizeInner(ty, .eager, zcu, {}) catch unreachable).scalar;1266 return (abiSizeInner(ty, .eager, zcu, {}) catch unreachable).scalar;
1249}1267}
12501268
...@@ -1269,7 +1287,7 @@ pub fn abiSizeSema(ty: Type, pt: Zcu.PerThread) SemaError!u64 {...@@ -1269,7 +1287,7 @@ pub fn abiSizeSema(ty: Type, pt: Zcu.PerThread) SemaError!u64 {
1269pub fn abiSizeInner(1287pub fn abiSizeInner(
1270 ty: Type,1288 ty: Type,
1271 comptime strat: ResolveStratLazy,1289 comptime strat: ResolveStratLazy,
1272 zcu: *Zcu,1290 zcu: strat.ZcuPtr(),
1273 tid: strat.Tid(),1291 tid: strat.Tid(),
1274) SemaError!AbiSizeInner {1292) SemaError!AbiSizeInner {
1275 const target = zcu.getTarget();1293 const target = zcu.getTarget();
...@@ -1542,7 +1560,7 @@ pub fn abiSizeInner(...@@ -1542,7 +1560,7 @@ pub fn abiSizeInner(
1542fn abiSizeInnerOptional(1560fn abiSizeInnerOptional(
1543 ty: Type,1561 ty: Type,
1544 comptime strat: ResolveStratLazy,1562 comptime strat: ResolveStratLazy,
1545 zcu: *Zcu,1563 zcu: strat.ZcuPtr(),
1546 tid: strat.Tid(),1564 tid: strat.Tid(),
1547) SemaError!AbiSizeInner {1565) SemaError!AbiSizeInner {
1548 const child_ty = ty.optionalChild(zcu);1566 const child_ty = ty.optionalChild(zcu);
...@@ -1701,7 +1719,7 @@ pub fn maxIntAlignment(target: std.Target, use_llvm: bool) u16 {...@@ -1701,7 +1719,7 @@ pub fn maxIntAlignment(target: std.Target, use_llvm: bool) u16 {
1701 };1719 };
1702}1720}
17031721
1704pub fn bitSize(ty: Type, zcu: *Zcu) u64 {1722pub fn bitSize(ty: Type, zcu: *const Zcu) u64 {
1705 return bitSizeInner(ty, .normal, zcu, {}) catch unreachable;1723 return bitSizeInner(ty, .normal, zcu, {}) catch unreachable;
1706}1724}
17071725
...@@ -1712,7 +1730,7 @@ pub fn bitSizeSema(ty: Type, pt: Zcu.PerThread) SemaError!u64 {...@@ -1712,7 +1730,7 @@ pub fn bitSizeSema(ty: Type, pt: Zcu.PerThread) SemaError!u64 {
1712pub fn bitSizeInner(1730pub fn bitSizeInner(
1713 ty: Type,1731 ty: Type,
1714 comptime strat: ResolveStrat,1732 comptime strat: ResolveStrat,
1715 zcu: *Zcu,1733 zcu: strat.ZcuPtr(),
1716 tid: strat.Tid(),1734 tid: strat.Tid(),
1717) SemaError!u64 {1735) SemaError!u64 {
1718 const target = zcu.getTarget();1736 const target = zcu.getTarget();
...@@ -2148,7 +2166,7 @@ pub fn unionBackingType(ty: Type, pt: Zcu.PerThread) !Type {...@@ -2148,7 +2166,7 @@ pub fn unionBackingType(ty: Type, pt: Zcu.PerThread) !Type {
2148 };2166 };
2149}2167}
21502168
2151pub fn unionGetLayout(ty: Type, zcu: *Zcu) Zcu.UnionLayout {2169pub fn unionGetLayout(ty: Type, zcu: *const Zcu) Zcu.UnionLayout {
2152 const union_obj = zcu.intern_pool.loadUnionType(ty.toIntern());2170 const union_obj = zcu.intern_pool.loadUnionType(ty.toIntern());
2153 return Type.getUnionLayout(union_obj, zcu);2171 return Type.getUnionLayout(union_obj, zcu);
2154}2172}
...@@ -2746,7 +2764,7 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {...@@ -2746,7 +2764,7 @@ pub fn onePossibleValue(starting_type: Type, pt: Zcu.PerThread) !?Value {
27462764
2747/// During semantic analysis, instead call `ty.comptimeOnlySema` which2765/// During semantic analysis, instead call `ty.comptimeOnlySema` which
2748/// resolves field types rather than asserting they are already resolved.2766/// resolves field types rather than asserting they are already resolved.
2749pub fn comptimeOnly(ty: Type, zcu: *Zcu) bool {2767pub fn comptimeOnly(ty: Type, zcu: *const Zcu) bool {
2750 return ty.comptimeOnlyInner(.normal, zcu, {}) catch unreachable;2768 return ty.comptimeOnlyInner(.normal, zcu, {}) catch unreachable;
2751}2769}
27522770
...@@ -2759,7 +2777,7 @@ pub fn comptimeOnlySema(ty: Type, pt: Zcu.PerThread) SemaError!bool {...@@ -2759,7 +2777,7 @@ pub fn comptimeOnlySema(ty: Type, pt: Zcu.PerThread) SemaError!bool {
2759pub fn comptimeOnlyInner(2777pub fn comptimeOnlyInner(
2760 ty: Type,2778 ty: Type,
2761 comptime strat: ResolveStrat,2779 comptime strat: ResolveStrat,
2762 zcu: *Zcu,2780 zcu: strat.ZcuPtr(),
2763 tid: strat.Tid(),2781 tid: strat.Tid(),
2764) SemaError!bool {2782) SemaError!bool {
2765 const ip = &zcu.intern_pool;2783 const ip = &zcu.intern_pool;
...@@ -2834,40 +2852,44 @@ pub fn comptimeOnlyInner(...@@ -2834,40 +2852,44 @@ pub fn comptimeOnlyInner(
2834 if (struct_type.layout == .@"packed")2852 if (struct_type.layout == .@"packed")
2835 return false;2853 return false;
28362854
2837 // A struct with no fields is not comptime-only.2855 return switch (strat) {
2838 return switch (struct_type.setRequiresComptimeWip(ip)) {2856 .normal => switch (struct_type.requiresComptime(ip)) {
2839 .no, .wip => false,2857 .wip => unreachable,
2840 .yes => true,2858 .no => false,
2841 .unknown => {2859 .yes => true,
2842 // Inlined `assert` so that the resolution calls below are not statically reachable.2860 .unknown => unreachable,
2843 if (strat != .sema) unreachable;2861 },
28442862 .sema => switch (struct_type.setRequiresComptimeWip(ip)) {
2845 if (struct_type.flagsUnordered(ip).field_types_wip) {2863 .no, .wip => false,
2846 struct_type.setRequiresComptime(ip, .unknown);2864 .yes => true,
2847 return false;2865 .unknown => {
2848 }2866 if (struct_type.flagsUnordered(ip).field_types_wip) {
2867 struct_type.setRequiresComptime(ip, .unknown);
2868 return false;
2869 }
28492870
2850 errdefer struct_type.setRequiresComptime(ip, .unknown);2871 errdefer struct_type.setRequiresComptime(ip, .unknown);
28512872
2852 const pt = strat.pt(zcu, tid);2873 const pt = strat.pt(zcu, tid);
2853 try ty.resolveFields(pt);2874 try ty.resolveFields(pt);
28542875
2855 for (0..struct_type.field_types.len) |i_usize| {2876 for (0..struct_type.field_types.len) |i_usize| {
2856 const i: u32 = @intCast(i_usize);2877 const i: u32 = @intCast(i_usize);
2857 if (struct_type.fieldIsComptime(ip, i)) continue;2878 if (struct_type.fieldIsComptime(ip, i)) continue;
2858 const field_ty = struct_type.field_types.get(ip)[i];2879 const field_ty = struct_type.field_types.get(ip)[i];
2859 if (try Type.fromInterned(field_ty).comptimeOnlyInner(strat, zcu, tid)) {2880 if (try Type.fromInterned(field_ty).comptimeOnlyInner(strat, zcu, tid)) {
2860 // Note that this does not cause the layout to2881 // Note that this does not cause the layout to
2861 // be considered resolved. Comptime-only types2882 // be considered resolved. Comptime-only types
2862 // still maintain a layout of their2883 // still maintain a layout of their
2863 // runtime-known fields.2884 // runtime-known fields.
2864 struct_type.setRequiresComptime(ip, .yes);2885 struct_type.setRequiresComptime(ip, .yes);
2865 return true;2886 return true;
2887 }
2866 }2888 }
2867 }
28682889
2869 struct_type.setRequiresComptime(ip, .no);2890 struct_type.setRequiresComptime(ip, .no);
2870 return false;2891 return false;
2892 },
2871 },2893 },
2872 };2894 };
2873 },2895 },
...@@ -2882,35 +2904,40 @@ pub fn comptimeOnlyInner(...@@ -2882,35 +2904,40 @@ pub fn comptimeOnlyInner(
28822904
2883 .union_type => {2905 .union_type => {
2884 const union_type = ip.loadUnionType(ty.toIntern());2906 const union_type = ip.loadUnionType(ty.toIntern());
2885 switch (union_type.setRequiresComptimeWip(ip)) {2907 return switch (strat) {
2886 .no, .wip => return false,2908 .normal => switch (union_type.requiresComptime(ip)) {
2887 .yes => return true,2909 .wip => unreachable,
2888 .unknown => {2910 .no => false,
2889 // Inlined `assert` so that the resolution calls below are not statically reachable.2911 .yes => true,
2890 if (strat != .sema) unreachable;2912 .unknown => unreachable,
28912913 },
2892 if (union_type.flagsUnordered(ip).status == .field_types_wip) {2914 .sema => switch (union_type.setRequiresComptimeWip(ip)) {
2893 union_type.setRequiresComptime(ip, .unknown);2915 .no, .wip => return false,
2894 return false;2916 .yes => return true,
2895 }2917 .unknown => {
2918 if (union_type.flagsUnordered(ip).status == .field_types_wip) {
2919 union_type.setRequiresComptime(ip, .unknown);
2920 return false;
2921 }
28962922
2897 errdefer union_type.setRequiresComptime(ip, .unknown);2923 errdefer union_type.setRequiresComptime(ip, .unknown);
28982924
2899 const pt = strat.pt(zcu, tid);2925 const pt = strat.pt(zcu, tid);
2900 try ty.resolveFields(pt);2926 try ty.resolveFields(pt);
29012927
2902 for (0..union_type.field_types.len) |field_idx| {2928 for (0..union_type.field_types.len) |field_idx| {
2903 const field_ty = union_type.field_types.get(ip)[field_idx];2929 const field_ty = union_type.field_types.get(ip)[field_idx];
2904 if (try Type.fromInterned(field_ty).comptimeOnlyInner(strat, zcu, tid)) {2930 if (try Type.fromInterned(field_ty).comptimeOnlyInner(strat, zcu, tid)) {
2905 union_type.setRequiresComptime(ip, .yes);2931 union_type.setRequiresComptime(ip, .yes);
2906 return true;2932 return true;
2933 }
2907 }2934 }
2908 }
29092935
2910 union_type.setRequiresComptime(ip, .no);2936 union_type.setRequiresComptime(ip, .no);
2911 return false;2937 return false;
2938 },
2912 },2939 },
2913 }2940 };
2914 },2941 },
29152942
2916 .opaque_type => false,2943 .opaque_type => false,
...@@ -3207,7 +3234,7 @@ pub fn fieldAlignmentInner(...@@ -3207,7 +3234,7 @@ pub fn fieldAlignmentInner(
3207 ty: Type,3234 ty: Type,
3208 index: usize,3235 index: usize,
3209 comptime strat: ResolveStrat,3236 comptime strat: ResolveStrat,
3210 zcu: *Zcu,3237 zcu: strat.ZcuPtr(),
3211 tid: strat.Tid(),3238 tid: strat.Tid(),
3212) SemaError!Alignment {3239) SemaError!Alignment {
3213 const ip = &zcu.intern_pool;3240 const ip = &zcu.intern_pool;
...@@ -3281,7 +3308,7 @@ pub fn structFieldAlignmentInner(...@@ -3281,7 +3308,7 @@ pub fn structFieldAlignmentInner(
3281 explicit_alignment: Alignment,3308 explicit_alignment: Alignment,
3282 layout: std.builtin.Type.ContainerLayout,3309 layout: std.builtin.Type.ContainerLayout,
3283 comptime strat: Type.ResolveStrat,3310 comptime strat: Type.ResolveStrat,
3284 zcu: *Zcu,3311 zcu: strat.ZcuPtr(),
3285 tid: strat.Tid(),3312 tid: strat.Tid(),
3286) SemaError!Alignment {3313) SemaError!Alignment {
3287 assert(layout != .@"packed");3314 assert(layout != .@"packed");
...@@ -3323,7 +3350,7 @@ pub fn unionFieldAlignmentInner(...@@ -3323,7 +3350,7 @@ pub fn unionFieldAlignmentInner(
3323 explicit_alignment: Alignment,3350 explicit_alignment: Alignment,
3324 layout: std.builtin.Type.ContainerLayout,3351 layout: std.builtin.Type.ContainerLayout,
3325 comptime strat: Type.ResolveStrat,3352 comptime strat: Type.ResolveStrat,
3326 zcu: *Zcu,3353 zcu: strat.ZcuPtr(),
3327 tid: strat.Tid(),3354 tid: strat.Tid(),
3328) SemaError!Alignment {3355) SemaError!Alignment {
3329 assert(layout != .@"packed");3356 assert(layout != .@"packed");
...@@ -3392,11 +3419,7 @@ pub const FieldOffset = struct {...@@ -3392,11 +3419,7 @@ pub const FieldOffset = struct {
3392};3419};
33933420
3394/// Supports structs and unions.3421/// Supports structs and unions.
3395pub fn structFieldOffset(3422pub fn structFieldOffset(ty: Type, index: usize, zcu: *const Zcu) u64 {
3396 ty: Type,
3397 index: usize,
3398 zcu: *Zcu,
3399) u64 {
3400 const ip = &zcu.intern_pool;3423 const ip = &zcu.intern_pool;
3401 switch (ip.indexToKey(ty.toIntern())) {3424 switch (ip.indexToKey(ty.toIntern())) {
3402 .struct_type => {3425 .struct_type => {
...@@ -3944,7 +3967,7 @@ fn resolveUnionInner(...@@ -3944,7 +3967,7 @@ fn resolveUnionInner(
3944 };3967 };
3945}3968}
39463969
3947pub fn getUnionLayout(loaded_union: InternPool.LoadedUnionType, zcu: *Zcu) Zcu.UnionLayout {3970pub fn getUnionLayout(loaded_union: InternPool.LoadedUnionType, zcu: *const Zcu) Zcu.UnionLayout {
3948 const ip = &zcu.intern_pool;3971 const ip = &zcu.intern_pool;
3949 assert(loaded_union.haveLayout(ip));3972 assert(loaded_union.haveLayout(ip));
3950 var most_aligned_field: u32 = undefined;3973 var most_aligned_field: u32 = undefined;
src/Zcu.zig+2-2
...@@ -3449,7 +3449,7 @@ pub fn atomicPtrAlignment(...@@ -3449,7 +3449,7 @@ pub fn atomicPtrAlignment(
3449/// * `@TypeOf(.{})`3449/// * `@TypeOf(.{})`
3450/// * A struct which has no fields (`struct {}`).3450/// * A struct which has no fields (`struct {}`).
3451/// * Not a struct.3451/// * Not a struct.
3452pub fn typeToStruct(zcu: *Zcu, ty: Type) ?InternPool.LoadedStructType {3452pub fn typeToStruct(zcu: *const Zcu, ty: Type) ?InternPool.LoadedStructType {
3453 if (ty.ip_index == .none) return null;3453 if (ty.ip_index == .none) return null;
3454 const ip = &zcu.intern_pool;3454 const ip = &zcu.intern_pool;
3455 return switch (ip.indexToKey(ty.ip_index)) {3455 return switch (ip.indexToKey(ty.ip_index)) {
...@@ -3458,7 +3458,7 @@ pub fn typeToStruct(zcu: *Zcu, ty: Type) ?InternPool.LoadedStructType {...@@ -3458,7 +3458,7 @@ pub fn typeToStruct(zcu: *Zcu, ty: Type) ?InternPool.LoadedStructType {
3458 };3458 };
3459}3459}
34603460
3461pub fn typeToPackedStruct(zcu: *Zcu, ty: Type) ?InternPool.LoadedStructType {3461pub fn typeToPackedStruct(zcu: *const Zcu, ty: Type) ?InternPool.LoadedStructType {
3462 const s = zcu.typeToStruct(ty) orelse return null;3462 const s = zcu.typeToStruct(ty) orelse return null;
3463 if (s.layout != .@"packed") return null;3463 if (s.layout != .@"packed") return null;
3464 return s;3464 return s;