Skip to content

Commit 1d93818

Browse files
authored
Merge pull request swiftlang#39787 from ktoso/distributed-func-in-actor-extension
2 parents 668fe4e + e1ae0be commit 1d93818

17 files changed

+92
-61
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ types where the metadata itself has unknown layout.)
217217
global ::= global 'To' // swift-as-ObjC thunk
218218
global ::= global 'TD' // dynamic dispatch thunk
219219
global ::= global 'Td' // direct method reference thunk
220+
global ::= global 'TE' // distributed actor thunk
220221
global ::= global 'TI' // implementation of a dynamic_replaceable function
221222
global ::= global 'Tu' // async function pointer of a function
222223
global ::= global 'TX' // function pointer of a dynamic_replaceable function

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ NODE(DependentProtocolConformanceAssociated)
7070
CONTEXT_NODE(Destructor)
7171
CONTEXT_NODE(DidSet)
7272
NODE(Directness)
73+
NODE(DistributedThunk)
7374
NODE(DynamicAttribute)
7475
NODE(DirectMethodReferenceAttribute)
7576
NODE(DynamicSelf)

lib/AST/ASTMangler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ void ASTMangler::appendSymbolKind(SymbolKind SKind) {
842842
case SymbolKind::DynamicThunk: return appendOperator("TD");
843843
case SymbolKind::SwiftAsObjCThunk: return appendOperator("To");
844844
case SymbolKind::ObjCAsSwiftThunk: return appendOperator("TO");
845-
case SymbolKind::DistributedThunk: return appendOperator("Td");
845+
case SymbolKind::DistributedThunk: return appendOperator("TE");
846846
}
847847
}
848848

