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

\section{@Vars@: Variables}
-}

{-# LANGUAGE CPP, FlexibleContexts, MultiWayIf, FlexibleInstances, DeriveDataTypeable #-}

-- |
-- #name_types#
-- GHC uses several kinds of name internally:
--
-- * 'OccName.OccName': see "OccName#name_types"
--
-- * 'RdrName.RdrName': see "RdrName#name_types"
--
-- * 'Name.Name': see "Name#name_types"
--
-- * 'Id.Id': see "Id#name_types"
--
-- * 'Var.Var' is a synonym for the 'Id.Id' type but it may additionally
--   potentially contain type variables, which have a 'TyCoRep.Kind'
--   rather than a 'TyCoRep.Type' and only contain some extra
--   details during typechecking.
--
--   These 'Var.Var' names may either be global or local, see "Var#globalvslocal"
--
-- #globalvslocal#
-- Global 'Id's and 'Var's are those that are imported or correspond
--    to a data constructor, primitive operation, or record selectors.
-- Local 'Id's and 'Var's are those bound within an expression
--    (e.g. by a lambda) or at the top level of the module being compiled.

module Var (
        -- * The main data type and synonyms
        Var, CoVar, Id, NcId, DictId, DFunId, EvVar, EqVar, EvId, IpId, JoinId,
        TyVar, TcTyVar, TypeVar, KindVar, TKVar, TyCoVar,

        -- * In and Out variants
        InVar,  InCoVar,  InId,  InTyVar,
        OutVar, OutCoVar, OutId, OutTyVar,

        -- ** Taking 'Var's apart
        varName, varUnique, varType,

        -- ** Modifying 'Var's
        setVarName, setVarUnique, setVarType, updateVarType,
        updateVarTypeM,

        -- ** Constructing, taking apart, modifying 'Id's
        mkGlobalVar, mkLocalVar, mkExportedLocalVar, mkCoVar,
        idInfo, idDetails,
        lazySetIdInfo, setIdDetails, globaliseId,
        setIdExported, setIdNotExported,

        -- ** Predicates
        isId, isTyVar, isTcTyVar,
        isLocalVar, isLocalId, isCoVar, isNonCoVarId, isTyCoVar,
        isGlobalId, isExportedId,
        mustHaveLocalBinding,

        -- * ArgFlags
        ArgFlag(..), isVisibleArgFlag, isInvisibleArgFlag, sameVis,
        AnonArgFlag(..), ForallVisFlag(..), argToForallVisFlag,

        -- * TyVar's
        VarBndr(..), TyCoVarBinder, TyVarBinder,
        binderVar, binderVars, binderArgFlag, binderType,
        mkTyCoVarBinder, mkTyCoVarBinders,
        mkTyVarBinder, mkTyVarBinders,
        isTyVarBinder,

        -- ** Constructing TyVar's
        mkTyVar, mkTcTyVar,

        -- ** Taking 'TyVar's apart
        tyVarName, tyVarKind, tcTyVarDetails, setTcTyVarDetails,

        -- ** Modifying 'TyVar's
        setTyVarName, setTyVarUnique, setTyVarKind, updateTyVarKind,
        updateTyVarKindM,

        nonDetCmpVar

    ) where

#include "GhclibHsVersions.h"

import GhcPrelude

import {-# SOURCE #-}   TyCoRep( Type, Kind )
import {-# SOURCE #-}   TyCoPpr( pprKind )
import {-# SOURCE #-}   TcType( TcTyVarDetails, pprTcTyVarDetails, vanillaSkolemTv )
import {-# SOURCE #-}   IdInfo( IdDetails, IdInfo, coVarDetails, isCoVarDetails,
                                vanillaIdInfo, pprIdDetails )

import Name hiding (varName)
import Unique ( Uniquable, Unique, getKey, getUnique
              , mkUniqueGrimily, nonDetCmpUnique )
import Util
import Binary
import DynFlags
import Outputable

import Data.Data

{-
************************************************************************
*                                                                      *
                     Synonyms
*                                                                      *
************************************************************************
-- These synonyms are here and not in Id because otherwise we need a very
-- large number of SOURCE imports of Id.hs :-(
-}

-- | Identifier
type Id    = Var       -- A term-level identifier
                       --  predicate: isId

-- | Coercion Variable
type CoVar = Id        -- See Note [Evidence: EvIds and CoVars]
                       --   predicate: isCoVar

-- |
type NcId  = Id        -- A term-level (value) variable that is
                       -- /not/ an (unlifted) coercion
                       --    predicate: isNonCoVarId

-- | Type or kind Variable
type TyVar   = Var     -- Type *or* kind variable (historical)

-- | Type or Kind Variable
type TKVar   = Var     -- Type *or* kind variable (historical)

-- | Type variable that might be a metavariable
type TcTyVar = Var

-- | Type Variable
type TypeVar = Var     -- Definitely a type variable

-- | Kind Variable
type KindVar = Var     -- Definitely a kind variable
                       -- See Note [Kind and type variables]

-- See Note [Evidence: EvIds and CoVars]
-- | Evidence Identifier
type EvId   = Id        -- Term-level evidence: DictId, IpId, or EqVar

-- | Evidence Variable
type EvVar  = EvId      -- ...historical name for EvId

-- | Dictionary Function Identifier
type DFunId = Id        -- A dictionary function

-- | Dictionary Identifier
type DictId = EvId      -- A dictionary variable

-- | Implicit parameter Identifier
type IpId   = EvId      -- A term-level implicit parameter

-- | Equality Variable
type EqVar  = EvId      -- Boxed equality evidence
type JoinId = Id        -- A join variable

-- | Type or Coercion Variable
type TyCoVar = Id       -- Type, *or* coercion variable
                        --   predicate: isTyCoVar


{- Many passes apply a substitution, and it's very handy to have type
   synonyms to remind us whether or not the substitution has been applied -}

type InVar      = Var
type InTyVar    = TyVar
type InCoVar    = CoVar
type InId       = Id
type OutVar     = Var
type OutTyVar   = TyVar
type OutCoVar   = CoVar
type OutId      = Id



{- Note [Evidence: EvIds and CoVars]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
* An EvId (evidence Id) is a term-level evidence variable
  (dictionary, implicit parameter, or equality). Could be boxed or unboxed.

* DictId, IpId, and EqVar are synonyms when we know what kind of
  evidence we are talking about.  For example, an EqVar has type (t1 ~ t2).

* A CoVar is always an un-lifted coercion, of type (t1 ~# t2) or (t1 ~R# t2)

Note [Kind and type variables]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Before kind polymorphism, TyVar were used to mean type variables. Now
they are used to mean kind *or* type variables. KindVar is used when we
know for sure that it is a kind variable. In future, we might want to
go over the whole compiler code to use:
   - TKVar   to mean kind or type variables
   - TypeVar to mean         type variables only
   - KindVar to mean kind         variables


************************************************************************
*                                                                      *
\subsection{The main data type declarations}
*                                                                      *
************************************************************************


Every @Var@ has a @Unique@, to uniquify it and for fast comparison, a
@Type@, and an @IdInfo@ (non-essential info about it, e.g.,
strictness).  The essential info about different kinds of @Vars@ is
in its @VarDetails@.
-}

-- | Variable
--
-- Essentially a typed 'Name', that may also contain some additional information
-- about the 'Var' and its use sites.
data Var
  = TyVar {  -- Type and kind variables
             -- see Note [Kind and type variables]
        Var -> Name
varName    :: !Name,
        Var -> Int
realUnique :: {-# UNPACK #-} !Int,
                                     -- ^ Key for fast comparison
                                     -- Identical to the Unique in the name,
                                     -- cached here for speed
        Var -> Kind
varType    :: Kind           -- ^ The type or kind of the 'Var' in question
 }

  | TcTyVar {                           -- Used only during type inference
                                        -- Used for kind variables during
                                        -- inference, as well
        varName        :: !Name,
        realUnique     :: {-# UNPACK #-} !Int,
        varType        :: Kind,
        Var -> TcTyVarDetails
tc_tv_details  :: TcTyVarDetails
  }

  | Id {
        varName    :: !Name,
        realUnique :: {-# UNPACK #-} !Int,
        varType    :: Type,
        Var -> IdScope
idScope    :: IdScope,
        Var -> IdDetails
id_details :: IdDetails,        -- Stable, doesn't change
        Var -> IdInfo
id_info    :: IdInfo }          -- Unstable, updated by simplifier

-- | Identifier Scope
data IdScope    -- See Note [GlobalId/LocalId]
  = GlobalId
  | LocalId ExportFlag

data ExportFlag   -- See Note [ExportFlag on binders]
  = NotExported   -- ^ Not exported: may be discarded as dead code.
  | Exported      -- ^ Exported: kept alive

{- Note [ExportFlag on binders]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An ExportFlag of "Exported" on a top-level binder says "keep this
binding alive; do not drop it as dead code".  This transitively
keeps alive all the other top-level bindings that this binding refers
to.  This property is persisted all the way down the pipeline, so that
the binding will be compiled all the way to object code, and its
symbols will appear in the linker symbol table.

However, note that this use of "exported" is quite different to the
export list on a Haskell module.  Setting the ExportFlag on an Id does
/not/ mean that if you import the module (in Haskell source code) you
will see this Id.  Of course, things that appear in the export list
of the source Haskell module do indeed have their ExportFlag set.
But many other things, such as dictionary functions, are kept alive
by having their ExportFlag set, even though they are not exported
in the source-code sense.

We should probably use a different term for ExportFlag, like
KeepAlive.

Note [GlobalId/LocalId]
~~~~~~~~~~~~~~~~~~~~~~~
A GlobalId is
  * always a constant (top-level)
  * imported, or data constructor, or primop, or record selector
  * has a Unique that is globally unique across the whole
    GHC invocation (a single invocation may compile multiple modules)
  * never treated as a candidate by the free-variable finder;
        it's a constant!

A LocalId is
  * bound within an expression (lambda, case, local let(rec))
  * or defined at top level in the module being compiled
  * always treated as a candidate by the free-variable finder

After CoreTidy, top-level LocalIds are turned into GlobalIds
-}

instance Outputable Var where
  ppr :: Var -> SDoc
ppr Var
var = (DynFlags -> SDoc) -> SDoc
sdocWithDynFlags ((DynFlags -> SDoc) -> SDoc) -> (DynFlags -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \DynFlags
dflags ->
            (PprStyle -> SDoc) -> SDoc
getPprStyle ((PprStyle -> SDoc) -> SDoc) -> (PprStyle -> SDoc) -> SDoc
forall a b. (a -> b) -> a -> b
$ \PprStyle
ppr_style ->
            if |  PprStyle -> Bool
debugStyle PprStyle
ppr_style Bool -> Bool -> Bool
&& (Bool -> Bool
not (GeneralFlag -> DynFlags -> Bool
gopt GeneralFlag
Opt_SuppressVarKinds DynFlags
dflags))
                 -> SDoc -> SDoc
parens (Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Var -> Name
varName Var
var) SDoc -> SDoc -> SDoc
<+> Var -> PprStyle -> SDoc
ppr_debug Var
var PprStyle
ppr_style SDoc -> SDoc -> SDoc
<+>
                          SDoc
dcolon SDoc -> SDoc -> SDoc
<+> Kind -> SDoc
pprKind (Var -> Kind
tyVarKind Var
var))
               |  Bool
otherwise
                 -> Name -> SDoc
forall a. Outputable a => a -> SDoc
ppr (Var -> Name
varName Var
var) SDoc -> SDoc -> SDoc
<> Var -> PprStyle -> SDoc
ppr_debug Var
var PprStyle
ppr_style

ppr_debug :: Var -> PprStyle -> SDoc
ppr_debug :: Var -> PprStyle -> SDoc
ppr_debug (TyVar {}) PprStyle
sty
  | PprStyle -> Bool
debugStyle PprStyle
sty = SDoc -> SDoc
brackets (String -> SDoc
text String
"tv")
ppr_debug (TcTyVar {tc_tv_details :: Var -> TcTyVarDetails
tc_tv_details = TcTyVarDetails
d}) PprStyle
sty
  | PprStyle -> Bool
dumpStyle PprStyle
sty Bool -> Bool -> Bool
|| PprStyle -> Bool
debugStyle PprStyle
sty = SDoc -> SDoc
brackets (TcTyVarDetails -> SDoc
pprTcTyVarDetails TcTyVarDetails
d)
ppr_debug (Id { idScope :: Var -> IdScope
idScope = IdScope
s, id_details :: Var -> IdDetails
id_details = IdDetails
d }) PprStyle
sty
  | PprStyle -> Bool
debugStyle PprStyle
sty = SDoc -> SDoc
brackets (IdScope -> SDoc
ppr_id_scope IdScope
s SDoc -> SDoc -> SDoc
<> IdDetails -> SDoc
pprIdDetails IdDetails
d)
ppr_debug Var
_ PprStyle
_ = SDoc
empty

ppr_id_scope :: IdScope -> SDoc
ppr_id_scope :: IdScope -> SDoc
ppr_id_scope IdScope
GlobalId              = String -> SDoc
text String
"gid"
ppr_id_scope (LocalId ExportFlag
Exported)    = String -> SDoc
text String
"lidx"
ppr_id_scope (LocalId ExportFlag
NotExported) = String -> SDoc
text String
"lid"

instance NamedThing Var where
  getName :: Var -> Name
getName = Var -> Name
varName

instance Uniquable Var where
  getUnique :: Var -> Unique
getUnique = Var -> Unique
varUnique

instance Eq Var where
    Var
a == :: Var -> Var -> Bool
== Var
b = Var -> Int
realUnique Var
a Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== Var -> Int
realUnique Var
b

instance Ord Var where
    Var
a <= :: Var -> Var -> Bool
<= Var
b = Var -> Int
realUnique Var
a Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Var -> Int
realUnique Var
b
    Var
a < :: Var -> Var -> Bool
<  Var
b = Var -> Int
realUnique Var
a Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<  Var -> Int
realUnique Var
b
    Var
a >= :: Var -> Var -> Bool
>= Var
b = Var -> Int
realUnique Var
a Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>= Var -> Int
realUnique Var
b
    Var
a > :: Var -> Var -> Bool
>  Var
b = Var -> Int
realUnique Var
a Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
>  Var -> Int
realUnique Var
b
    Var
a compare :: Var -> Var -> Ordering
`compare` Var
b = Var
a Var -> Var -> Ordering
`nonDetCmpVar` Var
b

-- | Compare Vars by their Uniques.
-- This is what Ord Var does, provided here to make it explicit at the
-- call-site that it can introduce non-determinism.
-- See Note [Unique Determinism]
nonDetCmpVar :: Var -> Var -> Ordering
nonDetCmpVar :: Var -> Var -> Ordering
nonDetCmpVar Var
a Var
b = Var -> Unique
varUnique Var
a Unique -> Unique -> Ordering
`nonDetCmpUnique` Var -> Unique
varUnique Var
b

instance Data Var where
  -- don't traverse?
  toConstr :: Var -> Constr
toConstr Var
_   = String -> Constr
abstractConstr String
"Var"
  gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Var
gunfold forall b r. Data b => c (b -> r) -> c r
_ forall r. r -> c r
_  = String -> Constr -> c Var
forall a. HasCallStack => String -> a
error String
"gunfold"
  dataTypeOf :: Var -> DataType
dataTypeOf Var
_ = String -> DataType
mkNoRepType String
"Var"

instance HasOccName Var where
  occName :: Var -> OccName
occName = Name -> OccName
nameOccName (Name -> OccName) -> (Var -> Name) -> Var -> OccName
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Var -> Name
varName

varUnique :: Var -> Unique
varUnique :: Var -> Unique
varUnique Var
var = Int -> Unique
mkUniqueGrimily (Var -> Int
realUnique Var
var)

setVarUnique :: Var -> Unique -> Var
setVarUnique :: Var -> Unique -> Var
setVarUnique Var
var Unique
uniq
  = Var
var { realUnique :: Int
realUnique = Unique -> Int
getKey Unique
uniq,
          varName :: Name
varName = Name -> Unique -> Name
setNameUnique (Var -> Name
varName Var
var) Unique
uniq }

setVarName :: Var -> Name -> Var
setVarName :: Var -> Name -> Var
setVarName Var
var Name
new_name
  = Var
var { realUnique :: Int
realUnique = Unique -> Int
getKey (Name -> Unique
forall a. Uniquable a => a -> Unique
getUnique Name
new_name),
          varName :: Name
varName = Name
new_name }

setVarType :: Id -> Type -> Id
setVarType :: Var -> Kind -> Var
setVarType Var
id Kind
ty = Var
id { varType :: Kind
varType = Kind
ty }

updateVarType :: (Type -> Type) -> Id -> Id
updateVarType :: (Kind -> Kind) -> Var -> Var
updateVarType Kind -> Kind
f Var
id = Var
id { varType :: Kind
varType = Kind -> Kind
f (Var -> Kind
varType Var
id) }

updateVarTypeM :: Monad m => (Type -> m Type) -> Id -> m Id
updateVarTypeM :: (Kind -> m Kind) -> Var -> m Var
updateVarTypeM Kind -> m Kind
f Var
id = do { Kind
ty' <- Kind -> m Kind
f (Var -> Kind
varType Var
id)
                         ; Var -> m Var
forall (m :: * -> *) a. Monad m => a -> m a
return (Var
id { varType :: Kind
varType = Kind
ty' }) }

{- *********************************************************************
*                                                                      *
*                   ArgFlag
*                                                                      *
********************************************************************* -}

-- | Argument Flag
--
-- Is something required to appear in source Haskell ('Required'),
-- permitted by request ('Specified') (visible type application), or
-- prohibited entirely from appearing in source Haskell ('Inferred')?
-- See Note [VarBndrs, TyCoVarBinders, TyConBinders, and visibility] in TyCoRep
data ArgFlag = Inferred | Specified | Required
  deriving (ArgFlag -> ArgFlag -> Bool
(ArgFlag -> ArgFlag -> Bool)
-> (ArgFlag -> ArgFlag -> Bool) -> Eq ArgFlag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ArgFlag -> ArgFlag -> Bool
$c/= :: ArgFlag -> ArgFlag -> Bool
== :: ArgFlag -> ArgFlag -> Bool
$c== :: ArgFlag -> ArgFlag -> Bool
Eq, Eq ArgFlag
Eq ArgFlag
-> (ArgFlag -> ArgFlag -> Ordering)
-> (ArgFlag -> ArgFlag -> Bool)
-> (ArgFlag -> ArgFlag -> Bool)
-> (ArgFlag -> ArgFlag -> Bool)
-> (ArgFlag -> ArgFlag -> Bool)
-> (ArgFlag -> ArgFlag -> ArgFlag)
-> (ArgFlag -> ArgFlag -> ArgFlag)
-> Ord ArgFlag
ArgFlag -> ArgFlag -> Bool
ArgFlag -> ArgFlag -> Ordering
ArgFlag -> ArgFlag -> ArgFlag
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
min :: ArgFlag -> ArgFlag -> ArgFlag
$cmin :: ArgFlag -> ArgFlag -> ArgFlag
max :: ArgFlag -> ArgFlag -> ArgFlag
$cmax :: ArgFlag -> ArgFlag -> ArgFlag
>= :: ArgFlag -> ArgFlag -> Bool
$c>= :: ArgFlag -> ArgFlag -> Bool
> :: ArgFlag -> ArgFlag -> Bool
$c> :: ArgFlag -> ArgFlag -> Bool
<= :: ArgFlag -> ArgFlag -> Bool
$c<= :: ArgFlag -> ArgFlag -> Bool
< :: ArgFlag -> ArgFlag -> Bool
$c< :: ArgFlag -> ArgFlag -> Bool
compare :: ArgFlag -> ArgFlag -> Ordering
$ccompare :: ArgFlag -> ArgFlag -> Ordering
$cp1Ord :: Eq ArgFlag
Ord, Typeable ArgFlag
DataType
Constr
Typeable ArgFlag
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ArgFlag -> c ArgFlag)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ArgFlag)
-> (ArgFlag -> Constr)
-> (ArgFlag -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ArgFlag))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgFlag))
-> ((forall b. Data b => b -> b) -> ArgFlag -> ArgFlag)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ArgFlag -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ArgFlag -> r)
-> (forall u. (forall d. Data d => d -> u) -> ArgFlag -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> ArgFlag -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag)
-> Data ArgFlag
ArgFlag -> DataType
ArgFlag -> Constr
(forall b. Data b => b -> b) -> ArgFlag -> ArgFlag
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArgFlag -> c ArgFlag
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArgFlag
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ArgFlag -> u
forall u. (forall d. Data d => d -> u) -> ArgFlag -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ArgFlag -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ArgFlag -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArgFlag
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArgFlag -> c ArgFlag
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArgFlag)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgFlag)
$cRequired :: Constr
$cSpecified :: Constr
$cInferred :: Constr
$tArgFlag :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag
gmapMp :: (forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag
gmapM :: (forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag
gmapQi :: Int -> (forall d. Data d => d -> u) -> ArgFlag -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ArgFlag -> u
gmapQ :: (forall d. Data d => d -> u) -> ArgFlag -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ArgFlag -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ArgFlag -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ArgFlag -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ArgFlag -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ArgFlag -> r
gmapT :: (forall b. Data b => b -> b) -> ArgFlag -> ArgFlag
$cgmapT :: (forall b. Data b => b -> b) -> ArgFlag -> ArgFlag
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgFlag)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgFlag)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c ArgFlag)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ArgFlag)
dataTypeOf :: ArgFlag -> DataType
$cdataTypeOf :: ArgFlag -> DataType
toConstr :: ArgFlag -> Constr
$ctoConstr :: ArgFlag -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArgFlag
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ArgFlag
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArgFlag -> c ArgFlag
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ArgFlag -> c ArgFlag
$cp1Data :: Typeable ArgFlag
Data)
  -- (<) on ArgFlag means "is less visible than"

-- | Does this 'ArgFlag' classify an argument that is written in Haskell?
isVisibleArgFlag :: ArgFlag -> Bool
isVisibleArgFlag :: ArgFlag -> Bool
isVisibleArgFlag ArgFlag
Required = Bool
True
isVisibleArgFlag ArgFlag
_        = Bool
False

-- | Does this 'ArgFlag' classify an argument that is not written in Haskell?
isInvisibleArgFlag :: ArgFlag -> Bool
isInvisibleArgFlag :: ArgFlag -> Bool
isInvisibleArgFlag = Bool -> Bool
not (Bool -> Bool) -> (ArgFlag -> Bool) -> ArgFlag -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArgFlag -> Bool
isVisibleArgFlag

-- | Do these denote the same level of visibility? 'Required'
-- arguments are visible, others are not. So this function
-- equates 'Specified' and 'Inferred'. Used for printing.
sameVis :: ArgFlag -> ArgFlag -> Bool
sameVis :: ArgFlag -> ArgFlag -> Bool
sameVis ArgFlag
Required ArgFlag
Required = Bool
True
sameVis ArgFlag
Required ArgFlag
_        = Bool
False
sameVis ArgFlag
_        ArgFlag
Required = Bool
False
sameVis ArgFlag
_        ArgFlag
_        = Bool
True

instance Outputable ArgFlag where
  ppr :: ArgFlag -> SDoc
ppr ArgFlag
Required  = String -> SDoc
text String
"[req]"
  ppr ArgFlag
Specified = String -> SDoc
text String
"[spec]"
  ppr ArgFlag
Inferred  = String -> SDoc
text String
"[infrd]"

instance Binary ArgFlag where
  put_ :: BinHandle -> ArgFlag -> IO ()
put_ BinHandle
bh ArgFlag
Required  = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
  put_ BinHandle
bh ArgFlag
Specified = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1
  put_ BinHandle
bh ArgFlag
Inferred  = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
2

  get :: BinHandle -> IO ArgFlag
get BinHandle
bh = do
    Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
    case Word8
h of
      Word8
0 -> ArgFlag -> IO ArgFlag
forall (m :: * -> *) a. Monad m => a -> m a
return ArgFlag
Required
      Word8
1 -> ArgFlag -> IO ArgFlag
forall (m :: * -> *) a. Monad m => a -> m a
return ArgFlag
Specified
      Word8
_ -> ArgFlag -> IO ArgFlag
forall (m :: * -> *) a. Monad m => a -> m a
return ArgFlag
Inferred

-- | The non-dependent version of 'ArgFlag'.

-- Appears here partly so that it's together with its friend ArgFlag,
-- but also because it is used in IfaceType, rather early in the
-- compilation chain
-- See Note [AnonArgFlag vs. ForallVisFlag]
data AnonArgFlag
  = VisArg    -- ^ Used for @(->)@: an ordinary non-dependent arrow.
              --   The argument is visible in source code.
  | InvisArg  -- ^ Used for @(=>)@: a non-dependent predicate arrow.
              --   The argument is invisible in source code.
  deriving (AnonArgFlag -> AnonArgFlag -> Bool
(AnonArgFlag -> AnonArgFlag -> Bool)
-> (AnonArgFlag -> AnonArgFlag -> Bool) -> Eq AnonArgFlag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: AnonArgFlag -> AnonArgFlag -> Bool
$c/= :: AnonArgFlag -> AnonArgFlag -> Bool
== :: AnonArgFlag -> AnonArgFlag -> Bool
$c== :: AnonArgFlag -> AnonArgFlag -> Bool
Eq, Eq AnonArgFlag
Eq AnonArgFlag
-> (AnonArgFlag -> AnonArgFlag -> Ordering)
-> (AnonArgFlag -> AnonArgFlag -> Bool)
-> (AnonArgFlag -> AnonArgFlag -> Bool)
-> (AnonArgFlag -> AnonArgFlag -> Bool)
-> (AnonArgFlag -> AnonArgFlag -> Bool)
-> (AnonArgFlag -> AnonArgFlag -> AnonArgFlag)
-> (AnonArgFlag -> AnonArgFlag -> AnonArgFlag)
-> Ord AnonArgFlag
AnonArgFlag -> AnonArgFlag -> Bool
AnonArgFlag -> AnonArgFlag -> Ordering
AnonArgFlag -> AnonArgFlag -> AnonArgFlag
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
min :: AnonArgFlag -> AnonArgFlag -> AnonArgFlag
$cmin :: AnonArgFlag -> AnonArgFlag -> AnonArgFlag
max :: AnonArgFlag -> AnonArgFlag -> AnonArgFlag
$cmax :: AnonArgFlag -> AnonArgFlag -> AnonArgFlag
>= :: AnonArgFlag -> AnonArgFlag -> Bool
$c>= :: AnonArgFlag -> AnonArgFlag -> Bool
> :: AnonArgFlag -> AnonArgFlag -> Bool
$c> :: AnonArgFlag -> AnonArgFlag -> Bool
<= :: AnonArgFlag -> AnonArgFlag -> Bool
$c<= :: AnonArgFlag -> AnonArgFlag -> Bool
< :: AnonArgFlag -> AnonArgFlag -> Bool
$c< :: AnonArgFlag -> AnonArgFlag -> Bool
compare :: AnonArgFlag -> AnonArgFlag -> Ordering
$ccompare :: AnonArgFlag -> AnonArgFlag -> Ordering
$cp1Ord :: Eq AnonArgFlag
Ord, Typeable AnonArgFlag
DataType
Constr
Typeable AnonArgFlag
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> AnonArgFlag -> c AnonArgFlag)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c AnonArgFlag)
-> (AnonArgFlag -> Constr)
-> (AnonArgFlag -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c AnonArgFlag))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c AnonArgFlag))
-> ((forall b. Data b => b -> b) -> AnonArgFlag -> AnonArgFlag)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> AnonArgFlag -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> AnonArgFlag -> r)
-> (forall u. (forall d. Data d => d -> u) -> AnonArgFlag -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> AnonArgFlag -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> AnonArgFlag -> m AnonArgFlag)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> AnonArgFlag -> m AnonArgFlag)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> AnonArgFlag -> m AnonArgFlag)
-> Data AnonArgFlag
AnonArgFlag -> DataType
AnonArgFlag -> Constr
(forall b. Data b => b -> b) -> AnonArgFlag -> AnonArgFlag
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AnonArgFlag -> c AnonArgFlag
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AnonArgFlag
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> AnonArgFlag -> u
forall u. (forall d. Data d => d -> u) -> AnonArgFlag -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AnonArgFlag -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AnonArgFlag -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AnonArgFlag -> m AnonArgFlag
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AnonArgFlag -> m AnonArgFlag
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AnonArgFlag
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AnonArgFlag -> c AnonArgFlag
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AnonArgFlag)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c AnonArgFlag)
$cInvisArg :: Constr
$cVisArg :: Constr
$tAnonArgFlag :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> AnonArgFlag -> m AnonArgFlag
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AnonArgFlag -> m AnonArgFlag
gmapMp :: (forall d. Data d => d -> m d) -> AnonArgFlag -> m AnonArgFlag
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> AnonArgFlag -> m AnonArgFlag
gmapM :: (forall d. Data d => d -> m d) -> AnonArgFlag -> m AnonArgFlag
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> AnonArgFlag -> m AnonArgFlag
gmapQi :: Int -> (forall d. Data d => d -> u) -> AnonArgFlag -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> AnonArgFlag -> u
gmapQ :: (forall d. Data d => d -> u) -> AnonArgFlag -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> AnonArgFlag -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AnonArgFlag -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> AnonArgFlag -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AnonArgFlag -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> AnonArgFlag -> r
gmapT :: (forall b. Data b => b -> b) -> AnonArgFlag -> AnonArgFlag
$cgmapT :: (forall b. Data b => b -> b) -> AnonArgFlag -> AnonArgFlag
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c AnonArgFlag)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c AnonArgFlag)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c AnonArgFlag)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c AnonArgFlag)
dataTypeOf :: AnonArgFlag -> DataType
$cdataTypeOf :: AnonArgFlag -> DataType
toConstr :: AnonArgFlag -> Constr
$ctoConstr :: AnonArgFlag -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AnonArgFlag
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c AnonArgFlag
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AnonArgFlag -> c AnonArgFlag
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> AnonArgFlag -> c AnonArgFlag
$cp1Data :: Typeable AnonArgFlag
Data)

