@@ -1672,23 +1672,29 @@ void StmtEmitter::visitFailStmt(FailStmt *S) {
1672
1672
1673
1673
// / Return a basic block suitable to be the destination block of a
1674
1674
// / try_apply instruction. The block is implicitly emitted and filled in.
1675
+ // /
1676
+ // / \param errorAddrOrType Either the address of the indirect error result where
1677
+ // / the result will be stored, or the type of the expected Owned error value.
1678
+ // /
1679
+ // / \param suppressErrorPath Should the error path be emitted as unreachable?
1675
1680
SILBasicBlock *
1676
1681
SILGenFunction::getTryApplyErrorDest (SILLocation loc,
1677
1682
CanSILFunctionType fnTy,
1678
1683
ExecutorBreadcrumb prevExecutor,
1679
- SILResultInfo errorResult,
1680
- SILValue indirectErrorAddr,
1684
+ TaggedUnion<SILValue, SILType> errorAddrOrType,
1681
1685
bool suppressErrorPath) {
1682
1686
// For now, don't try to re-use destination blocks for multiple
1683
1687
// failure sites.
1684
1688
SILBasicBlock *destBB = createBasicBlock (FunctionSection::Postmatter);
1685
1689
1686
1690
SILValue errorValue;
1687
- if (errorResult. getConvention () == ResultConvention::Owned ) {
1688
- errorValue = destBB->createPhiArgument (getSILType (errorResult, fnTy) ,
1689
- OwnershipKind::Owned);
1691
+ if (auto ownedErrorTy = errorAddrOrType. dyn_cast <SILType>() ) {
1692
+ errorValue = destBB->createPhiArgument (*ownedErrorTy ,
1693
+ OwnershipKind::Owned);
1690
1694
} else {
1691
- errorValue = indirectErrorAddr;
1695
+ auto errorAddr = errorAddrOrType.get <SILValue>();
1696
+ assert (errorAddr->getType ().isAddress ());
1697
+ errorValue = errorAddr;
1692
1698
}
1693
1699
1694
1700
assert (B.hasValidInsertionPoint () && B.insertingAtEndOfBlock ());
@@ -1761,9 +1767,6 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
1761
1767
} else {
1762
1768
// Call the _willThrowTyped entrypoint, which handles
1763
1769
// arbitrary error types.
1764
- SILValue tmpBuffer;
1765
- SILValue error;
1766
-
1767
1770
FuncDecl *entrypoint = ctx.getWillThrowTyped ();
1768
1771
auto genericSig = entrypoint->getGenericSignature ();
1769
1772
SubstitutionMap subMap = SubstitutionMap::get (
@@ -1776,18 +1779,15 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
1776
1779
// Materialize the error so we can pass the address down to the
1777
1780
// swift_willThrowTyped.
1778
1781
exnMV = exnMV.materialize (*this , loc);
1779
- error = exnMV.getValue ();
1780
- exn = exnMV.forward (*this );
1781
- } else {
1782
- // Claim the exception value.
1783
- exn = exnMV.forward (*this );
1784
- error = exn;
1785
1782
}
1786
1783
1787
1784
emitApplyOfLibraryIntrinsic (
1788
1785
loc, entrypoint, subMap,
1789
- { ManagedValue::forForwardedRValue (* this , error) },
1786
+ { exnMV },
1790
1787
SGFContext ());
1788
+
1789
+ // Claim the exception value.
1790
+ exn = exnMV.forward (*this );
1791
1791
}
1792
1792
} else {
1793
1793
// Claim the exception value.
@@ -1857,8 +1857,8 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
1857
1857
B.createDestroyAddr (loc, exn);
1858
1858
}
1859
1859
1860
- // Branch to the cleanup destination .
1861
- Cleanups.emitCleanupsForBranch (ThrowDest, loc, args , IsForUnwind);
1860
+ // Emit clean-ups needed prior to entering throw block .
1861
+ Cleanups.emitCleanupsBeforeBranch (ThrowDest, IsForUnwind);
1862
1862
1863
1863
if (indirectErrorAddr && !exn->getType ().isAddress ()) {
1864
1864
// Forward the error value into the return slot now. This has to happen
0 commit comments