Skip to content

Commit 40d2cda

Browse files
committed
[stdlib] Properly generalize metatype comparisons
1 parent 0cb4b14 commit 40d2cda

File tree

1 file changed

+4
-37
lines changed

1 file changed

+4
-37
lines changed

stdlib/public/core/Builtin.swift

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ internal func != (lhs: Builtin.RawPointer, rhs: Builtin.RawPointer) -> Bool {
158158
return !(lhs == rhs)
159159
}
160160

161-
#if !$Embedded
162161
/// Returns a Boolean value indicating whether two types are identical.
163162
///
164163
/// - Parameters:
@@ -176,11 +175,7 @@ public func == (
176175
case (.none, .none):
177176
return true
178177
case let (.some(ty0), .some(ty1)):
179-
// FIXME: this should read `Bool(Builtin.is_same_metatype(ty0, ty1))`,
180-
// but that currently requires copyability/escapability (rdar://145707064)
181-
let p1 = unsafeBitCast(ty0, to: UnsafeRawPointer.self)
182-
let p2 = unsafeBitCast(ty1, to: UnsafeRawPointer.self)
183-
return p1 == p2
178+
return Bool(Builtin.is_same_metatype(ty0, ty1))
184179
default:
185180
return false
186181
}
@@ -202,6 +197,9 @@ public func != (
202197
!(t0 == t1)
203198
}
204199

200+
#if !$Embedded
201+
// Embedded Swift is unhappy about conversions from `Any.Type` to
202+
// `any (~Copyable & ~Escapable).Type` (rdar://145706221)
205203
@usableFromInline
206204
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
207205
internal func == (t0: Any.Type?, t1: Any.Type?) -> Bool {
@@ -218,37 +216,6 @@ internal func == (t0: Any.Type?, t1: Any.Type?) -> Bool {
218216
internal func != (t0: Any.Type?, t1: Any.Type?) -> Bool {
219217
!(t0 == t1)
220218
}
221-
#else
222-
// FIXME: $Embedded doesn't grok `any (~Copyable & Escapable).Type` yet (rdar://145706221)
223-
224-
/// Returns a Boolean value indicating whether two types are identical.
225-
///
226-
/// - Parameters:
227-
/// - t0: A type to compare.
228-
/// - t1: Another type to compare.
229-
/// - Returns: `true` if both `t0` and `t1` are `nil` or if they represent the
230-
/// same type; otherwise, `false`.
231-
@inlinable @_transparent
232-
public func == (t0: Any.Type?, t1: Any.Type?) -> Bool {
233-
switch (t0, t1) {
234-
case (.none, .none): return true
235-
case let (.some(ty0), .some(ty1)):
236-
return Bool(Builtin.is_same_metatype(ty0, ty1))
237-
default: return false
238-
}
239-
}
240-
241-
/// Returns a Boolean value indicating whether two types are not identical.
242-
///
243-
/// - Parameters:
244-
/// - t0: A type to compare.
245-
/// - t1: Another type to compare.
246-
/// - Returns: `true` if one, but not both, of `t0` and `t1` are `nil`, or if
247-
/// they represent different types; otherwise, `false`.
248-
@inlinable @_transparent
249-
public func != (t0: Any.Type?, t1: Any.Type?) -> Bool {
250-
return !(t0 == t1)
251-
}
252219
#endif
253220

254221
/// Tell the optimizer that this code is unreachable if condition is

0 commit comments

Comments
 (0)