Commit graph

580 commits

Author SHA1 Message Date
Andrew Kelley
11cc1c16fa make @embedFile support module-mapped names the same way as @import
closes #14553
2023-02-05 03:25:43 -05:00
Luuk de Gram
c9b957c937 link: remove FnData and make it self-owned
This finishes the work started in #14502 where atoms are owned by the
linker themselves. This now makes debug atoms fully owned by dwarf,
and no information is left stored on the decl.
2023-02-03 22:55:46 +01:00
Andrew Kelley
873bb29c98 introduce ZON: Zig Object Notation
* std.zig.parse is moved to std.zig.Ast.parse
 * the new function has an additional parameter that requires passing
   Mode.zig or Mode.zon
 * moved parser.zig code to Parse.zig
 * added parseZon function next to parseRoot function
2023-02-03 00:06:11 -07:00
Jakub Konka
beb20d29db link: remove union types which are now internal to backends 2023-02-01 19:32:54 +01:00
Luuk de Gram
46f54b23ae
link: make Wasm atoms fully owned by the linker 2023-02-01 19:10:56 +01:00
Jakub Konka
e0f3975fc8 link: make SpirV atoms fully owned by the linker 2023-02-01 16:01:43 +01:00
Jakub Konka
5de2aae63c link: decouple DI atoms from linker atoms, and manage them in Dwarf linker 2023-02-01 15:03:55 +01:00
Jakub Konka
b3277c8936 link: make Plan9 atoms fully owned by the linker 2023-02-01 11:12:53 +01:00
Jakub Konka
c430e9afa7 link: make Coff atoms fully owned by the linker 2023-01-31 20:27:17 +01:00
Jakub Konka
4404c4d200 link: make Elf atoms fully owned by the linker 2023-01-31 17:54:12 +01:00
Jakub Konka
d42a931051 link: make MachO atoms fully owned by the linker 2023-01-31 00:43:25 +01:00
Jakub Konka
a898729139 self-hosted: remove allocateDeclIndexes from the public link.File API 2023-01-27 19:51:06 +01:00
Luuk de Gram
b25efb86e1
wasm: migrate to new non-allocateDeclIndexes API 2023-01-27 19:24:15 +01:00
Jakub Konka
cc1d7a0e31 coff: migrate to new non-allocateDeclIndexes API 2023-01-26 14:29:14 +01:00
Jakub Konka
e1b9800ffa elf: migrate to new non-allocateDeclIndexes API 2023-01-26 14:29:14 +01:00
Jakub Konka
4d804c1b23 macho: completely remove allocateDeclIndexes in favor of linker tracking 2023-01-26 14:29:14 +01:00
mlugg
5f9186d0ce
AstGen: detect and error on files included in multiple packages
Previously, if a source file was referenced from multiple packages, it
just became owned by the first one AstGen happened to reach; this was a
problem, because it could lead to inconsistent behaviour in the compiler
based on a race condition. This could be fixed by just analyzing such
files multiple times - however, it was pointed out by Andrew that it
might make more sense to enforce files being part of at most a single
package. Having a file in multiple packages would not only impact
compile times (due to Sema having to run multiple times on potentially a
lot of code) but is also a confusing anti-pattern which more often than
not is a mistake on the part of the user.

