Merge pull request #35098 from xedin/dont-precompute-default-bindings

[CSBindings] Don't generate bindings for defaults
This commit is contained in:
Pavel Yaskevich
2020-12-17 00:33:37 -08:00
committed by GitHub
3 changed files with 138 additions and 59 deletions

View File

@@ -5372,6 +5372,24 @@ TypeVarBindingProducer::TypeVarBindingProducer(
if (Any) {
Bindings.push_back(*Any);
}
{
bool noBindings = Bindings.empty();
for (const auto &entry : bindings.Defaults) {
auto *constraint = entry.second;
if (noBindings) {
// If there are no direct or transitive bindings to attempt
// let's add defaults to the list right away.
Bindings.push_back(getDefaultBinding(constraint));
} else {
// Otherwise let's delay attempting default bindings
// until all of the direct & transitive bindings and
// their derivatives have been attempted.
DelayedDefaults.push_back(constraint);
}
}
}
}
bool TypeVarBindingProducer::requiresOptionalAdjustment(
@@ -5403,3 +5421,15 @@ bool TypeVarBindingProducer::requiresOptionalAdjustment(
return false;
}
ConstraintSystem::PotentialBinding
TypeVarBindingProducer::getDefaultBinding(Constraint *constraint) const {
assert(constraint->getKind() == ConstraintKind::Defaultable ||
constraint->getKind() == ConstraintKind::DefaultClosureType);
auto type = constraint->getSecondType();
Binding binding{type, BindingKind::Exact, constraint};
return requiresOptionalAdjustment(binding)
? binding.withType(OptionalType::get(type))
: binding;
}