-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Dynamic Casting: Properly unwrap existential metatype sources #34469
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Existential metatypes are really just existentials that hold metatypes. As such, they should be handled in the general casting logic in much the same way as regular existentials: They should generally be ignored by most casting logic, and unwrapped as necessary at the top level. In particular, the previous code would fail to correctly handle the following cast from an existential metatype (`AnyObject.Type`) to an existential (`AnyObject`): ``` class C {} let a = C.self as AnyObject.Type let b = a as! AnyObject ``` With the old code, `b` above would hold a reference to a `__SwiftValue` box containing the type reference. The correct result would simply store the type reference directly in `b`. These two are only really distinguishable in that the correct form permits `a === b` to return `true`. Fixes rdar://70582753
@swift-ci Please test |
Build failed |
mikeash
approved these changes
Oct 28, 2020
@swift-ci Please test |
Build failed |
While I'm here, include some comments indicating the missing pieces still needed for Linux support to work. Basically, metatypes on Linux are not currently fully compatible with reference-counted class pointers, which prevents us from fully supporting metatype operations on Linux that we support on macOS.
Whitespace cleanup
@swift-ci Please test |
ainu-bot
added a commit
to google/swift
that referenced
this pull request
Oct 29, 2020
* 'main' of github.com:apple/swift: (22 commits) Dynamic Casting: Properly unwrap existential metatype sources (swiftlang#34469) Add -allow-critical-edges=false to copyforward_ossa.sil Add -allow-critical-edges flag. Sema: Check result builder availability Sema: Pass ExportContext by const reference where possible Sema: Put the AvailabilityContext inside the ExportContext Change interfaces to accept a FileCollectorBase [Parse] Remove unused declaration and diagnostic message [cxx-interop] Use regex instead of operand name to fix C++ constructor tests. [CodeCompletion] Fix a crash in collectPossibleReturnTypesFromContext [test] Update cross_langauge index test for mangling change Temporarily disable this test [Concurrency] SIL: add hop_to_executor instruction sil-opt: add an -enable-experimental-concurrency option. Sema: Don't visit elements of a BraceStmt twice when checking availability Sema: Rename AvailabilityWalker to ExprAvailabilityWalker Sema: Pull diagnoseDeclAvailability() out of AvailabilityWalker Sema: Rename some availability checking entry points SILGen: Stub out support for invoking foreign async methods. Add a mangling for completion block implementation functions. ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Existential metatypes are really just existentials that hold metatypes. As
such, they should be handled in the general casting logic in much the same way
as regular existentials: They should generally be ignored by most casting logic,
and unwrapped as necessary at the top level.
In particular, the previous code would fail to correctly handle the following
cast from an existential metatype (
AnyObject.Type
) to an existential(
AnyObject
):With the old code,
b
above would hold a reference to a__SwiftValue
boxcontaining the type reference. The correct result would simply store the type
reference directly in
b
. These two are only really distinguishable in thatthe correct form permits
a === b
to returntrue
.Fixes rdar://70582753