5202 Commits

Author SHA1 Message Date
Andrew Kelley
0d24bc7da0 LLVM: add DISubprogram and DIType lowering; handle dbg_stmt 2022-03-08 14:58:53 -07:00
Benjamin San Souci
e3c2cc1443
std.json: correctly handle sentinel terminated slices 2022-03-08 20:43:13 +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
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
76d810c568 std: disable flaky os.fcntl test
See tracking issue #11074
2022-03-06 20:49:49 -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
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
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
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
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
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
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
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
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
446324a1d8
Merge pull request #11025 from Vexu/stage2
stage2: implement `@extern`
2022-03-02 14:51:29 -05:00
Cody Tapscott
5c8a507e7a stage2 parser: UTF-8 encode \u{NNNNNN} escape sequences
The core of this change is to re-use the escape sequence parsing logic
for parsing both string and character literals.

The actual fix is that UTF-8 encoding was missing for string literals
with \u{...} escape sequences.
2022-03-02 14:45:19 -05:00
Veikka Tuominen
403a1fe5d7 stage2: add cast from ?*T to ?*anyopaque 2022-03-02 12:26:04 +02:00
Motiejus Jakštys
543bee0adf std.BufSet.clone: fix key ownership
This was introduced in d1a46548349a902c30057b3ba66ebad9bc25bdd2: when a
BufSet clones the keys, it used to assign the new pointers to the old
struct. Fix that by assigning the pointers to the correct, i.e. the new,
struct.

This caused double-free when using arena allocator for the new struct,
also in the test case.
2022-03-01 13:28:47 -05:00
Motiejus Jakštys
d1a4654834 std.BufSet: add clone and cloneWithAllocator
Following how ArrayList and HashMap does things. This is useful when one
wants to, ahem, clone the BufSet.
2022-02-28 15:51:58 -05:00
Veikka Tuominen
2682b41da5 make gpa.deinit work with stage2 2022-02-28 13:09:14 -07:00
David John
139b731d82 std: rename sched_yield to yield and move it to std.Thread 2022-02-27 15:34:02 -05:00
Andrew Kelley
b5066fdae2
Merge pull request #11001 from Vexu/stage2
stage2: make formatted printing work
2022-02-27 15:29:03 -05:00
Motiejus Jakštys
c03b733f09
std.HashMap: return explicit errors (#11000)
All errors from std.HashMap are allocation errors. Mark them as
such. This is helpful when one wants to return explicit errors where
HashMap is used.
2022-02-27 15:24:00 -05:00
Veikka Tuominen
9f59189c95 stage2: do not memoize calls that can mutate comptime state 2022-02-27 16:43:53 +02:00
Veikka Tuominen
7a92b89a9d stage2: forward discard result loc to more expressions 2022-02-27 13:32:55 +02:00
Veikka Tuominen
813f368a3c test runner: remove unnecessary stage2 workaround 2022-02-27 12:25:50 +02:00
Veikka Tuominen
1bbca4f935 stage2: fix bitcast to optional ptr in llvm backend; omit safety check for intToPtr on optional ptr 2022-02-27 12:15:49 +02:00
Veikka Tuominen
950d840be6 stage2: use stage1 test runner for stage2 2022-02-27 11:57:12 +02:00
Veikka Tuominen
593d23c0d7 stage2: get formatted printing (somewhat) working 2022-02-27 10:05:29 +02:00
Al Hoang
db82c1b982 add constant for haiku
* re-enable zig build on haiku
2022-02-26 10:53:13 +02:00
Endel Dreyer
cd9a6fed4f fix typo on Thread's getHandle docs 2022-02-26 10:48:37 +02:00
protty
5d30e8016d
time: introduce Instant (#10972) 2022-02-24 18:51:44 -05:00
Isaac Freund
52a2aa11e2 std: work around current packed struct situation
As of 6249a24, align() is not allowed on packed struct fields
and as such the align(4) was removed from the first field of
EdidOverrideProtocolAttributes. The endgame here is packed struct
backed by explicit integers, in this case a u32, but until that
is implemented put the align(4) on the pointer to avoid breaking
someone's UEFI code in a hard to debug way.
2022-02-24 16:08:37 -05:00
Andrew Kelley
5ab5e2e673 Revert "Merge pull request #10950 from hexops/sg/responsefiles"
This reverts commit 136a43934bc08dc3aee85f1182904b97456601d3, reversing
changes made to 9dd839b7ed15d1191f3303d069cffe0473e03e83.

This broke the behavior of `zig run`.
2022-02-24 12:11:11 -07:00
Andrew Kelley
6249a24e81 stage2: integer-backed packed structs
This implements #10113 for the self-hosted compiler only. It removes the
ability to override alignment of packed struct fields, and removes the
ability to put pointers and arrays inside packed structs.

After this commit, nearly all the behavior tests pass for the stage2 llvm
backend that involve packed structs.

I didn't implement the compile errors or compile error tests yet. I'm
waiting until we have stage2 building itself and then I want to rework
the compile error test harness with inspiration from Vexu's arocc test
harness. At that point it should be a much nicer dev experience to work
on compile errors.
2022-02-23 23:59:25 -07:00
Jakub Konka
136a43934b
Merge pull request #10950 from hexops/sg/responsefiles
Do not fail to build if 'zig build-lib' etc. arguments exceed OS limits
2022-02-23 22:54:25 +01:00
Jakub Konka
9dd839b7ed
Merge pull request #10976 from ziglang/x64-macos-fixes
x64: print test runner results on macos
2022-02-23 22:40:06 +01:00
Jan Philipp Hafer
5d89955543 compiler_rt: specify goals, organize README and compiler_rt.zig
* goals
  - zig as linker for object files generated by other compilers
  - zig-specific runtime features for eventual standardisation

* changes
  - missing routines are marked with `missing`
  - structure inspired by libgcc docs, but improved order and wording
  - rename misspelled functions
  - reorder and rephrase compiler_rt.zig to reflect documentation
  - potential decimal float or fixed-point arithmetic support:
    * 'Decimal float library routines' ca. 120 functions
    * 'Fixed-point fractional library routines' ca. 300 functions

thanks to @Vexu for multiple reviews and @scheibo for review
2022-02-23 16:38:51 -05:00
Andrew Kelley
ecf56d85ef
Merge pull request #10969 from Vexu/stage2
stage2: fn typeinfo params
2022-02-23 16:10:17 -05:00
Jakub Konka
b7760ad742 std: re-enable result printing in the test runner for macos 2022-02-23 19:39:50 +01:00
Evan Haas
9716a1c3ab translate-c: Add support for cast-to-union
Fixes #10955
2022-02-23 14:11:46 +02:00
Veikka Tuominen
92beb2b490 stage2: misc fixes in Sema 2022-02-23 10:40:40 +02:00
xReveres
b2805666a7 stage1-wasm: implement shared memory 2022-02-23 08:57:20 +01:00
Veikka Tuominen
f8154905e7 stage1: rename TypeInfo.FnArg to Fn.Param 2022-02-23 09:44:36 +02:00
Felix Queißner
6fdcf1ad2d
std.os.linux.socketpair: fd is an out parameter 2022-02-23 09:32:54 +02:00