Skip to content

Commit 8de981d

Browse files
committed
[NFC] AST: Pack ParamDecl bits into intrusive bitfield
1 parent 91f9f9d commit 8de981d

File tree

3 files changed

+30
-21
lines changed

3 files changed

+30
-21
lines changed

include/swift/AST/Decl.h

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,18 @@ class alignas(1 << DeclAlignInBits) Decl {
332332
unsigned IsDebuggerVar : 1;
333333
BITFIELD_END;
334334

335+
BITFIELD_START(ParamDecl, VarDecl, 1 + NumDefaultArgumentKindBits);
336+
/// True if the type is implicitly specified in the source, but this has an
337+
/// apparently valid typeRepr. This is used in accessors, which look like:
338+
/// set (value) {
339+
/// but need to get the typeRepr from the property as a whole so Sema can
340+
/// resolve the type.
341+
unsigned IsTypeLocImplicit : 1;
342+
343+
/// Information about a symbolic default argument, like #file.
344+
unsigned defaultArgumentKind : NumDefaultArgumentKindBits;
345+
BITFIELD_END;
346+
335347
BITFIELD_START(EnumElementDecl, ValueDecl, 3);
336348
/// \brief Whether or not this element directly or indirectly references
337349
/// the enum type.
@@ -553,6 +565,7 @@ class alignas(1 << DeclAlignInBits) Decl {
553565
AbstractStorageDeclBitfields AbstractStorageDeclBits;
554566
AbstractFunctionDeclBitfields AbstractFunctionDeclBits;
555567
VarDeclBitfields VarDeclBits;
568+
ParamDeclBitfields ParamDeclBits;
556569
EnumElementDeclBitfields EnumElementDeclBits;
557570
FuncDeclBitfields FuncDeclBits;
558571
ConstructorDeclBitfields ConstructorDeclBits;
@@ -4570,16 +4583,6 @@ class ParamDecl : public VarDecl {
45704583
/// The default value, if any, along with whether this is varargs.
45714584
llvm::PointerIntPair<StoredDefaultArgument *, 1> DefaultValueAndIsVariadic;
45724585

4573-
/// True if the type is implicitly specified in the source, but this has an
4574-
/// apparently valid typeRepr. This is used in accessors, which look like:
4575-
/// set (value) {
4576-
/// but need to get the typeRepr from the property as a whole so Sema can
4577-
/// resolve the type.
4578-
bool IsTypeLocImplicit = false;
4579-
4580-
/// Information about a symbolic default argument, like #file.
4581-
DefaultArgumentKind defaultArgumentKind = DefaultArgumentKind::None;
4582-
45834586
public:
45844587
ParamDecl(VarDecl::Specifier specifier,
45854588
SourceLoc specifierLoc, SourceLoc argumentNameLoc,
@@ -4606,17 +4609,17 @@ class ParamDecl : public VarDecl {
46064609

46074610
SourceLoc getSpecifierLoc() const { return SpecifierLoc; }
46084611

4609-
bool isTypeLocImplicit() const { return IsTypeLocImplicit; }
4610-
void setIsTypeLocImplicit(bool val) { IsTypeLocImplicit = val; }
4612+
bool isTypeLocImplicit() const { return ParamDeclBits.IsTypeLocImplicit; }
4613+
void setIsTypeLocImplicit(bool val) { ParamDeclBits.IsTypeLocImplicit = val; }
46114614

4612-
bool isDefaultArgument() const {
4613-
return defaultArgumentKind != DefaultArgumentKind::None;
4614-
}
46154615
DefaultArgumentKind getDefaultArgumentKind() const {
4616-
return defaultArgumentKind;
4616+
return static_cast<DefaultArgumentKind>(ParamDeclBits.defaultArgumentKind);
4617+
}
4618+
bool isDefaultArgument() const {
4619+
return getDefaultArgumentKind() != DefaultArgumentKind::None;
46174620
}
46184621
void setDefaultArgumentKind(DefaultArgumentKind K) {
4619-
defaultArgumentKind = K;
4622+
ParamDeclBits.defaultArgumentKind = static_cast<unsigned>(K);
46204623
}
46214624

46224625
Expr *getDefaultValue() const {

include/swift/AST/DefaultArgumentKind.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
#ifndef SWIFT_DEFAULTARGUMENTKIND_H
1818
#define SWIFT_DEFAULTARGUMENTKIND_H
1919

20+
#include <cstdint>
21+
2022
namespace llvm {
2123
class StringRef;
2224
}
@@ -26,7 +28,7 @@ namespace swift {
2628
class Expr;
2729

2830
/// Describes the kind of default argument a tuple pattern element has.
29-
enum class DefaultArgumentKind : unsigned {
31+
enum class DefaultArgumentKind : uint8_t {
3032
/// No default argument.
3133
None,
3234
/// A normal default argument.
@@ -51,6 +53,7 @@ enum class DefaultArgumentKind : unsigned {
5153
/// An empty dictionary literal.
5254
EmptyDictionary,
5355
};
56+
enum { NumDefaultArgumentKindBits = 4 };
5457

5558
/// Retrieve the spelling of this default argument in source code, or
5659
/// an empty string if it has none.

lib/AST/Decl.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4296,6 +4296,9 @@ ParamDecl::ParamDecl(Specifier specifier,
42964296
SpecifierLoc(specifierLoc) {
42974297
assert(specifier != Specifier::Var &&
42984298
"'var' cannot appear on parameters; you meant 'inout'");
4299+
ParamDeclBits.IsTypeLocImplicit = false;
4300+
ParamDeclBits.defaultArgumentKind =
4301+
static_cast<unsigned>(DefaultArgumentKind::None);
42994302
}
43004303

43014304
/// Clone constructor, allocates a new ParamDecl identical to the first.
@@ -4310,9 +4313,9 @@ ParamDecl::ParamDecl(ParamDecl *PD, bool withTypes)
43104313
ArgumentName(PD->getArgumentName()),
43114314
ArgumentNameLoc(PD->getArgumentNameLoc()),
43124315
SpecifierLoc(PD->getSpecifierLoc()),
4313-
DefaultValueAndIsVariadic(nullptr, PD->DefaultValueAndIsVariadic.getInt()),
4314-
IsTypeLocImplicit(PD->IsTypeLocImplicit),
4315-
defaultArgumentKind(PD->defaultArgumentKind) {
4316+
DefaultValueAndIsVariadic(nullptr, PD->DefaultValueAndIsVariadic.getInt()) {
4317+
ParamDeclBits.IsTypeLocImplicit = PD->ParamDeclBits.IsTypeLocImplicit;
4318+
ParamDeclBits.defaultArgumentKind = PD->ParamDeclBits.defaultArgumentKind;
43164319
typeLoc = PD->getTypeLoc().clone(PD->getASTContext());
43174320
if (!withTypes && typeLoc.getTypeRepr())
43184321
typeLoc.setType(Type());

0 commit comments

Comments
 (0)