Skip to content

Commit 7622993

Browse files
committed
[ConstraintSystem] Add a new endpoint to infer bindings for a given type variable
Since bindings now require finalization we need a new endpoint which perform all of the required actions before returning complete `PotentialBindings` object when they are requested for a particular type variable without any other context.
1 parent aae6e0c commit 7622993

File tree

4 files changed

+18
-3
lines changed

4 files changed

+18
-3
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,16 @@ bool ConstraintSystem::PotentialBindings::favoredOverDisjunction(
491491
return !InvolvesTypeVariables;
492492
}
493493

494+
ConstraintSystem::PotentialBindings
495+
ConstraintSystem::inferBindingsFor(TypeVariableType *typeVar) {
496+
auto bindings = getPotentialBindings(typeVar);
497+
498+
llvm::SmallDenseMap<TypeVariableType *, ConstraintSystem::PotentialBindings>
499+
inferred;
500+
bindings.finalize(*this, inferred);
501+
return bindings;
502+
}
503+
494504
Optional<ConstraintSystem::PotentialBinding>
495505
ConstraintSystem::getPotentialBindingForRelationalConstraint(
496506
PotentialBindings &result, Constraint *constraint,

lib/Sema/CSSolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2380,7 +2380,7 @@ void DisjunctionChoice::propagateConversionInfo(ConstraintSystem &cs) const {
23802380
if (typeVar->getImpl().getFixedType(nullptr))
23812381
return;
23822382

2383-
auto bindings = cs.getPotentialBindings(typeVar);
2383+
auto bindings = cs.inferBindingsFor(typeVar);
23842384
if (bindings.InvolvesTypeVariables || bindings.Bindings.size() != 1)
23852385
return;
23862386

lib/Sema/ConstraintGraph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1116,7 +1116,7 @@ bool ConstraintGraph::contractEdges() {
11161116
// us enough information to decided on l-valueness.
11171117
if (isParamBindingConstraint && tyvar1->getImpl().canBindToInOut()) {
11181118
bool isNotContractable = true;
1119-
if (auto bindings = CS.getPotentialBindings(tyvar1)) {
1119+
if (auto bindings = CS.inferBindingsFor(tyvar1)) {
11201120
// Holes can't be contracted.
11211121
if (bindings.IsHole)
11221122
continue;

lib/Sema/ConstraintSystem.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4649,14 +4649,19 @@ class ConstraintSystem {
46494649

46504650
Optional<Type> checkTypeOfBinding(TypeVariableType *typeVar, Type type) const;
46514651
Optional<PotentialBindings> determineBestBindings();
4652+
4653+
/// Infer bindings for the given type variable based on current
4654+
/// state of the constraint system.
4655+
PotentialBindings inferBindingsFor(TypeVariableType *typeVar);
4656+
4657+
private:
46524658
Optional<ConstraintSystem::PotentialBinding>
46534659
getPotentialBindingForRelationalConstraint(
46544660
PotentialBindings &result, Constraint *constraint,
46554661
bool &hasDependentMemberRelationalConstraints,
46564662
bool &hasNonDependentMemberRelationalConstraints) const;
46574663
PotentialBindings getPotentialBindings(TypeVariableType *typeVar) const;
46584664

4659-
private:
46604665
/// Add a constraint to the constraint system.
46614666
SolutionKind addConstraintImpl(ConstraintKind kind, Type first, Type second,
46624667
ConstraintLocatorBuilder locator,

0 commit comments

Comments
 (0)