lib/Demangling/Demangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ bool swift::Demangle::isFunctionAttr(Node::Kind kind) {
130130
case Node::Kind::OutlinedVariable:
131131
case Node::Kind::OutlinedBridgedMethod:
132132
case Node::Kind::MergedFunction:
133+
case Node::Kind::DistributedThunk:
133134
case Node::Kind::DynamicallyReplaceableFunctionImpl:
134135
case Node::Kind::DynamicallyReplaceableFunctionKey:
135136
case Node::Kind::DynamicallyReplaceableFunctionVar:
@@ -2359,6 +2360,7 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
23592360
case 'O': return createNode(Node::Kind::NonObjCAttribute);
23602361
case 'D': return createNode(Node::Kind::DynamicAttribute);
23612362
case 'd': return createNode(Node::Kind::DirectMethodReferenceAttribute);
2363+
case 'E': return createNode(Node::Kind::DistributedThunk);
23622364
case 'a': return createNode(Node::Kind::PartialApplyObjCForwarder);
23632365
case 'A': return createNode(Node::Kind::PartialApplyForwarder);
23642366
case 'm': return createNode(Node::Kind::MergedFunction);

lib/Demangling/NodePrinter.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,7 @@ class NodePrinter {
558558
case Node::Kind::ProtocolConformanceRefInTypeModule:
559559
case Node::Kind::ProtocolConformanceRefInProtocolModule:
560560
case Node::Kind::ProtocolConformanceRefInOtherModule:
561+
case Node::Kind::DistributedThunk:
561562
case Node::Kind::DynamicallyReplaceableFunctionKey:
562563
case Node::Kind::DynamicallyReplaceableFunctionImpl:
563564
case Node::Kind::DynamicallyReplaceableFunctionVar:
@@ -1986,6 +1987,11 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
19861987
Printer << "opaque type symbolic reference 0x";
19871988
Printer.writeHex(Node->getIndex());
19881989
return nullptr;
1990+
case Node::Kind::DistributedThunk:
1991+
if (!Options.ShortenThunk) {
1992+
Printer << "distributed thunk for ";
1993+
}
1994+
return nullptr;
19891995
case Node::Kind::DynamicallyReplaceableFunctionKey:
19901996
if (!Options.ShortenThunk) {
19911997
Printer << "dynamically replaceable key for ";

lib/Demangling/OldRemangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,12 @@ ManglingError Remangler::mangleMergedFunction(Node *node, unsigned depth) {
729729
return ManglingError::Success;
730730
}
731731

732+
ManglingError
733+
Remangler::mangleDistributedThunk(Node *node, unsigned depth) {
734+
Buffer << "TE";
735+
return ManglingError::Success;
736+
}
737+
732738
ManglingError
733739
Remangler::mangleDynamicallyReplaceableFunctionImpl(Node *node,
734740
unsigned depth) {

lib/Demangling/Remangler.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1610,6 +1610,7 @@ ManglingError Remangler::mangleGlobal(Node *node, unsigned depth) {
16101610
case Node::Kind::VTableAttribute:
16111611
case Node::Kind::DirectMethodReferenceAttribute:
16121612
case Node::Kind::MergedFunction:
1613+
case Node::Kind::DistributedThunk:
16131614
case Node::Kind::DynamicallyReplaceableFunctionKey:
16141615
case Node::Kind::DynamicallyReplaceableFunctionImpl:
16151616
case Node::Kind::DynamicallyReplaceableFunctionVar:
@@ -2241,6 +2242,12 @@ ManglingError Remangler::mangleMergedFunction(Node *node, unsigned depth) {
22412242
return ManglingError::Success;
22422243
}
22432244

2245+
ManglingError
2246+
Remangler::mangleDistributedThunk(Node *node, unsigned depth) {
2247+
Buffer << "TE";
2248+
return ManglingError::Success;
2249+
}
2250+
22442251
ManglingError
22452252
Remangler::mangleDynamicallyReplaceableFunctionImpl(Node *node,
22462253
unsigned depth) {

lib/IRGen/Linking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ std::string LinkEntity::mangleAsString() const {
477477
}
478478
case Kind::DistributedThunkAsyncFunctionPointer: {
479479
std::string Result = getSILDeclRef().mangle();
480-
Result.append("Td");
480+
Result.append("TE");
481481
Result.append("Tu");
482482
return Result;
483483
}

lib/SILGen/SILGen.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ static void emitOrDelayFunction(SILGenModule &SGM,
11441144
auto linkage = constant.getLinkage(ForDefinition);
11451145
bool mayDelay = !forceEmission &&
11461146
(constant.isImplicit() &&
1147+
!constant.isDynamicallyReplaceable() &&
11471148
!isPossiblyUsedExternally(linkage, SGM.M.isWholeModule()));
11481149

11491150
// Avoid emitting a delayable definition if it hasn't already been referenced.

lib/SILGen/SILGenDistributed.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -951,8 +951,20 @@ void SILGenFunction::emitDistributedThunk(SILDeclRef thunk) {
951951
auto nativeFnSILTy = SILType::getPrimitiveObjectType(nativeMethodTy);
952952
auto nativeSilFnType = nativeFnSILTy.castTo<SILFunctionType>();
953953

954-
SILValue nativeFn = emitClassMethodRef(
954+
bool isClassMethod = false;
955+
if (auto classDecl = dyn_cast<ClassDecl>(fd->getDeclContext())) {
956+
if (!classDecl->isFinal() && !fd->isFinal() &&
957+
!fd->hasForcedStaticDispatch())
958+
isClassMethod = true;
959+
}
960+
961+
SILValue nativeFn;
962+
if (isClassMethod) {
963+
nativeFn = emitClassMethodRef(
955964
loc, params[params.size() - 1], native, nativeMethodTy);
965+
} else {
966+
nativeFn = emitGlobalFunctionRef(loc, native);
967+
}
956968
auto subs = F.getForwardingSubstitutionMap();
957969

958970
if (nativeSilFnType->hasErrorResult()) {

0 commit comments

Comments
 (0)