Skip to content

Commit 542638d

Browse files
authored
Merge pull request swiftlang#7428 from jrose-apple/revert-generics-inlining
2 parents 5ca9aae + 1c60910 commit 542638d

24 files changed

+75
-340
lines changed

include/swift/SIL/SILModule.h

+3-10
Original file line numberDiff line numberDiff line change
@@ -430,19 +430,12 @@ class SILModule {
430430
bool linkFunction(StringRef Name,
431431
LinkingMode LinkAll = LinkingMode::LinkNormal);
432432

433-
/// Check if a given function exists in any of the modules with a
434-
/// required linkage, i.e. it can be linked by linkFunction.
435-
///
436-
/// If linkage parameter is none, then the linkage of the function
437-
/// with a given name does not matter.
433+
/// Check if a given function exists in the module,
434+
/// i.e. it can be linked by linkFunction.
438435
///
439436
/// \return null if this module has no such function. Otherwise
440437
/// the declaration of a function.
441-
SILFunction *findFunction(StringRef Name, Optional<SILLinkage> Linkage);
442-
443-
/// Check if a given function exists in the module,
444-
/// i.e. it can be linked by linkFunction.
445-
bool hasFunction(StringRef Name);
438+
SILFunction *hasFunction(StringRef Name, SILLinkage Linkage);
446439

447440
/// Link in all Witness Tables in the module.
448441
void linkAllWitnessTables();

include/swift/SILOptimizer/Utils/Devirtualize.h

-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ typedef std::pair<ValueBase *, ApplySite> DevirtualizationResult;
4646
DevirtualizationResult tryDevirtualizeApply(FullApplySite AI);
4747
DevirtualizationResult tryDevirtualizeApply(FullApplySite AI,
4848
ClassHierarchyAnalysis *CHA);
49-
bool canDevirtualizeApply(FullApplySite AI, ClassHierarchyAnalysis *CHA);
5049
bool isNominalTypeWithUnboundGenericParameters(SILType Ty, SILModule &M);
5150
bool canDevirtualizeClassMethod(FullApplySite AI, SILType ClassInstanceType);
5251
SILFunction *getTargetClassMethod(SILModule &M, SILType ClassOrMetatypeType,

include/swift/Serialization/SerializedSILLoader.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ class SerializedSILLoader {
9292
SILFunction *lookupSILFunction(SILFunction *Callee);
9393
SILFunction *
9494
lookupSILFunction(StringRef Name, bool declarationOnly = false,
95-
Optional<SILLinkage> linkage = None);
96-
bool hasSILFunction(StringRef Name, Optional<SILLinkage> linkage = None);
95+
SILLinkage linkage = SILLinkage::Private);
96+
bool hasSILFunction(StringRef Name, SILLinkage linkage = SILLinkage::Private);
9797
SILVTable *lookupVTable(Identifier Name);
9898
SILVTable *lookupVTable(const ClassDecl *C) {
9999
return lookupVTable(C->getName());

lib/AST/Substitution.cpp

+7-20
Original file line numberDiff line numberDiff line change
@@ -97,26 +97,13 @@ Substitution Substitution::subst(ModuleDecl *module,
9797
// conformances from thin air. FIXME: gross.
9898
if (!conformance &&
9999
proto->isSpecificProtocol(KnownProtocolKind::AnyObject)) {
100-
auto archetype =
101-
dyn_cast<ArchetypeType>(substReplacement->getCanonicalType());
102-
// If classDecl is not nullptr, it is a concrete class.
103-
auto classDecl = substReplacement->getClassOrBoundGenericClass();
104-
if (!classDecl && archetype->getSuperclass()) {
105-
// Replacement type is an archetype with a superclass constraint.
106-
classDecl = archetype->getSuperclass()->getClassOrBoundGenericClass();
107-
assert(classDecl);
108-
}
109-
if (classDecl) {
110-
// Create a concrete conformance based on the conforming class.
111-
SmallVector<ProtocolConformance *, 1> lookupResults;
112-
classDecl->lookupConformance(classDecl->getParentModule(), proto,
113-
lookupResults);
114-
conformance = ProtocolConformanceRef(lookupResults.front());
115-
} else if (archetype && archetype->requiresClass()) {
116-
// Replacement type is an archetype with a class constraint.
117-
// Create an abstract conformance.
118-
conformance = ProtocolConformanceRef(proto);
119-
}
100+
auto classDecl
101+
= substReplacement->getClassOrBoundGenericClass();
102+
assert(classDecl);
103+
SmallVector<ProtocolConformance *, 1> lookupResults;
104+
classDecl->lookupConformance(classDecl->getParentModule(),
105+
proto, lookupResults);
106+
conformance = ProtocolConformanceRef(lookupResults.front());
120107
}
121108

122109
assert(conformance);

lib/IRGen/IRGenSIL.cpp

+1-20
Original file line numberDiff line numberDiff line change
@@ -731,34 +731,19 @@ class IRGenSILFunction :
731731
copy.push_back(alloca.getAddress());
732732
}
733733

734-
/// Determine whether a generic variable has been inlined.
735-
static bool isInlinedGeneric(VarDecl *VarDecl, const SILDebugScope *DS) {
736-
if (!DS->InlinedCallSite)
737-
return false;
738-
if (VarDecl->hasType())
739-
return VarDecl->getType()->hasArchetype();
740-
return VarDecl->getInterfaceType()->hasTypeParameter();
741-
}
742-
743734
/// Emit debug info for a function argument or a local variable.
744735
template <typename StorageType>
745736
void emitDebugVariableDeclaration(StorageType Storage,
746737
DebugTypeInfo Ty,
747738
SILType SILTy,
748739
const SILDebugScope *DS,
749-
VarDecl *VarDecl,
740+
ValueDecl *VarDecl,
750741
StringRef Name,
751742
unsigned ArgNo = 0,
752743
IndirectionKind Indirection = DirectValue) {
753744
// Force all archetypes referenced by the type to be bound by this point.
754745
// TODO: just make sure that we have a path to them that the debug info
755746
// can follow.
756-
757-
// FIXME: The debug info type of all inlined instances of a variable must be
758-
// the same as the type of the abstract variable.
759-
if (isInlinedGeneric(VarDecl, DS))
760-
return;
761-
762747
auto runtimeTy = getRuntimeReifiedType(IGM,
763748
Ty.getType()->getCanonicalType());
764749
if (!IGM.IRGen.Opts.Optimize && runtimeTy->hasArchetype())
@@ -3769,10 +3754,6 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
37693754
CurSILFn->getDeclContext(), Decl,
37703755
i->getBoxType()->getFieldType(IGM.getSILModule(), 0).getSwiftType(),
37713756
type, /*Unwrap=*/false);
3772-
3773-
if (isInlinedGeneric(Decl, i->getDebugScope()))
3774-
return;
3775-
37763757
IGM.DebugInfo->emitVariableDeclaration(
37773758
Builder,
37783759
emitShadowCopy(boxWithAddr.getAddress(), i->getDebugScope(), Name, 0),

lib/SIL/Linker.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ SILFunction *SILLinkerVisitor::lookupFunction(StringRef Name,
117117
}
118118

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

lib/SIL/Linker.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class SILLinkerVisitor : public SILInstructionVisitor<SILLinkerVisitor, bool> {
6060

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

6565
/// Deserialize the VTable mapped to C if it exists and all SIL the VTable
6666
/// transitively references.

lib/SIL/SILModule.cpp

+11-35
Original file line numberDiff line numberDiff line change
@@ -499,29 +499,9 @@ bool SILModule::linkFunction(StringRef Name, SILModule::LinkingMode Mode) {
499499
return SILLinkerVisitor(*this, getSILLoader(), Mode).processFunction(Name);
500500
}
501501

502-
bool SILModule::hasFunction(StringRef Name) {
503-
if (lookUpFunction(Name))
504-
return true;
505-
SILLinkerVisitor Visitor(*this, getSILLoader(),
506-
SILModule::LinkingMode::LinkNormal);
507-
return Visitor.hasFunction(Name);
508-
}
509-
510-
/// Check if a given SIL linkage matches the required linkage.
511-
/// If the required linkage is Private, then anything matches it.
512-
static bool isMatchingLinkage(SILLinkage ActualLinkage,
513-
Optional<SILLinkage> Linkage) {
514-
if (!Linkage)
515-
return true;
516-
return ActualLinkage == Linkage;
517-
}
518-
519-
SILFunction *SILModule::findFunction(StringRef Name,
520-
Optional<SILLinkage> Linkage) {
521-
assert(Linkage);
522-
auto RequiredLinkage = *Linkage;
523-
assert((RequiredLinkage == SILLinkage::Public ||
524-
RequiredLinkage == SILLinkage::PublicExternal) &&
502+
SILFunction *SILModule::hasFunction(StringRef Name, SILLinkage Linkage) {
503+
assert((Linkage == SILLinkage::Public ||
504+
Linkage == SILLinkage::PublicExternal) &&
525505
"Only a lookup of public functions is supported currently");
526506

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

533513
// Nothing to do if the current module has a required function
534514
// with a proper linkage already.
535-
if (CurF && isMatchingLinkage(CurF->getLinkage(), Linkage)) {
515+
if (CurF && CurF->getLinkage() == Linkage) {
536516
F = CurF;
537517
} else {
538-
assert((!CurF || CurF->getLinkage() != RequiredLinkage) &&
518+
assert((!CurF || CurF->getLinkage() != Linkage) &&
539519
"hasFunction should be only called for functions that are not "
540520
"contained in the SILModule yet or do not have a required linkage");
541521
}
@@ -548,7 +528,7 @@ SILFunction *SILModule::findFunction(StringRef Name,
548528
// name is present in the current module.
549529
// This is done to reduce the amount of IO from the
550530
// swift module file.
551-
if (!Visitor.hasFunction(Name, RequiredLinkage))
531+
if (!Visitor.hasFunction(Name, Linkage))
552532
return nullptr;
553533
// The function in the current module will be changed.
554534
F = CurF;
@@ -558,31 +538,27 @@ SILFunction *SILModule::findFunction(StringRef Name,
558538
// or if it is known to exist, perform a lookup.
559539
if (!F) {
560540
// Try to load the function from other modules.
561-
F = Visitor.lookupFunction(Name, RequiredLinkage);
541+
F = Visitor.lookupFunction(Name, Linkage);
562542
// Bail if nothing was found and we are not sure if
563543
// this function exists elsewhere.
564544
if (!F)
565545
return nullptr;
566546
assert(F && "SILFunction should be present in one of the modules");
567-
assert(isMatchingLinkage(F->getLinkage(), Linkage) &&
568-
"SILFunction has a wrong linkage");
547+
assert(F->getLinkage() == Linkage && "SILFunction has a wrong linkage");
569548
}
570549
}
571550

572-
// If an external public function representing a pre-specialization
573-
// exists already and it is a non-optimizing compilation,
574-
// simply convert it into an external declaration,
551+
// If a function exists already and it is a non-optimizing
552+
// compilation, simply convert it into an external declaration,
575553
// so that a compiled version from the shared library is used.
576-
// It is important to remove its body here, because it may
577-
// contain references to non-public functions.
578554
if (F->isDefinition() &&
579555
F->getModule().getOptions().Optimization <
580556
SILOptions::SILOptMode::Optimize) {
581557
F->convertToDeclaration();
582558
}
583559
if (F->isExternalDeclaration())
584560
F->setFragile(IsFragile_t::IsNotFragile);
585-
F->setLinkage(RequiredLinkage);
561+
F->setLinkage(Linkage);
586562
return F;
587563
}
588564

lib/SILOptimizer/IPO/EagerSpecializer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class EagerDispatch {
287287
substConv(ReInfo.getSubstitutedType(), GenericFunc->getModule()),
288288
Builder(*GenericFunc), Loc(GenericFunc->getLocation()) {
289289
Builder.setCurrentDebugScope(GenericFunc->getDebugScope());
290-
IsClassF = Builder.getModule().findFunction(
290+
IsClassF = Builder.getModule().hasFunction(
291291
"_swift_isClassOrObjCExistentialType", SILLinkage::PublicExternal);
292292
assert(IsClassF);
293293
}

lib/SILOptimizer/Transforms/FunctionSignatureOpts.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static SILInstruction *findOnlyApply(SILFunction *F) {
9393
///
9494
/// TODO: we should teach the demangler to understand this suffix.
9595
static std::string getUniqueName(std::string Name, SILModule &M) {
96-
if (!M.hasFunction(Name))
96+
if (!M.lookUpFunction(Name))
9797
return Name;
9898
return getUniqueName(Name + "_unique_suffix", M);
9999
}
@@ -372,7 +372,7 @@ std::string FunctionSignatureTransform::createOptimizedSILFunctionName() {
372372
do {
373373
New = NewFM.mangle(UniqueID);
374374
++UniqueID;
375-
} while (M.hasFunction(New));
375+
} while (M.lookUpFunction(New));
376376

377377
return NewMangling::selectMangling(Old, New);
378378
}

0 commit comments

Comments
 (0)