Skip to content

Revert generics inlining for now #7428

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 2 commits into from
Feb 13, 2017
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
13 changes: 3 additions & 10 deletions include/swift/SIL/SILModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,19 +430,12 @@ class SILModule {
bool linkFunction(StringRef Name,
LinkingMode LinkAll = LinkingMode::LinkNormal);

/// Check if a given function exists in any of the modules with a
/// required linkage, i.e. it can be linked by linkFunction.
///
/// If linkage parameter is none, then the linkage of the function
/// with a given name does not matter.
/// Check if a given function exists in the module,
/// i.e. it can be linked by linkFunction.
///
/// \return null if this module has no such function. Otherwise
/// the declaration of a function.
SILFunction *findFunction(StringRef Name, Optional<SILLinkage> Linkage);

/// Check if a given function exists in the module,
/// i.e. it can be linked by linkFunction.
bool hasFunction(StringRef Name);
SILFunction *hasFunction(StringRef Name, SILLinkage Linkage);

/// Link in all Witness Tables in the module.
void linkAllWitnessTables();
Expand Down
1 change: 0 additions & 1 deletion include/swift/SILOptimizer/Utils/Devirtualize.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ typedef std::pair<ValueBase *, ApplySite> DevirtualizationResult;
DevirtualizationResult tryDevirtualizeApply(FullApplySite AI);
DevirtualizationResult tryDevirtualizeApply(FullApplySite AI,
ClassHierarchyAnalysis *CHA);
bool canDevirtualizeApply(FullApplySite AI, ClassHierarchyAnalysis *CHA);
bool isNominalTypeWithUnboundGenericParameters(SILType Ty, SILModule &M);
bool canDevirtualizeClassMethod(FullApplySite AI, SILType ClassInstanceType);
SILFunction *getTargetClassMethod(SILModule &M, SILType ClassOrMetatypeType,
Expand Down
4 changes: 2 additions & 2 deletions include/swift/Serialization/SerializedSILLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ class SerializedSILLoader {
SILFunction *lookupSILFunction(SILFunction *Callee);
SILFunction *
lookupSILFunction(StringRef Name, bool declarationOnly = false,
Optional<SILLinkage> linkage = None);
bool hasSILFunction(StringRef Name, Optional<SILLinkage> linkage = None);
SILLinkage linkage = SILLinkage::Private);
bool hasSILFunction(StringRef Name, SILLinkage linkage = SILLinkage::Private);
SILVTable *lookupVTable(Identifier Name);
SILVTable *lookupVTable(const ClassDecl *C) {
return lookupVTable(C->getName());
Expand Down
27 changes: 7 additions & 20 deletions lib/AST/Substitution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,26 +97,13 @@ Substitution Substitution::subst(ModuleDecl *module,
// conformances from thin air. FIXME: gross.
if (!conformance &&
proto->isSpecificProtocol(KnownProtocolKind::AnyObject)) {
auto archetype =
dyn_cast<ArchetypeType>(substReplacement->getCanonicalType());
// If classDecl is not nullptr, it is a concrete class.
auto classDecl = substReplacement->getClassOrBoundGenericClass();
if (!classDecl && archetype->getSuperclass()) {
// Replacement type is an archetype with a superclass constraint.
classDecl = archetype->getSuperclass()->getClassOrBoundGenericClass();
assert(classDecl);
}
if (classDecl) {
// Create a concrete conformance based on the conforming class.
SmallVector<ProtocolConformance *, 1> lookupResults;
classDecl->lookupConformance(classDecl->getParentModule(), proto,
lookupResults);
conformance = ProtocolConformanceRef(lookupResults.front());
} else if (archetype && archetype->requiresClass()) {
// Replacement type is an archetype with a class constraint.
// Create an abstract conformance.
conformance = ProtocolConformanceRef(proto);
}
auto classDecl
= substReplacement->getClassOrBoundGenericClass();
assert(classDecl);
SmallVector<ProtocolConformance *, 1> lookupResults;
classDecl->lookupConformance(classDecl->getParentModule(),
proto, lookupResults);
conformance = ProtocolConformanceRef(lookupResults.front());
}

assert(conformance);
Expand Down
21 changes: 1 addition & 20 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,34 +731,19 @@ class IRGenSILFunction :
copy.push_back(alloca.getAddress());
}

/// Determine whether a generic variable has been inlined.
static bool isInlinedGeneric(VarDecl *VarDecl, const SILDebugScope *DS) {
if (!DS->InlinedCallSite)
return false;
if (VarDecl->hasType())
return VarDecl->getType()->hasArchetype();
return VarDecl->getInterfaceType()->hasTypeParameter();
}

/// Emit debug info for a function argument or a local variable.
template <typename StorageType>
void emitDebugVariableDeclaration(StorageType Storage,
DebugTypeInfo Ty,
SILType SILTy,
const SILDebugScope *DS,
VarDecl *VarDecl,
ValueDecl *VarDecl,
StringRef Name,
unsigned ArgNo = 0,
IndirectionKind Indirection = DirectValue) {
// Force all archetypes referenced by the type to be bound by this point.
// TODO: just make sure that we have a path to them that the debug info
// can follow.

// FIXME: The debug info type of all inlined instances of a variable must be
// the same as the type of the abstract variable.
if (isInlinedGeneric(VarDecl, DS))
return;

auto runtimeTy = getRuntimeReifiedType(IGM,
Ty.getType()->getCanonicalType());
if (!IGM.IRGen.Opts.Optimize && runtimeTy->hasArchetype())
Expand Down Expand Up @@ -3769,10 +3754,6 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
CurSILFn->getDeclContext(), Decl,
i->getBoxType()->getFieldType(IGM.getSILModule(), 0).getSwiftType(),
type, /*Unwrap=*/false);

if (isInlinedGeneric(Decl, i->getDebugScope()))
return;

IGM.DebugInfo->emitVariableDeclaration(
Builder,
emitShadowCopy(boxWithAddr.getAddress(), i->getDebugScope(), Name, 0),
Expand Down
3 changes: 1 addition & 2 deletions lib/SIL/Linker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,7 @@ SILFunction *SILLinkerVisitor::lookupFunction(StringRef Name,
}

/// Process Decl, recursively deserializing any thing Decl may reference.
bool SILLinkerVisitor::hasFunction(StringRef Name,
Optional<SILLinkage> Linkage) {
bool SILLinkerVisitor::hasFunction(StringRef Name, SILLinkage Linkage) {
return Loader->hasSILFunction(Name, Linkage);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/SIL/Linker.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class SILLinkerVisitor : public SILInstructionVisitor<SILLinkerVisitor, bool> {

/// Process Name, try to check if there is a declaration of a function
/// with this Name.
bool hasFunction(StringRef Name, Optional<SILLinkage> Linkage = None);
bool hasFunction(StringRef Name, SILLinkage Linkage);

/// Deserialize the VTable mapped to C if it exists and all SIL the VTable
/// transitively references.
Expand Down
46 changes: 11 additions & 35 deletions lib/SIL/SILModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -499,29 +499,9 @@ bool SILModule::linkFunction(StringRef Name, SILModule::LinkingMode Mode) {
return SILLinkerVisitor(*this, getSILLoader(), Mode).processFunction(Name);
}

bool SILModule::hasFunction(StringRef Name) {
if (lookUpFunction(Name))
return true;
SILLinkerVisitor Visitor(*this, getSILLoader(),
SILModule::LinkingMode::LinkNormal);
return Visitor.hasFunction(Name);
}

/// Check if a given SIL linkage matches the required linkage.
/// If the required linkage is Private, then anything matches it.
static bool isMatchingLinkage(SILLinkage ActualLinkage,
Optional<SILLinkage> Linkage) {
if (!Linkage)
return true;
return ActualLinkage == Linkage;
}

SILFunction *SILModule::findFunction(StringRef Name,
Optional<SILLinkage> Linkage) {
assert(Linkage);
auto RequiredLinkage = *Linkage;
assert((RequiredLinkage == SILLinkage::Public ||
RequiredLinkage == SILLinkage::PublicExternal) &&
SILFunction *SILModule::hasFunction(StringRef Name, SILLinkage Linkage) {
assert((Linkage == SILLinkage::Public ||
Linkage == SILLinkage::PublicExternal) &&
"Only a lookup of public functions is supported currently");

SILFunction *F = nullptr;
Expand All @@ -532,10 +512,10 @@ SILFunction *SILModule::findFunction(StringRef Name,

// Nothing to do if the current module has a required function
// with a proper linkage already.
if (CurF && isMatchingLinkage(CurF->getLinkage(), Linkage)) {
if (CurF && CurF->getLinkage() == Linkage) {
F = CurF;
} else {
assert((!CurF || CurF->getLinkage() != RequiredLinkage) &&
assert((!CurF || CurF->getLinkage() != Linkage) &&
"hasFunction should be only called for functions that are not "
"contained in the SILModule yet or do not have a required linkage");
}
Expand All @@ -548,7 +528,7 @@ SILFunction *SILModule::findFunction(StringRef Name,
// name is present in the current module.
// This is done to reduce the amount of IO from the
// swift module file.
if (!Visitor.hasFunction(Name, RequiredLinkage))
if (!Visitor.hasFunction(Name, Linkage))
return nullptr;
// The function in the current module will be changed.
F = CurF;
Expand All @@ -558,31 +538,27 @@ SILFunction *SILModule::findFunction(StringRef Name,
// or if it is known to exist, perform a lookup.
if (!F) {
// Try to load the function from other modules.
F = Visitor.lookupFunction(Name, RequiredLinkage);
F = Visitor.lookupFunction(Name, Linkage);
// Bail if nothing was found and we are not sure if
// this function exists elsewhere.
if (!F)
return nullptr;
assert(F && "SILFunction should be present in one of the modules");
assert(isMatchingLinkage(F->getLinkage(), Linkage) &&
"SILFunction has a wrong linkage");
assert(F->getLinkage() == Linkage && "SILFunction has a wrong linkage");
}
}

// If an external public function representing a pre-specialization
// exists already and it is a non-optimizing compilation,
// simply convert it into an external declaration,
// If a function exists already and it is a non-optimizing
// compilation, simply convert it into an external declaration,
// so that a compiled version from the shared library is used.
// It is important to remove its body here, because it may
// contain references to non-public functions.
if (F->isDefinition() &&
F->getModule().getOptions().Optimization <
SILOptions::SILOptMode::Optimize) {
F->convertToDeclaration();
}
if (F->isExternalDeclaration())
F->setFragile(IsFragile_t::IsNotFragile);
F->setLinkage(RequiredLinkage);
F->setLinkage(Linkage);
return F;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/SILOptimizer/IPO/EagerSpecializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class EagerDispatch {
substConv(ReInfo.getSubstitutedType(), GenericFunc->getModule()),
Builder(*GenericFunc), Loc(GenericFunc->getLocation()) {
Builder.setCurrentDebugScope(GenericFunc->getDebugScope());
IsClassF = Builder.getModule().findFunction(
IsClassF = Builder.getModule().hasFunction(
"_swift_isClassOrObjCExistentialType", SILLinkage::PublicExternal);
assert(IsClassF);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static SILInstruction *findOnlyApply(SILFunction *F) {
///
/// TODO: we should teach the demangler to understand this suffix.
static std::string getUniqueName(std::string Name, SILModule &M) {
if (!M.hasFunction(Name))
if (!M.lookUpFunction(Name))
return Name;
return getUniqueName(Name + "_unique_suffix", M);
}
Expand Down Expand Up @@ -372,7 +372,7 @@ std::string FunctionSignatureTransform::createOptimizedSILFunctionName() {
do {
New = NewFM.mangle(UniqueID);
++UniqueID;
} while (M.hasFunction(New));
} while (M.lookUpFunction(New));

return NewMangling::selectMangling(Old, New);
}
Expand Down
Loading