2466 Commits

Author SHA1 Message Date
Pavel Verigo
a429d04ba9 stage2-wasm: enable already working tests 2025-03-24 14:59:58 +01:00
Pavel Verigo
ca2bd6d6ef stage2-wasm: fix comparing and storing optionals 2025-03-24 14:58:05 +01:00
David Rubin
22013f1b39
test: add a behavior test for 0-length loop fix 2025-03-24 06:58:01 -07:00
mlugg
26fdb81c16 Sema: fix in-memory coercion of functions introducing new generic parameters
While it is not allowed for a function coercion to change whether a
function is generic, it *is* okay to make existing concrete parameters
of a generic function also generic, or vice versa. Either of these cases
implies that the result is a generic function, so comptime type checks
will happen when the function is ultimately called.

Resolves: #21099
2025-03-24 04:32:45 +00:00
Jacob Young
98640cbeb8
Merge pull request #23209 from jacobly0/x86_64-rewrite
x86_64: rewrite wrapping multiplication
2025-03-23 21:56:58 -04:00
Jacob Young
f7e045c806 Merge pull request #23256 from xtexx/fix-gh-20113
x86_64: fix packedStore miscomp by spilling EFLAGS
2025-03-23 21:46:46 -04:00
Jacob Young
6705cbd5eb codegen: fix packed byte-aligned relocations
Closes #23131
2025-03-23 18:35:34 -04:00
Bingwu Zhang
a26f1768d8
x86_64: add behavior test for packed store 2025-03-22 16:36:14 +08:00
Jacob Young
2361468e23 x86_64: rewrite scalar shifts 2025-03-21 21:51:09 -04:00
Jacob Young
8e15321c7c behavior: split up x86_64 math tests 2025-03-21 21:51:08 -04:00
Jacob Young
c5c1c8538d x86_64: rewrite wrapping multiplication 2025-03-21 21:51:08 -04:00
Ali Cheraghi
d18eaf8586 spirv: aligned load for physical storage variables
Resolves #23212
2025-03-18 07:05:50 +03:30
Ali Cheraghi
54c097f50d spirv: packed struct init + field val access 2025-03-18 07:05:48 +03:30
Ali Cheraghi
50539a2447 spirv/target: arbitrary_precision_integers feature support 2025-03-17 21:56:17 +03:30
Ali Cheraghi
c1977bf0fb Sema: error on illegal code when targeting spirv 2025-03-17 21:56:14 +03:30
Ali Cheraghi
2fc409a32f spirv: don't hardcode test error type alignment 2025-03-17 20:19:08 +03:30
mlugg
2a4e06bcb3 Sema: rewrite comptime arithmetic
This commit reworks how Sema handles arithmetic on comptime-known
values, fixing many bugs in the process.

The general pattern is that arithmetic on comptime-known values is now
handled by the new namespace `Sema.arith`. Functions handling comptime
arithmetic no longer live on `Value`; this is because some of them can
emit compile errors, so some *can't* go on `Value`. Only semantic
analysis should really be doing arithmetic on `Value`s anyway, so it
makes sense for it to integrate more tightly with `Sema`.

This commit also implements more coherent rules surrounding how
`undefined` interacts with comptime and mixed-comptime-runtime
arithmetic. The rules are as follows.

* If an operation cannot trigger Illegal Behavior, and any operand is
  `undefined`, the result is `undefined`. This includes operations like
  `0 *| undef`, where the LHS logically *could* be used to determine a
  defined result. This is partly to simplify the language, but mostly to
  permit codegen backends to represent `undefined` values as completely
  invalid states.

* If an operation *can* trigger Illegal Behvaior, and any operand is
  `undefined`, then Illegal Behavior results. This occurs even if the
  operand in question isn't the one that "decides" illegal behavior; for
  instance, `undef / 1` is undefined. This is for the same reasons as
  described above.

* An operation which would trigger Illegal Behavior, when evaluated at
  comptime, instead triggers a compile error. Additionally, if one
  operand is comptime-known undef, such that the other (runtime-known)
  operand isn't needed to determine that Illegal Behavior would occur,
  the compile error is triggered.

* The only situation in which an operation with one comptime-known
  operand has a comptime-known result is if that operand is undefined,
  in which case the result is either undefined or a compile error per
  the above rules. This could potentially be loosened in future (for
  instance, `0 * rt` could be comptime-known 0 with a runtime assertion
  that `rt` is not undefined), but at least for now, defining it more
  conservatively simplifies the language and allows us to easily change
  this in future if desired.

This commit fixes many bugs regarding the handling of `undefined`,
particularly in vectors. Along with a collection of smaller tests, two
very large test cases are added to check arithmetic on `undefined`.

The operations which have been rewritten in this PR are:

* `+`, `+%`, `+|`, `@addWithOverflow`
* `-`, `-%`, `-|`, `@subWithOverflow`
* `*`, `*%`, `*|`, `@mulWithOverflow`
* `/`, `@divFloor`, `@divTrunc`, `@divExact`
* `%`, `@rem`, `@mod`

Other arithmetic operations are currently unchanged.

