Commit graph

10791 commits

Author SHA1 Message Date
mlugg
8f849684f4
std.zig.Zir: improve instruction tracking
The main change here is to partition tracked instructions found within a
declaration. It's very unlikely that, for instance, a `struct { ... }`
type declaration was intentionally turned into a reification or an
anonymous initialization, so it makes sense to track things in a few
different arrays.

In particular, this fixes an issue where a `func` instruction could
wrongly be mapped to something else if the types of function parameters
changed. This would cause huge problems further down the pipeline; we
expect that if a `declaration` is tracked, and it previously contained a
`func`/`func_inferred`/`func_fancy`, then this instruction is either
tracked to another `func`/`func_inferred`/`func_fancy` instruction, or
is lost.

Also, this commit takes the opportunity to rename the functions actually
doing this logic. `Zir.findDecls` was a name that might have made sense
at some point, but nowadays, it's definitely not finding declarations,
and it's not *exclusively* finding type declarations. Instead, the point
is to find instructions which we want to track; hence the new name,
`Zir.findTrackable`.

Lastly, a nice side effect of partitioning the output of `findTrackable`
is that `Zir.declIterator` no longer needs to accept input instructions
which aren't type declarations (e.g. `reify`, `func`).
2024-12-05 19:58:42 +00:00
mlugg
4d7818a76a
compiler: allow files with AstGen errors to undergo semantic analysis
This commit enhances AstGen to introduce a form of error resilience
which allows valid ZIR to be emitted even when AstGen errors occur.

When a non-fatal AstGen error (e.g. `appendErrorNode`) occurs, ZIR
generation is not affected; the error is added to `astgen.errors` and
ultimately to the errors stored in `extra`, but that doesn't stop us
getting valid ZIR. Fatal AstGen errors (e.g. `failNode`) are a bit
trickier. These errors return `error.AnalysisFail`, which is propagated
up the stack. In theory, any parent expression can catch this error and
handle it, continuing ZIR generation whilst throwing away whatever was
lost. For now, we only do this in one place: when creating declarations.
If a call to `fnDecl`, `comptimeDecl`, `globalVarDecl`, etc, returns
`error.AnalysisFail`, the `declaration` instruction is still created,
but its body simply contains the new `extended(astgen_error())`
instruction, which instructs Sema to terminate semantic analysis with a
transitive error. This means that a fatal AstGen error causes the
innermost declaration containing the error to fail, but the rest of the
file remains intact.

If a source file contains parse errors, or an `error.AnalysisFail`
happens when lowering the top-level struct (e.g. there is an error in
one of its fields, or a name has multiple declarations), then lowering
for the entire file fails. Alongside the existing `Zir.hasCompileErrors`
query, this commit introduces `Zir.loweringFailed`, which returns `true`
only in this case.

