Skip to content

Update to Swift 4 #1022

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 3 commits into from
Jun 26, 2017
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
24 changes: 12 additions & 12 deletions Foundation.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -2594,15 +2594,15 @@
r,
r,
);
OTHER_SWIFT_FLAGS = "-DDEPLOYMENT_ENABLE_LIBDISPATCH -DDEPLOYMENT_RUNTIME_SWIFT -swift-version 3";
OTHER_SWIFT_FLAGS = "-DDEPLOYMENT_ENABLE_LIBDISPATCH -DDEPLOYMENT_RUNTIME_SWIFT -swift-version 4";
PRODUCT_BUNDLE_IDENTIFIER = org.swift.Foundation;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_INDEX_STORE_ENABLE = NO;
SWIFT_INSTALL_OBJC_HEADER = NO;
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand Down Expand Up @@ -2667,14 +2667,14 @@
r,
r,
);
OTHER_SWIFT_FLAGS = "-DDEPLOYMENT_ENABLE_LIBDISPATCH -DDEPLOYMENT_RUNTIME_SWIFT -swift-version 3";
OTHER_SWIFT_FLAGS = "-DDEPLOYMENT_ENABLE_LIBDISPATCH -DDEPLOYMENT_RUNTIME_SWIFT -swift-version 4";
PRODUCT_BUNDLE_IDENTIFIER = org.swift.Foundation;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_INDEX_STORE_ENABLE = NO;
SWIFT_INSTALL_OBJC_HEADER = NO;
SWIFT_OBJC_INTERFACE_HEADER_NAME = "";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down Expand Up @@ -2716,7 +2716,7 @@
PRIVATE_HEADERS_FOLDER_PATH = /usr/local/include/CoreFoundation;
PRODUCT_NAME = "$(TARGET_NAME)";
PUBLIC_HEADERS_FOLDER_PATH = /usr/local/include/CoreFoundation;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand Down Expand Up @@ -2758,7 +2758,7 @@
PRIVATE_HEADERS_FOLDER_PATH = /usr/local/include/CoreFoundation;
PRODUCT_NAME = "$(TARGET_NAME)";
PUBLIC_HEADERS_FOLDER_PATH = /usr/local/include/CoreFoundation;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand All @@ -2778,12 +2778,12 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
MACH_O_TYPE = mh_execute;
OTHER_SWIFT_FLAGS = "-DDEPLOYMENT_ENABLE_LIBDISPATCH -swift-version 3";
OTHER_SWIFT_FLAGS = "-DDEPLOYMENT_ENABLE_LIBDISPATCH -swift-version 4";
PRODUCT_BUNDLE_IDENTIFIER = org.swift.TestFoundation;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
WRAPPER_EXTENSION = app;
};
name = Debug;
Expand All @@ -2804,11 +2804,11 @@
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
LIBRARY_SEARCH_PATHS = "$(inherited)";
MACH_O_TYPE = mh_execute;
OTHER_SWIFT_FLAGS = "-DDEPLOYMENT_ENABLE_LIBDISPATCH -swift-version 3";
OTHER_SWIFT_FLAGS = "-DDEPLOYMENT_ENABLE_LIBDISPATCH -swift-version 4";
PRODUCT_BUNDLE_IDENTIFIER = org.swift.TestFoundation;
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
WRAPPER_EXTENSION = app;
};
name = Release;
Expand Down Expand Up @@ -2863,7 +2863,7 @@
HEADER_SEARCH_PATHS = "$(CONFIGURATION_BUILD_DIR)/usr/local/include";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Debug;
};
Expand All @@ -2874,7 +2874,7 @@
CLANG_ENABLE_OBJC_ARC = YES;
HEADER_SEARCH_PATHS = "$(CONFIGURATION_BUILD_DIR)/usr/local/include";
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.0;
};
name = Release;
};
Expand Down
6 changes: 3 additions & 3 deletions Foundation/Calendar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,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 @@ -376,7 +376,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 @@ -393,7 +393,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)) }
}

/// Returns, via two inout parameters, the starting time and duration of a given calendar component that contains a given date.
Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
objects.reserveCapacity(objects.count + range.length)

if type(of: self) === NSArray.self || type(of: self) === NSMutableArray.self {
objects += _storage[range.toRange()!].map { _SwiftValue.fetch(nonOptional: $0) }
objects += _storage[Range(range)!].map { _SwiftValue.fetch(nonOptional: $0) }
return
}

