[Constraint solver] Constraint propagation, disabled by default.

This is an initial implementation of the constraint propagation pass,
disabled by default at the moment as it does not currently pass all
tests.

I have other changes that I'll hold off on for now because they are
incomplete. Without those changes, this pass doesn't really achieve
much, so this is really just a checkpoint on some progress and not
something really worth trying out at this point.
This commit is contained in:
Mark Lacey
2017-04-03 18:10:20 -07:00
parent 8f3bc160c5
commit 0cd57bd481
5 changed files with 281 additions and 16 deletions

View File

@@ -31,7 +31,8 @@ Constraint::Constraint(ConstraintKind kind, ArrayRef<Constraint *> constraints,
ConstraintLocator *locator,
ArrayRef<TypeVariableType *> typeVars)
: Kind(kind), HasRestriction(false), HasFix(false), IsActive(false),
RememberChoice(false), IsFavored(false), NumTypeVariables(typeVars.size()),
IsDisabled(false), RememberChoice(false), IsFavored(false),
NumTypeVariables(typeVars.size()),
Nested(constraints), Locator(locator)
{
assert(kind == ConstraintKind::Disjunction);
@@ -43,8 +44,8 @@ Constraint::Constraint(ConstraintKind Kind, Type First, Type Second,
ConstraintLocator *locator,
ArrayRef<TypeVariableType *> typeVars)
: Kind(Kind), HasRestriction(false), HasFix(false), IsActive(false),
RememberChoice(false), IsFavored(false), NumTypeVariables(typeVars.size()),
Types { First, Second }, Locator(locator)
IsDisabled(false), RememberChoice(false), IsFavored(false),
NumTypeVariables(typeVars.size()), Types { First, Second }, Locator(locator)
{
switch (Kind) {
case ConstraintKind::Bind:
@@ -100,8 +101,9 @@ Constraint::Constraint(ConstraintKind kind, Type first, Type second,
ConstraintLocator *locator,
ArrayRef<TypeVariableType *> typeVars)
: Kind(kind), HasRestriction(false), HasFix(false), IsActive(false),
RememberChoice(false), IsFavored(false), NumTypeVariables(typeVars.size()),
Member { first, second, member, useDC }, Locator(locator)
IsDisabled(false), RememberChoice(false), IsFavored(false),
NumTypeVariables(typeVars.size()), Member { first, second, member, useDC },
Locator(locator)
{
assert(kind == ConstraintKind::ValueMember ||
kind == ConstraintKind::UnresolvedValueMember);
@@ -117,7 +119,7 @@ Constraint::Constraint(Type type, OverloadChoice choice, DeclContext *useDC,
ConstraintLocator *locator,
ArrayRef<TypeVariableType *> typeVars)
: Kind(ConstraintKind::BindOverload),
HasRestriction(false), HasFix(false), IsActive(false),
HasRestriction(false), HasFix(false), IsActive(false), IsDisabled(false),
RememberChoice(false), IsFavored(false), NumTypeVariables(typeVars.size()),
Overload{type, choice, useDC}, Locator(locator)
{
@@ -129,7 +131,7 @@ Constraint::Constraint(ConstraintKind kind,
Type first, Type second, ConstraintLocator *locator,
ArrayRef<TypeVariableType *> typeVars)
: Kind(kind), Restriction(restriction),
HasRestriction(true), HasFix(false), IsActive(false),
HasRestriction(true), HasFix(false), IsActive(false), IsDisabled(false),
RememberChoice(false), IsFavored(false), NumTypeVariables(typeVars.size()),
Types{ first, second }, Locator(locator)
{
@@ -143,7 +145,7 @@ Constraint::Constraint(ConstraintKind kind, Fix fix,
ArrayRef<TypeVariableType *> typeVars)
: Kind(kind), FixData(fix.getData()), TheFix(fix.getKind()),
HasRestriction(false), HasFix(true),
IsActive(false), RememberChoice(false), IsFavored(false),
IsActive(false), IsDisabled(false), RememberChoice(false), IsFavored(false),
NumTypeVariables(typeVars.size()),
Types{ first, second }, Locator(locator)
{
@@ -216,7 +218,11 @@ void Constraint::print(llvm::raw_ostream &Out, SourceManager *sm) const {
Out << ":";
interleave(getNestedConstraints(),
[&](Constraint *constraint) { constraint->print(Out, sm); },
[&](Constraint *constraint) {
if (isDisabled())
Out << "[disabled] ";
constraint->print(Out, sm);
},
[&] { Out << " or "; });
return;
}