Skip to content

Foundation overlay needs to build with -swift-version 5 #19999

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Foundation/AffineTransform.swift
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public struct AffineTransform : ReferenceConvertible, Hashable, CustomStringConv

public func inverted() -> AffineTransform? {
let determinant = (m11 * m22) - (m12 * m21)
if fabs(determinant) <= ε {
if abs(determinant) <= ε {
return nil
}
var inverse = AffineTransform()
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ add_swift_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SD
UUID.swift
CheckClass.mm

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

SWIFT_MODULE_DEPENDS_OSX Darwin CoreFoundation CoreGraphics Dispatch IOKit ObjectiveC # auto-updated
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/SDK/Foundation/Calendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ public struct Calendar : Hashable, Equatable, ReferenceConvertible, _MutableBoxi
/// - parameter component: A component to calculate a range for.
/// - returns: The range, or nil if it could not be calculated.
public func minimumRange(of component: Component) -> Range<Int>? {
return _handle.map { $0.minimumRange(of: Calendar._toCalendarUnit([component])).toRange() }
return _handle.map { Range($0.minimumRange(of: Calendar._toCalendarUnit([component]))) }
}

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


Expand All @@ -383,7 +383,7 @@ public struct Calendar : Hashable, Equatable, ReferenceConvertible, _MutableBoxi
/// - parameter date: The absolute time for which the calculation is performed.
/// - 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).
public func range(of smaller: Component, in larger: Component, for date: Date) -> Range<Int>? {
return _handle.map { $0.range(of: Calendar._toCalendarUnit([smaller]), in: Calendar._toCalendarUnit([larger]), for: date).toRange() }
return _handle.map { Range($0.range(of: Calendar._toCalendarUnit([smaller]), in: Calendar._toCalendarUnit([larger]), for: date)) }
}

@available(*, unavailable, message: "use range(of:in:for:) instead")
Expand Down
20 changes: 20 additions & 0 deletions stdlib/public/SDK/Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ internal final class _DataStorage {
return d.bytes.advanced(by: -_offset)
case .customMutableReference(let d):
return d.bytes.advanced(by: -_offset)
@unknown default:
fatalError("Unknown Data backing type")
}
}
}
Expand Down Expand Up @@ -267,6 +269,8 @@ internal final class _DataStorage {
return data.mutableBytes.advanced(by: -_offset)
case .customMutableReference(let d):
return d.mutableBytes.advanced(by: -_offset)
@unknown default:
fatalError("Unknown Data backing type")
}
}
}
Expand All @@ -287,6 +291,8 @@ internal final class _DataStorage {
return d.length
case .customMutableReference(let d):
return d.length
@unknown default:
fatalError("Unknown Data backing type")
}
}
@inlinable
Expand Down Expand Up @@ -447,6 +453,8 @@ internal final class _DataStorage {
_backing = .customMutableReference(data)
case .customMutableReference(let d):
d.length = length
@unknown default:
fatalError("Unknown Data backing type")
}
}

Expand Down Expand Up @@ -478,6 +486,8 @@ internal final class _DataStorage {
_backing = .customMutableReference(data)
case .customMutableReference(let d):
d.append(bytes, length: length)
@unknown default:
fatalError("Unknown Data backing type")
}

}
Expand Down Expand Up @@ -528,6 +538,8 @@ internal final class _DataStorage {
_backing = .customReference(data)
case .customMutableReference(let d):
d.increaseLength(by: extraLength)
@unknown default:
fatalError("Unknown Data backing type")
}

}
Expand Down Expand Up @@ -614,6 +626,8 @@ internal final class _DataStorage {
_backing = .customMutableReference(data)
case .customMutableReference(let d):
d.replaceBytes(in: NSRange(location: range.location - _offset, length: range.length), withBytes: bytes!)
@unknown default:
fatalError("Unknown Data backing type")
}
}

Expand Down Expand Up @@ -664,6 +678,8 @@ internal final class _DataStorage {
_backing = .customMutableReference(data)
case .customMutableReference(let d):
d.replaceBytes(in: range, withBytes: replacementBytes, length: replacementLength)
@unknown default:
fatalError("Unknown Data backing type")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're going to have to come back and do something about these. If Data really can grow new representations, you'll need to make sure they're handled even in inlined code. Sadly we already have a pattern for this: https://twitter.com/UINT_MIN/status/1020503397357760512

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh :( ok, I should talk to @phausler about this

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code is going to have some changes coming in soon anyhow.

}
}

Expand Down Expand Up @@ -697,6 +713,8 @@ internal final class _DataStorage {
_backing = .customMutableReference(data)
case .customMutableReference(let d):
d.resetBytes(in: range)
@unknown default:
fatalError("Unknown Data backing type")
}

}
Expand Down Expand Up @@ -887,6 +905,8 @@ internal final class _DataStorage {
} else {
return _DataStorage(mutableReference: d.subdata(with: NSRange(location: range.lowerBound, length: range.count))._bridgeToObjectiveC().mutableCopy() as! NSMutableData, offset: range.lowerBound)
}
@unknown default:
fatalError("Unknown Data backing type")
}
}

