@@ -519,9 +519,9 @@ struct ASTContext::Implementation {
519519 // / Mapping from property declarations to the backing variable types.
520520 llvm::DenseMap<const VarDecl *, Type> PropertyWrapperBackingVarTypes;
521521
522- // / A mapping from the backing storage of a property that has a wrapper
523- // / to the original property with the wrapper .
524- llvm::DenseMap<const VarDecl *, VarDecl *> OriginalWrappedProperties ;
522+ // / A mapping from the backing storage of a property that has a wrapper or
523+ // / is `lazy` to the original property.
524+ llvm::DenseMap<const VarDecl *, VarDecl *> OriginalVarsForBackingStorage ;
525525
526526 // / The builtin initializer witness for a literal. Used when building
527527 // / LiteralExprs in fully-checked AST.
@@ -917,7 +917,7 @@ void ASTContext::Implementation::dump(llvm::raw_ostream &os) const {
917917 SIZE_AND_BYTES (DefaultAssociatedConformanceWitnesses);
918918 SIZE_AND_BYTES (DefaultTypeRequestCaches);
919919 SIZE_AND_BYTES (PropertyWrapperBackingVarTypes);
920- SIZE_AND_BYTES (OriginalWrappedProperties );
920+ SIZE_AND_BYTES (OriginalVarsForBackingStorage );
921921 SIZE_AND_BYTES (BuiltinInitWitness);
922922 SIZE_AND_BYTES (OriginalBodySourceRanges);
923923 SIZE_AND_BYTES (NextMacroDiscriminator);
@@ -7066,9 +7066,8 @@ VarDecl *VarDecl::getOriginalWrappedProperty(
70667066 if (!Bits.VarDecl .IsPropertyWrapperBackingProperty )
70677067 return nullptr ;
70687068
7069- ASTContext &ctx = getASTContext ();
7070- assert (ctx.getImpl ().OriginalWrappedProperties .count (this ) > 0 );
7071- auto original = ctx.getImpl ().OriginalWrappedProperties [this ];
7069+ auto *original = getOriginalVarForBackingStorage ();
7070+ ASSERT (original);
70727071 if (!kind)
70737072 return original;
70747073
@@ -7086,8 +7085,24 @@ VarDecl *VarDecl::getOriginalWrappedProperty(
70867085void VarDecl::setOriginalWrappedProperty (VarDecl *originalProperty) {
70877086 Bits.VarDecl .IsPropertyWrapperBackingProperty = true ;
70887087 ASTContext &ctx = getASTContext ();
7089- assert (ctx.getImpl ().OriginalWrappedProperties .count (this ) == 0 );
7090- ctx.getImpl ().OriginalWrappedProperties [this ] = originalProperty;
7088+ assert (ctx.getImpl ().OriginalVarsForBackingStorage .count (this ) == 0 );
7089+ ctx.getImpl ().OriginalVarsForBackingStorage [this ] = originalProperty;
7090+ }
7091+
7092+ void VarDecl::setLazyStorageFor (VarDecl *VD) {
7093+ Bits.VarDecl .IsLazyStorageProperty = true ;
7094+ ASTContext &ctx = getASTContext ();
7095+ ASSERT (ctx.getImpl ().OriginalVarsForBackingStorage .count (this ) == 0 );
7096+ ctx.getImpl ().OriginalVarsForBackingStorage [this ] = VD;
7097+ }
7098+
7099+ VarDecl *VarDecl::getOriginalVarForBackingStorage () const {
7100+ const auto &map = getASTContext ().getImpl ().OriginalVarsForBackingStorage ;
7101+ auto iter = map.find (this );
7102+ if (iter == map.end ())
7103+ return nullptr ;
7104+
7105+ return iter->second ;
70917106}
70927107
70937108#ifndef NDEBUG
0 commit comments