Skip to content

Commit 8083b2d

Browse files
committed
[Effects handling] Rename PotentialReason -> PotentialThrowsReason.
1 parent a2dc034 commit 8083b2d

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

lib/Sema/TypeCheckEffects.cpp

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ class EffectsHandlingWalker : public ASTWalker {
253253
};
254254

255255
/// A potential reason why something might throw.
256-
class PotentialReason {
256+
class PotentialThrowReason {
257257
public:
258258
enum class Kind : uint8_t {
259259
/// The function throws unconditionally.
@@ -275,21 +275,21 @@ class PotentialReason {
275275
Expr *TheExpression;
276276
Kind TheKind;
277277

278-
explicit PotentialReason(Kind kind) : TheKind(kind) {}
278+
explicit PotentialThrowReason(Kind kind) : TheKind(kind) {}
279279
public:
280-
static PotentialReason forRethrowsArgument(Expr *E) {
281-
PotentialReason result(Kind::CallRethrowsWithExplicitThrowingArgument);
280+
static PotentialThrowReason forRethrowsArgument(Expr *E) {
281+
PotentialThrowReason result(Kind::CallRethrowsWithExplicitThrowingArgument);
282282
result.TheExpression = E;
283283
return result;
284284
}
285-
static PotentialReason forDefaultArgument() {
286-
return PotentialReason(Kind::CallRethrowsWithDefaultThrowingArgument);
285+
static PotentialThrowReason forDefaultArgument() {
286+
return PotentialThrowReason(Kind::CallRethrowsWithDefaultThrowingArgument);
287287
}
288-
static PotentialReason forThrowingApply() {
289-
return PotentialReason(Kind::CallThrows);
288+
static PotentialThrowReason forThrowingApply() {
289+
return PotentialThrowReason(Kind::CallThrows);
290290
}
291-
static PotentialReason forThrow() {
292-
return PotentialReason(Kind::Throw);
291+
static PotentialThrowReason forThrow() {
292+
return PotentialThrowReason(Kind::Throw);
293293
}
294294

295295
Kind getKind() const { return TheKind; }
@@ -321,16 +321,16 @@ enum class ThrowingKind {
321321
};
322322

323323
/// A type expressing the result of classifying whether a call or function
324-
/// throws.
324+
/// throws or is async.
325325
class Classification {
326326
bool IsInvalid = false; // The AST is malformed. Don't diagnose.
327327
bool IsAsync = false;
328328
ThrowingKind Result = ThrowingKind::None;
329-
Optional<PotentialReason> Reason;
329+
Optional<PotentialThrowReason> Reason;
330330

331331
public:
332332
Classification() : Result(ThrowingKind::None) {}
333-
explicit Classification(ThrowingKind result, PotentialReason reason,
333+
explicit Classification(ThrowingKind result, PotentialThrowReason reason,
334334
bool isAsync)
335335
: IsAsync(isAsync), Result(result) {
336336
if (result == ThrowingKind::Throws ||
@@ -341,7 +341,7 @@ class Classification {
341341

342342
/// Return a classification saying that there's an unconditional
343343
/// throw site.
344-
static Classification forThrow(PotentialReason reason, bool isAsync) {
344+
static Classification forThrow(PotentialThrowReason reason, bool isAsync) {
345345
Classification result;
346346
result.Result = ThrowingKind::Throws;
347347
result.Reason = reason;
@@ -363,7 +363,7 @@ class Classification {
363363
return result;
364364
}
365365

366-
static Classification forRethrowingOnly(PotentialReason reason) {
366+
static Classification forRethrowingOnly(PotentialThrowReason reason) {
367367
Classification result;
368368
result.Result = ThrowingKind::RethrowingOnly;
369369
result.Reason = reason;
@@ -378,7 +378,7 @@ class Classification {
378378

379379
bool isInvalid() const { return IsInvalid; }
380380
ThrowingKind getResult() const { return Result; }
381-
PotentialReason getThrowsReason() const {
381+
PotentialThrowReason getThrowsReason() const {
382382
assert(getResult() == ThrowingKind::Throws ||
383383
getResult() == ThrowingKind::RethrowingOnly);
384384
return *Reason;
@@ -446,7 +446,7 @@ class ApplyClassifier {
446446

447447
assert(args.size() > fnRef.getNumArgumentsForFullApply() &&
448448
"partial application was throwing?");
449-
return Classification::forThrow(PotentialReason::forThrowingApply(),
449+
return Classification::forThrow(PotentialThrowReason::forThrowingApply(),
450450
isAsync);
451451
}
452452

@@ -476,7 +476,7 @@ class ApplyClassifier {
476476
// Try to classify the implementation of functions that we have
477477
// local knowledge of.
478478
Classification result =
479-
classifyThrowingFunctionBody(fnRef, PotentialReason::forThrowingApply());
479+
classifyThrowingFunctionBody(fnRef, PotentialThrowReason::forThrowingApply());
480480
assert(result.getResult() != ThrowingKind::None &&
481481
"body classification decided function was no-throw");
482482

@@ -496,7 +496,7 @@ class ApplyClassifier {
496496
/// if the function is an autoclosure that simply doesn't throw at all.
497497
Classification
498498
classifyThrowingFunctionBody(const AbstractFunction &fn,
499-
PotentialReason reason) {
499+
PotentialThrowReason reason) {
500500
// If we're not checking a 'rethrows' context, we don't need to
501501
// distinguish between 'throws' and 'rethrows'. But don't even
502502
// trust 'throws' for autoclosures.
@@ -517,7 +517,7 @@ class ApplyClassifier {
517517
}
518518

519519
Classification classifyThrowingParameterBody(ParamDecl *param,
520-
PotentialReason reason) {
520+
PotentialThrowReason reason) {
521521
assert(param->getType()
522522
->lookThroughAllOptionalTypes()
523523
->castTo<AnyFunctionType>()
@@ -542,7 +542,7 @@ class ApplyClassifier {
542542
}
543543

544544
Classification classifyThrowingFunctionBody(AbstractFunctionDecl *fn,
545-
PotentialReason reason) {
545+
PotentialThrowReason reason) {
546546
// Functions can't be rethrowing-only unless they're defined
547547
// within the rethrows context.
548548
if (!isLocallyDefinedInRethrowsContext(fn) || !fn->hasBody())
@@ -556,7 +556,7 @@ class ApplyClassifier {
556556
}
557557

558558
Classification classifyThrowingFunctionBody(AbstractClosureExpr *closure,
559-
PotentialReason reason) {
559+
PotentialThrowReason reason) {
560560
bool isAutoClosure = isa<AutoClosureExpr>(closure);
561561

562562
// Closures can't be rethrowing-only unless they're defined
@@ -705,7 +705,7 @@ class ApplyClassifier {
705705

706706
if (isa<DefaultArgumentExpr>(arg)) {
707707
return classifyArgumentByType(arg->getType(),
708-
PotentialReason::forDefaultArgument());
708+
PotentialThrowReason::forDefaultArgument());
709709
}
710710

711711
// If this argument is `nil` literal, it doesn't cause the call to throw.
@@ -736,7 +736,7 @@ class ApplyClassifier {
736736
// parameter type included a throwing function type.
737737
return classifyArgumentByType(
738738
paramType,
739-
PotentialReason::forRethrowsArgument(arg));
739+
PotentialThrowReason::forRethrowsArgument(arg));
740740
}
741741

742742
// FIXME: There's a case where we can end up with an ApplyExpr that
@@ -751,7 +751,7 @@ class ApplyClassifier {
751751
if (!paramFnType || !paramFnType->isThrowing())
752752
return Classification();
753753

754-
PotentialReason reason = PotentialReason::forRethrowsArgument(arg);
754+
PotentialThrowReason reason = PotentialThrowReason::forRethrowsArgument(arg);
755755

756756
// TODO: partial applications?
757757

@@ -793,7 +793,7 @@ class ApplyClassifier {
793793
/// a throwing function in a way that is permitted to cause a
794794
/// 'rethrows' function to throw.
795795
static Classification classifyArgumentByType(Type paramType,
796-
PotentialReason reason) {
796+
PotentialThrowReason reason) {
797797
if (!paramType || paramType->hasError())
798798
return Classification::forInvalidCode();
799799
if (auto fnType = paramType->getAs<AnyFunctionType>()) {
@@ -1022,26 +1022,26 @@ class Context {
10221022
}
10231023

10241024
static void maybeAddRethrowsNote(DiagnosticEngine &Diags, SourceLoc loc,
1025-
const PotentialReason &reason) {
1025+
const PotentialThrowReason &reason) {
10261026
switch (reason.getKind()) {
1027-
case PotentialReason::Kind::Throw:
1027+
case PotentialThrowReason::Kind::Throw:
10281028
llvm_unreachable("should already have been covered");
1029-
case PotentialReason::Kind::CallThrows:
1029+
case PotentialThrowReason::Kind::CallThrows:
10301030
// Already fully diagnosed.
10311031
return;
1032-
case PotentialReason::Kind::CallRethrowsWithExplicitThrowingArgument:
1032+
case PotentialThrowReason::Kind::CallRethrowsWithExplicitThrowingArgument:
10331033
Diags.diagnose(reason.getThrowingArgument()->getLoc(),
10341034
diag::because_rethrows_argument_throws);
10351035
return;
1036-
case PotentialReason::Kind::CallRethrowsWithDefaultThrowingArgument:
1036+
case PotentialThrowReason::Kind::CallRethrowsWithDefaultThrowingArgument:
10371037
Diags.diagnose(loc, diag::because_rethrows_default_argument_throws);
10381038
return;
10391039
}
10401040
llvm_unreachable("bad reason kind");
10411041
}
10421042

10431043
void diagnoseUncoveredThrowSite(ASTContext &ctx, ASTNode E,
1044-
const PotentialReason &reason) {
1044+
const PotentialThrowReason &reason) {
10451045
auto &Diags = ctx.Diags;
10461046
auto message = diag::throwing_call_without_try;
10471047
auto loc = E.getStartLoc();
@@ -1077,7 +1077,7 @@ class Context {
10771077
//
10781078
// Let's suggest couple of alternative fix-its
10791079
// because complete context is unavailable.
1080-
if (reason.getKind() != PotentialReason::Kind::CallThrows)
1080+
if (reason.getKind() != PotentialThrowReason::Kind::CallThrows)
10811081
return;
10821082

10831083
Diags.diagnose(loc, diag::note_forgot_try)
@@ -1090,7 +1090,7 @@ class Context {
10901090

10911091
void diagnoseThrowInLegalContext(DiagnosticEngine &Diags, ASTNode node,
10921092
bool isTryCovered,
1093-
const PotentialReason &reason,
1093+
const PotentialThrowReason &reason,
10941094
Diag<> diagForThrow,
10951095
Diag<> diagForThrowingCall,
10961096
Diag<> diagForTrylessThrowingCall) {
@@ -1119,7 +1119,7 @@ class Context {
11191119

11201120
void diagnoseUnhandledThrowSite(DiagnosticEngine &Diags, ASTNode E,
11211121
bool isTryCovered,
1122-
const PotentialReason &reason) {
1122+
const PotentialThrowReason &reason) {
11231123
switch (getKind()) {
11241124
case Kind::Handled:
11251125
llvm_unreachable("throw site is handled!");
@@ -1558,7 +1558,7 @@ class CheckEffectsCoverage : public EffectsHandlingWalker<CheckEffectsCoverage>
15581558

15591559
ShouldRecurse_t checkThrow(ThrowStmt *S) {
15601560
checkThrowAsyncSite(S, /*requiresTry*/ false,
1561-
Classification::forThrow(PotentialReason::forThrow(),
1561+
Classification::forThrow(PotentialThrowReason::forThrow(),
15621562
/*async*/false));
15631563
return ShouldRecurse;
15641564
}

0 commit comments

Comments
 (0)