Skip to content

Commit c25210f

Browse files
committed
Move IsUserAccessible bit from VarDecl up to ValueDecl (and adjust bits).
1 parent b662c3a commit c25210f

File tree

2 files changed

+39
-37
lines changed

2 files changed

+39
-37
lines changed

include/swift/AST/Decl.h

Lines changed: 33 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,12 @@ class alignas(1 << DeclAlignInBits) Decl {
287287
/// Whether we have already checked whether this declaration is a
288288
/// redeclaration.
289289
unsigned CheckedRedeclaration : 1;
290+
291+
/// Whether the decl can be accessed by swift users; for instance,
292+
/// a.storage for lazy var a is a decl that cannot be accessed.
293+
unsigned IsUserAccessible : 1;
290294
};
291-
enum { NumValueDeclBits = NumDeclBits + 2 };
295+
enum { NumValueDeclBits = NumDeclBits + 3 };
292296
static_assert(NumValueDeclBits <= 32, "fits in an unsigned");
293297

294298
class AbstractStorageDeclBitfields {
@@ -328,11 +332,8 @@ class alignas(1 << DeclAlignInBits) Decl {
328332
/// It is up to the debugger to instruct SIL how to access this variable.
329333
unsigned IsDebuggerVar : 1;
330334

331-
/// Whether the decl can be accessed by swift users; for instance,
332-
/// a.storage for lazy var a is a decl that cannot be accessed.
333-
unsigned IsUserAccessible : 1;
334335
};
335-
enum { NumVarDeclBits = NumAbstractStorageDeclBits + 6 };
336+
enum { NumVarDeclBits = NumAbstractStorageDeclBits + 5 };
336337
static_assert(NumVarDeclBits <= 32, "fits in an unsigned");
337338

338339
class EnumElementDeclBitfields {
@@ -384,10 +385,8 @@ class alignas(1 << DeclAlignInBits) Decl {
384385
/// Whether this function has a dynamic Self return type.
385386
unsigned HasDynamicSelf : 1;
386387

387-
/// Whether we are statically dispatched even if overridable
388-
unsigned ForcedStaticDispatch : 1;
389388
};
390-
enum { NumFuncDeclBits = NumAbstractFunctionDeclBits + 6 };
389+
enum { NumFuncDeclBits = NumAbstractFunctionDeclBits + 5 };
391390
static_assert(NumFuncDeclBits <= 32, "fits in an unsigned");
392391

393392
class ConstructorDeclBitfields {
@@ -401,9 +400,6 @@ class alignas(1 << DeclAlignInBits) Decl {
401400
/// analysis and SIL generation.
402401
unsigned ComputedBodyInitKind : 3;
403402

404-
/// The kind of initializer we have.
405-
unsigned InitKind : 2;
406-
407403
/// Whether this initializer is a stub placed into a subclass to
408404
/// catch invalid delegations to a designated initializer not
409405
/// overridden by the subclass. A stub will always trap at runtime.
@@ -413,7 +409,7 @@ class alignas(1 << DeclAlignInBits) Decl {
413409
/// an object construction that will invoke a stub.
414410
unsigned HasStubImplementation : 1;
415411
};
416-
enum { NumConstructorDeclBits = NumAbstractFunctionDeclBits + 6 };
412+
enum { NumConstructorDeclBits = NumAbstractFunctionDeclBits + 4 };
417413
static_assert(NumConstructorDeclBits <= 32, "fits in an unsigned");
418414

419415
class TypeDeclBitfields {
@@ -524,10 +520,8 @@ class alignas(1 << DeclAlignInBits) Decl {
524520
/// control inserting the implicit destructor.
525521
unsigned HasDestructorDecl : 1;
526522

527-
/// Whether the class has @objc ancestry.
528-
unsigned ObjCClassKind : 3;
529523
};
530-
enum { NumClassDeclBits = NumNominalTypeDeclBits + 11 };
524+
enum { NumClassDeclBits = NumNominalTypeDeclBits + 8 };
531525
static_assert(NumClassDeclBits <= 32, "fits in an unsigned");
532526

533527
class StructDeclBitfields {
@@ -2091,6 +2085,7 @@ class ValueDecl : public Decl {
20912085
: Decl(K, context), Name(name), NameLoc(NameLoc) {
20922086
ValueDeclBits.AlreadyInLookupTable = false;
20932087
ValueDeclBits.CheckedRedeclaration = false;
2088+
ValueDeclBits.IsUserAccessible = true;
20942089
}
20952090

20962091
public:
@@ -2116,6 +2111,14 @@ class ValueDecl : public Decl {
21162111
ValueDeclBits.CheckedRedeclaration = checked;
21172112
}
21182113

2114+
void setUserAccessible(bool Accessible) {
2115+
ValueDeclBits.IsUserAccessible = Accessible;
2116+
}
2117+
2118+
bool isUserAccessible() const {
2119+
return ValueDeclBits.IsUserAccessible;
2120+
}
2121+
21192122
bool hasName() const { return bool(Name); }
21202123
/// TODO: Rename to getSimpleName?
21212124
Identifier getName() const { return Name.getBaseName(); }
@@ -3183,6 +3186,9 @@ class ClassDecl : public NominalTypeDecl {
31833186
SourceLoc ClassLoc;
31843187
ObjCMethodLookupTable *ObjCMethodLookup = nullptr;
31853188

3189+
/// Whether the class has @objc ancestry.
3190+
unsigned ObjCKind : 3;
3191+
31863192
/// Create the Objective-C member lookup table.
31873193
void createObjCMethodLookup();
31883194

@@ -4278,7 +4284,6 @@ class VarDecl : public AbstractStorageDecl {
42784284
SourceLoc NameLoc, Identifier Name, Type Ty, DeclContext *DC)
42794285
: AbstractStorageDecl(Kind, DC, Name, NameLoc)
42804286
{
4281-
VarDeclBits.IsUserAccessible = true;
42824287
VarDeclBits.IsStatic = IsStatic;
42834288
VarDeclBits.IsLet = IsLet;
42844289
VarDeclBits.IsCaptureList = IsCaptureList;
@@ -4300,14 +4305,6 @@ class VarDecl : public AbstractStorageDecl {
43004305

43014306
SourceRange getSourceRange() const;
43024307

4303-
void setUserAccessible(bool Accessible) {
4304-
VarDeclBits.IsUserAccessible = Accessible;
4305-
}
4306-
4307-
bool isUserAccessible() const {
4308-
return VarDeclBits.IsUserAccessible;
4309-
}
4310-
43114308
TypeLoc &getTypeLoc() { return typeLoc; }
43124309
TypeLoc getTypeLoc() const { return typeLoc; }
43134310

@@ -5031,6 +5028,9 @@ class FuncDecl final : public AbstractFunctionDecl,
50315028
unsigned HaveSearchedForCommonOverloadReturnType : 1;
50325029
unsigned HaveFoundCommonOverloadReturnType : 1;
50335030

5031+
/// Whether we are statically dispatched even if overridable
5032+
unsigned ForcedStaticDispatch : 1;
5033+
50345034
/// \brief If this FuncDecl is an accessor for a property, this indicates
50355035
/// which property and what kind of accessor.
50365036
llvm::PointerIntPair<AbstractStorageDecl*, 3, AccessorKind> AccessorDecl;
@@ -5060,8 +5060,8 @@ class FuncDecl final : public AbstractFunctionDecl,
50605060
assert(NumParameterLists > 0 && "Must have at least an empty tuple arg");
50615061
FuncDeclBits.Mutating = false;
50625062
FuncDeclBits.HasDynamicSelf = false;
5063-
FuncDeclBits.ForcedStaticDispatch = false;
5064-
5063+
5064+
ForcedStaticDispatch = false;
50655065
HaveSearchedForCommonOverloadReturnType = false;
50665066
HaveFoundCommonOverloadReturnType = false;
50675067
}
@@ -5291,10 +5291,10 @@ class FuncDecl final : public AbstractFunctionDecl,
52915291

52925292
/// Returns true if the function is forced to be statically dispatched.
52935293
bool hasForcedStaticDispatch() const {
5294-
return FuncDeclBits.ForcedStaticDispatch;
5294+
return ForcedStaticDispatch;
52955295
}
52965296
void setForcedStaticDispatch(bool flag) {
5297-
FuncDeclBits.ForcedStaticDispatch = flag;
5297+
ForcedStaticDispatch = flag;
52985298
}
52995299

53005300
static bool classof(const Decl *D) { return D->getKind() == DeclKind::Func; }
@@ -5511,6 +5511,9 @@ enum class CtorInitializerKind {
55115511
/// }
55125512
/// \endcode
55135513
class ConstructorDecl : public AbstractFunctionDecl {
5514+
/// The kind of initializer we have.
5515+
unsigned InitKind : 2;
5516+
55145517
/// The failability of this initializer, which is an OptionalTypeKind.
55155518
unsigned Failability : 2;
55165519

@@ -5616,12 +5619,12 @@ class ConstructorDecl : public AbstractFunctionDecl {
56165619

56175620
/// Determine the kind of initializer this is.
56185621
CtorInitializerKind getInitKind() const {
5619-
return static_cast<CtorInitializerKind>(ConstructorDeclBits.InitKind);
5622+
return static_cast<CtorInitializerKind>(InitKind);
56205623
}
56215624

56225625
/// Set whether this is a convenience initializer.
56235626
void setInitKind(CtorInitializerKind kind) {
5624-
ConstructorDeclBits.InitKind = static_cast<unsigned>(kind);
5627+
InitKind = static_cast<unsigned>(kind);
56255628
}
56265629

56275630
/// Whether this is a designated initializer.

lib/AST/Decl.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ void Decl::setDeclContext(DeclContext *DC) {
310310
}
311311

312312
bool Decl::isUserAccessible() const {
313-
if (auto VD = dyn_cast<VarDecl>(this)) {
313+
if (auto VD = dyn_cast<ValueDecl>(this)) {
314314
return VD->isUserAccessible();
315315
}
316316
return true;
@@ -2442,7 +2442,7 @@ ClassDecl::ClassDecl(SourceLoc ClassLoc, Identifier Name, SourceLoc NameLoc,
24422442
= static_cast<unsigned>(StoredInheritsSuperclassInits::Unchecked);
24432443
ClassDeclBits.RawForeignKind = 0;
24442444
ClassDeclBits.HasDestructorDecl = 0;
2445-
ClassDeclBits.ObjCClassKind = 0;
2445+
ObjCKind = 0;
24462446
}
24472447

24482448
DestructorDecl *ClassDecl::getDestructor() {
@@ -2543,8 +2543,8 @@ bool ClassDecl::inheritsSuperclassInitializers(LazyResolver *resolver) {
25432543

25442544
ObjCClassKind ClassDecl::checkObjCAncestry() const {
25452545
// See if we've already computed this.
2546-
if (ClassDeclBits.ObjCClassKind)
2547-
return ObjCClassKind(ClassDeclBits.ObjCClassKind - 1);
2546+
if (ObjCKind)
2547+
return ObjCClassKind(ObjCKind - 1);
25482548

25492549
llvm::SmallPtrSet<const ClassDecl *, 8> visited;
25502550
bool genericAncestry = false, isObjC = false;
@@ -2581,7 +2581,7 @@ ObjCClassKind ClassDecl::checkObjCAncestry() const {
25812581
kind = ObjCClassKind::ObjCWithSwiftRoot;
25822582

25832583
// Save the result for later.
2584-
const_cast<ClassDecl *>(this)->ClassDeclBits.ObjCClassKind
2584+
const_cast<ClassDecl *>(this)->ObjCKind
25852585
= unsigned(kind) + 1;
25862586
return kind;
25872587
}
@@ -4699,9 +4699,8 @@ ConstructorDecl::ConstructorDecl(DeclName Name, SourceLoc ConstructorLoc,
46994699
setParameterLists(SelfDecl, BodyParams);
47004700

47014701
ConstructorDeclBits.ComputedBodyInitKind = 0;
4702-
ConstructorDeclBits.InitKind
4703-
= static_cast<unsigned>(CtorInitializerKind::Designated);
47044702
ConstructorDeclBits.HasStubImplementation = 0;
4703+
this->InitKind = static_cast<unsigned>(CtorInitializerKind::Designated);
47054704
this->Failability = static_cast<unsigned>(Failability);
47064705
}
47074706

0 commit comments

Comments
 (0)