aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
AgeCommit message (Collapse)Author
2021-01-16stage2: implement error notes and regress -femit-zirAndrew Kelley
* Implement error notes - note: other symbol exported here - note: previous else prong is here - note: previous '_' prong is here * Add Compilation.CObject.ErrorMsg. This object properly converts to AllErrors.Message when the time comes. * Add Compilation.CObject.failure_retryable. Properly handles out-of-memory and other transient failures. * Introduce Module.SrcLoc which has not only a byte offset but also references the file which the byte offset applies to. * Scope.Block now contains both a pointer to the "owner" Decl and the "source" Decl. As an example, during inline function call, the "owner" will be the Decl of the caller and the "source" will be the Decl of the callee. * Module.ErrorMsg now sports a `file_scope` field so that notes can refer to source locations in a file other than the parent error message. * Some instances where a `*Scope` was stored, now store a `*Scope.Container`. * Some methods in the `Scope` namespace were moved to the more specific type, since there was only an implementation for one particular tag. - `removeDecl` moved to `Scope.Container` - `destroy` moved to `Scope.File` * Two kinds of Scope deleted: - zir_module - decl * astgen: properly use DeclVal / DeclRef. DeclVal was incorrectly changed to be a reference; this commit fixes it. Fewer ZIR instructions processed as a result. - declval_in_module is renamed to declval - previous declval ZIR instruction is deleted; it was only for .zir files. * Test harness: friendlier diagnostics when an unexpected set of errors is encountered. * zir_sema: fix analyzeInstBlockFlat by properly calling resolvingInst on the last zir instruction in the block. Compile log implementation: * Write to a buffer rather than directly to stderr. * Only keep track of 1 callsite per Decl. * No longer mutate the ZIR Inst struct data. * "Compile log statement found" errors are only emitted when there are no other compile errors. -femit-zir and support for .zir source files is regressed. If we wanted to support this again, outputting .zir would need to be done as yet another backend rather than in the haphazard way it was previously implemented. For parsing .zir, it was implemented previously in a way that was not helpful for debugging. We need tighter integration with the test harness for it to be useful; so clearly a rewrite is needed. Given that a rewrite is needed, and it was getting in the way of progress and organization of the rest of stage2, I regressed the feature.
2021-01-14organize std lib concurrency primitives and add RwLockAndrew Kelley
* move concurrency primitives that always operate on kernel threads to the std.Thread namespace * remove std.SpinLock. Nobody should use this in a non-freestanding environment; the other primitives are always preferable. In freestanding, it will be necessary to put custom spin logic in there, so there are no use cases for a std lib version. * move some std lib files to the top level fields convention * add std.Thread.spinLoopHint * add std.Thread.Condition * add std.Thread.Semaphore * new implementation of std.Thread.Mutex for Windows and non-pthreads Linux * add std.Thread.RwLock Implementations provided by @kprotty
2021-01-11stage2: cleanups regarding red zone CLI flagsAndrew Kelley
* CLI: change to -mred-zone and -mno-red-zone to match gcc/clang. * build.zig: remove the double negative and make it an optional bool. This follows precedent from other flags, allowing the compiler CLI to be the decider of what is default instead of duplicating the default value into the build system code. * Compilation: make it an optional `want_red_zone` instead of a `no_red_zone` bool. The default is decided by a call to `target_util.hasRedZone`. * When creating a Clang command line, put -mred-zone on the command line if we are forcing it to be enabled. * Update update_clang_options.zig with respect to the recent {s}/{} format changes. * `zig cc` integration with red zone preference.
2021-01-11Added support for no red zoneLee Cannon
2021-01-09builtin: Add zig_versionJay Petacat
This will enable code to perform version checks and make it easier to support multiple versions of Zig. Within the SemVer implementation, an intermediate value needed to be coerced to a slice to workaround a comptime bug. Closes #6466
2021-01-07remove z/Z format specifiersJonathan Marler
Zig's format system is flexible enough to add custom formatters. This PR removes the new z/Z format specifiers that were added for printing Zig identifiers and replaces them with custom formatters.
2021-01-07Reduce use of deprecated IO typesJay Petacat
Related: #4917
2021-01-06stage2: update to new ArrayListHashMap APIAndrew Kelley
2021-01-06Merge pull request #7622 from tetsuo-cpp/array-hash-map-improvementsAndrew Kelley
std: Support equivalent ArrayList operations in ArrayHashMap
2021-01-06Merge pull request #7700 from FireFox317/more-stage2-stuff-llvmAndrew Kelley
stage2: improvements to LLVM backend
2021-01-06stage2: C backend: support unused DeclsAndrew Kelley
2021-01-06stage2: rename and move files related to LLVM backendTimon Kruiper
2021-01-05stage2: add compile log statementg-w1
2021-01-05minor fixups from moving identifiers and files aroundAndrew Kelley
2021-01-05stage2: C backend: re-implement emit-hAndrew Kelley
and also mark functions as `extern "C"` as appropriate to support c++ compilers.
2021-01-05stage2: rework the C backendAndrew Kelley
* std.ArrayList gains `moveToUnmanaged` and dead code `ArrayListUnmanaged.appendWrite` is deleted. * emit_h state is attached to Module rather than Compilation. * remove the implementation of emit-h because it did not properly integrate with incremental compilation. I will re-implement it in a follow-up commit. * Compilation: use the .codegen_failure tag rather than .dependency_failure tag for when `bin_file.updateDecl` fails. C backend: * Use a CValue tagged union instead of strings for C values. * Cleanly separate state into Object and DeclGen: - Object is present only when generating a .c file - DeclGen is present for both generating a .c and .h * Move some functions into their respective Object/DeclGen namespace. * Forward decls are managed by the incremental compilation frontend; C backend no longer renders function signatures based on callsites. For simplicity, all functions always get forward decls. * Constants are managed by the incremental compilation frontend. C backend no longer has a "constants" section. * Participate in incremental compilation. Each Decl gets an ArrayList for its generated C code and it is updated when the Decl is updated. During flush(), all these are joined together in the output file. * The new CValue tagged union is used to clean up using of assigning to locals without an additional pointer local. * Fix bug with bitcast of non-pointers making the memcpy destination immutable.
2021-01-06std: Rename ArrayList shrink => shrinkAndFreeAlex Cameron
2021-01-04ci: omit stage2 backend from stage1 on WindowsAndrew Kelley
to avoid out-of-memory on the CI runs.
2021-01-03stage2: add some missing deallocations in Compilation.zigTimon Kruiper
2021-01-02stage2: re-use ZIR for comptime and inline callsAndrew Kelley
Instead of freeing ZIR after semantic analysis, we keep it around so that it can be used for comptime calls, inline calls, and generic function calls. ZIR memory is now managed by the Decl arena. Debug dump() functions are conditionally compiled; only available in Debug builds of the compiler. Add a test for an inline function call.
2021-01-02stage2: implement function call inlining in the frontendAndrew Kelley
* remove the -Ddump-zir thing. that's handled through --verbose-ir * rework Fn to have an is_inline flag without requiring any more memory on the heap per function. * implement a rough first version of dumping typed zir (tzir) which is a lot more helpful for debugging than what we had before. We don't have a way to parse it though. * keep track of whether the inline-ness of a function changes because if it does we have to go update callsites. * add compile error for inline and export used together. inline function calls and comptime function calls are implemented the same way. A block instruction is set up to capture the result, and then a scope is set up that has a flag for is_comptime and some state if the scope is being inlined. when analyzing `ret` instructions, zig looks for inlining state in the scope, and if found, treats `ret` as a `break` instruction instead, with the target block being the one set up at the inline callsite. Follow-up items: * Complete out the debug TZIR dumping code. * Don't redundantly generate ZIR for each inline/comptime function call. Instead we should add a new state enum tag to Fn. * comptime and inlining branch quotas. * Add more test cases.
2021-01-02convert more {} to {d} and {s}Andrew Kelley
2021-01-02stage2: Use {z} instead of {s} in generated Zig codeLemonBoy
2021-01-02stage2: Use {s} instead of {} when formatting stringsLemonBoy
2021-01-02Duplicate OSAtomic.h between aarch64 and x86_64Jakub Konka
The reason this is required is for two reasons: 1) the libc targeting `aarch64` macOS is slightly newer than that targeting `x86_64`, and 2) `OSAtomic.h` uses relative imports rather than system-wide imports for accompanying headers which clearly is an oversight on Apple's part. Until such time when `libkern` headers between `x86_64` and `aarch64` are identical, this will require a manual intervention to duplicate the relevant headers between the respective architectures.
2021-01-02Detect native iframework dirs on macOSJakub Konka
This commit adds default search paths for system frameworks on macOS while also adding `-isysroot` for OS versions at least BigSur. Since BigSur (11.0.1), neither headers nor libs exist in standard root locations (`/usr/include`, `/System/Library/Frameworks`). Instead, they are now exclusively part of the installed developer toolchain (either via XCode.app or CLT), and specifying `-isysroot` allows us to keep using universal search paths such as `/System/Library/Frameworks` while only changing the include flag from `-iframework` to `-iframeworkwithsysroot`.
2020-12-30stage2: rework Value Payload layoutAndrew Kelley
This is the same as the previous commit but for Value instead of Type. Add `Value.castTag` and note that it is preferable to call than `Value.cast`. This matches other abstractions in the codebase. Added a convenience function `Value.Tag.create` which really cleans up the callsites of creating `Value` objects. `Value` tags can now share payload types. This is in preparation for another improvement that I want to do.
2020-12-30stage2: rework Type Payload layoutAndrew Kelley
Add `Type.castTag` and note that it is preferable to call than `Type.cast`. This matches other abstractions in the codebase. Added a convenience function `Type.Tag.create` which really cleans up the callsites of creating `Type` objects. `Type` payloads can now share types. This is in preparation for another improvement that I want to do.
2020-12-28stage2: better error message for root zig source file not foundAndrew Kelley
closes #6777 closes #6893
2020-12-28stage2: add extern functionsAndrew Kelley
and improve the C backend enough to support Hello World (almost)
2020-12-28stage2: add initial impl of LLVM backend in self-hosted compilerTimon Kruiper
2020-12-28Revert "stage2: add compile log statement (#7191)"Andrew Kelley
The addition of `addDeclErr` introduced a memory leak at every call site, and I also would like to push back on having more than 1 compilation error per `Decl`. This reverts commit 1634d45f1d53c8d7bfefa56ab4d2fa4cc8218b6d.
2020-12-26stage2: add compile log statement (#7191)g-w1
2020-12-24stage2: re-use compiler runtime libs across opt modes and strip flagAndrew Kelley
Previously Zig would need to recompile runtime libs if you changed the values of --strip or -O. Now, unless the `debug_compiler_runtime_libs` flag is set (which is currently not exposed to the CLI), Zig will always choose ReleaseFast or ReleaseSmall for compiler runtime libraries. When the main application chooses ReleaseFast or ReleaseSmall, that value is propagated to compiler runtime libraries. Otherwise a decision is made based on the target, which is currently ReleaseSmall for freestanding WebAssembly and ReleaseFast for everything else. Ultimately the purpose of this commit is to have Debug and ReleaseSafe builds of applications still get optimized builds of, e.g. libcxx and libunwind, as well as to spend less time unnecessarily rebuilding compiler runtime libraries.
2020-12-24stage2: tsan forces linking libcAndrew Kelley
2020-12-24zig cc: support both ubsan and tsan at the same timeAndrew Kelley
2020-12-24stage2: fix Cache deadlock and build more of TSANAndrew Kelley
* rename is_compiler_rt_or_libc to skip_linker_dependencies and set it to `true` for all sub-Compilations. I believe this resolves the deadlock we were experiencing on Drone CI and on some users' computers. I will remove the CI workaround in a follow-up commit. * enabling TSAN automatically causes the Compilation to link against libc++ even if not requested, because TSAN depends on libc++. * add -fno-rtti flags where appropriate when building TSAN objects. Thanks Firefox317 for pointing this out. * TSAN support: resolve all the undefined symbols. We are still seeing a dependency on __gcc_personality_v0 but will resolve this one in a follow-up commit. * static libs do not try to build libc++ or libc++abi.
2020-12-24WIP start adding support for TSANAndrew Kelley
2020-12-23rework std.ResetEvent, improve std lib Darwin integrationAndrew Kelley
* split std.ResetEvent into: - ResetEvent - requires init() at runtime and it can fail. Also requires deinit(). - StaticResetEvent - can be statically initialized and requires no deinitialization. Initialization cannot fail. * the POSIX sem_t implementation can in fact fail on initialization because it is allowed to be implemented as a file descriptor. * Completely define, clarify, and explain in detail the semantics of these APIs. Remove the `isSet` function. * `ResetEvent.timedWait` returns an enum instead of a possible error. * `ResetEvent.init` takes a pointer to the ResetEvent instead of returning a copy. * On Darwin, `ResetEvent` is implemented using Grand Central Dispatch, which is exposed by libSystem. stage2 changes: * ThreadPool: use a single, pre-initialized `ResetEvent` per worker. * WaitGroup: now requires init() and deinit() and init() can fail. - Add a `reset` function. - Compilation initializes one for the work queue in creation and re-uses it for every update. - Rename `stop` to `finish`. - Simplify the implementation based on the usage pattern.
2020-12-23Add emit_h path to compilation hash.Alex Cameron
2020-12-23Fix memory leakNoam Preil
2020-12-23Remove redundant emit_h member in Compilation struct.Alex Cameron
2020-12-23Implement emit-hAlex Cameron
2020-12-20add an option to compile zig in single-threaded modeAndrew Kelley
And enable it for Drone CI. I hate to do this, but I need to make progress on other fronts.
2020-12-20std.Progress: make the API thread-safeAndrew Kelley
We generally get away with atomic primitives, however a lock is required around the refresh function since it traverses the Node graph, and we need to be sure no references to Nodes remain after end() is called.
2020-12-20use kprotty's ThreadPool implementation (v5)Andrew Kelley
2020-12-20stage2: protect mutable state from data races in updateCObjectAndrew Kelley
2020-12-18std: introduce a thread-local CSPRNG for general useAndrew Kelley
std.crypto.random * cross platform, even freestanding * can't fail. on initialization for some systems requires calling os.getrandom(), in which case there are rare but theoretically possible errors. The code panics in these cases, however the application may choose to override the default seed function and then handle the failure another way. * thread-safe * supports the full Random interface * cryptographically secure * no syscall required to initialize on Linux (AT_RANDOM) * calls arc4random on systems that support it `std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`. I moved some of the Random implementations into their own files in the interest of organization. stage2 no longer requires passing a RNG; instead it uses this API. Closes #6704
2020-12-16stage2: add test_evented_io to cache hashAndrew Kelley
2020-12-13stage2: link musl dynamically by default if nativeIsaac Freund
If targeting the native OS and the system libc is musl, link against it dynamically by default.