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
15 changes: 8 additions & 7 deletions docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1265,14 +1265,17 @@ Function Specializations

::

specialization ::= type '_' type* 'Tg' SPEC-INFO // Generic re-abstracted specialization
specialization ::= type '_' type* 'TB' SPEC-INFO // Alternative mangling for generic re-abstracted specializations,
// used for functions with re-abstracted resilient parameter types.
specialization ::= type '_' type* 'T' dropped-arg* 'g' SPEC-INFO // Generic re-abstracted specialization
specialization ::= type '_' type* 'T' dropped-arg* 'B' SPEC-INFO // Alternative mangling for generic re-abstracted specializations,
// used for functions with re-abstracted resilient parameter types.
specialization ::= type '_' type* 'T' dropped-arg* 'G' SPEC-INFO // Generic not re-abstracted specialization
specialization ::= type '_' type* 'Ts' SPEC-INFO // Generic re-abstracted prespecialization
specialization ::= type '_' type* 'TG' SPEC-INFO // Generic not re-abstracted specialization
specialization ::= type '_' type* 'Ti' SPEC-INFO // Inlined function with generic substitutions.
specialization ::= type '_' type* 'Ta' SPEC-INFO // Non-async specialization

dropped-arg ::= 't' // The first argument is dropped
dropped-arg ::= 't' NATURAL // The `N+1`th argument is dropped

The types are the replacement types of the substitution list.

::
Expand All @@ -1294,7 +1297,7 @@ Some kinds need arguments, which precede ``Tf``.
spec-arg ::= identifier
spec-arg ::= type

SPEC-INFO ::= MT-REMOVED? FRAGILE? ASYNC-REMOVED? PASSID
SPEC-INFO ::= FRAGILE? ASYNC-REMOVED? PASSID

PASSID ::= '0' // AllocBoxToStack,
PASSID ::= '1' // ClosureSpecializer,
Expand All @@ -1305,8 +1308,6 @@ Some kinds need arguments, which precede ``Tf``.
PASSID ::= '6' // MoveDiagnosticInOutToOut,
PASSID ::= '7' // AsyncDemotion,

MT-REMOVED ::= 'm' // non-generic metatype arguments are removed in the specialized function

FRAGILE ::= 'q'

ASYNC-REMOVED ::= 'a' // async effect removed
Expand Down
2 changes: 1 addition & 1 deletion include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ NODE(NonUniqueExtendedExistentialTypeShapeSymbolicReference)
NODE(SymbolicExtendedExistentialType)

