@@ -2190,32 +2190,6 @@ static CanSILFunctionType getSILFunctionType(
2190
2190
isAsync = true ;
2191
2191
}
2192
2192
2193
- // Map 'throws' to the appropriate error convention.
2194
- // Give the type an error argument whether the substituted type semantically
2195
- // `throws` or if the abstraction pattern specifies a Swift function type
2196
- // that also throws. This prevents the need for a second possibly-thunking
2197
- // conversion when using a non-throwing function in more abstract throwing
2198
- // context.
2199
- bool isThrowing = substFnInterfaceType->getExtInfo ().isThrowing ();
2200
- if (auto origFnType = origType.getAs <AnyFunctionType>()) {
2201
- isThrowing |= origFnType->getExtInfo ().isThrowing ();
2202
- }
2203
- if (isThrowing && !foreignInfo.error &&
2204
- !foreignInfo.async ) {
2205
- assert (!origType.isForeign ()
2206
- && " using native Swift error convention for foreign type!" );
2207
- SILType exnType;
2208
- if (CanType thrownError = substFnInterfaceType.getThrownError ()) {
2209
- exnType = TC.getLoweredType (thrownError, expansionContext);
2210
- } else {
2211
- // Untyped error throws the exception type.
2212
- exnType = SILType::getExceptionType (TC.Context );
2213
- }
2214
- assert (exnType.isObject ());
2215
- errorResult = SILResultInfo (exnType.getASTType (),
2216
- ResultConvention::Owned);
2217
- }
2218
-
2219
2193
// Get the yield type for an accessor coroutine.
2220
2194
SILCoroutineKind coroutineKind = SILCoroutineKind::None;
2221
2195
AbstractionPattern coroutineOrigYieldType = AbstractionPattern::getInvalid ();
@@ -2308,6 +2282,36 @@ static CanSILFunctionType getSILFunctionType(
2308
2282
}
2309
2283
}
2310
2284
2285
+ // Map 'throws' to the appropriate error convention.
2286
+ // Give the type an error argument whether the substituted type semantically
2287
+ // `throws` or if the abstraction pattern specifies a Swift function type
2288
+ // that also throws. This prevents the need for a second possibly-thunking
2289
+ // conversion when using a non-throwing function in more abstract throwing
2290
+ // context.
2291
+ bool isThrowing = substFnInterfaceType->getExtInfo ().isThrowing ();
2292
+ if (auto origFnType = origType.getAs <AnyFunctionType>()) {
2293
+ isThrowing |= origFnType->getExtInfo ().isThrowing ();
2294
+ }
2295
+
2296
+ if (isThrowing && !foreignInfo.error &&
2297
+ !foreignInfo.async ) {
2298
+ assert (!origType.isForeign ()
2299
+ && " using native Swift error convention for foreign type!" );
2300
+ auto optPair = origType.getFunctionThrownErrorType (substFnInterfaceType);
2301
+ assert (optPair &&
2302
+ " Lowering a throwing function type against non-throwing pattern" );
2303
+
2304
+ auto origErrorType = optPair->first ;
2305
+ auto errorType = optPair->second ;
2306
+ auto &errorTLConv = TC.getTypeLowering (origErrorType, errorType,
2307
+ TypeExpansionContext::minimal ());
2308
+
2309
+ errorResult = SILResultInfo (errorTLConv.getLoweredType ().getASTType (),
2310
+ errorTLConv.isAddressOnly ()
2311
+ ? ResultConvention::Indirect
2312
+ : ResultConvention::Owned);
2313
+ }
2314
+
2311
2315
// Lower the result type.
2312
2316
AbstractionPattern origResultType = origType.getFunctionResultType ();
2313
2317
CanType substFormalResultType = substFnInterfaceType.getResult ();
0 commit comments