Skip to content

Commit 2ce6f1e

Browse files
committed
[docs] LibraryEvolution: Camel-case hypothetical attributes.
...and update one example to follow the Swift 3 API guidelines. No semantic changes.
1 parent 4562567 commit 2ce6f1e

File tree

1 file changed

+50
-49
lines changed

1 file changed

+50
-49
lines changed

docs/LibraryEvolution.rst

Lines changed: 50 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -355,14 +355,14 @@ example using methods::
355355
}
356356

357357
extension Point2D {
358-
@inlineable public func distanceTo(_ other: Point2D) -> Double {
358+
@inlineable public func distance(to other: Point2D) -> Double {
359359
let deltaX = self.x - other.x
360360
let deltaY = self.y - other.y
361361
return sqrt(deltaX*deltaX + deltaY*deltaY)
362362
}
363363
}
364364

365-
As written, this ``distanceTo`` method is not safe to inline. The next release
365+
As written, this ``distance`` method is not safe to inline. The next release
366366
of the library could very well replace the implementation of ``Point2D`` with a
367367
polar representation::
368368

@@ -371,15 +371,16 @@ polar representation::
371371
public init(x: Double, y: Double) { … }
372372
}
373373

374-
and the ``x`` and ``y`` properties have now disappeared. To avoid this, the bodies of inlineable functions have the following restrictions:
374+
and the ``x`` and ``y`` properties have now disappeared. To avoid this, the
375+
bodies of inlineable functions have the following restrictions:
375376

376377
- They may not define any local types (other than typealiases).
377378

378379
- They must not reference any ``private`` or ``fileprivate`` entities, except
379-
for those marked ``@always_emit_into_client`` (see below).
380+
for those marked ``@alwaysEmitIntoClient`` (see below).
380381

381382
- They must not reference any ``internal`` entities except for those that have
382-
been `versioned`_ and those declared ``@always_emit_into_client``. See below
383+
been `versioned`_ and those declared ``@alwaysEmitIntoClient``. See below
383384
for a discussion of versioning internal API.
384385

385386
- They must not reference any entities from the current module introduced
@@ -393,7 +394,7 @@ as the current body makes sense when deploying against an earlier version of
393394
the library.
394395

395396

396-
``@always_emit_into_client``
397+
``@alwaysEmitIntoClient``
397398
----------------------------
398399

399400
The normal ``@inlineable`` attribute states that a function *may* be inlined
@@ -406,13 +407,13 @@ that the function is emitted into the client:
406407
- The function is a helper for an ``@inlineable`` function, but should not be
407408
part of the library's ABI.
408409

409-
This is handled by the ``@always_emit_into_client`` attribute. If one of these
410+
This is handled by the ``@alwaysEmitIntoClient`` attribute. If one of these
410411
functions is referenced by a client module, its implementation is always copied
411-
into the client module. ``@always_emit_into_client`` functions are subject to
412+
into the client module. ``@alwaysEmitIntoClient`` functions are subject to
412413
the same restrictions as regular ``@inlineable`` functions, as described above.
413414
The description "inlineable" collectively refers to declarations marked with
414-
``@inlineable`` and declarations marked with ``@always_emit_into_client``. A
415-
declaration may not be both ``@inlineable`` and ``@always_emit_into_client``.
415+
``@inlineable`` and declarations marked with ``@alwaysEmitIntoClient``. A
416+
declaration may not be both ``@inlineable`` and ``@alwaysEmitIntoClient``.
416417

417418
.. note::
418419

@@ -421,60 +422,60 @@ declaration may not be both ``@inlineable`` and ``@always_emit_into_client``.
421422
.. admonition:: TODO
422423

423424
All of these names are provisional. In particular, It Would Be Nice(tm) if
424-
the final name for ``@always_emit_into_client`` was a variation of the
425+
the final name for ``@alwaysEmitIntoClient`` was a variation of the
425426
final name for ``@inlineable``.
426427

427428
Any local functions or closures within an inlineable function are themselves
428-
treated as ``@always_emit_into_client``. This is important in case it is
429+
treated as ``@alwaysEmitIntoClient``. This is important in case it is
429430
necessary to change the inlineable function later; existing clients should not
430431
be depending on internal details of the previous implementation.
431432

432-
``@always_emit_into_client`` is *not* a versioned attribute, and therefore it
433+
``@alwaysEmitIntoClient`` is *not* a versioned attribute, and therefore it
433434
may not be added to a declaration that was versioned in a previous release of a
434435
library. An existing ``@inlineable`` function may not be changed to an
435-
``@always_emit_into_client`` function or vice versa.
436+
``@alwaysEmitIntoClient`` function or vice versa.
436437

