Skip to content

Add Parsing and Serialization test-cases for new Opaque Value Instructions #7802

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Parse/ParseSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3764,7 +3764,7 @@ bool SILParser::parseSILInstruction(SILBasicBlock *BB, SILBuilder &B) {
SourceLoc TyLoc;

if (parseTypedValueRef(Val, B) ||
P.parseToken(tok::colon, diag::expected_tok_in_sil_instr, ":") ||
P.parseToken(tok::comma, diag::expected_tok_in_sil_instr, ",") ||
P.parseToken(tok::sil_dollar, diag::expected_tok_in_sil_instr, "$") ||
parseASTType(FormalConcreteTy, TyLoc) ||
P.parseToken(tok::comma, diag::expected_tok_in_sil_instr, ",") ||
Expand Down
4 changes: 4 additions & 0 deletions lib/Serialization/DeserializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -982,6 +982,10 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
Ty,
ctxConformances);
break;
case ValueKind::InitExistentialOpaqueInst:
ResultVal = Builder.createInitExistentialOpaque(Loc, Ty, ConcreteTy,
operand, ctxConformances);
break;
case ValueKind::InitExistentialMetatypeInst:
ResultVal = Builder.createInitExistentialMetatype(Loc, operand, Ty,
ctxConformances);
Expand Down
2 changes: 1 addition & 1 deletion lib/Serialization/SerializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
break;
}
case ValueKind::InitExistentialOpaqueInst: {
auto &IEOI = cast<InitExistentialRefInst>(SI);
auto &IEOI = cast<InitExistentialOpaqueInst>(SI);
operand = IEOI.getOperand();
Ty = IEOI.getType();
FormalConcreteType = IEOI.getFormalConcreteType();
Expand Down
54 changes: 45 additions & 9 deletions test/SIL/Parser/opaque_values_parse.sil
Original file line number Diff line number Diff line change
@@ -1,9 +1,54 @@
// RUN: %target-sil-opt -enable-sil-opaque-values -enable-sil-verify-all -emit-sorted-sil %s | %FileCheck %s

import Builtin
import Swift

sil_stage canonical

protocol Foo {
func foo()
}

struct S : Foo {
func foo()
init()
}

// CHECK-LABEL: sil @castOpaque : $@convention(thin) (Int) -> () {
// CHECK: bb0([[ARG:%.*]] : $Int):
// CHECK: unconditional_checked_cast_opaque [[ARG]] : $Int to $Foo
// CHECK-LABEL: } // end sil function 'castOpaque'
sil @castOpaque : $@convention(thin) (Int) -> () {
bb0(%0 : $Int):
%c = unconditional_checked_cast_opaque %0 : $Int to $Foo
%t = tuple ()
return %t : $()
}

// CHECK-LABEL: sil @initDeinitExistentialOpaque : $@convention(thin) <T> (@in T) -> () {
// CHECK: bb0([[ARG:%.*]] : $T):
// CHECK: [[IE:%.*]] = init_existential_opaque [[ARG]] : $T, $T, $Any
// CHECK: deinit_existential_opaque [[IE]] : $Any
// CHECK-LABEL: } // end sil function 'initDeinitExistentialOpaque'
sil @initDeinitExistentialOpaque : $@convention(thin) <T> (@in T) -> () {
bb0(%0 : $T):
%i = init_existential_opaque %0 : $T, $T, $Any
%d = deinit_existential_opaque %i : $Any
%t = tuple ()
return %t : $()
}

// CHECK-LABEL: sil @openExistentialOpaque : $@convention(thin) (@in Foo) -> () {
// CHECK: bb0([[ARG:%.*]] : $Foo):
// CHECK: open_existential_opaque [[ARG]] : $Foo to $@opened("2E9EACA6-FD59-11E6-B016-685B3593C496") Foo
// CHECK-LABEL: } // end sil function 'openExistentialOpaque'
sil @openExistentialOpaque : $@convention(thin) (@in Foo) -> () {
bb0(%0 : $Foo):
%o = open_existential_opaque %0 : $Foo to $@opened("2E9EACA6-FD59-11E6-B016-685B3593C496") Foo
%t = tuple ()
return %t : $()
}

// Test @callee_guaranteed parsing.
// ----

Expand Down Expand Up @@ -38,15 +83,6 @@ bb0(%0 : $T):
// Test @in_guaranteed parsing.
// ----

protocol Foo {
func foo()
}

struct S : Foo {
func foo()
init()
}

sil @doWithS : $@convention(method) (S) -> ()

// CHECK-LABEL: sil hidden [transparent] [thunk] @parse_mutating : $@convention(witness_method) (@in_guaranteed S) -> () {
Expand Down
54 changes: 45 additions & 9 deletions test/SIL/Serialization/opaque_values_serialize.sil
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,51 @@
sil_stage canonical

import Builtin
import Swift

protocol Foo {
func foo()
}

struct S : Foo {
func foo()
init()
}

// CHECK-LABEL: sil @castOpaque : $@convention(thin) (Int) -> () {
// CHECK: bb0([[ARG:%.*]] : $Int):
// CHECK: unconditional_checked_cast_opaque [[ARG]] : $Int to $Foo
// CHECK-LABEL: } // end sil function 'castOpaque'
sil @castOpaque : $@convention(thin) (Int) -> () {
bb0(%0 : $Int):
%c = unconditional_checked_cast_opaque %0 : $Int to $Foo
%t = tuple ()
return %t : $()
}

// CHECK-LABEL: sil @initDeinitExistentialOpaque : $@convention(thin) <T> (@in T) -> () {
// CHECK: bb0([[ARG:%.*]] : $T):
// CHECK: [[IE:%.*]] = init_existential_opaque [[ARG]] : $T, $T, $Any
// CHECK: deinit_existential_opaque [[IE]] : $Any
// CHECK-LABEL: } // end sil function 'initDeinitExistentialOpaque'
sil @initDeinitExistentialOpaque : $@convention(thin) <T> (@in T) -> () {
bb0(%0 : $T):
%i = init_existential_opaque %0 : $T, $T, $Any
%d = deinit_existential_opaque %i : $Any
%t = tuple ()
return %t : $()
}

// CHECK-LABEL: sil @openExistentialOpaque : $@convention(thin) (@in Foo) -> () {
// CHECK: bb0([[ARG:%.*]] : $Foo):
// CHECK: open_existential_opaque [[ARG]] : $Foo to $@opened({{.*}}) Foo
// CHECK-LABEL: } // end sil function 'openExistentialOpaque'
sil @openExistentialOpaque : $@convention(thin) (@in Foo) -> () {
bb0(%0 : $Foo):
%o = open_existential_opaque %0 : $Foo to $@opened("2E9EACA6-FD59-11E6-B016-685B3593C496") Foo
%t = tuple ()
return %t : $()
}

// Test @in/@out serialization.
// ----
Expand All @@ -25,15 +70,6 @@ bb0(%0 : $T):
// Test @in_guaranteed serialization.
// ----

protocol Foo {
func foo()
}

struct S : Foo {
func foo()
init()
}

sil @doWithS : $@convention(method) (S) -> ()

// CHECK-LABEL: sil hidden [transparent] [thunk] @serialize_mutating : $@convention(witness_method) (@in_guaranteed S) -> () {
Expand Down