65 Commits

Author SHA1 Message Date
Veikka Tuominen
b316c25cc6
Merge pull request #13075 from Vexu/stage2-fixes
Stage2 misc fixes
2022-10-10 23:27:17 +02:00
Veikka Tuominen
4a6cc1c602 Sema: allow equality comparisons between error unions and error sets
Closes #1302
2022-10-07 11:04:02 +03:00
Veikka Tuominen
0b1dd845d9 stage2: add error for non-void error union payload being ignored
See https://github.com/ziglang/zig/pull/6060#discussion_r471032912
2022-10-06 15:39:06 +03:00
Koakuma
2263bba6cd stage2: sparc64: Skip Sema-failing tests for now 2022-09-14 16:57:31 -07:00
joachimschmidt557
261fec8036
stage2 ARM: amend implementation of various AIR instructions
- unwrap_errunion_err for registers
- unwrap_errunion_payload for registers
- ptr_slice_len_ptr for all MCValues
- ptr_slice_ptr_ptr for all MCValues
2022-09-09 19:17:17 +02:00
Andrew Kelley
d2ad8afff4 LLVM: fix missing alignment on wrapping instructions
Previously, when lowering AIR instructions `wrap_errunion_payload`,
`wrap_errunion_err`, and `wrap_optional`, the LLVM backend would create
an alloca instruction to store the result, but did not set the alignment
on it. This caused UB which went undetected for a long time until we
started enabling the stack protector.

Closes #12594
Unblocks #12508
Inspires #12634

Tests passed locally:
 * test-behavior
 * test-cases
2022-08-25 16:15:48 -07:00
Veikka Tuominen
b55a5007fa Sema: fix parameter of type 'T' must be comptime error
Closes #12519
Closes #12505
2022-08-22 11:16:36 +03:00
Veikka Tuominen
b0a55e1b3b Sema: make noreturn error union behave correctly 2022-08-17 20:10:18 +03:00
Veikka Tuominen
03b1fbe50d stage2: fix airIsErr when is_ptr == true 2022-07-22 21:07:55 +03:00
Andrew Kelley
c3ae909e93 Revert "AstGen: preserve inferred ptr result loc for breaks"
This reverts commit 8bf3e1f8d0902abd4133e2729b3625c25011c3ff, which
introduced miscompilations for peer expressions any time they needed
coercions to runtime types.

I opened #11957 as a proposal to accomplish the goal of the reverted
commit.

Closes #11898
2022-06-28 18:38:25 -07:00
joachimschmidt557
960c142060 stage2 ARM: implement basic intCast and error union wrapping 2022-06-25 21:16:51 +02:00
Veikka Tuominen
0333ff4476 stage2: make error{} the same size as anyerror
Having `error{}` be a zero bit type causes issues when it interracts
with empty inferred error sets which are the same size as `anyerror`.
2022-06-11 23:49:33 +03:00
Veikka Tuominen
e4c0b848a4 Sema: allow simple else body even when all errors handled 2022-06-07 21:27:06 +03:00
Veikka Tuominen
d5e3d5d74c Sema: make analyzeIsNonErr even lazier for inferred error sets 2022-06-07 21:27:06 +03:00
joachimschmidt557
ddd5b57045 stage2 AArch64: complete genTypedValue 2022-05-27 16:43:11 -04: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
8c49420928 aarch64: update for new error union layout 2022-05-24 15:34:52 -07:00
Jakub Konka
c043d57cab x64,arm,aarch64: omit unsupported tests for now 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
Luuk de Gram
3a059ebe4c wasm: Fixes for error union semantics 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
50a5ddecc5
Merge pull request #11635 from wsengir/stage2-errsetcast-safety
stage2: `@errSetCast` safety
2022-05-18 16:35:37 -04:00
Luuk de Gram
e252f92b99 wasm: enable 128bit integer behavior tests 2022-05-18 07:43:33 +02:00
William Sengir
77d732a85f
aarch64,arm: disable broken @errSetCast test 2022-05-11 03:47:03 -07:00
Veikka Tuominen
83bb98e13b stage2 llvm: properly align error union payload 2022-04-02 19:31:32 -04:00
Andrew Kelley
c21f046a8b Sema: enhance is_non_err to be comptime more often
* Sema: store the precomputed monomorphed_funcs hash inside Module.Fn.
   This is important because it may be accessed when resizing monomorphed_funcs
   while this Fn has already been added to the set, but does not have the
   owner_decl, comptime_args, or other fields populated yet.
 * Sema: in `analyzeIsNonErr`, take advantage of the AIR tag being
   `wrap_errunion_payload` to infer that `is_non_err` is comptime true
   without performing any error set resolution.
   - Also add some code to check for empty inferred error sets in this
     function. If necessary we do resolve the inferred error set.
 * Sema: queue full type resolution of payload type when
   `wrap_errunion_payload` AIR instruction is emitted. This ensures the
   backend may check the alignment of it.
 * Sema: resolveTypeFully now additionally resolves comptime-only
   status.

