| ... | ... | @@ -36,6 +36,11 @@ comp: *Compilation, |
| 36 | 36 | zig_cache_artifact_directory: Compilation.Directory, |
| 37 | 37 | /// Pointer to externally managed resource. `null` if there is no zig file being compiled. |
| 38 | 38 | root_pkg: *Package, |
| 39 | |
| 40 | /// Used by AstGen worker to load and store ZIR cache. |
| 41 | global_zir_cache: Compilation.Directory, |
| 42 | /// Used by AstGen worker to load and store ZIR cache. |
| 43 | local_zir_cache: Compilation.Directory, |
| 39 | 44 | /// It's rare for a decl to be exported, so we save memory by having a sparse map of |
| 40 | 45 | /// Decl pointers to details about them being exported. |
| 41 | 46 | /// The Export memory is owned by the `export_owners` table; the slice itself is owned by this table. |
| ... | ... | @@ -2620,6 +2625,8 @@ pub fn deinit(mod: *Module) void { |
| 2620 | 2625 | mod.compile_log_text.deinit(gpa); |
| 2621 | 2626 | |
| 2622 | 2627 | mod.zig_cache_artifact_directory.handle.close(); |
| 2628 | mod.local_zir_cache.handle.close(); |
| 2629 | mod.global_zir_cache.handle.close(); |
| 2623 | 2630 | |
| 2624 | 2631 | mod.deletion_set.deinit(gpa); |
| 2625 | 2632 | |
| ... | ... | @@ -2722,18 +2729,12 @@ pub fn astGenFile(mod: *Module, file: *Scope.File, prog_node: *std.Progress.Node |
| 2722 | 2729 | path_hash.addBytes(file.sub_file_path); |
| 2723 | 2730 | break :hash path_hash.final(); |
| 2724 | 2731 | }; |
| 2725 | | const cache_directory = if (want_local_cache) |
| 2726 | | comp.local_cache_directory |
| 2727 | | else |
| 2728 | | comp.global_cache_directory; |
| 2732 | const cache_directory = if (want_local_cache) mod.local_zir_cache else mod.global_zir_cache; |
| 2733 | const zir_dir = cache_directory.handle; |
| 2729 | 2734 | |
| 2730 | 2735 | var cache_file: ?std.fs.File = null; |
| 2731 | 2736 | defer if (cache_file) |f| f.close(); |
| 2732 | 2737 | |
| 2733 | | // TODO do this before spawning astgen workers |
| 2734 | | var zir_dir = try cache_directory.handle.makeOpenPath("z", .{}); |
| 2735 | | defer zir_dir.close(); |
| 2736 | | |
| 2737 | 2738 | // Determine whether we need to reload the file from disk and redo parsing and AstGen. |
| 2738 | 2739 | switch (file.status) { |
| 2739 | 2740 | .never_loaded, .retryable_failure => cached: { |
| ... | ... | @@ -2899,7 +2900,7 @@ pub fn astGenFile(mod: *Module, file: *Scope.File, prog_node: *std.Progress.Node |
| 2899 | 2900 | else => |e| { |
| 2900 | 2901 | const pkg_path = file.pkg.root_src_directory.path orelse "."; |
| 2901 | 2902 | const cache_path = cache_directory.path orelse "."; |
| 2902 | | log.warn("unable to save cached ZIR code for {s}/{s} to {s}/z/{s}: {s}", .{ |
| 2903 | log.warn("unable to save cached ZIR code for {s}/{s} to {s}/{s}: {s}", .{ |
| 2903 | 2904 | pkg_path, file.sub_file_path, cache_path, &digest, @errorName(e), |
| 2904 | 2905 | }); |
| 2905 | 2906 | return; |
| ... | ... | @@ -3023,7 +3024,7 @@ pub fn astGenFile(mod: *Module, file: *Scope.File, prog_node: *std.Progress.Node |
| 3023 | 3024 | cache_file.?.writevAll(&iovecs) catch |err| { |
| 3024 | 3025 | const pkg_path = file.pkg.root_src_directory.path orelse "."; |
| 3025 | 3026 | const cache_path = cache_directory.path orelse "."; |
| 3026 | | log.warn("unable to write cached ZIR code for {s}/{s} to {s}/z/{s}: {s}", .{ |
| 3027 | log.warn("unable to write cached ZIR code for {s}/{s} to {s}/{s}: {s}", .{ |
| 3027 | 3028 | pkg_path, file.sub_file_path, cache_path, &digest, @errorName(err), |
| 3028 | 3029 | }); |
| 3029 | 3030 | }; |