Skip to content

Commit 0466c4e

Browse files
committed
Sema: Streamline conformance rethrows check
1 parent 4bc6162 commit 0466c4e

File tree

1 file changed

+10
-30
lines changed

1 file changed

+10
-30
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -755,36 +755,6 @@ class ApplyClassifier {
755755
}
756756
}
757757

758-
if (fnRef.getRethrowingKind() == FunctionRethrowingKind::ByConformance) {
759-
auto substitutions = fnRef.getSubstitutions();
760-
bool classifiedAsThrows = false;
761-
for (auto conformanceRef : substitutions.getConformances()) {
762-
if (conformanceRef.classifyAsThrows()) {
763-
classifiedAsThrows = true;
764-
break;
765-
}
766-
}
767-
768-
if (classifiedAsThrows) {
769-
// multiple passes can occur, so ensure that any sub-expressions of this
770-
// call are marked as throws to mimic the closure variant.
771-
if (auto subExpr = dyn_cast<ApplyExpr>(E->getFn())) {
772-
if (!subExpr->isThrowsSet()) {
773-
subExpr->setThrows(true);
774-
}
775-
}
776-
return Classification::forRethrowingOnly(
777-
PotentialThrowReason::forRethrowsConformance(E), isAsync);
778-
}
779-
} else if (fnRef.isBodyRethrows() &&
780-
fnRef.getRethrowingKind() == FunctionRethrowingKind::Throws) {
781-
return Classification::forThrow(PotentialThrowReason::forThrowingApply(),
782-
isAsync);
783-
} else if (fnRef.isBodyRethrows() &&
784-
fnRef.getRethrowingKind() == FunctionRethrowingKind::None) {
785-
return isAsync ? Classification::forAsync() : Classification();
786-
}
787-
788758
// If the function doesn't throw at all, we're done here.
789759
if (!fnType->isThrowing()) {
790760
return isAsync ? Classification::forAsync() : Classification();
@@ -814,6 +784,16 @@ class ApplyClassifier {
814784
isAsync);
815785
}
816786

787+
if (fnRef.getRethrowingKind() == FunctionRethrowingKind::ByConformance) {
788+
auto substitutions = fnRef.getSubstitutions();
789+
for (auto conformanceRef : substitutions.getConformances()) {
790+
if (conformanceRef.classifyAsThrows()) {
791+
return Classification::forRethrowingOnly(
792+
PotentialThrowReason::forRethrowsConformance(E), isAsync);
793+
}
794+
}
795+
}
796+
817797
// If the function's body is 'rethrows' for the number of
818798
// arguments we gave it, apply the rethrows logic.
819799
if (fnRef.isBodyRethrows()) {

0 commit comments

Comments
 (0)