17740 Commits

Author SHA1 Message Date
Jakub Konka
4ef26fc355 pass more behaviour tests 2022-03-24 17:04:50 +01:00
Jakub Konka
608025456b x64: account for signed ints in struct_field_val when struct fits in a register 2022-03-24 17:02:29 +01:00
Jakub Konka
9d2ff7ed16 x64: fix struct_field_val for structs fitting in register 2022-03-24 17:02:29 +01:00
Jakub Konka
77352c5bea x64: implement aggregate_init for arrays 2022-03-24 17:02:29 +01:00
Jakub Konka
4e801c2783 x64: implement aggregate_init for structs 2022-03-24 17:02:29 +01:00
Jakub Konka
2286f9bd1f dwarf: add debug info for tuples and anon structs 2022-03-24 17:02:29 +01:00
Andrew Kelley
2af69710a7 stage2: fix some generics issues
* std.meta: correct use of `default_value` in reification. stage1
   accepted a wrong type for `null`.
 * Sema: after instantiating a generic function, if the return type ends
   up being a comptime-known type, then we return an error, undoing the
   generic function instantiation, and making a comptime function call
   instead.
   - We also needed to clean up the dependency graph in this case.
 * Sema: reified enums set tag_ty_inferred to false since an integer tag
   type is provided. This is a limitation of the `@Type` builtin which
   will be addressed with #10710.
 * Sema: fix resolveInferredErrorSet incorrectly calling
   ensureFuncBodyAnalyzed on generic functions.
2022-03-23 23:28:05 -07:00
Andrew Kelley
aca42c6259 Sema: fix comptime elem_ptr compare fixed address 2022-03-23 19:58:13 -07:00
Andrew Kelley
74ccd0c40b Sema: Value.copy: we gotta copy the bytes
For Value.Tag.bytes, the value copy implementation did not copy the
bytes array. No good. This operation must do a deep copy. If we want
some other mechanism for not copying very large byte buffers then it has
to work differently than this one.
2022-03-23 19:20:38 -07:00
Andrew Kelley
7378ce67da Sema: introduce a type resolution queue
That happens after a function body is analyzed. This prevents circular
dependency compile errors and yet a way to mark types that need to be
fully resolved before a given function is sent to the codegen backend.
2022-03-23 18:45:51 -07:00
Andrew Kelley
57539a26b4 std.os: disable failing fnctl file locking test
See #11074
2022-03-23 17:29:39 -07:00
Andrew Kelley
e02ec8f7f5
Merge pull request #11280 from Luukdegram/wasm-errors
stage2: wasm - `@errorName` and more
2022-03-23 20:18:50 -04:00
Mitchell Hashimoto
a36f4ee290 stage2: able to slice to sentinel index at comptime
The runtime behavior allowed this in both stage1 and stage2, but stage1
fails with index out of bounds during comptime. This behavior makes
sense to support, and comptime behavior should match runtime behavior. I
implement this fix only in stage2.
2022-03-23 17:08:08 -04:00
Andrew Kelley
f27d3409bd behavior tests: disable failing stage1 test
My previous commit added a new behavior test that passes for stage2 but
I forgot to check whether it passes for stage1. Since it does not, it
has to be disabled.

Additionally, this commit organizes behavior tests; there is no longer a
section of tests only passing for stage1. Instead, tests are disabled on
an individual basis. There is an except for the file which has global
assembly in it.
2022-03-23 14:06:07 -07:00
Andrew Kelley
a2b0b0015d
Merge pull request #11273 from topolarity/bugfix-11272
stage2: Properly "flatten" elem_ptrs before deref
2022-03-23 16:46:50 -04:00
Andrew Kelley
41e300adf1 add behavior test to cover bug fix in previous commit 2022-03-23 13:46:06 -07:00
Cody Tapscott
5374e245c5 stage2: Remove premature elem_val index check
We were enforcing bounds on the index of an elem_ptr in pointerDeref,
but we want to support out-of-bounds accesses by reinterpreting memory.
This removes that check, so that the deref falls back to bitcasting, as
usual.