Resolves: #22743
Resolves: #22745
Resolves: #22748
Resolves: #22749
Resolves: #22914
2025-03-16 08:17:50 +00:00
mlugg
aa3db7cc15 Sema: correctly handle empty by-ref initializers
Resolves: #23210
2025-03-16 03:05:33 +00:00
Andrew Kelley
982c500be5
Merge pull request #23188 from jacobly0/fix-23143
x86_64: fix crashes with symbols
2025-03-11 16:11:09 -04:00
mlugg
423907c270 Sema: fix handling of @This() on opaques
Resolves: #22869
2025-03-11 13:13:52 +00:00
Jacob Young
cff90e3ae0 x86_64: implement select of register mask 2025-03-10 10:38:33 -04:00
Andrew Kelley
539f3effd3
Merge pull request #21933 from kcbanner/comptime_nan_comparison
Fix float vector comparisons with signed zero and NaN, add test coverage
2025-03-09 15:06:25 -04:00
kcbanner
144d69b571 test: add comptime memoization tests for bit-for-bit float equality 2025-03-04 23:31:12 -05:00
kcbanner
8eefc4c5c2 test: skip the float vector cmp tests on failing targets 2025-03-04 23:31:08 -05:00
Linus Groh
79460d4a3e Remove uses of deprecated callconv aliases 2025-03-05 03:01:43 +00:00
Matthew Lugg
c76f451abc
Merge pull request #22979 from mlugg/remove-legacy-coercions
Sema: remove legacy coercion
2025-03-03 22:18:28 +00:00
kcbanner
71d0d4bbfe test: separate out float vector tests and skip them on unsupported backends 2025-03-03 15:35:07 -05:00
kcbanner
981f84157c Value: fix comparison of NaN in compareHeteroAdvanaced
Sema: fix equality comparison of signed zeroes and NaN in compareScalar
tests: add test coverage for vector float comparisons
2025-03-03 15:35:07 -05:00
Jacob Young
a6525c1762
Merge pull request #22529 from xtexx/x86-64/shl-sat-int
x86_64: Implement integer saturating left shifting codegen
2025-03-02 02:51:36 -05:00
Bingwu Zhang
1da909a1e2
x86_64: add behavior tests for saturating shift left
Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
Signed-off-by: Bingwu Zhang <xtex@aosc.io>
2025-03-02 10:30:43 +08:00
xtex
4e32193de3
x86_64: implement integer saturating left shifting codegen
Simliarly to shl_with_overflow, we first SHL/SAL the integer, then
SHR/SAR it back to compare if overflow happens.
If overflow happened, set result to the upper limit to make it saturating.

Bug: #17645
Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
Signed-off-by: Bingwu Zhang <xtex@aosc.io>
2025-03-02 10:30:32 +08:00
Jacob Young
50b40c9621 x86_64: rewrite wrapping add/sub 2025-03-01 16:29:22 -05:00
mlugg
3aaf394249
test: remove dependencies on legacy coercion 2025-02-26 00:17:09 +00:00
Ali Cheraghi
aec0f9b3e7
test: skip failing tests with spirv-vulkan 2025-02-24 19:39:42 +01:00
mlugg
5e20e9b449 Sema: allow @ptrCast of slices changing the length
Also, refactor `Sema.ptrCastFull` to not be a horrifying hellscape.
2025-02-23 08:28:58 +00:00
Jacob Young
220f80e71d Dwarf: fix lowering of comptime-only optional pointer null values
Closes #22974
2025-02-22 22:47:32 -05:00
David Rubin
84aac8b6c7 Type: resolve union tag type before checking for runtime bits 2025-02-22 22:22:55 -05:00
Andrew Kelley
eb3c7f5706 zig build fmt 2025-02-22 17:09:20 -08:00
Pavel Verigo
b25d93e7d9 stage2-wasm: implement switch_dispatch + handle > 32 bit integers in switches
Updated solution is future proof for arbitary size integer handling for both strategies .br_table lowering if switch case is dense, .br_if base jump table if values are too sparse.
2025-02-22 18:34:00 -05:00
Jacob Young
300cb4881f x86_64: rewrite scalar @bitReverse 2025-02-22 00:05:47 -05:00
Alex Rønne Petersen
fc7a0c4878 Sema: Fix fnptr alignment safety checks to account for potential ISA tag.
As seen on e.g. Arm/Thumb and MIPS (MIPS16/microMIPS).

Fixes #22888.
2025-02-22 04:12:46 +01:00
Jacob Young
7d70d7b215 x86_64: rewrite scalar @popCount 2025-02-18 09:47:44 -05:00
Jacob Young
ebea56d279 x86_64: rewrite scalar @ctz 2025-02-18 09:47:44 -05:00
Andrew Kelley
d2e70ef84a
Merge pull request #22913 from jacobly0/x86_64-rewrite
x86_64: rewrite unsafe int vector multiplication
2025-02-17 16:13:22 -08:00
Alex Rønne Petersen
481b7bf3f0
std.Target: Remove functions that just wrap component functions.
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-17 19:18:19 +01:00
Jacob Young
82eedf56d7 x86_64: rewrite scalar @byteSwap 2025-02-17 05:36:18 -05:00
Jacob Young
cec6867d76 x86_64: rewrite unsafe int vector multiplication 2025-02-17 00:10:24 -05:00
Jacob Young
dcc9fe322e x86_64: rewrite unsafe scalar int multiplication 2025-02-15 04:13:21 -05:00
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