Skip to content

Commit 0af7f01

Browse files
committed
SILGen: More detailed subclass existentials tests
1 parent 0d0dc20 commit 0af7f01

File tree

1 file changed

+78
-0
lines changed

1 file changed

+78
-0
lines changed

test/SILGen/subclass_existentials.swift

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,101 @@ func conversions(
3131
derivedAndRType: (Derived & R).Type) {
3232

3333
// Values
34+
35+
// CHECK: [[BORROWED:%.*]] = begin_borrow %0 : $Base<Int> & P
36+
// CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[BORROWED]] : $Base<Int> & P
37+
// CHECK: [[REF:%.*]] = copy_value [[PAYLOAD]]
38+
// CHECK: [[BASE:%.*]] = upcast [[REF]] : $@opened("{{.*}}") Base<Int> & P to $Base<Int>
39+
// CHECK: destroy_value [[BASE]] : $Base<Int>
40+
// CHECK: end_borrow [[BORROWED]] from %0 : $Base<Int> & P
3441
let _: Base<Int> = baseAndP
42+
43+
// CHECK: [[BORROW:%.*]] = begin_borrow %0 : $Base<Int> & P
44+
// CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[BORROW]] : $Base<Int> & P
45+
// CHECK: [[RESULT:%.*]] = alloc_stack $P
46+
// CHECK: [[RESULT_PAYLOAD:%.*]] = init_existential_addr [[RESULT]] : $*P, $@opened("{{.*}}") Base<Int> & P
47+
// CHECK: [[REF:%.*]] = copy_value [[PAYLOAD]]
48+
// CHECK: store [[REF]] to [init] [[RESULT_PAYLOAD]]
49+
// CHECK: destroy_addr [[RESULT]] : $*P
50+
// CHECK: dealloc_stack [[RESULT]] : $*P
51+
// CHECK: end_borrow [[BORROW]] from %0 : $Base<Int> & P
3552
let _: P = baseAndP
53+
54+
// CHECK: [[BORROW:%.*]] = begin_borrow %0 : $Base<Int> & P
55+
// CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[BORROW]] : $Base<Int> & P
56+
// CHECK: [[RESULT:%.*]] = alloc_stack $Q
57+
// CHECK: [[RESULT_PAYLOAD:%.*]] = init_existential_addr [[RESULT]] : $*Q, $@opened("{{.*}}") Base<Int> & P
58+
// CHECK: [[REF:%.*]] = copy_value [[PAYLOAD]]
59+
// CHECK: store [[REF]] to [init] [[RESULT_PAYLOAD]]
60+
// CHECK: destroy_addr [[RESULT]] : $*Q
61+
// CHECK: dealloc_stack [[RESULT]] : $*Q
62+
// CHECK: end_borrow [[BORROW]] from %0 : $Base<Int> & P
3663
let _: Q = baseAndP
3764

65+
// CHECK: [[BORROW:%.*]] = begin_borrow %2 : $Derived & R
66+
// CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[BORROW]] : $Derived & R
67+
// CHECK: [[REF:%.*]] = copy_value [[PAYLOAD]]
68+
// CHECK: [[RESULT:%.*]] = init_existential_ref [[REF]] : $@opened("{{.*}}") Derived & R : $@opened("{{.*}}") Derived & R, $Base<Int> & P
69+
// CHECK: destroy_value [[RESULT]]
70+
// CHECK: end_borrow [[BORROW]] from %2 : $Derived & R
3871
let _: Base<Int> & P = derivedAndR
3972

4073
// Metatypes
74+
75+
// CHECK: [[PAYLOAD:%.*]] = open_existential_metatype %3 : $@thick (Base<Int> & P).Type to $@thick (@opened("{{.*}}") (Base<Int> & P)).Type
76+
// CHECK: [[RESULT:%.*]] = upcast [[PAYLOAD]] : $@thick (@opened("{{.*}}") (Base<Int> & P)).Type to $@thick Base<Int>.Type
4177
let _: Base<Int>.Type = baseAndPType
78+
79+
// CHECK: [[PAYLOAD:%.*]] = open_existential_metatype %3 : $@thick (Base<Int> & P).Type to $@thick (@opened("{{.*}}") (Base<Int> & P)).Type
80+
// CHECK: [[RESULT:%.*]] = init_existential_metatype [[PAYLOAD]] : $@thick (@opened("{{.*}}") (Base<Int> & P)).Type, $@thick P.Type
4281
let _: P.Type = baseAndPType
82+
83+
// CHECK: [[PAYLOAD:%.*]] = open_existential_metatype %3 : $@thick (Base<Int> & P).Type to $@thick (@opened("{{.*}}") (Base<Int> & P)).Type
84+
// CHECK: [[RESULT:%.*]] = init_existential_metatype [[PAYLOAD]] : $@thick (@opened("{{.*}}") (Base<Int> & P)).Type, $@thick Q.Type
4385
let _: Q.Type = baseAndPType
4486

87+
// CHECK: [[RESULT:%.*]] = init_existential_metatype %4 : $@thick Derived.Type, $@thick (Base<Int> & P).Type
88+
let _: (Base<Int> & P).Type = derivedType
89+
90+
// CHECK: [[PAYLOAD:%.*]] = open_existential_metatype %5 : $@thick (Derived & R).Type to $@thick (@opened("{{.*}}") (Derived & R)).Type
91+
// CHECK: [[RESULT:%.*]] = init_existential_metatype [[PAYLOAD]] : $@thick (@opened("{{.*}}") (Derived & R)).Type, $@thick (Base<Int> & P).Type
4592
let _: (Base<Int> & P).Type = derivedAndRType
93+
94+
// CHECK: return
4695
}
4796

