Skip to content

Commit 80419c7

Browse files
authored
Merge pull request #20135 from slavapestov/update-evolution-doc
Minor updates for LibraryEvolution.rst
2 parents 8828bef + 4959c33 commit 80419c7

File tree

1 file changed

+40
-27
lines changed

1 file changed

+40
-27
lines changed

docs/LibraryEvolution.rst

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ polar representation::
395395
and the ``x`` and ``y`` properties have now disappeared. To avoid this, the
396396
bodies of inlinable functions have the following restrictions:
397397

398-
- They may not define any local types (other than typealiases).
398+
- They may not define any local types.
399399

400400
- They must not reference any ``private`` or ``fileprivate`` entities.
401401

@@ -415,12 +415,12 @@ Default argument expressions for functions that are public, versioned, or
415415
inlinable are implemented very similar to inlinable functions and thus are
416416
subject to similar restrictions:
417417

418-
- They may not define any local types (other than typealiases).
418+
- They may not define any local types.
419419

420420
- They must not reference any non-``public`` entities.
421421

422422
- They must not reference any entities from the current module introduced
423-
after the function was made inlinable, except under appropriate availability
423+
after the default argument was added, except under appropriate availability
424424
guards.
425425

426426
A default argument implicitly has the same availability as the function it is
@@ -438,6 +438,8 @@ changes are permitted:
438438
- Adding or removing a non-public, non-versioned setter.
439439
- Changing from a stored variable to a computed variable, or vice versa, as
440440
long as a previously versioned setter is not removed.
441+
- As a special case of the above, adding or removing ``lazy`` from a stored
442+
property.
441443
- Changing the body of an accessor.
442444
- Adding or removing an observing accessor (``willSet`` or ``didSet``) to/from
443445
an existing variable. This is effectively the same as modifying the body of a
@@ -482,6 +484,7 @@ amount:
482484
- Adding or removing a non-public, non-versioned setter is still permitted.
483485
- Changing from stored to computed or vice versa is forbidden, because it would
484486
break existing clients.
487+
- Similarly, adding or removing ``lazy`` is forbidden.
485488
- Changing the body of an accessor is a `binary-compatible source-breaking
486489
change`.
487490
- Adding/removing observing accessors is likewise a `binary-compatible
@@ -530,6 +533,8 @@ the following changes are permitted:
530533
- Reordering any existing members, including stored properties.
531534
- Adding any new members, including stored properties.
532535
- Changing existing properties from stored to computed or vice versa.
536+
- As a special case of the above, adding or removing ``lazy`` from a stored
537+
property.
533538
- Changing the body of any methods, initializers, or accessors.
534539
- Adding or removing an observing accessor (``willSet`` or ``didSet``) to/from
535540
an existing property. This is effectively the same as modifying the body of a
@@ -651,8 +656,10 @@ properties in a ``@fixedContents`` struct are implicitly declared
651656
Reordering all other members is still permitted.
652657
- Adding new stored instance properties (public or non-public) is not permitted.
653658
Adding any other new members is still permitted.
654-
- Existing instance properties may not be changed from stored to computed or
655-
vice versa.
659+
- Changing existing instance properties from stored to computed or
660+
vice versa is not permitted.
661+
- Similarly, adding or removing ``lazy`` from a stored property is not
662+
permitted.
656663
- Changing the body of any *existing* methods, initializers, computed property
657664
accessors, or non-instance stored property accessors is permitted. Changing
658665
the body of a stored instance property observing accessor is permitted if the
@@ -670,6 +677,12 @@ Additionally, if the type of any stored instance property includes a struct or
670677
enum, that struct or enum must be `versioned <versioned entity>`. This includes
671678
generic parameters and members of tuples.
672679

680+
.. note::
681+
682+
The above restrictions do not apply to ``static`` properties of
683+
``@fixedContents`` structs. Static members effectively behave as top-level
684+
functions and variables.
685+
673686
.. note::
674687

675688
The name ``@fixedContents`` is intentionally awful to encourage us to come
@@ -787,9 +800,8 @@ clients that the enum cases are exhaustive. In particular:
787800

788801
- Adding new cases is not permitted.
789802
- Reordering existing cases is not permitted.
790-
- Adding a raw type to an enum that does not have one is not permitted -- it's
791-
used for optimization.
792803
- Removing a non-public case is not applicable.
804+
- Adding a raw type is still permitted.
793805
- Adding any other members is still permitted.
794806
- Removing any non-public, non-versioned members is still permitted.
795807
- Adding a new protocol conformance is still permitted.
@@ -827,6 +839,7 @@ There are very few safe changes to make to protocols and their members:
827839

828840
- A new non-type requirement may be added to a protocol, as long as it has an
829841
unconstrained default implementation.
842+
- A new associated type requirement may be added as long as it has a default.
830843
- A default may be added to an associated type.
831844
- Removing a default from an associated type is a `binary-compatible
832845
source-breaking change`.
@@ -840,9 +853,18 @@ There are very few safe changes to make to protocols and their members:
840853
be added to a function requirement without any additional versioning
841854
information.
842855

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`.
860+
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.
864+
843865
All other changes to the protocol itself are forbidden, including:
844866

