@@ -5188,7 +5188,8 @@ static void buildWithoutActuallyEscapingThunkBody(SILGenFunction &SGF,
5188
5188
5189
5189
SmallVector<ManagedValue, 8 > params;
5190
5190
SmallVector<ManagedValue, 8 > indirectResults;
5191
- SGF.collectThunkParams (loc, params, &indirectResults);
5191
+ SmallVector<ManagedValue, 1 > indirectErrorResults;
5192
+ SGF.collectThunkParams (loc, params, &indirectResults, &indirectErrorResults);
5192
5193
5193
5194
// Ignore the self parameter at the SIL level. IRGen will use it to
5194
5195
// recover type metadata.
@@ -5198,13 +5199,16 @@ static void buildWithoutActuallyEscapingThunkBody(SILGenFunction &SGF,
5198
5199
ManagedValue fnValue = params.pop_back_val ();
5199
5200
auto fnType = fnValue.getType ().castTo <SILFunctionType>();
5200
5201
5202
+ // Forward indirect result arguments.
5201
5203
SmallVector<SILValue, 8 > argValues;
5202
5204
if (!indirectResults.empty ()) {
5203
5205
for (auto result : indirectResults)
5204
5206
argValues.push_back (result.getLValueAddress ());
5205
5207
}
5206
5208
5207
- // Forward indirect result arguments.
5209
+ // Forward indirect error arguments.
5210
+ for (auto indirectError : indirectErrorResults)
5211
+ argValues.push_back (indirectError.getLValueAddress ());
5208
5212
5209
5213
// Add the rest of the arguments.
5210
5214
forwardFunctionArguments (SGF, loc, fnType, params, argValues);
@@ -5389,14 +5393,18 @@ ManagedValue SILGenFunction::getThunkedAutoDiffLinearMap(
5389
5393
SILGenFunction thunkSGF (SGM, *thunk, FunctionDC);
5390
5394
SmallVector<ManagedValue, 4 > params;
5391
5395
SmallVector<ManagedValue, 4 > thunkIndirectResults;
5392
- thunkSGF.collectThunkParams (loc, params, &thunkIndirectResults);
5396
+ SmallVector<ManagedValue, 4 > thunkIndirectErrorResults;
5397
+ thunkSGF.collectThunkParams (
5398
+ loc, params, &thunkIndirectResults, &thunkIndirectErrorResults);
5393
5399
5394
5400
SILFunctionConventions fromConv (fromType, getModule ());
5395
5401
SILFunctionConventions toConv (toType, getModule ());
5396
5402
if (!toConv.useLoweredAddresses ()) {
5397
5403
SmallVector<ManagedValue, 4 > thunkArguments;
5398
5404
for (auto indRes : thunkIndirectResults)
5399
5405
thunkArguments.push_back (indRes);
5406
+ for (auto indErrRes : thunkIndirectErrorResults)
5407
+ thunkArguments.push_back (indErrRes);
5400
5408
thunkArguments.append (params.begin (), params.end ());
5401
5409
SmallVector<SILParameterInfo, 4 > toParameters (
5402
5410
toConv.getParameters ().begin (), toConv.getParameters ().end ());
@@ -5405,7 +5413,8 @@ ManagedValue SILGenFunction::getThunkedAutoDiffLinearMap(
5405
5413
// Handle self reordering.
5406
5414
// - For pullbacks: reorder result infos.
5407
5415
// - For differentials: reorder parameter infos and arguments.
5408
- auto numIndirectResults = thunkIndirectResults.size ();
5416
+ auto numIndirectResults =
5417
+ thunkIndirectResults.size () + thunkIndirectErrorResults.size ();
5409
5418
if (reorderSelf && linearMapKind == AutoDiffLinearMapKind::Pullback &&
5410
5419
toResults.size () > 1 ) {
5411
5420
std::rotate (toResults.begin (), toResults.end () - 1 , toResults.end ());
@@ -5477,6 +5486,8 @@ ManagedValue SILGenFunction::getThunkedAutoDiffLinearMap(
5477
5486
SmallVector<ManagedValue, 4 > thunkArguments;
5478
5487
thunkArguments.append (thunkIndirectResults.begin (),
5479
5488
thunkIndirectResults.end ());
5489
+ thunkArguments.append (thunkIndirectErrorResults.begin (),
5490
+ thunkIndirectErrorResults.end ());
5480
5491
thunkArguments.append (params.begin (), params.end ());
5481
5492
SmallVector<SILParameterInfo, 4 > toParameters (toConv.getParameters ().begin (),
5482
5493
toConv.getParameters ().end ());
@@ -5723,7 +5734,9 @@ SILFunction *SILGenModule::getOrCreateCustomDerivativeThunk(
5723
5734
SILGenFunction thunkSGF (*this , *thunk, customDerivativeFn->getDeclContext ());
5724
5735
SmallVector<ManagedValue, 4 > params;
5725
5736
SmallVector<ManagedValue, 4 > indirectResults;
5726
- thunkSGF.collectThunkParams (loc, params, &indirectResults);
5737
+ SmallVector<ManagedValue, 1 > indirectErrorResults;
5738
+ thunkSGF.collectThunkParams (
5739
+ loc, params, &indirectResults, &indirectErrorResults);
5727
5740
5728
5741
auto *fnRef = thunkSGF.B .createFunctionRef (loc, customDerivativeFn);
5729
5742
auto fnRefType =
@@ -5767,6 +5780,8 @@ SILFunction *SILGenModule::getOrCreateCustomDerivativeThunk(
5767
5780
SmallVector<SILValue, 8 > arguments;
5768
5781
for (auto indRes : indirectResults)
5769
5782
arguments.push_back (indRes.getLValueAddress ());
5783
+ for (auto indErrorRes : indirectErrorResults)
5784
+ arguments.push_back (indErrorRes.getLValueAddress ());
5770
5785
forwardFunctionArguments (thunkSGF, loc, fnRefType, params, arguments);
5771
5786
5772
5787
// Apply function argument.
@@ -6200,6 +6215,13 @@ SILGenFunction::emitVTableThunk(SILDeclRef base,
6200
6215
inputOrigType.getFunctionResultType (),
6201
6216
inputSubstType.getResult (),
6202
6217
derivedFTy, thunkTy);
6218
+
6219
+ // If the function we're calling has as indirect error result, create an
6220
+ // argument for it.
6221
+ if (auto innerIndirectErrorAddr =
6222
+ emitThunkIndirectErrorArgument (*this , loc, derivedFTy)) {
6223
+ args.push_back (*innerIndirectErrorAddr);
6224
+ }
6203
6225
}
6204
6226
6205
6227
// Then, the arguments.
@@ -6584,13 +6606,13 @@ void SILGenFunction::emitProtocolWitness(
6584
6606
reqtOrigTy.getFunctionResultType (),
6585
6607
reqtSubstTy.getResult (),
6586
6608
witnessFTy, thunkTy);
6587
- }
6588
6609
6589
- // If the function we're calling has as indirect error result, create an
6590
- // argument for it.
6591
- if (auto innerIndirectErrorAddr =
6592
- emitThunkIndirectErrorArgument (*this , loc, witnessFTy)) {
6593
- args.push_back (*innerIndirectErrorAddr);
6610
+ // If the function we're calling has as indirect error result, create an
6611
+ // argument for it.
6612
+ if (auto innerIndirectErrorAddr =
6613
+ emitThunkIndirectErrorArgument (*this , loc, witnessFTy)) {
6614
+ args.push_back (*innerIndirectErrorAddr);
6615
+ }
6594
6616
}
6595
6617
6596
6618
// - the rest of the arguments
0 commit comments