Skip to content

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

Merged

Conversation

simanerush
Copy link
Member

This proposal allows annotating a set of declarations with nonisolated to prevent global actor inference.

Read full proposal...

@simanerush simanerush force-pushed the nonisolated-for-global-actor-cutoff branch from e09f2d6 to 968e64c Compare September 11, 2024 00:38
ktoso and others added 2 commits September 11, 2024 10:55
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
@simanerush simanerush force-pushed the nonisolated-for-global-actor-cutoff branch from cc2f805 to 30d8859 Compare September 11, 2024 04:03
@simanerush simanerush force-pushed the nonisolated-for-global-actor-cutoff branch from 30d8859 to 2514d13 Compare September 11, 2024 04:38
@Jumhyn
Copy link
Member

Jumhyn commented Sep 11, 2024

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?

@simanerush
Copy link
Member Author

@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 nonisolated to be written in more places than today.

@Jumhyn
Copy link
Member

Jumhyn commented Sep 11, 2024

@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
Copy link
Member

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?

Copy link
Member Author

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.

@rjmccall rjmccall added the LSG Contains topics under the domain of the Language Steering Group label Sep 30, 2024
Copy link
Member

@allevato allevato left a 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.

@allevato allevato merged commit b432080 into swiftlang:main Oct 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LSG Contains topics under the domain of the Language Steering Group
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants