@@ -324,7 +324,7 @@ are a few common reasons for this:
324
324
save the overhead of a cross-library function call and allow further
325
325
optimization of callers.
326
326
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
328
328
allows the library author to preserve invariants while still allowing
329
329
efficient access to the struct.
330
330
@@ -345,11 +345,12 @@ Clients are not required to inline a function marked ``@inlinable``.
345
345
understanding that it will not affect existing clients. This is the
346
346
standard example of a `binary-compatible source-breaking change `.
347
347
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.
353
354
354
355
Removing the ``@inlinable `` attribute completely---say, to reference private
355
356
implementation details that should not be `versioned <versioned entity> `---is a
@@ -408,12 +409,28 @@ bodies of inlinable functions have the following restrictions:
408
409
guards.
409
410
410
411
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
+
411
428
Default Argument Expressions
412
429
----------------------------
413
430
414
431
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:
417
434
418
435
- They may not define any local types.
419
436
@@ -642,14 +659,18 @@ extension; unlike access control, entities within the extension may freely
642
659
declare themselves to be either more or less available than what the extension
643
660
provides.
644
661
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.
645
665
646
- Fixed-Contents Structs
647
- ----------------------
648
666
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 ``.
650
671
This promises that no stored properties will be added to or removed from the
651
672
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
653
674
``@inlinable `` (as described above for top-level variables). In effect:
654
675
655
676
- Reordering stored instance properties (public or non-public) is not permitted.
@@ -680,14 +701,9 @@ generic parameters and members of tuples.
680
701
.. note ::
681
702
682
703
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
684
705
functions and variables.
685
706
686
- .. note ::
687
-
688
- The name ``@fixedContents `` is intentionally awful to encourage us to come
689
- up with a better one.
690
-
691
707
While adding or removing stored properties is forbidden, existing properties may
692
708
still be modified in limited ways:
693
709
@@ -698,13 +714,13 @@ still be modified in limited ways:
698
714
- A versioned ``internal `` property may be made ``public `` (without changing
699
715
its version).
700
716
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
702
718
if it does not delegate to another initializer, as long as the ``@inlinable ``
703
719
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
705
721
properties.
706
722
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
708
724
struct with a similar "shape". If such a struct is necessary, it should be
709
725
defined in a C header and imported into Swift.
710
726
@@ -717,7 +733,7 @@ defined in a C header and imported into Swift.
717
733
718
734
.. note ::
719
735
720
- Hypothetically, we could use a different model where a ``@fixedContents ``
736
+ Hypothetically, we could use a different model where a ``@frozen ``
721
737
struct only guarantees the "shape" of the struct, so to speak, while
722
738
leaving all property accesses to go through function calls. This would
723
739
allow stored properties to change their accessors, or (with the Behaviors
@@ -726,17 +742,17 @@ defined in a C header and imported into Swift.
726
742
a simple C-like struct that groups together simple values, with only public
727
743
stored properties and no observing accessors, and having to opt into direct
728
744
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
730
746
discovered that its use is causing performance issues.
731
747
732
748
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
734
750
accessors, i.e. no observing accessors and no behaviors.
735
751
736
- ``@fixedContents `` is a `versioned attribute `. This is so that clients can
752
+ ``@frozen `` is a `versioned attribute `. This is so that clients can
737
753
deploy against older versions of the library, which may have a different layout
738
754
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.)
740
756
741
757
742
758
Enums
@@ -1171,19 +1187,14 @@ A Unifying Theme
1171
1187
~~~~~~~~~~~~~~~~
1172
1188
1173
1189
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
1176
1192
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
1178
1194
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
1180
1196
"fragility attributes".
1181
1197
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
-
1187
1198
1188
1199
Versioning Internal Declarations
1189
1200
================================
@@ -1233,7 +1244,7 @@ at run time if the source code is reorganized, which is unacceptable.
1233
1244
keep things simple we'll stick with the basics.
1234
1245
1235
1246
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
1237
1248
removes one of the primary reasons to make something inlinable: to allow
1238
1249
efficient access to a type while still protecting its invariants.
1239
1250
@@ -1244,7 +1255,7 @@ efficient access to a type while still protecting its invariants.
1244
1255
*Backdating * refers to releasing a new version of a library that contains
1245
1256
changes, but pretending those changes were made in a previous version of the
1246
1257
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
1248
1259
since its introduction in version 1.0.
1249
1260
1250
1261
**This is not safe. **
@@ -1253,9 +1264,8 @@ Backdating the availability a versioned entity that was previously non-public
1253
1264
is clearly not safe: older versions of the library will not expose the entity
1254
1265
as part of their ABI. What may be less obvious is that the fragility attributes
1255
1266
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.
1259
1269
1260
1270
.. note ::
1261
1271
@@ -1470,7 +1480,7 @@ for verification. Important cases include but are not limited to:
1470
1480
- Unsafe `backdating <#backdating >`_.
1471
1481
1472
1482
- 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.
1474
1484
1475
1485
Wherever possible, this tool should also check for `binary-compatible
1476
1486
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
1627
1637
affect the model described in this document, or concern the parts of this
1628
1638
document that affect language semantics:
1629
1639
1640
+ - Non-exhaustive enums (`SE-0192 <SE0192 >`_)
1641
+ - Inlineable functions (`SE-0193 <SE0193 >`_)
1642
+ - Frozen structs and enums (`SE-0260 <SE0260 >`_)
1630
1643
- (draft) `Overridable methods in extensions `_
1631
1644
- (planned) Restricting retroactive modeling (protocol conformances for types you don't own)
1632
1645
- (planned) `Generalized existentials (values of protocol type) <Generics >`_
1633
- - (planned) Frozen enums (building on `SE-0192 <SE0192 >`_)
1634
1646
- (planned) Removing the "constant" guarantee for 'let' across module boundaries
1635
- - (planned) Syntax for declaring fixed-contents structs
1636
1647
- (future) Performance annotations for types
1637
1648
- (future) Attributes for stored property accessors
1638
1649
- (future) Stored properties in extensions
1639
1650
1640
1651
.. _Overridable methods in extensions : https://github.com/jrose-apple/swift-evolution/blob/overridable-members-in-extensions/proposals/nnnn-overridable-members-in-extensions.md
1641
1652
.. _Generics : https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#generalized-existentials
1642
1653
.. _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
1643
1656
1644
1657
This does not mean all of these proposals need to be accepted, only that their
1645
1658
acceptance or rejection will affect this document.
0 commit comments