Skip to content

Revert "Add debug info support for inlined and specialized generic va… #17820

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
Jul 7, 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: 0 additions & 1 deletion docs/ABI/Mangling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,6 @@ Function Specializations

specialization ::= type '_' type* 'Tg' SPEC-INFO // Generic re-abstracted specialization
specialization ::= type '_' type* 'TG' SPEC-INFO // Generic not re-abstracted specialization
specialization ::= type '_' type* 'Ti' SPEC-INFO // Inlined function with generic substitutions.

The types are the replacement types of the substitution list.

Expand Down
2 changes: 1 addition & 1 deletion include/swift/AST/SubstitutionMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ class SubstitutionMap {
/// existential.
bool hasOpenedExistential() const;

/// Query whether any replacement types in the map contain dynamic Self.
/// Query whether any replacement type sin the map contain dynamic Self.
bool hasDynamicSelf() const;

/// Whether the replacement types are all canonical.
Expand Down
1 change: 0 additions & 1 deletion include/swift/Demangling/DemangleNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ NODE(ResilientProtocolWitnessTable)
NODE(GenericSpecialization)
NODE(GenericSpecializationNotReAbstracted)
NODE(GenericSpecializationParam)
NODE(InlinedGenericFunction)
NODE(GenericTypeMetadataPattern)
CONTEXT_NODE(Getter)
NODE(Global)
Expand Down
81 changes: 1 addition & 80 deletions include/swift/SIL/TypeSubstCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
#include "swift/SIL/SILCloner.h"
#include "swift/SIL/DynamicCasts.h"
#include "swift/SILOptimizer/Utils/Local.h"
#include "swift/SILOptimizer/Utils/SpecializationMangler.h"
#include "llvm/Support/Debug.h"

namespace swift {
Expand Down Expand Up @@ -280,84 +279,6 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
super::visitDestroyValueInst(Destroy);
}

/// One abstract function in the debug info can only have one set of variables
/// and types. This function determines whether applying the substitutions in
/// \p SubsMap on the generic signature \p Sig will change the generic type
/// parameters in the signature. This is used to decide whether it's necessary
/// to clone a unique copy of the function declaration with the substitutions
/// applied for the debug info.
static bool substitutionsChangeGenericTypeParameters(SubstitutionMap SubsMap,
GenericSignature *Sig) {

// If there are no substitutions, just reuse
// the original decl.
if (SubsMap.empty())
return false;

auto Params = Sig->getSubstitutableParams();
return std::any_of(Params.begin(), Params.end(), [&](Type ParamType) {
Type Substitution = Type(ParamType).subst(SubsMap);
return !Substitution->isOpenedExistential() &&
(Substitution->getCanonicalType() !=
ParamType->getCanonicalType());
});
}

enum { ForInlining = true };
/// Helper function to clone the parent function of a SILDebugScope if
/// necessary when inlining said function into a new generic context.
/// \param SubsMap - the substitutions of the inlining/specialization process.
/// \param RemappedSig - the generic signature
static SILFunction *remapParentFunction(SILModule &M,
SILFunction *ParentFunction,
SubstitutionMap SubsMap,
GenericSignature *RemappedSig,
bool ForInlining = false) {
// If the original, non-inlined version of the function had no generic
// environment, there is no need to remap it.
auto *OriginalEnvironment = ParentFunction->getGenericEnvironment();
if (!RemappedSig || !OriginalEnvironment)
return ParentFunction;

if (SubsMap.hasArchetypes())
SubsMap = SubsMap.mapReplacementTypesOutOfContext();

if (!substitutionsChangeGenericTypeParameters(SubsMap, RemappedSig))
return ParentFunction;

// Clone the function with the substituted type for the debug info.
Mangle::GenericSpecializationMangler Mangler(
ParentFunction, SubsMap, IsNotSerialized, false, ForInlining);
std::string MangledName = Mangler.mangle(RemappedSig);

if (ParentFunction->getName() == MangledName)
return ParentFunction;
if (auto *CachedFn = M.lookUpFunction(MangledName))
ParentFunction = CachedFn;
else {
// Create a new function with this mangled name with an empty
// body. There won't be any IR generated for it (hence the linkage),
// but the symbol will be refered to by the debug info metadata.
ParentFunction = M.getOrCreateFunction(
ParentFunction->getLocation(), MangledName, SILLinkage::Shared,
ParentFunction->getLoweredFunctionType(), ParentFunction->isBare(),
ParentFunction->isTransparent(), ParentFunction->isSerialized(), 0,
ParentFunction->isThunk(), ParentFunction->getClassSubclassScope());
// Increment the ref count for the inlined function, so it doesn't
// get deleted before we can emit abstract debug info for it.
if (!ParentFunction->isZombie()) {
ParentFunction->setInlined();
// If the function was newly created with an empty body mark it as
// undead.
if (ParentFunction->empty()) {
M.eraseFunction(ParentFunction);
ParentFunction->setGenericEnvironment(OriginalEnvironment);
}
}
}
return ParentFunction;
}

/// The Swift module that the cloned function belongs to.
ModuleDecl *SwiftMod;
/// The substitutions list for the specialization.
Expand All @@ -368,7 +289,7 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
SILFunction &Original;
/// True, if used for inlining.
bool Inlining;
};
};

} // end namespace swift

