Skip to content

Commit ece84b1

Browse files
committed
[Diagnostics] Adjust ConstraintFix::diagnoseForAmbiguity to take an array
ref of pairs rather than two parallel arrays.
1 parent 6375481 commit ece84b1

File tree

3 files changed

+31
-31
lines changed

3 files changed

+31
-31
lines changed

lib/Sema/CSFix.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,15 +489,13 @@ bool DefineMemberBasedOnUse::diagnose(const Solution &solution,
489489
}
490490

491491
bool
492-
DefineMemberBasedOnUse::diagnoseForAmbiguity(ArrayRef<Solution> solutions,
493-
ArrayRef<ConstraintFix *> fixes) const {
492+
DefineMemberBasedOnUse::diagnoseForAmbiguity(CommonFixesArray commonFixes) const {
494493
Type concreteBaseType;
495-
for (unsigned i = 0; i < solutions.size(); ++i) {
496-
const auto *fix = fixes[i]->getAs<DefineMemberBasedOnUse>();
497-
const auto &solution = solutions[i];
498-
assert(llvm::find(solution.Fixes, fix) != solution.Fixes.end());
494+
for (const auto &solutionAndFix : commonFixes) {
495+
const auto *solution = solutionAndFix.first;
496+
const auto *fix = solutionAndFix.second->getAs<DefineMemberBasedOnUse>();
499497

500-
auto baseType = solution.simplifyType(fix->BaseType);
498+
auto baseType = solution->simplifyType(fix->BaseType);
501499
if (!concreteBaseType)
502500
concreteBaseType = baseType;
503501

@@ -508,7 +506,7 @@ DefineMemberBasedOnUse::diagnoseForAmbiguity(ArrayRef<Solution> solutions,
508506
}
509507
}
510508

511-
return diagnose(solutions.front());
509+
return diagnose(*commonFixes.front().first);
512510
}
513511

514512
DefineMemberBasedOnUse *

lib/Sema/CSFix.h

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -291,8 +291,10 @@ class ConstraintFix {
291291
virtual bool diagnose(const Solution &solution,
292292
bool asNote = false) const = 0;
293293

294-
virtual bool diagnoseForAmbiguity(ArrayRef<Solution> solutions,
295-
ArrayRef<ConstraintFix *> fixes) const {
294+
using CommonFixesArray =
295+
ArrayRef<std::pair<const Solution *, const ConstraintFix *>>;
296+
297+
virtual bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const {
296298
return false;
297299
}
298300

@@ -850,8 +852,7 @@ class DefineMemberBasedOnUse final : public ConstraintFix {
850852

851853
bool diagnose(const Solution &solution, bool asNote = false) const override;
852854

853-
bool diagnoseForAmbiguity(ArrayRef<Solution> solutions,
854-
ArrayRef<ConstraintFix *> fixes) const override;
855+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override;
855856

856857
static DefineMemberBasedOnUse *create(ConstraintSystem &cs, Type baseType,
857858
DeclNameRef member, bool alreadyDiagnosed,
@@ -1125,9 +1126,8 @@ class AddMissingArguments final
11251126

11261127
bool diagnose(const Solution &solution, bool asNote = false) const override;
11271128

1128-
bool diagnoseForAmbiguity(ArrayRef<Solution> solutions,
1129-
ArrayRef<ConstraintFix *> fixes) const override {
1130-
return diagnose(solutions.front());
1129+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
1130+
return diagnose(*commonFixes.front().first);
11311131
}
11321132

11331133
static AddMissingArguments *create(ConstraintSystem &cs,
@@ -1170,9 +1170,8 @@ class RemoveExtraneousArguments final
11701170

11711171
bool diagnose(const Solution &solution, bool asNote = false) const override;
11721172

1173-
bool diagnoseForAmbiguity(ArrayRef<Solution> solutions,
1174-
ArrayRef<ConstraintFix *> fixes) const override {
1175-
return diagnose(solutions.front());
1173+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
1174+
return diagnose(*commonFixes.front().first);
11761175
}
11771176

11781177
/// FIXME(diagnostics): Once `resolveDeclRefExpr` is gone this
@@ -1381,9 +1380,8 @@ class DefaultGenericArgument final : public ConstraintFix {
13811380

13821381
bool diagnose(const Solution &solution, bool asNote = false) const override;
13831382

1384-
bool diagnoseForAmbiguity(ArrayRef<Solution> solutions,
1385-
ArrayRef<ConstraintFix *> fixes) const override {
1386-
return diagnose(solutions.front());
1383+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
1384+
return diagnose(*commonFixes.front().first);
13871385
}
13881386

13891387
static DefaultGenericArgument *create(ConstraintSystem &cs,
@@ -1457,9 +1455,8 @@ class IgnoreContextualType : public ContextualMismatch {
14571455

14581456
bool diagnose(const Solution &solution, bool asNote = false) const override;
14591457

1460-
bool diagnoseForAmbiguity(ArrayRef<Solution> solutions,
1461-
ArrayRef<ConstraintFix *> fixes) const override {
1462-
return diagnose(solutions.front());
1458+
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
1459+
return diagnose(*commonFixes.front().first);
14631460
}
14641461

14651462
static IgnoreContextualType *create(ConstraintSystem &cs, Type resultTy,

lib/Sema/ConstraintSystem.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2947,12 +2947,15 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
29472947
return true;
29482948

29492949
// Collect aggregated fixes from all solutions
2950-
llvm::SmallMapVector<std::pair<ConstraintLocator *, FixKind>,
2951-
llvm::TinyPtrVector<ConstraintFix *>, 4>
2950+
using LocatorAndKind = std::pair<ConstraintLocator *, FixKind>;
2951+
using SolutionAndFix = std::pair<const Solution *, const ConstraintFix *>;
2952+
llvm::SmallMapVector<LocatorAndKind, llvm::SmallVector<SolutionAndFix, 4>, 4>
29522953
aggregatedFixes;
29532954
for (const auto &solution : solutions) {
2954-
for (auto *fix : solution.Fixes)
2955-
aggregatedFixes[{fix->getLocator(), fix->getKind()}].push_back(fix);
2955+
for (const auto *fix : solution.Fixes) {
2956+
LocatorAndKind key(fix->getLocator(), fix->getKind());
2957+
aggregatedFixes[key].emplace_back(&solution, fix);
2958+
}
29562959
}
29572960

29582961
// If there is an overload difference, let's see if there's a common callee
@@ -2983,9 +2986,11 @@ bool ConstraintSystem::diagnoseAmbiguityWithFixes(
29832986
bool diagnosed = false;
29842987
for (auto fixes: aggregatedFixes) {
29852988
// A common fix must appear in all solutions
2986-
if (fixes.second.size() != solutions.size()) continue;
2987-
diagnosed |= fixes.second.front()->diagnoseForAmbiguity(solutions,
2988-
fixes.second);
2989+
auto &commonFixes = fixes.second;
2990+
if (commonFixes.size() != solutions.size()) continue;
2991+
2992+
auto *firstFix = commonFixes.front().second;
2993+
diagnosed |= firstFix->diagnoseForAmbiguity(commonFixes);
29892994
}
29902995
return diagnosed;
29912996
}

0 commit comments

Comments
 (0)