closes #11306
2022-03-30 00:47:55 -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
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
Daniele Cocca
8f9c3fd3df
CBE: enable more passing tests (#11258) 2022-03-22 23:24:36 -04:00
Daniele Cocca
00ed8d9c50 CBE: enable more tests that are currently passing 2022-03-17 11:39:56 -07:00
Veikka Tuominen
a3cfb15fb4 Sema: always allow coercing error set to current inferred error set 2022-03-12 11:36:05 +02:00
Veikka Tuominen
98a01f99c9 Sema: fix typo in resolvePeerTypes 2022-03-12 11:14:17 +02: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
fca51c81bc stage2: is_non_error always returns comptime true for empty error set 2022-03-11 17:16:34 -05:00
Andrew Kelley
9f163310f2 stage2: improve Type.eql and Type.hash for error sets
* Reduce branching in Type.eql and Type.hash for error sets.
 * `Type.eql` uses element-wise bytes comparison since it can rely on
   the error sets being pre-sorted.
 * Avoid unnecessarily skipping tests that are passing.
2022-03-10 14:21:37 -07:00
Mitchell Hashimoto
569870ca41 stage2: error_set_merged type equality
This implements type equality for error sets. This is done
through element-wise error set comparison.

Inferred error sets are always distinct types and other error sets are
always sorted. See #11022.
2022-03-10 14:20:16 -07:00
Luuk de Gram
90f08a69aa wasm: Enable passing behavior tests
This also adds some float-related instructions to MIR/Emit
2022-03-09 13:53:20 -07: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
joachimschmidt557
d486a7b811 stage2 ARM: generate less no-op branches
The checks detecting such no-op branches (essentially instructions
that branch to the instruction immediately following the branch) were
tightened to catch more of these occurrences.
2022-03-04 23:28:14 +01:00
Mitchell Hashimoto
ac7028f559
stage2: implement @errSetCast (#11039) 2022-03-02 22:01:55 -05:00
Jakub Konka
ec54ceee6d
Merge pull request #11016 from ziglang/x64-more-codegen 2022-03-01 09:14:23 +01:00
Andrew Kelley
4763fd1a41 Sema: clean up peer resolution of errors
* Fix compile error for `zirErrorUnionType`.
 * Convert zirMergeErrorSets logic to call `Type.errorSetMerge`.
   It does not need to create a Decl as the TODO comment hinted.
 * Extract out a function called `resolveInferredErrorSetTy`.
 * Rework `resolvePeerTypes` with respect to error unions and
   error sets. This is a less complex implementation that passes all the
   same tests and uses many fewer lines of code by taking advantage of
   the function `coerceInMemoryAllowedErrorSets`.
   - Always merge error sets in the order that makes sense, even when
     that means `@typeInfo` incompatibility with stage1.
 * `Type.errorSetMerge` no longer overallocates.
 * Don't skip passing tests.
2022-02-28 23:15:58 -07:00
Mitchell Hashimoto
ea00e50045 stage2: skip error union test on native 2022-02-28 20:42:13 -07:00
Mitchell Hashimoto
bfada7c514 stage2: implement peer type resolution between error unions 2022-02-28 20:42:13 -07:00
Jakub Konka
12cdb36c5b codegen: fix padding calculation for error unions when lowering
* do not track `rdi` register before `call` inst, but instead freeze
  it from further use, until `call` has been realised
* pass more error union tests
2022-02-28 23:20:05 +01:00
Jakub Konka
05431d7c4a x64: impl unwrap_errunion_payload and unwrap_errunion_err for register 2022-02-28 23:20:05 +01:00
joachimschmidt557
91fbcf7093
stage2 ARM: enable more behavior tests 2022-02-27 21:38:56 +01:00
Mitchell Hashimoto
e999a925fa
stage2: @TypeInfo for error sets (#10998) 2022-02-26 22:59:06 -05:00