aboutsummaryrefslogtreecommitdiff
path: root/src/Module.zig
AgeCommit message (Collapse)Author
2022-12-14stage2: remove `pub` from a private functionAndrew Kelley
2022-12-14std.fs.Dir.statFile reworkAndrew Kelley
* revert changes to Module because the error set is consistent across operating systems. * remove duplicated Stat.fromSystem code and use a less redundant name. * make fs.Dir.statFile follow symlinks, and avoid pointless control flow through the posix layer.
2022-12-14std.fs.Dir.statFile: use fstatatPhilippe Pittoli
This avoids extra syscalls.
2022-12-14Sema: display cimport errors from clangVeikka Tuominen
2022-12-11Add a helpful note when using `**` on number types. (#13871)IntegratedQuantum
2022-12-06remove most conditional compilation based on stage1Andrew Kelley
There are still a few occurrences of "stage1" in the standard library and self-hosted compiler source, however, these instances need a bit more careful inspection to ensure no breakage.
2022-12-02Sema: add error for failed assumption about struct having runtime bitsVeikka Tuominen
2022-11-29std.mem.Allocator: allow shrink to failAndrew Kelley
closes #13535
2022-11-28CLI: more careful resolution of pathsAndrew Kelley
In general, we prefer compiler code to use relative paths based on open directory handles because this is the most portable. However, sometimes absolute paths are used, and sometimes relative paths are used that go up a directory. The recent improvements in 81d2135ca6ebd71b8c121a19957c8fbf7f87125b regressed the use case when an absolute path is used for the zig lib directory mixed with a relative path used for the root source file. This could happen when, for example, running the standard library tests, like this: stage3/bin/zig test ../lib/std/std.zig This happened because the zig lib dir was inferred to be an absolute directory based on the zig executable directory, while the root source file was detected as a relative path. There was no common prefix and so it was not determined that the std.zig file was inside the lib directory. This commit adds a function for resolving paths that preserves relative path names while allowing absolute paths, and converting relative upwards paths (e.g. "../foo") to absolute paths. This restores the previous functionality while remaining compatible with systems such as WASI that cannot deal with absolute paths.
2022-11-27Use a slice for InstMap instead of std.HashMapJimmi Holst Christensen
The `sema.inst_map` datastructure is very often accessed. All instructions that reference the result of other instructions does a lookup into this field. Because of this, a significant amount of time, is spent in `std.HashMap.get`. This commit replaces the `HashMap` with a simpler data structure that uses the zir indexes to index into a slice for the result. See the data structure doc comment for more info.
2022-11-23Sema: implement tuple declarationsVeikka Tuominen
2022-11-23AstGen: implement tuple declarationsVeikka Tuominen
2022-11-20Module: fix compile error for non-comptime-known global initializerVeikka Tuominen
2022-11-20Module: fix `fieldSrcLoc` for generated typesVeikka Tuominen
2022-11-16Module: call `ensureDeclAnalyzed` on `builtin.test_functions`Veikka Tuominen
Previously the compiler would crash on branching on undefined values if you tried using `zig test` with a freestanding target since there was no start code referencing `builtin.test_functions`. Closes #12554
2022-11-13Sema: remove `block` and `src` parameters from `getBuiltin`Veikka Tuominen
These parameters are only ever needed when `std.builtin` is out of sync with the compiler in which case panicking is the only valid operation anyways. Removing them causes a domino effect of functions no longer needing a `src` and/or a `block` parameter resulting in handling compilation errors where they are actually meaningful becoming simpler.
2022-11-04Sema: make `InferredErrorSet` deterministicJacob Young
Empirically, this `AutoHashMapUnmanaged` -> `AutoArrayHashMapUnmanaged` change fixes all non-determinism in `ReleaseFast` build artifacts. Closes #12183
2022-10-30re-apply "Fix C include files not being in `whole` cache (#11365)"Andrew Kelley
This reverts commit 06310e3d4eb47fed88b175891cb5865bb050f020, reapplying commit a430630002bf02162ccbf8d3eb10fd73e490cefd. I deeply apologize to @moosichu and those affected by this bug. The original fix was actually fine. When I reverted it, I misremembered how the Cache API works. I thought the fix was going to introduce nondeterminism into the hash, but I forgot that the order of files in the manifest doesn't actually matter when checking for a cache hit. Actually, it does matter a little bit. This fix has a subtle downside which is that it does introduce the possibility of false negatives when checking for cache hits of 2+ iterations ago. For example, if the code goes from "foo", to "bar", and then back to "foo", it may look like a cache miss when it should have been a hit because 2 iterations ago the code was the same. However, this is an uncommon use case, and all it does is cause a bit of wasted time and disk space. That said, my suggestion from earlier still applies and would be a nice follow-up enhancement to this fix: The proper solution to this is to, in whole cache mode, append the hash inputs to some data structure, and then after the compilation is complete, do some kind of sorting on the hash inputs so that they will be the same order every time, then apply them in sequence. No lock on the Cache object is needed for this scheme. closes #11063
2022-10-27remove test case triggering generic deletion bugVeikka Tuominen
This test should be restored once the underlying issue is resolved (with the typo fixed).
2022-10-27Module: mitigate generic deletion bugVeikka Tuominen
2022-10-21Change how `Block` propagates (error return) trace indexCody Tapscott
Instead of adding 3 fields to every `Block`, this adds just one. The function-level information is saved in the `Sema` struct instead, which is created/copied more rarely.
2022-10-21stage2: Keep error return traces alive when storing to `const`Cody Tapscott
This change extends the "lifetime" of the error return trace associated with an error to continue throughout the block of a `const` variable that it is assigned to. This is necessary to support patterns like this one in test_runner.zig: ```zig const result = foo(); if (result) |_| { // ... success logic } else |err| { // `foo()` should be included in the error trace here return error.TestFailed; } ``` To make this happen, the majority of the error return trace popping logic needed to move into Sema, since `const x = foo();` cannot be examined syntactically to determine whether it modifies the error return trace. We also have to make sure not to delete pertinent block information before it makes it to Sema, so that Sema can pop/restore around blocks correctly. * Why do this only for `const` and not `var`? * There is room to relax things for `var`, but only a little bit. We could do the same thing we do for const and keep the error trace alive for the remainder of the block where the *assignment* happens. Any wider scope would violate the stack discipline for traces, so it's not viable. In the end, I decided the most consistent behavior for the user is just to kill all error return traces assigned to a mutable `var`.
2022-10-21Merge pull request #13219 from Vexu/stage2-fixesVeikka Tuominen
Stage2 bug fixes
2022-10-20stage2: improve source location of assignmentVeikka Tuominen
2022-10-19Sema: remove unresolved inferred allocsVeikka Tuominen
Closes #2557
2022-10-18all: rename `@maximum` to `@max` and `@minimum` to `@min`Ali Chraghi
2022-10-18Sema: implement linksection on functionsjacobly0
* Sema: implement linksection on functions * Implement function linksection in Sema. * Don't clobber function linksection/align/addrspace in Sema. * Fix copy-paste typo in tests. * Add a bunch of missing test_step.dependOn. * Fix checkInSymtab match. Closes #12546
2022-10-15Module: fix early exit conditions during compilationJacob Young
* `--verbose-llvm-ir` should trigger analysis and codegen * `-femit-asm` etc should trigger codegen even with `-fno-emit-bin` Closes #12588
2022-10-15sanitize qualified name for nvptx backendGuillaume Wenzek
2022-10-12stage2: add @addrSpaceCast builtinRobin Voetter
2022-10-12Merge pull request #13081 from r00ster91/docsAndrew Kelley
fix(text): hyphenation and other fixes
2022-10-05fix(text): hyphenate "runtime" adjectivesr00ster91
2022-10-05fix(text): hyphenate "comptime" adjectivesr00ster91
2022-10-05Merge pull request #13071 from ziglang/resolve-cache-filesAndrew Kelley
stage2: resolve file before putting them into cache
2022-10-05Fix all std lib tests being run for any file within the std packageRyan Liptak
Before this commit: ``` $ zig test lib/std/fs/test.zig --main-pkg-path lib/std --zig-lib-dir lib 2170 passed; 37 skipped; 0 failed. ``` After this commit: ``` $ zig test lib/std/fs/test.zig --main-pkg-path lib/std --zig-lib-dir lib All 45 tests passed. ``` This matches stage1 behavior: ``` $ zig test -fstage1 lib/std/fs/test.zig --main-pkg-path lib/std --zig-lib-dir lib All 45 tests passed. ``` All tests are still run if `zig test` is run directly on `lib/std/std.zig`: ``` $ zig test lib/std/std.zig --main-pkg-path lib/std --zig-lib-dir lib 2170 passed; 37 skipped; 0 failed. ``` `zig build test-std` is unaffected by this change. Closes #12926
2022-10-05stage2: resolve file before putting them into cacheAndrew Kelley
This was an accidental misuse of the Cache API which intends to call resolve on all file paths going into it. This one callsite was failing to do that; fixed now. Fixes relative file paths from making it into the global cache manifest. See #13050
2022-10-03Merge pull request #12979 from Vexu/inline-switchAndrew Kelley
Implement inline switch cases
2022-10-01Sema: avoid undefined fields in file struct declsJacob Young
Fixes original comment of #12399
2022-09-30stage2: improve error message for missing member in file root structVeikka Tuominen
* the root struct decl name is fully qualified this prevents error messages containing 'main.main' * avoid declared here note when file struct is missing a member It always points at the start of the file which might contain another container misleading the user.
2022-09-27Sema: implement non-special inline switch prongsVeikka Tuominen
2022-09-15stage2: implement referenced by trace for error messagesVeikka Tuominen
Closes #7668 Closes #12141
2022-09-08Sema: fix UAF in zirClosureGetVeikka Tuominen
Previously if a decl failed its capture scope would be deallocated and set to undefined which would then lead to invalid dereference in `zirClosureGet`. To avoid this set the capture scope to a special failed state and fail the current decl with dependency failure if the failed state is encountered in `zirClosureGet`. Closes #12433 Closes #12530 Closes #12593
2022-09-07build-exe: allow combination of -fno-emit-bin and --verbose-airbfredl
Currently, `zig build-exe -fno-emit-bin --verbose-air src/main.zig` results in no output at all. With this refactor, it dumps AIR and then exits without invoking LLVM, as expected
2022-09-02Sema: remove unused src param from typeRequiresComptimeVeikka Tuominen
2022-08-30Sema: prevent access of undefined fieldsAndrew Kelley
When instantiating a generic function, there is a period of time where the function is inserted into monomorphed_funcs map, but is not yet initialized. Despite semantic analysis being single-threaded, generic function instantiation can happen recursively, meaning that the hash and equality functions for monomorphed_funcs entries are potentially invoked for an uninitialized function. This problem was mitigated by pre-setting the hash field on the newly allocated function, however it did not solve the problem for hash collisions in which case the equality function would be invoked. That it was solved for hash() but not eql() explains why the problem was difficult to observe. I tested this patch by temporarily sabotaging the hash and making it always return 0. This fix is centered on adding a new field to Module.Fn which is the one checked by eql() and is populated pre-initialization. closes #12643
2022-08-30coff: add missing bits required for minimal PE exampleJakub Konka
2022-08-30coff: reorganize the linkerJakub Konka
2022-08-24stage2: explicitly tagged enums no longer have one possible valueAndrew Kelley
Previously, Zig had inconsistent semantics for an enum like this: `enum(u8){zero = 0}` Although in theory this can only hold one possible value, the tag `zero`, Zig no longer will treat the type this way. It will do loads and stores, as if the type has runtime bits. Closes #12619 Tests passed locally: * test-behavior * test-cases
2022-08-24stage2: fix generic function cleanupAndrew Kelley
When removing generic function instantiations from monomorphed_funcs, we need to first make sure the function is generic, otherwise the hash map tries to access the `hash` field of the function which is undefined. closes #12614
2022-08-22Sema: fix parameter of type 'T' must be comptime errorVeikka Tuominen
Closes #12519 Closes #12505