218 Commits

Author SHA1 Message Date
Jacob Young
e5d5a8bc4e x86_64: implement switch jump tables 2025-01-16 20:42:08 -05:00
mlugg
d00e05f186
all: update to std.builtin.Type.Pointer.Size field renames
This was done by regex substitution with `sed`. I then manually went
over the entire diff and fixed any incorrect changes.

This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since
my regex happened to also trigger here. I opted to leave these changes
in, since they *are* a correct migration, even if they're not the one I
was trying to do!
2025-01-16 12:46:29 +00:00
mlugg
e9bd2d45d4
Sema: rewrite semantic analysis of function calls
This rewrite improves some error messages, hugely simplifies the logic,
and fixes several bugs. One of these bugs is technically a new rule
which Andrew and I agreed on: if a parameter has a comptime-only type
but is not declared `comptime`, then the corresponding call argument
should not be *evaluated* at comptime; only resolved. Implementing this
required changing how function types work a little, which in turn
required allowing a new kind of function coercion for some generic use
cases: function coercions are now allowed to implicitly *remove*
`comptime` annotations from parameters with comptime-only types. This is
okay because removing the annotation affects only the call site.

Resolves: #22262
2025-01-09 06:46:47 +00:00
Alex Rønne Petersen
c9e67e71c1
std.Target: Replace isARM() with isArmOrThumb() and rename it to isArm().
The old isARM() function was a portability trap. With the name it had, it seemed
like the obviously correct function to use, but it didn't include Thumb. In the
vast majority of cases where someone wants to ask "is the target Arm?", Thumb
*should* be included.

There are exactly 3 cases in the codebase where we do actually need to exclude
Thumb, although one of those is in Aro and mirrors a check in Clang that is
itself likely a bug. These rare cases can just add an extra isThumb() check.
2024-11-03 09:29:30 +01:00
mlugg
d11bbde5f9
compiler: remove anonymous struct types, unify all tuples
This commit reworks how anonymous struct literals and tuples work.

Previously, an untyped anonymous struct literal
(e.g. `const x = .{ .a = 123 }`) was given an "anonymous struct type",
which is a special kind of struct which coerces using structural
equivalence. This mechanism was a holdover from before we used
RLS / result types as the primary mechanism of type inference. This
commit changes the language so that the type assigned here is a "normal"
struct type. It uses a form of equivalence based on the AST node and the
type's structure, much like a reified (`@Type`) type.

Additionally, tuples have been simplified. The distinction between
"simple" and "complex" tuple types is eliminated. All tuples, even those
explicitly declared using `struct { ... }` syntax, use structural
equivalence, and do not undergo staged type resolution. Tuples are very
restricted: they cannot have non-`auto` layouts, cannot have aligned
fields, and cannot have default values with the exception of `comptime`
fields. Tuples currently do not have optimized layout, but this can be
changed in the future.

This change simplifies the language, and fixes some problematic
coercions through pointers which led to unintuitive behavior.

Resolves: #16865
2024-10-31 20:42:53 +00:00
mlugg
097766bba3 compiler: implement @FieldType
Resolves: #21702
2024-10-18 08:50:40 +01:00
David Rubin
bc161430b0 riscv: implement optional_payload_ptr_set 2024-09-12 20:29:10 -04:00
David Rubin
fbac7afa0f
riscv: implement errunion_payload_ptr_set 2024-09-01 17:34:06 +01:00
mlugg
c3fb30803f
behavior: avoid field/decl name conflicts 2024-08-29 23:43:52 +01:00
mlugg
0fe3fd01dd
std: update std.builtin.Type fields to follow naming conventions
The compiler actually doesn't need any functional changes for this: Sema
does reification based on the tag indices of `std.builtin.Type` already!
So, no zig1.wasm update is necessary.

This change is necessary to disallow name clashes between fields and
decls on a type, which is a prerequisite of #9938.
2024-08-28 08:39:59 +01:00
David Rubin
8da212c11b
riscv: update tests and fix reuse bug 2024-07-26 04:19:58 -07:00
David Rubin
a1f6a8ef90
riscv: airAsm rewrite
with this rewrite we can call functions inside of
inline assembly, enabling us to use the default start.zig logic

