forked from swiftlang/swift
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix dynamic runtime casts of Optionals.
Fixes <rdar://23122310> Runtime dynamic casts... This makes runtime dynamic casts consistent with language rules, and consequently makes specialization of generic code consistent with an equivalent nongeneric implementation. The runtime now supports casts from Optional<T> to U. Naturally the cast fails on nil source, but otherwise succeeds if T is convertible to U. When casting T to Optional<U> the runtime succeeds whenever T is convertible to U and simply wraps the result in an Optional. To greatly simplify the runtime, I am assuming that target-type-specific runtime cast entry points (e.g. swift_dynamicCastClass) are never invoked with an optional source. This assumption is valid for the following reasons. At the language level optionals must be unwrapped before downcasting (via as[?!]), so we only need to worry about SIL and IR lowering. This implementation assumes (with asserts) that: - SIL promotion from an address cast to a value casts should only happen when the source is nonoptional. Handling optional unwrapping in SIL would be too complicated because we need to check for Optional's own conformances. (I added a test case to ensure this promotion does not happen). This is not an issue for unchecked_ref_cast, which implicitly unwraps optionals, so we can promote those! - IRGen lowers unchecked_ref_cast (Builtin.castReference) directly to a bitcast (will be caught by asserts). - IRGen continues to emit the generic dynamicCast entry point for address-casts (will be caught by asserts).
- Loading branch information
Showing
5 changed files
with
208 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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