-- |
-- Statistics for per-module compilations
--
-- (c) The GRASP/AQUA Project, Glasgow University, 1993-1998
--

{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ViewPatterns #-}

module HscStats ( ppSourceStats ) where

import GhcPrelude

import Bag
import HsSyn
import Outputable
import SrcLoc
import Util

import Data.Char

-- | Source Statistics
ppSourceStats :: Bool -> Located (HsModule GhcPs) -> SDoc
ppSourceStats :: Bool -> Located (HsModule GhcPs) -> SDoc
ppSourceStats short :: Bool
short (Located (HsModule GhcPs)
-> Located (SrcSpanLess (Located (HsModule GhcPs)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (HsModule _ exports imports ldecls _ _))
  = (if Bool
short then [SDoc] -> SDoc
hcat else [SDoc] -> SDoc
vcat)
        (((String, Int) -> SDoc) -> [(String, Int)] -> [SDoc]
forall a b. (a -> b) -> [a] -> [b]
map (String, Int) -> SDoc
pp_val
            [("ExportAll        ", Int
export_all), -- 1 if no export list
             ("ExportDecls      ", Int
export_ds),
             ("ExportModules    ", Int
export_ms),
             ("Imports          ", Int
imp_no),
             ("  ImpSafe        ", Int
imp_safe),
             ("  ImpQual        ", Int
imp_qual),
             ("  ImpAs          ", Int
imp_as),
             ("  ImpAll         ", Int
imp_all),
             ("  ImpPartial     ", Int
imp_partial),
             ("  ImpHiding      ", Int
imp_hiding),
             ("FixityDecls      ", Int
fixity_sigs),
             ("DefaultDecls     ", Int
default_ds),
             ("TypeDecls        ", Int
type_ds),
             ("DataDecls        ", Int
data_ds),
             ("NewTypeDecls     ", Int
newt_ds),
             ("TypeFamilyDecls  ", Int
type_fam_ds),
             ("DataConstrs      ", Int
data_constrs),
             ("DataDerivings    ", Int
data_derivs),
             ("ClassDecls       ", Int
class_ds),
             ("ClassMethods     ", Int
class_method_ds),
             ("DefaultMethods   ", Int
default_method_ds),
             ("InstDecls        ", Int
inst_ds),
             ("InstMethods      ", Int
inst_method_ds),
             ("InstType         ", Int
inst_type_ds),
             ("InstData         ", Int
inst_data_ds),
             ("TypeSigs         ", Int
bind_tys),
             ("ClassOpSigs      ", Int
generic_sigs),
             ("ValBinds         ", Int
val_bind_ds),
             ("FunBinds         ", Int
fn_bind_ds),
             ("PatSynBinds      ", Int
patsyn_ds),
             ("InlineMeths      ", Int
method_inlines),
             ("InlineBinds      ", Int
bind_inlines),
             ("SpecialisedMeths ", Int
method_specs),
             ("SpecialisedBinds ", Int
bind_specs)
            ])
  where
    decls :: [HsDecl GhcPs]
decls = (LHsDecl GhcPs -> HsDecl GhcPs)
-> [LHsDecl GhcPs] -> [HsDecl GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map LHsDecl GhcPs -> HsDecl GhcPs
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [LHsDecl GhcPs]
ldecls

    pp_val :: (String, Int) -> SDoc
pp_val (_, 0) = SDoc
empty
    pp_val (str :: String
str, n :: Int
n)
      | Bool -> Bool
not Bool
short   = [SDoc] -> SDoc
hcat [String -> SDoc
text String
str, Int -> SDoc
int Int
n]
      | Bool
otherwise   = [SDoc] -> SDoc
hcat [String -> SDoc
text (String -> String
trim String
str), SDoc
equals, Int -> SDoc
int Int
n, SDoc
semi]

    trim :: String -> String
trim ls :: String
ls    = (Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Bool -> Bool
not(Bool -> Bool) -> (Char -> Bool) -> Char -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
.Char -> Bool
isSpace) ((Char -> Bool) -> String -> String
forall a. (a -> Bool) -> [a] -> [a]
dropWhile Char -> Bool
isSpace String
ls)

    (fixity_sigs :: Int
fixity_sigs, bind_tys :: Int
bind_tys, bind_specs :: Int
bind_specs, bind_inlines :: Int
bind_inlines, generic_sigs :: Int
generic_sigs)
        = [Sig GhcPs] -> (Int, Int, Int, Int, Int)
forall pass. [Sig pass] -> (Int, Int, Int, Int, Int)
count_sigs [Sig GhcPs
d | SigD _ d :: Sig GhcPs
d <- [HsDecl GhcPs]
decls]
                -- NB: this omits fixity decls on local bindings and
                -- in class decls. ToDo

    tycl_decls :: [TyClDecl GhcPs]
tycl_decls = [TyClDecl GhcPs
d | TyClD _ d :: TyClDecl GhcPs
d <- [HsDecl GhcPs]
decls]
    (class_ds :: Int
class_ds, type_ds :: Int
type_ds, data_ds :: Int
data_ds, newt_ds :: Int
newt_ds, type_fam_ds :: Int
type_fam_ds) =
      [TyClDecl GhcPs] -> (Int, Int, Int, Int, Int)
forall pass. [TyClDecl pass] -> (Int, Int, Int, Int, Int)
countTyClDecls [TyClDecl GhcPs]
tycl_decls

    inst_decls :: [InstDecl GhcPs]
inst_decls = [InstDecl GhcPs
d | InstD _ d :: InstDecl GhcPs
d <- [HsDecl GhcPs]
decls]
    inst_ds :: Int
inst_ds    = [InstDecl GhcPs] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [InstDecl GhcPs]
inst_decls
    default_ds :: Int
default_ds = (HsDecl GhcPs -> Bool) -> [HsDecl GhcPs] -> Int
forall a. (a -> Bool) -> [a] -> Int
count (\ x :: HsDecl GhcPs
x -> case HsDecl GhcPs
x of { DefD{} -> Bool
True; _ -> Bool
False}) [HsDecl GhcPs]
decls
    val_decls :: [HsBind GhcPs]
val_decls  = [HsBind GhcPs
d | ValD _ d :: HsBind GhcPs
d <- [HsDecl GhcPs]
decls]

    real_exports :: [LIE GhcPs]
real_exports = case Maybe (Located [LIE GhcPs])
exports of { Nothing -> []; Just (Located [LIE GhcPs] -> Located (SrcSpanLess (Located [LIE GhcPs]))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ es :: SrcSpanLess (Located [LIE GhcPs])
es) -> [LIE GhcPs]
SrcSpanLess (Located [LIE GhcPs])
es }
    n_exports :: Int
n_exports    = [LIE GhcPs] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LIE GhcPs]
real_exports
    export_ms :: Int
export_ms    = (LIE GhcPs -> Bool) -> [LIE GhcPs] -> Int
forall a. (a -> Bool) -> [a] -> Int
count (\ e :: LIE GhcPs
e -> case LIE GhcPs -> SrcSpanLess (LIE GhcPs)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LIE GhcPs
e of { IEModuleContents{} -> Bool
True
                                                 ; _ -> Bool
False})
                         [LIE GhcPs]
real_exports
    export_ds :: Int
export_ds    = Int
n_exports Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
export_ms
    export_all :: Int
export_all   = case Maybe (Located [LIE GhcPs])
exports of { Nothing -> 1; _ -> 0 }

    (val_bind_ds :: Int
val_bind_ds, fn_bind_ds :: Int
fn_bind_ds, patsyn_ds :: Int
patsyn_ds)
        = [(Int, Int, Int)] -> (Int, Int, Int)
sum3 ((HsBind GhcPs -> (Int, Int, Int))
-> [HsBind GhcPs] -> [(Int, Int, Int)]
forall a b. (a -> b) -> [a] -> [b]
map HsBind GhcPs -> (Int, Int, Int)
forall (pr :: Pass) (pl :: Pass) a b c.
(OutputableBndr (IdP (GhcPass (NoGhcTcPass pr))),
 OutputableBndr (NameOrRdrName (IdP (GhcPass (NoGhcTcPass pr)))),
 OutputableBndr (IdP (GhcPass pr)),
 OutputableBndr (NameOrRdrName (IdP (GhcPass pr))),
 OutputableBndr (NameOrRdrName (IdP (GhcPass pl))),
 OutputableBndr (IdP (GhcPass pl)),
 OutputableBndr (IdP (GhcPass (NoGhcTcPass pl))),
 OutputableBndr (NameOrRdrName (IdP (GhcPass (NoGhcTcPass pl)))),
 Num a, Num b, Num c,
 Outputable (XViaStrategy (GhcPass (NoGhcTcPass pl))),
 Outputable (XIPBinds (GhcPass (NoGhcTcPass pl))),
 Outputable (XViaStrategy (GhcPass pl)),
 Outputable (XIPBinds (GhcPass pl)),
 Outputable (XIPBinds (GhcPass pr)),
 Outputable (XViaStrategy (GhcPass pr)),
 Outputable (XIPBinds (GhcPass (NoGhcTcPass pr))),
 Outputable (XViaStrategy (GhcPass (NoGhcTcPass pr))),
 NoGhcTcPass pl ~ NoGhcTcPass (NoGhcTcPass pl),
 NoGhcTcPass pr ~ NoGhcTcPass (NoGhcTcPass pr)) =>
HsBindLR (GhcPass pl) (GhcPass pr) -> (a, b, c)
count_bind [HsBind GhcPs]
val_decls)

    (imp_no :: Int
imp_no, imp_safe :: Int
imp_safe, imp_qual :: Int
imp_qual, imp_as :: Int
imp_as, imp_all :: Int
imp_all, imp_partial :: Int
imp_partial, imp_hiding :: Int
imp_hiding)
        = [(Int, Int, Int, Int, Int, Int, Int)]
-> (Int, Int, Int, Int, Int, Int, Int)
sum7 ((LImportDecl GhcPs -> (Int, Int, Int, Int, Int, Int, Int))
-> [LImportDecl GhcPs] -> [(Int, Int, Int, Int, Int, Int, Int)]
forall a b. (a -> b) -> [a] -> [b]
map LImportDecl GhcPs -> (Int, Int, Int, Int, Int, Int, Int)
import_info [LImportDecl GhcPs]
imports)
    (data_constrs :: Int
data_constrs, data_derivs :: Int
data_derivs)
        = [(Int, Int)] -> (Int, Int)
sum2 ((TyClDecl GhcPs -> (Int, Int)) -> [TyClDecl GhcPs] -> [(Int, Int)]
forall a b. (a -> b) -> [a] -> [b]
map TyClDecl GhcPs -> (Int, Int)
forall pass. TyClDecl pass -> (Int, Int)
data_info [TyClDecl GhcPs]
tycl_decls)
    (class_method_ds :: Int
class_method_ds, default_method_ds :: Int
default_method_ds)
        = [(Int, Int)] -> (Int, Int)
sum2 ((TyClDecl GhcPs -> (Int, Int)) -> [TyClDecl GhcPs] -> [(Int, Int)]
forall a b. (a -> b) -> [a] -> [b]
map TyClDecl GhcPs -> (Int, Int)
forall (pl :: Pass).
(OutputableBndr (IdP (GhcPass (NoGhcTcPass pl))),
 OutputableBndr (NameOrRdrName (IdP (GhcPass (NoGhcTcPass pl)))),
 OutputableBndr (IdP (GhcPass pl)),
 OutputableBndr (NameOrRdrName (IdP (GhcPass pl))),
 Outputable (XIPBinds (GhcPass (NoGhcTcPass pl))),
 Outputable (XIPBinds (GhcPass pl)),
 Outputable (XViaStrategy (GhcPass pl)),
 Outputable (XViaStrategy (GhcPass (NoGhcTcPass pl))),
 NoGhcTcPass pl ~ NoGhcTcPass (NoGhcTcPass pl)) =>
TyClDecl (GhcPass pl) -> (Int, Int)
class_info [TyClDecl GhcPs]
tycl_decls)
    (inst_method_ds :: Int
inst_method_ds, method_specs :: Int
method_specs, method_inlines :: Int
method_inlines, inst_type_ds :: Int
inst_type_ds, inst_data_ds :: Int
inst_data_ds)
        = [(Int, Int, Int, Int, Int)] -> (Int, Int, Int, Int, Int)
sum5 ((InstDecl GhcPs -> (Int, Int, Int, Int, Int))
-> [InstDecl GhcPs] -> [(Int, Int, Int, Int, Int)]
forall a b. (a -> b) -> [a] -> [b]
map InstDecl GhcPs -> (Int, Int, Int, Int, Int)
forall (pl :: Pass).
(OutputableBndr (IdP (GhcPass (NoGhcTcPass pl))),
 OutputableBndr (NameOrRdrName (IdP (GhcPass (NoGhcTcPass pl)))),
 OutputableBndr (IdP (GhcPass pl)),
 OutputableBndr (NameOrRdrName (IdP (GhcPass pl))),
 Outputable (XIPBinds (GhcPass (NoGhcTcPass pl))),
 Outputable (XIPBinds (GhcPass pl)),
 Outputable (XViaStrategy (GhcPass pl)),
 Outputable (XViaStrategy (GhcPass (NoGhcTcPass pl))),
 NoGhcTcPass pl ~ NoGhcTcPass (NoGhcTcPass pl)) =>
InstDecl (GhcPass pl) -> (Int, Int, Int, Int, Int)
inst_info [InstDecl GhcPs]
inst_decls)

    count_bind :: HsBindLR (GhcPass pl) (GhcPass pr) -> (a, b, c)
count_bind (PatBind { pat_lhs :: forall idL idR. HsBindLR idL idR -> LPat idL
pat_lhs = (LPat (GhcPass pl) -> Located (SrcSpanLess (LPat (GhcPass pl)))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (VarPat{})) }) = (1,0,0)
    count_bind (PatBind {})                           = (0,1,0)
    count_bind (FunBind {})                           = (0,1,0)
    count_bind (PatSynBind {})                        = (0,0,1)
    count_bind b :: HsBindLR (GhcPass pl) (GhcPass pr)
b = String -> SDoc -> (a, b, c)
forall a. HasCallStack => String -> SDoc -> a
pprPanic "count_bind: Unhandled binder" (HsBindLR (GhcPass pl) (GhcPass pr) -> SDoc
forall a. Outputable a => a -> SDoc
ppr HsBindLR (GhcPass pl) (GhcPass pr)
b)

    count_sigs :: [Sig pass] -> (Int, Int, Int, Int, Int)
count_sigs sigs :: [Sig pass]
sigs = [(Int, Int, Int, Int, Int)] -> (Int, Int, Int, Int, Int)
sum5 ((Sig pass -> (Int, Int, Int, Int, Int))
-> [Sig pass] -> [(Int, Int, Int, Int, Int)]
forall a b. (a -> b) -> [a] -> [b]
map Sig pass -> (Int, Int, Int, Int, Int)
forall a b c d e pass.
(Num a, Num b, Num c, Num d, Num e) =>
Sig pass -> (a, b, c, d, e)
sig_info [Sig pass]
sigs)

    sig_info :: Sig pass -> (a, b, c, d, e)
sig_info (FixSig {})     = (1,0,0,0,0)
    sig_info (TypeSig {})    = (0,1,0,0,0)
    sig_info (SpecSig {})    = (0,0,1,0,0)
    sig_info (InlineSig {})  = (0,0,0,1,0)
    sig_info (ClassOpSig {}) = (0,0,0,0,1)
    sig_info _               = (0,0,0,0,0)

    import_info :: LImportDecl GhcPs -> (Int, Int, Int, Int, Int, Int, Int)
import_info (LImportDecl GhcPs -> Located (SrcSpanLess (LImportDecl GhcPs))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (ImportDecl { ideclSafe = safe, ideclQualified = qual
                                     , ideclAs = as, ideclHiding = spec }))
        = (Int, Int, Int, Int, Int, Int, Int)
-> (Int, Int, Int, Int, Int, Int, Int)
-> (Int, Int, Int, Int, Int, Int, Int)
add7 (1, Bool -> Int
safe_info Bool
safe, Bool -> Int
forall p. Num p => Bool -> p
qual_info Bool
qual, Maybe (Located ModuleName) -> Int
forall p a. Num p => Maybe a -> p
as_info Maybe (Located ModuleName)
as, 0,0,0) (Maybe (Bool, Located [LIE GhcPs])
-> (Int, Int, Int, Int, Int, Int, Int)
forall a b c d e f g b.
(Num a, Num b, Num c, Num d, Num e, Num f, Num g) =>
Maybe (Bool, b) -> (a, b, c, d, e, f, g)
spec_info Maybe (Bool, Located [LIE GhcPs])
spec)
    import_info (LImportDecl GhcPs -> Located (SrcSpanLess (LImportDecl GhcPs))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ (XImportDecl _)) = String -> (Int, Int, Int, Int, Int, Int, Int)
forall a. String -> a
panic "import_info"
    import_info _ = String -> (Int, Int, Int, Int, Int, Int, Int)
forall a. String -> a
panic " import_info: Impossible Match"
                             -- due to #15884

    safe_info :: Bool -> Int
safe_info = Bool -> Int
forall p. Num p => Bool -> p
qual_info
    qual_info :: Bool -> p
qual_info False  = 0
    qual_info True   = 1
    as_info :: Maybe a -> p
as_info Nothing  = 0
    as_info (Just _) = 1
    spec_info :: Maybe (Bool, b) -> (a, b, c, d, e, f, g)
spec_info Nothing           = (0,0,0,0,1,0,0)
    spec_info (Just (False, _)) = (0,0,0,0,0,1,0)
    spec_info (Just (True, _))  = (0,0,0,0,0,0,1)

    data_info :: TyClDecl pass -> (Int, Int)
data_info (DataDecl { tcdDataDefn :: forall pass. TyClDecl pass -> HsDataDefn pass
tcdDataDefn = HsDataDefn
                                          { dd_cons :: forall pass. HsDataDefn pass -> [LConDecl pass]
dd_cons = [LConDecl pass]
cs
                                          , dd_derivs :: forall pass. HsDataDefn pass -> HsDeriving pass
dd_derivs = (HsDeriving pass -> Located (SrcSpanLess (HsDeriving pass))
forall a. HasSrcSpan a => a -> Located (SrcSpanLess a)
dL->L _ derivs :: SrcSpanLess (HsDeriving pass)
derivs)}})
        = ( [LConDecl pass] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LConDecl pass]
cs
          , (Int -> LHsDerivingClause pass -> Int)
-> Int -> [LHsDerivingClause pass] -> Int
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\s :: Int
s dc :: LHsDerivingClause pass
dc -> GenLocated SrcSpan [LHsSigType pass] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (HsDerivingClause pass -> GenLocated SrcSpan [LHsSigType pass]
forall pass. HsDerivingClause pass -> Located [LHsSigType pass]
deriv_clause_tys (HsDerivingClause pass -> GenLocated SrcSpan [LHsSigType pass])
-> HsDerivingClause pass -> GenLocated SrcSpan [LHsSigType pass]
forall a b. (a -> b) -> a -> b
$ LHsDerivingClause pass -> SrcSpanLess (LHsDerivingClause pass)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc LHsDerivingClause pass
dc) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
s)
                   0 [LHsDerivingClause pass]
SrcSpanLess (HsDeriving pass)
derivs )
    data_info _ = (0,0)

    class_info :: TyClDecl (GhcPass pl) -> (Int, Int)
class_info decl :: TyClDecl (GhcPass pl)
decl@(ClassDecl {})
        = (Int
classops, (Int, Int, Int) -> Int
addpr ([(Int, Int, Int)] -> (Int, Int, Int)
sum3 ((HsBindLR (GhcPass pl) (GhcPass pl) -> (Int, Int, Int))
-> [HsBindLR (GhcPass pl) (GhcPass pl)] -> [(Int, Int, Int)]
forall a b. (a -> b) -> [a] -> [b]
map HsBindLR (GhcPass pl) (GhcPass pl) -> (Int, Int, Int)
forall (pr :: Pass) (pl :: Pass) a b c.
(OutputableBndr (IdP (GhcPass (NoGhcTcPass pr))),
 OutputableBndr (NameOrRdrName (IdP (GhcPass (NoGhcTcPass pr)))),
 OutputableBndr (IdP (GhcPass pr)),
 OutputableBndr (NameOrRdrName (IdP (GhcPass pr))),
 OutputableBndr (NameOrRdrName (IdP (GhcPass pl))),
 OutputableBndr (IdP (GhcPass pl)),
 OutputableBndr (IdP (GhcPass (NoGhcTcPass pl))),
 OutputableBndr (NameOrRdrName (IdP (GhcPass (NoGhcTcPass pl)))),
 Num a, Num b, Num c,
 Outputable (XViaStrategy (GhcPass (NoGhcTcPass pl))),
 Outputable (XIPBinds (GhcPass (NoGhcTcPass pl))),
 Outputable (XViaStrategy (GhcPass pl)),
 Outputable (XIPBinds (GhcPass pl)),
 Outputable (XIPBinds (GhcPass pr)),
 Outputable (XViaStrategy (GhcPass pr)),
 Outputable (XIPBinds (GhcPass (NoGhcTcPass pr))),
 Outputable (XViaStrategy (GhcPass (NoGhcTcPass pr))),
 NoGhcTcPass pl ~ NoGhcTcPass (NoGhcTcPass pl),
 NoGhcTcPass pr ~ NoGhcTcPass (NoGhcTcPass pr)) =>
HsBindLR (GhcPass pl) (GhcPass pr) -> (a, b, c)
count_bind [HsBindLR (GhcPass pl) (GhcPass pl)]
methods)))
      where
        methods :: [HsBindLR (GhcPass pl) (GhcPass pl)]
methods = (LHsBindLR (GhcPass pl) (GhcPass pl)
 -> HsBindLR (GhcPass pl) (GhcPass pl))
-> [LHsBindLR (GhcPass pl) (GhcPass pl)]
-> [HsBindLR (GhcPass pl) (GhcPass pl)]
forall a b. (a -> b) -> [a] -> [b]
map LHsBindLR (GhcPass pl) (GhcPass pl)
-> HsBindLR (GhcPass pl) (GhcPass pl)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc ([LHsBindLR (GhcPass pl) (GhcPass pl)]
 -> [HsBindLR (GhcPass pl) (GhcPass pl)])
-> [LHsBindLR (GhcPass pl) (GhcPass pl)]
-> [HsBindLR (GhcPass pl) (GhcPass pl)]
forall a b. (a -> b) -> a -> b
$ Bag (LHsBindLR (GhcPass pl) (GhcPass pl))
-> [LHsBindLR (GhcPass pl) (GhcPass pl)]
forall a. Bag a -> [a]
bagToList (TyClDecl (GhcPass pl) -> Bag (LHsBindLR (GhcPass pl) (GhcPass pl))
forall pass. TyClDecl pass -> LHsBinds pass
tcdMeths TyClDecl (GhcPass pl)
decl)
        (_, classops :: Int
classops, _, _, _) = [Sig (GhcPass pl)] -> (Int, Int, Int, Int, Int)
forall pass. [Sig pass] -> (Int, Int, Int, Int, Int)
count_sigs ((LSig (GhcPass pl) -> Sig (GhcPass pl))
-> [LSig (GhcPass pl)] -> [Sig (GhcPass pl)]
forall a b. (a -> b) -> [a] -> [b]
map LSig (GhcPass pl) -> Sig (GhcPass pl)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc (TyClDecl (GhcPass pl) -> [LSig (GhcPass pl)]
forall pass. TyClDecl pass -> [LSig pass]
tcdSigs TyClDecl (GhcPass pl)
decl))
    class_info _ = (0,0)

    inst_info :: InstDecl (GhcPass pl) -> (Int, Int, Int, Int, Int)
inst_info (TyFamInstD {}) = (0,0,0,1,0)
    inst_info (DataFamInstD {}) = (0,0,0,0,1)
    inst_info (ClsInstD { cid_inst :: forall pass. InstDecl pass -> ClsInstDecl pass
cid_inst = ClsInstDecl {cid_binds :: forall pass. ClsInstDecl pass -> LHsBinds pass
cid_binds = LHsBinds (GhcPass pl)
inst_meths
                                                 , cid_sigs :: forall pass. ClsInstDecl pass -> [LSig pass]
cid_sigs = [LSig (GhcPass pl)]
inst_sigs
                                                 , cid_tyfam_insts :: forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts = [LTyFamInstDecl (GhcPass pl)]
ats
                                                 , cid_datafam_insts :: forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts = [LDataFamInstDecl (GhcPass pl)]
adts } })
        = case [Sig (GhcPass pl)] -> (Int, Int, Int, Int, Int)
forall pass. [Sig pass] -> (Int, Int, Int, Int, Int)
count_sigs ((LSig (GhcPass pl) -> Sig (GhcPass pl))
-> [LSig (GhcPass pl)] -> [Sig (GhcPass pl)]
forall a b. (a -> b) -> [a] -> [b]
map LSig (GhcPass pl) -> Sig (GhcPass pl)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc [LSig (GhcPass pl)]
inst_sigs) of
            (_,_,ss :: Int
ss,is :: Int
is,_) ->
                  ((Int, Int, Int) -> Int
addpr ([(Int, Int, Int)] -> (Int, Int, Int)
sum3 ((HsBindLR (GhcPass pl) (GhcPass pl) -> (Int, Int, Int))
-> [HsBindLR (GhcPass pl) (GhcPass pl)] -> [(Int, Int, Int)]
forall a b. (a -> b) -> [a] -> [b]
map HsBindLR (GhcPass pl) (GhcPass pl) -> (Int, Int, Int)
forall (pr :: Pass) (pl :: Pass) a b c.
(OutputableBndr (IdP (GhcPass (NoGhcTcPass pr))),
 OutputableBndr (NameOrRdrName (IdP (GhcPass (NoGhcTcPass pr)))),
 OutputableBndr (IdP (GhcPass pr)),
 OutputableBndr (NameOrRdrName (IdP (GhcPass pr))),
 OutputableBndr (NameOrRdrName (IdP (GhcPass pl))),
 OutputableBndr (IdP (GhcPass pl)),
 OutputableBndr (IdP (GhcPass (NoGhcTcPass pl))),
 OutputableBndr (NameOrRdrName (IdP (GhcPass (NoGhcTcPass pl)))),
 Num a, Num b, Num c,
 Outputable (XViaStrategy (GhcPass (NoGhcTcPass pl))),
 Outputable (XIPBinds (GhcPass (NoGhcTcPass pl))),
 Outputable (XViaStrategy (GhcPass pl)),
 Outputable (XIPBinds (GhcPass pl)),
 Outputable (XIPBinds (GhcPass pr)),
 Outputable (XViaStrategy (GhcPass pr)),
 Outputable (XIPBinds (GhcPass (NoGhcTcPass pr))),
 Outputable (XViaStrategy (GhcPass (NoGhcTcPass pr))),
 NoGhcTcPass pl ~ NoGhcTcPass (NoGhcTcPass pl),
 NoGhcTcPass pr ~ NoGhcTcPass (NoGhcTcPass pr)) =>
HsBindLR (GhcPass pl) (GhcPass pr) -> (a, b, c)
count_bind [HsBindLR (GhcPass pl) (GhcPass pl)]
methods)),
                   Int
ss, Int
is, [LTyFamInstDecl (GhcPass pl)] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LTyFamInstDecl (GhcPass pl)]
ats, [LDataFamInstDecl (GhcPass pl)] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LDataFamInstDecl (GhcPass pl)]
adts)
      where
        methods :: [HsBindLR (GhcPass pl) (GhcPass pl)]
