Commit Graph

2518 Commits

Author SHA1 Message Date
Jacob Young 4ea18c22f9 x86_64: rewrite array access 2025-02-15 03:45:21 -05:00
Jacob Young f6bcc9dbcb x86_64: rewrite scalar and vector int @rem 2025-02-15 03:45:21 -05:00
Jacob Young 8c48376d64 x86_64: rewrite scalar and vector int @divTrunc 2025-02-15 03:45:21 -05:00
Jacob Young 9f121ec8fb x86_64: implement unsafe scalar and vector integer add/sub 2025-02-15 03:45:21 -05:00
Jacob Young 13ca87e204 x86_64: implement conversions between float and int vectors 2025-02-12 10:11:54 -05:00
Jacob Young 5433e0438c cbe: fix ub triggered by mulw overflowing the promoted type
Closes #21914
2025-02-10 17:22:16 -08:00
Jacob Young 74fbcd22e6 cbe: fix crash rendering argument names in lazy functions
Closes #19905
2025-02-10 17:20:52 -08:00
Jacob Young 4e4775d6bd x86_64: implement conversions between scalar floats and ints
Closes #22797
2025-02-09 00:42:55 -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
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 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 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
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
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
Jacob Young e4c049e410 x86_64: rewrite comparisons 2025-01-29 22:00:08 -08: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
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
Jacob Young b1fa89439a x86_64: rewrite float vector @abs and equality comparisons 2025-01-24 20:56:11 -05:00
Jacob Young ae3d95fc8d x86_64: rewrite scalar float equality comparisons 2025-01-24 20:56:11 -05:00
BratishkaErik 941677e083 std.Build: add addLibrary function (#22554)
Acts as a replacement for `addSharedLibrary` and `addStaticLibrary`, but
linking mode can be changed more easily in build.zig, for example:

In library:
```zig
const linkage = b.option(std.builtin.LinkMode, "linkage", "Link mode for a foo_bar library") orelse .static; // or other default

const lib = b.addLibrary(.{
    .linkage = linkage,
    .name = "foo_bar",
    .root_module = mod,
});
```

In consumer:
```zig
const dep_foo_bar = b.dependency("foo_bar", .{
    .target = target,
    .optimize = optimize,
    .linkage = .static // or dynamic
});

mod.linkLibrary(dep_foor_bar.artifact("foo_bar"));
```

It also matches nicely with `linkLibrary` name.

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2025-01-22 02:29:21 +00:00
Jacob Young d652dd0658 x86_64: rewrite @abs for scalar floats 2025-01-21 06:39:24 -05:00
mlugg 0ec6b2dd88 compiler: simplify generic functions, fix issues with inline calls
The original motivation here was to fix regressions caused by #22414.
However, while working on this, I ended up discussing a language
simplification with Andrew, which changes things a little from how they
worked before #22414.

The main user-facing change here is that any reference to a prior
function parameter, even if potentially comptime-known at the usage
site or even not analyzed, now makes a function generic. This applies
even if the parameter being referenced is not a `comptime` parameter,
since it could still be populated when performing an inline call. This
is a breaking language change.

The detection of this is done in AstGen; when evaluating a parameter
type or return type, we track whether it referenced any prior parameter,
and if so, we mark this type as being "generic" in ZIR. This will cause
Sema to not evaluate it until the time of instantiation or inline call.

A lovely consequence of this from an implementation perspective is that
it eliminates the need for most of the "generic poison" system. In
particular, `error.GenericPoison` is now completely unnecessary, because
we identify generic expressions earlier in the pipeline; this simplifies
the compiler and avoids redundant work. This also entirely eliminates
the concept of the "generic poison value". The only remnant of this
system is the "generic poison type" (`Type.generic_poison` and
`InternPool.Index.generic_poison_type`). This type is used in two
places:

* During semantic analysis, to represent an unknown result type.
* When storing generic function types, to represent a generic parameter/return type.

It's possible that these use cases should instead use `.none`, but I
leave that investigation to a future adventurer.

One last thing. Prior to #22414, inline calls were a little inefficient,
because they re-evaluated even non-generic parameter types whenever they
were called. Changing this behavior is what ultimately led to #22538.
Well, because the new logic will mark a type expression as generic if
there is any change its resolved type could differ in an inline call,
this redundant work is unnecessary! So, this is another way in which the
new design reduces redundant work and complexity.

Resolves: #22494
Resolves: #22532
Resolves: #22538
2025-01-21 02:41:42 +00:00
mlugg 8bcb578507 Sema: fix is_non_null_ptr handling for runtime-known pointers
We can still often determine a comptime result based on the type, even
if the pointer is runtime-known.

Also, we previously used load -> is non null instead of AIR
`is_non_null_ptr` if the pointer is comptime-known, but that's a bad
heuristic. Instead, we should check for the pointer to be
comptime-known, *and* for the load to be comptime-known, and only in
that case should we call `Sema.analyzeIsNonNull`.

Resolves: #22556
2025-01-21 00:33:32 +00:00
Jacob Young b9198b708f x86_64: rewrite @abs 2025-01-20 14:47:07 -05:00
mlugg 3b6e5ba490 Sema: don't try to initialize global union pointer at comptime
Resolves: #19832
2025-01-18 14:30:06 +00:00
Jacob Young 8c8dfb35f3 x86_64: fix crashes compiling the compiler and tests 2025-01-16 20:47:30 -05:00
Jacob Young c3d33440f0 x86_64: pass more behavior tests 2025-01-16 20:47:30 -05:00
Jacob Young 666d76d85c x86_64: implement load and store 2025-01-16 20:47:30 -05:00
Jacob Young 63730441d0 x86_64: implement union access 2025-01-16 20:47:30 -05:00