Skip to content

Commit fab574c

Browse files
committed
stdlib: Add some @_versioned declarations to fix resilient build
A recent change made accessibility checking stricter. This had some fallout on the half-baked @_versioned attribute, where we could no longer define @_versioned members on a non-@_versioned type. This was wrong anyway (and will be diagnosed when we add proper diagnostics for @_versioned), because type metadata for the internal type did not get the right linkage, but it used to work as long as you didn't try to get the type metadata at runtime. This patch adds @_versioned attributes to the right types now that this broken behavior is gone. As a result, _Variant{Set,Dictionary}Storage became resilient (non-@_versioned internal types are not resilient), which broke too many tests that assumed you can exhaustively switch over all the cases. Since eager-bridging is going to eliminate this enum anyway (or so I've heard), make it @_fixed_layout for now.
1 parent 745a4a3 commit fab574c

File tree

7 files changed

+45
-0
lines changed

7 files changed

+45
-0
lines changed

stdlib/public/core/ArrayBuffer.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import SwiftShims
2121
internal typealias _ArrayBridgeStorage
2222
= _BridgeStorage<_ContiguousArrayStorageBase, _NSArrayCore>
2323

24+
@_versioned
2425
@_fixed_layout
2526
internal struct _ArrayBuffer<Element> : _ArrayBufferProtocol {
2627

@@ -29,6 +30,7 @@ internal struct _ArrayBuffer<Element> : _ArrayBufferProtocol {
2930
_storage = _ArrayBridgeStorage(native: _emptyArrayStorage)
3031
}
3132

33+
@_versioned // FIXME(abi): Used from tests
3234
internal init(nsArray: _NSArrayCore) {
3335
_sanityCheck(_isClassOrObjCExistential(Element.self))
3436
_storage = _ArrayBridgeStorage(objC: nsArray)
@@ -113,6 +115,7 @@ extension _ArrayBuffer {
113115
/// Convert to an NSArray.
114116
///
115117
/// O(1) if the element type is bridged verbatim, O(*n*) otherwise.
118+
@_versioned // FIXME(abi): Used from tests
116119
internal func _asCocoaArray() -> _NSArrayCore {
117120
return _fastPath(_isNative) ? _native._asCocoaArray() : _nonNative
118121
}
@@ -273,6 +276,7 @@ extension _ArrayBuffer {
273276
/// A pointer to the first element.
274277
///
275278
/// - Precondition: The elements are known to be stored contiguously.
279+
@_versioned
276280
internal var firstElementAddress: UnsafeMutablePointer<Element> {
277281
_sanityCheck(_isNative, "must be a native buffer")
278282
return _native.firstElementAddress

stdlib/public/core/ArrayBufferProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
/// The underlying buffer for an ArrayType conforms to
1414
/// `_ArrayBufferProtocol`. This buffer does not provide value semantics.
15+
@_versioned
1516
internal protocol _ArrayBufferProtocol
1617
: MutableCollection, RandomAccessCollection {
1718

stdlib/public/core/Builtin.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,7 @@ public func _onFastPath() {
283283
// Declare it here instead of RuntimeShims.h, because we need to specify
284284
// the type of argument to be AnyClass. This is currently not possible
285285
// when using RuntimeShims.h
286+
@_versioned
286287
@_silgen_name("swift_objc_class_usesNativeSwiftReferenceCounting")
287288
func _usesNativeSwiftReferenceCounting(_ theClass: AnyClass) -> Bool
288289
#else
@@ -480,6 +481,7 @@ internal func _makeBridgeObject(
480481
)
481482
}
482483

484+
@_versioned
483485
@_silgen_name("_swift_class_getSuperclass")
484486
internal func _swift_class_getSuperclass(_ t: AnyClass) -> AnyClass?
485487

stdlib/public/core/ContiguousArrayBuffer.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ final class _ContiguousArrayStorage<Element> : _ContiguousArrayStorage1 {
176176
}
177177
}
178178

179+
@_versioned
179180
@_fixed_layout
180181
internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
181182

@@ -247,6 +248,7 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
247248
}
248249

249250
/// A pointer to the first element.
251+
@_versioned
250252
internal var firstElementAddress: UnsafeMutablePointer<Element> {
251253
return UnsafeMutablePointer(Builtin.projectTailElems(_storage,
252254
Element.self))
@@ -318,6 +320,7 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
318320
}
319321

320322
/// Get or set the value of the ith element.
323+
@_versioned
321324
internal subscript(i: Int) -> Element {
322325
get {
323326
return getElement(i)
@@ -434,6 +437,7 @@ internal struct _ContiguousArrayBuffer<Element> : _ArrayBufferProtocol {
434437
#endif
435438

436439
/// An object that keeps the elements stored in this buffer alive.
440+
@_versioned
437441
internal var owner: AnyObject {
438442
return _storage
439443
}

stdlib/public/core/HashedCollections.swift.gyb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2508,6 +2508,7 @@ internal struct _HashedContainerStorageHeader {
25082508
/// Enough bytes are allocated to hold the bitmap for marking valid entries,
25092509
/// keys, and values. The data layout starts with the bitmap, followed by the
25102510
/// keys, followed by the values.
2511+
@_versioned
25112512
final internal class _Native${Self}StorageImpl<${TypeParameters}> {
25122513
// Note: It is intended that ${TypeParameters}
25132514
// (without : Hashable) is used here - this storage must work
@@ -3229,6 +3230,7 @@ final internal class _Native${Self}StorageKeyNSEnumerator<
32293230
/// is also a proper `NS${Self}` subclass, which is returned to Objective-C
32303231
/// during bridging. `${Self}Index` points directly to
32313232
/// `_Native${Self}Storage`.
3233+
@_versioned
32323234
final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
32333235
: _SwiftNativeNS${Self}, _NS${Self}Core {
32343236

@@ -3564,7 +3566,10 @@ final internal class _Native${Self}StorageOwner<${TypeParametersDecl}>
35643566
}
35653567

35663568
#if _runtime(_ObjC)
3569+
@_versioned
3570+
@_fixed_layout
35673571
internal struct _Cocoa${Self}Storage : _HashStorage {
3572+
@_versioned
35683573
internal var cocoa${Self}: _NS${Self}
35693574

35703575
internal typealias Index = _Cocoa${Self}Index
@@ -3695,6 +3700,8 @@ internal struct _Cocoa${Self}Storage : _HashStorage {
36953700
internal struct _Cocoa${Self}Storage {}
36963701
#endif
36973702

3703+
@_versioned
3704+
@_fixed_layout
36983705
internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
36993706

37003707
internal typealias NativeStorage = _Native${Self}Storage<${TypeParameters}>
@@ -4408,6 +4415,7 @@ internal enum _Variant${Self}Storage<${TypeParametersDecl}> : _HashStorage {
44084415
}
44094416
}
44104417

4418+
@_versioned
44114419
internal struct _Native${Self}Index<${TypeParametersDecl}> :
44124420
Comparable {
44134421

@@ -4418,6 +4426,8 @@ internal struct _Native${Self}Index<${TypeParametersDecl}> :
44184426
// the new model.
44194427
@_versioned
44204428
internal var nativeStorage: NativeStorage
4429+
4430+
@_versioned
44214431
internal var offset: Int
44224432

44234433
@_versioned
@@ -4799,6 +4809,7 @@ final internal class _Cocoa${Self}Iterator : IteratorProtocol {
47994809
final internal class _Cocoa${Self}Iterator {}
48004810
#endif
48014811

4812+
@_versioned
48024813
internal enum ${Self}IteratorRepresentation<${TypeParametersDecl}> {
48034814
internal typealias _Iterator = ${Self}Iterator<${TypeParameters}>
48044815
internal typealias _NativeStorageOwner =

stdlib/public/core/SipHash.swift.gyb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,15 @@
1919
/// * Daniel J. Bernstein <[email protected]>
2020
//===----------------------------------------------------------------------===//
2121

22+
@_versioned
2223
internal enum _SipHashDetail {
24+
@_versioned
2325
@inline(__always)
2426
internal static func _rotate(_ x: UInt64, leftBy amount: Int) -> UInt64 {
2527
return (x << UInt64(amount)) | (x >> (64 - UInt64(amount)))
2628
}
2729

30+
@_versioned
2831
@inline(__always)
2932
internal static func _loadUnalignedUInt64LE(
3033
from p: UnsafeRawPointer
@@ -40,6 +43,7 @@ internal enum _SipHashDetail {
4043
(UInt64(p.load(fromByteOffset: 7, as: UInt8.self)) << 56)
4144
}
4245

46+
@_versioned
4347
@inline(__always)
4448
internal static func _loadPartialUnalignedUInt64LE(
4549
from p: UnsafeRawPointer,
@@ -57,6 +61,7 @@ internal enum _SipHashDetail {
5761
return result
5862
}
5963

64+
@_versioned
6065
@inline(__always)
6166
internal static func _sipRound(
6267
v0: inout UInt64,
@@ -87,16 +92,28 @@ internal enum _SipHashDetail {
8792
public // @testable
8893
struct ${Self} {
8994
// "somepseudorandomlygeneratedbytes"
95+
@_versioned
9096
internal var v0: UInt64 = 0x736f6d6570736575
97+
98+
@_versioned
9199
internal var v1: UInt64 = 0x646f72616e646f6d
100+
101+
@_versioned
92102
internal var v2: UInt64 = 0x6c7967656e657261
103+
104+
@_versioned
93105
internal var v3: UInt64 = 0x7465646279746573
94106

107+
@_versioned
95108
internal var hashedByteCount: UInt64 = 0
96109

110+
@_versioned
97111
internal var dataTail: UInt64 = 0
112+
113+
@_versioned
98114
internal var dataTailByteCount: Int = 0
99115

116+
@_versioned
100117
internal var finalizedHash: UInt64?
101118

102119
public init(key: (UInt64, UInt64)) {
@@ -113,6 +130,7 @@ struct ${Self} {
113130
}
114131

115132
// FIXME(ABI)#63 (UnsafeRawBufferPointer): Use UnsafeRawBufferPointer.
133+
@_versioned
116134
@inline(__always)
117135
internal mutating func _append_alwaysInline(
118136
_ data: UnsafeRawPointer,
@@ -165,6 +183,7 @@ struct ${Self} {
165183

166184
/// This function mixes in the given word directly into the state,
167185
/// ignoring `dataTail`.
186+
@_versioned
168187
@inline(__always)
169188
internal mutating func _appendDirectly(_ m: UInt64) {
170189
v3 ^= m
@@ -188,6 +207,7 @@ struct ${Self} {
188207
return _finalizeAndReturnHash_alwaysInline()
189208
}
190209

210+
@_versioned
191211
@inline(__always)
192212
internal mutating func _finalizeAndReturnHash_alwaysInline() -> UInt64 {
193213
if let finalizedHash = finalizedHash {
@@ -238,6 +258,7 @@ struct ${Self} {
238258
}
239259

240260
// FIXME(ABI)#65 (UnsafeRawBufferPointer): Use UnsafeRawBufferPointer.
261+
@_versioned
241262
@inline(__always)
242263
public // @testable
243264
static func _hash_alwaysInline(

stdlib/public/core/SliceBuffer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
/// Buffer type for `ArraySlice<Element>`.
14+
@_versioned
1415
internal struct _SliceBuffer<Element>
1516
: _ArrayBufferProtocol,
1617
RandomAccessCollection
@@ -121,6 +122,7 @@ internal struct _SliceBuffer<Element>
121122
internal var owner: AnyObject
122123
internal let subscriptBaseAddress: UnsafeMutablePointer<Element>
123124

125+
@_versioned
124126
internal var firstElementAddress: UnsafeMutablePointer<Element> {
125127
return subscriptBaseAddress + startIndex
126128
}

0 commit comments

Comments
 (0)