Commit Graph

17844 Commits

Author SHA1 Message Date
Andrew Kelley
05947ea870 stage2: implement @intToError with safety
This commit introduces a new AIR instruction `cmp_lt_errors_len`. It's
specific to this use case for two reasons:

 * The total number of errors is not stable during semantic analysis; it
   can only be reliably checked when flush() is called. So the backend
   that is lowering the instruction must emit a relocation of some kind
   and then populate it during flush().
 * The fewer AIR instructions in memory, the better for compiler
   performance, so we squish complex meanings into AIR tags without
   hesitation.

The instruction is implemented only in the LLVM backend so far. It does
this by creating a simple function which is gutted and re-populated
with each flush().

AstGen now uses ResultLoc.coerced_ty for `@intToError` and Sema does the
coercion.
2022-03-29 22:19:06 -07:00
Andrew Kelley
83617eac59 std: avoid referencing event loop when io_mode is blocking
This prevents unwanted symbols from ending up in the output binary.
2022-03-29 22:16:43 -07:00
Andrew Kelley
9821a0c6f0 Sema: fix generic instantiations of return types with nested captures
* In semaStructFields and semaUnionFields we return error.GenericPoison
   if one of the field types ends up being generic poison.
   - This requires handling function calls and function types taking
     this into account when calling `typeRequiresComptime` on the return
     type.
 * Unrelated: I noticed using Valgrind that struct reification did not
   populate the `known_opv` field. After fixing it, the behavior tests
   run Valgrind-clean.
 * ZIR: use `@ptrCast` to cast between slices instead of exploiting
   the fact that stage1 incorrectly allows `@bitCast` between slices.
   - A future enhancement will make Zig support `@ptrCast` to directly
     cast between slices.
2022-03-29 20:11:48 -07:00
Andrew Kelley
e39c86399d link: half-hearted bug fix for decl_state field
The init()/commit() API of this field leads to the type of bug that this
commit fixes by defering an uncomfortably complex expression. I didn't
bother doing the equivalent fix in link/MachO.zig because instead I
think the `decl_state` field should be entirely removed from Dwarf.
2022-03-29 20:08:28 -07:00
Andrew Kelley
b59428e9f7 Sema: adjust coercion of undefined error union payload
To no longer set the error code to undefined. This fixes the problem
where an undefined single-item pointer coerced to an error union of a
slice set the whole thing to undefined even though the sub-coercion to
the slice would have produced a defined value.
2022-03-29 16:56:12 -07:00
Andrew Kelley
12e1304805 test harness: fix not honoring one_test_case_per_file
I regressed this in 9aa431cba3.

thanks @topolarity for pointing out the issue
2022-03-29 12:20:10 -07:00
Andrew Kelley
9aa431cba3 test harness: include case names for compile errors
in the progress nodes
2022-03-29 12:01:45 -07:00
Daniele Cocca
8238d4b335 CBE: fix C output after PR #11302, reenable tests
Commit 052079c994 surfaced two issues with
the generated C code:

  - renderInt128() contained a seemingly unnecessary assertion to verify
    that the high 64 bits of the number were nonzero, dating back to
    9bf1681990. I removed it.
  - renderValue() didn't have any special handling for undefined structs,
    falling back to printing "{}" which generated invalid expressions
    such as "return {}" for functions returning structs, whereas
    "return (S){}" is the correct form. I changed it accordingly.

At the same time I'm reenabling the relevant tests.
2022-03-29 02:28:20 -04:00
Andrew Kelley
8df84cce8b Sema: queue full type resolution of builtin types 2022-03-28 18:49:49 -07:00
Andrew Kelley
4dd65316b7 AstGen: coerce break operands of labeled blocks
Similar code was already in place for conditional branches. This updates
AstGen to do the same for labeled blocks. It takes advantage of the
`store_to_block_ptr` instructions by mutating them in place to become
`as` instructions, coercing the break operands before they are returned
from the block.
2022-03-28 18:28:08 -07:00
Andrew Kelley
857743473c Merge @schmee's union debug info branch 2022-03-28 16:43:24 -07:00
Andrew Kelley
f4a357d720 stage2: finish debug info for unions in the LLVM backend
Sema:

 * queue full resolution of std.builtin.Type.Error when doing `@typeInfo`
   for error sets.

