| author | |
| committer | |
| log | 30ec43a6c78d9c8803becbea5a02edb8fae08af6 |
| tree | fd827ce826b593a18c128d019eb9adffb3c2ca26 |
| parent | 7ed2fbd7559ceb69ab03a8985fd7e5b591e22ab7 |
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 | ... | @@ -116,7 +116,7 @@ win32_resource_work_queue: if (build_options.only_core_functionality) void else |
| 116 | /// These jobs are to tokenize, parse, and astgen files, which may be outdated | 116 | /// These jobs are to tokenize, parse, and astgen files, which may be outdated |
| 117 | /// since the last compilation, as well as scan for `@import` and queue up | 117 | /// since the last compilation, as well as scan for `@import` and queue up |
| 118 | /// additional jobs corresponding to those new files. | 118 | /// additional jobs corresponding to those new files. |
| 119 | astgen_work_queue: std.fifo.LinearFifo(*Module.File, .Dynamic), | 119 | astgen_work_queue: std.fifo.LinearFifo(Zcu.File.Index, .Dynamic), |
| 120 | /// These jobs are to inspect the file system stat() and if the embedded file has changed | 120 | /// These jobs are to inspect the file system stat() and if the embedded file has changed |
| 121 | /// on disk, mark the corresponding Decl outdated and queue up an `analyze_decl` | 121 | /// on disk, mark the corresponding Decl outdated and queue up an `analyze_decl` |
| 122 | /// task for it. | 122 | /// task for it. |
| ... | @@ -1433,7 +1433,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil | ... | @@ -1433,7 +1433,7 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil |
| 1433 | .work_queue = std.fifo.LinearFifo(Job, .Dynamic).init(gpa), | 1433 | .work_queue = std.fifo.LinearFifo(Job, .Dynamic).init(gpa), |
| 1434 | .c_object_work_queue = std.fifo.LinearFifo(*CObject, .Dynamic).init(gpa), | 1434 | .c_object_work_queue = std.fifo.LinearFifo(*CObject, .Dynamic).init(gpa), |
| 1435 | .win32_resource_work_queue = if (build_options.only_core_functionality) {} else std.fifo.LinearFifo(*Win32Resource, .Dynamic).init(gpa), | 1435 | .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), |
| 1437 | .embed_file_work_queue = std.fifo.LinearFifo(*Module.EmbedFile, .Dynamic).init(gpa), | 1437 | .embed_file_work_queue = std.fifo.LinearFifo(*Module.EmbedFile, .Dynamic).init(gpa), |
| 1438 | .c_source_files = options.c_source_files, | 1438 | .c_source_files = options.c_source_files, |
| 1439 | .rc_source_files = options.rc_source_files, | 1439 | .rc_source_files = options.rc_source_files, |
| ... | @@ -2095,13 +2095,13 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { | ... | @@ -2095,13 +2095,13 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { |
| 2095 | } | 2095 | } |
| 2096 | } | 2096 | } |
| 2097 | 2097 | ||
| 2098 | if (comp.module) |module| { | 2098 | if (comp.module) |zcu| { |
| 2099 | module.compile_log_text.shrinkAndFree(gpa, 0); | 2099 | zcu.compile_log_text.shrinkAndFree(gpa, 0); |
| 2100 | 2100 | ||
| 2101 | // Make sure std.zig is inside the import_table. We unconditionally need | 2101 | // Make sure std.zig is inside the import_table. We unconditionally need |
| 2102 | // it for start.zig. | 2102 | // it for start.zig. |
| 2103 | const std_mod = module.std_mod; | 2103 | const std_mod = zcu.std_mod; |
| 2104 | _ = try module.importPkg(std_mod); | 2104 | _ = try zcu.importPkg(std_mod); |
| 2105 | 2105 | ||
| 2106 | // Normally we rely on importing std to in turn import the root source file | 2106 | // Normally we rely on importing std to in turn import the root source file |
| 2107 | // in the start code, but when using the stage1 backend that won't happen, | 2107 | // 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 { | ... | @@ -2110,64 +2110,65 @@ pub fn update(comp: *Compilation, main_progress_node: std.Progress.Node) !void { |
| 2110 | // Likewise, in the case of `zig test`, the test runner is the root source file, | 2110 | // Likewise, in the case of `zig test`, the test runner is the root source file, |
| 2111 | // and so there is nothing to import the main file. | 2111 | // and so there is nothing to import the main file. |
| 2112 | if (comp.config.is_test) { | 2112 | if (comp.config.is_test) { |
| 2113 | _ = try module.importPkg(module.main_mod); | 2113 | _ = try zcu.importPkg(zcu.main_mod); |
| 2114 | } | 2114 | } |
| 2115 | 2115 | ||
| 2116 | if (module.root_mod.deps.get("compiler_rt")) |compiler_rt_mod| { | 2116 | if (zcu.root_mod.deps.get("compiler_rt")) |compiler_rt_mod| { |
| 2117 | _ = try module.importPkg(compiler_rt_mod); | 2117 | _ = try zcu.importPkg(compiler_rt_mod); |
| 2118 | } | 2118 | } |
| 2119 | 2119 | ||
| 2120 | // Put a work item in for every known source file to detect if | 2120 | // Put a work item in for every known source file to detect if |
| 2121 | // it changed, and, if so, re-compute ZIR and then queue the job | 2121 | // it changed, and, if so, re-compute ZIR and then queue the job |
| 2122 | // to update it. | 2122 | // to update it. |
| 2123 | try comp.astgen_work_queue.ensureUnusedCapacity(module.import_table.count()); | 2123 | try comp.astgen_work_queue.ensureUnusedCapacity(zcu.import_table.count()); |
| 2124 | for (module.import_table.values()) |file| { | 2124 | for (zcu.import_table.values(), 0..) |file, file_index_usize| { |
| 2125 | const file_index: Zcu.File.Index = @enumFromInt(file_index_usize); | ||
| 2125 | if (file.mod.isBuiltin()) continue; | 2126 | if (file.mod.isBuiltin()) continue; |
| 2126 | comp.astgen_work_queue.writeItemAssumeCapacity(file); | 2127 | comp.astgen_work_queue.writeItemAssumeCapacity(file_index); |
| 2127 | } | 2128 | } |
| 2128 | 2129 | ||
| 2129 | // Put a work item in for checking if any files used with `@embedFile` changed. | 2130 | // 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 | try comp.embed_file_work_queue.ensureUnusedCapacity(zcu.embed_table.count()); |
| 2131 | for (module.embed_table.values()) |embed_file| { | 2132 | for (zcu.embed_table.values()) |embed_file| { |
| 2132 | comp.embed_file_work_queue.writeItemAssumeCapacity(embed_file); | 2133 | comp.embed_file_work_queue.writeItemAssumeCapacity(embed_file); |
| 2133 | } | 2134 | } |
| 2134 | 2135 | ||
| 2135 | try comp.work_queue.writeItem(.{ .analyze_mod = std_mod }); | 2136 | try comp.work_queue.writeItem(.{ .analyze_mod = std_mod }); |
| 2136 | if (comp.config.is_test) { | 2137 | 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 }); |
| 2138 | } | 2139 | } |
| 2139 | 2140 | ||
| 2140 | if (module.root_mod.deps.get("compiler_rt")) |compiler_rt_mod| { | 2141 | if (zcu.root_mod.deps.get("compiler_rt")) |compiler_rt_mod| { |
| 2141 | try comp.work_queue.writeItem(.{ .analyze_mod = compiler_rt_mod }); | 2142 | try comp.work_queue.writeItem(.{ .analyze_mod = compiler_rt_mod }); |
| 2142 | } | 2143 | } |
| 2143 | } | 2144 | } |
| 2144 | 2145 | ||
| 2145 | try comp.performAllTheWork(main_progress_node); | 2146 | try comp.performAllTheWork(main_progress_node); |
| 2146 | 2147 | ||
| 2147 | if (comp.module) |module| { | 2148 | if (comp.module) |zcu| { |
| 2148 | if (build_options.enable_debug_extensions and comp.verbose_intern_pool) { | 2149 | if (build_options.enable_debug_extensions and comp.verbose_intern_pool) { |
| 2149 | std.debug.print("intern pool stats for '{s}':\n", .{ | 2150 | std.debug.print("intern pool stats for '{s}':\n", .{ |
| 2150 | comp.root_name, | 2151 | comp.root_name, |
| 2151 | }); | 2152 | }); |
| 2152 | module.intern_pool.dump(); | 2153 | zcu.intern_pool.dump(); |
| 2153 | } | 2154 | } |
| 2154 | 2155 | ||
| 2155 | if (build_options.enable_debug_extensions and comp.verbose_generic_instances) { | 2156 | if (build_options.enable_debug_extensions and comp.verbose_generic_instances) { |
| 2156 | std.debug.print("generic instances for '{s}:0x{x}':\n", .{ | 2157 | std.debug.print("generic instances for '{s}:0x{x}':\n", .{ |
| 2157 | comp.root_name, | 2158 | comp.root_name, |
| 2158 | @as(usize, @intFromPtr(module)), | 2159 | @as(usize, @intFromPtr(zcu)), |
| 2159 | }); | 2160 | }); |
| 2160 | module.intern_pool.dumpGenericInstances(gpa); | 2161 | zcu.intern_pool.dumpGenericInstances(gpa); |
| 2161 | } | 2162 | } |
| 2162 | 2163 | ||
| 2163 | if (comp.config.is_test and comp.totalErrorCount() == 0) { | 2164 | if (comp.config.is_test and comp.totalErrorCount() == 0) { |
| 2164 | // The `test_functions` decl has been intentionally postponed until now, | 2165 | // The `test_functions` decl has been intentionally postponed until now, |
| 2165 | // at which point we must populate it with the list of test functions that | 2166 | // at which point we must populate it with the list of test functions that |
| 2166 | // have been discovered and not filtered out. | 2167 | // have been discovered and not filtered out. |
| 2167 | try module.populateTestFunctions(main_progress_node); | 2168 | try zcu.populateTestFunctions(main_progress_node); |
| 2168 | } | 2169 | } |
| 2169 | 2170 | ||
| 2170 | try module.processExports(); | 2171 | try zcu.processExports(); |
| 2171 | } | 2172 | } |
| 2172 | 2173 | ||
| 2173 | if (comp.totalErrorCount() != 0) { | 2174 | if (comp.totalErrorCount() != 0) { |
| ... | @@ -2615,7 +2616,9 @@ fn resolveEmitLoc( | ... | @@ -2615,7 +2616,9 @@ fn resolveEmitLoc( |
| 2615 | return slice.ptr; | 2616 | return slice.ptr; |
| 2616 | } | 2617 | } |
| 2617 | 2618 | ||
| 2618 | fn reportMultiModuleErrors(mod: *Module) !void { | 2619 | fn reportMultiModuleErrors(zcu: *Zcu) !void { |
| 2620 | const gpa = zcu.gpa; | ||
| 2621 | const ip = &zcu.intern_pool; | ||
| 2619 | // Some cases can give you a whole bunch of multi-module errors, which it's not helpful to | 2622 | // Some cases can give you a whole bunch of multi-module errors, which it's not helpful to |
| 2620 | // print all of, so we'll cap the number of these to emit. | 2623 | // print all of, so we'll cap the number of these to emit. |
| 2621 | var num_errors: u32 = 0; | 2624 | var num_errors: u32 = 0; |
| ... | @@ -2623,37 +2626,39 @@ fn reportMultiModuleErrors(mod: *Module) !void { | ... | @@ -2623,37 +2626,39 @@ fn reportMultiModuleErrors(mod: *Module) !void { |
| 2623 | // Attach the "some omitted" note to the final error message | 2626 | // Attach the "some omitted" note to the final error message |
| 2624 | var last_err: ?*Module.ErrorMsg = null; | 2627 | var last_err: ?*Module.ErrorMsg = null; |
| 2625 | 2628 | ||
| 2626 | for (mod.import_table.values()) |file| { | 2629 | for (zcu.import_table.values(), 0..) |file, file_index_usize| { |
| 2627 | if (!file.multi_pkg) continue; | 2630 | if (!file.multi_pkg) continue; |
| 2628 | 2631 | ||
| 2629 | num_errors += 1; | 2632 | num_errors += 1; |
| 2630 | if (num_errors > max_errors) continue; | 2633 | if (num_errors > max_errors) continue; |
| 2631 | 2634 | ||
| 2635 | const file_index: Zcu.File.Index = @enumFromInt(file_index_usize); | ||
| 2636 | |||
| 2632 | const err = err_blk: { | 2637 | const err = err_blk: { |
| 2633 | // Like with errors, let's cap the number of notes to prevent a huge error spew. | 2638 | // Like with errors, let's cap the number of notes to prevent a huge error spew. |
| 2634 | const max_notes = 5; | 2639 | const max_notes = 5; |
| 2635 | const omitted = file.references.items.len -| max_notes; | 2640 | const omitted = file.references.items.len -| max_notes; |
| 2636 | const num_notes = file.references.items.len - omitted; | 2641 | const num_notes = file.references.items.len - omitted; |
| 2637 | 2642 | ||
| 2638 | const notes = try mod.gpa.alloc(Module.ErrorMsg, if (omitted > 0) num_notes + 1 else num_notes); | 2643 | const notes = try gpa.alloc(Module.ErrorMsg, if (omitted > 0) num_notes + 1 else num_notes); |
| 2639 | errdefer mod.gpa.free(notes); | 2644 | errdefer gpa.free(notes); |
| 2640 | 2645 | ||
| 2641 | for (notes[0..num_notes], file.references.items[0..num_notes], 0..) |*note, ref, i| { | 2646 | 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); |
| 2643 | note.* = switch (ref) { | 2648 | note.* = switch (ref) { |
| 2644 | .import => |import| try Module.ErrorMsg.init( | 2649 | .import => |import| try Module.ErrorMsg.init( |
| 2645 | mod.gpa, | 2650 | gpa, |
| 2646 | .{ | 2651 | .{ |
| 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), |
| 2648 | .offset = .{ .token_abs = import.token }, | 2653 | .offset = .{ .token_abs = import.token }, |
| 2649 | }, | 2654 | }, |
| 2650 | "imported from module {s}", | 2655 | "imported from module {s}", |
| 2651 | .{import.file.mod.fully_qualified_name}, | 2656 | .{zcu.fileByIndex(import.file).mod.fully_qualified_name}, |
| 2652 | ), | 2657 | ), |
| 2653 | .root => |pkg| try Module.ErrorMsg.init( | 2658 | .root => |pkg| try Module.ErrorMsg.init( |
| 2654 | mod.gpa, | 2659 | gpa, |
| 2655 | .{ | 2660 | .{ |
| 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), |
| 2657 | .offset = .entire_file, | 2662 | .offset = .entire_file, |
| 2658 | }, | 2663 | }, |
| 2659 | "root of module {s}", | 2664 | "root of module {s}", |
| ... | @@ -2661,25 +2666,25 @@ fn reportMultiModuleErrors(mod: *Module) !void { | ... | @@ -2661,25 +2666,25 @@ fn reportMultiModuleErrors(mod: *Module) !void { |
| 2661 | ), | 2666 | ), |
| 2662 | }; | 2667 | }; |
| 2663 | } | 2668 | } |
| 2664 | errdefer for (notes[0..num_notes]) |*n| n.deinit(mod.gpa); | 2669 | errdefer for (notes[0..num_notes]) |*n| n.deinit(gpa); |
| 2665 | 2670 | ||
| 2666 | if (omitted > 0) { | 2671 | if (omitted > 0) { |
| 2667 | notes[num_notes] = try Module.ErrorMsg.init( | 2672 | notes[num_notes] = try Module.ErrorMsg.init( |
| 2668 | mod.gpa, | 2673 | gpa, |
| 2669 | .{ | 2674 | .{ |
| 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), |
| 2671 | .offset = .entire_file, | 2676 | .offset = .entire_file, |
| 2672 | }, | 2677 | }, |
| 2673 | "{} more references omitted", | 2678 | "{} more references omitted", |
| 2674 | .{omitted}, | 2679 | .{omitted}, |
| 2675 | ); | 2680 | ); |
| 2676 | } | 2681 | } |
| 2677 | errdefer if (omitted > 0) notes[num_notes].deinit(mod.gpa); | 2682 | errdefer if (omitted > 0) notes[num_notes].deinit(gpa); |
| 2678 | 2683 | ||
| 2679 | const err = try Module.ErrorMsg.create( | 2684 | const err = try Module.ErrorMsg.create( |
| 2680 | mod.gpa, | 2685 | gpa, |
| 2681 | .{ | 2686 | .{ |
| 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), |
| 2683 | .offset = .entire_file, | 2688 | .offset = .entire_file, |
| 2684 | }, | 2689 | }, |
| 2685 | "file exists in multiple modules", | 2690 | "file exists in multiple modules", |
| ... | @@ -2688,8 +2693,8 @@ fn reportMultiModuleErrors(mod: *Module) !void { | ... | @@ -2688,8 +2693,8 @@ fn reportMultiModuleErrors(mod: *Module) !void { |
| 2688 | err.notes = notes; | 2693 | err.notes = notes; |
| 2689 | break :err_blk err; | 2694 | break :err_blk err; |
| 2690 | }; | 2695 | }; |
| 2691 | errdefer err.destroy(mod.gpa); | 2696 | errdefer err.destroy(gpa); |
| 2692 | try mod.failed_files.putNoClobber(mod.gpa, file, err); | 2697 | try zcu.failed_files.putNoClobber(gpa, file, err); |
| 2693 | last_err = err; | 2698 | last_err = err; |
| 2694 | } | 2699 | } |
| 2695 | 2700 | ||
| ... | @@ -2700,15 +2705,15 @@ fn reportMultiModuleErrors(mod: *Module) !void { | ... | @@ -2700,15 +2705,15 @@ fn reportMultiModuleErrors(mod: *Module) !void { |
| 2700 | // There isn't really any meaningful place to put this note, so just attach it to the | 2705 | // There isn't really any meaningful place to put this note, so just attach it to the |
| 2701 | // last failed file | 2706 | // last failed file |
| 2702 | var note = try Module.ErrorMsg.init( | 2707 | var note = try Module.ErrorMsg.init( |
| 2703 | mod.gpa, | 2708 | gpa, |
| 2704 | err.src_loc, | 2709 | err.src_loc, |
| 2705 | "{} more errors omitted", | 2710 | "{} more errors omitted", |
| 2706 | .{num_errors - max_errors}, | 2711 | .{num_errors - max_errors}, |
| 2707 | ); | 2712 | ); |
| 2708 | errdefer note.deinit(mod.gpa); | 2713 | errdefer note.deinit(gpa); |
| 2709 | 2714 | ||
| 2710 | const i = err.notes.len; | 2715 | 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); |
| 2712 | err.notes[i] = note; | 2717 | err.notes[i] = note; |
| 2713 | } | 2718 | } |
| 2714 | 2719 | ||
| ... | @@ -2719,8 +2724,8 @@ fn reportMultiModuleErrors(mod: *Module) !void { | ... | @@ -2719,8 +2724,8 @@ fn reportMultiModuleErrors(mod: *Module) !void { |
| 2719 | // to add this flag after reporting the errors however, as otherwise | 2724 | // to add this flag after reporting the errors however, as otherwise |
| 2720 | // we'd get an error for every single downstream file, which wouldn't be | 2725 | // we'd get an error for every single downstream file, which wouldn't be |
| 2721 | // very useful. | 2726 | // very useful. |
| 2722 | for (mod.import_table.values()) |file| { | 2727 | for (zcu.import_table.values()) |file| { |
| 2723 | if (file.multi_pkg) file.recursiveMarkMultiPkg(mod); | 2728 | if (file.multi_pkg) file.recursiveMarkMultiPkg(zcu); |
| 2724 | } | 2729 | } |
| 2725 | } | 2730 | } |
| 2726 | 2731 | ||
| ... | @@ -2752,6 +2757,7 @@ const Header = extern struct { | ... | @@ -2752,6 +2757,7 @@ const Header = extern struct { |
| 2752 | first_dependency_len: u32, | 2757 | first_dependency_len: u32, |
| 2753 | dep_entries_len: u32, | 2758 | dep_entries_len: u32, |
| 2754 | free_dep_entries_len: u32, | 2759 | free_dep_entries_len: u32, |
| 2760 | files_len: u32, | ||
| 2755 | }, | 2761 | }, |
| 2756 | }; | 2762 | }; |
| 2757 | 2763 | ||
| ... | @@ -2759,7 +2765,7 @@ const Header = extern struct { | ... | @@ -2759,7 +2765,7 @@ const Header = extern struct { |
| 2759 | /// saved, such as the target and most CLI flags. A cache hit will only occur | 2765 | /// saved, such as the target and most CLI flags. A cache hit will only occur |
| 2760 | /// when subsequent compiler invocations use the same set of flags. | 2766 | /// when subsequent compiler invocations use the same set of flags. |
| 2761 | pub fn saveState(comp: *Compilation) !void { | 2767 | pub 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; |
| 2763 | var bufs_len: usize = 0; | 2769 | var bufs_len: usize = 0; |
| 2764 | 2770 | ||
| 2765 | const lf = comp.bin_file orelse return; | 2771 | const lf = comp.bin_file orelse return; |
| ... | @@ -2780,6 +2786,7 @@ pub fn saveState(comp: *Compilation) !void { | ... | @@ -2780,6 +2786,7 @@ pub fn saveState(comp: *Compilation) !void { |
| 2780 | .first_dependency_len = @intCast(ip.first_dependency.count()), | 2786 | .first_dependency_len = @intCast(ip.first_dependency.count()), |
| 2781 | .dep_entries_len = @intCast(ip.dep_entries.items.len), | 2787 | .dep_entries_len = @intCast(ip.dep_entries.items.len), |
| 2782 | .free_dep_entries_len = @intCast(ip.free_dep_entries.items.len), | 2788 | .free_dep_entries_len = @intCast(ip.free_dep_entries.items.len), |
| 2789 | .files_len = @intCast(zcu.files.entries.len), | ||
| 2783 | }, | 2790 | }, |
| 2784 | }; | 2791 | }; |
| 2785 | addBuf(&bufs_list, &bufs_len, mem.asBytes(&header)); | 2792 | addBuf(&bufs_list, &bufs_len, mem.asBytes(&header)); |
| ... | @@ -2804,8 +2811,10 @@ pub fn saveState(comp: *Compilation) !void { | ... | @@ -2804,8 +2811,10 @@ pub fn saveState(comp: *Compilation) !void { |
| 2804 | addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.dep_entries.items)); | 2811 | addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.dep_entries.items)); |
| 2805 | addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.free_dep_entries.items)); | 2812 | addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(ip.free_dep_entries.items)); |
| 2806 | 2813 | ||
| 2814 | addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(zcu.files.keys())); | ||
| 2815 | addBuf(&bufs_list, &bufs_len, mem.sliceAsBytes(zcu.files.values())); | ||
| 2816 | |||
| 2807 | // TODO: compilation errors | 2817 | // TODO: compilation errors |
| 2808 | // TODO: files | ||
| 2809 | // TODO: namespaces | 2818 | // TODO: namespaces |
| 2810 | // TODO: decls | 2819 | // TODO: decls |
| 2811 | // TODO: linker state | 2820 | // TODO: linker state |
| ... | @@ -3353,16 +3362,31 @@ pub fn performAllTheWork( | ... | @@ -3353,16 +3362,31 @@ pub fn performAllTheWork( |
| 3353 | } | 3362 | } |
| 3354 | } | 3363 | } |
| 3355 | 3364 | ||
| 3356 | while (comp.astgen_work_queue.readItem()) |file| { | 3365 | if (comp.module) |zcu| { |
| 3357 | comp.thread_pool.spawnWg(&comp.astgen_wait_group, workerAstGenFile, .{ | 3366 | { |
| 3358 | comp, file, zir_prog_node, &comp.astgen_wait_group, .root, | 3367 | // Worker threads may append to zcu.files and zcu.import_table |
| 3359 | }); | 3368 | // so we must hold the lock while spawning those tasks, since |
| 3360 | } | 3369 | // we access those tables in this loop. |
| 3370 | comp.mutex.lock(); | ||
| 3371 | defer comp.mutex.unlock(); | ||
| 3361 | 3372 | ||
| 3362 | while (comp.embed_file_work_queue.readItem()) |embed_file| { | 3373 | while (comp.astgen_work_queue.readItem()) |file_index| { |
| 3363 | comp.thread_pool.spawnWg(&comp.astgen_wait_group, workerCheckEmbedFile, .{ | 3374 | // Pre-load these things from our single-threaded context since they |
| 3364 | comp, embed_file, | 3375 | // will be needed by the worker threads. |
| 3365 | }); | 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 | } | ||
| 3366 | } | 3390 | } |
| 3367 | 3391 | ||
| 3368 | while (comp.c_object_work_queue.readItem()) |c_object| { | 3392 | while (comp.c_object_work_queue.readItem()) |c_object| { |
| ... | @@ -3426,8 +3450,8 @@ pub fn performAllTheWork( | ... | @@ -3426,8 +3450,8 @@ pub fn performAllTheWork( |
| 3426 | fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !void { | 3450 | fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !void { |
| 3427 | switch (job) { | 3451 | switch (job) { |
| 3428 | .codegen_decl => |decl_index| { | 3452 | .codegen_decl => |decl_index| { |
| 3429 | const module = comp.module.?; | 3453 | const zcu = comp.module.?; |
| 3430 | const decl = module.declPtr(decl_index); | 3454 | const decl = zcu.declPtr(decl_index); |
| 3431 | 3455 | ||
| 3432 | switch (decl.analysis) { | 3456 | switch (decl.analysis) { |
| 3433 | .unreferenced => unreachable, | 3457 | .unreferenced => unreachable, |
| ... | @@ -3445,7 +3469,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo | ... | @@ -3445,7 +3469,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo |
| 3445 | 3469 | ||
| 3446 | assert(decl.has_tv); | 3470 | assert(decl.has_tv); |
| 3447 | 3471 | ||
| 3448 | try module.linkerUpdateDecl(decl_index); | 3472 | try zcu.linkerUpdateDecl(decl_index); |
| 3449 | return; | 3473 | return; |
| 3450 | }, | 3474 | }, |
| 3451 | } | 3475 | } |
| ... | @@ -3454,16 +3478,16 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo | ... | @@ -3454,16 +3478,16 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo |
| 3454 | const named_frame = tracy.namedFrame("codegen_func"); | 3478 | const named_frame = tracy.namedFrame("codegen_func"); |
| 3455 | defer named_frame.end(); | 3479 | defer named_frame.end(); |
| 3456 | 3480 | ||
| 3457 | const module = comp.module.?; | 3481 | const zcu = comp.module.?; |
| 3458 | // This call takes ownership of `func.air`. | 3482 | // This call takes ownership of `func.air`. |
| 3459 | try module.linkerUpdateFunc(func.func, func.air); | 3483 | try zcu.linkerUpdateFunc(func.func, func.air); |
| 3460 | }, | 3484 | }, |
| 3461 | .analyze_func => |func| { | 3485 | .analyze_func => |func| { |
| 3462 | const named_frame = tracy.namedFrame("analyze_func"); | 3486 | const named_frame = tracy.namedFrame("analyze_func"); |
| 3463 | defer named_frame.end(); | 3487 | defer named_frame.end(); |
| 3464 | 3488 | ||
| 3465 | const module = comp.module.?; | 3489 | const zcu = comp.module.?; |
| 3466 | module.ensureFuncBodyAnalyzed(func) catch |err| switch (err) { | 3490 | zcu.ensureFuncBodyAnalyzed(func) catch |err| switch (err) { |
| 3467 | error.OutOfMemory => return error.OutOfMemory, | 3491 | error.OutOfMemory => return error.OutOfMemory, |
| 3468 | error.AnalysisFail => return, | 3492 | error.AnalysisFail => return, |
| 3469 | }; | 3493 | }; |
| ... | @@ -3472,8 +3496,8 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo | ... | @@ -3472,8 +3496,8 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo |
| 3472 | if (true) @panic("regressed compiler feature: emit-h should hook into updateExports, " ++ | 3496 | if (true) @panic("regressed compiler feature: emit-h should hook into updateExports, " ++ |
| 3473 | "not decl analysis, which is too early to know about @export calls"); | 3497 | "not decl analysis, which is too early to know about @export calls"); |
| 3474 | 3498 | ||
| 3475 | const module = comp.module.?; | 3499 | const zcu = comp.module.?; |
| 3476 | const decl = module.declPtr(decl_index); | 3500 | const decl = zcu.declPtr(decl_index); |
| 3477 | 3501 | ||
| 3478 | switch (decl.analysis) { | 3502 | switch (decl.analysis) { |
| 3479 | .unreferenced => unreachable, | 3503 | .unreferenced => unreachable, |
| ... | @@ -3491,7 +3515,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo | ... | @@ -3491,7 +3515,7 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo |
| 3491 | defer named_frame.end(); | 3515 | defer named_frame.end(); |
| 3492 | 3516 | ||
| 3493 | const gpa = comp.gpa; | 3517 | const gpa = comp.gpa; |
| 3494 | const emit_h = module.emit_h.?; | 3518 | const emit_h = zcu.emit_h.?; |
| 3495 | _ = try emit_h.decl_table.getOrPut(gpa, decl_index); | 3519 | _ = try emit_h.decl_table.getOrPut(gpa, decl_index); |
| 3496 | const decl_emit_h = emit_h.declPtr(decl_index); | 3520 | const decl_emit_h = emit_h.declPtr(decl_index); |
| 3497 | const fwd_decl = &decl_emit_h.fwd_decl; | 3521 | const fwd_decl = &decl_emit_h.fwd_decl; |
| ... | @@ -3499,10 +3523,12 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo | ... | @@ -3499,10 +3523,12 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo |
| 3499 | var ctypes_arena = std.heap.ArenaAllocator.init(gpa); | 3523 | var ctypes_arena = std.heap.ArenaAllocator.init(gpa); |
| 3500 | defer ctypes_arena.deinit(); | 3524 | defer ctypes_arena.deinit(); |
| 3501 | 3525 | ||
| 3526 | const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu); | ||
| 3527 | |||
| 3502 | var dg: c_codegen.DeclGen = .{ | 3528 | var dg: c_codegen.DeclGen = .{ |
| 3503 | .gpa = gpa, | 3529 | .gpa = gpa, |
| 3504 | .zcu = module, | 3530 | .zcu = zcu, |
| 3505 | .mod = module.namespacePtr(decl.src_namespace).file_scope.mod, | 3531 | .mod = file_scope.mod, |
| 3506 | .error_msg = null, | 3532 | .error_msg = null, |
| 3507 | .pass = .{ .decl = decl_index }, | 3533 | .pass = .{ .decl = decl_index }, |
| 3508 | .is_naked_fn = false, | 3534 | .is_naked_fn = false, |
| ... | @@ -3531,17 +3557,17 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo | ... | @@ -3531,17 +3557,17 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo |
| 3531 | } | 3557 | } |
| 3532 | }, | 3558 | }, |
| 3533 | .analyze_decl => |decl_index| { | 3559 | .analyze_decl => |decl_index| { |
| 3534 | const module = comp.module.?; | 3560 | const zcu = comp.module.?; |
| 3535 | module.ensureDeclAnalyzed(decl_index) catch |err| switch (err) { | 3561 | zcu.ensureDeclAnalyzed(decl_index) catch |err| switch (err) { |
| 3536 | error.OutOfMemory => return error.OutOfMemory, | 3562 | error.OutOfMemory => return error.OutOfMemory, |
| 3537 | error.AnalysisFail => return, | 3563 | error.AnalysisFail => return, |
| 3538 | }; | 3564 | }; |
| 3539 | const decl = module.declPtr(decl_index); | 3565 | const decl = zcu.declPtr(decl_index); |
| 3540 | if (decl.kind == .@"test" and comp.config.is_test) { | 3566 | if (decl.kind == .@"test" and comp.config.is_test) { |
| 3541 | // Tests are always emitted in test binaries. The decl_refs are created by | 3567 | // 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 |
| 3543 | // that now. | 3569 | // that now. |
| 3544 | try module.ensureFuncBodyAnalysisQueued(decl.val.toIntern()); | 3570 | try zcu.ensureFuncBodyAnalysisQueued(decl.val.toIntern()); |
| 3545 | } | 3571 | } |
| 3546 | }, | 3572 | }, |
| 3547 | .resolve_type_fully => |ty| { | 3573 | .resolve_type_fully => |ty| { |
| ... | @@ -3559,30 +3585,30 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo | ... | @@ -3559,30 +3585,30 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: std.Progress.Node) !vo |
| 3559 | defer named_frame.end(); | 3585 | defer named_frame.end(); |
| 3560 | 3586 | ||
| 3561 | const gpa = comp.gpa; | 3587 | const gpa = comp.gpa; |
| 3562 | const module = comp.module.?; | 3588 | const zcu = comp.module.?; |
| 3563 | const decl = module.declPtr(decl_index); | 3589 | const decl = zcu.declPtr(decl_index); |
| 3564 | const lf = comp.bin_file.?; | 3590 | const lf = comp.bin_file.?; |
| 3565 | lf.updateDeclLineNumber(module, decl_index) catch |err| { | 3591 | lf.updateDeclLineNumber(zcu, decl_index) catch |err| { |
| 3566 | try module.failed_analysis.ensureUnusedCapacity(gpa, 1); | 3592 | try zcu.failed_analysis.ensureUnusedCapacity(gpa, 1); |
| 3567 | module.failed_analysis.putAssumeCapacityNoClobber( | 3593 | zcu.failed_analysis.putAssumeCapacityNoClobber( |
| 3568 | InternPool.AnalUnit.wrap(.{ .decl = decl_index }), | 3594 | InternPool.AnalUnit.wrap(.{ .decl = decl_index }), |
| 3569 | try Module.ErrorMsg.create( | 3595 | try Zcu.ErrorMsg.create( |
| 3570 | gpa, | 3596 | gpa, |
| 3571 | decl.navSrcLoc(module), | 3597 | decl.navSrcLoc(zcu), |
| 3572 | "unable to update line number: {s}", | 3598 | "unable to update line number: {s}", |
| 3573 | .{@errorName(err)}, | 3599 | .{@errorName(err)}, |
| 3574 | ), | 3600 | ), |
| 3575 | ); | 3601 | ); |
| 3576 | decl.analysis = .codegen_failure; | 3602 | 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 })); |
| 3578 | }; | 3604 | }; |
| 3579 | }, | 3605 | }, |
| 3580 | .analyze_mod => |pkg| { | 3606 | .analyze_mod => |pkg| { |
| 3581 | const named_frame = tracy.namedFrame("analyze_mod"); | 3607 | const named_frame = tracy.namedFrame("analyze_mod"); |
| 3582 | defer named_frame.end(); | 3608 | defer named_frame.end(); |
| 3583 | 3609 | ||
| 3584 | const module = comp.module.?; | 3610 | const zcu = comp.module.?; |
| 3585 | module.semaPkg(pkg) catch |err| switch (err) { | 3611 | zcu.semaPkg(pkg) catch |err| switch (err) { |
| 3586 | error.OutOfMemory => return error.OutOfMemory, | 3612 | error.OutOfMemory => return error.OutOfMemory, |
| 3587 | error.AnalysisFail => return, | 3613 | error.AnalysisFail => return, |
| 3588 | }; | 3614 | }; |
| ... | @@ -4015,14 +4041,17 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye | ... | @@ -4015,14 +4041,17 @@ fn workerDocsWasmFallible(comp: *Compilation, prog_node: std.Progress.Node) anye |
| 4015 | const AstGenSrc = union(enum) { | 4041 | const AstGenSrc = union(enum) { |
| 4016 | root, | 4042 | root, |
| 4017 | import: struct { | 4043 | import: struct { |
| 4018 | importing_file: *Module.File, | 4044 | importing_file: Zcu.File.Index, |
| 4019 | import_tok: std.zig.Ast.TokenIndex, | 4045 | import_tok: std.zig.Ast.TokenIndex, |
| 4020 | }, | 4046 | }, |
| 4021 | }; | 4047 | }; |
| 4022 | 4048 | ||
| 4023 | fn workerAstGenFile( | 4049 | fn workerAstGenFile( |
| 4024 | comp: *Compilation, | 4050 | 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, | ||
| 4026 | prog_node: std.Progress.Node, | 4055 | prog_node: std.Progress.Node, |
| 4027 | wg: *WaitGroup, | 4056 | wg: *WaitGroup, |
| 4028 | src: AstGenSrc, | 4057 | src: AstGenSrc, |
| ... | @@ -4030,12 +4059,12 @@ fn workerAstGenFile( | ... | @@ -4030,12 +4059,12 @@ fn workerAstGenFile( |
| 4030 | const child_prog_node = prog_node.start(file.sub_file_path, 0); | 4059 | const child_prog_node = prog_node.start(file.sub_file_path, 0); |
| 4031 | defer child_prog_node.end(); | 4060 | defer child_prog_node.end(); |
| 4032 | 4061 | ||
| 4033 | const mod = comp.module.?; | 4062 | const zcu = comp.module.?; |
| 4034 | mod.astGenFile(file) catch |err| switch (err) { | 4063 | zcu.astGenFile(file, path_digest, root_decl) catch |err| switch (err) { |
| 4035 | error.AnalysisFail => return, | 4064 | error.AnalysisFail => return, |
| 4036 | else => { | 4065 | else => { |
| 4037 | file.status = .retryable_failure; | 4066 | 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) { |
| 4039 | // Swallowing this error is OK because it's implied to be OOM when | 4068 | // Swallowing this error is OK because it's implied to be OOM when |
| 4040 | // there is a missing `failed_files` error message. | 4069 | // there is a missing `failed_files` error message. |
| 4041 | error.OutOfMemory => {}, | 4070 | error.OutOfMemory => {}, |
| ... | @@ -4062,29 +4091,31 @@ fn workerAstGenFile( | ... | @@ -4062,29 +4091,31 @@ fn workerAstGenFile( |
| 4062 | // `@import("builtin")` is handled specially. | 4091 | // `@import("builtin")` is handled specially. |
| 4063 | if (mem.eql(u8, import_path, "builtin")) continue; | 4092 | if (mem.eql(u8, import_path, "builtin")) continue; |
| 4064 | 4093 | ||
| 4065 | const import_result = blk: { | 4094 | const import_result, const imported_path_digest, const imported_root_decl = blk: { |
| 4066 | comp.mutex.lock(); | 4095 | comp.mutex.lock(); |
| 4067 | defer comp.mutex.unlock(); | 4096 | defer comp.mutex.unlock(); |
| 4068 | 4097 | ||
| 4069 | const res = mod.importFile(file, import_path) catch continue; | 4098 | const res = zcu.importFile(file, import_path) catch continue; |
| 4070 | if (!res.is_pkg) { | 4099 | if (!res.is_pkg) { |
| 4071 | res.file.addReference(mod.*, .{ .import = .{ | 4100 | res.file.addReference(zcu.*, .{ .import = .{ |
| 4072 | .file = file, | 4101 | .file = file_index, |
| 4073 | .token = item.data.token, | 4102 | .token = item.data.token, |
| 4074 | } }) catch continue; | 4103 | } }) catch continue; |
| 4075 | } | 4104 | } |
| 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 }; | ||
| 4077 | }; | 4108 | }; |
| 4078 | if (import_result.is_new) { | 4109 | if (import_result.is_new) { |
| 4079 | log.debug("AstGen of {s} has import '{s}'; queuing AstGen of {s}", .{ | 4110 | log.debug("AstGen of {s} has import '{s}'; queuing AstGen of {s}", .{ |
| 4080 | file.sub_file_path, import_path, import_result.file.sub_file_path, | 4111 | file.sub_file_path, import_path, import_result.file.sub_file_path, |
| 4081 | }); | 4112 | }); |
| 4082 | const sub_src: AstGenSrc = .{ .import = .{ | 4113 | const sub_src: AstGenSrc = .{ .import = .{ |
| 4083 | .importing_file = file, | 4114 | .importing_file = file_index, |
| 4084 | .import_tok = item.data.token, | 4115 | .import_tok = item.data.token, |
| 4085 | } }; | 4116 | } }; |
| 4086 | comp.thread_pool.spawnWg(wg, workerAstGenFile, .{ | 4117 | 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, |
| 4088 | }); | 4119 | }); |
| 4089 | } | 4120 | } |
| 4090 | } | 4121 | } |
| ... | @@ -4435,21 +4466,22 @@ fn reportRetryableWin32ResourceError( | ... | @@ -4435,21 +4466,22 @@ fn reportRetryableWin32ResourceError( |
| 4435 | fn reportRetryableAstGenError( | 4466 | fn reportRetryableAstGenError( |
| 4436 | comp: *Compilation, | 4467 | comp: *Compilation, |
| 4437 | src: AstGenSrc, | 4468 | src: AstGenSrc, |
| 4438 | file: *Module.File, | 4469 | file_index: Zcu.File.Index, |
| 4439 | err: anyerror, | 4470 | err: anyerror, |
| 4440 | ) error{OutOfMemory}!void { | 4471 | ) error{OutOfMemory}!void { |
| 4441 | const mod = comp.module.?; | 4472 | const zcu = comp.module.?; |
| 4442 | const gpa = mod.gpa; | 4473 | const gpa = zcu.gpa; |
| 4443 | 4474 | ||
| 4475 | const file = zcu.fileByIndex(file_index); | ||
| 4444 | file.status = .retryable_failure; | 4476 | file.status = .retryable_failure; |
| 4445 | 4477 | ||
| 4446 | const src_loc: Module.LazySrcLoc = switch (src) { | 4478 | const src_loc: Module.LazySrcLoc = switch (src) { |
| 4447 | .root => .{ | 4479 | .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), |
| 4449 | .offset = .entire_file, | 4481 | .offset = .entire_file, |
| 4450 | }, | 4482 | }, |
| 4451 | .import => |info| .{ | 4483 | .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), |
| 4453 | .offset = .{ .token_abs = info.import_tok }, | 4485 | .offset = .{ .token_abs = info.import_tok }, |
| 4454 | }, | 4486 | }, |
| 4455 | }; | 4487 | }; |
| ... | @@ -4462,7 +4494,7 @@ fn reportRetryableAstGenError( | ... | @@ -4462,7 +4494,7 @@ fn reportRetryableAstGenError( |
| 4462 | { | 4494 | { |
| 4463 | comp.mutex.lock(); | 4495 | comp.mutex.lock(); |
| 4464 | defer comp.mutex.unlock(); | 4496 | defer comp.mutex.unlock(); |
| 4465 | try mod.failed_files.putNoClobber(gpa, file, err_msg); | 4497 | try zcu.failed_files.putNoClobber(gpa, file, err_msg); |
| 4466 | } | 4498 | } |
| 4467 | } | 4499 | } |
| 4468 | 4500 |
src/InternPool.zig+7-2| ... | @@ -123,9 +123,14 @@ pub const TrackedInst = extern struct { | ... | @@ -123,9 +123,14 @@ pub const TrackedInst = extern struct { |
| 123 | }; | 123 | }; |
| 124 | }; | 124 | }; |
| 125 | 125 | ||
| 126 | pub fn trackZir(ip: *InternPool, gpa: Allocator, file: *Module.File, inst: Zir.Inst.Index) Allocator.Error!TrackedInst.Index { | 126 | pub fn trackZir( |
| 127 | ip: *InternPool, | ||
| 128 | gpa: Allocator, | ||
| 129 | path_digest: Cache.BinDigest, | ||
| 130 | inst: Zir.Inst.Index, | ||
| 131 | ) Allocator.Error!TrackedInst.Index { | ||
| 127 | const key: TrackedInst = .{ | 132 | const key: TrackedInst = .{ |
| 128 | .path_digest = file.path_digest, | 133 | .path_digest = path_digest, |
| 129 | .inst = inst, | 134 | .inst = inst, |
| 130 | }; | 135 | }; |
| 131 | const gop = try ip.tracked_insts.getOrPut(gpa, key); | 136 | 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 { | ... | @@ -379,7 +379,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { |
| 379 | 379 | ||
| 380 | const new_file = try arena.create(File); | 380 | const new_file = try arena.create(File); |
| 381 | 381 | ||
| 382 | const bin_digest, const hex_digest = digest: { | 382 | const hex_digest = digest: { |
| 383 | var hasher: Cache.Hasher = Cache.hasher_init; | 383 | var hasher: Cache.Hasher = Cache.hasher_init; |
| 384 | hasher.update(generated_builtin_source); | 384 | hasher.update(generated_builtin_source); |
| 385 | 385 | ||
| ... | @@ -393,7 +393,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { | ... | @@ -393,7 +393,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { |
| 393 | .{std.fmt.fmtSliceHexLower(&bin_digest)}, | 393 | .{std.fmt.fmtSliceHexLower(&bin_digest)}, |
| 394 | ) catch unreachable; | 394 | ) catch unreachable; |
| 395 | 395 | ||
| 396 | break :digest .{ bin_digest, hex_digest }; | 396 | break :digest hex_digest; |
| 397 | }; | 397 | }; |
| 398 | 398 | ||
| 399 | const builtin_sub_path = try arena.dupe(u8, "b" ++ std.fs.path.sep_str ++ hex_digest); | 399 | 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 { | ... | @@ -443,10 +443,6 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { |
| 443 | .zir = undefined, | 443 | .zir = undefined, |
| 444 | .status = .never_loaded, | 444 | .status = .never_loaded, |
| 445 | .mod = new, | 445 | .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, | ||
| 450 | }; | 446 | }; |
| 451 | break :b new; | 447 | break :b new; |
| 452 | }; | 448 | }; |
src/Sema.zig+119-101| ... | @@ -546,8 +546,12 @@ pub const Block = struct { | ... | @@ -546,8 +546,12 @@ pub const Block = struct { |
| 546 | }; | 546 | }; |
| 547 | } | 547 | } |
| 548 | 548 | ||
| 549 | pub fn getFileScope(block: *Block, mod: *Module) *Module.File { | 549 | pub fn getFileScope(block: *Block, zcu: *Zcu) *Zcu.File { |
| 550 | return mod.namespacePtr(block.namespace).file_scope; | 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; | ||
| 551 | } | 555 | } |
| 552 | 556 | ||
| 553 | fn addTy( | 557 | fn addTy( |
| ... | @@ -826,7 +830,17 @@ pub const Block = struct { | ... | @@ -826,7 +830,17 @@ pub const Block = struct { |
| 826 | 830 | ||
| 827 | pub fn ownerModule(block: Block) *Package.Module { | 831 | pub fn ownerModule(block: Block) *Package.Module { |
| 828 | const zcu = block.sema.mod; | 832 | 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); | ||
| 830 | } | 844 | } |
| 831 | }; | 845 | }; |
| 832 | 846 | ||
| ... | @@ -1000,7 +1014,7 @@ fn analyzeBodyInner( | ... | @@ -1000,7 +1014,7 @@ fn analyzeBodyInner( |
| 1000 | if (build_options.enable_logging) { | 1014 | if (build_options.enable_logging) { |
| 1001 | std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ sub_file_path: { | 1015 | std.log.scoped(.sema_zir).debug("sema ZIR {s} %{d}", .{ sub_file_path: { |
| 1002 | const path_digest = block.src_base_inst.resolveFull(&mod.intern_pool).path_digest; | 1016 | 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).?; |
| 1004 | break :sub_file_path mod.import_table.values()[index].sub_file_path; | 1018 | break :sub_file_path mod.import_table.values()[index].sub_file_path; |
| 1005 | }, inst }); | 1019 | }, inst }); |
| 1006 | } | 1020 | } |
| ... | @@ -2730,7 +2744,7 @@ fn zirStructDecl( | ... | @@ -2730,7 +2744,7 @@ fn zirStructDecl( |
| 2730 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 2744 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| 2731 | const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand); | 2745 | const extra = sema.code.extraData(Zir.Inst.StructDecl, extended.operand); |
| 2732 | 2746 | ||
| 2733 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); | 2747 | const tracked_inst = try block.trackZir(inst); |
| 2734 | const src: LazySrcLoc = .{ | 2748 | const src: LazySrcLoc = .{ |
| 2735 | .base_node_inst = tracked_inst, | 2749 | .base_node_inst = tracked_inst, |
| 2736 | .offset = LazySrcLoc.Offset.nodeOffset(0), | 2750 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| ... | @@ -2806,7 +2820,7 @@ fn zirStructDecl( | ... | @@ -2806,7 +2820,7 @@ fn zirStructDecl( |
| 2806 | try ip.addDependency( | 2820 | try ip.addDependency( |
| 2807 | sema.gpa, | 2821 | sema.gpa, |
| 2808 | AnalUnit.wrap(.{ .decl = new_decl_index }), | 2822 | 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) }, |
| 2810 | ); | 2824 | ); |
| 2811 | } | 2825 | } |
| 2812 | 2826 | ||
| ... | @@ -2814,7 +2828,7 @@ fn zirStructDecl( | ... | @@ -2814,7 +2828,7 @@ fn zirStructDecl( |
| 2814 | const new_namespace_index: InternPool.OptionalNamespaceIndex = if (true or decls_len > 0) (try mod.createNamespace(.{ | 2828 | const new_namespace_index: InternPool.OptionalNamespaceIndex = if (true or decls_len > 0) (try mod.createNamespace(.{ |
| 2815 | .parent = block.namespace.toOptional(), | 2829 | .parent = block.namespace.toOptional(), |
| 2816 | .decl_index = new_decl_index, | 2830 | .decl_index = new_decl_index, |
| 2817 | .file_scope = block.getFileScope(mod), | 2831 | .file_scope = block.getFileScopeIndex(mod), |
| 2818 | })).toOptional() else .none; | 2832 | })).toOptional() else .none; |
| 2819 | errdefer if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns); | 2833 | errdefer if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns); |
| 2820 | 2834 | ||
| ... | @@ -2947,7 +2961,7 @@ fn zirEnumDecl( | ... | @@ -2947,7 +2961,7 @@ fn zirEnumDecl( |
| 2947 | const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand); | 2961 | const extra = sema.code.extraData(Zir.Inst.EnumDecl, extended.operand); |
| 2948 | var extra_index: usize = extra.end; | 2962 | var extra_index: usize = extra.end; |
| 2949 | 2963 | ||
| 2950 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); | 2964 | const tracked_inst = try block.trackZir(inst); |
| 2951 | const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) }; | 2965 | const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) }; |
| 2952 | const tag_ty_src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = .{ .node_offset_container_tag = 0 } }; | 2966 | const tag_ty_src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = .{ .node_offset_container_tag = 0 } }; |
| 2953 | 2967 | ||
| ... | @@ -3040,9 +3054,9 @@ fn zirEnumDecl( | ... | @@ -3040,9 +3054,9 @@ fn zirEnumDecl( |
| 3040 | 3054 | ||
| 3041 | if (sema.mod.comp.debug_incremental) { | 3055 | if (sema.mod.comp.debug_incremental) { |
| 3042 | try mod.intern_pool.addDependency( | 3056 | try mod.intern_pool.addDependency( |
| 3043 | sema.gpa, | 3057 | gpa, |
| 3044 | AnalUnit.wrap(.{ .decl = new_decl_index }), | 3058 | 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) }, |
| 3046 | ); | 3060 | ); |
| 3047 | } | 3061 | } |
| 3048 | 3062 | ||
| ... | @@ -3050,7 +3064,7 @@ fn zirEnumDecl( | ... | @@ -3050,7 +3064,7 @@ fn zirEnumDecl( |
| 3050 | const new_namespace_index: InternPool.OptionalNamespaceIndex = if (true or decls_len > 0) (try mod.createNamespace(.{ | 3064 | const new_namespace_index: InternPool.OptionalNamespaceIndex = if (true or decls_len > 0) (try mod.createNamespace(.{ |
| 3051 | .parent = block.namespace.toOptional(), | 3065 | .parent = block.namespace.toOptional(), |
| 3052 | .decl_index = new_decl_index, | 3066 | .decl_index = new_decl_index, |
| 3053 | .file_scope = block.getFileScope(mod), | 3067 | .file_scope = block.getFileScopeIndex(mod), |
| 3054 | })).toOptional() else .none; | 3068 | })).toOptional() else .none; |
| 3055 | errdefer if (!done) if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns); | 3069 | errdefer if (!done) if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns); |
| 3056 | 3070 | ||
| ... | @@ -3232,7 +3246,7 @@ fn zirUnionDecl( | ... | @@ -3232,7 +3246,7 @@ fn zirUnionDecl( |
| 3232 | const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand); | 3246 | const extra = sema.code.extraData(Zir.Inst.UnionDecl, extended.operand); |
| 3233 | var extra_index: usize = extra.end; | 3247 | var extra_index: usize = extra.end; |
| 3234 | 3248 | ||
| 3235 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); | 3249 | const tracked_inst = try block.trackZir(inst); |
| 3236 | const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) }; | 3250 | const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) }; |
| 3237 | 3251 | ||
| 3238 | extra_index += @intFromBool(small.has_tag_type); | 3252 | extra_index += @intFromBool(small.has_tag_type); |
| ... | @@ -3306,9 +3320,9 @@ fn zirUnionDecl( | ... | @@ -3306,9 +3320,9 @@ fn zirUnionDecl( |
| 3306 | 3320 | ||
| 3307 | if (sema.mod.comp.debug_incremental) { | 3321 | if (sema.mod.comp.debug_incremental) { |
| 3308 | try mod.intern_pool.addDependency( | 3322 | try mod.intern_pool.addDependency( |
| 3309 | sema.gpa, | 3323 | gpa, |
| 3310 | AnalUnit.wrap(.{ .decl = new_decl_index }), | 3324 | 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) }, |
| 3312 | ); | 3326 | ); |
| 3313 | } | 3327 | } |
| 3314 | 3328 | ||
| ... | @@ -3316,7 +3330,7 @@ fn zirUnionDecl( | ... | @@ -3316,7 +3330,7 @@ fn zirUnionDecl( |
| 3316 | const new_namespace_index: InternPool.OptionalNamespaceIndex = if (true or decls_len > 0) (try mod.createNamespace(.{ | 3330 | const new_namespace_index: InternPool.OptionalNamespaceIndex = if (true or decls_len > 0) (try mod.createNamespace(.{ |
| 3317 | .parent = block.namespace.toOptional(), | 3331 | .parent = block.namespace.toOptional(), |
| 3318 | .decl_index = new_decl_index, | 3332 | .decl_index = new_decl_index, |
| 3319 | .file_scope = block.getFileScope(mod), | 3333 | .file_scope = block.getFileScopeIndex(mod), |
| 3320 | })).toOptional() else .none; | 3334 | })).toOptional() else .none; |
| 3321 | errdefer if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns); | 3335 | errdefer if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns); |
| 3322 | 3336 | ||
| ... | @@ -3348,7 +3362,7 @@ fn zirOpaqueDecl( | ... | @@ -3348,7 +3362,7 @@ fn zirOpaqueDecl( |
| 3348 | const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand); | 3362 | const extra = sema.code.extraData(Zir.Inst.OpaqueDecl, extended.operand); |
| 3349 | var extra_index: usize = extra.end; | 3363 | var extra_index: usize = extra.end; |
| 3350 | 3364 | ||
| 3351 | const tracked_inst = try ip.trackZir(gpa, block.getFileScope(mod), inst); | 3365 | const tracked_inst = try block.trackZir(inst); |
| 3352 | const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) }; | 3366 | const src: LazySrcLoc = .{ .base_node_inst = tracked_inst, .offset = LazySrcLoc.Offset.nodeOffset(0) }; |
| 3353 | 3367 | ||
| 3354 | const captures_len = if (small.has_captures_len) blk: { | 3368 | const captures_len = if (small.has_captures_len) blk: { |
| ... | @@ -3397,14 +3411,14 @@ fn zirOpaqueDecl( | ... | @@ -3397,14 +3411,14 @@ fn zirOpaqueDecl( |
| 3397 | try ip.addDependency( | 3411 | try ip.addDependency( |
| 3398 | gpa, | 3412 | gpa, |
| 3399 | AnalUnit.wrap(.{ .decl = new_decl_index }), | 3413 | AnalUnit.wrap(.{ .decl = new_decl_index }), |
| 3400 | .{ .src_hash = try ip.trackZir(gpa, block.getFileScope(mod), inst) }, | 3414 | .{ .src_hash = try block.trackZir(inst) }, |
| 3401 | ); | 3415 | ); |
| 3402 | } | 3416 | } |
| 3403 | 3417 | ||
| 3404 | const new_namespace_index: InternPool.OptionalNamespaceIndex = if (decls_len > 0) (try mod.createNamespace(.{ | 3418 | const new_namespace_index: InternPool.OptionalNamespaceIndex = if (decls_len > 0) (try mod.createNamespace(.{ |
| 3405 | .parent = block.namespace.toOptional(), | 3419 | .parent = block.namespace.toOptional(), |
| 3406 | .decl_index = new_decl_index, | 3420 | .decl_index = new_decl_index, |
| 3407 | .file_scope = block.getFileScope(mod), | 3421 | .file_scope = block.getFileScopeIndex(mod), |
| 3408 | })).toOptional() else .none; | 3422 | })).toOptional() else .none; |
| 3409 | errdefer if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns); | 3423 | errdefer if (new_namespace_index.unwrap()) |ns| mod.destroyNamespace(ns); |
| 3410 | 3424 | ||
| ... | @@ -5893,8 +5907,8 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5893,8 +5907,8 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5893 | const tracy = trace(@src()); | 5907 | const tracy = trace(@src()); |
| 5894 | defer tracy.end(); | 5908 | defer tracy.end(); |
| 5895 | 5909 | ||
| 5896 | const mod = sema.mod; | 5910 | const zcu = sema.mod; |
| 5897 | const comp = mod.comp; | 5911 | const comp = zcu.comp; |
| 5898 | const gpa = sema.gpa; | 5912 | const gpa = sema.gpa; |
| 5899 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; | 5913 | const pl_node = sema.code.instructions.items(.data)[@intFromEnum(inst)].pl_node; |
| 5900 | const src = parent_block.nodeOffset(pl_node.src_node); | 5914 | 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 | ... | @@ -5940,7 +5954,7 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5940 | if (!comp.config.link_libc) | 5954 | if (!comp.config.link_libc) |
| 5941 | try sema.errNote(src, msg, "libc headers not available; compilation does not link against libc", .{}); | 5955 | try sema.errNote(src, msg, "libc headers not available; compilation does not link against libc", .{}); |
| 5942 | 5956 | ||
| 5943 | const gop = try mod.cimport_errors.getOrPut(gpa, sema.ownerUnit()); | 5957 | const gop = try zcu.cimport_errors.getOrPut(gpa, sema.ownerUnit()); |
| 5944 | if (!gop.found_existing) { | 5958 | if (!gop.found_existing) { |
| 5945 | gop.value_ptr.* = c_import_res.errors; | 5959 | gop.value_ptr.* = c_import_res.errors; |
| 5946 | c_import_res.errors = std.zig.ErrorBundle.empty; | 5960 | c_import_res.errors = std.zig.ErrorBundle.empty; |
| ... | @@ -5984,14 +5998,16 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr | ... | @@ -5984,14 +5998,16 @@ fn zirCImport(sema: *Sema, parent_block: *Block, inst: Zir.Inst.Index) CompileEr |
| 5984 | else => |e| return e, | 5998 | else => |e| return e, |
| 5985 | }; | 5999 | }; |
| 5986 | 6000 | ||
| 5987 | const result = mod.importPkg(c_import_mod) catch |err| | 6001 | const result = zcu.importPkg(c_import_mod) catch |err| |
| 5988 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); | 6002 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); |
| 5989 | 6003 | ||
| 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| | ||
| 5991 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); | 6007 | return sema.fail(&child_block, src, "C import failed: {s}", .{@errorName(err)}); |
| 5992 | 6008 | ||
| 5993 | try mod.ensureFileAnalyzed(result.file); | 6009 | try zcu.ensureFileAnalyzed(result.file_index); |
| 5994 | const file_root_decl_index = result.file.root_decl.unwrap().?; | 6010 | const file_root_decl_index = zcu.fileRootDecl(result.file_index).unwrap().?; |
| 5995 | return sema.analyzeDeclVal(parent_block, src, file_root_decl_index); | 6011 | return sema.analyzeDeclVal(parent_block, src, file_root_decl_index); |
| 5996 | } | 6012 | } |
| 5997 | 6013 | ||
| ... | @@ -6730,7 +6746,9 @@ fn lookupInNamespace( | ... | @@ -6730,7 +6746,9 @@ fn lookupInNamespace( |
| 6730 | // Skip decls which are not marked pub, which are in a different | 6746 | // Skip decls which are not marked pub, which are in a different |
| 6731 | // file than the `a.b`/`@hasDecl` syntax. | 6747 | // file than the `a.b`/`@hasDecl` syntax. |
| 6732 | const decl = mod.declPtr(decl_index); | 6748 | 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 | { | ||
| 6734 | try candidates.append(gpa, decl_index); | 6752 | try candidates.append(gpa, decl_index); |
| 6735 | } | 6753 | } |
| 6736 | } | 6754 | } |
| ... | @@ -6741,7 +6759,7 @@ fn lookupInNamespace( | ... | @@ -6741,7 +6759,7 @@ fn lookupInNamespace( |
| 6741 | if (sub_usingnamespace_decl_index == sema.owner_decl_index) continue; | 6759 | if (sub_usingnamespace_decl_index == sema.owner_decl_index) continue; |
| 6742 | const sub_usingnamespace_decl = mod.declPtr(sub_usingnamespace_decl_index); | 6760 | const sub_usingnamespace_decl = mod.declPtr(sub_usingnamespace_decl_index); |
| 6743 | const sub_is_pub = entry.value_ptr.*; | 6761 | 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)) { |
| 6745 | // Skip usingnamespace decls which are not marked pub, which are in | 6763 | // Skip usingnamespace decls which are not marked pub, which are in |
| 6746 | // a different file than the `a.b`/`@hasDecl` syntax. | 6764 | // a different file than the `a.b`/`@hasDecl` syntax. |
| 6747 | continue; | 6765 | continue; |
| ... | @@ -6749,7 +6767,7 @@ fn lookupInNamespace( | ... | @@ -6749,7 +6767,7 @@ fn lookupInNamespace( |
| 6749 | try sema.ensureDeclAnalyzed(sub_usingnamespace_decl_index); | 6767 | try sema.ensureDeclAnalyzed(sub_usingnamespace_decl_index); |
| 6750 | const ns_ty = sub_usingnamespace_decl.val.toType(); | 6768 | const ns_ty = sub_usingnamespace_decl.val.toType(); |
| 6751 | const sub_ns = mod.namespacePtrUnwrap(ns_ty.getNamespaceIndex(mod)) orelse continue; | 6769 | 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)); |
| 6753 | } | 6771 | } |
| 6754 | } | 6772 | } |
| 6755 | 6773 | ||
| ... | @@ -8067,20 +8085,20 @@ fn instantiateGenericCall( | ... | @@ -8067,20 +8085,20 @@ fn instantiateGenericCall( |
| 8067 | call_tag: Air.Inst.Tag, | 8085 | call_tag: Air.Inst.Tag, |
| 8068 | call_dbg_node: ?Zir.Inst.Index, | 8086 | call_dbg_node: ?Zir.Inst.Index, |
| 8069 | ) CompileError!Air.Inst.Ref { | 8087 | ) CompileError!Air.Inst.Ref { |
| 8070 | const mod = sema.mod; | 8088 | const zcu = sema.mod; |
| 8071 | const gpa = sema.gpa; | 8089 | const gpa = sema.gpa; |
| 8072 | const ip = &mod.intern_pool; | 8090 | const ip = &zcu.intern_pool; |
| 8073 | 8091 | ||
| 8074 | const func_val = try sema.resolveConstDefinedValue(block, func_src, func, .{ | 8092 | const func_val = try sema.resolveConstDefinedValue(block, func_src, func, .{ |
| 8075 | .needed_comptime_reason = "generic function being called must be comptime-known", | 8093 | .needed_comptime_reason = "generic function being called must be comptime-known", |
| 8076 | }); | 8094 | }); |
| 8077 | const generic_owner = switch (mod.intern_pool.indexToKey(func_val.toIntern())) { | 8095 | const generic_owner = switch (zcu.intern_pool.indexToKey(func_val.toIntern())) { |
| 8078 | .func => func_val.toIntern(), | 8096 | .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(), |
| 8080 | else => unreachable, | 8098 | else => unreachable, |
| 8081 | }; | 8099 | }; |
| 8082 | const generic_owner_func = mod.intern_pool.indexToKey(generic_owner).func; | 8100 | const generic_owner_func = zcu.intern_pool.indexToKey(generic_owner).func; |
| 8083 | const generic_owner_ty_info = mod.typeToFunc(Type.fromInterned(generic_owner_func.ty)).?; | 8101 | const generic_owner_ty_info = zcu.typeToFunc(Type.fromInterned(generic_owner_func.ty)).?; |
| 8084 | 8102 | ||
| 8085 | try sema.declareDependency(.{ .src_hash = generic_owner_func.zir_body_inst }); | 8103 | try sema.declareDependency(.{ .src_hash = generic_owner_func.zir_body_inst }); |
| 8086 | 8104 | ||
| ... | @@ -8092,10 +8110,10 @@ fn instantiateGenericCall( | ... | @@ -8092,10 +8110,10 @@ fn instantiateGenericCall( |
| 8092 | // The actual monomorphization happens via adding `func_instance` to | 8110 | // The actual monomorphization happens via adding `func_instance` to |
| 8093 | // `InternPool`. | 8111 | // `InternPool`. |
| 8094 | 8112 | ||
| 8095 | const fn_owner_decl = mod.declPtr(generic_owner_func.owner_decl); | 8113 | const fn_owner_decl = zcu.declPtr(generic_owner_func.owner_decl); |
| 8096 | const namespace_index = fn_owner_decl.src_namespace; | 8114 | const namespace_index = fn_owner_decl.src_namespace; |
| 8097 | const namespace = mod.namespacePtr(namespace_index); | 8115 | const namespace = zcu.namespacePtr(namespace_index); |
| 8098 | const fn_zir = namespace.file_scope.zir; | 8116 | const fn_zir = namespace.fileScope(zcu).zir; |
| 8099 | const fn_info = fn_zir.getFnInfo(generic_owner_func.zir_body_inst.resolve(ip)); | 8117 | const fn_info = fn_zir.getFnInfo(generic_owner_func.zir_body_inst.resolve(ip)); |
| 8100 | 8118 | ||
| 8101 | const comptime_args = try sema.arena.alloc(InternPool.Index, args_info.count()); | 8119 | const comptime_args = try sema.arena.alloc(InternPool.Index, args_info.count()); |
| ... | @@ -8110,7 +8128,7 @@ fn instantiateGenericCall( | ... | @@ -8110,7 +8128,7 @@ fn instantiateGenericCall( |
| 8110 | // `param_anytype_comptime` ZIR instructions to be ignored, resulting in a | 8128 | // `param_anytype_comptime` ZIR instructions to be ignored, resulting in a |
| 8111 | // new, monomorphized function, with the comptime parameters elided. | 8129 | // new, monomorphized function, with the comptime parameters elided. |
| 8112 | var child_sema: Sema = .{ | 8130 | var child_sema: Sema = .{ |
| 8113 | .mod = mod, | 8131 | .mod = zcu, |
| 8114 | .gpa = gpa, | 8132 | .gpa = gpa, |
| 8115 | .arena = sema.arena, | 8133 | .arena = sema.arena, |
| 8116 | .code = fn_zir, | 8134 | .code = fn_zir, |
| ... | @@ -8199,7 +8217,7 @@ fn instantiateGenericCall( | ... | @@ -8199,7 +8217,7 @@ fn instantiateGenericCall( |
| 8199 | const arg_ref = try args_info.analyzeArg(sema, block, arg_index, param_ty, generic_owner_ty_info, func); | 8217 | const arg_ref = try args_info.analyzeArg(sema, block, arg_index, param_ty, generic_owner_ty_info, func); |
| 8200 | try sema.validateRuntimeValue(block, args_info.argSrc(block, arg_index), arg_ref); | 8218 | try sema.validateRuntimeValue(block, args_info.argSrc(block, arg_index), arg_ref); |
| 8201 | const arg_ty = sema.typeOf(arg_ref); | 8219 | const arg_ty = sema.typeOf(arg_ref); |
| 8202 | if (arg_ty.zigTypeTag(mod) == .NoReturn) { | 8220 | if (arg_ty.zigTypeTag(zcu) == .NoReturn) { |
| 8203 | // This terminates argument analysis. | 8221 | // This terminates argument analysis. |
| 8204 | return arg_ref; | 8222 | return arg_ref; |
| 8205 | } | 8223 | } |
| ... | @@ -8283,12 +8301,12 @@ fn instantiateGenericCall( | ... | @@ -8283,12 +8301,12 @@ fn instantiateGenericCall( |
| 8283 | const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst); | 8301 | const new_func_inst = try child_sema.resolveInlineBody(&child_block, fn_info.param_body[args_info.count()..], fn_info.param_body_inst); |
| 8284 | const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern(); | 8302 | const callee_index = (child_sema.resolveConstDefinedValue(&child_block, LazySrcLoc.unneeded, new_func_inst, undefined) catch unreachable).toIntern(); |
| 8285 | 8303 | ||
| 8286 | const callee = mod.funcInfo(callee_index); | 8304 | const callee = zcu.funcInfo(callee_index); |
| 8287 | callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota); | 8305 | callee.branchQuota(ip).* = @max(callee.branchQuota(ip).*, sema.branch_quota); |
| 8288 | 8306 | ||
| 8289 | // Make a runtime call to the new function, making sure to omit the comptime args. | 8307 | // Make a runtime call to the new function, making sure to omit the comptime args. |
| 8290 | const func_ty = Type.fromInterned(callee.ty); | 8308 | 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).?; |
| 8292 | 8310 | ||
| 8293 | // If the call evaluated to a return type that requires comptime, never mind | 8311 | // If the call evaluated to a return type that requires comptime, never mind |
| 8294 | // our generic instantiation. Instead we need to perform a comptime call. | 8312 | // our generic instantiation. Instead we need to perform a comptime call. |
| ... | @@ -8304,13 +8322,13 @@ fn instantiateGenericCall( | ... | @@ -8304,13 +8322,13 @@ fn instantiateGenericCall( |
| 8304 | if (call_dbg_node) |some| try sema.zirDbgStmt(block, some); | 8322 | if (call_dbg_node) |some| try sema.zirDbgStmt(block, some); |
| 8305 | 8323 | ||
| 8306 | if (sema.owner_func_index != .none and | 8324 | 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)) |
| 8308 | { | 8326 | { |
| 8309 | ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true; | 8327 | ip.funcAnalysis(sema.owner_func_index).calls_or_awaits_errorable_fn = true; |
| 8310 | } | 8328 | } |
| 8311 | 8329 | ||
| 8312 | try sema.addReferenceEntry(call_src, AnalUnit.wrap(.{ .func = callee_index })); | 8330 | try sema.addReferenceEntry(call_src, AnalUnit.wrap(.{ .func = callee_index })); |
| 8313 | try mod.ensureFuncBodyAnalysisQueued(callee_index); | 8331 | try zcu.ensureFuncBodyAnalysisQueued(callee_index); |
| 8314 | 8332 | ||
| 8315 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Call).Struct.fields.len + runtime_args.items.len); | 8333 | try sema.air_extra.ensureUnusedCapacity(sema.gpa, @typeInfo(Air.Call).Struct.fields.len + runtime_args.items.len); |
| 8316 | const result = try block.addInst(.{ | 8334 | const result = try block.addInst(.{ |
| ... | @@ -8333,7 +8351,7 @@ fn instantiateGenericCall( | ... | @@ -8333,7 +8351,7 @@ fn instantiateGenericCall( |
| 8333 | if (call_tag == .call_always_tail) { | 8351 | if (call_tag == .call_always_tail) { |
| 8334 | return sema.handleTailCall(block, call_src, func_ty, result); | 8352 | return sema.handleTailCall(block, call_src, func_ty, result); |
| 8335 | } | 8353 | } |
| 8336 | if (func_ty.fnReturnType(mod).isNoReturn(mod)) { | 8354 | if (func_ty.fnReturnType(zcu).isNoReturn(zcu)) { |
| 8337 | _ = try block.addNoOp(.unreach); | 8355 | _ = try block.addNoOp(.unreach); |
| 8338 | return .unreachable_value; | 8356 | return .unreachable_value; |
| 8339 | } | 8357 | } |
| ... | @@ -9653,7 +9671,7 @@ fn funcCommon( | ... | @@ -9653,7 +9671,7 @@ fn funcCommon( |
| 9653 | .is_generic = final_is_generic, | 9671 | .is_generic = final_is_generic, |
| 9654 | .is_noinline = is_noinline, | 9672 | .is_noinline = is_noinline, |
| 9655 | 9673 | ||
| 9656 | .zir_body_inst = try ip.trackZir(gpa, block.getFileScope(mod), func_inst), | 9674 | .zir_body_inst = try block.trackZir(func_inst), |
| 9657 | .lbrace_line = src_locs.lbrace_line, | 9675 | .lbrace_line = src_locs.lbrace_line, |
| 9658 | .rbrace_line = src_locs.rbrace_line, | 9676 | .rbrace_line = src_locs.rbrace_line, |
| 9659 | .lbrace_column = @as(u16, @truncate(src_locs.columns)), | 9677 | .lbrace_column = @as(u16, @truncate(src_locs.columns)), |
| ... | @@ -9731,7 +9749,7 @@ fn funcCommon( | ... | @@ -9731,7 +9749,7 @@ fn funcCommon( |
| 9731 | .ty = func_ty, | 9749 | .ty = func_ty, |
| 9732 | .cc = cc, | 9750 | .cc = cc, |
| 9733 | .is_noinline = is_noinline, | 9751 | .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), |
| 9735 | .lbrace_line = src_locs.lbrace_line, | 9753 | .lbrace_line = src_locs.lbrace_line, |
| 9736 | .rbrace_line = src_locs.rbrace_line, | 9754 | .rbrace_line = src_locs.rbrace_line, |
| 9737 | .lbrace_column = @as(u16, @truncate(src_locs.columns)), | 9755 | .lbrace_column = @as(u16, @truncate(src_locs.columns)), |
| ... | @@ -13787,18 +13805,18 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13787,18 +13805,18 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13787 | const tracy = trace(@src()); | 13805 | const tracy = trace(@src()); |
| 13788 | defer tracy.end(); | 13806 | defer tracy.end(); |
| 13789 | 13807 | ||
| 13790 | const mod = sema.mod; | 13808 | const zcu = sema.mod; |
| 13791 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; | 13809 | const inst_data = sema.code.instructions.items(.data)[@intFromEnum(inst)].str_tok; |
| 13792 | const operand_src = block.tokenOffset(inst_data.src_tok); | 13810 | const operand_src = block.tokenOffset(inst_data.src_tok); |
| 13793 | const operand = inst_data.get(sema.code); | 13811 | const operand = inst_data.get(sema.code); |
| 13794 | 13812 | ||
| 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) { |
| 13796 | error.ImportOutsideModulePath => { | 13814 | error.ImportOutsideModulePath => { |
| 13797 | return sema.fail(block, operand_src, "import of file outside module path: '{s}'", .{operand}); | 13815 | return sema.fail(block, operand_src, "import of file outside module path: '{s}'", .{operand}); |
| 13798 | }, | 13816 | }, |
| 13799 | error.ModuleNotFound => { | 13817 | error.ModuleNotFound => { |
| 13800 | return sema.fail(block, operand_src, "no module named '{s}' available within module {s}", .{ | 13818 | 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, |
| 13802 | }); | 13820 | }); |
| 13803 | }, | 13821 | }, |
| 13804 | else => { | 13822 | else => { |
| ... | @@ -13807,8 +13825,8 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. | ... | @@ -13807,8 +13825,8 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. |
| 13807 | return sema.fail(block, operand_src, "unable to open '{s}': {s}", .{ operand, @errorName(err) }); | 13825 | return sema.fail(block, operand_src, "unable to open '{s}': {s}", .{ operand, @errorName(err) }); |
| 13808 | }, | 13826 | }, |
| 13809 | }; | 13827 | }; |
| 13810 | try mod.ensureFileAnalyzed(result.file); | 13828 | try zcu.ensureFileAnalyzed(result.file_index); |
| 13811 | const file_root_decl_index = result.file.root_decl.unwrap().?; | 13829 | const file_root_decl_index = zcu.fileRootDecl(result.file_index).unwrap().?; |
| 13812 | return sema.analyzeDeclVal(block, operand_src, file_root_decl_index); | 13830 | return sema.analyzeDeclVal(block, operand_src, file_root_decl_index); |
| 13813 | } | 13831 | } |
| 13814 | 13832 | ||
| ... | @@ -21089,7 +21107,7 @@ fn zirReify( | ... | @@ -21089,7 +21107,7 @@ fn zirReify( |
| 21089 | const ip = &mod.intern_pool; | 21107 | const ip = &mod.intern_pool; |
| 21090 | const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small); | 21108 | const name_strategy: Zir.Inst.NameStrategy = @enumFromInt(extended.small); |
| 21091 | const extra = sema.code.extraData(Zir.Inst.Reify, extended.operand).data; | 21109 | 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); |
| 21093 | const src: LazySrcLoc = .{ | 21111 | const src: LazySrcLoc = .{ |
| 21094 | .base_node_inst = tracked_inst, | 21112 | .base_node_inst = tracked_inst, |
| 21095 | .offset = LazySrcLoc.Offset.nodeOffset(0), | 21113 | .offset = LazySrcLoc.Offset.nodeOffset(0), |
| ... | @@ -21466,7 +21484,7 @@ fn zirReify( | ... | @@ -21466,7 +21484,7 @@ fn zirReify( |
| 21466 | const wip_ty = switch (try ip.getOpaqueType(gpa, .{ | 21484 | const wip_ty = switch (try ip.getOpaqueType(gpa, .{ |
| 21467 | .has_namespace = false, | 21485 | .has_namespace = false, |
| 21468 | .key = .{ .reified = .{ | 21486 | .key = .{ .reified = .{ |
| 21469 | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), | 21487 | .zir_index = try block.trackZir(inst), |
| 21470 | } }, | 21488 | } }, |
| 21471 | })) { | 21489 | })) { |
| 21472 | .existing => |ty| return Air.internedToRef(ty), | 21490 | .existing => |ty| return Air.internedToRef(ty), |
| ... | @@ -21660,7 +21678,7 @@ fn reifyEnum( | ... | @@ -21660,7 +21678,7 @@ fn reifyEnum( |
| 21660 | .tag_mode = if (is_exhaustive) .explicit else .nonexhaustive, | 21678 | .tag_mode = if (is_exhaustive) .explicit else .nonexhaustive, |
| 21661 | .fields_len = fields_len, | 21679 | .fields_len = fields_len, |
| 21662 | .key = .{ .reified = .{ | 21680 | .key = .{ .reified = .{ |
| 21663 | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), | 21681 | .zir_index = try block.trackZir(inst), |
| 21664 | .type_hash = hasher.final(), | 21682 | .type_hash = hasher.final(), |
| 21665 | } }, | 21683 | } }, |
| 21666 | })) { | 21684 | })) { |
| ... | @@ -21810,7 +21828,7 @@ fn reifyUnion( | ... | @@ -21810,7 +21828,7 @@ fn reifyUnion( |
| 21810 | .field_types = &.{}, // set later | 21828 | .field_types = &.{}, // set later |
| 21811 | .field_aligns = &.{}, // set later | 21829 | .field_aligns = &.{}, // set later |
| 21812 | .key = .{ .reified = .{ | 21830 | .key = .{ .reified = .{ |
| 21813 | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), | 21831 | .zir_index = try block.trackZir(inst), |
| 21814 | .type_hash = hasher.final(), | 21832 | .type_hash = hasher.final(), |
| 21815 | } }, | 21833 | } }, |
| 21816 | })) { | 21834 | })) { |
| ... | @@ -22062,7 +22080,7 @@ fn reifyStruct( | ... | @@ -22062,7 +22080,7 @@ fn reifyStruct( |
| 22062 | .inits_resolved = true, | 22080 | .inits_resolved = true, |
| 22063 | .has_namespace = false, | 22081 | .has_namespace = false, |
| 22064 | .key = .{ .reified = .{ | 22082 | .key = .{ .reified = .{ |
| 22065 | .zir_index = try ip.trackZir(gpa, block.getFileScope(mod), inst), | 22083 | .zir_index = try block.trackZir(inst), |
| 22066 | .type_hash = hasher.final(), | 22084 | .type_hash = hasher.final(), |
| 22067 | } }, | 22085 | } }, |
| 22068 | })) { | 22086 | })) { |
| ... | @@ -34894,14 +34912,14 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void { | ... | @@ -34894,14 +34912,14 @@ pub fn resolveStructLayout(sema: *Sema, ty: Type) SemaError!void { |
| 34894 | _ = try sema.typeRequiresComptime(ty); | 34912 | _ = try sema.typeRequiresComptime(ty); |
| 34895 | } | 34913 | } |
| 34896 | 34914 | ||
| 34897 | fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) CompileError!void { | 34915 | fn semaBackingIntType(zcu: *Zcu, struct_type: InternPool.LoadedStructType) CompileError!void { |
| 34898 | const gpa = mod.gpa; | 34916 | const gpa = zcu.gpa; |
| 34899 | const ip = &mod.intern_pool; | 34917 | const ip = &zcu.intern_pool; |
| 34900 | 34918 | ||
| 34901 | const decl_index = struct_type.decl.unwrap().?; | 34919 | const decl_index = struct_type.decl.unwrap().?; |
| 34902 | const decl = mod.declPtr(decl_index); | 34920 | const decl = zcu.declPtr(decl_index); |
| 34903 | 34921 | ||
| 34904 | const zir = mod.namespacePtr(struct_type.namespace.unwrap().?).file_scope.zir; | 34922 | const zir = zcu.namespacePtr(struct_type.namespace.unwrap().?).fileScope(zcu).zir; |
| 34905 | 34923 | ||
| 34906 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); | 34924 | var analysis_arena = std.heap.ArenaAllocator.init(gpa); |
| 34907 | defer analysis_arena.deinit(); | 34925 | defer analysis_arena.deinit(); |
| ... | @@ -34910,7 +34928,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co | ... | @@ -34910,7 +34928,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 34910 | defer comptime_err_ret_trace.deinit(); | 34928 | defer comptime_err_ret_trace.deinit(); |
| 34911 | 34929 | ||
| 34912 | var sema: Sema = .{ | 34930 | var sema: Sema = .{ |
| 34913 | .mod = mod, | 34931 | .mod = zcu, |
| 34914 | .gpa = gpa, | 34932 | .gpa = gpa, |
| 34915 | .arena = analysis_arena.allocator(), | 34933 | .arena = analysis_arena.allocator(), |
| 34916 | .code = zir, | 34934 | .code = zir, |
| ... | @@ -34941,7 +34959,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co | ... | @@ -34941,7 +34959,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 34941 | var accumulator: u64 = 0; | 34959 | var accumulator: u64 = 0; |
| 34942 | for (0..struct_type.field_types.len) |i| { | 34960 | for (0..struct_type.field_types.len) |i| { |
| 34943 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[i]); | 34961 | 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); |
| 34945 | } | 34963 | } |
| 34946 | break :blk accumulator; | 34964 | break :blk accumulator; |
| 34947 | }; | 34965 | }; |
| ... | @@ -34987,7 +35005,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co | ... | @@ -34987,7 +35005,7 @@ fn semaBackingIntType(mod: *Module, struct_type: InternPool.LoadedStructType) Co |
| 34987 | if (fields_bit_sum > std.math.maxInt(u16)) { | 35005 | if (fields_bit_sum > std.math.maxInt(u16)) { |
| 34988 | return sema.fail(&block, block.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum}); | 35006 | return sema.fail(&block, block.nodeOffset(0), "size of packed struct '{d}' exceeds maximum bit width of 65535", .{fields_bit_sum}); |
| 34989 | } | 35007 | } |
| 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)); |
| 34991 | struct_type.backingIntType(ip).* = backing_int_ty.toIntern(); | 35009 | struct_type.backingIntType(ip).* = backing_int_ty.toIntern(); |
| 34992 | } | 35010 | } |
| 34993 | 35011 | ||
| ... | @@ -35597,23 +35615,23 @@ fn structZirInfo(zir: Zir, zir_index: Zir.Inst.Index) struct { | ... | @@ -35597,23 +35615,23 @@ fn structZirInfo(zir: Zir, zir_index: Zir.Inst.Index) struct { |
| 35597 | } | 35615 | } |
| 35598 | 35616 | ||
| 35599 | fn semaStructFields( | 35617 | fn semaStructFields( |
| 35600 | mod: *Module, | 35618 | zcu: *Zcu, |
| 35601 | arena: Allocator, | 35619 | arena: Allocator, |
| 35602 | struct_type: InternPool.LoadedStructType, | 35620 | struct_type: InternPool.LoadedStructType, |
| 35603 | ) CompileError!void { | 35621 | ) CompileError!void { |
| 35604 | const gpa = mod.gpa; | 35622 | const gpa = zcu.gpa; |
| 35605 | const ip = &mod.intern_pool; | 35623 | const ip = &zcu.intern_pool; |
| 35606 | const decl_index = struct_type.decl.unwrap() orelse return; | 35624 | const decl_index = struct_type.decl.unwrap() orelse return; |
| 35607 | const decl = mod.declPtr(decl_index); | 35625 | const decl = zcu.declPtr(decl_index); |
| 35608 | const namespace_index = struct_type.namespace.unwrap() orelse decl.src_namespace; | 35626 | 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; |
| 35610 | const zir_index = struct_type.zir_index.unwrap().?.resolve(ip); | 35628 | const zir_index = struct_type.zir_index.unwrap().?.resolve(ip); |
| 35611 | 35629 | ||
| 35612 | const fields_len, const small, var extra_index = structZirInfo(zir, zir_index); | 35630 | const fields_len, const small, var extra_index = structZirInfo(zir, zir_index); |
| 35613 | 35631 | ||
| 35614 | if (fields_len == 0) switch (struct_type.layout) { | 35632 | if (fields_len == 0) switch (struct_type.layout) { |
| 35615 | .@"packed" => { | 35633 | .@"packed" => { |
| 35616 | try semaBackingIntType(mod, struct_type); | 35634 | try semaBackingIntType(zcu, struct_type); |
| 35617 | return; | 35635 | return; |
| 35618 | }, | 35636 | }, |
| 35619 | .auto, .@"extern" => { | 35637 | .auto, .@"extern" => { |
| ... | @@ -35627,7 +35645,7 @@ fn semaStructFields( | ... | @@ -35627,7 +35645,7 @@ fn semaStructFields( |
| 35627 | defer comptime_err_ret_trace.deinit(); | 35645 | defer comptime_err_ret_trace.deinit(); |
| 35628 | 35646 | ||
| 35629 | var sema: Sema = .{ | 35647 | var sema: Sema = .{ |
| 35630 | .mod = mod, | 35648 | .mod = zcu, |
| 35631 | .gpa = gpa, | 35649 | .gpa = gpa, |
| 35632 | .arena = arena, | 35650 | .arena = arena, |
| 35633 | .code = zir, | 35651 | .code = zir, |
| ... | @@ -35749,7 +35767,7 @@ fn semaStructFields( | ... | @@ -35749,7 +35767,7 @@ fn semaStructFields( |
| 35749 | 35767 | ||
| 35750 | struct_type.field_types.get(ip)[field_i] = field_ty.toIntern(); | 35768 | struct_type.field_types.get(ip)[field_i] = field_ty.toIntern(); |
| 35751 | 35769 | ||
| 35752 | if (field_ty.zigTypeTag(mod) == .Opaque) { | 35770 | if (field_ty.zigTypeTag(zcu) == .Opaque) { |
| 35753 | const msg = msg: { | 35771 | const msg = msg: { |
| 35754 | const msg = try sema.errMsg(ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); | 35772 | const msg = try sema.errMsg(ty_src, "opaque types have unknown size and therefore cannot be directly embedded in structs", .{}); |
| 35755 | errdefer msg.destroy(sema.gpa); | 35773 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -35759,7 +35777,7 @@ fn semaStructFields( | ... | @@ -35759,7 +35777,7 @@ fn semaStructFields( |
| 35759 | }; | 35777 | }; |
| 35760 | return sema.failWithOwnedErrorMsg(&block_scope, msg); | 35778 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 35761 | } | 35779 | } |
| 35762 | if (field_ty.zigTypeTag(mod) == .NoReturn) { | 35780 | if (field_ty.zigTypeTag(zcu) == .NoReturn) { |
| 35763 | const msg = msg: { | 35781 | const msg = msg: { |
| 35764 | const msg = try sema.errMsg(ty_src, "struct fields cannot be 'noreturn'", .{}); | 35782 | const msg = try sema.errMsg(ty_src, "struct fields cannot be 'noreturn'", .{}); |
| 35765 | errdefer msg.destroy(sema.gpa); | 35783 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -35772,7 +35790,7 @@ fn semaStructFields( | ... | @@ -35772,7 +35790,7 @@ fn semaStructFields( |
| 35772 | switch (struct_type.layout) { | 35790 | switch (struct_type.layout) { |
| 35773 | .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) { | 35791 | .@"extern" => if (!try sema.validateExternType(field_ty, .struct_field)) { |
| 35774 | const msg = msg: { | 35792 | 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)}); |
| 35776 | errdefer msg.destroy(sema.gpa); | 35794 | errdefer msg.destroy(sema.gpa); |
| 35777 | 35795 | ||
| 35778 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field); | 35796 | try sema.explainWhyTypeIsNotExtern(msg, ty_src, field_ty, .struct_field); |
| ... | @@ -35784,7 +35802,7 @@ fn semaStructFields( | ... | @@ -35784,7 +35802,7 @@ fn semaStructFields( |
| 35784 | }, | 35802 | }, |
| 35785 | .@"packed" => if (!try sema.validatePackedType(field_ty)) { | 35803 | .@"packed" => if (!try sema.validatePackedType(field_ty)) { |
| 35786 | const msg = msg: { | 35804 | 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)}); |
| 35788 | errdefer msg.destroy(sema.gpa); | 35806 | errdefer msg.destroy(sema.gpa); |
| 35789 | 35807 | ||
| 35790 | try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty); | 35808 | try sema.explainWhyTypeIsNotPacked(msg, ty_src, field_ty); |
| ... | @@ -35820,19 +35838,19 @@ fn semaStructFields( | ... | @@ -35820,19 +35838,19 @@ fn semaStructFields( |
| 35820 | 35838 | ||
| 35821 | // This logic must be kept in sync with `semaStructFields` | 35839 | // This logic must be kept in sync with `semaStructFields` |
| 35822 | fn semaStructFieldInits( | 35840 | fn semaStructFieldInits( |
| 35823 | mod: *Module, | 35841 | zcu: *Zcu, |
| 35824 | arena: Allocator, | 35842 | arena: Allocator, |
| 35825 | struct_type: InternPool.LoadedStructType, | 35843 | struct_type: InternPool.LoadedStructType, |
| 35826 | ) CompileError!void { | 35844 | ) CompileError!void { |
| 35827 | const gpa = mod.gpa; | 35845 | const gpa = zcu.gpa; |
| 35828 | const ip = &mod.intern_pool; | 35846 | const ip = &zcu.intern_pool; |
| 35829 | 35847 | ||
| 35830 | assert(!struct_type.haveFieldInits(ip)); | 35848 | assert(!struct_type.haveFieldInits(ip)); |
| 35831 | 35849 | ||
| 35832 | const decl_index = struct_type.decl.unwrap() orelse return; | 35850 | const decl_index = struct_type.decl.unwrap() orelse return; |
| 35833 | const decl = mod.declPtr(decl_index); | 35851 | const decl = zcu.declPtr(decl_index); |
| 35834 | const namespace_index = struct_type.namespace.unwrap() orelse decl.src_namespace; | 35852 | 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; |
| 35836 | const zir_index = struct_type.zir_index.unwrap().?.resolve(ip); | 35854 | const zir_index = struct_type.zir_index.unwrap().?.resolve(ip); |
| 35837 | const fields_len, const small, var extra_index = structZirInfo(zir, zir_index); | 35855 | const fields_len, const small, var extra_index = structZirInfo(zir, zir_index); |
| 35838 | 35856 | ||
| ... | @@ -35840,7 +35858,7 @@ fn semaStructFieldInits( | ... | @@ -35840,7 +35858,7 @@ fn semaStructFieldInits( |
| 35840 | defer comptime_err_ret_trace.deinit(); | 35858 | defer comptime_err_ret_trace.deinit(); |
| 35841 | 35859 | ||
| 35842 | var sema: Sema = .{ | 35860 | var sema: Sema = .{ |
| 35843 | .mod = mod, | 35861 | .mod = zcu, |
| 35844 | .gpa = gpa, | 35862 | .gpa = gpa, |
| 35845 | .arena = arena, | 35863 | .arena = arena, |
| 35846 | .code = zir, | 35864 | .code = zir, |
| ... | @@ -35950,7 +35968,7 @@ fn semaStructFieldInits( | ... | @@ -35950,7 +35968,7 @@ fn semaStructFieldInits( |
| 35950 | }); | 35968 | }); |
| 35951 | }; | 35969 | }; |
| 35952 | 35970 | ||
| 35953 | if (default_val.canMutateComptimeVarState(mod)) { | 35971 | if (default_val.canMutateComptimeVarState(zcu)) { |
| 35954 | return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{}); | 35972 | return sema.fail(&block_scope, init_src, "field default value contains reference to comptime-mutable memory", .{}); |
| 35955 | } | 35973 | } |
| 35956 | struct_type.field_inits.get(ip)[field_i] = default_val.toIntern(); | 35974 | struct_type.field_inits.get(ip)[field_i] = default_val.toIntern(); |
| ... | @@ -35960,14 +35978,14 @@ fn semaStructFieldInits( | ... | @@ -35960,14 +35978,14 @@ fn semaStructFieldInits( |
| 35960 | try sema.flushExports(); | 35978 | try sema.flushExports(); |
| 35961 | } | 35979 | } |
| 35962 | 35980 | ||
| 35963 | fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.LoadedUnionType) CompileError!void { | 35981 | fn semaUnionFields(zcu: *Zcu, arena: Allocator, union_type: InternPool.LoadedUnionType) CompileError!void { |
| 35964 | const tracy = trace(@src()); | 35982 | const tracy = trace(@src()); |
| 35965 | defer tracy.end(); | 35983 | defer tracy.end(); |
| 35966 | 35984 | ||
| 35967 | const gpa = mod.gpa; | 35985 | const gpa = zcu.gpa; |
| 35968 | const ip = &mod.intern_pool; | 35986 | const ip = &zcu.intern_pool; |
| 35969 | const decl_index = union_type.decl; | 35987 | 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; |
| 35971 | const zir_index = union_type.zir_index.resolve(ip); | 35989 | const zir_index = union_type.zir_index.resolve(ip); |
| 35972 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; | 35990 | const extended = zir.instructions.items(.data)[@intFromEnum(zir_index)].extended; |
| 35973 | assert(extended.opcode == .union_decl); | 35991 | assert(extended.opcode == .union_decl); |
| ... | @@ -36011,13 +36029,13 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36011,13 +36029,13 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36011 | const body = zir.bodySlice(extra_index, body_len); | 36029 | const body = zir.bodySlice(extra_index, body_len); |
| 36012 | extra_index += body.len; | 36030 | extra_index += body.len; |
| 36013 | 36031 | ||
| 36014 | const decl = mod.declPtr(decl_index); | 36032 | const decl = zcu.declPtr(decl_index); |
| 36015 | 36033 | ||
| 36016 | var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa); | 36034 | var comptime_err_ret_trace = std.ArrayList(LazySrcLoc).init(gpa); |
| 36017 | defer comptime_err_ret_trace.deinit(); | 36035 | defer comptime_err_ret_trace.deinit(); |
| 36018 | 36036 | ||
| 36019 | var sema: Sema = .{ | 36037 | var sema: Sema = .{ |
| 36020 | .mod = mod, | 36038 | .mod = zcu, |
| 36021 | .gpa = gpa, | 36039 | .gpa = gpa, |
| 36022 | .arena = arena, | 36040 | .arena = arena, |
| 36023 | .code = zir, | 36041 | .code = zir, |
| ... | @@ -36063,18 +36081,18 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36063,18 +36081,18 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36063 | if (small.auto_enum_tag) { | 36081 | if (small.auto_enum_tag) { |
| 36064 | // The provided type is an integer type and we must construct the enum tag type here. | 36082 | // The provided type is an integer type and we must construct the enum tag type here. |
| 36065 | int_tag_ty = provided_ty; | 36083 | int_tag_ty = provided_ty; |
| 36066 | if (int_tag_ty.zigTypeTag(mod) != .Int and int_tag_ty.zigTypeTag(mod) != .ComptimeInt) { | 36084 | if (int_tag_ty.zigTypeTag(zcu) != .Int and int_tag_ty.zigTypeTag(zcu) != .ComptimeInt) { |
| 36067 | return sema.fail(&block_scope, tag_ty_src, "expected integer tag type, found '{}'", .{int_tag_ty.fmt(mod)}); | 36085 | return sema.fail(&block_scope, tag_ty_src, "expected integer tag type, found '{}'", .{int_tag_ty.fmt(zcu)}); |
| 36068 | } | 36086 | } |
| 36069 | 36087 | ||
| 36070 | if (fields_len > 0) { | 36088 | 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); |
| 36072 | if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) { | 36090 | if (!(try sema.intFitsInType(field_count_val, int_tag_ty, null))) { |
| 36073 | const msg = msg: { | 36091 | const msg = msg: { |
| 36074 | const msg = try sema.errMsg(tag_ty_src, "specified integer tag type cannot represent every field", .{}); | 36092 | const msg = try sema.errMsg(tag_ty_src, "specified integer tag type cannot represent every field", .{}); |
| 36075 | errdefer msg.destroy(sema.gpa); | 36093 | errdefer msg.destroy(sema.gpa); |
| 36076 | try sema.errNote(tag_ty_src, msg, "type '{}' cannot fit values in range 0...{d}", .{ | 36094 | 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), |
| 36078 | fields_len - 1, | 36096 | fields_len - 1, |
| 36079 | }); | 36097 | }); |
| 36080 | break :msg msg; | 36098 | break :msg msg; |
| ... | @@ -36089,7 +36107,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36089,7 +36107,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36089 | union_type.tagTypePtr(ip).* = provided_ty.toIntern(); | 36107 | union_type.tagTypePtr(ip).* = provided_ty.toIntern(); |
| 36090 | const enum_type = switch (ip.indexToKey(provided_ty.toIntern())) { | 36108 | const enum_type = switch (ip.indexToKey(provided_ty.toIntern())) { |
| 36091 | .enum_type => ip.loadEnumType(provided_ty.toIntern()), | 36109 | .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)}), |
| 36093 | }; | 36111 | }; |
| 36094 | // The fields of the union must match the enum exactly. | 36112 | // The fields of the union must match the enum exactly. |
| 36095 | // A flag per field is used to check for missing and extraneous fields. | 36113 | // 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 | ... | @@ -36185,7 +36203,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36185 | const val = if (last_tag_val) |val| | 36203 | const val = if (last_tag_val) |val| |
| 36186 | try sema.intAdd(val, Value.one_comptime_int, int_tag_ty, undefined) | 36204 | try sema.intAdd(val, Value.one_comptime_int, int_tag_ty, undefined) |
| 36187 | else | 36205 | else |
| 36188 | try mod.intValue(int_tag_ty, 0); | 36206 | try zcu.intValue(int_tag_ty, 0); |
| 36189 | last_tag_val = val; | 36207 | last_tag_val = val; |
| 36190 | 36208 | ||
| 36191 | break :blk val; | 36209 | break :blk val; |
| ... | @@ -36197,7 +36215,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36197,7 +36215,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36197 | .offset = .{ .container_field_value = @intCast(gop.index) }, | 36215 | .offset = .{ .container_field_value = @intCast(gop.index) }, |
| 36198 | }; | 36216 | }; |
| 36199 | const msg = msg: { | 36217 | 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)}); |
| 36201 | errdefer msg.destroy(gpa); | 36219 | errdefer msg.destroy(gpa); |
| 36202 | try sema.errNote(other_value_src, msg, "other occurrence here", .{}); | 36220 | try sema.errNote(other_value_src, msg, "other occurrence here", .{}); |
| 36203 | break :msg msg; | 36221 | break :msg msg; |
| ... | @@ -36227,7 +36245,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36227,7 +36245,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36227 | const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*); | 36245 | const tag_info = ip.loadEnumType(union_type.tagTypePtr(ip).*); |
| 36228 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { | 36246 | const enum_index = tag_info.nameIndex(ip, field_name) orelse { |
| 36229 | return sema.fail(&block_scope, name_src, "no field named '{}' in enum '{}'", .{ | 36247 | 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), |
| 36231 | }); | 36249 | }); |
| 36232 | }; | 36250 | }; |
| 36233 | 36251 | ||
| ... | @@ -36254,7 +36272,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36254,7 +36272,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36254 | } | 36272 | } |
| 36255 | } | 36273 | } |
| 36256 | 36274 | ||
| 36257 | if (field_ty.zigTypeTag(mod) == .Opaque) { | 36275 | if (field_ty.zigTypeTag(zcu) == .Opaque) { |
| 36258 | const msg = msg: { | 36276 | const msg = msg: { |
| 36259 | const msg = try sema.errMsg(type_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); | 36277 | const msg = try sema.errMsg(type_src, "opaque types have unknown size and therefore cannot be directly embedded in unions", .{}); |
| 36260 | errdefer msg.destroy(sema.gpa); | 36278 | errdefer msg.destroy(sema.gpa); |
| ... | @@ -36269,7 +36287,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36269,7 +36287,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36269 | !try sema.validateExternType(field_ty, .union_field)) | 36287 | !try sema.validateExternType(field_ty, .union_field)) |
| 36270 | { | 36288 | { |
| 36271 | const msg = msg: { | 36289 | 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)}); |
| 36273 | errdefer msg.destroy(sema.gpa); | 36291 | errdefer msg.destroy(sema.gpa); |
| 36274 | 36292 | ||
| 36275 | try sema.explainWhyTypeIsNotExtern(msg, type_src, field_ty, .union_field); | 36293 | try sema.explainWhyTypeIsNotExtern(msg, type_src, field_ty, .union_field); |
| ... | @@ -36280,7 +36298,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36280,7 +36298,7 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36280 | return sema.failWithOwnedErrorMsg(&block_scope, msg); | 36298 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 36281 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { | 36299 | } else if (layout == .@"packed" and !try sema.validatePackedType(field_ty)) { |
| 36282 | const msg = msg: { | 36300 | 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)}); |
| 36284 | errdefer msg.destroy(sema.gpa); | 36302 | errdefer msg.destroy(sema.gpa); |
| 36285 | 36303 | ||
| 36286 | try sema.explainWhyTypeIsNotPacked(msg, type_src, field_ty); | 36304 | try sema.explainWhyTypeIsNotPacked(msg, type_src, field_ty); |
| ... | @@ -36325,10 +36343,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded | ... | @@ -36325,10 +36343,10 @@ fn semaUnionFields(mod: *Module, arena: Allocator, union_type: InternPool.Loaded |
| 36325 | return sema.failWithOwnedErrorMsg(&block_scope, msg); | 36343 | return sema.failWithOwnedErrorMsg(&block_scope, msg); |
| 36326 | } | 36344 | } |
| 36327 | } else if (enum_field_vals.count() > 0) { | 36345 | } 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)); |
| 36329 | union_type.tagTypePtr(ip).* = enum_ty; | 36347 | union_type.tagTypePtr(ip).* = enum_ty; |
| 36330 | } else { | 36348 | } 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)); |
| 36332 | union_type.tagTypePtr(ip).* = enum_ty; | 36350 | union_type.tagTypePtr(ip).* = enum_ty; |
| 36333 | } | 36351 | } |
| 36334 | 36352 |
src/Type.zig+1-1| ... | @@ -3455,7 +3455,7 @@ pub fn typeDeclSrcLine(ty: Type, zcu: *const Zcu) ?u32 { | ... | @@ -3455,7 +3455,7 @@ pub fn typeDeclSrcLine(ty: Type, zcu: *const Zcu) ?u32 { |
| 3455 | else => return null, | 3455 | else => return null, |
| 3456 | }; | 3456 | }; |
| 3457 | const info = tracked.resolveFull(&zcu.intern_pool); | 3457 | 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).?]; |
| 3459 | assert(file.zir_loaded); | 3459 | assert(file.zir_loaded); |
| 3460 | const zir = file.zir; | 3460 | const zir = file.zir; |
| 3461 | const inst = zir.instructions.get(@intFromEnum(info.inst)); | 3461 | const inst = zir.instructions.get(@intFromEnum(info.inst)); |
src/Zcu.zig+311-244| ... | @@ -72,6 +72,7 @@ codegen_prog_node: std.Progress.Node = undefined, | ... | @@ -72,6 +72,7 @@ codegen_prog_node: std.Progress.Node = undefined, |
| 72 | global_zir_cache: Compilation.Directory, | 72 | global_zir_cache: Compilation.Directory, |
| 73 | /// Used by AstGen worker to load and store ZIR cache. | 73 | /// Used by AstGen worker to load and store ZIR cache. |
| 74 | local_zir_cache: Compilation.Directory, | 74 | local_zir_cache: Compilation.Directory, |
| 75 | |||
| 75 | /// This is where all `Export` values are stored. Not all values here are necessarily valid exports; | 76 | /// This is where all `Export` values are stored. Not all values here are necessarily valid exports; |
| 76 | /// to enumerate all exports, `single_exports` and `multi_exports` must be consulted. | 77 | /// to enumerate all exports, `single_exports` and `multi_exports` must be consulted. |
| 77 | all_exports: ArrayListUnmanaged(Export) = .{}, | 78 | all_exports: ArrayListUnmanaged(Export) = .{}, |
| ... | @@ -88,14 +89,35 @@ multi_exports: std.AutoArrayHashMapUnmanaged(AnalUnit, extern struct { | ... | @@ -88,14 +89,35 @@ multi_exports: std.AutoArrayHashMapUnmanaged(AnalUnit, extern struct { |
| 88 | index: u32, | 89 | index: u32, |
| 89 | len: u32, | 90 | len: u32, |
| 90 | }) = .{}, | 91 | }) = .{}, |
| 91 | /// The set of all the Zig source files in the Module. We keep track of this in order | 92 | |
| 92 | /// to iterate over it and check which source files have been modified on the file system when | 93 | /// The set of all the Zig source files in the Zig Compilation Unit. Tracked in |
| 93 | /// an update is requested, as well as to cache `@import` results. | 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 | /// | ||
| 94 | /// Keys are fully resolved file paths. This table owns the keys and values. | 98 | /// 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`. | ||
| 95 | import_table: std.StringArrayHashMapUnmanaged(*File) = .{}, | 106 | import_table: std.StringArrayHashMapUnmanaged(*File) = .{}, |
| 96 | /// This acts as a map from `path_digest` to the corresponding `File`. | 107 | |
| 97 | /// The value is omitted, as keys are ordered identically to `import_table`. | 108 | /// Elements are ordered identically to `import_table`. |
| 98 | path_digest_map: std.AutoArrayHashMapUnmanaged(Cache.BinDigest, void) = .{}, | 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. | ||
| 119 | files: std.AutoArrayHashMapUnmanaged(Cache.BinDigest, Decl.OptionalIndex) = .{}, | ||
| 120 | |||
| 99 | /// The set of all the files which have been loaded with `@embedFile` in the Module. | 121 | /// The set of all the files which have been loaded with `@embedFile` in the Module. |
| 100 | /// We keep track of this in order to iterate over it and check which files have been | 122 | /// We keep track of this in order to iterate over it and check which files have been |
| 101 | /// modified on the file system when an update is requested, as well as to cache | 123 | /// modified on the file system when an update is requested, as well as to cache |
| ... | @@ -387,8 +409,8 @@ pub const Decl = struct { | ... | @@ -387,8 +409,8 @@ pub const Decl = struct { |
| 387 | anon, | 409 | anon, |
| 388 | }; | 410 | }; |
| 389 | 411 | ||
| 390 | const Index = InternPool.DeclIndex; | 412 | pub const Index = InternPool.DeclIndex; |
| 391 | const OptionalIndex = InternPool.OptionalDeclIndex; | 413 | pub const OptionalIndex = InternPool.OptionalDeclIndex; |
| 392 | 414 | ||
| 393 | pub fn zirBodies(decl: Decl, zcu: *Zcu) Zir.Inst.Declaration.Bodies { | 415 | pub fn zirBodies(decl: Decl, zcu: *Zcu) Zir.Inst.Declaration.Bodies { |
| 394 | const zir = decl.getFileScope(zcu).zir; | 416 | const zir = decl.getFileScope(zcu).zir; |
| ... | @@ -490,6 +512,10 @@ pub const Decl = struct { | ... | @@ -490,6 +512,10 @@ pub const Decl = struct { |
| 490 | } | 512 | } |
| 491 | 513 | ||
| 492 | pub fn getFileScope(decl: Decl, zcu: *Zcu) *File { | 514 | 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 { | ||
| 493 | return zcu.namespacePtr(decl.src_namespace).file_scope; | 519 | return zcu.namespacePtr(decl.src_namespace).file_scope; |
| 494 | } | 520 | } |
| 495 | 521 | ||
| ... | @@ -558,7 +584,7 @@ pub const Decl = struct { | ... | @@ -558,7 +584,7 @@ pub const Decl = struct { |
| 558 | break :inst generic_owner_decl.zir_decl_index.unwrap().?; | 584 | break :inst generic_owner_decl.zir_decl_index.unwrap().?; |
| 559 | }; | 585 | }; |
| 560 | const info = tracked.resolveFull(&zcu.intern_pool); | 586 | 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).?]; |
| 562 | assert(file.zir_loaded); | 588 | assert(file.zir_loaded); |
| 563 | const zir = file.zir; | 589 | const zir = file.zir; |
| 564 | const inst = zir.instructions.get(@intFromEnum(info.inst)); | 590 | const inst = zir.instructions.get(@intFromEnum(info.inst)); |
| ... | @@ -595,7 +621,7 @@ pub const DeclAdapter = struct { | ... | @@ -595,7 +621,7 @@ pub const DeclAdapter = struct { |
| 595 | /// The container that structs, enums, unions, and opaques have. | 621 | /// The container that structs, enums, unions, and opaques have. |
| 596 | pub const Namespace = struct { | 622 | pub const Namespace = struct { |
| 597 | parent: OptionalIndex, | 623 | parent: OptionalIndex, |
| 598 | file_scope: *File, | 624 | file_scope: File.Index, |
| 599 | /// Will be a struct, enum, union, or opaque. | 625 | /// Will be a struct, enum, union, or opaque. |
| 600 | decl_index: Decl.Index, | 626 | decl_index: Decl.Index, |
| 601 | /// Direct children of the namespace. | 627 | /// Direct children of the namespace. |
| ... | @@ -627,6 +653,10 @@ pub const Namespace = struct { | ... | @@ -627,6 +653,10 @@ pub const Namespace = struct { |
| 627 | } | 653 | } |
| 628 | }; | 654 | }; |
| 629 | 655 | ||
| 656 | pub fn fileScope(ns: Namespace, zcu: *Zcu) *File { | ||
| 657 | return zcu.fileByIndex(ns.file_scope); | ||
| 658 | } | ||
| 659 | |||
| 630 | // This renders e.g. "std.fs.Dir.OpenOptions" | 660 | // This renders e.g. "std.fs.Dir.OpenOptions" |
| 631 | pub fn renderFullyQualifiedName( | 661 | pub fn renderFullyQualifiedName( |
| 632 | ns: Namespace, | 662 | ns: Namespace, |
| ... | @@ -641,7 +671,7 @@ pub const Namespace = struct { | ... | @@ -641,7 +671,7 @@ pub const Namespace = struct { |
| 641 | writer, | 671 | writer, |
| 642 | ); | 672 | ); |
| 643 | } else { | 673 | } else { |
| 644 | try ns.file_scope.renderFullyQualifiedName(writer); | 674 | try ns.fileScope(zcu).renderFullyQualifiedName(writer); |
| 645 | } | 675 | } |
| 646 | if (name != .empty) try writer.print(".{}", .{name.fmt(&zcu.intern_pool)}); | 676 | if (name != .empty) try writer.print(".{}", .{name.fmt(&zcu.intern_pool)}); |
| 647 | } | 677 | } |
| ... | @@ -661,7 +691,7 @@ pub const Namespace = struct { | ... | @@ -661,7 +691,7 @@ pub const Namespace = struct { |
| 661 | ); | 691 | ); |
| 662 | break :sep '.'; | 692 | break :sep '.'; |
| 663 | } else sep: { | 693 | } else sep: { |
| 664 | try ns.file_scope.renderFullyQualifiedDebugName(writer); | 694 | try ns.fileScope(zcu).renderFullyQualifiedDebugName(writer); |
| 665 | break :sep ':'; | 695 | break :sep ':'; |
| 666 | }; | 696 | }; |
| 667 | if (name != .empty) try writer.print("{c}{}", .{ sep, name.fmt(&zcu.intern_pool) }); | 697 | if (name != .empty) try writer.print("{c}{}", .{ sep, name.fmt(&zcu.intern_pool) }); |
| ... | @@ -680,7 +710,7 @@ pub const Namespace = struct { | ... | @@ -680,7 +710,7 @@ pub const Namespace = struct { |
| 680 | const decl = zcu.declPtr(cur_ns.decl_index); | 710 | const decl = zcu.declPtr(cur_ns.decl_index); |
| 681 | count += decl.name.length(ip) + 1; | 711 | count += decl.name.length(ip) + 1; |
| 682 | cur_ns = zcu.namespacePtr(cur_ns.parent.unwrap() orelse { | 712 | 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; |
| 684 | break :count count; | 714 | break :count count; |
| 685 | }); | 715 | }); |
| 686 | } | 716 | } |
| ... | @@ -715,8 +745,6 @@ pub const Namespace = struct { | ... | @@ -715,8 +745,6 @@ pub const Namespace = struct { |
| 715 | }; | 745 | }; |
| 716 | 746 | ||
| 717 | pub const File = struct { | 747 | pub const File = struct { |
| 718 | /// The Decl of the struct that represents this File. | ||
| 719 | root_decl: Decl.OptionalIndex, | ||
| 720 | status: enum { | 748 | status: enum { |
| 721 | never_loaded, | 749 | never_loaded, |
| 722 | retryable_failure, | 750 | retryable_failure, |
| ... | @@ -744,8 +772,6 @@ pub const File = struct { | ... | @@ -744,8 +772,6 @@ pub const File = struct { |
| 744 | multi_pkg: bool = false, | 772 | multi_pkg: bool = false, |
| 745 | /// List of references to this file, used for multi-package errors. | 773 | /// List of references to this file, used for multi-package errors. |
| 746 | references: std.ArrayListUnmanaged(File.Reference) = .{}, | 774 | references: std.ArrayListUnmanaged(File.Reference) = .{}, |
| 747 | /// The hash of the path to this file, used to store `InternPool.TrackedInst`. | ||
| 748 | path_digest: Cache.BinDigest, | ||
| 749 | 775 | ||
| 750 | /// The most recent successful ZIR for this file, with no errors. | 776 | /// The most recent successful ZIR for this file, with no errors. |
| 751 | /// This is only populated when a previously successful ZIR | 777 | /// This is only populated when a previously successful ZIR |
| ... | @@ -757,7 +783,7 @@ pub const File = struct { | ... | @@ -757,7 +783,7 @@ pub const File = struct { |
| 757 | pub const Reference = union(enum) { | 783 | pub const Reference = union(enum) { |
| 758 | /// The file is imported directly (i.e. not as a package) with @import. | 784 | /// The file is imported directly (i.e. not as a package) with @import. |
| 759 | import: struct { | 785 | import: struct { |
| 760 | file: *File, | 786 | file: File.Index, |
| 761 | token: Ast.TokenIndex, | 787 | token: Ast.TokenIndex, |
| 762 | }, | 788 | }, |
| 763 | /// The file is the root of a module. | 789 | /// The file is the root of a module. |
| ... | @@ -791,28 +817,6 @@ pub const File = struct { | ... | @@ -791,28 +817,6 @@ pub const File = struct { |
| 791 | } | 817 | } |
| 792 | } | 818 | } |
| 793 | 819 | ||
| 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 | |||
| 816 | pub const Source = struct { | 820 | pub const Source = struct { |
| 817 | bytes: [:0]const u8, | 821 | bytes: [:0]const u8, |
| 818 | stat: Cache.File.Stat, | 822 | stat: Cache.File.Stat, |
| ... | @@ -865,13 +869,6 @@ pub const File = struct { | ... | @@ -865,13 +869,6 @@ pub const File = struct { |
| 865 | return &file.tree; | 869 | return &file.tree; |
| 866 | } | 870 | } |
| 867 | 871 | ||
| 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 | |||
| 875 | pub fn renderFullyQualifiedName(file: File, writer: anytype) !void { | 872 | pub fn renderFullyQualifiedName(file: File, writer: anytype) !void { |
| 876 | // Convert all the slashes into dots and truncate the extension. | 873 | // Convert all the slashes into dots and truncate the extension. |
| 877 | const ext = std.fs.path.extension(file.sub_file_path); | 874 | const ext = std.fs.path.extension(file.sub_file_path); |
| ... | @@ -937,7 +934,7 @@ pub const File = struct { | ... | @@ -937,7 +934,7 @@ pub const File = struct { |
| 937 | } | 934 | } |
| 938 | 935 | ||
| 939 | const mod = switch (ref) { | 936 | const mod = switch (ref) { |
| 940 | .import => |import| import.file.mod, | 937 | .import => |import| zcu.fileByIndex(import.file).mod, |
| 941 | .root => |mod| mod, | 938 | .root => |mod| mod, |
| 942 | }; | 939 | }; |
| 943 | if (mod != file.mod) file.multi_pkg = true; | 940 | if (mod != file.mod) file.multi_pkg = true; |
| ... | @@ -971,6 +968,10 @@ pub const File = struct { | ... | @@ -971,6 +968,10 @@ pub const File = struct { |
| 971 | } | 968 | } |
| 972 | } | 969 | } |
| 973 | } | 970 | } |
| 971 | |||
| 972 | pub const Index = enum(u32) { | ||
| 973 | _, | ||
| 974 | }; | ||
| 974 | }; | 975 | }; |
| 975 | 976 | ||
| 976 | pub const EmbedFile = struct { | 977 | pub const EmbedFile = struct { |
| ... | @@ -2355,7 +2356,7 @@ pub const LazySrcLoc = struct { | ... | @@ -2355,7 +2356,7 @@ pub const LazySrcLoc = struct { |
| 2355 | break :inst .{ info.path_digest, info.inst }; | 2356 | break :inst .{ info.path_digest, info.inst }; |
| 2356 | }; | 2357 | }; |
| 2357 | const file = file: { | 2358 | const file = file: { |
| 2358 | const index = zcu.path_digest_map.getIndex(want_path_digest).?; | 2359 | const index = zcu.files.getIndex(want_path_digest).?; |
| 2359 | break :file zcu.import_table.values()[index]; | 2360 | break :file zcu.import_table.values()[index]; |
| 2360 | }; | 2361 | }; |
| 2361 | assert(file.zir_loaded); | 2362 | assert(file.zir_loaded); |
| ... | @@ -2423,11 +2424,12 @@ pub fn deinit(zcu: *Zcu) void { | ... | @@ -2423,11 +2424,12 @@ pub fn deinit(zcu: *Zcu) void { |
| 2423 | for (zcu.import_table.keys()) |key| { | 2424 | for (zcu.import_table.keys()) |key| { |
| 2424 | gpa.free(key); | 2425 | gpa.free(key); |
| 2425 | } | 2426 | } |
| 2426 | for (zcu.import_table.values()) |value| { | 2427 | for (0..zcu.import_table.entries.len) |file_index_usize| { |
| 2427 | value.destroy(zcu); | 2428 | const file_index: File.Index = @enumFromInt(file_index_usize); |
| 2429 | zcu.destroyFile(file_index); | ||
| 2428 | } | 2430 | } |
| 2429 | zcu.import_table.deinit(gpa); | 2431 | zcu.import_table.deinit(gpa); |
| 2430 | zcu.path_digest_map.deinit(gpa); | 2432 | zcu.files.deinit(gpa); |
| 2431 | 2433 | ||
| 2432 | for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| { | 2434 | for (zcu.embed_table.keys(), zcu.embed_table.values()) |path, embed_file| { |
| 2433 | gpa.free(path); | 2435 | gpa.free(path); |
| ... | @@ -2531,6 +2533,37 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void { | ... | @@ -2531,6 +2533,37 @@ pub fn destroyDecl(mod: *Module, decl_index: Decl.Index) void { |
| 2531 | } | 2533 | } |
| 2532 | } | 2534 | } |
| 2533 | 2535 | ||
| 2536 | fn 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 | |||
| 2559 | pub 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 | |||
| 2534 | pub fn declPtr(mod: *Module, index: Decl.Index) *Decl { | 2567 | pub fn declPtr(mod: *Module, index: Decl.Index) *Decl { |
| 2535 | return mod.intern_pool.declPtr(index); | 2568 | return mod.intern_pool.declPtr(index); |
| 2536 | } | 2569 | } |
| ... | @@ -2563,14 +2596,14 @@ comptime { | ... | @@ -2563,14 +2596,14 @@ comptime { |
| 2563 | } | 2596 | } |
| 2564 | } | 2597 | } |
| 2565 | 2598 | ||
| 2566 | pub fn astGenFile(mod: *Module, file: *File) !void { | 2599 | pub fn astGenFile(zcu: *Zcu, file: *File, path_digest: Cache.BinDigest, opt_root_decl: Zcu.Decl.OptionalIndex) !void { |
| 2567 | assert(!file.mod.isBuiltin()); | 2600 | assert(!file.mod.isBuiltin()); |
| 2568 | 2601 | ||
| 2569 | const tracy = trace(@src()); | 2602 | const tracy = trace(@src()); |
| 2570 | defer tracy.end(); | 2603 | defer tracy.end(); |
| 2571 | 2604 | ||
| 2572 | const comp = mod.comp; | 2605 | const comp = zcu.comp; |
| 2573 | const gpa = mod.gpa; | 2606 | const gpa = zcu.gpa; |
| 2574 | 2607 | ||
| 2575 | // In any case we need to examine the stat of the file to determine the course of action. | 2608 | // In any case we need to examine the stat of the file to determine the course of action. |
| 2576 | var source_file = try file.mod.root.openFile(file.sub_file_path, .{}); | 2609 | var source_file = try file.mod.root.openFile(file.sub_file_path, .{}); |
| ... | @@ -2578,17 +2611,9 @@ pub fn astGenFile(mod: *Module, file: *File) !void { | ... | @@ -2578,17 +2611,9 @@ pub fn astGenFile(mod: *Module, file: *File) !void { |
| 2578 | 2611 | ||
| 2579 | const stat = try source_file.stat(); | 2612 | const stat = try source_file.stat(); |
| 2580 | 2613 | ||
| 2581 | const want_local_cache = file.mod == mod.main_mod; | 2614 | const want_local_cache = file.mod == zcu.main_mod; |
| 2582 | const hex_digest = hex: { | 2615 | const hex_digest = Cache.binToHex(path_digest); |
| 2583 | var hex: Cache.HexDigest = undefined; | 2616 | const cache_directory = if (want_local_cache) zcu.local_zir_cache else zcu.global_zir_cache; |
| 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; | ||
| 2592 | const zir_dir = cache_directory.handle; | 2617 | const zir_dir = cache_directory.handle; |
| 2593 | 2618 | ||
| 2594 | // Determine whether we need to reload the file from disk and redo parsing and AstGen. | 2619 | // 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 { | ... | @@ -2688,7 +2713,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void { |
| 2688 | { | 2713 | { |
| 2689 | comp.mutex.lock(); | 2714 | comp.mutex.lock(); |
| 2690 | defer comp.mutex.unlock(); | 2715 | defer comp.mutex.unlock(); |
| 2691 | try mod.failed_files.putNoClobber(gpa, file, null); | 2716 | try zcu.failed_files.putNoClobber(gpa, file, null); |
| 2692 | } | 2717 | } |
| 2693 | file.status = .astgen_failure; | 2718 | file.status = .astgen_failure; |
| 2694 | return error.AnalysisFail; | 2719 | return error.AnalysisFail; |
| ... | @@ -2712,7 +2737,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void { | ... | @@ -2712,7 +2737,7 @@ pub fn astGenFile(mod: *Module, file: *File) !void { |
| 2712 | else => |e| return e, | 2737 | else => |e| return e, |
| 2713 | }; | 2738 | }; |
| 2714 | 2739 | ||
| 2715 | mod.lockAndClearFileCompileError(file); | 2740 | zcu.lockAndClearFileCompileError(file); |
| 2716 | 2741 | ||
| 2717 | // If the previous ZIR does not have compile errors, keep it around | 2742 | // If the previous ZIR does not have compile errors, keep it around |
| 2718 | // in case parsing or new ZIR fails. In case of successful ZIR update | 2743 | // 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 { | ... | @@ -2818,27 +2843,27 @@ pub fn astGenFile(mod: *Module, file: *File) !void { |
| 2818 | { | 2843 | { |
| 2819 | comp.mutex.lock(); | 2844 | comp.mutex.lock(); |
| 2820 | defer comp.mutex.unlock(); | 2845 | defer comp.mutex.unlock(); |
| 2821 | try mod.failed_files.putNoClobber(gpa, file, null); | 2846 | try zcu.failed_files.putNoClobber(gpa, file, null); |
| 2822 | } | 2847 | } |
| 2823 | file.status = .astgen_failure; | 2848 | file.status = .astgen_failure; |
| 2824 | return error.AnalysisFail; | 2849 | return error.AnalysisFail; |
| 2825 | } | 2850 | } |
| 2826 | 2851 | ||
| 2827 | if (file.prev_zir) |prev_zir| { | 2852 | if (file.prev_zir) |prev_zir| { |
| 2828 | try updateZirRefs(mod, file, prev_zir.*); | 2853 | try updateZirRefs(zcu, file, prev_zir.*, path_digest); |
| 2829 | // No need to keep previous ZIR. | 2854 | // No need to keep previous ZIR. |
| 2830 | prev_zir.deinit(gpa); | 2855 | prev_zir.deinit(gpa); |
| 2831 | gpa.destroy(prev_zir); | 2856 | gpa.destroy(prev_zir); |
| 2832 | file.prev_zir = null; | 2857 | file.prev_zir = null; |
| 2833 | } | 2858 | } |
| 2834 | 2859 | ||
| 2835 | if (file.root_decl.unwrap()) |root_decl| { | 2860 | if (opt_root_decl.unwrap()) |root_decl| { |
| 2836 | // The root of this file must be re-analyzed, since the file has changed. | 2861 | // The root of this file must be re-analyzed, since the file has changed. |
| 2837 | comp.mutex.lock(); | 2862 | comp.mutex.lock(); |
| 2838 | defer comp.mutex.unlock(); | 2863 | defer comp.mutex.unlock(); |
| 2839 | 2864 | ||
| 2840 | log.debug("outdated root Decl: {}", .{root_decl}); | 2865 | 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, {}); |
| 2842 | } | 2867 | } |
| 2843 | } | 2868 | } |
| 2844 | 2869 | ||
| ... | @@ -2914,7 +2939,7 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File) | ... | @@ -2914,7 +2939,7 @@ fn loadZirCacheBody(gpa: Allocator, header: Zir.Header, cache_file: std.fs.File) |
| 2914 | 2939 | ||
| 2915 | /// This is called from the AstGen thread pool, so must acquire | 2940 | /// This is called from the AstGen thread pool, so must acquire |
| 2916 | /// the Compilation mutex when acting on shared state. | 2941 | /// the Compilation mutex when acting on shared state. |
| 2917 | fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void { | 2942 | fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir, path_digest: Cache.BinDigest) !void { |
| 2918 | const gpa = zcu.gpa; | 2943 | const gpa = zcu.gpa; |
| 2919 | const new_zir = file.zir; | 2944 | const new_zir = file.zir; |
| 2920 | 2945 | ||
| ... | @@ -2930,7 +2955,7 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void { | ... | @@ -2930,7 +2955,7 @@ fn updateZirRefs(zcu: *Module, file: *File, old_zir: Zir) !void { |
| 2930 | // iterating over this full set for every updated file. | 2955 | // iterating over this full set for every updated file. |
| 2931 | for (zcu.intern_pool.tracked_insts.keys(), 0..) |*ti, idx_raw| { | 2956 | for (zcu.intern_pool.tracked_insts.keys(), 0..) |*ti, idx_raw| { |
| 2932 | const ti_idx: InternPool.TrackedInst.Index = @enumFromInt(idx_raw); | 2957 | 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; |
| 2934 | const old_inst = ti.inst; | 2959 | const old_inst = ti.inst; |
| 2935 | ti.inst = inst_map.get(ti.inst) orelse { | 2960 | ti.inst = inst_map.get(ti.inst) orelse { |
| 2936 | // Tracking failed for this instruction. Invalidate associated `src_hash` deps. | 2961 | // Tracking failed for this instruction. Invalidate associated `src_hash` deps. |
| ... | @@ -3378,11 +3403,11 @@ pub fn mapOldZirToNew( | ... | @@ -3378,11 +3403,11 @@ pub fn mapOldZirToNew( |
| 3378 | } | 3403 | } |
| 3379 | 3404 | ||
| 3380 | /// Like `ensureDeclAnalyzed`, but the Decl is a file's root Decl. | 3405 | /// Like `ensureDeclAnalyzed`, but the Decl is a file's root Decl. |
| 3381 | pub fn ensureFileAnalyzed(zcu: *Zcu, file: *File) SemaError!void { | 3406 | pub fn ensureFileAnalyzed(zcu: *Zcu, file_index: File.Index) SemaError!void { |
| 3382 | if (file.root_decl.unwrap()) |existing_root| { | 3407 | if (zcu.fileRootDecl(file_index).unwrap()) |existing_root| { |
| 3383 | return zcu.ensureDeclAnalyzed(existing_root); | 3408 | return zcu.ensureDeclAnalyzed(existing_root); |
| 3384 | } else { | 3409 | } else { |
| 3385 | return zcu.semaFile(file); | 3410 | return zcu.semaFile(file_index); |
| 3386 | } | 3411 | } |
| 3387 | } | 3412 | } |
| 3388 | 3413 | ||
| ... | @@ -3455,7 +3480,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void { | ... | @@ -3455,7 +3480,7 @@ pub fn ensureDeclAnalyzed(mod: *Module, decl_index: Decl.Index) SemaError!void { |
| 3455 | } | 3480 | } |
| 3456 | 3481 | ||
| 3457 | if (mod.declIsRoot(decl_index)) { | 3482 | 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); |
| 3459 | break :blk .{ | 3484 | break :blk .{ |
| 3460 | .invalidate_decl_val = changed, | 3485 | .invalidate_decl_val = changed, |
| 3461 | .invalidate_decl_ref = changed, | 3486 | .invalidate_decl_ref = changed, |
| ... | @@ -3787,17 +3812,23 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index) | ... | @@ -3787,17 +3812,23 @@ pub fn ensureFuncBodyAnalysisQueued(mod: *Module, func_index: InternPool.Index) |
| 3787 | func.analysis(ip).state = .queued; | 3812 | func.analysis(ip).state = .queued; |
| 3788 | } | 3813 | } |
| 3789 | 3814 | ||
| 3790 | /// https://github.com/ziglang/zig/issues/14307 | 3815 | pub fn semaPkg(zcu: *Zcu, pkg: *Package.Module) !void { |
| 3791 | pub fn semaPkg(mod: *Module, pkg: *Package.Module) !void { | 3816 | const import_file_result = try zcu.importPkg(pkg); |
| 3792 | const file = (try mod.importPkg(pkg)).file; | 3817 | const root_decl_index = zcu.fileRootDecl(import_file_result.file_index); |
| 3793 | if (file.root_decl == .none) { | 3818 | if (root_decl_index == .none) { |
| 3794 | return mod.semaFile(file); | 3819 | return zcu.semaFile(import_file_result.file_index); |
| 3795 | } | 3820 | } |
| 3796 | } | 3821 | } |
| 3797 | 3822 | ||
| 3798 | fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespace.Index, file: *File) Allocator.Error!InternPool.Index { | 3823 | fn getFileRootStruct( |
| 3824 | zcu: *Zcu, | ||
| 3825 | decl_index: Decl.Index, | ||
| 3826 | namespace_index: Namespace.Index, | ||
| 3827 | file_index: File.Index, | ||
| 3828 | ) Allocator.Error!InternPool.Index { | ||
| 3799 | const gpa = zcu.gpa; | 3829 | const gpa = zcu.gpa; |
| 3800 | const ip = &zcu.intern_pool; | 3830 | const ip = &zcu.intern_pool; |
| 3831 | const file = zcu.fileByIndex(file_index); | ||
| 3801 | const extended = file.zir.instructions.items(.data)[@intFromEnum(Zir.Inst.Index.main_struct_inst)].extended; | 3832 | const extended = file.zir.instructions.items(.data)[@intFromEnum(Zir.Inst.Index.main_struct_inst)].extended; |
| 3802 | assert(extended.opcode == .struct_decl); | 3833 | assert(extended.opcode == .struct_decl); |
| 3803 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); | 3834 | const small: Zir.Inst.StructDecl.Small = @bitCast(extended.small); |
| ... | @@ -3818,7 +3849,7 @@ fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespa | ... | @@ -3818,7 +3849,7 @@ fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespa |
| 3818 | const decls = file.zir.bodySlice(extra_index, decls_len); | 3849 | const decls = file.zir.bodySlice(extra_index, decls_len); |
| 3819 | extra_index += decls_len; | 3850 | extra_index += decls_len; |
| 3820 | 3851 | ||
| 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); |
| 3822 | const wip_ty = switch (try ip.getStructType(gpa, .{ | 3853 | const wip_ty = switch (try ip.getStructType(gpa, .{ |
| 3823 | .layout = .auto, | 3854 | .layout = .auto, |
| 3824 | .fields_len = fields_len, | 3855 | .fields_len = fields_len, |
| ... | @@ -3863,8 +3894,9 @@ fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespa | ... | @@ -3863,8 +3894,9 @@ fn getFileRootStruct(zcu: *Zcu, decl_index: Decl.Index, namespace_index: Namespa |
| 3863 | /// If `type_outdated`, the struct type itself is considered outdated and is | 3894 | /// If `type_outdated`, the struct type itself is considered outdated and is |
| 3864 | /// reconstructed at a new InternPool index. Otherwise, the namespace is just | 3895 | /// reconstructed at a new InternPool index. Otherwise, the namespace is just |
| 3865 | /// re-analyzed. Returns whether the decl's tyval was invalidated. | 3896 | /// re-analyzed. Returns whether the decl's tyval was invalidated. |
| 3866 | fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool { | 3897 | fn semaFileUpdate(zcu: *Zcu, file_index: File.Index, type_outdated: bool) SemaError!bool { |
| 3867 | const decl = zcu.declPtr(file.root_decl.unwrap().?); | 3898 | const file = zcu.fileByIndex(file_index); |
| 3899 | const decl = zcu.declPtr(zcu.fileRootDecl(file_index).unwrap().?); | ||
| 3868 | 3900 | ||
| 3869 | log.debug("semaFileUpdate mod={s} sub_file_path={s} type_outdated={}", .{ | 3901 | log.debug("semaFileUpdate mod={s} sub_file_path={s} type_outdated={}", .{ |
| 3870 | file.mod.fully_qualified_name, | 3902 | file.mod.fully_qualified_name, |
| ... | @@ -3883,7 +3915,8 @@ fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool { | ... | @@ -3883,7 +3915,8 @@ fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool { |
| 3883 | 3915 | ||
| 3884 | if (decl.analysis == .file_failure) { | 3916 | if (decl.analysis == .file_failure) { |
| 3885 | // No struct type currently exists. Create one! | 3917 | // 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); | ||
| 3887 | return true; | 3920 | return true; |
| 3888 | } | 3921 | } |
| 3889 | 3922 | ||
| ... | @@ -3892,10 +3925,13 @@ fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool { | ... | @@ -3892,10 +3925,13 @@ fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool { |
| 3892 | 3925 | ||
| 3893 | if (type_outdated) { | 3926 | if (type_outdated) { |
| 3894 | // Invalidate the existing type, reusing the decl and namespace. | 3927 | // 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 | })); | ||
| 3896 | zcu.intern_pool.remove(decl.val.toIntern()); | 3932 | zcu.intern_pool.remove(decl.val.toIntern()); |
| 3897 | decl.val = undefined; | 3933 | 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); |
| 3899 | return true; | 3935 | return true; |
| 3900 | } | 3936 | } |
| 3901 | 3937 | ||
| ... | @@ -3923,35 +3959,36 @@ fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool { | ... | @@ -3923,35 +3959,36 @@ fn semaFileUpdate(zcu: *Zcu, file: *File, type_outdated: bool) SemaError!bool { |
| 3923 | 3959 | ||
| 3924 | /// Regardless of the file status, will create a `Decl` if none exists so that we can track | 3960 | /// Regardless of the file status, will create a `Decl` if none exists so that we can track |
| 3925 | /// dependencies and re-analyze when the file becomes outdated. | 3961 | /// dependencies and re-analyze when the file becomes outdated. |
| 3926 | fn semaFile(mod: *Module, file: *File) SemaError!void { | 3962 | fn semaFile(zcu: *Zcu, file_index: File.Index) SemaError!void { |
| 3927 | const tracy = trace(@src()); | 3963 | const tracy = trace(@src()); |
| 3928 | defer tracy.end(); | 3964 | defer tracy.end(); |
| 3929 | 3965 | ||
| 3930 | assert(file.root_decl == .none); | 3966 | const file = zcu.fileByIndex(file_index); |
| 3967 | assert(zcu.fileRootDecl(file_index) == .none); | ||
| 3931 | 3968 | ||
| 3932 | const gpa = mod.gpa; | 3969 | const gpa = zcu.gpa; |
| 3933 | log.debug("semaFile mod={s} sub_file_path={s}", .{ | 3970 | log.debug("semaFile zcu={s} sub_file_path={s}", .{ |
| 3934 | file.mod.fully_qualified_name, file.sub_file_path, | 3971 | file.mod.fully_qualified_name, file.sub_file_path, |
| 3935 | }); | 3972 | }); |
| 3936 | 3973 | ||
| 3937 | // Because these three things each reference each other, `undefined` | 3974 | // Because these three things each reference each other, `undefined` |
| 3938 | // placeholders are used before being set after the struct type gains an | 3975 | // placeholders are used before being set after the struct type gains an |
| 3939 | // InternPool index. | 3976 | // InternPool index. |
| 3940 | const new_namespace_index = try mod.createNamespace(.{ | 3977 | const new_namespace_index = try zcu.createNamespace(.{ |
| 3941 | .parent = .none, | 3978 | .parent = .none, |
| 3942 | .decl_index = undefined, | 3979 | .decl_index = undefined, |
| 3943 | .file_scope = file, | 3980 | .file_scope = file_index, |
| 3944 | }); | 3981 | }); |
| 3945 | errdefer mod.destroyNamespace(new_namespace_index); | 3982 | errdefer zcu.destroyNamespace(new_namespace_index); |
| 3946 | 3983 | ||
| 3947 | const new_decl_index = try mod.allocateNewDecl(new_namespace_index); | 3984 | const new_decl_index = try zcu.allocateNewDecl(new_namespace_index); |
| 3948 | const new_decl = mod.declPtr(new_decl_index); | 3985 | const new_decl = zcu.declPtr(new_decl_index); |
| 3949 | errdefer @panic("TODO error handling"); | 3986 | errdefer @panic("TODO error handling"); |
| 3950 | 3987 | ||
| 3951 | file.root_decl = new_decl_index.toOptional(); | 3988 | zcu.setFileRootDecl(file_index, new_decl_index.toOptional()); |
| 3952 | mod.namespacePtr(new_namespace_index).decl_index = new_decl_index; | 3989 | zcu.namespacePtr(new_namespace_index).decl_index = new_decl_index; |
| 3953 | 3990 | ||
| 3954 | new_decl.name = try file.fullyQualifiedName(mod); | 3991 | new_decl.name = try file.fullyQualifiedName(zcu); |
| 3955 | new_decl.name_fully_qualified = true; | 3992 | new_decl.name_fully_qualified = true; |
| 3956 | new_decl.is_pub = true; | 3993 | new_decl.is_pub = true; |
| 3957 | new_decl.is_exported = false; | 3994 | new_decl.is_exported = false; |
| ... | @@ -3965,13 +4002,13 @@ fn semaFile(mod: *Module, file: *File) SemaError!void { | ... | @@ -3965,13 +4002,13 @@ fn semaFile(mod: *Module, file: *File) SemaError!void { |
| 3965 | } | 4002 | } |
| 3966 | assert(file.zir_loaded); | 4003 | assert(file.zir_loaded); |
| 3967 | 4004 | ||
| 3968 | const struct_ty = try mod.getFileRootStruct(new_decl_index, new_namespace_index, file); | 4005 | const struct_ty = try zcu.getFileRootStruct(new_decl_index, new_namespace_index, file_index); |
| 3969 | errdefer mod.intern_pool.remove(struct_ty); | 4006 | errdefer zcu.intern_pool.remove(struct_ty); |
| 3970 | 4007 | ||
| 3971 | switch (mod.comp.cache_use) { | 4008 | switch (zcu.comp.cache_use) { |
| 3972 | .whole => |whole| if (whole.cache_manifest) |man| { | 4009 | .whole => |whole| if (whole.cache_manifest) |man| { |
| 3973 | const source = file.getSource(gpa) catch |err| { | 4010 | 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)}); |
| 3975 | return error.AnalysisFail; | 4012 | return error.AnalysisFail; |
| 3976 | }; | 4013 | }; |
| 3977 | 4014 | ||
| ... | @@ -3980,7 +4017,7 @@ fn semaFile(mod: *Module, file: *File) SemaError!void { | ... | @@ -3980,7 +4017,7 @@ fn semaFile(mod: *Module, file: *File) SemaError!void { |
| 3980 | file.mod.root.sub_path, | 4017 | file.mod.root.sub_path, |
| 3981 | file.sub_file_path, | 4018 | file.sub_file_path, |
| 3982 | }) catch |err| { | 4019 | }) 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)}); |
| 3984 | return error.AnalysisFail; | 4021 | return error.AnalysisFail; |
| 3985 | }; | 4022 | }; |
| 3986 | errdefer gpa.free(resolved_path); | 4023 | errdefer gpa.free(resolved_path); |
| ... | @@ -4000,57 +4037,58 @@ const SemaDeclResult = packed struct { | ... | @@ -4000,57 +4037,58 @@ const SemaDeclResult = packed struct { |
| 4000 | invalidate_decl_ref: bool, | 4037 | invalidate_decl_ref: bool, |
| 4001 | }; | 4038 | }; |
| 4002 | 4039 | ||
| 4003 | fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { | 4040 | fn semaDecl(zcu: *Zcu, decl_index: Decl.Index) !SemaDeclResult { |
| 4004 | const tracy = trace(@src()); | 4041 | const tracy = trace(@src()); |
| 4005 | defer tracy.end(); | 4042 | defer tracy.end(); |
| 4006 | 4043 | ||
| 4007 | const decl = mod.declPtr(decl_index); | 4044 | const decl = zcu.declPtr(decl_index); |
| 4008 | const ip = &mod.intern_pool; | 4045 | const ip = &zcu.intern_pool; |
| 4009 | 4046 | ||
| 4010 | if (decl.getFileScope(mod).status != .success_zir) { | 4047 | if (decl.getFileScope(zcu).status != .success_zir) { |
| 4011 | return error.AnalysisFail; | 4048 | return error.AnalysisFail; |
| 4012 | } | 4049 | } |
| 4013 | 4050 | ||
| 4014 | assert(!mod.declIsRoot(decl_index)); | 4051 | assert(!zcu.declIsRoot(decl_index)); |
| 4015 | 4052 | ||
| 4016 | if (decl.zir_decl_index == .none and decl.owns_tv) { | 4053 | if (decl.zir_decl_index == .none and decl.owns_tv) { |
| 4017 | // We are re-analyzing an anonymous owner Decl (for a function or a namespace type). | 4054 | // 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); |
| 4019 | } | 4056 | } |
| 4020 | 4057 | ||
| 4021 | log.debug("semaDecl '{d}'", .{@intFromEnum(decl_index)}); | 4058 | 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)}); |
| 4023 | defer blk: { | 4060 | 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)}); |
| 4025 | } | 4062 | } |
| 4026 | 4063 | ||
| 4027 | const old_has_tv = decl.has_tv; | 4064 | const old_has_tv = decl.has_tv; |
| 4028 | // The following values are ignored if `!old_has_tv` | 4065 | // 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; |
| 4030 | const old_val = decl.val; | 4067 | const old_val = decl.val; |
| 4031 | const old_align = decl.alignment; | 4068 | const old_align = decl.alignment; |
| 4032 | const old_linksection = decl.@"linksection"; | 4069 | const old_linksection = decl.@"linksection"; |
| 4033 | const old_addrspace = decl.@"addrspace"; | 4070 | 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| |
| 4035 | prev_func.analysis(ip).state == .inline_only | 4072 | prev_func.analysis(ip).state == .inline_only |
| 4036 | else | 4073 | else |
| 4037 | false; | 4074 | false; |
| 4038 | 4075 | ||
| 4039 | const decl_inst = decl.zir_decl_index.unwrap().?.resolve(ip); | 4076 | const decl_inst = decl.zir_decl_index.unwrap().?.resolve(ip); |
| 4040 | 4077 | ||
| 4041 | const gpa = mod.gpa; | 4078 | const gpa = zcu.gpa; |
| 4042 | const zir = decl.getFileScope(mod).zir; | 4079 | const zir = decl.getFileScope(zcu).zir; |
| 4043 | 4080 | ||
| 4044 | const builtin_type_target_index: InternPool.Index = ip_index: { | 4081 | const builtin_type_target_index: InternPool.Index = ip_index: { |
| 4045 | const std_mod = mod.std_mod; | 4082 | const std_mod = zcu.std_mod; |
| 4046 | if (decl.getFileScope(mod).mod != std_mod) break :ip_index .none; | 4083 | if (decl.getFileScope(zcu).mod != std_mod) break :ip_index .none; |
| 4047 | // We're in the std module. | 4084 | // We're in the std module. |
| 4048 | const std_file = (try mod.importPkg(std_mod)).file; | 4085 | const std_file_imported = try zcu.importPkg(std_mod); |
| 4049 | const std_decl = mod.declPtr(std_file.root_decl.unwrap().?); | 4086 | const std_file_root_decl_index = zcu.fileRootDecl(std_file_imported.file_index); |
| 4050 | const std_namespace = std_decl.getInnerNamespace(mod).?; | 4087 | const std_decl = zcu.declPtr(std_file_root_decl_index.unwrap().?); |
| 4088 | const std_namespace = std_decl.getInnerNamespace(zcu).?; | ||
| 4051 | const builtin_str = try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls); | 4089 | 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); | 4090 | const builtin_decl = zcu.declPtr(std_namespace.decls.getKeyAdapted(builtin_str, DeclAdapter{ .zcu = zcu }) orelse break :ip_index .none); |
| 4053 | const builtin_namespace = builtin_decl.getInnerNamespaceIndex(mod).unwrap() orelse break :ip_index .none; | 4091 | const builtin_namespace = builtin_decl.getInnerNamespaceIndex(zcu).unwrap() orelse break :ip_index .none; |
| 4054 | if (decl.src_namespace != builtin_namespace) break :ip_index .none; | 4092 | if (decl.src_namespace != builtin_namespace) break :ip_index .none; |
| 4055 | // We're in builtin.zig. This could be a builtin we need to add to a specific InternPool index. | 4093 | // We're in builtin.zig. This could be a builtin we need to add to a specific InternPool index. |
| 4056 | for ([_][]const u8{ | 4094 | for ([_][]const u8{ |
| ... | @@ -4083,7 +4121,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { | ... | @@ -4083,7 +4121,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 4083 | break :ip_index .none; | 4121 | break :ip_index .none; |
| 4084 | }; | 4122 | }; |
| 4085 | 4123 | ||
| 4086 | mod.intern_pool.removeDependenciesForDepender(gpa, AnalUnit.wrap(.{ .decl = decl_index })); | 4124 | zcu.intern_pool.removeDependenciesForDepender(gpa, AnalUnit.wrap(.{ .decl = decl_index })); |
| 4087 | 4125 | ||
| 4088 | decl.analysis = .in_progress; | 4126 | decl.analysis = .in_progress; |
| 4089 | 4127 | ||
| ... | @@ -4094,7 +4132,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { | ... | @@ -4094,7 +4132,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 4094 | defer comptime_err_ret_trace.deinit(); | 4132 | defer comptime_err_ret_trace.deinit(); |
| 4095 | 4133 | ||
| 4096 | var sema: Sema = .{ | 4134 | var sema: Sema = .{ |
| 4097 | .mod = mod, | 4135 | .mod = zcu, |
| 4098 | .gpa = gpa, | 4136 | .gpa = gpa, |
| 4099 | .arena = analysis_arena.allocator(), | 4137 | .arena = analysis_arena.allocator(), |
| 4100 | .code = zir, | 4138 | .code = zir, |
| ... | @@ -4112,8 +4150,8 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { | ... | @@ -4112,8 +4150,8 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 4112 | 4150 | ||
| 4113 | // Every Decl (other than file root Decls, which do not have a ZIR index) has a dependency on its own source. | 4151 | // Every Decl (other than file root Decls, which do not have a ZIR index) has a dependency on its own source. |
| 4114 | try sema.declareDependency(.{ .src_hash = try ip.trackZir( | 4152 | try sema.declareDependency(.{ .src_hash = try ip.trackZir( |
| 4115 | sema.gpa, | 4153 | gpa, |
| 4116 | decl.getFileScope(mod), | 4154 | zcu.filePathDigest(decl.getFileScopeIndex(zcu)), |
| 4117 | decl_inst, | 4155 | decl_inst, |
| 4118 | ) }); | 4156 | ) }); |
| 4119 | 4157 | ||
| ... | @@ -4129,7 +4167,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { | ... | @@ -4129,7 +4167,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 4129 | }; | 4167 | }; |
| 4130 | defer block_scope.instructions.deinit(gpa); | 4168 | defer block_scope.instructions.deinit(gpa); |
| 4131 | 4169 | ||
| 4132 | const decl_bodies = decl.zirBodies(mod); | 4170 | const decl_bodies = decl.zirBodies(zcu); |
| 4133 | 4171 | ||
| 4134 | const result_ref = try sema.resolveInlineBody(&block_scope, decl_bodies.value_body, decl_inst); | 4172 | const result_ref = try sema.resolveInlineBody(&block_scope, decl_bodies.value_body, decl_inst); |
| 4135 | // We'll do some other bits with the Sema. Clear the type target index just | 4173 | // 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 { | ... | @@ -4141,22 +4179,22 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 4141 | const ty_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_ty = 0 }); | 4179 | const ty_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_ty = 0 }); |
| 4142 | const init_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_init = 0 }); | 4180 | const init_src: LazySrcLoc = block_scope.src(.{ .node_offset_var_decl_init = 0 }); |
| 4143 | const decl_val = try sema.resolveFinalDeclValue(&block_scope, init_src, result_ref); | 4181 | 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); |
| 4145 | 4183 | ||
| 4146 | // Note this resolves the type of the Decl, not the value; if this Decl | 4184 | // Note this resolves the type of the Decl, not the value; if this Decl |
| 4147 | // is a struct, for example, this resolves `type` (which needs no resolution), | 4185 | // is a struct, for example, this resolves `type` (which needs no resolution), |
| 4148 | // not the struct itself. | 4186 | // not the struct itself. |
| 4149 | try decl_ty.resolveLayout(mod); | 4187 | try decl_ty.resolveLayout(zcu); |
| 4150 | 4188 | ||
| 4151 | if (decl.kind == .@"usingnamespace") { | 4189 | if (decl.kind == .@"usingnamespace") { |
| 4152 | if (!decl_ty.eql(Type.type, mod)) { | 4190 | if (!decl_ty.eql(Type.type, zcu)) { |
| 4153 | return sema.fail(&block_scope, ty_src, "expected type, found {}", .{ | 4191 | return sema.fail(&block_scope, ty_src, "expected type, found {}", .{ |
| 4154 | decl_ty.fmt(mod), | 4192 | decl_ty.fmt(zcu), |
| 4155 | }); | 4193 | }); |
| 4156 | } | 4194 | } |
| 4157 | const ty = decl_val.toType(); | 4195 | const ty = decl_val.toType(); |
| 4158 | if (ty.getNamespace(mod) == null) { | 4196 | if (ty.getNamespace(zcu) == null) { |
| 4159 | return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(mod)}); | 4197 | return sema.fail(&block_scope, ty_src, "type {} has no namespace", .{ty.fmt(zcu)}); |
| 4160 | } | 4198 | } |
| 4161 | 4199 | ||
| 4162 | decl.val = ty.toValue(); | 4200 | decl.val = ty.toValue(); |
| ... | @@ -4194,7 +4232,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { | ... | @@ -4194,7 +4232,7 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 4194 | .func => |func| { | 4232 | .func => |func| { |
| 4195 | decl.owns_tv = func.owner_decl == decl_index; | 4233 | decl.owns_tv = func.owner_decl == decl_index; |
| 4196 | queue_linker_work = false; | 4234 | 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; |
| 4198 | is_func = decl.owns_tv; | 4236 | is_func = decl.owns_tv; |
| 4199 | }, | 4237 | }, |
| 4200 | 4238 | ||
| ... | @@ -4246,10 +4284,10 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { | ... | @@ -4246,10 +4284,10 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 4246 | decl.analysis = .complete; | 4284 | decl.analysis = .complete; |
| 4247 | 4285 | ||
| 4248 | const result: SemaDeclResult = if (old_has_tv) .{ | 4286 | const result: SemaDeclResult = if (old_has_tv) .{ |
| 4249 | .invalidate_decl_val = !decl_ty.eql(old_ty, mod) or | 4287 | .invalidate_decl_val = !decl_ty.eql(old_ty, zcu) or |
| 4250 | !decl.val.eql(old_val, decl_ty, mod) or | 4288 | !decl.val.eql(old_val, decl_ty, zcu) or |
| 4251 | is_inline != old_is_inline, | 4289 | 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 |
| 4253 | decl.alignment != old_align or | 4291 | decl.alignment != old_align or |
| 4254 | decl.@"linksection" != old_linksection or | 4292 | decl.@"linksection" != old_linksection or |
| 4255 | decl.@"addrspace" != old_addrspace or | 4293 | decl.@"addrspace" != old_addrspace or |
| ... | @@ -4263,12 +4301,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { | ... | @@ -4263,12 +4301,12 @@ fn semaDecl(mod: *Module, decl_index: Decl.Index) !SemaDeclResult { |
| 4263 | if (has_runtime_bits) { | 4301 | if (has_runtime_bits) { |
| 4264 | // Needed for codegen_decl which will call updateDecl and then the | 4302 | // Needed for codegen_decl which will call updateDecl and then the |
| 4265 | // codegen backend wants full access to the Decl Type. | 4303 | // codegen backend wants full access to the Decl Type. |
| 4266 | try decl_ty.resolveFully(mod); | 4304 | try decl_ty.resolveFully(zcu); |
| 4267 | 4305 | ||
| 4268 | try mod.comp.work_queue.writeItem(.{ .codegen_decl = decl_index }); | 4306 | try zcu.comp.work_queue.writeItem(.{ .codegen_decl = decl_index }); |
| 4269 | 4307 | ||
| 4270 | if (result.invalidate_decl_ref and mod.emit_h != null) { | 4308 | if (result.invalidate_decl_ref and zcu.emit_h != null) { |
| 4271 | try mod.comp.work_queue.writeItem(.{ .emit_h_decl = decl_index }); | 4309 | try zcu.comp.work_queue.writeItem(.{ .emit_h_decl = decl_index }); |
| 4272 | } | 4310 | } |
| 4273 | } | 4311 | } |
| 4274 | 4312 | ||
| ... | @@ -4322,6 +4360,7 @@ fn semaAnonOwnerDecl(zcu: *Zcu, decl_index: Decl.Index) !SemaDeclResult { | ... | @@ -4322,6 +4360,7 @@ fn semaAnonOwnerDecl(zcu: *Zcu, decl_index: Decl.Index) !SemaDeclResult { |
| 4322 | 4360 | ||
| 4323 | pub const ImportFileResult = struct { | 4361 | pub const ImportFileResult = struct { |
| 4324 | file: *File, | 4362 | file: *File, |
| 4363 | file_index: File.Index, | ||
| 4325 | is_new: bool, | 4364 | is_new: bool, |
| 4326 | is_pkg: bool, | 4365 | is_pkg: bool, |
| 4327 | }; | 4366 | }; |
| ... | @@ -4344,20 +4383,25 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult { | ... | @@ -4344,20 +4383,25 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult { |
| 4344 | errdefer _ = zcu.import_table.pop(); | 4383 | errdefer _ = zcu.import_table.pop(); |
| 4345 | if (gop.found_existing) { | 4384 | if (gop.found_existing) { |
| 4346 | try gop.value_ptr.*.addReference(zcu.*, .{ .root = mod }); | 4385 | try gop.value_ptr.*.addReference(zcu.*, .{ .root = mod }); |
| 4347 | return ImportFileResult{ | 4386 | return .{ |
| 4348 | .file = gop.value_ptr.*, | 4387 | .file = gop.value_ptr.*, |
| 4388 | .file_index = @enumFromInt(gop.index), | ||
| 4349 | .is_new = false, | 4389 | .is_new = false, |
| 4350 | .is_pkg = true, | 4390 | .is_pkg = true, |
| 4351 | }; | 4391 | }; |
| 4352 | } | 4392 | } |
| 4353 | 4393 | ||
| 4394 | try zcu.files.ensureUnusedCapacity(gpa, 1); | ||
| 4395 | |||
| 4354 | if (mod.builtin_file) |builtin_file| { | 4396 | if (mod.builtin_file) |builtin_file| { |
| 4355 | keep_resolved_path = true; // It's now owned by import_table. | 4397 | keep_resolved_path = true; // It's now owned by import_table. |
| 4356 | gop.value_ptr.* = builtin_file; | 4398 | gop.value_ptr.* = builtin_file; |
| 4357 | try builtin_file.addReference(zcu.*, .{ .root = mod }); | 4399 | 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); | ||
| 4359 | return .{ | 4402 | return .{ |
| 4360 | .file = builtin_file, | 4403 | .file = builtin_file, |
| 4404 | .file_index = @enumFromInt(zcu.files.entries.len - 1), | ||
| 4361 | .is_new = false, | 4405 | .is_new = false, |
| 4362 | .is_pkg = true, | 4406 | .is_pkg = true, |
| 4363 | }; | 4407 | }; |
| ... | @@ -4382,43 +4426,36 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult { | ... | @@ -4382,43 +4426,36 @@ pub fn importPkg(zcu: *Zcu, mod: *Package.Module) !ImportFileResult { |
| 4382 | .zir = undefined, | 4426 | .zir = undefined, |
| 4383 | .status = .never_loaded, | 4427 | .status = .never_loaded, |
| 4384 | .mod = mod, | 4428 | .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 | }, | ||
| 4400 | }; | 4429 | }; |
| 4430 | |||
| 4431 | const path_digest = computePathDigest(zcu, mod, sub_file_path); | ||
| 4432 | |||
| 4401 | try new_file.addReference(zcu.*, .{ .root = mod }); | 4433 | try new_file.addReference(zcu.*, .{ .root = mod }); |
| 4402 | try zcu.path_digest_map.put(gpa, new_file.path_digest, {}); | 4434 | zcu.files.putAssumeCapacityNoClobber(path_digest, .none); |
| 4403 | return ImportFileResult{ | 4435 | return .{ |
| 4404 | .file = new_file, | 4436 | .file = new_file, |
| 4437 | .file_index = @enumFromInt(zcu.files.entries.len - 1), | ||
| 4405 | .is_new = true, | 4438 | .is_new = true, |
| 4406 | .is_pkg = true, | 4439 | .is_pkg = true, |
| 4407 | }; | 4440 | }; |
| 4408 | } | 4441 | } |
| 4409 | 4442 | ||
| 4443 | /// Called from a worker thread during AstGen. | ||
| 4444 | /// Also called from Sema during semantic analysis. | ||
| 4410 | pub fn importFile( | 4445 | pub fn importFile( |
| 4411 | zcu: *Zcu, | 4446 | zcu: *Zcu, |
| 4412 | cur_file: *File, | 4447 | cur_file: *File, |
| 4413 | import_string: []const u8, | 4448 | import_string: []const u8, |
| 4414 | ) !ImportFileResult { | 4449 | ) !ImportFileResult { |
| 4450 | const mod = cur_file.mod; | ||
| 4451 | |||
| 4415 | if (std.mem.eql(u8, import_string, "std")) { | 4452 | if (std.mem.eql(u8, import_string, "std")) { |
| 4416 | return zcu.importPkg(zcu.std_mod); | 4453 | return zcu.importPkg(zcu.std_mod); |
| 4417 | } | 4454 | } |
| 4418 | if (std.mem.eql(u8, import_string, "root")) { | 4455 | if (std.mem.eql(u8, import_string, "root")) { |
| 4419 | return zcu.importPkg(zcu.root_mod); | 4456 | return zcu.importPkg(zcu.root_mod); |
| 4420 | } | 4457 | } |
| 4421 | if (cur_file.mod.deps.get(import_string)) |pkg| { | 4458 | if (mod.deps.get(import_string)) |pkg| { |
| 4422 | return zcu.importPkg(pkg); | 4459 | return zcu.importPkg(pkg); |
| 4423 | } | 4460 | } |
| 4424 | if (!mem.endsWith(u8, import_string, ".zig")) { | 4461 | if (!mem.endsWith(u8, import_string, ".zig")) { |
| ... | @@ -4430,8 +4467,8 @@ pub fn importFile( | ... | @@ -4430,8 +4467,8 @@ pub fn importFile( |
| 4430 | // an import refers to the same as another, despite different relative paths | 4467 | // an import refers to the same as another, despite different relative paths |
| 4431 | // or differently mapped package names. | 4468 | // or differently mapped package names. |
| 4432 | const resolved_path = try std.fs.path.resolve(gpa, &.{ | 4469 | const resolved_path = try std.fs.path.resolve(gpa, &.{ |
| 4433 | cur_file.mod.root.root_dir.path orelse ".", | 4470 | mod.root.root_dir.path orelse ".", |
| 4434 | cur_file.mod.root.sub_path, | 4471 | mod.root.sub_path, |
| 4435 | cur_file.sub_file_path, | 4472 | cur_file.sub_file_path, |
| 4436 | "..", | 4473 | "..", |
| 4437 | import_string, | 4474 | import_string, |
| ... | @@ -4442,18 +4479,21 @@ pub fn importFile( | ... | @@ -4442,18 +4479,21 @@ pub fn importFile( |
| 4442 | 4479 | ||
| 4443 | const gop = try zcu.import_table.getOrPut(gpa, resolved_path); | 4480 | const gop = try zcu.import_table.getOrPut(gpa, resolved_path); |
| 4444 | errdefer _ = zcu.import_table.pop(); | 4481 | errdefer _ = zcu.import_table.pop(); |
| 4445 | if (gop.found_existing) return ImportFileResult{ | 4482 | if (gop.found_existing) return .{ |
| 4446 | .file = gop.value_ptr.*, | 4483 | .file = gop.value_ptr.*, |
| 4484 | .file_index = @enumFromInt(gop.index), | ||
| 4447 | .is_new = false, | 4485 | .is_new = false, |
| 4448 | .is_pkg = false, | 4486 | .is_pkg = false, |
| 4449 | }; | 4487 | }; |
| 4450 | 4488 | ||
| 4489 | try zcu.files.ensureUnusedCapacity(gpa, 1); | ||
| 4490 | |||
| 4451 | const new_file = try gpa.create(File); | 4491 | const new_file = try gpa.create(File); |
| 4452 | errdefer gpa.destroy(new_file); | 4492 | errdefer gpa.destroy(new_file); |
| 4453 | 4493 | ||
| 4454 | const resolved_root_path = try std.fs.path.resolve(gpa, &.{ | 4494 | const resolved_root_path = try std.fs.path.resolve(gpa, &.{ |
| 4455 | cur_file.mod.root.root_dir.path orelse ".", | 4495 | mod.root.root_dir.path orelse ".", |
| 4456 | cur_file.mod.root.sub_path, | 4496 | mod.root.sub_path, |
| 4457 | }); | 4497 | }); |
| 4458 | defer gpa.free(resolved_root_path); | 4498 | defer gpa.free(resolved_root_path); |
| 4459 | 4499 | ||
| ... | @@ -4484,26 +4524,14 @@ pub fn importFile( | ... | @@ -4484,26 +4524,14 @@ pub fn importFile( |
| 4484 | .tree = undefined, | 4524 | .tree = undefined, |
| 4485 | .zir = undefined, | 4525 | .zir = undefined, |
| 4486 | .status = .never_loaded, | 4526 | .status = .never_loaded, |
| 4487 | .mod = cur_file.mod, | 4527 | .mod = 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 | }, | ||
| 4503 | }; | 4528 | }; |
| 4504 | try zcu.path_digest_map.put(gpa, new_file.path_digest, {}); | 4529 | |
| 4505 | return ImportFileResult{ | 4530 | const path_digest = computePathDigest(zcu, mod, sub_file_path); |
| 4531 | zcu.files.putAssumeCapacityNoClobber(path_digest, .none); | ||
| 4532 | return .{ | ||
| 4506 | .file = new_file, | 4533 | .file = new_file, |
| 4534 | .file_index = @enumFromInt(zcu.files.entries.len - 1), | ||
| 4507 | .is_new = true, | 4535 | .is_new = true, |
| 4508 | .is_pkg = false, | 4536 | .is_pkg = false, |
| 4509 | }; | 4537 | }; |
| ... | @@ -4581,6 +4609,21 @@ pub fn embedFile( | ... | @@ -4581,6 +4609,21 @@ pub fn embedFile( |
| 4581 | return newEmbedFile(mod, cur_file.mod, sub_file_path, resolved_path, gop.value_ptr, src_loc); | 4609 | return newEmbedFile(mod, cur_file.mod, sub_file_path, resolved_path, gop.value_ptr, src_loc); |
| 4582 | } | 4610 | } |
| 4583 | 4611 | ||
| 4612 | fn 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 | |||
| 4584 | /// https://github.com/ziglang/zig/issues/14307 | 4627 | /// https://github.com/ziglang/zig/issues/14307 |
| 4585 | fn newEmbedFile( | 4628 | fn newEmbedFile( |
| 4586 | mod: *Module, | 4629 | mod: *Module, |
| ... | @@ -4765,7 +4808,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void | ... | @@ -4765,7 +4808,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4765 | const namespace_index = iter.namespace_index; | 4808 | const namespace_index = iter.namespace_index; |
| 4766 | const namespace = zcu.namespacePtr(namespace_index); | 4809 | const namespace = zcu.namespacePtr(namespace_index); |
| 4767 | const gpa = zcu.gpa; | 4810 | const gpa = zcu.gpa; |
| 4768 | const zir = namespace.file_scope.zir; | 4811 | const zir = namespace.fileScope(zcu).zir; |
| 4769 | const ip = &zcu.intern_pool; | 4812 | const ip = &zcu.intern_pool; |
| 4770 | 4813 | ||
| 4771 | const inst_data = zir.instructions.items(.data)[@intFromEnum(decl_inst)].declaration; | 4814 | 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 | ... | @@ -4848,7 +4891,8 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4848 | else => {}, | 4891 | else => {}, |
| 4849 | } | 4892 | } |
| 4850 | 4893 | ||
| 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); | ||
| 4852 | 4896 | ||
| 4853 | // We create a Decl for it regardless of analysis status. | 4897 | // We create a Decl for it regardless of analysis status. |
| 4854 | 4898 | ||
| ... | @@ -4878,7 +4922,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void | ... | @@ -4878,7 +4922,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4878 | namespace.decls.putAssumeCapacityNoClobberContext(decl_index, {}, .{ .zcu = zcu }); | 4922 | namespace.decls.putAssumeCapacityNoClobberContext(decl_index, {}, .{ .zcu = zcu }); |
| 4879 | 4923 | ||
| 4880 | const comp = zcu.comp; | 4924 | const comp = zcu.comp; |
| 4881 | const decl_mod = namespace.file_scope.mod; | 4925 | const decl_mod = namespace.fileScope(zcu).mod; |
| 4882 | const want_analysis = declaration.flags.is_export or switch (kind) { | 4926 | const want_analysis = declaration.flags.is_export or switch (kind) { |
| 4883 | .anon => unreachable, | 4927 | .anon => unreachable, |
| 4884 | .@"comptime" => true, | 4928 | .@"comptime" => true, |
| ... | @@ -4908,7 +4952,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void | ... | @@ -4908,7 +4952,7 @@ fn scanDecl(iter: *ScanDeclIter, decl_inst: Zir.Inst.Index) Allocator.Error!void |
| 4908 | // re-analysis for us if necessary. | 4952 | // re-analysis for us if necessary. |
| 4909 | if (prev_exported != declaration.flags.is_export or decl.analysis == .unreferenced) { | 4953 | if (prev_exported != declaration.flags.is_export or decl.analysis == .unreferenced) { |
| 4910 | log.debug("scanDecl queue analyze_decl file='{s}' decl_name='{}' decl_index={d}", .{ | 4954 | 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, |
| 4912 | }); | 4956 | }); |
| 4913 | comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = decl_index }); | 4957 | comp.work_queue.writeItemAssumeCapacity(.{ .analyze_decl = decl_index }); |
| 4914 | } | 4958 | } |
| ... | @@ -5512,77 +5556,78 @@ fn handleUpdateExports( | ... | @@ -5512,77 +5556,78 @@ fn handleUpdateExports( |
| 5512 | } | 5556 | } |
| 5513 | 5557 | ||
| 5514 | pub fn populateTestFunctions( | 5558 | pub fn populateTestFunctions( |
| 5515 | mod: *Module, | 5559 | zcu: *Zcu, |
| 5516 | main_progress_node: std.Progress.Node, | 5560 | main_progress_node: std.Progress.Node, |
| 5517 | ) !void { | 5561 | ) !void { |
| 5518 | const gpa = mod.gpa; | 5562 | const gpa = zcu.gpa; |
| 5519 | const ip = &mod.intern_pool; | 5563 | const ip = &zcu.intern_pool; |
| 5520 | const builtin_mod = mod.root_mod.getBuiltinDependency(); | 5564 | const builtin_mod = zcu.root_mod.getBuiltinDependency(); |
| 5521 | const builtin_file = (mod.importPkg(builtin_mod) catch unreachable).file; | 5565 | const builtin_file_index = (zcu.importPkg(builtin_mod) catch unreachable).file_index; |
| 5522 | const root_decl = mod.declPtr(builtin_file.root_decl.unwrap().?); | 5566 | const root_decl_index = zcu.fileRootDecl(builtin_file_index); |
| 5523 | const builtin_namespace = mod.namespacePtr(root_decl.src_namespace); | 5567 | const root_decl = zcu.declPtr(root_decl_index.unwrap().?); |
| 5568 | const builtin_namespace = zcu.namespacePtr(root_decl.src_namespace); | ||
| 5524 | const test_functions_str = try ip.getOrPutString(gpa, "test_functions", .no_embedded_nulls); | 5569 | const test_functions_str = try ip.getOrPutString(gpa, "test_functions", .no_embedded_nulls); |
| 5525 | const decl_index = builtin_namespace.decls.getKeyAdapted( | 5570 | const decl_index = builtin_namespace.decls.getKeyAdapted( |
| 5526 | test_functions_str, | 5571 | test_functions_str, |
| 5527 | DeclAdapter{ .zcu = mod }, | 5572 | DeclAdapter{ .zcu = zcu }, |
| 5528 | ).?; | 5573 | ).?; |
| 5529 | { | 5574 | { |
| 5530 | // We have to call `ensureDeclAnalyzed` here in case `builtin.test_functions` | 5575 | // We have to call `ensureDeclAnalyzed` here in case `builtin.test_functions` |
| 5531 | // was not referenced by start code. | 5576 | // 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); |
| 5533 | defer { | 5578 | defer { |
| 5534 | mod.sema_prog_node.end(); | 5579 | zcu.sema_prog_node.end(); |
| 5535 | mod.sema_prog_node = undefined; | 5580 | zcu.sema_prog_node = undefined; |
| 5536 | } | 5581 | } |
| 5537 | try mod.ensureDeclAnalyzed(decl_index); | 5582 | try zcu.ensureDeclAnalyzed(decl_index); |
| 5538 | } | 5583 | } |
| 5539 | 5584 | ||
| 5540 | const decl = mod.declPtr(decl_index); | 5585 | const decl = zcu.declPtr(decl_index); |
| 5541 | const test_fn_ty = decl.typeOf(mod).slicePtrFieldType(mod).childType(mod); | 5586 | const test_fn_ty = decl.typeOf(zcu).slicePtrFieldType(zcu).childType(zcu); |
| 5542 | 5587 | ||
| 5543 | const array_anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl = array: { | 5588 | 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 |
| 5545 | // decl reference it as a slice. | 5590 | // 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()); |
| 5547 | defer gpa.free(test_fn_vals); | 5592 | defer gpa.free(test_fn_vals); |
| 5548 | 5593 | ||
| 5549 | for (test_fn_vals, mod.test_functions.keys()) |*test_fn_val, test_decl_index| { | 5594 | for (test_fn_vals, zcu.test_functions.keys()) |*test_fn_val, test_decl_index| { |
| 5550 | const test_decl = mod.declPtr(test_decl_index); | 5595 | const test_decl = zcu.declPtr(test_decl_index); |
| 5551 | const test_decl_name = try test_decl.fullyQualifiedName(mod); | 5596 | const test_decl_name = try test_decl.fullyQualifiedName(zcu); |
| 5552 | const test_decl_name_len = test_decl_name.length(ip); | 5597 | const test_decl_name_len = test_decl_name.length(ip); |
| 5553 | const test_name_anon_decl: InternPool.Key.Ptr.BaseAddr.AnonDecl = n: { | 5598 | 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(.{ |
| 5555 | .len = test_decl_name_len, | 5600 | .len = test_decl_name_len, |
| 5556 | .child = .u8_type, | 5601 | .child = .u8_type, |
| 5557 | }); | 5602 | }); |
| 5558 | const test_name_val = try mod.intern(.{ .aggregate = .{ | 5603 | const test_name_val = try zcu.intern(.{ .aggregate = .{ |
| 5559 | .ty = test_name_ty.toIntern(), | 5604 | .ty = test_name_ty.toIntern(), |
| 5560 | .storage = .{ .bytes = test_decl_name.toString() }, | 5605 | .storage = .{ .bytes = test_decl_name.toString() }, |
| 5561 | } }); | 5606 | } }); |
| 5562 | break :n .{ | 5607 | break :n .{ |
| 5563 | .orig_ty = (try mod.singleConstPtrType(test_name_ty)).toIntern(), | 5608 | .orig_ty = (try zcu.singleConstPtrType(test_name_ty)).toIntern(), |
| 5564 | .val = test_name_val, | 5609 | .val = test_name_val, |
| 5565 | }; | 5610 | }; |
| 5566 | }; | 5611 | }; |
| 5567 | 5612 | ||
| 5568 | const test_fn_fields = .{ | 5613 | const test_fn_fields = .{ |
| 5569 | // name | 5614 | // name |
| 5570 | try mod.intern(.{ .slice = .{ | 5615 | try zcu.intern(.{ .slice = .{ |
| 5571 | .ty = .slice_const_u8_type, | 5616 | .ty = .slice_const_u8_type, |
| 5572 | .ptr = try mod.intern(.{ .ptr = .{ | 5617 | .ptr = try zcu.intern(.{ .ptr = .{ |
| 5573 | .ty = .manyptr_const_u8_type, | 5618 | .ty = .manyptr_const_u8_type, |
| 5574 | .base_addr = .{ .anon_decl = test_name_anon_decl }, | 5619 | .base_addr = .{ .anon_decl = test_name_anon_decl }, |
| 5575 | .byte_offset = 0, | 5620 | .byte_offset = 0, |
| 5576 | } }), | 5621 | } }), |
| 5577 | .len = try mod.intern(.{ .int = .{ | 5622 | .len = try zcu.intern(.{ .int = .{ |
| 5578 | .ty = .usize_type, | 5623 | .ty = .usize_type, |
| 5579 | .storage = .{ .u64 = test_decl_name_len }, | 5624 | .storage = .{ .u64 = test_decl_name_len }, |
| 5580 | } }), | 5625 | } }), |
| 5581 | } }), | 5626 | } }), |
| 5582 | // func | 5627 | // func |
| 5583 | try mod.intern(.{ .ptr = .{ | 5628 | try zcu.intern(.{ .ptr = .{ |
| 5584 | .ty = try mod.intern(.{ .ptr_type = .{ | 5629 | .ty = try zcu.intern(.{ .ptr_type = .{ |
| 5585 | .child = test_decl.typeOf(mod).toIntern(), | 5630 | .child = test_decl.typeOf(zcu).toIntern(), |
| 5586 | .flags = .{ | 5631 | .flags = .{ |
| 5587 | .is_const = true, | 5632 | .is_const = true, |
| 5588 | }, | 5633 | }, |
| ... | @@ -5591,29 +5636,29 @@ pub fn populateTestFunctions( | ... | @@ -5591,29 +5636,29 @@ pub fn populateTestFunctions( |
| 5591 | .byte_offset = 0, | 5636 | .byte_offset = 0, |
| 5592 | } }), | 5637 | } }), |
| 5593 | }; | 5638 | }; |
| 5594 | test_fn_val.* = try mod.intern(.{ .aggregate = .{ | 5639 | test_fn_val.* = try zcu.intern(.{ .aggregate = .{ |
| 5595 | .ty = test_fn_ty.toIntern(), | 5640 | .ty = test_fn_ty.toIntern(), |
| 5596 | .storage = .{ .elems = &test_fn_fields }, | 5641 | .storage = .{ .elems = &test_fn_fields }, |
| 5597 | } }); | 5642 | } }); |
| 5598 | } | 5643 | } |
| 5599 | 5644 | ||
| 5600 | const array_ty = try mod.arrayType(.{ | 5645 | const array_ty = try zcu.arrayType(.{ |
| 5601 | .len = test_fn_vals.len, | 5646 | .len = test_fn_vals.len, |
| 5602 | .child = test_fn_ty.toIntern(), | 5647 | .child = test_fn_ty.toIntern(), |
| 5603 | .sentinel = .none, | 5648 | .sentinel = .none, |
| 5604 | }); | 5649 | }); |
| 5605 | const array_val = try mod.intern(.{ .aggregate = .{ | 5650 | const array_val = try zcu.intern(.{ .aggregate = .{ |
| 5606 | .ty = array_ty.toIntern(), | 5651 | .ty = array_ty.toIntern(), |
| 5607 | .storage = .{ .elems = test_fn_vals }, | 5652 | .storage = .{ .elems = test_fn_vals }, |
| 5608 | } }); | 5653 | } }); |
| 5609 | break :array .{ | 5654 | break :array .{ |
| 5610 | .orig_ty = (try mod.singleConstPtrType(array_ty)).toIntern(), | 5655 | .orig_ty = (try zcu.singleConstPtrType(array_ty)).toIntern(), |
| 5611 | .val = array_val, | 5656 | .val = array_val, |
| 5612 | }; | 5657 | }; |
| 5613 | }; | 5658 | }; |
| 5614 | 5659 | ||
| 5615 | { | 5660 | { |
| 5616 | const new_ty = try mod.ptrType(.{ | 5661 | const new_ty = try zcu.ptrType(.{ |
| 5617 | .child = test_fn_ty.toIntern(), | 5662 | .child = test_fn_ty.toIntern(), |
| 5618 | .flags = .{ | 5663 | .flags = .{ |
| 5619 | .is_const = true, | 5664 | .is_const = true, |
| ... | @@ -5621,14 +5666,14 @@ pub fn populateTestFunctions( | ... | @@ -5621,14 +5666,14 @@ pub fn populateTestFunctions( |
| 5621 | }, | 5666 | }, |
| 5622 | }); | 5667 | }); |
| 5623 | const new_val = decl.val; | 5668 | const new_val = decl.val; |
| 5624 | const new_init = try mod.intern(.{ .slice = .{ | 5669 | const new_init = try zcu.intern(.{ .slice = .{ |
| 5625 | .ty = new_ty.toIntern(), | 5670 | .ty = new_ty.toIntern(), |
| 5626 | .ptr = try mod.intern(.{ .ptr = .{ | 5671 | .ptr = try zcu.intern(.{ .ptr = .{ |
| 5627 | .ty = new_ty.slicePtrFieldType(mod).toIntern(), | 5672 | .ty = new_ty.slicePtrFieldType(zcu).toIntern(), |
| 5628 | .base_addr = .{ .anon_decl = array_anon_decl }, | 5673 | .base_addr = .{ .anon_decl = array_anon_decl }, |
| 5629 | .byte_offset = 0, | 5674 | .byte_offset = 0, |
| 5630 | } }), | 5675 | } }), |
| 5631 | .len = (try mod.intValue(Type.usize, mod.test_functions.count())).toIntern(), | 5676 | .len = (try zcu.intValue(Type.usize, zcu.test_functions.count())).toIntern(), |
| 5632 | } }); | 5677 | } }); |
| 5633 | ip.mutateVarInit(decl.val.toIntern(), new_init); | 5678 | ip.mutateVarInit(decl.val.toIntern(), new_init); |
| 5634 | 5679 | ||
| ... | @@ -5638,13 +5683,13 @@ pub fn populateTestFunctions( | ... | @@ -5638,13 +5683,13 @@ pub fn populateTestFunctions( |
| 5638 | decl.has_tv = true; | 5683 | decl.has_tv = true; |
| 5639 | } | 5684 | } |
| 5640 | { | 5685 | { |
| 5641 | mod.codegen_prog_node = main_progress_node.start("Code Generation", 0); | 5686 | zcu.codegen_prog_node = main_progress_node.start("Code Generation", 0); |
| 5642 | defer { | 5687 | defer { |
| 5643 | mod.codegen_prog_node.end(); | 5688 | zcu.codegen_prog_node.end(); |
| 5644 | mod.codegen_prog_node = undefined; | 5689 | zcu.codegen_prog_node = undefined; |
| 5645 | } | 5690 | } |
| 5646 | 5691 | ||
| 5647 | try mod.linkerUpdateDecl(decl_index); | 5692 | try zcu.linkerUpdateDecl(decl_index); |
| 5648 | } | 5693 | } |
| 5649 | } | 5694 | } |
| 5650 | 5695 | ||
| ... | @@ -5684,31 +5729,35 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void { | ... | @@ -5684,31 +5729,35 @@ pub fn linkerUpdateDecl(zcu: *Zcu, decl_index: Decl.Index) !void { |
| 5684 | } | 5729 | } |
| 5685 | 5730 | ||
| 5686 | fn reportRetryableFileError( | 5731 | fn reportRetryableFileError( |
| 5687 | mod: *Module, | 5732 | zcu: *Zcu, |
| 5688 | file: *File, | 5733 | file_index: File.Index, |
| 5689 | comptime format: []const u8, | 5734 | comptime format: []const u8, |
| 5690 | args: anytype, | 5735 | args: anytype, |
| 5691 | ) error{OutOfMemory}!void { | 5736 | ) error{OutOfMemory}!void { |
| 5737 | const gpa = zcu.gpa; | ||
| 5738 | const ip = &zcu.intern_pool; | ||
| 5739 | |||
| 5740 | const file = zcu.fileByIndex(file_index); | ||
| 5692 | file.status = .retryable_failure; | 5741 | file.status = .retryable_failure; |
| 5693 | 5742 | ||
| 5694 | const err_msg = try ErrorMsg.create( | 5743 | const err_msg = try ErrorMsg.create( |
| 5695 | mod.gpa, | 5744 | gpa, |
| 5696 | .{ | 5745 | .{ |
| 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), |
| 5698 | .offset = .entire_file, | 5747 | .offset = .entire_file, |
| 5699 | }, | 5748 | }, |
| 5700 | format, | 5749 | format, |
| 5701 | args, | 5750 | args, |
| 5702 | ); | 5751 | ); |
| 5703 | errdefer err_msg.destroy(mod.gpa); | 5752 | errdefer err_msg.destroy(gpa); |
| 5704 | 5753 | ||
| 5705 | mod.comp.mutex.lock(); | 5754 | zcu.comp.mutex.lock(); |
| 5706 | defer mod.comp.mutex.unlock(); | 5755 | defer zcu.comp.mutex.unlock(); |
| 5707 | 5756 | ||
| 5708 | const gop = try mod.failed_files.getOrPut(mod.gpa, file); | 5757 | const gop = try zcu.failed_files.getOrPut(gpa, file); |
| 5709 | if (gop.found_existing) { | 5758 | if (gop.found_existing) { |
| 5710 | if (gop.value_ptr.*) |old_err_msg| { | 5759 | if (gop.value_ptr.*) |old_err_msg| { |
| 5711 | old_err_msg.destroy(mod.gpa); | 5760 | old_err_msg.destroy(gpa); |
| 5712 | } | 5761 | } |
| 5713 | } | 5762 | } |
| 5714 | gop.value_ptr.* = err_msg; | 5763 | gop.value_ptr.* = err_msg; |
| ... | @@ -6528,8 +6577,9 @@ pub fn getBuiltin(zcu: *Zcu, name: []const u8) Allocator.Error!Air.Inst.Ref { | ... | @@ -6528,8 +6577,9 @@ pub fn getBuiltin(zcu: *Zcu, name: []const u8) Allocator.Error!Air.Inst.Ref { |
| 6528 | pub fn getBuiltinDecl(zcu: *Zcu, name: []const u8) Allocator.Error!InternPool.DeclIndex { | 6577 | pub fn getBuiltinDecl(zcu: *Zcu, name: []const u8) Allocator.Error!InternPool.DeclIndex { |
| 6529 | const gpa = zcu.gpa; | 6578 | const gpa = zcu.gpa; |
| 6530 | const ip = &zcu.intern_pool; | 6579 | const ip = &zcu.intern_pool; |
| 6531 | const std_file = (zcu.importPkg(zcu.std_mod) catch @panic("failed to import lib/std.zig")).file; | 6580 | const std_file_imported = zcu.importPkg(zcu.std_mod) catch @panic("failed to import lib/std.zig"); |
| 6532 | const std_namespace = zcu.declPtr(std_file.root_decl.unwrap().?).getOwnedInnerNamespace(zcu).?; | 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).?; | ||
| 6533 | const builtin_str = try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls); | 6583 | const builtin_str = try ip.getOrPutString(gpa, "builtin", .no_embedded_nulls); |
| 6534 | const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Zcu.DeclAdapter{ .zcu = zcu }) orelse @panic("lib/std.zig is corrupt and missing 'builtin'"); | 6584 | const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Zcu.DeclAdapter{ .zcu = zcu }) orelse @panic("lib/std.zig is corrupt and missing 'builtin'"); |
| 6535 | zcu.ensureDeclAnalyzed(builtin_decl) catch @panic("std.builtin is corrupt"); | 6585 | 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 { | ... | @@ -6544,3 +6594,20 @@ pub fn getBuiltinType(zcu: *Zcu, name: []const u8) Allocator.Error!Type { |
| 6544 | ty.resolveFully(zcu) catch @panic("std.builtin is corrupt"); | 6594 | ty.resolveFully(zcu) catch @panic("std.builtin is corrupt"); |
| 6545 | return ty; | 6595 | return ty; |
| 6546 | } | 6596 | } |
| 6597 | |||
| 6598 | pub 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`. | ||
| 6603 | pub fn fileRootDecl(zcu: *const Zcu, i: File.Index) Decl.OptionalIndex { | ||
| 6604 | return zcu.files.values()[@intFromEnum(i)]; | ||
| 6605 | } | ||
| 6606 | |||
| 6607 | pub fn setFileRootDecl(zcu: *Zcu, i: File.Index, root_decl: Decl.OptionalIndex) void { | ||
| 6608 | zcu.files.values()[@intFromEnum(i)] = root_decl; | ||
| 6609 | } | ||
| 6610 | |||
| 6611 | pub 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( | ... | @@ -345,7 +345,7 @@ pub fn generate( |
| 345 | assert(fn_owner_decl.has_tv); | 345 | assert(fn_owner_decl.has_tv); |
| 346 | const fn_type = fn_owner_decl.typeOf(zcu); | 346 | const fn_type = fn_owner_decl.typeOf(zcu); |
| 347 | const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); | 347 | 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; |
| 349 | 349 | ||
| 350 | var branch_stack = std.ArrayList(Branch).init(gpa); | 350 | var branch_stack = std.ArrayList(Branch).init(gpa); |
| 351 | defer { | 351 | defer { |
src/arch/arm/CodeGen.zig+1-1| ... | @@ -352,7 +352,7 @@ pub fn generate( | ... | @@ -352,7 +352,7 @@ pub fn generate( |
| 352 | assert(fn_owner_decl.has_tv); | 352 | assert(fn_owner_decl.has_tv); |
| 353 | const fn_type = fn_owner_decl.typeOf(zcu); | 353 | const fn_type = fn_owner_decl.typeOf(zcu); |
| 354 | const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); | 354 | 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; |
| 356 | 356 | ||
| 357 | var branch_stack = std.ArrayList(Branch).init(gpa); | 357 | var branch_stack = std.ArrayList(Branch).init(gpa); |
| 358 | defer { | 358 | defer { |
src/arch/riscv64/CodeGen.zig+2-2| ... | @@ -712,8 +712,8 @@ pub fn generate( | ... | @@ -712,8 +712,8 @@ pub fn generate( |
| 712 | assert(fn_owner_decl.has_tv); | 712 | assert(fn_owner_decl.has_tv); |
| 713 | const fn_type = fn_owner_decl.typeOf(zcu); | 713 | const fn_type = fn_owner_decl.typeOf(zcu); |
| 714 | const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); | 714 | const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); |
| 715 | const target = &namespace.file_scope.mod.resolved_target.result; | 715 | const target = &namespace.fileScope(zcu).mod.resolved_target.result; |
| 716 | const mod = namespace.file_scope.mod; | 716 | const mod = namespace.fileScope(zcu).mod; |
| 717 | 717 | ||
| 718 | var branch_stack = std.ArrayList(Branch).init(gpa); | 718 | var branch_stack = std.ArrayList(Branch).init(gpa); |
| 719 | defer { | 719 | defer { |
src/arch/sparc64/CodeGen.zig+1-1| ... | @@ -277,7 +277,7 @@ pub fn generate( | ... | @@ -277,7 +277,7 @@ pub fn generate( |
| 277 | assert(fn_owner_decl.has_tv); | 277 | assert(fn_owner_decl.has_tv); |
| 278 | const fn_type = fn_owner_decl.typeOf(zcu); | 278 | const fn_type = fn_owner_decl.typeOf(zcu); |
| 279 | const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); | 279 | 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; |
| 281 | 281 | ||
| 282 | var branch_stack = std.ArrayList(Branch).init(gpa); | 282 | var branch_stack = std.ArrayList(Branch).init(gpa); |
| 283 | defer { | 283 | defer { |
src/arch/wasm/CodeGen.zig+6-6| ... | @@ -1212,11 +1212,11 @@ pub fn generate( | ... | @@ -1212,11 +1212,11 @@ pub fn generate( |
| 1212 | _ = src_loc; | 1212 | _ = src_loc; |
| 1213 | const comp = bin_file.comp; | 1213 | const comp = bin_file.comp; |
| 1214 | const gpa = comp.gpa; | 1214 | const gpa = comp.gpa; |
| 1215 | const mod = comp.module.?; | 1215 | const zcu = comp.module.?; |
| 1216 | const func = mod.funcInfo(func_index); | 1216 | const func = zcu.funcInfo(func_index); |
| 1217 | const decl = mod.declPtr(func.owner_decl); | 1217 | const decl = zcu.declPtr(func.owner_decl); |
| 1218 | const namespace = mod.namespacePtr(decl.src_namespace); | 1218 | const namespace = zcu.namespacePtr(decl.src_namespace); |
| 1219 | const target = namespace.file_scope.mod.resolved_target.result; | 1219 | const target = namespace.fileScope(zcu).mod.resolved_target.result; |
| 1220 | var code_gen: CodeGen = .{ | 1220 | var code_gen: CodeGen = .{ |
| 1221 | .gpa = gpa, | 1221 | .gpa = gpa, |
| 1222 | .air = air, | 1222 | .air = air, |
| ... | @@ -7706,7 +7706,7 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { | ... | @@ -7706,7 +7706,7 @@ fn airFence(func: *CodeGen, inst: Air.Inst.Index) InnerError!void { |
| 7706 | // for a single-threaded build, can we emit the `fence` instruction. | 7706 | // for a single-threaded build, can we emit the `fence` instruction. |
| 7707 | // In all other cases, we emit no instructions for a fence. | 7707 | // In all other cases, we emit no instructions for a fence. |
| 7708 | const func_namespace = zcu.namespacePtr(func.decl.src_namespace); | 7708 | 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; |
| 7710 | if (func.useAtomicFeature() and !single_threaded) { | 7710 | if (func.useAtomicFeature() and !single_threaded) { |
| 7711 | try func.addAtomicTag(.atomic_fence); | 7711 | try func.addAtomicTag(.atomic_fence); |
| 7712 | } | 7712 | } |
src/arch/x86_64/CodeGen.zig+1-1| ... | @@ -810,7 +810,7 @@ pub fn generate( | ... | @@ -810,7 +810,7 @@ pub fn generate( |
| 810 | assert(fn_owner_decl.has_tv); | 810 | assert(fn_owner_decl.has_tv); |
| 811 | const fn_type = fn_owner_decl.typeOf(zcu); | 811 | const fn_type = fn_owner_decl.typeOf(zcu); |
| 812 | const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); | 812 | const namespace = zcu.namespacePtr(fn_owner_decl.src_namespace); |
| 813 | const mod = namespace.file_scope.mod; | 813 | const mod = namespace.fileScope(zcu).mod; |
| 814 | 814 | ||
| 815 | var function = Self{ | 815 | var function = Self{ |
| 816 | .gpa = gpa, | 816 | .gpa = gpa, |
src/codegen.zig+6-6| ... | @@ -58,7 +58,7 @@ pub fn generateFunction( | ... | @@ -58,7 +58,7 @@ pub fn generateFunction( |
| 58 | const func = zcu.funcInfo(func_index); | 58 | const func = zcu.funcInfo(func_index); |
| 59 | const decl = zcu.declPtr(func.owner_decl); | 59 | const decl = zcu.declPtr(func.owner_decl); |
| 60 | const namespace = zcu.namespacePtr(decl.src_namespace); | 60 | 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; |
| 62 | switch (target.cpu.arch) { | 62 | switch (target.cpu.arch) { |
| 63 | .arm, | 63 | .arm, |
| 64 | .armeb, | 64 | .armeb, |
| ... | @@ -88,7 +88,7 @@ pub fn generateLazyFunction( | ... | @@ -88,7 +88,7 @@ pub fn generateLazyFunction( |
| 88 | const decl_index = lazy_sym.ty.getOwnerDecl(zcu); | 88 | const decl_index = lazy_sym.ty.getOwnerDecl(zcu); |
| 89 | const decl = zcu.declPtr(decl_index); | 89 | const decl = zcu.declPtr(decl_index); |
| 90 | const namespace = zcu.namespacePtr(decl.src_namespace); | 90 | 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; |
| 92 | switch (target.cpu.arch) { | 92 | switch (target.cpu.arch) { |
| 93 | .x86_64 => return @import("arch/x86_64/CodeGen.zig").generateLazy(lf, src_loc, lazy_sym, code, debug_output), | 93 | .x86_64 => return @import("arch/x86_64/CodeGen.zig").generateLazy(lf, src_loc, lazy_sym, code, debug_output), |
| 94 | else => unreachable, | 94 | else => unreachable, |
| ... | @@ -742,7 +742,7 @@ fn lowerDeclRef( | ... | @@ -742,7 +742,7 @@ fn lowerDeclRef( |
| 742 | const zcu = lf.comp.module.?; | 742 | const zcu = lf.comp.module.?; |
| 743 | const decl = zcu.declPtr(decl_index); | 743 | const decl = zcu.declPtr(decl_index); |
| 744 | const namespace = zcu.namespacePtr(decl.src_namespace); | 744 | 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; |
| 746 | 746 | ||
| 747 | const ptr_width = target.ptrBitWidth(); | 747 | const ptr_width = target.ptrBitWidth(); |
| 748 | const is_fn_body = decl.typeOf(zcu).zigTypeTag(zcu) == .Fn; | 748 | const is_fn_body = decl.typeOf(zcu).zigTypeTag(zcu) == .Fn; |
| ... | @@ -836,7 +836,7 @@ fn genDeclRef( | ... | @@ -836,7 +836,7 @@ fn genDeclRef( |
| 836 | 836 | ||
| 837 | const ptr_decl = zcu.declPtr(ptr_decl_index); | 837 | const ptr_decl = zcu.declPtr(ptr_decl_index); |
| 838 | const namespace = zcu.namespacePtr(ptr_decl.src_namespace); | 838 | 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; |
| 840 | 840 | ||
| 841 | const ptr_bits = target.ptrBitWidth(); | 841 | const ptr_bits = target.ptrBitWidth(); |
| 842 | const ptr_bytes: u64 = @divExact(ptr_bits, 8); | 842 | const ptr_bytes: u64 = @divExact(ptr_bits, 8); |
| ... | @@ -875,7 +875,7 @@ fn genDeclRef( | ... | @@ -875,7 +875,7 @@ fn genDeclRef( |
| 875 | } | 875 | } |
| 876 | 876 | ||
| 877 | const decl_namespace = zcu.namespacePtr(decl.src_namespace); | 877 | 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; |
| 879 | const is_threadlocal = val.isPtrToThreadLocal(zcu) and !single_threaded; | 879 | const is_threadlocal = val.isPtrToThreadLocal(zcu) and !single_threaded; |
| 880 | const is_extern = decl.isExtern(zcu); | 880 | const is_extern = decl.isExtern(zcu); |
| 881 | 881 | ||
| ... | @@ -985,7 +985,7 @@ pub fn genTypedValue( | ... | @@ -985,7 +985,7 @@ pub fn genTypedValue( |
| 985 | 985 | ||
| 986 | const owner_decl = zcu.declPtr(owner_decl_index); | 986 | const owner_decl = zcu.declPtr(owner_decl_index); |
| 987 | const namespace = zcu.namespacePtr(owner_decl.src_namespace); | 987 | 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; |
| 989 | const ptr_bits = target.ptrBitWidth(); | 989 | const ptr_bits = target.ptrBitWidth(); |
| 990 | 990 | ||
| 991 | if (!ty.isSlice(zcu)) switch (ip.indexToKey(val.toIntern())) { | 991 | if (!ty.isSlice(zcu)) switch (ip.indexToKey(val.toIntern())) { |
src/codegen/c.zig+1-1| ... | @@ -2581,7 +2581,7 @@ pub fn genTypeDecl( | ... | @@ -2581,7 +2581,7 @@ pub fn genTypeDecl( |
| 2581 | _ = try renderTypePrefix(.flush, global_ctype_pool, zcu, writer, global_ctype, .suffix, .{}); | 2581 | _ = try renderTypePrefix(.flush, global_ctype_pool, zcu, writer, global_ctype, .suffix, .{}); |
| 2582 | try writer.writeByte(';'); | 2582 | try writer.writeByte(';'); |
| 2583 | const owner_decl = zcu.declPtr(owner_decl_index); | 2583 | 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; |
| 2585 | if (!owner_mod.strip) { | 2585 | if (!owner_mod.strip) { |
| 2586 | try writer.writeAll(" /* "); | 2586 | try writer.writeAll(" /* "); |
| 2587 | try owner_decl.renderFullyQualifiedName(zcu, writer); | 2587 | try owner_decl.renderFullyQualifiedName(zcu, writer); |
src/codegen/llvm.zig+150-141| ... | @@ -1362,7 +1362,8 @@ pub const Object = struct { | ... | @@ -1362,7 +1362,8 @@ pub const Object = struct { |
| 1362 | const decl_index = func.owner_decl; | 1362 | const decl_index = func.owner_decl; |
| 1363 | const decl = zcu.declPtr(decl_index); | 1363 | const decl = zcu.declPtr(decl_index); |
| 1364 | const namespace = zcu.namespacePtr(decl.src_namespace); | 1364 | 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; | ||
| 1366 | const fn_info = zcu.typeToFunc(decl.typeOf(zcu)).?; | 1367 | const fn_info = zcu.typeToFunc(decl.typeOf(zcu)).?; |
| 1367 | const target = owner_mod.resolved_target.result; | 1368 | const target = owner_mod.resolved_target.result; |
| 1368 | const ip = &zcu.intern_pool; | 1369 | const ip = &zcu.intern_pool; |
| ... | @@ -1633,7 +1634,7 @@ pub const Object = struct { | ... | @@ -1633,7 +1634,7 @@ pub const Object = struct { |
| 1633 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); | 1634 | function_index.setAttributes(try attributes.finish(&o.builder), &o.builder); |
| 1634 | 1635 | ||
| 1635 | const file, const subprogram = if (!wip.strip) debug_info: { | 1636 | 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); |
| 1637 | 1638 | ||
| 1638 | const line_number = decl.navSrcLine(zcu) + 1; | 1639 | const line_number = decl.navSrcLine(zcu) + 1; |
| 1639 | const is_internal_linkage = decl.val.getExternFunc(zcu) == null; | 1640 | const is_internal_linkage = decl.val.getExternFunc(zcu) == null; |
| ... | @@ -1720,23 +1721,23 @@ pub const Object = struct { | ... | @@ -1720,23 +1721,23 @@ pub const Object = struct { |
| 1720 | 1721 | ||
| 1721 | pub fn updateExports( | 1722 | pub fn updateExports( |
| 1722 | self: *Object, | 1723 | self: *Object, |
| 1723 | mod: *Module, | 1724 | zcu: *Zcu, |
| 1724 | exported: Module.Exported, | 1725 | exported: Module.Exported, |
| 1725 | export_indices: []const u32, | 1726 | export_indices: []const u32, |
| 1726 | ) link.File.UpdateExportsError!void { | 1727 | ) link.File.UpdateExportsError!void { |
| 1727 | const decl_index = switch (exported) { | 1728 | const decl_index = switch (exported) { |
| 1728 | .decl_index => |i| i, | 1729 | .decl_index => |i| i, |
| 1729 | .value => |val| return updateExportedValue(self, mod, val, export_indices), | 1730 | .value => |val| return updateExportedValue(self, zcu, val, export_indices), |
| 1730 | }; | 1731 | }; |
| 1731 | const ip = &mod.intern_pool; | 1732 | const ip = &zcu.intern_pool; |
| 1732 | const global_index = self.decl_map.get(decl_index).?; | 1733 | const global_index = self.decl_map.get(decl_index).?; |
| 1733 | const decl = mod.declPtr(decl_index); | 1734 | const decl = zcu.declPtr(decl_index); |
| 1734 | const comp = mod.comp; | 1735 | const comp = zcu.comp; |
| 1735 | 1736 | ||
| 1736 | if (export_indices.len != 0) { | 1737 | if (export_indices.len != 0) { |
| 1737 | return updateExportedGlobal(self, mod, global_index, export_indices); | 1738 | return updateExportedGlobal(self, zcu, global_index, export_indices); |
| 1738 | } else { | 1739 | } 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)); |
| 1740 | try global_index.rename(fqn, &self.builder); | 1741 | try global_index.rename(fqn, &self.builder); |
| 1741 | global_index.setLinkage(.internal, &self.builder); | 1742 | global_index.setLinkage(.internal, &self.builder); |
| 1742 | if (comp.config.dll_export_fns) | 1743 | if (comp.config.dll_export_fns) |
| ... | @@ -1908,12 +1909,12 @@ pub const Object = struct { | ... | @@ -1908,12 +1909,12 @@ pub const Object = struct { |
| 1908 | 1909 | ||
| 1909 | const gpa = o.gpa; | 1910 | const gpa = o.gpa; |
| 1910 | const target = o.target; | 1911 | const target = o.target; |
| 1911 | const mod = o.module; | 1912 | const zcu = o.module; |
| 1912 | const ip = &mod.intern_pool; | 1913 | const ip = &zcu.intern_pool; |
| 1913 | 1914 | ||
| 1914 | if (o.debug_type_map.get(ty)) |debug_type| return debug_type; | 1915 | if (o.debug_type_map.get(ty)) |debug_type| return debug_type; |
| 1915 | 1916 | ||
| 1916 | switch (ty.zigTypeTag(mod)) { | 1917 | switch (ty.zigTypeTag(zcu)) { |
| 1917 | .Void, | 1918 | .Void, |
| 1918 | .NoReturn, | 1919 | .NoReturn, |
| 1919 | => { | 1920 | => { |
| ... | @@ -1925,12 +1926,12 @@ pub const Object = struct { | ... | @@ -1925,12 +1926,12 @@ pub const Object = struct { |
| 1925 | return debug_void_type; | 1926 | return debug_void_type; |
| 1926 | }, | 1927 | }, |
| 1927 | .Int => { | 1928 | .Int => { |
| 1928 | const info = ty.intInfo(mod); | 1929 | const info = ty.intInfo(zcu); |
| 1929 | assert(info.bits != 0); | 1930 | assert(info.bits != 0); |
| 1930 | const name = try o.allocTypeName(ty); | 1931 | const name = try o.allocTypeName(ty); |
| 1931 | defer gpa.free(name); | 1932 | defer gpa.free(name); |
| 1932 | const builder_name = try o.builder.metadataString(name); | 1933 | 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 |
| 1934 | const debug_int_type = switch (info.signedness) { | 1935 | const debug_int_type = switch (info.signedness) { |
| 1935 | .signed => try o.builder.debugSignedType(builder_name, debug_bits), | 1936 | .signed => try o.builder.debugSignedType(builder_name, debug_bits), |
| 1936 | .unsigned => try o.builder.debugUnsignedType(builder_name, debug_bits), | 1937 | .unsigned => try o.builder.debugUnsignedType(builder_name, debug_bits), |
| ... | @@ -1939,10 +1940,10 @@ pub const Object = struct { | ... | @@ -1939,10 +1940,10 @@ pub const Object = struct { |
| 1939 | return debug_int_type; | 1940 | return debug_int_type; |
| 1940 | }, | 1941 | }, |
| 1941 | .Enum => { | 1942 | .Enum => { |
| 1942 | const owner_decl_index = ty.getOwnerDecl(mod); | 1943 | const owner_decl_index = ty.getOwnerDecl(zcu); |
| 1943 | const owner_decl = o.module.declPtr(owner_decl_index); | 1944 | const owner_decl = o.module.declPtr(owner_decl_index); |
| 1944 | 1945 | ||
| 1945 | if (!ty.hasRuntimeBitsIgnoreComptime(mod)) { | 1946 | if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 1946 | const debug_enum_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); | 1947 | const debug_enum_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); |
| 1947 | try o.debug_type_map.put(gpa, ty, debug_enum_type); | 1948 | try o.debug_type_map.put(gpa, ty, debug_enum_type); |
| 1948 | return debug_enum_type; | 1949 | return debug_enum_type; |
| ... | @@ -1954,13 +1955,13 @@ pub const Object = struct { | ... | @@ -1954,13 +1955,13 @@ pub const Object = struct { |
| 1954 | defer gpa.free(enumerators); | 1955 | defer gpa.free(enumerators); |
| 1955 | 1956 | ||
| 1956 | const int_ty = Type.fromInterned(enum_type.tag_ty); | 1957 | const int_ty = Type.fromInterned(enum_type.tag_ty); |
| 1957 | const int_info = ty.intInfo(mod); | 1958 | const int_info = ty.intInfo(zcu); |
| 1958 | assert(int_info.bits != 0); | 1959 | assert(int_info.bits != 0); |
| 1959 | 1960 | ||
| 1960 | for (enum_type.names.get(ip), 0..) |field_name_ip, i| { | 1961 | for (enum_type.names.get(ip), 0..) |field_name_ip, i| { |
| 1961 | var bigint_space: Value.BigIntSpace = undefined; | 1962 | var bigint_space: Value.BigIntSpace = undefined; |
| 1962 | const bigint = if (enum_type.values.len != 0) | 1963 | 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) |
| 1964 | else | 1965 | else |
| 1965 | std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst(); | 1966 | std.math.big.int.Mutable.init(&bigint_space.limbs, i).toConst(); |
| 1966 | 1967 | ||
| ... | @@ -1972,7 +1973,8 @@ pub const Object = struct { | ... | @@ -1972,7 +1973,8 @@ pub const Object = struct { |
| 1972 | ); | 1973 | ); |
| 1973 | } | 1974 | } |
| 1974 | 1975 | ||
| 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); | ||
| 1976 | const scope = try o.namespaceToDebugScope(owner_decl.src_namespace); | 1978 | const scope = try o.namespaceToDebugScope(owner_decl.src_namespace); |
| 1977 | 1979 | ||
| 1978 | const name = try o.allocTypeName(ty); | 1980 | const name = try o.allocTypeName(ty); |
| ... | @@ -1982,10 +1984,10 @@ pub const Object = struct { | ... | @@ -1982,10 +1984,10 @@ pub const Object = struct { |
| 1982 | try o.builder.metadataString(name), | 1984 | try o.builder.metadataString(name), |
| 1983 | file, | 1985 | file, |
| 1984 | scope, | 1986 | scope, |
| 1985 | owner_decl.typeSrcLine(mod) + 1, // Line | 1987 | owner_decl.typeSrcLine(zcu) + 1, // Line |
| 1986 | try o.lowerDebugType(int_ty), | 1988 | try o.lowerDebugType(int_ty), |
| 1987 | ty.abiSize(mod) * 8, | 1989 | ty.abiSize(zcu) * 8, |
| 1988 | (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8, | 1990 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 1989 | try o.builder.debugTuple(enumerators), | 1991 | try o.builder.debugTuple(enumerators), |
| 1990 | ); | 1992 | ); |
| 1991 | 1993 | ||
| ... | @@ -2014,7 +2016,7 @@ pub const Object = struct { | ... | @@ -2014,7 +2016,7 @@ pub const Object = struct { |
| 2014 | }, | 2016 | }, |
| 2015 | .Pointer => { | 2017 | .Pointer => { |
| 2016 | // Normalize everything that the debug info does not represent. | 2018 | // Normalize everything that the debug info does not represent. |
| 2017 | const ptr_info = ty.ptrInfo(mod); | 2019 | const ptr_info = ty.ptrInfo(zcu); |
| 2018 | 2020 | ||
| 2019 | if (ptr_info.sentinel != .none or | 2021 | if (ptr_info.sentinel != .none or |
| 2020 | ptr_info.flags.address_space != .generic or | 2022 | ptr_info.flags.address_space != .generic or |
| ... | @@ -2025,10 +2027,10 @@ pub const Object = struct { | ... | @@ -2025,10 +2027,10 @@ pub const Object = struct { |
| 2025 | ptr_info.flags.is_const or | 2027 | ptr_info.flags.is_const or |
| 2026 | ptr_info.flags.is_volatile or | 2028 | ptr_info.flags.is_volatile or |
| 2027 | ptr_info.flags.size == .Many or ptr_info.flags.size == .C or | 2029 | 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)) |
| 2029 | { | 2031 | { |
| 2030 | const bland_ptr_ty = try mod.ptrType(.{ | 2032 | const bland_ptr_ty = try zcu.ptrType(.{ |
| 2031 | .child = if (!Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(mod)) | 2033 | .child = if (!Type.fromInterned(ptr_info.child).hasRuntimeBitsIgnoreComptime(zcu)) |
| 2032 | .anyopaque_type | 2034 | .anyopaque_type |
| 2033 | else | 2035 | else |
| 2034 | ptr_info.child, | 2036 | ptr_info.child, |
| ... | @@ -2050,18 +2052,18 @@ pub const Object = struct { | ... | @@ -2050,18 +2052,18 @@ pub const Object = struct { |
| 2050 | // Set as forward reference while the type is lowered in case it references itself | 2052 | // Set as forward reference while the type is lowered in case it references itself |
| 2051 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); | 2053 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); |
| 2052 | 2054 | ||
| 2053 | if (ty.isSlice(mod)) { | 2055 | if (ty.isSlice(zcu)) { |
| 2054 | const ptr_ty = ty.slicePtrFieldType(mod); | 2056 | const ptr_ty = ty.slicePtrFieldType(zcu); |
| 2055 | const len_ty = Type.usize; | 2057 | const len_ty = Type.usize; |
| 2056 | 2058 | ||
| 2057 | const name = try o.allocTypeName(ty); | 2059 | const name = try o.allocTypeName(ty); |
| 2058 | defer gpa.free(name); | 2060 | defer gpa.free(name); |
| 2059 | const line = 0; | 2061 | const line = 0; |
| 2060 | 2062 | ||
| 2061 | const ptr_size = ptr_ty.abiSize(mod); | 2063 | const ptr_size = ptr_ty.abiSize(zcu); |
| 2062 | const ptr_align = ptr_ty.abiAlignment(mod); | 2064 | const ptr_align = ptr_ty.abiAlignment(zcu); |
| 2063 | const len_size = len_ty.abiSize(mod); | 2065 | const len_size = len_ty.abiSize(zcu); |
| 2064 | const len_align = len_ty.abiAlignment(mod); | 2066 | const len_align = len_ty.abiAlignment(zcu); |
| 2065 | 2067 | ||
| 2066 | const len_offset = len_align.forward(ptr_size); | 2068 | const len_offset = len_align.forward(ptr_size); |
| 2067 | 2069 | ||
| ... | @@ -2093,8 +2095,8 @@ pub const Object = struct { | ... | @@ -2093,8 +2095,8 @@ pub const Object = struct { |
| 2093 | o.debug_compile_unit, // Scope | 2095 | o.debug_compile_unit, // Scope |
| 2094 | line, | 2096 | line, |
| 2095 | .none, // Underlying type | 2097 | .none, // Underlying type |
| 2096 | ty.abiSize(mod) * 8, | 2098 | ty.abiSize(zcu) * 8, |
| 2097 | (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8, | 2099 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2098 | try o.builder.debugTuple(&.{ | 2100 | try o.builder.debugTuple(&.{ |
| 2099 | debug_ptr_type, | 2101 | debug_ptr_type, |
| 2100 | debug_len_type, | 2102 | debug_len_type, |
| ... | @@ -2122,7 +2124,7 @@ pub const Object = struct { | ... | @@ -2122,7 +2124,7 @@ pub const Object = struct { |
| 2122 | 0, // Line | 2124 | 0, // Line |
| 2123 | debug_elem_ty, | 2125 | debug_elem_ty, |
| 2124 | target.ptrBitWidth(), | 2126 | target.ptrBitWidth(), |
| 2125 | (ty.ptrAlignment(mod).toByteUnits() orelse 0) * 8, | 2127 | (ty.ptrAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2126 | 0, // Offset | 2128 | 0, // Offset |
| 2127 | ); | 2129 | ); |
| 2128 | 2130 | ||
| ... | @@ -2146,13 +2148,14 @@ pub const Object = struct { | ... | @@ -2146,13 +2148,14 @@ pub const Object = struct { |
| 2146 | 2148 | ||
| 2147 | const name = try o.allocTypeName(ty); | 2149 | const name = try o.allocTypeName(ty); |
| 2148 | defer gpa.free(name); | 2150 | defer gpa.free(name); |
| 2149 | const owner_decl_index = ty.getOwnerDecl(mod); | 2151 | const owner_decl_index = ty.getOwnerDecl(zcu); |
| 2150 | const owner_decl = o.module.declPtr(owner_decl_index); | 2152 | const owner_decl = o.module.declPtr(owner_decl_index); |
| 2153 | const file_scope = zcu.namespacePtr(owner_decl.src_namespace).fileScope(zcu); | ||
| 2151 | const debug_opaque_type = try o.builder.debugStructType( | 2154 | const debug_opaque_type = try o.builder.debugStructType( |
| 2152 | try o.builder.metadataString(name), | 2155 | try o.builder.metadataString(name), |
| 2153 | try o.getDebugFile(mod.namespacePtr(owner_decl.src_namespace).file_scope), | 2156 | try o.getDebugFile(file_scope), |
| 2154 | try o.namespaceToDebugScope(owner_decl.src_namespace), | 2157 | try o.namespaceToDebugScope(owner_decl.src_namespace), |
| 2155 | owner_decl.typeSrcLine(mod) + 1, // Line | 2158 | owner_decl.typeSrcLine(zcu) + 1, // Line |
| 2156 | .none, // Underlying type | 2159 | .none, // Underlying type |
| 2157 | 0, // Size | 2160 | 0, // Size |
| 2158 | 0, // Align | 2161 | 0, // Align |
| ... | @@ -2167,13 +2170,13 @@ pub const Object = struct { | ... | @@ -2167,13 +2170,13 @@ pub const Object = struct { |
| 2167 | .none, // File | 2170 | .none, // File |
| 2168 | .none, // Scope | 2171 | .none, // Scope |
| 2169 | 0, // Line | 2172 | 0, // Line |
| 2170 | try o.lowerDebugType(ty.childType(mod)), | 2173 | try o.lowerDebugType(ty.childType(zcu)), |
| 2171 | ty.abiSize(mod) * 8, | 2174 | ty.abiSize(zcu) * 8, |
| 2172 | (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8, | 2175 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2173 | try o.builder.debugTuple(&.{ | 2176 | try o.builder.debugTuple(&.{ |
| 2174 | try o.builder.debugSubrange( | 2177 | try o.builder.debugSubrange( |
| 2175 | try o.builder.debugConstant(try o.builder.intConst(.i64, 0)), | 2178 | 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))), |
| 2177 | ), | 2180 | ), |
| 2178 | }), | 2181 | }), |
| 2179 | ); | 2182 | ); |
| ... | @@ -2181,14 +2184,14 @@ pub const Object = struct { | ... | @@ -2181,14 +2184,14 @@ pub const Object = struct { |
| 2181 | return debug_array_type; | 2184 | return debug_array_type; |
| 2182 | }, | 2185 | }, |
| 2183 | .Vector => { | 2186 | .Vector => { |
| 2184 | const elem_ty = ty.elemType2(mod); | 2187 | const elem_ty = ty.elemType2(zcu); |
| 2185 | // Vector elements cannot be padded since that would make | 2188 | // Vector elements cannot be padded since that would make |
| 2186 | // @bitSizOf(elem) * len > @bitSizOf(vec). | 2189 | // @bitSizOf(elem) * len > @bitSizOf(vec). |
| 2187 | // Neither gdb nor lldb seem to be able to display non-byte sized | 2190 | // Neither gdb nor lldb seem to be able to display non-byte sized |
| 2188 | // vectors properly. | 2191 | // vectors properly. |
| 2189 | const debug_elem_type = switch (elem_ty.zigTypeTag(mod)) { | 2192 | const debug_elem_type = switch (elem_ty.zigTypeTag(zcu)) { |
| 2190 | .Int => blk: { | 2193 | .Int => blk: { |
| 2191 | const info = elem_ty.intInfo(mod); | 2194 | const info = elem_ty.intInfo(zcu); |
| 2192 | assert(info.bits != 0); | 2195 | assert(info.bits != 0); |
| 2193 | const name = try o.allocTypeName(ty); | 2196 | const name = try o.allocTypeName(ty); |
| 2194 | defer gpa.free(name); | 2197 | defer gpa.free(name); |
| ... | @@ -2202,7 +2205,7 @@ pub const Object = struct { | ... | @@ -2202,7 +2205,7 @@ pub const Object = struct { |
| 2202 | try o.builder.metadataString("bool"), | 2205 | try o.builder.metadataString("bool"), |
| 2203 | 1, | 2206 | 1, |
| 2204 | ), | 2207 | ), |
| 2205 | else => try o.lowerDebugType(ty.childType(mod)), | 2208 | else => try o.lowerDebugType(ty.childType(zcu)), |
| 2206 | }; | 2209 | }; |
| 2207 | 2210 | ||
| 2208 | const debug_vector_type = try o.builder.debugVectorType( | 2211 | const debug_vector_type = try o.builder.debugVectorType( |
| ... | @@ -2211,12 +2214,12 @@ pub const Object = struct { | ... | @@ -2211,12 +2214,12 @@ pub const Object = struct { |
| 2211 | .none, // Scope | 2214 | .none, // Scope |
| 2212 | 0, // Line | 2215 | 0, // Line |
| 2213 | debug_elem_type, | 2216 | debug_elem_type, |
| 2214 | ty.abiSize(mod) * 8, | 2217 | ty.abiSize(zcu) * 8, |
| 2215 | (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8, | 2218 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2216 | try o.builder.debugTuple(&.{ | 2219 | try o.builder.debugTuple(&.{ |
| 2217 | try o.builder.debugSubrange( | 2220 | try o.builder.debugSubrange( |
| 2218 | try o.builder.debugConstant(try o.builder.intConst(.i64, 0)), | 2221 | 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))), |
| 2220 | ), | 2223 | ), |
| 2221 | }), | 2224 | }), |
| 2222 | ); | 2225 | ); |
| ... | @@ -2227,8 +2230,8 @@ pub const Object = struct { | ... | @@ -2227,8 +2230,8 @@ pub const Object = struct { |
| 2227 | .Optional => { | 2230 | .Optional => { |
| 2228 | const name = try o.allocTypeName(ty); | 2231 | const name = try o.allocTypeName(ty); |
| 2229 | defer gpa.free(name); | 2232 | defer gpa.free(name); |
| 2230 | const child_ty = ty.optionalChild(mod); | 2233 | const child_ty = ty.optionalChild(zcu); |
| 2231 | if (!child_ty.hasRuntimeBitsIgnoreComptime(mod)) { | 2234 | if (!child_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2232 | const debug_bool_type = try o.builder.debugBoolType( | 2235 | const debug_bool_type = try o.builder.debugBoolType( |
| 2233 | try o.builder.metadataString(name), | 2236 | try o.builder.metadataString(name), |
| 2234 | 8, | 2237 | 8, |
| ... | @@ -2242,7 +2245,7 @@ pub const Object = struct { | ... | @@ -2242,7 +2245,7 @@ pub const Object = struct { |
| 2242 | // Set as forward reference while the type is lowered in case it references itself | 2245 | // Set as forward reference while the type is lowered in case it references itself |
| 2243 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); | 2246 | try o.debug_type_map.put(gpa, ty, debug_fwd_ref); |
| 2244 | 2247 | ||
| 2245 | if (ty.optionalReprIsPayload(mod)) { | 2248 | if (ty.optionalReprIsPayload(zcu)) { |
| 2246 | const debug_optional_type = try o.lowerDebugType(child_ty); | 2249 | const debug_optional_type = try o.lowerDebugType(child_ty); |
| 2247 | 2250 | ||
| 2248 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); | 2251 | o.builder.debugForwardReferenceSetType(debug_fwd_ref, debug_optional_type); |
| ... | @@ -2255,10 +2258,10 @@ pub const Object = struct { | ... | @@ -2255,10 +2258,10 @@ pub const Object = struct { |
| 2255 | } | 2258 | } |
| 2256 | 2259 | ||
| 2257 | const non_null_ty = Type.u8; | 2260 | const non_null_ty = Type.u8; |
| 2258 | const payload_size = child_ty.abiSize(mod); | 2261 | const payload_size = child_ty.abiSize(zcu); |
| 2259 | const payload_align = child_ty.abiAlignment(mod); | 2262 | const payload_align = child_ty.abiAlignment(zcu); |
| 2260 | const non_null_size = non_null_ty.abiSize(mod); | 2263 | const non_null_size = non_null_ty.abiSize(zcu); |
| 2261 | const non_null_align = non_null_ty.abiAlignment(mod); | 2264 | const non_null_align = non_null_ty.abiAlignment(zcu); |
| 2262 | const non_null_offset = non_null_align.forward(payload_size); | 2265 | const non_null_offset = non_null_align.forward(payload_size); |
| 2263 | 2266 | ||
| 2264 | const debug_data_type = try o.builder.debugMemberType( | 2267 | const debug_data_type = try o.builder.debugMemberType( |
| ... | @@ -2289,8 +2292,8 @@ pub const Object = struct { | ... | @@ -2289,8 +2292,8 @@ pub const Object = struct { |
| 2289 | o.debug_compile_unit, // Scope | 2292 | o.debug_compile_unit, // Scope |
| 2290 | 0, // Line | 2293 | 0, // Line |
| 2291 | .none, // Underlying type | 2294 | .none, // Underlying type |
| 2292 | ty.abiSize(mod) * 8, | 2295 | ty.abiSize(zcu) * 8, |
| 2293 | (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8, | 2296 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2294 | try o.builder.debugTuple(&.{ | 2297 | try o.builder.debugTuple(&.{ |
| 2295 | debug_data_type, | 2298 | debug_data_type, |
| 2296 | debug_some_type, | 2299 | debug_some_type, |
| ... | @@ -2306,8 +2309,8 @@ pub const Object = struct { | ... | @@ -2306,8 +2309,8 @@ pub const Object = struct { |
| 2306 | return debug_optional_type; | 2309 | return debug_optional_type; |
| 2307 | }, | 2310 | }, |
| 2308 | .ErrorUnion => { | 2311 | .ErrorUnion => { |
| 2309 | const payload_ty = ty.errorUnionPayload(mod); | 2312 | const payload_ty = ty.errorUnionPayload(zcu); |
| 2310 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) { | 2313 | if (!payload_ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2311 | // TODO: Maybe remove? | 2314 | // TODO: Maybe remove? |
| 2312 | const debug_error_union_type = try o.lowerDebugType(Type.anyerror); | 2315 | const debug_error_union_type = try o.lowerDebugType(Type.anyerror); |
| 2313 | try o.debug_type_map.put(gpa, ty, debug_error_union_type); | 2316 | try o.debug_type_map.put(gpa, ty, debug_error_union_type); |
| ... | @@ -2317,10 +2320,10 @@ pub const Object = struct { | ... | @@ -2317,10 +2320,10 @@ pub const Object = struct { |
| 2317 | const name = try o.allocTypeName(ty); | 2320 | const name = try o.allocTypeName(ty); |
| 2318 | defer gpa.free(name); | 2321 | defer gpa.free(name); |
| 2319 | 2322 | ||
| 2320 | const error_size = Type.anyerror.abiSize(mod); | 2323 | const error_size = Type.anyerror.abiSize(zcu); |
| 2321 | const error_align = Type.anyerror.abiAlignment(mod); | 2324 | const error_align = Type.anyerror.abiAlignment(zcu); |
| 2322 | const payload_size = payload_ty.abiSize(mod); | 2325 | const payload_size = payload_ty.abiSize(zcu); |
| 2323 | const payload_align = payload_ty.abiAlignment(mod); | 2326 | const payload_align = payload_ty.abiAlignment(zcu); |
| 2324 | 2327 | ||
| 2325 | var error_index: u32 = undefined; | 2328 | var error_index: u32 = undefined; |
| 2326 | var payload_index: u32 = undefined; | 2329 | var payload_index: u32 = undefined; |
| ... | @@ -2368,8 +2371,8 @@ pub const Object = struct { | ... | @@ -2368,8 +2371,8 @@ pub const Object = struct { |
| 2368 | o.debug_compile_unit, // Sope | 2371 | o.debug_compile_unit, // Sope |
| 2369 | 0, // Line | 2372 | 0, // Line |
| 2370 | .none, // Underlying type | 2373 | .none, // Underlying type |
| 2371 | ty.abiSize(mod) * 8, | 2374 | ty.abiSize(zcu) * 8, |
| 2372 | (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8, | 2375 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2373 | try o.builder.debugTuple(&fields), | 2376 | try o.builder.debugTuple(&fields), |
| 2374 | ); | 2377 | ); |
| 2375 | 2378 | ||
| ... | @@ -2390,14 +2393,14 @@ pub const Object = struct { | ... | @@ -2390,14 +2393,14 @@ pub const Object = struct { |
| 2390 | const name = try o.allocTypeName(ty); | 2393 | const name = try o.allocTypeName(ty); |
| 2391 | defer gpa.free(name); | 2394 | defer gpa.free(name); |
| 2392 | 2395 | ||
| 2393 | if (mod.typeToPackedStruct(ty)) |struct_type| { | 2396 | if (zcu.typeToPackedStruct(ty)) |struct_type| { |
| 2394 | const backing_int_ty = struct_type.backingIntType(ip).*; | 2397 | const backing_int_ty = struct_type.backingIntType(ip).*; |
| 2395 | if (backing_int_ty != .none) { | 2398 | 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); |
| 2397 | const builder_name = try o.builder.metadataString(name); | 2400 | const builder_name = try o.builder.metadataString(name); |
| 2398 | const debug_int_type = switch (info.signedness) { | 2401 | const debug_int_type = switch (info.signedness) { |
| 2399 | .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(mod) * 8), | 2402 | .signed => try o.builder.debugSignedType(builder_name, ty.abiSize(zcu) * 8), |
| 2400 | .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(mod) * 8), | 2403 | .unsigned => try o.builder.debugUnsignedType(builder_name, ty.abiSize(zcu) * 8), |
| 2401 | }; | 2404 | }; |
| 2402 | try o.debug_type_map.put(gpa, ty, debug_int_type); | 2405 | try o.debug_type_map.put(gpa, ty, debug_int_type); |
| 2403 | return debug_int_type; | 2406 | return debug_int_type; |
| ... | @@ -2417,10 +2420,10 @@ pub const Object = struct { | ... | @@ -2417,10 +2420,10 @@ pub const Object = struct { |
| 2417 | const debug_fwd_ref = try o.builder.debugForwardReference(); | 2420 | const debug_fwd_ref = try o.builder.debugForwardReference(); |
| 2418 | 2421 | ||
| 2419 | for (tuple.types.get(ip), tuple.values.get(ip), 0..) |field_ty, field_val, i| { | 2422 | 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; |
| 2421 | 2424 | ||
| 2422 | const field_size = Type.fromInterned(field_ty).abiSize(mod); | 2425 | const field_size = Type.fromInterned(field_ty).abiSize(zcu); |
| 2423 | const field_align = Type.fromInterned(field_ty).abiAlignment(mod); | 2426 | const field_align = Type.fromInterned(field_ty).abiAlignment(zcu); |
| 2424 | const field_offset = field_align.forward(offset); | 2427 | const field_offset = field_align.forward(offset); |
| 2425 | offset = field_offset + field_size; | 2428 | offset = field_offset + field_size; |
| 2426 | 2429 | ||
| ... | @@ -2448,8 +2451,8 @@ pub const Object = struct { | ... | @@ -2448,8 +2451,8 @@ pub const Object = struct { |
| 2448 | o.debug_compile_unit, // Scope | 2451 | o.debug_compile_unit, // Scope |
| 2449 | 0, // Line | 2452 | 0, // Line |
| 2450 | .none, // Underlying type | 2453 | .none, // Underlying type |
| 2451 | ty.abiSize(mod) * 8, | 2454 | ty.abiSize(zcu) * 8, |
| 2452 | (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8, | 2455 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2453 | try o.builder.debugTuple(fields.items), | 2456 | try o.builder.debugTuple(fields.items), |
| 2454 | ); | 2457 | ); |
| 2455 | 2458 | ||
| ... | @@ -2467,7 +2470,7 @@ pub const Object = struct { | ... | @@ -2467,7 +2470,7 @@ pub const Object = struct { |
| 2467 | // into. Therefore we can satisfy this by making an empty namespace, | 2470 | // into. Therefore we can satisfy this by making an empty namespace, |
| 2468 | // rather than changing the frontend to unnecessarily resolve the | 2471 | // rather than changing the frontend to unnecessarily resolve the |
| 2469 | // struct field types. | 2472 | // struct field types. |
| 2470 | const owner_decl_index = ty.getOwnerDecl(mod); | 2473 | const owner_decl_index = ty.getOwnerDecl(zcu); |
| 2471 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); | 2474 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); |
| 2472 | try o.debug_type_map.put(gpa, ty, debug_struct_type); | 2475 | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2473 | return debug_struct_type; | 2476 | return debug_struct_type; |
| ... | @@ -2476,14 +2479,14 @@ pub const Object = struct { | ... | @@ -2476,14 +2479,14 @@ pub const Object = struct { |
| 2476 | else => {}, | 2479 | else => {}, |
| 2477 | } | 2480 | } |
| 2478 | 2481 | ||
| 2479 | if (!ty.hasRuntimeBitsIgnoreComptime(mod)) { | 2482 | if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2480 | const owner_decl_index = ty.getOwnerDecl(mod); | 2483 | const owner_decl_index = ty.getOwnerDecl(zcu); |
| 2481 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); | 2484 | const debug_struct_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); |
| 2482 | try o.debug_type_map.put(gpa, ty, debug_struct_type); | 2485 | try o.debug_type_map.put(gpa, ty, debug_struct_type); |
| 2483 | return debug_struct_type; | 2486 | return debug_struct_type; |
| 2484 | } | 2487 | } |
| 2485 | 2488 | ||
| 2486 | const struct_type = mod.typeToStruct(ty).?; | 2489 | const struct_type = zcu.typeToStruct(ty).?; |
| 2487 | 2490 | ||
| 2488 | var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{}; | 2491 | var fields: std.ArrayListUnmanaged(Builder.Metadata) = .{}; |
| 2489 | defer fields.deinit(gpa); | 2492 | defer fields.deinit(gpa); |
| ... | @@ -2499,14 +2502,14 @@ pub const Object = struct { | ... | @@ -2499,14 +2502,14 @@ pub const Object = struct { |
| 2499 | var it = struct_type.iterateRuntimeOrder(ip); | 2502 | var it = struct_type.iterateRuntimeOrder(ip); |
| 2500 | while (it.next()) |field_index| { | 2503 | while (it.next()) |field_index| { |
| 2501 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]); | 2504 | const field_ty = Type.fromInterned(struct_type.field_types.get(ip)[field_index]); |
| 2502 | if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue; | 2505 | if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue; |
| 2503 | const field_size = field_ty.abiSize(mod); | 2506 | const field_size = field_ty.abiSize(zcu); |
| 2504 | const field_align = mod.structFieldAlignment( | 2507 | const field_align = zcu.structFieldAlignment( |
| 2505 | struct_type.fieldAlign(ip, field_index), | 2508 | struct_type.fieldAlign(ip, field_index), |
| 2506 | field_ty, | 2509 | field_ty, |
| 2507 | struct_type.layout, | 2510 | struct_type.layout, |
| 2508 | ); | 2511 | ); |
| 2509 | const field_offset = ty.structFieldOffset(field_index, mod); | 2512 | const field_offset = ty.structFieldOffset(field_index, zcu); |
| 2510 | 2513 | ||
| 2511 | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse | 2514 | const field_name = struct_type.fieldName(ip, field_index).unwrap() orelse |
| 2512 | try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls); | 2515 | try ip.getOrPutStringFmt(gpa, "{d}", .{field_index}, .no_embedded_nulls); |
| ... | @@ -2529,8 +2532,8 @@ pub const Object = struct { | ... | @@ -2529,8 +2532,8 @@ pub const Object = struct { |
| 2529 | o.debug_compile_unit, // Scope | 2532 | o.debug_compile_unit, // Scope |
| 2530 | 0, // Line | 2533 | 0, // Line |
| 2531 | .none, // Underlying type | 2534 | .none, // Underlying type |
| 2532 | ty.abiSize(mod) * 8, | 2535 | ty.abiSize(zcu) * 8, |
| 2533 | (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8, | 2536 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2534 | try o.builder.debugTuple(fields.items), | 2537 | try o.builder.debugTuple(fields.items), |
| 2535 | ); | 2538 | ); |
| 2536 | 2539 | ||
| ... | @@ -2543,14 +2546,14 @@ pub const Object = struct { | ... | @@ -2543,14 +2546,14 @@ pub const Object = struct { |
| 2543 | return debug_struct_type; | 2546 | return debug_struct_type; |
| 2544 | }, | 2547 | }, |
| 2545 | .Union => { | 2548 | .Union => { |
| 2546 | const owner_decl_index = ty.getOwnerDecl(mod); | 2549 | const owner_decl_index = ty.getOwnerDecl(zcu); |
| 2547 | 2550 | ||
| 2548 | const name = try o.allocTypeName(ty); | 2551 | const name = try o.allocTypeName(ty); |
| 2549 | defer gpa.free(name); | 2552 | defer gpa.free(name); |
| 2550 | 2553 | ||
| 2551 | const union_type = ip.loadUnionType(ty.toIntern()); | 2554 | const union_type = ip.loadUnionType(ty.toIntern()); |
| 2552 | if (!union_type.haveFieldTypes(ip) or | 2555 | if (!union_type.haveFieldTypes(ip) or |
| 2553 | !ty.hasRuntimeBitsIgnoreComptime(mod) or | 2556 | !ty.hasRuntimeBitsIgnoreComptime(zcu) or |
| 2554 | !union_type.haveLayout(ip)) | 2557 | !union_type.haveLayout(ip)) |
| 2555 | { | 2558 | { |
| 2556 | const debug_union_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); | 2559 | const debug_union_type = try o.makeEmptyNamespaceDebugType(owner_decl_index); |
| ... | @@ -2558,7 +2561,7 @@ pub const Object = struct { | ... | @@ -2558,7 +2561,7 @@ pub const Object = struct { |
| 2558 | return debug_union_type; | 2561 | return debug_union_type; |
| 2559 | } | 2562 | } |
| 2560 | 2563 | ||
| 2561 | const layout = mod.getUnionLayout(union_type); | 2564 | const layout = zcu.getUnionLayout(union_type); |
| 2562 | 2565 | ||
| 2563 | const debug_fwd_ref = try o.builder.debugForwardReference(); | 2566 | const debug_fwd_ref = try o.builder.debugForwardReference(); |
| 2564 | 2567 | ||
| ... | @@ -2572,8 +2575,8 @@ pub const Object = struct { | ... | @@ -2572,8 +2575,8 @@ pub const Object = struct { |
| 2572 | o.debug_compile_unit, // Scope | 2575 | o.debug_compile_unit, // Scope |
| 2573 | 0, // Line | 2576 | 0, // Line |
| 2574 | .none, // Underlying type | 2577 | .none, // Underlying type |
| 2575 | ty.abiSize(mod) * 8, | 2578 | ty.abiSize(zcu) * 8, |
| 2576 | (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8, | 2579 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2577 | try o.builder.debugTuple( | 2580 | try o.builder.debugTuple( |
| 2578 | &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))}, | 2581 | &.{try o.lowerDebugType(Type.fromInterned(union_type.enum_tag_ty))}, |
| 2579 | ), | 2582 | ), |
| ... | @@ -2600,12 +2603,12 @@ pub const Object = struct { | ... | @@ -2600,12 +2603,12 @@ pub const Object = struct { |
| 2600 | 2603 | ||
| 2601 | for (0..tag_type.names.len) |field_index| { | 2604 | for (0..tag_type.names.len) |field_index| { |
| 2602 | const field_ty = union_type.field_types.get(ip)[field_index]; | 2605 | 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; |
| 2604 | 2607 | ||
| 2605 | const field_size = Type.fromInterned(field_ty).abiSize(mod); | 2608 | const field_size = Type.fromInterned(field_ty).abiSize(zcu); |
| 2606 | const field_align: InternPool.Alignment = switch (union_type.flagsPtr(ip).layout) { | 2609 | const field_align: InternPool.Alignment = switch (union_type.flagsPtr(ip).layout) { |
| 2607 | .@"packed" => .none, | 2610 | .@"packed" => .none, |
| 2608 | .auto, .@"extern" => mod.unionFieldNormalAlignment(union_type, @intCast(field_index)), | 2611 | .auto, .@"extern" => zcu.unionFieldNormalAlignment(union_type, @intCast(field_index)), |
| 2609 | }; | 2612 | }; |
| 2610 | 2613 | ||
| 2611 | const field_name = tag_type.names.get(ip)[field_index]; | 2614 | const field_name = tag_type.names.get(ip)[field_index]; |
| ... | @@ -2634,8 +2637,8 @@ pub const Object = struct { | ... | @@ -2634,8 +2637,8 @@ pub const Object = struct { |
| 2634 | o.debug_compile_unit, // Scope | 2637 | o.debug_compile_unit, // Scope |
| 2635 | 0, // Line | 2638 | 0, // Line |
| 2636 | .none, // Underlying type | 2639 | .none, // Underlying type |
| 2637 | ty.abiSize(mod) * 8, | 2640 | ty.abiSize(zcu) * 8, |
| 2638 | (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8, | 2641 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2639 | try o.builder.debugTuple(fields.items), | 2642 | try o.builder.debugTuple(fields.items), |
| 2640 | ); | 2643 | ); |
| 2641 | 2644 | ||
| ... | @@ -2693,8 +2696,8 @@ pub const Object = struct { | ... | @@ -2693,8 +2696,8 @@ pub const Object = struct { |
| 2693 | o.debug_compile_unit, // Scope | 2696 | o.debug_compile_unit, // Scope |
| 2694 | 0, // Line | 2697 | 0, // Line |
| 2695 | .none, // Underlying type | 2698 | .none, // Underlying type |
| 2696 | ty.abiSize(mod) * 8, | 2699 | ty.abiSize(zcu) * 8, |
| 2697 | (ty.abiAlignment(mod).toByteUnits() orelse 0) * 8, | 2700 | (ty.abiAlignment(zcu).toByteUnits() orelse 0) * 8, |
| 2698 | try o.builder.debugTuple(&full_fields), | 2701 | try o.builder.debugTuple(&full_fields), |
| 2699 | ); | 2702 | ); |
| 2700 | 2703 | ||
| ... | @@ -2707,7 +2710,7 @@ pub const Object = struct { | ... | @@ -2707,7 +2710,7 @@ pub const Object = struct { |
| 2707 | return debug_tagged_union_type; | 2710 | return debug_tagged_union_type; |
| 2708 | }, | 2711 | }, |
| 2709 | .Fn => { | 2712 | .Fn => { |
| 2710 | const fn_info = mod.typeToFunc(ty).?; | 2713 | const fn_info = zcu.typeToFunc(ty).?; |
| 2711 | 2714 | ||
| 2712 | var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa); | 2715 | var debug_param_types = std.ArrayList(Builder.Metadata).init(gpa); |
| 2713 | defer debug_param_types.deinit(); | 2716 | defer debug_param_types.deinit(); |
| ... | @@ -2715,32 +2718,32 @@ pub const Object = struct { | ... | @@ -2715,32 +2718,32 @@ pub const Object = struct { |
| 2715 | try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len); | 2718 | try debug_param_types.ensureUnusedCapacity(3 + fn_info.param_types.len); |
| 2716 | 2719 | ||
| 2717 | // Return type goes first. | 2720 | // Return type goes first. |
| 2718 | if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(mod)) { | 2721 | if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(zcu)) { |
| 2719 | const sret = firstParamSRet(fn_info, mod, target); | 2722 | const sret = firstParamSRet(fn_info, zcu, target); |
| 2720 | const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type); | 2723 | const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type); |
| 2721 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty)); | 2724 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty)); |
| 2722 | 2725 | ||
| 2723 | if (sret) { | 2726 | 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)); |
| 2725 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); | 2728 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); |
| 2726 | } | 2729 | } |
| 2727 | } else { | 2730 | } else { |
| 2728 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void)); | 2731 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(Type.void)); |
| 2729 | } | 2732 | } |
| 2730 | 2733 | ||
| 2731 | if (Type.fromInterned(fn_info.return_type).isError(mod) and | 2734 | if (Type.fromInterned(fn_info.return_type).isError(zcu) and |
| 2732 | o.module.comp.config.any_error_tracing) | 2735 | o.module.comp.config.any_error_tracing) |
| 2733 | { | 2736 | { |
| 2734 | const ptr_ty = try mod.singleMutPtrType(try o.getStackTraceType()); | 2737 | const ptr_ty = try zcu.singleMutPtrType(try o.getStackTraceType()); |
| 2735 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); | 2738 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); |
| 2736 | } | 2739 | } |
| 2737 | 2740 | ||
| 2738 | for (0..fn_info.param_types.len) |i| { | 2741 | for (0..fn_info.param_types.len) |i| { |
| 2739 | const param_ty = Type.fromInterned(fn_info.param_types.get(ip)[i]); | 2742 | 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; |
| 2741 | 2744 | ||
| 2742 | if (isByRef(param_ty, mod)) { | 2745 | if (isByRef(param_ty, zcu)) { |
| 2743 | const ptr_ty = try mod.singleMutPtrType(param_ty); | 2746 | const ptr_ty = try zcu.singleMutPtrType(param_ty); |
| 2744 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); | 2747 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ptr_ty)); |
| 2745 | } else { | 2748 | } else { |
| 2746 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty)); | 2749 | debug_param_types.appendAssumeCapacity(try o.lowerDebugType(param_ty)); |
| ... | @@ -2767,9 +2770,10 @@ pub const Object = struct { | ... | @@ -2767,9 +2770,10 @@ pub const Object = struct { |
| 2767 | } | 2770 | } |
| 2768 | 2771 | ||
| 2769 | fn namespaceToDebugScope(o: *Object, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata { | 2772 | fn namespaceToDebugScope(o: *Object, namespace_index: InternPool.NamespaceIndex) !Builder.Metadata { |
| 2770 | const mod = o.module; | 2773 | const zcu = o.module; |
| 2771 | const namespace = mod.namespacePtr(namespace_index); | 2774 | const namespace = zcu.namespacePtr(namespace_index); |
| 2772 | if (namespace.parent == .none) return try o.getDebugFile(namespace.file_scope); | 2775 | const file_scope = namespace.fileScope(zcu); |
| 2776 | if (namespace.parent == .none) return try o.getDebugFile(file_scope); | ||
| 2773 | 2777 | ||
| 2774 | const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index); | 2778 | const gop = try o.debug_unresolved_namespace_scopes.getOrPut(o.gpa, namespace_index); |
| 2775 | 2779 | ||
| ... | @@ -2779,13 +2783,14 @@ pub const Object = struct { | ... | @@ -2779,13 +2783,14 @@ pub const Object = struct { |
| 2779 | } | 2783 | } |
| 2780 | 2784 | ||
| 2781 | fn makeEmptyNamespaceDebugType(o: *Object, decl_index: InternPool.DeclIndex) !Builder.Metadata { | 2785 | fn makeEmptyNamespaceDebugType(o: *Object, decl_index: InternPool.DeclIndex) !Builder.Metadata { |
| 2782 | const mod = o.module; | 2786 | const zcu = o.module; |
| 2783 | const decl = mod.declPtr(decl_index); | 2787 | const decl = zcu.declPtr(decl_index); |
| 2788 | const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu); | ||
| 2784 | return o.builder.debugStructType( | 2789 | return o.builder.debugStructType( |
| 2785 | try o.builder.metadataString(decl.name.toSlice(&mod.intern_pool)), // TODO use fully qualified name | 2790 | try o.builder.metadataString(decl.name.toSlice(&zcu.intern_pool)), // TODO use fully qualified name |
| 2786 | try o.getDebugFile(mod.namespacePtr(decl.src_namespace).file_scope), | 2791 | try o.getDebugFile(file_scope), |
| 2787 | try o.namespaceToDebugScope(decl.src_namespace), | 2792 | try o.namespaceToDebugScope(decl.src_namespace), |
| 2788 | decl.typeSrcLine(mod) + 1, | 2793 | decl.typeSrcLine(zcu) + 1, |
| 2789 | .none, | 2794 | .none, |
| 2790 | 0, | 2795 | 0, |
| 2791 | 0, | 2796 | 0, |
| ... | @@ -2794,21 +2799,22 @@ pub const Object = struct { | ... | @@ -2794,21 +2799,22 @@ pub const Object = struct { |
| 2794 | } | 2799 | } |
| 2795 | 2800 | ||
| 2796 | fn getStackTraceType(o: *Object) Allocator.Error!Type { | 2801 | fn getStackTraceType(o: *Object) Allocator.Error!Type { |
| 2797 | const mod = o.module; | 2802 | const zcu = o.module; |
| 2798 | 2803 | ||
| 2799 | const std_mod = mod.std_mod; | 2804 | const std_mod = zcu.std_mod; |
| 2800 | const std_file = (mod.importPkg(std_mod) catch unreachable).file; | 2805 | const std_file_imported = zcu.importPkg(std_mod) catch unreachable; |
| 2801 | 2806 | ||
| 2802 | const builtin_str = try mod.intern_pool.getOrPutString(mod.gpa, "builtin", .no_embedded_nulls); | 2807 | const builtin_str = try zcu.intern_pool.getOrPutString(zcu.gpa, "builtin", .no_embedded_nulls); |
| 2803 | const std_namespace = mod.namespacePtr(mod.declPtr(std_file.root_decl.unwrap().?).src_namespace); | 2808 | const std_file_root_decl = zcu.fileRootDecl(std_file_imported.file_index); |
| 2804 | const builtin_decl = std_namespace.decls.getKeyAdapted(builtin_str, Module.DeclAdapter{ .zcu = mod }).?; | 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 }).?; | ||
| 2805 | 2811 | ||
| 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); |
| 2807 | // buffer is only used for int_type, `builtin` is a struct. | 2813 | // buffer is only used for int_type, `builtin` is a struct. |
| 2808 | const builtin_ty = mod.declPtr(builtin_decl).val.toType(); | 2814 | const builtin_ty = zcu.declPtr(builtin_decl).val.toType(); |
| 2809 | const builtin_namespace = mod.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(mod)).?; | 2815 | const builtin_namespace = zcu.namespacePtrUnwrap(builtin_ty.getNamespaceIndex(zcu)).?; |
| 2810 | const stack_trace_decl_index = builtin_namespace.decls.getKeyAdapted(stack_trace_str, Module.DeclAdapter{ .zcu = mod }).?; | 2816 | const stack_trace_decl_index = builtin_namespace.decls.getKeyAdapted(stack_trace_str, Module.DeclAdapter{ .zcu = zcu }).?; |
| 2811 | const stack_trace_decl = mod.declPtr(stack_trace_decl_index); | 2817 | const stack_trace_decl = zcu.declPtr(stack_trace_decl_index); |
| 2812 | 2818 | ||
| 2813 | // Sema should have ensured that StackTrace was analyzed. | 2819 | // Sema should have ensured that StackTrace was analyzed. |
| 2814 | assert(stack_trace_decl.has_tv); | 2820 | assert(stack_trace_decl.has_tv); |
| ... | @@ -2834,7 +2840,7 @@ pub const Object = struct { | ... | @@ -2834,7 +2840,7 @@ pub const Object = struct { |
| 2834 | const gpa = o.gpa; | 2840 | const gpa = o.gpa; |
| 2835 | const decl = zcu.declPtr(decl_index); | 2841 | const decl = zcu.declPtr(decl_index); |
| 2836 | const namespace = zcu.namespacePtr(decl.src_namespace); | 2842 | const namespace = zcu.namespacePtr(decl.src_namespace); |
| 2837 | const owner_mod = namespace.file_scope.mod; | 2843 | const owner_mod = namespace.fileScope(zcu).mod; |
| 2838 | const zig_fn_type = decl.typeOf(zcu); | 2844 | const zig_fn_type = decl.typeOf(zcu); |
| 2839 | const gop = try o.decl_map.getOrPut(gpa, decl_index); | 2845 | const gop = try o.decl_map.getOrPut(gpa, decl_index); |
| 2840 | if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function; | 2846 | if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.function; |
| ... | @@ -3059,17 +3065,17 @@ pub const Object = struct { | ... | @@ -3059,17 +3065,17 @@ pub const Object = struct { |
| 3059 | if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable; | 3065 | if (gop.found_existing) return gop.value_ptr.ptr(&o.builder).kind.variable; |
| 3060 | errdefer assert(o.decl_map.remove(decl_index)); | 3066 | errdefer assert(o.decl_map.remove(decl_index)); |
| 3061 | 3067 | ||
| 3062 | const mod = o.module; | 3068 | const zcu = o.module; |
| 3063 | const decl = mod.declPtr(decl_index); | 3069 | const decl = zcu.declPtr(decl_index); |
| 3064 | const is_extern = decl.isExtern(mod); | 3070 | const is_extern = decl.isExtern(zcu); |
| 3065 | 3071 | ||
| 3066 | const variable_index = try o.builder.addVariable( | 3072 | const variable_index = try o.builder.addVariable( |
| 3067 | try o.builder.strtabString((if (is_extern) | 3073 | try o.builder.strtabString((if (is_extern) |
| 3068 | decl.name | 3074 | decl.name |
| 3069 | else | 3075 | else |
| 3070 | try decl.fullyQualifiedName(mod)).toSlice(&mod.intern_pool)), | 3076 | try decl.fullyQualifiedName(zcu)).toSlice(&zcu.intern_pool)), |
| 3071 | try o.lowerType(decl.typeOf(mod)), | 3077 | try o.lowerType(decl.typeOf(zcu)), |
| 3072 | toLlvmGlobalAddressSpace(decl.@"addrspace", mod.getTarget()), | 3078 | toLlvmGlobalAddressSpace(decl.@"addrspace", zcu.getTarget()), |
| 3073 | ); | 3079 | ); |
| 3074 | gop.value_ptr.* = variable_index.ptrConst(&o.builder).global; | 3080 | gop.value_ptr.* = variable_index.ptrConst(&o.builder).global; |
| 3075 | 3081 | ||
| ... | @@ -3077,9 +3083,9 @@ pub const Object = struct { | ... | @@ -3077,9 +3083,9 @@ pub const Object = struct { |
| 3077 | if (is_extern) { | 3083 | if (is_extern) { |
| 3078 | variable_index.setLinkage(.external, &o.builder); | 3084 | variable_index.setLinkage(.external, &o.builder); |
| 3079 | variable_index.setUnnamedAddr(.default, &o.builder); | 3085 | variable_index.setUnnamedAddr(.default, &o.builder); |
| 3080 | if (decl.val.getVariable(mod)) |decl_var| { | 3086 | if (decl.val.getVariable(zcu)) |decl_var| { |
| 3081 | const decl_namespace = mod.namespacePtr(decl.src_namespace); | 3087 | const decl_namespace = zcu.namespacePtr(decl.src_namespace); |
| 3082 | const single_threaded = decl_namespace.file_scope.mod.single_threaded; | 3088 | const single_threaded = decl_namespace.fileScope(zcu).mod.single_threaded; |
| 3083 | variable_index.setThreadLocal( | 3089 | variable_index.setThreadLocal( |
| 3084 | if (decl_var.is_threadlocal and !single_threaded) .generaldynamic else .default, | 3090 | if (decl_var.is_threadlocal and !single_threaded) .generaldynamic else .default, |
| 3085 | &o.builder, | 3091 | &o.builder, |
| ... | @@ -4638,7 +4644,8 @@ pub const DeclGen = struct { | ... | @@ -4638,7 +4644,8 @@ pub const DeclGen = struct { |
| 4638 | const o = dg.object; | 4644 | const o = dg.object; |
| 4639 | const zcu = o.module; | 4645 | const zcu = o.module; |
| 4640 | const namespace = zcu.namespacePtr(dg.decl.src_namespace); | 4646 | 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; | ||
| 4642 | } | 4649 | } |
| 4643 | 4650 | ||
| 4644 | fn todo(dg: *DeclGen, comptime format: []const u8, args: anytype) Error { | 4651 | fn todo(dg: *DeclGen, comptime format: []const u8, args: anytype) Error { |
| ... | @@ -4682,7 +4689,7 @@ pub const DeclGen = struct { | ... | @@ -4682,7 +4689,7 @@ pub const DeclGen = struct { |
| 4682 | 4689 | ||
| 4683 | if (decl.val.getVariable(zcu)) |decl_var| { | 4690 | if (decl.val.getVariable(zcu)) |decl_var| { |
| 4684 | const decl_namespace = zcu.namespacePtr(decl.src_namespace); | 4691 | 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; |
| 4686 | variable_index.setThreadLocal( | 4693 | variable_index.setThreadLocal( |
| 4687 | if (decl_var.is_threadlocal and !single_threaded) .generaldynamic else .default, | 4694 | if (decl_var.is_threadlocal and !single_threaded) .generaldynamic else .default, |
| 4688 | &o.builder, | 4695 | &o.builder, |
| ... | @@ -4692,10 +4699,11 @@ pub const DeclGen = struct { | ... | @@ -4692,10 +4699,11 @@ pub const DeclGen = struct { |
| 4692 | const line_number = decl.navSrcLine(zcu) + 1; | 4699 | const line_number = decl.navSrcLine(zcu) + 1; |
| 4693 | 4700 | ||
| 4694 | const namespace = zcu.namespacePtr(decl.src_namespace); | 4701 | 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; | ||
| 4696 | 4704 | ||
| 4697 | if (!owner_mod.strip) { | 4705 | if (!owner_mod.strip) { |
| 4698 | const debug_file = try o.getDebugFile(namespace.file_scope); | 4706 | const debug_file = try o.getDebugFile(file_scope); |
| 4699 | 4707 | ||
| 4700 | const debug_global_var = try o.builder.debugGlobalVar( | 4708 | const debug_global_var = try o.builder.debugGlobalVar( |
| 4701 | try o.builder.metadataString(decl.name.toSlice(ip)), // Name | 4709 | try o.builder.metadataString(decl.name.toSlice(ip)), // Name |
| ... | @@ -5143,9 +5151,10 @@ pub const FuncGen = struct { | ... | @@ -5143,9 +5151,10 @@ pub const FuncGen = struct { |
| 5143 | const decl_index = func.owner_decl; | 5151 | const decl_index = func.owner_decl; |
| 5144 | const decl = zcu.declPtr(decl_index); | 5152 | const decl = zcu.declPtr(decl_index); |
| 5145 | const namespace = zcu.namespacePtr(decl.src_namespace); | 5153 | 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; | ||
| 5147 | 5156 | ||
| 5148 | self.file = try o.getDebugFile(namespace.file_scope); | 5157 | self.file = try o.getDebugFile(file_scope); |
| 5149 | 5158 | ||
| 5150 | const line_number = decl.navSrcLine(zcu) + 1; | 5159 | const line_number = decl.navSrcLine(zcu) + 1; |
| 5151 | self.inlined = self.wip.debug_location; | 5160 | self.inlined = self.wip.debug_location; |
src/codegen/spirv.zig+10-9| ... | @@ -188,19 +188,20 @@ pub const Object = struct { | ... | @@ -188,19 +188,20 @@ pub const Object = struct { |
| 188 | 188 | ||
| 189 | fn genDecl( | 189 | fn genDecl( |
| 190 | self: *Object, | 190 | self: *Object, |
| 191 | mod: *Module, | 191 | zcu: *Zcu, |
| 192 | decl_index: InternPool.DeclIndex, | 192 | decl_index: InternPool.DeclIndex, |
| 193 | air: Air, | 193 | air: Air, |
| 194 | liveness: Liveness, | 194 | liveness: Liveness, |
| 195 | ) !void { | 195 | ) !void { |
| 196 | const decl = mod.declPtr(decl_index); | 196 | const gpa = self.gpa; |
| 197 | const namespace = mod.namespacePtr(decl.src_namespace); | 197 | const decl = zcu.declPtr(decl_index); |
| 198 | const structured_cfg = namespace.file_scope.mod.structured_cfg; | 198 | const namespace = zcu.namespacePtr(decl.src_namespace); |
| 199 | const structured_cfg = namespace.fileScope(zcu).mod.structured_cfg; | ||
| 199 | 200 | ||
| 200 | var decl_gen = DeclGen{ | 201 | var decl_gen = DeclGen{ |
| 201 | .gpa = self.gpa, | 202 | .gpa = gpa, |
| 202 | .object = self, | 203 | .object = self, |
| 203 | .module = mod, | 204 | .module = zcu, |
| 204 | .spv = &self.spv, | 205 | .spv = &self.spv, |
| 205 | .decl_index = decl_index, | 206 | .decl_index = decl_index, |
| 206 | .air = air, | 207 | .air = air, |
| ... | @@ -212,19 +213,19 @@ pub const Object = struct { | ... | @@ -212,19 +213,19 @@ pub const Object = struct { |
| 212 | false => .{ .unstructured = .{} }, | 213 | false => .{ .unstructured = .{} }, |
| 213 | }, | 214 | }, |
| 214 | .current_block_label = undefined, | 215 | .current_block_label = undefined, |
| 215 | .base_line = decl.navSrcLine(mod), | 216 | .base_line = decl.navSrcLine(zcu), |
| 216 | }; | 217 | }; |
| 217 | defer decl_gen.deinit(); | 218 | defer decl_gen.deinit(); |
| 218 | 219 | ||
| 219 | decl_gen.genDecl() catch |err| switch (err) { | 220 | decl_gen.genDecl() catch |err| switch (err) { |
| 220 | error.CodegenFail => { | 221 | 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.?); |
| 222 | }, | 223 | }, |
| 223 | else => |other| { | 224 | else => |other| { |
| 224 | // There might be an error that happened *after* self.error_msg | 225 | // There might be an error that happened *after* self.error_msg |
| 225 | // was already allocated, so be sure to free it. | 226 | // was already allocated, so be sure to free it. |
| 226 | if (decl_gen.error_msg) |error_msg| { | 227 | if (decl_gen.error_msg) |error_msg| { |
| 227 | error_msg.deinit(mod.gpa); | 228 | error_msg.deinit(gpa); |
| 228 | } | 229 | } |
| 229 | 230 | ||
| 230 | return other; | 231 | return other; |
src/link/C.zig+8-4| ... | @@ -208,6 +208,8 @@ pub fn updateFunc( | ... | @@ -208,6 +208,8 @@ pub fn updateFunc( |
| 208 | fwd_decl.clearRetainingCapacity(); | 208 | fwd_decl.clearRetainingCapacity(); |
| 209 | code.clearRetainingCapacity(); | 209 | code.clearRetainingCapacity(); |
| 210 | 210 | ||
| 211 | const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu); | ||
| 212 | |||
| 211 | var function: codegen.Function = .{ | 213 | var function: codegen.Function = .{ |
| 212 | .value_map = codegen.CValueMap.init(gpa), | 214 | .value_map = codegen.CValueMap.init(gpa), |
| 213 | .air = air, | 215 | .air = air, |
| ... | @@ -217,7 +219,7 @@ pub fn updateFunc( | ... | @@ -217,7 +219,7 @@ pub fn updateFunc( |
| 217 | .dg = .{ | 219 | .dg = .{ |
| 218 | .gpa = gpa, | 220 | .gpa = gpa, |
| 219 | .zcu = zcu, | 221 | .zcu = zcu, |
| 220 | .mod = zcu.namespacePtr(decl.src_namespace).file_scope.mod, | 222 | .mod = file_scope.mod, |
| 221 | .error_msg = null, | 223 | .error_msg = null, |
| 222 | .pass = .{ .decl = decl_index }, | 224 | .pass = .{ .decl = decl_index }, |
| 223 | .is_naked_fn = decl.typeOf(zcu).fnCallingConvention(zcu) == .Naked, | 225 | .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 { | ... | @@ -335,11 +337,13 @@ pub fn updateDecl(self: *C, zcu: *Zcu, decl_index: InternPool.DeclIndex) !void { |
| 335 | fwd_decl.clearRetainingCapacity(); | 337 | fwd_decl.clearRetainingCapacity(); |
| 336 | code.clearRetainingCapacity(); | 338 | code.clearRetainingCapacity(); |
| 337 | 339 | ||
| 340 | const file_scope = zcu.namespacePtr(decl.src_namespace).fileScope(zcu); | ||
| 341 | |||
| 338 | var object: codegen.Object = .{ | 342 | var object: codegen.Object = .{ |
| 339 | .dg = .{ | 343 | .dg = .{ |
| 340 | .gpa = gpa, | 344 | .gpa = gpa, |
| 341 | .zcu = zcu, | 345 | .zcu = zcu, |
| 342 | .mod = zcu.namespacePtr(decl.src_namespace).file_scope.mod, | 346 | .mod = file_scope.mod, |
| 343 | .error_msg = null, | 347 | .error_msg = null, |
| 344 | .pass = .{ .decl = decl_index }, | 348 | .pass = .{ .decl = decl_index }, |
| 345 | .is_naked_fn = false, | 349 | .is_naked_fn = false, |
| ... | @@ -491,7 +495,7 @@ pub fn flushModule(self: *C, arena: Allocator, prog_node: std.Progress.Node) !vo | ... | @@ -491,7 +495,7 @@ pub fn flushModule(self: *C, arena: Allocator, prog_node: std.Progress.Node) !vo |
| 491 | for (self.decl_table.keys(), self.decl_table.values()) |decl_index, *decl_block| { | 495 | for (self.decl_table.keys(), self.decl_table.values()) |decl_index, *decl_block| { |
| 492 | const decl = zcu.declPtr(decl_index); | 496 | const decl = zcu.declPtr(decl_index); |
| 493 | const extern_name = if (decl.isExtern(zcu)) decl.name.toOptional() else .none; | 497 | 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; |
| 495 | try self.flushDeclBlock( | 499 | try self.flushDeclBlock( |
| 496 | zcu, | 500 | zcu, |
| 497 | mod, | 501 | mod, |
| ... | @@ -848,7 +852,7 @@ pub fn updateExports( | ... | @@ -848,7 +852,7 @@ pub fn updateExports( |
| 848 | const gpa = self.base.comp.gpa; | 852 | const gpa = self.base.comp.gpa; |
| 849 | const mod, const pass: codegen.DeclGen.Pass, const decl_block, const exported_block = switch (exported) { | 853 | const mod, const pass: codegen.DeclGen.Pass, const decl_block, const exported_block = switch (exported) { |
| 850 | .decl_index => |decl_index| .{ | 854 | .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, |
| 852 | .{ .decl = decl_index }, | 856 | .{ .decl = decl_index }, |
| 853 | self.decl_table.getPtr(decl_index).?, | 857 | self.decl_table.getPtr(decl_index).?, |
| 854 | (try self.exported_decls.getOrPut(gpa, decl_index)).value_ptr, | 858 | (try self.exported_decls.getOrPut(gpa, decl_index)).value_ptr, |
src/link/Dwarf.zig+1-1| ... | @@ -1204,7 +1204,7 @@ pub fn commitDeclState( | ... | @@ -1204,7 +1204,7 @@ pub fn commitDeclState( |
| 1204 | const decl = zcu.declPtr(decl_index); | 1204 | const decl = zcu.declPtr(decl_index); |
| 1205 | const ip = &zcu.intern_pool; | 1205 | const ip = &zcu.intern_pool; |
| 1206 | const namespace = zcu.namespacePtr(decl.src_namespace); | 1206 | 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; |
| 1208 | const target_endian = target.cpu.arch.endian(); | 1208 | const target_endian = target.cpu.arch.endian(); |
| 1209 | 1209 | ||
| 1210 | var dbg_line_buffer = &decl_state.dbg_line; | 1210 | var dbg_line_buffer = &decl_state.dbg_line; |
src/link/Wasm/ZigObject.zig+11-11| ... | @@ -335,29 +335,29 @@ fn finishUpdateDecl( | ... | @@ -335,29 +335,29 @@ fn finishUpdateDecl( |
| 335 | code: []const u8, | 335 | code: []const u8, |
| 336 | ) !void { | 336 | ) !void { |
| 337 | const gpa = wasm_file.base.comp.gpa; | 337 | const gpa = wasm_file.base.comp.gpa; |
| 338 | const mod = wasm_file.base.comp.module.?; | 338 | const zcu = wasm_file.base.comp.module.?; |
| 339 | const decl = mod.declPtr(decl_index); | 339 | const decl = zcu.declPtr(decl_index); |
| 340 | const decl_info = zig_object.decls_map.get(decl_index).?; | 340 | const decl_info = zig_object.decls_map.get(decl_index).?; |
| 341 | const atom_index = decl_info.atom; | 341 | const atom_index = decl_info.atom; |
| 342 | const atom = wasm_file.getAtomPtr(atom_index); | 342 | const atom = wasm_file.getAtomPtr(atom_index); |
| 343 | const sym = zig_object.symbol(atom.sym_index); | 343 | const sym = zig_object.symbol(atom.sym_index); |
| 344 | const full_name = try decl.fullyQualifiedName(mod); | 344 | const full_name = try decl.fullyQualifiedName(zcu); |
| 345 | sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&mod.intern_pool)); | 345 | sym.name = try zig_object.string_table.insert(gpa, full_name.toSlice(&zcu.intern_pool)); |
| 346 | try atom.code.appendSlice(gpa, code); | 346 | try atom.code.appendSlice(gpa, code); |
| 347 | atom.size = @intCast(code.len); | 347 | atom.size = @intCast(code.len); |
| 348 | 348 | ||
| 349 | switch (decl.typeOf(mod).zigTypeTag(mod)) { | 349 | switch (decl.typeOf(zcu).zigTypeTag(zcu)) { |
| 350 | .Fn => { | 350 | .Fn => { |
| 351 | sym.index = try zig_object.appendFunction(gpa, .{ .type_index = zig_object.atom_types.get(atom_index).? }); | 351 | sym.index = try zig_object.appendFunction(gpa, .{ .type_index = zig_object.atom_types.get(atom_index).? }); |
| 352 | sym.tag = .function; | 352 | sym.tag = .function; |
| 353 | }, | 353 | }, |
| 354 | else => { | 354 | 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: { |
| 356 | if (variable.is_const) { | 356 | if (variable.is_const) { |
| 357 | break :name ".rodata."; | 357 | break :name ".rodata."; |
| 358 | } else if (Value.fromInterned(variable.init).isUndefDeep(mod)) { | 358 | } else if (Value.fromInterned(variable.init).isUndefDeep(zcu)) { |
| 359 | const decl_namespace = mod.namespacePtr(decl.src_namespace); | 359 | const decl_namespace = zcu.namespacePtr(decl.src_namespace); |
| 360 | const optimize_mode = decl_namespace.file_scope.mod.optimize_mode; | 360 | const optimize_mode = decl_namespace.fileScope(zcu).mod.optimize_mode; |
| 361 | const is_initialized = switch (optimize_mode) { | 361 | const is_initialized = switch (optimize_mode) { |
| 362 | .Debug, .ReleaseSafe => true, | 362 | .Debug, .ReleaseSafe => true, |
| 363 | .ReleaseFast, .ReleaseSmall => false, | 363 | .ReleaseFast, .ReleaseSmall => false, |
| ... | @@ -382,7 +382,7 @@ fn finishUpdateDecl( | ... | @@ -382,7 +382,7 @@ fn finishUpdateDecl( |
| 382 | // Will be freed upon freeing of decl or after cleanup of Wasm binary. | 382 | // Will be freed upon freeing of decl or after cleanup of Wasm binary. |
| 383 | const full_segment_name = try std.mem.concat(gpa, u8, &.{ | 383 | const full_segment_name = try std.mem.concat(gpa, u8, &.{ |
| 384 | segment_name, | 384 | segment_name, |
| 385 | full_name.toSlice(&mod.intern_pool), | 385 | full_name.toSlice(&zcu.intern_pool), |
| 386 | }); | 386 | }); |
| 387 | errdefer gpa.free(full_segment_name); | 387 | errdefer gpa.free(full_segment_name); |
| 388 | sym.tag = .data; | 388 | sym.tag = .data; |
| ... | @@ -390,7 +390,7 @@ fn finishUpdateDecl( | ... | @@ -390,7 +390,7 @@ fn finishUpdateDecl( |
| 390 | }, | 390 | }, |
| 391 | } | 391 | } |
| 392 | if (code.len == 0) return; | 392 | if (code.len == 0) return; |
| 393 | atom.alignment = decl.getAlignment(mod); | 393 | atom.alignment = decl.getAlignment(zcu); |
| 394 | } | 394 | } |
| 395 | 395 | ||
| 396 | /// Creates and initializes a new segment in the 'Data' section. | 396 | /// Creates and initializes a new segment in the 'Data' section. |
src/main.zig+7-15| ... | @@ -27,8 +27,6 @@ const Cache = std.Build.Cache; | ... | @@ -27,8 +27,6 @@ const Cache = std.Build.Cache; |
| 27 | const target_util = @import("target.zig"); | 27 | const target_util = @import("target.zig"); |
| 28 | const crash_report = @import("crash_report.zig"); | 28 | const crash_report = @import("crash_report.zig"); |
| 29 | const Zcu = @import("Zcu.zig"); | 29 | const Zcu = @import("Zcu.zig"); |
| 30 | /// Deprecated. | ||
| 31 | const Module = Zcu; | ||
| 32 | const AstGen = std.zig.AstGen; | 30 | const AstGen = std.zig.AstGen; |
| 33 | const mingw = @import("mingw.zig"); | 31 | const mingw = @import("mingw.zig"); |
| 34 | const Server = std.zig.Server; | 32 | const Server = std.zig.Server; |
| ... | @@ -919,7 +917,7 @@ fn buildOutputType( | ... | @@ -919,7 +917,7 @@ fn buildOutputType( |
| 919 | var contains_res_file: bool = false; | 917 | var contains_res_file: bool = false; |
| 920 | var reference_trace: ?u32 = null; | 918 | var reference_trace: ?u32 = null; |
| 921 | var pdb_out_path: ?[]const u8 = null; | 919 | var pdb_out_path: ?[]const u8 = null; |
| 922 | var error_limit: ?Module.ErrorInt = null; | 920 | var error_limit: ?Zcu.ErrorInt = null; |
| 923 | // These are before resolving sysroot. | 921 | // These are before resolving sysroot. |
| 924 | var extra_cflags: std.ArrayListUnmanaged([]const u8) = .{}; | 922 | var extra_cflags: std.ArrayListUnmanaged([]const u8) = .{}; |
| 925 | var extra_rcflags: std.ArrayListUnmanaged([]const u8) = .{}; | 923 | var extra_rcflags: std.ArrayListUnmanaged([]const u8) = .{}; |
| ... | @@ -1107,7 +1105,7 @@ fn buildOutputType( | ... | @@ -1107,7 +1105,7 @@ fn buildOutputType( |
| 1107 | ); | 1105 | ); |
| 1108 | } else if (mem.eql(u8, arg, "--error-limit")) { | 1106 | } else if (mem.eql(u8, arg, "--error-limit")) { |
| 1109 | const next_arg = args_iter.nextOrFatal(); | 1107 | 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| { |
| 1111 | fatal("unable to parse error limit '{s}': {s}", .{ next_arg, @errorName(err) }); | 1109 | fatal("unable to parse error limit '{s}': {s}", .{ next_arg, @errorName(err) }); |
| 1112 | }; | 1110 | }; |
| 1113 | } else if (mem.eql(u8, arg, "-cflags")) { | 1111 | } else if (mem.eql(u8, arg, "-cflags")) { |
| ... | @@ -5956,7 +5954,7 @@ fn cmdAstCheck( | ... | @@ -5956,7 +5954,7 @@ fn cmdAstCheck( |
| 5956 | } | 5954 | } |
| 5957 | } | 5955 | } |
| 5958 | 5956 | ||
| 5959 | var file: Module.File = .{ | 5957 | var file: Zcu.File = .{ |
| 5960 | .status = .never_loaded, | 5958 | .status = .never_loaded, |
| 5961 | .source_loaded = false, | 5959 | .source_loaded = false, |
| 5962 | .tree_loaded = false, | 5960 | .tree_loaded = false, |
| ... | @@ -5967,8 +5965,6 @@ fn cmdAstCheck( | ... | @@ -5967,8 +5965,6 @@ fn cmdAstCheck( |
| 5967 | .tree = undefined, | 5965 | .tree = undefined, |
| 5968 | .zir = undefined, | 5966 | .zir = undefined, |
| 5969 | .mod = undefined, | 5967 | .mod = undefined, |
| 5970 | .root_decl = .none, | ||
| 5971 | .path_digest = undefined, | ||
| 5972 | }; | 5968 | }; |
| 5973 | if (zig_source_file) |file_name| { | 5969 | if (zig_source_file) |file_name| { |
| 5974 | var f = fs.cwd().openFile(file_name, .{}) catch |err| { | 5970 | var f = fs.cwd().openFile(file_name, .{}) catch |err| { |
| ... | @@ -6275,7 +6271,7 @@ fn cmdDumpZir( | ... | @@ -6275,7 +6271,7 @@ fn cmdDumpZir( |
| 6275 | }; | 6271 | }; |
| 6276 | defer f.close(); | 6272 | defer f.close(); |
| 6277 | 6273 | ||
| 6278 | var file: Module.File = .{ | 6274 | var file: Zcu.File = .{ |
| 6279 | .status = .never_loaded, | 6275 | .status = .never_loaded, |
| 6280 | .source_loaded = false, | 6276 | .source_loaded = false, |
| 6281 | .tree_loaded = false, | 6277 | .tree_loaded = false, |
| ... | @@ -6284,10 +6280,8 @@ fn cmdDumpZir( | ... | @@ -6284,10 +6280,8 @@ fn cmdDumpZir( |
| 6284 | .source = undefined, | 6280 | .source = undefined, |
| 6285 | .stat = undefined, | 6281 | .stat = undefined, |
| 6286 | .tree = undefined, | 6282 | .tree = undefined, |
| 6287 | .zir = try Module.loadZirCache(gpa, f), | 6283 | .zir = try Zcu.loadZirCache(gpa, f), |
| 6288 | .mod = undefined, | 6284 | .mod = undefined, |
| 6289 | .root_decl = .none, | ||
| 6290 | .path_digest = undefined, | ||
| 6291 | }; | 6285 | }; |
| 6292 | defer file.zir.deinit(gpa); | 6286 | defer file.zir.deinit(gpa); |
| 6293 | 6287 | ||
| ... | @@ -6342,7 +6336,7 @@ fn cmdChangelist( | ... | @@ -6342,7 +6336,7 @@ fn cmdChangelist( |
| 6342 | if (stat.size > std.zig.max_src_size) | 6336 | if (stat.size > std.zig.max_src_size) |
| 6343 | return error.FileTooBig; | 6337 | return error.FileTooBig; |
| 6344 | 6338 | ||
| 6345 | var file: Module.File = .{ | 6339 | var file: Zcu.File = .{ |
| 6346 | .status = .never_loaded, | 6340 | .status = .never_loaded, |
| 6347 | .source_loaded = false, | 6341 | .source_loaded = false, |
| 6348 | .tree_loaded = false, | 6342 | .tree_loaded = false, |
| ... | @@ -6357,8 +6351,6 @@ fn cmdChangelist( | ... | @@ -6357,8 +6351,6 @@ fn cmdChangelist( |
| 6357 | .tree = undefined, | 6351 | .tree = undefined, |
| 6358 | .zir = undefined, | 6352 | .zir = undefined, |
| 6359 | .mod = undefined, | 6353 | .mod = undefined, |
| 6360 | .root_decl = .none, | ||
| 6361 | .path_digest = undefined, | ||
| 6362 | }; | 6354 | }; |
| 6363 | 6355 | ||
| 6364 | file.mod = try Package.Module.createLimited(arena, .{ | 6356 | file.mod = try Package.Module.createLimited(arena, .{ |
| ... | @@ -6431,7 +6423,7 @@ fn cmdChangelist( | ... | @@ -6431,7 +6423,7 @@ fn cmdChangelist( |
| 6431 | var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .{}; | 6423 | var inst_map: std.AutoHashMapUnmanaged(Zir.Inst.Index, Zir.Inst.Index) = .{}; |
| 6432 | defer inst_map.deinit(gpa); | 6424 | defer inst_map.deinit(gpa); |
| 6433 | 6425 | ||
| 6434 | try Module.mapOldZirToNew(gpa, old_zir, file.zir, &inst_map); | 6426 | try Zcu.mapOldZirToNew(gpa, old_zir, file.zir, &inst_map); |
| 6435 | 6427 | ||
| 6436 | var bw = io.bufferedWriter(io.getStdOut().writer()); | 6428 | var bw = io.bufferedWriter(io.getStdOut().writer()); |
| 6437 | const stdout = bw.writer(); | 6429 | const stdout = bw.writer(); |