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
@@ -125,6 +125,35 @@ Use of this attribute imposes limitations on what can be in the body. For more d
125
125
126
126
This is currently used in the standard library as an additional annotation applied to @objc protocols signifying that any objects which conform to this protocol are not tagged. This means that (on Darwin platforms) such references, unlike AnyObject, have spare bits available from things like restricted memory spaces or alignment.
127
127
128
+
#### `@_silgen_name`
129
+
130
+
This attribute specifies the name that a declaration will have at link time. It is used for two purposes, the second of which is currently considered bad practice and should be replaced with shims:
131
+
132
+
1. To specify the symbol name of a Swift function so that it can be called from Swift-aware C. Such functions have bodies.
133
+
2. To provide a Swift declaration which really represents a C declaration. Such functions do not have bodies.
134
+
135
+
##### Using `@_silgen_name` to call Swift from Swift-aware C
136
+
137
+
Rather than hard-code Swift mangling into C code, `@_silgen_name` is used to provide a stable and known symbol name for linking. Note that C code still must understand and use the Swift calling convention (available in swift-clang) for such Swift functions (if they use Swift's CC). Example:
// ... C code can now call _swift_stdlib_destroyTLS on a void * ...
150
+
```
151
+
152
+
##### Using `@_silgen_name` to call C from Swift
153
+
154
+
The standard library cannot import the Darwin module (much less an ICU module), yet it needs access to these C functions that it otherwise wouldn't have a decl for. For that, we use shims. But, `@_silgen_name` can also be used on a body-less Swift function declaration to denote that it's an external C function whose symbol will be available at link time, even if not available at compile time. This usage is discouraged.
0 commit comments