Skip to content

Commit

Permalink
Keep track of unification during optimisation. Fixes #149.
Browse files Browse the repository at this point in the history
A VarDecl could be in the queue for optimisation while it is being unified with another VarDecl. In that case, we need to check if it was re-written and removed and optimise the target of the rewriting instead.
  • Loading branch information
guidotack committed Mar 16, 2017
1 parent 032d72b commit 91c23c7
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/optimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -610,23 +610,27 @@ namespace MiniZinc {
Item* item = constraintQueue.back();
constraintQueue.pop_back();
Call* c;
ArrayLit* al;
ArrayLit* al = NULL;
if (ConstraintI* ci = item->dyn_cast<ConstraintI>()) {
ci->flag(false);
c = Expression::dyn_cast<Call>(ci->e());
al = NULL;
} else {
if (item->removed()) {
item = m[envi.vo.find(item->cast<VarDeclI>()->e()->id()->decl())]->cast<VarDeclI>();
}
item->cast<VarDeclI>()->flag(false);
c = Expression::dyn_cast<Call>(item->cast<VarDeclI>()->e()->e());
al = Expression::dyn_cast<ArrayLit>(item->cast<VarDeclI>()->e()->e());
}
if (al) {
substituteFixedVars(envi, item, deletedVarDecls);
pushDependentConstraints(envi, item->cast<VarDeclI>()->e()->id(), constraintQueue);
} else if (!c || !(c->id()==constants().ids.forall || c->id()==constants().ids.exists ||
c->id()==constants().ids.clause) ) {
substituteFixedVars(envi, item, deletedVarDecls);
handledConstraint = simplifyConstraint(envi,item,deletedVarDecls,constraintQueue,vardeclQueue);
if (!item->removed()) {
if (al) {
substituteFixedVars(envi, item, deletedVarDecls);
pushDependentConstraints(envi, item->cast<VarDeclI>()->e()->id(), constraintQueue);
} else if (!c || !(c->id()==constants().ids.forall || c->id()==constants().ids.exists ||
c->id()==constants().ids.clause) ) {
substituteFixedVars(envi, item, deletedVarDecls);
handledConstraint = simplifyConstraint(envi,item,deletedVarDecls,constraintQueue,vardeclQueue);
}
}
}
}
Expand Down

0 comments on commit 91c23c7

Please sign in to comment.