@@ -67,3 +67,56 @@ entry(%0 : $*T, %1 : $*U, %2 : $Int):
67
67
%k = partial_apply %f<U>(%b) : $@convention(thin) <V> (@in V, <τ_0_0> { var τ_0_0 } <Int>) -> Int
68
68
return %k : $@callee_owned (@in U) -> Int
69
69
}
70
+
71
+ enum E<X> {
72
+ case None
73
+ case Some(X)
74
+ }
75
+
76
+ struct R<T> {
77
+ }
78
+
79
+ // Check that the capture promotion took place and the function now
80
+ // take argument of a type E<(R<T>) -> Builtin.Int32>, which used
81
+ // to be a slot inside a box.
82
+ // CHECK-LABEL: sil @_T023generic_promotable_box2Tf2nni_n : $@convention(thin) <T> (@in R<T>, @in Builtin.Int32, @owned E<(R<T>) -> Builtin.Int32>) -> ()
83
+ // CHECK: bb0(%0 : $*R<T>, %1 : $*Builtin.Int32, %2 : $E<(R<T>) -> Builtin.Int32>):
84
+ // CHECK-NOT: project_box
85
+ // CHECK: switch_enum %2 : $E<(R<T>) -> Builtin.Int32>
86
+ // CHECK-NOT: project_box
87
+ // CHECK: } // end sil function '_T023generic_promotable_box2Tf2nni_n'
88
+ sil @generic_promotable_box2 : $@convention(thin) <T> (@in R<T>, @in Int, <τ_0_0> { var E<(R<τ_0_0>) -> Int> } <T>) -> () {
89
+ entry(%0: $*R<T>, %1 : $*Int, %b : $<τ_0_0> { var E< (R<τ_0_0>)->Int > } <T>):
90
+ %a = project_box %b : $<τ_0_0> { var E<(R<τ_0_0>)->Int> } <T>, 0
91
+ %e = load %a : $*E<(R<T>)->Int>
92
+ switch_enum %e : $E<(R<T>)->Int>, case #E.Some!enumelt.1 : bb1, default bb2
93
+ bb1(%f : $@callee_owned (@in R<T>) -> @out Int):
94
+ %t = tuple ()
95
+ apply %f(%1, %0) : $@callee_owned (@in R<T>) -> @out Int
96
+ br exit
97
+ bb2:
98
+ br exit
99
+ exit:
100
+ %r = tuple ()
101
+ return %r : $()
102
+ }
103
+
104
+ // Check that alloc_box was eliminated and a specialized version of the
105
+ // closure is invoked.
106
+ // CHECK-LABEL: sil @call_generic_promotable_box_from_different_generic2
107
+ // CHECK: bb0(%0 : $*R<T>, %1 : $*E<(R<U>) -> Builtin.Int32>, %2 : $*Builtin.Int32):
108
+ // CHECK: %3 = load %1 : $*E<(R<U>) -> Builtin.Int32>
109
+ // CHECK: [[F:%.*]] = function_ref @_T023generic_promotable_box2Tf2nni_n : $@convention(thin) <τ_0_0> (@in R<τ_0_0>, @in Builtin.Int32, @owned E<(R<τ_0_0>) -> Builtin.Int32>) -> ()
110
+ // CHECK-NEXT: [[CLOSURE:%.*]] = partial_apply [[F]]<U>(%2, %3)
111
+ // CHECK-NEXT: return [[CLOSURE]]
112
+
113
+ sil @call_generic_promotable_box_from_different_generic2 : $@convention(thin) <T, U: P> (@in R<T>, @in E<(R<U>)->Int>, @in Int) -> @owned @callee_owned (@in R<U>) -> () {
114
+ entry(%0 : $*R<T>, %1 : $*E<(R<U>)->Int>, %2 : $*Int):
115
+ destroy_addr %0 : $*R<T>
116
+ %f = function_ref @generic_promotable_box2 : $@convention(thin) <V> (@in R<V>, @in Int, <τ_0_0> { var E<(R<τ_0_0>)->Int> } <V>) -> ()
117
+ %b = alloc_box $<τ_0_0> { var E<(R<τ_0_0>)->Int> } <U>
118
+ %a = project_box %b : $<τ_0_0> { var E<(R<τ_0_0>)->Int> } <U>, 0
119
+ copy_addr [take] %1 to [initialization] %a : $*E<(R<U>)->Int>
120
+ %k = partial_apply %f<U>(%2, %b) : $@convention(thin) <V> (@in R<V>, @in Int, <τ_0_0> { var E<(R<τ_0_0>)->Int> } <V>) -> ()
121
+ return %k : $@callee_owned (@in R<U>) -> ()
122
+ }
0 commit comments