-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Restrict withUnsafeBytes to swift 5.0 or greater availability to avoid ambiguity #21679
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
Conversation
@swift-ci please smoke test |
@swift-ci please test source compatibility |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, pending this working, of course.
@jrose-apple do you know what these interface files are failing for? |
@jrose-apple To clarify what we're doing here: SwiftNIO 1 added We're trying to avoid breaking Swift 4.2-mode users of Swift 5 by declaring our method as Swift 5 only. However, my gut feeling is that this is complaining that we wouldn't be able to build our overlay in Swift 4? (Which is true, but also, we build our overlay strictly in Swift 5) |
The verification is indeed happening with
Upon further thought, this is a real issue. I think the solution will be to annotate every new API with |
@jrose-apple @slavapestov This is worse than we thought, since it doesn't look like we can conditionally extend import Foundation
@available(swift, introduced: 5)
public protocol Foo {}
@available(swift, introduced: 5)
extension Data : Foo {}
|
No, you can't do that. Swift versions are a compile-time concept, but conformances exist at run time. |
I'll fix the interfaces test soon to use whatever Swift version they were originally built with, but yeah, unless ContiguousBytes itself is limited to Swift 5 mode you're going to be in trouble here. |
(feel free to XFAIL the test if you need to make progress) |
@jrose-apple Thanks for confirming — if this is the case, we can't fix this by making |
@jrose-apple Any protocol Foo {
func foo()
}
struct Bar : Foo {
@_implements(Foo, foo())
@available(swift, introduced: 4, obsoleted: 5)
func bar() {
print("Bar!")
}
@available(swift, introduced: 5)
func foo() {
print("Foo!")
}
}
let f: Foo = Bar()
f.foo() |
1ec3ea3
to
702cad0
Compare
@swift-ci please smoke test |
I hate to add more uses of EDIT: Or maybe that will work because the people who added the new capability will have added it to Data, making it more specific (i.e. a better overload) than the one on the protocol. |
…ty with external potential implementations
702cad0
to
e81c7f9
Compare
@swift-ci please smoke test |
@jrose-apple Hmm, from the perspective of the protocol conformance, I'm not sure what would happen. If In either case, it appears that just removing the
|
Fixing the interface tests in #21687. |
After review we have decided to take a different direction here. |
The recent refactor for
Data
added a new method ofwithUnsafeBytes
that vends aUnsafeRawBufferPointer
in its closure. However there were external projects that added this as a category toData
which unfortunately lead to un-reconcilable ambiguity. Marking this method as available in swift 5.0 it prevents the ambiguity at the cost of preventing the usage of the API that avoids undefined behavior in 4.2 mode.