Skip to content

Commit 73aba9b

Browse files
committed
Update LibraryEvolution.rst for new attribute names
1 parent 671ae94 commit 73aba9b

File tree

1 file changed

+56
-43
lines changed

1 file changed

+56
-43
lines changed

docs/LibraryEvolution.rst

Lines changed: 56 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,7 @@ are a few common reasons for this:
324324
save the overhead of a cross-library function call and allow further
325325
optimization of callers.
326326

327-
- The function accesses a fixed-contents struct with non-public members; this
327+
- The function accesses a frozen struct with non-public members; this
328328
allows the library author to preserve invariants while still allowing
329329
efficient access to the struct.
330330

@@ -345,11 +345,12 @@ Clients are not required to inline a function marked ``@inlinable``.
345345
understanding that it will not affect existing clients. This is the
346346
standard example of a `binary-compatible source-breaking change`.
347347

348-
Any local functions or closures within an inlinable function are themselves
349-
treated as ``@inlinable``, and a client that inlines the containing function
350-
must emit its own copy of the local functions or closures. This is important in
351-
case it is necessary to change the inlinable function later; existing clients
352-
should not be depending on internal details of the previous implementation.
348+
Any local functions or closures within an inlinable function are treated as
349+
``@_alwaysEmitIntoClient`` (see below). A client that inlines the containing
350+
function must emit its own copy of the local functions or closures. This is
351+
important in case it is necessary to change the inlinable function later;
352+
existing clients should not be depending on internal details of the previous
353+
implementation.
353354

354355
Removing the ``@inlinable`` attribute completely---say, to reference private
355356
implementation details that should not be `versioned <versioned entity>`---is a
@@ -408,12 +409,28 @@ bodies of inlinable functions have the following restrictions:
408409
guards.
409410

410411

412+
Always Emit Into Client
413+
-----------------------
414+
415+
A function, computed property or subscript annotated as ``@_alwaysEmitIntoClient``
416+
is similar to an ``@inlinable`` declaration, except the declaration is
417+
not part of the module's ABI, meaning that the client must always emit
418+
their own copy.
419+
420+
As a result, removing a declaration annotated as ``@_alwaysEmitIntoClient``
421+
is a binary-compatible source-breaking change.
422+
423+
.. admonition:: TODO
424+
425+
The implementation of ``@_alwaysEmitIntoClient`` is incomplete and
426+
should probably graduate to having its own evolution proposal.
427+
411428
Default Argument Expressions
412429
----------------------------
413430

414431
Default argument expressions for functions that are public, versioned, or
415-
inlinable are implemented very similar to inlinable functions and thus are
416-
subject to similar restrictions:
432+
inlinable are implicitly ``@_alwaysEmitIntoClient``. They are subject to
433+
similar restrictions:
417434

418435
- They may not define any local types.
419436

@@ -642,14 +659,18 @@ extension; unlike access control, entities within the extension may freely
642659
declare themselves to be either more or less available than what the extension
643660
provides.
644661

662+
We could also implement a ``@_alwaysEmitIntoClient`` attribute for conformances.
663+
This introduces its own challenges with runtime uniquing of witness tables now
664+
necessary for conformances.
645665

646-
Fixed-Contents Structs
647-
----------------------
648666

649-
To opt out of this flexibility, a struct may be marked ``@fixedContents``.
667+
Frozen Structs
668+
--------------
669+
670+
To opt out of this flexibility, a struct may be marked ``@frozen``.
650671
This promises that no stored properties will be added to or removed from the
651672
struct, even non-public ones. Additionally, all versioned instance stored
652-
properties in a ``@fixedContents`` struct are implicitly declared
673+
properties in a ``@frozen`` struct are implicitly declared
653674
``@inlinable`` (as described above for top-level variables). In effect:
654675

655676
- Reordering stored instance properties (public or non-public) is not permitted.
@@ -680,14 +701,9 @@ generic parameters and members of tuples.
680701
.. note::
681702