instance Outputable AnonArgFlag where
  ppr :: AnonArgFlag -> SDoc
ppr AnonArgFlag
VisArg   = String -> SDoc
text String
"[vis]"
  ppr AnonArgFlag
InvisArg = String -> SDoc
text String
"[invis]"

instance Binary AnonArgFlag where
  put_ :: BinHandle -> AnonArgFlag -> IO ()
put_ BinHandle
bh AnonArgFlag
VisArg   = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
0
  put_ BinHandle
bh AnonArgFlag
InvisArg = BinHandle -> Word8 -> IO ()
putByte BinHandle
bh Word8
1

  get :: BinHandle -> IO AnonArgFlag
get BinHandle
bh = do
    Word8
h <- BinHandle -> IO Word8
getByte BinHandle
bh
    case Word8
h of
      Word8
0 -> AnonArgFlag -> IO AnonArgFlag
forall (m :: * -> *) a. Monad m => a -> m a
return AnonArgFlag
VisArg
      Word8
_ -> AnonArgFlag -> IO AnonArgFlag
forall (m :: * -> *) a. Monad m => a -> m a
return AnonArgFlag
InvisArg

-- | Is a @forall@ invisible (e.g., @forall a b. {...}@, with a dot) or visible
-- (e.g., @forall a b -> {...}@, with an arrow)?

