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

Commit 396961f

Browse files
committed
First progress
1 parent 5a0e41b commit 396961f

File tree

2 files changed

+136
-1
lines changed

2 files changed

+136
-1
lines changed

haddock-api/src/Haddock/Interface.hs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ import FastString (unpackFS)
6060
import MonadUtils (liftIO)
6161
import TcRnTypes (tcg_rdr_env)
6262
import RdrName (plusGlobalRdrEnv)
63+
import ExtractDocs
64+
import Outputable
65+
import LoadIface
66+
import MkIface
6367

6468
#if defined(mingw32_HOST_OS)
6569
import System.IO
@@ -177,11 +181,18 @@ processModule verbosity modsum flags modMap instIfaceMap = do
177181
ic_rn_gbl_env = ic_rn_gbl_env old_IC `plusGlobalRdrEnv` new_rdr_env
178182
} }
179183

184+
dm <- desugarModule tm
185+
hsc_env' <- getSession
186+
let mod_guts = dm_core_module dm
187+
let mod_details = snd (tm_internals_ tm)
188+
(_iface, _bl) <- liftIO $ mkIface hsc_env' Nothing mod_details mod_guts
189+
dflags <- getDynFlags
190+
-- liftIO $ putStrLn $ (showSDoc dflags . pprModIface) iface
191+
180192
if not $ isBootSummary modsum then do
181193
out verbosity verbose "Creating interface..."
182194
(interface, msg) <- runWriterGhc $ createInterface tm flags modMap instIfaceMap
183195
liftIO $ mapM_ putStrLn msg
184-
dflags <- getDynFlags
185196
let (haddockable, haddocked) = ifaceHaddockCoverage interface
186197
percentage = round (fromIntegral haddocked * 100 / fromIntegral haddockable :: Double) :: Int
187198
modString = moduleString (ifaceMod interface)

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

Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,130 @@ import BasicTypes ( StringLiteral(..), SourceText(..) )
6363
import qualified Outputable as O
6464
import HsDecls ( getConArgs )
6565

