@@ -104,23 +104,15 @@ getPartialApplyOfDynamicMethodFormalType(SILGenModule &SGM, SILDeclRef member,
104
104
}
105
105
106
106
// / 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 ,
110
110
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 );
118
112
auto objcFormalTy = substMemberTy.withExtInfo (substMemberTy->getExtInfo ()
119
113
.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));
124
116
}
125
117
126
118
// / Check if we can perform a dynamic dispatch on a super method call.
@@ -481,19 +473,6 @@ class Callee {
481
473
return Constant;
482
474
}
483
475
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
-
497
476
ManagedValue getFnValue (SILGenFunction &SGF, bool isCurried,
498
477
Optional<ManagedValue> borrowedSelf) const & {
499
478
Optional<SILDeclRef> constant = None;
@@ -576,8 +555,8 @@ class Callee {
576
555
return ManagedValue::forUnmanaged (fn);
577
556
}
578
557
case Kind::DynamicMethod: {
579
- assert (constant-> isForeign );
580
- auto closureType = getDynamicMethodType ( SGF.SGM .M );
558
+ auto closureType = getDynamicMethodLoweredType (
559
+ SGF.SGM .M , *constant, getSubstFormalType () );
581
560
582
561
Scope S (SGF, Loc);
583
562
SILValue fn = SGF.B .createObjCMethod (
@@ -629,7 +608,8 @@ class Callee {
629
608
return createCalleeTypeInfo (SGF, constant, constantInfo.getSILType ());
630
609
}
631
610
case Kind::DynamicMethod: {
632
- auto formalType = getDynamicMethodType (SGF.SGM .M );
611
+ auto formalType = getDynamicMethodLoweredType (
612
+ SGF.SGM .M , *constant, getSubstFormalType ());
633
613
return createCalleeTypeInfo (SGF, constant, formalType);
634
614
}
635
615
}
@@ -5561,9 +5541,8 @@ RValue SILGenFunction::emitDynamicMemberRefExpr(DynamicMemberRefExpr *e,
5561
5541
operand->getType ().getSwiftRValueType (),
5562
5542
memberMethodTy->getCanonicalType ());
5563
5543
5564
- auto dynamicMethodTy = getDynamicMethodLoweredType (* this , operand , member,
5544
+ auto loweredMethodTy = getDynamicMethodLoweredType (SGM. M , member,
5565
5545
memberFnTy);
5566
- auto loweredMethodTy = SILType::getPrimitiveObjectType (dynamicMethodTy);
5567
5546
SILValue memberArg = hasMemberBB->createPHIArgument (
5568
5547
loweredMethodTy, ValueOwnershipKind::Owned);
5569
5548
@@ -5657,9 +5636,8 @@ RValue SILGenFunction::emitDynamicSubscriptExpr(DynamicSubscriptExpr *e,
5657
5636
5658
5637
auto functionTy = CanFunctionType::get (base->getType ().getSwiftRValueType (),
5659
5638
methodTy);
5660
- auto dynamicMethodTy = getDynamicMethodLoweredType (* this , base , member,
5639
+ auto loweredMethodTy = getDynamicMethodLoweredType (SGM. M , member,
5661
5640
functionTy);
5662
- auto loweredMethodTy = SILType::getPrimitiveObjectType (dynamicMethodTy);
5663
5641
SILValue memberArg = hasMemberBB->createPHIArgument (
5664
5642
loweredMethodTy, ValueOwnershipKind::Owned);
5665
5643
// Emit the application of 'self'.
0 commit comments