Support resilient stored properties in objcImpl

When an @objc @implementation class requires the use of `ClassMetadataStrategy::Update` because some of its stored properties do not have fixed sizes, we adjust the direct field offsets during class realization by emitting a custom metadata update function which calls a new entry point in the Swift runtime. That entry point adjusts field offsets like `swift_updateClassMetadata2()`, but it only assumes that the class has Objective-C metadata, not Swift metadata.

This commit introduces an alternative mechanism which does the same thing without using any Swift-only metadata. It’s a rough implementation with important limitations:

• We’re currently using the field offset vector, which means that field offsets are being emitted into @objc @implementation classes; these will be removed.
• The new Swift runtime entry point duplicates a lot of `swift_updateClassMetadata2()`’s implementation; it will be refactored into something much smaller and more compact.
• Availability bounds for this feature have not yet been implemented.

Future commits in this PR will correct these issues.
This commit is contained in:
Becca Royal-Gordon
2024-04-30 12:03:44 -07:00
parent 9e83099279
commit 427386feea
14 changed files with 830 additions and 167 deletions

View File

@@ -1437,6 +1437,21 @@ FUNCTION(UpdateClassMetadata2,
EFFECT(MetaData),
UNKNOWN_MEMEFFECTS)
// objc_class *swift_updatePureObjCClassMetadata(objc_class *self,
// ClassLayoutFlags flags,
// size_t numFields,
// TypeLayout * const *fieldTypes,
// size_t *fieldOffsets);
FUNCTION(UpdatePureObjCClassMetadata,
swift_updatePureObjCClassMetadata, SwiftCC, AlwaysAvailable,
RETURNS(ObjCClassPtrTy),
ARGS(ObjCClassPtrTy, SizeTy, SizeTy,
Int8PtrPtrTy->getPointerTo(),
SizeTy->getPointerTo()),
ATTRS(NoUnwind),
EFFECT(MetaData),
UNKNOWN_MEMEFFECTS)
// void *swift_lookUpClassMethod(Metadata *metadata,
// ClassDescriptor *description,
// MethodDescriptor *method);