0
Fork 0
mirror of https://codeberg.org/ziglang/zig synced 2026-11-18 07:05:05 +00:00
zig/lib/std
Andrew Kelley 274555be21 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.
History 2021-12-06 23:30:18 -08:00
..
atomic allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
build Add single section dumping and padding to InstallRawStep 2021-12-03 16:42:02 -08:00
c Added an explicit type for the termios constants (#10266) 2021-12-04 16:24:55 -05:00
compress allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
crypto allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
dwarf std: reorganization that allows new usingnamespace semantics 2021-09-01 17:54:06 -07:00
event allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
fmt remove redundant license headers from zig standard library 2021-08-24 12:25:09 -07:00
fs allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
hash allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
heap std: remove double free in GPA 2021-12-01 15:19:29 -07:00
io allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
json allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
math std/math: hide internal cos/tan functions 2021-12-06 01:17:01 +13:00
mem allocator: Move vtable into gen struct 2021-12-02 11:56:32 -08:00
meta std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
net allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
os Added an explicit type for the termios constants (#10266) 2021-12-04 16:24:55 -05:00
rand Add argument for fillFn to Random.init 2021-10-29 19:20:31 -04:00
special compiler_rt: add __ffssi2, __ffsdi2 and __ffsti2 (#10268) 2021-12-04 16:23:33 -05:00
target update target CPU features with LLVM 13 rc1 data 2021-08-15 23:09:55 -07:00
testing allocgate: change resize to return optional instead of error 2021-11-30 23:45:01 +00:00
Thread libstd: fix bug in std.Thread.Futex selecting incorrect default macOS version 2021-11-25 22:20:32 +01:00
time add functions to decode an epoch timestamp (#9040) 2021-09-14 19:02:23 +03:00
unicode migrate from std.Target.current to @import("builtin").target 2021-10-04 23:48:55 -07:00
valgrind remove redundant license headers from zig standard library 2021-08-24 12:25:09 -07:00
x migrate from std.Target.current to @import("builtin").target 2021-10-04 23:48:55 -07:00
zig std.os: handle ETXTBSY from open() 2021-12-06 16:29:39 -07:00
array_hash_map.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
array_list.zig allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
ascii.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
atomic.zig migrate from std.Target.current to @import("builtin").target 2021-10-04 23:48:55 -07:00
base64.zig std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
bit_set.zig 9944: make allocator the first argument (excl. self) 2021-12-03 16:42:59 -08:00
bounded_array.zig std.bounded_array: fix self parameter type in constSlice 2021-11-20 02:35:36 -05:00
buf_map.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
buf_set.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
build.zig Add emit path options to emit args in build.zig (#10278) 2021-12-05 19:54:33 -05:00
builtin.zig allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
c.zig Add chmod and chown 2021-11-15 20:04:55 -05:00
child_process.zig allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
coff.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
compress.zig remove redundant license headers from zig standard library 2021-08-24 12:25:09 -07:00
comptime_string_map.zig remove redundant license headers from zig standard library 2021-08-24 12:25:09 -07:00
crypto.zig add argon2 kdf (#9756) 2021-11-15 04:47:57 +01:00
cstr.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
debug.zig allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
dwarf.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
dynamic_library.zig std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
elf.zig elf: add amd64 relocation types 2021-09-19 14:02:22 +02:00
enums.zig remove redundant license headers from zig standard library 2021-08-24 12:25:09 -07:00
event.zig std, compiler-rt: remove test names where applicable 2021-09-01 17:54:06 -07:00
fifo.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
fmt.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
fs.zig stage2: improve handling of the generated file builtin.zig 2021-12-06 23:30:18 -08:00
hash.zig remove redundant license headers from zig standard library 2021-08-24 12:25:09 -07:00
hash_map.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
heap.zig allocgate: change resize to return optional instead of error 2021-11-30 23:45:01 +00:00
io.zig std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
json.zig allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
leb128.zig I'm working on a WebAssembly interpreter in zig. WebAssembly uses LEB128 encoding throughout its specification. 2021-09-20 01:58:18 -04:00
linked_list.zig remove redundant license headers from zig standard library 2021-08-24 12:25:09 -07:00
log.zig std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
macho.zig macho: move nlist_64 type/flags helpers to std.macho 2021-11-30 13:59:33 +01:00
math.zig std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
mem.zig allocgate: change resize to return optional instead of error 2021-11-30 23:45:01 +00:00
meta.zig std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
multi_array_list.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
net.zig update function name in error 2021-12-02 12:35:17 -08:00
once.zig std.Thread.Mutex: change API to lock() and unlock() 2021-11-09 18:31:03 -07:00
os.zig std.os: handle ETXTBSY from open() 2021-12-06 16:29:39 -07:00
packed_int_array.zig Better documentation, use of len field instead of function, @bitSizeOf instead of meta.bitCout 2021-10-09 03:15:34 -04:00
pdb.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
priority_dequeue.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
priority_queue.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
process.zig allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
Progress.zig Fix test label off-by-one error (#10277). 2021-12-06 12:18:41 -08:00
rand.zig std lib API deprecations for the upcoming 0.9.0 release 2021-11-30 00:13:07 -07:00
SemanticVersion.zig remove redundant license headers from zig standard library 2021-08-24 12:25:09 -07:00
sort.zig std.rand: Refactor Random interface 2021-10-27 16:07:48 -04:00
start.zig wasm: Update wasm stage2 test backend to use 'main' 2021-11-29 08:05:51 +01:00
start_windows_tls.zig remove redundant license headers from zig standard library 2021-08-24 12:25:09 -07:00
std.zig migrate from std.Target.current to @import("builtin").target 2021-10-04 23:48:55 -07:00
target.zig improve detection of how to execute binaries on the host 2021-12-02 21:51:14 -07:00
testing.zig allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
Thread.zig Merge pull request #9910 from mikdusan/dragonfly 2021-12-03 17:29:55 -08:00
time.zig migrate from std.Target.current to @import("builtin").target 2021-10-04 23:48:55 -07:00
unicode.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
valgrind.zig zig fmt: respect trailing commas in inline assembly 2021-08-29 11:57:32 +02:00
wasm.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00
x.zig remove redundant license headers from zig standard library 2021-08-24 12:25:09 -07:00
zig.zig allocgate: std Allocator interface refactor 2021-11-30 23:32:47 +00:00