Skip to content

Commit 6d8a50d

Browse files
authored
Merge pull request #33398 from DougGregor/refactor-to-effects-handling
[Sema] Refactor error-handling checking to effects-handling checking
2 parents c0055e7 + 462e37b commit 6d8a50d

File tree

10 files changed

+220
-222
lines changed

10 files changed

+220
-222
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4016,10 +4016,13 @@ ERROR(throw_in_nonexhaustive_catch,none,
40164016
"error is not handled because the enclosing catch is not exhaustive", ())
40174017

40184018
ERROR(throwing_call_in_illegal_context,none,
4019-
"call can throw, but errors cannot be thrown out of %0",
4020-
(StringRef))
4019+
"call can throw, but errors cannot be thrown out of "
4020+
"%select{<<ERROR>>|a default argument|a property initializer|a global variable initializer|an enum case raw value|a catch pattern|a catch guard expression|a defer body}0",
4021+
(unsigned))
40214022
ERROR(throw_in_illegal_context,none,
4022-
"errors cannot be thrown out of %0", (StringRef))
4023+
"errors cannot be thrown out of "
4024+
"%select{<<ERROR>>|a default argument|a property initializer|a global variable initializer|an enum case raw value|a catch pattern|a catch guard expression|a defer body}0",
4025+
(unsigned))
40234026

40244027
ERROR(throwing_operator_without_try,none,
40254028
"operator can throw but expression is not marked with 'try'", ())

lib/Sema/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ add_swift_host_library(swiftSema STATIC
4646
TypeCheckDeclObjC.cpp
4747
TypeCheckDeclOverride.cpp
4848
TypeCheckDeclPrimary.cpp
49-
TypeCheckError.cpp
49+
TypeCheckEffects.cpp
5050
TypeCheckExpr.cpp
5151
TypeCheckExprObjC.cpp
5252
TypeCheckGeneric.cpp

lib/Sema/PCMacro.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ class Instrumenter : InstrumenterBase {
354354

355355
if (NB != B) {
356356
FD->setBody(NB);
357-
TypeChecker::checkFunctionErrorHandling(FD);
357+
TypeChecker::checkFunctionEffects(FD);
358358
}
359359
}
360360
} else if (auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
@@ -695,7 +695,7 @@ void swift::performPCMacro(SourceFile &SF) {
695695
BraceStmt *NewBody = I.transformBraceStmt(Body, true);
696696
if (NewBody != Body) {
697697
TLCD->setBody(NewBody);
698-
TypeChecker::checkTopLevelErrorHandling(TLCD);
698+
TypeChecker::checkTopLevelEffects(TLCD);
699699
TypeChecker::contextualizeTopLevelCode(TLCD);
700700
}
701701
return false;

lib/Sema/PlaygroundTransform.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ class Instrumenter : InstrumenterBase {
294294
BraceStmt *NB = transformBraceStmt(B);
295295
if (NB != B) {
296296
FD->setBody(NB);
297-
TypeChecker::checkFunctionErrorHandling(FD);
297+
TypeChecker::checkFunctionEffects(FD);
298298
}
299299
}
300300
} else if (auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
@@ -893,7 +893,7 @@ void swift::performPlaygroundTransform(SourceFile &SF, bool HighPerformance) {
893893
BraceStmt *NewBody = I.transformBraceStmt(Body);
894894
if (NewBody != Body) {
895895
FD->setBody(NewBody);
896-
TypeChecker::checkFunctionErrorHandling(FD);
896+
TypeChecker::checkFunctionEffects(FD);
897897
}
898898
return false;
899899
}
@@ -905,7 +905,7 @@ void swift::performPlaygroundTransform(SourceFile &SF, bool HighPerformance) {
905905
BraceStmt *NewBody = I.transformBraceStmt(Body, true);
906906
if (NewBody != Body) {
907907
TLCD->setBody(NewBody);
908-
TypeChecker::checkTopLevelErrorHandling(TLCD);
908+
TypeChecker::checkTopLevelEffects(TLCD);
909909
}
910910
return false;
911911
}

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ EnumRawValuesRequest::evaluate(Evaluator &eval, EnumDecl *ED,
10661066
if (TypeChecker::typeCheckExpression(exprToCheck, ED,
10671067
rawTy,
10681068
CTP_EnumCaseRawValue)) {
1069-
TypeChecker::checkEnumElementErrorHandling(elt, exprToCheck);
1069+
TypeChecker::checkEnumElementEffects(elt, exprToCheck);
10701070
}
10711071
}
10721072

lib/Sema/TypeCheckDeclPrimary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,7 @@ Expr *DefaultArgumentExprRequest::evaluate(Evaluator &evaluator,
881881
return new (ctx) ErrorExpr(initExpr->getSourceRange(), ErrorType::get(ctx));
882882
}
883883

884-
TypeChecker::checkInitializerErrorHandling(dc, initExpr);
884+
TypeChecker::checkInitializerEffects(dc, initExpr);
885885

886886
// Walk the checked initializer and contextualize any closures
887887
// we saw there.
@@ -1657,7 +1657,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
16571657
PBD->getInitContext(i));
16581658
if (initContext) {
16591659
// Check safety of error-handling in the declaration, too.
1660-
TypeChecker::checkInitializerErrorHandling(initContext, init);
1660+
TypeChecker::checkInitializerEffects(initContext, init);
16611661
TypeChecker::contextualizeInitializer(initContext, init);
16621662
}
16631663
}

0 commit comments

Comments
 (0)