@@ -35,13 +35,14 @@ internal func _swift_bufferAllocate(
35
35
/// - Note: Subclasses must not have any stored properties; any storage
36
36
/// needed should be included in `Header`.
37
37
@_fixed_layout
38
- open class ManagedBuffer< Header , Element > {
38
+ open class ManagedBuffer< Header , Element : ~ Copyable > {
39
39
/// The stored `Header` instance.
40
40
///
41
41
/// During instance creation, in particular during
42
42
/// `ManagedBuffer.create`'s call to initialize, `ManagedBuffer`'s
43
43
/// `header` property is as-yet uninitialized, and therefore
44
44
/// reading the `header` property during `ManagedBuffer.create` is undefined.
45
+ @_preInverseGenerics
45
46
public final var header : Header
46
47
47
48
#if $Embedded
@@ -54,23 +55,26 @@ open class ManagedBuffer<Header, Element> {
54
55
// This is really unfortunate. In Swift 5.0, the method descriptor for this
55
56
// initializer was public and subclasses would "inherit" it, referencing its
56
57
// method descriptor from their class override table.
58
+ @_preInverseGenerics
57
59
@usableFromInline
58
60
internal init( _doNotCallMe: ( ) ) {
59
61
_internalInvariantFailure ( " Only initialize these by calling create " )
60
62
}
61
63
#endif
62
64
65
+ @_preInverseGenerics
63
66
@inlinable
64
67
deinit { }
65
68
}
66
69
67
70
@available ( * , unavailable)
68
- extension ManagedBuffer : Sendable { }
71
+ extension ManagedBuffer : Sendable where Element : ~ Copyable { }
69
72
70
- extension ManagedBuffer {
73
+ extension ManagedBuffer where Element : ~ Copyable {
71
74
/// Create a new instance of the most-derived class, calling
72
75
/// `factory` on the partially-constructed object to generate
73
76
/// an initial `Header`.
77
+ @_preInverseGenerics
74
78
@inlinable
75
79
public final class func create(
76
80
minimumCapacity: Int ,
@@ -96,6 +100,7 @@ extension ManagedBuffer {
96
100
/// This header may be nontrivial to compute; it is usually a good
97
101
/// idea to store this information in the "header" area when
98
102
/// an instance is created.
103
+ @_preInverseGenerics
99
104
@inlinable
100
105
@available ( OpenBSD, unavailable, message: " malloc_size is unavailable. " )
101
106
public final var capacity : Int {
@@ -106,12 +111,14 @@ extension ManagedBuffer {
106
111
return realCapacity
107
112
}
108
113
114
+ @_preInverseGenerics
109
115
@inlinable
110
116
internal final var firstElementAddress : UnsafeMutablePointer < Element > {
111
117
return UnsafeMutablePointer (
112
118
Builtin . projectTailElems ( self , Element . self) )
113
119
}
114
120
121
+ @_preInverseGenerics
115
122
@inlinable
116
123
internal final var headerAddress : UnsafeMutablePointer < Header > {
117
124
return UnsafeMutablePointer < Header > ( Builtin . addressof ( & header) )
@@ -122,6 +129,7 @@ extension ManagedBuffer {
122
129
///
123
130
/// - Note: This pointer is valid only for the duration of the
124
131
/// call to `body`.
132
+ @_preInverseGenerics
125
133
@inlinable
126
134
public final func withUnsafeMutablePointerToHeader< R> (
127
135
_ body: ( UnsafeMutablePointer < Header > ) throws -> R
@@ -134,6 +142,7 @@ extension ManagedBuffer {
134
142
///
135
143
/// - Note: This pointer is valid only for the duration of the
136
144
/// call to `body`.
145
+ @_preInverseGenerics
137
146
@inlinable
138
147
public final func withUnsafeMutablePointerToElements< R> (
139
148
_ body: ( UnsafeMutablePointer < Element > ) throws -> R
@@ -146,6 +155,7 @@ extension ManagedBuffer {
146
155
///
147
156
/// - Note: These pointers are valid only for the duration of the
148
157
/// call to `body`.
158
+ @_preInverseGenerics
149
159
@inlinable
150
160
public final func withUnsafeMutablePointers< R> (
151
161
_ body: ( UnsafeMutablePointer < Header > , UnsafeMutablePointer < Element > ) throws -> R
@@ -191,8 +201,9 @@ extension ManagedBuffer {
191
201
/// }
192
202
///
193
203
@frozen
194
- public struct ManagedBufferPointer < Header, Element> {
204
+ public struct ManagedBufferPointer < Header, Element: ~ Copyable > {
195
205
206
+ @_preInverseGenerics
196
207
@usableFromInline
197
208
internal var _nativeBuffer : Builtin . NativeObject
198
209
@@ -211,6 +222,7 @@ public struct ManagedBufferPointer<Header, Element> {
211
222
/// `bufferClass` is a non-`@objc` class with no declared stored
212
223
/// properties. The `deinit` of `bufferClass` must destroy its
213
224
/// stored `Header` and any constructed `Element`s.
225
+ @_preInverseGenerics
214
226
@inlinable
215
227
@available ( OpenBSD, unavailable, message: " malloc_size is unavailable. " )
216
228
public init (
@@ -224,7 +236,7 @@ public struct ManagedBufferPointer<Header, Element> {
224
236
225
237
// initialize the header field
226
238
try withUnsafeMutablePointerToHeader {
227
- $0. initialize ( to:
239
+ $0. initialize ( to:
228
240
try factory (
229
241
self . buffer,
230
242
{
@@ -240,6 +252,7 @@ public struct ManagedBufferPointer<Header, Element> {
240
252
///
241
253
/// - Precondition: `buffer` is an instance of a non-`@objc` class whose
242
254
/// `deinit` destroys its stored `Header` and any constructed `Element`s.
255
+ @_preInverseGenerics
243
256
@inlinable
244
257
public init ( unsafeBufferObject buffer: AnyObject ) {
245
258
ManagedBufferPointer . _checkValidBufferClass ( type ( of: buffer) )
@@ -257,6 +270,7 @@ public struct ManagedBufferPointer<Header, Element> {
257
270
/// _debugPreconditions in _checkValidBufferClass for any array. Since we know
258
271
/// for the _ContiguousArrayBuffer that this check must always succeed we omit
259
272
/// it in this specialized constructor.
273
+ @_preInverseGenerics
260
274
@inlinable
261
275
internal init ( _uncheckedUnsafeBufferObject buffer: AnyObject ) {
262
276
ManagedBufferPointer . _internalInvariantValidBufferClass ( type ( of: buffer) )
@@ -274,6 +288,7 @@ public struct ManagedBufferPointer<Header, Element> {
274
288
/// `bufferClass` is a non-`@objc` class with no declared stored
275
289
/// properties. The `deinit` of `bufferClass` must destroy its
276
290
/// stored `Header` and any constructed `Element`s.
291
+ @_preInverseGenerics
277
292
@inlinable
278
293
internal init (
279
294
bufferClass: AnyClass ,
@@ -290,12 +305,14 @@ public struct ManagedBufferPointer<Header, Element> {
290
305
291
306
/// Internal version for use by _ContiguousArrayBuffer.init where we know that
292
307
/// we have a valid buffer class and that the capacity is >= 0.
308
+ @_preInverseGenerics
293
309
@inlinable
294
310
internal init (
295
311
_uncheckedBufferClass: AnyClass ,
296
312
minimumCapacity: Int
297
313
) {
298
- ManagedBufferPointer . _internalInvariantValidBufferClass ( _uncheckedBufferClass, creating: true )
314
+ ManagedBufferPointer . _internalInvariantValidBufferClass (
315
+ _uncheckedBufferClass, creating: true )
299
316
_internalInvariant (
300
317
minimumCapacity >= 0 ,
301
318
" ManagedBufferPointer must have non-negative capacity " )
@@ -315,14 +332,16 @@ public struct ManagedBufferPointer<Header, Element> {
315
332
///
316
333
/// - Note: It is an error to use the `header` property of the resulting
317
334
/// instance unless it has been initialized.
335
+ @_preInverseGenerics
318
336
@inlinable
319
337
internal init ( _ buffer: ManagedBuffer < Header , Element > ) {
320
338
_nativeBuffer = Builtin . unsafeCastToNativeObject ( buffer)
321
339
}
322
340
}
323
341
324
- extension ManagedBufferPointer {
342
+ extension ManagedBufferPointer where Element : ~ Copyable {
325
343
/// The stored `Header` instance.
344
+ @_preInverseGenerics
326
345
@inlinable
327
346
public var header : Header {
328
347
_read {
@@ -334,6 +353,7 @@ extension ManagedBufferPointer {
334
353
}
335
354
336
355
/// Returns the object instance being used for storage.
356
+ @_preInverseGenerics
337
357
@inlinable
338
358
public var buffer : AnyObject {
339
359
return Builtin . castFromNativeObject ( _nativeBuffer)
@@ -344,6 +364,7 @@ extension ManagedBufferPointer {
344
364
/// This value may be nontrivial to compute; it is usually a good
345
365
/// idea to store this information in the "header" area when
346
366
/// an instance is created.
367
+ @_preInverseGenerics
347
368
@inlinable
348
369
@available ( OpenBSD, unavailable, message: " malloc_size is unavailable. " )
349
370
public var capacity : Int {
@@ -357,6 +378,7 @@ extension ManagedBufferPointer {
357
378
///
358
379
/// - Note: This pointer is valid only
359
380
/// for the duration of the call to `body`.
381
+ @_preInverseGenerics
360
382
@inlinable
361
383
public func withUnsafeMutablePointerToHeader< R> (
362
384
_ body: ( UnsafeMutablePointer < Header > ) throws -> R
@@ -369,6 +391,7 @@ extension ManagedBufferPointer {
369
391
///
370
392
/// - Note: This pointer is valid only for the duration of the
371
393
/// call to `body`.
394
+ @_preInverseGenerics
372
395
@inlinable
373
396
public func withUnsafeMutablePointerToElements< R> (
374
397
_ body: ( UnsafeMutablePointer < Element > ) throws -> R
@@ -381,9 +404,12 @@ extension ManagedBufferPointer {
381
404
///
382
405
/// - Note: These pointers are valid only for the duration of the
383
406
/// call to `body`.
407
+ @_preInverseGenerics
384
408
@inlinable
385
409
public func withUnsafeMutablePointers< R> (
386
- _ body: ( UnsafeMutablePointer < Header > , UnsafeMutablePointer < Element > ) throws -> R
410
+ _ body: (
411
+ UnsafeMutablePointer < Header > , UnsafeMutablePointer < Element >
412
+ ) throws -> R
387
413
) rethrows -> R {
388
414
defer { _fixLifetime ( _nativeBuffer) }
389
415
return try body ( _headerPointer, _elementPointer)
@@ -393,13 +419,15 @@ extension ManagedBufferPointer {
393
419
/// buffer; otherwise, returns `false`.
394
420
///
395
421
/// See `isKnownUniquelyReferenced` for details.
422
+ @_preInverseGenerics
396
423
@inlinable
397
424
public mutating func isUniqueReference( ) -> Bool {
398
425
return _isUnique ( & _nativeBuffer)
399
426
}
400
427
}
401
428
402
- extension ManagedBufferPointer {
429
+ extension ManagedBufferPointer where Element: ~ Copyable {
430
+ @_preInverseGenerics
403
431
@inlinable
404
432
internal static func _checkValidBufferClass(
405
433
_ bufferClass: AnyClass , creating: Bool = false
@@ -418,6 +446,7 @@ extension ManagedBufferPointer {
418
446
)
419
447
}
420
448
449
+ @_preInverseGenerics
421
450
@inlinable
422
451
internal static func _internalInvariantValidBufferClass(
423
452
_ bufferClass: AnyClass , creating: Bool = false
@@ -437,8 +466,9 @@ extension ManagedBufferPointer {
437
466
}
438
467
}
439
468
440
- extension ManagedBufferPointer {
469
+ extension ManagedBufferPointer where Element : ~ Copyable {
441
470
/// The required alignment for allocations of this type, minus 1
471
+ @_preInverseGenerics
442
472
@inlinable
443
473
internal static var _alignmentMask : Int {
444
474
return max (
@@ -447,19 +477,22 @@ extension ManagedBufferPointer {
447
477
}
448
478
449
479
/// The actual number of bytes allocated for this object.
480
+ @_preInverseGenerics
450
481
@inlinable
451
482
@available ( OpenBSD, unavailable, message: " malloc_size is unavailable. " )
452
483
internal var _capacityInBytes : Int {
453
484
return _swift_stdlib_malloc_size ( _address)
454
485
}
455
486
456
487
/// The address of this instance in a convenient pointer-to-bytes form
488
+ @_preInverseGenerics
457
489
@inlinable
458
490
internal var _address : UnsafeMutableRawPointer {
459
491
return UnsafeMutableRawPointer ( Builtin . bridgeToRawPointer ( _nativeBuffer) )
460
492
}
461
493
462
494
/// Offset from the allocated storage for `self` to the stored `Header`
495
+ @_preInverseGenerics
463
496
@inlinable
464
497
internal static var _headerOffset : Int {
465
498
_onFastPath ( )
@@ -471,6 +504,7 @@ extension ManagedBufferPointer {
471
504
/// An **unmanaged** pointer to the storage for the `Header`
472
505
/// instance. Not safe to use without _fixLifetime calls to
473
506
/// guarantee it doesn't dangle
507
+ @_preInverseGenerics
474
508
@inlinable
475
509
internal var _headerPointer : UnsafeMutablePointer < Header > {
476
510
_onFastPath ( )
@@ -481,6 +515,7 @@ extension ManagedBufferPointer {
481
515
/// An **unmanaged** pointer to the storage for `Element`s. Not
482
516
/// safe to use without _fixLifetime calls to guarantee it doesn't
483
517
/// dangle.
518
+ @_preInverseGenerics
484
519
@inlinable
485
520
internal var _elementPointer : UnsafeMutablePointer < Element > {
486
521
_onFastPath ( )
@@ -489,6 +524,7 @@ extension ManagedBufferPointer {
489
524
}
490
525
491
526
/// Offset from the allocated storage for `self` to the `Element` storage
527
+ @_preInverseGenerics
492
528
@inlinable
493
529
internal static var _elementOffset : Int {
494
530
_onFastPath ( )
0 commit comments