Commit graph

31856 commits

Author SHA1 Message Date
Andrew Kelley
933f7baa83 std.ArrayList: rename "precise" to "exact"
This word is shorter and has a more accurate definition.
2024-12-03 17:09:51 -08:00
Andrew Kelley
b3cd5b23a2 ArrayList: rename "ensure" to "reserve"
Matches the same word used for the corresponding append functions.
2024-12-03 16:51:58 -08:00
Andrew Kelley
702d014f07 ArrayList: rename "AssumeCapacity" to "Reserved"
Follows the convention that a single word used to describe a function
variant is desired if possible.
2024-12-03 14:57:33 -08:00
Alex Kladov
6188cb8e50 sema: add a missing errdefer
This fix doesn't matter at all in the grand scheme of things, but I
think the story behind it is perhaps curious, as it might point at a
design flaw in the Sema's error reporting API. So, a story:

On lobsters, there's a rather heated discussion on the merits on RAII vs
defer. I don't really like participating in heating discussions, but
also sort of can't stop thinking about this.

My own personal experience with Zig's defer and errdefer is that they
are fiddly to get right consistency --- if a program has a lot of
resource management to do, I _always_ mess up at least one
defer/errdefer. I've found my internal peace by just avoiding
spread-out, "pox" resource management, and instead centralizing resource
ownership under one of the following patterns:

* Either the thing is acquired and released in main
* Or main allocates N instances of thing, and then the rest of the code
  explicitly juggles this finite pool of N. Notably, this juggling
  typically doesn't involve defer/errdefer at all, as, at this level of
  precision, there are no `try`s left, so you only code the happy path
* Or there's some sort of arena thing, where a bunch of resources have a
  single owner, the user's don' bother cleaning up their resources, and
  instead the owner does it once at the end.

So I wanted to make a lobster.rs comment in the vein of "yeah, if your
program is mostly about resource management, then Zig could be kinda a
pain, but that's friction tells you something: perhaps your program
shouldn't be about resource management, and instead it should be doing
what it is supposed to do?". And, as an evidence for my claim, I wanted
to point out some large body of Zig code which doesn't have a lot of
errdefers.

So, I cracked opened Sema.zig, `ctrl+f` for `defer`, saw whopping 400
something occupancies, and my heart skipped a bit. Looking at the
occurrences, _some_ of them were non-resource-related usages of defer.
But a lot of them were the following pattern:

```zig
const msg = try sema.errMsg(src, "comptime control flow inside runtime block", .{});
errdefer msg.destroy(sema.gpa);
```

This is exactly the thing that I know _I_ can't get right consistently!
So, at this point, I made a prediction that at least one of `errdefer`s
is missing. So, I looked at the first few `const msg = try` and of
course found one without `errdefer`.

I am at 0.8 that, even with this PR applied, the claim will still stand
--- there will be `errdefer` missing. So it feels like some API
re-design is in order, to make sure individual error messages are not
resources.

Could Sema just own all partially-constructed error messages, and, at a
few known safe-points:

* if the control flow is normal, assert that there are no in-progress
  error messages
* if we are throwing an error, go and release messages immediately?

I am unlikely to do the actual refactor here, but I think it's worth
highlighting the overall pattern here.

