Skip to content

Commit e631a37

Browse files
committed
[ConstraintSystem] Replace Fix with ConstraintFix throughout solver
1 parent 1983431 commit e631a37

File tree

8 files changed

+155
-236
lines changed

8 files changed

+155
-236
lines changed

lib/Sema/CSApply.cpp

Lines changed: 5 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -7761,21 +7761,20 @@ Expr *ConstraintSystem::coerceToRValue(Expr *expr) {
77617761
/// Emit the fixes computed as part of the solution, returning true if we were
77627762
/// able to emit an error message, or false if none of the fixits worked out.
77637763
bool ConstraintSystem::applySolutionFixes(Expr *E, const Solution &solution) {
7764-
llvm::SmallDenseMap<Expr *,
7765-
SmallVector<std::pair<Fix, ConstraintLocator *>, 4>>
7764+
llvm::SmallDenseMap<Expr *, SmallVector<const ConstraintFix *, 4>>
77667765
fixesPerExpr;
77677766

7768-
for (const auto &fix : solution.Fixes)
7769-
fixesPerExpr[fix.second->getAnchor()].push_back(fix);
7767+
for (auto *fix : solution.Fixes)
7768+
fixesPerExpr[fix->getAnchor()].push_back(fix);
77707769

77717770
auto diagnoseExprFailures = [&](Expr *expr) -> bool {
77727771
auto fixes = fixesPerExpr.find(expr);
77737772
if (fixes == fixesPerExpr.end())
77747773
return false;
77757774

77767775
bool diagnosed = false;
7777-
for (auto &fix : fixes->second)
7778-
diagnosed |= applySolutionFix(E, solution, fix);
7776+
for (const auto *fix : fixes->second)
7777+
diagnosed |= fix->diagnose(E, solution);
77797778
return diagnosed;
77807779
};
77817780

@@ -7792,86 +7791,6 @@ bool ConstraintSystem::applySolutionFixes(Expr *E, const Solution &solution) {
77927791
return diagnosed;
77937792
}
77947793

7795-
/// \brief Apply the specified Fix to this solution, producing a fix-it hint
7796-
/// diagnostic for it and returning true. If the fix-it hint turned out to be
7797-
/// bogus, this returns false and doesn't emit anything.
7798-
bool ConstraintSystem::applySolutionFix(
7799-
Expr *expr, const Solution &solution,
7800-
std::pair<Fix, ConstraintLocator *> &fix) {
7801-
// Some fixes need more information from the locator.
7802-
ConstraintLocator *locator = fix.second;
7803-
7804-
// In the case of us having applied a type member constraint against a
7805-
// synthesized type variable during diagnostic generation, we may not have
7806-
// a valid locator.
7807-
if (!locator)
7808-
return false;
7809-
7810-
switch (fix.first.getKind()) {
7811-
case FixKind::ForceOptional: {
7812-
MissingOptionalUnwrapFailure failure(expr, solution, locator);
7813-
return failure.diagnose();
7814-
}
7815-
7816-
case FixKind::UnwrapOptionalBase: {
7817-
auto memberName = fix.first.getDeclNameArgument(*this);
7818-
bool resultIsOptional =
7819-
fix.first.isUnwrapOptionalBaseByOptionalChaining(*this);
7820-
MemberAccessOnOptionalBaseFailure failure(expr, solution, locator,
7821-
memberName, resultIsOptional);
7822-
return failure.diagnose();
7823-
}
7824-
7825-
case FixKind::ForceDowncast: {
7826-
MissingExplicitConversionFailure failure(expr, solution, locator,
7827-
fix.first.getTypeArgument(*this));
7828-
return failure.diagnose();
7829-
}
7830-
7831-
case FixKind::AddressOf: {
7832-
MissingAddressOfFailure failure(expr, solution, locator);
7833-
return failure.diagnose();
7834-
}
7835-
7836-
case FixKind::CoerceToCheckedCast: {
7837-
MissingForcedDowncastFailure failure(expr, solution, locator);
7838-
return failure.diagnose();
7839-
}
7840-
7841-
case FixKind::ExplicitlyEscaping: {
7842-
NoEscapeFuncToTypeConversionFailure failure(expr, solution, locator);
7843-
return failure.diagnose();
7844-
}
7845-
7846-
case FixKind::ExplicitlyEscapingToAny: {
7847-
NoEscapeFuncToTypeConversionFailure failure(expr, solution, locator,
7848-
getASTContext().TheAnyType);
7849-
return failure.diagnose();
7850-
}
7851-
7852-
case FixKind::RelabelArguments: {
7853-
LabelingFailure failure(solution, fix.second,
7854-
fix.first.getArgumentLabels(*this));
7855-
return failure.diagnose();
7856-
}
7857-
7858-
case FixKind::AddConformance: {
7859-
auto *anchor = locator->getAnchor();
7860-
auto &reqLoc = locator->getPath().back();
7861-
MissingConformanceFailure failure(
7862-
expr, solution, fix.second,
7863-
MissingConformances[{anchor, reqLoc.getValue()}]);
7864-
return failure.diagnose();
7865-
}
7866-
}
7867-
7868-
// FIXME: It would be really nice to emit a follow-up note showing where
7869-
// we got the other type information from, e.g., the parameter we're
7870-
// initializing.
7871-
return false;
7872-
}
7873-
7874-
78757794
/// \brief Apply a given solution to the expression, producing a fully
78767795
/// type-checked expression.
78777796
Expr *ConstraintSystem::applySolution(Solution &solution, Expr *expr,

lib/Sema/CSDiagnostics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ class MissingConformanceFailure final : public RequirementFailure {
155155
public:
156156
MissingConformanceFailure(Expr *expr, const Solution &solution,
157157
ConstraintLocator *locator,
158-
std::pair<TypeBase *, ProtocolDecl *> conformance)
158+
std::pair<Type, ProtocolDecl *> conformance)
159159
: RequirementFailure(expr, solution, locator),
160160
NonConformingType(conformance.first), Protocol(conformance.second) {}
161161

0 commit comments

Comments
 (0)