14495 Commits

Author SHA1 Message Date
mlugg
b8d114a29e
Zcu: use Value instead of TypedValue when initializing legacy anon decls
Also removes some unnecessary uses of legacy anon decls for constructing
the array of test functions for the test runner.
2024-03-26 13:48:07 +00:00
mlugg
0d8c7ae007
Zcu.Decl: replace typedValue with valueOrFail
Now that the legacy `Value` representation is eliminated, we can begin
to phase out the redundant `TypedValue` type.
2024-03-26 13:48:07 +00:00
mlugg
920f2c7794
compiler: minor cleanups 2024-03-26 13:48:07 +00:00
mlugg
26a94e8481
Zcu: eliminate Decl.alive field
Legacy anon decls now have three uses:
* Type owner decls
* Function owner decls
* `@export` and `@extern`

Therefore, there are no longer any cases where we wish to explicitly
omit legacy anon decls from the binary. This means we can remove the
concept of an "alive" vs "dead" `Decl`, which also allows us to remove
the separate `anon_work_queue` in `Compilation`.
2024-03-26 13:48:06 +00:00
mlugg
152a2ceaf7
compiler: audit uses of ptr.addr in the frontend
This commit also performs some refactors to `TypedValue.print` in
preparation for improved comptime pointer access logic. Once that logic
exists, `TypedValue.print` can use Sema to access pointers for more
helpful printing.

This commit also implements proposal #19435, because the existing logic
there relied on some blatantly incorrect code in `Value.sliceLen`.

Resolves: #19435
2024-03-26 13:48:06 +00:00
mlugg
884d957b6c
compiler: eliminate legacy Value representation
Good riddance!

Most of these changes are trivial. There's a fix for a minor bug this
exposed in `Value.readFromPackedMemory`, but aside from that, it's all
just things like changing `intern` calls to `toIntern`.
2024-03-26 13:48:06 +00:00
mlugg
5ec6e3036b
Sema: introduce separate MutableValue representation for comptime-mutable memory
Perhaps someday, we will make Sema operate on mutable values more
generally. For now, it makes sense to split out this representation,
since it is only used in comptime pointer accesses.

There are some currently unused methods on `MutableValue` which will
be used once I rewrite the comptime pointer access logic to be less
terrible.

The commit following this one will - at long last - delete the legacy
Value representation
2024-03-26 13:48:06 +00:00
mlugg
c6f3e9d79c
Zcu.Decl: remove ty field
`Decl` can no longer store un-interned values, so this field is now
unnecessary. The type can instead be fetched with the new `typeOf`
helper method, which just gets the type of the Decl's `Value`.
2024-03-26 13:48:06 +00:00
Andrew Kelley
405502286d
Merge pull request #19414 from mlugg/comptime-mutable-memory-yet-again
compiler: implement analysis-local comptime-mutable memory
2024-03-25 16:32:18 -07:00
Andrew Kelley
32b4d85605
Merge pull request #19406 from jacobly0/haiku
haiku: get a cross-compiled compiler working
2024-03-25 15:33:51 -07:00
mlugg
31a7f22b80 llvm: update current debug location scope when entering debug scope
This issue was causing debug information to sometimes not function
correctly for some local variables, with debuggers simply reporting that
the variable does not exist. What was happening was that after an AIR
body - and thus debug lexical scope - begins, but before any `dbg_stmt`
within it, the `scope` on `self.wip.debug_location` refers to the parent
scope, but the `scope` field on the `DILocalVariable` metadata passed to
`@llvm.dbg.declare` points, correctly, to the nested scope. I haven't
looked into precisely what happens here, but in short, it would appear
that LLVM Doesn't Like It (tm).

The fix is simple: when we change `self.scope` at the start or end of an
AIR body, also modify the scope on `self.wip.debug_location`. This is
correct as we always want the debug info for an instruction to be
associated with the block it is within, even if the line/column are
slightly outdated for any reason.
2024-03-25 15:05:52 +00:00
mlugg
9c3670fc93
compiler: implement analysis-local comptime-mutable memory
This commit changes how we represent comptime-mutable memory
(`comptime var`) in the compiler in order to implement the intended
behavior that references to such memory can only exist at comptime.

It does *not* clean up the representation of mutable values, improve the
representation of comptime-known pointers, or fix the many bugs in the
comptime pointer access code. These will be future enhancements.

