{-
(c) The University of Glasgow 2006
(c) The GRASP/AQUA Project, Glasgow University, 1993-1998
-}


{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DeriveTraversable #-}

module GHC.Iface.Syntax (
        module GHC.Iface.Type,

        IfaceDecl(..), IfaceFamTyConFlav(..), IfaceClassOp(..), IfaceAT(..),
        IfaceConDecl(..), IfaceConDecls(..), IfaceEqSpec,
        IfaceExpr(..), IfaceAlt(..), IfaceLetBndr(..), IfaceJoinInfo(..), IfaceBinding,
        IfaceBindingX(..), IfaceMaybeRhs(..), IfaceConAlt(..),
        IfaceIdInfo, IfaceIdDetails(..), IfaceUnfolding(..), IfGuidance(..),
        IfaceInfoItem(..), IfaceRule(..), IfaceAnnotation(..), IfaceAnnTarget,
        IfaceClsInst(..), IfaceFamInst(..), IfaceTickish(..),
        IfaceClassBody(..),
        IfaceBang(..),
        IfaceSrcBang(..), SrcUnpackedness(..), SrcStrictness(..),
        IfaceAxBranch(..),
        IfaceTyConParent(..),
        IfaceCompleteMatch(..),
        IfaceLFInfo(..), IfaceTopBndrInfo(..),

        -- * Binding names
        IfaceTopBndr,
        putIfaceTopBndr, getIfaceTopBndr,

        -- Misc
        ifaceDeclImplicitBndrs, visibleIfConDecls,
        ifaceDeclFingerprints,

        -- Free Names
        freeNamesIfDecl, freeNamesIfRule, freeNamesIfFamInst,

        -- Pretty printing
        pprIfaceExpr,
        pprIfaceDecl,
        AltPpr(..), ShowSub(..), ShowHowMuch(..), showToIface, showToHeader
    ) where

import GHC.Prelude

import GHC.Builtin.Names ( unrestrictedFunTyConKey, liftedTypeKindTyConKey,
                           constraintKindTyConKey )
import GHC.Types.Unique ( hasKey )
import GHC.Iface.Type
import GHC.Iface.Recomp.Binary
import GHC.Core( IsOrphan, isOrphan, UnfoldingCache(..) )
import GHC.Types.Demand
import GHC.Types.Cpr
import GHC.Core.Class
import GHC.Types.FieldLabel
import GHC.Types.Name.Set
import GHC.Core.Coercion.Axiom ( BranchIndex )
import GHC.Types.Name
import GHC.Types.CostCentre
import GHC.Types.Literal
import GHC.Types.ForeignCall
import GHC.Types.Annotations( AnnPayload, AnnTarget )
import GHC.Types.Basic
import GHC.Unit.Module
import GHC.Types.SrcLoc
import GHC.Data.BooleanFormula ( BooleanFormula, pprBooleanFormula, isTrue )
import GHC.Types.Var( VarBndr(..), binderVar, tyVarSpecToBinders, visArgTypeLike )
import GHC.Core.TyCon ( Role (..), Injectivity(..), tyConBndrVisForAllTyFlag )
import GHC.Core.DataCon (SrcStrictness(..), SrcUnpackedness(..))
import GHC.Builtin.Types ( constraintKindTyConName )
import GHC.Stg.InferTags.TagSig

import GHC.Utils.Lexeme (isLexSym)
import GHC.Utils.Fingerprint
import GHC.Utils.Binary
import GHC.Utils.Binary.Typeable ()
import GHC.Utils.Outputable as Outputable
import GHC.Utils.Panic
import GHC.Utils.Misc( dropList, filterByList, notNull, unzipWith,
                       seqList, zipWithEqual )

import Language.Haskell.Syntax.Basic (FieldLabelString(..))

import Control.Monad
import System.IO.Unsafe
import Control.DeepSeq

infixl 3 &&&

{-
************************************************************************
*                                                                      *
                    Declarations
*                                                                      *
************************************************************************
-}

-- | A binding top-level 'Name' in an interface file (e.g. the name of an
-- 'IfaceDecl').
type IfaceTopBndr = Name
  -- It's convenient to have a Name in the Iface syntax, although in each
  -- case the namespace is implied by the context. However, having a
  -- Name makes things like ifaceDeclImplicitBndrs and ifaceDeclFingerprints
  -- very convenient. Moreover, having the key of the binder means that
  -- we can encode known-key things cleverly in the symbol table. See Note
  -- [Symbol table representation of Names]
  --
  -- We don't serialise the namespace onto the disk though; rather we
  -- drop it when serialising and add it back in when deserialising.

getIfaceTopBndr :: BinHandle -> IO IfaceTopBndr
getIfaceTopBndr :: BinHandle -> IO IfExtName
getIfaceTopBndr BinHandle
bh = forall a. Binary a => BinHandle -> IO a
get BinHandle
bh

putIfaceTopBndr :: BinHandle -> IfaceTopBndr -> IO ()
putIfaceTopBndr :: BinHandle -> IfExtName -> IO ()
putIfaceTopBndr BinHandle
bh IfExtName
name =
    case BinHandle -> UserData
getUserData BinHandle
bh of
      UserData{ ud_put_binding_name :: UserData -> BinHandle -> IfExtName -> IO ()
ud_put_binding_name = BinHandle -> IfExtName -> IO ()
put_binding_name } ->
          --pprTrace "putIfaceTopBndr" (ppr name) $
          BinHandle -> IfExtName -> IO ()
put_binding_name BinHandle
bh IfExtName
name


data IfaceDecl
  = IfaceId { IfaceDecl -> IfExtName
ifName      :: IfaceTopBndr,
              IfaceDecl -> IfaceType
ifType      :: IfaceType,
              IfaceDecl -> IfaceIdDetails
ifIdDetails :: IfaceIdDetails,
              IfaceDecl -> IfaceIdInfo
ifIdInfo    :: IfaceIdInfo
              }

  | IfaceData { ifName       :: IfaceTopBndr,   -- Type constructor
                IfaceDecl -> [IfaceTyConBinder]
ifBinders    :: [IfaceTyConBinder],
                IfaceDecl -> IfaceType
ifResKind    :: IfaceType,      -- Result kind of type constructor
                IfaceDecl -> Maybe CType
ifCType      :: Maybe CType,    -- C type for CAPI FFI
                IfaceDecl -> [Role]
ifRoles      :: [Role],         -- Roles
                IfaceDecl -> IfaceContext
ifCtxt       :: IfaceContext,   -- The "stupid theta"
                IfaceDecl -> IfaceConDecls
ifCons       :: IfaceConDecls,  -- Includes new/data/data family info
                IfaceDecl -> Bool
ifGadtSyntax :: Bool,           -- True <=> declared using
                                                -- GADT syntax
                IfaceDecl -> IfaceTyConParent
ifParent     :: IfaceTyConParent -- The axiom, for a newtype,
                                                 -- or data/newtype family instance
    }

  | IfaceSynonym { ifName    :: IfaceTopBndr,      -- Type constructor
                   ifRoles   :: [Role],            -- Roles
                   ifBinders :: [IfaceTyConBinder],
                   ifResKind :: IfaceKind,         -- Kind of the *result*
                   IfaceDecl -> IfaceType
ifSynRhs  :: IfaceType }

  | IfaceFamily  { ifName    :: IfaceTopBndr,      -- Type constructor
                   IfaceDecl -> Maybe IfLclName
ifResVar  :: Maybe IfLclName,   -- Result variable name, used
                                                   -- only for pretty-printing
                                                   -- with --show-iface
                   ifBinders :: [IfaceTyConBinder],
                   ifResKind :: IfaceKind,         -- Kind of the *tycon*
                   IfaceDecl -> IfaceFamTyConFlav
ifFamFlav :: IfaceFamTyConFlav,
                   IfaceDecl -> Injectivity
ifFamInj  :: Injectivity }      -- injectivity information

  | IfaceClass { ifName    :: IfaceTopBndr,             -- Name of the class TyCon
                 ifRoles   :: [Role],                   -- Roles
                 ifBinders :: [IfaceTyConBinder],
                 IfaceDecl -> [FunDep IfLclName]
ifFDs     :: [FunDep IfLclName],       -- Functional dependencies
                 IfaceDecl -> IfaceClassBody
ifBody    :: IfaceClassBody            -- Methods, superclasses, ATs
    }

  | IfaceAxiom { ifName       :: IfaceTopBndr,        -- Axiom name
                 IfaceDecl -> IfaceTyCon
ifTyCon      :: IfaceTyCon,     -- LHS TyCon
                 IfaceDecl -> Role
ifRole       :: Role,           -- Role of axiom
                 IfaceDecl -> [IfaceAxBranch]
ifAxBranches :: [IfaceAxBranch] -- Branches
    }

  | IfacePatSyn { ifName          :: IfaceTopBndr,           -- Name of the pattern synonym
                  IfaceDecl -> Bool
ifPatIsInfix    :: Bool,
                  IfaceDecl -> (IfExtName, Bool)
ifPatMatcher    :: (IfExtName, Bool),
                  IfaceDecl -> Maybe (IfExtName, Bool)
ifPatBuilder    :: Maybe (IfExtName, Bool),
                  -- Everything below is redundant,
                  -- but needed to implement pprIfaceDecl
                  IfaceDecl -> [IfaceForAllSpecBndr]
ifPatUnivBndrs  :: [IfaceForAllSpecBndr],
                  IfaceDecl -> [IfaceForAllSpecBndr]
ifPatExBndrs    :: [IfaceForAllSpecBndr],
                  IfaceDecl -> IfaceContext
ifPatProvCtxt   :: IfaceContext,
                  IfaceDecl -> IfaceContext
ifPatReqCtxt    :: IfaceContext,
                  IfaceDecl -> IfaceContext
ifPatArgs       :: [IfaceType],
                  IfaceDecl -> IfaceType
ifPatTy         :: IfaceType,
                  IfaceDecl -> [FieldLabel]
ifFieldLabels   :: [FieldLabel] }

-- See also 'ClassBody'
data IfaceClassBody
  -- Abstract classes don't specify their body; they only occur in @hs-boot@ and
  -- @hsig@ files.
  = IfAbstractClass
  | IfConcreteClass {
     IfaceClassBody -> IfaceContext
ifClassCtxt :: IfaceContext,             -- Super classes
     IfaceClassBody -> [IfaceAT]
ifATs       :: [IfaceAT],                -- Associated type families
     IfaceClassBody -> [IfaceClassOp]
ifSigs      :: [IfaceClassOp],           -- Method signatures
     IfaceClassBody -> BooleanFormula IfLclName
ifMinDef    :: BooleanFormula IfLclName  -- Minimal complete definition
    }

data IfaceTyConParent
  = IfNoParent
  | IfDataInstance
       IfExtName     -- Axiom name
       IfaceTyCon    -- Family TyCon (pretty-printing only, not used in GHC.IfaceToCore)
                     -- see Note [Pretty printing via Iface syntax] in GHC.Types.TyThing.Ppr
       IfaceAppArgs  -- Arguments of the family TyCon

data IfaceFamTyConFlav
  = IfaceDataFamilyTyCon                      -- Data family
  | IfaceOpenSynFamilyTyCon
  | IfaceClosedSynFamilyTyCon (Maybe (IfExtName, [IfaceAxBranch]))
    -- ^ Name of associated axiom and branches for pretty printing purposes,
    -- or 'Nothing' for an empty closed family without an axiom
    -- See Note [Pretty printing via Iface syntax] in "GHC.Types.TyThing.Ppr"
  | IfaceAbstractClosedSynFamilyTyCon
  | IfaceBuiltInSynFamTyCon -- for pretty printing purposes only

data IfaceClassOp
  = IfaceClassOp IfaceTopBndr
                 IfaceType                         -- Class op type
                 (Maybe (DefMethSpec IfaceType))   -- Default method
                 -- The types of both the class op itself,
                 -- and the default method, are *not* quantified
                 -- over the class variables

data IfaceAT = IfaceAT  -- See GHC.Core.Class.ClassATItem
                  IfaceDecl          -- The associated type declaration
                  (Maybe IfaceType)  -- Default associated type instance, if any


-- This is just like CoAxBranch
data IfaceAxBranch = IfaceAxBranch { IfaceAxBranch -> [IfaceTvBndr]
ifaxbTyVars    :: [IfaceTvBndr]
                                   , IfaceAxBranch -> [IfaceTvBndr]
ifaxbEtaTyVars :: [IfaceTvBndr]
                                   , IfaceAxBranch -> [IfaceIdBndr]
ifaxbCoVars    :: [IfaceIdBndr]
                                   , IfaceAxBranch -> IfaceAppArgs
ifaxbLHS       :: IfaceAppArgs
                                   , IfaceAxBranch -> [Role]
ifaxbRoles     :: [Role]
                                   , IfaceAxBranch -> IfaceType
ifaxbRHS       :: IfaceType
                                   , IfaceAxBranch -> [Int]
ifaxbIncomps   :: [BranchIndex] }
                                     -- See Note [Storing compatibility] in GHC.Core.Coercion.Axiom

data IfaceConDecls
  = IfAbstractTyCon -- c.f TyCon.AbstractTyCon
  | IfDataTyCon !Bool [IfaceConDecl] -- Data type decls
        -- The Bool is True for "type data" declarations.
        -- see Note [Type data declarations] in GHC.Rename.Module
  | IfNewTyCon  IfaceConDecl   -- Newtype decls

-- For IfDataTyCon and IfNewTyCon we store:
--  * the data constructor(s);
-- The field labels are stored individually in the IfaceConDecl
-- (there is some redundancy here, because a field label may occur
-- in multiple IfaceConDecls and represent the same field label)

data IfaceConDecl
  = IfCon {
        IfaceConDecl -> IfExtName
ifConName    :: IfaceTopBndr,                -- Constructor name
        IfaceConDecl -> Bool
ifConWrapper :: Bool,                   -- True <=> has a wrapper
        IfaceConDecl -> Bool
ifConInfix   :: Bool,                   -- True <=> declared infix

        -- The universal type variables are precisely those
        -- of the type constructor of this data constructor
        -- This is *easy* to guarantee when creating the IfCon
        -- but it's not so easy for the original TyCon/DataCon
        -- So this guarantee holds for IfaceConDecl, but *not* for DataCon

        IfaceConDecl -> [IfaceBndr]
ifConExTCvs   :: [IfaceBndr],  -- Existential ty/covars
        IfaceConDecl -> [IfaceForAllSpecBndr]
ifConUserTvBinders :: [IfaceForAllSpecBndr],
          -- The tyvars, in the order the user wrote them
          -- INVARIANT: the set of tyvars in ifConUserTvBinders is exactly the
          --            set of tyvars (*not* covars) of ifConExTCvs, unioned
          --            with the set of ifBinders (from the parent IfaceDecl)
          --            whose tyvars do not appear in ifConEqSpec
          -- See Note [DataCon user type variable binders] in GHC.Core.DataCon
        IfaceConDecl -> [IfaceTvBndr]
ifConEqSpec  :: IfaceEqSpec,        -- Equality constraints
        IfaceConDecl -> IfaceContext
ifConCtxt    :: IfaceContext,       -- Non-stupid context
        IfaceConDecl -> [(IfaceType, IfaceType)]
ifConArgTys  :: [(IfaceMult, IfaceType)],-- Arg types
        IfaceConDecl -> [FieldLabel]
ifConFields  :: [FieldLabel],  -- ...ditto... (field labels)
        IfaceConDecl -> [IfaceBang]
ifConStricts :: [IfaceBang],
          -- Empty (meaning all lazy),
          -- or 1-1 corresp with arg tys
          -- See Note [Bangs on imported data constructors] in GHC.Types.Id.Make
        IfaceConDecl -> [IfaceSrcBang]
ifConSrcStricts :: [IfaceSrcBang] } -- empty meaning no src stricts

type IfaceEqSpec = [(IfLclName,IfaceType)]

-- | This corresponds to an HsImplBang; that is, the final
-- implementation decision about the data constructor arg
data IfaceBang
  = IfNoBang | IfStrict | IfUnpack | IfUnpackCo IfaceCoercion

-- | This corresponds to HsSrcBang
data IfaceSrcBang
  = IfSrcBang SrcUnpackedness SrcStrictness

data IfaceClsInst
  = IfaceClsInst { IfaceClsInst -> IfExtName
ifInstCls  :: IfExtName,                -- See comments with
                   IfaceClsInst -> [Maybe IfaceTyCon]
ifInstTys  :: [Maybe IfaceTyCon],       -- the defn of ClsInst
                   IfaceClsInst -> IfExtName
ifDFun     :: IfExtName,                -- The dfun
                   IfaceClsInst -> OverlapFlag
ifOFlag    :: OverlapFlag,              -- Overlap flag
                   IfaceClsInst -> IsOrphan
ifInstOrph :: IsOrphan }                -- See Note [Orphans] in GHC.Core.InstEnv
        -- There's always a separate IfaceDecl for the DFun, which gives
        -- its IdInfo with its full type and version number.
        -- The instance declarations taken together have a version number,
        -- and we don't want that to wobble gratuitously
        -- If this instance decl is *used*, we'll record a usage on the dfun;
        -- and if the head does not change it won't be used if it wasn't before

-- The ifFamInstTys field of IfaceFamInst contains a list of the rough
-- match types
data IfaceFamInst
  = IfaceFamInst { IfaceFamInst -> IfExtName
ifFamInstFam      :: IfExtName            -- Family name
                 , IfaceFamInst -> [Maybe IfaceTyCon]
ifFamInstTys      :: [Maybe IfaceTyCon]   -- See above
                 , IfaceFamInst -> IfExtName
ifFamInstAxiom    :: IfExtName            -- The axiom
                 , IfaceFamInst -> IsOrphan
ifFamInstOrph     :: IsOrphan             -- Just like IfaceClsInst
                 }

data IfaceRule
  = IfaceRule {
        IfaceRule -> IfLclName
ifRuleName   :: RuleName,
        IfaceRule -> Activation
ifActivation :: Activation,
        IfaceRule -> [IfaceBndr]
ifRuleBndrs  :: [IfaceBndr],    -- Tyvars and term vars
        IfaceRule -> IfExtName
ifRuleHead   :: IfExtName,      -- Head of lhs
        IfaceRule -> [IfaceExpr]
ifRuleArgs   :: [IfaceExpr],    -- Args of LHS
        IfaceRule -> IfaceExpr
ifRuleRhs    :: IfaceExpr,
        IfaceRule -> Bool
ifRuleAuto   :: Bool,
        IfaceRule -> IsOrphan
ifRuleOrph   :: IsOrphan   -- Just like IfaceClsInst
    }

data IfaceAnnotation
  = IfaceAnnotation {
        IfaceAnnotation -> IfaceAnnTarget
ifAnnotatedTarget :: IfaceAnnTarget,
        IfaceAnnotation -> AnnPayload
ifAnnotatedValue  :: AnnPayload
  }

type IfaceAnnTarget = AnnTarget OccName

data IfaceCompleteMatch = IfaceCompleteMatch [IfExtName] (Maybe IfaceTyCon)

instance Outputable IfaceCompleteMatch where
  ppr :: IfaceCompleteMatch -> SDoc
ppr (IfaceCompleteMatch [IfExtName]
cls Maybe IfaceTyCon
mtc) = forall doc. IsLine doc => String -> doc
text String
"COMPLETE" forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
colon forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr [IfExtName]
cls forall doc. IsLine doc => doc -> doc -> doc
<+> case Maybe IfaceTyCon
mtc of
    Maybe IfaceTyCon
Nothing -> forall doc. IsOutput doc => doc
empty
    Just IfaceTyCon
tc -> SDoc
dcolon forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceTyCon
tc

-- Here's a tricky case:
--   * Compile with -O module A, and B which imports A.f
--   * Change function f in A, and recompile without -O
--   * When we read in old A.hi we read in its IdInfo (as a thunk)
--      (In earlier GHCs we used to drop IdInfo immediately on reading,
--       but we do not do that now.  Instead it's discarded when the
--       ModIface is read into the various decl pools.)
--   * The version comparison sees that new (=NoInfo) differs from old (=HasInfo *)
--      and so gives a new version.

type IfaceIdInfo = [IfaceInfoItem]

data IfaceInfoItem
  = HsArity         Arity
  | HsDmdSig        DmdSig
  | HsCprSig        CprSig
  | HsInline        InlinePragma
  | HsUnfold        Bool             -- True <=> isStrongLoopBreaker is true
                    IfaceUnfolding   -- See Note [Expose recursive functions]
  | HsNoCafRefs
  | HsLFInfo        IfaceLFInfo
  | HsTagSig        TagSig

-- NB: Specialisations and rules come in separately and are
-- only later attached to the Id.  Partial reason: some are orphans.

data IfaceUnfolding
  = IfCoreUnfold UnfoldingSource
                 IfUnfoldingCache -- See Note [Tying the 'CoreUnfolding' knot]
                 IfGuidance
                 IfaceExpr
  | IfDFunUnfold [IfaceBndr] [IfaceExpr]

type IfUnfoldingCache = UnfoldingCache

data IfGuidance
  = IfNoGuidance            -- Compute it from the IfaceExpr
  | IfWhen Arity Bool Bool  -- Just like UnfWhen in Core.UnfoldingGuidance

-- We only serialise the IdDetails of top-level Ids, and even then
-- we only need a very limited selection.  Notably, none of the
-- implicit ones are needed here, because they are not put in
-- interface files

data IfaceIdDetails
  = IfVanillaId
  | IfWorkerLikeId [CbvMark]
  | IfRecSelId (Either IfaceTyCon IfaceDecl) Bool
  | IfDFunId

-- | Iface type for LambdaFormInfo. Fields not relevant for imported Ids are
-- omitted in this type.
data IfaceLFInfo
  = IfLFReEntrant !RepArity
  | IfLFThunk
      !Bool -- True <=> updatable
      !Bool -- True <=> might be a function type
  | IfLFCon !Name
  | IfLFUnknown !Bool
  | IfLFUnlifted

instance Outputable IfaceLFInfo where
    ppr :: IfaceLFInfo -> SDoc
ppr (IfLFReEntrant Int
arity) =
      forall doc. IsLine doc => String -> doc
text String
"LFReEntrant" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Int
arity

    ppr (IfLFThunk Bool
updatable Bool
mb_fun) =
      forall doc. IsLine doc => String -> doc
text String
"LFThunk" forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => doc -> doc
parens
        (forall doc. IsLine doc => String -> doc
text String
"updatable=" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr Bool
updatable forall doc. IsLine doc => doc -> doc -> doc
<+>
         forall doc. IsLine doc => String -> doc
text String
"might_be_function=" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Bool
mb_fun)

    ppr (IfLFCon IfExtName
con) =
      forall doc. IsLine doc => String -> doc
text String
"LFCon" forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc -> doc
brackets (forall a. Outputable a => a -> SDoc
ppr IfExtName
con)

    ppr IfaceLFInfo
IfLFUnlifted =
      forall doc. IsLine doc => String -> doc
text String
"LFUnlifted"

    ppr (IfLFUnknown Bool
fun_flag) =
      forall doc. IsLine doc => String -> doc
text String
"LFUnknown" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Bool
fun_flag

instance Binary IfaceLFInfo where
    put_ :: BinHandle -> IfaceLFInfo -> IO ()
put_ BinHandle
bh (IfLFReEntrant Int
arity) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Int
arity
    put_ BinHandle
bh (IfLFThunk Bool
updatable Bool
mb_fun) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
updatable
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
mb_fun
    put_ BinHandle
bh (IfLFCon IfExtName
con_name) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfExtName
con_name
    put_ BinHandle
bh (IfLFUnknown Bool
fun_flag) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
3
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
fun_flag
    put_ BinHandle
bh IfaceLFInfo
IfLFUnlifted =
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
4
    get :: BinHandle -> IO IfaceLFInfo
get BinHandle
bh = do
        Word8
tag <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
tag of
            Word8
0 -> Int -> IfaceLFInfo
IfLFReEntrant forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
            Word8
1 -> Bool -> Bool -> IfaceLFInfo
IfLFThunk forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
            Word8
2 -> IfExtName -> IfaceLFInfo
IfLFCon forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
            Word8
3 -> Bool -> IfaceLFInfo
IfLFUnknown forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
            Word8
4 -> forall (f :: * -> *) a. Applicative f => a -> f a
pure IfaceLFInfo
IfLFUnlifted
            Word8
_ -> forall a. HasCallStack => String -> a
panic String
"Invalid byte"

{-
Note [Versioning of instances]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
See [https://gitlab.haskell.org/ghc/ghc/wikis/commentary/compiler/recompilation-avoidance#instances]


************************************************************************
*                                                                      *
                Functions over declarations
*                                                                      *
************************************************************************
-}

visibleIfConDecls :: IfaceConDecls -> [IfaceConDecl]
visibleIfConDecls :: IfaceConDecls -> [IfaceConDecl]
visibleIfConDecls (IfAbstractTyCon {}) = []
visibleIfConDecls (IfDataTyCon Bool
_ [IfaceConDecl]
cs)   = [IfaceConDecl]
cs
visibleIfConDecls (IfNewTyCon IfaceConDecl
c)       = [IfaceConDecl
c]

ifaceDeclImplicitBndrs :: IfaceDecl -> [OccName]
--  *Excludes* the 'main' name, but *includes* the implicitly-bound names
-- Deeply revolting, because it has to predict what gets bound,
-- especially the question of whether there's a wrapper for a datacon
-- See Note [Implicit TyThings] in GHC.Driver.Env

-- N.B. the set of names returned here *must* match the set of TyThings
-- returned by GHC.Types.TyThing.implicitTyThings, in the sense that
-- TyThing.getOccName should define a bijection between the two lists.
-- This invariant is used in GHC.IfaceToCore.tc_iface_decl_fingerprint
-- (see Note [Tricky iface loop] in GHC.Types.TyThing.)
-- The order of the list does not matter.

ifaceDeclImplicitBndrs :: IfaceDecl -> [OccName]
ifaceDeclImplicitBndrs (IfaceData {ifName :: IfaceDecl -> IfExtName
ifName = IfExtName
tc_name, ifCons :: IfaceDecl -> IfaceConDecls
ifCons = IfaceConDecls
cons })
  = case IfaceConDecls
cons of
      IfAbstractTyCon {} -> []
      IfNewTyCon  IfaceConDecl
cd     -> OccName -> OccName
mkNewTyCoOcc (forall name. HasOccName name => name -> OccName
occName IfExtName
tc_name) forall a. a -> [a] -> [a]
: IfaceConDecl -> [OccName]
ifaceConDeclImplicitBndrs IfaceConDecl
cd
      IfDataTyCon Bool
type_data [IfaceConDecl]
cds
        | Bool
type_data ->
          -- Constructors in "type data" declarations have no implicits.
          -- see Note [Type data declarations] in GHC.Rename.Module
          [forall name. HasOccName name => name -> OccName
occName IfExtName
con_name | IfCon { ifConName :: IfaceConDecl -> IfExtName
ifConName = IfExtName
con_name } <- [IfaceConDecl]
cds]
        | Bool
otherwise -> forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap IfaceConDecl -> [OccName]
ifaceConDeclImplicitBndrs [IfaceConDecl]
cds

ifaceDeclImplicitBndrs (IfaceClass { ifBody :: IfaceDecl -> IfaceClassBody
ifBody = IfaceClassBody
IfAbstractClass })
  = []

ifaceDeclImplicitBndrs (IfaceClass { ifName :: IfaceDecl -> IfExtName
ifName = IfExtName
cls_tc_name
                                   , ifBody :: IfaceDecl -> IfaceClassBody
ifBody = IfConcreteClass {
                                        ifClassCtxt :: IfaceClassBody -> IfaceContext
ifClassCtxt = IfaceContext
sc_ctxt,
                                        ifSigs :: IfaceClassBody -> [IfaceClassOp]
ifSigs      = [IfaceClassOp]
sigs,
                                        ifATs :: IfaceClassBody -> [IfaceAT]
ifATs       = [IfaceAT]
ats
                                     }})
  = --   (possibly) newtype coercion
    [OccName]
co_occs forall a. [a] -> [a] -> [a]
++
    --    data constructor (DataCon namespace)
    --    data worker (Id namespace)
    --    no wrapper (class dictionaries never have a wrapper)
    [OccName
dc_occ, OccName
dcww_occ] forall a. [a] -> [a] -> [a]
++
    -- associated types
    [forall name. HasOccName name => name -> OccName
occName (IfaceDecl -> IfExtName
ifName IfaceDecl
at) | IfaceAT IfaceDecl
at Maybe IfaceType
_ <- [IfaceAT]
ats ] forall a. [a] -> [a] -> [a]
++
    -- superclass selectors
    [Int -> OccName -> OccName
mkSuperDictSelOcc Int
n OccName
cls_tc_occ | Int
n <- [Int
1..Int
n_ctxt]] forall a. [a] -> [a] -> [a]
++
    -- operation selectors
    [forall name. HasOccName name => name -> OccName
occName IfExtName
op | IfaceClassOp IfExtName
op  IfaceType
_ Maybe (DefMethSpec IfaceType)
_ <- [IfaceClassOp]
sigs]
  where
    cls_tc_occ :: OccName
cls_tc_occ = forall name. HasOccName name => name -> OccName
occName IfExtName
cls_tc_name
    n_ctxt :: Int
n_ctxt = forall (t :: * -> *) a. Foldable t => t a -> Int
length IfaceContext
sc_ctxt
    n_sigs :: Int
n_sigs = forall (t :: * -> *) a. Foldable t => t a -> Int
length [IfaceClassOp]
sigs
    co_occs :: [OccName]
co_occs | Bool
is_newtype = [OccName -> OccName
mkNewTyCoOcc OccName
cls_tc_occ]
            | Bool
otherwise  = []
    dcww_occ :: OccName
dcww_occ = OccName -> OccName
mkDataConWorkerOcc OccName
dc_occ
    dc_occ :: OccName
dc_occ = OccName -> OccName
mkClassDataConOcc OccName
cls_tc_occ
    is_newtype :: Bool
is_newtype = Int
n_sigs forall a. Num a => a -> a -> a
+ Int
n_ctxt forall a. Eq a => a -> a -> Bool
== Int
1 -- Sigh (keep this synced with buildClass)

ifaceDeclImplicitBndrs IfaceDecl
_ = []

ifaceConDeclImplicitBndrs :: IfaceConDecl -> [OccName]
ifaceConDeclImplicitBndrs :: IfaceConDecl -> [OccName]
ifaceConDeclImplicitBndrs (IfCon {
        ifConWrapper :: IfaceConDecl -> Bool
ifConWrapper = Bool
has_wrapper, ifConName :: IfaceConDecl -> IfExtName
ifConName = IfExtName
con_name })
  = [forall name. HasOccName name => name -> OccName
occName IfExtName
con_name, OccName
work_occ] forall a. [a] -> [a] -> [a]
++ [OccName]
wrap_occs
  where
    con_occ :: OccName
con_occ = forall name. HasOccName name => name -> OccName
occName IfExtName
con_name
    work_occ :: OccName
work_occ  = OccName -> OccName
mkDataConWorkerOcc OccName
con_occ                   -- Id namespace
    wrap_occs :: [OccName]
wrap_occs | Bool
has_wrapper = [OccName -> OccName
mkDataConWrapperOcc OccName
con_occ]  -- Id namespace
              | Bool
otherwise   = []

-- -----------------------------------------------------------------------------
-- The fingerprints of an IfaceDecl

       -- We better give each name bound by the declaration a
       -- different fingerprint!  So we calculate the fingerprint of
       -- each binder by combining the fingerprint of the whole
       -- declaration with the name of the binder. (#5614, #7215)
ifaceDeclFingerprints :: Fingerprint -> IfaceDecl -> [(OccName,Fingerprint)]
ifaceDeclFingerprints :: Fingerprint -> IfaceDecl -> [(OccName, Fingerprint)]
ifaceDeclFingerprints Fingerprint
hash IfaceDecl
decl
  = (forall a. NamedThing a => a -> OccName
getOccName IfaceDecl
decl, Fingerprint
hash) forall a. a -> [a] -> [a]
:
    [ (OccName
occ, (Fingerprint, OccName) -> Fingerprint
computeFingerprint' (Fingerprint
hash,OccName
occ))
    | OccName
occ <- IfaceDecl -> [OccName]
ifaceDeclImplicitBndrs IfaceDecl
decl ]
  where
     computeFingerprint' :: (Fingerprint, OccName) -> Fingerprint
computeFingerprint' =
       forall a. IO a -> a
unsafeDupablePerformIO
        forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a.
Binary a =>
(BinHandle -> IfExtName -> IO ()) -> a -> IO Fingerprint
computeFingerprint (forall a. HasCallStack => String -> a
panic String
"ifaceDeclFingerprints")

{-
************************************************************************
*                                                                      *
                Expressions
*                                                                      *
************************************************************************
-}

data IfaceExpr
  = IfaceLcl    IfLclName
  | IfaceExt    IfExtName
  | IfaceType   IfaceType
  | IfaceCo     IfaceCoercion
  | IfaceTuple  TupleSort [IfaceExpr]   -- Saturated; type arguments omitted
  | IfaceLam    IfaceLamBndr IfaceExpr
  | IfaceApp    IfaceExpr IfaceExpr
  | IfaceCase   IfaceExpr IfLclName [IfaceAlt]
  | IfaceECase  IfaceExpr IfaceType     -- See Note [Empty case alternatives]
  | IfaceLet    (IfaceBinding IfaceLetBndr) IfaceExpr
  | IfaceCast   IfaceExpr IfaceCoercion
  | IfaceLit    Literal
  | IfaceLitRubbish TypeOrConstraint IfaceType
       -- See GHC.Types.Literal Note [Rubbish literals] item (6)
  | IfaceFCall  ForeignCall IfaceType
  | IfaceTick   IfaceTickish IfaceExpr    -- from Tick tickish E

data IfaceTickish
  = IfaceHpcTick Module Int                -- from HpcTick x
  | IfaceSCC     CostCentre Bool Bool      -- from ProfNote
  | IfaceSource  RealSrcSpan String        -- from SourceNote
  -- no breakpoints: we never export these into interface files

data IfaceAlt = IfaceAlt IfaceConAlt [IfLclName] IfaceExpr
        -- Note: IfLclName, not IfaceBndr (and same with the case binder)
        -- We reconstruct the kind/type of the thing from the context
        -- thus saving bulk in interface files

data IfaceConAlt = IfaceDefault
                 | IfaceDataAlt IfExtName
                 | IfaceLitAlt Literal

type IfaceBinding b = IfaceBindingX IfaceExpr b

data IfaceBindingX r b
  = IfaceNonRec b r
  | IfaceRec    [(b, r)]
  deriving (forall a b. a -> IfaceBindingX r b -> IfaceBindingX r a
forall a b. (a -> b) -> IfaceBindingX r a -> IfaceBindingX r b
forall r a b. a -> IfaceBindingX r b -> IfaceBindingX r a
forall r a b. (a -> b) -> IfaceBindingX r a -> IfaceBindingX r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: forall a b. a -> IfaceBindingX r b -> IfaceBindingX r a
$c<$ :: forall r a b. a -> IfaceBindingX r b -> IfaceBindingX r a
fmap :: forall a b. (a -> b) -> IfaceBindingX r a -> IfaceBindingX r b
$cfmap :: forall r a b. (a -> b) -> IfaceBindingX r a -> IfaceBindingX r b
Functor, forall a. IfaceBindingX r a -> Bool
forall r a. Eq a => a -> IfaceBindingX r a -> Bool
forall r a. Num a => IfaceBindingX r a -> a
forall r a. Ord a => IfaceBindingX r a -> a
forall m a. Monoid m => (a -> m) -> IfaceBindingX r a -> m
forall r m. Monoid m => IfaceBindingX r m -> m
forall r a. IfaceBindingX r a -> Bool
forall r a. IfaceBindingX r a -> Int
forall r a. IfaceBindingX r a -> [a]
forall a b. (a -> b -> b) -> b -> IfaceBindingX r a -> b
forall r a. (a -> a -> a) -> IfaceBindingX r a -> a
forall r m a. Monoid m => (a -> m) -> IfaceBindingX r a -> m
forall r b a. (b -> a -> b) -> b -> IfaceBindingX r a -> b
forall r a b. (a -> b -> b) -> b -> IfaceBindingX r a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
product :: forall a. Num a => IfaceBindingX r a -> a
$cproduct :: forall r a. Num a => IfaceBindingX r a -> a
sum :: forall a. Num a => IfaceBindingX r a -> a
$csum :: forall r a. Num a => IfaceBindingX r a -> a
minimum :: forall a. Ord a => IfaceBindingX r a -> a
$cminimum :: forall r a. Ord a => IfaceBindingX r a -> a
maximum :: forall a. Ord a => IfaceBindingX r a -> a
$cmaximum :: forall r a. Ord a => IfaceBindingX r a -> a
elem :: forall a. Eq a => a -> IfaceBindingX r a -> Bool
$celem :: forall r a. Eq a => a -> IfaceBindingX r a -> Bool
length :: forall a. IfaceBindingX r a -> Int
$clength :: forall r a. IfaceBindingX r a -> Int
null :: forall a. IfaceBindingX r a -> Bool
$cnull :: forall r a. IfaceBindingX r a -> Bool
toList :: forall a. IfaceBindingX r a -> [a]
$ctoList :: forall r a. IfaceBindingX r a -> [a]
foldl1 :: forall a. (a -> a -> a) -> IfaceBindingX r a -> a
$cfoldl1 :: forall r a. (a -> a -> a) -> IfaceBindingX r a -> a
foldr1 :: forall a. (a -> a -> a) -> IfaceBindingX r a -> a
$cfoldr1 :: forall r a. (a -> a -> a) -> IfaceBindingX r a -> a
foldl' :: forall b a. (b -> a -> b) -> b -> IfaceBindingX r a -> b
$cfoldl' :: forall r b a. (b -> a -> b) -> b -> IfaceBindingX r a -> b
foldl :: forall b a. (b -> a -> b) -> b -> IfaceBindingX r a -> b
$cfoldl :: forall r b a. (b -> a -> b) -> b -> IfaceBindingX r a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> IfaceBindingX r a -> b
$cfoldr' :: forall r a b. (a -> b -> b) -> b -> IfaceBindingX r a -> b
foldr :: forall a b. (a -> b -> b) -> b -> IfaceBindingX r a -> b
$cfoldr :: forall r a b. (a -> b -> b) -> b -> IfaceBindingX r a -> b
foldMap' :: forall m a. Monoid m => (a -> m) -> IfaceBindingX r a -> m
$cfoldMap' :: forall r m a. Monoid m => (a -> m) -> IfaceBindingX r a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> IfaceBindingX r a -> m
$cfoldMap :: forall r m a. Monoid m => (a -> m) -> IfaceBindingX r a -> m
fold :: forall m. Monoid m => IfaceBindingX r m -> m
$cfold :: forall r m. Monoid m => IfaceBindingX r m -> m
Foldable, forall r. Functor (IfaceBindingX r)
forall r. Foldable (IfaceBindingX r)
forall r (m :: * -> *) a.
Monad m =>
IfaceBindingX r (m a) -> m (IfaceBindingX r a)
forall r (f :: * -> *) a.
Applicative f =>
IfaceBindingX r (f a) -> f (IfaceBindingX r a)
forall r (m :: * -> *) a b.
Monad m =>
(a -> m b) -> IfaceBindingX r a -> m (IfaceBindingX r b)
forall r (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> IfaceBindingX r a -> f (IfaceBindingX r b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> IfaceBindingX r a -> f (IfaceBindingX r b)
sequence :: forall (m :: * -> *) a.
Monad m =>
IfaceBindingX r (m a) -> m (IfaceBindingX r a)
$csequence :: forall r (m :: * -> *) a.
Monad m =>
IfaceBindingX r (m a) -> m (IfaceBindingX r a)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> IfaceBindingX r a -> m (IfaceBindingX r b)
$cmapM :: forall r (m :: * -> *) a b.
Monad m =>
(a -> m b) -> IfaceBindingX r a -> m (IfaceBindingX r b)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
IfaceBindingX r (f a) -> f (IfaceBindingX r a)
$csequenceA :: forall r (f :: * -> *) a.
Applicative f =>
IfaceBindingX r (f a) -> f (IfaceBindingX r a)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> IfaceBindingX r a -> f (IfaceBindingX r b)
$ctraverse :: forall r (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> IfaceBindingX r a -> f (IfaceBindingX r b)
Traversable, IfaceBindingX r b -> IfaceBindingX r b -> Bool
IfaceBindingX r b -> IfaceBindingX r b -> Ordering
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
forall {r} {b}. (Ord b, Ord r) => Eq (IfaceBindingX r b)
forall r b.
(Ord b, Ord r) =>
IfaceBindingX r b -> IfaceBindingX r b -> Bool
forall r b.
(Ord b, Ord r) =>
IfaceBindingX r b -> IfaceBindingX r b -> Ordering
forall r b.
(Ord b, Ord r) =>
IfaceBindingX r b -> IfaceBindingX r b -> IfaceBindingX r b
min :: IfaceBindingX r b -> IfaceBindingX r b -> IfaceBindingX r b
$cmin :: forall r b.
(Ord b, Ord r) =>
IfaceBindingX r b -> IfaceBindingX r b -> IfaceBindingX r b
max :: IfaceBindingX r b -> IfaceBindingX r b -> IfaceBindingX r b
$cmax :: forall r b.
(Ord b, Ord r) =>
IfaceBindingX r b -> IfaceBindingX r b -> IfaceBindingX r b
>= :: IfaceBindingX r b -> IfaceBindingX r b -> Bool
$c>= :: forall r b.
(Ord b, Ord r) =>
IfaceBindingX r b -> IfaceBindingX r b -> Bool
> :: IfaceBindingX r b -> IfaceBindingX r b -> Bool
$c> :: forall r b.
(Ord b, Ord r) =>
IfaceBindingX r b -> IfaceBindingX r b -> Bool
<= :: IfaceBindingX r b -> IfaceBindingX r b -> Bool
$c<= :: forall r b.
(Ord b, Ord r) =>
IfaceBindingX r b -> IfaceBindingX r b -> Bool
< :: IfaceBindingX r b -> IfaceBindingX r b -> Bool
$c< :: forall r b.
(Ord b, Ord r) =>
IfaceBindingX r b -> IfaceBindingX r b -> Bool
compare :: IfaceBindingX r b -> IfaceBindingX r b -> Ordering
$ccompare :: forall r b.
(Ord b, Ord r) =>
IfaceBindingX r b -> IfaceBindingX r b -> Ordering
Ord, IfaceBindingX r b -> IfaceBindingX r b -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall r b.
(Eq b, Eq r) =>
IfaceBindingX r b -> IfaceBindingX r b -> Bool
/= :: IfaceBindingX r b -> IfaceBindingX r b -> Bool
$c/= :: forall r b.
(Eq b, Eq r) =>
IfaceBindingX r b -> IfaceBindingX r b -> Bool
== :: IfaceBindingX r b -> IfaceBindingX r b -> Bool
$c== :: forall r b.
(Eq b, Eq r) =>
IfaceBindingX r b -> IfaceBindingX r b -> Bool
Eq)

-- IfaceLetBndr is like IfaceIdBndr, but has IdInfo too
-- It's used for *non-top-level* let/rec binders
-- See Note [IdInfo on nested let-bindings]
data IfaceLetBndr = IfLetBndr IfLclName IfaceType IfaceIdInfo IfaceJoinInfo

data IfaceTopBndrInfo = IfLclTopBndr IfLclName IfaceType IfaceIdInfo IfaceIdDetails
                      | IfGblTopBndr IfaceTopBndr

-- See Note [Interface File with Core: Sharing RHSs]
data IfaceMaybeRhs = IfUseUnfoldingRhs | IfRhs IfaceExpr

data IfaceJoinInfo = IfaceNotJoinPoint
                   | IfaceJoinPoint JoinArity

{-
Note [Empty case alternatives]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In Iface syntax an IfaceCase does not record the types of the alternatives,
unlike Core syntax Case. But we need this type if the alternatives are empty.
Hence IfaceECase. See Note [Empty case alternatives] in GHC.Core.

Note [Expose recursive functions]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
For supercompilation we want to put *all* unfoldings in the interface
file, even for functions that are recursive (or big).  So we need to
know when an unfolding belongs to a loop-breaker so that we can refrain
from inlining it (except during supercompilation).

Note [IdInfo on nested let-bindings]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Occasionally we want to preserve IdInfo on nested let bindings. The one
that came up was a NOINLINE pragma on a let-binding inside an INLINE
function.  The user (Duncan Coutts) really wanted the NOINLINE control
to cross the separate compilation boundary.

In general we retain all info that is left by GHC.Core.Tidy.tidyLetBndr, since
that is what is seen by importing module with --make

Note [Displaying axiom incompatibilities]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
With -fprint-axiom-incomps we display which closed type family equations
are incompatible with which. This information is sometimes necessary
because GHC doesn't try equations in order: any equation can be used when
all preceding equations that are incompatible with it do not apply.

For example, the last "a && a = a" equation in Data.Type.Bool.&& is
actually compatible with all previous equations, and can reduce at any
time.

This is displayed as:
Prelude> :i Data.Type.Equality.==
type family (==) (a :: k) (b :: k) :: Bool
  where
    {- #0 -} (==) (f a) (g b) = (f == g) && (a == b)
    {- #1 -} (==) a a = 'True
          -- incompatible with: #0
    {- #2 -} (==) _1 _2 = 'False
          -- incompatible with: #1, #0
The comment after an equation refers to all previous equations (0-indexed)
that are incompatible with it.

************************************************************************
*                                                                      *
              Printing IfaceDecl
*                                                                      *
************************************************************************
-}

pprAxBranch :: SDoc -> BranchIndex -> IfaceAxBranch -> SDoc
-- The TyCon might be local (just an OccName), or this might
-- be a branch for an imported TyCon, so it would be an ExtName
-- So it's easier to take an SDoc here
--
-- This function is used
--    to print interface files,
--    in debug messages
--    in :info F for GHCi, which goes via toConToIfaceDecl on the family tycon
-- For user error messages we use Coercion.pprCoAxiom and friends
pprAxBranch :: SDoc -> Int -> IfaceAxBranch -> SDoc
pprAxBranch SDoc
pp_tc Int
idx (IfaceAxBranch { ifaxbTyVars :: IfaceAxBranch -> [IfaceTvBndr]
ifaxbTyVars = [IfaceTvBndr]
tvs
                                     , ifaxbCoVars :: IfaceAxBranch -> [IfaceIdBndr]
ifaxbCoVars = [IfaceIdBndr]
_cvs
                                     , ifaxbLHS :: IfaceAxBranch -> IfaceAppArgs
ifaxbLHS = IfaceAppArgs
pat_tys
                                     , ifaxbRHS :: IfaceAxBranch -> IfaceType
ifaxbRHS = IfaceType
rhs
                                     , ifaxbIncomps :: IfaceAxBranch -> [Int]
ifaxbIncomps = [Int]
incomps })
  = forall a. HasCallStack => Bool -> SDoc -> a -> a
assertPpr (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [IfaceIdBndr]
_cvs) (SDoc
pp_tc forall doc. IsDoc doc => doc -> doc -> doc
$$ forall a. Outputable a => a -> SDoc
ppr [IfaceIdBndr]
_cvs) forall a b. (a -> b) -> a -> b
$
    SDoc -> Int -> SDoc -> SDoc
hang SDoc
ppr_binders Int
2 (SDoc -> Int -> SDoc -> SDoc
hang SDoc
pp_lhs Int
2 (forall doc. IsLine doc => doc
equals forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceType
rhs))
    SDoc -> SDoc -> SDoc
$+$
    Int -> SDoc -> SDoc
nest Int
4 SDoc
maybe_incomps
  where
    -- See Note [Printing foralls in type family instances] in GHC.Iface.Type
    ppr_binders :: SDoc
ppr_binders = SDoc
maybe_index forall doc. IsLine doc => doc -> doc -> doc
<+>
      [IfaceForAllBndr] -> SDoc
pprUserIfaceForAll (forall a b. (a -> b) -> [a] -> [b]
map (ForAllTyFlag -> IfaceTvBndr -> IfaceForAllBndr
mkIfaceForAllTvBndr ForAllTyFlag
Specified) [IfaceTvBndr]
tvs)
    pp_lhs :: SDoc
pp_lhs = SDoc -> Int -> SDoc -> SDoc
hang SDoc
pp_tc Int
2 (IfaceAppArgs -> SDoc
pprParendIfaceAppArgs IfaceAppArgs
pat_tys)

    -- See Note [Displaying axiom incompatibilities]
    maybe_index :: SDoc
maybe_index
      = (SDocContext -> Bool) -> SDoc -> SDoc
ppWhenOption SDocContext -> Bool
sdocPrintAxiomIncomps forall a b. (a -> b) -> a -> b
$
          forall doc. IsLine doc => String -> doc
text String
"{-" forall doc. IsLine doc => doc -> doc -> doc
<+> (forall doc. IsLine doc => String -> doc
text String
"#" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr Int
idx) forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"-}"
    maybe_incomps :: SDoc
maybe_incomps
      = (SDocContext -> Bool) -> SDoc -> SDoc
ppWhenOption SDocContext -> Bool
sdocPrintAxiomIncomps forall a b. (a -> b) -> a -> b
$
          forall doc. IsOutput doc => Bool -> doc -> doc
ppWhen (forall (f :: * -> *) a. Foldable f => f a -> Bool
notNull [Int]
incomps) forall a b. (a -> b) -> a -> b
$
            forall doc. IsLine doc => String -> doc
text String
"--" forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"incompatible with:"
            forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas (\Int
incomp -> forall doc. IsLine doc => String -> doc
text String
"#" forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr Int
incomp) [Int]
incomps

instance Outputable IfaceAnnotation where
  ppr :: IfaceAnnotation -> SDoc
ppr (IfaceAnnotation IfaceAnnTarget
target AnnPayload
value) = forall a. Outputable a => a -> SDoc
ppr IfaceAnnTarget
target forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => doc
colon forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr AnnPayload
value

instance NamedThing IfaceClassOp where
  getName :: IfaceClassOp -> IfExtName
getName (IfaceClassOp IfExtName
n IfaceType
_ Maybe (DefMethSpec IfaceType)
_) = IfExtName
n

instance HasOccName IfaceClassOp where
  occName :: IfaceClassOp -> OccName
occName = forall a. NamedThing a => a -> OccName
getOccName

instance NamedThing IfaceConDecl where
  getName :: IfaceConDecl -> IfExtName
getName = IfaceConDecl -> IfExtName
ifConName

instance HasOccName IfaceConDecl where
  occName :: IfaceConDecl -> OccName
occName = forall a. NamedThing a => a -> OccName
getOccName

instance NamedThing IfaceDecl where
  getName :: IfaceDecl -> IfExtName
getName = IfaceDecl -> IfExtName
ifName

instance HasOccName IfaceDecl where
  occName :: IfaceDecl -> OccName
occName = forall a. NamedThing a => a -> OccName
getOccName

instance Outputable IfaceDecl where
  ppr :: IfaceDecl -> SDoc
ppr = ShowSub -> IfaceDecl -> SDoc
pprIfaceDecl ShowSub
showToIface

instance (Outputable r, Outputable b) => Outputable (IfaceBindingX r b) where
  ppr :: IfaceBindingX r b -> SDoc
ppr IfaceBindingX r b
b = case IfaceBindingX r b
b of
            (IfaceNonRec b
b r
r) -> forall {a} {a}. (Outputable a, Outputable a) => (a, a) -> SDoc
ppr_bind (b
b, r
r)
            (IfaceRec [(b, r)]
pairs) -> forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => String -> doc
text String
"rec {", Int -> SDoc -> SDoc
nest Int
2 (forall doc. IsLine doc => [doc] -> doc
sep (forall a b. (a -> b) -> [a] -> [b]
map forall {a} {a}. (Outputable a, Outputable a) => (a, a) -> SDoc
ppr_bind [(b, r)]
pairs)),forall doc. IsLine doc => String -> doc
text String
"}"]
    where
      ppr_bind :: (a, a) -> SDoc
ppr_bind (a
b, a
r) = forall a. Outputable a => a -> SDoc
ppr a
b forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => doc
equals forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr a
r

instance Outputable IfaceTopBndrInfo where
    ppr :: IfaceTopBndrInfo -> SDoc
ppr (IfLclTopBndr IfLclName
lcl_name IfaceType
_ IfaceIdInfo
_ IfaceIdDetails
_) = forall a. Outputable a => a -> SDoc
ppr IfLclName
lcl_name
    ppr (IfGblTopBndr IfExtName
gbl) = forall a. Outputable a => a -> SDoc
ppr IfExtName
gbl

instance Outputable IfaceMaybeRhs where
  ppr :: IfaceMaybeRhs -> SDoc
ppr IfaceMaybeRhs
IfUseUnfoldingRhs = forall doc. IsLine doc => String -> doc
text String
"<unfolding>"
  ppr (IfRhs IfaceExpr
ie) = forall a. Outputable a => a -> SDoc
ppr IfaceExpr
ie

{-
Note [Minimal complete definition]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The minimal complete definition should only be included if a complete
class definition is shown. Since the minimal complete definition is
anonymous we can't reuse the same mechanism that is used for the
filtering of method signatures. Instead we just check if anything at all is
filtered and hide it in that case.
-}

data ShowSub
  = ShowSub
      { ShowSub -> ShowHowMuch
ss_how_much :: ShowHowMuch
      , ShowSub -> ShowForAllFlag
ss_forall :: ShowForAllFlag }

-- See Note [Printing IfaceDecl binders]
-- The alternative pretty printer referred to in the note.
newtype AltPpr = AltPpr (Maybe (OccName -> SDoc))

data ShowHowMuch
  = ShowHeader AltPpr -- ^Header information only, not rhs
  | ShowSome [OccName] AltPpr
  -- ^ Show only some sub-components. Specifically,
  --
  -- [@\[\]@] Print all sub-components.
  -- [@(n:ns)@] Print sub-component @n@ with @ShowSub = ns@;
  -- elide other sub-components to @...@
  -- May 14: the list is max 1 element long at the moment
  | ShowIface
  -- ^Everything including GHC-internal information (used in --show-iface)

{-
Note [Printing IfaceDecl binders]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The binders in an IfaceDecl are just OccNames, so we don't know what module they
come from.  But when we pretty-print a TyThing by converting to an IfaceDecl
(see GHC.Types.TyThing.Ppr), the TyThing may come from some other module so we really need
the module qualifier.  We solve this by passing in a pretty-printer for the
binders.

When printing an interface file (--show-iface), we want to print
everything unqualified, so we can just print the OccName directly.
-}

instance Outputable ShowHowMuch where
  ppr :: ShowHowMuch -> SDoc
ppr (ShowHeader AltPpr
_)    = forall doc. IsLine doc => String -> doc
text String
"ShowHeader"
  ppr ShowHowMuch
ShowIface         = forall doc. IsLine doc => String -> doc
text String
"ShowIface"
  ppr (ShowSome [OccName]
occs AltPpr
_) = forall doc. IsLine doc => String -> doc
text String
"ShowSome" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr [OccName]
occs

showToHeader :: ShowSub
showToHeader :: ShowSub
showToHeader = ShowSub { ss_how_much :: ShowHowMuch
ss_how_much = AltPpr -> ShowHowMuch
ShowHeader forall a b. (a -> b) -> a -> b
$ Maybe (OccName -> SDoc) -> AltPpr
AltPpr forall a. Maybe a
Nothing
                       , ss_forall :: ShowForAllFlag
ss_forall = ShowForAllFlag
ShowForAllWhen }

showToIface :: ShowSub
showToIface :: ShowSub
showToIface = ShowSub { ss_how_much :: ShowHowMuch
ss_how_much = ShowHowMuch
ShowIface
                      , ss_forall :: ShowForAllFlag
ss_forall = ShowForAllFlag
ShowForAllWhen }

ppShowIface :: ShowSub -> SDoc -> SDoc
ppShowIface :: ShowSub -> SDoc -> SDoc
ppShowIface (ShowSub { ss_how_much :: ShowSub -> ShowHowMuch
ss_how_much = ShowHowMuch
ShowIface }) SDoc
doc = SDoc
doc
ppShowIface ShowSub
_                                     SDoc
_   = forall doc. IsOutput doc => doc
Outputable.empty

-- show if all sub-components or the complete interface is shown
ppShowAllSubs :: ShowSub -> SDoc -> SDoc -- See Note [Minimal complete definition]
ppShowAllSubs :: ShowSub -> SDoc -> SDoc
ppShowAllSubs (ShowSub { ss_how_much :: ShowSub -> ShowHowMuch
ss_how_much = ShowSome [] AltPpr
_ }) SDoc
doc = SDoc
doc
ppShowAllSubs (ShowSub { ss_how_much :: ShowSub -> ShowHowMuch
ss_how_much = ShowHowMuch
ShowIface })     SDoc
doc = SDoc
doc
ppShowAllSubs ShowSub
_                                         SDoc
_   = forall doc. IsOutput doc => doc
Outputable.empty

ppShowRhs :: ShowSub -> SDoc -> SDoc
ppShowRhs :: ShowSub -> SDoc -> SDoc
ppShowRhs (ShowSub { ss_how_much :: ShowSub -> ShowHowMuch
ss_how_much = ShowHeader AltPpr
_ }) SDoc
_   = forall doc. IsOutput doc => doc
Outputable.empty
ppShowRhs ShowSub
_                                        SDoc
doc = SDoc
doc

showSub :: HasOccName n => ShowSub -> n -> Bool
showSub :: forall n. HasOccName n => ShowSub -> n -> Bool
showSub (ShowSub { ss_how_much :: ShowSub -> ShowHowMuch
ss_how_much = ShowHeader AltPpr
_ })     n
_     = Bool
False
showSub (ShowSub { ss_how_much :: ShowSub -> ShowHowMuch
ss_how_much = ShowSome (OccName
n:[OccName]
_) AltPpr
_ }) n
thing = OccName
n forall a. Eq a => a -> a -> Bool
== forall name. HasOccName name => name -> OccName
occName n
thing
showSub (ShowSub { ss_how_much :: ShowSub -> ShowHowMuch
ss_how_much = ShowHowMuch
_ })              n
_     = Bool
True

ppr_trim :: [Maybe SDoc] -> [SDoc]
-- Collapse a group of Nothings to a single "..."
ppr_trim :: [Maybe SDoc] -> [SDoc]
ppr_trim [Maybe SDoc]
xs
  = forall a b. (a, b) -> b
snd (forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr forall {a}. IsLine a => Maybe a -> (Bool, [a]) -> (Bool, [a])
go (Bool
False, []) [Maybe SDoc]
xs)
  where
    go :: Maybe a -> (Bool, [a]) -> (Bool, [a])
go (Just a
doc) (Bool
_,     [a]
so_far) = (Bool
False, a
doc forall a. a -> [a] -> [a]
: [a]
so_far)
    go Maybe a
Nothing    (Bool
True,  [a]
so_far) = (Bool
True, [a]
so_far)
    go Maybe a
Nothing    (Bool
False, [a]
so_far) = (Bool
True, forall doc. IsLine doc => String -> doc
text String
"..." forall a. a -> [a] -> [a]
: [a]
so_far)

isIfaceDataInstance :: IfaceTyConParent -> Bool
isIfaceDataInstance :: IfaceTyConParent -> Bool
isIfaceDataInstance IfaceTyConParent
IfNoParent = Bool
False
isIfaceDataInstance IfaceTyConParent
_          = Bool
True

pprClassRoles :: ShowSub -> IfaceTopBndr -> [IfaceTyConBinder] -> [Role] -> SDoc
pprClassRoles :: ShowSub -> IfExtName -> [IfaceTyConBinder] -> [Role] -> SDoc
pprClassRoles ShowSub
ss IfExtName
clas [IfaceTyConBinder]
binders [Role]
roles =
    (Role -> Bool) -> SDoc -> [IfaceTyConBinder] -> [Role] -> SDoc
pprRoles (forall a. Eq a => a -> a -> Bool
== Role
Nominal)
             (ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr (ShowSub -> ShowHowMuch
ss_how_much ShowSub
ss) (forall name. HasOccName name => name -> OccName
occName IfExtName
clas))
             [IfaceTyConBinder]
binders
             [Role]
roles

pprClassStandaloneKindSig :: ShowSub -> IfaceTopBndr -> IfaceKind -> SDoc
pprClassStandaloneKindSig :: ShowSub -> IfExtName -> IfaceType -> SDoc
pprClassStandaloneKindSig ShowSub
ss IfExtName
clas =
  SDoc -> IfaceType -> SDoc
pprStandaloneKindSig (ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr (ShowSub -> ShowHowMuch
ss_how_much ShowSub
ss) (forall name. HasOccName name => name -> OccName
occName IfExtName
clas))

constraintIfaceKind :: IfaceKind
constraintIfaceKind :: IfaceType
constraintIfaceKind =
  IfaceTyCon -> IfaceAppArgs -> IfaceType
IfaceTyConApp (IfExtName -> IfaceTyConInfo -> IfaceTyCon
IfaceTyCon IfExtName
constraintKindTyConName (PromotionFlag -> IfaceTyConSort -> IfaceTyConInfo
mkIfaceTyConInfo PromotionFlag
NotPromoted IfaceTyConSort
IfaceNormalTyCon)) IfaceAppArgs
IA_Nil

pprIfaceDecl :: ShowSub -> IfaceDecl -> SDoc
-- NB: pprIfaceDecl is also used for pretty-printing TyThings in GHCi
--     See Note [Pretty printing via Iface syntax] in GHC.Types.TyThing.Ppr
pprIfaceDecl :: ShowSub -> IfaceDecl -> SDoc
pprIfaceDecl ShowSub
ss (IfaceData { ifName :: IfaceDecl -> IfExtName
ifName = IfExtName
tycon, ifCType :: IfaceDecl -> Maybe CType
ifCType = Maybe CType
ctype,
                             ifCtxt :: IfaceDecl -> IfaceContext
ifCtxt = IfaceContext
context, ifResKind :: IfaceDecl -> IfaceType
ifResKind = IfaceType
kind,
                             ifRoles :: IfaceDecl -> [Role]
ifRoles = [Role]
roles, ifCons :: IfaceDecl -> IfaceConDecls
ifCons = IfaceConDecls
condecls,
                             ifParent :: IfaceDecl -> IfaceTyConParent
ifParent = IfaceTyConParent
parent,
                             ifGadtSyntax :: IfaceDecl -> Bool
ifGadtSyntax = Bool
gadt,
                             ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
binders })

  | Bool
gadt      = forall doc. IsDoc doc => [doc] -> doc
vcat [ SDoc
pp_roles
                     , SDoc
pp_ki_sig
                     , SDoc
pp_nd forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_lhs forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_kind forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_where
                     , Int -> SDoc -> SDoc
nest Int
2 (forall doc. IsDoc doc => [doc] -> doc
vcat [SDoc]
pp_cons)
                     , Int -> SDoc -> SDoc
nest Int
2 forall a b. (a -> b) -> a -> b
$ ShowSub -> SDoc -> SDoc
ppShowIface ShowSub
ss SDoc
pp_extra ]
  | Bool
otherwise = forall doc. IsDoc doc => [doc] -> doc
vcat [ SDoc
pp_roles
                     , SDoc
pp_ki_sig
                     , SDoc -> Int -> SDoc -> SDoc
hang (SDoc
pp_nd forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_lhs) Int
2 (forall doc. IsLine doc => [doc] -> doc
add_bars [SDoc]
pp_cons)
                     , Int -> SDoc -> SDoc
nest Int
2 forall a b. (a -> b) -> a -> b
$ ShowSub -> SDoc -> SDoc
ppShowIface ShowSub
ss SDoc
pp_extra ]
  where
    is_data_instance :: Bool
is_data_instance = IfaceTyConParent -> Bool
isIfaceDataInstance IfaceTyConParent
parent
    -- See Note [Printing foralls in type family instances] in GHC.Iface.Type
    pp_data_inst_forall :: SDoc
    pp_data_inst_forall :: SDoc
pp_data_inst_forall = [IfaceForAllBndr] -> SDoc
pprUserIfaceForAll [IfaceForAllBndr]
forall_bndrs

    forall_bndrs :: [IfaceForAllBndr]
    forall_bndrs :: [IfaceForAllBndr]
forall_bndrs = [forall var argf. var -> argf -> VarBndr var argf
Bndr (forall tv argf. VarBndr tv argf -> tv
binderVar IfaceTyConBinder
tc_bndr) ForAllTyFlag
Specified | IfaceTyConBinder
tc_bndr <- [IfaceTyConBinder]
binders]

    cons :: [IfaceConDecl]
cons       = IfaceConDecls -> [IfaceConDecl]
visibleIfConDecls IfaceConDecls
condecls
    pp_where :: SDoc
pp_where   = forall doc. IsOutput doc => Bool -> doc -> doc
ppWhen (Bool
gadt Bool -> Bool -> Bool
&& Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [IfaceConDecl]
cons)) forall a b. (a -> b) -> a -> b
$ forall doc. IsLine doc => String -> doc
text String
"where"
    pp_cons :: [SDoc]
pp_cons    = [Maybe SDoc] -> [SDoc]
ppr_trim (forall a b. (a -> b) -> [a] -> [b]
map IfaceConDecl -> Maybe SDoc
show_con [IfaceConDecl]
cons) :: [SDoc]
    pp_kind :: SDoc
pp_kind    = forall doc. IsOutput doc => Bool -> doc -> doc
ppUnless (if Bool
ki_sig_printable
                              then IfaceType -> Bool
isIfaceRhoType IfaceType
kind
                                      -- Even in the presence of a standalone kind signature, a non-tau
                                      -- result kind annotation cannot be discarded as it determines the arity.
                                      -- See Note [Arity inference in kcCheckDeclHeader_sig] in GHC.Tc.Gen.HsType
                              else IfaceType -> Bool
isIfaceLiftedTypeKind IfaceType
kind)
                          (SDoc
dcolon forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceType
kind)

    pp_lhs :: SDoc
pp_lhs = case IfaceTyConParent
parent of
               IfaceTyConParent
IfNoParent -> SuppressBndrSig
-> IfaceContext
-> ShowSub
-> IfExtName
-> [IfaceTyConBinder]
-> SDoc
pprIfaceDeclHead SuppressBndrSig
suppress_bndr_sig IfaceContext
context ShowSub
ss IfExtName
tycon [IfaceTyConBinder]
binders
               IfDataInstance{}
                          -> forall doc. IsLine doc => String -> doc
text String
"instance" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_data_inst_forall
                                             forall doc. IsLine doc => doc -> doc -> doc
<+> IfaceTyConParent -> SDoc
pprIfaceTyConParent IfaceTyConParent
parent

    pp_roles :: SDoc
pp_roles
      | Bool
is_data_instance = forall doc. IsOutput doc => doc
empty
      | Bool
otherwise        = (Role -> Bool) -> SDoc -> [IfaceTyConBinder] -> [Role] -> SDoc
pprRoles (forall a. Eq a => a -> a -> Bool
== Role
Representational) SDoc
name_doc [IfaceTyConBinder]
binders [Role]
roles
            -- Don't display roles for data family instances (yet)
            -- See discussion on #8672.

    ki_sig_printable :: Bool
ki_sig_printable =
      -- If we print a standalone kind signature for a data instance, we leak
      -- the internal constructor name:
      --
      --    type T15827.R:Dka :: forall k. k -> *
      --    data instance forall k (a :: k). D a = MkD (Proxy a)
      --
      -- This T15827.R:Dka is a compiler-generated type constructor for the
      -- data instance.
      Bool -> Bool
not Bool
is_data_instance

    pp_ki_sig :: SDoc
pp_ki_sig = forall doc. IsOutput doc => Bool -> doc -> doc
ppWhen Bool
ki_sig_printable forall a b. (a -> b) -> a -> b
$
                SDoc -> IfaceType -> SDoc
pprStandaloneKindSig SDoc
name_doc ([IfaceTyConBinder] -> IfaceType -> IfaceType
mkIfaceTyConKind [IfaceTyConBinder]
binders IfaceType
kind)

    -- See Note [Suppressing binder signatures] in GHC.Iface.Type
    suppress_bndr_sig :: SuppressBndrSig
suppress_bndr_sig = Bool -> SuppressBndrSig
SuppressBndrSig Bool
ki_sig_printable

    name_doc :: SDoc
name_doc = ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr (ShowSub -> ShowHowMuch
ss_how_much ShowSub
ss) (forall name. HasOccName name => name -> OccName
occName IfExtName
tycon)

    add_bars :: [doc] -> doc
add_bars []     = forall doc. IsOutput doc => doc
Outputable.empty
    add_bars (doc
c:[doc]
cs) = forall doc. IsLine doc => [doc] -> doc
sep ((forall doc. IsLine doc => doc
equals forall doc. IsLine doc => doc -> doc -> doc
<+> doc
c) forall a. a -> [a] -> [a]
: forall a b. (a -> b) -> [a] -> [b]
map (forall doc. IsLine doc => doc
vbar forall doc. IsLine doc => doc -> doc -> doc
<+>) [doc]
cs)

    ok_con :: IfaceConDecl -> Bool
ok_con IfaceConDecl
dc = forall n. HasOccName n => ShowSub -> n -> Bool
showSub ShowSub
ss IfaceConDecl
dc Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any (forall n. HasOccName n => ShowSub -> n -> Bool
showSub ShowSub
ss forall b c a. (b -> c) -> (a -> b) -> a -> c
. FieldLabel -> IfExtName
flSelector) (IfaceConDecl -> [FieldLabel]
ifConFields IfaceConDecl
dc)

    show_con :: IfaceConDecl -> Maybe SDoc
show_con IfaceConDecl
dc
      | IfaceConDecl -> Bool
ok_con IfaceConDecl
dc = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ShowSub
-> Bool
-> IfExtName
-> [IfaceTyConBinder]
-> IfaceTyConParent
-> IfaceConDecl
-> SDoc
pprIfaceConDecl ShowSub
ss Bool
gadt IfExtName
tycon [IfaceTyConBinder]
binders IfaceTyConParent
parent IfaceConDecl
dc
      | Bool
otherwise = forall a. Maybe a
Nothing

    pp_nd :: SDoc
pp_nd = case IfaceConDecls
condecls of
              IfAbstractTyCon{} -> forall doc. IsLine doc => String -> doc
text String
"data"
              IfDataTyCon Bool
True [IfaceConDecl]
_ -> forall doc. IsLine doc => String -> doc
text String
"type data"
              IfDataTyCon{}     -> forall doc. IsLine doc => String -> doc
text String
"data"
              IfNewTyCon{}      -> forall doc. IsLine doc => String -> doc
text String
"newtype"

    pp_extra :: SDoc
pp_extra = forall doc. IsDoc doc => [doc] -> doc
vcat [Maybe CType -> SDoc
pprCType Maybe CType
ctype]

pprIfaceDecl ShowSub
ss (IfaceClass { ifName :: IfaceDecl -> IfExtName
ifName  = IfExtName
clas
                            , ifRoles :: IfaceDecl -> [Role]
ifRoles = [Role]
roles
                            , ifFDs :: IfaceDecl -> [FunDep IfLclName]
ifFDs    = [FunDep IfLclName]
fds
                            , ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
binders
                            , ifBody :: IfaceDecl -> IfaceClassBody
ifBody = IfaceClassBody
IfAbstractClass })
  = forall doc. IsDoc doc => [doc] -> doc
vcat [ ShowSub -> IfExtName -> [IfaceTyConBinder] -> [Role] -> SDoc
pprClassRoles ShowSub
ss IfExtName
clas [IfaceTyConBinder]
binders [Role]
roles
         , ShowSub -> IfExtName -> IfaceType -> SDoc
pprClassStandaloneKindSig ShowSub
ss IfExtName
clas ([IfaceTyConBinder] -> IfaceType -> IfaceType
mkIfaceTyConKind [IfaceTyConBinder]
binders IfaceType
constraintIfaceKind)
         , forall doc. IsLine doc => String -> doc
text String
"class" forall doc. IsLine doc => doc -> doc -> doc
<+> SuppressBndrSig
-> IfaceContext
-> ShowSub
-> IfExtName
-> [IfaceTyConBinder]
-> SDoc
pprIfaceDeclHead SuppressBndrSig
suppress_bndr_sig [] ShowSub
ss IfExtName
clas [IfaceTyConBinder]
binders forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => [FunDep a] -> SDoc
pprFundeps [FunDep IfLclName]
fds ]
  where
    -- See Note [Suppressing binder signatures] in GHC.Iface.Type
    suppress_bndr_sig :: SuppressBndrSig
suppress_bndr_sig = Bool -> SuppressBndrSig
SuppressBndrSig Bool
True

pprIfaceDecl ShowSub
ss (IfaceClass { ifName :: IfaceDecl -> IfExtName
ifName  = IfExtName
clas
                            , ifRoles :: IfaceDecl -> [Role]
ifRoles = [Role]
roles
                            , ifFDs :: IfaceDecl -> [FunDep IfLclName]
ifFDs    = [FunDep IfLclName]
fds
                            , ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
binders
                            , ifBody :: IfaceDecl -> IfaceClassBody
ifBody = IfConcreteClass {
                                ifATs :: IfaceClassBody -> [IfaceAT]
ifATs = [IfaceAT]
ats,
                                ifSigs :: IfaceClassBody -> [IfaceClassOp]
ifSigs = [IfaceClassOp]
sigs,
                                ifClassCtxt :: IfaceClassBody -> IfaceContext
ifClassCtxt = IfaceContext
context,
                                ifMinDef :: IfaceClassBody -> BooleanFormula IfLclName
ifMinDef = BooleanFormula IfLclName
minDef
                              }})
  = forall doc. IsDoc doc => [doc] -> doc
vcat [ ShowSub -> IfExtName -> [IfaceTyConBinder] -> [Role] -> SDoc
pprClassRoles ShowSub
ss IfExtName
clas [IfaceTyConBinder]
binders [Role]
roles
         , ShowSub -> IfExtName -> IfaceType -> SDoc
pprClassStandaloneKindSig ShowSub
ss IfExtName
clas ([IfaceTyConBinder] -> IfaceType -> IfaceType
mkIfaceTyConKind [IfaceTyConBinder]
binders IfaceType
constraintIfaceKind)
         , forall doc. IsLine doc => String -> doc
text String
"class" forall doc. IsLine doc => doc -> doc -> doc
<+> SuppressBndrSig
-> IfaceContext
-> ShowSub
-> IfExtName
-> [IfaceTyConBinder]
-> SDoc
pprIfaceDeclHead SuppressBndrSig
suppress_bndr_sig IfaceContext
context ShowSub
ss IfExtName
clas [IfaceTyConBinder]
binders forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => [FunDep a] -> SDoc
pprFundeps [FunDep IfLclName]
fds forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_where
         , Int -> SDoc -> SDoc
nest Int
2 (forall doc. IsDoc doc => [doc] -> doc
vcat [ forall doc. IsDoc doc => [doc] -> doc
vcat [SDoc]
asocs, forall doc. IsDoc doc => [doc] -> doc
vcat [SDoc]
dsigs
                        , ShowSub -> SDoc -> SDoc
ppShowAllSubs ShowSub
ss (BooleanFormula IfLclName -> SDoc
pprMinDef BooleanFormula IfLclName
minDef)])]
    where
      pp_where :: SDoc
pp_where = ShowSub -> SDoc -> SDoc
ppShowRhs ShowSub
ss forall a b. (a -> b) -> a -> b
$ forall doc. IsOutput doc => Bool -> doc -> doc
ppUnless (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [IfaceClassOp]
sigs Bool -> Bool -> Bool
&& forall (t :: * -> *) a. Foldable t => t a -> Bool
null [IfaceAT]
ats) (forall doc. IsLine doc => String -> doc
text String
"where")

      asocs :: [SDoc]
asocs = [Maybe SDoc] -> [SDoc]
ppr_trim forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map IfaceAT -> Maybe SDoc
maybeShowAssoc [IfaceAT]
ats
      dsigs :: [SDoc]
dsigs = [Maybe SDoc] -> [SDoc]
ppr_trim forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map IfaceClassOp -> Maybe SDoc
maybeShowSig [IfaceClassOp]
sigs

      maybeShowAssoc :: IfaceAT -> Maybe SDoc
      maybeShowAssoc :: IfaceAT -> Maybe SDoc
maybeShowAssoc asc :: IfaceAT
asc@(IfaceAT IfaceDecl
d Maybe IfaceType
_)
        | forall n. HasOccName n => ShowSub -> n -> Bool
showSub ShowSub
ss IfaceDecl
d = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ ShowSub -> IfaceAT -> SDoc
pprIfaceAT ShowSub
ss IfaceAT
asc
        | Bool
otherwise    = forall a. Maybe a
Nothing

      maybeShowSig :: IfaceClassOp -> Maybe SDoc
      maybeShowSig :: IfaceClassOp -> Maybe SDoc
maybeShowSig IfaceClassOp
sg
        | forall n. HasOccName n => ShowSub -> n -> Bool
showSub ShowSub
ss IfaceClassOp
sg = forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$  ShowSub -> IfaceClassOp -> SDoc
pprIfaceClassOp ShowSub
ss IfaceClassOp
sg
        | Bool
otherwise     = forall a. Maybe a
Nothing

      pprMinDef :: BooleanFormula IfLclName -> SDoc
      pprMinDef :: BooleanFormula IfLclName -> SDoc
pprMinDef BooleanFormula IfLclName
minDef = forall doc. IsOutput doc => Bool -> doc -> doc
ppUnless (forall a. BooleanFormula a -> Bool
isTrue BooleanFormula IfLclName
minDef) forall a b. (a -> b) -> a -> b
$ -- hide empty definitions
        forall doc. IsLine doc => String -> doc
text String
"{-# MINIMAL" forall doc. IsLine doc => doc -> doc -> doc
<+>
        forall a.
(Rational -> a -> SDoc) -> Rational -> BooleanFormula a -> SDoc
pprBooleanFormula
          (\Rational
_ IfLclName
def -> Bool -> SDoc -> SDoc
cparen (IfLclName -> Bool
isLexSym IfLclName
def) (forall a. Outputable a => a -> SDoc
ppr IfLclName
def)) Rational
0 BooleanFormula IfLclName
minDef forall doc. IsLine doc => doc -> doc -> doc
<+>
        forall doc. IsLine doc => String -> doc
text String
"#-}"

      -- See Note [Suppressing binder signatures] in GHC.Iface.Type
      suppress_bndr_sig :: SuppressBndrSig
suppress_bndr_sig = Bool -> SuppressBndrSig
SuppressBndrSig Bool
True

pprIfaceDecl ShowSub
ss (IfaceSynonym { ifName :: IfaceDecl -> IfExtName
ifName    = IfExtName
tc
                              , ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
binders
                              , ifSynRhs :: IfaceDecl -> IfaceType
ifSynRhs  = IfaceType
mono_ty
                              , ifResKind :: IfaceDecl -> IfaceType
ifResKind = IfaceType
res_kind})
  = forall doc. IsDoc doc => [doc] -> doc
vcat [ SDoc -> IfaceType -> SDoc
pprStandaloneKindSig SDoc
name_doc ([IfaceTyConBinder] -> IfaceType -> IfaceType
mkIfaceTyConKind [IfaceTyConBinder]
binders IfaceType
res_kind)
         , SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"type" forall doc. IsLine doc => doc -> doc -> doc
<+> SuppressBndrSig
-> IfaceContext
-> ShowSub
-> IfExtName
-> [IfaceTyConBinder]
-> SDoc
pprIfaceDeclHead SuppressBndrSig
suppress_bndr_sig [] ShowSub
ss IfExtName
tc [IfaceTyConBinder]
binders forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => doc
equals)
           Int
2 (forall doc. IsLine doc => [doc] -> doc
sep [ [IfaceForAllBndr] -> SDoc
pprIfaceForAll [IfaceForAllBndr]
tvs, IfaceContext -> SDoc
pprIfaceContextArr IfaceContext
theta, SDoc
ppr_tau
                  , forall doc. IsOutput doc => Bool -> doc -> doc
ppUnless (IfaceType -> Bool
isIfaceLiftedTypeKind IfaceType
res_kind) (SDoc
dcolon forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceType
res_kind) ])
         ]
  where
    ([IfaceForAllBndr]
tvs, IfaceContext
theta, IfaceType
tau) = IfaceType -> ([IfaceForAllBndr], IfaceContext, IfaceType)
splitIfaceSigmaTy IfaceType
mono_ty
    name_doc :: SDoc
name_doc = ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr (ShowSub -> ShowHowMuch
ss_how_much ShowSub
ss) (forall name. HasOccName name => name -> OccName
occName IfExtName
tc)

    -- See Note [Printing type abbreviations] in GHC.Iface.Type
    ppr_tau :: SDoc
ppr_tau | IfExtName
tc forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
liftedTypeKindTyConKey Bool -> Bool -> Bool
||
              IfExtName
tc forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
unrestrictedFunTyConKey Bool -> Bool -> Bool
||
              IfExtName
tc forall a. Uniquable a => a -> Unique -> Bool
`hasKey` Unique
constraintKindTyConKey
            = (SDocContext -> SDocContext) -> SDoc -> SDoc
updSDocContext (\SDocContext
ctx -> SDocContext
ctx { sdocPrintTypeAbbreviations :: Bool
sdocPrintTypeAbbreviations = Bool
False }) forall a b. (a -> b) -> a -> b
$ forall a. Outputable a => a -> SDoc
ppr IfaceType
tau
            | Bool
otherwise = forall a. Outputable a => a -> SDoc
ppr IfaceType
tau

    -- See Note [Suppressing binder signatures] in GHC.Iface.Type
    suppress_bndr_sig :: SuppressBndrSig
suppress_bndr_sig = Bool -> SuppressBndrSig
SuppressBndrSig Bool
True

pprIfaceDecl ShowSub
ss (IfaceFamily { ifName :: IfaceDecl -> IfExtName
ifName = IfExtName
tycon
                             , ifFamFlav :: IfaceDecl -> IfaceFamTyConFlav
ifFamFlav = IfaceFamTyConFlav
rhs, ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
binders
                             , ifResKind :: IfaceDecl -> IfaceType
ifResKind = IfaceType
res_kind
                             , ifResVar :: IfaceDecl -> Maybe IfLclName
ifResVar = Maybe IfLclName
res_var, ifFamInj :: IfaceDecl -> Injectivity
ifFamInj = Injectivity
inj })
  | IfaceFamTyConFlav
IfaceDataFamilyTyCon <- IfaceFamTyConFlav
rhs
  = forall doc. IsDoc doc => [doc] -> doc
vcat [ SDoc -> IfaceType -> SDoc
pprStandaloneKindSig SDoc
name_doc ([IfaceTyConBinder] -> IfaceType -> IfaceType
mkIfaceTyConKind [IfaceTyConBinder]
binders IfaceType
res_kind)
         , forall doc. IsLine doc => String -> doc
text String
"data family" forall doc. IsLine doc => doc -> doc -> doc
<+> SuppressBndrSig
-> IfaceContext
-> ShowSub
-> IfExtName
-> [IfaceTyConBinder]
-> SDoc
pprIfaceDeclHead SuppressBndrSig
suppress_bndr_sig [] ShowSub
ss IfExtName
tycon [IfaceTyConBinder]
binders
         ]

  | Bool
otherwise
  = forall doc. IsDoc doc => [doc] -> doc
vcat [ SDoc -> IfaceType -> SDoc
pprStandaloneKindSig SDoc
name_doc ([IfaceTyConBinder] -> IfaceType -> IfaceType
mkIfaceTyConKind [IfaceTyConBinder]
binders IfaceType
res_kind)
         , SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"type family"
                   forall doc. IsLine doc => doc -> doc -> doc
<+> SuppressBndrSig
-> IfaceContext
-> ShowSub
-> IfExtName
-> [IfaceTyConBinder]
-> SDoc
pprIfaceDeclHead SuppressBndrSig
suppress_bndr_sig [] ShowSub
ss IfExtName
tycon [IfaceTyConBinder]
binders
                   forall doc. IsLine doc => doc -> doc -> doc
<+> ShowSub -> SDoc -> SDoc
ppShowRhs ShowSub
ss (forall {doc}. IsLine doc => IfaceFamTyConFlav -> doc
pp_where IfaceFamTyConFlav
rhs))
              Int
2 (Maybe IfLclName -> Injectivity -> SDoc
pp_inj Maybe IfLclName
res_var Injectivity
inj forall doc. IsLine doc => doc -> doc -> doc
<+> ShowSub -> SDoc -> SDoc
ppShowRhs ShowSub
ss (IfaceFamTyConFlav -> SDoc
pp_rhs IfaceFamTyConFlav
rhs))
           forall doc. IsDoc doc => doc -> doc -> doc
$$
           Int -> SDoc -> SDoc
nest Int
2 (ShowSub -> SDoc -> SDoc
ppShowRhs ShowSub
ss (IfaceFamTyConFlav -> SDoc
pp_branches IfaceFamTyConFlav
rhs))
         ]
  where
    name_doc :: SDoc
name_doc = ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr (ShowSub -> ShowHowMuch
ss_how_much ShowSub
ss) (forall name. HasOccName name => name -> OccName
occName IfExtName
tycon)

    pp_where :: IfaceFamTyConFlav -> doc
pp_where (IfaceClosedSynFamilyTyCon {}) = forall doc. IsLine doc => String -> doc
text String
"where"
    pp_where IfaceFamTyConFlav
_                              = forall doc. IsOutput doc => doc
empty

    pp_inj :: Maybe IfLclName -> Injectivity -> SDoc
pp_inj Maybe IfLclName
Nothing    Injectivity
_   = forall doc. IsOutput doc => doc
empty
    pp_inj (Just IfLclName
res) Injectivity
inj
       | Injective [Bool]
injectivity <- Injectivity
inj = forall doc. IsLine doc => [doc] -> doc
hsep [ forall doc. IsLine doc => doc
equals, forall a. Outputable a => a -> SDoc
ppr IfLclName
res
                                             , IfLclName -> [Bool] -> SDoc
pp_inj_cond IfLclName
res [Bool]
injectivity]
       | Bool
otherwise = forall doc. IsLine doc => [doc] -> doc
hsep [ forall doc. IsLine doc => doc
equals, forall a. Outputable a => a -> SDoc
ppr IfLclName
res ]

    pp_inj_cond :: IfLclName -> [Bool] -> SDoc
pp_inj_cond IfLclName
res [Bool]
inj = case forall a. [Bool] -> [a] -> [a]
filterByList [Bool]
inj [IfaceTyConBinder]
binders of
       []  -> forall doc. IsOutput doc => doc
empty
       [IfaceTyConBinder]
tvs -> forall doc. IsLine doc => [doc] -> doc
hsep [forall doc. IsLine doc => doc
vbar, forall a. Outputable a => a -> SDoc
ppr IfLclName
res, forall doc. IsLine doc => String -> doc
text String
"->", forall a. Outputable a => [a] -> SDoc
interppSP (forall a b. (a -> b) -> [a] -> [b]
map IfaceTyConBinder -> IfLclName
ifTyConBinderName [IfaceTyConBinder]
tvs)]

    pp_rhs :: IfaceFamTyConFlav -> SDoc
pp_rhs IfaceFamTyConFlav
IfaceDataFamilyTyCon
      = ShowSub -> SDoc -> SDoc
ppShowIface ShowSub
ss (forall doc. IsLine doc => String -> doc
text String
"data")
    pp_rhs IfaceFamTyConFlav
IfaceOpenSynFamilyTyCon
      = ShowSub -> SDoc -> SDoc
ppShowIface ShowSub
ss (forall doc. IsLine doc => String -> doc
text String
"open")
    pp_rhs IfaceFamTyConFlav
IfaceAbstractClosedSynFamilyTyCon
      = ShowSub -> SDoc -> SDoc
ppShowIface ShowSub
ss (forall doc. IsLine doc => String -> doc
text String
"closed, abstract")
    pp_rhs (IfaceClosedSynFamilyTyCon {})
      = forall doc. IsOutput doc => doc
empty  -- see pp_branches
    pp_rhs IfaceFamTyConFlav
IfaceBuiltInSynFamTyCon
      = ShowSub -> SDoc -> SDoc
ppShowIface ShowSub
ss (forall doc. IsLine doc => String -> doc
text String
"built-in")

    pp_branches :: IfaceFamTyConFlav -> SDoc
pp_branches (IfaceClosedSynFamilyTyCon (Just (IfExtName
ax, [IfaceAxBranch]
brs)))
      = forall doc. IsDoc doc => [doc] -> doc
vcat (forall a b c. (a -> b -> c) -> [(a, b)] -> [c]
unzipWith (SDoc -> Int -> IfaceAxBranch -> SDoc
pprAxBranch
                     (ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr
                       (ShowSub -> ShowHowMuch
ss_how_much ShowSub
ss)
                       (forall name. HasOccName name => name -> OccName
occName IfExtName
tycon))
                  ) forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..] [IfaceAxBranch]
brs)
        forall doc. IsDoc doc => doc -> doc -> doc
$$ ShowSub -> SDoc -> SDoc
ppShowIface ShowSub
ss (forall doc. IsLine doc => String -> doc
text String
"axiom" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfExtName
ax)
    pp_branches IfaceFamTyConFlav
_ = forall doc. IsOutput doc => doc
Outputable.empty

    -- See Note [Suppressing binder signatures] in GHC.Iface.Type
    suppress_bndr_sig :: SuppressBndrSig
suppress_bndr_sig = Bool -> SuppressBndrSig
SuppressBndrSig Bool
True

pprIfaceDecl ShowSub
_ (IfacePatSyn { ifName :: IfaceDecl -> IfExtName
ifName = IfExtName
name,
                              ifPatUnivBndrs :: IfaceDecl -> [IfaceForAllSpecBndr]
ifPatUnivBndrs = [IfaceForAllSpecBndr]
univ_bndrs, ifPatExBndrs :: IfaceDecl -> [IfaceForAllSpecBndr]
ifPatExBndrs = [IfaceForAllSpecBndr]
ex_bndrs,
                              ifPatProvCtxt :: IfaceDecl -> IfaceContext
ifPatProvCtxt = IfaceContext
prov_ctxt, ifPatReqCtxt :: IfaceDecl -> IfaceContext
ifPatReqCtxt = IfaceContext
req_ctxt,
                              ifPatArgs :: IfaceDecl -> IfaceContext
ifPatArgs = IfaceContext
arg_tys, ifFieldLabels :: IfaceDecl -> [FieldLabel]
ifFieldLabels = [FieldLabel]
pat_fldlbls,
                              ifPatTy :: IfaceDecl -> IfaceType
ifPatTy = IfaceType
pat_ty} )
  = (SDocContext -> SDoc) -> SDoc
sdocWithContext SDocContext -> SDoc
mk_msg
  where
    pat_keywrd :: SDoc
pat_keywrd = forall doc. IsLine doc => String -> doc
text String
"pattern"
    mk_msg :: SDocContext -> SDoc
mk_msg SDocContext
sdocCtx
      = forall doc. IsDoc doc => [doc] -> doc
vcat [ SDoc
ppr_pat_ty
             -- only print this for record pattern synonyms
             , if forall (t :: * -> *) a. Foldable t => t a -> Bool
null [FieldLabel]
pat_fldlbls then forall doc. IsOutput doc => doc
Outputable.empty
               else SDoc
pat_keywrd forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc IfExtName
name forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pat_body]
      where
        ppr_pat_ty :: SDoc
ppr_pat_ty =
          SDoc -> Int -> SDoc -> SDoc
hang (SDoc
pat_keywrd forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. OutputableBndr a => a -> SDoc
pprPrefixOcc IfExtName
name)
            Int
2 (SDoc
dcolon forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => [doc] -> doc
sep [SDoc
univ_msg
                              , IfaceContext -> SDoc
pprIfaceContextArr IfaceContext
req_ctxt
                              , forall doc. IsOutput doc => Bool -> doc -> doc
ppWhen Bool
insert_empty_ctxt forall a b. (a -> b) -> a -> b
$ forall doc. IsLine doc => doc -> doc
parens forall doc. IsOutput doc => doc
empty forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
darrow
                              , SDoc
ex_msg
                              , IfaceContext -> SDoc
pprIfaceContextArr IfaceContext
prov_ctxt
                              , IfaceType -> SDoc
pprIfaceType forall a b. (a -> b) -> a -> b
$ forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr (FunTyFlag -> IfaceType -> IfaceType -> IfaceType -> IfaceType
IfaceFunTy FunTyFlag
visArgTypeLike IfaceType
many_ty)
                                                     IfaceType
pat_ty IfaceContext
arg_tys ])
        pat_body :: SDoc
pat_body = forall doc. IsLine doc => doc -> doc
braces forall a b. (a -> b) -> a -> b
$ forall doc. IsLine doc => [doc] -> doc
sep forall a b. (a -> b) -> a -> b
$ forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate forall doc. IsLine doc => doc
comma forall a b. (a -> b) -> a -> b
$ forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [FieldLabel]
pat_fldlbls
        univ_msg :: SDoc
univ_msg = [IfaceForAllBndr] -> SDoc
pprUserIfaceForAll forall a b. (a -> b) -> a -> b
$ forall a. [VarBndr a Specificity] -> [VarBndr a ForAllTyFlag]
tyVarSpecToBinders [IfaceForAllSpecBndr]
univ_bndrs
        ex_msg :: SDoc
ex_msg   = [IfaceForAllBndr] -> SDoc
pprUserIfaceForAll forall a b. (a -> b) -> a -> b
$ forall a. [VarBndr a Specificity] -> [VarBndr a ForAllTyFlag]
tyVarSpecToBinders [IfaceForAllSpecBndr]
ex_bndrs

        insert_empty_ctxt :: Bool
insert_empty_ctxt = forall (t :: * -> *) a. Foldable t => t a -> Bool
null IfaceContext
req_ctxt
            Bool -> Bool -> Bool
&& Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null IfaceContext
prov_ctxt Bool -> Bool -> Bool
&& SDocContext -> SDoc -> Bool
isEmpty SDocContext
sdocCtx SDoc
ex_msg)

pprIfaceDecl ShowSub
ss (IfaceId { ifName :: IfaceDecl -> IfExtName
ifName = IfExtName
var, ifType :: IfaceDecl -> IfaceType
ifType = IfaceType
ty,
                              ifIdDetails :: IfaceDecl -> IfaceIdDetails
ifIdDetails = IfaceIdDetails
details, ifIdInfo :: IfaceDecl -> IfaceIdInfo
ifIdInfo = IfaceIdInfo
info })
  = forall doc. IsDoc doc => [doc] -> doc
vcat [ SDoc -> Int -> SDoc -> SDoc
hang (ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr (ShowSub -> ShowHowMuch
ss_how_much ShowSub
ss) (forall name. HasOccName name => name -> OccName
occName IfExtName
var) forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon)
              Int
2 (ShowForAllFlag -> IfaceType -> SDoc
pprIfaceSigmaType (ShowSub -> ShowForAllFlag
ss_forall ShowSub
ss) IfaceType
ty)
         , ShowSub -> SDoc -> SDoc
ppShowIface ShowSub
ss (forall a. Outputable a => a -> SDoc
ppr IfaceIdDetails
details)
         , ShowSub -> SDoc -> SDoc
ppShowIface ShowSub
ss (forall a. Outputable a => a -> SDoc
ppr IfaceIdInfo
info) ]

pprIfaceDecl ShowSub
_ (IfaceAxiom { ifName :: IfaceDecl -> IfExtName
ifName = IfExtName
name, ifTyCon :: IfaceDecl -> IfaceTyCon
ifTyCon = IfaceTyCon
tycon
                           , ifAxBranches :: IfaceDecl -> [IfaceAxBranch]
ifAxBranches = [IfaceAxBranch]
branches })
  = SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"axiom" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfExtName
name forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon)
       Int
2 (forall doc. IsDoc doc => [doc] -> doc
vcat forall a b. (a -> b) -> a -> b
$ forall a b c. (a -> b -> c) -> [(a, b)] -> [c]
unzipWith (SDoc -> Int -> IfaceAxBranch -> SDoc
pprAxBranch (forall a. Outputable a => a -> SDoc
ppr IfaceTyCon
tycon)) forall a b. (a -> b) -> a -> b
$ forall a b. [a] -> [b] -> [(a, b)]
zip [Int
0..] [IfaceAxBranch]
branches)

pprCType :: Maybe CType -> SDoc
pprCType :: Maybe CType -> SDoc
pprCType Maybe CType
Nothing      = forall doc. IsOutput doc => doc
Outputable.empty
pprCType (Just CType
cType) = forall doc. IsLine doc => String -> doc
text String
"C type:" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr CType
cType

-- if, for each role, suppress_if role is True, then suppress the role
-- output
pprRoles :: (Role -> Bool) -> SDoc -> [IfaceTyConBinder]
         -> [Role] -> SDoc
pprRoles :: (Role -> Bool) -> SDoc -> [IfaceTyConBinder] -> [Role] -> SDoc
pprRoles Role -> Bool
suppress_if SDoc
tyCon [IfaceTyConBinder]
bndrs [Role]
roles
  = forall a. (SDocContext -> a) -> (a -> SDoc) -> SDoc
sdocOption SDocContext -> Bool
sdocPrintExplicitKinds forall a b. (a -> b) -> a -> b
$ \Bool
print_kinds ->
      let froles :: [Role]
froles = forall a. PrintExplicitKinds -> [IfaceTyConBinder] -> [a] -> [a]
suppressIfaceInvisibles (Bool -> PrintExplicitKinds
PrintExplicitKinds Bool
print_kinds) [IfaceTyConBinder]
bndrs [Role]
roles
      in forall doc. IsOutput doc => Bool -> doc -> doc
ppUnless (forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
all Role -> Bool
suppress_if [Role]
froles Bool -> Bool -> Bool
|| forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Role]
froles) forall a b. (a -> b) -> a -> b
$
         forall doc. IsLine doc => String -> doc
