Skip to content

[Concurrency] memberAccessHasSpecialPermissionInSwift5 should treat… #70555

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 2 commits into from
Feb 13, 2024

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Dec 20, 2023

… init accessors as stored properties

Init accessor properties cannot escape self and are only
allowed to initialized and access a set of properties declared
in their @storageRestrictions(...) attribute.

Resolves: #70550

@xedin
Copy link
Contributor Author

xedin commented Dec 20, 2023

@kavon I'd appreciate if you could help me come up with an example that should warn. I looked at the FlowIsolation path and it's ran after assign_or_init is expanded into individual accesses to underlying stored properties and/or setter/getter calls.

@KeithBauerANZ
Copy link

probably should test both initializes: and accesses:? The example from #70550 only has initializes: and it's not completely obvious to me that the rules should be the same?

@xedin
Copy link
Contributor Author

xedin commented Dec 20, 2023

Based on my read of FlowIsolation it doesn't matter what kind of access is performed inside, it tracks references.

Comment on lines +752 to +759
init(radians: Double) {
self.radians = radians // Ok
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some suggestions for other things to test for:

  1. What happens if you init radians, escape self from the initializer, and then try to access radians again?
  2. Same as above but if radians is a nonisolated property.
  3. What happens if you try to escape self prior to radians being initialized?

I assume that for all of these, they should work the same as a computed property (which is hopefully already tested). Only (3) is one that is really to ensure FlowIsolation doesn't crash, since it should already get flagged as an error by DI prior.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise if those are working, then this PR LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kavon I had to make some changes to FlowIsolation pass to recognize setter use of init accessor properties. That cannot be done earlier because only DI knows when to use init accessor and when to use a setter for a particular property.

@xedin
Copy link
Contributor Author

xedin commented Feb 1, 2024

@swift-ci please test

xedin added 2 commits February 7, 2024 09:30
… init accessors as stored properties

Init accessor properties cannot escape self and are only allowed
to initialized and access a set of properties declared in their
`@storageRestrictions(...)` attribute.

Resolves: swiftlang#70550
… accessor properties

Init accessor properties should be handled specifically because
they do not reference underlying storage directly via `ref_element_addr`
instructions when 'self' is fully initialized.
@xedin
Copy link
Contributor Author

xedin commented Feb 7, 2024

@swift-ci please test

Comment on lines +766 to +769
escapingSelf(self)

self.radians = 0
// expected-warning@-1 {{actor-isolated property 'radians' can not be mutated from a non-isolated context; this is an error in Swift 6}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏼

@xedin
Copy link
Contributor Author

xedin commented Feb 12, 2024

@swift-ci please smoke test macOS platform

@xedin xedin merged commit 1e1564e into swiftlang:main Feb 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"init accessors" don't work with actors
3 participants