17369 Commits

Author SHA1 Message Date
Mitchell Hashimoto
cd32b11eb8
stage2: inferred alloc can use bitcast ty
The comment notes that we can't because of constness, but the recent
work by @Vexu lets us use the bitcast ty cause constness comes later.

The following tests pass from this:

```
test "A" {
    const ary = [_:0]u8{42};
    const ptr: [*:0]const u8 = &ary;
    try expect(ptr[1] == 0);
}

test "B" {
    comptime {
        const ary = [_:0]u8{42};
        const ptr: [*:0]const u8 = &ary;
        try expect(ptr[1] == 0);
    }
}
```
2022-03-08 12:04:51 -08:00
Mitchell Hashimoto
55ccf4c7a8 stage2: elem vals of many pointers need not deref pointers
By the time zirElemVal is reached for a many pointer, a load has already
happened, making sure the operand is already dereferenced.

This makes `mem.sliceTo` now work.
2022-03-08 14:10:43 -05:00
Andrew Kelley
6ffa44554e
Merge pull request #11079 from Vexu/stage2
stage2: make references to const allocs const
2022-03-08 13:49:29 -05:00
Benjamin San Souci
e3c2cc1443
std.json: correctly handle sentinel terminated slices 2022-03-08 20:43:13 +02:00
Evan Haas
4b9fd57aa8
translate-c: use nested scope for comma operator in macros
Fixes #11040
2022-03-08 20:38:51 +02:00
Jonathan Marler
d805adddd6 deprecated TypeInfo in favor of Type
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-03-08 20:38:12 +02:00
Jakub Konka
404f5d6179 x64: pass more behavior/cast.zig tests 2022-03-08 10:56:54 +01:00
joachimschmidt557
3ea603c82a stage2 ARM: implement ptr_add, ptr_sub for all element sizes
Also reduces slice_elem_val to ptr_add, simplifying the implementation
2022-03-08 10:54:08 +01:00
Veikka Tuominen
8f037db885 stage2: correct constness of allocs 2022-03-08 11:23:39 +02:00
Veikka Tuominen
1f4a097117 stage2: fix mem{set,cpy} for non comptime mutable pointers 2022-03-08 11:23:38 +02:00
Jakub Konka
ba17552b4e dwarf: move all dwarf into standalone module
Hook up Elf and MachO linkers to the new solution.
2022-03-08 09:46:27 +01:00
Andrew Kelley
38c161afab Sema: fix @hasDecl for simple enums 2022-03-07 13:54:25 -07:00
Andrew Kelley
c467f6693e stage2: fix union layout returning non-zero for zero-sized tag 2022-03-07 13:36:58 -07:00
Andrew Kelley
f59cbd89e3
Merge pull request #11077 from mitchellh/array-init-ty
stage2: sentinel-terminated array initialization
2022-03-07 13:54:09 -05:00
Mitchell Hashimoto
85b0a4a8fd
stage2: new zir array_init_sent for sentinel-terminated array inits
This uses a new ZIR inst `array_init_sent` (and a ref equivalent) to
represent array init expressions that terminate in a a sentinel value.

The sentienl value is the last value in the `MultiOp` payload. This
makes it a bit more awkward to deal with (lots of "len - 1") but makes
it so that the payload matches the fact that sentinels appear at the end
of arrays. However, this is not a hill I want to die on so if we want to
change it to index 0, I'm happy to do so.

This makes the following work properly:

    try expect(@TypeOf([_:0]u8{}) == [0:0]u8);
