@@ -1148,11 +1148,9 @@ populateLookupTableEntryFromLazyIDCLoader(ASTContext &ctx,
11481148 MemberLookupTable &LookupTable,
11491149 DeclBaseName name,
11501150 IterableDeclContext *IDC) {
1151- IDC->setLoadingLazyMembers (true );
11521151 auto ci = ctx.getOrCreateLazyIterableContextData (IDC,
11531152 /* lazyLoader=*/ nullptr );
11541153 if (auto res = ci->loader ->loadNamedMembers (IDC, name, ci->memberData )) {
1155- IDC->setLoadingLazyMembers (false );
11561154 if (auto s = ctx.Stats ) {
11571155 ++s->getFrontendCounters ().NamedLazyMemberLoadSuccessCount ;
11581156 }
@@ -1161,7 +1159,6 @@ populateLookupTableEntryFromLazyIDCLoader(ASTContext &ctx,
11611159 }
11621160 return false ;
11631161 } else {
1164- IDC->setLoadingLazyMembers (false );
11651162 if (auto s = ctx.Stats ) {
11661163 ++s->getFrontendCounters ().NamedLazyMemberLoadFailureCount ;
11671164 }
@@ -1210,25 +1207,21 @@ void NominalTypeDecl::prepareLookupTable() {
12101207
12111208 if (hasLazyMembers ()) {
12121209 assert (!hasUnparsedMembers ());
1213-
1214- // Lazy members: if the table needs population, populate the table _only
1215- // from those members already in the IDC member list_ such as implicits or
1216- // globals-as-members.
12171210 LookupTable->addMembers (getCurrentMembersWithoutLoading ());
1218- for (auto e : getExtensions ()) {
1219- // If we can lazy-load this extension, only take the members we've loaded
1220- // so far.
1221- if (e->wasDeserialized () || e->hasClangNode ()) {
1222- LookupTable->addMembers (e->getCurrentMembersWithoutLoading ());
1223- continue ;
1224- }
1225-
1226- // Else, load all the members into the table.
1227- LookupTable->addMembers (e->getMembers ());
1228- }
12291211 } else {
12301212 LookupTable->addMembers (getMembers ());
1231- LookupTable->updateLookupTable (this );
1213+ }
1214+
1215+ for (auto e : getExtensions ()) {
1216+ // If we can lazy-load this extension, only take the members we've loaded
1217+ // so far.
1218+ if (e->wasDeserialized () || e->hasClangNode ()) {
1219+ LookupTable->addMembers (e->getCurrentMembersWithoutLoading ());
1220+ continue ;
1221+ }
1222+
1223+ // Else, load all the members into the table.
1224+ LookupTable->addMembers (e->getMembers ());
12321225 }
12331226}
12341227
@@ -1257,34 +1250,42 @@ maybeFilterOutAttrImplements(TinyPtrVector<ValueDecl *> decls,
12571250TinyPtrVector<ValueDecl *>
12581251NominalTypeDecl::lookupDirect (DeclName name,
12591252 OptionSet<LookupDirectFlags> flags) {
1260- ASTContext &ctx = getASTContext ();
1261- if (auto s = ctx.Stats ) {
1262- ++s->getFrontendCounters ().NominalTypeLookupDirectCount ;
1263- }
1253+ return evaluateOrDefault (getASTContext ().evaluator ,
1254+ DirectLookupRequest ({this , name, flags}), {});
1255+ }
1256+
1257+ llvm::Expected<TinyPtrVector<ValueDecl *>>
1258+ DirectLookupRequest::evaluate (Evaluator &evaluator,
1259+ DirectLookupDescriptor desc) const {
1260+ const auto &name = desc.Name ;
1261+ const auto flags = desc.Options ;
1262+ auto *decl = desc.DC ;
12641263
12651264 // We only use NamedLazyMemberLoading when a user opts-in and we have
12661265 // not yet loaded all the members into the IDC list in the first place.
1266+ ASTContext &ctx = decl->getASTContext ();
12671267 const bool useNamedLazyMemberLoading = (ctx.LangOpts .NamedLazyMemberLoading &&
1268- hasLazyMembers ());
1269-
1268+ decl->hasLazyMembers ());
1269+ const bool disableAdditionalExtensionLoading =
1270+ flags.contains (NominalTypeDecl::LookupDirectFlags::IgnoreNewExtensions);
12701271 const bool includeAttrImplements =
1271- flags.contains (LookupDirectFlags::IncludeAttrImplements);
1272+ flags.contains (NominalTypeDecl:: LookupDirectFlags::IncludeAttrImplements);
12721273
1273- LLVM_DEBUG (llvm::dbgs () << getNameStr () << " .lookupDirect("
1274+ LLVM_DEBUG (llvm::dbgs () << decl-> getNameStr () << " .lookupDirect("
12741275 << name << " )"
1275- << " , hasLazyMembers()=" << hasLazyMembers ()
1276- << " , useNamedLazyMemberLoading=" << useNamedLazyMemberLoading
1276+ << " , hasLazyMembers()=" << decl->hasLazyMembers ()
1277+ << " , useNamedLazyMemberLoading="
1278+ << useNamedLazyMemberLoading
12771279 << " \n " );
12781280
1279-
1280- prepareLookupTable ();
1281+ decl->prepareLookupTable ();
12811282
12821283 auto tryCacheLookup =
1283- [=](MemberLookupTable * table,
1284+ [=](MemberLookupTable & table,
12841285 DeclName name) -> Optional<TinyPtrVector<ValueDecl *>> {
12851286 // Look for a declaration with this name.
1286- auto known = table-> find (name);
1287- if (known == table-> end ()) {
1287+ auto known = table. find (name);
1288+ if (known == table. end ()) {
12881289 return None;
12891290 }
12901291
@@ -1293,36 +1294,40 @@ NominalTypeDecl::lookupDirect(DeclName name,
12931294 includeAttrImplements);
12941295 };
12951296
1296- auto updateLookupTable = [this ](MemberLookupTable *table) {
1297+ auto updateLookupTable = [&decl](MemberLookupTable &table,
1298+ bool noExtensions) {
12971299 // Make sure we have the complete list of members (in this nominal and in
12981300 // all extensions).
1299- (void )getMembers ();
1301+ (void )decl->getMembers ();
1302+
1303+ if (noExtensions)
1304+ return ;
13001305
1301- for (auto E : getExtensions ())
1306+ for (auto E : decl-> getExtensions ())
13021307 (void )E->getMembers ();
13031308
1304- LookupTable-> updateLookupTable (this );
1309+ table. updateLookupTable (decl );
13051310 };
13061311
1312+ auto &Table = *decl->LookupTable ;
13071313 if (!useNamedLazyMemberLoading) {
1308- updateLookupTable (LookupTable );
1309- } else if (!LookupTable-> isLazilyComplete (name.getBaseName ())) {
1314+ updateLookupTable (Table, disableAdditionalExtensionLoading );
1315+ } else if (!Table. isLazilyComplete (name.getBaseName ())) {
13101316 // The lookup table believes it doesn't have a complete accounting of this
13111317 // name - either because we're never seen it before, or another extension
13121318 // was registered since the last time we searched. Ask the loaders to give
13131319 // us a hand.
1314- auto &Table = *LookupTable;
13151320 DeclBaseName baseName (name.getBaseName ());
1316- if (populateLookupTableEntryFromLazyIDCLoader (ctx, Table, baseName, this )) {
1317- updateLookupTable (LookupTable );
1318- } else {
1319- populateLookupTableEntryFromExtensions (ctx, Table, this , baseName);
1321+ if (populateLookupTableEntryFromLazyIDCLoader (ctx, Table, baseName, decl )) {
1322+ updateLookupTable (Table, disableAdditionalExtensionLoading );
1323+ } else if (!disableAdditionalExtensionLoading) {
1324+ populateLookupTableEntryFromExtensions (ctx, Table, decl , baseName);
13201325 }
13211326 Table.markLazilyComplete (baseName);
13221327 }
13231328
13241329 // Look for a declaration with this name.
1325- return tryCacheLookup (LookupTable , name)
1330+ return tryCacheLookup (Table , name)
13261331 .getValueOr (TinyPtrVector<ValueDecl *>());
13271332}
13281333
0 commit comments