Skip to content

Commit

Permalink
Merge pull request swiftlang#3634 from aschwaighofer/int_init_objecti…
Browse files Browse the repository at this point in the history
…dentifier_label

Add 'bitPattern:' label to '(U)Int.init(ObjectIdentifier)'
  • Loading branch information
lattner authored Jul 21, 2016
2 parents 97c325f + b6da135 commit f207607
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
22 changes: 18 additions & 4 deletions stdlib/public/core/Reflection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ extension ObjectIdentifier : CustomDebugStringConvertible {
}

public func <(lhs: ObjectIdentifier, rhs: ObjectIdentifier) -> Bool {
return UInt(lhs) < UInt(rhs)
return UInt(bitPattern: lhs) < UInt(bitPattern: rhs)
}

public func ==(x: ObjectIdentifier, y: ObjectIdentifier) -> Bool {
Expand All @@ -57,15 +57,15 @@ public func ==(x: ObjectIdentifier, y: ObjectIdentifier) -> Bool {

extension UInt {
/// Create a `UInt` that captures the full value of `objectID`.
public init(_ objectID: ObjectIdentifier) {
public init(bitPattern objectID: ObjectIdentifier) {
self.init(Builtin.ptrtoint_Word(objectID._value))
}
}

extension Int {
/// Create an `Int` that captures the full value of `objectID`.
public init(_ objectID: ObjectIdentifier) {
self.init(bitPattern: UInt(objectID))
public init(bitPattern objectID: ObjectIdentifier) {
self.init(bitPattern: UInt(bitPattern: objectID))
}
}

Expand Down Expand Up @@ -631,3 +631,17 @@ extension ObjectIdentifier {
Builtin.unreachable()
}
}

extension UInt {
@available(*, unavailable, renamed: "init(bitPattern:)")
public init(_ objectID: ObjectIdentifier) {
Builtin.unreachable()
}
}

extension Int {
@available(*, unavailable, renamed: "init(bitPattern:)")
public init(_ objectID: ObjectIdentifier) {
Builtin.unreachable()
}
}
5 changes: 4 additions & 1 deletion test/1_stdlib/Runtime.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -995,8 +995,11 @@ Reflection.test("ObjectIdentifier/CustomDebugStringConvertible") {
expectEqual(String(reflecting: oi1), String(reflecting: oi1))
expectNotEqual(String(reflecting: oi1), String(reflecting: oi2))

let p1 = UnsafePointer<Void>(bitPattern: UInt(oi1))!
let p1 = UnsafePointer<Void>(bitPattern: UInt(bitPattern: oi1))!
expectPrinted("ObjectIdentifier(\(p1))", oi1)
let p2 = UnsafePointer<Void>(bitPattern: Int(bitPattern: oi1))!
expectPrinted("ObjectIdentifier(\(p2))", oi1)

}

Reflection.test("CustomMirrorIsInherited") {
Expand Down

0 comments on commit f207607

Please sign in to comment.