@@ -2272,6 +2272,52 @@ static bool hasUnownedInnerPointerResult(CanSILFunctionType fnType) {
2272
2272
return false ;
2273
2273
}
2274
2274
2275
+ static ResultPlanPtr
2276
+ computeResultPlan (SILGenFunction *SGF, CanSILFunctionType substFnType,
2277
+ AbstractionPattern origResultType, CanType substResultType,
2278
+ const Optional<ForeignErrorConvention> &foreignError,
2279
+ SILFunctionTypeRepresentation rep, SILLocation loc,
2280
+ SGFContext evalContext,
2281
+ SmallVectorImpl<SILValue> &indirectResultAddrs) {
2282
+ auto origResultTypeForPlan = origResultType;
2283
+ auto substResultTypeForPlan = substResultType;
2284
+ ArrayRef<SILResultInfo> allResults = substFnType->getAllResults ();
2285
+ SILResultInfo optResult;
2286
+
2287
+ // The plan needs to be built using the formal result type
2288
+ // after foreign-error adjustment.
2289
+ if (foreignError) {
2290
+ switch (foreignError->getKind ()) {
2291
+ // These conventions make the formal result type ().
2292
+ case ForeignErrorConvention::ZeroResult:
2293
+ case ForeignErrorConvention::NonZeroResult:
2294
+ assert (substResultType->isVoid ());
2295
+ allResults = {};
2296
+ break ;
2297
+
2298
+ // These conventions leave the formal result alone.
2299
+ case ForeignErrorConvention::ZeroPreservedResult:
2300
+ case ForeignErrorConvention::NonNilError:
2301
+ break ;
2302
+
2303
+ // This convention changes the formal result to the optional object
2304
+ // type; we need to make our own make SILResultInfo array.
2305
+ case ForeignErrorConvention::NilResult: {
2306
+ assert (allResults.size () == 1 );
2307
+ SILType objectType =
2308
+ allResults[0 ].getSILType ().getAnyOptionalObjectType ();
2309
+ optResult = allResults[0 ].getWithType (objectType.getSwiftRValueType ());
2310
+ allResults = optResult;
2311
+ break ;
2312
+ }
2313
+ }
2314
+ }
2315
+
2316
+ ResultPlanBuilder builder (*SGF, loc, allResults, rep, indirectResultAddrs);
2317
+ return builder.build (evalContext.getEmitInto (), origResultTypeForPlan,
2318
+ substResultTypeForPlan);
2319
+ }
2320
+
2275
2321
// / Emit a function application, assuming that the arguments have been
2276
2322
// / lowered appropriately for the abstraction level but that the
2277
2323
// / result does need to be turned back into something matching a
@@ -2292,45 +2338,9 @@ RValue SILGenFunction::emitApply(
2292
2338
2293
2339
// Create the result plan.
2294
2340
SmallVector<SILValue, 4 > indirectResultAddrs;
2295
- ResultPlanPtr resultPlan = [&]() -> ResultPlanPtr {
2296
- auto origResultTypeForPlan = origResultType;
2297
- auto substResultTypeForPlan = substResultType;
2298
- ArrayRef<SILResultInfo> allResults = substFnType->getAllResults ();
2299
- SILResultInfo optResult;
2300
-
2301
- // The plan needs to be built using the formal result type
2302
- // after foreign-error adjustment.
2303
- if (foreignError) {
2304
- switch (foreignError->getKind ()) {
2305
- // These conventions make the formal result type ().
2306
- case ForeignErrorConvention::ZeroResult:
2307
- case ForeignErrorConvention::NonZeroResult:
2308
- assert (substResultType->isVoid ());
2309
- allResults = {};
2310
- break ;
2311
-
2312
- // These conventions leave the formal result alone.
2313
- case ForeignErrorConvention::ZeroPreservedResult:
2314
- case ForeignErrorConvention::NonNilError:
2315
- break ;
2316
-
2317
- // This convention changes the formal result to the optional object
2318
- // type; we need to make our own make SILResultInfo array.
2319
- case ForeignErrorConvention::NilResult: {
2320
- assert (allResults.size () == 1 );
2321
- SILType objectType =
2322
- allResults[0 ].getSILType ().getAnyOptionalObjectType ();
2323
- optResult = allResults[0 ].getWithType (objectType.getSwiftRValueType ());
2324
- allResults = optResult;
2325
- break ;
2326
- }
2327
- }
2328
- }
2329
-
2330
- ResultPlanBuilder builder (*this , loc, allResults, rep, indirectResultAddrs);
2331
- return builder.build (evalContext.getEmitInto (),
2332
- origResultTypeForPlan, substResultTypeForPlan);
2333
- }();
2341
+ ResultPlanPtr resultPlan = computeResultPlan (
2342
+ this , substFnType, origResultType, substResultType, foreignError, rep,
2343
+ loc, evalContext, indirectResultAddrs);
2334
2344
2335
2345
// If the function returns an inner pointer, we'll need to lifetime-extend
2336
2346
// the 'self' parameter.
0 commit comments