Skip to content

Commit 1a5c002

Browse files
committed
Rutime: Code review feedback from John
1 parent 8be09fe commit 1a5c002

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

include/swift/ABI/Metadata.h

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3319,18 +3319,26 @@ using SingletonMetadataCache =
33193319
template <typename Runtime>
33203320
struct TargetResilientClassMetadataPattern;
33213321

3322-
/// An instantiation pattern for non-generic resilient class metadata.
3323-
/// Used in conjunction with SingletonMetadataInitialization.
3322+
/// A function for allocating metadata for a resilient class, calculating
3323+
/// the correct metadata size at runtime.
33243324
using MetadataRelocator =
33253325
Metadata *(const TargetTypeContextDescriptor<InProcess> *type,
33263326
const TargetResilientClassMetadataPattern<InProcess> *pattern);
33273327

33283328
/// An instantiation pattern for non-generic resilient class metadata.
3329+
///
3330+
/// Used for classes with resilient ancestry, that is, where at least one
3331+
/// ancestor is defined in a different resilience domain.
3332+
///
3333+
/// The hasResilientSuperclass() flag in the class context descriptor is
3334+
/// set in this case, and hasSingletonMetadataInitialization() must be
3335+
/// set as well.
3336+
///
3337+
/// The pattern is referenced from the SingletonMetadataInitialization
3338+
/// record in the class context descriptor.
33293339
template <typename Runtime>
33303340
struct TargetResilientClassMetadataPattern {
3331-
/// If the class descriptor's hasResilientSuperclass() flag is set,
3332-
/// this field instead points at a function that allocates metadata
3333-
/// with the correct size at runtime.
3341+
/// A function that allocates metadata with the correct size at runtime.
33343342
TargetRelativeDirectPointer<Runtime, MetadataRelocator> RelocationFunction;
33353343

33363344
/// The heap-destructor function.
@@ -3371,17 +3379,19 @@ struct TargetSingletonMetadataInitialization {
33713379
IncompleteMetadata;
33723380

33733381
/// If the class descriptor's hasResilientSuperclass() flag is set,
3374-
/// this field instead points at a function that allocates metadata
3375-
/// with the correct size at runtime.
3382+
/// this field instead points at a pattern used to allocate and
3383+
/// initialize metadata for this class, since it's size and contents
3384+
/// is not known at compile time.
33763385
TargetRelativeDirectPointer<Runtime, TargetResilientClassMetadataPattern<Runtime>>
33773386
ResilientPattern;
33783387
};
33793388

3380-
/// The completion function. The pattern will always be null.
3389+
/// The completion function. The pattern will always be null, even
3390+
/// for a resilient class.
33813391
TargetRelativeDirectPointer<Runtime, MetadataCompleter>
33823392
CompletionFunction;
33833393

3384-
bool hasRelocationFunction(
3394+
bool hasResilientClassPattern(
33853395
const TargetTypeContextDescriptor<Runtime> *description) const {
33863396
auto *classDescription =
33873397
dyn_cast<TargetClassDescriptor<Runtime>>(description);
@@ -3391,7 +3401,7 @@ struct TargetSingletonMetadataInitialization {
33913401

33923402
TargetMetadata<Runtime> *allocate(
33933403
const TargetTypeContextDescriptor<Runtime> *description) const {
3394-
if (hasRelocationFunction(description)) {
3404+
if (hasResilientClassPattern(description)) {
33953405
return ResilientPattern->RelocationFunction(description,
33963406
ResilientPattern.get());
33973407
}

include/swift/Runtime/Metadata.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,9 @@ void swift_initStructMetadata(StructMetadata *self,
577577
/// Allocate the metadata for a class and copy fields from the given pattern.
578578
/// The final size of the metadata is calculated at runtime from the metadata
579579
/// bounds in the class descriptor.
580+
///
581+
/// This function is only intended to be called from the relocation function
582+
/// of a resilient class pattern.
580583
SWIFT_RUNTIME_EXPORT
581584
ClassMetadata *
582585
swift_relocateClassMetadata(ClassDescriptor *descriptor,

0 commit comments

Comments
 (0)