Skip to content

Commit 52591ef

Browse files
committed
[Sema] Rename error-handling code to effects-handling code.
The error-handling code is getting generalized for 'async' handling as well, so rename the various entry points to talk about "effects" instead.
1 parent 6a5522f commit 52591ef

9 files changed

+43
-43
lines changed

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
}

lib/Sema/TypeCheckError.cpp renamed to lib/Sema/TypeCheckEffects.cpp

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//===--- TypeCheckError.cpp - Type Checking for Error Coverage ------------===//
1+
//===--- TypeCheckEffects.cpp - Type Checking for Effects Coverage --------===//
22
//
33
// This source file is part of the Swift.org open source project
44
//
@@ -10,8 +10,8 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// This file implements semantic analysis to ensure that errors are
14-
// caught.
13+
// This file implements semantic analysis to ensure that various effects (such
14+
// as throwing and async) are properly handled.
1515
//
1616
//===----------------------------------------------------------------------===//
1717

@@ -184,9 +184,9 @@ enum ShouldRecurse_t : bool {
184184
};
185185

186186
/// A CRTP ASTWalker implementation that looks for interesting
187-
/// nodes for error handling.
187+
/// nodes for effects handling.
188188
template <class Impl>
189-
class ErrorHandlingWalker : public ASTWalker {
189+
class EffectsHandlingWalker : public ASTWalker {
190190
Impl &asImpl() { return *static_cast<Impl*>(this); }
191191
public:
192192
bool walkToDeclPre(Decl *D) override {
@@ -221,7 +221,7 @@ class ErrorHandlingWalker : public ASTWalker {
221221
} else if (auto interpolated = dyn_cast<InterpolatedStringLiteralExpr>(E)) {
222222
recurse = asImpl().checkInterpolatedStringLiteral(interpolated);
223223
}
224-
// Error handling validation (via checkTopLevelErrorHandling) happens after
224+
// Error handling validation (via checkTopLevelEffects) happens after
225225
// type checking. If an unchecked expression is still around, the code was
226226
// invalid.
227227
#define UNCHECKED_EXPR(KIND, BASE) \
@@ -580,7 +580,7 @@ class ApplyClassifier {
580580
}
581581

582582
class FunctionBodyClassifier
583-
: public ErrorHandlingWalker<FunctionBodyClassifier> {
583+
: public EffectsHandlingWalker<FunctionBodyClassifier> {
584584
ApplyClassifier &Self;
585585
public:
586586
bool IsInvalid = false;
@@ -1221,8 +1221,8 @@ class Context {
12211221

12221222
/// A class to walk over a local context and validate the correctness
12231223
/// of its error coverage.
1224-
class CheckErrorCoverage : public ErrorHandlingWalker<CheckErrorCoverage> {
1225-
friend class ErrorHandlingWalker<CheckErrorCoverage>;
1224+
class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage> {
1225+
friend class EffectsHandlingWalker<CheckEffectsCoverage>;
12261226

12271227
ASTContext &Ctx;
12281228

@@ -1288,13 +1288,13 @@ class CheckErrorCoverage : public ErrorHandlingWalker<CheckErrorCoverage> {
12881288
/// An RAII object for restoring all the interesting state in an
12891289
/// error-coverage.
12901290
class ContextScope {
1291-
CheckErrorCoverage &Self;
1291+
CheckEffectsCoverage &Self;
12921292
Context OldContext;
12931293
DeclContext *OldRethrowsDC;
12941294
ContextFlags OldFlags;
12951295
ThrowingKind OldMaxThrowingKind;
12961296
public:
1297-
ContextScope(CheckErrorCoverage &self, Optional<Context> newContext)
1297+
ContextScope(CheckEffectsCoverage &self, Optional<Context> newContext)
12981298
: Self(self), OldContext(self.CurContext),
12991299
OldRethrowsDC(self.Classifier.RethrowsDC),
13001300
OldFlags(self.Flags),
@@ -1379,7 +1379,7 @@ class CheckErrorCoverage : public ErrorHandlingWalker<CheckErrorCoverage> {
13791379
};
13801380

13811381
public:
1382-
CheckErrorCoverage(ASTContext &ctx, Context initialContext)
1382+
CheckEffectsCoverage(ASTContext &ctx, Context initialContext)
13831383
: Ctx(ctx), CurContext(initialContext),
13841384
MaxThrowingKind(ThrowingKind::None) {
13851385

@@ -1528,8 +1528,8 @@ class CheckErrorCoverage : public ErrorHandlingWalker<CheckErrorCoverage> {
15281528
// Check the inactive regions of a #if block to disable warnings that may
15291529
// be due to platform specific code.
15301530
struct ConservativeThrowChecker : public ASTWalker {
1531-
CheckErrorCoverage &CEC;
1532-
ConservativeThrowChecker(CheckErrorCoverage &CEC) : CEC(CEC) {}
1531+
CheckEffectsCoverage &CEC;
1532+
ConservativeThrowChecker(CheckEffectsCoverage &CEC) : CEC(CEC) {}
15331533

15341534
Expr *walkToExprPost(Expr *E) override {
15351535
if (isa<TryExpr>(E))
@@ -1694,9 +1694,9 @@ class CheckErrorCoverage : public ErrorHandlingWalker<CheckErrorCoverage> {
16941694

16951695
} // end anonymous namespace
16961696

1697-
void TypeChecker::checkTopLevelErrorHandling(TopLevelCodeDecl *code) {
1697+
void TypeChecker::checkTopLevelEffects(TopLevelCodeDecl *code) {
16981698
auto &ctx = code->getDeclContext()->getASTContext();
1699-
CheckErrorCoverage checker(ctx, Context::forTopLevelCode(code));
1699+
CheckEffectsCoverage checker(ctx, Context::forTopLevelCode(code));
17001700

17011701
// In some language modes, we allow top-level code to omit 'try' marking.
17021702
if (ctx.LangOpts.EnableThrowWithoutTry)
@@ -1705,16 +1705,16 @@ void TypeChecker::checkTopLevelErrorHandling(TopLevelCodeDecl *code) {
17051705
code->getBody()->walk(checker);
17061706
}
17071707

1708-
void TypeChecker::checkFunctionErrorHandling(AbstractFunctionDecl *fn) {
1708+
void TypeChecker::checkFunctionEffects(AbstractFunctionDecl *fn) {
17091709
#ifndef NDEBUG
1710-
PrettyStackTraceDecl debugStack("checking error handling for", fn);
1710+
PrettyStackTraceDecl debugStack("checking effects handling for", fn);
17111711
#endif
17121712

17131713
auto isDeferBody = isa<FuncDecl>(fn) && cast<FuncDecl>(fn)->isDeferBody();
17141714
auto context =
17151715
isDeferBody ? Context::forDeferBody() : Context::forFunction(fn);
17161716
auto &ctx = fn->getASTContext();
1717-
CheckErrorCoverage checker(ctx, context);
1717+
CheckEffectsCoverage checker(ctx, context);
17181718

17191719
// If this is a debugger function, suppress 'try' marking at the top level.
17201720
if (fn->getAttrs().hasAttribute<LLDBDebuggerFunctionAttr>())
@@ -1728,30 +1728,30 @@ void TypeChecker::checkFunctionErrorHandling(AbstractFunctionDecl *fn) {
17281728
superInit->walk(checker);
17291729
}
17301730

1731-
void TypeChecker::checkInitializerErrorHandling(Initializer *initCtx,
1731+
void TypeChecker::checkInitializerEffects(Initializer *initCtx,
17321732
Expr *init) {
17331733
auto &ctx = initCtx->getASTContext();
1734-
CheckErrorCoverage checker(ctx, Context::forInitializer(initCtx));
1734+
CheckEffectsCoverage checker(ctx, Context::forInitializer(initCtx));
17351735
init->walk(checker);
17361736
}
17371737

1738-
/// Check the correctness of error handling within the given enum
1738+
/// Check the correctness of effects within the given enum
17391739
/// element's raw value expression.
17401740
///
17411741
/// The syntactic restrictions on such expressions should make it
17421742
/// impossible for errors to ever arise, but checking them anyway (1)
17431743
/// ensures correctness if those restrictions are ever loosened,
17441744
/// perhaps accidentally, and (2) allows the verifier to assert that
17451745
/// all calls have been checked.
1746-
void TypeChecker::checkEnumElementErrorHandling(EnumElementDecl *elt, Expr *E) {
1746+
void TypeChecker::checkEnumElementEffects(EnumElementDecl *elt, Expr *E) {
17471747
auto &ctx = elt->getASTContext();
1748-
CheckErrorCoverage checker(ctx, Context::forEnumElementInitializer(elt));
1748+
CheckEffectsCoverage checker(ctx, Context::forEnumElementInitializer(elt));
17491749
E->walk(checker);
17501750
}
17511751

1752-
void TypeChecker::checkPropertyWrapperErrorHandling(
1752+
void TypeChecker::checkPropertyWrapperEffects(
17531753
PatternBindingDecl *binding, Expr *expr) {
17541754
auto &ctx = binding->getASTContext();
1755-
CheckErrorCoverage checker(ctx, Context::forPatternBinding(binding));
1755+
CheckEffectsCoverage checker(ctx, Context::forPatternBinding(binding));
17561756
expr->walk(checker);
17571757
}

lib/Sema/TypeCheckStmt.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,7 +1698,7 @@ static Type getFunctionBuilderType(FuncDecl *FD) {
16981698
bool TypeChecker::typeCheckAbstractFunctionBody(AbstractFunctionDecl *AFD) {
16991699
auto res = evaluateOrDefault(AFD->getASTContext().evaluator,
17001700
TypeCheckFunctionBodyRequest{AFD}, true);
1701-
TypeChecker::checkFunctionErrorHandling(AFD);
1701+
TypeChecker::checkFunctionEffects(AFD);
17021702
TypeChecker::computeCaptures(AFD);
17031703
return res;
17041704
}
@@ -2152,7 +2152,7 @@ void TypeChecker::typeCheckTopLevelCodeDecl(TopLevelCodeDecl *TLCD) {
21522152
BraceStmt *Body = TLCD->getBody();
21532153
StmtChecker(TLCD).typeCheckStmt(Body);
21542154
TLCD->setBody(Body);
2155-
checkTopLevelErrorHandling(TLCD);
2155+
checkTopLevelEffects(TLCD);
21562156
performTopLevelDeclDiagnostics(TLCD);
21572157
}
21582158

lib/Sema/TypeCheckStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2491,7 +2491,7 @@ static void typeCheckSynthesizedWrapperInitializer(
24912491
dyn_cast_or_null<Initializer>(pbd->getInitContext(i))) {
24922492
TypeChecker::contextualizeInitializer(initializerContext, initializer);
24932493
}
2494-
TypeChecker::checkPropertyWrapperErrorHandling(pbd, initializer);
2494+
TypeChecker::checkPropertyWrapperEffects(pbd, initializer);
24952495
}
24962496

24972497
static PropertyWrapperMutability::Value

lib/Sema/TypeChecker.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,11 +1147,11 @@ void diagnoseIfDeprecated(SourceRange SourceRange,
11471147
void checkForForbiddenPrefix(ASTContext &C, DeclBaseName Name);
11481148

11491149
/// Check error handling in the given type-checked top-level code.
1150-
void checkTopLevelErrorHandling(TopLevelCodeDecl *D);
1151-
void checkFunctionErrorHandling(AbstractFunctionDecl *D);
1152-
void checkInitializerErrorHandling(Initializer *I, Expr *E);
1153-
void checkEnumElementErrorHandling(EnumElementDecl *D, Expr *expr);
1154-
void checkPropertyWrapperErrorHandling(PatternBindingDecl *binding,
1150+
void checkTopLevelEffects(TopLevelCodeDecl *D);
1151+
void checkFunctionEffects(AbstractFunctionDecl *D);
1152+
void checkInitializerEffects(Initializer *I, Expr *E);
1153+
void checkEnumElementEffects(EnumElementDecl *D, Expr *expr);
1154+
void checkPropertyWrapperEffects(PatternBindingDecl *binding,
11551155
Expr *expr);
11561156

11571157
/// If an expression references 'self.init' or 'super.init' in an

0 commit comments

Comments
 (0)