Swift objects can implement Equatable without implementing
Hashable. Obj-C NSObject always provides both.
Now that we bridge Swift Equatable to Obj-C `-isEqual:`,
we have to be conservative with how we expose `-hash`
for Swift types that are Equatable but not Hashable.
This looks like "incomplete hashing" of such types.
Rather than attempting Error bridging early when trying to dynamically
cast to NSError or NSObject, treat it as the *last* thing we do when
all else fails. Push most of this code over into Objective-C-specific
handling rather than #ifdef'd into the main casting logic to make that
slightly more clear.
One oddity of Error/NSError bridging is that a class that conforms to
Error can be dynamically cast to NSObject via Error bridging. This has
always been known to the static compiler, but the runtime itself was
not always handling such a cast uniformly. Do so now,
uniformly. However, this forced us to weaken an assertion, because
casting a class type to NSError or NSObject can produce an object with
a different identity.
Fixes rdar://problem/57393991.
* [runtime] Fix some casts of _SwiftValue.
* Allow _SwiftValue to be cast to NSObject by yielding the box object itself.
* Failed casts from NSDictionary containing _SwiftValue should not crash.
SR-4306, rdar://31197066