12
12
13
13
import SwiftShims
14
14
15
- /// A common base class for classes that need to be non-`@objc`,
16
- /// recognizably in the type system.
17
- ///
18
- /// - SeeAlso: `isUniquelyReferenced`
19
- public class NonObjectiveCBase {
20
- public init ( ) { }
21
- }
22
-
23
15
/// A base class of `ManagedBuffer<Header, Element>`, used during
24
16
/// instance creation.
25
17
///
@@ -28,7 +20,7 @@ public class NonObjectiveCBase {
28
20
/// `header` property is as-yet uninitialized, and therefore
29
21
/// `ManagedProtoBuffer` does not offer access to the as-yet
30
22
/// uninitialized `header` property of `ManagedBuffer`.
31
- public class ManagedProtoBuffer < Header, Element> : NonObjectiveCBase {
23
+ public class ManagedProtoBuffer < Header, Element> {
32
24
/// The actual number of elements that can be stored in this object.
33
25
///
34
26
/// This header may be nontrivial to compute; it is usually a good
@@ -299,18 +291,10 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
299
291
/// Returns `true` iff `self` holds the only strong reference to its buffer.
300
292
///
301
293
/// See `isUniquelyReferenced` for details.
302
- public mutating func holdsUniqueReference ( ) -> Bool {
294
+ public mutating func isUniqueReference ( ) -> Bool {
303
295
return _isUnique ( & _nativeBuffer)
304
296
}
305
297
306
- /// Returns `true` iff either `self` holds the only strong reference
307
- /// to its buffer or the pinned has been 'pinned'.
308
- ///
309
- /// See `isUniquelyReferenced` for details.
310
- public mutating func holdsUniqueOrPinnedReference( ) -> Bool {
311
- return _isUniqueOrPinned ( & _nativeBuffer)
312
- }
313
-
314
298
//===--- internal/private API -------------------------------------------===//
315
299
316
300
/// Create with new storage containing space for an initial `Header`
@@ -453,6 +437,10 @@ public struct ManagedBufferPointer<Header, Element> : Equatable {
453
437
toAlignment: alignof ( Element . self) )
454
438
}
455
439
440
+ internal mutating func _isUniqueOrPinnedReference( ) -> Bool {
441
+ return _isUniqueOrPinned ( & _nativeBuffer)
442
+ }
443
+
456
444
internal var _nativeBuffer : Builtin . NativeObject
457
445
}
458
446
@@ -466,19 +454,18 @@ public func == <Header, Element>(
466
454
// FIXME: when our calling convention changes to pass self at +0,
467
455
// inout should be dropped from the arguments to these functions.
468
456
469
- /// Returns `true` iff `object` is a non-`@objc` class instance with
470
- /// a single strong reference.
457
+ /// Returns `true` iff `object` is known to be a class instance with a single
458
+ /// strong reference.
471
459
///
472
460
/// * Does *not* modify `object`; the use of `inout` is an
473
461
/// implementation artifact.
474
- /// * If `object` is an Objective-C class instance, returns `false`.
475
462
/// * Weak references do not affect the result of this function.
476
463
///
477
464
/// Useful for implementing the copy-on-write optimization for the
478
465
/// deep storage of value types:
479
466
///
480
467
/// mutating func modifyMe(_ arg: X) {
481
- /// if isUniquelyReferencedNonObjC (&myStorage) {
468
+ /// if isKnownUniquelyReferenced (&myStorage) {
482
469
/// myStorage.modifyInPlace(arg)
483
470
/// }
484
471
/// else {
@@ -489,16 +476,16 @@ public func == <Header, Element>(
489
476
/// This function is safe to use for `mutating` functions in
490
477
/// multithreaded code because a false positive would imply that there
491
478
/// is already a user-level data race on the value being mutated.
492
- public func isUniquelyReferencedNonObjC < T : AnyObject > ( _ object: inout T ) -> Bool
479
+ public func isKnownUniquelyReferenced < T : AnyObject > ( _ object: inout T ) -> Bool
493
480
{
494
481
return _isUnique ( & object)
495
482
}
496
483
497
- internal func isUniquelyReferencedOrPinnedNonObjC < T : AnyObject > ( _ object: inout T ) -> Bool {
484
+ internal func _isKnownUniquelyReferencedOrPinned < T : AnyObject > ( _ object: inout T ) -> Bool {
498
485
return _isUniqueOrPinned ( & object)
499
486
}
500
487
501
- /// Returns `true` iff `object` is a non-`@objc` class instance with a single
488
+ /// Returns `true` iff `object` is known to be a class instance with a single
502
489
/// strong reference.
503
490
///
504
491
/// * Does *not* modify `object`; the use of `inout` is an
@@ -509,36 +496,7 @@ internal func isUniquelyReferencedOrPinnedNonObjC<T : AnyObject>(_ object: inout
509
496
/// deep storage of value types:
510
497
///
511
498
/// mutating func modifyMe(_ arg: X) {
512
- /// if isUniquelyReferenced(&myStorage) {
513
- /// myStorage.modifyInPlace(arg)
514
- /// }
515
- /// else {
516
- /// myStorage = myStorage.createModified(arg)
517
- /// }
518
- /// }
519
- ///
520
- /// This function is safe to use for `mutating` functions in
521
- /// multithreaded code because a false positive would imply that there
522
- /// is already a user-level data race on the value being mutated.
523
- public func isUniquelyReferenced< T : NonObjectiveCBase > (
524
- _ object: inout T
525
- ) -> Bool {
526
- return _isUnique ( & object)
527
- }
528
-
529
- /// Returns `true` iff `object` is a non-`@objc` class instance with
530
- /// a single strong reference.
531
- ///
532
- /// * Does *not* modify `object`; the use of `inout` is an
533
- /// implementation artifact.
534
- /// * If `object` is an Objective-C class instance, returns `false`.
535
- /// * Weak references do not affect the result of this function.
536
- ///
537
- /// Useful for implementing the copy-on-write optimization for the
538
- /// deep storage of value types:
539
- ///
540
- /// mutating func modifyMe(_ arg: X) {
541
- /// if isUniquelyReferencedNonObjC(&myStorage) {
499
+ /// if isKnownUniquelyReferenced(&myStorage) {
542
500
/// myStorage.modifyInPlace(arg)
543
501
/// }
544
502
/// else {
@@ -549,7 +507,7 @@ public func isUniquelyReferenced<T : NonObjectiveCBase>(
549
507
/// This function is safe to use for `mutating` functions in
550
508
/// multithreaded code because a false positive would imply that there
551
509
/// is already a user-level data race on the value being mutated.
552
- public func isUniquelyReferencedNonObjC < T : AnyObject > (
510
+ public func isKnownUniquelyReferenced < T : AnyObject > (
553
511
_ object: inout T ?
554
512
) -> Bool {
555
513
return _isUnique ( & object)
@@ -560,4 +518,39 @@ extension ManagedBufferPointer {
560
518
public var allocatedElementCount : Int {
561
519
Builtin . unreachable ( )
562
520
}
521
+
522
+ @available ( * , unavailable, renamed: " isUniqueReference " )
523
+ public mutating func holdsUniqueReference( ) -> Bool {
524
+ Builtin . unreachable ( )
525
+ }
526
+
527
+ @available ( * , unavailable, message: " this API is no longer available " )
528
+ public mutating func holdsUniqueOrPinnedReference( ) -> Bool {
529
+ Builtin . unreachable ( )
530
+ }
531
+ }
532
+
533
+ @available ( * , unavailable, renamed: " isKnownUniquelyReferenced " )
534
+ public func isUniquelyReferenced< T> (
535
+ _ object: inout T
536
+ ) -> Bool {
537
+ Builtin . unreachable ( )
538
+ }
539
+
540
+ @available ( * , unavailable, message: " use isKnownUniquelyReferenced instead " )
541
+ public class NonObjectiveCBase { }
542
+
543
+
544
+ @available ( * , unavailable, renamed: " isKnownUniquelyReferenced " )
545
+ public func isUniquelyReferencedNonObjC< T : AnyObject > (
546
+ _ object: inout T
547
+ ) -> Bool {
548
+ Builtin . unreachable ( )
549
+ }
550
+
551
+ @available ( * , unavailable, renamed: " isKnownUniquelyReferenced " )
552
+ public func isUniquelyReferencedNonObjC< T : AnyObject > (
553
+ _ object: inout T ?
554
+ ) -> Bool {
555
+ Builtin . unreachable ( )
563
556
}
0 commit comments