Skip to content

Commit 8de1763

Browse files
committed
[ConstraintSystem] Record both viable and unviable candidates produced by lookup
Try to form a "complete" set of overload choices based on lookup results, which means include both viable and unviable-but-fixed candidates for solver to attempt. Latter are going to be skipped until "salvage" mode so there should be no overhead for the solver in "performance first" mode.
1 parent 8b5396b commit 8de1763

File tree

1 file changed

+21
-26
lines changed

1 file changed

+21
-26
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -4203,9 +4203,9 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
42034203
break;
42044204
}
42054205

4206+
SmallVector<Constraint *, 4> candidates;
42064207
// If we found viable candidates, then we're done!
42074208
if (!result.ViableCandidates.empty()) {
4208-
llvm::SmallVector<Constraint *, 8> candidates;
42094209
generateConstraints(
42104210
candidates, memberTy, result.ViableCandidates, useDC, locator,
42114211
result.getFavoredIndex(), /*requiresFix=*/false,
@@ -4222,11 +4222,30 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
42224222
generateConstraints(candidates, memberTy, outerAlternatives,
42234223
useDC, locator);
42244224
}
4225+
}
4226+
4227+
if (!result.UnviableCandidates.empty()) {
4228+
SmallVector<OverloadChoice, 8> choices;
4229+
llvm::transform(
4230+
result.UnviableCandidates, std::back_inserter(choices),
4231+
[](const std::pair<OverloadChoice, MemberLookupResult::UnviableReason>
4232+
&candidate) { return candidate.first; });
4233+
4234+
// Generate constraints for unvailable choices if they have a fix,
4235+
// and disable them by default, they'd get picked up in the "salvage" mode.
4236+
generateConstraints(candidates, memberTy, choices, useDC, locator,
4237+
/*favoredChoice=*/None, /*requiresFix=*/true,
4238+
[&](unsigned idx, const OverloadChoice &choice) {
4239+
return fixMemberRef(
4240+
*this, baseTy, member, choice, locator,
4241+
result.UnviableCandidates[idx].second);
4242+
});
4243+
}
42254244

4245+
if (!candidates.empty()) {
42264246
addOverloadSet(candidates, locator);
42274247
return SolutionKind::Solved;
42284248
}
4229-
42304249

42314250
// If the lookup found no hits at all (either viable or unviable), diagnose it
42324251
// as such and try to recover in various ways.
@@ -4238,30 +4257,6 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyMemberConstraint(
42384257
if (!MissingMembers.insert(locator))
42394258
return SolutionKind::Error;
42404259

4241-
if (!result.UnviableCandidates.empty()) {
4242-
SmallVector<OverloadChoice, 8> choices;
4243-
llvm::transform(
4244-
result.UnviableCandidates, std::back_inserter(choices),
4245-
[](const std::pair<OverloadChoice, MemberLookupResult::UnviableReason>
4246-
&candidate) { return candidate.first; });
4247-
4248-
SmallVector<Constraint *, 4> candidates;
4249-
generateConstraints(candidates, memberTy, choices, useDC, locator,
4250-
/*favoredChoice=*/None, /*requiresFix=*/true,
4251-
[&](unsigned idx, const OverloadChoice &choice) {
4252-
return fixMemberRef(
4253-
*this, baseTy, member, choice, locator,
4254-
result.UnviableCandidates[idx].second);
4255-
});
4256-
4257-
// If there are any viable "fixed" candidates, let's schedule
4258-
// them to be attempted.
4259-
if (!candidates.empty()) {
4260-
addOverloadSet(candidates, locator);
4261-
return SolutionKind::Solved;
4262-
}
4263-
}
4264-
42654260
if (baseObjTy->getOptionalObjectType()) {
42664261
// If the base type was an optional, look through it.
42674262

0 commit comments

Comments
 (0)