Commit Graph

1327 Commits

Author SHA1 Message Date
Nathan Bourgeois fdf19984b8 std.Target: add psp os 2026-03-21 02:56:24 -04:00
Matthew Lugg 0978566db8 incremental: handle loss of main struct instruction
My changes to how incremental compilation handles container types mean
that, at least for now, it is possible for the ZIR `.main_struct_inst`
of a source file to be lost (this happens if the number of top-level
fields in a file changes for instance). I missed a few things which
needed changing to account for this, which could lead to crashes with
certain (trivial) changes---oops!

Adds two new incremental test cases. They are currently disabled for
wasm32-wasi-selfhosted because they both trigger a crash in the WASM
backend.
2026-03-12 21:27:16 +01:00
Matthew Lugg 4eb8360911 compiler: various lil' fixes 2026-03-10 10:26:14 +00:00
Matthew Lugg 978f7fb1ff Zcu: improve error message sorting 2026-03-10 10:26:14 +00:00
Matthew Lugg 51c23f7ba4 compiler: split default field values back out from layout resolution
I was trying out combining struct layout resolution with resolution of
default field values, but it broke a few cases which it's not clear we
want to break. The simplest such case was a struct with a field which
was a slice of itself, with a default value of `&.{}`.

So, at least for now, I'm accepting defeat and splitting this back out.
This allows a couple of behavior tests which were removed to be
re-introduced---I will do that in the commit following this one.

I have *not* made this separate phase of resolution "lazy": instead, it
is tied to layout resolution, in the sense that if a struct's layout is
referenced, then its default field values are also referenced. I chose
this approach for simplicity---not of the implementation (it's actually
slightly *more* code to do it this way!), but in terms of the language
specification. I think this behavior is easier to understand and keep in
your head. It can be easily changed in future if we decide we want to.

This partially reverts the commit titled "compiler: merge struct default
value resolution into layout resolution".
2026-03-10 10:26:13 +00:00
Matthew Lugg 5cc12da1c0 cbe: rework CType and other major refactors
The goal of these changes is to allow the C backend to support the new
lazier type resolution system implemented by the frontend. This required
a full rewrite of the `CType` abstraction, and major changes to the C
backend "linker".

The `DebugConstPool` abstraction introduced in a previous commit turns
out to be useful for the C backend to codegen types. Because this use
case is not debug information but rather general linking (albeit when
targeting an unusual object format), I have renamed the abstraction to
`ConstPool`. With it, the C linker is told when a type's layout becomes
known, and can at that point generate the corresponding C definitions,
rather than deferring this work until `flush`.

The work done in `flush` is now more-or-less *solely* focused on
collecting all of the buffers into a big array for a vectored write.
This does unfortunately involve a non-trivial graph traversal to emit
type definitions in an appropriate order, but it's still quite fast in
practice, and it operates on fairly compact dependency data. We don't
generate the actual type *definitions* in `flush`; that happens during
compilation using `ConstPool` as discussed above. (We do generate the
typedefs for underaligned types in `flush`, but that's a trivial amount
of work in most cases.)

`CType` is now an ephemeral type: it is created only when we render a
type (the logic for which has been pushed into just 2 or 3 functions in
`codegen.c`---most of the backend now operates on unmolested Zig `Type`s
instead). C types are no longer stored in a "pool", although the type
"dependencies" of generated C code (that is, the struct, unions, and
typedefs which the generated code references) are tracked (in some
simple hash sets) and given to the linker so it can codegen the types.
2026-03-10 10:26:12 +00:00
Matthew Lugg 7ca061f3d6 compiler: rework and simplify main loop 2026-03-10 10:26:12 +00:00
Matthew Lugg bcb1a6bdf3 compiler: make Dwarf and self-hosted x86_64 happy
Introduces a small abstraction, `link.DebugConstPool`, to deal with
lowering type/value information into debug info when it may not be known
until type resolution (which in some cases will *never* happen). It is
currently only used by self-hosted DWARF logic, but it will also be of
use to the LLVM backend (which is my next focus).
2026-03-10 10:26:11 +00:00
Matthew Lugg 1826ba69d8 compiler: make dependency loop errors good 2026-03-10 10:26:09 +00:00
Matthew Lugg a9bfc94ee6 compiler: small misc cleanups 2026-03-10 10:26:09 +00:00
Matthew Lugg 650185692d compiler: merge struct default value resolution into layout resolution
This actually doesn't cause any dependency loops in std, which is pretty
much my benchmark for it being acceptable. This can be reverted if it
turns out to be problematic, but for now, let's err on the side of
language simplicity.