682703
The above restrictions do not apply to ``static`` properties of
683-
``@fixedContents`` structs. Static members effectively behave as top-level
704+
``@frozen`` structs. Static members effectively behave as top-level
684705
functions and variables.
685706

686-
.. note::
687-
688-
The name ``@fixedContents`` is intentionally awful to encourage us to come
689-
up with a better one.
690-
691707
While adding or removing stored properties is forbidden, existing properties may
692708
still be modified in limited ways:
693709

@@ -698,13 +714,13 @@ still be modified in limited ways:
698714
- A versioned ``internal`` property may be made ``public`` (without changing
699715
its version).
700716

701-
An initializer of a fixed-contents struct may be declared ``@inlinable`` even
717+
An initializer of a frozen struct may be declared ``@inlinable`` even
702718
if it does not delegate to another initializer, as long as the ``@inlinable``
703719
attribute, or the initializer itself, is not introduced earlier than the
704-
``@fixedContents`` attribute and the struct has no non-versioned stored
720+
``@frozen`` attribute and the struct has no non-versioned stored
705721
properties.
706722

707-
A ``@fixedContents`` struct is *not* guaranteed to use the same layout as a C
723+
A ``@frozen`` struct is *not* guaranteed to use the same layout as a C
708724
struct with a similar "shape". If such a struct is necessary, it should be
709725
defined in a C header and imported into Swift.
710726

@@ -717,7 +733,7 @@ defined in a C header and imported into Swift.
717733

718734
.. note::
719735

720-
Hypothetically, we could use a different model where a ``@fixedContents``
736+
Hypothetically, we could use a different model where a ``@frozen``
721737
struct only guarantees the "shape" of the struct, so to speak, while
722738
leaving all property accesses to go through function calls. This would
723739
allow stored properties to change their accessors, or (with the Behaviors
@@ -726,17 +742,17 @@ defined in a C header and imported into Swift.
726742
a simple C-like struct that groups together simple values, with only public
727743
stored properties and no observing accessors, and having to opt into direct
728744
access to those properties seems unnecessarily burdensome. The struct is
729-
being declared ``@fixedContents`` for a reason, after all: it's been
745+
being declared ``@frozen`` for a reason, after all: it's been
730746
discovered that its use is causing performance issues.
731747

732748
Consequently, as a first pass we may just require all stored properties in
733-
a ``@fixedContents`` struct, public or non-public, to have trivial
749+
a ``@frozen`` struct, public or non-public, to have trivial
734750
accessors, i.e. no observing accessors and no behaviors.
735751

736-
``@fixedContents`` is a `versioned attribute`. This is so that clients can
752+
``@frozen`` is a `versioned attribute`. This is so that clients can
737753
deploy against older versions of the library, which may have a different layout
738754
for the struct. (In this case the client must manipulate the struct as if the
739-
``@fixedContents`` attribute were absent.)
755+
``@frozen`` attribute were absent.)
740756

741757

742758
Enums
@@ -1171,19 +1187,14 @@ A Unifying Theme
11711187
~~~~~~~~~~~~~~~~
11721188

11731189
So far this document has talked about ways to give up flexibility for several
1174-
different kinds of declarations: ``@inlinable`` for functions,
1175-
``@fixedContents`` for structs, etc. Each of these has a different set of
1190+
different kinds of declarations: namely ``@inlinable`` for functions, and
1191+
``@frozen`` for enums and structs. Each of these has a different set of
11761192
constraints it enforces on the library author and promises it makes to clients.
1177-
However, they all follow a common theme of giving up the flexibility of future
1193+
However, they follow a common theme of giving up the flexibility of future
11781194
changes in exchange for improved performance and perhaps some semantic
1179-
guarantees. Therefore, all of these attributes are informally referred to as
1195+
guarantees. Therefore, these attributes are informally referred to as
11801196
"fragility attributes".
11811197

1182-
Given that these attributes share several characteristics, we could consider
1183-
converging on a single common attribute, say ``@fixed``, ``@inline``, or
1184-
``@fragile``. However, this may be problematic if the same declaration has
1185-
multiple kinds of flexibility.
1186-
11871198

