authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-14 17:32:51-07:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-07-14 17:32:51-07:00
logd404d8a3637bc30dffc736e5fa1a68b8af0e19cb
tree2f668bf2a185fe788fa20753ae6d8462778c4204
parent464537db62e1d4ca6bc1357135b0f6c451e48c17
parentad55fb7a209e1b9d41b8d4f1d3e48211ff20d2f9
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #20593 from jacobly0/more-races

InternPool: fix more races

31 files changed, 998 insertions(+), 516 deletions(-)

src/Air/types_resolved.zig+3-3
......@@ -501,8 +501,8 @@ fn checkType(ty: Type, zcu: *Zcu) bool {
501501 .struct_type => {
502502 const struct_obj = zcu.typeToStruct(ty).?;
503503 return switch (struct_obj.layout) {
504 .@"packed" => struct_obj.backingIntType(ip).* != .none,
505 .auto, .@"extern" => struct_obj.flagsPtr(ip).fully_resolved,
504 .@"packed" => struct_obj.backingIntTypeUnordered(ip) != .none,
505 .auto, .@"extern" => struct_obj.flagsUnordered(ip).fully_resolved,
506506 };
507507 },
508508 .anon_struct_type => |tuple| {
......@@ -516,6 +516,6 @@ fn checkType(ty: Type, zcu: *Zcu) bool {
516516 },
517517 else => unreachable,
518518 },
519 .Union => return zcu.typeToUnion(ty).?.flagsPtr(ip).status == .fully_resolved,
519 .Union => return zcu.typeToUnion(ty).?.flagsUnordered(ip).status == .fully_resolved,
520520 };
521521}
src/Compilation.zig+165-89
......@@ -101,7 +101,15 @@ link_error_flags: link.File.ErrorFlags = .{},
101101link_errors: std.ArrayListUnmanaged(link.File.ErrorMsg) = .{},
102102lld_errors: std.ArrayListUnmanaged(LldError) = .{},
103103
104work_queue: std.fifo.LinearFifo(Job, .Dynamic),
104work_queues: [
105 len: {
106 var len: usize = 0;
107 for (std.enums.values(Job.Tag)) |tag| {
108 len = @max(Job.stage(tag) + 1, len);
109 }
110 break :len len;
111 }
112]std.fifo.LinearFifo(Job, .Dynamic),
105113
106114codegen_work: if (InternPool.single_threaded) void else struct {
107115 mutex: std.Thread.Mutex,
......@@ -370,6 +378,20 @@ const Job = union(enum) {
370378
371379 /// The value is the index into `system_libs`.
372380 windows_import_lib: usize,
381
382 const Tag = @typeInfo(Job).Union.tag_type.?;
383 fn stage(tag: Tag) usize {
384 return switch (tag) {
385 // Prioritize functions so that codegen can get to work on them on a
386 // separate thread, while Sema goes back to its own work.
387 .resolve_type_fully, .analyze_func, .codegen_func => 0,
388 else => 1,
389 };
390 }
391 comptime {
392 // Job dependencies
393 assert(stage(.resolve_type_fully) <= stage(.codegen_func));
394 }
373395};
374396
375397const CodegenJob = union(enum) {
......@@ -1452,7 +1474,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
14521474 .emit_asm = options.emit_asm,
14531475 .emit_llvm_ir = options.emit_llvm_ir,
14541476 .emit_llvm_bc = options.emit_llvm_bc,
1455 .work_queue = std.fifo.LinearFifo(Job, .Dynamic).init(gpa),
1477 .work_queues = .{std.fifo.LinearFifo(Job, .Dynamic).init(gpa)} ** @typeInfo(std.meta.FieldType(Compilation, .work_queues)).Array.len,
14561478 .codegen_work = if (InternPool.single_threaded) {} else .{
14571479 .mutex = .{},
14581480 .cond = .{},
......@@ -1760,12 +1782,12 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
17601782 if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable;
17611783
17621784 if (glibc.needsCrtiCrtn(target)) {
1763 try comp.work_queue.write(&[_]Job{
1785 try comp.queueJobs(&[_]Job{
17641786 .{ .glibc_crt_file = .crti_o },
17651787 .{ .glibc_crt_file = .crtn_o },
17661788 });
17671789 }
1768 try comp.work_queue.write(&[_]Job{
1790 try comp.queueJobs(&[_]Job{
17691791 .{ .glibc_crt_file = .scrt1_o },
17701792 .{ .glibc_crt_file = .libc_nonshared_a },
17711793 .{ .glibc_shared_objects = {} },
......@@ -1774,14 +1796,13 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
17741796 if (comp.wantBuildMuslFromSource()) {
17751797 if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable;
17761798
1777 try comp.work_queue.ensureUnusedCapacity(6);
17781799 if (musl.needsCrtiCrtn(target)) {
1779 comp.work_queue.writeAssumeCapacity(&[_]Job{
1800 try comp.queueJobs(&[_]Job{
17801801 .{ .musl_crt_file = .crti_o },
17811802 .{ .musl_crt_file = .crtn_o },
17821803 });
17831804 }
1784 comp.work_queue.writeAssumeCapacity(&[_]Job{
1805 try comp.queueJobs(&[_]Job{
17851806 .{ .musl_crt_file = .crt1_o },
17861807 .{ .musl_crt_file = .scrt1_o },
17871808 .{ .musl_crt_file = .rcrt1_o },
......@@ -1795,15 +1816,12 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
17951816 if (comp.wantBuildWasiLibcFromSource()) {
17961817 if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable;
17971818
1798 // worst-case we need all components
1799 try comp.work_queue.ensureUnusedCapacity(comp.wasi_emulated_libs.len + 2);
1800
18011819 for (comp.wasi_emulated_libs) |crt_file| {
1802 comp.work_queue.writeItemAssumeCapacity(.{
1820 try comp.queueJob(.{
18031821 .wasi_libc_crt_file = crt_file,
18041822 });
18051823 }
1806 comp.work_queue.writeAssumeCapacity(&[_]Job{
1824 try comp.queueJobs(&[_]Job{
18071825 .{ .wasi_libc_crt_file = wasi_libc.execModelCrtFile(comp.config.wasi_exec_model) },
18081826 .{ .wasi_libc_crt_file = .libc_a },
18091827 });
......@@ -1813,9 +1831,10 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18131831 if (!std.zig.target.canBuildLibC(target)) return error.LibCUnavailable;
18141832
18151833 const crt_job: Job = .{ .mingw_crt_file = if (is_dyn_lib) .dllcrt2_o else .crt2_o };
1816 try comp.work_queue.ensureUnusedCapacity(2);
1817 comp.work_queue.writeItemAssumeCapacity(.{ .mingw_crt_file = .mingw32_lib });
1818 comp.work_queue.writeItemAssumeCapacity(crt_job);
1834 try comp.queueJobs(&.{
1835 .{ .mingw_crt_file = .mingw32_lib },
1836 crt_job,
1837 });
18191838
18201839 // When linking mingw-w64 there are some import libs we always need.
18211840 for (mingw.always_link_libs) |name| {
......@@ -1829,20 +1848,19 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18291848 // Generate Windows import libs.
18301849 if (target.os.tag == .windows) {
18311850 const count = comp.system_libs.count();
1832 try comp.work_queue.ensureUnusedCapacity(count);
18331851 for (0..count) |i| {
1834 comp.work_queue.writeItemAssumeCapacity(.{ .windows_import_lib = i });
1852 try comp.queueJob(.{ .windows_import_lib = i });
18351853 }
18361854 }
18371855 if (comp.wantBuildLibUnwindFromSource()) {
1838 try comp.work_queue.writeItem(.{ .libunwind = {} });
1856 try comp.queueJob(.{ .libunwind = {} });
18391857 }
18401858 if (build_options.have_llvm and is_exe_or_dyn_lib and comp.config.link_libcpp) {
1841 try comp.work_queue.writeItem(.libcxx);
1842 try comp.work_queue.writeItem(.libcxxabi);
1859 try comp.queueJob(.libcxx);
1860 try comp.queueJob(.libcxxabi);
18431861 }
18441862 if (build_options.have_llvm and comp.config.any_sanitize_thread) {
1845 try comp.work_queue.writeItem(.libtsan);
1863 try comp.queueJob(.libtsan);
18461864 }
18471865
18481866 if (target.isMinGW() and comp.config.any_non_single_threaded) {
......@@ -1872,7 +1890,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
18721890 if (!comp.skip_linker_dependencies and is_exe_or_dyn_lib and
18731891 !comp.config.link_libc and capable_of_building_zig_libc)
18741892 {
1875 try comp.work_queue.writeItem(.{ .zig_libc = {} });
1893 try comp.queueJob(.{ .zig_libc = {} });
18761894 }
18771895 }
18781896
......@@ -1883,7 +1901,7 @@ pub fn destroy(comp: *Compilation) void {
18831901 if (comp.bin_file) |lf| lf.destroy();
18841902 if (comp.module) |zcu| zcu.deinit();
18851903 comp.cache_use.deinit();
1886 comp.work_queue.deinit();
1904 for (comp.work_queues) |work_queue| work_queue.deinit();
18871905 if (!InternPool.single_threaded) comp.codegen_work.queue.deinit();
18881906 comp.c_object_work_queue.deinit();
18891907 if (!build_options.only_core_functionality) {
......@@ -2199,13 +2217,13 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
21992217 }
22002218 }
22012219
2202 try comp.work_queue.writeItem(.{ .analyze_mod = std_mod });
2220 try comp.queueJob(.{ .analyze_mod = std_mod });
22032221 if (comp.config.is_test) {
2204 try comp.work_queue.writeItem(.{ .analyze_mod = zcu.main_mod });
2222 try comp.queueJob(.{ .analyze_mod = zcu.main_mod });
22052223 }
22062224
22072225 if (zcu.root_mod.deps.get("compiler_rt")) |compiler_rt_mod| {
2208 try comp.work_queue.writeItem(.{ .analyze_mod = compiler_rt_mod });
2226 try comp.queueJob(.{ .analyze_mod = compiler_rt_mod });
22092227 }
22102228 }
22112229
......@@ -2852,11 +2870,7 @@ pub fn makeBinFileWritable(comp: *Compilation) !void {
28522870
28532871const Header = extern struct {
28542872 intern_pool: extern struct {
2855 //items_len: u32,
2856 //extra_len: u32,
2857 //limbs_len: u32,
2858 //string_bytes_len: u32,
2859 //tracked_insts_len: u32,
2873 thread_count: u32,
28602874 src_hash_deps_len: u32,
28612875 decl_val_deps_len: u32,
28622876 namespace_deps_len: u32,
......@@ -2864,28 +2878,39 @@ const Header = extern struct {
28642878 first_dependency_len: u32,
28652879 dep_entries_len: u32,
28662880 free_dep_entries_len: u32,
2867 //files_len: u32,
28682881 },
2882
2883 const PerThread = extern struct {
2884 intern_pool: extern struct {
2885 items_len: u32,
2886 extra_len: u32,
2887 limbs_len: u32,
2888 string_bytes_len: u32,
2889 tracked_insts_len: u32,
2890 files_len: u32,
2891 },
2892 };
28692893};
28702894
28712895/// Note that all state that is included in the cache hash namespace is *not*
28722896/// saved, such as the target and most CLI flags. A cache hit will only occur
28732897/// when subsequent compiler invocations use the same set of flags.
28742898pub fn saveState(comp: *Compilation) !void {
2875 var bufs_list: [21]std.posix.iovec_const = undefined;
2876 var bufs_len: usize = 0;
2877
28782899 const lf = comp.bin_file orelse return;
28792900
2901 const gpa = comp.gpa;
2902
2903 var bufs = std.ArrayList(std.posix.iovec_const).init(gpa);
2904 defer bufs.deinit();
2905
2906 var pt_headers = std.ArrayList(Header.PerThread).init(gpa);
2907 defer pt_headers.deinit();
2908
28802909 if (comp.module) |zcu| {
28812910 const ip = &zcu.intern_pool;
28822911 const header: Header = .{
28832912 .intern_pool = .{
2884 //.items_len = @intCast(ip.items.len),
2885 //.extra_len = @intCast(ip.extra.items.len),
2886 //.limbs_len = @intCast(ip.limbs.items.len),
2887 //.string_bytes_len = @intCast(ip.string_bytes.items.len),
2888 //.tracked_insts_len = @intCast(ip.tracked_insts.count()),
2913 .thread_count = @intCast(ip.locals.len),
28892914 .src_hash_deps_len = @intCast(ip.src_hash_deps.count()),
28902915 .decl_val_deps_len = @intCast(ip.decl_val_deps.count()),
28912916 .namespace_deps_len = @intCast(ip.namespace_deps.count()),
......@@ -2893,38 +2918,54 @@ pub fn saveState(comp: *Compilation) !void {
28932918 .first_dependency_len = @intCast(ip.first_dependency.count()),
28942919 .dep_entries_len = @intCast(ip.dep_entries.items.len),
28952920 .free_dep_entries_len = @intCast(ip.free_dep_entries.items.len),
2896 //.files_len = @intCast(ip.files.entries.len),
28972921 },
28982922 };
2899 addBuf(&bufs_list, &bufs_len, mem.asBytes(&header));
2900 //addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.limbs.items));
2901 //addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.extra.items));
2902 //addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.items.items(.data)));
2903 //addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.items.items(.tag)));
2904 //addBuf(&bufs_list, &bufs_len, ip.string_bytes.items);
2905 //addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.tracked_insts.keys()));
2906
2907 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.src_hash_deps.keys()));
2908 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.src_hash_deps.values()));
2909 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.decl_val_deps.keys()));
2910 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.decl_val_deps.values()));
2911 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.namespace_deps.keys()));
2912 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.namespace_deps.values()));
2913 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.namespace_name_deps.keys()));
2914 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.namespace_name_deps.values()));
2915
2916 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.first_dependency.keys()));
2917 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.first_dependency.values()));
2918 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.dep_entries.items));
2919 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.free_dep_entries.items));
2920
2921 //addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.files.keys()));
2922 //addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.files.values()));
2923
2924 // TODO: compilation errors
2925 // TODO: namespaces
2926 // TODO: decls
2927 // TODO: linker state
2923
2924 try pt_headers.ensureTotalCapacityPrecise(header.intern_pool.thread_count);
2925 for (ip.locals) |*local| pt_headers.appendAssumeCapacity(.{
2926 .intern_pool = .{
2927 .items_len = @intCast(local.mutate.items.len),
2928 .extra_len = @intCast(local.mutate.extra.len),
2929 .limbs_len = @intCast(local.mutate.limbs.len),
2930 .string_bytes_len = @intCast(local.mutate.strings.len),
2931 .tracked_insts_len = @intCast(local.mutate.tracked_insts.len),
2932 .files_len = @intCast(local.mutate.files.len),
2933 },
2934 });
2935
2936 try bufs.ensureTotalCapacityPrecise(14 + 8 * pt_headers.items.len);
2937 addBuf(&bufs, mem.asBytes(&header));
2938 addBuf(&bufs, mem.sliceAsBytes(pt_headers.items));
2939
2940 addBuf(&bufs, mem.sliceAsBytes(ip.src_hash_deps.keys()));
2941 addBuf(&bufs, mem.sliceAsBytes(ip.src_hash_deps.values()));
2942 addBuf(&bufs, mem.sliceAsBytes(ip.decl_val_deps.keys()));
2943 addBuf(&bufs, mem.sliceAsBytes(ip.decl_val_deps.values()));
2944 addBuf(&bufs, mem.sliceAsBytes(ip.namespace_deps.keys()));
2945 addBuf(&bufs, mem.sliceAsBytes(ip.namespace_deps.values()));
2946 addBuf(&bufs, mem.sliceAsBytes(ip.namespace_name_deps.keys()));
2947 addBuf(&bufs, mem.sliceAsBytes(ip.namespace_name_deps.values()));
2948
2949 addBuf(&bufs, mem.sliceAsBytes(ip.first_dependency.keys()));
2950 addBuf(&bufs, mem.sliceAsBytes(ip.first_dependency.values()));
2951 addBuf(&bufs, mem.sliceAsBytes(ip.dep_entries.items));
2952 addBuf(&bufs, mem.sliceAsBytes(ip.free_dep_entries.items));
2953
2954 for (ip.locals, pt_headers.items) |*local, pt_header| {
2955 addBuf(&bufs, mem.sliceAsBytes(local.shared.limbs.view().items(.@"0")[0..pt_header.intern_pool.limbs_len]));
2956 addBuf(&bufs, mem.sliceAsBytes(local.shared.extra.view().items(.@"0")[0..pt_header.intern_pool.extra_len]));
2957 addBuf(&bufs, mem.sliceAsBytes(local.shared.items.view().items(.data)[0..pt_header.intern_pool.items_len]));
2958 addBuf(&bufs, mem.sliceAsBytes(local.shared.items.view().items(.tag)[0..pt_header.intern_pool.items_len]));
2959 addBuf(&bufs, local.shared.strings.view().items(.@"0")[0..pt_header.intern_pool.string_bytes_len]);
2960 addBuf(&bufs, mem.sliceAsBytes(local.shared.tracked_insts.view().items(.@"0")[0..pt_header.intern_pool.tracked_insts_len]));
2961 addBuf(&bufs, mem.sliceAsBytes(local.shared.files.view().items(.bin_digest)[0..pt_header.intern_pool.files_len]));
2962 addBuf(&bufs, mem.sliceAsBytes(local.shared.files.view().items(.root_decl)[0..pt_header.intern_pool.files_len]));
2963 }
2964
2965 //// TODO: compilation errors
2966 //// TODO: namespaces
2967 //// TODO: decls
2968 //// TODO: linker state
29282969 }
29292970 var basename_buf: [255]u8 = undefined;
29302971 const basename = std.fmt.bufPrint(&basename_buf, "{s}.zcs", .{
......@@ -2938,20 +2979,14 @@ pub fn saveState(comp: *Compilation) !void {
29382979 // the previous incremental compilation state.
29392980 var af = try lf.emit.directory.handle.atomicFile(basename, .{});
29402981 defer af.deinit();
2941 try af.file.pwritevAll(bufs_list[0..bufs_len], 0);
2982 try af.file.pwritevAll(bufs.items, 0);
29422983 try af.finish();
29432984}
29442985
2945fn addBuf(bufs_list: []std.posix.iovec_const, bufs_len: *usize, buf: []const u8) void {
2986fn addBuf(list: *std.ArrayList(std.posix.iovec_const), buf: []const u8) void {
29462987 // Even when len=0, the undefined pointer might cause EFAULT.
29472988 if (buf.len == 0) return;
2948
2949 const i = bufs_len.*;
2950 bufs_len.* = i + 1;
2951 bufs_list[i] = .{
2952 .base = buf.ptr,
2953 .len = buf.len,
2954 };
2989 list.appendAssumeCapacity(.{ .base = buf.ptr, .len = buf.len });
29552990}
29562991
29572992/// This function is temporally single-threaded.
......@@ -3011,7 +3046,7 @@ pub fn totalErrorCount(comp: *Compilation) u32 {
30113046 }
30123047 }
30133048
3014 if (zcu.intern_pool.global_error_set.mutate.list.len > zcu.error_limit) {
3049 if (zcu.intern_pool.global_error_set.getNamesFromMainThread().len > zcu.error_limit) {
30153050 total += 1;
30163051 }
30173052 }
......@@ -3095,6 +3130,39 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
30953130 for (zcu.failed_embed_files.values()) |error_msg| {
30963131 try addModuleErrorMsg(zcu, &bundle, error_msg.*, &all_references);
30973132 }
3133 {
3134 const SortOrder = struct {
3135 zcu: *Zcu,
3136 err: *?Error,
3137
3138 const Error = @typeInfo(
3139 @typeInfo(@TypeOf(Zcu.SrcLoc.span)).Fn.return_type.?,
3140 ).ErrorUnion.error_set;
3141
3142 pub fn lessThan(ctx: @This(), lhs_index: usize, rhs_index: usize) bool {
3143 if (ctx.err.*) |_| return lhs_index < rhs_index;
3144 const errors = ctx.zcu.failed_analysis.values();
3145 const lhs_src_loc = errors[lhs_index].src_loc.upgrade(ctx.zcu);
3146 const rhs_src_loc = errors[rhs_index].src_loc.upgrade(ctx.zcu);
3147 return if (lhs_src_loc.file_scope != rhs_src_loc.file_scope) std.mem.order(
3148 u8,
3149 lhs_src_loc.file_scope.sub_file_path,
3150 rhs_src_loc.file_scope.sub_file_path,
3151 ).compare(.lt) else (lhs_src_loc.span(ctx.zcu.gpa) catch |e| {
3152 ctx.err.* = e;
3153 return lhs_index < rhs_index;
3154 }).main < (rhs_src_loc.span(ctx.zcu.gpa) catch |e| {
3155 ctx.err.* = e;
3156 return lhs_index < rhs_index;
3157 }).main;
3158 }
3159 };
3160 var err: ?SortOrder.Error = null;
3161 // This leaves `zcu.failed_analysis` an invalid state, but we do not
3162 // need lookups anymore anyway.
3163 zcu.failed_analysis.entries.sort(SortOrder{ .zcu = zcu, .err = &err });
3164 if (err) |e| return e;
3165 }
30983166 for (zcu.failed_analysis.keys(), zcu.failed_analysis.values()) |anal_unit, error_msg| {
30993167 const decl_index = switch (anal_unit.unwrap()) {
31003168 .decl => |d| d,
......@@ -3140,7 +3208,7 @@ pub fn getAllErrorsAlloc(comp: *Compilation) !ErrorBundle {
31403208 try addModuleErrorMsg(zcu, &bundle, value.*, &all_references);
31413209 }
31423210
3143 const actual_error_count = zcu.intern_pool.global_error_set.mutate.list.len;
3211 const actual_error_count = zcu.intern_pool.global_error_set.getNamesFromMainThread().len;
31443212 if (actual_error_count > zcu.error_limit) {
31453213 try bundle.addRootErrorMessage(.{
31463214 .msg = try bundle.printString("ZCU used more errors than possible: used {d}, max {d}", .{
......@@ -3543,18 +3611,18 @@ fn performAllTheWorkInner(
35433611 comp.codegen_work.cond.signal();
35443612 };
35453613
3546 while (true) {
3547 if (comp.work_queue.readItem()) |work_item| {
3548 try processOneJob(@intFromEnum(Zcu.PerThread.Id.main), comp, work_item, main_progress_node);
3549 continue;
3550 }
3614 work: while (true) {
3615 for (&comp.work_queues) |*work_queue| if (work_queue.readItem()) |job| {
3616 try processOneJob(@intFromEnum(Zcu.PerThread.Id.main), comp, job, main_progress_node);
3617 continue :work;
3618 };
35513619 if (comp.module) |zcu| {
35523620 // If there's no work queued, check if there's anything outdated
35533621 // which we need to work on, and queue it if so.
35543622 if (try zcu.findOutdatedToAnalyze()) |outdated| {
35553623 switch (outdated.unwrap()) {
3556 .decl => |decl| try comp.work_queue.writeItem(.{ .analyze_decl = decl }),
3557 .func => |func| try comp.work_queue.writeItem(.{ .analyze_func = func }),
3624 .decl => |decl| try comp.queueJob(.{ .analyze_decl = decl }),
3625 .func => |func| try comp.queueJob(.{ .analyze_func = func }),
35583626 }
35593627 continue;
35603628 }
......@@ -3575,6 +3643,14 @@ fn performAllTheWorkInner(
35753643
35763644const JobError = Allocator.Error;
35773645
3646pub fn queueJob(comp: *Compilation, job: Job) !void {
3647 try comp.work_queues[Job.stage(job)].writeItem(job);
3648}
3649
3650pub fn queueJobs(comp: *Compilation, jobs: []const Job) !void {
3651 for (jobs) |job| try comp.queueJob(job);
3652}
3653
35783654fn processOneJob(tid: usize, comp: *Compilation, job: Job, prog_node: std.Progress.Node) JobError!void {
35793655 switch (job) {
35803656 .codegen_decl => |decl_index| {
......@@ -6478,7 +6554,7 @@ pub fn addLinkLib(comp: *Compilation, lib_name: []const u8) !void {
64786554 };
64796555 const target = comp.root_mod.resolved_target.result;
64806556 if (target.os.tag == .windows and target.ofmt != .c) {
6481 try comp.work_queue.writeItem(.{
6557 try comp.queueJob(.{
64826558 .windows_import_lib = comp.system_libs.count() - 1,
64836559 });
64846560 }
src/InternPool.zig+584-153
......@@ -147,8 +147,6 @@ pub fn trackZir(
147147 }
148148 defer shard.mutate.tracked_inst_map.len += 1;
149149 const local = ip.getLocal(tid);
150 local.mutate.tracked_insts.mutex.lock();
151 defer local.mutate.tracked_insts.mutex.unlock();
152150 const list = local.getMutableTrackedInsts(gpa);
153151 try list.ensureUnusedCapacity(1);
154152 const map_header = map.header().*;
......@@ -418,10 +416,10 @@ const Local = struct {
418416 arena: std.heap.ArenaAllocator.State,
419417
420418 items: ListMutate,
421 extra: MutexListMutate,
419 extra: ListMutate,
422420 limbs: ListMutate,
423421 strings: ListMutate,
424 tracked_insts: MutexListMutate,
422 tracked_insts: ListMutate,
425423 files: ListMutate,
426424 maps: ListMutate,
427425
......@@ -471,20 +469,12 @@ const Local = struct {
471469 const Namespaces = List(struct { *[1 << namespaces_bucket_width]Zcu.Namespace });
472470
473471 const ListMutate = struct {
472 mutex: std.Thread.Mutex,
474473 len: u32,
475474
476475 const empty: ListMutate = .{
477 .len = 0,
478 };
479 };
480
481 const MutexListMutate = struct {
482 mutex: std.Thread.Mutex,
483 list: ListMutate,
484
485 const empty: MutexListMutate = .{
486476 .mutex = .{},
487 .list = ListMutate.empty,
477 .len = 0,
488478 };
489479 };
490480
......@@ -694,6 +684,8 @@ const Local = struct {
694684 const new_slice = new_list.view().slice();
695685 inline for (fields) |field| @memcpy(new_slice.items(field)[0..len], old_slice.items(field)[0..len]);
696686 }
687 mutable.mutate.mutex.lock();
688 defer mutable.mutate.mutex.unlock();
697689 mutable.list.release(new_list);
698690 }
699691
......@@ -760,7 +752,7 @@ const Local = struct {
760752 return .{
761753 .gpa = gpa,
762754 .arena = &local.mutate.arena,
763 .mutate = &local.mutate.extra.list,
755 .mutate = &local.mutate.extra,
764756 .list = &local.shared.extra,
765757 };
766758 }
......@@ -802,7 +794,7 @@ const Local = struct {
802794 return .{
803795 .gpa = gpa,
804796 .arena = &local.mutate.arena,
805 .mutate = &local.mutate.tracked_insts.list,
797 .mutate = &local.mutate.tracked_insts,
806798 .list = &local.shared.tracked_insts,
807799 };
808800 }
......@@ -1714,29 +1706,76 @@ pub const Key = union(enum) {
17141706 comptime_args: Index.Slice,
17151707
17161708 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.
1717 pub fn analysis(func: *const Func, ip: *const InternPool) *FuncAnalysis {
1709 fn analysisPtr(func: Func, ip: *InternPool) *FuncAnalysis {
17181710 const extra = ip.getLocalShared(func.tid).extra.acquire();
17191711 return @ptrCast(&extra.view().items(.@"0")[func.analysis_extra_index]);
17201712 }
17211713
1714 pub fn analysisUnordered(func: Func, ip: *const InternPool) FuncAnalysis {
1715 return @atomicLoad(FuncAnalysis, func.analysisPtr(@constCast(ip)), .unordered);
1716 }
1717
1718 pub fn setAnalysisState(func: Func, ip: *InternPool, state: FuncAnalysis.State) void {
1719 const extra_mutex = &ip.getLocal(func.tid).mutate.extra.mutex;
1720 extra_mutex.lock();
1721 defer extra_mutex.unlock();
1722
1723 const analysis_ptr = func.analysisPtr(ip);
1724 var analysis = analysis_ptr.*;
1725 analysis.state = state;
1726 @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release);
1727 }
1728
1729 pub fn setCallsOrAwaitsErrorableFn(func: Func, ip: *InternPool, value: bool) void {
1730 const extra_mutex = &ip.getLocal(func.tid).mutate.extra.mutex;
1731 extra_mutex.lock();
1732 defer extra_mutex.unlock();
1733
1734 const analysis_ptr = func.analysisPtr(ip);
1735 var analysis = analysis_ptr.*;
1736 analysis.calls_or_awaits_errorable_fn = value;
1737 @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release);
1738 }
1739
17221740 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.
1723 pub fn zirBodyInst(func: *const Func, ip: *const InternPool) *TrackedInst.Index {
1741 fn zirBodyInstPtr(func: Func, ip: *InternPool) *TrackedInst.Index {
17241742 const extra = ip.getLocalShared(func.tid).extra.acquire();
17251743 return @ptrCast(&extra.view().items(.@"0")[func.zir_body_inst_extra_index]);
17261744 }
17271745
1746 pub fn zirBodyInstUnordered(func: Func, ip: *const InternPool) TrackedInst.Index {
1747 return @atomicLoad(TrackedInst.Index, func.zirBodyInstPtr(@constCast(ip)), .unordered);
1748 }
1749
17281750 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.
1729 pub fn branchQuota(func: *const Func, ip: *const InternPool) *u32 {
1751 fn branchQuotaPtr(func: Func, ip: *InternPool) *u32 {
17301752 const extra = ip.getLocalShared(func.tid).extra.acquire();
17311753 return &extra.view().items(.@"0")[func.branch_quota_extra_index];
17321754 }
17331755
1756 pub fn branchQuotaUnordered(func: Func, ip: *const InternPool) u32 {
1757 return @atomicLoad(u32, func.branchQuotaPtr(@constCast(ip)), .unordered);
1758 }
1759
1760 pub fn maxBranchQuota(func: Func, ip: *InternPool, new_branch_quota: u32) void {
1761 const extra_mutex = &ip.getLocal(func.tid).mutate.extra.mutex;
1762 extra_mutex.lock();
1763 defer extra_mutex.unlock();
1764
1765 const branch_quota_ptr = func.branchQuotaPtr(ip);
1766 @atomicStore(u32, branch_quota_ptr, @max(branch_quota_ptr.*, new_branch_quota), .release);
1767 }
1768
17341769 /// Returns a pointer that becomes invalid after any additions to the `InternPool`.
1735 pub fn resolvedErrorSet(func: *const Func, ip: *const InternPool) *Index {
1770 fn resolvedErrorSetPtr(func: Func, ip: *InternPool) *Index {
17361771 const extra = ip.getLocalShared(func.tid).extra.acquire();
1737 assert(func.analysis(ip).inferred_error_set);
1772 assert(func.analysisUnordered(ip).inferred_error_set);
17381773 return @ptrCast(&extra.view().items(.@"0")[func.resolved_error_set_extra_index]);
17391774 }
1775
1776 pub fn resolvedErrorSetUnordered(func: Func, ip: *const InternPool) Index {
1777 return @atomicLoad(Index, func.resolvedErrorSetPtr(@constCast(ip)), .unordered);
1778 }
17401779 };
17411780
17421781 pub const Int = struct {
......@@ -2663,47 +2702,170 @@ pub const LoadedUnionType = struct {
26632702 /// This accessor is provided so that the tag type can be mutated, and so that
26642703 /// when it is mutated, the mutations are observed.
26652704 /// The returned pointer expires with any addition to the `InternPool`.
2666 pub fn tagTypePtr(self: LoadedUnionType, ip: *const InternPool) *Index {
2705 fn tagTypePtr(self: LoadedUnionType, ip: *InternPool) *Index {
26672706 const extra = ip.getLocalShared(self.tid).extra.acquire();
26682707 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "tag_ty").?;
26692708 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + field_index]);
26702709 }
26712710
2711 pub fn tagTypeUnordered(u: LoadedUnionType, ip: *const InternPool) Index {
2712 return @atomicLoad(Index, u.tagTypePtr(@constCast(ip)), .unordered);
2713 }
2714
2715 pub fn setTagType(u: LoadedUnionType, ip: *InternPool, tag_type: Index) void {
2716 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2717 extra_mutex.lock();
2718 defer extra_mutex.unlock();
2719
2720 @atomicStore(Index, u.tagTypePtr(ip), tag_type, .release);
2721 }
2722
26722723 /// The returned pointer expires with any addition to the `InternPool`.
2673 pub fn flagsPtr(self: LoadedUnionType, ip: *const InternPool) *Tag.TypeUnion.Flags {
2724 fn flagsPtr(self: LoadedUnionType, ip: *InternPool) *Tag.TypeUnion.Flags {
26742725 const extra = ip.getLocalShared(self.tid).extra.acquire();
26752726 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "flags").?;
26762727 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + field_index]);
26772728 }
26782729
2730 pub fn flagsUnordered(u: LoadedUnionType, ip: *const InternPool) Tag.TypeUnion.Flags {
2731 return @atomicLoad(Tag.TypeUnion.Flags, u.flagsPtr(@constCast(ip)), .unordered);
2732 }
2733
2734 pub fn setStatus(u: LoadedUnionType, ip: *InternPool, status: Status) void {
2735 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2736 extra_mutex.lock();
2737 defer extra_mutex.unlock();
2738
2739 const flags_ptr = u.flagsPtr(ip);
2740 var flags = flags_ptr.*;
2741 flags.status = status;
2742 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2743 }
2744
2745 pub fn setStatusIfLayoutWip(u: LoadedUnionType, ip: *InternPool, status: Status) void {
2746 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2747 extra_mutex.lock();
2748 defer extra_mutex.unlock();
2749
2750 const flags_ptr = u.flagsPtr(ip);
2751 var flags = flags_ptr.*;
2752 if (flags.status == .layout_wip) flags.status = status;
2753 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2754 }
2755
2756 pub fn setAlignment(u: LoadedUnionType, ip: *InternPool, alignment: Alignment) void {
2757 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2758 extra_mutex.lock();
2759 defer extra_mutex.unlock();
2760
2761 const flags_ptr = u.flagsPtr(ip);
2762 var flags = flags_ptr.*;
2763 flags.alignment = alignment;
2764 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2765 }
2766
2767 pub fn assumeRuntimeBitsIfFieldTypesWip(u: LoadedUnionType, ip: *InternPool) bool {
2768 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2769 extra_mutex.lock();
2770 defer extra_mutex.unlock();
2771
2772 const flags_ptr = u.flagsPtr(ip);
2773 var flags = flags_ptr.*;
2774 defer if (flags.status == .field_types_wip) {
2775 flags.assumed_runtime_bits = true;
2776 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2777 };
2778 return flags.status == .field_types_wip;
2779 }
2780
2781 pub fn setRequiresComptimeWip(u: LoadedUnionType, ip: *InternPool) RequiresComptime {
2782 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2783 extra_mutex.lock();
2784 defer extra_mutex.unlock();
2785
2786 const flags_ptr = u.flagsPtr(ip);
2787 var flags = flags_ptr.*;
2788 defer if (flags.requires_comptime == .unknown) {
2789 flags.requires_comptime = .wip;
2790 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2791 };
2792 return flags.requires_comptime;
2793 }
2794
2795 pub fn setRequiresComptime(u: LoadedUnionType, ip: *InternPool, requires_comptime: RequiresComptime) void {
2796 assert(requires_comptime != .wip); // see setRequiresComptimeWip
2797
2798 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2799 extra_mutex.lock();
2800 defer extra_mutex.unlock();
2801
2802 const flags_ptr = u.flagsPtr(ip);
2803 var flags = flags_ptr.*;
2804 flags.requires_comptime = requires_comptime;
2805 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2806 }
2807
2808 pub fn assumePointerAlignedIfFieldTypesWip(u: LoadedUnionType, ip: *InternPool, ptr_align: Alignment) bool {
2809 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2810 extra_mutex.lock();
2811 defer extra_mutex.unlock();
2812
2813 const flags_ptr = u.flagsPtr(ip);
2814 var flags = flags_ptr.*;
2815 defer if (flags.status == .field_types_wip) {
2816 flags.alignment = ptr_align;
2817 flags.assumed_pointer_aligned = true;
2818 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
2819 };
2820 return flags.status == .field_types_wip;
2821 }
2822
26792823 /// The returned pointer expires with any addition to the `InternPool`.
2680 pub fn size(self: LoadedUnionType, ip: *const InternPool) *u32 {
2824 fn sizePtr(self: LoadedUnionType, ip: *InternPool) *u32 {
26812825 const extra = ip.getLocalShared(self.tid).extra.acquire();
26822826 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "size").?;
26832827 return &extra.view().items(.@"0")[self.extra_index + field_index];
26842828 }
26852829
2830 pub fn sizeUnordered(u: LoadedUnionType, ip: *const InternPool) u32 {
2831 return @atomicLoad(u32, u.sizePtr(@constCast(ip)), .unordered);
2832 }
2833
26862834 /// The returned pointer expires with any addition to the `InternPool`.
2687 pub fn padding(self: LoadedUnionType, ip: *const InternPool) *u32 {
2835 fn paddingPtr(self: LoadedUnionType, ip: *InternPool) *u32 {
26882836 const extra = ip.getLocalShared(self.tid).extra.acquire();
26892837 const field_index = std.meta.fieldIndex(Tag.TypeUnion, "padding").?;
26902838 return &extra.view().items(.@"0")[self.extra_index + field_index];
26912839 }
26922840
2841 pub fn paddingUnordered(u: LoadedUnionType, ip: *const InternPool) u32 {
2842 return @atomicLoad(u32, u.paddingPtr(@constCast(ip)), .unordered);
2843 }
2844
26932845 pub fn hasTag(self: LoadedUnionType, ip: *const InternPool) bool {
2694 return self.flagsPtr(ip).runtime_tag.hasTag();
2846 return self.flagsUnordered(ip).runtime_tag.hasTag();
26952847 }
26962848
26972849 pub fn haveFieldTypes(self: LoadedUnionType, ip: *const InternPool) bool {
2698 return self.flagsPtr(ip).status.haveFieldTypes();
2850 return self.flagsUnordered(ip).status.haveFieldTypes();
26992851 }
27002852
27012853 pub fn haveLayout(self: LoadedUnionType, ip: *const InternPool) bool {
2702 return self.flagsPtr(ip).status.haveLayout();
2854 return self.flagsUnordered(ip).status.haveLayout();
27032855 }
27042856
2705 pub fn getLayout(self: LoadedUnionType, ip: *const InternPool) std.builtin.Type.ContainerLayout {
2706 return self.flagsPtr(ip).layout;
2857 pub fn setHaveLayout(u: LoadedUnionType, ip: *InternPool, size: u32, padding: u32, alignment: Alignment) void {
2858 const extra_mutex = &ip.getLocal(u.tid).mutate.extra.mutex;
2859 extra_mutex.lock();
2860 defer extra_mutex.unlock();
2861
2862 @atomicStore(u32, u.sizePtr(ip), size, .unordered);
2863 @atomicStore(u32, u.paddingPtr(ip), padding, .unordered);
2864 const flags_ptr = u.flagsPtr(ip);
2865 var flags = flags_ptr.*;
2866 flags.alignment = alignment;
2867 flags.status = .have_layout;
2868 @atomicStore(Tag.TypeUnion.Flags, flags_ptr, flags, .release);
27072869 }
27082870
27092871 pub fn fieldAlign(self: LoadedUnionType, ip: *const InternPool, field_index: usize) Alignment {
......@@ -2726,7 +2888,7 @@ pub const LoadedUnionType = struct {
27262888
27272889 pub fn setFieldAligns(self: LoadedUnionType, ip: *const InternPool, aligns: []const Alignment) void {
27282890 if (aligns.len == 0) return;
2729 assert(self.flagsPtr(ip).any_aligned_fields);
2891 assert(self.flagsUnordered(ip).any_aligned_fields);
27302892 @memcpy(self.field_aligns.get(ip), aligns);
27312893 }
27322894};
......@@ -2877,26 +3039,26 @@ pub const LoadedStructType = struct {
28773039 };
28783040
28793041 /// Look up field index based on field name.
2880 pub fn nameIndex(self: LoadedStructType, ip: *const InternPool, name: NullTerminatedString) ?u32 {
2881 const names_map = self.names_map.unwrap() orelse {
3042 pub fn nameIndex(s: LoadedStructType, ip: *const InternPool, name: NullTerminatedString) ?u32 {
3043 const names_map = s.names_map.unwrap() orelse {
28823044 const i = name.toUnsigned(ip) orelse return null;
2883 if (i >= self.field_types.len) return null;
3045 if (i >= s.field_types.len) return null;
28843046 return i;
28853047 };
28863048 const map = names_map.getConst(ip);
2887 const adapter: NullTerminatedString.Adapter = .{ .strings = self.field_names.get(ip) };
3049 const adapter: NullTerminatedString.Adapter = .{ .strings = s.field_names.get(ip) };
28883050 const field_index = map.getIndexAdapted(name, adapter) orelse return null;
28893051 return @intCast(field_index);
28903052 }
28913053
28923054 /// Returns the already-existing field with the same name, if any.
28933055 pub fn addFieldName(
2894 self: LoadedStructType,
3056 s: LoadedStructType,
28953057 ip: *InternPool,
28963058 name: NullTerminatedString,
28973059 ) ?u32 {
2898 const extra = ip.getLocalShared(self.tid).extra.acquire();
2899 return ip.addFieldName(extra, self.names_map.unwrap().?, self.field_names.start, name);
3060 const extra = ip.getLocalShared(s.tid).extra.acquire();
3061 return ip.addFieldName(extra, s.names_map.unwrap().?, s.field_names.start, name);
29003062 }
29013063
29023064 pub fn fieldAlign(s: LoadedStructType, ip: *const InternPool, i: usize) Alignment {
......@@ -2924,143 +3086,313 @@ pub const LoadedStructType = struct {
29243086 s.comptime_bits.setBit(ip, i);
29253087 }
29263088
3089 /// The returned pointer expires with any addition to the `InternPool`.
3090 /// Asserts the struct is not packed.
3091 fn flagsPtr(s: LoadedStructType, ip: *InternPool) *Tag.TypeStruct.Flags {
3092 assert(s.layout != .@"packed");
3093 const extra = ip.getLocalShared(s.tid).extra.acquire();
3094 const flags_field_index = std.meta.fieldIndex(Tag.TypeStruct, "flags").?;
3095 return @ptrCast(&extra.view().items(.@"0")[s.extra_index + flags_field_index]);
3096 }
3097
3098 pub fn flagsUnordered(s: LoadedStructType, ip: *const InternPool) Tag.TypeStruct.Flags {
3099 return @atomicLoad(Tag.TypeStruct.Flags, s.flagsPtr(@constCast(ip)), .unordered);
3100 }
3101
3102 /// The returned pointer expires with any addition to the `InternPool`.
3103 /// Asserts that the struct is packed.
3104 fn packedFlagsPtr(s: LoadedStructType, ip: *InternPool) *Tag.TypeStructPacked.Flags {
3105 assert(s.layout == .@"packed");
3106 const extra = ip.getLocalShared(s.tid).extra.acquire();
3107 const flags_field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?;
3108 return @ptrCast(&extra.view().items(.@"0")[s.extra_index + flags_field_index]);
3109 }
3110
3111 pub fn packedFlagsUnordered(s: LoadedStructType, ip: *const InternPool) Tag.TypeStructPacked.Flags {
3112 return @atomicLoad(Tag.TypeStructPacked.Flags, s.packedFlagsPtr(@constCast(ip)), .unordered);
3113 }
3114
29273115 /// Reads the non-opv flag calculated during AstGen. Used to short-circuit more
29283116 /// complicated logic.
2929 pub fn knownNonOpv(s: LoadedStructType, ip: *InternPool) bool {
3117 pub fn knownNonOpv(s: LoadedStructType, ip: *const InternPool) bool {
29303118 return switch (s.layout) {
29313119 .@"packed" => false,
2932 .auto, .@"extern" => s.flagsPtr(ip).known_non_opv,
3120 .auto, .@"extern" => s.flagsUnordered(ip).known_non_opv,
29333121 };
29343122 }
29353123
2936 /// The returned pointer expires with any addition to the `InternPool`.
2937 /// Asserts the struct is not packed.
2938 pub fn flagsPtr(self: LoadedStructType, ip: *InternPool) *Tag.TypeStruct.Flags {
2939 assert(self.layout != .@"packed");
2940 const extra = ip.getLocalShared(self.tid).extra.acquire();
2941 const flags_field_index = std.meta.fieldIndex(Tag.TypeStruct, "flags").?;
2942 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + flags_field_index]);
3124 pub fn requiresComptime(s: LoadedStructType, ip: *const InternPool) RequiresComptime {
3125 return s.flagsUnordered(ip).requires_comptime;
29433126 }
29443127
2945 /// The returned pointer expires with any addition to the `InternPool`.
2946 /// Asserts that the struct is packed.
2947 pub fn packedFlagsPtr(self: LoadedStructType, ip: *InternPool) *Tag.TypeStructPacked.Flags {
2948 assert(self.layout == .@"packed");
2949 const extra = ip.getLocalShared(self.tid).extra.acquire();
2950 const flags_field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?;
2951 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + flags_field_index]);
3128 pub fn setRequiresComptimeWip(s: LoadedStructType, ip: *InternPool) RequiresComptime {
3129 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3130 extra_mutex.lock();
3131 defer extra_mutex.unlock();
3132
3133 const flags_ptr = s.flagsPtr(ip);
3134 var flags = flags_ptr.*;
3135 defer if (flags.requires_comptime == .unknown) {
3136 flags.requires_comptime = .wip;
3137 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3138 };
3139 return flags.requires_comptime;
3140 }
3141
3142 pub fn setRequiresComptime(s: LoadedStructType, ip: *InternPool, requires_comptime: RequiresComptime) void {
3143 assert(requires_comptime != .wip); // see setRequiresComptimeWip
3144
3145 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3146 extra_mutex.lock();
3147 defer extra_mutex.unlock();
3148
3149 const flags_ptr = s.flagsPtr(ip);
3150 var flags = flags_ptr.*;
3151 flags.requires_comptime = requires_comptime;
3152 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
29523153 }
29533154
29543155 pub fn assumeRuntimeBitsIfFieldTypesWip(s: LoadedStructType, ip: *InternPool) bool {
29553156 if (s.layout == .@"packed") return false;
3157
3158 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3159 extra_mutex.lock();
3160 defer extra_mutex.unlock();
3161
29563162 const flags_ptr = s.flagsPtr(ip);
2957 if (flags_ptr.field_types_wip) {
2958 flags_ptr.assumed_runtime_bits = true;
2959 return true;
2960 }
2961 return false;
3163 var flags = flags_ptr.*;
3164 defer if (flags.field_types_wip) {
3165 flags.assumed_runtime_bits = true;
3166 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3167 };
3168 return flags.field_types_wip;
29623169 }
29633170
2964 pub fn setTypesWip(s: LoadedStructType, ip: *InternPool) bool {
3171 pub fn setFieldTypesWip(s: LoadedStructType, ip: *InternPool) bool {
29653172 if (s.layout == .@"packed") return false;
3173
3174 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3175 extra_mutex.lock();
3176 defer extra_mutex.unlock();
3177
29663178 const flags_ptr = s.flagsPtr(ip);
2967 if (flags_ptr.field_types_wip) return true;
2968 flags_ptr.field_types_wip = true;
2969 return false;
3179 var flags = flags_ptr.*;
3180 defer {
3181 flags.field_types_wip = true;
3182 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3183 }
3184 return flags.field_types_wip;
29703185 }
29713186
2972 pub fn clearTypesWip(s: LoadedStructType, ip: *InternPool) void {
3187 pub fn clearFieldTypesWip(s: LoadedStructType, ip: *InternPool) void {
29733188 if (s.layout == .@"packed") return;
2974 s.flagsPtr(ip).field_types_wip = false;
3189
3190 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3191 extra_mutex.lock();
3192 defer extra_mutex.unlock();
3193
3194 const flags_ptr = s.flagsPtr(ip);
3195 var flags = flags_ptr.*;
3196 flags.field_types_wip = false;
3197 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
29753198 }
29763199
29773200 pub fn setLayoutWip(s: LoadedStructType, ip: *InternPool) bool {
29783201 if (s.layout == .@"packed") return false;
3202
3203 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3204 extra_mutex.lock();
3205 defer extra_mutex.unlock();
3206
29793207 const flags_ptr = s.flagsPtr(ip);
2980 if (flags_ptr.layout_wip) return true;
2981 flags_ptr.layout_wip = true;
2982 return false;
3208 var flags = flags_ptr.*;
3209 defer {
3210 flags.layout_wip = true;
3211 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3212 }
3213 return flags.layout_wip;
29833214 }
29843215
29853216 pub fn clearLayoutWip(s: LoadedStructType, ip: *InternPool) void {
29863217 if (s.layout == .@"packed") return;
2987 s.flagsPtr(ip).layout_wip = false;
3218
3219 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3220 extra_mutex.lock();
3221 defer extra_mutex.unlock();
3222
3223 const flags_ptr = s.flagsPtr(ip);
3224 var flags = flags_ptr.*;
3225 flags.layout_wip = false;
3226 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
29883227 }
29893228
2990 pub fn setAlignmentWip(s: LoadedStructType, ip: *InternPool) bool {
2991 if (s.layout == .@"packed") return false;
3229 pub fn setAlignment(s: LoadedStructType, ip: *InternPool, alignment: Alignment) void {
3230 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3231 extra_mutex.lock();
3232 defer extra_mutex.unlock();
3233
3234 const flags_ptr = s.flagsPtr(ip);
3235 var flags = flags_ptr.*;
3236 flags.alignment = alignment;
3237 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3238 }
3239
3240 pub fn assumePointerAlignedIfFieldTypesWip(s: LoadedStructType, ip: *InternPool, ptr_align: Alignment) bool {
3241 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3242 extra_mutex.lock();
3243 defer extra_mutex.unlock();
3244
3245 const flags_ptr = s.flagsPtr(ip);
3246 var flags = flags_ptr.*;
3247 defer if (flags.field_types_wip) {
3248 flags.alignment = ptr_align;
3249 flags.assumed_pointer_aligned = true;
3250 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3251 };
3252 return flags.field_types_wip;
3253 }
3254
3255 pub fn assumePointerAlignedIfWip(s: LoadedStructType, ip: *InternPool, ptr_align: Alignment) bool {
3256 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3257 extra_mutex.lock();
3258 defer extra_mutex.unlock();
3259
29923260 const flags_ptr = s.flagsPtr(ip);
2993 if (flags_ptr.alignment_wip) return true;
2994 flags_ptr.alignment_wip = true;
2995 return false;
3261 var flags = flags_ptr.*;
3262 defer {
3263 if (flags.alignment_wip) {
3264 flags.alignment = ptr_align;
3265 flags.assumed_pointer_aligned = true;
3266 } else flags.alignment_wip = true;
3267 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3268 }
3269 return flags.alignment_wip;
29963270 }
29973271
29983272 pub fn clearAlignmentWip(s: LoadedStructType, ip: *InternPool) void {
29993273 if (s.layout == .@"packed") return;
3000 s.flagsPtr(ip).alignment_wip = false;
3274
3275 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3276 extra_mutex.lock();
3277 defer extra_mutex.unlock();
3278
3279 const flags_ptr = s.flagsPtr(ip);
3280 var flags = flags_ptr.*;
3281 flags.alignment_wip = false;
3282 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
30013283 }
30023284
30033285 pub fn setInitsWip(s: LoadedStructType, ip: *InternPool) bool {
3004 const local = ip.getLocal(s.tid);
3005 local.mutate.extra.mutex.lock();
3006 defer local.mutate.extra.mutex.unlock();
3007 return switch (s.layout) {
3008 .@"packed" => @as(Tag.TypeStructPacked.Flags, @bitCast(@atomicRmw(
3009 u32,
3010 @as(*u32, @ptrCast(s.packedFlagsPtr(ip))),
3011 .Or,
3012 @bitCast(Tag.TypeStructPacked.Flags{ .field_inits_wip = true }),
3013 .acq_rel,
3014 ))).field_inits_wip,
3015 .auto, .@"extern" => @as(Tag.TypeStruct.Flags, @bitCast(@atomicRmw(
3016 u32,
3017 @as(*u32, @ptrCast(s.flagsPtr(ip))),
3018 .Or,
3019 @bitCast(Tag.TypeStruct.Flags{ .field_inits_wip = true }),
3020 .acq_rel,
3021 ))).field_inits_wip,
3022 };
3286 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3287 extra_mutex.lock();
3288 defer extra_mutex.unlock();
3289
3290 switch (s.layout) {
3291 .@"packed" => {
3292 const flags_ptr = s.packedFlagsPtr(ip);
3293 var flags = flags_ptr.*;
3294 defer {
3295 flags.field_inits_wip = true;
3296 @atomicStore(Tag.TypeStructPacked.Flags, flags_ptr, flags, .release);
3297 }
3298 return flags.field_inits_wip;
3299 },
3300 .auto, .@"extern" => {
3301 const flags_ptr = s.flagsPtr(ip);
3302 var flags = flags_ptr.*;
3303 defer {
3304 flags.field_inits_wip = true;
3305 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3306 }
3307 return flags.field_inits_wip;
3308 },
3309 }
30233310 }
30243311
30253312 pub fn clearInitsWip(s: LoadedStructType, ip: *InternPool) void {
3313 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3314 extra_mutex.lock();
3315 defer extra_mutex.unlock();
3316
30263317 switch (s.layout) {
3027 .@"packed" => s.packedFlagsPtr(ip).field_inits_wip = false,
3028 .auto, .@"extern" => s.flagsPtr(ip).field_inits_wip = false,
3318 .@"packed" => {
3319 const flags_ptr = s.packedFlagsPtr(ip);
3320 var flags = flags_ptr.*;
3321 flags.field_inits_wip = false;
3322 @atomicStore(Tag.TypeStructPacked.Flags, flags_ptr, flags, .release);
3323 },
3324 .auto, .@"extern" => {
3325 const flags_ptr = s.flagsPtr(ip);
3326 var flags = flags_ptr.*;
3327 flags.field_inits_wip = false;
3328 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3329 },
30293330 }
30303331 }
30313332
30323333 pub fn setFullyResolved(s: LoadedStructType, ip: *InternPool) bool {
30333334 if (s.layout == .@"packed") return true;
3335
3336 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3337 extra_mutex.lock();
3338 defer extra_mutex.unlock();
3339
30343340 const flags_ptr = s.flagsPtr(ip);
3035 if (flags_ptr.fully_resolved) return true;
3036 flags_ptr.fully_resolved = true;
3037 return false;
3341 var flags = flags_ptr.*;
3342 defer {
3343 flags.fully_resolved = true;
3344 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3345 }
3346 return flags.fully_resolved;
30383347 }
30393348
30403349 pub fn clearFullyResolved(s: LoadedStructType, ip: *InternPool) void {
3041 s.flagsPtr(ip).fully_resolved = false;
3350 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3351 extra_mutex.lock();
3352 defer extra_mutex.unlock();
3353
3354 const flags_ptr = s.flagsPtr(ip);
3355 var flags = flags_ptr.*;
3356 flags.fully_resolved = false;
3357 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
30423358 }
30433359
30443360 /// The returned pointer expires with any addition to the `InternPool`.
30453361 /// Asserts the struct is not packed.
3046 pub fn size(self: LoadedStructType, ip: *InternPool) *u32 {
3047 assert(self.layout != .@"packed");
3048 const extra = ip.getLocalShared(self.tid).extra.acquire();
3362 fn sizePtr(s: LoadedStructType, ip: *InternPool) *u32 {
3363 assert(s.layout != .@"packed");
3364 const extra = ip.getLocalShared(s.tid).extra.acquire();
30493365 const size_field_index = std.meta.fieldIndex(Tag.TypeStruct, "size").?;
3050 return @ptrCast(&extra.view().items(.@"0")[self.extra_index + size_field_index]);
3366 return @ptrCast(&extra.view().items(.@"0")[s.extra_index + size_field_index]);
3367 }
3368
3369 pub fn sizeUnordered(s: LoadedStructType, ip: *const InternPool) u32 {
3370 return @atomicLoad(u32, s.sizePtr(@constCast(ip)), .unordered);
30513371 }
30523372
30533373 /// The backing integer type of the packed struct. Whether zig chooses
30543374 /// this type or the user specifies it, it is stored here. This will be
30553375 /// set to `none` until the layout is resolved.
30563376 /// Asserts the struct is packed.
3057 pub fn backingIntType(s: LoadedStructType, ip: *InternPool) *Index {
3377 fn backingIntTypePtr(s: LoadedStructType, ip: *InternPool) *Index {
30583378 assert(s.layout == .@"packed");
30593379 const extra = ip.getLocalShared(s.tid).extra.acquire();
30603380 const field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "backing_int_ty").?;
30613381 return @ptrCast(&extra.view().items(.@"0")[s.extra_index + field_index]);
30623382 }
30633383
3384 pub fn backingIntTypeUnordered(s: LoadedStructType, ip: *const InternPool) Index {
3385 return @atomicLoad(Index, s.backingIntTypePtr(@constCast(ip)), .unordered);
3386 }
3387
3388 pub fn setBackingIntType(s: LoadedStructType, ip: *InternPool, backing_int_ty: Index) void {
3389 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3390 extra_mutex.lock();
3391 defer extra_mutex.unlock();
3392
3393 @atomicStore(Index, s.backingIntTypePtr(ip), backing_int_ty, .release);
3394 }
3395
30643396 /// Asserts the struct is not packed.
30653397 pub fn setZirIndex(s: LoadedStructType, ip: *InternPool, new_zir_index: TrackedInst.Index.Optional) void {
30663398 assert(s.layout != .@"packed");
......@@ -3073,29 +3405,56 @@ pub const LoadedStructType = struct {
30733405 return types.len == 0 or types[0] != .none;
30743406 }
30753407
3076 pub fn haveFieldInits(s: LoadedStructType, ip: *InternPool) bool {
3408 pub fn haveFieldInits(s: LoadedStructType, ip: *const InternPool) bool {
30773409 return switch (s.layout) {
3078 .@"packed" => s.packedFlagsPtr(ip).inits_resolved,
3079 .auto, .@"extern" => s.flagsPtr(ip).inits_resolved,
3410 .@"packed" => s.packedFlagsUnordered(ip).inits_resolved,
3411 .auto, .@"extern" => s.flagsUnordered(ip).inits_resolved,
30803412 };
30813413 }
30823414
30833415 pub fn setHaveFieldInits(s: LoadedStructType, ip: *InternPool) void {
3416 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3417 extra_mutex.lock();
3418 defer extra_mutex.unlock();
3419
30843420 switch (s.layout) {
3085 .@"packed" => s.packedFlagsPtr(ip).inits_resolved = true,
3086 .auto, .@"extern" => s.flagsPtr(ip).inits_resolved = true,
3421 .@"packed" => {
3422 const flags_ptr = s.packedFlagsPtr(ip);
3423 var flags = flags_ptr.*;
3424 flags.inits_resolved = true;
3425 @atomicStore(Tag.TypeStructPacked.Flags, flags_ptr, flags, .release);
3426 },
3427 .auto, .@"extern" => {
3428 const flags_ptr = s.flagsPtr(ip);
3429 var flags = flags_ptr.*;
3430 flags.inits_resolved = true;
3431 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3432 },
30873433 }
30883434 }
30893435
30903436 pub fn haveLayout(s: LoadedStructType, ip: *InternPool) bool {
30913437 return switch (s.layout) {
3092 .@"packed" => s.backingIntType(ip).* != .none,
3093 .auto, .@"extern" => s.flagsPtr(ip).layout_resolved,
3438 .@"packed" => s.backingIntTypeUnordered(ip) != .none,
3439 .auto, .@"extern" => s.flagsUnordered(ip).layout_resolved,
30943440 };
30953441 }
30963442
3443 pub fn setLayoutResolved(s: LoadedStructType, ip: *InternPool, size: u32, alignment: Alignment) void {
3444 const extra_mutex = &ip.getLocal(s.tid).mutate.extra.mutex;
3445 extra_mutex.lock();
3446 defer extra_mutex.unlock();
3447
3448 @atomicStore(u32, s.sizePtr(ip), size, .unordered);
3449 const flags_ptr = s.flagsPtr(ip);
3450 var flags = flags_ptr.*;
3451 flags.alignment = alignment;
3452 flags.layout_resolved = true;
3453 @atomicStore(Tag.TypeStruct.Flags, flags_ptr, flags, .release);
3454 }
3455
30973456 pub fn isTuple(s: LoadedStructType, ip: *InternPool) bool {
3098 return s.layout != .@"packed" and s.flagsPtr(ip).is_tuple;
3457 return s.layout != .@"packed" and s.flagsUnordered(ip).is_tuple;
30993458 }
31003459
31013460 pub fn hasReorderedFields(s: LoadedStructType) bool {
......@@ -3209,7 +3568,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType {
32093568 const decl: DeclIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "decl").?]);
32103569 const zir_index: TrackedInst.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?]);
32113570 const fields_len = extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "fields_len").?];
3212 const flags: Tag.TypeStruct.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "flags").?], .monotonic));
3571 const flags: Tag.TypeStruct.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStruct, "flags").?], .unordered));
32133572 var extra_index = item.data + @as(u32, @typeInfo(Tag.TypeStruct).Struct.fields.len);
32143573 const captures_len = if (flags.any_captures) c: {
32153574 const len = extra_list.view().items(.@"0")[extra_index];
......@@ -3317,7 +3676,7 @@ pub fn loadStructType(ip: *const InternPool, index: Index) LoadedStructType {
33173676 const fields_len = extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "fields_len").?];
33183677 const namespace: OptionalNamespaceIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "namespace").?]);
33193678 const names_map: MapIndex = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "names_map").?]);
3320 const flags: Tag.TypeStructPacked.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?], .monotonic));
3679 const flags: Tag.TypeStructPacked.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?], .unordered));
33213680 var extra_index = item.data + @as(u32, @typeInfo(Tag.TypeStructPacked).Struct.fields.len);
33223681 const has_inits = item.tag == .type_struct_packed_inits;
33233682 const captures_len = if (flags.any_captures) c: {
......@@ -5442,10 +5801,10 @@ pub fn init(ip: *InternPool, gpa: Allocator, available_threads: usize) !void {
54425801 .arena = .{},
54435802
54445803 .items = Local.ListMutate.empty,
5445 .extra = Local.MutexListMutate.empty,
5804 .extra = Local.ListMutate.empty,
54465805 .limbs = Local.ListMutate.empty,
54475806 .strings = Local.ListMutate.empty,
5448 .tracked_insts = Local.MutexListMutate.empty,
5807 .tracked_insts = Local.ListMutate.empty,
54495808 .files = Local.ListMutate.empty,
54505809 .maps = Local.ListMutate.empty,
54515810
......@@ -5635,7 +5994,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
56355994 const extra_list = unwrapped_index.getExtra(ip);
56365995 const extra_items = extra_list.view().items(.@"0");
56375996 const zir_index: TrackedInst.Index = @enumFromInt(extra_items[data + std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?]);
5638 const flags: Tag.TypeStruct.Flags = @bitCast(@atomicLoad(u32, &extra_items[data + std.meta.fieldIndex(Tag.TypeStruct, "flags").?], .monotonic));
5997 const flags: Tag.TypeStruct.Flags = @bitCast(@atomicLoad(u32, &extra_items[data + std.meta.fieldIndex(Tag.TypeStruct, "flags").?], .unordered));
56395998 const end_extra_index = data + @as(u32, @typeInfo(Tag.TypeStruct).Struct.fields.len);
56405999 if (flags.is_reified) {
56416000 assert(!flags.any_captures);
......@@ -5658,7 +6017,7 @@ pub fn indexToKey(ip: *const InternPool, index: Index) Key {
56586017 const extra_list = unwrapped_index.getExtra(ip);
56596018 const extra_items = extra_list.view().items(.@"0");
56606019 const zir_index: TrackedInst.Index = @enumFromInt(extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "zir_index").?]);
5661 const flags: Tag.TypeStructPacked.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?], .monotonic));
6020 const flags: Tag.TypeStructPacked.Flags = @bitCast(@atomicLoad(u32, &extra_items[item.data + std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?], .unordered));
56626021 const end_extra_index = data + @as(u32, @typeInfo(Tag.TypeStructPacked).Struct.fields.len);
56636022 if (flags.is_reified) {
56646023 assert(!flags.any_captures);
......@@ -6155,7 +6514,7 @@ fn extraFuncDecl(tid: Zcu.PerThread.Id, extra: Local.Extra, extra_index: u32) Ke
61556514fn extraFuncInstance(ip: *const InternPool, tid: Zcu.PerThread.Id, extra: Local.Extra, extra_index: u32) Key.Func {
61566515 const extra_items = extra.view().items(.@"0");
61576516 const analysis_extra_index = extra_index + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?;
6158 const analysis: FuncAnalysis = @bitCast(@atomicLoad(u32, &extra_items[analysis_extra_index], .monotonic));
6517 const analysis: FuncAnalysis = @bitCast(@atomicLoad(u32, &extra_items[analysis_extra_index], .unordered));
61596518 const owner_decl: DeclIndex = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "owner_decl").?]);
61606519 const ty: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "ty").?]);
61616520 const generic_owner: Index = @enumFromInt(extra_items[extra_index + std.meta.fieldIndex(Tag.FuncInstance, "generic_owner").?]);
......@@ -8702,7 +9061,7 @@ pub fn remove(ip: *InternPool, tid: Zcu.PerThread.Id, index: Index) void {
87029061 // Restore the original item at this index.
87039062 assert(static_keys[@intFromEnum(index)] == .simple_type);
87049063 const items = ip.getLocalShared(unwrapped_index.tid).items.acquire().view();
8705 @atomicStore(Tag, &items.items(.tag)[unwrapped_index.index], .simple_type, .monotonic);
9064 @atomicStore(Tag, &items.items(.tag)[unwrapped_index.index], .simple_type, .unordered);
87069065 return;
87079066 }
87089067
......@@ -8719,7 +9078,7 @@ pub fn remove(ip: *InternPool, tid: Zcu.PerThread.Id, index: Index) void {
87199078 // Thus, we will rewrite the tag to `removed`, leaking the item until
87209079 // next GC but causing `KeyAdapter` to ignore it.
87219080 const items = ip.getLocalShared(unwrapped_index.tid).items.acquire().view();
8722 @atomicStore(Tag, &items.items(.tag)[unwrapped_index.index], .removed, .monotonic);
9081 @atomicStore(Tag, &items.items(.tag)[unwrapped_index.index], .removed, .unordered);
87239082}
87249083
87259084fn addInt(
......@@ -9415,9 +9774,11 @@ pub fn errorUnionPayload(ip: *const InternPool, ty: Index) Index {
94159774/// The is only legal because the initializer is not part of the hash.
94169775pub fn mutateVarInit(ip: *InternPool, index: Index, init_index: Index) void {
94179776 const unwrapped_index = index.unwrap(ip);
9777
94189778 const local = ip.getLocal(unwrapped_index.tid);
94199779 local.mutate.extra.mutex.lock();
94209780 defer local.mutate.extra.mutex.unlock();
9781
94219782 const extra_items = local.shared.extra.view().items(.@"0");
94229783 const item = unwrapped_index.getItem(ip);
94239784 assert(item.tag == .variable);
......@@ -9436,7 +9797,7 @@ fn dumpStatsFallible(ip: *const InternPool, arena: Allocator) anyerror!void {
94369797 var decls_len: usize = 0;
94379798 for (ip.locals) |*local| {
94389799 items_len += local.mutate.items.len;
9439 extra_len += local.mutate.extra.list.len;
9800 extra_len += local.mutate.extra.len;
94409801 limbs_len += local.mutate.limbs.len;
94419802 decls_len += local.mutate.decls.buckets_list.len;
94429803 }
......@@ -10730,29 +11091,29 @@ pub fn zigTypeTagOrPoison(ip: *const InternPool, index: Index) error{GenericPois
1073011091 };
1073111092}
1073211093
10733pub fn isFuncBody(ip: *const InternPool, index: Index) bool {
10734 return switch (index.unwrap(ip).getTag(ip)) {
11094pub fn isFuncBody(ip: *const InternPool, func: Index) bool {
11095 return switch (func.unwrap(ip).getTag(ip)) {
1073511096 .func_decl, .func_instance, .func_coerced => true,
1073611097 else => false,
1073711098 };
1073811099}
1073911100
10740pub fn funcAnalysis(ip: *const InternPool, index: Index) *FuncAnalysis {
10741 const unwrapped_index = index.unwrap(ip);
10742 const extra = unwrapped_index.getExtra(ip);
10743 const item = unwrapped_index.getItem(ip);
11101fn funcAnalysisPtr(ip: *InternPool, func: Index) *FuncAnalysis {
11102 const unwrapped_func = func.unwrap(ip);
11103 const extra = unwrapped_func.getExtra(ip);
11104 const item = unwrapped_func.getItem(ip);
1074411105 const extra_index = switch (item.tag) {
1074511106 .func_decl => item.data + std.meta.fieldIndex(Tag.FuncDecl, "analysis").?,
1074611107 .func_instance => item.data + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?,
1074711108 .func_coerced => {
1074811109 const extra_index = item.data + std.meta.fieldIndex(Tag.FuncCoerced, "func").?;
10749 const func_index: Index = @enumFromInt(extra.view().items(.@"0")[extra_index]);
10750 const unwrapped_func = func_index.unwrap(ip);
10751 const func_item = unwrapped_func.getItem(ip);
10752 return @ptrCast(&unwrapped_func.getExtra(ip).view().items(.@"0")[
10753 switch (func_item.tag) {
10754 .func_decl => func_item.data + std.meta.fieldIndex(Tag.FuncDecl, "analysis").?,
10755 .func_instance => func_item.data + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?,
11110 const coerced_func_index: Index = @enumFromInt(extra.view().items(.@"0")[extra_index]);
11111 const unwrapped_coerced_func = coerced_func_index.unwrap(ip);
11112 const coerced_func_item = unwrapped_coerced_func.getItem(ip);
11113 return @ptrCast(&unwrapped_coerced_func.getExtra(ip).view().items(.@"0")[
11114 switch (coerced_func_item.tag) {
11115 .func_decl => coerced_func_item.data + std.meta.fieldIndex(Tag.FuncDecl, "analysis").?,
11116 .func_instance => coerced_func_item.data + std.meta.fieldIndex(Tag.FuncInstance, "analysis").?,
1075611117 else => unreachable,
1075711118 }
1075811119 ]);
......@@ -10762,14 +11123,65 @@ pub fn funcAnalysis(ip: *const InternPool, index: Index) *FuncAnalysis {
1076211123 return @ptrCast(&extra.view().items(.@"0")[extra_index]);
1076311124}
1076411125
10765pub fn funcHasInferredErrorSet(ip: *const InternPool, i: Index) bool {
10766 return funcAnalysis(ip, i).inferred_error_set;
11126pub fn funcAnalysisUnordered(ip: *const InternPool, func: Index) FuncAnalysis {
11127 return @atomicLoad(FuncAnalysis, @constCast(ip).funcAnalysisPtr(func), .unordered);
1076711128}
1076811129
10769pub fn funcZirBodyInst(ip: *const InternPool, index: Index) TrackedInst.Index {
10770 const unwrapped_index = index.unwrap(ip);
10771 const item = unwrapped_index.getItem(ip);
10772 const item_extra = unwrapped_index.getExtra(ip);
11130pub fn funcSetAnalysisState(ip: *InternPool, func: Index, state: FuncAnalysis.State) void {
11131 const unwrapped_func = func.unwrap(ip);
11132 const extra_mutex = &ip.getLocal(unwrapped_func.tid).mutate.extra.mutex;
11133 extra_mutex.lock();
11134 defer extra_mutex.unlock();
11135
11136 const analysis_ptr = ip.funcAnalysisPtr(func);
11137 var analysis = analysis_ptr.*;
11138 analysis.state = state;
11139 @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release);
11140}
11141
11142pub fn funcMaxStackAlignment(ip: *InternPool, func: Index, new_stack_alignment: Alignment) void {
11143 const unwrapped_func = func.unwrap(ip);
11144 const extra_mutex = &ip.getLocal(unwrapped_func.tid).mutate.extra.mutex;
11145 extra_mutex.lock();
11146 defer extra_mutex.unlock();
11147
11148 const analysis_ptr = ip.funcAnalysisPtr(func);
11149 var analysis = analysis_ptr.*;
11150 analysis.stack_alignment = switch (analysis.stack_alignment) {
11151 .none => new_stack_alignment,
11152 else => |old_stack_alignment| old_stack_alignment.maxStrict(new_stack_alignment),
11153 };
11154 @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release);
11155}
11156
11157pub fn funcSetCallsOrAwaitsErrorableFn(ip: *InternPool, func: Index) void {
11158 const unwrapped_func = func.unwrap(ip);
11159 const extra_mutex = &ip.getLocal(unwrapped_func.tid).mutate.extra.mutex;
11160 extra_mutex.lock();
11161 defer extra_mutex.unlock();
11162
11163 const analysis_ptr = ip.funcAnalysisPtr(func);
11164 var analysis = analysis_ptr.*;
11165 analysis.calls_or_awaits_errorable_fn = true;
11166 @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release);
11167}
11168
11169pub fn funcSetCold(ip: *InternPool, func: Index, is_cold: bool) void {
11170 const unwrapped_func = func.unwrap(ip);
11171 const extra_mutex = &ip.getLocal(unwrapped_func.tid).mutate.extra.mutex;
11172 extra_mutex.lock();
11173 defer extra_mutex.unlock();
11174
11175 const analysis_ptr = ip.funcAnalysisPtr(func);
11176 var analysis = analysis_ptr.*;
11177 analysis.is_cold = is_cold;
11178 @atomicStore(FuncAnalysis, analysis_ptr, analysis, .release);
11179}
11180
11181pub fn funcZirBodyInst(ip: *const InternPool, func: Index) TrackedInst.Index {
11182 const unwrapped_func = func.unwrap(ip);
11183 const item = unwrapped_func.getItem(ip);
11184 const item_extra = unwrapped_func.getExtra(ip);
1077311185 const zir_body_inst_field_index = std.meta.fieldIndex(Tag.FuncDecl, "zir_body_inst").?;
1077411186 switch (item.tag) {
1077511187 .func_decl => return @enumFromInt(item_extra.view().items(.@"0")[item.data + zir_body_inst_field_index]),
......@@ -10806,17 +11218,17 @@ pub fn iesFuncIndex(ip: *const InternPool, ies_index: Index) Index {
1080611218/// Returns a mutable pointer to the resolved error set type of an inferred
1080711219/// error set function. The returned pointer is invalidated when anything is
1080811220/// added to `ip`.
10809pub fn iesResolved(ip: *const InternPool, ies_index: Index) *Index {
11221fn iesResolvedPtr(ip: *InternPool, ies_index: Index) *Index {
1081011222 const ies_item = ies_index.getItem(ip);
1081111223 assert(ies_item.tag == .type_inferred_error_set);
10812 return funcIesResolved(ip, ies_item.data);
11224 return ip.funcIesResolvedPtr(ies_item.data);
1081311225}
1081411226
1081511227/// Returns a mutable pointer to the resolved error set type of an inferred
1081611228/// error set function. The returned pointer is invalidated when anything is
1081711229/// added to `ip`.
10818pub fn funcIesResolved(ip: *const InternPool, func_index: Index) *Index {
10819 assert(funcHasInferredErrorSet(ip, func_index));
11230fn funcIesResolvedPtr(ip: *InternPool, func_index: Index) *Index {
11231 assert(ip.funcAnalysisUnordered(func_index).inferred_error_set);
1082011232 const unwrapped_func = func_index.unwrap(ip);
1082111233 const func_extra = unwrapped_func.getExtra(ip);
1082211234 const func_item = unwrapped_func.getItem(ip);
......@@ -10842,6 +11254,19 @@ pub fn funcIesResolved(ip: *const InternPool, func_index: Index) *Index {
1084211254 return @ptrCast(&func_extra.view().items(.@"0")[extra_index]);
1084311255}
1084411256
11257pub fn funcIesResolvedUnordered(ip: *const InternPool, index: Index) Index {
11258 return @atomicLoad(Index, @constCast(ip).funcIesResolvedPtr(index), .unordered);
11259}
11260
11261pub fn funcSetIesResolved(ip: *InternPool, index: Index, ies: Index) void {
11262 const unwrapped_func = index.unwrap(ip);
11263 const extra_mutex = &ip.getLocal(unwrapped_func.tid).mutate.extra.mutex;
11264 extra_mutex.lock();
11265 defer extra_mutex.unlock();
11266
11267 @atomicStore(Index, ip.funcIesResolvedPtr(index), ies, .release);
11268}
11269
1084511270pub fn funcDeclInfo(ip: *const InternPool, index: Index) Key.Func {
1084611271 const unwrapped_index = index.unwrap(ip);
1084711272 const item = unwrapped_index.getItem(ip);
......@@ -10950,7 +11375,10 @@ const GlobalErrorSet = struct {
1095011375 names: Names,
1095111376 map: Shard.Map(GlobalErrorSet.Index),
1095211377 } align(std.atomic.cache_line),
10953 mutate: Local.MutexListMutate align(std.atomic.cache_line),
11378 mutate: struct {
11379 names: Local.ListMutate,
11380 map: struct { mutex: std.Thread.Mutex },
11381 } align(std.atomic.cache_line),
1095411382
1095511383 const Names = Local.List(struct { NullTerminatedString });
1095611384
......@@ -10959,7 +11387,10 @@ const GlobalErrorSet = struct {
1095911387 .names = Names.empty,
1096011388 .map = Shard.Map(GlobalErrorSet.Index).empty,
1096111389 },
10962 .mutate = Local.MutexListMutate.empty,
11390 .mutate = .{
11391 .names = Local.ListMutate.empty,
11392 .map = .{ .mutex = .{} },
11393 },
1096311394 };
1096411395
1096511396 const Index = enum(Zcu.ErrorInt) {
......@@ -10969,7 +11400,7 @@ const GlobalErrorSet = struct {
1096911400
1097011401 /// Not thread-safe, may only be called from the main thread.
1097111402 pub fn getNamesFromMainThread(ges: *const GlobalErrorSet) []const NullTerminatedString {
10972 const len = ges.mutate.list.len;
11403 const len = ges.mutate.names.len;
1097311404 return if (len > 0) ges.shared.names.view().items(.@"0")[0..len] else &.{};
1097411405 }
1097511406
......@@ -10994,8 +11425,8 @@ const GlobalErrorSet = struct {
1099411425 if (entry.hash != hash) continue;
1099511426 if (names.view().items(.@"0")[@intFromEnum(index) - 1] == name) return index;
1099611427 }
10997 ges.mutate.mutex.lock();
10998 defer ges.mutate.mutex.unlock();
11428 ges.mutate.map.mutex.lock();
11429 defer ges.mutate.map.mutex.unlock();
1099911430 if (map.entries != ges.shared.map.entries) {
1100011431 map = ges.shared.map;
1100111432 map_mask = map.header().mask();
......@@ -11012,12 +11443,12 @@ const GlobalErrorSet = struct {
1101211443 const mutable_names: Names.Mutable = .{
1101311444 .gpa = gpa,
1101411445 .arena = arena_state,
11015 .mutate = &ges.mutate.list,
11446 .mutate = &ges.mutate.names,
1101611447 .list = &ges.shared.names,
1101711448 };
1101811449 try mutable_names.ensureUnusedCapacity(1);
1101911450 const map_header = map.header().*;
11020 if (ges.mutate.list.len < map_header.capacity * 3 / 5) {
11451 if (ges.mutate.names.len < map_header.capacity * 3 / 5) {
1102111452 mutable_names.appendAssumeCapacity(.{name});
1102211453 const index: GlobalErrorSet.Index = @enumFromInt(mutable_names.mutate.len);
1102311454 const entry = &map.entries[map_index];
src/Sema.zig+98-123
......@@ -2530,13 +2530,13 @@ pub fn failWithOwnedErrorMsg(sema: *Sema, block: ?*Block, err_msg: *Module.Error
25302530 }
25312531
25322532 if (sema.owner_func_index != .none) {
2533 ip.funcAnalysis(sema.owner_func_index).state = .sema_failure;
2533 ip.funcSetAnalysisState(sema.owner_func_index, .sema_failure);
25342534 } else {
25352535 sema.owner_decl.analysis = .sema_failure;
25362536 }
25372537
25382538 if (sema.func_index != .none) {
2539 ip.funcAnalysis(sema.func_index).state = .sema_failure;
2539 ip.funcSetAnalysisState(sema.func_index, .sema_failure);
25402540 }
25412541
25422542 return error.AnalysisFail;
......@@ -2848,7 +2848,7 @@ fn zirStructDecl(
28482848 }
28492849
28502850 try pt.finalizeAnonDecl(new_decl_index);
2851 try mod.comp.work_queue.writeItem(.{ .resolve_type_fully = wip_ty.index });
2851 try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
28522852 try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .decl = new_decl_index }));
28532853 return Air.internedToRef(wip_ty.finish(ip, new_decl_index, new_namespace_index));
28542854}
......@@ -3353,7 +3353,7 @@ fn zirUnionDecl(
33533353 }
33543354
33553355 try pt.finalizeAnonDecl(new_decl_index);
3356 try mod.comp.work_queue.writeItem(.{ .resolve_type_fully = wip_ty.index });
3356 try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
33573357 try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .decl = new_decl_index }));
33583358 return Air.internedToRef(wip_ty.finish(ip, new_decl_index, new_namespace_index));
33593359}
......@@ -6550,14 +6550,7 @@ fn zirSetAlignStack(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.Inst
65506550 }
65516551 sema.prev_stack_alignment_src = src;
65526552
6553 const ip = &mod.intern_pool;
6554 const a = ip.funcAnalysis(sema.func_index);
6555 if (a.stack_alignment != .none) {
6556 a.stack_alignment = @enumFromInt(@max(
6557 @intFromEnum(alignment),
6558 @intFromEnum(a.stack_alignment),
6559 ));
6560 }
6553 mod.intern_pool.funcMaxStackAlignment(sema.func_index, alignment);
65616554}
65626555
65636556fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
......@@ -6570,7 +6563,7 @@ fn zirSetCold(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData)
65706563 .needed_comptime_reason = "operand to @setCold must be comptime-known",
65716564 });
65726565 if (sema.func_index == .none) return; // does nothing outside a function
6573 ip.funcAnalysis(sema.func_index).is_cold = is_cold;
6566 ip.funcSetCold(sema.func_index, is_cold);
65746567}
65756568
65766569fn zirSetFloatMode(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstData) CompileError!void {
......@@ -7085,7 +7078,7 @@ fn zirCall(
70857078 const call_inst = try sema.analyzeCall(block, func, func_ty, callee_src, call_src, modifier, ensure_result_used, args_info, call_dbg_node, .call);
70867079
70877080 if (sema.owner_func_index == .none or
7088 !mod.intern_pool.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn)
7081 !mod.intern_pool.funcAnalysisUnordered(sema.owner_func_index).calls_or_awaits_errorable_fn)
70897082 {
70907083 // No errorable fn actually called; we have no error return trace
70917084 input_is_error = false;
......@@ -7793,7 +7786,7 @@ fn analyzeCall(
77937786 _ = ics.callee();
77947787
77957788 if (!inlining.has_comptime_args) {
7796 if (module_fn.analysis(ip).state == .sema_failure)
7789 if (module_fn.analysisUnordered(ip).state == .sema_failure)
77977790 return error.AnalysisFail;
77987791
77997792 var block_it = block;
......@@ -7816,7 +7809,7 @@ fn analyzeCall(
78167809 try sema.resolveInst(fn_info.ret_ty_ref);
78177810 const ret_ty_src: LazySrcLoc = .{ .base_node_inst = module_fn.zir_body_inst, .offset = .{ .node_offset_fn_type_ret_ty = 0 } };
78187811 sema.fn_ret_ty = try sema.analyzeAsType(&child_block, ret_ty_src, ret_ty_inst);
7819 if (module_fn.analysis(ip).inferred_error_set) {
7812 if (module_fn.analysisUnordered(ip).inferred_error_set) {
78207813 // Create a fresh inferred error set type for inline/comptime calls.
78217814 const ies = try sema.arena.create(InferredErrorSet);
78227815 ies.* = .{ .func = .none };
......@@ -7942,7 +7935,7 @@ fn analyzeCall(
79427935 if (call_dbg_node) |some| try sema.zirDbgStmt(block, some);
79437936
79447937 if (sema.owner_func_index != .none and Type.fromInterned(func_ty_info.return_type).isError(mod)) {
7945 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;
7938 ip.funcSetCallsOrAwaitsErrorableFn(sema.owner_func_index);
79467939 }
79477940
79487941 if (try sema.resolveValue(func)) |func_val| {
......@@ -8386,7 +8379,7 @@ fn instantiateGenericCall(
83868379 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern();
83878380
83888381 const callee = zcu.funcInfo(callee_index);
8389 callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota);
8382 callee.maxBranchQuota(ip, sema.branch_quota);
83908383
83918384 // Make a runtime call to the new function, making sure to omit the comptime args.
83928385 const func_ty = Type.fromInterned(callee.ty);
......@@ -8408,7 +8401,7 @@ fn instantiateGenericCall(
84088401 if (sema.owner_func_index != .none and
84098402 Type.fromInterned(func_ty_info.return_type).isError(zcu))
84108403 {
8411 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;
8404 ip.funcSetCallsOrAwaitsErrorableFn(sema.owner_func_index);
84128405 }
84138406
84148407 try sema.addReferenceEntry(call_src, AnalUnit.wrap(.{ .func = callee_index }));
......@@ -8769,9 +8762,9 @@ fn zirErrorFromInt(sema: *Sema, block: *Block, extended: Zir.Inst.Extended.InstD
87698762 const int = try sema.usizeCast(block, operand_src, try value.toUnsignedIntSema(pt));
87708763 if (int > len: {
87718764 const mutate = &ip.global_error_set.mutate;
8772 mutate.mutex.lock();
8773 defer mutate.mutex.unlock();
8774 break :len mutate.list.len;
8765 mutate.map.mutex.lock();
8766 defer mutate.map.mutex.unlock();
8767 break :len mutate.names.len;
87758768 } or int == 0)
87768769 return sema.fail(block, operand_src, "integer value '{d}' represents no error", .{int});
87778770 return Air.internedToRef((try pt.intern(.{ .err = .{
......@@ -18395,7 +18388,7 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1839518388 try ty.resolveLayout(pt); // Getting alignment requires type layout
1839618389 const union_obj = mod.typeToUnion(ty).?;
1839718390 const tag_type = union_obj.loadTagType(ip);
18398 const layout = union_obj.getLayout(ip);
18391 const layout = union_obj.flagsUnordered(ip).layout;
1839918392
1840018393 const union_field_vals = try gpa.alloc(InternPool.Index, tag_type.names.len);
1840118394 defer gpa.free(union_field_vals);
......@@ -18713,8 +18706,8 @@ fn zirTypeInfo(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai
1871318706 const backing_integer_val = try pt.intern(.{ .opt = .{
1871418707 .ty = (try pt.optionalType(.type_type)).toIntern(),
1871518708 .val = if (mod.typeToPackedStruct(ty)) |packed_struct| val: {
18716 assert(Type.fromInterned(packed_struct.backingIntType(ip).*).isInt(mod));
18717 break :val packed_struct.backingIntType(ip).*;
18709 assert(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)).isInt(mod));
18710 break :val packed_struct.backingIntTypeUnordered(ip);
1871818711 } else .none,
1871918712 } });
1872018713
......@@ -19795,7 +19788,7 @@ fn restoreErrRetIndex(sema: *Sema, start_block: *Block, src: LazySrcLoc, target_
1979519788 return;
1979619789 }
1979719790
19798 if (!mod.intern_pool.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn) return;
19791 if (!mod.intern_pool.funcAnalysisUnordered(sema.owner_func_index).calls_or_awaits_errorable_fn) return;
1979919792 if (!start_block.ownerModule().error_tracing) return;
1980019793
1980119794 assert(saved_index != .none); // The .error_return_trace_index field was dropped somewhere
......@@ -21053,7 +21046,7 @@ fn getErrorReturnTrace(sema: *Sema, block: *Block) CompileError!Air.Inst.Ref {
2105321046 const opt_ptr_stack_trace_ty = try pt.optionalType(ptr_stack_trace_ty.toIntern());
2105421047
2105521048 if (sema.owner_func_index != .none and
21056 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn and
21049 ip.funcAnalysisUnordered(sema.owner_func_index).calls_or_awaits_errorable_fn and
2105721050 block.ownerModule().error_tracing)
2105821051 {
2105921052 return block.addTy(.err_return_trace, opt_ptr_stack_trace_ty);
......@@ -22201,11 +22194,11 @@ fn reifyUnion(
2220122194 if (any_aligns) {
2220222195 loaded_union.setFieldAligns(ip, field_aligns);
2220322196 }
22204 loaded_union.tagTypePtr(ip).* = enum_tag_ty;
22205 loaded_union.flagsPtr(ip).status = .have_field_types;
22197 loaded_union.setTagType(ip, enum_tag_ty);
22198 loaded_union.setStatus(ip, .have_field_types);
2220622199
2220722200 try pt.finalizeAnonDecl(new_decl_index);
22208 try mod.comp.work_queue.writeItem(.{ .resolve_type_fully = wip_ty.index });
22201 try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
2220922202 try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .decl = new_decl_index }));
2221022203 return Air.internedToRef(wip_ty.finish(ip, new_decl_index, .none));
2221122204}
......@@ -22464,15 +22457,15 @@ fn reifyStruct(
2246422457 if (opt_backing_int_val.optionalValue(mod)) |backing_int_val| {
2246522458 const backing_int_ty = backing_int_val.toType();
2246622459 try sema.checkBackingIntType(block, src, backing_int_ty, fields_bit_sum);
22467 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
22460 struct_type.setBackingIntType(ip, backing_int_ty.toIntern());
2246822461 } else {
2246922462 const backing_int_ty = try pt.intType(.unsigned, @intCast(fields_bit_sum));
22470 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
22463 struct_type.setBackingIntType(ip, backing_int_ty.toIntern());
2247122464 }
2247222465 }
2247322466
2247422467 try pt.finalizeAnonDecl(new_decl_index);
22475 try mod.comp.work_queue.writeItem(.{ .resolve_type_fully = wip_ty.index });
22468 try mod.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
2247622469 try sema.addReferenceEntry(src, AnalUnit.wrap(.{ .decl = new_decl_index }));
2247722470 return Air.internedToRef(wip_ty.finish(ip, new_decl_index, .none));
2247822471}
......@@ -28347,7 +28340,7 @@ fn unionFieldPtr(
2834728340 .is_const = union_ptr_info.flags.is_const,
2834828341 .is_volatile = union_ptr_info.flags.is_volatile,
2834928342 .address_space = union_ptr_info.flags.address_space,
28350 .alignment = if (union_obj.getLayout(ip) == .auto) blk: {
28343 .alignment = if (union_obj.flagsUnordered(ip).layout == .auto) blk: {
2835128344 const union_align = if (union_ptr_info.flags.alignment != .none)
2835228345 union_ptr_info.flags.alignment
2835328346 else
......@@ -28375,7 +28368,7 @@ fn unionFieldPtr(
2837528368 }
2837628369
2837728370 if (try sema.resolveDefinedValue(block, src, union_ptr)) |union_ptr_val| ct: {
28378 switch (union_obj.getLayout(ip)) {
28371 switch (union_obj.flagsUnordered(ip).layout) {
2837928372 .auto => if (initializing) {
2838028373 // Store to the union to initialize the tag.
2838128374 const field_tag = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
......@@ -28413,7 +28406,7 @@ fn unionFieldPtr(
2841328406 }
2841428407
2841528408 try sema.requireRuntimeBlock(block, src, null);
28416 if (!initializing and union_obj.getLayout(ip) == .auto and block.wantSafety() and
28409 if (!initializing and union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and
2841728410 union_ty.unionTagTypeSafety(mod) != null and union_obj.field_types.len > 1)
2841828411 {
2841928412 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
......@@ -28456,7 +28449,7 @@ fn unionFieldVal(
2845628449 const un = ip.indexToKey(union_val.toIntern()).un;
2845728450 const field_tag = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
2845828451 const tag_matches = un.tag == field_tag.toIntern();
28459 switch (union_obj.getLayout(ip)) {
28452 switch (union_obj.flagsUnordered(ip).layout) {
2846028453 .auto => {
2846128454 if (tag_matches) {
2846228455 return Air.internedToRef(un.val);
......@@ -28490,7 +28483,7 @@ fn unionFieldVal(
2849028483 }
2849128484
2849228485 try sema.requireRuntimeBlock(block, src, null);
28493 if (union_obj.getLayout(ip) == .auto and block.wantSafety() and
28486 if (union_obj.flagsUnordered(ip).layout == .auto and block.wantSafety() and
2849428487 union_ty.unionTagTypeSafety(zcu) != null and union_obj.field_types.len > 1)
2849528488 {
2849628489 const wanted_tag_val = try pt.enumValueFieldIndex(Type.fromInterned(union_obj.enum_tag_ty), enum_field_index);
......@@ -32037,7 +32030,7 @@ pub fn ensureDeclAnalyzed(sema: *Sema, decl_index: InternPool.DeclIndex) Compile
3203732030
3203832031 pt.ensureDeclAnalyzed(decl_index) catch |err| {
3203932032 if (sema.owner_func_index != .none) {
32040 ip.funcAnalysis(sema.owner_func_index).state = .dependency_failure;
32033 ip.funcSetAnalysisState(sema.owner_func_index, .dependency_failure);
3204132034 } else {
3204232035 sema.owner_decl.analysis = .dependency_failure;
3204332036 }
......@@ -32051,7 +32044,7 @@ fn ensureFuncBodyAnalyzed(sema: *Sema, func: InternPool.Index) CompileError!void
3205132044 const ip = &mod.intern_pool;
3205232045 pt.ensureFuncBodyAnalyzed(func) catch |err| {
3205332046 if (sema.owner_func_index != .none) {
32054 ip.funcAnalysis(sema.owner_func_index).state = .dependency_failure;
32047 ip.funcSetAnalysisState(sema.owner_func_index, .dependency_failure);
3205532048 } else {
3205632049 sema.owner_decl.analysis = .dependency_failure;
3205732050 }
......@@ -32397,7 +32390,7 @@ fn analyzeIsNonErrComptimeOnly(
3239732390 // If the error set is empty, we must return a comptime true or false.
3239832391 // However we want to avoid unnecessarily resolving an inferred error set
3239932392 // in case it is already non-empty.
32400 switch (ip.funcIesResolved(func_index).*) {
32393 switch (ip.funcIesResolvedUnordered(func_index)) {
3240132394 .anyerror_type => break :blk,
3240232395 .none => {},
3240332396 else => |i| if (ip.indexToKey(i).error_set_type.names.len != 0) break :blk,
......@@ -33466,7 +33459,7 @@ fn wrapErrorUnionSet(
3346633459 .inferred_error_set_type => |func_index| ok: {
3346733460 // We carefully do this in an order that avoids unnecessarily
3346833461 // resolving the destination error set type.
33469 switch (ip.funcIesResolved(func_index).*) {
33462 switch (ip.funcIesResolvedUnordered(func_index)) {
3347033463 .anyerror_type => break :ok,
3347133464 .none => if (.ok == try sema.coerceInMemoryAllowedErrorSets(block, dest_err_set_ty, inst_ty, inst_src, inst_src)) {
3347233465 break :ok;
......@@ -35071,33 +35064,25 @@ pub fn resolveStructAlignment(
3507135064
3507235065 assert(sema.ownerUnit().unwrap().decl == struct_type.decl.unwrap().?);
3507335066
35074 assert(struct_type.flagsPtr(ip).alignment == .none);
3507535067 assert(struct_type.layout != .@"packed");
35068 assert(struct_type.flagsUnordered(ip).alignment == .none);
3507635069
35077 if (struct_type.flagsPtr(ip).field_types_wip) {
35078 // We'll guess "pointer-aligned", if the struct has an
35079 // underaligned pointer field then some allocations
35080 // might require explicit alignment.
35081 struct_type.flagsPtr(ip).assumed_pointer_aligned = true;
35082 const result = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
35083 struct_type.flagsPtr(ip).alignment = result;
35084 return;
35085 }
35070 const ptr_align = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
35071
35072 // We'll guess "pointer-aligned", if the struct has an
35073 // underaligned pointer field then some allocations
35074 // might require explicit alignment.
35075 if (struct_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;
3508635076
3508735077 try sema.resolveTypeFieldsStruct(ty, struct_type);
3508835078
35089 if (struct_type.setAlignmentWip(ip)) {
35090 // We'll guess "pointer-aligned", if the struct has an
35091 // underaligned pointer field then some allocations
35092 // might require explicit alignment.
35093 struct_type.flagsPtr(ip).assumed_pointer_aligned = true;
35094 const result = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
35095 struct_type.flagsPtr(ip).alignment = result;
35096 return;
35097 }
35079 // We'll guess "pointer-aligned", if the struct has an
35080 // underaligned pointer field then some allocations
35081 // might require explicit alignment.
35082 if (struct_type.assumePointerAlignedIfWip(ip, ptr_align)) return;
3509835083 defer struct_type.clearAlignmentWip(ip);
3509935084
35100 var result: Alignment = .@"1";
35085 var alignment: Alignment = .@"1";
3510135086
3510235087 for (0..struct_type.field_types.len) |i| {
3510335088 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
......@@ -35109,10 +35094,10 @@ pub fn resolveStructAlignment(
3510935094 struct_type.layout,
3511035095 .sema,
3511135096 );
35112 result = result.maxStrict(field_align);
35097 alignment = alignment.maxStrict(field_align);
3511335098 }
3511435099
35115 struct_type.flagsPtr(ip).alignment = result;
35100 struct_type.setAlignment(ip, alignment);
3511635101}
3511735102
3511835103pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
......@@ -35177,7 +35162,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3517735162 big_align = big_align.maxStrict(field_align.*);
3517835163 }
3517935164
35180 if (struct_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35165 if (struct_type.flagsUnordered(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
3518135166 const msg = try sema.errMsg(
3518235167 ty.srcLoc(zcu),
3518335168 "struct layout depends on it having runtime bits",
......@@ -35186,7 +35171,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3518635171 return sema.failWithOwnedErrorMsg(null, msg);
3518735172 }
3518835173
35189 if (struct_type.flagsPtr(ip).assumed_pointer_aligned and
35174 if (struct_type.flagsUnordered(ip).assumed_pointer_aligned and
3519035175 big_align.compareStrict(.neq, Alignment.fromByteUnits(@divExact(zcu.getTarget().ptrBitWidth(), 8))))
3519135176 {
3519235177 const msg = try sema.errMsg(
......@@ -35254,10 +35239,7 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3525435239 offsets[i] = @intCast(aligns[i].forward(offset));
3525535240 offset = offsets[i] + sizes[i];
3525635241 }
35257 struct_type.size(ip).* = @intCast(big_align.forward(offset));
35258 const flags = struct_type.flagsPtr(ip);
35259 flags.alignment = big_align;
35260 flags.layout_resolved = true;
35242 struct_type.setLayoutResolved(ip, @intCast(big_align.forward(offset)), big_align);
3526135243 _ = try sema.typeRequiresComptime(ty);
3526235244}
3526335245
......@@ -35350,13 +35332,13 @@ fn semaBackingIntType(pt: Zcu.PerThread, struct_type: InternPool.LoadedStructTyp
3535035332 };
3535135333
3535235334 try sema.checkBackingIntType(&block, backing_int_src, backing_int_ty, fields_bit_sum);
35353 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
35335 struct_type.setBackingIntType(ip, backing_int_ty.toIntern());
3535435336 } else {
3535535337 if (fields_bit_sum > std.math.maxInt(u16)) {
3535635338 return sema.fail(&block, block.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
3535735339 }
3535835340 const backing_int_ty = try pt.intType(.unsigned, @intCast(fields_bit_sum));
35359 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
35341 struct_type.setBackingIntType(ip, backing_int_ty.toIntern());
3536035342 }
3536135343
3536235344 try sema.flushExports();
......@@ -35430,15 +35412,12 @@ pub fn resolveUnionAlignment(
3543035412
3543135413 assert(!union_type.haveLayout(ip));
3543235414
35433 if (union_type.flagsPtr(ip).status == .field_types_wip) {
35434 // We'll guess "pointer-aligned", if the union has an
35435 // underaligned pointer field then some allocations
35436 // might require explicit alignment.
35437 union_type.flagsPtr(ip).assumed_pointer_aligned = true;
35438 const result = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
35439 union_type.flagsPtr(ip).alignment = result;
35440 return;
35441 }
35415 const ptr_align = Alignment.fromByteUnits(@divExact(target.ptrBitWidth(), 8));
35416
35417 // We'll guess "pointer-aligned", if the union has an
35418 // underaligned pointer field then some allocations
35419 // might require explicit alignment.
35420 if (union_type.assumePointerAlignedIfFieldTypesWip(ip, ptr_align)) return;
3544235421
3544335422 try sema.resolveTypeFieldsUnion(ty, union_type);
3544435423
......@@ -35456,7 +35435,7 @@ pub fn resolveUnionAlignment(
3545635435 max_align = max_align.max(field_align);
3545735436 }
3545835437
35459 union_type.flagsPtr(ip).alignment = max_align;
35438 union_type.setAlignment(ip, max_align);
3546035439}
3546135440
3546235441/// This logic must be kept in sync with `Module.getUnionLayout`.
......@@ -35471,7 +35450,8 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3547135450
3547235451 assert(sema.ownerUnit().unwrap().decl == union_type.decl);
3547335452
35474 switch (union_type.flagsPtr(ip).status) {
35453 const old_flags = union_type.flagsUnordered(ip);
35454 switch (old_flags.status) {
3547535455 .none, .have_field_types => {},
3547635456 .field_types_wip, .layout_wip => {
3547735457 const msg = try sema.errMsg(
......@@ -35484,12 +35464,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3548435464 .have_layout, .fully_resolved_wip, .fully_resolved => return,
3548535465 }
3548635466
35487 const prev_status = union_type.flagsPtr(ip).status;
35488 errdefer if (union_type.flagsPtr(ip).status == .layout_wip) {
35489 union_type.flagsPtr(ip).status = prev_status;
35490 };
35467 errdefer union_type.setStatusIfLayoutWip(ip, old_flags.status);
3549135468
35492 union_type.flagsPtr(ip).status = .layout_wip;
35469 union_type.setStatus(ip, .layout_wip);
3549335470
3549435471 var max_size: u64 = 0;
3549535472 var max_align: Alignment = .@"1";
......@@ -35516,8 +35493,8 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3551635493 max_align = max_align.max(field_align);
3551735494 }
3551835495
35519 const flags = union_type.flagsPtr(ip);
35520 const has_runtime_tag = flags.runtime_tag.hasTag() and try sema.typeHasRuntimeBits(Type.fromInterned(union_type.enum_tag_ty));
35496 const has_runtime_tag = union_type.flagsUnordered(ip).runtime_tag.hasTag() and
35497 try sema.typeHasRuntimeBits(Type.fromInterned(union_type.enum_tag_ty));
3552135498 const size, const alignment, const padding = if (has_runtime_tag) layout: {
3552235499 const enum_tag_type = Type.fromInterned(union_type.enum_tag_ty);
3552335500 const tag_align = try sema.typeAbiAlignment(enum_tag_type);
......@@ -35551,12 +35528,9 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3555135528 break :layout .{ size, max_align.max(tag_align), padding };
3555235529 } else .{ max_align.forward(max_size), max_align, 0 };
3555335530
35554 union_type.size(ip).* = @intCast(size);
35555 union_type.padding(ip).* = padding;
35556 flags.alignment = alignment;
35557 flags.status = .have_layout;
35531 union_type.setHaveLayout(ip, @intCast(size), padding, alignment);
3555835532
35559 if (union_type.flagsPtr(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
35533 if (union_type.flagsUnordered(ip).assumed_runtime_bits and !(try sema.typeHasRuntimeBits(ty))) {
3556035534 const msg = try sema.errMsg(
3556135535 ty.srcLoc(pt.zcu),
3556235536 "union layout depends on it having runtime bits",
......@@ -35565,7 +35539,7 @@ pub fn resolveUnionLayout(sema: *Sema, ty: Type) SemaError!void {
3556535539 return sema.failWithOwnedErrorMsg(null, msg);
3556635540 }
3556735541
35568 if (union_type.flagsPtr(ip).assumed_pointer_aligned and
35542 if (union_type.flagsUnordered(ip).assumed_pointer_aligned and
3556935543 alignment.compareStrict(.neq, Alignment.fromByteUnits(@divExact(pt.zcu.getTarget().ptrBitWidth(), 8))))
3557035544 {
3557135545 const msg = try sema.errMsg(
......@@ -35612,7 +35586,7 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
3561235586
3561335587 assert(sema.ownerUnit().unwrap().decl == union_obj.decl);
3561435588
35615 switch (union_obj.flagsPtr(ip).status) {
35589 switch (union_obj.flagsUnordered(ip).status) {
3561635590 .none, .have_field_types, .field_types_wip, .layout_wip, .have_layout => {},
3561735591 .fully_resolved_wip, .fully_resolved => return,
3561835592 }
......@@ -35621,15 +35595,15 @@ pub fn resolveUnionFully(sema: *Sema, ty: Type) SemaError!void {
3562135595 // After we have resolve union layout we have to go over the fields again to
3562235596 // make sure pointer fields get their child types resolved as well.
3562335597 // See also similar code for structs.
35624 const prev_status = union_obj.flagsPtr(ip).status;
35625 errdefer union_obj.flagsPtr(ip).status = prev_status;
35598 const prev_status = union_obj.flagsUnordered(ip).status;
35599 errdefer union_obj.setStatus(ip, prev_status);
3562635600
35627 union_obj.flagsPtr(ip).status = .fully_resolved_wip;
35601 union_obj.setStatus(ip, .fully_resolved_wip);
3562835602 for (0..union_obj.field_types.len) |field_index| {
3562935603 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[field_index]);
3563035604 try field_ty.resolveFully(pt);
3563135605 }
35632 union_obj.flagsPtr(ip).status = .fully_resolved;
35606 union_obj.setStatus(ip, .fully_resolved);
3563335607 }
3563435608
3563535609 // And let's not forget comptime-only status.
......@@ -35662,7 +35636,7 @@ pub fn resolveTypeFieldsStruct(
3566235636
3566335637 if (struct_type.haveFieldTypes(ip)) return;
3566435638
35665 if (struct_type.setTypesWip(ip)) {
35639 if (struct_type.setFieldTypesWip(ip)) {
3566635640 const msg = try sema.errMsg(
3566735641 Type.fromInterned(ty).srcLoc(zcu),
3566835642 "struct '{}' depends on itself",
......@@ -35670,7 +35644,7 @@ pub fn resolveTypeFieldsStruct(
3567035644 );
3567135645 return sema.failWithOwnedErrorMsg(null, msg);
3567235646 }
35673 defer struct_type.clearTypesWip(ip);
35647 defer struct_type.clearFieldTypesWip(ip);
3567435648
3567535649 semaStructFields(pt, sema.arena, struct_type) catch |err| switch (err) {
3567635650 error.AnalysisFail => {
......@@ -35739,7 +35713,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3573935713 },
3574035714 else => {},
3574135715 }
35742 switch (union_type.flagsPtr(ip).status) {
35716 switch (union_type.flagsUnordered(ip).status) {
3574335717 .none => {},
3574435718 .field_types_wip => {
3574535719 const msg = try sema.errMsg(
......@@ -35757,8 +35731,8 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3575735731 => return,
3575835732 }
3575935733
35760 union_type.flagsPtr(ip).status = .field_types_wip;
35761 errdefer union_type.flagsPtr(ip).status = .none;
35734 union_type.setStatus(ip, .field_types_wip);
35735 errdefer union_type.setStatus(ip, .none);
3576235736 semaUnionFields(pt, sema.arena, union_type) catch |err| switch (err) {
3576335737 error.AnalysisFail => {
3576435738 if (owner_decl.analysis == .complete) {
......@@ -35769,7 +35743,7 @@ pub fn resolveTypeFieldsUnion(sema: *Sema, ty: Type, union_type: InternPool.Load
3576935743 error.OutOfMemory => return error.OutOfMemory,
3577035744 error.ComptimeBreak, error.ComptimeReturn, error.GenericPoison => unreachable,
3577135745 };
35772 union_type.flagsPtr(ip).status = .have_field_types;
35746 union_type.setStatus(ip, .have_field_types);
3577335747}
3577435748
3577535749/// Returns a normal error set corresponding to the fully populated inferred
......@@ -35790,10 +35764,10 @@ fn resolveInferredErrorSet(
3579035764
3579135765 // TODO: during an incremental update this might not be `.none`, but the
3579235766 // function might be out-of-date!
35793 const resolved_ty = func.resolvedErrorSet(ip).*;
35767 const resolved_ty = func.resolvedErrorSetUnordered(ip);
3579435768 if (resolved_ty != .none) return resolved_ty;
3579535769
35796 if (func.analysis(ip).state == .in_progress)
35770 if (func.analysisUnordered(ip).state == .in_progress)
3579735771 return sema.fail(block, src, "unable to resolve inferred error set", .{});
3579835772
3579935773 // In order to ensure that all dependencies are properly added to the set,
......@@ -35830,7 +35804,7 @@ fn resolveInferredErrorSet(
3583035804
3583135805 // This will now have been resolved by the logic at the end of `Module.analyzeFnBody`
3583235806 // which calls `resolveInferredErrorSetPtr`.
35833 const final_resolved_ty = func.resolvedErrorSet(ip).*;
35807 const final_resolved_ty = func.resolvedErrorSetUnordered(ip);
3583435808 assert(final_resolved_ty != .none);
3583535809 return final_resolved_ty;
3583635810}
......@@ -35996,8 +35970,7 @@ fn semaStructFields(
3599635970 return;
3599735971 },
3599835972 .auto, .@"extern" => {
35999 struct_type.size(ip).* = 0;
36000 struct_type.flagsPtr(ip).layout_resolved = true;
35973 struct_type.setLayoutResolved(ip, 0, .none);
3600135974 return;
3600235975 },
3600335976 };
......@@ -36191,7 +36164,7 @@ fn semaStructFields(
3619136164 extra_index += zir_field.init_body_len;
3619236165 }
3619336166
36194 struct_type.clearTypesWip(ip);
36167 struct_type.clearFieldTypesWip(ip);
3619536168 if (!any_inits) struct_type.setHaveFieldInits(ip);
3619636169
3619736170 try sema.flushExports();
......@@ -36467,7 +36440,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
3646736440 }
3646836441 } else {
3646936442 // The provided type is the enum tag type.
36470 union_type.tagTypePtr(ip).* = provided_ty.toIntern();
36443 union_type.setTagType(ip, provided_ty.toIntern());
3647136444 const enum_type = switch (ip.indexToKey(provided_ty.toIntern())) {
3647236445 .enum_type => ip.loadEnumType(provided_ty.toIntern()),
3647336446 else => return sema.fail(&block_scope, tag_ty_src, "expected enum tag type, found '{}'", .{provided_ty.fmt(pt)}),
......@@ -36605,10 +36578,11 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
3660536578 }
3660636579
3660736580 if (explicit_tags_seen.len > 0) {
36608 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
36581 const tag_ty = union_type.tagTypeUnordered(ip);
36582 const tag_info = ip.loadEnumType(tag_ty);
3660936583 const enum_index = tag_info.nameIndex(ip, field_name) orelse {
3661036584 return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{
36611 field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(pt),
36585 field_name.fmt(ip), Type.fromInterned(tag_ty).fmt(pt),
3661236586 });
3661336587 };
3661436588
......@@ -36645,7 +36619,7 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
3664536619 };
3664636620 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3664736621 }
36648 const layout = union_type.getLayout(ip);
36622 const layout = union_type.flagsUnordered(ip).layout;
3664936623 if (layout == .@"extern" and
3665036624 !try sema.validateExternType(field_ty, .union_field))
3665136625 {
......@@ -36688,7 +36662,8 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
3668836662 union_type.setFieldAligns(ip, field_aligns.items);
3668936663
3669036664 if (explicit_tags_seen.len > 0) {
36691 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
36665 const tag_ty = union_type.tagTypeUnordered(ip);
36666 const tag_info = ip.loadEnumType(tag_ty);
3669236667 if (tag_info.names.len > fields_len) {
3669336668 const msg = msg: {
3669436669 const msg = try sema.errMsg(src, "enum field(s) missing in union", .{});
......@@ -36696,21 +36671,21 @@ fn semaUnionFields(pt: Zcu.PerThread, arena: Allocator, union_type: InternPool.L
3669636671
3669736672 for (tag_info.names.get(ip), 0..) |field_name, field_index| {
3669836673 if (explicit_tags_seen[field_index]) continue;
36699 try sema.addFieldErrNote(Type.fromInterned(union_type.tagTypePtr(ip).*), field_index, msg, "field '{}' missing, declared here", .{
36674 try sema.addFieldErrNote(Type.fromInterned(tag_ty), field_index, msg, "field '{}' missing, declared here", .{
3670036675 field_name.fmt(ip),
3670136676 });
3670236677 }
36703 try sema.addDeclaredHereNote(msg, Type.fromInterned(union_type.tagTypePtr(ip).*));
36678 try sema.addDeclaredHereNote(msg, Type.fromInterned(tag_ty));
3670436679 break :msg msg;
3670536680 };
3670636681 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3670736682 }
3670836683 } else if (enum_field_vals.count() > 0) {
3670936684 const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), zcu.declPtr(union_type.decl));
36710 union_type.tagTypePtr(ip).* = enum_ty;
36685 union_type.setTagType(ip, enum_ty);
3671136686 } else {
3671236687 const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, zcu.declPtr(union_type.decl));
36713 union_type.tagTypePtr(ip).* = enum_ty;
36688 union_type.setTagType(ip, enum_ty);
3671436689 }
3671536690
3671636691 try sema.flushExports();
......@@ -37086,7 +37061,7 @@ pub fn typeHasOnePossibleValue(sema: *Sema, ty: Type) CompileError!?Value {
3708637061 try ty.resolveLayout(pt);
3708737062
3708837063 const union_obj = ip.loadUnionType(ty.toIntern());
37089 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypePtr(ip).*))) orelse
37064 const tag_val = (try sema.typeHasOnePossibleValue(Type.fromInterned(union_obj.tagTypeUnordered(ip)))) orelse
3709037065 return null;
3709137066 if (union_obj.field_types.len == 0) {
3709237067 const only = try pt.intern(.{ .empty_enum_value = ty.toIntern() });
src/Type.zig+48-47
......@@ -605,17 +605,15 @@ pub fn hasRuntimeBitsAdvanced(
605605
606606 .union_type => {
607607 const union_type = ip.loadUnionType(ty.toIntern());
608 switch (union_type.flagsPtr(ip).runtime_tag) {
608 const union_flags = union_type.flagsUnordered(ip);
609 switch (union_flags.runtime_tag) {
609610 .none => {
610 if (union_type.flagsPtr(ip).status == .field_types_wip) {
611 // In this case, we guess that hasRuntimeBits() for this type is true,
612 // and then later if our guess was incorrect, we emit a compile error.
613 union_type.flagsPtr(ip).assumed_runtime_bits = true;
614 return true;
615 }
611 // In this case, we guess that hasRuntimeBits() for this type is true,
612 // and then later if our guess was incorrect, we emit a compile error.
613 if (union_type.assumeRuntimeBitsIfFieldTypesWip(ip)) return true;
616614 },
617615 .safety, .tagged => {
618 const tag_ty = union_type.tagTypePtr(ip).*;
616 const tag_ty = union_type.tagTypeUnordered(ip);
619617 // tag_ty will be `none` if this union's tag type is not resolved yet,
620618 // in which case we want control flow to continue down below.
621619 if (tag_ty != .none and
......@@ -627,8 +625,8 @@ pub fn hasRuntimeBitsAdvanced(
627625 }
628626 switch (strat) {
629627 .sema => try ty.resolveFields(pt),
630 .eager => assert(union_type.flagsPtr(ip).status.haveFieldTypes()),
631 .lazy => if (!union_type.flagsPtr(ip).status.haveFieldTypes())
628 .eager => assert(union_flags.status.haveFieldTypes()),
629 .lazy => if (!union_flags.status.haveFieldTypes())
632630 return error.NeedLazy,
633631 }
634632 for (0..union_type.field_types.len) |field_index| {
......@@ -745,8 +743,8 @@ pub fn hasWellDefinedLayout(ty: Type, mod: *Module) bool {
745743 },
746744 .union_type => {
747745 const union_type = ip.loadUnionType(ty.toIntern());
748 return switch (union_type.flagsPtr(ip).runtime_tag) {
749 .none, .safety => union_type.flagsPtr(ip).layout != .auto,
746 return switch (union_type.flagsUnordered(ip).runtime_tag) {
747 .none, .safety => union_type.flagsUnordered(ip).layout != .auto,
750748 .tagged => false,
751749 };
752750 },
......@@ -1045,7 +1043,7 @@ pub fn abiAlignmentAdvanced(
10451043 if (struct_type.layout == .@"packed") {
10461044 switch (strat) {
10471045 .sema => try ty.resolveLayout(pt),
1048 .lazy => if (struct_type.backingIntType(ip).* == .none) return .{
1046 .lazy => if (struct_type.backingIntTypeUnordered(ip) == .none) return .{
10491047 .val = Value.fromInterned(try pt.intern(.{ .int = .{
10501048 .ty = .comptime_int_type,
10511049 .storage = .{ .lazy_align = ty.toIntern() },
......@@ -1053,10 +1051,10 @@ pub fn abiAlignmentAdvanced(
10531051 },
10541052 .eager => {},
10551053 }
1056 return .{ .scalar = Type.fromInterned(struct_type.backingIntType(ip).*).abiAlignment(pt) };
1054 return .{ .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiAlignment(pt) };
10571055 }
10581056
1059 if (struct_type.flagsPtr(ip).alignment == .none) switch (strat) {
1057 if (struct_type.flagsUnordered(ip).alignment == .none) switch (strat) {
10601058 .eager => unreachable, // struct alignment not resolved
10611059 .sema => try ty.resolveStructAlignment(pt),
10621060 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
......@@ -1065,7 +1063,7 @@ pub fn abiAlignmentAdvanced(
10651063 } })) },
10661064 };
10671065
1068 return .{ .scalar = struct_type.flagsPtr(ip).alignment };
1066 return .{ .scalar = struct_type.flagsUnordered(ip).alignment };
10691067 },
10701068 .anon_struct_type => |tuple| {
10711069 var big_align: Alignment = .@"1";
......@@ -1088,7 +1086,7 @@ pub fn abiAlignmentAdvanced(
10881086 .union_type => {
10891087 const union_type = ip.loadUnionType(ty.toIntern());
10901088
1091 if (union_type.flagsPtr(ip).alignment == .none) switch (strat) {
1089 if (union_type.flagsUnordered(ip).alignment == .none) switch (strat) {
10921090 .eager => unreachable, // union layout not resolved
10931091 .sema => try ty.resolveUnionAlignment(pt),
10941092 .lazy => return .{ .val = Value.fromInterned(try pt.intern(.{ .int = .{
......@@ -1097,7 +1095,7 @@ pub fn abiAlignmentAdvanced(
10971095 } })) },
10981096 };
10991097
1100 return .{ .scalar = union_type.flagsPtr(ip).alignment };
1098 return .{ .scalar = union_type.flagsUnordered(ip).alignment };
11011099 },
11021100 .opaque_type => return .{ .scalar = .@"1" },
11031101 .enum_type => return .{
......@@ -1420,7 +1418,7 @@ pub fn abiSizeAdvanced(
14201418 .sema => try ty.resolveLayout(pt),
14211419 .lazy => switch (struct_type.layout) {
14221420 .@"packed" => {
1423 if (struct_type.backingIntType(ip).* == .none) return .{
1421 if (struct_type.backingIntTypeUnordered(ip) == .none) return .{
14241422 .val = Value.fromInterned(try pt.intern(.{ .int = .{
14251423 .ty = .comptime_int_type,
14261424 .storage = .{ .lazy_size = ty.toIntern() },
......@@ -1440,11 +1438,11 @@ pub fn abiSizeAdvanced(
14401438 }
14411439 switch (struct_type.layout) {
14421440 .@"packed" => return .{
1443 .scalar = Type.fromInterned(struct_type.backingIntType(ip).*).abiSize(pt),
1441 .scalar = Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).abiSize(pt),
14441442 },
14451443 .auto, .@"extern" => {
14461444 assert(struct_type.haveLayout(ip));
1447 return .{ .scalar = struct_type.size(ip).* };
1445 return .{ .scalar = struct_type.sizeUnordered(ip) };
14481446 },
14491447 }
14501448 },
......@@ -1464,7 +1462,7 @@ pub fn abiSizeAdvanced(
14641462 const union_type = ip.loadUnionType(ty.toIntern());
14651463 switch (strat) {
14661464 .sema => try ty.resolveLayout(pt),
1467 .lazy => if (!union_type.flagsPtr(ip).status.haveLayout()) return .{
1465 .lazy => if (!union_type.flagsUnordered(ip).status.haveLayout()) return .{
14681466 .val = Value.fromInterned(try pt.intern(.{ .int = .{
14691467 .ty = .comptime_int_type,
14701468 .storage = .{ .lazy_size = ty.toIntern() },
......@@ -1474,7 +1472,7 @@ pub fn abiSizeAdvanced(
14741472 }
14751473
14761474 assert(union_type.haveLayout(ip));
1477 return .{ .scalar = union_type.size(ip).* };
1475 return .{ .scalar = union_type.sizeUnordered(ip) };
14781476 },
14791477 .opaque_type => unreachable, // no size available
14801478 .enum_type => return .{ .scalar = Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty).abiSize(pt) },
......@@ -1788,7 +1786,7 @@ pub fn bitSizeAdvanced(
17881786 if (is_packed) try ty.resolveLayout(pt);
17891787 }
17901788 if (is_packed) {
1791 return try Type.fromInterned(struct_type.backingIntType(ip).*).bitSizeAdvanced(pt, strat);
1789 return try Type.fromInterned(struct_type.backingIntTypeUnordered(ip)).bitSizeAdvanced(pt, strat);
17921790 }
17931791 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;
17941792 },
......@@ -1808,7 +1806,7 @@ pub fn bitSizeAdvanced(
18081806 if (!is_packed) {
18091807 return (try ty.abiSizeAdvanced(pt, strat_lazy)).scalar * 8;
18101808 }
1811 assert(union_type.flagsPtr(ip).status.haveFieldTypes());
1809 assert(union_type.flagsUnordered(ip).status.haveFieldTypes());
18121810
18131811 var size: u64 = 0;
18141812 for (0..union_type.field_types.len) |field_index| {
......@@ -2056,9 +2054,10 @@ pub fn unionTagType(ty: Type, mod: *Module) ?Type {
20562054 else => return null,
20572055 }
20582056 const union_type = ip.loadUnionType(ty.toIntern());
2059 switch (union_type.flagsPtr(ip).runtime_tag) {
2057 const union_flags = union_type.flagsUnordered(ip);
2058 switch (union_flags.runtime_tag) {
20602059 .tagged => {
2061 assert(union_type.flagsPtr(ip).status.haveFieldTypes());
2060 assert(union_flags.status.haveFieldTypes());
20622061 return Type.fromInterned(union_type.enum_tag_ty);
20632062 },
20642063 else => return null,
......@@ -2135,7 +2134,7 @@ pub fn containerLayout(ty: Type, mod: *Module) std.builtin.Type.ContainerLayout
21352134 return switch (ip.indexToKey(ty.toIntern())) {
21362135 .struct_type => ip.loadStructType(ty.toIntern()).layout,
21372136 .anon_struct_type => .auto,
2138 .union_type => ip.loadUnionType(ty.toIntern()).flagsPtr(ip).layout,
2137 .union_type => ip.loadUnionType(ty.toIntern()).flagsUnordered(ip).layout,
21392138 else => unreachable,
21402139 };
21412140}
......@@ -2157,7 +2156,7 @@ pub fn errorSetIsEmpty(ty: Type, mod: *Module) bool {
21572156 .anyerror_type, .adhoc_inferred_error_set_type => false,
21582157 else => switch (ip.indexToKey(ty.toIntern())) {
21592158 .error_set_type => |error_set_type| error_set_type.names.len == 0,
2160 .inferred_error_set_type => |i| switch (ip.funcIesResolved(i).*) {
2159 .inferred_error_set_type => |i| switch (ip.funcIesResolvedUnordered(i)) {
21612160 .none, .anyerror_type => false,
21622161 else => |t| ip.indexToKey(t).error_set_type.names.len == 0,
21632162 },
......@@ -2175,7 +2174,7 @@ pub fn isAnyError(ty: Type, mod: *Module) bool {
21752174 .anyerror_type => true,
21762175 .adhoc_inferred_error_set_type => false,
21772176 else => switch (mod.intern_pool.indexToKey(ty.toIntern())) {
2178 .inferred_error_set_type => |i| ip.funcIesResolved(i).* == .anyerror_type,
2177 .inferred_error_set_type => |i| ip.funcIesResolvedUnordered(i) == .anyerror_type,
21792178 else => false,
21802179 },
21812180 };
......@@ -2200,7 +2199,7 @@ pub fn errorSetHasFieldIp(
22002199 .anyerror_type => true,
22012200 else => switch (ip.indexToKey(ty)) {
22022201 .error_set_type => |error_set_type| error_set_type.nameIndex(ip, name) != null,
2203 .inferred_error_set_type => |i| switch (ip.funcIesResolved(i).*) {
2202 .inferred_error_set_type => |i| switch (ip.funcIesResolvedUnordered(i)) {
22042203 .anyerror_type => true,
22052204 .none => false,
22062205 else => |t| ip.indexToKey(t).error_set_type.nameIndex(ip, name) != null,
......@@ -2336,7 +2335,7 @@ pub fn intInfo(starting_ty: Type, mod: *Module) InternPool.Key.IntType {
23362335 .c_ulonglong_type => return .{ .signedness = .unsigned, .bits = target.c_type_bit_size(.ulonglong) },
23372336 else => switch (ip.indexToKey(ty.toIntern())) {
23382337 .int_type => |int_type| return int_type,
2339 .struct_type => ty = Type.fromInterned(ip.loadStructType(ty.toIntern()).backingIntType(ip).*),
2338 .struct_type => ty = Type.fromInterned(ip.loadStructType(ty.toIntern()).backingIntTypeUnordered(ip)),
23402339 .enum_type => ty = Type.fromInterned(ip.loadEnumType(ty.toIntern()).tag_ty),
23412340 .vector_type => |vector_type| ty = Type.fromInterned(vector_type.child),
23422341
......@@ -2826,17 +2825,18 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se
28262825 return false;
28272826
28282827 // A struct with no fields is not comptime-only.
2829 return switch (struct_type.flagsPtr(ip).requires_comptime) {
2828 return switch (struct_type.setRequiresComptimeWip(ip)) {
28302829 .no, .wip => false,
28312830 .yes => true,
28322831 .unknown => {
28332832 assert(strat == .sema);
28342833
2835 if (struct_type.flagsPtr(ip).field_types_wip)
2834 if (struct_type.flagsUnordered(ip).field_types_wip) {
2835 struct_type.setRequiresComptime(ip, .unknown);
28362836 return false;
2837 }
28372838
2838 struct_type.flagsPtr(ip).requires_comptime = .wip;
2839 errdefer struct_type.flagsPtr(ip).requires_comptime = .unknown;
2839 errdefer struct_type.setRequiresComptime(ip, .unknown);
28402840
28412841 try ty.resolveFields(pt);
28422842
......@@ -2849,12 +2849,12 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se
28492849 // be considered resolved. Comptime-only types
28502850 // still maintain a layout of their
28512851 // runtime-known fields.
2852 struct_type.flagsPtr(ip).requires_comptime = .yes;
2852 struct_type.setRequiresComptime(ip, .yes);
28532853 return true;
28542854 }
28552855 }
28562856
2857 struct_type.flagsPtr(ip).requires_comptime = .no;
2857 struct_type.setRequiresComptime(ip, .no);
28582858 return false;
28592859 },
28602860 };
......@@ -2870,29 +2870,30 @@ pub fn comptimeOnlyAdvanced(ty: Type, pt: Zcu.PerThread, strat: ResolveStrat) Se
28702870
28712871 .union_type => {
28722872 const union_type = ip.loadUnionType(ty.toIntern());
2873 switch (union_type.flagsPtr(ip).requires_comptime) {
2873 switch (union_type.setRequiresComptimeWip(ip)) {
28742874 .no, .wip => return false,
28752875 .yes => return true,
28762876 .unknown => {
28772877 assert(strat == .sema);
28782878
2879 if (union_type.flagsPtr(ip).status == .field_types_wip)
2879 if (union_type.flagsUnordered(ip).status == .field_types_wip) {
2880 union_type.setRequiresComptime(ip, .unknown);
28802881 return false;
2882 }
28812883
2882 union_type.flagsPtr(ip).requires_comptime = .wip;
2883 errdefer union_type.flagsPtr(ip).requires_comptime = .unknown;
2884 errdefer union_type.setRequiresComptime(ip, .unknown);
28842885
28852886 try ty.resolveFields(pt);
28862887
28872888 for (0..union_type.field_types.len) |field_idx| {
28882889 const field_ty = union_type.field_types.get(ip)[field_idx];
28892890 if (try Type.fromInterned(field_ty).comptimeOnlyAdvanced(pt, strat)) {
2890 union_type.flagsPtr(ip).requires_comptime = .yes;
2891 union_type.setRequiresComptime(ip, .yes);
28912892 return true;
28922893 }
28932894 }
28942895
2895 union_type.flagsPtr(ip).requires_comptime = .no;
2896 union_type.setRequiresComptime(ip, .no);
28962897 return false;
28972898 },
28982899 }
......@@ -3117,7 +3118,7 @@ pub fn errorSetNames(ty: Type, mod: *Module) InternPool.NullTerminatedString.Sli
31173118 const ip = &mod.intern_pool;
31183119 return switch (ip.indexToKey(ty.toIntern())) {
31193120 .error_set_type => |x| x.names,
3120 .inferred_error_set_type => |i| switch (ip.funcIesResolved(i).*) {
3121 .inferred_error_set_type => |i| switch (ip.funcIesResolvedUnordered(i)) {
31213122 .none => unreachable, // unresolved inferred error set
31223123 .anyerror_type => unreachable,
31233124 else => |t| ip.indexToKey(t).error_set_type.names,
......@@ -3374,7 +3375,7 @@ pub fn isTuple(ty: Type, mod: *Module) bool {
33743375 const struct_type = ip.loadStructType(ty.toIntern());
33753376 if (struct_type.layout == .@"packed") return false;
33763377 if (struct_type.decl == .none) return false;
3377 return struct_type.flagsPtr(ip).is_tuple;
3378 return struct_type.flagsUnordered(ip).is_tuple;
33783379 },
33793380 .anon_struct_type => |anon_struct| anon_struct.names.len == 0,
33803381 else => false,
......@@ -3396,7 +3397,7 @@ pub fn isTupleOrAnonStruct(ty: Type, mod: *Module) bool {
33963397 const struct_type = ip.loadStructType(ty.toIntern());
33973398 if (struct_type.layout == .@"packed") return false;
33983399 if (struct_type.decl == .none) return false;
3399 return struct_type.flagsPtr(ip).is_tuple;
3400 return struct_type.flagsUnordered(ip).is_tuple;
34003401 },
34013402 .anon_struct_type => true,
34023403 else => false,
src/Value.zig+1-1
......@@ -558,7 +558,7 @@ pub fn writeToPackedMemory(
558558 },
559559 .Union => {
560560 const union_obj = mod.typeToUnion(ty).?;
561 switch (union_obj.getLayout(ip)) {
561 switch (union_obj.flagsUnordered(ip).layout) {
562562 .auto, .@"extern" => unreachable, // Handled in non-packed writeToMemory
563563 .@"packed" => {
564564 if (val.unionTag(mod)) |union_tag| {
src/Zcu.zig+4-4
......@@ -2968,7 +2968,7 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index)
29682968 const is_outdated = mod.outdated.contains(func_as_depender) or
29692969 mod.potentially_outdated.contains(func_as_depender);
29702970
2971 switch (func.analysis(ip).state) {
2971 switch (func.analysisUnordered(ip).state) {
29722972 .none => {},
29732973 .queued => return,
29742974 // As above, we don't need to forward errors here.
......@@ -2983,13 +2983,13 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index)
29832983
29842984 // Decl itself is safely analyzed, and body analysis is not yet queued
29852985
2986 try mod.comp.work_queue.writeItem(.{ .analyze_func = func_index });
2986 try mod.comp.queueJob(.{ .analyze_func = func_index });
29872987 if (mod.emit_h != null) {
29882988 // TODO: we ideally only want to do this if the function's type changed
29892989 // since the last update
2990 try mod.comp.work_queue.writeItem(.{ .emit_h_decl = decl_index });
2990 try mod.comp.queueJob(.{ .emit_h_decl = decl_index });
29912991 }
2992 func.analysis(ip).state = .queued;
2992 func.setAnalysisState(ip, .queued);
29932993}
29942994
29952995pub const SemaDeclResult = packed struct {
src/Zcu/PerThread.zig+34-36
......@@ -641,8 +641,8 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
641641
642642 // We'll want to remember what the IES used to be before the update for
643643 // dependency invalidation purposes.
644 const old_resolved_ies = if (func.analysis(ip).inferred_error_set)
645 func.resolvedErrorSet(ip).*
644 const old_resolved_ies = if (func.analysisUnordered(ip).inferred_error_set)
645 func.resolvedErrorSetUnordered(ip)
646646 else
647647 .none;
648648
......@@ -671,7 +671,7 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
671671 zcu.deleteUnitReferences(func_as_depender);
672672 }
673673
674 switch (func.analysis(ip).state) {
674 switch (func.analysisUnordered(ip).state) {
675675 .success => if (!was_outdated) return,
676676 .sema_failure,
677677 .dependency_failure,
......@@ -693,11 +693,11 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
693693
694694 var air = pt.analyzeFnBody(func_index, sema_arena) catch |err| switch (err) {
695695 error.AnalysisFail => {
696 if (func.analysis(ip).state == .in_progress) {
696 if (func.analysisUnordered(ip).state == .in_progress) {
697697 // If this decl caused the compile error, the analysis field would
698698 // be changed to indicate it was this Decl's fault. Because this
699699 // did not happen, we infer here that it was a dependency failure.
700 func.analysis(ip).state = .dependency_failure;
700 func.setAnalysisState(ip, .dependency_failure);
701701 }
702702 return error.AnalysisFail;
703703 },
......@@ -707,8 +707,8 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
707707
708708 const invalidate_ies_deps = i: {
709709 if (!was_outdated) break :i false;
710 if (!func.analysis(ip).inferred_error_set) break :i true;
711 const new_resolved_ies = func.resolvedErrorSet(ip).*;
710 if (!func.analysisUnordered(ip).inferred_error_set) break :i true;
711 const new_resolved_ies = func.resolvedErrorSetUnordered(ip);
712712 break :i new_resolved_ies != old_resolved_ies;
713713 };
714714 if (invalidate_ies_deps) {
......@@ -729,7 +729,7 @@ pub fn ensureFuncBodyAnalyzed(pt: Zcu.PerThread, maybe_coerced_func_index: Inter
729729 return;
730730 }
731731
732 try comp.work_queue.writeItem(.{ .codegen_func = .{
732 try comp.queueJob(.{ .codegen_func = .{
733733 .func = func_index,
734734 .air = air,
735735 } });
......@@ -783,7 +783,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
783783 .{@errorName(err)},
784784 ),
785785 );
786 func.analysis(ip).state = .codegen_failure;
786 func.setAnalysisState(ip, .codegen_failure);
787787 return;
788788 },
789789 };
......@@ -797,12 +797,12 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
797797 // Correcting this failure will involve changing a type this function
798798 // depends on, hence triggering re-analysis of this function, so this
799799 // interacts correctly with incremental compilation.
800 func.analysis(ip).state = .codegen_failure;
800 func.setAnalysisState(ip, .codegen_failure);
801801 } else if (comp.bin_file) |lf| {
802802 lf.updateFunc(pt, func_index, air, liveness) catch |err| switch (err) {
803803 error.OutOfMemory => return error.OutOfMemory,
804804 error.AnalysisFail => {
805 func.analysis(ip).state = .codegen_failure;
805 func.setAnalysisState(ip, .codegen_failure);
806806 },
807807 else => {
808808 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
......@@ -812,7 +812,7 @@ pub fn linkerUpdateFunc(pt: Zcu.PerThread, func_index: InternPool.Index, air: Ai
812812 "unable to codegen: {s}",
813813 .{@errorName(err)},
814814 ));
815 func.analysis(ip).state = .codegen_failure;
815 func.setAnalysisState(ip, .codegen_failure);
816816 try zcu.retryable_failures.append(zcu.gpa, InternPool.AnalUnit.wrap(.{ .func = func_index }));
817817 },
818818 };
......@@ -903,7 +903,7 @@ fn getFileRootStruct(
903903 decl.analysis = .complete;
904904
905905 try pt.scanNamespace(namespace_index, decls, decl);
906 try zcu.comp.work_queue.writeItem(.{ .resolve_type_fully = wip_ty.index });
906 try zcu.comp.queueJob(.{ .resolve_type_fully = wip_ty.index });
907907 return wip_ty.finish(ip, decl_index, namespace_index.toOptional());
908908}
909909
......@@ -1080,7 +1080,7 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult {
10801080 const old_linksection = decl.@"linksection";
10811081 const old_addrspace = decl.@"addrspace";
10821082 const old_is_inline = if (decl.getOwnedFunction(zcu)) |prev_func|
1083 prev_func.analysis(ip).state == .inline_only
1083 prev_func.analysisUnordered(ip).state == .inline_only
10841084 else
10851085 false;
10861086
......@@ -1311,10 +1311,10 @@ fn semaDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) !Zcu.SemaDeclResult {
13111311 // codegen backend wants full access to the Decl Type.
13121312 try decl_ty.resolveFully(pt);
13131313
1314 try zcu.comp.work_queue.writeItem(.{ .codegen_decl = decl_index });
1314 try zcu.comp.queueJob(.{ .codegen_decl = decl_index });
13151315
13161316 if (result.invalidate_decl_ref and zcu.emit_h != null) {
1317 try zcu.comp.work_queue.writeItem(.{ .emit_h_decl = decl_index });
1317 try zcu.comp.queueJob(.{ .emit_h_decl = decl_index });
13181318 }
13191319 }
13201320
......@@ -1740,8 +1740,6 @@ pub fn scanNamespace(
17401740 var seen_decls: std.AutoHashMapUnmanaged(InternPool.NullTerminatedString, void) = .{};
17411741 defer seen_decls.deinit(gpa);
17421742
1743 try zcu.comp.work_queue.ensureUnusedCapacity(decls.len);
1744
17451743 namespace.decls.clearRetainingCapacity();
17461744 try namespace.decls.ensureTotalCapacity(gpa, decls.len);
17471745
......@@ -1967,7 +1965,7 @@ const ScanDeclIter = struct {
19671965 log.debug("scanDecl queue analyze_decl file='{s}' decl_name='{}' decl_index={d}", .{
19681966 namespace.fileScope(zcu).sub_file_path, decl_name.fmt(ip), decl_index,
19691967 });
1970 comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = decl_index });
1968 try comp.queueJob(.{ .analyze_decl = decl_index });
19711969 }
19721970 }
19731971
......@@ -1976,7 +1974,7 @@ const ScanDeclIter = struct {
19761974 // updated line numbers. Look into this!
19771975 // TODO Look into detecting when this would be unnecessary by storing enough state
19781976 // in `Decl` to notice that the line number did not change.
1979 comp.work_queue.writeItemAssumeCapacity(.{ .update_line_number = decl_index });
1977 try comp.queueJob(.{ .update_line_number = decl_index });
19801978 }
19811979 }
19821980};
......@@ -1991,7 +1989,7 @@ pub fn abortAnonDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) void {
19911989/// Finalize the creation of an anon decl.
19921990pub fn finalizeAnonDecl(pt: Zcu.PerThread, decl_index: Zcu.Decl.Index) Allocator.Error!void {
19931991 if (pt.zcu.declPtr(decl_index).typeOf(pt.zcu).isFnOrHasRuntimeBits(pt)) {
1994 try pt.zcu.comp.work_queue.writeItem(.{ .codegen_decl = decl_index });
1992 try pt.zcu.comp.queueJob(.{ .codegen_decl = decl_index });
19951993 }
19961994}
19971995
......@@ -2037,7 +2035,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
20372035 .fn_ret_ty = Type.fromInterned(fn_ty_info.return_type),
20382036 .fn_ret_ty_ies = null,
20392037 .owner_func_index = func_index,
2040 .branch_quota = @max(func.branchQuota(ip).*, Sema.default_branch_quota),
2038 .branch_quota = @max(func.branchQuotaUnordered(ip), Sema.default_branch_quota),
20412039 .comptime_err_ret_trace = &comptime_err_ret_trace,
20422040 };
20432041 defer sema.deinit();
......@@ -2047,14 +2045,14 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
20472045 try sema.declareDependency(.{ .src_hash = decl.zir_decl_index.unwrap().? });
20482046 try sema.declareDependency(.{ .decl_val = decl_index });
20492047
2050 if (func.analysis(ip).inferred_error_set) {
2048 if (func.analysisUnordered(ip).inferred_error_set) {
20512049 const ies = try arena.create(Sema.InferredErrorSet);
20522050 ies.* = .{ .func = func_index };
20532051 sema.fn_ret_ty_ies = ies;
20542052 }
20552053
20562054 // reset in case calls to errorable functions are removed.
2057 func.analysis(ip).calls_or_awaits_errorable_fn = false;
2055 func.setCallsOrAwaitsErrorableFn(ip, false);
20582056
20592057 // First few indexes of extra are reserved and set at the end.
20602058 const reserved_count = @typeInfo(Air.ExtraIndex).Enum.fields.len;
......@@ -2080,7 +2078,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
20802078 };
20812079 defer inner_block.instructions.deinit(gpa);
20822080
2083 const fn_info = sema.code.getFnInfo(func.zirBodyInst(ip).resolve(ip));
2081 const fn_info = sema.code.getFnInfo(func.zirBodyInstUnordered(ip).resolve(ip));
20842082
20852083 // Here we are performing "runtime semantic analysis" for a function body, which means
20862084 // we must map the parameter ZIR instructions to `arg` AIR instructions.
......@@ -2149,7 +2147,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
21492147 });
21502148 }
21512149
2152 func.analysis(ip).state = .in_progress;
2150 func.setAnalysisState(ip, .in_progress);
21532151
21542152 const last_arg_index = inner_block.instructions.items.len;
21552153
......@@ -2176,7 +2174,7 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
21762174 }
21772175
21782176 // If we don't get an error return trace from a caller, create our own.
2179 if (func.analysis(ip).calls_or_awaits_errorable_fn and
2177 if (func.analysisUnordered(ip).calls_or_awaits_errorable_fn and
21802178 mod.comp.config.any_error_tracing and
21812179 !sema.fn_ret_ty.isError(mod))
21822180 {
......@@ -2218,10 +2216,10 @@ pub fn analyzeFnBody(pt: Zcu.PerThread, func_index: InternPool.Index, arena: All
22182216 else => |e| return e,
22192217 };
22202218 assert(ies.resolved != .none);
2221 ip.funcIesResolved(func_index).* = ies.resolved;
2219 ip.funcSetIesResolved(func_index, ies.resolved);
22222220 }
22232221
2224 func.analysis(ip).state = .success;
2222 func.setAnalysisState(ip, .success);
22252223
22262224 // Finally we must resolve the return type and parameter types so that backends
22272225 // have full access to type information.
......@@ -2415,6 +2413,7 @@ fn processExportsInner(
24152413) error{OutOfMemory}!void {
24162414 const zcu = pt.zcu;
24172415 const gpa = zcu.gpa;
2416 const ip = &zcu.intern_pool;
24182417
24192418 for (export_indices) |export_idx| {
24202419 const new_export = &zcu.all_exports.items[export_idx];
......@@ -2423,7 +2422,7 @@ fn processExportsInner(
24232422 new_export.status = .failed_retryable;
24242423 try zcu.failed_exports.ensureUnusedCapacity(gpa, 1);
24252424 const msg = try Zcu.ErrorMsg.create(gpa, new_export.src, "exported symbol collision: {}", .{
2426 new_export.opts.name.fmt(&zcu.intern_pool),
2425 new_export.opts.name.fmt(ip),
24272426 });
24282427 errdefer msg.destroy(gpa);
24292428 const other_export = zcu.all_exports.items[gop.value_ptr.*];
......@@ -2443,8 +2442,7 @@ fn processExportsInner(
24432442 if (!decl.owns_tv) break :failed false;
24442443 if (decl.typeOf(zcu).zigTypeTag(zcu) != .Fn) break :failed false;
24452444 // Check if owned function failed
2446 const a = zcu.funcInfo(decl.val.toIntern()).analysis(&zcu.intern_pool);
2447 break :failed a.state != .success;
2445 break :failed zcu.funcInfo(decl.val.toIntern()).analysisUnordered(ip).state != .success;
24482446 }) {
24492447 // This `Decl` is failed, so was never sent to codegen.
24502448 // TODO: we should probably tell the backend to delete any old exports of this `Decl`?
......@@ -3072,7 +3070,7 @@ pub fn getUnionLayout(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionTyp
30723070 most_aligned_field_size = field_size;
30733071 }
30743072 }
3075 const have_tag = loaded_union.flagsPtr(ip).runtime_tag.hasTag();
3073 const have_tag = loaded_union.flagsUnordered(ip).runtime_tag.hasTag();
30763074 if (!have_tag or !Type.fromInterned(loaded_union.enum_tag_ty).hasRuntimeBits(pt)) {
30773075 return .{
30783076 .abi_size = payload_align.forward(payload_size),
......@@ -3091,7 +3089,7 @@ pub fn getUnionLayout(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionTyp
30913089 const tag_size = Type.fromInterned(loaded_union.enum_tag_ty).abiSize(pt);
30923090 const tag_align = Type.fromInterned(loaded_union.enum_tag_ty).abiAlignment(pt).max(.@"1");
30933091 return .{
3094 .abi_size = loaded_union.size(ip).*,
3092 .abi_size = loaded_union.sizeUnordered(ip),
30953093 .abi_align = tag_align.max(payload_align),
30963094 .most_aligned_field = most_aligned_field,
30973095 .most_aligned_field_size = most_aligned_field_size,
......@@ -3100,7 +3098,7 @@ pub fn getUnionLayout(pt: Zcu.PerThread, loaded_union: InternPool.LoadedUnionTyp
31003098 .payload_align = payload_align,
31013099 .tag_align = tag_align,
31023100 .tag_size = tag_size,
3103 .padding = loaded_union.padding(ip).*,
3101 .padding = loaded_union.paddingUnordered(ip),
31043102 };
31053103}
31063104
......@@ -3142,7 +3140,7 @@ pub fn unionFieldNormalAlignmentAdvanced(
31423140 strat: Type.ResolveStrat,
31433141) Zcu.SemaError!InternPool.Alignment {
31443142 const ip = &pt.zcu.intern_pool;
3145 assert(loaded_union.flagsPtr(ip).layout != .@"packed");
3143 assert(loaded_union.flagsUnordered(ip).layout != .@"packed");
31463144 const field_align = loaded_union.fieldAlign(ip, field_index);
31473145 if (field_align != .none) return field_align;
31483146 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
src/arch/arm/abi.zig+1-1
......@@ -56,7 +56,7 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread, ctx: Context) Class {
5656 .Union => {
5757 const bit_size = ty.bitSize(pt);
5858 const union_obj = pt.zcu.typeToUnion(ty).?;
59 if (union_obj.getLayout(ip) == .@"packed") {
59 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
6060 if (bit_size > 64) return .memory;
6161 return .byval;
6262 }
src/arch/riscv64/CodeGen.zig+1-1
......@@ -768,7 +768,7 @@ pub fn generate(
768768 @intFromEnum(FrameIndex.stack_frame),
769769 FrameAlloc.init(.{
770770 .size = 0,
771 .alignment = func.analysis(ip).stack_alignment.max(.@"1"),
771 .alignment = func.analysisUnordered(ip).stack_alignment.max(.@"1"),
772772 }),
773773 );
774774 function.frame_allocs.set(
src/arch/wasm/CodeGen.zig+7-7
......@@ -1011,7 +1011,7 @@ fn typeToValtype(ty: Type, pt: Zcu.PerThread) wasm.Valtype {
10111011 },
10121012 .Struct => {
10131013 if (pt.zcu.typeToPackedStruct(ty)) |packed_struct| {
1014 return typeToValtype(Type.fromInterned(packed_struct.backingIntType(ip).*), pt);
1014 return typeToValtype(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt);
10151015 } else {
10161016 return wasm.Valtype.i32;
10171017 }
......@@ -1746,7 +1746,7 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
17461746 => return ty.hasRuntimeBitsIgnoreComptime(pt),
17471747 .Union => {
17481748 if (mod.typeToUnion(ty)) |union_obj| {
1749 if (union_obj.getLayout(ip) == .@"packed") {
1749 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
17501750 return ty.abiSize(pt) > 8;
17511751 }
17521752 }
......@@ -1754,7 +1754,7 @@ fn isByRef(ty: Type, pt: Zcu.PerThread) bool {
17541754 },
17551755 .Struct => {
17561756 if (mod.typeToPackedStruct(ty)) |packed_struct| {
1757 return isByRef(Type.fromInterned(packed_struct.backingIntType(ip).*), pt);
1757 return isByRef(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt);
17581758 }
17591759 return ty.hasRuntimeBitsIgnoreComptime(pt);
17601760 },
......@@ -3377,7 +3377,7 @@ fn lowerConstant(func: *CodeGen, val: Value, ty: Type) InnerError!WValue {
33773377 assert(struct_type.layout == .@"packed");
33783378 var buf: [8]u8 = .{0} ** 8; // zero the buffer so we do not read 0xaa as integer
33793379 val.writeToPackedMemory(ty, pt, &buf, 0) catch unreachable;
3380 const backing_int_ty = Type.fromInterned(struct_type.backingIntType(ip).*);
3380 const backing_int_ty = Type.fromInterned(struct_type.backingIntTypeUnordered(ip));
33813381 const int_val = try pt.intValue(
33823382 backing_int_ty,
33833383 mem.readInt(u64, &buf, .little),
......@@ -3443,7 +3443,7 @@ fn emitUndefined(func: *CodeGen, ty: Type) InnerError!WValue {
34433443 },
34443444 .Struct => {
34453445 const packed_struct = mod.typeToPackedStruct(ty).?;
3446 return func.emitUndefined(Type.fromInterned(packed_struct.backingIntType(ip).*));
3446 return func.emitUndefined(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)));
34473447 },
34483448 else => return func.fail("Wasm TODO: emitUndefined for type: {}\n", .{ty.zigTypeTag(mod)}),
34493449 }
......@@ -3974,7 +3974,7 @@ fn airStructFieldVal(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
39743974 .Struct => result: {
39753975 const packed_struct = mod.typeToPackedStruct(struct_ty).?;
39763976 const offset = pt.structPackedFieldBitOffset(packed_struct, field_index);
3977 const backing_ty = Type.fromInterned(packed_struct.backingIntType(ip).*);
3977 const backing_ty = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
39783978 const wasm_bits = toWasmBits(backing_ty.intInfo(mod).bits) orelse {
39793979 return func.fail("TODO: airStructFieldVal for packed structs larger than 128 bits", .{});
39803980 };
......@@ -5377,7 +5377,7 @@ fn airAggregateInit(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
53775377 }
53785378 const packed_struct = mod.typeToPackedStruct(result_ty).?;
53795379 const field_types = packed_struct.field_types;
5380 const backing_type = Type.fromInterned(packed_struct.backingIntType(ip).*);
5380 const backing_type = Type.fromInterned(packed_struct.backingIntTypeUnordered(ip));
53815381
53825382 // ensure the result is zero'd
53835383 const result = try func.allocLocal(backing_type);
src/arch/wasm/abi.zig+3-3
......@@ -71,7 +71,7 @@ pub fn classifyType(ty: Type, pt: Zcu.PerThread) [2]Class {
7171 },
7272 .Union => {
7373 const union_obj = pt.zcu.typeToUnion(ty).?;
74 if (union_obj.getLayout(ip) == .@"packed") {
74 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
7575 if (ty.bitSize(pt) <= 64) return direct;
7676 return .{ .direct, .direct };
7777 }
......@@ -107,7 +107,7 @@ pub fn scalarType(ty: Type, pt: Zcu.PerThread) Type {
107107 switch (ty.zigTypeTag(mod)) {
108108 .Struct => {
109109 if (mod.typeToPackedStruct(ty)) |packed_struct| {
110 return scalarType(Type.fromInterned(packed_struct.backingIntType(ip).*), pt);
110 return scalarType(Type.fromInterned(packed_struct.backingIntTypeUnordered(ip)), pt);
111111 } else {
112112 assert(ty.structFieldCount(mod) == 1);
113113 return scalarType(ty.structFieldType(0, mod), pt);
......@@ -115,7 +115,7 @@ pub fn scalarType(ty: Type, pt: Zcu.PerThread) Type {
115115 },
116116 .Union => {
117117 const union_obj = mod.typeToUnion(ty).?;
118 if (union_obj.getLayout(ip) != .@"packed") {
118 if (union_obj.flagsUnordered(ip).layout != .@"packed") {
119119 const layout = pt.getUnionLayout(union_obj);
120120 if (layout.payload_size == 0 and layout.tag_size != 0) {
121121 return scalarType(ty.unionTagTypeSafety(mod).?, pt);
src/arch/x86_64/CodeGen.zig+1-1
......@@ -856,7 +856,7 @@ pub fn generate(
856856 @intFromEnum(FrameIndex.stack_frame),
857857 FrameAlloc.init(.{
858858 .size = 0,
859 .alignment = func.analysis(ip).stack_alignment.max(.@"1"),
859 .alignment = func.analysisUnordered(ip).stack_alignment.max(.@"1"),
860860 }),
861861 );
862862 function.frame_allocs.set(
src/arch/x86_64/abi.zig+5-5
......@@ -349,7 +349,7 @@ fn classifySystemVStruct(
349349 .@"packed" => {},
350350 }
351351 } else if (pt.zcu.typeToUnion(field_ty)) |field_loaded_union| {
352 switch (field_loaded_union.getLayout(ip)) {
352 switch (field_loaded_union.flagsUnordered(ip).layout) {
353353 .auto, .@"extern" => {
354354 byte_offset = classifySystemVUnion(result, byte_offset, field_loaded_union, pt, target);
355355 continue;
......@@ -362,11 +362,11 @@ fn classifySystemVStruct(
362362 result_class.* = result_class.combineSystemV(field_class);
363363 byte_offset += field_ty.abiSize(pt);
364364 }
365 const final_byte_offset = starting_byte_offset + loaded_struct.size(ip).*;
365 const final_byte_offset = starting_byte_offset + loaded_struct.sizeUnordered(ip);
366366 std.debug.assert(final_byte_offset == std.mem.alignForward(
367367 u64,
368368 byte_offset,
369 loaded_struct.flagsPtr(ip).alignment.toByteUnits().?,
369 loaded_struct.flagsUnordered(ip).alignment.toByteUnits().?,
370370 ));
371371 return final_byte_offset;
372372}
......@@ -390,7 +390,7 @@ fn classifySystemVUnion(
390390 .@"packed" => {},
391391 }
392392 } else if (pt.zcu.typeToUnion(field_ty)) |field_loaded_union| {
393 switch (field_loaded_union.getLayout(ip)) {
393 switch (field_loaded_union.flagsUnordered(ip).layout) {
394394 .auto, .@"extern" => {
395395 _ = classifySystemVUnion(result, starting_byte_offset, field_loaded_union, pt, target);
396396 continue;
......@@ -402,7 +402,7 @@ fn classifySystemVUnion(
402402 for (result[@intCast(starting_byte_offset / 8)..][0..field_classes.len], field_classes) |*result_class, field_class|
403403 result_class.* = result_class.combineSystemV(field_class);
404404 }
405 return starting_byte_offset + loaded_union.size(ip).*;
405 return starting_byte_offset + loaded_union.sizeUnordered(ip);
406406}
407407
408408pub const SysV = struct {
src/codegen.zig+2-2
......@@ -548,8 +548,8 @@ pub fn generateSymbol(
548548 }
549549 }
550550
551 const size = struct_type.size(ip).*;
552 const alignment = struct_type.flagsPtr(ip).alignment.toByteUnits().?;
551 const size = struct_type.sizeUnordered(ip);
552 const alignment = struct_type.flagsUnordered(ip).alignment.toByteUnits().?;
553553
554554 const padding = math.cast(
555555 usize,
src/codegen/c.zig+7-7
......@@ -1366,7 +1366,7 @@ pub const DeclGen = struct {
13661366 const loaded_union = ip.loadUnionType(ty.toIntern());
13671367 if (un.tag == .none) {
13681368 const backing_ty = try ty.unionBackingType(pt);
1369 switch (loaded_union.getLayout(ip)) {
1369 switch (loaded_union.flagsUnordered(ip).layout) {
13701370 .@"packed" => {
13711371 if (!location.isInitializer()) {
13721372 try writer.writeByte('(');
......@@ -1401,7 +1401,7 @@ pub const DeclGen = struct {
14011401 const field_index = zcu.unionTagFieldIndex(loaded_union, Value.fromInterned(un.tag)).?;
14021402 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
14031403 const field_name = loaded_union.loadTagType(ip).names.get(ip)[field_index];
1404 if (loaded_union.getLayout(ip) == .@"packed") {
1404 if (loaded_union.flagsUnordered(ip).layout == .@"packed") {
14051405 if (field_ty.hasRuntimeBits(pt)) {
14061406 if (field_ty.isPtrAtRuntime(zcu)) {
14071407 try writer.writeByte('(');
......@@ -1629,7 +1629,7 @@ pub const DeclGen = struct {
16291629 },
16301630 .union_type => {
16311631 const loaded_union = ip.loadUnionType(ty.toIntern());
1632 switch (loaded_union.getLayout(ip)) {
1632 switch (loaded_union.flagsUnordered(ip).layout) {
16331633 .auto, .@"extern" => {
16341634 if (!location.isInitializer()) {
16351635 try writer.writeByte('(');
......@@ -1792,7 +1792,7 @@ pub const DeclGen = struct {
17921792 else => unreachable,
17931793 }
17941794 }
1795 if (fn_val.getFunction(zcu)) |func| if (func.analysis(ip).is_cold)
1795 if (fn_val.getFunction(zcu)) |func| if (func.analysisUnordered(ip).is_cold)
17961796 try w.writeAll("zig_cold ");
17971797 if (fn_info.return_type == .noreturn_type) try w.writeAll("zig_noreturn ");
17981798
......@@ -5527,7 +5527,7 @@ fn fieldLocation(
55275527 .{ .field = field_index } },
55285528 .union_type => {
55295529 const loaded_union = ip.loadUnionType(container_ty.toIntern());
5530 switch (loaded_union.getLayout(ip)) {
5530 switch (loaded_union.flagsUnordered(ip).layout) {
55315531 .auto, .@"extern" => {
55325532 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
55335533 if (!field_ty.hasRuntimeBitsIgnoreComptime(pt))
......@@ -5763,7 +5763,7 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue {
57635763 .{ .field = extra.field_index },
57645764 .union_type => field_name: {
57655765 const loaded_union = ip.loadUnionType(struct_ty.toIntern());
5766 switch (loaded_union.getLayout(ip)) {
5766 switch (loaded_union.flagsUnordered(ip).layout) {
57675767 .auto, .@"extern" => {
57685768 const name = loaded_union.loadTagType(ip).names.get(ip)[extra.field_index];
57695769 break :field_name if (loaded_union.hasTag(ip))
......@@ -7267,7 +7267,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
72677267
72687268 const writer = f.object.writer();
72697269 const local = try f.allocLocal(inst, union_ty);
7270 if (loaded_union.getLayout(ip) == .@"packed") return f.moveCValue(inst, union_ty, payload);
7270 if (loaded_union.flagsUnordered(ip).layout == .@"packed") return f.moveCValue(inst, union_ty, payload);
72717271
72727272 const field: CValue = if (union_ty.unionTagTypeSafety(zcu)) |tag_ty| field: {
72737273 const layout = union_ty.unionGetLayout(pt);
src/codegen/c/Type.zig+2-2
......@@ -1744,7 +1744,7 @@ pub const Pool = struct {
17441744 .@"packed" => return pool.fromType(
17451745 allocator,
17461746 scratch,
1747 Type.fromInterned(loaded_struct.backingIntType(ip).*),
1747 Type.fromInterned(loaded_struct.backingIntTypeUnordered(ip)),
17481748 pt,
17491749 mod,
17501750 kind,
......@@ -1817,7 +1817,7 @@ pub const Pool = struct {
18171817 },
18181818 .union_type => {
18191819 const loaded_union = ip.loadUnionType(ip_index);
1820 switch (loaded_union.getLayout(ip)) {
1820 switch (loaded_union.flagsUnordered(ip).layout) {
18211821 .auto, .@"extern" => {
18221822 const has_tag = loaded_union.hasTag(ip);
18231823 const fwd_decl = try pool.getFwdDecl(allocator, .{
src/codegen/llvm.zig+17-16
......@@ -1086,7 +1086,7 @@ pub const Object = struct {
10861086 // If there is no such function in the module, it means the source code does not need it.
10871087 const name = o.builder.strtabStringIfExists(lt_errors_fn_name) orelse return;
10881088 const llvm_fn = o.builder.getGlobal(name) orelse return;
1089 const errors_len = o.pt.zcu.intern_pool.global_error_set.mutate.list.len;
1089 const errors_len = o.pt.zcu.intern_pool.global_error_set.getNamesFromMainThread().len;
10901090
10911091 var wip = try Builder.WipFunction.init(&o.builder, .{
10921092 .function = llvm_fn.ptrConst(&o.builder).kind.function,
......@@ -1385,13 +1385,14 @@ pub const Object = struct {
13851385 var attributes = try function_index.ptrConst(&o.builder).attributes.toWip(&o.builder);
13861386 defer attributes.deinit(&o.builder);
13871387
1388 if (func.analysis(ip).is_noinline) {
1388 const func_analysis = func.analysisUnordered(ip);
1389 if (func_analysis.is_noinline) {
13891390 try attributes.addFnAttr(.@"noinline", &o.builder);
13901391 } else {
13911392 _ = try attributes.removeFnAttr(.@"noinline");
13921393 }
13931394
1394 const stack_alignment = func.analysis(ip).stack_alignment;
1395 const stack_alignment = func.analysisUnordered(ip).stack_alignment;
13951396 if (stack_alignment != .none) {
13961397 try attributes.addFnAttr(.{ .alignstack = stack_alignment.toLlvm() }, &o.builder);
13971398 try attributes.addFnAttr(.@"noinline", &o.builder);
......@@ -1399,7 +1400,7 @@ pub const Object = struct {
13991400 _ = try attributes.removeFnAttr(.alignstack);
14001401 }
14011402
1402 if (func.analysis(ip).is_cold) {
1403 if (func_analysis.is_cold) {
14031404 try attributes.addFnAttr(.cold, &o.builder);
14041405 } else {
14051406 _ = try attributes.removeFnAttr(.cold);
......@@ -1624,7 +1625,7 @@ pub const Object = struct {
16241625 llvm_arg_i += 1;
16251626
16261627 const alignment = param_ty.abiAlignment(pt).toLlvm();
1627 const arg_ptr = try buildAllocaInner(&wip, param_llvm_ty, alignment, target);
1628 const arg_ptr = try buildAllocaInner(&wip, param.typeOfWip(&wip), alignment, target);
16281629 _ = try wip.store(.normal, param, arg_ptr, alignment);
16291630
16301631 args.appendAssumeCapacity(if (isByRef(param_ty, pt))
......@@ -2403,7 +2404,7 @@ pub const Object = struct {
24032404 defer gpa.free(name);
24042405
24052406 if (zcu.typeToPackedStruct(ty)) |struct_type| {
2406 const backing_int_ty = struct_type.backingIntType(ip).*;
2407 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
24072408 if (backing_int_ty != .none) {
24082409 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);
24092410 const builder_name = try o.builder.metadataString(name);
......@@ -2615,7 +2616,7 @@ pub const Object = struct {
26152616 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(pt)) continue;
26162617
26172618 const field_size = Type.fromInterned(field_ty).abiSize(pt);
2618 const field_align: InternPool.Alignment = switch (union_type.flagsPtr(ip).layout) {
2619 const field_align: InternPool.Alignment = switch (union_type.flagsUnordered(ip).layout) {
26192620 .@"packed" => .none,
26202621 .auto, .@"extern" => pt.unionFieldNormalAlignment(union_type, @intCast(field_index)),
26212622 };
......@@ -3303,7 +3304,7 @@ pub const Object = struct {
33033304 const struct_type = ip.loadStructType(t.toIntern());
33043305
33053306 if (struct_type.layout == .@"packed") {
3306 const int_ty = try o.lowerType(Type.fromInterned(struct_type.backingIntType(ip).*));
3307 const int_ty = try o.lowerType(Type.fromInterned(struct_type.backingIntTypeUnordered(ip)));
33073308 try o.type_map.put(o.gpa, t.toIntern(), int_ty);
33083309 return int_ty;
33093310 }
......@@ -3346,7 +3347,7 @@ pub const Object = struct {
33463347 // This is a zero-bit field. If there are runtime bits after this field,
33473348 // map to the next LLVM field (which we know exists): otherwise, don't
33483349 // map the field, indicating it's at the end of the struct.
3349 if (offset != struct_type.size(ip).*) {
3350 if (offset != struct_type.sizeUnordered(ip)) {
33503351 try o.struct_field_map.put(o.gpa, .{
33513352 .struct_ty = t.toIntern(),
33523353 .field_index = field_index,
......@@ -3450,7 +3451,7 @@ pub const Object = struct {
34503451 const union_obj = ip.loadUnionType(t.toIntern());
34513452 const layout = pt.getUnionLayout(union_obj);
34523453
3453 if (union_obj.flagsPtr(ip).layout == .@"packed") {
3454 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
34543455 const int_ty = try o.builder.intType(@intCast(t.bitSize(pt)));
34553456 try o.type_map.put(o.gpa, t.toIntern(), int_ty);
34563457 return int_ty;
......@@ -3697,7 +3698,7 @@ pub const Object = struct {
36973698 if (layout.payload_size == 0) return o.lowerValue(un.tag);
36983699
36993700 const union_obj = mod.typeToUnion(ty).?;
3700 const container_layout = union_obj.getLayout(ip);
3701 const container_layout = union_obj.flagsUnordered(ip).layout;
37013702
37023703 assert(container_layout == .@"packed");
37033704
......@@ -4205,7 +4206,7 @@ pub const Object = struct {
42054206 if (layout.payload_size == 0) return o.lowerValue(un.tag);
42064207
42074208 const union_obj = mod.typeToUnion(ty).?;
4208 const container_layout = union_obj.getLayout(ip);
4209 const container_layout = union_obj.flagsUnordered(ip).layout;
42094210
42104211 var need_unnamed = false;
42114212 const payload = if (un.tag != .none) p: {
......@@ -10045,7 +10046,7 @@ pub const FuncGen = struct {
1004510046 },
1004610047 .Struct => {
1004710048 if (mod.typeToPackedStruct(result_ty)) |struct_type| {
10048 const backing_int_ty = struct_type.backingIntType(ip).*;
10049 const backing_int_ty = struct_type.backingIntTypeUnordered(ip);
1004910050 assert(backing_int_ty != .none);
1005010051 const big_bits = Type.fromInterned(backing_int_ty).bitSize(pt);
1005110052 const int_ty = try o.builder.intType(@intCast(big_bits));
......@@ -10155,7 +10156,7 @@ pub const FuncGen = struct {
1015510156 const layout = union_ty.unionGetLayout(pt);
1015610157 const union_obj = mod.typeToUnion(union_ty).?;
1015710158
10158 if (union_obj.getLayout(ip) == .@"packed") {
10159 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
1015910160 const big_bits = union_ty.bitSize(pt);
1016010161 const int_llvm_ty = try o.builder.intType(@intCast(big_bits));
1016110162 const field_ty = Type.fromInterned(union_obj.field_types.get(ip)[extra.field_index]);
......@@ -11281,7 +11282,7 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E
1128111282 .struct_type => {
1128211283 const struct_type = ip.loadStructType(return_type.toIntern());
1128311284 assert(struct_type.haveLayout(ip));
11284 const size: u64 = struct_type.size(ip).*;
11285 const size: u64 = struct_type.sizeUnordered(ip);
1128511286 assert((std.math.divCeil(u64, size, 8) catch unreachable) == types_index);
1128611287 if (size % 8 > 0) {
1128711288 types_buffer[types_index - 1] = try o.builder.intType(@intCast(size % 8 * 8));
......@@ -11587,7 +11588,7 @@ const ParamTypeIterator = struct {
1158711588 .struct_type => {
1158811589 const struct_type = ip.loadStructType(ty.toIntern());
1158911590 assert(struct_type.haveLayout(ip));
11590 const size: u64 = struct_type.size(ip).*;
11591 const size: u64 = struct_type.sizeUnordered(ip);
1159111592 assert((std.math.divCeil(u64, size, 8) catch unreachable) == types_index);
1159211593 if (size % 8 > 0) {
1159311594 types_buffer[types_index - 1] =
src/codegen/spirv.zig+3-3
......@@ -1463,7 +1463,7 @@ const DeclGen = struct {
14631463 const ip = &mod.intern_pool;
14641464 const union_obj = mod.typeToUnion(ty).?;
14651465
1466 if (union_obj.getLayout(ip) == .@"packed") {
1466 if (union_obj.flagsUnordered(ip).layout == .@"packed") {
14671467 return self.todo("packed union types", .{});
14681468 }
14691469
......@@ -1735,7 +1735,7 @@ const DeclGen = struct {
17351735 };
17361736
17371737 if (struct_type.layout == .@"packed") {
1738 return try self.resolveType(Type.fromInterned(struct_type.backingIntType(ip).*), .direct);
1738 return try self.resolveType(Type.fromInterned(struct_type.backingIntTypeUnordered(ip)), .direct);
17391739 }
17401740
17411741 var member_types = std.ArrayList(IdRef).init(self.gpa);
......@@ -5081,7 +5081,7 @@ const DeclGen = struct {
50815081 const union_ty = mod.typeToUnion(ty).?;
50825082 const tag_ty = Type.fromInterned(union_ty.enum_tag_ty);
50835083
5084 if (union_ty.getLayout(ip) == .@"packed") {
5084 if (union_ty.flagsUnordered(ip).layout == .@"packed") {
50855085 unreachable; // TODO
50865086 }
50875087
src/link/Coff.zig+1-1
......@@ -1156,7 +1156,7 @@ pub fn updateFunc(self: *Coff, pt: Zcu.PerThread, func_index: InternPool.Index,
11561156 const code = switch (res) {
11571157 .ok => code_buffer.items,
11581158 .fail => |em| {
1159 func.analysis(&mod.intern_pool).state = .codegen_failure;
1159 func.setAnalysisState(&mod.intern_pool, .codegen_failure);
11601160 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
11611161 return;
11621162 },
src/link/Elf/ZigObject.zig+1-1
......@@ -1093,7 +1093,7 @@ pub fn updateFunc(
10931093 const code = switch (res) {
10941094 .ok => code_buffer.items,
10951095 .fail => |em| {
1096 func.analysis(&mod.intern_pool).state = .codegen_failure;
1096 func.setAnalysisState(&mod.intern_pool, .codegen_failure);
10971097 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
10981098 return;
10991099 },
src/link/MachO/ZigObject.zig+1-1
......@@ -699,7 +699,7 @@ pub fn updateFunc(
699699 const code = switch (res) {
700700 .ok => code_buffer.items,
701701 .fail => |em| {
702 func.analysis(&mod.intern_pool).state = .codegen_failure;
702 func.setAnalysisState(&mod.intern_pool, .codegen_failure);
703703 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
704704 return;
705705 },
src/link/Plan9.zig+1-1
......@@ -449,7 +449,7 @@ pub fn updateFunc(self: *Plan9, pt: Zcu.PerThread, func_index: InternPool.Index,
449449 const code = switch (res) {
450450 .ok => try code_buffer.toOwnedSlice(),
451451 .fail => |em| {
452 func.analysis(&mod.intern_pool).state = .codegen_failure;
452 func.setAnalysisState(&mod.intern_pool, .codegen_failure);
453453 try mod.failed_analysis.put(mod.gpa, AnalUnit.wrap(.{ .decl = decl_index }), em);
454454 return;
455455 },
src/link/Wasm/ZigObject.zig+1-1
......@@ -1051,7 +1051,7 @@ fn setupErrorsLen(zig_object: *ZigObject, wasm_file: *Wasm) !void {
10511051 const gpa = wasm_file.base.comp.gpa;
10521052 const sym_index = zig_object.findGlobalSymbol("__zig_errors_len") orelse return;
10531053
1054 const errors_len = 1 + wasm_file.base.comp.module.?.intern_pool.global_error_set.mutate.list.len;
1054 const errors_len = 1 + wasm_file.base.comp.module.?.intern_pool.global_error_set.getNamesFromMainThread().len;
10551055 // overwrite existing atom if it already exists (maybe the error set has increased)
10561056 // if not, allcoate a new atom.
10571057 const atom_index = if (wasm_file.symbol_atom.get(.{ .file = zig_object.index, .index = sym_index })) |index| blk: {
stage1/zig1.wasm
Binary files a/stage1/zig1.wasm and b/stage1/zig1.wasm differ
test/cases/compile_errors/bogus_method_call_on_slice.zig+1-1
......@@ -16,6 +16,6 @@ pub export fn entry2() void {
1616// backend=stage2
1717// target=native
1818//
19// :3:6: error: no field or member function named 'copy' in '[]const u8'
1920// :9:8: error: no field or member function named 'bar' in '@TypeOf(.{})'
2021// :12:18: error: no field or member function named 'bar' in 'struct{comptime foo: comptime_int = 1}'
21// :3:6: error: no field or member function named 'copy' in '[]const u8'
test/cases/compile_errors/compile_log.zig+2-2
......@@ -17,14 +17,14 @@ export fn baz() void {
1717// target=native
1818//
1919// :6:5: error: found compile log statement
20// :12:5: note: also here
2120// :6:5: note: also here
21// :12:5: note: also here
2222//
2323// Compile Log Output:
2424// @as(*const [5:0]u8, "begin")
2525// @as(*const [1:0]u8, "a"), @as(i32, 12), @as(*const [1:0]u8, "b"), @as([]const u8, "hi"[0..2])
2626// @as(*const [3:0]u8, "end")
27// @as(comptime_int, 4)
2827// @as(*const [5:0]u8, "begin")
2928// @as(*const [1:0]u8, "a"), @as(i32, [runtime value]), @as(*const [1:0]u8, "b"), @as([]const u8, [runtime value])
3029// @as(*const [3:0]u8, "end")
30// @as(comptime_int, 4)
test/cases/compile_errors/extern_function_with_comptime_parameter.zig+1-1
......@@ -18,6 +18,6 @@ comptime {
1818// backend=stage2
1919// target=native
2020//
21// :1:15: error: comptime parameters not allowed in function with calling convention 'C'
2122// :5:30: error: comptime parameters not allowed in function with calling convention 'C'
2223// :6:30: error: generic parameters not allowed in function with calling convention 'C'
23// :1:15: error: comptime parameters not allowed in function with calling convention 'C'
test/cases/compile_errors/invalid_store_to_comptime_field.zig+1-1
......@@ -82,6 +82,6 @@ pub export fn entry8() void {
8282// :36:29: note: default value set here
8383// :46:12: error: value stored in comptime field does not match the default value of the field
8484// :55:25: error: value stored in comptime field does not match the default value of the field
85// :68:36: error: value stored in comptime field does not match the default value of the field
8685// :61:30: error: value stored in comptime field does not match the default value of the field
8786// :59:29: note: default value set here
87// :68:36: error: value stored in comptime field does not match the default value of the field
test/cases/compile_errors/invalid_variadic_function.zig+1-1
......@@ -18,6 +18,6 @@ comptime {
1818//
1919// :1:1: error: variadic function does not support '.Unspecified' calling convention
2020// :1:1: note: supported calling conventions: '.C'
21// :2:1: error: generic function cannot be variadic
2221// :1:1: error: variadic function does not support '.Inline' calling convention
2322// :1:1: note: supported calling conventions: '.C'
23// :2:1: error: generic function cannot be variadic
test/cases/error_in_nested_declaration.zig+1-1
......@@ -26,6 +26,6 @@ pub export fn entry2() void {
2626// backend=llvm
2727// target=native
2828//
29// :17:12: error: C pointers cannot point to opaque types
3029// :6:20: error: cannot @bitCast to '[]i32'
3130// :6:20: note: use @ptrCast to cast from '[]u32'
31// :17:12: error: C pointers cannot point to opaque types