aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
AgeCommit message (Collapse)Author
2025-02-28Revert "Merge pull request #22898 from kristoff-it/deprecated-proposal"Andrew Kelley
This reverts commit dea72d15da4fba909dc3ccb2e9dc5286372ac023, reversing changes made to ab381933c87bcc744058d25a876cfdc0d23fc674. The changeset does not work as advertised and does not have sufficient test coverage. Reopens #22822
2025-02-26reword deprecated error slightlyAndrew Kelley
"found" -> "reached" to match "reached unreachable code"
2025-02-26`@deprecated`: optimize sema implementationLoris Cro
mlugg suggested a better way of implementing analysis of an istruction that cannot be referenced by other instructions.
2025-02-26`@deprecated`: add testsLoris Cro
2025-02-26initial implementation of `@deprecated`Loris Cro
2025-02-26Sema: remove legacy coercionmlugg
This was meant to be removed in #21817, but was somehow missed.
2025-02-24Merge pull request #22154 from alexrp/disable-intrinsicsAlex Rønne Petersen
compiler: Implement `@disableIntrinsics()` builtin function.
2025-02-23Sema: allow `@ptrCast` of slices changing the lengthmlugg
Also, refactor `Sema.ptrCastFull` to not be a horrifying hellscape.
2025-02-23compiler: Implement @disableIntrinsics() builtin function.Alex Rønne Petersen
Closes #21833. Closes #22110.
2025-02-22zig build fmtAndrew Kelley
2025-02-22Sema: Fix fnptr alignment safety checks to account for potential ISA tag.Alex Rønne Petersen
As seen on e.g. Arm/Thumb and MIPS (MIPS16/microMIPS). Fixes #22888.
2025-02-17std.Target: Remove functions that just wrap component functions.Alex Rønne Petersen
Functions like isMinGW() and isGnuLibC() have a good reason to exist: They look at multiple components of the target. But functions like isWasm(), isDarwin(), isGnu(), etc only exist to save 4-8 characters. I don't think this is a good enough reason to keep them, especially given that: * It's not immediately obvious to a reader whether target.isDarwin() means the same thing as target.os.tag.isDarwin() precisely because isMinGW() and similar functions *do* look at multiple components. * It's not clear where we would draw the line. The logical conclusion before this commit would be to also wrap Arch.isX86(), Os.Tag.isSolarish(), Abi.isOpenHarmony(), etc... this obviously quickly gets out of hand. * It's nice to just have a single correct way of doing something.
2025-02-17std.Target: Move Cpu.Arch.supportsAddressSpace() up to Cpu.Alex Rønne Petersen
This allows it to inspect CPU features which is needed for Propeller, and AVR in the future.
2025-02-17std.Target: Make Cpu.Arch.supportsAddressSpace() take an optional context.Alex Rønne Petersen
Allows deduplicating the code in Sema.
2025-02-17std.builtin: Rename CallingConvention.wasm_watc to wasm_mvp.Alex Rønne Petersen
2025-02-17std.builtin: Remove CallingConvention.arm_(apcs,aapcs16_vfp).Alex Rønne Petersen
* arm_apcs is the long dead "OABI" which we never had working support for. * arm_aapcs16_vfp is for arm-watchos-none which is a dead target that we've dropped support for.
2025-02-17std.Target: Remove Cpu.Arch.propeller2 and use a CPU feature instead.Alex Rønne Petersen
2025-02-17Sema: make source location in checkCallConvSupportsVarArgs more meaningfulTw
As calling convention may not be specified explicitly in the source, so use va_arg's location instead. Signed-off-by: Tw <tw19881113@gmail.com>
2025-02-15x86_64: implement error set and enum safetyJacob Young
This is all of the expected 0.14.0 progress on #21530, which can now be postponed once this commit is merged. This required rewriting the (un)wrap operations since the original implementations were extremely buggy. Also adds an easy way to retrigger Sema OPV bugs so that I don't have to keep updating #22419 all the time.
2025-02-10std.ArrayList: popOrNull() -> pop() [v2] (#22720)Meghan Denny
2025-02-07Merge pull request #22717 from jacobly0/x86_64-rewriteAndrew Kelley
x86_64: rewrite `@truncate`
2025-02-06x86_64: rewrite vector `@truncate`Jacob Young
2025-02-06Sema: add missing `validateRuntimeValue` callsmlugg
Resolves: #13791
2025-02-05Sema: fix `@typeInfo` of function with generic return type and IESmlugg
Resolves: #20088
2025-02-05Sema: fix `@errorCast` with error unionsmlugg
Resolves: #20169
2025-02-05Sema: disable runtime safety checks in comptime blocksmlugg
Sometimes we emit runtime instructions in comptime scopes. These instructions will be discarded, but they allow comptime blocks to contain intermediate runtime-known values, which is necessary for expressions like `runtime_array.len` to work. Since we will always throw away these runtime instructions, including safety checks is a time waste at best and trips an assertion at worst! Resolves: #20064
2025-02-05Sema: fix comparison between error set and comptime-known error unionmlugg
Resolves: #20613
2025-02-05Sema: add fast path to PTR when all types are the samemlugg
I have no idea why I didn't add this when I first implemented this PTR logic.
2025-02-05Sema: fix PTR of slice of sentinel-terminated arraymlugg
Resolves: #20901
2025-02-05compiler: provide result type to sentinel expression in slice operationmlugg
Resolves: #21867
2025-02-05Sema: fix crash on `@tagName` of undefined enum literalmlugg
Resolves: #20826
2025-02-04compiler: integrate importing ZON with incremental compilationmlugg
The changes from a few commits earlier, where semantic analysis no longer occurs if any Zig files failed to lower to ZIR, mean `file` dependencies are no longer necessary! However, we now need them for ZON files, to be invalidated whenever a ZON file changes.
2025-02-04compiler: integrate ZON with the ZIR caching systemmlugg
This came with a big cleanup to `Zcu.PerThread.updateFile` (formerly `astGenFile`). Also, change how the cache manifest works for files in the import table. Instead of being added to the manifest when we call `semaFile` on them, we iterate the import table after running the AstGen workers and add all the files to the cache manifest then. The downside is that this is a bit more eager to include files in the manifest; in particular, files which are imported but not actually referenced are now included in analysis. So, for instance, modifying any standard library file will invalidate all Zig compilations using that standard library, even if they don't use that file. The original motivation here was simply that the old logic in `semaFile` didn't translate nicely to ZON. However, it turns out to actually be necessary for correctness. Because `@import("foo.zig")` is an AstGen-level error if `foo.zig` does not exist, we need to invalidate the cache when an imported but unreferenced file is removed to make sure this error is triggered when it needs to be. Resolves: #22746
2025-02-04compiler: a few renamesmlugg
This is mainly in preparation for integrating ZonGen into the pipeline properly, although these names are better because `astGenFile` isn't *necessarily* running AstGen; it may determine that the current ZIR is up-to-date, or load cached ZIR.
2025-02-04Zcu: remove `*_loaded` fields on `File`mlugg
Instead, `source`, `tree`, and `zir` should all be optional. This is precisely what we're actually trying to model here; and `File` isn't optimized for memory consumption or serializability anyway, so it's fine to use a couple of extra bytes on actual optionals here.
2025-02-03compiler,std: implement ZON supportMason Remaley
This commit allows using ZON (Zig Object Notation) in a few ways. * `@import` can be used to load ZON at comptime and convert it to a normal Zig value. In this case, `@import` must have a result type. * `std.zon.parse` can be used to parse ZON at runtime, akin to the parsing logic in `std.json`. * `std.zon.stringify` can be used to convert arbitrary data structures to ZON at runtime, again akin to `std.json`.
2025-02-02fix: error on non-exhaustive enums with zero width backing type (#21374)Will Lillis
Co-authored-by: WillLillis <wlillis@umass.edu>
2025-02-01Merge pull request #22672 from jacobly0/x86_64-rewriteAndrew Kelley
x86_64: rewrite float conversions
2025-02-01compiler: do not propagate result type to `try` operandmlugg
This commit effectively reverts 9e683f0, and hence un-accepts #19777. While nice in theory, this proposal turned out to have a few problems. Firstly, supplying a result type implicitly coerces the operand to this type -- that's the main point of result types! But for `try`, this is actually a bad idea; we want a redundant `try` to be a compile error, not to silently coerce the non-error value to an error union. In practice, this didn't always happen, because the implementation was buggy anyway; but when it did, it was really quite silly. For instance, `try try ... try .{ ... }` was an accepted expression, with the inner initializer being initially coerced to `E!E!...E!T`. Secondly, the result type inference here didn't play nicely with `return`. If you write `return try`, the operand would actually receive a result type of `E!E!T`, since the `return` gave a result type of `E!T` and the `try` wrapped it in *another* error union. More generally, the problem here is that `try` doesn't know when it should or shouldn't nest error unions. This occasionally broke code which looked like it should work. So, this commit prevents `try` from propagating result types through to its operand. A key motivation for the original proposal here was decl literals; so, as a special case, `try .foo(...)` is still an allowed syntax form, caught by AstGen and specially lowered. This does open the doors to allowing other special cases for decl literals in future, such as `.foo(...) catch ...`, but those proposals are for another time. Resolves: #21991 Resolves: #22633
2025-02-01Sema: skip aliasing check and runtime operation for `@memcpy` of zero-bit typemlugg
This check isn't valid in such cases, because the source and destination pointers both refer to zero bits of memory, meaning they effectively never alias. Resolves: #21655
2025-02-01Sema: fix `@splat` of OPV arraysmlugg
2025-01-31x86_64: rewrite float vector conversionsJacob Young
2025-01-31Sema: introduce all_vector_instructions backend featureJacob Young
Sema is arbitrarily scalarizing some operations, which means that when I try to implement vectorized versions of those operations in a backend, they are impossible to test due to Sema not producing them. Now, I can implement them and then temporarily enable the new feature for that backend in order to test them. Once the backend supports all of them, the feature can be permanently enabled. This also deletes the Air instructions `int_from_bool` and `int_from_ptr`, which are just bitcasts with a fixed result type, since changing `un_op` to `ty_op` takes up the same amount of memory.
2025-01-30compiler: add `intcast_safe` AIR instructionmlugg
This instruction is like `intcast`, but includes two safety checks: * Checks that the int is in range of the destination type * If the destination type is an exhaustive enum, checks that the int is a named enum value This instruction is locked behind the `safety_checked_instructions` backend feature; if unsupported, Sema will emit a fallback, as with other safety-checked instructions. This instruction is used to add a missing safety check for `@enumFromInt` truncating bits. This check also has a fallback for backends which do not yet support `safety_checked_instructions`. Resolves: #21946
2025-01-29Sema: explain why we tried to call an `extern fn` at comptimemlugg
I recently saw a user hit the "comptime call of extern function" error, and get confused because they didn't know why the scope was `comptime`. So, use `explainWhyBlockIsComptime` on this and related errors to add all the relevant notes. The added test case shows the motivating situation.
2025-01-29Sema: `@memcpy` changesmlugg
* The langspec definition of `@memcpy` has been changed so that the source and destination element types must be in-memory coercible, allowing all such calls to be raw copying operations, not actually applying any coercions. * Implement aliasing check for comptime `@memcpy`; a compile error will now be emitted if the arguments alias. * Implement more efficient comptime `@memcpy` by loading and storing a whole array at once, similar to how `@memset` is implemented.
2025-01-26fix: Only suggest try on destructure of error union if payload type can be ↵Will Lillis
destructured (#21510)
2025-01-26Merge pull request #22602 from mlugg/incr-embedfileMatthew Lugg
incremental: handle `@embedFile`
2025-01-25Merge pull request #22581 from jacobly0/x86_64-rewriteAndrew Kelley
x86_64: rewrite `@abs` on floats
2025-01-25incremental: handle `@embedFile`mlugg
Uses of `@embedFile` register dependencies on the corresponding `Zcu.EmbedFile`. At the start of every update, we iterate all embedded files and update them if necessary, and invalidate the dependencies if they changed. In order to properly integrate with the lazy analysis model, failed embed files are now reported by the `AnalUnit` which actually used `@embedFile`; the filesystem error is stored in the `Zcu.EmbedFile`. An incremental test is added covering incremental updates to embedded files, and I have verified locally that dependency invalidation is working correctly.