12 Commits

Author SHA1 Message Date
Ali Cheraghi
872f68c9cb
rename spirv backend name
`stage2_spirv64` -> `stage2_spirv`
2025-06-16 13:22:19 +03:30
Ali Cheraghi
aec0f9b3e7
test: skip failing tests with spirv-vulkan 2025-02-24 19:39:42 +01:00
David Rubin
8d30fc45c4
riscv: implement more operators
we can run `std.debug.print` now, with both run-time strings and integers!
2024-07-26 04:05:39 -07:00
David Rubin
d9e0cafe64 riscv: add stage2_riscv to test matrix and bypass failing tests 2024-05-11 02:17:24 -07:00
Robin Voetter
ac16545895
spirv: enable passing tests 2024-04-06 13:52:48 +02:00
Robin Voetter
27b91288dc
spirv: disable failing tests 2024-03-30 19:47:56 +01:00
Jacob Young
c11b6adf13 Ast: fix comptime destructure
A preceding `comptime` keyword was being ignored if the first
destructure variable was an expression.
2024-03-17 15:23:16 -07:00
Robin Voetter
9fbba0e01a
spirv: update tests 2024-02-04 19:09:33 +01:00
mlugg
9c16b2370d
test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
mlugg
9b394a200a Sema: allow destructuring vectors
This was intended to work when destructuring was first implemented, and
was just unintentionally missed out.
2023-11-07 06:11:01 +00:00
mlugg
644041b3a4 Sema: refactor detection of comptime-known consts
This was previously implemented by analyzing the AIR prior to the ZIR
`make_ptr_const` instruction. This solution was highly delicate, and in
particular broke down whenever there was a second `alloc` between the
`store` and `alloc` instructions, which is especially common in
destructure statements.

Sema now uses a different strategy to detect whether a `const` is
comptime-known. When the `alloc` is created, Sema begins tracking all
pointers and stores which refer to that allocation in temporary local
state. If any store is not comptime-known or has a higher runtime index
than the allocation, the allocation is marked as being runtime-known.
When we reach the `make_ptr_const` instruction, if the allocation is not
marked as runtime-known, it must be comptime-known. Sema will use the
set of `store` instructions to re-initialize the value in comptime
memory. We optimize for the common case of a single `store` instruction
by not creating a comptime alloc in this case, instead directly plucking
the result value from the instruction.

Resolves: #16083
2023-09-23 13:51:18 +01:00
mlugg
88f5315ddf compiler: implement destructuring syntax
This change implements the following syntax into the compiler:

```zig
const x: u32, var y, foo.bar = .{ 1, 2, 3 };
```

A destructure expression may only appear within a block (i.e. not at
comtainer scope). The LHS consists of a sequence of comma-separated var
decls and/or lvalue expressions. The RHS is a normal expression.

A new result location type, `destructure`, is used, which contains
result pointers for each component of the destructure. This means that
when the RHS is a more complicated expression, peer type resolution is
not used: each result value is individually destructured and written to
the result pointers. RLS is always used for destructure expressions,
meaning every `const` on the LHS of such an expression creates a true
stack allocation.

Aside from anonymous array literals, Sema is capable of destructuring
the following types:
* Tuples
* Arrays
* Vectors

A destructure may be prefixed with the `comptime` keyword, in which case
the entire destructure is evaluated at comptime: this means all `var`s
in the LHS are `comptime var`s, every lvalue expression is evaluated at
comptime, and the RHS is evaluated at comptime. If every LHS is a
`const`, this is not allowed: as with single declarations, the user
should instead mark the RHS as `comptime`.

There are a few subtleties in the grammar changes here. For one thing,
if every LHS is an lvalue expression (rather than a var decl), a
destructure is considered an expression. This makes, for instance,
`if (cond) x, y = .{ 1, 2 };` valid Zig code. A destructure is allowed
in almost every context where a standard assignment expression is
permitted. The exception is `switch` prongs, which cannot be
destructures as the comma is ambiguous with the end of the prong.

A follow-up commit will begin utilizing this syntax in the Zig compiler.

Resolves: #498
2023-09-15 11:33:53 -07:00