-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Use a true-const pattern to initialize non-generic resilient class metadata #18893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
4a23d3c
d562344
120be25
03cb6d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3085,7 +3085,7 @@ class TargetGenericMetadataPatternTrailingObjects : | |
} | ||
}; | ||
|
||
/// An instantiation pattern for class metadata. | ||
/// An instantiation pattern for generic class metadata. | ||
template <typename Runtime> | ||
struct TargetGenericClassMetadataPattern final : | ||
TargetGenericMetadataPattern<Runtime>, | ||
|
@@ -3138,7 +3138,7 @@ struct TargetGenericClassMetadataPattern final : | |
using GenericClassMetadataPattern = | ||
TargetGenericClassMetadataPattern<InProcess>; | ||
|
||
/// An instantiation pattern for value metadata. | ||
/// An instantiation pattern for generic value metadata. | ||
template <typename Runtime> | ||
struct TargetGenericValueMetadataPattern final : | ||
TargetGenericMetadataPattern<Runtime>, | ||
|
@@ -3316,10 +3316,43 @@ struct TargetInPlaceValueMetadataCache { | |
using InPlaceValueMetadataCache = | ||
TargetInPlaceValueMetadataCache<InProcess>; | ||
|
||
template <typename Runtime> | ||
struct TargetResilientClassMetadataPattern; | ||
|
||
/// An instantiation pattern for non-generic resilient class metadata. | ||
/// Used in conjunction with InPlaceValueMetadataInitialization. | ||
using MetadataRelocator = | ||
Metadata *(const TargetTypeContextDescriptor<InProcess> *description); | ||
Metadata *(const TargetTypeContextDescriptor<InProcess> *type, | ||
const TargetResilientClassMetadataPattern<InProcess> *pattern); | ||
|
||
/// An instantiation pattern for non-generic resilient class metadata. | ||
template <typename Runtime> | ||
struct TargetResilientClassMetadataPattern { | ||
/// If the class descriptor's hasResilientSuperclass() flag is set, | ||
/// this field instead points at a function that allocates metadata | ||
/// with the correct size at runtime. | ||
TargetRelativeDirectPointer<Runtime, MetadataRelocator> RelocationFunction; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment needs to be rewritten, since the "if" clause is now the precondition for this entire structure existing. |
||
|
||
/// The heap-destructor function. | ||
TargetRelativeDirectPointer<Runtime, HeapObjectDestroyer> Destroy; | ||
|
||
/// The ivar-destructor function. | ||
TargetRelativeDirectPointer<Runtime, ClassIVarDestroyer> IVarDestroyer; | ||
|
||
/// The class flags. | ||
ClassFlags Flags; | ||
|
||
// The following fields are only present in ObjC interop. | ||
|
||
/// Our ClassROData. | ||
TargetRelativeDirectPointer<Runtime, void> Data; | ||
|
||
/// Our metaclass. | ||
TargetRelativeDirectPointer<Runtime, TargetAnyClassMetadata<Runtime>> Metaclass; | ||
}; | ||
|
||
using ResilientClassMetadataPattern = | ||
TargetResilientClassMetadataPattern<InProcess>; | ||
|
||
/// The control structure for performing non-trivial initialization of | ||
/// singleton value metadata, which is required when e.g. a non-generic | ||
|
@@ -3340,8 +3373,8 @@ struct TargetInPlaceValueMetadataInitialization { | |
/// If the class descriptor's hasResilientSuperclass() flag is set, | ||
/// this field instead points at a function that allocates metadata | ||
/// with the correct size at runtime. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment needs similar fixing. |
||
TargetRelativeDirectPointer<Runtime, MetadataRelocator> | ||
RelocationFunction; | ||
TargetRelativeDirectPointer<Runtime, TargetResilientClassMetadataPattern<Runtime>> | ||
ResilientPattern; | ||
}; | ||
|
||
/// The completion function. The pattern will always be null. | ||
|
@@ -3358,8 +3391,10 @@ struct TargetInPlaceValueMetadataInitialization { | |
|
||
TargetMetadata<Runtime> *allocate( | ||
const TargetTypeContextDescriptor<Runtime> *description) const { | ||
if (hasRelocationFunction(description)) | ||
return RelocationFunction(description); | ||
if (hasRelocationFunction(description)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
return ResilientPattern->RelocationFunction(description, | ||
ResilientPattern.get()); | ||
} | ||
return IncompleteMetadata.get(); | ||
} | ||
}; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -574,15 +574,13 @@ void swift_initStructMetadata(StructMetadata *self, | |
const TypeLayout * const *fieldTypes, | ||
uint32_t *fieldOffsets); | ||
|
||
/// Relocate the metadata for a class and copy fields from the given template. | ||
/// The final size of the metadata is calculated at runtime from the size of | ||
/// the superclass metadata together with the given number of immediate | ||
/// members. | ||
/// Allocate the metadata for a class and copy fields from the given pattern. | ||
/// The final size of the metadata is calculated at runtime from the metadata | ||
/// bounds in the class descriptor. | ||
SWIFT_RUNTIME_EXPORT | ||
ClassMetadata * | ||
swift_relocateClassMetadata(ClassDescriptor *descriptor, | ||
ClassMetadata *pattern, | ||
size_t patternSize); | ||
ResilientClassMetadataPattern *pattern); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment should probably clarify that it's part of the construction process for resilient classes and expected to be called from the relocation function as opposed to, say, being a general utility for arbitrary code to use. |
||
|
||
/// Initialize the field offset vector for a dependent-layout class, using the | ||
/// "Universal" layout strategy. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should elaborate a bit about the breakdown between the different class-metadata allocation situations.