@@ -1157,30 +1157,22 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1157
1157
1158
1158
// Otherwise, we have a statically-dispatched call.
1159
1159
CanFunctionType substFnType = getSubstFnType ();
1160
- ArrayRef<Substitution> subs;
1161
-
1160
+
1162
1161
auto afd = dyn_cast<AbstractFunctionDecl>(e->getDecl ());
1163
1162
if (afd) {
1164
- auto constantInfo = SGF.getConstantInfo (constant);
1165
-
1166
- // Forward local substitutions to a non-generic local function.
1167
- if (afd->getParent ()->isLocalContext () && !afd->getGenericParams ())
1168
- subs = constantInfo.getForwardingSubstitutions (SGF.getASTContext ());
1169
-
1170
1163
// If there are captures, put the placeholder curry level in the formal
1171
1164
// type.
1172
1165
// TODO: Eliminate the need for this.
1173
1166
if (afd->getCaptureInfo ().hasLocalCaptures ())
1174
1167
substFnType = CanFunctionType::get (
1175
1168
SGF.getASTContext ().TheEmptyTupleType , substFnType);
1176
1169
}
1177
-
1170
+
1171
+ ArrayRef<Substitution> subs;
1178
1172
if (e->getDeclRef ().isSpecialized ()) {
1179
- assert (subs.empty () && " nested local generics not yet supported" );
1180
1173
subs = e->getDeclRef ().getSubstitutions ();
1181
1174
}
1182
-
1183
-
1175
+
1184
1176
// Enum case constructor references are open-coded.
1185
1177
if (isa<EnumElementDecl>(e->getDecl ()))
1186
1178
setCallee (Callee::forEnumElement (SGF, constant, substFnType, e));
@@ -1189,21 +1181,20 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1189
1181
1190
1182
// If the decl ref requires captures, emit the capture params.
1191
1183
if (afd) {
1184
+ // FIXME: We should be checking hasLocalCaptures() on the lowered
1185
+ // captures in the constant info too, to generate more efficient
1186
+ // code for mutually recursive local functions which otherwise
1187
+ // capture no state.
1192
1188
if (afd->getCaptureInfo ().hasLocalCaptures ()) {
1193
- assert (!e->getDeclRef ().isSpecialized ()
1194
- && " generic local fns not implemented" );
1195
-
1196
1189
SmallVector<ManagedValue, 4 > captures;
1197
1190
SGF.emitCaptures (e, afd, CaptureEmission::ImmediateApplication,
1198
1191
captures);
1199
1192
ApplyCallee->setCaptures (std::move (captures));
1200
1193
}
1201
-
1202
- // FIXME: We should be checking hasLocalCaptures() on the lowered
1203
- // captures in the constant info too, to generate more efficient
1204
- // code for mutually recursive local functions which otherwise
1205
- // capture no state.
1206
-
1194
+
1195
+ if (subs.empty () && afd->getCaptureInfo ().hasGenericParamCaptures ()) {
1196
+ subs = SGF.getForwardingSubstitutions ();
1197
+ }
1207
1198
}
1208
1199
1209
1200
// If there are substitutions, add them, always at depth 0.
@@ -1227,14 +1218,15 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
1227
1218
SILDeclRef constant (e);
1228
1219
1229
1220
ArrayRef<Substitution> subs;
1221
+ if (e->getCaptureInfo ().hasGenericParamCaptures ())
1222
+ subs = SGF.getForwardingSubstitutions ();
1223
+
1230
1224
CanFunctionType substFnType = getSubstFnType ();
1231
1225
1232
1226
// FIXME: We should be checking hasLocalCaptures() on the lowered
1233
1227
// captures in the constant info above, to generate more efficient
1234
1228
// code for mutually recursive local functions which otherwise
1235
1229
// capture no state.
1236
- auto constantInfo = SGF.getConstantInfo (constant);
1237
- subs = constantInfo.getForwardingSubstitutions (SGF.getASTContext ());
1238
1230
1239
1231
// If there are captures, put the placeholder curry level in the formal
1240
1232
// type.
0 commit comments