@@ -1565,8 +1565,11 @@ bool DeclContext::lookupQualified(Type type,
1565
1565
assert (decls.empty () && " additive lookup not supported" );
1566
1566
1567
1567
// Handle AnyObject lookup.
1568
- if (type->isAnyObject ())
1569
- return lookupAnyObject (member, options, decls);
1568
+ if (type->isAnyObject ()) {
1569
+ AnyObjectLookupRequest req (this , member, options);
1570
+ decls = evaluateOrDefault (getASTContext ().evaluator , req, {});
1571
+ return !decls.empty ();
1572
+ }
1570
1573
1571
1574
// Handle lookup in a module.
1572
1575
if (auto moduleTy = type->getAs <ModuleType>())
@@ -1798,31 +1801,32 @@ bool DeclContext::lookupQualified(ModuleDecl *module, DeclName member,
1798
1801
return !decls.empty ();
1799
1802
}
1800
1803
1801
- bool DeclContext::lookupAnyObject (DeclName member, NLOptions options,
1802
- SmallVectorImpl<ValueDecl *> &decls) const {
1804
+ llvm::Expected<QualifiedLookupResult>
1805
+ AnyObjectLookupRequest::evaluate (Evaluator &evaluator, const DeclContext *dc,
1806
+ DeclName member, NLOptions options) const {
1803
1807
using namespace namelookup ;
1804
- assert (decls. empty () && " additive lookup not supported " ) ;
1808
+ QualifiedLookupResult decls ;
1805
1809
1806
1810
// Configure lookup and dig out the tracker.
1807
1811
ReferencedNameTracker *tracker = nullptr ;
1808
1812
bool isLookupCascading;
1809
- configureLookup (this , options, tracker, isLookupCascading);
1813
+ configureLookup (dc , options, tracker, isLookupCascading);
1810
1814
1811
1815
// Record this lookup.
1812
1816
if (tracker)
1813
1817
tracker->addDynamicLookupName (member.getBaseName (), isLookupCascading);
1814
1818
1815
1819
// Type-only lookup won't find anything on AnyObject.
1816
1820
if (options & NL_OnlyTypes)
1817
- return false ;
1821
+ return decls ;
1818
1822
1819
- auto *stats = getASTContext ().Stats ;
1823
+ auto *stats = dc-> getASTContext ().Stats ;
1820
1824
if (stats)
1821
1825
stats->getFrontendCounters ().NumLookupQualifiedInAnyObject ++;
1822
1826
1823
1827
// Collect all of the visible declarations.
1824
1828
SmallVector<ValueDecl *, 4 > allDecls;
1825
- for (auto import : namelookup::getAllImports (this )) {
1829
+ for (auto import : namelookup::getAllImports (dc )) {
1826
1830
import .second ->lookupClassMember (import .first , member, allDecls);
1827
1831
}
1828
1832
@@ -1840,26 +1844,23 @@ bool DeclContext::lookupAnyObject(DeclName member, NLOptions options,
1840
1844
if (decl->getOverriddenDecl ())
1841
1845
continue ;
1842
1846
1843
- auto dc = decl->getDeclContext ();
1844
- auto nominal = dc->getSelfNominalTypeDecl ();
1845
- assert (nominal && " Couldn't find nominal type?" );
1846
- (void )nominal;
1847
+ assert (decl->getDeclContext ()->isTypeContext () &&
1848
+ " Couldn't find nominal type?" );
1847
1849
1848
1850
// If we didn't see this declaration before, and it's an acceptable
1849
1851
// result, add it to the list.
1850
1852
// declaration to the list.
1851
1853
if (knownDecls.insert (decl).second &&
1852
- isAcceptableLookupResult (this , options, decl,
1854
+ isAcceptableLookupResult (dc , options, decl,
1853
1855
/* onlyCompleteObjectInits=*/ false ))
1854
1856
decls.push_back (decl);
1855
1857
}
1856
1858
1857
- pruneLookupResultSet (this , options, decls);
1858
- if (auto *debugClient = this ->getParentModule ()->getDebugClient ()) {
1859
- debugClient->finishLookupInAnyObject (this , member, options, decls);
1859
+ pruneLookupResultSet (dc , options, decls);
1860
+ if (auto *debugClient = dc ->getParentModule ()->getDebugClient ()) {
1861
+ debugClient->finishLookupInAnyObject (dc , member, options, decls);
1860
1862
}
1861
- // We're done. Report success/failure.
1862
- return !decls.empty ();
1863
+ return decls;
1863
1864
}
1864
1865
1865
1866
void DeclContext::lookupAllObjCMethods (
@@ -2647,3 +2648,28 @@ void swift::simple_display(llvm::raw_ostream &out, NLKind kind) {
2647
2648
}
2648
2649
llvm_unreachable (" Unhandled case in switch" );
2649
2650
}
2651
+
2652
+ void swift::simple_display (llvm::raw_ostream &out, NLOptions options) {
2653
+ using Flag = std::pair<NLOptions, StringRef>;
2654
+ Flag possibleFlags[] = {
2655
+ #define FLAG (Name ) {Name, #Name},
2656
+ FLAG (NL_ProtocolMembers)
2657
+ FLAG (NL_RemoveNonVisible)
2658
+ FLAG (NL_RemoveOverridden)
2659
+ FLAG (NL_IgnoreAccessControl)
2660
+ FLAG (NL_KnownNonCascadingDependency)
2661
+ FLAG (NL_KnownCascadingDependency)
2662
+ FLAG (NL_OnlyTypes)
2663
+ FLAG (NL_IncludeAttributeImplements)
2664
+ #undef FLAG
2665
+ };
2666
+
2667
+ auto flagsToPrint = llvm::make_filter_range (
2668
+ possibleFlags, [&](Flag flag) { return options & flag.first ; });
2669
+
2670
+ out << " { " ;
2671
+ interleave (
2672
+ flagsToPrint, [&](Flag flag) { out << flag.second ; },
2673
+ [&] { out << " , " ; });
2674
+ out << " }" ;
2675
+ }
0 commit comments