Skip to content
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
13 changes: 12 additions & 1 deletion include/swift/Basic/Mangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"

namespace swift {
Expand Down Expand Up @@ -100,14 +101,24 @@ class Mangler {
return StringRef(Storage.data(), Storage.size());
}

void print(llvm::raw_ostream &os) const {
os << getBufferStr() << '\n';
}

public:
/// Dump the current stored state in the Mangler. Only for use in the debugger!
SWIFT_DEBUG_DUMPER(dumpBufferStr()) {
print(llvm::dbgs());
}

protected:
/// Removes the last characters of the buffer by setting it's size to a
/// smaller value.
void resetBuffer(size_t toPos) {
assert(toPos <= Storage.size());
Storage.resize(toPos);
}

protected:
Mangler() : Buffer(Storage) { }

/// Begins a new mangling but does not add the mangling prefix.
Expand Down
1 change: 1 addition & 0 deletions include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ NODE(ImplEscaping)
NODE(ImplConvention)
NODE(ImplDifferentiabilityKind)
NODE(ImplErasedIsolation)
NODE(ImplTransferringResult)
NODE(ImplParameterResultDifferentiability)
NODE(ImplParameterTransferring)
NODE(ImplFunctionAttribute)
Expand Down
7 changes: 4 additions & 3 deletions lib/AST/ASTMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1987,9 +1987,6 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
if (!fn->isNoEscape())
OpArgs.push_back('e');

if (fn->hasTransferringResult())
OpArgs.push_back('T');

switch (fn->getIsolation()) {
case SILFunctionTypeIsolation::Unknown:
break;
Expand Down Expand Up @@ -2097,6 +2094,10 @@ void ASTMangler::appendImplFunctionType(SILFunctionType *fn,
appendType(param.getInterfaceType(), sig, forDecl);
}

// Mangle if we have a transferring result.
if (fn->hasTransferringResult())
OpArgs.push_back('T');

// Mangle the results.
for (auto result : fn->getResults()) {
OpArgs.push_back(getResultConvention(result.getConvention()));
Expand Down
5 changes: 5 additions & 0 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2319,6 +2319,11 @@ NodePointer Demangler::demangleImplFunctionType() {
Param = addChild(Param, Transferring);
++NumTypesToAdd;
}

if (nextIf('T')) {
type->addChild(createNode(Node::Kind::ImplTransferringResult), *this);
}

while (NodePointer Result = demangleImplResultConvention(
Node::Kind::ImplResult)) {
type = addChild(type, Result);
Expand Down
16 changes: 15 additions & 1 deletion lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ class NodePrinter {
case Node::Kind::ImplDifferentiabilityKind:
case Node::Kind::ImplEscaping:
case Node::Kind::ImplErasedIsolation:
case Node::Kind::ImplTransferringResult:
case Node::Kind::ImplConvention:
case Node::Kind::ImplParameterResultDifferentiability:
case Node::Kind::ImplParameterTransferring:
Expand Down Expand Up @@ -975,6 +976,7 @@ class NodePrinter {
void printImplFunctionType(NodePointer fn, unsigned depth) {
NodePointer patternSubs = nullptr;
NodePointer invocationSubs = nullptr;
NodePointer transferringResult = nullptr;
enum State { Attrs, Inputs, Results } curState = Attrs;
auto transitionTo = [&](State newState) {
assert(newState >= curState);
Expand All @@ -988,7 +990,14 @@ class NodePrinter {
}
Printer << '(';
continue;
case Inputs: Printer << ") -> ("; continue;
case Inputs:
Printer << ") -> ";
if (transferringResult) {
print(transferringResult, depth + 1);
Printer << " ";
}
Printer << "(";
continue;
case Results: printer_unreachable("no state after Results");
}
printer_unreachable("bad state");
Expand All @@ -1010,6 +1019,8 @@ class NodePrinter {
patternSubs = child;
} else if (child->getKind() == Node::Kind::ImplInvocationSubstitutions) {
invocationSubs = child;
} else if (child->getKind() == Node::Kind::ImplTransferringResult) {
transferringResult = child;
} else {
assert(curState == Attrs);
print(child, depth + 1);
Expand Down Expand Up @@ -2748,6 +2759,9 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
case Node::Kind::ImplErasedIsolation:
Printer << "@isolated(any)";
return nullptr;
case Node::Kind::ImplTransferringResult:
Printer << "transferring";
return nullptr;
case Node::Kind::ImplConvention:
Printer << Node->getText();
return nullptr;
Expand Down
6 changes: 6 additions & 0 deletions lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1736,6 +1736,12 @@ ManglingError Remangler::mangleImplErasedIsolation(Node *node, unsigned depth) {
return ManglingError::Success;
}

ManglingError Remangler::mangleImplTransferringResult(Node *node,
unsigned depth) {
// The old mangler does not encode transferring result
return ManglingError::Success;
}

ManglingError Remangler::mangleImplPatternSubstitutions(Node *node,
unsigned depth) {
// The old mangler does not encode substituted function types.
Expand Down
9 changes: 9 additions & 0 deletions lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1781,6 +1781,12 @@ ManglingError Remangler::mangleImplErasedIsolation(Node *node, unsigned depth) {
return ManglingError::Success;
}

ManglingError Remangler::mangleImplTransferringResult(Node *node,
unsigned depth) {
Buffer << 'T';
return ManglingError::Success;
}

ManglingError Remangler::mangleImplConvention(Node *node, unsigned depth) {
char ConvCh = llvm::StringSwitch<char>(node->getText())
.Case("@callee_unowned", 'y')
Expand Down Expand Up @@ -1955,6 +1961,9 @@ ManglingError Remangler::mangleImplFunctionType(Node *node, unsigned depth) {
case Node::Kind::ImplErasedIsolation:
Buffer << 'A';
break;
case Node::Kind::ImplTransferringResult:
Buffer << 'T';
break;
case Node::Kind::ImplConvention: {
char ConvCh = llvm::StringSwitch<char>(Child->getText())
.Case("@callee_unowned", 'y')
Expand Down
1 change: 1 addition & 0 deletions test/Demangle/Inputs/manglings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,4 @@ $sS3fIedgyyTd_D ---> @escaping @differentiable @callee_guaranteed (@unowned Swif
$s4testA2A5KlassCyYTF ---> test.test() -> transferring test.Klass
$s4main5KlassCACYTcMD ---> demangling cache variable for type metadata for (main.Klass) -> transferring main.Klass
$s4null19transferAsyncResultAA16NonSendableKlassCyYaYTF ---> null.transferAsyncResult() -> transferring null.NonSendableKlass
$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)