97+
// CHECK-LABEL: sil hidden @_T021subclass_existentials11methodCallsyAA1P_AA4BaseCySiGXc8baseAndP_AaC_AFXcXp0fG5PTypetF : $@convention(thin) (@owned Base<Int> & P, @thick (Base<Int> & P).Type) -> () {
98+
4899
func methodCalls(
49100
baseAndP: Base<Int> & P,
50101
baseAndPType: (Base<Int> & P).Type) {
51102

103+
// CHECK: [[BORROW:%.*]] = begin_borrow %0 : $Base<Int> & P
104+
// CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[BORROW]] : $Base<Int> & P to $@opened("{{.*}}") Base<Int> & P
105+
// CHECK: [[REF:%.*]] = copy_value [[PAYLOAD]] : $@opened("{{.*}}") Base<Int> & P
106+
// CHECK: [[CLASS_REF:%.*]] = upcast [[REF]] : $@opened("{{.*}}") Base<Int> & P to $Base<Int>
107+
// CHECK: [[METHOD:%.*]] = class_method [[CLASS_REF]] : $Base<Int>, #Base.classSelfReturn!1 : <T> (Base<T>) -> () -> @dynamic_self Base<T>, $@convention(method) <τ_0_0> (@guaranteed Base<τ_0_0>) -> @owned Base<τ_0_0>
108+
// CHECK: [[RESULT_CLASS_REF:%.*]] = apply [[METHOD]]<Int>([[CLASS_REF]]) : $@convention(method) <τ_0_0> (@guaranteed Base<τ_0_0>) -> @owned Base<τ_0_0>
109+
// CHECK: destroy_value [[CLASS_REF]] : $Base<Int>
110+
// CHECK: [[RESULT_REF:%.*]] = unchecked_ref_cast [[RESULT_CLASS_REF]] : $Base<Int> to $@opened("{{.*}}") Base<Int> & P
111+
// CHECK: [[RESULT:%.*]] = init_existential_ref [[RESULT_REF]] : $@opened("{{.*}}") Base<Int> & P : $@opened("{{.*}}") Base<Int> & P, $Base<Int> & P
112+
// CHECK: destroy_value [[RESULT]] : $Base<Int> & P
113+
// CHECK: end_borrow [[BORROW]] from %0 : $Base<Int> & P
52114
let _: Base<Int> & P = baseAndP.classSelfReturn()
115+
116+
// CHECK: [[BORROW:%.*]] = begin_borrow %0 : $Base<Int> & P
117+
// CHECK: [[PAYLOAD:%.*]] = open_existential_ref [[BORROW]] : $Base<Int> & P to $@opened("{{.*}}") Base<Int> & P
118+
// CHECK: [[SELF_BOX:%.*]] = alloc_stack $@opened("{{.*}}") Base<Int> & P
119+
// CHECK: store [[PAYLOAD]] to [init] [[SELF_BOX]] : $*@opened("{{.*}}") Base<Int> & P
120+
// CHECK: [[METHOD:%.*]] = witness_method $@opened("{{.*}}") Base<Int> & P, #P.protocolSelfReturn!1 : <Self where Self : P> (Self) -> () -> @dynamic_self Self, %16 : $@opened("{{.*}}") Base<Int> & P : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @out τ_0_0
121+
// CHECK: [[RESULT_BOX:%.*]] = alloc_stack $@opened("{{.*}}") Base<Int> & P
122+
// CHECK: apply [[METHOD]]<@opened("{{.*}}") Base<Int> & P>([[RESULT_BOX]], [[SELF_BOX]]) : $@convention(witness_method) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> @out τ_0_0
123+
// CHECK: [[RESULT_REF:%.*]] = load [take] %20 : $*@opened("{{.*}}") Base<Int> & P
124+
// CHECK: [[RESULT:%.*]] = init_existential_ref [[RESULT_REF]] : $@opened("{{.*}}") Base<Int> & P : $@opened("{{.*}}") Base<Int> & P, $Base<Int> & P
125+
// CHECK: destroy_value [[RESULT]] : $Base<Int> & P
126+
// CHECK: dealloc_stack [[RESULT_BOX]] : $*@opened("{{.*}}") Base<Int> & P
127+
// CHECK: dealloc_stack [[SELF_BOX]] : $*@opened("{{.*}}") Base<Int> & P
128+
// CHECK: end_borrow [[BORROW]] from %0 : $Base<Int> & P
53129
let _: Base<Int> & P = baseAndP.protocolSelfReturn()
54130

55131
let _: Base<Int> & P = baseAndPType.classSelfReturn()
@@ -63,6 +139,8 @@ func methodCalls(
63139
let _: () -> (Base<Int> & P) = baseAndPType.protocolSelfReturn
64140
}
65141

142+
// CHECK-LABEL: sil hidden @_T021subclass_existentials19functionConversionsyAA1P_AA4BaseCySiGXcyc07returnsE4AndP_AaC_AFXcXpyc0feG5PTypeAA7DerivedCyc0fI0AJmyc0fI4TypeAA1R_AJXcyc0fiG1RAaM_AJXcXpyc0fiG5RTypetF : $@convention(thin) (@owned @callee_owned () -> @owned Base<Int> & P, @owned @callee_owned () -> @thick (Base<Int> & P).Type, @owned @callee_owned () -> @owned Derived, @owned @callee_owned () -> @thick Derived.Type, @owned @callee_owned () -> @owned Derived & R, @owned @callee_owned () -> @thick (Derived & R).Type) -> () {
143+
66144
func functionConversions(
67145
returnsBaseAndP: @escaping () -> (Base<Int> & P),
68146
returnsBaseAndPType: @escaping () -> (Base<Int> & P).Type,

0 commit comments

Comments
 (0)