Commit Graph

17881 Commits

Author SHA1 Message Date
joachimschmidt557
8c12ad98b8
stage2 ARM: implement mul_with_overflow for ints <= 32 bits 2022-04-01 22:51:18 +02:00
joachimschmidt557
c4778fc029
stage2 ARM: implement mul_with_overflow for ints <= 16 bits 2022-04-01 22:02:56 +02:00
joachimschmidt557
77e70189f4
stage2 ARM: implement shl_with_overflow for ints <= 32 bits 2022-04-01 22:02:56 +02:00
joachimschmidt557
37a8c28802
stage2 ARM: implement add/sub_with_overflow for ints < 32 bits 2022-04-01 22:02:56 +02:00
joachimschmidt557
7285f0557c
stage2 ARM: implement add/sub_with_overflow for u32/i32 2022-04-01 22:02:55 +02:00
joachimschmidt557
e2e69803dc
stage2 ARM: change binOp lowering mechanism to use Mir tags
The Air -> Mir correspondence is not 1:1, so this better represents
what Mir insruction we actually want to generate.
2022-04-01 22:02:51 +02:00
Jakub Konka
8b5d5f44e2 macho: set CS_LINKER_SIGNED flag in code signature generated by zld
This way, if the user wants to use `codesign` (or other tool) they
will not be forced to `-f` force signature update. This matches
the behavior promoted by Apple's `ld64` linker.
2022-04-01 14:33:37 +02:00
Jakub Konka
fd29ddc06c x64: implement add/sub with wrapping and xor op 2022-04-01 11:37:18 +02:00
Andrew Kelley
87179d91a7 stage2: hook up Sema to the progress bar 2022-04-01 00:17:02 -07:00
Andrew Kelley
b45c6c757c std.hash_map: workaround for circular dependency
See #11367

It's debatable whether this ends up being a legitimate compile error or
whether the lang spec allows this test case. For now this workaround
seems very reasonable; delaying comptime execution of `verifyContext`
until the struct is instantiated.
2022-04-01 00:17:02 -07:00
Andrew Kelley
26253acf1d AstGen: use block_inline and break_inline consistently
These are more efficiently semantically analyzed. More importantly, if
they don't match, we get a crash in Sema.

Missing places prior to this commit:
 * labeled blocks
 * `break` and `continue` on comptime (not inline) loops
 * `if`, `try`, `orelse`, and `catch` inside comptime scopes
2022-03-31 23:47:34 -07:00
Andrew Kelley
ecd756834b CI: update CLI invokation
243afdcdf5 removed `-Dskip-compile-errors`
and added `-Dskip-stage`.
2022-03-31 16:06:50 -07:00
Andrew Kelley
243afdcdf5 test harness improvements
* `-Dskip-compile-errors` is removed; `-Dskip-stage1` is added.
 * Use `std.testing.allocator` instead of a new instance of GPA.
   - Fix the memory leaks this revealed.
 * Show the file name when it is not parsed correctly such as when the
   manifest is missing.
   - Better error messages when test files are not parsed correctly.
 * Ignore unknown files such as swap files.
 * Move logic from declarative file to the test harness implementation.
 * Move stage1 tests to stage2 tests where appropriate.
2022-03-31 15:10:31 -07:00
Andrew Kelley
df1ba38a88 AstGen: fix treating noreturn instructions as void
Fixes regression introduced in cf4aad4858.
2022-03-31 15:06:12 -07:00
Andrew Kelley
b6133931d0 Sema: fix segfault during resolveInferredErrorSet
There was a simple missing check of adding an inferred error set to
itself, in which case we should not try to mutate the hash map while
iterating over it.
2022-03-31 12:25:48 -07:00
Andrew Kelley
cf4aad4858 AstGen: fix referencing unreferencable instructions
Sema avoids adding map entries for certain instructions such as
`set_eval_branch_quota` and `atomic_store`. This means that result
location semantics in AstGen must not emit any instructions that attempt
to use the result of any of these instructions.

This commit makes AstGen replace such instructions with
`Zir.Inst.Ref.void_value` if their result value ends up being
referenced.

