Skip to content

[5.3] Allow initializing a wrapped property with a nonmutating setter #31460

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
merged 1 commit into from
May 1, 2020

Conversation

artemcm
Copy link
Contributor

@artemcm artemcm commented May 1, 2020

Cherry-pick #31161 into release/5.3, originally reviewed by @slavapestov

The title is achieved in 3 steps:

  • CSApply detects assignments to property wrappers inside constructors, and produces an inout expr instead of a load, which it normally would because nonmutating setters take the self by-value. This is necessary because the assign_by_wrapper instruction expects an address type for its $1 operand.
  • SILGenLValue now emits the assign_by_wrapper pattern for such setters, ignoring the fact that they capture self by value. It also introduces an additional load instruction for the setter patrial_apply because the setter signature still expects a value and we now have an address (because of (1)).
  • DefiniteInitialization ignores specifically load instructions used to produce a self value for a setter referenced on assign_by_wrapper because it will be deleted by lowering anyway.

This is achieved in 3 steps:

- CSApply detects assignments to property wrappers inside constructors, and produces an inout expr instead of a load, which it normally would because nonmutating setters take the self by-value. This is necessary becasue the assign_by_wrapper instruction expects an address type for its $1 operand.
- SILGenLValue now emits the assign_by_wrapper pattern for such setters, ignoring the fact that they capture `self` by value. It also introduces an additional load instruction for the setter patrial_apply because the setter signature still expects a value and we now have an address (because of (1)).
- DefiniteInitialization ignores specifically load instructions used to produce a `self` value for a setter referenced on assign_by_wrapper because it will be deleted by lowering anyway.
@artemcm artemcm requested review from slavapestov and DougGregor May 1, 2020 01:14
@artemcm
Copy link
Contributor Author

artemcm commented May 1, 2020

@swift-ci test

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2020

Build failed
Swift Test Linux Platform
Git Sha - 46775cc

@theblixguy theblixguy added the r5.3 label May 1, 2020
@artemcm
Copy link
Contributor Author

artemcm commented May 1, 2020

@swift-ci Please test Linux platform

@artemcm artemcm merged commit 60f7aa2 into swiftlang:release/5.3 May 1, 2020
@AnthonyLatsis AnthonyLatsis added swift 5.3 🍒 release cherry pick Flag: Release branch cherry picks labels Jan 8, 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 swift 5.3
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants