Skip to content

Commit 5fd8e71

Browse files
committed
SILGen: More dynamic method call cleanup
1 parent b3b438b commit 5fd8e71

File tree

1 file changed

+12
-34
lines changed

1 file changed

+12
-34
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 12 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -104,23 +104,15 @@ getPartialApplyOfDynamicMethodFormalType(SILGenModule &SGM, SILDeclRef member,
104104
}
105105

106106
/// Retrieve the type to use for a method found via dynamic lookup.
107-
static CanSILFunctionType
108-
getDynamicMethodLoweredType(SILGenFunction &SGF, SILValue v,
109-
SILDeclRef methodName,
107+
static SILType
108+
getDynamicMethodLoweredType(SILModule &M,
109+
SILDeclRef constant,
110110
CanAnyFunctionType substMemberTy) {
111-
auto &ctx = SGF.getASTContext();
112-
CanType selfTy = v->getType().getSwiftRValueType();
113-
assert((!methodName.getDecl()->isInstanceMember() ||
114-
selfTy->is<ArchetypeType>()) &&
115-
"Dynamic lookup needs an archetype");
116-
117-
// Replace the 'self' parameter type in the method type with it.
111+
assert(constant.isForeign);
118112
auto objcFormalTy = substMemberTy.withExtInfo(substMemberTy->getExtInfo()
119113
.withSILRepresentation(SILFunctionTypeRepresentation::ObjCMethod));
120-
121-
auto methodTy = SGF.SGM.M.Types
122-
.getUncachedSILFunctionTypeForConstant(methodName, objcFormalTy);
123-
return methodTy;
114+
return SILType::getPrimitiveObjectType(
115+
M.Types.getUncachedSILFunctionTypeForConstant(constant, objcFormalTy));
124116
}
125117

126118
/// Check if we can perform a dynamic dispatch on a super method call.
@@ -481,19 +473,6 @@ class Callee {
481473
return Constant;
482474
}
483475

484-
SILType getDynamicMethodType(SILModule &M) const {
485-
// Lower the substituted type from the AST, which should have any generic
486-
// parameters in the original signature erased to their upper bounds.
487-
auto substFormalType = getSubstFormalType();
488-
auto objcFormalType = substFormalType.withExtInfo(
489-
substFormalType->getExtInfo().withSILRepresentation(
490-
SILFunctionTypeRepresentation::ObjCMethod));
491-
auto fnType = M.Types.getUncachedSILFunctionTypeForConstant(
492-
Constant, objcFormalType);
493-
494-
return SILType::getPrimitiveObjectType(fnType);
495-
}
496-
497476
ManagedValue getFnValue(SILGenFunction &SGF, bool isCurried,
498477
Optional<ManagedValue> borrowedSelf) const & {
499478
Optional<SILDeclRef> constant = None;
@@ -576,8 +555,8 @@ class Callee {
576555
return ManagedValue::forUnmanaged(fn);
577556
}
578557
case Kind::DynamicMethod: {
579-
assert(constant->isForeign);
580-
auto closureType = getDynamicMethodType(SGF.SGM.M);
558+
auto closureType = getDynamicMethodLoweredType(
559+
SGF.SGM.M, *constant, getSubstFormalType());
581560

582561
Scope S(SGF, Loc);
583562
SILValue fn = SGF.B.createObjCMethod(
@@ -629,7 +608,8 @@ class Callee {
629608
return createCalleeTypeInfo(SGF, constant, constantInfo.getSILType());
630609
}
631610
case Kind::DynamicMethod: {
632-
auto formalType = getDynamicMethodType(SGF.SGM.M);
611+
auto formalType = getDynamicMethodLoweredType(
612+
SGF.SGM.M, *constant, getSubstFormalType());
633613
return createCalleeTypeInfo(SGF, constant, formalType);
634614
}
635615
}
@@ -5561,9 +5541,8 @@ RValue SILGenFunction::emitDynamicMemberRefExpr(DynamicMemberRefExpr *e,
55615541
operand->getType().getSwiftRValueType(),
55625542
memberMethodTy->getCanonicalType());
55635543

5564-
auto dynamicMethodTy = getDynamicMethodLoweredType(*this, operand, member,
5544+
auto loweredMethodTy = getDynamicMethodLoweredType(SGM.M, member,
55655545
memberFnTy);
5566-
auto loweredMethodTy = SILType::getPrimitiveObjectType(dynamicMethodTy);
55675546
SILValue memberArg = hasMemberBB->createPHIArgument(
55685547
loweredMethodTy, ValueOwnershipKind::Owned);
55695548

@@ -5657,9 +5636,8 @@ RValue SILGenFunction::emitDynamicSubscriptExpr(DynamicSubscriptExpr *e,
56575636

56585637
auto functionTy = CanFunctionType::get(base->getType().getSwiftRValueType(),
56595638
methodTy);
5660-
auto dynamicMethodTy = getDynamicMethodLoweredType(*this, base, member,
5639+
auto loweredMethodTy = getDynamicMethodLoweredType(SGM.M, member,
56615640
functionTy);
5662-
auto loweredMethodTy = SILType::getPrimitiveObjectType(dynamicMethodTy);
56635641
SILValue memberArg = hasMemberBB->createPHIArgument(
56645642
loweredMethodTy, ValueOwnershipKind::Owned);
56655643
// Emit the application of 'self'.

0 commit comments

Comments
 (0)