cabal icon indicating copy to clipboard operation
cabal copied to clipboard

Add fake-depends

Open phadej opened this issue 5 months ago • 14 comments

Describe the feature request

fake-depends is a field like build-depends which would constraint solver, but otherwise do nothing.

It's sometimes (rarely, but nevertheless) needed to add a constraint, but the dependency is not (at least directly) used anywhere. It would be great if .cabal format had a way to explicitly specify that.

One (bad) example is to use fake-depends: QuickCheck with build-depends: tasty-quickcheck. You can import everything through tasty-quickcheck re-exports, but you may need to constraint underlying QuickCheck. Arguably tasty-quickcheck shouldn't re-export anything, or at least properly version own (re)exports. But here we are.

See export-depends in #11052 for another semantically more precise dependency specification field.

phadej avatar Jul 08 '25 16:07 phadej

Similar example: A dependency d has an incorrect bound on t (e.g. no upper bound), hence the user of d may currently need to add a dependency on t -- just to tighten the bound -- even though t is purely transitive. I recall having to do this when aeson-2 came out.

Bikeshedding: Could also be called solver-depends, solving-depends.

tbidne avatar Jul 08 '25 23:07 tbidne

I think this is the same feature as #9558.

sebright avatar Jul 09 '25 06:07 sebright

I'm not convinced this belongs in cabal. For sure, I actually make use of the first example (did so 2 days ago, in fact), but I just used build-depends and disabled -Wall since my App.hs was main = putStrLn "hi". The other example is best covered by using cabal.project.local while petitioning the Hackage trustees for a metadata update on the broken package; doing it in a cabal file not only distributes the pain to victims, it hides the symptoms of the actual problem.

geekosaur avatar Jul 09 '25 14:07 geekosaur

@geekosaur

Suggesting -Wno-.... is not an option. The .cabal format should allow us to express things in a way so we don't need to disable legit warnings. (Of course ignoring a warning is an option, but there SHOULD be a way to do things "correctly").

using cabal.project.local is not an option for packages to be uploaded on Hackage. We "bundle" the extra constraints into uploaded metadata. And this issue is exactly about being able to do that.

(Don't mix Cabal and cabal-install issue. cabal.project.local won't work for stack users / Stackage curators).

phadej avatar Jul 10 '25 12:07 phadej

is export-depends the same as fake-depends semantically?

gbaz avatar Jul 30 '25 19:07 gbaz

@gbaz No. export-depends is for reexported-modules. If export-depends is changed to fake-depends reexported-modules could break.

In other words, export-depends is not true build-depends (GHC doesn't care while compiling the modules), but its not "fake" dependency. It must be written to package configuration file for re-exported modules to exist.

fake-depends only constraint the solver.

phadej avatar Jul 30 '25 19:07 phadej

I need this because of hashable: I depend on it transitively and observe different hashing of things, which makes me unable to write tests (sans workarounds like testing against several possibilities). I'd rather pin hashable to something producing a known-in-advance result.

ulysses4ever avatar Sep 16 '25 13:09 ulysses4ever

The only thing I truly dislike about this is the name.

That said, I realized on looking things over that cabal's own test suite would benefit from it: see https://github.com/haskell/cabal/blob/master/cabal-testsuite/cabal-testsuite.cabal#L122-L150 .

geekosaur avatar Sep 16 '25 15:09 geekosaur

I'm not attached to the name, any better suggestions? Maybe phantom-depends, is it any better?

phadej avatar Sep 16 '25 15:09 phadej

Sounds better to me, if only because we already have e.g. "phantom types" in the ecosystem. "Phantom" to me says it's not used directly but may be used indirectly, which seems to cover all the suggested use cases; "fake" just sounds like an ugly hack. Granting that the potential use I pointed to just above probably is one.

geekosaur avatar Sep 16 '25 15:09 geekosaur

@geekosaur no it won't. Proposed semantics for fake-depends / phantom-depends is that they add constraints on the packages, but if those packages are not transitively needed by anything, they won't be included in the build plan.

phadej avatar Sep 16 '25 15:09 phadej

I like phantom-depends more too. I was also thinking about trans-depends (or transitive-depends), but maybe it's too narrow of a view?..

ulysses4ever avatar Sep 16 '25 20:09 ulysses4ever

Could the field just be called constraints, since the listed packages aren't treated as dependencies?

sebright avatar Oct 09 '25 19:10 sebright

@sebright that is an option, but it could be quite confusing, as it would be different from the cabal.project one.

phadej avatar Oct 09 '25 21:10 phadej