21
21
import SwiftShims
22
22
23
23
@_fixed_layout
24
- public // @testable
25
- struct _BridgeStorage <
26
- NativeClass: AnyObject , ObjCClass: AnyObject
24
+ @usableFromInline
25
+ internal struct _BridgeStorage <
26
+ NativeClass: AnyObject ,
27
+ ObjCClass: AnyObject
27
28
> {
28
- public // @testable
29
- typealias Native = NativeClass
30
-
31
- public // @testable
32
- typealias ObjC = ObjCClass
33
-
34
- @inlinable // FIXME(sil-serialize-all)
29
+ @usableFromInline
30
+ internal typealias Native = NativeClass
31
+
32
+ @usableFromInline
33
+ internal typealias ObjC = ObjCClass
34
+
35
+ // rawValue is passed inout to _isUnique. Although its value
36
+ // is unchanged, it must appear mutable to the optimizer.
37
+ @usableFromInline
38
+ internal var rawValue : Builtin . BridgeObject
39
+
40
+ @inlinable
35
41
@inline ( __always)
36
- public // @testable
37
- init ( native: Native , bits: Int ) {
42
+ internal init ( native: Native , isFlagged flag: Bool ) {
43
+ // Note: Some platforms provide more than one spare bit, but the minimum is
44
+ // a single bit.
45
+
38
46
_sanityCheck ( _usesNativeSwiftReferenceCounting ( NativeClass . self) )
39
-
40
- // More bits are available on some platforms, but it's not portable
41
- _sanityCheck ( 0 ... 1 ~= bits,
42
- " BridgeStorage can't store bits outside the range 0...1 " )
43
47
44
48
rawValue = _makeNativeBridgeObject (
45
- native, UInt ( bits) << _objectPointerLowSpareBitShift)
49
+ native,
50
+ flag ? ( 1 as UInt ) << _objectPointerLowSpareBitShift : 0 )
46
51
}
47
-
48
- @inlinable // FIXME(sil-serialize-all)
52
+
53
+ @inlinable
49
54
@inline ( __always)
50
- public // @testable
51
- init ( objC: ObjC ) {
55
+ internal init ( objC: ObjC ) {
52
56
_sanityCheck ( _usesNativeSwiftReferenceCounting ( NativeClass . self) )
53
57
rawValue = _makeObjCBridgeObject ( objC)
54
58
}
55
-
56
- @inlinable // FIXME(sil-serialize-all)
59
+
60
+ @inlinable
57
61
@inline ( __always)
58
- public // @testable
59
- init ( native: Native ) {
62
+ internal init ( native: Native ) {
60
63
_sanityCheck ( _usesNativeSwiftReferenceCounting ( NativeClass . self) )
61
64
rawValue = Builtin . reinterpretCast ( native)
62
65
}
@@ -69,97 +72,73 @@ struct _BridgeStorage<
69
72
}
70
73
#endif
71
74
72
- @inlinable // FIXME(sil-serialize-all)
73
- public // @testable
74
- var spareBits : Int {
75
- @inline ( __always) get {
76
- _sanityCheck ( isNative)
77
- return Int (
78
- _nonPointerBits ( rawValue) >> _objectPointerLowSpareBitShift)
79
- }
80
- }
81
-
82
- @inlinable // FIXME(sil-serialize-all)
75
+ @inlinable
83
76
@inline ( __always)
84
- public // @testable
85
- mutating func isUniquelyReferencedNative( ) -> Bool {
77
+ internal mutating func isUniquelyReferencedNative( ) -> Bool {
86
78
return _isUnique ( & rawValue)
87
79
}
88
80
89
- @inlinable // FIXME(sil-serialize-all)
90
- public // @testable
91
- var isNative : Bool {
81
+ @inlinable
82
+ internal var isNative : Bool {
92
83
@inline ( __always) get {
93
84
let result = Builtin . classifyBridgeObject ( rawValue)
94
85
return !Bool( Builtin . or_Int1 ( result. isObjCObject,
95
86
result. isObjCTaggedPointer) )
96
87
}
97
88
}
98
-
99
- @inlinable // FIXME(sil-serialize-all)
100
- @inline ( __always)
101
- public // @testable
102
- func isNativeWithClearedSpareBits( _ bits: Int ) -> Bool {
103
- return ( _bitPattern ( rawValue) &
104
- ( _bridgeObjectTaggedPointerBits | _objCTaggedPointerBits |
105
- _objectPointerIsObjCBit |
106
- ( UInt ( bits) ) << _objectPointerLowSpareBitShift) ) == 0
89
+
90
+ @inlinable
91
+ static var flagMask : UInt {
92
+ @inline ( __always) get {
93
+ return ( 1 as UInt ) << _objectPointerLowSpareBitShift
94
+ }
95
+ }
96
+
97
+ @inlinable
98
+ internal var isUnflaggedNative : Bool {
99
+ @inline ( __always) get {
100
+ return ( _bitPattern ( rawValue) &
101
+ ( _bridgeObjectTaggedPointerBits | _objCTaggedPointerBits |
102
+ _objectPointerIsObjCBit | _BridgeStorage. flagMask) ) == 0
103
+ }
107
104
}
108
105
109
- @inlinable // FIXME(sil-serialize-all)
110
- public // @testable
111
- var isObjC : Bool {
106
+ @inlinable
107
+ internal var isObjC : Bool {
112
108
@inline ( __always) get {
113
109
return !isNative
114
110
}
115
111
}
116
-
117
- @inlinable // FIXME(sil-serialize-all)
118
- public // @testable
119
- var nativeInstance : Native {
112
+
113
+ @inlinable
114
+ internal var nativeInstance : Native {
120
115
@inline ( __always) get {
121
116
_sanityCheck ( isNative)
122
117
return Builtin . castReferenceFromBridgeObject ( rawValue)
123
118
}
124
119
}
125
-
126
- @inlinable // FIXME(sil-serialize-all)
127
- public // @testable
128
- var nativeInstance_noSpareBits : Native {
120
+
121
+ @inlinable
122
+ internal var unflaggedNativeInstance : Native {
129
123
@inline ( __always) get {
130
124
_sanityCheck ( isNative)
131
125
_sanityCheck ( _nonPointerBits ( rawValue) == 0 )
132
126
return Builtin . reinterpretCast ( rawValue)
133
127
}
134
128
}
135
-
136
- @inlinable // FIXME(sil-serialize-all)
129
+
130
+ @inlinable
137
131
@inline ( __always)
138
- public // @testable
139
- mutating func isUniquelyReferenced_native_noSpareBits( ) -> Bool {
132
+ internal mutating func isUniquelyReferencedUnflaggedNative( ) -> Bool {
140
133
_sanityCheck ( isNative)
141
134
return _isUnique_native ( & rawValue)
142
135
}
143
136
144
- @inlinable // FIXME(sil-serialize-all)
145
- public // @testable
146
- var objCInstance : ObjC {
137
+ @inlinable
138
+ internal var objCInstance : ObjC {
147
139
@inline ( __always) get {
148
140
_sanityCheck ( isObjC)
149
141
return Builtin . castReferenceFromBridgeObject ( rawValue)
150
142
}
151
143
}
152
-
153
- //===--- private --------------------------------------------------------===//
154
- @inlinable // FIXME(sil-serialize-all)
155
- internal var _isTagged : Bool {
156
- @inline ( __always) get {
157
- return Bool ( Builtin . classifyBridgeObject ( rawValue) . isObjCTaggedPointer)
158
- }
159
- }
160
-
161
- // rawValue is passed inout to _isUnique. Although its value
162
- // is unchanged, it must appear mutable to the optimizer.
163
- @usableFromInline
164
- internal var rawValue : Builtin . BridgeObject
165
144
}
0 commit comments