1493 Commits

Author SHA1 Message Date
daurnimator
3b297f58f7 src: use zig_panic rather than having LLVM abort 2019-09-19 11:51:39 -04:00
Andrew Kelley
005a54a853
fixups for @splat
* Fix codegen for splat - instead of giving vectors of length N
   to shufflevector for both of the operands, it gives vectors of length
   1. The mask vector is the only one that needs N elements.
 * Separate Splat into SplatSrc and SplatGen; the `len` is not needed
   once it gets to codegen since it is redundant with the result type.
 * Refactor compile error for wrong vector element type so that the
   compile error message is not duplicated in zig source code
 * Improve implementation to correctly handle comptime values such as
   undefined and lazy values.
 * Improve compile error for bad vector element type to point to the
   correct place.
 * Delete dead code.
 * Modify behavior test to use an array cast instead of vector element
   indexing since I'm merging this splat commit out-of-order from
   Shawn's patch set.
2019-09-19 10:58:12 -04:00
Shawn Landden
01577a3af4
@splat 2019-09-19 10:11:06 -04:00
Andrew Kelley
380c8ec2c9
implement runtime @byteSwap and other fixups
* update docs for `@byteSwap`.
 * fix hash & eql functions for ZigLLVMFnIdBswap not updated to
   include vector len. this was causing incorrect bswap function
   being called in unrelated code
 * fix `@byteSwap` behavior tests only testing comptime and not
   runtime operations
 * implement runtime `@byteSwap`
 * fix incorrect logic in ir_render_vector_to_array and
   ir_render_array_to_vector with regards to whether or not to bitcast
 * `@byteSwap` accepts an array operand which it will cast to vector
 * simplify `@byteSwap` semantic analysis code and various fixes
2019-09-19 00:59:04 -04:00
Shawn Landden
76f5396077
@byteSwap on vectors 2019-09-18 16:49:14 -04:00
Andrew Kelley
2038f4d45a
rework the implementation
* update documentation
   - move `@shuffle` to be sorted alphabetically
   - remove mention of LLVM
   - minor clarifications & rewording
 * introduce ir_resolve_vector_elem_type to avoid duplicate compile
   error message and duplicate vector element checking logic
 * rework ir_analyze_shuffle_vector to solve various issues
 * improve `@shuffle` to allow implicit cast of arrays
 * the shuffle tests weren't being run
2019-09-18 16:15:19 -04:00
Shawn Landden
193604c837
stage1: add @shuffle() shufflevector support
I change the semantics of the mask operand, to make it a little more
flexible. There is no real danger in this because it is a compile-error
if you do it the LLVM way (and there is an appropiate error to tell you
this).

v2: avoid problems with double-free
2019-09-18 11:26:45 -04:00
Andrew Kelley
558b4ac1f0
adjust codegen of casting between arrays and vectors
* bitcasting is still better when the size_in_bits aligns with the ABI
   size of the element type. Logic is reworked to do bitcasting when
   possible
 * rather than using insertelement/extractelement to work with arrays,
   store/load elements directly. This matches codegen for arrays
   elsewhere.