To be clear, this *does* regress some cases which previously worked: I
will have to remove some behavior tests as a result of this commit. To
be honest, the tests which look to be failing as a result of this are
things which I think are generally unadvisable; I actually reckon a bit
more friction to use default field values in non-trivial ways might be a
good thing to stop people from misusing them as much. Struct fields
should very rarely have default values; about the only common situation
where they make sense is "options" structs.
2026-03-10 10:26:08 +00:00
Matthew Lugg 3086c7977b type resolution progress 2026-03-10 10:26:07 +00:00
Matthew Lugg 510ea6f61f type resolution progress 2026-03-10 10:26:07 +00:00
Ryan Liptak f16eb18ce8 Use / as path separator when writing tar files
The tar format expects `/`, although some untar implementations do seem to handle Windows-style `\` path separators (7-Zip at least).

The tar.Writer API can't really enforce this, though, as doing so would effectively make `\` an illegal character when it's really not. So, it's up to the user to provide paths with the correct path separators.

`Build/WebServer.zig` will still output tars with `\` as a path separator on Windows, but that's currently only used during fuzzing which is not yet implemented on Windows.
2026-03-08 02:10:00 +01:00
Kendall Condon e40557b1f7 allow specifying mode in --debug-rt
The motivation is that libfuzzer is slow in Debug mode and bugs usually
manifest late into fuzzing, which makes testing it in ReleaseSafe
useful.
2026-02-13 17:58:09 -05:00
Jacob Young f2cbc1912b tracy: replace namedFrame with traceNamed
It is not valid to use frames here because multiple compilations may run
concurrently, and a frame with a given name must stop before starting
again.
2026-02-09 10:47:21 -05:00
Jacob Young a28d57292f IoUring: update to new Io APIs 2026-02-09 10:47:21 -05:00
Andrew Kelley 922ab8b8bc std: finish moving time to Io interface
Importantly, adds ability to get Clock resolution, which may be zero.
This allows error.Unexpected and error.ClockUnsupported to be removed
from timeout and clock reading error sets.
2026-02-02 23:02:31 -08:00
Andrew Kelley 372e8e54d3 compiler: update for std.Io.File.MultiReader API 2026-01-30 22:03:14 -08:00
Andrew Kelley 380ea6fb5e Merge pull request 'Compilation: make libzigc share zcu if possible' (#31037) from GasInfinity/zig:libc-share-zcu into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31037
2026-01-30 08:16:39 +01:00
Andrew Kelley 649aaf4814 std: migrate getcwd to Io
progress towards #30150
2026-01-29 18:40:55 -08:00
GasInfinity e7baa09ce4 feat(Compilation): make libzigc share zcu if possible 2026-01-29 10:31:56 +01:00
Ryan Liptak 29b7214027 Disentangle from error.CurrentWorkingDirectoryUnlinked
This error is actually only ever directly returned from `std.posix.getcwd` (and only on POSIX systems, so never on Windows). Its inclusion in almost all of the error sets its currently found in is a leftover from when `std.fs.path.resolve` called `std.process.getCwdAlloc` (https://github.com/ziglang/zig/issues/13613).
2026-01-27 20:48:25 +01:00
Bingwu Zhang fc517bd01c Compilation: fix incorrect saved buf count
Change-Id: Ib2a2ffcb6224e571fed1151e687d8a8efe0bb95b
2026-01-12 11:21:54 +01:00
Andrew Kelley 6a5bb3ede3 std: find a better home for the "preopens" concept 2026-01-08 05:06:31 +01:00
Andrew Kelley ee574f665c std.Io.Dir: introduce renamePreserve and use it in File.Atomic.link
breaking change: the error for renaming over a non-empty directory now
returns error.DirNotEmpty rather than error.PathAlreadyExists.
2026-01-07 11:03:37 -08:00
Andrew Kelley 1f1381a866 update API usage of std.crypto.random to io.random 2026-01-07 11:03:36 -08:00
Alex Rønne Petersen a996a75e06 compiler: make all Zig-provided libraries use -ffunction-sections -fdata-sections
We already did this for some of them; this just makes us consistent. Doing this
gives the linker more flexibility to rearrange code/data, but more importantly,
allows --gc-sections to get rid of all the unused code, which is a real concern
for these libraries in particular.
2026-01-06 21:15:02 +01:00
Alex Rønne Petersen e226df2ed5 Merge pull request 'add OpenBSD libc cross-compilation support' (#30064) from alexrp/zig:openbsd into master
Reviewed-on: https://codeberg.org/ziglang/zig/pulls/30064
Reviewed-by: Andrew Kelley <andrewrk@noreply.codeberg.org>
2026-01-06 16:12:54 +01:00
Andrew Kelley 39605bd6bc compiler: update to new createFileAtomic API 2026-01-05 20:28:58 -08:00
Alex Rønne Petersen a78f891d05 compiler: support building openbsd crt0 and stub shared libraries
closes #2878
2026-01-05 16:50:46 +01:00
Alex Rønne Petersen 9f16886536 compiler: define ___OpenBSD and OpenBSDX_Y when targeting openbsd libc 2026-01-05 14:52:48 +01:00
Andrew Kelley 88dd682155 Compilation: revert bad code transformation
I added `unreachable` in this branch based on a misunderstanding of the
original control flow.
2026-01-04 00:27:09 -08:00
Andrew Kelley 1070c2a71a rename env_map to environ_map
For naming consistency with `std.process.Environ.Map`.
2026-01-04 00:27:09 -08:00
Andrew Kelley 85fe35d246 compiler: fix -Denable-llvm compilation failures 2026-01-04 00:27:08 -08:00
Andrew Kelley 960c512efd compiler: update std lib API usage 2026-01-04 00:27:08 -08:00
Andrew Kelley de8c4cd64e compiler: update to new std.process APIs 2026-01-04 00:27:08 -08:00
Andrew Kelley 32af0f6154 std: move child process APIs to std.Io
this gets the build runner compiling again on linux

this work is incomplete; it only moves code around so that environment
variables can be wrangled properly. a future commit will need to audit
the cancelation and error handling of this moved logic.
2026-01-04 00:27:08 -08:00
Andrew Kelley 2adfd4d107 std.Io: fix and improve Group API
Rename `wait` to `await` to be consistent with Future API. The
convention here is that this set of functionality goes together:
* async/concurrent
* await/cancel

Also rename Select `wait` to `await` for the same reason.

`Group.await` now can return `error.Canceled`. Furthermore,
`Group.await` does not auto-propagate cancelation. Instead, users should
follow the pattern of `defer group.cancel(io);` after initialization,
and doing `try group.await(io);` at the end of the success path.
Advanced logic can choose to do something other than this pattern in the
event of cancelation.

Additionally, fixes a bug in `std.Io.Threaded` future await, in which it
swallowed an `error.Canceled`. Now if a task is canceled while awaiting
a future, after propagating the cancel request, it also recancels,
meaning that the awaiting task will properly detect its own cancelation
at the next cancelation point.

Furthermore, fixes a bug in the compiler where `error.Canceled` was
being swallowed in `dispatchPrelinkWork`.

Finally, fixes std.crypto code that inappropriately used
`catch unreachable` in response to cancelation without even so much as a
comment explaining why it was believed to be unreachable. Now, those
functions have `error.Canceled` in the error set and propagate
cancelation properly.

With this way of doing things, `Group.await` has a nice property: even if
all tasks in the group are CPU bound and without cancelation points, the
`Group.await` can still be canceled. In such case, the task that was
waiting for `await` wakes up with a chance to do some more resource
cleanup tasks, such as canceling more things, before entering the
deferred `Group.cancel` call at which point it has to suspend until the
canceled but uninterruptible CPU bound tasks complete.

closes #30601
2025-12-29 22:47:34 -08:00
Andrew Kelley 187d0a692d compiler: handle cancelation from finishPrelinkQueue 2025-12-23 22:15:12 -08:00
Andrew Kelley a8088306f6 std: rename other Dir "make" functions to "create" 2025-12-23 22:15:11 -08:00
Andrew Kelley 54865e0483 compiler: fix compilation when linking libc 2025-12-23 22:15:10 -08:00
Andrew Kelley a5b719e9eb compiler: fix build failures from std.Io-fs 2025-12-23 22:15:10 -08:00
Andrew Kelley 608145c2f0 fix more fallout from locking stderr 2025-12-23 22:15:10 -08:00
Andrew Kelley 16bd2e137e compiler: fix most compilation errors from std.fs changes 2025-12-23 22:15:09 -08:00
Andrew Kelley 1925e0319f update lockStderrWriter sites
use the application's Io implementation where possible. This correctly
makes writing to stderr cancelable, fallible, and participate in the
application's event loop. It also removes one more hard-coded
dependency on a secondary Io implementation.
2025-12-23 22:15:09 -08:00
Andrew Kelley 16f8af1b9a compiler: update various code to new fs API 2025-12-23 22:15:09 -08:00
Andrew Kelley 4a53e5b0b4 fix a handful of compilation errors related to std.fs migration 2025-12-23 22:15:08 -08:00
Andrew Kelley ebdbbd20ac update makeDir() sites to specify permissions 2025-12-23 22:15:08 -08:00
Andrew Kelley 1dcfc8787e update all readFileAlloc() to accept Io instance 2025-12-23 22:15:08 -08:00