Commit graph

110 commits

Author SHA1 Message Date
r00ster91
654e0b6679 fix(text): hyphenation and other fixes 2022-10-05 21:19:10 +02:00
joachimschmidt557
94499898e5
stage2 ARM: implement basic array_elem_val 2022-09-09 20:26:04 +02:00
joachimschmidt557
3794f2c493
stage2 ARM: implement struct_field_val for registers 2022-09-09 19:17:18 +02:00
Andrew Kelley
04572f6e34 Sema: fix coerceResultPtr
It did not handle properly when the dummy operand was a comptime_int; it
was crashing in coerce because comptime_int is supposed to be
comptime-known. So when calling coerceResultPtr, we pass the actual
operand, not a dummy operand, which means it will have the proper
comptime value when necessary.
2022-07-14 18:11:46 -07:00
joachimschmidt557
960c142060 stage2 ARM: implement basic intCast and error union wrapping 2022-06-25 21:16:51 +02:00
Koakuma
672d6df429 stage2: sparc64: Skip Sema-failing tests for now 2022-06-24 21:19:33 +07:00
Veikka Tuominen
b9dcbe6b4c Sema: handle sentinels in tupleToArray 2022-06-17 18:57:02 +03:00
Veikka Tuominen
2b93546b39 Sema: fix initialization of array with comptime only elem type 2022-06-03 20:21:20 +03:00
joachimschmidt557
ddd5b57045 stage2 AArch64: complete genTypedValue 2022-05-27 16:43:11 -04:00
Andrew Kelley
0e830b1630 clean up behavior tests
Split big test into the two separate things it is testing.
Add missing checks to the test which revealed the test is not actually
passing yet for the C backend.
2022-04-22 07:52:21 -07:00
Annika L
c992b25908 C backend: Fix array declarations 2022-04-22 07:42:47 -07:00
Jakub Konka
4ef26fc355 pass more behaviour tests 2022-03-24 17:04:50 +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
Luuk de Gram
2fc91a09a2
wasm: Enable passing tests
This enables the tests that now pass due to the changes to lower
parent pointers are lowered, as well as the additional features to unions.
2022-03-19 20:56:04 +01:00
joachimschmidt557
3ecba7d7a2
stage2 ARM: implement slice_elem_ptr, ptr_elem_ptr 2022-03-18 12:12:14 +01:00
Joachim Schmidt
3c3826bf93
Merge pull request #11192 from joachimschmidt557/stage2-arm
stage2 ARM: misc improvements
2022-03-17 09:40:41 +01: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
joachimschmidt557
ca1ffb0951
stage2 ARM: genSetStack for stack_argument_offset 2022-03-16 20:19:58 +01:00
joachimschmidt557
b74cd902c6
stage2 AArch64: enable mul for ints with <= 64 bits 2022-03-13 11:32:08 +01:00
Andrew Kelley
55ba335e0f Sema: fix resolution of inferred error sets
Introduce `Module.ensureFuncBodyAnalyzed` and corresponding `Sema`
function. This mirrors `ensureDeclAnalyzed` except also waits until the
function body has been semantically analyzed, meaning that inferred
error sets will have been populated.

Resolving error sets can now emit a "unable to resolve inferred error
set" error instead of producing an incorrect error set type. Resolving
error sets now calls `ensureFuncBodyAnalyzed`. Closes #11046.

`coerceInMemoryAllowedErrorSets` now does a lot more work to avoid
resolving an inferred error set if possible. Same with
`wrapErrorUnionSet`.

Inferred error set types no longer check the `func` field to determine if
they are equal. That was incorrect because an inline or comptime function
call produces a unique error set which has the same `*Module.Fn` value for
this field. Instead we use the `*Module.Fn.InferredErrorSet` pointers to
test equality of inferred error sets.
2022-03-11 19:38:07 -07:00
Mitchell Hashimoto
797f4db227 stage2: Array len field should be a usize not comptime_int 2022-03-11 17:15:36 -05:00
Andrew Kelley
f736cde397 Sema: implement pointer to tuple to pointer to array coercion
This involved an LLVM backend fix for the aggregate_init instruction.
2022-03-09 18:49:37 -07:00
joachimschmidt557
3ea603c82a stage2 ARM: implement ptr_add, ptr_sub for all element sizes
Also reduces slice_elem_val to ptr_add, simplifying the implementation
2022-03-08 10:54:08 +01:00
joachimschmidt557
a06e9eca45
stage2 AArch64: add more slice support
* airSlice
* airArrayToSlice
* and initial support for airSlicePtr and co
2022-03-05 11:31:51 +01:00
Jakub Konka
3ec74a1cd8 codegen: handle elem_ptr when lowering to memory
* x64: handle storing from-to non-stack memory
2022-03-02 20:04:34 -05:00
Andrew Kelley
1c8a86f063 Sema: detect comptime-known union initializations
Follow a similar pattern as we already do for validate_array_init and
validate_struct_init.