437438
It is a `binary-compatible source-breaking change` to completely remove a
438-
public entity marked ``@always_emit_into_client`` from a library. (Non-public,
439+
public entity marked ``@alwaysEmitIntoClient`` from a library. (Non-public,
439440
non-versioned entities may always be removed from a library; they are not part
440441
of its API or ABI.)
441442

442-
Removing ``@always_emit_into_client`` from a public entity is also a
443+
Removing ``@alwaysEmitIntoClient`` from a public entity is also a
443444
`binary-compatible source-breaking change`, and requires updating the
444-
availability of that entity. Removing ``@always_emit_into_client`` from a
445+
availability of that entity. Removing ``@alwaysEmitIntoClient`` from a
445446
non-public entity is always permitted.
446447

447448
.. note::
448449

449-
As an example, if an API is marked ``@always_emit_into_client`` in version
450+
As an example, if an API is marked ``@alwaysEmitIntoClient`` in version
450451
1 of a library, and the attribute is removed in version 2, the entity
451452
itself must be updated to state that it is introduced in version 2. This is
452453
equivalent to removing the entity and then adding a new one with the same
453454
name.
454455

455456
Although they are not a supported feature for arbitrary libraries at this time,
456-
`transparent`_ functions are implicitly marked ``@always_emit_into_client``.
457+
`transparent`_ functions are implicitly marked ``@alwaysEmitIntoClient``.
457458

458459
.. _transparent: https://github.com/apple/swift/blob/master/docs/TransparentAttr.rst
459460

460461
.. note::
461462

462-
Why have both ``@inlineable`` and ``@always_emit_into_client``? Because for
463+
Why have both ``@inlineable`` and ``@alwaysEmitIntoClient``? Because for
463464
a larger function, like ``MutableCollectionType.sort``, it may be useful to
464465
provide the body to clients for analysis, but not duplicate code when not
465-
necessary. ``@always_emit_into_client`` also may not be added to an
466+
necessary. ``@alwaysEmitIntoClient`` also may not be added to an
466467
existing versioned declaration.
467468

468469
.. admonition:: TODO
469470

470-
What does it mean for an ``@always_emit_into_client`` declaration to
471+
What does it mean for an ``@alwaysEmitIntoClient`` declaration to
471472
satisfy a protocol requirement?
472473

473474

474475
Default Argument Expressions
475476
----------------------------
476477

477-
Default argument expressions are implemented as ``@always_emit_into_client``
478+
Default argument expressions are implemented as ``@alwaysEmitIntoClient``
478479
functions and thus are subject to the same restrictions as inlineable
479480
functions. A default argument implicitly has the same availability as the
480481
function it is attached to.
@@ -565,7 +566,7 @@ clients to access them more efficiently. This restricts changes a fair amount:
565566

566567
Any inlineable accessors must follow the rules for `inlineable functions`_, as
567568
described above. Top-level computed variables may be marked
568-
``@always_emit_into_client``, with the same restrictions as for functions.
569+
``@alwaysEmitIntoClient``, with the same restrictions as for functions.
569570

570571
Note that if a constant's initial value expression has any observable side
571572
effects, including the allocation of class instances, it must not be treated
@@ -600,7 +601,7 @@ layout.
600601

601602
.. admonition:: TODO
602603

603-
We need to pin down how this, and the ``@fixed_contents`` attribute below,
604+
We need to pin down how this, and the ``@fixedContents`` attribute below,
604605
interacts with the "Behaviors" proposal. Behaviors that just change the
605606
accessors of a property are fine, but those that provide new entry points
606607
are trickier.
@@ -616,7 +617,7 @@ Methods and Initializers
616617

617618
For the most part struct methods and initializers are treated exactly like
618619
top-level functions. They permit all of the same modifications and can also be
619-
marked ``@inlineable`` or ``@always_emit_into_client``, with the same
620+
marked ``@inlineable`` or ``@alwaysEmitIntoClient``, with the same
620621
restrictions. Inlineable initializers must always delegate to another
621622
initializer, since new properties may be added between new releases. For the
622623
same reason, initializers declared outside of the struct's module must always
@@ -631,7 +632,7 @@ all of the same modifications, and also allow adding or removing an initial
631632
value entirely.
632633

633634
Struct properties can also be marked ``@inlineable`` or
634-
``@always_emit_into_client``, with the same restrictions as for top-level
635+
``@alwaysEmitIntoClient``, with the same restrictions as for top-level
635636
bindings. An inlineable stored property may not become computed, but the offset
636637
of its storage within the struct is not necessarily fixed.
637638

@@ -642,7 +643,7 @@ of its storage within the struct is not necessarily fixed.
642643
be fixed. This would have to be balanced against other goals for struct
643644
layout.
644645

645-
Only computed properties may be marked ``@always_emit_into_client``.
646+
Only computed properties may be marked ``@alwaysEmitIntoClient``.
646647

647648
Like top-level constants, it is *not* safe to change a ``let`` property into a
648649
variable or vice versa. Properties declared with ``let`` are assumed not to
@@ -660,7 +661,7 @@ stored subscripts. This means that the following changes are permitted:
660661
- Changing the body of an accessor.
661662

662663
Like properties, subscripts can be marked ``@inlineable`` or
663-
``@always_emit_into_client``, which restricts the set of changes:
664+
``@alwaysEmitIntoClient``, which restricts the set of changes:
664665

665666
- Adding a versioned setter is still permitted.
666667
- Adding or removing a non-public, non-versioned setter is still permitted.
@@ -714,10 +715,10 @@ provides.
714715
Fixed-Contents Structs
715716
----------------------
716717

717-
To opt out of this flexibility, a struct may be marked ``@fixed_contents``.
718+
To opt out of this flexibility, a struct may be marked ``@fixedContents``.
718719
This promises that no stored properties will be added to or removed from the
719720
struct, even non-public ones. Additionally, all versioned instance stored
720-
properties in a ``@fixed_contents`` struct are implicitly declared
721+
properties in a ``@fixedContents`` struct are implicitly declared
721722
``@inlineable`` (as described above for top-level variables). In effect:
722723

723724
- Reordering all members, including stored properties, is still permitted.
@@ -757,12 +758,12 @@ still be modified in limited ways:
757758
its version).
758759

