-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add a proposal to allow nonisolated
to prevent global actor inference.
#2560
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
Add a proposal to allow nonisolated
to prevent global actor inference.
#2560
Conversation
d2f223f
to
e09f2d6
Compare
e09f2d6
to
968e64c
Compare
The first code snippet has some non-correct code that would not compile. It's showcasing the bad workaround, but still, it should be compiling code :)
Fix some code snippets in NNNN-nonisolated-for-global-actor-cutoff.md
cc2f805
to
30d8859
Compare
30d8859
to
2514d13
Compare
I had a hard time understanding rules 3 and 4 because they don't really seem to be related to global actor isolation at all even though that's the framing of the document. I also don't really see those rules discussed in the motivation section nor mentioned in the proposed solution section, unless I'm totally missing something? |
@Jumhyn good point! I can restructure the proposal a bit to make it clear that while these rules are not strictly related to global actor cut-off, they still enable |
…of the proposal.
@simanerush Thanks, I think that restructuring reads a lot better!! I might even argue for dropping any mention of global actors from the document title as well, since I think that sets the stage wrong. But also I see how perhaps the global actor bits are the 'primary' focus and the other parts are more ancillary. |
|
||
```swift | ||
class MyClass { | ||
nonisolated var x: NonSendable = NonSendable() // okay |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this simply introducing a new explicit spelling of existing default behavior? In other words, is this snippet exactly equivalent to the following?
class MyClass {
var x: NonSendable = NonSendable()
}
It might be helpful to show the two snippets side-by-side to emphasize that this isn't adding new functionality, but merely making it possible to write it explicitly.
Do you have any motivating use cases for when someone would want to spell it explicitly that you could add here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think the main goal here is to allow expressing the default behavior for consistency. I don't think I have a motivating use case here, since it's more about a personal preference of the programmer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the recent changes! I'll be scheduling the review shortly.
This proposal allows annotating a set of declarations with
nonisolated
to prevent global actor inference.Read full proposal...