Skip to content

Commit 25dace0

Browse files
committed
[SILGen] ResultPlan: Add a FIXME about foreign error bridging in checking continuations mode
(cherry picked from commit 6ecbb08)
1 parent 1450c4f commit 25dace0

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

lib/SILGen/ResultPlan.cpp

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,8 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
881881
SILValue bridgedForeignError) override {
882882
// There should be no direct results from the call.
883883
assert(directResults.empty());
884-
884+
auto &ctx = SGF.getASTContext();
885+
885886
// Await the continuation we handed off to the completion handler.
886887
SILBasicBlock *resumeBlock = SGF.createBasicBlock();
887888
SILBasicBlock *errorBlock = nullptr;
@@ -923,9 +924,20 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
923924
SGF.B.setInsertionPoint(
924925
++bridgedForeignError->getDefiningInstruction()->getIterator());
925926

926-
auto continuationDecl = SGF.getASTContext().getUnsafeContinuationDecl();
927-
928-
auto errorTy = SGF.getASTContext().getErrorExistentialType();
927+
// FIXME: this case is not respecting checked bridging, and it's a
928+
// great candidate for that. This situation comes up when bridging
929+
// to an ObjC completion-handler method that returns a bool. It seems
930+
// that bool indicates whether the handler was invoked. If it was not
931+
// then it writes out an error. Here for the unsafe bridging, we're
932+
// invoking the continuation by re-wrapping it in an
933+
// UnsafeContinuation<_, Error> and then immediately calling its
934+
// resume(throwing: error) method. For a checked bridging scenario, we
935+
// would need to use a copy of the original CheckedContinuation that
936+
// was passed to the callee. Whether that's by invoking the block
937+
// ourselves, or just invoking the CheckedContinuation.
938+
939+
auto continuationDecl = ctx.getUnsafeContinuationDecl();
940+
auto errorTy = ctx.getErrorExistentialType();
929941
auto continuationBGT =
930942
BoundGenericType::get(continuationDecl, Type(),
931943
{calleeTypeInfo.substResultType, errorTy});
@@ -976,7 +988,7 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
976988

977989
Scope errorScope(SGF, loc);
978990

979-
auto errorTy = SGF.getASTContext().getErrorExistentialType();
991+
auto errorTy = ctx.getErrorExistentialType();
980992
auto errorVal = SGF.B.createTermResult(
981993
SILType::getPrimitiveObjectType(errorTy), OwnershipKind::Owned);
982994

0 commit comments

Comments
 (0)