mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user