Skip to content

Commit 3806f91

Browse files
committed
[IRGen] Added LinkEntity for partial apply forwarder.
Up to now, there had been no need to define a LinkEntity for a partial apply forwarder. Now that async partial apply forwarders will each have their own async function pointer, an entity is needed to pass to the code that generates the async function pointers. No demangling or remangling changes are required because that code has existed for as long as partial apply forwarders to support demangling their symbols.
1 parent 27642b3 commit 3806f91

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

include/swift/IRGen/Linking.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,11 @@ class LinkEntity {
447447
/// context.
448448
/// The pointer is a SILFunction*.
449449
AsyncFunctionPointer,
450+
451+
/// The thunk provided for partially applying a function at some values
452+
/// which are captured.
453+
/// The pointer is an llvm::Function*.
454+
PartialApplyForwarder,
450455
};
451456
friend struct llvm::DenseMapInfo<LinkEntity>;
452457

@@ -1217,6 +1222,15 @@ class LinkEntity {
12171222
return entity;
12181223
}
12191224

1225+
static LinkEntity forPartialApplyForwarder(llvm::Function *function) {
1226+
LinkEntity entity;
1227+
entity.Pointer = function;
1228+
entity.SecondaryPointer = nullptr;
1229+
entity.Data =
1230+
LINKENTITY_SET_FIELD(Kind, unsigned(Kind::PartialApplyForwarder));
1231+
return entity;
1232+
}
1233+
12201234
void mangle(llvm::raw_ostream &out) const;
12211235
void mangle(SmallVectorImpl<char> &buffer) const;
12221236
std::string mangleAsString() const;

lib/IRGen/Linking.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ std::string LinkEntity::mangleAsString() const {
460460
Result.append("Tu");
461461
return Result;
462462
}
463+
case Kind::PartialApplyForwarder:
464+
std::string Result;
465+
Result = std::string(static_cast<llvm::Function *>(Pointer)->getName());
466+
return Result;
463467
}
464468
llvm_unreachable("bad entity kind!");
465469
}
@@ -740,6 +744,8 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {
740744
case Kind::DispatchThunkAllocatorAsyncFunctionPointer:
741745
return getUnderlyingEntityForAsyncFunctionPointer()
742746
.getLinkage(ForDefinition);
747+
case Kind::PartialApplyForwarder:
748+
return SILLinkage::Private;
743749
}
744750
llvm_unreachable("bad link entity kind");
745751
}
@@ -821,6 +827,7 @@ bool LinkEntity::isContextDescriptor() const {
821827
case Kind::NoncanonicalSpecializedGenericTypeMetadata:
822828
case Kind::NoncanonicalSpecializedGenericTypeMetadataCacheVariable:
823829
case Kind::CanonicalPrespecializedGenericTypeCachingOnceToken:
830+
case Kind::PartialApplyForwarder:
824831
return false;
825832
}
826833
llvm_unreachable("invalid descriptor");
@@ -937,6 +944,8 @@ llvm::Type *LinkEntity::getDefaultDeclarationType(IRGenModule &IGM) const {
937944
case Kind::DispatchThunkAllocatorAsyncFunctionPointer:
938945
case Kind::AsyncFunctionPointerAST:
939946
return IGM.AsyncFunctionPointerTy;
947+
case Kind::PartialApplyForwarder:
948+
return IGM.FunctionPtrTy;
940949
default:
941950
llvm_unreachable("declaration LLVM type not specified");
942951
}
@@ -992,6 +1001,7 @@ Alignment LinkEntity::getAlignment(IRGenModule &IGM) const {
9921001
case Kind::DifferentiabilityWitness:
9931002
case Kind::NoncanonicalSpecializedGenericTypeMetadata:
9941003
case Kind::NoncanonicalSpecializedGenericTypeMetadataCacheVariable:
1004+
case Kind::PartialApplyForwarder:
9951005
return IGM.getPointerAlignment();
9961006
case Kind::CanonicalPrespecializedGenericTypeCachingOnceToken:
9971007
case Kind::TypeMetadataDemanglingCacheVariable:
@@ -1086,6 +1096,7 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
10861096
// TODO: Revisit some of the below, for weak conformances.
10871097
case Kind::ObjCMetadataUpdateFunction:
10881098
case Kind::ObjCResilientClassStub:
1099+
case Kind::PartialApplyForwarder:
10891100
case Kind::TypeMetadataPattern:
10901101
case Kind::TypeMetadataInstantiationCache:
10911102
case Kind::TypeMetadataInstantiationFunction:
@@ -1221,6 +1232,7 @@ DeclContext *LinkEntity::getDeclContextForEmission() const {
12211232
case Kind::ValueWitness:
12221233
case Kind::ValueWitnessTable:
12231234
case Kind::DifferentiabilityWitness:
1235+
case Kind::PartialApplyForwarder:
12241236
return nullptr;
12251237

12261238
case Kind::AsyncFunctionPointer:

0 commit comments

Comments
 (0)