@@ -4841,8 +4841,9 @@ namespace {
48414841
48424842 // While importing the DeclContext, we might have imported the decl
48434843 // itself.
4844- if (auto Known = Impl.importDeclCached (decl, getVersion ()))
4845- return Known;
4844+ auto Known = Impl.importDeclCached (decl, getVersion ());
4845+ if (Known.hasValue ())
4846+ return Known.getValue ();
48464847
48474848 ImportedName importedName;
48484849 std::tie (importedName, std::ignore) = importFullName (decl);
@@ -4926,8 +4927,11 @@ namespace {
49264927 }
49274928
49284929 private:
4929- static bool isAcceptableResult (Decl *fn,
4930- Optional<AccessorInfo> accessorInfo) {
4930+ static bool isAcceptableResultOrNull (Decl *fn,
4931+ Optional<AccessorInfo> accessorInfo) {
4932+ if (nullptr == fn)
4933+ return true ;
4934+
49314935 // We can't safely re-use the same declaration if it disagrees
49324936 // in accessor-ness.
49334937 auto accessor = dyn_cast<AccessorDecl>(fn);
@@ -5038,7 +5042,7 @@ namespace {
50385042 getVersion ()});
50395043 if (known != Impl.ImportedDecls .end ()) {
50405044 auto decl = known->second ;
5041- if (isAcceptableResult (decl, accessorInfo))
5045+ if (isAcceptableResultOrNull (decl, accessorInfo))
50425046 return decl;
50435047 }
50445048 }
@@ -5056,7 +5060,7 @@ namespace {
50565060 if (isActiveSwiftVersion ()) {
50575061 if (isMethodAlreadyImported (selector, importedName, isInstance, dc,
50585062 [&](AbstractFunctionDecl *fn) {
5059- return isAcceptableResult (fn, accessorInfo);
5063+ return isAcceptableResultOrNull (fn, accessorInfo);
50605064 })) {
50615065 return nullptr ;
50625066 }
@@ -5190,7 +5194,7 @@ namespace {
51905194 getVersion ()});
51915195 if (known != Impl.ImportedDecls .end ()) {
51925196 auto decl = known->second ;
5193- if (isAcceptableResult (decl, accessorInfo))
5197+ if (isAcceptableResultOrNull (decl, accessorInfo))
51945198 return decl;
51955199 }
51965200 }
@@ -5885,8 +5889,9 @@ namespace {
58855889
58865890 // While importing the DeclContext, we might have imported the decl
58875891 // itself.
5888- if (auto Known = Impl.importDeclCached (decl, getVersion ()))
5889- return Known;
5892+ auto Known = Impl.importDeclCached (decl, getVersion ());
5893+ if (Known.hasValue ())
5894+ return Known.getValue ();
58905895
58915896 return importObjCPropertyDecl (decl, dc);
58925897 }
@@ -8589,16 +8594,16 @@ void SwiftDeclConverter::importInheritedConstructors(
85898594 }
85908595}
85918596
8592- Decl *ClangImporter::Implementation::importDeclCached (
8597+ Optional< Decl *> ClangImporter::Implementation::importDeclCached (
85938598 const clang::NamedDecl *ClangDecl,
85948599 ImportNameVersion version,
85958600 bool UseCanonical) {
85968601 auto Known = ImportedDecls.find (
85978602 { UseCanonical? ClangDecl->getCanonicalDecl (): ClangDecl, version });
8598- if (Known ! = ImportedDecls.end ())
8599- return Known-> second ;
8603+ if (Known = = ImportedDecls.end ())
8604+ return None ;
86008605
8601- return nullptr ;
8606+ return Known-> second ;
86028607}
86038608
86048609// / Checks if we don't need to import the typedef itself. If the typedef
@@ -9451,11 +9456,12 @@ Decl *ClangImporter::Implementation::importDeclAndCacheImpl(
94519456
94529457 auto Canon = cast<clang::NamedDecl>(UseCanonicalDecl? ClangDecl->getCanonicalDecl (): ClangDecl);
94539458
9454- if (auto Known = importDeclCached (Canon, version, UseCanonicalDecl)) {
9459+ auto Known = importDeclCached (Canon, version, UseCanonicalDecl);
9460+ if (Known.hasValue ()) {
94559461 if (!SuperfluousTypedefsAreTransparent &&
94569462 SuperfluousTypedefs.count (Canon))
94579463 return nullptr ;
9458- return Known;
9464+ return Known. getValue () ;
94599465 }
94609466
94619467 bool TypedefIsSuperfluous = false ;
@@ -9464,8 +9470,10 @@ Decl *ClangImporter::Implementation::importDeclAndCacheImpl(
94649470 startedImportingEntity ();
94659471 Decl *Result = importDeclImpl (ClangDecl, version, TypedefIsSuperfluous,
94669472 HadForwardDeclaration);
9467- if (!Result)
9473+ if (!Result) {
9474+ ImportedDecls[{Canon, version}] = nullptr ;
94689475 return nullptr ;
9476+ }
94699477
94709478 if (TypedefIsSuperfluous) {
94719479 SuperfluousTypedefs.insert (Canon);
@@ -9633,8 +9641,9 @@ ClangImporter::Implementation::importDeclForDeclContext(
96339641
96349642 // There's a cycle. Is the declaration imported enough to break the cycle
96359643 // gracefully? If so, we'll have it in the decl cache.
9636- if (auto cached = importDeclCached (contextDecl, version, useCanonicalDecl))
9637- return cached;
9644+ auto cached = importDeclCached (contextDecl, version, useCanonicalDecl);
9645+ if (cached.hasValue ())
9646+ return cached.getValue ();
96389647
96399648 // Can't break it? Warn and return nullptr, which is at least better than
96409649 // stack overflow by recursion.
0 commit comments