sjakobi / haddock

Haskell Documentation Tool
www.haskell.org/haddock/
Other
0 stars 0 forks source link

Disparity of avails between mi_exports and docs_structure #24

Closed sjakobi closed 6 years ago

sjakobi commented 6 years ago
$ inplace/bin/ghc-stage2 -ddump-hi -fforce-recomp -haddock testsuite/tests/showIface/HaddockIssue849.hs
....snip...
exports:
  Data.Maybe.maybe
  Data.Tuple.curry
  Data.Tuple.fst
  Data.Tuple.snd
  Data.Tuple.swap
  Data.Tuple.uncurry
  GHC.Maybe.Maybe{GHC.Maybe.Just GHC.Maybe.Nothing}
...snip...
docs:
...snip...
       documentation structure:
         re-exported module(s): [Data.Functor.Identity]
           []
         re-exported module(s): [Data.Maybe]
           [GHC.Maybe.Maybe{GHC.Maybe.Maybe, GHC.Maybe.Nothing,
                            GHC.Maybe.Just;},
            Data.Maybe.maybe]
         re-exported module(s): [Data.Tuple]
           [Data.Tuple.fst, Data.Tuple.snd, Data.Tuple.curry, Data.Tuple.swap,
            Data.Tuple.uncurry]
...snip...

The strange bit is that Maybe is listed in the exports as

GHC.Maybe.Maybe{GHC.Maybe.Just GHC.Maybe.Nothing}

while docs_structure lists it as

GHC.Maybe.Maybe{GHC.Maybe.Maybe, GHC.Maybe.Nothing, GHC.Maybe.Just;}

Is the re-export of the Maybe type constructor implicit in the export list?

sjakobi commented 6 years ago

I think this is simply due to the use of pprExport in pprModIface:

{-
When printing export lists, we print like this:
        Avail   f               f
        AvailTC C [C, x, y]     C(x,y)
        AvailTC C [x, y]        C!(x,y)         -- Exporting x, y but not C
-}

pprExport :: IfaceExport -> SDoc
pprExport (Avail n)         = ppr n
pprExport (AvailTC _ [] []) = Outputable.empty
pprExport (AvailTC n ns0 fs)
  = case ns0 of
      (n':ns) | n==n' -> ppr n <> pp_export ns fs
      _               -> ppr n <> vbar <> pp_export ns0 fs
  where
    pp_export []    [] = Outputable.empty
    pp_export names fs = braces (hsep (map ppr names ++ map (ppr . flLabel) fs))

(Note the apparently outdated comment)

sjakobi commented 6 years ago

As I was wondering whether the format of the export list is unambiguous: It is!

In the case of

class C m where
  f :: m ()
  g :: m ()

We get Lib.C{Lib.f Lib.g} if C is exported, Lib.C|{Lib.f Lib.g} otherwise.

In the case of data types like Maybe there seems to be no way of exporting any constructors without the type constructor.