methods = (LHsBindLR (GhcPass pl) (GhcPass pl)
 -> HsBindLR (GhcPass pl) (GhcPass pl))
-> [LHsBindLR (GhcPass pl) (GhcPass pl)]
-> [HsBindLR (GhcPass pl) (GhcPass pl)]
forall a b. (a -> b) -> [a] -> [b]
map LHsBindLR (GhcPass pl) (GhcPass pl)
-> HsBindLR (GhcPass pl) (GhcPass pl)
forall a. HasSrcSpan a => a -> SrcSpanLess a
unLoc ([LHsBindLR (GhcPass pl) (GhcPass pl)]
 -> [HsBindLR (GhcPass pl) (GhcPass pl)])
-> [LHsBindLR (GhcPass pl) (GhcPass pl)]
-> [HsBindLR (GhcPass pl) (GhcPass pl)]
forall a b. (a -> b) -> a -> b
$ LHsBinds (GhcPass pl) -> [LHsBindLR (GhcPass pl) (GhcPass pl)]
forall a. Bag a -> [a]
bagToList LHsBinds (GhcPass pl)
inst_meths
    inst_info (ClsInstD _ (XClsInstDecl _)) = String -> (Int, Int, Int, Int, Int)
forall a. String -> a
panic "inst_info"
    inst_info (XInstDecl _)                 = String -> (Int, Int, Int, Int, Int)
