@@ -4470,12 +4470,9 @@ struct Parser::ParsedAccessors {
4470
4470
#include " swift/AST/AccessorKinds.def"
4471
4471
4472
4472
void record (Parser &P, AbstractStorageDecl *storage, bool invalid,
4473
- const DeclAttributes &attrs,
4474
4473
SmallVectorImpl<Decl *> &decls);
4475
4474
4476
- StorageImplInfo
4477
- classify (Parser &P, AbstractStorageDecl *storage, bool invalid,
4478
- const DeclAttributes &attrs);
4475
+ void classify (Parser &P, AbstractStorageDecl *storage, bool invalid);
4479
4476
4480
4477
// / Add an accessor. If there's an existing accessor of this kind,
4481
4478
// / return it. The new accessor is still remembered but will be
@@ -4908,7 +4905,7 @@ Parser::parseDeclVarGetSet(Pattern *pattern, ParseDeclOptions Flags,
4908
4905
accessors.Set ->setInvalid ();
4909
4906
}
4910
4907
4911
- accessors.record (*this , PrimaryVar, Invalid, Attributes, Decls);
4908
+ accessors.record (*this , PrimaryVar, Invalid, Decls);
4912
4909
4913
4910
return makeParserResult (PrimaryVar);
4914
4911
}
@@ -4936,10 +4933,8 @@ AccessorDecl *Parser::ParsedAccessors::add(AccessorDecl *accessor) {
4936
4933
// / Record a bunch of parsed accessors into the given abstract storage decl.
4937
4934
void Parser::ParsedAccessors::record (Parser &P, AbstractStorageDecl *storage,
4938
4935
bool invalid,
4939
- const DeclAttributes &attrs,
4940
4936
SmallVectorImpl<Decl *> &decls) {
4941
- auto storageKind = classify (P, storage, invalid, attrs);
4942
- storage->setImplInfo (storageKind);
4937
+ classify (P, storage, invalid);
4943
4938
4944
4939
decls.append (Accessors.begin (), Accessors.end ());
4945
4940
storage->setAccessors (LBLoc, Accessors, RBLoc);
@@ -4979,53 +4974,8 @@ static void diagnoseAndIgnoreObservers(Parser &P,
4979
4974
}
4980
4975
}
4981
4976
4982
- // / Gets the storage info of the provided storage decl if it has the
4983
- // / @_hasStorage attribute and it's not in SIL mode.
4984
- // /
4985
- // / In this case, we say the decl is:
4986
- // /
4987
- // / Read:
4988
- // / - Stored, always
4989
- // / Write:
4990
- // / - Stored, if the decl is a 'var'.
4991
- // / - StoredWithObservers, if the decl has a setter
4992
- // / - This indicates that the original decl had a 'didSet' and/or 'willSet'
4993
- // / - InheritedWithObservers, if the decl has a setter and is an overridde.
4994
- // / - Immutable, if the decl is a 'let' or it does not have a setter.
4995
- // / ReadWrite:
4996
- // / - Stored, if the decl has no accessors listed.
4997
- // / - Immutable, if the decl is a 'let' or it does not have a setter.
4998
- // / - MaterializeToTemporary, if the decl has a setter.
4999
- static StorageImplInfo classifyWithHasStorageAttr (
5000
- Parser::ParsedAccessors &accessors, ASTContext &ctx,
5001
- VarDecl *var, const DeclAttributes &attrs) {
5002
-
5003
- WriteImplKind writeImpl;
5004
- ReadWriteImplKind readWriteImpl;
5005
-
5006
- if (accessors.Get && accessors.Set ) {
5007
- // If we see `@_hasStorage var x: T { get set }`, then our property has
5008
- // willSet/didSet observers.
5009
- writeImpl = attrs.hasAttribute <OverrideAttr>() ?
5010
- WriteImplKind::InheritedWithObservers :
5011
- WriteImplKind::StoredWithObservers;
5012
- readWriteImpl = ReadWriteImplKind::MaterializeToTemporary;
5013
- } else if (var->isLet ()) {
5014
- writeImpl = WriteImplKind::Immutable;
5015
- readWriteImpl = ReadWriteImplKind::Immutable;
5016
- } else {
5017
- // Default to stored writes.
5018
- writeImpl = WriteImplKind::Stored;
5019
- readWriteImpl = ReadWriteImplKind::Stored;
5020
- }
5021
-
5022
- // Always force Stored reads if @_hasStorage is present.
5023
- return StorageImplInfo (ReadImplKind::Stored, writeImpl, readWriteImpl);
5024
- }
5025
-
5026
- StorageImplInfo
5027
- Parser::ParsedAccessors::classify (Parser &P, AbstractStorageDecl *storage,
5028
- bool invalid, const DeclAttributes &attrs) {
4977
+ void Parser::ParsedAccessors::classify (Parser &P, AbstractStorageDecl *storage,
4978
+ bool invalid) {
5029
4979
// If there was a problem parsing accessors, mark all parsed accessors
5030
4980
// as invalid to avoid tripping up later invariants.
5031
4981
// We also want to avoid diagnose missing accessors if something
@@ -5092,102 +5042,6 @@ Parser::ParsedAccessors::classify(Parser &P, AbstractStorageDecl *storage,
5092
5042
} else if (Modify) {
5093
5043
diagnoseConflictingAccessors (P, Modify, MutableAddress);
5094
5044
}
5095
-
5096
- if (auto *var = dyn_cast<VarDecl>(storage)) {
5097
- // Allow the @_hasStorage attribute to override all the accessors we parsed
5098
- // when making the final classification.
5099
- if (attrs.hasAttribute <HasStorageAttr>()) {
5100
- // The SIL rules for @_hasStorage are slightly different from the non-SIL
5101
- // rules. In SIL mode, @_hasStorage marks that the type is simply stored,
5102
- // and the only thing that determines mutability is the existence of the
5103
- // setter.
5104
- //
5105
- // FIXME: SIL should not be special cased here. The behavior should be
5106
- // consistent between SIL and non-SIL.
5107
- // The strategy here should be to keep track of all opaque accessors
5108
- // along with enough information to access the storage trivially
5109
- // if allowed. This could be a representational change to
5110
- // StorageImplInfo such that it keeps a bitset of listed accessors
5111
- // and dynamically determines the access strategy from that.
5112
- if (P.isInSILMode ())
5113
- return StorageImplInfo::getSimpleStored (
5114
- StorageIsMutable_t (Set != nullptr ));
5115
-
5116
- return classifyWithHasStorageAttr (*this , P.Context , var, attrs);
5117
- }
5118
- }
5119
-
5120
- // 'get', 'read', and a non-mutable addressor are all exclusive.
5121
- ReadImplKind readImpl;
5122
- if (Get) {
5123
- readImpl = ReadImplKind::Get;
5124
- } else if (Read) {
5125
- readImpl = ReadImplKind::Read;
5126
- } else if (Address) {
5127
- readImpl = ReadImplKind::Address;
5128
-
5129
- // If there's a writing accessor of any sort, there must also be a
5130
- // reading accessor.
5131
- } else if (auto mutator = findFirstMutator ()) {
5132
- readImpl = ReadImplKind::Get;
5133
-
5134
- // Subscripts always have to have some sort of accessor; they can't be
5135
- // purely stored.
5136
- } else if (isa<SubscriptDecl>(storage)) {
5137
- readImpl = ReadImplKind::Get;
5138
-
5139
- // Check if we have observers.
5140
- } else if (WillSet || DidSet) {
5141
- if (attrs.hasAttribute <OverrideAttr>()) {
5142
- readImpl = ReadImplKind::Inherited;
5143
- } else {
5144
- readImpl = ReadImplKind::Stored;
5145
- }
5146
-
5147
- // Otherwise, it's stored.
5148
- } else {
5149
- readImpl = ReadImplKind::Stored;
5150
- }
5151
-
5152
- // Prefer using 'set' and 'modify' over a mutable addressor.
5153
- WriteImplKind writeImpl;
5154
- ReadWriteImplKind readWriteImpl;
5155
- if (Set) {
5156
- writeImpl = WriteImplKind::Set;
5157
- if (Modify) {
5158
- readWriteImpl = ReadWriteImplKind::Modify;
5159
- } else {
5160
- readWriteImpl = ReadWriteImplKind::MaterializeToTemporary;
5161
- }
5162
- } else if (Modify) {
5163
- writeImpl = WriteImplKind::Modify;
5164
- readWriteImpl = ReadWriteImplKind::Modify;
5165
- } else if (MutableAddress) {
5166
- writeImpl = WriteImplKind::MutableAddress;
5167
- readWriteImpl = ReadWriteImplKind::MutableAddress;
5168
-
5169
- // Check if we have observers.
5170
- } else if (readImpl == ReadImplKind::Inherited) {
5171
- writeImpl = WriteImplKind::InheritedWithObservers;
5172
- readWriteImpl = ReadWriteImplKind::MaterializeToTemporary;
5173
-
5174
- // Otherwise, it's stored.
5175
- } else if (readImpl == ReadImplKind::Stored) {
5176
- if (WillSet || DidSet) {
5177
- writeImpl = WriteImplKind::StoredWithObservers;
5178
- readWriteImpl = ReadWriteImplKind::MaterializeToTemporary;
5179
- } else {
5180
- writeImpl = WriteImplKind::Stored;
5181
- readWriteImpl = ReadWriteImplKind::Stored;
5182
- }
5183
-
5184
- // Otherwise, it's immutable.
5185
- } else {
5186
- writeImpl = WriteImplKind::Immutable;
5187
- readWriteImpl = ReadWriteImplKind::Immutable;
5188
- }
5189
-
5190
- return StorageImplInfo (readImpl, writeImpl, readWriteImpl);
5191
5045
}
5192
5046
5193
5047
@@ -6598,8 +6452,7 @@ Parser::parseDeclSubscript(SourceLoc StaticLoc,
6598
6452
Invalid = true ;
6599
6453
}
6600
6454
6601
- accessors.record (*this , Subscript, (Invalid || !Status.isSuccess ()),
6602
- Attributes, Decls);
6455
+ accessors.record (*this , Subscript, (Invalid || !Status.isSuccess ()), Decls);
6603
6456
6604
6457
// No need to setLocalDiscriminator because subscripts cannot
6605
6458
// validly appear outside of type decls.
0 commit comments