@@ -837,12 +837,7 @@ Protocols
837
837
838
838
There are very few safe changes to make to protocols and their members:
839
839
840
- - A new non-type requirement may be added to a protocol, as long as it has an
841
- unconstrained default implementation.
842
- - A new associated type requirement may be added as long as it has a default.
843
840
- A default may be added to an associated type.
844
- - Removing a default from an associated type is a `binary-compatible
845
- source-breaking change `.
846
841
- A new optional requirement may be added to an ``@objc `` protocol.
847
842
- All members may be reordered, including associated types.
848
843
- Changing *internal * parameter names of function and subscript requirements
@@ -853,40 +848,33 @@ There are very few safe changes to make to protocols and their members:
853
848
be added to a function requirement without any additional versioning
854
849
information.
855
850
856
- Note that clients can use a protocol as an existential type as long as it does
857
- not have any associated types or requirements containing `` Self `` in
858
- non-covariant position. Therefore adding such a requirement becomes a
859
- `binary-compatible source-breaking change `.
851
+ New requirements can be added to a protocol. However, restrictions around
852
+ existential types mean that adding new associated types or non-type requirements
853
+ involving `` Self `` can break source compatibility. For this reason, the following
854
+ are `binary-compatible source-breaking changes `:
860
855
861
- Adding such requirements to protocols that already contain such requirements and
862
- cannot be used as existential types, on the other hand, is always
863
- source-compatible.
856
+ - A new non-type requirement may be added to a protocol, as long as it has an
857
+ unconstrained default implementation in a protocol extension of the
858
+ protocol itself or some other protocol it refines.
859
+ - A new associated type requirement may be added as long as it has a
860
+ default.
864
861
865
862
All other changes to the protocol itself are forbidden, including:
866
863
867
864
- Adding or removing refined protocols.
868
865
- Removing any existing requirements (type or non-type).
866
+ - Removing the default type of an associated type.
869
867
- Making an existing requirement optional.
870
868
- Making a non-``@objc `` protocol ``@objc `` or vice versa.
871
- - Adding or removing constraints from an associated type, including inherited
872
- associated types.
869
+ - Adding or removing protocols and superclasses from the inheritance
870
+ clause of an associated type.
871
+ - Adding or removing constraints from the ``where `` clause of
872
+ the protocol or an associated type.
873
873
874
874
Protocol extensions may be more freely modified; `see below `__.
875
875
876
876
__ #protocol-extensions
877
877
878
- .. note ::
879
-
880
- A protocol's associated types are used in computing the "generic signature"
881
- that uniquely identifies a generic function. Adding an associated type
882
- could perturb the generic signature and thus change the identity of a
883
- function, breaking binary compatibility.
884
-
885
- It may be possible to allow adding associated types as long as they have
886
- proper availability annotations, but this is not in scope for the initial
887
- version of Swift ABI stability.
888
-
889
-
890
878
Classes
891
879
~~~~~~~
892
880
0 commit comments