Skip to content

Commit f2f6388

Browse files
[NFC] Always use syntactic information in ExtendedNominalRequest.
Since we started saving the nominal in the .swiftmodule, changing the other call-sites in ClangImporter to save the value means that we can rely on the typeRepr being non-null except when the syntax tree was ill-formed.
1 parent 0dcb936 commit f2f6388

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

lib/AST/NameLookup.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,18 +2123,14 @@ SuperclassDeclRequest::evaluate(Evaluator &evaluator,
21232123
llvm::Expected<NominalTypeDecl *>
21242124
ExtendedNominalRequest::evaluate(Evaluator &evaluator,
21252125
ExtensionDecl *ext) const {
2126-
DirectlyReferencedTypeDecls referenced;
2127-
ASTContext &ctx = ext->getASTContext();
2126+
auto typeRepr = ext->getExtendedTypeRepr();
2127+
if (!typeRepr)
2128+
// We must've seen 'extension { ... }' during parsing.
2129+
return nullptr;
21282130

2129-
// Prefer syntactic information when we have it.
2130-
if (auto typeRepr = ext->getExtendedTypeRepr()) {
2131-
referenced = directReferencesForTypeRepr(evaluator, ctx, typeRepr, ext);
2132-
} else if (auto type = ext->getExtendedType()) {
2133-
// Fall back to semantic types.
2134-
// FIXME: In the long run, we shouldn't need this. Non-syntactic results
2135-
// should be cached.
2136-
referenced = directReferencesForType(type);
2137-
}
2131+
ASTContext &ctx = ext->getASTContext();
2132+
DirectlyReferencedTypeDecls referenced =
2133+
directReferencesForTypeRepr(evaluator, ctx, typeRepr, ext);
21382134

21392135
// Resolve those type declarations to nominal type declarations.
21402136
SmallVector<ModuleDecl *, 2> modulesFound;

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "swift/AST/GenericSignature.h"
3131
#include "swift/AST/Module.h"
3232
#include "swift/AST/NameLookup.h"
33+
#include "swift/AST/NameLookupRequests.h"
3334
#include "swift/AST/ParameterList.h"
3435
#include "swift/AST/Pattern.h"
3536
#include "swift/AST/PrettyStackTrace.h"
@@ -4546,10 +4547,10 @@ namespace {
45464547
Impl.SwiftContext, loc,
45474548
nullptr,
45484549
{ }, dc, nullptr, decl);
4549-
Impl.SwiftContext
4550-
.evaluator
4551-
.cacheOutput(ExtendedTypeRequest{result},
4552-
objcClass->getDeclaredType());
4550+
Impl.SwiftContext.evaluator.cacheOutput(ExtendedTypeRequest{result},
4551+
objcClass->getDeclaredType());
4552+
Impl.SwiftContext.evaluator.cacheOutput(ExtendedNominalRequest{result},
4553+
objcClass);
45534554

45544555
// Determine the type and generic args of the extension.
45554556
if (objcClass->getGenericParams()) {
@@ -8127,6 +8128,8 @@ ClangImporter::Implementation::importDeclContextOf(
81278128
getClangModuleForDecl(decl), nullptr);
81288129
SwiftContext.evaluator.cacheOutput(ExtendedTypeRequest{ext},
81298130
nominal->getDeclaredType());
8131+
SwiftContext.evaluator.cacheOutput(ExtendedNominalRequest{ext},
8132+
std::move(nominal));
81308133
ext->setValidationToChecked();
81318134
ext->setMemberLoader(this, reinterpret_cast<uintptr_t>(declSubmodule));
81328135

0 commit comments

Comments
 (0)