Commit Graph

17906 Commits

Author SHA1 Message Date
Andrew Kelley
62f54aa39c Sema: in-memory coercion of differently named int types
which have the same number of bits and the same signedness.
2022-04-06 02:39:55 -07:00
Andrew Kelley
9213aa789b stage2: ThreadPool: update to new function pointer semantics 2022-04-05 23:16:35 -07:00
Andrew Kelley
dd9782a8bc Sema: fix handling compile errors during circular dependency error
Previously, Zig would try to generate a function whose type contained
structs or unions which had not been fully resolved due to circular
dependency errors. With this commit, `resolveTypeFully` will be sure to
return `error.AnalysisFail` even in this scenario, leading to proper
display of compilation errors instead of a crash.
2022-04-05 23:16:35 -07:00
Luuk de Gram
ac873367b9 wasm: Use 'select' instruction for max/min
Rather than using blocks and control flow to check which operand is the maximum or minimum,
we use wasm's `select` instruction which returns us the operand based on a result from a comparison.
This saves us the need of control flow, as well as reduce the instruction count from 13 to 7.
2022-04-05 21:56:25 +02:00
Damien Firmenich
5fafcc2b62
zig fmt: remove trailing whitespace on doc comments
Fixes #11353

The renderer treats comments and doc comments differently since doc
comments are parsed into the Ast. This commit adds a check after getting
the text for the doc comment and trims whitespace at the end before
rendering.

The `a = 0,` in the test is here to avoid a ParseError while parsing the
test.
2022-04-05 18:08:33 +03:00
Andrew Kelley
95a87e88fa Sema: forward switch condition to captures 2022-04-04 22:46:05 -07:00
Andrew Kelley
51ef31a833 Sema: add empty tuple to mutable slice coercion 2022-04-04 14:29:08 -07:00
Evan Haas
b4bf3bdf7e std.fmt: Fix incorrect behavior with large floating point integers.
I consider this an interim workaround/hack until #1299 is finished.

There is a bug in the original C implementation of the errol3 (and errol4)
algorithm that can result in undefined behavior or an obviously incorrect
result (leading ':' in the output)

This change checks for those two problems and uses a slower fallback
path if they occur. I can't guarantee that this will always produce
the correct result, but since the workaround is only used if the original
algorithm is guaranteed to fail, it should never turn a previously-correct
result into an incorrect one.

Fixes #11283
2022-04-04 16:04:35 -04:00
Jakub Konka
364e53f3bf dwarf: emit debug info for local variables on x86_64
Add support for emitting debug info for local variables within a subprogram.
This required moving bits responsible for populating the debug info back to
`CodeGen` from `Emit` as we require the operand to be resolved at callsite
plus we need to know its type. Without enforcing this, we could end up
with a `dead` mcv.
2022-04-04 21:46:53 +02:00
Philipp Lühmann
795f075790 langref: rename incorrect expect to assert 2022-04-04 15:44:01 +03:00
ominitay
f654e16d06 std.simd: Fix suggestVectorSizeForCpu 2022-04-04 15:34:27 +03:00
Tom Read Cutting
cdcb34cdf4
Pull elf magic string out to re-used constant 2022-04-04 15:33:24 +03:00
Ryan Liptak
6d04ab6d5b Add std.testing.checkAllAllocationFailures
Adds a function that allows checking for memory leaks (and other problems) by taking advantage of the FailingAllocator and inducing failure at every allocation point within the provided `test_fn` (based on the strategy employed in the Zig parser tests, which can now use this function).
2022-04-04 15:32:43 +03:00
Andrew Kelley
91eb1af917 stage2: more resilient error handling
* If more than one error is reported for the same Decl, the first error
   message is kept and the second one discarded.
 * Prevent functions from being sent to codegen backends if there were
   any errors resolving any of their parameter types or return type.
2022-04-02 19:18:41 -07:00
Andrew Kelley
3432e66faf stage2: remove dependencies on async functions
This commit removes the tiny amount of dependency on async/await that
the self-hosted compiler has so that it can self-host before async/await
language features are working.
2022-04-02 19:18:41 -07:00
Andrew Kelley
843d5adcd6 std.ArrayHashMap: lazier verifyContext calls
Companion commit to b45c6c757c.

Related: #11367
2022-04-02 19:18:41 -07:00
Andrew Kelley
3b32e0be31 behavior tests: disable failing stage1 test
I forgot to check that the new behavior tests also pass in stage1. One
of them does not.

Fixes regression from 4618c41fa6.
2022-04-02 19:02:29 -07:00
Andrew Kelley
4618c41fa6 Sema: mechanism for converting comptime breaks to runtime
closes #11369
2022-04-02 18:30:44 -07:00
Veikka Tuominen
83bb98e13b stage2 llvm: properly align error union payload 2022-04-02 19:31:32 -04:00
Luuk de Gram
a0a587ff85 wasm: Enable passing behavior tests
This shuffles some tests do ensure the new instructions are tested for the wasm backend,
by moving vectors into their own tests as well as move the f16 test cases as those require
special operating also.
2022-04-02 21:54:01 +02:00
Luuk de Gram
2c40b37f79 wasm: Implement @ctz for bitsize <= 64
Implements the `ctz` AIR instruction for integers with bitsize <= 64.
When the bitsize of the integer does not match the bitsize of a wasm type,
we first XOR the value with the value of (1<<bitsize) to set the right bits
and ensure we will only count the trailing zeroes of the integer with the correct bitsize.
2022-04-02 21:54:01 +02:00
Luuk de Gram
bd27fe2bf5 wasm: Implement @clz
Implements the `clz` AIR instruction for integers with bitsize <= 64.
When the bitsize of the integer is not the same as wasm's bitsize,
we substract the difference in bits as those will always be 0 for the integer, but should
not be counted towards the end result. We also wrap the result to ensure it fits
in the result type as documented in the language reference.
2022-04-02 21:54:01 +02:00
Luuk de Gram
5ba03369ee wasm: Implement @mulAdd for f32, f64
This implements the `mul_add` AIR instruction for floats of bitsize 32 and 64.
f16's will require us being able to extend and truncate f16's to correctly
store and load them without losing the accuracy.
2022-04-02 21:54:01 +02:00
Luuk de Gram
219fa192c6 wasm: Implement @maximum & @minimum
This implements the `max` and `min` AIR instructions by checking
whether LHS is great/lesser than RHS. If that's the case, we assign
LHS to the result, otherwise assign RHS to it instead.
2022-04-02 21:54:01 +02:00
Jakub Konka
3ee44ce949
Merge pull request #11373 from joachimschmidt557/stage2-arm
stage2 ARM: implement overflow operations for ints <= 32 bits
2022-04-02 10:52:34 +02:00
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