Comptime memory lives for the duration of a single Sema, and is not
permitted to escape that one analysis, either by becoming runtime-known
or by becoming comptime-known to other analyses. These restrictions mean
that we can represent comptime allocations not via Decl, but with state
local to Sema - specifically, the new `Sema.comptime_allocs` field. All
comptime-mutable allocations, as well as any comptime-known const allocs
containing references to such memory, live in here. This allows for
relatively fast checking of whether a value references any
comptime-mtuable memory, since we need only traverse values up to
pointers: pointers to Decls can never reference comptime-mutable memory,
and pointers into `Sema.comptime_allocs` always do.

This change exposed some faulty pointer access logic in `Value.zig`.
I've fixed the important cases, but there are some TODOs I've put in
which are definitely possible to hit with sufficiently esoteric code. I
plan to resolve these by auditing all direct accesses to pointers (most
of them ought to use Sema to perform the pointer access!), but for now
this is sufficient for all realistic code and to get tests passing.

This change eliminates `Zcu.tmp_hack_arena`, instead using the Sema
arena for comptime memory mutations, which is possible since comptime
memory is now local to the current Sema.

This change should allow `Decl` to store only an `InternPool.Index`
rather than a full-blown `ty: Type, val: Value`. This commit does not
perform this refactor.
2024-03-25 14:49:41 +00:00
Jacob Young
2dd74cd312 haiku: debitrot 2024-03-23 18:11:32 +01:00
Andrew Kelley
a2651cbc82
Merge pull request #19388 from ziglang/cache-dedup
cache system file deduplication
2024-03-22 01:13:43 -07:00
Andrew Kelley
2f4bbd6c63 std.Build.Cache: use an array hash map for files
Rather than an ArrayList. Provides deduplication.
2024-03-21 19:56:30 -07:00
Andrew Kelley
7bc0b74b6d move Package.Path to std.Build.Cache.Path 2024-03-21 16:16:47 -07:00
Elaine Gibson
62929d599c mingw: link to api sets instead of ucrtbase 2024-03-21 15:06:24 -07:00
Elaine Gibson
e12a72db92 main: set subsystem version from target windows version 2024-03-21 15:05:17 -07:00
Andrew Kelley
b5cef9e8b4
Merge pull request #19374 from ziglang/slice-by-len-safety
add OOB safety check for by-length slice of array
2024-03-21 01:47:54 -07:00
Andrew Kelley
4d5e0a0434 Revert the last two commits in this branch
When the slice-by-length start position is runtime-known, it is likely
protected by a runtime-known condition and therefore a compile error is
less appropriate than a runtime panic check.

This is demonstrated in the json code that was updated and then reverted
in this commit.

When #3806 is implemented, this decision can be reassessed.

Revert "std: work around compiler unable to evaluate condition at compile time"
Revert "frontend: comptime array slice-by-length OOB detection"

This reverts commit 7741aca96c8cc6df7e8c4bd10ada741d6a3ffb9d.
This reverts commit 2583b389eaf5f7aaa0eb79b51126506c1e172d15.
2024-03-20 17:29:06 -07:00
Andrew Kelley
2583b389ea frontend: comptime array slice-by-length OOB detection 2024-03-20 17:02:35 -07:00
Andrew Kelley
ab22844176 frontend: add missing bounds check for slice-by-length arrays
closes #18382
2024-03-20 16:29:46 -07:00
Elaine Gibson
19b6995939 mingw: define _WIN32_WINNT when building CRT 2024-03-20 15:02:04 -07:00
Andrew Kelley
8c94950c24 fix compilation failures found by CI 2024-03-19 16:18:18 -07:00
Andrew Kelley
6b2899df2a compiler: fix wrong detection of rlimit
related to #19352
2024-03-19 11:45:10 -07:00
Andrew Kelley
cd62005f19 extract std.posix from std.os
closes #5019
2024-03-19 11:45:09 -07:00
Robin Voetter
7057bffc14
Merge pull request #19337 from Snektron/spirv-globals
spirv: rework generic global
2024-03-19 09:34:59 +01:00
Robin Voetter
335ff5a5f4
spirv: fix optional comparison 2024-03-18 19:13:50 +01:00
Robin Voetter
8ed134243a
spirv: unused instruction pruning linker pass 2024-03-18 19:13:50 +01:00
Robin Voetter
9b18125562
spirv: make generic globals invocation-local 2024-03-18 19:13:50 +01:00
Robin Voetter
20d7bb68ac
spirv: add zig-specific ext inst
This may be removed again in the future...
2024-03-18 19:13:49 +01:00
Robin Voetter
e566158acf
spirv: make IdResult an enum 2024-03-18 19:13:49 +01:00
Robin Voetter
9b058117f0
spirv: update assembler with new spec 2024-03-18 19:13:48 +01:00
Robin Voetter
028f532dc0
spirv: update spec to SPIRV-Headers/8b246ff
We need this "unstable" version to get the Zig identifiers.
2024-03-18 19:13:47 +01:00
SuperAuguste
8e7d9afdac Add 64bit byteswap case, use fewer locals 2024-03-18 12:40:41 +01:00
Veikka Tuominen
64173dadca
Merge pull request #19334 from antlilja/llvm-fast-math
Fix setFloatMode in LLVM backend
2024-03-18 04:27:39 +02:00
kcbanner
54f6e74cda cbe: rework StringLiteral to decide between string literal or array initializator syntax
This fixes an issue with boostrapping the compiler using MSVC. There is a CircularBuffer with
an array of length 65536 initialized to undefined, and because the undefined path of `renderValue`
was using `StringLiteral` to render this, the resulting zig2.c would fail to compile using MSVC.