LLVM backend:

 * change a TODO comment to a proper explanation of why debug info
   for structs is left as a fwd decl sometimes.
 * remove handling of packed unions which does not match the type
   information or constant generation code.
 * remove copy+pasted code
 * fix union debug info not matching the memory layout
 * remove unnecessary error checks and type casting
2022-03-28 16:27:45 -07:00
John Schmidt
c546608fca stage2: LLVM: (WIP) add union fields debug info 2022-03-28 16:24:51 -07:00
Andrew Kelley
b6ccde47ad Sema: allow mixing array and vector operands
* Added peer type resolution for arrays and vectors: the vector type is
   selected.
 * Fixed passing the lhs type or rhs type instead of the peer resolved
   type when calling Value methods during analyzeArithmetic handling of
   comptime expressions.
 * `checkVectorizableBinaryOperands` now allows mixing vectors and
   arrays, as long as one of the operands is a vector.

This matches stage1's handling of `^=` but apparently stage1 is
inconsistent and does not handle e.g. `*=`. stage2 now will always allow
mixing vector and array operands for all operations.
2022-03-28 14:17:05 -07:00
Veikka Tuominen
691c7cb3cd std.build: fix functions returning address of by value parameter 2022-03-28 13:06:11 -07:00
Veikka Tuominen
c517e65d8f Sema: implement coerceInMemoryAllowed for optionals 2022-03-28 13:05:40 -07:00
Veikka Tuominen
5515b81f8c Sema: use the correct integer
Sure would be nice if these two incompatible indexes had distinct types.
2022-03-28 13:05:21 -07:00
Veikka Tuominen
a415fe0bc0 AstGen: clear rl_ty_inst in setBreakResultLoc if one is not provided 2022-03-28 13:05:08 -07:00
Veikka Tuominen
3c4ac47e00 stage2 llvm: fix union init of byRef values 2022-03-28 13:04:50 -07:00
Andrew Kelley
7e47f106cc Value.hashPtr: handle lazy_align as an integer
Although lazy_align is a different tag than integer values, it needs to
be hashed and equality-tested as if it were a simple integer. Otherwise
our basic data structure guarantees fall apart.
2022-03-28 12:05:08 -07:00
Jakub Konka
c38b4bcee7
Merge pull request #11334 from ziglang/stage2-x64-overflow
x64: implement add, sub and mul with overflow
2022-03-28 20:58:18 +02:00
Jakub Konka
e6729036e4 x64: partially fix genImul, enable overflow tests 2022-03-28 17:45:50 +02:00
Jakub Konka
107052aded x64: implement add, sub and mul with overflow 2022-03-28 16:37:35 +02:00
ominitay
25d4c5df70
std.mem.zeroInit: Fix behaviour with empty initialiser 2022-03-28 14:10:36 +03:00
Veikka Tuominen
460e7a2445
Merge pull request #11319 from Vexu/stage2-arg-count
stage2: check arg count before types
2022-03-28 13:05:40 +03:00
Jakub Konka
b8cd56dc94
Merge pull request #11300 from ziglang/stage2-debug-error-sets 2022-03-28 07:40:33 +02:00
Andrew Kelley
7be340e3cc std.crypto.blake3: use @Vector instead of std.meta.Vector 2022-03-27 14:53:40 -07:00
Andrew Kelley
3fc0e0c57b Sema: implement @setFloatMode
We are putting off actual optimization of floats because we have a
couple proposals being considered which would change how it works.

