Skip to content

Commit bd109be

Browse files
authored
Merge pull request #19999 from apple/david/Foundation-overlay-swift-5
Foundation overlay needs to build with -swift-version 5
2 parents 9aba7e2 + 88f0d3a commit bd109be

File tree

9 files changed

+37
-29
lines changed

9 files changed

+37
-29
lines changed

stdlib/public/SDK/Foundation/AffineTransform.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public struct AffineTransform : ReferenceConvertible, Hashable, CustomStringConv
239239

240240
public func inverted() -> AffineTransform? {
241241
let determinant = (m11 * m22) - (m12 * m21)
242-
if fabs(determinant) <= ε {
242+
if abs(determinant) <= ε {
243243
return nil
244244
}
245245
var inverse = AffineTransform()

stdlib/public/SDK/Foundation/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ add_swift_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SD
5959
UUID.swift
6060
CheckClass.mm
6161

62-
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}" "-Xllvm" "-sil-inline-generics" "-Xllvm" "-sil-partial-specialization" "-swift-version" "3"
62+
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}" "-Xllvm" "-sil-inline-generics" "-Xllvm" "-sil-partial-specialization" "-swift-version" "5"
6363
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
6464

6565
SWIFT_MODULE_DEPENDS_OSX Darwin CoreFoundation CoreGraphics Dispatch IOKit ObjectiveC # auto-updated

stdlib/public/SDK/Foundation/Calendar.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ public struct Calendar : Hashable, Equatable, ReferenceConvertible, _MutableBoxi
357357
/// - parameter component: A component to calculate a range for.
358358
/// - returns: The range, or nil if it could not be calculated.
359359
public func minimumRange(of component: Component) -> Range<Int>? {
360-
return _handle.map { $0.minimumRange(of: Calendar._toCalendarUnit([component])).toRange() }
360+
return _handle.map { Range($0.minimumRange(of: Calendar._toCalendarUnit([component]))) }
361361
}
362362

363363
/// The maximum range limits of the values that a given component can take on in the receive
@@ -366,7 +366,7 @@ public struct Calendar : Hashable, Equatable, ReferenceConvertible, _MutableBoxi
366366
/// - parameter component: A component to calculate a range for.
367367
/// - returns: The range, or nil if it could not be calculated.
368368
public func maximumRange(of component: Component) -> Range<Int>? {
369-
return _handle.map { $0.maximumRange(of: Calendar._toCalendarUnit([component])).toRange() }
369+
return _handle.map { Range($0.maximumRange(of: Calendar._toCalendarUnit([component]))) }
370370
}
371371

372372

@@ -383,7 +383,7 @@ public struct Calendar : Hashable, Equatable, ReferenceConvertible, _MutableBoxi
383383
/// - parameter date: The absolute time for which the calculation is performed.
384384
/// - returns: The range of absolute time values smaller can take on in larger at the time specified by date. Returns `nil` if larger is not logically bigger than smaller in the calendar, or the given combination of components does not make sense (or is a computation which is undefined).
385385
public func range(of smaller: Component, in larger: Component, for date: Date) -> Range<Int>? {
386-
return _handle.map { $0.range(of: Calendar._toCalendarUnit([smaller]), in: Calendar._toCalendarUnit([larger]), for: date).toRange() }
386+
return _handle.map { Range($0.range(of: Calendar._toCalendarUnit([smaller]), in: Calendar._toCalendarUnit([larger]), for: date)) }
387387
}
388388

389389
@available(*, unavailable, message: "use range(of:in:for:) instead")

stdlib/public/SDK/Foundation/Data.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ internal final class _DataStorage {
141141
return d.bytes.advanced(by: -_offset)
142142
case .customMutableReference(let d):
143143
return d.bytes.advanced(by: -_offset)
144+
@unknown default:
145+
fatalError("Unknown Data backing type")
144146
}
145147
}
146148
}
@@ -267,6 +269,8 @@ internal final class _DataStorage {
267269
return data.mutableBytes.advanced(by: -_offset)
268270
case .customMutableReference(let d):
269271
return d.mutableBytes.advanced(by: -_offset)
272+
@unknown default:
273+
fatalError("Unknown Data backing type")
270274
}
271275
}
272276
}
@@ -287,6 +291,8 @@ internal final class _DataStorage {
287291
return d.length
288292
case .customMutableReference(let d):
289293
return d.length
294+
@unknown default:
295+
fatalError("Unknown Data backing type")
290296
}
291297
}
292298
@inlinable
@@ -447,6 +453,8 @@ internal final class _DataStorage {
447453
_backing = .customMutableReference(data)
448454
case .customMutableReference(let d):
449455
d.length = length
456+
@unknown default:
457+
fatalError("Unknown Data backing type")
450458
}
451459
}
452460

