Skip to content

Commit ad5a81f

Browse files
committed
[stdlib] Reinstate original versions of metatype comparisons
Add a new language feature to avoid the stdlib’s swiftinterface becoming unintelligible to older compilers due to the generalization of Builtin.is_same_metatype. Restore the original version of the `==` operator so that metatypes can continue to be compared even if the generalized version ends up getting omitted. rdar://149396721
1 parent 2f133b3 commit ad5a81f

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ LANGUAGE_FEATURE(SendableCompletionHandlers, 463, "Objective-C completion handle
257257
LANGUAGE_FEATURE(AsyncExecutionBehaviorAttributes, 0, "@concurrent and nonisolated(nonsending)")
258258
LANGUAGE_FEATURE(IsolatedConformances, 407, "Global-actor isolated conformances")
259259
LANGUAGE_FEATURE(ValueGenericsNameLookup, 452, "Value generics appearing as static members for namelookup")
260+
LANGUAGE_FEATURE(GeneralizedIsSameMetaTypeBuiltin, 465, "Builtin.is_same_metatype with support for noncopyable/nonescapable types")
260261

261262
// Swift 6
262263
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)

stdlib/public/core/Builtin.swift

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

161+
#if compiler(>=5.3) && $GeneralizedIsSameMetaTypeBuiltin
161162
/// Returns a Boolean value indicating whether two types are identical.
162163
///
163164
/// - Parameters:
@@ -196,13 +197,24 @@ public func != (
196197
) -> Bool {
197198
!(t0 == t1)
198199
}
200+
#endif
199201

200202
#if !$Embedded
201203
// Embedded Swift is unhappy about conversions from `Any.Type` to
202204
// `any (~Copyable & ~Escapable).Type` (rdar://145706221)
203-
@usableFromInline
204-
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
205-
internal func == (t0: Any.Type?, t1: Any.Type?) -> Bool {
205+
206+
/// Returns a Boolean value indicating whether two types are identical.
207+
///
208+
/// - Parameters:
209+
/// - t0: A type to compare.
210+
/// - t1: Another type to compare.
211+
/// - Returns: `true` if both `t0` and `t1` are `nil` or if they represent the
212+
/// same type; otherwise, `false`.
213+
public func == (t0: Any.Type?, t1: Any.Type?) -> Bool {
214+
// FIXME: This is a legacy ABI entry point that has been obsoleted by the
215+
// generalized definition above. We need to mark it as SwiftStdlibLegacyABI
216+
// once all supported compilers have the $GeneralizedIsSameMetaTypeBuiltin
217+
// feature. (rdar://149396721)
206218
switch (t0, t1) {
207219
case (.none, .none): return true
208220
case let (.some(ty0), .some(ty1)):
@@ -211,9 +223,18 @@ internal func == (t0: Any.Type?, t1: Any.Type?) -> Bool {
211223
}
212224
}
213225

214-
@usableFromInline
215-
@_spi(SwiftStdlibLegacyABI) @available(swift, obsoleted: 1)
216-
internal func != (t0: Any.Type?, t1: Any.Type?) -> Bool {
226+
/// Returns a Boolean value indicating whether two types are not identical.
227+
///
228+
/// - Parameters:
229+
/// - t0: A type to compare.
230+
/// - t1: Another type to compare.
231+
/// - Returns: `true` if one, but not both, of `t0` and `t1` are `nil`, or if
232+
/// they represent different types; otherwise, `false`.
233+
public func != (t0: Any.Type?, t1: Any.Type?) -> Bool {
234+
// FIXME: This is a legacy ABI entry point that has been obsoleted by the
235+
// generalized definition above. We need to mark it as SwiftStdlibLegacyABI
236+
// once all supported compilers have the $GeneralizedIsSameMetaTypeBuiltin
237+
// feature. (rdar://149396721)
217238
!(t0 == t1)
218239
}
219240
#endif

0 commit comments

Comments
 (0)