Skip to content

Commit e626cfb

Browse files
committed
Remove lazy member loading re-entrancy guards
Effectively revert #28907. The request evaluator will also catch re-entrancy here, and those cycles can be broken with NameLookupFlags::IgnoreNewExtensions.
1 parent b09c995 commit e626cfb

File tree

3 files changed

+6
-34
lines changed

3 files changed

+6
-34
lines changed

include/swift/AST/DeclContext.h

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -681,18 +681,9 @@ enum class IterableDeclContextKind : uint8_t {
681681
/// Note that an iterable declaration context must inherit from both
682682
/// \c IterableDeclContext and \c DeclContext.
683683
class IterableDeclContext {
684-
enum LazyMembers : unsigned {
685-
Present = 1 << 0,
686-
687-
/// Lazy member loading has a variety of feedback loops that need to
688-
/// switch to pseudo-empty-member behaviour to avoid infinite recursion;
689-
/// we use this flag to control them.
690-
InProgress = 1 << 1,
691-
};
692-
693684
/// The first declaration in this context along with a bit indicating whether
694685
/// the members of this context will be lazily produced.
695-
mutable llvm::PointerIntPair<Decl *, 2, LazyMembers> FirstDeclAndLazyMembers;
686+
mutable llvm::PointerIntPair<Decl *, 1, bool> FirstDeclAndLazyMembers;
696687

697688
/// The last declaration in this context, used for efficient insertion,
698689
/// along with the kind of iterable declaration context.
@@ -780,20 +771,7 @@ class IterableDeclContext {
780771

781772
/// Check whether there are lazily-loaded members.
782773
bool hasLazyMembers() const {
783-
return FirstDeclAndLazyMembers.getInt() & LazyMembers::Present;
784-
}
785-
786-
bool isLoadingLazyMembers() {
787-
return FirstDeclAndLazyMembers.getInt() & LazyMembers::InProgress;
788-
}
789-
790-
void setLoadingLazyMembers(bool inProgress) {
791-
LazyMembers status = FirstDeclAndLazyMembers.getInt();
792-
if (inProgress)
793-
status = LazyMembers(status | LazyMembers::InProgress);
794-
else
795-
status = LazyMembers(status & ~LazyMembers::InProgress);
796-
FirstDeclAndLazyMembers.setInt(status);
774+
return FirstDeclAndLazyMembers.getInt();
797775
}
798776

799777
/// Setup the loader for lazily-loaded members.

lib/AST/DeclContext.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -798,8 +798,7 @@ void IterableDeclContext::setMemberLoader(LazyMemberLoader *loader,
798798

799799
ASTContext &ctx = getASTContext();
800800
auto contextInfo = ctx.getOrCreateLazyIterableContextData(this, loader);
801-
auto lazyMembers = FirstDeclAndLazyMembers.getInt() | LazyMembers::Present;
802-
FirstDeclAndLazyMembers.setInt(LazyMembers(lazyMembers));
801+
FirstDeclAndLazyMembers.setInt(true);
803802
contextInfo->memberData = contextData;
804803

805804
++NumLazyIterableDeclContexts;
@@ -855,12 +854,11 @@ void IterableDeclContext::loadAllMembers() const {
855854
return;
856855

857856
// Don't try to load all members re-entrant-ly.
858-
auto contextInfo = ctx.getOrCreateLazyIterableContextData(this,
859-
/*lazyLoader=*/nullptr);
860-
auto lazyMembers = FirstDeclAndLazyMembers.getInt() & ~LazyMembers::Present;
861-
FirstDeclAndLazyMembers.setInt(LazyMembers(lazyMembers));
857+
FirstDeclAndLazyMembers.setInt(false);
862858

863859
const Decl *container = getDecl();
860+
auto contextInfo = ctx.getOrCreateLazyIterableContextData(this,
861+
/*lazyLoader=*/nullptr);
864862
contextInfo->loader->loadAllMembers(const_cast<Decl *>(container),
865863
contextInfo->memberData);
866864

lib/AST/NameLookup.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}
@@ -1285,7 +1282,6 @@ DirectLookupRequest::evaluate(Evaluator &evaluator,
12851282
<< useNamedLazyMemberLoading
12861283
<< "\n");
12871284

1288-
12891285
decl->prepareLookupTable();
12901286

12911287
auto tryCacheLookup =

0 commit comments

Comments
 (0)