8856 Commits

Author SHA1 Message Date
Andrew Kelley
bd89a73d52 Sema: implement functions generic across callconv() or align() 2022-05-30 14:16:28 -07:00
Andrew Kelley
7e98b047dd AstGen: simplify function return type expressions
This check for primitives is already handled by the generic logic that
checks if the body ends up being empty. I kept this commit in the git
history in case we ever want that nodePrimitive function again in the
future, it might be useful.
2022-05-30 12:03:53 -07:00
Andrew Kelley
9da3a058d8 stage2: add missing data to ZIR encoding of functions
The main purpose of this commit is to prepare to implement support for
callconv(), align(), linksection(), and addrspace() annotations on
generic functions where the provided expression depends on comptime
parameters (making the function generic).

It's a rather involved change, so this commit only makes the necessary
changes to AstGen without regressing any behavior, and a follow-up
commit can finish the task by making the enhancements to Sema.

By my quick estimation, the new encoding for functions is a negligible
improvement - along the lines of 0.005% fewer total ZIR bytes on
average. Still, it's nice that this commit, while adding more
data into ZIR, actually ends up reducing the storage size thanks to a
slightly more sophisticated encoding.

Zir.Inst.ExtendedFunc is renamed to Zir.Inst.FuncFancy to eliminate
confusion about it being an extended instruction (it used to be but is
no longer). The encoding for this instruction is completely reworked.

The encoding for Zir.Inst.Func is also changed slightly - when the
return type body length is 1, then only a Zir.Inst.Ref is provided; not
a full body.

linksection() and addrspace() are now communicated via func_fancy ZIR
instruction rather than as part of the corresponding decl. This allows
their expressions to observe comptime parameters.
2022-05-30 12:03:53 -07:00
Veikka Tuominen
0274e2f1fd translate-c: check variable types being demoted to opaque 2022-05-29 12:07:29 +03:00
TwoClocks
36b4658752 translate-c: check record fields for opaque demotions 2022-05-29 12:06:37 +03:00
Veikka Tuominen
ee651c3cd3 Revert "reserve correct space for bitfields"
This reverts commit 22cb6938891c73d64b749a2516c8eaf79aa25b03.
2022-05-29 12:04:50 +03:00
TwoClocks
22cb693889 reserve correct space for bitfields 2022-05-28 17:31:26 +03:00
Ali Chraghi
0e6285c8fc math: make cast return optional instead of an error 2022-05-27 16:43:33 -04:00
joachimschmidt557
ddd5b57045 stage2 AArch64: complete genTypedValue 2022-05-27 16:43:11 -04:00
Andrew Kelley
4994ac18e4
Merge pull request #11733 from Vexu/stage2
more misc stage2 fixes
2022-05-27 16:20:49 -04:00
Veikka Tuominen
8bf3e1f8d0 AstGen: preserve inferred ptr result loc for breaks 2022-05-27 10:29:24 +03:00
Veikka Tuominen
e08cdad53b Sema: add error for runtime indexing comptime array 2022-05-27 10:29:15 +03:00
Andrew Kelley
41162ed646 stage0: fix -fsingle-threaded CLI arg parsing
closes #11730
2022-05-26 18:59:55 -07:00
Jakub Konka
d1e4600675 test: correctly track identical error msgs in handled errors list
Prior to this change, for an example compiler error test case with
multiple identical errors messages such as

```
:1:2: error: foo
:1:2: error: foo
```

the test harness would never increment the error index thus only
marking the very first error message as handled yielding a false
positive.

