Skip to content

Design Guidelines #9

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

Closed
mattmassicotte opened this issue May 28, 2024 · 6 comments
Closed

Design Guidelines #9

mattmassicotte opened this issue May 28, 2024 · 6 comments

Comments

@mattmassicotte
Copy link
Collaborator

I'm not certain if this belongs in "Common Errors", or more something else. But I'd really like to expand on the trade-offs of fine- vs coarse-grained isolation.

For example:

class SomeClass {
    @MainActor
    var isolatedValue = 1
}

vs

actor SomeClass {
    @MainActor
    var isolatedValue = 1
}

vs

@MainActor
class SomeClass {
    var isolatedValue = 1
}

Especially to tie in the use of nonisolated for selectively opting-out of whatever domain your type is part of.

@mattmassicotte
Copy link
Collaborator Author

@hborla do you have any ideas on this?

@hborla
Copy link
Member

hborla commented May 29, 2024

@mattmassicotte I agree with you that this doesn't belong in Common Compiler Errors. Perhaps we need another section on API design. I've been thinking about expanding the Swift API Design Guidelines with concurrency guidelines, but that probably needs more explanation than what typically goes in that guide. I think it makes sense to add a section specifically about API changes and the implications in the migration guide, and this topic would fit into there. Thoughts?

@mattmassicotte
Copy link
Collaborator Author

mattmassicotte commented May 29, 2024

Anedotally, I see many people looking for help with design. This is a pretty natural extension of the common errors section too. That helps you understand what's up. But, if you need/want to make deeper changes, having some recommendations to look at could be really useful.

I have not read the Swift API Design Guidelines. I agree that adding something to that guide could make sense. But, I also think you are right that these kinds of issues could be more involved. Plus, it would spread some very related information around.

"API Design"? "Design Guidelines"?

@mattmassicotte mattmassicotte changed the title isolation granularity Isolation Granularity May 30, 2024
@mattmassicotte mattmassicotte changed the title Isolation Granularity Design Guidelines Jun 7, 2024
@mattmassicotte
Copy link
Collaborator Author

I'm co-opting this issue to represent the ideas that might go into #46.

Some things off the top of my head:

  • Swift 5 + warnings first, or right to Swift 6?
  • expressing truth first, then refactor/introduce more concurrency second
  • Dynamic vs static isolation
  • How should static isolation be structured (ie the original topic of "isolation granularity")
  • Starting at leaf modules, top-level code, someting else?
  • Fear of MainActor vs dealing with potentially-long-running synchronous code
  • Changing classes into actors without careful thought
  • Adding Sendable conformances to reference types to workaround awkward isolation

Some of this stuff does appear in other areas already, but might not be terrible to re-iterate.

@mattmassicotte
Copy link
Collaborator Author

InferSendableFromCaptures could be really important to mention as well.

mattmassicotte added a commit that referenced this issue Jun 14, 2024
mattmassicotte added a commit that referenced this issue Jun 17, 2024
@mattmassicotte
Copy link
Collaborator Author

I split this up becuase the migratio guidance document was getting quite large. However, I still do think there are some useful tips to include:

  • MainActor + nonisolated
  • Changing classes into actors
  • Adding Sendable conformances to reference types to workaround awkward isolation
  • Using multiple isolation domains within a single type

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

No branches or pull requests

2 participants