Skip to content

Commit 7909d83

Browse files
committed
AST: Refactor directReferencesForTypeRepr() to track inverses
1 parent 6c0ca54 commit 7909d83

File tree

12 files changed

+179
-134
lines changed

12 files changed

+179
-134
lines changed

include/swift/AST/NameLookup.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ struct InheritedNominalEntry : Located<NominalTypeDecl *> {
603603
void getDirectlyInheritedNominalTypeDecls(
604604
llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *> decl,
605605
unsigned i, llvm::SmallVectorImpl<InheritedNominalEntry> &result,
606-
bool &anyObject);
606+
InvertibleProtocolSet &inverses, bool &anyObject);
607607

608608
/// Retrieve the set of nominal type declarations that are directly
609609
/// "inherited" by the given declaration, looking through typealiases
@@ -612,7 +612,7 @@ void getDirectlyInheritedNominalTypeDecls(
612612
/// If we come across the AnyObject type, set \c anyObject true.
613613
SmallVector<InheritedNominalEntry, 4> getDirectlyInheritedNominalTypeDecls(
614614
llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *> decl,
615-
bool &anyObject);
615+
InvertibleProtocolSet &inverses, bool &anyObject);
616616

617617
/// Retrieve the set of nominal type declarations that appear as the
618618
/// constraint type of any "Self" constraints in the where clause of the

include/swift/AST/NameLookupRequests.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ void simple_display(
5858

5959
/// Describes a set of type declarations that are "direct" referenced by
6060
/// a particular type in the AST.
61-
using DirectlyReferencedTypeDecls = llvm::TinyPtrVector<TypeDecl *>;
61+
using DirectlyReferencedTypeDecls = std::pair<llvm::TinyPtrVector<TypeDecl *>,
62+
InvertibleProtocolSet>;
6263

6364
/// Request the set of declarations directly referenced by the an "inherited"
6465
/// type of a type or extension declaration.
@@ -270,6 +271,7 @@ class ExtendedNominalRequest
270271

271272
struct SelfBounds {
272273
llvm::TinyPtrVector<NominalTypeDecl *> decls;
274+
InvertibleProtocolSet inverses;
273275
bool anyObject = false;
274276
};
275277

lib/AST/AccessRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ DefaultAndMaxAccessLevelRequest::evaluate(Evaluator &evaluator,
248248

249249
// Try to scope the extension's access to the least public type mentioned
250250
// in its where clause.
251-
for (auto *typeDecl : typeDecls) {
251+
for (auto *typeDecl : typeDecls.first) {
252252
if (isa<TypeAliasDecl>(typeDecl) || isa<NominalTypeDecl>(typeDecl)) {
253253
auto scope = typeDecl->getFormalAccessScope(ED->getDeclContext());
254254
maxScope = maxScope->intersectWith(scope);

lib/AST/ConformanceLookupTable.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,10 @@ void ConformanceLookupTable::forEachInStage(ConformanceStage stage,
209209
}
210210
} else if (next->getParentSourceFile() ||
211211
next->getParentModule()->isBuiltinModule()) {
212+
InvertibleProtocolSet inverses;
212213
bool anyObject = false;
213214
for (const auto &found :
214-
getDirectlyInheritedNominalTypeDecls(next, anyObject)) {
215+
getDirectlyInheritedNominalTypeDecls(next, inverses, anyObject)) {
215216
if (auto proto = dyn_cast<ProtocolDecl>(found.Item))
216217
protocols.push_back(
217218
{proto, found.Loc, found.uncheckedLoc, found.preconcurrencyLoc});
@@ -497,9 +498,10 @@ void ConformanceLookupTable::addInheritedProtocols(
497498
llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *> decl,
498499
ConformanceSource source) {
499500
// Find all of the protocols in the inheritance list.
501+
InvertibleProtocolSet inverses;
500502
bool anyObject = false;
501503
for (const auto &found :
502-
getDirectlyInheritedNominalTypeDecls(decl, anyObject)) {
504+
getDirectlyInheritedNominalTypeDecls(decl, inverses, anyObject)) {
503505
if (auto proto = dyn_cast<ProtocolDecl>(found.Item)) {
504506
addProtocol(proto, found.Loc,
505507
source.withUncheckedLoc(found.uncheckedLoc)

0 commit comments

Comments
 (0)