@@ -31,25 +31,101 @@ func conversions(
31
31
derivedAndRType: ( Derived & R ) . Type) {
32
32
33
33
// 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
34
41
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
35
52
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
36
63
let _: Q = baseAndP
37
64
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
38
71
let _: Base < Int > & P = derivedAndR
39
72
40
73
// 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
41
77
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
42
81
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
43
85
let _: Q . Type = baseAndPType
44
86
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
45
92
let _: ( Base < Int > & P ) . Type = derivedAndRType
93
+
94
+ // CHECK: return
46
95
}
47
96
97
+ // CHECK-LABEL: sil hidden @_T021subclass_existentials11methodCallsyAA1P_AA4BaseCySiGXc8baseAndP_AaC_AFXcXp0fG5PTypetF : $@convention(thin) (@owned Base<Int> & P, @thick (Base<Int> & P).Type) -> () {
98
+
48
99
func methodCalls(
49
100
baseAndP: Base < Int > & P ,
50
101
baseAndPType: ( Base < Int > & P ) . Type) {
51
102
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
52
114
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
53
129
let _: Base < Int > & P = baseAndP. protocolSelfReturn ( )
54
130
55
131
let _: Base < Int > & P = baseAndPType. classSelfReturn ( )
@@ -63,6 +139,8 @@ func methodCalls(
63
139
let _: ( ) -> ( Base < Int > & P ) = baseAndPType. protocolSelfReturn
64
140
}
65
141
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
+
66
144
func functionConversions(
67
145
returnsBaseAndP: @escaping ( ) -> ( Base < Int > & P ) ,
68
146
returnsBaseAndPType: @escaping ( ) -> ( Base < Int > & P ) . Type,
0 commit comments