all that's left is to implement lr/sc loops for atomically manipulating
1 and 2 byte values, after which we can use the segfault handler logic.
2024-07-26 04:19:55 -07:00
David Rubin
b533e848a2
riscv: enable passing tests 2024-07-26 04:19:17 -07:00
David Rubin
9bc7e8c852
riscv: update tests 2024-07-26 04:05:43 -07:00
David Rubin
1820f44104
riscv: implement sub-byte addition 2024-07-26 04:05:42 -07:00
David Rubin
cde6956b21
riscv: remove redundant assert in genBinOp 2024-07-26 04:05:41 -07: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
7a02878f4e
riscv: truncate airStructFieldVal result 2024-07-14 23:02:33 -07:00
David Rubin
4fd8900337
riscv: rewrite "binOp"
Reorganize how the binOp and genBinOp functions work.

I've spent quite a while here reading exactly through the spec and so many
tests are enabled because of several critical issues the old design had.

There are some regressions that will take a long time to figure out individually
so I will ignore them for now, and pray they get fixed by themselves. When
we're closer to 100% passing is when I will start diving into them one-by-one.
2024-06-13 02:24:39 -07:00
David Rubin
a270c6f8c8
riscv: implement optional logic 2024-06-13 02:22:33 -07:00
David Rubin
083b7b483e
riscv: zero registers when using register-wide operations
what was happening is that instructions like `lb` were only affecting the lower bytes of the register and leaving the top dirty. this would lead to situtations were `cmp_eq` for example was using `xor`, which was failing because of the left-over stuff in the top of the register.

with this commit, we now zero out or truncate depending on the context, to ensure instructions like xor will provide proper results.
2024-06-13 02:22:04 -07:00
David Rubin
b67995689d
riscv: add airAggregateInit for arrays 2024-06-13 02:22:04 -07:00
David Rubin
05de6c279b
riscv: std.fmt.format running
- implements `airSlice`, `airBitAnd`, `airBitOr`, `airShr`.

- got a basic design going for the `airErrorName` but for some reason it simply returns
empty bytes. will investigate further.

- only generating `.got.zig` entries when not compiling an object or shared library

- reduced the total amount of ops a mnemonic can have to 3, simplifying the logic
2024-06-13 02:20:47 -07:00
David Rubin
c457f35da5
riscv: arbitrary sized arrays 2024-06-13 02:19:40 -07:00
David Rubin
ffb63a05a3 riscv: finally fix bug + airAggregateInit
i just hadn't realized that I placed the `riscv_start` branch in the non-simplified
starts
2024-05-11 02:17:24 -07:00
David Rubin
2fd83d8c0a riscv: by-value structs + @min 2024-05-11 02:17:24 -07:00
David Rubin
a30af172e8 riscv: math progress 2024-05-11 02:17:24 -07:00
David Rubin
d9e0cafe64 riscv: add stage2_riscv to test matrix and bypass failing tests 2024-05-11 02:17:24 -07:00
Jacob Young
eb723a4070 Update uses of @fieldParentPtr to use RLS 2024-03-30 20:50:48 -04:00
Jacob Young
9b2345e182 Sema: rework @fieldParentPtr to accept a pointer type
There is no way to know the expected parent pointer attributes (most
notably alignment) from the type of the field pointer, so provide them
in the first argument.
2024-03-30 20:50:48 -04:00
mlugg
20403ee41d
behavior: add tests for #18816 2024-03-06 21:26:38 +00:00
Ali Chraghi
66e6d0d314 test: skip new failing tests for spirv 2024-02-15 18:44:24 +03:30
Jacob Young
6fe90a913a llvm: fix lowering of recursive debug info
This change allows recursing over types that are currently being
resolved fully with a second pass of forward resolution.

