authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-04 14:16:42-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-07-04 17:51:35-07:00
log30ec43a6c78d9c8803becbea5a02edb8fae08af6
treefd827ce826b593a18c128d019eb9adffb3c2ca26
parent7ed2fbd7559ceb69ab03a8985fd7e5b591e22ab7

Zcu: extract permanent state from File

Primarily, this commit removes 2 fields from File, relying on the data being stored in the `files` field, with the key as the path digest, and the value as the struct decl corresponding to the File. This table is serialized into the compiler state that survives between incremental updates. Meanwhile, the File struct remains ephemeral data that can be reconstructed the first time it is needed by the compiler process, as well as operated on by independent worker threads. A key outcome of this commit is that there is now a stable index that can be used to refer to a File. This will be needed when serializing error messages to survive incremental compilation updates.

20 files changed, 779 insertions(+), 655 deletions(-)

src/Compilation.zig+133-101
......@@ -116,7 +116,7 @@ win32_resource_work_queue: if (build_options.only_core_functionality) void else
116116/// These jobs are to tokenize, parse, and astgen files, which may be outdated
117117/// since the last compilation, as well as scan for `@import` and queue up
118118/// additional jobs corresponding to those new files.
119astgen_work_queue: std.fifo.LinearFifo(*Module.File, .Dynamic),
119astgen_work_queue: std.fifo.LinearFifo(Zcu.File.Index, .Dynamic),
120120/// These jobs are to inspect the file system stat() and if the embedded file has changed
121121/// on disk, mark the corresponding Decl outdated and queue up an `analyze_decl`
122122/// task for it.
......@@ -1433,7 +1433,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
14331433 .work_queue = std.fifo.LinearFifo(Job, .Dynamic).init(gpa),
14341434 .c_object_work_queue = std.fifo.LinearFifo(*CObject, .Dynamic).init(gpa),
14351435 .win32_resource_work_queue = if (build_options.only_core_functionality) {} else std.fifo.LinearFifo(*Win32Resource, .Dynamic).init(gpa),
1436 .astgen_work_queue = std.fifo.LinearFifo(*Module.File, .Dynamic).init(gpa),
1436 .astgen_work_queue = std.fifo.LinearFifo(Zcu.File.Index, .Dynamic).init(gpa),
14371437 .embed_file_work_queue = std.fifo.LinearFifo(*Module.EmbedFile, .Dynamic).init(gpa),
14381438 .c_source_files = options.c_source_files,
14391439 .rc_source_files = options.rc_source_files,
......@@ -2095,13 +2095,13 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
20952095 }
20962096 }
20972097
2098 if (comp.module) |module| {
2099 module.compile_log_text.shrinkAndFree(gpa, 0);
2098 if (comp.module) |zcu| {
2099 zcu.compile_log_text.shrinkAndFree(gpa, 0);
21002100
21012101 // Make sure std.zig is inside the import_table. We unconditionally need
21022102 // it for start.zig.
2103 const std_mod = module.std_mod;
2104 _ = try module.importPkg(std_mod);
2103 const std_mod = zcu.std_mod;
2104 _ = try zcu.importPkg(std_mod);
21052105
21062106 // Normally we rely on importing std to in turn import the root source file
21072107 // in the start code, but when using the stage1 backend that won't happen,
......@@ -2110,64 +2110,65 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void {
21102110 // Likewise, in the case of `zig test`, the test runner is the root source file,
21112111 // and so there is nothing to import the main file.
21122112 if (comp.config.is_test) {
2113 _ = try module.importPkg(module.main_mod);
2113 _ = try zcu.importPkg(zcu.main_mod);
21142114 }
21152115
2116 if (module.root_mod.deps.get("compiler_rt")) |compiler_rt_mod| {
2117 _ = try module.importPkg(compiler_rt_mod);
2116 if (zcu.root_mod.deps.get("compiler_rt")) |compiler_rt_mod| {
2117 _ = try zcu.importPkg(compiler_rt_mod);
21182118 }
21192119
21202120 // Put a work item in for every known source file to detect if
21212121 // it changed, and, if so, re-compute ZIR and then queue the job
21222122 // to update it.
2123 try comp.astgen_work_queue.ensureUnusedCapacity(module.import_table.count());
2124 for (module.import_table.values()) |file| {
2123 try comp.astgen_work_queue.ensureUnusedCapacity(zcu.import_table.count());
2124 for (zcu.import_table.values(), 0..) |file, file_index_usize| {
2125 const file_index: Zcu.File.Index = @enumFromInt(file_index_usize);
21252126 if (file.mod.isBuiltin()) continue;
2126 comp.astgen_work_queue.writeItemAssumeCapacity(file);
2127 comp.astgen_work_queue.writeItemAssumeCapacity(file_index);
21272128 }
21282129
21292130 // Put a work item in for checking if any files used with `@embedFile` changed.
2130 try comp.embed_file_work_queue.ensureUnusedCapacity(module.embed_table.count());
2131 for (module.embed_table.values()) |embed_file| {
2131 try comp.embed_file_work_queue.ensureUnusedCapacity(zcu.embed_table.count());
2132 for (zcu.embed_table.values()) |embed_file| {
21322133 comp.embed_file_work_queue.writeItemAssumeCapacity(embed_file);
21332134 }
21342135
21352136 try comp.work_queue.writeItem(.{ .analyze_mod = std_mod });
21362137 if (comp.config.is_test) {
2137 try comp.work_queue.writeItem(.{ .analyze_mod = module.main_mod });
2138 try comp.work_queue.writeItem(.{ .analyze_mod = zcu.main_mod });
21382139 }
21392140
2140 if (module.root_mod.deps.get("compiler_rt")) |compiler_rt_mod| {
2141 if (zcu.root_mod.deps.get("compiler_rt")) |compiler_rt_mod| {
21412142 try comp.work_queue.writeItem(.{ .analyze_mod = compiler_rt_mod });
21422143 }
21432144 }
21442145
21452146 try comp.performAllTheWork(main_progress_node);
21462147
2147 if (comp.module) |module| {
2148 if (comp.module) |zcu| {
21482149 if (build_options.enable_debug_extensions and comp.verbose_intern_pool) {
21492150 std.debug.print("intern pool stats for '{s}':\n", .{
21502151 comp.root_name,
21512152 });
2152 module.intern_pool.dump();
2153 zcu.intern_pool.dump();
21532154 }
21542155
21552156 if (build_options.enable_debug_extensions and comp.verbose_generic_instances) {
21562157 std.debug.print("generic instances for '{s}:0x{x}':\n", .{
21572158 comp.root_name,
2158 @as(usize, @intFromPtr(module)),
2159 @as(usize, @intFromPtr(zcu)),
21592160 });
2160 module.intern_pool.dumpGenericInstances(gpa);
2161 zcu.intern_pool.dumpGenericInstances(gpa);
21612162 }
21622163
21632164 if (comp.config.is_test and comp.totalErrorCount() == 0) {
21642165 // The `test_functions` decl has been intentionally postponed until now,
21652166 // at which point we must populate it with the list of test functions that
21662167 // have been discovered and not filtered out.
2167 try module.populateTestFunctions(main_progress_node);
2168 try zcu.populateTestFunctions(main_progress_node);
21682169 }
21692170
2170 try module.processExports();
2171 try zcu.processExports();
21712172 }
21722173
21732174 if (comp.totalErrorCount() != 0) {
......@@ -2615,7 +2616,9 @@ fn resolveEmitLoc(
26152616 return slice.ptr;
26162617}
26172618
2618fn reportMultiModuleErrors(mod: *Module) !void {
2619fn reportMultiModuleErrors(zcu: *Zcu) !void {
2620 const gpa = zcu.gpa;
2621 const ip = &zcu.intern_pool;
26192622 // Some cases can give you a whole bunch of multi-module errors, which it's not helpful to
26202623 // print all of, so we'll cap the number of these to emit.
26212624 var num_errors: u32 = 0;
......@@ -2623,37 +2626,39 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26232626 // Attach the "some omitted" note to the final error message
26242627 var last_err: ?*Module.ErrorMsg = null;
26252628
2626 for (mod.import_table.values()) |file| {
2629 for (zcu.import_table.values(), 0..) |file, file_index_usize| {
26272630 if (!file.multi_pkg) continue;
26282631
26292632 num_errors += 1;
26302633 if (num_errors > max_errors) continue;
26312634
2635 const file_index: Zcu.File.Index = @enumFromInt(file_index_usize);
2636
26322637 const err = err_blk: {
26332638 // Like with errors, let's cap the number of notes to prevent a huge error spew.
26342639 const max_notes = 5;
26352640 const omitted = file.references.items.len -| max_notes;
26362641 const num_notes = file.references.items.len - omitted;
26372642
2638 const notes = try mod.gpa.alloc(Module.ErrorMsg, if (omitted > 0) num_notes + 1 else num_notes);
2639 errdefer mod.gpa.free(notes);
2643 const notes = try gpa.alloc(Module.ErrorMsg, if (omitted > 0) num_notes + 1 else num_notes);
2644 errdefer gpa.free(notes);
26402645
26412646 for (notes[0..num_notes], file.references.items[0..num_notes], 0..) |*note, ref, i| {
2642 errdefer for (notes[0..i]) |*n| n.deinit(mod.gpa);
2647 errdefer for (notes[0..i]) |*n| n.deinit(gpa);
26432648 note.* = switch (ref) {
26442649 .import => |import| try Module.ErrorMsg.init(
2645 mod.gpa,
2650 gpa,
26462651 .{
2647 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, import.file, .main_struct_inst),
2652 .base_node_inst = try ip.trackZir(gpa, zcu.filePathDigest(import.file), .main_struct_inst),
26482653 .offset = .{ .token_abs = import.token },
26492654 },
26502655 "imported from module {s}",
2651 .{import.file.mod.fully_qualified_name},
2656 .{zcu.fileByIndex(import.file).mod.fully_qualified_name},
26522657 ),
26532658 .root => |pkg| try Module.ErrorMsg.init(
2654 mod.gpa,
2659 gpa,
26552660 .{
2656 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, file, .main_struct_inst),
2661 .base_node_inst = try ip.trackZir(gpa, zcu.filePathDigest(file_index), .main_struct_inst),
26572662 .offset = .entire_file,
26582663 },
26592664 "root of module {s}",
......@@ -2661,25 +2666,25 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26612666 ),
26622667 };
26632668 }
2664 errdefer for (notes[0..num_notes]) |*n| n.deinit(mod.gpa);
2669 errdefer for (notes[0..num_notes]) |*n| n.deinit(gpa);
26652670
26662671 if (omitted > 0) {
26672672 notes[num_notes] = try Module.ErrorMsg.init(
2668 mod.gpa,
2673 gpa,
26692674 .{
2670 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, file, .main_struct_inst),
2675 .base_node_inst = try ip.trackZir(gpa, zcu.filePathDigest(file_index), .main_struct_inst),
26712676 .offset = .entire_file,
26722677 },
26732678 "{} more references omitted",
26742679 .{omitted},
26752680 );
26762681 }
2677 errdefer if (omitted > 0) notes[num_notes].deinit(mod.gpa);
2682 errdefer if (omitted > 0) notes[num_notes].deinit(gpa);
26782683
26792684 const err = try Module.ErrorMsg.create(
2680 mod.gpa,
2685 gpa,
26812686 .{
2682 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, file, .main_struct_inst),
2687 .base_node_inst = try ip.trackZir(gpa, zcu.filePathDigest(file_index), .main_struct_inst),
26832688 .offset = .entire_file,
26842689 },
26852690 "file exists in multiple modules",
......@@ -2688,8 +2693,8 @@ fn reportMultiModuleErrors(mod: *Module) !void {
26882693 err.notes = notes;
26892694 break :err_blk err;
26902695 };
2691 errdefer err.destroy(mod.gpa);
2692 try mod.failed_files.putNoClobber(mod.gpa, file, err);
2696 errdefer err.destroy(gpa);
2697 try zcu.failed_files.putNoClobber(gpa, file, err);
26932698 last_err = err;
26942699 }
26952700
......@@ -2700,15 +2705,15 @@ fn reportMultiModuleErrors(mod: *Module) !void {
27002705 // There isn't really any meaningful place to put this note, so just attach it to the
27012706 // last failed file
27022707 var note = try Module.ErrorMsg.init(
2703 mod.gpa,
2708 gpa,
27042709 err.src_loc,
27052710 "{} more errors omitted",
27062711 .{num_errors - max_errors},
27072712 );
2708 errdefer note.deinit(mod.gpa);
2713 errdefer note.deinit(gpa);
27092714
27102715 const i = err.notes.len;
2711 err.notes = try mod.gpa.realloc(err.notes, i + 1);
2716 err.notes = try gpa.realloc(err.notes, i + 1);
27122717 err.notes[i] = note;
27132718 }
27142719
......@@ -2719,8 +2724,8 @@ fn reportMultiModuleErrors(mod: *Module) !void {
27192724 // to add this flag after reporting the errors however, as otherwise
27202725 // we'd get an error for every single downstream file, which wouldn't be
27212726 // very useful.
2722 for (mod.import_table.values()) |file| {
2723 if (file.multi_pkg) file.recursiveMarkMultiPkg(mod);
2727 for (zcu.import_table.values()) |file| {
2728 if (file.multi_pkg) file.recursiveMarkMultiPkg(zcu);
27242729 }
27252730}
27262731
......@@ -2752,6 +2757,7 @@ const Header = extern struct {
27522757 first_dependency_len: u32,
27532758 dep_entries_len: u32,
27542759 free_dep_entries_len: u32,
2760 files_len: u32,
27552761 },
27562762};
27572763
......@@ -2759,7 +2765,7 @@ const Header = extern struct {
27592765/// saved, such as the target and most CLI flags. A cache hit will only occur
27602766/// when subsequent compiler invocations use the same set of flags.
27612767pub fn saveState(comp: *Compilation) !void {
2762 var bufs_list: [19]std.posix.iovec_const = undefined;
2768 var bufs_list: [21]std.posix.iovec_const = undefined;
27632769 var bufs_len: usize = 0;
27642770
27652771 const lf = comp.bin_file orelse return;
......@@ -2780,6 +2786,7 @@ pub fn saveState(comp: *Compilation) !void {
27802786 .first_dependency_len = @intCast(ip.first_dependency.count()),
27812787 .dep_entries_len = @intCast(ip.dep_entries.items.len),
27822788 .free_dep_entries_len = @intCast(ip.free_dep_entries.items.len),
2789 .files_len = @intCast(zcu.files.entries.len),
27832790 },
27842791 };
27852792 addBuf(&bufs_list, &bufs_len, mem.asBytes(&header));
......@@ -2804,8 +2811,10 @@ pub fn saveState(comp: *Compilation) !void {
28042811 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.dep_entries.items));
28052812 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.free_dep_entries.items));
28062813
2814 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(zcu.files.keys()));
2815 addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(zcu.files.values()));
2816
28072817 // TODO: compilation errors
2808 // TODO: files
28092818 // TODO: namespaces
28102819 // TODO: decls
28112820 // TODO: linker state
......@@ -3353,16 +3362,31 @@ pub fn performAllTheWork(
33533362 }
33543363 }
33553364
3356 while (comp.astgen_work_queue.readItem()) |file| {
3357 comp.thread_pool.spawnWg(&comp.astgen_wait_group, workerAstGenFile, .{
3358 comp, file, zir_prog_node, &comp.astgen_wait_group, .root,
3359 });
3360 }
3365 if (comp.module) |zcu| {
3366 {
3367 // Worker threads may append to zcu.files and zcu.import_table
3368 // so we must hold the lock while spawning those tasks, since
3369 // we access those tables in this loop.
3370 comp.mutex.lock();
3371 defer comp.mutex.unlock();
33613372
3362 while (comp.embed_file_work_queue.readItem()) |embed_file| {
3363 comp.thread_pool.spawnWg(&comp.astgen_wait_group, workerCheckEmbedFile, .{
3364 comp, embed_file,
3365 });
3373 while (comp.astgen_work_queue.readItem()) |file_index| {
3374 // Pre-load these things from our single-threaded context since they
3375 // will be needed by the worker threads.
3376 const path_digest = zcu.filePathDigest(file_index);
3377 const root_decl = zcu.fileRootDecl(file_index);
3378 const file = zcu.fileByIndex(file_index);
3379 comp.thread_pool.spawnWg(&comp.astgen_wait_group, workerAstGenFile, .{
3380 comp, file, file_index, path_digest, root_decl, zir_prog_node, &comp.astgen_wait_group, .root,
3381 });
3382 }
3383 }
3384
3385 while (comp.embed_file_work_queue.readItem()) |embed_file| {
3386 comp.thread_pool.spawnWg(&comp.astgen_wait_group, workerCheckEmbedFile, .{
3387 comp, embed_file,
3388 });
3389 }
33663390 }
33673391
33683392 while (comp.c_object_work_queue.readItem()) |c_object| {
......@@ -3426,8 +3450,8 @@ pub fn performAllTheWork(
34263450fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !void {
34273451 switch (job) {
34283452 .codegen_decl => |decl_index| {
3429 const module = comp.module.?;
3430 const decl = module.declPtr(decl_index);
3453 const zcu = comp.module.?;
3454 const decl = zcu.declPtr(decl_index);
34313455
34323456 switch (decl.analysis) {
34333457 .unreferenced => unreachable,
......@@ -3445,7 +3469,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
34453469
34463470 assert(decl.has_tv);
34473471
3448 try module.linkerUpdateDecl(decl_index);
3472 try zcu.linkerUpdateDecl(decl_index);
34493473 return;
34503474 },
34513475 }
......@@ -3454,16 +3478,16 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
34543478 const named_frame = tracy.namedFrame("codegen_func");
34553479 defer named_frame.end();
34563480
3457 const module = comp.module.?;
3481 const zcu = comp.module.?;
34583482 // This call takes ownership of `func.air`.
3459 try module.linkerUpdateFunc(func.func, func.air);
3483 try zcu.linkerUpdateFunc(func.func, func.air);
34603484 },
34613485 .analyze_func => |func| {
34623486 const named_frame = tracy.namedFrame("analyze_func");
34633487 defer named_frame.end();
34643488
3465 const module = comp.module.?;
3466 module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
3489 const zcu = comp.module.?;
3490 zcu.ensureFuncBodyAnalyzed(func) catch |err| switch (err) {
34673491 error.OutOfMemory => return error.OutOfMemory,
34683492 error.AnalysisFail => return,
34693493 };
......@@ -3472,8 +3496,8 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
34723496 if (true) @panic("regressed compiler feature: emit-h should hook into updateExports, " ++
34733497 "not decl analysis, which is too early to know about @export calls");
34743498
3475 const module = comp.module.?;
3476 const decl = module.declPtr(decl_index);
3499 const zcu = comp.module.?;
3500 const decl = zcu.declPtr(decl_index);
34773501
34783502 switch (decl.analysis) {
34793503 .unreferenced => unreachable,
......@@ -3491,7 +3515,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
34913515 defer named_frame.end();
34923516
34933517 const gpa = comp.gpa;
3494 const emit_h = module.emit_h.?;
3518 const emit_h = zcu.emit_h.?;
34953519 _ = try emit_h.decl_table.getOrPut(gpa, decl_index);
34963520 const decl_emit_h = emit_h.declPtr(decl_index);
34973521 const fwd_decl = &decl_emit_h.fwd_decl;
......@@ -3499,10 +3523,12 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
34993523 var ctypes_arena = std.heap.ArenaAllocator.init(gpa);
35003524 defer ctypes_arena.deinit();
35013525
3526 const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu);
3527
35023528 var dg: c_codegen.DeclGen = .{
35033529 .gpa = gpa,
3504 .zcu = module,
3505 .mod = module.namespacePtr(decl.src_namespace).file_scope.mod,
3530 .zcu = zcu,
3531 .mod = file_scope.mod,
35063532 .error_msg = null,
35073533 .pass = .{ .decl = decl_index },
35083534 .is_naked_fn = false,
......@@ -3531,17 +3557,17 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
35313557 }
35323558 },
35333559 .analyze_decl => |decl_index| {
3534 const module = comp.module.?;
3535 module.ensureDeclAnalyzed(decl_index) catch |err| switch (err) {
3560 const zcu = comp.module.?;
3561 zcu.ensureDeclAnalyzed(decl_index) catch |err| switch (err) {
35363562 error.OutOfMemory => return error.OutOfMemory,
35373563 error.AnalysisFail => return,
35383564 };
3539 const decl = module.declPtr(decl_index);
3565 const decl = zcu.declPtr(decl_index);
35403566 if (decl.kind == .@"test" and comp.config.is_test) {
35413567 // Tests are always emitted in test binaries. The decl_refs are created by
3542 // Module.populateTestFunctions, but this will not queue body analysis, so do
3568 // Zcu.populateTestFunctions, but this will not queue body analysis, so do
35433569 // that now.
3544 try module.ensureFuncBodyAnalysisQueued(decl.val.toIntern());
3570 try zcu.ensureFuncBodyAnalysisQueued(decl.val.toIntern());
35453571 }
35463572 },
35473573 .resolve_type_fully => |ty| {
......@@ -3559,30 +3585,30 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo
35593585 defer named_frame.end();
35603586
35613587 const gpa = comp.gpa;
3562 const module = comp.module.?;
3563 const decl = module.declPtr(decl_index);
3588 const zcu = comp.module.?;
3589 const decl = zcu.declPtr(decl_index);
35643590 const lf = comp.bin_file.?;
3565 lf.updateDeclLineNumber(module, decl_index) catch |err| {
3566 try module.failed_analysis.ensureUnusedCapacity(gpa, 1);
3567 module.failed_analysis.putAssumeCapacityNoClobber(
3591 lf.updateDeclLineNumber(zcu, decl_index) catch |err| {
3592 try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1);
3593 zcu.failed_analysis.putAssumeCapacityNoClobber(
35683594 InternPool.AnalUnit.wrap(.{ .decl = decl_index }),
3569 try Module.ErrorMsg.create(
3595 try Zcu.ErrorMsg.create(
35703596 gpa,
3571 decl.navSrcLoc(module),
3597 decl.navSrcLoc(zcu),
35723598 "unable to update line number: {s}",
35733599 .{@errorName(err)},
35743600 ),
35753601 );
35763602 decl.analysis = .codegen_failure;
3577 try module.retryable_failures.append(gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }));
3603 try zcu.retryable_failures.append(gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }));
35783604 };
35793605 },
35803606 .analyze_mod => |pkg| {
35813607 const named_frame = tracy.namedFrame("analyze_mod");
35823608 defer named_frame.end();
35833609
3584 const module = comp.module.?;
3585 module.semaPkg(pkg) catch |err| switch (err) {
3610 const zcu = comp.module.?;
3611 zcu.semaPkg(pkg) catch |err| switch (err) {
35863612 error.OutOfMemory => return error.OutOfMemory,
35873613 error.AnalysisFail => return,
35883614 };
......@@ -4015,14 +4041,17 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye
40154041const AstGenSrc = union(enum) {
40164042 root,
40174043 import: struct {
4018 importing_file: *Module.File,
4044 importing_file: Zcu.File.Index,
40194045 import_tok: std.zig.Ast.TokenIndex,
40204046 },
40214047};
40224048
40234049fn workerAstGenFile(
40244050 comp: *Compilation,
4025 file: *Module.File,
4051 file: *Zcu.File,
4052 file_index: Zcu.File.Index,
4053 path_digest: Cache.BinDigest,
4054 root_decl: Zcu.Decl.OptionalIndex,
40264055 prog_node: std.Progress.Node,
40274056 wg: *WaitGroup,
40284057 src: AstGenSrc,
......@@ -4030,12 +4059,12 @@ fn workerAstGenFile(
40304059 const child_prog_node = prog_node.start(file.sub_file_path, 0);
40314060 defer child_prog_node.end();
40324061
4033 const mod = comp.module.?;
4034 mod.astGenFile(file) catch |err| switch (err) {
4062 const zcu = comp.module.?;
4063 zcu.astGenFile(file, path_digest, root_decl) catch |err| switch (err) {
40354064 error.AnalysisFail => return,
40364065 else => {
40374066 file.status = .retryable_failure;
4038 comp.reportRetryableAstGenError(src, file, err) catch |oom| switch (oom) {
4067 comp.reportRetryableAstGenError(src, file_index, err) catch |oom| switch (oom) {
40394068 // Swallowing this error is OK because it's implied to be OOM when
40404069 // there is a missing `failed_files` error message.
40414070 error.OutOfMemory => {},
......@@ -4062,29 +4091,31 @@ fn workerAstGenFile(
40624091 // `@import("builtin")` is handled specially.
40634092 if (mem.eql(u8, import_path, "builtin")) continue;
40644093
4065 const import_result = blk: {
4094 const import_result, const imported_path_digest, const imported_root_decl = blk: {
40664095 comp.mutex.lock();
40674096 defer comp.mutex.unlock();
40684097
4069 const res = mod.importFile(file, import_path) catch continue;
4098 const res = zcu.importFile(file, import_path) catch continue;
40704099 if (!res.is_pkg) {
4071 res.file.addReference(mod.*, .{ .import = .{
4072 .file = file,
4100 res.file.addReference(zcu.*, .{ .import = .{
4101 .file = file_index,
40734102 .token = item.data.token,
40744103 } }) catch continue;
40754104 }
4076 break :blk res;
4105 const imported_path_digest = zcu.filePathDigest(res.file_index);
4106 const imported_root_decl = zcu.fileRootDecl(res.file_index);
4107 break :blk .{ res, imported_path_digest, imported_root_decl };
40774108 };
40784109 if (import_result.is_new) {
40794110 log.debug("AstGen of {s} has import '{s}'; queuing AstGen of {s}", .{
40804111 file.sub_file_path, import_path, import_result.file.sub_file_path,
40814112 });
40824113 const sub_src: AstGenSrc = .{ .import = .{
4083 .importing_file = file,
4114 .importing_file = file_index,
40844115 .import_tok = item.data.token,
40854116 } };
40864117 comp.thread_pool.spawnWg(wg, workerAstGenFile, .{
4087 comp, import_result.file, prog_node, wg, sub_src,
4118 comp, import_result.file, import_result.file_index, imported_path_digest, imported_root_decl, prog_node, wg, sub_src,
40884119 });
40894120 }
40904121 }
......@@ -4435,21 +4466,22 @@ fn reportRetryableWin32ResourceError(
44354466fn reportRetryableAstGenError(
44364467 comp: *Compilation,
44374468 src: AstGenSrc,
4438 file: *Module.File,
4469 file_index: Zcu.File.Index,
44394470 err: anyerror,
44404471) error{OutOfMemory}!void {
4441 const mod = comp.module.?;
4442 const gpa = mod.gpa;
4472 const zcu = comp.module.?;
4473 const gpa = zcu.gpa;
44434474
4475 const file = zcu.fileByIndex(file_index);
44444476 file.status = .retryable_failure;
44454477
44464478 const src_loc: Module.LazySrcLoc = switch (src) {
44474479 .root => .{
4448 .base_node_inst = try mod.intern_pool.trackZir(gpa, file, .main_struct_inst),
4480 .base_node_inst = try zcu.intern_pool.trackZir(gpa, zcu.filePathDigest(file_index), .main_struct_inst),
44494481 .offset = .entire_file,
44504482 },
44514483 .import => |info| .{
4452 .base_node_inst = try mod.intern_pool.trackZir(gpa, info.importing_file, .main_struct_inst),
4484 .base_node_inst = try zcu.intern_pool.trackZir(gpa, zcu.filePathDigest(info.importing_file), .main_struct_inst),
44534485 .offset = .{ .token_abs = info.import_tok },
44544486 },
44554487 };
......@@ -4462,7 +4494,7 @@ fn reportRetryableAstGenError(
44624494 {
44634495 comp.mutex.lock();
44644496 defer comp.mutex.unlock();
4465 try mod.failed_files.putNoClobber(gpa, file, err_msg);
4497 try zcu.failed_files.putNoClobber(gpa, file, err_msg);
44664498 }
44674499}
44684500
src/InternPool.zig+7-2
......@@ -123,9 +123,14 @@ pub const TrackedInst = extern struct {
123123 };
124124};
125125
126pub fn trackZir(ip: *InternPool, gpa: Allocator, file: *Module.File, inst: Zir.Inst.Index) Allocator.Error!TrackedInst.Index {
126pub fn trackZir(
127 ip: *InternPool,
128 gpa: Allocator,
129 path_digest: Cache.BinDigest,
130 inst: Zir.Inst.Index,
131) Allocator.Error!TrackedInst.Index {
127132 const key: TrackedInst = .{
128 .path_digest = file.path_digest,
133 .path_digest = path_digest,
129134 .inst = inst,
130135 };
131136 const gop = try ip.tracked_insts.getOrPut(gpa, key);
src/Package/Module.zig+2-6
......@@ -379,7 +379,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
379379
380380 const new_file = try arena.create(File);
381381
382 const bin_digest, const hex_digest = digest: {
382 const hex_digest = digest: {
383383 var hasher: Cache.Hasher = Cache.hasher_init;
384384 hasher.update(generated_builtin_source);
385385
......@@ -393,7 +393,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
393393 .{std.fmt.fmtSliceHexLower(&bin_digest)},
394394 ) catch unreachable;
395395
396 break :digest .{ bin_digest, hex_digest };
396 break :digest hex_digest;
397397 };
398398
399399 const builtin_sub_path = try arena.dupe(u8, "b" ++ std.fs.path.sep_str ++ hex_digest);
......@@ -443,10 +443,6 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
443443 .zir = undefined,
444444 .status = .never_loaded,
445445 .mod = new,
446 .root_decl = .none,
447 // We might as well use this digest for the File `path digest`, since there's a
448 // one-to-one correspondence here between distinct paths and distinct contents.
449 .path_digest = bin_digest,
450446 };
451447 break :b new;
452448 };
src/Sema.zig+119-101
......@@ -546,8 +546,12 @@ pub const Block = struct {
546546 };
547547 }
548548
549 pub fn getFileScope(block: *Block, mod: *Module) *Module.File {
550 return mod.namespacePtr(block.namespace).file_scope;
549 pub fn getFileScope(block: *Block, zcu: *Zcu) *Zcu.File {
550 return zcu.fileByIndex(getFileScopeIndex(block, zcu));
551 }
552
553 pub fn getFileScopeIndex(block: *Block, zcu: *Zcu) Zcu.File.Index {
554 return zcu.namespacePtr(block.namespace).file_scope;
551555 }
552556
553557 fn addTy(
......@@ -826,7 +830,17 @@ pub const Block = struct {
826830
827831 pub fn ownerModule(block: Block) *Package.Module {
828832 const zcu = block.sema.mod;
829 return zcu.namespacePtr(block.namespace).file_scope.mod;
833 return zcu.namespacePtr(block.namespace).fileScope(zcu).mod;
834 }
835
836 fn trackZir(block: *Block, inst: Zir.Inst.Index) Allocator.Error!InternPool.TrackedInst.Index {
837 const sema = block.sema;
838 const gpa = sema.gpa;
839 const zcu = sema.mod;
840 const ip = &zcu.intern_pool;
841 const file_index = block.getFileScopeIndex(zcu);
842 const path_digest = zcu.filePathDigest(file_index);
843 return ip.trackZir(gpa, path_digest, inst);
830844 }
831845};
832846
......@@ -1000,7 +1014,7 @@ fn analyzeBodyInner(
10001014 if (build_options.enable_logging) {
10011015 std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ sub_file_path: {
10021016 const path_digest = block.src_base_inst.resolveFull(&mod.intern_pool).path_digest;
1003 const index = mod.path_digest_map.getIndex(path_digest).?;
1017 const index = mod.files.getIndex(path_digest).?;
10041018 break :sub_file_path mod.import_table.values()[index].sub_file_path;
10051019 }, inst });
10061020 }
......@@ -2730,7 +2744,7 @@ fn zirStructDecl(
27302744 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
27312745 const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand);
27322746
2733 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
2747 const tracked_inst = try block.trackZir(inst);
27342748 const src: LazySrcLoc = .{
27352749 .base_node_inst = tracked_inst,
27362750 .offset = LazySrcLoc.Offset.nodeOffset(0),
......@@ -2806,7 +2820,7 @@ fn zirStructDecl(
28062820 try ip.addDependency(
28072821 sema.gpa,
28082822 AnalUnit.wrap(.{ .decl = new_decl_index }),
2809 .{ .src_hash = try ip.trackZir(sema.gpa, block.getFileScope(mod), inst) },
2823 .{ .src_hash = try block.trackZir(inst) },
28102824 );
28112825 }
28122826
......@@ -2814,7 +2828,7 @@ fn zirStructDecl(
28142828 const new_namespace_index: InternPool.OptionalNamespaceIndex = if (true or decls_len > 0) (try mod.createNamespace(.{
28152829 .parent = block.namespace.toOptional(),
28162830 .decl_index = new_decl_index,
2817 .file_scope = block.getFileScope(mod),
2831 .file_scope = block.getFileScopeIndex(mod),
28182832 })).toOptional() else .none;
28192833 errdefer if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns);
28202834
......@@ -2947,7 +2961,7 @@ fn zirEnumDecl(
29472961 const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand);
29482962 var extra_index: usize = extra.end;
29492963
2950 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
2964 const tracked_inst = try block.trackZir(inst);
29512965 const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) };
29522966 const tag_ty_src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = .{ .node_offset_container_tag = 0 } };
29532967
......@@ -3040,9 +3054,9 @@ fn zirEnumDecl(
30403054
30413055 if (sema.mod.comp.debug_incremental) {
30423056 try mod.intern_pool.addDependency(
3043 sema.gpa,
3057 gpa,
30443058 AnalUnit.wrap(.{ .decl = new_decl_index }),
3045 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
3059 .{ .src_hash = try block.trackZir(inst) },
30463060 );
30473061 }
30483062
......@@ -3050,7 +3064,7 @@ fn zirEnumDecl(
30503064 const new_namespace_index: InternPool.OptionalNamespaceIndex = if (true or decls_len > 0) (try mod.createNamespace(.{
30513065 .parent = block.namespace.toOptional(),
30523066 .decl_index = new_decl_index,
3053 .file_scope = block.getFileScope(mod),
3067 .file_scope = block.getFileScopeIndex(mod),
30543068 })).toOptional() else .none;
30553069 errdefer if (!done) if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns);
30563070
......@@ -3232,7 +3246,7 @@ fn zirUnionDecl(
32323246 const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand);
32333247 var extra_index: usize = extra.end;
32343248
3235 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
3249 const tracked_inst = try block.trackZir(inst);
32363250 const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) };
32373251
32383252 extra_index += @intFromBool(small.has_tag_type);
......@@ -3306,9 +3320,9 @@ fn zirUnionDecl(
33063320
33073321 if (sema.mod.comp.debug_incremental) {
33083322 try mod.intern_pool.addDependency(
3309 sema.gpa,
3323 gpa,
33103324 AnalUnit.wrap(.{ .decl = new_decl_index }),
3311 .{ .src_hash = try mod.intern_pool.trackZir(sema.gpa, block.getFileScope(mod), inst) },
3325 .{ .src_hash = try block.trackZir(inst) },
33123326 );
33133327 }
33143328
......@@ -3316,7 +3330,7 @@ fn zirUnionDecl(
33163330 const new_namespace_index: InternPool.OptionalNamespaceIndex = if (true or decls_len > 0) (try mod.createNamespace(.{
33173331 .parent = block.namespace.toOptional(),
33183332 .decl_index = new_decl_index,
3319 .file_scope = block.getFileScope(mod),
3333 .file_scope = block.getFileScopeIndex(mod),
33203334 })).toOptional() else .none;
33213335 errdefer if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns);
33223336
......@@ -3348,7 +3362,7 @@ fn zirOpaqueDecl(
33483362 const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand);
33493363 var extra_index: usize = extra.end;
33503364
3351 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
3365 const tracked_inst = try block.trackZir(inst);
33523366 const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) };
33533367
33543368 const captures_len = if (small.has_captures_len) blk: {
......@@ -3397,14 +3411,14 @@ fn zirOpaqueDecl(
33973411 try ip.addDependency(
33983412 gpa,
33993413 AnalUnit.wrap(.{ .decl = new_decl_index }),
3400 .{ .src_hash = try ip.trackZir(gpa, block.getFileScope(mod), inst) },
3414 .{ .src_hash = try block.trackZir(inst) },
34013415 );
34023416 }
34033417
34043418 const new_namespace_index: InternPool.OptionalNamespaceIndex = if (decls_len > 0) (try mod.createNamespace(.{
34053419 .parent = block.namespace.toOptional(),
34063420 .decl_index = new_decl_index,
3407 .file_scope = block.getFileScope(mod),
3421 .file_scope = block.getFileScopeIndex(mod),
34083422 })).toOptional() else .none;
34093423 errdefer if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns);
34103424
......@@ -5893,8 +5907,8 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
58935907 const tracy = trace(@src());
58945908 defer tracy.end();
58955909
5896 const mod = sema.mod;
5897 const comp = mod.comp;
5910 const zcu = sema.mod;
5911 const comp = zcu.comp;
58985912 const gpa = sema.gpa;
58995913 const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node;
59005914 const src = parent_block.nodeOffset(pl_node.src_node);
......@@ -5940,7 +5954,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
59405954 if (!comp.config.link_libc)
59415955 try sema.errNote(src, msg, "libc headers not available; compilation does not link against libc", .{});
59425956
5943 const gop = try mod.cimport_errors.getOrPut(gpa, sema.ownerUnit());
5957 const gop = try zcu.cimport_errors.getOrPut(gpa, sema.ownerUnit());
59445958 if (!gop.found_existing) {
59455959 gop.value_ptr.* = c_import_res.errors;
59465960 c_import_res.errors = std.zig.ErrorBundle.empty;
......@@ -5984,14 +5998,16 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr
59845998 else => |e| return e,
59855999 };
59866000
5987 const result = mod.importPkg(c_import_mod) catch |err|
6001 const result = zcu.importPkg(c_import_mod) catch |err|
59886002 return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)});
59896003
5990 mod.astGenFile(result.file) catch |err|
6004 const path_digest = zcu.filePathDigest(result.file_index);
6005 const root_decl = zcu.fileRootDecl(result.file_index);
6006 zcu.astGenFile(result.file, path_digest, root_decl) catch |err|
59916007 return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)});
59926008
5993 try mod.ensureFileAnalyzed(result.file);
5994 const file_root_decl_index = result.file.root_decl.unwrap().?;
6009 try zcu.ensureFileAnalyzed(result.file_index);
6010 const file_root_decl_index = zcu.fileRootDecl(result.file_index).unwrap().?;
59956011 return sema.analyzeDeclVal(parent_block, src, file_root_decl_index);
59966012}
59976013
......@@ -6730,7 +6746,9 @@ fn lookupInNamespace(
67306746 // Skip decls which are not marked pub, which are in a different
67316747 // file than the `a.b`/`@hasDecl` syntax.
67326748 const decl = mod.declPtr(decl_index);
6733 if (decl.is_pub or (src_file == decl.getFileScope(mod) and checked_namespaces.values()[check_i])) {
6749 if (decl.is_pub or (src_file == decl.getFileScopeIndex(mod) and
6750 checked_namespaces.values()[check_i]))
6751 {
67346752 try candidates.append(gpa, decl_index);
67356753 }
67366754 }
......@@ -6741,7 +6759,7 @@ fn lookupInNamespace(
67416759 if (sub_usingnamespace_decl_index == sema.owner_decl_index) continue;
67426760 const sub_usingnamespace_decl = mod.declPtr(sub_usingnamespace_decl_index);
67436761 const sub_is_pub = entry.value_ptr.*;
6744 if (!sub_is_pub and src_file != sub_usingnamespace_decl.getFileScope(mod)) {
6762 if (!sub_is_pub and src_file != sub_usingnamespace_decl.getFileScopeIndex(mod)) {
67456763 // Skip usingnamespace decls which are not marked pub, which are in
67466764 // a different file than the `a.b`/`@hasDecl` syntax.
67476765 continue;
......@@ -6749,7 +6767,7 @@ fn lookupInNamespace(
67496767 try sema.ensureDeclAnalyzed(sub_usingnamespace_decl_index);
67506768 const ns_ty = sub_usingnamespace_decl.val.toType();
67516769 const sub_ns = mod.namespacePtrUnwrap(ns_ty.getNamespaceIndex(mod)) orelse continue;
6752 try checked_namespaces.put(gpa, sub_ns, src_file == sub_usingnamespace_decl.getFileScope(mod));
6770 try checked_namespaces.put(gpa, sub_ns, src_file == sub_usingnamespace_decl.getFileScopeIndex(mod));
67536771 }
67546772 }
67556773
......@@ -8067,20 +8085,20 @@ fn instantiateGenericCall(
80678085 call_tag: Air.Inst.Tag,
80688086 call_dbg_node: ?Zir.Inst.Index,
80698087) CompileError!Air.Inst.Ref {
8070 const mod = sema.mod;
8088 const zcu = sema.mod;
80718089 const gpa = sema.gpa;
8072 const ip = &mod.intern_pool;
8090 const ip = &zcu.intern_pool;
80738091
80748092 const func_val = try sema.resolveConstDefinedValue(block, func_src, func, .{
80758093 .needed_comptime_reason = "generic function being called must be comptime-known",
80768094 });
8077 const generic_owner = switch (mod.intern_pool.indexToKey(func_val.toIntern())) {
8095 const generic_owner = switch (zcu.intern_pool.indexToKey(func_val.toIntern())) {
80788096 .func => func_val.toIntern(),
8079 .ptr => |ptr| mod.declPtr(ptr.base_addr.decl).val.toIntern(),
8097 .ptr => |ptr| zcu.declPtr(ptr.base_addr.decl).val.toIntern(),
80808098 else => unreachable,
80818099 };
8082 const generic_owner_func = mod.intern_pool.indexToKey(generic_owner).func;
8083 const generic_owner_ty_info = mod.typeToFunc(Type.fromInterned(generic_owner_func.ty)).?;
8100 const generic_owner_func = zcu.intern_pool.indexToKey(generic_owner).func;
8101 const generic_owner_ty_info = zcu.typeToFunc(Type.fromInterned(generic_owner_func.ty)).?;
80848102
80858103 try sema.declareDependency(.{ .src_hash = generic_owner_func.zir_body_inst });
80868104
......@@ -8092,10 +8110,10 @@ fn instantiateGenericCall(
80928110 // The actual monomorphization happens via adding `func_instance` to
80938111 // `InternPool`.
80948112
8095 const fn_owner_decl = mod.declPtr(generic_owner_func.owner_decl);
8113 const fn_owner_decl = zcu.declPtr(generic_owner_func.owner_decl);
80968114 const namespace_index = fn_owner_decl.src_namespace;
8097 const namespace = mod.namespacePtr(namespace_index);
8098 const fn_zir = namespace.file_scope.zir;
8115 const namespace = zcu.namespacePtr(namespace_index);
8116 const fn_zir = namespace.fileScope(zcu).zir;
80998117 const fn_info = fn_zir.getFnInfo(generic_owner_func.zir_body_inst.resolve(ip));
81008118
81018119 const comptime_args = try sema.arena.alloc(InternPool.Index, args_info.count());
......@@ -8110,7 +8128,7 @@ fn instantiateGenericCall(
81108128 // `param_anytype_comptime` ZIR instructions to be ignored, resulting in a
81118129 // new, monomorphized function, with the comptime parameters elided.
81128130 var child_sema: Sema = .{
8113 .mod = mod,
8131 .mod = zcu,
81148132 .gpa = gpa,
81158133 .arena = sema.arena,
81168134 .code = fn_zir,
......@@ -8199,7 +8217,7 @@ fn instantiateGenericCall(
81998217 const arg_ref = try args_info.analyzeArg(sema, block, arg_index, param_ty, generic_owner_ty_info, func);
82008218 try sema.validateRuntimeValue(block, args_info.argSrc(block, arg_index), arg_ref);
82018219 const arg_ty = sema.typeOf(arg_ref);
8202 if (arg_ty.zigTypeTag(mod) == .NoReturn) {
8220 if (arg_ty.zigTypeTag(zcu) == .NoReturn) {
82038221 // This terminates argument analysis.
82048222 return arg_ref;
82058223 }
......@@ -8283,12 +8301,12 @@ fn instantiateGenericCall(
82838301 const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst);
82848302 const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern();
82858303
8286 const callee = mod.funcInfo(callee_index);
8304 const callee = zcu.funcInfo(callee_index);
82878305 callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota);
82888306
82898307 // Make a runtime call to the new function, making sure to omit the comptime args.
82908308 const func_ty = Type.fromInterned(callee.ty);
8291 const func_ty_info = mod.typeToFunc(func_ty).?;
8309 const func_ty_info = zcu.typeToFunc(func_ty).?;
82928310
82938311 // If the call evaluated to a return type that requires comptime, never mind
82948312 // our generic instantiation. Instead we need to perform a comptime call.
......@@ -8304,13 +8322,13 @@ fn instantiateGenericCall(
83048322 if (call_dbg_node) |some| try sema.zirDbgStmt(block, some);
83058323
83068324 if (sema.owner_func_index != .none and
8307 Type.fromInterned(func_ty_info.return_type).isError(mod))
8325 Type.fromInterned(func_ty_info.return_type).isError(zcu))
83088326 {
83098327 ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true;
83108328 }
83118329
83128330 try sema.addReferenceEntry(call_src, AnalUnit.wrap(.{ .func = callee_index }));
8313 try mod.ensureFuncBodyAnalysisQueued(callee_index);
8331 try zcu.ensureFuncBodyAnalysisQueued(callee_index);
83148332
83158333 try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Call).Struct.fields.len + runtime_args.items.len);
83168334 const result = try block.addInst(.{
......@@ -8333,7 +8351,7 @@ fn instantiateGenericCall(
83338351 if (call_tag == .call_always_tail) {
83348352 return sema.handleTailCall(block, call_src, func_ty, result);
83358353 }
8336 if (func_ty.fnReturnType(mod).isNoReturn(mod)) {
8354 if (func_ty.fnReturnType(zcu).isNoReturn(zcu)) {
83378355 _ = try block.addNoOp(.unreach);
83388356 return .unreachable_value;
83398357 }
......@@ -9653,7 +9671,7 @@ fn funcCommon(
96539671 .is_generic = final_is_generic,
96549672 .is_noinline = is_noinline,
96559673
9656 .zir_body_inst = try ip.trackZir(gpa, block.getFileScope(mod), func_inst),
9674 .zir_body_inst = try block.trackZir(func_inst),
96579675 .lbrace_line = src_locs.lbrace_line,
96589676 .rbrace_line = src_locs.rbrace_line,
96599677 .lbrace_column = @as(u16, @truncate(src_locs.columns)),
......@@ -9731,7 +9749,7 @@ fn funcCommon(
97319749 .ty = func_ty,
97329750 .cc = cc,
97339751 .is_noinline = is_noinline,
9734 .zir_body_inst = try ip.trackZir(gpa, block.getFileScope(mod), func_inst),
9752 .zir_body_inst = try block.trackZir(func_inst),
97359753 .lbrace_line = src_locs.lbrace_line,
97369754 .rbrace_line = src_locs.rbrace_line,
97379755 .lbrace_column = @as(u16, @truncate(src_locs.columns)),
......@@ -13787,18 +13805,18 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1378713805 const tracy = trace(@src());
1378813806 defer tracy.end();
1378913807
13790 const mod = sema.mod;
13808 const zcu = sema.mod;
1379113809 const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok;
1379213810 const operand_src = block.tokenOffset(inst_data.src_tok);
1379313811 const operand = inst_data.get(sema.code);
1379413812
13795 const result = mod.importFile(block.getFileScope(mod), operand) catch |err| switch (err) {
13813 const result = zcu.importFile(block.getFileScope(zcu), operand) catch |err| switch (err) {
1379613814 error.ImportOutsideModulePath => {
1379713815 return sema.fail(block, operand_src, "import of file outside module path: '{s}'", .{operand});
1379813816 },
1379913817 error.ModuleNotFound => {
1380013818 return sema.fail(block, operand_src, "no module named '{s}' available within module {s}", .{
13801 operand, block.getFileScope(mod).mod.fully_qualified_name,
13819 operand, block.getFileScope(zcu).mod.fully_qualified_name,
1380213820 });
1380313821 },
1380413822 else => {
......@@ -13807,8 +13825,8 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
1380713825 return sema.fail(block, operand_src, "unable to open '{s}': {s}", .{ operand, @errorName(err) });
1380813826 },
1380913827 };
13810 try mod.ensureFileAnalyzed(result.file);
13811 const file_root_decl_index = result.file.root_decl.unwrap().?;
13828 try zcu.ensureFileAnalyzed(result.file_index);
13829 const file_root_decl_index = zcu.fileRootDecl(result.file_index).unwrap().?;
1381213830 return sema.analyzeDeclVal(block, operand_src, file_root_decl_index);
1381313831}
1381413832
......@@ -21089,7 +21107,7 @@ fn zirReify(
2108921107 const ip = &mod.intern_pool;
2109021108 const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small);
2109121109 const extra = sema.code.extraData(Zir.Inst.Reify, extended.operand).data;
21092 const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst);
21110 const tracked_inst = try block.trackZir(inst);
2109321111 const src: LazySrcLoc = .{
2109421112 .base_node_inst = tracked_inst,
2109521113 .offset = LazySrcLoc.Offset.nodeOffset(0),
......@@ -21466,7 +21484,7 @@ fn zirReify(
2146621484 const wip_ty = switch (try ip.getOpaqueType(gpa, .{
2146721485 .has_namespace = false,
2146821486 .key = .{ .reified = .{
21469 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),
21487 .zir_index = try block.trackZir(inst),
2147021488 } },
2147121489 })) {
2147221490 .existing => |ty| return Air.internedToRef(ty),
......@@ -21660,7 +21678,7 @@ fn reifyEnum(
2166021678 .tag_mode = if (is_exhaustive) .explicit else .nonexhaustive,
2166121679 .fields_len = fields_len,
2166221680 .key = .{ .reified = .{
21663 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),
21681 .zir_index = try block.trackZir(inst),
2166421682 .type_hash = hasher.final(),
2166521683 } },
2166621684 })) {
......@@ -21810,7 +21828,7 @@ fn reifyUnion(
2181021828 .field_types = &.{}, // set later
2181121829 .field_aligns = &.{}, // set later
2181221830 .key = .{ .reified = .{
21813 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),
21831 .zir_index = try block.trackZir(inst),
2181421832 .type_hash = hasher.final(),
2181521833 } },
2181621834 })) {
......@@ -22062,7 +22080,7 @@ fn reifyStruct(
2206222080 .inits_resolved = true,
2206322081 .has_namespace = false,
2206422082 .key = .{ .reified = .{
22065 .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst),
22083 .zir_index = try block.trackZir(inst),
2206622084 .type_hash = hasher.final(),
2206722085 } },
2206822086 })) {
......@@ -34894,14 +34912,14 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void {
3489434912 _ = try sema.typeRequiresComptime(ty);
3489534913}
3489634914
34897fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) CompileError!void {
34898 const gpa = mod.gpa;
34899 const ip = &mod.intern_pool;
34915fn semaBackingIntType(zcu: *Zcu, struct_type: InternPool.LoadedStructType) CompileError!void {
34916 const gpa = zcu.gpa;
34917 const ip = &zcu.intern_pool;
3490034918
3490134919 const decl_index = struct_type.decl.unwrap().?;
34902 const decl = mod.declPtr(decl_index);
34920 const decl = zcu.declPtr(decl_index);
3490334921
34904 const zir = mod.namespacePtr(struct_type.namespace.unwrap().?).file_scope.zir;
34922 const zir = zcu.namespacePtr(struct_type.namespace.unwrap().?).fileScope(zcu).zir;
3490534923
3490634924 var analysis_arena = std.heap.ArenaAllocator.init(gpa);
3490734925 defer analysis_arena.deinit();
......@@ -34910,7 +34928,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
3491034928 defer comptime_err_ret_trace.deinit();
3491134929
3491234930 var sema: Sema = .{
34913 .mod = mod,
34931 .mod = zcu,
3491434932 .gpa = gpa,
3491534933 .arena = analysis_arena.allocator(),
3491634934 .code = zir,
......@@ -34941,7 +34959,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
3494134959 var accumulator: u64 = 0;
3494234960 for (0..struct_type.field_types.len) |i| {
3494334961 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]);
34944 accumulator += try field_ty.bitSizeAdvanced(mod, .sema);
34962 accumulator += try field_ty.bitSizeAdvanced(zcu, .sema);
3494534963 }
3494634964 break :blk accumulator;
3494734965 };
......@@ -34987,7 +35005,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co
3498735005 if (fields_bit_sum > std.math.maxInt(u16)) {
3498835006 return sema.fail(&block, block.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum});
3498935007 }
34990 const backing_int_ty = try mod.intType(.unsigned, @intCast(fields_bit_sum));
35008 const backing_int_ty = try zcu.intType(.unsigned, @intCast(fields_bit_sum));
3499135009 struct_type.backingIntType(ip).* = backing_int_ty.toIntern();
3499235010 }
3499335011
......@@ -35597,23 +35615,23 @@ fn structZirInfo(zir: Zir, zir_index: Zir.Inst.Index) struct {
3559735615}
3559835616
3559935617fn semaStructFields(
35600 mod: *Module,
35618 zcu: *Zcu,
3560135619 arena: Allocator,
3560235620 struct_type: InternPool.LoadedStructType,
3560335621) CompileError!void {
35604 const gpa = mod.gpa;
35605 const ip = &mod.intern_pool;
35622 const gpa = zcu.gpa;
35623 const ip = &zcu.intern_pool;
3560635624 const decl_index = struct_type.decl.unwrap() orelse return;
35607 const decl = mod.declPtr(decl_index);
35625 const decl = zcu.declPtr(decl_index);
3560835626 const namespace_index = struct_type.namespace.unwrap() orelse decl.src_namespace;
35609 const zir = mod.namespacePtr(namespace_index).file_scope.zir;
35627 const zir = zcu.namespacePtr(namespace_index).fileScope(zcu).zir;
3561035628 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip);
3561135629
3561235630 const fields_len, const small, var extra_index = structZirInfo(zir, zir_index);
3561335631
3561435632 if (fields_len == 0) switch (struct_type.layout) {
3561535633 .@"packed" => {
35616 try semaBackingIntType(mod, struct_type);
35634 try semaBackingIntType(zcu, struct_type);
3561735635 return;
3561835636 },
3561935637 .auto, .@"extern" => {
......@@ -35627,7 +35645,7 @@ fn semaStructFields(
3562735645 defer comptime_err_ret_trace.deinit();
3562835646
3562935647 var sema: Sema = .{
35630 .mod = mod,
35648 .mod = zcu,
3563135649 .gpa = gpa,
3563235650 .arena = arena,
3563335651 .code = zir,
......@@ -35749,7 +35767,7 @@ fn semaStructFields(
3574935767
3575035768 struct_type.field_types.get(ip)[field_i] = field_ty.toIntern();
3575135769
35752 if (field_ty.zigTypeTag(mod) == .Opaque) {
35770 if (field_ty.zigTypeTag(zcu) == .Opaque) {
3575335771 const msg = msg: {
3575435772 const msg = try sema.errMsg(ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{});
3575535773 errdefer msg.destroy(sema.gpa);
......@@ -35759,7 +35777,7 @@ fn semaStructFields(
3575935777 };
3576035778 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3576135779 }
35762 if (field_ty.zigTypeTag(mod) == .NoReturn) {
35780 if (field_ty.zigTypeTag(zcu) == .NoReturn) {
3576335781 const msg = msg: {
3576435782 const msg = try sema.errMsg(ty_src, "struct fields cannot be 'noreturn'", .{});
3576535783 errdefer msg.destroy(sema.gpa);
......@@ -35772,7 +35790,7 @@ fn semaStructFields(
3577235790 switch (struct_type.layout) {
3577335791 .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) {
3577435792 const msg = msg: {
35775 const msg = try sema.errMsg(ty_src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
35793 const msg = try sema.errMsg(ty_src, "extern structs cannot contain fields of type '{}'", .{field_ty.fmt(zcu)});
3577635794 errdefer msg.destroy(sema.gpa);
3577735795
3577835796 try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field);
......@@ -35784,7 +35802,7 @@ fn semaStructFields(
3578435802 },
3578535803 .@"packed" => if (!try sema.validatePackedType(field_ty)) {
3578635804 const msg = msg: {
35787 const msg = try sema.errMsg(ty_src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
35805 const msg = try sema.errMsg(ty_src, "packed structs cannot contain fields of type '{}'", .{field_ty.fmt(zcu)});
3578835806 errdefer msg.destroy(sema.gpa);
3578935807
3579035808 try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty);
......@@ -35820,19 +35838,19 @@ fn semaStructFields(
3582035838
3582135839// This logic must be kept in sync with `semaStructFields`
3582235840fn semaStructFieldInits(
35823 mod: *Module,
35841 zcu: *Zcu,
3582435842 arena: Allocator,
3582535843 struct_type: InternPool.LoadedStructType,
3582635844) CompileError!void {
35827 const gpa = mod.gpa;
35828 const ip = &mod.intern_pool;
35845 const gpa = zcu.gpa;
35846 const ip = &zcu.intern_pool;
3582935847
3583035848 assert(!struct_type.haveFieldInits(ip));
3583135849
3583235850 const decl_index = struct_type.decl.unwrap() orelse return;
35833 const decl = mod.declPtr(decl_index);
35851 const decl = zcu.declPtr(decl_index);
3583435852 const namespace_index = struct_type.namespace.unwrap() orelse decl.src_namespace;
35835 const zir = mod.namespacePtr(namespace_index).file_scope.zir;
35853 const zir = zcu.namespacePtr(namespace_index).fileScope(zcu).zir;
3583635854 const zir_index = struct_type.zir_index.unwrap().?.resolve(ip);
3583735855 const fields_len, const small, var extra_index = structZirInfo(zir, zir_index);
3583835856
......@@ -35840,7 +35858,7 @@ fn semaStructFieldInits(
3584035858 defer comptime_err_ret_trace.deinit();
3584135859
3584235860 var sema: Sema = .{
35843 .mod = mod,
35861 .mod = zcu,
3584435862 .gpa = gpa,
3584535863 .arena = arena,
3584635864 .code = zir,
......@@ -35950,7 +35968,7 @@ fn semaStructFieldInits(
3595035968 });
3595135969 };
3595235970
35953 if (default_val.canMutateComptimeVarState(mod)) {
35971 if (default_val.canMutateComptimeVarState(zcu)) {
3595435972 return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{});
3595535973 }
3595635974 struct_type.field_inits.get(ip)[field_i] = default_val.toIntern();
......@@ -35960,14 +35978,14 @@ fn semaStructFieldInits(
3596035978 try sema.flushExports();
3596135979}
3596235980
35963fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.LoadedUnionType) CompileError!void {
35981fn semaUnionFields(zcu: *Zcu, arena: Allocator, union_type: InternPool.LoadedUnionType) CompileError!void {
3596435982 const tracy = trace(@src());
3596535983 defer tracy.end();
3596635984
35967 const gpa = mod.gpa;
35968 const ip = &mod.intern_pool;
35985 const gpa = zcu.gpa;
35986 const ip = &zcu.intern_pool;
3596935987 const decl_index = union_type.decl;
35970 const zir = mod.namespacePtr(union_type.namespace.unwrap().?).file_scope.zir;
35988 const zir = zcu.namespacePtr(union_type.namespace.unwrap().?).fileScope(zcu).zir;
3597135989 const zir_index = union_type.zir_index.resolve(ip);
3597235990 const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended;
3597335991 assert(extended.opcode == .union_decl);
......@@ -36011,13 +36029,13 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3601136029 const body = zir.bodySlice(extra_index, body_len);
3601236030 extra_index += body.len;
3601336031
36014 const decl = mod.declPtr(decl_index);
36032 const decl = zcu.declPtr(decl_index);
3601536033
3601636034 var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa);
3601736035 defer comptime_err_ret_trace.deinit();
3601836036
3601936037 var sema: Sema = .{
36020 .mod = mod,
36038 .mod = zcu,
3602136039 .gpa = gpa,
3602236040 .arena = arena,
3602336041 .code = zir,
......@@ -36063,18 +36081,18 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3606336081 if (small.auto_enum_tag) {
3606436082 // The provided type is an integer type and we must construct the enum tag type here.
3606536083 int_tag_ty = provided_ty;
36066 if (int_tag_ty.zigTypeTag(mod) != .Int and int_tag_ty.zigTypeTag(mod) != .ComptimeInt) {
36067 return sema.fail(&block_scope, tag_ty_src, "expected integer tag type, found '{}'", .{int_tag_ty.fmt(mod)});
36084 if (int_tag_ty.zigTypeTag(zcu) != .Int and int_tag_ty.zigTypeTag(zcu) != .ComptimeInt) {
36085 return sema.fail(&block_scope, tag_ty_src, "expected integer tag type, found '{}'", .{int_tag_ty.fmt(zcu)});
3606836086 }
3606936087
3607036088 if (fields_len > 0) {
36071 const field_count_val = try mod.intValue(Type.comptime_int, fields_len - 1);
36089 const field_count_val = try zcu.intValue(Type.comptime_int, fields_len - 1);
3607236090 if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) {
3607336091 const msg = msg: {
3607436092 const msg = try sema.errMsg(tag_ty_src, "specified integer tag type cannot represent every field", .{});
3607536093 errdefer msg.destroy(sema.gpa);
3607636094 try sema.errNote(tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{
36077 int_tag_ty.fmt(mod),
36095 int_tag_ty.fmt(zcu),
3607836096 fields_len - 1,
3607936097 });
3608036098 break :msg msg;
......@@ -36089,7 +36107,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3608936107 union_type.tagTypePtr(ip).* = provided_ty.toIntern();
3609036108 const enum_type = switch (ip.indexToKey(provided_ty.toIntern())) {
3609136109 .enum_type => ip.loadEnumType(provided_ty.toIntern()),
36092 else => return sema.fail(&block_scope, tag_ty_src, "expected enum tag type, found '{}'", .{provided_ty.fmt(mod)}),
36110 else => return sema.fail(&block_scope, tag_ty_src, "expected enum tag type, found '{}'", .{provided_ty.fmt(zcu)}),
3609336111 };
3609436112 // The fields of the union must match the enum exactly.
3609536113 // A flag per field is used to check for missing and extraneous fields.
......@@ -36185,7 +36203,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3618536203 const val = if (last_tag_val) |val|
3618636204 try sema.intAdd(val, Value.one_comptime_int, int_tag_ty, undefined)
3618736205 else
36188 try mod.intValue(int_tag_ty, 0);
36206 try zcu.intValue(int_tag_ty, 0);
3618936207 last_tag_val = val;
3619036208
3619136209 break :blk val;
......@@ -36197,7 +36215,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3619736215 .offset = .{ .container_field_value = @intCast(gop.index) },
3619836216 };
3619936217 const msg = msg: {
36200 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(mod, &sema)});
36218 const msg = try sema.errMsg(value_src, "enum tag value {} already taken", .{enum_tag_val.fmtValue(zcu, &sema)});
3620136219 errdefer msg.destroy(gpa);
3620236220 try sema.errNote(other_value_src, msg, "other occurrence here", .{});
3620336221 break :msg msg;
......@@ -36227,7 +36245,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3622736245 const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*);
3622836246 const enum_index = tag_info.nameIndex(ip, field_name) orelse {
3622936247 return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{
36230 field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(mod),
36248 field_name.fmt(ip), Type.fromInterned(union_type.tagTypePtr(ip).*).fmt(zcu),
3623136249 });
3623236250 };
3623336251
......@@ -36254,7 +36272,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3625436272 }
3625536273 }
3625636274
36257 if (field_ty.zigTypeTag(mod) == .Opaque) {
36275 if (field_ty.zigTypeTag(zcu) == .Opaque) {
3625836276 const msg = msg: {
3625936277 const msg = try sema.errMsg(type_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{});
3626036278 errdefer msg.destroy(sema.gpa);
......@@ -36269,7 +36287,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3626936287 !try sema.validateExternType(field_ty, .union_field))
3627036288 {
3627136289 const msg = msg: {
36272 const msg = try sema.errMsg(type_src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36290 const msg = try sema.errMsg(type_src, "extern unions cannot contain fields of type '{}'", .{field_ty.fmt(zcu)});
3627336291 errdefer msg.destroy(sema.gpa);
3627436292
3627536293 try sema.explainWhyTypeIsNotExtern(msg, type_src, field_ty, .union_field);
......@@ -36280,7 +36298,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3628036298 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3628136299 } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) {
3628236300 const msg = msg: {
36283 const msg = try sema.errMsg(type_src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(mod)});
36301 const msg = try sema.errMsg(type_src, "packed unions cannot contain fields of type '{}'", .{field_ty.fmt(zcu)});
3628436302 errdefer msg.destroy(sema.gpa);
3628536303
3628636304 try sema.explainWhyTypeIsNotPacked(msg, type_src, field_ty);
......@@ -36325,10 +36343,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded
3632536343 return sema.failWithOwnedErrorMsg(&block_scope, msg);
3632636344 }
3632736345 } else if (enum_field_vals.count() > 0) {
36328 const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), mod.declPtr(union_type.decl));
36346 const enum_ty = try sema.generateUnionTagTypeNumbered(&block_scope, enum_field_names, enum_field_vals.keys(), zcu.declPtr(union_type.decl));
3632936347 union_type.tagTypePtr(ip).* = enum_ty;
3633036348 } else {
36331 const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, mod.declPtr(union_type.decl));
36349 const enum_ty = try sema.generateUnionTagTypeSimple(&block_scope, enum_field_names, zcu.declPtr(union_type.decl));
3633236350 union_type.tagTypePtr(ip).* = enum_ty;
3633336351 }
3633436352
src/Type.zig+1-1
......@@ -3455,7 +3455,7 @@ pub fn typeDeclSrcLine(ty: Type, zcu: *const Zcu) ?u32 {
34553455 else => return null,
34563456 };
34573457 const info = tracked.resolveFull(&zcu.intern_pool);
3458 const file = zcu.import_table.values()[zcu.path_digest_map.getIndex(info.path_digest).?];
3458 const file = zcu.import_table.values()[zcu.files.getIndex(info.path_digest).?];
34593459 assert(file.zir_loaded);
34603460 const zir = file.zir;
34613461 const inst = zir.instructions.get(@intFromEnum(info.inst));
src/Zcu.zig+311-244
......@@ -72,6 +72,7 @@ codegen_prog_node: std.Progress.Node = undefined,
7272global_zir_cache: Compilation.Directory,
7373/// Used by AstGen worker to load and store ZIR cache.
7474local_zir_cache: Compilation.Directory,
75
7576/// This is where all `Export` values are stored. Not all values here are necessarily valid exports;
7677/// to enumerate all exports, `single_exports` and `multi_exports` must be consulted.
7778all_exports: ArrayListUnmanaged(Export) = .{},
......@@ -88,14 +89,35 @@ multi_exports: std.AutoArrayHashMapUnmanaged(AnalUnit, extern struct {
8889 index: u32,
8990 len: u32,
9091}) = .{},
91/// The set of all the Zig source files in the Module. We keep track of this in order
92/// to iterate over it and check which source files have been modified on the file system when
93/// an update is requested, as well as to cache `@import` results.
92
93/// The set of all the Zig source files in the Zig Compilation Unit. Tracked in
94/// order to iterate over it and check which source files have been modified on
95/// the file system when an update is requested, as well as to cache `@import`
96/// results.
97///
9498/// Keys are fully resolved file paths. This table owns the keys and values.
99///
100/// Protected by Compilation's mutex.
101///
102/// Not serialized. This state is reconstructed during the first call to
103/// `Compilation.update` of the process for a given `Compilation`.
104///
105/// Indexes correspond 1:1 to `files`.
95106import_table: std.StringArrayHashMapUnmanaged(*File) = .{},
96/// This acts as a map from `path_digest` to the corresponding `File`.
97/// The value is omitted, as keys are ordered identically to `import_table`.
98path_digest_map: std.AutoArrayHashMapUnmanaged(Cache.BinDigest, void) = .{},
107
108/// Elements are ordered identically to `import_table`.
109///
110/// Unlike `import_table`, this data is serialized as part of incremental
111/// compilation state.
112///
113/// Key is the hash of the path to this file, used to store
114/// `InternPool.TrackedInst`.
115///
116/// Value is the `Decl` of the struct that represents this `File`.
117///
118/// Protected by Compilation's mutex.
119files: std.AutoArrayHashMapUnmanaged(Cache.BinDigest, Decl.OptionalIndex) = .{},
120
99121/// The set of all the files which have been loaded with `@embedFile` in the Module.
100122/// We keep track of this in order to iterate over it and check which files have been
101123/// modified on the file system when an update is requested, as well as to cache
......@@ -387,8 +409,8 @@ pub const Decl = struct {
387409 anon,
388410 };
389411
390 const Index = InternPool.DeclIndex;
391 const OptionalIndex = InternPool.OptionalDeclIndex;
412 pub const Index = InternPool.DeclIndex;
413 pub const OptionalIndex = InternPool.OptionalDeclIndex;
392414
393415 pub fn zirBodies(decl: Decl, zcu: *Zcu) Zir.Inst.Declaration.Bodies {
394416 const zir = decl.getFileScope(zcu).zir;
......@@ -490,6 +512,10 @@ pub const Decl = struct {
490512 }
491513
492514 pub fn getFileScope(decl: Decl, zcu: *Zcu) *File {
515 return zcu.fileByIndex(getFileScopeIndex(decl, zcu));
516 }
517
518 pub fn getFileScopeIndex(decl: Decl, zcu: *Zcu) File.Index {
493519 return zcu.namespacePtr(decl.src_namespace).file_scope;
494520 }
495521
......@@ -558,7 +584,7 @@ pub const Decl = struct {
558584 break :inst generic_owner_decl.zir_decl_index.unwrap().?;
559585 };
560586 const info = tracked.resolveFull(&zcu.intern_pool);
561 const file = zcu.import_table.values()[zcu.path_digest_map.getIndex(info.path_digest).?];
587 const file = zcu.import_table.values()[zcu.files.getIndex(info.path_digest).?];
562588 assert(file.zir_loaded);
563589 const zir = file.zir;
564590 const inst = zir.instructions.get(@intFromEnum(info.inst));
......@@ -595,7 +621,7 @@ pub const DeclAdapter = struct {
595621/// The container that structs, enums, unions, and opaques have.
596622pub const Namespace = struct {
597623 parent: OptionalIndex,
598 file_scope: *File,
624 file_scope: File.Index,
599625 /// Will be a struct, enum, union, or opaque.
600626 decl_index: Decl.Index,
601627 /// Direct children of the namespace.
......@@ -627,6 +653,10 @@ pub const Namespace = struct {
627653 }
628654 };
629655
656 pub fn fileScope(ns: Namespace, zcu: *Zcu) *File {
657 return zcu.fileByIndex(ns.file_scope);
658 }
659
630660 // This renders e.g. "std.fs.Dir.OpenOptions"
631661 pub fn renderFullyQualifiedName(
632662 ns: Namespace,
......@@ -641,7 +671,7 @@ pub const Namespace = struct {
641671 writer,
642672 );
643673 } else {
644 try ns.file_scope.renderFullyQualifiedName(writer);
674 try ns.fileScope(zcu).renderFullyQualifiedName(writer);
645675 }
646676 if (name != .empty) try writer.print(".{}", .{name.fmt(&zcu.intern_pool)});
647677 }
......@@ -661,7 +691,7 @@ pub const Namespace = struct {
661691 );
662692 break :sep '.';
663693 } else sep: {
664 try ns.file_scope.renderFullyQualifiedDebugName(writer);
694 try ns.fileScope(zcu).renderFullyQualifiedDebugName(writer);
665695 break :sep ':';
666696 };
667697 if (name != .empty) try writer.print("{c}{}", .{ sep, name.fmt(&zcu.intern_pool) });
......@@ -680,7 +710,7 @@ pub const Namespace = struct {
680710 const decl = zcu.declPtr(cur_ns.decl_index);
681711 count += decl.name.length(ip) + 1;
682712 cur_ns = zcu.namespacePtr(cur_ns.parent.unwrap() orelse {
683 count += ns.file_scope.sub_file_path.len;
713 count += ns.fileScope(zcu).sub_file_path.len;
684714 break :count count;
685715 });
686716 }
......@@ -715,8 +745,6 @@ pub const Namespace = struct {
715745};
716746
717747pub const File = struct {
718 /// The Decl of the struct that represents this File.
719 root_decl: Decl.OptionalIndex,
720748 status: enum {
721749 never_loaded,
722750 retryable_failure,
......@@ -744,8 +772,6 @@ pub const File = struct {
744772 multi_pkg: bool = false,
745773 /// List of references to this file, used for multi-package errors.
746774 references: std.ArrayListUnmanaged(File.Reference) = .{},
747 /// The hash of the path to this file, used to store `InternPool.TrackedInst`.
748 path_digest: Cache.BinDigest,
749775
750776 /// The most recent successful ZIR for this file, with no errors.
751777 /// This is only populated when a previously successful ZIR
......@@ -757,7 +783,7 @@ pub const File = struct {
757783 pub const Reference = union(enum) {
758784 /// The file is imported directly (i.e. not as a package) with @import.
759785 import: struct {
760 file: *File,
786 file: File.Index,
761787 token: Ast.TokenIndex,
762788 },
763789 /// The file is the root of a module.
......@@ -791,28 +817,6 @@ pub const File = struct {
791817 }
792818 }
793819
794 pub fn deinit(file: *File, mod: *Module) void {
795 const gpa = mod.gpa;
796 const is_builtin = file.mod.isBuiltin();
797 log.debug("deinit File {s}", .{file.sub_file_path});
798 if (is_builtin) {
799 file.unloadTree(gpa);
800 file.unloadZir(gpa);
801 } else {
802 gpa.free(file.sub_file_path);
803 file.unload(gpa);
804 }
805 file.references.deinit(gpa);
806 if (file.root_decl.unwrap()) |root_decl| {
807 mod.destroyDecl(root_decl);
808 }
809 if (file.prev_zir) |prev_zir| {
810 prev_zir.deinit(gpa);
811 gpa.destroy(prev_zir);
812 }
813 file.* = undefined;
814 }
815
816820 pub const Source = struct {
817821 bytes: [:0]const u8,
818822 stat: Cache.File.Stat,
......@@ -865,13 +869,6 @@ pub const File = struct {
865869 return &file.tree;
866870 }
867871
868 pub fn destroy(file: *File, mod: *Module) void {
869 const gpa = mod.gpa;
870 const is_builtin = file.mod.isBuiltin();
871 file.deinit(mod);
872 if (!is_builtin) gpa.destroy(file);
873 }
874
875872 pub fn renderFullyQualifiedName(file: File, writer: anytype) !void {
876873 // Convert all the slashes into dots and truncate the extension.
877874 const ext = std.fs.path.extension(file.sub_file_path);
......@@ -937,7 +934,7 @@ pub const File = struct {
937934 }
938935
939936 const mod = switch (ref) {
940 .import => |import| import.file.mod,
937 .import => |import| zcu.fileByIndex(import.file).mod,
941938 .root => |mod| mod,
942939 };
943940 if (mod != file.mod) file.multi_pkg = true;
......@@ -971,6 +968,10 @@ pub const File = struct {
971968 }
972969 }
973970 }
971
972 pub const Index = enum(u32) {
973 _,
974 };
974975};
975976
976977pub const EmbedFile = struct {
......@@ -2355,7 +2356,7 @@ pub const LazySrcLoc = struct {
23552356 break :inst .{ info.path_digest, info.inst };
23562357 };
23572358 const file = file: {
2358 const index = zcu.path_digest_map.getIndex(want_path_digest).?;
2359 const index = zcu.files.getIndex(want_path_digest).?;
23592360 break :file zcu.import_table.values()[index];
23602361 };
23612362 assert(file.zir_loaded);
......@@ -2423,11 +2424,12 @@ pub fn deinit(zcu: *Zcu) void {
24232424 for (zcu.import_table.keys()) |key| {
24242425 gpa.free(key);
24252426 }
2426 for (zcu.import_table.values()) |value| {
2427 value.destroy(zcu);
2427 for (0..zcu.import_table.entries.len) |file_index_usize| {
2428 const file_index: File.Index = @enumFromInt(file_index_usize);
2429 zcu.destroyFile(file_index);
24282430 }
24292431 zcu.import_table.deinit(gpa);
2430 zcu.path_digest_map.deinit(gpa);
2432 zcu.files.deinit(gpa);
24312433
24322434 for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| {
24332435 gpa.free(path);
......@@ -2531,6 +2533,37 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void {
25312533 }
25322534}
25332535
2536fn deinitFile(zcu: *Zcu, file_index: File.Index) void {
2537 const gpa = zcu.gpa;
2538 const file = zcu.fileByIndex(file_index);
2539 const is_builtin = file.mod.isBuiltin();
2540 log.debug("deinit File {s}", .{file.sub_file_path});
2541 if (is_builtin) {
2542 file.unloadTree(gpa);
2543 file.unloadZir(gpa);
2544 } else {
2545 gpa.free(file.sub_file_path);
2546 file.unload(gpa);
2547 }
2548 file.references.deinit(gpa);
2549 if (zcu.fileRootDecl(file_index).unwrap()) |root_decl| {
2550 zcu.destroyDecl(root_decl);
2551 }
2552 if (file.prev_zir) |prev_zir| {
2553 prev_zir.deinit(gpa);
2554 gpa.destroy(prev_zir);
2555 }
2556 file.* = undefined;
2557}
2558
2559pub fn destroyFile(zcu: *Zcu, file_index: File.Index) void {
2560 const gpa = zcu.gpa;
2561 const file = zcu.fileByIndex(file_index);
2562 const is_builtin = file.mod.isBuiltin();
2563 zcu.deinitFile(file_index);
2564 if (!is_builtin) gpa.destroy(file);
2565}
2566
25342567pub fn declPtr(mod: *Module, index: Decl.Index) *Decl {
25352568 return mod.intern_pool.declPtr(index);
25362569}
......@@ -2563,14 +2596,14 @@ comptime {
25632596 }
25642597}
25652598
2566pub fn astGenFile(mod: *Module, file: *File) !void {
2599pub fn astGenFile(zcu: *Zcu, file: *File, path_digest: Cache.BinDigest, opt_root_decl: Zcu.Decl.OptionalIndex) !void {
25672600 assert(!file.mod.isBuiltin());
25682601
25692602 const tracy = trace(@src());
25702603 defer tracy.end();
25712604
2572 const comp = mod.comp;
2573 const gpa = mod.gpa;
2605 const comp = zcu.comp;
2606 const gpa = zcu.gpa;
25742607
25752608 // In any case we need to examine the stat of the file to determine the course of action.
25762609 var source_file = try file.mod.root.openFile(file.sub_file_path, .{});
......@@ -2578,17 +2611,9 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
25782611
25792612 const stat = try source_file.stat();
25802613
2581 const want_local_cache = file.mod == mod.main_mod;
2582 const hex_digest = hex: {
2583 var hex: Cache.HexDigest = undefined;
2584 _ = std.fmt.bufPrint(
2585 &hex,
2586 "{s}",
2587 .{std.fmt.fmtSliceHexLower(&file.path_digest)},
2588 ) catch unreachable;
2589 break :hex hex;
2590 };
2591 const cache_directory = if (want_local_cache) mod.local_zir_cache else mod.global_zir_cache;
2614 const want_local_cache = file.mod == zcu.main_mod;
2615 const hex_digest = Cache.binToHex(path_digest);
2616 const cache_directory = if (want_local_cache) zcu.local_zir_cache else zcu.global_zir_cache;
25922617 const zir_dir = cache_directory.handle;
25932618
25942619 // Determine whether we need to reload the file from disk and redo parsing and AstGen.
......@@ -2688,7 +2713,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
26882713 {
26892714 comp.mutex.lock();
26902715 defer comp.mutex.unlock();
2691 try mod.failed_files.putNoClobber(gpa, file, null);
2716 try zcu.failed_files.putNoClobber(gpa, file, null);
26922717 }
26932718 file.status = .astgen_failure;
26942719 return error.AnalysisFail;
......@@ -2712,7 +2737,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
27122737 else => |e| return e,
27132738 };
27142739
2715 mod.lockAndClearFileCompileError(file);
2740 zcu.lockAndClearFileCompileError(file);
27162741
27172742 // If the previous ZIR does not have compile errors, keep it around
27182743 // in case parsing or new ZIR fails. In case of successful ZIR update
......@@ -2818,27 +2843,27 @@ pub fn astGenFile(mod: *Module, file: *File) !void {
28182843 {
28192844 comp.mutex.lock();
28202845 defer comp.mutex.unlock();
2821 try mod.failed_files.putNoClobber(gpa, file, null);
2846 try zcu.failed_files.putNoClobber(gpa, file, null);
28222847 }
28232848 file.status = .astgen_failure;
28242849 return error.AnalysisFail;
28252850 }
28262851
28272852 if (file.prev_zir) |prev_zir| {
2828 try updateZirRefs(mod, file, prev_zir.*);
2853 try updateZirRefs(zcu, file, prev_zir.*, path_digest);
28292854 // No need to keep previous ZIR.
28302855 prev_zir.deinit(gpa);
28312856 gpa.destroy(prev_zir);
28322857 file.prev_zir = null;
28332858 }
28342859
2835 if (file.root_decl.unwrap()) |root_decl| {
2860 if (opt_root_decl.unwrap()) |root_decl| {
28362861 // The root of this file must be re-analyzed, since the file has changed.
28372862 comp.mutex.lock();
28382863 defer comp.mutex.unlock();
28392864
28402865 log.debug("outdated root Decl: {}", .{root_decl});
2841 try mod.outdated_file_root.put(gpa, root_decl, {});
2866 try zcu.outdated_file_root.put(gpa, root_decl, {});
28422867 }
28432868}
28442869
......@@ -2914,7 +2939,7 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File)
29142939
29152940/// This is called from the AstGen thread pool, so must acquire
29162941/// the Compilation mutex when acting on shared state.
2917fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void {
2942fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir, path_digest: Cache.BinDigest) !void {
29182943 const gpa = zcu.gpa;
29192944 const new_zir = file.zir;
29202945
......@@ -2930,7 +2955,7 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void {
29302955 // iterating over this full set for every updated file.
29312956 for (zcu.intern_pool.tracked_insts.keys(), 0..) |*ti, idx_raw| {
29322957 const ti_idx: InternPool.TrackedInst.Index = @enumFromInt(idx_raw);
2933 if (!std.mem.eql(u8, &ti.path_digest, &file.path_digest)) continue;
2958 if (!std.mem.eql(u8, &ti.path_digest, &path_digest)) continue;
29342959 const old_inst = ti.inst;
29352960 ti.inst = inst_map.get(ti.inst) orelse {
29362961 // Tracking failed for this instruction. Invalidate associated `src_hash` deps.
......@@ -3378,11 +3403,11 @@ pub fn mapOldZirToNew(
33783403}
33793404
33803405/// Like `ensureDeclAnalyzed`, but the Decl is a file's root Decl.
3381pub fn ensureFileAnalyzed(zcu: *Zcu, file: *File) SemaError!void {
3382 if (file.root_decl.unwrap()) |existing_root| {
3406pub fn ensureFileAnalyzed(zcu: *Zcu, file_index: File.Index) SemaError!void {
3407 if (zcu.fileRootDecl(file_index).unwrap()) |existing_root| {
33833408 return zcu.ensureDeclAnalyzed(existing_root);
33843409 } else {
3385 return zcu.semaFile(file);
3410 return zcu.semaFile(file_index);
33863411 }
33873412}
33883413
......@@ -3455,7 +3480,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void {
34553480 }
34563481
34573482 if (mod.declIsRoot(decl_index)) {
3458 const changed = try mod.semaFileUpdate(decl.getFileScope(mod), decl_was_outdated);
3483 const changed = try mod.semaFileUpdate(decl.getFileScopeIndex(mod), decl_was_outdated);
34593484 break :blk .{
34603485 .invalidate_decl_val = changed,
34613486 .invalidate_decl_ref = changed,
......@@ -3787,17 +3812,23 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index)
37873812 func.analysis(ip).state = .queued;
37883813}
37893814
3790/// https://github.com/ziglang/zig/issues/14307
3791pub fn semaPkg(mod: *Module, pkg: *Package.Module) !void {
3792 const file = (try mod.importPkg(pkg)).file;
3793 if (file.root_decl == .none) {
3794 return mod.semaFile(file);
3815pub fn semaPkg(zcu: *Zcu, pkg: *Package.Module) !void {
3816 const import_file_result = try zcu.importPkg(pkg);
3817 const root_decl_index = zcu.fileRootDecl(import_file_result.file_index);
3818 if (root_decl_index == .none) {
3819 return zcu.semaFile(import_file_result.file_index);
37953820 }
37963821}
37973822
3798fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespace.Index, file: *File) Allocator.Error!InternPool.Index {
3823fn getFileRootStruct(
3824 zcu: *Zcu,
3825 decl_index: Decl.Index,
3826 namespace_index: Namespace.Index,
3827 file_index: File.Index,
3828) Allocator.Error!InternPool.Index {
37993829 const gpa = zcu.gpa;
38003830 const ip = &zcu.intern_pool;
3831 const file = zcu.fileByIndex(file_index);
38013832 const extended = file.zir.instructions.items(.data)[@intFromEnum(Zir.Inst.Index.main_struct_inst)].extended;
38023833 assert(extended.opcode == .struct_decl);
38033834 const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small);
......@@ -3818,7 +3849,7 @@ fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespa
38183849 const decls = file.zir.bodySlice(extra_index, decls_len);
38193850 extra_index += decls_len;
38203851
3821 const tracked_inst = try ip.trackZir(gpa, file, .main_struct_inst);
3852 const tracked_inst = try ip.trackZir(gpa, zcu.filePathDigest(file_index), .main_struct_inst);
38223853 const wip_ty = switch (try ip.getStructType(gpa, .{
38233854 .layout = .auto,
38243855 .fields_len = fields_len,
......@@ -3863,8 +3894,9 @@ fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespa
38633894/// If `type_outdated`, the struct type itself is considered outdated and is
38643895/// reconstructed at a new InternPool index. Otherwise, the namespace is just
38653896/// re-analyzed. Returns whether the decl's tyval was invalidated.
3866fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool {
3867 const decl = zcu.declPtr(file.root_decl.unwrap().?);
3897fn semaFileUpdate(zcu: *Zcu, file_index: File.Index, type_outdated: bool) SemaError!bool {
3898 const file = zcu.fileByIndex(file_index);
3899 const decl = zcu.declPtr(zcu.fileRootDecl(file_index).unwrap().?);
38683900
38693901 log.debug("semaFileUpdate mod={s} sub_file_path={s} type_outdated={}", .{
38703902 file.mod.fully_qualified_name,
......@@ -3883,7 +3915,8 @@ fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool {
38833915
38843916 if (decl.analysis == .file_failure) {
38853917 // No struct type currently exists. Create one!
3886 _ = try zcu.getFileRootStruct(file.root_decl.unwrap().?, decl.src_namespace, file);
3918 const root_decl = zcu.fileRootDecl(file_index);
3919 _ = try zcu.getFileRootStruct(root_decl.unwrap().?, decl.src_namespace, file_index);
38873920 return true;
38883921 }
38893922
......@@ -3892,10 +3925,13 @@ fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool {
38923925
38933926 if (type_outdated) {
38943927 // Invalidate the existing type, reusing the decl and namespace.
3895 zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, AnalUnit.wrap(.{ .decl = file.root_decl.unwrap().? }));
3928 const file_root_decl = zcu.fileRootDecl(file_index).unwrap().?;
3929 zcu.intern_pool.removeDependenciesForDepender(zcu.gpa, AnalUnit.wrap(.{
3930 .decl = file_root_decl,
3931 }));
38963932 zcu.intern_pool.remove(decl.val.toIntern());
38973933 decl.val = undefined;
3898 _ = try zcu.getFileRootStruct(file.root_decl.unwrap().?, decl.src_namespace, file);
3934 _ = try zcu.getFileRootStruct(file_root_decl, decl.src_namespace, file_index);
38993935 return true;
39003936 }
39013937
......@@ -3923,35 +3959,36 @@ fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool {
39233959
39243960/// Regardless of the file status, will create a `Decl` if none exists so that we can track
39253961/// dependencies and re-analyze when the file becomes outdated.
3926fn semaFile(mod: *Module, file: *File) SemaError!void {
3962fn semaFile(zcu: *Zcu, file_index: File.Index) SemaError!void {
39273963 const tracy = trace(@src());
39283964 defer tracy.end();
39293965
3930 assert(file.root_decl == .none);
3966 const file = zcu.fileByIndex(file_index);
3967 assert(zcu.fileRootDecl(file_index) == .none);
39313968
3932 const gpa = mod.gpa;
3933 log.debug("semaFile mod={s} sub_file_path={s}", .{
3969 const gpa = zcu.gpa;
3970 log.debug("semaFile zcu={s} sub_file_path={s}", .{
39343971 file.mod.fully_qualified_name, file.sub_file_path,
39353972 });
39363973
39373974 // Because these three things each reference each other, `undefined`
39383975 // placeholders are used before being set after the struct type gains an
39393976 // InternPool index.
3940 const new_namespace_index = try mod.createNamespace(.{
3977 const new_namespace_index = try zcu.createNamespace(.{
39413978 .parent = .none,
39423979 .decl_index = undefined,
3943 .file_scope = file,
3980 .file_scope = file_index,
39443981 });
3945 errdefer mod.destroyNamespace(new_namespace_index);
3982 errdefer zcu.destroyNamespace(new_namespace_index);
39463983
3947 const new_decl_index = try mod.allocateNewDecl(new_namespace_index);
3948 const new_decl = mod.declPtr(new_decl_index);
3984 const new_decl_index = try zcu.allocateNewDecl(new_namespace_index);
3985 const new_decl = zcu.declPtr(new_decl_index);
39493986 errdefer @panic("TODO error handling");
39503987
3951 file.root_decl = new_decl_index.toOptional();
3952 mod.namespacePtr(new_namespace_index).decl_index = new_decl_index;
3988 zcu.setFileRootDecl(file_index, new_decl_index.toOptional());
3989 zcu.namespacePtr(new_namespace_index).decl_index = new_decl_index;
39533990
3954 new_decl.name = try file.fullyQualifiedName(mod);
3991 new_decl.name = try file.fullyQualifiedName(zcu);
39553992 new_decl.name_fully_qualified = true;
39563993 new_decl.is_pub = true;
39573994 new_decl.is_exported = false;
......@@ -3965,13 +4002,13 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {
39654002 }
39664003 assert(file.zir_loaded);
39674004
3968 const struct_ty = try mod.getFileRootStruct(new_decl_index, new_namespace_index, file);
3969 errdefer mod.intern_pool.remove(struct_ty);
4005 const struct_ty = try zcu.getFileRootStruct(new_decl_index, new_namespace_index, file_index);
4006 errdefer zcu.intern_pool.remove(struct_ty);
39704007
3971 switch (mod.comp.cache_use) {
4008 switch (zcu.comp.cache_use) {
39724009 .whole => |whole| if (whole.cache_manifest) |man| {
39734010 const source = file.getSource(gpa) catch |err| {
3974 try reportRetryableFileError(mod, file, "unable to load source: {s}", .{@errorName(err)});
4011 try reportRetryableFileError(zcu, file_index, "unable to load source: {s}", .{@errorName(err)});
39754012 return error.AnalysisFail;
39764013 };
39774014
......@@ -3980,7 +4017,7 @@ fn semaFile(mod: *Module, file: *File) SemaError!void {
39804017 file.mod.root.sub_path,
39814018 file.sub_file_path,
39824019 }) catch |err| {
3983 try reportRetryableFileError(mod, file, "unable to resolve path: {s}", .{@errorName(err)});
4020 try reportRetryableFileError(zcu, file_index, "unable to resolve path: {s}", .{@errorName(err)});
39844021 return error.AnalysisFail;
39854022 };
39864023 errdefer gpa.free(resolved_path);
......@@ -4000,57 +4037,58 @@ const SemaDeclResult = packed struct {
40004037 invalidate_decl_ref: bool,
40014038};
40024039
4003fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
4040fn semaDecl(zcu: *Zcu, decl_index: Decl.Index) !SemaDeclResult {
40044041 const tracy = trace(@src());
40054042 defer tracy.end();
40064043
4007 const decl = mod.declPtr(decl_index);
4008 const ip = &mod.intern_pool;
4044 const decl = zcu.declPtr(decl_index);
4045 const ip = &zcu.intern_pool;
40094046
4010 if (decl.getFileScope(mod).status != .success_zir) {
4047 if (decl.getFileScope(zcu).status != .success_zir) {
40114048 return error.AnalysisFail;
40124049 }
40134050
4014 assert(!mod.declIsRoot(decl_index));
4051 assert(!zcu.declIsRoot(decl_index));
40154052
40164053 if (decl.zir_decl_index == .none and decl.owns_tv) {
40174054 // We are re-analyzing an anonymous owner Decl (for a function or a namespace type).
4018 return mod.semaAnonOwnerDecl(decl_index);
4055 return zcu.semaAnonOwnerDecl(decl_index);
40194056 }
40204057
40214058 log.debug("semaDecl '{d}'", .{@intFromEnum(decl_index)});
4022 log.debug("decl name '{}'", .{(try decl.fullyQualifiedName(mod)).fmt(ip)});
4059 log.debug("decl name '{}'", .{(try decl.fullyQualifiedName(zcu)).fmt(ip)});
40234060 defer blk: {
4024 log.debug("finish decl name '{}'", .{(decl.fullyQualifiedName(mod) catch break :blk).fmt(ip)});
4061 log.debug("finish decl name '{}'", .{(decl.fullyQualifiedName(zcu) catch break :blk).fmt(ip)});
40254062 }
40264063
40274064 const old_has_tv = decl.has_tv;
40284065 // The following values are ignored if `!old_has_tv`
4029 const old_ty = if (old_has_tv) decl.typeOf(mod) else undefined;
4066 const old_ty = if (old_has_tv) decl.typeOf(zcu) else undefined;
40304067 const old_val = decl.val;
40314068 const old_align = decl.alignment;
40324069 const old_linksection = decl.@"linksection";
40334070 const old_addrspace = decl.@"addrspace";
4034 const old_is_inline = if (decl.getOwnedFunction(mod)) |prev_func|
4071 const old_is_inline = if (decl.getOwnedFunction(zcu)) |prev_func|
40354072 prev_func.analysis(ip).state == .inline_only
40364073 else
40374074 false;
40384075
40394076 const decl_inst = decl.zir_decl_index.unwrap().?.resolve(ip);
40404077
4041 const gpa = mod.gpa;
4042 const zir = decl.getFileScope(mod).zir;
4078 const gpa = zcu.gpa;
4079 const zir = decl.getFileScope(zcu).zir;
40434080
40444081 const builtin_type_target_index: InternPool.Index = ip_index: {
4045 const std_mod = mod.std_mod;
4046 if (decl.getFileScope(mod).mod != std_mod) break :ip_index .none;
4082 const std_mod = zcu.std_mod;
4083 if (decl.getFileScope(zcu).mod != std_mod) break :ip_index .none;
40474084 // We're in the std module.
4048 const std_file = (try mod.importPkg(std_mod)).file;
4049 const std_decl = mod.declPtr(std_file.root_decl.unwrap().?);
4050 const std_namespace = std_decl.getInnerNamespace(mod).?;
4085 const std_file_imported = try zcu.importPkg(std_mod);
4086 const std_file_root_decl_index = zcu.fileRootDecl(std_file_imported.file_index);
4087 const std_decl = zcu.declPtr(std_file_root_decl_index.unwrap().?);
4088 const std_namespace = std_decl.getInnerNamespace(zcu).?;
40514089 const builtin_str = try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls);
4052 const builtin_decl = mod.declPtr(std_namespace.decls.getKeyAdapted(builtin_str, DeclAdapter{ .zcu = mod }) orelse break :ip_index .none);
4053 const builtin_namespace = builtin_decl.getInnerNamespaceIndex(mod).unwrap() orelse break :ip_index .none;
4090 const builtin_decl = zcu.declPtr(std_namespace.decls.getKeyAdapted(builtin_str, DeclAdapter{ .zcu = zcu }) orelse break :ip_index .none);
4091 const builtin_namespace = builtin_decl.getInnerNamespaceIndex(zcu).unwrap() orelse break :ip_index .none;
40544092 if (decl.src_namespace != builtin_namespace) break :ip_index .none;
40554093 // We're in builtin.zig. This could be a builtin we need to add to a specific InternPool index.
40564094 for ([_][]const u8{
......@@ -4083,7 +4121,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
40834121 break :ip_index .none;
40844122 };
40854123
4086 mod.intern_pool.removeDependenciesForDepender(gpa, AnalUnit.wrap(.{ .decl = decl_index }));
4124 zcu.intern_pool.removeDependenciesForDepender(gpa, AnalUnit.wrap(.{ .decl = decl_index }));
40874125
40884126 decl.analysis = .in_progress;
40894127
......@@ -4094,7 +4132,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
40944132 defer comptime_err_ret_trace.deinit();
40954133
40964134 var sema: Sema = .{
4097 .mod = mod,
4135 .mod = zcu,
40984136 .gpa = gpa,
40994137 .arena = analysis_arena.allocator(),
41004138 .code = zir,
......@@ -4112,8 +4150,8 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
41124150
41134151 // Every Decl (other than file root Decls, which do not have a ZIR index) has a dependency on its own source.
41144152 try sema.declareDependency(.{ .src_hash = try ip.trackZir(
4115 sema.gpa,
4116 decl.getFileScope(mod),
4153 gpa,
4154 zcu.filePathDigest(decl.getFileScopeIndex(zcu)),
41174155 decl_inst,
41184156 ) });
41194157
......@@ -4129,7 +4167,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
41294167 };
41304168 defer block_scope.instructions.deinit(gpa);
41314169
4132 const decl_bodies = decl.zirBodies(mod);
4170 const decl_bodies = decl.zirBodies(zcu);
41334171
41344172 const result_ref = try sema.resolveInlineBody(&block_scope, decl_bodies.value_body, decl_inst);
41354173 // We'll do some other bits with the Sema. Clear the type target index just
......@@ -4141,22 +4179,22 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
41414179 const ty_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_ty = 0 });
41424180 const init_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_init = 0 });
41434181 const decl_val = try sema.resolveFinalDeclValue(&block_scope, init_src, result_ref);
4144 const decl_ty = decl_val.typeOf(mod);
4182 const decl_ty = decl_val.typeOf(zcu);
41454183
41464184 // Note this resolves the type of the Decl, not the value; if this Decl
41474185 // is a struct, for example, this resolves `type` (which needs no resolution),
41484186 // not the struct itself.
4149 try decl_ty.resolveLayout(mod);
4187 try decl_ty.resolveLayout(zcu);
41504188
41514189 if (decl.kind == .@"usingnamespace") {
4152 if (!decl_ty.eql(Type.type, mod)) {
4190 if (!decl_ty.eql(Type.type, zcu)) {
41534191 return sema.fail(&block_scope, ty_src, "expected type, found {}", .{
4154 decl_ty.fmt(mod),
4192 decl_ty.fmt(zcu),
41554193 });
41564194 }
41574195 const ty = decl_val.toType();
4158 if (ty.getNamespace(mod) == null) {
4159 return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)});
4196 if (ty.getNamespace(zcu) == null) {
4197 return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(zcu)});
41604198 }
41614199
41624200 decl.val = ty.toValue();
......@@ -4194,7 +4232,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
41944232 .func => |func| {
41954233 decl.owns_tv = func.owner_decl == decl_index;
41964234 queue_linker_work = false;
4197 is_inline = decl.owns_tv and decl_ty.fnCallingConvention(mod) == .Inline;
4235 is_inline = decl.owns_tv and decl_ty.fnCallingConvention(zcu) == .Inline;
41984236 is_func = decl.owns_tv;
41994237 },
42004238
......@@ -4246,10 +4284,10 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
42464284 decl.analysis = .complete;
42474285
42484286 const result: SemaDeclResult = if (old_has_tv) .{
4249 .invalidate_decl_val = !decl_ty.eql(old_ty, mod) or
4250 !decl.val.eql(old_val, decl_ty, mod) or
4287 .invalidate_decl_val = !decl_ty.eql(old_ty, zcu) or
4288 !decl.val.eql(old_val, decl_ty, zcu) or
42514289 is_inline != old_is_inline,
4252 .invalidate_decl_ref = !decl_ty.eql(old_ty, mod) or
4290 .invalidate_decl_ref = !decl_ty.eql(old_ty, zcu) or
42534291 decl.alignment != old_align or
42544292 decl.@"linksection" != old_linksection or
42554293 decl.@"addrspace" != old_addrspace or
......@@ -4263,12 +4301,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult {
42634301 if (has_runtime_bits) {
42644302 // Needed for codegen_decl which will call updateDecl and then the
42654303 // codegen backend wants full access to the Decl Type.
4266 try decl_ty.resolveFully(mod);
4304 try decl_ty.resolveFully(zcu);
42674305
4268 try mod.comp.work_queue.writeItem(.{ .codegen_decl = decl_index });
4306 try zcu.comp.work_queue.writeItem(.{ .codegen_decl = decl_index });
42694307
4270 if (result.invalidate_decl_ref and mod.emit_h != null) {
4271 try mod.comp.work_queue.writeItem(.{ .emit_h_decl = decl_index });
4308 if (result.invalidate_decl_ref and zcu.emit_h != null) {
4309 try zcu.comp.work_queue.writeItem(.{ .emit_h_decl = decl_index });
42724310 }
42734311 }
42744312
......@@ -4322,6 +4360,7 @@ fn semaAnonOwnerDecl(zcu: *Zcu, decl_index: Decl.Index) !SemaDeclResult {
43224360
43234361pub const ImportFileResult = struct {
43244362 file: *File,
4363 file_index: File.Index,
43254364 is_new: bool,
43264365 is_pkg: bool,
43274366};
......@@ -4344,20 +4383,25 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
43444383 errdefer _ = zcu.import_table.pop();
43454384 if (gop.found_existing) {
43464385 try gop.value_ptr.*.addReference(zcu.*, .{ .root = mod });
4347 return ImportFileResult{
4386 return .{
43484387 .file = gop.value_ptr.*,
4388 .file_index = @enumFromInt(gop.index),
43494389 .is_new = false,
43504390 .is_pkg = true,
43514391 };
43524392 }
43534393
4394 try zcu.files.ensureUnusedCapacity(gpa, 1);
4395
43544396 if (mod.builtin_file) |builtin_file| {
43554397 keep_resolved_path = true; // It's now owned by import_table.
43564398 gop.value_ptr.* = builtin_file;
43574399 try builtin_file.addReference(zcu.*, .{ .root = mod });
4358 try zcu.path_digest_map.put(gpa, builtin_file.path_digest, {});
4400 const path_digest = computePathDigest(zcu, mod, builtin_file.sub_file_path);
4401 zcu.files.putAssumeCapacityNoClobber(path_digest, .none);
43594402 return .{
43604403 .file = builtin_file,
4404 .file_index = @enumFromInt(zcu.files.entries.len - 1),
43614405 .is_new = false,
43624406 .is_pkg = true,
43634407 };
......@@ -4382,43 +4426,36 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult {
43824426 .zir = undefined,
43834427 .status = .never_loaded,
43844428 .mod = mod,
4385 .root_decl = .none,
4386 .path_digest = digest: {
4387 const want_local_cache = mod == zcu.main_mod;
4388 var path_hash: Cache.HashHelper = .{};
4389 path_hash.addBytes(build_options.version);
4390 path_hash.add(builtin.zig_backend);
4391 if (!want_local_cache) {
4392 path_hash.addOptionalBytes(mod.root.root_dir.path);
4393 path_hash.addBytes(mod.root.sub_path);
4394 }
4395 path_hash.addBytes(sub_file_path);
4396 var bin: Cache.BinDigest = undefined;
4397 path_hash.hasher.final(&bin);
4398 break :digest bin;
4399 },
44004429 };
4430
4431 const path_digest = computePathDigest(zcu, mod, sub_file_path);
4432
44014433 try new_file.addReference(zcu.*, .{ .root = mod });
4402 try zcu.path_digest_map.put(gpa, new_file.path_digest, {});
4403 return ImportFileResult{
4434 zcu.files.putAssumeCapacityNoClobber(path_digest, .none);
4435 return .{
44044436 .file = new_file,
4437 .file_index = @enumFromInt(zcu.files.entries.len - 1),
44054438 .is_new = true,
44064439 .is_pkg = true,
44074440 };
44084441}
44094442
4443/// Called from a worker thread during AstGen.
4444/// Also called from Sema during semantic analysis.
44104445pub fn importFile(
44114446 zcu: *Zcu,
44124447 cur_file: *File,
44134448 import_string: []const u8,
44144449) !ImportFileResult {
4450 const mod = cur_file.mod;
4451
44154452 if (std.mem.eql(u8, import_string, "std")) {
44164453 return zcu.importPkg(zcu.std_mod);
44174454 }
44184455 if (std.mem.eql(u8, import_string, "root")) {
44194456 return zcu.importPkg(zcu.root_mod);
44204457 }
4421 if (cur_file.mod.deps.get(import_string)) |pkg| {
4458 if (mod.deps.get(import_string)) |pkg| {
44224459 return zcu.importPkg(pkg);
44234460 }
44244461 if (!mem.endsWith(u8, import_string, ".zig")) {
......@@ -4430,8 +4467,8 @@ pub fn importFile(
44304467 // an import refers to the same as another, despite different relative paths
44314468 // or differently mapped package names.
44324469 const resolved_path = try std.fs.path.resolve(gpa, &.{
4433 cur_file.mod.root.root_dir.path orelse ".",
4434 cur_file.mod.root.sub_path,
4470 mod.root.root_dir.path orelse ".",
4471 mod.root.sub_path,
44354472 cur_file.sub_file_path,
44364473 "..",
44374474 import_string,
......@@ -4442,18 +4479,21 @@ pub fn importFile(
44424479
44434480 const gop = try zcu.import_table.getOrPut(gpa, resolved_path);
44444481 errdefer _ = zcu.import_table.pop();
4445 if (gop.found_existing) return ImportFileResult{
4482 if (gop.found_existing) return .{
44464483 .file = gop.value_ptr.*,
4484 .file_index = @enumFromInt(gop.index),
44474485 .is_new = false,
44484486 .is_pkg = false,
44494487 };
44504488
4489 try zcu.files.ensureUnusedCapacity(gpa, 1);
4490
44514491 const new_file = try gpa.create(File);
44524492 errdefer gpa.destroy(new_file);
44534493
44544494 const resolved_root_path = try std.fs.path.resolve(gpa, &.{
4455 cur_file.mod.root.root_dir.path orelse ".",
4456 cur_file.mod.root.sub_path,
4495 mod.root.root_dir.path orelse ".",
4496 mod.root.sub_path,
44574497 });
44584498 defer gpa.free(resolved_root_path);
44594499
......@@ -4484,26 +4524,14 @@ pub fn importFile(
44844524 .tree = undefined,
44854525 .zir = undefined,
44864526 .status = .never_loaded,
4487 .mod = cur_file.mod,
4488 .root_decl = .none,
4489 .path_digest = digest: {
4490 const want_local_cache = cur_file.mod == zcu.main_mod;
4491 var path_hash: Cache.HashHelper = .{};
4492 path_hash.addBytes(build_options.version);
4493 path_hash.add(builtin.zig_backend);
4494 if (!want_local_cache) {
4495 path_hash.addOptionalBytes(cur_file.mod.root.root_dir.path);
4496 path_hash.addBytes(cur_file.mod.root.sub_path);
4497 }
4498 path_hash.addBytes(sub_file_path);
4499 var bin: Cache.BinDigest = undefined;
4500 path_hash.hasher.final(&bin);
4501 break :digest bin;
4502 },
4527 .mod = mod,
45034528 };
4504 try zcu.path_digest_map.put(gpa, new_file.path_digest, {});
4505 return ImportFileResult{
4529
4530 const path_digest = computePathDigest(zcu, mod, sub_file_path);
4531 zcu.files.putAssumeCapacityNoClobber(path_digest, .none);
4532 return .{
45064533 .file = new_file,
4534 .file_index = @enumFromInt(zcu.files.entries.len - 1),
45074535 .is_new = true,
45084536 .is_pkg = false,
45094537 };
......@@ -4581,6 +4609,21 @@ pub fn embedFile(
45814609 return newEmbedFile(mod, cur_file.mod, sub_file_path, resolved_path, gop.value_ptr, src_loc);
45824610}
45834611
4612fn computePathDigest(zcu: *Zcu, mod: *Package.Module, sub_file_path: []const u8) Cache.BinDigest {
4613 const want_local_cache = mod == zcu.main_mod;
4614 var path_hash: Cache.HashHelper = .{};
4615 path_hash.addBytes(build_options.version);
4616 path_hash.add(builtin.zig_backend);
4617 if (!want_local_cache) {
4618 path_hash.addOptionalBytes(mod.root.root_dir.path);
4619 path_hash.addBytes(mod.root.sub_path);
4620 }
4621 path_hash.addBytes(sub_file_path);
4622 var bin: Cache.BinDigest = undefined;
4623 path_hash.hasher.final(&bin);
4624 return bin;
4625}
4626
45844627/// https://github.com/ziglang/zig/issues/14307
45854628fn newEmbedFile(
45864629 mod: *Module,
......@@ -4765,7 +4808,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
47654808 const namespace_index = iter.namespace_index;
47664809 const namespace = zcu.namespacePtr(namespace_index);
47674810 const gpa = zcu.gpa;
4768 const zir = namespace.file_scope.zir;
4811 const zir = namespace.fileScope(zcu).zir;
47694812 const ip = &zcu.intern_pool;
47704813
47714814 const inst_data = zir.instructions.items(.data)[@intFromEnum(decl_inst)].declaration;
......@@ -4848,7 +4891,8 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
48484891 else => {},
48494892 }
48504893
4851 const tracked_inst = try ip.trackZir(gpa, iter.parent_decl.getFileScope(zcu), decl_inst);
4894 const parent_file_scope_index = iter.parent_decl.getFileScopeIndex(zcu);
4895 const tracked_inst = try ip.trackZir(gpa, zcu.filePathDigest(parent_file_scope_index), decl_inst);
48524896
48534897 // We create a Decl for it regardless of analysis status.
48544898
......@@ -4878,7 +4922,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
48784922 namespace.decls.putAssumeCapacityNoClobberContext(decl_index, {}, .{ .zcu = zcu });
48794923
48804924 const comp = zcu.comp;
4881 const decl_mod = namespace.file_scope.mod;
4925 const decl_mod = namespace.fileScope(zcu).mod;
48824926 const want_analysis = declaration.flags.is_export or switch (kind) {
48834927 .anon => unreachable,
48844928 .@"comptime" => true,
......@@ -4908,7 +4952,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void
49084952 // re-analysis for us if necessary.
49094953 if (prev_exported != declaration.flags.is_export or decl.analysis == .unreferenced) {
49104954 log.debug("scanDecl queue analyze_decl file='{s}' decl_name='{}' decl_index={d}", .{
4911 namespace.file_scope.sub_file_path, decl_name.fmt(ip), decl_index,
4955 namespace.fileScope(zcu).sub_file_path, decl_name.fmt(ip), decl_index,
49124956 });
49134957 comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = decl_index });
49144958 }
......@@ -5512,77 +5556,78 @@ fn handleUpdateExports(
55125556}
55135557
55145558pub fn populateTestFunctions(
5515 mod: *Module,
5559 zcu: *Zcu,
55165560 main_progress_node: std.Progress.Node,
55175561) !void {
5518 const gpa = mod.gpa;
5519 const ip = &mod.intern_pool;
5520 const builtin_mod = mod.root_mod.getBuiltinDependency();
5521 const builtin_file = (mod.importPkg(builtin_mod) catch unreachable).file;
5522 const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?);
5523 const builtin_namespace = mod.namespacePtr(root_decl.src_namespace);
5562 const gpa = zcu.gpa;
5563 const ip = &zcu.intern_pool;
5564 const builtin_mod = zcu.root_mod.getBuiltinDependency();
5565 const builtin_file_index = (zcu.importPkg(builtin_mod) catch unreachable).file_index;
5566 const root_decl_index = zcu.fileRootDecl(builtin_file_index);
5567 const root_decl = zcu.declPtr(root_decl_index.unwrap().?);
5568 const builtin_namespace = zcu.namespacePtr(root_decl.src_namespace);
55245569 const test_functions_str = try ip.getOrPutString(gpa, "test_functions", .no_embedded_nulls);
55255570 const decl_index = builtin_namespace.decls.getKeyAdapted(
55265571 test_functions_str,
5527 DeclAdapter{ .zcu = mod },
5572 DeclAdapter{ .zcu = zcu },
55285573 ).?;
55295574 {
55305575 // We have to call `ensureDeclAnalyzed` here in case `builtin.test_functions`
55315576 // was not referenced by start code.
5532 mod.sema_prog_node = main_progress_node.start("Semantic Analysis", 0);
5577 zcu.sema_prog_node = main_progress_node.start("Semantic Analysis", 0);
55335578 defer {
5534 mod.sema_prog_node.end();
5535 mod.sema_prog_node = undefined;
5579 zcu.sema_prog_node.end();
5580 zcu.sema_prog_node = undefined;
55365581 }
5537 try mod.ensureDeclAnalyzed(decl_index);
5582 try zcu.ensureDeclAnalyzed(decl_index);
55385583 }
55395584
5540 const decl = mod.declPtr(decl_index);
5541 const test_fn_ty = decl.typeOf(mod).slicePtrFieldType(mod).childType(mod);
5585 const decl = zcu.declPtr(decl_index);
5586 const test_fn_ty = decl.typeOf(zcu).slicePtrFieldType(zcu).childType(zcu);
55425587
55435588 const array_anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl = array: {
5544 // Add mod.test_functions to an array decl then make the test_functions
5589 // Add zcu.test_functions to an array decl then make the test_functions
55455590 // decl reference it as a slice.
5546 const test_fn_vals = try gpa.alloc(InternPool.Index, mod.test_functions.count());
5591 const test_fn_vals = try gpa.alloc(InternPool.Index, zcu.test_functions.count());
55475592 defer gpa.free(test_fn_vals);
55485593
5549 for (test_fn_vals, mod.test_functions.keys()) |*test_fn_val, test_decl_index| {
5550 const test_decl = mod.declPtr(test_decl_index);
5551 const test_decl_name = try test_decl.fullyQualifiedName(mod);
5594 for (test_fn_vals, zcu.test_functions.keys()) |*test_fn_val, test_decl_index| {
5595 const test_decl = zcu.declPtr(test_decl_index);
5596 const test_decl_name = try test_decl.fullyQualifiedName(zcu);
55525597 const test_decl_name_len = test_decl_name.length(ip);
55535598 const test_name_anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl = n: {
5554 const test_name_ty = try mod.arrayType(.{
5599 const test_name_ty = try zcu.arrayType(.{
55555600 .len = test_decl_name_len,
55565601 .child = .u8_type,
55575602 });
5558 const test_name_val = try mod.intern(.{ .aggregate = .{
5603 const test_name_val = try zcu.intern(.{ .aggregate = .{
55595604 .ty = test_name_ty.toIntern(),
55605605 .storage = .{ .bytes = test_decl_name.toString() },
55615606 } });
55625607 break :n .{
5563 .orig_ty = (try mod.singleConstPtrType(test_name_ty)).toIntern(),
5608 .orig_ty = (try zcu.singleConstPtrType(test_name_ty)).toIntern(),
55645609 .val = test_name_val,
55655610 };
55665611 };
55675612
55685613 const test_fn_fields = .{
55695614 // name
5570 try mod.intern(.{ .slice = .{
5615 try zcu.intern(.{ .slice = .{
55715616 .ty = .slice_const_u8_type,
5572 .ptr = try mod.intern(.{ .ptr = .{
5617 .ptr = try zcu.intern(.{ .ptr = .{
55735618 .ty = .manyptr_const_u8_type,
55745619 .base_addr = .{ .anon_decl = test_name_anon_decl },
55755620 .byte_offset = 0,
55765621 } }),
5577 .len = try mod.intern(.{ .int = .{
5622 .len = try zcu.intern(.{ .int = .{
55785623 .ty = .usize_type,
55795624 .storage = .{ .u64 = test_decl_name_len },
55805625 } }),
55815626 } }),
55825627 // func
5583 try mod.intern(.{ .ptr = .{
5584 .ty = try mod.intern(.{ .ptr_type = .{
5585 .child = test_decl.typeOf(mod).toIntern(),
5628 try zcu.intern(.{ .ptr = .{
5629 .ty = try zcu.intern(.{ .ptr_type = .{
5630 .child = test_decl.typeOf(zcu).toIntern(),
55865631 .flags = .{
55875632 .is_const = true,
55885633 },
......@@ -5591,29 +5636,29 @@ pub fn populateTestFunctions(
55915636 .byte_offset = 0,
55925637 } }),
55935638 };
5594 test_fn_val.* = try mod.intern(.{ .aggregate = .{
5639 test_fn_val.* = try zcu.intern(.{ .aggregate = .{
55955640 .ty = test_fn_ty.toIntern(),
55965641 .storage = .{ .elems = &test_fn_fields },
55975642 } });
55985643 }
55995644
5600 const array_ty = try mod.arrayType(.{
5645 const array_ty = try zcu.arrayType(.{
56015646 .len = test_fn_vals.len,
56025647 .child = test_fn_ty.toIntern(),
56035648 .sentinel = .none,
56045649 });
5605 const array_val = try mod.intern(.{ .aggregate = .{
5650 const array_val = try zcu.intern(.{ .aggregate = .{
56065651 .ty = array_ty.toIntern(),
56075652 .storage = .{ .elems = test_fn_vals },
56085653 } });
56095654 break :array .{
5610 .orig_ty = (try mod.singleConstPtrType(array_ty)).toIntern(),
5655 .orig_ty = (try zcu.singleConstPtrType(array_ty)).toIntern(),
56115656 .val = array_val,
56125657 };
56135658 };
56145659
56155660 {
5616 const new_ty = try mod.ptrType(.{
5661 const new_ty = try zcu.ptrType(.{
56175662 .child = test_fn_ty.toIntern(),
56185663 .flags = .{
56195664 .is_const = true,
......@@ -5621,14 +5666,14 @@ pub fn populateTestFunctions(
56215666 },
56225667 });
56235668 const new_val = decl.val;
5624 const new_init = try mod.intern(.{ .slice = .{
5669 const new_init = try zcu.intern(.{ .slice = .{
56255670 .ty = new_ty.toIntern(),
5626 .ptr = try mod.intern(.{ .ptr = .{
5627 .ty = new_ty.slicePtrFieldType(mod).toIntern(),
5671 .ptr = try zcu.intern(.{ .ptr = .{
5672 .ty = new_ty.slicePtrFieldType(zcu).toIntern(),
56285673 .base_addr = .{ .anon_decl = array_anon_decl },
56295674 .byte_offset = 0,
56305675 } }),
5631 .len = (try mod.intValue(Type.usize, mod.test_functions.count())).toIntern(),
5676 .len = (try zcu.intValue(Type.usize, zcu.test_functions.count())).toIntern(),
56325677 } });
56335678 ip.mutateVarInit(decl.val.toIntern(), new_init);
56345679
......@@ -5638,13 +5683,13 @@ pub fn populateTestFunctions(
56385683 decl.has_tv = true;
56395684 }
56405685 {
5641 mod.codegen_prog_node = main_progress_node.start("Code Generation", 0);
5686 zcu.codegen_prog_node = main_progress_node.start("Code Generation", 0);
56425687 defer {
5643 mod.codegen_prog_node.end();
5644 mod.codegen_prog_node = undefined;
5688 zcu.codegen_prog_node.end();
5689 zcu.codegen_prog_node = undefined;
56455690 }
56465691
5647 try mod.linkerUpdateDecl(decl_index);
5692 try zcu.linkerUpdateDecl(decl_index);
56485693 }
56495694}
56505695
......@@ -5684,31 +5729,35 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void {
56845729}
56855730
56865731fn reportRetryableFileError(
5687 mod: *Module,
5688 file: *File,
5732 zcu: *Zcu,
5733 file_index: File.Index,
56895734 comptime format: []const u8,
56905735 args: anytype,
56915736) error{OutOfMemory}!void {
5737 const gpa = zcu.gpa;
5738 const ip = &zcu.intern_pool;
5739
5740 const file = zcu.fileByIndex(file_index);
56925741 file.status = .retryable_failure;
56935742
56945743 const err_msg = try ErrorMsg.create(
5695 mod.gpa,
5744 gpa,
56965745 .{
5697 .base_node_inst = try mod.intern_pool.trackZir(mod.gpa, file, .main_struct_inst),
5746 .base_node_inst = try ip.trackZir(gpa, zcu.filePathDigest(file_index), .main_struct_inst),
56985747 .offset = .entire_file,
56995748 },
57005749 format,
57015750 args,
57025751 );
5703 errdefer err_msg.destroy(mod.gpa);
5752 errdefer err_msg.destroy(gpa);
57045753
5705 mod.comp.mutex.lock();
5706 defer mod.comp.mutex.unlock();
5754 zcu.comp.mutex.lock();
5755 defer zcu.comp.mutex.unlock();
57075756
5708 const gop = try mod.failed_files.getOrPut(mod.gpa, file);
5757 const gop = try zcu.failed_files.getOrPut(gpa, file);
57095758 if (gop.found_existing) {
57105759 if (gop.value_ptr.*) |old_err_msg| {
5711 old_err_msg.destroy(mod.gpa);
5760 old_err_msg.destroy(gpa);
57125761 }
57135762 }
57145763 gop.value_ptr.* = err_msg;
......@@ -6528,8 +6577,9 @@ pub fn getBuiltin(zcu: *Zcu, name: []const u8) Allocator.Error!Air.Inst.Ref {
65286577pub fn getBuiltinDecl(zcu: *Zcu, name: []const u8) Allocator.Error!InternPool.DeclIndex {
65296578 const gpa = zcu.gpa;
65306579 const ip = &zcu.intern_pool;
6531 const std_file = (zcu.importPkg(zcu.std_mod) catch @panic("failed to import lib/std.zig")).file;
6532 const std_namespace = zcu.declPtr(std_file.root_decl.unwrap().?).getOwnedInnerNamespace(zcu).?;
6580 const std_file_imported = zcu.importPkg(zcu.std_mod) catch @panic("failed to import lib/std.zig");
6581 const std_file_root_decl = zcu.fileRootDecl(std_file_imported.file_index).unwrap().?;
6582 const std_namespace = zcu.declPtr(std_file_root_decl).getOwnedInnerNamespace(zcu).?;
65336583 const builtin_str = try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls);
65346584 const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Zcu.DeclAdapter{ .zcu = zcu }) orelse @panic("lib/std.zig is corrupt and missing 'builtin'");
65356585 zcu.ensureDeclAnalyzed(builtin_decl) catch @panic("std.builtin is corrupt");
......@@ -6544,3 +6594,20 @@ pub fn getBuiltinType(zcu: *Zcu, name: []const u8) Allocator.Error!Type {
65446594 ty.resolveFully(zcu) catch @panic("std.builtin is corrupt");
65456595 return ty;
65466596}
6597
6598pub fn fileByIndex(zcu: *const Zcu, i: File.Index) *File {
6599 return zcu.import_table.values()[@intFromEnum(i)];
6600}
6601
6602/// Returns the `Decl` of the struct that represents this `File`.
6603pub fn fileRootDecl(zcu: *const Zcu, i: File.Index) Decl.OptionalIndex {
6604 return zcu.files.values()[@intFromEnum(i)];
6605}
6606
6607pub fn setFileRootDecl(zcu: *Zcu, i: File.Index, root_decl: Decl.OptionalIndex) void {
6608 zcu.files.values()[@intFromEnum(i)] = root_decl;
6609}
6610
6611pub fn filePathDigest(zcu: *const Zcu, i: File.Index) Cache.BinDigest {
6612 return zcu.files.keys()[@intFromEnum(i)];
6613}
src/arch/aarch64/CodeGen.zig+1-1
......@@ -345,7 +345,7 @@ pub fn generate(
345345 assert(fn_owner_decl.has_tv);
346346 const fn_type = fn_owner_decl.typeOf(zcu);
347347 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
348 const target = &namespace.file_scope.mod.resolved_target.result;
348 const target = &namespace.fileScope(zcu).mod.resolved_target.result;
349349
350350 var branch_stack = std.ArrayList(Branch).init(gpa);
351351 defer {
src/arch/arm/CodeGen.zig+1-1
......@@ -352,7 +352,7 @@ pub fn generate(
352352 assert(fn_owner_decl.has_tv);
353353 const fn_type = fn_owner_decl.typeOf(zcu);
354354 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
355 const target = &namespace.file_scope.mod.resolved_target.result;
355 const target = &namespace.fileScope(zcu).mod.resolved_target.result;
356356
357357 var branch_stack = std.ArrayList(Branch).init(gpa);
358358 defer {
src/arch/riscv64/CodeGen.zig+2-2
......@@ -712,8 +712,8 @@ pub fn generate(
712712 assert(fn_owner_decl.has_tv);
713713 const fn_type = fn_owner_decl.typeOf(zcu);
714714 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
715 const target = &namespace.file_scope.mod.resolved_target.result;
716 const mod = namespace.file_scope.mod;
715 const target = &namespace.fileScope(zcu).mod.resolved_target.result;
716 const mod = namespace.fileScope(zcu).mod;
717717
718718 var branch_stack = std.ArrayList(Branch).init(gpa);
719719 defer {
src/arch/sparc64/CodeGen.zig+1-1
......@@ -277,7 +277,7 @@ pub fn generate(
277277 assert(fn_owner_decl.has_tv);
278278 const fn_type = fn_owner_decl.typeOf(zcu);
279279 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
280 const target = &namespace.file_scope.mod.resolved_target.result;
280 const target = &namespace.fileScope(zcu).mod.resolved_target.result;
281281
282282 var branch_stack = std.ArrayList(Branch).init(gpa);
283283 defer {
src/arch/wasm/CodeGen.zig+6-6
......@@ -1212,11 +1212,11 @@ pub fn generate(
12121212 _ = src_loc;
12131213 const comp = bin_file.comp;
12141214 const gpa = comp.gpa;
1215 const mod = comp.module.?;
1216 const func = mod.funcInfo(func_index);
1217 const decl = mod.declPtr(func.owner_decl);
1218 const namespace = mod.namespacePtr(decl.src_namespace);
1219 const target = namespace.file_scope.mod.resolved_target.result;
1215 const zcu = comp.module.?;
1216 const func = zcu.funcInfo(func_index);
1217 const decl = zcu.declPtr(func.owner_decl);
1218 const namespace = zcu.namespacePtr(decl.src_namespace);
1219 const target = namespace.fileScope(zcu).mod.resolved_target.result;
12201220 var code_gen: CodeGen = .{
12211221 .gpa = gpa,
12221222 .air = air,
......@@ -7706,7 +7706,7 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void {
77067706 // for a single-threaded build, can we emit the `fence` instruction.
77077707 // In all other cases, we emit no instructions for a fence.
77087708 const func_namespace = zcu.namespacePtr(func.decl.src_namespace);
7709 const single_threaded = func_namespace.file_scope.mod.single_threaded;
7709 const single_threaded = func_namespace.fileScope(zcu).mod.single_threaded;
77107710 if (func.useAtomicFeature() and !single_threaded) {
77117711 try func.addAtomicTag(.atomic_fence);
77127712 }
src/arch/x86_64/CodeGen.zig+1-1
......@@ -810,7 +810,7 @@ pub fn generate(
810810 assert(fn_owner_decl.has_tv);
811811 const fn_type = fn_owner_decl.typeOf(zcu);
812812 const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace);
813 const mod = namespace.file_scope.mod;
813 const mod = namespace.fileScope(zcu).mod;
814814
815815 var function = Self{
816816 .gpa = gpa,
src/codegen.zig+6-6
......@@ -58,7 +58,7 @@ pub fn generateFunction(
5858 const func = zcu.funcInfo(func_index);
5959 const decl = zcu.declPtr(func.owner_decl);
6060 const namespace = zcu.namespacePtr(decl.src_namespace);
61 const target = namespace.file_scope.mod.resolved_target.result;
61 const target = namespace.fileScope(zcu).mod.resolved_target.result;
6262 switch (target.cpu.arch) {
6363 .arm,
6464 .armeb,
......@@ -88,7 +88,7 @@ pub fn generateLazyFunction(
8888 const decl_index = lazy_sym.ty.getOwnerDecl(zcu);
8989 const decl = zcu.declPtr(decl_index);
9090 const namespace = zcu.namespacePtr(decl.src_namespace);
91 const target = namespace.file_scope.mod.resolved_target.result;
91 const target = namespace.fileScope(zcu).mod.resolved_target.result;
9292 switch (target.cpu.arch) {
9393 .x86_64 => return @import("arch/x86_64/CodeGen.zig").generateLazy(lf, src_loc, lazy_sym, code, debug_output),
9494 else => unreachable,
......@@ -742,7 +742,7 @@ fn lowerDeclRef(
742742 const zcu = lf.comp.module.?;
743743 const decl = zcu.declPtr(decl_index);
744744 const namespace = zcu.namespacePtr(decl.src_namespace);
745 const target = namespace.file_scope.mod.resolved_target.result;
745 const target = namespace.fileScope(zcu).mod.resolved_target.result;
746746
747747 const ptr_width = target.ptrBitWidth();
748748 const is_fn_body = decl.typeOf(zcu).zigTypeTag(zcu) == .Fn;
......@@ -836,7 +836,7 @@ fn genDeclRef(
836836
837837 const ptr_decl = zcu.declPtr(ptr_decl_index);
838838 const namespace = zcu.namespacePtr(ptr_decl.src_namespace);
839 const target = namespace.file_scope.mod.resolved_target.result;
839 const target = namespace.fileScope(zcu).mod.resolved_target.result;
840840
841841 const ptr_bits = target.ptrBitWidth();
842842 const ptr_bytes: u64 = @divExact(ptr_bits, 8);
......@@ -875,7 +875,7 @@ fn genDeclRef(
875875 }
876876
877877 const decl_namespace = zcu.namespacePtr(decl.src_namespace);
878 const single_threaded = decl_namespace.file_scope.mod.single_threaded;
878 const single_threaded = decl_namespace.fileScope(zcu).mod.single_threaded;
879879 const is_threadlocal = val.isPtrToThreadLocal(zcu) and !single_threaded;
880880 const is_extern = decl.isExtern(zcu);
881881
......@@ -985,7 +985,7 @@ pub fn genTypedValue(
985985
986986 const owner_decl = zcu.declPtr(owner_decl_index);
987987 const namespace = zcu.namespacePtr(owner_decl.src_namespace);
988 const target = namespace.file_scope.mod.resolved_target.result;
988 const target = namespace.fileScope(zcu).mod.resolved_target.result;
989989 const ptr_bits = target.ptrBitWidth();
990990
991991 if (!ty.isSlice(zcu)) switch (ip.indexToKey(val.toIntern())) {
src/codegen/c.zig+1-1
......@@ -2581,7 +2581,7 @@ pub fn genTypeDecl(
25812581 _ = try renderTypePrefix(.flush, global_ctype_pool, zcu, writer, global_ctype, .suffix, .{});
25822582 try writer.writeByte(';');
25832583 const owner_decl = zcu.declPtr(owner_decl_index);
2584 const owner_mod = zcu.namespacePtr(owner_decl.src_namespace).file_scope.mod;
2584 const owner_mod = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu).mod;
25852585 if (!owner_mod.strip) {
25862586 try writer.writeAll(" /* ");
25872587 try owner_decl.renderFullyQualifiedName(zcu, writer);
src/codegen/llvm.zig+150-141
......@@ -1362,7 +1362,8 @@ pub const Object = struct {
13621362 const decl_index = func.owner_decl;
13631363 const decl = zcu.declPtr(decl_index);
13641364 const namespace = zcu.namespacePtr(decl.src_namespace);
1365 const owner_mod = namespace.file_scope.mod;
1365 const file_scope = namespace.fileScope(zcu);
1366 const owner_mod = file_scope.mod;
13661367 const fn_info = zcu.typeToFunc(decl.typeOf(zcu)).?;
13671368 const target = owner_mod.resolved_target.result;
13681369 const ip = &zcu.intern_pool;
......@@ -1633,7 +1634,7 @@ pub const Object = struct {
16331634 function_index.setAttributes(try attributes.finish(&o.builder), &o.builder);
16341635
16351636 const file, const subprogram = if (!wip.strip) debug_info: {
1636 const file = try o.getDebugFile(namespace.file_scope);
1637 const file = try o.getDebugFile(file_scope);
16371638
16381639 const line_number = decl.navSrcLine(zcu) + 1;
16391640 const is_internal_linkage = decl.val.getExternFunc(zcu) == null;
......@@ -1720,23 +1721,23 @@ pub const Object = struct {
17201721
17211722 pub fn updateExports(
17221723 self: *Object,
1723 mod: *Module,
1724 zcu: *Zcu,
17241725 exported: Module.Exported,
17251726 export_indices: []const u32,
17261727 ) link.File.UpdateExportsError!void {
17271728 const decl_index = switch (exported) {
17281729 .decl_index => |i| i,
1729 .value => |val| return updateExportedValue(self, mod, val, export_indices),
1730 .value => |val| return updateExportedValue(self, zcu, val, export_indices),
17301731 };
1731 const ip = &mod.intern_pool;
1732 const ip = &zcu.intern_pool;
17321733 const global_index = self.decl_map.get(decl_index).?;
1733 const decl = mod.declPtr(decl_index);
1734 const comp = mod.comp;
1734 const decl = zcu.declPtr(decl_index);
1735 const comp = zcu.comp;
17351736
17361737 if (export_indices.len != 0) {
1737 return updateExportedGlobal(self, mod, global_index, export_indices);
1738 return updateExportedGlobal(self, zcu, global_index, export_indices);
17381739 } else {
1739 const fqn = try self.builder.strtabString((try decl.fullyQualifiedName(mod)).toSlice(ip));
1740 const fqn = try self.builder.strtabString((try decl.fullyQualifiedName(zcu)).toSlice(ip));
17401741 try global_index.rename(fqn, &self.builder);
17411742 global_index.setLinkage(.internal, &self.builder);
17421743 if (comp.config.dll_export_fns)
......@@ -1908,12 +1909,12 @@ pub const Object = struct {
19081909
19091910 const gpa = o.gpa;
19101911 const target = o.target;
1911 const mod = o.module;
1912 const ip = &mod.intern_pool;
1912 const zcu = o.module;
1913 const ip = &zcu.intern_pool;
19131914
19141915 if (o.debug_type_map.get(ty)) |debug_type| return debug_type;
19151916
1916 switch (ty.zigTypeTag(mod)) {
1917 switch (ty.zigTypeTag(zcu)) {
19171918 .Void,
19181919 .NoReturn,
19191920 => {
......@@ -1925,12 +1926,12 @@ pub const Object = struct {
19251926 return debug_void_type;
19261927 },
19271928 .Int => {
1928 const info = ty.intInfo(mod);
1929 const info = ty.intInfo(zcu);
19291930 assert(info.bits != 0);
19301931 const name = try o.allocTypeName(ty);
19311932 defer gpa.free(name);
19321933 const builder_name = try o.builder.metadataString(name);
1933 const debug_bits = ty.abiSize(mod) * 8; // lldb cannot handle non-byte sized types
1934 const debug_bits = ty.abiSize(zcu) * 8; // lldb cannot handle non-byte sized types
19341935 const debug_int_type = switch (info.signedness) {
19351936 .signed => try o.builder.debugSignedType(builder_name, debug_bits),
19361937 .unsigned => try o.builder.debugUnsignedType(builder_name, debug_bits),
......@@ -1939,10 +1940,10 @@ pub const Object = struct {
19391940 return debug_int_type;
19401941 },
19411942 .Enum => {
1942 const owner_decl_index = ty.getOwnerDecl(mod);
1943 const owner_decl_index = ty.getOwnerDecl(zcu);
19431944 const owner_decl = o.module.declPtr(owner_decl_index);
19441945
1945 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) {
1946 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
19461947 const debug_enum_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
19471948 try o.debug_type_map.put(gpa, ty, debug_enum_type);
19481949 return debug_enum_type;
......@@ -1954,13 +1955,13 @@ pub const Object = struct {
19541955 defer gpa.free(enumerators);
19551956
19561957 const int_ty = Type.fromInterned(enum_type.tag_ty);
1957 const int_info = ty.intInfo(mod);
1958 const int_info = ty.intInfo(zcu);
19581959 assert(int_info.bits != 0);
19591960
19601961 for (enum_type.names.get(ip), 0..) |field_name_ip, i| {
19611962 var bigint_space: Value.BigIntSpace = undefined;
19621963 const bigint = if (enum_type.values.len != 0)
1963 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, mod)
1964 Value.fromInterned(enum_type.values.get(ip)[i]).toBigInt(&bigint_space, zcu)
19641965 else
19651966 std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst();
19661967
......@@ -1972,7 +1973,8 @@ pub const Object = struct {
19721973 );
19731974 }
19741975
1975 const file = try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope);
1976 const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu);
1977 const file = try o.getDebugFile(file_scope);
19761978 const scope = try o.namespaceToDebugScope(owner_decl.src_namespace);
19771979
19781980 const name = try o.allocTypeName(ty);
......@@ -1982,10 +1984,10 @@ pub const Object = struct {
19821984 try o.builder.metadataString(name),
19831985 file,
19841986 scope,
1985 owner_decl.typeSrcLine(mod) + 1, // Line
1987 owner_decl.typeSrcLine(zcu) + 1, // Line
19861988 try o.lowerDebugType(int_ty),
1987 ty.abiSize(mod) * 8,
1988 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
1989 ty.abiSize(zcu) * 8,
1990 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
19891991 try o.builder.debugTuple(enumerators),
19901992 );
19911993
......@@ -2014,7 +2016,7 @@ pub const Object = struct {
20142016 },
20152017 .Pointer => {
20162018 // Normalize everything that the debug info does not represent.
2017 const ptr_info = ty.ptrInfo(mod);
2019 const ptr_info = ty.ptrInfo(zcu);
20182020
20192021 if (ptr_info.sentinel != .none or
20202022 ptr_info.flags.address_space != .generic or
......@@ -2025,10 +2027,10 @@ pub const Object = struct {
20252027 ptr_info.flags.is_const or
20262028 ptr_info.flags.is_volatile or
20272029 ptr_info.flags.size == .Many or ptr_info.flags.size == .C or
2028 !Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(mod))
2030 !Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(zcu))
20292031 {
2030 const bland_ptr_ty = try mod.ptrType(.{
2031 .child = if (!Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(mod))
2032 const bland_ptr_ty = try zcu.ptrType(.{
2033 .child = if (!Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(zcu))
20322034 .anyopaque_type
20332035 else
20342036 ptr_info.child,
......@@ -2050,18 +2052,18 @@ pub const Object = struct {
20502052 // Set as forward reference while the type is lowered in case it references itself
20512053 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
20522054
2053 if (ty.isSlice(mod)) {
2054 const ptr_ty = ty.slicePtrFieldType(mod);
2055 if (ty.isSlice(zcu)) {
2056 const ptr_ty = ty.slicePtrFieldType(zcu);
20552057 const len_ty = Type.usize;
20562058
20572059 const name = try o.allocTypeName(ty);
20582060 defer gpa.free(name);
20592061 const line = 0;
20602062
2061 const ptr_size = ptr_ty.abiSize(mod);
2062 const ptr_align = ptr_ty.abiAlignment(mod);
2063 const len_size = len_ty.abiSize(mod);
2064 const len_align = len_ty.abiAlignment(mod);
2063 const ptr_size = ptr_ty.abiSize(zcu);
2064 const ptr_align = ptr_ty.abiAlignment(zcu);
2065 const len_size = len_ty.abiSize(zcu);
2066 const len_align = len_ty.abiAlignment(zcu);
20652067
20662068 const len_offset = len_align.forward(ptr_size);
20672069
......@@ -2093,8 +2095,8 @@ pub const Object = struct {
20932095 o.debug_compile_unit, // Scope
20942096 line,
20952097 .none, // Underlying type
2096 ty.abiSize(mod) * 8,
2097 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
2098 ty.abiSize(zcu) * 8,
2099 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
20982100 try o.builder.debugTuple(&.{
20992101 debug_ptr_type,
21002102 debug_len_type,
......@@ -2122,7 +2124,7 @@ pub const Object = struct {
21222124 0, // Line
21232125 debug_elem_ty,
21242126 target.ptrBitWidth(),
2125 (ty.ptrAlignment(mod).toByteUnits() orelse 0) * 8,
2127 (ty.ptrAlignment(zcu).toByteUnits() orelse 0) * 8,
21262128 0, // Offset
21272129 );
21282130
......@@ -2146,13 +2148,14 @@ pub const Object = struct {
21462148
21472149 const name = try o.allocTypeName(ty);
21482150 defer gpa.free(name);
2149 const owner_decl_index = ty.getOwnerDecl(mod);
2151 const owner_decl_index = ty.getOwnerDecl(zcu);
21502152 const owner_decl = o.module.declPtr(owner_decl_index);
2153 const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu);
21512154 const debug_opaque_type = try o.builder.debugStructType(
21522155 try o.builder.metadataString(name),
2153 try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope),
2156 try o.getDebugFile(file_scope),
21542157 try o.namespaceToDebugScope(owner_decl.src_namespace),
2155 owner_decl.typeSrcLine(mod) + 1, // Line
2158 owner_decl.typeSrcLine(zcu) + 1, // Line
21562159 .none, // Underlying type
21572160 0, // Size
21582161 0, // Align
......@@ -2167,13 +2170,13 @@ pub const Object = struct {
21672170 .none, // File
21682171 .none, // Scope
21692172 0, // Line
2170 try o.lowerDebugType(ty.childType(mod)),
2171 ty.abiSize(mod) * 8,
2172 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
2173 try o.lowerDebugType(ty.childType(zcu)),
2174 ty.abiSize(zcu) * 8,
2175 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
21732176 try o.builder.debugTuple(&.{
21742177 try o.builder.debugSubrange(
21752178 try o.builder.debugConstant(try o.builder.intConst(.i64, 0)),
2176 try o.builder.debugConstant(try o.builder.intConst(.i64, ty.arrayLen(mod))),
2179 try o.builder.debugConstant(try o.builder.intConst(.i64, ty.arrayLen(zcu))),
21772180 ),
21782181 }),
21792182 );
......@@ -2181,14 +2184,14 @@ pub const Object = struct {
21812184 return debug_array_type;
21822185 },
21832186 .Vector => {
2184 const elem_ty = ty.elemType2(mod);
2187 const elem_ty = ty.elemType2(zcu);
21852188 // Vector elements cannot be padded since that would make
21862189 // @bitSizOf(elem) * len > @bitSizOf(vec).
21872190 // Neither gdb nor lldb seem to be able to display non-byte sized
21882191 // vectors properly.
2189 const debug_elem_type = switch (elem_ty.zigTypeTag(mod)) {
2192 const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) {
21902193 .Int => blk: {
2191 const info = elem_ty.intInfo(mod);
2194 const info = elem_ty.intInfo(zcu);
21922195 assert(info.bits != 0);
21932196 const name = try o.allocTypeName(ty);
21942197 defer gpa.free(name);
......@@ -2202,7 +2205,7 @@ pub const Object = struct {
22022205 try o.builder.metadataString("bool"),
22032206 1,
22042207 ),
2205 else => try o.lowerDebugType(ty.childType(mod)),
2208 else => try o.lowerDebugType(ty.childType(zcu)),
22062209 };
22072210
22082211 const debug_vector_type = try o.builder.debugVectorType(
......@@ -2211,12 +2214,12 @@ pub const Object = struct {
22112214 .none, // Scope
22122215 0, // Line
22132216 debug_elem_type,
2214 ty.abiSize(mod) * 8,
2215 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
2217 ty.abiSize(zcu) * 8,
2218 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
22162219 try o.builder.debugTuple(&.{
22172220 try o.builder.debugSubrange(
22182221 try o.builder.debugConstant(try o.builder.intConst(.i64, 0)),
2219 try o.builder.debugConstant(try o.builder.intConst(.i64, ty.vectorLen(mod))),
2222 try o.builder.debugConstant(try o.builder.intConst(.i64, ty.vectorLen(zcu))),
22202223 ),
22212224 }),
22222225 );
......@@ -2227,8 +2230,8 @@ pub const Object = struct {
22272230 .Optional => {
22282231 const name = try o.allocTypeName(ty);
22292232 defer gpa.free(name);
2230 const child_ty = ty.optionalChild(mod);
2231 if (!child_ty.hasRuntimeBitsIgnoreComptime(mod)) {
2233 const child_ty = ty.optionalChild(zcu);
2234 if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
22322235 const debug_bool_type = try o.builder.debugBoolType(
22332236 try o.builder.metadataString(name),
22342237 8,
......@@ -2242,7 +2245,7 @@ pub const Object = struct {
22422245 // Set as forward reference while the type is lowered in case it references itself
22432246 try o.debug_type_map.put(gpa, ty, debug_fwd_ref);
22442247
2245 if (ty.optionalReprIsPayload(mod)) {
2248 if (ty.optionalReprIsPayload(zcu)) {
22462249 const debug_optional_type = try o.lowerDebugType(child_ty);
22472250
22482251 o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type);
......@@ -2255,10 +2258,10 @@ pub const Object = struct {
22552258 }
22562259
22572260 const non_null_ty = Type.u8;
2258 const payload_size = child_ty.abiSize(mod);
2259 const payload_align = child_ty.abiAlignment(mod);
2260 const non_null_size = non_null_ty.abiSize(mod);
2261 const non_null_align = non_null_ty.abiAlignment(mod);
2261 const payload_size = child_ty.abiSize(zcu);
2262 const payload_align = child_ty.abiAlignment(zcu);
2263 const non_null_size = non_null_ty.abiSize(zcu);
2264 const non_null_align = non_null_ty.abiAlignment(zcu);
22622265 const non_null_offset = non_null_align.forward(payload_size);
22632266
22642267 const debug_data_type = try o.builder.debugMemberType(
......@@ -2289,8 +2292,8 @@ pub const Object = struct {
22892292 o.debug_compile_unit, // Scope
22902293 0, // Line
22912294 .none, // Underlying type
2292 ty.abiSize(mod) * 8,
2293 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
2295 ty.abiSize(zcu) * 8,
2296 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
22942297 try o.builder.debugTuple(&.{
22952298 debug_data_type,
22962299 debug_some_type,
......@@ -2306,8 +2309,8 @@ pub const Object = struct {
23062309 return debug_optional_type;
23072310 },
23082311 .ErrorUnion => {
2309 const payload_ty = ty.errorUnionPayload(mod);
2310 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
2312 const payload_ty = ty.errorUnionPayload(zcu);
2313 if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) {
23112314 // TODO: Maybe remove?
23122315 const debug_error_union_type = try o.lowerDebugType(Type.anyerror);
23132316 try o.debug_type_map.put(gpa, ty, debug_error_union_type);
......@@ -2317,10 +2320,10 @@ pub const Object = struct {
23172320 const name = try o.allocTypeName(ty);
23182321 defer gpa.free(name);
23192322
2320 const error_size = Type.anyerror.abiSize(mod);
2321 const error_align = Type.anyerror.abiAlignment(mod);
2322 const payload_size = payload_ty.abiSize(mod);
2323 const payload_align = payload_ty.abiAlignment(mod);
2323 const error_size = Type.anyerror.abiSize(zcu);
2324 const error_align = Type.anyerror.abiAlignment(zcu);
2325 const payload_size = payload_ty.abiSize(zcu);
2326 const payload_align = payload_ty.abiAlignment(zcu);
23242327
23252328 var error_index: u32 = undefined;
23262329 var payload_index: u32 = undefined;
......@@ -2368,8 +2371,8 @@ pub const Object = struct {
23682371 o.debug_compile_unit, // Sope
23692372 0, // Line
23702373 .none, // Underlying type
2371 ty.abiSize(mod) * 8,
2372 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
2374 ty.abiSize(zcu) * 8,
2375 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
23732376 try o.builder.debugTuple(&fields),
23742377 );
23752378
......@@ -2390,14 +2393,14 @@ pub const Object = struct {
23902393 const name = try o.allocTypeName(ty);
23912394 defer gpa.free(name);
23922395
2393 if (mod.typeToPackedStruct(ty)) |struct_type| {
2396 if (zcu.typeToPackedStruct(ty)) |struct_type| {
23942397 const backing_int_ty = struct_type.backingIntType(ip).*;
23952398 if (backing_int_ty != .none) {
2396 const info = Type.fromInterned(backing_int_ty).intInfo(mod);
2399 const info = Type.fromInterned(backing_int_ty).intInfo(zcu);
23972400 const builder_name = try o.builder.metadataString(name);
23982401 const debug_int_type = switch (info.signedness) {
2399 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(mod) * 8),
2400 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(mod) * 8),
2402 .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(zcu) * 8),
2403 .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(zcu) * 8),
24012404 };
24022405 try o.debug_type_map.put(gpa, ty, debug_int_type);
24032406 return debug_int_type;
......@@ -2417,10 +2420,10 @@ pub const Object = struct {
24172420 const debug_fwd_ref = try o.builder.debugForwardReference();
24182421
24192422 for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| {
2420 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
2423 if (field_val != .none or !Type.fromInterned(field_ty).hasRuntimeBits(zcu)) continue;
24212424
2422 const field_size = Type.fromInterned(field_ty).abiSize(mod);
2423 const field_align = Type.fromInterned(field_ty).abiAlignment(mod);
2425 const field_size = Type.fromInterned(field_ty).abiSize(zcu);
2426 const field_align = Type.fromInterned(field_ty).abiAlignment(zcu);
24242427 const field_offset = field_align.forward(offset);
24252428 offset = field_offset + field_size;
24262429
......@@ -2448,8 +2451,8 @@ pub const Object = struct {
24482451 o.debug_compile_unit, // Scope
24492452 0, // Line
24502453 .none, // Underlying type
2451 ty.abiSize(mod) * 8,
2452 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
2454 ty.abiSize(zcu) * 8,
2455 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
24532456 try o.builder.debugTuple(fields.items),
24542457 );
24552458
......@@ -2467,7 +2470,7 @@ pub const Object = struct {
24672470 // into. Therefore we can satisfy this by making an empty namespace,
24682471 // rather than changing the frontend to unnecessarily resolve the
24692472 // struct field types.
2470 const owner_decl_index = ty.getOwnerDecl(mod);
2473 const owner_decl_index = ty.getOwnerDecl(zcu);
24712474 const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
24722475 try o.debug_type_map.put(gpa, ty, debug_struct_type);
24732476 return debug_struct_type;
......@@ -2476,14 +2479,14 @@ pub const Object = struct {
24762479 else => {},
24772480 }
24782481
2479 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) {
2480 const owner_decl_index = ty.getOwnerDecl(mod);
2482 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
2483 const owner_decl_index = ty.getOwnerDecl(zcu);
24812484 const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
24822485 try o.debug_type_map.put(gpa, ty, debug_struct_type);
24832486 return debug_struct_type;
24842487 }
24852488
2486 const struct_type = mod.typeToStruct(ty).?;
2489 const struct_type = zcu.typeToStruct(ty).?;
24872490
24882491 var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{};
24892492 defer fields.deinit(gpa);
......@@ -2499,14 +2502,14 @@ pub const Object = struct {
24992502 var it = struct_type.iterateRuntimeOrder(ip);
25002503 while (it.next()) |field_index| {
25012504 const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]);
2502 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
2503 const field_size = field_ty.abiSize(mod);
2504 const field_align = mod.structFieldAlignment(
2505 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
2506 const field_size = field_ty.abiSize(zcu);
2507 const field_align = zcu.structFieldAlignment(
25052508 struct_type.fieldAlign(ip, field_index),
25062509 field_ty,
25072510 struct_type.layout,
25082511 );
2509 const field_offset = ty.structFieldOffset(field_index, mod);
2512 const field_offset = ty.structFieldOffset(field_index, zcu);
25102513
25112514 const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse
25122515 try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls);
......@@ -2529,8 +2532,8 @@ pub const Object = struct {
25292532 o.debug_compile_unit, // Scope
25302533 0, // Line
25312534 .none, // Underlying type
2532 ty.abiSize(mod) * 8,
2533 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
2535 ty.abiSize(zcu) * 8,
2536 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
25342537 try o.builder.debugTuple(fields.items),
25352538 );
25362539
......@@ -2543,14 +2546,14 @@ pub const Object = struct {
25432546 return debug_struct_type;
25442547 },
25452548 .Union => {
2546 const owner_decl_index = ty.getOwnerDecl(mod);
2549 const owner_decl_index = ty.getOwnerDecl(zcu);
25472550
25482551 const name = try o.allocTypeName(ty);
25492552 defer gpa.free(name);
25502553
25512554 const union_type = ip.loadUnionType(ty.toIntern());
25522555 if (!union_type.haveFieldTypes(ip) or
2553 !ty.hasRuntimeBitsIgnoreComptime(mod) or
2556 !ty.hasRuntimeBitsIgnoreComptime(zcu) or
25542557 !union_type.haveLayout(ip))
25552558 {
25562559 const debug_union_type = try o.makeEmptyNamespaceDebugType(owner_decl_index);
......@@ -2558,7 +2561,7 @@ pub const Object = struct {
25582561 return debug_union_type;
25592562 }
25602563
2561 const layout = mod.getUnionLayout(union_type);
2564 const layout = zcu.getUnionLayout(union_type);
25622565
25632566 const debug_fwd_ref = try o.builder.debugForwardReference();
25642567
......@@ -2572,8 +2575,8 @@ pub const Object = struct {
25722575 o.debug_compile_unit, // Scope
25732576 0, // Line
25742577 .none, // Underlying type
2575 ty.abiSize(mod) * 8,
2576 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
2578 ty.abiSize(zcu) * 8,
2579 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
25772580 try o.builder.debugTuple(
25782581 &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))},
25792582 ),
......@@ -2600,12 +2603,12 @@ pub const Object = struct {
26002603
26012604 for (0..tag_type.names.len) |field_index| {
26022605 const field_ty = union_type.field_types.get(ip)[field_index];
2603 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
2606 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(zcu)) continue;
26042607
2605 const field_size = Type.fromInterned(field_ty).abiSize(mod);
2608 const field_size = Type.fromInterned(field_ty).abiSize(zcu);
26062609 const field_align: InternPool.Alignment = switch (union_type.flagsPtr(ip).layout) {
26072610 .@"packed" => .none,
2608 .auto, .@"extern" => mod.unionFieldNormalAlignment(union_type, @intCast(field_index)),
2611 .auto, .@"extern" => zcu.unionFieldNormalAlignment(union_type, @intCast(field_index)),
26092612 };
26102613
26112614 const field_name = tag_type.names.get(ip)[field_index];
......@@ -2634,8 +2637,8 @@ pub const Object = struct {
26342637 o.debug_compile_unit, // Scope
26352638 0, // Line
26362639 .none, // Underlying type
2637 ty.abiSize(mod) * 8,
2638 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
2640 ty.abiSize(zcu) * 8,
2641 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
26392642 try o.builder.debugTuple(fields.items),
26402643 );
26412644
......@@ -2693,8 +2696,8 @@ pub const Object = struct {
26932696 o.debug_compile_unit, // Scope
26942697 0, // Line
26952698 .none, // Underlying type
2696 ty.abiSize(mod) * 8,
2697 (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8,
2699 ty.abiSize(zcu) * 8,
2700 (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8,
26982701 try o.builder.debugTuple(&full_fields),
26992702 );
27002703
......@@ -2707,7 +2710,7 @@ pub const Object = struct {
27072710 return debug_tagged_union_type;
27082711 },
27092712 .Fn => {
2710 const fn_info = mod.typeToFunc(ty).?;
2713 const fn_info = zcu.typeToFunc(ty).?;
27112714
27122715 var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa);
27132716 defer debug_param_types.deinit();
......@@ -2715,32 +2718,32 @@ pub const Object = struct {
27152718 try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len);
27162719
27172720 // Return type goes first.
2718 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(mod)) {
2719 const sret = firstParamSRet(fn_info, mod, target);
2721 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) {
2722 const sret = firstParamSRet(fn_info, zcu, target);
27202723 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
27212724 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));
27222725
27232726 if (sret) {
2724 const ptr_ty = try mod.singleMutPtrType(Type.fromInterned(fn_info.return_type));
2727 const ptr_ty = try zcu.singleMutPtrType(Type.fromInterned(fn_info.return_type));
27252728 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
27262729 }
27272730 } else {
27282731 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void));
27292732 }
27302733
2731 if (Type.fromInterned(fn_info.return_type).isError(mod) and
2734 if (Type.fromInterned(fn_info.return_type).isError(zcu) and
27322735 o.module.comp.config.any_error_tracing)
27332736 {
2734 const ptr_ty = try mod.singleMutPtrType(try o.getStackTraceType());
2737 const ptr_ty = try zcu.singleMutPtrType(try o.getStackTraceType());
27352738 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
27362739 }
27372740
27382741 for (0..fn_info.param_types.len) |i| {
27392742 const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]);
2740 if (!param_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
2743 if (!param_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
27412744
2742 if (isByRef(param_ty, mod)) {
2743 const ptr_ty = try mod.singleMutPtrType(param_ty);
2745 if (isByRef(param_ty, zcu)) {
2746 const ptr_ty = try zcu.singleMutPtrType(param_ty);
27442747 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty));
27452748 } else {
27462749 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty));
......@@ -2767,9 +2770,10 @@ pub const Object = struct {
27672770 }
27682771
27692772 fn namespaceToDebugScope(o: *Object, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata {
2770 const mod = o.module;
2771 const namespace = mod.namespacePtr(namespace_index);
2772 if (namespace.parent == .none) return try o.getDebugFile(namespace.file_scope);
2773 const zcu = o.module;
2774 const namespace = zcu.namespacePtr(namespace_index);
2775 const file_scope = namespace.fileScope(zcu);
2776 if (namespace.parent == .none) return try o.getDebugFile(file_scope);
27732777
27742778 const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index);
27752779
......@@ -2779,13 +2783,14 @@ pub const Object = struct {
27792783 }
27802784
27812785 fn makeEmptyNamespaceDebugType(o: *Object, decl_index: InternPool.DeclIndex) !Builder.Metadata {
2782 const mod = o.module;
2783 const decl = mod.declPtr(decl_index);
2786 const zcu = o.module;
2787 const decl = zcu.declPtr(decl_index);
2788 const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu);
27842789 return o.builder.debugStructType(
2785 try o.builder.metadataString(decl.name.toSlice(&mod.intern_pool)), // TODO use fully qualified name
2786 try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope),
2790 try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)), // TODO use fully qualified name
2791 try o.getDebugFile(file_scope),
27872792 try o.namespaceToDebugScope(decl.src_namespace),
2788 decl.typeSrcLine(mod) + 1,
2793 decl.typeSrcLine(zcu) + 1,
27892794 .none,
27902795 0,
27912796 0,
......@@ -2794,21 +2799,22 @@ pub const Object = struct {
27942799 }
27952800
27962801 fn getStackTraceType(o: *Object) Allocator.Error!Type {
2797 const mod = o.module;
2802 const zcu = o.module;
27982803
2799 const std_mod = mod.std_mod;
2800 const std_file = (mod.importPkg(std_mod) catch unreachable).file;
2804 const std_mod = zcu.std_mod;
2805 const std_file_imported = zcu.importPkg(std_mod) catch unreachable;
28012806
2802 const builtin_str = try mod.intern_pool.getOrPutString(mod.gpa, "builtin", .no_embedded_nulls);
2803 const std_namespace = mod.namespacePtr(mod.declPtr(std_file.root_decl.unwrap().?).src_namespace);
2804 const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Module.DeclAdapter{ .zcu = mod }).?;
2807 const builtin_str = try zcu.intern_pool.getOrPutString(zcu.gpa, "builtin", .no_embedded_nulls);
2808 const std_file_root_decl = zcu.fileRootDecl(std_file_imported.file_index);
2809 const std_namespace = zcu.namespacePtr(zcu.declPtr(std_file_root_decl.unwrap().?).src_namespace);
2810 const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Module.DeclAdapter{ .zcu = zcu }).?;
28052811
2806 const stack_trace_str = try mod.intern_pool.getOrPutString(mod.gpa, "StackTrace", .no_embedded_nulls);
2812 const stack_trace_str = try zcu.intern_pool.getOrPutString(zcu.gpa, "StackTrace", .no_embedded_nulls);
28072813 // buffer is only used for int_type, `builtin` is a struct.
2808 const builtin_ty = mod.declPtr(builtin_decl).val.toType();
2809 const builtin_namespace = mod.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(mod)).?;
2810 const stack_trace_decl_index = builtin_namespace.decls.getKeyAdapted(stack_trace_str, Module.DeclAdapter{ .zcu = mod }).?;
2811 const stack_trace_decl = mod.declPtr(stack_trace_decl_index);
2814 const builtin_ty = zcu.declPtr(builtin_decl).val.toType();
2815 const builtin_namespace = zcu.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(zcu)).?;
2816 const stack_trace_decl_index = builtin_namespace.decls.getKeyAdapted(stack_trace_str, Module.DeclAdapter{ .zcu = zcu }).?;
2817 const stack_trace_decl = zcu.declPtr(stack_trace_decl_index);
28122818
28132819 // Sema should have ensured that StackTrace was analyzed.
28142820 assert(stack_trace_decl.has_tv);
......@@ -2834,7 +2840,7 @@ pub const Object = struct {
28342840 const gpa = o.gpa;
28352841 const decl = zcu.declPtr(decl_index);
28362842 const namespace = zcu.namespacePtr(decl.src_namespace);
2837 const owner_mod = namespace.file_scope.mod;
2843 const owner_mod = namespace.fileScope(zcu).mod;
28382844 const zig_fn_type = decl.typeOf(zcu);
28392845 const gop = try o.decl_map.getOrPut(gpa, decl_index);
28402846 if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function;
......@@ -3059,17 +3065,17 @@ pub const Object = struct {
30593065 if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable;
30603066 errdefer assert(o.decl_map.remove(decl_index));
30613067
3062 const mod = o.module;
3063 const decl = mod.declPtr(decl_index);
3064 const is_extern = decl.isExtern(mod);
3068 const zcu = o.module;
3069 const decl = zcu.declPtr(decl_index);
3070 const is_extern = decl.isExtern(zcu);
30653071
30663072 const variable_index = try o.builder.addVariable(
30673073 try o.builder.strtabString((if (is_extern)
30683074 decl.name
30693075 else
3070 try decl.fullyQualifiedName(mod)).toSlice(&mod.intern_pool)),
3071 try o.lowerType(decl.typeOf(mod)),
3072 toLlvmGlobalAddressSpace(decl.@"addrspace", mod.getTarget()),
3076 try decl.fullyQualifiedName(zcu)).toSlice(&zcu.intern_pool)),
3077 try o.lowerType(decl.typeOf(zcu)),
3078 toLlvmGlobalAddressSpace(decl.@"addrspace", zcu.getTarget()),
30733079 );
30743080 gop.value_ptr.* = variable_index.ptrConst(&o.builder).global;
30753081
......@@ -3077,9 +3083,9 @@ pub const Object = struct {
30773083 if (is_extern) {
30783084 variable_index.setLinkage(.external, &o.builder);
30793085 variable_index.setUnnamedAddr(.default, &o.builder);
3080 if (decl.val.getVariable(mod)) |decl_var| {
3081 const decl_namespace = mod.namespacePtr(decl.src_namespace);
3082 const single_threaded = decl_namespace.file_scope.mod.single_threaded;
3086 if (decl.val.getVariable(zcu)) |decl_var| {
3087 const decl_namespace = zcu.namespacePtr(decl.src_namespace);
3088 const single_threaded = decl_namespace.fileScope(zcu).mod.single_threaded;
30833089 variable_index.setThreadLocal(
30843090 if (decl_var.is_threadlocal and !single_threaded) .generaldynamic else .default,
30853091 &o.builder,
......@@ -4638,7 +4644,8 @@ pub const DeclGen = struct {
46384644 const o = dg.object;
46394645 const zcu = o.module;
46404646 const namespace = zcu.namespacePtr(dg.decl.src_namespace);
4641 return namespace.file_scope.mod;
4647 const file_scope = namespace.fileScope(zcu);
4648 return file_scope.mod;
46424649 }
46434650
46444651 fn todo(dg: *DeclGen, comptime format: []const u8, args: anytype) Error {
......@@ -4682,7 +4689,7 @@ pub const DeclGen = struct {
46824689
46834690 if (decl.val.getVariable(zcu)) |decl_var| {
46844691 const decl_namespace = zcu.namespacePtr(decl.src_namespace);
4685 const single_threaded = decl_namespace.file_scope.mod.single_threaded;
4692 const single_threaded = decl_namespace.fileScope(zcu).mod.single_threaded;
46864693 variable_index.setThreadLocal(
46874694 if (decl_var.is_threadlocal and !single_threaded) .generaldynamic else .default,
46884695 &o.builder,
......@@ -4692,10 +4699,11 @@ pub const DeclGen = struct {
46924699 const line_number = decl.navSrcLine(zcu) + 1;
46934700
46944701 const namespace = zcu.namespacePtr(decl.src_namespace);
4695 const owner_mod = namespace.file_scope.mod;
4702 const file_scope = namespace.fileScope(zcu);
4703 const owner_mod = file_scope.mod;
46964704
46974705 if (!owner_mod.strip) {
4698 const debug_file = try o.getDebugFile(namespace.file_scope);
4706 const debug_file = try o.getDebugFile(file_scope);
46994707
47004708 const debug_global_var = try o.builder.debugGlobalVar(
47014709 try o.builder.metadataString(decl.name.toSlice(ip)), // Name
......@@ -5143,9 +5151,10 @@ pub const FuncGen = struct {
51435151 const decl_index = func.owner_decl;
51445152 const decl = zcu.declPtr(decl_index);
51455153 const namespace = zcu.namespacePtr(decl.src_namespace);
5146 const owner_mod = namespace.file_scope.mod;
5154 const file_scope = namespace.fileScope(zcu);
5155 const owner_mod = file_scope.mod;
51475156
5148 self.file = try o.getDebugFile(namespace.file_scope);
5157 self.file = try o.getDebugFile(file_scope);
51495158
51505159 const line_number = decl.navSrcLine(zcu) + 1;
51515160 self.inlined = self.wip.debug_location;
src/codegen/spirv.zig+10-9
......@@ -188,19 +188,20 @@ pub const Object = struct {
188188
189189 fn genDecl(
190190 self: *Object,
191 mod: *Module,
191 zcu: *Zcu,
192192 decl_index: InternPool.DeclIndex,
193193 air: Air,
194194 liveness: Liveness,
195195 ) !void {
196 const decl = mod.declPtr(decl_index);
197 const namespace = mod.namespacePtr(decl.src_namespace);
198 const structured_cfg = namespace.file_scope.mod.structured_cfg;
196 const gpa = self.gpa;
197 const decl = zcu.declPtr(decl_index);
198 const namespace = zcu.namespacePtr(decl.src_namespace);
199 const structured_cfg = namespace.fileScope(zcu).mod.structured_cfg;
199200
200201 var decl_gen = DeclGen{
201 .gpa = self.gpa,
202 .gpa = gpa,
202203 .object = self,
203 .module = mod,
204 .module = zcu,
204205 .spv = &self.spv,
205206 .decl_index = decl_index,
206207 .air = air,
......@@ -212,19 +213,19 @@ pub const Object = struct {
212213 false => .{ .unstructured = .{} },
213214 },
214215 .current_block_label = undefined,
215 .base_line = decl.navSrcLine(mod),
216 .base_line = decl.navSrcLine(zcu),
216217 };
217218 defer decl_gen.deinit();
218219
219220 decl_gen.genDecl() catch |err| switch (err) {
220221 error.CodegenFail => {
221 try mod.failed_analysis.put(mod.gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }), decl_gen.error_msg.?);
222 try zcu.failed_analysis.put(gpa, InternPool.AnalUnit.wrap(.{ .decl = decl_index }), decl_gen.error_msg.?);
222223 },
223224 else => |other| {
224225 // There might be an error that happened *after* self.error_msg
225226 // was already allocated, so be sure to free it.
226227 if (decl_gen.error_msg) |error_msg| {
227 error_msg.deinit(mod.gpa);
228 error_msg.deinit(gpa);
228229 }
229230
230231 return other;
src/link/C.zig+8-4
......@@ -208,6 +208,8 @@ pub fn updateFunc(
208208 fwd_decl.clearRetainingCapacity();
209209 code.clearRetainingCapacity();
210210
211 const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu);
212
211213 var function: codegen.Function = .{
212214 .value_map = codegen.CValueMap.init(gpa),
213215 .air = air,
......@@ -217,7 +219,7 @@ pub fn updateFunc(
217219 .dg = .{
218220 .gpa = gpa,
219221 .zcu = zcu,
220 .mod = zcu.namespacePtr(decl.src_namespace).file_scope.mod,
222 .mod = file_scope.mod,
221223 .error_msg = null,
222224 .pass = .{ .decl = decl_index },
223225 .is_naked_fn = decl.typeOf(zcu).fnCallingConvention(zcu) == .Naked,
......@@ -335,11 +337,13 @@ pub fn updateDecl(self: *C, zcu: *Zcu, decl_index: InternPool.DeclIndex) !void {
335337 fwd_decl.clearRetainingCapacity();
336338 code.clearRetainingCapacity();
337339
340 const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu);
341
338342 var object: codegen.Object = .{
339343 .dg = .{
340344 .gpa = gpa,
341345 .zcu = zcu,
342 .mod = zcu.namespacePtr(decl.src_namespace).file_scope.mod,
346 .mod = file_scope.mod,
343347 .error_msg = null,
344348 .pass = .{ .decl = decl_index },
345349 .is_naked_fn = false,
......@@ -491,7 +495,7 @@ pub fn flushModule(self: *C, arena: Allocator, prog_node: std.Progress.Node) !vo
491495 for (self.decl_table.keys(), self.decl_table.values()) |decl_index, *decl_block| {
492496 const decl = zcu.declPtr(decl_index);
493497 const extern_name = if (decl.isExtern(zcu)) decl.name.toOptional() else .none;
494 const mod = zcu.namespacePtr(decl.src_namespace).file_scope.mod;
498 const mod = zcu.namespacePtr(decl.src_namespace).fileScope(zcu).mod;
495499 try self.flushDeclBlock(
496500 zcu,
497501 mod,
......@@ -848,7 +852,7 @@ pub fn updateExports(
848852 const gpa = self.base.comp.gpa;
849853 const mod, const pass: codegen.DeclGen.Pass, const decl_block, const exported_block = switch (exported) {
850854 .decl_index => |decl_index| .{
851 zcu.namespacePtr(zcu.declPtr(decl_index).src_namespace).file_scope.mod,
855 zcu.namespacePtr(zcu.declPtr(decl_index).src_namespace).fileScope(zcu).mod,
852856 .{ .decl = decl_index },
853857 self.decl_table.getPtr(decl_index).?,
854858 (try self.exported_decls.getOrPut(gpa, decl_index)).value_ptr,
src/link/Dwarf.zig+1-1
......@@ -1204,7 +1204,7 @@ pub fn commitDeclState(
12041204 const decl = zcu.declPtr(decl_index);
12051205 const ip = &zcu.intern_pool;
12061206 const namespace = zcu.namespacePtr(decl.src_namespace);
1207 const target = namespace.file_scope.mod.resolved_target.result;
1207 const target = namespace.fileScope(zcu).mod.resolved_target.result;
12081208 const target_endian = target.cpu.arch.endian();
12091209
12101210 var dbg_line_buffer = &decl_state.dbg_line;
src/link/Wasm/ZigObject.zig+11-11
......@@ -335,29 +335,29 @@ fn finishUpdateDecl(
335335 code: []const u8,
336336) !void {
337337 const gpa = wasm_file.base.comp.gpa;
338 const mod = wasm_file.base.comp.module.?;
339 const decl = mod.declPtr(decl_index);
338 const zcu = wasm_file.base.comp.module.?;
339 const decl = zcu.declPtr(decl_index);
340340 const decl_info = zig_object.decls_map.get(decl_index).?;
341341 const atom_index = decl_info.atom;
342342 const atom = wasm_file.getAtomPtr(atom_index);
343343 const sym = zig_object.symbol(atom.sym_index);
344 const full_name = try decl.fullyQualifiedName(mod);
345 sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&mod.intern_pool));
344 const full_name = try decl.fullyQualifiedName(zcu);
345 sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&zcu.intern_pool));
346346 try atom.code.appendSlice(gpa, code);
347347 atom.size = @intCast(code.len);
348348
349 switch (decl.typeOf(mod).zigTypeTag(mod)) {
349 switch (decl.typeOf(zcu).zigTypeTag(zcu)) {
350350 .Fn => {
351351 sym.index = try zig_object.appendFunction(gpa, .{ .type_index = zig_object.atom_types.get(atom_index).? });
352352 sym.tag = .function;
353353 },
354354 else => {
355 const segment_name: []const u8 = if (decl.getOwnedVariable(mod)) |variable| name: {
355 const segment_name: []const u8 = if (decl.getOwnedVariable(zcu)) |variable| name: {
356356 if (variable.is_const) {
357357 break :name ".rodata.";
358 } else if (Value.fromInterned(variable.init).isUndefDeep(mod)) {
359 const decl_namespace = mod.namespacePtr(decl.src_namespace);
360 const optimize_mode = decl_namespace.file_scope.mod.optimize_mode;
358 } else if (Value.fromInterned(variable.init).isUndefDeep(zcu)) {
359 const decl_namespace = zcu.namespacePtr(decl.src_namespace);
360 const optimize_mode = decl_namespace.fileScope(zcu).mod.optimize_mode;
361361 const is_initialized = switch (optimize_mode) {
362362 .Debug, .ReleaseSafe => true,
363363 .ReleaseFast, .ReleaseSmall => false,
......@@ -382,7 +382,7 @@ fn finishUpdateDecl(
382382 // Will be freed upon freeing of decl or after cleanup of Wasm binary.
383383 const full_segment_name = try std.mem.concat(gpa, u8, &.{
384384 segment_name,
385 full_name.toSlice(&mod.intern_pool),
385 full_name.toSlice(&zcu.intern_pool),
386386 });
387387 errdefer gpa.free(full_segment_name);
388388 sym.tag = .data;
......@@ -390,7 +390,7 @@ fn finishUpdateDecl(
390390 },
391391 }
392392 if (code.len == 0) return;
393 atom.alignment = decl.getAlignment(mod);
393 atom.alignment = decl.getAlignment(zcu);
394394}
395395
396396/// Creates and initializes a new segment in the 'Data' section.
src/main.zig+7-15
......@@ -27,8 +27,6 @@ const Cache = std.Build.Cache;
2727const target_util = @import("target.zig");
2828const crash_report = @import("crash_report.zig");
2929const Zcu = @import("Zcu.zig");
30/// Deprecated.
31const Module = Zcu;
3230const AstGen = std.zig.AstGen;
3331const mingw = @import("mingw.zig");
3432const Server = std.zig.Server;
......@@ -919,7 +917,7 @@ fn buildOutputType(
919917 var contains_res_file: bool = false;
920918 var reference_trace: ?u32 = null;
921919 var pdb_out_path: ?[]const u8 = null;
922 var error_limit: ?Module.ErrorInt = null;
920 var error_limit: ?Zcu.ErrorInt = null;
923921 // These are before resolving sysroot.
924922 var extra_cflags: std.ArrayListUnmanaged([]const u8) = .{};
925923 var extra_rcflags: std.ArrayListUnmanaged([]const u8) = .{};
......@@ -1107,7 +1105,7 @@ fn buildOutputType(
11071105 );
11081106 } else if (mem.eql(u8, arg, "--error-limit")) {
11091107 const next_arg = args_iter.nextOrFatal();
1110 error_limit = std.fmt.parseUnsigned(Module.ErrorInt, next_arg, 0) catch |err| {
1108 error_limit = std.fmt.parseUnsigned(Zcu.ErrorInt, next_arg, 0) catch |err| {
11111109 fatal("unable to parse error limit '{s}': {s}", .{ next_arg, @errorName(err) });
11121110 };
11131111 } else if (mem.eql(u8, arg, "-cflags")) {
......@@ -5956,7 +5954,7 @@ fn cmdAstCheck(
59565954 }
59575955 }
59585956
5959 var file: Module.File = .{
5957 var file: Zcu.File = .{
59605958 .status = .never_loaded,
59615959 .source_loaded = false,
59625960 .tree_loaded = false,
......@@ -5967,8 +5965,6 @@ fn cmdAstCheck(
59675965 .tree = undefined,
59685966 .zir = undefined,
59695967 .mod = undefined,
5970 .root_decl = .none,
5971 .path_digest = undefined,
59725968 };
59735969 if (zig_source_file) |file_name| {
59745970 var f = fs.cwd().openFile(file_name, .{}) catch |err| {
......@@ -6275,7 +6271,7 @@ fn cmdDumpZir(
62756271 };
62766272 defer f.close();
62776273
6278 var file: Module.File = .{
6274 var file: Zcu.File = .{
62796275 .status = .never_loaded,
62806276 .source_loaded = false,
62816277 .tree_loaded = false,
......@@ -6284,10 +6280,8 @@ fn cmdDumpZir(
62846280 .source = undefined,
62856281 .stat = undefined,
62866282 .tree = undefined,
6287 .zir = try Module.loadZirCache(gpa, f),
6283 .zir = try Zcu.loadZirCache(gpa, f),
62886284 .mod = undefined,
6289 .root_decl = .none,
6290 .path_digest = undefined,
62916285 };
62926286 defer file.zir.deinit(gpa);
62936287
......@@ -6342,7 +6336,7 @@ fn cmdChangelist(
63426336 if (stat.size > std.zig.max_src_size)
63436337 return error.FileTooBig;
63446338
6345 var file: Module.File = .{
6339 var file: Zcu.File = .{
63466340 .status = .never_loaded,
63476341 .source_loaded = false,
63486342 .tree_loaded = false,
......@@ -6357,8 +6351,6 @@ fn cmdChangelist(
63576351 .tree = undefined,
63586352 .zir = undefined,
63596353 .mod = undefined,
6360 .root_decl = .none,
6361 .path_digest = undefined,
63626354 };
63636355
63646356 file.mod = try Package.Module.createLimited(arena, .{
......@@ -6431,7 +6423,7 @@ fn cmdChangelist(
64316423 var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .{};
64326424 defer inst_map.deinit(gpa);
64336425
6434 try Module.mapOldZirToNew(gpa, old_zir, file.zir, &inst_map);
6426 try Zcu.mapOldZirToNew(gpa, old_zir, file.zir, &inst_map);
64356427
64366428 var bw = io.bufferedWriter(io.getStdOut().writer());
64376429 const stdout = bw.writer();