759760
An initializer of a fixed-contents struct may be declared ``@inlineable`` or
760-
``@always_emit_into_client`` even if it does not delegate to another
761+
``@alwaysEmitIntoClient`` even if it does not delegate to another
761762
initializer, as long as the ``@inlineable`` attribute, or the initializer
762-
itself, is not introduced earlier than the ``@fixed_contents`` attribute and
763+
itself, is not introduced earlier than the ``@fixedContents`` attribute and
763764
the struct has no non-versioned stored properties.
764765

765-
A ``@fixed_contents`` struct is *not* guaranteed to use the same layout as a C
766+
A ``@fixedContents`` struct is *not* guaranteed to use the same layout as a C
766767
struct with a similar "shape". If such a struct is necessary, it should be
767768
defined in a C header and imported into Swift.
768769

@@ -774,7 +775,7 @@ defined in a C header and imported into Swift.
774775

775776
.. note::
776777

777-
Hypothetically, we could use a different model where a ``@fixed_contents``
778+
Hypothetically, we could use a different model where a ``@fixedContents``
778779
struct only guarantees the "shape" of the struct, so to speak, while
779780
leaving all property accesses to go through function calls. This would
780781
allow stored properties to change their accessors, or (with the Behaviors
@@ -783,17 +784,17 @@ defined in a C header and imported into Swift.
783784
a simple C-like struct that groups together simple values, with only public
784785
stored properties and no observing accessors, and having to opt into direct
785786
access to those properties seems unnecessarily burdensome. The struct is
786-
being declared ``@fixed_contents`` for a reason, after all: it's been
787+
being declared ``@fixedContents`` for a reason, after all: it's been
787788
discovered that its use is causing performance issues.
788789

789790
Consequently, as a first pass we may just require all stored properties in
790-
a ``@fixed_contents`` struct, public or non-public, to have trivial
791+
a ``@fixedContents`` struct, public or non-public, to have trivial
791792
accessors, i.e. no observing accessors and no behaviors.
792793

793-
``@fixed_contents`` is a `versioned attribute`. This is so that clients can
794+
``@fixedContents`` is a `versioned attribute`. This is so that clients can
794795
deploy against older versions of the library, which may have a different layout
795796
for the struct. (In this case the client must manipulate the struct as if the
796-
``@fixed_contents`` attribute were absent.)
797+
``@fixedContents`` attribute were absent.)
797798

798799

799800
Enums
@@ -837,7 +838,7 @@ Initializers
837838

838839
For the most part enum initializers are treated exactly like top-level
839840
functions. They permit all of the same modifications and can also be marked
840-
``@inlineable`` or ``@always_emit_into_client``, with the same restrictions.
841+
``@inlineable`` or ``@alwaysEmitIntoClient``, with the same restrictions.
841842
Unlike struct initializers, enum initializers do not always need to delegate to
842843
another initializer, even if they are inlineable or declared in a separate
843844
module.
@@ -1036,7 +1037,7 @@ initializers. An existing initializer may not be marked ``required``.
10361037

