Skip to content

Remove used conformances list #25044

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
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
1 change: 0 additions & 1 deletion docs/CompilerPerformance.md
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,6 @@ $ cat /tmp/stats/*.json
"AST.NumSourceLinesPerSecond": 3,
"AST.NumLinkLibraries": 0,
"AST.NumLoadedModules": 4,
"AST.NumImportedExternalDefinitions": 0,
"AST.NumTotalClangImportedEntities": 0,
...
"time.swift.Parsing.wall": 5.038023e-03,
Expand Down
15 changes: 1 addition & 14 deletions include/swift/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,13 +255,6 @@ class ASTContext final {
#define IDENTIFIER_WITH_NAME(Name, IdStr) Identifier Id_##Name;
#include "swift/AST/KnownIdentifiers.def"

/// The list of external definitions imported by this context.
llvm::SetVector<Decl *> ExternalDefinitions;

/// FIXME: HACK HACK HACK
/// This state should be tracked somewhere else.
unsigned LastCheckedExternalDefinition = 0;

/// A consumer of type checker debug output.
std::unique_ptr<TypeCheckerDebugConsumer> TypeCheckerDebug;

Expand Down Expand Up @@ -580,14 +573,8 @@ class ASTContext final {
ForeignLanguage language,
const DeclContext *dc);

/// Add a declaration to a list of declarations that need to be emitted
/// as part of the current module or source file, but are otherwise not
/// nested within it.
void addExternalDecl(Decl *decl);

/// Add a declaration that was synthesized to a per-source file list if
/// if is part of a source file, or the external declarations list if
/// it is part of an imported type context.
/// if is part of a source file.
void addSynthesizedDecl(Decl *decl);

/// Add a cleanup function to be called when the ASTContext is deallocated.
Expand Down
8 changes: 0 additions & 8 deletions include/swift/AST/LazyResolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,6 @@ class LazyResolver {

/// Resolve an implicitly-generated member with the given name.
virtual void resolveImplicitMember(NominalTypeDecl *nominal, DeclName member) = 0;

/// Mark the given conformance as "used" from the given declaration context.
virtual void markConformanceUsed(ProtocolConformanceRef conformance,
DeclContext *dc) = 0;

/// Fill in the signature conformances of the given protocol conformance.
virtual void checkConformanceRequirements(
NormalProtocolConformance *conformance) = 0;
};

class LazyMemberLoader;
Expand Down
6 changes: 3 additions & 3 deletions include/swift/AST/ProtocolConformance.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/TinyPtrVector.h"
#include <utility>

namespace swift {
Expand Down Expand Up @@ -174,9 +175,8 @@ class alignas(1 << DeclAlignInBits) ProtocolConformance {
template<typename F>
bool forEachTypeWitness(LazyResolver *resolver, F f) const {
const ProtocolDecl *protocol = getProtocol();
for (auto req : protocol->getMembers()) {
auto assocTypeReq = dyn_cast<AssociatedTypeDecl>(req);
if (!assocTypeReq || req->isInvalid())
for (auto assocTypeReq : protocol->getAssociatedTypeMembers()) {
if (assocTypeReq->isInvalid())
continue;

// If we don't have and cannot resolve witnesses, skip it.
Expand Down
3 changes: 0 additions & 3 deletions include/swift/Basic/Statistics.def
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ FRONTEND_STATISTIC(AST, NumLinkLibraries)
/// Number of top-level modules loaded in the AST context.
FRONTEND_STATISTIC(AST, NumLoadedModules)

/// Number of external definitions imported into the AST context.
FRONTEND_STATISTIC(AST, NumImportedExternalDefinitions)

/// Number of Clang entities imported into the AST context.
FRONTEND_STATISTIC(AST, NumTotalClangImportedEntities)

Expand Down
8 changes: 3 additions & 5 deletions include/swift/IRGen/Linking.h
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,9 @@ class LinkEntity {
static AssociatedTypeDecl *
getAssociatedTypeByIndex(const ProtocolConformance *conformance,
unsigned index) {
for (auto requirement : conformance->getProtocol()->getMembers()) {
if (auto associate = dyn_cast<AssociatedTypeDecl>(requirement)) {
if (index == 0) return associate;
index--;
}
for (auto associate : conformance->getProtocol()->getAssociatedTypeMembers()) {
if (index == 0) return associate;
index--;
}
llvm_unreachable("didn't find associated type in protocol?");
}
Expand Down
12 changes: 5 additions & 7 deletions include/swift/SIL/SILWitnessVisitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,11 @@ template <class T> class SILWitnessVisitor : public ASTVisitor<T> {
}

// Add the associated types.
for (Decl *member : protocol->getMembers()) {
if (auto associatedType = dyn_cast<AssociatedTypeDecl>(member)) {
// If this is a new associated type (which does not override an
// existing associated type), add it.
if (associatedType->getOverriddenDecls().empty())
asDerived().addAssociatedType(AssociatedType(associatedType));
}
for (auto *associatedType : protocol->getAssociatedTypeMembers()) {
// If this is a new associated type (which does not override an
// existing associated type), add it.
if (associatedType->getOverriddenDecls().empty())
asDerived().addAssociatedType(AssociatedType(associatedType));
}

if (asDerived().shouldVisitRequirementSignatureOnly())
Expand Down
17 changes: 3 additions & 14 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1362,20 +1362,10 @@ bool ASTContext::hasArrayLiteralIntrinsics() const {
&& getDeallocateUninitializedArray();
}

void ASTContext::addExternalDecl(Decl *decl) {
ExternalDefinitions.insert(decl);
}

void ASTContext::addSynthesizedDecl(Decl *decl) {
auto *mod = cast<FileUnit>(decl->getDeclContext()->getModuleScopeContext());
if (mod->getKind() == FileUnitKind::ClangModule ||
mod->getKind() == FileUnitKind::DWARFModule ||
mod->getKind() == FileUnitKind::SerializedAST) {
ExternalDefinitions.insert(decl);
return;
}

cast<SourceFile>(mod)->SynthesizedDecls.push_back(decl);
auto *fileUnit = decl->getDeclContext()->getModuleScopeContext();
if (auto *sf = dyn_cast<SourceFile>(fileUnit))
sf->SynthesizedDecls.push_back(decl);
}

void ASTContext::addCleanup(std::function<void(void)> cleanup) {
Expand Down Expand Up @@ -2050,7 +2040,6 @@ ASTContext::takeDelayedConformanceDiags(NormalProtocolConformance *conformance){
size_t ASTContext::getTotalMemory() const {
size_t Size = sizeof(*this) +
// LoadedModules ?
// ExternalDefinitions ?
llvm::capacity_in_bytes(CanonicalGenericTypeParamTypeNames) +
// RemappedTypes ?
sizeof(getImpl()) +
Expand Down
158 changes: 76 additions & 82 deletions lib/AST/GenericSignatureBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3730,12 +3730,8 @@ GenericSignatureBuilder::lookupConformance(CanType dependentType,
// FIXME: When lookupConformance() starts respecting modules, we'll need
// to do some filtering here.
ModuleDecl *searchModule = conformedProtocol->getParentModule();
auto result = searchModule->lookupConformance(conformingReplacementType,
conformedProtocol);
if (result && getLazyResolver())
getLazyResolver()->markConformanceUsed(*result, searchModule);

return result;
return searchModule->lookupConformance(conformingReplacementType,
conformedProtocol);
}

LazyResolver *GenericSignatureBuilder::getLazyResolver() const {
Expand Down Expand Up @@ -4242,92 +4238,90 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
};

// Add requirements for each of the associated types.
for (auto Member : proto->getMembers()) {
if (auto assocTypeDecl = dyn_cast<AssociatedTypeDecl>(Member)) {
// Add requirements placed directly on this associated type.
Type assocType =
DependentMemberType::get(selfType.getDependentType(*this), assocTypeDecl);
if (!onlySameTypeConstraints) {
auto assocResult =
addInheritedRequirements(assocTypeDecl, assocType, source,
/*inferForModule=*/nullptr);
if (isErrorResult(assocResult))
return assocResult;
}

