Skip to content

Commit 3beab2b

Browse files
authored
Merge pull request #40863 from DougGregor/compile-time-param-bit-manip-5.6
2 parents c12e31f + 9d76c35 commit 3beab2b

File tree

4 files changed

+32
-15
lines changed

4 files changed

+32
-15
lines changed

include/swift/AST/Decl.h

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5397,7 +5397,16 @@ class ParamDecl : public VarDecl {
53975397
friend class DefaultArgumentInitContextRequest;
53985398
friend class DefaultArgumentExprRequest;
53995399

5400-
llvm::PointerIntPair<Identifier, 1, bool> ArgumentNameAndDestructured;
5400+
enum class ArgumentNameFlags : uint8_t {
5401+
/// Whether or not this parameter is destructed.
5402+
Destructured = 1 << 0,
5403+
5404+
/// Whether or not this parameter is '_const'.
5405+
IsCompileTimeConst = 1 << 1,
5406+
};
5407+
5408+
llvm::PointerIntPair<Identifier, 2, OptionSet<ArgumentNameFlags>>
5409+
ArgumentNameAndFlags;
54015410
SourceLoc ParameterNameLoc;
54025411
SourceLoc ArgumentNameLoc;
54035412
SourceLoc SpecifierLoc;
@@ -5428,13 +5437,10 @@ class ParamDecl : public VarDecl {
54285437

54295438
/// Whether or not this parameter is 'isolated'.
54305439
IsIsolated = 1 << 2,
5431-
5432-
/// Whether or not this parameter is '_const'.
5433-
IsCompileTimeConst = 1 << 3,
54345440
};
54355441

54365442
/// The default value, if any, along with flags.
5437-
llvm::PointerIntPair<StoredDefaultArgument *, 4, OptionSet<Flags>>
5443+
llvm::PointerIntPair<StoredDefaultArgument *, 3, OptionSet<Flags>>
54385444
DefaultValueAndFlags;
54395445

54405446
friend class ParamSpecifierRequest;
@@ -5452,7 +5458,7 @@ class ParamDecl : public VarDecl {
54525458

54535459
/// Retrieve the argument (API) name for this function parameter.
54545460
Identifier getArgumentName() const {
5455-
return ArgumentNameAndDestructured.getPointer();
5461+
return ArgumentNameAndFlags.getPointer();
54565462
}
54575463

54585464
/// Retrieve the parameter (local) name for this function parameter.
@@ -5472,8 +5478,17 @@ class ParamDecl : public VarDecl {
54725478
TypeRepr *getTypeRepr() const { return TyRepr; }
54735479
void setTypeRepr(TypeRepr *repr) { TyRepr = repr; }
54745480

5475-
bool isDestructured() const { return ArgumentNameAndDestructured.getInt(); }
5476-
void setDestructured(bool repr) { ArgumentNameAndDestructured.setInt(repr); }
5481+
bool isDestructured() const {
5482+
auto flags = ArgumentNameAndFlags.getInt();
5483+
return flags.contains(ArgumentNameFlags::Destructured);
5484+
}
5485+
5486+
void setDestructured(bool repr) {
5487+
auto flags = ArgumentNameAndFlags.getInt();
5488+
flags = repr ? flags | ArgumentNameFlags::Destructured
5489+
: flags - ArgumentNameFlags::Destructured;
5490+
ArgumentNameAndFlags.setInt(flags);
5491+
}
54775492

54785493
DefaultArgumentKind getDefaultArgumentKind() const {
54795494
return static_cast<DefaultArgumentKind>(Bits.ParamDecl.defaultArgumentKind);
@@ -5605,13 +5620,15 @@ class ParamDecl : public VarDecl {
56055620

56065621
/// Whether or not this parameter is marked with '_const'.
56075622
bool isCompileTimeConst() const {
5608-
return DefaultValueAndFlags.getInt().contains(Flags::IsCompileTimeConst);
5623+
return ArgumentNameAndFlags.getInt().contains(
5624+
ArgumentNameFlags::IsCompileTimeConst);
56095625
}
56105626

56115627
void setCompileTimeConst(bool value = true) {
5612-
auto flags = DefaultValueAndFlags.getInt();
5613-
DefaultValueAndFlags.setInt(value ? flags | Flags::IsCompileTimeConst
5614-
: flags - Flags::IsCompileTimeConst);
5628+
auto flags = ArgumentNameAndFlags.getInt();
5629+
flags = value ? flags | ArgumentNameFlags::IsCompileTimeConst
5630+
: flags - ArgumentNameFlags::IsCompileTimeConst;
5631+
ArgumentNameAndFlags.setInt(flags);
56155632
}
56165633

56175634
/// Does this parameter reject temporary pointer conversions?

include/swift/AST/TypeAlignments.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ namespace swift {
7575
constexpr size_t SILFunctionAlignInBits = 2;
7676
constexpr size_t ASTContextAlignInBits = 2;
7777
constexpr size_t TypeVariableAlignInBits = 4;
78-
constexpr size_t StoredDefaultArgumentAlignInBits = 4;
78+
constexpr size_t StoredDefaultArgumentAlignInBits = 3;
7979

8080
// Well, this is the *minimum* pointer alignment; it's going to be 3 on
8181
// 64-bit targets, but that doesn't matter.

include/swift/AST/Types.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,7 @@ class ParameterTypeFlags {
19961996

19971997
ParameterTypeFlags withCompileTimeConst(bool isConst) const {
19981998
return ParameterTypeFlags(isConst ? value | ParameterTypeFlags::CompileTimeConst
1999-
: value | ParameterTypeFlags::CompileTimeConst);
1999+
: value - ParameterTypeFlags::CompileTimeConst);
20002000
}
20012001

20022002
ParameterTypeFlags withShared(bool isShared) const {

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6543,7 +6543,7 @@ ParamDecl::ParamDecl(SourceLoc specifierLoc,
65436543
/*IsStatic*/ false,
65446544
VarDecl::Introducer::Let, parameterNameLoc, parameterName, dc,
65456545
StorageIsNotMutable),
6546-
ArgumentNameAndDestructured(argumentName, false),
6546+
ArgumentNameAndFlags(argumentName, None),
65476547
ParameterNameLoc(parameterNameLoc),
65486548
ArgumentNameLoc(argumentNameLoc), SpecifierLoc(specifierLoc) {
65496549
Bits.ParamDecl.SpecifierComputed = false;

0 commit comments

Comments
 (0)