Skip to content

Commit 4cde33c

Browse files
authored
Merge pull request #80867 from lorentey/is_same_metatype_condfail_6.2
[6.2][stdlib] Allow metatype comparisons to work with outdated compilers
2 parents e6f5966 + 3fce89c commit 4cde33c

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ LANGUAGE_FEATURE(RawIdentifiers, 451, "Raw identifiers")
256256
LANGUAGE_FEATURE(SendableCompletionHandlers, 463, "Objective-C completion handler parameters are imported as @Sendable")
257257
LANGUAGE_FEATURE(IsolatedConformances, 470, "Global-actor isolated conformances")
258258
LANGUAGE_FEATURE(AsyncExecutionBehaviorAttributes, 0, "@concurrent and nonisolated(nonsending)")
259+
LANGUAGE_FEATURE(GeneralizedIsSameMetaTypeBuiltin, 465, "Builtin.is_same_metatype with support for noncopyable/nonescapable types")
259260

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

lib/AST/FeatureSet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,8 @@ static bool usesFeatureCoroutineAccessors(Decl *decl) {
508508
}
509509
}
510510

511+
UNINTERESTING_FEATURE(GeneralizedIsSameMetaTypeBuiltin)
512+
511513
static bool usesFeatureCustomAvailability(Decl *decl) {
512514
for (auto attr : decl->getSemanticAvailableAttrs()) {
513515
if (attr.getDomain().isCustom())

stdlib/public/core/Builtin.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,15 @@ public func == (
175175
case (.none, .none):
176176
return true
177177
case let (.some(ty0), .some(ty1)):
178+
#if compiler(>=5.3) && $GeneralizedIsSameMetaTypeBuiltin
178179
return Bool(Builtin.is_same_metatype(ty0, ty1))
180+
#else
181+
// FIXME: Remove this branch once all supported compilers understand the
182+
// generalized is_same_metatype builtin
183+
let p1 = unsafeBitCast(ty0, to: UnsafeRawPointer.self)
184+
let p2 = unsafeBitCast(ty1, to: UnsafeRawPointer.self)
185+
return p1 == p2
186+
#endif
179187
default:
180188
return false
181189
}

0 commit comments

Comments
 (0)