Commit graph

7436 commits

Author SHA1 Message Date
Andrew Kelley
6a6e72fff8
Merge pull request #20511 from archbirdplus
runtime page size detection
rework GeneralPurposeAllocator to reduce active mapping count
Allocator VTable API update
2025-02-07 06:21:51 -08:00
Andrew Kelley
2d4954ad63
Merge pull request #22717 from jacobly0/x86_64-rewrite
x86_64: rewrite `@truncate`
2025-02-07 04:06:50 -08:00
Isaac Freund
87bbb49d5f test: check @tagName() in callconv C function
This is a regression test for an x86_64 backend miscompilation when
using @tagName() in a callconv(.c) function with -fPIC.
2025-02-07 07:20:53 +01:00
Andrew Kelley
f1717777a2 std.heap: delete LoggingAllocator and friends
I don't think these belong in std, at least not in their current form.

If someone wants to add these back I'd like to review the patch before
it lands.

Reverts 629e2e7844
2025-02-06 14:23:23 -08:00
Jacob Young
6afc5770d3 wasm: disable failing tests 2025-02-06 17:02:54 -05:00
Jacob Young
c2718c4803 x86_64: rewrite float @mod 2025-02-06 16:14:53 -05:00
Jacob Young
288d3062d0 x86_64: avoid comparing different transcendental function impls 2025-02-06 16:14:53 -05:00
Jacob Young
fa9b0fa6d3 x86_64: rewrite most of the remaining float ops 2025-02-06 16:14:53 -05:00
Jacob Young
39119088f9 x86_64: rewrite vector @truncate 2025-02-06 16:14:53 -05:00
Jacob Young
c58e60a042 x86_64: rewrite scalar @truncate 2025-02-06 16:14:53 -05:00
mlugg
5d935e1137
behavior: add test for old bug
Resolves: #18435
2025-02-06 01:23:27 +00:00
mlugg
75ec7d863e
Sema: add missing validateRuntimeValue calls
Resolves: #13791
2025-02-06 01:11:10 +00:00
mlugg
164700740b
behavior: add test for old bug
Resolves: #13013
2025-02-06 00:52:03 +00:00
mlugg
6bd92a21b7
behavior: add test for old bug
Resolves: #2289
2025-02-06 00:51:59 +00:00
mlugg
b21becb2a6
incremental: fix crash when introducing syntax error
Clearing the analysis roots was very clever and all, but not actually
valid. We need to avoid *any* reference to the analysis errors if there
were any fatal files, and that includes sorting the errors!

Resolves: #22774
2025-02-05 22:00:55 +00:00
mlugg
3031d81387
Sema: fix @typeInfo of function with generic return type and IES
Resolves: #20088
2025-02-05 21:26:04 +00:00
mlugg
5317d88414
Sema: fix @errorCast with error unions
Resolves: #20169
2025-02-05 21:17:40 +00:00
mlugg
fbbf34e563
Sema: disable runtime safety checks in comptime blocks
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-05 21:17:40 +00:00
mlugg
cac814cf58
Sema: fix comparison between error set and comptime-known error union
Resolves: #20613
2025-02-05 20:13:56 +00:00
mlugg
fbe0ae4fd4
Sema: fix PTR of slice of sentinel-terminated array
Resolves: #20901
2025-02-05 19:53:12 +00:00
mlugg
0f38558435
compiler: provide result type to sentinel expression in slice operation
Resolves: #21867
2025-02-05 19:36:14 +00:00
mlugg
456f3c026b
Sema: fix crash on @tagName of undefined enum literal
Resolves: #20826
2025-02-05 19:08:05 +00:00
mlugg
3ce857d054
Sema: fix incorrectly succeeding type resolution
Resolves: #21436
2025-02-05 18:31:39 +00:00
Matthew Lugg
f01f1e33c9
Merge pull request #22754 from mlugg/files-and-stuff
ZON and incremental bits
2025-02-05 12:17:13 +00:00
Will Lillis
cf059ee087
AstGen: improve error for invalid bytes in strings and comments 2025-02-05 11:10:11 +02:00
mlugg
bebfa036ba
test: remove failing case
Unfortunately, now that this error is more in line with other `@import`
errors, it isn't so easy to have a test case for.
2025-02-04 18:30:50 +00:00
mlugg
d60910c9d0
incremental: add ZON test 2025-02-04 16:20:30 +00:00
Mason Remaley
13c6eb0d71
compiler,std: implement ZON support
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-03 09:14:37 +00:00
Will Lillis
953355ebea
fix: error on non-exhaustive enums with zero width backing type (#21374)
Co-authored-by: WillLillis <wlillis@umass.edu>
2025-02-02 03:36:16 +00:00
Andrew Kelley
963651bbf2
Merge pull request #22672 from jacobly0/x86_64-rewrite
x86_64: rewrite float conversions
2025-02-01 14:32:43 -08:00
mlugg
3924f173af compiler: do not propagate result type to try operand
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-01 15:48:45 +00:00
mlugg
149031204c
Sema: skip aliasing check and runtime operation for @memcpy of zero-bit type
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-01 09:48:18 +00:00
Jacob Young
4c5abe5ac6 x86_64: rewrite vector @intCast 2025-01-31 23:09:58 -05:00
Jacob Young
f0ac14ce97 x86_64: rewrite scalar @intCast 2025-01-31 23:09:36 -05:00
Jacob Young
b9531f5de6 x86_64: rewrite float vector conversions 2025-01-31 23:00:34 -05:00
Jacob Young
8195b64f57 x86_64: rewrite scalar float conversions 2025-01-31 23:00:34 -05:00
mlugg
b01d6b156c compiler: add intcast_safe AIR instruction
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-30 14:47:59 +00:00
Jacob Young
e4c049e410 x86_64: rewrite comparisons 2025-01-29 22:00:08 -08:00
mlugg
107b65ec5d Sema: explain why we tried to call an extern fn at comptime
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-29 18:43:24 +00:00
mlugg
71d16106ad Sema: @memcpy changes
* 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-29 06:35:22 +00:00
Andrew Kelley
eed3b9567d
Merge pull request #22610 from jacobly0/x86_64-rewrite
x86_64: rewrite `@min`/`@max` for scalar floats
2025-01-27 11:47:52 -08:00
Will Lillis
672bc8141f
fix: Only suggest try on destructure of error union if payload type can be destructured (#21510) 2025-01-26 19:38:07 +01:00
Jacob Young
654da648b3 x86_64: rewrite @min/@max for float vectors 2025-01-26 09:51:07 -05:00
Jacob Young
0c890bb9a4 x86_64: rewrite @min/@max for scalar floats 2025-01-26 06:58:37 -05:00
Matthew Lugg
3767b08039
Merge pull request #22602 from mlugg/incr-embedfile
incremental: handle `@embedFile`
2025-01-26 01:41:56 +00:00
Andrew Kelley
d0d5ca2b6c
Merge pull request #22581 from jacobly0/x86_64-rewrite
x86_64: rewrite `@abs` on floats
2025-01-25 07:30:45 -08:00
mlugg
fcf8d5ada2
incr-check: check compile errors against expected
Also modifies all incremental cases using `#expect_error` to include the
errors and notes which are expected.
2025-01-25 09:32:40 +00:00
mlugg
f47b8de2ad
incremental: handle @embedFile
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.
2025-01-25 06:07:08 +00:00
Jacob Young
c7433212d1 x86_64: rewrite scalar and vector int @min and @max 2025-01-24 21:02:32 -05:00
Jacob Young
ba82d6e83e x86_64: fix typo and lower optimized insts 2025-01-24 20:56:11 -05:00