-- See Note [AnonArgFlag vs. ForallVisFlag]
data ForallVisFlag
  = ForallVis   -- ^ A visible @forall@ (with an arrow)
  | ForallInvis -- ^ An invisible @forall@ (with a dot)
  deriving (ForallVisFlag -> ForallVisFlag -> Bool
(ForallVisFlag -> ForallVisFlag -> Bool)
-> (ForallVisFlag -> ForallVisFlag -> Bool) -> Eq ForallVisFlag
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ForallVisFlag -> ForallVisFlag -> Bool
$c/= :: ForallVisFlag -> ForallVisFlag -> Bool
== :: ForallVisFlag -> ForallVisFlag -> Bool
$c== :: ForallVisFlag -> ForallVisFlag -> Bool
Eq, Eq ForallVisFlag
Eq ForallVisFlag
-> (ForallVisFlag -> ForallVisFlag -> Ordering)
-> (ForallVisFlag -> ForallVisFlag -> Bool)
-> (ForallVisFlag -> ForallVisFlag -> Bool)
-> (ForallVisFlag -> ForallVisFlag -> Bool)
-> (ForallVisFlag -> ForallVisFlag -> Bool)
-> (ForallVisFlag -> ForallVisFlag -> ForallVisFlag)
-> (ForallVisFlag -> ForallVisFlag -> ForallVisFlag)
-> Ord ForallVisFlag
ForallVisFlag -> ForallVisFlag -> Bool
ForallVisFlag -> ForallVisFlag -> Ordering
ForallVisFlag -> ForallVisFlag -> ForallVisFlag
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
min :: ForallVisFlag -> ForallVisFlag -> ForallVisFlag
$cmin :: ForallVisFlag -> ForallVisFlag -> ForallVisFlag
max :: ForallVisFlag -> ForallVisFlag -> ForallVisFlag
$cmax :: ForallVisFlag -> ForallVisFlag -> ForallVisFlag
>= :: ForallVisFlag -> ForallVisFlag -> Bool
$c>= :: ForallVisFlag -> ForallVisFlag -> Bool
> :: ForallVisFlag -> ForallVisFlag -> Bool
$c> :: ForallVisFlag -> ForallVisFlag -> Bool
<= :: ForallVisFlag -> ForallVisFlag -> Bool
$c<= :: ForallVisFlag -> ForallVisFlag -> Bool
< :: ForallVisFlag -> ForallVisFlag -> Bool
$c< :: ForallVisFlag -> ForallVisFlag -> Bool
compare :: ForallVisFlag -> ForallVisFlag -> Ordering
$ccompare :: ForallVisFlag -> ForallVisFlag -> Ordering
$cp1Ord :: Eq ForallVisFlag
Ord, Typeable ForallVisFlag
DataType
Constr
Typeable ForallVisFlag
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> ForallVisFlag -> c ForallVisFlag)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c ForallVisFlag)
-> (ForallVisFlag -> Constr)
-> (ForallVisFlag -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c ForallVisFlag))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c ForallVisFlag))
-> ((forall b. Data b => b -> b) -> ForallVisFlag -> ForallVisFlag)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> ForallVisFlag -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> ForallVisFlag -> r)
-> (forall u. (forall d. Data d => d -> u) -> ForallVisFlag -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> ForallVisFlag -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> ForallVisFlag -> m ForallVisFlag)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ForallVisFlag -> m ForallVisFlag)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> ForallVisFlag -> m ForallVisFlag)
-> Data ForallVisFlag
ForallVisFlag -> DataType
ForallVisFlag -> Constr
(forall b. Data b => b -> b) -> ForallVisFlag -> ForallVisFlag
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ForallVisFlag -> c ForallVisFlag
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ForallVisFlag
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> ForallVisFlag -> u
forall u. (forall d. Data d => d -> u) -> ForallVisFlag -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ForallVisFlag -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ForallVisFlag -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ForallVisFlag -> m ForallVisFlag
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ForallVisFlag -> m ForallVisFlag
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ForallVisFlag
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ForallVisFlag -> c ForallVisFlag
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ForallVisFlag)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ForallVisFlag)
$cForallInvis :: Constr
$cForallVis :: Constr
$tForallVisFlag :: DataType
gmapMo :: (forall d. Data d => d -> m d) -> ForallVisFlag -> m ForallVisFlag
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ForallVisFlag -> m ForallVisFlag
gmapMp :: (forall d. Data d => d -> m d) -> ForallVisFlag -> m ForallVisFlag
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> ForallVisFlag -> m ForallVisFlag
gmapM :: (forall d. Data d => d -> m d) -> ForallVisFlag -> m ForallVisFlag
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> ForallVisFlag -> m ForallVisFlag
gmapQi :: Int -> (forall d. Data d => d -> u) -> ForallVisFlag -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> ForallVisFlag -> u
gmapQ :: (forall d. Data d => d -> u) -> ForallVisFlag -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> ForallVisFlag -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ForallVisFlag -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> ForallVisFlag -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ForallVisFlag -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> ForallVisFlag -> r
gmapT :: (forall b. Data b => b -> b) -> ForallVisFlag -> ForallVisFlag
$cgmapT :: (forall b. Data b => b -> b) -> ForallVisFlag -> ForallVisFlag
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ForallVisFlag)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c ForallVisFlag)
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c ForallVisFlag)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c ForallVisFlag)
dataTypeOf :: ForallVisFlag -> DataType
$cdataTypeOf :: ForallVisFlag -> DataType
toConstr :: ForallVisFlag -> Constr
$ctoConstr :: ForallVisFlag -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ForallVisFlag
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c ForallVisFlag
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ForallVisFlag -> c ForallVisFlag
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> ForallVisFlag -> c ForallVisFlag
$cp1Data :: Typeable ForallVisFlag
Data)

