IRGen: Make type(of:) behavior consistent in ObjC bridged contexts.

When we use type(of: x) on a class in an ObjC bridged context, the optimizer turns this into a SIL `value_metatype @objc` operation, which is supposed to get the dynamic type of the object as an ObjC class. This was previously lowered by IRGen into a `object_getClass` call, which extracts the isa pointer from the object, but is inconsistent with the `-class` method in ObjC or with the Swift-native behavior, which both look through artificial subclasses, proxies, and so on. This inconsistency led to observably different behavior between debug and release builds and between ObjC-bridged and native entry points, so provide an alternative runtime entry point that replicates the behavior of getting a native Swift class. Fixes SR-7258.
This commit is contained in:
Joe Groff
2018-04-06 13:24:31 -07:00
parent 88b785cadd
commit a4aa054838
10 changed files with 84 additions and 45 deletions

View File

@@ -869,6 +869,12 @@ FUNCTION(GetObjCClassFromMetadata, swift_getObjCClassFromMetadata, C_CC,
ARGS(TypeMetadataPtrTy),
ATTRS(NoUnwind, ReadNone))
// Metadata *swift_getObjCClassFromObject(id object);
FUNCTION(GetObjCClassFromObject, swift_getObjCClassFromObject, C_CC,
RETURNS(ObjCClassPtrTy),
ARGS(ObjCPtrTy),
ATTRS(NoUnwind, ReadNone))
// MetadataResponse swift_getTupleTypeMetadata(MetadataRequest request,
// TupleTypeFlags flags,
// Metadata * const *elts,