Skip to content

Commit 783b619

Browse files
authored
Merge pull request #39499 from ktoso/wip-tbd-fix-distributed
[Distributed] fix missing _remote func entry in TBD
2 parents ff3eeae + 6834f61 commit 783b619

File tree

5 files changed

+58
-6
lines changed

5 files changed

+58
-6
lines changed

include/swift/IRGen/Linking.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,10 @@ class LinkEntity {
153153
/// a class.
154154
DispatchThunkAllocatorAsyncFunctionPointer,
155155

156+
/// An async function pointer for a distributed thunk.
157+
/// The pointer is a FuncDecl* inside an actor (class).
158+
DistributedThunkAsyncFunctionPointer,
159+
156160
/// A method descriptor. The pointer is a FuncDecl* inside a protocol
157161
/// or a class.
158162
MethodDescriptor,
@@ -1198,7 +1202,9 @@ class LinkEntity {
11981202

11991203
static LinkEntity forAsyncFunctionPointer(SILDeclRef declRef) {
12001204
LinkEntity entity;
1201-
entity.setForDecl(Kind::AsyncFunctionPointerAST,
1205+
entity.setForDecl(declRef.isDistributedThunk()
1206+
? Kind::DistributedThunkAsyncFunctionPointer
1207+
: Kind::AsyncFunctionPointerAST,
12021208
declRef.getAbstractFunctionDecl());
12031209
entity.SecondaryPointer =
12041210
reinterpret_cast<void *>(static_cast<uintptr_t>(declRef.kind));
@@ -1264,6 +1270,8 @@ class LinkEntity {
12641270
void mangle(llvm::raw_ostream &out) const;
12651271
void mangle(SmallVectorImpl<char> &buffer) const;
12661272
std::string mangleAsString() const;
1273+
1274+
SILDeclRef getSILDeclRef() const;
12671275
SILLinkage getLinkage(ForDefinition_t isDefinition) const;
12681276

12691277
bool hasDecl() const {

lib/FrontendTool/TBD.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ static bool validateSymbols(DiagnosticEngine &diags,
7676
// symbol table, so make sure to mangle IRGen names before comparing them
7777
// with what TBDGen created.
7878
auto unmangledName = nameValue.getKey();
79+
7980
SmallString<128> name;
8081
llvm::Mangler::getNameWithPrefix(name, unmangledName,
8182
IRModule.getDataLayout());

lib/IRGen/Linking.cpp

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,18 +460,20 @@ std::string LinkEntity::mangleAsString() const {
460460
Result.append("Tu");
461461
return Result;
462462
}
463+
case Kind::DistributedThunkAsyncFunctionPointer: {
464+
std::string Result = getSILDeclRef().mangle();
465+
Result.append("Td");
466+
Result.append("Tu");
467+
return Result;
468+
}
463469
case Kind::KnownAsyncFunctionPointer: {
464470
std::string Result(static_cast<char *>(Pointer));
465471
Result.append("Tu");
466472
return Result;
467473
}
468474

469475
case Kind::AsyncFunctionPointerAST: {
470-
std::string Result;
471-
Result = SILDeclRef(const_cast<ValueDecl *>(getDecl()),
472-
static_cast<SILDeclRef::Kind>(
473-
reinterpret_cast<uintptr_t>(SecondaryPointer)))
474-
.mangle();
476+
std::string Result = getSILDeclRef().mangle();
475477
Result.append("Tu");
476478
return Result;
477479
}
@@ -483,6 +485,15 @@ std::string LinkEntity::mangleAsString() const {
483485
llvm_unreachable("bad entity kind!");
484486
}
485487

488+
SILDeclRef LinkEntity::getSILDeclRef() const {
489+
assert(getKind() == Kind::DistributedThunkAsyncFunctionPointer ||
490+
getKind() == Kind::AsyncFunctionPointerAST);
491+
492+
return SILDeclRef(const_cast<ValueDecl *>(getDecl()),
493+
static_cast<SILDeclRef::Kind>(
494+
reinterpret_cast<uintptr_t>(SecondaryPointer)));
495+
}
496+
486497
SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {
487498
// For when `this` is a protocol conformance of some kind.
488499
auto getLinkageAsConformance = [&] {
@@ -717,6 +728,7 @@ SILLinkage LinkEntity::getLinkage(ForDefinition_t forDefinition) const {
717728
return getSILFunction()->getEffectiveSymbolLinkage();
718729

719730
case Kind::AsyncFunctionPointerAST:
731+
case Kind::DistributedThunkAsyncFunctionPointer:
720732
return getSILLinkage(getDeclLinkage(getDecl()), forDefinition);
721733

722734
case Kind::DynamicallyReplaceableFunctionImpl:
@@ -779,6 +791,7 @@ bool LinkEntity::isContextDescriptor() const {
779791
return true;
780792
case Kind::AsyncFunctionPointer:
781793
case Kind::AsyncFunctionPointerAST:
794+
case Kind::DistributedThunkAsyncFunctionPointer:
782795
case Kind::PropertyDescriptor:
783796
case Kind::DispatchThunk:
784797
case Kind::DispatchThunkDerivative:
@@ -962,6 +975,7 @@ llvm::Type *LinkEntity::getDefaultDeclarationType(IRGenModule &IGM) const {
962975
case Kind::DispatchThunkAsyncFunctionPointer:
963976
case Kind::DispatchThunkInitializerAsyncFunctionPointer:
964977
case Kind::DispatchThunkAllocatorAsyncFunctionPointer:
978+
case Kind::DistributedThunkAsyncFunctionPointer:
965979
case Kind::PartialApplyForwarderAsyncFunctionPointer:
966980
case Kind::AsyncFunctionPointerAST:
967981
case Kind::KnownAsyncFunctionPointer:
@@ -1071,6 +1085,7 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
10711085
}
10721086

10731087
case Kind::AsyncFunctionPointerAST:
1088+
case Kind::DistributedThunkAsyncFunctionPointer:
10741089
case Kind::DispatchThunk:
10751090
case Kind::DispatchThunkDerivative:
10761091
case Kind::DispatchThunkInitializer:
@@ -1165,6 +1180,7 @@ bool LinkEntity::isWeakImported(ModuleDecl *module) const {
11651180
DeclContext *LinkEntity::getDeclContextForEmission() const {
11661181
switch (getKind()) {
11671182
case Kind::AsyncFunctionPointerAST:
1183+
case Kind::DistributedThunkAsyncFunctionPointer:
11681184
case Kind::DispatchThunk:
11691185
case Kind::DispatchThunkDerivative:
11701186
case Kind::DispatchThunkInitializer:

lib/TBDGen/TBDGen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,7 @@ void TBDGenVisitor::visitAbstractFunctionDecl(AbstractFunctionDecl *AFD) {
718718

719719
if (AFD->isDistributed()) {
720720
addSymbol(SILDeclRef(AFD).asDistributed());
721+
addAsyncFunctionPointerSymbol(SILDeclRef(AFD).asDistributed());
721722
}
722723

723724
// Add derivative function symbols.

test/TBD/distributed.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// REQUIRES: VENDOR=apple
2+
// REQUIRES: concurrency
3+
// REQUIRES: distributed
4+
5+
// RUN: %empty-directory(%t)
6+
// RUN: %target-swift-frontend %s -enable-testing -enable-experimental-distributed -disable-availability-checking -emit-ir -o %t/test.ll -emit-tbd -emit-tbd-path %t/test.tbd
7+
// RUN cat %t/test.tbd | %FileCheck %s --dump-input=always
8+
9+
import _Distributed
10+
11+
// CHECK: @"$s4test1AC13_remote_helloyyYaKFTd" = hidden global %swift.async_func_pointer
12+
// CHECK: @"$s4test1AC13_remote_helloyyYaKFTdTu" = hidden global %swift.async_func_pointer
13+
distributed actor SomeDistributedActor {
14+
distributed func hello(name: String) -> String {
15+
"Hello, \(name)!"
16+
}
17+
}
18+
19+
// function:
20+
// IR unmangledName = $s4test20SomeDistributedActorC5hello4nameS2S_tF
21+
// function method descriptor
22+
// IR unmangledName = $s4test20SomeDistributedActorC5hello4nameS2S_tFTq
23+
// thunk, method reference
24+
// IR unmangledName = $s4test20SomeDistributedActorC5hello4nameS2S_tFTd
25+
// thunk, method reference + async function pointer
26+
// IR unmangledName = $s4test20SomeDistributedActorC5hello4nameS2S_tFTdTu

0 commit comments

Comments
 (0)