Skip to content

Commit 0f41071

Browse files
committed
[IRGen] Distributed: Switch DistributedAccessor linking to reference underlying thunks
Preparing to start emitting distributed requirement accessors that don't have `SILFunction *` because they are associated with protocol requirements.
1 parent 548f2f6 commit 0f41071

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

include/swift/IRGen/Linking.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,9 @@ class LinkEntity {
359359
/// the metadata cache once.
360360
CanonicalPrespecializedGenericTypeCachingOnceToken,
361361

362+
/// The function used to access distributed methods and accessors.
363+
DistributedAccessor,
364+
362365
/// The same as AsyncFunctionPointer but with a different stored value, for
363366
/// use by TBDGen.
364367
/// The pointer is an AbstractFunctionDecl*.
@@ -512,8 +515,6 @@ class LinkEntity {
512515
/// The pointer is a const char* of the name.
513516
KnownAsyncFunctionPointer,
514517

515-
/// The pointer is SILFunction*
516-
DistributedAccessor,
517518
/// An async function pointer for a distributed accessor (method or
518519
/// property).
519520
/// The pointer is a SILFunction*.
@@ -1341,6 +1342,10 @@ class LinkEntity {
13411342
}
13421343

13431344
static LinkEntity forDistributedTargetAccessor(SILFunction *target) {
1345+
return forDistributedTargetAccessor(target->getDeclContext()->getAsDecl());
1346+
}
1347+
1348+
static LinkEntity forDistributedTargetAccessor(Decl *target) {
13441349
LinkEntity entity;
13451350
entity.Pointer = target;
13461351
entity.SecondaryPointer = nullptr;

lib/IRGen/Linking.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ std::string LinkEntity::mangleAsString() const {
518518
}
519519

520520
case Kind::DistributedAccessor: {
521-
std::string Result(getSILFunction()->getName());
521+
std::string Result = getSILDeclRef().mangle();
522522
Result.append("TF");
523523
return Result;
524524
}
@@ -554,6 +554,7 @@ SILDeclRef::Kind LinkEntity::getSILDeclRefKind() const {
554554
switch (getKind()) {
555555
case Kind::DispatchThunk:
556556
case Kind::MethodDescriptor:
557+
case Kind::DistributedAccessor:
557558
return SILDeclRef::Kind::Func;
558559
case Kind::DispatchThunkInitializer:
559560
case Kind::MethodDescriptorInitializer:
@@ -571,7 +572,10 @@ SILDeclRef::Kind LinkEntity::getSILDeclRefKind() const {
571572
}
572573

573574
SILDeclRef LinkEntity::getSILDeclRef() const {
574-
return SILDeclRef(const_cast<ValueDecl *>(getDecl()), getSILDeclRefKind());
575+
auto ref = SILDeclRef(const_cast<ValueDecl *>(getDecl()), getSILDeclRefKind());
576+
if (getKind() == Kind::DistributedAccessor)
577+
return ref.asDistributed();
578+
return ref;
575579
}
576580

577581
SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {
@@ -1306,8 +1310,7 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
13061310
return false;
13071311
case Kind::DynamicallyReplaceableFunctionKey:
13081312
case Kind::DynamicallyReplaceableFunctionVariable:
1309-
case Kind::SILFunction:
1310-
case Kind::DistributedAccessor: {
1313+
case Kind::SILFunction: {
13111314
return getSILFunction()->isWeakImported(module);
13121315
}
13131316

@@ -1369,6 +1372,7 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
13691372
case Kind::OpaqueTypeDescriptorAccessorImpl:
13701373
case Kind::OpaqueTypeDescriptorAccessorKey:
13711374
case Kind::OpaqueTypeDescriptorAccessorVar:
1375+
case Kind::DistributedAccessor:
13721376
return getDecl()->isWeakImported(module);
13731377

13741378
case Kind::CanonicalSpecializedGenericSwiftMetaclassStub:
@@ -1480,6 +1484,7 @@ DeclContext *LinkEntity::getDeclContextForEmission() const {
14801484
case Kind::OpaqueTypeDescriptorAccessorKey:
14811485
case Kind::OpaqueTypeDescriptorAccessorVar:
14821486
case Kind::CanonicalPrespecializedGenericTypeCachingOnceToken:
1487+
case Kind::DistributedAccessor:
14831488
return getDecl()->getDeclContext();
14841489

14851490
case Kind::CanonicalSpecializedGenericSwiftMetaclassStub:
@@ -1555,7 +1560,6 @@ DeclContext *LinkEntity::getDeclContextForEmission() const {
15551560
return getUnderlyingEntityForAsyncFunctionPointer()
15561561
.getDeclContextForEmission();
15571562

1558-
case Kind::DistributedAccessor:
15591563
case Kind::AccessibleFunctionRecord: {
15601564
return getSILFunction()->getParentModule();
15611565
}

0 commit comments

Comments
 (0)