Skip to content

Commit

Permalink
no-copy semantics for peer result function calls
Browse files Browse the repository at this point in the history
```zig
export fn entry() void {
    var c = true;
    var x = if (c) foo() else bar();
}
```

```llvm
define void @entry() #2 !dbg !35 {
Entry:
  %c = alloca i1, align 1
  %x = alloca %Foo, align 4
  store i1 true, i1* %c, align 1, !dbg !47
  call void @llvm.dbg.declare(metadata i1* %c, metadata !39, metadata !DIExpression()), !dbg !48
  %0 = load i1, i1* %c, align 1, !dbg !49
  br i1 %0, label %Then, label %Else, !dbg !49

Then:                                             ; preds = %Entry
  call fastcc void @foo(%Foo* sret %x), !dbg !50
  br label %EndIf, !dbg !51

Else:                                             ; preds = %Entry
  call fastcc void @bar(%Foo* sret %x), !dbg !52
  br label %EndIf, !dbg !51

EndIf:                                            ; preds = %Else, %Then
  call void @llvm.dbg.declare(metadata %Foo* %x, metadata !42, metadata !DIExpression()), !dbg !53
  ret void, !dbg !54
}
```
  • Loading branch information
andrewrk committed Jun 7, 2019
1 parent b19b1c1 commit 76a3938
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 74 deletions.
8 changes: 8 additions & 0 deletions BRANCH_TODO
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,11 @@ inferred comptime

handle if with no else



static IrInstruction *ir_const_unreachable(IrAnalyze *ira, IrInstruction *source_instruction) {
IrInstruction *result = ir_const(ira, source_instruction, ira->codegen->builtin_types.entry_unreachable);
result->value.special = ConstValSpecialStatic;
return result;
}

4 changes: 3 additions & 1 deletion src/all_types.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3590,8 +3590,10 @@ enum ResultLocId {

struct ResultLoc {
ResultLocId id;
bool written;
IrInstruction *resolved_loc; // result ptr
IrInstruction *source_instruction;
IrInstruction *gen_instruction;
IrInstruction *gen_instruction; // value to store to the result loc
ZigType *implicit_elem_type;
};

Expand Down
Loading

5 comments on commit 76a3938

@bar

This comment was marked as off-topic.

@andrewrk

This comment was marked as off-topic.

@bar

This comment was marked as off-topic.

@bar

This comment was marked as off-topic.

@andrewrk

This comment was marked as off-topic.

Please sign in to comment.