instance Outputable ForallVisFlag where
  ppr :: ForallVisFlag -> SDoc
ppr ForallVisFlag
f = String -> SDoc
text (String -> SDoc) -> String -> SDoc
forall a b. (a -> b) -> a -> b
$ case ForallVisFlag
f of
                   ForallVisFlag
ForallVis   -> String
"ForallVis"
                   ForallVisFlag
ForallInvis -> String
"ForallInvis"

-- | Convert an 'ArgFlag' to its corresponding 'ForallVisFlag'.
argToForallVisFlag :: ArgFlag -> ForallVisFlag
argToForallVisFlag :: ArgFlag -> ForallVisFlag
argToForallVisFlag ArgFlag
Required  = ForallVisFlag
ForallVis
argToForallVisFlag ArgFlag
Specified = ForallVisFlag
ForallInvis
argToForallVisFlag ArgFlag
Inferred  = ForallVisFlag
ForallInvis

{-
Note [AnonArgFlag vs. ForallVisFlag]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The AnonArgFlag and ForallVisFlag data types are quite similar at a first
glance:

  data AnonArgFlag   = VisArg    | InvisArg
  data ForallVisFlag = ForallVis | ForallInvis

Both data types keep track of visibility of some sort. AnonArgFlag tracks
whether a FunTy has a visible argument (->) or an invisible predicate argument
(=>). ForallVisFlag tracks whether a `forall` quantifier is visible
(forall a -> {...}) or invisible (forall a. {...}).

Given their similarities, it's tempting to want to combine these two data types
into one, but they actually represent distinct concepts. AnonArgFlag reflects a
property of *Core* types, whereas ForallVisFlag reflects a property of the GHC
AST. In other words, AnonArgFlag is all about internals, whereas ForallVisFlag
is all about surface syntax. Therefore, they are kept as separate data types.
-}

