Skip to content

Mangling for suspend/await resume partial functions #36429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ Globals
global ::= mangled-name 'TA' // partial application forwarder
global ::= mangled-name 'Ta' // ObjC partial application forwarder
global ::= mangled-name 'Tw' index // async partial apply thunk for a non-constant function
global ::= mangled-name 'TQ' index // Async await continuation partial function
global ::= mangled-name 'TY' index // Async suspend continuation partial function

global ::= type 'w' VALUE-WITNESS-KIND // value witness

Expand Down
2 changes: 2 additions & 0 deletions include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@ NODE(AutoDiffDerivativeVTableThunk)
NODE(DifferentiabilityWitness)
NODE(IndexSubset)
NODE(AsyncNonconstantPartialApplyThunk)
NODE(AsyncAwaitResumePartialFunction)
NODE(AsyncSuspendResumePartialFunction)

#undef CONTEXT_NODE
#undef NODE
10 changes: 10 additions & 0 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ bool swift::Demangle::isFunctionAttr(Node::Kind kind) {
case Node::Kind::DynamicallyReplaceableFunctionVar:
case Node::Kind::AsyncFunctionPointer:
case Node::Kind::AsyncNonconstantPartialApplyThunk:
case Node::Kind::AsyncAwaitResumePartialFunction:
case Node::Kind::AsyncSuspendResumePartialFunction:
return true;
default:
return false;
Expand Down Expand Up @@ -2297,6 +2299,14 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
case 'X': return createNode(Node::Kind::DynamicallyReplaceableFunctionVar);
case 'x': return createNode(Node::Kind::DynamicallyReplaceableFunctionKey);
case 'I': return createNode(Node::Kind::DynamicallyReplaceableFunctionImpl);
case 'Y':
case 'Q': {
NodePointer discriminator = demangleIndexAsNode();
return createWithChild(
c == 'Q' ? Node::Kind::AsyncAwaitResumePartialFunction :
/*'Y'*/ Node::Kind::AsyncSuspendResumePartialFunction,
discriminator);
}
case 'C': {
NodePointer type = popNode(Node::Kind::Type);
return createWithChild(Node::Kind::CoroutineContinuationPrototype, type);
Expand Down
15 changes: 15 additions & 0 deletions lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,8 @@ class NodePrinter {
case Node::Kind::DifferentiabilityWitness:
case Node::Kind::IndexSubset:
case Node::Kind::AsyncNonconstantPartialApplyThunk:
case Node::Kind::AsyncAwaitResumePartialFunction:
case Node::Kind::AsyncSuspendResumePartialFunction:
return false;
}
printer_unreachable("bad node kind");
Expand Down Expand Up @@ -2781,7 +2783,20 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
Printer << ")";
Printer << " thunk for non-constant partial apply in ";
return nullptr;
case Node::Kind::AsyncAwaitResumePartialFunction:
Printer << "(";
print(Node->getChild(0));
Printer << ")";
Printer << " await resume partial function for ";
return nullptr;
case Node::Kind::AsyncSuspendResumePartialFunction:
Printer << "(";
print(Node->getChild(0));
Printer << ")";
Printer << " suspend resume partial function for ";
return nullptr;
}

printer_unreachable("bad node kind!");
}

Expand Down
7 changes: 7 additions & 0 deletions lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,13 @@ void Remangler::mangleAsyncNonconstantPartialApplyThunk(Node *node) {
unreachable("unsupported");
}

void Remangler::mangleAsyncAwaitResumePartialFunction(Node *node) {
unreachable("unsupported");
}
void Remangler::mangleAsyncSuspendResumePartialFunction(Node *node) {
unreachable("unsupported");
}

void Remangler::mangleDirectness(Node *node) {
auto getChar = [](Directness d) -> char {
switch (d) {
Expand Down
12 changes: 12 additions & 0 deletions lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,8 @@ void Remangler::mangleGlobal(Node *node) {
case Node::Kind::DynamicallyReplaceableFunctionVar:
case Node::Kind::AsyncFunctionPointer:
case Node::Kind::AsyncNonconstantPartialApplyThunk:
case Node::Kind::AsyncAwaitResumePartialFunction:
case Node::Kind::AsyncSuspendResumePartialFunction:
mangleInReverseOrder = true;
break;
default:
Expand Down Expand Up @@ -1910,6 +1912,16 @@ void Remangler::mangleAsyncNonconstantPartialApplyThunk(Node *node) {
mangleChildNode(node, 0);
}

void Remangler::mangleAsyncAwaitResumePartialFunction(Node *node) {
Buffer << "TQ";
mangleChildNode(node, 0);
}

void Remangler::mangleAsyncSuspendResumePartialFunction(Node *node) {
Buffer << "TY";
mangleChildNode(node, 0);
}

void Remangler::manglePostfixOperator(Node *node) {
mangleIdentifierImpl(node, /*isOperator*/ true);
Buffer << "oP";
Expand Down
2 changes: 2 additions & 0 deletions test/Demangle/Inputs/manglings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,5 @@ $s13test_mangling3fooyS2f_xq_t16_Differentiation14DifferentiableR_r0_lFAcDRzAcDR
$s5async1hyyS2iJXEF ---> async.h(@concurrent (Swift.Int) -> Swift.Int) -> ()
$s12create_pa_f2Tw_ ---> (0) thunk for non-constant partial apply in create_pa_f2
$s12create_pa_f2Tw0_ ---> (1) thunk for non-constant partial apply in create_pa_f2
$s5Actor02MyA0C17testAsyncFunctionyyYKFTY0_ ---> (1) suspend resume partial function for Actor.MyActor.testAsyncFunction() async throws -> ()
$s5Actor02MyA0C17testAsyncFunctionyyYKFTQ1_ ---> (2) await resume partial function for Actor.MyActor.testAsyncFunction() async throws -> ()