[GHC] #15129: Expose ghc-pkg internals as a library

GHC ghc-devs at haskell.org
Mon May 7 23:09:43 UTC 2018


#15129: Expose ghc-pkg internals as a library
-------------------------------------+-------------------------------------
           Reporter:  ryanreich      |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  normal         |         Milestone:  8.6.1
          Component:  Core           |           Version:  8.2.2
  Libraries                          |
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 The module [https://downloads.haskell.org/~ghc/latest/docs/html/libraries
 /ghc-boot-8.4.1/GHC-PackageDb.html GHC.PackageDb], which is in the `ghc-
 boot` package and therefore shipped alongside `base`, and which exposes
 the crucial data type `InstalledPackageInfo a b c d e f g` and functions
 `readPackageDbForGhc`, `readPackageDbForGhcPkg`, and `writePackageDb`, is
 nonetheless crippled outside of GHC:

 - The first function requires instances of the `BinaryStringRep` and
 `DbUnitIdModuleRep` classes, which do not have any in any public package

 - The second one uses a polymorphic parameter that, in order to run
 without error, actually needs to be
 [https://downloads.haskell.org/~ghc/latest/docs/html/libraries/Cabal-2.2.0.0
 /Distribution-InstalledPackageInfo.html
 Distribution.InstalledPackageInfo], defined in the completely different
 `Cabal` package neither mentioning nor mentioned by `ghc-boot`

 - The third one takes two arguments of which the first (a list of
 `InstalledPackageInfo a b c d e f g`) is redundant because it can be
 constructed from the second, but no conversion function is defined.

 While it is possible to write both the instances and conversion function
 by hand, it is extremely awkward and I worry that it is also fragile,
 given the internal nature of this entire module.

 The full functionality of this package is only available within the
 [https://github.com/ghc/ghc/blob/master/utils/ghc-pkg/Main.hs Main] module
 of `ghc-pkg`, which is highly monolithic despite containing such
 [https://github.com/ghc/ghc/blob/master/utils/ghc-pkg/Main.hs#L1226-L1307
 generally useful code] as the above instances and conversion function.
 Since `GHC.PackageDb` provides so much of `ghc-pkg`'s essential
 functionality as a library, it seems reasonable to request that this code
 be brought out of the opaque `Main` module and into a public library.  I
 understand from the comments that `ghc-boot` is not the place for this,
 but perhaps one of the following is:

 a. `Cabal`, because it already has the `InstalledPackageInfo` (no
 parameters) type used by `ghc-pkg`; however, `Cabal` seems committed to
 calling `ghc-pkg` as an executable, not providing linkage to its
 internals.

 b. a separate `ghc-pkg` library containing, possibly, a more carefully
 chosen selection of that executable's code.

-- 
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15129>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list