Skip to content

Commit 49078dd

Browse files
authored
Merge pull request #8114 from eeckstein/remove-conformancecollector
2 parents ca3a398 + a16beae commit 49078dd

File tree

8 files changed

+7
-544
lines changed

8 files changed

+7
-544
lines changed

include/swift/SIL/InstructionUtils.h

Lines changed: 0 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,9 @@
1414
#define SWIFT_SIL_INSTRUCTIONUTILS_H
1515

1616
#include "swift/SIL/SILInstruction.h"
17-
#include "llvm/ADT/SmallVector.h"
18-
#include "llvm/ADT/SmallPtrSet.h"
1917

2018
namespace swift {
2119

22-
class SILWitnessTable;
23-
2420
/// Strip off casts/indexing insts/address projections from V until there is
2521
/// nothing left to strip.
2622
SILValue getUnderlyingObject(SILValue V);
@@ -77,99 +73,6 @@ SILValue stripIndexingInsts(SILValue V);
7773
/// intrinsic call.
7874
SILValue stripExpectIntrinsic(SILValue V);
7975

80-
/// Collects conformances which are used by instructions or inside witness
81-
/// tables.
82-
///
83-
/// It also collects "escaping" metatypes. If a metatype can escape to a not
84-
/// visible function (outside the compilation unit), all it's conformances have
85-
/// to be alive, because an opaque type can be tested at runtime if it conforms
86-
/// to a protocol.
87-
class ConformanceCollector {
88-
/// The used conformances.
89-
llvm::SmallVector<const ProtocolConformance *, 8> Conformances;
90-
91-
/// Types of which metatypes are escaping.
92-
llvm::SmallVector<const NominalTypeDecl *, 8> EscapingMetaTypes;
93-
94-
/// Conformances and types which have been handled.
95-
llvm::SmallPtrSet<const void *, 8> Visited;
96-
97-
SILModule &M;
98-
99-
void scanType(Type type);
100-
void scanSubsts(SubstitutionList substs);
101-
102-
template <typename T> void scanFuncParams(ArrayRef<T> OrigParams,
103-
ArrayRef<T> SubstParams) {
104-
size_t NumParams = OrigParams.size();
105-
assert(NumParams == SubstParams.size());
106-
for (size_t Idx = 0; Idx < NumParams; ++Idx) {
107-
if (OrigParams[Idx].getType()->hasTypeParameter()) {
108-
scanType(SubstParams[Idx].getType());
109-
}
110-
}
111-
}
112-
113-
void scanConformance(ProtocolConformance *C);
114-
115-
void scanConformance(ProtocolConformanceRef CRef) {
116-
if (CRef.isConcrete())
117-
scanConformance(CRef.getConcrete());
118-
}
119-
120-
void scanConformances(ArrayRef<ProtocolConformanceRef> CRefs);
121-
122-
public:
123-
124-
ConformanceCollector(SILModule &M) : M(M) { }
125-
126-
#ifndef NDEBUG
127-
static bool verifyInIRGen() {
128-
// TODO: currently disabled because of several problems.
129-
return false;
130-
}
131-
#endif
132-
133-
/// Collect all used conformances of an instruction.
134-
///
135-
/// If the instruction can escape a metatype, also record this metatype.
136-
void collect(SILInstruction *I);
137-
138-
/// Collect all used conformances and metatypes of a witness table.
139-
void collect(SILWitnessTable *WT);
140-
141-
/// Clears all information about used conformances and metatypes.
142-
void clear() {
143-
Conformances.clear();
144-
EscapingMetaTypes.clear();
145-
Visited.clear();
146-
}
147-
148-
/// For debug purposes.
149-
void dump();
150-
151-
/// Returns the list of collected used conformances.
152-
ArrayRef<const ProtocolConformance *> getUsedConformances() {
153-
return Conformances;
154-
}
155-
156-
/// Returns the list of collected escaping metatypes.
157-
ArrayRef<const NominalTypeDecl *> getEscapingMetaTypes() {
158-
return EscapingMetaTypes;
159-
}
160-
161-
/// Returns true if \p Conf is in the list of used conformances.
162-
bool isUsed(const ProtocolConformance *Conf) {
163-
return Visited.count(Conf) != 0;
164-
}
165-
166-
/// Returns true if the metatype of \p NT is in the list of escaping
167-
/// metatypes.
168-
bool isMetaTypeEscaping(const NominalTypeDecl *NT) {
169-
return Visited.count(NT) != 0;
170-
}
171-
};
172-
17376
/// A utility class for evaluating whether a newly parsed or deserialized
17477
/// function has qualified or unqualified ownership.
17578
///

lib/IRGen/GenDecl.cpp

Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -849,19 +849,9 @@ void IRGenerator::emitGlobalTopLevel() {
849849
// Emit witness tables.
850850
for (SILWitnessTable &wt : PrimaryIGM->getSILModule().getWitnessTableList()) {
851851
CurrentIGMPtr IGM = getGenModule(wt.getConformance()->getDeclContext());
852-
#ifndef NDEBUG
853-
IGM->EligibleConfs.collect(&wt);
854-
IGM->CurrentWitnessTable = &wt;
855-
#endif
856-
857852
if (!canEmitWitnessTableLazily(&wt)) {
858853
IGM->emitSILWitnessTable(&wt);
859854
}
860-
861-
#ifndef NDEBUG
862-
IGM->EligibleConfs.clear();
863-
IGM->CurrentWitnessTable = nullptr;
864-
#endif
865855
}
866856

867857
for (auto Iter : *this) {
@@ -1895,83 +1885,6 @@ IRGenModule::getAddrOfLLVMVariable(LinkEntity entity, Alignment alignment,
18951885
llvm_unreachable("bad reference kind");
18961886
}
18971887

1898-
void IRGenModule::checkEligibleConf(const ProtocolConformance *Conf) {
1899-
#ifndef NDEBUG
1900-
if (!ConformanceCollector::verifyInIRGen())
1901-
return;
1902-
1903-
if (EligibleConfs.isUsed(Conf))
1904-
return;
1905-
1906-
if (CurrentInst) {
1907-
llvm::errs() << "## Conformance: ";
1908-
Conf->dump();
1909-
llvm::errs() << "## Inst: ";
1910-
CurrentInst->dump();
1911-
llvm_unreachable(
1912-
"ConformanceCollector is missing a conformance in instruction");
1913-
}
1914-
if (CurrentWitnessTable) {
1915-
llvm_unreachable(
1916-
"ConformanceCollector is missing a conformance in witness table");
1917-
}
1918-
#endif
1919-
}
1920-
1921-
void IRGenModule::checkEligibleMetaType(NominalTypeDecl *NT) {
1922-
#ifndef NDEBUG
1923-
if (!ConformanceCollector::verifyInIRGen())
1924-
return;
1925-
1926-
if (!NT || EligibleConfs.isMetaTypeEscaping(NT))
1927-
return;
1928-
1929-
if (CurrentInst) {
1930-
// Ignore instructions which may use a metatype but do not let escape it.
1931-
switch (CurrentInst->getKind()) {
1932-
case ValueKind::DestroyAddrInst:
1933-
case ValueKind::StructElementAddrInst:
1934-
case ValueKind::TupleElementAddrInst:
1935-
case ValueKind::InjectEnumAddrInst:
1936-
case ValueKind::SwitchEnumAddrInst:
1937-
case ValueKind::SelectEnumAddrInst:
1938-
case ValueKind::IndexAddrInst:
1939-
case ValueKind::RefElementAddrInst:
1940-
case ValueKind::RefTailAddrInst:
1941-
case ValueKind::TailAddrInst:
1942-
case ValueKind::AllocValueBufferInst:
1943-
case ValueKind::ProjectValueBufferInst:
1944-
case ValueKind::ProjectBoxInst:
1945-
case ValueKind::CopyAddrInst:
1946-
case ValueKind::UncheckedRefCastAddrInst:
1947-
case ValueKind::AllocStackInst:
1948-
case ValueKind::SuperMethodInst:
1949-
case ValueKind::WitnessMethodInst:
1950-
case ValueKind::DeallocRefInst:
1951-
case ValueKind::AllocGlobalInst:
1952-
return;
1953-
case ValueKind::ApplyInst:
1954-
case ValueKind::TryApplyInst:
1955-
case ValueKind::PartialApplyInst:
1956-
// It's not trivial to find the non-escaping vs. escaping meta-
1957-
// types of an apply. Therefore we just trust the ConformanceCollector
1958-
// that it does the right job.
1959-
return;
1960-
default:
1961-
break;
1962-
}
1963-
llvm::errs() << "## NominalType: " << NT->getName() << "\n## Inst: ";
1964-
CurrentInst->dump();
1965-
llvm_unreachable(
1966-
"ConformanceCollector is missing a metatype in instruction");
1967-
}
1968-
if (CurrentWitnessTable) {
1969-
llvm_unreachable(
1970-
"ConformanceCollector is missing a metatype in witness table");
1971-
}
1972-
#endif
1973-
}
1974-
19751888
/// A convenient wrapper around getAddrOfLLVMVariable which uses the
19761889
/// default type as the definition type.
19771890
llvm::Constant *
@@ -2513,7 +2426,6 @@ IRGenModule::getAddrOfTypeMetadataAccessFunction(CanType type,
25132426
ForDefinition_t forDefinition) {
25142427
assert(!type->hasArchetype() && !type->hasTypeParameter());
25152428
NominalTypeDecl *Nominal = type->getNominalOrBoundGenericNominal();
2516-
checkEligibleMetaType(Nominal);
25172429
IRGen.addLazyTypeMetadata(Nominal);
25182430

25192431
LinkEntity entity = LinkEntity::forTypeMetadataAccessFunction(type);
@@ -2537,7 +2449,6 @@ IRGenModule::getAddrOfGenericTypeMetadataAccessFunction(
25372449
ForDefinition_t forDefinition) {
25382450
assert(!genericArgs.empty());
25392451
assert(nominal->isGenericContext());
2540-
checkEligibleMetaType(nominal);
25412452
IRGen.addLazyTypeMetadata(nominal);
25422453

25432454
auto type = nominal->getDeclaredType()->getCanonicalType();
@@ -2561,7 +2472,6 @@ llvm::Constant *
25612472
IRGenModule::getAddrOfTypeMetadataLazyCacheVariable(CanType type,
25622473
ForDefinition_t forDefinition) {
25632474
assert(!type->hasArchetype() && !type->hasTypeParameter());
2564-
checkEligibleMetaType(type->getNominalOrBoundGenericNominal());
25652475
LinkEntity entity = LinkEntity::forTypeMetadataLazyCacheVariable(type);
25662476
return getAddrOfLLVMVariable(entity, getPointerAlignment(), forDefinition,
25672477
TypeMetadataPtrTy, DebugTypeInfo());
@@ -2712,7 +2622,6 @@ ConstantReference IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
27122622
SymbolReferenceKind refKind) {
27132623
assert(isPattern || !isa<UnboundGenericType>(concreteType));
27142624

2715-
checkEligibleMetaType(concreteType->getNominalOrBoundGenericNominal());
27162625
llvm::Type *defaultVarTy;
27172626
unsigned adjustmentIndex;
27182627
Alignment alignment = getPointerAlignment();
@@ -2807,7 +2716,6 @@ ConstantReference IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
28072716
llvm::Constant *IRGenModule::getAddrOfNominalTypeDescriptor(NominalTypeDecl *D,
28082717
ConstantInitFuture definition) {
28092718
assert(definition && "not defining nominal type descriptor?");
2810-
checkEligibleMetaType(D);
28112719
auto entity = LinkEntity::forNominalTypeDescriptor(D);
28122720
return getAddrOfLLVMVariable(entity, getPointerAlignment(),
28132721
definition,
@@ -3181,7 +3089,6 @@ IRGenModule::getResilienceExpansionForLayout(SILGlobalVariable *global) {
31813089
llvm::Constant *IRGenModule::
31823090
getAddrOfGenericWitnessTableCache(const NormalProtocolConformance *conf,
31833091
ForDefinition_t forDefinition) {
3184-
checkEligibleConf(conf);
31853092
auto entity = LinkEntity::forGenericProtocolWitnessTableCache(conf);
31863093
auto expectedTy = getGenericWitnessTableCacheTy();
31873094
return getAddrOfLLVMVariable(entity, getPointerAlignment(), forDefinition,
@@ -3191,7 +3098,6 @@ getAddrOfGenericWitnessTableCache(const NormalProtocolConformance *conf,
31913098
llvm::Function *
31923099
IRGenModule::getAddrOfGenericWitnessTableInstantiationFunction(
31933100
const NormalProtocolConformance *conf) {
3194-
checkEligibleConf(conf);
31953101
auto forDefinition = ForDefinition;
31963102

31973103
LinkEntity entity =
@@ -3238,8 +3144,6 @@ llvm::Function *
32383144
IRGenModule::getAddrOfWitnessTableAccessFunction(
32393145
const NormalProtocolConformance *conf,
32403146
ForDefinition_t forDefinition) {
3241-
checkEligibleConf(conf);
3242-
32433147
IRGen.addLazyWitnessTable(conf);
32443148

32453149
LinkEntity entity = LinkEntity::forProtocolWitnessTableAccessFunction(conf);
@@ -3268,7 +3172,6 @@ IRGenModule::getAddrOfWitnessTableLazyAccessFunction(
32683172
const NormalProtocolConformance *conf,
32693173
CanType conformingType,
32703174
ForDefinition_t forDefinition) {
3271-
checkEligibleConf(conf);
32723175
LinkEntity entity =
32733176
LinkEntity::forProtocolWitnessTableLazyAccessFunction(conf, conformingType);
32743177
llvm::Function *&entry = GlobalFuncs[entity];
@@ -3293,7 +3196,6 @@ IRGenModule::getAddrOfWitnessTableLazyCacheVariable(
32933196
CanType conformingType,
32943197
ForDefinition_t forDefinition) {
32953198
assert(!conformingType->hasArchetype());
3296-
checkEligibleConf(conf);
32973199
LinkEntity entity =
32983200
LinkEntity::forProtocolWitnessTableLazyCacheVariable(conf, conformingType);
32993201
return getAddrOfLLVMVariable(entity, getPointerAlignment(),
@@ -3310,7 +3212,6 @@ IRGenModule::getAddrOfWitnessTableLazyCacheVariable(
33103212
llvm::Constant*
33113213
IRGenModule::getAddrOfWitnessTable(const NormalProtocolConformance *conf,
33123214
ConstantInit definition) {
3313-
checkEligibleConf(conf);
33143215
IRGen.addLazyWitnessTable(conf);
33153216

33163217
auto entity = LinkEntity::forDirectProtocolWitnessTable(conf);
@@ -3322,7 +3223,6 @@ llvm::Function *
33223223
IRGenModule::getAddrOfAssociatedTypeMetadataAccessFunction(
33233224
const NormalProtocolConformance *conformance,
33243225
AssociatedTypeDecl *associate) {
3325-
checkEligibleConf(conformance);
33263226
auto forDefinition = ForDefinition;
33273227

33283228
LinkEntity entity =
@@ -3344,7 +3244,6 @@ IRGenModule::getAddrOfAssociatedTypeWitnessTableAccessFunction(
33443244
const NormalProtocolConformance *conformance,
33453245
CanType associatedType,
33463246
ProtocolDecl *associatedProtocol) {
3347-
checkEligibleConf(conformance);
33483247
auto forDefinition = ForDefinition;
33493248

33503249
LinkEntity entity =

lib/IRGen/IRGenModule.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,6 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
135135
DataLayout(target->createDataLayout()), Triple(Context.LangOpts.Target),
136136
TargetMachine(std::move(target)), silConv(irgen.SIL),
137137
OutputFilename(OutputFilename),
138-
#ifndef NDEBUG
139-
EligibleConfs(getSILModule()),
140-
#endif
141138
TargetInfo(SwiftTargetInfo::get(*this)), DebugInfo(nullptr),
142139
ModuleHash(nullptr), ObjCInterop(Context.LangOpts.EnableObjCInterop),
143140
Types(*new TypeConverter(*this)) {

lib/IRGen/IRGenModule.h

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
#include "swift/AST/Decl.h"
2222
#include "swift/AST/Module.h"
2323
#include "swift/SIL/SILFunction.h"
24-
#include "swift/SIL/SILWitnessTable.h"
25-
#include "swift/SIL/InstructionUtils.h"
2624
#include "swift/Basic/LLVM.h"
2725
#include "swift/Basic/ClusteredBitVector.h"
2826
#include "swift/Basic/SuccessorMap.h"
@@ -396,14 +394,7 @@ class IRGenModule {
396394
SILModuleConventions silConv;
397395

398396
llvm::SmallString<128> OutputFilename;
399-
400-
#ifndef NDEBUG
401-
// Used for testing ConformanceCollector.
402-
ConformanceCollector EligibleConfs;
403-
SILInstruction *CurrentInst = nullptr;
404-
SILWitnessTable *CurrentWitnessTable = nullptr;
405-
#endif
406-
397+
407398
/// Order dependency -- TargetInfo must be initialized after Opts.
408399
const SwiftTargetInfo TargetInfo;
409400
/// Holds lexical scope info, etc. Is a nullptr if we compile without -g.
@@ -1049,9 +1040,6 @@ private: \
10491040
DebugTypeInfo debugType,
10501041
SymbolReferenceKind refKind);
10511042

1052-
void checkEligibleConf(const ProtocolConformance *Conf);
1053-
void checkEligibleMetaType(NominalTypeDecl *NT);
1054-
10551043
void emitLazyPrivateDefinitions();
10561044
void addRuntimeResolvableType(CanType type);
10571045

lib/IRGen/IRGenSIL.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include "swift/SIL/SILModule.h"
4545
#include "swift/SIL/SILType.h"
4646
#include "swift/SIL/SILVisitor.h"
47+
#include "swift/SIL/InstructionUtils.h"
4748
#include "clang/CodeGen/CodeGenABITypes.h"
4849

4950
#include "CallEmission.h"
@@ -1589,10 +1590,6 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
15891590

15901591
for (auto InsnIter = BB->begin(); InsnIter != BB->end(); ++InsnIter) {
15911592
auto &I = *InsnIter;
1592-
#ifndef NDEBUG
1593-
IGM.EligibleConfs.collect(&I);
1594-
IGM.CurrentInst = &I;
1595-
#endif
15961593
if (IGM.DebugInfo) {
15971594
// Set the debug info location for I, if applicable.
15981595
SILLocation ILoc = I.getLoc();
@@ -1647,10 +1644,6 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
16471644
}
16481645
visit(&I);
16491646

1650-
#ifndef NDEBUG
1651-
IGM.EligibleConfs.clear();
1652-
IGM.CurrentInst = nullptr;
1653-
#endif
16541647
}
16551648

16561649
assert(Builder.hasPostTerminatorIP() && "SIL bb did not terminate block?!");

0 commit comments

Comments
 (0)