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

Audit pass on Sendable conformances and requirements #272

Merged
merged 3 commits into from
Jun 23, 2023

Conversation

phausler
Copy link
Member

This brings the main API surface up to Sendable clean in complete mode.

The primary point of change is Async(Throwing)Channel. Which previously permitted a potential Sendability soundness hole. It now requires that AsyncChannel's Element type MUST be Sendable. The reasoning is that this type's primary use case is to send elements from one isolation to another. This means that the element must be Sendable to achieve this.

@phausler phausler requested a review from FranzBusch June 22, 2023 19:44
Package.swift Outdated
Comment on lines 24 to 27
swiftSettings: [
.unsafeFlags([
"-strict-concurrency=complete"
], .when(configuration: .debug))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we add this. AFAIK any package with unsafeFlags can't be depended on.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh that thing is still present eh... that is unfortunate.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW - I've been shimming around this by only setting it when there's an environment variable ('CI') set so that I can still get the benefit in my local CI without impacting downstream packages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@neonichu is there a sanctioned way to have strict concurrency warnings on without negatively impacting downstream consumers?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have a discussion about this in the Swift repo swiftlang/swift#65993. It would be great if we can find a solution to safely opt-in to strict checking . cc @tomerd @hborla

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that it is impossible to safely opt-in to a flag that is considered to be unstable.

I would suggest working around this by conditionally passing the unsafe flag based on some environment variable so that it can be enabled for local development / CI, but not for clients of the package.

}
}

extension OrderedSetContainer: @unchecked Sendable where Element: Sendable { }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need @unchecked here? If OrderedSet is conditionally Sendable than we should be able to do the same 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.

because OrderedSet itself is not marked w/ Sendable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That sounds like an oversight right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is there at an untagged version; 1.1.0

@phausler phausler force-pushed the pr/sendable_audit branch from 3510f36 to 37fd4d5 Compare June 23, 2023 18:31
struct ChannelStateMachine<Element, Failure: Error>: Sendable {
private struct SuspendedProducer: Hashable {
// NOTE: this is only marked as unchecked since the swift-collections tag is before auditing for Sendable
extension OrderedSet: @unchecked Sendable where Element: Sendable { }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lorentey This is the use in question

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is alright to do -- the type is already conditionally sendable, it just isn't marked as such in a shipping release yet.

My only worry is what happens when swift-collection ships the official conformance. Is the duplicate conformance going to become a compiler error?

Copy link
Member Author

@phausler phausler Jun 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are limiting usage to 1.0.4 so as soon as we upgrade we can remove this

plus iirc the duplicate conformance should be a no-op

@phausler phausler merged commit a42b72a into apple:main Jun 23, 2023
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

Successfully merging this pull request may close these issues.

5 participants