Additionally, while here, regress `dereference_anyopaque` test case
as not passing on `wasm32-wasi` target.
2022-05-26 16:23:56 +02:00
Jakub Konka
01607b54fc
Merge pull request #11722 from ziglang/stage2-behavior
stage2: enhance array concatenation and multiplication
2022-05-26 13:28:30 +02:00
Veikka Tuominen
92c4e4f2c2 Sema: zirArrayType does need source location 2022-05-26 13:26:55 +03:00
Jakub Konka
90f12a9186
Merge pull request #11723 from koachan/sparc64-codegen
stage2: sparc64: Small refactorings and stack pointer accounting fixes
2022-05-26 12:06:11 +02:00
Jakub Konka
0e0b00fd48 regalloc: use StaticBitSet internally 2022-05-26 12:05:51 +02:00
Koakuma
c5b99267c0 stage2: sparc64: Remove saved_regs_stack_space calculation
SPARC does not have an explicit notion of saving/restoring registers.
The usual windowing mechanism (save/restore/return) already takes care of that
for us.
2022-05-26 13:48:39 +07:00
Koakuma
3923722cc6 stage2: sparc64: Account for stack bias & reserved area in genSetReg
genSetReg with ptr_stack_offset should add the bias and reserved area
before emitting the instruction.
2022-05-26 13:48:29 +07:00
Koakuma
5fa971610e stage2: sparc64: Change binOpImmediate immediates to u12
Sync with the check in binOp.
2022-05-26 13:09:56 +07:00
Koakuma
0310d88d7e stage2: sparc64: Add cmp and mov synthetic instructions 2022-05-26 13:08:39 +07:00
Andrew Kelley
83f69af971 stage2: implement runtime array multiplication
Additionally:

 * Sema: fix array cat/mul not setting the sentinel value
   - This required an LLVM backend enhancement to the handling of the
     AIR instruction aggregate_init that likely needs to be
     propagated to the other backends.
 * Sema: report integer overflow of array concatenation in a proper
   compile error instead of crashing.
 * Sema: fix not using proper pointer address space for array cat/mul
2022-05-25 22:33:48 -07:00
Andrew Kelley
b82081e709 Sema: implement array concatenation with runtime operands 2022-05-25 22:33:48 -07:00
Andrew Kelley
ab88165326 Sema: generic function instantiations inherit branch quota 2022-05-25 23:32:52 -04:00
Andrew Kelley
1dd7109476
Merge pull request #11716 from Vexu/stage2
Stage2 misc fixes
2022-05-25 22:30:08 -04:00
Jakub Konka
97816e3cb8 aarch64: check lo/cc flag for unsigned sub_with_overflow
With this change, we are now correctly lowering `sub_with_overflow`
for signed and unsigned integers of register-sized integers (32-
or 64-bit precisely). We also match LLVM's behavior and so, the
condition flags we now set are:

* unsigned:
  - `add_with_overflow`: `hs`/`cs` (carry set)
  - `sub_with_overflow`: `lo`/`cc` (carry clear)
* signed:
  - `add_with_overflow`/`sub_with_overflow`: `vs` (overflow)
2022-05-25 23:43:45 +02:00
Veikka Tuominen
f409d925ad Sema: check for generic poison in resolveInst 2022-05-25 23:11:13 +03:00
Veikka Tuominen
eba66f4a58 Sema: handle block.is_typeof in more places 2022-05-25 19:57:44 +03:00
Veikka Tuominen
d214b6bdf0 stage2: packed struct fields do not have a byte offset 2022-05-25 19:57:38 +03:00
Jakub Konka
7000395a7d x64: use new condition codes enum for register with overflow mcv 2022-05-25 17:18:43 +02:00
Jakub Konka
5fb7070642 x64: move from compare_flags_* mcv to eflags with condition codes enum 2022-05-25 17:06:47 +02:00
Veikka Tuominen
b0e8bf15f5 Sema: add error for dereferencing comptime value at runtime 2022-05-25 17:39:55 +03:00
Andrew Kelley
a4ff94804c Sema: additional check for one-possible-value types in analyzeLoad
This is needed because pointers to zero-bit types are not necessarily
comptime known, but when doing a load, only the element type having one
possible value is relevant.
2022-05-24 18:20:03 -07:00
Andrew Kelley
1f16b07d6f stage2: treat error{}!void as a zero-bit type 2022-05-24 17:53:04 -07:00
Andrew Kelley
c711c788f0 stage2: fixes for error unions, optionals, errors
* `?E` where E is an error set with only one field now lowers the same
   as `bool`.
 * Fix implementation of errUnionErrOffset and errUnionPayloadOffset to
   properly compute the offset of each field. Also name them the same
   as the corresponding LLVM functions and have the same function
   signature, to avoid confusion. This fixes a bug where wasm was
   passing the error union type instead of the payload type.
 * Fix C backend handling of optionals with zero-bit payload types.
 * C backend: separate out airOptionalPayload and airOptionalPayloadPtr
   which reduces branching and cleans up control flow.
 * Make Type.isNoReturn return true for error sets with no fields.
 * Make `?error{}` have only one possible value (null).
