The runtime support for casting optionals introduced in 35cb1afa
resulted in a redundant retain.
Fixes SR-459: Weakened optionals don't zero...
rdar://24057977.
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).
Make the following illegal:
switch thing {
case .A(var x):
modify(x0
}
And provide a replacement 'var' -> 'let' fix-it.
rdar://problem/23172698
Swift SVN r32883
There's still work left to do. In terms of next steps, there's still rdar://problem/22126141, which covers removing the 'workaround' overloads for print (that prevent bogus overload resolution failures), as well as providing a decent diagnostic when users invoke print with 'appendNewline'.
Swift SVN r30976
This decreases total testing time by over a minute on my old Mac Pro.
It probably has much less effect on systems with fewer cores, but shouldn't
be any worse there.
Swift SVN r22745