text String
"type role" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
tyCon forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => [doc] -> doc
hsep (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [Role]
froles)

pprStandaloneKindSig :: SDoc -> IfaceType -> SDoc
pprStandaloneKindSig :: SDoc -> IfaceType -> SDoc
pprStandaloneKindSig SDoc
tyCon IfaceType
ty = forall doc. IsLine doc => String -> doc
text String
"type" forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
tyCon forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"::" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceType
ty

pprInfixIfDeclBndr :: ShowHowMuch -> OccName -> SDoc
pprInfixIfDeclBndr :: ShowHowMuch -> OccName -> SDoc
pprInfixIfDeclBndr (ShowSome [OccName]
_ (AltPpr (Just OccName -> SDoc
ppr_bndr))) OccName
name
  = Bool -> SDoc -> SDoc
pprInfixVar (OccName -> Bool
isSymOcc OccName
name) (OccName -> SDoc
ppr_bndr OccName
name)
pprInfixIfDeclBndr ShowHowMuch
_ OccName
name
  = Bool -> SDoc -> SDoc
pprInfixVar (OccName -> Bool
isSymOcc OccName
name) (forall a. Outputable a => a -> SDoc
ppr OccName
name)

pprPrefixIfDeclBndr :: ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr :: ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr (ShowHeader (AltPpr (Just OccName -> SDoc
ppr_bndr))) OccName
name
  = OccName -> SDoc -> SDoc
