Skip to content

Commit b891a45

Browse files
committed
[CSBindings] Change the direction of literal coverage determination
1 parent dd1b8b3 commit b891a45

File tree

1 file changed

+21
-40
lines changed

1 file changed

+21
-40
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -562,53 +562,34 @@ void BindingSet::determineLiteralCoverage() {
562562

563563
bool allowsNil = canBeNil();
564564

565-
for (auto binding = Bindings.begin(); binding != Bindings.end();) {
566-
bool isCovered = false;
567-
Type adjustedTy;
568-
569-
// Tracks the number of covered literal requirements,
570-
// so checking could be stopped as soon as all of the
571-
// requirements are satisfied.
572-
unsigned numCoveredRequirements = 0;
573-
for (auto &literalRequirement : Literals) {
574-
auto &literalInfo = literalRequirement.second;
575-
576-
if (!literalInfo.viableAsBinding()) {
577-
++numCoveredRequirements;
578-
continue;
579-
}
565+
for (auto &entry : Literals) {
566+
auto &literal = entry.second;
567+
568+
if (!literal.viableAsBinding())
569+
continue;
570+
571+
for (auto binding = Bindings.begin(); binding != Bindings.end();
572+
++binding) {
573+
574+
bool isCovered = false;
575+
Type adjustedTy;
580576

581577
std::tie(isCovered, adjustedTy) =
582-
literalInfo.isCoveredBy(*binding, allowsNil, CS.DC);
578+
literal.isCoveredBy(*binding, allowsNil, CS.DC);
583579

584-
if (isCovered) {
585-
literalInfo.setCoveredBy(binding->getSource());
586-
++numCoveredRequirements;
587-
break;
588-
}
589-
}
580+
if (!isCovered)
581+
continue;
590582

591-
// If the type has been adjusted, we need to re-insert
592-
// the binding but skip all of the previous checks.
593-
//
594-
// It's okay to do this here since iteration stops after
595-
// first covering binding has been found.
596-
if (isCovered && adjustedTy) {
597-
binding = Bindings.erase(binding);
598-
adjustedBindings.push_back(binding->withType(adjustedTy));
599-
continue;
600-
}
583+
literal.setCoveredBy(binding->getSource());
601584

602-
// If all of the literal requirements are now covered
603-
// by existing bindings, there is nothing left to do.
604-
if (numCoveredRequirements == Literals.size())
605-
break;
585+
if (adjustedTy) {
586+
Bindings.erase(binding);
587+
Bindings.insert(binding->withType(adjustedTy));
588+
}
606589

607-
++binding;
590+
break;
591+
}
608592
}
609-
610-
for (auto &newBinding : adjustedBindings)
611-
(void)Bindings.insert(std::move(newBinding));
612593
}
613594

614595
void BindingSet::addLiteralRequirement(Constraint *constraint) {

0 commit comments

Comments
 (0)