-
Couldn't load subscription status.
- Fork 10.6k
Runtime optional casts. #204
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
Conversation
test/1_stdlib/Runtime.swift
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
print? Shouldn't it use expectEqual?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. I decided to move these all to an Interpreter test case, rewrote them all as prints, then changed my mind.
Reuses the enum metadata layout and builder because most of the logic is also required for Optional (generic arg and payload). We may want to optimize this at some point (Optional doesn't have a Parent), but I don't see much opportunity. Note that with this approach there will be no change in metadata layout. Changing the kind still breaks the ABI of course. Also leaves the MirrorData summary string as "(Enum Value)". We should consider changing it.
There was previously no way to detect a type that is nominally Optional at runtime. The standard library, namely OutputStream, needs to handle Optionals specially in order to cirumvent conversion to the Optional's wrapped type. This should be done with conditional conformance, but until that feature is available, Builtin.isOptional will serve as a useful crutch.
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).
…-data-copy Fixes incorrect behavior of DispatchData.copyBytes() when the start …
…-data-copy Fixes incorrect behavior of DispatchData.copyBytes() when the start … Signed-off-by: Daniel A. Steffen <dsteffen@apple.com>
Add composition types
[Gardening] Update all Python scripting to conform to the style guidelines enforced by the black code-formatting tool.
For JSQCoreDataKit drop building Swift 3, and update to tip for Swift 4
@jckarter Let me know if you foresee any problem with this change in cast behavior.