You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Protocol requirements can be such that an infinite number of associated types
421
-
are derivable from a type conforming to that protocol. A classic example is,
459
+
There can be an infinite number of type parameters derivable from a conformance
460
+
requirement, because a protocol's associated type requirement can be part of a cycle with the protocol itself:
422
461
423
462
```swift
424
463
protocolP<A>: ~Copyable {
425
464
associatedtypeA: ~Copyable, P
426
465
}
427
466
```
428
467
429
-
For a generic environment `<R where R: P>`, all of `R.A, R.A.A, R.A.A.A, ...`,
430
-
are Copyable because the type with one fewer `A` conforms to `P`.
468
+
For a generic signature `<R where R: P>`, all of the type parameters
469
+
`R.A, R.A.A, R.A.A.A, ...`,
470
+
are Copyable.
471
+
For any type parameter `X` rooted in `R`, the type `X.A` conforms to `P`, and by the expansion procedure, that implies `X.A: Copyable` because `A` is a primary
472
+
associated type of `P`.
431
473
432
474
Next, consider this pair of mutually recursive protocols where only one of
extensionQueueHolder: Copyable where G.Quack:Copyable {} // error
588
627
```
589
-
This restriction isfor runtime implementation reasons.
628
+
This restriction isfor runtime implementation limitations.
590
629
591
-
<!-- TODO: Perhaps this needs elaboration?-->
630
+
<!-- TODO: Perhaps the limitation needs elaboration?-->
592
631
593
632
594
633
## Source Compatibility
@@ -635,8 +674,24 @@ assumption is no longer true.
635
674
The ABI of existing code is not affected by this proposal.
636
675
637
676
On the other hand, changing an associated type declaration in an library
638
-
to suppress conformance is an ABI-breaking change, for similar reasons
639
-
to those described above.
677
+
to suppress conformance is can be an ABI-breaking change. For example, an
678
+
extension of a protocol providing a default implementation could have its symbol
679
+
name change, as these two implementations of `greet` must have distinct names:
680
+
681
+
```swift
682
+
protocol Greeter<T> {
683
+
associatedtype T:~Copyable
684
+
funcgreet()
685
+
}
686
+
687
+
extensionGreeter {
688
+
funcgreet() { print("hello")}
689
+
}
690
+
691
+
extensionGreeterwhere T:~Copyable {
692
+
funcgreet() { print("سلام") }
693
+
}
694
+
```
640
695
641
696
## Future Directions
642
697
@@ -660,10 +715,25 @@ constrained existential via `any Q<some ~Copyable>`.
660
715
661
716
## Alternatives Considered
662
717
718
+
Through the development of this proposal, various alternate formulations were considered.
719
+
663
720
### No recursion
664
721
665
-
A prior version of this proposal [was pitched](https://forums.swift.org/t/pitch-suppressed-default-conformances-on-associated-types/81880) that was absent of any defaulting behavior
666
-
for associated types.
722
+
A prior version of this proposal [was pitched](https://forums.swift.org/t/pitch-suppressed-default-conformances-on-associated-types/81880) that was absent of any defaulting behavior for associated types. The primary fault was that it
723
+
provided an inconsistent behavior when compared with generic types like S:
724
+
725
+
```swift
726
+
struct S<T:~Copyable>:~Copyable {}
727
+
728
+
protocol P<T>:~Copyable {
729
+
associatedtype T:~Copyable
730
+
}
731
+
732
+
extensionS {} // T: Copyable
733
+
extensionP {} // T: ~Copyable
734
+
```
735
+
736
+
Only the extensionfor S provides a defaultfor its T.
0 commit comments