Skip to content

[stdlib] Fixing compilation warnings #7314

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
Feb 8, 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
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Dispatch/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public struct DispatchDataIterator : IteratorProtocol, Sequence {
extension DispatchData {
@_semantics("convertToObjectiveC")
public func _bridgeToObjectiveC() -> __DispatchData {
return unsafeBitCast(__wrapped, to: __DispatchData.self)
return __wrapped
}

public static func _forceBridgeFromObjectiveC(_ input: __DispatchData, result: inout DispatchData?) {
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Foundation/Data.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public final class _DataStorage {
var dest = dest_
var source = source_
var num = num_
if _DataStorage.vmOpsThreshold <= num && ((unsafeBitCast(source, to: Int.self) | unsafeBitCast(dest, to: Int.self)) & (NSPageSize() - 1)) == 0 {
if _DataStorage.vmOpsThreshold <= num && ((unsafeBitCast(source, to: Int.self) | Int(bitPattern: dest)) & (NSPageSize() - 1)) == 0 {
let pages = NSRoundDownToMultipleOfPageSize(num)
NSCopyMemoryPages(source!, dest, pages)
source = source!.advanced(by: pages)
Expand Down
4 changes: 3 additions & 1 deletion stdlib/public/SDK/Foundation/DateInterval.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,9 @@ public struct DateInterval : ReferenceConvertible, Comparable, Hashable {
public var hashValue: Int {
var buf: (UInt, UInt) = (UInt(start.timeIntervalSinceReferenceDate), UInt(end.timeIntervalSinceReferenceDate))
return withUnsafeMutablePointer(to: &buf) {
return Int(bitPattern: CFHashBytes(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self), CFIndex(MemoryLayout<UInt>.size * 2)))
$0.withMemoryRebound(to: UInt8.self, capacity: 2 * MemoryLayout<UInt>.size / MemoryLayout<UInt8>.size) {
return Int(bitPattern: CFHashBytes($0, CFIndex(MemoryLayout<UInt>.size * 2)))
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions stdlib/public/SDK/Foundation/IndexSet.swift
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ private final class _MutablePairHandle<ImmutableType : NSObject, MutableType : N
return try whatToDo(i)
case .Mutable(let m):
// TODO: It should be possible to reflect the constraint that MutableType is a subtype of ImmutableType in the generics for the class, but I haven't figured out how yet. For now, cheat and unsafe bit cast.
return try whatToDo(unsafeBitCast(m, to: ImmutableType.self))
return try whatToDo(unsafeDowncast(m, to: ImmutableType.self))
}
}

Expand All @@ -966,7 +966,7 @@ private final class _MutablePairHandle<ImmutableType : NSObject, MutableType : N
return i
case .Mutable(let m):
// TODO: It should be possible to reflect the constraint that MutableType is a subtype of ImmutableType in the generics for the class, but I haven't figured out how yet. For now, cheat and unsafe bit cast.
return unsafeBitCast(m, to: ImmutableType.self)
return unsafeDowncast(m, to: ImmutableType.self)
}
}
}
32 changes: 23 additions & 9 deletions stdlib/public/SDK/Foundation/UUID.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,18 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
/* Create a new UUID with RFC 4122 version 4 random bytes */
public init() {
withUnsafeMutablePointer(to: &uuid) {
uuid_generate_random(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self))
$0.withMemoryRebound(to: UInt8.self, capacity: 16) {
uuid_generate_random($0)
}
}
}

fileprivate init(reference: NSUUID) {
var bytes: uuid_t = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
withUnsafeMutablePointer(to: &bytes) {
reference.getBytes(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self))
$0.withMemoryRebound(to: UInt8.self, capacity: 16) {
reference.getBytes($0)
}
}
uuid = bytes
}
Expand All @@ -40,7 +44,9 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
/// Returns nil for invalid strings.
public init?(uuidString string: String) {
let res = withUnsafeMutablePointer(to: &uuid) {
return uuid_parse(string, unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self))
$0.withMemoryRebound(to: UInt8.self, capacity: 16) {
return uuid_parse(string, $0)
}
}
if res != 0 {
return nil
Expand All @@ -56,18 +62,24 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
public var uuidString: String {
var bytes: uuid_string_t = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
var localValue = uuid
return withUnsafeMutablePointer(to: &localValue) { val in
withUnsafeMutablePointer(to: &bytes) { str in
uuid_unparse(unsafeBitCast(val, to: UnsafePointer<UInt8>.self), unsafeBitCast(str, to: UnsafeMutablePointer<Int8>.self))
return String(cString: unsafeBitCast(str, to: UnsafePointer<CChar>.self), encoding: .utf8)!
return withUnsafeMutablePointer(to: &localValue) {
$0.withMemoryRebound(to: UInt8.self, capacity: 16) { val in
withUnsafeMutablePointer(to: &bytes) {
$0.withMemoryRebound(to: Int8.self, capacity: 37) { str in
uuid_unparse(val, str)
return String(cString: UnsafePointer(str), encoding: .utf8)!
}
}
}
}
}

public var hashValue: Int {
var localValue = uuid
return withUnsafeMutablePointer(to: &localValue) {
return Int(bitPattern: CFHashBytes(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self), CFIndex(MemoryLayout<uuid_t>.size)))
$0.withMemoryRebound(to: UInt8.self, capacity: 16) {
return Int(bitPattern: CFHashBytes($0, CFIndex(MemoryLayout<uuid_t>.size)))
}
}
}

Expand All @@ -84,7 +96,9 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
fileprivate var reference: NSUUID {
var bytes = uuid
return withUnsafePointer(to: &bytes) {
return NSUUID(uuidBytes: unsafeBitCast($0, to: UnsafePointer<UInt8>.self))
$0.withMemoryRebound(to: UInt8.self, capacity: 16) {
return NSUUID(uuidBytes: $0)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Intents/INRequestRideIntent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extension INRequestRideIntent {
paymentMethod: INPaymentMethod? = nil,
scheduledPickupTime: INDateComponentsRange? = nil
) {
if #available(iOS 10.3, watchOS 3.2, *) {
if #available(iOS 10.3, *) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it correct to drop availability here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The whole extension is only available in watchOS 3.2, so this check will always be true. (At least that what the compiler warning said).

self.init(__pickupLocation: pickupLocation,
dropOffLocation: dropOffLocation,
rideOptionName: rideOptionName,
Expand Down