@@ -416,7 +416,17 @@ bool irgen::hasKnownVTableEntry(IRGenModule &IGM,
416
416
return hasKnownSwiftImplementation (IGM, theClass);
417
417
}
418
418
419
- static bool hasBuiltinTypeMetadata (CanType type) {
419
+ // / Is it basically trivial to access the given metadata? If so, we don't
420
+ // / need a cache variable in its accessor.
421
+ bool irgen::isTypeMetadataAccessTrivial (IRGenModule &IGM, CanType type) {
422
+ // Value type metadata only requires dynamic initialization on first
423
+ // access if it contains a resilient type.
424
+ if (isa<StructType>(type) || isa<EnumType>(type)) {
425
+ assert (!cast<NominalType>(type)->getDecl ()->isGenericContext () &&
426
+ " shouldn't be called for a generic type" );
427
+ return (IGM.getTypeInfoForLowered (type).isFixedSize ());
428
+ }
429
+
420
430
// The empty tuple type has a singleton metadata.
421
431
if (auto tuple = dyn_cast<TupleType>(type))
422
432
return tuple->getNumElements () == 0 ;
@@ -431,32 +441,17 @@ static bool hasBuiltinTypeMetadata(CanType type) {
431
441
if (isa<SILBoxType>(type))
432
442
return true ;
433
443
434
- return false ;
435
- }
436
-
437
- // / Is it basically trivial to access the given metadata? If so, we don't
438
- // / need a cache variable in its accessor.
439
- static bool isTypeMetadataAccessTrivial (IRGenModule &IGM, CanType type) {
440
- // Value type metadata only requires dynamic initialization on first
441
- // access if it contains a resilient type.
442
- if (isa<StructType>(type) || isa<EnumType>(type)) {
443
- assert (!cast<NominalType>(type)->getDecl ()->isGenericContext () &&
444
- " shouldn't be called for a generic type" );
445
- return (IGM.getTypeInfoForLowered (type).isFixedSize ());
446
- }
447
-
448
- if (hasBuiltinTypeMetadata (type)) {
444
+ // DynamicSelfType is actually local.
445
+ if (type->hasDynamicSelfType ())
449
446
return true ;
450
- }
451
447
452
448
return false ;
453
449
}
454
450
455
451
// / Return the standard access strategy for getting a non-dependent
456
452
// / type metadata object.
457
453
MetadataAccessStrategy
458
- irgen::getTypeMetadataAccessStrategy (IRGenModule &IGM, CanType type,
459
- bool preferDirectAccess) {
454
+ irgen::getTypeMetadataAccessStrategy (IRGenModule &IGM, CanType type) {
460
455
assert (!type->hasArchetype ());
461
456
462
457
// Non-generic structs, enums, and classes are special cases.
@@ -469,10 +464,6 @@ irgen::getTypeMetadataAccessStrategy(IRGenModule &IGM, CanType type,
469
464
if (nominal->getDecl ()->isGenericContext ())
470
465
return MetadataAccessStrategy::NonUniqueAccessor;
471
466
472
- if (preferDirectAccess &&
473
- isTypeMetadataAccessTrivial (IGM, type))
474
- return MetadataAccessStrategy::Direct;
475
-
476
467
// If the type doesn't guarantee that it has an access function,
477
468
// we might have to use a non-unique accessor.
478
469
@@ -492,14 +483,6 @@ irgen::getTypeMetadataAccessStrategy(IRGenModule &IGM, CanType type,
492
483
llvm_unreachable (" bad formal linkage" );
493
484
}
494
485
495
- // DynamicSelfType is actually local.
496
- if (type->hasDynamicSelfType ())
497
- return MetadataAccessStrategy::Direct;
498
-
499
- // Some types have special metadata in the runtime.
500
- if (hasBuiltinTypeMetadata (type))
501
- return MetadataAccessStrategy::Direct;
502
-
503
486
// Everything else requires a shared accessor function.
504
487
return MetadataAccessStrategy::NonUniqueAccessor;
505
488
}
@@ -1158,22 +1141,20 @@ static llvm::Value *emitCallToTypeMetadataAccessFunction(IRGenFunction &IGF,
1158
1141
1159
1142
// / Produce the type metadata pointer for the given type.
1160
1143
llvm::Value *IRGenFunction::emitTypeMetadataRef (CanType type) {
1161
- if (!type->hasArchetype ()) {
1162
- switch (getTypeMetadataAccessStrategy (IGM, type,
1163
- /* preferDirectAccess=*/ true )) {
1164
- case MetadataAccessStrategy::Direct:
1165
- return emitDirectTypeMetadataRef (*this , type);
1166
- case MetadataAccessStrategy::PublicUniqueAccessor:
1167
- case MetadataAccessStrategy::HiddenUniqueAccessor:
1168
- case MetadataAccessStrategy::PrivateAccessor:
1169
- return emitCallToTypeMetadataAccessFunction (*this , type, NotForDefinition);
1170
- case MetadataAccessStrategy::NonUniqueAccessor:
1171
- return emitCallToTypeMetadataAccessFunction (*this , type, ForDefinition);
1172
- }
1173
- llvm_unreachable (" bad type metadata access strategy" );
1144
+ if (type->hasArchetype () ||
1145
+ isTypeMetadataAccessTrivial (IGM, type)) {
1146
+ return emitDirectTypeMetadataRef (*this , type);
1174
1147
}
1175
1148
1176
- return emitDirectTypeMetadataRef (*this , type);
1149
+ switch (getTypeMetadataAccessStrategy (IGM, type)) {
1150
+ case MetadataAccessStrategy::PublicUniqueAccessor:
1151
+ case MetadataAccessStrategy::HiddenUniqueAccessor:
1152
+ case MetadataAccessStrategy::PrivateAccessor:
1153
+ return emitCallToTypeMetadataAccessFunction (*this , type, NotForDefinition);
1154
+ case MetadataAccessStrategy::NonUniqueAccessor:
1155
+ return emitCallToTypeMetadataAccessFunction (*this , type, ForDefinition);
1156
+ }
1157
+ llvm_unreachable (" bad type metadata access strategy" );
1177
1158
}
1178
1159
1179
1160
// / Return the address of a function that will return type metadata
@@ -1183,13 +1164,11 @@ llvm::Function *irgen::getOrCreateTypeMetadataAccessFunction(IRGenModule &IGM,
1183
1164
assert (!type->hasArchetype () &&
1184
1165
" cannot create global function to return dependent type metadata" );
1185
1166
1186
- switch (getTypeMetadataAccessStrategy (IGM, type,
1187
- /* preferDirectAccess=*/ false )) {
1167
+ switch (getTypeMetadataAccessStrategy (IGM, type)) {
1188
1168
case MetadataAccessStrategy::PublicUniqueAccessor:
1189
1169
case MetadataAccessStrategy::HiddenUniqueAccessor:
1190
1170
case MetadataAccessStrategy::PrivateAccessor:
1191
1171
return getTypeMetadataAccessFunction (IGM, type, NotForDefinition);
1192
- case MetadataAccessStrategy::Direct:
1193
1172
case MetadataAccessStrategy::NonUniqueAccessor:
1194
1173
return getTypeMetadataAccessFunction (IGM, type, ForDefinition);
1195
1174
}
0 commit comments