{- *********************************************************************
*                                                                      *
*                   VarBndr, TyCoVarBinder
*                                                                      *
********************************************************************* -}

-- Variable Binder
--
-- VarBndr is polymorphic in both var and visibility fields.
-- Currently there are six different uses of 'VarBndr':
--   * Var.TyVarBinder   = VarBndr TyVar ArgFlag
--   * Var.TyCoVarBinder = VarBndr TyCoVar ArgFlag
--   * TyCon.TyConBinder     = VarBndr TyVar TyConBndrVis
--   * TyCon.TyConTyCoBinder = VarBndr TyCoVar TyConBndrVis
--   * IfaceType.IfaceForAllBndr  = VarBndr IfaceBndr ArgFlag
--   * IfaceType.IfaceTyConBinder = VarBndr IfaceBndr TyConBndrVis
data VarBndr var argf = Bndr var argf
  deriving( Typeable (VarBndr var argf)
DataType
Constr
Typeable (VarBndr var argf)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> VarBndr var argf
    -> c (VarBndr var argf))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (VarBndr var argf))
-> (VarBndr var argf -> Constr)
-> (VarBndr var argf -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (VarBndr var argf)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (VarBndr var argf)))
-> ((forall b. Data b => b -> b)
    -> VarBndr var argf -> VarBndr var argf)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> VarBndr var argf -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> VarBndr var argf -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> VarBndr var argf -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> VarBndr var argf -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> VarBndr var argf -> m (VarBndr var argf))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> VarBndr var argf -> m (VarBndr var argf))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> VarBndr var argf -> m (VarBndr var argf))
