@@ -465,6 +465,27 @@ static RuntimeEffect metadataEffect(SILType ty) {
465
465
return RuntimeEffect::MetaData;
466
466
}
467
467
468
+ // / Whether this particular SIL function is known a prior not to use the
469
+ // / generic metadata it is given.
470
+ static bool knownToNotUseGenericMetadata (SILFunction &f) {
471
+ // swift_willThrowTypedImpl only uses the generic metadata when a global
472
+ // hook has been installed, so we treat it as if the generic metadata is
473
+ // unused.
474
+ if (f.getName () == " swift_willThrowTypedImpl" )
475
+ return true ;
476
+
477
+ return false ;
478
+ }
479
+
480
+ // / Whether this apply site is a call to a functio that is known not to use
481
+ // / the generic metadata it is given.
482
+ static bool knownToNotUseGenericMetadata (ApplySite &as) {
483
+ if (auto *callee = as.getCalleeFunction ()) {
484
+ return knownToNotUseGenericMetadata (*callee);
485
+ }
486
+ return false ;
487
+ }
488
+
468
489
RuntimeEffect swift::getRuntimeEffect (SILInstruction *inst, SILType &impactType) {
469
490
auto ifNonTrivial = [&](SILType type, RuntimeEffect effect) -> RuntimeEffect {
470
491
// Nonescaping closures are modeled with ownership to track borrows, but
@@ -1017,7 +1038,7 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
1017
1038
}
1018
1039
}
1019
1040
1020
- if (!as.getSubstitutionMap ().empty ())
1041
+ if (!as.getSubstitutionMap ().empty () && ! knownToNotUseGenericMetadata (as) )
1021
1042
rt |= RuntimeEffect::MetaData;
1022
1043
if (auto *pa = dyn_cast<PartialApplyInst>(inst)) {
1023
1044
if (!pa->isOnStack ())
0 commit comments