2022-03-07 08:26:00 -08:00
Mitchell Hashimoto
c9fac41368
stage2: resolve array type for typed array init expressions
Array types with sentinels were not being typed correctly in the
translation from ZIR to Sema (comptime). This modifies the `array_init`
ZIR to also retain the type of the init expression (note: untyped array
initialization is done via the `array_init_anon` ZIR and so is unchanged
in this commit).
2022-03-07 07:30:30 -08:00
Andrew Kelley
8c32d989c9
Merge pull request #11054 from schmee/mul-add
Implement `@mulAdd` for scalar floats
2022-03-07 04:00:45 -05:00
Andrew Kelley
6547da8f97 Sema: handle peer type resolution of optional slices 2022-03-06 21:29:07 -07:00
Andrew Kelley
76d810c568 std: disable flaky os.fcntl test
See tracking issue #11074
2022-03-06 20:49:49 -07:00
Andrew Kelley
e74382b602 ci: azure: update to newest LTS ubuntu 2022-03-06 20:03:57 -07:00
Andrew Kelley
3c1ebf9556 compiler_rt: avoid redundant exports when testing 2022-03-06 19:58:01 -07:00
Andrew Kelley
4c17b93f0a compiler_rt: additional powerpc-specific alias
Apparently LLVM lowers f128 fma to `fmaf128` instead of `fmal`.
2022-03-06 16:34:44 -07:00
Andrew Kelley
488eb8ac29 disable failing @mulAdd test 2022-03-06 16:18:51 -07:00
Andrew Kelley
c52d437224 stage1: improved implementation of target_long_double_is_f128 2022-03-06 16:11:39 -07:00
Andrew Kelley
c68d9773df compiler-rt: make __fmax and fmaq aliases of fmal
on targets where that is the case.
2022-03-06 16:11:39 -07:00
Andrew Kelley
71b8760d3b stage2: rework @mulAdd
* mul_add AIR instruction: use `pl_op` instead of `ty_pl`. The type is
   always the same as the operand; no need to waste bytes redundantly
   storing the type.
 * AstGen: use coerced_ty for all the operands except for one which we
   use to communicate the type.
 * Sema: use the correct source location for requireRuntimeBlock in
   handling of `@mulAdd`.
 * native backends: handle liveness even for the functions that are
   TODO.
 * C backend: implement `@mulAdd`. It lowers to libc calls.
 * LLVM backend: make `@mulAdd` handle all float types.
   - improved fptrunc and fpext to handle f80 with compiler-rt calls.
 * Value.mulAdd: handle all float types and use the `@mulAdd` builtin.
 * behavior tests: revert the changes to testing `@mulAdd`. These
   changes broke the test coverage, making it only tested at
   compile-time.

Improved f80 support:
 * std.math.fma handles f80
 * move fma functions from freestanding libc to compiler-rt
   - add __fmax and fmal
   - make __fmax and fmaq only exported when they don't alias fmal.
   - make their linkage weak just like the rest of compiler-rt symbols.
 * removed `longDoubleIsF128` and replaced it with `longDoubleIs` which
   takes a type as a parameter. The implementation is now more accurate
   and handles more targets. Similarly, in stage2 the function
   CTypes.sizeInBits is more accurate for long double for more targets.
2022-03-06 16:11:39 -07:00
John Schmidt
6637335981 stage2: implement @mulAdd for scalar floats 2022-03-06 15:36:56 -07:00
Luuk de Gram
c7e4c711fc wasm: Fix incremental compilation
- atoms may have relocations, so freeing them when we update the parent
atom will cause segfaults.
- Not all declarations will live in symbol_atom
2022-03-06 23:33:50 +01:00
Jakub Konka
27c084065a
Merge pull request #11070 from Luukdegram/wasm-unify
stage2: wasm - unify codegen with other backends
2022-03-06 20:44:51 +01:00
Andrew Kelley
9154a86069
Merge pull request #11065 from hexops/sg/responsefiles-2
Do not fail to build if 'zig build-lib' etc. arguments exceed OS limits (take 2)
2022-03-06 14:35:52 -05:00
Andrew Kelley
e535521619 CI: additionally test wasm32-wasi with LLVM backend 2022-03-06 12:25:33 -07:00
Luuk de Gram
6d84f22fa0 stage2: Fix wasm linker for llvm backend
This fixes 2 entrypoints within the self-hosted wasm linker that would be called
for the llvm backend, whereas we should simply call into the llvm backend to perform such action.
i.e. not allocate a decl index when we have an llvm object, and when flushing a module,
we should be calling it on llvm's object, rather than have the wasm linker perform the operation.

