17798 Commits

Author SHA1 Message Date
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
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
leesongun
7ae22813ee
stage1: implement casting from u0 2022-03-27 11:49:54 +03:00
matu3ba
dbbda0f41a
std.testing: add methods tmpDirPath, getTestArgs, buildExe
continuation of #11093 to simplify testing IPC

* use cases
  - get path to temporary directory
  - get the test arguments inside test block for reusage
  - build executables from text within test blocks, ie to test IPC
* missing conventions
  - how to name and debug test cases
  - where do simple+repititve build commands for testing belong
2022-03-27 11:43:40 +03:00
Veikka Tuominen
f9a2c0fc6c
Merge pull request #10871 from schmee/stage2-bitcast-safety
stage2: add type checking for @bitCast
2022-03-27 11:31:30 +03:00
tecanec
3beef3945c
std: SIMD utility functions
This file contains a collections of functions that may be useful for SIMD, such as generating a vector with a linear range of numbers starting at zero, joining two vectors together, getting the index of the first true in a vector of bools, etc.
2022-03-27 11:28:44 +03:00
Yorhel
a3030221c3 std.fs: Handle EINVAL from linux.getdents64
Fixes #11178
2022-03-27 11:24:31 +03:00
jagt
29c32b3dc5 Namespace.decls use context to save memory
change `Module.Namespace.decls` from `AutoArrayHashMapUnmanaged` to
`ArrayHashMapUnmanaged(*Decl, void)` with custom context to eliminate
duplicated decl name strings.