845-
- Adding a new associated type.
867+
- Adding or removing refined protocols.
846868
- Removing any existing requirements (type or non-type).
847869
- Making an existing requirement optional.
848870
- Making a non-``@objc`` protocol ``@objc`` or vice versa.
@@ -874,6 +896,8 @@ support all of the following changes:
874896

875897
- Reordering any existing members, including stored properties.
876898
- Changing existing properties from stored to computed or vice versa.
899+
- As a special case of the above, adding or removing ``lazy`` from a stored
900+
property.
877901
- Changing the body of any methods, initializers, or accessors.
878902
- Adding or removing an observing accessor (``willSet`` or ``didSet``) to/from
879903
an existing property. This is effectively the same as modifying the body of a
@@ -1090,13 +1114,20 @@ additive feature, it can be added to the model at any time.
10901114
Extensions
10911115
~~~~~~~~~~
10921116

1093-
Non-protocol extensions largely follow the same rules as the types they extend.
1117+
Extensions largely follow the same rules as the types they extend.
10941118
The following changes are permitted:
10951119

10961120
- Adding new extensions and removing empty extensions (that is, extensions that
10971121
declare neither members nor protocol conformances).
10981122
- Moving a member from one extension to another within the same module, as long
10991123
as both extensions have the exact same constraints.
1124+
- Adding any new member.
1125+
- Reordering members.
1126+
- Removing any non-public, non-versioned member.
1127+
- Changing the body of any methods, initializers, or accessors.
1128+
1129+
Additionally, non-protocol extensions allow a few additional changes:
1130+
11001131
- Moving a member from an unconstrained extension to the declaration of the
11011132
base type, provided that the declaration is in the same module. The reverse
11021133
is permitted for all members except stored properties, although note that
@@ -1105,24 +1136,6 @@ The following changes are permitted:
11051136
- Adding a new protocol conformance (with proper availability annotations).
11061137
- Removing conformances to non-public protocols.
11071138

1108-
Adding, removing, reordering, and modifying members follow the same rules as
1109-
the base type; see the sections on structs, enums, and classes above.
1110-
1111-
1112-
Protocol Extensions
1113-
-------------------
1114-
1115-
Protocol extensions follow slightly different rules from other extensions; the
1116-
following changes are permitted:
1117-
1118-
- Adding new extensions and removing empty extensions.
1119-
- Moving a member from one extension to another within the same module, as long
1120-
as both extensions have the exact same constraints.
1121-
- Adding any new member.
1122-
- Reordering members.
1123-
- Removing any non-public, non-versioned member.
1124-
- Changing the body of any methods, initializers, or accessors.
1125-
11261139
.. note::
11271140

11281141
Although it is not related to evolution, it is worth noting that members of

0 commit comments

Comments
 (0)