Commit graph

17075 commits

Author SHA1 Message Date
Alex Rønne Petersen
6bb6013d3a
Merge pull request #24768 from alichraghi/spv5
spirv: remove prune_unused ISel
2025-08-10 19:45:16 +02:00
Techatrix
2983285815 zig fmt: flush stdout before exiting with error 2025-08-10 19:42:54 +02:00
Andrew Kelley
0a1a738320
Merge pull request #24743 from ziglang/BufferedWriter
std.Io: delete BufferedWriter
2025-08-09 16:28:19 -07:00
Ali Cheraghi
bed99e1ecd
spirv: remove prune_unused ISel 2025-08-09 13:27:04 +03:30
Ian Johnson
14f11377cb Fetch.git: fix FetchStream packet reading
Progress towards #24732
2025-08-08 19:37:33 -07:00
Andrew Kelley
8c9dfcbd0f std.Io: remove BufferedWriter 2025-08-08 17:17:53 -07:00
mlugg
5f7a0bbabf Sema: fix unreasonable progress node numbers
The "completed" count in the "Semantic Analysis" progress node had
regressed since 0.14.0: the number got crazy big very fast, even on
simple cases. For instance, an empty `pub fn main` got to ~59,000 where
on 0.14 it only reached ~4,000. This was happening because I was
unintentionally introducing a node every time type resolution was
*requested*, even if (as is usually the case) it turned out to already
be done. The fix is simply to start the progress node a little later,
once we know we are actually doing semantic analysis. This brings the
number for that empty test case down to ~5,000, which makes perfect
sense. It won't exactly match 0.14, because the standard library has
changed, and also because the compiler's progress output does have some
*intentional* changes.
2025-08-08 23:14:26 +01:00
Andrew Kelley
2a8751e37f Fetch.git: replace a toss with discardAll
toss is only valid following a peek.
2025-08-08 15:03:05 -07:00
mlugg
1440519239 compiler: improve error reporting
The functions `Compilation.create` and `Compilation.update` previously
returned inferred error sets, which had built up a lot of crap over
time. This meant that certain error conditions -- particularly certain
filesystem errors -- were not being reported properly (at best the CLI
would just print the error name). This was also a problem in
sub-compilations, where at times only the error name -- which might just
be something like `LinkFailed` -- would be visible.

This commit makes the error handling here more disciplined by
introducing concrete error sets to these functions (and a few more as a
consequence). These error sets are small: errors in `update` are almost
all reported via compile errors, and errors in `create` are reported
through a new `Compilation.CreateDiagnostic` type, a tagged union of
possible error cases. This allows for better error reporting.

Sub-compilations also report errors more correctly in several cases,
leading to more informative errors in the case of compiler bugs.

Also fixes some race conditions in library building by replacing calls
to `setMiscFailure` with calls to `lockAndSetMiscFailure`. Compilation
of libraries such as libc happens on the thread pool, so the logic must
synchronize its access to shared `Compilation` state.
2025-08-08 22:37:27 +01:00
Andrew Kelley
1ba6838bc3
Merge pull request #24740 from ziglang/http-plus-fixes
fetch, tls, and http fixes
2025-08-08 12:33:53 -07:00
Andrew Kelley
9a538e0d54 link.Dwarf: minimal changes to remove CountingWriter 2025-08-07 22:26:42 -07:00
Andrew Kelley
281f657377 Revert "random patches from another branch"
This reverts commit 76ed05523d6327789a8365571b67a214ac527ef9.

