@@ -1564,23 +1564,29 @@ void StmtEmitter::visitFailStmt(FailStmt *S) {
15641564
15651565// / Return a basic block suitable to be the destination block of a
15661566// / 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?
15671572SILBasicBlock *
15681573SILGenFunction::getTryApplyErrorDest (SILLocation loc,
15691574 CanSILFunctionType fnTy,
15701575 ExecutorBreadcrumb prevExecutor,
1571- SILResultInfo errorResult,
1572- SILValue indirectErrorAddr,
1576+ TaggedUnion<SILValue, SILType> errorAddrOrType,
15731577 bool suppressErrorPath) {
15741578 // For now, don't try to re-use destination blocks for multiple
15751579 // failure sites.
15761580 SILBasicBlock *destBB = createBasicBlock (FunctionSection::Postmatter);
15771581
15781582 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);
15821586 } else {
1583- errorValue = indirectErrorAddr;
1587+ auto errorAddr = errorAddrOrType.get <SILValue>();
1588+ assert (errorAddr->getType ().isAddress ());
1589+ errorValue = errorAddr;
15841590 }
15851591
15861592 assert (B.hasValidInsertionPoint () && B.insertingAtEndOfBlock ());
@@ -1653,9 +1659,6 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
16531659 } else {
16541660 // Call the _willThrowTyped entrypoint, which handles
16551661 // arbitrary error types.
1656- SILValue tmpBuffer;
1657- SILValue error;
1658-
16591662 FuncDecl *entrypoint = ctx.getWillThrowTyped ();
16601663 auto genericSig = entrypoint->getGenericSignature ();
16611664 SubstitutionMap subMap = SubstitutionMap::get (
@@ -1668,18 +1671,15 @@ void SILGenFunction::emitThrow(SILLocation loc, ManagedValue exnMV,
16681671 // Materialize the error so we can pass the address down to the
16691672 // swift_willThrowTyped.
16701673 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;
16771674 }
16781675
16791676 emitApplyOfLibraryIntrinsic (
16801677 loc, entrypoint, subMap,
1681- { ManagedValue::forForwardedRValue (* this , error) },
1678+ { exnMV },
16821679 SGFContext ());
1680+
1681+ // Claim the exception value.
1682+ exn = exnMV.forward (*this );
16831683 }
16841684 } else {
16851685 // Claim the exception value.
0 commit comments