@@ -334,7 +334,7 @@ class alignas(1 << DeclAlignInBits) Decl {
334334 IsUserAccessible : 1
335335 );
336336
337- SWIFT_INLINE_BITFIELD (AbstractStorageDecl, ValueDecl, 1 +1 +1 +1 +2 +1 +1 ,
337+ SWIFT_INLINE_BITFIELD (AbstractStorageDecl, ValueDecl, 1 +1 +1 +1 +2 +1 +1 + 1 ,
338338 // / Whether the getter is mutating.
339339 IsGetterMutating : 1 ,
340340
@@ -353,14 +353,14 @@ class alignas(1 << DeclAlignInBits) Decl {
353353 // / Whether a keypath component can directly reference this storage,
354354 // / or if it must use the overridden declaration instead.
355355 HasComputedValidKeyPathComponent : 1 ,
356- ValidKeyPathComponent : 1
357- );
358-
359- SWIFT_INLINE_BITFIELD (VarDecl, AbstractStorageDecl, 1 +4 +1 +1 +1 +1 ,
356+ ValidKeyPathComponent : 1 ,
357+
360358 // / Whether this property is a type property (currently unfortunately
361359 // / called 'static').
362- IsStatic : 1 ,
360+ IsStatic : 1
361+ );
363362
363+ SWIFT_INLINE_BITFIELD (VarDecl, AbstractStorageDecl, 4 +1 +1 +1 +1 ,
364364 // / The specifier associated with this variable or parameter. This
365365 // / determines the storage semantics of the value e.g. mutability.
366366 Specifier : 4 ,
@@ -393,6 +393,10 @@ class alignas(1 << DeclAlignInBits) Decl {
393393 // / Information about a symbolic default argument, like #file.
394394 defaultArgumentKind : NumDefaultArgumentKindBits
395395 );
396+
397+ SWIFT_INLINE_BITFIELD (SubscriptDecl, VarDecl, 2 ,
398+ StaticSpelling : 2
399+ );
396400
397401 SWIFT_INLINE_BITFIELD (EnumElementDecl, ValueDecl, 1 ,
398402 // / The ResilienceExpansion to use for default arguments.
@@ -4283,15 +4287,17 @@ class AbstractStorageDecl : public ValueDecl {
42834287 }
42844288
42854289protected:
4286- AbstractStorageDecl (DeclKind Kind, DeclContext *DC, DeclName Name,
4287- SourceLoc NameLoc, StorageIsMutable_t supportsMutation)
4290+ AbstractStorageDecl (DeclKind Kind, bool IsStatic, DeclContext *DC,
4291+ DeclName Name, SourceLoc NameLoc,
4292+ StorageIsMutable_t supportsMutation)
42884293 : ValueDecl(Kind, DC, Name, NameLoc) {
42894294 Bits.AbstractStorageDecl .HasStorage = true ;
42904295 Bits.AbstractStorageDecl .SupportsMutation = supportsMutation;
42914296 Bits.AbstractStorageDecl .IsGetterMutating = false ;
42924297 Bits.AbstractStorageDecl .IsSetterMutating = true ;
42934298 Bits.AbstractStorageDecl .OpaqueReadOwnership =
42944299 unsigned (OpaqueReadOwnership::Owned);
4300+ Bits.AbstractStorageDecl .IsStatic = IsStatic;
42954301 }
42964302
42974303 void setSupportsMutationIfStillStored (StorageIsMutable_t supportsMutation) {
@@ -4312,9 +4318,16 @@ class AbstractStorageDecl : public ValueDecl {
43124318 // / attribute.
43134319 bool isTransparent () const ;
43144320
4315- // / Determine whether this storage is a static member, if it
4316- // / is a member. Currently only variables can be static.
4317- inline bool isStatic () const ; // defined in this header
4321+ // / Is this a type ('static') variable?
4322+ bool isStatic () const {
4323+ return Bits.AbstractStorageDecl .IsStatic ;
4324+ }
4325+ void setStatic (bool IsStatic) {
4326+ Bits.AbstractStorageDecl .IsStatic = IsStatic;
4327+ }
4328+
4329+ // / \returns the way 'static'/'class' should be spelled for this declaration.
4330+ StaticSpellingKind getCorrectStaticSpelling () const ;
43184331
43194332 // / Return the interface type of the stored value.
43204333 Type getValueInterfaceType () const ;
@@ -4612,10 +4625,9 @@ class VarDecl : public AbstractStorageDecl {
46124625
46134626 VarDecl (DeclKind Kind, bool IsStatic, Specifier Sp, bool IsCaptureList,
46144627 SourceLoc NameLoc, Identifier Name, DeclContext *DC)
4615- : AbstractStorageDecl(Kind, DC, Name, NameLoc,
4628+ : AbstractStorageDecl(Kind, IsStatic, DC, Name, NameLoc,
46164629 StorageIsMutable_t (!isImmutableSpecifier(Sp)))
46174630 {
4618- Bits.VarDecl .IsStatic = IsStatic;
46194631 Bits.VarDecl .Specifier = static_cast <unsigned >(Sp);
46204632 Bits.VarDecl .IsCaptureList = IsCaptureList;
46214633 Bits.VarDecl .IsDebuggerVar = false ;
@@ -4794,14 +4806,6 @@ class VarDecl : public AbstractStorageDecl {
47944806 return getSpecifier () == Specifier::InOut;
47954807 }
47964808
4797-
4798- // / Is this a type ('static') variable?
4799- bool isStatic () const { return Bits.VarDecl .IsStatic ; }
4800- void setStatic (bool IsStatic) { Bits.VarDecl .IsStatic = IsStatic; }
4801-
4802- // / \returns the way 'static'/'class' should be spelled for this declaration.
4803- StaticSpellingKind getCorrectStaticSpelling () const ;
4804-
48054809 bool isImmutable () const {
48064810 return isImmutableSpecifier (getSpecifier ());
48074811 }
@@ -5110,24 +5114,40 @@ enum class ObjCSubscriptKind {
51105114// / signatures (indices and element type) are distinct.
51115115// /
51125116class SubscriptDecl : public GenericContext , public AbstractStorageDecl {
5117+ SourceLoc StaticLoc;
51135118 SourceLoc ArrowLoc;
51145119 ParameterList *Indices;
51155120 TypeLoc ElementTy;
51165121
51175122public:
5118- SubscriptDecl (DeclName Name, SourceLoc SubscriptLoc, ParameterList *Indices,
5123+ SubscriptDecl (DeclName Name,
5124+ SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
5125+ SourceLoc SubscriptLoc, ParameterList *Indices,
51195126 SourceLoc ArrowLoc, TypeLoc ElementTy, DeclContext *Parent,
51205127 GenericParamList *GenericParams)
51215128 : GenericContext(DeclContextKind::SubscriptDecl, Parent),
5122- AbstractStorageDecl (DeclKind::Subscript, Parent, Name, SubscriptLoc,
5129+ AbstractStorageDecl (DeclKind::Subscript,
5130+ StaticSpelling != StaticSpellingKind::None,
5131+ Parent, Name, SubscriptLoc,
51235132 /* will be overwritten*/ StorageIsNotMutable),
5124- ArrowLoc(ArrowLoc), Indices(nullptr ), ElementTy(ElementTy) {
5133+ StaticLoc(StaticLoc), ArrowLoc(ArrowLoc),
5134+ Indices(nullptr ), ElementTy(ElementTy) {
5135+ Bits.SubscriptDecl .StaticSpelling = static_cast <unsigned >(StaticSpelling);
51255136 setIndices (Indices);
51265137 setGenericParams (GenericParams);
51275138 }
51285139
5140+ // / \returns the way 'static'/'class' was spelled in the source.
5141+ StaticSpellingKind getStaticSpelling () const {
5142+ return static_cast <StaticSpellingKind>(Bits.SubscriptDecl .StaticSpelling );
5143+ }
5144+
5145+ SourceLoc getStaticLoc () const { return StaticLoc; }
51295146 SourceLoc getSubscriptLoc () const { return getNameLoc (); }
5130- SourceLoc getStartLoc () const { return getSubscriptLoc (); }
5147+
5148+ SourceLoc getStartLoc () const {
5149+ return getStaticLoc ().isValid () ? getStaticLoc () : getSubscriptLoc ();
5150+ }
51315151 SourceRange getSourceRange () const ;
51325152 SourceRange getSignatureSourceRange () const ;
51335153
@@ -6825,15 +6845,6 @@ AbstractStorageDecl::overwriteSetterAccess(AccessLevel accessLevel) {
68256845 mutableAddressor->overwriteAccess (accessLevel);
68266846}
68276847
6828- inline bool AbstractStorageDecl::isStatic () const {
6829- if (auto var = dyn_cast<VarDecl>(this )) {
6830- return var->isStatic ();
6831- }
6832-
6833- // Currently, subscripts are never static.
6834- return false ;
6835- }
6836-
68376848// / Constructors and destructors always have a 'self' parameter,
68386849// / which is stored in an instance member. Functions only have a
68396850// / 'self' if they are declared inside of a nominal type or extension,
0 commit comments