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

Unnecessary nonisolated(unsafe) produces no warning #71546

Closed
mattmassicotte opened this issue Feb 11, 2024 · 2 comments · Fixed by #72078
Closed

Unnecessary nonisolated(unsafe) produces no warning #71546

mattmassicotte opened this issue Feb 11, 2024 · 2 comments · Fixed by #72078
Assignees
Labels
compiler The Swift compiler in itself concurrency Feature: umbrella label for concurrency language features diagnostics QoI Bug: Diagnostics Quality of Implementation missing warning Bug: Missing warning swift 6.0 type checker Area → compiler: Semantic analysis

Comments

@mattmassicotte
Copy link

mattmassicotte commented Feb 11, 2024

Motivation

During the process of migrating a system towards supporting concurrency, you might need to use nonisolated(unsafe) from SE-0412.

public final class ActuallySendableClass {
	public init() {
	}
}

struct NonIsolatedContainer {
	nonisolated(unsafe) static let a = ActuallySendableClass()
}

But, later on, the class might be updated to conform to Sendable. Today, no diagnostics are produced.

public final class ActuallySendableClass: Sendable {
	public init() {
	}
}

struct NonIsolatedContainer {
	// now unnecessary
	nonisolated(unsafe) static let a = ActuallySendableClass()
}

Proposed solution

I think a warning would be appropriate here now that nonisolated(unsafe) is no longer required.

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 Feb 11, 2024
@hborla hborla added concurrency Feature: umbrella label for concurrency language features type checker Area → compiler: Semantic analysis and removed feature A feature request or implementation triage needed This issue needs more specific labels labels Feb 11, 2024
@hborla
Copy link
Member

hborla commented Feb 11, 2024

I think this is a good idea. There are cases where nonisolated is still necessary (e.g. for a public actor property), but in those cases we can still warn about removing the (unsafe) part.

@hborla
Copy link
Member

hborla commented Feb 20, 2024

@simanerush This is a good concurrency starter bug! Interested in taking a look?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself concurrency Feature: umbrella label for concurrency language features diagnostics QoI Bug: Diagnostics Quality of Implementation missing warning Bug: Missing warning swift 6.0 type checker Area → compiler: Semantic analysis
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants