@@ -37,8 +37,6 @@ import Data.Traversable
37
37
38
38
import Avail hiding (avail )
39
39
import qualified Avail
40
- import qualified Module
41
- import qualified SrcLoc
42
40
import ConLike (ConLike (.. ))
43
41
import GHC
44
42
import GhcMonad
@@ -51,7 +49,7 @@ import TcIface
51
49
import TcRnMonad
52
50
import FastString ( unpackFS )
53
51
import HsDecls ( getConArgs )
54
- import BasicTypes ( SourceText ( .. ), WarningTxt (.. ), WarningSort (.. ), warningTxtContents )
52
+ import BasicTypes ( WarningTxt (.. ), WarningSort (.. ), warningTxtContents )
55
53
import qualified Outputable as O
56
54
import DynFlags ( getDynFlags )
57
55
@@ -112,9 +110,7 @@ createInterface mod_iface flags modMap instIfaceMap = do
112
110
++ map getName fam_instances
113
111
instanceMap = M. fromList (map (getSrcSpan &&& id ) localInsts)
114
112
115
- -- TODO: Entirely remove DeclMap.
116
- let declMap = M. empty
117
- maps = (docMap, argMap, declMap, instanceMap)
113
+ let maps = (docMap, argMap, instanceMap)
118
114
allWarnings = M. unions (warningMap : map ifaceWarningMap (M. elems modMap))
119
115
120
116
-- Locations of all TH splices
@@ -161,7 +157,7 @@ createInterface mod_iface flags modMap instIfaceMap = do
161
157
, ifaceRnExportItems = []
162
158
, ifaceExports = exportedNames
163
159
, ifaceVisibleExports = visibleNames
164
- , ifaceDeclMap = declMap
160
+ , ifaceDeclMap = M. empty -- TODO: get rid of this
165
161
, ifaceFixMap = fixMap
166
162
, ifaceInstances = instances
167
163
, ifaceFamInstances = fam_instances
@@ -274,7 +270,7 @@ parseOption "not-home" = return (Just OptNotHome)
274
270
parseOption " show-extensions" = return (Just OptShowExtensions )
275
271
parseOption other = tell [" Unrecognised option: " ++ other] >> return Nothing
276
272
277
- type Maps = (DocMap Name , ArgMap Name , DeclMap , InstMap )
273
+ type Maps = (DocMap Name , ArgMap Name , InstMap )
278
274
279
275
-- | Extract a map of fixity declarations only
280
276
mkFixMap :: [Name ] -> [(OccName , Fixity )] -> FixMap
@@ -349,88 +345,40 @@ availExportItem :: Bool -- is it a signature
349
345
-> AvailInfo
350
346
-> ErrMsgGhc [ExportItem GhcRn ]
351
347
availExportItem is_sig modMap thisMod semMod warnings exportedNames
352
- (docMap, argMap, declMap, _) fixMap splices instIfaceMap
348
+ (docMap, argMap, _) fixMap splices instIfaceMap
353
349
availInfo = declWith availInfo
354
350
where
355
351
declWith :: AvailInfo -> ErrMsgGhc [ ExportItem GhcRn ]
356
352
declWith avail = do
357
353
dflags <- getDynFlags
358
354
let t = availName avail -- NB: 't' might not be in the scope of 'avail'.
359
355
-- Example: @data C = D@, where C isn't exported.
360
- r <- findDecl avail
361
- case r of
362
- ([L l (ValD _ _)], (doc, _)) -> do
363
- -- Top-level binding without type signature
364
- export <- hiValExportItem t l doc (l `elem` splices) $ M. lookup t fixMap
365
- return [export]
366
- (ds, docs_) | decl : _ <- filter (not . isValD . unLoc) ds ->
367
- let declNames = getMainDeclBinder (unL decl)
368
- in case () of
369
- _
370
- -- We should not show a subordinate by itself if any of its
371
- -- parents is also exported. See note [1].
372
- | t `notElem` declNames,
373
- Just p <- find isExported (parents t $ unL decl) ->
374
- do liftErrMsg $ tell [
375
- " Warning: " ++ moduleString thisMod ++ " : " ++
376
- pretty dflags (nameOccName t) ++ " is exported separately but " ++
377
- " will be documented under " ++ pretty dflags (nameOccName p) ++
378
- " . Consider exporting it together with its parent(s)" ++
379
- " for code clarity." ]
380
- return []
381
-
382
- -- normal case
383
- | otherwise -> case decl of
384
- -- A single signature might refer to many names, but we
385
- -- create an export item for a single name only. So we
386
- -- modify the signature to contain only that single name.
387
- L loc (SigD _ sig) ->
388
- case filterSigNames (== t) sig of
389
- Nothing -> do
390
- liftErrMsg $ tell [
391
- " Warning: " ++ moduleString thisMod ++ " : " ++
392
- pretty dflags sig ++ " doesn't contain " ++ pretty dflags t ++
393
- " . Names in the signature: " ++ pretty dflags (sigNameNoLoc sig)]
394
- pure []
395
- Just sig' ->
396
- availExportDecl avail (L loc (SigD noExt sig')) docs_
397
- L loc (TyClD _ cl@ ClassDecl {}) -> do
398
- mdef <- liftGhcToErrMsgGhc $ minimalDef t
399
- let sig = maybeToList $ fmap (noLoc . MinimalSig noExt NoSourceText . noLoc . fmap noLoc) mdef
400
- availExportDecl avail
401
- (L loc $ TyClD noExt cl { tcdSigs = sig ++ tcdSigs cl }) docs_
402
-
403
- _ -> availExportDecl avail decl docs_
404
-
405
- ([] , _) -> do
406
- mayDecl <- hiDecl t
407
- case mayDecl of
408
- Nothing -> return [ ExportNoDecl t [] ]
409
- Just decl -> do
410
- docs_ <- do
411
- let tmod = nameModule t
412
- if tmod == thisMod
413
- then pure (lookupDocs avail warnings docMap argMap)
414
- else case M. lookup tmod modMap of
415
- Just iface ->
416
- pure (lookupDocs avail warnings (ifaceDocMap iface) (ifaceArgMap iface))
417
- Nothing ->
418
- -- We try to get the subs and docs
419
- -- from the installed .haddock file for that package.
420
- -- TODO: This needs to be more sophisticated to deal
421
- -- with signature inheritance
422
- case M. lookup (nameModule t) instIfaceMap of
423
- Nothing -> do
424
- liftErrMsg $ tell
425
- [" Warning: " ++ pretty dflags thisMod ++
426
- " : Couldn't find .haddock for export " ++ pretty dflags t]
427
- let subs_ = availNoDocs avail
428
- pure (noDocForDecl, subs_)
429
- Just instIface ->
430
- pure (lookupDocs avail warnings (instDocMap instIface) (instArgMap instIface))
431
- availExportDecl avail decl docs_
432
-
433
- _ -> return []
356
+ mayDecl <- hiDecl t
357
+ case mayDecl of
358
+ Nothing -> return [ ExportNoDecl t [] ]
359
+ Just decl -> do
360
+ docs_ <- do
361
+ let tmod = nameModule t
362
+ if tmod == thisMod
363
+ then pure (lookupDocs avail warnings docMap argMap)
364
+ else case M. lookup tmod modMap of
365
+ Just iface ->
366
+ pure (lookupDocs avail warnings (ifaceDocMap iface) (ifaceArgMap iface))
367
+ Nothing ->
368
+ -- We try to get the subs and docs
369
+ -- from the installed .haddock file for that package.
370
+ -- TODO: This needs to be more sophisticated to deal
371
+ -- with signature inheritance
372
+ case M. lookup (nameModule t) instIfaceMap of
373
+ Nothing -> do
374
+ liftErrMsg $ tell
375
+ [" Warning: " ++ pretty dflags thisMod ++
376
+ " : Couldn't find .haddock for export " ++ pretty dflags t]
377
+ let subs_ = availNoDocs avail
378
+ pure (noDocForDecl, subs_)
379
+ Just instIface ->
380
+ pure (lookupDocs avail warnings (instDocMap instIface) (instArgMap instIface))
381
+ availExportDecl avail decl docs_
434
382
435
383
availExportDecl :: AvailInfo -> LHsDecl GhcRn
436
384
-> (DocForDecl Name , [(Name , DocForDecl Name )])
@@ -478,38 +426,6 @@ availExportItem is_sig modMap thisMod semMod warnings exportedNames
478
426
})
479
427
in traverse extractSub subs
480
428
481
- exportedNameSet = mkNameSet exportedNames
482
- isExported n = elemNameSet n exportedNameSet
483
-
484
- findDecl :: AvailInfo -> ErrMsgGhc ([LHsDecl GhcRn ], (DocForDecl Name , [(Name , DocForDecl Name )]))
485
- findDecl avail
486
- | m == semMod =
487
- case M. lookup n declMap of
488
- Just ds -> return (ds, lookupDocs avail warnings docMap argMap)
489
- Nothing
490
- | is_sig -> do
491
- -- OK, so it wasn't in the local declaration map. It could
492
- -- have been inherited from a signature. Reconstitute it
493
- -- from the type.
494
- mb_r <- hiDecl n
495
- case mb_r of
496
- Nothing -> return ([] , (noDocForDecl, availNoDocs avail))
497
- -- TODO: If we try harder, we might be able to find
498
- -- a Haddock! Look in the Haddocks for each thing in
499
- -- requirementContext (pkgState)
500
- Just decl -> return ([decl], (noDocForDecl, availNoDocs avail))
501
- | otherwise ->
502
- return ([] , (noDocForDecl, availNoDocs avail))
503
- | Just iface <- M. lookup (semToIdMod (moduleUnitId thisMod) m) modMap
504
- , Just ds <- M. lookup n (ifaceDeclMap iface) =
505
- return (ds, lookupDocs avail warnings
506
- (ifaceDocMap iface)
507
- (ifaceArgMap iface))
508
- | otherwise = return ([] , (noDocForDecl, availNoDocs avail))
509
- where
510
- n = availName avail
511
- m = nameModule n
512
-
513
429
findBundledPatterns :: AvailInfo -> ErrMsgGhc [(HsDecl GhcRn , DocForDecl Name )]
514
430
findBundledPatterns avail = do
515
431
patsyns <- for constructor_names $ \ name -> do
@@ -544,13 +460,6 @@ availNoDocs :: AvailInfo -> [(Name, DocForDecl Name)]
544
460
availNoDocs avail =
545
461
zip (availSubordinates avail) (repeat noDocForDecl)
546
462
547
- -- | Given a 'Module' from a 'Name', convert it into a 'Module' that
548
- -- we can actually find in the 'IfaceMap'.
549
- semToIdMod :: UnitId -> Module -> Module
550
- semToIdMod this_uid m
551
- | Module. isHoleModule m = mkModule this_uid (moduleName m)
552
- | otherwise = m
553
-
554
463
hiDecl :: Name -> ErrMsgGhc (Maybe (LHsDecl GhcRn ))
555
464
hiDecl t = do
556
465
dflags <- getDynFlags
@@ -569,24 +478,6 @@ hiDecl t = do
569
478
O. comma O. <+> O. quotes (O. ppr t) O. <+>
570
479
O. text " -- Please report this on Haddock issue tracker!"
571
480
572
- -- | This function is called for top-level bindings without type signatures.
573
- -- It gets the type signature from GHC and that means it's not going to
574
- -- have a meaningful 'SrcSpan'. So we pass down 'SrcSpan' for the
575
- -- declaration and use it instead - 'nLoc' here.
576
- hiValExportItem :: Name -> SrcSpan -> DocForDecl Name -> Bool
577
- -> Maybe Fixity -> ErrMsgGhc (ExportItem GhcRn )
578
- hiValExportItem name nLoc doc splice fixity = do
579
- mayDecl <- hiDecl name
580
- case mayDecl of
581
- Nothing -> return (ExportNoDecl name [] )
582
- Just decl -> return (ExportDecl (fixSpan decl) [] doc [] [] fixities splice)
583
- where
584
- fixSpan (L l t) = L (SrcLoc. combineSrcSpans l nLoc) t
585
- fixities = case fixity of
586
- Just f -> [(name, f)]
587
- Nothing -> []
588
-
589
-
590
481
-- | Lookup docs for a declaration from maps.
591
482
lookupDocs :: AvailInfo -> WarningMap -> DocMap Name -> ArgMap Name
592
483
-> (DocForDecl Name , [(Name , DocForDecl Name )])
@@ -761,7 +652,7 @@ pruneExportItems = filter hasDoc
761
652
762
653
763
654
mkVisibleNames :: Maps -> [ExportItem GhcRn ] -> [DocOption ] -> [Name ]
764
- mkVisibleNames (_, _, _, instMap) exports opts
655
+ mkVisibleNames (_, _, instMap) exports opts
765
656
| OptHide `elem` opts = []
766
657
| otherwise = let ns = concatMap exportName exports
767
658
in seqList ns `seq` ns
0 commit comments