The solution was to move the already-existing array initializer path (used in the non-undefined path)
into StringLiteral, and make StringLiteral aware of the total length so it could decide between which
style of initialization to use. We prefer to use string literals if we can, as this results in the least
amount of emitted C source.
2024-03-17 16:17:04 -07:00
Andrew Kelley
95cb939440
Merge pull request #19333 from Vexu/fixes
Miscellaneous error fixes
2024-03-17 15:26:55 -07:00
Andrew Kelley
d981549d65
Merge pull request #19323 from jacobly0/rm-fn-type-align
AstGen: disallow alignment on function types
2024-03-17 15:19:54 -07:00
antlilja
79b868d504 LLVM: Use fast math when requested 2024-03-17 16:26:28 +01:00
antlilja
b20cee586c LLVM: Fix incorrect fast constant in FastMath packed struct 2024-03-17 16:25:59 +01:00
antlilja
37a4d9391f LLVM: Fix reaching unreachable code when emitting fast call 2024-03-17 16:23:14 +01:00
Robin Voetter
3bffa58012
Revert "spirv: merge construct(Struct/Vector/Array) into constructComposite"
This reverts commit eb2d61d02e503f01070c05e2e1fc87e827124d94.
2024-03-17 14:17:26 +01:00
Veikka Tuominen
436c72e89a Sema: allow param instructions to clobber inst_map
Closes #18840
2024-03-17 14:42:12 +02:00
Veikka Tuominen
fec4b7ef5c Sema: fix spurious type has no namespace error
Closes #19232
2024-03-17 14:42:12 +02:00
Veikka Tuominen
f983adfc10 Sema: fix printing of inferred error set of generic fn
Closes #19332
2024-03-17 13:33:05 +02:00
Anton Lilja
294f51814f
LLVM lowerDebugType: Lower union types without a layout into an empty namespace 2024-03-17 13:25:09 +02:00
Jacob Young
e646e01161 Revert "back out the build_runner.zig moving change"
This reverts commit 1a01151a4e1e83826d6911c929210aabcaed36e9 in
preparation for a zig1.wasm update.
2024-03-17 03:06:39 +01:00
Jacob Young
d10c52c194 AstGen: disallow alignment on function types
A pointer type already has an alignment, so this information does not
need to be duplicated on the function type.  This already has precedence
with addrspace which is already disallowed on function types for this
reason.  Also fixes `@TypeOf(&func)` to have the correct addrspace and
alignment.
2024-03-17 03:06:17 +01:00
Andreas Herrmann
dbb11915bd Fix "unable to generate DLL import .lib file"
Closes https://github.com/ziglang/zig/issues/19284

As of 9f2cb920c055bc990cc9d593b8dc9eaa450d07b9 configuring the global
cache directory to a relative path causes errors of the following form
when cross compiling to `windows-gnu`.
```
error: unable to generate DLL import .lib file for kernel32: FileNotFound
```

The issue occurred because the `def_final_path` included the global
cache path as a prefix and later on the `def_final_file` was created
using that path with the global cache directory handle.
2024-03-16 13:33:36 +02:00