Skip to content

Commit 077fec0

Browse files
committed
Pretend that swift_willThrowTypedImpl doesn't use its generic metadata
1 parent eff9bac commit 077fec0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

lib/SIL/Utils/InstructionUtils.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,27 @@ static RuntimeEffect metadataEffect(SILType ty) {
465465
return RuntimeEffect::MetaData;
466466
}
467467

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+
468489
RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType) {
469490
auto ifNonTrivial = [&](SILType type, RuntimeEffect effect) -> RuntimeEffect {
470491
// Nonescaping closures are modeled with ownership to track borrows, but
@@ -1017,7 +1038,7 @@ RuntimeEffect swift::getRuntimeEffect(SILInstruction *inst, SILType &impactType)
10171038
}
10181039
}
10191040

1020-
if (!as.getSubstitutionMap().empty())
1041+
if (!as.getSubstitutionMap().empty() && !knownToNotUseGenericMetadata(as))
10211042
rt |= RuntimeEffect::MetaData;
10221043
if (auto *pa = dyn_cast<PartialApplyInst>(inst)) {
10231044
if (!pa->isOnStack())

0 commit comments

Comments
 (0)