Skip to content
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

nonisolated property wrappers #76725

Open
mattmassicotte opened this issue Sep 26, 2024 · 2 comments
Open

nonisolated property wrappers #76725

mattmassicotte opened this issue Sep 26, 2024 · 2 comments
Labels
actor isolation Feature → concurrency: Actor isolation compiler The Swift compiler itself concurrency Feature: umbrella label for concurrency language features feature A feature request or implementation property wrappers Feature: property wrappers swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal

Comments

@mattmassicotte
Copy link
Contributor

Motivation

This isn't an area I understand very well. But it seems like nonisolated property wrappers should be possible if the underlying wrapper type is Sendable.

@propertyWrapper
struct Wrapped<T: Sendable>: Sendable {
	var wrappedValue: T

	init(wrappedValue: T) {
		self.wrappedValue = wrappedValue
	}
}

actor MyActor {
	// if you can write this...
	nonisolated var computedValue: Int {
		get {
			0
		}
		set {
			// ... even if it tricky to implement
		}
	}

	// shouldn't you be able to write this
	// if the wrapper is Sendable?
	@Wrapped nonisolated var wrappedValue: Int = 0
}

Proposed solution

I think this code should be accepted. As is, it produces an error:

error: 'nonisolated' is not supported on properties with property wrappers

Alternatives considered

No response

Additional information

No response

@mattmassicotte mattmassicotte added feature A feature request or implementation triage needed This issue needs more specific labels labels Sep 26, 2024
@AnthonyLatsis AnthonyLatsis added concurrency Feature: umbrella label for concurrency language features compiler The Swift compiler itself swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal actor isolation Feature → concurrency: Actor isolation property wrappers Feature: property wrappers and removed triage needed This issue needs more specific labels labels Sep 27, 2024
@jamieQ
Copy link
Contributor

jamieQ commented Sep 27, 2024

some historical context of possible relevance:

  1. PR comment thread addressing the root problem
  2. related forums thread (also links to other related pitches/discussions)

@mattmassicotte
Copy link
Contributor Author

@jamieQ thank you! Looks like a non-trivial problem :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
actor isolation Feature → concurrency: Actor isolation compiler The Swift compiler itself concurrency Feature: umbrella label for concurrency language features feature A feature request or implementation property wrappers Feature: property wrappers swift evolution proposal needed Flag → feature: A feature that warrants a Swift evolution proposal
Projects
None yet
Development

No branches or pull requests

3 participants