25
25
#include " MetadataCache.h"
26
26
#include " BytecodeLayouts.h"
27
27
#include " swift/ABI/TypeIdentity.h"
28
+ #include " swift/Basic/Defer.h"
28
29
#include " swift/Basic/MathUtils.h"
29
30
#include " swift/Basic/Lazy.h"
30
31
#include " swift/Basic/Range.h"
@@ -3980,7 +3981,6 @@ swift::swift_updatePureObjCClassMetadata(Class cls,
3980
3981
size_t numFields,
3981
3982
const TypeLayout * const *fieldTypes) {
3982
3983
auto self = (ObjCClass *)cls;
3983
- bool requiresUpdate = SWIFT_RUNTIME_WEAK_CHECK (_objc_realizeClassFromSwift);
3984
3984
3985
3985
// Realize the superclass first.
3986
3986
(void )swift_getInitializedObjCClass ((Class)self->Isa );
@@ -3990,38 +3990,21 @@ swift::swift_updatePureObjCClassMetadata(Class cls,
3990
3990
auto rodata = getROData (self);
3991
3991
self->RODataAndFlags = (uintptr_t )rodata;
3992
3992
3993
- // If we're running on a older Objective-C runtime, just realize
3994
- // the class.
3995
- if (!requiresUpdate) {
3996
- // If we don't have a backward deployment layout, we cannot proceed here.
3997
- if (rodata->InstanceSize == 0 ) {
3998
- fatalError (0 , " class %s does not have a fragile layout; "
3999
- " the deployment target was newer than this OS\n " ,
4000
- rodata->Name );
4001
- }
3993
+ bool requiresRealizeClassFromSwift =
3994
+ SWIFT_RUNTIME_WEAK_CHECK (_objc_realizeClassFromSwift);
3995
+ assert (requiresRealizeClassFromSwift);
4002
3996
3997
+ SWIFT_DEFER {
4003
3998
// Realize the class. This causes the runtime to slide the field offsets
4004
3999
// stored in the field offset globals.
4005
- //
4006
- // Note that the field offset vector is *not* updated; however in
4007
- // Objective-C interop mode, we don't actually use the field offset vector
4008
- // of non-generic classes.
4009
- //
4010
- // In particular, class mirrors always use the Objective-C ivar descriptors,
4011
- // which point at field offset globals and not the field offset vector.
4012
- swift_getInitializedObjCClass ((Class)self);
4013
- return cls;
4014
- }
4000
+ SWIFT_RUNTIME_WEAK_USE (_objc_realizeClassFromSwift (cls, cls));
4001
+ };
4015
4002
4016
4003
// Update the field offset globals using runtime type information; the layout
4017
4004
// of resilient types might be different than the statically-emitted layout.
4018
4005
ClassIvarList *ivars = rodata->IvarList ;
4019
4006
if (!ivars) {
4020
4007
assert (numFields == 0 );
4021
-
4022
- // See remark above about how this slides field offset globals.
4023
- SWIFT_RUNTIME_WEAK_USE (_objc_realizeClassFromSwift (cls, cls));
4024
-
4025
4008
return cls;
4026
4009
}
4027
4010
@@ -4030,16 +4013,12 @@ swift::swift_updatePureObjCClassMetadata(Class cls,
4030
4013
4031
4014
bool copiedIvarList = false ;
4032
4015
4033
- // Update the field offset globals using runtime type information; the layout
4034
- // of resilient types might be different than the statically-emitted layout.
4035
- size_t size, alignMask;
4036
-
4037
4016
// Start layout from our static notion of where the superclass starts.
4038
4017
// Objective-C expects us to have generated a correct ivar layout, which it
4039
4018
// will simply slide if it needs to.
4040
4019
assert (self->Superclass && " Swift cannot implement a root class" );
4041
- size = rodata->InstanceStart ;
4042
- alignMask = 0xF ; // malloc alignment guarantee
4020
+ size_t size = rodata->InstanceStart ;
4021
+ size_t alignMask = 0xF ; // malloc alignment guarantee
4043
4022
4044
4023
// Okay, now do layout.
4045
4024
for (unsigned i = 0 ; i != numFields; ++i) {
@@ -4092,9 +4071,6 @@ swift::swift_updatePureObjCClassMetadata(Class cls,
4092
4071
if (rodata->InstanceSize != size)
4093
4072
rodata->InstanceSize = size;
4094
4073
4095
- // See remark above about how this slides field offset globals.
4096
- SWIFT_RUNTIME_WEAK_USE (_objc_realizeClassFromSwift (cls, cls));
4097
-
4098
4074
return cls;
4099
4075
}
4100
4076
#endif
0 commit comments