Skip to content

Commit 1c60910

Browse files
committed
Revert "Merge pull request #6092 from swiftix/wip-generics-inlining-flag-4"
This reverts commit 1b3d29a, reversing changes made to b324249. We're seeing a handful of issues from turning on inlining of generics, so I'm reverting to unblock the bots.
1 parent f0c0bd8 commit 1c60910

24 files changed

+75
-343
lines changed

include/swift/SIL/SILModule.h

Lines changed: 3 additions & 10 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 7 additions & 20 deletions
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

Lines changed: 1 addition & 20 deletions
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

Lines changed: 1 addition & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -499,39 +499,23 @@ bool SILModule::linkFunction(StringRef Name, SILModule::LinkingMode Mode) {
499499
return SILLinkerVisitor(*this, getSILLoader(), Mode).processFunction(Name);
500500
}
501501

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

522507
SILFunction *F = nullptr;
523-
SILLinkage RequiredLinkage = Linkage ? *Linkage : SILLinkage::Private;
524508

525509
// First, check if there is a function with a required name in the
526510
// current module.
527511
SILFunction *CurF = lookUpFunction(Name);
528512

529513
// Nothing to do if the current module has a required function
530514
// with a proper linkage already.
531-
if (CurF && isMatchingLinkage(CurF->getLinkage(), Linkage)) {
515+
if (CurF && CurF->getLinkage() == Linkage) {
532516
F = CurF;
533517
} else {
534-
assert((!CurF || CurF->getLinkage() != RequiredLinkage) &&
518+
assert((!CurF || CurF->getLinkage() != Linkage) &&
535519
"hasFunction should be only called for functions that are not "
536520
"contained in the SILModule yet or do not have a required linkage");
537521
}
@@ -544,7 +528,7 @@ SILFunction *SILModule::findFunction(StringRef Name,
544528
// name is present in the current module.
545529
// This is done to reduce the amount of IO from the
546530
// swift module file.
547-
if (!Visitor.hasFunction(Name, RequiredLinkage))
531+
if (!Visitor.hasFunction(Name, Linkage))
548532
return nullptr;
549533
// The function in the current module will be changed.
550534
F = CurF;
@@ -554,14 +538,13 @@ SILFunction *SILModule::findFunction(StringRef Name,
554538
// or if it is known to exist, perform a lookup.
555539
if (!F) {
556540
// Try to load the function from other modules.
557-
F = Visitor.lookupFunction(Name, RequiredLinkage);
541+
F = Visitor.lookupFunction(Name, Linkage);
558542
// Bail if nothing was found and we are not sure if
559543
// this function exists elsewhere.
560544
if (!F)
561545
return nullptr;
562546
assert(F && "SILFunction should be present in one of the modules");
563-
assert(isMatchingLinkage(F->getLinkage(), Linkage) &&
564-
"SILFunction has a wrong linkage");
547+
assert(F->getLinkage() == Linkage && "SILFunction has a wrong linkage");
565548
}
566549
}
567550

@@ -573,19 +556,9 @@ SILFunction *SILModule::findFunction(StringRef Name,
573556
SILOptions::SILOptMode::Optimize) {
574557
F->convertToDeclaration();
575558
}
576-
if (F->isExternalDeclaration()) {
559+
if (F->isExternalDeclaration())
577560
F->setFragile(IsFragile_t::IsNotFragile);
578-
if (isAvailableExternally(F->getLinkage()) &&
579-
!hasPublicVisibility(F->getLinkage()) && !Linkage) {
580-
// We were just asked if a given function exists anywhere.
581-
// It is not going to be used by the current module.
582-
// Since external non-public function declarations should not
583-
// exist, strip the "external" part from the linkage.
584-
F->setLinkage(stripExternalFromLinkage(F->getLinkage()));
585-
}
586-
}
587-
if (Linkage)
588-
F->setLinkage(RequiredLinkage);
561+
F->setLinkage(Linkage);
589562
return F;
590563
}
591564

lib/SILOptimizer/IPO/EagerSpecializer.cpp

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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)