@@ -1564,23 +1564,29 @@ void StmtEmitter::visitFailStmt(FailStmt *S) {
1564
1564
1565
1565
// / Return a basic block suitable to be the destination block of a
1566
1566
// / try_apply instruction. The block is implicitly emitted and filled in.
1567
+ // /
1568
+ // / \param errorAddrOrType Either the address of the indirect error result where
1569
+ // / the result will be stored, or the type of the expected Owned error value.
1570
+ // /
1571
+ // / \param suppressErrorPath Should the error path be emitted as unreachable?
1567
1572
SILBasicBlock *
1568
1573
SILGenFunction::getTryApplyErrorDest (SILLocation loc,
1569
1574
CanSILFunctionType fnTy,
1570
1575
ExecutorBreadcrumb prevExecutor,
1571
- SILResultInfo errorResult,
1572
- SILValue indirectErrorAddr,
1576
+ TaggedUnion<SILValue, SILType> errorAddrOrType,
1573
1577
bool suppressErrorPath) {
1574
1578
// For now, don't try to re-use destination blocks for multiple
1575
1579
// failure sites.
1576
1580
SILBasicBlock *destBB = createBasicBlock (FunctionSection::Postmatter);
1577
1581
1578
1582
SILValue errorValue;
1579
- if (errorResult. getConvention () == ResultConvention::Owned ) {
1580
- errorValue = destBB->createPhiArgument (getSILType (errorResult, fnTy) ,
1581
- OwnershipKind::Owned);
1583
+ if (auto ownedErrorTy = errorAddrOrType. dyn_cast <SILType>() ) {
1584
+ errorValue = destBB->createPhiArgument (*ownedErrorTy ,
1585
+ OwnershipKind::Owned);
1582
1586
} else {
1583
- errorValue = indirectErrorAddr;
1587
+ auto errorAddr = errorAddrOrType.get <SILValue>();
1588
+ assert (errorAddr->getType ().isAddress ());
1589
+ errorValue = errorAddr;
1584
1590
}
1585
1591
1586
1592
assert (B.hasValidInsertionPoint () && B.insertingAtEndOfBlock ());
@@ -1653,9 +1659,6 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
1653
1659
} else {
1654
1660
// Call the _willThrowTyped entrypoint, which handles
1655
1661
// arbitrary error types.
1656
- SILValue tmpBuffer;
1657
- SILValue error;
1658
-
1659
1662
FuncDecl *entrypoint = ctx.getWillThrowTyped ();
1660
1663
auto genericSig = entrypoint->getGenericSignature ();
1661
1664
SubstitutionMap subMap = SubstitutionMap::get (
@@ -1668,18 +1671,15 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
1668
1671
// Materialize the error so we can pass the address down to the
1669
1672
// swift_willThrowTyped.
1670
1673
exnMV = exnMV.materialize (*this , loc);
1671
- error = exnMV.getValue ();
1672
- exn = exnMV.forward (*this );
1673
- } else {
1674
- // Claim the exception value.
1675
- exn = exnMV.forward (*this );
1676
- error = exn;
1677
1674
}
1678
1675
1679
1676
emitApplyOfLibraryIntrinsic (
1680
1677
loc, entrypoint, subMap,
1681
- { ManagedValue::forForwardedRValue (* this , error) },
1678
+ { exnMV },
1682
1679
SGFContext ());
1680
+
1681
+ // Claim the exception value.
1682
+ exn = exnMV.forward (*this );
1683
1683
}
1684
1684
} else {
1685
1685
// Claim the exception value.
0 commit comments