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

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

module GHC.Hs.Stats ( ppSourceStats ) where

import GHC.Prelude

import GHC.Data.Bag
import GHC.Hs
import GHC.Types.SrcLoc

import GHC.Utils.Outputable
import GHC.Utils.Misc
import GHC.Utils.Panic

import Data.Char

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

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

    trim :: String -> String
trim 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)

    (Int
fixity_sigs, Int
bind_tys, Int
bind_specs, Int
bind_inlines, 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 XSigD GhcPs
_ 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 XTyClD GhcPs
_ TyClDecl GhcPs
d <- [HsDecl GhcPs]
decls]
    (Int
class_ds, Int
type_ds, Int
data_ds, Int
newt_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 XInstD GhcPs
_ InstDecl GhcPs
d <- [HsDecl GhcPs]
decls]
    inst_ds :: Int
inst_ds    = [InstDecl GhcPs] -> Int
forall a. [a] -> 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 (\ HsDecl GhcPs
x -> case HsDecl GhcPs
x of { DefD{} -> Bool
True; HsDecl GhcPs
_ -> Bool
False}) [HsDecl GhcPs]
decls
    val_decls :: [HsBindLR GhcPs GhcPs]
val_decls  = [HsBindLR GhcPs GhcPs
d | ValD XValD GhcPs
_ HsBindLR GhcPs GhcPs
d <- [HsDecl GhcPs]
decls]

    real_exports :: [GenLocated SrcSpanAnnA (IE GhcPs)]
real_exports = case Maybe (XRec GhcPs [LIE GhcPs])
exports of { Maybe (XRec GhcPs [LIE GhcPs])
Nothing -> []; Just (L SrcSpanAnnL
_ [GenLocated SrcSpanAnnA (IE GhcPs)]
es) -> [GenLocated SrcSpanAnnA (IE GhcPs)]
es }
    n_exports :: Int
