Skip to content

Commit a8cc606

Browse files
committed
[Name lookup] Prevent recursion in typealias -> nominal type decl resolution.
1 parent b947a47 commit a8cc606

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/AST/NameLookup.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1966,7 +1966,8 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
19661966
ASTContext &ctx,
19671967
ArrayRef<TypeDecl *> typeDecls,
19681968
SmallVectorImpl<ModuleDecl *> &modulesFound,
1969-
bool &anyObject) {
1969+
bool &anyObject,
1970+
llvm::SmallPtrSetImpl<TypeAliasDecl *> &typealiases) {
19701971
TinyPtrVector<NominalTypeDecl *> nominalDecls;
19711972

19721973
for (auto typeDecl : typeDecls) {
@@ -1978,11 +1979,16 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
19781979

19791980
// Recursively resolve typealiases.
19801981
if (auto typealias = dyn_cast<TypeAliasDecl>(typeDecl)) {
1982+
// FIXME: Ad hoc recursion breaking, so we don't look through the
1983+
// same typealias multiple times.
1984+
if (!typealiases.insert(typealias).second)
1985+
continue;
1986+
19811987
auto underlyingTypeReferences
19821988
= evaluator(UnderlyingTypeDeclsReferencedRequest{typealias});
19831989
auto underlyingNominalReferences
19841990
= resolveTypeDeclsToNominal(evaluator, ctx, underlyingTypeReferences,
1985-
modulesFound, anyObject);
1991+
modulesFound, anyObject, typealiases);
19861992
nominalDecls.insert(nominalDecls.end(),
19871993
underlyingNominalReferences.begin(),
19881994
underlyingNominalReferences.end());
@@ -2024,6 +2030,17 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
20242030
return nominalDecls;
20252031
}
20262032

2033+
static TinyPtrVector<NominalTypeDecl *>
2034+
resolveTypeDeclsToNominal(Evaluator &evaluator,
2035+
ASTContext &ctx,
2036+
ArrayRef<TypeDecl *> typeDecls,
2037+
SmallVectorImpl<ModuleDecl *> &modulesFound,
2038+
bool &anyObject) {
2039+
llvm::SmallPtrSet<TypeAliasDecl *, 4> typealiases;
2040+
return resolveTypeDeclsToNominal(evaluator, ctx, typeDecls, modulesFound,
2041+
anyObject, typealiases);
2042+
}
2043+
20272044
/// Perform unqualified name lookup for types at the given location.
20282045
static DirectlyReferencedTypeDecls
20292046
directReferencesForUnqualifiedTypeLookup(ASTContext &ctx, DeclName name,

0 commit comments

Comments
 (0)