Skip to content

Commit 2f0a2f9

Browse files
committed
Silence some warnings in 3.1
1 parent 03a0fc9 commit 2f0a2f9

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ matrix:
2121
- set -o pipefail
2222
- xcodebuild test -scheme Concurrent | xcpretty -c
2323
# !!!: Make sure desired device name & OS version are suitable for the Xcode version installed on osx_image
24-
- iOS_DEVICE_NAME="iPad Pro (12.9 inch)"
24+
- iOS_DEVICE_NAME="iPad Pro (12.9-inch)"
2525
- iOS_RUNTIME_VERSION="10.0"
2626
# Get simulator identifier for desired device/runtime pair
2727
- SIMULATOR_ID=$(xcrun instruments -s | grep -o "${iOS_DEVICE_NAME} (${iOS_RUNTIME_VERSION}) \[.*\]" | grep -o "\[.*\]" | sed "s/^\[\(.*\)\]$/\1/")

Sources/Transactions.swift

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
import Darwin
1515
#endif
1616

17+
// Here to silence builtin warnings for using unsafeBitCast with reference
18+
// types. The layout of all types in the STM is fixed (doesn't depend on the
19+
// generic parameter), so bit casts are always legal.
20+
private func transmute<T, U>(_ x: T, to type: U.Type) -> U {
21+
return unsafeBitCast(x, to: type)
22+
}
23+
1724
internal final class Entry {
1825
let ident : ObjectIdentifier
1926
let oldValue : TVarType<Any>
@@ -36,20 +43,20 @@ internal final class Entry {
3643
init<T>(_ location : TVar<T>, _ value : TVarType<T>, _ valid : Bool) {
3744
self.ident = ObjectIdentifier(T.self)
3845
// HACK: bridge-all-the-things-to-Any makes this a legal transformation.
39-
self.location = unsafeBitCast(location, to: TVar<Any>.self)
46+
self.location = transmute(location, to: TVar<Any>.self)
4047
// HACK: TVarType's layout doesn't depend on T.
41-
self.oldValue = unsafeBitCast(location.value, to: TVarType<Any>.self)
42-
self._newValue = unsafeBitCast(value, to: TVarType<Any>.self)
48+
self.oldValue = transmute(location.value, to: TVarType<Any>.self)
49+
self._newValue = transmute(value, to: TVarType<Any>.self)
4350
self.hasOldValue = valid
4451
}
4552

4653
private init<T>(_ ident : ObjectIdentifier, _ oldValue : TVarType<T>, _ location : TVar<T>, _ value : TVarType<T>, _ valid : Bool) {
4754
self.ident = ident
4855
// HACK: bridge-all-the-things-to-Any makes this a legal transformation.
49-
self.location = unsafeBitCast(location, to: TVar<Any>.self)
56+
self.location = transmute(location, to: TVar<Any>.self)
5057
// HACK: TVarType's layout doesn't depend on T.
51-
self.oldValue = unsafeBitCast(oldValue, to: TVarType<Any>.self)
52-
self._newValue = unsafeBitCast(value, to: TVarType<Any>.self)
58+
self.oldValue = transmute(oldValue, to: TVarType<Any>.self)
59+
self._newValue = transmute(value, to: TVarType<Any>.self)
5360
self.hasOldValue = valid
5461
}
5562

@@ -136,7 +143,7 @@ internal final class TLog {
136143
if let entry = self.log[location.hashValue] {
137144
precondition(ObjectIdentifier(T.self) == entry.ident)
138145
// HACK: TVarType's layout doesn't depend on T.
139-
entry._newValue = unsafeBitCast(value, to: TVarType<Any>.self)
146+
entry._newValue = transmute(value, to: TVarType<Any>.self)
140147
} else {
141148
let entry = Entry(location, value)
142149
log[location.hashValue] = entry

0 commit comments

Comments
 (0)