Skip to content

Commit 7ce150b

Browse files
authored
Merge pull request #25044 from slavapestov/remove-used-conformances-list
Remove used conformances list
2 parents 1024599 + c9ea70e commit 7ce150b

35 files changed

+342
-504
lines changed

docs/CompilerPerformance.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,6 @@ $ cat /tmp/stats/*.json
717717
"AST.NumSourceLinesPerSecond": 3,
718718
"AST.NumLinkLibraries": 0,
719719
"AST.NumLoadedModules": 4,
720-
"AST.NumImportedExternalDefinitions": 0,
721720
"AST.NumTotalClangImportedEntities": 0,
722721
...
723722
"time.swift.Parsing.wall": 5.038023e-03,

include/swift/AST/ASTContext.h

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -255,13 +255,6 @@ class ASTContext final {
255255
#define IDENTIFIER_WITH_NAME(Name, IdStr) Identifier Id_##Name;
256256
#include "swift/AST/KnownIdentifiers.def"
257257

258-
/// The list of external definitions imported by this context.
259-
llvm::SetVector<Decl *> ExternalDefinitions;
260-
261-
/// FIXME: HACK HACK HACK
262-
/// This state should be tracked somewhere else.
263-
unsigned LastCheckedExternalDefinition = 0;
264-
265258
/// A consumer of type checker debug output.
266259
std::unique_ptr<TypeCheckerDebugConsumer> TypeCheckerDebug;
267260

@@ -580,14 +573,8 @@ class ASTContext final {
580573
ForeignLanguage language,
581574
const DeclContext *dc);
582575

583-
/// Add a declaration to a list of declarations that need to be emitted
584-
/// as part of the current module or source file, but are otherwise not
585-
/// nested within it.
586-
void addExternalDecl(Decl *decl);
587-
588576
/// Add a declaration that was synthesized to a per-source file list if
589-
/// if is part of a source file, or the external declarations list if
590-
/// it is part of an imported type context.
577+
/// if is part of a source file.
591578
void addSynthesizedDecl(Decl *decl);
592579

593580
/// Add a cleanup function to be called when the ASTContext is deallocated.

include/swift/AST/LazyResolver.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,6 @@ class LazyResolver {
7474

7575
/// Resolve an implicitly-generated member with the given name.
7676
virtual void resolveImplicitMember(NominalTypeDecl *nominal, DeclName member) = 0;
77-
78-
/// Mark the given conformance as "used" from the given declaration context.
79-
virtual void markConformanceUsed(ProtocolConformanceRef conformance,
80-
DeclContext *dc) = 0;
81-
82-
/// Fill in the signature conformances of the given protocol conformance.
83-
virtual void checkConformanceRequirements(
84-
NormalProtocolConformance *conformance) = 0;
8577
};
8678

8779
class LazyMemberLoader;

include/swift/AST/ProtocolConformance.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "llvm/ADT/DenseMap.h"
2828
#include "llvm/ADT/FoldingSet.h"
2929
#include "llvm/ADT/SmallPtrSet.h"
30+
#include "llvm/ADT/TinyPtrVector.h"
3031
#include <utility>
3132

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

182182
// If we don't have and cannot resolve witnesses, skip it.

include/swift/Basic/Statistics.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,6 @@ FRONTEND_STATISTIC(AST, NumLinkLibraries)
105105
/// Number of top-level modules loaded in the AST context.
106106
FRONTEND_STATISTIC(AST, NumLoadedModules)
107107

108-
/// Number of external definitions imported into the AST context.
109-
FRONTEND_STATISTIC(AST, NumImportedExternalDefinitions)
110-
111108
/// Number of Clang entities imported into the AST context.
112109
FRONTEND_STATISTIC(AST, NumTotalClangImportedEntities)
113110

include/swift/IRGen/Linking.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,11 +480,9 @@ class LinkEntity {
480480
static AssociatedTypeDecl *
481481
getAssociatedTypeByIndex(const ProtocolConformance *conformance,
482482
unsigned index) {
483-
for (auto requirement : conformance->getProtocol()->getMembers()) {
484-
if (auto associate = dyn_cast<AssociatedTypeDecl>(requirement)) {
485-
if (index == 0) return associate;
486-
index--;
487-
}
483+
for (auto associate : conformance->getProtocol()->getAssociatedTypeMembers()) {
484+
if (index == 0) return associate;
485+
index--;
488486
}
489487
llvm_unreachable("didn't find associated type in protocol?");
490488
}

include/swift/SIL/SILWitnessVisitor.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,11 @@ template <class T> class SILWitnessVisitor : public ASTVisitor<T> {
9191
}
9292

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

103101
if (asDerived().shouldVisitRequirementSignatureOnly())

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,20 +1362,10 @@ bool ASTContext::hasArrayLiteralIntrinsics() const {
13621362
&& getDeallocateUninitializedArray();
13631363
}
13641364

1365-
void ASTContext::addExternalDecl(Decl *decl) {
1366-
ExternalDefinitions.insert(decl);
1367-
}
1368-
13691365
void ASTContext::addSynthesizedDecl(Decl *decl) {
1370-
auto *mod = cast<FileUnit>(decl->getDeclContext()->getModuleScopeContext());
1371-
if (mod->getKind() == FileUnitKind::ClangModule ||
1372-
mod->getKind() == FileUnitKind::DWARFModule ||
1373-
mod->getKind() == FileUnitKind::SerializedAST) {
1374-
ExternalDefinitions.insert(decl);
1375-
return;
1376-
}
1377-
1378-
cast<SourceFile>(mod)->SynthesizedDecls.push_back(decl);
1366+
auto *fileUnit = decl->getDeclContext()->getModuleScopeContext();
1367+
if (auto *sf = dyn_cast<SourceFile>(fileUnit))
1368+
sf->SynthesizedDecls.push_back(decl);
13791369
}
13801370

13811371
void ASTContext::addCleanup(std::function<void(void)> cleanup) {
@@ -2050,7 +2040,6 @@ ASTContext::takeDelayedConformanceDiags(NormalProtocolConformance *conformance){
20502040
size_t ASTContext::getTotalMemory() const {
20512041
size_t Size = sizeof(*this) +
20522042
// LoadedModules ?
2053-
// ExternalDefinitions ?
20542043
llvm::capacity_in_bytes(CanonicalGenericTypeParamTypeNames) +
20552044
// RemappedTypes ?
20562045
sizeof(getImpl()) +

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 76 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,12 +3730,8 @@ GenericSignatureBuilder::lookupConformance(CanType dependentType,
37303730
// FIXME: When lookupConformance() starts respecting modules, we'll need
37313731
// to do some filtering here.
37323732
ModuleDecl *searchModule = conformedProtocol->getParentModule();
3733-
auto result = searchModule->lookupConformance(conformingReplacementType,
3734-
conformedProtocol);
3735-
if (result && getLazyResolver())
3736-
getLazyResolver()->markConformanceUsed(*result, searchModule);
3737-
3738-
return result;
3733+
return searchModule->lookupConformance(conformingReplacementType,
3734+
conformedProtocol);
37393735
}
37403736

37413737
LazyResolver *GenericSignatureBuilder::getLazyResolver() const {
@@ -4242,92 +4238,90 @@ ConstraintResult GenericSignatureBuilder::expandConformanceRequirement(
42424238
};
42434239

42444240
// Add requirements for each of the associated types.
4245-
for (auto Member : proto->getMembers()) {
4246-
if (auto assocTypeDecl = dyn_cast<AssociatedTypeDecl>(Member)) {
4247-
// Add requirements placed directly on this associated type.
4248-
Type assocType =
4249-
DependentMemberType::get(selfType.getDependentType(*this), assocTypeDecl);
4250-
if (!onlySameTypeConstraints) {
4251-
auto assocResult =
4252-
addInheritedRequirements(assocTypeDecl, assocType, source,
4253-
/*inferForModule=*/nullptr);
4254-
if (isErrorResult(assocResult))
4255-
return assocResult;
4256-
}
4257-
4258-
// Add requirements from this associated type's where clause.
4259-
RequirementRequest::visitRequirements(assocTypeDecl,
4260-
TypeResolutionStage::Structural,
4261-
[&](const Requirement &req, RequirementRepr *reqRepr) {
4262-
// If we're only looking at same-type constraints, skip everything else.
4263-
if (onlySameTypeConstraints &&
4264-
req.getKind() != RequirementKind::SameType)
4265-
return false;
4266-
4267-
auto innerSource = FloatingRequirementSource::viaProtocolRequirement(
4268-
source, proto, reqRepr, /*inferred=*/false);
4269-
addRequirement(req, reqRepr, innerSource, &protocolSubMap,
4270-
/*inferForModule=*/nullptr);
4241+
for (auto assocTypeDecl : proto->getAssociatedTypeMembers()) {
4242+
// Add requirements placed directly on this associated type.
4243+
Type assocType =
4244+
DependentMemberType::get(selfType.getDependentType(*this), assocTypeDecl);
4245+
if (!onlySameTypeConstraints) {
4246+
auto assocResult =
4247+
addInheritedRequirements(assocTypeDecl, assocType, source,
4248+
/*inferForModule=*/nullptr);
4249+
if (isErrorResult(assocResult))
4250+
return assocResult;
4251+
}
4252+
4253+
// Add requirements from this associated type's where clause.
4254+
RequirementRequest::visitRequirements(assocTypeDecl,
4255+
TypeResolutionStage::Structural,
4256+
[&](const Requirement &req, RequirementRepr *reqRepr) {
4257+
// If we're only looking at same-type constraints, skip everything else.
4258+
if (onlySameTypeConstraints &&
4259+
req.getKind() != RequirementKind::SameType)
42714260
return false;
4272-
});
42734261

4274-
// Check whether we inherited any types with the same name.
4275-
auto knownInherited =
4276-
inheritedTypeDecls.find(assocTypeDecl->getFullName());
4277-
if (knownInherited == inheritedTypeDecls.end()) continue;
4278-
4279-
bool shouldWarnAboutRedeclaration =
4280-
source->kind == RequirementSource::RequirementSignatureSelf &&
4281-
!assocTypeDecl->getAttrs().hasAttribute<NonOverrideAttr>() &&
4282-
!assocTypeDecl->getAttrs().hasAttribute<OverrideAttr>() &&
4283-
!assocTypeDecl->hasDefaultDefinitionType() &&
4284-
(!assocTypeDecl->getInherited().empty() ||
4285-
assocTypeDecl->getTrailingWhereClause() ||
4286-
getASTContext().LangOpts.WarnImplicitOverrides);
4287-
for (auto inheritedType : knownInherited->second) {
4288-
// If we have inherited associated type...
4289-
if (auto inheritedAssocTypeDecl =
4290-
dyn_cast<AssociatedTypeDecl>(inheritedType)) {
4291-
// Complain about the first redeclaration.
4292-
if (shouldWarnAboutRedeclaration) {
4293-
auto inheritedFromProto = inheritedAssocTypeDecl->getProtocol();
4294-
auto fixItWhere = getProtocolWhereLoc();
4295-
Diags.diagnose(assocTypeDecl,
4296-
diag::inherited_associated_type_redecl,
4297-
assocTypeDecl->getFullName(),
4298-
inheritedFromProto->getDeclaredInterfaceType())
4299-
.fixItInsertAfter(
4300-
fixItWhere.first,
4301-
getAssociatedTypeReqs(assocTypeDecl, fixItWhere.second))
4302-
.fixItRemove(assocTypeDecl->getSourceRange());
4303-
4304-
Diags.diagnose(inheritedAssocTypeDecl, diag::decl_declared_here,
4305-
inheritedAssocTypeDecl->getFullName());
4306-
4307-
shouldWarnAboutRedeclaration = false;
4308-
}
4309-
4310-
continue;
4311-
}
4262+
auto innerSource = FloatingRequirementSource::viaProtocolRequirement(
4263+
source, proto, reqRepr, /*inferred=*/false);
4264+
addRequirement(req, reqRepr, innerSource, &protocolSubMap,
4265+
/*inferForModule=*/nullptr);
4266+
return false;
4267+
});
43124268

4313-
// We inherited a type; this associated type will be identical
4314-
// to that typealias.
4315-
if (source->kind == RequirementSource::RequirementSignatureSelf) {
4316-
auto inheritedOwningDecl =
4317-
inheritedType->getDeclContext()->getSelfNominalTypeDecl();
4269+
// Check whether we inherited any types with the same name.
4270+
auto knownInherited =
4271+
inheritedTypeDecls.find(assocTypeDecl->getFullName());
4272+
if (knownInherited == inheritedTypeDecls.end()) continue;
4273+
4274+
bool shouldWarnAboutRedeclaration =
4275+
source->kind == RequirementSource::RequirementSignatureSelf &&
4276+
!assocTypeDecl->getAttrs().hasAttribute<NonOverrideAttr>() &&
4277+
!assocTypeDecl->getAttrs().hasAttribute<OverrideAttr>() &&
4278+
!assocTypeDecl->hasDefaultDefinitionType() &&
4279+
(!assocTypeDecl->getInherited().empty() ||
4280+
assocTypeDecl->getTrailingWhereClause() ||
4281+
getASTContext().LangOpts.WarnImplicitOverrides);
4282+
for (auto inheritedType : knownInherited->second) {
4283+
// If we have inherited associated type...
4284+
if (auto inheritedAssocTypeDecl =
4285+
dyn_cast<AssociatedTypeDecl>(inheritedType)) {
4286+
// Complain about the first redeclaration.
4287+
if (shouldWarnAboutRedeclaration) {
4288+
auto inheritedFromProto = inheritedAssocTypeDecl->getProtocol();
4289+
auto fixItWhere = getProtocolWhereLoc();
43184290
Diags.diagnose(assocTypeDecl,
4319-
diag::associated_type_override_typealias,
4291+
diag::inherited_associated_type_redecl,
43204292
assocTypeDecl->getFullName(),
4321-
inheritedOwningDecl->getDescriptiveKind(),
4322-
inheritedOwningDecl->getDeclaredInterfaceType());
4293+
inheritedFromProto->getDeclaredInterfaceType())
4294+
.fixItInsertAfter(
4295+
fixItWhere.first,
4296+
getAssociatedTypeReqs(assocTypeDecl, fixItWhere.second))
4297+
.fixItRemove(assocTypeDecl->getSourceRange());
4298+
4299+
Diags.diagnose(inheritedAssocTypeDecl, diag::decl_declared_here,
4300+
inheritedAssocTypeDecl->getFullName());
4301+
4302+
shouldWarnAboutRedeclaration = false;
43234303
}
43244304

4325-
addInferredSameTypeReq(assocTypeDecl, inheritedType);
4305+
continue;
43264306
}
43274307

4328-
inheritedTypeDecls.erase(knownInherited);
4329-
continue;
4308+
// We inherited a type; this associated type will be identical
4309+
// to that typealias.
4310+
if (source->kind == RequirementSource::RequirementSignatureSelf) {
4311+
auto inheritedOwningDecl =
4312+
inheritedType->getDeclContext()->getSelfNominalTypeDecl();
4313+
Diags.diagnose(assocTypeDecl,
4314+
diag::associated_type_override_typealias,
4315+
assocTypeDecl->getFullName(),
4316+
inheritedOwningDecl->getDescriptiveKind(),
4317+
inheritedOwningDecl->getDeclaredInterfaceType());
4318+
}
4319+
4320+
addInferredSameTypeReq(assocTypeDecl, inheritedType);
43304321
}
4322+
4323+
inheritedTypeDecls.erase(knownInherited);
4324+
continue;
43314325
}
43324326

43334327
// Check all remaining inherited type declarations to determine if

lib/AST/ProtocolConformance.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -904,8 +904,9 @@ NormalProtocolConformance::getAssociatedConformance(Type assocType,
904904
// Fill in the signature conformances, if we haven't done so yet.
905905
if (getSignatureConformances().empty()) {
906906
assocType->getASTContext().getLazyResolver()
907-
->checkConformanceRequirements(
908-
const_cast<NormalProtocolConformance *>(this));
907+
->resolveTypeWitness(
908+
const_cast<NormalProtocolConformance *>(this),
909+
nullptr);
909910
}
910911

911912
assert(!getSignatureConformances().empty() &&

lib/AST/SubstitutionMap.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -416,17 +416,6 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
416416
// to use that.
417417
if (normal->getState() == ProtocolConformanceState::CheckingTypeWitnesses)
418418
return None;
419-
420-
auto lazyResolver = type->getASTContext().getLazyResolver();
421-
if (lazyResolver == nullptr)
422-
return None;
423-
424-
lazyResolver->resolveTypeWitness(normal, nullptr);
425-
426-
// Error case: the conformance is broken, so we cannot handle this
427-
// substitution.
428-
if (normal->getSignatureConformances().empty())
429-
return None;
430419
}
431420

432421
// Get the associated conformance.

lib/AST/Type.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2693,11 +2693,9 @@ void ArchetypeType::populateNestedTypes() const {
26932693
llvm::SmallPtrSet<Identifier, 4> knownNestedTypes;
26942694
ProtocolType::visitAllProtocols(getConformsTo(),
26952695
[&](ProtocolDecl *proto) -> bool {
2696-
for (auto member : proto->getMembers()) {
2697-
if (auto assocType = dyn_cast<AssociatedTypeDecl>(member)) {
2698-
if (knownNestedTypes.insert(assocType->getName()).second)
2699-
nestedTypes.push_back({ assocType->getName(), Type() });
2700-
}
2696+
for (auto assocType : proto->getAssociatedTypeMembers()) {
2697+
if (knownNestedTypes.insert(assocType->getName()).second)
2698+
nestedTypes.push_back({ assocType->getName(), Type() });
27012699
}
27022700

27032701
return false;

0 commit comments

Comments
 (0)