Skip to content

Commit 74efc7d

Browse files
authored
Merge pull request #80859 from lorentey/is_same_metatype_condfail
[stdlib] Allow metatype comparisons to work with outdated compilers
2 parents 39cf29b + 0c406b8 commit 74efc7d

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
@@ -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)

lib/AST/FeatureSet.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,8 @@ static bool usesFeatureCoroutineAccessors(Decl *decl) {
560560
}
561561
}
562562

563+
UNINTERESTING_FEATURE(GeneralizedIsSameMetaTypeBuiltin)
564+
563565
static bool usesFeatureCustomAvailability(Decl *decl) {
564566
for (auto attr : decl->getSemanticAvailableAttrs()) {
565567
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)