-> Data (VarBndr var argf)
VarBndr var argf -> DataType
VarBndr var argf -> Constr
(forall b. Data b => b -> b)
-> VarBndr var argf -> VarBndr var argf
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VarBndr var argf -> c (VarBndr var argf)
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VarBndr var argf)
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VarBndr var argf))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> VarBndr var argf -> u
forall u. (forall d. Data d => d -> u) -> VarBndr var argf -> [u]
forall var argf.
(Data var, Data argf) =>
Typeable (VarBndr var argf)
forall var argf.
(Data var, Data argf) =>
VarBndr var argf -> DataType
forall var argf.
(Data var, Data argf) =>
VarBndr var argf -> Constr
forall var argf.
(Data var, Data argf) =>
(forall b. Data b => b -> b)
-> VarBndr var argf -> VarBndr var argf
forall var argf u.
(Data var, Data argf) =>
Int -> (forall d. Data d => d -> u) -> VarBndr var argf -> u
forall var argf u.
(Data var, Data argf) =>
(forall d. Data d => d -> u) -> VarBndr var argf -> [u]
forall var argf r r'.
(Data var, Data argf) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VarBndr var argf -> r
forall var argf r r'.
(Data var, Data argf) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VarBndr var argf -> r
forall var argf (m :: * -> *).
(Data var, Data argf, Monad m) =>
(forall d. Data d => d -> m d)
-> VarBndr var argf -> m (VarBndr var argf)
forall var argf (m :: * -> *).
(Data var, Data argf, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> VarBndr var argf -> m (VarBndr var argf)
forall var argf (c :: * -> *).
(Data var, Data argf) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VarBndr var argf)
forall var argf (c :: * -> *).
(Data var, Data argf) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VarBndr var argf -> c (VarBndr var argf)
forall var argf (t :: * -> *) (c :: * -> *).
(Data var, Data argf, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (VarBndr var argf))
forall var argf (t :: * -> * -> *) (c :: * -> *).
(Data var, Data argf, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VarBndr var argf))
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VarBndr var argf -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VarBndr var argf -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> VarBndr var argf -> m (VarBndr var argf)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> VarBndr var argf -> m (VarBndr var argf)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VarBndr var argf)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VarBndr var argf -> c (VarBndr var argf)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (VarBndr var argf))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VarBndr var argf))
$cBndr :: Constr
$tVarBndr :: DataType
gmapMo :: (forall d. Data d => d -> m d)
-> VarBndr var argf -> m (VarBndr var argf)
$cgmapMo :: forall var argf (m :: * -> *).
(Data var, Data argf, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> VarBndr var argf -> m (VarBndr var argf)
gmapMp :: (forall d. Data d => d -> m d)
-> VarBndr var argf -> m (VarBndr var argf)
$cgmapMp :: forall var argf (m :: * -> *).
(Data var, Data argf, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> VarBndr var argf -> m (VarBndr var argf)
gmapM :: (forall d. Data d => d -> m d)
-> VarBndr var argf -> m (VarBndr var argf)
$cgmapM :: forall var argf (m :: * -> *).
(Data var, Data argf, Monad m) =>
(forall d. Data d => d -> m d)
-> VarBndr var argf -> m (VarBndr var argf)
gmapQi :: Int -> (forall d. Data d => d -> u) -> VarBndr var argf -> u
$cgmapQi :: forall var argf u.
(Data var, Data argf) =>
Int -> (forall d. Data d => d -> u) -> VarBndr var argf -> u
gmapQ :: (forall d. Data d => d -> u) -> VarBndr var argf -> [u]
$cgmapQ :: forall var argf u.
(Data var, Data argf) =>
(forall d. Data d => d -> u) -> VarBndr var argf -> [u]
gmapQr :: (r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VarBndr var argf -> r
$cgmapQr :: forall var argf r r'.
(Data var, Data argf) =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> VarBndr var argf -> r
gmapQl :: (r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VarBndr var argf -> r
$cgmapQl :: forall var argf r r'.
(Data var, Data argf) =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> VarBndr var argf -> r
gmapT :: (forall b. Data b => b -> b)
-> VarBndr var argf -> VarBndr var argf
$cgmapT :: forall var argf.
(Data var, Data argf) =>
(forall b. Data b => b -> b)
-> VarBndr var argf -> VarBndr var argf
dataCast2 :: (forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VarBndr var argf))
$cdataCast2 :: forall var argf (t :: * -> * -> *) (c :: * -> *).
(Data var, Data argf, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (VarBndr var argf))
dataCast1 :: (forall d. Data d => c (t d)) -> Maybe (c (VarBndr var argf))
$cdataCast1 :: forall var argf (t :: * -> *) (c :: * -> *).
(Data var, Data argf, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (VarBndr var argf))
dataTypeOf :: VarBndr var argf -> DataType
$cdataTypeOf :: forall var argf.
(Data var, Data argf) =>
VarBndr var argf -> DataType
toConstr :: VarBndr var argf -> Constr
$ctoConstr :: forall var argf.
(Data var, Data argf) =>
VarBndr var argf -> Constr
gunfold :: (forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VarBndr var argf)
$cgunfold :: forall var argf (c :: * -> *).
(Data var, Data argf) =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (VarBndr var argf)
gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VarBndr var argf -> c (VarBndr var argf)
$cgfoldl :: forall var argf (c :: * -> *).
(Data var, Data argf) =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> VarBndr var argf -> c (VarBndr var argf)
$cp1Data :: forall var argf.
(Data var, Data argf) =>
Typeable (VarBndr var argf)
Data )

-- | Variable Binder
--
-- A 'TyCoVarBinder' is the binder of a ForAllTy
-- It's convenient to define this synonym here rather its natural
-- home in TyCoRep, because it's used in DataCon.hs-boot
--
-- A 'TyVarBinder' is a binder with only TyVar
type TyCoVarBinder = VarBndr TyCoVar ArgFlag
type TyVarBinder   = VarBndr TyVar ArgFlag

binderVar :: VarBndr tv argf -> tv
binderVar :: VarBndr tv argf -> tv
binderVar (Bndr tv
v argf
_) = tv
v

binderVars :: [VarBndr tv argf] -> [tv]
binderVars :: [VarBndr tv argf] -> [tv]
binderVars [VarBndr tv argf]
tvbs = (VarBndr tv argf -> tv) -> [VarBndr tv argf] -> [tv]
forall a b. (a -> b) -> [a] -> [b]
map VarBndr tv argf -> tv
forall tv argf. VarBndr tv argf -> tv
binderVar [VarBndr tv argf]
tvbs

binderArgFlag :: VarBndr tv argf -> argf
binderArgFlag :: VarBndr tv argf -> argf
binderArgFlag (Bndr tv
_ argf
argf) = argf
argf

binderType :: VarBndr TyCoVar argf -> Type
binderType :: VarBndr Var argf -> Kind
binderType (Bndr Var
tv argf
_) = Var -> Kind
varType Var
tv

-- | Make a named binder
mkTyCoVarBinder :: ArgFlag -> TyCoVar -> TyCoVarBinder
mkTyCoVarBinder :: ArgFlag -> Var -> TyCoVarBinder
mkTyCoVarBinder ArgFlag
vis Var
var = Var -> ArgFlag -> TyCoVarBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr Var
var ArgFlag
vis

-- | Make a named binder
-- 'var' should be a type variable
mkTyVarBinder :: ArgFlag -> TyVar -> TyVarBinder
mkTyVarBinder :: ArgFlag -> Var -> TyCoVarBinder
mkTyVarBinder ArgFlag
vis Var
var
  = ASSERT( isTyVar var )
    Var -> ArgFlag -> TyCoVarBinder
forall var argf. var -> argf -> VarBndr var argf
Bndr Var
var ArgFlag
vis

-- | Make many named binders
mkTyCoVarBinders :: ArgFlag -> [TyCoVar] -> [TyCoVarBinder]
mkTyCoVarBinders :: ArgFlag -> [Var] -> [TyCoVarBinder]
mkTyCoVarBinders ArgFlag
vis = (Var -> TyCoVarBinder) -> [Var] -> [TyCoVarBinder]
forall a b. (a -> b) -> [a] -> [b]
map (ArgFlag -> Var -> TyCoVarBinder
mkTyCoVarBinder ArgFlag
vis)

-- | Make many named binders
-- Input vars should be type variables
mkTyVarBinders :: ArgFlag -> [TyVar] -> [TyVarBinder]
mkTyVarBinders :: ArgFlag -> [Var] -> [TyCoVarBinder]
mkTyVarBinders ArgFlag
vis = (Var -> TyCoVarBinder) -> [Var] -> [TyCoVarBinder]
forall a b. (a -> b) -> [a] -> [b]
map (ArgFlag -> Var -> TyCoVarBinder
mkTyVarBinder ArgFlag
vis)

isTyVarBinder :: TyCoVarBinder -> Bool
isTyVarBinder :: TyCoVarBinder -> Bool
isTyVarBinder (Bndr Var
v ArgFlag
_) = Var -> Bool
isTyVar Var
v

instance Outputable tv => Outputable (VarBndr tv ArgFlag) where
  ppr :: VarBndr tv ArgFlag -> SDoc
ppr (Bndr tv
v ArgFlag
Required)  = tv -> SDoc
forall a. Outputable a => a -> SDoc
ppr tv
v
  ppr (Bndr tv
v ArgFlag
Specified) = Char -> SDoc
char Char
'@' SDoc -> SDoc -> SDoc
<> tv -> SDoc
forall a. Outputable a => a -> SDoc
ppr tv
v
  ppr (Bndr tv
v ArgFlag
Inferred)  = SDoc -> SDoc
braces (tv -> SDoc
forall a. Outputable a => a -> SDoc
ppr tv
v)

instance (Binary tv, Binary vis) => Binary (VarBndr tv vis) where
  put_ :: BinHandle -> VarBndr tv vis -> IO ()
put_ BinHandle
bh (Bndr tv
tv vis
vis) = do { BinHandle -> tv -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh tv
tv; BinHandle -> vis -> IO ()
forall a. Binary a => BinHandle -> a -> IO ()
put_ BinHandle
bh vis
vis }

  get :: BinHandle -> IO (VarBndr tv vis)
get BinHandle
bh = do { tv
tv <- BinHandle -> IO tv
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh; vis
vis <- BinHandle -> IO vis
forall a. Binary a => BinHandle -> IO a
get BinHandle
bh; VarBndr tv vis -> IO (VarBndr tv vis)
forall (m :: * -> *) a. Monad m => a -> m a
return (tv -> vis -> VarBndr tv vis
forall var argf. var -> argf -> VarBndr var argf
Bndr tv
tv vis
vis) }

instance NamedThing tv => NamedThing (VarBndr tv flag) where
  getName :: VarBndr tv flag -> Name
getName (Bndr tv
tv flag
_) = tv -> Name
forall a. NamedThing a => a -> Name
getName tv
tv

{-
************************************************************************
*                                                                      *
*                 Type and kind variables                              *
*                                                                      *
************************************************************************
-}

tyVarName :: TyVar -> Name
tyVarName :: Var -> Name
tyVarName = Var -> Name
varName

tyVarKind :: TyVar -> Kind
tyVarKind :: Var -> Kind
tyVarKind = Var -> Kind
varType

setTyVarUnique :: TyVar -> Unique -> TyVar
setTyVarUnique :: Var -> Unique -> Var
setTyVarUnique = Var -> Unique -> Var
setVarUnique

setTyVarName :: TyVar -> Name -> TyVar
setTyVarName :: Var -> Name -> Var
setTyVarName   = Var -> Name -> Var
setVarName

setTyVarKind :: TyVar -> Kind -> TyVar
setTyVarKind :: Var -> Kind -> Var
setTyVarKind Var
tv Kind
k = Var
tv {varType :: Kind
varType = Kind
k}

updateTyVarKind :: (Kind -> Kind) -> TyVar -> TyVar
updateTyVarKind :: (Kind -> Kind) -> Var -> Var
updateTyVarKind Kind -> Kind
update Var
tv = Var
tv {varType :: Kind
varType = Kind -> Kind
update (Var -> Kind
tyVarKind Var
tv)}

updateTyVarKindM :: (Monad m) => (Kind -> m Kind) -> TyVar -> m TyVar
updateTyVarKindM :: (Kind -> m Kind) -> Var -> m Var
updateTyVarKindM Kind -> m Kind
update Var
tv
  = do { Kind
k' <- Kind -> m Kind
update (Var -> Kind
tyVarKind Var
tv)
       ; Var -> m Var
forall (m :: * -> *) a. Monad m => a -> m a
return (Var -> m Var) -> Var -> m Var
forall a b. (a -> b) -> a -> b
$ Var
tv {varType :: Kind
varType = Kind
k'} }

mkTyVar :: Name -> Kind -> TyVar
mkTyVar :: Name -> Kind -> Var
mkTyVar Name
name Kind
kind = TyVar :: Name -> Int -> Kind -> Var
TyVar { varName :: Name
varName    = Name
name
                          , realUnique :: Int
realUnique = Unique -> Int
getKey (Name -> Unique
nameUnique Name
name)
                          , varType :: Kind
varType  = Kind
kind
                          }

mkTcTyVar :: Name -> Kind -> TcTyVarDetails -> TyVar
mkTcTyVar :: Name -> Kind -> TcTyVarDetails -> Var
mkTcTyVar Name
name Kind
kind TcTyVarDetails
details
  = -- NB: 'kind' may be a coercion kind; cf, 'TcMType.newMetaCoVar'
    TcTyVar :: Name -> Int -> Kind -> TcTyVarDetails -> Var
TcTyVar {   varName :: Name
varName    = Name
name,
                realUnique :: Int
realUnique = Unique -> Int
getKey (Name -> Unique
nameUnique Name
name),
                varType :: Kind
varType  = Kind
kind,
                tc_tv_details :: TcTyVarDetails
tc_tv_details = TcTyVarDetails
details
        }

tcTyVarDetails :: TyVar -> TcTyVarDetails
-- See Note [TcTyVars in the typechecker] in TcType
tcTyVarDetails :: Var -> TcTyVarDetails
tcTyVarDetails (TcTyVar { tc_tv_details :: Var -> TcTyVarDetails
tc_tv_details = TcTyVarDetails
details }) = TcTyVarDetails
details
tcTyVarDetails (TyVar {})                            = TcTyVarDetails
vanillaSkolemTv
tcTyVarDetails Var
var = String -> SDoc -> TcTyVarDetails
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"tcTyVarDetails" (Var -> SDoc
forall a. Outputable a => a -> SDoc
ppr Var
var SDoc -> SDoc -> SDoc
<+> SDoc
dcolon SDoc -> SDoc -> SDoc
<+> Kind -> SDoc
pprKind (Var -> Kind
tyVarKind Var
var))

setTcTyVarDetails :: TyVar -> TcTyVarDetails -> TyVar
setTcTyVarDetails :: Var -> TcTyVarDetails -> Var
setTcTyVarDetails Var
tv TcTyVarDetails
details = Var
tv { tc_tv_details :: TcTyVarDetails
tc_tv_details = TcTyVarDetails
details }

{-
%************************************************************************
%*                                                                      *
\subsection{Ids}
*                                                                      *
************************************************************************
-}

idInfo :: HasDebugCallStack => Id -> IdInfo
idInfo :: Var -> IdInfo
idInfo (Id { id_info :: Var -> IdInfo
id_info = IdInfo
info }) = IdInfo
info
idInfo Var
other                   = String -> SDoc -> IdInfo
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"idInfo" (Var -> SDoc
forall a. Outputable a => a -> SDoc
ppr Var
other)

idDetails :: Id -> IdDetails
idDetails :: Var -> IdDetails
idDetails (Id { id_details :: Var -> IdDetails
id_details = IdDetails
details }) = IdDetails
details
idDetails Var
other                         = String -> SDoc -> IdDetails
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"idDetails" (Var -> SDoc
forall a. Outputable a => a -> SDoc
ppr Var
other)

-- The next three have a 'Var' suffix even though they always build
-- Ids, because Id.hs uses 'mkGlobalId' etc with different types
mkGlobalVar :: IdDetails -> Name -> Type -> IdInfo -> Id
mkGlobalVar :: IdDetails -> Name -> Kind -> IdInfo -> Var
mkGlobalVar IdDetails
details Name
name Kind
ty IdInfo
info
  = Name -> Kind -> IdScope -> IdDetails -> IdInfo -> Var
mk_id Name
name Kind
ty IdScope
GlobalId IdDetails
details IdInfo
info

mkLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id
mkLocalVar :: IdDetails -> Name -> Kind -> IdInfo -> Var
mkLocalVar IdDetails
details Name
name Kind
ty IdInfo
info
  = Name -> Kind -> IdScope -> IdDetails -> IdInfo -> Var
mk_id Name
name Kind
ty (ExportFlag -> IdScope
LocalId ExportFlag
NotExported) IdDetails
details  IdInfo
info

mkCoVar :: Name -> Type -> CoVar
-- Coercion variables have no IdInfo
mkCoVar :: Name -> Kind -> Var
mkCoVar Name
name Kind
ty = Name -> Kind -> IdScope -> IdDetails -> IdInfo -> Var
mk_id Name
name Kind
ty (ExportFlag -> IdScope
LocalId ExportFlag
NotExported) IdDetails
coVarDetails IdInfo
vanillaIdInfo

-- | Exported 'Var's will not be removed as dead code
mkExportedLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id
mkExportedLocalVar :: IdDetails -> Name -> Kind -> IdInfo -> Var
mkExportedLocalVar IdDetails
details Name
name Kind
ty IdInfo
info
  = Name -> Kind -> IdScope -> IdDetails -> IdInfo -> Var
mk_id Name
name Kind
ty (ExportFlag -> IdScope
LocalId ExportFlag
Exported) IdDetails
details IdInfo
info

mk_id :: Name -> Type -> IdScope -> IdDetails -> IdInfo -> Id
mk_id :: Name -> Kind -> IdScope -> IdDetails -> IdInfo -> Var
mk_id Name
name Kind
ty IdScope
scope IdDetails
details IdInfo
info
  = Id :: Name -> Int -> Kind -> IdScope -> IdDetails -> IdInfo -> Var
Id { varName :: Name
varName    = Name
name,
         realUnique :: Int
realUnique = Unique -> Int
getKey (Name -> Unique
nameUnique Name
name),
         varType :: Kind
varType    = Kind
ty,
         idScope :: IdScope
idScope    = IdScope
scope,
         id_details :: IdDetails
id_details = IdDetails
details,
         id_info :: IdInfo
id_info    = IdInfo
info }

-------------------
lazySetIdInfo :: Id -> IdInfo -> Var
lazySetIdInfo :: Var -> IdInfo -> Var
lazySetIdInfo Var
id IdInfo
info = Var
id { id_info :: IdInfo
id_info = IdInfo
info }

setIdDetails :: Id -> IdDetails -> Id
setIdDetails :: Var -> IdDetails -> Var
setIdDetails Var
id IdDetails
details = Var
id { id_details :: IdDetails
id_details = IdDetails
details }

globaliseId :: Id -> Id
-- ^ If it's a local, make it global
globaliseId :: Var -> Var
globaliseId Var
id = Var
id { idScope :: IdScope
idScope = IdScope
GlobalId }

setIdExported :: Id -> Id
-- ^ Exports the given local 'Id'. Can also be called on global 'Id's, such as data constructors
-- and class operations, which are born as global 'Id's and automatically exported
setIdExported :: Var -> Var
setIdExported id :: Var
id@(Id { idScope :: Var -> IdScope
idScope = LocalId {} }) = Var
id { idScope :: IdScope
idScope = ExportFlag -> IdScope
LocalId ExportFlag
Exported }
setIdExported id :: Var
id@(Id { idScope :: Var -> IdScope
idScope = IdScope
GlobalId })   = Var
id
setIdExported Var
tv                               = String -> SDoc -> Var
forall a. HasCallStack => String -> SDoc -> a
pprPanic String
"setIdExported" (Var -> SDoc
forall a. Outputable a => a -> SDoc
ppr Var
tv)

setIdNotExported :: Id -> Id
-- ^ We can only do this to LocalIds
setIdNotExported :: Var -> Var
setIdNotExported Var
id = ASSERT( isLocalId id )
                      Var
id { idScope :: IdScope
idScope = ExportFlag -> IdScope
LocalId ExportFlag
NotExported }

{-
************************************************************************
*                                                                      *
\subsection{Predicates over variables}
*                                                                      *
************************************************************************
-}

-- | Is this a type-level (i.e., computationally irrelevant, thus erasable)
-- variable? Satisfies @isTyVar = not . isId@.
isTyVar :: Var -> Bool        -- True of both TyVar and TcTyVar
isTyVar :: Var -> Bool
isTyVar (TyVar {})   = Bool
True
isTyVar (TcTyVar {}) = Bool
True
isTyVar Var
_            = Bool
False

isTcTyVar :: Var -> Bool      -- True of TcTyVar only
isTcTyVar :: Var -> Bool
isTcTyVar (TcTyVar {}) = Bool
True
isTcTyVar Var
_            = Bool
False

isTyCoVar :: Var -> Bool
isTyCoVar :: Var -> Bool
isTyCoVar Var
v = Var -> Bool
isTyVar Var
v Bool -> Bool -> Bool
|| Var -> Bool
isCoVar Var
v

-- | Is this a value-level (i.e., computationally relevant) 'Id'entifier?
-- Satisfies @isId = not . isTyVar@.
isId :: Var -> Bool
isId :: Var -> Bool
isId (Id {}) = Bool
True
isId Var
_       = Bool
False

-- | Is this a coercion variable?
-- Satisfies @'isId' v ==> 'isCoVar' v == not ('isNonCoVarId' v)@.
isCoVar :: Var -> Bool
isCoVar :: Var -> Bool
isCoVar (Id { id_details :: Var -> IdDetails
id_details = IdDetails
details }) = IdDetails -> Bool
isCoVarDetails IdDetails
details
isCoVar Var
_                             = Bool
False

-- | Is this a term variable ('Id') that is /not/ a coercion variable?
-- Satisfies @'isId' v ==> 'isCoVar' v == not ('isNonCoVarId' v)@.
isNonCoVarId :: Var -> Bool
isNonCoVarId :: Var -> Bool
isNonCoVarId (Id { id_details :: Var -> IdDetails
id_details = IdDetails
details }) = Bool -> Bool
not (IdDetails -> Bool
isCoVarDetails IdDetails
details)
isNonCoVarId Var
_                             = Bool
False

isLocalId :: Var -> Bool
isLocalId :: Var -> Bool
isLocalId (Id { idScope :: Var -> IdScope
idScope = LocalId ExportFlag
_ }) = Bool
True
isLocalId Var
_                            = Bool
False

-- | 'isLocalVar' returns @True@ for type variables as well as local 'Id's
-- These are the variables that we need to pay attention to when finding free
-- variables, or doing dependency analysis.
isLocalVar :: Var -> Bool
isLocalVar :: Var -> Bool
isLocalVar Var
v = Bool -> Bool
not (Var -> Bool
isGlobalId Var
v)

isGlobalId :: Var -> Bool
isGlobalId :: Var -> Bool
isGlobalId (Id { idScope :: Var -> IdScope
idScope = IdScope
GlobalId }) = Bool
True
isGlobalId Var
_                           = Bool
False

-- | 'mustHaveLocalBinding' returns @True@ of 'Id's and 'TyVar's
-- that must have a binding in this module.  The converse
-- is not quite right: there are some global 'Id's that must have
-- bindings, such as record selectors.  But that doesn't matter,
-- because it's only used for assertions
mustHaveLocalBinding        :: Var -> Bool
mustHaveLocalBinding :: Var -> Bool
mustHaveLocalBinding Var
var = Var -> Bool
isLocalVar Var
var

-- | 'isExportedIdVar' means \"don't throw this away\"
isExportedId :: Var -> Bool
isExportedId :: Var -> Bool
isExportedId (Id { idScope :: Var -> IdScope
idScope = IdScope
GlobalId })        = Bool
True
isExportedId (Id { idScope :: Var -> IdScope
idScope = LocalId ExportFlag
Exported}) = Bool
True
isExportedId Var
_ = Bool
False