-
Notifications
You must be signed in to change notification settings - Fork 696
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
Improve algorithm for choosing flags with ./Setup configure
#2925
Conversation
Travis failure seems to be due to |
@grayjay Our policy is that Cabal should be buildable out of the box on all supported versions of GHC. Can you please make your patch compatible with |
@23Skidoo I fixed it. Would you like me to combine the last two commits? |
I looked into printing a different error message when the set of missing dependencies doesn't depend on flag choices, but it would be a large change relative to the improvement in message quality. I reworded the existing message instead. |
Cabal previously tried all flag combinations, which was too slow. The new algorithm assigns one flag at a time, and backtracks when a flag introduces a dependency that is unavailable. This change also fixes a space leak.
0c6f42d
to
b0b0386
Compare
…ncies This commit takes the union of all dependencies that caused Cabal to backtrack when trying different combinations of flags. Previously, Cabal printed the shortest list of missing dependencies from a single flag assignment. The new error message requires less searching.
4f6d9fe
to
6ca6a01
Compare
I rebased and cleaned up the history. If that's a problem, I can restore it. |
@grayjay OK, thanks, will take another look at this soon. Sorry for the delay. |
@@ -189,7 +190,7 @@ instance Monoid d => Mon.Monoid (DepTestRslt d) where | |||
mappend (MissingDeps d) (MissingDeps d') = MissingDeps (d `mappend` d') | |||
|
|||
|
|||
data BT a = BTN a | BTB (BT a) (BT a) -- very simple binary tree | |||
data Tree a = Tree a [Tree a] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is now exactly the same as http://hackage.haskell.org/package/containers-0.5.6.3/docs/Data-Tree.html
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I just updated the PR.
@kosmikus could you have a look at this one too. |
As the one hit hard by this bug, I really appreciate the work here to fix it. So, I kind of hate to raise this possibility, but.. It's possible for setting flag A xor B to yield an unavailable dependency, while setting flag A and B yields a dependency that is available.
Sounds like the backtracking introduced in this patch would cause the resolver to see A alone is bad, and never try A and B, so never find the preferred dependency. I have not verified this is the case, and I don't know if such a thing appears in real-world cabal files. |
@joeyh I think this actually should not matter; the ./Setup resolver is not actually used for any serious flag selection unless you manually call ./Setup configure. If you use "cabal configure", cabal-install's solver will be use which can actually do a proper job of it. |
@joeyh I just tried the test case, and it seems to work. |
There is one case in which it's actually useful. When |
b3509b9
to
561dc48
Compare
I discovered a problem when rebasing this onto master. The backtracking optimization is incompatible with #2731. For example, the unavailable dependency outside of a conditional causes
I haven't tried anything yet, but I see a few options:
|
Kristen Kozak wrote:
If you mean it would need to exhastively check 2^21 combinations of flags Even if it turned out to be too slow in such a case, that would be much see shy jo |
@joeyh Thanks for the feedback. Yes, it would have to try all combinations until it found a solution. I'll make a PR with just the space leak fix when I have time. |
@23Skidoo I tried updating this to work with master, and it actually wasn't too hard. I'll make another pull request. |
This pull request fixes the space leak in #2777 and should also improve the run time in many cases. The new algorithm assigns one flag at a time and backtracks when a flag introduces a dependency that is unavailable, instead of always trying every flag combination until one succeeds.
The first commit changes the search algorithm, and the second commit updates error messages. Previously, Cabal printed the shortest list of missing dependencies from a single complete flag assignment. Now it is easier to take the union of all dependencies that caused Cabal to backtrack. Is this change okay? Here is an example:
./Setup configure
on master prints:This branch only lists the dependencies introduced by flag1, because there is no need to search farther:
EDIT: I think that the new error message is a little confusing, especially when a package has no flags, but I'm not sure how to reword it.