@@ -2905,25 +2905,8 @@ class MetadataReader {
2905
2905
return builtSubsts;
2906
2906
}
2907
2907
2908
- BuiltType readNominalTypeFromMetadata (MetadataRef origMetadata,
2909
- bool skipArtificialSubclasses = false ) {
2910
- auto metadata = origMetadata;
2911
- auto descriptorAddress =
2912
- readAddressOfNominalTypeDescriptor (metadata,
2913
- skipArtificialSubclasses);
2914
- if (!descriptorAddress)
2915
- return BuiltType ();
2916
-
2917
- // If we've skipped an artificial subclasses, check the cache at
2918
- // the superclass. (This also protects against recursion.)
2919
- if (skipArtificialSubclasses && metadata != origMetadata) {
2920
- auto it = TypeCache.find (getAddress (metadata));
2921
- if (it != TypeCache.end ())
2922
- return it->second ;
2923
- }
2924
-
2925
- // Read the nominal type descriptor.
2926
- ContextDescriptorRef descriptor = readContextDescriptor (descriptorAddress);
2908
+ BuiltType readNominalTypeFromDescriptor (MetadataRef metadata,
2909
+ ContextDescriptorRef descriptor) {
2927
2910
if (!descriptor)
2928
2911
return BuiltType ();
2929
2912
@@ -2932,34 +2915,64 @@ class MetadataReader {
2932
2915
if (!typeDecl)
2933
2916
return BuiltType ();
2934
2917
2918
+ // Attempt to build the parent (if it exists).
2919
+ BuiltType parent;
2920
+ if (auto parentDescriptor = readParentContextDescriptor (descriptor))
2921
+ if (parentDescriptor->isResolved ())
2922
+ if (auto resolvedParent = parentDescriptor->getResolved ())
2923
+ parent = readNominalTypeFromDescriptor (metadata, resolvedParent);
2924
+
2935
2925
// Build the nominal type.
2936
2926
BuiltType nominal;
2937
2927
if (descriptor->isGeneric ()) {
2938
2928
// Resolve the generic arguments.
2939
2929
auto builtGenerics = getGenericSubst (metadata, descriptor);
2940
2930
if (builtGenerics.empty ())
2941
2931
return BuiltType ();
2942
- nominal = Builder.createBoundGenericType (typeDecl, builtGenerics);
2932
+ nominal = Builder.createBoundGenericType (typeDecl, builtGenerics, parent );
2943
2933
} else {
2944
- nominal = Builder.createNominalType (typeDecl);
2934
+ nominal = Builder.createNominalType (typeDecl, parent);
2935
+ }
2936
+
2937
+ return nominal;
2938
+ }
2939
+
2940
+ BuiltType readNominalTypeFromMetadata (MetadataRef origMetadata,
2941
+ bool skipArtificialSubclasses = false ) {
2942
+ auto metadata = origMetadata;
2943
+ auto descriptorAddress =
2944
+ readAddressOfNominalTypeDescriptor (metadata, skipArtificialSubclasses);
2945
+ if (!descriptorAddress)
2946
+ return BuiltType ();
2947
+
2948
+ // If we've skipped an artificial subclasses, check the cache at
2949
+ // the superclass. (This also protects against recursion.)
2950
+ if (skipArtificialSubclasses && metadata != origMetadata) {
2951
+ auto it = TypeCache.find (getAddress (metadata));
2952
+ if (it != TypeCache.end ())
2953
+ return it->second ;
2945
2954
}
2946
2955
2956
+ // Read the nominal type descriptor.
2957
+ ContextDescriptorRef descriptor = readContextDescriptor (descriptorAddress);
2958
+ auto nominal = readNominalTypeFromDescriptor (origMetadata, descriptor);
2959
+
2947
2960
if (!nominal)
2948
2961
return BuiltType ();
2949
-
2962
+
2950
2963
TypeCache[getAddress (metadata)] = nominal;
2951
2964
2952
2965
// If we've skipped an artificial subclass, remove the
2953
2966
// recursion-protection entry we made for it.
2954
2967
if (skipArtificialSubclasses && metadata != origMetadata) {
2955
2968
TypeCache.erase (getAddress (origMetadata));
2956
2969
}
2957
-
2958
2970
return nominal;
2959
2971
}
2960
2972
2961
- BuiltType readNominalTypeFromClassMetadata (MetadataRef origMetadata,
2962
- bool skipArtificialSubclasses = false ) {
2973
+ BuiltType
2974
+ readNominalTypeFromClassMetadata (MetadataRef origMetadata,
2975
+ bool skipArtificialSubclasses = false ) {
2963
2976
auto classMeta = cast<TargetClassMetadata>(origMetadata);
2964
2977
if (classMeta->isTypeMetadata ())
2965
2978
return readNominalTypeFromMetadata (origMetadata, skipArtificialSubclasses);
0 commit comments