// Add requirements from this associated type's where clause.
RequirementRequest::visitRequirements(assocTypeDecl,
TypeResolutionStage::Structural,
[&](const Requirement &req, RequirementRepr *reqRepr) {
// If we're only looking at same-type constraints, skip everything else.
if (onlySameTypeConstraints &&
req.getKind() != RequirementKind::SameType)
return false;

auto innerSource = FloatingRequirementSource::viaProtocolRequirement(
source, proto, reqRepr, /*inferred=*/false);
addRequirement(req, reqRepr, innerSource, &protocolSubMap,
/*inferForModule=*/nullptr);
for (auto assocTypeDecl : proto->getAssociatedTypeMembers()) {
// Add requirements placed directly on this associated type.
Type assocType =
DependentMemberType::get(selfType.getDependentType(*this), assocTypeDecl);
if (!onlySameTypeConstraints) {
auto assocResult =
addInheritedRequirements(assocTypeDecl, assocType, source,
/*inferForModule=*/nullptr);
if (isErrorResult(assocResult))
return assocResult;
}

// Add requirements from this associated type's where clause.
RequirementRequest::visitRequirements(assocTypeDecl,
TypeResolutionStage::Structural,
[&](const Requirement &req, RequirementRepr *reqRepr) {
// If we're only looking at same-type constraints, skip everything else.
if (onlySameTypeConstraints &&
req.getKind() != RequirementKind::SameType)
return false;
});

// Check whether we inherited any types with the same name.
auto knownInherited =
inheritedTypeDecls.find(assocTypeDecl->getFullName());
if (knownInherited == inheritedTypeDecls.end()) continue;

bool shouldWarnAboutRedeclaration =
source->kind == RequirementSource::RequirementSignatureSelf &&
!assocTypeDecl->getAttrs().hasAttribute<NonOverrideAttr>() &&
!assocTypeDecl->getAttrs().hasAttribute<OverrideAttr>() &&
!assocTypeDecl->hasDefaultDefinitionType() &&
(!assocTypeDecl->getInherited().empty() ||
assocTypeDecl->getTrailingWhereClause() ||
getASTContext().LangOpts.WarnImplicitOverrides);
for (auto inheritedType : knownInherited->second) {
// If we have inherited associated type...
if (auto inheritedAssocTypeDecl =
dyn_cast<AssociatedTypeDecl>(inheritedType)) {
// Complain about the first redeclaration.
if (shouldWarnAboutRedeclaration) {
auto inheritedFromProto = inheritedAssocTypeDecl->getProtocol();
auto fixItWhere = getProtocolWhereLoc();
Diags.diagnose(assocTypeDecl,
diag::inherited_associated_type_redecl,
assocTypeDecl->getFullName(),
inheritedFromProto->getDeclaredInterfaceType())
.fixItInsertAfter(
fixItWhere.first,
getAssociatedTypeReqs(assocTypeDecl, fixItWhere.second))
.fixItRemove(assocTypeDecl->getSourceRange());

Diags.diagnose(inheritedAssocTypeDecl, diag::decl_declared_here,
inheritedAssocTypeDecl->getFullName());

shouldWarnAboutRedeclaration = false;
}

continue;
}
auto innerSource = FloatingRequirementSource::viaProtocolRequirement(
source, proto, reqRepr, /*inferred=*/false);
addRequirement(req, reqRepr, innerSource, &protocolSubMap,
/*inferForModule=*/nullptr);
return false;
});

// We inherited a type; this associated type will be identical
// to that typealias.
if (source->kind == RequirementSource::RequirementSignatureSelf) {
auto inheritedOwningDecl =
inheritedType->getDeclContext()->getSelfNominalTypeDecl();
// Check whether we inherited any types with the same name.
auto knownInherited =
inheritedTypeDecls.find(assocTypeDecl->getFullName());
if (knownInherited == inheritedTypeDecls.end()) continue;

bool shouldWarnAboutRedeclaration =
source->kind == RequirementSource::RequirementSignatureSelf &&
!assocTypeDecl->getAttrs().hasAttribute<NonOverrideAttr>() &&
!assocTypeDecl->getAttrs().hasAttribute<OverrideAttr>() &&
!assocTypeDecl->hasDefaultDefinitionType() &&
(!assocTypeDecl->getInherited().empty() ||
assocTypeDecl->getTrailingWhereClause() ||
getASTContext().LangOpts.WarnImplicitOverrides);
for (auto inheritedType : knownInherited->second) {
// If we have inherited associated type...
if (auto inheritedAssocTypeDecl =
dyn_cast<AssociatedTypeDecl>(inheritedType)) {
// Complain about the first redeclaration.
if (shouldWarnAboutRedeclaration) {
auto inheritedFromProto = inheritedAssocTypeDecl->getProtocol();
auto fixItWhere = getProtocolWhereLoc();
Diags.diagnose(assocTypeDecl,
diag::associated_type_override_typealias,
diag::inherited_associated_type_redecl,
assocTypeDecl->getFullName(),
inheritedOwningDecl->getDescriptiveKind(),
inheritedOwningDecl->getDeclaredInterfaceType());
inheritedFromProto->getDeclaredInterfaceType())
.fixItInsertAfter(
fixItWhere.first,
getAssociatedTypeReqs(assocTypeDecl, fixItWhere.second))
.fixItRemove(assocTypeDecl->getSourceRange());

Diags.diagnose(inheritedAssocTypeDecl, diag::decl_declared_here,
inheritedAssocTypeDecl->getFullName());

shouldWarnAboutRedeclaration = false;
}

addInferredSameTypeReq(assocTypeDecl, inheritedType);
continue;
}

inheritedTypeDecls.erase(knownInherited);
continue;
// We inherited a type; this associated type will be identical
// to that typealias.
if (source->kind == RequirementSource::RequirementSignatureSelf) {
auto inheritedOwningDecl =
inheritedType->getDeclContext()->getSelfNominalTypeDecl();
Diags.diagnose(assocTypeDecl,
diag::associated_type_override_typealias,
assocTypeDecl->getFullName(),
inheritedOwningDecl->getDescriptiveKind(),
inheritedOwningDecl->getDeclaredInterfaceType());
}

addInferredSameTypeReq(assocTypeDecl, inheritedType);
}

inheritedTypeDecls.erase(knownInherited);
continue;
}

// Check all remaining inherited type declarations to determine if
Expand Down
5 changes: 3 additions & 2 deletions lib/AST/ProtocolConformance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -904,8 +904,9 @@ NormalProtocolConformance::getAssociatedConformance(Type assocType,
// Fill in the signature conformances, if we haven't done so yet.
if (getSignatureConformances().empty()) {
assocType->getASTContext().getLazyResolver()
->checkConformanceRequirements(
const_cast<NormalProtocolConformance *>(this));
->resolveTypeWitness(
const_cast<NormalProtocolConformance *>(this),
nullptr);
}

assert(!getSignatureConformances().empty() &&
Expand Down
11 changes: 0 additions & 11 deletions lib/AST/SubstitutionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,17 +416,6 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
// to use that.
if (normal->getState() == ProtocolConformanceState::CheckingTypeWitnesses)
return None;

auto lazyResolver = type->getASTContext().getLazyResolver();
if (lazyResolver == nullptr)
return None;

lazyResolver->resolveTypeWitness(normal, nullptr);

// Error case: the conformance is broken, so we cannot handle this
// substitution.
if (normal->getSignatureConformances().empty())
return None;
}

// Get the associated conformance.
Expand Down
8 changes: 3 additions & 5 deletions lib/AST/Type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2693,11 +2693,9 @@ void ArchetypeType::populateNestedTypes() const {
llvm::SmallPtrSet<Identifier, 4> knownNestedTypes;
ProtocolType::visitAllProtocols(getConformsTo(),
[&](ProtocolDecl *proto) -> bool {
for (auto member : proto->getMembers()) {
if (auto assocType = dyn_cast<AssociatedTypeDecl>(member)) {
if (knownNestedTypes.insert(assocType->getName()).second)
nestedTypes.push_back({ assocType->getName(), Type() });
}
for (auto assocType : proto->getAssociatedTypeMembers()) {
if (knownNestedTypes.insert(assocType->getName()).second)
nestedTypes.push_back({ assocType->getName(), Type() });
}

return false;
Expand Down
Loading