Skip to content

Add ExistentialToGeneric mangling and demangling code #16603

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 15, 2018
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
1 change: 1 addition & 0 deletions docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,7 @@ Some kinds need arguments, which precede ``Tf``.
ARG-SPEC-KIND ::= 'c' // Consumes n 'type' arguments which are closed over types in argument order
// and one 'identifier' argument which is the closure symbol name
ARG-SPEC-KIND ::= 'p' CONST-PROP // Constant propagated argument
ARG-SPEC-KIND ::= 'e' 'D'? 'G'? 'X'? // Generic argument, with optional dead, owned=>guaranteed or exploded-specifier
ARG-SPEC-KIND ::= 'd' 'G'? 'X'? // Dead argument, with optional owned=>guaranteed or exploded-specifier
ARG-SPEC-KIND ::= 'g' 'X'? // Owned => Guaranteed,, with optional exploded-specifier
ARG-SPEC-KIND ::= 'x' // Exploded
Expand Down
1 change: 1 addition & 0 deletions include/swift/Demangling/Demangle.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ enum class FunctionSigSpecializationParamKind : unsigned {
OwnedToGuaranteed = 1 << 7,
SROA = 1 << 8,
GuaranteedToOwned = 1 << 9,
ExistentialToGeneric = 1 << 10,
};

/// The pass that caused the specialization to occur. We use this to make sure
Expand Down
2 changes: 2 additions & 0 deletions include/swift/SILOptimizer/Utils/SpecializationMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class FunctionSignatureSpecializationMangler : public SpecializationMangler {
OwnedToGuaranteed=64,
SROA=128,
GuaranteedToOwned=256,
ExistentialToGeneric=512,
First_OptionSetEntry=32, LastOptionSetEntry=32768,
};

Expand All @@ -151,6 +152,7 @@ class FunctionSignatureSpecializationMangler : public SpecializationMangler {
void setArgumentDead(unsigned OrigArgIdx);
void setArgumentOwnedToGuaranteed(unsigned OrigArgIdx);
void setArgumentGuaranteedToOwned(unsigned OrigArgIdx);
void setArgumentExistentialToGeneric(unsigned OrigArgIdx);
void setArgumentSROA(unsigned OrigArgIdx);
void setArgumentBoxToValue(unsigned OrigArgIdx);
void setArgumentBoxToStack(unsigned OrigArgIdx);
Expand Down
18 changes: 18 additions & 0 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1982,6 +1982,24 @@ NodePointer Demangler::demangleFuncSpecParam(Node::IndexType ParamIdx) {
return nullptr;
}
}
case 'e': {
unsigned Value =
unsigned(FunctionSigSpecializationParamKind::ExistentialToGeneric);
if (nextIf('D'))
Value |= unsigned(FunctionSigSpecializationParamKind::Dead);
if (nextIf('G'))
Value |=
unsigned(FunctionSigSpecializationParamKind::OwnedToGuaranteed);
if (nextIf('O'))
Value |=
unsigned(FunctionSigSpecializationParamKind::GuaranteedToOwned);
if (nextIf('X'))
Value |= unsigned(FunctionSigSpecializationParamKind::SROA);
return addChild(
Param,
createNode(Node::Kind::FunctionSignatureSpecializationParamKind,
Value));
}
case 'd': {
unsigned Value = unsigned(FunctionSigSpecializationParamKind::Dead);
if (nextIf('G'))
Expand Down
14 changes: 12 additions & 2 deletions lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,9 @@ unsigned NodePrinter::printFunctionSigSpecializationParam(NodePointer Node,
((V & unsigned(FunctionSigSpecializationParamKind::OwnedToGuaranteed)) ||
(V & unsigned(FunctionSigSpecializationParamKind::GuaranteedToOwned)) ||
(V & unsigned(FunctionSigSpecializationParamKind::SROA)) ||
(V & unsigned(FunctionSigSpecializationParamKind::Dead))) &&
(V & unsigned(FunctionSigSpecializationParamKind::Dead))||
(V & unsigned(
FunctionSigSpecializationParamKind::ExistentialToGeneric))) &&
"Invalid OptionSet");
print(Node->getChild(Idx++));
return Idx;
Expand Down Expand Up @@ -1215,11 +1217,18 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
uint64_t raw = Node->getIndex();

