@@ -353,15 +353,14 @@ typeDocs :: HsDecl Name -> Map Int HsDocString
353
353
typeDocs d =
354
354
let docs = go 0 in
355
355
case d of
356
- SigD (TypeSig _ ty _) -> docs (unLoc ty)
357
- SigD (PatSynSig _ _ req prov ty) ->
358
- let allTys = ty : concat [ unLoc req, unLoc prov ]
359
- in F. foldMap (docs . unLoc) allTys
360
- ForD (ForeignImport _ ty _ _) -> docs (unLoc ty)
356
+ SigD (TypeSig _ ty) -> docs (unLoc (hsSigWcType ty))
357
+ SigD (PatSynSig _ ty) -> docs (unLoc (hsSigType ty))
358
+ ForD (ForeignImport _ ty _ _) -> docs (unLoc (hsSigType ty))
361
359
TyClD (SynDecl { tcdRhs = ty }) -> docs (unLoc ty)
362
360
_ -> M. empty
363
361
where
364
- go n (HsForAllTy _ _ _ _ ty) = go n (unLoc ty)
362
+ go n (HsForAllTy { hst_body = ty }) = go n (unLoc ty)
363
+ go n (HsQualTy { hst_body = ty }) = go n (unLoc ty)
365
364
go n (HsFunTy (L _ (HsDocTy _ (L _ x))) (L _ ty)) = M. insert n x $ go (n+ 1 ) ty
366
365
go n (HsFunTy _ ty) = go (n+ 1 ) (unLoc ty)
367
366
go n (HsDocTy _ (L _ doc)) = M. singleton n doc
@@ -740,8 +739,8 @@ fullModuleContents dflags warnings gre (docMap, argMap, subMap, declMap, instMap
740
739
expandSig = foldr f []
741
740
where
742
741
f :: LHsDecl name -> [LHsDecl name ] -> [LHsDecl name ]
743
- f (L l (SigD (TypeSig names t nwcs ))) xs = foldr (\ n acc -> L l (SigD (TypeSig [n] t nwcs)) : acc) xs names
744
- f (L l (SigD (GenericSig names t))) xs = foldr (\ n acc -> L l (SigD (GenericSig [n] t)) : acc) xs names
742
+ f (L l (SigD (TypeSig names t))) xs = foldr (\ n acc -> L l (SigD (TypeSig [n] t)) : acc) xs names
743
+ f (L l (SigD (ClassOpSig b names t))) xs = foldr (\ n acc -> L l (SigD (ClassOpSig b [n] t)) : acc) xs names
745
744
f x xs = x : xs
746
745
747
746
mkExportItem :: LHsDecl Name -> ErrMsgGhc (Maybe (ExportItem Name ))
@@ -785,17 +784,17 @@ extractDecl name mdl decl
785
784
case unLoc decl of
786
785
TyClD d@ ClassDecl {} ->
787
786
let matches = [ sig | sig <- tcdSigs d, name `elem` sigName sig,
788
- isVanillaLSig sig ] -- TODO: document fixity
787
+ isTypeLSig sig ] -- TODO: document fixity
789
788
in case matches of
790
- [s0] -> let (n, tyvar_names) = (tcdName d, getTyVars d)
791
- L pos sig = extractClassDecl n tyvar_names s0
789
+ [s0] -> let (n, tyvar_names) = (tcdName d, tyClDeclTyVars d)
790
+ L pos sig = addClassContext n tyvar_names s0
792
791
in L pos (SigD sig)
793
792
_ -> error " internal: extractDecl (ClassDecl)"
794
793
TyClD d@ DataDecl {} ->
795
- let (n, tyvar_names ) = (tcdName d, map toTypeNoLoc $ getTyVars d )
796
- in SigD <$> extractRecSel name mdl n tyvar_names (dd_cons (tcdDataDefn d))
794
+ let (n, tyvar_tys ) = (tcdName d, lHsQTyVarsToTypes (tyClDeclTyVars d) )
795
+ in SigD <$> extractRecSel name mdl n tyvar_tys (dd_cons (tcdDataDefn d))
797
796
InstD (DataFamInstD DataFamInstDecl { dfid_tycon = L _ n
798
- , dfid_pats = HsWB { hswb_cts = tys }
797
+ , dfid_pats = HsIB { hsib_body = tys }
799
798
, dfid_defn = defn }) ->
800
799
SigD <$> extractRecSel name mdl n tys (dd_cons defn)
801
800
InstD (ClsInstD ClsInstDecl { cid_datafam_insts = insts }) ->
@@ -809,24 +808,6 @@ extractDecl name mdl decl
809
808
[d0] -> extractDecl name mdl (noLoc . InstD $ DataFamInstD d0)
810
809
_ -> error " internal: extractDecl (ClsInstD)"
811
810
_ -> error " internal: extractDecl"
812
- where
813
- getTyVars = hsLTyVarLocNames . tyClDeclTyVars
814
-
815
-
816
- toTypeNoLoc :: Located Name -> LHsType Name
817
- toTypeNoLoc = noLoc . HsTyVar . unLoc
818
-
819
-
820
- extractClassDecl :: Name -> [Located Name ] -> LSig Name -> LSig Name
821
- extractClassDecl c tvs0 (L pos (TypeSig lname ltype _)) = case ltype of
822
- L _ (HsForAllTy expl _ tvs (L _ preds) ty) ->
823
- L pos (TypeSig lname (noLoc (HsForAllTy expl Nothing tvs (lctxt preds) ty)) [] )
824
- _ -> L pos (TypeSig lname (noLoc (HsForAllTy Implicit Nothing emptyHsQTvs (lctxt [] ) ltype)) [] )
825
- where
826
- lctxt = noLoc . ctxt
827
- ctxt preds = nlHsTyConApp c (map toTypeNoLoc tvs0) : preds
828
- extractClassDecl _ _ _ = error " extractClassDecl: unexpected decl"
829
-
830
811
831
812
extractRecSel :: Name -> Module -> Name -> [LHsType Name ] -> [LConDecl Name ]
832
813
-> LSig Name
@@ -835,7 +816,7 @@ extractRecSel _ _ _ _ [] = error "extractRecSel: selector not found"
835
816
extractRecSel nm mdl t tvs (L _ con : rest) =
836
817
case con_details con of
837
818
RecCon (L _ fields) | ((l,L _ (ConDeclField _nn ty _)) : _) <- matching_fields fields ->
838
- L l (TypeSig [noLoc nm] (noLoc (HsFunTy data_ty (getBangType ty))) [] )
819
+ L l (TypeSig [noLoc nm] (mkEmptySigWcType ( noLoc (HsFunTy data_ty (getBangType ty)))) )
839
820
_ -> extractRecSel nm mdl t tvs rest
840
821
where
841
822
matching_fields :: [LConDeclField Name ] -> [(SrcSpan , LConDeclField Name )]
@@ -845,7 +826,6 @@ extractRecSel nm mdl t tvs (L _ con : rest) =
845
826
| ResTyGADT _ ty <- con_res con = ty
846
827
| otherwise = foldl' (\ x y -> noLoc (HsAppTy x y)) (noLoc (HsTyVar t)) tvs
847
828
848
-
849
829
-- | Keep export items with docs.
850
830
pruneExportItems :: [ExportItem Name ] -> [ExportItem Name ]
851
831
pruneExportItems = filter hasDoc
0 commit comments