This fixes a compiler crash when running std lib atomic tests.
2022-03-30 23:19:10 -07:00
Meghan Denny
08565b23f9 stage2: fix print_zir for .builtin_src 2022-03-31 02:12:44 -04:00
Veikka Tuominen
75c2cff40e stage2: handle assembly input names 2022-03-31 01:33:28 -04:00
Andrew Kelley
6655c6092e std.base64: upgrade to new function pointer semantics 2022-03-30 20:38:01 -07:00
Andrew Kelley
02d69f5009 Sema: fix usingnamespace decl Value in wrong arena
closes #11297
2022-03-30 17:24:01 -07:00
James Mintram
5d5b1b68fc Remove a std.debug.print from the dwarf.zig file
This was causing freestanding builds to fail due to the
use of `std.debug.print`
2022-03-30 19:35:20 -04:00
Veikka Tuominen
3c64c519e6
Merge pull request #11246 from jmc-88/cbe-asm
CBE: improve support for asm inputs
2022-03-31 00:04:04 +03:00
Andrew Kelley
d227f76afb std.zig.Ast: fix escaped capture of by-value parameters 2022-03-30 11:52:10 -07:00
Andrew Kelley
47dfaf47b8 stage2: test compile errors independently
Until we land some incremental compilation bug fixes, this prevents CI
failures when running the compile errors test cases.
2022-03-30 11:22:27 -07:00
Jakub Konka
f5d9160f1b dwarf: pass DeclState around instead of storing a temp global in Dwarf
Avoids many pitfalls connected with premature/early return in case
there are errors with Decl, etc. This is effectively bringing back
the old design however in a much nicer packaging, where every
mechanism related to tracking Decl's debug info is now nicely
wrapped in a single struct (aka the `DeclState`). This includes
relocation table, type arena, etc. It is now the caller's
responsibility to deinit the state (so that no memory is leaked)
after `Decl` has been analysed (or errored out). The caller here
is typically a linker such as `Elf` or `MachO`.
2022-03-30 14:21:13 -04:00
Meghan
b73cf97c93
replace other uses of std.meta.Vector with @Vector (#11346) 2022-03-30 14:12:14 -04:00
Jakub Konka
b153e156b1
Merge pull request #11342 from ziglang/stage2-x64-mul-div
x64: use all available registers (caller and callee), and fix how we multiply (fixes @mulWithOverflow for byte-size operands)
2022-03-30 11:22:35 +02:00
Daniele Cocca
907dc1e13f CBE: improve support for asm inputs
This is not complete support for asm expressions, but allows a few more
test cases from test/behavior/asm.zig to pass. Since the non-register
inputs are named `input_${n}` they can cause name collisions: I'm
wrapping the asm expressions in their own block to prevent that.

Contextually, this change also makes test/behavior/asm.zig run for
stage2, but skips individual tests for most backends (I only verified
the C and LLVM backends successfully run one new test case) and the
entire test file for aarch64, where it's running into preexisting
shortcomings.
2022-03-30 12:10:02 +03:00
Daniele Cocca
ebafdb958c AstGen: don't coerce inputs to usize in asmExpr
Instead, use ResultLoc.none to allow for the expression type to be
inferred [^1]. This effectively moves the type coercion to Sema, in
order to turn comptime values into usable values for the backends to
consume. Right now the coercion is applies as comptime_int -> usize and
comptime_float -> f64, as an arbitrary choice.

[^1]: 9f25c8140c/src/AstGen.zig (L207-L208)
2022-03-30 11:57:16 +03:00
Daniele Cocca
633fe41a2c Sema: allow comptime blocks for global assembly
An assembly expression in a comptime block is legal Zig in the case of
global assembly [^1]. Instead of unconditionally asserting that the
expression lives in a runtime block, here we assert that if the
expression lives in a comptime block it must be outside of function
scope.

[^1]: https://ziglang.org/documentation/0.9.1/#Global-Assembly
2022-03-30 11:57:15 +03:00
Daniele Cocca
5d5282b5f1 AstGen: support local var references for outputs 2022-03-30 11:57:15 +03: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
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
Jakub Konka
376d0878ec x64: spill .rdi to stack if expecting return value saved on stack
Since .rdi is not part of the callee saved registers, it needs to be
proactively spilled to the stack so that we don't clobber the
return address where to save the return value.
2022-03-30 00:37:42 +02:00
Jakub Konka
d447cd940d x64: track callee and caller saved registers
This is now required to correctly track and spill registers
required for some ops such `mul` or `div` (both required use of
`.rax` and `.rdx` registers).
2022-03-30 00:37:42 +02:00
Jakub Konka
60879bc8ae x64: clean up instruction tracking for div/mul ops 2022-03-30 00:37:42 +02:00
Jakub Konka
ee6e3aef5d x64: redo @mulWithOverflow using rax/rdx based multiplication 2022-03-30 00:37:42 +02:00
Jakub Konka
f9773ab622 x64: clean up abstraction for generating integer division 2022-03-30 00:37:42 +02: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