@@ -273,6 +273,15 @@ static_assert(uint8_t(SelfAccessKind::LastSelfAccessKind) <
273273 " Self Access Kind is too small to fit in SelfAccess kind bits. "
274274 " Please expand " );
275275
276+ enum class MemberwiseInitKind {
277+ // / The regular memberwise initializer.
278+ Regular,
279+ // / A compatibility memberwise initializer that includes all private
280+ // / initialized variables. This only exists for migration purposes, and will
281+ // / be removed in a future language mode.
282+ Compatibility
283+ };
284+
276285enum class UsingSpecifier : uint8_t {
277286 MainActor,
278287 Nonisolated,
@@ -4634,9 +4643,10 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
46344643 ArrayRef<VarDecl *> getInitAccessorProperties () const ;
46354644
46364645 // / Return a collection of all properties that will be part of the memberwise
4637- // / initializer.
4638- ArrayRef<VarDecl *> getMemberwiseInitProperties () const ;
4639-
4646+ // / initializer.
4647+ ArrayRef<VarDecl *>
4648+ getMemberwiseInitProperties (MemberwiseInitKind initKind) const ;
4649+
46404650 // / Establish a mapping between properties that could be iniitalized
46414651 // / via other properties by means of init accessors. This mapping is
46424652 // / one-to-many because we allow intersecting `initializes(...)`.
@@ -4679,11 +4689,11 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
46794689 }
46804690
46814691 // / Whether this declaration has a synthesized memberwise initializer.
4682- bool hasMemberwiseInitializer () const ;
4692+ bool hasMemberwiseInitializer (MemberwiseInitKind initKind ) const ;
46834693
46844694 // / Retrieves the synthesized memberwise initializer for this declaration,
46854695 // / or \c nullptr if it does not have one.
4686- ConstructorDecl *getMemberwiseInitializer () const ;
4696+ ConstructorDecl *getMemberwiseInitializer (MemberwiseInitKind initKind ) const ;
46874697
46884698 // / Retrieves the effective memberwise initializer for this declaration, or
46894699 // / \c nullptr if it does not have one.
@@ -6781,9 +6791,14 @@ class VarDecl : public AbstractStorageDecl {
67816791 bool isLazyStorageProperty () const {
67826792 return Bits.VarDecl .IsLazyStorageProperty ;
67836793 }
6784- void setLazyStorageProperty (bool IsLazyStorage) {
6785- Bits.VarDecl .IsLazyStorageProperty = IsLazyStorage;
6786- }
6794+
6795+ // / Mark this VarDecl as backing storage for a the lazy variable `VD`.
6796+ void setLazyStorageFor (VarDecl *VD);
6797+
6798+ // / For a backing storage variable for either a property wrapper or `lazy`
6799+ // / variable, retrieves the original declared variable. Otherwise returns
6800+ // / \c nullptr.
6801+ VarDecl *getOriginalVarForBackingStorage () const ;
67876802
67886803 // / Retrieve the backing storage property for a lazy property.
67896804 VarDecl *getLazyStorageProperty () const ;
@@ -6962,7 +6977,9 @@ class VarDecl : public AbstractStorageDecl {
69626977 // / actual declared property (which may or may not be considered "stored"
69636978 // / as the moment) to the backing storage property. Otherwise, the stored
69646979 // / backing property will be treated as the member-initialized property.
6965- bool isMemberwiseInitialized (bool preferDeclaredProperties) const ;
6980+ bool isMemberwiseInitialized (
6981+ MemberwiseInitKind initKind, bool preferDeclaredProperties,
6982+ std::optional<AccessLevel> minAccess = std::nullopt ) const ;
69666983
69676984 // / Return the range of semantics attributes attached to this VarDecl.
69686985 auto getSemanticsAttrs () const
@@ -7723,6 +7740,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
77237740 enum class SILSynthesizeKind {
77247741 None,
77257742 MemberwiseInitializer,
7743+ CompatibilityMemberwiseInitializer,
77267744 DistributedActorFactory
77277745
77287746 // This enum currently needs to fit in a 2-bit bitfield.
@@ -8095,11 +8113,19 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
80958113
80968114 // / Note that this is a memberwise initializer and thus the body will be
80978115 // / generated by SILGen.
8098- void setIsMemberwiseInitializer () {
8116+ void setIsMemberwiseInitializer (MemberwiseInitKind initKind ) {
80998117 assert (getBodyKind () == BodyKind::None);
81008118 assert (isa<ConstructorDecl>(this ));
81018119 setBodyKind (BodyKind::SILSynthesize);
8102- setSILSynthesizeKind (SILSynthesizeKind::MemberwiseInitializer);
8120+ switch (initKind) {
8121+ case MemberwiseInitKind::Regular:
8122+ setSILSynthesizeKind (SILSynthesizeKind::MemberwiseInitializer);
8123+ break ;
8124+ case MemberwiseInitKind::Compatibility:
8125+ setSILSynthesizeKind (
8126+ SILSynthesizeKind::CompatibilityMemberwiseInitializer);
8127+ break ;
8128+ }
81038129 }
81048130
81058131 // / Mark that the body should be filled in to be a factory method for creating
@@ -8135,9 +8161,20 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
81358161 // / typechecking.
81368162 bool isBodySkipped () const ;
81378163
8138- bool isMemberwiseInitializer () const {
8139- return getBodyKind () == BodyKind::SILSynthesize
8140- && getSILSynthesizeKind () == SILSynthesizeKind::MemberwiseInitializer;
8164+ // / Checks whether this is a memberwise initializer decl, and if so the kind,
8165+ // / otherwise \c std::nullopt.
8166+ std::optional<MemberwiseInitKind> isMemberwiseInitializer () const {
8167+ if (getBodyKind () != BodyKind::SILSynthesize)
8168+ return std::nullopt ;
8169+
8170+ switch (getSILSynthesizeKind ()) {
8171+ case SILSynthesizeKind::MemberwiseInitializer:
8172+ return MemberwiseInitKind::Regular;
8173+ case SILSynthesizeKind::CompatibilityMemberwiseInitializer:
8174+ return MemberwiseInitKind::Compatibility;
8175+ default :
8176+ return std::nullopt ;
8177+ }
81418178 }
81428179
81438180 // / Determines whether this function represents a distributed actor
@@ -10191,6 +10228,23 @@ getAccessorNameForDiagnostic(AccessorDecl *accessor, bool article,
1019110228StringRef getAccessorNameForDiagnostic (AccessorKind accessorKind, bool article,
1019210229 bool underscored);
1019310230
10231+ inline void simple_display (llvm::raw_ostream &out,
10232+ MemberwiseInitKind initKind) {
10233+ switch (initKind) {
10234+ case MemberwiseInitKind::Regular:
10235+ out << " regular" ;
10236+ break ;
10237+ case MemberwiseInitKind::Compatibility:
10238+ out << " compatibility" ;
10239+ break ;
10240+ }
10241+ }
10242+
10243+ // / Retrieve a textual representation for a particular kind of memberwise
10244+ // / initializer in a given nominal decl.
10245+ void printMemberwiseInit (NominalTypeDecl *nominal, MemberwiseInitKind initKind,
10246+ llvm::raw_ostream &out);
10247+
1019410248void simple_display (llvm::raw_ostream &out,
1019510249 OptionSet<NominalTypeDecl::LookupDirectFlags> options);
1019610250
0 commit comments