@@ -48,8 +48,6 @@ published should not limit its evolution in the future.
48
48
49
49
- Drew Crawford is concerned about inlineable code breaking modularity;
50
50
you can't just release a new dylib to fix a bug.
51
- - Joe Groff has brought up always-emitted-into-the-client code, which has
52
- fewer restrictions and different behavior than may-inline code.
53
51
- David Owens wants it to be clearer that this document doesn't really
54
52
cover behavior changes and proper semantic versioning, just binary
55
53
compatibility.
@@ -322,7 +320,6 @@ available to clients as part of the module's public interface. ``@inlineable``
322
320
is a `versioned attribute `; clients may not assume that the body of the
323
321
function is suitable when deploying against older versions of the library.
324
322
325
-
326
323
Clients are not required to inline a function marked ``@inlineable ``.
327
324
328
325
.. note ::
@@ -369,11 +366,13 @@ and the ``x`` and ``y`` properties have now disappeared. To avoid this, the bodi
369
366
370
367
- They may not define any local types (other than typealiases).
371
368
372
- - They must not reference any ``private `` entities, except for local functions
373
- declared within the inlineable function itself.
369
+ - They must not reference any ``private `` entities, except for those marked
370
+ ``@always_emit_into_client `` (see below). This includes local functions
371
+ defined within the inlineable function.
374
372
375
373
- They must not reference any ``internal `` entities except for those that have
376
- been `versioned `_. See below for a discussion of versioning internal API.
374
+ been `versioned `_ and those declared ``@always_emit_into_client ``. See below
375
+ for a discussion of versioning internal API.
377
376
378
377
- They must not reference any entities from the current module introduced
379
378
after the function was made inlineable.
@@ -386,29 +385,85 @@ as the current body makes sense when deploying against an earlier version of
386
385
the library.
387
386
388
387
389
- Local Functions
390
- ---------------
388
+ ``@always_emit_into_client ``
389
+ ----------------------------
390
+
391
+ The normal ``@inlineable `` attribute states that a function *may * be inlined
392
+ into a client binary. There are a few cases where it is worth *guaranteeing *
393
+ that the function is emitted into the client:
394
+
395
+ - The function is used to determine which version of the library a client was
396
+ compiled against.
397
+
398
+ - The function is a helper for an ``@inlineable `` function, but should not be
399
+ part of the library's ABI.
400
+
401
+ This is handled by the ``@always_emit_into_client `` attribute. If one of these
402
+ functions is referenced by a client module, its implementation is always copied
403
+ into the client module. ``@always_emit_into_client `` functions are subject to
404
+ the same restrictions as regular ``@inlineable `` functions, as described above.
405
+ The description "inlineable" collectively refers to declarations marked with
406
+ ``@inlineable `` and declarations marked with ``@always_emit_into_client ``.
407
+
408
+ .. note ::
409
+
410
+ This is represented by a ``shared `` function in SIL.
411
+
412
+ .. admonition :: TODO
413
+
414
+ All of these names are provisional.
415
+
416
+ Any local functions or closures within an function marked ``@inlineable `` or
417
+ ``@always_emit_into_client `` are themselves treated as
418
+ ``@always_emit_into_client ``. This is important in case it is necessary to
419
+ change the inlineable function later; existing clients should not be depending
420
+ on internal details of the previous implementation.
421
+
422
+ ``@always_emit_into_client `` is a `versioned attribute `; clients may not assume
423
+ that the body of the function is suitable when deploying against older versions
424
+ of the library. Local functions and closures implicitly have the same
425
+ availability as the enclosing function's ``@always_emit_into_client `` or
426
+ ``@inlineable `` attribute. An existing ``@inlineable `` function may not be
427
+ changed to an ``@always_emit_into_client `` function or vice versa.
391
428
392
- If an inlineable function contains local functions or closures, these are
393
- implicitly made inlineable as well. This is important in case the library
394
- author decides to change the inlineable function later. If the inlineable
395
- function is emitted into a client module as described above, the local
396
- functions must be as well. (At the SIL level, these local functions are
397
- considered to have ``shared `` linkage.)
429
+ .. note ::
430
+
431
+ If the ``@always_emit_into_client `` attribute is added to a function that
432
+ was available in a previous version of the library, clearly existing
433
+ clients will still depend on the presence of that function in the library's
434
+ ABI. However, allowing ``@always_emit_into_client `` to be converted into
435
+ ``@inlineable `` in *some * cases but not *all * makes for a more confusing
436
+ model with very little gain.
437
+
438
+ Although they are not a supported feature for arbitrary libraries at this time,
439
+ `transparent `_ functions are implicitly marked ``@always_emit_into_client ``.
440
+ (Note that ``@_transparent `` is *not * a versioned attribute and cannot be added
441
+ to a function after the fact.)
442
+
443
+ .. _transparent : https://github.com/apple/swift/blob/master/docs/TransparentAttr.rst
444
+
445
+ .. note ::
446
+
447
+ Why have both ``@inlineable `` and ``@always_emit_into_client ``? Because for
448
+ a larger function, like ``MutableCollectionType.sort ``, it may be useful to
449
+ provide the body to clients for analysis, but not duplicate code when not
450
+ necessary.
398
451
399
- Local functions are subject to the same restrictions as the inlineable
400
- functions containing them, as described above.
452
+ .. admonition :: TODO
453
+
454
+ What does it mean for an ``@always_emit_into_client `` declaration to
455
+ satisfy a protocol requirement?
401
456
402
457
403
458
Default Argument Expressions
404
459
----------------------------
405
460
406
- Default argument expressions are subject to the same restrictions as inlineable
407
- functions, because they are implemented as inlineable functions. However,
408
- default arguments are *always * inlined into their callers and cannot be
409
- referenced as first-class functions, so they do not need to be versioned. (More
410
- explicitly, a default argument implicitly has the same availability as the
411
- function it is attached to.)
461
+ Default argument expressions are implemented as `` @always_emit_into_client ``
462
+ functions and thus are subject to the same restrictions as inlineable
463
+ functions. However, default arguments are *always * inlined into their callers
464
+ and cannot be referenced as first-class functions, so they do not need to be
465
+ versioned. (More explicitly, a default argument implicitly has the same
466
+ availability as the function it is attached to.)
412
467
413
468
.. note ::
414
469
@@ -494,8 +549,9 @@ clients to access them more efficiently. This restricts changes a fair amount:
494
549
inlineable while still allowing the setter to change. This would need
495
550
syntax, though.
496
551
497
- Any inlineable accessors must follow the rules for `inlineable functions `_,
498
- as described above.
552
+ Any inlineable accessors must follow the rules for `inlineable functions `_, as
553
+ described above. Top-level computed variables may be marked
554
+ ``@always_emit_into_client ``.
499
555
500
556
Note that if a constant's initial value expression has any observable side
501
557
effects, including the allocation of class instances, it must not be treated
@@ -546,10 +602,11 @@ Methods and Initializers
546
602
547
603
For the most part struct methods and initializers are treated exactly like
548
604
top-level functions. They permit all of the same modifications and can also be
549
- marked ``@inlineable ``, with the same restrictions. Inlineable initializers
550
- must always delegate to another initializer, since new properties may be added
551
- between new releases. For the same reason, initializers declared outside of the
552
- struct's module must always delegate to another initializer.
605
+ marked ``@inlineable `` or ``@always_emit_into_client ``, with the same
606
+ restrictions. Inlineable initializers must always delegate to another
607
+ initializer, since new properties may be added between new releases. For the
608
+ same reason, initializers declared outside of the struct's module must always
609
+ delegate to another initializer.
553
610
554
611
555
612
Properties
@@ -559,10 +616,10 @@ Struct properties behave largely the same as top-level bindings. They permit
559
616
all of the same modifications, and also allow adding or removing an initial
560
617
value entirely.
561
618
562
- Struct properties can also be marked ``@inlineable ``, with the same
563
- restrictions as for top-level bindings. An inlineable stored property may not
564
- become computed, but the offset of its storage within the struct is not
565
- necessarily fixed.
619
+ Struct properties can also be marked ``@inlineable `` or
620
+ `` @always_emit_into_client ``, with the same restrictions as for top-level
621
+ bindings. An inlineable stored property may not become computed, but the offset
622
+ of its storage within the struct is not necessarily fixed.
566
623
567
624
.. note ::
568
625
@@ -571,6 +628,8 @@ necessarily fixed.
571
628
be fixed. This would have to be balanced against other goals for struct
572
629
layout.
573
630
631
+ Only computed properties may be marked ``@always_emit_into_client ``.
632
+
574
633
Like top-level constants, it is *not * safe to change a ``let `` property into a
575
634
variable or vice versa. Properties declared with ``let `` are assumed not to
576
635
change for the entire lifetime of the program once they have been initialized.
@@ -586,8 +645,8 @@ stored subscripts. This means that the following changes are permitted:
586
645
- Adding or removing a non-public, non-versioned setter.
587
646
- Changing the body of an accessor.
588
647
589
- Like properties, subscripts can be marked ``@inlineable ``, which restricts the
590
- set of changes:
648
+ Like properties, subscripts can be marked ``@inlineable `` or
649
+ `` @always_emit_into_client ``, which restricts the set of changes:
591
650
592
651
- Adding a versioned setter is still permitted.
593
652
- Adding or removing a non-public, non-versioned setter is still permitted.
@@ -684,8 +743,9 @@ still be modified in limited ways:
684
743
- A versioned ``internal `` property may be made ``public `` (without changing
685
744
its version).
686
745
687
- An initializer of a fixed-contents struct may be declared ``@inlineable `` even
688
- if it does not delegate to another initializer, as long as the ``@inlineable ``
746
+ An initializer of a fixed-contents struct may be declared ``@inlineable `` or
747
+ ``@always_emit_into_client `` even if it does not delegate to another
748
+ initializer, as long as the ``@inlineable `` or ``@always_emit_into_client ``
689
749
attribute is not introduced earlier than the ``@fixed_contents `` attribute and
690
750
the struct has no non-versioned stored properties.
691
751
@@ -764,9 +824,10 @@ Initializers
764
824
765
825
For the most part enum initializers are treated exactly like top-level
766
826
functions. They permit all of the same modifications and can also be marked
767
- ``@inlineable ``, with the same restrictions. Unlike struct initializers, enum
768
- initializers do not always need to delegate to another initializer, even if
769
- they are ``@inlineable `` or declared in a separate module.
827
+ ``@inlineable `` or ``@always_emit_into_client ``, with the same restrictions.
828
+ Unlike struct initializers, enum initializers do not always need to delegate to
829
+ another initializer, even if they are inlineable or declared in a separate
830
+ module.
770
831
771
832
772
833
Methods and Subscripts
@@ -961,9 +1022,9 @@ convenience initializer; that initializer may only call existing ``required``
961
1022
initializers. An existing initializer may not be marked ``required ``.
962
1023
963
1024
All of the modifications permitted for top-level functions are also permitted
964
- for class initializers. Convenience initializers may be marked ``@inlineable ``,
965
- with the same restrictions as top-level functions; designated initializers may
966
- not.
1025
+ for class initializers. Convenience initializers may be marked ``@inlineable ``
1026
+ or `` @always_emit_into_client ``, with the same restrictions as top-level
1027
+ functions; designated initializers may not.
967
1028
968
1029
969
1030
Methods
@@ -987,7 +1048,8 @@ top-level functions, but the potential for overrides complicates things a little
987
1048
988
1049
Class and instance methods may be marked ``@inlineable ``, with the same
989
1050
restrictions as struct methods. ``dynamic `` methods may not be marked
990
- ``@inlineable ``.
1051
+ ``@inlineable ``. Only non-overriding ``final `` methods may be marked
1052
+ ``@always_emit_into_client ``.
991
1053
992
1054
If an inlineable method is overridden, the overriding method does not need to
993
1055
also be inlineable. Clients may only inline a method when they can devirtualize
@@ -1026,8 +1088,9 @@ Constant properties (those declared with ``let``) still permit changing their
1026
1088
value, as well as adding or removing an initial value entirely.
1027
1089
1028
1090
Both variable and constant properties (on both instances and classes) may be
1029
- marked ``@inlineable ``. This behaves as described for struct properties.
1030
- ``dynamic `` properties may not be marked ``@inlineable ``.
1091
+ marked ``@inlineable ``; non-overriding ``final `` computed properties may also
1092
+ be marked ``@always_emit_into_client ``. This behaves as described for struct
1093
+ properties. ``dynamic `` properties may not be marked ``@inlineable ``.
1031
1094
1032
1095
If an inlineable property is overridden, the overriding property does not need
1033
1096
to also be inlineable. Clients may only inline a property access when they can
@@ -1050,7 +1113,9 @@ Adding a public setter to a subscript that may be overridden is a
1050
1113
know what to do with the setter and will likely not behave correctly.
1051
1114
1052
1115
Class subscripts may be marked ``@inlineable ``, which behaves as described for
1053
- struct subscripts. ``dynamic `` subscripts may not be marked ``@inlineable ``.
1116
+ struct subscripts. Non-overriding ``final `` subscripts may also be marked
1117
+ ``@always_emit_into_client ``. ``dynamic `` subscripts may not be marked
1118
+ ``@inlineable ``.
1054
1119
1055
1120
If an inlineable subscript is overridden, the overriding subscript does not need
1056
1121
to also be inlineable. Clients may only inline a subscript access when they can
@@ -1235,7 +1300,8 @@ As the sole exception, it is safe to backdate ``@inlineable`` on a top-level
1235
1300
function, a method, a subscript, or a struct or enum initializer. It is not
1236
1301
safe to backdate ``@inlineable `` for a top-level variable or constant, a
1237
1302
property, or a class initializer. As usual, a library author may not assume
1238
- that a client will actually inline the call.
1303
+ that a client will actually inline the call. It is not safe to backdate the
1304
+ ``@always_emit_into_client `` attribute.
1239
1305
1240
1306
.. note ::
1241
1307
@@ -1298,8 +1364,8 @@ outside the current module, since once it's inlined it will be.
1298
1364
1299
1365
For inlineable code, the availability context is exactly the same as the
1300
1366
equivalent non-inlineable code except that the assumed version of the
1301
- containing library is the version attached to the ``@inlineable `` attribute,
1302
- and any `library version dependencies
1367
+ containing library is the version attached to the ``@inlineable `` or
1368
+ `` @always_emit_into_client `` attribute, and any `library version dependencies
1303
1369
<#declaring-library-version-dependencies> `_ or minimum deployment target must
1304
1370
be specified explicitly using ``@available ``. Code within this context must be
1305
1371
treated as if the containing library were just a normal dependency.
0 commit comments