parenSymOcc OccName
name (OccName -> SDoc
ppr_bndr OccName
name)
pprPrefixIfDeclBndr (ShowSome [OccName]
_ (AltPpr (Just OccName -> SDoc
ppr_bndr))) OccName
name
  = OccName -> SDoc -> SDoc
parenSymOcc OccName
name (OccName -> SDoc
ppr_bndr OccName
name)
pprPrefixIfDeclBndr ShowHowMuch
_ OccName
name
  = OccName -> SDoc -> SDoc
parenSymOcc OccName
name (forall a. Outputable a => a -> SDoc
ppr OccName
name)

instance Outputable IfaceClassOp where
   ppr :: IfaceClassOp -> SDoc
ppr = ShowSub -> IfaceClassOp -> SDoc
pprIfaceClassOp ShowSub
showToIface

pprIfaceClassOp :: ShowSub -> IfaceClassOp -> SDoc
pprIfaceClassOp :: ShowSub -> IfaceClassOp -> SDoc
pprIfaceClassOp ShowSub
ss (IfaceClassOp IfExtName
n IfaceType
ty Maybe (DefMethSpec IfaceType)
dm)
  = IfExtName -> IfaceType -> SDoc
pp_sig IfExtName
n IfaceType
ty forall doc. IsDoc doc => doc -> doc -> doc
$$ SDoc
generic_dm
  where
   generic_dm :: SDoc
