Skip to content

Commit ff967c7

Browse files
author
Joe Shajrawi
authored
Merge pull request #7802 from shajrawi/parse_serializ_opaque
Add Parsing and Serialization test-cases for new Opaque Value Instructions
2 parents 305272a + f0ddf0f commit ff967c7

File tree

5 files changed

+96
-20
lines changed

5 files changed

+96
-20
lines changed

lib/Parse/ParseSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3764,7 +3764,7 @@ bool SILParser::parseSILInstruction(SILBasicBlock *BB, SILBuilder &B) {
37643764
SourceLoc TyLoc;
37653765

37663766
if (parseTypedValueRef(Val, B) ||
3767-
P.parseToken(tok::colon, diag::expected_tok_in_sil_instr, ":") ||
3767+
P.parseToken(tok::comma, diag::expected_tok_in_sil_instr, ",") ||
37683768
P.parseToken(tok::sil_dollar, diag::expected_tok_in_sil_instr, "$") ||
37693769
parseASTType(FormalConcreteTy, TyLoc) ||
37703770
P.parseToken(tok::comma, diag::expected_tok_in_sil_instr, ",") ||

lib/Serialization/DeserializeSIL.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -982,6 +982,10 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn, SILBasicBlock *BB,
982982
Ty,
983983
ctxConformances);
984984
break;
985+
case ValueKind::InitExistentialOpaqueInst:
986+
ResultVal = Builder.createInitExistentialOpaque(Loc, Ty, ConcreteTy,
987+
operand, ctxConformances);
988+
break;
985989
case ValueKind::InitExistentialMetatypeInst:
986990
ResultVal = Builder.createInitExistentialMetatype(Loc, operand, Ty,
987991
ctxConformances);

lib/Serialization/SerializeSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
581581
break;
582582
}
583583
case ValueKind::InitExistentialOpaqueInst: {
584-
auto &IEOI = cast<InitExistentialRefInst>(SI);
584+
auto &IEOI = cast<InitExistentialOpaqueInst>(SI);
585585
operand = IEOI.getOperand();
586586
Ty = IEOI.getType();
587587
FormalConcreteType = IEOI.getFormalConcreteType();

test/SIL/Parser/opaque_values_parse.sil

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,54 @@
11
// RUN: %target-sil-opt -enable-sil-opaque-values -enable-sil-verify-all -emit-sorted-sil %s | %FileCheck %s
22

33
import Builtin
4+
import Swift
45

56
sil_stage canonical
67

8+
protocol Foo {
9+
func foo()
10+
}
11+
12+
struct S : Foo {
13+
func foo()
14+
init()
15+
}
16+
17+
// CHECK-LABEL: sil @castOpaque : $@convention(thin) (Int) -> () {
18+
// CHECK: bb0([[ARG:%.*]] : $Int):
19+
// CHECK: unconditional_checked_cast_opaque [[ARG]] : $Int to $Foo
20+
// CHECK-LABEL: } // end sil function 'castOpaque'
21+
sil @castOpaque : $@convention(thin) (Int) -> () {
22+
bb0(%0 : $Int):
23+
%c = unconditional_checked_cast_opaque %0 : $Int to $Foo
24+
%t = tuple ()
25+
return %t : $()
26+
}
27+
28+
// CHECK-LABEL: sil @initDeinitExistentialOpaque : $@convention(thin) <T> (@in T) -> () {
29+
// CHECK: bb0([[ARG:%.*]] : $T):
30+
// CHECK: [[IE:%.*]] = init_existential_opaque [[ARG]] : $T, $T, $Any
31+
// CHECK: deinit_existential_opaque [[IE]] : $Any
32+
// CHECK-LABEL: } // end sil function 'initDeinitExistentialOpaque'
33+
sil @initDeinitExistentialOpaque : $@convention(thin) <T> (@in T) -> () {
34+
bb0(%0 : $T):
35+
%i = init_existential_opaque %0 : $T, $T, $Any
36+
%d = deinit_existential_opaque %i : $Any
37+
%t = tuple ()
38+
return %t : $()
39+
}
40+
41+
// CHECK-LABEL: sil @openExistentialOpaque : $@convention(thin) (@in Foo) -> () {
42+
// CHECK: bb0([[ARG:%.*]] : $Foo):
43+
// CHECK: open_existential_opaque [[ARG]] : $Foo to $@opened("2E9EACA6-FD59-11E6-B016-685B3593C496") Foo
44+
// CHECK-LABEL: } // end sil function 'openExistentialOpaque'
45+
sil @openExistentialOpaque : $@convention(thin) (@in Foo) -> () {
46+
bb0(%0 : $Foo):
47+
%o = open_existential_opaque %0 : $Foo to $@opened("2E9EACA6-FD59-11E6-B016-685B3593C496") Foo
48+
%t = tuple ()
49+
return %t : $()
50+
}
51+
752
// Test @callee_guaranteed parsing.
853
// ----
954

@@ -38,15 +83,6 @@ bb0(%0 : $T):
3883
// Test @in_guaranteed parsing.
3984
// ----
4085

41-
protocol Foo {
42-
func foo()
43-
}
44-
45-
struct S : Foo {
46-
func foo()
47-
init()
48-
}
49-
5086
sil @doWithS : $@convention(method) (S) -> ()
5187

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

test/SIL/Serialization/opaque_values_serialize.sil

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,51 @@
99
sil_stage canonical
1010

1111
import Builtin
12+
import Swift
13+
14+
protocol Foo {
15+
func foo()
16+
}
17+
18+
struct S : Foo {
19+
func foo()
20+
init()
21+
}
22+
23+
// CHECK-LABEL: sil @castOpaque : $@convention(thin) (Int) -> () {
24+
// CHECK: bb0([[ARG:%.*]] : $Int):
25+
// CHECK: unconditional_checked_cast_opaque [[ARG]] : $Int to $Foo
26+
// CHECK-LABEL: } // end sil function 'castOpaque'
27+
sil @castOpaque : $@convention(thin) (Int) -> () {
28+
bb0(%0 : $Int):
29+
%c = unconditional_checked_cast_opaque %0 : $Int to $Foo
30+
%t = tuple ()
31+
return %t : $()
32+
}
33+
34+
// CHECK-LABEL: sil @initDeinitExistentialOpaque : $@convention(thin) <T> (@in T) -> () {
35+
// CHECK: bb0([[ARG:%.*]] : $T):
36+
// CHECK: [[IE:%.*]] = init_existential_opaque [[ARG]] : $T, $T, $Any
37+
// CHECK: deinit_existential_opaque [[IE]] : $Any
38+
// CHECK-LABEL: } // end sil function 'initDeinitExistentialOpaque'
39+
sil @initDeinitExistentialOpaque : $@convention(thin) <T> (@in T) -> () {
40+
bb0(%0 : $T):
41+
%i = init_existential_opaque %0 : $T, $T, $Any
42+
%d = deinit_existential_opaque %i : $Any
43+
%t = tuple ()
44+
return %t : $()
45+
}
46+
47+
// CHECK-LABEL: sil @openExistentialOpaque : $@convention(thin) (@in Foo) -> () {
48+
// CHECK: bb0([[ARG:%.*]] : $Foo):
49+
// CHECK: open_existential_opaque [[ARG]] : $Foo to $@opened({{.*}}) Foo
50+
// CHECK-LABEL: } // end sil function 'openExistentialOpaque'
51+
sil @openExistentialOpaque : $@convention(thin) (@in Foo) -> () {
52+
bb0(%0 : $Foo):
53+
%o = open_existential_opaque %0 : $Foo to $@opened("2E9EACA6-FD59-11E6-B016-685B3593C496") Foo
54+
%t = tuple ()
55+
return %t : $()
56+
}
1257

1358
// Test @in/@out serialization.
1459
// ----
@@ -25,15 +70,6 @@ bb0(%0 : $T):
2570
// Test @in_guaranteed serialization.
2671
// ----
2772

28-
protocol Foo {
29-
func foo()
30-
}
31-
32-
struct S : Foo {
33-
func foo()
34-
init()
35-
}
36-
3773
sil @doWithS : $@convention(method) (S) -> ()
3874

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

0 commit comments

Comments
 (0)