-
Notifications
You must be signed in to change notification settings - Fork 710
Solver is often stumped by restrictive upper bounds #1783
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I would be interested to know if a proper SMT solver would come up with a solution, when fed with the constraints. It would be possible to have cabal just print all the constraints and then copy-n-paste them into an off-the-shelf constraint solver. |
I mostly hacked together a Cabal version constraint solver prototype using Z3 a while back. It works, and it is fast. Like all of Hackage in less than a second fast. There needs to be a lot more work done to produce user friendly errors, and to apply some other common sense rules.. it also needs some patches to the z3 bindings to support incremental solves. Etc etc. |
@NathanHowell That's really cool. Do you have an example of the kind of error messages it gives and your thoughts on how they could be improved? I would like to investigate using a real solver. It might get rid of lots of the problems we have. Ideally the solver error message would include a minimal sense of constraints that cause a conflict to appear. Can Z3 produce such a thing? |
Whoops, I was writing a comment but then decided against it, and accidentally clicked "close". |
@tibbe : we use aspcud in OPAM, which uses a format called CUDF as the interchange format to external solvers. Would probably be effective for Cabal too... |
@tibbe SAT and SMT solvers provide some tools for this but generally you need to do it yourself. If a solution is found it may not be the best one, but it is a solution. And for counterexamples they can be complex, not a simple one... So you need to do that yourself. Incremental solvers like z3 can make it faster but it's still a lot of code to write. |
I'm beginning to think this is caused exclusively by |
There's also a wiki page on constraint-solving through SAT-solving: I think that could be really cool. The wiki-page is somehow confused on conditional constraints — implications seem easy to encode as boolean formulas. What might be harder is enabling flags automatically if they add dependencies that are available, if desired (I'm not sure that's the current behavior of flags, but such flags are desirable in a few scenarios, say https://www.reddit.com/r/haskell/comments/4pf86b/cabal_build_variants/d4kv7yp). EDIT: to be sure, you can easily express in a boolean formula that the presence of a package implies a certain flag, but that forces the flag. It seems one would need to somehow use MaxSAT (that maximizes the number of enabled booleans in a solution) but use "maximize" only some variables, I don't know if that's available out-of-the-box. |
@Blaisorblade translating the cabal constraint satisfaction problem into SAT or SMT language is mostly straight-forward; several people (including myself) have done this in the past, and it's mostly a matter of sitting down on a calm weekend. And in fact, solvers like Z3 then can easily beat the modular cabal solver finding some arbitrary solution. However, as soon as you want an optimal solution according to some criteria (which you then need to encode in the SMT/SAT language as well), things get ugly and demotivating, and then the realization sets in that the modular cabal solver is not that bad after all... :-/ |
Just found #2860, answering there... |
Question: has anyone tried using a datalog variant? I may have a poke at seeing if the data log tools in z3 and friends are On Friday, July 8, 2016, Herbert Valerio Riedel [email protected]
|
I think that cabal is much better at handling restrictive upper bounds now that it can reorder goals with the conflict counting feature added in #3513. If a package has a restrictive upper bound and it occurs frequently in conflict sets, conflict counting causes the solver to choose the packages affected by the constraint earlier. Then it can make choices that take the constraint into account. I tried to reproduce the original problem by specifying Turning Please open another issue if there is still a problem. |
To define the term: by "restrictive upper bound" I mean an upper bound which excludes some packages available from Hackage. So if foo 1.0, 1.1, and 1.2 are available on Hackage, a bound of
foo < 1.3
would not be restrictive, whereasfoo < 1.2
would be restrictive.I went to build a project I haven't touched in a few months (haskellers.com), and cabal was unable to produce a build plan. Eventually, I whittled this down to this cabal file. In this file, there is only one restrictive upper bound: http-conduit. I then ran the following command with both cabal-install 1.16 + GHC 7.6 and cabal-install 1.18 + GHC 7.8:
In both cases, there was no response for approximately 15 minutes, at which point I killed cabal. However, I was able to cause the dry run to succeed almost immediately (< 10 seconds) with either of the following:
I'd like to note that these are the kinds of errors Yesod users complained about regularly in the past. The ultimate "solution" I settled on was (1) encourage usage of yesod-platform to help out the constraint solver, and (2) remove most upper bounds in cabal files. Obviously it would be better if cabal was better able to handle these situations.
The text was updated successfully, but these errors were encountered: