@@ -4532,23 +4532,30 @@ void CallEmission::emitToUnmappedExplosionWithDirectTypedError(
4532
4532
extractScalarResults (IGF, result->getType (), result, nativeExplosion);
4533
4533
auto values = nativeExplosion.claimAll ();
4534
4534
4535
- Explosion errorExplosion;
4536
- if (!errorSchema.empty ()) {
4537
- auto *expandedType = errorSchema.getExpandedType (IGF.IGM );
4535
+ auto convertIntoExplosion = [](IRGenFunction &IGF,
4536
+ const NativeConventionSchema &schema,
4537
+ llvm::ArrayRef<llvm::Value *> values,
4538
+ Explosion &explosion,
4539
+ std::function<unsigned (unsigned )> mapIndex) {
4540
+ auto *expandedType = schema.getExpandedType (IGF.IGM );
4538
4541
if (auto *structTy = dyn_cast<llvm::StructType>(expandedType)) {
4539
4542
for (unsigned i = 0 , e = structTy->getNumElements (); i < e; ++i) {
4540
- llvm::Value *elt = values[combined. errorValueMapping [i] ];
4543
+ llvm::Value *elt = values[mapIndex (i) ];
4541
4544
auto *nativeTy = structTy->getElementType (i);
4542
4545
elt = convertForDirectError (IGF, elt, nativeTy, /* forExtraction*/ true );
4543
- errorExplosion .add (elt);
4546
+ explosion .add (elt);
4544
4547
}
4545
4548
} else {
4546
- auto *converted =
4547
- convertForDirectError (IGF, values[combined.errorValueMapping [0 ]],
4548
- expandedType, /* forExtraction*/ true );
4549
- errorExplosion.add (converted);
4549
+ auto *converted = convertForDirectError (
4550
+ IGF, values[mapIndex (0 )], expandedType, /* forExtraction*/ true );
4551
+ explosion.add (converted);
4550
4552
}
4553
+ };
4551
4554
4555
+ Explosion errorExplosion;
4556
+ if (!errorSchema.empty ()) {
4557
+ convertIntoExplosion (IGF, errorSchema, values, errorExplosion,
4558
+ [&](auto i) { return combined.errorValueMapping [i]; });
4552
4559
typedErrorExplosion =
4553
4560
errorSchema.mapFromNative (IGF.IGM , IGF, errorExplosion, errorType);
4554
4561
} else {
@@ -4558,19 +4565,8 @@ void CallEmission::emitToUnmappedExplosionWithDirectTypedError(
4558
4565
// If the regular result type is void, there is nothing to explode
4559
4566
if (!nativeSchema.empty ()) {
4560
4567
Explosion resultExplosion;
4561
- auto *expandedType = nativeSchema.getExpandedType (IGF.IGM );
4562
- if (auto *structTy = dyn_cast<llvm::StructType>(expandedType)) {
4563
- for (unsigned i = 0 , e = structTy->getNumElements (); i < e; ++i) {
4564
- auto *nativeTy = structTy->getElementType (i);
4565
- auto *converted = convertForDirectError (IGF, values[i], nativeTy,
4566
- /* forExtraction*/ true );
4567
- resultExplosion.add (converted);
4568
- }
4569
- } else {
4570
- auto *converted = convertForDirectError (IGF, values[0 ], expandedType,
4571
- /* forExtraction*/ true );
4572
- resultExplosion.add (converted);
4573
- }
4568
+ convertIntoExplosion (IGF, nativeSchema, values, resultExplosion,
4569
+ [](auto i) { return i; });
4574
4570
out = nativeSchema.mapFromNative (IGF.IGM , IGF, resultExplosion, resultType);
4575
4571
}
4576
4572
}
0 commit comments