Skip to content

Commit 436e551

Browse files
author
ematejska
authored
Merge pull request #5465 from jckarter/capture-promotion-bug-3.0
[3.0] CapturePromotion: Substitute using callee generic signature instead of caller's.
2 parents 95fcf73 + efc946b commit 436e551

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

lib/SILOptimizer/IPO/CapturePromotion.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,8 @@ constructClonedFunction(PartialApplyInst *PAI, FunctionRefInst *FRI,
864864
TypeSubstitutionMap ContextSubs;
865865

866866
ArrayRef<Substitution> ApplySubs = PAI->getSubstitutions();
867-
auto genericSig = F->getLoweredFunctionType()->getGenericSignature();
868-
auto *genericParams = F->getContextGenericParams();
867+
auto genericSig = PAI->getOrigCalleeType()->getGenericSignature();
868+
auto *genericParams = FRI->getReferencedFunction()->getContextGenericParams();
869869

870870
if (!ApplySubs.empty()) {
871871
InterfaceSubs = genericSig->getSubstitutionMap(ApplySubs);
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// RUN: %target-swift-frontend -emit-sil -O %s | %FileCheck %s
2+
3+
sil_stage raw
4+
5+
import Builtin
6+
7+
typealias Int = Builtin.Int32
8+
9+
// CHECK-LABEL: sil @_TTSf2i__promotable_box : $@convention(thin) (Builtin.Int32) -> Builtin.Int32
10+
11+
sil @promotable_box : $@convention(thin) (@box Int) -> Int {
12+
entry(%b : $@box Int):
13+
%a = project_box %b : $@box Int
14+
%v = load %a : $*Int
15+
return %v : $Int
16+
}
17+
18+
// CHECK-LABEL: sil @call_promotable_box_from_generic
19+
// CHECK: [[F:%.*]] = function_ref @_TTSf2i__promotable_box
20+
// CHECK: partial_apply [[F]](
21+
22+
sil @call_promotable_box_from_generic : $@convention(thin) <T> (@in T, Int) -> @owned @callee_owned () -> Int {
23+
entry(%0 : $*T, %1 : $Int):
24+
destroy_addr %0 : $*T
25+
%f = function_ref @promotable_box : $@convention(thin) (@box Int) -> Int
26+
%b = alloc_box $Int
27+
%a = project_box %b : $@box Int
28+
store %1 to %a : $*Int
29+
%k = partial_apply %f(%b) : $@convention(thin) (@box Int) -> Int
30+
return %k : $@callee_owned () -> Int
31+
}
32+
33+
protocol P {}
34+
35+
sil @generic_promotable_box : $@convention(thin) <T> (@in T, @box Int) -> Int {
36+
entry(%0 : $*T, %b : $@box Int):
37+
%a = project_box %b : $@box Int
38+
%v = load %a : $*Int
39+
return %v : $Int
40+
}
41+
42+
sil @call_generic_promotable_box_from_different_generic : $@convention(thin) <T, U: P> (@in T, @in U, Int) -> @owned @callee_owned (@in U) -> Int {
43+
entry(%0 : $*T, %1 : $*U, %2 : $Int):
44+
destroy_addr %0 : $*T
45+
destroy_addr %1 : $*U
46+
%f = function_ref @generic_promotable_box : $@convention(thin) <V> (@in V, @box Int) -> Int
47+
%b = alloc_box $Int
48+
%a = project_box %b : $@box Int
49+
store %2 to %a : $*Int
50+
%k = partial_apply %f<U>(%b) : $@convention(thin) <V> (@in V, @box Int) -> Int
51+
return %k : $@callee_owned (@in U) -> Int
52+
}

0 commit comments

Comments
 (0)