@@ -1218,6 +1218,9 @@ class swift::MemberLookupTable : public ASTAllocated<swift::MemberLookupTable> {
12181218 // / Lookup table mapping names to the set of declarations with that name.
12191219 LookupTable Lookup;
12201220
1221+ // / List of containers that have lazily-loaded members
1222+ llvm::SmallVector<ExtensionDecl *, 2 > ExtensionsWithLazyMembers;
1223+
12211224 // / The set of names of lazily-loaded members that the lookup table has a
12221225 // / complete accounting of with respect to all known extensions of its
12231226 // / parent nominal type.
@@ -1246,6 +1249,14 @@ class swift::MemberLookupTable : public ASTAllocated<swift::MemberLookupTable> {
12461249 // / Add the given members to the lookup table.
12471250 void addMembers (DeclRange members);
12481251
1252+ void addExtensionWithLazyMembers (ExtensionDecl *ext) {
1253+ ExtensionsWithLazyMembers.push_back (ext);
1254+ }
1255+
1256+ ArrayRef<ExtensionDecl *> getExtensionsWithLazyMembers () const {
1257+ return ExtensionsWithLazyMembers;
1258+ }
1259+
12491260 // / Returns \c true if the lookup table has a complete accounting of the
12501261 // / given name.
12511262 bool isLazilyComplete (DeclBaseName name) const {
@@ -1435,10 +1446,11 @@ void NominalTypeDecl::addedExtension(ExtensionDecl *ext) {
14351446 auto *table = LookupTable.getPointer ();
14361447 assert (table);
14371448
1438- if (ext->hasLazyMembers ()) {
1449+ if (ext->wasDeserialized () || ext-> hasClangNode ()) {
14391450 table->addMembers (ext->getCurrentMembersWithoutLoading ());
14401451 table->clearLazilyCompleteCache ();
14411452 table->clearLazilyCompleteForMacroExpansionCache ();
1453+ table->addExtensionWithLazyMembers (ext);
14421454 } else {
14431455 table->addMembers (ext->getMembers ());
14441456 }
@@ -1534,6 +1546,9 @@ populateLookupTableEntryFromLazyIDCLoader(ASTContext &ctx,
15341546 MemberLookupTable &LookupTable,
15351547 DeclBaseName name,
15361548 IterableDeclContext *IDC) {
1549+ if (!IDC->hasLazyMembers ())
1550+ return ;
1551+
15371552 auto ci = ctx.getOrCreateLazyIterableContextData (IDC,
15381553 /* lazyLoader=*/ nullptr );
15391554 auto res = ci->loader ->loadNamedMembers (IDC, name, ci->memberData );
@@ -1553,7 +1568,7 @@ populateLookupTableEntryFromExtensions(ASTContext &ctx,
15531568 assert (!table.isLazilyComplete (name) &&
15541569 " Should not be searching extensions for complete name!" );
15551570
1556- for (auto e : nominal-> getExtensions ()) {
1571+ for (auto e : table. getExtensionsWithLazyMembers ()) {
15571572 // If there's no lazy members to look at, all the members of this extension
15581573 // are present in the lookup table.
15591574 if (!e->hasLazyMembers ()) {
@@ -1789,6 +1804,7 @@ void NominalTypeDecl::prepareLookupTable() {
17891804 // LazyMemberLoader::loadNamedMembers().
17901805 if (e->wasDeserialized () || e->hasClangNode ()) {
17911806 table->addMembers (e->getCurrentMembersWithoutLoading ());
1807+ table->addExtensionWithLazyMembers (e);
17921808 continue ;
17931809 }
17941810
@@ -1848,21 +1864,14 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
18481864 const auto flags = desc.Options ;
18491865 auto *decl = desc.DC ;
18501866
1851- // We only use NamedLazyMemberLoading when a user opts-in and we have
1852- // not yet loaded all the members into the IDC list in the first place.
18531867 ASTContext &ctx = decl->getASTContext ();
1854- const bool useNamedLazyMemberLoading = (ctx.LangOpts .NamedLazyMemberLoading &&
1855- decl->hasLazyMembers ());
18561868 const bool includeAttrImplements =
18571869 flags.contains (NominalTypeDecl::LookupDirectFlags::IncludeAttrImplements);
18581870 const bool excludeMacroExpansions =
18591871 flags.contains (NominalTypeDecl::LookupDirectFlags::ExcludeMacroExpansions);
18601872
18611873 LLVM_DEBUG (llvm::dbgs () << decl->getNameStr () << " .lookupDirect("
18621874 << name << " )"
1863- << " , hasLazyMembers()=" << decl->hasLazyMembers ()
1864- << " , useNamedLazyMemberLoading="
1865- << useNamedLazyMemberLoading
18661875 << " , excludeMacroExpansions="
18671876 << excludeMacroExpansions
18681877 << " \n " );
@@ -1875,15 +1884,7 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
18751884 decl->prepareExtensions ();
18761885
18771886 auto &Table = *decl->getLookupTable ();
1878- if (!useNamedLazyMemberLoading) {
1879- // Make sure we have the complete list of members (in this nominal and in
1880- // all extensions).
1881- (void )decl->getMembers ();
1882-
1883- for (auto E : decl->getExtensions ())
1884- (void )E->getMembers ();
1885-
1886- } else if (!Table.isLazilyComplete (name.getBaseName ())) {
1887+ if (!Table.isLazilyComplete (name.getBaseName ())) {
18871888 DeclBaseName baseName (name.getBaseName ());
18881889
18891890 if (isa_and_nonnull<clang::NamespaceDecl>(decl->getClangDecl ())) {
0 commit comments