17327 Commits

Author SHA1 Message Date
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
Jakub Konka
3318400ea3 macho: migrate to named struct for slices 2022-03-05 17:55:01 +01:00
Jakub Konka
eaf08bfb84 macho: handle optional non-ptr types in DWARF 2022-03-05 17:55:01 +01:00
Joachim Schmidt
ac936c0aba
Merge pull request #11059 from joachimschmidt557/stage2-aarch64
stage2 AArch64: various improvements
2022-03-05 14:30:02 +01:00
joachimschmidt557
a06e9eca45
stage2 AArch64: add more slice support
* airSlice
* airArrayToSlice
* and initial support for airSlicePtr and co
2022-03-05 11:31:51 +01:00
Mitchell Hashimoto
e297860158 stage2: test changed behavior of c pointer resolution from stage1
stage1 peer resolves the given test to `[*c]u8` but stage2 makes that a
const u8. I believe stage2 behavior is correct since the pointer itself
is const.
2022-03-05 02:56:24 -05:00
joachimschmidt557
ed7e2938ff
stage2 AArch64: generate less no-op branches
mirroring d486a7b81188ea1e027334c81589157efde2ad23 for aarch64
2022-03-05 08:56:01 +01:00
joachimschmidt557
691ec964ef
stage2 AArch64: implement bitwise binary operations
for integers with bit sizes <= 64
2022-03-05 08:56:01 +01:00
joachimschmidt557
e3121accac
stage2 AArch64: introduce logical immediate instructions 2022-03-05 08:56:01 +01:00
Andrew Kelley
f2a5d0bf94 stage2: fix tuple assigned to variable
Before this we would see ZIR code like this:
```
%69 = alloc_inferred_mut()
%70 = array_base_ptr(%69)
%71 = elem_ptr_imm(%70, 0)
```
This would crash the compiler because it expects to see a
`coerce_result_ptr` instruction after `alloc_inferred_mut`, but that
does not happen in this case because there is no type to coerce the
result pointer to.

In this commit I modified AstGen so that it has similar codegen as when
using a const instead of a var:
```
%69 = alloc_inferred_mut()
%76 = array_init_anon(.{%71, %73, %75})
%77 = store_to_inferred_ptr(%69, %76)
```

This does not obey result locations, meaning if you call a function
inside the initializer, it will end up doing a copy into the LHS.
Solving this problem, or changing the language to make this legal,
will be left for my future self to deal with. Hi future self!
I see you reading this commit log. Hope you're doing OK buddy.

Sema for `store_ptr` of a tuple where the pointer is in fact the same
element type as the operand had an issue where the comptime fields would
get incorrectly lowered to runtime stores to bogus addresses. This is
solved with an exception to the optimization in Sema for storing
pointers that handles tuples element-wise. In the case that we are
storing a tuple to itself, it skips the optimization. This results in
better code and avoids the problem. However this caused a regression in
GeneralPurposeAllocator from the standard library.

I regressed the test runner code back to the simpler path. It's too
hard to debug standard library code in the LLVM backend right now since
we don't have debug info hooked up. Also, we didn't have any behavior
test coverage of whatever was regressed, so let's try to get that
coverage added as a stepping stone to getting the standard library
working.
2022-03-04 18:27:46 -07:00
Andrew Kelley
d3648cc030 zig cc: integrate with -fstack-check, -fno-stack-check 2022-03-04 18:10:37 -07:00
joachimschmidt557
d486a7b811 stage2 ARM: generate less no-op branches
The checks detecting such no-op branches (essentially instructions
that branch to the instruction immediately following the branch) were
tightened to catch more of these occurrences.
2022-03-04 23:28:14 +01:00
Andrew Kelley
7605166426
Merge pull request #11052 from mitchellh/peer-c
stage2: peer resolve *T and [*c]T
2022-03-04 01:16:47 -05:00
Andrew Kelley
63c5c510b1 Sema: rework peer type logic for pointers
Now it's centered around a switch on the chosen type tag which gives us
easy access to pointer data.

The logic is simplied and in some cases logic is removed when it is
sufficient to choose the type that is a better coercion target without
knowing whether such coercion will succeed ahead of time.

A bug is fixed at the bottom of the function; we were doing the opposite
of what we were supposed to with `seen_const`.

