@@ -63,6 +63,130 @@ import BasicTypes ( StringLiteral(..), SourceText(..) )
63
63
import qualified Outputable as O
64
64
import HsDecls ( getConArgs )
65
65
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
+
66
190
67
191
-- | Use a 'TypecheckedModule' to produce an 'Interface'.
68
192
-- To do this, we need access to already processed modules in the topological
0 commit comments