Skip to content

Commit aa8b3c4

Browse files
committed
[AST] Move lazily-computed @objc bits into a separate LazySemanticInfo field.
To help us isolate the state that is primarily managed through the request-evaluator, encapsulate that information in a LazySemanticInfo member (as we do with superclass info and enum raw type info) rather than scattering it around the AST.
1 parent be3974a commit aa8b3c4

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

include/swift/AST/Decl.h

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ class alignas(1 << DeclAlignInBits) Decl {
307307
NumElements : 32
308308
);
309309

310-
SWIFT_INLINE_BITFIELD(ValueDecl, Decl, 1+1+1+1+1,
310+
SWIFT_INLINE_BITFIELD(ValueDecl, Decl, 1+1+1,
311311
AlreadyInLookupTable : 1,
312312

313313
/// Whether we have already checked whether this declaration is a
@@ -316,13 +316,7 @@ class alignas(1 << DeclAlignInBits) Decl {
316316

317317
/// Whether the decl can be accessed by swift users; for instance,
318318
/// a.storage for lazy var a is a decl that cannot be accessed.
319-
IsUserAccessible : 1,
320-
321-
/// Whether the "IsObjC" bit has been computed yet.
322-
IsObjCComputed : 1,
323-
324-
/// Whether this declaration is exposed to Objective-C.
325-
IsObjC : 1
319+
IsUserAccessible : 1
326320
);
327321

328322
SWIFT_INLINE_BITFIELD(AbstractStorageDecl, ValueDecl, 1+1+1+1+1,
@@ -2181,6 +2175,14 @@ class ValueDecl : public Decl {
21812175
llvm::PointerIntPair<Type, 3, OptionalEnum<AccessLevel>> TypeAndAccess;
21822176
unsigned LocalDiscriminator = 0;
21832177

2178+
struct {
2179+
/// Whether the "IsObjC" bit has been computed yet.
2180+
unsigned isObjCComputed : 1;
2181+
2182+
/// Whether this declaration is exposed to Objective-C.
2183+
unsigned isObjC : 1;
2184+
} LazySemanticInfo;
2185+
21842186
protected:
21852187
ValueDecl(DeclKind K,
21862188
llvm::PointerUnion<DeclContext *, ASTContext *> context,
@@ -2189,8 +2191,8 @@ class ValueDecl : public Decl {
21892191
Bits.ValueDecl.AlreadyInLookupTable = false;
21902192
Bits.ValueDecl.CheckedRedeclaration = false;
21912193
Bits.ValueDecl.IsUserAccessible = true;
2192-
Bits.ValueDecl.IsObjCComputed = false;
2193-
Bits.ValueDecl.IsObjC = false;
2194+
LazySemanticInfo.isObjCComputed = false;
2195+
LazySemanticInfo.isObjC = false;
21942196
}
21952197

21962198
// MemberLookupTable borrows a bit from this type

lib/AST/Decl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1989,24 +1989,24 @@ CanType ValueDecl::getOverloadSignatureType() const {
19891989
}
19901990

19911991
bool ValueDecl::isObjC() const {
1992-
if (Bits.ValueDecl.IsObjCComputed)
1993-
return Bits.ValueDecl.IsObjC;
1992+
if (LazySemanticInfo.isObjCComputed)
1993+
return LazySemanticInfo.isObjC;
19941994

19951995
// Fallback: look for an @objc attribute.
19961996
// FIXME: This should become an error, eventually.
19971997
return getAttrs().hasAttribute<ObjCAttr>();
19981998
}
19991999

20002000
void ValueDecl::setIsObjC(bool value) {
2001-
assert(!Bits.ValueDecl.IsObjCComputed || Bits.ValueDecl.IsObjC == value);
2001+
assert(!LazySemanticInfo.isObjCComputed || LazySemanticInfo.isObjC == value);
20022002

2003-
if (Bits.ValueDecl.IsObjCComputed) {
2004-
assert(Bits.ValueDecl.IsObjC == value);
2003+
if (LazySemanticInfo.isObjCComputed) {
2004+
assert(LazySemanticInfo.isObjC == value);
20052005
return;
20062006
}
20072007

2008-
Bits.ValueDecl.IsObjCComputed = true;
2009-
Bits.ValueDecl.IsObjC = value;
2008+
LazySemanticInfo.isObjCComputed = true;
2009+
LazySemanticInfo.isObjC = value;
20102010
}
20112011

20122012
bool ValueDecl::canBeAccessedByDynamicLookup() const {

0 commit comments

Comments
 (0)