10371038
All of the modifications permitted for top-level functions are also permitted
10381039
for class initializers. Convenience initializers may be marked ``@inlineable``
1039-
or ``@always_emit_into_client``, with the same restrictions as top-level
1040+
or ``@alwaysEmitIntoClient``, with the same restrictions as top-level
10401041
functions; designated initializers may not.
10411042

10421043

@@ -1062,7 +1063,7 @@ top-level functions, but the potential for overrides complicates things a little
10621063
Class and instance methods may be marked ``@inlineable``, with the same
10631064
restrictions as struct methods. ``dynamic`` methods may not be marked
10641065
``@inlineable``. Only non-overriding ``final`` methods may be marked
1065-
``@always_emit_into_client``.
1066+
``@alwaysEmitIntoClient``.
10661067

10671068
If an inlineable method is overridden, the overriding method does not need to
10681069
also be inlineable. Clients may only inline a method when they can devirtualize
@@ -1102,7 +1103,7 @@ value, as well as adding or removing an initial value entirely.
11021103

11031104
Both variable and constant properties (on both instances and classes) may be
11041105
marked ``@inlineable``; non-overriding ``final`` computed properties may also
1105-
be marked ``@always_emit_into_client``. This behaves as described for struct
1106+
be marked ``@alwaysEmitIntoClient``. This behaves as described for struct
11061107
properties. ``dynamic`` properties may not be marked ``@inlineable``.
11071108

11081109
If an inlineable property is overridden, the overriding property does not need
@@ -1127,7 +1128,7 @@ know what to do with the setter and will likely not behave correctly.
11271128

11281129
Class subscripts may be marked ``@inlineable``, which behaves as described for
11291130
struct subscripts. Non-overriding ``final`` subscripts may also be marked
1130-
``@always_emit_into_client``. ``dynamic`` subscripts may not be marked
1131+
``@alwaysEmitIntoClient``. ``dynamic`` subscripts may not be marked
11311132
``@inlineable``.
11321133

11331134
If an inlineable subscript is overridden, the overriding subscript does not need
@@ -1228,7 +1229,7 @@ A Unifying Theme
12281229

12291230
So far this document has talked about ways to give up flexibility for several
12301231
different kinds of declarations: ``@inlineable`` for functions,
1231-
``@fixed_contents`` for structs, etc. Each of these has a different set of
1232+
``@fixedContents`` for structs, etc. Each of these has a different set of
12321233
constraints it enforces on the library author and promises it makes to clients.
12331234
However, they all follow a common theme of giving up the flexibility of future
12341235
changes in exchange for improved performance and perhaps some semantic
@@ -1271,11 +1272,11 @@ Non-public conformances are never considered versioned, even if both the
12711272
conforming type and the protocol are versioned. A conformance is considered
12721273
public if and only if both the conforming type and protocol are public.
12731274

1274-
Non-public entities declared ``@always_emit_into_client`` may not be versioned.
1275+
Non-public entities declared ``@alwaysEmitIntoClient`` may not be versioned.
12751276

12761277
.. admonition:: TODO
12771278

1278-
...but we do need a way for ``@always_emit_into_client`` functions to
1279+
...but we do need a way for ``@alwaysEmitIntoClient`` functions to
12791280
declare the minimum version of the library they can be used in, right?
12801281
Syntax?
12811282

@@ -1314,7 +1315,7 @@ is clearly not safe: older versions of the library will not expose the entity
13141315
as part of their ABI. What may be less obvious is that the fragility attributes
13151316
likewise are not safe to backdate, even if you know the attributes could have
13161317
been added in the past. To give one example, the presence of ``@closed`` or
1317-
``@fixed_contents`` may affect the layout and calling conventions for an enum
1318+
``@fixedContents`` may affect the layout and calling conventions for an enum
13181319
or struct.
13191320

13201321
As the sole exception, it is safe to backdate ``@inlineable`` on a top-level
@@ -1529,7 +1530,7 @@ for verification. Important cases include but are not limited to:
15291530
- Unsafe `backdating <#backdating>`_.
15301531

15311532
- Unsafe modifications to entities marked with fragility attributes, such as
1532-
adding a stored property to a ``@fixed_contents`` struct.
1533+
adding a stored property to a ``@fixedContents`` struct.
15331534

15341535
Wherever possible, this tool should also check for `binary-compatible
15351536
source-breaking changes <binary-compatible source-breaking change>`, such as

0 commit comments

Comments
 (0)