959 Commits

Author SHA1 Message Date
Andrew Kelley
fa30ebfbe5
suspension points inside branching control flow 2019-08-04 18:24:10 -04:00
Andrew Kelley
12924477a5
fix regression in calling extern functions 2019-08-03 20:33:16 -04:00
Andrew Kelley
87710a1cc2
implement @asyncCall which supports async function pointers 2019-08-03 16:17:42 -04:00
Andrew Kelley
c879209661
add compile error for calling async function pointer 2019-08-03 02:40:38 -04:00
Andrew Kelley
056c4e2c98
implement async await and return 2019-08-02 01:06:00 -04:00
Andrew Kelley
1dd0c3d49f
fix calling an inferred async function 2019-08-01 16:41:30 -04:00
Andrew Kelley
e7ae4e4645
reimplement async with function splitting instead of switch 2019-08-01 16:08:52 -04:00
Andrew Kelley
dbdc4d62d0
improve support for anyframe and anyframe->T
* add implicit cast from `*@Frame(func)` to `anyframe->T` or `anyframe`.
 * add implicit cast from `anyframe->T` to `anyframe`.
 * `resume` works on `anyframe->T` and `anyframe` types.
2019-07-29 19:32:49 -04:00
Andrew Kelley
ee64a22045
add the anyframe and anyframe->T types 2019-07-26 19:52:35 -04:00
Andrew Kelley
018a89c7a1
async functions return void, no more GetSize resume block 2019-07-26 17:07:19 -04:00
Andrew Kelley
ead2d32be8
calling an inferred async function 2019-07-25 00:03:06 -04:00
Andrew Kelley
e220812f2f
implement local variables in async functions 2019-07-24 02:59:51 -04:00
Andrew Kelley
19ee495750
add error for function with ccc indirectly calling async function 2019-07-23 19:35:41 -04:00
Andrew Kelley
7e9760de10
inferring async from async calls 2019-07-23 18:54:45 -04:00
Andrew Kelley
317d1ecb2c
Merge remote-tracking branch 'origin/master' into rewrite-coroutines 2019-07-22 14:37:08 -04:00
Andrew Kelley
fcadeb50c0
fix multiple coroutines existing clobbering each other 2019-07-22 14:36:14 -04:00
Andrew Kelley
a3327f0fbd
fix usingnamespace analyzing the expression multiple times 2019-07-22 12:33:24 -04:00
Andrew Kelley
59bf9ca58c
implement async function parameters 2019-07-21 23:27:47 -04:00
Andrew Kelley
78e03c466c
simple async function passing test 2019-07-21 19:56:37 -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
af8661405b
fix usingnamespace
It used to be that usingnamespace was only allowed at top level. This
made it OK to put the state inside the AST node data structure. However,
now usingnamespace can occur inside any aggregate data structure, and
therefore the state must be in the TopLevelDeclaration rather than in
the AST node.

There were two other problems with the usingnamespace implementation:

 * It was passing the wrong destination ScopeDecl, so it could cause an
   incorrect error such as "import of file outside package path".
 * When doing `usingnamespace` on a file that already had
   `pub usingnamespace` in it would "steal" the usingnamespace, causing
   incorrect "use of undeclared identifier" errors in the target file.

closes #2632
closes #2580
2019-07-19 16:56:44 -04:00
Andrew Kelley
b1f8b53d20
rename internal names regarding usingnamespace 2019-07-16 16:20:54 -04:00
Michael Dusan
7a2b0cc9c4 fix stack escape in add_source_file() 2019-06-29 13:19:39 -04:00
Andrew Kelley
3085d29af8
Merge remote-tracking branch 'origin/master' into copy-elision-3 2019-06-26 14:44:01 -04:00
Andrew Kelley
c61e0a078c
fix union init with void payload
all std lib tests passing now
2019-06-25 11:31:38 -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
ff6d563b04
fix implicit cast to optional to error union to return result loc 2019-06-21 17:49:54 -04:00
Shawn Landden
ebde2ff899 stage1: update fn_key_eql() for @mulAdd() on vectors 2019-06-21 08:44:20 -05:00
Andrew Kelley
b588a803bf
fix comptime modification of const struct field 2019-06-19 14:35:59 -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
b025193de5
inferred comptime values rather than elided scopes
because of this example:

```zig
export fn entry(b: bool) usize {
    var runtime = [1]i32{3};
    comptime var i: usize = 0;
    inline while (i < 2) : (i += 1) {
        const result = if (i == 0) [1]i32{2} else runtime;
    }
    comptime {
        return i;
    }
}
```

The problem is that the concept of "resetting" a result location,
introduced in the previous commit, cannot handle elision scopes.
This concept is inherently broken with inline loops.
2019-06-17 13:31:19 -04:00
Andrew Kelley
60025a3704
Merge remote-tracking branch 'origin/master' into copy-elision-3 2019-06-15 10:34:04 -04:00
Andrew Kelley
f8f054b354
fix @export for arrays not respecting the symbol name
Previously, the symbol name parameter of `@export` would be ignored for
variables, and the variable name would be used for the symbol name.
Now it works as expected.

See #2679
2019-06-14 17:23:24 -04:00
Andrew Kelley
42ea2d0d1c
fix @export for arrays and allow sections on extern variables
previously `@export` for an array would panic with a TODO message.
now it will do the export. However, it uses the variable's name
rather than the name passed to `@export`. Issue #2679 remains open
for that problem.
2019-06-14 15:28:52 -04:00
Andrew Kelley
7411a88d5f
fix comptime function calls 2019-06-11 00:27:10 -04:00
Andrew Kelley
3a4b749c8a
Merge remote-tracking branch 'origin/master' into copy-elision-3 2019-06-09 19:44:01 -04:00
Andrew Kelley
b735764898
different array literal syntax when inferring the size
old syntax:  []i32{1, 2, 3}
new syntax: [_]i32{1, 2, 3}

