Skip to content

Commit fb178c6

Browse files
authored
Merge pull request #41549 from jckarter/disable-reabstraction-opt-for-foreign-convention
SILGen: Add missing processing to reabstraction fast-path.
2 parents 02cd873 + 7c9f13a commit fb178c6

File tree

2 files changed

+21
-10
lines changed

2 files changed

+21
-10
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,9 @@ SubstitutionMap SILGenModule::mapSubstitutionsForWitnessOverride(
6868
/// Return the abstraction pattern to use when calling a function value.
6969
static AbstractionPattern
7070
getIndirectApplyAbstractionPattern(SILGenFunction &SGF,
71+
AbstractionPattern pattern,
7172
CanFunctionType fnType) {
7273
assert(fnType);
73-
AbstractionPattern pattern(fnType);
7474
switch (fnType->getRepresentation()) {
7575
case FunctionTypeRepresentation::Swift:
7676
case FunctionTypeRepresentation::Thin:
@@ -875,9 +875,9 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
875875

876876
ManagedValue fn = SGF.emitRValueAsSingleValue(e);
877877
auto substType = cast<FunctionType>(e->getType()->getCanonicalType());
878-
878+
auto origType = AbstractionPattern(substType);
879879
// When calling an C or block function, there's implicit bridging.
880-
auto origType = getIndirectApplyAbstractionPattern(SGF, substType);
880+
origType = getIndirectApplyAbstractionPattern(SGF, origType, substType);
881881

882882
setCallee(Callee::forIndirect(fn, origType, substType, e));
883883
}
@@ -1182,10 +1182,6 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
11821182
}
11831183

11841184
void visitMemberRefExpr(MemberRefExpr *e) {
1185-
// If we're loading a closure-type property out of a generic aggregate,
1186-
// we might reabstract it under normal circumstances, but since we're
1187-
// going to apply it immediately here, there's no reason to. We can
1188-
// invoke the function value at whatever abstraction level we get.
11891185
assert(isa<VarDecl>(e->getMember().getDecl()));
11901186

11911187
// Any writebacks for this access are tightly scoped.
@@ -1197,9 +1193,12 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
11971193

11981194
ManagedValue fn = SGF.emitLoadOfLValue(e, std::move(lv), SGFContext())
11991195
.getAsSingleValue(SGF, e);
1200-
1201-
setCallee(Callee::forIndirect(fn, lv.getOrigFormalType(),
1202-
cast<FunctionType>(lv.getSubstFormalType()), e));
1196+
auto substType = cast<FunctionType>(lv.getSubstFormalType());
1197+
auto origType = lv.getOrigFormalType();
1198+
// When calling an C or block function, there's implicit bridging.
1199+
origType = getIndirectApplyAbstractionPattern(SGF, origType, substType);
1200+
1201+
setCallee(Callee::forIndirect(fn, origType, substType, e));
12031202
}
12041203

12051204
void visitAbstractClosureExpr(AbstractClosureExpr *e) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-silgen -verify %s
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
struct Wrapper {
7+
let closure: @convention(c) ([Int]) -> Void
8+
9+
func callIt() {
10+
self.closure([])
11+
}
12+
}

0 commit comments

Comments
 (0)