Expand Down Expand Up @@ -381,7 +381,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
ptr.advanced(by: idx).pointee = Int32(hash).littleEndian
}
}
return Data(bytesNoCopy: buffer, count: size, deallocator: .custom({ _ in
return Data(bytesNoCopy: buffer, count: size, deallocator: .custom({ (_, _) in
buffer.deallocate(capacity: size)
}))
}
Expand Down Expand Up @@ -495,7 +495,7 @@ open class NSArray : NSObject, NSCopying, NSMutableCopying, NSSecureCoding, NSCo
return []
}

let swiftRange = range.toRange()!
let swiftRange = Range(range)!
return allObjects[swiftRange].sorted { lhs, rhs in
return cmptr(lhs, rhs) == .orderedAscending
}
Expand Down Expand Up @@ -784,7 +784,7 @@ open class NSMutableArray : NSArray {

open func removeObjects(in range: NSRange) {
if type(of: self) === NSMutableArray.self {
_storage.removeSubrange(range.toRange()!)
_storage.removeSubrange(Range(range)!)
} else {
for idx in range.toCountableRange()!.reversed() {
removeObject(at: idx)
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ open class NSData : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
open func range(of dataToFind: Data, options mask: SearchOptions = [], in searchRange: NSRange) -> NSRange {
let dataToFind = dataToFind._nsObject
guard dataToFind.length > 0 else {return NSRange(location: NSNotFound, length: 0)}
guard let searchRange = searchRange.toRange() else {fatalError("invalid range")}
guard let searchRange = Range(searchRange) else {fatalError("invalid range")}

precondition(searchRange.upperBound <= self.length, "range outside the bounds of data")

Expand Down
8 changes: 4 additions & 4 deletions Foundation/NSError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ open class NSError : NSObject, NSCopying, NSSecureCoding, NSCoding {
if let info = aDecoder.decodeObject(of: [NSSet.self, NSDictionary.self, NSArray.self, NSString.self, NSNumber.self, NSData.self, NSURL.self], forKey: "NSUserInfo") as? NSDictionary {
var filteredUserInfo = [String : Any]()
// user info must be filtered so that the keys are all strings
info.enumerateKeysAndObjects(options: []) {
if let key = $0.0 as? NSString {
filteredUserInfo[key._swiftObject] = $0.1
info.enumerateKeysAndObjects({ (key, value, _) in
if let key = key as? NSString {
filteredUserInfo[key._swiftObject] = value
}
}
})
_userInfo = filteredUserInfo
}
}
Expand Down
6 changes: 3 additions & 3 deletions Foundation/NSIndexSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ open class NSIndexSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {

open func mutableCopy(with zone: NSZone? = nil) -> Any {
let set = NSMutableIndexSet()
enumerateRanges(options: []) {
set.add(in: $0.0)
enumerateRanges(options: []) { (range, _) in
set.add(in: range)
}
return set
}
Expand Down Expand Up @@ -400,7 +400,7 @@ open class NSIndexSet : NSObject, NSCopying, NSMutableCopying, NSSecureCoding {
lock.unlock()
if stop { return }

let idx = rangeSequence.index(rangeSequence.startIndex, offsetBy: IntMax(rangeIdx))
let idx = rangeSequence.index(rangeSequence.startIndex, offsetBy: Int64(rangeIdx))
let curRange = rangeSequence[idx]
let intersection = NSIntersectionRange(curRange, range)
if passRanges {
Expand Down
12 changes: 6 additions & 6 deletions Foundation/NSNotificationQueue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,16 +109,16 @@ open class NotificationQueue: NSObject {
var predicate: (NSNotificationListEntry) -> Bool
switch coalesceMask {
case [.onName, .onSender]:
predicate = { (entryNotification, _) in
return _SwiftValue.store(notification.object) !== _SwiftValue.store(entryNotification.object) || notification.name != entryNotification.name
predicate = { entry in
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this one have remained as previous with the SE-110 revert?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unfortunately these three still gave the error 'does not support destructuring' even after I checked it with the latest compiler, but it was the only ones.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we should follow up on that separately but it shouldn't hold this up.

return _SwiftValue.store(notification.object) !== _SwiftValue.store(entry.0.object) || notification.name != entry.0.name
}
case [.onName]:
predicate = { (entryNotification, _) in
return notification.name != entryNotification.name
predicate = { entry in
return notification.name != entry.0.name
}
case [.onSender]:
predicate = { (entryNotification, _) in
return _SwiftValue.store(notification.object) !== _SwiftValue.store(entryNotification.object)
predicate = { entry in
return _SwiftValue.store(notification.object) !== _SwiftValue.store(entry.0.object)
}
default:
return
Expand Down
2 changes: 1 addition & 1 deletion Foundation/NSOrderedSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@ extension NSMutableOrderedSet {
NSUnimplemented()
}

let swiftRange = range.toRange()!
let swiftRange = Range(range)!
_orderedStorage[swiftRange].sort { lhs, rhs in
return cmptr(_SwiftValue.fetch(nonOptional: lhs), _SwiftValue.fetch(nonOptional: rhs)) == .orderedAscending
}
Expand Down
9 changes: 7 additions & 2 deletions Foundation/NSURLSession/http/HTTPBodySource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,13 @@ internal final class _HTTPBodyFileSource {
var fileSystemRepresentation: UnsafePointer<Int8>! = nil
fileURL.withUnsafeFileSystemRepresentation {
fileSystemRepresentation = $0
}
self.channel = DispatchIO(type: .stream, path: fileSystemRepresentation, oflag: O_RDONLY, mode: 0, queue: workQueue, cleanupHandler: {_ in })
}
guard let channel = DispatchIO(type: .stream, path: fileSystemRepresentation,
oflag: O_RDONLY, mode: 0, queue: workQueue,
cleanupHandler: {_ in }) else {
fatalError("Cant create DispatchIO channel")
}
self.channel = channel
self.channel.setLimit(highWater: CFURLSessionMaxWriteSize)
}

Expand Down
4 changes: 2 additions & 2 deletions Foundation/NSXMLNode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,8 @@ open class XMLNode: NSObject, NSCopying {
if let parentNode = _CFXMLNodeGetParent(parent!) {
let grandparent = XMLNode._objectNodeForNode(parentNode)
let possibleParentNodes = grandparent.filter { $0.name == self.parent?.name }
let count = possibleParentNodes.reduce(0) {
return $0.0 + 1
let count = possibleParentNodes.reduce(0) { (x, _) in
return x + 1
}

if count <= 1 {
Expand Down
4 changes: 2 additions & 2 deletions TestFoundation/TestNSCompoundPredicate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class TestNSCompoundPredicate: XCTestCase {
var shortCircuited = true

let bOK = NSPredicate(value: false)
let bDontEval = NSPredicate(block: { _ in
let bDontEval = NSPredicate(block: { (_, _) in
shortCircuited = false
return true
})
Expand All @@ -106,7 +106,7 @@ class TestNSCompoundPredicate: XCTestCase {
var shortCircuited = true

let bOK = NSPredicate(value: true)
let bDontEval = NSPredicate(block: { _ in
let bDontEval = NSPredicate(block: { (_, _) in
shortCircuited = false
return true
})
Expand Down
2 changes: 1 addition & 1 deletion TestFoundation/TestNSRange.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class TestNSRange : XCTestCase {
func test_NSRangeBridging() {
let swiftRange: Range<Int> = 1..<7
let range = NSRange(swiftRange)
let swiftRange2 = range.toRange()
let swiftRange2 = Range(range)
XCTAssertEqual(swiftRange, swiftRange2)
}

Expand Down
7 changes: 3 additions & 4 deletions TestFoundation/TestNSURLSession.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ class TestURLSession : XCTestCase {
let session = URLSession(configuration: URLSessionConfiguration.default,
delegate: delegate, delegateQueue: nil)
let completionExpectation = expectation(description: "dataTask completion block wasn't called")
let task = session.dataTask(with: url) { _ in
let task = session.dataTask(with: url) { (_, _, _) in
completionExpectation.fulfill()
}
task.resume()
Expand All @@ -207,9 +207,8 @@ class TestURLSession : XCTestCase {
delegate: nil,
delegateQueue: nil)
let completionExpectation = expectation(description: "dataTask completion block wasn't called")
let task = session.dataTask(with: url) { result in
let error = result.2 as? URLError

let task = session.dataTask(with: url) { (_, _, result) in
let error = result as? URLError
XCTAssertNotNil(error)
XCTAssertEqual(error?.code, .badURL)
completionExpectation.fulfill()
Expand Down
8 changes: 4 additions & 4 deletions lib/phases.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ def generate(self):
generated += " -I" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + self.product.ROOT_HEADERS_FOLDER_PATH
generated += " -I" + Configuration.current.build_directory.relative()
swiftflags = TargetConditional.value(self.product.SWIFTCFLAGS)
# Force building in Swift 3 compatibility mode.
swiftflags += " -swift-version 3"
# Force building in Swift 4 compatibility mode.
swiftflags += " -swift-version 4"
if swiftflags is not None:
generated += " " + swiftflags
return generated
Expand Down Expand Up @@ -431,10 +431,10 @@ def generate(self):
if resource is None:
continue
swiftSources += " " + resource.relative()
# Note: Fix -swift-version 3 for now.
# Note: Fix -swift-version 4 for now.
return """
build """ + appName + """: SwiftExecutable """ + swiftSources + self.generate_dependencies(libDependencyName) + """
flags = -swift-version 3 -I""" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + self.product.ROOT_HEADERS_FOLDER_PATH + " -I" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + " -L" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + " " + TargetConditional.value(self.product.SWIFTCFLAGS) + """
flags = -swift-version 4 -I""" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + self.product.ROOT_HEADERS_FOLDER_PATH + " -I" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + " -L" + Configuration.current.build_directory.path_by_appending(self.product.name).relative() + " " + TargetConditional.value(self.product.SWIFTCFLAGS) + """
build """ + self.executableName + """: phony | """ + appName + """
"""

Expand Down