they don't work
2025-08-07 22:26:42 -07:00
Andrew Kelley
c5a5983150 random patches from another branch 2025-08-07 22:26:42 -07:00
Andrew Kelley
94dd28b7f7 std.Io: delete CountingWriter 2025-08-07 22:26:42 -07:00
Andrew Kelley
3fb86841cc
Merge pull request #24661 from alichraghi/spv4
spirv: refactor and remove deduplication ISel
2025-08-07 20:55:50 -07:00
Andrew Kelley
8da645c883 Fetch: fix FetchStream logic 2025-08-07 19:55:40 -07:00
Andrew Kelley
d7bf608821 Fetch: make FetchStream live longer 2025-08-07 19:55:40 -07:00
Andrew Kelley
af2ac24333 Fetch: handle compressed git+http 2025-08-07 19:55:40 -07:00
Andrew Kelley
46b34949c3 TLS, HTTP, and package fetching fixes
* TLS: add missing assert for output buffer length requirement
* TLS: add missing flushes
* TLS: add flush implementation
* TLS: finish drain implementation
* HTTP: correct buffer sizes for TLS
* HTTP: expose a getReadError method on Connection
* HTTP: add missing flush on sendBodyComplete
* Fetch: remove unwanted deinit
* Fetch: improve error reporting
2025-08-07 10:04:52 -07:00
Andrew Kelley
4567241d8d fetch: avoid copying Resource 2025-08-07 10:04:52 -07:00
Andrew Kelley
e061445fc2 std.Io: delete BufferedReader 2025-08-07 10:04:52 -07:00
Andrew Kelley
9e5048c3a5 fetch: update for new http API
it's not quite finished because I need to make it not copy the Resource
2025-08-07 10:04:51 -07:00
Justus Klausecker
aaee26bb19 remove unnecessary discard 2025-08-07 14:34:05 +02:00
Justus Klausecker
ba549a7d67 Add support for both '_' and 'else' prongs at the same time in switch statements
If both are used, 'else' handles named members and '_' handles
unnamed members. In this case the 'else' prong will be unrolled
to an explicit case containing all remaining named values.
2025-08-07 13:58:47 +02:00
Justus Klausecker
1d9b1c0212 Permit explicit tags with '_' switch prong
Mainly affects ZIR representation of switch_block[_ref]
and special prong (detection) logic for switch.
Adds a new SpecialProng tag 'absorbing_under' that allows
specifying additional explicit tags in a '_' prong which
are respected when checking that every value is handled
during semantic analysis but are not transformed into AIR
and instead 'absorbed' by the '_' branch.
2025-08-07 13:57:57 +02:00
Matthew Lugg
fd9cfc39f5
Merge pull request #24199 from Justus2308/24106-fmt-casts
zig fmt: canonicalize nested cast builtin order
2025-08-07 10:55:03 +01:00
mlugg
e17a050bc6 link: prevent deadlock when prelink tasks fail
If an error occured which prevented a prelink task from being queued,
then `pending_prelink_tasks` would never be decremented, which could
cause deadlocks in some cases. So, instead of calculating ahead of time
the number of prelink tasks to expect, we use a simpler strategy which
is much like a wait group: we add 1 to a value when we spawn a worker,
and in the worker function, `defer` decrementing the value. The initial
value is 1, and there's a decrement after all of the workers are
spawned, so once it hits 0, prelink is done (be it with a failure or a
success).
2025-08-06 21:50:16 +01:00
mlugg
3de8bbd3d4 Sema: fix initializing comptime-known constant with OPV union field
Resolves: #24716
2025-08-06 20:47:03 +01:00
Alex Rønne Petersen
7ee6dab39f Revert "Sema: Stop adding Windows implib link inputs for extern "..." syntax."
This reverts commit b461d07a54.

After some discussion in the team, we've decided that this is too disruptive,
especially because the linker errors are less than helpful. That's a fixable
problem, so we might reconsider this in the future, but revert it for now.
2025-08-06 06:15:13 +02:00
Andrew Kelley
196e36bbb2 std: remove BoundedArray
This use case is handled by ArrayListUnmanaged via the "...Bounded"
method variants, and it's more optimal to share machine code, versus
generating multiple versions of each function for differing array
lengths.
2025-08-05 09:56:02 -07:00
Andrew Kelley
6f545683f3 std: replace various mem copies with @memmove 2025-08-05 09:56:02 -07:00
Ian Johnson
96be6f6566 std.compress.flate.Decompress: return correct size for unbuffered decompression
Closes #24686