generic_dm | Just (GenericDM IfaceType
dm_ty) <- Maybe (DefMethSpec IfaceType)
dm
              =  forall doc. IsLine doc => String -> doc
text String
"default" forall doc. IsLine doc => doc -> doc -> doc
<+> IfExtName -> IfaceType -> SDoc
pp_sig IfExtName
n IfaceType
dm_ty
              | Bool
otherwise
              = forall doc. IsOutput doc => doc
empty
   pp_sig :: IfExtName -> IfaceType -> SDoc
pp_sig IfExtName
n IfaceType
ty
     = ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr (ShowSub -> ShowHowMuch
ss_how_much ShowSub
ss) (forall name. HasOccName name => name -> OccName
occName IfExtName
n)
     forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon
     forall doc. IsLine doc => doc -> doc -> doc
<+> ShowForAllFlag -> IfaceType -> SDoc
pprIfaceSigmaType ShowForAllFlag
ShowForAllWhen IfaceType
ty

instance Outputable IfaceAT where
   ppr :: IfaceAT -> SDoc
ppr = ShowSub -> IfaceAT -> SDoc
pprIfaceAT ShowSub
showToIface

pprIfaceAT :: ShowSub -> IfaceAT -> SDoc
pprIfaceAT :: ShowSub -> IfaceAT -> SDoc
pprIfaceAT ShowSub
ss (IfaceAT IfaceDecl
d Maybe IfaceType
mb_def)
  = forall doc. IsDoc doc => [doc] -> doc
vcat [ ShowSub -> IfaceDecl -> SDoc
pprIfaceDecl ShowSub
ss IfaceDecl
d
         , case Maybe IfaceType
mb_def of
              Maybe IfaceType
Nothing  -> forall doc. IsOutput doc => doc
Outputable.empty
              Just IfaceType
rhs -> Int -> SDoc -> SDoc
nest Int
2 forall a b. (a -> b) -> a -> b
$
                          forall doc. IsLine doc => String -> doc
text String
"Default:" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceType
rhs ]

instance Outputable IfaceTyConParent where
  ppr :: IfaceTyConParent -> SDoc
ppr IfaceTyConParent
p = IfaceTyConParent -> SDoc
pprIfaceTyConParent IfaceTyConParent
p

pprIfaceTyConParent :: IfaceTyConParent -> SDoc
pprIfaceTyConParent :: IfaceTyConParent -> SDoc
pprIfaceTyConParent IfaceTyConParent
IfNoParent
  = forall doc. IsOutput doc => doc
Outputable.empty
pprIfaceTyConParent (IfDataInstance IfExtName
_ IfaceTyCon
tc IfaceAppArgs
tys)
  = PprPrec -> IfaceTyCon -> IfaceAppArgs -> SDoc
pprIfaceTypeApp PprPrec
topPrec IfaceTyCon
tc IfaceAppArgs
tys

pprIfaceDeclHead :: SuppressBndrSig
                 -> IfaceContext -> ShowSub -> Name
                 -> [IfaceTyConBinder]   -- of the tycon, for invisible-suppression
                 -> SDoc
pprIfaceDeclHead :: SuppressBndrSig
-> IfaceContext
-> ShowSub
-> IfExtName
-> [IfaceTyConBinder]
-> SDoc
pprIfaceDeclHead SuppressBndrSig
suppress_sig IfaceContext
context ShowSub
ss IfExtName
tc_occ [IfaceTyConBinder]
bndrs
  = forall a. (SDocContext -> a) -> (a -> SDoc) -> SDoc
sdocOption SDocContext -> Bool
sdocPrintExplicitKinds forall a b. (a -> b) -> a -> b
$ \Bool
print_kinds ->
    forall doc. IsLine doc => [doc] -> doc
sep [ IfaceContext -> SDoc
pprIfaceContextArr IfaceContext
context
        , ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr (ShowSub -> ShowHowMuch
ss_how_much ShowSub
ss) (forall name. HasOccName name => name -> OccName
occName IfExtName
tc_occ)
          forall doc. IsLine doc => doc -> doc -> doc
<+> SuppressBndrSig -> [IfaceTyConBinder] -> SDoc
pprIfaceTyConBinders SuppressBndrSig
suppress_sig
                (forall a. PrintExplicitKinds -> [IfaceTyConBinder] -> [a] -> [a]
suppressIfaceInvisibles (Bool -> PrintExplicitKinds
PrintExplicitKinds Bool
print_kinds) [IfaceTyConBinder]
bndrs [IfaceTyConBinder]
bndrs) ]

pprIfaceConDecl :: ShowSub -> Bool
                -> IfaceTopBndr
                -> [IfaceTyConBinder]
                -> IfaceTyConParent
                -> IfaceConDecl -> SDoc
pprIfaceConDecl :: ShowSub
-> Bool
-> IfExtName
-> [IfaceTyConBinder]
-> IfaceTyConParent
-> IfaceConDecl
-> SDoc
pprIfaceConDecl ShowSub
ss Bool
gadt_style IfExtName
tycon [IfaceTyConBinder]
tc_binders IfaceTyConParent
parent
        (IfCon { ifConName :: IfaceConDecl -> IfExtName
ifConName = IfExtName
name, ifConInfix :: IfaceConDecl -> Bool
ifConInfix = Bool
is_infix,
                 ifConUserTvBinders :: IfaceConDecl -> [IfaceForAllSpecBndr]
ifConUserTvBinders = [IfaceForAllSpecBndr]
user_tvbs,
                 ifConEqSpec :: IfaceConDecl -> [IfaceTvBndr]
ifConEqSpec = [IfaceTvBndr]
eq_spec, ifConCtxt :: IfaceConDecl -> IfaceContext
ifConCtxt = IfaceContext
ctxt, ifConArgTys :: IfaceConDecl -> [(IfaceType, IfaceType)]
ifConArgTys = [(IfaceType, IfaceType)]
arg_tys,
                 ifConStricts :: IfaceConDecl -> [IfaceBang]
ifConStricts = [IfaceBang]
stricts, ifConFields :: IfaceConDecl -> [FieldLabel]
ifConFields = [FieldLabel]
fields })
  | Bool
gadt_style = SDoc
pp_prefix_con forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
ppr_gadt_ty
  | Bool
otherwise  = SDoc -> SDoc
ppr_ex_quant SDoc
pp_h98_con
  where
    pp_h98_con :: SDoc
pp_h98_con
      | Bool -> Bool
not (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [FieldLabel]
fields) = SDoc
pp_prefix_con forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_field_args
      | Bool
is_infix
      , [SDoc
ty1, SDoc
ty2] <- [SDoc]
pp_args
      = forall doc. IsLine doc => [doc] -> doc
sep [ SDoc
ty1
            , ShowHowMuch -> OccName -> SDoc
pprInfixIfDeclBndr ShowHowMuch
how_much (forall name. HasOccName name => name -> OccName
occName IfExtName
name)
            , SDoc
ty2]
      | Bool
otherwise = SDoc
pp_prefix_con forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => [doc] -> doc
sep [SDoc]
pp_args

    how_much :: ShowHowMuch
how_much = ShowSub -> ShowHowMuch
ss_how_much ShowSub
ss
    tys_w_strs :: [(IfaceBang, IfaceType)]
    tys_w_strs :: [(IfaceBang, IfaceType)]
tys_w_strs = forall a b. [a] -> [b] -> [(a, b)]
zip [IfaceBang]
stricts (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(IfaceType, IfaceType)]
arg_tys)
    pp_prefix_con :: SDoc
pp_prefix_con = ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr ShowHowMuch
how_much (forall name. HasOccName name => name -> OccName
occName IfExtName
name)

    -- If we're pretty-printing a H98-style declaration with existential
    -- quantification, then user_tvbs will always consist of the universal
    -- tyvar binders followed by the existential tyvar binders. So to recover
    -- the visibilities of the existential tyvar binders, we can simply drop
    -- the universal tyvar binders from user_tvbs.
    ex_tvbs :: [IfaceForAllSpecBndr]
ex_tvbs = forall b a. [b] -> [a] -> [a]
dropList [IfaceTyConBinder]
tc_binders [IfaceForAllSpecBndr]
user_tvbs
    ppr_ex_quant :: SDoc -> SDoc
ppr_ex_quant = [IfaceForAllBndr] -> IfaceContext -> SDoc -> SDoc
pprIfaceForAllPartMust ([IfaceForAllSpecBndr] -> [IfaceForAllBndr]
ifaceForAllSpecToBndrs [IfaceForAllSpecBndr]
ex_tvbs) IfaceContext
ctxt
    pp_gadt_res_ty :: SDoc
pp_gadt_res_ty = [IfaceTvBndr] -> SDoc
mk_user_con_res_ty [IfaceTvBndr]
eq_spec
    ppr_gadt_ty :: SDoc
ppr_gadt_ty = [IfaceForAllBndr] -> IfaceContext -> SDoc -> SDoc
pprIfaceForAllPart ([IfaceForAllSpecBndr] -> [IfaceForAllBndr]
ifaceForAllSpecToBndrs [IfaceForAllSpecBndr]
user_tvbs) IfaceContext
ctxt SDoc
pp_tau

        -- A bit gruesome this, but we can't form the full con_tau, and ppr it,
        -- because we don't have a Name for the tycon, only an OccName
    pp_tau :: SDoc
pp_tau | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [FieldLabel]
fields
           = case [SDoc]
pp_args forall a. [a] -> [a] -> [a]
++ [SDoc
pp_gadt_res_ty] of
                (SDoc
t:[SDoc]
ts) -> forall doc. IsLine doc => [doc] -> doc
fsep (SDoc
t forall a. a -> [a] -> [a]
: forall a b c.
HasDebugCallStack =>
String -> (a -> b -> c) -> [a] -> [b] -> [c]
zipWithEqual String
"pprIfaceConDecl" (\(IfaceType
w,IfaceType
_) SDoc
d -> IfaceType -> SDoc
ppr_arr IfaceType
w forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
d)
                                                 [(IfaceType, IfaceType)]
arg_tys [SDoc]
ts)
                []     -> forall a. HasCallStack => String -> a
panic String
"pp_con_taus"
           | Bool
otherwise
           = forall doc. IsLine doc => [doc] -> doc
sep [SDoc
pp_field_args, SDoc
arrow forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
pp_gadt_res_ty]

    -- Constructors are linear by default, but we don't want to show
    -- linear arrows when -XLinearTypes is disabled
    ppr_arr :: IfaceType -> SDoc
ppr_arr IfaceType
w = forall a. (SDocContext -> a) -> (a -> SDoc) -> SDoc
sdocOption SDocContext -> Bool
sdocLinearTypes forall a b. (a -> b) -> a -> b
$ \Bool
linearTypes ->
                if Bool
linearTypes
                then FunTyFlag -> IfaceType -> SDoc
pprTypeArrow FunTyFlag
visArgTypeLike IfaceType
w
                else SDoc
arrow

    ppr_bang :: IfaceBang -> SDoc
ppr_bang IfaceBang
IfNoBang = forall doc. IsOutput doc => doc -> doc
whenPprDebug forall a b. (a -> b) -> a -> b
$ forall doc. IsLine doc => Char -> doc
char Char
'_'
    ppr_bang IfaceBang
IfStrict = forall doc. IsLine doc => Char -> doc
char Char
'!'
    ppr_bang IfaceBang
IfUnpack = forall doc. IsLine doc => String -> doc
text String
"{-# UNPACK #-}"
    ppr_bang (IfUnpackCo IfaceCoercion
co) = forall doc. IsLine doc => String -> doc
text String
"! {-# UNPACK #-}" forall doc. IsLine doc => doc -> doc -> doc
<>
                               IfaceCoercion -> SDoc
pprParendIfaceCoercion IfaceCoercion
co

    pprFieldArgTy, pprArgTy :: (IfaceBang, IfaceType) -> SDoc
    -- If using record syntax, the only reason one would need to parenthesize
    -- a compound field type is if it's preceded by a bang pattern.
    pprFieldArgTy :: (IfaceBang, IfaceType) -> SDoc
pprFieldArgTy (IfaceBang
bang, IfaceType
ty) = PprPrec -> IfaceBang -> IfaceType -> SDoc
ppr_arg_ty (IfaceBang -> PprPrec
bang_prec IfaceBang
bang) IfaceBang
bang IfaceType
ty
    -- If not using record syntax, a compound field type might need to be
    -- parenthesized if one of the following holds:
    --
    -- 1. We're using Haskell98 syntax.
    -- 2. The field type is preceded with a bang pattern.
    pprArgTy :: (IfaceBang, IfaceType) -> SDoc
pprArgTy (IfaceBang
bang, IfaceType
ty) = PprPrec -> IfaceBang -> IfaceType -> SDoc
ppr_arg_ty (forall a. Ord a => a -> a -> a
max PprPrec
gadt_prec (IfaceBang -> PprPrec
bang_prec IfaceBang
bang)) IfaceBang
bang IfaceType
ty

    ppr_arg_ty :: PprPrec -> IfaceBang -> IfaceType -> SDoc
    ppr_arg_ty :: PprPrec -> IfaceBang -> IfaceType -> SDoc
ppr_arg_ty PprPrec
prec IfaceBang
bang IfaceType
ty = IfaceBang -> SDoc
ppr_bang IfaceBang
bang forall doc. IsLine doc => doc -> doc -> doc
<> PprPrec -> IfaceType -> SDoc
pprPrecIfaceType PprPrec
prec IfaceType
ty

    -- If we're displaying the fields GADT-style, e.g.,
    --
    --   data Foo a where
    --     MkFoo :: (Int -> Int) -> Maybe a -> Foo
    --
    -- Then we use `funPrec`, since that will ensure `Int -> Int` gets the
    -- parentheses that it requires, but simple compound types like `Maybe a`
    -- (which don't require parentheses in a function argument position) won't
    -- get them, assuming that there are no bang patterns (see bang_prec).
    --
    -- If we're displaying the fields Haskell98-style, e.g.,
    --
    --   data Foo a = MkFoo (Int -> Int) (Maybe a)
    --
    -- Then not only must we parenthesize `Int -> Int`, we must also
    -- parenthesize compound fields like (Maybe a). Therefore, we pick
    -- `appPrec`, which has higher precedence than `funPrec`.
    gadt_prec :: PprPrec
    gadt_prec :: PprPrec
gadt_prec
      | Bool
gadt_style = PprPrec
funPrec
      | Bool
otherwise  = PprPrec
appPrec

    -- The presence of bang patterns or UNPACK annotations requires
    -- surrounding the type with parentheses, if needed (#13699)
    bang_prec :: IfaceBang -> PprPrec
    bang_prec :: IfaceBang -> PprPrec
bang_prec IfaceBang
IfNoBang     = PprPrec
topPrec
    bang_prec IfaceBang
IfStrict     = PprPrec
appPrec
    bang_prec IfaceBang
IfUnpack     = PprPrec
appPrec
    bang_prec IfUnpackCo{} = PprPrec
appPrec

    pp_args :: [SDoc] -- No records, e.g., `  Maybe a  ->  Int -> ...` or
                      --                   `!(Maybe a) -> !Int -> ...`
    pp_args :: [SDoc]
pp_args = forall a b. (a -> b) -> [a] -> [b]
map (IfaceBang, IfaceType) -> SDoc
pprArgTy [(IfaceBang, IfaceType)]
tys_w_strs

    pp_field_args :: SDoc -- Records, e.g., { x ::   Maybe a,  y ::  Int } or
                          --                { x :: !(Maybe a), y :: !Int }
    pp_field_args :: SDoc
pp_field_args = forall doc. IsLine doc => doc -> doc
braces forall a b. (a -> b) -> a -> b
$ forall doc. IsLine doc => [doc] -> doc
sep forall a b. (a -> b) -> a -> b
$ forall doc. IsLine doc => doc -> [doc] -> [doc]
punctuate forall doc. IsLine doc => doc
comma forall a b. (a -> b) -> a -> b
$ [Maybe SDoc] -> [SDoc]
ppr_trim forall a b. (a -> b) -> a -> b
$
                    forall a b c. (a -> b -> c) -> [a] -> [b] -> [c]
zipWith FieldLabel -> (IfaceBang, IfaceType) -> Maybe SDoc
maybe_show_label [FieldLabel]
fields [(IfaceBang, IfaceType)]
tys_w_strs

    maybe_show_label :: FieldLabel -> (IfaceBang, IfaceType) -> Maybe SDoc
    maybe_show_label :: FieldLabel -> (IfaceBang, IfaceType) -> Maybe SDoc
maybe_show_label FieldLabel
lbl (IfaceBang, IfaceType)
bty
      | forall n. HasOccName n => ShowSub -> n -> Bool
showSub ShowSub
ss IfExtName
sel = forall a. a -> Maybe a
Just (ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr ShowHowMuch
how_much OccName
occ
                                forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon forall doc. IsLine doc => doc -> doc -> doc
<+> (IfaceBang, IfaceType) -> SDoc
pprFieldArgTy (IfaceBang, IfaceType)
bty)
      | Bool
otherwise      = forall a. Maybe a
Nothing
      where
        sel :: IfExtName
sel = FieldLabel -> IfExtName
flSelector FieldLabel
lbl
        occ :: OccName
occ = IfLclName -> OccName
mkVarOccFS (FieldLabelString -> IfLclName
field_label forall a b. (a -> b) -> a -> b
$ FieldLabel -> FieldLabelString
flLabel FieldLabel
lbl)

    mk_user_con_res_ty :: IfaceEqSpec -> SDoc
    -- See Note [Result type of a data family GADT]
    mk_user_con_res_ty :: [IfaceTvBndr] -> SDoc
mk_user_con_res_ty [IfaceTvBndr]
eq_spec
      | IfDataInstance IfExtName
_ IfaceTyCon
tc IfaceAppArgs
tys <- IfaceTyConParent
parent
      = IfaceType -> SDoc
pprIfaceType (IfaceTyCon -> IfaceAppArgs -> IfaceType
IfaceTyConApp IfaceTyCon
tc (IfaceTySubst -> IfaceAppArgs -> IfaceAppArgs
substIfaceAppArgs IfaceTySubst
gadt_subst IfaceAppArgs
tys))
      | Bool
otherwise
      = IfaceTySubst -> SDoc
ppr_tc_app IfaceTySubst
gadt_subst
      where
        gadt_subst :: IfaceTySubst
gadt_subst = [IfaceTvBndr] -> IfaceTySubst
mkIfaceTySubst [IfaceTvBndr]
eq_spec

    -- When pretty-printing a GADT return type, we:
    --
    -- 1. Take the data tycon binders, extract their variable names and
    --    visibilities, and construct suitable arguments from them. (This is
    --    the role of mk_tc_app_args.)
    -- 2. Apply the GADT substitution constructed from the eq_spec.
    --    (See Note [Result type of a data family GADT].)
    -- 3. Pretty-print the data type constructor applied to its arguments.
    --    This process will omit any invisible arguments, such as coercion
    --    variables, if necessary. (See Note
    --    [VarBndrs, ForAllTyBinders, TyConBinders, and visibility] in GHC.Core.TyCo.Rep.)
    ppr_tc_app :: IfaceTySubst -> SDoc
ppr_tc_app IfaceTySubst
gadt_subst =
      ShowHowMuch -> OccName -> SDoc
pprPrefixIfDeclBndr ShowHowMuch
how_much (forall name. HasOccName name => name -> OccName
occName IfExtName
tycon)
      forall doc. IsLine doc => doc -> doc -> doc
<+> IfaceAppArgs -> SDoc
pprParendIfaceAppArgs
            (IfaceTySubst -> IfaceAppArgs -> IfaceAppArgs
substIfaceAppArgs IfaceTySubst
gadt_subst ([IfaceTyConBinder] -> IfaceAppArgs
mk_tc_app_args [IfaceTyConBinder]
tc_binders))

    mk_tc_app_args :: [IfaceTyConBinder] -> IfaceAppArgs
    mk_tc_app_args :: [IfaceTyConBinder] -> IfaceAppArgs
mk_tc_app_args [] = IfaceAppArgs
IA_Nil
    mk_tc_app_args (Bndr IfaceBndr
bndr TyConBndrVis
vis:[IfaceTyConBinder]
tc_bndrs) =
      IfaceType -> ForAllTyFlag -> IfaceAppArgs -> IfaceAppArgs
IA_Arg (IfLclName -> IfaceType
IfaceTyVar (IfaceBndr -> IfLclName
ifaceBndrName IfaceBndr
bndr)) (TyConBndrVis -> ForAllTyFlag
tyConBndrVisForAllTyFlag TyConBndrVis
vis)
             ([IfaceTyConBinder] -> IfaceAppArgs
mk_tc_app_args [IfaceTyConBinder]
tc_bndrs)

instance Outputable IfaceRule where
  ppr :: IfaceRule -> SDoc
ppr (IfaceRule { ifRuleName :: IfaceRule -> IfLclName
ifRuleName = IfLclName
name, ifActivation :: IfaceRule -> Activation
ifActivation = Activation
act, ifRuleBndrs :: IfaceRule -> [IfaceBndr]
ifRuleBndrs = [IfaceBndr]
bndrs,
                   ifRuleHead :: IfaceRule -> IfExtName
ifRuleHead = IfExtName
fn, ifRuleArgs :: IfaceRule -> [IfaceExpr]
ifRuleArgs = [IfaceExpr]
args, ifRuleRhs :: IfaceRule -> IfaceExpr
ifRuleRhs = IfaceExpr
rhs,
                   ifRuleOrph :: IfaceRule -> IsOrphan
ifRuleOrph = IsOrphan
orph })
    = forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => [doc] -> doc
hsep [ IfLclName -> SDoc
pprRuleName IfLclName
name
                 , if IsOrphan -> Bool
isOrphan IsOrphan
orph then forall doc. IsLine doc => String -> doc
text String
"[orphan]" else forall doc. IsOutput doc => doc
Outputable.empty
                 , forall a. Outputable a => a -> SDoc
ppr Activation
act
                 , SDoc
pp_foralls ]
          , Int -> SDoc -> SDoc
nest Int
2 (forall doc. IsLine doc => [doc] -> doc
sep [forall a. Outputable a => a -> SDoc
ppr IfExtName
fn forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => [doc] -> doc
sep (forall a b. (a -> b) -> [a] -> [b]
map IfaceExpr -> SDoc
pprParendIfaceExpr [IfaceExpr]
args),
                        forall doc. IsLine doc => String -> doc
text String
"=" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceExpr
rhs]) ]
    where
      pp_foralls :: SDoc
pp_foralls = forall doc. IsOutput doc => Bool -> doc -> doc
ppUnless (forall (t :: * -> *) a. Foldable t => t a -> Bool
null [IfaceBndr]
bndrs) forall a b. (a -> b) -> a -> b
$ SDoc
forAllLit forall doc. IsLine doc => doc -> doc -> doc
<+> [IfaceBndr] -> SDoc
pprIfaceBndrs [IfaceBndr]
bndrs forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
dot

instance Outputable IfaceClsInst where
  ppr :: IfaceClsInst -> SDoc
ppr (IfaceClsInst { ifDFun :: IfaceClsInst -> IfExtName
ifDFun = IfExtName
dfun_id, ifOFlag :: IfaceClsInst -> OverlapFlag
ifOFlag = OverlapFlag
flag
                    , ifInstCls :: IfaceClsInst -> IfExtName
ifInstCls = IfExtName
cls, ifInstTys :: IfaceClsInst -> [Maybe IfaceTyCon]
ifInstTys = [Maybe IfaceTyCon]
mb_tcs
                    , ifInstOrph :: IfaceClsInst -> IsOrphan
ifInstOrph = IsOrphan
orph })
    = SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"instance" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr OverlapFlag
flag
              forall doc. IsLine doc => doc -> doc -> doc
<+> (if IsOrphan -> Bool
isOrphan IsOrphan
orph then forall doc. IsLine doc => String -> doc
text String
"[orphan]" else forall doc. IsOutput doc => doc
Outputable.empty)
              forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfExtName
cls forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => doc -> doc
brackets (forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas Maybe IfaceTyCon -> SDoc
ppr_rough [Maybe IfaceTyCon]
mb_tcs))
         Int
2 (forall doc. IsLine doc => doc
equals forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfExtName
dfun_id)

instance Outputable IfaceFamInst where
  ppr :: IfaceFamInst -> SDoc
ppr (IfaceFamInst { ifFamInstFam :: IfaceFamInst -> IfExtName
ifFamInstFam = IfExtName
fam, ifFamInstTys :: IfaceFamInst -> [Maybe IfaceTyCon]
ifFamInstTys = [Maybe IfaceTyCon]
mb_tcs
                    , ifFamInstAxiom :: IfaceFamInst -> IfExtName
ifFamInstAxiom = IfExtName
tycon_ax, ifFamInstOrph :: IfaceFamInst -> IsOrphan
ifFamInstOrph = IsOrphan
orph })
    = SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"family instance"
              forall doc. IsLine doc => doc -> doc -> doc
<+> (if IsOrphan -> Bool
isOrphan IsOrphan
orph then forall doc. IsLine doc => String -> doc
text String
"[orphan]" else forall doc. IsOutput doc => doc
Outputable.empty)
              forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfExtName
fam forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas (forall doc. IsLine doc => doc -> doc
brackets forall b c a. (b -> c) -> (a -> b) -> a -> c
. Maybe IfaceTyCon -> SDoc
ppr_rough) [Maybe IfaceTyCon]
mb_tcs)
         Int
2 (forall doc. IsLine doc => doc
equals forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfExtName
tycon_ax)

ppr_rough :: Maybe IfaceTyCon -> SDoc
ppr_rough :: Maybe IfaceTyCon -> SDoc
ppr_rough Maybe IfaceTyCon
Nothing   = forall doc. IsLine doc => doc
dot
ppr_rough (Just IfaceTyCon
tc) = forall a. Outputable a => a -> SDoc
ppr IfaceTyCon
tc

