Skip to content

Remove the now usused ConformanceCollector utility. #8114

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
Mar 15, 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
97 changes: 0 additions & 97 deletions include/swift/SIL/InstructionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@
#define SWIFT_SIL_INSTRUCTIONUTILS_H

#include "swift/SIL/SILInstruction.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/SmallPtrSet.h"

namespace swift {

class SILWitnessTable;

/// Strip off casts/indexing insts/address projections from V until there is
/// nothing left to strip.
SILValue getUnderlyingObject(SILValue V);
Expand Down Expand Up @@ -77,99 +73,6 @@ SILValue stripIndexingInsts(SILValue V);
/// intrinsic call.
SILValue stripExpectIntrinsic(SILValue V);

/// Collects conformances which are used by instructions or inside witness
/// tables.
///
/// It also collects "escaping" metatypes. If a metatype can escape to a not
/// visible function (outside the compilation unit), all it's conformances have
/// to be alive, because an opaque type can be tested at runtime if it conforms
/// to a protocol.
class ConformanceCollector {
/// The used conformances.
llvm::SmallVector<const ProtocolConformance *, 8> Conformances;

/// Types of which metatypes are escaping.
llvm::SmallVector<const NominalTypeDecl *, 8> EscapingMetaTypes;

/// Conformances and types which have been handled.
llvm::SmallPtrSet<const void *, 8> Visited;

SILModule &M;

void scanType(Type type);
void scanSubsts(SubstitutionList substs);

template <typename T> void scanFuncParams(ArrayRef<T> OrigParams,
ArrayRef<T> SubstParams) {
size_t NumParams = OrigParams.size();
assert(NumParams == SubstParams.size());
for (size_t Idx = 0; Idx < NumParams; ++Idx) {
if (OrigParams[Idx].getType()->hasTypeParameter()) {
scanType(SubstParams[Idx].getType());
}
}
}

void scanConformance(ProtocolConformance *C);

void scanConformance(ProtocolConformanceRef CRef) {
if (CRef.isConcrete())
scanConformance(CRef.getConcrete());
}

void scanConformances(ArrayRef<ProtocolConformanceRef> CRefs);

public:

ConformanceCollector(SILModule &M) : M(M) { }

#ifndef NDEBUG
static bool verifyInIRGen() {
// TODO: currently disabled because of several problems.
return false;
}
#endif

/// Collect all used conformances of an instruction.
///
/// If the instruction can escape a metatype, also record this metatype.
void collect(SILInstruction *I);

/// Collect all used conformances and metatypes of a witness table.
void collect(SILWitnessTable *WT);

/// Clears all information about used conformances and metatypes.
void clear() {
Conformances.clear();
EscapingMetaTypes.clear();
Visited.clear();
}

/// For debug purposes.
void dump();

/// Returns the list of collected used conformances.
ArrayRef<const ProtocolConformance *> getUsedConformances() {
return Conformances;
}

/// Returns the list of collected escaping metatypes.
ArrayRef<const NominalTypeDecl *> getEscapingMetaTypes() {
return EscapingMetaTypes;
}

/// Returns true if \p Conf is in the list of used conformances.
bool isUsed(const ProtocolConformance *Conf) {
return Visited.count(Conf) != 0;
}

/// Returns true if the metatype of \p NT is in the list of escaping
/// metatypes.
bool isMetaTypeEscaping(const NominalTypeDecl *NT) {
return Visited.count(NT) != 0;
}
};

/// A utility class for evaluating whether a newly parsed or deserialized
/// function has qualified or unqualified ownership.
///
Expand Down
101 changes: 0 additions & 101 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -849,19 +849,9 @@ void IRGenerator::emitGlobalTopLevel() {
// Emit witness tables.
for (SILWitnessTable &wt : PrimaryIGM->getSILModule().getWitnessTableList()) {
CurrentIGMPtr IGM = getGenModule(wt.getConformance()->getDeclContext());
#ifndef NDEBUG
IGM->EligibleConfs.collect(&wt);
IGM->CurrentWitnessTable = &wt;
#endif

if (!canEmitWitnessTableLazily(&wt)) {
IGM->emitSILWitnessTable(&wt);
}

#ifndef NDEBUG
IGM->EligibleConfs.clear();
IGM->CurrentWitnessTable = nullptr;
#endif
}

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

void IRGenModule::checkEligibleConf(const ProtocolConformance *Conf) {
#ifndef NDEBUG
if (!ConformanceCollector::verifyInIRGen())
return;

if (EligibleConfs.isUsed(Conf))
return;

if (CurrentInst) {
llvm::errs() << "## Conformance: ";
Conf->dump();
llvm::errs() << "## Inst: ";
CurrentInst->dump();
llvm_unreachable(
"ConformanceCollector is missing a conformance in instruction");
}
if (CurrentWitnessTable) {
llvm_unreachable(
"ConformanceCollector is missing a conformance in witness table");
}
#endif
}

void IRGenModule::checkEligibleMetaType(NominalTypeDecl *NT) {
#ifndef NDEBUG
if (!ConformanceCollector::verifyInIRGen())
return;

if (!NT || EligibleConfs.isMetaTypeEscaping(NT))
return;

if (CurrentInst) {
// Ignore instructions which may use a metatype but do not let escape it.
switch (CurrentInst->getKind()) {
case ValueKind::DestroyAddrInst:
case ValueKind::StructElementAddrInst:
case ValueKind::TupleElementAddrInst:
case ValueKind::InjectEnumAddrInst:
case ValueKind::SwitchEnumAddrInst:
case ValueKind::SelectEnumAddrInst:
case ValueKind::IndexAddrInst:
case ValueKind::RefElementAddrInst:
case ValueKind::RefTailAddrInst:
case ValueKind::TailAddrInst:
case ValueKind::AllocValueBufferInst:
case ValueKind::ProjectValueBufferInst:
case ValueKind::ProjectBoxInst:
case ValueKind::CopyAddrInst:
case ValueKind::UncheckedRefCastAddrInst:
case ValueKind::AllocStackInst:
case ValueKind::SuperMethodInst:
case ValueKind::WitnessMethodInst:
case ValueKind::DeallocRefInst:
case ValueKind::AllocGlobalInst:
return;
case ValueKind::ApplyInst:
case ValueKind::TryApplyInst:
case ValueKind::PartialApplyInst:
// It's not trivial to find the non-escaping vs. escaping meta-
// types of an apply. Therefore we just trust the ConformanceCollector
// that it does the right job.
return;
default:
break;
}
llvm::errs() << "## NominalType: " << NT->getName() << "\n## Inst: ";
CurrentInst->dump();
llvm_unreachable(
"ConformanceCollector is missing a metatype in instruction");
}
if (CurrentWitnessTable) {
llvm_unreachable(
"ConformanceCollector is missing a metatype in witness table");
}
#endif
}

/// A convenient wrapper around getAddrOfLLVMVariable which uses the
/// default type as the definition type.
llvm::Constant *
Expand Down Expand Up @@ -2513,7 +2426,6 @@ IRGenModule::getAddrOfTypeMetadataAccessFunction(CanType type,
ForDefinition_t forDefinition) {
assert(!type->hasArchetype() && !type->hasTypeParameter());
NominalTypeDecl *Nominal = type->getNominalOrBoundGenericNominal();
checkEligibleMetaType(Nominal);
IRGen.addLazyTypeMetadata(Nominal);

LinkEntity entity = LinkEntity::forTypeMetadataAccessFunction(type);
Expand All @@ -2537,7 +2449,6 @@ IRGenModule::getAddrOfGenericTypeMetadataAccessFunction(
ForDefinition_t forDefinition) {
assert(!genericArgs.empty());
assert(nominal->isGenericContext());
checkEligibleMetaType(nominal);
IRGen.addLazyTypeMetadata(nominal);

auto type = nominal->getDeclaredType()->getCanonicalType();
Expand All @@ -2561,7 +2472,6 @@ llvm::Constant *
IRGenModule::getAddrOfTypeMetadataLazyCacheVariable(CanType type,
ForDefinition_t forDefinition) {
assert(!type->hasArchetype() && !type->hasTypeParameter());
checkEligibleMetaType(type->getNominalOrBoundGenericNominal());
LinkEntity entity = LinkEntity::forTypeMetadataLazyCacheVariable(type);
return getAddrOfLLVMVariable(entity, getPointerAlignment(), forDefinition,
TypeMetadataPtrTy, DebugTypeInfo());
Expand Down Expand Up @@ -2712,7 +2622,6 @@ ConstantReference IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
SymbolReferenceKind refKind) {
assert(isPattern || !isa<UnboundGenericType>(concreteType));

checkEligibleMetaType(concreteType->getNominalOrBoundGenericNominal());
llvm::Type *defaultVarTy;
unsigned adjustmentIndex;
Alignment alignment = getPointerAlignment();
Expand Down Expand Up @@ -2807,7 +2716,6 @@ ConstantReference IRGenModule::getAddrOfTypeMetadata(CanType concreteType,
llvm::Constant *IRGenModule::getAddrOfNominalTypeDescriptor(NominalTypeDecl *D,
ConstantInitFuture definition) {
assert(definition && "not defining nominal type descriptor?");
checkEligibleMetaType(D);
auto entity = LinkEntity::forNominalTypeDescriptor(D);
return getAddrOfLLVMVariable(entity, getPointerAlignment(),
definition,
Expand Down Expand Up @@ -3181,7 +3089,6 @@ IRGenModule::getResilienceExpansionForLayout(SILGlobalVariable *global) {
llvm::Constant *IRGenModule::
getAddrOfGenericWitnessTableCache(const NormalProtocolConformance *conf,
ForDefinition_t forDefinition) {
checkEligibleConf(conf);
auto entity = LinkEntity::forGenericProtocolWitnessTableCache(conf);
auto expectedTy = getGenericWitnessTableCacheTy();
return getAddrOfLLVMVariable(entity, getPointerAlignment(), forDefinition,
Expand All @@ -3191,7 +3098,6 @@ getAddrOfGenericWitnessTableCache(const NormalProtocolConformance *conf,
llvm::Function *
IRGenModule::getAddrOfGenericWitnessTableInstantiationFunction(
const NormalProtocolConformance *conf) {
checkEligibleConf(conf);
auto forDefinition = ForDefinition;

LinkEntity entity =
Expand Down Expand Up @@ -3238,8 +3144,6 @@ llvm::Function *
IRGenModule::getAddrOfWitnessTableAccessFunction(
const NormalProtocolConformance *conf,
ForDefinition_t forDefinition) {
checkEligibleConf(conf);

IRGen.addLazyWitnessTable(conf);

LinkEntity entity = LinkEntity::forProtocolWitnessTableAccessFunction(conf);
Expand Down Expand Up @@ -3268,7 +3172,6 @@ IRGenModule::getAddrOfWitnessTableLazyAccessFunction(
const NormalProtocolConformance *conf,
CanType conformingType,
ForDefinition_t forDefinition) {
checkEligibleConf(conf);
LinkEntity entity =
LinkEntity::forProtocolWitnessTableLazyAccessFunction(conf, conformingType);
llvm::Function *&entry = GlobalFuncs[entity];
Expand All @@ -3293,7 +3196,6 @@ IRGenModule::getAddrOfWitnessTableLazyCacheVariable(
CanType conformingType,
ForDefinition_t forDefinition) {
assert(!conformingType->hasArchetype());
checkEligibleConf(conf);
LinkEntity entity =
LinkEntity::forProtocolWitnessTableLazyCacheVariable(conf, conformingType);
return getAddrOfLLVMVariable(entity, getPointerAlignment(),
Expand All @@ -3310,7 +3212,6 @@ IRGenModule::getAddrOfWitnessTableLazyCacheVariable(
llvm::Constant*
IRGenModule::getAddrOfWitnessTable(const NormalProtocolConformance *conf,
ConstantInit definition) {
checkEligibleConf(conf);
IRGen.addLazyWitnessTable(conf);

auto entity = LinkEntity::forDirectProtocolWitnessTable(conf);
Expand All @@ -3322,7 +3223,6 @@ llvm::Function *
IRGenModule::getAddrOfAssociatedTypeMetadataAccessFunction(
const NormalProtocolConformance *conformance,
AssociatedTypeDecl *associate) {
checkEligibleConf(conformance);
auto forDefinition = ForDefinition;

LinkEntity entity =
Expand All @@ -3344,7 +3244,6 @@ IRGenModule::getAddrOfAssociatedTypeWitnessTableAccessFunction(
const NormalProtocolConformance *conformance,
CanType associatedType,
ProtocolDecl *associatedProtocol) {
checkEligibleConf(conformance);
auto forDefinition = ForDefinition;

LinkEntity entity =
Expand Down
3 changes: 0 additions & 3 deletions lib/IRGen/IRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ IRGenModule::IRGenModule(IRGenerator &irgen,
DataLayout(target->createDataLayout()), Triple(Context.LangOpts.Target),
TargetMachine(std::move(target)), silConv(irgen.SIL),
OutputFilename(OutputFilename),
#ifndef NDEBUG
EligibleConfs(getSILModule()),
#endif
TargetInfo(SwiftTargetInfo::get(*this)), DebugInfo(nullptr),
ModuleHash(nullptr), ObjCInterop(Context.LangOpts.EnableObjCInterop),
Types(*new TypeConverter(*this)) {
Expand Down
14 changes: 1 addition & 13 deletions lib/IRGen/IRGenModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
#include "swift/AST/Decl.h"
#include "swift/AST/Module.h"
#include "swift/SIL/SILFunction.h"
#include "swift/SIL/SILWitnessTable.h"
#include "swift/SIL/InstructionUtils.h"
#include "swift/Basic/LLVM.h"
#include "swift/Basic/ClusteredBitVector.h"
#include "swift/Basic/SuccessorMap.h"
Expand Down Expand Up @@ -396,14 +394,7 @@ class IRGenModule {
SILModuleConventions silConv;

llvm::SmallString<128> OutputFilename;

#ifndef NDEBUG
// Used for testing ConformanceCollector.
ConformanceCollector EligibleConfs;
SILInstruction *CurrentInst = nullptr;
SILWitnessTable *CurrentWitnessTable = nullptr;
#endif


/// Order dependency -- TargetInfo must be initialized after Opts.
const SwiftTargetInfo TargetInfo;
/// Holds lexical scope info, etc. Is a nullptr if we compile without -g.
Expand Down Expand Up @@ -1049,9 +1040,6 @@ private: \
DebugTypeInfo debugType,
SymbolReferenceKind refKind);

void checkEligibleConf(const ProtocolConformance *Conf);
void checkEligibleMetaType(NominalTypeDecl *NT);

void emitLazyPrivateDefinitions();
void addRuntimeResolvableType(CanType type);

Expand Down
9 changes: 1 addition & 8 deletions lib/IRGen/IRGenSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include "swift/SIL/SILModule.h"
#include "swift/SIL/SILType.h"
#include "swift/SIL/SILVisitor.h"
#include "swift/SIL/InstructionUtils.h"
#include "clang/CodeGen/CodeGenABITypes.h"

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

for (auto InsnIter = BB->begin(); InsnIter != BB->end(); ++InsnIter) {
auto &I = *InsnIter;
#ifndef NDEBUG
IGM.EligibleConfs.collect(&I);
IGM.CurrentInst = &I;
#endif
if (IGM.DebugInfo) {
// Set the debug info location for I, if applicable.
SILLocation ILoc = I.getLoc();
Expand Down Expand Up @@ -1647,10 +1644,6 @@ void IRGenSILFunction::visitSILBasicBlock(SILBasicBlock *BB) {
}
visit(&I);

#ifndef NDEBUG
IGM.EligibleConfs.clear();
IGM.CurrentInst = nullptr;
#endif
}

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