The end result here is that files with AstGen failures will almost
always still emit valid ZIR, and hence can undergo semantic analysis on
the parts of the file which are (from AstGen's perspective) valid. This
is a noteworthy improvement to UX, but the main motivation here is
actually incremental compilation. Previously, AstGen failures caused
lots of semantic analysis work to be thrown out, because all `AnalUnit`s
in the file required re-analysis so as to trigger necessary transitive
failures and remove stored compile errors which would no longer make
sense (because a fresh compilation of this code would not emit those
errors, as the units those errors applied to would fail sooner due to
referencing a failed file). Now, this case only applies when a file has
severe top-level errors, which is far less common than something like
having an unused variable.

Lastly, this commit changes a few errors in `AstGen` to become fatal
when they were previously non-fatal and vice versa. If there is still a
reasonable way to continue AstGen and lower to ZIR after an error, it is
non-fatal; otherwise, it is fatal. For instance, `comptime const`, while
redundant syntax, has a clear meaning we can lower; on the other hand,
using an undeclared identifer has no sane lowering, so must trigger a
fatal error.
2024-12-05 19:58:38 +00:00
Alex Rønne Petersen
d70be200d8
Merge pull request #22141 from alexrp/target-remove-bridgeos
`std.Target`: Remove `Os.Tag.bridgeos`
2024-12-05 15:05:25 +01:00
Frank Denis
c9d6f8b505
Remove parallel variants of AEGIS-MAC (#22146)
The construction is likely to change before standardization
2024-12-04 22:45:07 +00:00
Alex Rønne Petersen
09b39f77b7
std.Target: Remove Os.Tag.bridgeos.
It doesn't appear that targeting bridgeOS is meaningfully supported by Apple.
Even LLVM/Clang appear to have incomplete support for it, suggesting that Apple
never bothered to upstream that support. So there's really no sense in us
pretending to support this.
2024-12-03 20:43:15 +01:00
Alex Rønne Petersen
14c79203c4
std.os.linux: Fix fadvise64 syscall selection for n32/x32. 2024-12-01 02:23:55 +01:00
Andrew Kelley
8d8801c96d
Merge pull request #19968 from wooster0/eql
std.mem.eql: make comparisons for zero-sized and non-sized types work
2024-11-29 16:19:39 -05:00
Pat Tullmann
5e1a83ad29 defaultPanic: @trap on 'other' target
The freestanding and other OS targets by default need to just @trap in the
default Panic implementation.

And `isValidMemory` won't work with freestanding or other targets.

Update the unwind_freestanding.zig test case to also run on the 'other' OS
target, too.  This should keep the Zig's stacktrace generation from
regressing on the standalone targets.
2024-11-29 15:30:05 -05:00
Andrew Kelley
a47aa9dd9d
Merge pull request #22095 from alexrp/test-llvm-emit
Change `llvm_targets` tests to actually emit objects, and fix bugs found as a result
2024-11-29 15:28:54 -05:00
Rohan Vashisht
88d57917b7
Updated ascii.zig's isWhitespace function to use switch instead of for loop. (#22094) 2024-11-29 12:26:23 -08:00
Jay Petacat
97b8d662e6 std.Build: Detect pkg-config names with "lib" prefix 2024-11-29 15:11:14 -05:00
Alex Rønne Petersen
4a73b8cbb3 std.builtin: Add VaListXtensa. 2024-11-28 23:31:11 +01:00
Alex Rønne Petersen
7fe219998f
std.Target: Fix long double alignment for wasm(32,64)-emscripten-*. 2024-11-28 21:31:28 +01:00
Alex Rønne Petersen
6cd67cec67
std.Target: Fix long double size for aarch64-bridgeos-*. 2024-11-28 21:31:28 +01:00
Alex Rønne Petersen
310d1c1ff4
std.Target: Fix long/unsigned long size for aarch64-watchos-ilp32. 2024-11-28 21:31:28 +01:00
Alex Rønne Petersen
aea4f705dc
std.Target: Add missing C type info for aix, elfiamcu, hermit, hurd, rtems, and zos. 2024-11-28 21:31:28 +01:00
Andrew Kelley
182cdf74bf
Merge pull request #22087 from ziglang/std.ArrayHashMap
std.ArrayHashMap: add `reinit` method and other housekeeping, including the move towards "unmanaged" containers
2024-11-28 14:07:30 -05:00
Alex Rønne Petersen
3fb0ab5195
std.Build.Step.Run: Use std.zig.target.glibcRuntimeTriple() in runCommand(). 2024-11-28 17:18:00 +01:00
Alex Rønne Petersen
80ac91172f
std.zig.target: Add glibcRuntimeTriple() function.
This lets us centralize the logic for constructing a target triple that matches
the format used by glibc's build-many-glibcs.py script.
2024-11-28 17:18:00 +01:00
Alex Rønne Petersen
f02659d93c
std.Target: Add hurdTuple() and hurdTupleSimple() functions.
These serve the same purpose as the linuxTriple() and linuxTripleSimple()
functions, i.e. to return a triple understood by the GNU ecosystem.
2024-11-28 17:18:00 +01:00
Alex Rønne Petersen
8594f179f9
Merge pull request #22067 from alexrp/pie-tests
Add PIC/PIE tests and fix some bugs + some improvements to the test harness
2024-11-28 14:07:28 +01:00
Andrew Kelley
e374483d67 std.ArrayHashMap: update to the "gpa"/"arena" convention
for Allocator names
2024-11-27 14:35:01 -08:00
Andrew Kelley
20215a376c prepare to remove the "Managed" variant of std.ArrayHashMap 2024-11-27 14:34:27 -08:00
Andrew Kelley
da6e80c30a std.ArrayHashMap: explicit error sets 2024-11-27 14:34:26 -08:00
Andrew Kelley
c9c7ede2f9 introduce std.ArrayHashMap.reinit 2024-11-27 14:34:08 -08:00
Alex Rønne Petersen
6cf01a679f std.Thread.Futex: Mark inline asm volatile in WasmImpl.
Closes #22082.
2024-11-27 23:24:37 +01:00
Justin Braben
d16a9b0acb
std.os.windows: Map PIPE_NOT_AVAILABLE from OpenFile() to error.NoDevice (#21938) 2024-11-27 22:33:29 +01:00
mlugg
1a99c99ee9 std.Build: gracefully handle child stdin closing when running tests
We have deduced that it seems the sporadic BrokenPipe failures happening
on the CI runners (e.g.
https://github.com/ziglang/zig/actions/runs/12035916948/job/33555963190)
are likely caused by the test runner's stdin pipe abnormally closing,
likely due to the process crashing. Here, we introduce error handling
for this case, so that if these writes fail, the step is marked as
failed correctly, and we still collect the child's stderr to report.
This won't fix the CI issues, but it should promote them to proper error
messages including child stderr, which -- at least in theory -- should
allow us to ultimately track down where the errors come from.

Note that this change is desirable regardless of bugs in the test runner
or similar, since the child process could terminate abnormally for any
number of reasons (e.g. a crashing test), and such cases should be
correctly reported by the build runner.
2024-11-27 19:35:31 +00:00
Andrew Kelley
11bf2d92de diversify "unable to spawn" failure messages
to help understand where a spurious failure is occurring
2024-11-26 13:56:40 -08:00
Andrew Kelley
68b3f50866
Merge pull request #22070 from Rexicon226/fix-crc32
add `crc32` as a feature dep of `sse4.2` and refactor `update_cpu_feature.zig`
2024-11-26 16:29:51 -05:00
Alex Rønne Petersen
047311a76a std.math: Disable isSignalNan test on mips32.
https://github.com/ziglang/zig/issues/14366
2024-11-26 18:29:13 +01:00
Chris Boesch
87863a834b
std.math.complex: Add squared magnitude function (#21998) 2024-11-26 13:03:48 +00:00
Andrew Kelley
21f0fce28b CI: update macOS runner to 13
Apple has already dropped support for macOS 12.
GitHub Actions is dropping macOS 12 support now.
The Zig project is also dropping macOS 12 support now.

This commit also bumps default minimum macos version to 13.
2024-11-25 15:00:10 -08:00
Andrew Kelley
775b48dd10 std.io.Poller: handle EPIPE as EOF
closes #17483
2024-11-25 14:18:55 -08:00
Andrew Kelley
aa5341bf85 std.process.Child: explicit error set for wait 2024-11-25 14:18:55 -08:00
David Rubin
f36f7d54a7
refactor update_cpu_features.zig
Most of this commit is whitespace changes, moving to use RLS
for assigning the `CpuModel`
2024-11-25 01:11:15 -08:00
David Rubin
9e17e097e5
make crc32 a featdep of sse4.2
To my knowledge there isn't an implementation of `sse4.2` that doesn't have `crc32`.
The Clang driver also sets `crc32` to be implicitly enabled when an explicit `-crc32`
wasn't provided. This matches that behaviour.

We need this behaviour to compile libraries like `rocksdb` which currently guard against
`crc32` intrinsics by checking for `sse4.2`.
2024-11-25 01:11:15 -08:00
Andrew Kelley
ca67f80b6e std.hash.int: avoid words like "easy" and "fast" in doc comments 2024-11-24 15:30:52 -08:00
Francesco Alemanno
ae6c24b490 std.hash.int: better handle odd bit sizes
Uses the non rational solution of a quadratic, I made it work up to 256
bits, added Mathematica code in case anyone wants to verify the magic
constant.

integers between sizes 3...15 were affected by fatal bias, it is best to
make them pass through the generic solution.

Thanks to RetroDev256 & Andrew feedback.
2024-11-24 15:29:20 -08:00
Andrew Kelley
d09fd249c0 std.hash.int: restore previous behavior
In the parent commit, I handled odd bit sizes by upcasting and
truncating. However it seems the else branch is intended to handle
those cases instead, so this commit reverts that behavior.
2024-11-24 15:27:03 -08:00
Andrew Kelley
5ad44c14b0 std.hash.int: use anytype instead of explicit type parameter
also
* allow signed ints, simply bitcast them to unsigned
* handle odd bit sizes by upcasting and then truncating
* naming conventions
* remove redundant code
* better use of testing API
2024-11-24 15:27:03 -08:00
Francesco Alemanno
aee6f7d7ee std.hash: improve simple hashing of unsigned integers
Before, the default bit mixer was very biased, and after a
lot of searching it turns out that selecting a better solution is hard.

I wrote a custom statistical analysis taylored for bit mixers in order
to select the best one at each size (u64/u32/u16), compared a lot of
mixers, and packaged the best ones in this commit.
2024-11-24 15:27:03 -08:00
Ilia Choly
e2f24a2d70 Allocator.free: document zero-length behavior
It wasn't immediately clear from the implementation whether passing
zero-length memory to free() was undefined behavior or intentionally
supported. Since ArrayList and other core data structures rely on
this behavior working correctly, this should be explicitly documented
as part of the public API contract.
2024-11-24 18:19:11 -05:00
Bruno Reis
c2db5d9cd1 treat errno(6) (NXIO) as expected error in openatZ 2024-11-24 18:17:56 -05:00
Andrew Barchuk
1f37b70344
Remove unused buf field from std.fmt.Parser (#21994)
And make the initialization less error prone by removing a default for
iter, which is required for a functional parser

std: Add a brief doc comment for `std.fmt.Parser`
2024-11-24 15:09:36 -08:00
Fri3dNstuff
b2030cb9ab
std.meta.eql: use == directly when comparing packed structs (#21982) 2024-11-24 14:29:44 -08:00
Jacob Young
c894ac09a3 dwarf: fix stepping through an inline loop containing one statement
Previously, stepping from the single statement within the loop would
always exit the loop because all of the code unrolled from the loop is
associated with the same line and treated by the debugger as one line.
2024-11-24 17:28:12 -05:00
Alex Rønne Petersen
1e0267a96b
std.os.linux.pie: Fix a relocation error for s390x. 2024-11-24 22:11:17 +01:00
Alex Rønne Petersen
ddcde20817
std.Target: Fix Abi.default() for mips64/mips64el.
This is necessary after:

* 270fbbcd86
* 11915ae48e
2024-11-24 22:11:16 +01:00
Alex Rønne Petersen
24ecf45569
std.Target: Add Os.HurdVersionRange for Os.Tag.hurd.
This is necessary since isGnuLibC() is true for hurd, so we need to be able to
represent a glibc version for it.

Also add an Os.TaggedVersionRange.gnuLibCVersion() convenience function.
2024-11-24 22:11:16 +01:00