forall a. String -> a
panic "inst_info"

    -- TODO: use Sum monoid
    addpr :: (Int,Int,Int) -> Int
    sum2 :: [(Int, Int)] -> (Int, Int)
    sum3 :: [(Int, Int, Int)] -> (Int, Int, Int)
    sum5 :: [(Int, Int, Int, Int, Int)] -> (Int, Int, Int, Int, Int)
    sum7 :: [(Int, Int, Int, Int, Int, Int, Int)] -> (Int, Int, Int, Int, Int, Int, Int)
    add7 :: (Int, Int, Int, Int, Int, Int, Int) -> (Int, Int, Int, Int, Int, Int, Int)
         -> (Int, Int, Int, Int, Int, Int, Int)

    addpr :: (Int, Int, Int) -> Int
addpr (x :: Int
x,y :: Int
y,z :: Int
z) = Int
xInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
yInt -> Int -> Int
forall a. Num a => a -> a -> a
+Int
z
    sum2 :: [(Int, Int)] -> (Int, Int)
sum2 = ((Int, Int) -> (Int, Int) -> (Int, Int))
-> (Int, Int) -> [(Int, Int)] -> (Int, Int)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Int, Int) -> (Int, Int) -> (Int, Int)
forall a b. (Num a, Num b) => (a, b) -> (a, b) -> (a, b)
add2 (0,0)
      where
        add2 :: (a, b) -> (a, b) -> (a, b)
