Skip to content

[6.2][stdlib] Allow metatype comparisons to work with outdated compilers #80867

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: release/6.2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ LANGUAGE_FEATURE(RawIdentifiers, 451, "Raw identifiers")
LANGUAGE_FEATURE(SendableCompletionHandlers, 463, "Objective-C completion handler parameters are imported as @Sendable")
LANGUAGE_FEATURE(IsolatedConformances, 470, "Global-actor isolated conformances")
LANGUAGE_FEATURE(AsyncExecutionBehaviorAttributes, 0, "@concurrent and nonisolated(nonsending)")
LANGUAGE_FEATURE(GeneralizedIsSameMetaTypeBuiltin, 465, "Builtin.is_same_metatype with support for noncopyable/nonescapable types")

// Swift 6
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
Expand Down
2 changes: 2 additions & 0 deletions lib/AST/FeatureSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,8 @@ static bool usesFeatureCoroutineAccessors(Decl *decl) {
}
}

UNINTERESTING_FEATURE(GeneralizedIsSameMetaTypeBuiltin)

static bool usesFeatureCustomAvailability(Decl *decl) {
for (auto attr : decl->getSemanticAvailableAttrs()) {
if (attr.getDomain().isCustom())
Expand Down
8 changes: 8 additions & 0 deletions stdlib/public/core/Builtin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,15 @@ public func == (
case (.none, .none):
return true
case let (.some(ty0), .some(ty1)):
#if compiler(>=5.3) && $GeneralizedIsSameMetaTypeBuiltin
return Bool(Builtin.is_same_metatype(ty0, ty1))
#else
// FIXME: Remove this branch once all supported compilers understand the
// generalized is_same_metatype builtin
let p1 = unsafeBitCast(ty0, to: UnsafeRawPointer.self)
let p2 = unsafeBitCast(ty1, to: UnsafeRawPointer.self)
return p1 == p2
#endif
default:
return false
}
Expand Down