aboutsummaryrefslogtreecommitdiff
path: root/src/Cache.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-12-06 16:38:12 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-12-06 23:30:18 -0800
commit274555be21ea756d8480a586f771274a79a58d80 (patch)
treefccbc4b05398e9ea5d29fe1ac88f0b49a0779689 /src/Cache.zig
parenta711fcbbfa41d3f1dedc7ce4be9106e21b6c7ffb (diff)
downloadzig-274555be21ea756d8480a586f771274a79a58d80.tar.gz
zig-274555be21ea756d8480a586f771274a79a58d80.zip
stage2: improve handling of the generated file builtin.zig
All Zig code is eligible to `@import("builtin")` which is mapped to a generated file, build.zig, based on the target and other settings. Zig invocations which share the same target settings will generate the same builtin.zig file and thus the path to builtin.zig is in a shared cache folder, and different projects can sometimes use the same file. Before this commit, this led to race conditions where multiple invocations of `zig` would race to write this file. If one process wanted to *read* the file while the other process *wrote* the file, the reading process could observe a truncated or partially written builtin.zig file. This commit makes the following improvements: - limitations: - avoid clobbering the inode, mtime in the hot path - avoid creating a partially written file - builtin.zig needs to be on disk for debug info / stack trace purposes - don't mark the task as complete until the file is finished being populated (possibly by an external process) - strategy: - create the `@import("builtin")` `Module.File` during the AstGen work, based on generating the contents in memory rather than loading from disk. - write builtin.zig in a separate task that doesn't have to complete until the end of the AstGen work queue so that it can be done in parallel with everything else. - when writing the file, first stat the file path. If it exists, we are done. - otherwise, write the file to a temp file in the same directory and atomically rename it into place (clobbering the inode, mtime in the cold path). - summary: - all limitations respected - hot path: one stat() syscall that happens in a worker thread This required adding a missing function to the standard library: `std.fs.Dir.statFile`. In this commit, it does open() and then fstat() which is two syscalls. It should be improved in a future commit to only make one. Fixes #9439.
Diffstat (limited to 'src/Cache.zig')
0 files changed, 0 insertions, 0 deletions