Also, this fixes the wasm intrinsics for wasm.memory.size and wasm.memory.grow.
Lastly, this commit ensures that when an extern function is being resolved, we tell LLVM how
to import such function.
2022-03-06 14:17:36 -05:00
Daniele Cocca
716abe3389 CBE: mark more tests as passing 2022-03-06 14:15:57 -05:00
Luuk de Gram
13fca53b92
wasm: Unify function generation
Like decl code generation, also unify the wasm backend and the wasm linker to call into
the general purpose `codegen.zig` to generate the code for a function.
2022-03-06 19:38:53 +01:00
Luuk de Gram
2faba4092a
wasm: Remove old DeclGen/genTypedValue 2022-03-06 19:38:53 +01:00
Luuk de Gram
70fc6e3776
wasm: call into generateSymbol when lowering
This also unifies the wasm backend to use `generateSymbol` when lowering a constant
that cannot be lowered to an immediate value.
As both decls and constants are now refactored, the old `genTypedValue` is removed.
2022-03-06 19:38:53 +01:00
Luuk de Gram
5a45fe2dba
wasm: Call generateSymbol for updateDecl
To unify the wasm backend with the other backends, we will now call `generateSymbol` to
lower a Decl into bytes. This means we also have to change some function signatures
to comply with the linker interface.

Since the general purpose generateSymbol is less featureful than wasm's, some tests are
temporarily disabled.
2022-03-06 19:38:50 +01:00
Jakub Konka
12e636c24e
Merge pull request #11068 from Luukdegram/codegen-fixes
stage2: Fix codegen for unions and error unions
2022-03-06 19:37:43 +01:00
Jakub Konka
e4039cecc7 x64: fix (un)wrapping error unions + refactor 2022-03-06 19:02:02 +01:00
Luuk de Gram
23e2368ac3
stage2: Fix codegen for unions and error unions
When an union had a zero-sized payload type, we would lower the tag twice. This is fixed
by exiting early when `payload_size` is 0.

With regards to error unions, we were only accounting for padding for the payload field.
However, the errorset value can have a smaller alignment than the payload as well, i.e. error!usize.
We fix this by also accounting for padding/alignment of the error set tag of an error union.
2022-03-06 16:04:15 +01:00
Mitchell Hashimoto
bf972e44d5 stage2: coerce [*:0]u8 to other valid pointer types
This makes the following work properly (as it does in stage1, too):

  var zero_ptr: [*:0]const u8 = undefined;
  var no_zero_ptr: [*]const u8 = zero_ptr;

Prior to this this would fail with an "expected type" error since
coercion failed.
2022-03-06 10:38:53 +02:00
The Depressed Milkman
cd43f323d2 correct @frameSize() params in documentation
The documentation omitted the primary parameter, making it difficult to
understand what this function actually does.
2022-03-06 10:32:07 +02:00
Stephen Gutekanst
c3a2b51a2c fix regression in zig run runtime arguments
This brings back #10950, which was reverted in 5ab5e2e6731a9f1198df6c53134545ccc6a6bbd3
because it [introduced a regression in `zig run`](https://github.com/ziglang/zig/pull/10950#issuecomment-1049481212)
where the runtime arguments passed were incorrect.

I've fixed the issue, and notably this was the only location where we
directly relied on accessing arguments by index in this code still (all
other locations use the iterator proper) and so we should be all good to
go now.

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2022-03-05 16:27:29 -07:00
Stephen Gutekanst
cfb4f48941 Revert "Revert "Merge pull request #10950 from hexops/sg/responsefiles""
This reverts commit 5ab5e2e6731a9f1198df6c53134545ccc6a6bbd3.
2022-03-05 16:04:21 -07:00
Jakub Konka
72992b6513
Merge pull request #11062 from ziglang/dwarf-more-types 2022-03-05 23:07:36 +01:00
Jakub Konka
908f41a67c
Merge pull request #11021 from topolarity/wasi-cwd
stdlib: Add emulated CWD to std.os for WASI targets
2022-03-05 20:31:44 +01:00
Jakub Konka
1252bdd4d6 elf: add debug info for non-ptr optionals 2022-03-05 20:18:18 +01:00
Jakub Konka
9a027d9ee3 macho: fix incorrect line and pc advancement 2022-03-05 17:55:01 +01:00
Jakub Konka
0a9088bd06 macho: remove anon_struct_type which is now redundant 2022-03-05 17:55:01 +01:00
Jakub Konka
2be003a3b3 macho: write NOPs as padding for machine code section 2022-03-05 17:55:01 +01:00