Skip to content
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

Closed
wants to merge 5 commits into from

Conversation

grayjay
Copy link
Collaborator

@grayjay grayjay commented May 13, 2019

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:

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog.
  • The documentation has been updated, if necessary.
  • If the change is docs-only, [ci skip] is used to avoid triggering the build bots.

Please also shortly describe how you tested your change. Bonus points for added tests!

@grayjay
Copy link
Collaborator Author

grayjay commented May 14, 2019

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.

@phadej
Copy link
Collaborator

phadej commented May 14, 2019 via email

@23Skidoo
Copy link
Member

If there aren’t, then cabal check could reject such definitions?

I think it'd be totally fine to do this, we can always relax this restriction later.

@grayjay
Copy link
Collaborator Author

grayjay commented May 16, 2019

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.

@23Skidoo
Copy link
Member

@grayjay SGTM.

@grayjay grayjay force-pushed the issue-6038 branch 2 times, most recently from e0c83bb to d22f35a Compare November 21, 2019 09:42
@grayjay
Copy link
Collaborator Author

grayjay commented Nov 21, 2019

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

@grayjay
Copy link
Collaborator Author

grayjay commented Dec 9, 2019

I'm planning to merge this next weekend if no one objects.

@phadej
Copy link
Collaborator

phadej commented Dec 9, 2019

I was going to (try to) stabilize master for 3.2 release this week. How high is the risk that this introduces regressions?

@phadej
Copy link
Collaborator

phadej commented Dec 9, 2019

Yet, this doesn't change anything in Cabal the library, so as far as CI is happy, I'm happy too.

@grayjay
Copy link
Collaborator Author

grayjay commented Dec 9, 2019

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.

@phadej
Copy link
Collaborator

phadej commented Dec 9, 2019

Wouldn't a positive test be a copy of cabal-testsuite/PackageTests/MultipleLibraries with a visibility toggled?

@grayjay
Copy link
Collaborator Author

grayjay commented Dec 9, 2019

I'm not sure. It looks like there some complexity with the GHC support for sublibraries in the discussion in #5848.

@phadej
Copy link
Collaborator

phadej commented Dec 9, 2019

We can skip that test for GHC <8.8, I'll try this today as well.

EDIT: #6409

@phadej phadej added this to the 3.2 milestone Dec 10, 2019
@phadej
Copy link
Collaborator

phadej commented Dec 10, 2019

I'm milestoning this for 3.2. Let's get this in. If I introduce conflicts I can do the merging.

@fgaz
Copy link
Member

fgaz commented Dec 10, 2019

Sorry, I've been busy lately. I'll take a look before the weekend

@grayjay
Copy link
Collaborator Author

grayjay commented Dec 11, 2019

@phadej @fgaz Thanks for looking into the integration testing. I'm fine with merging this before or after the release.

Copy link
Member

@fgaz fgaz left a 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this entail?

Copy link
Collaborator Author

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:

-- 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" [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great :)

@fgaz
Copy link
Member

fgaz commented Dec 15, 2019

Almost forgot: would it be possible to give a better error when using ghc<8.8 and depending on a public library?
edit: it probably should be done in another pr. let's merge this first

@grayjay
Copy link
Collaborator Author

grayjay commented Dec 17, 2019

@fgaz Thanks for the review!

Almost forgot: would it be possible to give a better error when using ghc<8.8 and depending on a public library?

How should the solver handle ghc<8.8? Should it disallow inter-package dependencies on sublibraries?

@fgaz
Copy link
Member

fgaz commented Dec 17, 2019

There are two options:

  • disallow inter-package dependencies on sublibraries, since they will fail Cabal's checks
  • override Cabal's checks with the --allow-depending-on-private-libs flag (see Prevent dependency on private library #5848 (review) and later comments), so that cabal-install can enable the multilibs functionality even on older ghcs

I think it was agreed to go with the second
/cc @hvr @ezyang

@grayjay
Copy link
Collaborator Author

grayjay commented Dec 18, 2019

@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?

@fgaz
Copy link
Member

fgaz commented Dec 18, 2019

Yes

@phadej
Copy link
Collaborator

phadej commented May 14, 2020

@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.

grayjay added 5 commits May 17, 2020 00:40
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.
@grayjay
Copy link
Collaborator Author

grayjay commented May 17, 2020

@phadej I was only rebasing the branch. I think that the only thing blocking this PR was the integration test, but I see that you added tests in #6409. Thanks for adding them! This PR still has a TODO for handling installed packages, but I would rather do that in a separate PR.

@grayjay
Copy link
Collaborator Author

grayjay commented May 26, 2020

This was merged in #6836.

@grayjay grayjay closed this May 26, 2020
@grayjay grayjay deleted the issue-6038 branch May 26, 2020 01:50
@phadej phadej mentioned this pull request Jul 10, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cabal-install: cannot depend on public sublibrary when the package does not contain a main library too
4 participants