Skip to content

Add 'bitPattern:' label to '(U)Int.init(ObjectIdentifier)' #3634

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
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
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)
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add a test for Int(bitPattern:) as well? Seems like that API is not covered by any other tests.

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

}

Reflection.test("CustomMirrorIsInherited") {
Expand Down