I threw in a bit of behavior test cleanup on top of it.
2022-03-02 17:28:39 -07:00
Jakub Konka
ec54ceee6d
Merge pull request #11016 from ziglang/x64-more-codegen 2022-03-01 09:14:23 +01:00
Andrew Kelley
157f66ec07 Sema: fix pointer type hash and equality functions
Several issues with pointer types are fixed:

Prior to this commit, Zig would not canonicalize a pointer type with
an explicit alignment to alignment=0 if it matched the pointee ABI
alignment. In order to fix this, `Type.ptr` now takes a Target
parameter. I also moved the host_size canonicalization to `Type.ptr`
since target is now available. Similarly, is_allowzero in the case of
C pointers is now treated as a canonicalization done by the function
rather than a precondition.

in-memory coercion for pointers now properly checks ABI alignment
of pointee types instead of incorrectly treating the 0 value as an
alignment.

Type equality is completely reworked based on the tag() rather than the
zigTypeTag(). It's still semantically based on zigTypeTag() but that
knowledge is implied rather than dictating the control flow of the
logic. Importantly, this fixes cases for opaques, structs, tuples,
enums, and unions, where type equality was incorrectly returning based
on whether the tag() values were equal.

Additionally, pointer type equality now takes into account alignment.
Because we canonicalize non-zero alignment which equals pointee type ABI
alignment to alignment=0, this now can be a simple integer comparison.

Type hashing is implemented for pointers and floats. Array types now
additionally hash their sentinels.

This regressed some behavior tests that were passing but only because
of bugs regarding type equality.

The C backend has a noticeable problem with lowering differently-aligned
pointers (particularly slices) as the same type, causing C compilation
errors due to duplicate declarations.
2022-02-28 19:22:16 -07:00
Jakub Konka
cfbc3537ef x64: pass more behavior tests 2022-02-28 23:20:05 +01:00
joachimschmidt557
1bf8da19e1
stage2 ARM: implement slice and array_to_slice 2022-02-27 21:38:56 +01:00
joachimschmidt557
91fbcf7093
stage2 ARM: enable more behavior tests 2022-02-27 21:38:56 +01:00
Andrew Kelley
6249a24e81 stage2: integer-backed packed structs
This implements #10113 for the self-hosted compiler only. It removes the
ability to override alignment of packed struct fields, and removes the
ability to put pointers and arrays inside packed structs.

After this commit, nearly all the behavior tests pass for the stage2 llvm
backend that involve packed structs.

I didn't implement the compile errors or compile error tests yet. I'm
waiting until we have stage2 building itself and then I want to rework
the compile error test harness with inspiration from Vexu's arocc test
harness. At that point it should be a much nicer dev experience to work
on compile errors.
2022-02-23 23:59:25 -07:00
Jakub Konka
25e4b16e25 Port more behavior tests 2022-02-22 21:57:42 +01:00
Jakub Konka
97c25fb8d0 x64: implement array_elem_val when array is stored in memory 2022-02-18 09:14:15 +01:00
Jakub Konka
abfaf8382b x64: implement array_elem_val when array fits in register 2022-02-18 09:14:15 +01:00
Jakub Konka
78e6f9c44c x64: fix ptr_add
However, still missing is taking into account pointer alignment
when performing arithmetic.
2022-02-16 14:13:06 +01:00
joachimschmidt557
22895f5616
stage2 AArch64: Enable behavior testing 2022-02-14 22:33:01 +01:00
Andrew Kelley
c349191b75 organize behavior tests
moving towards disabling failing tests on an individual basis
2022-02-12 21:13:07 -07:00
Jakub Konka
eb70f6e8d7
Merge pull request #10638 from Luukdegram/wasm-refactor
Stage2: wasm - Refactor lowering constants
2022-01-20 20:26:09 +01:00
Jakub Konka
df6c0067b2 stage2: fix passing arguments on the stack
* push the arguments in reverse order
* add logic for pushing args of any abi size to stack - very similar to
  `genSetStack` however, uses `.rsp` as the base register
