Commit Graph

5466 Commits

Author SHA1 Message Date
Andrew Kelley
eaf74f4f96
fix bitcast packed struct to integer and back 2019-06-13 20:24:10 -04:00
Andrew Kelley
57347aacd7
fix atomic builtin functions 2019-06-13 20:01:25 -04:00
Andrew Kelley
24cfa3534f
allow comptime array literals casted to slices 2019-06-13 16:51:26 -04:00
Andrew Kelley
3cbe827464
fix behavior for nested array literals
new compile error for trying to cast runtime array literals to slices
2019-06-13 16:25:35 -04:00
Andrew Kelley
efb064449f
fix runtime initialize array elem and then implicit cast to slice 2019-06-13 13:31:15 -04:00
Jonathan Marler
9e8db5b750 Remove const on argsAlloc 2019-06-13 11:42:17 -04:00
Josh Wolfe
82ab006e58 HashMap.getValue() 2019-06-13 11:41:34 -04:00
Jonathan Marler
8a2c2da805 Handle putNoClobber errors 2019-06-13 01:56:12 -04:00
Josh Wolfe
80fa871f4a Add HashMap apis that assert the common case
* putNoClobber() for put()
* removeAssertDiscard() for remove()
2019-06-13 00:17:12 -04:00
Andrew Kelley
ca0988e1d0
comment out the behavior tests that are failing 2019-06-12 22:19:56 -04:00
Andrew Kelley
b552e68c14
fix result loc implicit casting optionals and error unions
```zig
pub fn openHandle(handle: i32) File {
    return File{ .handle = handle };
}

pub fn getStdErr() anyerror!File {
    return openHandle(1);
}
```
2019-06-12 22:13:18 -04:00
Andrew Kelley
cdf14baa45
fix double nested peer result locations
```zig
export fn entry(x: bool) i32 {
    return if (x)
        if (x) a else b
    else
        if (x) c else d;
}
```
2019-06-12 21:46:04 -04:00
Andrew Kelley
0d62c92947
fix declref not writing to result loc
```zig
const a: i32 = 0;
const b: i32 = 1;
const c: i32 = 2;
const d: i32 = 3;

export fn entry(x: bool) i32 {
    return if (x)
        if (x)
            a
        else if (x)
            b
        else
            c
    else
        d;
}
```
2019-06-12 19:43:24 -04:00
Andrew Kelley
e6fa2ee706
fix nested peer result locs with no memory loc
```zig
export fn entry2(c: bool) i32 {
    return if (c)
        i32(0)
    else if (c)
        i32(1)
    else
        i32(2);
}
```

```llvm
define i32 @entry2(i1) #2 !dbg !35 {
Entry:
  %c = alloca i1, align 1
  store i1 %0, i1* %c, align 1
  call void @llvm.dbg.declare(metadata i1* %c, metadata !41, metadata !DIExpression()), !dbg !42
  %1 = load i1, i1* %c, align 1, !dbg !43
  br i1 %1, label %Then, label %Else, !dbg !43

Then:                                             ; preds = %Entry
  br label %EndIf3, !dbg !45

Else:                                             ; preds = %Entry
  %2 = load i1, i1* %c, align 1, !dbg !46
  br i1 %2, label %Then1, label %Else2, !dbg !46

Then1:                                            ; preds = %Else
  br label %EndIf, !dbg !47

Else2:                                            ; preds = %Else
  br label %EndIf, !dbg !47

EndIf:                                            ; preds = %Else2, %Then1
  %3 = phi i32 [ 1, %Then1 ], [ 2, %Else2 ], !dbg !47
  br label %EndIf3, !dbg !45

EndIf3:                                           ; preds = %EndIf, %Then
  %4 = phi i32 [ 0, %Then ], [ %3, %EndIf ], !dbg !45
  ret i32 %4, !dbg !48
}
```
2019-06-12 18:08:56 -04:00
Andrew Kelley
1526d89711
fix @bitCast with runtime scalar and dest result loc var 2019-06-12 15:02:46 -04:00
Andrew Kelley
35352e0f48
fix alignment problem with @bitCast result location 2019-06-12 13:49:57 -04:00
Andrew Kelley
278c7a2bc3
fix @bitCast regressions 2019-06-12 13:42:21 -04:00
emekoi
3ed6acd2d2 fixed infinite loop when caching packages 2019-06-11 19:19:44 -05:00
Andrew Kelley
ce5d50e4ed
fix runtime if nested inside comptime if 2019-06-11 18:26:01 -04:00
emekoi
e12c7d88b2 made root package available to itself 2019-06-11 16:06:24 -05:00
emekoi
4ea7685a5b made root package available to all other packages 2019-06-11 16:05:56 -05:00
Andrew Kelley
b3a4ec1bd2
fix returning scalar values
```zig
export fn entry1() i32 {
    return bar();
}
```

