sjakobi / haddock

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

Aliases are expanded #6

Closed sjakobi closed 6 years ago

sjakobi commented 6 years ago

In microlens we currently generate

image

for what should be

image

sjakobi commented 6 years ago

Surprisingly, the .hi-files seem to use the alias we want:

_Right :: Traversal (Either a b) (Either a b') b b'
alexbiehl commented 6 years ago

Is this from show-hi?

Simon Jakobi notifications@github.com schrieb am Mo., 16. Juli 2018, 14:48:

Surprisingly, the .hi-files seem to use the alias we want:

_Right :: Traversal (Either a b) (Either a b') b b'

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/sjakobi/haddock/issues/6#issuecomment-405236162, or mute the thread https://github.com/notifications/unsubscribe-auth/AByiif6rvQ4Sq1fxHyn3Ypo-wH-7Sm0Uks5uHIuVgaJpZM4VRCz4 .

alexbiehl commented 6 years ago

Maybe something is expanding type synonyms in haddock.

sjakobi commented 6 years ago

Is this from show-hi?

That's how --show-iface dumps the .hi-file.

sjakobi commented 6 years ago

Using hiDecl instead of generating the HsDecl in mkDeclMap doesn't seem to have caused this issue.

sjakobi commented 6 years ago

The problem seems to be somewhere in tyThingToLHsDecl. The TyThing we find in hiDecl still has the alias according to pprTyThing showToIface.

sjakobi commented 6 years ago

Aliases aren't expanded in every case:

{-# language RankNTypes #-}
module Lib where

type Traversal s t a b = forall f. Applicative f => (a -> f b) -> s -> f t

-- Fails
_Right :: Traversal (Either a b) (Either a b') b b'
_Right f (Right b) = Right <$> f b
_Right _ (Left a) = pure (Left a)

type Unit = ()

-- Works
x :: Unit
x = ()
RyanGlScott commented 6 years ago

Ugh, I know why this is happening. It's due to these lines in synifyType:

https://github.com/haskell/haddock/blob/4abf7d4979b5364da59f7412a3d7143aea26cf7e/haddock-api/src/Haddock/Convert.hs#L517-L520

In particular, this calls tcSplitSigmaTy, which in turn invokes two functions (splitForAllTys and tcSplitPredFunTy_maybe) that expand type synonyms. This also explains why this doesn't affect type Unit = (), as this code is only ever called for types with a forall at the front.

I'm not sure of a way to work around this other than developing a counterpart to tcSplitSigmaTy that doesn't expand type synonyms...

sjakobi commented 6 years ago

Let's discuss this further at https://github.com/haskell/haddock/issues/879.