-
Notifications
You must be signed in to change notification settings - Fork 697
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
Solver: Support dependencies on sub-libraries (issue #6039). #6047
Conversation
I just realized that this PR probably doesn't handle visibility correctly. It only reads the top-level visibility field, but the field can also appear in conditionals. Handling conditional visibility would probably require something similar to the "component on/off" flags in #4087 (comment), though that would be a significant change. Another option would be to handle visibility similarly to the way buildable is handled after #5337. At the start of dependency solving, we could check whether a component is private with the current environment and flag constraints, which would allow the solver to reject most dependencies on private libraries. A visibility field controlled by an automatic flag could still cause a build failure at the end of solving. |
Is there a use case for visibility controlled by an automatic flag? If there aren’t, then cabal check could reject such definitions?
… On 14 May 2019, at 8.10, Kristen Kozak ***@***.***> wrote:
I just realized that this PR probably doesn't handle visibility correctly. It only reads the top-level visibility field, but the field can also appear in conditionals.
Handling conditional visibility would probably require something similar to the "component on/off" flags in #4087 (comment), though that would be a significant change.
Another option would be to handle visibility similarly to the way buildable is handled after #5337. At the start of dependency solving, we could check whether a component is private with the current environment and flag constraints, which would allow the solver to reject most dependencies on private libraries. A visibility field controlled by an automatic flag could still cause a build failure at the end of solving.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
I think it'd be totally fine to do this, we can always relax this restriction later. |
I like the idea of disallowing visibility controlled by automatic flags, if it would be easy to reverse later. I could update this PR to try to determine whether libraries are visible at the start of solving, as I described above, which should always be correct when automatic flags aren't allowed. |
@grayjay SGTM. |
e0c83bb
to
d22f35a
Compare
I finally updated this PR to determine whether each library is visible in the current environment at the start of solving. The solver checks the visibility of the main library and sub-libraries, though I'm not sure if it is possible for the main library to be private. cc @fgaz |
I'm planning to merge this next weekend if no one objects. |
I was going to (try to) stabilize |
Yet, this doesn't change anything in |
Yes, it only affects the solver. I think there is a small risk of a regression in cabal-install, especially since this PR only contains unit tests, and, as far I know, there isn't a positive integration test for depending on sublibraries yet. |
Wouldn't a positive test be a copy of |
I'm not sure. It looks like there some complexity with the GHC support for sublibraries in the discussion in #5848. |
We can skip that test for GHC <8.8, I'll try this today as well. EDIT: #6409 |
I'm milestoning this for 3.2. Let's get this in. If I introduce conflicts I can do the merging. |
Sorry, I've been busy lately. I'll take a look before the weekend |
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.
Looks good! Thank you!
where | ||
-- TODO: Handle sub-libraries and visibility. |
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.
What does this entail?
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.
I forgot to look into handling installed packages. It could be tricky because of the hack where the solver treats installed internal libraries as packages with munged names:
cabal/cabal-install/Distribution/Solver/Modular/IndexConversion.hs
Lines 106 to 131 in 8f42d3f
-- Note [Index conversion with internal libraries] | |
-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | |
-- Something very interesting happens when we have internal libraries | |
-- in our index. In this case, we maybe have p-0.1, which itself | |
-- depends on the internal library p-internal ALSO from p-0.1. | |
-- Here's the danger: | |
-- | |
-- - If we treat both of these packages as having PN "p", | |
-- then the solver will try to pick one or the other, | |
-- but never both. | |
-- | |
-- - If we drop the internal packages, now p-0.1 has a | |
-- dangling dependency on an "installed" package we know | |
-- nothing about. Oops. | |
-- | |
-- An expedient hack is to put p-internal into cabal-install's | |
-- index as a MUNGED package name, so that it doesn't conflict | |
-- with anyone else (except other instances of itself). But | |
-- yet, we ought NOT to say that PNs in the solver are munged | |
-- package names, because they're not; for source packages, | |
-- we really will never see munged package names. | |
-- | |
-- The tension here is that the installed package index is actually | |
-- per library, but the solver is per package. We need to smooth | |
-- it over, and munging the package names is a pretty good way to | |
-- do it. |
I would need to figure out how to distinguish between inter- and intra-package dependencies when enforcing visibility.
db = [ Right $ exAv "A" 1 [ExAny "B"] | ||
, Right $ exAvNoLibrary "B" 2 `withExe` exe | ||
, Right $ exAv "B" 1 [] `withExe` exe ] | ||
in runTest $ mkTest db "choose version of build-depends dependency that has a library" ["A"] $ | ||
solverSuccess [("A", 1), ("B", 1)] | ||
] | ||
, testGroup "sub-library dependencies" [ |
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 great :)
Almost forgot: would it be possible to give a better error when using ghc<8.8 and depending on a public library? |
@fgaz Thanks for the review!
How should the solver handle ghc<8.8? Should it disallow inter-package dependencies on sublibraries? |
There are two options:
I think it was agreed to go with the second |
@fgaz Does the second option (override with --allow-depending-on-private-libs) mean that the solver doesn't need to give a different error for ghc<8.8? |
Yes |
836fd15
to
8146c52
Compare
@grayjay I noticed you worked on this recently. Do you think we can get this merged in the beginning of June 2020? I optimistally milestone this for 3.4. But if the above deadline is too tight, feel free to de-milestone. |
This commit tracks dependencies on sub-libraries by extending the functionality for tracking executables that was added in e86f838. It also starts adding support for library visibility, though it currently only works for source packages. There is a TODO for handling installed packages. This commit handles visibility similarly to the way that the buildable field is handled currently. It only checks whether a component is made private by the current environment and flag constraints at the start of dependency solving. This means that the solver can treat a component as visible when the visibility is controlled by an automatic flag, and the build can fail later, depending on the value that is chosen for the flag. Fixes haskell#6038.
This commit also refactors the Dependencies type so that it can represent any combination of dependencies, buildability, and visibility.
This was merged in #6836. |
This commit tracks dependencies on sub-libraries by extending the functionality
for tracking executables that was added in
e86f838. It also starts adding support for
library visibility, though it currently only works for source packages. There
is a TODO for handling installed packages.
Fixes #6038.
/cc @fgaz @kosmikus
Please include the following checklist in your PR:
[ci skip]
is used to avoid triggering the build bots.Please also shortly describe how you tested your change. Bonus points for added tests!