2022-05-24 15:34:52 -07:00
joachimschmidt557
c847a462ae stage2 ARM: update to new union layout 2022-05-24 15:34:52 -07:00
Jakub Konka
26376c9fda wasm: use errUnionPayloadOffset and errUnionErrOffset from codegen.zig 2022-05-24 15:34:52 -07:00
Jakub Konka
8c49420928 aarch64: update for new error union layout 2022-05-24 15:34:52 -07:00
Jakub Konka
41f517e5f5 x64: update for new error union layout 2022-05-24 15:34:52 -07:00
Jakub Konka
b42100c70f dwarf: update abbrev info generation for new error union layout 2022-05-24 15:34:52 -07:00
Andrew Kelley
cd59b8277d LLVM: rename two functions
llvmType -> lowerType
genTypedValue -> lowerValue
2022-05-24 15:34:52 -07:00
Andrew Kelley
02e9d9b43b stage2: make ?anyerror represented the same as anyerror
I was able to get the backend implementation working on LLVM and the C
backend, but I'm going to ask for some help on the other backends.
2022-05-24 15:34:52 -07:00
Andrew Kelley
c97c7f9e3b C backend: update to new error union semantics 2022-05-24 15:34:52 -07:00
Luuk de Gram
3a059ebe4c wasm: Fixes for error union semantics 2022-05-24 15:34:52 -07:00
Luuk de Gram
c90a97f9be codegen: Order error union fields per alignment
Based on the size of the payload the native backends will lower
the error union with its fields (errorset & payload) in the correct order.
e.g. ErrorA!u8 will first lower the error set's value and then the payload.
In the event of ErrorA!u32 will lower the payload first.
2022-05-24 15:34:52 -07:00
Andrew Kelley
3264abe3d8 stage2: fixes for error union semantics
* Sema: avoid unnecessary safety checks when an error set is empty.
 * Sema: make zirErrorToInt handle comptime errors that are represented
   as integers.
 * Sema: make empty error sets properly integrate with
   typeHasOnePossibleValue.
 * Type: correct the ABI alignment and size of error unions which have
   both zero-bit error set and zero-bit payload. The previous code did
   not account for the fact that we still need to store a bit for
   whether there is an error.
 * LLVM: lower error unions possibly with the payload first or with the
   error code first, depending on alignment. Previously it always put
   the error code first and used a padding array.
 * LLVM: lower functions which have an empty error set as the return
   type the same as anyerror, so that they can be used where
   fn()anyerror function pointers are expected. In such functions, Zig
   will lower ret to returning zero instead of void.

As a result, one more behavior test is passing.
2022-05-24 15:34:52 -07:00
Andrew Kelley
818fbd9c56 stage2: string literal interning
This is a temporary addition to stage2 in order to match stage1 behavior,
however the end-game once the lang spec is settled will be to use a global
InternPool for comptime memoized objects, making this behavior consistent
across all types, not only string literals. Or, we might decide to not
guarantee string literals to have equal comptime pointers, in which case
this commit can be reverted.
2022-05-24 01:01:24 -07:00
Thomas Cheng
64de32b341 Fix segfault in error note 2022-05-23 11:57:30 +03:00
Andrew Kelley
b64a1d5abb
Merge pull request #11684 from ziglang/fix-10318
Set macOS/iPhoneOS/tvOS/watchOS ABI to none (unspecified) by default
2022-05-22 19:29:42 -04:00