Skip to content

Commit db8183d

Browse files
committed
[IRGen] Added LinkEntities for AsyncFunctionPointer.
Two LinkEntities are needed to enable the construction during both IRGen and TBDGen.
1 parent 4156382 commit db8183d

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

include/swift/IRGen/Linking.h

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ class LinkEntity {
293293
/// the metadata cache once.
294294
CanonicalPrespecializedGenericTypeCachingOnceToken,
295295

296+
/// The same as AsyncFunctionPointer but with a different stored value, for
297+
/// use by TBDGen.
298+
/// The pointer is a AbstractStorageDecl*.
299+
AsyncFunctionPointerAST,
300+
296301
/// The pointer is a SILFunction*.
297302
DynamicallyReplaceableFunctionKey,
298303

@@ -410,6 +415,13 @@ class LinkEntity {
410415
/// passed to swift_getCanonicalSpecializedMetadata.
411416
/// The pointer is a canonical TypeBase*.
412417
NoncanonicalSpecializedGenericTypeMetadataCacheVariable,
418+
419+
/// Provides the data required to invoke an async function using the async
420+
/// calling convention in the form of the size of the context to allocate
421+
/// and the relative address of the function to call with that allocated
422+
/// context.
423+
/// The pointer is a SILFunction*.
424+
AsyncFunctionPointer,
413425
};
414426
friend struct llvm::DenseMapInfo<LinkEntity>;
415427

@@ -418,7 +430,7 @@ class LinkEntity {
418430
}
419431

420432
static bool isDeclKind(Kind k) {
421-
return k <= Kind::CanonicalPrespecializedGenericTypeCachingOnceToken;
433+
return k <= Kind::AsyncFunctionPointerAST;
422434
}
423435
static bool isTypeKind(Kind k) {
424436
return k >= Kind::ProtocolWitnessTableLazyAccessFunction;
@@ -1088,6 +1100,21 @@ class LinkEntity {
10881100
return entity;
10891101
}
10901102

1103+
static LinkEntity forAsyncFunctionPointer(SILFunction *silFunction) {
1104+
LinkEntity entity;
1105+
entity.Pointer = silFunction;
1106+
entity.SecondaryPointer = nullptr;
1107+
entity.Data = LINKENTITY_SET_FIELD(
1108+
Kind, unsigned(LinkEntity::Kind::AsyncFunctionPointer));
1109+
return entity;
1110+
}
1111+
1112+
static LinkEntity forAsyncFunctionPointer(AbstractFunctionDecl *decl) {
1113+
LinkEntity entity;
1114+
entity.setForDecl(Kind::AsyncFunctionPointerAST, decl);
1115+
return entity;
1116+
}
1117+
10911118
void mangle(llvm::raw_ostream &out) const;
10921119
void mangle(SmallVectorImpl<char> &buffer) const;
10931120
std::string mangleAsString() const;
@@ -1110,14 +1137,15 @@ class LinkEntity {
11101137
}
11111138

11121139
bool hasSILFunction() const {
1113-
return getKind() == Kind::SILFunction ||
1140+
return getKind() == Kind::AsyncFunctionPointer ||
11141141
getKind() == Kind::DynamicallyReplaceableFunctionVariable ||
1115-
getKind() == Kind::DynamicallyReplaceableFunctionKey;
1142+
getKind() == Kind::DynamicallyReplaceableFunctionKey ||
1143+
getKind() == Kind::SILFunction;
11161144
}
11171145

11181146
SILFunction *getSILFunction() const {
11191147
assert(hasSILFunction());
1120-
return reinterpret_cast<SILFunction*>(Pointer);
1148+
return reinterpret_cast<SILFunction *>(Pointer);
11211149
}
11221150

11231151
SILGlobalVariable *getSILGlobalVariable() const {

lib/IRGen/Linking.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,17 @@ std::string LinkEntity::mangleAsString() const {
430430
return mangler.mangleSILDifferentiabilityWitnessKey(
431431
{getSILDifferentiabilityWitness()->getOriginalFunction()->getName(),
432432
getSILDifferentiabilityWitness()->getConfig()});
433+
case Kind::AsyncFunctionPointer: {
434+
std::string Result(getSILFunction()->getName());
435+
Result.append("AD");
436+
return Result;
437+
}
438+
case Kind::AsyncFunctionPointerAST: {
439+
std::string Result;
440+
Result = mangler.mangleEntity(getDecl());
441+
Result.append("AD");
442+
return Result;
443+
}
433444
}
434445
llvm_unreachable("bad entity kind!");
435446
}
@@ -663,9 +674,13 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {
663674
case Kind::DynamicallyReplaceableFunctionKey:
664675
return getSILFunction()->getLinkage();
665676

677+
case Kind::AsyncFunctionPointer:
666678
case Kind::SILFunction:
667679
return getSILFunction()->getEffectiveSymbolLinkage();
668680

681+
case Kind::AsyncFunctionPointerAST:
682+
return getSILLinkage(getDeclLinkage(getDecl()), forDefinition);
683+
669684
case Kind::DynamicallyReplaceableFunctionImpl:
670685
case Kind::DynamicallyReplaceableFunctionKeyAST:
671686
return getSILLinkage(getDeclLinkage(getDecl()), forDefinition);
@@ -712,6 +727,8 @@ bool LinkEntity::isContextDescriptor() const {
712727
case Kind::ProtocolDescriptor:
713728
case Kind::OpaqueTypeDescriptor:
714729
return true;
730+
case Kind::AsyncFunctionPointer:
731+
case Kind::AsyncFunctionPointerAST:
715732
case Kind::PropertyDescriptor:
716733
case Kind::DispatchThunk:
717734
case Kind::DispatchThunkInitializer:
@@ -780,6 +797,8 @@ bool LinkEntity::isContextDescriptor() const {
780797

781798
llvm::Type *LinkEntity::getDefaultDeclarationType(IRGenModule &IGM) const {
782799
switch (getKind()) {
800+
case Kind::AsyncFunctionPointer:
801+
return IGM.AsyncFunctionPointerTy;
783802
case Kind::ModuleDescriptor:
784803
case Kind::ExtensionDescriptor:
785804
case Kind::AnonymousDescriptor:
@@ -909,6 +928,7 @@ Alignment LinkEntity::getAlignment(IRGenModule &IGM) const {
909928
case Kind::MethodDescriptorAllocator:
910929
case Kind::OpaqueTypeDescriptor:
911930
return Alignment(4);
931+
case Kind::AsyncFunctionPointer:
912932
case Kind::ObjCClassRef:
913933
case Kind::ObjCClass:
914934
case Kind::TypeMetadataLazyCacheVariable:
@@ -951,6 +971,7 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
951971
return getSILGlobalVariable()->getDecl()->isWeakImported(module);
952972
}
953973
return false;
974+
case Kind::AsyncFunctionPointer:
954975
case Kind::DynamicallyReplaceableFunctionKey:
955976
case Kind::DynamicallyReplaceableFunctionVariable:
956977
case Kind::SILFunction: {
@@ -977,6 +998,7 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
977998
return false;
978999
}
9791000

1001+
case Kind::AsyncFunctionPointerAST:
9801002
case Kind::DispatchThunk:
9811003
case Kind::DispatchThunkInitializer:
9821004
case Kind::DispatchThunkAllocator:
@@ -1053,6 +1075,7 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
10531075

10541076
DeclContext *LinkEntity::getDeclContextForEmission() const {
10551077
switch (getKind()) {
1078+
case Kind::AsyncFunctionPointerAST:
10561079
case Kind::DispatchThunk:
10571080
case Kind::DispatchThunkInitializer:
10581081
case Kind::DispatchThunkAllocator:
@@ -1095,6 +1118,7 @@ DeclContext *LinkEntity::getDeclContextForEmission() const {
10951118
case Kind::CanonicalSpecializedGenericSwiftMetaclassStub:
10961119
return getType()->getClassOrBoundGenericClass()->getDeclContext();
10971120

1121+
case Kind::AsyncFunctionPointer:
10981122
case Kind::SILFunction:
10991123
case Kind::DynamicallyReplaceableFunctionVariable:
11001124
case Kind::DynamicallyReplaceableFunctionKey:

0 commit comments

Comments
 (0)