Skip to content

[5.9] [Macros] "Subsume" the initializer when an accessor macros adds non-observing accessors #65502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

DougGregor
Copy link
Member

  • Explanation: When an accessor macro adds a non-observing accessor to a property, it subsumes the initializer. Model this using the same scheme as when a property wrapper subsumes the initializer of a stored property when it turns it into a computed property. This eliminates a problem where applying an accessor macro to a stored property was preventing inference of the property type from an initializer, the prior fix for which had introduced cyclic references. This property modeling addresses both issues at once.
  • Scope: Affects the handling of stored property initializers with accessor macros.
  • Risk: Low, leverages existing handling of subsumed initializers (from property wrappers) for accessor macros.
  • Issue: rdar://108565923
  • Original pull request: [Macros] "Subsume" the initializer when an accessor macros adds non-observing accessors #65501

…add accessors"

This reverts commit ef7970b. We
shouldn't need this.
…bservers

When an accessor macro adds a non-observing accessor to a property, it
subsumes the initializer. We had previously modeled this as removing
the initializer, but doing so means that the initializer could not be
used for type inference and was lost in the AST.

Explicitly mark the initializer as "subsumed" here, and be more
careful when querying the initializer to distinguish between "the
initializer that was written" and "the initializer that will execute"
in more places. This distinction already existed at the
pattern-binding level, but not at the variable-declaration level.

This is the proper fix for the circular reference issue described in
rdar://108565923 (test case in the prior commit).
@DougGregor DougGregor requested a review from a team as a code owner April 28, 2023 17:15
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit 554cce9 into swiftlang:release/5.9 Apr 28, 2023
@DougGregor DougGregor deleted the accessor-macro-subsume-init-5.9 branch April 28, 2023 22:56
@AnthonyLatsis AnthonyLatsis added the 🍒 release cherry pick Flag: Release branch cherry picks label May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🍒 release cherry pick Flag: Release branch cherry picks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants