@@ -364,10 +364,9 @@ class alignas(1 << DeclAlignInBits) Decl {
364
364
IsStatic : 1
365
365
);
366
366
367
- SWIFT_INLINE_BITFIELD (VarDecl, AbstractStorageDecl, 4 +1 +1 +1 +1 +1 ,
368
- // / The specifier associated with this variable or parameter. This
369
- // / determines the storage semantics of the value e.g. mutability.
370
- Specifier : 4 ,
367
+ SWIFT_INLINE_BITFIELD (VarDecl, AbstractStorageDecl, 1 +1 +1 +1 +1 +1 ,
368
+ // / Encodes whether this is a 'let' binding.
369
+ Introducer : 1 ,
371
370
372
371
// / Whether this declaration was an element of a capture list.
373
372
IsCaptureList : 1 ,
@@ -388,7 +387,11 @@ class alignas(1 << DeclAlignInBits) Decl {
388
387
IsPropertyWrapperBackingProperty : 1
389
388
);
390
389
391
- SWIFT_INLINE_BITFIELD (ParamDecl, VarDecl, 1 + NumDefaultArgumentKindBits,
390
+ SWIFT_INLINE_BITFIELD (ParamDecl, VarDecl, 2 +1 +NumDefaultArgumentKindBits,
391
+ // / The specifier associated with this parameter. This determines
392
+ // / the storage semantics of the value e.g. mutability.
393
+ Specifier : 2 ,
394
+
392
395
// / True if the type is implicitly specified in the source, but this has an
393
396
// / apparently valid typeRepr. This is used in accessors, which look like:
394
397
// / set (value) {
@@ -4485,16 +4488,6 @@ class AbstractStorageDecl : public ValueDecl {
4485
4488
Bits.AbstractStorageDecl .IsStatic = IsStatic;
4486
4489
}
4487
4490
4488
- void setSupportsMutationIfStillStored (StorageIsMutable_t supportsMutation) {
4489
- if (auto ptr = Accessors.getPointer ()) {
4490
- auto impl = ptr->getImplInfo ();
4491
- if (!impl.isSimpleStored ()) return ;
4492
- impl = StorageImplInfo::getSimpleStored (supportsMutation);
4493
- ptr->overwriteImplInfo (impl);
4494
- }
4495
- Bits.AbstractStorageDecl .SupportsMutation = supportsMutation;
4496
- }
4497
-
4498
4491
void computeIsValidKeyPathComponent ();
4499
4492
4500
4493
OpaqueTypeDecl *OpaqueReturn = nullptr ;
@@ -4813,45 +4806,28 @@ enum class PropertyWrapperSynthesizedPropertyKind {
4813
4806
// / VarDecl - 'var' and 'let' declarations.
4814
4807
class VarDecl : public AbstractStorageDecl {
4815
4808
public:
4816
- enum class Specifier : uint8_t {
4817
- // For Var Decls
4818
-
4809
+ enum class Introducer : uint8_t {
4819
4810
Let = 0 ,
4820
- Var = 1 ,
4821
-
4822
- // For Param Decls
4823
-
4824
- Default = Let,
4825
- InOut = 2 ,
4826
- Shared = 3 ,
4827
- Owned = 4 ,
4811
+ Var = 1
4828
4812
};
4829
4813
4830
4814
protected:
4831
4815
PointerUnion3<PatternBindingDecl *, Stmt *, VarDecl *> Parent;
4832
4816
4833
- VarDecl (DeclKind Kind, bool IsStatic, Specifier Sp, bool IsCaptureList,
4834
- SourceLoc NameLoc, Identifier Name, DeclContext *DC)
4835
- : AbstractStorageDecl(Kind, IsStatic, DC, Name, NameLoc,
4836
- StorageIsMutable_t (!isImmutableSpecifier(Sp)))
4837
- {
4838
- Bits.VarDecl .Specifier = static_cast <unsigned >(Sp);
4839
- Bits.VarDecl .IsCaptureList = IsCaptureList;
4840
- Bits.VarDecl .IsDebuggerVar = false ;
4841
- Bits.VarDecl .IsLazyStorageProperty = false ;
4842
- Bits.VarDecl .HasNonPatternBindingInit = false ;
4843
- Bits.VarDecl .IsPropertyWrapperBackingProperty = false ;
4844
- }
4817
+ VarDecl (DeclKind kind, bool isStatic, Introducer introducer,
4818
+ bool issCaptureList, SourceLoc nameLoc, Identifier name,
4819
+ DeclContext *dc, StorageIsMutable_t supportsMutation);
4845
4820
4846
4821
// / This is the type specified, including location information.
4847
4822
TypeLoc typeLoc;
4848
4823
4849
4824
Type typeInContext;
4850
4825
4851
4826
public:
4852
- VarDecl (bool IsStatic, Specifier Sp, bool IsCaptureList, SourceLoc NameLoc,
4853
- Identifier Name, DeclContext *DC)
4854
- : VarDecl(DeclKind::Var, IsStatic, Sp, IsCaptureList, NameLoc, Name, DC) {}
4827
+ VarDecl (bool isStatic, Introducer introducer, bool isCaptureList,
4828
+ SourceLoc nameLoc, Identifier name, DeclContext *dc)
4829
+ : VarDecl(DeclKind::Var, isStatic, introducer, isCaptureList, nameLoc,
4830
+ name, dc, StorageIsMutable_t(introducer == Introducer::Var)) {}
4855
4831
4856
4832
SourceRange getSourceRange () const ;
4857
4833
@@ -5025,81 +5001,19 @@ class VarDecl : public AbstractStorageDecl {
5025
5001
VarDecl *getOverriddenDecl () const {
5026
5002
return cast_or_null<VarDecl>(AbstractStorageDecl::getOverriddenDecl ());
5027
5003
}
5028
-
5029
- // / Determine whether this declaration is an anonymous closure parameter.
5030
- bool isAnonClosureParam () const ;
5031
-
5032
- // / Return the raw specifier value for this property or parameter.
5033
- Specifier getSpecifier () const {
5034
- return static_cast <Specifier>(Bits.VarDecl .Specifier );
5035
- }
5036
- void setSpecifier (Specifier Spec);
5037
-
5038
- // / Is the type of this parameter 'inout'?
5039
- // /
5040
- // / FIXME(Remove InOut): This is only valid on ParamDecls but multiple parts
5041
- // / of the compiler check ParamDecls and VarDecls along the same paths.
5042
- bool isInOut () const {
5043
- // FIXME: Re-enable this assertion and fix callers.
5044
- // assert((getKind() == DeclKind::Param) && "querying 'inout' on var decl?");
5045
- return getSpecifier () == Specifier::InOut;
5046
- }
5047
5004
5048
- bool isImmutable () const {
5049
- return isImmutableSpecifier (getSpecifier ());
5050
- }
5051
- static bool isImmutableSpecifier (Specifier sp) {
5052
- switch (sp) {
5053
- case Specifier::Let:
5054
- case Specifier::Shared:
5055
- case Specifier::Owned:
5056
- return true ;
5057
- case Specifier::Var:
5058
- case Specifier::InOut:
5059
- return false ;
5060
- }
5061
- llvm_unreachable (" unhandled specifier" );
5062
- }
5063
5005
// / Is this an immutable 'let' property?
5064
- bool isLet () const { return getSpecifier () == Specifier::Let; }
5065
- // / Is this an immutable 'shared' property?
5066
- bool isShared () const { return getSpecifier () == Specifier::Shared; }
5067
- // / Is this an immutable 'owned' property?
5068
- bool isOwned () const { return getSpecifier () == Specifier::Owned; }
5006
+ // /
5007
+ // / If this is a ParamDecl, isLet() is true iff
5008
+ // / getSpecifier() == Specifier::Default.
5009
+ bool isLet () const { return getIntroducer () == Introducer::Let; }
5069
5010
5070
- ValueOwnership getValueOwnership () const {
5071
- return getValueOwnershipForSpecifier ( getSpecifier () );
5011
+ Introducer getIntroducer () const {
5012
+ return Introducer (Bits. VarDecl . Introducer );
5072
5013
}
5073
5014
5074
- static ValueOwnership getValueOwnershipForSpecifier (Specifier specifier) {
5075
- switch (specifier) {
5076
- case Specifier::Let:
5077
- return ValueOwnership::Default;
5078
- case Specifier::Var:
5079
- return ValueOwnership::Default;
5080
- case Specifier::InOut:
5081
- return ValueOwnership::InOut;
5082
- case Specifier::Shared:
5083
- return ValueOwnership::Shared;
5084
- case Specifier::Owned:
5085
- return ValueOwnership::Owned;
5086
- }
5087
- llvm_unreachable (" unhandled specifier" );
5088
- }
5089
-
5090
- static Specifier
5091
- getParameterSpecifierForValueOwnership (ValueOwnership ownership) {
5092
- switch (ownership) {
5093
- case ValueOwnership::Default:
5094
- return Specifier::Let;
5095
- case ValueOwnership::Shared:
5096
- return Specifier::Shared;
5097
- case ValueOwnership::InOut:
5098
- return Specifier::InOut;
5099
- case ValueOwnership::Owned:
5100
- return Specifier::Owned;
5101
- }
5102
- llvm_unreachable (" unhandled ownership" );
5015
+ void setIntroducer (Introducer value) {
5016
+ Bits.VarDecl .Introducer = uint8_t (value);
5103
5017
}
5104
5018
5105
5019
// / Is this an element in a capture list?
@@ -5281,7 +5195,14 @@ class ParamDecl : public VarDecl {
5281
5195
DefaultValueAndFlags;
5282
5196
5283
5197
public:
5284
- ParamDecl (VarDecl::Specifier specifier,
5198
+ enum class Specifier : uint8_t {
5199
+ Default = 0 ,
5200
+ InOut = 1 ,
5201
+ Shared = 2 ,
5202
+ Owned = 3 ,
5203
+ };
5204
+
5205
+ ParamDecl (Specifier specifier,
5285
5206
SourceLoc specifierLoc, SourceLoc argumentNameLoc,
5286
5207
Identifier argumentName, SourceLoc parameterNameLoc,
5287
5208
Identifier parameterName, DeclContext *dc);
@@ -5400,6 +5321,70 @@ class ParamDecl : public VarDecl {
5400
5321
return getVarargBaseTy (getInterfaceType ());
5401
5322
}
5402
5323
5324
+ // / Determine whether this declaration is an anonymous closure parameter.
5325
+ bool isAnonClosureParam () const ;
5326
+
5327
+ // / Return the raw specifier value for this parameter.
5328
+ Specifier getSpecifier () const {
5329
+ return static_cast <Specifier>(Bits.ParamDecl .Specifier );
5330
+ }
5331
+ void setSpecifier (Specifier Spec);
5332
+
5333
+ // / Is the type of this parameter 'inout'?
5334
+ bool isInOut () const { return getSpecifier () == Specifier::InOut; }
5335
+ // / Is this an immutable 'shared' property?
5336
+ bool isShared () const { return getSpecifier () == Specifier::Shared; }
5337
+ // / Is this an immutable 'owned' property?
5338
+ bool isOwned () const { return getSpecifier () == Specifier::Owned; }
5339
+
5340
+ bool isImmutable () const {
5341
+ return isImmutableSpecifier (getSpecifier ());
5342
+ }
5343
+ static bool isImmutableSpecifier (Specifier sp) {
5344
+ switch (sp) {
5345
+ case Specifier::Default:
5346
+ case Specifier::Shared:
5347
+ case Specifier::Owned:
5348
+ return true ;
5349
+ case Specifier::InOut:
5350
+ return false ;
5351
+ }
5352
+ llvm_unreachable (" unhandled specifier" );
5353
+ }
5354
+
5355
+ ValueOwnership getValueOwnership () const {
5356
+ return getValueOwnershipForSpecifier (getSpecifier ());
5357
+ }
5358
+
5359
+ static ValueOwnership getValueOwnershipForSpecifier (Specifier specifier) {
5360
+ switch (specifier) {
5361
+ case Specifier::Default:
5362
+ return ValueOwnership::Default;
5363
+ case Specifier::InOut:
5364
+ return ValueOwnership::InOut;
5365
+ case Specifier::Shared:
5366
+ return ValueOwnership::Shared;
5367
+ case Specifier::Owned:
5368
+ return ValueOwnership::Owned;
5369
+ }
5370
+ llvm_unreachable (" unhandled specifier" );
5371
+ }
5372
+
5373
+ static Specifier
5374
+ getParameterSpecifierForValueOwnership (ValueOwnership ownership) {
5375
+ switch (ownership) {
5376
+ case ValueOwnership::Default:
5377
+ return Specifier::Default;
5378
+ case ValueOwnership::Shared:
5379
+ return Specifier::Shared;
5380
+ case ValueOwnership::InOut:
5381
+ return Specifier::InOut;
5382
+ case ValueOwnership::Owned:
5383
+ return Specifier::Owned;
5384
+ }
5385
+ llvm_unreachable (" unhandled ownership" );
5386
+ }
5387
+
5403
5388
SourceRange getSourceRange () const ;
5404
5389
5405
5390
AnyFunctionType::Param toFunctionParam (Type type = Type()) const ;
0 commit comments