Commit Graph

4080 Commits

Author SHA1 Message Date
Andrew Kelley
ad5770eba4 organize behavior tests
* Identify the ones that are passing and stop skipping them.
 * Flatten out the main behavior.zig file and have each individual test
   disable itself if it is not passing.
2022-03-18 15:02:52 -07:00
Andrew Kelley
d5803441cd
Merge pull request #11220 from schmee/vector-bitreverse
stage2: implement `@bitReverse` for vectors
2022-03-18 15:27:08 -04:00
Andrew Kelley
e60c0468aa
Merge pull request #11217 from jmc-88/cbe-tuples
CBE: add support for tuples
2022-03-18 15:23:40 -04:00
Jakub Konka
338bf55e84
Merge pull request #11216 from joachimschmidt557/stage2-arm
stage2 ARM: remove MCValue.embedded_in_code
2022-03-18 20:02:33 +01:00
Mitchell Hashimoto
3e74acb139 AstGen: labeled blocks should always complete with a normal break
They aren't inline blocks by nature of being labeled.

Fixes #11213
2022-03-18 11:40:39 -07:00
Daniele Cocca
6fdca525de CBE: add support for tuples
Also promote tests that are now passing.
2022-03-18 16:50:34 +00:00
John Schmidt
870341e32e stage2: implement @bitReverse for vectors 2022-03-18 16:28:38 +01:00
Daniele Cocca
085e122e29 bugs/3779: replace expectEqual*() with expect() 2022-03-18 11:20:28 +00:00
Daniele Cocca
af8586da3a tuple: replace expectEqual() with expect() 2022-03-18 11:18:12 +00:00
joachimschmidt557
3ecba7d7a2
stage2 ARM: implement slice_elem_ptr, ptr_elem_ptr 2022-03-18 12:12:14 +01:00
Andrew Kelley
f3f5a5d05b stage2: improve @typeName
* make it always return a fully qualified name. stage1 is inconsistent
   about this.
 * AstGen: fix anon_name_strategy to correctly be `func` when anon type
   creation happens in the operand of the return expression.
 * Sema: implement type names for the "function" naming strategy.
 * Put "enum", "union", "opaque", or "struct" in place of "anon" when
   creating respective anonymous Decl names.
 * std.testing: add `expectStringStartsWith`. Didn't end up using it
   after all.

Also this enables the real test runner for stage2 LLVM backend (sans
wasm32) since it works now.
2022-03-18 00:12:22 -07:00
Andrew Kelley
69d78bdae4 stage2 test harness: ask for the backend explicitly
Follow-up to 35d6ee08c4
2022-03-17 20:10:00 -07:00
Andrew Kelley
1d1364c3cd Sema: change how undefined is handled in coerce
Instead of doing it before the switch tower, do it afterwards, so that
special handling may be done before undefined gets casted to the
destination type.

In this case the special handling we want to do is *[N]T to []T setting
the slice length based on the array length, even when the array value is
undefined.
2022-03-17 19:59:20 -07:00
Andrew Kelley
76b382072a
Merge pull request #11200 from Luukdegram/wasm-memcpy
stage2: wasm - Implement memcpy instruction
2022-03-17 18:25:15 -07:00
John Schmidt
d7d2ccb7af Avoid index out of bounds for one-valued types in zirValidateArrayInit
Previously, the code assumed that `ptr_elem_ptr` was always followed by
a `store`, but this is not true for types with one value (such as `u0`).
2022-03-17 18:00:48 -07:00
John Schmidt
adfcc8851b Implement @byteSwap for vectors
Make the behavior tests for this a little more primitive to exercise as
little extra functionality as possible.
2022-03-17 18:00:48 -07:00
Andrew Kelley
7233a3324a stage2: implement @reduce
Notably, Value.eql and Value.hash are improved to treat NaN as equal to
itself, so that Type/Value can be hash map keys. Likewise float hashing
normalizes the float value before computing the hash.
2022-03-17 17:24:35 -07:00
Luuk de Gram
eafdc5562f
wasm: Implement 'memcpy' instruction
This implements the `memcpy` instruction and also updates the inline memcpy calls
to make use of the same implementation. We use the fast-loop when the length is comptime known,
and use a runtime loop when the length is runtime known.
We also perform feature-dection to emit a simply wasm memory.copy instruction when the feature
'bulk-memory' is enabled. (off by default).
2022-03-17 20:41:23 +01:00
Andrew Kelley
291f5055f4 disable x86_64 behavior test that does not run valgrind clean 2022-03-17 11:48:50 -07:00
Daniele Cocca
00ed8d9c50 CBE: enable more tests that are currently passing 2022-03-17 11:39:56 -07:00
Joachim Schmidt
3c3826bf93
Merge pull request #11192 from joachimschmidt557/stage2-arm
stage2 ARM: misc improvements
2022-03-17 09:40:41 +01:00
Andrew Kelley
87779cfd93 stage2: prevent UB in the LLVM backend
* Sema: fix `zirTypeInfo` allocating with the wrong arenas for some
   stuff.
 * LLVM: split `airDbgInline` into two functions, one for each AIR tag.
   - remove the redundant copy to type_map_arena. This is the first
     thing that lowerDebugType does so this hack was probably just
     accidentally avoiding UB (which is still present prior to this
     commit).
   - don't store an inline fn inst into the di_map for the generic
     decl.
   - use a dummy function type for the debug info to avoid whatever UB
     is happening.
   - we are now ignoring the function type passed in with the
     dbg_inline_begin and dbg_inline_end.
 * behavior tests: prepare the vector tests to be enabled one at a time.