add2 (x1 :: a
x1,x2 :: b
x2) (y1 :: a
y1,y2 :: b
y2) = (a
x1a -> a -> a
forall a. Num a => a -> a -> a
+a
y1,b
x2b -> b -> b
forall a. Num a => a -> a -> a
+b
y2)
    sum3 :: [(Int, Int, Int)] -> (Int, Int, Int)
sum3 = ((Int, Int, Int) -> (Int, Int, Int) -> (Int, Int, Int))
-> (Int, Int, Int) -> [(Int, Int, Int)] -> (Int, Int, Int)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Int, Int, Int) -> (Int, Int, Int) -> (Int, Int, Int)
forall a b c.
(Num a, Num b, Num c) =>
(a, b, c) -> (a, b, c) -> (a, b, c)
add3 (0,0,0)
      where
        add3 :: (a, b, c) -> (a, b, c) -> (a, b, c)
add3 (x1 :: a
x1,x2 :: b
x2,x3 :: c
x3) (y1 :: a
y1,y2 :: b
y2,y3 :: c
y3) = (a
x1a -> a -> a
forall a. Num a => a -> a -> a
+a
y1,b
x2b -> b -> b
forall a. Num a => a -> a -> a
+b
y2,c
x3c -> c -> c
forall a. Num a => a -> a -> a
+c
y3)
    sum5 :: [(Int, Int, Int, Int, Int)] -> (Int, Int, Int, Int, Int)
