Skip to content

Commit 029e296

Browse files
authored
Allow Identifiable and correct ObjectIdentifier for embedded variants (#68597)
1 parent d66cfa9 commit 029e296

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

stdlib/public/core/Identifiable.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
/// lifetime of an object. If an object has a stronger notion of identity, it
4040
/// may be appropriate to provide a custom implementation.
4141
@available(SwiftStdlib 5.1, *)
42-
@_unavailableInEmbedded
4342
public protocol Identifiable<ID> {
4443

4544
/// A type representing the stable identity of the entity associated with
@@ -51,7 +50,6 @@ public protocol Identifiable<ID> {
5150
}
5251

5352
@available(SwiftStdlib 5.1, *)
54-
@_unavailableInEmbedded
5553
extension Identifiable where Self: AnyObject {
5654
public var id: ObjectIdentifier {
5755
return ObjectIdentifier(self)

stdlib/public/core/ObjectIdentifier.swift

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,31 @@ public struct ObjectIdentifier: Sendable {
5050
/// // Prints "false"
5151
///
5252
/// - Parameter x: An instance of a class.
53+
#if $Embedded
54+
@inlinable // trivial-implementation
55+
public init<Object: AnyObject>(_ x: Object) {
56+
self._value = Builtin.bridgeToRawPointer(x)
57+
}
58+
#else
5359
@inlinable // trivial-implementation
5460
public init(_ x: AnyObject) {
5561
self._value = Builtin.bridgeToRawPointer(x)
5662
}
57-
63+
#endif
5864
/// Creates an instance that uniquely identifies the given metatype.
5965
///
6066
/// - Parameter: A metatype.
67+
#if $Embedded
68+
@inlinable // trivial-implementation
69+
public init<Object>(_ x: Object.Type) {
70+
self._value = unsafeBitCast(x, to: Builtin.RawPointer.self)
71+
}
72+
#else
6173
@inlinable // trivial-implementation
6274
public init(_ x: Any.Type) {
6375
self._value = unsafeBitCast(x, to: Builtin.RawPointer.self)
6476
}
77+
#endif
6578
}
6679

6780
@_unavailableInEmbedded

0 commit comments

Comments
 (0)