// Added in Swift 5.8
NODE(MetatypeParamsRemoved)
NODE(DroppedArgument)
NODE(HasSymbolQuery)
NODE(OpaqueReturnTypeIndex)
NODE(OpaqueReturnTypeParent)
Expand Down
4 changes: 3 additions & 1 deletion include/swift/Demangling/Demangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,9 @@ class Demangler : public NodeFactory {
NodePointer popDependentAssociatedConformance();
NodePointer demangleDependentProtocolConformanceAssociated();
NodePointer demangleThunkOrSpecialization();
NodePointer demangleGenericSpecialization(Node::Kind SpecKind);
NodePointer demangleGenericSpecialization(Node::Kind SpecKind,
NodePointer droppedArguments);
NodePointer demangleGenericSpecializationWithDroppedArguments();
NodePointer demangleFunctionSpecialization();
NodePointer demangleFuncSpecParam(Node::Kind Kind);
NodePointer addFuncSpecParamNumber(NodePointer Param,
Expand Down
6 changes: 4 additions & 2 deletions include/swift/SIL/GenericSpecializationMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,15 @@ class GenericSpecializationMangler : public SpecializationMangler {
std::string manglePrespecialized(GenericSignature sig,
SubstitutionMap subs);

void appendRemovedParams(const SmallBitVector &paramsRemoved);

public:
GenericSpecializationMangler(SILFunction *F, swift::SerializedKind_t Serialized)
: SpecializationMangler(SpecializationPass::GenericSpecializer,
Serialized, F) {}

std::string mangleNotReabstracted(SubstitutionMap subs,
bool metatyeParamsRemoved);
const SmallBitVector &paramsRemoved = SmallBitVector());

/// Mangle a generic specialization with re-abstracted parameters.
///
Expand All @@ -107,7 +109,7 @@ class GenericSpecializationMangler : public SpecializationMangler {
/// \param metatyeParamsRemoved true if non-generic metatype parameters are
/// removed in the specialized function.
std::string mangleReabstracted(SubstitutionMap subs, bool alternativeMangling,
bool metatyeParamsRemoved = false);
const SmallBitVector &paramsRemoved = SmallBitVector());

std::string mangleForDebugInfo(GenericSignature sig, SubstitutionMap subs,
bool forInlining);
Expand Down
22 changes: 10 additions & 12 deletions include/swift/SILOptimizer/Utils/Generics.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class ReabstractionInfo {
/// A 1-bit means that the argument is a metatype argument. The argument is
/// dropped and replaced by a `metatype` instruction in the entry block.
/// Only used if `dropMetatypeArgs` is true.
SmallBitVector droppedMetatypeArgs;
SmallBitVector droppedArguments;

/// Set to true if the function has a re-abstracted (= converted from
/// indirect to direct) resilient argument or return type. This can happen if
Expand All @@ -84,10 +84,10 @@ class ReabstractionInfo {
/// specializer.
bool ConvertIndirectToDirect = true;

/// If true, drop metatype arguments.
/// See `droppedMetatypeArgs`.
bool dropMetatypeArgs = false;
/// If true, drop unused arguments.
/// See `droppedArguments`.
bool dropUnusedArguments = false;

bool hasIndirectErrorResult = false;

/// The first NumResults bits in Conversions refer to formal indirect
Expand Down Expand Up @@ -277,15 +277,13 @@ class ReabstractionInfo {
/// Returns true if there are any conversions from indirect to direct values.
bool hasConversions() const { return Conversions.any(); }

/// Returns true if the argument at `ArgIdx` is a dropped metatype argument.
/// See `droppedMetatypeArgs`.
bool isDroppedMetatypeArg(unsigned ArgIdx) const {
return droppedMetatypeArgs.test(ArgIdx);
/// Returns true if the argument at `ArgIdx` is a dropped argument.
/// See `droppedArguments`.
bool isDroppedArgument(unsigned ArgIdx) const {
return droppedArguments.test(ArgIdx);
}

/// Returns true if there are any dropped metatype arguments.
/// See `droppedMetatypeArgs`.
bool hasDroppedMetatypeArgs() const { return droppedMetatypeArgs.any(); }
const SmallBitVector &getDroppedArgs() const { return droppedArguments; }

/// Remove the arguments of a partial apply, leaving the arguments for the
/// partial apply result function.
Expand Down
45 changes: 34 additions & 11 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2844,18 +2844,20 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
return Thunk;
}
case 'g':
return demangleGenericSpecialization(Node::Kind::GenericSpecialization);
return demangleGenericSpecialization(Node::Kind::GenericSpecialization, nullptr);
case 'G':
return demangleGenericSpecialization(Node::Kind::
GenericSpecializationNotReAbstracted);
GenericSpecializationNotReAbstracted, nullptr);
case 'B':
return demangleGenericSpecialization(Node::Kind::
GenericSpecializationInResilienceDomain);
GenericSpecializationInResilienceDomain, nullptr);
case 't':
return demangleGenericSpecializationWithDroppedArguments();
case 's':
return demangleGenericSpecialization(
Node::Kind::GenericSpecializationPrespecialized);
Node::Kind::GenericSpecializationPrespecialized, nullptr);
case 'i':
return demangleGenericSpecialization(Node::Kind::InlinedGenericFunction);
return demangleGenericSpecialization(Node::Kind::InlinedGenericFunction, nullptr);
case 'p': {
NodePointer Spec = demangleSpecAttributes(Node::Kind::
GenericPartialSpecialization);
Expand Down Expand Up @@ -3202,10 +3204,18 @@ std::string Demangler::demangleBridgedMethodParams() {
return Str;
}

NodePointer Demangler::demangleGenericSpecialization(Node::Kind SpecKind) {
NodePointer Demangler::demangleGenericSpecialization(Node::Kind SpecKind,
NodePointer droppedArguments) {
NodePointer Spec = demangleSpecAttributes(SpecKind);
if (!Spec)
return nullptr;

if (droppedArguments) {
for (NodePointer a : *droppedArguments) {
Spec->addChild(a, *this);
}
}

NodePointer TyList = popTypeList();
if (!TyList)
return nullptr;
Expand All @@ -3216,6 +3226,24 @@ NodePointer Demangler::demangleGenericSpecialization(Node::Kind SpecKind) {
return Spec;
}

NodePointer Demangler::demangleGenericSpecializationWithDroppedArguments() {
pushBack();
NodePointer tmp = createNode(Node::Kind::GenericSpecialization);
while (nextIf('t')) {
int n = demangleNatural();
addChild(tmp, createNode(Node::Kind::DroppedArgument, n < 0 ? 0 : n + 1));
}
Node::Kind specKind;
switch (nextChar()) {
case 'g': specKind = Node::Kind::GenericSpecialization; break;
case 'G': specKind = Node::Kind::GenericSpecializationNotReAbstracted; break;
case 'B': specKind = Node::Kind::GenericSpecializationInResilienceDomain; break;
default:
return nullptr;
}
return demangleGenericSpecialization(specKind, tmp);
}

NodePointer Demangler::demangleFunctionSpecialization() {
NodePointer Spec = demangleSpecAttributes(
Node::Kind::FunctionSignatureSpecialization);
Expand Down Expand Up @@ -3429,21 +3457,16 @@ NodePointer Demangler::addFuncSpecParamNumber(NodePointer Param,
}

NodePointer Demangler::demangleSpecAttributes(Node::Kind SpecKind) {
bool metatypeParamsRemoved = nextIf('m');
bool isSerialized = nextIf('q');
bool asyncRemoved = nextIf('a');

int PassID = (int)nextChar() - '0';
if (PassID < 0 || PassID >= MAX_SPECIALIZATION_PASS) {
assert(false && "unexpected pass id");
return nullptr;
}

NodePointer SpecNd = createNode(SpecKind);

if (metatypeParamsRemoved)
SpecNd->addChild(createNode(Node::Kind::MetatypeParamsRemoved), *this);

if (isSerialized)
SpecNd->addChild(createNode(Node::Kind::IsSerialized),
*this);
Expand Down
8 changes: 4 additions & 4 deletions lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ class NodePrinter {
case Node::Kind::SILBoxMutableField:
case Node::Kind::SILBoxImmutableField:
case Node::Kind::IsSerialized:
case Node::Kind::MetatypeParamsRemoved:
case Node::Kind::DroppedArgument:
case Node::Kind::SpecializationPassID:
case Node::Kind::Static:
case Node::Kind::Subscript:
Expand Down Expand Up @@ -1290,7 +1290,7 @@ void NodePrinter::printSpecializationPrefix(NodePointer node,
for (NodePointer child : *node) {
switch (child->getKind()) {
case Node::Kind::SpecializationPassID:
case Node::Kind::MetatypeParamsRemoved:
case Node::Kind::DroppedArgument:
// We skip those nodes since it does not contain any
// information that is useful to our users.
break;
Expand Down Expand Up @@ -1836,8 +1836,8 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
case Node::Kind::IsSerialized:
Printer << "serialized";
return nullptr;
case Node::Kind::MetatypeParamsRemoved:
Printer << "metatypes-removed";
case Node::Kind::DroppedArgument:
Printer << "param" << Node->getIndex() << "-removed";
return nullptr;
case Node::Kind::GenericSpecializationParam:
print(Node->getChild(0), depth + 1);
Expand Down
4 changes: 2 additions & 2 deletions lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ ManglingError Remangler::mangleAsyncRemoved(Node *node, unsigned depth) {
return ManglingError::Success;
}

ManglingError Remangler::mangleMetatypeParamsRemoved(Node *node, unsigned depth) {
Buffer << "m";
ManglingError Remangler::mangleDroppedArgument(Node *node, unsigned depth) {
Buffer << "t" << node->getIndex();
return ManglingError::Success;
}

Expand Down
35 changes: 24 additions & 11 deletions lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ class Remangler : public RemanglerBase {
}

ManglingError mangleGenericSpecializationNode(Node *node,
const char *operatorStr,
char specKind,
unsigned depth);
ManglingError mangleAnyNominalType(Node *node, unsigned depth);
ManglingError mangleAnyGenericType(Node *node, StringRef TypeOp,
Expand Down Expand Up @@ -1693,7 +1693,7 @@ Remangler::mangleGenericPartialSpecializationNotReAbstracted(Node *node,
}

ManglingError
Remangler::mangleGenericSpecializationNode(Node *node, const char *operatorStr,
Remangler::mangleGenericSpecializationNode(Node *node, char specKind,
unsigned depth) {
bool FirstParam = true;
for (NodePointer Child : *node) {
Expand All @@ -1705,42 +1705,52 @@ Remangler::mangleGenericSpecializationNode(Node *node, const char *operatorStr,
DEMANGLER_ASSERT(
!FirstParam && "generic specialization with no substitutions", node);

Buffer << operatorStr;
Buffer << 'T';

for (NodePointer Child : *node) {
if (Child->getKind() != Node::Kind::GenericSpecializationParam)
if (Child->getKind() == Node::Kind::DroppedArgument)
RETURN_IF_ERROR(mangle(Child, depth + 1));
}


Buffer << specKind;

for (NodePointer Child : *node) {
if (Child->getKind() != Node::Kind::GenericSpecializationParam &&
Child->getKind() != Node::Kind::DroppedArgument) {
RETURN_IF_ERROR(mangle(Child, depth + 1));
}
}

return ManglingError::Success;
}

ManglingError Remangler::mangleGenericSpecialization(Node *node,
unsigned depth) {
return mangleGenericSpecializationNode(node, "Tg", depth + 1);
return mangleGenericSpecializationNode(node, 'g', depth + 1);
}

ManglingError
Remangler::mangleGenericSpecializationPrespecialized(Node *node,
unsigned depth) {
return mangleGenericSpecializationNode(node, "Ts", depth + 1);
return mangleGenericSpecializationNode(node, 's', depth + 1);
}

ManglingError
Remangler::mangleGenericSpecializationNotReAbstracted(Node *node,
unsigned depth) {
return mangleGenericSpecializationNode(node, "TG", depth + 1);
return mangleGenericSpecializationNode(node, 'G', depth + 1);
}

ManglingError
Remangler::mangleGenericSpecializationInResilienceDomain(Node *node,
unsigned depth) {
return mangleGenericSpecializationNode(node, "TB", depth + 1);
return mangleGenericSpecializationNode(node, 'B', depth + 1);
}

ManglingError Remangler::mangleInlinedGenericFunction(Node *node,
unsigned depth) {
return mangleGenericSpecializationNode(node, "Ti", depth + 1);
return mangleGenericSpecializationNode(node, 'i', depth + 1);
}

ManglingError Remangler::mangleGenericSpecializationParam(Node *node,
Expand Down Expand Up @@ -3067,8 +3077,11 @@ ManglingError Remangler::mangleAsyncRemoved(Node *node, unsigned depth) {
return ManglingError::Success;
}

ManglingError Remangler::mangleMetatypeParamsRemoved(Node *node, unsigned depth) {
Buffer << 'm';
ManglingError Remangler::mangleDroppedArgument(Node *node, unsigned depth) {
Buffer << "t";
int n = node->getIndex();
if (n > 0)
Buffer << (n-1);
return ManglingError::Success;
}

Expand Down
Loading