sum5 = ((Int, Int, Int, Int, Int)
 -> (Int, Int, Int, Int, Int) -> (Int, Int, Int, Int, Int))
-> (Int, Int, Int, Int, Int)
-> [(Int, Int, Int, Int, Int)]
-> (Int, Int, Int, Int, Int)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Int, Int, Int, Int, Int)
-> (Int, Int, Int, Int, Int) -> (Int, Int, Int, Int, Int)
forall a b c d e.
(Num a, Num b, Num c, Num d, Num e) =>
(a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e)
add5 (0,0,0,0,0)
      where
        add5 :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e)
add5 (x1 :: a
x1,x2 :: b
x2,x3 :: c
x3,x4 :: d
x4,x5 :: e
x5) (y1 :: a
y1,y2 :: b
y2,y3 :: c
y3,y4 :: d
y4,y5 :: e
y5) = (a
x1a -> a -> a
forall a. Num a => a -> a -> a
+a
y1,b
x2b -> b -> b
forall a. Num a => a -> a -> a
+b
y2,c
x3c -> c -> c
forall a. Num a => a -> a -> a
+c
y3,d
x4d -> d -> d
forall a. Num a => a -> a -> a
+d
y4,e
x5e -> e -> e
forall a. Num a => a -> a -> a
+e
y5)
    sum7 :: [(Int, Int, Int, Int, Int, Int, Int)]