@@ -478,6 +486,8 @@ internal final class _DataStorage {
478486
_backing = .customMutableReference(data)
479487
case .customMutableReference(let d):
480488
d.append(bytes, length: length)
489+
@unknown default:
490+
fatalError("Unknown Data backing type")
481491
}
482492

483493
}
@@ -528,6 +538,8 @@ internal final class _DataStorage {
528538
_backing = .customReference(data)
529539
case .customMutableReference(let d):
530540
d.increaseLength(by: extraLength)
541+
@unknown default:
542+
fatalError("Unknown Data backing type")
531543
}
532544

533545
}
@@ -614,6 +626,8 @@ internal final class _DataStorage {
614626
_backing = .customMutableReference(data)
615627
case .customMutableReference(let d):
616628
d.replaceBytes(in: NSRange(location: range.location - _offset, length: range.length), withBytes: bytes!)
629+
@unknown default:
630+
fatalError("Unknown Data backing type")
617631
}
618632
}
619633

@@ -664,6 +678,8 @@ internal final class _DataStorage {
664678
_backing = .customMutableReference(data)
665679
case .customMutableReference(let d):
666680
d.replaceBytes(in: range, withBytes: replacementBytes, length: replacementLength)
681+
@unknown default:
682+
fatalError("Unknown Data backing type")
667683
}
668684
}
669685

@@ -697,6 +713,8 @@ internal final class _DataStorage {
697713
_backing = .customMutableReference(data)
698714
case .customMutableReference(let d):
699715
d.resetBytes(in: range)
716+
@unknown default:
717+
fatalError("Unknown Data backing type")
700718
}
701719

702720
}
@@ -887,6 +905,8 @@ internal final class _DataStorage {
887905
} else {
888906
return _DataStorage(mutableReference: d.subdata(with: NSRange(location: range.lowerBound, length: range.count))._bridgeToObjectiveC().mutableCopy() as! NSMutableData, offset: range.lowerBound)
889907
}
908+
@unknown default:
909+
fatalError("Unknown Data backing type")
890910
}
891911
}
892912

stdlib/public/SDK/Foundation/ExtraStringAPIs.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ extension String.UTF16View.Index {
1515
@available(swift, deprecated: 3.2)
1616
@available(swift, obsoleted: 4.0)
1717
public init(_ offset: Int) {
18-
assert(offset >= 0, "Negative UTF16 index offset not allowed")
19-
self.init(encodedOffset: offset)
18+
fatalError()
2019
}
2120

2221
@available(swift, deprecated: 3.2)
2322
@available(swift, obsoleted: 4.0)
2423
public func distance(to other: String.UTF16View.Index?) -> Int {
25-
return _offset.distance(to: other!._offset)
24+
fatalError()
2625
}
2726

2827
@available(swift, deprecated: 3.2)
2928
@available(swift, obsoleted: 4.0)
3029
public func advanced(by n: Int) -> String.UTF16View.Index {
31-
return String.UTF16View.Index(_offset.advanced(by: n))
30+
fatalError()
3231
}
3332
}

