249 Commits

Author SHA1 Message Date
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
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
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
0a3c6dbda9
implement noasync function calls
See #3157
2019-09-05 21:55:32 -04:00
Michael Dusan
fe153ad2a4 stage1 enhance IR print
- print fn name in pass1
- replace scalar with enum IrPass for clarity
2019-09-05 13:06:10 -04:00
Jonathan Marler
b728cb6d4e Add @Type builtin 2019-09-03 22:50:29 -06:00
Michael Dusan
1f99899408 stage1 enhance IR print
- pass2 now prints missing instructions in a trailing fashion
- instruction struct name added to print as column 2
2019-08-31 22:42:58 -04:00
Andrew Kelley
13b5a4bf8c
remove cancel 2019-08-15 14:05:12 -04:00
Andrew Kelley
5092634103
avoid the word "coroutine", they're "async functions" 2019-08-13 14:14:19 -04:00
Andrew Kelley
22428a7546
fix try in an async function with error union and non-zero-bit payload 2019-08-10 15:20:08 -04:00
Andrew Kelley
b9d1d45dfd
fix combining try with errdefer cancel 2019-08-09 21:49:40 -04:00
Andrew Kelley
2e7f53f1f0
fix cancel inside an errdefer 2019-08-09 17:34:06 -04:00
Andrew Kelley
34bfdf193a
cancel, defer, errdefer all working as intended now 2019-08-08 11:37:49 -04:00
Andrew Kelley
7e1fcb55b3
implement cancel
all behavior tests passing in this branch
2019-08-07 00:53:04 -04:00
Andrew Kelley
400500a3af
improve async function semantics
* add safety panic for resuming a function which is returning, pending
   an await
 * remove IrInstructionResultPtr
 * add IrInstructionReturnBegin. This does the early return in async
   functions; does nothing in normal functions.
 * `await` gets a result location
 * `analyze_fn_async` will call `analyze_fn_body` if necessary.
 * async function frames have a result pointer field for themselves
   to access and one for the awaiter to supply before the atomic rmw.
   when returning, async functions copy the result to the awaiter result
   pointer, if it is non-null.
 * async function frames have a stack trace pointer which is supplied by
   the awaiter before the atomicrmw. Later in the frame is a stack trace
   struct and addresses, which is used for its own calls and awaits.
 * when awaiting an async function, if an early return occurred, the
   awaiter tail resumes the frame.
 * when an async function returns, early return does a suspend
   (in IrInstructionReturnBegin) before copying
   the error return trace data, result, and running the defers.
   After the last defer runs, the frame will no longer be accessed.
 * proper acquire/release atomic ordering attributes in async functions.
2019-08-06 16:53:22 -04:00
Andrew Kelley
a7763c06f9
delete IrInstructionMarkErrRetTracePtr
this IR instruction is no longer needed
2019-08-05 00:44:39 -04:00
Andrew Kelley
fbf21efd24
simpler, less memory intensive suspend/resume implementation 2019-08-04 18:58:14 -04:00
Andrew Kelley
056c4e2c98
implement async await and return 2019-08-02 01:06:00 -04:00
Andrew Kelley
ee64a22045
add the anyframe and anyframe->T types 2019-07-26 19:52:35 -04:00
Andrew Kelley
7b3686861f
@frameSize works via PrefixData 2019-07-25 22:24:01 -04:00
Andrew Kelley
538c0cd225
implement @frameSize 2019-07-25 15:05:55 -04:00
Andrew Kelley
70bced5dcf
implement @frame and @Frame 2019-07-25 01:47:56 -04:00
Andrew Kelley
11bd50f2b2
implement coroutine resume 2019-07-21 20:54:08 -04:00
Andrew Kelley
72e983670e
simple async function call working 2019-07-21 16:21:16 -04:00
Andrew Kelley
54e716afdc
remove coroutines implementation and promise type 2019-07-19 18:18:44 -04:00
Andrew Kelley
4bae87764f
update @unionInit to integrate with result location semantics 2019-07-03 13:40:40 -04:00
Andrew Kelley
9da054095c
Merge branch 'comptime-union-init' of https://github.com/rbscott/zig into rbscott-comptime-union-init 2019-07-03 11:26:55 -04:00
Andrew Kelley
df11512f85
fixups 2019-07-02 16:52:55 -04:00
Andrew Kelley
140335b99f
Merge branch 'has-field' of https://github.com/shawnl/zig into shawnl-has-field 2019-07-02 16:21:40 -04:00
Andrew Kelley
3085d29af8
Merge remote-tracking branch 'origin/master' into copy-elision-3 2019-06-26 14:44:01 -04:00
Shawn Landden
71e014caec stage1: add @sin @cos @exp @exp2 @ln @log2 @log10 @fabs @floor @ceil @trunc @round
and expand @sqrt

