@@ -1225,9 +1225,8 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
12251225 auto captureInfo = SGF.SGM .Types .getLoweredLocalCaptures (constant);
12261226 SGF.SGM .Types .setCaptureTypeExpansionContext (constant, SGF.SGM .M );
12271227
1228- if (afd->getDeclContext ()->isLocalContext () &&
1229- !captureInfo.hasGenericParamCaptures ())
1230- subs = SubstitutionMap ();
1228+ subs = SGF.SGM .Types .getSubstitutionMapWithCapturedEnvironments (
1229+ constant, captureInfo, subs);
12311230
12321231 // Check whether we have to dispatch to the original implementation of a
12331232 // dynamically_replaceable inside of a dynamic_replacement(for:) function.
@@ -1304,17 +1303,14 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
13041303
13051304 // A directly-called closure can be emitted as a direct call instead of
13061305 // really producing a closure object.
1307-
1308- auto captureInfo = SGF.SGM .M .Types .getLoweredLocalCaptures (constant);
1309-
13101306 SubstitutionMap subs;
1311- if (captureInfo. hasGenericParamCaptures () )
1312- subs = SGF.getForwardingSubstitutionMap ( );
1307+ std::tie (std::ignore, std::ignore, subs )
1308+ = SGF.SGM . Types . getForwardingSubstitutionsForLowering (constant );
13131309
13141310 setCallee (Callee::forDirect (SGF, constant, subs, e));
13151311
13161312 // If the closure requires captures, emit them.
1317- if (!captureInfo. getCaptures (). empty ( )) {
1313+ if (SGF. SGM . Types . hasLoweredLocalCaptures (constant )) {
13181314 SmallVector<ManagedValue, 4 > captures;
13191315 SGF.emitCaptures (e, constant, CaptureEmission::ImmediateApplication,
13201316 captures);
@@ -6712,14 +6708,9 @@ static Callee getBaseAccessorFunctionRef(SILGenFunction &SGF,
67126708 subs, loc, true );
67136709 }
67146710
6715- // The accessor might be a local function that does not capture any
6716- // generic parameters, in which case we don't want to pass in any
6717- // substitutions.
67186711 auto captureInfo = SGF.SGM .Types .getLoweredLocalCaptures (constant);
6719- if (decl->getDeclContext ()->isLocalContext () &&
6720- !captureInfo.hasGenericParamCaptures ()) {
6721- subs = SubstitutionMap ();
6722- }
6712+ subs = SGF.SGM .Types .getSubstitutionMapWithCapturedEnvironments (
6713+ constant, captureInfo, subs);
67236714
67246715 // If this is a method in a protocol, generate it as a protocol call.
67256716 if (isa<ProtocolDecl>(decl->getDeclContext ())) {
0 commit comments