```llvm
define i32 @entry1() #2 !dbg !35 {
Entry:
  %0 = call fastcc i32 @bar(), !dbg !39
  ret i32 %0, !dbg !41
}
```
2019-06-11 16:04:04 -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
60c3861805
temporarily simplify test_runner.zig
so that this branch can start passing behavior tests. after the tests
pass, go back and undo the changes in this commit
2019-06-11 14:46:46 -04:00
Nicholas Walton
fcc0728a35 Update langref.html.in
Missing an "it"
2019-06-11 14:37:15 -04:00
Andrew Kelley
0ac566892d
fix for loop index variable not in scope 2019-06-11 14:15:58 -04:00
Andrew Kelley
515092210f
fix not checking return value of resolving result 2019-06-11 13:48:53 -04:00
Andrew Kelley
1c2e889820
fix struct and array init when result casted to anyerror!?T
previous commit message is incorrect, it was only for
anyerror!T
2019-06-11 13:44:09 -04:00
Andrew Kelley
fc8d881240
fix struct and array init when result casted to anyerror!?T 2019-06-11 13:27:01 -04:00
Andrew Kelley
06f307ff77
fix implicit casting return value struct/arary init to optional 2019-06-11 12:19:57 -04:00
daurnimator
43d52fa4c5
std: add std.http.Headers field
Based on lua-http's data structure
2019-06-11 22:54:40 +10:00
Andrew Kelley
a431a73dab
fixes for crashes and compile errors 2019-06-11 01:24:55 -04:00
Andrew Kelley
b053a65573
fix comptime variables 2019-06-11 00:36:03 -04:00
Andrew Kelley
7411a88d5f
fix comptime function calls 2019-06-11 00:27:10 -04:00
Andrew Kelley
33371ab55c
Merge remote-tracking branch 'origin/master' into copy-elision-3 2019-06-11 00:09:58 -04:00
Andrew Kelley
d504318f2e
remove the final legacy stack allocation 2019-06-10 23:54:28 -04:00
Andrew Kelley
f6d4e2565e
use result loc for ref instruction 2019-06-10 23:51:43 -04:00
Andrew Kelley
a0427d29e4
fix peer result locations in the face of unreachable
```zig
export fn entry() void {
    var nothing: ?*i32 = null;
    var whatever = if (nothing) |x1| i32(1) else unreachable;
}
```

```llvm
define void @entry() #2 !dbg !35 {
Entry:
  %nothing = alloca i32*, align 8
  %whatever = alloca i32, align 4
  store i32* null, i32** %nothing, align 8, !dbg !45
  call void @llvm.dbg.declare(metadata i32** %nothing, metadata !39, metadata !DIExpression()), !dbg !45
  %0 = load i32*, i32** %nothing, align 8, !dbg !46
  %1 = icmp ne i32* %0, null, !dbg !46
  br i1 %1, label %OptionalThen, label %OptionalElse, !dbg !46

OptionalThen:                                     ; preds = %Entry
  call void @llvm.dbg.declare(metadata i32** %nothing, metadata !43, metadata !DIExpression()), !dbg !46
  store i32 1, i32* %whatever, align 4, !dbg !47
  br label %OptionalEndIf, !dbg !46

OptionalElse:                                     ; preds = %Entry
  tail call fastcc void @panic(%"[]u8"* @1, %builtin.StackTrace* null), !dbg !48
  unreachable, !dbg !48

OptionalEndIf:                                    ; preds = %OptionalThen
  call void @llvm.dbg.declare(metadata i32* %whatever, metadata !44, metadata !DIExpression()), !dbg !49
  ret void, !dbg !50
}
```
2019-06-10 23:25: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
tgschultz
34a22a85ca altered all instances of readInt* in std.io (and std.debug) to consume the minimum byte size required instead of @sizeOf(). 2019-06-10 17:10:35 -04:00
Andrew Kelley
4f085b8d2c
result location semantics for error union wrapping a payload 2019-06-10 16:55:07 -04:00
Ryan Liptak
05e92a51aa Use std.math.isPowerOfTwo across std lib 2019-06-10 16:42:39 -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
Andrew Kelley
1a51bf6304
hook up result locations for union initializations
```zig
export fn entry() void {
    var x = Foo{ .bar = bar() };
}
```

```llvm
define void @entry() #2 !dbg !44 {
Entry:
  %x = alloca %Foo, align 4
  %0 = getelementptr inbounds %Foo, %Foo* %x, i32 0, i32 1, !dbg !68
  store i1 true, i1* %0, align 1, !dbg !68
  %1 = getelementptr inbounds %Foo, %Foo* %x, i32 0, i32 0, !dbg !68
  %2 = bitcast { i32, [4 x i8] }* %1 to %Bar*, !dbg !68
  call fastcc void @bar(%Bar* sret %2), !dbg !68
  call void @llvm.dbg.declare(metadata %Foo* %x, metadata !48, metadata !DIExpression()), !dbg !69
  ret void, !dbg !70
}
```
2019-06-10 11:15:32 -04:00