Merge pull request #23724 from brentdax/static-start

[NFC] Correct assumptions about static AbstractStorageDecls
This commit is contained in:
Brent Royal-Gordon
2019-04-02 17:16:27 -07:00
committed by GitHub
14 changed files with 102 additions and 87 deletions

View File

@@ -334,7 +334,7 @@ protected:
IsUserAccessible : 1
);
SWIFT_INLINE_BITFIELD(AbstractStorageDecl, ValueDecl, 1+1+1+1+2+1+1,
SWIFT_INLINE_BITFIELD(AbstractStorageDecl, ValueDecl, 1+1+1+1+2+1+1+1,
/// Whether the getter is mutating.
IsGetterMutating : 1,
@@ -353,14 +353,14 @@ protected:
/// Whether a keypath component can directly reference this storage,
/// or if it must use the overridden declaration instead.
HasComputedValidKeyPathComponent : 1,
ValidKeyPathComponent : 1
);
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 1+4+1+1+1+1,
ValidKeyPathComponent : 1,
/// Whether this property is a type property (currently unfortunately
/// called 'static').
IsStatic : 1,
IsStatic : 1
);
SWIFT_INLINE_BITFIELD(VarDecl, AbstractStorageDecl, 4+1+1+1+1,
/// The specifier associated with this variable or parameter. This
/// determines the storage semantics of the value e.g. mutability.
Specifier : 4,
@@ -393,6 +393,10 @@ protected:
/// Information about a symbolic default argument, like #file.
defaultArgumentKind : NumDefaultArgumentKindBits
);
SWIFT_INLINE_BITFIELD(SubscriptDecl, VarDecl, 2,
StaticSpelling : 2
);
SWIFT_INLINE_BITFIELD(EnumElementDecl, ValueDecl, 1,
/// The ResilienceExpansion to use for default arguments.
@@ -4283,8 +4287,9 @@ private:
}
protected:
AbstractStorageDecl(DeclKind Kind, DeclContext *DC, DeclName Name,
SourceLoc NameLoc, StorageIsMutable_t supportsMutation)
AbstractStorageDecl(DeclKind Kind, bool IsStatic, DeclContext *DC,
DeclName Name, SourceLoc NameLoc,
StorageIsMutable_t supportsMutation)
: ValueDecl(Kind, DC, Name, NameLoc) {
Bits.AbstractStorageDecl.HasStorage = true;
Bits.AbstractStorageDecl.SupportsMutation = supportsMutation;
@@ -4292,6 +4297,7 @@ protected:
Bits.AbstractStorageDecl.IsSetterMutating = true;
Bits.AbstractStorageDecl.OpaqueReadOwnership =
unsigned(OpaqueReadOwnership::Owned);
Bits.AbstractStorageDecl.IsStatic = IsStatic;
}
void setSupportsMutationIfStillStored(StorageIsMutable_t supportsMutation) {
@@ -4312,9 +4318,16 @@ public:
/// attribute.
bool isTransparent() const;
/// Determine whether this storage is a static member, if it
/// is a member. Currently only variables can be static.
inline bool isStatic() const; // defined in this header
/// Is this a type ('static') variable?
bool isStatic() const {
return Bits.AbstractStorageDecl.IsStatic;
}
void setStatic(bool IsStatic) {
Bits.AbstractStorageDecl.IsStatic = IsStatic;
}
/// \returns the way 'static'/'class' should be spelled for this declaration.
StaticSpellingKind getCorrectStaticSpelling() const;
/// Return the interface type of the stored value.
Type getValueInterfaceType() const;
@@ -4612,10 +4625,9 @@ protected:
VarDecl(DeclKind Kind, bool IsStatic, Specifier Sp, bool IsCaptureList,
SourceLoc NameLoc, Identifier Name, DeclContext *DC)
: AbstractStorageDecl(Kind, DC, Name, NameLoc,
: AbstractStorageDecl(Kind, IsStatic, DC, Name, NameLoc,
StorageIsMutable_t(!isImmutableSpecifier(Sp)))
{
Bits.VarDecl.IsStatic = IsStatic;
Bits.VarDecl.Specifier = static_cast<unsigned>(Sp);
Bits.VarDecl.IsCaptureList = IsCaptureList;
Bits.VarDecl.IsDebuggerVar = false;
@@ -4794,14 +4806,6 @@ public:
return getSpecifier() == Specifier::InOut;
}
/// Is this a type ('static') variable?
bool isStatic() const { return Bits.VarDecl.IsStatic; }
void setStatic(bool IsStatic) { Bits.VarDecl.IsStatic = IsStatic; }
/// \returns the way 'static'/'class' should be spelled for this declaration.
StaticSpellingKind getCorrectStaticSpelling() const;
bool isImmutable() const {
return isImmutableSpecifier(getSpecifier());
}
@@ -5110,24 +5114,40 @@ enum class ObjCSubscriptKind {
/// signatures (indices and element type) are distinct.
///
class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
SourceLoc StaticLoc;
SourceLoc ArrowLoc;
ParameterList *Indices;
TypeLoc ElementTy;
public:
SubscriptDecl(DeclName Name, SourceLoc SubscriptLoc, ParameterList *Indices,
SubscriptDecl(DeclName Name,
SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
SourceLoc SubscriptLoc, ParameterList *Indices,
SourceLoc ArrowLoc, TypeLoc ElementTy, DeclContext *Parent,
GenericParamList *GenericParams)
: GenericContext(DeclContextKind::SubscriptDecl, Parent),
AbstractStorageDecl(DeclKind::Subscript, Parent, Name, SubscriptLoc,
AbstractStorageDecl(DeclKind::Subscript,
StaticSpelling != StaticSpellingKind::None,
Parent, Name, SubscriptLoc,
/*will be overwritten*/ StorageIsNotMutable),
ArrowLoc(ArrowLoc), Indices(nullptr), ElementTy(ElementTy) {
StaticLoc(StaticLoc), ArrowLoc(ArrowLoc),
Indices(nullptr), ElementTy(ElementTy) {
Bits.SubscriptDecl.StaticSpelling = static_cast<unsigned>(StaticSpelling);
setIndices(Indices);
setGenericParams(GenericParams);
}
/// \returns the way 'static'/'class' was spelled in the source.
StaticSpellingKind getStaticSpelling() const {
return static_cast<StaticSpellingKind>(Bits.SubscriptDecl.StaticSpelling);
}
SourceLoc getStaticLoc() const { return StaticLoc; }
SourceLoc getSubscriptLoc() const { return getNameLoc(); }
SourceLoc getStartLoc() const { return getSubscriptLoc(); }
SourceLoc getStartLoc() const {
return getStaticLoc().isValid() ? getStaticLoc() : getSubscriptLoc();
}
SourceRange getSourceRange() const;
SourceRange getSignatureSourceRange() const;
@@ -6825,15 +6845,6 @@ AbstractStorageDecl::overwriteSetterAccess(AccessLevel accessLevel) {
mutableAddressor->overwriteAccess(accessLevel);
}
inline bool AbstractStorageDecl::isStatic() const {
if (auto var = dyn_cast<VarDecl>(this)) {
return var->isStatic();
}
// Currently, subscripts are never static.
return false;
}
/// Constructors and destructors always have a 'self' parameter,
/// which is stored in an instance member. Functions only have a
/// 'self' if they are declared inside of a nominal type or extension,

View File

@@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
/// Don't worry about adhering to the 80-column limit for this line.
const uint16_t SWIFTMODULE_VERSION_MINOR = 481; // Last change: custom attrs
const uint16_t SWIFTMODULE_VERSION_MINOR = 482; // static subscripts
using DeclIDField = BCFixed<31>;
@@ -1183,6 +1183,7 @@ namespace decls_block {
DeclIDField, // overridden decl
AccessLevelField, // access level
AccessLevelField, // setter access, if applicable
StaticSpellingKindField, // is subscript static?
BCVBR<5>, // number of parameter name components
BCArray<IdentifierIDField> // name components,
// followed by DeclID accessors,