n_exports    = [GenLocated SrcSpanAnnA (IE GhcPs)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [GenLocated SrcSpanAnnA (IE GhcPs)]
real_exports
    export_ms :: Int
export_ms    = (GenLocated SrcSpanAnnA (IE GhcPs) -> Bool)
-> [GenLocated SrcSpanAnnA (IE GhcPs)] -> Int
forall a. (a -> Bool) -> [a] -> Int
count (\ GenLocated SrcSpanAnnA (IE GhcPs)
e -> case GenLocated SrcSpanAnnA (IE GhcPs) -> IE GhcPs
forall l e. GenLocated l e -> e
unLoc GenLocated SrcSpanAnnA (IE GhcPs)
e of { IEModuleContents{} -> Bool
True
                                                 ; IE GhcPs
_ -> Bool
False})
                         [GenLocated SrcSpanAnnA (IE 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 (XRec GhcPs [LIE GhcPs])
exports of { Maybe (XRec GhcPs [LIE GhcPs])
Nothing -> Int
1; Maybe (XRec GhcPs [LIE GhcPs])
_ -> Int
0 }

    (Int
val_bind_ds, Int
fn_bind_ds, Int
patsyn_ds)
        = [(Int, Int, Int)] -> (Int, Int, Int)
sum3 ((HsBindLR GhcPs GhcPs -> (Int, Int, Int))
-> [HsBindLR GhcPs GhcPs] -> [(Int, Int, Int)]
forall a b. (a -> b) -> [a] -> [b]
map HsBindLR GhcPs GhcPs -> (Int, Int, Int)
forall {idL} {l} {a} {b} {c} {idR}.
(XRec idL (Pat idL) ~ GenLocated l (Pat idL), Num a, Num b, Num c,
 Outputable (HsBindLR idL idR)) =>
HsBindLR idL idR -> (a, b, c)
count_bind [HsBindLR GhcPs GhcPs]
val_decls)

    (Int
imp_no, Int
imp_safe, Int
imp_qual, Int
imp_as, Int
imp_all, Int
imp_partial, Int
imp_hiding)
        = [(Int, Int, Int, Int, Int, Int, Int)]
-> (Int, Int, Int, Int, Int, Int, Int)
sum7 ((GenLocated SrcSpanAnnA (ImportDecl GhcPs)
 -> (Int, Int, Int, Int, Int, Int, Int))
-> [GenLocated SrcSpanAnnA (ImportDecl 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)
GenLocated SrcSpanAnnA (ImportDecl GhcPs)
-> (Int, Int, Int, Int, Int, Int, Int)
import_info [LImportDecl GhcPs]
[GenLocated SrcSpanAnnA (ImportDecl GhcPs)]
imports)
    (Int
data_constrs, 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} {l} {t :: * -> *} {a}.
(XRec pass (HsDerivingClause pass)
 ~ GenLocated l (HsDerivingClause pass),
 XRec pass (DerivClauseTys pass) ~ t a, Foldable t) =>
TyClDecl pass -> (Int, Int)
data_info [TyClDecl GhcPs]
tycl_decls)
    (Int
class_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 {pass} {l} {l} {l}.
(XRec pass (HsBindLR pass pass)
 ~ GenLocated l (HsBindLR pass pass),
 XRec pass (Sig pass) ~ GenLocated l (Sig pass),
 XRec pass (Pat pass) ~ GenLocated l (Pat pass),
 Outputable (HsBindLR pass pass)) =>
TyClDecl pass -> (Int, Int)
class_info [TyClDecl GhcPs]
tycl_decls)
    (Int
inst_method_ds, Int
method_specs, Int
method_inlines, Int
inst_type_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)
inst_info [InstDecl GhcPs]
inst_decls)

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

    count_sigs :: [Sig pass] -> (Int, Int, Int, Int, Int)
count_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 {})     = (a
1,b
0,c
0,d
0,e
0)
    sig_info (TypeSig {})    = (a
0,b
1,c
0,d
0,e
0)
    sig_info (SpecSig {})    = (a
0,b
0,c
1,d
0,e
0)
    sig_info (InlineSig {})  = (a
0,b
0,c
0,d
1,e
0)
    sig_info (ClassOpSig {}) = (a
0,b
0,c
0,d
0,e
1)
    sig_info Sig pass
_               = (a
0,b
0,c
0,d
0,e
0)

    import_info :: LImportDecl GhcPs -> (Int, Int, Int, Int, Int, Int, Int)
    import_info :: LImportDecl GhcPs -> (Int, Int, Int, Int, Int, Int, Int)
import_info (L SrcSpanAnnA
_ (ImportDecl { ideclSafe :: forall pass. ImportDecl pass -> Bool
ideclSafe = Bool
safe, ideclQualified :: forall pass. ImportDecl pass -> ImportDeclQualifiedStyle
ideclQualified = ImportDeclQualifiedStyle
qual
                                 , ideclAs :: forall pass. ImportDecl pass -> Maybe (XRec pass ModuleName)
ideclAs = Maybe (XRec GhcPs ModuleName)
as, ideclImportList :: forall pass.
ImportDecl pass
-> Maybe (ImportListInterpretation, XRec pass [LIE pass])
ideclImportList = Maybe (ImportListInterpretation, XRec GhcPs [LIE GhcPs])
spec }))
        = (Int, Int, Int, Int, Int, Int, Int)
-> (Int, Int, Int, Int, Int, Int, Int)
-> (Int, Int, Int, Int, Int, Int, Int)
add7 (Int
1, Bool -> Int
forall {a}. Num a => Bool -> a
safe_info Bool
safe, ImportDeclQualifiedStyle -> Int
forall {a}. Num a => ImportDeclQualifiedStyle -> a
qual_info ImportDeclQualifiedStyle
qual, Maybe (GenLocated SrcSpanAnnA ModuleName) -> Int
forall {a} {a}. Num a => Maybe a -> a
as_info Maybe (XRec GhcPs ModuleName)
Maybe (GenLocated SrcSpanAnnA ModuleName)
as, Int
0,Int
0,Int
0) (Maybe
  (ImportListInterpretation,
   GenLocated SrcSpanAnnL [GenLocated SrcSpanAnnA (IE 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 (ImportListInterpretation, b) -> (a, b, c, d, e, f, g)
spec_info Maybe (ImportListInterpretation, XRec GhcPs [LIE GhcPs])
Maybe
  (ImportListInterpretation,
   GenLocated SrcSpanAnnL [GenLocated SrcSpanAnnA (IE GhcPs)])
spec)

    safe_info :: Bool -> a
safe_info Bool
False = a
0
    safe_info Bool
True = a
1
    qual_info :: ImportDeclQualifiedStyle -> a
qual_info ImportDeclQualifiedStyle
NotQualified = a
0
    qual_info ImportDeclQualifiedStyle
_  = a
1
    as_info :: Maybe a -> a
as_info Maybe a
Nothing  = a
0
    as_info (Just a
_) = a
1
    spec_info :: Maybe (ImportListInterpretation, b) -> (a, b, c, d, e, f, g)
spec_info Maybe (ImportListInterpretation, b)
Nothing           = (a
0,b
0,c
0,d
0,e
1,f
0,g
0)
    spec_info (Just (ImportListInterpretation
Exactly, b
_)) = (a
0,b
0,c
0,d
0,e
0,f
1,g
0)
    spec_info (Just (ImportListInterpretation
EverythingBut, b
_))  = (a
0,b
0,c
0,d
0,e
0,f
0,g
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 -> DataDefnCons (LConDecl pass)
dd_cons = DataDefnCons (LConDecl pass)
cs
                                          , dd_derivs :: forall pass. HsDataDefn pass -> HsDeriving pass
dd_derivs = HsDeriving pass
derivs}})
        = ( DataDefnCons (LConDecl pass) -> Int
forall a. DataDefnCons a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length DataDefnCons (LConDecl pass)
cs
          , (Int -> GenLocated l (HsDerivingClause pass) -> Int)
-> Int -> [GenLocated l (HsDerivingClause pass)] -> Int
forall b a. (b -> a -> b) -> b -> [a] -> b
forall (t :: * -> *) b a.
Foldable t =>
(b -> a -> b) -> b -> t a -> b
foldl' (\Int
s GenLocated l (HsDerivingClause pass)
dc -> t a -> Int
forall a. t a -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length (HsDerivingClause pass -> XRec pass (DerivClauseTys pass)
forall pass. HsDerivingClause pass -> LDerivClauseTys pass
deriv_clause_tys (HsDerivingClause pass -> XRec pass (DerivClauseTys pass))
-> HsDerivingClause pass -> XRec pass (DerivClauseTys pass)
forall a b. (a -> b) -> a -> b
$ GenLocated l (HsDerivingClause pass) -> HsDerivingClause pass
forall l e. GenLocated l e -> e
unLoc GenLocated l (HsDerivingClause pass)
dc) Int -> Int -> Int
forall a. Num a => a -> a -> a
+ Int
s)
                   Int
0 HsDeriving pass
[GenLocated l (HsDerivingClause pass)]
derivs )
    data_info TyClDecl pass
_ = (Int
0,Int
0)

    class_info :: TyClDecl pass -> (Int, Int)
class_info decl :: TyClDecl pass
decl@(ClassDecl {})
        = (Int
classops, (Int, Int, Int) -> Int
addpr ([(Int, Int, Int)] -> (Int, Int, Int)
sum3 ((HsBindLR pass pass -> (Int, Int, Int))
-> [HsBindLR pass pass] -> [(Int, Int, Int)]
forall a b. (a -> b) -> [a] -> [b]
map HsBindLR pass pass -> (Int, Int, Int)
forall {idL} {l} {a} {b} {c} {idR}.
(XRec idL (Pat idL) ~ GenLocated l (Pat idL), Num a, Num b, Num c,
 Outputable (HsBindLR idL idR)) =>
HsBindLR idL idR -> (a, b, c)
count_bind [HsBindLR pass pass]
methods)))
      where
        methods :: [HsBindLR pass pass]
methods = (GenLocated l (HsBindLR pass pass) -> HsBindLR pass pass)
-> [GenLocated l (HsBindLR pass pass)] -> [HsBindLR pass pass]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated l (HsBindLR pass pass) -> HsBindLR pass pass
forall l e. GenLocated l e -> e
unLoc ([GenLocated l (HsBindLR pass pass)] -> [HsBindLR pass pass])
-> [GenLocated l (HsBindLR pass pass)] -> [HsBindLR pass pass]
forall a b. (a -> b) -> a -> b
$ Bag (GenLocated l (HsBindLR pass pass))
-> [GenLocated l (HsBindLR pass pass)]
forall a. Bag a -> [a]
bagToList (TyClDecl pass -> LHsBinds pass
forall pass. TyClDecl pass -> LHsBinds pass
tcdMeths TyClDecl pass
decl)
        (Int
_, Int
classops, Int
_, Int
_, Int
_) = [Sig pass] -> (Int, Int, Int, Int, Int)
forall {pass}. [Sig pass] -> (Int, Int, Int, Int, Int)
count_sigs ((GenLocated l (Sig pass) -> Sig pass)
-> [GenLocated l (Sig pass)] -> [Sig pass]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated l (Sig pass) -> Sig pass
forall l e. GenLocated l e -> e
unLoc (TyClDecl pass -> [XRec pass (Sig pass)]
forall pass. TyClDecl pass -> [LSig pass]
tcdSigs TyClDecl pass
decl))
    class_info TyClDecl pass
_ = (Int
0,Int
0)

    inst_info :: InstDecl GhcPs -> (Int, Int, Int, Int, Int)
    inst_info :: InstDecl GhcPs -> (Int, Int, Int, Int, Int)
inst_info (TyFamInstD {}) = (Int
0,Int
0,Int
0,Int
1,Int
0)
    inst_info (DataFamInstD {}) = (Int
0,Int
0,Int
0,Int
0,Int
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 GhcPs
inst_meths
                                                 , cid_sigs :: forall pass. ClsInstDecl pass -> [LSig pass]
cid_sigs = [XRec GhcPs (Sig GhcPs)]
inst_sigs
                                                 , cid_tyfam_insts :: forall pass. ClsInstDecl pass -> [LTyFamInstDecl pass]
cid_tyfam_insts = [LTyFamInstDecl GhcPs]
ats
                                                 , cid_datafam_insts :: forall pass. ClsInstDecl pass -> [LDataFamInstDecl pass]
cid_datafam_insts = [LDataFamInstDecl GhcPs]
adts } })
        = case [Sig GhcPs] -> (Int, Int, Int, Int, Int)
