From 9204d7cee449ee6a76f1ae00f56bacdd1a1fdfd8 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 8 Nov 2019 13:45:11 -0800 Subject: [PATCH 1/8] [Constraint systme] Rename solve() -> solveImpl(). solve() is a bit too overloaded, so rename the version that does the core "evaluate all of the steps to produce a set of solutions" functionality to solveImpl(). --- lib/Sema/CSSolver.cpp | 8 ++++---- lib/Sema/ConstraintSystem.cpp | 2 +- lib/Sema/ConstraintSystem.h | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/Sema/CSSolver.cpp b/lib/Sema/CSSolver.cpp index 2b25a2cb2f7cf..888ced49fc325 100644 --- a/lib/Sema/CSSolver.cpp +++ b/lib/Sema/CSSolver.cpp @@ -537,7 +537,7 @@ ConstraintSystem::solveSingle(FreeTypeVariableBinding allowFreeTypeVariables, state.recordFixes = allowFixes; SmallVector solutions; - solve(solutions); + solveImpl(solutions); filterSolutions(solutions); if (solutions.size() != 1) @@ -629,7 +629,7 @@ bool ConstraintSystem::Candidate::solve( // Use solve which doesn't try to filter solution list. // Because we want the whole set of possible domain choices. - cs.solve(solutions); + cs.solveImpl(solutions); } if (ctx.LangOpts.DebugConstraintSolver) { @@ -1257,7 +1257,7 @@ bool ConstraintSystem::solve(Expr *const expr, SolverState state(*this, allowFreeTypeVariables); // Solve the system. - solve(solutions); + solveImpl(solutions); if (getASTContext().LangOpts.DebugConstraintSolver) { auto &log = getASTContext().TypeCheckerDebug->getStream(); @@ -1281,7 +1281,7 @@ bool ConstraintSystem::solve(Expr *const expr, return solutions.empty() || getExpressionTooComplex(solutions); } -void ConstraintSystem::solve(SmallVectorImpl &solutions) { +void ConstraintSystem::solveImpl(SmallVectorImpl &solutions) { assert(solverState); // If constraint system failed while trying to diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 994435a76aa0b..3649416810a23 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -2404,7 +2404,7 @@ bool ConstraintSystem::salvage(SmallVectorImpl &viable, Expr *expr) { state.recordFixes = true; // Solve the system. - solve(viable); + solveImpl(viable); // Check whether we have a best solution; this can happen if we found // a series of fixes that worked. diff --git a/lib/Sema/ConstraintSystem.h b/lib/Sema/ConstraintSystem.h index 0a608825d1f02..e582d7687386d 100644 --- a/lib/Sema/ConstraintSystem.h +++ b/lib/Sema/ConstraintSystem.h @@ -3634,7 +3634,7 @@ class ConstraintSystem { /// It doesn't filter solutions, that's the job of top-level `solve` methods. /// /// \param solutions The set of solutions to this system of constraints. - void solve(SmallVectorImpl &solutions); + void solveImpl(SmallVectorImpl &solutions); /// Compare two solutions to the same set of constraints. /// From 7ff75da27caefec5de8eb1d225ea135a8defc291 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 8 Nov 2019 15:11:42 -0800 Subject: [PATCH 2/8] [Constraint system] Drop unnecessary Expr* parameter from core solve. This parameter was unused anyway. --- lib/Sema/CSSolver.cpp | 5 ++--- lib/Sema/ConstraintSystem.h | 2 +- lib/Sema/TypeCheckConstraints.cpp | 6 +++--- lib/Sema/TypeCheckPropertyWrapper.cpp | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/lib/Sema/CSSolver.cpp b/lib/Sema/CSSolver.cpp index 888ced49fc325..35da16eab8e85 100644 --- a/lib/Sema/CSSolver.cpp +++ b/lib/Sema/CSSolver.cpp @@ -1243,15 +1243,14 @@ ConstraintSystem::solveImpl(Expr *&expr, } // Try to solve the constraint system using computed suggestions. - solve(expr, solutions, allowFreeTypeVariables); + solve(solutions, allowFreeTypeVariables); // If there are no solutions let's mark system as unsolved, // and solved otherwise even if there are multiple solutions still present. return solutions.empty() ? SolutionKind::Unsolved : SolutionKind::Solved; } -bool ConstraintSystem::solve(Expr *const expr, - SmallVectorImpl &solutions, +bool ConstraintSystem::solve(SmallVectorImpl &solutions, FreeTypeVariableBinding allowFreeTypeVariables) { // Set up solver state. SolverState state(*this, allowFreeTypeVariables); diff --git a/lib/Sema/ConstraintSystem.h b/lib/Sema/ConstraintSystem.h index e582d7687386d..463c30c028964 100644 --- a/lib/Sema/ConstraintSystem.h +++ b/lib/Sema/ConstraintSystem.h @@ -3610,7 +3610,7 @@ class ConstraintSystem { /// \returns true if an error occurred, false otherwise. Note that multiple /// ambiguous solutions for the same constraint system are considered to be /// success by this API. - bool solve(Expr *const expr, SmallVectorImpl &solutions, + bool solve(SmallVectorImpl &solutions, FreeTypeVariableBinding allowFreeTypeVariables = FreeTypeVariableBinding::Disallow); diff --git a/lib/Sema/TypeCheckConstraints.cpp b/lib/Sema/TypeCheckConstraints.cpp index da846dddf17fa..2d46069a68d79 100644 --- a/lib/Sema/TypeCheckConstraints.cpp +++ b/lib/Sema/TypeCheckConstraints.cpp @@ -2470,7 +2470,7 @@ getTypeOfCompletionOperatorImpl(TypeChecker &TC, DeclContext *DC, Expr *expr, // Attempt to solve the constraint system. SmallVector viable; - if (CS.solve(expr, viable, FreeTypeVariableBinding::Disallow)) + if (CS.solve(viable, FreeTypeVariableBinding::Disallow)) return nullptr; auto &solution = viable[0]; @@ -3246,7 +3246,7 @@ bool TypeChecker::typesSatisfyConstraint(Type type1, Type type2, if (openArchetypes) { assert(!unwrappedIUO && "FIXME"); SmallVector solutions; - return !cs.solve(nullptr, solutions, FreeTypeVariableBinding::Allow); + return !cs.solve(solutions, FreeTypeVariableBinding::Allow); } if (auto solution = cs.solveSingle()) { @@ -3450,7 +3450,7 @@ bool TypeChecker::convertToType(Expr *&expr, Type type, DeclContext *dc, // Attempt to solve the constraint system. SmallVector viable; - if ((cs.solve(expr, viable) || viable.size() != 1) && + if ((cs.solve(viable) || viable.size() != 1) && cs.salvage(viable, expr)) { return true; } diff --git a/lib/Sema/TypeCheckPropertyWrapper.cpp b/lib/Sema/TypeCheckPropertyWrapper.cpp index 7bb40498473d3..45dc61d349ab2 100644 --- a/lib/Sema/TypeCheckPropertyWrapper.cpp +++ b/lib/Sema/TypeCheckPropertyWrapper.cpp @@ -591,7 +591,7 @@ PropertyWrapperBackingPropertyTypeRequest::evaluate( propertyType, emptyLocator); SmallVector solutions; - if (cs.solve(nullptr, solutions) || solutions.size() != 1) { + if (cs.solve(solutions) || solutions.size() != 1) { var->diagnose(diag::property_wrapper_incompatible_property, propertyType, rawType); var->setInvalid(); From 0e269a512724a282512fc885be4806d71cd4d870 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 8 Nov 2019 16:29:29 -0800 Subject: [PATCH 3/8] [Constraint solver] Be more careful about NULL parent expression. --- lib/Sema/CSDiagnostics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index e5b29bc132253..79d892014e07f 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -680,7 +680,7 @@ bool MissingConformanceFailure::diagnoseAsAmbiguousOperatorRef() { // about missing conformance just in case. auto operatorID = name.getIdentifier(); - auto *applyExpr = cast(findParentExpr(anchor)); + auto *applyExpr = cast_or_null(findParentExpr(anchor)); if (auto *binaryOp = dyn_cast(applyExpr)) { auto lhsType = getType(binaryOp->getArg()->getElement(0)); auto rhsType = getType(binaryOp->getArg()->getElement(1)); From c744066c52e1150122d63bd865c5b4d0622fa511 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 8 Nov 2019 17:20:16 -0800 Subject: [PATCH 4/8] [Constraint solver] Stop using the "root expression" in failure diagnostics. We're still using the root expression to find the parent map, but we're not falling back to it indiscriminately. Use the parent of the anchor (or appropriate substitute) instead so we have a better handle on which expression we're diagnosing for. --- lib/Sema/CSDiagnostics.cpp | 18 +++++++++++------- lib/Sema/CSDiagnostics.h | 4 +++- test/Constraints/bridging.swift | 4 ++-- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index 79d892014e07f..47b8ffc57a571 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -1048,7 +1048,10 @@ bool MissingExplicitConversionFailure::diagnoseAsError() { if (!useAs && !useAsBang) return false; - auto *expr = getParentExpr(); + auto *expr = findParentExpr(getAnchor()); + if (!expr) + expr = getAnchor(); + // If we're performing pattern matching, // "as" means something completely different... if (auto binOpExpr = dyn_cast(expr)) { @@ -1146,8 +1149,9 @@ void MissingOptionalUnwrapFailure::offerDefaultValueUnwrapFixIt( // Figure out what we need to parenthesize. bool needsParensInside = exprNeedsParensBeforeAddingNilCoalescing(DC, expr); + auto parentExpr = findParentExpr(anchor); bool needsParensOutside = - exprNeedsParensAfterAddingNilCoalescing(DC, expr, getParentExpr()); + exprNeedsParensAfterAddingNilCoalescing(DC, expr, parentExpr); llvm::SmallString<2> insertBefore; llvm::SmallString<32> insertAfter; @@ -1488,7 +1492,7 @@ bool TypeChecker::diagnoseSelfAssignment(const Expr *expr) { } bool TrailingClosureAmbiguityFailure::diagnoseAsNote() { - const auto *expr = getParentExpr(); + const auto *expr = getRawAnchor(); auto *callExpr = dyn_cast(expr); if (!callExpr) return false; @@ -1543,6 +1547,7 @@ bool TrailingClosureAmbiguityFailure::diagnoseAsNote() { AssignmentFailure::AssignmentFailure(Expr *destExpr, ConstraintSystem &cs, SourceLoc diagnosticLoc) : FailureDiagnostic(destExpr, cs, cs.getConstraintLocator(destExpr)), + DestExpr(destExpr), Loc(diagnosticLoc), DeclDiagnostic(findDeclDiagonstic(cs.getASTContext(), destExpr)), TypeDiagnostic(diag::assignment_lhs_not_lvalue) {} @@ -1550,11 +1555,10 @@ AssignmentFailure::AssignmentFailure(Expr *destExpr, ConstraintSystem &cs, bool AssignmentFailure::diagnoseAsError() { auto &cs = getConstraintSystem(); auto *DC = getDC(); - auto *destExpr = getParentExpr(); // Walk through the destination expression, resolving what the problem is. If // we find a node in the lvalue path that is problematic, this returns it. - auto immInfo = resolveImmutableBase(destExpr); + auto immInfo = resolveImmutableBase(DestExpr); Optional choice = immInfo.second; @@ -1755,7 +1759,7 @@ bool AssignmentFailure::diagnoseAsError() { return true; } - emitDiagnostic(Loc, TypeDiagnostic, getType(destExpr)) + emitDiagnostic(Loc, TypeDiagnostic, getType(DestExpr)) .highlight(immInfo.first->getSourceRange()); return true; } @@ -3339,7 +3343,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() { return true; } - Expr *expr = getParentExpr(); + Expr *expr = findParentExpr(getAnchor()); SourceRange baseRange = expr ? expr->getSourceRange() : SourceRange(); // If the base is an implicit self type reference, and we're in a diff --git a/lib/Sema/CSDiagnostics.h b/lib/Sema/CSDiagnostics.h index ca59005b399ed..3aa050154677f 100644 --- a/lib/Sema/CSDiagnostics.h +++ b/lib/Sema/CSDiagnostics.h @@ -698,6 +698,7 @@ class TrailingClosureAmbiguityFailure final : public FailureDiagnostic { /// trying to assign something to immutable value, or trying /// to access mutating member on immutable base. class AssignmentFailure final : public FailureDiagnostic { + Expr *DestExpr; SourceLoc Loc; Diag DeclDiagnostic; Diag TypeDiagnostic; @@ -710,7 +711,8 @@ class AssignmentFailure final : public FailureDiagnostic { SourceLoc diagnosticLoc, Diag declDiag, Diag typeDiag) : FailureDiagnostic(destExpr, cs, cs.getConstraintLocator(destExpr)), - Loc(diagnosticLoc), DeclDiagnostic(declDiag), TypeDiagnostic(typeDiag) { + DestExpr(destExpr), Loc(diagnosticLoc), DeclDiagnostic(declDiag), + TypeDiagnostic(typeDiag) { } bool diagnoseAsError() override; diff --git a/test/Constraints/bridging.swift b/test/Constraints/bridging.swift index f6ef698c65723..bafa1dab76723 100644 --- a/test/Constraints/bridging.swift +++ b/test/Constraints/bridging.swift @@ -248,9 +248,9 @@ func rdar19770981(_ s: String, ns: NSString) { _ = ns as String > s // 'as' has lower precedence than '+' so add parens with the fixit: - s + ns // expected-error{{'NSString' is not implicitly convertible to 'String'; did you mean to use 'as' to explicitly convert?}}{{7-7=(}}{{9-9= as String)}} + s + ns // expected-error{{'NSString' is not implicitly convertible to 'String'; did you mean to use 'as' to explicitly convert?}}{{9-9= as String}} _ = s + (ns as String) - ns + s // expected-error{{'NSString' is not implicitly convertible to 'String'; did you mean to use 'as' to explicitly convert?}}{{3-3=(}}{{5-5= as String)}} + ns + s // expected-error{{'NSString' is not implicitly convertible to 'String'; did you mean to use 'as' to explicitly convert?}}{{5-5= as String}} _ = (ns as String) + s } From a7d6deb09a1d999187209a7e495b84a3f51f7377 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 8 Nov 2019 21:35:03 -0800 Subject: [PATCH 5/8] [Constraint system] Use parent of anchor for trailing closure ambiguity. --- lib/Sema/CSDiagnostics.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index 47b8ffc57a571..0f39025513063 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -1492,8 +1492,8 @@ bool TypeChecker::diagnoseSelfAssignment(const Expr *expr) { } bool TrailingClosureAmbiguityFailure::diagnoseAsNote() { - const auto *expr = getRawAnchor(); - auto *callExpr = dyn_cast(expr); + const auto *expr = findParentExpr(getAnchor()); + auto *callExpr = dyn_cast_or_null(expr); if (!callExpr) return false; if (!callExpr->hasTrailingClosure()) From 3fbdac51908a5fb93ab931d953fdd7e8553a527b Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 8 Nov 2019 21:39:27 -0800 Subject: [PATCH 6/8] [Failure diagnostic] Use the constraint system's parent map. --- lib/Sema/CSDiagnostics.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index 0f39025513063..b893907d809aa 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -93,7 +93,7 @@ FailureDiagnostic::emitDiagnostic(ArgTypes &&... Args) const { } Expr *FailureDiagnostic::findParentExpr(Expr *subExpr) const { - return E ? E->getParentMap()[subExpr] : nullptr; + return CS.getParentExpr(subExpr); } Expr * From bc926f7eb70ef1ab5ae80f8894d16c94b59f3df0 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 8 Nov 2019 22:38:49 -0800 Subject: [PATCH 7/8] [Constraint system] Drop the root expression from FailureDiagnostic. We're not using it for anything, now. --- lib/Sema/CSApply.cpp | 2 +- lib/Sema/CSDiag.cpp | 30 ++-- lib/Sema/CSDiagnostics.cpp | 6 +- lib/Sema/CSDiagnostics.h | 255 +++++++++++++++---------------- lib/Sema/CSFix.cpp | 211 +++++++++++++------------ lib/Sema/CSFix.h | 102 ++++++------- lib/Sema/CalleeCandidateInfo.cpp | 2 +- lib/Sema/ConstraintSystem.cpp | 4 +- 8 files changed, 299 insertions(+), 313 deletions(-) diff --git a/lib/Sema/CSApply.cpp b/lib/Sema/CSApply.cpp index b473eb41e7616..87ad5f4dc9a4b 100644 --- a/lib/Sema/CSApply.cpp +++ b/lib/Sema/CSApply.cpp @@ -7381,7 +7381,7 @@ bool ConstraintSystem::applySolutionFixes(Expr *E, const Solution &solution) { ArrayRef secondaryFixes{fixes.begin() + 1, fixes.end()}; auto *coalescedFix = primaryFix->coalescedWith(secondaryFixes); - auto diagnosed = coalescedFix->diagnose(root); + auto diagnosed = coalescedFix->diagnose(); if (coalescedFix->isWarning()) { assert(diagnosed && "warnings should always be diagnosed"); (void)diagnosed; diff --git a/lib/Sema/CSDiag.cpp b/lib/Sema/CSDiag.cpp index 3bd7fb44a0d28..b8e7800dc36f9 100644 --- a/lib/Sema/CSDiag.cpp +++ b/lib/Sema/CSDiag.cpp @@ -471,7 +471,7 @@ void FailureDiagnosis::diagnoseUnviableLookupResults( // If we found no results at all, mention that fact. if (result.UnviableCandidates.empty()) { - MissingMemberFailure failure(nullptr, CS, baseObjTy, memberName, + MissingMemberFailure failure(CS, baseObjTy, memberName, CS.getConstraintLocator(E)); auto diagnosed = failure.diagnoseAsError(); assert(diagnosed && "Failed to produce missing member diagnostic"); @@ -513,7 +513,7 @@ void FailureDiagnosis::diagnoseUnviableLookupResults( case MemberLookupResult::UR_UnavailableInExistential: { InvalidMemberRefOnExistential failure( - baseExpr, CS, instanceTy, memberName, CS.getConstraintLocator(E)); + CS, instanceTy, memberName, CS.getConstraintLocator(E)); failure.diagnoseAsError(); return; } @@ -524,7 +524,7 @@ void FailureDiagnosis::diagnoseUnviableLookupResults( ? ConstraintLocator::SubscriptMember : ConstraintLocator::Member; AllowTypeOrInstanceMemberFailure failure( - expr, CS, baseObjTy, choice->getDecl(), memberName, + CS, baseObjTy, choice->getDecl(), memberName, CS.getConstraintLocator(E, locatorKind)); auto diagnosed = failure.diagnoseAsError(); assert(diagnosed && @@ -534,7 +534,7 @@ void FailureDiagnosis::diagnoseUnviableLookupResults( } case MemberLookupResult::UR_MutatingMemberOnRValue: case MemberLookupResult::UR_MutatingGetterOnRValue: { - MutatingMemberRefOnImmutableBase failure(E, CS, choice->getDecl(), + MutatingMemberRefOnImmutableBase failure(CS, choice->getDecl(), CS.getConstraintLocator(E)); (void)failure.diagnose(); return; @@ -548,7 +548,7 @@ void FailureDiagnosis::diagnoseUnviableLookupResults( // visible to us, but the conforming type is. In this case, we need to // clamp the formal access for diagnostics purposes to the formal access // of the protocol itself. - InaccessibleMemberFailure failure(expr, CS, choice->getDecl(), + InaccessibleMemberFailure failure(CS, choice->getDecl(), CS.getConstraintLocator(E)); auto diagnosed = failure.diagnoseAsError(); assert(diagnosed && "failed to produce expected diagnostic"); @@ -730,7 +730,7 @@ bool FailureDiagnosis::diagnoseGeneralConversionFailure(Constraint *constraint){ if (auto fromTT = fromType->getAs()) if (auto toTT = toType->getAs()) { if (fromTT->getNumElements() != toTT->getNumElements()) { - auto failure = TupleContextualFailure(anchor, CS, fromTT, toTT, + auto failure = TupleContextualFailure(CS, fromTT, toTT, CS.getConstraintLocator(expr)); return failure.diagnoseAsError(); } @@ -748,7 +748,7 @@ bool FailureDiagnosis::diagnoseGeneralConversionFailure(Constraint *constraint){ // then we have a type error. if (computeTupleShuffle(TEType->castTo()->getElements(), toTT->getElements(), sources)) { - auto failure = TupleContextualFailure(anchor, CS, fromTT, toTT, + auto failure = TupleContextualFailure(CS, fromTT, toTT, CS.getConstraintLocator(expr)); return failure.diagnoseAsError(); } @@ -766,7 +766,7 @@ bool FailureDiagnosis::diagnoseGeneralConversionFailure(Constraint *constraint){ // Check for various issues converting to Bool. - ContextualFailure failure(expr, CS, fromType, toType, + ContextualFailure failure(CS, fromType, toType, constraint->getLocator()); if (failure.diagnoseConversionToBool()) return true; @@ -1285,7 +1285,7 @@ bool FailureDiagnosis::diagnoseContextualConversionError( return false; ContextualFailure failure( - expr, CS, CTP, exprType, contextualType, + CS, CTP, exprType, contextualType, CS.getConstraintLocator(expr, LocatorPathElt::ContextualType())); return failure.diagnoseAsError(); } @@ -2877,7 +2877,7 @@ bool FailureDiagnosis::visitApplyExpr(ApplyExpr *callExpr) { LocatorPathElt::ApplyArgToParam(0, 0, flags)}, /*summaryFlags=*/0); - ArgumentMismatchFailure failure(expr, CS, lhsType, rhsType, locator); + ArgumentMismatchFailure failure(CS, lhsType, rhsType, locator); return failure.diagnosePatternMatchingMismatch(); } @@ -3133,7 +3133,7 @@ bool FailureDiagnosis::diagnoseClosureExpr( // destructuring and provide a proper fix-it. if (argTupleTy->getNumElements() == actualArgCount) { ClosureParamDestructuringFailure failure( - expr, CS, fnType, CS.getConstraintLocator(CE)); + CS, fnType, CS.getConstraintLocator(CE)); return failure.diagnoseAsError(); } } @@ -3312,7 +3312,7 @@ bool FailureDiagnosis::visitArrayExpr(ArrayExpr *E) { return false; } - ContextualFailure failure(expr, CS, CS.getType(E), contextualType, + ContextualFailure failure(CS, CS.getType(E), contextualType, CS.getConstraintLocator(E)); if (failure.diagnoseConversionToDictionary()) return true; @@ -3581,7 +3581,7 @@ bool FailureDiagnosis::diagnoseMemberFailures( if (auto baseFTy = baseObjTy->getAs()) { if (baseExpr && baseFTy->getParams().empty()) { auto failure = - MissingCallFailure(expr, CS, CS.getConstraintLocator(baseExpr)); + MissingCallFailure(CS, CS.getConstraintLocator(baseExpr)); return failure.diagnoseAsError(); } } @@ -3720,7 +3720,7 @@ bool FailureDiagnosis::diagnoseMemberFailures( if (!optionalResult.ViableCandidates.empty()) { MemberAccessOnOptionalBaseFailure failure( - expr, CS, CS.getConstraintLocator(baseExpr), memberName, + CS, CS.getConstraintLocator(baseExpr), memberName, /*resultOptional=*/false); return failure.diagnoseAsError(); } @@ -4224,7 +4224,7 @@ void FailureDiagnosis::diagnoseAmbiguity(Expr *E) { { bool diagnosed = false; for (auto *fix : CS.getFixes()) - diagnosed |= fix->diagnose(expr); + diagnosed |= fix->diagnose(); if (diagnosed) return; diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index b893907d809aa..c2b275a7ad33d 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -1546,7 +1546,7 @@ bool TrailingClosureAmbiguityFailure::diagnoseAsNote() { AssignmentFailure::AssignmentFailure(Expr *destExpr, ConstraintSystem &cs, SourceLoc diagnosticLoc) - : FailureDiagnostic(destExpr, cs, cs.getConstraintLocator(destExpr)), + : FailureDiagnostic(cs, cs.getConstraintLocator(destExpr)), DestExpr(destExpr), Loc(diagnosticLoc), DeclDiagnostic(findDeclDiagonstic(cs.getASTContext(), destExpr)), @@ -3556,7 +3556,7 @@ bool AllowTypeOrInstanceMemberFailure::diagnoseAsError() { // components, let's provide a tailored diagnostic and return because // that is unsupported so there is no fix-it. if (locator->isForKeyPathComponent()) { - InvalidStaticMemberRefInKeyPath failure(expr, cs, Member, locator); + InvalidStaticMemberRefInKeyPath failure(cs, Member, locator); return failure.diagnoseAsError(); } @@ -5536,7 +5536,7 @@ bool ArgumentMismatchFailure::diagnoseMisplacedMissingArgument() const { auto *anchor = getRawAnchor(); MissingArgumentsFailure failure( - getParentExpr(), cs, {param.withType(argType)}, + cs, {param.withType(argType)}, cs.getConstraintLocator(anchor, ConstraintLocator::ApplyArgument)); return failure.diagnoseSingleMissingArgument(); diff --git a/lib/Sema/CSDiagnostics.h b/lib/Sema/CSDiagnostics.h index 3aa050154677f..b7421a57dcc58 100644 --- a/lib/Sema/CSDiagnostics.h +++ b/lib/Sema/CSDiagnostics.h @@ -38,7 +38,6 @@ class FunctionArgApplyInfo; /// provides most basic information such as location of /// the problem, parent expression and some utility methods. class FailureDiagnostic { - Expr *E; ConstraintSystem &CS; ConstraintLocator *Locator; @@ -51,9 +50,8 @@ class FailureDiagnostic { bool HasComplexLocator; public: - FailureDiagnostic(Expr *expr, ConstraintSystem &cs, - ConstraintLocator *locator) - : E(expr), CS(cs), Locator(locator), RawAnchor(locator->getAnchor()) { + FailureDiagnostic(ConstraintSystem &cs, ConstraintLocator *locator) + : CS(cs), Locator(locator), RawAnchor(locator->getAnchor()) { std::tie(Anchor, HasComplexLocator) = computeAnchor(); } @@ -84,8 +82,6 @@ class FailureDiagnostic { return CS; } - Expr *getParentExpr() const { return E; } - Expr *getRawAnchor() const { return RawAnchor; } Expr *getAnchor() const { return Anchor; } @@ -375,9 +371,9 @@ class RequirementFailure : public FailureDiagnostic { Type LHS, RHS; public: - RequirementFailure(ConstraintSystem &cs, Expr *expr, Type lhs, Type rhs, + RequirementFailure(ConstraintSystem &cs, Type lhs, Type rhs, ConstraintLocator *locator) - : FailureDiagnostic(expr, cs, locator), + : FailureDiagnostic(cs, locator), Conformance(getConformanceForConditionalReq(locator)), Signature(getSignature(locator)), AffectedDecl(getDeclRef()), LHS(resolveType(lhs)), RHS(resolveType(rhs)) { @@ -389,10 +385,6 @@ class RequirementFailure : public FailureDiagnostic { assert(getGenericContext() && "Affected decl not within a generic context?"); - // It's possible sometimes not to have no base expression. - if (!expr) - return; - if (auto *parentExpr = findParentExpr(getRawAnchor())) Apply = dyn_cast(parentExpr); } @@ -467,10 +459,10 @@ class RequirementFailure : public FailureDiagnostic { /// ``` class MissingConformanceFailure final : public RequirementFailure { public: - MissingConformanceFailure(Expr *expr, ConstraintSystem &cs, + MissingConformanceFailure(ConstraintSystem &cs, ConstraintLocator *locator, std::pair conformance) - : RequirementFailure(cs, expr, conformance.first, conformance.second, + : RequirementFailure(cs, conformance.first, conformance.second, locator) { auto reqElt = locator->castLastElementTo(); assert(reqElt.getRequirementKind() == RequirementKind::Conformance || @@ -526,9 +518,9 @@ class MissingConformanceFailure final : public RequirementFailure { /// `S.T` is not the same type as `Int`, which is required by `foo`. class SameTypeRequirementFailure final : public RequirementFailure { public: - SameTypeRequirementFailure(Expr *expr, ConstraintSystem &cs, Type lhs, + SameTypeRequirementFailure(ConstraintSystem &cs, Type lhs, Type rhs, ConstraintLocator *locator) - : RequirementFailure(cs, expr, lhs, rhs, locator) { + : RequirementFailure(cs, lhs, rhs, locator) { auto reqElt = locator->castLastElementTo(); assert(reqElt.getRequirementKind() == RequirementKind::SameType); } @@ -562,9 +554,9 @@ class SameTypeRequirementFailure final : public RequirementFailure { /// `A` is not the superclass of `B`, which is required by `foo`. class SuperclassRequirementFailure final : public RequirementFailure { public: - SuperclassRequirementFailure(Expr *expr, ConstraintSystem &cs, Type lhs, + SuperclassRequirementFailure(ConstraintSystem &cs, Type lhs, Type rhs, ConstraintLocator *locator) - : RequirementFailure(cs, expr, lhs, rhs, locator) { + : RequirementFailure(cs, lhs, rhs, locator) { auto reqElt = locator->castLastElementTo(); assert(reqElt.getRequirementKind() == RequirementKind::Superclass); } @@ -595,9 +587,9 @@ class LabelingFailure final : public FailureDiagnostic { ArrayRef CorrectLabels; public: - LabelingFailure(Expr *root, ConstraintSystem &cs, ConstraintLocator *locator, + LabelingFailure(ConstraintSystem &cs, ConstraintLocator *locator, ArrayRef labels) - : FailureDiagnostic(root, cs, locator), CorrectLabels(labels) {} + : FailureDiagnostic(cs, locator), CorrectLabels(labels) {} bool diagnoseAsError() override; bool diagnoseAsNote() override; @@ -609,10 +601,10 @@ class NoEscapeFuncToTypeConversionFailure final : public FailureDiagnostic { Type ConvertTo; public: - NoEscapeFuncToTypeConversionFailure(Expr *expr, ConstraintSystem &cs, + NoEscapeFuncToTypeConversionFailure(ConstraintSystem &cs, ConstraintLocator *locator, Type toType = Type()) - : FailureDiagnostic(expr, cs, locator), ConvertTo(toType) {} + : FailureDiagnostic(cs, locator), ConvertTo(toType) {} bool diagnoseAsError() override; @@ -630,10 +622,10 @@ class MemberAccessOnOptionalBaseFailure final : public FailureDiagnostic { bool ResultTypeIsOptional; public: - MemberAccessOnOptionalBaseFailure(Expr *expr, ConstraintSystem &cs, + MemberAccessOnOptionalBaseFailure(ConstraintSystem &cs, ConstraintLocator *locator, DeclName memberName, bool resultOptional) - : FailureDiagnostic(expr, cs, locator), Member(memberName), + : FailureDiagnostic(cs, locator), Member(memberName), ResultTypeIsOptional(resultOptional) {} bool diagnoseAsError() override; @@ -646,9 +638,9 @@ class MissingOptionalUnwrapFailure final : public FailureDiagnostic { Type UnwrappedType; public: - MissingOptionalUnwrapFailure(Expr *expr, ConstraintSystem &cs, Type baseType, + MissingOptionalUnwrapFailure(ConstraintSystem &cs, Type baseType, Type unwrappedType, ConstraintLocator *locator) - : FailureDiagnostic(expr, cs, locator), BaseType(baseType), + : FailureDiagnostic(cs, locator), BaseType(baseType), UnwrappedType(unwrappedType) {} bool diagnoseAsError() override; @@ -674,7 +666,7 @@ class RValueTreatedAsLValueFailure final : public FailureDiagnostic { public: RValueTreatedAsLValueFailure(ConstraintSystem &cs, ConstraintLocator *locator) - : FailureDiagnostic(nullptr, cs, locator) {} + : FailureDiagnostic(cs, locator) {} bool diagnoseAsError() override; }; @@ -683,10 +675,10 @@ class TrailingClosureAmbiguityFailure final : public FailureDiagnostic { ArrayRef Choices; public: - TrailingClosureAmbiguityFailure(Expr *root, ConstraintSystem &cs, + TrailingClosureAmbiguityFailure(ConstraintSystem &cs, Expr *anchor, ArrayRef choices) - : FailureDiagnostic(root, cs, cs.getConstraintLocator(anchor)), + : FailureDiagnostic(cs, cs.getConstraintLocator(anchor)), Choices(choices) {} bool diagnoseAsError() override { return false; } @@ -710,7 +702,7 @@ class AssignmentFailure final : public FailureDiagnostic { AssignmentFailure(Expr *destExpr, ConstraintSystem &cs, SourceLoc diagnosticLoc, Diag declDiag, Diag typeDiag) - : FailureDiagnostic(destExpr, cs, cs.getConstraintLocator(destExpr)), + : FailureDiagnostic(cs, cs.getConstraintLocator(destExpr)), DestExpr(destExpr), Loc(diagnosticLoc), DeclDiagnostic(declDiag), TypeDiagnostic(typeDiag) { } @@ -743,15 +735,15 @@ class ContextualFailure : public FailureDiagnostic { Type FromType, ToType; public: - ContextualFailure(Expr *root, ConstraintSystem &cs, Type lhs, Type rhs, + ContextualFailure(ConstraintSystem &cs, Type lhs, Type rhs, ConstraintLocator *locator) - : ContextualFailure(root, cs, cs.getContextualTypePurpose(), lhs, rhs, + : ContextualFailure(cs, cs.getContextualTypePurpose(), lhs, rhs, locator) {} - ContextualFailure(Expr *root, ConstraintSystem &cs, + ContextualFailure(ConstraintSystem &cs, ContextualTypePurpose purpose, Type lhs, Type rhs, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), CTP(purpose), + : FailureDiagnostic(cs, locator), CTP(purpose), FromType(resolve(lhs)), ToType(resolve(rhs)) {} Type getFromType() const { return FromType; } @@ -869,11 +861,11 @@ class GenericArgumentsMismatchFailure final : public ContextualFailure { ArrayRef Mismatches; public: - GenericArgumentsMismatchFailure(Expr *expr, ConstraintSystem &cs, + GenericArgumentsMismatchFailure(ConstraintSystem &cs, Type actualType, Type requiredType, ArrayRef mismatches, ConstraintLocator *locator) - : ContextualFailure(expr, cs, actualType, requiredType, locator), + : ContextualFailure(cs, actualType, requiredType, locator), Mismatches(mismatches) { assert(actualType->is()); assert(requiredType->is()); @@ -913,10 +905,10 @@ class GenericArgumentsMismatchFailure final : public ContextualFailure { /// ``` class ThrowingFunctionConversionFailure final : public ContextualFailure { public: - ThrowingFunctionConversionFailure(Expr *root, ConstraintSystem &cs, + ThrowingFunctionConversionFailure(ConstraintSystem &cs, Type fromType, Type toType, ConstraintLocator *locator) - : ContextualFailure(root, cs, fromType, toType, locator) { + : ContextualFailure(cs, fromType, toType, locator) { auto fnType1 = fromType->castTo(); auto fnType2 = toType->castTo(); assert(fnType1->throws() != fnType2->throws()); @@ -930,10 +922,10 @@ class ThrowingFunctionConversionFailure final : public ContextualFailure { /// "as" or "as!" has to be specified explicitly in cases like that. class MissingExplicitConversionFailure final : public ContextualFailure { public: - MissingExplicitConversionFailure(Expr *expr, ConstraintSystem &cs, + MissingExplicitConversionFailure(ConstraintSystem &cs, Type fromType, Type toType, ConstraintLocator *locator) - : ContextualFailure(expr, cs, fromType, toType, locator) {} + : ContextualFailure(cs, fromType, toType, locator) {} bool diagnoseAsError() override; @@ -962,9 +954,9 @@ class MissingExplicitConversionFailure final : public ContextualFailure { /// to `inout` or pointer parameter, without explicitly specifying `&`. class MissingAddressOfFailure final : public ContextualFailure { public: - MissingAddressOfFailure(Expr *expr, ConstraintSystem &cs, Type argTy, + MissingAddressOfFailure(ConstraintSystem &cs, Type argTy, Type paramTy, ConstraintLocator *locator) - : ContextualFailure(expr, cs, argTy, paramTy, locator) {} + : ContextualFailure(cs, argTy, paramTy, locator) {} bool diagnoseAsError() override; }; @@ -982,9 +974,9 @@ class MissingAddressOfFailure final : public ContextualFailure { /// ``` class InvalidUseOfAddressOf final : public ContextualFailure { public: - InvalidUseOfAddressOf(Expr *root, ConstraintSystem &cs, Type lhs, Type rhs, + InvalidUseOfAddressOf(ConstraintSystem &cs, Type lhs, Type rhs, ConstraintLocator *locator) - : ContextualFailure(root, cs, lhs, rhs, locator) {} + : ContextualFailure(cs, lhs, rhs, locator) {} bool diagnoseAsError() override; @@ -996,9 +988,9 @@ class InvalidUseOfAddressOf final : public ContextualFailure { /// Diagnose mismatches relating to tuple destructuring. class TupleContextualFailure final : public ContextualFailure { public: - TupleContextualFailure(Expr *root, ConstraintSystem &cs, Type lhs, Type rhs, + TupleContextualFailure(ConstraintSystem &cs, Type lhs, Type rhs, ConstraintLocator *locator) - : ContextualFailure(root, cs, lhs, rhs, locator) {} + : ContextualFailure(cs, lhs, rhs, locator) {} bool diagnoseAsError() override; @@ -1015,7 +1007,7 @@ class TupleContextualFailure final : public ContextualFailure { class AutoClosureForwardingFailure final : public FailureDiagnostic { public: AutoClosureForwardingFailure(ConstraintSystem &cs, ConstraintLocator *locator) - : FailureDiagnostic(nullptr, cs, locator) {} + : FailureDiagnostic(cs, locator) {} bool diagnoseAsError() override; }; @@ -1030,10 +1022,10 @@ class AutoClosureForwardingFailure final : public FailureDiagnostic { /// \endcode class AutoClosurePointerConversionFailure final : public ContextualFailure { public: - AutoClosurePointerConversionFailure(Expr *root, ConstraintSystem &cs, + AutoClosurePointerConversionFailure(ConstraintSystem &cs, Type pointeeType, Type pointerType, ConstraintLocator *locator) - : ContextualFailure(root, cs, pointeeType, pointerType, locator) {} + : ContextualFailure(cs, pointeeType, pointerType, locator) {} bool diagnoseAsError() override; }; @@ -1054,18 +1046,18 @@ class NonOptionalUnwrapFailure final : public FailureDiagnostic { Type BaseType; public: - NonOptionalUnwrapFailure(Expr *root, ConstraintSystem &cs, Type baseType, + NonOptionalUnwrapFailure(ConstraintSystem &cs, Type baseType, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), BaseType(baseType) {} + : FailureDiagnostic(cs, locator), BaseType(baseType) {} bool diagnoseAsError() override; }; class MissingCallFailure final : public FailureDiagnostic { public: - MissingCallFailure(Expr *root, ConstraintSystem &cs, + MissingCallFailure(ConstraintSystem &cs, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator) {} + : FailureDiagnostic(cs, locator) {} bool diagnoseAsError() override; }; @@ -1075,11 +1067,11 @@ class PropertyWrapperReferenceFailure : public ContextualFailure { bool UsingStorageWrapper; public: - PropertyWrapperReferenceFailure(Expr *root, ConstraintSystem &cs, + PropertyWrapperReferenceFailure(ConstraintSystem &cs, VarDecl *property, bool usingStorageWrapper, Type base, Type wrapper, ConstraintLocator *locator) - : ContextualFailure(root, cs, base, wrapper, locator), Property(property), + : ContextualFailure(cs, base, wrapper, locator), Property(property), UsingStorageWrapper(usingStorageWrapper) {} VarDecl *getProperty() const { return Property; } @@ -1099,12 +1091,12 @@ class PropertyWrapperReferenceFailure : public ContextualFailure { class ExtraneousPropertyWrapperUnwrapFailure final : public PropertyWrapperReferenceFailure { public: - ExtraneousPropertyWrapperUnwrapFailure(Expr *root, ConstraintSystem &cs, + ExtraneousPropertyWrapperUnwrapFailure(ConstraintSystem &cs, VarDecl *property, bool usingStorageWrapper, Type base, Type wrapper, ConstraintLocator *locator) - : PropertyWrapperReferenceFailure(root, cs, property, usingStorageWrapper, + : PropertyWrapperReferenceFailure(cs, property, usingStorageWrapper, base, wrapper, locator) {} bool diagnoseAsError() override; @@ -1113,11 +1105,11 @@ class ExtraneousPropertyWrapperUnwrapFailure final class MissingPropertyWrapperUnwrapFailure final : public PropertyWrapperReferenceFailure { public: - MissingPropertyWrapperUnwrapFailure(Expr *root, ConstraintSystem &cs, + MissingPropertyWrapperUnwrapFailure(ConstraintSystem &cs, VarDecl *property, bool usingStorageWrapper, Type base, Type wrapper, ConstraintLocator *locator) - : PropertyWrapperReferenceFailure(root, cs, property, usingStorageWrapper, + : PropertyWrapperReferenceFailure(cs, property, usingStorageWrapper, base, wrapper, locator) {} bool diagnoseAsError() override; @@ -1125,9 +1117,9 @@ class MissingPropertyWrapperUnwrapFailure final class SubscriptMisuseFailure final : public FailureDiagnostic { public: - SubscriptMisuseFailure(Expr *root, ConstraintSystem &cs, + SubscriptMisuseFailure(ConstraintSystem &cs, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator) {} + : FailureDiagnostic(cs, locator) {} bool diagnoseAsError() override; bool diagnoseAsNote() override; @@ -1138,9 +1130,9 @@ class InvalidMemberRefFailure : public FailureDiagnostic { DeclName Name; public: - InvalidMemberRefFailure(Expr *root, ConstraintSystem &cs, Type baseType, + InvalidMemberRefFailure(ConstraintSystem &cs, Type baseType, DeclName memberName, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), BaseType(baseType->getRValueType()), + : FailureDiagnostic(cs, locator), BaseType(baseType->getRValueType()), Name(memberName) {} protected: @@ -1159,9 +1151,9 @@ class InvalidMemberRefFailure : public FailureDiagnostic { /// ``` class MissingMemberFailure final : public InvalidMemberRefFailure { public: - MissingMemberFailure(Expr *root, ConstraintSystem &cs, Type baseType, + MissingMemberFailure(ConstraintSystem &cs, Type baseType, DeclName memberName, ConstraintLocator *locator) - : InvalidMemberRefFailure(root, cs, baseType, memberName, locator) {} + : InvalidMemberRefFailure(cs, baseType, memberName, locator) {} bool diagnoseAsError() override; @@ -1186,9 +1178,9 @@ class MissingMemberFailure final : public InvalidMemberRefFailure { /// ``` class InvalidMemberRefOnExistential final : public InvalidMemberRefFailure { public: - InvalidMemberRefOnExistential(Expr *root, ConstraintSystem &cs, Type baseType, + InvalidMemberRefOnExistential(ConstraintSystem &cs, Type baseType, DeclName memberName, ConstraintLocator *locator) - : InvalidMemberRefFailure(root, cs, baseType, memberName, locator) {} + : InvalidMemberRefFailure(cs, baseType, memberName, locator) {} bool diagnoseAsError() override; }; @@ -1215,10 +1207,10 @@ class AllowTypeOrInstanceMemberFailure final : public FailureDiagnostic { DeclName Name; public: - AllowTypeOrInstanceMemberFailure(Expr *root, ConstraintSystem &cs, + AllowTypeOrInstanceMemberFailure(ConstraintSystem &cs, Type baseType, ValueDecl *member, DeclName name, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), + : FailureDiagnostic(cs, locator), BaseType(baseType->getRValueType()), Member(member), Name(name) { assert(member); } @@ -1236,9 +1228,9 @@ class PartialApplicationFailure final : public FailureDiagnostic { bool CompatibilityWarning; public: - PartialApplicationFailure(Expr *root, bool warning, ConstraintSystem &cs, + PartialApplicationFailure(bool warning, ConstraintSystem &cs, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), CompatibilityWarning(warning) {} + : FailureDiagnostic(cs, locator), CompatibilityWarning(warning) {} bool diagnoseAsError() override; }; @@ -1249,10 +1241,10 @@ class InvalidInitRefFailure : public FailureDiagnostic { const ConstructorDecl *Init; SourceRange BaseRange; - InvalidInitRefFailure(Expr *root, ConstraintSystem &cs, Type baseTy, + InvalidInitRefFailure(ConstraintSystem &cs, Type baseTy, const ConstructorDecl *init, SourceRange baseRange, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), BaseType(baseTy), Init(init), + : FailureDiagnostic(cs, locator), BaseType(baseTy), Init(init), BaseRange(baseRange) {} public: @@ -1273,11 +1265,11 @@ class InvalidInitRefFailure : public FailureDiagnostic { /// ``` class InvalidDynamicInitOnMetatypeFailure final : public InvalidInitRefFailure { public: - InvalidDynamicInitOnMetatypeFailure(Expr *root, ConstraintSystem &cs, + InvalidDynamicInitOnMetatypeFailure(ConstraintSystem &cs, Type baseTy, const ConstructorDecl *init, SourceRange baseRange, ConstraintLocator *locator) - : InvalidInitRefFailure(root, cs, baseTy, init, baseRange, locator) {} + : InvalidInitRefFailure(cs, baseTy, init, baseRange, locator) {} bool diagnoseAsError() override; }; @@ -1297,11 +1289,11 @@ class InitOnProtocolMetatypeFailure final : public InvalidInitRefFailure { bool IsStaticallyDerived; public: - InitOnProtocolMetatypeFailure(Expr *root, ConstraintSystem &cs, Type baseTy, + InitOnProtocolMetatypeFailure(ConstraintSystem &cs, Type baseTy, const ConstructorDecl *init, bool isStaticallyDerived, SourceRange baseRange, ConstraintLocator *locator) - : InvalidInitRefFailure(root, cs, baseTy, init, baseRange, locator), + : InvalidInitRefFailure(cs, baseTy, init, baseRange, locator), IsStaticallyDerived(isStaticallyDerived) {} bool diagnoseAsError() override; @@ -1317,11 +1309,11 @@ class InitOnProtocolMetatypeFailure final : public InvalidInitRefFailure { class ImplicitInitOnNonConstMetatypeFailure final : public InvalidInitRefFailure { public: - ImplicitInitOnNonConstMetatypeFailure(Expr *root, ConstraintSystem &cs, + ImplicitInitOnNonConstMetatypeFailure(ConstraintSystem &cs, Type baseTy, const ConstructorDecl *init, ConstraintLocator *locator) - : InvalidInitRefFailure(root, cs, baseTy, init, SourceRange(), locator) {} + : InvalidInitRefFailure(cs, baseTy, init, SourceRange(), locator) {} bool diagnoseAsError() override; }; @@ -1332,10 +1324,10 @@ class MissingArgumentsFailure final : public FailureDiagnostic { SmallVector SynthesizedArgs; public: - MissingArgumentsFailure(Expr *root, ConstraintSystem &cs, + MissingArgumentsFailure(ConstraintSystem &cs, ArrayRef synthesizedArgs, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), + : FailureDiagnostic(cs, locator), SynthesizedArgs(synthesizedArgs.begin(), synthesizedArgs.end()) { assert(!SynthesizedArgs.empty() && "No missing arguments?!"); } @@ -1390,10 +1382,10 @@ class ExtraneousArgumentsFailure final : public FailureDiagnostic { public: ExtraneousArgumentsFailure( - Expr *root, ConstraintSystem &cs, FunctionType *contextualType, + ConstraintSystem &cs, FunctionType *contextualType, ArrayRef> extraArgs, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), + : FailureDiagnostic(cs, locator), ContextualType(resolveType(contextualType)->castTo()), ExtraArgs(extraArgs.begin(), extraArgs.end()) {} @@ -1423,12 +1415,12 @@ class OutOfOrderArgumentFailure final : public FailureDiagnostic { SmallVector Bindings; public: - OutOfOrderArgumentFailure(Expr *root, ConstraintSystem &cs, + OutOfOrderArgumentFailure(ConstraintSystem &cs, unsigned argIdx, unsigned prevArgIdx, ArrayRef bindings, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), ArgIdx(argIdx), + : FailureDiagnostic(cs, locator), ArgIdx(argIdx), PrevArgIdx(prevArgIdx), Bindings(bindings.begin(), bindings.end()) {} bool diagnoseAsError() override; @@ -1444,10 +1436,10 @@ class ClosureParamDestructuringFailure final : public FailureDiagnostic { FunctionType *ContextualType; public: - ClosureParamDestructuringFailure(Expr *root, ConstraintSystem &cs, + ClosureParamDestructuringFailure(ConstraintSystem &cs, FunctionType *contextualType, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), ContextualType(contextualType) {} + : FailureDiagnostic(cs, locator), ContextualType(contextualType) {} bool diagnoseAsError() override; @@ -1474,9 +1466,9 @@ class InaccessibleMemberFailure final : public FailureDiagnostic { ValueDecl *Member; public: - InaccessibleMemberFailure(Expr *root, ConstraintSystem &cs, ValueDecl *member, + InaccessibleMemberFailure(ConstraintSystem &cs, ValueDecl *member, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), Member(member) {} + : FailureDiagnostic(cs, locator), Member(member) {} bool diagnoseAsError() override; }; @@ -1498,10 +1490,10 @@ class MutatingMemberRefOnImmutableBase final : public FailureDiagnostic { ValueDecl *Member; public: - MutatingMemberRefOnImmutableBase(Expr *root, ConstraintSystem &cs, + MutatingMemberRefOnImmutableBase(ConstraintSystem &cs, ValueDecl *member, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), Member(member) {} + : FailureDiagnostic(cs, locator), Member(member) {} bool diagnoseAsError() override; }; @@ -1514,9 +1506,9 @@ class MutatingMemberRefOnImmutableBase final : public FailureDiagnostic { class AnyObjectKeyPathRootFailure final : public FailureDiagnostic { public: - AnyObjectKeyPathRootFailure(Expr *root, ConstraintSystem &cs, + AnyObjectKeyPathRootFailure(ConstraintSystem &cs, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator) {} + : FailureDiagnostic(cs, locator) {} bool diagnoseAsError() override; }; @@ -1539,9 +1531,9 @@ class KeyPathSubscriptIndexHashableFailure final : public FailureDiagnostic { Type NonConformingType; public: - KeyPathSubscriptIndexHashableFailure(Expr *root, ConstraintSystem &cs, + KeyPathSubscriptIndexHashableFailure(ConstraintSystem &cs, Type type, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), NonConformingType(type) { + : FailureDiagnostic(cs, locator), NonConformingType(type) { assert(locator->isResultOfKeyPathDynamicMemberLookup() || locator->isKeyPathSubscriptComponent()); } @@ -1553,9 +1545,9 @@ class InvalidMemberRefInKeyPath : public FailureDiagnostic { ValueDecl *Member; public: - InvalidMemberRefInKeyPath(Expr *root, ConstraintSystem &cs, ValueDecl *member, + InvalidMemberRefInKeyPath(ConstraintSystem &cs, ValueDecl *member, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), Member(member) { + : FailureDiagnostic(cs, locator), Member(member) { assert(member->hasName()); assert(locator->isForKeyPathComponent() || locator->isForKeyPathDynamicMemberLookup()); @@ -1588,9 +1580,9 @@ class InvalidMemberRefInKeyPath : public FailureDiagnostic { /// ``` class InvalidStaticMemberRefInKeyPath final : public InvalidMemberRefInKeyPath { public: - InvalidStaticMemberRefInKeyPath(Expr *root, ConstraintSystem &cs, + InvalidStaticMemberRefInKeyPath(ConstraintSystem &cs, ValueDecl *member, ConstraintLocator *locator) - : InvalidMemberRefInKeyPath(root, cs, member, locator) {} + : InvalidMemberRefInKeyPath(cs, member, locator) {} bool diagnoseAsError() override; }; @@ -1615,10 +1607,10 @@ class InvalidStaticMemberRefInKeyPath final : public InvalidMemberRefInKeyPath { class InvalidMemberWithMutatingGetterInKeyPath final : public InvalidMemberRefInKeyPath { public: - InvalidMemberWithMutatingGetterInKeyPath(Expr *root, ConstraintSystem &cs, + InvalidMemberWithMutatingGetterInKeyPath(ConstraintSystem &cs, ValueDecl *member, ConstraintLocator *locator) - : InvalidMemberRefInKeyPath(root, cs, member, locator) {} + : InvalidMemberRefInKeyPath(cs, member, locator) {} bool diagnoseAsError() override; }; @@ -1637,9 +1629,9 @@ class InvalidMemberWithMutatingGetterInKeyPath final /// ``` class InvalidMethodRefInKeyPath final : public InvalidMemberRefInKeyPath { public: - InvalidMethodRefInKeyPath(Expr *root, ConstraintSystem &cs, ValueDecl *method, + InvalidMethodRefInKeyPath(ConstraintSystem &cs, ValueDecl *method, ConstraintLocator *locator) - : InvalidMemberRefInKeyPath(root, cs, method, locator) { + : InvalidMemberRefInKeyPath(cs, method, locator) { assert(isa(method)); } @@ -1654,9 +1646,9 @@ class InvalidMethodRefInKeyPath final : public InvalidMemberRefInKeyPath { /// ``` class ExtraneousReturnFailure final : public FailureDiagnostic { public: - ExtraneousReturnFailure(Expr *root, ConstraintSystem &cs, + ExtraneousReturnFailure(ConstraintSystem &cs, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator) {} + : FailureDiagnostic(cs, locator) {} bool diagnoseAsError() override; }; @@ -1670,10 +1662,10 @@ class ExtraneousReturnFailure final : public FailureDiagnostic { /// ``` class CollectionElementContextualFailure final : public ContextualFailure { public: - CollectionElementContextualFailure(Expr *root, ConstraintSystem &cs, + CollectionElementContextualFailure(ConstraintSystem &cs, Type eltType, Type contextualType, ConstraintLocator *locator) - : ContextualFailure(root, cs, eltType, contextualType, locator) {} + : ContextualFailure(cs, eltType, contextualType, locator) {} bool diagnoseAsError() override; }; @@ -1682,11 +1674,11 @@ class MissingContextualConformanceFailure final : public ContextualFailure { ContextualTypePurpose Context; public: - MissingContextualConformanceFailure(Expr *root, ConstraintSystem &cs, + MissingContextualConformanceFailure(ConstraintSystem &cs, ContextualTypePurpose context, Type type, Type protocolType, ConstraintLocator *locator) - : ContextualFailure(root, cs, type, protocolType, locator), + : ContextualFailure(cs, type, protocolType, locator), Context(context) { assert(protocolType->is() || protocolType->is()); @@ -1702,9 +1694,9 @@ class MissingContextualConformanceFailure final : public ContextualFailure { /// argument type of `inout` parameter, they have to be equal. class InOutConversionFailure final : public ContextualFailure { public: - InOutConversionFailure(Expr *root, ConstraintSystem &cs, Type argType, + InOutConversionFailure(ConstraintSystem &cs, Type argType, Type paramType, ConstraintLocator *locator) - : ContextualFailure(root, cs, argType, paramType, locator) {} + : ContextualFailure(cs, argType, paramType, locator) {} bool diagnoseAsError() override; @@ -1726,10 +1718,10 @@ class MissingGenericArgumentsFailure final : public FailureDiagnostic { SmallVector Parameters; public: - MissingGenericArgumentsFailure(Expr *root, ConstraintSystem &cs, + MissingGenericArgumentsFailure(ConstraintSystem &cs, ArrayRef missingParams, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator) { + : FailureDiagnostic(cs, locator) { assert(!missingParams.empty()); Parameters.append(missingParams.begin(), missingParams.end()); } @@ -1771,12 +1763,11 @@ class SkipUnhandledConstructInFunctionBuilderFailure final void diagnosePrimary(bool asNote); public: - SkipUnhandledConstructInFunctionBuilderFailure(Expr *root, - ConstraintSystem &cs, + SkipUnhandledConstructInFunctionBuilderFailure(ConstraintSystem &cs, UnhandledNode unhandled, NominalTypeDecl *builder, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), + : FailureDiagnostic(cs, locator), unhandled(unhandled), builder(builder) { } @@ -1795,10 +1786,10 @@ class InvalidTupleSplatWithSingleParameterFailure final Type ParamType; public: - InvalidTupleSplatWithSingleParameterFailure(Expr *root, ConstraintSystem &cs, + InvalidTupleSplatWithSingleParameterFailure(ConstraintSystem &cs, Type paramTy, ConstraintLocator *locator) - : FailureDiagnostic(root, cs, locator), ParamType(paramTy) {} + : FailureDiagnostic(cs, locator), ParamType(paramTy) {} bool diagnoseAsError() override; }; @@ -1810,9 +1801,9 @@ class InvalidTupleSplatWithSingleParameterFailure final /// ``` class ExpandArrayIntoVarargsFailure final : public ContextualFailure { public: - ExpandArrayIntoVarargsFailure(Expr *root, ConstraintSystem &cs, Type lhs, + ExpandArrayIntoVarargsFailure(ConstraintSystem &cs, Type lhs, Type rhs, ConstraintLocator *locator) - : ContextualFailure(root, cs, lhs, rhs, locator) {} + : ContextualFailure(cs, lhs, rhs, locator) {} bool diagnoseAsError() override; bool diagnoseAsNote() override; @@ -1835,9 +1826,9 @@ class ArgumentMismatchFailure : public ContextualFailure { Optional Info; public: - ArgumentMismatchFailure(Expr *root, ConstraintSystem &cs, Type argType, + ArgumentMismatchFailure(ConstraintSystem &cs, Type argType, Type paramType, ConstraintLocator *locator) - : ContextualFailure(root, cs, argType, paramType, locator), + : ContextualFailure(cs, argType, paramType, locator), Info(getFunctionArgApplyInfo(getLocator())) {} bool diagnoseAsError() override; @@ -1956,27 +1947,27 @@ class ArgumentMismatchFailure : public ContextualFailure { /// Replace a coercion ('as') with a forced checked cast ('as!'). class MissingForcedDowncastFailure final : public ContextualFailure { public: - MissingForcedDowncastFailure(Expr *expr, ConstraintSystem &cs, Type fromType, + MissingForcedDowncastFailure(ConstraintSystem &cs, Type fromType, Type toType, ConstraintLocator *locator) - : ContextualFailure(expr, cs, fromType, toType, locator) {} + : ContextualFailure(cs, fromType, toType, locator) {} bool diagnoseAsError() override; }; class ExtraneousCallFailure final : public FailureDiagnostic { public: - ExtraneousCallFailure(Expr *expr, ConstraintSystem &cs, + ExtraneousCallFailure(ConstraintSystem &cs, ConstraintLocator *locator) - : FailureDiagnostic(expr, cs, locator) {} + : FailureDiagnostic(cs, locator) {} bool diagnoseAsError() override; }; class InvalidUseOfTrailingClosure final : public ArgumentMismatchFailure { public: - InvalidUseOfTrailingClosure(Expr *root, ConstraintSystem &cs, Type argType, + InvalidUseOfTrailingClosure(ConstraintSystem &cs, Type argType, Type paramType, ConstraintLocator *locator) - : ArgumentMismatchFailure(root, cs, argType, paramType, locator) {} + : ArgumentMismatchFailure(cs, argType, paramType, locator) {} bool diagnoseAsError() override; }; @@ -1994,12 +1985,12 @@ class NonEphemeralConversionFailure final : public ArgumentMismatchFailure { bool DowngradeToWarning; public: - NonEphemeralConversionFailure(Expr *expr, ConstraintSystem &cs, + NonEphemeralConversionFailure(ConstraintSystem &cs, ConstraintLocator *locator, Type fromType, Type toType, ConversionRestrictionKind conversionKind, bool downgradeToWarning) - : ArgumentMismatchFailure(expr, cs, fromType, toType, locator), + : ArgumentMismatchFailure(cs, fromType, toType, locator), ConversionKind(conversionKind), DowngradeToWarning(downgradeToWarning) { } @@ -2019,10 +2010,10 @@ class NonEphemeralConversionFailure final : public ArgumentMismatchFailure { class AssignmentTypeMismatchFailure final : public ContextualFailure { public: - AssignmentTypeMismatchFailure(Expr *expr, ConstraintSystem &cs, + AssignmentTypeMismatchFailure(ConstraintSystem &cs, ContextualTypePurpose context, Type srcType, Type dstType, ConstraintLocator *locator) - : ContextualFailure(expr, cs, context, srcType, dstType, locator) {} + : ContextualFailure(cs, context, srcType, dstType, locator) {} bool diagnoseAsError() override; bool diagnoseAsNote() override; diff --git a/lib/Sema/CSFix.cpp b/lib/Sema/CSFix.cpp index a05fc8f4a11d3..bdb3690896a2e 100644 --- a/lib/Sema/CSFix.cpp +++ b/lib/Sema/CSFix.cpp @@ -56,9 +56,9 @@ std::string ForceDowncast::getName() const { return name.c_str(); } -bool ForceDowncast::diagnose(Expr *expr, bool asNote) const { +bool ForceDowncast::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); - MissingExplicitConversionFailure failure(expr, cs, getFromType(), getToType(), + MissingExplicitConversionFailure failure(cs, getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -68,8 +68,8 @@ ForceDowncast *ForceDowncast::create(ConstraintSystem &cs, Type fromType, return new (cs.getAllocator()) ForceDowncast(cs, fromType, toType, locator); } -bool ForceOptional::diagnose(Expr *root, bool asNote) const { - MissingOptionalUnwrapFailure failure(root, getConstraintSystem(), BaseType, +bool ForceOptional::diagnose(bool asNote) const { + MissingOptionalUnwrapFailure failure(getConstraintSystem(), BaseType, UnwrappedType, getLocator()); return failure.diagnose(asNote); } @@ -81,11 +81,11 @@ ForceOptional *ForceOptional::create(ConstraintSystem &cs, Type baseType, ForceOptional(cs, baseType, unwrappedType, locator); } -bool UnwrapOptionalBase::diagnose(Expr *root, bool asNote) const { +bool UnwrapOptionalBase::diagnose(bool asNote) const { bool resultIsOptional = getKind() == FixKind::UnwrapOptionalBaseWithOptionalResult; MemberAccessOnOptionalBaseFailure failure( - root, getConstraintSystem(), getLocator(), MemberName, resultIsOptional); + getConstraintSystem(), getLocator(), MemberName, resultIsOptional); return failure.diagnose(asNote); } @@ -102,9 +102,9 @@ UnwrapOptionalBase *UnwrapOptionalBase::createWithOptionalResult( cs, FixKind::UnwrapOptionalBaseWithOptionalResult, member, locator); } -bool AddAddressOf::diagnose(Expr *root, bool asNote) const { +bool AddAddressOf::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); - MissingAddressOfFailure failure(root, cs, getFromType(), getToType(), + MissingAddressOfFailure failure(cs, getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -114,7 +114,7 @@ AddAddressOf *AddAddressOf::create(ConstraintSystem &cs, Type argTy, return new (cs.getAllocator()) AddAddressOf(cs, argTy, paramTy, locator); } -bool TreatRValueAsLValue::diagnose(Expr *root, bool asNote) const { +bool TreatRValueAsLValue::diagnose(bool asNote) const { RValueTreatedAsLValueFailure failure(getConstraintSystem(), getLocator()); return failure.diagnose(asNote); } @@ -124,8 +124,8 @@ TreatRValueAsLValue *TreatRValueAsLValue::create(ConstraintSystem &cs, return new (cs.getAllocator()) TreatRValueAsLValue(cs, locator); } -bool CoerceToCheckedCast::diagnose(Expr *root, bool asNote) const { - MissingForcedDowncastFailure failure(root, getConstraintSystem(), +bool CoerceToCheckedCast::diagnose(bool asNote) const { + MissingForcedDowncastFailure failure(getConstraintSystem(), getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); @@ -161,8 +161,8 @@ CoerceToCheckedCast *CoerceToCheckedCast::attempt(ConstraintSystem &cs, CoerceToCheckedCast(cs, fromType, toType, locator); } -bool MarkExplicitlyEscaping::diagnose(Expr *root, bool asNote) const { - NoEscapeFuncToTypeConversionFailure failure(root, getConstraintSystem(), +bool MarkExplicitlyEscaping::diagnose(bool asNote) const { + NoEscapeFuncToTypeConversionFailure failure(getConstraintSystem(), getLocator(), ConvertTo); return failure.diagnose(asNote); } @@ -174,8 +174,8 @@ MarkExplicitlyEscaping::create(ConstraintSystem &cs, ConstraintLocator *locator, MarkExplicitlyEscaping(cs, locator, convertingTo); } -bool RelabelArguments::diagnose(Expr *root, bool asNote) const { - LabelingFailure failure(root, getConstraintSystem(), getLocator(), +bool RelabelArguments::diagnose(bool asNote) const { + LabelingFailure failure(getConstraintSystem(), getLocator(), getLabels()); return failure.diagnose(asNote); } @@ -189,19 +189,19 @@ RelabelArguments::create(ConstraintSystem &cs, return new (mem) RelabelArguments(cs, correctLabels, locator); } -bool MissingConformance::diagnose(Expr *root, bool asNote) const { +bool MissingConformance::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); auto *locator = getLocator(); if (IsContextual) { auto context = cs.getContextualTypePurpose(); MissingContextualConformanceFailure failure( - root, cs, context, NonConformingType, ProtocolType, locator); + cs, context, NonConformingType, ProtocolType, locator); return failure.diagnose(asNote); } MissingConformanceFailure failure( - root, cs, locator, std::make_pair(NonConformingType, ProtocolType)); + cs, locator, std::make_pair(NonConformingType, ProtocolType)); return failure.diagnose(asNote); } @@ -221,8 +221,8 @@ MissingConformance::forRequirement(ConstraintSystem &cs, Type type, cs, /*isContextual=*/false, type, protocolType, locator); } -bool SkipSameTypeRequirement::diagnose(Expr *root, bool asNote) const { - SameTypeRequirementFailure failure(root, getConstraintSystem(), LHS, RHS, +bool SkipSameTypeRequirement::diagnose(bool asNote) const { + SameTypeRequirementFailure failure(getConstraintSystem(), LHS, RHS, getLocator()); return failure.diagnose(asNote); } @@ -233,8 +233,8 @@ SkipSameTypeRequirement::create(ConstraintSystem &cs, Type lhs, Type rhs, return new (cs.getAllocator()) SkipSameTypeRequirement(cs, lhs, rhs, locator); } -bool SkipSuperclassRequirement::diagnose(Expr *root, bool asNote) const { - SuperclassRequirementFailure failure(root, getConstraintSystem(), LHS, RHS, +bool SkipSuperclassRequirement::diagnose(bool asNote) const { + SuperclassRequirementFailure failure(getConstraintSystem(), LHS, RHS, getLocator()); return failure.diagnose(asNote); } @@ -246,8 +246,8 @@ SkipSuperclassRequirement::create(ConstraintSystem &cs, Type lhs, Type rhs, SkipSuperclassRequirement(cs, lhs, rhs, locator); } -bool ContextualMismatch::diagnose(Expr *root, bool asNote) const { - auto failure = ContextualFailure(root, getConstraintSystem(), getFromType(), +bool ContextualMismatch::diagnose(bool asNote) const { + auto failure = ContextualFailure(getConstraintSystem(), getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -258,9 +258,9 @@ ContextualMismatch *ContextualMismatch::create(ConstraintSystem &cs, Type lhs, return new (cs.getAllocator()) ContextualMismatch(cs, lhs, rhs, locator); } -bool AllowTupleTypeMismatch::diagnose(Expr *root, bool asNote) const { +bool AllowTupleTypeMismatch::diagnose(bool asNote) const { auto failure = TupleContextualFailure( - root, getConstraintSystem(), getFromType(), getToType(), getLocator()); + getConstraintSystem(), getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -272,9 +272,9 @@ AllowTupleTypeMismatch::create(ConstraintSystem &cs, Type lhs, Type rhs, return new (cs.getAllocator()) AllowTupleTypeMismatch(cs, lhs, rhs, locator); } -bool GenericArgumentsMismatch::diagnose(Expr *root, bool asNote) const { +bool GenericArgumentsMismatch::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); - GenericArgumentsMismatchFailure failure(root, cs, getFromType(), getToType(), + GenericArgumentsMismatchFailure failure(cs, getFromType(), getToType(), getMismatches(), getLocator()); return failure.diagnose(asNote); } @@ -289,7 +289,7 @@ GenericArgumentsMismatch *GenericArgumentsMismatch::create( GenericArgumentsMismatch(cs, actual, required, mismatches, locator); } -bool AutoClosureForwarding::diagnose(Expr *root, bool asNote) const { +bool AutoClosureForwarding::diagnose(bool asNote) const { auto failure = AutoClosureForwardingFailure(getConstraintSystem(), getLocator()); return failure.diagnose(asNote); @@ -300,8 +300,8 @@ AutoClosureForwarding *AutoClosureForwarding::create(ConstraintSystem &cs, return new (cs.getAllocator()) AutoClosureForwarding(cs, locator); } -bool AllowAutoClosurePointerConversion::diagnose(Expr *root, bool asNote) const { - auto failure = AutoClosurePointerConversionFailure(root, getConstraintSystem(), +bool AllowAutoClosurePointerConversion::diagnose(bool asNote) const { + auto failure = AutoClosurePointerConversionFailure(getConstraintSystem(), getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -314,8 +314,8 @@ AllowAutoClosurePointerConversion::create(ConstraintSystem &cs, Type pointeeType AllowAutoClosurePointerConversion(cs, pointeeType, pointerType, locator); } -bool RemoveUnwrap::diagnose(Expr *root, bool asNote) const { - auto failure = NonOptionalUnwrapFailure(root, getConstraintSystem(), BaseType, +bool RemoveUnwrap::diagnose(bool asNote) const { + auto failure = NonOptionalUnwrapFailure(getConstraintSystem(), BaseType, getLocator()); return failure.diagnose(asNote); } @@ -325,8 +325,8 @@ RemoveUnwrap *RemoveUnwrap::create(ConstraintSystem &cs, Type baseType, return new (cs.getAllocator()) RemoveUnwrap(cs, baseType, locator); } -bool InsertExplicitCall::diagnose(Expr *root, bool asNote) const { - auto failure = MissingCallFailure(root, getConstraintSystem(), getLocator()); +bool InsertExplicitCall::diagnose(bool asNote) const { + auto failure = MissingCallFailure(getConstraintSystem(), getLocator()); return failure.diagnose(asNote); } @@ -335,10 +335,10 @@ InsertExplicitCall *InsertExplicitCall::create(ConstraintSystem &cs, return new (cs.getAllocator()) InsertExplicitCall(cs, locator); } -bool UsePropertyWrapper::diagnose(Expr *root, bool asNote) const { +bool UsePropertyWrapper::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); auto failure = ExtraneousPropertyWrapperUnwrapFailure( - root, cs, Wrapped, UsingStorageWrapper, Base, Wrapper, getLocator()); + cs, Wrapped, UsingStorageWrapper, Base, Wrapper, getLocator()); return failure.diagnose(asNote); } @@ -351,10 +351,10 @@ UsePropertyWrapper *UsePropertyWrapper::create(ConstraintSystem &cs, cs, wrapped, usingStorageWrapper, base, wrapper, locator); } -bool UseWrappedValue::diagnose(Expr *root, bool asNote) const { +bool UseWrappedValue::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); auto failure = MissingPropertyWrapperUnwrapFailure( - root, cs, PropertyWrapper, usingStorageWrapper(), Base, Wrapper, + cs, PropertyWrapper, usingStorageWrapper(), Base, Wrapper, getLocator()); return failure.diagnose(asNote); } @@ -367,8 +367,8 @@ UseWrappedValue *UseWrappedValue::create(ConstraintSystem &cs, UseWrappedValue(cs, propertyWrapper, base, wrapper, locator); } -bool UseSubscriptOperator::diagnose(Expr *root, bool asNote) const { - auto failure = SubscriptMisuseFailure(root, getConstraintSystem(), getLocator()); +bool UseSubscriptOperator::diagnose(bool asNote) const { + auto failure = SubscriptMisuseFailure(getConstraintSystem(), getLocator()); return failure.diagnose(asNote); } @@ -377,8 +377,8 @@ UseSubscriptOperator *UseSubscriptOperator::create(ConstraintSystem &cs, return new (cs.getAllocator()) UseSubscriptOperator(cs, locator); } -bool DefineMemberBasedOnUse::diagnose(Expr *root, bool asNote) const { - auto failure = MissingMemberFailure(root, getConstraintSystem(), BaseType, +bool DefineMemberBasedOnUse::diagnose(bool asNote) const { + auto failure = MissingMemberFailure(getConstraintSystem(), BaseType, Name, getLocator()); return failure.diagnose(asNote); } @@ -398,16 +398,16 @@ AllowMemberRefOnExistential::create(ConstraintSystem &cs, Type baseType, AllowMemberRefOnExistential(cs, baseType, memberName, member, locator); } -bool AllowMemberRefOnExistential::diagnose(Expr *root, bool asNote) const { +bool AllowMemberRefOnExistential::diagnose(bool asNote) const { auto failure = - InvalidMemberRefOnExistential(root, getConstraintSystem(), getBaseType(), + InvalidMemberRefOnExistential(getConstraintSystem(), getBaseType(), getMemberName(), getLocator()); return failure.diagnose(asNote); } -bool AllowTypeOrInstanceMember::diagnose(Expr *root, bool asNote) const { +bool AllowTypeOrInstanceMember::diagnose(bool asNote) const { auto failure = AllowTypeOrInstanceMemberFailure( - root, getConstraintSystem(), getBaseType(), getMember(), getMemberName(), + getConstraintSystem(), getBaseType(), getMember(), getMemberName(), getLocator()); return failure.diagnose(asNote); } @@ -420,8 +420,8 @@ AllowTypeOrInstanceMember::create(ConstraintSystem &cs, Type baseType, AllowTypeOrInstanceMember(cs, baseType, member, usedName, locator); } -bool AllowInvalidPartialApplication::diagnose(Expr *root, bool asNote) const { - auto failure = PartialApplicationFailure(root, isWarning(), +bool AllowInvalidPartialApplication::diagnose(bool asNote) const { + auto failure = PartialApplicationFailure(isWarning(), getConstraintSystem(), getLocator()); return failure.diagnose(asNote); } @@ -433,23 +433,23 @@ AllowInvalidPartialApplication::create(bool isWarning, ConstraintSystem &cs, AllowInvalidPartialApplication(isWarning, cs, locator); } -bool AllowInvalidInitRef::diagnose(Expr *root, bool asNote) const { +bool AllowInvalidInitRef::diagnose(bool asNote) const { switch (Kind) { case RefKind::DynamicOnMetatype: { InvalidDynamicInitOnMetatypeFailure failure( - root, getConstraintSystem(), BaseType, Init, BaseRange, getLocator()); + getConstraintSystem(), BaseType, Init, BaseRange, getLocator()); return failure.diagnose(asNote); } case RefKind::ProtocolMetatype: { - InitOnProtocolMetatypeFailure failure(root, getConstraintSystem(), BaseType, + InitOnProtocolMetatypeFailure failure(getConstraintSystem(), BaseType, Init, IsStaticallyDerived, BaseRange, getLocator()); return failure.diagnose(asNote); } case RefKind::NonConstMetatype: { - ImplicitInitOnNonConstMetatypeFailure failure(root, getConstraintSystem(), + ImplicitInitOnNonConstMetatypeFailure failure(getConstraintSystem(), BaseType, Init, getLocator()); return failure.diagnose(asNote); } @@ -488,8 +488,8 @@ AllowInvalidInitRef::create(RefKind kind, ConstraintSystem &cs, Type baseTy, cs, kind, baseTy, init, isStaticallyDerived, baseRange, locator); } -bool AllowClosureParamDestructuring::diagnose(Expr *root, bool asNote) const { - ClosureParamDestructuringFailure failure(root, getConstraintSystem(), +bool AllowClosureParamDestructuring::diagnose(bool asNote) const { + ClosureParamDestructuringFailure failure(getConstraintSystem(), ContextualType, getLocator()); return failure.diagnose(asNote); } @@ -502,9 +502,9 @@ AllowClosureParamDestructuring::create(ConstraintSystem &cs, AllowClosureParamDestructuring(cs, contextualType, locator); } -bool AddMissingArguments::diagnose(Expr *root, bool asNote) const { +bool AddMissingArguments::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); - MissingArgumentsFailure failure(root, cs, getSynthesizedArguments(), + MissingArgumentsFailure failure(cs, getSynthesizedArguments(), getLocator()); return failure.diagnose(asNote); } @@ -518,8 +518,8 @@ AddMissingArguments::create(ConstraintSystem &cs, return new (mem) AddMissingArguments(cs, synthesizedArgs, locator); } -bool RemoveExtraneousArguments::diagnose(Expr *root, bool asNote) const { - ExtraneousArgumentsFailure failure(root, getConstraintSystem(), +bool RemoveExtraneousArguments::diagnose(bool asNote) const { + ExtraneousArgumentsFailure failure(getConstraintSystem(), ContextualType, getExtraArguments(), getLocator()); return failure.diagnose(asNote); @@ -554,8 +554,8 @@ RemoveExtraneousArguments *RemoveExtraneousArguments::create( RemoveExtraneousArguments(cs, contextualType, extraArgs, locator); } -bool MoveOutOfOrderArgument::diagnose(Expr *root, bool asNote) const { - OutOfOrderArgumentFailure failure(root, getConstraintSystem(), ArgIdx, +bool MoveOutOfOrderArgument::diagnose(bool asNote) const { + OutOfOrderArgumentFailure failure(getConstraintSystem(), ArgIdx, PrevArgIdx, Bindings, getLocator()); return failure.diagnose(asNote); } @@ -567,8 +567,8 @@ MoveOutOfOrderArgument *MoveOutOfOrderArgument::create( MoveOutOfOrderArgument(cs, argIdx, prevArgIdx, bindings, locator); } -bool AllowInaccessibleMember::diagnose(Expr *root, bool asNote) const { - InaccessibleMemberFailure failure(root, getConstraintSystem(), getMember(), +bool AllowInaccessibleMember::diagnose(bool asNote) const { + InaccessibleMemberFailure failure(getConstraintSystem(), getMember(), getLocator()); return failure.diagnose(asNote); } @@ -581,9 +581,8 @@ AllowInaccessibleMember::create(ConstraintSystem &cs, Type baseType, AllowInaccessibleMember(cs, baseType, member, name, locator); } -bool AllowAnyObjectKeyPathRoot::diagnose(Expr *root, bool asNote) const { - AnyObjectKeyPathRootFailure failure(root, getConstraintSystem(), - getLocator()); +bool AllowAnyObjectKeyPathRoot::diagnose(bool asNote) const { + AnyObjectKeyPathRootFailure failure(getConstraintSystem(), getLocator()); return failure.diagnose(asNote); } @@ -593,9 +592,8 @@ AllowAnyObjectKeyPathRoot::create(ConstraintSystem &cs, return new (cs.getAllocator()) AllowAnyObjectKeyPathRoot(cs, locator); } -bool TreatKeyPathSubscriptIndexAsHashable::diagnose(Expr *root, - bool asNote) const { - KeyPathSubscriptIndexHashableFailure failure(root, getConstraintSystem(), +bool TreatKeyPathSubscriptIndexAsHashable::diagnose(bool asNote) const { + KeyPathSubscriptIndexHashableFailure failure(getConstraintSystem(), NonConformingType, getLocator()); return failure.diagnose(asNote); } @@ -607,22 +605,22 @@ TreatKeyPathSubscriptIndexAsHashable::create(ConstraintSystem &cs, Type type, TreatKeyPathSubscriptIndexAsHashable(cs, type, locator); } -bool AllowInvalidRefInKeyPath::diagnose(Expr *root, bool asNote) const { +bool AllowInvalidRefInKeyPath::diagnose(bool asNote) const { switch (Kind) { case RefKind::StaticMember: { - InvalidStaticMemberRefInKeyPath failure(root, getConstraintSystem(), Member, + InvalidStaticMemberRefInKeyPath failure(getConstraintSystem(), Member, getLocator()); return failure.diagnose(asNote); } case RefKind::MutatingGetter: { InvalidMemberWithMutatingGetterInKeyPath failure( - root, getConstraintSystem(), Member, getLocator()); + getConstraintSystem(), Member, getLocator()); return failure.diagnose(asNote); } case RefKind::Method: { - InvalidMethodRefInKeyPath failure(root, getConstraintSystem(), Member, + InvalidMethodRefInKeyPath failure(getConstraintSystem(), Member, getLocator()); return failure.diagnose(asNote); } @@ -670,8 +668,8 @@ KeyPathContextualMismatch::create(ConstraintSystem &cs, Type lhs, Type rhs, KeyPathContextualMismatch(cs, lhs, rhs, locator); } -bool RemoveAddressOf::diagnose(Expr *root, bool asNote) const { - InvalidUseOfAddressOf failure(root, getConstraintSystem(), getFromType(), +bool RemoveAddressOf::diagnose(bool asNote) const { + InvalidUseOfAddressOf failure(getConstraintSystem(), getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -681,8 +679,8 @@ RemoveAddressOf *RemoveAddressOf::create(ConstraintSystem &cs, Type lhs, Type rh return new (cs.getAllocator()) RemoveAddressOf(cs, lhs, rhs, locator); } -bool RemoveReturn::diagnose(Expr *root, bool asNote) const { - ExtraneousReturnFailure failure(root, getConstraintSystem(), getLocator()); +bool RemoveReturn::diagnose(bool asNote) const { + ExtraneousReturnFailure failure(getConstraintSystem(), getLocator()); return failure.diagnose(asNote); } @@ -691,10 +689,9 @@ RemoveReturn *RemoveReturn::create(ConstraintSystem &cs, return new (cs.getAllocator()) RemoveReturn(cs, locator); } -bool CollectionElementContextualMismatch::diagnose(Expr *root, - bool asNote) const { +bool CollectionElementContextualMismatch::diagnose(bool asNote) const { CollectionElementContextualFailure failure( - root, getConstraintSystem(), getFromType(), getToType(), getLocator()); + getConstraintSystem(), getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -706,10 +703,9 @@ CollectionElementContextualMismatch::create(ConstraintSystem &cs, Type srcType, CollectionElementContextualMismatch(cs, srcType, dstType, locator); } -bool ExplicitlySpecifyGenericArguments::diagnose(Expr *root, - bool asNote) const { +bool ExplicitlySpecifyGenericArguments::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); - MissingGenericArgumentsFailure failure(root, cs, getParameters(), + MissingGenericArgumentsFailure failure(cs, getParameters(), getLocator()); return failure.diagnose(asNote); } @@ -751,16 +747,15 @@ SkipUnhandledConstructInFunctionBuilder::create(ConstraintSystem &cs, SkipUnhandledConstructInFunctionBuilder(cs, unhandled, builder, locator); } -bool SkipUnhandledConstructInFunctionBuilder::diagnose(Expr *root, - bool asNote) const { +bool SkipUnhandledConstructInFunctionBuilder::diagnose(bool asNote) const { SkipUnhandledConstructInFunctionBuilderFailure failure( - root, getConstraintSystem(), unhandled, builder, getLocator()); + getConstraintSystem(), unhandled, builder, getLocator()); return failure.diagnose(asNote); } -bool AllowMutatingMemberOnRValueBase::diagnose(Expr *root, bool asNote) const { +bool AllowMutatingMemberOnRValueBase::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); - MutatingMemberRefOnImmutableBase failure(root, cs, getMember(), getLocator()); + MutatingMemberRefOnImmutableBase failure(cs, getMember(), getLocator()); return failure.diagnose(asNote); } @@ -772,9 +767,9 @@ AllowMutatingMemberOnRValueBase::create(ConstraintSystem &cs, Type baseType, AllowMutatingMemberOnRValueBase(cs, baseType, member, name, locator); } -bool AllowTupleSplatForSingleParameter::diagnose(Expr *root, bool asNote) const { +bool AllowTupleSplatForSingleParameter::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); - InvalidTupleSplatWithSingleParameterFailure failure(root, cs, ParamType, + InvalidTupleSplatWithSingleParameterFailure failure(cs, ParamType, getLocator()); return failure.diagnose(asNote); } @@ -847,9 +842,9 @@ bool AllowTupleSplatForSingleParameter::attempt( return cs.recordFix(fix); } -bool DropThrowsAttribute::diagnose(Expr *root, bool asNote) const { +bool DropThrowsAttribute::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); - ThrowingFunctionConversionFailure failure(root, cs, getFromType(), + ThrowingFunctionConversionFailure failure(cs, getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -862,9 +857,9 @@ DropThrowsAttribute *DropThrowsAttribute::create(ConstraintSystem &cs, DropThrowsAttribute(cs, fromType, toType, locator); } -bool IgnoreContextualType::diagnose(Expr *root, bool asNote) const { +bool IgnoreContextualType::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); - ContextualFailure failure(root, cs, getFromType(), getToType(), getLocator()); + ContextualFailure failure(cs, getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -876,7 +871,7 @@ IgnoreContextualType *IgnoreContextualType::create(ConstraintSystem &cs, IgnoreContextualType(cs, resultTy, specifiedTy, locator); } -bool IgnoreAssignmentDestinationType::diagnose(Expr *root, bool asNote) const { +bool IgnoreAssignmentDestinationType::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); auto *AE = cast(getAnchor()); @@ -897,7 +892,7 @@ bool IgnoreAssignmentDestinationType::diagnose(Expr *root, bool asNote) const { : CTP_AssignSource; AssignmentTypeMismatchFailure failure( - root, cs, CTP, getFromType(), getToType(), + cs, CTP, getFromType(), getToType(), cs.getConstraintLocator(AE->getSrc(), LocatorPathElt::ContextualType())); return failure.diagnose(asNote); } @@ -910,9 +905,9 @@ IgnoreAssignmentDestinationType::create(ConstraintSystem &cs, Type sourceTy, IgnoreAssignmentDestinationType(cs, sourceTy, destTy, locator); } -bool AllowInOutConversion::diagnose(Expr *root, bool asNote) const { +bool AllowInOutConversion::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); - InOutConversionFailure failure(root, cs, getFromType(), getToType(), + InOutConversionFailure failure(cs, getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -970,9 +965,9 @@ ExpandArrayIntoVarargs::attempt(ConstraintSystem &cs, Type argType, return nullptr; } -bool ExpandArrayIntoVarargs::diagnose(Expr *root, bool asNote) const { +bool ExpandArrayIntoVarargs::diagnose(bool asNote) const { ExpandArrayIntoVarargsFailure failure( - root, getConstraintSystem(), getFromType(), getToType(), getLocator()); + getConstraintSystem(), getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -1004,9 +999,9 @@ UseValueTypeOfRawRepresentative::attempt(ConstraintSystem &cs, Type argType, return nullptr; } -bool AllowArgumentMismatch::diagnose(Expr *root, bool asNote) const { +bool AllowArgumentMismatch::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); - ArgumentMismatchFailure failure(root, cs, getFromType(), getToType(), + ArgumentMismatchFailure failure(cs, getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -1018,8 +1013,8 @@ AllowArgumentMismatch::create(ConstraintSystem &cs, Type argType, AllowArgumentMismatch(cs, argType, paramType, locator); } -bool RemoveInvalidCall::diagnose(Expr *root, bool asNote) const { - ExtraneousCallFailure failure(root, getConstraintSystem(), getLocator()); +bool RemoveInvalidCall::diagnose(bool asNote) const { + ExtraneousCallFailure failure(getConstraintSystem(), getLocator()); return failure.diagnose(asNote); } @@ -1028,9 +1023,9 @@ RemoveInvalidCall *RemoveInvalidCall::create(ConstraintSystem &cs, return new (cs.getAllocator()) RemoveInvalidCall(cs, locator); } -bool AllowInvalidUseOfTrailingClosure::diagnose(Expr *expr, bool asNote) const { +bool AllowInvalidUseOfTrailingClosure::diagnose(bool asNote) const { auto &cs = getConstraintSystem(); - InvalidUseOfTrailingClosure failure(expr, cs, getFromType(), getToType(), + InvalidUseOfTrailingClosure failure(cs, getFromType(), getToType(), getLocator()); return failure.diagnose(asNote); } @@ -1043,9 +1038,9 @@ AllowInvalidUseOfTrailingClosure::create(ConstraintSystem &cs, Type argType, AllowInvalidUseOfTrailingClosure(cs, argType, paramType, locator); } -bool TreatEphemeralAsNonEphemeral::diagnose(Expr *root, bool asNote) const { +bool TreatEphemeralAsNonEphemeral::diagnose(bool asNote) const { NonEphemeralConversionFailure failure( - root, getConstraintSystem(), getLocator(), getFromType(), getToType(), + getConstraintSystem(), getLocator(), getFromType(), getToType(), ConversionKind, isWarning()); return failure.diagnose(asNote); } diff --git a/lib/Sema/CSFix.h b/lib/Sema/CSFix.h index 26dfc80bab30e..2f5b11a99c604 100644 --- a/lib/Sema/CSFix.h +++ b/lib/Sema/CSFix.h @@ -254,7 +254,7 @@ class ConstraintFix { /// Diagnose a failure associated with this fix given /// root expression and information from constraint system. - virtual bool diagnose(Expr *root, bool asNote = false) const = 0; + virtual bool diagnose(bool asNote = false) const = 0; virtual ConstraintFix *coalescedWith(ArrayRef fixes) { return this; @@ -290,7 +290,7 @@ class ForceOptional final : public ConstraintFix { public: std::string getName() const override { return "force optional"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static ForceOptional *create(ConstraintSystem &cs, Type baseType, Type unwrappedType, ConstraintLocator *locator); @@ -312,7 +312,7 @@ class UnwrapOptionalBase final : public ConstraintFix { return "unwrap optional base of member lookup"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static UnwrapOptionalBase *create(ConstraintSystem &cs, DeclName member, ConstraintLocator *locator); @@ -330,7 +330,7 @@ class TreatRValueAsLValue final : public ConstraintFix { public: std::string getName() const override { return "treat rvalue as lvalue"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static TreatRValueAsLValue *create(ConstraintSystem &cs, ConstraintLocator *locator); @@ -350,7 +350,7 @@ class MarkExplicitlyEscaping final : public ConstraintFix { public: std::string getName() const override { return "add @escaping"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static MarkExplicitlyEscaping *create(ConstraintSystem &cs, ConstraintLocator *locator, @@ -382,7 +382,7 @@ class RelabelArguments final return {getTrailingObjects(), NumLabels}; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static RelabelArguments *create(ConstraintSystem &cs, llvm::ArrayRef correctLabels, @@ -415,7 +415,7 @@ class MissingConformance final : public ConstraintFix { return "add missing protocol conformance"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static MissingConformance *forRequirement(ConstraintSystem &cs, Type type, Type protocolType, @@ -445,7 +445,7 @@ class SkipSameTypeRequirement final : public ConstraintFix { return "skip same-type generic requirement"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; Type lhsType() { return LHS; } Type rhsType() { return RHS; } @@ -469,7 +469,7 @@ class SkipSuperclassRequirement final : public ConstraintFix { return "skip superclass generic requirement"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; Type subclassType() { return LHS; } Type superclassType() { return RHS; } @@ -504,7 +504,7 @@ class ContextualMismatch : public ConstraintFix { Type getFromType() const { return LHS; } Type getToType() const { return RHS; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static ContextualMismatch *create(ConstraintSystem &cs, Type lhs, Type rhs, ConstraintLocator *locator); @@ -522,7 +522,7 @@ class DropThrowsAttribute final : public ContextualMismatch { public: std::string getName() const override { return "drop 'throws' attribute"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static DropThrowsAttribute *create(ConstraintSystem &cs, FunctionType *fromType, @@ -540,7 +540,7 @@ class ForceDowncast final : public ContextualMismatch { public: std::string getName() const override; - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static ForceDowncast *create(ConstraintSystem &cs, Type fromType, Type toType, ConstraintLocator *locator); @@ -555,7 +555,7 @@ class AddAddressOf final : public ContextualMismatch { public: std::string getName() const override { return "add address-of"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AddAddressOf *create(ConstraintSystem &cs, Type argTy, Type paramTy, ConstraintLocator *locator); @@ -571,7 +571,7 @@ class RemoveAddressOf final : public ContextualMismatch { return "remove extraneous use of `&`"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static RemoveAddressOf *create(ConstraintSystem &cs, Type lhs, Type rhs, ConstraintLocator *locator); @@ -613,7 +613,7 @@ class GenericArgumentsMismatch final return {getTrailingObjects(), NumMismatches}; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static GenericArgumentsMismatch *create(ConstraintSystem &cs, Type actual, Type required, @@ -668,7 +668,7 @@ class AutoClosureForwarding final : public ConstraintFix { public: std::string getName() const override { return "fix @autoclosure forwarding"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AutoClosureForwarding *create(ConstraintSystem &cs, ConstraintLocator *locator); @@ -686,7 +686,7 @@ class AllowAutoClosurePointerConversion final : public ContextualMismatch { return "allow pointer conversion for autoclosure result type"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AllowAutoClosurePointerConversion *create(ConstraintSystem &cs, Type pointeeType, @@ -705,7 +705,7 @@ class RemoveUnwrap final : public ConstraintFix { return "remove unwrap operator `!` or `?`"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static RemoveUnwrap *create(ConstraintSystem &cs, Type baseType, ConstraintLocator *locator); @@ -720,7 +720,7 @@ class InsertExplicitCall final : public ConstraintFix { return "insert explicit `()` to make a call"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static InsertExplicitCall *create(ConstraintSystem &cs, ConstraintLocator *locator); @@ -744,7 +744,7 @@ class UsePropertyWrapper final : public ConstraintFix { return "insert '$' or '_' to use property wrapper type instead of wrapped type"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static UsePropertyWrapper *create(ConstraintSystem &cs, VarDecl *wrapped, bool usingStorageWrapper, Type base, @@ -771,7 +771,7 @@ class UseWrappedValue final : public ConstraintFix { return "remove '$' or _ to use wrapped type instead of wrapper type"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static UseWrappedValue *create(ConstraintSystem &cs, VarDecl *propertyWrapper, Type base, Type wrapper, @@ -787,7 +787,7 @@ class UseSubscriptOperator final : public ConstraintFix { return "replace '.subscript(...)' with subscript operator"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static UseSubscriptOperator *create(ConstraintSystem &cs, ConstraintLocator *locator); @@ -810,7 +810,7 @@ class DefineMemberBasedOnUse final : public ConstraintFix { "' based on its use"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static DefineMemberBasedOnUse *create(ConstraintSystem &cs, Type baseType, DeclName member, @@ -852,7 +852,7 @@ class AllowMemberRefOnExistential final : public AllowInvalidMemberRef { "' on value of protocol type"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AllowMemberRefOnExistential *create(ConstraintSystem &cs, Type baseType, ValueDecl *member, @@ -874,7 +874,7 @@ class AllowTypeOrInstanceMember final : public AllowInvalidMemberRef { return "allow access to instance member on type or a type member on instance"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AllowTypeOrInstanceMember *create(ConstraintSystem &cs, Type baseType, ValueDecl *member, DeclName usedName, @@ -892,7 +892,7 @@ class AllowInvalidPartialApplication final : public ConstraintFix { return "allow partially applied 'mutating' method"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AllowInvalidPartialApplication *create(bool isWarning, ConstraintSystem &cs, @@ -923,7 +923,7 @@ class AllowInvalidInitRef final : public ConstraintFix { return "allow invalid initializer reference"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AllowInvalidInitRef * dynamicOnMetatype(ConstraintSystem &cs, Type baseTy, ConstructorDecl *init, @@ -961,7 +961,7 @@ class AllowTupleTypeMismatch final : public ContextualMismatch { return "fix tuple mismatches in type and arity"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; }; class AllowMutatingMemberOnRValueBase final : public AllowInvalidMemberRef { @@ -976,7 +976,7 @@ class AllowMutatingMemberOnRValueBase final : public AllowInvalidMemberRef { return "allow `mutating` method on r-value base"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AllowMutatingMemberOnRValueBase * create(ConstraintSystem &cs, Type baseType, ValueDecl *member, DeclName name, @@ -997,7 +997,7 @@ class AllowClosureParamDestructuring final : public ConstraintFix { return "allow closure parameter destructuring"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AllowClosureParamDestructuring *create(ConstraintSystem &cs, FunctionType *contextualType, @@ -1030,7 +1030,7 @@ class AddMissingArguments final return {getTrailingObjects(), NumSynthesized}; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AddMissingArguments *create(ConstraintSystem &cs, llvm::ArrayRef synthesizedArgs, @@ -1070,7 +1070,7 @@ class RemoveExtraneousArguments final return {getTrailingObjects(), NumExtraneous}; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; /// FIXME(diagnostics): Once `resolveDeclRefExpr` is gone this /// logic would be obsolete. @@ -1111,7 +1111,7 @@ class MoveOutOfOrderArgument final : public ConstraintFix { return "move out-of-order argument to correct position"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static MoveOutOfOrderArgument *create(ConstraintSystem &cs, unsigned argIdx, @@ -1132,7 +1132,7 @@ class AllowInaccessibleMember final : public AllowInvalidMemberRef { return "allow inaccessible member reference"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AllowInaccessibleMember *create(ConstraintSystem &cs, Type baseType, ValueDecl *member, DeclName name, @@ -1149,7 +1149,7 @@ class AllowAnyObjectKeyPathRoot final : public ConstraintFix { return "allow anyobject as root type for a keypath"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AllowAnyObjectKeyPathRoot *create(ConstraintSystem &cs, ConstraintLocator *locator); @@ -1169,7 +1169,7 @@ class TreatKeyPathSubscriptIndexAsHashable final : public ConstraintFix { return "treat keypath subscript index as conforming to Hashable"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static TreatKeyPathSubscriptIndexAsHashable * create(ConstraintSystem &cs, Type type, ConstraintLocator *locator); @@ -1208,7 +1208,7 @@ class AllowInvalidRefInKeyPath final : public ConstraintFix { llvm_unreachable("covered switch"); } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; /// Determine whether give reference requires a fix and produce one. static AllowInvalidRefInKeyPath * @@ -1227,7 +1227,7 @@ class RemoveReturn final : public ConstraintFix { public: std::string getName() const override { return "remove or omit return type"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static RemoveReturn *create(ConstraintSystem &cs, ConstraintLocator *locator); }; @@ -1242,7 +1242,7 @@ class CollectionElementContextualMismatch final : public ContextualMismatch { return "fix collection element contextual mismatch"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static CollectionElementContextualMismatch * create(ConstraintSystem &cs, Type srcType, Type dstType, @@ -1280,7 +1280,7 @@ class ExplicitlySpecifyGenericArguments final return {getTrailingObjects(), NumMissingParams}; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; ConstraintFix *coalescedWith(ArrayRef fixes) override; @@ -1315,7 +1315,7 @@ class SkipUnhandledConstructInFunctionBuilder final : public ConstraintFix { return "skip unhandled constructs when applying a function builder"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static SkipUnhandledConstructInFunctionBuilder * create(ConstraintSystem &cs, UnhandledNode unhandledNode, @@ -1337,7 +1337,7 @@ class AllowTupleSplatForSingleParameter final : public ConstraintFix { return "allow single parameter tuple splat"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; /// Apply this fix to given arguments/parameters and return `true` /// this fix is not applicable and solver can't continue, `false` @@ -1358,7 +1358,7 @@ class IgnoreContextualType : public ContextualMismatch { return "ignore specified contextual type"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static IgnoreContextualType *create(ConstraintSystem &cs, Type resultTy, Type specifiedTy, @@ -1375,7 +1375,7 @@ class IgnoreAssignmentDestinationType final : public ContextualMismatch { return "ignore type of the assignment destination"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static IgnoreAssignmentDestinationType *create(ConstraintSystem &cs, Type sourceTy, Type destTy, @@ -1395,7 +1395,7 @@ class AllowInOutConversion final : public ContextualMismatch { return "allow conversions between argument/parameter marked as `inout`"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AllowInOutConversion *create(ConstraintSystem &cs, Type argType, Type paramType, @@ -1419,7 +1419,7 @@ class AllowArgumentMismatch : public ContextualMismatch { return "allow argument to parameter type conversion mismatch"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static AllowArgumentMismatch *create(ConstraintSystem &cs, Type argType, Type paramType, @@ -1438,7 +1438,7 @@ class ExpandArrayIntoVarargs final : public AllowArgumentMismatch { return "cannot pass Array elements as variadic arguments"; } - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static ExpandArrayIntoVarargs *attempt(ConstraintSystem &cs, Type argType, Type paramType, @@ -1488,7 +1488,7 @@ class CoerceToCheckedCast final : public ContextualMismatch { public: std::string getName() const { return "as to as!"; } - bool diagnose(Expr *root, bool asNote = false) const; + bool diagnose(bool asNote = false) const; static CoerceToCheckedCast *attempt(ConstraintSystem &cs, Type fromType, Type toType, ConstraintLocator *locator); @@ -1503,7 +1503,7 @@ class RemoveInvalidCall final : public ConstraintFix { return "remove extraneous call from value of non-function type"; } - bool diagnose(Expr *root, bool asNote = false) const; + bool diagnose(bool asNote = false) const; static RemoveInvalidCall *create(ConstraintSystem &cs, ConstraintLocator *locator); @@ -1520,7 +1520,7 @@ class AllowInvalidUseOfTrailingClosure final : public AllowArgumentMismatch { return "allow invalid use of trailing closure"; } - bool diagnose(Expr *root, bool asNote = false) const; + bool diagnose(bool asNote = false) const; static AllowInvalidUseOfTrailingClosure *create(ConstraintSystem &cs, Type argType, Type paramType, @@ -1542,7 +1542,7 @@ class TreatEphemeralAsNonEphemeral final : public AllowArgumentMismatch { ConversionRestrictionKind getConversionKind() const { return ConversionKind; } std::string getName() const override; - bool diagnose(Expr *root, bool asNote = false) const override; + bool diagnose(bool asNote = false) const override; static TreatEphemeralAsNonEphemeral * create(ConstraintSystem &cs, ConstraintLocator *locator, Type srcType, diff --git a/lib/Sema/CalleeCandidateInfo.cpp b/lib/Sema/CalleeCandidateInfo.cpp index f55e148002d66..16cfd53f9afd5 100644 --- a/lib/Sema/CalleeCandidateInfo.cpp +++ b/lib/Sema/CalleeCandidateInfo.cpp @@ -968,7 +968,7 @@ bool CalleeCandidateInfo::diagnoseSimpleErrors(const Expr *E) { assert(decl && "Only decl-based candidates may be marked inaccessible"); InaccessibleMemberFailure failure( - nullptr, CS, decl, CS.getConstraintLocator(const_cast(E))); + CS, decl, CS.getConstraintLocator(const_cast(E))); auto diagnosed = failure.diagnoseAsError(); assert(diagnosed && "failed to produce expected diagnostic"); diff --git a/lib/Sema/ConstraintSystem.cpp b/lib/Sema/ConstraintSystem.cpp index 3649416810a23..2da9a5dd3957a 100644 --- a/lib/Sema/ConstraintSystem.cpp +++ b/lib/Sema/ConstraintSystem.cpp @@ -2627,7 +2627,7 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes( ConstraintSystem::SolverScope scope(*this); applySolution(*viable.first); // All of the solutions supposed to produce a "candidate" note. - diagnosed &= viable.second->diagnose(expr, /*asNote*/ true); + diagnosed &= viable.second->diagnose(/*asNote*/ true); } // If not all of the fixes produced a note, we can't diagnose this. @@ -2752,7 +2752,7 @@ bool ConstraintSystem::diagnoseAmbiguity(Expr *expr, : diag::ambiguous_decl_ref, name); - TrailingClosureAmbiguityFailure failure(expr, *this, anchor, + TrailingClosureAmbiguityFailure failure(*this, anchor, overload.choices); if (failure.diagnoseAsNote()) return true; From 51cb33336384a72aea4a101f3f2320a2d4868ac3 Mon Sep 17 00:00:00 2001 From: Doug Gregor Date: Fri, 8 Nov 2019 22:47:27 -0800 Subject: [PATCH 8/8] [Constraint system] Fall back to baseCS when looking for an expression's parent --- lib/Sema/ConstraintSystem.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/Sema/ConstraintSystem.h b/lib/Sema/ConstraintSystem.h index 463c30c028964..94fb9a377cac4 100644 --- a/lib/Sema/ConstraintSystem.h +++ b/lib/Sema/ConstraintSystem.h @@ -1979,7 +1979,13 @@ class ConstraintSystem { /// Lookup and return parent associated with given expression. Expr *getParentExpr(Expr *expr) const { auto e = ExprWeights.find(expr); - return e != ExprWeights.end() ? e->second.second : nullptr; + if (e != ExprWeights.end()) + return e->second.second; + + if (baseCS && baseCS != this) + return baseCS->getParentExpr(expr); + + return nullptr; } /// Returns a locator describing the callee for the anchor of a given locator.