authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-07-11 10:47:23-04:00
committergravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-07-13 04:47:38-04:00
loga1053e8e1d961ba92ce83a8ef5470ac7f7e92e60
treec59338917f7e80fc8bfe8106363a612a9e52b024
parentd72a8db2db1a5c77af2deb713248dc53f9adcb73

InternPool: add and use a mutate mutex for each list

This allows the mutate mutex to only be locked during actual grows, which are rare. For the lists that didn't previously have a mutex, this change has little effect since grows are rare and there is zero contention on a mutex that is only ever locked by one thread. This change allows `extra` to be mutated without racing with a grow.

24 files changed, 814 insertions(+), 406 deletions(-)

src/Air/types_resolved.zig+3-3
......@@ -501,8 +501,8 @@ fn checkType(ty: Type, zcu: *Zcu) bool {
501501 .struct_type => {
502502 const struct_obj = zcu.typeToStruct(ty).?;
503503 return switch (struct_obj.layout) {
504 .@"packed" => struct_obj.backingIntType(ip).* != .none,
505 .auto, .@"extern" => struct_obj.flagsPtr(ip).fully_resolved,
504 .@"packed" => struct_obj.backingIntTypeUnordered(ip) != .none,
505 .auto, .@"extern" => struct_obj.flagsUnordered(ip).fully_resolved,
506506 };
507507 },
508508 .anon_struct_type => |tuple| {
......@@ -516,6 +516,6 @@ fn checkType(ty: Type, zcu: *Zcu) bool {
516516 },
517517 else => unreachable,
518518 },
519 .Union => return zcu.typeToUnion(ty).?.flagsPtr(ip).status == .fully_resolved,
519 .Union => return zcu.typeToUnion(ty).?.flagsUnordered(ip).status == .fully_resolved,
520520 };
521521}
src/Compilation.zig+2-2
......@@ -3011,7 +3011,7 @@ pub fn totalErrorCount(comp: *Compilation) u32 {
30113011 }
30123012 }
30133013
3014 if (zcu.intern_pool.global_error_set.mutate.list.len > zcu.error_limit) {
3014 if (zcu.intern_pool.global_error_set.getNamesFromMainThread().len > zcu.error_limit) {
30153015 total += 1;
30163016 }
30173017 }
......@@ -3140,7 +3140,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
31403140 try addModuleErrorMsg(zcu, &bundle, value.*, &all_references);
31413141 }
31423142
3143 const actual_error_count = zcu.intern_pool.global_error_set.mutate.list.len;
3143 const actual_error_count = zcu.intern_pool.global_error_set.getNamesFromMainThread().len;
31443144 if (actual_error_count > zcu.error_limit) {
31453145 try bundle.addRootErrorMessage(.{
31463146 .msg = try bundle.printString("ZCU used more errors than possible: used {d}, max {d}", .{
src/InternPool.zig+584-153
......@@ -147,8 +147,6 @@ pub fn trackZir(
147147 }
148148 defer shard.mutate.tracked_inst_map.len += 1;
149149 const local = ip.getLocal(tid);
150 local.mutate.tracked_insts.mutex.lock();
151 defer local.mutate.tracked_insts.mutex.unlock();
152150 const list = local.getMutableTrackedInsts(gpa);
153151 try list.ensureUnusedCapacity(1);
154152 const map_header = map.header().*;
......@@ -418,10 +416,10 @@ const Local = struct {
418416 arena: std.heap.ArenaAllocator.State,
419417
420418 items: ListMutate,
421 extra: MutexListMutate,
419 extra: ListMutate,
422420 limbs: ListMutate,
423421 strings: ListMutate,
424 tracked_insts: MutexListMutate,
422 tracked_insts: ListMutate,
425423 files: ListMutate,
426424 maps: ListMutate,
427425
......@@ -471,20 +469,12 @@ const Local = struct {
471469 const Namespaces = List(struct { *[1 << namespaces_bucket_width]Zcu.Namespace });
472470
473471 const ListMutate = struct {
472 mutex: std.Thread.Mutex,
474473 len: u32,
475474
476475 const empty: ListMutate = .{
477 .len = 0,
478 };
479 };
480
481 const MutexListMutate = struct {
482 mutex: std.Thread.Mutex,
483 list: ListMutate,
484
485 const empty: MutexListMutate = .{
486476 .mutex = .{},
487 .list = ListMutate.empty,
477 .len = 0,
488478 };
489479 };
490480
......@@ -694,6 +684,8 @@ const Local = struct {
694684 const new_slice = new_list.view().slice();
695685 inline for (fields) |field| @memcpy(new_slice.items(field)[0..len], old_slice.items(field)[0..len]);
696686 }
687 mutable.mutate.mutex.lock();
688 defer mutable.mutate.mutex.unlock();
697689 mutable.list.release(new_list);
698690 }
699691
......@@ -760,7 +752,7 @@ const Local = struct {
760752 return .{
761753 .gpa = gpa,
762754 .arena = &local.mutate.arena,
763 .mutate = &local.mutate.extra.list,
755 .mutate = &local.mutate.extra,
764756 .list = &local.shared.extra,
765757 };
766758 }
......@@ -802,7 +794,7 @@ const Local = struct {
802794 return .{
803795 .gpa = gpa,
804796 .arena = &local.mutate.arena,
805 .mutate = &local.mutate.tracked_insts.list,
797 .mutate = &local.mutate.tracked_insts,
806798 .list = &local.shared.tracked_insts,
807799 };
808800 }
......@@ -1714,29 +1706,76 @@ pub const Key = union(enum) {
17141706 comptime_args: Index.Slice,
17151707
17161708 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.
1717 pub fn analysis(func: *const Func, ip: *const InternPool) *FuncAnalysis {
1709 fn analysisPtr(func: Func, ip: *InternPool) *FuncAnalysis {
17181710 const extra = ip.getLocalShared(func.tid).extra.acquire();
17191711 return @ptrCast(&extra.view().items(.@"0")[func.analysis_extra_index]);
17201712 }
17211713
1714 pub fn analysisUnordered(func: Func, ip: *const InternPool) FuncAnalysis {
1715 return @atomicLoad(FuncAnalysis, func.analysisPtr(@constCast(ip)), .unordered);
1716 }
1717
1718 pub fn setAnalysisState(func: Func, ip: *InternPool, state: FuncAnalysis.State) void {
1719 const extra_mutex = &ip.getLocal(func.tid).mutate.extra.mutex;
1720 extra_mutex.lock();
1721 defer extra_mutex.unlock();
1722
1723 const analysis_ptr = func.analysisPtr(ip);
1724 var analysis = analysis_ptr.*;
1725 analysis.state = state;
1726 @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release);
1727 }
1728
1729 pub fn setCallsOrAwaitsErrorableFn(func: Func, ip: *InternPool, value: bool) void {
1730 const extra_mutex = &ip.getLocal(func.tid).mutate.extra.mutex;
1731 extra_mutex.lock();
1732 defer extra_mutex.unlock();
1733
1734 const analysis_ptr = func.analysisPtr(ip);
1735 var analysis = analysis_ptr.*;
1736 analysis.calls_or_awaits_errorable_fn = value;
1737 @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release);
1738 }
1739
17221740 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.
1723 pub fn zirBodyInst(func: *const Func, ip: *const InternPool) *TrackedInst.Index {
1741 fn zirBodyInstPtr(func: Func, ip: *InternPool) *TrackedInst.Index {
17241742 const extra = ip.getLocalShared(func.tid).extra.acquire();
17251743 return @ptrCast(&extra.view().items(.@"0")[func.zir_body_inst_extra_index]);
17261744 }
17271745
1746 pub fn zirBodyInstUnordered(func: Func, ip: *const InternPool) TrackedInst.Index {
1747 return @atomicLoad(TrackedInst.Index, func.zirBodyInstPtr(@constCast(ip)), .unordered);
1748 }
1749
17281750 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.
1729 pub fn branchQuota(func: *const Func, ip: *const InternPool) *u32 {
1751 fn branchQuotaPtr(func: Func, ip: *InternPool) *u32 {
17301752 const extra = ip.getLocalShared(func.tid).extra.acquire();
17311753 return &extra.view().items(.@"0")[func.branch_quota_extra_index];
17321754 }
17331755
1756 pub fn branchQuotaUnordered(func: Func, ip: *const InternPool) u32 {
1757 return @atomicLoad(u32, func.branchQuotaPtr(@constCast(ip)), .unordered);
1758 }
1759
1760 pub fn maxBranchQuota(func: Func, ip: *InternPool, new_branch_quota: u32) void {
1761 const extra_mutex = &ip.getLocal(func.tid).mutate.extra.mutex;
1762 extra_mutex.lock();
1763 defer extra_mutex.unlock();
1764
1765 const branch_quota_ptr = func.branchQuotaPtr(ip);
1766 @atomicStore(u32, branch_quota_ptr, @max(branch_quota_ptr.*, new_branch_quota), .release);
1767 }
1768
17341769 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.
1735 pub fn resolvedErrorSet(func: *const Func, ip: *const InternPool) *Index {
1770 fn resolvedErrorSetPtr(func: Func, ip: *InternPool) *Index {
17361771 const extra = ip.getLocalShared(func.tid).extra.acquire();
1737 assert(func.analysis(ip).inferred_error_set);
1772 assert(func.analysisUnordered(ip).inferred_error_set);
17381773 return @ptrCast(&extra.view().items(.@"0")[func.resolved_error_set_extra_index]);
17391774 }
1775
1776 pub fn resolvedErrorSetUnordered(func: Func, ip: *const InternPool) Index {
1777 return @atomicLoad(Index, func.resolvedErrorSetPtr(@constCast(ip)), .unordered);
1778 }
17401779 };
17411780
17421781 pub const Int = struct {
......@@ -2663,47 +2702,170 @@ pub const LoadedUnionType = struct {
26632702 /// This accessor is provided so that the tag type can be mutated, and so that
26642703 /// when it is mutated, the mutations are observed.
26652704 /// The returned pointer expires with any addition to the `InternPool`.
2666 pub fn tagTypePtr(self: LoadedUnionType, ip: *const InternPool) *Index {
2705 fn tagTypePtr(self: LoadedUnionType, ip: *InternPool) *Index {
26672706 const extra = ip.getLocalShared(self.tid).extra.acquire();
26682707 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "tag_ty").?;
26692708 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + field_index]);
26702709 }
26712710
2711 pub fn tagTypeUnordered(u: LoadedUnionType, ip: *const InternPool) Index {
2712 return @atomicLoad(Index, u.tagTypePtr(@constCast(ip)), .unordered);
2713 }
2714
2715 pub fn setTagType(u: LoadedUnionType, ip: *InternPool, tag_type: Index) void {
2716 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2717 extra_mutex.lock();
2718 defer extra_mutex.unlock();
2719
2720 @atomicStore(Index, u.tagTypePtr(ip), tag_type, .release);
2721 }
2722
26722723 /// The returned pointer expires with any addition to the `InternPool`.
2673 pub fn flagsPtr(self: LoadedUnionType, ip: *const InternPool) *Tag.TypeUnion.Flags {
2724 fn flagsPtr(self: LoadedUnionType, ip: *InternPool) *Tag.TypeUnion.Flags {
26742725 const extra = ip.getLocalShared(self.tid).extra.acquire();
26752726 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "flags").?;
26762727 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + field_index]);
26772728 }
26782729
2730 pub fn flagsUnordered(u: LoadedUnionType, ip: *const InternPool) Tag.TypeUnion.Flags {
2731 return @atomicLoad(Tag.TypeUnion.Flags, u.flagsPtr(@constCast(ip)), .unordered);
2732 }
2733
2734 pub fn setStatus(u: LoadedUnionType, ip: *InternPool, status: Status) void {
2735 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2736 extra_mutex.lock();
2737 defer extra_mutex.unlock();
2738
2739 const flags_ptr = u.flagsPtr(ip);
2740 var flags = flags_ptr.*;
2741 flags.status = status;
2742 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2743 }
2744
2745 pub fn setStatusIfLayoutWip(u: LoadedUnionType, ip: *InternPool, status: Status) void {
2746 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2747 extra_mutex.lock();
2748 defer extra_mutex.unlock();
2749
2750 const flags_ptr = u.flagsPtr(ip);
2751 var flags = flags_ptr.*;
2752 if (flags.status == .layout_wip) flags.status = status;
2753 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2754 }
2755
2756 pub fn setAlignment(u: LoadedUnionType, ip: *InternPool, alignment: Alignment) void {
2757 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2758 extra_mutex.lock();
2759 defer extra_mutex.unlock();
2760
2761 const flags_ptr = u.flagsPtr(ip);
2762 var flags = flags_ptr.*;
2763 flags.alignment = alignment;
2764 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2765 }
2766
2767 pub fn assumeRuntimeBitsIfFieldTypesWip(u: LoadedUnionType, ip: *InternPool) bool {
2768 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2769 extra_mutex.lock();
2770 defer extra_mutex.unlock();
2771
2772 const flags_ptr = u.flagsPtr(ip);
2773 var flags = flags_ptr.*;
2774 defer if (flags.status == .field_types_wip) {
2775 flags.assumed_runtime_bits = true;
2776 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2777 };
2778 return flags.status == .field_types_wip;
2779 }
2780
2781 pub fn setRequiresComptimeWip(u: LoadedUnionType, ip: *InternPool) RequiresComptime {
2782 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2783 extra_mutex.lock();
2784 defer extra_mutex.unlock();
2785
2786 const flags_ptr = u.flagsPtr(ip);
2787 var flags = flags_ptr.*;
2788 defer if (flags.requires_comptime == .unknown) {
2789 flags.requires_comptime = .wip;
2790 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2791 };
2792 return flags.requires_comptime;
2793 }
2794
2795 pub fn setRequiresComptime(u: LoadedUnionType, ip: *InternPool, requires_comptime: RequiresComptime) void {
2796 assert(requires_comptime != .wip); // see setRequiresComptimeWip
2797
2798 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2799 extra_mutex.lock();
2800 defer extra_mutex.unlock();
2801
2802 const flags_ptr = u.flagsPtr(ip);
2803 var flags = flags_ptr.*;
2804 flags.requires_comptime = requires_comptime;
2805 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2806 }
2807
2808 pub fn assumePointerAlignedIfFieldTypesWip(u: LoadedUnionType, ip: *InternPool, ptr_align: Alignment) bool {
2809 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2810 extra_mutex.lock();
2811 defer extra_mutex.unlock();
2812
2813 const flags_ptr = u.flagsPtr(ip);
2814 var flags = flags_ptr.*;
2815 defer if (flags.status == .field_types_wip) {
2816 flags.alignment = ptr_align;
2817 flags.assumed_pointer_aligned = true;
2818 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2819 };
2820 return flags.status == .field_types_wip;
2821 }
2822
26792823 /// The returned pointer expires with any addition to the `InternPool`.
2680 pub fn size(self: LoadedUnionType, ip: *const InternPool) *u32 {
2824 fn sizePtr(self: LoadedUnionType, ip: *InternPool) *u32 {
26812825 const extra = ip.getLocalShared(self.tid).extra.acquire();
26822826 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "size").?;
26832827 return &extra.view().items(.@"0")[self.extra_index + field_index];
26842828 }
26852829
2830 pub fn sizeUnordered(u: LoadedUnionType, ip: *const InternPool) u32 {
2831 return @atomicLoad(u32, u.sizePtr(@constCast(ip)), .unordered);
2832 }
2833
26862834 /// The returned pointer expires with any addition to the `InternPool`.
2687 pub fn padding(self: LoadedUnionType, ip: *const InternPool) *u32 {
2835 fn paddingPtr(self: LoadedUnionType, ip: *InternPool) *u32 {
26882836 const extra = ip.getLocalShared(self.tid).extra.acquire();
26892837 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "padding").?;
26902838 return &extra.view().items(.@"0")[self.extra_index + field_index];
26912839 }
26922840
2841 pub fn paddingUnordered(u: LoadedUnionType, ip: *const InternPool) u32 {
2842 return @atomicLoad(u32, u.paddingPtr(@constCast(ip)), .unordered);
2843 }
2844
26932845 pub fn hasTag(self: LoadedUnionType, ip: *const InternPool) bool {
2694 return self.flagsPtr(ip).runtime_tag.hasTag();
2846 return self.flagsUnordered(ip).runtime_tag.hasTag();
26952847 }
26962848
26972849 pub fn haveFieldTypes(self: LoadedUnionType, ip: *const InternPool) bool {
2698 return self.flagsPtr(ip).status.haveFieldTypes();
2850 return self.flagsUnordered(ip).status.haveFieldTypes();
26992851 }
27002852
27012853 pub fn haveLayout(self: LoadedUnionType, ip: *const InternPool) bool {
2702 return self.flagsPtr(ip).status.haveLayout();
2854 return self.flagsUnordered(ip).status.haveLayout();
27032855 }
27042856
2705 pub fn getLayout(self: LoadedUnionType, ip: *const InternPool) std.builtin.Type.ContainerLayout {
2706 return self.flagsPtr(ip).layout;
2857 pub fn setHaveLayout(u: LoadedUnionType, ip: *InternPool, size: u32, padding: u32, alignment: Alignment) void {
2858 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2859 extra_mutex.lock();
2860 defer extra_mutex.unlock();
2861
2862 @atomicStore(u32, u.sizePtr(ip), size, .unordered);
2863 @atomicStore(u32, u.paddingPtr(ip), padding, .unordered);
2864 const flags_ptr = u.flagsPtr(ip);
2865 var flags = flags_ptr.*;
2866 flags.alignment = alignment;
2867 flags.status = .have_layout;
2868 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
27072869 }
27082870
27092871 pub fn fieldAlign(self: LoadedUnionType, ip: *const InternPool, field_index: usize) Alignment {
......@@ -2726,7 +2888,7 @@ pub const LoadedUnionType = struct {
27262888
27272889 pub fn setFieldAligns(self: LoadedUnionType, ip: *const InternPool, aligns: []const Alignment) void {
27282890 if (aligns.len == 0) return;
2729 assert(self.flagsPtr(ip).any_aligned_fields);
2891 assert(self.flagsUnordered(ip).any_aligned_fields);
27302892 @memcpy(self.field_aligns.get(ip), aligns);
27312893 }
27322894};
......@@ -2877,26 +3039,26 @@ pub const LoadedStructType = struct {
28773039 };
28783040
28793041 /// Look up field index based on field name.
2880 pub fn nameIndex(self: LoadedStructType, ip: *const InternPool, name: NullTerminatedString) ?u32 {
2881 const names_map = self.names_map.unwrap() orelse {
3042 pub fn nameIndex(s: LoadedStructType, ip: *const InternPool, name: NullTerminatedString) ?u32 {
3043 const names_map = s.names_map.unwrap() orelse {
28823044 const i = name.toUnsigned(ip) orelse return null;
2883 if (i >= self.field_types.len) return null;
3045 if (i >= s.field_types.len) return null;
28843046 return i;
28853047 };
28863048 const map = names_map.getConst(ip);
2887 const adapter: NullTerminatedString.Adapter = .{ .strings = self.field_names.get(ip) };
3049 const adapter: NullTerminatedString.Adapter = .{ .strings = s.field_names.get(ip) };
28883050 const field_index = map.getIndexAdapted(name, adapter) orelse return null;
28893051 return @intCast(field_index);
28903052 }
28913053
28923054 /// Returns the already-existing field with the same name, if any.
28933055 pub fn addFieldName(
2894 self: LoadedStructType,
3056 s: LoadedStructType,
28953057 ip: *InternPool,
28963058 name: NullTerminatedString,
28973059 ) ?u32 {
2898 const extra = ip.getLocalShared(self.tid).extra.acquire();
2899 return ip.addFieldName(extra, self.names_map.unwrap().?, self.field_names.start, name);
3060 const extra = ip.getLocalShared(s.tid).extra.acquire();
3061 return ip.addFieldName(extra, s.names_map.unwrap().?, s.field_names.start, name);
29003062 }
29013063
29023064 pub fn fieldAlign(s: LoadedStructType, ip: *const InternPool, i: usize) Alignment {
......@@ -2924,143 +3086,313 @@ pub const LoadedStructType = struct {
29243086 s.comptime_bits.setBit(ip, i);
29253087 }
29263088
3089 /// The returned pointer expires with any addition to the `InternPool`.
3090 /// Asserts the struct is not packed.
3091 fn flagsPtr(s: LoadedStructType, ip: *InternPool) *Tag.TypeStruct.Flags {
3092 assert(s.layout != .@"packed");
3093 const extra = ip.getLocalShared(s.tid).extra.acquire();
3094 const flags_field_index = std.meta.fieldIndex(Tag.TypeStruct, "flags").?;
3095 return @ptrCast(&extra.view().items(.@"0")[s.extra_index + flags_field_index]);
3096 }
3097
3098 pub fn flagsUnordered(s: LoadedStructType, ip: *const InternPool) Tag.TypeStruct.Flags {
3099 return @atomicLoad(Tag.TypeStruct.Flags, s.flagsPtr(@constCast(ip)), .unordered);
3100 }
3101
3102 /// The returned pointer expires with any addition to the `InternPool`.
3103 /// Asserts that the struct is packed.
3104 fn packedFlagsPtr(s: LoadedStructType, ip: *InternPool) *Tag.TypeStructPacked.Flags {
3105 assert(s.layout == .@"packed");
3106 const extra = ip.getLocalShared(s.tid).extra.acquire();
3107 const flags_field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?;
3108 return @ptrCast(&extra.view().items(.@"0")[s.extra_index + flags_field_index]);
3109 }
3110
3111 pub fn packedFlagsUnordered(s: LoadedStructType, ip: *const InternPool) Tag.TypeStructPacked.Flags {
3112 return @atomicLoad(Tag.TypeStructPacked.Flags, s.packedFlagsPtr(@constCast(ip)), .unordered);
3113 }
3114
29273115 /// Reads the non-opv flag calculated during AstGen. Used to short-circuit more
29283116 /// complicated logic.
2929 pub fn knownNonOpv(s: LoadedStructType, ip: *InternPool) bool {
3117 pub fn knownNonOpv(s: LoadedStructType, ip: *const InternPool) bool {
29303118 return switch (s.layout) {
29313119 .@"packed" => false,
2932 .auto, .@"extern" => s.flagsPtr(ip).known_non_opv,
3120 .auto, .@"extern" => s.flagsUnordered(ip).known_non_opv,
29333121 };
29343122 }
29353123
2936 /// The returned pointer expires with any addition to the `InternPool`.
2937 /// Asserts the struct is not packed.
2938 pub fn flagsPtr(self: LoadedStructType, ip: *InternPool) *Tag.TypeStruct.Flags {
2939 assert(self.layout != .@"packed");
2940 const extra = ip.getLocalShared(self.tid).extra.acquire();
2941 const flags_field_index = std.meta.fieldIndex(Tag.TypeStruct, "flags").?;
2942 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + flags_field_index]);
3124 pub fn requiresComptime(s: LoadedStructType, ip: *const InternPool) RequiresComptime {
3125 return s.flagsUnordered(ip).requires_comptime;
29433126 }
29443127
2945 /// The returned pointer expires with any addition to the `InternPool`.
2946 /// Asserts that the struct is packed.
2947 pub fn packedFlagsPtr(self: LoadedStructType, ip: *InternPool) *Tag.TypeStructPacked.Flags {
2948 assert(self.layout == .@"packed");
2949 const extra = ip.getLocalShared(self.tid).extra.acquire();
2950 const flags_field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?;
2951 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + flags_field_index]);
3128 pub fn setRequiresComptimeWip(s: LoadedStructType, ip: *InternPool) RequiresComptime {
3129 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3130 extra_mutex.lock();
3131 defer extra_mutex.unlock();
3132
3133 const flags_ptr = s.flagsPtr(ip);
3134 var flags = flags_ptr.*;
3135 defer if (flags.requires_comptime == .unknown) {
3136 flags.requires_comptime = .wip;
3137 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3138 };
3139 return flags.requires_comptime;
3140 }
3141
3142 pub fn setRequiresComptime(s: LoadedStructType, ip: *InternPool, requires_comptime: RequiresComptime) void {
3143 assert(requires_comptime != .wip); // see setRequiresComptimeWip
3144
3145 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3146 extra_mutex.lock();
3147 defer extra_mutex.unlock();
3148
3149 const flags_ptr = s.flagsPtr(ip);
3150 var flags = flags_ptr.*;
3151 flags.requires_comptime = requires_comptime;
3152 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
29523153 }
29533154
29543155 pub fn assumeRuntimeBitsIfFieldTypesWip(s: LoadedStructType, ip: *InternPool) bool {
29553156 if (s.layout == .@"packed") return false;
3157
3158 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3159 extra_mutex.lock();
3160 defer extra_mutex.unlock();
3161
29563162 const flags_ptr = s.flagsPtr(ip);
2957 if (flags_ptr.field_types_wip) {
2958 flags_ptr.assumed_runtime_bits = true;
2959 return true;
2960 }
2961 return false;
3163 var flags = flags_ptr.*;
3164 defer if (flags.field_types_wip) {
3165 flags.assumed_runtime_bits = true;
3166 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3167 };
3168 return flags.field_types_wip;
29623169 }
29633170
2964 pub fn setTypesWip(s: LoadedStructType, ip: *InternPool) bool {
3171 pub fn setFieldTypesWip(s: LoadedStructType, ip: *InternPool) bool {
29653172 if (s.layout == .@"packed") return false;
3173
3174 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3175 extra_mutex.lock();
3176 defer extra_mutex.unlock();
3177
29663178 const flags_ptr = s.flagsPtr(ip);
2967 if (flags_ptr.field_types_wip) return true;
2968 flags_ptr.field_types_wip = true;
2969 return false;
3179 var flags = flags_ptr.*;
3180 defer {
3181 flags.field_types_wip = true;
3182 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3183 }
3184 return flags.field_types_wip;
29703185 }
29713186
2972 pub fn clearTypesWip(s: LoadedStructType, ip: *InternPool) void {
3187 pub fn clearFieldTypesWip(s: LoadedStructType, ip: *InternPool) void {
29733188 if (s.layout == .@"packed") return;
2974 s.flagsPtr(ip).field_types_wip = false;
3189
3190 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3191 extra_mutex.lock();
3192 defer extra_mutex.unlock();
3193
3194 const flags_ptr = s.flagsPtr(ip);
3195 var flags = flags_ptr.*;
3196 flags.field_types_wip = false;
3197 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
29753198 }
29763199
29773200 pub fn setLayoutWip(s: LoadedStructType, ip: *InternPool) bool {
29783201 if (s.layout == .@"packed") return false;
3202
3203 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3204 extra_mutex.lock();
3205 defer extra_mutex.unlock();
3206
29793207 const flags_ptr = s.flagsPtr(ip);
2980 if (flags_ptr.layout_wip) return true;
2981 flags_ptr.layout_wip = true;
2982 return false;
3208 var flags = flags_ptr.*;
3209 defer {
3210 flags.layout_wip = true;
3211 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3212 }
3213 return flags.layout_wip;
29833214 }
29843215
29853216 pub fn clearLayoutWip(s: LoadedStructType, ip: *InternPool) void {
29863217 if (s.layout == .@"packed") return;
2987 s.flagsPtr(ip).layout_wip = false;
3218
3219 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3220 extra_mutex.lock();
3221 defer extra_mutex.unlock();
3222
3223 const flags_ptr = s.flagsPtr(ip);
3224 var flags = flags_ptr.*;
3225 flags.layout_wip = false;
3226 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
29883227 }
29893228
2990 pub fn setAlignmentWip(s: LoadedStructType, ip: *InternPool) bool {
2991 if (s.layout == .@"packed") return false;
3229 pub fn setAlignment(s: LoadedStructType, ip: *InternPool, alignment: Alignment) void {
3230 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3231 extra_mutex.lock();
3232 defer extra_mutex.unlock();
3233
3234 const flags_ptr = s.flagsPtr(ip);
3235 var flags = flags_ptr.*;
3236 flags.alignment = alignment;
3237 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3238 }
3239
3240 pub fn assumePointerAlignedIfFieldTypesWip(s: LoadedStructType, ip: *InternPool, ptr_align: Alignment) bool {
3241 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3242 extra_mutex.lock();
3243 defer extra_mutex.unlock();
3244
3245 const flags_ptr = s.flagsPtr(ip);
3246 var flags = flags_ptr.*;
3247 defer if (flags.field_types_wip) {
3248 flags.alignment = ptr_align;
3249 flags.assumed_pointer_aligned = true;
3250 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3251 };
3252 return flags.field_types_wip;
3253 }
3254
3255 pub fn assumePointerAlignedIfWip(s: LoadedStructType, ip: *InternPool, ptr_align: Alignment) bool {
3256 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3257 extra_mutex.lock();
3258 defer extra_mutex.unlock();
3259
29923260 const flags_ptr = s.flagsPtr(ip);
2993 if (flags_ptr.alignment_wip) return true;
2994 flags_ptr.alignment_wip = true;
2995 return false;
3261 var flags = flags_ptr.*;
3262 defer {
3263 if (flags.alignment_wip) {
3264 flags.alignment = ptr_align;
3265 flags.assumed_pointer_aligned = true;
3266 } else flags.alignment_wip = true;
3267 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3268 }
3269 return flags.alignment_wip;
29963270 }
29973271
29983272 pub fn clearAlignmentWip(s: LoadedStructType, ip: *InternPool) void {
29993273 if (s.layout == .@"packed") return;
3000 s.flagsPtr(ip).alignment_wip = false;
3274
3275 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3276 extra_mutex.lock();
3277 defer extra_mutex.unlock();
3278
3279 const flags_ptr = s.flagsPtr(ip);
3280 var flags = flags_ptr.*;
3281 flags.alignment_wip = false;
3282 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
30013283 }
30023284
30033285 pub fn setInitsWip(s: LoadedStructType, ip: *InternPool) bool {
3004 const local = ip.getLocal(s.tid);
3005 local.mutate.extra.mutex.lock();
3006 defer local.mutate.extra.mutex.unlock();
3007 return switch (s.layout) {
3008 .@"packed" => @as(Tag.TypeStructPacked.Flags, @bitCast(@atomicRmw(
3009 u32,
3010 @as(*u32, @ptrCast(s.packedFlagsPtr(ip))),
3011 .Or,
3012 @bitCast(Tag.TypeStructPacked.Flags{ .field_inits_wip = true }),
3013 .acq_rel,
3014 ))).field_inits_wip,
3015 .auto, .@"extern" => @as(Tag.TypeStruct.Flags, @bitCast(@atomicRmw(
3016 u32,
3017 @as(*u32, @ptrCast(s.flagsPtr(ip))),
3018 .Or,
3019 @bitCast(Tag.TypeStruct.Flags{ .field_inits_wip = true }),
3020 .acq_rel,
3021 ))).field_inits_wip,
3022 };
3286 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3287 extra_mutex.lock();
3288 defer extra_mutex.unlock();
3289
3290 switch (s.layout) {
3291 .@"packed" => {
3292 const flags_ptr = s.packedFlagsPtr(ip);
3293 var flags = flags_ptr.*;
3294 defer {
3295 flags.field_inits_wip = true;
3296 @atomicStore(Tag.TypeStructPacked.Flags, flags_ptr, flags, .release);
3297 }
3298 return flags.field_inits_wip;
3299 },
3300 .auto, .@"extern" => {
3301 const flags_ptr = s.flagsPtr(ip);
3302 var flags = flags_ptr.*;
3303 defer {
3304 flags.field_inits_wip = true;
3305 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3306 }
3307 return flags.field_inits_wip;
3308 },
3309 }
30233310 }
30243311
30253312 pub fn clearInitsWip(s: LoadedStructType, ip: *InternPool) void {
3313 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3314 extra_mutex.lock();
3315 defer extra_mutex.unlock();
3316
30263317 switch (s.layout) {
3027 .@"packed" => s.packedFlagsPtr(ip).field_inits_wip = false,
3028 .auto, .@"extern" => s.flagsPtr(ip).field_inits_wip = false,
3318 .@"packed" => {
3319 const flags_ptr = s.packedFlagsPtr(ip);
3320 var flags = flags_ptr.*;
3321 flags.field_inits_wip = false;
3322 @atomicStore(Tag.TypeStructPacked.Flags, flags_ptr, flags, .release);
3323 },
3324 .auto, .@"extern" => {
3325 const flags_ptr = s.flagsPtr(ip);
3326 var flags = flags_ptr.*;
3327 flags.field_inits_wip = false;
3328 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3329 },
30293330 }
30303331 }
30313332
30323333 pub fn setFullyResolved(s: LoadedStructType, ip: *InternPool) bool {
30333334 if (s.layout == .@"packed") return true;
3335
3336 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3337 extra_mutex.lock();
3338 defer extra_mutex.unlock();
3339
30343340 const flags_ptr = s.flagsPtr(ip);
3035 if (flags_ptr.fully_resolved) return true;
3036 flags_ptr.fully_resolved = true;
3037 return false;
3341 var flags = flags_ptr.*;
3342 defer {
3343 flags.fully_resolved = true;
3344 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3345 }
3346 return flags.fully_resolved;
30383347 }
30393348
30403349 pub fn clearFullyResolved(s: LoadedStructType, ip: *InternPool) void {
3041 s.flagsPtr(ip).fully_resolved = false;
3350 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3351 extra_mutex.lock();
3352 defer extra_mutex.unlock();
3353
3354 const flags_ptr = s.flagsPtr(ip);
3355 var flags = flags_ptr.*;
3356 flags.fully_resolved = false;
3357 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
30423358 }
30433359
30443360 /// The returned pointer expires with any addition to the `InternPool`.
30453361 /// Asserts the struct is not packed.
3046 pub fn size(self: LoadedStructType, ip: *InternPool) *u32 {
3047 assert(self.layout != .@"packed");
3048 const extra = ip.getLocalShared(self.tid).extra.acquire();
3362 fn sizePtr(s: LoadedStructType, ip: *InternPool) *u32 {
3363 assert(s.layout != .@"packed");
3364 const extra = ip.getLocalShared(s.tid).extra.acquire();
30493365 const size_field_index = std.meta.fieldIndex(Tag.TypeStruct, "size").?;
3050 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + size_field_index]);
3366 return @ptrCast(&extra.view().items(.@"0")[s.extra_index + size_field_index]);
3367 }
3368
3369 pub fn sizeUnordered(s: LoadedStructType, ip: *const InternPool) u32 {
3370 return @atomicLoad(u32, s.sizePtr(@constCast(ip)), .unordered);
30513371 }
30523372
30533373 /// The backing integer type of the packed struct. Whether zig chooses
30543374 /// this type or the user specifies it, it is stored here. This will be
30553375 /// set to `none` until the layout is resolved.
30563376 /// Asserts the struct is packed.
3057 pub fn backingIntType(s: LoadedStructType, ip: *InternPool) *Index {
3377 fn backingIntTypePtr(s: LoadedStructType, ip: *InternPool) *Index {
30583378 assert(s.layout == .@"packed");
30593379 const extra = ip.getLocalShared(s.tid).extra.acquire();
30603380 const field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "backing_int_ty").?;
30613381 return @ptrCast(&extra.view().items(.@"0")[s.extra_index + field_index]);
30623382 }
30633383
3384 pub fn backingIntTypeUnordered(s: LoadedStructType, ip: *const InternPool) Index {
3385 return @atomicLoad(Index, s.backingIntTypePtr(@constCast(ip)), .unordered);
3386 }
3387
3388 pub fn setBackingIntType(s: LoadedStructType, ip: *InternPool, backing_int_ty: Index) void {
3389 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3390 extra_mutex.lock();
3391 defer extra_mutex.unlock();
3392
3393 @atomicStore(Index, s.backingIntTypePtr(ip), backing_int_ty, .release);
3394 }
3395
30643396 /// Asserts the struct is not packed.
30653397 pub fn setZirIndex(s: LoadedStructType, ip: *InternPool, new_zir_index: TrackedInst.Index.Optional) void {
30663398 assert(s.layout != .@"packed");
......@@ -3073,29 +3405,56 @@ pub const LoadedStructType = struct {
30733405 return types.len == 0 or types[0] != .none;
30743406 }
30753407
3076 pub fn haveFieldInits(s: LoadedStructType, ip: *InternPool) bool {
3408 pub fn haveFieldInits(s: LoadedStructType, ip: *const InternPool) bool {
30773409 return switch (s.layout) {
3078 .@"packed" => s.packedFlagsPtr(ip).inits_resolved,
3079 .auto, .@"extern" => s.flagsPtr(ip).inits_resolved,
3410 .@"packed" => s.packedFlagsUnordered(ip).inits_resolved,
3411 .auto, .@"extern" => s.flagsUnordered(ip).inits_resolved,
30803412 };
30813413 }
30823414
30833415 pub fn setHaveFieldInits(s: LoadedStructType, ip: *InternPool) void {
3416 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3417 extra_mutex.lock();
3418 defer extra_mutex.unlock();
3419
30843420 switch (s.layout) {
3085 .@"packed" => s.packedFlagsPtr(ip).inits_resolved = true,
3086 .auto, .@"extern" => s.flagsPtr(ip).inits_resolved = true,
3421 .@"packed" => {
3422 const flags_ptr = s.packedFlagsPtr(ip);
3423 var flags = flags_ptr.*;
3424 flags.inits_resolved = true;
3425 @atomicStore(Tag.TypeStructPacked.Flags, flags_ptr, flags, .release);
3426 },
3427 .auto, .@"extern" => {
3428 const flags_ptr = s.flagsPtr(ip);
3429 var flags = flags_ptr.*;
3430 flags.inits_resolved = true;
3431 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3432 },
30873433 }
30883434 }
30893435
30903436 pub fn haveLayout(s: LoadedStructType, ip: *InternPool) bool {
30913437 return switch (s.layout) {
3092 .@"packed" => s.backingIntType(ip).* != .none,
3093 .auto, .@"extern" => s.flagsPtr(ip).layout_resolved,
3438 .@"packed" => s.backingIntTypeUnordered(ip) != .none,
3439 .auto, .@"extern" => s.flagsUnordered(ip).layout_resolved,
30943440 };
30953441 }
30963442
3443 pub fn setLayoutResolved(s: LoadedStructType, ip: *InternPool, size: u32, alignment: Alignment) void {
3444 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3445 extra_mutex.lock();
3446 defer extra_mutex.unlock();
3447
3448 @atomicStore(u32, s.sizePtr(ip), size, .unordered);
3449 const flags_ptr = s.flagsPtr(ip);
3450 var flags = flags_ptr.*;
3451 flags.alignment = alignment;
3452 flags.layout_resolved = true;
3453 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3454 }
3455
30973456 pub fn isTuple(s: LoadedStructType, ip: *InternPool) bool {
3098 return s.layout != .@"packed" and s.flagsPtr(ip).is_tuple;
3457 return s.layout != .@"packed" and s.flagsUnordered(ip).is_tuple;
30993458 }
31003459
31013460 pub fn hasReorderedFields(s: LoadedStructType) bool {
......@@ -3209,7 +3568,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType {
32093568 const decl: DeclIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "decl").?]);
32103569 const zir_index: TrackedInst.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?]);
32113570 const fields_len = extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "fields_len").?];
3212 const flags: Tag.TypeStruct.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "flags").?], .monotonic));
3571 const flags: Tag.TypeStruct.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "flags").?], .unordered));
32133572 var extra_index = item.data + @as(u32, @typeInfo(Tag.TypeStruct).Struct.fields.len);
32143573 const captures_len = if (flags.any_captures) c: {
32153574 const len = extra_list.view().items(.@"0")[extra_index];
......@@ -3317,7 +3676,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType {
33173676 const fields_len = extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "fields_len").?];
33183677 const namespace: OptionalNamespaceIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "namespace").?]);
33193678 const names_map: MapIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "names_map").?]);
3320 const flags: Tag.TypeStructPacked.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?], .monotonic));
3679 const flags: Tag.TypeStructPacked.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?], .unordered));
33213680 var extra_index = item.data + @as(u32, @typeInfo(Tag.TypeStructPacked).Struct.fields.len);
33223681 const has_inits = item.tag == .type_struct_packed_inits;
33233682 const captures_len = if (flags.any_captures) c: {
......@@ -5442,10 +5801,10 @@ pub fn init(ip: *InternPool, gpa: Allocator, available_threads: usize) !void {
54425801 .arena = .{},
54435802
54445803 .items = Local.ListMutate.empty,
5445 .extra = Local.MutexListMutate.empty,
5804 .extra = Local.ListMutate.empty,
54465805 .limbs = Local.ListMutate.empty,
54475806 .strings = Local.ListMutate.empty,
5448 .tracked_insts = Local.MutexListMutate.empty,
5807 .tracked_insts = Local.ListMutate.empty,
54495808 .files = Local.ListMutate.empty,
54505809 .maps = Local.ListMutate.empty,
54515810
......@@ -5635,7 +5994,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
56355994 const extra_list = unwrapped_index.getExtra(ip);
56365995 const extra_items = extra_list.view().items(.@"0");
56375996 const zir_index: TrackedInst.Index = @enumFromInt(extra_items[data + std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?]);
5638 const flags: Tag.TypeStruct.Flags = @bitCast(@atomicLoad(u32, &extra_items[data + std.meta.fieldIndex(Tag.TypeStruct, "flags").?], .monotonic));
5997 const flags: Tag.TypeStruct.Flags = @bitCast(@atomicLoad(u32, &extra_items[data + std.meta.fieldIndex(Tag.TypeStruct, "flags").?], .unordered));
56395998 const end_extra_index = data + @as(u32, @typeInfo(Tag.TypeStruct).Struct.fields.len);
56405999 if (flags.is_reified) {
56416000 assert(!flags.any_captures);
......@@ -5658,7 +6017,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
56586017 const extra_list = unwrapped_index.getExtra(ip);
56596018 const extra_items = extra_list.view().items(.@"0");
56606019 const zir_index: TrackedInst.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "zir_index").?]);
5661 const flags: Tag.TypeStructPacked.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?], .monotonic));
6020 const flags: Tag.TypeStructPacked.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?], .unordered));
56626021 const end_extra_index = data + @as(u32, @typeInfo(Tag.TypeStructPacked).Struct.fields.len);
56636022 if (flags.is_reified) {
56646023 assert(!flags.any_captures);
......@@ -6155,7 +6514,7 @@ fn extraFuncDecl(tid: Zcu.PerThread.Id, extra: Local.Extra, extra_index: u32) Ke
61556514fn extraFuncInstance(ip: *const InternPool, tid: Zcu.PerThread.Id, extra: Local.Extra, extra_index: u32) Key.Func {
61566515 const extra_items = extra.view().items(.@"0");
61576516 const analysis_extra_index = extra_index + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?;
6158 const analysis: FuncAnalysis = @bitCast(@atomicLoad(u32, &extra_items[analysis_extra_index], .monotonic));
6517 const analysis: FuncAnalysis = @bitCast(@atomicLoad(u32, &extra_items[analysis_extra_index], .unordered));
61596518 const owner_decl: DeclIndex = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "owner_decl").?]);
61606519 const ty: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "ty").?]);
61616520 const generic_owner: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "generic_owner").?]);
......@@ -8702,7 +9061,7 @@ pub fn remove(ip: *InternPool, tid: Zcu.PerThread.Id, index: Index) void {
87029061 // Restore the original item at this index.
87039062 assert(static_keys[@intFromEnum(index)] == .simple_type);
87049063 const items = ip.getLocalShared(unwrapped_index.tid).items.acquire().view();
8705 @atomicStore(Tag, &items.items(.tag)[unwrapped_index.index], .simple_type, .monotonic);
9064 @atomicStore(Tag, &items.items(.tag)[unwrapped_index.index], .simple_type, .unordered);
87069065 return;
87079066 }
87089067
......@@ -8719,7 +9078,7 @@ pub fn remove(ip: *InternPool, tid: Zcu.PerThread.Id, index: Index) void {
87199078 // Thus, we will rewrite the tag to `removed`, leaking the item until
87209079 // next GC but causing `KeyAdapter` to ignore it.
87219080 const items = ip.getLocalShared(unwrapped_index.tid).items.acquire().view();
8722 @atomicStore(Tag, &items.items(.tag)[unwrapped_index.index], .removed, .monotonic);
9081 @atomicStore(Tag, &items.items(.tag)[unwrapped_index.index], .removed, .unordered);
87239082}
87249083
87259084fn addInt(
......@@ -9415,9 +9774,11 @@ pub fn errorUnionPayload(ip: *const InternPool, ty: Index) Index {
94159774/// The is only legal because the initializer is not part of the hash.
94169775pub fn mutateVarInit(ip: *InternPool, index: Index, init_index: Index) void {
94179776 const unwrapped_index = index.unwrap(ip);
9777
94189778 const local = ip.getLocal(unwrapped_index.tid);
94199779 local.mutate.extra.mutex.lock();
94209780 defer local.mutate.extra.mutex.unlock();
9781
94219782 const extra_items = local.shared.extra.view().items(.@"0");
94229783 const item = unwrapped_index.getItem(ip);
94239784 assert(item.tag == .variable);
......@@ -9436,7 +9797,7 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
94369797 var decls_len: usize = 0;
94379798 for (ip.locals) |*local| {
94389799 items_len += local.mutate.items.len;
9439 extra_len += local.mutate.extra.list.len;
9800 extra_len += local.mutate.extra.len;
94409801 limbs_len += local.mutate.limbs.len;
94419802 decls_len += local.mutate.decls.buckets_list.len;
94429803 }
......@@ -10730,29 +11091,29 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois
1073011091 };
1073111092}
1073211093
10733pub fn isFuncBody(ip: *const InternPool, index: Index) bool {
10734 return switch (index.unwrap(ip).getTag(ip)) {
11094pub fn isFuncBody(ip: *const InternPool, func: Index) bool {
11095 return switch (func.unwrap(ip).getTag(ip)) {
1073511096 .func_decl, .func_instance, .func_coerced => true,
1073611097 else => false,
1073711098 };
1073811099}
1073911100
10740pub fn funcAnalysis(ip: *const InternPool, index: Index) *FuncAnalysis {
10741 const unwrapped_index = index.unwrap(ip);
10742 const extra = unwrapped_index.getExtra(ip);
10743 const item = unwrapped_index.getItem(ip);
11101fn funcAnalysisPtr(ip: *InternPool, func: Index) *FuncAnalysis {
11102 const unwrapped_func = func.unwrap(ip);
11103 const extra = unwrapped_func.getExtra(ip);
11104 const item = unwrapped_func.getItem(ip);
1074411105 const extra_index = switch (item.tag) {
1074511106 .func_decl => item.data + std.meta.fieldIndex(Tag.FuncDecl, "analysis").?,
1074611107 .func_instance => item.data + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?,
1074711108 .func_coerced => {
1074811109 const extra_index = item.data + std.meta.fieldIndex(Tag.FuncCoerced, "func").?;
10749 const func_index: Index = @enumFromInt(extra.view().items(.@"0")[extra_index]);
10750 const unwrapped_func = func_index.unwrap(ip);
10751 const func_item = unwrapped_func.getItem(ip);
10752 return @ptrCast(&unwrapped_func.getExtra(ip).view().items(.@"0")[
10753 switch (func_item.tag) {
10754 .func_decl => func_item.data + std.meta.fieldIndex(Tag.FuncDecl, "analysis").?,
10755 .func_instance => func_item.data + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?,
11110 const coerced_func_index: Index = @enumFromInt(extra.view().items(.@"0")[extra_index]);
11111 const unwrapped_coerced_func = coerced_func_index.unwrap(ip);
11112 const coerced_func_item = unwrapped_coerced_func.getItem(ip);
11113 return @ptrCast(&unwrapped_coerced_func.getExtra(ip).view().items(.@"0")[
11114 switch (coerced_func_item.tag) {
11115 .func_decl => coerced_func_item.data + std.meta.fieldIndex(Tag.FuncDecl, "analysis").?,
11116 .func_instance => coerced_func_item.data + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?,
1075611117 else => unreachable,
1075711118 }
1075811119 ]);
......@@ -10762,14 +11123,65 @@ pub fn funcAnalysis(ip: *const InternPool, index: Index) *FuncAnalysis {
1076211123 return @ptrCast(&extra.view().items(.@"0")[extra_index]);
1076311124}
1076411125
10765pub fn funcHasInferredErrorSet(ip: *const InternPool, i: Index) bool {
10766 return funcAnalysis(ip, i).inferred_error_set;
11126pub fn funcAnalysisUnordered(ip: *const InternPool, func: Index) FuncAnalysis {
11127 return @atomicLoad(FuncAnalysis, @constCast(ip).funcAnalysisPtr(func), .unordered);
1076711128}
1076811129
10769pub fn funcZirBodyInst(ip: *const InternPool, index: Index) TrackedInst.Index {
10770 const unwrapped_index = index.unwrap(ip);
10771 const item = unwrapped_index.getItem(ip);
10772 const item_extra = unwrapped_index.getExtra(ip);
11130pub fn funcSetAnalysisState(ip: *InternPool, func: Index, state: FuncAnalysis.State) void {
11131 const unwrapped_func = func.unwrap(ip);
11132 const extra_mutex = &ip.getLocal(unwrapped_func.tid).mutate.extra.mutex;
11133 extra_mutex.lock();
11134 defer extra_mutex.unlock();
11135
11136 const analysis_ptr = ip.funcAnalysisPtr(func);
11137 var analysis = analysis_ptr.*;
11138 analysis.state = state;
11139 @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release);
11140}
11141
11142pub fn funcMaxStackAlignment(ip: *InternPool, func: Index, new_stack_alignment: Alignment) void {
11143 const unwrapped_func = func.unwrap(ip);
11144 const extra_mutex = &ip.getLocal(unwrapped_func.tid).mutate.extra.mutex;
11145 extra_mutex.lock();
11146 defer extra_mutex.unlock();
11147
11148 const analysis_ptr = ip.funcAnalysisPtr(func);
11149 var analysis = analysis_ptr.*;
11150 analysis.stack_alignment = switch (analysis.stack_alignment) {
11151 .none => new_stack_alignment,
11152 else => |old_stack_alignment| old_stack_alignment.maxStrict(new_stack_alignment),
11153 };
11154 @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release);
11155}
11156
11157pub fn funcSetCallsOrAwaitsErrorableFn(ip: *InternPool, func: Index) void {
11158 const unwrapped_func = func.unwrap(ip);
11159 const extra_mutex = &ip.getLocal(unwrapped_func.tid).mutate.extra.mutex;
11160 extra_mutex.lock();
11161 defer extra_mutex.unlock();
11162
11163 const analysis_ptr = ip.funcAnalysisPtr(func);
11164 var analysis = analysis_ptr.*;
11165 analysis.calls_or_awaits_errorable_fn = true;
11166 @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release);
11167}
11168
11169pub fn funcSetCold(ip: *InternPool, func: Index, is_cold: bool) void {
11170 const unwrapped_func = func.unwrap(ip);
11171 const extra_mutex = &ip.getLocal(unwrapped_func.tid).mutate.extra.mutex;
11172 extra_mutex.lock();
11173 defer extra_mutex.unlock();
11174
11175 const analysis_ptr = ip.funcAnalysisPtr(func);
11176 var analysis = analysis_ptr.*;
11177 analysis.is_cold = is_cold;
11178 @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release);
11179}
11180
11181pub fn funcZirBodyInst(ip: *const InternPool, func: Index) TrackedInst.Index {
11182 const unwrapped_func = func.unwrap(ip);
11183 const item = unwrapped_func.getItem(ip);
11184 const item_extra = unwrapped_func.getExtra(ip);
1077311185 const zir_body_inst_field_index = std.meta.fieldIndex(Tag.FuncDecl, "zir_body_inst").?;
1077411186 switch (item.tag) {
1077511187 .func_decl => return @enumFromInt(item_extra.view().items(.@"0")[item.data + zir_body_inst_field_index]),
......@@ -10806,17 +11218,17 @@ pub fn iesFuncIndex(ip: *const InternPool, ies_index: Index) Index {
1080611218/// Returns a mutable pointer to the resolved error set type of an inferred
1080711219/// error set function. The returned pointer is invalidated when anything is
1080811220/// added to `ip`.
10809pub fn iesResolved(ip: *const InternPool, ies_index: Index) *Index {
11221fn iesResolvedPtr(ip: *InternPool, ies_index: Index) *Index {
1081011222 const ies_item = ies_index.getItem(ip);
1081111223 assert(ies_item.tag == .type_inferred_error_set);
10812 return funcIesResolved(ip, ies_item.data);
11224 return ip.funcIesResolvedPtr(ies_item.data);
1081311225}
1081411226
1081511227/// Returns a mutable pointer to the resolved error set type of an inferred
1081611228/// error set function. The returned pointer is invalidated when anything is
1081711229/// added to `ip`.
10818pub fn funcIesResolved(ip: *const InternPool, func_index: Index) *Index {
10819 assert(funcHasInferredErrorSet(ip, func_index));
11230fn funcIesResolvedPtr(ip: *InternPool, func_index: Index) *Index {
11231 assert(ip.funcAnalysisUnordered(func_index).inferred_error_set);
1082011232 const unwrapped_func = func_index.unwrap(ip);
1082111233 const func_extra = unwrapped_func.getExtra(ip);
1082211234 const func_item = unwrapped_func.getItem(ip);
......@@ -10842,6 +11254,19 @@ pub fn funcIesResolved(ip: *const InternPool, func_index: Index) *Index {
1084211254 return @ptrCast(&func_extra.view().items(.@"0")[extra_index]);
1084311255}
1084411256
11257pub fn funcIesResolvedUnordered(ip: *const InternPool, index: Index) Index {
11258 return @atomicLoad(Index, @constCast(ip).funcIesResolvedPtr(index), .unordered);
11259}
11260
11261pub fn funcSetIesResolved(ip: *InternPool, index: Index, ies: Index) void {
11262 const unwrapped_func = index.unwrap(ip);
11263 const extra_mutex = &ip.getLocal(unwrapped_func.tid).mutate.extra.mutex;
11264 extra_mutex.lock();
11265 defer extra_mutex.unlock();
11266
11267 @atomicStore(Index, ip.funcIesResolvedPtr(index), ies, .release);
11268}
11269
1084511270pub fn funcDeclInfo(ip: *const InternPool, index: Index) Key.Func {
1084611271 const unwrapped_index = index.unwrap(ip);
1084711272 const item = unwrapped_index.getItem(ip);
......@@ -10950,7 +11375,10 @@ const GlobalErrorSet = struct {
1095011375 names: Names,
1095111376 map: Shard.Map(GlobalErrorSet.Index),
1095211377 } align(std.atomic.cache_line),
10953 mutate: Local.MutexListMutate align(std.atomic.cache_line),
11378 mutate: struct {
11379 names: Local.ListMutate,
11380 map: struct { mutex: std.Thread.Mutex },
11381 } align(std.atomic.cache_line),
1095411382
1095511383 const Names = Local.List(struct { NullTerminatedString });
1095611384
......@@ -10959,7 +11387,10 @@ const GlobalErrorSet = struct {
1095911387 .names = Names.empty,
1096011388 .map = Shard.Map(GlobalErrorSet.Index).empty,
1096111389 },
10962 .mutate = Local.MutexListMutate.empty,
11390 .mutate = .{
11391 .names = Local.ListMutate.empty,
11392 .map = .{ .mutex = .{} },
11393 },
1096311394 };
1096411395
1096511396 const Index = enum(Zcu.ErrorInt) {
......@@ -10969,7 +11400,7 @@ const GlobalErrorSet = struct {
1096911400
1097011401 /// Not thread-safe, may only be called from the main thread.
1097111402 pub fn getNamesFromMainThread(ges: *const GlobalErrorSet) []const NullTerminatedString {
10972 const len = ges.mutate.list.len;
11403 const len = ges.mutate.names.len;
1097311404 return if (len > 0) ges.shared.names.view().items(.@"0")[0..len] else &.{};
1097411405 }
1097511406
......@@ -10994,8 +11425,8 @@ const GlobalErrorSet = struct {
1099411425 if (entry.hash != hash) continue;
1099511426 if (names.view().items(.@"0")[@intFromEnum(index) - 1] == name) return index;
1099611427 }
10997 ges.mutate.mutex.lock();
10998 defer ges.mutate.mutex.unlock();
11428 ges.mutate.map.mutex.lock();
11429 defer ges.mutate.map.mutex.unlock();
1099911430 if (map.entries != ges.shared.map.entries) {
1100011431 map = ges.shared.map;
1100111432 map_mask = map.header().mask();
......@@ -11012,12 +11443,12 @@ const GlobalErrorSet = struct {
1101211443 const mutable_names: Names.Mutable = .{
1101311444 .gpa = gpa,
1101411445 .arena = arena_state,
11015 .mutate = &ges.mutate.list,
11446 .mutate = &ges.mutate.names,
1101611447 .list = &ges.shared.names,
1101711448 };
1101811449 try mutable_names.ensureUnusedCapacity(1);
1101911450 const map_header = map.header().*;
11020 if (ges.mutate.list.len < map_header.capacity * 3 / 5) {
11451 if (ges.mutate.names.len < map_header.capacity * 3 / 5) {
1102111452 mutable_names.appendAssumeCapacity(.{name});
1102211453 const index: GlobalErrorSet.Index = @enumFromInt(mutable_names.mutate.len);
1102311454 const entry = &map.entries[map_index];
src/Sema.zig+94-119
......@@ -2535,13 +2535,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
25352535 }
25362536
25372537 if (sema.owner_func_index != .none) {
2538 ip.funcAnalysis(sema.owner_func_index).state = .sema_failure;
2538 ip.funcSetAnalysisState(sema.owner_func_index, .sema_failure);
25392539 } else {
25402540 sema.owner_decl.analysis = .sema_failure;
25412541 }
25422542
25432543 if (sema.func_index != .none) {
2544 ip.funcAnalysis(sema.func_index).state = .sema_failure;
2544 ip.funcSetAnalysisState(sema.func_index, .sema_failure);
25452545 }
25462546
25472547 return error.AnalysisFail;
......@@ -6555,14 +6555,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
65556555 }
65566556 sema.prev_stack_alignment_src = src;
65576557
6558 const ip = &mod.intern_pool;
6559 const a = ip.funcAnalysis(sema.func_index);
6560 if (a.stack_alignment != .none) {
6561 a.stack_alignment = @enumFromInt(@max(
6562 @intFromEnum(alignment),
6563 @intFromEnum(a.stack_alignment),
6564 ));
6565 }
6558 mod.intern_pool.funcMaxStackAlignment(sema.func_index, alignment);
65666559}
65676560
65686561fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
......@@ -6575,7 +6568,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
65756568 .needed_comptime_reason = "operand to @setCold must be comptime-known",
65766569 });
65776570 if (sema.func_index == .none) return; // does nothing outside a function
6578 ip.funcAnalysis(sema.func_index).is_cold = is_cold;
6571 ip.funcSetCold(sema.func_index, is_cold);
65796572}
65806573
65816574fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
......@@ -7090,7 +7083,7 @@ fn zirCall(
70907083 const call_inst = try sema.analyzeCall(block, func, func_ty, callee_src, call_src, modifier, ensure_result_used, args_info, call_dbg_node, .call);
70917084
70927085 if (sema.owner_func_index == .none or
7093 !mod.intern_pool.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn)
7086 !mod.intern_pool.funcAnalysisUnordered(sema.owner_func_index).calls_or_awaits_errorable_fn)
70947087 {
70957088 // No errorable fn actually called; we have no error return trace
70967089 input_is_error = false;
......@@ -7798,7 +7791,7 @@ fn analyzeCall(
77987791 _ = ics.callee();
77997792
78007793 if (!inlining.has_comptime_args) {
7801 if (module_fn.analysis(ip).state == .sema_failure)
7794 if (module_fn.analysisUnordered(ip).state == .sema_failure)
78027795 return error.AnalysisFail;
78037796
78047797 var block_it = block;
......@@ -7821,7 +7814,7 @@ fn analyzeCall(
78217814 try sema.resolveInst(fn_info.ret_ty_ref);
78227815 const ret_ty_src: LazySrcLoc = .{ .base_node_inst = module_fn.zir_body_inst, .offset = .{ .node_offset_fn_type_ret_ty = 0 } };
78237816 sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);
7824 if (module_fn.analysis(ip).inferred_error_set) {
7817 if (module_fn.analysisUnordered(ip).inferred_error_set) {
78257818 // Create a fresh inferred error set type for inline/comptime calls.
78267819 const ies = try sema.arena.create(InferredErrorSet);
78277820 ies.* = .{ .func = .none };
......@@ -7947,7 +7940,7 @@ fn analyzeCall(
79477940 if (call_dbg_node) |some| try sema.zirDbgStmt(block, some);
79487941
79497942 if (sema.owner_func_index != .none and Type.fromInterned(func_ty_info.return_type).isError(mod)) {
7950 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;
7943 ip.funcSetCallsOrAwaitsErrorableFn(sema.owner_func_index);
79517944 }
79527945
79537946 if (try sema.resolveValue(func)) |func_val| {
......@@ -8391,7 +8384,7 @@ fn instantiateGenericCall(
83918384 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern();
83928385
83938386 const callee = zcu.funcInfo(callee_index);
8394 callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota);
8387 callee.maxBranchQuota(ip, sema.branch_quota);
83958388
83968389 // Make a runtime call to the new function, making sure to omit the comptime args.
83978390 const func_ty = Type.fromInterned(callee.ty);
......@@ -8413,7 +8406,7 @@ fn instantiateGenericCall(
84138406 if (sema.owner_func_index != .none and
84148407 Type.fromInterned(func_ty_info.return_type).isError(zcu))
84158408 {
8416 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;
8409 ip.funcSetCallsOrAwaitsErrorableFn(sema.owner_func_index);
84178410 }
84188411
84198412 try sema.addReferenceEntry(call_src, AnalUnit.wrap(.{ .func = callee_index }));
......@@ -8774,9 +8767,9 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
87748767 const int = try sema.usizeCast(block, operand_src, try value.toUnsignedIntSema(pt));
87758768 if (int > len: {
87768769 const mutate = &ip.global_error_set.mutate;
8777 mutate.mutex.lock();
8778 defer mutate.mutex.unlock();
8779 break :len mutate.list.len;
8770 mutate.map.mutex.lock();
8771 defer mutate.map.mutex.unlock();
8772 break :len mutate.names.len;
87808773 } or int == 0)
87818774 return sema.fail(block, operand_src, "integer value '{d}' represents no error", .{int});
87828775 return Air.internedToRef((try pt.intern(.{ .err = .{
......@@ -18400,7 +18393,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1840018393 try ty.resolveLayout(pt); // Getting alignment requires type layout
1840118394 const union_obj = mod.typeToUnion(ty).?;
1840218395 const tag_type = union_obj.loadTagType(ip);
18403 const layout = union_obj.getLayout(ip);
18396 const layout = union_obj.flagsUnordered(ip).layout;
1840418397
1840518398 const union_field_vals = try gpa.alloc(InternPool.Index, tag_type.names.len);
1840618399 defer gpa.free(union_field_vals);
......@@ -18718,8 +18711,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1871818711 const backing_integer_val = try pt.intern(.{ .opt = .{
1871918712 .ty = (try pt.optionalType(.type_type)).toIntern(),
1872018713 .val = if (mod.typeToPackedStruct(ty)) |packed_struct| val: {
18721 assert(Type.fromInterned(packed_struct.backingIntType(ip).*).isInt(mod));
18722 break :val packed_struct.backingIntType(ip).*;
18714 assert(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)).isInt(mod));
18715 break :val packed_struct.backingIntTypeUnordered(ip);
1872318716 } else .none,
1872418717 } });
1872518718
......@@ -19800,7 +19793,7 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
1980019793 return;
1980119794 }
1980219795
19803 if (!mod.intern_pool.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn) return;
19796 if (!mod.intern_pool.funcAnalysisUnordered(sema.owner_func_index).calls_or_awaits_errorable_fn) return;
1980419797 if (!start_block.ownerModule().error_tracing) return;
1980519798
1980619799 assert(saved_index != .none); // The .error_return_trace_index field was dropped somewhere
......@@ -21058,7 +21051,7 @@ fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
2105821051 const opt_ptr_stack_trace_ty = try pt.optionalType(ptr_stack_trace_ty.toIntern());
2105921052
2106021053 if (sema.owner_func_index != .none and
21061 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn and
21054 ip.funcAnalysisUnordered(sema.owner_func_index).calls_or_awaits_errorable_fn and
2106221055 block.ownerModule().error_tracing)
2106321056 {
2106421057 return block.addTy(.err_return_trace, opt_ptr_stack_trace_ty);
......@@ -22206,8 +22199,8 @@ fn reifyUnion(
2220622199 if (any_aligns) {
2220722200 loaded_union.setFieldAligns(ip, field_aligns);
2220822201 }
22209 loaded_union.tagTypePtr(ip).* = enum_tag_ty;
22210 loaded_union.flagsPtr(ip).status = .have_field_types;
22202 loaded_union.setTagType(ip, enum_tag_ty);
22203 loaded_union.setStatus(ip, .have_field_types);
2221122204
2221222205 try pt.finalizeAnonDecl(new_decl_index);
2221322206 try mod.comp.work_queue.writeItem(.{ .resolve_type_fully = wip_ty.index });
......@@ -22469,10 +22462,10 @@ fn reifyStruct(
2246922462 if (opt_backing_int_val.optionalValue(mod)) |backing_int_val| {
2247022463 const backing_int_ty = backing_int_val.toType();
2247122464 try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum);
22472 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
22465 struct_type.setBackingIntType(ip, backing_int_ty.toIntern());
2247322466 } else {
2247422467 const backing_int_ty = try pt.intType(.unsigned, @intCast(fields_bit_sum));
22475 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
22468 struct_type.setBackingIntType(ip, backing_int_ty.toIntern());
2247622469 }
2247722470 }
2247822471
......@@ -28352,7 +28345,7 @@ fn unionFieldPtr(
2835228345 .is_const = union_ptr_info.flags.is_const,
2835328346 .is_volatile = union_ptr_info.flags.is_volatile,
2835428347 .address_space = union_ptr_info.flags.address_space,
28355 .alignment = if (union_obj.getLayout(ip) == .auto) blk: {
28348 .alignment = if (union_obj.flagsUnordered(ip).layout == .auto) blk: {
2835628349 const union_align = if (union_ptr_info.flags.alignment != .none)
2835728350 union_ptr_info.flags.alignment
2835828351 else
......@@ -28380,7 +28373,7 @@ fn unionFieldPtr(
2838028373 }
2838128374
2838228375 if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| ct: {
28383 switch (union_obj.getLayout(ip)) {
28376 switch (union_obj.flagsUnordered(ip).layout) {
2838428377 .auto => if (initializing) {
2838528378 // Store to the union to initialize the tag.
2838628379 const field_tag = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
......@@ -28418,7 +28411,7 @@ fn unionFieldPtr(
2841828411 }
2841928412
2842028413 try sema.requireRuntimeBlock(block, src, null);
28421 if (!initializing and union_obj.getLayout(ip) == .auto and block.wantSafety() and
28414 if (!initializing and union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and
2842228415 union_ty.unionTagTypeSafety(mod) != null and union_obj.field_types.len > 1)
2842328416 {
2842428417 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
......@@ -28461,7 +28454,7 @@ fn unionFieldVal(
2846128454 const un = ip.indexToKey(union_val.toIntern()).un;
2846228455 const field_tag = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
2846328456 const tag_matches = un.tag == field_tag.toIntern();
28464 switch (union_obj.getLayout(ip)) {
28457 switch (union_obj.flagsUnordered(ip).layout) {
2846528458 .auto => {
2846628459 if (tag_matches) {
2846728460 return Air.internedToRef(un.val);
......@@ -28495,7 +28488,7 @@ fn unionFieldVal(
2849528488 }
2849628489
2849728490 try sema.requireRuntimeBlock(block, src, null);
28498 if (union_obj.getLayout(ip) == .auto and block.wantSafety() and
28491 if (union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and
2849928492 union_ty.unionTagTypeSafety(zcu) != null and union_obj.field_types.len > 1)
2850028493 {
2850128494 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
......@@ -32042,7 +32035,7 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile
3204232035
3204332036 pt.ensureDeclAnalyzed(decl_index) catch |err| {
3204432037 if (sema.owner_func_index != .none) {
32045 ip.funcAnalysis(sema.owner_func_index).state = .dependency_failure;
32038 ip.funcSetAnalysisState(sema.owner_func_index, .dependency_failure);
3204632039 } else {
3204732040 sema.owner_decl.analysis = .dependency_failure;
3204832041 }
......@@ -32056,7 +32049,7 @@ fn ensureFuncBodyAnalyzed(sema: *Sema, func: InternPool.Index) CompileError!void
3205632049 const ip = &mod.intern_pool;
3205732050 pt.ensureFuncBodyAnalyzed(func) catch |err| {
3205832051 if (sema.owner_func_index != .none) {
32059 ip.funcAnalysis(sema.owner_func_index).state = .dependency_failure;
32052 ip.funcSetAnalysisState(sema.owner_func_index, .dependency_failure);
3206032053 } else {
3206132054 sema.owner_decl.analysis = .dependency_failure;
3206232055 }
......@@ -32402,7 +32395,7 @@ fn analyzeIsNonErrComptimeOnly(
3240232395 // If the error set is empty, we must return a comptime true or false.
3240332396 // However we want to avoid unnecessarily resolving an inferred error set
3240432397 // in case it is already non-empty.
32405 switch (ip.funcIesResolved(func_index).*) {
32398 switch (ip.funcIesResolvedUnordered(func_index)) {
3240632399 .anyerror_type => break :blk,
3240732400 .none => {},
3240832401 else => |i| if (ip.indexToKey(i).error_set_type.names.len != 0) break :blk,
......@@ -33471,7 +33464,7 @@ fn wrapErrorUnionSet(
3347133464 .inferred_error_set_type => |func_index| ok: {
3347233465 // We carefully do this in an order that avoids unnecessarily
3347333466 // resolving the destination error set type.
33474 switch (ip.funcIesResolved(func_index).*) {
33467 switch (ip.funcIesResolvedUnordered(func_index)) {
3347533468 .anyerror_type => break :ok,
3347633469 .none => if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {
3347733470 break :ok;
......@@ -35076,33 +35069,25 @@ pub fn resolveStructAlignment(
3507635069
3507735070 assert(sema.ownerUnit().unwrap().decl == struct_type.decl.unwrap().?);
3507835071
35079 assert(struct_type.flagsPtr(ip).alignment == .none);
3508035072 assert(struct_type.layout != .@"packed");
35073 assert(struct_type.flagsUnordered(ip).alignment == .none);
3508135074
35082 if (struct_type.flagsPtr(ip).field_types_wip) {
35083 // We'll guess "pointer-aligned", if the struct has an
35084 // underaligned pointer field then some allocations
35085 // might require explicit alignment.
35086 struct_type.flagsPtr(ip).assumed_pointer_aligned = true;
35087 const result = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
35088 struct_type.flagsPtr(ip).alignment = result;
35089 return;
35090 }
35075 const ptr_align = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
35076
35077 // We'll guess "pointer-aligned", if the struct has an
35078 // underaligned pointer field then some allocations
35079 // might require explicit alignment.
35080 if (struct_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;
3509135081
3509235082 try sema.resolveTypeFieldsStruct(ty, struct_type);
3509335083
35094 if (struct_type.setAlignmentWip(ip)) {
35095 // We'll guess "pointer-aligned", if the struct has an
35096 // underaligned pointer field then some allocations
35097 // might require explicit alignment.
35098 struct_type.flagsPtr(ip).assumed_pointer_aligned = true;
35099 const result = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
35100 struct_type.flagsPtr(ip).alignment = result;
35101 return;
35102 }
35084 // We'll guess "pointer-aligned", if the struct has an
35085 // underaligned pointer field then some allocations
35086 // might require explicit alignment.
35087 if (struct_type.assumePointerAlignedIfWip(ip, ptr_align)) return;
3510335088 defer struct_type.clearAlignmentWip(ip);
3510435089
35105 var result: Alignment = .@"1";
35090 var alignment: Alignment = .@"1";
3510635091
3510735092 for (0..struct_type.field_types.len) |i| {
3510835093 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
......@@ -35114,10 +35099,10 @@ pub fn resolveStructAlignment(
3511435099 struct_type.layout,
3511535100 .sema,
3511635101 );
35117 result = result.maxStrict(field_align);
35102 alignment = alignment.maxStrict(field_align);
3511835103 }
3511935104
35120 struct_type.flagsPtr(ip).alignment = result;
35105 struct_type.setAlignment(ip, alignment);
3512135106}
3512235107
3512335108pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
......@@ -35182,7 +35167,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3518235167 big_align = big_align.maxStrict(field_align.*);
3518335168 }
3518435169
35185 if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35170 if (struct_type.flagsUnordered(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
3518635171 const msg = try sema.errMsg(
3518735172 ty.srcLoc(zcu),
3518835173 "struct layout depends on it having runtime bits",
......@@ -35191,7 +35176,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3519135176 return sema.failWithOwnedErrorMsg(null, msg);
3519235177 }
3519335178
35194 if (struct_type.flagsPtr(ip).assumed_pointer_aligned and
35179 if (struct_type.flagsUnordered(ip).assumed_pointer_aligned and
3519535180 big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8))))
3519635181 {
3519735182 const msg = try sema.errMsg(
......@@ -35259,10 +35244,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3525935244 offsets[i] = @intCast(aligns[i].forward(offset));
3526035245 offset = offsets[i] + sizes[i];
3526135246 }
35262 struct_type.size(ip).* = @intCast(big_align.forward(offset));
35263 const flags = struct_type.flagsPtr(ip);
35264 flags.alignment = big_align;
35265 flags.layout_resolved = true;
35247 struct_type.setLayoutResolved(ip, @intCast(big_align.forward(offset)), big_align);
3526635248 _ = try sema.typeRequiresComptime(ty);
3526735249}
3526835250
......@@ -35355,13 +35337,13 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp
3535535337 };
3535635338
3535735339 try sema.checkBackingIntType(&block, backing_int_src, backing_int_ty, fields_bit_sum);
35358 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
35340 struct_type.setBackingIntType(ip, backing_int_ty.toIntern());
3535935341 } else {
3536035342 if (fields_bit_sum > std.math.maxInt(u16)) {
3536135343 return sema.fail(&block, block.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
3536235344 }
3536335345 const backing_int_ty = try pt.intType(.unsigned, @intCast(fields_bit_sum));
35364 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
35346 struct_type.setBackingIntType(ip, backing_int_ty.toIntern());
3536535347 }
3536635348
3536735349 try sema.flushExports();
......@@ -35435,15 +35417,12 @@ pub fn resolveUnionAlignment(
3543535417
3543635418 assert(!union_type.haveLayout(ip));
3543735419
35438 if (union_type.flagsPtr(ip).status == .field_types_wip) {
35439 // We'll guess "pointer-aligned", if the union has an
35440 // underaligned pointer field then some allocations
35441 // might require explicit alignment.
35442 union_type.flagsPtr(ip).assumed_pointer_aligned = true;
35443 const result = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
35444 union_type.flagsPtr(ip).alignment = result;
35445 return;
35446 }
35420 const ptr_align = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
35421
35422 // We'll guess "pointer-aligned", if the union has an
35423 // underaligned pointer field then some allocations
35424 // might require explicit alignment.
35425 if (union_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;
3544735426
3544835427 try sema.resolveTypeFieldsUnion(ty, union_type);
3544935428
......@@ -35461,7 +35440,7 @@ pub fn resolveUnionAlignment(
3546135440 max_align = max_align.max(field_align);
3546235441 }
3546335442
35464 union_type.flagsPtr(ip).alignment = max_align;
35443 union_type.setAlignment(ip, max_align);
3546535444}
3546635445
3546735446/// This logic must be kept in sync with `Module.getUnionLayout`.
......@@ -35476,7 +35455,8 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3547635455
3547735456 assert(sema.ownerUnit().unwrap().decl == union_type.decl);
3547835457
35479 switch (union_type.flagsPtr(ip).status) {
35458 const old_flags = union_type.flagsUnordered(ip);
35459 switch (old_flags.status) {
3548035460 .none, .have_field_types => {},
3548135461 .field_types_wip, .layout_wip => {
3548235462 const msg = try sema.errMsg(
......@@ -35489,12 +35469,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3548935469 .have_layout, .fully_resolved_wip, .fully_resolved => return,
3549035470 }
3549135471
35492 const prev_status = union_type.flagsPtr(ip).status;
35493 errdefer if (union_type.flagsPtr(ip).status == .layout_wip) {
35494 union_type.flagsPtr(ip).status = prev_status;
35495 };
35472 errdefer union_type.setStatusIfLayoutWip(ip, old_flags.status);
3549635473
35497 union_type.flagsPtr(ip).status = .layout_wip;
35474 union_type.setStatus(ip, .layout_wip);
3549835475
3549935476 var max_size: u64 = 0;
3550035477 var max_align: Alignment = .@"1";
......@@ -35521,8 +35498,8 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3552135498 max_align = max_align.max(field_align);
3552235499 }
3552335500
35524 const flags = union_type.flagsPtr(ip);
35525 const has_runtime_tag = flags.runtime_tag.hasTag() and try sema.typeHasRuntimeBits(Type.fromInterned(union_type.enum_tag_ty));
35501 const has_runtime_tag = union_type.flagsUnordered(ip).runtime_tag.hasTag() and
35502 try sema.typeHasRuntimeBits(Type.fromInterned(union_type.enum_tag_ty));
3552635503 const size, const alignment, const padding = if (has_runtime_tag) layout: {
3552735504 const enum_tag_type = Type.fromInterned(union_type.enum_tag_ty);
3552835505 const tag_align = try sema.typeAbiAlignment(enum_tag_type);
......@@ -35556,12 +35533,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3555635533 break :layout .{ size, max_align.max(tag_align), padding };
3555735534 } else .{ max_align.forward(max_size), max_align, 0 };
3555835535
35559 union_type.size(ip).* = @intCast(size);
35560 union_type.padding(ip).* = padding;
35561 flags.alignment = alignment;
35562 flags.status = .have_layout;
35536 union_type.setHaveLayout(ip, @intCast(size), padding, alignment);
3556335537
35564 if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35538 if (union_type.flagsUnordered(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
3556535539 const msg = try sema.errMsg(
3556635540 ty.srcLoc(pt.zcu),
3556735541 "union layout depends on it having runtime bits",
......@@ -35570,7 +35544,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3557035544 return sema.failWithOwnedErrorMsg(null, msg);
3557135545 }
3557235546
35573 if (union_type.flagsPtr(ip).assumed_pointer_aligned and
35547 if (union_type.flagsUnordered(ip).assumed_pointer_aligned and
3557435548 alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(pt.zcu.getTarget().ptrBitWidth(), 8))))
3557535549 {
3557635550 const msg = try sema.errMsg(
......@@ -35617,7 +35591,7 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
3561735591
3561835592 assert(sema.ownerUnit().unwrap().decl == union_obj.decl);
3561935593
35620 switch (union_obj.flagsPtr(ip).status) {
35594 switch (union_obj.flagsUnordered(ip).status) {
3562135595 .none, .have_field_types, .field_types_wip, .layout_wip, .have_layout => {},
3562235596 .fully_resolved_wip, .fully_resolved => return,
3562335597 }
......@@ -35626,15 +35600,15 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
3562635600 // After we have resolve union layout we have to go over the fields again to
3562735601 // make sure pointer fields get their child types resolved as well.
3562835602 // See also similar code for structs.
35629 const prev_status = union_obj.flagsPtr(ip).status;
35630 errdefer union_obj.flagsPtr(ip).status = prev_status;
35603 const prev_status = union_obj.flagsUnordered(ip).status;
35604 errdefer union_obj.setStatus(ip, prev_status);
3563135605
35632 union_obj.flagsPtr(ip).status = .fully_resolved_wip;
35606 union_obj.setStatus(ip, .fully_resolved_wip);
3563335607 for (0..union_obj.field_types.len) |field_index| {
3563435608 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3563535609 try field_ty.resolveFully(pt);
3563635610 }
35637 union_obj.flagsPtr(ip).status = .fully_resolved;
35611 union_obj.setStatus(ip, .fully_resolved);
3563835612 }
3563935613
3564035614 // And let's not forget comptime-only status.
......@@ -35667,7 +35641,7 @@ pub fn resolveTypeFieldsStruct(
3566735641
3566835642 if (struct_type.haveFieldTypes(ip)) return;
3566935643
35670 if (struct_type.setTypesWip(ip)) {
35644 if (struct_type.setFieldTypesWip(ip)) {
3567135645 const msg = try sema.errMsg(
3567235646 Type.fromInterned(ty).srcLoc(zcu),
3567335647 "struct '{}' depends on itself",
......@@ -35675,7 +35649,7 @@ pub fn resolveTypeFieldsStruct(
3567535649 );
3567635650 return sema.failWithOwnedErrorMsg(null, msg);
3567735651 }
35678 defer struct_type.clearTypesWip(ip);
35652 defer struct_type.clearFieldTypesWip(ip);
3567935653
3568035654 semaStructFields(pt, sema.arena, struct_type) catch |err| switch (err) {
3568135655 error.AnalysisFail => {
......@@ -35744,7 +35718,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3574435718 },
3574535719 else => {},
3574635720 }
35747 switch (union_type.flagsPtr(ip).status) {
35721 switch (union_type.flagsUnordered(ip).status) {
3574835722 .none => {},
3574935723 .field_types_wip => {
3575035724 const msg = try sema.errMsg(
......@@ -35762,8 +35736,8 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3576235736 => return,
3576335737 }
3576435738
35765 union_type.flagsPtr(ip).status = .field_types_wip;
35766 errdefer union_type.flagsPtr(ip).status = .none;
35739 union_type.setStatus(ip, .field_types_wip);
35740 errdefer union_type.setStatus(ip, .none);
3576735741 semaUnionFields(pt, sema.arena, union_type) catch |err| switch (err) {
3576835742 error.AnalysisFail => {
3576935743 if (owner_decl.analysis == .complete) {
......@@ -35774,7 +35748,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3577435748 error.OutOfMemory => return error.OutOfMemory,
3577535749 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
3577635750 };
35777 union_type.flagsPtr(ip).status = .have_field_types;
35751 union_type.setStatus(ip, .have_field_types);
3577835752}
3577935753
3578035754/// Returns a normal error set corresponding to the fully populated inferred
......@@ -35795,10 +35769,10 @@ fn resolveInferredErrorSet(
3579535769
3579635770 // TODO: during an incremental update this might not be `.none`, but the
3579735771 // function might be out-of-date!
35798 const resolved_ty = func.resolvedErrorSet(ip).*;
35772 const resolved_ty = func.resolvedErrorSetUnordered(ip);
3579935773 if (resolved_ty != .none) return resolved_ty;
3580035774
35801 if (func.analysis(ip).state == .in_progress)
35775 if (func.analysisUnordered(ip).state == .in_progress)
3580235776 return sema.fail(block, src, "unable to resolve inferred error set", .{});
3580335777
3580435778 // In order to ensure that all dependencies are properly added to the set,
......@@ -35835,7 +35809,7 @@ fn resolveInferredErrorSet(
3583535809
3583635810 // This will now have been resolved by the logic at the end of `Module.analyzeFnBody`
3583735811 // which calls `resolveInferredErrorSetPtr`.
35838 const final_resolved_ty = func.resolvedErrorSet(ip).*;
35812 const final_resolved_ty = func.resolvedErrorSetUnordered(ip);
3583935813 assert(final_resolved_ty != .none);
3584035814 return final_resolved_ty;
3584135815}
......@@ -36001,8 +35975,7 @@ fn semaStructFields(
3600135975 return;
3600235976 },
3600335977 .auto, .@"extern" => {
36004 struct_type.size(ip).* = 0;
36005 struct_type.flagsPtr(ip).layout_resolved = true;
35978 struct_type.setLayoutResolved(ip, 0, .none);
3600635979 return;
3600735980 },
3600835981 };
......@@ -36196,7 +36169,7 @@ fn semaStructFields(
3619636169 extra_index += zir_field.init_body_len;
3619736170 }
3619836171
36199 struct_type.clearTypesWip(ip);
36172 struct_type.clearFieldTypesWip(ip);
3620036173 if (!any_inits) struct_type.setHaveFieldInits(ip);
3620136174
3620236175 try sema.flushExports();
......@@ -36472,7 +36445,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
3647236445 }
3647336446 } else {
3647436447 // The provided type is the enum tag type.
36475 union_type.tagTypePtr(ip).* = provided_ty.toIntern();
36448 union_type.setTagType(ip, provided_ty.toIntern());
3647636449 const enum_type = switch (ip.indexToKey(provided_ty.toIntern())) {
3647736450 .enum_type => ip.loadEnumType(provided_ty.toIntern()),
3647836451 else => return sema.fail(&block_scope, tag_ty_src, "expected enum tag type, found '{}'", .{provided_ty.fmt(pt)}),
......@@ -36610,10 +36583,11 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
3661036583 }
3661136584
3661236585 if (explicit_tags_seen.len > 0) {
36613 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
36586 const tag_ty = union_type.tagTypeUnordered(ip);
36587 const tag_info = ip.loadEnumType(tag_ty);
3661436588 const enum_index = tag_info.nameIndex(ip, field_name) orelse {
3661536589 return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{
36616 field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(pt),
36590 field_name.fmt(ip), Type.fromInterned(tag_ty).fmt(pt),
3661736591 });
3661836592 };
3661936593
......@@ -36650,7 +36624,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
3665036624 };
3665136625 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3665236626 }
36653 const layout = union_type.getLayout(ip);
36627 const layout = union_type.flagsUnordered(ip).layout;
3665436628 if (layout == .@"extern" and
3665536629 !try sema.validateExternType(field_ty, .union_field))
3665636630 {
......@@ -36693,7 +36667,8 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
3669336667 union_type.setFieldAligns(ip, field_aligns.items);
3669436668
3669536669 if (explicit_tags_seen.len > 0) {
36696 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
36670 const tag_ty = union_type.tagTypeUnordered(ip);
36671 const tag_info = ip.loadEnumType(tag_ty);
3669736672 if (tag_info.names.len > fields_len) {
3669836673 const msg = msg: {
3669936674 const msg = try sema.errMsg(src, "enum field(s) missing in union", .{});
......@@ -36701,21 +36676,21 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
3670136676
3670236677 for (tag_info.names.get(ip), 0..) |field_name, field_index| {
3670336678 if (explicit_tags_seen[field_index]) continue;
36704 try sema.addFieldErrNote(Type.fromInterned(union_type.tagTypePtr(ip).*), field_index, msg, "field '{}' missing, declared here", .{
36679 try sema.addFieldErrNote(Type.fromInterned(tag_ty), field_index, msg, "field '{}' missing, declared here", .{
3670536680 field_name.fmt(ip),
3670636681 });
3670736682 }
36708 try sema.addDeclaredHereNote(msg, Type.fromInterned(union_type.tagTypePtr(ip).*));
36683 try sema.addDeclaredHereNote(msg, Type.fromInterned(tag_ty));
3670936684 break :msg msg;
3671036685 };
3671136686 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3671236687 }
3671336688 } else if (enum_field_vals.count() > 0) {
3671436689 const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), zcu.declPtr(union_type.decl));
36715 union_type.tagTypePtr(ip).* = enum_ty;
36690 union_type.setTagType(ip, enum_ty);
3671636691 } else {
3671736692 const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, zcu.declPtr(union_type.decl));
36718 union_type.tagTypePtr(ip).* = enum_ty;
36693 union_type.setTagType(ip, enum_ty);
3671936694 }
3672036695
3672136696 try sema.flushExports();
......@@ -37091,7 +37066,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3709137066 try ty.resolveLayout(pt);
3709237067
3709337068 const union_obj = ip.loadUnionType(ty.toIntern());
37094 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse
37069 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypeUnordered(ip)))) orelse
3709537070 return null;
3709637071 if (union_obj.field_types.len == 0) {
3709737072 const only = try pt.intern(.{ .empty_enum_value = ty.toIntern() });
src/Type.zig+48-47
......@@ -605,17 +605,15 @@ pub fn hasRuntimeBitsAdvanced(
605605
606606 .union_type => {
607607 const union_type = ip.loadUnionType(ty.toIntern());
608 switch (union_type.flagsPtr(ip).runtime_tag) {
608 const union_flags = union_type.flagsUnordered(ip);
609 switch (union_flags.runtime_tag) {
609610 .none => {
610 if (union_type.flagsPtr(ip).status == .field_types_wip) {
611 // In this case, we guess that hasRuntimeBits() for this type is true,
612 // and then later if our guess was incorrect, we emit a compile error.
613 union_type.flagsPtr(ip).assumed_runtime_bits = true;
614 return true;
615 }
611 // In this case, we guess that hasRuntimeBits() for this type is true,
612 // and then later if our guess was incorrect, we emit a compile error.
613 if (union_type.assumeRuntimeBitsIfFieldTypesWip(ip)) return true;
616614 },
617615 .safety, .tagged => {
618 const tag_ty = union_type.tagTypePtr(ip).*;
616 const tag_ty = union_type.tagTypeUnordered(ip);
619617 // tag_ty will be `none` if this union's tag type is not resolved yet,
620618 // in which case we want control flow to continue down below.
621619 if (tag_ty != .none and
......@@ -627,8 +625,8 @@ pub fn hasRuntimeBitsAdvanced(
627625 }
628626 switch (strat) {
629627 .sema => try ty.resolveFields(pt),
630 .eager => assert(union_type.flagsPtr(ip).status.haveFieldTypes()),
631 .lazy => if (!union_type.flagsPtr(ip).status.haveFieldTypes())
628 .eager => assert(union_flags.status.haveFieldTypes()),
629 .lazy => if (!union_flags.status.haveFieldTypes())
632630 return error.NeedLazy,
633631 }
634632 for (0..union_type.field_types.len) |field_index| {
......@@ -745,8 +743,8 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
745743 },
746744 .union_type => {
747745 const union_type = ip.loadUnionType(ty.toIntern());
748 return switch (union_type.flagsPtr(ip).runtime_tag) {
749 .none, .safety => union_type.flagsPtr(ip).layout != .auto,
746 return switch (union_type.flagsUnordered(ip).runtime_tag) {
747 .none, .safety => union_type.flagsUnordered(ip).layout != .auto,
750748 .tagged => false,
751749 };
752750 },
......@@ -1045,7 +1043,7 @@ pub fn abiAlignmentAdvanced(
10451043 if (struct_type.layout == .@"packed") {
10461044 switch (strat) {
10471045 .sema => try ty.resolveLayout(pt),
1048 .lazy => if (struct_type.backingIntType(ip).* == .none) return .{
1046 .lazy => if (struct_type.backingIntTypeUnordered(ip) == .none) return .{
10491047 .val = Value.fromInterned(try pt.intern(.{ .int = .{
10501048 .ty = .comptime_int_type,
10511049 .storage = .{ .lazy_align = ty.toIntern() },
......@@ -1053,10 +1051,10 @@ pub fn abiAlignmentAdvanced(
10531051 },
10541052 .eager => {},
10551053 }
1056 return .{ .scalar = Type.fromInterned(struct_type.backingIntType(ip).*).abiAlignment(pt) };
1054 return .{ .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiAlignment(pt) };
10571055 }
10581056
1059 if (struct_type.flagsPtr(ip).alignment == .none) switch (strat) {
1057 if (struct_type.flagsUnordered(ip).alignment == .none) switch (strat) {
10601058 .eager => unreachable, // struct alignment not resolved
10611059 .sema => try ty.resolveStructAlignment(pt),
10621060 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
......@@ -1065,7 +1063,7 @@ pub fn abiAlignmentAdvanced(
10651063 } })) },
10661064 };
10671065
1068 return .{ .scalar = struct_type.flagsPtr(ip).alignment };
1066 return .{ .scalar = struct_type.flagsUnordered(ip).alignment };
10691067 },
10701068 .anon_struct_type => |tuple| {
10711069 var big_align: Alignment = .@"1";
......@@ -1088,7 +1086,7 @@ pub fn abiAlignmentAdvanced(
10881086 .union_type => {
10891087 const union_type = ip.loadUnionType(ty.toIntern());
10901088
1091 if (union_type.flagsPtr(ip).alignment == .none) switch (strat) {
1089 if (union_type.flagsUnordered(ip).alignment == .none) switch (strat) {
10921090 .eager => unreachable, // union layout not resolved
10931091 .sema => try ty.resolveUnionAlignment(pt),
10941092 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
......@@ -1097,7 +1095,7 @@ pub fn abiAlignmentAdvanced(
10971095 } })) },
10981096 };
10991097
1100 return .{ .scalar = union_type.flagsPtr(ip).alignment };
1098 return .{ .scalar = union_type.flagsUnordered(ip).alignment };
11011099 },
11021100 .opaque_type => return .{ .scalar = .@"1" },
11031101 .enum_type => return .{
......@@ -1420,7 +1418,7 @@ pub fn abiSizeAdvanced(
14201418 .sema => try ty.resolveLayout(pt),
14211419 .lazy => switch (struct_type.layout) {
14221420 .@"packed" => {
1423 if (struct_type.backingIntType(ip).* == .none) return .{
1421 if (struct_type.backingIntTypeUnordered(ip) == .none) return .{
14241422 .val = Value.fromInterned(try pt.intern(.{ .int = .{
14251423 .ty = .comptime_int_type,
14261424 .storage = .{ .lazy_size = ty.toIntern() },
......@@ -1440,11 +1438,11 @@ pub fn abiSizeAdvanced(
14401438 }
14411439 switch (struct_type.layout) {
14421440 .@"packed" => return .{
1443 .scalar = Type.fromInterned(struct_type.backingIntType(ip).*).abiSize(pt),
1441 .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiSize(pt),
14441442 },
14451443 .auto, .@"extern" => {
14461444 assert(struct_type.haveLayout(ip));
1447 return .{ .scalar = struct_type.size(ip).* };
1445 return .{ .scalar = struct_type.sizeUnordered(ip) };
14481446 },
14491447 }
14501448 },
......@@ -1464,7 +1462,7 @@ pub fn abiSizeAdvanced(
14641462 const union_type = ip.loadUnionType(ty.toIntern());
14651463 switch (strat) {
14661464 .sema => try ty.resolveLayout(pt),
1467 .lazy => if (!union_type.flagsPtr(ip).status.haveLayout()) return .{
1465 .lazy => if (!union_type.flagsUnordered(ip).status.haveLayout()) return .{
14681466 .val = Value.fromInterned(try pt.intern(.{ .int = .{
14691467 .ty = .comptime_int_type,
14701468 .storage = .{ .lazy_size = ty.toIntern() },
......@@ -1474,7 +1472,7 @@ pub fn abiSizeAdvanced(
14741472 }
14751473
14761474 assert(union_type.haveLayout(ip));
1477 return .{ .scalar = union_type.size(ip).* };
1475 return .{ .scalar = union_type.sizeUnordered(ip) };
14781476 },
14791477 .opaque_type => unreachable, // no size available
14801478 .enum_type => return .{ .scalar = Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).abiSize(pt) },
......@@ -1788,7 +1786,7 @@ pub fn bitSizeAdvanced(
17881786 if (is_packed) try ty.resolveLayout(pt);
17891787 }
17901788 if (is_packed) {
1791 return try Type.fromInterned(struct_type.backingIntType(ip).*).bitSizeAdvanced(pt, strat);
1789 return try Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).bitSizeAdvanced(pt, strat);
17921790 }
17931791 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;
17941792 },
......@@ -1808,7 +1806,7 @@ pub fn bitSizeAdvanced(
18081806 if (!is_packed) {
18091807 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;
18101808 }
1811 assert(union_type.flagsPtr(ip).status.haveFieldTypes());
1809 assert(union_type.flagsUnordered(ip).status.haveFieldTypes());
18121810
18131811 var size: u64 = 0;
18141812 for (0..union_type.field_types.len) |field_index| {
......@@ -2056,9 +2054,10 @@ pub fn unionTagType(ty: Type, mod: *Module) ?Type {
20562054 else => return null,
20572055 }
20582056 const union_type = ip.loadUnionType(ty.toIntern());
2059 switch (union_type.flagsPtr(ip).runtime_tag) {
2057 const union_flags = union_type.flagsUnordered(ip);
2058 switch (union_flags.runtime_tag) {
20602059 .tagged => {
2061 assert(union_type.flagsPtr(ip).status.haveFieldTypes());
2060 assert(union_flags.status.haveFieldTypes());
20622061 return Type.fromInterned(union_type.enum_tag_ty);
20632062 },
20642063 else => return null,
......@@ -2135,7 +2134,7 @@ pub fn containerLayout(ty: Type, mod: *Module) std.builtin.Type.ContainerLayout
21352134 return switch (ip.indexToKey(ty.toIntern())) {
21362135 .struct_type => ip.loadStructType(ty.toIntern()).layout,
21372136 .anon_struct_type => .auto,
2138 .union_type => ip.loadUnionType(ty.toIntern()).flagsPtr(ip).layout,
2137 .union_type => ip.loadUnionType(ty.toIntern()).flagsUnordered(ip).layout,
21392138 else => unreachable,
21402139 };
21412140}
......@@ -2157,7 +2156,7 @@ pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool {
21572156 .anyerror_type, .adhoc_inferred_error_set_type => false,
21582157 else => switch (ip.indexToKey(ty.toIntern())) {
21592158 .error_set_type => |error_set_type| error_set_type.names.len == 0,
2160 .inferred_error_set_type => |i| switch (ip.funcIesResolved(i).*) {
2159 .inferred_error_set_type => |i| switch (ip.funcIesResolvedUnordered(i)) {
21612160 .none, .anyerror_type => false,
21622161 else => |t| ip.indexToKey(t).error_set_type.names.len == 0,
21632162 },
......@@ -2175,7 +2174,7 @@ pub fn isAnyError(ty: Type, mod: *Module) bool {
21752174 .anyerror_type => true,
21762175 .adhoc_inferred_error_set_type => false,
21772176 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2178 .inferred_error_set_type => |i| ip.funcIesResolved(i).* == .anyerror_type,
2177 .inferred_error_set_type => |i| ip.funcIesResolvedUnordered(i) == .anyerror_type,
21792178 else => false,
21802179 },
21812180 };
......@@ -2200,7 +2199,7 @@ pub fn errorSetHasFieldIp(
22002199 .anyerror_type => true,
22012200 else => switch (ip.indexToKey(ty)) {
22022201 .error_set_type => |error_set_type| error_set_type.nameIndex(ip, name) != null,
2203 .inferred_error_set_type => |i| switch (ip.funcIesResolved(i).*) {
2202 .inferred_error_set_type => |i| switch (ip.funcIesResolvedUnordered(i)) {
22042203 .anyerror_type => true,
22052204 .none => false,
22062205 else => |t| ip.indexToKey(t).error_set_type.nameIndex(ip, name) != null,
......@@ -2336,7 +2335,7 @@ pub fn intInfo(starting_ty: Type, mod: *Module) InternPool.Key.IntType {
23362335 .c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) },
23372336 else => switch (ip.indexToKey(ty.toIntern())) {
23382337 .int_type => |int_type| return int_type,
2339 .struct_type => ty = Type.fromInterned(ip.loadStructType(ty.toIntern()).backingIntType(ip).*),
2338 .struct_type => ty = Type.fromInterned(ip.loadStructType(ty.toIntern()).backingIntTypeUnordered(ip)),
23402339 .enum_type => ty = Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty),
23412340 .vector_type => |vector_type| ty = Type.fromInterned(vector_type.child),
23422341
......@@ -2826,17 +2825,18 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se
28262825 return false;
28272826
28282827 // A struct with no fields is not comptime-only.
2829 return switch (struct_type.flagsPtr(ip).requires_comptime) {
2828 return switch (struct_type.setRequiresComptimeWip(ip)) {
28302829 .no, .wip => false,
28312830 .yes => true,
28322831 .unknown => {
28332832 assert(strat == .sema);
28342833
2835 if (struct_type.flagsPtr(ip).field_types_wip)
2834 if (struct_type.flagsUnordered(ip).field_types_wip) {
2835 struct_type.setRequiresComptime(ip, .unknown);
28362836 return false;
2837 }
28372838
2838 struct_type.flagsPtr(ip).requires_comptime = .wip;
2839 errdefer struct_type.flagsPtr(ip).requires_comptime = .unknown;
2839 errdefer struct_type.setRequiresComptime(ip, .unknown);
28402840
28412841 try ty.resolveFields(pt);
28422842
......@@ -2849,12 +2849,12 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se
28492849 // be considered resolved. Comptime-only types
28502850 // still maintain a layout of their
28512851 // runtime-known fields.
2852 struct_type.flagsPtr(ip).requires_comptime = .yes;
2852 struct_type.setRequiresComptime(ip, .yes);
28532853 return true;
28542854 }
28552855 }
28562856
2857 struct_type.flagsPtr(ip).requires_comptime = .no;
2857 struct_type.setRequiresComptime(ip, .no);
28582858 return false;
28592859 },
28602860 };
......@@ -2870,29 +2870,30 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se
28702870
28712871 .union_type => {
28722872 const union_type = ip.loadUnionType(ty.toIntern());
2873 switch (union_type.flagsPtr(ip).requires_comptime) {
2873 switch (union_type.setRequiresComptimeWip(ip)) {
28742874 .no, .wip => return false,
28752875 .yes => return true,
28762876 .unknown => {
28772877 assert(strat == .sema);
28782878
2879 if (union_type.flagsPtr(ip).status == .field_types_wip)
2879 if (union_type.flagsUnordered(ip).status == .field_types_wip) {
2880 union_type.setRequiresComptime(ip, .unknown);
28802881 return false;
2882 }
28812883
2882 union_type.flagsPtr(ip).requires_comptime = .wip;
2883 errdefer union_type.flagsPtr(ip).requires_comptime = .unknown;
2884 errdefer union_type.setRequiresComptime(ip, .unknown);
28842885
28852886 try ty.resolveFields(pt);
28862887
28872888 for (0..union_type.field_types.len) |field_idx| {
28882889 const field_ty = union_type.field_types.get(ip)[field_idx];
28892890 if (try Type.fromInterned(field_ty).comptimeOnlyAdvanced(pt, strat)) {
2890 union_type.flagsPtr(ip).requires_comptime = .yes;
2891 union_type.setRequiresComptime(ip, .yes);
28912892 return true;
28922893 }
28932894 }
28942895
2895 union_type.flagsPtr(ip).requires_comptime = .no;
2896 union_type.setRequiresComptime(ip, .no);
28962897 return false;
28972898 },
28982899 }
......@@ -3117,7 +3118,7 @@ pub fn errorSetNames(ty: Type, mod: *Module) InternPool.NullTerminatedString.Sli
31173118 const ip = &mod.intern_pool;
31183119 return switch (ip.indexToKey(ty.toIntern())) {
31193120 .error_set_type => |x| x.names,
3120 .inferred_error_set_type => |i| switch (ip.funcIesResolved(i).*) {
3121 .inferred_error_set_type => |i| switch (ip.funcIesResolvedUnordered(i)) {
31213122 .none => unreachable, // unresolved inferred error set
31223123 .anyerror_type => unreachable,
31233124 else => |t| ip.indexToKey(t).error_set_type.names,
......@@ -3374,7 +3375,7 @@ pub fn isTuple(ty: Type, mod: *Module) bool {
33743375 const struct_type = ip.loadStructType(ty.toIntern());
33753376 if (struct_type.layout == .@"packed") return false;
33763377 if (struct_type.decl == .none) return false;
3377 return struct_type.flagsPtr(ip).is_tuple;
3378 return struct_type.flagsUnordered(ip).is_tuple;
33783379 },
33793380 .anon_struct_type => |anon_struct| anon_struct.names.len == 0,
33803381 else => false,
......@@ -3396,7 +3397,7 @@ pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool {
33963397 const struct_type = ip.loadStructType(ty.toIntern());
33973398 if (struct_type.layout == .@"packed") return false;
33983399 if (struct_type.decl == .none) return false;
3399 return struct_type.flagsPtr(ip).is_tuple;
3400 return struct_type.flagsUnordered(ip).is_tuple;
34003401 },
34013402 .anon_struct_type => true,
34023403 else => false,
src/Value.zig+1-1
......@@ -558,7 +558,7 @@ pub fn writeToPackedMemory(
558558 },
559559 .Union => {
560560 const union_obj = mod.typeToUnion(ty).?;
561 switch (union_obj.getLayout(ip)) {
561 switch (union_obj.flagsUnordered(ip).layout) {
562562 .auto, .@"extern" => unreachable, // Handled in non-packed writeToMemory
563563 .@"packed" => {
564564 if (val.unionTag(mod)) |union_tag| {
src/Zcu.zig+2-2
......@@ -2968,7 +2968,7 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index)
29682968 const is_outdated = mod.outdated.contains(func_as_depender) or
29692969 mod.potentially_outdated.contains(func_as_depender);
29702970
2971 switch (func.analysis(ip).state) {
2971 switch (func.analysisUnordered(ip).state) {
29722972 .none => {},
29732973 .queued => return,
29742974 // As above, we don't need to forward errors here.
......@@ -2989,7 +2989,7 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index)
29892989 // since the last update
29902990 try mod.comp.work_queue.writeItem(.{ .emit_h_decl = decl_index });
29912991 }
2992 func.analysis(ip).state = .queued;
2992 func.setAnalysisState(ip, .queued);
29932993}
29942994
29952995pub const SemaDeclResult = packed struct {
src/Zcu/PerThread.zig+27-27
......@@ -641,8 +641,8 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
641641
642642 // We'll want to remember what the IES used to be before the update for
643643 // dependency invalidation purposes.
644 const old_resolved_ies = if (func.analysis(ip).inferred_error_set)
645 func.resolvedErrorSet(ip).*
644 const old_resolved_ies = if (func.analysisUnordered(ip).inferred_error_set)
645 func.resolvedErrorSetUnordered(ip)
646646 else
647647 .none;
648648
......@@ -671,7 +671,7 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
671671 zcu.deleteUnitReferences(func_as_depender);
672672 }
673673
674 switch (func.analysis(ip).state) {
674 switch (func.analysisUnordered(ip).state) {
675675 .success => if (!was_outdated) return,
676676 .sema_failure,
677677 .dependency_failure,
......@@ -693,11 +693,11 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
693693
694694 var air = pt.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) {
695695 error.AnalysisFail => {
696 if (func.analysis(ip).state == .in_progress) {
696 if (func.analysisUnordered(ip).state == .in_progress) {
697697 // If this decl caused the compile error, the analysis field would
698698 // be changed to indicate it was this Decl's fault. Because this
699699 // did not happen, we infer here that it was a dependency failure.
700 func.analysis(ip).state = .dependency_failure;
700 func.setAnalysisState(ip, .dependency_failure);
701701 }
702702 return error.AnalysisFail;
703703 },
......@@ -707,8 +707,8 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
707707
708708 const invalidate_ies_deps = i: {
709709 if (!was_outdated) break :i false;
710 if (!func.analysis(ip).inferred_error_set) break :i true;
711 const new_resolved_ies = func.resolvedErrorSet(ip).*;
710 if (!func.analysisUnordered(ip).inferred_error_set) break :i true;
711 const new_resolved_ies = func.resolvedErrorSetUnordered(ip);
712712 break :i new_resolved_ies != old_resolved_ies;
713713 };
714714 if (invalidate_ies_deps) {
......@@ -783,7 +783,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
783783 .{@errorName(err)},
784784 ),
785785 );
786 func.analysis(ip).state = .codegen_failure;
786 func.setAnalysisState(ip, .codegen_failure);
787787 return;
788788 },
789789 };
......@@ -797,12 +797,12 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
797797 // Correcting this failure will involve changing a type this function
798798 // depends on, hence triggering re-analysis of this function, so this
799799 // interacts correctly with incremental compilation.
800 func.analysis(ip).state = .codegen_failure;
800 func.setAnalysisState(ip, .codegen_failure);
801801 } else if (comp.bin_file) |lf| {
802802 lf.updateFunc(pt, func_index, air, liveness) catch |err| switch (err) {
803803 error.OutOfMemory => return error.OutOfMemory,
804804 error.AnalysisFail => {
805 func.analysis(ip).state = .codegen_failure;
805 func.setAnalysisState(ip, .codegen_failure);
806806 },
807807 else => {
808808 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
......@@ -812,7 +812,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
812812 "unable to codegen: {s}",
813813 .{@errorName(err)},
814814 ));
815 func.analysis(ip).state = .codegen_failure;
815 func.setAnalysisState(ip, .codegen_failure);
816816 try zcu.retryable_failures.append(zcu.gpa, InternPool.AnalUnit.wrap(.{ .func = func_index }));
817817 },
818818 };
......@@ -1080,7 +1080,7 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult {
10801080 const old_linksection = decl.@"linksection";
10811081 const old_addrspace = decl.@"addrspace";
10821082 const old_is_inline = if (decl.getOwnedFunction(zcu)) |prev_func|
1083 prev_func.analysis(ip).state == .inline_only
1083 prev_func.analysisUnordered(ip).state == .inline_only
10841084 else
10851085 false;
10861086
......@@ -2037,7 +2037,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
20372037 .fn_ret_ty = Type.fromInterned(fn_ty_info.return_type),
20382038 .fn_ret_ty_ies = null,
20392039 .owner_func_index = func_index,
2040 .branch_quota = @max(func.branchQuota(ip).*, Sema.default_branch_quota),
2040 .branch_quota = @max(func.branchQuotaUnordered(ip), Sema.default_branch_quota),
20412041 .comptime_err_ret_trace = &comptime_err_ret_trace,
20422042 };
20432043 defer sema.deinit();
......@@ -2047,14 +2047,14 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
20472047 try sema.declareDependency(.{ .src_hash = decl.zir_decl_index.unwrap().? });
20482048 try sema.declareDependency(.{ .decl_val = decl_index });
20492049
2050 if (func.analysis(ip).inferred_error_set) {
2050 if (func.analysisUnordered(ip).inferred_error_set) {
20512051 const ies = try arena.create(Sema.InferredErrorSet);
20522052 ies.* = .{ .func = func_index };
20532053 sema.fn_ret_ty_ies = ies;
20542054 }
20552055
20562056 // reset in case calls to errorable functions are removed.
2057 func.analysis(ip).calls_or_awaits_errorable_fn = false;
2057 func.setCallsOrAwaitsErrorableFn(ip, false);
20582058
20592059 // First few indexes of extra are reserved and set at the end.
20602060 const reserved_count = @typeInfo(Air.ExtraIndex).Enum.fields.len;
......@@ -2080,7 +2080,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
20802080 };
20812081 defer inner_block.instructions.deinit(gpa);
20822082
2083 const fn_info = sema.code.getFnInfo(func.zirBodyInst(ip).resolve(ip));
2083 const fn_info = sema.code.getFnInfo(func.zirBodyInstUnordered(ip).resolve(ip));
20842084
20852085 // Here we are performing "runtime semantic analysis" for a function body, which means
20862086 // we must map the parameter ZIR instructions to `arg` AIR instructions.
......@@ -2149,7 +2149,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
21492149 });
21502150 }
21512151
2152 func.analysis(ip).state = .in_progress;
2152 func.setAnalysisState(ip, .in_progress);
21532153
21542154 const last_arg_index = inner_block.instructions.items.len;
21552155
......@@ -2176,7 +2176,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
21762176 }
21772177
21782178 // If we don't get an error return trace from a caller, create our own.
2179 if (func.analysis(ip).calls_or_awaits_errorable_fn and
2179 if (func.analysisUnordered(ip).calls_or_awaits_errorable_fn and
21802180 mod.comp.config.any_error_tracing and
21812181 !sema.fn_ret_ty.isError(mod))
21822182 {
......@@ -2218,10 +2218,10 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
22182218 else => |e| return e,
22192219 };
22202220 assert(ies.resolved != .none);
2221 ip.funcIesResolved(func_index).* = ies.resolved;
2221 ip.funcSetIesResolved(func_index, ies.resolved);
22222222 }
22232223
2224 func.analysis(ip).state = .success;
2224 func.setAnalysisState(ip, .success);
22252225
22262226 // Finally we must resolve the return type and parameter types so that backends
22272227 // have full access to type information.
......@@ -2415,6 +2415,7 @@ fn processExportsInner(
24152415) error{OutOfMemory}!void {
24162416 const zcu = pt.zcu;
24172417 const gpa = zcu.gpa;
2418 const ip = &zcu.intern_pool;
24182419
24192420 for (export_indices) |export_idx| {
24202421 const new_export = &zcu.all_exports.items[export_idx];
......@@ -2423,7 +2424,7 @@ fn processExportsInner(
24232424 new_export.status = .failed_retryable;
24242425 try zcu.failed_exports.ensureUnusedCapacity(gpa, 1);
24252426 const msg = try Zcu.ErrorMsg.create(gpa, new_export.src, "exported symbol collision: {}", .{
2426 new_export.opts.name.fmt(&zcu.intern_pool),
2427 new_export.opts.name.fmt(ip),
24272428 });
24282429 errdefer msg.destroy(gpa);
24292430 const other_export = zcu.all_exports.items[gop.value_ptr.*];
......@@ -2443,8 +2444,7 @@ fn processExportsInner(
24432444 if (!decl.owns_tv) break :failed false;
24442445 if (decl.typeOf(zcu).zigTypeTag(zcu) != .Fn) break :failed false;
24452446 // Check if owned function failed
2446 const a = zcu.funcInfo(decl.val.toIntern()).analysis(&zcu.intern_pool);
2447 break :failed a.state != .success;
2447 break :failed zcu.funcInfo(decl.val.toIntern()).analysisUnordered(ip).state != .success;
24482448 }) {
24492449 // This `Decl` is failed, so was never sent to codegen.
24502450 // TODO: we should probably tell the backend to delete any old exports of this `Decl`?
......@@ -3072,7 +3072,7 @@ pub fn getUnionLayout(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionTyp
30723072 most_aligned_field_size = field_size;
30733073 }
30743074 }
3075 const have_tag = loaded_union.flagsPtr(ip).runtime_tag.hasTag();
3075 const have_tag = loaded_union.flagsUnordered(ip).runtime_tag.hasTag();
30763076 if (!have_tag or !Type.fromInterned(loaded_union.enum_tag_ty).hasRuntimeBits(pt)) {
30773077 return .{
30783078 .abi_size = payload_align.forward(payload_size),
......@@ -3091,7 +3091,7 @@ pub fn getUnionLayout(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionTyp
30913091 const tag_size = Type.fromInterned(loaded_union.enum_tag_ty).abiSize(pt);
30923092 const tag_align = Type.fromInterned(loaded_union.enum_tag_ty).abiAlignment(pt).max(.@"1");
30933093 return .{
3094 .abi_size = loaded_union.size(ip).*,
3094 .abi_size = loaded_union.sizeUnordered(ip),
30953095 .abi_align = tag_align.max(payload_align),
30963096 .most_aligned_field = most_aligned_field,
30973097 .most_aligned_field_size = most_aligned_field_size,
......@@ -3100,7 +3100,7 @@ pub fn getUnionLayout(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionTyp
31003100 .payload_align = payload_align,
31013101 .tag_align = tag_align,
31023102 .tag_size = tag_size,
3103 .padding = loaded_union.padding(ip).*,
3103 .padding = loaded_union.paddingUnordered(ip),
31043104 };
31053105}
31063106
......@@ -3142,7 +3142,7 @@ pub fn unionFieldNormalAlignmentAdvanced(
31423142 strat: Type.ResolveStrat,
31433143) Zcu.SemaError!InternPool.Alignment {
31443144 const ip = &pt.zcu.intern_pool;
3145 assert(loaded_union.flagsPtr(ip).layout != .@"packed");
3145 assert(loaded_union.flagsUnordered(ip).layout != .@"packed");
31463146 const field_align = loaded_union.fieldAlign(ip, field_index);
31473147 if (field_align != .none) return field_align;
31483148 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
src/arch/arm/abi.zig+1-1
......@@ -56,7 +56,7 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread, ctx: Context) Class {
5656 .Union => {
5757 const bit_size = ty.bitSize(pt);
5858 const union_obj = pt.zcu.typeToUnion(ty).?;
59 if (union_obj.getLayout(ip) == .@"packed") {
59 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
6060 if (bit_size > 64) return .memory;
6161 return .byval;
6262 }
src/arch/riscv64/CodeGen.zig+1-1
......@@ -768,7 +768,7 @@ pub fn generate(
768768 @intFromEnum(FrameIndex.stack_frame),
769769 FrameAlloc.init(.{
770770 .size = 0,
771 .alignment = func.analysis(ip).stack_alignment.max(.@"1"),
771 .alignment = func.analysisUnordered(ip).stack_alignment.max(.@"1"),
772772 }),
773773 );
774774 function.frame_allocs.set(
src/arch/wasm/CodeGen.zig+7-7
......@@ -1011,7 +1011,7 @@ fn typeToValtype(ty: Type, pt: Zcu.PerThread) wasm.Valtype {
10111011 },
10121012 .Struct => {
10131013 if (pt.zcu.typeToPackedStruct(ty)) |packed_struct| {
1014 return typeToValtype(Type.fromInterned(packed_struct.backingIntType(ip).*), pt);
1014 return typeToValtype(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt);
10151015 } else {
10161016 return wasm.Valtype.i32;
10171017 }
......@@ -1746,7 +1746,7 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
17461746 => return ty.hasRuntimeBitsIgnoreComptime(pt),
17471747 .Union => {
17481748 if (mod.typeToUnion(ty)) |union_obj| {
1749 if (union_obj.getLayout(ip) == .@"packed") {
1749 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
17501750 return ty.abiSize(pt) > 8;
17511751 }
17521752 }
......@@ -1754,7 +1754,7 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
17541754 },
17551755 .Struct => {
17561756 if (mod.typeToPackedStruct(ty)) |packed_struct| {
1757 return isByRef(Type.fromInterned(packed_struct.backingIntType(ip).*), pt);
1757 return isByRef(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt);
17581758 }
17591759 return ty.hasRuntimeBitsIgnoreComptime(pt);
17601760 },
......@@ -3377,7 +3377,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33773377 assert(struct_type.layout == .@"packed");
33783378 var buf: [8]u8 = .{0} ** 8; // zero the buffer so we do not read 0xaa as integer
33793379 val.writeToPackedMemory(ty, pt, &buf, 0) catch unreachable;
3380 const backing_int_ty = Type.fromInterned(struct_type.backingIntType(ip).*);
3380 const backing_int_ty = Type.fromInterned(struct_type.backingIntTypeUnordered(ip));
33813381 const int_val = try pt.intValue(
33823382 backing_int_ty,
33833383 mem.readInt(u64, &buf, .little),
......@@ -3443,7 +3443,7 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
34433443 },
34443444 .Struct => {
34453445 const packed_struct = mod.typeToPackedStruct(ty).?;
3446 return func.emitUndefined(Type.fromInterned(packed_struct.backingIntType(ip).*));
3446 return func.emitUndefined(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)));
34473447 },
34483448 else => return func.fail("Wasm TODO: emitUndefined for type: {}\n", .{ty.zigTypeTag(mod)}),
34493449 }
......@@ -3974,7 +3974,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
39743974 .Struct => result: {
39753975 const packed_struct = mod.typeToPackedStruct(struct_ty).?;
39763976 const offset = pt.structPackedFieldBitOffset(packed_struct, field_index);
3977 const backing_ty = Type.fromInterned(packed_struct.backingIntType(ip).*);
3977 const backing_ty = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
39783978 const wasm_bits = toWasmBits(backing_ty.intInfo(mod).bits) orelse {
39793979 return func.fail("TODO: airStructFieldVal for packed structs larger than 128 bits", .{});
39803980 };
......@@ -5377,7 +5377,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53775377 }
53785378 const packed_struct = mod.typeToPackedStruct(result_ty).?;
53795379 const field_types = packed_struct.field_types;
5380 const backing_type = Type.fromInterned(packed_struct.backingIntType(ip).*);
5380 const backing_type = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
53815381
53825382 // ensure the result is zero'd
53835383 const result = try func.allocLocal(backing_type);
src/arch/wasm/abi.zig+3-3
......@@ -71,7 +71,7 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {
7171 },
7272 .Union => {
7373 const union_obj = pt.zcu.typeToUnion(ty).?;
74 if (union_obj.getLayout(ip) == .@"packed") {
74 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
7575 if (ty.bitSize(pt) <= 64) return direct;
7676 return .{ .direct, .direct };
7777 }
......@@ -107,7 +107,7 @@ pub fn scalarType(ty: Type, pt: Zcu.PerThread) Type {
107107 switch (ty.zigTypeTag(mod)) {
108108 .Struct => {
109109 if (mod.typeToPackedStruct(ty)) |packed_struct| {
110 return scalarType(Type.fromInterned(packed_struct.backingIntType(ip).*), pt);
110 return scalarType(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt);
111111 } else {
112112 assert(ty.structFieldCount(mod) == 1);
113113 return scalarType(ty.structFieldType(0, mod), pt);
......@@ -115,7 +115,7 @@ pub fn scalarType(ty: Type, pt: Zcu.PerThread) Type {
115115 },
116116 .Union => {
117117 const union_obj = mod.typeToUnion(ty).?;
118 if (union_obj.getLayout(ip) != .@"packed") {
118 if (union_obj.flagsUnordered(ip).layout != .@"packed") {
119119 const layout = pt.getUnionLayout(union_obj);
120120 if (layout.payload_size == 0 and layout.tag_size != 0) {
121121 return scalarType(ty.unionTagTypeSafety(mod).?, pt);
src/arch/x86_64/CodeGen.zig+1-1
......@@ -856,7 +856,7 @@ pub fn generate(
856856 @intFromEnum(FrameIndex.stack_frame),
857857 FrameAlloc.init(.{
858858 .size = 0,
859 .alignment = func.analysis(ip).stack_alignment.max(.@"1"),
859 .alignment = func.analysisUnordered(ip).stack_alignment.max(.@"1"),
860860 }),
861861 );
862862 function.frame_allocs.set(
src/arch/x86_64/abi.zig+5-5
......@@ -349,7 +349,7 @@ fn classifySystemVStruct(
349349 .@"packed" => {},
350350 }
351351 } else if (pt.zcu.typeToUnion(field_ty)) |field_loaded_union| {
352 switch (field_loaded_union.getLayout(ip)) {
352 switch (field_loaded_union.flagsUnordered(ip).layout) {
353353 .auto, .@"extern" => {
354354 byte_offset = classifySystemVUnion(result, byte_offset, field_loaded_union, pt, target);
355355 continue;
......@@ -362,11 +362,11 @@ fn classifySystemVStruct(
362362 result_class.* = result_class.combineSystemV(field_class);
363363 byte_offset += field_ty.abiSize(pt);
364364 }
365 const final_byte_offset = starting_byte_offset + loaded_struct.size(ip).*;
365 const final_byte_offset = starting_byte_offset + loaded_struct.sizeUnordered(ip);
366366 std.debug.assert(final_byte_offset == std.mem.alignForward(
367367 u64,
368368 byte_offset,
369 loaded_struct.flagsPtr(ip).alignment.toByteUnits().?,
369 loaded_struct.flagsUnordered(ip).alignment.toByteUnits().?,
370370 ));
371371 return final_byte_offset;
372372}
......@@ -390,7 +390,7 @@ fn classifySystemVUnion(
390390 .@"packed" => {},
391391 }
392392 } else if (pt.zcu.typeToUnion(field_ty)) |field_loaded_union| {
393 switch (field_loaded_union.getLayout(ip)) {
393 switch (field_loaded_union.flagsUnordered(ip).layout) {
394394 .auto, .@"extern" => {
395395 _ = classifySystemVUnion(result, starting_byte_offset, field_loaded_union, pt, target);
396396 continue;
......@@ -402,7 +402,7 @@ fn classifySystemVUnion(
402402 for (result[@intCast(starting_byte_offset / 8)..][0..field_classes.len], field_classes) |*result_class, field_class|
403403 result_class.* = result_class.combineSystemV(field_class);
404404 }
405 return starting_byte_offset + loaded_union.size(ip).*;
405 return starting_byte_offset + loaded_union.sizeUnordered(ip);
406406}
407407
408408pub const SysV = struct {
src/codegen.zig+2-2
......@@ -548,8 +548,8 @@ pub fn generateSymbol(
548548 }
549549 }
550550
551 const size = struct_type.size(ip).*;
552 const alignment = struct_type.flagsPtr(ip).alignment.toByteUnits().?;
551 const size = struct_type.sizeUnordered(ip);
552 const alignment = struct_type.flagsUnordered(ip).alignment.toByteUnits().?;
553553
554554 const padding = math.cast(
555555 usize,
src/codegen/c.zig+7-7
......@@ -1366,7 +1366,7 @@ pub const DeclGen = struct {
13661366 const loaded_union = ip.loadUnionType(ty.toIntern());
13671367 if (un.tag == .none) {
13681368 const backing_ty = try ty.unionBackingType(pt);
1369 switch (loaded_union.getLayout(ip)) {
1369 switch (loaded_union.flagsUnordered(ip).layout) {
13701370 .@"packed" => {
13711371 if (!location.isInitializer()) {
13721372 try writer.writeByte('(');
......@@ -1401,7 +1401,7 @@ pub const DeclGen = struct {
14011401 const field_index = zcu.unionTagFieldIndex(loaded_union, Value.fromInterned(un.tag)).?;
14021402 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
14031403 const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];
1404 if (loaded_union.getLayout(ip) == .@"packed") {
1404 if (loaded_union.flagsUnordered(ip).layout == .@"packed") {
14051405 if (field_ty.hasRuntimeBits(pt)) {
14061406 if (field_ty.isPtrAtRuntime(zcu)) {
14071407 try writer.writeByte('(');
......@@ -1629,7 +1629,7 @@ pub const DeclGen = struct {
16291629 },
16301630 .union_type => {
16311631 const loaded_union = ip.loadUnionType(ty.toIntern());
1632 switch (loaded_union.getLayout(ip)) {
1632 switch (loaded_union.flagsUnordered(ip).layout) {
16331633 .auto, .@"extern" => {
16341634 if (!location.isInitializer()) {
16351635 try writer.writeByte('(');
......@@ -1792,7 +1792,7 @@ pub const DeclGen = struct {
17921792 else => unreachable,
17931793 }
17941794 }
1795 if (fn_val.getFunction(zcu)) |func| if (func.analysis(ip).is_cold)
1795 if (fn_val.getFunction(zcu)) |func| if (func.analysisUnordered(ip).is_cold)
17961796 try w.writeAll("zig_cold ");
17971797 if (fn_info.return_type == .noreturn_type) try w.writeAll("zig_noreturn ");
17981798
......@@ -5527,7 +5527,7 @@ fn fieldLocation(
55275527 .{ .field = field_index } },
55285528 .union_type => {
55295529 const loaded_union = ip.loadUnionType(container_ty.toIntern());
5530 switch (loaded_union.getLayout(ip)) {
5530 switch (loaded_union.flagsUnordered(ip).layout) {
55315531 .auto, .@"extern" => {
55325532 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
55335533 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt))
......@@ -5763,7 +5763,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
57635763 .{ .field = extra.field_index },
57645764 .union_type => field_name: {
57655765 const loaded_union = ip.loadUnionType(struct_ty.toIntern());
5766 switch (loaded_union.getLayout(ip)) {
5766 switch (loaded_union.flagsUnordered(ip).layout) {
57675767 .auto, .@"extern" => {
57685768 const name = loaded_union.loadTagType(ip).names.get(ip)[extra.field_index];
57695769 break :field_name if (loaded_union.hasTag(ip))
......@@ -7267,7 +7267,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
72677267
72687268 const writer = f.object.writer();
72697269 const local = try f.allocLocal(inst, union_ty);
7270 if (loaded_union.getLayout(ip) == .@"packed") return f.moveCValue(inst, union_ty, payload);
7270 if (loaded_union.flagsUnordered(ip).layout == .@"packed") return f.moveCValue(inst, union_ty, payload);
72717271
72727272 const field: CValue = if (union_ty.unionTagTypeSafety(zcu)) |tag_ty| field: {
72737273 const layout = union_ty.unionGetLayout(pt);
src/codegen/c/Type.zig+2-2
......@@ -1744,7 +1744,7 @@ pub const Pool = struct {
17441744 .@"packed" => return pool.fromType(
17451745 allocator,
17461746 scratch,
1747 Type.fromInterned(loaded_struct.backingIntType(ip).*),
1747 Type.fromInterned(loaded_struct.backingIntTypeUnordered(ip)),
17481748 pt,
17491749 mod,
17501750 kind,
......@@ -1817,7 +1817,7 @@ pub const Pool = struct {
18171817 },
18181818 .union_type => {
18191819 const loaded_union = ip.loadUnionType(ip_index);
1820 switch (loaded_union.getLayout(ip)) {
1820 switch (loaded_union.flagsUnordered(ip).layout) {
18211821 .auto, .@"extern" => {
18221822 const has_tag = loaded_union.hasTag(ip);
18231823 const fwd_decl = try pool.getFwdDecl(allocator, .{
src/codegen/llvm.zig+16-15
......@@ -1086,7 +1086,7 @@ pub const Object = struct {
10861086 // If there is no such function in the module, it means the source code does not need it.
10871087 const name = o.builder.strtabStringIfExists(lt_errors_fn_name) orelse return;
10881088 const llvm_fn = o.builder.getGlobal(name) orelse return;
1089 const errors_len = o.pt.zcu.intern_pool.global_error_set.mutate.list.len;
1089 const errors_len = o.pt.zcu.intern_pool.global_error_set.getNamesFromMainThread().len;
10901090
10911091 var wip = try Builder.WipFunction.init(&o.builder, .{
10921092 .function = llvm_fn.ptrConst(&o.builder).kind.function,
......@@ -1385,13 +1385,14 @@ pub const Object = struct {
13851385 var attributes = try function_index.ptrConst(&o.builder).attributes.toWip(&o.builder);
13861386 defer attributes.deinit(&o.builder);
13871387
1388 if (func.analysis(ip).is_noinline) {
1388 const func_analysis = func.analysisUnordered(ip);
1389 if (func_analysis.is_noinline) {
13891390 try attributes.addFnAttr(.@"noinline", &o.builder);
13901391 } else {
13911392 _ = try attributes.removeFnAttr(.@"noinline");
13921393 }
13931394
1394 const stack_alignment = func.analysis(ip).stack_alignment;
1395 const stack_alignment = func.analysisUnordered(ip).stack_alignment;
13951396 if (stack_alignment != .none) {
13961397 try attributes.addFnAttr(.{ .alignstack = stack_alignment.toLlvm() }, &o.builder);
13971398 try attributes.addFnAttr(.@"noinline", &o.builder);
......@@ -1399,7 +1400,7 @@ pub const Object = struct {
13991400 _ = try attributes.removeFnAttr(.alignstack);
14001401 }
14011402
1402 if (func.analysis(ip).is_cold) {
1403 if (func_analysis.is_cold) {
14031404 try attributes.addFnAttr(.cold, &o.builder);
14041405 } else {
14051406 _ = try attributes.removeFnAttr(.cold);
......@@ -2403,7 +2404,7 @@ pub const Object = struct {
24032404 defer gpa.free(name);
24042405
24052406 if (zcu.typeToPackedStruct(ty)) |struct_type| {
2406 const backing_int_ty = struct_type.backingIntType(ip).*;
2407 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
24072408 if (backing_int_ty != .none) {
24082409 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);
24092410 const builder_name = try o.builder.metadataString(name);
......@@ -2615,7 +2616,7 @@ pub const Object = struct {
26152616 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
26162617
26172618 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2618 const field_align: InternPool.Alignment = switch (union_type.flagsPtr(ip).layout) {
2619 const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) {
26192620 .@"packed" => .none,
26202621 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),
26212622 };
......@@ -3303,7 +3304,7 @@ pub const Object = struct {
33033304 const struct_type = ip.loadStructType(t.toIntern());
33043305
33053306 if (struct_type.layout == .@"packed") {
3306 const int_ty = try o.lowerType(Type.fromInterned(struct_type.backingIntType(ip).*));
3307 const int_ty = try o.lowerType(Type.fromInterned(struct_type.backingIntTypeUnordered(ip)));
33073308 try o.type_map.put(o.gpa, t.toIntern(), int_ty);
33083309 return int_ty;
33093310 }
......@@ -3346,7 +3347,7 @@ pub const Object = struct {
33463347 // This is a zero-bit field. If there are runtime bits after this field,
33473348 // map to the next LLVM field (which we know exists): otherwise, don't
33483349 // map the field, indicating it's at the end of the struct.
3349 if (offset != struct_type.size(ip).*) {
3350 if (offset != struct_type.sizeUnordered(ip)) {
33503351 try o.struct_field_map.put(o.gpa, .{
33513352 .struct_ty = t.toIntern(),
33523353 .field_index = field_index,
......@@ -3450,7 +3451,7 @@ pub const Object = struct {
34503451 const union_obj = ip.loadUnionType(t.toIntern());
34513452 const layout = pt.getUnionLayout(union_obj);
34523453
3453 if (union_obj.flagsPtr(ip).layout == .@"packed") {
3454 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
34543455 const int_ty = try o.builder.intType(@intCast(t.bitSize(pt)));
34553456 try o.type_map.put(o.gpa, t.toIntern(), int_ty);
34563457 return int_ty;
......@@ -3697,7 +3698,7 @@ pub const Object = struct {
36973698 if (layout.payload_size == 0) return o.lowerValue(un.tag);
36983699
36993700 const union_obj = mod.typeToUnion(ty).?;
3700 const container_layout = union_obj.getLayout(ip);
3701 const container_layout = union_obj.flagsUnordered(ip).layout;
37013702
37023703 assert(container_layout == .@"packed");
37033704
......@@ -4205,7 +4206,7 @@ pub const Object = struct {
42054206 if (layout.payload_size == 0) return o.lowerValue(un.tag);
42064207
42074208 const union_obj = mod.typeToUnion(ty).?;
4208 const container_layout = union_obj.getLayout(ip);
4209 const container_layout = union_obj.flagsUnordered(ip).layout;
42094210
42104211 var need_unnamed = false;
42114212 const payload = if (un.tag != .none) p: {
......@@ -10045,7 +10046,7 @@ pub const FuncGen = struct {
1004510046 },
1004610047 .Struct => {
1004710048 if (mod.typeToPackedStruct(result_ty)) |struct_type| {
10048 const backing_int_ty = struct_type.backingIntType(ip).*;
10049 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
1004910050 assert(backing_int_ty != .none);
1005010051 const big_bits = Type.fromInterned(backing_int_ty).bitSize(pt);
1005110052 const int_ty = try o.builder.intType(@intCast(big_bits));
......@@ -10155,7 +10156,7 @@ pub const FuncGen = struct {
1015510156 const layout = union_ty.unionGetLayout(pt);
1015610157 const union_obj = mod.typeToUnion(union_ty).?;
1015710158
10158 if (union_obj.getLayout(ip) == .@"packed") {
10159 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
1015910160 const big_bits = union_ty.bitSize(pt);
1016010161 const int_llvm_ty = try o.builder.intType(@intCast(big_bits));
1016110162 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
......@@ -11281,7 +11282,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E
1128111282 .struct_type => {
1128211283 const struct_type = ip.loadStructType(return_type.toIntern());
1128311284 assert(struct_type.haveLayout(ip));
11284 const size: u64 = struct_type.size(ip).*;
11285 const size: u64 = struct_type.sizeUnordered(ip);
1128511286 assert((std.math.divCeil(u64, size, 8) catch unreachable) == types_index);
1128611287 if (size % 8 > 0) {
1128711288 types_buffer[types_index - 1] = try o.builder.intType(@intCast(size % 8 * 8));
......@@ -11587,7 +11588,7 @@ const ParamTypeIterator = struct {
1158711588 .struct_type => {
1158811589 const struct_type = ip.loadStructType(ty.toIntern());
1158911590 assert(struct_type.haveLayout(ip));
11590 const size: u64 = struct_type.size(ip).*;
11591 const size: u64 = struct_type.sizeUnordered(ip);
1159111592 assert((std.math.divCeil(u64, size, 8) catch unreachable) == types_index);
1159211593 if (size % 8 > 0) {
1159311594 types_buffer[types_index - 1] =
src/codegen/spirv.zig+3-3
......@@ -1463,7 +1463,7 @@ const DeclGen = struct {
14631463 const ip = &mod.intern_pool;
14641464 const union_obj = mod.typeToUnion(ty).?;
14651465
1466 if (union_obj.getLayout(ip) == .@"packed") {
1466 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
14671467 return self.todo("packed union types", .{});
14681468 }
14691469
......@@ -1735,7 +1735,7 @@ const DeclGen = struct {
17351735 };
17361736
17371737 if (struct_type.layout == .@"packed") {
1738 return try self.resolveType(Type.fromInterned(struct_type.backingIntType(ip).*), .direct);
1738 return try self.resolveType(Type.fromInterned(struct_type.backingIntTypeUnordered(ip)), .direct);
17391739 }
17401740
17411741 var member_types = std.ArrayList(IdRef).init(self.gpa);
......@@ -5081,7 +5081,7 @@ const DeclGen = struct {
50815081 const union_ty = mod.typeToUnion(ty).?;
50825082 const tag_ty = Type.fromInterned(union_ty.enum_tag_ty);
50835083
5084 if (union_ty.getLayout(ip) == .@"packed") {
5084 if (union_ty.flagsUnordered(ip).layout == .@"packed") {
50855085 unreachable; // TODO
50865086 }
50875087
src/link/Coff.zig+1-1
......@@ -1156,7 +1156,7 @@ pub fn updateFunc(self: *Coff, pt: Zcu.PerThread, func_index: InternPool.Index,
11561156 const code = switch (res) {
11571157 .ok => code_buffer.items,
11581158 .fail => |em| {
1159 func.analysis(&mod.intern_pool).state = .codegen_failure;
1159 func.setAnalysisState(&mod.intern_pool, .codegen_failure);
11601160 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
11611161 return;
11621162 },
src/link/Elf/ZigObject.zig+1-1
......@@ -1093,7 +1093,7 @@ pub fn updateFunc(
10931093 const code = switch (res) {
10941094 .ok => code_buffer.items,
10951095 .fail => |em| {
1096 func.analysis(&mod.intern_pool).state = .codegen_failure;
1096 func.setAnalysisState(&mod.intern_pool, .codegen_failure);
10971097 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
10981098 return;
10991099 },
src/link/MachO/ZigObject.zig+1-1
......@@ -699,7 +699,7 @@ pub fn updateFunc(
699699 const code = switch (res) {
700700 .ok => code_buffer.items,
701701 .fail => |em| {
702 func.analysis(&mod.intern_pool).state = .codegen_failure;
702 func.setAnalysisState(&mod.intern_pool, .codegen_failure);
703703 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
704704 return;
705705 },
src/link/Plan9.zig+1-1
......@@ -449,7 +449,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
449449 const code = switch (res) {
450450 .ok => try code_buffer.toOwnedSlice(),
451451 .fail => |em| {
452 func.analysis(&mod.intern_pool).state = .codegen_failure;
452 func.setAnalysisState(&mod.intern_pool, .codegen_failure);
453453 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
454454 return;
455455 },
src/link/Wasm/ZigObject.zig+1-1
......@@ -1051,7 +1051,7 @@ fn setupErrorsLen(zig_object: *ZigObject, wasm_file: *Wasm) !void {
10511051 const gpa = wasm_file.base.comp.gpa;
10521052 const sym_index = zig_object.findGlobalSymbol("__zig_errors_len") orelse return;
10531053
1054 const errors_len = 1 + wasm_file.base.comp.module.?.intern_pool.global_error_set.mutate.list.len;
1054 const errors_len = 1 + wasm_file.base.comp.module.?.intern_pool.global_error_set.getNamesFromMainThread().len;
10551055 // overwrite existing atom if it already exists (maybe the error set has increased)
10561056 // if not, allcoate a new atom.
10571057 const atom_index = if (wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = sym_index })) |index| blk: {