* increment and decrement `.rsp` if we called a function with args on
  the stack in `airCall`
* add logic for recovering args from the caller's stack in the callee
2022-01-19 20:21:00 +01:00
Luuk de Gram
9615d7aee7
wasm: Refactor storing values.
Due to the new structure of lowerConstant, we can now simplify the logic in a lot of situations.
- We no longer have to check the `WValue`'s tag to determine how to load/store a value.
- We can now provide simple memcopy's for aggregate types.
- Constants are now memoized, meaning we do no longer lower constants on each callsite.
2022-01-19 20:01:23 +01:00
Jakub Konka
8201939d7f stage2: implement airArrayElemVal 2022-01-18 18:55:02 +01:00
Andrew Kelley
4d05f2ae5f remove zig_is_stage2 from @import("builtin")
Instead use the standarized option for communicating the
zig compiler backend at comptime, which is `zig_backend`. This was
introduced in commit 1c24ef0d0b.
2022-01-17 21:55:49 -07:00
Jakub Konka
ab204f81b0 stage2: return error.SkipZigTest in unsupported behavior tests 2022-01-17 20:30:44 +01:00
Andrew Kelley
336d0c97fe stage2: detection of comptime array literals
Introduce `validate_array_init_comptime`, similar to
`validate_struct_init_comptime` introduced in
713d2a9b38.

`zirValidateArrayInit` is improved to detect comptime array literals and
emit AIR accordingly. This code is very similar to the changes
introduced in that same commit for `zirValidateStructInit`.

The C backend needed some improvements to continue passing the same set
of tests:
 * `resolveInst` for arrays now will add a local `static const` with the
   array value and so then `elem_val` instructions reference that local.
   It memoizes accesses using `value_map`, which is changed to use
   `Air.Inst.Ref` as the key rather than `Air.Inst.Index`.
 * This required a mechanism for writing to a "header" which is lines
   that appear at the beginning of a function body, before everything
   else.
 * dbg_stmt output comments rather than `#line` directives.
   TODO comment reproduced here:

We need to re-evaluate whether to emit these or not. If we naively emit
these directives, the output file will report bogus line numbers because
every newline after the #line directive adds one to the line.
We also don't print the filename yet, so the output is strictly unhelpful.
If we wanted to go this route, we would need to go all the way and not output
newlines until the next dbg_stmt occurs.
Perhaps an additional compilation option is in order?

`Value.elemValue` is improved to support `elem_ptr` values.
2022-01-13 22:13:44 -07:00
drew
2f53406ad8
CBE; implement airLoad and airStore for arrays (#10452)
Effectively a small continuation of #10152

This allows the for.zig behavior tests to pass. Unfortunately to fully test everything I had to move a lot of behavior tests from array.zig; most of them now pass (sorry @rainbowbismuth!)

I'm also conflicted on how I store constants into arrays because it's kind of stupid; array's can't be re-initialized using the same syntax, so instead of initializing each element, a new array is made which is copied into the destination. This also required that renderValue can't emit string literals for byte arrays given that they need to always have an extra byte for the NULL terminator, meaning that strings are no longer grep-able in the output.
2021-12-30 15:19:12 -05:00
Andrew Kelley
85d4c8620f Sema: implement array coercion 2021-12-27 22:06:23 -07:00
Andrew Kelley
7f70c27e9d stage2: more division support
AIR:
 * div is renamed to div_trunc.
 * Add div_float, div_floor, div_exact.
   - Implemented in Sema and LLVM codegen. C backend has a stub.

Improvements to std.math.big.Int:
 * Add `eqZero` function to `Mutable`.
 * Fix incorrect results for `divFloor`.

Compiler-rt:
 * Add muloti4 to the stage2 section.
2021-10-21 19:05:26 -07:00
Andrew Kelley
0d4a94f32f stage2: improve handling of 0-bit types and arrays
* Make `alloc` AIR instructions call `resolveTypeLayout`.
 * `Sema.zirResolveInferredAlloc` now calls `requireRuntimeBlock` in the
   case that it operates on a non-comptime instruction.
 * `Type.abiSize` and `Type.abiAlignment` now return 0 for `void`
 * Sema: implement `resolveTypeFields` for unions.
 * LLVM Backend: support `ptr_elem_ptr` when the element type is 0-bit.
 * Type: improve `abiAlignment` implementation for structs to properly
   handle fields with non-default alignment.
 * Value: implement hashing array, vector, and structs.
2021-10-13 21:20:38 -07:00