You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't think there is a clear design for component-based solving yet, so I wanted to create an issue where we can discuss it. #1575 addresses circular dependencies in test suites but is moving towards a different solution.
Related issues: #779, #3978, #3492 (comment) - solver doesn't reject configurations that require unbuildable/non-existent components #1575 - cabal can't handle cycles between packages that are not cycles between components #2725, #5413 - cabal requires dependencies of components that aren't being built #3662 - more per-component support #3263 - fine-grained dependencies #6039
Here are my thoughts, so far. At a minimum, the solver should keep track of dependencies between packages' components. (I think that it currently tracks dependencies from components to packages.) Then it can stop requiring dependencies of components that aren't needed, and ensure that required components are buildable. The solver should still ensure that all components within a package are consistent (have the same version and flag assignments), unless they have different qualifiers. Maybe we can add a flag or use private dependencies to relax that restriction later.
This design isn't 100% component-based: We keep package variables and add one
boolean variable for each component. However, the nodes of the dependency
graph are components.
We add several search tree transformations to enforce new component-related
constraints.
Tree structure
Per-component solving requires some changes to the variables used by the
solver, which means that we also need to change the goals, as well as the
choice nodes created for those goals.
Variables
Types of variables (including those that already exist):
Package:
The instance chosen for a specific package, as before.
Flag:
The boolean value for a specific flag, as before.
Flag-like (I'm not sure whether these should be implemented as flag
variables, stanza variables, or something new):
Each has two possible values.
They are used in conditionals to control dependencies, just like flags,
except that they aren't in the .cabal file. They need to be added when
the solver converts the package indexes to the solver-specific index
format.
Three types of flag-like variables per package:
Tests/Benchmarks enabled:
Two variables per package, just like current test and benchmark
stanza variables.
The default value is disabled.
Component on/off:
There is one variable per component in the package.
The two choices are Required and Not Required On and Off.
Required On:
It means that this component must be built. Either it is a
top-level target, or it is a dependency of another component.
Buildable: False is treated as a failure.
Not Required Off:
The component does not need to be built. It may be built anyway,
because of an old Cabal setup version or --enable-tests/benchmarks.
The default value is off.
Setup script features:
There is only one variable per package. The two choices are New and
Old.
New:
It means that the package has a simple build type or uses
Cabal >= 1.24 for the Custom build type.
The solver can choose to build a subset of components.
The solver can ignore dependencies of unbuildable components.
Old:
It means that the package can use Cabal < 1.24 for the Custom build
type.
The solver must choose dependencies for all lib/exe components,
though the components are allowed to have Buildable: False.
The solver must also choose dependencies for all test (or benchmark)
components when tests (or benchmarks) are enabled, though they may
also be unbuildable.
TODO: How do we know when a setup script supports per-component
builds? Do we only need the setup Cabal version and build type?
Why do we still have package variables?
Per-component solving needs to work with Custom setup scripts that don't
support per-component builds.
Constraints from one component should still apply to others. Otherwise, we
might break packages that only constrain dependencies for one component
(usually the library).
--enable-tests/benchmarks needs to find all tests/benchmarks in the
package.
We only need to choose the package instance once for all components. If we
ever need to build components with conflicting dependencies, we can use
qualified goals.
Each time we choose a package instance while building the tree, we immediately
add all flag-like goals for that instance to the set of remaining goals. TODO: How do we handle component goals for installed packages? Do we know
which executables are available? Can we find all components by package name
and version in the installed package index?
We add package goals as we discover new dependencies while building the tree,
as before.
Index conversion
This phase adds flags to the dependency tree for each package, in order to
implement the behavior of the flag-like goals described above.
Say x represents the contents of an executable stanza (The same applies to
libraries). x would be transformed into:
executable my-exe
if flag(my-exe-component-on)
x, with "Buildable: False" fields converted to failures
else
if flag(old-setup-script-features)
x
else
x, transformed as in #3039 (in order to ignore dependencies when
the component is unbuildable) and all dependencies converted to
qualified constraints
Test/benchmark component transformation:
x represents the contents of a test suite stanza. The transformation is
like the lib/exe transformation, except that it also uses the tests-enabled
flag.
test-suite my-test
if flag(my-test-component-on)
x, with "Buildable: False" fields converted to failures
else
if flag(tests-enabled)
if flag(old-setup-script-features)
x
else
x, transformed as in #3039 (in order to ignore dependencies when
the component is unbuildable) and all dependencies converted to
qualified constraints
else
empty test-suite stanza
Dependency graph
Nodes are components, not packages.
We can choose whether to check for cycles between packages or components.
We add two search tree transformations to ensure that the value of the
"setup script features" variable is consistent with the actual features of
the setup script. We could combine these two transformations if it turns out
to be simpler.
One transformation disables the "New" "setup script features" choice for each
package that has Custom build type and a setup Cabal version that is less than
1.24.
The other transformation enforces Cabal >= 1.24 for the setup script for each
package that chose "New" for the "setup script features" variable.
(There are two transformations because the solver can assign the variables in
either order.)
Component dependency validation steps
We add two more tree transformations. These could be combined with the
existing validation phase transformations.
Note that we need to perform two checks for each dependency on a component:
The package instance must contain the right component, and the component must
be enabled.
First transformation:
Create a set of required components while descending the search tree, by
looking at build-depends, tool-depends, and build targets.
For each package instance choice, prune all instances that don't contain all
of the components that are required so far.
For each component choice, if the component is required, prune the "Off"
choice.
Second transformation:
Create a set of visited packages and a set of available components while
descending the search tree:
For each package instance choice, add the package to the package set and
add all components provided by that instance to the component set.
For each component choice that turns off a component, remove that
component from the component set.
Every time a dependency is introduced by a build-depends or tool-depends, check that if the package was visited then the component is
available. If the component is not available, prune the choice that
introduced the dependency.
Enabling tests/benchmarks
--enable-tests/benchmarks doesn't need to change much. The current stanza
variables have the same behavior as the flag-like variables I described above.
Internal dependencies
The solver also tracks dependencies between a single package's components. A
dependency between components is handled as a dependency on an exact package
version, so that both components come from the same package instance.
More questions
What if a user specifies an unbuildable component as a build target? The
solver could try to build the component by flipping flags, but then the
install plan would depend on the list of targets. This problem is very
similar to 'cabal new-build test:test-suite' doesn't force tests to be enabled. #3923, except that it deals with enabling components instead of
tests.
How do we know when a setup script supports per-component builds? Do we only need the setup Cabal version and build type?
Per-component occurs if and only if:
We are new-build
build-type is not Custom
cabal-version >= 1.8
--disable-per-component is not specified
The canonical source of truth is why_not_per_component in ProjectPlanning. Probably best to just cross-reference two sites for now.
Constraints from one component should still apply to others. Otherwise, we
might break packages that only constrain dependencies for one component
(usually the library).
But note that to fix things like #3732 we'll have to relax how we do the constraints here. I guess this is covered by what you say later: "If we
ever need to build components with conflicting dependencies, we can use
qualified goals."
How do we handle component goals for installed packages? Do we know
which executables are available? Can we find all components by package name
and version in the installed package index?
At the moment, we won't know anything about executables, but we don't have to, because new-build will never have those as "installed" packages.
Internal libraries pose a special problem, because they show up in the installed package index (I recently committed a hack to handle this case). With our current featureset, we are allowed to assume that any internal library in the installed package index can only be reached by a corresponding "public" library from the package (so the "correct" way to handle internal libraries is to bundle them all up together with the public library into one 'package node'). The hacked code doesn't actually do this but that's what should be done morally.
What if a user specifies an unbuildable component as a build target? The
solver could try to build the component by flipping flags, but then the
install plan would depend on the list of targets.
Perhaps there should be a distinction made between "build targets" (what am I going to build this round) and "solver targets" (please work hard to dep solve so that X is buildable.) The latter is stable and shouldn't change even if you decide to build different things. This should solve the next bullet point too.
We are new-build
build-type is not Custom
cabal-version >= 1.8
--disable-per-component is not specified
I see that I had this part backwards. These rules simplify things, because the solver doesn't need to choose whether to use per-component build for each package; there is only one choice. In that case, I think that we don't need to add the "setup script features" variables, for now.
I had also incorrectly assumed that every package that ignores dependencies of unbuildable components also supports per-component build. Since the two attributes are not linked, I think we should handle #3881 separately.
But note that to fix things like #3732 we'll have to relax how we do the constraints here. I guess this is > covered by what you say later: "If we
ever need to build components with conflicting dependencies, we can use
qualified goals."
I'm not sure that we should make cabal find a solution for the example at the top of #3732, which only constrains base in one component. It looks the same as a package where the author meant for the constraint on base to apply to all components but wanted to avoid duplication. I haven't searched Hackage to see how common that pattern is, though.
Per-component solving would still allow more flexibility in less extreme cases, even if it always applied all build-depends constraints. Take this example:
executable exe1
build-depends: x > 2
executable exe2
build-depends: y < 3
Say that x > 2 and y < 3 have conflicting constraints on z. Then per-component solving would allow exe1 and exe2 to be installed separately while the current solver wouldn't find a solution.
Qualified goals would only help by allowing components that were independently solvable to be solvable together with different qualifiers (possibly using different versions of the package containing the components).
At the moment, we won't know anything about executables, but we don't have to, because new-build will never have those as "installed" packages.
Okay, so cabal will behave as if those package instances provided libraries but not executables.
Internal libraries pose a special problem, because they show up in the installed package index (I recently committed a hack to handle this case). With our current featureset, we are allowed to assume that any internal library in the installed package index can only be reached by a corresponding "public" library from the package (so the "correct" way to handle internal libraries is to bundle them all up together with the public library into one 'package node'). The hacked code doesn't actually do this but that's what should be done morally.
I'm not sure I understand this part. Can we always reach all of the internal libraries if we have the main library from the installed package index? I think that is all the solver needs to do.
Perhaps there should be a distinction made between "build targets" (what am I going to build this round) and "solver targets" (please work hard to dep solve so that X is buildable.) The latter is stable and shouldn't change even if you decide to build different things. This should solve the next bullet point too.
That distinction makes sense. I still don't know how we should choose those two sets of targets, though.
For "solver targets", maybe we should just give the solver a list of packages to solve for and apply a preference to build all components within each of those packages. Is there any situation where we would want to give the solver a subset of a package's components as targets?
I'm not sure that we should make cabal find a solution for the example at the top of #3732, which only constrains base in one component. It looks the same as a package where the author meant for the constraint on base to apply to all components but wanted to avoid duplication.
IMO a better way to avoid duplication is to make it more explicit that multiple components ought to share common dependencies/constraints via the likes of #2832, and then we could unlock/enable per-component solving also in the aforementioned case when a high enough cabal-version: value is set (c.f. to how the semantics for build-depends & multiple components changed between cabal-version 1.6 and 1.8)
I had also incorrectly assumed that every package that ignores dependencies of unbuildable components also supports per-component build.
Yeah, but I think the converse is true (per-component = correct handling of non-buildable components.)
I'm not sure I understand this part. Can we always reach all of the internal libraries if we have the main library from the installed package index? I think that is all the solver needs to do.
Not necessarily. For example, we may have registered an internal library which was only linked by the test suite, but not by the actual public library of a package. @dcoutts would probably say that this just means we shouldn't have registered it but it seems better to me to not assume any relationship without tracing the dependency relations.
For "solver targets", maybe we should just give the solver a list of packages to solve for and apply a preference to build all components within each of those packages. Is there any situation where we would want to give the solver a subset of a package's components as targets?
Yeah I'm not sure what the default should be. What we have right now is best effort which seems to work decently well, so maybe every component would have a designation like, "never", "best-effort", "always", with everything defaulting to best-effort.
The problem I described applies in either direction, not just under a hypothetical B depending on B:foo. The expectation in fact is B:foo depending on B, so ensuring that B and B:foo have compatible dependencies is necessary.
@geekosaur I am talking about the case when B:library does NOT depend on B:foo. That is the most common case that I've seen with sub libraries. In which case we need to care whether B:foo is buildable only when something else depends on it or when we are doing cabal build B!
@geekosaur I don't think it's debatable whether this feature is needed given the extensive net of issues in the OP and the number of high-profile figures involved in those. Also, I totally get what @lehins says, and I'm very fuzzy on what you're saying: I am sort of kind of able to see the argument that forcing "collective" solving of all components in a package may have some benefits in terms of consistency between different components but it's a very hand-wawy argument, I feel. If component-aware solving was running into a real roadblock w r.t. consistency of build, that would be spotted by Kristen in her plan (see the link below), I'm sure of it. There might be some corner cases, sure. But we must optimize for general problems, not corner cases. And prior discussions are pretty clear that this feature would solve a bunch of big pain points.
A pinch of optimism: a design was laid out long time ago: #4087 (comment) Someone just needs to put the time to realize it.
Consistent solving (picking only one package version) and per-component solving (picking only requested components) are orthogonal issues.
Currently cabal-install solver solves for all components even if not all are requested. Luckily unrequested components are not built, but still, they affect the build plan. If B:foo depends on B, but downstream depends on B only, then B:foo dependencies should not affect the build plan.
I totally get what @lehins says, and I'm very fuzzy on what you're saying
Okay, apparently I am failing to speak English tonight. I really do not understand what is backwards or fuzzy about "if B:foo depends on B but it was built with different dependencies than B, it can't actually use B".
And if this is not considered a problem, why do --enable-tests and --enable-benchmarks exist when their purpose is to ensure a consistent build plan in those cases, as with this case?
A pinch of optimism: a design was laid out long time ago: #4087 (comment) Someone just needs to put the time to realize it.
Yes, there is a design, and we have implemented parts of it, such as checking that required components are available. I think that we should still move in this direction, and I've been checking that solver changes are compatible with this design as I review code. It would be great if we had the resources to implement solver variables to control whether each component is enabled, and I would be happy to help with design and code review. (EDIT: I also think that we could probably remove some of the cases handled in the original design.)
Consistency:
We might need to make a Cabal spec change when we allow the solver to turn off specific components, in order to avoid breaking packages that use bounds on one component to constrain all components.
We might need to make a Cabal spec change when we allow the solver to turn off specific components, in order to avoid breaking packages that use bounds on one component to constrain all components.
I don't think that were ever part of spec, and cabal check does warn about missing bounds on independent components:
cabal-version: 3.6
name: tmp-example
version: 0librarybuild-depends: base <5, bytestring <0.12library foo
visiblity: public
build-depends: base <5, bytestring
% cabal check
...
Warning: [missing-upper-bounds] On library 'foo', these packages miss upper
bounds:
- bytestring
...
And even if there are packages which are relying on current behavior, they may be fixed with revisions. Not a big deal.
@lehins I had a long chat with @geekosaur on Cabal''s matrix (welcome, by the way!). I think I was able to get his idea, and now I'll try to put it in a way that may (or may not) be more accessible. Brandon should feel free to correct me, and he probably will because we seem to be in disagreement still. But I still want to share in case it could help even if a bit :-)
The concern is real simple, and it's entirely performance related: imagine, B has B.lib (the default library) and B.foo (another component, say a private library). Under the current feature request, B.lib may end up having different versions of dependencies in the plan depending on whether it's built individually or as a part of B.foo. This should be perfectly valid in principle. But Brandon's concern is UX. Imagine a user who keeps building B and then B.foo and then B again, and so on. Switching between components will require re-solving and rebuilding B in this case.
Overall, it seems like with the proposed feature, we get a degradation in UX for this particular use case: first, the plans for different components are different, second, you keep switching components. The reason I'm not so worried about this is as follows. While the first seems like it will be a common case (that's the whole reason why we want per-component solving), the second doesn't seem like a terribly important scenario to me. Also, there is a simple workaround for it: if you need to switch between B.lib and B.foo all the time and you're bothered by the snags, just say cabal build B B:foo, which will hopefully give you what you want without re-solving/re-building all the time. Now, you can find corner cases like several dozen components in a package and wanting to switch between half of them, then it's tedious to name all of them, and you don't want to go the full-blown cabal build all (which is a perfectly valid workaround too IMO). But this path seems to have vanishing importance, so I really don't see it as a show stopper. I wonder what others think..
THis is the first time I hear this. If you have some issues, please report them. Otherwise, don't complain "behind maintainers back".
@phadej I would not dare to complain behind your back. I was more than sure you'd be following this conversation. Instances for vector in quickcheck-instances are fine for the regular user of vector, but they are suboptimal for anyone who is trying to test their more advanced uses of vector. In particular vectors in quickcheck-instances are always constructed from a list, which never produces vectors that have a non-zero offset, which is critical for testing more advance or unsafe uses of vector.
My goal in this comment was not to complain about quickcheck-classes. The point I was trying to bring across is that it should not be your responsibility to maintain a package like that. It should be responsibility of actual package maintainers, like vector to provide functionality for generating random valid values like Arbitrary, because actual maintainers have all the intrinsic knowledge about potential corner cases. The thing that I am trying to stress here is that sublibraries would allow us to do that, if this dependency resolution issue is solved.
Overall, it seems like with the proposed feature, we get a degradation in UX for this particular use case
We may want to treat packages under development and dependencies differently. So if there package foo and main library and sublibraries bar and baz and I'm working on it. Then it makes sense to solve for all component. But if I work on some package that depends on foo and only use foo:lib there's no point in solving for foo:bar, foo:baz.
Current state of affair limits usefulness of public sublibraries. Why one would move code into sublibrary? One of main reasons: because it depends on something that main library shouldn't (see example with Arbitrary instances).
Current state of affair limits usefulness of public sublibraries.
I don't think anyone contends this point. The question is what should be the path forward. And the answer has to be debated and all pros and cons are better discovered before an actual implementation happens.
Current state of affair limits usefulness of public sublibraries.
That sounds like a neat idea. It does tap into the complexity budget sadly, which Cabal doesn't have much to spare. But maybe it's the way to go. I'd be interested in hearing @sebright's thoughts.
One thing I say about this idea is: I hope there will be a way to solve/build individual components in local packages anyway.
We may want to treat packages under development and dependencies differently. So if there package foo and main library and sublibraries bar and baz and I'm working on it. Then it makes sense to solve for all component. But if I work on some package that depends on foo and only use foo:lib there's no point in solving for foo:bar, foo:baz.
The design above treats top-level packages (packages in cabal.project or arguments to the install command) differently than dependencies, though we never decided exactly how to determine the list of "solver targets". After seeing the outcome of making test targets optional in v2 build, including issues like #7883, I now think that we should solve for all components of top-level packages by default. However, the set of targets could still be reduced with manual flags and the "buildable" field, as is possible today.
Current state of affair limits usefulness of public sublibraries.
That sounds like a neat idea. It does tap into the complexity budget sadly, which Cabal doesn't have much to spare. But maybe it's the way to go. I'd be interested in hearing @sebright's thoughts.
__monty__: (Consider me an uninformed observer.) Is there actually any good reason to want a different build plan for a component than for that component as part of all components? (I can imagine not wanting to be held back by parts of a project but morally you're temporarily breaking a project by moving part of it to a newer version of a dependency and expecting Cabal to deal with that is not much different from
expecting it to deal with components that have outright files missing or syntax errors.)
geekosaur: that's more or less my opinion, but see https://github.com/haskell/cabal/issues/4087
Per-component dependency solving · Issue #4087 · haskell/cabal - GitHub
I don't think there is a clear design for component-based solving yet, so I wanted to create an issue where we can discuss it. #1575 addresses circular dependencies in test suites but is moving tow...
__monty__: Still reading but so far I don't understand the opposition. It's just never desirable to resolve for the same component IMO. It's already annoying and shouldn't be a thing with testsuites.
Artem: @irc_libera.chat___monty__:kf8nh.com: if you're talking about local packages, then maybe. Otherwise, here's a short and sweet explanations: https://github.com/haskell/vector/issues/519
FYI: cabal-install will always solve for tasty too · Issue #519 · haskell/vector - GitHub
Due vector having a (private) library for benchmarks, cabal-install's solver will always also solve for its dependencies, even if that (private sub) library is never required. This is not really a ...
Although, I many times find myself wanting to not bother about deps in the closure of other components and wanting to focus on one component at a time. In that case I'd prefer that other components' dependencies would not leak into my plan.
__monty__: IMO that should not be the default behavior though. Supporting it with a flag or such would be fine.
With benchmarks and testsuites there's a disconnect. I feel like as a developer using Criterion or Quickcheck, I shouldn't be constrained in any way by the version of, say, base or Text, that those tools happen to depend on.
geekosaur: And that indeed isn't the default there
That's what --enable-tests and --enable-benchmarks do
__monty__: I remember my library getting rebuilt when passing --enable-tests. That's unexpected IMO.
geekosaur: Okay now I'm confused
You want them to not affect the solver during development but somehow not affect it when testing as well, meaning tests have disjoint dependencies?
geekosaur@geekosaur:matrix.org: This is exactly what I'm worried about
@irc_libera.chat___monty__:kf8nh.com: I want the testing tools to not constrain the thing under test.
But that's a separate discussion and I don't want to derail the initial point here.
geekosaur@geekosaur:matrix.org: How can they do that if they depend on the things being tested?
@irc_libera.chat___monty__:kf8nh.com: The reason I want that is that constraining the dependencies of the thing under test by the dependencies of the testing tool actually means you end up distributing something different from the thing that passed your testsuite. And that's bad IMO.
geekosaur@geekosaur:matrix.org: The only possible solution there is to tighten the dependencies in the cabal file. Think about it
If the test suite depends on the library being tested, their transitive dependencies must match
@irc_libera.chat___monty__:kf8nh.com: You're right that you wouldn't be able to test a library by doing `import Quickcheck; import library`. So if that is your chosen method of testing I think it should always constrain all the components.
geekosaur@geekosaur:matrix.org: And you have the problem anyway if you don't lock down the dependencies in the cabal file anyway because you don't know if the person installing it has the same Hackage snapshot (cabal update)
Or is using a different snapshot by e.g. having the cardano repo first
Basically the whole ecosystem isn't designed for reproducibility
Which is a major reason for stack and nix, which at least try to
@irc_libera.chat___monty__:kf8nh.com: "The problem" being? I don't actually mind a hackage user getting a different build plan, as long as the build plan is testable, i.e. running cabal test wouldn't rebuild the thing under test.
Artem: Yes, that's the crux of the issue. Well, applied to sub libraries, I guess
@irc_libera.chat___monty__:kf8nh.com: "The problem" being? I don't actually mind a hackage user getting a different build plan, as long as the build plan is testable, i.e. running cabal test wouldn't rebuild the thing under test.
geekosaur@geekosaur:matrix.org: then turn on --enable-tests
but note that they can't actually test very well unless they make a project for it, I think
and the result might still get rebuilt later when using the library if the constraints are different at that point, including by not including test suite dependencies
cabal does this all the time anyway because cabal update can change transitive dependencies
Artem: Correct. And there's a workaround for that too: index-state. We just have to think about different people having different ideas about it and being able to peacefully coexist. Currently, the package authors with sub libraries seem in a tough spot
geekosaur@geekosaur:matrix.org: there's also changing ghc options, etc. if you really want reproducibility you currently have to think about a lot of things
@irc_libera.chat___monty__:kf8nh.com: Yes, the testsuite issue is very complicated, that's why I didn't want it derailing the original point.
geekosaur@geekosaur:matrix.org: You're not the only one raising it, BTW, maerwald has been complaining about it for a while (but also about how nobody ever does it)
@irc_libera.chat___monty__:kf8nh.com
I think I feel most sympathetic to, building in a package, compute the plan for all the components. Building as a dependency only, build just the necessary components.
geekosaur@geekosaur:matrix.org: but the issues were opened by people who think the latter should apply to packages as well
@irc_libera.chat___monty__:kf8nh.com: I think I feel most sympathetic to, building in a package, compute the plan for all the components. Building as a dependency only, build just the necessary components.
Artem: I agree with this with addition: having a way to request solving/building one component in the local package
@irc_libera.chat___monty__:kf8nh.com: Sure, I'm always in favor of giving the user more control. The default behavior should be as unsurprising and convenient as possible though.
(apologies for confusion, matrix isn't designed for cut and paste. but the link will force you to install a Matrix client)
Activity
sebright commentedon Nov 5, 2016
Here are my thoughts, so far. At a minimum, the solver should keep track of dependencies between packages' components. (I think that it currently tracks dependencies from components to packages.) Then it can stop requiring dependencies of components that aren't needed, and ensure that required components are buildable. The solver should still ensure that all components within a package are consistent (have the same version and flag assignments), unless they have different qualifiers. Maybe we can add a flag or use private dependencies to relax that restriction later.
ezyang commentedon Nov 7, 2016
@GrayJay, thanks for making this ticket. Your plan seems eminently reasonable. Go for it!
sebright commentedon Mar 20, 2017
Here is a first pass at a design:
Summary
boolean variable for each component. However, the nodes of the dependency
graph are components.
Cabal version, Buildable field value, component enabled/disabled, and
--enable-tests/benchmarks. This design would also fix Non-buildable components don't work with new-build and pre-1.24 Custom setups #3881.constraints.
Tree structure
solver, which means that we also need to change the goals, as well as the
choice nodes created for those goals.
Variables
variables, stanza variables, or something new):
except that they aren't in the
.cabalfile. They need to be added whenthe solver converts the package indexes to the solver-specific index
format.
stanza variables.
Required and Not RequiredOn and Off.RequiredOn:top-level target, or it is a dependency of another component.
Buildable: Falseis treated as a failure.Not RequiredOff:because of an old Cabal setup version or
--enable-tests/benchmarks.Old.
Cabal >= 1.24 for the Custom build type.
type.
though the components are allowed to have
Buildable: False.components when tests (or benchmarks) are enabled, though they may
also be unbuildable.
builds? Do we only need the setup Cabal version and build type?
support per-component builds.
might break packages that only constrain dependencies for one component
(usually the library).
--enable-tests/benchmarksneeds to find all tests/benchmarks in thepackage.
ever need to build components with conflicting dependencies, we can use
qualified goals.
add all flag-like goals for that instance to the set of remaining goals.
TODO: How do we handle component goals for installed packages? Do we know
which executables are available? Can we find all components by package name
and version in the installed package index?
as before.
Index conversion
implement the behavior of the flag-like goals described above.
dependency tree in order to ignore dependencies of unbuildable components
(Tests for #2731 (Ignore dependencies that are not Buildable) #3039).
Exe/lib component transformation
Sayxrepresents the contents of an executable stanza (The same applies tolibraries).
xwould be transformed into:Test/benchmark component transformation:
xrepresents the contents of a test suite stanza. The transformation islike the lib/exe transformation, except that it also uses the
tests-enabledflag.
Dependency graph
between packages? It would fix Handle apparent package dependency cycles due to test suites / benchmarks #1575, but it may be a worse fix than Allow "cycles" through test suite dependencies #3422.
(It wouldn't allow a test framework to depend on an installed version of the
package under test.)
Custom setup validation steps
"setup script features" variable is consistent with the actual features of
the setup script. We could combine these two transformations if it turns out
to be simpler.
package that has Custom build type and a setup Cabal version that is less than
1.24.
package that chose "New" for the "setup script features" variable.
either order.)
Component dependency validation steps
existing validation phase transformations.
The package instance must contain the right component, and the component must
be enabled.
looking at
build-depends,tool-depends, and build targets.of the components that are required so far.
choice.
descending the search tree:
add all components provided by that instance to the component set.
component from the component set.
build-dependsortool-depends, check that if the package was visited then the component isavailable. If the component is not available, prune the choice that
introduced the dependency.
Enabling tests/benchmarks
--enable-tests/benchmarksdoesn't need to change much. The current stanzavariables have the same behavior as the flag-like variables I described above.
Internal dependencies
dependency between components is handled as a dependency on an exact package
version, so that both components come from the same package instance.
More questions
solver could try to build the component by flipping flags, but then the
install plan would depend on the list of targets. This problem is very
similar to 'cabal new-build test:test-suite' doesn't force tests to be enabled. #3923, except that it deals with enabling components instead of
tests.
Should we just translate it to
--enable-tests? This problem also relates to'cabal new-build test:test-suite' doesn't force tests to be enabled. #3923.
/cc @kosmikus @ezyang @Ericson2314 @dcoutts @edsko @hvr @23Skidoo
ezyang commentedon Mar 20, 2017
Thanks, this looks great.
Per-component occurs if and only if:
--disable-per-componentis not specifiedThe canonical source of truth is
why_not_per_componentin ProjectPlanning. Probably best to just cross-reference two sites for now.But note that to fix things like #3732 we'll have to relax how we do the constraints here. I guess this is covered by what you say later: "If we
ever need to build components with conflicting dependencies, we can use
qualified goals."
At the moment, we won't know anything about executables, but we don't have to, because new-build will never have those as "installed" packages.
Internal libraries pose a special problem, because they show up in the installed package index (I recently committed a hack to handle this case). With our current featureset, we are allowed to assume that any internal library in the installed package index can only be reached by a corresponding "public" library from the package (so the "correct" way to handle internal libraries is to bundle them all up together with the public library into one 'package node'). The hacked code doesn't actually do this but that's what should be done morally.
Perhaps there should be a distinction made between "build targets" (what am I going to build this round) and "solver targets" (please work hard to dep solve so that X is buildable.) The latter is stable and shouldn't change even if you decide to build different things. This should solve the next bullet point too.
sebright commentedon Mar 25, 2017
Thanks for the feedback!
I see that I had this part backwards. These rules simplify things, because the solver doesn't need to choose whether to use per-component build for each package; there is only one choice. In that case, I think that we don't need to add the "setup script features" variables, for now.
I had also incorrectly assumed that every package that ignores dependencies of unbuildable components also supports per-component build. Since the two attributes are not linked, I think we should handle #3881 separately.
I'm not sure that we should make cabal find a solution for the example at the top of #3732, which only constrains
basein one component. It looks the same as a package where the author meant for the constraint onbaseto apply to all components but wanted to avoid duplication. I haven't searched Hackage to see how common that pattern is, though.Per-component solving would still allow more flexibility in less extreme cases, even if it always applied all build-depends constraints. Take this example:
Say that
x > 2andy < 3have conflicting constraints onz. Then per-component solving would allow exe1 and exe2 to be installed separately while the current solver wouldn't find a solution.Qualified goals would only help by allowing components that were independently solvable to be solvable together with different qualifiers (possibly using different versions of the package containing the components).
Okay, so cabal will behave as if those package instances provided libraries but not executables.
I'm not sure I understand this part. Can we always reach all of the internal libraries if we have the main library from the installed package index? I think that is all the solver needs to do.
That distinction makes sense. I still don't know how we should choose those two sets of targets, though.
For "solver targets", maybe we should just give the solver a list of packages to solve for and apply a preference to build all components within each of those packages. Is there any situation where we would want to give the solver a subset of a package's components as targets?
hvr commentedon Mar 25, 2017
re
IMO a better way to avoid duplication is to make it more explicit that multiple components ought to share common dependencies/constraints via the likes of #2832, and then we could unlock/enable per-component solving also in the aforementioned case when a high enough
cabal-version:value is set (c.f. to how the semantics forbuild-depends& multiple components changed betweencabal-version1.6 and 1.8)ezyang commentedon Mar 27, 2017
Yeah, but I think the converse is true (per-component = correct handling of non-buildable components.)
Not necessarily. For example, we may have registered an internal library which was only linked by the test suite, but not by the actual public library of a package. @dcoutts would probably say that this just means we shouldn't have registered it but it seems better to me to not assume any relationship without tracing the dependency relations.
Yeah I'm not sure what the default should be. What we have right now is best effort which seems to work decently well, so maybe every component would have a designation like, "never", "best-effort", "always", with everything defaulting to best-effort.
Solver: Detect cycles between packages and their setup scripts (fixes h…
Solver: Detect cycles between packages and their setup scripts (fixes h…
Solver: Enforce dependencies on libraries (fixes haskell#779).
Solver: Enforce dependencies on libraries (fixes haskell#779).
Solver: Enforce dependencies on libraries (fixes #779).
22 remaining items
geekosaur commentedon Sep 19, 2025
The problem I described applies in either direction, not just under a hypothetical
Bdepending onB:foo. The expectation in fact isB:foodepending onB, so ensuring thatBandB:foohave compatible dependencies is necessary.lehins commentedon Sep 19, 2025
@geekosaur I am talking about the case when
B:librarydoes NOT depend onB:foo. That is the most common case that I've seen with sub libraries. In which case we need to care whetherB:foois buildable only when something else depends on it or when we are doingcabal build B!ulysses4ever commentedon Sep 19, 2025
@geekosaur I don't think it's debatable whether this feature is needed given the extensive net of issues in the OP and the number of high-profile figures involved in those. Also, I totally get what @lehins says, and I'm very fuzzy on what you're saying: I am sort of kind of able to see the argument that forcing "collective" solving of all components in a package may have some benefits in terms of consistency between different components but it's a very hand-wawy argument, I feel. If component-aware solving was running into a real roadblock w r.t. consistency of build, that would be spotted by Kristen in her plan (see the link below), I'm sure of it. There might be some corner cases, sure. But we must optimize for general problems, not corner cases. And prior discussions are pretty clear that this feature would solve a bunch of big pain points.
A pinch of optimism: a design was laid out long time ago: #4087 (comment) Someone just needs to put the time to realize it.
phadej commentedon Sep 19, 2025
@ulysses4ever
Consistent solving (picking only one package version) and per-component solving (picking only requested components) are orthogonal issues.
Currently
cabal-installsolver solves for all components even if not all are requested. Luckily unrequested components are not built, but still, they affect the build plan. IfB:foodepends onB, but downstream depends onBonly, thenB:foodependencies should not affect the build plan.@lehins
THis is the first time I hear this. If you have some issues, please report them. Otherwise, don't complain "behind maintainers back".
geekosaur commentedon Sep 19, 2025
So am I, and I thought I made that quite clear in my last message. Why do you think otherwise?
geekosaur commentedon Sep 19, 2025
Okay, apparently I am failing to speak English tonight. I really do not understand what is backwards or fuzzy about "if
B:foodepends onBbut it was built with different dependencies thanB, it can't actually useB".And if this is not considered a problem, why do
--enable-testsand--enable-benchmarksexist when their purpose is to ensure a consistent build plan in those cases, as with this case?sebright commentedon Sep 19, 2025
Yes, there is a design, and we have implemented parts of it, such as checking that required components are available. I think that we should still move in this direction, and I've been checking that solver changes are compatible with this design as I review code. It would be great if we had the resources to implement solver variables to control whether each component is enabled, and I would be happy to help with design and code review. (EDIT: I also think that we could probably remove some of the cases handled in the original design.)
Consistency:
We might need to make a Cabal spec change when we allow the solver to turn off specific components, in order to avoid breaking packages that use bounds on one component to constrain all components.
phadej commentedon Sep 19, 2025
I don't think that were ever part of spec, and
cabal checkdoes warn about missing bounds on independent components:And even if there are packages which are relying on current behavior, they may be fixed with revisions. Not a big deal.
ulysses4ever commentedon Sep 19, 2025
@lehins I had a long chat with @geekosaur on Cabal''s matrix (welcome, by the way!). I think I was able to get his idea, and now I'll try to put it in a way that may (or may not) be more accessible. Brandon should feel free to correct me, and he probably will because we seem to be in disagreement still. But I still want to share in case it could help even if a bit :-)
The concern is real simple, and it's entirely performance related: imagine, B has B.lib (the default library) and B.foo (another component, say a private library). Under the current feature request, B.lib may end up having different versions of dependencies in the plan depending on whether it's built individually or as a part of B.foo. This should be perfectly valid in principle. But Brandon's concern is UX. Imagine a user who keeps building
Band thenB.fooand thenBagain, and so on. Switching between components will require re-solving and rebuildingBin this case.Overall, it seems like with the proposed feature, we get a degradation in UX for this particular use case: first, the plans for different components are different, second, you keep switching components. The reason I'm not so worried about this is as follows. While the first seems like it will be a common case (that's the whole reason why we want per-component solving), the second doesn't seem like a terribly important scenario to me. Also, there is a simple workaround for it: if you need to switch between B.lib and B.foo all the time and you're bothered by the snags, just say
cabal build B B:foo, which will hopefully give you what you want without re-solving/re-building all the time. Now, you can find corner cases like several dozen components in a package and wanting to switch between half of them, then it's tedious to name all of them, and you don't want to go the full-blowncabal build all(which is a perfectly valid workaround too IMO). But this path seems to have vanishing importance, so I really don't see it as a show stopper. I wonder what others think..lehins commentedon Sep 19, 2025
@phadej I would not dare to complain behind your back. I was more than sure you'd be following this conversation. Instances for
vectorinquickcheck-instancesare fine for the regular user ofvector, but they are suboptimal for anyone who is trying to test their more advanced uses ofvector. In particular vectors inquickcheck-instancesare always constructed from a list, which never produces vectors that have a non-zero offset, which is critical for testing more advance or unsafe uses of vector.My goal in this comment was not to complain about
quickcheck-classes. The point I was trying to bring across is that it should not be your responsibility to maintain a package like that. It should be responsibility of actual package maintainers, likevectorto provide functionality for generating random valid values like Arbitrary, because actual maintainers have all the intrinsic knowledge about potential corner cases. The thing that I am trying to stress here is that sublibraries would allow us to do that, if this dependency resolution issue is solved.Shimuuar commentedon Sep 19, 2025
We may want to treat packages under development and dependencies differently. So if there package
fooand main library and sublibrariesbarandbazand I'm working on it. Then it makes sense to solve for all component. But if I work on some package that depends onfooand only usefoo:libthere's no point in solving forfoo:bar,foo:baz.Current state of affair limits usefulness of public sublibraries. Why one would move code into sublibrary? One of main reasons: because it depends on something that main library shouldn't (see example with Arbitrary instances).
ulysses4ever commentedon Sep 19, 2025
I don't think anyone contends this point. The question is what should be the path forward. And the answer has to be debated and all pros and cons are better discovered before an actual implementation happens.
That sounds like a neat idea. It does tap into the complexity budget sadly, which Cabal doesn't have much to spare. But maybe it's the way to go. I'd be interested in hearing @sebright's thoughts.
One thing I say about this idea is: I hope there will be a way to solve/build individual components in local packages anyway.
sebright commentedon Sep 20, 2025
The design above treats top-level packages (packages in
cabal.projector arguments to theinstallcommand) differently than dependencies, though we never decided exactly how to determine the list of "solver targets". After seeing the outcome of making test targets optional in v2 build, including issues like #7883, I now think that we should solve for all components of top-level packages by default. However, the set of targets could still be reduced with manual flags and the "buildable" field, as is possible today.@ulysses4ever Which idea are you referring to?
ulysses4ever commentedon Sep 20, 2025
@sebright the one about treating local packages differently. So, you just opined on it, thank you!
geekosaur commentedon Sep 20, 2025
From Matrix last night:
(apologies for confusion, matrix isn't designed for cut and paste. but the link will force you to install a Matrix client)