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 {...@@ -501,8 +501,8 @@ fn checkType(ty: Type, zcu: *Zcu) bool {
501 .struct_type => {501 .struct_type => {
502 const struct_obj = zcu.typeToStruct(ty).?;502 const struct_obj = zcu.typeToStruct(ty).?;
503 return switch (struct_obj.layout) {503 return switch (struct_obj.layout) {
504 .@"packed" => struct_obj.backingIntType(ip).* != .none,504 .@"packed" => struct_obj.backingIntTypeUnordered(ip) != .none,
505 .auto, .@"extern" => struct_obj.flagsPtr(ip).fully_resolved,505 .auto, .@"extern" => struct_obj.flagsUnordered(ip).fully_resolved,
506 };506 };
507 },507 },
508 .anon_struct_type => |tuple| {508 .anon_struct_type => |tuple| {
...@@ -516,6 +516,6 @@ fn checkType(ty: Type, zcu: *Zcu) bool {...@@ -516,6 +516,6 @@ fn checkType(ty: Type, zcu: *Zcu) bool {
516 },516 },
517 else => unreachable,517 else => unreachable,
518 },518 },
519 .Union => return zcu.typeToUnion(ty).?.flagsPtr(ip).status == .fully_resolved,519 .Union => return zcu.typeToUnion(ty).?.flagsUnordered(ip).status == .fully_resolved,
520 };520 };
521}521}
src/Compilation.zig+2-2
...@@ -3011,7 +3011,7 @@ pub fn totalErrorCount(comp: *Compilation) u32 {...@@ -3011,7 +3011,7 @@ pub fn totalErrorCount(comp: *Compilation) u32 {
3011 }3011 }
3012 }3012 }
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) {
3015 total += 1;3015 total += 1;
3016 }3016 }
3017 }3017 }
...@@ -3140,7 +3140,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {...@@ -3140,7 +3140,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
3140 try addModuleErrorMsg(zcu, &bundle, value.*, &all_references);3140 try addModuleErrorMsg(zcu, &bundle, value.*, &all_references);
3141 }3141 }
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;
3144 if (actual_error_count > zcu.error_limit) {3144 if (actual_error_count > zcu.error_limit) {
3145 try bundle.addRootErrorMessage(.{3145 try bundle.addRootErrorMessage(.{
3146 .msg = try bundle.printString("ZCU used more errors than possible: used {d}, max {d}", .{3146 .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(...@@ -147,8 +147,6 @@ pub fn trackZir(
147 }147 }
148 defer shard.mutate.tracked_inst_map.len += 1;148 defer shard.mutate.tracked_inst_map.len += 1;
149 const local = ip.getLocal(tid);149 const local = ip.getLocal(tid);
150 local.mutate.tracked_insts.mutex.lock();
151 defer local.mutate.tracked_insts.mutex.unlock();
152 const list = local.getMutableTrackedInsts(gpa);150 const list = local.getMutableTrackedInsts(gpa);
153 try list.ensureUnusedCapacity(1);151 try list.ensureUnusedCapacity(1);
154 const map_header = map.header().*;152 const map_header = map.header().*;
...@@ -418,10 +416,10 @@ const Local = struct {...@@ -418,10 +416,10 @@ const Local = struct {
418 arena: std.heap.ArenaAllocator.State,416 arena: std.heap.ArenaAllocator.State,
419417
420 items: ListMutate,418 items: ListMutate,
421 extra: MutexListMutate,419 extra: ListMutate,
422 limbs: ListMutate,420 limbs: ListMutate,
423 strings: ListMutate,421 strings: ListMutate,
424 tracked_insts: MutexListMutate,422 tracked_insts: ListMutate,
425 files: ListMutate,423 files: ListMutate,
426 maps: ListMutate,424 maps: ListMutate,
427425
...@@ -471,20 +469,12 @@ const Local = struct {...@@ -471,20 +469,12 @@ const Local = struct {
471 const Namespaces = List(struct { *[1 << namespaces_bucket_width]Zcu.Namespace });469 const Namespaces = List(struct { *[1 << namespaces_bucket_width]Zcu.Namespace });
472470
473 const ListMutate = struct {471 const ListMutate = struct {
472 mutex: std.Thread.Mutex,
474 len: u32,473 len: u32,
475474
476 const empty: ListMutate = .{475 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 = .{
486 .mutex = .{},476 .mutex = .{},
487 .list = ListMutate.empty,477 .len = 0,
488 };478 };
489 };479 };
490480
...@@ -694,6 +684,8 @@ const Local = struct {...@@ -694,6 +684,8 @@ const Local = struct {
694 const new_slice = new_list.view().slice();684 const new_slice = new_list.view().slice();
695 inline for (fields) |field| @memcpy(new_slice.items(field)[0..len], old_slice.items(field)[0..len]);685 inline for (fields) |field| @memcpy(new_slice.items(field)[0..len], old_slice.items(field)[0..len]);
696 }686 }
687 mutable.mutate.mutex.lock();
688 defer mutable.mutate.mutex.unlock();
697 mutable.list.release(new_list);689 mutable.list.release(new_list);
698 }690 }
699691
...@@ -760,7 +752,7 @@ const Local = struct {...@@ -760,7 +752,7 @@ const Local = struct {
760 return .{752 return .{
761 .gpa = gpa,753 .gpa = gpa,
762 .arena = &local.mutate.arena,754 .arena = &local.mutate.arena,
763 .mutate = &local.mutate.extra.list,755 .mutate = &local.mutate.extra,
764 .list = &local.shared.extra,756 .list = &local.shared.extra,
765 };757 };
766 }758 }
...@@ -802,7 +794,7 @@ const Local = struct {...@@ -802,7 +794,7 @@ const Local = struct {
802 return .{794 return .{
803 .gpa = gpa,795 .gpa = gpa,
804 .arena = &local.mutate.arena,796 .arena = &local.mutate.arena,
805 .mutate = &local.mutate.tracked_insts.list,797 .mutate = &local.mutate.tracked_insts,
806 .list = &local.shared.tracked_insts,798 .list = &local.shared.tracked_insts,
807 };799 };
808 }800 }
...@@ -1714,29 +1706,76 @@ pub const Key = union(enum) {...@@ -1714,29 +1706,76 @@ pub const Key = union(enum) {
1714 comptime_args: Index.Slice,1706 comptime_args: Index.Slice,
17151707
1716 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.1708 /// 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 {
1718 const extra = ip.getLocalShared(func.tid).extra.acquire();1710 const extra = ip.getLocalShared(func.tid).extra.acquire();
1719 return @ptrCast(&extra.view().items(.@"0")[func.analysis_extra_index]);1711 return @ptrCast(&extra.view().items(.@"0")[func.analysis_extra_index]);
1720 }1712 }
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
1722 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.1740 /// 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 {
1724 const extra = ip.getLocalShared(func.tid).extra.acquire();1742 const extra = ip.getLocalShared(func.tid).extra.acquire();
1725 return @ptrCast(&extra.view().items(.@"0")[func.zir_body_inst_extra_index]);1743 return @ptrCast(&extra.view().items(.@"0")[func.zir_body_inst_extra_index]);
1726 }1744 }
17271745
1746 pub fn zirBodyInstUnordered(func: Func, ip: *const InternPool) TrackedInst.Index {
1747 return @atomicLoad(TrackedInst.Index, func.zirBodyInstPtr(@constCast(ip)), .unordered);
1748 }
1749
1728 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.1750 /// 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 {
1730 const extra = ip.getLocalShared(func.tid).extra.acquire();1752 const extra = ip.getLocalShared(func.tid).extra.acquire();
1731 return &extra.view().items(.@"0")[func.branch_quota_extra_index];1753 return &extra.view().items(.@"0")[func.branch_quota_extra_index];
1732 }1754 }
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
1734 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.1769 /// 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 {
1736 const extra = ip.getLocalShared(func.tid).extra.acquire();1771 const extra = ip.getLocalShared(func.tid).extra.acquire();
1737 assert(func.analysis(ip).inferred_error_set);1772 assert(func.analysisUnordered(ip).inferred_error_set);
1738 return @ptrCast(&extra.view().items(.@"0")[func.resolved_error_set_extra_index]);1773 return @ptrCast(&extra.view().items(.@"0")[func.resolved_error_set_extra_index]);
1739 }1774 }
1775
1776 pub fn resolvedErrorSetUnordered(func: Func, ip: *const InternPool) Index {
1777 return @atomicLoad(Index, func.resolvedErrorSetPtr(@constCast(ip)), .unordered);
1778 }
1740 };1779 };
17411780
1742 pub const Int = struct {1781 pub const Int = struct {
...@@ -2663,47 +2702,170 @@ pub const LoadedUnionType = struct {...@@ -2663,47 +2702,170 @@ pub const LoadedUnionType = struct {
2663 /// This accessor is provided so that the tag type can be mutated, and so that2702 /// This accessor is provided so that the tag type can be mutated, and so that
2664 /// when it is mutated, the mutations are observed.2703 /// when it is mutated, the mutations are observed.
2665 /// The returned pointer expires with any addition to the `InternPool`.2704 /// 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 {
2667 const extra = ip.getLocalShared(self.tid).extra.acquire();2706 const extra = ip.getLocalShared(self.tid).extra.acquire();
2668 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "tag_ty").?;2707 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "tag_ty").?;
2669 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + field_index]);2708 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + field_index]);
2670 }2709 }
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
2672 /// The returned pointer expires with any addition to the `InternPool`.2723 /// 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 {
2674 const extra = ip.getLocalShared(self.tid).extra.acquire();2725 const extra = ip.getLocalShared(self.tid).extra.acquire();
2675 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "flags").?;2726 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "flags").?;
2676 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + field_index]);2727 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + field_index]);
2677 }2728 }
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
2679 /// The returned pointer expires with any addition to the `InternPool`.2823 /// 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 {
2681 const extra = ip.getLocalShared(self.tid).extra.acquire();2825 const extra = ip.getLocalShared(self.tid).extra.acquire();
2682 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "size").?;2826 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "size").?;
2683 return &extra.view().items(.@"0")[self.extra_index + field_index];2827 return &extra.view().items(.@"0")[self.extra_index + field_index];
2684 }2828 }
26852829
2830 pub fn sizeUnordered(u: LoadedUnionType, ip: *const InternPool) u32 {
2831 return @atomicLoad(u32, u.sizePtr(@constCast(ip)), .unordered);
2832 }
2833
2686 /// The returned pointer expires with any addition to the `InternPool`.2834 /// 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 {
2688 const extra = ip.getLocalShared(self.tid).extra.acquire();2836 const extra = ip.getLocalShared(self.tid).extra.acquire();
2689 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "padding").?;2837 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "padding").?;
2690 return &extra.view().items(.@"0")[self.extra_index + field_index];2838 return &extra.view().items(.@"0")[self.extra_index + field_index];
2691 }2839 }
26922840
2841 pub fn paddingUnordered(u: LoadedUnionType, ip: *const InternPool) u32 {
2842 return @atomicLoad(u32, u.paddingPtr(@constCast(ip)), .unordered);
2843 }
2844
2693 pub fn hasTag(self: LoadedUnionType, ip: *const InternPool) bool {2845 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();
2695 }2847 }
26962848
2697 pub fn haveFieldTypes(self: LoadedUnionType, ip: *const InternPool) bool {2849 pub fn haveFieldTypes(self: LoadedUnionType, ip: *const InternPool) bool {
2698 return self.flagsPtr(ip).status.haveFieldTypes();2850 return self.flagsUnordered(ip).status.haveFieldTypes();
2699 }2851 }
27002852
2701 pub fn haveLayout(self: LoadedUnionType, ip: *const InternPool) bool {2853 pub fn haveLayout(self: LoadedUnionType, ip: *const InternPool) bool {
2702 return self.flagsPtr(ip).status.haveLayout();2854 return self.flagsUnordered(ip).status.haveLayout();
2703 }2855 }
27042856
2705 pub fn getLayout(self: LoadedUnionType, ip: *const InternPool) std.builtin.Type.ContainerLayout {2857 pub fn setHaveLayout(u: LoadedUnionType, ip: *InternPool, size: u32, padding: u32, alignment: Alignment) void {
2706 return self.flagsPtr(ip).layout;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);
2707 }2869 }
27082870
2709 pub fn fieldAlign(self: LoadedUnionType, ip: *const InternPool, field_index: usize) Alignment {2871 pub fn fieldAlign(self: LoadedUnionType, ip: *const InternPool, field_index: usize) Alignment {
...@@ -2726,7 +2888,7 @@ pub const LoadedUnionType = struct {...@@ -2726,7 +2888,7 @@ pub const LoadedUnionType = struct {
27262888
2727 pub fn setFieldAligns(self: LoadedUnionType, ip: *const InternPool, aligns: []const Alignment) void {2889 pub fn setFieldAligns(self: LoadedUnionType, ip: *const InternPool, aligns: []const Alignment) void {
2728 if (aligns.len == 0) return;2890 if (aligns.len == 0) return;
2729 assert(self.flagsPtr(ip).any_aligned_fields);2891 assert(self.flagsUnordered(ip).any_aligned_fields);
2730 @memcpy(self.field_aligns.get(ip), aligns);2892 @memcpy(self.field_aligns.get(ip), aligns);
2731 }2893 }
2732};2894};
...@@ -2877,26 +3039,26 @@ pub const LoadedStructType = struct {...@@ -2877,26 +3039,26 @@ pub const LoadedStructType = struct {
2877 };3039 };
28783040
2879 /// Look up field index based on field name.3041 /// Look up field index based on field name.
2880 pub fn nameIndex(self: LoadedStructType, ip: *const InternPool, name: NullTerminatedString) ?u32 {3042 pub fn nameIndex(s: LoadedStructType, ip: *const InternPool, name: NullTerminatedString) ?u32 {
2881 const names_map = self.names_map.unwrap() orelse {3043 const names_map = s.names_map.unwrap() orelse {
2882 const i = name.toUnsigned(ip) orelse return null;3044 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;
2884 return i;3046 return i;
2885 };3047 };
2886 const map = names_map.getConst(ip);3048 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) };
2888 const field_index = map.getIndexAdapted(name, adapter) orelse return null;3050 const field_index = map.getIndexAdapted(name, adapter) orelse return null;
2889 return @intCast(field_index);3051 return @intCast(field_index);
2890 }3052 }
28913053
2892 /// Returns the already-existing field with the same name, if any.3054 /// Returns the already-existing field with the same name, if any.
2893 pub fn addFieldName(3055 pub fn addFieldName(
2894 self: LoadedStructType,3056 s: LoadedStructType,
2895 ip: *InternPool,3057 ip: *InternPool,
2896 name: NullTerminatedString,3058 name: NullTerminatedString,
2897 ) ?u32 {3059 ) ?u32 {
2898 const extra = ip.getLocalShared(self.tid).extra.acquire();3060 const extra = ip.getLocalShared(s.tid).extra.acquire();
2899 return ip.addFieldName(extra, self.names_map.unwrap().?, self.field_names.start, name);3061 return ip.addFieldName(extra, s.names_map.unwrap().?, s.field_names.start, name);
2900 }3062 }
29013063
2902 pub fn fieldAlign(s: LoadedStructType, ip: *const InternPool, i: usize) Alignment {3064 pub fn fieldAlign(s: LoadedStructType, ip: *const InternPool, i: usize) Alignment {
...@@ -2924,143 +3086,313 @@ pub const LoadedStructType = struct {...@@ -2924,143 +3086,313 @@ pub const LoadedStructType = struct {
2924 s.comptime_bits.setBit(ip, i);3086 s.comptime_bits.setBit(ip, i);
2925 }3087 }
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
2927 /// Reads the non-opv flag calculated during AstGen. Used to short-circuit more3115 /// Reads the non-opv flag calculated during AstGen. Used to short-circuit more
2928 /// complicated logic.3116 /// complicated logic.
2929 pub fn knownNonOpv(s: LoadedStructType, ip: *InternPool) bool {3117 pub fn knownNonOpv(s: LoadedStructType, ip: *const InternPool) bool {
2930 return switch (s.layout) {3118 return switch (s.layout) {
2931 .@"packed" => false,3119 .@"packed" => false,
2932 .auto, .@"extern" => s.flagsPtr(ip).known_non_opv,3120 .auto, .@"extern" => s.flagsUnordered(ip).known_non_opv,
2933 };3121 };
2934 }3122 }
29353123
2936 /// The returned pointer expires with any addition to the `InternPool`.3124 pub fn requiresComptime(s: LoadedStructType, ip: *const InternPool) RequiresComptime {
2937 /// Asserts the struct is not packed.3125 return s.flagsUnordered(ip).requires_comptime;
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]);
2943 }3126 }
29443127
2945 /// The returned pointer expires with any addition to the `InternPool`.3128 pub fn setRequiresComptimeWip(s: LoadedStructType, ip: *InternPool) RequiresComptime {
2946 /// Asserts that the struct is packed.3129 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
2947 pub fn packedFlagsPtr(self: LoadedStructType, ip: *InternPool) *Tag.TypeStructPacked.Flags {3130 extra_mutex.lock();
2948 assert(self.layout == .@"packed");3131 defer extra_mutex.unlock();
2949 const extra = ip.getLocalShared(self.tid).extra.acquire();3132
2950 const flags_field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?;3133 const flags_ptr = s.flagsPtr(ip);
2951 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + flags_field_index]);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);
2952 }3153 }
29533154
2954 pub fn assumeRuntimeBitsIfFieldTypesWip(s: LoadedStructType, ip: *InternPool) bool {3155 pub fn assumeRuntimeBitsIfFieldTypesWip(s: LoadedStructType, ip: *InternPool) bool {
2955 if (s.layout == .@"packed") return false;3156 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
2956 const flags_ptr = s.flagsPtr(ip);3162 const flags_ptr = s.flagsPtr(ip);
2957 if (flags_ptr.field_types_wip) {3163 var flags = flags_ptr.*;
2958 flags_ptr.assumed_runtime_bits = true;3164 defer if (flags.field_types_wip) {
2959 return true;3165 flags.assumed_runtime_bits = true;
2960 }3166 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
2961 return false;3167 };
3168 return flags.field_types_wip;
2962 }3169 }
29633170
2964 pub fn setTypesWip(s: LoadedStructType, ip: *InternPool) bool {3171 pub fn setFieldTypesWip(s: LoadedStructType, ip: *InternPool) bool {
2965 if (s.layout == .@"packed") return false;3172 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
2966 const flags_ptr = s.flagsPtr(ip);3178 const flags_ptr = s.flagsPtr(ip);
2967 if (flags_ptr.field_types_wip) return true;3179 var flags = flags_ptr.*;
2968 flags_ptr.field_types_wip = true;3180 defer {
2969 return false;3181 flags.field_types_wip = true;
3182 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3183 }
3184 return flags.field_types_wip;
2970 }3185 }
29713186
2972 pub fn clearTypesWip(s: LoadedStructType, ip: *InternPool) void {3187 pub fn clearFieldTypesWip(s: LoadedStructType, ip: *InternPool) void {
2973 if (s.layout == .@"packed") return;3188 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);
2975 }3198 }
29763199
2977 pub fn setLayoutWip(s: LoadedStructType, ip: *InternPool) bool {3200 pub fn setLayoutWip(s: LoadedStructType, ip: *InternPool) bool {
2978 if (s.layout == .@"packed") return false;3201 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
2979 const flags_ptr = s.flagsPtr(ip);3207 const flags_ptr = s.flagsPtr(ip);
2980 if (flags_ptr.layout_wip) return true;3208 var flags = flags_ptr.*;
2981 flags_ptr.layout_wip = true;3209 defer {
2982 return false;3210 flags.layout_wip = true;
3211 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3212 }
3213 return flags.layout_wip;
2983 }3214 }
29843215
2985 pub fn clearLayoutWip(s: LoadedStructType, ip: *InternPool) void {3216 pub fn clearLayoutWip(s: LoadedStructType, ip: *InternPool) void {
2986 if (s.layout == .@"packed") return;3217 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);
2988 }3227 }
29893228
2990 pub fn setAlignmentWip(s: LoadedStructType, ip: *InternPool) bool {3229 pub fn setAlignment(s: LoadedStructType, ip: *InternPool, alignment: Alignment) void {
2991 if (s.layout == .@"packed") return false;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
2992 const flags_ptr = s.flagsPtr(ip);3260 const flags_ptr = s.flagsPtr(ip);
2993 if (flags_ptr.alignment_wip) return true;3261 var flags = flags_ptr.*;
2994 flags_ptr.alignment_wip = true;3262 defer {
2995 return false;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;
2996 }3270 }
29973271
2998 pub fn clearAlignmentWip(s: LoadedStructType, ip: *InternPool) void {3272 pub fn clearAlignmentWip(s: LoadedStructType, ip: *InternPool) void {
2999 if (s.layout == .@"packed") return;3273 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);
3001 }3283 }
30023284
3003 pub fn setInitsWip(s: LoadedStructType, ip: *InternPool) bool {3285 pub fn setInitsWip(s: LoadedStructType, ip: *InternPool) bool {
3004 const local = ip.getLocal(s.tid);3286 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3005 local.mutate.extra.mutex.lock();3287 extra_mutex.lock();
3006 defer local.mutate.extra.mutex.unlock();3288 defer extra_mutex.unlock();
3007 return switch (s.layout) {3289
3008 .@"packed" => @as(Tag.TypeStructPacked.Flags, @bitCast(@atomicRmw(3290 switch (s.layout) {
3009 u32,3291 .@"packed" => {
3010 @as(*u32, @ptrCast(s.packedFlagsPtr(ip))),3292 const flags_ptr = s.packedFlagsPtr(ip);
3011 .Or,3293 var flags = flags_ptr.*;
3012 @bitCast(Tag.TypeStructPacked.Flags{ .field_inits_wip = true }),3294 defer {
3013 .acq_rel,3295 flags.field_inits_wip = true;
3014 ))).field_inits_wip,3296 @atomicStore(Tag.TypeStructPacked.Flags, flags_ptr, flags, .release);
3015 .auto, .@"extern" => @as(Tag.TypeStruct.Flags, @bitCast(@atomicRmw(3297 }
3016 u32,3298 return flags.field_inits_wip;
3017 @as(*u32, @ptrCast(s.flagsPtr(ip))),3299 },
3018 .Or,3300 .auto, .@"extern" => {
3019 @bitCast(Tag.TypeStruct.Flags{ .field_inits_wip = true }),3301 const flags_ptr = s.flagsPtr(ip);
3020 .acq_rel,3302 var flags = flags_ptr.*;
3021 ))).field_inits_wip,3303 defer {
3022 };3304 flags.field_inits_wip = true;
3305 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3306 }
3307 return flags.field_inits_wip;
3308 },
3309 }
3023 }3310 }
30243311
3025 pub fn clearInitsWip(s: LoadedStructType, ip: *InternPool) void {3312 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
3026 switch (s.layout) {3317 switch (s.layout) {
3027 .@"packed" => s.packedFlagsPtr(ip).field_inits_wip = false,3318 .@"packed" => {
3028 .auto, .@"extern" => s.flagsPtr(ip).field_inits_wip = false,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 },
3029 }3330 }
3030 }3331 }
30313332
3032 pub fn setFullyResolved(s: LoadedStructType, ip: *InternPool) bool {3333 pub fn setFullyResolved(s: LoadedStructType, ip: *InternPool) bool {
3033 if (s.layout == .@"packed") return true;3334 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
3034 const flags_ptr = s.flagsPtr(ip);3340 const flags_ptr = s.flagsPtr(ip);
3035 if (flags_ptr.fully_resolved) return true;3341 var flags = flags_ptr.*;
3036 flags_ptr.fully_resolved = true;3342 defer {
3037 return false;3343 flags.fully_resolved = true;
3344 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3345 }
3346 return flags.fully_resolved;
3038 }3347 }
30393348
3040 pub fn clearFullyResolved(s: LoadedStructType, ip: *InternPool) void {3349 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);
3042 }3358 }
30433359
3044 /// The returned pointer expires with any addition to the `InternPool`.3360 /// The returned pointer expires with any addition to the `InternPool`.
3045 /// Asserts the struct is not packed.3361 /// Asserts the struct is not packed.
3046 pub fn size(self: LoadedStructType, ip: *InternPool) *u32 {3362 fn sizePtr(s: LoadedStructType, ip: *InternPool) *u32 {
3047 assert(self.layout != .@"packed");3363 assert(s.layout != .@"packed");
3048 const extra = ip.getLocalShared(self.tid).extra.acquire();3364 const extra = ip.getLocalShared(s.tid).extra.acquire();
3049 const size_field_index = std.meta.fieldIndex(Tag.TypeStruct, "size").?;3365 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);
3051 }3371 }
30523372
3053 /// The backing integer type of the packed struct. Whether zig chooses3373 /// The backing integer type of the packed struct. Whether zig chooses
3054 /// this type or the user specifies it, it is stored here. This will be3374 /// this type or the user specifies it, it is stored here. This will be
3055 /// set to `none` until the layout is resolved.3375 /// set to `none` until the layout is resolved.
3056 /// Asserts the struct is packed.3376 /// Asserts the struct is packed.
3057 pub fn backingIntType(s: LoadedStructType, ip: *InternPool) *Index {3377 fn backingIntTypePtr(s: LoadedStructType, ip: *InternPool) *Index {
3058 assert(s.layout == .@"packed");3378 assert(s.layout == .@"packed");
3059 const extra = ip.getLocalShared(s.tid).extra.acquire();3379 const extra = ip.getLocalShared(s.tid).extra.acquire();
3060 const field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "backing_int_ty").?;3380 const field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "backing_int_ty").?;
3061 return @ptrCast(&extra.view().items(.@"0")[s.extra_index + field_index]);3381 return @ptrCast(&extra.view().items(.@"0")[s.extra_index + field_index]);
3062 }3382 }
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
3064 /// Asserts the struct is not packed.3396 /// Asserts the struct is not packed.
3065 pub fn setZirIndex(s: LoadedStructType, ip: *InternPool, new_zir_index: TrackedInst.Index.Optional) void {3397 pub fn setZirIndex(s: LoadedStructType, ip: *InternPool, new_zir_index: TrackedInst.Index.Optional) void {
3066 assert(s.layout != .@"packed");3398 assert(s.layout != .@"packed");
...@@ -3073,29 +3405,56 @@ pub const LoadedStructType = struct {...@@ -3073,29 +3405,56 @@ pub const LoadedStructType = struct {
3073 return types.len == 0 or types[0] != .none;3405 return types.len == 0 or types[0] != .none;
3074 }3406 }
30753407
3076 pub fn haveFieldInits(s: LoadedStructType, ip: *InternPool) bool {3408 pub fn haveFieldInits(s: LoadedStructType, ip: *const InternPool) bool {
3077 return switch (s.layout) {3409 return switch (s.layout) {
3078 .@"packed" => s.packedFlagsPtr(ip).inits_resolved,3410 .@"packed" => s.packedFlagsUnordered(ip).inits_resolved,
3079 .auto, .@"extern" => s.flagsPtr(ip).inits_resolved,3411 .auto, .@"extern" => s.flagsUnordered(ip).inits_resolved,
3080 };3412 };
3081 }3413 }
30823414
3083 pub fn setHaveFieldInits(s: LoadedStructType, ip: *InternPool) void {3415 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
3084 switch (s.layout) {3420 switch (s.layout) {
3085 .@"packed" => s.packedFlagsPtr(ip).inits_resolved = true,3421 .@"packed" => {
3086 .auto, .@"extern" => s.flagsPtr(ip).inits_resolved = true,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 },
3087 }3433 }
3088 }3434 }
30893435
3090 pub fn haveLayout(s: LoadedStructType, ip: *InternPool) bool {3436 pub fn haveLayout(s: LoadedStructType, ip: *InternPool) bool {
3091 return switch (s.layout) {3437 return switch (s.layout) {
3092 .@"packed" => s.backingIntType(ip).* != .none,3438 .@"packed" => s.backingIntTypeUnordered(ip) != .none,
3093 .auto, .@"extern" => s.flagsPtr(ip).layout_resolved,3439 .auto, .@"extern" => s.flagsUnordered(ip).layout_resolved,
3094 };3440 };
3095 }3441 }
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
3097 pub fn isTuple(s: LoadedStructType, ip: *InternPool) bool {3456 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;
3099 }3458 }
31003459
3101 pub fn hasReorderedFields(s: LoadedStructType) bool {3460 pub fn hasReorderedFields(s: LoadedStructType) bool {
...@@ -3209,7 +3568,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType {...@@ -3209,7 +3568,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType {
3209 const decl: DeclIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "decl").?]);3568 const decl: DeclIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "decl").?]);
3210 const zir_index: TrackedInst.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?]);3569 const zir_index: TrackedInst.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?]);
3211 const fields_len = extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "fields_len").?];3570 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));
3213 var extra_index = item.data + @as(u32, @typeInfo(Tag.TypeStruct).Struct.fields.len);3572 var extra_index = item.data + @as(u32, @typeInfo(Tag.TypeStruct).Struct.fields.len);
3214 const captures_len = if (flags.any_captures) c: {3573 const captures_len = if (flags.any_captures) c: {
3215 const len = extra_list.view().items(.@"0")[extra_index];3574 const len = extra_list.view().items(.@"0")[extra_index];
...@@ -3317,7 +3676,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType {...@@ -3317,7 +3676,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType {
3317 const fields_len = extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "fields_len").?];3676 const fields_len = extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "fields_len").?];
3318 const namespace: OptionalNamespaceIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "namespace").?]);3677 const namespace: OptionalNamespaceIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "namespace").?]);
3319 const names_map: MapIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "names_map").?]);3678 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));
3321 var extra_index = item.data + @as(u32, @typeInfo(Tag.TypeStructPacked).Struct.fields.len);3680 var extra_index = item.data + @as(u32, @typeInfo(Tag.TypeStructPacked).Struct.fields.len);
3322 const has_inits = item.tag == .type_struct_packed_inits;3681 const has_inits = item.tag == .type_struct_packed_inits;
3323 const captures_len = if (flags.any_captures) c: {3682 const captures_len = if (flags.any_captures) c: {
...@@ -5442,10 +5801,10 @@ pub fn init(ip: *InternPool, gpa: Allocator, available_threads: usize) !void {...@@ -5442,10 +5801,10 @@ pub fn init(ip: *InternPool, gpa: Allocator, available_threads: usize) !void {
5442 .arena = .{},5801 .arena = .{},
54435802
5444 .items = Local.ListMutate.empty,5803 .items = Local.ListMutate.empty,
5445 .extra = Local.MutexListMutate.empty,5804 .extra = Local.ListMutate.empty,
5446 .limbs = Local.ListMutate.empty,5805 .limbs = Local.ListMutate.empty,
5447 .strings = Local.ListMutate.empty,5806 .strings = Local.ListMutate.empty,
5448 .tracked_insts = Local.MutexListMutate.empty,5807 .tracked_insts = Local.ListMutate.empty,
5449 .files = Local.ListMutate.empty,5808 .files = Local.ListMutate.empty,
5450 .maps = Local.ListMutate.empty,5809 .maps = Local.ListMutate.empty,
54515810
...@@ -5635,7 +5994,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -5635,7 +5994,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
5635 const extra_list = unwrapped_index.getExtra(ip);5994 const extra_list = unwrapped_index.getExtra(ip);
5636 const extra_items = extra_list.view().items(.@"0");5995 const extra_items = extra_list.view().items(.@"0");
5637 const zir_index: TrackedInst.Index = @enumFromInt(extra_items[data + std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?]);5996 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));
5639 const end_extra_index = data + @as(u32, @typeInfo(Tag.TypeStruct).Struct.fields.len);5998 const end_extra_index = data + @as(u32, @typeInfo(Tag.TypeStruct).Struct.fields.len);
5640 if (flags.is_reified) {5999 if (flags.is_reified) {
5641 assert(!flags.any_captures);6000 assert(!flags.any_captures);
...@@ -5658,7 +6017,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {...@@ -5658,7 +6017,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
5658 const extra_list = unwrapped_index.getExtra(ip);6017 const extra_list = unwrapped_index.getExtra(ip);
5659 const extra_items = extra_list.view().items(.@"0");6018 const extra_items = extra_list.view().items(.@"0");
5660 const zir_index: TrackedInst.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "zir_index").?]);6019 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));
5662 const end_extra_index = data + @as(u32, @typeInfo(Tag.TypeStructPacked).Struct.fields.len);6021 const end_extra_index = data + @as(u32, @typeInfo(Tag.TypeStructPacked).Struct.fields.len);
5663 if (flags.is_reified) {6022 if (flags.is_reified) {
5664 assert(!flags.any_captures);6023 assert(!flags.any_captures);
...@@ -6155,7 +6514,7 @@ fn extraFuncDecl(tid: Zcu.PerThread.Id, extra: Local.Extra, extra_index: u32) Ke...@@ -6155,7 +6514,7 @@ fn extraFuncDecl(tid: Zcu.PerThread.Id, extra: Local.Extra, extra_index: u32) Ke
6155fn extraFuncInstance(ip: *const InternPool, tid: Zcu.PerThread.Id, extra: Local.Extra, extra_index: u32) Key.Func {6514fn extraFuncInstance(ip: *const InternPool, tid: Zcu.PerThread.Id, extra: Local.Extra, extra_index: u32) Key.Func {
6156 const extra_items = extra.view().items(.@"0");6515 const extra_items = extra.view().items(.@"0");
6157 const analysis_extra_index = extra_index + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?;6516 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));
6159 const owner_decl: DeclIndex = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "owner_decl").?]);6518 const owner_decl: DeclIndex = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "owner_decl").?]);
6160 const ty: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "ty").?]);6519 const ty: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "ty").?]);
6161 const generic_owner: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "generic_owner").?]);6520 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 {...@@ -8702,7 +9061,7 @@ pub fn remove(ip: *InternPool, tid: Zcu.PerThread.Id, index: Index) void {
8702 // Restore the original item at this index.9061 // Restore the original item at this index.
8703 assert(static_keys[@intFromEnum(index)] == .simple_type);9062 assert(static_keys[@intFromEnum(index)] == .simple_type);
8704 const items = ip.getLocalShared(unwrapped_index.tid).items.acquire().view();9063 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);
8706 return;9065 return;
8707 }9066 }
87089067
...@@ -8719,7 +9078,7 @@ pub fn remove(ip: *InternPool, tid: Zcu.PerThread.Id, index: Index) void {...@@ -8719,7 +9078,7 @@ pub fn remove(ip: *InternPool, tid: Zcu.PerThread.Id, index: Index) void {
8719 // Thus, we will rewrite the tag to `removed`, leaking the item until9078 // Thus, we will rewrite the tag to `removed`, leaking the item until
8720 // next GC but causing `KeyAdapter` to ignore it.9079 // next GC but causing `KeyAdapter` to ignore it.
8721 const items = ip.getLocalShared(unwrapped_index.tid).items.acquire().view();9080 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);
8723}9082}
87249083
8725fn addInt(9084fn addInt(
...@@ -9415,9 +9774,11 @@ pub fn errorUnionPayload(ip: *const InternPool, ty: Index) Index {...@@ -9415,9 +9774,11 @@ pub fn errorUnionPayload(ip: *const InternPool, ty: Index) Index {
9415/// The is only legal because the initializer is not part of the hash.9774/// The is only legal because the initializer is not part of the hash.
9416pub fn mutateVarInit(ip: *InternPool, index: Index, init_index: Index) void {9775pub fn mutateVarInit(ip: *InternPool, index: Index, init_index: Index) void {
9417 const unwrapped_index = index.unwrap(ip);9776 const unwrapped_index = index.unwrap(ip);
9777
9418 const local = ip.getLocal(unwrapped_index.tid);9778 const local = ip.getLocal(unwrapped_index.tid);
9419 local.mutate.extra.mutex.lock();9779 local.mutate.extra.mutex.lock();
9420 defer local.mutate.extra.mutex.unlock();9780 defer local.mutate.extra.mutex.unlock();
9781
9421 const extra_items = local.shared.extra.view().items(.@"0");9782 const extra_items = local.shared.extra.view().items(.@"0");
9422 const item = unwrapped_index.getItem(ip);9783 const item = unwrapped_index.getItem(ip);
9423 assert(item.tag == .variable);9784 assert(item.tag == .variable);
...@@ -9436,7 +9797,7 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {...@@ -9436,7 +9797,7 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
9436 var decls_len: usize = 0;9797 var decls_len: usize = 0;
9437 for (ip.locals) |*local| {9798 for (ip.locals) |*local| {
9438 items_len += local.mutate.items.len;9799 items_len += local.mutate.items.len;
9439 extra_len += local.mutate.extra.list.len;9800 extra_len += local.mutate.extra.len;
9440 limbs_len += local.mutate.limbs.len;9801 limbs_len += local.mutate.limbs.len;
9441 decls_len += local.mutate.decls.buckets_list.len;9802 decls_len += local.mutate.decls.buckets_list.len;
9442 }9803 }
...@@ -10730,29 +11091,29 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois...@@ -10730,29 +11091,29 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois
10730 };11091 };
10731}11092}
1073211093
10733pub fn isFuncBody(ip: *const InternPool, index: Index) bool {11094pub fn isFuncBody(ip: *const InternPool, func: Index) bool {
10734 return switch (index.unwrap(ip).getTag(ip)) {11095 return switch (func.unwrap(ip).getTag(ip)) {
10735 .func_decl, .func_instance, .func_coerced => true,11096 .func_decl, .func_instance, .func_coerced => true,
10736 else => false,11097 else => false,
10737 };11098 };
10738}11099}
1073911100
10740pub fn funcAnalysis(ip: *const InternPool, index: Index) *FuncAnalysis {11101fn funcAnalysisPtr(ip: *InternPool, func: Index) *FuncAnalysis {
10741 const unwrapped_index = index.unwrap(ip);11102 const unwrapped_func = func.unwrap(ip);
10742 const extra = unwrapped_index.getExtra(ip);11103 const extra = unwrapped_func.getExtra(ip);
10743 const item = unwrapped_index.getItem(ip);11104 const item = unwrapped_func.getItem(ip);
10744 const extra_index = switch (item.tag) {11105 const extra_index = switch (item.tag) {
10745 .func_decl => item.data + std.meta.fieldIndex(Tag.FuncDecl, "analysis").?,11106 .func_decl => item.data + std.meta.fieldIndex(Tag.FuncDecl, "analysis").?,
10746 .func_instance => item.data + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?,11107 .func_instance => item.data + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?,
10747 .func_coerced => {11108 .func_coerced => {
10748 const extra_index = item.data + std.meta.fieldIndex(Tag.FuncCoerced, "func").?;11109 const extra_index = item.data + std.meta.fieldIndex(Tag.FuncCoerced, "func").?;
10749 const func_index: Index = @enumFromInt(extra.view().items(.@"0")[extra_index]);11110 const coerced_func_index: Index = @enumFromInt(extra.view().items(.@"0")[extra_index]);
10750 const unwrapped_func = func_index.unwrap(ip);11111 const unwrapped_coerced_func = coerced_func_index.unwrap(ip);
10751 const func_item = unwrapped_func.getItem(ip);11112 const coerced_func_item = unwrapped_coerced_func.getItem(ip);
10752 return @ptrCast(&unwrapped_func.getExtra(ip).view().items(.@"0")[11113 return @ptrCast(&unwrapped_coerced_func.getExtra(ip).view().items(.@"0")[
10753 switch (func_item.tag) {11114 switch (coerced_func_item.tag) {
10754 .func_decl => func_item.data + std.meta.fieldIndex(Tag.FuncDecl, "analysis").?,11115 .func_decl => coerced_func_item.data + std.meta.fieldIndex(Tag.FuncDecl, "analysis").?,
10755 .func_instance => func_item.data + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?,11116 .func_instance => coerced_func_item.data + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?,
10756 else => unreachable,11117 else => unreachable,
10757 }11118 }
10758 ]);11119 ]);
...@@ -10762,14 +11123,65 @@ pub fn funcAnalysis(ip: *const InternPool, index: Index) *FuncAnalysis {...@@ -10762,14 +11123,65 @@ pub fn funcAnalysis(ip: *const InternPool, index: Index) *FuncAnalysis {
10762 return @ptrCast(&extra.view().items(.@"0")[extra_index]);11123 return @ptrCast(&extra.view().items(.@"0")[extra_index]);
10763}11124}
1076411125
10765pub fn funcHasInferredErrorSet(ip: *const InternPool, i: Index) bool {11126pub fn funcAnalysisUnordered(ip: *const InternPool, func: Index) FuncAnalysis {
10766 return funcAnalysis(ip, i).inferred_error_set;11127 return @atomicLoad(FuncAnalysis, @constCast(ip).funcAnalysisPtr(func), .unordered);
10767}11128}
1076811129
10769pub fn funcZirBodyInst(ip: *const InternPool, index: Index) TrackedInst.Index {11130pub fn funcSetAnalysisState(ip: *InternPool, func: Index, state: FuncAnalysis.State) void {
10770 const unwrapped_index = index.unwrap(ip);11131 const unwrapped_func = func.unwrap(ip);
10771 const item = unwrapped_index.getItem(ip);11132 const extra_mutex = &ip.getLocal(unwrapped_func.tid).mutate.extra.mutex;
10772 const item_extra = unwrapped_index.getExtra(ip);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);
10773 const zir_body_inst_field_index = std.meta.fieldIndex(Tag.FuncDecl, "zir_body_inst").?;11185 const zir_body_inst_field_index = std.meta.fieldIndex(Tag.FuncDecl, "zir_body_inst").?;
10774 switch (item.tag) {11186 switch (item.tag) {
10775 .func_decl => return @enumFromInt(item_extra.view().items(.@"0")[item.data + zir_body_inst_field_index]),11187 .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 {...@@ -10806,17 +11218,17 @@ pub fn iesFuncIndex(ip: *const InternPool, ies_index: Index) Index {
10806/// Returns a mutable pointer to the resolved error set type of an inferred11218/// Returns a mutable pointer to the resolved error set type of an inferred
10807/// error set function. The returned pointer is invalidated when anything is11219/// error set function. The returned pointer is invalidated when anything is
10808/// added to `ip`.11220/// added to `ip`.
10809pub fn iesResolved(ip: *const InternPool, ies_index: Index) *Index {11221fn iesResolvedPtr(ip: *InternPool, ies_index: Index) *Index {
10810 const ies_item = ies_index.getItem(ip);11222 const ies_item = ies_index.getItem(ip);
10811 assert(ies_item.tag == .type_inferred_error_set);11223 assert(ies_item.tag == .type_inferred_error_set);
10812 return funcIesResolved(ip, ies_item.data);11224 return ip.funcIesResolvedPtr(ies_item.data);
10813}11225}
1081411226
10815/// Returns a mutable pointer to the resolved error set type of an inferred11227/// Returns a mutable pointer to the resolved error set type of an inferred
10816/// error set function. The returned pointer is invalidated when anything is11228/// error set function. The returned pointer is invalidated when anything is
10817/// added to `ip`.11229/// added to `ip`.
10818pub fn funcIesResolved(ip: *const InternPool, func_index: Index) *Index {11230fn funcIesResolvedPtr(ip: *InternPool, func_index: Index) *Index {
10819 assert(funcHasInferredErrorSet(ip, func_index));11231 assert(ip.funcAnalysisUnordered(func_index).inferred_error_set);
10820 const unwrapped_func = func_index.unwrap(ip);11232 const unwrapped_func = func_index.unwrap(ip);
10821 const func_extra = unwrapped_func.getExtra(ip);11233 const func_extra = unwrapped_func.getExtra(ip);
10822 const func_item = unwrapped_func.getItem(ip);11234 const func_item = unwrapped_func.getItem(ip);
...@@ -10842,6 +11254,19 @@ pub fn funcIesResolved(ip: *const InternPool, func_index: Index) *Index {...@@ -10842,6 +11254,19 @@ pub fn funcIesResolved(ip: *const InternPool, func_index: Index) *Index {
10842 return @ptrCast(&func_extra.view().items(.@"0")[extra_index]);11254 return @ptrCast(&func_extra.view().items(.@"0")[extra_index]);
10843}11255}
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
10845pub fn funcDeclInfo(ip: *const InternPool, index: Index) Key.Func {11270pub fn funcDeclInfo(ip: *const InternPool, index: Index) Key.Func {
10846 const unwrapped_index = index.unwrap(ip);11271 const unwrapped_index = index.unwrap(ip);
10847 const item = unwrapped_index.getItem(ip);11272 const item = unwrapped_index.getItem(ip);
...@@ -10950,7 +11375,10 @@ const GlobalErrorSet = struct {...@@ -10950,7 +11375,10 @@ const GlobalErrorSet = struct {
10950 names: Names,11375 names: Names,
10951 map: Shard.Map(GlobalErrorSet.Index),11376 map: Shard.Map(GlobalErrorSet.Index),
10952 } align(std.atomic.cache_line),11377 } 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
10955 const Names = Local.List(struct { NullTerminatedString });11383 const Names = Local.List(struct { NullTerminatedString });
1095611384
...@@ -10959,7 +11387,10 @@ const GlobalErrorSet = struct {...@@ -10959,7 +11387,10 @@ const GlobalErrorSet = struct {
10959 .names = Names.empty,11387 .names = Names.empty,
10960 .map = Shard.Map(GlobalErrorSet.Index).empty,11388 .map = Shard.Map(GlobalErrorSet.Index).empty,
10961 },11389 },
10962 .mutate = Local.MutexListMutate.empty,11390 .mutate = .{
11391 .names = Local.ListMutate.empty,
11392 .map = .{ .mutex = .{} },
11393 },
10963 };11394 };
1096411395
10965 const Index = enum(Zcu.ErrorInt) {11396 const Index = enum(Zcu.ErrorInt) {
...@@ -10969,7 +11400,7 @@ const GlobalErrorSet = struct {...@@ -10969,7 +11400,7 @@ const GlobalErrorSet = struct {
1096911400
10970 /// Not thread-safe, may only be called from the main thread.11401 /// Not thread-safe, may only be called from the main thread.
10971 pub fn getNamesFromMainThread(ges: *const GlobalErrorSet) []const NullTerminatedString {11402 pub fn getNamesFromMainThread(ges: *const GlobalErrorSet) []const NullTerminatedString {
10972 const len = ges.mutate.list.len;11403 const len = ges.mutate.names.len;
10973 return if (len > 0) ges.shared.names.view().items(.@"0")[0..len] else &.{};11404 return if (len > 0) ges.shared.names.view().items(.@"0")[0..len] else &.{};
10974 }11405 }
1097511406
...@@ -10994,8 +11425,8 @@ const GlobalErrorSet = struct {...@@ -10994,8 +11425,8 @@ const GlobalErrorSet = struct {
10994 if (entry.hash != hash) continue;11425 if (entry.hash != hash) continue;
10995 if (names.view().items(.@"0")[@intFromEnum(index) - 1] == name) return index;11426 if (names.view().items(.@"0")[@intFromEnum(index) - 1] == name) return index;
10996 }11427 }
10997 ges.mutate.mutex.lock();11428 ges.mutate.map.mutex.lock();
10998 defer ges.mutate.mutex.unlock();11429 defer ges.mutate.map.mutex.unlock();
10999 if (map.entries != ges.shared.map.entries) {11430 if (map.entries != ges.shared.map.entries) {
11000 map = ges.shared.map;11431 map = ges.shared.map;
11001 map_mask = map.header().mask();11432 map_mask = map.header().mask();
...@@ -11012,12 +11443,12 @@ const GlobalErrorSet = struct {...@@ -11012,12 +11443,12 @@ const GlobalErrorSet = struct {
11012 const mutable_names: Names.Mutable = .{11443 const mutable_names: Names.Mutable = .{
11013 .gpa = gpa,11444 .gpa = gpa,
11014 .arena = arena_state,11445 .arena = arena_state,
11015 .mutate = &ges.mutate.list,11446 .mutate = &ges.mutate.names,
11016 .list = &ges.shared.names,11447 .list = &ges.shared.names,
11017 };11448 };
11018 try mutable_names.ensureUnusedCapacity(1);11449 try mutable_names.ensureUnusedCapacity(1);
11019 const map_header = map.header().*;11450 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) {
11021 mutable_names.appendAssumeCapacity(.{name});11452 mutable_names.appendAssumeCapacity(.{name});
11022 const index: GlobalErrorSet.Index = @enumFromInt(mutable_names.mutate.len);11453 const index: GlobalErrorSet.Index = @enumFromInt(mutable_names.mutate.len);
11023 const entry = &map.entries[map_index];11454 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...@@ -2535,13 +2535,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
2535 }2535 }
25362536
2537 if (sema.owner_func_index != .none) {2537 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);
2539 } else {2539 } else {
2540 sema.owner_decl.analysis = .sema_failure;2540 sema.owner_decl.analysis = .sema_failure;
2541 }2541 }
25422542
2543 if (sema.func_index != .none) {2543 if (sema.func_index != .none) {
2544 ip.funcAnalysis(sema.func_index).state = .sema_failure;2544 ip.funcSetAnalysisState(sema.func_index, .sema_failure);
2545 }2545 }
25462546
2547 return error.AnalysisFail;2547 return error.AnalysisFail;
...@@ -6555,14 +6555,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst...@@ -6555,14 +6555,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
6555 }6555 }
6556 sema.prev_stack_alignment_src = src;6556 sema.prev_stack_alignment_src = src;
65576557
6558 const ip = &mod.intern_pool;6558 mod.intern_pool.funcMaxStackAlignment(sema.func_index, alignment);
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 }
6566}6559}
65676560
6568fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {6561fn 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)...@@ -6575,7 +6568,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
6575 .needed_comptime_reason = "operand to @setCold must be comptime-known",6568 .needed_comptime_reason = "operand to @setCold must be comptime-known",
6576 });6569 });
6577 if (sema.func_index == .none) return; // does nothing outside a function6570 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);
6579}6572}
65806573
6581fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {6574fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
...@@ -7090,7 +7083,7 @@ fn zirCall(...@@ -7090,7 +7083,7 @@ fn zirCall(
7090 const call_inst = try sema.analyzeCall(block, func, func_ty, callee_src, call_src, modifier, ensure_result_used, args_info, call_dbg_node, .call);7083 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
7092 if (sema.owner_func_index == .none or7085 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)
7094 {7087 {
7095 // No errorable fn actually called; we have no error return trace7088 // No errorable fn actually called; we have no error return trace
7096 input_is_error = false;7089 input_is_error = false;
...@@ -7798,7 +7791,7 @@ fn analyzeCall(...@@ -7798,7 +7791,7 @@ fn analyzeCall(
7798 _ = ics.callee();7791 _ = ics.callee();
77997792
7800 if (!inlining.has_comptime_args) {7793 if (!inlining.has_comptime_args) {
7801 if (module_fn.analysis(ip).state == .sema_failure)7794 if (module_fn.analysisUnordered(ip).state == .sema_failure)
7802 return error.AnalysisFail;7795 return error.AnalysisFail;
78037796
7804 var block_it = block;7797 var block_it = block;
...@@ -7821,7 +7814,7 @@ fn analyzeCall(...@@ -7821,7 +7814,7 @@ fn analyzeCall(
7821 try sema.resolveInst(fn_info.ret_ty_ref);7814 try sema.resolveInst(fn_info.ret_ty_ref);
7822 const ret_ty_src: LazySrcLoc = .{ .base_node_inst = module_fn.zir_body_inst, .offset = .{ .node_offset_fn_type_ret_ty = 0 } };7815 const ret_ty_src: LazySrcLoc = .{ .base_node_inst = module_fn.zir_body_inst, .offset = .{ .node_offset_fn_type_ret_ty = 0 } };
7823 sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);7816 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) {
7825 // Create a fresh inferred error set type for inline/comptime calls.7818 // Create a fresh inferred error set type for inline/comptime calls.
7826 const ies = try sema.arena.create(InferredErrorSet);7819 const ies = try sema.arena.create(InferredErrorSet);
7827 ies.* = .{ .func = .none };7820 ies.* = .{ .func = .none };
...@@ -7947,7 +7940,7 @@ fn analyzeCall(...@@ -7947,7 +7940,7 @@ fn analyzeCall(
7947 if (call_dbg_node) |some| try sema.zirDbgStmt(block, some);7940 if (call_dbg_node) |some| try sema.zirDbgStmt(block, some);
79487941
7949 if (sema.owner_func_index != .none and Type.fromInterned(func_ty_info.return_type).isError(mod)) {7942 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);
7951 }7944 }
79527945
7953 if (try sema.resolveValue(func)) |func_val| {7946 if (try sema.resolveValue(func)) |func_val| {
...@@ -8391,7 +8384,7 @@ fn instantiateGenericCall(...@@ -8391,7 +8384,7 @@ fn instantiateGenericCall(
8391 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern();8384 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern();
83928385
8393 const callee = zcu.funcInfo(callee_index);8386 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
8396 // Make a runtime call to the new function, making sure to omit the comptime args.8389 // Make a runtime call to the new function, making sure to omit the comptime args.
8397 const func_ty = Type.fromInterned(callee.ty);8390 const func_ty = Type.fromInterned(callee.ty);
...@@ -8413,7 +8406,7 @@ fn instantiateGenericCall(...@@ -8413,7 +8406,7 @@ fn instantiateGenericCall(
8413 if (sema.owner_func_index != .none and8406 if (sema.owner_func_index != .none and
8414 Type.fromInterned(func_ty_info.return_type).isError(zcu))8407 Type.fromInterned(func_ty_info.return_type).isError(zcu))
8415 {8408 {
8416 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;8409 ip.funcSetCallsOrAwaitsErrorableFn(sema.owner_func_index);
8417 }8410 }
84188411
8419 try sema.addReferenceEntry(call_src, AnalUnit.wrap(.{ .func = callee_index }));8412 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...@@ -8774,9 +8767,9 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
8774 const int = try sema.usizeCast(block, operand_src, try value.toUnsignedIntSema(pt));8767 const int = try sema.usizeCast(block, operand_src, try value.toUnsignedIntSema(pt));
8775 if (int > len: {8768 if (int > len: {
8776 const mutate = &ip.global_error_set.mutate;8769 const mutate = &ip.global_error_set.mutate;
8777 mutate.mutex.lock();8770 mutate.map.mutex.lock();
8778 defer mutate.mutex.unlock();8771 defer mutate.map.mutex.unlock();
8779 break :len mutate.list.len;8772 break :len mutate.names.len;
8780 } or int == 0)8773 } or int == 0)
8781 return sema.fail(block, operand_src, "integer value '{d}' represents no error", .{int});8774 return sema.fail(block, operand_src, "integer value '{d}' represents no error", .{int});
8782 return Air.internedToRef((try pt.intern(.{ .err = .{8775 return Air.internedToRef((try pt.intern(.{ .err = .{
...@@ -18400,7 +18393,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18400,7 +18393,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18400 try ty.resolveLayout(pt); // Getting alignment requires type layout18393 try ty.resolveLayout(pt); // Getting alignment requires type layout
18401 const union_obj = mod.typeToUnion(ty).?;18394 const union_obj = mod.typeToUnion(ty).?;
18402 const tag_type = union_obj.loadTagType(ip);18395 const tag_type = union_obj.loadTagType(ip);
18403 const layout = union_obj.getLayout(ip);18396 const layout = union_obj.flagsUnordered(ip).layout;
1840418397
18405 const union_field_vals = try gpa.alloc(InternPool.Index, tag_type.names.len);18398 const union_field_vals = try gpa.alloc(InternPool.Index, tag_type.names.len);
18406 defer gpa.free(union_field_vals);18399 defer gpa.free(union_field_vals);
...@@ -18718,8 +18711,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai...@@ -18718,8 +18711,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
18718 const backing_integer_val = try pt.intern(.{ .opt = .{18711 const backing_integer_val = try pt.intern(.{ .opt = .{
18719 .ty = (try pt.optionalType(.type_type)).toIntern(),18712 .ty = (try pt.optionalType(.type_type)).toIntern(),
18720 .val = if (mod.typeToPackedStruct(ty)) |packed_struct| val: {18713 .val = if (mod.typeToPackedStruct(ty)) |packed_struct| val: {
18721 assert(Type.fromInterned(packed_struct.backingIntType(ip).*).isInt(mod));18714 assert(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)).isInt(mod));
18722 break :val packed_struct.backingIntType(ip).*;18715 break :val packed_struct.backingIntTypeUnordered(ip);
18723 } else .none,18716 } else .none,
18724 } });18717 } });
1872518718
...@@ -19800,7 +19793,7 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_...@@ -19800,7 +19793,7 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
19800 return;19793 return;
19801 }19794 }
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;
19804 if (!start_block.ownerModule().error_tracing) return;19797 if (!start_block.ownerModule().error_tracing) return;
1980519798
19806 assert(saved_index != .none); // The .error_return_trace_index field was dropped somewhere19799 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 {...@@ -21058,7 +21051,7 @@ fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
21058 const opt_ptr_stack_trace_ty = try pt.optionalType(ptr_stack_trace_ty.toIntern());21051 const opt_ptr_stack_trace_ty = try pt.optionalType(ptr_stack_trace_ty.toIntern());
2105921052
21060 if (sema.owner_func_index != .none and21053 if (sema.owner_func_index != .none and
21061 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn and21054 ip.funcAnalysisUnordered(sema.owner_func_index).calls_or_awaits_errorable_fn and
21062 block.ownerModule().error_tracing)21055 block.ownerModule().error_tracing)
21063 {21056 {
21064 return block.addTy(.err_return_trace, opt_ptr_stack_trace_ty);21057 return block.addTy(.err_return_trace, opt_ptr_stack_trace_ty);
...@@ -22206,8 +22199,8 @@ fn reifyUnion(...@@ -22206,8 +22199,8 @@ fn reifyUnion(
22206 if (any_aligns) {22199 if (any_aligns) {
22207 loaded_union.setFieldAligns(ip, field_aligns);22200 loaded_union.setFieldAligns(ip, field_aligns);
22208 }22201 }
22209 loaded_union.tagTypePtr(ip).* = enum_tag_ty;22202 loaded_union.setTagType(ip, enum_tag_ty);
22210 loaded_union.flagsPtr(ip).status = .have_field_types;22203 loaded_union.setStatus(ip, .have_field_types);
2221122204
22212 try pt.finalizeAnonDecl(new_decl_index);22205 try pt.finalizeAnonDecl(new_decl_index);
22213 try mod.comp.work_queue.writeItem(.{ .resolve_type_fully = wip_ty.index });22206 try mod.comp.work_queue.writeItem(.{ .resolve_type_fully = wip_ty.index });
...@@ -22469,10 +22462,10 @@ fn reifyStruct(...@@ -22469,10 +22462,10 @@ fn reifyStruct(
22469 if (opt_backing_int_val.optionalValue(mod)) |backing_int_val| {22462 if (opt_backing_int_val.optionalValue(mod)) |backing_int_val| {
22470 const backing_int_ty = backing_int_val.toType();22463 const backing_int_ty = backing_int_val.toType();
22471 try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum);22464 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());
22473 } else {22466 } else {
22474 const backing_int_ty = try pt.intType(.unsigned, @intCast(fields_bit_sum));22467 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());
22476 }22469 }
22477 }22470 }
2247822471
...@@ -28352,7 +28345,7 @@ fn unionFieldPtr(...@@ -28352,7 +28345,7 @@ fn unionFieldPtr(
28352 .is_const = union_ptr_info.flags.is_const,28345 .is_const = union_ptr_info.flags.is_const,
28353 .is_volatile = union_ptr_info.flags.is_volatile,28346 .is_volatile = union_ptr_info.flags.is_volatile,
28354 .address_space = union_ptr_info.flags.address_space,28347 .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: {
28356 const union_align = if (union_ptr_info.flags.alignment != .none)28349 const union_align = if (union_ptr_info.flags.alignment != .none)
28357 union_ptr_info.flags.alignment28350 union_ptr_info.flags.alignment
28358 else28351 else
...@@ -28380,7 +28373,7 @@ fn unionFieldPtr(...@@ -28380,7 +28373,7 @@ fn unionFieldPtr(
28380 }28373 }
2838128374
28382 if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| ct: {28375 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) {
28384 .auto => if (initializing) {28377 .auto => if (initializing) {
28385 // Store to the union to initialize the tag.28378 // Store to the union to initialize the tag.
28386 const field_tag = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);28379 const field_tag = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
...@@ -28418,7 +28411,7 @@ fn unionFieldPtr(...@@ -28418,7 +28411,7 @@ fn unionFieldPtr(
28418 }28411 }
2841928412
28420 try sema.requireRuntimeBlock(block, src, null);28413 try sema.requireRuntimeBlock(block, src, null);
28421 if (!initializing and union_obj.getLayout(ip) == .auto and block.wantSafety() and28414 if (!initializing and union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and
28422 union_ty.unionTagTypeSafety(mod) != null and union_obj.field_types.len > 1)28415 union_ty.unionTagTypeSafety(mod) != null and union_obj.field_types.len > 1)
28423 {28416 {
28424 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);28417 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
...@@ -28461,7 +28454,7 @@ fn unionFieldVal(...@@ -28461,7 +28454,7 @@ fn unionFieldVal(
28461 const un = ip.indexToKey(union_val.toIntern()).un;28454 const un = ip.indexToKey(union_val.toIntern()).un;
28462 const field_tag = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);28455 const field_tag = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
28463 const tag_matches = un.tag == field_tag.toIntern();28456 const tag_matches = un.tag == field_tag.toIntern();
28464 switch (union_obj.getLayout(ip)) {28457 switch (union_obj.flagsUnordered(ip).layout) {
28465 .auto => {28458 .auto => {
28466 if (tag_matches) {28459 if (tag_matches) {
28467 return Air.internedToRef(un.val);28460 return Air.internedToRef(un.val);
...@@ -28495,7 +28488,7 @@ fn unionFieldVal(...@@ -28495,7 +28488,7 @@ fn unionFieldVal(
28495 }28488 }
2849628489
28497 try sema.requireRuntimeBlock(block, src, null);28490 try sema.requireRuntimeBlock(block, src, null);
28498 if (union_obj.getLayout(ip) == .auto and block.wantSafety() and28491 if (union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and
28499 union_ty.unionTagTypeSafety(zcu) != null and union_obj.field_types.len > 1)28492 union_ty.unionTagTypeSafety(zcu) != null and union_obj.field_types.len > 1)
28500 {28493 {
28501 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);28494 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...@@ -32042,7 +32035,7 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile
3204232035
32043 pt.ensureDeclAnalyzed(decl_index) catch |err| {32036 pt.ensureDeclAnalyzed(decl_index) catch |err| {
32044 if (sema.owner_func_index != .none) {32037 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);
32046 } else {32039 } else {
32047 sema.owner_decl.analysis = .dependency_failure;32040 sema.owner_decl.analysis = .dependency_failure;
32048 }32041 }
...@@ -32056,7 +32049,7 @@ fn ensureFuncBodyAnalyzed(sema: *Sema, func: InternPool.Index) CompileError!void...@@ -32056,7 +32049,7 @@ fn ensureFuncBodyAnalyzed(sema: *Sema, func: InternPool.Index) CompileError!void
32056 const ip = &mod.intern_pool;32049 const ip = &mod.intern_pool;
32057 pt.ensureFuncBodyAnalyzed(func) catch |err| {32050 pt.ensureFuncBodyAnalyzed(func) catch |err| {
32058 if (sema.owner_func_index != .none) {32051 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);
32060 } else {32053 } else {
32061 sema.owner_decl.analysis = .dependency_failure;32054 sema.owner_decl.analysis = .dependency_failure;
32062 }32055 }
...@@ -32402,7 +32395,7 @@ fn analyzeIsNonErrComptimeOnly(...@@ -32402,7 +32395,7 @@ fn analyzeIsNonErrComptimeOnly(
32402 // If the error set is empty, we must return a comptime true or false.32395 // If the error set is empty, we must return a comptime true or false.
32403 // However we want to avoid unnecessarily resolving an inferred error set32396 // However we want to avoid unnecessarily resolving an inferred error set
32404 // in case it is already non-empty.32397 // in case it is already non-empty.
32405 switch (ip.funcIesResolved(func_index).*) {32398 switch (ip.funcIesResolvedUnordered(func_index)) {
32406 .anyerror_type => break :blk,32399 .anyerror_type => break :blk,
32407 .none => {},32400 .none => {},
32408 else => |i| if (ip.indexToKey(i).error_set_type.names.len != 0) break :blk,32401 else => |i| if (ip.indexToKey(i).error_set_type.names.len != 0) break :blk,
...@@ -33471,7 +33464,7 @@ fn wrapErrorUnionSet(...@@ -33471,7 +33464,7 @@ fn wrapErrorUnionSet(
33471 .inferred_error_set_type => |func_index| ok: {33464 .inferred_error_set_type => |func_index| ok: {
33472 // We carefully do this in an order that avoids unnecessarily33465 // We carefully do this in an order that avoids unnecessarily
33473 // resolving the destination error set type.33466 // resolving the destination error set type.
33474 switch (ip.funcIesResolved(func_index).*) {33467 switch (ip.funcIesResolvedUnordered(func_index)) {
33475 .anyerror_type => break :ok,33468 .anyerror_type => break :ok,
33476 .none => if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {33469 .none => if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {
33477 break :ok;33470 break :ok;
...@@ -35076,33 +35069,25 @@ pub fn resolveStructAlignment(...@@ -35076,33 +35069,25 @@ pub fn resolveStructAlignment(
3507635069
35077 assert(sema.ownerUnit().unwrap().decl == struct_type.decl.unwrap().?);35070 assert(sema.ownerUnit().unwrap().decl == struct_type.decl.unwrap().?);
3507835071
35079 assert(struct_type.flagsPtr(ip).alignment == .none);
35080 assert(struct_type.layout != .@"packed");35072 assert(struct_type.layout != .@"packed");
35073 assert(struct_type.flagsUnordered(ip).alignment == .none);
3508135074
35082 if (struct_type.flagsPtr(ip).field_types_wip) {35075 const ptr_align = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
35083 // We'll guess "pointer-aligned", if the struct has an35076
35084 // underaligned pointer field then some allocations35077 // We'll guess "pointer-aligned", if the struct has an
35085 // might require explicit alignment.35078 // underaligned pointer field then some allocations
35086 struct_type.flagsPtr(ip).assumed_pointer_aligned = true;35079 // might require explicit alignment.
35087 const result = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));35080 if (struct_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;
35088 struct_type.flagsPtr(ip).alignment = result;
35089 return;
35090 }
3509135081
35092 try sema.resolveTypeFieldsStruct(ty, struct_type);35082 try sema.resolveTypeFieldsStruct(ty, struct_type);
3509335083
35094 if (struct_type.setAlignmentWip(ip)) {35084 // We'll guess "pointer-aligned", if the struct has an
35095 // We'll guess "pointer-aligned", if the struct has an35085 // underaligned pointer field then some allocations
35096 // underaligned pointer field then some allocations35086 // might require explicit alignment.
35097 // might require explicit alignment.35087 if (struct_type.assumePointerAlignedIfWip(ip, ptr_align)) return;
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 }
35103 defer struct_type.clearAlignmentWip(ip);35088 defer struct_type.clearAlignmentWip(ip);
3510435089
35105 var result: Alignment = .@"1";35090 var alignment: Alignment = .@"1";
3510635091
35107 for (0..struct_type.field_types.len) |i| {35092 for (0..struct_type.field_types.len) |i| {
35108 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);35093 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
...@@ -35114,10 +35099,10 @@ pub fn resolveStructAlignment(...@@ -35114,10 +35099,10 @@ pub fn resolveStructAlignment(
35114 struct_type.layout,35099 struct_type.layout,
35115 .sema,35100 .sema,
35116 );35101 );
35117 result = result.maxStrict(field_align);35102 alignment = alignment.maxStrict(field_align);
35118 }35103 }
3511935104
35120 struct_type.flagsPtr(ip).alignment = result;35105 struct_type.setAlignment(ip, alignment);
35121}35106}
3512235107
35123pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {35108pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
...@@ -35182,7 +35167,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35182,7 +35167,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
35182 big_align = big_align.maxStrict(field_align.*);35167 big_align = big_align.maxStrict(field_align.*);
35183 }35168 }
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))) {
35186 const msg = try sema.errMsg(35171 const msg = try sema.errMsg(
35187 ty.srcLoc(zcu),35172 ty.srcLoc(zcu),
35188 "struct layout depends on it having runtime bits",35173 "struct layout depends on it having runtime bits",
...@@ -35191,7 +35176,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35191,7 +35176,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
35191 return sema.failWithOwnedErrorMsg(null, msg);35176 return sema.failWithOwnedErrorMsg(null, msg);
35192 }35177 }
3519335178
35194 if (struct_type.flagsPtr(ip).assumed_pointer_aligned and35179 if (struct_type.flagsUnordered(ip).assumed_pointer_aligned and
35195 big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8))))35180 big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8))))
35196 {35181 {
35197 const msg = try sema.errMsg(35182 const msg = try sema.errMsg(
...@@ -35259,10 +35244,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35259,10 +35244,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
35259 offsets[i] = @intCast(aligns[i].forward(offset));35244 offsets[i] = @intCast(aligns[i].forward(offset));
35260 offset = offsets[i] + sizes[i];35245 offset = offsets[i] + sizes[i];
35261 }35246 }
35262 struct_type.size(ip).* = @intCast(big_align.forward(offset));35247 struct_type.setLayoutResolved(ip, @intCast(big_align.forward(offset)), big_align);
35263 const flags = struct_type.flagsPtr(ip);
35264 flags.alignment = big_align;
35265 flags.layout_resolved = true;
35266 _ = try sema.typeRequiresComptime(ty);35248 _ = try sema.typeRequiresComptime(ty);
35267}35249}
3526835250
...@@ -35355,13 +35337,13 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp...@@ -35355,13 +35337,13 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp
35355 };35337 };
3535635338
35357 try sema.checkBackingIntType(&block, backing_int_src, backing_int_ty, fields_bit_sum);35339 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());
35359 } else {35341 } else {
35360 if (fields_bit_sum > std.math.maxInt(u16)) {35342 if (fields_bit_sum > std.math.maxInt(u16)) {
35361 return sema.fail(&block, block.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});35343 return sema.fail(&block, block.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
35362 }35344 }
35363 const backing_int_ty = try pt.intType(.unsigned, @intCast(fields_bit_sum));35345 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());
35365 }35347 }
3536635348
35367 try sema.flushExports();35349 try sema.flushExports();
...@@ -35435,15 +35417,12 @@ pub fn resolveUnionAlignment(...@@ -35435,15 +35417,12 @@ pub fn resolveUnionAlignment(
3543535417
35436 assert(!union_type.haveLayout(ip));35418 assert(!union_type.haveLayout(ip));
3543735419
35438 if (union_type.flagsPtr(ip).status == .field_types_wip) {35420 const ptr_align = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
35439 // We'll guess "pointer-aligned", if the union has an35421
35440 // underaligned pointer field then some allocations35422 // We'll guess "pointer-aligned", if the union has an
35441 // might require explicit alignment.35423 // underaligned pointer field then some allocations
35442 union_type.flagsPtr(ip).assumed_pointer_aligned = true;35424 // might require explicit alignment.
35443 const result = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));35425 if (union_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;
35444 union_type.flagsPtr(ip).alignment = result;
35445 return;
35446 }
3544735426
35448 try sema.resolveTypeFieldsUnion(ty, union_type);35427 try sema.resolveTypeFieldsUnion(ty, union_type);
3544935428
...@@ -35461,7 +35440,7 @@ pub fn resolveUnionAlignment(...@@ -35461,7 +35440,7 @@ pub fn resolveUnionAlignment(
35461 max_align = max_align.max(field_align);35440 max_align = max_align.max(field_align);
35462 }35441 }
3546335442
35464 union_type.flagsPtr(ip).alignment = max_align;35443 union_type.setAlignment(ip, max_align);
35465}35444}
3546635445
35467/// This logic must be kept in sync with `Module.getUnionLayout`.35446/// This logic must be kept in sync with `Module.getUnionLayout`.
...@@ -35476,7 +35455,8 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35476,7 +35455,8 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3547635455
35477 assert(sema.ownerUnit().unwrap().decl == union_type.decl);35456 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) {
35480 .none, .have_field_types => {},35460 .none, .have_field_types => {},
35481 .field_types_wip, .layout_wip => {35461 .field_types_wip, .layout_wip => {
35482 const msg = try sema.errMsg(35462 const msg = try sema.errMsg(
...@@ -35489,12 +35469,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35489,12 +35469,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
35489 .have_layout, .fully_resolved_wip, .fully_resolved => return,35469 .have_layout, .fully_resolved_wip, .fully_resolved => return,
35490 }35470 }
3549135471
35492 const prev_status = union_type.flagsPtr(ip).status;35472 errdefer union_type.setStatusIfLayoutWip(ip, old_flags.status);
35493 errdefer if (union_type.flagsPtr(ip).status == .layout_wip) {
35494 union_type.flagsPtr(ip).status = prev_status;
35495 };
3549635473
35497 union_type.flagsPtr(ip).status = .layout_wip;35474 union_type.setStatus(ip, .layout_wip);
3549835475
35499 var max_size: u64 = 0;35476 var max_size: u64 = 0;
35500 var max_align: Alignment = .@"1";35477 var max_align: Alignment = .@"1";
...@@ -35521,8 +35498,8 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35521,8 +35498,8 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
35521 max_align = max_align.max(field_align);35498 max_align = max_align.max(field_align);
35522 }35499 }
3552335500
35524 const flags = union_type.flagsPtr(ip);35501 const has_runtime_tag = union_type.flagsUnordered(ip).runtime_tag.hasTag() and
35525 const has_runtime_tag = flags.runtime_tag.hasTag() and try sema.typeHasRuntimeBits(Type.fromInterned(union_type.enum_tag_ty));35502 try sema.typeHasRuntimeBits(Type.fromInterned(union_type.enum_tag_ty));
35526 const size, const alignment, const padding = if (has_runtime_tag) layout: {35503 const size, const alignment, const padding = if (has_runtime_tag) layout: {
35527 const enum_tag_type = Type.fromInterned(union_type.enum_tag_ty);35504 const enum_tag_type = Type.fromInterned(union_type.enum_tag_ty);
35528 const tag_align = try sema.typeAbiAlignment(enum_tag_type);35505 const tag_align = try sema.typeAbiAlignment(enum_tag_type);
...@@ -35556,12 +35533,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35556,12 +35533,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
35556 break :layout .{ size, max_align.max(tag_align), padding };35533 break :layout .{ size, max_align.max(tag_align), padding };
35557 } else .{ max_align.forward(max_size), max_align, 0 };35534 } else .{ max_align.forward(max_size), max_align, 0 };
3555835535
35559 union_type.size(ip).* = @intCast(size);35536 union_type.setHaveLayout(ip, @intCast(size), padding, alignment);
35560 union_type.padding(ip).* = padding;
35561 flags.alignment = alignment;
35562 flags.status = .have_layout;
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))) {
35565 const msg = try sema.errMsg(35539 const msg = try sema.errMsg(
35566 ty.srcLoc(pt.zcu),35540 ty.srcLoc(pt.zcu),
35567 "union layout depends on it having runtime bits",35541 "union layout depends on it having runtime bits",
...@@ -35570,7 +35544,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {...@@ -35570,7 +35544,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
35570 return sema.failWithOwnedErrorMsg(null, msg);35544 return sema.failWithOwnedErrorMsg(null, msg);
35571 }35545 }
3557235546
35573 if (union_type.flagsPtr(ip).assumed_pointer_aligned and35547 if (union_type.flagsUnordered(ip).assumed_pointer_aligned and
35574 alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(pt.zcu.getTarget().ptrBitWidth(), 8))))35548 alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(pt.zcu.getTarget().ptrBitWidth(), 8))))
35575 {35549 {
35576 const msg = try sema.errMsg(35550 const msg = try sema.errMsg(
...@@ -35617,7 +35591,7 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {...@@ -35617,7 +35591,7 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
3561735591
35618 assert(sema.ownerUnit().unwrap().decl == union_obj.decl);35592 assert(sema.ownerUnit().unwrap().decl == union_obj.decl);
3561935593
35620 switch (union_obj.flagsPtr(ip).status) {35594 switch (union_obj.flagsUnordered(ip).status) {
35621 .none, .have_field_types, .field_types_wip, .layout_wip, .have_layout => {},35595 .none, .have_field_types, .field_types_wip, .layout_wip, .have_layout => {},
35622 .fully_resolved_wip, .fully_resolved => return,35596 .fully_resolved_wip, .fully_resolved => return,
35623 }35597 }
...@@ -35626,15 +35600,15 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {...@@ -35626,15 +35600,15 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
35626 // After we have resolve union layout we have to go over the fields again to35600 // After we have resolve union layout we have to go over the fields again to
35627 // make sure pointer fields get their child types resolved as well.35601 // make sure pointer fields get their child types resolved as well.
35628 // See also similar code for structs.35602 // See also similar code for structs.
35629 const prev_status = union_obj.flagsPtr(ip).status;35603 const prev_status = union_obj.flagsUnordered(ip).status;
35630 errdefer union_obj.flagsPtr(ip).status = prev_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);
35633 for (0..union_obj.field_types.len) |field_index| {35607 for (0..union_obj.field_types.len) |field_index| {
35634 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);35608 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
35635 try field_ty.resolveFully(pt);35609 try field_ty.resolveFully(pt);
35636 }35610 }
35637 union_obj.flagsPtr(ip).status = .fully_resolved;35611 union_obj.setStatus(ip, .fully_resolved);
35638 }35612 }
3563935613
35640 // And let's not forget comptime-only status.35614 // And let's not forget comptime-only status.
...@@ -35667,7 +35641,7 @@ pub fn resolveTypeFieldsStruct(...@@ -35667,7 +35641,7 @@ pub fn resolveTypeFieldsStruct(
3566735641
35668 if (struct_type.haveFieldTypes(ip)) return;35642 if (struct_type.haveFieldTypes(ip)) return;
3566935643
35670 if (struct_type.setTypesWip(ip)) {35644 if (struct_type.setFieldTypesWip(ip)) {
35671 const msg = try sema.errMsg(35645 const msg = try sema.errMsg(
35672 Type.fromInterned(ty).srcLoc(zcu),35646 Type.fromInterned(ty).srcLoc(zcu),
35673 "struct '{}' depends on itself",35647 "struct '{}' depends on itself",
...@@ -35675,7 +35649,7 @@ pub fn resolveTypeFieldsStruct(...@@ -35675,7 +35649,7 @@ pub fn resolveTypeFieldsStruct(
35675 );35649 );
35676 return sema.failWithOwnedErrorMsg(null, msg);35650 return sema.failWithOwnedErrorMsg(null, msg);
35677 }35651 }
35678 defer struct_type.clearTypesWip(ip);35652 defer struct_type.clearFieldTypesWip(ip);
3567935653
35680 semaStructFields(pt, sema.arena, struct_type) catch |err| switch (err) {35654 semaStructFields(pt, sema.arena, struct_type) catch |err| switch (err) {
35681 error.AnalysisFail => {35655 error.AnalysisFail => {
...@@ -35744,7 +35718,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load...@@ -35744,7 +35718,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
35744 },35718 },
35745 else => {},35719 else => {},
35746 }35720 }
35747 switch (union_type.flagsPtr(ip).status) {35721 switch (union_type.flagsUnordered(ip).status) {
35748 .none => {},35722 .none => {},
35749 .field_types_wip => {35723 .field_types_wip => {
35750 const msg = try sema.errMsg(35724 const msg = try sema.errMsg(
...@@ -35762,8 +35736,8 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load...@@ -35762,8 +35736,8 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
35762 => return,35736 => return,
35763 }35737 }
3576435738
35765 union_type.flagsPtr(ip).status = .field_types_wip;35739 union_type.setStatus(ip, .field_types_wip);
35766 errdefer union_type.flagsPtr(ip).status = .none;35740 errdefer union_type.setStatus(ip, .none);
35767 semaUnionFields(pt, sema.arena, union_type) catch |err| switch (err) {35741 semaUnionFields(pt, sema.arena, union_type) catch |err| switch (err) {
35768 error.AnalysisFail => {35742 error.AnalysisFail => {
35769 if (owner_decl.analysis == .complete) {35743 if (owner_decl.analysis == .complete) {
...@@ -35774,7 +35748,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load...@@ -35774,7 +35748,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
35774 error.OutOfMemory => return error.OutOfMemory,35748 error.OutOfMemory => return error.OutOfMemory,
35775 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,35749 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
35776 };35750 };
35777 union_type.flagsPtr(ip).status = .have_field_types;35751 union_type.setStatus(ip, .have_field_types);
35778}35752}
3577935753
35780/// Returns a normal error set corresponding to the fully populated inferred35754/// Returns a normal error set corresponding to the fully populated inferred
...@@ -35795,10 +35769,10 @@ fn resolveInferredErrorSet(...@@ -35795,10 +35769,10 @@ fn resolveInferredErrorSet(
3579535769
35796 // TODO: during an incremental update this might not be `.none`, but the35770 // TODO: during an incremental update this might not be `.none`, but the
35797 // function might be out-of-date!35771 // function might be out-of-date!
35798 const resolved_ty = func.resolvedErrorSet(ip).*;35772 const resolved_ty = func.resolvedErrorSetUnordered(ip);
35799 if (resolved_ty != .none) return resolved_ty;35773 if (resolved_ty != .none) return resolved_ty;
3580035774
35801 if (func.analysis(ip).state == .in_progress)35775 if (func.analysisUnordered(ip).state == .in_progress)
35802 return sema.fail(block, src, "unable to resolve inferred error set", .{});35776 return sema.fail(block, src, "unable to resolve inferred error set", .{});
3580335777
35804 // In order to ensure that all dependencies are properly added to the set,35778 // In order to ensure that all dependencies are properly added to the set,
...@@ -35835,7 +35809,7 @@ fn resolveInferredErrorSet(...@@ -35835,7 +35809,7 @@ fn resolveInferredErrorSet(
3583535809
35836 // This will now have been resolved by the logic at the end of `Module.analyzeFnBody`35810 // This will now have been resolved by the logic at the end of `Module.analyzeFnBody`
35837 // which calls `resolveInferredErrorSetPtr`.35811 // which calls `resolveInferredErrorSetPtr`.
35838 const final_resolved_ty = func.resolvedErrorSet(ip).*;35812 const final_resolved_ty = func.resolvedErrorSetUnordered(ip);
35839 assert(final_resolved_ty != .none);35813 assert(final_resolved_ty != .none);
35840 return final_resolved_ty;35814 return final_resolved_ty;
35841}35815}
...@@ -36001,8 +35975,7 @@ fn semaStructFields(...@@ -36001,8 +35975,7 @@ fn semaStructFields(
36001 return;35975 return;
36002 },35976 },
36003 .auto, .@"extern" => {35977 .auto, .@"extern" => {
36004 struct_type.size(ip).* = 0;35978 struct_type.setLayoutResolved(ip, 0, .none);
36005 struct_type.flagsPtr(ip).layout_resolved = true;
36006 return;35979 return;
36007 },35980 },
36008 };35981 };
...@@ -36196,7 +36169,7 @@ fn semaStructFields(...@@ -36196,7 +36169,7 @@ fn semaStructFields(
36196 extra_index += zir_field.init_body_len;36169 extra_index += zir_field.init_body_len;
36197 }36170 }
3619836171
36199 struct_type.clearTypesWip(ip);36172 struct_type.clearFieldTypesWip(ip);
36200 if (!any_inits) struct_type.setHaveFieldInits(ip);36173 if (!any_inits) struct_type.setHaveFieldInits(ip);
3620136174
36202 try sema.flushExports();36175 try sema.flushExports();
...@@ -36472,7 +36445,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L...@@ -36472,7 +36445,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
36472 }36445 }
36473 } else {36446 } else {
36474 // The provided type is the enum tag type.36447 // The provided type is the enum tag type.
36475 union_type.tagTypePtr(ip).* = provided_ty.toIntern();36448 union_type.setTagType(ip, provided_ty.toIntern());
36476 const enum_type = switch (ip.indexToKey(provided_ty.toIntern())) {36449 const enum_type = switch (ip.indexToKey(provided_ty.toIntern())) {
36477 .enum_type => ip.loadEnumType(provided_ty.toIntern()),36450 .enum_type => ip.loadEnumType(provided_ty.toIntern()),
36478 else => return sema.fail(&block_scope, tag_ty_src, "expected enum tag type, found '{}'", .{provided_ty.fmt(pt)}),36451 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...@@ -36610,10 +36583,11 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
36610 }36583 }
3661136584
36612 if (explicit_tags_seen.len > 0) {36585 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);
36614 const enum_index = tag_info.nameIndex(ip, field_name) orelse {36588 const enum_index = tag_info.nameIndex(ip, field_name) orelse {
36615 return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{36589 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),
36617 });36591 });
36618 };36592 };
3661936593
...@@ -36650,7 +36624,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L...@@ -36650,7 +36624,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
36650 };36624 };
36651 return sema.failWithOwnedErrorMsg(&block_scope, msg);36625 return sema.failWithOwnedErrorMsg(&block_scope, msg);
36652 }36626 }
36653 const layout = union_type.getLayout(ip);36627 const layout = union_type.flagsUnordered(ip).layout;
36654 if (layout == .@"extern" and36628 if (layout == .@"extern" and
36655 !try sema.validateExternType(field_ty, .union_field))36629 !try sema.validateExternType(field_ty, .union_field))
36656 {36630 {
...@@ -36693,7 +36667,8 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L...@@ -36693,7 +36667,8 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
36693 union_type.setFieldAligns(ip, field_aligns.items);36667 union_type.setFieldAligns(ip, field_aligns.items);
3669436668
36695 if (explicit_tags_seen.len > 0) {36669 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);
36697 if (tag_info.names.len > fields_len) {36672 if (tag_info.names.len > fields_len) {
36698 const msg = msg: {36673 const msg = msg: {
36699 const msg = try sema.errMsg(src, "enum field(s) missing in union", .{});36674 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...@@ -36701,21 +36676,21 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
3670136676
36702 for (tag_info.names.get(ip), 0..) |field_name, field_index| {36677 for (tag_info.names.get(ip), 0..) |field_name, field_index| {
36703 if (explicit_tags_seen[field_index]) continue;36678 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", .{
36705 field_name.fmt(ip),36680 field_name.fmt(ip),
36706 });36681 });
36707 }36682 }
36708 try sema.addDeclaredHereNote(msg, Type.fromInterned(union_type.tagTypePtr(ip).*));36683 try sema.addDeclaredHereNote(msg, Type.fromInterned(tag_ty));
36709 break :msg msg;36684 break :msg msg;
36710 };36685 };
36711 return sema.failWithOwnedErrorMsg(&block_scope, msg);36686 return sema.failWithOwnedErrorMsg(&block_scope, msg);
36712 }36687 }
36713 } else if (enum_field_vals.count() > 0) {36688 } else if (enum_field_vals.count() > 0) {
36714 const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), zcu.declPtr(union_type.decl));36689 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);
36716 } else {36691 } else {
36717 const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, zcu.declPtr(union_type.decl));36692 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);
36719 }36694 }
3672036695
36721 try sema.flushExports();36696 try sema.flushExports();
...@@ -37091,7 +37066,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {...@@ -37091,7 +37066,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
37091 try ty.resolveLayout(pt);37066 try ty.resolveLayout(pt);
3709237067
37093 const union_obj = ip.loadUnionType(ty.toIntern());37068 const union_obj = ip.loadUnionType(ty.toIntern());
37094 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse37069 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypeUnordered(ip)))) orelse
37095 return null;37070 return null;
37096 if (union_obj.field_types.len == 0) {37071 if (union_obj.field_types.len == 0) {
37097 const only = try pt.intern(.{ .empty_enum_value = ty.toIntern() });37072 const only = try pt.intern(.{ .empty_enum_value = ty.toIntern() });
src/Type.zig+48-47
...@@ -605,17 +605,15 @@ pub fn hasRuntimeBitsAdvanced(...@@ -605,17 +605,15 @@ pub fn hasRuntimeBitsAdvanced(
605605
606 .union_type => {606 .union_type => {
607 const union_type = ip.loadUnionType(ty.toIntern());607 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) {
609 .none => {610 .none => {
610 if (union_type.flagsPtr(ip).status == .field_types_wip) {611 // In this case, we guess that hasRuntimeBits() for this type is true,
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.
612 // and then later if our guess was incorrect, we emit a compile error.613 if (union_type.assumeRuntimeBitsIfFieldTypesWip(ip)) return true;
613 union_type.flagsPtr(ip).assumed_runtime_bits = true;
614 return true;
615 }
616 },614 },
617 .safety, .tagged => {615 .safety, .tagged => {
618 const tag_ty = union_type.tagTypePtr(ip).*;616 const tag_ty = union_type.tagTypeUnordered(ip);
619 // tag_ty will be `none` if this union's tag type is not resolved yet,617 // tag_ty will be `none` if this union's tag type is not resolved yet,
620 // in which case we want control flow to continue down below.618 // in which case we want control flow to continue down below.
621 if (tag_ty != .none and619 if (tag_ty != .none and
...@@ -627,8 +625,8 @@ pub fn hasRuntimeBitsAdvanced(...@@ -627,8 +625,8 @@ pub fn hasRuntimeBitsAdvanced(
627 }625 }
628 switch (strat) {626 switch (strat) {
629 .sema => try ty.resolveFields(pt),627 .sema => try ty.resolveFields(pt),
630 .eager => assert(union_type.flagsPtr(ip).status.haveFieldTypes()),628 .eager => assert(union_flags.status.haveFieldTypes()),
631 .lazy => if (!union_type.flagsPtr(ip).status.haveFieldTypes())629 .lazy => if (!union_flags.status.haveFieldTypes())
632 return error.NeedLazy,630 return error.NeedLazy,
633 }631 }
634 for (0..union_type.field_types.len) |field_index| {632 for (0..union_type.field_types.len) |field_index| {
...@@ -745,8 +743,8 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {...@@ -745,8 +743,8 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
745 },743 },
746 .union_type => {744 .union_type => {
747 const union_type = ip.loadUnionType(ty.toIntern());745 const union_type = ip.loadUnionType(ty.toIntern());
748 return switch (union_type.flagsPtr(ip).runtime_tag) {746 return switch (union_type.flagsUnordered(ip).runtime_tag) {
749 .none, .safety => union_type.flagsPtr(ip).layout != .auto,747 .none, .safety => union_type.flagsUnordered(ip).layout != .auto,
750 .tagged => false,748 .tagged => false,
751 };749 };
752 },750 },
...@@ -1045,7 +1043,7 @@ pub fn abiAlignmentAdvanced(...@@ -1045,7 +1043,7 @@ pub fn abiAlignmentAdvanced(
1045 if (struct_type.layout == .@"packed") {1043 if (struct_type.layout == .@"packed") {
1046 switch (strat) {1044 switch (strat) {
1047 .sema => try ty.resolveLayout(pt),1045 .sema => try ty.resolveLayout(pt),
1048 .lazy => if (struct_type.backingIntType(ip).* == .none) return .{1046 .lazy => if (struct_type.backingIntTypeUnordered(ip) == .none) return .{
1049 .val = Value.fromInterned(try pt.intern(.{ .int = .{1047 .val = Value.fromInterned(try pt.intern(.{ .int = .{
1050 .ty = .comptime_int_type,1048 .ty = .comptime_int_type,
1051 .storage = .{ .lazy_align = ty.toIntern() },1049 .storage = .{ .lazy_align = ty.toIntern() },
...@@ -1053,10 +1051,10 @@ pub fn abiAlignmentAdvanced(...@@ -1053,10 +1051,10 @@ pub fn abiAlignmentAdvanced(
1053 },1051 },
1054 .eager => {},1052 .eager => {},
1055 }1053 }
1056 return .{ .scalar = Type.fromInterned(struct_type.backingIntType(ip).*).abiAlignment(pt) };1054 return .{ .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiAlignment(pt) };
1057 }1055 }
10581056
1059 if (struct_type.flagsPtr(ip).alignment == .none) switch (strat) {1057 if (struct_type.flagsUnordered(ip).alignment == .none) switch (strat) {
1060 .eager => unreachable, // struct alignment not resolved1058 .eager => unreachable, // struct alignment not resolved
1061 .sema => try ty.resolveStructAlignment(pt),1059 .sema => try ty.resolveStructAlignment(pt),
1062 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{1060 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
...@@ -1065,7 +1063,7 @@ pub fn abiAlignmentAdvanced(...@@ -1065,7 +1063,7 @@ pub fn abiAlignmentAdvanced(
1065 } })) },1063 } })) },
1066 };1064 };
10671065
1068 return .{ .scalar = struct_type.flagsPtr(ip).alignment };1066 return .{ .scalar = struct_type.flagsUnordered(ip).alignment };
1069 },1067 },
1070 .anon_struct_type => |tuple| {1068 .anon_struct_type => |tuple| {
1071 var big_align: Alignment = .@"1";1069 var big_align: Alignment = .@"1";
...@@ -1088,7 +1086,7 @@ pub fn abiAlignmentAdvanced(...@@ -1088,7 +1086,7 @@ pub fn abiAlignmentAdvanced(
1088 .union_type => {1086 .union_type => {
1089 const union_type = ip.loadUnionType(ty.toIntern());1087 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) {
1092 .eager => unreachable, // union layout not resolved1090 .eager => unreachable, // union layout not resolved
1093 .sema => try ty.resolveUnionAlignment(pt),1091 .sema => try ty.resolveUnionAlignment(pt),
1094 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{1092 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
...@@ -1097,7 +1095,7 @@ pub fn abiAlignmentAdvanced(...@@ -1097,7 +1095,7 @@ pub fn abiAlignmentAdvanced(
1097 } })) },1095 } })) },
1098 };1096 };
10991097
1100 return .{ .scalar = union_type.flagsPtr(ip).alignment };1098 return .{ .scalar = union_type.flagsUnordered(ip).alignment };
1101 },1099 },
1102 .opaque_type => return .{ .scalar = .@"1" },1100 .opaque_type => return .{ .scalar = .@"1" },
1103 .enum_type => return .{1101 .enum_type => return .{
...@@ -1420,7 +1418,7 @@ pub fn abiSizeAdvanced(...@@ -1420,7 +1418,7 @@ pub fn abiSizeAdvanced(
1420 .sema => try ty.resolveLayout(pt),1418 .sema => try ty.resolveLayout(pt),
1421 .lazy => switch (struct_type.layout) {1419 .lazy => switch (struct_type.layout) {
1422 .@"packed" => {1420 .@"packed" => {
1423 if (struct_type.backingIntType(ip).* == .none) return .{1421 if (struct_type.backingIntTypeUnordered(ip) == .none) return .{
1424 .val = Value.fromInterned(try pt.intern(.{ .int = .{1422 .val = Value.fromInterned(try pt.intern(.{ .int = .{
1425 .ty = .comptime_int_type,1423 .ty = .comptime_int_type,
1426 .storage = .{ .lazy_size = ty.toIntern() },1424 .storage = .{ .lazy_size = ty.toIntern() },
...@@ -1440,11 +1438,11 @@ pub fn abiSizeAdvanced(...@@ -1440,11 +1438,11 @@ pub fn abiSizeAdvanced(
1440 }1438 }
1441 switch (struct_type.layout) {1439 switch (struct_type.layout) {
1442 .@"packed" => return .{1440 .@"packed" => return .{
1443 .scalar = Type.fromInterned(struct_type.backingIntType(ip).*).abiSize(pt),1441 .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiSize(pt),
1444 },1442 },
1445 .auto, .@"extern" => {1443 .auto, .@"extern" => {
1446 assert(struct_type.haveLayout(ip));1444 assert(struct_type.haveLayout(ip));
1447 return .{ .scalar = struct_type.size(ip).* };1445 return .{ .scalar = struct_type.sizeUnordered(ip) };
1448 },1446 },
1449 }1447 }
1450 },1448 },
...@@ -1464,7 +1462,7 @@ pub fn abiSizeAdvanced(...@@ -1464,7 +1462,7 @@ pub fn abiSizeAdvanced(
1464 const union_type = ip.loadUnionType(ty.toIntern());1462 const union_type = ip.loadUnionType(ty.toIntern());
1465 switch (strat) {1463 switch (strat) {
1466 .sema => try ty.resolveLayout(pt),1464 .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 .{
1468 .val = Value.fromInterned(try pt.intern(.{ .int = .{1466 .val = Value.fromInterned(try pt.intern(.{ .int = .{
1469 .ty = .comptime_int_type,1467 .ty = .comptime_int_type,
1470 .storage = .{ .lazy_size = ty.toIntern() },1468 .storage = .{ .lazy_size = ty.toIntern() },
...@@ -1474,7 +1472,7 @@ pub fn abiSizeAdvanced(...@@ -1474,7 +1472,7 @@ pub fn abiSizeAdvanced(
1474 }1472 }
14751473
1476 assert(union_type.haveLayout(ip));1474 assert(union_type.haveLayout(ip));
1477 return .{ .scalar = union_type.size(ip).* };1475 return .{ .scalar = union_type.sizeUnordered(ip) };
1478 },1476 },
1479 .opaque_type => unreachable, // no size available1477 .opaque_type => unreachable, // no size available
1480 .enum_type => return .{ .scalar = Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).abiSize(pt) },1478 .enum_type => return .{ .scalar = Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).abiSize(pt) },
...@@ -1788,7 +1786,7 @@ pub fn bitSizeAdvanced(...@@ -1788,7 +1786,7 @@ pub fn bitSizeAdvanced(
1788 if (is_packed) try ty.resolveLayout(pt);1786 if (is_packed) try ty.resolveLayout(pt);
1789 }1787 }
1790 if (is_packed) {1788 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);
1792 }1790 }
1793 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;1791 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;
1794 },1792 },
...@@ -1808,7 +1806,7 @@ pub fn bitSizeAdvanced(...@@ -1808,7 +1806,7 @@ pub fn bitSizeAdvanced(
1808 if (!is_packed) {1806 if (!is_packed) {
1809 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;1807 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;
1810 }1808 }
1811 assert(union_type.flagsPtr(ip).status.haveFieldTypes());1809 assert(union_type.flagsUnordered(ip).status.haveFieldTypes());
18121810
1813 var size: u64 = 0;1811 var size: u64 = 0;
1814 for (0..union_type.field_types.len) |field_index| {1812 for (0..union_type.field_types.len) |field_index| {
...@@ -2056,9 +2054,10 @@ pub fn unionTagType(ty: Type, mod: *Module) ?Type {...@@ -2056,9 +2054,10 @@ pub fn unionTagType(ty: Type, mod: *Module) ?Type {
2056 else => return null,2054 else => return null,
2057 }2055 }
2058 const union_type = ip.loadUnionType(ty.toIntern());2056 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) {
2060 .tagged => {2059 .tagged => {
2061 assert(union_type.flagsPtr(ip).status.haveFieldTypes());2060 assert(union_flags.status.haveFieldTypes());
2062 return Type.fromInterned(union_type.enum_tag_ty);2061 return Type.fromInterned(union_type.enum_tag_ty);
2063 },2062 },
2064 else => return null,2063 else => return null,
...@@ -2135,7 +2134,7 @@ pub fn containerLayout(ty: Type, mod: *Module) std.builtin.Type.ContainerLayout...@@ -2135,7 +2134,7 @@ pub fn containerLayout(ty: Type, mod: *Module) std.builtin.Type.ContainerLayout
2135 return switch (ip.indexToKey(ty.toIntern())) {2134 return switch (ip.indexToKey(ty.toIntern())) {
2136 .struct_type => ip.loadStructType(ty.toIntern()).layout,2135 .struct_type => ip.loadStructType(ty.toIntern()).layout,
2137 .anon_struct_type => .auto,2136 .anon_struct_type => .auto,
2138 .union_type => ip.loadUnionType(ty.toIntern()).flagsPtr(ip).layout,2137 .union_type => ip.loadUnionType(ty.toIntern()).flagsUnordered(ip).layout,
2139 else => unreachable,2138 else => unreachable,
2140 };2139 };
2141}2140}
...@@ -2157,7 +2156,7 @@ pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool {...@@ -2157,7 +2156,7 @@ pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool {
2157 .anyerror_type, .adhoc_inferred_error_set_type => false,2156 .anyerror_type, .adhoc_inferred_error_set_type => false,
2158 else => switch (ip.indexToKey(ty.toIntern())) {2157 else => switch (ip.indexToKey(ty.toIntern())) {
2159 .error_set_type => |error_set_type| error_set_type.names.len == 0,2158 .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)) {
2161 .none, .anyerror_type => false,2160 .none, .anyerror_type => false,
2162 else => |t| ip.indexToKey(t).error_set_type.names.len == 0,2161 else => |t| ip.indexToKey(t).error_set_type.names.len == 0,
2163 },2162 },
...@@ -2175,7 +2174,7 @@ pub fn isAnyError(ty: Type, mod: *Module) bool {...@@ -2175,7 +2174,7 @@ pub fn isAnyError(ty: Type, mod: *Module) bool {
2175 .anyerror_type => true,2174 .anyerror_type => true,
2176 .adhoc_inferred_error_set_type => false,2175 .adhoc_inferred_error_set_type => false,
2177 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {2176 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,
2179 else => false,2178 else => false,
2180 },2179 },
2181 };2180 };
...@@ -2200,7 +2199,7 @@ pub fn errorSetHasFieldIp(...@@ -2200,7 +2199,7 @@ pub fn errorSetHasFieldIp(
2200 .anyerror_type => true,2199 .anyerror_type => true,
2201 else => switch (ip.indexToKey(ty)) {2200 else => switch (ip.indexToKey(ty)) {
2202 .error_set_type => |error_set_type| error_set_type.nameIndex(ip, name) != null,2201 .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)) {
2204 .anyerror_type => true,2203 .anyerror_type => true,
2205 .none => false,2204 .none => false,
2206 else => |t| ip.indexToKey(t).error_set_type.nameIndex(ip, name) != null,2205 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 {...@@ -2336,7 +2335,7 @@ pub fn intInfo(starting_ty: Type, mod: *Module) InternPool.Key.IntType {
2336 .c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) },2335 .c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) },
2337 else => switch (ip.indexToKey(ty.toIntern())) {2336 else => switch (ip.indexToKey(ty.toIntern())) {
2338 .int_type => |int_type| return int_type,2337 .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)),
2340 .enum_type => ty = Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty),2339 .enum_type => ty = Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty),
2341 .vector_type => |vector_type| ty = Type.fromInterned(vector_type.child),2340 .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...@@ -2826,17 +2825,18 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se
2826 return false;2825 return false;
28272826
2828 // A struct with no fields is not comptime-only.2827 // 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)) {
2830 .no, .wip => false,2829 .no, .wip => false,
2831 .yes => true,2830 .yes => true,
2832 .unknown => {2831 .unknown => {
2833 assert(strat == .sema);2832 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);
2836 return false;2836 return false;
2837 }
28372838
2838 struct_type.flagsPtr(ip).requires_comptime = .wip;2839 errdefer struct_type.setRequiresComptime(ip, .unknown);
2839 errdefer struct_type.flagsPtr(ip).requires_comptime = .unknown;
28402840
2841 try ty.resolveFields(pt);2841 try ty.resolveFields(pt);
28422842
...@@ -2849,12 +2849,12 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se...@@ -2849,12 +2849,12 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se
2849 // be considered resolved. Comptime-only types2849 // be considered resolved. Comptime-only types
2850 // still maintain a layout of their2850 // still maintain a layout of their
2851 // runtime-known fields.2851 // runtime-known fields.
2852 struct_type.flagsPtr(ip).requires_comptime = .yes;2852 struct_type.setRequiresComptime(ip, .yes);
2853 return true;2853 return true;
2854 }2854 }
2855 }2855 }
28562856
2857 struct_type.flagsPtr(ip).requires_comptime = .no;2857 struct_type.setRequiresComptime(ip, .no);
2858 return false;2858 return false;
2859 },2859 },
2860 };2860 };
...@@ -2870,29 +2870,30 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se...@@ -2870,29 +2870,30 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se
28702870
2871 .union_type => {2871 .union_type => {
2872 const union_type = ip.loadUnionType(ty.toIntern());2872 const union_type = ip.loadUnionType(ty.toIntern());
2873 switch (union_type.flagsPtr(ip).requires_comptime) {2873 switch (union_type.setRequiresComptimeWip(ip)) {
2874 .no, .wip => return false,2874 .no, .wip => return false,
2875 .yes => return true,2875 .yes => return true,
2876 .unknown => {2876 .unknown => {
2877 assert(strat == .sema);2877 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);
2880 return false;2881 return false;
2882 }
28812883
2882 union_type.flagsPtr(ip).requires_comptime = .wip;2884 errdefer union_type.setRequiresComptime(ip, .unknown);
2883 errdefer union_type.flagsPtr(ip).requires_comptime = .unknown;
28842885
2885 try ty.resolveFields(pt);2886 try ty.resolveFields(pt);
28862887
2887 for (0..union_type.field_types.len) |field_idx| {2888 for (0..union_type.field_types.len) |field_idx| {
2888 const field_ty = union_type.field_types.get(ip)[field_idx];2889 const field_ty = union_type.field_types.get(ip)[field_idx];
2889 if (try Type.fromInterned(field_ty).comptimeOnlyAdvanced(pt, strat)) {2890 if (try Type.fromInterned(field_ty).comptimeOnlyAdvanced(pt, strat)) {
2890 union_type.flagsPtr(ip).requires_comptime = .yes;2891 union_type.setRequiresComptime(ip, .yes);
2891 return true;2892 return true;
2892 }2893 }
2893 }2894 }
28942895
2895 union_type.flagsPtr(ip).requires_comptime = .no;2896 union_type.setRequiresComptime(ip, .no);
2896 return false;2897 return false;
2897 },2898 },
2898 }2899 }
...@@ -3117,7 +3118,7 @@ pub fn errorSetNames(ty: Type, mod: *Module) InternPool.NullTerminatedString.Sli...@@ -3117,7 +3118,7 @@ pub fn errorSetNames(ty: Type, mod: *Module) InternPool.NullTerminatedString.Sli
3117 const ip = &mod.intern_pool;3118 const ip = &mod.intern_pool;
3118 return switch (ip.indexToKey(ty.toIntern())) {3119 return switch (ip.indexToKey(ty.toIntern())) {
3119 .error_set_type => |x| x.names,3120 .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)) {
3121 .none => unreachable, // unresolved inferred error set3122 .none => unreachable, // unresolved inferred error set
3122 .anyerror_type => unreachable,3123 .anyerror_type => unreachable,
3123 else => |t| ip.indexToKey(t).error_set_type.names,3124 else => |t| ip.indexToKey(t).error_set_type.names,
...@@ -3374,7 +3375,7 @@ pub fn isTuple(ty: Type, mod: *Module) bool {...@@ -3374,7 +3375,7 @@ pub fn isTuple(ty: Type, mod: *Module) bool {
3374 const struct_type = ip.loadStructType(ty.toIntern());3375 const struct_type = ip.loadStructType(ty.toIntern());
3375 if (struct_type.layout == .@"packed") return false;3376 if (struct_type.layout == .@"packed") return false;
3376 if (struct_type.decl == .none) return false;3377 if (struct_type.decl == .none) return false;
3377 return struct_type.flagsPtr(ip).is_tuple;3378 return struct_type.flagsUnordered(ip).is_tuple;
3378 },3379 },
3379 .anon_struct_type => |anon_struct| anon_struct.names.len == 0,3380 .anon_struct_type => |anon_struct| anon_struct.names.len == 0,
3380 else => false,3381 else => false,
...@@ -3396,7 +3397,7 @@ pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool {...@@ -3396,7 +3397,7 @@ pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool {
3396 const struct_type = ip.loadStructType(ty.toIntern());3397 const struct_type = ip.loadStructType(ty.toIntern());
3397 if (struct_type.layout == .@"packed") return false;3398 if (struct_type.layout == .@"packed") return false;
3398 if (struct_type.decl == .none) return false;3399 if (struct_type.decl == .none) return false;
3399 return struct_type.flagsPtr(ip).is_tuple;3400 return struct_type.flagsUnordered(ip).is_tuple;
3400 },3401 },
3401 .anon_struct_type => true,3402 .anon_struct_type => true,
3402 else => false,3403 else => false,
src/Value.zig+1-1
...@@ -558,7 +558,7 @@ pub fn writeToPackedMemory(...@@ -558,7 +558,7 @@ pub fn writeToPackedMemory(
558 },558 },
559 .Union => {559 .Union => {
560 const union_obj = mod.typeToUnion(ty).?;560 const union_obj = mod.typeToUnion(ty).?;
561 switch (union_obj.getLayout(ip)) {561 switch (union_obj.flagsUnordered(ip).layout) {
562 .auto, .@"extern" => unreachable, // Handled in non-packed writeToMemory562 .auto, .@"extern" => unreachable, // Handled in non-packed writeToMemory
563 .@"packed" => {563 .@"packed" => {
564 if (val.unionTag(mod)) |union_tag| {564 if (val.unionTag(mod)) |union_tag| {
src/Zcu.zig+2-2
...@@ -2968,7 +2968,7 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index)...@@ -2968,7 +2968,7 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index)
2968 const is_outdated = mod.outdated.contains(func_as_depender) or2968 const is_outdated = mod.outdated.contains(func_as_depender) or
2969 mod.potentially_outdated.contains(func_as_depender);2969 mod.potentially_outdated.contains(func_as_depender);
29702970
2971 switch (func.analysis(ip).state) {2971 switch (func.analysisUnordered(ip).state) {
2972 .none => {},2972 .none => {},
2973 .queued => return,2973 .queued => return,
2974 // As above, we don't need to forward errors here.2974 // As above, we don't need to forward errors here.
...@@ -2989,7 +2989,7 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index)...@@ -2989,7 +2989,7 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index)
2989 // since the last update2989 // since the last update
2990 try mod.comp.work_queue.writeItem(.{ .emit_h_decl = decl_index });2990 try mod.comp.work_queue.writeItem(.{ .emit_h_decl = decl_index });
2991 }2991 }
2992 func.analysis(ip).state = .queued;2992 func.setAnalysisState(ip, .queued);
2993}2993}
29942994
2995pub const SemaDeclResult = packed struct {2995pub 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...@@ -641,8 +641,8 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
641641
642 // We'll want to remember what the IES used to be before the update for642 // We'll want to remember what the IES used to be before the update for
643 // dependency invalidation purposes.643 // dependency invalidation purposes.
644 const old_resolved_ies = if (func.analysis(ip).inferred_error_set)644 const old_resolved_ies = if (func.analysisUnordered(ip).inferred_error_set)
645 func.resolvedErrorSet(ip).*645 func.resolvedErrorSetUnordered(ip)
646 else646 else
647 .none;647 .none;
648648
...@@ -671,7 +671,7 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter...@@ -671,7 +671,7 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
671 zcu.deleteUnitReferences(func_as_depender);671 zcu.deleteUnitReferences(func_as_depender);
672 }672 }
673673
674 switch (func.analysis(ip).state) {674 switch (func.analysisUnordered(ip).state) {
675 .success => if (!was_outdated) return,675 .success => if (!was_outdated) return,
676 .sema_failure,676 .sema_failure,
677 .dependency_failure,677 .dependency_failure,
...@@ -693,11 +693,11 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter...@@ -693,11 +693,11 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
693693
694 var air = pt.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) {694 var air = pt.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) {
695 error.AnalysisFail => {695 error.AnalysisFail => {
696 if (func.analysis(ip).state == .in_progress) {696 if (func.analysisUnordered(ip).state == .in_progress) {
697 // If this decl caused the compile error, the analysis field would697 // If this decl caused the compile error, the analysis field would
698 // be changed to indicate it was this Decl's fault. Because this698 // be changed to indicate it was this Decl's fault. Because this
699 // did not happen, we infer here that it was a dependency failure.699 // 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);
701 }701 }
702 return error.AnalysisFail;702 return error.AnalysisFail;
703 },703 },
...@@ -707,8 +707,8 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter...@@ -707,8 +707,8 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
707707
708 const invalidate_ies_deps = i: {708 const invalidate_ies_deps = i: {
709 if (!was_outdated) break :i false;709 if (!was_outdated) break :i false;
710 if (!func.analysis(ip).inferred_error_set) break :i true;710 if (!func.analysisUnordered(ip).inferred_error_set) break :i true;
711 const new_resolved_ies = func.resolvedErrorSet(ip).*;711 const new_resolved_ies = func.resolvedErrorSetUnordered(ip);
712 break :i new_resolved_ies != old_resolved_ies;712 break :i new_resolved_ies != old_resolved_ies;
713 };713 };
714 if (invalidate_ies_deps) {714 if (invalidate_ies_deps) {
...@@ -783,7 +783,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai...@@ -783,7 +783,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
783 .{@errorName(err)},783 .{@errorName(err)},
784 ),784 ),
785 );785 );
786 func.analysis(ip).state = .codegen_failure;786 func.setAnalysisState(ip, .codegen_failure);
787 return;787 return;
788 },788 },
789 };789 };
...@@ -797,12 +797,12 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai...@@ -797,12 +797,12 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
797 // Correcting this failure will involve changing a type this function797 // Correcting this failure will involve changing a type this function
798 // depends on, hence triggering re-analysis of this function, so this798 // depends on, hence triggering re-analysis of this function, so this
799 // interacts correctly with incremental compilation.799 // interacts correctly with incremental compilation.
800 func.analysis(ip).state = .codegen_failure;800 func.setAnalysisState(ip, .codegen_failure);
801 } else if (comp.bin_file) |lf| {801 } else if (comp.bin_file) |lf| {
802 lf.updateFunc(pt, func_index, air, liveness) catch |err| switch (err) {802 lf.updateFunc(pt, func_index, air, liveness) catch |err| switch (err) {
803 error.OutOfMemory => return error.OutOfMemory,803 error.OutOfMemory => return error.OutOfMemory,
804 error.AnalysisFail => {804 error.AnalysisFail => {
805 func.analysis(ip).state = .codegen_failure;805 func.setAnalysisState(ip, .codegen_failure);
806 },806 },
807 else => {807 else => {
808 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);808 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
...@@ -812,7 +812,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai...@@ -812,7 +812,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
812 "unable to codegen: {s}",812 "unable to codegen: {s}",
813 .{@errorName(err)},813 .{@errorName(err)},
814 ));814 ));
815 func.analysis(ip).state = .codegen_failure;815 func.setAnalysisState(ip, .codegen_failure);
816 try zcu.retryable_failures.append(zcu.gpa, InternPool.AnalUnit.wrap(.{ .func = func_index }));816 try zcu.retryable_failures.append(zcu.gpa, InternPool.AnalUnit.wrap(.{ .func = func_index }));
817 },817 },
818 };818 };
...@@ -1080,7 +1080,7 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult {...@@ -1080,7 +1080,7 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult {
1080 const old_linksection = decl.@"linksection";1080 const old_linksection = decl.@"linksection";
1081 const old_addrspace = decl.@"addrspace";1081 const old_addrspace = decl.@"addrspace";
1082 const old_is_inline = if (decl.getOwnedFunction(zcu)) |prev_func|1082 const old_is_inline = if (decl.getOwnedFunction(zcu)) |prev_func|
1083 prev_func.analysis(ip).state == .inline_only1083 prev_func.analysisUnordered(ip).state == .inline_only
1084 else1084 else
1085 false;1085 false;
10861086
...@@ -2037,7 +2037,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All...@@ -2037,7 +2037,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
2037 .fn_ret_ty = Type.fromInterned(fn_ty_info.return_type),2037 .fn_ret_ty = Type.fromInterned(fn_ty_info.return_type),
2038 .fn_ret_ty_ies = null,2038 .fn_ret_ty_ies = null,
2039 .owner_func_index = func_index,2039 .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),
2041 .comptime_err_ret_trace = &comptime_err_ret_trace,2041 .comptime_err_ret_trace = &comptime_err_ret_trace,
2042 };2042 };
2043 defer sema.deinit();2043 defer sema.deinit();
...@@ -2047,14 +2047,14 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All...@@ -2047,14 +2047,14 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
2047 try sema.declareDependency(.{ .src_hash = decl.zir_decl_index.unwrap().? });2047 try sema.declareDependency(.{ .src_hash = decl.zir_decl_index.unwrap().? });
2048 try sema.declareDependency(.{ .decl_val = decl_index });2048 try sema.declareDependency(.{ .decl_val = decl_index });
20492049
2050 if (func.analysis(ip).inferred_error_set) {2050 if (func.analysisUnordered(ip).inferred_error_set) {
2051 const ies = try arena.create(Sema.InferredErrorSet);2051 const ies = try arena.create(Sema.InferredErrorSet);
2052 ies.* = .{ .func = func_index };2052 ies.* = .{ .func = func_index };
2053 sema.fn_ret_ty_ies = ies;2053 sema.fn_ret_ty_ies = ies;
2054 }2054 }
20552055
2056 // reset in case calls to errorable functions are removed.2056 // 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
2059 // First few indexes of extra are reserved and set at the end.2059 // First few indexes of extra are reserved and set at the end.
2060 const reserved_count = @typeInfo(Air.ExtraIndex).Enum.fields.len;2060 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...@@ -2080,7 +2080,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
2080 };2080 };
2081 defer inner_block.instructions.deinit(gpa);2081 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
2085 // Here we are performing "runtime semantic analysis" for a function body, which means2085 // Here we are performing "runtime semantic analysis" for a function body, which means
2086 // we must map the parameter ZIR instructions to `arg` AIR instructions.2086 // 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...@@ -2149,7 +2149,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
2149 });2149 });
2150 }2150 }
21512151
2152 func.analysis(ip).state = .in_progress;2152 func.setAnalysisState(ip, .in_progress);
21532153
2154 const last_arg_index = inner_block.instructions.items.len;2154 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...@@ -2176,7 +2176,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
2176 }2176 }
21772177
2178 // If we don't get an error return trace from a caller, create our own.2178 // 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 and2179 if (func.analysisUnordered(ip).calls_or_awaits_errorable_fn and
2180 mod.comp.config.any_error_tracing and2180 mod.comp.config.any_error_tracing and
2181 !sema.fn_ret_ty.isError(mod))2181 !sema.fn_ret_ty.isError(mod))
2182 {2182 {
...@@ -2218,10 +2218,10 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All...@@ -2218,10 +2218,10 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
2218 else => |e| return e,2218 else => |e| return e,
2219 };2219 };
2220 assert(ies.resolved != .none);2220 assert(ies.resolved != .none);
2221 ip.funcIesResolved(func_index).* = ies.resolved;2221 ip.funcSetIesResolved(func_index, ies.resolved);
2222 }2222 }
22232223
2224 func.analysis(ip).state = .success;2224 func.setAnalysisState(ip, .success);
22252225
2226 // Finally we must resolve the return type and parameter types so that backends2226 // Finally we must resolve the return type and parameter types so that backends
2227 // have full access to type information.2227 // have full access to type information.
...@@ -2415,6 +2415,7 @@ fn processExportsInner(...@@ -2415,6 +2415,7 @@ fn processExportsInner(
2415) error{OutOfMemory}!void {2415) error{OutOfMemory}!void {
2416 const zcu = pt.zcu;2416 const zcu = pt.zcu;
2417 const gpa = zcu.gpa;2417 const gpa = zcu.gpa;
2418 const ip = &zcu.intern_pool;
24182419
2419 for (export_indices) |export_idx| {2420 for (export_indices) |export_idx| {
2420 const new_export = &zcu.all_exports.items[export_idx];2421 const new_export = &zcu.all_exports.items[export_idx];
...@@ -2423,7 +2424,7 @@ fn processExportsInner(...@@ -2423,7 +2424,7 @@ fn processExportsInner(
2423 new_export.status = .failed_retryable;2424 new_export.status = .failed_retryable;
2424 try zcu.failed_exports.ensureUnusedCapacity(gpa, 1);2425 try zcu.failed_exports.ensureUnusedCapacity(gpa, 1);
2425 const msg = try Zcu.ErrorMsg.create(gpa, new_export.src, "exported symbol collision: {}", .{2426 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),
2427 });2428 });
2428 errdefer msg.destroy(gpa);2429 errdefer msg.destroy(gpa);
2429 const other_export = zcu.all_exports.items[gop.value_ptr.*];2430 const other_export = zcu.all_exports.items[gop.value_ptr.*];
...@@ -2443,8 +2444,7 @@ fn processExportsInner(...@@ -2443,8 +2444,7 @@ fn processExportsInner(
2443 if (!decl.owns_tv) break :failed false;2444 if (!decl.owns_tv) break :failed false;
2444 if (decl.typeOf(zcu).zigTypeTag(zcu) != .Fn) break :failed false;2445 if (decl.typeOf(zcu).zigTypeTag(zcu) != .Fn) break :failed false;
2445 // Check if owned function failed2446 // Check if owned function failed
2446 const a = zcu.funcInfo(decl.val.toIntern()).analysis(&zcu.intern_pool);2447 break :failed zcu.funcInfo(decl.val.toIntern()).analysisUnordered(ip).state != .success;
2447 break :failed a.state != .success;
2448 }) {2448 }) {
2449 // This `Decl` is failed, so was never sent to codegen.2449 // This `Decl` is failed, so was never sent to codegen.
2450 // TODO: we should probably tell the backend to delete any old exports of this `Decl`?2450 // 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...@@ -3072,7 +3072,7 @@ pub fn getUnionLayout(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionTyp
3072 most_aligned_field_size = field_size;3072 most_aligned_field_size = field_size;
3073 }3073 }
3074 }3074 }
3075 const have_tag = loaded_union.flagsPtr(ip).runtime_tag.hasTag();3075 const have_tag = loaded_union.flagsUnordered(ip).runtime_tag.hasTag();
3076 if (!have_tag or !Type.fromInterned(loaded_union.enum_tag_ty).hasRuntimeBits(pt)) {3076 if (!have_tag or !Type.fromInterned(loaded_union.enum_tag_ty).hasRuntimeBits(pt)) {
3077 return .{3077 return .{
3078 .abi_size = payload_align.forward(payload_size),3078 .abi_size = payload_align.forward(payload_size),
...@@ -3091,7 +3091,7 @@ pub fn getUnionLayout(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionTyp...@@ -3091,7 +3091,7 @@ pub fn getUnionLayout(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionTyp
3091 const tag_size = Type.fromInterned(loaded_union.enum_tag_ty).abiSize(pt);3091 const tag_size = Type.fromInterned(loaded_union.enum_tag_ty).abiSize(pt);
3092 const tag_align = Type.fromInterned(loaded_union.enum_tag_ty).abiAlignment(pt).max(.@"1");3092 const tag_align = Type.fromInterned(loaded_union.enum_tag_ty).abiAlignment(pt).max(.@"1");
3093 return .{3093 return .{
3094 .abi_size = loaded_union.size(ip).*,3094 .abi_size = loaded_union.sizeUnordered(ip),
3095 .abi_align = tag_align.max(payload_align),3095 .abi_align = tag_align.max(payload_align),
3096 .most_aligned_field = most_aligned_field,3096 .most_aligned_field = most_aligned_field,
3097 .most_aligned_field_size = most_aligned_field_size,3097 .most_aligned_field_size = most_aligned_field_size,
...@@ -3100,7 +3100,7 @@ pub fn getUnionLayout(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionTyp...@@ -3100,7 +3100,7 @@ pub fn getUnionLayout(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionTyp
3100 .payload_align = payload_align,3100 .payload_align = payload_align,
3101 .tag_align = tag_align,3101 .tag_align = tag_align,
3102 .tag_size = tag_size,3102 .tag_size = tag_size,
3103 .padding = loaded_union.padding(ip).*,3103 .padding = loaded_union.paddingUnordered(ip),
3104 };3104 };
3105}3105}
31063106
...@@ -3142,7 +3142,7 @@ pub fn unionFieldNormalAlignmentAdvanced(...@@ -3142,7 +3142,7 @@ pub fn unionFieldNormalAlignmentAdvanced(
3142 strat: Type.ResolveStrat,3142 strat: Type.ResolveStrat,
3143) Zcu.SemaError!InternPool.Alignment {3143) Zcu.SemaError!InternPool.Alignment {
3144 const ip = &pt.zcu.intern_pool;3144 const ip = &pt.zcu.intern_pool;
3145 assert(loaded_union.flagsPtr(ip).layout != .@"packed");3145 assert(loaded_union.flagsUnordered(ip).layout != .@"packed");
3146 const field_align = loaded_union.fieldAlign(ip, field_index);3146 const field_align = loaded_union.fieldAlign(ip, field_index);
3147 if (field_align != .none) return field_align;3147 if (field_align != .none) return field_align;
3148 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);3148 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 {...@@ -56,7 +56,7 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread, ctx: Context) Class {
56 .Union => {56 .Union => {
57 const bit_size = ty.bitSize(pt);57 const bit_size = ty.bitSize(pt);
58 const union_obj = pt.zcu.typeToUnion(ty).?;58 const union_obj = pt.zcu.typeToUnion(ty).?;
59 if (union_obj.getLayout(ip) == .@"packed") {59 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
60 if (bit_size > 64) return .memory;60 if (bit_size > 64) return .memory;
61 return .byval;61 return .byval;
62 }62 }
src/arch/riscv64/CodeGen.zig+1-1
...@@ -768,7 +768,7 @@ pub fn generate(...@@ -768,7 +768,7 @@ pub fn generate(
768 @intFromEnum(FrameIndex.stack_frame),768 @intFromEnum(FrameIndex.stack_frame),
769 FrameAlloc.init(.{769 FrameAlloc.init(.{
770 .size = 0,770 .size = 0,
771 .alignment = func.analysis(ip).stack_alignment.max(.@"1"),771 .alignment = func.analysisUnordered(ip).stack_alignment.max(.@"1"),
772 }),772 }),
773 );773 );
774 function.frame_allocs.set(774 function.frame_allocs.set(
src/arch/wasm/CodeGen.zig+7-7
...@@ -1011,7 +1011,7 @@ fn typeToValtype(ty: Type, pt: Zcu.PerThread) wasm.Valtype {...@@ -1011,7 +1011,7 @@ fn typeToValtype(ty: Type, pt: Zcu.PerThread) wasm.Valtype {
1011 },1011 },
1012 .Struct => {1012 .Struct => {
1013 if (pt.zcu.typeToPackedStruct(ty)) |packed_struct| {1013 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);
1015 } else {1015 } else {
1016 return wasm.Valtype.i32;1016 return wasm.Valtype.i32;
1017 }1017 }
...@@ -1746,7 +1746,7 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {...@@ -1746,7 +1746,7 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
1746 => return ty.hasRuntimeBitsIgnoreComptime(pt),1746 => return ty.hasRuntimeBitsIgnoreComptime(pt),
1747 .Union => {1747 .Union => {
1748 if (mod.typeToUnion(ty)) |union_obj| {1748 if (mod.typeToUnion(ty)) |union_obj| {
1749 if (union_obj.getLayout(ip) == .@"packed") {1749 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
1750 return ty.abiSize(pt) > 8;1750 return ty.abiSize(pt) > 8;
1751 }1751 }
1752 }1752 }
...@@ -1754,7 +1754,7 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {...@@ -1754,7 +1754,7 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
1754 },1754 },
1755 .Struct => {1755 .Struct => {
1756 if (mod.typeToPackedStruct(ty)) |packed_struct| {1756 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);
1758 }1758 }
1759 return ty.hasRuntimeBitsIgnoreComptime(pt);1759 return ty.hasRuntimeBitsIgnoreComptime(pt);
1760 },1760 },
...@@ -3377,7 +3377,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {...@@ -3377,7 +3377,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
3377 assert(struct_type.layout == .@"packed");3377 assert(struct_type.layout == .@"packed");
3378 var buf: [8]u8 = .{0} ** 8; // zero the buffer so we do not read 0xaa as integer3378 var buf: [8]u8 = .{0} ** 8; // zero the buffer so we do not read 0xaa as integer
3379 val.writeToPackedMemory(ty, pt, &buf, 0) catch unreachable;3379 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));
3381 const int_val = try pt.intValue(3381 const int_val = try pt.intValue(
3382 backing_int_ty,3382 backing_int_ty,
3383 mem.readInt(u64, &buf, .little),3383 mem.readInt(u64, &buf, .little),
...@@ -3443,7 +3443,7 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {...@@ -3443,7 +3443,7 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
3443 },3443 },
3444 .Struct => {3444 .Struct => {
3445 const packed_struct = mod.typeToPackedStruct(ty).?;3445 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)));
3447 },3447 },
3448 else => return func.fail("Wasm TODO: emitUndefined for type: {}\n", .{ty.zigTypeTag(mod)}),3448 else => return func.fail("Wasm TODO: emitUndefined for type: {}\n", .{ty.zigTypeTag(mod)}),
3449 }3449 }
...@@ -3974,7 +3974,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -3974,7 +3974,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
3974 .Struct => result: {3974 .Struct => result: {
3975 const packed_struct = mod.typeToPackedStruct(struct_ty).?;3975 const packed_struct = mod.typeToPackedStruct(struct_ty).?;
3976 const offset = pt.structPackedFieldBitOffset(packed_struct, field_index);3976 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));
3978 const wasm_bits = toWasmBits(backing_ty.intInfo(mod).bits) orelse {3978 const wasm_bits = toWasmBits(backing_ty.intInfo(mod).bits) orelse {
3979 return func.fail("TODO: airStructFieldVal for packed structs larger than 128 bits", .{});3979 return func.fail("TODO: airStructFieldVal for packed structs larger than 128 bits", .{});
3980 };3980 };
...@@ -5377,7 +5377,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {...@@ -5377,7 +5377,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
5377 }5377 }
5378 const packed_struct = mod.typeToPackedStruct(result_ty).?;5378 const packed_struct = mod.typeToPackedStruct(result_ty).?;
5379 const field_types = packed_struct.field_types;5379 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
5382 // ensure the result is zero'd5382 // ensure the result is zero'd
5383 const result = try func.allocLocal(backing_type);5383 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 {...@@ -71,7 +71,7 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {
71 },71 },
72 .Union => {72 .Union => {
73 const union_obj = pt.zcu.typeToUnion(ty).?;73 const union_obj = pt.zcu.typeToUnion(ty).?;
74 if (union_obj.getLayout(ip) == .@"packed") {74 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
75 if (ty.bitSize(pt) <= 64) return direct;75 if (ty.bitSize(pt) <= 64) return direct;
76 return .{ .direct, .direct };76 return .{ .direct, .direct };
77 }77 }
...@@ -107,7 +107,7 @@ pub fn scalarType(ty: Type, pt: Zcu.PerThread) Type {...@@ -107,7 +107,7 @@ pub fn scalarType(ty: Type, pt: Zcu.PerThread) Type {
107 switch (ty.zigTypeTag(mod)) {107 switch (ty.zigTypeTag(mod)) {
108 .Struct => {108 .Struct => {
109 if (mod.typeToPackedStruct(ty)) |packed_struct| {109 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);
111 } else {111 } else {
112 assert(ty.structFieldCount(mod) == 1);112 assert(ty.structFieldCount(mod) == 1);
113 return scalarType(ty.structFieldType(0, mod), pt);113 return scalarType(ty.structFieldType(0, mod), pt);
...@@ -115,7 +115,7 @@ pub fn scalarType(ty: Type, pt: Zcu.PerThread) Type {...@@ -115,7 +115,7 @@ pub fn scalarType(ty: Type, pt: Zcu.PerThread) Type {
115 },115 },
116 .Union => {116 .Union => {
117 const union_obj = mod.typeToUnion(ty).?;117 const union_obj = mod.typeToUnion(ty).?;
118 if (union_obj.getLayout(ip) != .@"packed") {118 if (union_obj.flagsUnordered(ip).layout != .@"packed") {
119 const layout = pt.getUnionLayout(union_obj);119 const layout = pt.getUnionLayout(union_obj);
120 if (layout.payload_size == 0 and layout.tag_size != 0) {120 if (layout.payload_size == 0 and layout.tag_size != 0) {
121 return scalarType(ty.unionTagTypeSafety(mod).?, pt);121 return scalarType(ty.unionTagTypeSafety(mod).?, pt);
src/arch/x86_64/CodeGen.zig+1-1
...@@ -856,7 +856,7 @@ pub fn generate(...@@ -856,7 +856,7 @@ pub fn generate(
856 @intFromEnum(FrameIndex.stack_frame),856 @intFromEnum(FrameIndex.stack_frame),
857 FrameAlloc.init(.{857 FrameAlloc.init(.{
858 .size = 0,858 .size = 0,
859 .alignment = func.analysis(ip).stack_alignment.max(.@"1"),859 .alignment = func.analysisUnordered(ip).stack_alignment.max(.@"1"),
860 }),860 }),
861 );861 );
862 function.frame_allocs.set(862 function.frame_allocs.set(
src/arch/x86_64/abi.zig+5-5
...@@ -349,7 +349,7 @@ fn classifySystemVStruct(...@@ -349,7 +349,7 @@ fn classifySystemVStruct(
349 .@"packed" => {},349 .@"packed" => {},
350 }350 }
351 } else if (pt.zcu.typeToUnion(field_ty)) |field_loaded_union| {351 } 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) {
353 .auto, .@"extern" => {353 .auto, .@"extern" => {
354 byte_offset = classifySystemVUnion(result, byte_offset, field_loaded_union, pt, target);354 byte_offset = classifySystemVUnion(result, byte_offset, field_loaded_union, pt, target);
355 continue;355 continue;
...@@ -362,11 +362,11 @@ fn classifySystemVStruct(...@@ -362,11 +362,11 @@ fn classifySystemVStruct(
362 result_class.* = result_class.combineSystemV(field_class);362 result_class.* = result_class.combineSystemV(field_class);
363 byte_offset += field_ty.abiSize(pt);363 byte_offset += field_ty.abiSize(pt);
364 }364 }
365 const final_byte_offset = starting_byte_offset + loaded_struct.size(ip).*;365 const final_byte_offset = starting_byte_offset + loaded_struct.sizeUnordered(ip);
366 std.debug.assert(final_byte_offset == std.mem.alignForward(366 std.debug.assert(final_byte_offset == std.mem.alignForward(
367 u64,367 u64,
368 byte_offset,368 byte_offset,
369 loaded_struct.flagsPtr(ip).alignment.toByteUnits().?,369 loaded_struct.flagsUnordered(ip).alignment.toByteUnits().?,
370 ));370 ));
371 return final_byte_offset;371 return final_byte_offset;
372}372}
...@@ -390,7 +390,7 @@ fn classifySystemVUnion(...@@ -390,7 +390,7 @@ fn classifySystemVUnion(
390 .@"packed" => {},390 .@"packed" => {},
391 }391 }
392 } else if (pt.zcu.typeToUnion(field_ty)) |field_loaded_union| {392 } 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) {
394 .auto, .@"extern" => {394 .auto, .@"extern" => {
395 _ = classifySystemVUnion(result, starting_byte_offset, field_loaded_union, pt, target);395 _ = classifySystemVUnion(result, starting_byte_offset, field_loaded_union, pt, target);
396 continue;396 continue;
...@@ -402,7 +402,7 @@ fn classifySystemVUnion(...@@ -402,7 +402,7 @@ fn classifySystemVUnion(
402 for (result[@intCast(starting_byte_offset / 8)..][0..field_classes.len], field_classes) |*result_class, field_class|402 for (result[@intCast(starting_byte_offset / 8)..][0..field_classes.len], field_classes) |*result_class, field_class|
403 result_class.* = result_class.combineSystemV(field_class);403 result_class.* = result_class.combineSystemV(field_class);
404 }404 }
405 return starting_byte_offset + loaded_union.size(ip).*;405 return starting_byte_offset + loaded_union.sizeUnordered(ip);
406}406}
407407
408pub const SysV = struct {408pub const SysV = struct {
src/codegen.zig+2-2
...@@ -548,8 +548,8 @@ pub fn generateSymbol(...@@ -548,8 +548,8 @@ pub fn generateSymbol(
548 }548 }
549 }549 }
550550
551 const size = struct_type.size(ip).*;551 const size = struct_type.sizeUnordered(ip);
552 const alignment = struct_type.flagsPtr(ip).alignment.toByteUnits().?;552 const alignment = struct_type.flagsUnordered(ip).alignment.toByteUnits().?;
553553
554 const padding = math.cast(554 const padding = math.cast(
555 usize,555 usize,
src/codegen/c.zig+7-7
...@@ -1366,7 +1366,7 @@ pub const DeclGen = struct {...@@ -1366,7 +1366,7 @@ pub const DeclGen = struct {
1366 const loaded_union = ip.loadUnionType(ty.toIntern());1366 const loaded_union = ip.loadUnionType(ty.toIntern());
1367 if (un.tag == .none) {1367 if (un.tag == .none) {
1368 const backing_ty = try ty.unionBackingType(pt);1368 const backing_ty = try ty.unionBackingType(pt);
1369 switch (loaded_union.getLayout(ip)) {1369 switch (loaded_union.flagsUnordered(ip).layout) {
1370 .@"packed" => {1370 .@"packed" => {
1371 if (!location.isInitializer()) {1371 if (!location.isInitializer()) {
1372 try writer.writeByte('(');1372 try writer.writeByte('(');
...@@ -1401,7 +1401,7 @@ pub const DeclGen = struct {...@@ -1401,7 +1401,7 @@ pub const DeclGen = struct {
1401 const field_index = zcu.unionTagFieldIndex(loaded_union, Value.fromInterned(un.tag)).?;1401 const field_index = zcu.unionTagFieldIndex(loaded_union, Value.fromInterned(un.tag)).?;
1402 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);1402 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
1403 const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];1403 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") {
1405 if (field_ty.hasRuntimeBits(pt)) {1405 if (field_ty.hasRuntimeBits(pt)) {
1406 if (field_ty.isPtrAtRuntime(zcu)) {1406 if (field_ty.isPtrAtRuntime(zcu)) {
1407 try writer.writeByte('(');1407 try writer.writeByte('(');
...@@ -1629,7 +1629,7 @@ pub const DeclGen = struct {...@@ -1629,7 +1629,7 @@ pub const DeclGen = struct {
1629 },1629 },
1630 .union_type => {1630 .union_type => {
1631 const loaded_union = ip.loadUnionType(ty.toIntern());1631 const loaded_union = ip.loadUnionType(ty.toIntern());
1632 switch (loaded_union.getLayout(ip)) {1632 switch (loaded_union.flagsUnordered(ip).layout) {
1633 .auto, .@"extern" => {1633 .auto, .@"extern" => {
1634 if (!location.isInitializer()) {1634 if (!location.isInitializer()) {
1635 try writer.writeByte('(');1635 try writer.writeByte('(');
...@@ -1792,7 +1792,7 @@ pub const DeclGen = struct {...@@ -1792,7 +1792,7 @@ pub const DeclGen = struct {
1792 else => unreachable,1792 else => unreachable,
1793 }1793 }
1794 }1794 }
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)
1796 try w.writeAll("zig_cold ");1796 try w.writeAll("zig_cold ");
1797 if (fn_info.return_type == .noreturn_type) try w.writeAll("zig_noreturn ");1797 if (fn_info.return_type == .noreturn_type) try w.writeAll("zig_noreturn ");
17981798
...@@ -5527,7 +5527,7 @@ fn fieldLocation(...@@ -5527,7 +5527,7 @@ fn fieldLocation(
5527 .{ .field = field_index } },5527 .{ .field = field_index } },
5528 .union_type => {5528 .union_type => {
5529 const loaded_union = ip.loadUnionType(container_ty.toIntern());5529 const loaded_union = ip.loadUnionType(container_ty.toIntern());
5530 switch (loaded_union.getLayout(ip)) {5530 switch (loaded_union.flagsUnordered(ip).layout) {
5531 .auto, .@"extern" => {5531 .auto, .@"extern" => {
5532 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);5532 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
5533 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt))5533 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt))
...@@ -5763,7 +5763,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -5763,7 +5763,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
5763 .{ .field = extra.field_index },5763 .{ .field = extra.field_index },
5764 .union_type => field_name: {5764 .union_type => field_name: {
5765 const loaded_union = ip.loadUnionType(struct_ty.toIntern());5765 const loaded_union = ip.loadUnionType(struct_ty.toIntern());
5766 switch (loaded_union.getLayout(ip)) {5766 switch (loaded_union.flagsUnordered(ip).layout) {
5767 .auto, .@"extern" => {5767 .auto, .@"extern" => {
5768 const name = loaded_union.loadTagType(ip).names.get(ip)[extra.field_index];5768 const name = loaded_union.loadTagType(ip).names.get(ip)[extra.field_index];
5769 break :field_name if (loaded_union.hasTag(ip))5769 break :field_name if (loaded_union.hasTag(ip))
...@@ -7267,7 +7267,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {...@@ -7267,7 +7267,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
72677267
7268 const writer = f.object.writer();7268 const writer = f.object.writer();
7269 const local = try f.allocLocal(inst, union_ty);7269 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
7272 const field: CValue = if (union_ty.unionTagTypeSafety(zcu)) |tag_ty| field: {7272 const field: CValue = if (union_ty.unionTagTypeSafety(zcu)) |tag_ty| field: {
7273 const layout = union_ty.unionGetLayout(pt);7273 const layout = union_ty.unionGetLayout(pt);
src/codegen/c/Type.zig+2-2
...@@ -1744,7 +1744,7 @@ pub const Pool = struct {...@@ -1744,7 +1744,7 @@ pub const Pool = struct {
1744 .@"packed" => return pool.fromType(1744 .@"packed" => return pool.fromType(
1745 allocator,1745 allocator,
1746 scratch,1746 scratch,
1747 Type.fromInterned(loaded_struct.backingIntType(ip).*),1747 Type.fromInterned(loaded_struct.backingIntTypeUnordered(ip)),
1748 pt,1748 pt,
1749 mod,1749 mod,
1750 kind,1750 kind,
...@@ -1817,7 +1817,7 @@ pub const Pool = struct {...@@ -1817,7 +1817,7 @@ pub const Pool = struct {
1817 },1817 },
1818 .union_type => {1818 .union_type => {
1819 const loaded_union = ip.loadUnionType(ip_index);1819 const loaded_union = ip.loadUnionType(ip_index);
1820 switch (loaded_union.getLayout(ip)) {1820 switch (loaded_union.flagsUnordered(ip).layout) {
1821 .auto, .@"extern" => {1821 .auto, .@"extern" => {
1822 const has_tag = loaded_union.hasTag(ip);1822 const has_tag = loaded_union.hasTag(ip);
1823 const fwd_decl = try pool.getFwdDecl(allocator, .{1823 const fwd_decl = try pool.getFwdDecl(allocator, .{
src/codegen/llvm.zig+16-15
...@@ -1086,7 +1086,7 @@ pub const Object = struct {...@@ -1086,7 +1086,7 @@ pub const Object = struct {
1086 // If there is no such function in the module, it means the source code does not need it.1086 // If there is no such function in the module, it means the source code does not need it.
1087 const name = o.builder.strtabStringIfExists(lt_errors_fn_name) orelse return;1087 const name = o.builder.strtabStringIfExists(lt_errors_fn_name) orelse return;
1088 const llvm_fn = o.builder.getGlobal(name) orelse return;1088 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
1091 var wip = try Builder.WipFunction.init(&o.builder, .{1091 var wip = try Builder.WipFunction.init(&o.builder, .{
1092 .function = llvm_fn.ptrConst(&o.builder).kind.function,1092 .function = llvm_fn.ptrConst(&o.builder).kind.function,
...@@ -1385,13 +1385,14 @@ pub const Object = struct {...@@ -1385,13 +1385,14 @@ pub const Object = struct {
1385 var attributes = try function_index.ptrConst(&o.builder).attributes.toWip(&o.builder);1385 var attributes = try function_index.ptrConst(&o.builder).attributes.toWip(&o.builder);
1386 defer attributes.deinit(&o.builder);1386 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) {
1389 try attributes.addFnAttr(.@"noinline", &o.builder);1390 try attributes.addFnAttr(.@"noinline", &o.builder);
1390 } else {1391 } else {
1391 _ = try attributes.removeFnAttr(.@"noinline");1392 _ = try attributes.removeFnAttr(.@"noinline");
1392 }1393 }
13931394
1394 const stack_alignment = func.analysis(ip).stack_alignment;1395 const stack_alignment = func.analysisUnordered(ip).stack_alignment;
1395 if (stack_alignment != .none) {1396 if (stack_alignment != .none) {
1396 try attributes.addFnAttr(.{ .alignstack = stack_alignment.toLlvm() }, &o.builder);1397 try attributes.addFnAttr(.{ .alignstack = stack_alignment.toLlvm() }, &o.builder);
1397 try attributes.addFnAttr(.@"noinline", &o.builder);1398 try attributes.addFnAttr(.@"noinline", &o.builder);
...@@ -1399,7 +1400,7 @@ pub const Object = struct {...@@ -1399,7 +1400,7 @@ pub const Object = struct {
1399 _ = try attributes.removeFnAttr(.alignstack);1400 _ = try attributes.removeFnAttr(.alignstack);
1400 }1401 }
14011402
1402 if (func.analysis(ip).is_cold) {1403 if (func_analysis.is_cold) {
1403 try attributes.addFnAttr(.cold, &o.builder);1404 try attributes.addFnAttr(.cold, &o.builder);
1404 } else {1405 } else {
1405 _ = try attributes.removeFnAttr(.cold);1406 _ = try attributes.removeFnAttr(.cold);
...@@ -2403,7 +2404,7 @@ pub const Object = struct {...@@ -2403,7 +2404,7 @@ pub const Object = struct {
2403 defer gpa.free(name);2404 defer gpa.free(name);
24042405
2405 if (zcu.typeToPackedStruct(ty)) |struct_type| {2406 if (zcu.typeToPackedStruct(ty)) |struct_type| {
2406 const backing_int_ty = struct_type.backingIntType(ip).*;2407 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
2407 if (backing_int_ty != .none) {2408 if (backing_int_ty != .none) {
2408 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);2409 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);
2409 const builder_name = try o.builder.metadataString(name);2410 const builder_name = try o.builder.metadataString(name);
...@@ -2615,7 +2616,7 @@ pub const Object = struct {...@@ -2615,7 +2616,7 @@ pub const Object = struct {
2615 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;2616 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
26162617
2617 const field_size = Type.fromInterned(field_ty).abiSize(pt);2618 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) {
2619 .@"packed" => .none,2620 .@"packed" => .none,
2620 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),2621 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),
2621 };2622 };
...@@ -3303,7 +3304,7 @@ pub const Object = struct {...@@ -3303,7 +3304,7 @@ pub const Object = struct {
3303 const struct_type = ip.loadStructType(t.toIntern());3304 const struct_type = ip.loadStructType(t.toIntern());
33043305
3305 if (struct_type.layout == .@"packed") {3306 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)));
3307 try o.type_map.put(o.gpa, t.toIntern(), int_ty);3308 try o.type_map.put(o.gpa, t.toIntern(), int_ty);
3308 return int_ty;3309 return int_ty;
3309 }3310 }
...@@ -3346,7 +3347,7 @@ pub const Object = struct {...@@ -3346,7 +3347,7 @@ pub const Object = struct {
3346 // This is a zero-bit field. If there are runtime bits after this field,3347 // This is a zero-bit field. If there are runtime bits after this field,
3347 // map to the next LLVM field (which we know exists): otherwise, don't3348 // map to the next LLVM field (which we know exists): otherwise, don't
3348 // map the field, indicating it's at the end of the struct.3349 // 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)) {
3350 try o.struct_field_map.put(o.gpa, .{3351 try o.struct_field_map.put(o.gpa, .{
3351 .struct_ty = t.toIntern(),3352 .struct_ty = t.toIntern(),
3352 .field_index = field_index,3353 .field_index = field_index,
...@@ -3450,7 +3451,7 @@ pub const Object = struct {...@@ -3450,7 +3451,7 @@ pub const Object = struct {
3450 const union_obj = ip.loadUnionType(t.toIntern());3451 const union_obj = ip.loadUnionType(t.toIntern());
3451 const layout = pt.getUnionLayout(union_obj);3452 const layout = pt.getUnionLayout(union_obj);
34523453
3453 if (union_obj.flagsPtr(ip).layout == .@"packed") {3454 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
3454 const int_ty = try o.builder.intType(@intCast(t.bitSize(pt)));3455 const int_ty = try o.builder.intType(@intCast(t.bitSize(pt)));
3455 try o.type_map.put(o.gpa, t.toIntern(), int_ty);3456 try o.type_map.put(o.gpa, t.toIntern(), int_ty);
3456 return int_ty;3457 return int_ty;
...@@ -3697,7 +3698,7 @@ pub const Object = struct {...@@ -3697,7 +3698,7 @@ pub const Object = struct {
3697 if (layout.payload_size == 0) return o.lowerValue(un.tag);3698 if (layout.payload_size == 0) return o.lowerValue(un.tag);
36983699
3699 const union_obj = mod.typeToUnion(ty).?;3700 const union_obj = mod.typeToUnion(ty).?;
3700 const container_layout = union_obj.getLayout(ip);3701 const container_layout = union_obj.flagsUnordered(ip).layout;
37013702
3702 assert(container_layout == .@"packed");3703 assert(container_layout == .@"packed");
37033704
...@@ -4205,7 +4206,7 @@ pub const Object = struct {...@@ -4205,7 +4206,7 @@ pub const Object = struct {
4205 if (layout.payload_size == 0) return o.lowerValue(un.tag);4206 if (layout.payload_size == 0) return o.lowerValue(un.tag);
42064207
4207 const union_obj = mod.typeToUnion(ty).?;4208 const union_obj = mod.typeToUnion(ty).?;
4208 const container_layout = union_obj.getLayout(ip);4209 const container_layout = union_obj.flagsUnordered(ip).layout;
42094210
4210 var need_unnamed = false;4211 var need_unnamed = false;
4211 const payload = if (un.tag != .none) p: {4212 const payload = if (un.tag != .none) p: {
...@@ -10045,7 +10046,7 @@ pub const FuncGen = struct {...@@ -10045,7 +10046,7 @@ pub const FuncGen = struct {
10045 },10046 },
10046 .Struct => {10047 .Struct => {
10047 if (mod.typeToPackedStruct(result_ty)) |struct_type| {10048 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);
10049 assert(backing_int_ty != .none);10050 assert(backing_int_ty != .none);
10050 const big_bits = Type.fromInterned(backing_int_ty).bitSize(pt);10051 const big_bits = Type.fromInterned(backing_int_ty).bitSize(pt);
10051 const int_ty = try o.builder.intType(@intCast(big_bits));10052 const int_ty = try o.builder.intType(@intCast(big_bits));
...@@ -10155,7 +10156,7 @@ pub const FuncGen = struct {...@@ -10155,7 +10156,7 @@ pub const FuncGen = struct {
10155 const layout = union_ty.unionGetLayout(pt);10156 const layout = union_ty.unionGetLayout(pt);
10156 const union_obj = mod.typeToUnion(union_ty).?;10157 const union_obj = mod.typeToUnion(union_ty).?;
1015710158
10158 if (union_obj.getLayout(ip) == .@"packed") {10159 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
10159 const big_bits = union_ty.bitSize(pt);10160 const big_bits = union_ty.bitSize(pt);
10160 const int_llvm_ty = try o.builder.intType(@intCast(big_bits));10161 const int_llvm_ty = try o.builder.intType(@intCast(big_bits));
10161 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);10162 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...@@ -11281,7 +11282,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E
11281 .struct_type => {11282 .struct_type => {
11282 const struct_type = ip.loadStructType(return_type.toIntern());11283 const struct_type = ip.loadStructType(return_type.toIntern());
11283 assert(struct_type.haveLayout(ip));11284 assert(struct_type.haveLayout(ip));
11284 const size: u64 = struct_type.size(ip).*;11285 const size: u64 = struct_type.sizeUnordered(ip);
11285 assert((std.math.divCeil(u64, size, 8) catch unreachable) == types_index);11286 assert((std.math.divCeil(u64, size, 8) catch unreachable) == types_index);
11286 if (size % 8 > 0) {11287 if (size % 8 > 0) {
11287 types_buffer[types_index - 1] = try o.builder.intType(@intCast(size % 8 * 8));11288 types_buffer[types_index - 1] = try o.builder.intType(@intCast(size % 8 * 8));
...@@ -11587,7 +11588,7 @@ const ParamTypeIterator = struct {...@@ -11587,7 +11588,7 @@ const ParamTypeIterator = struct {
11587 .struct_type => {11588 .struct_type => {
11588 const struct_type = ip.loadStructType(ty.toIntern());11589 const struct_type = ip.loadStructType(ty.toIntern());
11589 assert(struct_type.haveLayout(ip));11590 assert(struct_type.haveLayout(ip));
11590 const size: u64 = struct_type.size(ip).*;11591 const size: u64 = struct_type.sizeUnordered(ip);
11591 assert((std.math.divCeil(u64, size, 8) catch unreachable) == types_index);11592 assert((std.math.divCeil(u64, size, 8) catch unreachable) == types_index);
11592 if (size % 8 > 0) {11593 if (size % 8 > 0) {
11593 types_buffer[types_index - 1] =11594 types_buffer[types_index - 1] =
src/codegen/spirv.zig+3-3
...@@ -1463,7 +1463,7 @@ const DeclGen = struct {...@@ -1463,7 +1463,7 @@ const DeclGen = struct {
1463 const ip = &mod.intern_pool;1463 const ip = &mod.intern_pool;
1464 const union_obj = mod.typeToUnion(ty).?;1464 const union_obj = mod.typeToUnion(ty).?;
14651465
1466 if (union_obj.getLayout(ip) == .@"packed") {1466 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
1467 return self.todo("packed union types", .{});1467 return self.todo("packed union types", .{});
1468 }1468 }
14691469
...@@ -1735,7 +1735,7 @@ const DeclGen = struct {...@@ -1735,7 +1735,7 @@ const DeclGen = struct {
1735 };1735 };
17361736
1737 if (struct_type.layout == .@"packed") {1737 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);
1739 }1739 }
17401740
1741 var member_types = std.ArrayList(IdRef).init(self.gpa);1741 var member_types = std.ArrayList(IdRef).init(self.gpa);
...@@ -5081,7 +5081,7 @@ const DeclGen = struct {...@@ -5081,7 +5081,7 @@ const DeclGen = struct {
5081 const union_ty = mod.typeToUnion(ty).?;5081 const union_ty = mod.typeToUnion(ty).?;
5082 const tag_ty = Type.fromInterned(union_ty.enum_tag_ty);5082 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") {
5085 unreachable; // TODO5085 unreachable; // TODO
5086 }5086 }
50875087
src/link/Coff.zig+1-1
...@@ -1156,7 +1156,7 @@ pub fn updateFunc(self: *Coff, pt: Zcu.PerThread, func_index: InternPool.Index,...@@ -1156,7 +1156,7 @@ pub fn updateFunc(self: *Coff, pt: Zcu.PerThread, func_index: InternPool.Index,
1156 const code = switch (res) {1156 const code = switch (res) {
1157 .ok => code_buffer.items,1157 .ok => code_buffer.items,
1158 .fail => |em| {1158 .fail => |em| {
1159 func.analysis(&mod.intern_pool).state = .codegen_failure;1159 func.setAnalysisState(&mod.intern_pool, .codegen_failure);
1160 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);1160 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
1161 return;1161 return;
1162 },1162 },
src/link/Elf/ZigObject.zig+1-1
...@@ -1093,7 +1093,7 @@ pub fn updateFunc(...@@ -1093,7 +1093,7 @@ pub fn updateFunc(
1093 const code = switch (res) {1093 const code = switch (res) {
1094 .ok => code_buffer.items,1094 .ok => code_buffer.items,
1095 .fail => |em| {1095 .fail => |em| {
1096 func.analysis(&mod.intern_pool).state = .codegen_failure;1096 func.setAnalysisState(&mod.intern_pool, .codegen_failure);
1097 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);1097 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
1098 return;1098 return;
1099 },1099 },
src/link/MachO/ZigObject.zig+1-1
...@@ -699,7 +699,7 @@ pub fn updateFunc(...@@ -699,7 +699,7 @@ pub fn updateFunc(
699 const code = switch (res) {699 const code = switch (res) {
700 .ok => code_buffer.items,700 .ok => code_buffer.items,
701 .fail => |em| {701 .fail => |em| {
702 func.analysis(&mod.intern_pool).state = .codegen_failure;702 func.setAnalysisState(&mod.intern_pool, .codegen_failure);
703 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);703 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
704 return;704 return;
705 },705 },
src/link/Plan9.zig+1-1
...@@ -449,7 +449,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,...@@ -449,7 +449,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
449 const code = switch (res) {449 const code = switch (res) {
450 .ok => try code_buffer.toOwnedSlice(),450 .ok => try code_buffer.toOwnedSlice(),
451 .fail => |em| {451 .fail => |em| {
452 func.analysis(&mod.intern_pool).state = .codegen_failure;452 func.setAnalysisState(&mod.intern_pool, .codegen_failure);
453 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);453 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
454 return;454 return;
455 },455 },
src/link/Wasm/ZigObject.zig+1-1
...@@ -1051,7 +1051,7 @@ fn setupErrorsLen(zig_object: *ZigObject, wasm_file: *Wasm) !void {...@@ -1051,7 +1051,7 @@ fn setupErrorsLen(zig_object: *ZigObject, wasm_file: *Wasm) !void {
1051 const gpa = wasm_file.base.comp.gpa;1051 const gpa = wasm_file.base.comp.gpa;
1052 const sym_index = zig_object.findGlobalSymbol("__zig_errors_len") orelse return;1052 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;
1055 // overwrite existing atom if it already exists (maybe the error set has increased)1055 // overwrite existing atom if it already exists (maybe the error set has increased)
1056 // if not, allcoate a new atom.1056 // if not, allcoate a new atom.
1057 const atom_index = if (wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = sym_index })) |index| blk: {1057 const atom_index = if (wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = sym_index })) |index| blk: {