Skip to content

Commit c4c4c17

Browse files
committed
[stdlib] _BridgeStorage: Remove second type parameter (ObjCClass)
It used to be a shadow protocol existential, but now it’s invariably AnyObject. I see no reason to keep supporting this unused abstraction.
1 parent 0463230 commit c4c4c17

File tree

8 files changed

+35
-24
lines changed

8 files changed

+35
-24
lines changed

Diff for: stdlib/public/core/ArrayBuffer.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import SwiftShims
2020

2121
@usableFromInline
2222
internal typealias _ArrayBridgeStorage
23-
= _BridgeStorage<__ContiguousArrayStorageBase, AnyObject>
23+
= _BridgeStorage<__ContiguousArrayStorageBase>
2424

2525
@usableFromInline
2626
@_fixed_layout

Diff for: stdlib/public/core/BridgeStorage.swift

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
// Types that are bridged to Objective-C need to manage an object
1414
// that may be either some native class or the @objc Cocoa
1515
// equivalent. _BridgeStorage discriminates between these two
16-
// possibilities and stores a few extra bits when the stored type is
16+
// possibilities and stores a single extra bit when the stored type is
1717
// native. It is assumed that the @objc class instance may in fact
1818
// be a tagged pointer, and thus no extra bits may be available.
1919
//
@@ -22,15 +22,12 @@ import SwiftShims
2222

