Skip to content

Commit 7bede89

Browse files
committed
[AST] NFC: Repack misc IterableDeclContext bits
1 parent 045d996 commit 7bede89

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

include/swift/AST/DeclContext.h

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ typedef IteratorRange<DeclIterator> DeclRange;
591591

592592
/// The kind of an \c IterableDeclContext.
593593
enum class IterableDeclContextKind : uint8_t {
594-
NominalTypeDecl,
594+
NominalTypeDecl = 0,
595595
ExtensionDecl,
596596
};
597597

@@ -601,24 +601,28 @@ enum class IterableDeclContextKind : uint8_t {
601601
/// Note that an iterable declaration context must inherit from both
602602
/// \c IterableDeclContext and \c DeclContext.
603603
class IterableDeclContext {
604+
enum LazyMembers : unsigned {
605+
Present = 1 << 0,
606+
607+
/// Lazy member loading has a variety of feedback loops that need to
608+
/// switch to pseudo-empty-member behaviour to avoid infinite recursion;
609+
/// we use this flag to control them.
610+
InProgress = 1 << 1,
611+
};
612+
604613
/// The first declaration in this context along with a bit indicating whether
605614
/// the members of this context will be lazily produced.
606-
mutable llvm::PointerIntPair<Decl *, 1, bool> FirstDeclAndLazyMembers;
615+
mutable llvm::PointerIntPair<Decl *, 2, LazyMembers> FirstDeclAndLazyMembers;
607616

608617
/// The last declaration in this context, used for efficient insertion,
609618
/// along with the kind of iterable declaration context.
610-
mutable llvm::PointerIntPair<Decl *, 2, IterableDeclContextKind>
619+
mutable llvm::PointerIntPair<Decl *, 1, IterableDeclContextKind>
611620
LastDeclAndKind;
612621

613622
/// The DeclID this IDC was deserialized from, if any. Used for named lazy
614623
/// member loading, as a key when doing lookup in this IDC.
615624
serialization::DeclID SerialID;
616625

617-
/// Lazy member loading has a variety of feedback loops that need to
618-
/// switch to pseudo-empty-member behaviour to avoid infinite recursion;
619-
/// we use this flag to control them.
620-
bool lazyMemberLoadingInProgress = false;
621-
622626
template<class A, class B, class C>
623627
friend struct ::llvm::cast_convert_val;
624628

@@ -650,15 +654,20 @@ class IterableDeclContext {
650654

651655
/// Check whether there are lazily-loaded members.
652656
bool hasLazyMembers() const {
653-
return FirstDeclAndLazyMembers.getInt();
657+
return FirstDeclAndLazyMembers.getInt() & LazyMembers::Present;
654658
}
655659

656660
bool isLoadingLazyMembers() {
657-
return lazyMemberLoadingInProgress;
661+
return FirstDeclAndLazyMembers.getInt() & LazyMembers::InProgress;
658662
}
659663

660664
void setLoadingLazyMembers(bool inProgress) {
661-
lazyMemberLoadingInProgress = inProgress;
665+
LazyMembers status = FirstDeclAndLazyMembers.getInt();
666+
if (inProgress)
667+
status = LazyMembers(status | LazyMembers::InProgress);
668+
else
669+
status = LazyMembers(status & ~LazyMembers::InProgress);
670+
FirstDeclAndLazyMembers.setInt(status);
662671
}
663672

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

lib/AST/DeclContext.cpp

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

939939
ASTContext &ctx = getASTContext();
940940
auto contextInfo = ctx.getOrCreateLazyIterableContextData(this, loader);
941-
FirstDeclAndLazyMembers.setInt(true);
941+
auto lazyMembers = FirstDeclAndLazyMembers.getInt() | LazyMembers::Present;
942+
FirstDeclAndLazyMembers.setInt(LazyMembers(lazyMembers));
942943
contextInfo->memberData = contextData;
943944

944945
++NumLazyIterableDeclContexts;
@@ -958,7 +959,8 @@ void IterableDeclContext::loadAllMembers() const {
958959
ASTContext &ctx = getASTContext();
959960
auto contextInfo = ctx.getOrCreateLazyIterableContextData(this,
960961
/*lazyLoader=*/nullptr);
961-
FirstDeclAndLazyMembers.setInt(false);
962+
auto lazyMembers = FirstDeclAndLazyMembers.getInt() & ~LazyMembers::Present;
963+
FirstDeclAndLazyMembers.setInt(LazyMembers(lazyMembers));
962964

963965
const Decl *container = getDecl();
964966
contextInfo->loader->loadAllMembers(const_cast<Decl *>(container),

0 commit comments

Comments
 (0)