@@ -556,7 +556,7 @@ irgen::tryEmitConstantTypeMetadataRef(IRGenModule &IGM, CanType type,
556
556
SymbolReferenceKind refKind) {
557
557
if (IGM.isStandardLibrary ())
558
558
return ConstantReference ();
559
- if (! isTypeMetadataAccessTrivial (IGM, type))
559
+ if (isCompleteTypeMetadataStaticallyAddressable (IGM, type))
560
560
return ConstantReference ();
561
561
return IGM.getAddrOfTypeMetadata (type, refKind);
562
562
}
@@ -722,7 +722,7 @@ bool irgen::isNominalGenericContextTypeMetadataAccessTrivial(
722
722
};
723
723
auto isExistential = [&]() { return argument->isExistentialType (); };
724
724
auto metadataAccessIsTrivial = [&]() {
725
- return irgen::isTypeMetadataAccessTrivial (IGM,
725
+ return irgen::isCompleteTypeMetadataStaticallyAddressable (IGM,
726
726
argument->getCanonicalType ());
727
727
};
728
728
return !isGenericWithoutPrespecializedConformance () && !isExistential () &&
@@ -732,9 +732,9 @@ bool irgen::isNominalGenericContextTypeMetadataAccessTrivial(
732
732
&& IGM.getTypeInfoForUnlowered (type).isFixedSize (ResilienceExpansion::Maximal);
733
733
}
734
734
735
- // / Is it basically trivial to access the given metadata? If so, we don't
736
- // / need a cache variable in its accessor.
737
- bool irgen::isTypeMetadataAccessTrivial (IRGenModule &IGM, CanType type) {
735
+ // / Is complete metadata for the given type available at a fixed address?
736
+ bool irgen::isCompleteTypeMetadataStaticallyAddressable (IRGenModule &IGM,
737
+ CanType type) {
738
738
assert (!type->hasArchetype ());
739
739
740
740
// Value type metadata only requires dynamic initialization on first
@@ -775,10 +775,6 @@ bool irgen::isTypeMetadataAccessTrivial(IRGenModule &IGM, CanType type) {
775
775
if (isa<SILBoxType>(type))
776
776
return true ;
777
777
778
- // DynamicSelfType is actually local.
779
- if (type->hasDynamicSelfType ())
780
- return true ;
781
-
782
778
if (isa<BoundGenericStructType>(type) || isa<BoundGenericEnumType>(type)) {
783
779
auto nominalType = cast<BoundGenericType>(type);
784
780
auto *nominalDecl = nominalType->getDecl ();
@@ -794,6 +790,19 @@ bool irgen::isTypeMetadataAccessTrivial(IRGenModule &IGM, CanType type) {
794
790
return false ;
795
791
}
796
792
793
+ // / Should requests for the given type's metadata be cached?
794
+ bool irgen::shouldCacheTypeMetadataAccess (IRGenModule &IGM, CanType type) {
795
+ // DynamicSelfType is actually local.
796
+ if (type->hasDynamicSelfType ())
797
+ return false ;
798
+
799
+ // Statically addressable metadata does not need a cache.
800
+ if (isCompleteTypeMetadataStaticallyAddressable (IGM, type))
801
+ return false ;
802
+
803
+ return true ;
804
+ }
805
+
797
806
// / Return the standard access strategy for getting a non-dependent
798
807
// / type metadata object.
799
808
MetadataAccessStrategy irgen::getTypeMetadataAccessStrategy (CanType type) {
@@ -2016,7 +2025,7 @@ emitDirectTypeMetadataAccessFunctionBody(IRGenFunction &IGF,
2016
2025
}
2017
2026
2018
2027
// We should not be doing more serious work along this path.
2019
- assert (isTypeMetadataAccessTrivial (IGF.IGM , type));
2028
+ assert (isCompleteTypeMetadataStaticallyAddressable (IGF.IGM , type));
2020
2029
2021
2030
// Okay, everything else is built from a Swift metadata object.
2022
2031
llvm::Constant *metadata = IGF.IGM .getAddrOfTypeMetadata (type);
@@ -2064,7 +2073,7 @@ irgen::createTypeMetadataAccessFunction(IRGenModule &IGM, CanType type,
2064
2073
2065
2074
// If our preferred access method is to go via an accessor, it means
2066
2075
// there is some non-trivial computation that needs to be cached.
2067
- if (isTypeMetadataAccessTrivial (IGM, type)) {
2076
+ if (! shouldCacheTypeMetadataAccess (IGM, type)) {
2068
2077
cacheStrategy = CacheStrategy::None;
2069
2078
} else {
2070
2079
switch (cacheStrategy) {
@@ -2194,7 +2203,7 @@ static bool shouldAccessByMangledName(IRGenModule &IGM, CanType type) {
2194
2203
// others may require accessors to trigger instantiation.
2195
2204
//
2196
2205
// TODO: Also need to count the parent type's generic arguments.
2197
- if (isTypeMetadataAccessTrivial (IGM, nom)) {
2206
+ if (! shouldCacheTypeMetadataAccess (IGM, nom)) {
2198
2207
NumAddresses += 1 ;
2199
2208
} else {
2200
2209
NumCalls += 1 ;
@@ -2545,8 +2554,7 @@ IRGenFunction::emitTypeMetadataRef(CanType type,
2545
2554
}
2546
2555
2547
2556
if (type->hasArchetype () ||
2548
- isTypeMetadataAccessTrivial (IGM, type)) {
2549
- // FIXME: propagate metadata request!
2557
+ !shouldCacheTypeMetadataAccess (IGM, type)) {
2550
2558
return emitDirectTypeMetadataRef (*this , type, request);
2551
2559
}
2552
2560
0 commit comments