{-
Note [Result type of a data family GADT]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider
   data family T a
   data instance T (p,q) where
      T1 :: T (Int, Maybe c)
      T2 :: T (Bool, q)

The IfaceDecl actually looks like

   data TPr p q where
      T1 :: forall p q. forall c. (p~Int,q~Maybe c) => TPr p q
      T2 :: forall p q. (p~Bool) => TPr p q

To reconstruct the result types for T1 and T2 that we
want to pretty print, we substitute the eq-spec
[p->Int, q->Maybe c] in the arg pattern (p,q) to give
   T (Int, Maybe c)
Remember that in IfaceSyn, the TyCon and DataCon share the same
universal type variables.

----------------------------- Printing IfaceExpr ------------------------------------
-}

instance Outputable IfaceExpr where
    ppr :: IfaceExpr -> SDoc
ppr IfaceExpr
e = (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr SDoc -> SDoc
noParens IfaceExpr
e

noParens :: SDoc -> SDoc
noParens :: SDoc -> SDoc
noParens SDoc
pp = SDoc
pp

pprParendIfaceExpr :: IfaceExpr -> SDoc
pprParendIfaceExpr :: IfaceExpr -> SDoc
pprParendIfaceExpr = (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr forall doc. IsLine doc => doc -> doc
parens

-- | Pretty Print an IfaceExpr
--
-- The first argument should be a function that adds parens in context that need
-- an atomic value (e.g. function args)
pprIfaceExpr :: (SDoc -> SDoc) -> IfaceExpr -> SDoc

pprIfaceExpr :: (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr SDoc -> SDoc
_ (IfaceLcl IfLclName
v)       = forall a. Outputable a => a -> SDoc
ppr IfLclName
v
pprIfaceExpr SDoc -> SDoc
_ (IfaceExt IfExtName
v)       = forall a. Outputable a => a -> SDoc
ppr IfExtName
v
pprIfaceExpr SDoc -> SDoc
_ (IfaceLit Literal
l)       = forall a. Outputable a => a -> SDoc
ppr Literal
l
pprIfaceExpr SDoc -> SDoc
_ (IfaceFCall ForeignCall
cc IfaceType
ty) = forall doc. IsLine doc => doc -> doc
braces (forall a. Outputable a => a -> SDoc
ppr ForeignCall
cc forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceType
ty)
pprIfaceExpr SDoc -> SDoc
_ (IfaceType IfaceType
ty)     = forall doc. IsLine doc => Char -> doc
char Char
'@' forall doc. IsLine doc => doc -> doc -> doc
<> IfaceType -> SDoc
pprParendIfaceType IfaceType
ty
pprIfaceExpr SDoc -> SDoc
_ (IfaceCo IfaceCoercion
co)       = forall doc. IsLine doc => String -> doc
text String
"@~" forall doc. IsLine doc => doc -> doc -> doc
<> IfaceCoercion -> SDoc
pprParendIfaceCoercion IfaceCoercion
co
pprIfaceExpr SDoc -> SDoc
_ (IfaceTuple TupleSort
c [IfaceExpr]
as)  = TupleSort -> SDoc -> SDoc
tupleParens TupleSort
c (forall a. (a -> SDoc) -> [a] -> SDoc
pprWithCommas forall a. Outputable a => a -> SDoc
ppr [IfaceExpr]
as)

pprIfaceExpr SDoc -> SDoc
_ (IfaceLitRubbish TypeOrConstraint
tc IfaceType
r)
  = forall doc. IsLine doc => String -> doc
text String
"RUBBISH"
    forall doc. IsLine doc => doc -> doc -> doc
<> (case TypeOrConstraint
tc of { TypeOrConstraint
TypeLike -> forall doc. IsOutput doc => doc
empty; TypeOrConstraint
ConstraintLike -> forall doc. IsLine doc => String -> doc
text String
"[c]" })
    forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc -> doc
parens (forall a. Outputable a => a -> SDoc
ppr IfaceType
r)

pprIfaceExpr SDoc -> SDoc
add_par app :: IfaceExpr
app@(IfaceApp IfaceExpr
_ IfaceExpr
_) = SDoc -> SDoc
add_par (IfaceExpr -> [SDoc] -> SDoc
pprIfaceApp IfaceExpr
app [])

pprIfaceExpr SDoc -> SDoc
add_par i :: IfaceExpr
i@(IfaceLam IfaceLamBndr
_ IfaceExpr
_)
  = SDoc -> SDoc
add_par (forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => Char -> doc
char Char
'\\' forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => [doc] -> doc
sep (forall a b. (a -> b) -> [a] -> [b]
map IfaceLamBndr -> SDoc
pprIfaceLamBndr [IfaceLamBndr]
bndrs) forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
arrow,
                  (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr SDoc -> SDoc
noParens IfaceExpr
body])
  where
    ([IfaceLamBndr]
bndrs,IfaceExpr
body) = [IfaceLamBndr] -> IfaceExpr -> ([IfaceLamBndr], IfaceExpr)
collect [] IfaceExpr
i
    collect :: [IfaceLamBndr] -> IfaceExpr -> ([IfaceLamBndr], IfaceExpr)
collect [IfaceLamBndr]
bs (IfaceLam IfaceLamBndr
b IfaceExpr
e) = [IfaceLamBndr] -> IfaceExpr -> ([IfaceLamBndr], IfaceExpr)
collect (IfaceLamBndr
bforall a. a -> [a] -> [a]
:[IfaceLamBndr]
bs) IfaceExpr
e
    collect [IfaceLamBndr]
bs IfaceExpr
e              = (forall a. [a] -> [a]
reverse [IfaceLamBndr]
bs, IfaceExpr
e)

pprIfaceExpr SDoc -> SDoc
add_par (IfaceECase IfaceExpr
scrut IfaceType
ty)
  = SDoc -> SDoc
add_par (forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => String -> doc
text String
"case" forall doc. IsLine doc => doc -> doc -> doc
<+> (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr SDoc -> SDoc
noParens IfaceExpr
scrut
                 , forall doc. IsLine doc => String -> doc
text String
"ret_ty" forall doc. IsLine doc => doc -> doc -> doc
<+> IfaceType -> SDoc
pprParendIfaceType IfaceType
ty
                 , forall doc. IsLine doc => String -> doc
text String
"of {}" ])

pprIfaceExpr SDoc -> SDoc
add_par (IfaceCase IfaceExpr
scrut IfLclName
bndr [IfaceAlt IfaceConAlt
con [IfLclName]
bs IfaceExpr
rhs])
  = SDoc -> SDoc
add_par (forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => String -> doc
text String
"case"
                        forall doc. IsLine doc => doc -> doc -> doc
<+> (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr SDoc -> SDoc
noParens IfaceExpr
scrut forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"of"
                        forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfLclName
bndr forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => Char -> doc
char Char
'{' forall doc. IsLine doc => doc -> doc -> doc
<+> IfaceConAlt -> [IfLclName] -> SDoc
ppr_con_bs IfaceConAlt
con [IfLclName]
bs forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
arrow,
                  (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr SDoc -> SDoc
noParens IfaceExpr
rhs forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => Char -> doc
char Char
'}'])

pprIfaceExpr SDoc -> SDoc
add_par (IfaceCase IfaceExpr
scrut IfLclName
bndr [IfaceAlt]
alts)
  = SDoc -> SDoc
add_par (forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => String -> doc
text String
"case"
                        forall doc. IsLine doc => doc -> doc -> doc
<+> (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr SDoc -> SDoc
noParens IfaceExpr
scrut forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => String -> doc
text String
"of"
                        forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfLclName
bndr forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => Char -> doc
char Char
'{',
                  Int -> SDoc -> SDoc
nest Int
2 (forall doc. IsLine doc => [doc] -> doc
sep (forall a b. (a -> b) -> [a] -> [b]
map IfaceAlt -> SDoc
pprIfaceAlt [IfaceAlt]
alts)) forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => Char -> doc
char Char
'}'])

pprIfaceExpr SDoc -> SDoc
_       (IfaceCast IfaceExpr
expr IfaceCoercion
co)
  = forall doc. IsLine doc => [doc] -> doc
sep [IfaceExpr -> SDoc
pprParendIfaceExpr IfaceExpr
expr,
         Int -> SDoc -> SDoc
nest Int
2 (forall doc. IsLine doc => String -> doc
text String
"`cast`"),
         IfaceCoercion -> SDoc
pprParendIfaceCoercion IfaceCoercion
co]

pprIfaceExpr SDoc -> SDoc
add_par (IfaceLet (IfaceNonRec IfaceLetBndr
b IfaceExpr
rhs) IfaceExpr
body)
  = SDoc -> SDoc
add_par (forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => String -> doc
text String
"let {",
                  Int -> SDoc -> SDoc
nest Int
2 ((IfaceLetBndr, IfaceExpr) -> SDoc
ppr_bind (IfaceLetBndr
b, IfaceExpr
rhs)),
                  forall doc. IsLine doc => String -> doc
text String
"} in",
                  (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr SDoc -> SDoc
noParens IfaceExpr
body])

pprIfaceExpr SDoc -> SDoc
add_par (IfaceLet (IfaceRec [(IfaceLetBndr, IfaceExpr)]
pairs) IfaceExpr
body)
  = SDoc -> SDoc
add_par (forall doc. IsLine doc => [doc] -> doc
sep [forall doc. IsLine doc => String -> doc
text String
"letrec {",
                  Int -> SDoc -> SDoc
nest Int
2 (forall doc. IsLine doc => [doc] -> doc
sep (forall a b. (a -> b) -> [a] -> [b]
map (IfaceLetBndr, IfaceExpr) -> SDoc
ppr_bind [(IfaceLetBndr, IfaceExpr)]
pairs)),
                  forall doc. IsLine doc => String -> doc
text String
"} in",
                  (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr SDoc -> SDoc
noParens IfaceExpr
body])

pprIfaceExpr SDoc -> SDoc
add_par (IfaceTick IfaceTickish
tickish IfaceExpr
e)
  = SDoc -> SDoc
add_par (IfaceTickish -> SDoc
pprIfaceTickish IfaceTickish
tickish forall doc. IsLine doc => doc -> doc -> doc
<+> (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr SDoc -> SDoc
noParens IfaceExpr
e)

pprIfaceAlt :: IfaceAlt -> SDoc
pprIfaceAlt :: IfaceAlt -> SDoc
pprIfaceAlt (IfaceAlt IfaceConAlt
con [IfLclName]
bs IfaceExpr
rhs)
  = forall doc. IsLine doc => [doc] -> doc
sep [IfaceConAlt -> [IfLclName] -> SDoc
ppr_con_bs IfaceConAlt
con [IfLclName]
bs, SDoc
arrow forall doc. IsLine doc => doc -> doc -> doc
<+> (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr SDoc -> SDoc
noParens IfaceExpr
rhs]

ppr_con_bs :: IfaceConAlt -> [IfLclName] -> SDoc
ppr_con_bs :: IfaceConAlt -> [IfLclName] -> SDoc
ppr_con_bs IfaceConAlt
con [IfLclName]
bs = forall a. Outputable a => a -> SDoc
ppr IfaceConAlt
con forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => [doc] -> doc
hsep (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [IfLclName]
bs)

ppr_bind :: (IfaceLetBndr, IfaceExpr) -> SDoc
ppr_bind :: (IfaceLetBndr, IfaceExpr) -> SDoc
ppr_bind (IfLetBndr IfLclName
b IfaceType
ty IfaceIdInfo
info IfaceJoinInfo
ji, IfaceExpr
rhs)
  = forall doc. IsLine doc => [doc] -> doc
sep [SDoc -> Int -> SDoc -> SDoc
hang (forall a. Outputable a => a -> SDoc
ppr IfLclName
b forall doc. IsLine doc => doc -> doc -> doc
<+> SDoc
dcolon forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceType
ty) Int
2 (forall a. Outputable a => a -> SDoc
ppr IfaceJoinInfo
ji forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceIdInfo
info),
         forall doc. IsLine doc => doc
equals forall doc. IsLine doc => doc -> doc -> doc
<+> (SDoc -> SDoc) -> IfaceExpr -> SDoc
pprIfaceExpr SDoc -> SDoc
noParens IfaceExpr
rhs]

------------------
pprIfaceTickish :: IfaceTickish -> SDoc
pprIfaceTickish :: IfaceTickish -> SDoc
pprIfaceTickish (IfaceHpcTick Module
m Int
ix)
  = forall doc. IsLine doc => doc -> doc
braces (forall doc. IsLine doc => String -> doc
text String
"tick" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Module
m forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Int
ix)
pprIfaceTickish (IfaceSCC CostCentre
cc Bool
tick Bool
scope)
  = forall doc. IsLine doc => doc -> doc
braces (CostCentre -> SDoc
pprCostCentreCore CostCentre
cc forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Bool
tick forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Bool
scope)
pprIfaceTickish (IfaceSource RealSrcSpan
src String
_names)
  = forall doc. IsLine doc => doc -> doc
braces (Bool -> RealSrcSpan -> SDoc
pprUserRealSpan Bool
True RealSrcSpan
src)

------------------
pprIfaceApp :: IfaceExpr -> [SDoc] -> SDoc
pprIfaceApp :: IfaceExpr -> [SDoc] -> SDoc
pprIfaceApp (IfaceApp IfaceExpr
fun IfaceExpr
arg) [SDoc]
args = IfaceExpr -> [SDoc] -> SDoc
pprIfaceApp IfaceExpr
fun forall a b. (a -> b) -> a -> b
$
                                          Int -> SDoc -> SDoc
nest Int
2 (IfaceExpr -> SDoc
pprParendIfaceExpr IfaceExpr
arg) forall a. a -> [a] -> [a]
: [SDoc]
args
pprIfaceApp IfaceExpr
fun                [SDoc]
args = forall doc. IsLine doc => [doc] -> doc
sep (IfaceExpr -> SDoc
pprParendIfaceExpr IfaceExpr
fun forall a. a -> [a] -> [a]
: [SDoc]
args)

------------------
instance Outputable IfaceConAlt where
    ppr :: IfaceConAlt -> SDoc
ppr IfaceConAlt
IfaceDefault      = forall doc. IsLine doc => String -> doc
text String
"DEFAULT"
    ppr (IfaceLitAlt Literal
l)   = forall a. Outputable a => a -> SDoc
ppr Literal
l
    ppr (IfaceDataAlt IfExtName
d)  = forall a. Outputable a => a -> SDoc
ppr IfExtName
d

------------------
instance Outputable IfaceIdDetails where
  ppr :: IfaceIdDetails -> SDoc
ppr IfaceIdDetails
IfVanillaId       = forall doc. IsOutput doc => doc
Outputable.empty
  ppr (IfWorkerLikeId [CbvMark]
dmd) = forall doc. IsLine doc => String -> doc
text String
"StrWork" forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc -> doc
parens (forall a. Outputable a => a -> SDoc
ppr [CbvMark]
dmd)
  ppr (IfRecSelId Either IfaceTyCon IfaceDecl
tc Bool
b) = forall doc. IsLine doc => String -> doc
text String
"RecSel" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Either IfaceTyCon IfaceDecl
tc
                          forall doc. IsLine doc => doc -> doc -> doc
<+> if Bool
b
                                then forall doc. IsLine doc => String -> doc
text String
"<naughty>"
                                else forall doc. IsOutput doc => doc
Outputable.empty
  ppr IfaceIdDetails
IfDFunId          = forall doc. IsLine doc => String -> doc
text String
"DFunId"

instance Outputable IfaceInfoItem where
  ppr :: IfaceInfoItem -> SDoc
ppr (HsUnfold Bool
lb IfaceUnfolding
unf)     = forall doc. IsLine doc => String -> doc
text String
"Unfolding"
                              forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsOutput doc => Bool -> doc -> doc
ppWhen Bool
lb (forall doc. IsLine doc => String -> doc
text String
"(loop-breaker)")
                              forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
colon forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceUnfolding
unf
  ppr (HsInline InlinePragma
prag)       = forall doc. IsLine doc => String -> doc
text String
"Inline:" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr InlinePragma
prag
  ppr (HsArity Int
arity)       = forall doc. IsLine doc => String -> doc
text String
"Arity:" forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => Int -> doc
int Int
arity
  ppr (HsDmdSig DmdSig
str)        = forall doc. IsLine doc => String -> doc
text String
"Strictness:" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr DmdSig
str
  ppr (HsCprSig CprSig
cpr)        = forall doc. IsLine doc => String -> doc
text String
"CPR:" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr CprSig
cpr
  ppr IfaceInfoItem
HsNoCafRefs           = forall doc. IsLine doc => String -> doc
text String
"HasNoCafRefs"
  ppr (HsLFInfo IfaceLFInfo
lf_info)    = forall doc. IsLine doc => String -> doc
text String
"LambdaFormInfo:" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfaceLFInfo
lf_info
  ppr (HsTagSig TagSig
tag_sig)    = forall doc. IsLine doc => String -> doc
text String
"TagSig:" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr TagSig
tag_sig

instance Outputable IfaceJoinInfo where
  ppr :: IfaceJoinInfo -> SDoc
ppr IfaceJoinInfo
IfaceNotJoinPoint   = forall doc. IsOutput doc => doc
empty
  ppr (IfaceJoinPoint Int
ar) = forall doc. IsLine doc => doc -> doc
angleBrackets (forall doc. IsLine doc => String -> doc
text String
"join" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr Int
ar)

instance Outputable IfaceUnfolding where
  ppr :: IfaceUnfolding -> SDoc
ppr (IfCoreUnfold UnfoldingSource
src IfUnfoldingCache
_ IfGuidance
guide IfaceExpr
e)
    = forall doc. IsLine doc => [doc] -> doc
sep [ forall doc. IsLine doc => String -> doc
text String
"Core:" forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr UnfoldingSource
src forall doc. IsLine doc => doc -> doc -> doc
<+> forall a. Outputable a => a -> SDoc
ppr IfGuidance
guide, forall a. Outputable a => a -> SDoc
ppr IfaceExpr
e ]
  ppr (IfDFunUnfold [IfaceBndr]
bs [IfaceExpr]
es) = SDoc -> Int -> SDoc -> SDoc
hang (forall doc. IsLine doc => String -> doc
text String
"DFun:" forall doc. IsLine doc => doc -> doc -> doc
<+> forall doc. IsLine doc => [doc] -> doc
sep (forall a b. (a -> b) -> [a] -> [b]
map forall a. Outputable a => a -> SDoc
ppr [IfaceBndr]
bs) forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
dot)
                                Int
2 (forall doc. IsLine doc => [doc] -> doc
sep (forall a b. (a -> b) -> [a] -> [b]
map IfaceExpr -> SDoc
pprParendIfaceExpr [IfaceExpr]
es))

instance Outputable IfGuidance where
  ppr :: IfGuidance -> SDoc
ppr IfGuidance
IfNoGuidance   = forall doc. IsOutput doc => doc
empty
  ppr (IfWhen Int
a Bool
u Bool
b) = forall doc. IsLine doc => doc -> doc
angleBrackets (forall a. Outputable a => a -> SDoc
ppr Int
a forall doc. IsLine doc => doc -> doc -> doc
<> forall doc. IsLine doc => doc
comma forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr Bool
u forall doc. IsLine doc => doc -> doc -> doc
<> forall a. Outputable a => a -> SDoc
ppr Bool
b)

{-
************************************************************************
*                                                                      *
              Finding the Names in Iface syntax
*                                                                      *
************************************************************************

This is used for dependency analysis in GHC.Iface.Make, so that we
fingerprint a declaration before the things that depend on it.  It
is specific to interface-file fingerprinting in the sense that we
don't collect *all* Names: for example, the DFun of an instance is
recorded textually rather than by its fingerprint when
fingerprinting the instance, so DFuns are not dependencies.
-}

freeNamesIfDecl :: IfaceDecl -> NameSet
freeNamesIfDecl :: IfaceDecl -> NameSet
freeNamesIfDecl (IfaceId { ifType :: IfaceDecl -> IfaceType
ifType = IfaceType
t, ifIdDetails :: IfaceDecl -> IfaceIdDetails
ifIdDetails = IfaceIdDetails
d, ifIdInfo :: IfaceDecl -> IfaceIdInfo
ifIdInfo = IfaceIdInfo
i})
  = IfaceType -> NameSet
freeNamesIfType IfaceType
t NameSet -> NameSet -> NameSet
&&&
    IfaceIdInfo -> NameSet
freeNamesIfIdInfo IfaceIdInfo
i NameSet -> NameSet -> NameSet
&&&
    IfaceIdDetails -> NameSet
freeNamesIfIdDetails IfaceIdDetails
d

freeNamesIfDecl (IfaceData { ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
bndrs, ifResKind :: IfaceDecl -> IfaceType
ifResKind = IfaceType
res_k
                           , ifParent :: IfaceDecl -> IfaceTyConParent
ifParent = IfaceTyConParent
p, ifCtxt :: IfaceDecl -> IfaceContext
ifCtxt = IfaceContext
ctxt, ifCons :: IfaceDecl -> IfaceConDecls
ifCons = IfaceConDecls
cons })
  = forall vis. [VarBndr IfaceBndr vis] -> NameSet
freeNamesIfVarBndrs [IfaceTyConBinder]
bndrs NameSet -> NameSet -> NameSet
&&&
    IfaceType -> NameSet
freeNamesIfType IfaceType
res_k NameSet -> NameSet -> NameSet
&&&
    IfaceTyConParent -> NameSet
freeNamesIfaceTyConParent IfaceTyConParent
p NameSet -> NameSet -> NameSet
&&&
    IfaceContext -> NameSet
freeNamesIfContext IfaceContext
ctxt NameSet -> NameSet -> NameSet
&&&
    IfaceConDecls -> NameSet
freeNamesIfConDecls IfaceConDecls
cons

freeNamesIfDecl (IfaceSynonym { ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
bndrs, ifResKind :: IfaceDecl -> IfaceType
ifResKind = IfaceType
res_k
                              , ifSynRhs :: IfaceDecl -> IfaceType
ifSynRhs = IfaceType
rhs })
  = forall vis. [VarBndr IfaceBndr vis] -> NameSet
freeNamesIfVarBndrs [IfaceTyConBinder]
bndrs NameSet -> NameSet -> NameSet
&&&
    IfaceType -> NameSet
freeNamesIfKind IfaceType
res_k NameSet -> NameSet -> NameSet
&&&
    IfaceType -> NameSet
freeNamesIfType IfaceType
rhs

freeNamesIfDecl (IfaceFamily { ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
bndrs, ifResKind :: IfaceDecl -> IfaceType
ifResKind = IfaceType
res_k
                             , ifFamFlav :: IfaceDecl -> IfaceFamTyConFlav
ifFamFlav = IfaceFamTyConFlav
flav })
  = forall vis. [VarBndr IfaceBndr vis] -> NameSet
freeNamesIfVarBndrs [IfaceTyConBinder]
bndrs NameSet -> NameSet -> NameSet
&&&
    IfaceType -> NameSet
freeNamesIfKind IfaceType
res_k NameSet -> NameSet -> NameSet
&&&
    IfaceFamTyConFlav -> NameSet
freeNamesIfFamFlav IfaceFamTyConFlav
flav

freeNamesIfDecl (IfaceClass{ ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
bndrs, ifBody :: IfaceDecl -> IfaceClassBody
ifBody = IfaceClassBody
cls_body })
  = forall vis. [VarBndr IfaceBndr vis] -> NameSet
freeNamesIfVarBndrs [IfaceTyConBinder]
bndrs NameSet -> NameSet -> NameSet
&&&
    IfaceClassBody -> NameSet
freeNamesIfClassBody IfaceClassBody
cls_body

freeNamesIfDecl (IfaceAxiom { ifTyCon :: IfaceDecl -> IfaceTyCon
ifTyCon = IfaceTyCon
tc, ifAxBranches :: IfaceDecl -> [IfaceAxBranch]
ifAxBranches = [IfaceAxBranch]
branches })
  = IfaceTyCon -> NameSet
freeNamesIfTc IfaceTyCon
tc NameSet -> NameSet -> NameSet
&&&
    forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceAxBranch -> NameSet
freeNamesIfAxBranch [IfaceAxBranch]
branches

freeNamesIfDecl (IfacePatSyn { ifPatMatcher :: IfaceDecl -> (IfExtName, Bool)
ifPatMatcher = (IfExtName
matcher, Bool
_)
                             , ifPatBuilder :: IfaceDecl -> Maybe (IfExtName, Bool)
ifPatBuilder = Maybe (IfExtName, Bool)
mb_builder
                             , ifPatUnivBndrs :: IfaceDecl -> [IfaceForAllSpecBndr]
ifPatUnivBndrs = [IfaceForAllSpecBndr]
univ_bndrs
                             , ifPatExBndrs :: IfaceDecl -> [IfaceForAllSpecBndr]
ifPatExBndrs = [IfaceForAllSpecBndr]
ex_bndrs
                             , ifPatProvCtxt :: IfaceDecl -> IfaceContext
ifPatProvCtxt = IfaceContext
prov_ctxt
                             , ifPatReqCtxt :: IfaceDecl -> IfaceContext
ifPatReqCtxt = IfaceContext
req_ctxt
                             , ifPatArgs :: IfaceDecl -> IfaceContext
ifPatArgs = IfaceContext
args
                             , ifPatTy :: IfaceDecl -> IfaceType
ifPatTy = IfaceType
pat_ty
                             , ifFieldLabels :: IfaceDecl -> [FieldLabel]
ifFieldLabels = [FieldLabel]
lbls })
  = IfExtName -> NameSet
unitNameSet IfExtName
matcher NameSet -> NameSet -> NameSet
&&&
    forall b a. b -> (a -> b) -> Maybe a -> b
maybe NameSet
emptyNameSet (IfExtName -> NameSet
unitNameSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a, b) -> a
fst) Maybe (IfExtName, Bool)
mb_builder NameSet -> NameSet -> NameSet
&&&
    forall vis. [VarBndr IfaceBndr vis] -> NameSet
freeNamesIfVarBndrs [IfaceForAllSpecBndr]
univ_bndrs NameSet -> NameSet -> NameSet
&&&
    forall vis. [VarBndr IfaceBndr vis] -> NameSet
freeNamesIfVarBndrs [IfaceForAllSpecBndr]
ex_bndrs NameSet -> NameSet -> NameSet
&&&
    IfaceContext -> NameSet
freeNamesIfContext IfaceContext
prov_ctxt NameSet -> NameSet -> NameSet
&&&
    IfaceContext -> NameSet
freeNamesIfContext IfaceContext
req_ctxt NameSet -> NameSet -> NameSet
&&&
    forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceType -> NameSet
freeNamesIfType IfaceContext
args NameSet -> NameSet -> NameSet
&&&
    IfaceType -> NameSet
freeNamesIfType IfaceType
pat_ty NameSet -> NameSet -> NameSet
&&&
    [IfExtName] -> NameSet
mkNameSet (forall a b. (a -> b) -> [a] -> [b]
map FieldLabel -> IfExtName
flSelector [FieldLabel]
lbls)

freeNamesIfClassBody :: IfaceClassBody -> NameSet
freeNamesIfClassBody :: IfaceClassBody -> NameSet
freeNamesIfClassBody IfaceClassBody
IfAbstractClass
  = NameSet
emptyNameSet
freeNamesIfClassBody (IfConcreteClass{ ifClassCtxt :: IfaceClassBody -> IfaceContext
ifClassCtxt = IfaceContext
ctxt, ifATs :: IfaceClassBody -> [IfaceAT]
ifATs = [IfaceAT]
ats, ifSigs :: IfaceClassBody -> [IfaceClassOp]
ifSigs = [IfaceClassOp]
sigs })
  = IfaceContext -> NameSet
freeNamesIfContext IfaceContext
ctxt  NameSet -> NameSet -> NameSet
&&&
    forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceAT -> NameSet
freeNamesIfAT [IfaceAT]
ats NameSet -> NameSet -> NameSet
&&&
    forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceClassOp -> NameSet
freeNamesIfClsSig [IfaceClassOp]
sigs

freeNamesIfAxBranch :: IfaceAxBranch -> NameSet
freeNamesIfAxBranch :: IfaceAxBranch -> NameSet
freeNamesIfAxBranch (IfaceAxBranch { ifaxbTyVars :: IfaceAxBranch -> [IfaceTvBndr]
ifaxbTyVars   = [IfaceTvBndr]
tyvars
                                   , ifaxbCoVars :: IfaceAxBranch -> [IfaceIdBndr]
ifaxbCoVars   = [IfaceIdBndr]
covars
                                   , ifaxbLHS :: IfaceAxBranch -> IfaceAppArgs
ifaxbLHS      = IfaceAppArgs
lhs
                                   , ifaxbRHS :: IfaceAxBranch -> IfaceType
ifaxbRHS      = IfaceType
rhs })
  = forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceTvBndr -> NameSet
freeNamesIfTvBndr [IfaceTvBndr]
tyvars NameSet -> NameSet -> NameSet
&&&
    forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceIdBndr -> NameSet
freeNamesIfIdBndr [IfaceIdBndr]
covars NameSet -> NameSet -> NameSet
&&&
    IfaceAppArgs -> NameSet
freeNamesIfAppArgs IfaceAppArgs
lhs NameSet -> NameSet -> NameSet
&&&
    IfaceType -> NameSet
freeNamesIfType IfaceType
rhs

freeNamesIfIdDetails :: IfaceIdDetails -> NameSet
freeNamesIfIdDetails :: IfaceIdDetails -> NameSet
freeNamesIfIdDetails (IfRecSelId Either IfaceTyCon IfaceDecl
tc Bool
_) =
  forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either IfaceTyCon -> NameSet
freeNamesIfTc IfaceDecl -> NameSet
freeNamesIfDecl Either IfaceTyCon IfaceDecl
tc
freeNamesIfIdDetails IfaceIdDetails
_                 = NameSet
emptyNameSet

-- All other changes are handled via the version info on the tycon
freeNamesIfFamFlav :: IfaceFamTyConFlav -> NameSet
freeNamesIfFamFlav :: IfaceFamTyConFlav -> NameSet
freeNamesIfFamFlav IfaceFamTyConFlav
IfaceOpenSynFamilyTyCon             = NameSet
emptyNameSet
freeNamesIfFamFlav IfaceFamTyConFlav
IfaceDataFamilyTyCon                = NameSet
emptyNameSet
freeNamesIfFamFlav (IfaceClosedSynFamilyTyCon (Just (IfExtName
ax, [IfaceAxBranch]
br)))
  = IfExtName -> NameSet
unitNameSet IfExtName
ax NameSet -> NameSet -> NameSet
&&& forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceAxBranch -> NameSet
freeNamesIfAxBranch [IfaceAxBranch]
br
freeNamesIfFamFlav (IfaceClosedSynFamilyTyCon Maybe (IfExtName, [IfaceAxBranch])
Nothing) = NameSet
emptyNameSet
freeNamesIfFamFlav IfaceFamTyConFlav
IfaceAbstractClosedSynFamilyTyCon   = NameSet
emptyNameSet
freeNamesIfFamFlav IfaceFamTyConFlav
IfaceBuiltInSynFamTyCon             = NameSet
emptyNameSet

freeNamesIfContext :: IfaceContext -> NameSet
freeNamesIfContext :: IfaceContext -> NameSet
freeNamesIfContext = forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceType -> NameSet
freeNamesIfType

freeNamesIfAT :: IfaceAT -> NameSet
freeNamesIfAT :: IfaceAT -> NameSet
freeNamesIfAT (IfaceAT IfaceDecl
decl Maybe IfaceType
mb_def)
  = IfaceDecl -> NameSet
freeNamesIfDecl IfaceDecl
decl NameSet -> NameSet -> NameSet
&&&
    case Maybe IfaceType
mb_def of
      Maybe IfaceType
Nothing  -> NameSet
emptyNameSet
      Just IfaceType
rhs -> IfaceType -> NameSet
freeNamesIfType IfaceType
rhs

freeNamesIfClsSig :: IfaceClassOp -> NameSet
freeNamesIfClsSig :: IfaceClassOp -> NameSet
freeNamesIfClsSig (IfaceClassOp IfExtName
_n IfaceType
ty Maybe (DefMethSpec IfaceType)
dm) = IfaceType -> NameSet
freeNamesIfType IfaceType
ty NameSet -> NameSet -> NameSet
&&& Maybe (DefMethSpec IfaceType) -> NameSet
freeNamesDM Maybe (DefMethSpec IfaceType)
dm

freeNamesDM :: Maybe (DefMethSpec IfaceType) -> NameSet
freeNamesDM :: Maybe (DefMethSpec IfaceType) -> NameSet
freeNamesDM (Just (GenericDM IfaceType
ty)) = IfaceType -> NameSet
freeNamesIfType IfaceType
ty
freeNamesDM Maybe (DefMethSpec IfaceType)
_                     = NameSet
emptyNameSet

freeNamesIfConDecls :: IfaceConDecls -> NameSet
freeNamesIfConDecls :: IfaceConDecls -> NameSet
freeNamesIfConDecls (IfDataTyCon Bool
_ [IfaceConDecl]
cs) = forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceConDecl -> NameSet
freeNamesIfConDecl [IfaceConDecl]
cs
freeNamesIfConDecls (IfNewTyCon    IfaceConDecl
c)  = IfaceConDecl -> NameSet
freeNamesIfConDecl IfaceConDecl
c
freeNamesIfConDecls IfaceConDecls
_                   = NameSet
emptyNameSet

freeNamesIfConDecl :: IfaceConDecl -> NameSet
freeNamesIfConDecl :: IfaceConDecl -> NameSet
freeNamesIfConDecl (IfCon { ifConExTCvs :: IfaceConDecl -> [IfaceBndr]
ifConExTCvs  = [IfaceBndr]
ex_tvs, ifConCtxt :: IfaceConDecl -> IfaceContext
ifConCtxt = IfaceContext
ctxt
                          , ifConArgTys :: IfaceConDecl -> [(IfaceType, IfaceType)]
ifConArgTys  = [(IfaceType, IfaceType)]
arg_tys
                          , ifConFields :: IfaceConDecl -> [FieldLabel]
ifConFields  = [FieldLabel]
flds
                          , ifConEqSpec :: IfaceConDecl -> [IfaceTvBndr]
ifConEqSpec  = [IfaceTvBndr]
eq_spec
                          , ifConStricts :: IfaceConDecl -> [IfaceBang]
ifConStricts = [IfaceBang]
bangs })
  = forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceBndr -> NameSet
freeNamesIfBndr [IfaceBndr]
ex_tvs NameSet -> NameSet -> NameSet
&&&
    IfaceContext -> NameSet
freeNamesIfContext IfaceContext
ctxt NameSet -> NameSet -> NameSet
&&&
    forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceType -> NameSet
freeNamesIfType (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> a
fst [(IfaceType, IfaceType)]
arg_tys) NameSet -> NameSet -> NameSet
&&& -- these are multiplicities, represented as types
    forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceType -> NameSet
freeNamesIfType (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [(IfaceType, IfaceType)]
arg_tys) NameSet -> NameSet -> NameSet
&&&
    [IfExtName] -> NameSet
mkNameSet (forall a b. (a -> b) -> [a] -> [b]
map FieldLabel -> IfExtName
flSelector [FieldLabel]
flds) NameSet -> NameSet -> NameSet
&&&
    forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceType -> NameSet
freeNamesIfType (forall a b. (a -> b) -> [a] -> [b]
map forall a b. (a, b) -> b
snd [IfaceTvBndr]
eq_spec) NameSet -> NameSet -> NameSet
&&& -- equality constraints
    forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceBang -> NameSet
freeNamesIfBang [IfaceBang]
bangs

freeNamesIfBang :: IfaceBang -> NameSet
freeNamesIfBang :: IfaceBang -> NameSet
freeNamesIfBang (IfUnpackCo IfaceCoercion
co) = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
co
freeNamesIfBang IfaceBang
_               = NameSet
emptyNameSet

freeNamesIfKind :: IfaceType -> NameSet
freeNamesIfKind :: IfaceType -> NameSet
freeNamesIfKind = IfaceType -> NameSet
freeNamesIfType

freeNamesIfAppArgs :: IfaceAppArgs -> NameSet
freeNamesIfAppArgs :: IfaceAppArgs -> NameSet
freeNamesIfAppArgs (IA_Arg IfaceType
t ForAllTyFlag
_ IfaceAppArgs
ts) = IfaceType -> NameSet
freeNamesIfType IfaceType
t NameSet -> NameSet -> NameSet
&&& IfaceAppArgs -> NameSet
freeNamesIfAppArgs IfaceAppArgs
ts
freeNamesIfAppArgs IfaceAppArgs
IA_Nil          = NameSet
emptyNameSet

freeNamesIfType :: IfaceType -> NameSet
freeNamesIfType :: IfaceType -> NameSet
freeNamesIfType (IfaceFreeTyVar TyVar
_)    = NameSet
emptyNameSet
freeNamesIfType (IfaceTyVar IfLclName
_)        = NameSet
emptyNameSet
freeNamesIfType (IfaceAppTy IfaceType
s IfaceAppArgs
t)      = IfaceType -> NameSet
freeNamesIfType IfaceType
s NameSet -> NameSet -> NameSet
&&& IfaceAppArgs -> NameSet
freeNamesIfAppArgs IfaceAppArgs
t
freeNamesIfType (IfaceTyConApp IfaceTyCon
tc IfaceAppArgs
ts) = IfaceTyCon -> NameSet
freeNamesIfTc IfaceTyCon
tc NameSet -> NameSet -> NameSet
&&& IfaceAppArgs -> NameSet
freeNamesIfAppArgs IfaceAppArgs
ts
freeNamesIfType (IfaceTupleTy TupleSort
_ PromotionFlag
_ IfaceAppArgs
ts) = IfaceAppArgs -> NameSet
freeNamesIfAppArgs IfaceAppArgs
ts
freeNamesIfType (IfaceLitTy IfaceTyLit
_)        = NameSet
emptyNameSet
freeNamesIfType (IfaceForAllTy IfaceForAllBndr
tv IfaceType
t)  = forall vis. VarBndr IfaceBndr vis -> NameSet
freeNamesIfVarBndr IfaceForAllBndr
tv NameSet -> NameSet -> NameSet
&&& IfaceType -> NameSet
freeNamesIfType IfaceType
t
freeNamesIfType (IfaceFunTy FunTyFlag
_ IfaceType
w IfaceType
s IfaceType
t)  = IfaceType -> NameSet
freeNamesIfType IfaceType
s NameSet -> NameSet -> NameSet
&&& IfaceType -> NameSet
freeNamesIfType IfaceType
t NameSet -> NameSet -> NameSet
&&& IfaceType -> NameSet
freeNamesIfType IfaceType
w
freeNamesIfType (IfaceCastTy IfaceType
t IfaceCoercion
c)     = IfaceType -> NameSet
freeNamesIfType IfaceType
t NameSet -> NameSet -> NameSet
&&& IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
c
freeNamesIfType (IfaceCoercionTy IfaceCoercion
c)   = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
c

freeNamesIfMCoercion :: IfaceMCoercion -> NameSet
freeNamesIfMCoercion :: IfaceMCoercion -> NameSet
freeNamesIfMCoercion IfaceMCoercion
IfaceMRefl    = NameSet
emptyNameSet
freeNamesIfMCoercion (IfaceMCo IfaceCoercion
co) = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
co

freeNamesIfCoercion :: IfaceCoercion -> NameSet
freeNamesIfCoercion :: IfaceCoercion -> NameSet
freeNamesIfCoercion (IfaceReflCo IfaceType
t) = IfaceType -> NameSet
freeNamesIfType IfaceType
t
freeNamesIfCoercion (IfaceGReflCo Role
_ IfaceType
t IfaceMCoercion
mco)
  = IfaceType -> NameSet
freeNamesIfType IfaceType
t NameSet -> NameSet -> NameSet
&&& IfaceMCoercion -> NameSet
freeNamesIfMCoercion IfaceMCoercion
mco
freeNamesIfCoercion (IfaceFunCo Role
_ IfaceCoercion
c_mult IfaceCoercion
c1 IfaceCoercion
c2)
  = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
c_mult NameSet -> NameSet -> NameSet
&&& IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
c1 NameSet -> NameSet -> NameSet
&&& IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
c2
freeNamesIfCoercion (IfaceTyConAppCo Role
_ IfaceTyCon
tc [IfaceCoercion]
cos)
  = IfaceTyCon -> NameSet
freeNamesIfTc IfaceTyCon
tc NameSet -> NameSet -> NameSet
&&& forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceCoercion -> NameSet
freeNamesIfCoercion [IfaceCoercion]
cos
freeNamesIfCoercion (IfaceAppCo IfaceCoercion
c1 IfaceCoercion
c2)
  = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
c1 NameSet -> NameSet -> NameSet
&&& IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
c2
freeNamesIfCoercion (IfaceForAllCo IfaceBndr
_ IfaceCoercion
kind_co IfaceCoercion
co)
  = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
kind_co NameSet -> NameSet -> NameSet
&&& IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
co
freeNamesIfCoercion (IfaceFreeCoVar TyVar
_) = NameSet
emptyNameSet
freeNamesIfCoercion (IfaceCoVarCo IfLclName
_)   = NameSet
emptyNameSet
freeNamesIfCoercion (IfaceHoleCo TyVar
_)    = NameSet
emptyNameSet
freeNamesIfCoercion (IfaceAxiomInstCo IfExtName
ax Int
_ [IfaceCoercion]
cos)
  = IfExtName -> NameSet
unitNameSet IfExtName
ax NameSet -> NameSet -> NameSet
&&& forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceCoercion -> NameSet
freeNamesIfCoercion [IfaceCoercion]
cos
freeNamesIfCoercion (IfaceUnivCo IfaceUnivCoProv
p Role
_ IfaceType
t1 IfaceType
t2)
  = IfaceUnivCoProv -> NameSet
freeNamesIfProv IfaceUnivCoProv
p NameSet -> NameSet -> NameSet
&&& IfaceType -> NameSet
freeNamesIfType IfaceType
t1 NameSet -> NameSet -> NameSet
&&& IfaceType -> NameSet
freeNamesIfType IfaceType
t2
freeNamesIfCoercion (IfaceSymCo IfaceCoercion
c)
  = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
c
freeNamesIfCoercion (IfaceTransCo IfaceCoercion
c1 IfaceCoercion
c2)
  = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
c1 NameSet -> NameSet -> NameSet
&&& IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
c2
freeNamesIfCoercion (IfaceSelCo CoSel
_ IfaceCoercion
co)
  = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
co
freeNamesIfCoercion (IfaceLRCo LeftOrRight
_ IfaceCoercion
co)
  = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
co
freeNamesIfCoercion (IfaceInstCo IfaceCoercion
co IfaceCoercion
co2)
  = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
co NameSet -> NameSet -> NameSet
&&& IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
co2
freeNamesIfCoercion (IfaceKindCo IfaceCoercion
c)
  = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
c
freeNamesIfCoercion (IfaceSubCo IfaceCoercion
co)
  = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
co
freeNamesIfCoercion (IfaceAxiomRuleCo IfLclName
_ax [IfaceCoercion]
cos)
  -- the axiom is just a string, so we don't count it as a name.
  = forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceCoercion -> NameSet
freeNamesIfCoercion [IfaceCoercion]
cos

freeNamesIfProv :: IfaceUnivCoProv -> NameSet
freeNamesIfProv :: IfaceUnivCoProv -> NameSet
freeNamesIfProv (IfacePhantomProv IfaceCoercion
co)    = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
co
freeNamesIfProv (IfaceProofIrrelProv IfaceCoercion
co) = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
co
freeNamesIfProv (IfacePluginProv String
_)      = NameSet
emptyNameSet
freeNamesIfProv (IfaceCorePrepProv Bool
_)    = NameSet
emptyNameSet

freeNamesIfVarBndr :: VarBndr IfaceBndr vis -> NameSet
freeNamesIfVarBndr :: forall vis. VarBndr IfaceBndr vis -> NameSet
freeNamesIfVarBndr (Bndr IfaceBndr
bndr vis
_) = IfaceBndr -> NameSet
freeNamesIfBndr IfaceBndr
bndr

freeNamesIfVarBndrs :: [VarBndr IfaceBndr vis] -> NameSet
freeNamesIfVarBndrs :: forall vis. [VarBndr IfaceBndr vis] -> NameSet
freeNamesIfVarBndrs = forall a. (a -> NameSet) -> [a] -> NameSet
fnList forall vis. VarBndr IfaceBndr vis -> NameSet
freeNamesIfVarBndr

freeNamesIfBndr :: IfaceBndr -> NameSet
freeNamesIfBndr :: IfaceBndr -> NameSet
freeNamesIfBndr (IfaceIdBndr IfaceIdBndr
b) = IfaceIdBndr -> NameSet
freeNamesIfIdBndr IfaceIdBndr
b
freeNamesIfBndr (IfaceTvBndr IfaceTvBndr
b) = IfaceTvBndr -> NameSet
freeNamesIfTvBndr IfaceTvBndr
b

freeNamesIfBndrs :: [IfaceBndr] -> NameSet
freeNamesIfBndrs :: [IfaceBndr] -> NameSet
freeNamesIfBndrs = forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceBndr -> NameSet
freeNamesIfBndr

freeNamesIfLetBndr :: IfaceLetBndr -> NameSet
-- Remember IfaceLetBndr is used only for *nested* bindings
-- The IdInfo can contain an unfolding (in the case of
-- local INLINE pragmas), so look there too
freeNamesIfLetBndr :: IfaceLetBndr -> NameSet
freeNamesIfLetBndr (IfLetBndr IfLclName
_name IfaceType
ty IfaceIdInfo
info IfaceJoinInfo
_ji) = IfaceType -> NameSet
freeNamesIfType IfaceType
ty
                                                 NameSet -> NameSet -> NameSet
&&& IfaceIdInfo -> NameSet
freeNamesIfIdInfo IfaceIdInfo
info

freeNamesIfTvBndr :: IfaceTvBndr -> NameSet
freeNamesIfTvBndr :: IfaceTvBndr -> NameSet
freeNamesIfTvBndr (IfLclName
_fs,IfaceType
k) = IfaceType -> NameSet
freeNamesIfKind IfaceType
k
    -- kinds can have Names inside, because of promotion

freeNamesIfIdBndr :: IfaceIdBndr -> NameSet
freeNamesIfIdBndr :: IfaceIdBndr -> NameSet
freeNamesIfIdBndr (IfaceType
_, IfLclName
_fs,IfaceType
k) = IfaceType -> NameSet
freeNamesIfKind IfaceType
k

freeNamesIfIdInfo :: IfaceIdInfo -> NameSet
freeNamesIfIdInfo :: IfaceIdInfo -> NameSet
freeNamesIfIdInfo = forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceInfoItem -> NameSet
freeNamesItem

freeNamesItem :: IfaceInfoItem -> NameSet
freeNamesItem :: IfaceInfoItem -> NameSet
freeNamesItem (HsUnfold Bool
_ IfaceUnfolding
u)         = IfaceUnfolding -> NameSet
freeNamesIfUnfold IfaceUnfolding
u
freeNamesItem (HsLFInfo (IfLFCon IfExtName
n)) = IfExtName -> NameSet
unitNameSet IfExtName
n
freeNamesItem IfaceInfoItem
_                      = NameSet
emptyNameSet

freeNamesIfUnfold :: IfaceUnfolding -> NameSet
freeNamesIfUnfold :: IfaceUnfolding -> NameSet
freeNamesIfUnfold (IfCoreUnfold UnfoldingSource
_ IfUnfoldingCache
_ IfGuidance
_ IfaceExpr
e) = IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
e
freeNamesIfUnfold (IfDFunUnfold [IfaceBndr]
bs [IfaceExpr]
es)   = [IfaceBndr] -> NameSet
freeNamesIfBndrs [IfaceBndr]
bs NameSet -> NameSet -> NameSet
&&& forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceExpr -> NameSet
freeNamesIfExpr [IfaceExpr]
es

freeNamesIfExpr :: IfaceExpr -> NameSet
freeNamesIfExpr :: IfaceExpr -> NameSet
freeNamesIfExpr (IfaceExt IfExtName
v)          = IfExtName -> NameSet
unitNameSet IfExtName
v
freeNamesIfExpr (IfaceFCall ForeignCall
_ IfaceType
ty)     = IfaceType -> NameSet
freeNamesIfType IfaceType
ty
freeNamesIfExpr (IfaceType IfaceType
ty)        = IfaceType -> NameSet
freeNamesIfType IfaceType
ty
freeNamesIfExpr (IfaceCo IfaceCoercion
co)          = IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
co
freeNamesIfExpr (IfaceTuple TupleSort
_ [IfaceExpr]
as)     = forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceExpr -> NameSet
freeNamesIfExpr [IfaceExpr]
as
freeNamesIfExpr (IfaceLam (IfaceBndr
b,IfaceOneShot
_) IfaceExpr
body) = IfaceBndr -> NameSet
freeNamesIfBndr IfaceBndr
b NameSet -> NameSet -> NameSet
&&& IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
body
freeNamesIfExpr (IfaceApp IfaceExpr
f IfaceExpr
a)        = IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
f NameSet -> NameSet -> NameSet
&&& IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
a
freeNamesIfExpr (IfaceCast IfaceExpr
e IfaceCoercion
co)      = IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
e NameSet -> NameSet -> NameSet
&&& IfaceCoercion -> NameSet
freeNamesIfCoercion IfaceCoercion
co
freeNamesIfExpr (IfaceTick IfaceTickish
_ IfaceExpr
e)       = IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
e
freeNamesIfExpr (IfaceECase IfaceExpr
e IfaceType
ty)     = IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
e NameSet -> NameSet -> NameSet
&&& IfaceType -> NameSet
freeNamesIfType IfaceType
ty
freeNamesIfExpr (IfaceCase IfaceExpr
s IfLclName
_ [IfaceAlt]
alts)
  = IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
s NameSet -> NameSet -> NameSet
&&& forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceAlt -> NameSet
fn_alt [IfaceAlt]
alts NameSet -> NameSet -> NameSet
&&& [IfaceAlt] -> NameSet
fn_cons [IfaceAlt]
alts
  where
    fn_alt :: IfaceAlt -> NameSet
fn_alt (IfaceAlt IfaceConAlt
_con [IfLclName]
_bs IfaceExpr
r) = IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
r

    -- Depend on the data constructors.  Just one will do!
    -- Note [Tracking data constructors]
    fn_cons :: [IfaceAlt] -> NameSet
fn_cons []                                     = NameSet
emptyNameSet
    fn_cons (IfaceAlt IfaceConAlt
IfaceDefault [IfLclName]
_ IfaceExpr
_       : [IfaceAlt]
xs) = [IfaceAlt] -> NameSet
fn_cons [IfaceAlt]
xs
    fn_cons (IfaceAlt (IfaceDataAlt IfExtName
con) [IfLclName]
_ IfaceExpr
_ : [IfaceAlt]
_ ) = IfExtName -> NameSet
unitNameSet IfExtName
con
    fn_cons (IfaceAlt
_                               : [IfaceAlt]
_ ) = NameSet
emptyNameSet

freeNamesIfExpr (IfaceLet (IfaceNonRec IfaceLetBndr
bndr IfaceExpr
rhs) IfaceExpr
body)
  = IfaceLetBndr -> NameSet
freeNamesIfLetBndr IfaceLetBndr
bndr NameSet -> NameSet -> NameSet
&&& IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
rhs NameSet -> NameSet -> NameSet
&&& IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
body

freeNamesIfExpr (IfaceLet (IfaceRec [(IfaceLetBndr, IfaceExpr)]
as) IfaceExpr
x)
  = forall a. (a -> NameSet) -> [a] -> NameSet
fnList (IfaceLetBndr, IfaceExpr) -> NameSet
fn_pair [(IfaceLetBndr, IfaceExpr)]
as NameSet -> NameSet -> NameSet
&&& IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
x
  where
    fn_pair :: (IfaceLetBndr, IfaceExpr) -> NameSet
fn_pair (IfaceLetBndr
bndr, IfaceExpr
rhs) = IfaceLetBndr -> NameSet
freeNamesIfLetBndr IfaceLetBndr
bndr NameSet -> NameSet -> NameSet
&&& IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
rhs

freeNamesIfExpr IfaceExpr
_ = NameSet
emptyNameSet

freeNamesIfTc :: IfaceTyCon -> NameSet
freeNamesIfTc :: IfaceTyCon -> NameSet
freeNamesIfTc IfaceTyCon
tc = IfExtName -> NameSet
unitNameSet (IfaceTyCon -> IfExtName
ifaceTyConName IfaceTyCon
tc)
-- ToDo: shouldn't we include IfaceIntTc & co.?

freeNamesIfRule :: IfaceRule -> NameSet
freeNamesIfRule :: IfaceRule -> NameSet
freeNamesIfRule (IfaceRule { ifRuleBndrs :: IfaceRule -> [IfaceBndr]
ifRuleBndrs = [IfaceBndr]
bs, ifRuleHead :: IfaceRule -> IfExtName
ifRuleHead = IfExtName
f
                           , ifRuleArgs :: IfaceRule -> [IfaceExpr]
ifRuleArgs = [IfaceExpr]
es, ifRuleRhs :: IfaceRule -> IfaceExpr
ifRuleRhs = IfaceExpr
rhs })
  = IfExtName -> NameSet
unitNameSet IfExtName
f NameSet -> NameSet -> NameSet
&&&
    forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceBndr -> NameSet
freeNamesIfBndr [IfaceBndr]
bs NameSet -> NameSet -> NameSet
&&&
    forall a. (a -> NameSet) -> [a] -> NameSet
fnList IfaceExpr -> NameSet
freeNamesIfExpr [IfaceExpr]
es NameSet -> NameSet -> NameSet
&&&
    IfaceExpr -> NameSet
freeNamesIfExpr IfaceExpr
rhs

freeNamesIfFamInst :: IfaceFamInst -> NameSet
freeNamesIfFamInst :: IfaceFamInst -> NameSet
freeNamesIfFamInst (IfaceFamInst { ifFamInstFam :: IfaceFamInst -> IfExtName
ifFamInstFam = IfExtName
famName
                                 , ifFamInstAxiom :: IfaceFamInst -> IfExtName
ifFamInstAxiom = IfExtName
axName })
  = IfExtName -> NameSet
unitNameSet IfExtName
famName NameSet -> NameSet -> NameSet
&&&
    IfExtName -> NameSet
unitNameSet IfExtName
axName

freeNamesIfaceTyConParent :: IfaceTyConParent -> NameSet
freeNamesIfaceTyConParent :: IfaceTyConParent -> NameSet
freeNamesIfaceTyConParent IfaceTyConParent
IfNoParent = NameSet
emptyNameSet
freeNamesIfaceTyConParent (IfDataInstance IfExtName
ax IfaceTyCon
tc IfaceAppArgs
tys)
  = IfExtName -> NameSet
unitNameSet IfExtName
ax NameSet -> NameSet -> NameSet
&&& IfaceTyCon -> NameSet
freeNamesIfTc IfaceTyCon
tc NameSet -> NameSet -> NameSet
&&& IfaceAppArgs -> NameSet
freeNamesIfAppArgs IfaceAppArgs
tys

-- helpers
(&&&) :: NameSet -> NameSet -> NameSet
&&& :: NameSet -> NameSet -> NameSet
(&&&) = NameSet -> NameSet -> NameSet
unionNameSet

fnList :: (a -> NameSet) -> [a] -> NameSet
fnList :: forall a. (a -> NameSet) -> [a] -> NameSet
fnList a -> NameSet
f = forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr NameSet -> NameSet -> NameSet
(&&&) NameSet
emptyNameSet forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map a -> NameSet
f

{-
Note [Tracking data constructors]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In a case expression
   case e of { C a -> ...; ... }
You might think that we don't need to include the datacon C
in the free names, because its type will probably show up in
the free names of 'e'.  But in rare circumstances this may
not happen.   Here's the one that bit me:

   module DynFlags where
     import {-# SOURCE #-} Packages( PackageState )
     data DynFlags = DF ... PackageState ...

   module Packages where
     import GHC.Driver.Session
     data PackageState = PS ...
     lookupModule (df :: DynFlags)
        = case df of
              DF ...p... -> case p of
                               PS ... -> ...

Now, lookupModule depends on DynFlags, but the transitive dependency
on the *locally-defined* type PackageState is not visible. We need
to take account of the use of the data constructor PS in the pattern match.


************************************************************************
*                                                                      *
                Binary instances
*                                                                      *
************************************************************************

Note that there is a bit of subtlety here when we encode names. While
IfaceTopBndrs is really just a synonym for Name, we need to take care to
encode them with {get,put}IfaceTopBndr. The difference becomes important when
we go to fingerprint an IfaceDecl. See Note [Fingerprinting IfaceDecls] for
details.

-}

instance Binary IfaceDecl where
    put_ :: BinHandle -> IfaceDecl -> IO ()
put_ BinHandle
bh (IfaceId IfExtName
name IfaceType
ty IfaceIdDetails
details IfaceIdInfo
idinfo) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
        BinHandle -> IfExtName -> IO ()
putIfaceTopBndr BinHandle
bh IfExtName
name
        forall a. Binary a => BinHandle -> a -> IO ()
lazyPut BinHandle
bh (IfaceType
ty, IfaceIdDetails
details, IfaceIdInfo
idinfo)
        -- See Note [Lazy deserialization of IfaceId]

    put_ BinHandle
bh (IfaceData IfExtName
a1 [IfaceTyConBinder]
a2 IfaceType
a3 Maybe CType
a4 [Role]
a5 IfaceContext
a6 IfaceConDecls
a7 Bool
a8 IfaceTyConParent
a9) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
2
        BinHandle -> IfExtName -> IO ()
putIfaceTopBndr BinHandle
bh IfExtName
a1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceTyConBinder]
a2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
a3
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Maybe CType
a4
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [Role]
a5
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceContext
a6
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceConDecls
a7
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
a8
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceTyConParent
a9

    put_ BinHandle
bh (IfaceSynonym IfExtName
a1 [Role]
a2 [IfaceTyConBinder]
a3 IfaceType
a4 IfaceType
a5) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
3
        BinHandle -> IfExtName -> IO ()
putIfaceTopBndr BinHandle
bh IfExtName
a1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [Role]
a2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceTyConBinder]
a3
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
a4
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
a5

    put_ BinHandle
bh (IfaceFamily IfExtName
a1 Maybe IfLclName
a2 [IfaceTyConBinder]
a3 IfaceType
a4 IfaceFamTyConFlav
a5 Injectivity
a6) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
4
        BinHandle -> IfExtName -> IO ()
putIfaceTopBndr BinHandle
bh IfExtName
a1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Maybe IfLclName
a2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceTyConBinder]
a3
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
a4
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceFamTyConFlav
a5
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Injectivity
a6

    -- NB: Written in a funny way to avoid an interface change
    put_ BinHandle
bh (IfaceClass {
                ifName :: IfaceDecl -> IfExtName
ifName    = IfExtName
a2,
                ifRoles :: IfaceDecl -> [Role]
ifRoles   = [Role]
a3,
                ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
a4,
                ifFDs :: IfaceDecl -> [FunDep IfLclName]
ifFDs     = [FunDep IfLclName]
a5,
                ifBody :: IfaceDecl -> IfaceClassBody
ifBody = IfConcreteClass {
                    ifClassCtxt :: IfaceClassBody -> IfaceContext
ifClassCtxt = IfaceContext
a1,
                    ifATs :: IfaceClassBody -> [IfaceAT]
ifATs  = [IfaceAT]
a6,
                    ifSigs :: IfaceClassBody -> [IfaceClassOp]
ifSigs = [IfaceClassOp]
a7,
                    ifMinDef :: IfaceClassBody -> BooleanFormula IfLclName
ifMinDef  = BooleanFormula IfLclName
a8
                }}) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
5
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceContext
a1
        BinHandle -> IfExtName -> IO ()
putIfaceTopBndr BinHandle
bh IfExtName
a2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [Role]
a3
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceTyConBinder]
a4
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [FunDep IfLclName]
a5
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceAT]
a6
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceClassOp]
a7
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh BooleanFormula IfLclName
a8

    put_ BinHandle
bh (IfaceAxiom IfExtName
a1 IfaceTyCon
a2 Role
a3 [IfaceAxBranch]
a4) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
6
        BinHandle -> IfExtName -> IO ()
putIfaceTopBndr BinHandle
bh IfExtName
a1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceTyCon
a2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Role
a3
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceAxBranch]
a4

    put_ BinHandle