11881199
Versioning Internal Declarations
11891200
================================
@@ -1233,7 +1244,7 @@ at run time if the source code is reorganized, which is unacceptable.
12331244
keep things simple we'll stick with the basics.
12341245

12351246
We could do away with the entire feature if we restricted inlinable functions
1236-
and fixed-contents structs to only refer to public entities. However, this
1247+
and frozen structs to only refer to public entities. However, this
12371248
removes one of the primary reasons to make something inlinable: to allow
12381249
efficient access to a type while still protecting its invariants.
12391250

@@ -1244,7 +1255,7 @@ efficient access to a type while still protecting its invariants.
12441255
*Backdating* refers to releasing a new version of a library that contains
12451256
changes, but pretending those changes were made in a previous version of the
12461257
library. For example, you might want to release version 1.2 of the "Magician"
1247-
library, but pretend that the "SpellIncantation" struct was fixed-contents
1258+
library, but pretend that the "SpellIncantation" struct was frozen
12481259
since its introduction in version 1.0.
12491260

12501261
**This is not safe.**
@@ -1253,9 +1264,8 @@ Backdating the availability a versioned entity that was previously non-public
12531264
is clearly not safe: older versions of the library will not expose the entity
12541265
as part of their ABI. What may be less obvious is that the fragility attributes
12551266
likewise are not safe to backdate, even if you know the attributes could have
1256-
been added in the past. To give one example, the presence of ``@closed`` or
1257-
``@fixedContents`` may affect the layout and calling conventions for an enum
1258-
or struct.
1267+
been added in the past. To give one example, the presence of ``@frozen`` may
1268+
affect the layout and calling conventions for an enum or struct.
12591269

12601270
.. note::
12611271

@@ -1470,7 +1480,7 @@ for verification. Important cases include but are not limited to:
14701480
- Unsafe `backdating <#backdating>`_.
14711481

14721482
- Unsafe modifications to entities marked with fragility attributes, such as
1473-
adding a stored property to a ``@fixedContents`` struct.
1483+
adding a stored property to a ``@frozen`` struct.
14741484

14751485
Wherever possible, this tool should also check for `binary-compatible
14761486
source-breaking changes <binary-compatible source-breaking change>`, such as
@@ -1627,19 +1637,22 @@ The following proposals (some currently in the process, some planned) will
16271637
affect the model described in this document, or concern the parts of this
16281638
document that affect language semantics:
16291639

1640+
- Non-exhaustive enums (`SE-0192 <SE0192>`_)
1641+
- Inlineable functions (`SE-0193 <SE0193>`_)
1642+
- Frozen structs and enums (`SE-0260 <SE0260>`_)
16301643
- (draft) `Overridable methods in extensions`_
16311644
- (planned) Restricting retroactive modeling (protocol conformances for types you don't own)
16321645
- (planned) `Generalized existentials (values of protocol type) <Generics>`_
1633-
- (planned) Frozen enums (building on `SE-0192 <SE0192>`_)
16341646
- (planned) Removing the "constant" guarantee for 'let' across module boundaries
1635-
- (planned) Syntax for declaring fixed-contents structs
16361647
- (future) Performance annotations for types
16371648
- (future) Attributes for stored property accessors
16381649
- (future) Stored properties in extensions
16391650

16401651
.. _Overridable methods in extensions: https://github.com/jrose-apple/swift-evolution/blob/overridable-members-in-extensions/proposals/nnnn-overridable-members-in-extensions.md
16411652
.. _Generics: https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#generalized-existentials
16421653
.. _SE0192: https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md
1654+
.. _SE0193: https://github.com/apple/swift-evolution/blob/master/proposals/0193-cross-module-inlining-and-specialization.md
1655+
.. _SE0260: https://github.com/apple/swift-evolution/blob/master/proposals/0260-library-evolution.md
16431656

16441657
This does not mean all of these proposals need to be accepted, only that their
16451658
acceptance or rejection will affect this document.

0 commit comments

Comments
 (0)