2323
@_fixed_layout
2424
@usableFromInline
25-
internal struct _BridgeStorage<
26-
NativeClass: AnyObject,
27-
ObjCClass: AnyObject
28-
> {
25+
internal struct _BridgeStorage<NativeClass: AnyObject> {
2926
@usableFromInline
3027
internal typealias Native = NativeClass
3128

3229
@usableFromInline
33-
internal typealias ObjC = ObjCClass
30+
internal typealias ObjC = AnyObject
3431

3532
// rawValue is passed inout to _isUnique. Although its value
3633
// is unchanged, it must appear mutable to the optimizer.

Diff for: stdlib/public/core/DictionaryVariant.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ extension Dictionary {
3535
@_fixed_layout
3636
internal struct _Variant {
3737
@usableFromInline
38-
internal var object: _BridgeStorage<_RawDictionaryStorage, AnyObject>
38+
internal var object: _BridgeStorage<_RawDictionaryStorage>
3939

4040
@inlinable
4141
@inline(__always)

Diff for: stdlib/public/core/SetVariant.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ extension Set {
3131
@_fixed_layout
3232
internal struct _Variant {
3333
@usableFromInline
34-
internal var object: _BridgeStorage<_RawSetStorage, AnyObject>
34+
internal var object: _BridgeStorage<_RawSetStorage>
3535

3636
@inlinable
3737
@inline(__always)

Diff for: test/SILOptimizer/dead_array_elim.sil

+7-7
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ bb0(%0 : $TrivialDestructor):
6464
store %0 to %10 : $*TrivialDestructor
6565
%13 = struct_extract %5 : $Array<TrivialDestructor>, #Array._buffer
6666
%14 = struct_extract %13 : $_ArrayBuffer<TrivialDestructor>, #_ArrayBuffer._storage
67-
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase, AnyObject>, #_BridgeStorage.rawValue
67+
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase>, #_BridgeStorage.rawValue
6868
strong_retain %0 : $TrivialDestructor
6969
strong_release %15 : $Builtin.BridgeObject
7070
// CHECK-NEXT: tuple ()
@@ -91,7 +91,7 @@ bb0(%0 : $TrivialDestructor):
9191
%7 = pointer_to_address %6 : $Builtin.RawPointer to [strict] $*TrivialDestructor
9292
%13 = struct_extract %5 : $Array<TrivialDestructor>, #Array._buffer
9393
%14 = struct_extract %13 : $_ArrayBuffer<TrivialDestructor>, #_ArrayBuffer._storage
94-
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase, AnyObject>, #_BridgeStorage.rawValue
94+
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase>, #_BridgeStorage.rawValue
9595
strong_retain %0 : $TrivialDestructor
9696
strong_release %15 : $Builtin.BridgeObject
9797

@@ -121,7 +121,7 @@ bb0(%0 : $TrivialDestructor):
121121
%6 = tuple_extract %4 : $(Array<TrivialDestructor>, Builtin.RawPointer), 1
122122
%13 = struct_extract %5 : $Array<TrivialDestructor>, #Array._buffer
123123
%14 = struct_extract %13 : $_ArrayBuffer<TrivialDestructor>, #_ArrayBuffer._storage
124-
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase, AnyObject>, #_BridgeStorage.rawValue
124+
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase>, #_BridgeStorage.rawValue
125125
cond_br undef, bb1, bb2
126126

127127
bb1:
@@ -159,7 +159,7 @@ bb1:
159159
%5 = tuple_extract %4 : $(Array<TrivialDestructor>, Builtin.RawPointer), 0
160160
%13 = struct_extract %5 : $Array<TrivialDestructor>, #Array._buffer
161161
%14 = struct_extract %13 : $_ArrayBuffer<TrivialDestructor>, #_ArrayBuffer._storage
162-
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase, AnyObject>, #_BridgeStorage.rawValue
162+
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase>, #_BridgeStorage.rawValue
163163
strong_release %15 : $Builtin.BridgeObject
164164
%18 = tuple ()
165165
return %18 : $()
@@ -190,7 +190,7 @@ bb0(%0 : $TrivialDestructor):
190190
%12 = tuple_extract %4 : $(Array<TrivialDestructor>, Builtin.RawPointer), 0
191191
%13 = struct_extract %12 : $Array<TrivialDestructor>, #Array._buffer
192192
%14 = struct_extract %13 : $_ArrayBuffer<TrivialDestructor>, #_ArrayBuffer._storage
193-
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase, AnyObject>, #_BridgeStorage.rawValue
193+
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase>, #_BridgeStorage.rawValue
194194
strong_release %15 : $Builtin.BridgeObject
195195

196196
return %22 : $TrivialDestructor
@@ -217,7 +217,7 @@ bb0(%0 : $TrivialDestructor, %1 : $TrivialDestructor):
217217
%7 = pointer_to_address %6 : $Builtin.RawPointer to [strict] $*TrivialDestructor
218218
%13 = struct_extract %5 : $Array<TrivialDestructor>, #Array._buffer
219219
%14 = struct_extract %13 : $_ArrayBuffer<TrivialDestructor>, #_ArrayBuffer._storage
220-
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase, AnyObject>, #_BridgeStorage.rawValue
220+
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase>, #_BridgeStorage.rawValue
221221
cond_br undef, bb1, bb2
222222

223223
bb1:
@@ -260,7 +260,7 @@ bb1:
260260
%7 = pointer_to_address %6 : $Builtin.RawPointer to [strict] $*TrivialDestructor
261261
%13 = struct_extract %5 : $Array<TrivialDestructor>, #Array._buffer
262262
%14 = struct_extract %13 : $_ArrayBuffer<TrivialDestructor>, #_ArrayBuffer._storage
263-
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase, AnyObject>, #_BridgeStorage.rawValue
263+
%15 = struct_extract %14 : $_BridgeStorage<__ContiguousArrayStorageBase>, #_BridgeStorage.rawValue
264264
strong_retain %0 : $TrivialDestructor
265265
store %0 to %7 : $*TrivialDestructor
266266
strong_release %15 : $Builtin.BridgeObject

Diff for: test/SILOptimizer/licm_multiend.sil

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ bb0:
5555
%1 = struct_element_addr %0 : $*ReversedCollection<Array<Int>>, #ReversedCollection._base
5656
%2 = struct_element_addr %1 : $*Array<Int>, #Array._buffer
5757
%3 = struct_element_addr %2 : $*_ArrayBuffer<Int>, #_ArrayBuffer._storage
58-
%4 = struct_element_addr %3 : $*_BridgeStorage<__ContiguousArrayStorageBase, AnyObject>, #_BridgeStorage.rawValue
58+
%4 = struct_element_addr %3 : $*_BridgeStorage<__ContiguousArrayStorageBase>, #_BridgeStorage.rawValue
5959
%5 = load %4 : $*Builtin.BridgeObject
6060
%6 = unchecked_ref_cast %5 : $Builtin.BridgeObject to $__ContiguousArrayStorageBase
6161
%7 = ref_element_addr %6 : $__ContiguousArrayStorageBase, #__ContiguousArrayStorageBase.countAndCapacity
@@ -140,7 +140,7 @@ bb0:
140140
%1 = struct_element_addr %0 : $*ReversedCollection<Array<Int>>, #ReversedCollection._base
141141
%2 = struct_element_addr %1 : $*Array<Int>, #Array._buffer
142142
%3 = struct_element_addr %2 : $*_ArrayBuffer<Int>, #_ArrayBuffer._storage
143-
%4 = struct_element_addr %3 : $*_BridgeStorage<__ContiguousArrayStorageBase, AnyObject>, #_BridgeStorage.rawValue
143+
%4 = struct_element_addr %3 : $*_BridgeStorage<__ContiguousArrayStorageBase>, #_BridgeStorage.rawValue
144144
%5 = load %4 : $*Builtin.BridgeObject
145145
%6 = unchecked_ref_cast %5 : $Builtin.BridgeObject to $__ContiguousArrayStorageBase
146146
%7 = ref_element_addr %6 : $__ContiguousArrayStorageBase, #__ContiguousArrayStorageBase.countAndCapacity

Diff for: test/api-digester/Outputs/stability-stdlib-abi.swift.expected

+18-4
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ Func Dictionary._bridgeToObjectiveCImpl() has return type change from _NSDiction
289289
Func _NativeDictionary.bridged() has return type change from _NSDictionary to AnyObject
290290
Protocol _NSDictionary has been removed
291291
Protocol _NSDictionaryCore has been removed
292-
Var Dictionary._Variant.object has declared type change from _BridgeStorage<_RawDictionaryStorage, _NSDictionary> to _BridgeStorage<_RawDictionaryStorage, AnyObject>
292+
Var Dictionary._Variant.object has declared type change from _BridgeStorage<_RawDictionaryStorage, _NSDictionary> to _BridgeStorage<_RawDictionaryStorage>
293293
Var _CocoaDictionary.object has declared type change from _NSDictionary to AnyObject
294294

295295
Class _EmptySetSingleton has removed conformance to _NSSetCore
@@ -301,7 +301,7 @@ Func _NativeSet.bridged() has return type change from _NSSet to AnyObject
301301
Func _stdlib_CFSetGetValues(_:_:) has been removed
302302
Protocol _NSSet has been removed
303303
Protocol _NSSetCore has been removed
304-
Var Set._Variant.object has declared type change from _BridgeStorage<_RawSetStorage, _NSSet> to _BridgeStorage<_RawSetStorage, AnyObject>
304+
Var Set._Variant.object has declared type change from _BridgeStorage<_RawSetStorage, _NSSet> to _BridgeStorage<_RawSetStorage>
305305
Var _CocoaSet.object has declared type change from _NSSet to AnyObject
306306

307307
Protocol _NSNumber has been removed
@@ -313,7 +313,7 @@ Class __SwiftDeferredNSArray has removed conformance to _NSArrayCore
313313
Class __SwiftNativeNSArrayWithContiguousStorage has removed conformance to _NSArrayCore
314314
Constructor Array.init(_immutableCocoaArray:) has parameter 0 type change from _NSArrayCore to AnyObject
315315
Constructor _ArrayBuffer.init(nsArray:) has parameter 0 type change from _NSArrayCore to AnyObject
316-
Constructor _ArrayBuffer.init(storage:) has parameter 0 type change from _BridgeStorage<__ContiguousArrayStorageBase, _NSArrayCore> to _BridgeStorage<__ContiguousArrayStorageBase, AnyObject>
316+
Constructor _ArrayBuffer.init(storage:) has parameter 0 type change from _BridgeStorage<__ContiguousArrayStorageBase, _NSArrayCore> to _BridgeStorage<__ContiguousArrayStorageBase>
317317
Constructor _CocoaArrayWrapper.init(_:) has parameter 0 type change from _NSArrayCore to AnyObject
318318
Func _ArrayBuffer._asCocoaArray() has return type change from _NSArrayCore to AnyObject
319319
Func _CocoaArrayWrapper.contiguousStorage(_:) has been removed
@@ -325,8 +325,22 @@ Struct _CocoaArrayWrapper has type witness type for Collection.SubSequence chang
325325
Struct _CocoaArrayWrapper has type witness type for RandomAccessCollection.SubSequence changing from Slice<_CocoaArrayWrapper> to _SliceBuffer<AnyObject>
326326
Struct _CocoaArrayWrapper has type witness type for Sequence.SubSequence changing from Slice<_CocoaArrayWrapper> to _SliceBuffer<AnyObject>
327327
Var _ArrayBuffer._nonNative has declared type change from _NSArrayCore to _CocoaArrayWrapper
328-
Var _ArrayBuffer._storage has declared type change from _BridgeStorage<__ContiguousArrayStorageBase, _NSArrayCore> to _BridgeStorage<__ContiguousArrayStorageBase, AnyObject>
328+
Var _ArrayBuffer._storage has declared type change from _BridgeStorage<__ContiguousArrayStorageBase, _NSArrayCore> to _BridgeStorage<__ContiguousArrayStorageBase>
329329
Var _CocoaArrayWrapper.buffer has declared type change from _NSArrayCore to AnyObject
330330

331331
Var _SliceBuffer.endIndexAndFlags in a non-resilient type changes position from 2 to 3
332332
Var _SliceBuffer.startIndex in a non-resilient type changes position from 3 to 2
333+
334+
Constructor _BridgeStorage.init(native:) has generic signature change from <τ_0_0, τ_0_1 where τ_0_0 : AnyObject, τ_0_1 : AnyObject> to <τ_0_0 where τ_0_0 : AnyObject>
335+
Constructor _BridgeStorage.init(native:) has return type change from _BridgeStorage<τ_0_0, τ_0_1> to _BridgeStorage<τ_0_0>
336+
Constructor _BridgeStorage.init(native:isFlagged:) has generic signature change from <τ_0_0, τ_0_1 where τ_0_0 : AnyObject, τ_0_1 : AnyObject> to <τ_0_0 where τ_0_0 : AnyObject>
337+
Constructor _BridgeStorage.init(native:isFlagged:) has return type change from _BridgeStorage<τ_0_0, τ_0_1> to _BridgeStorage<τ_0_0>
338+
Constructor _BridgeStorage.init(objC:) has generic signature change from <τ_0_0, τ_0_1 where τ_0_0 : AnyObject, τ_0_1 : AnyObject> to <τ_0_0 where τ_0_0 : AnyObject>
339+
Constructor _BridgeStorage.init(objC:) has parameter 0 type change from τ_0_1 to AnyObject
340+
Constructor _BridgeStorage.init(objC:) has return type change from _BridgeStorage<τ_0_0, τ_0_1> to _BridgeStorage<τ_0_0>
341+
Constructor _BridgeStorage.init(taggedPayload:) has generic signature change from <τ_0_0, τ_0_1 where τ_0_0 : AnyObject, τ_0_1 : AnyObject> to <τ_0_0 where τ_0_0 : AnyObject>
342+
Constructor _BridgeStorage.init(taggedPayload:) has return type change from _BridgeStorage<τ_0_0, τ_0_1> to _BridgeStorage<τ_0_0>
343+
Func _BridgeStorage.isUniquelyReferencedNative() has generic signature change from <τ_0_0, τ_0_1 where τ_0_0 : AnyObject, τ_0_1 : AnyObject> to <τ_0_0 where τ_0_0 : AnyObject>
344+
Func _BridgeStorage.isUniquelyReferencedUnflaggedNative() has generic signature change from <τ_0_0, τ_0_1 where τ_0_0 : AnyObject, τ_0_1 : AnyObject> to <τ_0_0 where τ_0_0 : AnyObject>
345+
Struct _BridgeStorage has generic signature change from <τ_0_0, τ_0_1 where τ_0_0 : AnyObject, τ_0_1 : AnyObject> to <τ_0_0 where τ_0_0 : AnyObject>
346+
Var _BridgeStorage.objCInstance has declared type change from τ_0_1 to AnyObject

Diff for: test/stdlib/BridgeStorage.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ var unTaggedNSString : NSString {
116116
}
117117

118118
allTests.test("_BridgeStorage") {
119-
typealias B = _BridgeStorage<C, NSString>
119+
typealias B = _BridgeStorage<C>
120120

121121
let oy: NSString = "oy"
122-
expectTrue(B(objC: oy).objCInstance == oy)
122+
expectTrue(B(objC: oy).objCInstance === oy)
123123

124124
for flag in [false, true] {
125125
do {

0 commit comments

Comments
 (0)