aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2023-10-24 01:14:09 -0400
committerGitHub <noreply@github.com>2023-10-24 01:14:09 -0400
commitb798aaf49937568541e8d89eb0be0058871a969f (patch)
tree7671d5a76b00d7d11bed51cac88950fb5ed27324 /src/Compilation.zig
parent794dc694b140908a9affc5b449cda09bbe971cfe (diff)
parentd4911794ae8f43745b2d98a725acf440954f8d90 (diff)
downloadzig-b798aaf49937568541e8d89eb0be0058871a969f.tar.gz
zig-b798aaf49937568541e8d89eb0be0058871a969f.zip
Merge pull request #17687
frontend: rework `@embedFile` for incremental compilation
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig55
1 files changed, 26 insertions, 29 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 1d54456f6b..30dbfe9ce1 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -267,10 +267,6 @@ const Job = union(enum) {
/// It may have already be analyzed, or it may have been determined
/// to be outdated; in this case perform semantic analysis again.
analyze_decl: Module.Decl.Index,
- /// The file that was loaded with `@embedFile` has changed on disk
- /// and has been re-loaded into memory. All Decls that depend on it
- /// need to be re-analyzed.
- update_embed_file: *Module.EmbedFile,
/// The source file containing the Decl has been updated, and so the
/// Decl may need its line number information updated in the debug info.
update_line_number: Module.Decl.Index,
@@ -3374,9 +3370,6 @@ pub fn performAllTheWork(
var win32_resource_prog_node = main_progress_node.start("Compile Win32 Resources", comp.rc_source_files.len);
defer win32_resource_prog_node.end();
- var embed_file_prog_node = main_progress_node.start("Detect @embedFile updates", comp.embed_file_work_queue.count);
- defer embed_file_prog_node.end();
-
comp.work_queue_wait_group.reset();
defer comp.work_queue_wait_group.wait();
@@ -3412,7 +3405,7 @@ pub fn performAllTheWork(
while (comp.embed_file_work_queue.readItem()) |embed_file| {
comp.astgen_wait_group.start();
try comp.thread_pool.spawn(workerCheckEmbedFile, .{
- comp, embed_file, &embed_file_prog_node, &comp.astgen_wait_group,
+ comp, embed_file, &comp.astgen_wait_group,
});
}
@@ -3602,16 +3595,6 @@ fn processOneJob(comp: *Compilation, job: Job, prog_node: *std.Progress.Node) !v
try module.ensureFuncBodyAnalysisQueued(decl.val.toIntern());
}
},
- .update_embed_file => |embed_file| {
- const named_frame = tracy.namedFrame("update_embed_file");
- defer named_frame.end();
-
- const module = comp.bin_file.options.module.?;
- module.updateEmbedFile(embed_file) catch |err| switch (err) {
- error.OutOfMemory => return error.OutOfMemory,
- error.AnalysisFail => return,
- };
- },
.update_line_number => |decl_index| {
const named_frame = tracy.namedFrame("update_line_number");
defer named_frame.end();
@@ -3921,17 +3904,11 @@ fn workerUpdateBuiltinZigFile(
fn workerCheckEmbedFile(
comp: *Compilation,
embed_file: *Module.EmbedFile,
- prog_node: *std.Progress.Node,
wg: *WaitGroup,
) void {
defer wg.finish();
- var child_prog_node = prog_node.start(embed_file.sub_file_path, 0);
- child_prog_node.activate();
- defer child_prog_node.end();
-
- const mod = comp.bin_file.options.module.?;
- mod.detectEmbedFileUpdate(embed_file) catch |err| {
+ comp.detectEmbedFileUpdate(embed_file) catch |err| {
comp.reportRetryableEmbedFileError(embed_file, err) catch |oom| switch (oom) {
// Swallowing this error is OK because it's implied to be OOM when
// there is a missing `failed_embed_files` error message.
@@ -3941,6 +3918,25 @@ fn workerCheckEmbedFile(
};
}
+fn detectEmbedFileUpdate(comp: *Compilation, embed_file: *Module.EmbedFile) !void {
+ const mod = comp.bin_file.options.module.?;
+ const ip = &mod.intern_pool;
+ const sub_file_path = ip.stringToSlice(embed_file.sub_file_path);
+ var file = try embed_file.owner.root.openFile(sub_file_path, .{});
+ defer file.close();
+
+ const stat = try file.stat();
+
+ const unchanged_metadata =
+ stat.size == embed_file.stat.size and
+ stat.mtime == embed_file.stat.mtime and
+ stat.inode == embed_file.stat.inode;
+
+ if (unchanged_metadata) return;
+
+ @panic("TODO: handle embed file incremental update");
+}
+
pub fn obtainCObjectCacheManifest(comp: *const Compilation) Cache.Manifest {
var man = comp.cache_parent.obtain();
@@ -4298,11 +4294,12 @@ fn reportRetryableEmbedFileError(
) error{OutOfMemory}!void {
const mod = comp.bin_file.options.module.?;
const gpa = mod.gpa;
-
- const src_loc: Module.SrcLoc = mod.declPtr(embed_file.owner_decl).srcLoc(mod);
-
+ const src_loc = embed_file.src_loc;
+ const ip = &mod.intern_pool;
const err_msg = try Module.ErrorMsg.create(gpa, src_loc, "unable to load '{}{s}': {s}", .{
- embed_file.mod.root, embed_file.sub_file_path, @errorName(err),
+ embed_file.owner.root,
+ ip.stringToSlice(embed_file.sub_file_path),
+ @errorName(err),
});
errdefer err_msg.destroy(gpa);