Resolves: #13662
2023-01-22 19:00:03 +00:00
mlugg
6d71d79dc2
Package: store package name directly
By @Vexu's suggestion, since fetching the name from the parent package
is error-prone and complex, and optimising Package for size isn't really
a priority.
2023-01-22 19:00:03 +00:00
Veikka Tuominen
342bae02d8 Sema: automatically optimize order of struct fields
This is a simple starting version of the optimization described in #168
where the fields are just sorted by order of descending alignment.
2023-01-16 19:46:41 +02:00
Veikka Tuominen
d8128c272a Sema: fix typeInfo decls with usingnamespace
Closes #12403
2023-01-11 21:11:21 +02:00
Techatrix
1f8f79cd53
std: add helper functions to std.zig.Ast for extracting data out of nodes 2023-01-09 16:59:19 +02:00
Veikka Tuominen
f2faa303a5 Sema: handle enum expressions referencing local variables
Closes #12272
2023-01-05 22:03:32 +02:00
Veikka Tuominen
8c4727f9ab Sema: remove generic function from monomorphed_funcs on any error 2023-01-05 14:26:53 +02:00
Veikka Tuominen
01dba1c054 Sema: add system for checking backend feature support 2023-01-05 14:26:53 +02:00
Veikka Tuominen
abd005f302 Sema: do not immediately destroy failed generic instantiation
Closes #12535
Closes #12765
Closes #12927
2023-01-03 18:38:15 +02:00
Veikka Tuominen
4e64373fc0 fix generic function arg debug info referencing wrong parameter
Closes #14123
2022-12-30 17:00:50 +02:00
Andrew Kelley
32d76f0e4a stage2: remove pub from a private function 2022-12-14 14:26:02 -07:00
Andrew Kelley
a62c8d36d5 std.fs.Dir.statFile rework
* 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-14 14:26:02 -07:00
Philippe Pittoli
f65cdef7c8 std.fs.Dir.statFile: use fstatat
This avoids extra syscalls.
2022-12-14 14:11:59 -07:00
Veikka Tuominen
bc97a5662d Sema: display cimport errors from clang 2022-12-14 14:08:22 +02:00
IntegratedQuantum
15a6336bb4
Add a helpful note when using ** on number types. (#13871) 2022-12-11 14:41:42 -05:00
Andrew Kelley
50eb7983cd remove most conditional compilation based on stage1
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-06 20:38:54 -07:00
Veikka Tuominen
59dad43de2 Sema: add error for failed assumption about struct having runtime bits 2022-12-02 18:46:59 +02:00
Andrew Kelley
ceb0a632cf std.mem.Allocator: allow shrink to fail
closes #13535
2022-11-29 23:30:38 -07:00
Andrew Kelley
3ae4931dc1 CLI: more careful resolution of paths
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 81d2135ca6
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-28 01:23:39 -05:00
Jimmi Holst Christensen
6097165241 Use a slice for InstMap instead of std.HashMap
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-27 02:10:00 -05:00
Veikka Tuominen
d5da2a6114 Sema: implement tuple declarations 2022-11-23 12:13:39 +02:00
Veikka Tuominen
80575face7 AstGen: implement tuple declarations 2022-11-23 12:13:39 +02:00
Veikka Tuominen
034507ef7c Module: fix compile error for non-comptime-known global initializer 2022-11-20 20:25:12 +02:00
Veikka Tuominen
7b131a7cd4 Module: fix fieldSrcLoc for generated types 2022-11-20 20:25:11 +02:00
Veikka Tuominen
fb09093d95 Module: call ensureDeclAnalyzed on builtin.test_functions
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-16 01:12:28 +02:00
Veikka Tuominen
0184c8d86f Sema: remove block and src parameters from getBuiltin
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-13 15:45:25 -05:00
Jacob Young
cbed6bb085 Sema: make InferredErrorSet deterministic
Empirically, this `AutoHashMapUnmanaged` -> `AutoArrayHashMapUnmanaged`
change fixes all non-determinism in `ReleaseFast` build artifacts.

Closes #12183
2022-11-04 00:00:10 -04:00
Andrew Kelley
30b8b29f88 re-apply "Fix C include files not being in whole cache (#11365)"
This reverts commit 06310e3d4e, reapplying
commit a430630002.

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-30 17:04:09 -07:00
Veikka Tuominen
b12a5cea75 remove test case triggering generic deletion bug
This test should be restored once the underlying issue is resolved (with the typo fixed).
2022-10-27 01:31:05 +03:00
Veikka Tuominen
db799ae628 Module: mitigate generic deletion bug 2022-10-27 01:31:05 +03:00
Cody Tapscott
c36a2c27a5 Change how Block propagates (error return) trace index
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-21 12:46:46 -07:00
Cody Tapscott
d060cbbec7 stage2: Keep error return traces alive when storing to const
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-21 12:40:29 -07:00
Veikka Tuominen
972c39e2c0
Merge pull request #13219 from Vexu/stage2-fixes
Stage2 bug fixes
2022-10-21 12:11:49 +02:00
Veikka Tuominen
c95a34b68f stage2: improve source location of assignment 2022-10-20 20:11:00 +03:00