Mitigates #11199.
2022-03-17 00:00:41 -07:00
Mitchell Hashimoto
79d3780fbd stage2: bit_not on u0 is always 0 2022-03-16 23:18:35 -07:00
Andrew Kelley
80642b5984 remove unnecessary TODO comment
`testing.expect` is better than `testing.expectEqual` for behavior
tests. Better for behavior tests to stick to only testing the limited
behavior they are meant to test and avoid functions such as
`expectEqual` that drag in too much of the standard library (in this
case to print helpful diffs about why a value is not equal to another).
2022-03-16 20:35:41 -07:00
John Schmidt
c8ed813097 Implement @mulAdd for vectors 2022-03-16 20:11:05 -07:00
Daniele Cocca
312536540b CBE: better handling of sentineled slices/arrays
Adds the sentinel element to the type name to avoid ambiguous
declarations, and outputs the sentinel element (if needed) even in what
would otherwise be empty arrays.
2022-03-16 19:58:45 -07:00
Mitchell Hashimoto
418197b6c5 stage2: elem_ptr needs to know if slice or direct access
This fixes one of the major issues plaguing the `std.sort` comptime tests.
The high level issue is that at comptime, we need to know whether `elem_ptr` is
being used to subslice an array-like pointer or access a child value. High-level
example:

    var x: [2][2]i32 = undefined;
    var a = &x[0]; // elem_ptr, type *[2]i32

    var y: [5]i32 = undefined;
    var b = y[1..3]; // elem_ptr, type *[2]i32

`a` is pointing directly to the 0th element of `x`. But `b` is
subslicing the 1st and 2nd element of `y`. At runtime with a well
defined memory layout, this is an inconsequential detail. At comptime,
the values aren't laid out exactly in-memory so we need to know the
difference.

This becomes an issue specifically in this case:

    var c: []i32 = a;
    var d: []i32 = b;

When converting the `*[N]T` to `[]T` we need to know what array to point
to. For runtime, its all the same. For comptime, we need to know if its
the parent array or the child value.

See the behavior tests for more details.

This commit fixes this by adding a boolean to track this on the
`elem_ptr`. We can't just immediately deref the child for `&x[0]`
because it is legal to ptrCast it to a many-pointer, do arithmetic, and
then cast it back (see behavior test) so we need to retain access to the
"parent" indexable.
2022-03-16 16:26:54 -07:00
joachimschmidt557
dcc1de12b0
stage2 ARM: implement addwrap, subwrap, mulwrap 2022-03-16 20:20:07 +01:00
joachimschmidt557
2412ac2c5f
stage2 ARM: fix shl for ints with bits < 32 2022-03-16 20:20:07 +01:00
joachimschmidt557
0eebdfcad3
stage2 ARM: fix bitwise negation of ints with bits < 32 2022-03-16 20:20:07 +01:00
joachimschmidt557
ca1ffb0951
stage2 ARM: genSetStack for stack_argument_offset 2022-03-16 20:19:58 +01:00
Andrew Kelley
1f313b3d7c LLVM: make the load function copy isByRef=true types 2022-03-16 11:52:22 -07:00
Mitchell Hashimoto
394252c9db stage2: move duplicate error set check to AstGen 2022-03-16 01:41:22 -04:00
Andrew Kelley
9a6fa67cbc Sema: only do store_ptr tuple optimization for arrays
Check the big comment in the diff for more details.
Fixes default-initialization of structs from empty struct literals.
2022-03-15 19:21:58 -07:00
Mitchell Hashimoto
fd43434149 stage2: TypeInfo for func with generic return type should set null
Prior to these, the return type was non-null but the value was generic
poison which wasn't usable in user-space. This sets the value to null.
This also adds a behavior test for this.

