@@ -946,56 +946,44 @@ static bool contextAllowsPatternBindingWithoutVariables(DeclContext *dc) {
946
946
return true ;
947
947
}
948
948
949
- static VarDecl *getStoredPropertyFor (VarDecl *var) {
950
- if (var->isStatic ())
951
- return nullptr ;
952
-
953
- if (var->isLazyStorageProperty ())
954
- return nullptr ;
949
+ static bool hasStoredProperties (NominalTypeDecl *decl) {
950
+ return (isa<StructDecl>(decl) ||
951
+ (isa<ClassDecl>(decl) && !decl->hasClangNode ()));
952
+ }
955
953
956
- if (var->getOriginalWrappedProperty ())
957
- return nullptr ;
954
+ static void computeLoweredStoredProperties (NominalTypeDecl *decl) {
955
+ // Just walk over the members of the type, forcing backing storage
956
+ // for lazy properties and property wrappers to be synthesized.
957
+ for (auto *member : decl->getMembers ()) {
958
+ auto *var = dyn_cast<VarDecl>(member);
959
+ if (!var || var->isStatic ())
960
+ continue ;
958
961
959
- if (var->getAttrs ().hasAttribute <LazyAttr>()) {
960
- if (auto *storage = var->getLazyStorageProperty ()) {
961
- assert (storage->hasStorage ());
962
- return storage;
963
- }
962
+ if (var->getAttrs ().hasAttribute <LazyAttr>())
963
+ (void ) var->getLazyStorageProperty ();
964
964
965
- return nullptr ;
965
+ if (var->hasAttachedPropertyWrapper ())
966
+ (void ) var->getPropertyWrapperBackingProperty ();
966
967
}
967
-
968
- if (var->hasAttachedPropertyWrapper ()) {
969
- if (auto *storage = var->getPropertyWrapperBackingProperty ()) {
970
- assert (storage->hasStorage ());
971
- return storage;
972
- }
973
-
974
- return nullptr ;
975
- }
976
-
977
- if (var->getAttrs ().hasAttribute <NSManagedAttr>())
978
- return nullptr ;
979
-
980
- if (!var->hasStorage ())
981
- return nullptr ;
982
-
983
- return var;
984
968
}
985
969
986
970
llvm::Expected<ArrayRef<VarDecl *>>
987
971
StoredPropertiesRequest::evaluate (Evaluator &evaluator,
988
972
NominalTypeDecl *decl) const {
989
- if (isa<EnumDecl>(decl) ||
990
- isa<ProtocolDecl>(decl) ||
991
- (isa<ClassDecl>(decl) && decl->hasClangNode ()))
973
+ if (!hasStoredProperties (decl))
992
974
return ArrayRef<VarDecl *>();
993
975
994
976
SmallVector<VarDecl *, 4 > results;
977
+
978
+ // Unless we're in a source file we don't have to do anything
979
+ // special to lower lazy properties and property wrappers.
980
+ if (isa<SourceFile>(decl->getModuleScopeContext ()))
981
+ computeLoweredStoredProperties (decl);
982
+
995
983
for (auto *member : decl->getMembers ()) {
996
984
if (auto *var = dyn_cast<VarDecl>(member))
997
- if (auto *storage = getStoredPropertyFor ( var))
998
- results.push_back (storage );
985
+ if (!var-> isStatic () && var-> hasStorage ( ))
986
+ results.push_back (var );
999
987
}
1000
988
1001
989
return decl->getASTContext ().AllocateCopy (results);
@@ -1004,16 +992,20 @@ StoredPropertiesRequest::evaluate(Evaluator &evaluator,
1004
992
llvm::Expected<ArrayRef<Decl *>>
1005
993
StoredPropertiesAndMissingMembersRequest::evaluate (Evaluator &evaluator,
1006
994
NominalTypeDecl *decl) const {
1007
- if (isa<EnumDecl>(decl) ||
1008
- isa<ProtocolDecl>(decl) ||
1009
- (isa<ClassDecl>(decl) && decl->hasClangNode ()))
995
+ if (!hasStoredProperties (decl))
1010
996
return ArrayRef<Decl *>();
1011
997
1012
998
SmallVector<Decl *, 4 > results;
999
+
1000
+ // Unless we're in a source file we don't have to do anything
1001
+ // special to lower lazy properties and property wrappers.
1002
+ if (isa<SourceFile>(decl->getModuleScopeContext ()))
1003
+ computeLoweredStoredProperties (decl);
1004
+
1013
1005
for (auto *member : decl->getMembers ()) {
1014
1006
if (auto *var = dyn_cast<VarDecl>(member))
1015
- if (auto *storage = getStoredPropertyFor ( var))
1016
- results.push_back (storage );
1007
+ if (!var-> isStatic () && var-> hasStorage ( ))
1008
+ results.push_back (var );
1017
1009
1018
1010
if (auto missing = dyn_cast<MissingMemberDecl>(member))
1019
1011
if (missing->getNumberOfFieldOffsetVectorEntries () > 0 )
0 commit comments