@@ -724,15 +724,33 @@ tryCastToAnyHashable(
724724 assert (cast<StructMetadata>(destType)->Description
725725 == &STRUCT_TYPE_DESCR_SYM (s11AnyHashable));
726726
727- auto hashableConformance = reinterpret_cast <const HashableWitnessTable *>(
727+ switch (srcType->getKind ()) {
728+ case MetadataKind::ForeignClass: // CF -> String
729+ case MetadataKind::ObjCClassWrapper: { // Obj-C -> String
730+ #if SWIFT_OBJC_INTEROP
731+ // TODO: Implement a fast path for NSString->AnyHashable casts.
732+ // These are incredibly common because an NSDictionary with
733+ // NSString keys is bridged by default to [AnyHashable:Any].
734+ // Until this is implemented, fall through to the default case
735+ SWIFT_FALLTHROUGH;
736+ #else
737+ // If no Obj-C interop, just fall through to the default case.
738+ SWIFT_FALLTHROUGH;
739+ #endif
740+ }
741+ default : {
742+ auto hashableConformance = reinterpret_cast <const HashableWitnessTable *>(
728743 swift_conformsToProtocol (srcType, &HashableProtocolDescriptor));
729- if (hashableConformance) {
730- _swift_convertToAnyHashableIndirect (srcValue, destLocation,
731- srcType, hashableConformance);
732- return DynamicCastResult::SuccessViaCopy;
733- } else {
734- return DynamicCastResult::Failure;
744+ if (hashableConformance) {
745+ _swift_convertToAnyHashableIndirect (srcValue, destLocation,
746+ srcType, hashableConformance);
747+ return DynamicCastResult::SuccessViaCopy;
748+ } else {
749+ return DynamicCastResult::Failure;
750+ }
735751 }
752+ }
753+ return DynamicCastResult::Failure;
736754}
737755
738756static DynamicCastResult
0 commit comments