You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/ReferenceGuides/UnderscoredAttributes.md
+48-51
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,10 @@ the Swift ABI. This attribute is intended for the SIMD types in the standard
23
23
library which use it to increase the alignment of their internal storage to at
24
24
least 16 bytes.
25
25
26
+
## `@_alwaysEmitConformanceMetadata`
27
+
28
+
Forces conformances of the attributed protocol to always have their Type Metadata get emitted into the binary and prevents it from being optimized away or stripped by the linker.
29
+
26
30
## `@_alwaysEmitIntoClient`
27
31
28
32
Forces the body of a function to be emitted into client code.
@@ -39,6 +43,14 @@ Most notably, default argument expressions are implicitly
39
43
`@_alwaysEmitIntoClient`, which means that adding a default argument to a
40
44
function which did not have one previously does not break ABI.
41
45
46
+
## `@_assemblyVision`
47
+
48
+
Forces emission of assembly vision remarks for a function or method, showing
49
+
where various runtime calls and performance impacting hazards are in the code
50
+
at source level after optimization.
51
+
52
+
Adding this attribute to a type leads to remarks being emitted for all methods.
53
+
42
54
## `@_backDeploy(before: ...)`
43
55
44
56
Causes the body of a function to be emitted into the module interface to be
@@ -53,14 +65,6 @@ client is called instead.
53
65
For more details, see the [pitch thread](https://forums.swift.org/t/pitch-function-back-deployment/55769/)
54
66
in the forums.
55
67
56
-
## `@_assemblyVision`
57
-
58
-
Forces emission of assembly vision remarks for a function or method, showing
59
-
where various runtime calls and performance impacting hazards are in the code
60
-
at source level after optimization.
61
-
62
-
Adding this attribute to a type leads to remarks being emitted for all methods.
63
-
64
68
## `@_borrowed`
65
69
66
70
Indicates that the [conservative access pattern](/docs/Lexicon.md#access-pattern)
@@ -482,6 +486,19 @@ Fun fact: Rust has a very similar concept called
482
486
including one called `Send`,
483
487
which inspired the design of `Sendable`.
484
488
489
+
## `@_noAllocation`, `@_noLocks`
490
+
491
+
These attributes are performance annotations. If a function is annotated with
492
+
such an attribute, the compiler issues a diagnostic message if the function
493
+
calls a runtime function which allocates memory or locks, respectively.
494
+
The `@_noLocks` attribute implies `@_noAllocation` because a memory allocation
495
+
also locks.
496
+
497
+
## `@_noImplicitCopy`
498
+
499
+
Marks a var decl as a variable that must be copied explicitly using the builtin
500
+
function Builtin.copy.
501
+
485
502
## `@_nonEphemeral`
486
503
487
504
Marks a function parameter that cannot accept a temporary pointer produced from
@@ -755,6 +772,14 @@ Clients can access SPI by marking the import as `@_spi(spiName) import Module`.
755
772
This design makes it easy to find out which clients are using certain SPIs by
756
773
doing a textual search.
757
774
775
+
## `@_spi_available(platform, version)`
776
+
777
+
Like `@available`, this attribute indicates a decl is available only as an SPI.
778
+
This implies several behavioral changes comparing to regular `@available`:
779
+
1. Type checker diagnoses when a client accidently exposes such a symbol in library APIs.
780
+
2. When emitting public interfaces, `@_spi_available` is printed as `@available(platform, unavailable)`.
781
+
3. ClangImporter imports ObjC macros `SPI_AVAILABLE` and `__SPI_AVAILABLE` to this attribute.
782
+
758
783
## `@_staticInitializeObjCMetadata`
759
784
760
785
Indicates that a static initializer should be emitted to register the
@@ -789,19 +814,11 @@ A type eraser has the following restrictions:
789
814
This feature was designed to be used for compiler-driven type erasure for
790
815
dynamic replacement of functions with an opaque return type.
791
816
792
-
## `@_weakLinked`
793
-
794
-
Allows a declaration to be weakly-referenced, i.e., any references emitted by
795
-
client modules to the declaration's symbol will have weak linkage. This means
796
-
that client code will compile without the guarantee that the symbol will be
797
-
available at runtime. This requires a dynamic safety check (such as using
798
-
`dlsym (3)`); otherwise, accessing the symbol when it is unavailable leads
799
-
to a runtime crash.
817
+
## `@_unavailableFromAsync`
800
818
801
-
This is an unsafe alternative to using `@available`, which is statically checked.
802
-
If the availability of a library symbol is newer than the deployment target of
803
-
the client, the symbol will be weakly linked, but checking for `@available` and
804
-
`#(un)available` ensures that a symbol is not accessed when it is unavailable.
819
+
Marks a synchronous API as being unavailable from asynchronous contexts. Direct
820
+
usage of annotated API from asynchronous contexts will result in a warning from
821
+
the compiler.
805
822
806
823
## `@_unsafeMainActor`, `@_unsafeSendable`
807
824
@@ -812,38 +829,23 @@ within Swift 5 code that has adopted concurrency, but non-`@MainActor`
812
829
See the forum post on [Concurrency in Swift 5 and 6](https://forums.swift.org/t/concurrency-in-swift-5-and-6/49337)
813
830
for more details.
814
831
815
-
## `@_noImplicitCopy`
816
-
817
-
Marks a var decl as a variable that must be copied explicitly using the builtin
818
-
function Builtin.copy.
819
-
820
-
## `@_noAllocation`, `@_noLocks`
821
-
822
-
These attributes are performance annotations. If a function is annotated with
823
-
such an attribute, the compiler issues a diagnostic message if the function
824
-
calls a runtime function which allocates memory or locks, respectively.
825
-
The `@_noLocks` attribute implies `@_noAllocation` because a memory allocation
826
-
also locks.
827
-
828
-
## `@_unavailableFromAsync`
829
-
830
-
Marks a synchronous API as being unavailable from asynchronous contexts. Direct
831
-
usage of annotated API from asynchronous contexts will result in a warning from
832
-
the compiler.
833
-
834
832
## `@_unsafeInheritExecutor`
835
833
836
834
This `async` function uses the pre-SE-0338 semantics of unsafely inheriting the caller's executor. This is an underscored feature because the right way of inheriting an executor is to pass in the required executor and switch to it. Unfortunately, there are functions in the standard library which need to inherit their caller's executor but cannot change their ABI because they were not defined as `@_alwaysEmitIntoClient` in the initial release.
837
835
836
+
## `@_weakLinked`
838
837
839
-
## `@_spi_available(platform, version)`
840
-
841
-
Like `@available`, this attribute indicates a decl is available only as an SPI.
842
-
This implies several behavioral changes comparing to regular `@available`:
843
-
1. Type checker diagnoses when a client accidently exposes such a symbol in library APIs.
844
-
2. When emitting public interfaces, `@_spi_available` is printed as `@available(platform, unavailable)`.
845
-
3. ClangImporter imports ObjC macros `SPI_AVAILABLE` and `__SPI_AVAILABLE` to this attribute.
838
+
Allows a declaration to be weakly-referenced, i.e., any references emitted by
839
+
client modules to the declaration's symbol will have weak linkage. This means
840
+
that client code will compile without the guarantee that the symbol will be
841
+
available at runtime. This requires a dynamic safety check (such as using
842
+
`dlsym (3)`); otherwise, accessing the symbol when it is unavailable leads
843
+
to a runtime crash.
846
844
845
+
This is an unsafe alternative to using `@available`, which is statically checked.
846
+
If the availability of a library symbol is newer than the deployment target of
847
+
the client, the symbol will be weakly linked, but checking for `@available` and
848
+
`#(un)available` ensures that a symbol is not accessed when it is unavailable.
847
849
848
850
## `_local`
849
851
@@ -852,8 +854,3 @@ the distributed actor isolation checks. This is used for things like `whenLocal`
852
854
where the actor passed to the closure is known-to-be-local, and similarly a
853
855
`self` of obtained from an _isolated_ function inside a distributed actor is
854
856
also guaranteed to be local by construction.
855
-
856
-
857
-
## `@_alwaysEmitConformanceMetadata`
858
-
859
-
Forces conformances of the attributed protocol to always have their Type Metadata get emitted into the binary and prevents it from being optimized away or stripped by the linker.
0 commit comments