aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
AgeCommit message (Collapse)Author
2025-09-20Sema: avoid ptr_add/ptr_sub instructions void elem typeAndrew Kelley
2025-09-20Sema: fix YAGNI violationAndrew Kelley
2025-09-20Sema: more conservative elem_ptr_load implementationAndrew Kelley
like field_ptr_load, this now does byval operations when the lhs is comptime-known.
2025-09-20frontend: replace elem_val_node with elem_ptr_loadAndrew Kelley
avoids unnecessary copies
2025-09-20frontend: replace field_val and field_val_namedAndrew Kelley
with field_ptr_load and field_ptr_named_load. These avoid doing by-val load operations for structs that are runtime-known while keeping the previous semantics for comptime-known values.
2025-09-20Sema: fix source location of "declared here" noteAndrew Kelley
point at the var not at the init expression
2025-09-20Sema: fix accessing ptr field of double array pointer with sentinelAndrew Kelley
2025-09-20compiler: require comptime vector indexesAndrew Kelley
2025-09-15frontend: fix reference tracking through coerced function bodiesmlugg
This bug was manifesting for user as a nasty link error because they were calling their application's main entry point as a coerced function, which essentially broke reference tracking for the entire ZCU, causing exported symbols to silently not get exported. I've been a little unsure about how coerced functions should interact with the unit graph before, but the solution is actually really obvious now: they shouldn't! `Sema` is now responsible for unwrapping possibly-coerced functions *before* queuing analysis or marking unit references. This makes the reference graph optimal (there are no redundant edges representing coerced versions of the same function) and simplifies logic elsewhere at the expense of just a few lines in Sema.
2025-09-07frontend: vectors and arrays no longer support in-memory coercionAndrew Kelley
closes #25172
2025-09-05Sema: forbid packed unions with mismatched field bit sizesAndrew Kelley
2025-08-29std.Io: delete GenericReaderAndrew Kelley
and delete deprecated alias std.io
2025-08-28AstGen: forward result type through unary float builtinsDavid Rubin
Uses a new `float_op_result_ty` ZIR instruction tag.
2025-08-15what if we kissed by the extern source bitmlugg
2025-08-13Merge pull request #24674 from Justus2308/undef-shift-bitwiseMatthew Lugg
Sema: Improve comptime arithmetic undef handling
2025-08-13sema: strip `@splat` operand result type before checking itDavid Rubin
2025-08-13Merge pull request #24381 from Justus2308/switch-better-underscoreMatthew Lugg
Enhance switch on non-exhaustive enums
2025-08-13std.io.Writer.Allocating: rename getWritten() to written()Isaac Freund
This "get" is useless noise and was copied from FixedBufferWriter. Since this API has not yet landed in a release, now is a good time to make the breaking change to fix this.
2025-08-12fix: emit vector instead of scalar u1_zero in shl_with_overflow logicJustus Klausecker
2025-08-12add undef shift tests ; mirror `zirShl` logic for `@shlWithOverflow`Justus Klausecker
2025-08-12Sema: replace all remaining aggregate interns related to `@typeInfo`Justus Klausecker
2025-08-12remove redundant test casesJustus Klausecker
2025-08-12replace even more aggregate internsJustus Klausecker
2025-08-12Sema: replace most aggregate interns with pt.aggregateValueJustus Klausecker
2025-08-12address most commentsJustus Klausecker
2025-08-12make `>>` a compile error with any undef arg ; add a bunch of test casesJustus Klausecker
2025-08-12Sema: Improve comptime arithmetic undef handlingJustus Klausecker
This commit expands on the foundations laid by https://github.com/ziglang/zig/pull/23177 and moves even more `Sema`-only functionality from `Value` to `Sema.arith`. Specifically all shift and bitwise operations, `@truncate`, `@bitReverse` and `@byteSwap` have been moved and adapted to the new rules around `undefined`. Especially the comptime shift operations have been basically rewritten, fixing many open issues in the process. New rules applied to operators: * `<<`, `@shlExact`, `@shlWithOverflow`, `>>`, `@shrExact`: compile error if any operand is undef * `<<|`, `~`, `^`, `@truncate`, `@bitReverse`, `@byteSwap`: return undef if any operand is undef * `&`, `|`: Return undef if both operands are undef, turn undef into actual `0xAA` bytes otherwise Additionally this commit canonicalizes the representation of aggregates with all-undefined members in the `InternPool` by disallowing them and enforcing the usage of a single typed `undef` value instead. This reduces the amount of edge cases and fixes a bunch of bugs related to partially undefined vecs. List of operations directly affected by this patch: * `<<`, `<<|`, `@shlExact`, `@shlWithOverflow` * `>>`, `@shrExact` * `&`, `|`, `~`, `^` and their atomic rmw + reduce pendants * `@truncate`, `@bitReverse`, `@byteSwap`
2025-08-11std.ArrayList: make unmanaged the defaultAndrew Kelley
2025-08-08Sema: fix unreasonable progress node numbersmlugg
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-08compiler: improve error reportingmlugg
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-07remove unnecessary discardJustus Klausecker
2025-08-07Add support for both '_' and 'else' prongs at the same time in switch statementsJustus Klausecker
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-07Permit explicit tags with '_' switch prongJustus Klausecker
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-06Sema: fix initializing comptime-known constant with OPV union fieldmlugg
Resolves: #24716
2025-08-06Revert "Sema: Stop adding Windows implib link inputs for `extern "..."` syntax."Alex Rønne Petersen
This reverts commit b461d07a5464aec86c533434dab0b58edfffb331. 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-05std: replace various mem copies with `@memmove`Andrew Kelley
2025-08-03Merge pull request #22997 from Rexicon226/align-0-reifyMatthew Lugg
sema: compile error on reifying align(0) fields and pointers
2025-08-01build system: replace fuzzing UI with build UI, add time reportmlugg
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-01refactor `reifyUnion` alignment handlingDavid Rubin
2025-08-01remove usages of `.alignment = 0`David Rubin
2025-08-01Sema: compile error on reifying align(0) struct fieldsDavid Rubin
2025-07-31Sema: remove incorrect `requireRuntimeBlock` callsJackson Wambolt
Part of #22353 Resolves: #24273 Co-Authored-By: Matthew Lugg <mlugg@mlugg.co.uk>
2025-07-31Merge pull request #24632 from mlugg/lossy-int-to-float-coercionMatthew Lugg
Sema: compile error on lossy int to float coercion
2025-07-31Sema: add note suggesting dropping try on non error-unionsmikastiv
2025-07-31Sema: disallow slicing many-item pointer with different sentineldweiller
This change prevents adding or changing the sentinel in the type of a many-item pointer via the slicing syntax `ptr[a.. :S]`.
2025-07-31Sema: compile error on lossy int to float coercionmlugg
Resolves: #21586
2025-07-30Sema: check min/max operand typesJackson Wambolt
2025-07-30Sema: disallow tags on non-auto unions when reifying (#23488)Krzysztof Wolicki
2025-07-30Sema: remove incorrect safety check for saturating left shiftJustus Klausecker
2025-07-29Sema: don't rely on Livenessmlugg
We're currently experimenting with backends which effectively do their own liveness analysis, so this old trick of mine isn't necessarily valid anymore. However, we can fix that trivially: just make the "nop" instruction we jam into here have the right type. That way, the leftover field/element pointer instructions are perfectly valid, but still unused.