In the meantime, lowering optimized float mode to be the same as
strict is a perfectly legal way to implement the Zig language specification.
2022-03-27 14:52:12 -07:00
Andrew Kelley
c8f8440271 stage1: disable failing test
The new behavior test introduced in the previous commit is not passing
for stage1 on mips.
2022-03-27 14:40:24 -07:00
Andrew Kelley
6d2ec7a4e3 LLVM: handle aggregate_init for packed structs 2022-03-27 14:22:47 -07:00
Veikka Tuominen
d5e89dd70b stage2: add temporary workaround for lack of argument count check 2022-03-27 22:57:43 +03:00
Veikka Tuominen
7217148edf Value: hash lazy_align 2022-03-27 22:38:37 +03:00
Andrew Kelley
052079c994
Merge pull request #11302 from mitchellh/slice-null-cptr
stage2: runtime safety checks for slicing a null C pointer and @intCast truncating bits
2022-03-27 15:37:09 -04:00
Andrew Kelley
0501962b4c
Merge pull request #11321 from Luukdegram/wasm-overflow
stage2: wasm - Implement overflow arithmetic
2022-03-27 15:24:39 -04:00
Jakub Konka
366ec21052 dwarf: track type relocation state in Dwarf module 2022-03-27 20:53:06 +02:00
Jakub Konka
4ca9b4c44a dwarf: move DbgInfoTypeRelocsTable into Dwarf module 2022-03-27 20:53:06 +02:00
Jakub Konka
1a80315836 dwarf: rename DebugInfoAtom into Atom; free all allocated memory 2022-03-27 20:53:06 +02:00
Jakub Konka
b4815b3131 dwarf: draft poc of deferred resolution of error sets debug info 2022-03-27 20:53:06 +02:00
Jakub Konka
e444e69dc4 dwarf: do not use Type.errorSetNames() for inferred error sets
Otherwise, we risk tripping an assertion in `Type.errorSetNames()`
in case the inferred error set was not yet fully resolved. This so
far only surfaced when Dwarf triggers recursive analysis of an
error set as part of emitting debug info for an error union.
2022-03-27 20:53:06 +02:00
Jakub Konka
4985abcc49 dwarf: add debug info for error unions 2022-03-27 20:53:06 +02:00
Jakub Konka
a1040a105a dwarf: add debug info for error sets 2022-03-27 20:53:06 +02:00
Veikka Tuominen
bda7993beb Sema: fix error set memory unsafety
All error names are supposed to be owned by Module.
2022-03-27 20:31:54 +03:00
Luuk de Gram
e1bb09648f
wasm: Enable overflow behavior tests 2022-03-27 19:02:45 +02:00
Luuk de Gram
3114faddd8
wasm: Implement overflow arithmetic
This implements the overflow arithmetic for unsigned and signed integers.
Meaning the following instructions:
- @addWithOverflow
- @subWithOverflow
- @shlWithOverflow
- @mulWithOverflow
2022-03-27 19:00:49 +02:00
Mitchell Hashimoto
3c91818438
stage2: runtime safety check intCast signedness 2022-03-27 09:20:37 -07:00
Mitchell Hashimoto
4ad98d0714
stage2: runtime safety check intCast to u0 must fit 2022-03-27 09:20:37 -07:00
Mitchell Hashimoto
8fbac2e86d
stage2: runtime safety check integer cast truncating bits 2022-03-27 09:20:37 -07:00
Mitchell Hashimoto
01698528d1
stage2: safety checks for slicing a null C pointer 2022-03-27 09:20:35 -07:00
Jakub Konka
d15bbebe2e macho: do not create dSYM bundle for stage2 LLVM backend
Instead, we fallback to the old-fashioned stabs-based mechanism
until I add the missing mechanism for extracting and relocating
DWARF from relocatable object files and writing it into a dSYM
bundle.
2022-03-27 13:20:13 +02:00
BlueAlmost
406507c6dc
std.math.Complex: add 'negation' and 'mulitply by i' 2022-03-27 11:54:43 +03:00