Repository navigation
Conversation
15fb9bf to
1b7db36
Compare
|
Would it be possible to add some prose about "the grouping approach" somewhere close to this PR (commit message or PR description or both)? |
1b7db36 to
c7e3c0a
Compare
|
Sure! Adding a stripped before/after trace: cabal freeze trace beforeNote two libraries, both exposing cabal freeze trace after |
|
@sorki Thanks for working on finishing #6039! I haven't read the code yet, but it sounds like this PR doesn't currently add a way to check whether two installed libraries with the same package name and version were installed together. I'm concerned that that could cause the solver to err in the unsafe direction and allow inconsistent dependencies. For example, a source package (A-1.0) could depend on one installed sub-library from B-2.0 configured with one set of flags and a second installed sub-library from B-2.0 configured with a different set of flags. This inconsistency in dependencies could lead to subtle and confusing bugs. There is some discussion of how to group libraries by instance starting at #6039 (comment). Would it be possible to add a check in this PR, even if it's initially too conservative and needs to be loosened later? Here are a few ideas for how to implement the check:
|
Thanks for the feedback! This indeed only helps in simple
I've tried this but quickly found issues:
Trying this approach now - grabbing |
I'm not sure I understand. I would expect the situation in the second bullet point to lead to a conflict, because the solver can't choose two instances for the same package name. I would expect it to have to choose one instance, either the one with the main library or the one with the sub-library. So there would be no solution if a source package depended on both libraries. I know that this approach isn't perfect, but I suggested it because I think that it only fails in the safe direction (failing to find a solution when there is one), so it could be a good temporary solution. It would allow us to merge this PR quickly without increasing the scope too much. Then the full solution, such as |
827e4bb to
9c15b07
Compare
Wasn't quite clear, it would create a solver conflict now without munging.
I might have a full solution! |
e6f250b to
6de27a0
Compare
|
Companion repository with the original reproducer and Nix expressions to build a patched GHC + Cabal, cabal-install from this PRs branch https://github.com/sorki/my-nix-ghc |
c125b0b to
6de27a0
Compare
|
Sorry, I didn't realize that this PR was ready for review. I'm traveling for the next week and a half, but I'll try to get to it soon after that. I just had one comment so far from skimming the list of files. Could you please add some unit tests to cabal-install/tests/UnitTests/Distribution/Solver/Modular/Solver.hs? |
No worries. I can try but I think it needs an integration test as the |
I'm not sure I understand. Where is |
sebright
left a comment
There was a problem hiding this comment.
I didn't review much of the non-test code yet, but I wanted to add the comment that I had so far.
| case find matchMainLib comps of | ||
| Nothing -> | ||
| -- no main library, use arbitrary (first one) for componentInstanceUnitId assignment | ||
| assignAll (componentInstanceUnitId fstComp) |
There was a problem hiding this comment.
Why does this use an arbitrary component? Maybe it would be better to combine all of the components' UnitIDs into one value, in all cases.
There was a problem hiding this comment.
Not quite sure if there's any benefit in combining them
- provenance is easier with non-combined one (you can grep for it)
- for grouping, it doesn't matter which components ID is chosen as long as all of the grouped comps get assigned the same id
Also I don't know what would be the good strategy for combining them.
40aac4e to
5028e61
Compare
Solver unit tests already contain a sufficient tests for sub-libraries, but they cannot test the installed package index issue as the test harness prepares the package index correctly (it isn't loaded from disk which is what this PR addresses). I'm completely lost as how to properly test this, except for what I did in #11788 (comment) |
Before this patch, sub-libraries (either public or private) of installed packages are treated as top level separate packages from solvers point of view. This differs from how source packages are handled, which are treated as a single package. Sub-libraries of installed packages needed munging to prevent conflicts like described in `Note [Index conversion with internal libraries]`. Due to package name munging, top level library we are trying to build, cannot depend on public sub-libraries, more precisely - it can, but the installed packages are never used. Instead they are always rebuilt from source (as only source package index exposes public sub-libs correctly). The idea is to make packages coming from *installed* package index look similar to packages coming from *source* - appearing as a single package instead of multiple. The approach we choose is adding a grouping pass to solvers installed package index conversion. After the index is converted, we group installed packages by name and version and adjust all dependencies to point to newly built groups instead of split sub-lib packages. This way, solver only sees a single package (similar to how source packages are treated). This is done by means of adding * `InstGroup` `Loc` to solver * `installedSublibs` field to `InstalledPackageInfo` * and finally expanding `installedSublibs` in `ProjectPlanning` Now the sub-libs are handled correctly and build process picks installed public sub-libs when available. It also allows us to drop package name munging hacks from solver completely. Closes haskell#6039
same as `IPI.sourceComponentName`
This is no longer needed since private sub-libraries won't appear at top level, only as `installedSublibs` of top-level ones. Related to haskell#6039
`InstanceUnitId` serves as a unique identifier for a group of installed packages, allowing us to reconstruct package in solver, similar to how source package looks. Previously solver would treat each component of an installed package as a separate unit, leading to hacks like package name/component munging to prevent conflicts with the main package library. As there was no way to match sub-components to main library from existing `InstalledPackageInfo` fields, we need to add `InstanceUnitId` field, that links sub-components to main library if it exists or to some other component if not, allowing us to easily group components in solvers index conversion pass.
5028e61 to
28e0c0e
Compare
28e0c0e to
9ba946c
Compare
Before this patch, sub-libraries (either public or private) of installed
packages are treated as top level separate packages from solvers point of view.
This differs from how source packages are handled, which are treated as
a single package.
Sub-libraries of installed packages needed munging to prevent conflicts
like described in
Note [Index conversion with internal libraries].Due to package name munging, top level library we are trying to build,
cannot depend on public sub-libraries, more precisely - it can, but
the installed packages are never used. Instead they are always
rebuilt from source (as only source package index exposes public
sub-libs correctly).
The idea is to make packages coming from installed package index look
similar to packages coming from source - appearing as a single package
instead of multiple.
The approach we choose is adding a grouping pass to solvers installed package
index conversion. After the index is converted, we group installed
packages by name and version and adjust all dependencies to point to
newly built groups instead of split sub-lib packages. This way, solver
only sees a single package (similar to how source packages are treated).
This is done by means of adding
InstGroupLocto solverinstalledSublibsfield toInstalledPackageInfoinstalledSublibsinProjectPlanningNow the sub-libs are handled correctly and build process
picks installed public sub-libs when available. It also
allows us to drop package name munging hacks from solver
completely.
See #6039
Template Α: This PR modifies behaviour or interface
Include the following checklist in your PR:
significance: significantin the changelog file.