@@ -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 frozen struct with non-public members; this
327
+ - The function accesses a fixed-contents 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,12 +345,11 @@ 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 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.
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.
354
353
355
354
Removing the ``@inlinable `` attribute completely---say, to reference private
356
355
implementation details that should not be `versioned <versioned entity> `---is a
@@ -409,28 +408,12 @@ bodies of inlinable functions have the following restrictions:
409
408
guards.
410
409
411
410
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
-
428
411
Default Argument Expressions
429
412
----------------------------
430
413
431
414
Default argument expressions for functions that are public, versioned, or
432
- inlinable are implicitly `` @_alwaysEmitIntoClient ``. They are subject to
433
- similar restrictions:
415
+ inlinable are implemented very similar to inlinable functions and thus are
416
+ subject to similar restrictions:
434
417
435
418
- They may not define any local types.
436
419
@@ -659,18 +642,14 @@ extension; unlike access control, entities within the extension may freely
659
642
declare themselves to be either more or less available than what the extension
660
643
provides.
661
644
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.
665
645
646
+ Fixed-Contents Structs
647
+ ----------------------
666
648
667
- Frozen Structs
668
- --------------
669
-
670
- To opt out of this flexibility, a struct may be marked ``@frozen ``.
649
+ To opt out of this flexibility, a struct may be marked ``@fixedContents ``.
671
650
This promises that no stored properties will be added to or removed from the
672
651
struct, even non-public ones. Additionally, all versioned instance stored
673
- properties in a ``@frozen `` struct are implicitly declared
652
+ properties in a ``@fixedContents `` struct are implicitly declared
674
653
``@inlinable `` (as described above for top-level variables). In effect:
675
654
676
655
- Reordering stored instance properties (public or non-public) is not permitted.
@@ -701,9 +680,14 @@ generic parameters and members of tuples.
701
680
.. note ::
702
681
703
682
The above restrictions do not apply to ``static `` properties of
704
- ``@frozen `` structs. Static members effectively behave as top-level
683
+ ``@fixedContents `` structs. Static members effectively behave as top-level
705
684
functions and variables.
706
685
686
+ .. note ::
687
+
688
+ The name ``@fixedContents `` is intentionally awful to encourage us to come
689
+ up with a better one.
690
+
707
691
While adding or removing stored properties is forbidden, existing properties may
708
692
still be modified in limited ways:
709
693
@@ -714,13 +698,13 @@ still be modified in limited ways:
714
698
- A versioned ``internal `` property may be made ``public `` (without changing
715
699
its version).
716
700
717
- An initializer of a frozen struct may be declared ``@inlinable `` even
701
+ An initializer of a fixed-contents struct may be declared ``@inlinable `` even
718
702
if it does not delegate to another initializer, as long as the ``@inlinable ``
719
703
attribute, or the initializer itself, is not introduced earlier than the
720
- ``@frozen `` attribute and the struct has no non-versioned stored
704
+ ``@fixedContents `` attribute and the struct has no non-versioned stored
721
705
properties.
722
706
723
- A ``@frozen `` struct is *not * guaranteed to use the same layout as a C
707
+ A ``@fixedContents `` struct is *not * guaranteed to use the same layout as a C
724
708
struct with a similar "shape". If such a struct is necessary, it should be
725
709
defined in a C header and imported into Swift.
726
710
@@ -733,7 +717,7 @@ defined in a C header and imported into Swift.
733
717
734
718
.. note ::
735
719
736
- Hypothetically, we could use a different model where a ``@frozen ``
720
+ Hypothetically, we could use a different model where a ``@fixedContents ``
737
721
struct only guarantees the "shape" of the struct, so to speak, while
738
722
leaving all property accesses to go through function calls. This would
739
723
allow stored properties to change their accessors, or (with the Behaviors
@@ -742,17 +726,17 @@ defined in a C header and imported into Swift.
742
726
a simple C-like struct that groups together simple values, with only public
743
727
stored properties and no observing accessors, and having to opt into direct
744
728
access to those properties seems unnecessarily burdensome. The struct is
745
- being declared ``@frozen `` for a reason, after all: it's been
729
+ being declared ``@fixedContents `` for a reason, after all: it's been
746
730
discovered that its use is causing performance issues.
747
731
748
732
Consequently, as a first pass we may just require all stored properties in
749
- a ``@frozen `` struct, public or non-public, to have trivial
733
+ a ``@fixedContents `` struct, public or non-public, to have trivial
750
734
accessors, i.e. no observing accessors and no behaviors.
751
735
752
- ``@frozen `` is a `versioned attribute `. This is so that clients can
736
+ ``@fixedContents `` is a `versioned attribute `. This is so that clients can
753
737
deploy against older versions of the library, which may have a different layout
754
738
for the struct. (In this case the client must manipulate the struct as if the
755
- ``@frozen `` attribute were absent.)
739
+ ``@fixedContents `` attribute were absent.)
756
740
757
741
758
742
Enums
@@ -1187,14 +1171,19 @@ A Unifying Theme
1187
1171
~~~~~~~~~~~~~~~~
1188
1172
1189
1173
So far this document has talked about ways to give up flexibility for several
1190
- different kinds of declarations: namely ``@inlinable `` for functions, and
1191
- ``@frozen `` for enums and structs. Each of these has a different set of
1174
+ different kinds of declarations: ``@inlinable `` for functions,
1175
+ ``@fixedContents `` for structs, etc . Each of these has a different set of
1192
1176
constraints it enforces on the library author and promises it makes to clients.
1193
- However, they follow a common theme of giving up the flexibility of future
1177
+ However, they all follow a common theme of giving up the flexibility of future
1194
1178
changes in exchange for improved performance and perhaps some semantic
1195
- guarantees. Therefore, these attributes are informally referred to as
1179
+ guarantees. Therefore, all of these attributes are informally referred to as
1196
1180
"fragility attributes".
1197
1181
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
+
1198
1187
1199
1188
Versioning Internal Declarations
1200
1189
================================
@@ -1244,7 +1233,7 @@ at run time if the source code is reorganized, which is unacceptable.
1244
1233
keep things simple we'll stick with the basics.
1245
1234
1246
1235
We could do away with the entire feature if we restricted inlinable functions
1247
- and frozen structs to only refer to public entities. However, this
1236
+ and fixed-contents structs to only refer to public entities. However, this
1248
1237
removes one of the primary reasons to make something inlinable: to allow
1249
1238
efficient access to a type while still protecting its invariants.
1250
1239
@@ -1255,7 +1244,7 @@ efficient access to a type while still protecting its invariants.
1255
1244
*Backdating * refers to releasing a new version of a library that contains
1256
1245
changes, but pretending those changes were made in a previous version of the
1257
1246
library. For example, you might want to release version 1.2 of the "Magician"
1258
- library, but pretend that the "SpellIncantation" struct was frozen
1247
+ library, but pretend that the "SpellIncantation" struct was fixed-contents
1259
1248
since its introduction in version 1.0.
1260
1249
1261
1250
**This is not safe. **
@@ -1264,8 +1253,9 @@ Backdating the availability a versioned entity that was previously non-public
1264
1253
is clearly not safe: older versions of the library will not expose the entity
1265
1254
as part of their ABI. What may be less obvious is that the fragility attributes
1266
1255
likewise are not safe to backdate, even if you know the attributes could have
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.
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.
1269
1259
1270
1260
.. note ::
1271
1261
@@ -1480,7 +1470,7 @@ for verification. Important cases include but are not limited to:
1480
1470
- Unsafe `backdating <#backdating >`_.
1481
1471
1482
1472
- Unsafe modifications to entities marked with fragility attributes, such as
1483
- adding a stored property to a ``@frozen `` struct.
1473
+ adding a stored property to a ``@fixedContents `` struct.
1484
1474
1485
1475
Wherever possible, this tool should also check for `binary-compatible
1486
1476
source-breaking changes <binary-compatible source-breaking change> `, such as
@@ -1637,22 +1627,19 @@ The following proposals (some currently in the process, some planned) will
1637
1627
affect the model described in this document, or concern the parts of this
1638
1628
document that affect language semantics:
1639
1629
1640
- - Non-exhaustive enums (`SE-0192 <SE0192 >`_)
1641
- - Inlineable functions (`SE-0193 <SE0193 >`_)
1642
- - Frozen structs and enums (`SE-0260 <SE0260 >`_)
1643
1630
- (draft) `Overridable methods in extensions `_
1644
1631
- (planned) Restricting retroactive modeling (protocol conformances for types you don't own)
1645
1632
- (planned) `Generalized existentials (values of protocol type) <Generics >`_
1633
+ - (planned) Frozen enums (building on `SE-0192 <SE0192 >`_)
1646
1634
- (planned) Removing the "constant" guarantee for 'let' across module boundaries
1635
+ - (planned) Syntax for declaring fixed-contents structs
1647
1636
- (future) Performance annotations for types
1648
1637
- (future) Attributes for stored property accessors
1649
1638
- (future) Stored properties in extensions
1650
1639
1651
1640
.. _Overridable methods in extensions : https://github.com/jrose-apple/swift-evolution/blob/overridable-members-in-extensions/proposals/nnnn-overridable-members-in-extensions.md
1652
1641
.. _Generics : https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md#generalized-existentials
1653
1642
.. _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
1656
1643
1657
1644
This does not mean all of these proposals need to be accepted, only that their
1658
1645
acceptance or rejection will affect this document.
0 commit comments