As a bonus, this commit also makes the `git.zig` "testing `main`" compile again.
2025-08-04 19:32:14 -07:00
Alex Rønne Petersen
163e9ce7d9
Merge pull request #24629 from alexrp/android-requires-libc
`std.Target`: require libc for Android API levels prior to 29
2025-08-04 17:59:47 +02:00
Matthew Lugg
9b509dad30
Merge pull request #24689 from mlugg/build-no-watch-regression
build runner: fix FTBFS on targets without `--watch` implementation
2025-08-04 16:23:58 +01:00
Loris Cro
70c6a9fba6 init: small fix to zig init template
it was placing the current zig version in the wrong field
2025-08-04 14:25:08 +02:00
mlugg
32a069f909
cli: add --debug-libc to zig build
This option is similar to `--debug-target` in letting us override
details of the build runner target when debugging the build system.
While `--debug-target` lets us override the target query, this option
lets us override the libc installation. This option is only usable in a
compiler built with debug extensions.

I am using this to (try to) test the build runner targeting SerenityOS.
2025-08-04 09:47:56 +01:00
Ali Cheraghi
cd4b03c5ed
spirv: define and use extended instruction set opcodes 2025-08-04 07:05:00 +03:30
Andrew Kelley
dabae3f9dc linker: remove dependency on std.fifo 2025-08-03 19:22:28 -07:00
Justus Klausecker
7c35070b90 zig fmt: apply new cast builtin order 2025-08-03 14:59:56 +02:00
Ali Cheraghi
246e1de554
Watch: do not fail when file is removed
before this we would get a crash
2025-08-03 13:16:49 +03:30
Matthew Lugg
c80aa9f719
Merge pull request #22997 from Rexicon226/align-0-reify
sema: compile error on reifying align(0) fields and pointers
2025-08-03 09:58:23 +01:00
Ali Cheraghi
58b9200106
spirv: use packed struct's backing int type for shift value 2025-08-03 12:10:23 +03:30
DialecticalMaterialist
616e69c807 OpenGL SPIR-V support
The support was already there but somebody forgot to allow to use the
calling conventions spirv_fragment and spirv_vertex when having opengl
as os tag.
2025-08-03 10:39:07 +02:00
David Rubin
4d1010d36c llvm: correctly lower double_integer for rv32 2025-08-03 10:22:26 +02:00
Ali Cheraghi
d15a7b1b21
spirv: move more type emitting functions to Module 2025-08-03 04:54:28 +03:30
Ali Cheraghi
5525a90a47
spirv: remove deduplication ISel 2025-08-02 08:56:39 +03:30
Ali Cheraghi
31de2c873f
spirv: refactor 2025-08-02 04:16:01 +03:30
Andrew Kelley
742956865c
Merge pull request #24614 from ziglang/flate
std.compress.flate: rework decompression and delete compression
2025-08-01 16:34:43 -07:00
mlugg
dcc3e6e1dd build system: replace fuzzing UI with build UI, add time report
This commit replaces the "fuzzer" UI, previously accessed with the
`--fuzz` and `--port` flags, with a more interesting web UI which allows
more interactions with the Zig build system. Most notably, it allows
accessing the data emitted by a new "time report" system, which allows
users to see which parts of Zig programs take the longest to compile.

The option to expose the web UI is `--webui`. By default, it will listen
on `[::1]` on a random port, but any IPv6 or IPv4 address can be
specified with e.g. `--webui=[::1]:8000` or `--webui=127.0.0.1:8000`.
The options `--fuzz` and `--time-report` both imply `--webui` if not
given. Currently, `--webui` is incompatible with `--watch`; specifying
both will cause `zig build` to exit with a fatal error.