Also the bottom of the function has a more complete handling of the
possible combinations of `any_are_null`, `convert_to_slice`, and
`err_set_ty`.

In the behavior tests, not as many backends needed to be skipped.
2022-03-03 23:12:18 -07:00
Mitchell Hashimoto
26be5bb8b1 stage2: peer resolve *T to [*c]T 2022-03-03 21:33:18 -07:00
Andrew Kelley
c9ee3c1e47
Merge pull request #11048 from Luukdegram/wasm-builtins
stage2: Implement wasm builtins
2022-03-03 20:39:10 -05:00
Andrew Kelley
e532b0c0b5 stage2: cleanups to wasm memory intrinsics
* AIR: use pl_op instead of ty_pl for wasm_memory_size. No need to
   store the type because the type is always `u32`.
 * AstGen: use coerced_ty for `@wasmMemorySize` and `@wasmMemoryGrow`
   and do the coercions in Sema.
 * Sema: use more accurate source locations for errors.
 * Provide more information in the compiler error message.
 * Codegen: use liveness data to avoid lowering unused
   `@wasmMemorySize`.
 * LLVM backend: add implementation
   - I wasn't able to test it because we are hitting a linker error for
     `-target wasm32-wasi -fLLVM`.
 * C backend: use `zig_unimplemented()` instead of silently doing wrong
   behavior for these builtins.
 * behavior tests: branch only on stage2_arch for inclusion of the
   wasm.zig file. We would change it to `builtin.cpu.arch` but that is
   causing a compiler crash on some backends.
2022-03-03 18:31:55 -07:00
Luuk de Gram
7fd32de018 cbe: Implement wasm builtins
This implements the wasm builtins by lowering to builtins that are supported by c-compilers.
In this case: Clang.

This also simplifies the `AIR` instruction as it now uses the payload field of `ty_pl` and `pl_op`
directly to store the index argument rather than storing it inside Extra. This saves us 4 bytes
per builtin call.
2022-03-03 16:33:46 -07:00
Luuk de Gram
21f0503c01 Update behavior tests 2022-03-03 16:33:46 -07:00
Luuk de Gram
43cb19ea4d wasm: Implement @wasmMemoryGrow builtin
Similarly to the other wasm builtin, this implements the grow variation where the memory
index is a comptime known value. The operand as well as the result are runtime values.
This also verifies during semantic analysis the target we're building for is wasm, or else
emits a compilation error. This means that other backends do not have to handle this AIR instruction,
other than the wasm and LLVM backends.
2022-03-03 16:33:46 -07:00
Luuk de Gram
ec4c30ae48 wasm: Implement @wasmMemorySize() builtin
This implements the `wasmMemorySize` builtin, in Sema and the Wasm backend.
The Stage2 implementation differs from stage1 in the way that `index` must be a comptime value.
The stage1 variant is incorrect, as the index is part of the instruction encoding, and therefore,
cannot be a runtime value.
2022-03-03 16:33:46 -07:00
Andrew Kelley
0ea51f7f49
Merge pull request #11049 from mitchellh/peer-arrays
stage2: fix a couple issues with peer resolution and const casting arrays
2022-03-03 17:56:37 -05:00
Andrew Kelley
6c045f9e83
Merge pull request #11047 from Vexu/stage2
Stage2: make `expectEqualSlices` work
2022-03-03 17:55:55 -05:00
Cody Tapscott
aafcd8eab3 stdlib std.os: Rename RelativePath to RelativePathWasi 2022-03-03 14:31:49 -07:00
Cody Tapscott
ade2d0c6a2 stdlib WASI: Add realpath() support for non-absolute Preopens 2022-03-03 14:31:49 -07:00
Cody Tapscott
58f961f4cb stdlib: Add emulated CWD to std.os for WASI targets
This adds a special CWD file descriptor, AT.FDCWD (-2), to refer to the
current working directory. The `*at(...)` functions look for this and
resolve relative paths against the stored CWD. Absolute paths are
dynamically matched against the stored Preopens.

"os.initPreopensWasi()" must be called before std.os functions will
resolve relative or absolute paths correctly. This is asserted at
runtime.

Support has been added for: `open`, `rename`, `mkdir`, `rmdir`, `chdir`,
`fchdir`, `link`, `symlink`, `unlink`, `readlink`, `fstatat`, `access`,
and `faccessat`.

