Skip to content

Commit b9f1610

Browse files
authored
Merge pull request swiftlang#14753 from rjmccall/type-descriptor-hierarchy
Render TypeContextDescriptor into a proper hierarchy; NFC
2 parents a9784c7 + 23fa44e commit b9f1610

File tree

7 files changed

+367
-231
lines changed

7 files changed

+367
-231
lines changed

include/swift/Remote/MetadataReader.h

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -540,23 +540,44 @@ class MetadataReader {
540540
llvm::Optional<uint32_t>
541541
readGenericArgsOffset(MetadataRef metadata,
542542
ContextDescriptorRef descriptor) {
543-
auto type = cast<TargetTypeContextDescriptor<Runtime>>(descriptor);
544-
if (auto *classMetadata = dyn_cast<TargetClassMetadata<Runtime>>(metadata)){
545-
if (classMetadata->SuperClass) {
546-
auto superMetadata = readMetadata(classMetadata->SuperClass);
547-
if (!superMetadata)
548-
return llvm::None;
543+
switch (descriptor->getKind()) {
544+
case ContextDescriptorKind::Class: {
545+
auto type = cast<TargetClassDescriptor<Runtime>>(descriptor);
549546

550-
auto result =
551-
type->getGenericArgumentOffset(
552-
classMetadata,
553-
cast<TargetClassMetadata<Runtime>>(superMetadata));
547+
auto *classMetadata = dyn_cast<TargetClassMetadata<Runtime>>(metadata);
548+
if (!classMetadata)
549+
return llvm::None;
554550

555-
return result;
556-
}
551+
if (!classMetadata->SuperClass)
552+
return type->getGenericArgumentOffset(nullptr, nullptr);
553+
554+
auto superMetadata = readMetadata(classMetadata->SuperClass);
555+
if (!superMetadata)
556+
return llvm::None;
557+
558+
auto superClassMetadata =
559+
dyn_cast<TargetClassMetadata<Runtime>>(superMetadata);
560+
if (!superClassMetadata)
561+
return llvm::None;
562+
563+
auto result =
564+
type->getGenericArgumentOffset(classMetadata, superClassMetadata);
565+
return result;
566+
}
567+
568+
case ContextDescriptorKind::Enum: {
569+
auto type = cast<TargetEnumDescriptor<Runtime>>(descriptor);
570+
return type->getGenericArgumentOffset();
557571
}
558572

559-
return type->getGenericArgumentOffset();
573+
case ContextDescriptorKind::Struct: {
574+
auto type = cast<TargetStructDescriptor<Runtime>>(descriptor);
575+
return type->getGenericArgumentOffset();
576+
}
577+
578+
default:
579+
return llvm::None;
580+
}
560581
}
561582

562583
/// Read a single generic type argument from a bound generic type
@@ -959,15 +980,21 @@ class MetadataReader {
959980
case ContextDescriptorKind::Anonymous:
960981
baseSize = sizeof(TargetAnonymousContextDescriptor<Runtime>);
961982
break;
983+
case ContextDescriptorKind::Class:
984+
baseSize = sizeof(TargetClassDescriptor<Runtime>);
985+
genericHeaderSize = sizeof(TypeGenericContextDescriptorHeader);
986+
hasVTable = flags.getKindSpecificFlags()
987+
& (uint16_t)TypeContextDescriptorFlags::HasVTable;
988+
break;
989+
case ContextDescriptorKind::Enum:
990+
baseSize = sizeof(TargetEnumDescriptor<Runtime>);
991+
genericHeaderSize = sizeof(TypeGenericContextDescriptorHeader);
992+
break;
993+
case ContextDescriptorKind::Struct:
994+
baseSize = sizeof(TargetStructDescriptor<Runtime>);
995+
genericHeaderSize = sizeof(TypeGenericContextDescriptorHeader);
996+
break;
962997
default:
963-
if (kind >= ContextDescriptorKind::Type_First
964-
&& kind <= ContextDescriptorKind::Type_Last) {
965-
baseSize = sizeof(TargetTypeContextDescriptor<Runtime>);
966-
genericHeaderSize = sizeof(TypeGenericContextDescriptorHeader);
967-
hasVTable = flags.getKindSpecificFlags()
968-
& (uint16_t)TypeContextDescriptorFlags::HasVTable;
969-
break;
970-
}
971998
// We don't know about this kind of context.
972999
return nullptr;
9731000
}

0 commit comments

Comments
 (0)