When the web UI is enabled, the build runner spawns the web server as
soon as the configure phase completes. The frontend code consists of one
HTML file, one JavaScript file, two CSS files, and a few Zig source
files which are built into a WASM blob on-demand -- this is all very
similar to the old fuzzer UI. Also inherited from the fuzzer UI is that
the build system communicates with web clients over a WebSocket
connection.

When the build finishes, if `--webui` was passed (i.e. if the web server
is running), the build runner does not terminate; it continues running
to serve web requests, allowing interactive control of the build system.

In the web interface is an overall "status" indicating whether a build
is currently running, and also a list of all steps in this build. There
are visual indicators (colors and spinners) for in-progress, succeeded,
and failed steps. There is a "Rebuild" button which will cause the build
system to reset the state of every step (note that this does not affect
caching) and evaluate the step graph again.

If `--time-report` is passed to `zig build`, a new section of the
interface becomes visible, which associates every build step with a
"time report". For most steps, this is just a simple "time taken" value.
However, for `Compile` steps, the compiler communicates with the build
system to provide it with much more interesting information: time taken
for various pipeline phases, with a per-declaration and per-file
breakdown, sorted by slowest declarations/files first. This feature is
still in its early stages: the data can be a little tricky to
understand, and there is no way to, for instance, sort by different
properties, or filter to certain files. However, it has already given us
some interesting statistics, and can be useful for spotting, for
instance, particularly complex and slow compile-time logic.
Additionally, if a compilation uses LLVM, its time report includes the
"LLVM pass timing" information, which was previously accessible with the
(now removed) `-ftime-report` compiler flag.

To make time reports more useful, ZIR and compilation caches are ignored
by the Zig compiler when they are enabled -- in other words, `Compile`
steps *always* run, even if their result should be cached. This means
that the flag can be used to analyze a project's compile time without
having to repeatedly clear cache directory, for instance. However, when
using `-fincremental`, updates other than the first will only show you
the statistics for what changed on that particular update. Notably, this
gives us a fairly nice way to see exactly which declarations were
re-analyzed by an incremental update.

If `--fuzz` is passed to `zig build`, another section of the web
interface becomes visible, this time exposing the fuzzer. This is quite
similar to the fuzzer UI this commit replaces, with only a few cosmetic
tweaks. The interface is closer than before to supporting multiple fuzz
steps at a time (in line with the overall strategy for this build UI,
the goal will be for all of the fuzz steps to be accessible in the same
interface), but still doesn't actually support it. The fuzzer UI looks
quite different under the hood: as a result, various bugs are fixed,
although other bugs remain. For instance, viewing the source code of any
file other than the root of the main module is completely broken (as on
master) due to some bogus file-to-module assignment logic in the fuzzer
UI.

Implementation notes:

* The `lib/build-web/` directory holds the client side of the web UI.

* The general server logic is in `std.Build.WebServer`.

* Fuzzing-specific logic is in `std.Build.Fuzz`.

* `std.Build.abi` is the new home of `std.Build.Fuzz.abi`, since it now
  relates to the build system web UI in general.

* The build runner now has an **actual** general-purpose allocator,
  because thanks to `--watch` and `--webui`, the process can be
  arbitrarily long-lived. The gpa is `std.heap.DebugAllocator`, but the
  arena remains backed by `std.heap.page_allocator` for efficiency. I
  fixed several crashes caused by conflation of `gpa` and `arena` in the
  build runner and `std.Build`, but there may still be some I have
  missed.

* The I/O logic in `std.Build.WebServer` is pretty gnarly; there are a
  *lot* of threads involved. I anticipate this situation improving
  significantly once the `std.Io` interface (with concurrency support)
  is introduced.
2025-08-01 23:48:21 +01:00
David Rubin
5678a600ff
refactor reifyUnion alignment handling 2025-08-01 14:57:16 -07:00