This also includes limited support for `getcwd()` and `realpath()`.
These return an error if the CWD does not correspond to a Preopen with
an absolute path. They also do not currently expand symlinks.
2022-03-03 14:31:49 -07:00
Veikka Tuominen
aa7cbca7d3 stage2: make analyzePtrArithmetic no-op with offset=0 2022-03-03 22:42:34 +02:00
Veikka Tuominen
69bd2c243e stage2: remove opaque type workaround from Type.ptrAlignment 2022-03-03 22:16:49 +02:00
Veikka Tuominen
7691013d10 stage2: add 'called from here' error note 2022-03-03 22:14:43 +02:00
Hiroaki Nakamura
3605dd307f
os/linux/io_uring: add recvmsg and sendmsg (#10212)
* os/linux/io_uring: add recvmsg and sendmsg

* Use std.os.iovec and std.os.iovec_const

* Remove msg_ prefix in msghdr and msghdr_const in arm64 etc

* Strip msg_ prefix in msghdr and msghdr_const for linux arm-eabi

* Copy msghdr and msghdr_const from i386 to mips

* Add sockaddr to lib/std/os/linux/mips.zig

* Copy msghdr and msghdr_const from x86_64 to riscv64
2022-03-03 14:13:54 -06:00
Andrew Kelley
e91c16e38b
Merge pull request #11043 from topolarity/ptr-fixes
stage2: Improve `@ptrCast` support for sliced/optional operands
2022-03-03 15:12:02 -05:00
Andrew Kelley
365aca0e90 Sema: allow pointers to opaques to be aligned 2022-03-03 13:11:06 -07:00
Cody Tapscott
85610a9aff stage2 llvm: Lower 0-bit field-ptr as ptr-to-void 2022-03-03 13:08:14 -07:00
Cody Tapscott
b6a6f05c0d stage2: support @ptrCast for slices with an offset 2022-03-03 13:08:14 -07:00
Cody Tapscott
b6f1a8612b stage2: Preserve larger alignment in @ptrCast 2022-03-03 13:08:14 -07:00
Mitchell Hashimoto
7deadf4301 stage2: reify error sets 2022-03-03 15:07:23 -05:00
Mitchell Hashimoto
b96d5fd71f
stage2: peer resolve const array pointer to unknown ptr 2022-03-03 11:08:14 -08:00
Mitchell Hashimoto
0924f17a23
stage2: peer resolve const u8 slices correctly 2022-03-03 11:04:04 -08:00
Motiejus Jakštys
65943010c7
std.BoundedArray: return explicit errors (#11044)
* std.BoundedArray: return explicit errors

Makes it easier to mark explicit errors when using BoundedArray
downstream.

* std.BoundedArray.insert() returns Overflow only
2022-03-03 19:39:45 +01:00
Andrew Kelley
9aa220ebb5 freestanding libc: add missing export of sqrt, sqrtf
this was a typo in a previous commit, didn't mean to omit these.
2022-03-03 00:52:55 -08:00
Andrew Kelley
0a4f58490f behavior tests cleanup: promote math.zig 2022-03-03 01:24:26 -07:00
Andrew Kelley
67ba4c5679 stage2: add all functions to freestanding libc
Looks like all these functions are at least compiling successfully. I
haven't tried to run their test suites yet.

The one exception is `clone` which is crashing the compiler due to the
inline assembly. Still, this is progress!
2022-03-03 01:24:26 -07:00
Andrew Kelley
b33f3b23c9 LLVM: fix lowering of unions and switches
`Module.Union.getLayout` now additionally returns a `padding` field
which tells how many bytes are between the final field end offset and
the ending offset of the union. This is used by the LLVM backend to
explicitly insert padding.

LLVM backend: lowering of unions now inserts additional padding so that
LLVM's internals will agree on the ABI size to match what ABI size zig
wants unions to be. This is an alternative to calling LLVMABISizeOfType
and LLVMABIAlignmentOfType which end up crashing when recursive struct
definitions come into play. We no longer ever call these two functions
and the bindings are deleted to avoid future footgun firings.

LLVM backend: lowering of unions now represents untagged unions
consistently. Before it was tripping an assertion.

LLVM backend: switch cases call inttoptr on the case items and condition
if necessary. Prevents tripping an LLVM assertion.

After this commit, we are no longer tripping over any LLVM assertions.
2022-03-03 01:19:49 -07:00