Skip to content

Commit a602531

Browse files
committed
[SILGen] Pass storage block type and callee info to async completion handler generator
Instead of relying on `continuationType` for information, let's take it from the source.
1 parent b7c2cb8 commit a602531

File tree

3 files changed

+20
-21
lines changed

3 files changed

+20
-21
lines changed

lib/SILGen/ResultPlan.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -767,9 +767,9 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
767767
{continuation});
768768

769769
// Stash it in a buffer for a block object.
770-
auto blockStorageTy = SILType::getPrimitiveAddressType(
771-
SILBlockStorageType::get(continuationTy));
772-
auto blockStorage = SGF.emitTemporaryAllocation(loc, blockStorageTy);
770+
auto blockStorageTy = SILBlockStorageType::get(continuationTy);
771+
auto blockStorage = SGF.emitTemporaryAllocation(
772+
loc, SILType::getPrimitiveAddressType(blockStorageTy));
773773
auto continuationAddr = SGF.B.createProjectBlockStorage(loc, blockStorage);
774774
SGF.B.createStore(loc, wrappedContinuation, continuationAddr,
775775
StoreOwnershipQualifier::Trivial);
@@ -796,11 +796,10 @@ class ForeignAsyncInitializationPlan final : public ResultPlan {
796796
SGF.SGM.getOrCreateForeignAsyncCompletionHandlerImplFunction(
797797
cast<SILFunctionType>(
798798
impFnTy->mapTypeOutOfContext()->getReducedType(sig)),
799-
continuationTy->mapTypeOutOfContext()->getReducedType(sig),
800-
origFormalType, sig, *calleeTypeInfo.foreign.async,
801-
calleeTypeInfo.foreign.error);
799+
blockStorageTy->mapTypeOutOfContext()->getReducedType(sig),
800+
origFormalType, sig, calleeTypeInfo);
802801
auto impRef = SGF.B.createFunctionRef(loc, impl);
803-
802+
804803
// Initialize the block object for the completion handler.
805804
SILValue block = SGF.B.createInitBlockStorageHeader(loc, blockStorage,
806805
impRef, SILType::getPrimitiveObjectType(impFnTy),

lib/SILGen/SILGen.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ namespace swift {
3232
namespace Lowering {
3333
class TypeConverter;
3434
class SILGenFunction;
35+
class CalleeTypeInfo;
3536

3637
/// An enum to indicate whether a protocol method requirement is satisfied by
3738
/// a free function, as for an operator requirement.
@@ -182,10 +183,9 @@ class LLVM_LIBRARY_VISIBILITY SILGenModule : public ASTVisitor<SILGenModule> {
182183
/// implementation function for an ObjC API that was imported
183184
/// as `async` in Swift.
184185
SILFunction *getOrCreateForeignAsyncCompletionHandlerImplFunction(
185-
CanSILFunctionType blockType, CanType continuationTy,
186+
CanSILFunctionType blockType, CanType blockStorageType,
186187
AbstractionPattern origFormalType, CanGenericSignature sig,
187-
ForeignAsyncConvention convention,
188-
llvm::Optional<ForeignErrorConvention> foreignError);
188+
CalleeTypeInfo &calleeInfo);
189189

190190
/// Determine whether the given class has any instance variables that
191191
/// need to be destroyed.

lib/SILGen/SILGenThunk.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
//
2121
//===----------------------------------------------------------------------===//
2222

23+
#include "Callee.h"
2324
#include "ManagedValue.h"
2425
#include "SILGenFunction.h"
2526
#include "SILGenFunctionBuilder.h"
@@ -198,12 +199,12 @@ static const clang::Type *prependParameterType(
198199
}
199200

200201
SILFunction *SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
201-
CanSILFunctionType blockType, CanType continuationTy,
202+
CanSILFunctionType blockType, CanType blockStorageType,
202203
AbstractionPattern origFormalType, CanGenericSignature sig,
203-
ForeignAsyncConvention convention,
204-
llvm::Optional<ForeignErrorConvention> foreignError) {
205-
// Extract the result and error types from the continuation type.
206-
auto resumeType = cast<BoundGenericType>(continuationTy).getGenericArgs()[0];
204+
CalleeTypeInfo &calleeInfo) {
205+
auto convention = *calleeInfo.foreign.async;
206+
auto resumeType =
207+
calleeInfo.substResultType->mapTypeOutOfContext()->getReducedType(sig);
207208

208209
CanAnyFunctionType completionHandlerOrigTy = [&]() {
209210
auto completionHandlerOrigTy =
@@ -236,18 +237,17 @@ SILFunction *SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
236237
// block buffer. The block storage holds the continuation we feed the
237238
// result values into.
238239
SmallVector<SILParameterInfo, 4> implArgs;
239-
auto blockStorageTy = SILBlockStorageType::get(continuationTy);
240-
implArgs.push_back(SILParameterInfo(blockStorageTy,
241-
ParameterConvention::Indirect_InoutAliasable));
242-
240+
implArgs.push_back(SILParameterInfo(
241+
blockStorageType, ParameterConvention::Indirect_InoutAliasable));
242+
243243
std::copy(blockType->getParameters().begin(),
244244
blockType->getParameters().end(),
245245
std::back_inserter(implArgs));
246246

247247
auto newClangTy = prependParameterType(
248248
getASTContext(),
249249
blockType->getClangTypeInfo().getType(),
250-
getASTContext().getClangTypeForIRGen(blockStorageTy));
250+
getASTContext().getClangTypeForIRGen(blockStorageType));
251251

252252
auto implTy = SILFunctionType::get(
253253
sig,
@@ -384,7 +384,7 @@ SILFunction *SILGenModule::getOrCreateForeignAsyncCompletionHandlerImplFunction(
384384
errorScope.pop();
385385
SGF.B.createBranch(loc, returnBB);
386386
SGF.B.emitBlock(noneErrorBB);
387-
} else if (foreignError) {
387+
} else if (auto foreignError = calleeInfo.foreign.error) {
388388
resumeIntrinsic = getResumeUnsafeThrowingContinuation();
389389
} else {
390390
resumeIntrinsic = getResumeUnsafeContinuation();

0 commit comments

Comments
 (0)