This was masked by another bug that was forcing bitcasts incorrectly,
which is why this wasn't noticed earlier.
2022-03-23 13:44:31 -07:00
Cody Tapscott
1c22381909 stage2: Properly "flatten" elem_ptrs before deref
Sema.pointerDeref() assumes that elem_ptrs have been "flattened" when
they were created, so that you an elem_ptr will never be the array_ptr
of another elem_ptr when they share the same type.

Value.elemPtr does this already, but a couple of places in Sema were
bypassing this logic.
2022-03-23 13:44:31 -07:00
Luuk de Gram
5cb16dfa59
wasm: Enable all passing tests
All tests have been manually verified which are now passing. This means that any remaining
TODO is an actual to-be-fixed or to-be-implemented test case.
2022-03-23 21:40:33 +01:00
Luuk de Gram
60676a0ba5
wasm: Implement more instructions
Implements the following instructions:
 - int_to_float
 - ptr_slice_len_ptr
 - ptr_slice_ptr_ptr
 - unwrap_errunion_payload_ptr
 - unwrap_errunion_err_ptr
2022-03-23 21:40:33 +01:00
Luuk de Gram
685f05b562
wasm: Implement opt_payload_ptr
Implements lowering constants for pointers of value 'opt_payload_ptr'.
The offset is calculated by determining the abi size of the full type and
then substracting the payload size.
2022-03-23 21:40:33 +01:00
Luuk de Gram
a9a629f89a
wasm: Fix switching on errors
Error sets contain the entire global error set.
Users are often switching on specific errors only present within that operand.
This means that cases are almost always sparse and not contiguous.
For this reason, we will instead emit the default case for error values not present in
that specific operand error set. This is fine as those cases will never be hit,
as prevented by the type system.

By still allowing jump tables for those cases, rather than if-else chains, we save runtime cost
as well as binary size.
2022-03-23 21:40:32 +01:00
Luuk de Gram
49051c0651
wasm: Implement @errorName
This implements the `error_name` instruction, which is emit for runtime `@errorName` callsites.

The implementation works by creating 2 symbols and corresponding atoms.
The initial symbol contains a table which each element consisting of a slice where the ptr field
points towards the error name, and the len field contains the error name length without the sentinel.

The secondary symbol contains a list of all error names from the global error set.

During the error_name instruction, we first get a pointer to the first symbol.
Then based on the operand we perform pointer arithmetic, to get the correct index into this table.
e.g. error index 2 = ptr + (2 * ptr size). The result of this will be stored in a local
and then returned as instruction result.

During `flush()` we populate the error names table by looping over the global error set
and creating a relocation for each error name. This relocation is appended to the table symbol.
Then finally, this name is written to the names list itself.

Finally, both symbols' atom are allocated within the rest of the binary.
When no error name is referenced, the `error_name_symbol` is never set, and therefore
no error name table will be emit into the final binary.
2022-03-23 21:40:32 +01:00
William Sengir
b872539a13 stage2: enable some passing array & vector tests 2022-03-23 16:39:29 -04:00
William Sengir
d7530c8f7b stage2: make zero-sized array not cause recursive type definition 2022-03-23 16:38:33 -04:00
Cody Tapscott
6fc07f49a9 stage2: concat/mult of slices yields ptr to array 2022-03-23 16:34:48 -04:00
Locria Cyber
23bae382c9 Add sem_open & sem_close 2022-03-23 16:31:03 -04:00
Cody Tapscott
a9a91a5d49 stage2 CBE: Improve support for unions and error sets
This includes various fixes/improvements to the C backend to improve
error/union support. It also fixes up our handling of decls, where some
decls were not correctly marked alive.
2022-03-23 16:29:38 -04:00
Andrew Kelley
2f9264d8dc stage2: fix -Domit-stage2 regression
This flag is used when building stage1 to omit the stage2 backends from
the compiler to save memory on the CI server. It regressed with the
merging of e8813b296bc55a13b534bd9b2a03e1f6af366915 because Value
functions started calling into Sema functions.