stdlib/public/SDK/Foundation/JSONEncoder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1077,7 +1077,7 @@ open class JSONDecoder {
10771077
guard !stringKey.isEmpty else { return stringKey }
10781078

10791079
// Find the first non-underscore character
1080-
guard let firstNonUnderscore = stringKey.index(where: { $0 != "_" }) else {
1080+
guard let firstNonUnderscore = stringKey.firstIndex(where: { $0 != "_" }) else {
10811081
// Reached the end without finding an _
10821082
return stringKey
10831083
}

stdlib/public/SDK/Foundation/NSError.swift

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -428,16 +428,6 @@ public protocol _BridgedStoredNSError :
428428
init(_nsError error: NSError)
429429
}
430430

431-
/// TODO: Better way to do this?
432-
internal func _stringDictToAnyHashableDict(_ input: [String : Any])
433-
-> [AnyHashable : Any] {
434-
var result = [AnyHashable : Any](minimumCapacity: input.count)
435-
for (k, v) in input {
436-
result[k] = v
437-
}
438-
return result
439-
}
440-
441431
/// Various helper implementations for _BridgedStoredNSError
442432
extension _BridgedStoredNSError {
443433
public var code: Code {
@@ -449,7 +439,7 @@ extension _BridgedStoredNSError {
449439
public init(_ code: Code, userInfo: [String : Any] = [:]) {
450440
self.init(_nsError: NSError(domain: Self.errorDomain,
451441
code: unsafeBinaryIntegerToInt(code.rawValue),
452-
userInfo: _stringDictToAnyHashableDict(userInfo)))
442+
userInfo: userInfo))
453443
}
454444

455445
/// The user-info dictionary for an error that was bridged from
@@ -483,8 +473,7 @@ public extension _BridgedStoredNSError {
483473
var errorUserInfo: [String : Any] {
484474
var result: [String : Any] = [:]
485475
for (key, value) in _nsError.userInfo {
486-
guard let stringKey = key.base as? String else { continue }
487-
result[stringKey] = value
476+
result[key] = value
488477
}
489478
return result
490479
}
@@ -615,7 +604,7 @@ public extension CocoaError {
615604

616605
extension CocoaError {
617606
public static func error(_ code: CocoaError.Code, userInfo: [AnyHashable : Any]? = nil, url: URL? = nil) -> Error {
618-
var info: [AnyHashable : Any] = userInfo ?? [:]
607+
var info: [String : Any] = userInfo as? [String : Any] ?? [:]
619608
if let url = url {
620609
info[NSURLErrorKey] = url
621610
}

stdlib/public/SDK/Foundation/NSObject.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,8 @@ public class NSKeyValueObservation : NSObject {
149149
let bridgeClass: AnyClass = NSKeyValueObservation.self
150150
let observeSel = #selector(NSObject.observeValue(forKeyPath:of:change:context:))
151151
let swapSel = #selector(NSKeyValueObservation._swizzle_me_observeValue(forKeyPath:of:change:context:))
152-
let rootObserveImpl = class_getInstanceMethod(bridgeClass, observeSel)
153-
let swapObserveImpl = class_getInstanceMethod(bridgeClass, swapSel)
152+
let rootObserveImpl = class_getInstanceMethod(bridgeClass, observeSel)!
153+
let swapObserveImpl = class_getInstanceMethod(bridgeClass, swapSel)!
154154
method_exchangeImplementations(rootObserveImpl, swapObserveImpl)
155155
return nil
156156
}()

stdlib/public/SDK/Foundation/NSStringAPI.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,12 +1217,12 @@ extension StringProtocol where Index == String.Index {
12171217
let range = range.relative(to: self)
12181218
_ns.enumerateLinguisticTags(
12191219
in: _toRelativeNSRange(range),
1220-
scheme: tagScheme._ephemeralString,
1220+
scheme: NSLinguisticTagScheme(rawValue: tagScheme._ephemeralString),
12211221
options: opts,
12221222
orthography: orthography != nil ? orthography! : nil
12231223
) {
12241224
var stop_ = false
1225-
body($0, self._range($1), self._range($2), &stop_)
1225+
body($0!.rawValue, self._range($1), self._range($2), &stop_)
12261226
if stop_ {
12271227
$3.pointee = true
12281228
}
@@ -1463,7 +1463,7 @@ extension StringProtocol where Index == String.Index {
14631463
let result = tokenRanges._withNilOrAddress(of: &nsTokenRanges) {
14641464
self._ns.linguisticTags(
14651465
in: _toRelativeNSRange(range.relative(to: self)),
1466-
scheme: tagScheme._ephemeralString,
1466+
scheme: NSLinguisticTagScheme(rawValue: tagScheme._ephemeralString),
14671467
options: opts,
14681468
orthography: orthography,
14691469
tokenRanges: $0) as NSArray

0 commit comments

Comments
 (0)