Skip to content

Commit 857e4f6

Browse files
committed
VarArg code is all conforming to a C ABI so unlikely to ever change
1 parent a6ef182 commit 857e4f6

File tree

1 file changed

+53
-51
lines changed

1 file changed

+53
-51
lines changed

stdlib/public/core/VarArgs.swift

Lines changed: 53 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ internal typealias _VAInt = Int32
124124
/// The pointer argument is valid only for the duration of the function's
125125
/// execution.
126126
/// - Returns: The return value, if any, of the `body` closure parameter.
127-
@inlinable // FIXME(sil-serialize-all)
127+
@inlinable // c-abi
128128
public func withVaList<R>(_ args: [CVarArg],
129129
_ body: (CVaListPointer) -> R) -> R {
130130
let builder = _VaListBuilder()
@@ -135,7 +135,7 @@ public func withVaList<R>(_ args: [CVarArg],
135135
}
136136

137137
/// Invoke `body` with a C `va_list` argument derived from `builder`.
138-
@inlinable // FIXME(sil-serialize-all)
138+
@inlinable // c-abi
139139
internal func _withVaList<R>(
140140
_ builder: _VaListBuilder,
141141
_ body: (CVaListPointer) -> R
@@ -166,7 +166,7 @@ internal func _withVaList<R>(
166166
/// pointer.
167167
/// - Returns: A pointer that can be used with C functions that take a
168168
/// `va_list` argument.
169-
@inlinable // FIXME(sil-serialize-all)
169+
@inlinable // c-abi
170170
public func getVaList(_ args: [CVarArg]) -> CVaListPointer {
171171
let builder = _VaListBuilder()
172172
for a in args {
@@ -179,7 +179,7 @@ public func getVaList(_ args: [CVarArg]) -> CVaListPointer {
179179
}
180180
#endif
181181

182-
@inlinable // FIXME(sil-serialize-all)
182+
@inlinable // c-abi
183183
public func _encodeBitsAsWords<T>(_ x: T) -> [Int] {
184184
let result = [Int](
185185
repeating: 0,
@@ -201,7 +201,7 @@ public func _encodeBitsAsWords<T>(_ x: T) -> [Int] {
201201
extension Int : CVarArg {
202202
/// Transform `self` into a series of machine words that can be
203203
/// appropriately interpreted by C varargs.
204-
@inlinable // FIXME(sil-serialize-all)
204+
@inlinable // c-abi
205205
public var _cVarArgEncoding: [Int] {
206206
return _encodeBitsAsWords(self)
207207
}
@@ -216,14 +216,14 @@ extension Bool : CVarArg {
216216
extension Int64 : CVarArg, _CVarArgAligned {
217217
/// Transform `self` into a series of machine words that can be
218218
/// appropriately interpreted by C varargs.
219-
@inlinable // FIXME(sil-serialize-all)
219+
@inlinable // c-abi
220220
public var _cVarArgEncoding: [Int] {
221221
return _encodeBitsAsWords(self)
222222
}
223223

224224
/// Returns the required alignment in bytes of
225225
/// the value returned by `_cVarArgEncoding`.
226-
@inlinable // FIXME(sil-serialize-all)
226+
@inlinable // c-abi
227227
public var _cVarArgAlignment: Int {
228228
// FIXME: alignof differs from the ABI alignment on some architectures
229229
return MemoryLayout.alignment(ofValue: self)
@@ -233,7 +233,7 @@ extension Int64 : CVarArg, _CVarArgAligned {
233233
extension Int32 : CVarArg {
234234
/// Transform `self` into a series of machine words that can be
235235
/// appropriately interpreted by C varargs.
236-
@inlinable // FIXME(sil-serialize-all)
236+
@inlinable // c-abi
237237
public var _cVarArgEncoding: [Int] {
238238
return _encodeBitsAsWords(_VAInt(self))
239239
}
@@ -242,7 +242,7 @@ extension Int32 : CVarArg {
242242
extension Int16 : CVarArg {
243243
/// Transform `self` into a series of machine words that can be
244244
/// appropriately interpreted by C varargs.
245-
@inlinable // FIXME(sil-serialize-all)
245+
@inlinable // c-abi
246246
public var _cVarArgEncoding: [Int] {
247247
return _encodeBitsAsWords(_VAInt(self))
248248
}
@@ -251,7 +251,7 @@ extension Int16 : CVarArg {
251251
extension Int8 : CVarArg {
252252
/// Transform `self` into a series of machine words that can be
253253
/// appropriately interpreted by C varargs.
254-
@inlinable // FIXME(sil-serialize-all)
254+
@inlinable // c-abi
255255
public var _cVarArgEncoding: [Int] {
256256
return _encodeBitsAsWords(_VAInt(self))
257257
}
@@ -261,7 +261,7 @@ extension Int8 : CVarArg {
261261
extension UInt : CVarArg {
262262
/// Transform `self` into a series of machine words that can be
263263
/// appropriately interpreted by C varargs.
264-
@inlinable // FIXME(sil-serialize-all)
264+
@inlinable // c-abi
265265
public var _cVarArgEncoding: [Int] {
266266
return _encodeBitsAsWords(self)
267267
}
@@ -270,14 +270,14 @@ extension UInt : CVarArg {
270270
extension UInt64 : CVarArg, _CVarArgAligned {
271271
/// Transform `self` into a series of machine words that can be
272272
/// appropriately interpreted by C varargs.
273-
@inlinable // FIXME(sil-serialize-all)
273+
@inlinable // c-abi
274274
public var _cVarArgEncoding: [Int] {
275275
return _encodeBitsAsWords(self)
276276
}
277277

278278
/// Returns the required alignment in bytes of
279279
/// the value returned by `_cVarArgEncoding`.
280-
@inlinable // FIXME(sil-serialize-all)
280+
@inlinable // c-abi
281281
public var _cVarArgAlignment: Int {
282282
// FIXME: alignof differs from the ABI alignment on some architectures
283283
return MemoryLayout.alignment(ofValue: self)
@@ -287,7 +287,7 @@ extension UInt64 : CVarArg, _CVarArgAligned {
287287
extension UInt32 : CVarArg {
288288
/// Transform `self` into a series of machine words that can be
289289
/// appropriately interpreted by C varargs.
290-
@inlinable // FIXME(sil-serialize-all)
290+
@inlinable // c-abi
291291
public var _cVarArgEncoding: [Int] {
292292
return _encodeBitsAsWords(_VAUInt(self))
293293
}
@@ -296,7 +296,7 @@ extension UInt32 : CVarArg {
296296
extension UInt16 : CVarArg {
297297
/// Transform `self` into a series of machine words that can be
298298
/// appropriately interpreted by C varargs.
299-
@inlinable // FIXME(sil-serialize-all)
299+
@inlinable // c-abi
300300
public var _cVarArgEncoding: [Int] {
301301
return _encodeBitsAsWords(_VAUInt(self))
302302
}
@@ -305,7 +305,7 @@ extension UInt16 : CVarArg {
305305
extension UInt8 : CVarArg {
306306
/// Transform `self` into a series of machine words that can be
307307
/// appropriately interpreted by C varargs.
308-
@inlinable // FIXME(sil-serialize-all)
308+
@inlinable // c-abi
309309
public var _cVarArgEncoding: [Int] {
310310
return _encodeBitsAsWords(_VAUInt(self))
311311
}
@@ -314,7 +314,7 @@ extension UInt8 : CVarArg {
314314
extension OpaquePointer : CVarArg {
315315
/// Transform `self` into a series of machine words that can be
316316
/// appropriately interpreted by C varargs.
317-
@inlinable // FIXME(sil-serialize-all)
317+
@inlinable // c-abi
318318
public var _cVarArgEncoding: [Int] {
319319
return _encodeBitsAsWords(self)
320320
}
@@ -323,7 +323,7 @@ extension OpaquePointer : CVarArg {
323323
extension UnsafePointer : CVarArg {
324324
/// Transform `self` into a series of machine words that can be
325325
/// appropriately interpreted by C varargs.
326-
@inlinable // FIXME(sil-serialize-all)
326+
@inlinable // c-abi
327327
public var _cVarArgEncoding: [Int] {
328328
return _encodeBitsAsWords(self)
329329
}
@@ -332,7 +332,7 @@ extension UnsafePointer : CVarArg {
332332
extension UnsafeMutablePointer : CVarArg {
333333
/// Transform `self` into a series of machine words that can be
334334
/// appropriately interpreted by C varargs.
335-
@inlinable // FIXME(sil-serialize-all)
335+
@inlinable // c-abi
336336
public var _cVarArgEncoding: [Int] {
337337
return _encodeBitsAsWords(self)
338338
}
@@ -352,14 +352,14 @@ extension AutoreleasingUnsafeMutablePointer : CVarArg {
352352
extension Float : _CVarArgPassedAsDouble, _CVarArgAligned {
353353
/// Transform `self` into a series of machine words that can be
354354
/// appropriately interpreted by C varargs.
355-
@inlinable // FIXME(sil-serialize-all)
355+
@inlinable // c-abi
356356
public var _cVarArgEncoding: [Int] {
357357
return _encodeBitsAsWords(Double(self))
358358
}
359359

360360
/// Returns the required alignment in bytes of
361361
/// the value returned by `_cVarArgEncoding`.
362-
@inlinable // FIXME(sil-serialize-all)
362+
@inlinable // c-abi
363363
public var _cVarArgAlignment: Int {
364364
// FIXME: alignof differs from the ABI alignment on some architectures
365365
return MemoryLayout.alignment(ofValue: Double(self))
@@ -369,14 +369,14 @@ extension Float : _CVarArgPassedAsDouble, _CVarArgAligned {
369369
extension Double : _CVarArgPassedAsDouble, _CVarArgAligned {
370370
/// Transform `self` into a series of machine words that can be
371371
/// appropriately interpreted by C varargs.
372-
@inlinable // FIXME(sil-serialize-all)
372+
@inlinable // c-abi
373373
public var _cVarArgEncoding: [Int] {
374374
return _encodeBitsAsWords(self)
375375
}
376376

377377
/// Returns the required alignment in bytes of
378378
/// the value returned by `_cVarArgEncoding`.
379-
@inlinable // FIXME(sil-serialize-all)
379+
@inlinable // c-abi
380380
public var _cVarArgAlignment: Int {
381381
// FIXME: alignof differs from the ABI alignment on some architectures
382382
return MemoryLayout.alignment(ofValue: self)
@@ -388,36 +388,37 @@ extension Double : _CVarArgPassedAsDouble, _CVarArgAligned {
388388
/// An object that can manage the lifetime of storage backing a
389389
/// `CVaListPointer`.
390390
@_fixed_layout // FIXME(sil-serialize-all)
391-
@usableFromInline // FIXME(sil-serialize-all)
391+
@_fixed_layout // c-abi
392+
@usableFromInline // c-abi
392393
final internal class _VaListBuilder {
393394

394-
@_fixed_layout // FIXME(sil-serialize-all)
395+
@_fixed_layout // c-abi
395396
@usableFromInline
396397
internal struct Header {
397-
@inlinable // FIXME(sil-serialize-all)
398+
@inlinable // c-abi
398399
internal init() {}
399400

400-
@usableFromInline // FIXME(sil-serialize-all)
401+
@usableFromInline // c-abi
401402
internal var gp_offset = CUnsignedInt(0)
402-
@usableFromInline // FIXME(sil-serialize-all)
403+
@usableFromInline // c-abi
403404
internal var fp_offset =
404405
CUnsignedInt(_countGPRegisters * MemoryLayout<Int>.stride)
405-
@usableFromInline // FIXME(sil-serialize-all)
406+
@usableFromInline // c-abi
406407
internal var overflow_arg_area: UnsafeMutablePointer<Int>?
407-
@usableFromInline // FIXME(sil-serialize-all)
408+
@usableFromInline // c-abi
408409
internal var reg_save_area: UnsafeMutablePointer<Int>?
409410
}
410411

411-
@inlinable // FIXME(sil-serialize-all)
412+
@inlinable // c-abi
412413
internal init() {
413414
// prepare the register save area
414415
storage = ContiguousArray(repeating: 0, count: _registerSaveWords)
415416
}
416417

417-
@inlinable // FIXME(sil-serialize-all)
418+
@inlinable // c-abi
418419
deinit {}
419420

420-
@inlinable // FIXME(sil-serialize-all)
421+
@inlinable // c-abi
421422
internal func append(_ arg: CVarArg) {
422423
var encoded = arg._cVarArgEncoding
423424

@@ -459,7 +460,7 @@ final internal class _VaListBuilder {
459460

460461
}
461462

462-
@inlinable // FIXME(sil-serialize-all)
463+
@inlinable // c-abi
463464
internal func va_list() -> CVaListPointer {
464465
header.reg_save_area = storage._baseAddress
465466
header.overflow_arg_area
@@ -469,15 +470,15 @@ final internal class _VaListBuilder {
469470
Builtin.addressof(&self.header)))
470471
}
471472

472-
@usableFromInline // FIXME(sil-serialize-all)
473+
@usableFromInline // c-abi
473474
internal var gpRegistersUsed = 0
474-
@usableFromInline // FIXME(sil-serialize-all)
475+
@usableFromInline // c-abi
475476
internal var fpRegistersUsed = 0
476477

477-
@usableFromInline // FIXME(sil-serialize-all)
478+
@usableFromInline // c-abi
478479
final // Property must be final since it is used by Builtin.addressof.
479480
internal var header = Header()
480-
@usableFromInline // FIXME(sil-serialize-all)
481+
@usableFromInline // c-abi
481482
internal var storage: ContiguousArray<Int>
482483
}
483484

@@ -486,13 +487,14 @@ final internal class _VaListBuilder {
486487
/// An object that can manage the lifetime of storage backing a
487488
/// `CVaListPointer`.
488489
@_fixed_layout // FIXME(sil-serialize-all)
489-
@usableFromInline // FIXME(sil-serialize-all)
490+
@_fixed_layout // c-abi
491+
@usableFromInline // c-abi
490492
final internal class _VaListBuilder {
491493

492-
@inlinable // FIXME(sil-serialize-all)
494+
@inlinable // c-abi
493495
internal init() {}
494496

495-
@inlinable // FIXME(sil-serialize-all)
497+
@inlinable // c-abi
496498
internal func append(_ arg: CVarArg) {
497499
// Write alignment padding if necessary.
498500
// This is needed on architectures where the ABI alignment of some
@@ -519,7 +521,7 @@ final internal class _VaListBuilder {
519521
// Marking it inlinable will cause it to resiliently use accessors to
520522
// project `_VaListBuilder.alignedStorageForEmptyVaLists` as a computed
521523
// property.
522-
@usableFromInline // FIXME(sil-serialize-all)
524+
@usableFromInline // c-abi
523525
internal func va_list() -> CVaListPointer {
524526
// Use Builtin.addressof to emphasize that we are deliberately escaping this
525527
// pointer and assuming it is safe to do so.
@@ -532,7 +534,7 @@ final internal class _VaListBuilder {
532534
// but possibly more aligned than that.
533535
// FIXME: this should be packaged into a better storage type
534536

535-
@inlinable // FIXME(sil-serialize-all)
537+
@inlinable // c-abi
536538
internal func appendWords(_ words: [Int]) {
537539
let newCount = count + words.count
538540
if newCount > allocated {
@@ -558,22 +560,22 @@ final internal class _VaListBuilder {
558560
}
559561
}
560562

561-
@inlinable // FIXME(sil-serialize-all)
563+
@inlinable // c-abi
562564
internal func rawSizeAndAlignment(
563565
_ wordCount: Int
564566
) -> (Builtin.Word, Builtin.Word) {
565567
return ((wordCount * MemoryLayout<Int>.stride)._builtinWordValue,
566568
requiredAlignmentInBytes._builtinWordValue)
567569
}
568570

569-
@inlinable // FIXME(sil-serialize-all)
571+
@inlinable // c-abi
570572
internal func allocStorage(wordCount: Int) -> UnsafeMutablePointer<Int> {
571573
let (rawSize, rawAlignment) = rawSizeAndAlignment(wordCount)
572574
let rawStorage = Builtin.allocRaw(rawSize, rawAlignment)
573575
return UnsafeMutablePointer<Int>(rawStorage)
574576
}
575577

576-
@usableFromInline // FIXME(sil-serialize-all)
578+
@usableFromInline // c-abi
577579
internal func deallocStorage(
578580
wordCount: Int,
579581
storage: UnsafeMutablePointer<Int>
@@ -582,21 +584,21 @@ final internal class _VaListBuilder {
582584
Builtin.deallocRaw(storage._rawValue, rawSize, rawAlignment)
583585
}
584586

585-
@inlinable // FIXME(sil-serialize-all)
587+
@inlinable // c-abi
586588
deinit {
587589
if let allocatedStorage = storage {
588590
deallocStorage(wordCount: allocated, storage: allocatedStorage)
589591
}
590592
}
591593

592594
// FIXME: alignof differs from the ABI alignment on some architectures
593-
@usableFromInline // FIXME(sil-serialize-all)
595+
@usableFromInline // c-abi
594596
internal let requiredAlignmentInBytes = MemoryLayout<Double>.alignment
595-
@usableFromInline // FIXME(sil-serialize-all)
597+
@usableFromInline // c-abi
596598
internal var count = 0
597-
@usableFromInline // FIXME(sil-serialize-all)
599+
@usableFromInline // c-abi
598600
internal var allocated = 0
599-
@usableFromInline // FIXME(sil-serialize-all)
601+
@usableFromInline // c-abi
600602
internal var storage: UnsafeMutablePointer<Int>?
601603

602604
internal static var alignedStorageForEmptyVaLists: Double = 0

0 commit comments

Comments
 (0)