Co-authored-by: InKryption <inkryption07@gmail.com>
2022-03-15 20:12:22 -04:00
Cody Tapscott
480e7eec65 stage2: Fix panic on initializing comptime fields in tuple
This resolves https://github.com/ziglang/zig/issues/11159

The problem was that:
  1. We were not correctly deleting the field stores after recognizing
     that an array initializer was a comptime-known value.
  2. LLVM was not checking that the final type had no runtime bits, and
     so would generate an invalid store.

This also adds several test cases for related bugs, just to check these
in for later work.
2022-03-15 17:01:16 -07:00
Mitchell Hashimoto
7d0b6956c0 stage2: resolve type fully when resolving inferred allocs
We must resolve the type fully so that pointer children (i.e. slices)
are resolved. Additionally, we must resolve even if we can know the
value at comptime because the `alloc_inferred` ZIR always produces a
constant in the AIR.

Fixes #11181
2022-03-15 19:55:21 -04:00
Andrew Kelley
2c434cddd6 AstGen: add missing coercion for const locals
A const local which had its init expression write to the result pointer,
but then gets elided to directly initialize, was missing the coercion to
the type annotation.
2022-03-15 16:41:10 -07:00
Andrew Kelley
d4a0d5f959 Sema: implement @truncate for SIMD vectors 2022-03-15 15:09:48 -07:00
Daniele Cocca
9b5737b5a6 s/testClz/testCtz/g
The test name here was likely the result of a bad copy-paste, as the
test code is actually testing for trailing zeroes, not leading zeroes.
2022-03-15 19:00:16 +00:00
Andrew Kelley
c64279b15b Sema: fix shl_sat with comptime rhs 2022-03-14 23:15:01 -07:00
Andrew Kelley
2f92d1a026 stage2: fixups for topolarity-comptime-memory-reinterp branch
* don't store `has_well_defined_layout` in memory.
 * remove struct `hasWellDefinedLayout` logic. it's just
   `layout != .Auto`. This means we only need one implementation, in
   Type.
 * fix some of the cases being wrong in `hasWellDefinedLayout`, such as
   optional pointers.
 * move `tag_ty_inferred` field into a position that makes it more
   obvious how the struct layout will be done. Also we don't have a
   compiler that intelligently moves fields around so this layout is
   better.
 * Sema: don't `resolveTypeLayout` in `zirCoerceResultPtr` unless
   necessary.
 * Rename `ComptimePtrLoadKit` `target` field to `pointee` to avoid
   confusion with `target`.
2022-03-14 21:43:03 -07:00
Cody Tapscott
50a1ca24ca Add test for issue #11139 2022-03-14 21:43:02 -07:00
Cody Tapscott
1f76b4c6b8 stage2 llvm: Respect container type when lowering parent pointers
We need to make sure that we bitcast our pointers correctly before
we use get_element_ptr to compute the offset for the parent
pointer.

This also includes a small fix-up for a problem where ptrs to const
i64/u64 were not using the correct type in >1-level decl chains
(where we call lowerParentPtr recursively)
2022-03-14 21:42:43 -07:00
Andrew Kelley
a2a5d3c288
Merge pull request #11167 from mitchellh/codegen-arrays
stage2: codegen of arrays should use type length, not value length
2022-03-15 00:40:32 -04:00
Andrew Kelley
f36bf8506c
Merge pull request #11164 from mitchellh/reify-union
stage2: reify unions
2022-03-15 00:21:11 -04:00
Mitchell Hashimoto
67647154c1
stage2: apply fix for #11165 to codegen.zig for native backends
Co-authored-by: Cody Tapscott <topolarity@tapscott.me>
2022-03-14 20:00:17 -07:00
Mitchell Hashimoto
a859f94644
stage2: LLVM codegen of arrays should use type length, not value length
It is possible for the value length to be longer than the type because
we allow in-memory coercing of types such as `[5:0]u8` to `[5]u8`. In
such a case, the value length is 6 but the type length if 5.

The `.repeated` value type already got this right, so this is extending
similar logic out to `.aggregate` and `.bytes`. Both scenarios are
tested in behavior tests.

Fixes #11165
2022-03-14 17:41:12 -07:00
Andrew Kelley
84f96779c3
Merge pull request #11143 from jmc-88/cbe
CBE: Implement popCount, byteSwap, bitReverse for ints <= 128 bits
2022-03-14 18:23:00 -04:00
Mitchell Hashimoto
edd07aa808
stage2: reify unions 2022-03-14 14:34:28 -07:00