Also see:
https://zig.news/andrewrk/how-to-use-hash-map-contexts-to-save-memory-when-doing-a-string-table-3l33
2022-03-27 11:23:11 +03:00
Veikka Tuominen
23507f20b9
Merge pull request #11315 from wsengir/stage2-simplify-muladd
stage2: simplify mul_add
2022-03-27 11:12:42 +03:00
William Sengir
adc2824fa4
stage2: simplify scalar_ty for mul_add in LLVM backend 2022-03-26 16:29:48 -07:00
William Sengir
6a48345649
Sema: remove redundant mul_add comptime vectorization
Moving comptime vectorization into `Value` has proven to simplify and
clean up a lot of code.
2022-03-26 16:29:48 -07:00
Joachim Schmidt
97a53bb8a1
Merge pull request #11311 from joachimschmidt557/builtin-with-overflow
stage2: Change semantics of AIR arithmetic overflow instructions
2022-03-26 22:29:48 +01:00
Luuk de Gram
16e88b75ba wasm: Enable passing tests 2022-03-26 21:20:29 +01:00
Luuk de Gram
97448e4d5f wasm: Only generate import when referenced
Rather than creating an import for externs on updateDecl, we now
generate them when they're referenced. This is required so using @TypeOf(extern_fn())
will not emit the import into the binary (causing an incorrect function type index
as it won't be fully analyzed).
2022-03-26 21:20:29 +01:00
joachimschmidt557
9070ad7774
stage2 LLVM: Adjust to new AIR arithmetic overflow instructions 2022-03-26 17:21:42 +01:00
joachimschmidt557
e2468e3f27
Sema: change zirOverflowArithmetic to use new version of AIR insts
Also applies the change to Liveness
2022-03-26 17:21:42 +01:00
joachimschmidt557
1803167db2
AIR: change signature of overflow arithmetic instructions
add_with_overflow and similar functions now have the ty_pl data
attached. The Payload will now be a binary operation and the inst is
expected to return a tuple consisting of the destination integer type
and an overflow bit (u1).

Co-authored-by: Jan Philipp Hafer <jan.hafer@rwth-aachen.de>
2022-03-26 17:21:39 +01:00
Andrew Kelley
af844931b2 stage2: resolve types more lazily
This avoids unwanted "foo depends on itself" compilation errors.
2022-03-26 00:33:14 -07:00
Andrew Kelley
6ef761307c
Merge pull request #11284 from topolarity/compile-errors-indep-files
Add primitive file support for compile error tests
2022-03-26 00:45:38 -04:00
Andrew Kelley
88e98a0611
Merge pull request #11289 from schmee/stage2-select
stage2: implement `@select`
2022-03-26 00:33:22 -04:00
Andrew Kelley
bae35bdf2d stage2: result location types for function call arguments
* AstGen: restore the param_type ZIR instruction and pass it to the
   expression for function call arguments. This does not solve the
   problem for generic function parameters, but it catches stage2 up to
   stage1 which also does not solve the problem for generic function
   parameters.
   - Most of the enhancements in this commit will still be needed for a
     more sophisticated further improvement to handle generic function
     types.
   - In Sema, handling of `as` coercion recognizes the `var_args_param`
     Type Tag and passes the operand through doing no coercion.
   - That was the last ZIR tag and we are now using all 256 ZIR tags.
 * AstGen: array init and struct init expressions use the anon form even
   when the result location has a type. Prevents the type system
   incorrectly believing, for example, that a tuple is actually an array
   when the result location is a param_type of a function with `anytype`
   parameter.
 * Sema: add missing coercion in `unionInit` to coerce the init to the
   corresponding union field type.
 * `Value.fieldValue` now takes a type and does not take an allocator.

closes #11293

After this commit, stage2 passes all the parser tests.
2022-03-26 00:27:12 -04:00
Andrew Kelley
bcd7eb012a
Merge pull request #11304 from joachimschmidt557/stage2-aarch64
stage2 AArch64: remove MCValue.embedded_in_code
2022-03-25 22:22:47 -04:00
joachimschmidt557
c1098e9036 stage2 x86_64: remove MCValue.embedded_in_code 2022-03-25 22:22:16 -04:00
Andrew Kelley
600c7fe1da
Merge pull request #11299 from Vexu/stage2-build
stage2 fixes on the way to `zig2 build --help` working
2022-03-25 21:35:04 -04:00
John Schmidt
607300a59b sema: simplify @bitCast error messages 2022-03-26 01:07:52 +01:00
John Schmidt
dc5dc3ac59 stage2: add type checking for @bitCast 2022-03-25 23:33:05 +01:00
John Schmidt
a7b3082ba0 Implement type.bitSize for unions 2022-03-25 23:15:37 +01:00
Veikka Tuominen
2f326f24dd Sema: implement zirSwitchCapture multi for unions 2022-03-25 22:32:15 +02:00
Veikka Tuominen
17d214a249 Sema: implement zirStructInit for runtime-known union values 2022-03-25 22:32:15 +02:00
Veikka Tuominen
5ff518fbb9 Sema: implement zirSwitchCapture for error sets 2022-03-25 22:32:14 +02:00
Veikka Tuominen
26dfbf8122 type: fix onePossibleValue for auto numbered enums 2022-03-25 22:32:14 +02:00
Veikka Tuominen
f6bd534fc9 Sema: ensure error_set_merged is sorted 2022-03-25 22:32:14 +02:00
Veikka Tuominen
a4c5ec49f1 Sema: add error for empty switch 2022-03-25 22:30:35 +02:00
Cody Tapscott
0568b45779 Move existing compile errors to independent files
Some cases had to stay behind, either because they required complex case
configuration that we don't support in independent files yet, or because
they have associated comments which we don't want to lose track of.

To make sure I didn't drop any tests in the process, I logged all
obj/test/exe test cases from a run of "zig build test" and compared
before/after this change.

All of the test cases match, with two exceptions:
 - "use of comptime-known undefined function value" was deleted, since
   it was a duplicate
 - "slice sentinel mismatch" was renamed to "vector index out of
   bounds", since it was incorrectly named
2022-03-25 12:27:46 -07:00
Cody Tapscott
1de63ad793 zig fmt: Add --exclude argument to skip dir/file
This change adds a "--exclude" parameter to zig format, which can be
used to make sure that it does not process certain files or folders
when recursively walking a directory.

To do this, we simply piggy-back on the existing "seen" logic in zig
fmt and mark these files/folders as seen before processing begins.
2022-03-25 12:27:46 -07:00
Cody Tapscott
7f64f7c925 Add rudimentary compile error test file support
This brings two quality-of-life improvements for folks working on
compile error test cases:
 - test cases can be added/changed without re-building Zig
 - wrapping the source in a multi-line string literal is not necessary

I decided to keep things as simple as possible for this initial
implementation. The test "manifest" is a contiguous comment block at the
end of the test file:
1. The first line is the test case name
2. The second line is a blank comment
2. The following lines are expected errors

Here's an example:
```zig
const U = union(enum(u2)) {
    A: u8,
    B: u8,
    C: u8,
    D: u8,
    E: u8,
};
export fn entry() void {
    _ = U{ .E = 1 };
}

// union with too small explicit unsigned tag type
//
// tmp.zig:1:22: error: specified integer tag type cannot represent every field
// tmp.zig:1:22: note: type u2 cannot fit values in range 0...4
```

The mode of the test (obj/exe/test), as well as the target
(stage1/stage2) is determined based on the directory containing the
test.

We'll probably eventually want to support embedding this information
in the test files themselves, similar to the arocc test runner, but
that enhancement can be tackled later.
2022-03-25 12:25:43 -07:00
joachimschmidt557
f7da4b9bc8
stage2 AArch64: change semantics of MCValue.stack_offset
Mirrors the changes performed to stack_offset in the ARM backend
2022-03-25 19:21:34 +01:00
joachimschmidt557
16e4966332
stage2 AArch64: remove MCValue.embedded_in_code 2022-03-25 19:21:34 +01:00
joachimschmidt557
061d6699c0
stage2 AArch64: lower cmp to binOp 2022-03-25 19:21:34 +01:00
John Schmidt
cd46daf7d0 sema: coerce inputs to vectors in zirSelect 2022-03-25 19:14:11 +01:00
John Schmidt
f47db0a0db sema: use pl_op for @select 2022-03-25 16:13:54 +01:00
John Schmidt
12d5efcbe6 stage2: implement @select 2022-03-25 16:13:54 +01:00
Jakub Konka
1c33ea2c35 dwarf: add debug info for unions 2022-03-25 13:53:40 +01:00
Evan Haas
0d5d353197 translate-c: Use @Vector for vector expressions
Removes translate-c usage of std.meta.Vector, which was deprecated in d42d31f72f
2022-03-25 14:47:51 +02:00
dxps
9a127501f6 chore: doc fixes, closes 11091 2022-03-25 11:22:30 +02:00
Andrew Kelley
7f91be9c80 AstGen: emit break_inline from inline while loop 2022-03-24 22:45:10 -07:00
Andrew Kelley
bcf2eb1a00 Sema: fix closure capture typeof runtime-known parameter
Closures are not necessarily constant values. For example, Zig
code might do something like this:

    fn foo(x: anytype) void {
        const S = struct {field: @TypeOf(x)};
    }

...in which case the closure_capture instruction has access to a
runtime value only. In such case we preserve the type and use a
dummy runtime value.

closes #11292
2022-03-24 21:47:18 -07:00
Andrew Kelley
b802a67562 std.MultiArrayList: check size of element, not pointer
Ever since a semi-recent language specification update, pointers to
zero-sized types still have runtime bits.
2022-03-24 19:55:12 -07:00