forall {pass}. [Sig pass] -> (Int, Int, Int, Int, Int)
count_sigs ((GenLocated SrcSpanAnnA (Sig GhcPs) -> Sig GhcPs)
-> [GenLocated SrcSpanAnnA (Sig GhcPs)] -> [Sig GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnA (Sig GhcPs) -> Sig GhcPs
forall l e. GenLocated l e -> e
unLoc [XRec GhcPs (Sig GhcPs)]
[GenLocated SrcSpanAnnA (Sig GhcPs)]
inst_sigs) of
            (Int
_,Int
_,Int
ss,Int
is,Int
_) ->
                  ((Int, Int, Int) -> Int
addpr ([(Int, Int, Int)] -> (Int, Int, Int)
sum3 ((HsBindLR GhcPs GhcPs -> (Int, Int, Int))
-> [HsBindLR GhcPs GhcPs] -> [(Int, Int, Int)]
forall a b. (a -> b) -> [a] -> [b]
map HsBindLR GhcPs GhcPs -> (Int, Int, Int)
forall {idL} {l} {a} {b} {c} {idR}.
(XRec idL (Pat idL) ~ GenLocated l (Pat idL), Num a, Num b, Num c,
 Outputable (HsBindLR idL idR)) =>
HsBindLR idL idR -> (a, b, c)
count_bind [HsBindLR GhcPs GhcPs]
methods)),
                   Int
ss, Int
is, [GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LTyFamInstDecl GhcPs]
[GenLocated SrcSpanAnnA (TyFamInstDecl GhcPs)]
ats, [GenLocated SrcSpanAnnA (DataFamInstDecl GhcPs)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [LDataFamInstDecl GhcPs]
[GenLocated SrcSpanAnnA (DataFamInstDecl GhcPs)]
adts)
      where
        methods :: [HsBindLR GhcPs GhcPs]
methods = (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs)
 -> HsBindLR GhcPs GhcPs)
-> [GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs)]
-> [HsBindLR GhcPs GhcPs]
forall a b. (a -> b) -> [a] -> [b]
map GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs)
-> HsBindLR GhcPs GhcPs
forall l e. GenLocated l e -> e
unLoc ([GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs)]
 -> [HsBindLR GhcPs GhcPs])
