Skip to content

Commit 2d463d7

Browse files
Merge pull request #36436 from nate-chandler/concurrency/irgen/nonconstant-async-partial-apply-thunk-mangling
[IRGen] Mangling for async, non-constant partial_apply thunks.
2 parents 8416578 + efaaee3 commit 2d463d7

File tree

9 files changed

+47
-1
lines changed

9 files changed

+47
-1
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ Globals
147147
// TODO check this::
148148
global ::= mangled-name 'TA' // partial application forwarder
149149
global ::= mangled-name 'Ta' // ObjC partial application forwarder
150+
global ::= mangled-name 'Tw' index // async partial apply thunk for a non-constant function
150151

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

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ NODE(AutoDiffSubsetParametersThunk)
316316
NODE(AutoDiffDerivativeVTableThunk)
317317
NODE(DifferentiabilityWitness)
318318
NODE(IndexSubset)
319+
NODE(AsyncNonconstantPartialApplyThunk)
319320

320321
#undef CONTEXT_NODE
321322
#undef NODE

lib/Demangling/Demangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ bool swift::Demangle::isFunctionAttr(Node::Kind kind) {
123123
case Node::Kind::DynamicallyReplaceableFunctionKey:
124124
case Node::Kind::DynamicallyReplaceableFunctionVar:
125125
case Node::Kind::AsyncFunctionPointer:
126+
case Node::Kind::AsyncNonconstantPartialApplyThunk:
126127
return true;
127128
default:
128129
return false;
@@ -2520,6 +2521,11 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
25202521
return demangleAutoDiffFunctionOrSimpleThunk(
25212522
Node::Kind::AutoDiffFunction);
25222523
}
2524+
case 'w': {
2525+
NodePointer discriminator = demangleIndexAsNode();
2526+
return createWithChild(Node::Kind::AsyncNonconstantPartialApplyThunk,
2527+
discriminator);
2528+
}
25232529
default:
25242530
return nullptr;
25252531
}

lib/Demangling/NodePrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,7 @@ class NodePrinter {
573573
case Node::Kind::AutoDiffFunctionKind:
574574
case Node::Kind::DifferentiabilityWitness:
575575
case Node::Kind::IndexSubset:
576+
case Node::Kind::AsyncNonconstantPartialApplyThunk:
576577
return false;
577578
}
578579
printer_unreachable("bad node kind");
@@ -2774,6 +2775,12 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
27742775
case Node::Kind::AsyncFunctionPointer:
27752776
Printer << "async function pointer to ";
27762777
return nullptr;
2778+
case Node::Kind::AsyncNonconstantPartialApplyThunk:
2779+
Printer << "(";
2780+
print(Node->getChild(0));
2781+
Printer << ")";
2782+
Printer << " thunk for non-constant partial apply in ";
2783+
return nullptr;
27772784
}
27782785
printer_unreachable("bad node kind!");
27792786
}

lib/Demangling/OldRemangler.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -606,6 +606,10 @@ void Remangler::mangleDynamicallyReplaceableFunctionVar(Node *node) {
606606
Buffer << "TX";
607607
}
608608

609+
void Remangler::mangleAsyncNonconstantPartialApplyThunk(Node *node) {
610+
unreachable("unsupported");
611+
}
612+
609613
void Remangler::mangleDirectness(Node *node) {
610614
auto getChar = [](Directness d) -> char {
611615
switch (d) {

lib/Demangling/Remangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1396,6 +1396,7 @@ void Remangler::mangleGlobal(Node *node) {
13961396
case Node::Kind::DynamicallyReplaceableFunctionImpl:
13971397
case Node::Kind::DynamicallyReplaceableFunctionVar:
13981398
case Node::Kind::AsyncFunctionPointer:
1399+
case Node::Kind::AsyncNonconstantPartialApplyThunk:
13991400
mangleInReverseOrder = true;
14001401
break;
14011402
default:
@@ -1904,6 +1905,11 @@ void Remangler::mangleDynamicallyReplaceableFunctionVar(Node *node) {
19041905
Buffer << "TX";
19051906
}
19061907

1908+
void Remangler::mangleAsyncNonconstantPartialApplyThunk(Node *node) {
1909+
Buffer << "Tw";
1910+
mangleChildNode(node, 0);
1911+
}
1912+
19071913
void Remangler::manglePostfixOperator(Node *node) {
19081914
mangleIdentifierImpl(node, /*isOperator*/ true);
19091915
Buffer << "oP";

lib/IRGen/IRGenMangler.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,23 @@ std::string IRGenMangler::manglePartialApplyForwarder(StringRef FuncName) {
7979
return finalize();
8080
}
8181

82+
std::string
83+
IRGenMangler::mangleAsyncNonconstantPartialApplyThunk(StringRef FuncName,
84+
unsigned index) {
85+
if (FuncName.empty()) {
86+
beginMangling();
87+
} else {
88+
if (FuncName.startswith(MANGLING_PREFIX_STR)) {
89+
Buffer << FuncName;
90+
} else {
91+
beginMangling();
92+
appendIdentifier(FuncName);
93+
}
94+
}
95+
appendOperator("Tw", Index(index));
96+
return finalize();
97+
}
98+
8299
SymbolicMangling
83100
IRGenMangler::withSymbolicReferences(IRGenModule &IGM,
84101
llvm::function_ref<void ()> body) {

lib/IRGen/IRGenMangler.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,9 @@ class IRGenMangler : public Mangle::ASTMangler {
574574
}
575575

576576
std::string manglePartialApplyForwarder(StringRef FuncName);
577-
577+
std::string mangleAsyncNonconstantPartialApplyThunk(StringRef FuncName,
578+
unsigned index);
579+
578580
std::string mangleTypeForForeignMetadataUniquing(Type type) {
579581
return mangleTypeWithoutPrefix(type);
580582
}

test/Demangle/Inputs/manglings.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,3 +388,5 @@ $sS2f8mangling3FooV13TangentVectorVIegydd_SfAESfIegydd_TJOp ---> autodiff self-r
388388
$s13test_mangling3fooyS2f_S2ftFWJrSpSr ---> reverse-mode differentiability witness for test_mangling.foo(Swift.Float, Swift.Float, Swift.Float) -> Swift.Float with respect to parameters {0} and results {0}
389389
$s13test_mangling3fooyS2f_xq_t16_Differentiation14DifferentiableR_r0_lFAcDRzAcDR_r0_lWJrUSSpSr ---> reverse-mode differentiability witness for test_mangling.foo<A, B where B: _Differentiation.Differentiable>(Swift.Float, A, B) -> Swift.Float with respect to parameters {1, 2} and results {0} with <A, B where A: _Differentiation.Differentiable, B: _Differentiation.Differentiable>
390390
$s5async1hyyS2iJXEF ---> async.h(@concurrent (Swift.Int) -> Swift.Int) -> ()
391+
$s12create_pa_f2Tw_ ---> (0) thunk for non-constant partial apply in create_pa_f2
392+
$s12create_pa_f2Tw0_ ---> (1) thunk for non-constant partial apply in create_pa_f2

0 commit comments

Comments
 (0)