aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
AgeCommit message (Collapse)Author
2024-08-13comp: actually report codegen errorsJakub Konka
2024-08-12all: Handle spirv in addition to spirv(32,64) where applicable.Alex Rønne Petersen
Some of this is arbitrary since spirv (as opposed to spirv32/spirv64) refers to the version with logical memory layout, i.e. no 'real' pointers. This change at least matches what clang does.
2024-08-11compiler: split Decl into Nav and Caumlugg
The type `Zcu.Decl` in the compiler is problematic: over time it has gained many responsibilities. Every source declaration, container type, generic instantiation, and `@extern` has a `Decl`. The functions of these `Decl`s are in some cases entirely disjoint. After careful analysis, I determined that the two main responsibilities of `Decl` are as follows: * A `Decl` acts as the "subject" of semantic analysis at comptime. A single unit of analysis is either a runtime function body, or a `Decl`. It registers incremental dependencies, tracks analysis errors, etc. * A `Decl` acts as a "global variable": a pointer to it is consistent, and it may be lowered to a specific symbol by the codegen backend. This commit eliminates `Decl` and introduces new types to model these responsibilities: `Cau` (Comptime Analysis Unit) and `Nav` (Named Addressable Value). Every source declaration, and every container type requiring resolution (so *not* including `opaque`), has a `Cau`. For a source declaration, this `Cau` performs the resolution of its value. (When #131 is implemented, it is unsolved whether type and value resolution will share a `Cau` or have two distinct `Cau`s.) For a type, this `Cau` is the context in which type resolution occurs. Every non-`comptime` source declaration, every generic instantiation, and every distinct `extern` has a `Nav`. These are sent to codegen/link: the backends by definition do not care about `Cau`s. This commit has some minor technically-breaking changes surrounding `usingnamespace`. I don't think they'll impact anyone, since the changes are fixes around semantics which were previously inconsistent (the behavior changed depending on hashmap iteration order!). Aside from that, this changeset has no significant user-facing changes. Instead, it is an internal refactor which makes it easier to correctly model the responsibilities of different objects, particularly regarding incremental compilation. The performance impact should be negligible, but I will take measurements before merging this work into `master`. Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com> Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2024-08-08Compilation: Mark .c++ files as having C++ extensionsin-ack
Some projects, such as Cap'n Proto, use .c++ as their filenames. Without this, compiling them fails because zig c++ will fall back to using the linker.
2024-08-07Compilation: fix -femit-docsAndrew Kelley
2024-08-07Compilation: fix not showing sub-errors for autodocsAndrew Kelley
2024-07-29compiler: Enable -Werror=date-time for C/C++ code in release builds.Alex Rønne Petersen
We advertise reproducible builds for release modes, so let's help users achieve that in C/C++ code. Users can still override this manually if they really want.
2024-07-28link: Accept `-Brepro` linker option and pass it to LLD.Alex Rønne Petersen
Enable it by default when building Zig code in release modes. Contributes to #9432.
2024-07-28Merge pull request #20807 from Rexicon226/riscvJakub Konka
riscv: more backend progress
2024-07-26comp: enable compilation of zig_libcDavid Rubin
2024-07-26frontend: add missed cache hash on --debug-rtAndrew Kelley
Makes adding --debug-rt correctly invalidate the cache for compiler_rt and libfuzzer.
2024-07-25add --debug-rt CLI arg to the compiler + bonus editsAndrew Kelley
The flag makes compiler_rt and libfuzzer be in debug mode. Also: * fuzzer: override debug logs and disable debug logs for frequently called functions * std.Build.Fuzz: fix bug of rerunning the old unit test binary * report errors from rebuilding the unit tests better * link.Elf: additionally add tsan lib and fuzzer lib to the hash
2024-07-24add sub-compilation cache inputs to parents in whole modeAndrew Kelley
closes #20782
2024-07-24Compilation: build compiler_rt and fuzzer in parallelAndrew Kelley
With the rest of the pipeline. Tracked by #9188
2024-07-23default "trace pc guard" coverage offAndrew Kelley
* Add -f(no-)sanitize-coverage-trace-pc-guard CLI flag which defaults to off. This value lowers to TracePCGuard = true (LLVM backend) and -Xclang -fsanitize-coverage-trace-pc-guard. These settings are not automatically included with -ffuzz. * Add `Build.Step.Compile` flag for sanitize_coverage_trace_pc_guard with appropriate documentation. * Add `zig cc` integration for the respective flags. * Avoid crashing in ELF linker code when -ffuzz -femit-llvm-ir used together.
2024-07-23LLVM: more fine-grained sancov emit optionsAndrew Kelley
Exposes sanitizer coverage flags to the target machine emit function. Makes it easier to change sancov options without rebuilding the C++ files. This also enables PCTable = true for sancov which is needed by AFL, and adds the corresponding Clang flag.
2024-07-23Merge pull request #20725 from ziglang/fuzzAndrew Kelley
initial support for integrated fuzzing
2024-07-22Compilation: fix regression in addCCArgsAndrew Kelley
`-fno-sanitize=function` must come after `-fsanitize=undefined` or it has no effect.
2024-07-22initial support for integrated fuzzingAndrew Kelley
* Add the `-ffuzz` and `-fno-fuzz` CLI arguments. * Detect fuzz testing flags from zig cc. * Set the correct clang flags when fuzz testing is requested. It can be combined with TSAN and UBSAN. * Compilation: build fuzzer library when needed which is currently an empty zig file. * Add optforfuzzing to every function in the llvm backend for modules that have requested fuzzing. * In ZigLLVMTargetMachineEmitToFile, add the optimization passes for sanitizer coverage. * std.mem.eql uses a naive implementation optimized for fuzzing when builtin.fuzz is true. Tracked by #20702
2024-07-22macho: redo input file parsing in prep for multithreadingJakub Konka
2024-07-20Merge pull request #20688 from ziglang/incr-testAndrew Kelley
introduce a new tool for testing incremental compilation
2024-07-20dev: fix llvm backend checksJacob Young
2024-07-20add std.fmt.hexAndrew Kelley
converts an unsigned integer into an array
2024-07-19dev: introduce dev environments that enable compiler feature setsJacob Young
2024-07-15update some Module references to Zcu insteadAndrew Kelley
I ended up reverting my real change, so here's a consolation prize instead.
2024-07-15frontend: move updateZirRefs to be single-threadedAndrew Kelley
for simplicity's sake. This makes it O(M) instead of O(N*M) where N is tracked insts and M is number of changed source files.
2024-07-14frontend: add -fincremental, -fno-incremental flagAndrew Kelley
Remove --debug-incremental This flag is also added to the build system. Importantly, this tells Compile step whether or not to keep the compiler running between rebuilds. It defaults off because it is currently crashing zirUpdateRefs.
2024-07-14make zig compiler processes live across rebuildsAndrew Kelley
Changes the `make` function signature to take an options struct, which additionally includes `watch: bool`. I intentionally am not exposing this information to configure phase logic. Also adds global zig cache to the compiler cache prefixes. Closes #20600
2024-07-14Merge pull request #20593 from jacobly0/more-racesAndrew Kelley
InternPool: fix more races
2024-07-13frontend: report correct paths for C objectsAndrew Kelley
oops, the src_path field of CObject is not relative to the module owner's root directory.
2024-07-13Compilation: restore `saveState`Jacob Young
2024-07-13Compilation: introduce work stages for better work distributionJacob Young
2024-07-13InternPool: add and use a mutate mutex for each listJacob Young
This allows the mutate mutex to only be locked during actual grows, which are rare. For the lists that didn't previously have a mutex, this change has little effect since grows are rare and there is zero contention on a mutex that is only ever locked by one thread. This change allows `extra` to be mutated without racing with a grow.
2024-07-12Compilation: fix rebase conflictAndrew Kelley
2024-07-12frontend: add file system inputs for incremental cache modeAndrew Kelley
These are also used for whole cache mode in the case that any compile errors are emitted.
2024-07-12integrate Compile steps with file watchingAndrew Kelley
Updates the build runner to unconditionally require a zig lib directory parameter. This parameter is needed in order to correctly understand file system inputs from zig compiler subprocesses, since they will refer to "the zig lib directory", and the build runner needs to place file system watches on directories in there. The build runner's fanotify file watching implementation now accounts for when two or more Cache.Path instances compare unequal but ultimately refer to the same directory in the file system. Breaking change: std.Build no longer has a zig_lib_dir field. Instead, there is the Graph zig_lib_directory field, and individual Compile steps can still have their zig lib directories overridden. I think this is unlikely to break anyone's build in practice. The compiler now sends a "file_system_inputs" message to the build runner which shares the full set of files that were added to the cache system with the build system, so that the build runner can watch properly and redo the Compile step. This is implemented for whole cache mode but not yet for incremental cache mode.
2024-07-10Compilation: fix leakJacob Young
2024-07-10InternPool: make `global_error_set` thread-safeJacob Young
2024-07-10InternPool: make `tracked_insts` thread-safeJacob Young
2024-07-10InternPool: make `files` more thread-safeJacob Young
2024-07-10InternPool: add `FileIndex` to `*File` mappingJacob Young
2024-07-08Compilation: put supported codegen backends on a separate threadJacob Young
(There are no supported backends.)
2024-07-07InternPool: implement and use thread-safe list for extra and limbsJacob Young
2024-07-07InternPool: implement and use thread-safe list for itemsJacob Young
2024-07-07InternPool: implement and use thread-safe list for stringsJacob Young
2024-07-07InternPool: implement thread-safe hash mapJacob Young
2024-07-07Zcu: pass `PerThread` to intern pool string functionsJacob Young
2024-07-07Zcu: introduce `PerThread` and pass to all the functionsJacob Young
2024-07-04frontend: TrackedInst stores FileIndex instead of path digestAndrew Kelley
The purpose of using path digest was to reference a file in a serializable manner. Now that there is a stable index associated with files, it is a superior way to accomplish that goal, since removes one layer of indirection, and makes TrackedInst 8 bytes instead of 20. The saved Zig Compiler State file for "hello world" goes from 1.3M to 1.2M with this change.
2024-07-04Zcu: extract permanent state from FileAndrew Kelley
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.