1
- // ===--- TypeCheckError .cpp - Type Checking for Error Coverage ---- --------===//
1
+ // ===--- TypeCheckEffects .cpp - Type Checking for Effects Coverage --------===//
2
2
//
3
3
// This source file is part of the Swift.org open source project
4
4
//
10
10
//
11
11
// ===----------------------------------------------------------------------===//
12
12
//
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 .
15
15
//
16
16
// ===----------------------------------------------------------------------===//
17
17
@@ -184,9 +184,9 @@ enum ShouldRecurse_t : bool {
184
184
};
185
185
186
186
// / A CRTP ASTWalker implementation that looks for interesting
187
- // / nodes for error handling.
187
+ // / nodes for effects handling.
188
188
template <class Impl >
189
- class ErrorHandlingWalker : public ASTWalker {
189
+ class EffectsHandlingWalker : public ASTWalker {
190
190
Impl &asImpl () { return *static_cast <Impl*>(this ); }
191
191
public:
192
192
bool walkToDeclPre (Decl *D) override {
@@ -221,7 +221,7 @@ class ErrorHandlingWalker : public ASTWalker {
221
221
} else if (auto interpolated = dyn_cast<InterpolatedStringLiteralExpr>(E)) {
222
222
recurse = asImpl ().checkInterpolatedStringLiteral (interpolated);
223
223
}
224
- // Error handling validation (via checkTopLevelErrorHandling ) happens after
224
+ // Error handling validation (via checkTopLevelEffects ) happens after
225
225
// type checking. If an unchecked expression is still around, the code was
226
226
// invalid.
227
227
#define UNCHECKED_EXPR (KIND, BASE ) \
@@ -580,7 +580,7 @@ class ApplyClassifier {
580
580
}
581
581
582
582
class FunctionBodyClassifier
583
- : public ErrorHandlingWalker <FunctionBodyClassifier> {
583
+ : public EffectsHandlingWalker <FunctionBodyClassifier> {
584
584
ApplyClassifier &Self;
585
585
public:
586
586
bool IsInvalid = false ;
@@ -1221,8 +1221,8 @@ class Context {
1221
1221
1222
1222
// / A class to walk over a local context and validate the correctness
1223
1223
// / 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 >;
1226
1226
1227
1227
ASTContext &Ctx;
1228
1228
@@ -1288,13 +1288,13 @@ class CheckErrorCoverage : public ErrorHandlingWalker<CheckErrorCoverage> {
1288
1288
// / An RAII object for restoring all the interesting state in an
1289
1289
// / error-coverage.
1290
1290
class ContextScope {
1291
- CheckErrorCoverage &Self;
1291
+ CheckEffectsCoverage &Self;
1292
1292
Context OldContext;
1293
1293
DeclContext *OldRethrowsDC;
1294
1294
ContextFlags OldFlags;
1295
1295
ThrowingKind OldMaxThrowingKind;
1296
1296
public:
1297
- ContextScope (CheckErrorCoverage &self, Optional<Context> newContext)
1297
+ ContextScope (CheckEffectsCoverage &self, Optional<Context> newContext)
1298
1298
: Self(self), OldContext(self.CurContext),
1299
1299
OldRethrowsDC (self.Classifier.RethrowsDC),
1300
1300
OldFlags(self.Flags),
@@ -1379,7 +1379,7 @@ class CheckErrorCoverage : public ErrorHandlingWalker<CheckErrorCoverage> {
1379
1379
};
1380
1380
1381
1381
public:
1382
- CheckErrorCoverage (ASTContext &ctx, Context initialContext)
1382
+ CheckEffectsCoverage (ASTContext &ctx, Context initialContext)
1383
1383
: Ctx(ctx), CurContext(initialContext),
1384
1384
MaxThrowingKind (ThrowingKind::None) {
1385
1385
@@ -1528,8 +1528,8 @@ class CheckErrorCoverage : public ErrorHandlingWalker<CheckErrorCoverage> {
1528
1528
// Check the inactive regions of a #if block to disable warnings that may
1529
1529
// be due to platform specific code.
1530
1530
struct ConservativeThrowChecker : public ASTWalker {
1531
- CheckErrorCoverage &CEC;
1532
- ConservativeThrowChecker (CheckErrorCoverage &CEC) : CEC(CEC) {}
1531
+ CheckEffectsCoverage &CEC;
1532
+ ConservativeThrowChecker (CheckEffectsCoverage &CEC) : CEC(CEC) {}
1533
1533
1534
1534
Expr *walkToExprPost (Expr *E) override {
1535
1535
if (isa<TryExpr>(E))
@@ -1694,9 +1694,9 @@ class CheckErrorCoverage : public ErrorHandlingWalker<CheckErrorCoverage> {
1694
1694
1695
1695
} // end anonymous namespace
1696
1696
1697
- void TypeChecker::checkTopLevelErrorHandling (TopLevelCodeDecl *code) {
1697
+ void TypeChecker::checkTopLevelEffects (TopLevelCodeDecl *code) {
1698
1698
auto &ctx = code->getDeclContext ()->getASTContext ();
1699
- CheckErrorCoverage checker (ctx, Context::forTopLevelCode (code));
1699
+ CheckEffectsCoverage checker (ctx, Context::forTopLevelCode (code));
1700
1700
1701
1701
// In some language modes, we allow top-level code to omit 'try' marking.
1702
1702
if (ctx.LangOpts .EnableThrowWithoutTry )
@@ -1705,16 +1705,16 @@ void TypeChecker::checkTopLevelErrorHandling(TopLevelCodeDecl *code) {
1705
1705
code->getBody ()->walk (checker);
1706
1706
}
1707
1707
1708
- void TypeChecker::checkFunctionErrorHandling (AbstractFunctionDecl *fn) {
1708
+ void TypeChecker::checkFunctionEffects (AbstractFunctionDecl *fn) {
1709
1709
#ifndef NDEBUG
1710
- PrettyStackTraceDecl debugStack (" checking error handling for" , fn);
1710
+ PrettyStackTraceDecl debugStack (" checking effects handling for" , fn);
1711
1711
#endif
1712
1712
1713
1713
auto isDeferBody = isa<FuncDecl>(fn) && cast<FuncDecl>(fn)->isDeferBody ();
1714
1714
auto context =
1715
1715
isDeferBody ? Context::forDeferBody () : Context::forFunction (fn);
1716
1716
auto &ctx = fn->getASTContext ();
1717
- CheckErrorCoverage checker (ctx, context);
1717
+ CheckEffectsCoverage checker (ctx, context);
1718
1718
1719
1719
// If this is a debugger function, suppress 'try' marking at the top level.
1720
1720
if (fn->getAttrs ().hasAttribute <LLDBDebuggerFunctionAttr>())
@@ -1728,30 +1728,30 @@ void TypeChecker::checkFunctionErrorHandling(AbstractFunctionDecl *fn) {
1728
1728
superInit->walk (checker);
1729
1729
}
1730
1730
1731
- void TypeChecker::checkInitializerErrorHandling (Initializer *initCtx,
1731
+ void TypeChecker::checkInitializerEffects (Initializer *initCtx,
1732
1732
Expr *init) {
1733
1733
auto &ctx = initCtx->getASTContext ();
1734
- CheckErrorCoverage checker (ctx, Context::forInitializer (initCtx));
1734
+ CheckEffectsCoverage checker (ctx, Context::forInitializer (initCtx));
1735
1735
init->walk (checker);
1736
1736
}
1737
1737
1738
- // / Check the correctness of error handling within the given enum
1738
+ // / Check the correctness of effects within the given enum
1739
1739
// / element's raw value expression.
1740
1740
// /
1741
1741
// / The syntactic restrictions on such expressions should make it
1742
1742
// / impossible for errors to ever arise, but checking them anyway (1)
1743
1743
// / ensures correctness if those restrictions are ever loosened,
1744
1744
// / perhaps accidentally, and (2) allows the verifier to assert that
1745
1745
// / all calls have been checked.
1746
- void TypeChecker::checkEnumElementErrorHandling (EnumElementDecl *elt, Expr *E) {
1746
+ void TypeChecker::checkEnumElementEffects (EnumElementDecl *elt, Expr *E) {
1747
1747
auto &ctx = elt->getASTContext ();
1748
- CheckErrorCoverage checker (ctx, Context::forEnumElementInitializer (elt));
1748
+ CheckEffectsCoverage checker (ctx, Context::forEnumElementInitializer (elt));
1749
1749
E->walk (checker);
1750
1750
}
1751
1751
1752
- void TypeChecker::checkPropertyWrapperErrorHandling (
1752
+ void TypeChecker::checkPropertyWrapperEffects (
1753
1753
PatternBindingDecl *binding, Expr *expr) {
1754
1754
auto &ctx = binding->getASTContext ();
1755
- CheckErrorCoverage checker (ctx, Context::forPatternBinding (binding));
1755
+ CheckEffectsCoverage checker (ctx, Context::forPatternBinding (binding));
1756
1756
expr->walk (checker);
1757
1757
}
0 commit comments