Skip to content

Commit 142973b

Browse files
committed
Use a non-conflicting mangling for distributed thunks.
Distributed thunks were using the same mangling as direct method reference thunks (i.e., for "super" calls). Although not technically conflicting so long as actors never gain inheritance, it's confusing and could cause problems in the future. So, introduce a distinct mangling for distributed thunks and plumb them through the demangling and remangler.
1 parent d366979 commit 142973b

File tree

9 files changed

+26
-2
lines changed

9 files changed

+26
-2
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) {

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,3 +420,4 @@ $sSIxip6foobarP ---> foobar in Swift.DefaultIndices.subscript : A
420420
$s13__lldb_expr_110$10016c2d8yXZ1B10$10016c2e0LLC ---> __lldb_expr_1.(unknown context at $10016c2d8).(B in $10016c2e0)
421421
$s__TJO ---> $s__TJO
422422
$s6Foobar7Vector2VAASdRszlE10simdMatrix5scale6rotate9translateSo0C10_double3x3aACySdG_SdAJtFZ0D4TypeL_aySd__GD ---> MatrixType #1 in static (extension in Foobar):Foobar.Vector2<Swift.Double><A where A == Swift.Double>.simdMatrix(scale: Foobar.Vector2<Swift.Double>, rotate: Swift.Double, translate: Foobar.Vector2<Swift.Double>) -> __C.simd_double3x3
423+
$s17distributed_thunk2DAC1fyyFTE ---> distributed thunk for distributed_thunk.DA.f() -> ()

test/SILGen/distributed_thunk.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import _Distributed
77
distributed actor DA { }
88

99
extension DA {
10-
// CHECK-LABEL: sil hidden [thunk] [ossa] @$s17distributed_thunk2DAC1fyyFTd : $@convention(method) @async (@guaranteed DA) -> @error Error
10+
// CHECK-LABEL: sil hidden [thunk] [ossa] @$s17distributed_thunk2DAC1fyyFTE : $@convention(method) @async (@guaranteed DA) -> @error Error
1111
// CHECK: function_ref @swift_distributed_actor_is_remote
1212

1313
// Call the actor function

0 commit comments

Comments
 (0)