Skip to content

Commit 09a5b99

Browse files
committed
[ConstraintSystem] Run salvage even if diagnostics are suppressed
There are some situations where the solver is able to find a valid solution only during `salvage` (mostly but not limited to unavailable declarations), which means that we need to keep running `salvage` even if the diagnostics are suppressed until the underlying issues in the normal solving mode are fixed. One of the issues: ```swift extension Unmanaged { @inline(__always) internal static func passRetained(_ instance: __owned Instance?) -> Self? { guard let instance = instance else { return nil } return .passRetained(instance) } } ``` `.passRetained(instance)` is ambiguous during normal solving but is able to find a solution during `salvage` because it attemtps more type bindings. Resolves: rdar://119001449
1 parent d270dad commit 09a5b99

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

lib/Sema/CSSolver.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,14 +1515,6 @@ ConstraintSystem::solve(SyntacticElementTarget &target,
15151515
LLVM_FALLTHROUGH;
15161516

15171517
case SolutionResult::UndiagnosedError:
1518-
/// If we have a SolutionCallback, we are inspecting constraint system
1519-
/// solutions directly and thus also want to receive ambiguous solutions.
1520-
/// Hence always run the second (salvaging) stage.
1521-
if (shouldSuppressDiagnostics() && !Context.SolutionCallback) {
1522-
solution.markAsDiagnosed();
1523-
return llvm::None;
1524-
}
1525-
15261518
if (stage == 1) {
15271519
diagnoseFailureFor(target);
15281520
reportSolutionsToSolutionCallback(solution);

lib/Sema/ConstraintSystem.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4389,6 +4389,10 @@ SolutionResult ConstraintSystem::salvage() {
43894389
return SolutionResult::forSolved(std::move(viable[0]));
43904390
}
43914391

4392+
if (shouldSuppressDiagnostics())
4393+
return viable.empty() ? SolutionResult::forUndiagnosedError()
4394+
: SolutionResult::forAmbiguous(viable);
4395+
43924396
// FIXME: If we were able to actually fix things along the way,
43934397
// we may have to hunt for the best solution. For now, we don't care.
43944398

@@ -5228,7 +5232,7 @@ static bool diagnoseContextualFunctionCallGenericAmbiguity(
52285232

52295233
bool ConstraintSystem::diagnoseAmbiguityWithFixes(
52305234
SmallVectorImpl<Solution> &solutions) {
5231-
if (solutions.empty())
5235+
if (solutions.empty() || shouldSuppressDiagnostics())
52325236
return false;
52335237

52345238
SolutionDiff solutionDiff(solutions);

0 commit comments

Comments
 (0)