66+
createInterface' :: ModIface
67+
-> [Flag] -- Boolean flags
68+
-> IfaceMap -- Locally processed modules
69+
-> InstIfaceMap -- External, already installed interfaces
70+
-> ErrMsgGhc Interface
71+
createInterface' mod_iface flags modMap instIfaceMap = do
72+
73+
let docs = mi_docs mod_iface
74+
ms = pm_mod_summary . tm_parsed_module $ tm
75+
mi = moduleInfo tm
76+
L _ hsm = parsedSource tm
77+
!safety = modInfoSafe mi
78+
mdl = mi_module mod_iface
79+
sem_mdl = tcg_semantic_mod (fst (tm_internals_ tm))
80+
is_sig = isJust (mi_sig_of mod_iface)
81+
dflags = ms_hspp_opts ms
82+
!instances = modInfoInstances mi
83+
!fam_instances = md_fam_insts md
84+
!exportedNames = modInfoExportsWithSelectors mi
85+
86+
(TcGblEnv { tcg_rdr_env = gre
87+
, tcg_warns = warnings
88+
, tcg_exports = all_exports
89+
}, md) = tm_internals_ tm
90+
91+
-- The renamed source should always be available to us, but it's best
92+
-- to be on the safe side.
93+
(group_, imports, mayExports, mayDocHeader) <-
94+
case renamedSource tm of
95+
Nothing -> do
96+
liftErrMsg $ tell [ "Warning: Renamed source is not available." ]
97+
return (emptyRnGroup, [], Nothing, Nothing)
98+
Just x -> return x
99+
100+
opts <- liftErrMsg $ mkDocOpts (haddockOptions dflags) flags mdl
101+
102+
-- Process the top-level module header documentation.
103+
(!info, mbDoc) <- liftErrMsg $ processModuleHeader dflags gre safety mayDocHeader
104+
105+
let declsWithDocs = topDecls group_
106+
107+
exports0 = fmap (reverse . map (first unLoc)) mayExports
108+
exports
109+
| OptIgnoreExports `elem` opts = Nothing
110+
| otherwise = exports0
111+
112+
unrestrictedImportedMods
113+
-- module re-exports are only possible with
114+
-- explicit export list
115+
| Just{} <- exports
116+
= unrestrictedModuleImports (map unLoc imports)
117+
| otherwise = M.empty
118+
119+
fixMap = mkFixMap group_
120+
(decls, _) = unzip declsWithDocs
121+
localInsts = filter (nameIsLocalOrFrom sem_mdl)
122+
$ map getName instances
123+
++ map getName fam_instances
124+
-- Locations of all TH splices
125+
splices = [ l | L l (SpliceD _ _) <- hsmodDecls hsm ]
126+
127+
warningMap <- liftErrMsg (mkWarningMap dflags warnings gre exportedNames)
128+
129+
maps@(!docMap, !argMap, !declMap, _) <-
130+
liftErrMsg (mkMaps dflags gre localInsts declsWithDocs)
131+
132+
let allWarnings = M.unions (warningMap : map ifaceWarningMap (M.elems modMap))
133+
134+
-- The MAIN functionality: compute the export items which will
135+
-- each be the actual documentation of this module.
136+
exportItems <- mkExportItems is_sig modMap mdl sem_mdl allWarnings gre
137+
exportedNames decls maps fixMap unrestrictedImportedMods
138+
splices exports all_exports instIfaceMap dflags
139+
140+
let !visibleNames = mkVisibleNames maps exportItems opts
141+
142+
-- Measure haddock documentation coverage.
143+
let prunedExportItems0 = pruneExportItems exportItems
144+
!haddockable = 1 + length exportItems -- module + exports
145+
!haddocked = (if isJust mbDoc then 1 else 0) + length prunedExportItems0
146+
!coverage = (haddockable, haddocked)
147+
148+
-- Prune the export list to just those declarations that have
149+
-- documentation, if the 'prune' option is on.
150+
let prunedExportItems'
151+
| OptPrune `elem` opts = prunedExportItems0
152+
| otherwise = exportItems
153+
!prunedExportItems = seqList prunedExportItems' `seq` prunedExportItems'
154+
155+
let !aliases =
156+
mkAliasMap dflags $ tm_renamed_source tm
157+
158+
modWarn <- liftErrMsg (moduleWarning dflags gre warnings)
159+
160+
tokenizedSrc <- mkMaybeTokenizedSrc flags tm
161+
162+
return $! Interface {
163+
ifaceMod = mdl -- Done
164+
, ifaceIsSig = is_sig -- Done
165+
, ifaceOrigFilename = msHsFilePath ms
166+
, ifaceInfo = info
167+
, ifaceDoc = Documentation mbDoc modWarn
168+
, ifaceRnDoc = Documentation Nothing Nothing
169+
, ifaceOptions = opts
170+
, ifaceDocMap = docMap
171+
, ifaceArgMap = argMap
172+
, ifaceRnDocMap = M.empty -- Done
173+
, ifaceRnArgMap = M.empty -- Done
174+
, ifaceExportItems = prunedExportItems
175+
, ifaceRnExportItems = [] -- Done
176+
, ifaceExports = exportedNames
177+
, ifaceVisibleExports = visibleNames
178+
, ifaceDeclMap = declMap
179+
, ifaceFixMap = fixMap
180+
, ifaceModuleAliases = aliases
181+
, ifaceInstances = instances
182+
, ifaceFamInstances = fam_instances
183+
, ifaceOrphanInstances = [] -- Done: Filled in `attachInstances`
184+
, ifaceRnOrphanInstances = [] -- Done: Filled in `renameInterface`
185+
, ifaceHaddockCoverage = coverage
186+
, ifaceWarningMap = warningMap
187+
, ifaceTokenizedSrc = tokenizedSrc -- Ignore
188+
}
189+
66190

67191
-- | Use a 'TypecheckedModule' to produce an 'Interface'.
68192
-- To do this, we need access to already processed modules in the topological

0 commit comments

Comments
 (0)