36
36
#include " swift/Basic/ArrayRefView.h"
37
37
#include " swift/Basic/Compiler.h"
38
38
#include " swift/Basic/InlineBitfield.h"
39
+ #include " swift/Basic/NullablePtr.h"
39
40
#include " swift/Basic/OptionalEnum.h"
40
41
#include " swift/Basic/Range.h"
41
42
#include " llvm/ADT/DenseMap.h"
@@ -334,7 +335,7 @@ class alignas(1 << DeclAlignInBits) Decl {
334
335
IsUserAccessible : 1
335
336
);
336
337
337
- SWIFT_INLINE_BITFIELD (AbstractStorageDecl, ValueDecl, 1 +1 +1 +1 +2 +1 +1 ,
338
+ SWIFT_INLINE_BITFIELD (AbstractStorageDecl, ValueDecl, 1 +1 +1 +1 +2 +1 +1 + 1 ,
338
339
// / Whether the getter is mutating.
339
340
IsGetterMutating : 1 ,
340
341
@@ -353,14 +354,14 @@ class alignas(1 << DeclAlignInBits) Decl {
353
354
// / Whether a keypath component can directly reference this storage,
354
355
// / or if it must use the overridden declaration instead.
355
356
HasComputedValidKeyPathComponent : 1 ,
356
- ValidKeyPathComponent : 1
357
- );
358
-
359
- SWIFT_INLINE_BITFIELD (VarDecl, AbstractStorageDecl, 1 +4 +1 +1 +1 +1 ,
357
+ ValidKeyPathComponent : 1 ,
358
+
360
359
// / Whether this property is a type property (currently unfortunately
361
360
// / called 'static').
362
- IsStatic : 1 ,
361
+ IsStatic : 1
362
+ );
363
363
364
+ SWIFT_INLINE_BITFIELD (VarDecl, AbstractStorageDecl, 4 +1 +1 +1 +1 ,
364
365
// / The specifier associated with this variable or parameter. This
365
366
// / determines the storage semantics of the value e.g. mutability.
366
367
Specifier : 4 ,
@@ -394,11 +395,10 @@ class alignas(1 << DeclAlignInBits) Decl {
394
395
defaultArgumentKind : NumDefaultArgumentKindBits
395
396
);
396
397
397
- SWIFT_INLINE_BITFIELD (EnumElementDecl, ValueDecl, 1 ,
398
- // / The ResilienceExpansion to use for default arguments.
399
- DefaultArgumentResilienceExpansion : 1
398
+ SWIFT_INLINE_BITFIELD (SubscriptDecl, VarDecl, 2 ,
399
+ StaticSpelling : 2
400
400
);
401
-
401
+
402
402
SWIFT_INLINE_BITFIELD (AbstractFunctionDecl, ValueDecl, 3 +8 +1 +1 +1 +1 +1 +1 +1 ,
403
403
// / \see AbstractFunctionDecl::BodyKind
404
404
BodyKind : 3 ,
@@ -421,9 +421,6 @@ class alignas(1 << DeclAlignInBits) Decl {
421
421
// / Whether NeedsNewVTableEntry is valid.
422
422
HasComputedNeedsNewVTableEntry : 1 ,
423
423
424
- // / The ResilienceExpansion to use for default arguments.
425
- DefaultArgumentResilienceExpansion : 1 ,
426
-
427
424
// / Whether this member was synthesized as part of a derived
428
425
// / protocol conformance.
429
426
Synthesized : 1
@@ -4283,15 +4280,17 @@ class AbstractStorageDecl : public ValueDecl {
4283
4280
}
4284
4281
4285
4282
protected:
4286
- AbstractStorageDecl (DeclKind Kind, DeclContext *DC, DeclName Name,
4287
- SourceLoc NameLoc, StorageIsMutable_t supportsMutation)
4283
+ AbstractStorageDecl (DeclKind Kind, bool IsStatic, DeclContext *DC,
4284
+ DeclName Name, SourceLoc NameLoc,
4285
+ StorageIsMutable_t supportsMutation)
4288
4286
: ValueDecl(Kind, DC, Name, NameLoc) {
4289
4287
Bits.AbstractStorageDecl .HasStorage = true ;
4290
4288
Bits.AbstractStorageDecl .SupportsMutation = supportsMutation;
4291
4289
Bits.AbstractStorageDecl .IsGetterMutating = false ;
4292
4290
Bits.AbstractStorageDecl .IsSetterMutating = true ;
4293
4291
Bits.AbstractStorageDecl .OpaqueReadOwnership =
4294
4292
unsigned (OpaqueReadOwnership::Owned);
4293
+ Bits.AbstractStorageDecl .IsStatic = IsStatic;
4295
4294
}
4296
4295
4297
4296
void setSupportsMutationIfStillStored (StorageIsMutable_t supportsMutation) {
@@ -4312,9 +4311,16 @@ class AbstractStorageDecl : public ValueDecl {
4312
4311
// / attribute.
4313
4312
bool isTransparent () const ;
4314
4313
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
4314
+ // / Is this a type ('static') variable?
4315
+ bool isStatic () const {
4316
+ return Bits.AbstractStorageDecl .IsStatic ;
4317
+ }
4318
+ void setStatic (bool IsStatic) {
4319
+ Bits.AbstractStorageDecl .IsStatic = IsStatic;
4320
+ }
4321
+
4322
+ // / \returns the way 'static'/'class' should be spelled for this declaration.
4323
+ StaticSpellingKind getCorrectStaticSpelling () const ;
4318
4324
4319
4325
// / Return the interface type of the stored value.
4320
4326
Type getValueInterfaceType () const ;
@@ -4612,10 +4618,9 @@ class VarDecl : public AbstractStorageDecl {
4612
4618
4613
4619
VarDecl (DeclKind Kind, bool IsStatic, Specifier Sp, bool IsCaptureList,
4614
4620
SourceLoc NameLoc, Identifier Name, DeclContext *DC)
4615
- : AbstractStorageDecl(Kind, DC, Name, NameLoc,
4621
+ : AbstractStorageDecl(Kind, IsStatic, DC, Name, NameLoc,
4616
4622
StorageIsMutable_t (!isImmutableSpecifier(Sp)))
4617
4623
{
4618
- Bits.VarDecl .IsStatic = IsStatic;
4619
4624
Bits.VarDecl .Specifier = static_cast <unsigned >(Sp);
4620
4625
Bits.VarDecl .IsCaptureList = IsCaptureList;
4621
4626
Bits.VarDecl .IsDebuggerVar = false ;
@@ -4743,8 +4748,32 @@ class VarDecl : public AbstractStorageDecl {
4743
4748
// / return this. Otherwise, this VarDecl must belong to a CaseStmt's
4744
4749
// / CaseLabelItem. In that case, return the first case label item of the first
4745
4750
// / case stmt in a sequence of case stmts that fallthrough into each other.
4751
+ // /
4752
+ // / NOTE: During type checking, we emit an error if we have a single case
4753
+ // / label item with a pattern that has multiple var decls of the same
4754
+ // / name. This means that during type checking and before type checking, we
4755
+ // / may have a _malformed_ switch stmt var decl linked list since var decls in
4756
+ // / the same case label item that have the same name will point at the same
4757
+ // / canonical var decl, namely the first var decl with the name in the
4758
+ // / canonical case label item's var decl list. This is ok, since we are going
4759
+ // / to emit the error, but it requires us to be more careful/cautious before
4760
+ // / type checking has been complete when relying on canonical var decls
4761
+ // / matching up.
4746
4762
VarDecl *getCanonicalVarDecl () const ;
4747
4763
4764
+ // / If this is a case stmt var decl, return the var decl that corresponds to
4765
+ // / this var decl in the first case label item of the case stmt. Returns
4766
+ // / nullptr if this isn't a VarDecl that is part of a case stmt.
4767
+ NullablePtr<VarDecl> getCorrespondingFirstCaseLabelItemVarDecl () const ;
4768
+
4769
+ // / If this is a case stmt var decl, return the case body var decl that this
4770
+ // / var decl maps to.
4771
+ NullablePtr<VarDecl> getCorrespondingCaseBodyVariable () const ;
4772
+
4773
+ // / Return true if this var decl is an implicit var decl belonging to a case
4774
+ // / stmt's body.
4775
+ bool isCaseBodyVariable () const ;
4776
+
4748
4777
// / True if the global stored property requires lazy initialization.
4749
4778
bool isLazilyInitializedGlobal () const ;
4750
4779
@@ -4794,14 +4823,6 @@ class VarDecl : public AbstractStorageDecl {
4794
4823
return getSpecifier () == Specifier::InOut;
4795
4824
}
4796
4825
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
-
4805
4826
bool isImmutable () const {
4806
4827
return isImmutableSpecifier (getSpecifier ());
4807
4828
}
@@ -5110,24 +5131,40 @@ enum class ObjCSubscriptKind {
5110
5131
// / signatures (indices and element type) are distinct.
5111
5132
// /
5112
5133
class SubscriptDecl : public GenericContext , public AbstractStorageDecl {
5134
+ SourceLoc StaticLoc;
5113
5135
SourceLoc ArrowLoc;
5114
5136
ParameterList *Indices;
5115
5137
TypeLoc ElementTy;
5116
5138
5117
5139
public:
5118
- SubscriptDecl (DeclName Name, SourceLoc SubscriptLoc, ParameterList *Indices,
5140
+ SubscriptDecl (DeclName Name,
5141
+ SourceLoc StaticLoc, StaticSpellingKind StaticSpelling,
5142
+ SourceLoc SubscriptLoc, ParameterList *Indices,
5119
5143
SourceLoc ArrowLoc, TypeLoc ElementTy, DeclContext *Parent,
5120
5144
GenericParamList *GenericParams)
5121
5145
: GenericContext(DeclContextKind::SubscriptDecl, Parent),
5122
- AbstractStorageDecl (DeclKind::Subscript, Parent, Name, SubscriptLoc,
5146
+ AbstractStorageDecl (DeclKind::Subscript,
5147
+ StaticSpelling != StaticSpellingKind::None,
5148
+ Parent, Name, SubscriptLoc,
5123
5149
/* will be overwritten*/ StorageIsNotMutable),
5124
- ArrowLoc(ArrowLoc), Indices(nullptr ), ElementTy(ElementTy) {
5150
+ StaticLoc(StaticLoc), ArrowLoc(ArrowLoc),
5151
+ Indices(nullptr ), ElementTy(ElementTy) {
5152
+ Bits.SubscriptDecl .StaticSpelling = static_cast <unsigned >(StaticSpelling);
5125
5153
setIndices (Indices);
5126
5154
setGenericParams (GenericParams);
5127
5155
}
5128
5156
5157
+ // / \returns the way 'static'/'class' was spelled in the source.
5158
+ StaticSpellingKind getStaticSpelling () const {
5159
+ return static_cast <StaticSpellingKind>(Bits.SubscriptDecl .StaticSpelling );
5160
+ }
5161
+
5162
+ SourceLoc getStaticLoc () const { return StaticLoc; }
5129
5163
SourceLoc getSubscriptLoc () const { return getNameLoc (); }
5130
- SourceLoc getStartLoc () const { return getSubscriptLoc (); }
5164
+
5165
+ SourceLoc getStartLoc () const {
5166
+ return getStaticLoc ().isValid () ? getStaticLoc () : getSubscriptLoc ();
5167
+ }
5131
5168
SourceRange getSourceRange () const ;
5132
5169
SourceRange getSignatureSourceRange () const ;
5133
5170
@@ -5287,8 +5324,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
5287
5324
Bits.AbstractFunctionDecl .Throws = Throws;
5288
5325
Bits.AbstractFunctionDecl .NeedsNewVTableEntry = false ;
5289
5326
Bits.AbstractFunctionDecl .HasComputedNeedsNewVTableEntry = false ;
5290
- Bits.AbstractFunctionDecl .DefaultArgumentResilienceExpansion =
5291
- unsigned (ResilienceExpansion::Maximal);
5292
5327
Bits.AbstractFunctionDecl .Synthesized = false ;
5293
5328
}
5294
5329
@@ -5536,21 +5571,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
5536
5571
// / Resolved during type checking
5537
5572
void setIsOverridden () { Bits.AbstractFunctionDecl .Overridden = true ; }
5538
5573
5539
- // / The ResilienceExpansion for default arguments.
5540
- // /
5541
- // / In Swift 4 mode, default argument expressions are serialized, and must
5542
- // / obey the restrictions imposed upon inlinable function bodies.
5543
- ResilienceExpansion getDefaultArgumentResilienceExpansion () const {
5544
- return ResilienceExpansion (
5545
- Bits.AbstractFunctionDecl .DefaultArgumentResilienceExpansion );
5546
- }
5547
-
5548
- // / Set the ResilienceExpansion for default arguments.
5549
- void setDefaultArgumentResilienceExpansion (ResilienceExpansion expansion) {
5550
- Bits.AbstractFunctionDecl .DefaultArgumentResilienceExpansion =
5551
- unsigned (expansion);
5552
- }
5553
-
5554
5574
// / Set information about the foreign error convention used by this
5555
5575
// / declaration.
5556
5576
void setForeignErrorConvention (const ForeignErrorConvention &convention);
@@ -6005,10 +6025,7 @@ class EnumElementDecl : public DeclContext, public ValueDecl {
6005
6025
Params(Params),
6006
6026
EqualsLoc(EqualsLoc),
6007
6027
RawValueExpr(RawValueExpr)
6008
- {
6009
- Bits.EnumElementDecl .DefaultArgumentResilienceExpansion =
6010
- static_cast <unsigned >(ResilienceExpansion::Maximal);
6011
- }
6028
+ {}
6012
6029
6013
6030
Identifier getName () const { return getFullName ().getBaseIdentifier (); }
6014
6031
@@ -6037,21 +6054,6 @@ class EnumElementDecl : public DeclContext, public ValueDecl {
6037
6054
TypeCheckedRawValueExpr = e;
6038
6055
}
6039
6056
6040
- // / The ResilienceExpansion for default arguments.
6041
- // /
6042
- // / In Swift 4 mode, default argument expressions are serialized, and must
6043
- // / obey the restrictions imposed upon inlinable function bodies.
6044
- ResilienceExpansion getDefaultArgumentResilienceExpansion () const {
6045
- return ResilienceExpansion (
6046
- Bits.EnumElementDecl .DefaultArgumentResilienceExpansion );
6047
- }
6048
-
6049
- // / Set the ResilienceExpansion for default arguments.
6050
- void setDefaultArgumentResilienceExpansion (ResilienceExpansion expansion) {
6051
- Bits.EnumElementDecl .DefaultArgumentResilienceExpansion =
6052
- unsigned (expansion);
6053
- }
6054
-
6055
6057
// / Return the containing EnumDecl.
6056
6058
EnumDecl *getParentEnum () const {
6057
6059
return cast<EnumDecl>(getDeclContext ());
@@ -6825,15 +6827,6 @@ AbstractStorageDecl::overwriteSetterAccess(AccessLevel accessLevel) {
6825
6827
mutableAddressor->overwriteAccess (accessLevel);
6826
6828
}
6827
6829
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
-
6837
6830
// / Constructors and destructors always have a 'self' parameter,
6838
6831
// / which is stored in an instance member. Functions only have a
6839
6832
// / 'self' if they are declared inside of a nominal type or extension,
0 commit comments