closes #1797
2019-06-09 19:26:32 -04:00
Andrew Kelley
771e88951a
result location mechanism for struct initialization
```zig
export fn entry() void {
    const static = Foo{
        .x = 9,
        .bar = Bar{ .y = 10 },
    };
    const runtime = foo(true);
}

fn foo(c: bool) Foo {
    return Foo{
        .x = 12,
        .bar = if (c) bar1() else bar2(),
    };
}

fn bar1() Bar {
    return Bar{ .y = 34 };
}

fn bar2() Bar {
    return Bar{ .y = 56 };
}
```

```llvm
@0 = internal unnamed_addr constant %Foo { i32 9, %Bar { i32 10 } }, align 4
@1 = internal unnamed_addr constant %Bar { i32 34 }, align 4
@2 = internal unnamed_addr constant %Bar { i32 56 }, align 4

define void @entry() #2 !dbg !35 {
Entry:
  %runtime = alloca %Foo, align 4
  call void @llvm.dbg.declare(metadata %Foo* @0, metadata !39, metadata !DIExpression()), !dbg !50
  call fastcc void @foo(%Foo* sret %runtime, i1 true), !dbg !51
  call void @llvm.dbg.declare(metadata %Foo* %runtime, metadata !49, metadata !DIExpression()), !dbg !52
  ret void, !dbg !53
}

define internal fastcc void @foo(%Foo* nonnull sret, i1) unnamed_addr #2 !dbg !54 {
Entry:
  %c = alloca i1, align 1
  store i1 %1, i1* %c, align 1
  call void @llvm.dbg.declare(metadata i1* %c, metadata !60, metadata !DIExpression()), !dbg !61
  %2 = getelementptr inbounds %Foo, %Foo* %0, i32 0, i32 0, !dbg !62
  store i32 12, i32* %2, align 4, !dbg !62
  %3 = getelementptr inbounds %Foo, %Foo* %0, i32 0, i32 1, !dbg !64
  %4 = load i1, i1* %c, align 1, !dbg !65
  br i1 %4, label %Then, label %Else, !dbg !65

Then:                                             ; preds = %Entry
  call fastcc void @bar1(%Bar* sret %3), !dbg !66
  br label %EndIf, !dbg !64

Else:                                             ; preds = %Entry
  call fastcc void @bar2(%Bar* sret %3), !dbg !67
  br label %EndIf, !dbg !64

EndIf:                                            ; preds = %Else, %Then
  ret void, !dbg !68
}

define internal fastcc void @bar1(%Bar* nonnull sret) unnamed_addr #2 !dbg !69 {
Entry:
  %1 = bitcast %Bar* %0 to i8*, !dbg !73
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %1, i8* align 4 bitcast (%Bar* @1 to i8*), i64 4, i1 false), !dbg !73
  ret void, !dbg !73
}

define internal fastcc void @bar2(%Bar* nonnull sret) unnamed_addr #2 !dbg !75 {
Entry:
  %1 = bitcast %Bar* %0 to i8*, !dbg !76
  call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %1, i8* align 4 bitcast (%Bar* @2 to i8*), i64 4, i1 false), !dbg !76
  ret void, !dbg !76
}

!39 = !DILocalVariable(name: "static", scope: !40, file: !5, line: 2, type: !41)
!49 = !DILocalVariable(name: "runtime", scope: !40, file: !5, line: 6, type: !41)
```
2019-06-08 18:51:31 -04:00
Andrew Kelley
52eb347188
hook up result locs for try 2019-06-08 01:16:19 -04:00
LemonBoy
80cd142c96 Propagate DIFlags to LLVM 2019-06-04 09:05:33 +02:00
Andrew Kelley
ccce3d8526
no-copy semantics for function forwarding
```zig
fn foo() Foo {
    return bar();
}
```

```llvm
define internal fastcc void @foo(%Foo* nonnull sret) unnamed_addr #2 !dbg !48 {
Entry:
  call fastcc void @bar(%Foo* sret %0), !dbg !52
  ret void, !dbg !54
}
```
2019-05-31 01:36:57 -04:00
Andrew Kelley
78f32259da
default struct field initialization expressions
closes #485
2019-05-30 15:46:11 -04:00
Andrew Kelley
1ab0ac3ea2
cleanups for windows subsystem in builtin.zig 2019-05-29 16:55:02 -04:00
Andrew Kelley
1ccbd1fb67
use works on unions and enums in addition to structs 2019-05-29 16:31:49 -04:00
Andrew Kelley
9891c4f30d
Merge branch 'use-struct-pt2' of https://github.com/LemonBoy/zig into LemonBoy-use-struct-pt2 2019-05-29 15:48:49 -04:00
LemonBoy
528c151a55 Reject undefined as type
Make analyze_type_expr behave like ir_resolve_type when the user tries
to use `undefined` as a type.

Closes #2436
2019-05-28 18:02:57 -04:00
LemonBoy
048169cbea Avoid a crash when there are no namespace components
Fixes #2500
2019-05-28 17:49:37 -04:00
emekoi
3f302594b8 respect subsystem flag in all cases 2019-05-27 22:15:33 -04:00
LemonBoy
86b3007b94
Reject slices in use expressions
Co-Authored-By: emekoi <emekankurumeh@outlook.com>
2019-05-24 13:20:44 +02:00