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

Commit b605510

Browse files
committed
wip
1 parent 191d77e commit b605510

File tree

5 files changed

+26
-21
lines changed

5 files changed

+26
-21
lines changed

haddock-api/haddock-api.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ library
5353

5454
, ghc-paths
5555
, haddock-library == 1.2.*
56+
, pipes
5657

5758
hs-source-dirs:
5859
src

haddock-api/src/Haddock.hs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ import Packages
7373
import Panic (handleGhcException)
7474
import Module
7575
import FastString
76+
import Pipes
7677

7778
--------------------------------------------------------------------------------
7879
-- * Exception handling
@@ -161,9 +162,9 @@ haddockWithGhc ghc args = handleTopExceptions $ do
161162
forM_ (warnings args) $ \warning -> do
162163
hPutStrLn stderr warning
163164

164-
ghc flags' $ do
165+
ghc flags' $ runEffect $ do
165166

166-
dflags <- getDynFlags
167+
dflags <- lift getDynFlags
167168

168169
if not (null files) then do
169170
(packages, ifaces, homeLinks) <- readPackagesAndProcessModules flags files
@@ -176,14 +177,15 @@ haddockWithGhc ghc args = handleTopExceptions $ do
176177
}
177178

178179
-- Render the interfaces.
179-
liftIO $ renderStep dflags flags qual packages ifaces
180+
lift $ liftIO $ renderStep dflags flags qual packages ifaces
180181

181182
else do
182183
when (any (`elem` [Flag_Html, Flag_Hoogle, Flag_LaTeX]) flags) $
183184
throwE "No input file(s)."
184185

185186
-- Get packages supplied with --read-interface.
186-
packages <- liftIO $ readInterfaceFiles freshNameCache (readIfaceArgs flags)
187+
readInterfaceFiles freshNameCache (readIfaceArgs flags)
188+
let packages = undefined
187189

188190
-- Render even though there are no input files (usually contents/index).
189191
liftIO $ renderStep dflags flags qual packages []
@@ -208,16 +210,12 @@ withGhc flags action = do
208210

209211

210212
readPackagesAndProcessModules :: [Flag] -> [String]
211-
-> Ghc ([(DocPaths, InterfaceFile)], [Interface], LinkEnv)
213+
-> Producer' Interface (StateT LinkEnv Ghc) ()
212214
readPackagesAndProcessModules flags files = do
213215
-- Get packages supplied with --read-interface.
214-
packages <- readInterfaceFiles nameCacheFromGhc (readIfaceArgs flags)
215-
216-
-- Create the interfaces -- this is the core part of Haddock.
217-
let ifaceFiles = map snd packages
218-
(ifaces, homeLinks) <- processModules (verbosity flags) files flags ifaceFiles
219-
220-
return (packages, ifaces, homeLinks)
216+
readInterfaceFiles nameCacheFromGhc (readIfaceArgs flags)
217+
>-> map snd
218+
>-> processModules (verbosity flags) files flags
221219

222220

223221
renderStep :: DynFlags -> [Flag] -> QualOption -> [(DocPaths, InterfaceFile)] -> [Interface] -> IO ()
@@ -365,19 +363,18 @@ modulePackageInfo dflags flags modu =
365363
readInterfaceFiles :: MonadIO m
366364
=> NameCacheAccessor m
367365
-> [(DocPaths, FilePath)]
368-
-> m [(DocPaths, InterfaceFile)]
366+
-> Producer' (DocPaths, InterfaceFile) m ()
369367
readInterfaceFiles name_cache_accessor pairs = do
370-
catMaybes `liftM` mapM tryReadIface pairs
368+
mapM_ tryReadIface pairs
371369
where
372370
-- try to read an interface, warn if we can't
373371
tryReadIface (paths, file) =
374-
readInterfaceFile name_cache_accessor file >>= \case
372+
lift (readInterfaceFile name_cache_accessor file) >>= \case
375373
Left err -> liftIO $ do
376374
putStrLn ("Warning: Cannot read " ++ file ++ ":")
377375
putStrLn (" " ++ err)
378376
putStrLn "Skipping this interface."
379-
return Nothing
380-
Right f -> return $ Just (paths, f)
377+
Right f -> yield (paths, f)
381378

382379

383380
-------------------------------------------------------------------------------

haddock-api/src/Haddock/Interface.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ import GHC hiding (verbosity)
5757
import HscTypes
5858
import FastString (unpackFS)
5959

60+
import Pipes
61+
6062
-- | Create 'Interface's and a link environment by typechecking the list of
6163
-- modules using the GHC API and processing the resulting syntax trees.
6264
processModules
@@ -65,11 +67,11 @@ processModules
6567
-- module topology
6668
-> [Flag] -- ^ Command-line flags
6769
-> [InterfaceFile] -- ^ Interface files of package dependencies
68-
-> Ghc ([Interface], LinkEnv) -- ^ Resulting list of interfaces and renaming
70+
-> Producer' Interface (StateT LinkEnv Ghc) () -- ^ Resulting list of interfaces and renaming
6971
-- environment
7072
processModules verbosity modules flags extIfaces = do
7173

72-
out verbosity verbose "Creating interfaces..."
74+
lift $ lift $ out verbosity verbose "Creating interfaces..."
7375
let instIfaceMap = Map.fromList [ (instMod iface, iface) | ext <- extIfaces
7476
, iface <- ifInstalledIfaces ext ]
7577
interfaces <- createIfaces0 verbosity modules flags instIfaceMap

haddock-api/src/Haddock/Interface/Specialize.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
{-# LANGUAGE Rank2Types #-}
33
{-# LANGUAGE ScopedTypeVariables #-}
44
{-# LANGUAGE RecordWildCards #-}
5+
{-# LANGUAGE BangPatterns #-}
6+
{-# LANGUAGE Strict #-}
57

68

79
module Haddock.Interface.Specialize
@@ -34,7 +36,8 @@ specialize :: (Eq name, Typeable name)
3436
=> Data a
3537
=> name -> HsType name -> a -> a
3638
specialize name details =
37-
everywhere $ mkT step
39+
let !a = everywhere $ mkT step
40+
in a
3841
where
3942
step (HsTyVar (L _ name')) | name == name' = details
4043
step typ = typ

haddock.cabal

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ executable haddock
6262
ghc-boot,
6363
ghc >= 7.11 && < 8.1,
6464
bytestring,
65-
transformers
65+
transformers,
66+
pipes
6667

6768
other-modules:
6869
ResponseFile,
@@ -121,6 +122,7 @@ executable haddock
121122
Haddock.Options
122123
Haddock.GhcUtils
123124
Haddock.Syb
125+
Haddock.Pipes
124126
Haddock.Convert
125127
else
126128
build-depends: haddock-api == 2.16.*

0 commit comments

Comments
 (0)