@@ -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,28 @@ 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 ;
1818
-
1819
- auto *stats = getASTContext ().Stats ;
1820
- if (stats)
1821
- stats->getFrontendCounters ().NumLookupQualifiedInAnyObject ++;
1821
+ return decls;
1822
1822
1823
1823
// Collect all of the visible declarations.
1824
1824
SmallVector<ValueDecl *, 4 > allDecls;
1825
- for (auto import : namelookup::getAllImports (this )) {
1825
+ for (auto import : namelookup::getAllImports (dc )) {
1826
1826
import .second ->lookupClassMember (import .first , member, allDecls);
1827
1827
}
1828
1828
@@ -1840,26 +1840,23 @@ bool DeclContext::lookupAnyObject(DeclName member, NLOptions options,
1840
1840
if (decl->getOverriddenDecl ())
1841
1841
continue ;
1842
1842
1843
- auto dc = decl->getDeclContext ();
1844
- auto nominal = dc->getSelfNominalTypeDecl ();
1845
- assert (nominal && " Couldn't find nominal type?" );
1846
- (void )nominal;
1843
+ assert (decl->getDeclContext ()->isTypeContext () &&
1844
+ " Couldn't find nominal type?" );
1847
1845
1848
1846
// If we didn't see this declaration before, and it's an acceptable
1849
1847
// result, add it to the list.
1850
1848
// declaration to the list.
1851
1849
if (knownDecls.insert (decl).second &&
1852
- isAcceptableLookupResult (this , options, decl,
1850
+ isAcceptableLookupResult (dc , options, decl,
1853
1851
/* onlyCompleteObjectInits=*/ false ))
1854
1852
decls.push_back (decl);
1855
1853
}
1856
1854
1857
- pruneLookupResultSet (this , options, decls);
1858
- if (auto *debugClient = this ->getParentModule ()->getDebugClient ()) {
1859
- debugClient->finishLookupInAnyObject (this , member, options, decls);
1855
+ pruneLookupResultSet (dc , options, decls);
1856
+ if (auto *debugClient = dc ->getParentModule ()->getDebugClient ()) {
1857
+ debugClient->finishLookupInAnyObject (dc , member, options, decls);
1860
1858
}
1861
- // We're done. Report success/failure.
1862
- return !decls.empty ();
1859
+ return decls;
1863
1860
}
1864
1861
1865
1862
void DeclContext::lookupAllObjCMethods (
@@ -2635,3 +2632,40 @@ void FindLocalVal::visitCatchStmt(CatchStmt *S) {
2635
2632
checkPattern (S->getErrorPattern (), DeclVisibilityKind::LocalVariable);
2636
2633
visit (S->getBody ());
2637
2634
}
2635
+
2636
+ void swift::simple_display (llvm::raw_ostream &out, NLKind kind) {
2637
+ switch (kind) {
2638
+ case NLKind::QualifiedLookup:
2639
+ out << " QualifiedLookup" ;
2640
+ return ;
2641
+ case NLKind::UnqualifiedLookup:
2642
+ out << " UnqualifiedLookup" ;
2643
+ return ;
2644
+ }
2645
+ llvm_unreachable (" Unhandled case in switch" );
2646
+ }
2647
+
2648
+ void swift::simple_display (llvm::raw_ostream &out, NLOptions options) {
2649
+ using Flag = std::pair<NLOptions, StringRef>;
2650
+ Flag possibleFlags[] = {
2651
+ #define FLAG (Name ) {Name, #Name},
2652
+ FLAG (NL_ProtocolMembers)
2653
+ FLAG (NL_RemoveNonVisible)
2654
+ FLAG (NL_RemoveOverridden)
2655
+ FLAG (NL_IgnoreAccessControl)
2656
+ FLAG (NL_KnownNonCascadingDependency)
2657
+ FLAG (NL_KnownCascadingDependency)
2658
+ FLAG (NL_OnlyTypes)
2659
+ FLAG (NL_IncludeAttributeImplements)
2660
+ #undef FLAG
2661
+ };
2662
+
2663
+ auto flagsToPrint = llvm::make_filter_range (
2664
+ possibleFlags, [&](Flag flag) { return options & flag.first ; });
2665
+
2666
+ out << " { " ;
2667
+ interleave (
2668
+ flagsToPrint, [&](Flag flag) { out << flag.second ; },
2669
+ [&] { out << " , " ; });
2670
+ out << " }" ;
2671
+ }
0 commit comments