bh (IfacePatSyn IfExtName
a1 Bool
a2 (IfExtName, Bool)
a3 Maybe (IfExtName, Bool)
a4 [IfaceForAllSpecBndr]
a5 [IfaceForAllSpecBndr]
a6 IfaceContext
a7 IfaceContext
a8 IfaceContext
a9 IfaceType
a10 [FieldLabel]
a11) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
7
        BinHandle -> IfExtName -> IO ()
putIfaceTopBndr BinHandle
bh IfExtName
a1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
a2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh (IfExtName, Bool)
a3
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Maybe (IfExtName, Bool)
a4
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceForAllSpecBndr]
a5
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceForAllSpecBndr]
a6
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceContext
a7
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceContext
a8
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceContext
a9
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
a10
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [FieldLabel]
a11

    put_ BinHandle
bh (IfaceClass {
                ifName :: IfaceDecl -> IfExtName
ifName    = IfExtName
a1,
                ifRoles :: IfaceDecl -> [Role]
ifRoles   = [Role]
a2,
                ifBinders :: IfaceDecl -> [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
a3,
                ifFDs :: IfaceDecl -> [FunDep IfLclName]
ifFDs     = [FunDep IfLclName]
a4,
                ifBody :: IfaceDecl -> IfaceClassBody
ifBody = IfaceClassBody
IfAbstractClass }) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
8
        BinHandle -> IfExtName -> IO ()
putIfaceTopBndr BinHandle
bh IfExtName
a1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [Role]
a2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceTyConBinder]
a3
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [FunDep IfLclName]
a4

    get :: BinHandle -> IO IfaceDecl
get BinHandle
bh = do
        Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
h of
            Word8
0 -> do IfExtName
name <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    ~(IfaceType
ty, IfaceIdDetails
details, IfaceIdInfo
idinfo) <- forall a. Binary a => BinHandle -> IO a
lazyGet BinHandle
bh
                    -- See Note [Lazy deserialization of IfaceId]
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfExtName
-> IfaceType -> IfaceIdDetails -> IfaceIdInfo -> IfaceDecl
IfaceId IfExtName
name IfaceType
ty IfaceIdDetails
details IfaceIdInfo
idinfo)
            Word8
1 -> forall a. HasCallStack => String -> a
error String
"Binary.get(TyClDecl): ForeignType"
            Word8
2 -> do IfExtName
a1  <- BinHandle -> IO IfExtName
getIfaceTopBndr BinHandle
bh
                    [IfaceTyConBinder]
