dhall-lang / dhall-haskell

Maintainable configuration files
https://dhall-lang.org/
BSD 3-Clause "New" or "Revised" License
914 stars 213 forks source link

Move library to `dhall-core` package #1102

Open f-f opened 5 years ago

f-f commented 5 years ago

As @Gabriel439 explained in https://github.com/dhall-lang/dhall-haskell/issues/1096#issuecomment-510963407:

the main issue we're running into is that the dhall package is actually doing two separate things:

  • Providing a native Haskell binding
  • Providing the dhall executable

If we could split out the native Haskell binding into a smaller separate package (i.e. dhall-core or dhall-api) and leave the dhall package for the executable (and re-exporting the Haskell API for backwards compatibility) then I'd have fewer reservations about adding extra dependencies to the dhall package. The reason why is that I'd like people using dhall as a native Haskell binding to have a smaller dependency footprint.

For example, if they were separate packages then somebody using the executable-free package to configure their Haskell program wouldn't need to depend on repline, aeson, aeson-pretty, Diff, dotgen, cborg-json, or ansi-terminal. Similarly, we could freely add dependencies like yaml to the executable package guilt-free.

I'll add that:

quasicomputational commented 5 years ago

Decoupling dependencies from the core would also make it a bit easier to do smoke testing and porting to new GHCs or particularly massive dependency bumps. aeson in particular would be nice to be able to selectively ignore, since it's a moderately complicated package that tends to need some porting work of its own.

jneira commented 5 years ago

It would be great too for eta and dhall-eta. However i would keep the lib part of dhall-json and friends in its own repos/packages, with the core suffix as suggested by @f-f

sjakobi commented 3 years ago

I've just made a pass over dhall's current direct dependencies. If we'd move the Dhall module and its module dependencies into a new library package, I expect that the new package wouldn't need to depend on the following non-boot packages:

All of these packages are pretty minimal though – limited gains IMHO.

To shed the aeson dependency (and transitive dependencies like dlist, strict, uuid-types) we'd also need to (re)move this FromJSON instance

https://github.com/dhall-lang/dhall-haskell/blob/6a1af03658d78165973358b9e91f1347e3ffaf4b/dhall/src/Dhall/Pretty/Internal.hs#L141-L145

, possibly to dhall-lsp-server where I believe it's being used.

I believe we'd need to keep the Diff dependency because it's being used to produce type error messages.

For additional dependency weight loss, we could try the following:

Lastly, I'd like to mention that users concerned about dhall's dependency footprint should check whether they require import resolution via HTTP, which can be disabled with -f-with-http.

mmhat commented 3 years ago

@sjakobi Thank you for your investigations on that topic!

sjakobi commented 3 years ago

I'm somewhat skeptical that we can remove Dhall.Optics without increasing our dependence on other heavy-weight packages. https://hackage.haskell.org/package/prolens is lightweight and looks interesting though…

Regarding Cabal flags: The problem I see with these is that they have to be enabled by the end user. AFAIK there's no way in Cabal to say "dhall should preferably be built with aeson-pretty:-flib-only and parsers:-f-attoparsec". Nevertheless it might be useful to compile the flag settings that minimize dhall's dependency footprint, so users can refer to them.

mmhat commented 3 years ago

I'm somewhat skeptical that we can remove Dhall.Optics without increasing our dependence on other heavy-weight packages. https://hackage.haskell.org/package/prolens is lightweight and looks interesting though…

I share your concerns but I think it might be worth getting those functions in some lightweight upstream library and depend on that. Like the author of #998 I am not really familiar with 'lens-family' and their policy. Note that 'microlens' already has rewriteOf, to and transformOf. (Not sure if the to defined there suites our needs though.)

I didn't know about prolens which indeed looks interesting!

Nevertheless it might be useful to compile the flag settings that minimize dhall's dependency footprint, so users can refer to them.

Well, that's all I had in mind ;-)

Gabriella439 commented 3 years ago

The recent discussion made me realize that there might be a more lightweight solution to this problem, which is to add a configure flag (e.g. -fno-cli or -f-cli) to disable the modules which are only used for the CLI (e.g. Dhall.Main). Then users who only want the Haskell API will have a lighter dependency footprint

mmhat commented 3 years ago

@Gabriel439 I see that solving this by a Cabal Flag is tempting but I see some downsides of this approach as well:

Personally I use Dhall mostly as a library and therefore I tend to prefer a split into two packages: dhall-core for the embedded usecase and dhall as a "frontend" of that library providing the executable.