Skip to content

Commit 646e86b

Browse files
Merge pull request #34122 from varungandhi-apple/vg-fix-convention-demangling
[Demangler] Print convention attributes consistently.
2 parents 039be66 + 26d8283 commit 646e86b

File tree

2 files changed

+38
-49
lines changed

2 files changed

+38
-49
lines changed

lib/Demangling/NodePrinter.cpp

Lines changed: 36 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "swift/Demangling/Demangle.h"
1919
#include "swift/AST/Ownership.h"
2020
#include "swift/Strings.h"
21+
#include <cassert>
2122
#include <cstdio>
2223
#include <cstdlib>
2324

@@ -753,6 +754,35 @@ class NodePrinter {
753754
setInvalid();
754755
return;
755756
}
757+
758+
switch (node->getKind()) {
759+
case Node::Kind::FunctionType:
760+
case Node::Kind::UncurriedFunctionType:
761+
case Node::Kind::NoEscapeFunctionType:
762+
break;
763+
case Node::Kind::AutoClosureType:
764+
case Node::Kind::EscapingAutoClosureType:
765+
Printer << "@autoclosure "; break;
766+
case Node::Kind::ThinFunctionType:
767+
Printer << "@convention(thin) "; break;
768+
case Node::Kind::CFunctionPointer:
769+
Printer << "@convention(c) "; break;
770+
case Node::Kind::ObjCBlock:
771+
Printer << "@convention(block) "; break;
772+
case Node::Kind::EscapingObjCBlock:
773+
Printer << "@escaping @convention(block) "; break;
774+
case Node::Kind::DifferentiableFunctionType:
775+
Printer << "@differentiable "; break;
776+
case Node::Kind::EscapingDifferentiableFunctionType:
777+
Printer << "@escaping @differentiable "; break;
778+
case Node::Kind::LinearFunctionType:
779+
Printer << "@differentiable(linear) "; break;
780+
case Node::Kind::EscapingLinearFunctionType:
781+
Printer << "@escaping @differentiable(linear) "; break;
782+
default:
783+
assert(false && "Unhandled function type in printFunctionType!");
784+
}
785+
756786
unsigned startIndex = 0;
757787
bool isAsync = false, isThrows = false;
758788
if (node->getChild(startIndex)->getKind() == Node::Kind::ThrowsAnnotation) {
@@ -1256,39 +1286,19 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
12561286
case Node::Kind::UnknownIndex:
12571287
Printer << "unknown index";
12581288
return nullptr;
1289+
case Node::Kind::FunctionType:
1290+
case Node::Kind::UncurriedFunctionType:
12591291
case Node::Kind::NoEscapeFunctionType:
1260-
printFunctionType(nullptr, Node);
1261-
return nullptr;
1262-
case Node::Kind::EscapingAutoClosureType:
1263-
Printer << "@autoclosure ";
1264-
printFunctionType(nullptr, Node);
1265-
return nullptr;
12661292
case Node::Kind::AutoClosureType:
1267-
Printer << "@autoclosure ";
1268-
printFunctionType(nullptr, Node);
1269-
return nullptr;
1293+
case Node::Kind::EscapingAutoClosureType:
12701294
case Node::Kind::ThinFunctionType:
1271-
Printer << "@convention(thin) ";
1272-
printFunctionType(nullptr, Node);
1273-
return nullptr;
1295+
case Node::Kind::CFunctionPointer:
1296+
case Node::Kind::ObjCBlock:
1297+
case Node::Kind::EscapingObjCBlock:
12741298
case Node::Kind::DifferentiableFunctionType:
1275-
Printer << "@differentiable ";
1276-
printFunctionType(nullptr, Node);
1277-
return nullptr;
12781299
case Node::Kind::EscapingDifferentiableFunctionType:
1279-
Printer << "@escaping @differentiable ";
1280-
printFunctionType(nullptr, Node);
1281-
return nullptr;
12821300
case Node::Kind::LinearFunctionType:
1283-
Printer << "@differentiable(linear) ";
1284-
printFunctionType(nullptr, Node);
1285-
return nullptr;
12861301
case Node::Kind::EscapingLinearFunctionType:
1287-
Printer << "@escaping @differentiable(linear) ";
1288-
printFunctionType(nullptr, Node);
1289-
return nullptr;
1290-
case Node::Kind::FunctionType:
1291-
case Node::Kind::UncurriedFunctionType:
12921302
printFunctionType(nullptr, Node);
12931303
return nullptr;
12941304
case Node::Kind::ArgumentTuple:
@@ -1881,21 +1891,6 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
18811891
case Node::Kind::DynamicSelf:
18821892
Printer << "Self";
18831893
return nullptr;
1884-
case Node::Kind::CFunctionPointer: {
1885-
Printer << "@convention(c) ";
1886-
printFunctionType(nullptr, Node);
1887-
return nullptr;
1888-
}
1889-
case Node::Kind::ObjCBlock: {
1890-
Printer << "@convention(block) ";
1891-
printFunctionType(nullptr, Node);
1892-
return nullptr;
1893-
}
1894-
case Node::Kind::EscapingObjCBlock: {
1895-
Printer << "@escaping @convention(block) ";
1896-
printFunctionType(nullptr, Node);
1897-
return nullptr;
1898-
}
18991894
case Node::Kind::SILBoxType: {
19001895
Printer << "@box ";
19011896
NodePointer type = Node->getChild(0);
@@ -2648,14 +2643,6 @@ void NodePrinter::printEntityType(NodePointer Entity, NodePointer type,
26482643
Printer << ' ';
26492644
type = dependentType->getFirstChild();
26502645
}
2651-
if (type->getKind() == Node::Kind::DifferentiableFunctionType)
2652-
Printer << "@differentiable ";
2653-
else if (type->getKind() == Node::Kind::EscapingDifferentiableFunctionType)
2654-
Printer << "@escaping @differentiable ";
2655-
else if (type->getKind() == Node::Kind::LinearFunctionType)
2656-
Printer << "@differentiable(linear) ";
2657-
else if (type->getKind() == Node::Kind::EscapingLinearFunctionType)
2658-
Printer << "@escaping @differentiable(linear) ";
26592646
printFunctionType(labelList, type);
26602647
} else {
26612648
print(type);

test/Demangle/Inputs/manglings.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,8 @@ $s3red4testyAA3ResOyxSayq_GAEs5ErrorAAq_sAFHD1__HCg_GADyxq_GsAFR_r0_lF ---> red.
357357
$s3red4testyAA7OurTypeOy4them05TheirD0Vy5AssocQzGAjE0F8ProtocolAAxAA0c7DerivedH0HD1_AA0c4BaseH0HI1_AieKHA2__HCg_GxmAaLRzlF ---> red.test<A where A: red.OurDerivedProtocol>(A.Type) -> red.OurType<them.TheirType<A.Assoc>>
358358
$s17property_wrappers10WithTuplesV9fractionsSd_S2dtvpfP ---> property wrapper backing initializer of property_wrappers.WithTuples.fractions : (Swift.Double, Swift.Double, Swift.Double)
359359
$sSo17OS_dispatch_queueC4sync7executeyyyXE_tFTOTA ---> {T:$sSo17OS_dispatch_queueC4sync7executeyyyXE_tFTO} partial apply forwarder for @nonobjc __C.OS_dispatch_queue.sync(execute: () -> ()) -> ()
360+
$s4main1gyySiXCvp ---> main.g : @convention(c) (Swift.Int) -> ()
361+
$s4main1gyySiXBvp ---> main.g : @convention(block) (Swift.Int) -> ()
360362
$sxq_Idgnr_D ---> @differentiable @callee_guaranteed (@in_guaranteed A) -> (@out B)
361363
$sxq_Ilgnr_D ---> @differentiable(linear) @callee_guaranteed (@in_guaranteed A) -> (@out B)
362364
$sS3fIedgyywd_D ---> @escaping @differentiable @callee_guaranteed (@unowned Swift.Float, @unowned @noDerivative Swift.Float) -> (@unowned Swift.Float)

0 commit comments

Comments
 (0)