a2  <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceType
a3  <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Maybe CType
a4  <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [Role]
a5  <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceContext
a6  <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceConDecls
a7  <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Bool
a8  <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceTyConParent
a9  <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfExtName
-> [IfaceTyConBinder]
-> IfaceType
-> Maybe CType
-> [Role]
-> IfaceContext
-> IfaceConDecls
-> Bool
-> IfaceTyConParent
-> IfaceDecl
IfaceData IfExtName
a1 [IfaceTyConBinder]
a2 IfaceType
a3 Maybe CType
a4 [Role]
a5 IfaceContext
a6 IfaceConDecls
a7 Bool
a8 IfaceTyConParent
a9)
            Word8
3 -> do IfExtName
a1 <- BinHandle -> IO IfExtName
getIfaceTopBndr BinHandle
bh
                    [Role]
a2 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [IfaceTyConBinder]
a3 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceType
a4 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceType
a5 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfExtName
-> [Role]
-> [IfaceTyConBinder]
-> IfaceType
-> IfaceType
-> IfaceDecl
IfaceSynonym IfExtName
a1 [Role]
a2 [IfaceTyConBinder]
a3 IfaceType
a4 IfaceType
a5)
            Word8
4 -> do IfExtName
a1 <- BinHandle -> IO IfExtName
getIfaceTopBndr BinHandle
bh
                    Maybe IfLclName
a2 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [IfaceTyConBinder]
a3 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceType
a4 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceFamTyConFlav
a5 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Injectivity
a6 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfExtName
-> Maybe IfLclName
-> [IfaceTyConBinder]
-> IfaceType
-> IfaceFamTyConFlav
-> Injectivity
-> IfaceDecl
IfaceFamily IfExtName
a1 Maybe IfLclName
a2 [IfaceTyConBinder]
a3 IfaceType
a4 IfaceFamTyConFlav
a5 Injectivity
a6)
            Word8
5 -> do IfaceContext
a1 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfExtName
a2 <- BinHandle -> IO IfExtName
getIfaceTopBndr BinHandle
bh
                    [Role]
a3 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [IfaceTyConBinder]
a4 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [FunDep IfLclName]
a5 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [IfaceAT]
a6 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [IfaceClassOp]
a7 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    BooleanFormula IfLclName
a8 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceClass {
                        ifName :: IfExtName
ifName    = IfExtName
a2,
                        ifRoles :: [Role]
ifRoles   = [Role]
a3,
                        ifBinders :: [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
a4,
                        ifFDs :: [FunDep IfLclName]
ifFDs     = [FunDep IfLclName]
a5,
                        ifBody :: IfaceClassBody
ifBody = IfConcreteClass {
                            ifClassCtxt :: IfaceContext
ifClassCtxt = IfaceContext
a1,
                            ifATs :: [IfaceAT]
ifATs  = [IfaceAT]
a6,
                            ifSigs :: [IfaceClassOp]
ifSigs = [IfaceClassOp]
a7,
                            ifMinDef :: BooleanFormula IfLclName
ifMinDef  = BooleanFormula IfLclName
a8
                        }})
            Word8
6 -> do IfExtName
a1 <- BinHandle -> IO IfExtName
getIfaceTopBndr BinHandle
bh
                    IfaceTyCon
a2 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Role
a3 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [IfaceAxBranch]
a4 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfExtName -> IfaceTyCon -> Role -> [IfaceAxBranch] -> IfaceDecl
IfaceAxiom IfExtName
a1 IfaceTyCon
a2 Role
a3 [IfaceAxBranch]
a4)
            Word8
7 -> do IfExtName
a1 <- BinHandle -> IO IfExtName
getIfaceTopBndr BinHandle
bh
                    Bool
a2 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    (IfExtName, Bool)
a3 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Maybe (IfExtName, Bool)
a4 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [IfaceForAllSpecBndr]
a5 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [IfaceForAllSpecBndr]
a6 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceContext
a7 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceContext
a8 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceContext
a9 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceType
a10 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [FieldLabel]
a11 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfExtName
-> Bool
-> (IfExtName, Bool)
-> Maybe (IfExtName, Bool)
-> [IfaceForAllSpecBndr]
-> [IfaceForAllSpecBndr]
-> IfaceContext
-> IfaceContext
-> IfaceContext
-> IfaceType
-> [FieldLabel]
-> IfaceDecl
IfacePatSyn IfExtName
a1 Bool
a2 (IfExtName, Bool)
a3 Maybe (IfExtName, Bool)
a4 [IfaceForAllSpecBndr]
a5 [IfaceForAllSpecBndr]
a6 IfaceContext
a7 IfaceContext
a8 IfaceContext
a9 IfaceType
a10 [FieldLabel]
a11)
            Word8
8 -> do IfExtName
a1 <- BinHandle -> IO IfExtName
getIfaceTopBndr BinHandle
bh
                    [Role]
a2 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [IfaceTyConBinder]
a3 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [FunDep IfLclName]
a4 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceClass {
                        ifName :: IfExtName
ifName    = IfExtName
a1,
                        ifRoles :: [Role]
ifRoles   = [Role]
a2,
                        ifBinders :: [IfaceTyConBinder]
ifBinders = [IfaceTyConBinder]
a3,
                        ifFDs :: [FunDep IfLclName]
ifFDs     = [FunDep IfLclName]
a4,
                        ifBody :: IfaceClassBody
ifBody = IfaceClassBody
IfAbstractClass })
            Word8
_ -> forall a. HasCallStack => String -> a
panic ([String] -> String
unwords [String
"Unknown IfaceDecl tag:", forall a. Show a => a -> String
show Word8
h])

{- Note [Lazy deserialization of IfaceId]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The use of lazyPut and lazyGet in the IfaceId Binary instance is
purely for performance reasons, to avoid deserializing details about
identifiers that will never be used. It's not involved in tying the
knot in the type checker. It saved ~1% of the total build time of GHC.

When we read an interface file, we extend the PTE, a mapping of Names
to TyThings, with the declarations we have read. The extension of the
PTE is strict in the Names, but not in the TyThings themselves.
GHC.IfaceToCore.tcIfaceDecls calculates the list of (Name, TyThing) bindings
to add to the PTE.  For an IfaceId, there's just one binding to add; and
the ty, details, and idinfo fields of an IfaceId are used only in the
TyThing. So by reading those fields lazily we may be able to save the
work of ever having to deserialize them (into IfaceType, etc.).

For IfaceData and IfaceClass, tcIfaceDecls creates extra implicit bindings
(the constructors and field selectors of the data declaration, or the
methods of the class), whose Names depend on more than just the Name
of the type constructor or class itself. So deserializing them lazily
would be more involved. Similar comments apply to the other
constructors of IfaceDecl with the additional point that they probably
represent a small proportion of all declarations.
-}

instance Binary IfaceFamTyConFlav where
    put_ :: BinHandle -> IfaceFamTyConFlav -> IO ()
put_ BinHandle
bh IfaceFamTyConFlav
IfaceDataFamilyTyCon              = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
    put_ BinHandle
bh IfaceFamTyConFlav
IfaceOpenSynFamilyTyCon           = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
    put_ BinHandle
bh (IfaceClosedSynFamilyTyCon Maybe (IfExtName, [IfaceAxBranch])
mb)    = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
2 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Maybe (IfExtName, [IfaceAxBranch])
mb
    put_ BinHandle
bh IfaceFamTyConFlav
IfaceAbstractClosedSynFamilyTyCon = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
3
    put_ BinHandle
_ IfaceFamTyConFlav
IfaceBuiltInSynFamTyCon
        = forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"Cannot serialize IfaceBuiltInSynFamTyCon, used for pretty-printing only" forall doc. IsOutput doc => doc
Outputable.empty

    get :: BinHandle -> IO IfaceFamTyConFlav
get BinHandle
bh = do { Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
                ; case Word8
h of
                    Word8
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceFamTyConFlav
IfaceDataFamilyTyCon
                    Word8
1 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceFamTyConFlav
IfaceOpenSynFamilyTyCon
                    Word8
2 -> do { Maybe (IfExtName, [IfaceAxBranch])
mb <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                            ; forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (IfExtName, [IfaceAxBranch]) -> IfaceFamTyConFlav
IfaceClosedSynFamilyTyCon Maybe (IfExtName, [IfaceAxBranch])
mb) }
                    Word8
3 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceFamTyConFlav
IfaceAbstractClosedSynFamilyTyCon
                    Word8
_ -> forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"Binary.get(IfaceFamTyConFlav): Invalid tag"
                                  (forall a. Outputable a => a -> SDoc
ppr (forall a b. (Integral a, Num b) => a -> b
fromIntegral Word8
h :: Int)) }

instance Binary IfaceClassOp where
    put_ :: BinHandle -> IfaceClassOp -> IO ()
put_ BinHandle
bh (IfaceClassOp IfExtName
n IfaceType
ty Maybe (DefMethSpec IfaceType)
def) = do
        BinHandle -> IfExtName -> IO ()
putIfaceTopBndr BinHandle
bh IfExtName
n
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
ty
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Maybe (DefMethSpec IfaceType)
def
    get :: BinHandle -> IO IfaceClassOp
get BinHandle
bh = do
        IfExtName
n   <- BinHandle -> IO IfExtName
getIfaceTopBndr BinHandle
bh
        IfaceType
ty  <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        Maybe (DefMethSpec IfaceType)
def <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        forall (m :: * -> *) a. Monad m => a -> m a
return (IfExtName
-> IfaceType -> Maybe (DefMethSpec IfaceType) -> IfaceClassOp
IfaceClassOp IfExtName
n IfaceType
ty Maybe (DefMethSpec IfaceType)
def)

instance Binary IfaceAT where
    put_ :: BinHandle -> IfaceAT -> IO ()
put_ BinHandle
bh (IfaceAT IfaceDecl
dec Maybe IfaceType
defs) = do
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceDecl
dec
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Maybe IfaceType
defs
    get :: BinHandle -> IO IfaceAT
get BinHandle
bh = do
        IfaceDecl
dec  <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        Maybe IfaceType
defs <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceDecl -> Maybe IfaceType -> IfaceAT
IfaceAT IfaceDecl
dec Maybe IfaceType
defs)

instance Binary IfaceAxBranch where
    put_ :: BinHandle -> IfaceAxBranch -> IO ()
put_ BinHandle
bh (IfaceAxBranch [IfaceTvBndr]
a1 [IfaceTvBndr]
a2 [IfaceIdBndr]
a3 IfaceAppArgs
a4 [Role]
a5 IfaceType
a6 [Int]
a7) = do
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceTvBndr]
a1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceTvBndr]
a2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceIdBndr]
a3
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceAppArgs
a4
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [Role]
a5
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
a6
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [Int]
a7
    get :: BinHandle -> IO IfaceAxBranch
get BinHandle
bh = do
        [IfaceTvBndr]
a1 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [IfaceTvBndr]
a2 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [IfaceIdBndr]
a3 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        IfaceAppArgs
a4 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [Role]
a5 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        IfaceType
a6 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [Int]
a7 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        forall (m :: * -> *) a. Monad m => a -> m a
return ([IfaceTvBndr]
-> [IfaceTvBndr]
-> [IfaceIdBndr]
-> IfaceAppArgs
-> [Role]
-> IfaceType
-> [Int]
-> IfaceAxBranch
IfaceAxBranch [IfaceTvBndr]
a1 [IfaceTvBndr]
a2 [IfaceIdBndr]
a3 IfaceAppArgs
a4 [Role]
a5 IfaceType
a6 [Int]
a7)

instance Binary IfaceConDecls where
    put_ :: BinHandle -> IfaceConDecls -> IO ()
put_ BinHandle
bh IfaceConDecls
IfAbstractTyCon  = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
    put_ BinHandle
bh (IfDataTyCon Bool
False [IfaceConDecl]
cs) = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceConDecl]
cs
    put_ BinHandle
bh (IfDataTyCon Bool
True [IfaceConDecl]
cs) = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
2 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceConDecl]
cs
    put_ BinHandle
bh (IfNewTyCon IfaceConDecl
c)   = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
3 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceConDecl
c
    get :: BinHandle -> IO IfaceConDecls
get BinHandle
bh = do
        Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
h of
            Word8
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceConDecls
IfAbstractTyCon
            Word8
1 -> forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Bool -> [IfaceConDecl] -> IfaceConDecls
IfDataTyCon Bool
False) (forall a. Binary a => BinHandle -> IO a
get BinHandle
bh)
            Word8
2 -> forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM (Bool -> [IfaceConDecl] -> IfaceConDecls
IfDataTyCon Bool
True) (forall a. Binary a => BinHandle -> IO a
get BinHandle
bh)
            Word8
3 -> forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM IfaceConDecl -> IfaceConDecls
IfNewTyCon (forall a. Binary a => BinHandle -> IO a
get BinHandle
bh)
            Word8
_ -> forall a. HasCallStack => String -> a
error String
"Binary(IfaceConDecls).get: Invalid IfaceConDecls"

instance Binary IfaceConDecl where
    put_ :: BinHandle -> IfaceConDecl -> IO ()
put_ BinHandle
bh (IfCon IfExtName
a1 Bool
a2 Bool
a3 [IfaceBndr]
a4 [IfaceForAllSpecBndr]
a5 [IfaceTvBndr]
a6 IfaceContext
a7 [(IfaceType, IfaceType)]
a8 [FieldLabel]
a9 [IfaceBang]
a10 [IfaceSrcBang]
a11) = do
        BinHandle -> IfExtName -> IO ()
putIfaceTopBndr BinHandle
bh IfExtName
a1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
a2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
a3
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceBndr]
a4
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceForAllSpecBndr]
a5
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceTvBndr]
a6
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceContext
a7
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [(IfaceType, IfaceType)]
a8
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh (forall (t :: * -> *) a. Foldable t => t a -> Int
length [FieldLabel]
a9)
        forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh) [FieldLabel]
a9
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceBang]
a10
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceSrcBang]
a11
    get :: BinHandle -> IO IfaceConDecl
get BinHandle
bh = do
        IfExtName
a1 <- BinHandle -> IO IfExtName
getIfaceTopBndr BinHandle
bh
        Bool
a2 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        Bool
a3 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [IfaceBndr]
a4 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [IfaceForAllSpecBndr]
a5 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [IfaceTvBndr]
a6 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        IfaceContext
a7 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [(IfaceType, IfaceType)]
a8 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        Int
n_fields <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [FieldLabel]
a9 <- forall (m :: * -> *) a. Applicative m => Int -> m a -> m [a]
replicateM Int
n_fields (forall a. Binary a => BinHandle -> IO a
get BinHandle
bh)
        [IfaceBang]
a10 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [IfaceSrcBang]
a11 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        forall (m :: * -> *) a. Monad m => a -> m a
return (IfExtName
-> Bool
-> Bool
-> [IfaceBndr]
-> [IfaceForAllSpecBndr]
-> [IfaceTvBndr]
-> IfaceContext
-> [(IfaceType, IfaceType)]
-> [FieldLabel]
-> [IfaceBang]
-> [IfaceSrcBang]
-> IfaceConDecl
IfCon IfExtName
a1 Bool
a2 Bool
a3 [IfaceBndr]
a4 [IfaceForAllSpecBndr]
a5 [IfaceTvBndr]
a6 IfaceContext
a7 [(IfaceType, IfaceType)]
a8 [FieldLabel]
a9 [IfaceBang]
a10 [IfaceSrcBang]
a11)

instance Binary IfaceBang where
    put_ :: BinHandle -> IfaceBang -> IO ()
put_ BinHandle
bh IfaceBang
IfNoBang        = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
    put_ BinHandle
bh IfaceBang
IfStrict        = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
    put_ BinHandle
bh IfaceBang
IfUnpack        = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
2
    put_ BinHandle
bh (IfUnpackCo IfaceCoercion
co) = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
3 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceCoercion
co

    get :: BinHandle -> IO IfaceBang
get BinHandle
bh = do
            Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
            case Word8
h of
              Word8
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceBang
IfNoBang
              Word8
1 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceBang
IfStrict
              Word8
2 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceBang
IfUnpack
              Word8
_ -> IfaceCoercion -> IfaceBang
IfUnpackCo forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh

instance Binary IfaceSrcBang where
    put_ :: BinHandle -> IfaceSrcBang -> IO ()
put_ BinHandle
bh (IfSrcBang SrcUnpackedness
a1 SrcStrictness
a2) =
      do forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh SrcUnpackedness
a1
         forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh SrcStrictness
a2

    get :: BinHandle -> IO IfaceSrcBang
get BinHandle
bh =
      do SrcUnpackedness
a1 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
         SrcStrictness
a2 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
         forall (m :: * -> *) a. Monad m => a -> m a
return (SrcUnpackedness -> SrcStrictness -> IfaceSrcBang
IfSrcBang SrcUnpackedness
a1 SrcStrictness
a2)

instance Binary IfaceClsInst where
    put_ :: BinHandle -> IfaceClsInst -> IO ()
put_ BinHandle
bh (IfaceClsInst IfExtName
cls [Maybe IfaceTyCon]
tys IfExtName
dfun OverlapFlag
flag IsOrphan
orph) = do
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfExtName
cls
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [Maybe IfaceTyCon]
tys
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfExtName
dfun
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh OverlapFlag
flag
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IsOrphan
orph
    get :: BinHandle -> IO IfaceClsInst
get BinHandle
bh = do
        IfExtName
cls  <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [Maybe IfaceTyCon]
tys  <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        IfExtName
dfun <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        OverlapFlag
flag <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        IsOrphan
orph <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        forall (m :: * -> *) a. Monad m => a -> m a
return (IfExtName
-> [Maybe IfaceTyCon]
-> IfExtName
-> OverlapFlag
-> IsOrphan
-> IfaceClsInst
IfaceClsInst IfExtName
cls [Maybe IfaceTyCon]
tys IfExtName
dfun OverlapFlag
flag IsOrphan
orph)

instance Binary IfaceFamInst where
    put_ :: BinHandle -> IfaceFamInst -> IO ()
put_ BinHandle
bh (IfaceFamInst IfExtName
fam [Maybe IfaceTyCon]
tys IfExtName
name IsOrphan
orph) = do
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfExtName
fam
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [Maybe IfaceTyCon]
tys
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfExtName
name
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IsOrphan
orph
    get :: BinHandle -> IO IfaceFamInst
get BinHandle
bh = do
        IfExtName
fam      <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [Maybe IfaceTyCon]
tys      <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        IfExtName
name     <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        IsOrphan
orph     <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        forall (m :: * -> *) a. Monad m => a -> m a
return (IfExtName
-> [Maybe IfaceTyCon] -> IfExtName -> IsOrphan -> IfaceFamInst
IfaceFamInst IfExtName
fam [Maybe IfaceTyCon]
tys IfExtName
name IsOrphan
orph)

instance Binary IfaceRule where
    put_ :: BinHandle -> IfaceRule -> IO ()
put_ BinHandle
bh (IfaceRule IfLclName
a1 Activation
a2 [IfaceBndr]
a3 IfExtName
a4 [IfaceExpr]
a5 IfaceExpr
a6 Bool
a7 IsOrphan
a8) = do
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfLclName
a1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Activation
a2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceBndr]
a3
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfExtName
a4
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceExpr]
a5
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceExpr
a6
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
a7
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IsOrphan
a8
    get :: BinHandle -> IO IfaceRule
get BinHandle
bh = do
        IfLclName
a1 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        Activation
a2 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [IfaceBndr]
a3 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        IfExtName
a4 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [IfaceExpr]
a5 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        IfaceExpr
a6 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        Bool
a7 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        IsOrphan
a8 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        forall (m :: * -> *) a. Monad m => a -> m a
return (IfLclName
-> Activation
-> [IfaceBndr]
-> IfExtName
-> [IfaceExpr]
-> IfaceExpr
-> Bool
-> IsOrphan
-> IfaceRule
IfaceRule IfLclName
a1 Activation
a2 [IfaceBndr]
a3 IfExtName
a4 [IfaceExpr]
a5 IfaceExpr
a6 Bool
a7 IsOrphan
a8)

instance Binary IfaceAnnotation where
    put_ :: BinHandle -> IfaceAnnotation -> IO ()
put_ BinHandle
bh (IfaceAnnotation IfaceAnnTarget
a1 AnnPayload
a2) = do
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceAnnTarget
a1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh AnnPayload
a2
    get :: BinHandle -> IO IfaceAnnotation
get BinHandle
bh = do
        IfaceAnnTarget
a1 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        AnnPayload
a2 <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceAnnTarget -> AnnPayload -> IfaceAnnotation
IfaceAnnotation IfaceAnnTarget
a1 AnnPayload
a2)

instance Binary IfaceIdDetails where
    put_ :: BinHandle -> IfaceIdDetails -> IO ()
put_ BinHandle
bh IfaceIdDetails
IfVanillaId      = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
    put_ BinHandle
bh (IfRecSelId Either IfaceTyCon IfaceDecl
a Bool
b) = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Either IfaceTyCon IfaceDecl
a forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
b
    put_ BinHandle
bh (IfWorkerLikeId [CbvMark]
dmds) = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
2 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [CbvMark]
dmds
    put_ BinHandle
bh IfaceIdDetails
IfDFunId         = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
3
    get :: BinHandle -> IO IfaceIdDetails
get BinHandle
bh = do
        Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
h of
            Word8
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceIdDetails
IfVanillaId
            Word8
1 -> do { Either IfaceTyCon IfaceDecl
a <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh; Bool
b <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh; forall (m :: * -> *) a. Monad m => a -> m a
return (Either IfaceTyCon IfaceDecl -> Bool -> IfaceIdDetails
IfRecSelId Either IfaceTyCon IfaceDecl
a Bool
b) }
            Word8
2 -> do { [CbvMark]
dmds <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh; forall (m :: * -> *) a. Monad m => a -> m a
return ([CbvMark] -> IfaceIdDetails
IfWorkerLikeId [CbvMark]
dmds) }
            Word8
_ -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceIdDetails
IfDFunId

instance Binary IfaceInfoItem where
    put_ :: BinHandle -> IfaceInfoItem -> IO ()
put_ BinHandle
bh (HsArity Int
aa)          = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Int
aa
    put_ BinHandle
bh (HsDmdSig DmdSig
ab)         = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh DmdSig
ab
    put_ BinHandle
bh (HsUnfold Bool
lb IfaceUnfolding
ad)      = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
2 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
lb forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceUnfolding
ad
    put_ BinHandle
bh (HsInline InlinePragma
ad)         = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
3 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh InlinePragma
ad
    put_ BinHandle
bh IfaceInfoItem
HsNoCafRefs           = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
4
    put_ BinHandle
bh (HsCprSig CprSig
cpr)        = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
6 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh CprSig
cpr
    put_ BinHandle
bh (HsLFInfo IfaceLFInfo
lf_info)    = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
7 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceLFInfo
lf_info
    put_ BinHandle
bh (HsTagSig TagSig
sig)        = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
8 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh TagSig
sig

    get :: BinHandle -> IO IfaceInfoItem
get BinHandle
bh = do
        Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
h of
            Word8
0 -> forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Int -> IfaceInfoItem
HsArity forall a b. (a -> b) -> a -> b
$ forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
            Word8
1 -> forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM DmdSig -> IfaceInfoItem
HsDmdSig forall a b. (a -> b) -> a -> b
$ forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
            Word8
2 -> do Bool
lb <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceUnfolding
ad <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> IfaceUnfolding -> IfaceInfoItem
HsUnfold Bool
lb IfaceUnfolding
ad)
            Word8
3 -> forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM InlinePragma -> IfaceInfoItem
HsInline forall a b. (a -> b) -> a -> b
$ forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
            Word8
4 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceInfoItem
HsNoCafRefs
            Word8
6 -> CprSig -> IfaceInfoItem
HsCprSig forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
            Word8
7 -> IfaceLFInfo -> IfaceInfoItem
HsLFInfo forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
            Word8
_ -> TagSig -> IfaceInfoItem
HsTagSig forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh

instance Binary IfaceUnfolding where
    put_ :: BinHandle -> IfaceUnfolding -> IO ()
put_ BinHandle
bh (IfCoreUnfold UnfoldingSource
s IfUnfoldingCache
c IfGuidance
g IfaceExpr
e) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh UnfoldingSource
s
        BinHandle -> IfUnfoldingCache -> IO ()
putUnfoldingCache BinHandle
bh IfUnfoldingCache
c
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfGuidance
g
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceExpr
e
    put_ BinHandle
bh (IfDFunUnfold [IfaceBndr]
as [IfaceExpr]
bs) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceBndr]
as
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceExpr]
bs
    get :: BinHandle -> IO IfaceUnfolding
get BinHandle
bh = do
        Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
h of
            Word8
0 -> do UnfoldingSource
s <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfUnfoldingCache
c <- BinHandle -> IO IfUnfoldingCache
getUnfoldingCache BinHandle
bh
                    IfGuidance
g <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceExpr
e <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (UnfoldingSource
-> IfUnfoldingCache -> IfGuidance -> IfaceExpr -> IfaceUnfolding
IfCoreUnfold UnfoldingSource
s IfUnfoldingCache
c IfGuidance
g IfaceExpr
e)
            Word8
_ -> do [IfaceBndr]
as <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [IfaceExpr]
bs <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return ([IfaceBndr] -> [IfaceExpr] -> IfaceUnfolding
IfDFunUnfold [IfaceBndr]
as [IfaceExpr]
bs)

instance Binary IfGuidance where
    put_ :: BinHandle -> IfGuidance -> IO ()
put_ BinHandle
bh IfGuidance
IfNoGuidance = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
    put_ BinHandle
bh (IfWhen Int
a Bool
b Bool
c ) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Int
a
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
b
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
c
    get :: BinHandle -> IO IfGuidance
get BinHandle
bh = do
        Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
h of
            Word8
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfGuidance
IfNoGuidance
            Word8
_ -> do Int
a <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Bool
b <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Bool
c <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (Int -> Bool -> Bool -> IfGuidance
IfWhen Int
a Bool
b Bool
c)

putUnfoldingCache :: BinHandle -> IfUnfoldingCache -> IO ()
putUnfoldingCache :: BinHandle -> IfUnfoldingCache -> IO ()
putUnfoldingCache BinHandle
bh (UnfoldingCache { uf_is_value :: IfUnfoldingCache -> Bool
uf_is_value = Bool
hnf, uf_is_conlike :: IfUnfoldingCache -> Bool
uf_is_conlike = Bool
conlike
                                     , uf_is_work_free :: IfUnfoldingCache -> Bool
uf_is_work_free = Bool
wf, uf_expandable :: IfUnfoldingCache -> Bool
uf_expandable = Bool
exp }) = do
    let b :: Word8
b = forall a. Bits a => a
zeroBits forall a. Bits a => a -> Bool -> a
.<<|. Bool
hnf forall a. Bits a => a -> Bool -> a
.<<|. Bool
conlike forall a. Bits a => a -> Bool -> a
.<<|. Bool
wf forall a. Bits a => a -> Bool -> a
.<<|. Bool
exp
    BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
b

getUnfoldingCache :: BinHandle -> IO IfUnfoldingCache
getUnfoldingCache :: BinHandle -> IO IfUnfoldingCache
getUnfoldingCache BinHandle
bh = do
    Word8
b <- BinHandle -> IO Word8
getByte BinHandle
bh
    let hnf :: Bool
hnf     = forall a. Bits a => a -> Int -> Bool
testBit Word8
b Int
3
        conlike :: Bool
conlike = forall a. Bits a => a -> Int -> Bool
testBit Word8
b Int
2
        wf :: Bool
wf      = forall a. Bits a => a -> Int -> Bool
testBit Word8
b Int
1
        exp :: Bool
exp     = forall a. Bits a => a -> Int -> Bool
testBit Word8
b Int
0
    forall (m :: * -> *) a. Monad m => a -> m a
return (UnfoldingCache { uf_is_value :: Bool
uf_is_value = Bool
hnf, uf_is_conlike :: Bool
uf_is_conlike = Bool
conlike
                           , uf_is_work_free :: Bool
uf_is_work_free = Bool
wf, uf_expandable :: Bool
uf_expandable = Bool
exp })

infixl 9 .<<|.
(.<<|.) :: (Bits a) => a -> Bool -> a
a
x .<<|. :: forall a. Bits a => a -> Bool -> a
.<<|. Bool
b = (if Bool
b then (forall a. Bits a => a -> Int -> a
`setBit` Int
0) else forall a. a -> a
id) (a
x forall a. Bits a => a -> Int -> a
`shiftL` Int
1)

instance Binary IfaceAlt where
    put_ :: BinHandle -> IfaceAlt -> IO ()
put_ BinHandle
bh (IfaceAlt IfaceConAlt
a [IfLclName]
b IfaceExpr
c) = do
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceConAlt
a
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfLclName]
b
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceExpr
c
    get :: BinHandle -> IO IfaceAlt
get BinHandle
bh = do
        IfaceConAlt
a <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        [IfLclName]
b <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        IfaceExpr
c <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceConAlt -> [IfLclName] -> IfaceExpr -> IfaceAlt
IfaceAlt IfaceConAlt
a [IfLclName]
b IfaceExpr
c)

instance Binary IfaceExpr where
    put_ :: BinHandle -> IfaceExpr -> IO ()
put_ BinHandle
bh (IfaceLcl IfLclName
aa) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfLclName
aa
    put_ BinHandle
bh (IfaceType IfaceType
ab) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
ab
    put_ BinHandle
bh (IfaceCo IfaceCoercion
ab) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceCoercion
ab
    put_ BinHandle
bh (IfaceTuple TupleSort
ac [IfaceExpr]
ad) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
3
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh TupleSort
ac
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceExpr]
ad
    put_ BinHandle
bh (IfaceLam (IfaceBndr
ae, IfaceOneShot
os) IfaceExpr
af) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
4
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceBndr
ae
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceOneShot
os
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceExpr
af
    put_ BinHandle
bh (IfaceApp IfaceExpr
ag IfaceExpr
ah) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
5
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceExpr
ag
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceExpr
ah
    put_ BinHandle
bh (IfaceCase IfaceExpr
ai IfLclName
aj [IfaceAlt]
ak) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
6
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceExpr
ai
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfLclName
aj
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfaceAlt]
ak
    put_ BinHandle
bh (IfaceLet IfaceBindingX IfaceExpr IfaceLetBndr
al IfaceExpr
am) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
7
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceBindingX IfaceExpr IfaceLetBndr
al
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceExpr
am
    put_ BinHandle
bh (IfaceTick IfaceTickish
an IfaceExpr
ao) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
8
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceTickish
an
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceExpr
ao
    put_ BinHandle
bh (IfaceLit Literal
ap) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
9
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Literal
ap
    put_ BinHandle
bh (IfaceFCall ForeignCall
as IfaceType
at) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
10
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh ForeignCall
as
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
at
    put_ BinHandle
bh (IfaceExt IfExtName
aa) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
11
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfExtName
aa
    put_ BinHandle
bh (IfaceCast IfaceExpr
ie IfaceCoercion
ico) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
12
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceExpr
ie
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceCoercion
ico
    put_ BinHandle
bh (IfaceECase IfaceExpr
a IfaceType
b) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
13
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceExpr
a
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
b
    put_ BinHandle
bh (IfaceLitRubbish TypeOrConstraint
TypeLike IfaceType
r) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
14
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
r
    put_ BinHandle
bh (IfaceLitRubbish TypeOrConstraint
ConstraintLike IfaceType
r) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
15
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
r
    get :: BinHandle -> IO IfaceExpr
get BinHandle
bh = do
        Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
h of
            Word8
0 -> do IfLclName
aa <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfLclName -> IfaceExpr
IfaceLcl IfLclName
aa)
            Word8
1 -> do IfaceType
ab <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceType -> IfaceExpr
IfaceType IfaceType
ab)
            Word8
2 -> do IfaceCoercion
ab <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceCoercion -> IfaceExpr
IfaceCo IfaceCoercion
ab)
            Word8
