Skip to content

Commit 6a11410

Browse files
committed
GSB: Simplify EquivalenceClass::lookupNestedType()
We don't use the other concrete types, so we don't have to store them either.
1 parent 1d809b0 commit 6a11410

File tree

2 files changed

+14
-47
lines changed

2 files changed

+14
-47
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,9 @@ class GenericSignatureBuilder {
228228

229229
/// Lookup a nested type with the given name within this equivalence
230230
/// class.
231-
///
232-
/// \param otherConcreteTypes If non-null, will be filled in the all of the
233-
/// concrete types we found (other than the result) with the same name.
234231
TypeDecl *lookupNestedType(
235232
GenericSignatureBuilder &builder,
236-
Identifier name,
237-
SmallVectorImpl<TypeDecl *> *otherConcreteTypes = nullptr);
233+
Identifier name);
238234

239235
/// Retrieve the "anchor" type that canonically describes this equivalence
240236
/// class, for use in the canonical type.
@@ -268,7 +264,7 @@ class GenericSignatureBuilder {
268264
unsigned numConformancesPresent;
269265
CanType superclassPresent;
270266
CanType concreteTypePresent;
271-
llvm::TinyPtrVector<TypeDecl *> types;
267+
TypeDecl *type;
272268
};
273269

274270
/// Cached nested-type information, which contains the best declaration

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 12 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2020,36 +2020,16 @@ static void lookupConcreteNestedType(NominalTypeDecl *decl,
20202020
concreteDecls.push_back(cast<TypeDecl>(member));
20212021
}
20222022

2023-
static auto findBestConcreteNestedType(SmallVectorImpl<TypeDecl *> &concreteDecls) {
2024-
return std::min_element(concreteDecls.begin(), concreteDecls.end(),
2025-
[](TypeDecl *type1, TypeDecl *type2) {
2026-
return TypeDecl::compare(type1, type2) < 0;
2027-
});
2023+
static TypeDecl *findBestConcreteNestedType(SmallVectorImpl<TypeDecl *> &concreteDecls) {
2024+
return *std::min_element(concreteDecls.begin(), concreteDecls.end(),
2025+
[](TypeDecl *type1, TypeDecl *type2) {
2026+
return TypeDecl::compare(type1, type2) < 0;
2027+
});
20282028
}
20292029

20302030
TypeDecl *EquivalenceClass::lookupNestedType(
20312031
GenericSignatureBuilder &builder,
2032-
Identifier name,
2033-
SmallVectorImpl<TypeDecl *> *otherConcreteTypes) {
2034-
// Populates the result structures from the given cache entry.
2035-
auto populateResult = [&](const CachedNestedType &cache) -> TypeDecl * {
2036-
if (otherConcreteTypes)
2037-
otherConcreteTypes->clear();
2038-
2039-
// If there aren't any types in the cache, we're done.
2040-
if (cache.types.empty()) return nullptr;
2041-
2042-
// The first type in the cache is always the final result.
2043-
// Collect the rest in the concrete-declarations list, if needed.
2044-
if (otherConcreteTypes) {
2045-
for (auto type : ArrayRef<TypeDecl *>(cache.types).slice(1)) {
2046-
otherConcreteTypes->push_back(type);
2047-
}
2048-
}
2049-
2050-
return cache.types.front();
2051-
};
2052-
2032+
Identifier name) {
20532033
// If we have a cached value that is up-to-date, use that.
20542034
auto cached = nestedTypeNameCache.find(name);
20552035
if (cached != nestedTypeNameCache.end() &&
@@ -2059,7 +2039,7 @@ TypeDecl *EquivalenceClass::lookupNestedType(
20592039
(!concreteType ||
20602040
cached->second.concreteTypePresent == concreteType->getCanonicalType())) {
20612041
++NumNestedTypeCacheHits;
2062-
return populateResult(cached->second);
2042+
return cached->second.type;
20632043
}
20642044

20652045
// Cache miss; go compute the result.
@@ -2112,24 +2092,16 @@ TypeDecl *EquivalenceClass::lookupNestedType(
21122092
entry.concreteTypePresent =
21132093
concreteType ? concreteType->getCanonicalType() : CanType();
21142094
if (bestAssocType) {
2115-
entry.types.push_back(bestAssocType);
2116-
entry.types.insert(entry.types.end(),
2117-
concreteDecls.begin(), concreteDecls.end());
2095+
entry.type = bestAssocType;
21182096
assert(bestAssocType->getOverriddenDecls().empty() &&
21192097
"Lookup should never keep a non-anchor associated type");
21202098
} else if (!concreteDecls.empty()) {
21212099
// Find the best concrete type.
2122-
auto bestConcreteTypeIter = findBestConcreteNestedType(concreteDecls);
2123-
2124-
// Put the best concrete type first; the rest will follow.
2125-
entry.types.push_back(*bestConcreteTypeIter);
2126-
entry.types.insert(entry.types.end(),
2127-
concreteDecls.begin(), bestConcreteTypeIter);
2128-
entry.types.insert(entry.types.end(),
2129-
bestConcreteTypeIter + 1, concreteDecls.end());
2100+
entry.type = findBestConcreteNestedType(concreteDecls);
21302101
}
21312102

2132-
return populateResult((nestedTypeNameCache[name] = std::move(entry)));
2103+
nestedTypeNameCache[name] = entry;
2104+
return entry.type;
21332105
}
21342106

21352107
static Type getSugaredDependentType(Type type,
@@ -3829,8 +3801,7 @@ ResolvedType GenericSignatureBuilder::maybeResolveEquivalenceClass(
38293801
if (concreteDecls.empty())
38303802
return ResolvedType::forUnresolved(nullptr);
38313803

3832-
auto bestConcreteTypeIter = findBestConcreteNestedType(concreteDecls);
3833-
concreteDecl = *bestConcreteTypeIter;
3804+
concreteDecl = findBestConcreteNestedType(concreteDecls);
38343805
}
38353806
}
38363807

0 commit comments

Comments
 (0)