bool printedOptionSet = false;
if (raw &
uint64_t(FunctionSigSpecializationParamKind::ExistentialToGeneric)) {
printedOptionSet = true;
Printer << "Existential To Protocol Constrained Generic";
}

if (raw & uint64_t(FunctionSigSpecializationParamKind::Dead)) {
if (printedOptionSet)
Printer << " and ";
printedOptionSet = true;
Printer << "Dead";
}

if (raw & uint64_t(FunctionSigSpecializationParamKind::OwnedToGuaranteed)) {
if (printedOptionSet)
Printer << " and ";
Expand Down Expand Up @@ -1269,6 +1278,7 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
case FunctionSigSpecializationParamKind::ClosureProp:
Printer << "Closure Propagated";
return nullptr;
case FunctionSigSpecializationParamKind::ExistentialToGeneric:
case FunctionSigSpecializationParamKind::Dead:
case FunctionSigSpecializationParamKind::OwnedToGuaranteed:
case FunctionSigSpecializationParamKind::GuaranteedToOwned:
Expand Down
15 changes: 14 additions & 1 deletion lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1019,7 +1019,20 @@ void Remangler::mangleFunctionSignatureSpecializationParam(Node *node) {
Buffer << 'x';
return;
default:
if (kindValue & unsigned(FunctionSigSpecializationParamKind::Dead)) {
if (kindValue &
unsigned(
FunctionSigSpecializationParamKind::ExistentialToGeneric)) {
Buffer << 'e';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems weird that this is an if/else if construct that duplicates some of the cases here. Can you instead redo this as a series of independent ifs instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow. The idea here is that we allow "ARG-SPEC-KIND ::= 'e' 'D'? 'G'? 'X'? ---Generic argument, with optional dead, owned=>guaranteed or exploded-specifier". Please note the upper case and lower case. Let me know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. It seems strange that the first letter is lower case and the rest are upper case, for each of the different argument kinds. But I guess that’s what we have today already.

if (kindValue & unsigned(FunctionSigSpecializationParamKind::Dead))
Buffer << 'D';
if (kindValue &
unsigned(FunctionSigSpecializationParamKind::OwnedToGuaranteed))
Buffer << 'G';
if (kindValue &
unsigned(FunctionSigSpecializationParamKind::GuaranteedToOwned))
Buffer << 'O';
} else if (kindValue &
unsigned(FunctionSigSpecializationParamKind::Dead)) {
Buffer << 'd';
if (kindValue &
unsigned(FunctionSigSpecializationParamKind::OwnedToGuaranteed))
Expand Down
11 changes: 11 additions & 0 deletions lib/SILOptimizer/Utils/SpecializationMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ void FunctionSignatureSpecializationMangler::setArgumentGuaranteedToOwned(
ArgumentModifierIntBase(ArgumentModifier::GuaranteedToOwned);
}

void FunctionSignatureSpecializationMangler::setArgumentExistentialToGeneric(
unsigned OrigArgIdx) {
OrigArgs[OrigArgIdx].first |=
ArgumentModifierIntBase(ArgumentModifier::ExistentialToGeneric);
}

void FunctionSignatureSpecializationMangler::setArgumentBoxToValue(
unsigned OrigArgIdx) {
OrigArgs[OrigArgIdx].first =
Expand Down Expand Up @@ -287,6 +293,11 @@ void FunctionSignatureSpecializationMangler::mangleArgument(
}

bool hasSomeMod = false;
if (ArgMod & ArgumentModifierIntBase(ArgumentModifier::ExistentialToGeneric)) {
ArgOpBuffer << 'e';
hasSomeMod = true;
}

if (ArgMod & ArgumentModifierIntBase(ArgumentModifier::Dead)) {
ArgOpBuffer << 'd';
hasSomeMod = true;
Expand Down