3 -> do TupleSort
ac <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [IfaceExpr]
ad <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (TupleSort -> [IfaceExpr] -> IfaceExpr
IfaceTuple TupleSort
ac [IfaceExpr]
ad)
            Word8
4 -> do IfaceBndr
ae <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceOneShot
os <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceExpr
af <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceLamBndr -> IfaceExpr -> IfaceExpr
IfaceLam (IfaceBndr
ae, IfaceOneShot
os) IfaceExpr
af)
            Word8
5 -> do IfaceExpr
ag <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceExpr
ah <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceExpr -> IfaceExpr -> IfaceExpr
IfaceApp IfaceExpr
ag IfaceExpr
ah)
            Word8
6 -> do IfaceExpr
ai <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfLclName
aj <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    [IfaceAlt]
ak <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceExpr -> IfLclName -> [IfaceAlt] -> IfaceExpr
IfaceCase IfaceExpr
ai IfLclName
aj [IfaceAlt]
ak)
            Word8
7 -> do IfaceBindingX IfaceExpr IfaceLetBndr
al <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceExpr
am <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceBindingX IfaceExpr IfaceLetBndr -> IfaceExpr -> IfaceExpr
IfaceLet IfaceBindingX IfaceExpr IfaceLetBndr
al IfaceExpr
am)
            Word8
8 -> do IfaceTickish
an <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    IfaceExpr
ao <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceTickish -> IfaceExpr -> IfaceExpr
IfaceTick IfaceTickish
an IfaceExpr
ao)
            Word8
9 -> do Literal
ap <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (Literal -> IfaceExpr
IfaceLit Literal
ap)
            Word8
10 -> do ForeignCall
as <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                     IfaceType
at <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                     forall (m :: * -> *) a. Monad m => a -> m a
return (ForeignCall -> IfaceType -> IfaceExpr
IfaceFCall ForeignCall
as IfaceType
at)
            Word8
11 -> do IfExtName
aa <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                     forall (m :: * -> *) a. Monad m => a -> m a
return (IfExtName -> IfaceExpr
IfaceExt IfExtName
aa)
            Word8
12 -> do IfaceExpr
ie <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                     IfaceCoercion
ico <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                     forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceExpr -> IfaceCoercion -> IfaceExpr
IfaceCast IfaceExpr
ie IfaceCoercion
ico)
            Word8
13 -> do IfaceExpr
a <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                     IfaceType
b <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                     forall (m :: * -> *) a. Monad m => a -> m a
return (IfaceExpr -> IfaceType -> IfaceExpr
IfaceECase IfaceExpr
a IfaceType
b)
            Word8
14 -> do IfaceType
r <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                     forall (m :: * -> *) a. Monad m => a -> m a
return (TypeOrConstraint -> IfaceType -> IfaceExpr
IfaceLitRubbish TypeOrConstraint
TypeLike IfaceType
r)
            Word8
15 -> do IfaceType
r <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                     forall (m :: * -> *) a. Monad m => a -> m a
return (TypeOrConstraint -> IfaceType -> IfaceExpr
IfaceLitRubbish TypeOrConstraint
ConstraintLike IfaceType
r)
            Word8
_ -> forall a. HasCallStack => String -> a
panic (String
"get IfaceExpr " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Word8
h)

instance Binary IfaceTickish where
    put_ :: BinHandle -> IfaceTickish -> IO ()
put_ BinHandle
bh (IfaceHpcTick Module
m Int
ix) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Module
m
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Int
ix
    put_ BinHandle
bh (IfaceSCC CostCentre
cc Bool
tick Bool
push) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh CostCentre
cc
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
tick
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Bool
push
    put_ BinHandle
bh (IfaceSource RealSrcSpan
src String
name) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
2
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh (RealSrcSpan -> IfLclName
srcSpanFile RealSrcSpan
src)
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh (RealSrcSpan -> Int
srcSpanStartLine RealSrcSpan
src)
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh (RealSrcSpan -> Int
srcSpanStartCol RealSrcSpan
src)
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh (RealSrcSpan -> Int
srcSpanEndLine RealSrcSpan
src)
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh (RealSrcSpan -> Int
srcSpanEndCol RealSrcSpan
src)
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh String
name

    get :: BinHandle -> IO IfaceTickish
get BinHandle
bh = do
        Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
h of
            Word8
0 -> do Module
m <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Int
ix <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (Module -> Int -> IfaceTickish
IfaceHpcTick Module
m Int
ix)
            Word8
1 -> do CostCentre
cc <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Bool
tick <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Bool
push <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (CostCentre -> Bool -> Bool -> IfaceTickish
IfaceSCC CostCentre
cc Bool
tick Bool
push)
            Word8
2 -> do IfLclName
file <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Int
sl <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Int
sc <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Int
el <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    Int
ec <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    let start :: RealSrcLoc
start = IfLclName -> Int -> Int -> RealSrcLoc
mkRealSrcLoc IfLclName
file Int
sl Int
sc
                        end :: RealSrcLoc
end = IfLclName -> Int -> Int -> RealSrcLoc
mkRealSrcLoc IfLclName
file Int
el Int
ec
                    String
name <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                    forall (m :: * -> *) a. Monad m => a -> m a
return (RealSrcSpan -> String -> IfaceTickish
IfaceSource (RealSrcLoc -> RealSrcLoc -> RealSrcSpan
mkRealSrcSpan RealSrcLoc
start RealSrcLoc
end) String
name)
            Word8
_ -> forall a. HasCallStack => String -> a
panic (String
"get IfaceTickish " forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show Word8
h)

instance Binary IfaceConAlt where
    put_ :: BinHandle -> IfaceConAlt -> IO ()
put_ BinHandle
bh IfaceConAlt
IfaceDefault      = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
    put_ BinHandle
bh (IfaceDataAlt IfExtName
aa) = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfExtName
aa
    put_ BinHandle
bh (IfaceLitAlt Literal
ac)  = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
2 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Literal
ac
    get :: BinHandle -> IO IfaceConAlt
get BinHandle
bh = do
        Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
h of
            Word8
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceConAlt
IfaceDefault
            Word8
1 -> forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM IfExtName -> IfaceConAlt
IfaceDataAlt forall a b. (a -> b) -> a -> b
$ forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
            Word8
_ -> forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Literal -> IfaceConAlt
IfaceLitAlt  forall a b. (a -> b) -> a -> b
$ forall a. Binary a => BinHandle -> IO a
get BinHandle
bh

instance (Binary r, Binary b) => Binary (IfaceBindingX b r) where
    put_ :: BinHandle -> IfaceBindingX b r -> IO ()
put_ BinHandle
bh (IfaceNonRec r
aa b
ab) = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh r
aa forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh b
ab
    put_ BinHandle
bh (IfaceRec [(r, b)]
ac)       = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1 forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [(r, b)]
ac
    get :: BinHandle -> IO (IfaceBindingX b r)
get BinHandle
bh = do
        Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
h of
            Word8
0 -> do { r
aa <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh; b
ab <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh; forall (m :: * -> *) a. Monad m => a -> m a
return (forall r b. b -> r -> IfaceBindingX r b
IfaceNonRec r
aa b
ab) }
            Word8
_ -> do { [(r, b)]
ac <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh; forall (m :: * -> *) a. Monad m => a -> m a
return (forall r b. [(b, r)] -> IfaceBindingX r b
IfaceRec [(r, b)]
ac) }

instance Binary IfaceLetBndr where
    put_ :: BinHandle -> IfaceLetBndr -> IO ()
put_ BinHandle
bh (IfLetBndr IfLclName
a IfaceType
b IfaceIdInfo
c IfaceJoinInfo
d) = do
            forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfLclName
a
            forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
b
            forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceIdInfo
c
            forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceJoinInfo
d
    get :: BinHandle -> IO IfaceLetBndr
get BinHandle
bh = do IfLclName
a <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                IfaceType
b <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                IfaceIdInfo
c <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                IfaceJoinInfo
d <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                forall (m :: * -> *) a. Monad m => a -> m a
return (IfLclName
-> IfaceType -> IfaceIdInfo -> IfaceJoinInfo -> IfaceLetBndr
IfLetBndr IfLclName
a IfaceType
b IfaceIdInfo
c IfaceJoinInfo
d)

instance Binary IfaceTopBndrInfo where
    put_ :: BinHandle -> IfaceTopBndrInfo -> IO ()
put_ BinHandle
bh (IfLclTopBndr IfLclName
lcl IfaceType
ty IfaceIdInfo
info IfaceIdDetails
dets) = do
            BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
            forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfLclName
lcl
            forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceType
ty
            forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceIdInfo
info
            forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceIdDetails
dets
    put_ BinHandle
bh (IfGblTopBndr IfExtName
gbl) = do
            BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
            forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfExtName
gbl
    get :: BinHandle -> IO IfaceTopBndrInfo
get BinHandle
bh = do
      Word8
tag <- BinHandle -> IO Word8
getByte BinHandle
bh
      case Word8
tag of
        Word8
0 -> IfLclName
-> IfaceType -> IfaceIdInfo -> IfaceIdDetails -> IfaceTopBndrInfo
IfLclTopBndr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        Word8
1 -> IfExtName -> IfaceTopBndrInfo
IfGblTopBndr forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
        Word8
_ -> forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"IfaceTopBndrInfo" (forall a. Integral a => a -> SDoc
intWithCommas Word8
tag)

instance Binary IfaceMaybeRhs where
  put_ :: BinHandle -> IfaceMaybeRhs -> IO ()
put_ BinHandle
bh IfaceMaybeRhs
IfUseUnfoldingRhs = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
  put_ BinHandle
bh (IfRhs IfaceExpr
e) = do
    BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
    forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceExpr
e

  get :: BinHandle -> IO IfaceMaybeRhs
get BinHandle
bh = do
    Word8
b <- BinHandle -> IO Word8
getByte BinHandle
bh
    case Word8
b of
      Word8
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceMaybeRhs
IfUseUnfoldingRhs
      Word8
1 -> IfaceExpr -> IfaceMaybeRhs
IfRhs forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
      Word8
_ -> forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"IfaceMaybeRhs" (forall a. Integral a => a -> SDoc
intWithCommas Word8
b)



instance Binary IfaceJoinInfo where
    put_ :: BinHandle -> IfaceJoinInfo -> IO ()
put_ BinHandle
bh IfaceJoinInfo
IfaceNotJoinPoint = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
    put_ BinHandle
bh (IfaceJoinPoint Int
ar) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Int
ar
    get :: BinHandle -> IO IfaceJoinInfo
get BinHandle
bh = do
        Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
h of
            Word8
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceJoinInfo
IfaceNotJoinPoint
            Word8
_ -> forall (m :: * -> *) a1 r. Monad m => (a1 -> r) -> m a1 -> m r
liftM Int -> IfaceJoinInfo
IfaceJoinPoint forall a b. (a -> b) -> a -> b
$ forall a. Binary a => BinHandle -> IO a
get BinHandle
bh

instance Binary IfaceTyConParent where
    put_ :: BinHandle -> IfaceTyConParent -> IO ()
put_ BinHandle
bh IfaceTyConParent
IfNoParent = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
    put_ BinHandle
bh (IfDataInstance IfExtName
ax IfaceTyCon
pr IfaceAppArgs
ty) = do
        BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfExtName
ax
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceTyCon
pr
        forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh IfaceAppArgs
ty
    get :: BinHandle -> IO IfaceTyConParent
get BinHandle
bh = do
        Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
        case Word8
h of
            Word8
0 -> forall (m :: * -> *) a. Monad m => a -> m a
return IfaceTyConParent
IfNoParent
            Word8
_ -> do
                IfExtName
ax <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                IfaceTyCon
pr <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                IfaceAppArgs
ty <- forall a. Binary a => BinHandle -> IO a
get BinHandle
bh
                forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ IfExtName -> IfaceTyCon -> IfaceAppArgs -> IfaceTyConParent
IfDataInstance IfExtName
ax IfaceTyCon
pr IfaceAppArgs
ty

instance Binary IfaceCompleteMatch where
  put_ :: BinHandle -> IfaceCompleteMatch -> IO ()
put_ BinHandle
bh (IfaceCompleteMatch [IfExtName]
cs Maybe IfaceTyCon
mtc) = forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh [IfExtName]
cs forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh Maybe IfaceTyCon
mtc
  get :: BinHandle -> IO IfaceCompleteMatch
get BinHandle
bh = [IfExtName] -> Maybe IfaceTyCon -> IfaceCompleteMatch
IfaceCompleteMatch forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> forall a. Binary a => BinHandle -> IO a
get BinHandle
bh


{-
************************************************************************
*                                                                      *
                NFData instances
   See Note [Avoiding space leaks in toIface*] in GHC.CoreToIface
*                                                                      *
************************************************************************
-}

instance NFData IfaceDecl where
  rnf :: IfaceDecl -> ()
rnf = \case
    IfaceId IfExtName
f1 IfaceType
f2 IfaceIdDetails
f3 IfaceIdInfo
f4 ->
      forall a. NFData a => a -> ()
rnf IfExtName
f1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceType
f2 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceIdDetails
f3 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceIdInfo
f4

    IfaceData IfExtName
f1 [IfaceTyConBinder]
f2 IfaceType
f3 Maybe CType
f4 [Role]
f5 IfaceContext
f6 IfaceConDecls
f7 Bool
f8 IfaceTyConParent
f9 ->
      IfExtName
f1 seq :: forall a b. a -> b -> b
`seq` forall a b. [a] -> b -> b
seqList [IfaceTyConBinder]
f2 seq :: forall a b. a -> b -> b
`seq` IfaceType
f3 seq :: forall a b. a -> b -> b
`seq` Maybe CType
f4 seq :: forall a b. a -> b -> b
`seq` [Role]
f5 seq :: forall a b. a -> b -> b
`seq`
      forall a. NFData a => a -> ()
rnf IfaceContext
f6 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceConDecls
f7 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Bool
f8 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceTyConParent
f9

    IfaceSynonym IfExtName
f1 [Role]
f2 [IfaceTyConBinder]
f3 IfaceType
f4 IfaceType
f5 ->
      forall a. NFData a => a -> ()
rnf IfExtName
f1 seq :: forall a b. a -> b -> b
`seq` [Role]
f2 seq :: forall a b. a -> b -> b
`seq` forall a b. [a] -> b -> b
seqList [IfaceTyConBinder]
f3 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceType
f4 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceType
f5

    IfaceFamily IfExtName
f1 Maybe IfLclName
f2 [IfaceTyConBinder]
f3 IfaceType
f4 IfaceFamTyConFlav
f5 Injectivity
f6 ->
      forall a. NFData a => a -> ()
rnf IfExtName
f1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Maybe IfLclName
f2 seq :: forall a b. a -> b -> b
`seq` forall a b. [a] -> b -> b
seqList [IfaceTyConBinder]
f3 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceType
f4 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceFamTyConFlav
f5 seq :: forall a b. a -> b -> b
`seq` Injectivity
f6 seq :: forall a b. a -> b -> b
`seq` ()

    IfaceClass IfExtName
f1 [Role]
f2 [IfaceTyConBinder]
f3 [FunDep IfLclName]
f4 IfaceClassBody
f5 ->
      forall a. NFData a => a -> ()
rnf IfExtName
f1 seq :: forall a b. a -> b -> b
`seq` [Role]
f2 seq :: forall a b. a -> b -> b
`seq` forall a b. [a] -> b -> b
seqList [IfaceTyConBinder]
f3 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [FunDep IfLclName]
f4 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceClassBody
f5

    IfaceAxiom IfExtName
nm IfaceTyCon
tycon Role
role [IfaceAxBranch]
ax ->
      forall a. NFData a => a -> ()
rnf IfExtName
nm seq :: forall a b. a -> b -> b
`seq`
      forall a. NFData a => a -> ()
rnf IfaceTyCon
tycon seq :: forall a b. a -> b -> b
`seq`
      Role
role seq :: forall a b. a -> b -> b
`seq`
      forall a. NFData a => a -> ()
rnf [IfaceAxBranch]
ax

    IfacePatSyn IfExtName
f1 Bool
f2 (IfExtName, Bool)
f3 Maybe (IfExtName, Bool)
f4 [IfaceForAllSpecBndr]
f5 [IfaceForAllSpecBndr]
f6 IfaceContext
f7 IfaceContext
f8 IfaceContext
f9 IfaceType
f10 [FieldLabel]
f11 ->
      forall a. NFData a => a -> ()
rnf IfExtName
f1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Bool
f2 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf (IfExtName, Bool)
f3 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Maybe (IfExtName, Bool)
f4 seq :: forall a b. a -> b -> b
`seq` [IfaceForAllSpecBndr]
f5 seq :: forall a b. a -> b -> b
`seq` [IfaceForAllSpecBndr]
f6 seq :: forall a b. a -> b -> b
`seq`
      forall a. NFData a => a -> ()
rnf IfaceContext
f7 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceContext
f8 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceContext
f9 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceType
f10 seq :: forall a b. a -> b -> b
`seq` [FieldLabel]
f11 seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceAxBranch where
  rnf :: IfaceAxBranch -> ()
rnf (IfaceAxBranch [IfaceTvBndr]
f1 [IfaceTvBndr]
f2 [IfaceIdBndr]
f3 IfaceAppArgs
f4 [Role]
f5 IfaceType
f6 [Int]
f7) =
    forall a. NFData a => a -> ()
rnf [IfaceTvBndr]
f1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceTvBndr]
f2 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceIdBndr]
f3 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceAppArgs
f4 seq :: forall a b. a -> b -> b
`seq` [Role]
f5 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceType
f6 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [Int]
f7

instance NFData IfaceClassBody where
  rnf :: IfaceClassBody -> ()
rnf = \case
    IfaceClassBody
IfAbstractClass -> ()
    IfConcreteClass IfaceContext
f1 [IfaceAT]
f2 [IfaceClassOp]
f3 BooleanFormula IfLclName
f4 -> forall a. NFData a => a -> ()
rnf IfaceContext
f1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceAT]
f2 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceClassOp]
f3 seq :: forall a b. a -> b -> b
`seq` BooleanFormula IfLclName
f4 seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceAT where
  rnf :: IfaceAT -> ()
rnf (IfaceAT IfaceDecl
f1 Maybe IfaceType
f2) = forall a. NFData a => a -> ()
rnf IfaceDecl
f1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Maybe IfaceType
f2

instance NFData IfaceClassOp where
  rnf :: IfaceClassOp -> ()
rnf (IfaceClassOp IfExtName
f1 IfaceType
f2 Maybe (DefMethSpec IfaceType)
f3) = forall a. NFData a => a -> ()
rnf IfExtName
f1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceType
f2 seq :: forall a b. a -> b -> b
`seq` Maybe (DefMethSpec IfaceType)
f3 seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceTyConParent where
  rnf :: IfaceTyConParent -> ()
rnf = \case
    IfaceTyConParent
IfNoParent -> ()
    IfDataInstance IfExtName
f1 IfaceTyCon
f2 IfaceAppArgs
f3 -> forall a. NFData a => a -> ()
rnf IfExtName
f1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceTyCon
f2 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceAppArgs
f3

instance NFData IfaceConDecls where
  rnf :: IfaceConDecls -> ()
rnf = \case
    IfaceConDecls
IfAbstractTyCon -> ()
    IfDataTyCon Bool
_ [IfaceConDecl]
f1 -> forall a. NFData a => a -> ()
rnf [IfaceConDecl]
f1
    IfNewTyCon IfaceConDecl
f1 -> forall a. NFData a => a -> ()
rnf IfaceConDecl
f1

instance NFData IfaceConDecl where
  rnf :: IfaceConDecl -> ()
rnf (IfCon IfExtName
f1 Bool
f2 Bool
f3 [IfaceBndr]
f4 [IfaceForAllSpecBndr]
f5 [IfaceTvBndr]
f6 IfaceContext
f7 [(IfaceType, IfaceType)]
f8 [FieldLabel]
f9 [IfaceBang]
f10 [IfaceSrcBang]
f11) =
    forall a. NFData a => a -> ()
rnf IfExtName
f1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Bool
f2 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Bool
f3 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceBndr]
f4 seq :: forall a b. a -> b -> b
`seq` [IfaceForAllSpecBndr]
f5 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceTvBndr]
f6 seq :: forall a b. a -> b -> b
`seq`
    forall a. NFData a => a -> ()
rnf IfaceContext
f7 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [(IfaceType, IfaceType)]
f8 seq :: forall a b. a -> b -> b
`seq` [FieldLabel]
f9 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceBang]
f10 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceSrcBang]
f11

instance NFData IfaceSrcBang where
  rnf :: IfaceSrcBang -> ()
rnf (IfSrcBang SrcUnpackedness
f1 SrcStrictness
f2) = SrcUnpackedness
f1 seq :: forall a b. a -> b -> b
`seq` SrcStrictness
f2 seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceBang where
  rnf :: IfaceBang -> ()
rnf IfaceBang
x = IfaceBang
x seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceIdDetails where
  rnf :: IfaceIdDetails -> ()
rnf = \case
    IfaceIdDetails
IfVanillaId -> ()
    IfWorkerLikeId [CbvMark]
dmds -> [CbvMark]
dmds forall a b. [a] -> b -> b
`seqList` ()
    IfRecSelId (Left IfaceTyCon
tycon) Bool
b -> forall a. NFData a => a -> ()
rnf IfaceTyCon
tycon seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Bool
b
    IfRecSelId (Right IfaceDecl
decl) Bool
b -> forall a. NFData a => a -> ()
rnf IfaceDecl
decl seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Bool
b
    IfaceIdDetails
IfDFunId -> ()

instance NFData IfaceInfoItem where
  rnf :: IfaceInfoItem -> ()
rnf = \case
    HsArity Int
a -> forall a. NFData a => a -> ()
rnf Int
a
    HsDmdSig DmdSig
str -> DmdSig -> ()
seqDmdSig DmdSig
str
    HsInline InlinePragma
p -> InlinePragma
p seq :: forall a b. a -> b -> b
`seq` () -- TODO: seq further?
    HsUnfold Bool
b IfaceUnfolding
unf -> forall a. NFData a => a -> ()
rnf Bool
b seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceUnfolding
unf
    IfaceInfoItem
HsNoCafRefs -> ()
    HsCprSig CprSig
cpr -> CprSig
cpr seq :: forall a b. a -> b -> b
`seq` ()
    HsLFInfo IfaceLFInfo
lf_info -> IfaceLFInfo
lf_info seq :: forall a b. a -> b -> b
`seq` () -- TODO: seq further?
    HsTagSig TagSig
sig -> TagSig
sig seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfGuidance where
  rnf :: IfGuidance -> ()
rnf = \case
    IfGuidance
IfNoGuidance -> ()
    IfWhen Int
a Bool
b Bool
c -> Int
a seq :: forall a b. a -> b -> b
`seq` Bool
b seq :: forall a b. a -> b -> b
`seq` Bool
c seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceUnfolding where
  rnf :: IfaceUnfolding -> ()
rnf = \case
    IfCoreUnfold UnfoldingSource
src IfUnfoldingCache
cache IfGuidance
guidance IfaceExpr
expr -> UnfoldingSource
src seq :: forall a b. a -> b -> b
`seq` IfUnfoldingCache
cache seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfGuidance
guidance seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceExpr
expr
    IfDFunUnfold [IfaceBndr]
bndrs [IfaceExpr]
exprs             -> forall a. NFData a => a -> ()
rnf [IfaceBndr]
bndrs seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceExpr]
exprs
    -- See Note [UnfoldingCache] in GHC.Core for why it suffices to merely `seq` on cache

instance NFData IfaceExpr where
  rnf :: IfaceExpr -> ()
rnf = \case
    IfaceLcl IfLclName
nm -> forall a. NFData a => a -> ()
rnf IfLclName
nm
    IfaceExt IfExtName
nm -> forall a. NFData a => a -> ()
rnf IfExtName
nm
    IfaceType IfaceType
ty -> forall a. NFData a => a -> ()
rnf IfaceType
ty
    IfaceCo IfaceCoercion
co -> forall a. NFData a => a -> ()
rnf IfaceCoercion
co
    IfaceTuple TupleSort
sort [IfaceExpr]
exprs -> TupleSort
sort seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceExpr]
exprs
    IfaceLam IfaceLamBndr
bndr IfaceExpr
expr -> forall a. NFData a => a -> ()
rnf IfaceLamBndr
bndr seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceExpr
expr
    IfaceApp IfaceExpr
e1 IfaceExpr
e2 -> forall a. NFData a => a -> ()
rnf IfaceExpr
e1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceExpr
e2
    IfaceCase IfaceExpr
e IfLclName
nm [IfaceAlt]
alts -> forall a. NFData a => a -> ()
rnf IfaceExpr
e seq :: forall a b. a -> b -> b
`seq` IfLclName
nm seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceAlt]
alts
    IfaceECase IfaceExpr
e IfaceType
ty -> forall a. NFData a => a -> ()
rnf IfaceExpr
e seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceType
ty
    IfaceLet IfaceBindingX IfaceExpr IfaceLetBndr
bind IfaceExpr
e -> forall a. NFData a => a -> ()
rnf IfaceBindingX IfaceExpr IfaceLetBndr
bind seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceExpr
e
    IfaceCast IfaceExpr
e IfaceCoercion
co -> forall a. NFData a => a -> ()
rnf IfaceExpr
e seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceCoercion
co
    IfaceLit Literal
l -> Literal
l seq :: forall a b. a -> b -> b
`seq` () -- FIXME
    IfaceLitRubbish TypeOrConstraint
tc IfaceType
r -> TypeOrConstraint
tc seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceType
r seq :: forall a b. a -> b -> b
`seq` ()
    IfaceFCall ForeignCall
fc IfaceType
ty -> ForeignCall
fc seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceType
ty
    IfaceTick IfaceTickish
tick IfaceExpr
e -> forall a. NFData a => a -> ()
rnf IfaceTickish
tick seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceExpr
e

instance NFData IfaceAlt where
  rnf :: IfaceAlt -> ()
rnf (IfaceAlt IfaceConAlt
con [IfLclName]
bndrs IfaceExpr
rhs) = forall a. NFData a => a -> ()
rnf IfaceConAlt
con seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfLclName]
bndrs seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceExpr
rhs

instance (NFData b, NFData a) => NFData (IfaceBindingX a b) where
  rnf :: IfaceBindingX a b -> ()
rnf = \case
    IfaceNonRec b
bndr a
e -> forall a. NFData a => a -> ()
rnf b
bndr seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf a
e
    IfaceRec [(b, a)]
binds -> forall a. NFData a => a -> ()
rnf [(b, a)]
binds

instance NFData IfaceTopBndrInfo where
  rnf :: IfaceTopBndrInfo -> ()
rnf (IfGblTopBndr IfExtName
n) = IfExtName
n seq :: forall a b. a -> b -> b
`seq` ()
  rnf (IfLclTopBndr IfLclName
fs IfaceType
ty IfaceIdInfo
info IfaceIdDetails
dets) = forall a. NFData a => a -> ()
rnf IfLclName
fs seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceType
ty seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceIdInfo
info seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceIdDetails
dets seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceMaybeRhs where
  rnf :: IfaceMaybeRhs -> ()
rnf IfaceMaybeRhs
IfUseUnfoldingRhs = ()
  rnf (IfRhs IfaceExpr
ce) = forall a. NFData a => a -> ()
rnf IfaceExpr
ce seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceLetBndr where
  rnf :: IfaceLetBndr -> ()
rnf (IfLetBndr IfLclName
nm IfaceType
ty IfaceIdInfo
id_info IfaceJoinInfo
join_info) =
    forall a. NFData a => a -> ()
rnf IfLclName
nm seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceType
ty seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceIdInfo
id_info seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceJoinInfo
join_info

instance NFData IfaceFamTyConFlav where
  rnf :: IfaceFamTyConFlav -> ()
rnf = \case
    IfaceFamTyConFlav
IfaceDataFamilyTyCon -> ()
    IfaceFamTyConFlav
IfaceOpenSynFamilyTyCon -> ()
    IfaceClosedSynFamilyTyCon Maybe (IfExtName, [IfaceAxBranch])
f1 -> forall a. NFData a => a -> ()
rnf Maybe (IfExtName, [IfaceAxBranch])
f1
    IfaceFamTyConFlav
IfaceAbstractClosedSynFamilyTyCon -> ()
    IfaceFamTyConFlav
IfaceBuiltInSynFamTyCon -> ()

instance NFData IfaceJoinInfo where
  rnf :: IfaceJoinInfo -> ()
rnf IfaceJoinInfo
x = IfaceJoinInfo
x seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceTickish where
  rnf :: IfaceTickish -> ()
rnf = \case
    IfaceHpcTick Module
m Int
i -> forall a. NFData a => a -> ()
rnf Module
m seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Int
i
    IfaceSCC CostCentre
cc Bool
b1 Bool
b2 -> CostCentre
cc seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Bool
b1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Bool
b2
    IfaceSource RealSrcSpan
src String
str -> RealSrcSpan
src seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf String
str

instance NFData IfaceConAlt where
  rnf :: IfaceConAlt -> ()
rnf = \case
    IfaceConAlt
IfaceDefault -> ()
    IfaceDataAlt IfExtName
nm -> forall a. NFData a => a -> ()
rnf IfExtName
nm
    IfaceLitAlt Literal
lit -> Literal
lit seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceCompleteMatch where
  rnf :: IfaceCompleteMatch -> ()
rnf (IfaceCompleteMatch [IfExtName]
f1 Maybe IfaceTyCon
mtc) = forall a. NFData a => a -> ()
rnf [IfExtName]
f1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Maybe IfaceTyCon
mtc

instance NFData IfaceRule where
  rnf :: IfaceRule -> ()
rnf (IfaceRule IfLclName
f1 Activation
f2 [IfaceBndr]
f3 IfExtName
f4 [IfaceExpr]
f5 IfaceExpr
f6 Bool
f7 IsOrphan
f8) =
    forall a. NFData a => a -> ()
rnf IfLclName
f1 seq :: forall a b. a -> b -> b
`seq` Activation
f2 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceBndr]
f3 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfExtName
f4 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [IfaceExpr]
f5 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfaceExpr
f6 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf Bool
f7 seq :: forall a b. a -> b -> b
`seq` IsOrphan
f8 seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceFamInst where
  rnf :: IfaceFamInst -> ()
rnf (IfaceFamInst IfExtName
f1 [Maybe IfaceTyCon]
f2 IfExtName
f3 IsOrphan
f4) =
    forall a. NFData a => a -> ()
rnf IfExtName
f1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [Maybe IfaceTyCon]
f2 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfExtName
f3 seq :: forall a b. a -> b -> b
`seq` IsOrphan
f4 seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceClsInst where
  rnf :: IfaceClsInst -> ()
rnf (IfaceClsInst IfExtName
f1 [Maybe IfaceTyCon]
f2 IfExtName
f3 OverlapFlag
f4 IsOrphan
f5) =
    IfExtName
f1 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf [Maybe IfaceTyCon]
f2 seq :: forall a b. a -> b -> b
`seq` forall a. NFData a => a -> ()
rnf IfExtName
f3 seq :: forall a b. a -> b -> b
`seq` OverlapFlag
f4 seq :: forall a b. a -> b -> b
`seq` IsOrphan
f5 seq :: forall a b. a -> b -> b
`seq` ()

instance NFData IfaceAnnotation where
  rnf :: IfaceAnnotation -> ()
rnf (IfaceAnnotation IfaceAnnTarget
f1 AnnPayload
f2) = IfaceAnnTarget
f1 seq :: forall a b. a -> b -> b
`seq` AnnPayload
f2 seq :: forall a b. a -> b -> b
`seq` ()