Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.

Fix #1015 with dataConUserTyVars #1016

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Changes in TBA

* NewOcean is the new default theme (#721, #782, #949)
* "Linuwial" is the new default theme (#721, #782, #949)

* Fix style switcher (enabled by `--built-in-themes`) (#949)

Expand Down
6 changes: 3 additions & 3 deletions doc/invoking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ The following options are available:
reader can switch between themes with browsers that support
alternate style sheets, or with the "Style" menu that gets added
when the page is loaded. If no themes are specified, then just the
default built-in theme ("NewOcean") is used.
default built-in theme ("Linuwial") is used.

The path parameter can be one of:

Expand All @@ -307,11 +307,11 @@ The following options are available:
- A *CSS file*: The base name of the file becomes the name of the
theme.

- The *name* of a built-in theme ("NewOcean", "Ocean", or "Classic").
- The *name* of a built-in theme ("Linuwial", "Ocean", or "Classic").

.. option:: --built-in-themes

Includes the built-in themes ("NewOcean", "Ocean", and "Classic"). Can be
Includes the built-in themes ("Linuwial", "Ocean", and "Classic"). Can be
combined with :option:`--theme`. Note that order matters: The first
specified theme will be the default.

Expand Down
4 changes: 2 additions & 2 deletions ghc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ utils/haddock_dist_DATA_FILES += html/Ocean.theme/minus.gif
utils/haddock_dist_DATA_FILES += html/Ocean.theme/ocean.css
utils/haddock_dist_DATA_FILES += html/Ocean.theme/plus.gif
utils/haddock_dist_DATA_FILES += html/Ocean.theme/synopsis.png
utils/haddock_dist_DATA_FILES += html/NewOcean.std-theme/new-ocean.css
utils/haddock_dist_DATA_FILES += html/NewOcean.std-theme/synopsis.png
utils/haddock_dist_DATA_FILES += html/Linuwial.std-theme/linuwial.css
utils/haddock_dist_DATA_FILES += html/Linuwial.std-theme/synopsis.png
utils/haddock_dist_DATA_FILES += html/solarized.css
utils/haddock_dist_DATA_FILES += html/highlight.js
utils/haddock_dist_DATA_FILES += latex/haddock.sty
Expand Down
10 changes: 5 additions & 5 deletions haddock-api/haddock-api.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ data-files:
html/Ocean.theme/ocean.css
html/Ocean.theme/plus.gif
html/Ocean.theme/synopsis.png
html/NewOcean.std-theme/new-ocean.css
html/NewOcean.std-theme/synopsis.png
html/Linuwial.std-theme/linuwial.css
html/Linuwial.std-theme/synopsis.png
latex/haddock.sty

library
Expand Down Expand Up @@ -173,8 +173,8 @@ test-suite spec
, ghc-paths ^>= 0.1.0.9
, haddock-library ^>= 1.7.0
, xhtml ^>= 3000.2.2
, hspec >= 2.4.4 && < 2.6
, QuickCheck ^>= 2.11
, hspec >= 2.4.4 && < 2.7
, QuickCheck >= 2.11 && < 2.13

-- Versions for the dependencies below are transitively pinned by
-- the non-reinstallable `ghc` package and hence need no version
Expand All @@ -190,7 +190,7 @@ test-suite spec
, transformers

build-tool-depends:
hspec-discover:hspec-discover >= 2.4.4 && < 2.6
hspec-discover:hspec-discover >= 2.4.4 && < 2.7

source-repository head
type: git
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,13 @@ pre + pre {
margin-top: 0.5em;
}

blockquote {
border-left: 3px solid #c7a5d3;
background-color: #eee4f1;
margin: 0.5em;
padding: 0.0005em 0.3em 0.5em 0.5em;
}

.src {
background: #f4f4f4;
padding: 0.2em 0.5em;
Expand Down
6 changes: 1 addition & 5 deletions haddock-api/src/Haddock.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ import Packages
import Panic (handleGhcException)
import Module
import FastString
import qualified DynamicLoading

--------------------------------------------------------------------------------
-- * Exception handling
Expand Down Expand Up @@ -450,10 +449,7 @@ withGhc' libDir flags ghcActs = runGhc (Just libDir) $ do
-- that may need to be re-linked: Haddock doesn't do any
-- dynamic or static linking at all!
_ <- setSessionDynFlags dynflags''
hscenv <- GHC.getSession
dynflags''' <- liftIO (DynamicLoading.initializePlugins hscenv dynflags'')
_ <- setSessionDynFlags dynflags'''
ghcActs dynflags'''
ghcActs dynflags''
where

-- ignore sublists of flags that start with "+RTS" and end in "-RTS"
Expand Down
10 changes: 8 additions & 2 deletions haddock-api/src/Haddock/Backends/Hoogle.hs
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,14 @@ ppCtor dflags dat subdocs con@ConDeclH98 {}
-- docs for con_names on why it is a list to begin with.
name = commaSeparate dflags . map unL $ getConNames con

resType = apps $ map (reL . HsTyVar NoExt NotPromoted . reL) $
(tcdName dat) : [hsTyVarName v | L _ v@(UserTyVar _ _) <- hsQTvExplicit $ tyClDeclTyVars dat]
resType = let c = HsTyVar NoExt NotPromoted (noLoc (tcdName dat))
as = map (tyVarBndr2Type . unLoc) (hsQTvExplicit $ tyClDeclTyVars dat)
in apps (map noLoc (c : as))

tyVarBndr2Type :: HsTyVarBndr GhcRn -> HsType GhcRn
tyVarBndr2Type (UserTyVar _ n) = HsTyVar NoExt NotPromoted n
tyVarBndr2Type (KindedTyVar _ n k) = HsKindSig NoExt (noLoc (HsTyVar NoExt NotPromoted n)) k
tyVarBndr2Type (XTyVarBndr _) = panic "haddock:ppCtor"

ppCtor dflags _dat subdocs con@(ConDeclGADT { })
= concatMap (lookupCon dflags subdocs) (getConNames con) ++ f
Expand Down
51 changes: 29 additions & 22 deletions haddock-api/src/Haddock/Backends/LaTeX.hs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ ppTypeOrFunSig typ (doc, argDocs) (pref1, pref2, sep0) unicode
text "\\end{tabulary}\\par" $$
fromMaybe empty (documentationToLaTeX doc)

-- This splits up a type signature along `->` and adds docs (when they exist)
-- | This splits up a type signature along @->@ and adds docs (when they exist)
-- to the arguments. The output is a list of (leader/seperator, argument and
-- its doc)
ppSubSigLike :: Bool -- ^ unicode
Expand All @@ -474,13 +474,10 @@ ppSubSigLike unicode typ argDocs subdocs leader = do_args 0 leader typ
arg_doc n = rDoc . fmap _doc $ Map.lookup n argDocs

do_args :: Int -> LaTeX -> HsType DocNameI -> [(LaTeX, LaTeX)]
do_args _n leader (HsForAllTy _ tvs ltype)
= [ ( decltt leader
, decltt (hsep (forallSymbol unicode : ppTyVars tvs ++ [dot]))
<+> ppLType unicode ltype
) ]
do_args n leader (HsForAllTy _ tvs ltype)
= do_largs n (leader <+> decltt (ppForAllPart unicode tvs)) ltype
do_args n leader (HsQualTy _ lctxt ltype)
= (decltt leader, ppLContextNoArrow lctxt unicode <+> nl)
= (decltt leader, decltt (ppLContextNoArrow lctxt unicode) <+> nl)
: do_largs n (darrow unicode) ltype

do_args n leader (HsFunTy _ (L _ (HsRecTy _ fields)) r)
Expand Down Expand Up @@ -512,8 +509,9 @@ ppTypeSig nms ty unicode =
<+> ppType unicode ty


ppTyVars :: [LHsTyVarBndr DocNameI] -> [LaTeX]
ppTyVars = map (ppSymName . getName . hsLTyVarName)
-- | Pretty-print type variables.
ppTyVars :: Bool -> [LHsTyVarBndr DocNameI] -> [LaTeX]
ppTyVars unicode tvs = map (ppHsTyVarBndr unicode . unLoc) tvs


tyvarNames :: LHsQTyVars DocNameI -> [Name]
Expand Down Expand Up @@ -716,15 +714,21 @@ ppDataDecl pats instances subdocs doc dataDecl unicode =


-- ppConstrHdr is for (non-GADT) existentials constructors' syntax
ppConstrHdr :: Bool -> [Name] -> HsContext DocNameI -> Bool -> LaTeX
ppConstrHdr forall tvs ctxt unicode
= (if null tvs then empty else ppForall)
<+>
(if null ctxt then empty else ppContextNoArrow ctxt unicode <+> darrow unicode <+> text " ")
ppConstrHdr
:: Bool -- ^ print explicit foralls
-> [LHsTyVarBndr DocNameI] -- ^ type variables
-> HsContext DocNameI -- ^ context
-> Bool -- ^ unicode
-> LaTeX
ppConstrHdr forall_ tvs ctxt unicode = ppForall <> ppCtxt
where
ppForall = case forall of
True -> forallSymbol unicode <+> hsep (map ppName tvs) <+> text ". "
False -> empty
ppForall
| null tvs || not forall_ = empty
| otherwise = ppForAllPart unicode tvs

ppCtxt
| null ctxt = empty
| otherwise = ppContextNoArrow ctxt unicode <+> darrow unicode <> space


-- | Pretty-print a constructor
Expand Down Expand Up @@ -753,11 +757,10 @@ ppSideBySideConstr subdocs unicode leader (L _ con) =
-- First line of the constructor (no doc, no fields, single-line)
decl = case con of
ConDeclH98{ con_args = det
, con_ex_tvs = vars
, con_ex_tvs = tyVars
, con_forall = L _ forall_
, con_mb_cxt = cxt
} -> let tyVars = map (getName . hsLTyVarName) vars
context = unLoc (fromMaybe (noLoc []) cxt)
forall_ = False
} -> let context = unLoc (fromMaybe (noLoc []) cxt)
header_ = ppConstrHdr forall_ tyVars context unicode
in case det of
-- Prefix constructor, e.g. 'Just a'
Expand Down Expand Up @@ -1010,13 +1013,17 @@ ppKind unicode ki = ppr_mono_ty (reparenTypePrec PREC_TOP ki) unicode
-- Drop top-level for-all type variables in user style
-- since they are implicit in Haskell

ppForAllPart :: Bool -> [LHsTyVarBndr DocNameI] -> LaTeX
ppForAllPart unicode tvs = hsep (forallSymbol unicode : ppTyVars unicode tvs) <> dot


ppr_mono_lty :: LHsType DocNameI -> Bool -> LaTeX
ppr_mono_lty ty unicode = ppr_mono_ty (unLoc ty) unicode


ppr_mono_ty :: HsType DocNameI -> Bool -> LaTeX
ppr_mono_ty (HsForAllTy _ tvs ty) unicode
= sep [ hsep (forallSymbol unicode : ppTyVars tvs) <> dot
= sep [ ppForAllPart unicode tvs
, ppr_mono_lty ty unicode ]
ppr_mono_ty (HsQualTy _ ctxt ty) unicode
= sep [ ppLContext ctxt unicode
Expand Down
65 changes: 24 additions & 41 deletions haddock-api/src/Haddock/Backends/Xhtml/Decl.hs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ ppTypeOrFunSig summary links loc docnames typ (doc, argDocs) (pref1, pref2, sep)
curname = getName <$> listToMaybe docnames


-- This splits up a type signature along `->` and adds docs (when they exist) to
-- the arguments.
-- | This splits up a type signature along @->@ and adds docs (when they exist)
-- to the arguments.
--
-- If one passes in a list of the available subdocs, any top-level `HsRecTy`
-- found will be expanded out into their fields.
Expand All @@ -149,9 +149,7 @@ ppSubSigLike unicode qual typ argDocs subdocs sep emptyCtxts = do_args 0 sep typ

do_args :: Int -> Html -> HsType DocNameI -> [SubDecl]
do_args n leader (HsForAllTy _ tvs ltype)
= do_largs n leader' ltype
where
leader' = leader <+> ppForAll tvs unicode qual
= do_largs n (leader <+> ppForAllPart unicode qual tvs) ltype

do_args n leader (HsQualTy _ lctxt ltype)
| null (unLoc lctxt)
Expand Down Expand Up @@ -185,15 +183,6 @@ ppSubSigLike unicode qual typ argDocs subdocs sep emptyCtxts = do_args 0 sep typ
gadtOpen = toHtml "{"



ppForAll :: [LHsTyVarBndr DocNameI] -> Unicode -> Qualification -> Html
ppForAll tvs unicode qual =
case [ppKTv n k | L _ (KindedTyVar _ (L _ n) k) <- tvs] of
[] -> noHtml
ts -> forallSymbol unicode <+> hsep ts +++ dot
where ppKTv n k = parens $
ppTyName (getName n) <+> dcolon unicode <+> ppLKind unicode qual k

ppFixities :: [(DocName, Fixity)] -> Qualification -> Html
ppFixities [] _ = noHtml
ppFixities fs qual = foldr1 (+++) (map ppFix uniq_fs) +++ rightEdge
Expand Down Expand Up @@ -258,10 +247,6 @@ ppTypeSig summary nms pp_ty unicode =
htmlNames = intersperse (stringToHtml ", ") $ map (ppBinder summary) nms


ppTyName :: Name -> Html
ppTyName = ppName Prefix


ppSimpleSig :: LinksInfo -> Splice -> Unicode -> Qualification -> HideEmptyContexts -> SrcSpan
-> [DocName] -> HsType DocNameI
-> Html
Expand Down Expand Up @@ -814,24 +799,23 @@ ppShortConstrParts :: Bool -> Bool -> ConDecl DocNameI -> Unicode -> Qualificati
ppShortConstrParts summary dataInst con unicode qual
= case con of
ConDeclH98{ con_args = det
, con_ex_tvs = vars
, con_ex_tvs = tyVars
, con_forall = L _ forall_
, con_mb_cxt = cxt
} -> let tyVars = map (getName . hsLTyVarName) vars
context = unLoc (fromMaybe (noLoc []) cxt)
forall_ = False
} -> let context = unLoc (fromMaybe (noLoc []) cxt)
header_ = ppConstrHdr forall_ tyVars context unicode qual
in case det of

-- Prefix constructor, e.g. 'Just a'
PrefixCon args ->
( header_ +++ hsep (ppOcc : map (ppLParendType unicode qual HideEmptyContexts) args)
( header_ <+> hsep (ppOcc : map (ppLParendType unicode qual HideEmptyContexts) args)
, noHtml
, noHtml
)

-- Record constructor, e.g. 'Identity { runIdentity :: a }'
RecCon (L _ fields) ->
( header_ +++ ppOcc <+> char '{'
( header_ <+> ppOcc <+> char '{'
, shortSubDecls dataInst [ ppShortField summary unicode qual field
| L _ field <- fields
]
Expand All @@ -840,7 +824,7 @@ ppShortConstrParts summary dataInst con unicode qual

-- Infix constructor, e.g. 'a :| [a]'
InfixCon arg1 arg2 ->
( header_ +++ hsep [ ppLParendType unicode qual HideEmptyContexts arg1
( header_ <+> hsep [ ppLParendType unicode qual HideEmptyContexts arg1
, ppOccInfix
, ppLParendType unicode qual HideEmptyContexts arg2
]
Expand Down Expand Up @@ -888,28 +872,27 @@ ppSideBySideConstr subdocs fixities unicode pkg qual (L _ con)

decl = case con of
ConDeclH98{ con_args = det
, con_ex_tvs = vars
, con_ex_tvs = tyVars
, con_forall = L _ forall_
, con_mb_cxt = cxt
} -> let tyVars = map (getName . hsLTyVarName) vars
context = unLoc (fromMaybe (noLoc []) cxt)
forall_ = False
} -> let context = unLoc (fromMaybe (noLoc []) cxt)
header_ = ppConstrHdr forall_ tyVars context unicode qual
in case det of
-- Prefix constructor, e.g. 'Just a'
PrefixCon args
| hasArgDocs -> header_ +++ ppOcc <+> fixity
| otherwise -> hsep [ header_ +++ ppOcc
| hasArgDocs -> header_ <+> ppOcc <+> fixity
| otherwise -> hsep [ header_ <+> ppOcc
, hsep (map (ppLParendType unicode qual HideEmptyContexts) args)
, fixity
]

-- Record constructor, e.g. 'Identity { runIdentity :: a }'
RecCon _ -> header_ +++ ppOcc <+> fixity
RecCon _ -> header_ <+> ppOcc <+> fixity

-- Infix constructor, e.g. 'a :| [a]'
InfixCon arg1 arg2
| hasArgDocs -> header_ +++ ppOcc <+> fixity
| otherwise -> hsep [ header_ +++ ppLParendType unicode qual HideEmptyContexts arg1
| hasArgDocs -> header_ <+> ppOcc <+> fixity
| otherwise -> hsep [ header_ <+> ppLParendType unicode qual HideEmptyContexts arg1
, ppOccInfix
, ppLParendType unicode qual HideEmptyContexts arg2
, fixity
Expand Down Expand Up @@ -962,17 +945,17 @@ ppSideBySideConstr subdocs fixities unicode pkg qual (L _ con)


-- ppConstrHdr is for (non-GADT) existentials constructors' syntax
ppConstrHdr :: Bool -- ^ print explicit foralls
-> [Name] -- ^ type variables
-> HsContext DocNameI -- ^ context
-> Unicode -> Qualification -> Html
ppConstrHdr
:: Bool -- ^ print explicit foralls
-> [LHsTyVarBndr DocNameI] -- ^ type variables
-> HsContext DocNameI -- ^ context
-> Unicode -> Qualification
-> Html
ppConstrHdr forall_ tvs ctxt unicode qual = ppForall +++ ppCtxt
where
ppForall
| null tvs || not forall_ = noHtml
| otherwise = forallSymbol unicode
<+> hsep (map (ppName Prefix) tvs)
<+> toHtml ". "
| otherwise = ppForAllPart unicode qual tvs

ppCtxt
| null ctxt = noHtml
Expand Down
2 changes: 1 addition & 1 deletion haddock-api/src/Haddock/Backends/Xhtml/Themes.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ standardTheme :: FilePath -> IO PossibleThemes
standardTheme libDir = liftM (liftEither (take 1)) (defaultThemes libDir)


-- | Default themes that are part of Haddock; added with --default-themes
-- | Default themes that are part of Haddock; added with @--built-in-themes@
-- The first theme in this list is considered the standard theme.
-- Themes are "discovered" by scanning the html sub-dir of the libDir,
-- and looking for directories with the extension .theme or .std-theme.
Expand Down
Loading