@@ -1019,6 +1019,12 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1019
1019
if (!ctor->isRequired ())
1020
1020
return false ;
1021
1021
1022
+ // @objc dynamic initializers are statically dispatched (we're
1023
+ // calling the allocating entry point, which is a thunk that
1024
+ // does the dynamic dispatch for us).
1025
+ if (ctor->isObjCDynamic ())
1026
+ return false ;
1027
+
1022
1028
// Required constructors are statically dispatched when the 'self'
1023
1029
// value is statically derived.
1024
1030
ApplyExpr *thisCallSite = callSites.back ();
@@ -1032,64 +1038,32 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1032
1038
}
1033
1039
1034
1040
void processClassMethod (DeclRefExpr *e, AbstractFunctionDecl *afd) {
1035
- SILDeclRef::Kind kind;
1036
- bool requiresAllocRefDynamic = false ;
1037
-
1038
- if (isa<FuncDecl>(afd)) {
1039
- kind = SILDeclRef::Kind::Func;
1040
- } else {
1041
- if (requiresForeignEntryPoint (afd)) {
1042
- // When we're performing Objective-C dispatch, we don't have an
1043
- // allocating constructor to call. So, perform an alloc_ref_dynamic
1044
- // and pass that along to the initializer.
1045
- requiresAllocRefDynamic = true ;
1046
- kind = SILDeclRef::Kind::Initializer;
1047
- } else {
1048
- kind = SILDeclRef::Kind::Allocator;
1049
- }
1050
- }
1051
-
1052
1041
ApplyExpr *thisCallSite = callSites.back ();
1053
1042
callSites.pop_back ();
1054
1043
1055
- // If we require a dynamic allocation of the object here, do so now.
1056
- if (requiresAllocRefDynamic) {
1057
- SILLocation loc = thisCallSite->getArg ();
1058
- RValue selfMetatype = SGF.emitRValue (thisCallSite->getArg ());
1059
- auto selfValue =
1060
- allocateObject (std::move (selfMetatype).getAsSingleValue (SGF, loc),
1061
- loc, /* objc*/ true );
1062
- RValue self = RValue (SGF, loc, selfValue.getType ().getASTType (),
1063
- selfValue);
1064
- ArgumentSource selfArgSource (thisCallSite->getArg (), std::move (self));
1065
- setSelfParam (std::move (selfArgSource), thisCallSite);
1066
- } else {
1067
- ArgumentSource selfArgSource (thisCallSite->getArg ());
1068
- setSelfParam (std::move (selfArgSource), thisCallSite);
1069
- }
1044
+ ArgumentSource selfArgSource (thisCallSite->getArg ());
1045
+ setSelfParam (std::move (selfArgSource), thisCallSite);
1070
1046
1071
1047
// Directly dispatch to calls of the replaced function inside of
1072
1048
// '@_dynamicReplacement(for:)' methods.
1073
1049
bool isObjCReplacementCall = false ;
1074
1050
if (isCallToReplacedInDynamicReplacement (SGF, afd, isObjCReplacementCall) &&
1075
1051
thisCallSite->getArg ()->isSelfExprOf (
1076
1052
cast<AbstractFunctionDecl>(SGF.FunctionDC ->getAsDecl ()), false )) {
1077
- auto constant = SILDeclRef (afd, kind ).asForeign (
1053
+ auto constant = SILDeclRef (afd).asForeign (
1078
1054
!isObjCReplacementCall && requiresForeignEntryPoint (e->getDecl ()));
1079
1055
auto subs = e->getDeclRef ().getSubstitutions ();
1080
1056
if (isObjCReplacementCall)
1081
1057
setCallee (Callee::forDirect (SGF, constant, subs, e));
1082
1058
else
1083
1059
setCallee (Callee::forDirect (
1084
1060
SGF,
1085
- SILDeclRef (cast<AbstractFunctionDecl>(SGF.FunctionDC ->getAsDecl ()),
1086
- kind),
1061
+ SILDeclRef (cast<AbstractFunctionDecl>(SGF.FunctionDC ->getAsDecl ())),
1087
1062
subs, e, true ));
1088
1063
return ;
1089
1064
}
1090
1065
1091
- auto constant = SILDeclRef (afd, kind)
1092
- .asForeign (requiresForeignEntryPoint (afd));
1066
+ auto constant = SILDeclRef (afd).asForeign (requiresForeignEntryPoint (afd));
1093
1067
1094
1068
auto subs = e->getDeclRef ().getSubstitutions ();
1095
1069
setCallee (Callee::forClassMethod (SGF, constant, subs, e));
0 commit comments