We were failing to replace opaque types with their underlying type
upon encountering an internal type from the current module. This
could happen when the internal type appeared in generic substitutions,
for example when calling a protocol extension method.
Fixes <rdar://problem/60951353>.
Check the availability of decls that declare an opaque return type to ensure they deploy to a
runtime that supports opaque types.
rdar://problem/50731151
Assume we have:
Protocol P
An intenal extension to Optional - conforming to P
Compiling under whole module mode
Use of Optional type T?
Given a dynamic cast from T? to P, that cast might succeed even if T itself does not conform to P
rdar://problem/40500142
If the source and target are the same existential type, but the source is P.Protocol and the dest is P.Type, then we need to consider whether the protocol is self-conforming.
The only cases where a protocol self-conforms are objc protocols, but we're going to expect P.Type to hold a class object. And this case doesn't matter since for a self-conforming protocol type there can't be any type-level methods.
Thus we consider this kind of cast to always fail. The only exception from this rule is when the target is Any.Type, because *.Protocol can always be casted to Any.Type.
Fixes rdar://32682967
If the concrete type is an existential or a generic type, we should not perform the optimization, because we don’t know enough information about it.
Fixes rdar://31372306
The SIL optimizer logic that determined feasability of dynamic casts
completely ignored tuple types, therefore assuming that they would
always fail. Check for structural identity, ignoring adding/removing
labels. Fixes rdar://problem/28121915.