This revealed that the accuracy of ln is not as good as the current algorithm in
musl and glibc, and should be ported again.

v2: actually include tests
v3: fix reversal of in and out arguments on f128M_sqrt()
    add test for @sqrt on comptime_float
    do not include @nearbyInt() until it works on all targets.
2019-06-22 14:34:34 -05:00
Andrew Kelley
0498bd40d9
fix loops with multiple break statements 2019-06-20 22:38:40 -04:00
Shawn Landden
fce2d2d18b stage1: add support for @mulAdd fused-multiply-add for floats and vectors of floats
Not all of the softfloat library is being built....

Vector support is very buggy at the moment, but should work when the bugs are fixed.
(as I had the same code working with another vector function, that hasn't been merged yet).
2019-06-19 12:07:02 -05:00
Andrew Kelley
4e182c7e9e
inferred comptime array inits 2019-06-17 17:46:03 -04:00
Andrew Kelley
74250e434e
inferred comptime union inits 2019-06-17 16:27:45 -04:00
Andrew Kelley
9564c05cd5
better result location handling of inline loops 2019-06-15 19:19:13 -04:00
Andrew Kelley
6bf193af19
better result location semantics with optionals and return locations
somewhere along this branch, #1901 has been fixed.
2019-06-15 12:28:21 -04:00
Andrew Kelley
e1d14e73b5
fix @bitCast semantics when there is no parent result loc 2019-06-11 15:44:06 -04:00
Andrew Kelley
06f307ff77
fix implicit casting return value struct/arary init to optional 2019-06-11 12:19:57 -04:00
Andrew Kelley
f6d4e2565e
use result loc for ref instruction 2019-06-10 23:51:43 -04:00
Andrew Kelley
4582ec518f
result location semantics for vector to array
```zig
export fn entry() void {
    var x: @Vector(4, i32) = undefined;
    var y: [4]i32 = x;
}
```

```llvm
define void @entry() #2 !dbg !35 {
Entry:
  %x = alloca <4 x i32>, align 16
  %y = alloca [4 x i32], align 4
  %0 = bitcast <4 x i32>* %x to i8*, !dbg !47
  call void @llvm.memset.p0i8.i64(i8* align 16 %0, i8 -86, i64 16, i1 false), !dbg !47
  call void @llvm.dbg.declare(metadata <4 x i32>* %x, metadata !39, metadata !DIExpression()), !dbg !47
  %1 = load <4 x i32>, <4 x i32>* %x, align 16, !dbg !48
  %2 = bitcast [4 x i32]* %y to <4 x i32>*, !dbg !48
  store <4 x i32> %1, <4 x i32>* %2, align 16, !dbg !48
  call void @llvm.dbg.declare(metadata [4 x i32]* %y, metadata !45, metadata !DIExpression()), !dbg !49
  ret void, !dbg !50
}
```
2019-06-10 19:49:24 -04:00
Andrew Kelley
9a324ecb42
result loc semantics for loading packed struct pointer to packed struct
```zig
export fn entry() void {
    var x = foo();
    var ptr = &x.b;
    var y = ptr.*;
}
const Foo = packed struct {
    a: u24 = 1,
    b: Bar = Bar{},
};

const Bar = packed struct {
    a: u4 = 2,
    b: u4 = 3,
};
```

```llvm
define void @entry() #2 !dbg !35 {
Entry:
  %x = alloca %Foo, align 1
  %ptr = alloca i32*, align 8
  %y = alloca %Bar, align 1
  call fastcc void @foo(%Foo* sret %x), !dbg !55
  call void @llvm.dbg.declare(metadata %Foo* %x, metadata !39, metadata !DIExpression()), !dbg !56
  %0 = getelementptr inbounds %Foo, %Foo* %x, i32 0, i32 0, !dbg !57
  store i32* %0, i32** %ptr, align 8, !dbg !57
  call void @llvm.dbg.declare(metadata i32** %ptr, metadata !51, metadata !DIExpression()), !dbg !58
  %1 = load i32*, i32** %ptr, align 8, !dbg !59
  %2 = load i32, i32* %1, align 1, !dbg !60
  %3 = lshr i32 %2, 24, !dbg !60
  %4 = trunc i32 %3 to i8, !dbg !60
  %5 = bitcast %Bar* %y to i8*, !dbg !60
  store i8 %4, i8* %5, !dbg !60
  call void @llvm.dbg.declare(metadata %Bar* %y, metadata !54, metadata !DIExpression()), !dbg !61
  ret void, !dbg !62
}
```
2019-06-10 19:11:34 -04:00
Andrew Kelley
65f6ea66f4
result loc semantics for @sliceToBytes and @bytesToSlice 2019-06-10 18:34:27 -04:00
Andrew Kelley
ee3f7e20f6
result location semantics for cmpxchg 2019-06-10 17:49:36 -04:00
Andrew Kelley
b9c033ae1a
result location semantics for error union wrapping an error 2019-06-10 17:28:25 -04:00
Andrew Kelley
4f085b8d2c
result location semantics for error union wrapping a payload 2019-06-10 16:55:07 -04:00
Andrew Kelley
eaa9d8bdac
result location semantics for optional wrap 2019-06-10 16:20:13 -04:00
Andrew Kelley
c362895116
result location semantics for slices
```zig
export fn entry() void {
    var buf: [10]u8 = undefined;
    const slice1: []const u8 = &buf;
    const slice2 = buf[0..];
}
```

```llvm
define void @entry() #2 !dbg !35 {
Entry:
  %buf = alloca [10 x i8], align 1
  %slice1 = alloca %"[]u8", align 8
  %slice2 = alloca %"[]u8", align 8
  %0 = bitcast [10 x i8]* %buf to i8*, !dbg !46
  call void @llvm.memset.p0i8.i64(i8* align 1 %0, i8 -86, i64 10, i1 false), !dbg !46
  call void @llvm.dbg.declare(metadata [10 x i8]* %buf, metadata !39, metadata !DIExpression()), !dbg !46
  %1 = getelementptr inbounds %"[]u8", %"[]u8"* %slice1, i32 0, i32 0, !dbg !47
  %2 = getelementptr inbounds [10 x i8], [10 x i8]* %buf, i64 0, i64 0, !dbg !47
  store i8* %2, i8** %1, align 8, !dbg !47
  %3 = getelementptr inbounds %"[]u8", %"[]u8"* %slice1, i32 0, i32 1, !dbg !47
  store i64 10, i64* %3, align 8, !dbg !47
  call void @llvm.dbg.declare(metadata %"[]u8"* %slice1, metadata !44, metadata !DIExpression()), !dbg !48
  %4 = getelementptr inbounds %"[]u8", %"[]u8"* %slice2, i32 0, i32 0, !dbg !49
  %5 = getelementptr inbounds [10 x i8], [10 x i8]* %buf, i64 0, i64 0, !dbg !49
  store i8* %5, i8** %4, align 8, !dbg !49
  %6 = getelementptr inbounds %"[]u8", %"[]u8"* %slice2, i32 0, i32 1, !dbg !49
  store i64 10, i64* %6, align 8, !dbg !49
  call void @llvm.dbg.declare(metadata %"[]u8"* %slice2, metadata !45, metadata !DIExpression()), !dbg !50
  ret void, !dbg !51
}
```
2019-06-10 15:49:45 -04:00
Andrew Kelley
17b1ac5d03
result location semantics for @bitCast
```zig
export fn entry() void {
    var x = @bitCast(f32, foo());
}
```

```llvm
define void @entry() #2 !dbg !35 {
Entry:
  %x = alloca float, align 4
  %0 = bitcast float* %x to %Foo*, !dbg !42
  call fastcc void @foo(%Foo* sret %0), !dbg !42
  call void @llvm.dbg.declare(metadata float* %x, metadata !39, metadata !DIExpression()), !dbg !43
  ret void, !dbg !44
}
```
2019-06-10 12:24:19 -04:00