Skip to content

Commit 73cfca8

Browse files
committed
[IRGen] Corrected mangling of AsyncFunctionPointers.
Previously, the suffix "AD" was used to mangle AsyncFunctionPointers. That was incorrect because it was already used in the mangling scheme. Here, that error is fixed by using 'u' under the thunk or specialization operator 'T' to mangle AsyncFunctionPointers. Additionally, printing and demangling support is added. rdar://problem/72336407
1 parent d89ffe7 commit 73cfca8

File tree

39 files changed

+55
-35
lines changed

39 files changed

+55
-35
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ types where the metadata itself has unknown layout.)
207207
global ::= global 'TD' // dynamic dispatch thunk
208208
global ::= global 'Td' // direct method reference thunk
209209
global ::= global 'TI' // implementation of a dynamic_replaceable function
210+
global :== global 'Tu' // async function pointer of a function
210211
global ::= global 'TX' // function pointer of a dynamic_replaceable function
211212
global ::= entity entity 'TV' // vtable override thunk, derived followed by base
212213
global ::= type label-list? 'D' // type mangling for the debugger with label list for function types.

include/swift/Demangling/DemangleNodes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,5 +306,8 @@ NODE(GlobalVariableOnceToken)
306306
NODE(GlobalVariableOnceDeclList)
307307
NODE(CanonicalPrespecializedGenericTypeCachingOnceToken)
308308

309+
// Added in Swift 5.5
310+
NODE(AsyncFunctionPointer)
311+
309312
#undef CONTEXT_NODE
310313
#undef NODE

lib/Demangling/Demangler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ bool swift::Demangle::isFunctionAttr(Node::Kind kind) {
122122
case Node::Kind::DynamicallyReplaceableFunctionImpl:
123123
case Node::Kind::DynamicallyReplaceableFunctionKey:
124124
case Node::Kind::DynamicallyReplaceableFunctionVar:
125+
case Node::Kind::AsyncFunctionPointer:
125126
return true;
126127
default:
127128
return false;
@@ -2473,6 +2474,7 @@ NodePointer Demangler::popProtocolConformance() {
24732474
return nullptr;
24742475
return createNode(Node::Kind::OutlinedBridgedMethod, Params);
24752476
}
2477+
case 'u': return createNode(Node::Kind::AsyncFunctionPointer);
24762478
default:
24772479
return nullptr;
24782480
}

lib/Demangling/NodePrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,7 @@ class NodePrinter {
564564
case Node::Kind::GlobalVariableOnceFunction:
565565
case Node::Kind::GlobalVariableOnceToken:
566566
case Node::Kind::CanonicalPrespecializedGenericTypeCachingOnceToken:
567+
case Node::Kind::AsyncFunctionPointer:
567568
return false;
568569
}
569570
printer_unreachable("bad node kind");
@@ -2552,6 +2553,9 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
25522553
"metadata for ";
25532554
print(Node->getChild(0));
25542555
return nullptr;
2556+
case Node::Kind::AsyncFunctionPointer:
2557+
Printer << "async function pointer to ";
2558+
return nullptr;
25552559
}
25562560
printer_unreachable("bad node kind!");
25572561
}

lib/Demangling/OldRemangler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,10 @@ void Remangler::mangleDefaultArgumentInitializer(Node *node,
816816
mangleNamedEntity(node, 'I', "A", ctx);
817817
}
818818

819+
void Remangler::mangleAsyncFunctionPointer(Node *node) {
820+
Buffer << "Tu";
821+
}
822+
819823
void Remangler::mangleDeallocator(Node *node, EntityContext &ctx) {
820824
mangleSimpleEntity(node, 'F', "D", ctx);
821825
}

lib/Demangling/Remangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,10 @@ void Remangler::mangleDefaultArgumentInitializer(Node *node) {
835835
mangleChildNode(node, 1);
836836
}
837837

838+
void Remangler::mangleAsyncFunctionPointer(Node *node) {
839+
Buffer << "Tu";
840+
}
841+
838842
void Remangler::mangleDependentAssociatedTypeRef(Node *node) {
839843
mangleIdentifier(node->getFirstChild());
840844
if (node->getNumChildren() > 1)
@@ -1382,6 +1386,7 @@ void Remangler::mangleGlobal(Node *node) {
13821386
case Node::Kind::DynamicallyReplaceableFunctionKey:
13831387
case Node::Kind::DynamicallyReplaceableFunctionImpl:
13841388
case Node::Kind::DynamicallyReplaceableFunctionVar:
1389+
case Node::Kind::AsyncFunctionPointer:
13851390
mangleInReverseOrder = true;
13861391
break;
13871392
default:

lib/IRGen/Linking.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,13 +432,13 @@ std::string LinkEntity::mangleAsString() const {
432432
getSILDifferentiabilityWitness()->getConfig()});
433433
case Kind::AsyncFunctionPointer: {
434434
std::string Result(getSILFunction()->getName());
435-
Result.append("AD");
435+
Result.append("Tu");
436436
return Result;
437437
}
438438
case Kind::AsyncFunctionPointerAST: {
439439
std::string Result;
440440
Result = mangler.mangleEntity(getDecl());
441-
Result.append("AD");
441+
Result.append("Tu");
442442
return Result;
443443
}
444444
}

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,3 +371,4 @@ $s7example1fyyYF -> example.f() async -> ()
371371
$s7example1fyyYKF -> example.f() async throws -> ()
372372
$s4main20receiveInstantiationyySo34__CxxTemplateInst12MagicWrapperIiEVzF ---> main.receiveInstantiation(inout __C.__CxxTemplateInst12MagicWrapperIiE) -> ()
373373
$s4main19returnInstantiationSo34__CxxTemplateInst12MagicWrapperIiEVyF ---> main.returnInstantiation() -> __C.__CxxTemplateInst12MagicWrapperIiE
374+
$s4main6testityyYFTu ---> async function pointer to main.testit() async -> ()

test/IRGen/async/run-call-classinstance-int64-to-void.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class S {
2929
init()
3030
}
3131

32-
// CHECK-LL: @classinstanceSInt64ToVoidAD =
32+
// CHECK-LL: @classinstanceSInt64ToVoidTu =
3333
// CHECK-LL: define hidden swiftcc void @classinstanceSInt64ToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}}) {{#[0-9]+}} {
3434
sil hidden @classinstanceSInt64ToVoid : $@async @convention(method) (Int64, @guaranteed S) -> () {
3535
bb0(%int : $Int64, %instance : $S):

test/IRGen/async/run-call-classinstance-void-to-void.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class S {
2929
init()
3030
}
3131

32-
// CHECK-LL: @classinstanceSVoidToVoidAD =
32+
// CHECK-LL: @classinstanceSVoidToVoidTu =
3333
// CHECK-LL: define hidden swiftcc void @classinstanceSVoidToVoid(%swift.task* {{%[0-9]+}}, %swift.executor* {{%[0-9]+}}, %swift.context* {{%[0-9]+}}) {{#[0-9]*}} {
3434
sil hidden @classinstanceSVoidToVoid : $@async @convention(method) (@guaranteed S) -> () {
3535
bb0(%instance : $S):

0 commit comments

Comments
 (0)