Review feedback was light, and mainly focused on the potential future direction of non-primary associated types also being able to default to the copyable behavior. The language steering group believes that the need for this future direction will be informed by adoption of this proposal, and such defaulting behavior could be layered on in future if needed.
Thanks to everyone who participated in the review.
I'm glad that this proposal get accepted. However, I'm still not sure I fully understand the default witness section.
The proposal says "even if the default witness for a suppressed associated type conforms to Copyable and/or Escapable, matching generic requirement(s) are not introduced". I fully agree with this, what I don't understand is why it needs a special statement.
This following code is just from the proposal:
func runForwardsInt(_ it: some Iterable<Int>) {
_ = copy it.getIter() // OK
}
func runForwardsNC(_ it: some Iterable<NonCopyableType>) {
_ = copy it.getIter() // error: copy of noncopyable type
}
As I understand it, both the return values of it.getIter() are just associatedtype Iters, inside these 2 functions, the default implementaion of ForwardIterator has no way to be witnessed. Because the it passed to runForwardsInt can be of a custom type, which does conform to Iterable<Int>, but implements a noncopyable Iter.
Am I missing something? And what part does "associatedtype default implementation" play here? @kavon
Yeah that example in the proposal is missing a little bit of something. The issue I was trying to get at is when a default will be inferred and there’s a default witness that doesn’t conform to that defaulted protocol. That only happens in this proposal when it’s a suppressed primary associated type that has a default witness that doesn’t conform to either Copyable or Escapable:
struct SafeFD: ~Copyable {}
protocol File<Descriptor> {
associatedtype Descriptor: ~Copyable = SafeFD
}
struct Handle: File {} // relies on SafeFD as the default witness
struct UnsafeHandle: File {
typealias Descriptor = Int
}
func doSomething(_ s: some File) {}
doSomething(Handle()) // error: global function 'doSomething' requires that 'SafeFD' conform to 'Copyable'
doSomething(UnsafeHandle())
I wouldn’t expect there to be many protocols with a primary associated type that has a default like this, but it is something worth knowing.