Skip to content

Commit a4230ab

Browse files
[stdlib] Update stdlib to 4.0 and reorganize compatibility shims (#17580)
* Update stdlib to 4.0 and move all compatibility shims into a dedicated source file
1 parent 109829b commit a4230ab

File tree

72 files changed

+1381
-1818
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+1381
-1818
lines changed

cmake/modules/SwiftSource.cmake

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,9 @@ function(_compile_swift_files
257257
"-Xfrontend" "${GROUP_INFO_JSON_FILE}")
258258
endif()
259259

260-
# Force swift 3 compatibility mode for Standard Library.
260+
# Force swift 4 compatibility mode for Standard Library.
261261
if (SWIFTFILE_IS_STDLIB)
262-
list(APPEND swift_flags "-swift-version" "3")
262+
list(APPEND swift_flags "-swift-version" "4")
263263
endif()
264264

265265
# Force swift 4 compatibility mode for overlays.

stdlib/private/StdlibUnittest/MinimalTypes.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public var GenericMinimalHashableValue_equalImpl =
220220
fatalError("GenericMinimalHashableValue_equalImpl is not set yet")
221221
})
222222
public var GenericMinimalHashableValue_hashIntoImpl =
223-
ResettableValue<(Any, inout Hasher) -> Void>({ _ in
223+
ResettableValue<(Any, inout Hasher) -> Void>({ (_,_) in
224224
fatalError("GenericMinimalHashableValue_hashIntoImpl is not set yet")
225225
})
226226

@@ -276,7 +276,7 @@ public var GenericMinimalHashableClass_equalImpl =
276276
fatalError("GenericMinimalHashableClass_equalImpl is not set yet")
277277
})
278278
public var GenericMinimalHashableClass_hashIntoImpl =
279-
ResettableValue<(Any, inout Hasher) -> Void>({ _ in
279+
ResettableValue<(Any, inout Hasher) -> Void>({ (_,_) in
280280
fatalError("GenericMinimalHashableClass_hashIntoImpl is not set yet")
281281
})
282282

stdlib/private/StdlibUnittest/StdlibUnittest.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1775,15 +1775,15 @@ public func _parseDottedVersionTriple(_ s: String) -> (Int, Int, Int) {
17751775
}
17761776

17771777
func _getOSVersion() -> OSVersion {
1778-
#if os(iOS) && (arch(i386) || arch(x86_64))
1778+
#if os(iOS) && targetEnvironment(simulator)
17791779
// On simulator, the plist file that we try to read turns out to be host's
17801780
// plist file, which indicates OS X.
17811781
//
17821782
// FIXME: how to get the simulator version *without* UIKit?
17831783
return .iOSSimulator
1784-
#elseif os(tvOS) && (arch(i386) || arch(x86_64))
1784+
#elseif os(tvOS) && targetEnvironment(simulator)
17851785
return .tvOSSimulator
1786-
#elseif os(watchOS) && (arch(i386) || arch(x86_64))
1786+
#elseif os(watchOS) && targetEnvironment(simulator)
17871787
return .watchOSSimulator
17881788
#elseif os(Linux)
17891789
return .linux

stdlib/public/SDK/AppKit/AppKit.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import Foundation
1414
@_exported import AppKit
1515

16-
extension NSCursor : _DefaultCustomPlaygroundQuickLookable {
16+
extension NSCursor : __DefaultCustomPlaygroundQuickLookable {
1717
@available(*, deprecated, message: "NSCursor._defaultCustomPlaygroundQuickLook will be removed in a future Swift version")
1818
public var _defaultCustomPlaygroundQuickLook: PlaygroundQuickLook {
1919
return .image(image)
@@ -24,7 +24,7 @@ internal struct _NSViewQuickLookState {
2424
static var views = Set<NSView>()
2525
}
2626

27-
extension NSView : _DefaultCustomPlaygroundQuickLookable {
27+
extension NSView : __DefaultCustomPlaygroundQuickLookable {
2828
@available(*, deprecated, message: "NSView._defaultCustomPlaygroundQuickLook will be removed in a future Swift version")
2929
public var _defaultCustomPlaygroundQuickLook: PlaygroundQuickLook {
3030
// if you set NSView.needsDisplay, you can get yourself in a recursive scenario where the same view

stdlib/public/SDK/CoreGraphics/CoreGraphics.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,13 @@ public extension CGPoint {
228228
}
229229
}
230230

231-
extension CGPoint : CustomReflectable, CustomPlaygroundQuickLookable {
231+
extension CGPoint : CustomReflectable {
232232
public var customMirror: Mirror {
233233
return Mirror(self, children: ["x": x, "y": y], displayStyle: .`struct`)
234234
}
235+
}
235236

237+
extension CGPoint : _CustomPlaygroundQuickLookable {
236238
@available(*, deprecated, message: "CGPoint.customPlaygroundQuickLook will be removed in a future Swift version")
237239
public var customPlaygroundQuickLook: PlaygroundQuickLook {
238240
return .point(Double(x), Double(y))
@@ -293,14 +295,16 @@ public extension CGSize {
293295
}
294296
}
295297

296-
extension CGSize : CustomReflectable, CustomPlaygroundQuickLookable {
298+
extension CGSize : CustomReflectable {
297299
public var customMirror: Mirror {
298300
return Mirror(
299301
self,
300302
children: ["width": width, "height": height],
301303
displayStyle: .`struct`)
302304
}
305+
}
303306

307+
extension CGSize : _CustomPlaygroundQuickLookable {
304308
@available(*, deprecated, message: "CGSize.customPlaygroundQuickLook will be removed in a future Swift version")
305309
public var customPlaygroundQuickLook: PlaygroundQuickLook {
306310
return .size(Double(width), Double(height))
@@ -431,14 +435,16 @@ public extension CGRect {
431435
public var y: CGFloat { return minY }
432436
}
433437

434-
extension CGRect : CustomReflectable, CustomPlaygroundQuickLookable {
438+
extension CGRect : CustomReflectable {
435439
public var customMirror: Mirror {
436440
return Mirror(
437441
self,
438442
children: ["origin": origin, "size": size],
439443
displayStyle: .`struct`)
440444
}
445+
}
441446

447+
extension CGRect : _CustomPlaygroundQuickLookable {
442448
@available(*, deprecated, message: "CGRect.customPlaygroundQuickLook will be removed in a future Swift version")
443449
public var customPlaygroundQuickLook: PlaygroundQuickLook {
444450
return .rectangle(

stdlib/public/SDK/Foundation/Date.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ extension NSDate : _HasCustomAnyHashableRepresentation {
272272
}
273273
}
274274

275-
extension Date : CustomPlaygroundQuickLookable {
275+
extension Date : _CustomPlaygroundQuickLookable {
276276
var summary: String {
277277
let df = DateFormatter()
278278
df.dateStyle = .medium

stdlib/public/SDK/Foundation/NSCoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ extension NSKeyedUnarchiver {
172172
@available(macOS 10.13, iOS 11.0, watchOS 4.0, tvOS 11.0, *)
173173
public static func unarchivedObject<DecodedObjectType>(ofClass cls: DecodedObjectType.Type, from data: Data) throws -> DecodedObjectType? where DecodedObjectType : NSCoding, DecodedObjectType : NSObject {
174174
var error: NSError?
175-
let result = __NSKeyedUnarchiverSecureUnarchiveObjectOfClass(cls as! AnyClass, data, &error)
175+
let result = __NSKeyedUnarchiverSecureUnarchiveObjectOfClass(cls as AnyClass, data, &error)
176176
try resolveError(error)
177177
return result as? DecodedObjectType
178178
}

stdlib/public/SDK/Foundation/NSDate.swift

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

1313
@_exported import Foundation // Clang module
1414

15-
extension NSDate : CustomPlaygroundQuickLookable {
15+
extension NSDate : _CustomPlaygroundQuickLookable {
1616
@nonobjc
1717
var summary: String {
1818
let df = DateFormatter()

stdlib/public/SDK/Foundation/NSRange.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ extension NSRange : CustomReflectable {
197197
}
198198
}
199199

200-
extension NSRange : CustomPlaygroundQuickLookable {
200+
extension NSRange : _CustomPlaygroundQuickLookable {
201201
@available(*, deprecated, message: "NSRange.customPlaygroundQuickLook will be removed in a future Swift version")
202202
public var customPlaygroundQuickLook: PlaygroundQuickLook {
203203
return .range(Int64(location), Int64(length))

stdlib/public/SDK/Foundation/NSString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ extension NSString {
107107
}
108108
}
109109

110-
extension NSString : CustomPlaygroundQuickLookable {
110+
extension NSString : _CustomPlaygroundQuickLookable {
111111
@available(*, deprecated, message: "NSString.customPlaygroundQuickLook will be removed in a future Swift version")
112112
public var customPlaygroundQuickLook: PlaygroundQuickLook {
113113
return .text(self as String)

stdlib/public/SDK/Foundation/NSURL.swift

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

1313
@_exported import Foundation // Clang module
1414

15-
extension NSURL : CustomPlaygroundQuickLookable {
15+
extension NSURL : _CustomPlaygroundQuickLookable {
1616
@available(*, deprecated, message: "NSURL.customPlaygroundQuickLook will be removed in a future Swift version")
1717
public var customPlaygroundQuickLook: PlaygroundQuickLook {
1818
guard let str = absoluteString else { return .text("Unknown URL") }

stdlib/public/SDK/Foundation/URL.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ extension NSURL : _HasCustomAnyHashableRepresentation {
12101210
}
12111211
}
12121212

1213-
extension URL : CustomPlaygroundQuickLookable {
1213+
extension URL : _CustomPlaygroundQuickLookable {
12141214
@available(*, deprecated, message: "URL.customPlaygroundQuickLook will be removed in a future Swift version")
12151215
public var customPlaygroundQuickLook: PlaygroundQuickLook {
12161216
return .url(absoluteString)

stdlib/public/SDK/SpriteKit/SpriteKitQuickLooks.swift.gyb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
% for Self in ['SKShapeNode', 'SKSpriteNode', 'SKTextureAtlas', 'SKTexture']:
1616

17-
extension ${Self} : CustomPlaygroundQuickLookable {
17+
extension ${Self} : _CustomPlaygroundQuickLookable {
1818
@available(*, deprecated, message: "${Self}.customPlaygroundQuickLook will be removed in a future Swift version")
1919
public var customPlaygroundQuickLook: PlaygroundQuickLook {
2020
let data = (self as AnyObject)._copyImageData?() as Data?

stdlib/public/core/Algorithm.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,3 @@ extension EnumeratedSequence: Sequence {
158158
return Iterator(_base: _base.makeIterator())
159159
}
160160
}
161-
162-
@available(*, deprecated: 4.2, renamed: "EnumeratedSequence.Iterator")
163-
public typealias EnumeratedIterator<T: Sequence> = EnumeratedSequence<T>.Iterator

stdlib/public/core/BidirectionalCollection.swift

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// A type that provides subscript access to its elements, with bidirectional
14-
/// index traversal.
15-
///
16-
/// In most cases, it's best to ignore this protocol and use the
17-
/// `BidirectionalCollection` protocol instead, because it has a more complete
18-
/// interface.
19-
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'BidirectionalCollection' instead")
20-
public typealias BidirectionalIndexable = BidirectionalCollection
21-
2213
/// A collection that supports backward as well as forward traversal.
2314
///
2415
/// Bidirectional collections offer traversal backward from any valid index,

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ set(SWIFTLIB_ESSENTIAL
7373
Hashing.swift
7474
HeapBuffer.swift
7575
ICU.swift
76-
ImplicitlyUnwrappedOptional.swift
7776
Indices.swift
7877
InputStream.swift
7978
IntegerParsing.swift
@@ -123,7 +122,6 @@ set(SWIFTLIB_ESSENTIAL
123122
Sort.swift.gyb
124123
StaticString.swift
125124
Stride.swift.gyb
126-
StringCharacterView.swift # ORDER DEPENDENCY: Must precede String.swift
127125
StringHashable.swift # ORDER DEPENDENCY: Must precede String.swift
128126
String.swift
129127
StringBridge.swift
@@ -168,6 +166,7 @@ set(SWIFTLIB_ESSENTIAL
168166
StringGraphemeBreaking.swift # ORDER DEPENDENCY: Must follow UTF16.swift
169167
ValidUTF8Buffer.swift
170168
WriteBackMutableSlice.swift
169+
MigrationSupport.swift
171170
)
172171

173172
# The complete list of sources in the core standard library. Includes

stdlib/public/core/ClosedRange.swift

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -459,16 +459,7 @@ extension ClosedRange {
459459
}
460460
}
461461

462-
extension ClosedRange where Bound: Strideable, Bound.Stride : SignedInteger {
463-
/// Now that Range is conditionally a collection when Bound: Strideable,
464-
/// CountableRange is no longer needed. This is a deprecated initializer
465-
/// for any remaining uses of Range(countableRange).
466-
@available(*,deprecated: 4.2,
467-
message: "CountableRange is now Range. No need to convert any more.")
468-
public init(_ other: ClosedRange<Bound>) {
469-
self = other
470-
}
471-
462+
extension ClosedRange where Bound: Strideable, Bound.Stride : SignedInteger {
472463
/// Creates an instance equivalent to the given `Range`.
473464
///
474465
/// - Parameter other: A `Range` to convert to a `ClosedRange` instance.
@@ -495,8 +486,7 @@ extension ClosedRange {
495486
}
496487
}
497488

498-
@available(*, deprecated, renamed: "ClosedRange.Index")
499-
public typealias ClosedRangeIndex<T> = ClosedRange<T>.Index where T: Strideable, T.Stride: SignedInteger
500-
489+
// Note: this is not for compatibility only, it is considered a useful
490+
// shorthand. TODO: Add documentation
501491
public typealias CountableClosedRange<Bound: Strideable> = ClosedRange<Bound>
502492
where Bound.Stride : SignedInteger

stdlib/public/core/Collection.swift

Lines changed: 5 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
/// A type that provides subscript access to its elements, with forward
14-
/// index traversal.
15-
///
16-
/// In most cases, it's best to ignore this protocol and use the `Collection`
17-
/// protocol instead, because it has a more complete interface.
18-
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'Collection' instead")
19-
public typealias IndexableBase = Collection
20-
21-
/// A type that provides subscript access to its elements, with forward index
22-
/// traversal.
23-
///
24-
/// In most cases, it's best to ignore this protocol and use the `Collection`
25-
/// protocol instead, because it has a more complete interface.
26-
@available(*, deprecated, message: "it will be removed in Swift 4.0. Please use 'Collection' instead")
27-
public typealias Indexable = Collection
28-
2913
/// A type that iterates over a collection using its indices.
3014
///
3115
/// The `IndexingIterator` type is the default iterator for any collection that
@@ -349,6 +333,11 @@ extension IndexingIterator: IteratorProtocol, Sequence {
349333
/// the number of contained elements, accessing its `count` property is an
350334
/// O(*n*) operation.
351335
public protocol Collection: Sequence where SubSequence: Collection {
336+
// FIXME: ideally this would be in MigrationSupport.swift, but it needs
337+
// to be on the protocol instead of as an extension
338+
@available(*, deprecated/*, obsoleted: 5.0*/, message: "all index distances are now of type Int")
339+
typealias IndexDistance = Int
340+
352341
// FIXME(ABI): Associated type inference requires this.
353342
associatedtype Element
354343

@@ -826,9 +815,6 @@ public protocol Collection: Sequence where SubSequence: Collection {
826815
__consuming func randomElement<T: RandomNumberGenerator>(
827816
using generator: inout T
828817
) -> Element?
829-
830-
@available(*, deprecated, message: "all index distances are now of type Int")
831-
typealias IndexDistance = Int
832818
}
833819

834820
/// Default implementation for forward collections.
@@ -1803,35 +1789,3 @@ extension Collection {
18031789
return try preprocess()
18041790
}
18051791
}
1806-
1807-
extension Collection {
1808-
// FIXME: <rdar://problem/34142121>
1809-
// This typealias should be removed as it predates the source compatibility
1810-
// guarantees of Swift 3, but it cannot due to a bug.
1811-
@available(*, unavailable, renamed: "Iterator")
1812-
public typealias Generator = Iterator
1813-
1814-
@available(swift, deprecated: 3.2, renamed: "Element")
1815-
public typealias _Element = Element
1816-
1817-
@available(*, deprecated, message: "all index distances are now of type Int")
1818-
public func index<T: BinaryInteger>(_ i: Index, offsetBy n: T) -> Index {
1819-
return index(i, offsetBy: Int(n))
1820-
}
1821-
@available(*, deprecated, message: "all index distances are now of type Int")
1822-
public func formIndex<T: BinaryInteger>(_ i: inout Index, offsetBy n: T) {
1823-
return formIndex(&i, offsetBy: Int(n))
1824-
}
1825-
@available(*, deprecated, message: "all index distances are now of type Int")
1826-
public func index<T: BinaryInteger>(_ i: Index, offsetBy n: T, limitedBy limit: Index) -> Index? {
1827-
return index(i, offsetBy: Int(n), limitedBy: limit)
1828-
}
1829-
@available(*, deprecated, message: "all index distances are now of type Int")
1830-
public func formIndex<T: BinaryInteger>(_ i: inout Index, offsetBy n: T, limitedBy limit: Index) -> Bool {
1831-
return formIndex(&i, offsetBy: Int(n), limitedBy: limit)
1832-
}
1833-
@available(*, deprecated, message: "all index distances are now of type Int")
1834-
public func distance<T: BinaryInteger>(from start: Index, to end: Index) -> T {
1835-
return numericCast(distance(from: start, to: end) as Int)
1836-
}
1837-
}

stdlib/public/core/CollectionOfOne.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,3 @@ extension CollectionOfOne : CustomReflectable {
170170
return Mirror(self, children: ["element": _element])
171171
}
172172
}
173-
174-
@available(*,deprecated: 4.2,renamed: "CollectionOfOne.Iterator")
175-
public typealias IteratorOverOne<T> = CollectionOfOne<T>.Iterator

0 commit comments

Comments
 (0)