Expand Down
7 changes: 3 additions & 4 deletions stdlib/public/SDK/Foundation/ExtraStringAPIs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,18 @@ extension String.UTF16View.Index {
@available(swift, deprecated: 3.2)
@available(swift, obsoleted: 4.0)
public init(_ offset: Int) {
assert(offset >= 0, "Negative UTF16 index offset not allowed")
self.init(encodedOffset: offset)
fatalError()
}

@available(swift, deprecated: 3.2)
@available(swift, obsoleted: 4.0)
public func distance(to other: String.UTF16View.Index?) -> Int {
return _offset.distance(to: other!._offset)
fatalError()
}

@available(swift, deprecated: 3.2)
@available(swift, obsoleted: 4.0)
public func advanced(by n: Int) -> String.UTF16View.Index {
return String.UTF16View.Index(_offset.advanced(by: n))
fatalError()
}
}
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Foundation/JSONEncoder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ open class JSONDecoder {
guard !stringKey.isEmpty else { return stringKey }

// Find the first non-underscore character
guard let firstNonUnderscore = stringKey.index(where: { $0 != "_" }) else {
guard let firstNonUnderscore = stringKey.firstIndex(where: { $0 != "_" }) else {
// Reached the end without finding an _
return stringKey
}
Expand Down
17 changes: 3 additions & 14 deletions stdlib/public/SDK/Foundation/NSError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -428,16 +428,6 @@ public protocol _BridgedStoredNSError :
init(_nsError error: NSError)
}

/// TODO: Better way to do this?
internal func _stringDictToAnyHashableDict(_ input: [String : Any])
-> [AnyHashable : Any] {
var result = [AnyHashable : Any](minimumCapacity: input.count)
for (k, v) in input {
result[k] = v
}
return result
}

/// Various helper implementations for _BridgedStoredNSError
extension _BridgedStoredNSError {
public var code: Code {
Expand All @@ -449,7 +439,7 @@ extension _BridgedStoredNSError {
public init(_ code: Code, userInfo: [String : Any] = [:]) {
self.init(_nsError: NSError(domain: Self.errorDomain,
code: unsafeBinaryIntegerToInt(code.rawValue),
userInfo: _stringDictToAnyHashableDict(userInfo)))
userInfo: userInfo))
}

/// The user-info dictionary for an error that was bridged from
Expand Down Expand Up @@ -483,8 +473,7 @@ public extension _BridgedStoredNSError {
var errorUserInfo: [String : Any] {
var result: [String : Any] = [:]
for (key, value) in _nsError.userInfo {
guard let stringKey = key.base as? String else { continue }
result[stringKey] = value
result[key] = value
}
return result
}
Expand Down Expand Up @@ -615,7 +604,7 @@ public extension CocoaError {

extension CocoaError {
public static func error(_ code: CocoaError.Code, userInfo: [AnyHashable : Any]? = nil, url: URL? = nil) -> Error {
var info: [AnyHashable : Any] = userInfo ?? [:]
var info: [String : Any] = userInfo as? [String : Any] ?? [:]
if let url = url {
info[NSURLErrorKey] = url
}
Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/SDK/Foundation/NSObject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ public class NSKeyValueObservation : NSObject {
let bridgeClass: AnyClass = NSKeyValueObservation.self
let observeSel = #selector(NSObject.observeValue(forKeyPath:of:change:context:))
let swapSel = #selector(NSKeyValueObservation._swizzle_me_observeValue(forKeyPath:of:change:context:))
let rootObserveImpl = class_getInstanceMethod(bridgeClass, observeSel)
let swapObserveImpl = class_getInstanceMethod(bridgeClass, swapSel)
let rootObserveImpl = class_getInstanceMethod(bridgeClass, observeSel)!
let swapObserveImpl = class_getInstanceMethod(bridgeClass, swapSel)!
method_exchangeImplementations(rootObserveImpl, swapObserveImpl)
return nil
}()
Expand Down
6 changes: 3 additions & 3 deletions stdlib/public/SDK/Foundation/NSStringAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1217,12 +1217,12 @@ extension StringProtocol where Index == String.Index {
let range = range.relative(to: self)
_ns.enumerateLinguisticTags(
in: _toRelativeNSRange(range),
scheme: tagScheme._ephemeralString,
scheme: NSLinguisticTagScheme(rawValue: tagScheme._ephemeralString),
options: opts,
orthography: orthography != nil ? orthography! : nil
) {
var stop_ = false
body($0, self._range($1), self._range($2), &stop_)
body($0!.rawValue, self._range($1), self._range($2), &stop_)
if stop_ {
$3.pointee = true
}
Expand Down Expand Up @@ -1463,7 +1463,7 @@ extension StringProtocol where Index == String.Index {
let result = tokenRanges._withNilOrAddress(of: &nsTokenRanges) {
self._ns.linguisticTags(
in: _toRelativeNSRange(range.relative(to: self)),
scheme: tagScheme._ephemeralString,
scheme: NSLinguisticTagScheme(rawValue: tagScheme._ephemeralString),
options: opts,
orthography: orthography,
tokenRanges: $0) as NSArray
Expand Down