PS: I am only 0.9 sure that what I've found is indeed a bug! I don't
understand the code, I did a dumb text search, so I _could_ have made a
fool of myself here :P
2024-12-03 14:18:26 -05:00
Andrew Kelley
4e09e363cd
Merge pull request #21720 from kubkon/macho-dwarf-v5
macho: add basic handling of DWARFv5
2024-12-03 02:28:22 -05:00
Jakub Konka
29c7f6810f macho: fix 32bit builds 2024-12-02 22:05:21 -05:00
Jakub Konka
f78006c1bf CMakeLists: add MachO/Dwarf.zig and remove MachO/dwarf.zig 2024-12-02 22:05:21 -05:00
Jakub Konka
0769afbb0f macho: refactors errors from parsing DWARF
Currently we don't report any errors to the user due to a bug in
self-hosted x86_64-macos backend.
2024-12-02 22:05:21 -05:00
Jakub Konka
c824b35051 macho: move things around in MachO/Object.zig and refactor 2024-12-02 22:05:21 -05:00
Jakub Konka
8e81500051 macho: handle DWARFv5 when parsing debug info in objects 2024-12-02 22:05:21 -05:00
Jakub Konka
808306f49a macho: rename dwarf.zig to Dwarf.zig
Separate commit since macOS is case-insensitive by default and so
I had to do it from Linux.
2024-12-02 22:05:21 -05:00
Jacob Young
c013f45ad0 coff: fix memory leak 2024-12-02 16:01:58 -05:00
Alex Rønne Petersen
5c6b25d9bb
Merge pull request #22115 from alexrp/x32-tests
`test`: Add `x86_64-linux-(gnux32,muslx32)` to module tests.
2024-12-01 13:43:16 +01:00
Alex Rønne Petersen
1731510933
test: Add x86_64-linux-(gnux32,muslx32) to module tests. 2024-12-01 02:23:55 +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
Tw
aa7d138462 zig fetch: add missing path separator in error message
Signed-off-by: Tw <tw19881113@gmail.com>
2024-11-29 18:50:21 -05: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
mlugg
c3821fe4ca compiler: use @Type instead of @TypeOf to print enum literal type 2024-11-29 15:26:58 -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
Justin Braben
07cd488d42
Add build option to set tracy-callstack-depth in build.zig (#21990) 2024-11-29 12:13:06 -08:00
Jay Petacat
97b8d662e6 std.Build: Detect pkg-config names with "lib" prefix 2024-11-29 15:11:14 -05:00
Andrew Kelley
cfdb001a8f
Merge pull request #22099 from Rexicon226/fix-cat-mul
change `++` and `**` to not return mutable pointers
2024-11-29 15:05:49 -05:00
David Rubin
77f16d457b
test: adjust behaviour test to new concat/mul semantics 2024-11-28 18:05:36 -08:00
David Rubin
1d78d4f8c1
sema: hotpath ++ and ** for array-pointers 2024-11-28 18:05:36 -08:00
Alex Rønne Petersen
4a73b8cbb3 std.builtin: Add VaListXtensa. 2024-11-28 23:31:11 +01:00
Alex Rønne Petersen
78b8ce5095
test: Change llvm_targets to actually emit an object for each target.
Without doing this, we don't actually test whether the data layout string we
generate matches LLVM's.

A number of targets had to be commented out due to this change:

* Some are using a non-working experimental LLVM backend (arc, csky, ...).
* Some don't have working LLD support (lanai, sparc, ...).
* Some don't have working self-hosted linker support (nvptx).
* Some are using ABIs that haven't been standardized (loongarch32).

Finally, all non-x86 uefi targets are hopelessly broken and can't really be
fixed until we change our emit logic to lower *-uefi-* verbatim rather than to
*-windows-*. See: https://github.com/ziglang/zig/issues/21630
2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
0bf054f4c5
test: Remove aarch64(_be)-linux-gnuilp32 from llvm_targets.
LLVM doesn't handle this target correctly (pointer size, etc).
2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
abf3032ff1
test: Add m68k-linux-musl to llvm_targets. 2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
322013c648
test: Add aarch64(_be)-linux-musl to llvm_targets. 2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
11d51ea5a2
test: Remove aarch64-rtems-ilp32 from llvm_targets.
LLVM can't represent this target at the moment.
2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
4369d3b93d
test: Add *-windows-cygnus triples to llvm_targets. 2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
7361f0bafa
link.MachO: Don't try to get a semver value for bridgeos. 2024-11-28 22:04:00 +01:00
Alex Rønne Petersen
f0f2dc52cc
llvm: Lower ohoseabi to ohos instead of verbatim.
LLVM doesn't recognize ohoseabi.
2024-11-28 22:04:00 +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
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
David Rubin
bc3094b278
sema: make ++ and ** return immutable pointers 2024-11-27 20:39:23 -08: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
3ce6de8765 revert langref section "common errdefer slip ups"
This does not belong in the language reference.

reverts 91a88a789f
2024-11-26 15:03:24 -08:00