Skip to content

Commit 9893a3e

Browse files
committed
Mangling: add a new mangling for generic specialization
For performance annotations we need the generic specializer to trop non-generic metatype argumentrs (which we don't do in general). For this we need a separate mangling.
1 parent f06fab8 commit 9893a3e

File tree

9 files changed

+47
-5
lines changed

9 files changed

+47
-5
lines changed

docs/ABI/Mangling.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1133,7 +1133,7 @@ Some kinds need arguments, which precede ``Tf``.
11331133
spec-arg ::= identifier
11341134
spec-arg ::= type
11351135

1136-
SPEC-INFO ::= FRAGILE? PASSID
1136+
SPEC-INFO ::= MT-REMOVED? FRAGILE? PASSID
11371137

11381138
PASSID ::= '0' // AllocBoxToStack,
11391139
PASSID ::= '1' // ClosureSpecializer,
@@ -1142,6 +1142,8 @@ Some kinds need arguments, which precede ``Tf``.
11421142
PASSID ::= '4' // FunctionSignatureOpts,
11431143
PASSID ::= '5' // GenericSpecializer,
11441144

1145+
MT-REMOVED ::= 'm' // non-generic metatype arguments are removed in the specialized function
1146+
11451147
FRAGILE ::= 'q'
11461148

11471149
ARG-SPEC-KIND ::= 'n' // Unmodified argument

include/swift/Demangling/DemangleNodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,5 +344,7 @@ NODE(UniqueExtendedExistentialTypeShapeSymbolicReference)
344344
NODE(NonUniqueExtendedExistentialTypeShapeSymbolicReference)
345345
NODE(SymbolicExtendedExistentialType)
346346

347+
NODE(MetatypeParamsRemoved)
348+
347349
#undef CONTEXT_NODE
348350
#undef NODE

include/swift/SIL/GenericSpecializationMangler.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,19 @@ class GenericSpecializationMangler : public SpecializationMangler {
9090

9191
std::string mangleNotReabstracted(SubstitutionMap subs);
9292

93-
std::string mangleReabstracted(SubstitutionMap subs, bool alternativeMangling);
93+
/// Mangle a generic specialization with re-abstracted parameters.
94+
///
95+
/// Re-abstracted means that indirect (generic) parameters/returns are
96+
/// converted to direct parameters/returns.
97+
///
98+
/// This is the default for generic specializations.
99+
///
100+
/// \param alternativeMangling true for specialized functions with a
101+
/// differet resilience expansion.
102+
/// \param metatyeParamsRemoved true if non-generic metatype parameters are
103+
/// removed in the specialized function.
104+
std::string mangleReabstracted(SubstitutionMap subs, bool alternativeMangling,
105+
bool metatyeParamsRemoved = false);
94106

95107
std::string mangleForDebugInfo(GenericSignature sig, SubstitutionMap subs,
96108
bool forInlining);

lib/Demangling/Demangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3040,13 +3040,18 @@ NodePointer Demangler::addFuncSpecParamNumber(NodePointer Param,
30403040
}
30413041

30423042
NodePointer Demangler::demangleSpecAttributes(Node::Kind SpecKind) {
3043+
bool metatypeParamsRemoved = nextIf('m');
30433044
bool isSerialized = nextIf('q');
30443045

30453046
int PassID = (int)nextChar() - '0';
30463047
if (PassID < 0 || PassID > 9)
30473048
return nullptr;
30483049

30493050
NodePointer SpecNd = createNode(SpecKind);
3051+
3052+
if (metatypeParamsRemoved)
3053+
SpecNd->addChild(createNode(Node::Kind::MetatypeParamsRemoved), *this);
3054+
30503055
if (isSerialized)
30513056
SpecNd->addChild(createNode(Node::Kind::IsSerialized),
30523057
*this);

lib/Demangling/NodePrinter.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@ class NodePrinter {
496496
case Node::Kind::SILBoxMutableField:
497497
case Node::Kind::SILBoxImmutableField:
498498
case Node::Kind::IsSerialized:
499+
case Node::Kind::MetatypeParamsRemoved:
499500
case Node::Kind::SpecializationPassID:
500501
case Node::Kind::Static:
501502
case Node::Kind::Subscript:
@@ -1127,7 +1128,8 @@ void NodePrinter::printSpecializationPrefix(NodePointer node,
11271128
for (NodePointer child : *node) {
11281129
switch (child->getKind()) {
11291130
case Node::Kind::SpecializationPassID:
1130-
// We skip the SpecializationPassID since it does not contain any
1131+
case Node::Kind::MetatypeParamsRemoved:
1132+
// We skip those nodes since it does not contain any
11311133
// information that is useful to our users.
11321134
break;
11331135

@@ -1549,6 +1551,9 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
15491551
case Node::Kind::IsSerialized:
15501552
Printer << "serialized";
15511553
return nullptr;
1554+
case Node::Kind::MetatypeParamsRemoved:
1555+
Printer << "metatypes-removed";
1556+
return nullptr;
15521557
case Node::Kind::GenericSpecializationParam:
15531558
print(Node->getChild(0), depth + 1);
15541559
for (unsigned i = 1, e = Node->getNumChildren(); i < e; ++i) {

lib/Demangling/OldRemangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,11 @@ ManglingError Remangler::mangleIsSerialized(Node *node, unsigned depth) {
446446
return ManglingError::Success;
447447
}
448448

449+
ManglingError Remangler::mangleMetatypeParamsRemoved(Node *node, unsigned depth) {
450+
Buffer << "m";
451+
return ManglingError::Success;
452+
}
453+
449454
ManglingError
450455
Remangler::mangleFunctionSignatureSpecializationReturn(Node *node,
451456
unsigned depth) {

lib/Demangling/Remangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2801,6 +2801,11 @@ ManglingError Remangler::mangleIsSerialized(Node *node, unsigned depth) {
28012801
return ManglingError::Success;
28022802
}
28032803

2804+
ManglingError Remangler::mangleMetatypeParamsRemoved(Node *node, unsigned depth) {
2805+
Buffer << 'm';
2806+
return ManglingError::Success;
2807+
}
2808+
28042809
ManglingError Remangler::mangleStatic(Node *node, unsigned depth) {
28052810
RETURN_IF_ERROR(mangleSingleChildNode(node, depth + 1));
28062811
Buffer << 'Z';

lib/SIL/Utils/GenericSpecializationMangler.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,18 @@ mangleNotReabstracted(SubstitutionMap subs) {
105105
}
106106

107107
std::string GenericSpecializationMangler::
108-
mangleReabstracted(SubstitutionMap subs, bool alternativeMangling) {
108+
mangleReabstracted(SubstitutionMap subs, bool alternativeMangling,
109+
bool metatyeParamsRemoved) {
109110
beginMangling();
110111
appendSubstitutions(getGenericSignature(), subs);
111112

112113
// See ReabstractionInfo::hasConvertedResilientParams for why and when to use
113114
// the alternative mangling.
114-
appendSpecializationOperator(alternativeMangling ? "TB" : "Tg");
115+
if (metatyeParamsRemoved) {
116+
appendSpecializationOperator(alternativeMangling ? "TBm" : "Tgm");
117+
} else {
118+
appendSpecializationOperator(alternativeMangling ? "TB" : "Tg");
119+
}
115120
return finalize();
116121
}
117122

test/Demangle/Inputs/manglings.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,7 @@ $S18resilient_protocol21ResilientBaseProtocolTL ---> protocol requirements base
359359
$S1t1PP10AssocType2_AA1QTn ---> associated conformance descriptor for t.P.AssocType2: t.Q
360360
$S1t1PP10AssocType2_AA1QTN ---> default associated conformance accessor for t.P.AssocType2: t.Q
361361
$s4Test6testityyxlFAA8MystructV_TB5 ---> generic specialization <Test.Mystruct> of Test.testit<A>(A) -> ()
362+
$sSUss17FixedWidthIntegerRzrlEyxqd__cSzRd__lufCSu_SiTgm5 ---> generic specialization <Swift.UInt, Swift.Int> of (extension in Swift):Swift.UnsignedInteger< where A: Swift.FixedWidthInteger>.init<A where A1: Swift.BinaryInteger>(A1) -> A
362363
$sSD5IndexVy__GD ---> $sSD5IndexVy__GD
363364
$s4test3StrCACycfC ---> {T:$s4test3StrCACycfc} test.Str.__allocating_init() -> test.Str
364365
$s18keypaths_inlinable13KeypathStructV8computedSSvpACTKq ---> key path getter for keypaths_inlinable.KeypathStruct.computed : Swift.String : keypaths_inlinable.KeypathStruct, serialized

0 commit comments

Comments
 (0)