The end goal for this build option is to eliminate it.
2022-03-23 13:24:55 -07:00
Marc Tiehuis
2e0de0b4e2
math/big: correct fix for divmod (#11271)
Fixes #11166.
2022-03-23 19:24:25 +01:00
Andrew Kelley
1cf1346323 Sema: rename isArrayLike to isArrayOrVector 2022-03-22 22:00:03 -07:00
Andrew Kelley
8326ab7adb Sema: fix merge conflicts with previous commit
The previous commit and e8813b296bc55a13b534bd9b2a03e1f6af366915 had
merge conflicts which didn't get caught by git.
2022-03-22 20:44:32 -07:00
Mitchell Hashimoto
e81ebc24e9 stage2: runtime safety checks for slicing 2022-03-22 23:41:59 -04:00
Jakub Konka
47f1a43bb7 dwarf: lower enums 2022-03-22 23:37:20 -04:00
Daniele Cocca
8f9c3fd3df
CBE: enable more passing tests (#11258) 2022-03-22 23:24:36 -04:00
Locria Cyber
eb5e0cba21 Fix ucontext_t 2022-03-22 23:19:02 -04:00
Andrew Kelley
4a837dddd0
Merge pull request #11266 from joachimschmidt557/stage2-arm
stage2 ARM: move closer to test runner output working
2022-03-22 23:18:26 -04:00
Andrew Kelley
98b932cfab fix merge conflicts 2022-03-22 20:17:43 -07:00
joachimschmidt557
be1cca3416 stage2 ARM: implement comparison of optional pointers 2022-03-22 20:16:05 -07:00
joachimschmidt557
95e166b2e1 stage2 ARM: implement min, max for integers <= 32 bits 2022-03-22 20:16:05 -07:00
joachimschmidt557
62529a291b stage2 ARM: More support for error unions 2022-03-22 20:16:05 -07:00
joachimschmidt557
a4e8294c91 stage2 ARM: change semantics of MCValue.stack_argument_offset
MCValue.stack_argument_offset now has the same semantics as
MCValue.stack_offset
2022-03-22 20:16:05 -07:00
joachimschmidt557
6ac04d8fd7 stage2 ARM: change semantics of MCValue.stack_offset
A stack_offset will now denote the exact offset applied to the start
of the stack frame (=fp when frame pointer is emitted)
2022-03-22 20:16:05 -07:00
Andrew Kelley
e8813b296b
Merge pull request #11260 from ziglang/lazy-alignof
stage2: lazy `@alignOf`
2022-03-22 22:30:38 -04:00
Mitchell Hashimoto
cb6364624f stage2: slice behavior test passes, just has diff behavior from stage1
This is from discussions from #11249. The stage2 behavior is correct and
is strictly more accurate, so we'd prefer to keep it. In that case, I
modified the behavior tests to have the conditional between
stage1/stage2 and get this test passing.
2022-03-22 19:56:10 -04:00
Andrew Kelley
44f9061b71 fix merge conflicts and test cases 2022-03-22 15:58:19 -07:00
Andrew Kelley
60d8c4739d Sema: introduce a mechanism in Value to resolve types
This commit adds a new optional argument to several Value methods which
provides the ability to resolve types if it comes to it. This prevents
having duplicated logic inside both Sema and Value.

With this commit, the "struct contains slice of itself" test is passing
by exploiting the new lazy_align Value Tag.
2022-03-22 15:45:59 -07:00
Andrew Kelley
593130ce0a stage2: lazy @alignOf
Add a `target` parameter to every function that deals with Type and
Value.
2022-03-22 15:45:58 -07:00
Jakub Konka
b74f292410 Revert "ignore target lib dirs when invoked with -feach-lib-rpath"
This reverts commit 3701697a0a586e630a2452dea29951f0051a47fd.

The commit introduced a regression when building stage2 on nixOS where
the linker would fail to find relevant LLVM dynamic libraries as some
search dirs were missing.
2022-03-22 20:51:34 +01:00
Jan200101
3701697a0a ignore target lib dirs when invoked with -feach-lib-rpath 2022-03-22 09:03:22 +01:00