-> (Int, Int, Int, Int, Int, Int, Int)
sum7 = ((Int, Int, Int, Int, Int, Int, Int)
 -> (Int, Int, Int, Int, Int, Int, Int)
 -> (Int, Int, Int, Int, Int, Int, Int))
-> (Int, Int, Int, Int, Int, Int, Int)
-> [(Int, Int, Int, Int, Int, Int, Int)]
-> (Int, Int, Int, Int, Int, Int, Int)
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (Int, Int, Int, Int, Int, Int, Int)
-> (Int, Int, Int, Int, Int, Int, Int)
-> (Int, Int, Int, Int, Int, Int, Int)
add7 (0,0,0,0,0,0,0)

    add7 :: (Int, Int, Int, Int, Int, Int, Int)
-> (Int, Int, Int, Int, Int, Int, Int)
-> (Int, Int, Int, Int, Int, Int, Int)
add7 (x1 :: Int
x1,x2 :: Int
x2,x3 :: Int
x3,x4 :: Int
x4,x5 :: Int
x5,x6 :: Int
x6,x7 :: Int
x7) (y1 :: Int
y1,y2 :: Int
y2,y3 :: Int
y3,y4 :: Int
y4,y5 :: Int
y5,y6 :: Int
y6,y7 :: Int
y7) = (Int
x1Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
y1,Int
x2Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
y2,Int
x3Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
y3,Int
x4Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
y4,Int
x5Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
y5,Int
x6Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
y6,Int
x7Int -> Int -> Int
forall a. Num a => a -> a -> a
+Int
y7)