Skip to content

SILGen: Add missing processing to reabstraction fast-path. #41549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions lib/SILGen/SILGenApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ SubstitutionMap SILGenModule::mapSubstitutionsForWitnessOverride(
/// Return the abstraction pattern to use when calling a function value.
static AbstractionPattern
getIndirectApplyAbstractionPattern(SILGenFunction &SGF,
AbstractionPattern pattern,
CanFunctionType fnType) {
assert(fnType);
AbstractionPattern pattern(fnType);
switch (fnType->getRepresentation()) {
case FunctionTypeRepresentation::Swift:
case FunctionTypeRepresentation::Thin:
Expand Down Expand Up @@ -875,9 +875,9 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {

ManagedValue fn = SGF.emitRValueAsSingleValue(e);
auto substType = cast<FunctionType>(e->getType()->getCanonicalType());

auto origType = AbstractionPattern(substType);
// When calling an C or block function, there's implicit bridging.
auto origType = getIndirectApplyAbstractionPattern(SGF, substType);
origType = getIndirectApplyAbstractionPattern(SGF, origType, substType);

setCallee(Callee::forIndirect(fn, origType, substType, e));
}
Expand Down Expand Up @@ -1171,10 +1171,6 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
}

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

// Any writebacks for this access are tightly scoped.
Expand All @@ -1186,9 +1182,12 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {

ManagedValue fn = SGF.emitLoadOfLValue(e, std::move(lv), SGFContext())
.getAsSingleValue(SGF, e);

setCallee(Callee::forIndirect(fn, lv.getOrigFormalType(),
cast<FunctionType>(lv.getSubstFormalType()), e));
auto substType = cast<FunctionType>(lv.getSubstFormalType());
auto origType = lv.getOrigFormalType();
// When calling an C or block function, there's implicit bridging.
origType = getIndirectApplyAbstractionPattern(SGF, origType, substType);

setCallee(Callee::forIndirect(fn, origType, substType, e));
}

void visitAbstractClosureExpr(AbstractClosureExpr *e) {
Expand Down
12 changes: 12 additions & 0 deletions test/SILGen/call_convention_c_closure_with_bridged_arg.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -emit-silgen -verify %s
// REQUIRES: objc_interop

import Foundation

struct Wrapper {
let closure: @convention(c) ([Int]) -> Void

func callIt() {
self.closure([])
}
}