@@ -1218,6 +1218,9 @@ class swift::MemberLookupTable : public ASTAllocated<swift::MemberLookupTable> {
1218
1218
// / Lookup table mapping names to the set of declarations with that name.
1219
1219
LookupTable Lookup;
1220
1220
1221
+ // / List of containers that have lazily-loaded members
1222
+ llvm::SmallVector<ExtensionDecl *, 2 > ExtensionsWithLazyMembers;
1223
+
1221
1224
// / The set of names of lazily-loaded members that the lookup table has a
1222
1225
// / complete accounting of with respect to all known extensions of its
1223
1226
// / parent nominal type.
@@ -1246,6 +1249,14 @@ class swift::MemberLookupTable : public ASTAllocated<swift::MemberLookupTable> {
1246
1249
// / Add the given members to the lookup table.
1247
1250
void addMembers (DeclRange members);
1248
1251
1252
+ void addExtensionWithLazyMembers (ExtensionDecl *ext) {
1253
+ ExtensionsWithLazyMembers.push_back (ext);
1254
+ }
1255
+
1256
+ ArrayRef<ExtensionDecl *> getExtensionsWithLazyMembers () const {
1257
+ return ExtensionsWithLazyMembers;
1258
+ }
1259
+
1249
1260
// / Returns \c true if the lookup table has a complete accounting of the
1250
1261
// / given name.
1251
1262
bool isLazilyComplete (DeclBaseName name) const {
@@ -1435,10 +1446,11 @@ void NominalTypeDecl::addedExtension(ExtensionDecl *ext) {
1435
1446
auto *table = LookupTable.getPointer ();
1436
1447
assert (table);
1437
1448
1438
- if (ext->hasLazyMembers ()) {
1449
+ if (ext->wasDeserialized () || ext-> hasClangNode ()) {
1439
1450
table->addMembers (ext->getCurrentMembersWithoutLoading ());
1440
1451
table->clearLazilyCompleteCache ();
1441
1452
table->clearLazilyCompleteForMacroExpansionCache ();
1453
+ table->addExtensionWithLazyMembers (ext);
1442
1454
} else {
1443
1455
table->addMembers (ext->getMembers ());
1444
1456
}
@@ -1534,6 +1546,9 @@ populateLookupTableEntryFromLazyIDCLoader(ASTContext &ctx,
1534
1546
MemberLookupTable &LookupTable,
1535
1547
DeclBaseName name,
1536
1548
IterableDeclContext *IDC) {
1549
+ if (!IDC->hasLazyMembers ())
1550
+ return ;
1551
+
1537
1552
auto ci = ctx.getOrCreateLazyIterableContextData (IDC,
1538
1553
/* lazyLoader=*/ nullptr );
1539
1554
auto res = ci->loader ->loadNamedMembers (IDC, name, ci->memberData );
@@ -1553,7 +1568,7 @@ populateLookupTableEntryFromExtensions(ASTContext &ctx,
1553
1568
assert (!table.isLazilyComplete (name) &&
1554
1569
" Should not be searching extensions for complete name!" );
1555
1570
1556
- for (auto e : nominal-> getExtensions ()) {
1571
+ for (auto e : table. getExtensionsWithLazyMembers ()) {
1557
1572
// If there's no lazy members to look at, all the members of this extension
1558
1573
// are present in the lookup table.
1559
1574
if (!e->hasLazyMembers ()) {
@@ -1789,6 +1804,7 @@ void NominalTypeDecl::prepareLookupTable() {
1789
1804
// LazyMemberLoader::loadNamedMembers().
1790
1805
if (e->wasDeserialized () || e->hasClangNode ()) {
1791
1806
table->addMembers (e->getCurrentMembersWithoutLoading ());
1807
+ table->addExtensionWithLazyMembers (e);
1792
1808
continue ;
1793
1809
}
1794
1810
@@ -1848,21 +1864,14 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
1848
1864
const auto flags = desc.Options ;
1849
1865
auto *decl = desc.DC ;
1850
1866
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.
1853
1867
ASTContext &ctx = decl->getASTContext ();
1854
- const bool useNamedLazyMemberLoading = (ctx.LangOpts .NamedLazyMemberLoading &&
1855
- decl->hasLazyMembers ());
1856
1868
const bool includeAttrImplements =
1857
1869
flags.contains (NominalTypeDecl::LookupDirectFlags::IncludeAttrImplements);
1858
1870
const bool excludeMacroExpansions =
1859
1871
flags.contains (NominalTypeDecl::LookupDirectFlags::ExcludeMacroExpansions);
1860
1872
1861
1873
LLVM_DEBUG (llvm::dbgs () << decl->getNameStr () << " .lookupDirect("
1862
1874
<< name << " )"
1863
- << " , hasLazyMembers()=" << decl->hasLazyMembers ()
1864
- << " , useNamedLazyMemberLoading="
1865
- << useNamedLazyMemberLoading
1866
1875
<< " , excludeMacroExpansions="
1867
1876
<< excludeMacroExpansions
1868
1877
<< " \n " );
@@ -1875,15 +1884,7 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
1875
1884
decl->prepareExtensions ();
1876
1885
1877
1886
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 ())) {
1887
1888
DeclBaseName baseName (name.getBaseName ());
1888
1889
1889
1890
if (isa_and_nonnull<clang::NamespaceDecl>(decl->getClangDecl ())) {
0 commit comments