2019-09-18 10:24:28 -04:00
Shawn Landden
0e3ca4c63e
Fix array->vector and vector->array for many types. Allow vector of bool.
Vectors do not have the same packing as arrays, and just bitcasting
is not the correct way to convert them.
2019-09-18 09:52:58 -04:00
Andrew Kelley
c4416b224d
Merge remote-tracking branch 'origin/master' into llvm9 2019-09-15 20:59:53 -04:00
Andrew Kelley
8223aca09b
no-stack-arg-probe only for UEFI 2019-09-13 14:46:22 -04:00
Andrew Kelley
2b698888ce
fix regression from incorrect conflict resolution in prev commit
thanks for catching this LemonBoy
2019-09-13 14:42:30 -04:00
Andrew Kelley
c15e464320
Merge branch 'uefi' of https://github.com/nrdmn/zig into nrdmn-uefi 2019-09-13 14:10:42 -04:00
Andrew Kelley
cf4bccf765
improvements targeted at improving async functions
* Reuse bytes of async function frames when non-async functions
   make `noasync` calls. This prevents explosive stack growth.
 * Zig now passes a stack size argument to the linker when linking ELF
   binaries. Linux ignores this value, but it is available as a program
   header called GNU_STACK. I prototyped some code that memory maps
   extra space to the stack using this program header, but there was
   still a problem when accessing stack memory very far down. Stack
   probing is needed or not working or something. I also prototyped
   using `@newStackCall` to call main and that does work around the
   issue but it also brings its own issues. That code is commented out
   for now in std/special/start.zig. I'm on a plane with no Internet,
   but I plan to consult with the musl community for advice when I get a
   chance.
 * Added `noasync` to a bunch of function calls in std.debug. It's very
   messy but it's a workaround that makes stack traces functional with
   evented I/O enabled. Eventually these will be cleaned up as the root
   bugs are found and fixed. Programs built in blocking mode are
   unaffected.
 * Lowered the default stack size of std.io.InStream (for the async
   version) to 1 MiB instead of 4. Until we figure out how to get
   choosing a stack size working (see 2nd bullet point above), 4 MiB
   tends to cause segfaults due to stack size running out, or usage of
   stack memory too far apart, or something like that.
 * Default thread stack size is bumped from 8 MiB to 16 to match the
   size we give for the main thread. It's planned to eventually remove
   this hard coded value and have Zig able to determine this value
   during semantic analysis, with call graph analysis and function
   pointer annotations and extern function annotations.
2019-09-12 01:40:58 -04:00
Andrew Kelley
c9b2210fcf
async function calls re-use frame buffers
See #3069
2019-09-10 22:59:00 -04:00
Andrew Kelley
185cb13278
Merge remote-tracking branch 'origin/master' into llvm9 2019-09-10 13:00:35 -04:00
Andrew Kelley
f50bfb94b5
fix bad LLVM IR when for target expr needs to be spilled
Also reduce the size of ZigVar in memory by making the name
a `const char *` rather than a `Buf`.
2019-09-09 15:59:16 -04:00
Andrew Kelley
f7721ac37c
implement spilling when returning error union async function call
closes #3190
2019-09-09 12:15:39 -04:00
Andrew Kelley
2482bdf22b
release builds of stage1 have llvm ir verification
the stage2 zig code however gets compiled in release mode,
and stripped.
2019-09-09 09:33:33 -04:00
Andrew Kelley
5dde3cd3bd
move logic for propagating framework dirs to zig cc 2019-09-08 15:09:05 -04:00
Andrew Kelley
d1a98ccff4
implement spills when expressions used across suspend points
closes #3077
2019-09-07 00:13:12 -04:00
Andrew Kelley
9ca8d9e21a
fix await used in an expression generating bad LLVM 2019-09-07 00:13:12 -04:00
Andrew Kelley
7d303ae861
runtime safety for noasync function calls
See #3157
2019-09-06 13:08:44 -04:00
Andrew Kelley
0a3c6dbda9
implement noasync function calls
See #3157
2019-09-05 21:55:32 -04:00
LemonBoy
0107b19124 Resolve lazy values when checking for definedness
Fixes #3154
2019-09-05 13:09:43 -04:00
Andrew Kelley
ac7703f65f
fixups and add documentation for @Type 2019-09-04 11:12:14 -04:00
Jonathan Marler
b728cb6d4e Add @Type builtin 2019-09-03 22:50:29 -06:00
Andrew Kelley
77a5f888be
emit a compile error if a test becomes async
See #3117
2019-09-03 22:09:47 -04:00
Andrew Kelley
be17a4b6c1
fix compiler crash in struct field pointers
when the llvm type has not been fully analyzed. This is a regression
from lazy values.
2019-09-03 14:51:34 -04:00
Andrew Kelley
e673d865fb
fix stack traces on macos when passing absolute path to root source file
The comment added by this commit is copied here:

For macOS stack traces, we want to avoid having to parse the compilation unit debug
info. As long as each debug info file has a path independent of the compilation unit
directory (DW_AT_comp_dir), then we never have to look at the compilation unit debug
info. If we provide an absolute path to LLVM here for the compilation unit debug info,
LLVM will emit DWARF info that depends on DW_AT_comp_dir. To avoid this, we pass "."
for the compilation unit directory. This forces each debug file to have a directory
rather than be relative to DW_AT_comp_dir. According to DWARF 5, debug files will
no longer reference DW_AT_comp_dir, for the purpose of being able to support the
common practice of stripping all but the line number sections from an executable.