-> [GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs)]
-> [HsBindLR GhcPs GhcPs]
forall a b. (a -> b) -> a -> b
$ Bag (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs))
-> [GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs)]
forall a. Bag a -> [a]
bagToList LHsBinds GhcPs
Bag (GenLocated SrcSpanAnnA (HsBindLR GhcPs GhcPs))
inst_meths

    -- 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 (Int
x,Int
y,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 a b. (a -> b -> b) -> b -> [a] -> b
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 (Int
0,Int
0)
      where
        add2 :: (a, b) -> (a, b) -> (a, b)
add2 (a
x1,b
x2) (a
y1,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 a b. (a -> b -> b) -> b -> [a] -> b
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 (Int
0,Int
0,Int
0)
      where
        add3 :: (a, b, c) -> (a, b, c) -> (a, b, c)
add3 (a
x1,b
x2,c
x3) (a
y1,b
y2,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 a b. (a -> b -> b) -> b -> [a] -> b
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 (Int
0,Int
0,Int
0,Int
0,Int
0)
      where
        add5 :: (a, b, c, d, e) -> (a, b, c, d, e) -> (a, b, c, d, e)
add5 (a
x1,b
x2,c
x3,d
x4,e
x5) (a
y1,b
y2,c
y3,d
y4,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 a b. (a -> b -> b) -> b -> [a] -> b
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 (Int
0,Int
0,Int
0,Int
0,Int
0,Int
0,Int
0)

    add7 :: (Int, Int, Int, Int, Int, Int, Int)
-> (Int, Int, Int, Int, Int, Int, Int)
-> (Int, Int, Int, Int, Int, Int, Int)
add7 (Int
x1,Int
x2,Int
x3,Int
x4,Int
x5,Int
x6,Int
x7) (Int
y1,Int
y2,Int
y3,Int
y4,Int
y5,Int
y6,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)