Skip to content

[5.5] Restrict uses of 'self' in actor initializers #38043

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
Jun 25, 2021

Conversation

kavon
Copy link
Member

@kavon kavon commented Jun 23, 2021

Explanation: Actor initializers permit races due to unrestricted use of 'self', and this radar plugs that hole by rejecting unsafe uses of 'self'.
Risk: Low. Any developers that have written non-trivial code in an actor's initializer will be affected by a source break. This primarily would be early adopters of actors, and will not affect any uses of @mainactor.
Original PRs: #37075 and #38096
Radar/SR Issue: rdar://78790369
Reviewed By: Konrad Malawski
Testing: Regression tests are included

@kavon kavon added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. r5.5 concurrency Feature: umbrella label for concurrency language features labels Jun 23, 2021
@kavon kavon marked this pull request as ready for review June 23, 2021 00:33
@kavon kavon requested a review from a team as a code owner June 23, 2021 00:33
@kavon
Copy link
Member Author

kavon commented Jun 23, 2021

@swift-ci please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - e887f5cda73cdc24511224a874d4604cc37f8d7f

A uniqueness rule for 'self' is enforced throughout
the following types of actor initializers:

1. synchronous
2. global-actor isolated

This means that 'self' cannot be used for anything,
even after 'self' is fully initialized, other than
for access to stored properties. Method calls are
considered escaping uses of 'self', since it is passed
implicitly to the method of computed property when invoked.

Also, an actor's convenience init now treats self as
nonisolated.

This provides a way to perform follow-up work after
self is fully initialized, when creating the
actor from a synchronous context.

Resolves rdar://78790369
@kavon kavon force-pushed the 5.5-restricted-self-actorinit branch from e887f5c to 2e61dfe Compare June 23, 2021 21:30
@kavon
Copy link
Member Author

kavon commented Jun 23, 2021

@swift-ci please test

This is a follow-up to the changes that restrict
uses of 'self' in certain actor initializers, to
guide people to using the convenience inits for
now.
@kavon
Copy link
Member Author

kavon commented Jun 25, 2021

@swift-ci please test

@kavon
Copy link
Member Author

kavon commented Jun 25, 2021

@swift-ci nominate

@DougGregor DougGregor merged commit 50c9826 into swiftlang:release/5.5 Jun 25, 2021
@AnthonyLatsis AnthonyLatsis added 🍒 release cherry pick Flag: Release branch cherry picks swift 5.5 labels Jan 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. concurrency Feature: umbrella label for concurrency language features 🍒 release cherry pick Flag: Release branch cherry picks swift 5.5
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants