@@ -253,7 +253,7 @@ class EffectsHandlingWalker : public ASTWalker {
253
253
};
254
254
255
255
// / A potential reason why something might throw.
256
- class PotentialReason {
256
+ class PotentialThrowReason {
257
257
public:
258
258
enum class Kind : uint8_t {
259
259
// / The function throws unconditionally.
@@ -275,21 +275,21 @@ class PotentialReason {
275
275
Expr *TheExpression;
276
276
Kind TheKind;
277
277
278
- explicit PotentialReason (Kind kind) : TheKind(kind) {}
278
+ explicit PotentialThrowReason (Kind kind) : TheKind(kind) {}
279
279
public:
280
- static PotentialReason forRethrowsArgument (Expr *E) {
281
- PotentialReason result (Kind::CallRethrowsWithExplicitThrowingArgument);
280
+ static PotentialThrowReason forRethrowsArgument (Expr *E) {
281
+ PotentialThrowReason result (Kind::CallRethrowsWithExplicitThrowingArgument);
282
282
result.TheExpression = E;
283
283
return result;
284
284
}
285
- static PotentialReason forDefaultArgument () {
286
- return PotentialReason (Kind::CallRethrowsWithDefaultThrowingArgument);
285
+ static PotentialThrowReason forDefaultArgument () {
286
+ return PotentialThrowReason (Kind::CallRethrowsWithDefaultThrowingArgument);
287
287
}
288
- static PotentialReason forThrowingApply () {
289
- return PotentialReason (Kind::CallThrows);
288
+ static PotentialThrowReason forThrowingApply () {
289
+ return PotentialThrowReason (Kind::CallThrows);
290
290
}
291
- static PotentialReason forThrow () {
292
- return PotentialReason (Kind::Throw);
291
+ static PotentialThrowReason forThrow () {
292
+ return PotentialThrowReason (Kind::Throw);
293
293
}
294
294
295
295
Kind getKind () const { return TheKind; }
@@ -321,16 +321,16 @@ enum class ThrowingKind {
321
321
};
322
322
323
323
// / A type expressing the result of classifying whether a call or function
324
- // / throws.
324
+ // / throws or is async .
325
325
class Classification {
326
326
bool IsInvalid = false ; // The AST is malformed. Don't diagnose.
327
327
bool IsAsync = false ;
328
328
ThrowingKind Result = ThrowingKind::None;
329
- Optional<PotentialReason > Reason;
329
+ Optional<PotentialThrowReason > Reason;
330
330
331
331
public:
332
332
Classification () : Result(ThrowingKind::None) {}
333
- explicit Classification (ThrowingKind result, PotentialReason reason,
333
+ explicit Classification (ThrowingKind result, PotentialThrowReason reason,
334
334
bool isAsync)
335
335
: IsAsync(isAsync), Result(result) {
336
336
if (result == ThrowingKind::Throws ||
@@ -341,7 +341,7 @@ class Classification {
341
341
342
342
// / Return a classification saying that there's an unconditional
343
343
// / throw site.
344
- static Classification forThrow (PotentialReason reason, bool isAsync) {
344
+ static Classification forThrow (PotentialThrowReason reason, bool isAsync) {
345
345
Classification result;
346
346
result.Result = ThrowingKind::Throws;
347
347
result.Reason = reason;
@@ -363,7 +363,7 @@ class Classification {
363
363
return result;
364
364
}
365
365
366
- static Classification forRethrowingOnly (PotentialReason reason) {
366
+ static Classification forRethrowingOnly (PotentialThrowReason reason) {
367
367
Classification result;
368
368
result.Result = ThrowingKind::RethrowingOnly;
369
369
result.Reason = reason;
@@ -378,7 +378,7 @@ class Classification {
378
378
379
379
bool isInvalid () const { return IsInvalid; }
380
380
ThrowingKind getResult () const { return Result; }
381
- PotentialReason getThrowsReason () const {
381
+ PotentialThrowReason getThrowsReason () const {
382
382
assert (getResult () == ThrowingKind::Throws ||
383
383
getResult () == ThrowingKind::RethrowingOnly);
384
384
return *Reason;
@@ -446,7 +446,7 @@ class ApplyClassifier {
446
446
447
447
assert (args.size () > fnRef.getNumArgumentsForFullApply () &&
448
448
" partial application was throwing?" );
449
- return Classification::forThrow (PotentialReason ::forThrowingApply (),
449
+ return Classification::forThrow (PotentialThrowReason ::forThrowingApply (),
450
450
isAsync);
451
451
}
452
452
@@ -476,7 +476,7 @@ class ApplyClassifier {
476
476
// Try to classify the implementation of functions that we have
477
477
// local knowledge of.
478
478
Classification result =
479
- classifyThrowingFunctionBody (fnRef, PotentialReason ::forThrowingApply ());
479
+ classifyThrowingFunctionBody (fnRef, PotentialThrowReason ::forThrowingApply ());
480
480
assert (result.getResult () != ThrowingKind::None &&
481
481
" body classification decided function was no-throw" );
482
482
@@ -496,7 +496,7 @@ class ApplyClassifier {
496
496
// / if the function is an autoclosure that simply doesn't throw at all.
497
497
Classification
498
498
classifyThrowingFunctionBody (const AbstractFunction &fn,
499
- PotentialReason reason) {
499
+ PotentialThrowReason reason) {
500
500
// If we're not checking a 'rethrows' context, we don't need to
501
501
// distinguish between 'throws' and 'rethrows'. But don't even
502
502
// trust 'throws' for autoclosures.
@@ -517,7 +517,7 @@ class ApplyClassifier {
517
517
}
518
518
519
519
Classification classifyThrowingParameterBody (ParamDecl *param,
520
- PotentialReason reason) {
520
+ PotentialThrowReason reason) {
521
521
assert (param->getType ()
522
522
->lookThroughAllOptionalTypes ()
523
523
->castTo <AnyFunctionType>()
@@ -542,7 +542,7 @@ class ApplyClassifier {
542
542
}
543
543
544
544
Classification classifyThrowingFunctionBody (AbstractFunctionDecl *fn,
545
- PotentialReason reason) {
545
+ PotentialThrowReason reason) {
546
546
// Functions can't be rethrowing-only unless they're defined
547
547
// within the rethrows context.
548
548
if (!isLocallyDefinedInRethrowsContext (fn) || !fn->hasBody ())
@@ -556,7 +556,7 @@ class ApplyClassifier {
556
556
}
557
557
558
558
Classification classifyThrowingFunctionBody (AbstractClosureExpr *closure,
559
- PotentialReason reason) {
559
+ PotentialThrowReason reason) {
560
560
bool isAutoClosure = isa<AutoClosureExpr>(closure);
561
561
562
562
// Closures can't be rethrowing-only unless they're defined
@@ -705,7 +705,7 @@ class ApplyClassifier {
705
705
706
706
if (isa<DefaultArgumentExpr>(arg)) {
707
707
return classifyArgumentByType (arg->getType (),
708
- PotentialReason ::forDefaultArgument ());
708
+ PotentialThrowReason ::forDefaultArgument ());
709
709
}
710
710
711
711
// If this argument is `nil` literal, it doesn't cause the call to throw.
@@ -736,7 +736,7 @@ class ApplyClassifier {
736
736
// parameter type included a throwing function type.
737
737
return classifyArgumentByType (
738
738
paramType,
739
- PotentialReason ::forRethrowsArgument (arg));
739
+ PotentialThrowReason ::forRethrowsArgument (arg));
740
740
}
741
741
742
742
// FIXME: There's a case where we can end up with an ApplyExpr that
@@ -751,7 +751,7 @@ class ApplyClassifier {
751
751
if (!paramFnType || !paramFnType->isThrowing ())
752
752
return Classification ();
753
753
754
- PotentialReason reason = PotentialReason ::forRethrowsArgument (arg);
754
+ PotentialThrowReason reason = PotentialThrowReason ::forRethrowsArgument (arg);
755
755
756
756
// TODO: partial applications?
757
757
@@ -793,7 +793,7 @@ class ApplyClassifier {
793
793
// / a throwing function in a way that is permitted to cause a
794
794
// / 'rethrows' function to throw.
795
795
static Classification classifyArgumentByType (Type paramType,
796
- PotentialReason reason) {
796
+ PotentialThrowReason reason) {
797
797
if (!paramType || paramType->hasError ())
798
798
return Classification::forInvalidCode ();
799
799
if (auto fnType = paramType->getAs <AnyFunctionType>()) {
@@ -1022,26 +1022,26 @@ class Context {
1022
1022
}
1023
1023
1024
1024
static void maybeAddRethrowsNote (DiagnosticEngine &Diags, SourceLoc loc,
1025
- const PotentialReason &reason) {
1025
+ const PotentialThrowReason &reason) {
1026
1026
switch (reason.getKind ()) {
1027
- case PotentialReason ::Kind::Throw:
1027
+ case PotentialThrowReason ::Kind::Throw:
1028
1028
llvm_unreachable (" should already have been covered" );
1029
- case PotentialReason ::Kind::CallThrows:
1029
+ case PotentialThrowReason ::Kind::CallThrows:
1030
1030
// Already fully diagnosed.
1031
1031
return ;
1032
- case PotentialReason ::Kind::CallRethrowsWithExplicitThrowingArgument:
1032
+ case PotentialThrowReason ::Kind::CallRethrowsWithExplicitThrowingArgument:
1033
1033
Diags.diagnose (reason.getThrowingArgument ()->getLoc (),
1034
1034
diag::because_rethrows_argument_throws);
1035
1035
return ;
1036
- case PotentialReason ::Kind::CallRethrowsWithDefaultThrowingArgument:
1036
+ case PotentialThrowReason ::Kind::CallRethrowsWithDefaultThrowingArgument:
1037
1037
Diags.diagnose (loc, diag::because_rethrows_default_argument_throws);
1038
1038
return ;
1039
1039
}
1040
1040
llvm_unreachable (" bad reason kind" );
1041
1041
}
1042
1042
1043
1043
void diagnoseUncoveredThrowSite (ASTContext &ctx, ASTNode E,
1044
- const PotentialReason &reason) {
1044
+ const PotentialThrowReason &reason) {
1045
1045
auto &Diags = ctx.Diags ;
1046
1046
auto message = diag::throwing_call_without_try;
1047
1047
auto loc = E.getStartLoc ();
@@ -1077,7 +1077,7 @@ class Context {
1077
1077
//
1078
1078
// Let's suggest couple of alternative fix-its
1079
1079
// because complete context is unavailable.
1080
- if (reason.getKind () != PotentialReason ::Kind::CallThrows)
1080
+ if (reason.getKind () != PotentialThrowReason ::Kind::CallThrows)
1081
1081
return ;
1082
1082
1083
1083
Diags.diagnose (loc, diag::note_forgot_try)
@@ -1090,7 +1090,7 @@ class Context {
1090
1090
1091
1091
void diagnoseThrowInLegalContext (DiagnosticEngine &Diags, ASTNode node,
1092
1092
bool isTryCovered,
1093
- const PotentialReason &reason,
1093
+ const PotentialThrowReason &reason,
1094
1094
Diag<> diagForThrow,
1095
1095
Diag<> diagForThrowingCall,
1096
1096
Diag<> diagForTrylessThrowingCall) {
@@ -1119,7 +1119,7 @@ class Context {
1119
1119
1120
1120
void diagnoseUnhandledThrowSite (DiagnosticEngine &Diags, ASTNode E,
1121
1121
bool isTryCovered,
1122
- const PotentialReason &reason) {
1122
+ const PotentialThrowReason &reason) {
1123
1123
switch (getKind ()) {
1124
1124
case Kind::Handled:
1125
1125
llvm_unreachable (" throw site is handled!" );
@@ -1558,7 +1558,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
1558
1558
1559
1559
ShouldRecurse_t checkThrow (ThrowStmt *S) {
1560
1560
checkThrowAsyncSite (S, /* requiresTry*/ false ,
1561
- Classification::forThrow (PotentialReason ::forThrow (),
1561
+ Classification::forThrow (PotentialThrowReason ::forThrow (),
1562
1562
/* async*/ false ));
1563
1563
return ShouldRecurse;
1564
1564
}
0 commit comments