@@ -4841,8 +4841,9 @@ namespace {
4841
4841
4842
4842
// While importing the DeclContext, we might have imported the decl
4843
4843
// 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 ();
4846
4847
4847
4848
ImportedName importedName;
4848
4849
std::tie (importedName, std::ignore) = importFullName (decl);
@@ -4926,8 +4927,11 @@ namespace {
4926
4927
}
4927
4928
4928
4929
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
+
4931
4935
// We can't safely re-use the same declaration if it disagrees
4932
4936
// in accessor-ness.
4933
4937
auto accessor = dyn_cast<AccessorDecl>(fn);
@@ -5038,7 +5042,7 @@ namespace {
5038
5042
getVersion ()});
5039
5043
if (known != Impl.ImportedDecls .end ()) {
5040
5044
auto decl = known->second ;
5041
- if (isAcceptableResult (decl, accessorInfo))
5045
+ if (isAcceptableResultOrNull (decl, accessorInfo))
5042
5046
return decl;
5043
5047
}
5044
5048
}
@@ -5056,7 +5060,7 @@ namespace {
5056
5060
if (isActiveSwiftVersion ()) {
5057
5061
if (isMethodAlreadyImported (selector, importedName, isInstance, dc,
5058
5062
[&](AbstractFunctionDecl *fn) {
5059
- return isAcceptableResult (fn, accessorInfo);
5063
+ return isAcceptableResultOrNull (fn, accessorInfo);
5060
5064
})) {
5061
5065
return nullptr ;
5062
5066
}
@@ -5190,7 +5194,7 @@ namespace {
5190
5194
getVersion ()});
5191
5195
if (known != Impl.ImportedDecls .end ()) {
5192
5196
auto decl = known->second ;
5193
- if (isAcceptableResult (decl, accessorInfo))
5197
+ if (isAcceptableResultOrNull (decl, accessorInfo))
5194
5198
return decl;
5195
5199
}
5196
5200
}
@@ -5885,8 +5889,9 @@ namespace {
5885
5889
5886
5890
// While importing the DeclContext, we might have imported the decl
5887
5891
// 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 ();
5890
5895
5891
5896
return importObjCPropertyDecl (decl, dc);
5892
5897
}
@@ -8589,16 +8594,16 @@ void SwiftDeclConverter::importInheritedConstructors(
8589
8594
}
8590
8595
}
8591
8596
8592
- Decl *ClangImporter::Implementation::importDeclCached (
8597
+ Optional< Decl *> ClangImporter::Implementation::importDeclCached (
8593
8598
const clang::NamedDecl *ClangDecl,
8594
8599
ImportNameVersion version,
8595
8600
bool UseCanonical) {
8596
8601
auto Known = ImportedDecls.find (
8597
8602
{ UseCanonical? ClangDecl->getCanonicalDecl (): ClangDecl, version });
8598
- if (Known ! = ImportedDecls.end ())
8599
- return Known-> second ;
8603
+ if (Known = = ImportedDecls.end ())
8604
+ return None ;
8600
8605
8601
- return nullptr ;
8606
+ return Known-> second ;
8602
8607
}
8603
8608
8604
8609
// / Checks if we don't need to import the typedef itself. If the typedef
@@ -9451,11 +9456,12 @@ Decl *ClangImporter::Implementation::importDeclAndCacheImpl(
9451
9456
9452
9457
auto Canon = cast<clang::NamedDecl>(UseCanonicalDecl? ClangDecl->getCanonicalDecl (): ClangDecl);
9453
9458
9454
- if (auto Known = importDeclCached (Canon, version, UseCanonicalDecl)) {
9459
+ auto Known = importDeclCached (Canon, version, UseCanonicalDecl);
9460
+ if (Known.hasValue ()) {
9455
9461
if (!SuperfluousTypedefsAreTransparent &&
9456
9462
SuperfluousTypedefs.count (Canon))
9457
9463
return nullptr ;
9458
- return Known;
9464
+ return Known. getValue () ;
9459
9465
}
9460
9466
9461
9467
bool TypedefIsSuperfluous = false ;
@@ -9464,8 +9470,10 @@ Decl *ClangImporter::Implementation::importDeclAndCacheImpl(
9464
9470
startedImportingEntity ();
9465
9471
Decl *Result = importDeclImpl (ClangDecl, version, TypedefIsSuperfluous,
9466
9472
HadForwardDeclaration);
9467
- if (!Result)
9473
+ if (!Result) {
9474
+ ImportedDecls[{Canon, version}] = nullptr ;
9468
9475
return nullptr ;
9476
+ }
9469
9477
9470
9478
if (TypedefIsSuperfluous) {
9471
9479
SuperfluousTypedefs.insert (Canon);
@@ -9633,8 +9641,9 @@ ClangImporter::Implementation::importDeclForDeclContext(
9633
9641
9634
9642
// There's a cycle. Is the declaration imported enough to break the cycle
9635
9643
// 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 ();
9638
9647
9639
9648
// Can't break it? Warn and return nullptr, which is at least better than
9640
9649
// stack overflow by recursion.
0 commit comments