Skip to content

Commit b1c83af

Browse files
authored
Merge pull request #40862 from DougGregor/param-decl-is-compile-time-const-overflow
2 parents da38e8c + f739411 commit b1c83af

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

include/swift/AST/Decl.h

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5463,7 +5463,16 @@ class ParamDecl : public VarDecl {
54635463
friend class DefaultArgumentInitContextRequest;
54645464
friend class DefaultArgumentExprRequest;
54655465

5466-
llvm::PointerIntPair<Identifier, 1, bool> ArgumentNameAndDestructured;
5466+
enum class ArgumentNameFlags : uint8_t {
5467+
/// Whether or not this parameter is destructed.
5468+
Destructured = 1 << 0,
5469+
5470+
/// Whether or not this parameter is '_const'.
5471+
IsCompileTimeConst = 1 << 1,
5472+
};
5473+
5474+
llvm::PointerIntPair<Identifier, 2, OptionSet<ArgumentNameFlags>>
5475+
ArgumentNameAndFlags;
54675476
SourceLoc ParameterNameLoc;
54685477
SourceLoc ArgumentNameLoc;
54695478
SourceLoc SpecifierLoc;
@@ -5494,13 +5503,10 @@ class ParamDecl : public VarDecl {
54945503

54955504
/// Whether or not this parameter is 'isolated'.
54965505
IsIsolated = 1 << 2,
5497-
5498-
/// Whether or not this parameter is '_const'.
5499-
IsCompileTimeConst = 1 << 3,
55005506
};
55015507

55025508
/// The default value, if any, along with flags.
5503-
llvm::PointerIntPair<StoredDefaultArgument *, 4, OptionSet<Flags>>
5509+
llvm::PointerIntPair<StoredDefaultArgument *, 3, OptionSet<Flags>>
55045510
DefaultValueAndFlags;
55055511

55065512
friend class ParamSpecifierRequest;
@@ -5518,7 +5524,7 @@ class ParamDecl : public VarDecl {
55185524

55195525
/// Retrieve the argument (API) name for this function parameter.
55205526
Identifier getArgumentName() const {
5521-
return ArgumentNameAndDestructured.getPointer();
5527+
return ArgumentNameAndFlags.getPointer();
55225528
}
55235529

55245530
/// Retrieve the parameter (local) name for this function parameter.
@@ -5538,8 +5544,17 @@ class ParamDecl : public VarDecl {
55385544
TypeRepr *getTypeRepr() const { return TyRepr; }
55395545
void setTypeRepr(TypeRepr *repr) { TyRepr = repr; }
55405546

5541-
bool isDestructured() const { return ArgumentNameAndDestructured.getInt(); }
5542-
void setDestructured(bool repr) { ArgumentNameAndDestructured.setInt(repr); }
5547+
bool isDestructured() const {
5548+
auto flags = ArgumentNameAndFlags.getInt();
5549+
return flags.contains(ArgumentNameFlags::Destructured);
5550+
}
5551+
5552+
void setDestructured(bool repr) {
5553+
auto flags = ArgumentNameAndFlags.getInt();
5554+
flags = repr ? flags | ArgumentNameFlags::Destructured
5555+
: flags - ArgumentNameFlags::Destructured;
5556+
ArgumentNameAndFlags.setInt(flags);
5557+
}
55435558

55445559
DefaultArgumentKind getDefaultArgumentKind() const {
55455560
return static_cast<DefaultArgumentKind>(Bits.ParamDecl.defaultArgumentKind);
@@ -5671,13 +5686,15 @@ class ParamDecl : public VarDecl {
56715686

56725687
/// Whether or not this parameter is marked with '_const'.
56735688
bool isCompileTimeConst() const {
5674-
return DefaultValueAndFlags.getInt().contains(Flags::IsCompileTimeConst);
5689+
return ArgumentNameAndFlags.getInt().contains(
5690+
ArgumentNameFlags::IsCompileTimeConst);
56755691
}
56765692

56775693
void setCompileTimeConst(bool value = true) {
5678-
auto flags = DefaultValueAndFlags.getInt();
5679-
DefaultValueAndFlags.setInt(value ? flags | Flags::IsCompileTimeConst
5680-
: flags - Flags::IsCompileTimeConst);
5694+
auto flags = ArgumentNameAndFlags.getInt();
5695+
flags = value ? flags | ArgumentNameFlags::IsCompileTimeConst
5696+
: flags - ArgumentNameFlags::IsCompileTimeConst;
5697+
ArgumentNameAndFlags.setInt(flags);
56815698
}
56825699

56835700
/// 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.

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6554,7 +6554,7 @@ ParamDecl::ParamDecl(SourceLoc specifierLoc,
65546554
/*IsStatic*/ false,
65556555
VarDecl::Introducer::Let, parameterNameLoc, parameterName, dc,
65566556
StorageIsNotMutable),
6557-
ArgumentNameAndDestructured(argumentName, false),
6557+
ArgumentNameAndFlags(argumentName, None),
65586558
ParameterNameLoc(parameterNameLoc),
65596559
ArgumentNameLoc(argumentNameLoc), SpecifierLoc(specifierLoc) {
65606560
Bits.ParamDecl.SpecifierComputed = false;

0 commit comments

Comments
 (0)