Skip to content

Commit 8b95cc4

Browse files
authored
[stdlib] Fixing compilation warnings (#7314)
<rdar://problem/30320630>
1 parent d5e57ee commit 8b95cc4

File tree

6 files changed

+31
-15
lines changed

6 files changed

+31
-15
lines changed

stdlib/public/SDK/Dispatch/Data.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public struct DispatchDataIterator : IteratorProtocol, Sequence {
272272
extension DispatchData {
273273
@_semantics("convertToObjectiveC")
274274
public func _bridgeToObjectiveC() -> __DispatchData {
275-
return unsafeBitCast(__wrapped, to: __DispatchData.self)
275+
return __wrapped
276276
}
277277

278278
public static func _forceBridgeFromObjectiveC(_ input: __DispatchData, result: inout DispatchData?) {

stdlib/public/SDK/Foundation/Data.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public final class _DataStorage {
8383
var dest = dest_
8484
var source = source_
8585
var num = num_
86-
if _DataStorage.vmOpsThreshold <= num && ((unsafeBitCast(source, to: Int.self) | unsafeBitCast(dest, to: Int.self)) & (NSPageSize() - 1)) == 0 {
86+
if _DataStorage.vmOpsThreshold <= num && ((unsafeBitCast(source, to: Int.self) | Int(bitPattern: dest)) & (NSPageSize() - 1)) == 0 {
8787
let pages = NSRoundDownToMultipleOfPageSize(num)
8888
NSCopyMemoryPages(source!, dest, pages)
8989
source = source!.advanced(by: pages)

stdlib/public/SDK/Foundation/DateInterval.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ public struct DateInterval : ReferenceConvertible, Comparable, Hashable {
157157
public var hashValue: Int {
158158
var buf: (UInt, UInt) = (UInt(start.timeIntervalSinceReferenceDate), UInt(end.timeIntervalSinceReferenceDate))
159159
return withUnsafeMutablePointer(to: &buf) {
160-
return Int(bitPattern: CFHashBytes(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self), CFIndex(MemoryLayout<UInt>.size * 2)))
160+
$0.withMemoryRebound(to: UInt8.self, capacity: 2 * MemoryLayout<UInt>.size / MemoryLayout<UInt8>.size) {
161+
return Int(bitPattern: CFHashBytes($0, CFIndex(MemoryLayout<UInt>.size * 2)))
162+
}
161163
}
162164
}
163165

stdlib/public/SDK/Foundation/IndexSet.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ private final class _MutablePairHandle<ImmutableType : NSObject, MutableType : N
956956
return try whatToDo(i)
957957
case .Mutable(let m):
958958
// 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.
959-
return try whatToDo(unsafeBitCast(m, to: ImmutableType.self))
959+
return try whatToDo(unsafeDowncast(m, to: ImmutableType.self))
960960
}
961961
}
962962

@@ -966,7 +966,7 @@ private final class _MutablePairHandle<ImmutableType : NSObject, MutableType : N
966966
return i
967967
case .Mutable(let m):
968968
// 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.
969-
return unsafeBitCast(m, to: ImmutableType.self)
969+
return unsafeDowncast(m, to: ImmutableType.self)
970970
}
971971
}
972972
}

stdlib/public/SDK/Foundation/UUID.swift

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,18 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
2323
/* Create a new UUID with RFC 4122 version 4 random bytes */
2424
public init() {
2525
withUnsafeMutablePointer(to: &uuid) {
26-
uuid_generate_random(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self))
26+
$0.withMemoryRebound(to: UInt8.self, capacity: 16) {
27+
uuid_generate_random($0)
28+
}
2729
}
2830
}
2931

3032
fileprivate init(reference: NSUUID) {
3133
var bytes: uuid_t = (0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
3234
withUnsafeMutablePointer(to: &bytes) {
33-
reference.getBytes(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self))
35+
$0.withMemoryRebound(to: UInt8.self, capacity: 16) {
36+
reference.getBytes($0)
37+
}
3438
}
3539
uuid = bytes
3640
}
@@ -40,7 +44,9 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
4044
/// Returns nil for invalid strings.
4145
public init?(uuidString string: String) {
4246
let res = withUnsafeMutablePointer(to: &uuid) {
43-
return uuid_parse(string, unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self))
47+
$0.withMemoryRebound(to: UInt8.self, capacity: 16) {
48+
return uuid_parse(string, $0)
49+
}
4450
}
4551
if res != 0 {
4652
return nil
@@ -56,18 +62,24 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
5662
public var uuidString: String {
5763
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)
5864
var localValue = uuid
59-
return withUnsafeMutablePointer(to: &localValue) { val in
60-
withUnsafeMutablePointer(to: &bytes) { str in
61-
uuid_unparse(unsafeBitCast(val, to: UnsafePointer<UInt8>.self), unsafeBitCast(str, to: UnsafeMutablePointer<Int8>.self))
62-
return String(cString: unsafeBitCast(str, to: UnsafePointer<CChar>.self), encoding: .utf8)!
65+
return withUnsafeMutablePointer(to: &localValue) {
66+
$0.withMemoryRebound(to: UInt8.self, capacity: 16) { val in
67+
withUnsafeMutablePointer(to: &bytes) {
68+
$0.withMemoryRebound(to: Int8.self, capacity: 37) { str in
69+
uuid_unparse(val, str)
70+
return String(cString: UnsafePointer(str), encoding: .utf8)!
71+
}
72+
}
6373
}
6474
}
6575
}
6676

6777
public var hashValue: Int {
6878
var localValue = uuid
6979
return withUnsafeMutablePointer(to: &localValue) {
70-
return Int(bitPattern: CFHashBytes(unsafeBitCast($0, to: UnsafeMutablePointer<UInt8>.self), CFIndex(MemoryLayout<uuid_t>.size)))
80+
$0.withMemoryRebound(to: UInt8.self, capacity: 16) {
81+
return Int(bitPattern: CFHashBytes($0, CFIndex(MemoryLayout<uuid_t>.size)))
82+
}
7183
}
7284
}
7385

@@ -84,7 +96,9 @@ public struct UUID : ReferenceConvertible, Hashable, Equatable, CustomStringConv
8496
fileprivate var reference: NSUUID {
8597
var bytes = uuid
8698
return withUnsafePointer(to: &bytes) {
87-
return NSUUID(uuidBytes: unsafeBitCast($0, to: UnsafePointer<UInt8>.self))
99+
$0.withMemoryRebound(to: UInt8.self, capacity: 16) {
100+
return NSUUID(uuidBytes: $0)
101+
}
88102
}
89103
}
90104

stdlib/public/SDK/Intents/INRequestRideIntent.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ extension INRequestRideIntent {
2525
paymentMethod: INPaymentMethod? = nil,
2626
scheduledPickupTime: INDateComponentsRange? = nil
2727
) {
28-
if #available(iOS 10.3, watchOS 3.2, *) {
28+
if #available(iOS 10.3, *) {
2929
self.init(__pickupLocation: pickupLocation,
3030
dropOffLocation: dropOffLocation,
3131
rideOptionName: rideOptionName,

0 commit comments

Comments
 (0)