Skip to content

Commit 97a8913

Browse files
authored
Merge pull request #72080 from gottesmm/pr-1ceed601a7f309b017b034969164c2ec5050e7e4
[transferring] Fix mangling for reabstraction thunks with a transferring result.
2 parents 753a940 + 29db927 commit 97a8913

File tree

8 files changed

+53
-5
lines changed

8 files changed

+53
-5
lines changed

include/swift/Basic/Mangler.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "llvm/ADT/SmallString.h"
2222
#include "llvm/ADT/StringRef.h"
2323
#include "llvm/ADT/StringMap.h"
24+
#include "llvm/Support/Debug.h"
2425
#include "llvm/Support/raw_ostream.h"
2526

2627
namespace swift {
@@ -100,14 +101,24 @@ class Mangler {
100101
return StringRef(Storage.data(), Storage.size());
101102
}
102103

104+
void print(llvm::raw_ostream &os) const {
105+
os << getBufferStr() << '\n';
106+
}
107+
108+
public:
109+
/// Dump the current stored state in the Mangler. Only for use in the debugger!
110+
SWIFT_DEBUG_DUMPER(dumpBufferStr()) {
111+
print(llvm::dbgs());
112+
}
113+
114+
protected:
103115
/// Removes the last characters of the buffer by setting it's size to a
104116
/// smaller value.
105117
void resetBuffer(size_t toPos) {
106118
assert(toPos <= Storage.size());
107119
Storage.resize(toPos);
108120
}
109121

110-
protected:
111122
Mangler() : Buffer(Storage) { }
112123

113124
/// Begins a new mangling but does not add the mangling prefix.

include/swift/Demangling/DemangleNodes.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ NODE(ImplEscaping)
132132
NODE(ImplConvention)
133133
NODE(ImplDifferentiabilityKind)
134134
NODE(ImplErasedIsolation)
135+
NODE(ImplTransferringResult)
135136
NODE(ImplParameterResultDifferentiability)
136137
NODE(ImplParameterTransferring)
137138
NODE(ImplFunctionAttribute)

lib/AST/ASTMangler.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1987,9 +1987,6 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
19871987
if (!fn->isNoEscape())
19881988
OpArgs.push_back('e');
19891989

1990-
if (fn->hasTransferringResult())
1991-
OpArgs.push_back('T');
1992-
19931990
switch (fn->getIsolation()) {
19941991
case SILFunctionTypeIsolation::Unknown:
19951992
break;
@@ -2097,6 +2094,10 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
20972094
appendType(param.getInterfaceType(), sig, forDecl);
20982095
}
20992096

2097+
// Mangle if we have a transferring result.
2098+
if (fn->hasTransferringResult())
2099+
OpArgs.push_back('T');
2100+
21002101
// Mangle the results.
21012102
for (auto result : fn->getResults()) {
21022103
OpArgs.push_back(getResultConvention(result.getConvention()));

lib/Demangling/Demangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,6 +2319,11 @@ NodePointer Demangler::demangleImplFunctionType() {
23192319
Param = addChild(Param, Transferring);
23202320
++NumTypesToAdd;
23212321
}
2322+
2323+
if (nextIf('T')) {
2324+
type->addChild(createNode(Node::Kind::ImplTransferringResult), *this);
2325+
}
2326+
23222327
while (NodePointer Result = demangleImplResultConvention(
23232328
Node::Kind::ImplResult)) {
23242329
type = addChild(type, Result);

lib/Demangling/NodePrinter.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ class NodePrinter {
425425
case Node::Kind::ImplDifferentiabilityKind:
426426
case Node::Kind::ImplEscaping:
427427
case Node::Kind::ImplErasedIsolation:
428+
case Node::Kind::ImplTransferringResult:
428429
case Node::Kind::ImplConvention:
429430
case Node::Kind::ImplParameterResultDifferentiability:
430431
case Node::Kind::ImplParameterTransferring:
@@ -975,6 +976,7 @@ class NodePrinter {
975976
void printImplFunctionType(NodePointer fn, unsigned depth) {
976977
NodePointer patternSubs = nullptr;
977978
NodePointer invocationSubs = nullptr;
979+
NodePointer transferringResult = nullptr;
978980
enum State { Attrs, Inputs, Results } curState = Attrs;
979981
auto transitionTo = [&](State newState) {
980982
assert(newState >= curState);
@@ -988,7 +990,14 @@ class NodePrinter {
988990
}
989991
Printer << '(';
990992
continue;
991-
case Inputs: Printer << ") -> ("; continue;
993+
case Inputs:
994+
Printer << ") -> ";
995+
if (transferringResult) {
996+
print(transferringResult, depth + 1);
997+
Printer << " ";
998+
}
999+
Printer << "(";
1000+
continue;
9921001
case Results: printer_unreachable("no state after Results");
9931002
}
9941003
printer_unreachable("bad state");
@@ -1010,6 +1019,8 @@ class NodePrinter {
10101019
patternSubs = child;
10111020
} else if (child->getKind() == Node::Kind::ImplInvocationSubstitutions) {
10121021
invocationSubs = child;
1022+
} else if (child->getKind() == Node::Kind::ImplTransferringResult) {
1023+
transferringResult = child;
10131024
} else {
10141025
assert(curState == Attrs);
10151026
print(child, depth + 1);
@@ -2748,6 +2759,9 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
27482759
case Node::Kind::ImplErasedIsolation:
27492760
Printer << "@isolated(any)";
27502761
return nullptr;
2762+
case Node::Kind::ImplTransferringResult:
2763+
Printer << "transferring";
2764+
return nullptr;
27512765
case Node::Kind::ImplConvention:
27522766
Printer << Node->getText();
27532767
return nullptr;

lib/Demangling/OldRemangler.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,6 +1736,12 @@ ManglingError Remangler::mangleImplErasedIsolation(Node *node, unsigned depth) {
17361736
return ManglingError::Success;
17371737
}
17381738

1739+
ManglingError Remangler::mangleImplTransferringResult(Node *node,
1740+
unsigned depth) {
1741+
// The old mangler does not encode transferring result
1742+
return ManglingError::Success;
1743+
}
1744+
17391745
ManglingError Remangler::mangleImplPatternSubstitutions(Node *node,
17401746
unsigned depth) {
17411747
// The old mangler does not encode substituted function types.

lib/Demangling/Remangler.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,6 +1781,12 @@ ManglingError Remangler::mangleImplErasedIsolation(Node *node, unsigned depth) {
17811781
return ManglingError::Success;
17821782
}
17831783

1784+
ManglingError Remangler::mangleImplTransferringResult(Node *node,
1785+
unsigned depth) {
1786+
Buffer << 'T';
1787+
return ManglingError::Success;
1788+
}
1789+
17841790
ManglingError Remangler::mangleImplConvention(Node *node, unsigned depth) {
17851791
char ConvCh = llvm::StringSwitch<char>(node->getText())
17861792
.Case("@callee_unowned", 'y')
@@ -1955,6 +1961,9 @@ ManglingError Remangler::mangleImplFunctionType(Node *node, unsigned depth) {
19551961
case Node::Kind::ImplErasedIsolation:
19561962
Buffer << 'A';
19571963
break;
1964+
case Node::Kind::ImplTransferringResult:
1965+
Buffer << 'T';
1966+
break;
19581967
case Node::Kind::ImplConvention: {
19591968
char ConvCh = llvm::StringSwitch<char>(Child->getText())
19601969
.Case("@callee_unowned", 'y')

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,4 @@ $sS3fIedgyyTd_D ---> @escaping @differentiable @callee_guaranteed (@unowned Swif
467467
$s4testA2A5KlassCyYTF ---> test.test() -> transferring test.Klass
468468
$s4main5KlassCACYTcMD ---> demangling cache variable for type metadata for (main.Klass) -> transferring main.Klass
469469
$s4null19transferAsyncResultAA16NonSendableKlassCyYaYTF ---> null.transferAsyncResult() -> transferring null.NonSendableKlass
470+
$s4null16NonSendableKlassCIegHo_ACs5Error_pIegHTrzo_TR ---> {T:} reabstraction thunk helper from @escaping @callee_guaranteed @async () -> (@owned null.NonSendableKlass) to @escaping @callee_guaranteed @async () -> transferring (@out null.NonSendableKlass, @error @owned Swift.Error)

0 commit comments

Comments
 (0)