Skip to content

Commit 4a49e65

Browse files
committed
[Sema] NFC: Replace a couple of closure parameters with ASTContext
Make it a bit clearer which function actually cares about the closure it's handed.
1 parent 25830d6 commit 4a49e65

File tree

1 file changed

+13
-17
lines changed

1 file changed

+13
-17
lines changed

lib/Sema/MiscDiagnostics.cpp

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
17451745
ASTContext &ctx = inClosure->getASTContext();
17461746

17471747
auto requiresSelfQualification =
1748-
isClosureRequiringSelfQualification(inClosure, ctx);
1748+
isClosureRequiringSelfQualification(inClosure);
17491749

17501750
// Metatype self captures don't extend the lifetime of an object.
17511751
if (captureType->is<MetatypeType>()) {
@@ -1783,7 +1783,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
17831783
// that defines self if present.
17841784
if (validateSelfRebindings) {
17851785
if (auto conditionalStmt = parentConditionalStmt(selfDecl)) {
1786-
if (!hasValidSelfRebinding(conditionalStmt, inClosure)) {
1786+
if (!hasValidSelfRebinding(conditionalStmt, ctx)) {
17871787
return false;
17881788
}
17891789
}
@@ -1793,7 +1793,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
17931793
// closure unwraps self. If not, implicit self is not allowed
17941794
// in this closure or in any nested closure.
17951795
if (closureHasWeakSelfCapture(inClosure) &&
1796-
!hasValidSelfRebinding(parentConditionalStmt(selfDecl), inClosure)) {
1796+
!hasValidSelfRebinding(parentConditionalStmt(selfDecl), ctx)) {
17971797
return false;
17981798
}
17991799

@@ -1967,7 +1967,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
19671967

19681968
static bool
19691969
hasValidSelfRebinding(const LabeledConditionalStmt *conditionalStmt,
1970-
const AbstractClosureExpr *inClosure) {
1970+
ASTContext &ctx) {
19711971
if (!conditionalStmt) {
19721972
return false;
19731973
}
@@ -1980,8 +1980,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
19801980
// guard let self = self else { return }
19811981
// method() // <- implicit self is not allowed
19821982
//
1983-
return conditionalStmt->rebindsSelf(inClosure->getASTContext(),
1984-
/*requiresCaptureListRef*/ true);
1983+
return conditionalStmt->rebindsSelf(ctx, /*requiresCaptureListRef*/ true);
19851984
}
19861985

19871986
/// The `LabeledConditionalStmt` that contains the given `ValueDecl` if
@@ -2064,8 +2063,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
20642063
/// Return true if this is a closure expression that will require explicit
20652064
/// use or capture of "self." for qualification of member references.
20662065
static bool
2067-
isClosureRequiringSelfQualification(const AbstractClosureExpr *CE,
2068-
ASTContext &Ctx) {
2066+
isClosureRequiringSelfQualification(const AbstractClosureExpr *CE) {
20692067
if (closureHasWeakSelfCapture(CE)) {
20702068
return true;
20712069
}
@@ -2253,7 +2251,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
22532251
// to use implicit self, even after fixing any invalid parents.
22542252
auto isEscapingAutoclosure =
22552253
isa<AutoClosureExpr>(ACE) &&
2256-
isClosureRequiringSelfQualification(ACE, Ctx);
2254+
isClosureRequiringSelfQualification(ACE);
22572255
if (!isEscapingAutoclosure) {
22582256
closureForDiagnostics = parentDisallowingImplicitSelf;
22592257
}
@@ -2390,7 +2388,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
23902388
return true;
23912389
}
23922390

2393-
if (isUsageAlwaysPreviouslyRejected(selfDecl, ACE)) {
2391+
if (isUsageAlwaysPreviouslyRejected(selfDecl)) {
23942392
return false;
23952393
}
23962394

@@ -2436,7 +2434,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
24362434
}
24372435

24382436
if (auto condStmt = parentConditionalStmt(selfDecl)) {
2439-
auto isValidSelfRebinding = hasValidSelfRebinding(condStmt, ACE);
2437+
auto isValidSelfRebinding = hasValidSelfRebinding(condStmt, Ctx);
24402438

24412439
// Swfit 5.8 permitted implicit self without validating any
24422440
// parent closures. If implicit self is only disallowed due to
@@ -2450,8 +2448,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
24502448
// If the binding is valid when only checking for a load expr,
24512449
// then we must only warn.
24522450
auto usesLoadExpr =
2453-
condStmt->rebindsSelf(ACE->getASTContext(),
2454-
/*requiresCaptureListRef*/ false,
2451+
condStmt->rebindsSelf(Ctx, /*requiresCaptureListRef*/ false,
24552452
/*requireLoadExpr*/ true);
24562453

24572454
if (!isValidSelfRebinding && usesLoadExpr) {
@@ -2464,12 +2461,11 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
24642461

24652462
/// Checks if this implicit self usage was always previously rejected as
24662463
/// invalid, so can continue to be treated an error.
2467-
bool isUsageAlwaysPreviouslyRejected(ValueDecl *selfDecl,
2468-
AbstractClosureExpr *ACE) {
2464+
bool isUsageAlwaysPreviouslyRejected(ValueDecl *selfDecl) {
24692465
// If the self decl refers to a weak self unwrap condition
24702466
// in some parent closure, then there is no source-compatibility
24712467
// requirement to avoid an error.
2472-
return hasValidSelfRebinding(parentConditionalStmt(selfDecl), ACE);
2468+
return hasValidSelfRebinding(parentConditionalStmt(selfDecl), Ctx);
24732469
}
24742470

24752471
/// Checks if this is a usage of implicit self in a strong self closure
@@ -2507,7 +2503,7 @@ static void diagnoseImplicitSelfUseInClosure(const Expr *E,
25072503
// FIXME: This is happening too early, because closure->getType() isn't set.
25082504
if (auto *closure = dyn_cast<AbstractClosureExpr>(DC))
25092505
if (closure->getType())
2510-
if (DiagnoseWalker::isClosureRequiringSelfQualification(closure, ctx))
2506+
if (DiagnoseWalker::isClosureRequiringSelfQualification(closure))
25112507
ACE = const_cast<AbstractClosureExpr *>(closure);
25122508
DC = DC->getParent();
25132509
}

0 commit comments

Comments
 (0)