Closes #16414
2024-02-15 02:46:18 -08:00
Robin Voetter
9fbba0e01a
spirv: update tests 2024-02-04 19:09:33 +01:00
dweiller
8108c9f4d2 test/behavior: replace all 'comptime expect' with 'comptime assert' 2024-01-15 20:55:01 +11:00
Veikka Tuominen
804cee3b93 categorize behavior/bugs/<issueno>.zig tests 2024-01-06 16:49:41 -08:00
Bogdan Romanyuk
bece97ef24
Sema: ensure tuple fields is resolved and fix internal out-of-bounds access 2023-11-25 14:05:51 +00:00
Robin Voetter
28e1d82857
spirv: disable failing tests 2023-11-24 01:11:12 +01:00
mlugg
9c16b2370d
test: update behavior to silence 'var is never mutated' errors 2023-11-19 09:57:03 +00:00
mlugg
997eaf6d87 Sema: do not force resolution of struct field inits when calling function pointer field
b3462b7 caused a regression in a third-party project, since it forced
resolution of field initializers for any field call 'foo.bar()', despite
this only being necessary when 'bar' is a comptime field.

See https://github.com/ziglang/zig/pull/17692#issuecomment-1802096734.
2023-11-08 23:47:10 -07:00
kcbanner
f10499be0a
sema: analyze field init bodies in a second pass
This change allows struct field inits to use layout information
of their own struct without causing a circular dependency.

`semaStructFields` caches the ranges of the init bodies in the `StructType`
trailing data. The init bodies are then resolved by `resolveStructFieldInits`,
which is called before the inits are actually required.

Within the init bodies, the struct decl's instruction is repurposed to refer
to the field type itself. This is to allow us to easily rebuild the inst_map
mapping required for the init body instructions to refer to the field type.

Thanks to @mlugg for the guidance on this one!
2023-11-07 00:49:35 +00:00
Luuk de Gram
db1825e931
wasm: re-enable regressed tests 2023-11-01 19:47:15 +01:00
Jacob Young
d890e81761 mem: fix ub in writeInt
Use inline to vastly simplify the exposed API.  This allows a
comptime-known endian parameter to be propogated, making extra functions
for a specific endianness completely unnecessary.
2023-10-31 21:37:35 -04:00
DilithiumNitrate
91e117697a
Fix hasRuntimeBitsAdvanced lazy case for pointers and optionals
As suggested by mlugg, always returns `error.NeedLazy`. If this has a
performance impact, it could be replaced by adding lazy handling to
`comptimeOnlyAdvanced`.
2023-10-29 21:12:43 +00:00
Robin Voetter
4bf27da6a6 Revert "Revert "Merge pull request #17657 from Snektron/spirv-recursive-ptrs""
This reverts commit 9f0359d78f9facc38418e32b0e8c1bf6f99f0d26 in an attempt to
make the tests pass again. The CI failure from that merge should be unrelated
to this commit.
2023-10-23 06:27:12 -04:00
Andrew Kelley
9f0359d78f Revert "Merge pull request #17657 from Snektron/spirv-recursive-ptrs"
This reverts commit b822e841cda0adabe3fec260ff51c18508f7ee32, reversing
changes made to 0c99ba1eab63865592bb084feb271cd4e4b0357e.

This caused a CI failure when it landed in master branch.
2023-10-22 12:15:31 -07:00
Robin Voetter
6281ad91df
spirv: self-referential pointers via new fwd_ptr_type
Its a little ugly but it works.
2023-10-21 17:46:54 +02:00
Robin Voetter
1deec09f03
spirv: improve union operations
This removes the strategy where union with different active
fields would be generated, and instead simply pointer casts
the active field type where required. This also allows removing
spv.ptrType and using self.ptrType instead, and allows caching
all union types (because there is only the canonical one).
2023-10-21 17:46:53 +02:00
Robin Voetter
faad97edff
spirv: update failing / passing tests
Some tests are now failing due to debug info changes, some tests
now pass due to improved compiler functionality.
2023-10-15 20:08:18 +02:00
Robin Voetter
3ca1f88898
std.testing: disable expectEqualSlices printing for spirv 2023-10-15 14:00:26 +02:00