Expand Down
5 changes: 0 additions & 5 deletions include/swift/SILOptimizer/Utils/GenericCloner.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class GenericCloner : public TypeSubstCloner<GenericCloner> {
IsSerialized_t Serialized;
const ReabstractionInfo &ReInfo;
CloneCollector::CallbackType Callback;
llvm::SmallDenseMap<const SILDebugScope *, const SILDebugScope *, 8>
RemappedScopeCache;

public:
friend class SILCloner<GenericCloner>;
Expand Down Expand Up @@ -92,9 +90,6 @@ class GenericCloner : public TypeSubstCloner<GenericCloner> {
/// by initCloned.
void populateCloned();
SILFunction *getCloned() { return &getBuilder().getFunction(); }

const SILDebugScope *remapScope(const SILDebugScope *DS);

};

} // end namespace swift
Expand Down
29 changes: 14 additions & 15 deletions include/swift/SILOptimizer/Utils/SpecializationMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ class SpecializationMangler : public Mangle::ASTMangler {
protected:
SpecializationMangler(SpecializationPass P, IsSerialized_t Serialized,
SILFunction *F)
: Pass(P), Serialized(Serialized), Function(F),
ArgOpBuffer(ArgOpStorage) {}
: Pass(P), Serialized(Serialized), Function(F), ArgOpBuffer(ArgOpStorage) {}

SILFunction *getFunction() const { return Function; }

Expand All @@ -68,17 +67,17 @@ class GenericSpecializationMangler : public SpecializationMangler {

SubstitutionMap SubMap;
bool isReAbstracted;
bool isInlined;

public:
GenericSpecializationMangler(SILFunction *F, SubstitutionMap SubMap,
IsSerialized_t Serialized, bool isReAbstracted,
bool isInlined = false)
: SpecializationMangler(SpecializationPass::GenericSpecializer,
Serialized, F),
SubMap(SubMap), isReAbstracted(isReAbstracted), isInlined(isInlined) {}

std::string mangle(GenericSignature *Sig = nullptr);

GenericSpecializationMangler(SILFunction *F,
SubstitutionMap SubMap,
IsSerialized_t Serialized,
bool isReAbstracted)
: SpecializationMangler(SpecializationPass::GenericSpecializer, Serialized, F),
SubMap(SubMap), isReAbstracted(isReAbstracted) {}

std::string mangle();
};

class PartialSpecializationMangler : public SpecializationMangler {
Expand All @@ -89,10 +88,10 @@ class PartialSpecializationMangler : public SpecializationMangler {
public:
PartialSpecializationMangler(SILFunction *F,
CanSILFunctionType SpecializedFnTy,
IsSerialized_t Serialized, bool isReAbstracted)
: SpecializationMangler(SpecializationPass::GenericSpecializer,
Serialized, F),
SpecializedFnTy(SpecializedFnTy), isReAbstracted(isReAbstracted) {}
IsSerialized_t Serialized,
bool isReAbstracted)
: SpecializationMangler(SpecializationPass::GenericSpecializer, Serialized, F),
SpecializedFnTy(SpecializedFnTy), isReAbstracted(isReAbstracted) {}

std::string mangle();
};
Expand Down
9 changes: 3 additions & 6 deletions lib/Demangling/Demangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1731,13 +1731,11 @@ NodePointer Demangler::demangleThunkOrSpecialization() {
Thunk = addChild(Thunk, popNode(Node::Kind::Type));
return addChild(Thunk, Ty2);
}
case 'g':
case'g':
return demangleGenericSpecialization(Node::Kind::GenericSpecialization);
case 'G':
case'G':
return demangleGenericSpecialization(Node::Kind::
GenericSpecializationNotReAbstracted);
case 'i':
return demangleGenericSpecialization(Node::Kind::InlinedGenericFunction);
case'p': {
NodePointer Spec = demangleSpecAttributes(Node::Kind::
GenericPartialSpecialization);
Expand Down Expand Up @@ -1868,8 +1866,7 @@ NodePointer Demangler::demangleGenericSpecialization(Node::Kind SpecKind) {
if (!TyList)
return nullptr;
for (NodePointer Ty : *TyList) {
Spec->addChild(createWithChild(Node::Kind::GenericSpecializationParam, Ty),
*this);
Spec->addChild(createWithChild(Node::Kind::GenericSpecializationParam, Ty), *this);
}
return Spec;
}
Expand Down
4 changes: 0 additions & 4 deletions lib/Demangling/NodePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,6 @@ class NodePrinter {
case Node::Kind::GenericSpecialization:
case Node::Kind::GenericSpecializationNotReAbstracted:
case Node::Kind::GenericSpecializationParam:
case Node::Kind::InlinedGenericFunction:
case Node::Kind::GenericTypeMetadataPattern:
case Node::Kind::Getter:
case Node::Kind::Global:
Expand Down Expand Up @@ -1182,9 +1181,6 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
case Node::Kind::GenericSpecializationNotReAbstracted:
printSpecializationPrefix(Node, "generic not re-abstracted specialization");
return nullptr;
case Node::Kind::InlinedGenericFunction:
printSpecializationPrefix(Node, "inlined generic function");
return nullptr;
case Node::Kind::SpecializationIsFragile:
Printer << "preserving fragile attribute";
return nullptr;
Expand Down
12 changes: 0 additions & 12 deletions lib/Demangling/OldRemangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ void Remangler::mangleGenericSpecialization(Node *node) {
// Start another mangled name.
Out << "__T";
}

void Remangler::mangleGenericSpecializationNotReAbstracted(Node *node) {
Out << "TSr";
mangleChildNodes(node); // GenericSpecializationParams
Expand All @@ -546,17 +545,6 @@ void Remangler::mangleGenericSpecializationNotReAbstracted(Node *node) {
Out << "__T";
}

void Remangler::mangleInlinedGenericFunction(Node *node) {
Out << "TSi";
mangleChildNodes(node); // GenericSpecializationParams

// Specializations are just prepended to already-mangled names.
resetSubstitutions();

// Start another mangled name.
Out << "__T";
}

void Remangler::mangleGenericPartialSpecialization(Node *node) {
unreachable("todo");
}
Expand Down
22 changes: 2 additions & 20 deletions lib/Demangling/Remangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1122,20 +1122,8 @@ void Remangler::mangleGenericSpecialization(Node *node) {
}
assert(!FirstParam && "generic specialization with no substitutions");

switch (node->getKind()) {
case Node::Kind::GenericSpecialization:
Buffer << "Tg";
break;
case Node::Kind::GenericSpecializationNotReAbstracted:
Buffer << "TG";
break;
case Node::Kind::InlinedGenericFunction:
Buffer << "Ti";
break;
default:
unreachable("unsupported node");
}

Buffer << (node->getKind() ==
Node::Kind::GenericSpecializationNotReAbstracted ? "TG" : "Tg");
for (NodePointer Child : *node) {
if (Child->getKind() != Node::Kind::GenericSpecializationParam)
mangle(Child);
Expand All @@ -1146,11 +1134,6 @@ void Remangler::mangleGenericSpecializationNotReAbstracted(Node *node) {
mangleGenericSpecialization(node);
}

void Remangler::mangleInlinedGenericFunction(Node *node) {
mangleGenericSpecialization(node);
}


void Remangler::mangleGenericSpecializationParam(Node *node) {
unreachable("handled inline");
}
Expand Down Expand Up @@ -1178,7 +1161,6 @@ void Remangler::mangleGlobal(Node *node) {
case Node::Kind::FunctionSignatureSpecialization:
case Node::Kind::GenericSpecialization:
case Node::Kind::GenericSpecializationNotReAbstracted:
case Node::Kind::InlinedGenericFunction:
case Node::Kind::GenericPartialSpecialization:
case Node::Kind::GenericPartialSpecializationNotReAbstracted:
case Node::Kind::OutlinedBridgedMethod:
Expand Down
Loading