mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
[Mangler] Add new mangling schemes.
This commit is contained in:
@@ -259,6 +259,8 @@ types where the metadata itself has unknown layout.)
|
||||
global ::= from-type to-type generic-signature? 'Tr' // obsolete mangling for reabstraction thunk
|
||||
global ::= entity generic-signature? type type* 'TK' // key path getter
|
||||
global ::= entity generic-signature? type type* 'Tk' // key path setter
|
||||
global ::= entity generic-signature? type type* 'Tkmu' // key path unapplied method
|
||||
global ::= entity generic-signature? type type* 'TkMA' // key path applied method
|
||||
global ::= type generic-signature 'TH' // key path equality
|
||||
global ::= type generic-signature 'Th' // key path hasher
|
||||
global ::= global generic-signature? 'TJ' AUTODIFF-FUNCTION-KIND INDEX-SUBSET 'p' INDEX-SUBSET 'r' // autodiff function
|
||||
|
||||
@@ -346,16 +346,20 @@ public:
|
||||
AutoDiffLinearMapKind linearMapKind,
|
||||
const AutoDiffConfig &config);
|
||||
|
||||
std::string mangleKeyPathGetterThunkHelper(const AbstractStorageDecl *property,
|
||||
GenericSignature signature,
|
||||
CanType baseType,
|
||||
SubstitutionMap subs,
|
||||
ResilienceExpansion expansion);
|
||||
std::string mangleKeyPathGetterThunkHelper(
|
||||
const AbstractStorageDecl *property, GenericSignature signature,
|
||||
CanType baseType, SubstitutionMap subs, ResilienceExpansion expansion);
|
||||
std::string mangleKeyPathSetterThunkHelper(const AbstractStorageDecl *property,
|
||||
GenericSignature signature,
|
||||
CanType baseType,
|
||||
SubstitutionMap subs,
|
||||
ResilienceExpansion expansion);
|
||||
std::string mangleKeyPathUnappliedMethodThunkHelper(
|
||||
const AbstractFunctionDecl *method, GenericSignature signature,
|
||||
CanType baseType, SubstitutionMap subs, ResilienceExpansion expansion);
|
||||
std::string mangleKeyPathAppliedMethodThunkHelper(
|
||||
const AbstractFunctionDecl *method, GenericSignature signature,
|
||||
CanType baseType, SubstitutionMap subs, ResilienceExpansion expansion);
|
||||
std::string mangleKeyPathEqualsHelper(ArrayRef<CanType> indices,
|
||||
GenericSignature signature,
|
||||
ResilienceExpansion expansion);
|
||||
|
||||
@@ -161,6 +161,8 @@ NODE(NonIsolatedCallerFunctionType)
|
||||
NODE(SendingResultFunctionType)
|
||||
NODE(KeyPathGetterThunkHelper)
|
||||
NODE(KeyPathSetterThunkHelper)
|
||||
NODE(KeyPathUnappliedMethodThunkHelper)
|
||||
NODE(KeyPathAppliedMethodThunkHelper)
|
||||
NODE(KeyPathEqualsThunkHelper)
|
||||
NODE(KeyPathHashThunkHelper)
|
||||
NODE(LazyProtocolWitnessTableAccessor)
|
||||
|
||||
@@ -377,19 +377,16 @@ std::string ASTMangler::mangleGlobalVariableFull(const VarDecl *decl) {
|
||||
}
|
||||
|
||||
std::string ASTMangler::mangleKeyPathGetterThunkHelper(
|
||||
const AbstractStorageDecl *property,
|
||||
GenericSignature signature,
|
||||
CanType baseType,
|
||||
SubstitutionMap subs,
|
||||
ResilienceExpansion expansion) {
|
||||
const AbstractStorageDecl *property, GenericSignature signature,
|
||||
CanType baseType, SubstitutionMap subs, ResilienceExpansion expansion) {
|
||||
beginMangling();
|
||||
appendEntity(property);
|
||||
if (signature)
|
||||
appendGenericSignature(signature);
|
||||
appendType(baseType, signature);
|
||||
if (isa<SubscriptDecl>(property)) {
|
||||
// Subscripts can be generic, and different key paths could capture the same
|
||||
// subscript at different generic arguments.
|
||||
// Subscripts can be generic, and different key paths could
|
||||
// capture the same subscript at different generic arguments.
|
||||
for (auto sub : subs.getReplacementTypes()) {
|
||||
sub = sub->mapTypeOutOfContext();
|
||||
|
||||
@@ -448,6 +445,74 @@ std::string ASTMangler::mangleKeyPathSetterThunkHelper(
|
||||
return finalize();
|
||||
}
|
||||
|
||||
std::string ASTMangler::mangleKeyPathAppliedMethodThunkHelper(
|
||||
const AbstractFunctionDecl *method, GenericSignature signature,
|
||||
CanType baseType, SubstitutionMap subs, ResilienceExpansion expansion) {
|
||||
beginMangling();
|
||||
isa<ConstructorDecl>(method)
|
||||
? appendConstructorEntity(cast<ConstructorDecl>(method), false)
|
||||
: appendEntity(method);
|
||||
|
||||
if (signature)
|
||||
appendGenericSignature(signature);
|
||||
appendType(baseType, signature);
|
||||
if (isa<FuncDecl>(method) || isa<ConstructorDecl>(method)) {
|
||||
// Methods can be generic, and different key paths could capture the same
|
||||
// method at different generic arguments.
|
||||
for (auto sub : subs.getReplacementTypes()) {
|
||||
sub = sub->mapTypeOutOfContext();
|
||||
|
||||
// FIXME: This seems wrong. We used to just mangle opened archetypes as
|
||||
// their interface type. Let's make that explicit now.
|
||||
sub = sub.transformRec([](Type t) -> std::optional<Type> {
|
||||
if (auto *openedExistential = t->getAs<ExistentialArchetypeType>())
|
||||
return openedExistential->getInterfaceType();
|
||||
return std::nullopt;
|
||||
});
|
||||
|
||||
appendType(sub->getCanonicalType(), signature);
|
||||
}
|
||||
}
|
||||
appendOperator("TkMA");
|
||||
if (expansion == ResilienceExpansion::Minimal)
|
||||
appendOperator("q");
|
||||
return finalize();
|
||||
}
|
||||
|
||||
std::string ASTMangler::mangleKeyPathUnappliedMethodThunkHelper(
|
||||
const AbstractFunctionDecl *method, GenericSignature signature,
|
||||
CanType baseType, SubstitutionMap subs, ResilienceExpansion expansion) {
|
||||
beginMangling();
|
||||
isa<ConstructorDecl>(method)
|
||||
? appendConstructorEntity(cast<ConstructorDecl>(method), false)
|
||||
: appendEntity(method);
|
||||
|
||||
if (signature)
|
||||
appendGenericSignature(signature);
|
||||
appendType(baseType, signature);
|
||||
if (isa<FuncDecl>(method) || isa<ConstructorDecl>(method)) {
|
||||
// Methods can be generic, and different key paths could capture the same
|
||||
// method at different generic arguments.
|
||||
for (auto sub : subs.getReplacementTypes()) {
|
||||
sub = sub->mapTypeOutOfContext();
|
||||
|
||||
// FIXME: This seems wrong. We used to just mangle opened archetypes as
|
||||
// their interface type. Let's make that explicit now.
|
||||
sub = sub.transformRec([](Type t) -> std::optional<Type> {
|
||||
if (auto *openedExistential = t->getAs<ExistentialArchetypeType>())
|
||||
return openedExistential->getInterfaceType();
|
||||
return std::nullopt;
|
||||
});
|
||||
|
||||
appendType(sub->getCanonicalType(), signature);
|
||||
}
|
||||
}
|
||||
appendOperator("Tkmu");
|
||||
if (expansion == ResilienceExpansion::Minimal)
|
||||
appendOperator("q");
|
||||
return finalize();
|
||||
}
|
||||
|
||||
std::string ASTMangler::mangleKeyPathEqualsHelper(ArrayRef<CanType> indices,
|
||||
GenericSignature signature,
|
||||
ResilienceExpansion expansion) {
|
||||
|
||||
@@ -2933,8 +2933,9 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
|
||||
addChild(Thunk, popNode(Node::Kind::Type));
|
||||
return Thunk;
|
||||
}
|
||||
case 'g':
|
||||
case 'g': {
|
||||
return demangleGenericSpecialization(Node::Kind::GenericSpecialization, nullptr);
|
||||
}
|
||||
case 'G':
|
||||
return demangleGenericSpecialization(Node::Kind::
|
||||
GenericSpecializationNotReAbstracted, nullptr);
|
||||
@@ -2966,8 +2967,15 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
|
||||
return demangleFunctionSpecialization();
|
||||
case 'K':
|
||||
case 'k': {
|
||||
auto nodeKind = c == 'K' ? Node::Kind::KeyPathGetterThunkHelper
|
||||
Node::Kind nodeKind;
|
||||
if (nextIf("mu")) {
|
||||
nodeKind = Node::Kind::KeyPathUnappliedMethodThunkHelper;
|
||||
} else if (nextIf("MA")) {
|
||||
nodeKind = Node::Kind::KeyPathAppliedMethodThunkHelper;
|
||||
} else {
|
||||
nodeKind = c == 'K' ? Node::Kind::KeyPathGetterThunkHelper
|
||||
: Node::Kind::KeyPathSetterThunkHelper;
|
||||
}
|
||||
|
||||
bool isSerialized = nextIf('q');
|
||||
|
||||
|
||||
@@ -456,6 +456,8 @@ private:
|
||||
case Node::Kind::PropertyWrapperInitFromProjectedValue:
|
||||
case Node::Kind::KeyPathGetterThunkHelper:
|
||||
case Node::Kind::KeyPathSetterThunkHelper:
|
||||
case Node::Kind::KeyPathUnappliedMethodThunkHelper:
|
||||
case Node::Kind::KeyPathAppliedMethodThunkHelper:
|
||||
case Node::Kind::KeyPathEqualsThunkHelper:
|
||||
case Node::Kind::KeyPathHashThunkHelper:
|
||||
case Node::Kind::LazyProtocolWitnessTableAccessor:
|
||||
@@ -2104,10 +2106,16 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
|
||||
return nullptr;
|
||||
case Node::Kind::KeyPathGetterThunkHelper:
|
||||
case Node::Kind::KeyPathSetterThunkHelper:
|
||||
case Node::Kind::KeyPathUnappliedMethodThunkHelper:
|
||||
case Node::Kind::KeyPathAppliedMethodThunkHelper:
|
||||
if (Node->getKind() == Node::Kind::KeyPathGetterThunkHelper)
|
||||
Printer << "key path getter for ";
|
||||
else
|
||||
else if (Node->getKind() == Node::Kind::KeyPathSetterThunkHelper)
|
||||
Printer << "key path setter for ";
|
||||
else if (Node->getKind() == Node::Kind::KeyPathUnappliedMethodThunkHelper)
|
||||
Printer << "key path unapplied method ";
|
||||
else if (Node->getKind() == Node::Kind::KeyPathAppliedMethodThunkHelper)
|
||||
Printer << "key path applied method ";
|
||||
|
||||
print(Node->getChild(0), depth + 1);
|
||||
Printer << " : ";
|
||||
|
||||
@@ -2709,6 +2709,18 @@ ManglingError Remangler::mangleKeyPathSetterThunkHelper(Node *node,
|
||||
return mangleChildNodes(node, depth + 1);
|
||||
}
|
||||
|
||||
ManglingError
|
||||
Remangler::mangleKeyPathUnappliedMethodThunkHelper(Node *node, unsigned depth) {
|
||||
Buffer << "Tkmu";
|
||||
return mangleChildNodes(node, depth + 1);
|
||||
}
|
||||
|
||||
ManglingError Remangler::mangleKeyPathAppliedMethodThunkHelper(Node *node,
|
||||
unsigned depth) {
|
||||
Buffer << "TkMA";
|
||||
return mangleChildNodes(node, depth + 1);
|
||||
}
|
||||
|
||||
ManglingError Remangler::mangleKeyPathEqualsThunkHelper(Node *node,
|
||||
unsigned depth) {
|
||||
Buffer << "TH";
|
||||
|
||||
@@ -3056,6 +3056,16 @@ ManglingError Remangler::mangleKeyPathSetterThunkHelper(Node *node,
|
||||
return mangleKeyPathThunkHelper(node, "Tk", depth + 1);
|
||||
}
|
||||
|
||||
ManglingError
|
||||
Remangler::mangleKeyPathUnappliedMethodThunkHelper(Node *node, unsigned depth) {
|
||||
return mangleKeyPathThunkHelper(node, "Tkmu", depth + 1);
|
||||
}
|
||||
|
||||
ManglingError Remangler::mangleKeyPathAppliedMethodThunkHelper(Node *node,
|
||||
unsigned depth) {
|
||||
return mangleKeyPathThunkHelper(node, "TkMA", depth + 1);
|
||||
}
|
||||
|
||||
ManglingError Remangler::mangleKeyPathEqualsThunkHelper(Node *node,
|
||||
unsigned depth) {
|
||||
return mangleKeyPathThunkHelper(node, "TH", depth + 1);
|
||||
|
||||
Reference in New Issue
Block a user