1
1
# The Swift Runtime
2
2
3
- This document describes the interface to the Swift runtime, which provides
3
+ This document describes the ABI interface to the Swift runtime, which provides
4
4
the following core functionality for Swift programs:
5
5
6
6
- memory management, including allocation and reference counting;
7
7
- the runtime type system, including dynamic casting, generic instantiation,
8
8
and protocol conformance registration;
9
9
10
+ It is intended to describe only the runtime interface that compiler-generated
11
+ code should conform to, not details of how things are implemented.
12
+
10
13
The final runtime interface is currently a work-in-progress; it is a goal of
11
14
Swift 3 to stabilize it. This document attempts to describe both the current
12
15
state of the runtime and the intended endpoint of the stable interface.
16
+ Changes that are intended to be made before stabilization are marked with
17
+ ** ABI TODO** . Entry points that only exist on Darwin platforms with
18
+ ObjC interop, and
19
+ information that only pertains to ObjC interop, are marked ** ObjC-only** .
20
+
21
+ ## Deprecated entry points
22
+
23
+ Entry points in this section are intended to be removed or internalized before
24
+ ABI stabilization.
25
+
26
+ ### Exported C++ symbols
27
+
28
+ ** ABI TODO** : Any exported C++ symbols are implementation details that are not
29
+ intended to be part of the stable runtime interface.
30
+
31
+ ### ` _swift_ClassMirror_count `
32
+ ### ` _swift_ClassMirror_quickLookObject `
33
+ ### ` _swift_ClassMirror_subscript `
34
+ ### ` _swift_EnumMirror_caseName `
35
+ ### ` _swift_EnumMirror_count `
36
+ ### ` _swift_EnumMirror_subscript `
37
+ ### ` _swift_MagicMirrorData_objcValue `
38
+ ### ` _swift_MagicMirrorData_objcValueType `
39
+ ### ` _swift_MagicMirrorData_summary `
40
+ ### ` _swift_MagicMirrorData_value `
41
+ ### ` _swift_MagicMirrorData_valueType `
42
+ ### ` _swift_ObjCMirror_count `
43
+ ### ` _swift_ObjCMirror_subscript `
44
+ ### ` _swift_StructMirror_count `
45
+ ### ` _swift_StructMirror_subscript `
46
+ ### ` _swift_TupleMirror_count `
47
+ ### ` _swift_TupleMirror_subscript `
48
+ ### ` _swift_reflectAny `
49
+
50
+ ** ABI TODO** : These functions are implementation details of the standard
51
+ library ` reflect ` interface. They will be superseded by a low-level
52
+ runtime reflection API.
53
+
54
+ ## Memory allocation
55
+
56
+ ### TODO
57
+
58
+ ```
59
+ ```
60
+
61
+ ## Reference counting
62
+
63
+
64
+ ### swift\_ retainCount
65
+
66
+ ```
67
+ @convention(c) (@unowned NativeObject) -> UInt
68
+ ```
69
+
70
+ Returns a random number.
71
+
72
+ ** ABI TODO** : Only used by runtime tests and ` SwiftObject.mm ` . Should be
73
+ internalized.
74
+
75
+ ### TODO
76
+
77
+ ```
78
+ 0000000000027ba0 T _swift_bridgeObjectRelease
79
+ 0000000000027c50 T _swift_bridgeObjectRelease_n
80
+ 0000000000027b50 T _swift_bridgeObjectRetain
81
+ 0000000000027be0 T _swift_bridgeObjectRetain_n
82
+ 000000000001ce70 T _swift_release
83
+ 000000000001cee0 T _swift_release_n
84
+ 000000000001ce30 T _swift_retain
85
+ 000000000001ce50 T _swift_retain_n
86
+ 000000000001d140 T _swift_tryPin
87
+ 000000000001d240 T _swift_tryRetain
88
+ 0000000000027b10 T _swift_unknownRelease
89
+ 0000000000027a70 T _swift_unknownRelease_n
90
+ 0000000000027ad0 T _swift_unknownRetain
91
+ 0000000000027a10 T _swift_unknownRetain_n
92
+ 0000000000027d50 T _swift_unknownUnownedAssign
93
+ 00000000000280a0 T _swift_unknownUnownedCopyAssign
94
+ 0000000000027fd0 T _swift_unknownUnownedCopyInit
95
+ 0000000000027ed0 T _swift_unknownUnownedDestroy
96
+ 0000000000027cb0 T _swift_unknownUnownedInit
97
+ 0000000000027f20 T _swift_unknownUnownedLoadStrong
98
+ 00000000000281f0 T _swift_unknownUnownedTakeAssign
99
+ 0000000000028070 T _swift_unknownUnownedTakeInit
100
+ 0000000000027f70 T _swift_unknownUnownedTakeStrong
101
+ 00000000000282b0 T _swift_unknownWeakAssign
102
+ 0000000000028560 T _swift_unknownWeakCopyAssign
103
+ 00000000000284e0 T _swift_unknownWeakCopyInit
104
+ 00000000000283e0 T _swift_unknownWeakDestroy
105
+ 0000000000028270 T _swift_unknownWeakInit
106
+ 0000000000028420 T _swift_unknownWeakLoadStrong
107
+ 0000000000028610 T _swift_unknownWeakTakeAssign
108
+ 0000000000028520 T _swift_unknownWeakTakeInit
109
+ 0000000000028470 T _swift_unknownWeakTakeStrong
110
+ 000000000001d3c0 T _swift_unownedCheck
111
+ 000000000001cfb0 T _swift_unownedRelease
112
+ 000000000001d0a0 T _swift_unownedRelease_n
113
+ 000000000001cf70 T _swift_unownedRetain
114
+ 000000000001cf60 T _swift_unownedRetainCount
115
+ 000000000001d2b0 T _swift_unownedRetainStrong
116
+ 000000000001d310 T _swift_unownedRetainStrongAndRelease
117
+ 000000000001d060 T _swift_unownedRetain_n
118
+ 000000000001d1b0 T _swift_unpin
119
+ 000000000001ca20 T _swift_verifyEndOfLifetime
120
+ 000000000001d680 T _swift_weakAssign
121
+ 000000000001d830 T _swift_weakCopyAssign
122
+ 000000000001d790 T _swift_weakCopyInit
123
+ 000000000001d770 T _swift_weakDestroy
124
+ 000000000001d640 T _swift_weakInit
125
+ 000000000001d6d0 T _swift_weakLoadStrong
126
+ 000000000001d8b0 T _swift_weakTakeAssign
127
+ 000000000001d800 T _swift_weakTakeInit
128
+ 000000000001d710 T _swift_weakTakeStrong
129
+ ```
130
+
131
+ ** ABI TODO** : ` _unsynchronized ` r/r entry points
132
+
133
+ ## Error objects
134
+
135
+ The ` ErrorType ` existential type uses a special single-word, reference-
136
+ counted representation.
137
+
138
+ ** ObjC-only** : The representation is internal to the runtime in order
139
+ to provide efficient bridging with the platform ` NSError ` and ` CFError `
140
+ implementations. On non-ObjC platforms this bridging is unnecessary, and
141
+ the error object interface could be made more fragile.
13
142
14
- ## Entry points
143
+ To preserve the encapsulation of the ErrorType representation, and
144
+ allow for future representation optimizations, the runtime provides
145
+ special entry points for allocating, projecting, and reference
146
+ counting error values.
15
147
16
- TODO
17
148
18
149
```
19
- 0000000000000000 T __Z13class_getNamePKN5swift13ClassMetadataE
20
- 000000000001c660 T __ZN5swift10fatalErrorEPKcz
21
- 00000000000267b0 T __ZN5swift15getNSErrorClassEv
22
- 0000000000000010 T __ZN5swift15nameForMetadataEPKNS_8MetadataEb
23
- 000000000001e340 T __ZN5swift17MetadataAllocator5allocEm
24
- 000000000002b3c0 T __ZN5swift17getRootSuperclassEv
25
- 00000000000009d0 T __ZN5swift24swift_dynamicCastFailureEPKNS_8MetadataES2_PKc
26
- 0000000000000980 T __ZN5swift24swift_dynamicCastFailureEPKvPKcS1_S3_S3_
27
- 0000000000022600 T __ZN5swift27installCommonValueWitnessesEPNS_17ValueWitnessTableE
28
- 0000000000026de0 T __ZN5swift28tryDynamicCastNSErrorToValueEPNS_11OpaqueValueES1_PKNS_8MetadataES4_NS_16DynamicCastFlagsE
29
- 0000000000023930 T __ZN5swift32swift_assignExistentialWithCopy0EPNS_11OpaqueValueEPKS0_PKNS_8MetadataE
30
- 00000000000239b0 T __ZN5swift32swift_assignExistentialWithCopy1EPNS_11OpaqueValueEPKS0_PKNS_8MetadataE
31
- 000000000002c420 T __ZN5swift8Demangle10mangleNodeERKNSt3__110shared_ptrINS0_4NodeEEE
32
- 0000000000007550 T __ZN5swift8Demangle12nodeToStringENSt3__110shared_ptrINS0_4NodeEEERKNS0_15DemangleOptionsE
33
- 000000000002c180 T __ZN5swift8Demangle16mangleIdentifierEPKcmNS0_12OperatorKindERNSt3__112basic_stringIcNS4_11char_traitsIcEENS4_9allocatorIcEEEEb
34
- 00000000000074a0 T __ZN5swift8Demangle18demangleTypeAsNodeEPKcmRKNS0_15DemangleOptionsE
35
- 00000000000049e0 T __ZN5swift8Demangle20demangleSymbolAsNodeEPKcmRKNS0_15DemangleOptionsE
36
- 0000000000007790 T __ZN5swift8Demangle20demangleTypeAsStringEPKcmRKNS0_15DemangleOptionsE
37
- 0000000000007630 T __ZN5swift8Demangle22demangleSymbolAsStringEPKcmRKNS0_15DemangleOptionsE
38
- 00000000000049d0 T __ZN5swift8Demangle4NodeD1Ev
39
- 0000000000004900 T __ZN5swift8Demangle4NodeD2Ev
40
- 00000000000078f0 T __ZN5swift8Punycode14decodePunycodeEN4llvm9StringRefERNSt3__16vectorIjNS3_9allocatorIjEEEE
41
- 0000000000007c70 T __ZN5swift8Punycode14encodePunycodeERKNSt3__16vectorIjNS1_9allocatorIjEEEERNS1_12basic_stringIcNS1_11char_traitsIcEENS3_IcEEEE
42
- 0000000000007fc0 T __ZN5swift8Punycode18decodePunycodeUTF8EN4llvm9StringRefERNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE
43
- 000000000002f720 T __ZN5swift8Punycode18encodePunycodeUTF8EN4llvm9StringRefERNSt3__112basic_stringIcNS3_11char_traitsIcEENS3_9allocatorIcEEEE
44
- 0000000000026910 T __ZNK5swift10SwiftError13isPureNSErrorEv
45
- 0000000000026960 T __ZNK5swift10SwiftError19getErrorConformanceEv
46
- 00000000000266c0 T __ZNK5swift10SwiftError7getTypeEv
47
- 0000000000023430 T __ZNK5swift23ExistentialTypeMetadata12mayTakeValueEPKNS_11OpaqueValueE
48
- 00000000000234a0 T __ZNK5swift23ExistentialTypeMetadata12projectValueEPKNS_11OpaqueValueE
49
- 0000000000023550 T __ZNK5swift23ExistentialTypeMetadata14getDynamicTypeEPKNS_11OpaqueValueE
50
- 00000000000235a0 T __ZNK5swift23ExistentialTypeMetadata15getWitnessTableEPKNS_11OpaqueValueEj
51
- 0000000000023400 T __ZNK5swift23ExistentialTypeMetadata17getRepresentationEv
52
- 0000000000023460 T __ZNK5swift23ExistentialTypeMetadata26deinitExistentialContainerEPNS_11OpaqueValueE
53
- 0000000000002ee0 T __ZNK5swift25ProtocolConformanceRecord15getWitnessTableEPKNS_8MetadataE
54
- 0000000000002e30 T __ZNK5swift25ProtocolConformanceRecord24getCanonicalTypeMetadataEv
55
- 0000000000023e30 T __ZNK5swift8Metadata14getClassObjectEv
56
- 0000000000023de0 T __ZNK5swift8Metadata17getGenericPatternEv
57
- 0000000000023da0 T __ZNK5swift8Metadata24getNominalTypeDescriptorEv
58
- 00000000000048b0 T __ZNR5swift8Demangle16DemanglerPrinterlsEx
59
- 0000000000004860 T __ZNR5swift8Demangle16DemanglerPrinterlsEy
150
+ 00000000000268e0 T _swift_allocError
151
+ 0000000000026d50 T _swift_bridgeErrorTypeToNSError
152
+ 0000000000026900 T _swift_deallocError
153
+ 0000000000027120 T _swift_errorRelease
154
+ 0000000000027100 T _swift_errorRetain
155
+ 0000000000026b80 T _swift_getErrorValue
156
+ ```
157
+
158
+ ** ABI TODO** : ` _unsynchronized ` r/r entry points
159
+
160
+ ** ABI TODO** : ` _n ` r/r entry points
161
+
162
+ ### swift\_ convertErrorTypeToNSError, swift\_ convertNSErrorToErrorType
163
+
164
+ ** ObjC-only** . Standard library entry points used to handle implicit conversions
165
+ between ` ErrorType ` and ` NSError ` .
166
+
167
+ ** ABI TODO** : These should be implemented as shims or in Swift code, not
168
+ in the runtime.
169
+
170
+ ## TODO
171
+
172
+ ```
60
173
000000000002b340 T __swift_class_getInstancePositiveExtentSize
61
174
000000000002b350 T __swift_class_getInstancePositiveExtentSize_native
62
175
0000000000024040 T __swift_debug_verifyTypeLayoutAttribute
63
176
0000000000004080 T __swift_getSuperclass_nonNull
64
177
0000000000003ff0 T __swift_isClass
65
178
00000000000279f0 T __swift_usesNativeSwiftReferenceCounting_class
66
179
000000000002ae40 T __swift_usesNativeSwiftReferenceCounting_nonNull
67
- 0000000000032e00 T _swift_ClassMirror_count
68
- 00000000000332a0 T _swift_ClassMirror_quickLookObject
69
- 0000000000032e90 T _swift_ClassMirror_subscript
70
- 0000000000032a60 T _swift_EnumMirror_caseName
71
- 0000000000032b40 T _swift_EnumMirror_count
72
- 0000000000032bd0 T _swift_EnumMirror_subscript
73
- 0000000000032590 T _swift_MagicMirrorData_objcValue
74
- 0000000000032730 T _swift_MagicMirrorData_objcValueType
75
- 00000000000325d0 T _swift_MagicMirrorData_summary
76
- 0000000000032530 T _swift_MagicMirrorData_value
77
- 0000000000032580 T _swift_MagicMirrorData_valueType
78
- 00000000000331e0 T _swift_ObjCMirror_count
79
- 0000000000033200 T _swift_ObjCMirror_subscript
80
- 00000000000328a0 T _swift_StructMirror_count
81
- 00000000000328b0 T _swift_StructMirror_subscript
82
- 0000000000032750 T _swift_TupleMirror_count
83
- 0000000000032760 T _swift_TupleMirror_subscript
84
180
000000000001cb30 T _swift_allocBox
85
- 00000000000268e0 T _swift_allocError
86
181
000000000001c990 T _swift_allocObject
87
- 000000000001cab0 T _swift_allocPOD
88
182
000000000001e3e0 T _swift_allocateGenericClassMetadata
89
183
000000000001e620 T _swift_allocateGenericValueMetadata
90
184
0000000000023a40 T _swift_assignExistentialWithCopy
91
- 0000000000026d50 T _swift_bridgeErrorTypeToNSError
92
185
0000000000003b60 T _swift_bridgeNonVerbatimFromObjectiveC
93
186
0000000000003c80 T _swift_bridgeNonVerbatimFromObjectiveCConditional
94
187
00000000000037e0 T _swift_bridgeNonVerbatimToObjectiveC
95
- 0000000000027ba0 T _swift_bridgeObjectRelease
96
- 0000000000027c50 T _swift_bridgeObjectRelease_n
97
- 0000000000027b50 T _swift_bridgeObjectRetain
98
- 0000000000027be0 T _swift_bridgeObjectRetain_n
99
188
000000000001ca60 T _swift_bufferAllocate
100
189
000000000001ca70 T _swift_bufferAllocateOnStack
101
190
000000000001ca80 T _swift_bufferDeallocateFromStack
102
191
000000000001ca90 T _swift_bufferHeaderSize
103
192
0000000000003060 T _swift_conformsToProtocol
104
- 0000000000026db0 T _swift_convertErrorTypeToNSError
105
- 0000000000026d60 T _swift_convertNSErrorToErrorType
106
193
000000000001dbf0 T _swift_copyPOD
107
194
000000000001cd30 T _swift_deallocBox
108
195
000000000001d490 T _swift_deallocClassInstance
109
- 0000000000026900 T _swift_deallocError
110
196
000000000001cd60 T _swift_deallocObject
111
197
000000000001d4c0 T _swift_deallocPartialClassInstance
112
198
0000000000023e60 T _swift_demangleSimpleClass
@@ -131,14 +217,10 @@ TODO
131
217
00000000000287d0 T _swift_dynamicCastTypeToObjCProtocolUnconditional
132
218
0000000000000de0 T _swift_dynamicCastUnknownClass
133
219
0000000000000fd0 T _swift_dynamicCastUnknownClassUnconditional
134
- 0000000000027120 T _swift_errorRelease
135
- 0000000000027100 T _swift_errorRetain
136
- 000000000001d630 T _swift_fixLifetime
137
220
00000000000039c0 T _swift_getBridgedNonVerbatimObjectiveCType
138
221
0000000000000b60 T _swift_getDynamicType
139
222
000000000001c560 T _swift_getEnumCaseMultiPayload
140
223
000000000001be60 T _swift_getEnumCaseSinglePayload
141
- 0000000000026b80 T _swift_getErrorValue
142
224
0000000000023230 T _swift_getExistentialMetatypeMetadata
143
225
0000000000023630 T _swift_getExistentialTypeMetadata
144
226
0000000000023b90 T _swift_getForeignTypeMetadata
@@ -185,66 +267,30 @@ TODO
185
267
0000000000028770 T _swift_objcRespondsToSelector
186
268
0000000000026550 T _swift_once
187
269
000000000001ce10 T _swift_projectBox
188
- 00000000000336d0 T _swift_reflectAny
189
270
0000000000002ef0 T _swift_registerProtocolConformances
190
- 000000000001ce70 T _swift_release
191
- 000000000001cee0 T _swift_release_n
192
271
000000000001c7d0 T _swift_reportFatalError
193
272
000000000001c730 T _swift_reportFatalErrorInFile
194
273
000000000001c940 T _swift_reportMissingMethod
195
274
000000000001c8d0 T _swift_reportUnimplementedInitializer
196
275
000000000001c840 T _swift_reportUnimplementedInitializerInFile
197
- 000000000001ce30 T _swift_retain
198
- 000000000001cf50 T _swift_retainCount
199
- 000000000001ce50 T _swift_retain_n
200
276
000000000001d400 T _swift_rootObjCDealloc
201
277
000000000001c960 T _swift_slowAlloc
202
278
000000000001c980 T _swift_slowDealloc
203
279
0000000000033930 T _swift_stdlib_demangleName
204
280
000000000001c400 T _swift_storeEnumTagMultiPayload
205
281
000000000001bf90 T _swift_storeEnumTagSinglePayload
206
- 000000000001d140 T _swift_tryPin
207
- 000000000001d240 T _swift_tryRetain
208
- 0000000000027b10 T _swift_unknownRelease
209
- 0000000000027a70 T _swift_unknownRelease_n
210
- 0000000000027ad0 T _swift_unknownRetain
211
- 0000000000027a10 T _swift_unknownRetain_n
212
- 0000000000027d50 T _swift_unknownUnownedAssign
213
- 00000000000280a0 T _swift_unknownUnownedCopyAssign
214
- 0000000000027fd0 T _swift_unknownUnownedCopyInit
215
- 0000000000027ed0 T _swift_unknownUnownedDestroy
216
- 0000000000027cb0 T _swift_unknownUnownedInit
217
- 0000000000027f20 T _swift_unknownUnownedLoadStrong
218
- 00000000000281f0 T _swift_unknownUnownedTakeAssign
219
- 0000000000028070 T _swift_unknownUnownedTakeInit
220
- 0000000000027f70 T _swift_unknownUnownedTakeStrong
221
- 00000000000282b0 T _swift_unknownWeakAssign
222
- 0000000000028560 T _swift_unknownWeakCopyAssign
223
- 00000000000284e0 T _swift_unknownWeakCopyInit
224
- 00000000000283e0 T _swift_unknownWeakDestroy
225
- 0000000000028270 T _swift_unknownWeakInit
226
- 0000000000028420 T _swift_unknownWeakLoadStrong
227
- 0000000000028610 T _swift_unknownWeakTakeAssign
228
- 0000000000028520 T _swift_unknownWeakTakeInit
229
- 0000000000028470 T _swift_unknownWeakTakeStrong
230
- 000000000001d3c0 T _swift_unownedCheck
231
- 000000000001cfb0 T _swift_unownedRelease
232
- 000000000001d0a0 T _swift_unownedRelease_n
233
- 000000000001cf70 T _swift_unownedRetain
234
- 000000000001cf60 T _swift_unownedRetainCount
235
- 000000000001d2b0 T _swift_unownedRetainStrong
236
- 000000000001d310 T _swift_unownedRetainStrongAndRelease
237
- 000000000001d060 T _swift_unownedRetain_n
238
- 000000000001d1b0 T _swift_unpin
239
- 000000000001ca20 T _swift_verifyEndOfLifetime
240
- 000000000001d680 T _swift_weakAssign
241
- 000000000001d830 T _swift_weakCopyAssign
242
- 000000000001d790 T _swift_weakCopyInit
243
- 000000000001d770 T _swift_weakDestroy
244
- 000000000001d640 T _swift_weakInit
245
- 000000000001d6d0 T _swift_weakLoadStrong
246
- 000000000001d8b0 T _swift_weakTakeAssign
247
- 000000000001d800 T _swift_weakTakeInit
248
- 000000000001d710 T _swift_weakTakeStrong
249
282
0000000000027140 T _swift_willThrow
250
283
```
284
+
285
+ ## Tasks
286
+
287
+ - Moving to per-type instantiation functions instead of using
288
+ ` getGenericMetadata ` directly
289
+
290
+ - ` swift_objc_ ` naming convention for ObjC
291
+
292
+ - Alternative ABIs for retain/release
293
+
294
+ - Unsynchronized retain/release
295
+
296
+
0 commit comments