closes #2700
2019-09-03 13:46:08 -04:00
Andrew Kelley
d74b8567cf
omit prefix data for async functions sometimes
When `@frameSize` is never called, and `@asyncCall` on a runtime-known
pointer is never used, no prefix data for async functions is needed.

Related: #3160
2019-09-02 21:31:26 -04:00
Andrew Kelley
058050f22c
Merge remote-tracking branch 'origin/master' into llvm9 2019-09-02 20:56:31 -04:00
Andrew Kelley
4a5b0cde13
fix const result loc, runtime if cond, else unreachable
Closes #2791. See that issue for more details; I documented the
debugging process quite thoroughly on this one.
2019-09-02 20:28:25 -04:00
Andrew Kelley
0fe28855c5
add ability to specify darwin framework search dirs 2019-09-02 11:48:06 -04:00
Andrew Kelley
5c3a9a1a3e
improvements to @asyncCall
* `await @asyncCall` generates better code. See #3065
 * `@asyncCall` works with a real `@Frame(func)` in addition to
   a byte slice. Closes #3072
 * `@asyncCall` allows passing `{}` (a void value) as the result
   pointer, which uses the result location inside the frame.
   Closes #3068
 * support `await @asyncCall` on a non-async function. This is in
   preparation for safe recursion (#1006).
2019-08-31 18:50:16 -04:00
Andrew Kelley
a223063923
@typeOf now guarantees no runtime side effects
related: #1627
2019-08-31 11:00:31 -04:00
Andrew Kelley
6ab8b2aab4
support recursive async and non-async functions
which heap allocate their own frames

related: #1006
2019-08-30 20:06:02 -04:00
Andrew Kelley
03910925f0
await does not force async if callee is blocking
closes #3067
2019-08-29 21:51:37 -04:00
Andrew Kelley
d9f0446b1f
make @sizeOf lazy 2019-08-29 12:43:56 -04:00
Andrew Kelley
94bbb46ca6
fix not fully resolving debug info for structs causing llvm error 2019-08-29 10:29:48 -04:00
Andrew Kelley
f7f8692730
fix not fully resolving debug info for structs causing llvm error 2019-08-29 10:24:24 -04:00
Andrew Kelley
928ce5e326
Merge remote-tracking branch 'origin/master' into llvm9 2019-08-28 16:59:35 -04:00
Andrew Kelley
af90da1531
fix implicit cast from zero sized array ptr to slice
closes #1850
2019-08-28 12:16:52 -04:00
Andrew Kelley
ae65c236c5
fix regression with global variable assignment...
...with optional unwrapping with var initialized to undefined
2019-08-26 15:24:24 -04:00
Andrew Kelley
fa6c20a02d
hook up unions with lazy values
this case works now:

```zig
const Expr = union(enum) {
    Literal: u8,
    Question: *Expr,
};
```
2019-08-25 11:34:07 -04:00
Andrew Kelley
ac4dd9d665
better handling of lazy structs
this case works now:

```zig
const A = struct {
    b_list_pointer: *const []B,
};
const B = struct {
    a_pointer: *const A,
};

const b_list: []B = [_]B{};
const a = A{ .b_list_pointer = &b_list };
const obj = B{ .a_pointer = &a };
```
2019-08-23 15:54:51 -04:00
Andrew Kelley
1dd658d1d0
allow top level declarations to be lazy
this case now works:

```zig
const A = struct {
    b: B,
};
const B = fn (A) void;
```
2019-08-23 14:07:34 -04:00
Andrew Kelley
3865b6ad8f
Merge remote-tracking branch 'origin/master' into fix-field-alignment-kludge 2019-08-23 11:43:37 -04:00
Jonathan Marler
9322eee80a Encapsulate bigint representation, assert on cast data loss 2019-08-23 11:14:08 -04:00
Andrew Kelley
8460d5617c
introduce lazy values
see #2174
2019-08-22 12:08:04 -04:00