ghc-8.2.2: The GHC API

Safe Haskell | None
Language | Haskell2010

Var

Contents

- The main data type and synonyms
- In and Out variants
  - Taking `Var`s apart
  - Modifying `Var`s
  - Constructing, taking apart, modifying `Id`s
  - Predicates
- TyVar's
  - Constructing TyVar's
  - Taking `TyVar`s apart
  - Modifying `TyVar`s

Description

GHC uses several kinds of name internally:

- `OccName`: see OccName
- `RdrName`: see RdrName
- `Name`: see Name
- `Id`: see Id
- `Var` is a synonym for the `Id` type but it may additionally potentially contain type variables, which have a `Kind` rather than a `Type` and only contain some extra details during typechecking.

These `Var` names may either be global or local, see Var

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.

Synopsis

- data Var
- type CoVar = Id
- type Id = Var
- type NcId = Id
- type DictId = EvId
- type DFunId = Id
- type EvVar = EvId
- type EqVar = EvId
- type EvId = Id
- type IpId = EvId
- type JoinId = Id
- type TyVar = Var
- type TypeVar = Var
- type KindVar = Var
- type TKVar = Var
- type TyCoVar = Id
- type InVar = Var
- type InCoVar = CoVar
- type InId = Id
- type InTyVar = TyVar
- type OutVar = Var
- type OutCoVar = CoVar
- type OutId = Id
- type OutTyVar = TyVar
- varName :: Var -> Name
- varUnique :: Var -> Unique
- varType :: Var -> Kind
- setVarName :: Var -> Name -> Var
- setVarUnique :: Var -> Unique -> Var
- setVarType :: Id -> Type -> Id
- updateVarType :: (Type -> Type) -> Id -> Id
- updateVarTypeM :: Monad m => (Type -> m Type) -> Id -> m Id
- mkGlobalVar :: IdDetails -> Name -> Type -> IdInfo -> Id
- mkLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id
- mkExportedLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id
- mkCoVar :: Name -> Type -> CoVar
- idInfo :: HasDebugCallStack => Id -> IdInfo
- idDetails :: Id -> IdDetails
- lazySetIdInfo :: Id -> IdInfo -> Var
- setIdDetails :: Id -> IdDetails -> Id
- globaliseId :: Id -> Id
- setIdExported :: Id -> Id
- setIdNotExported :: Id -> Id
- isId :: Var -> Bool
- isTyVar :: Var -> Bool
- isTcTyVar :: Var -> Bool
- isLocalVar :: Var -> Bool
- isLocalId :: Var -> Bool
- isCoVar :: Var -> Bool
- isNonCoVarId :: Var -> Bool
- isTyCoVar :: Var -> Bool
- isGlobalId :: Var -> Bool
- isExportedId :: Var -> Bool
- mustHaveLocalBinding :: Var -> Bool
- data TyVarBndr tyvar argf = TvBndr tyvar argf
- data ArgFlag
  - = Required
  - | Specified
  - | Inferred
- type TyVarBinder = TyVarBndr TyVar ArgFlag
- binderVar :: TyVarBndr tv argf -> tv
- binderVars :: [TyVarBndr tv argf] -> [tv]
- binderArgFlag :: TyVarBndr tv argf -> argf
- binderKind :: TyVarBndr TyVar argf -> Kind
- isVisibleArgFlag :: ArgFlag -> Bool
- isInvisibleArgFlag :: ArgFlag -> Bool
- sameVis :: ArgFlag -> ArgFlag -> Bool
- mkTyVar :: Name -> Kind -> TyVar
- mkTcTyVar :: Name -> Kind -> TcTyVarDetails -> TyVar
- tyVarName :: TyVar -> Name
- tyVarKind :: TyVar -> Kind
- tcTyVarDetails :: TyVar -> TcTyVarDetails
- setTcTyVarDetails :: TyVar -> TcTyVarDetails -> TyVar
- setTyVarName :: TyVar -> Name -> TyVar
- setTyVarUnique :: TyVar -> Unique -> TyVar
- setTyVarKind :: TyVar -> Kind -> TyVar
- updateTyVarKind :: (Kind -> Kind) -> TyVar -> TyVar
- updateTyVarKindM :: Monad m => (Kind -> m Kind) -> TyVar -> m TyVar
- nonDetCmpVar :: Var -> Var -> Ordering

# The main data type and synonyms

data Var #

Variable

Essentially a typed `Name`, that may also contain some additional information about the `Var` and it's use sites.

Instances

Eq Var # |
Methods (==) :: Var -> Var -> Bool # (/=) :: Var -> Var -> Bool #
Data Var # |

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Var -> c Var Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Var Source #

toConstr :: Var -> Constr Source #

dataTypeOf :: Var -> DataType Source #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Var) Source #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Var) Source #

gmapT :: (forall b. Data b => b -> b) -> Var -> Var Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Var -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Var -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Var -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Var -> m Var Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Var -> m Var Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Var -> m Var Source #

Ord Var # |
Methods compare :: Var -> Var -> Ordering # (<) :: Var -> Var -> Bool # (<=) :: Var -> Var -> Bool # (>) :: Var -> Var -> Bool # (>=) :: Var -> Var -> Bool # max :: Var -> Var -> Var # min :: Var -> Var -> Var #
Outputable Var # |
Methods ppr :: Var -> SDoc # pprPrec :: Rational -> Var -> SDoc #
Uniquable Var # |
Methods getUnique :: Var -> Unique #
HasOccName Var # |
Methods occName :: Var -> OccName #
NamedThing Var # |
Methods getOccName :: Var -> OccName # getName :: Var -> Name #
type PostRn Id ty # |
type PostRn Id ty = ty
type PostTc Id ty # |
type PostTc Id ty = ty

type CoVar = Id #

Coercion Variable

type Id = Var #

Identifier

type NcId = Id #

type DictId = EvId #

Dictionary Identifier

type DFunId = Id #

Dictionary Function Identifier

type EvVar = EvId #

Evidence Variable

type EqVar = EvId #

Equality Variable

type EvId = Id #

Evidence Identifier

type IpId = EvId #

Implicit parameter Identifier

type JoinId = Id #

type TyVar = Var #

Type or kind Variable

type TypeVar = Var #

Type Variable

type KindVar = Var #

Kind Variable

type TKVar = Var #

Type or Kind Variable

type TyCoVar = Id #

Type or Coercion Variable

# In and Out variants

type InVar = Var #

type InCoVar = CoVar #

type InId = Id #

type InTyVar = TyVar #

type OutVar = Var #

type OutCoVar = CoVar #

type OutId = Id #

type OutTyVar = TyVar #

## Taking `Var`s apart

varName :: Var -> Name #

varUnique :: Var -> Unique #

varType :: Var -> Kind #

The type or kind of the `Var` in question

## Modifying `Var`s

setVarName :: Var -> Name -> Var #

setVarUnique :: Var -> Unique -> Var #

setVarType :: Id -> Type -> Id #

updateVarType :: (Type -> Type) -> Id -> Id #

updateVarTypeM :: Monad m => (Type -> m Type) -> Id -> m Id #

## Constructing, taking apart, modifying `Id`s

mkGlobalVar :: IdDetails -> Name -> Type -> IdInfo -> Id #

mkLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id #

mkExportedLocalVar :: IdDetails -> Name -> Type -> IdInfo -> Id #

Exported `Var`s will not be removed as dead code

mkCoVar :: Name -> Type -> CoVar #

idInfo :: HasDebugCallStack => Id -> IdInfo #

idDetails :: Id -> IdDetails #

lazySetIdInfo :: Id -> IdInfo -> Var #

setIdDetails :: Id -> IdDetails -> Id #

globaliseId :: Id -> Id #

If it's a local, make it global

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

setIdNotExported :: Id -> Id #

We can only do this to LocalIds

## Predicates

isId :: Var -> Bool #

isTyVar :: Var -> Bool #

isTcTyVar :: Var -> Bool #

isLocalVar :: Var -> Bool #

`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.

isLocalId :: Var -> Bool #

isCoVar :: Var -> Bool #

isNonCoVarId :: Var -> Bool #

isTyCoVar :: Var -> Bool #

isGlobalId :: Var -> Bool #

isExportedId :: Var -> Bool #

`isExportedIdVar` means "don't throw this away"

mustHaveLocalBinding :: Var -> Bool #

`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

# TyVar's

data TyVarBndr tyvar argf #

Constructors

TvBndr tyvar argf |

Instances

(Data argf, Data tyvar) => Data (TyVarBndr tyvar argf) # |

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> TyVarBndr tyvar argf -> c (TyVarBndr tyvar argf) Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (TyVarBndr tyvar argf) Source #

toConstr :: TyVarBndr tyvar argf -> Constr Source #

dataTypeOf :: TyVarBndr tyvar argf -> DataType Source #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (TyVarBndr tyvar argf)) Source #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (TyVarBndr tyvar argf)) Source #

gmapT :: (forall b. Data b => b -> b) -> TyVarBndr tyvar argf -> TyVarBndr tyvar argf Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> TyVarBndr tyvar argf -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> TyVarBndr tyvar argf -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> TyVarBndr tyvar argf -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> TyVarBndr tyvar argf -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> TyVarBndr tyvar argf -> m (TyVarBndr tyvar argf) Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> TyVarBndr tyvar argf -> m (TyVarBndr tyvar argf) Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> TyVarBndr tyvar argf -> m (TyVarBndr tyvar argf) Source #

Outputable tv => Outputable (TyVarBndr tv ArgFlag) # |
Methods ppr :: TyVarBndr tv ArgFlag -> SDoc # pprPrec :: Rational -> TyVarBndr tv ArgFlag -> SDoc #
Outputable tv => Outputable (TyVarBndr tv TyConBndrVis) # |
Methods ppr :: TyVarBndr tv TyConBndrVis -> SDoc # pprPrec :: Rational -> TyVarBndr tv TyConBndrVis -> SDoc #
(Binary tv, Binary vis) => Binary (TyVarBndr tv vis) # |
Methods put_ :: BinHandle -> TyVarBndr tv vis -> IO () # put :: BinHandle -> TyVarBndr tv vis -> IO (Bin * (TyVarBndr tv vis)) # get :: BinHandle -> IO (TyVarBndr tv vis) #

data 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 [TyBinders and ArgFlags] in TyCoRep

Constructors

Required |
Specified |
Inferred |

Instances

Eq ArgFlag # |
Methods (==) :: ArgFlag -> ArgFlag -> Bool # (/=) :: ArgFlag -> ArgFlag -> Bool #
Data ArgFlag # |

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ArgFlag -> c ArgFlag Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ArgFlag Source #

toConstr :: ArgFlag -> Constr Source #

dataTypeOf :: ArgFlag -> DataType Source #

dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c ArgFlag) Source #

dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ArgFlag) Source #

gmapT :: (forall b. Data b => b -> b) -> ArgFlag -> ArgFlag Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ArgFlag -> r Source #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ArgFlag -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> ArgFlag -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ArgFlag -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ArgFlag -> m ArgFlag Source #

Outputable ArgFlag # |
Methods ppr :: ArgFlag -> SDoc # pprPrec :: Rational -> ArgFlag -> SDoc #
Binary ArgFlag # |
Methods put_ :: BinHandle -> ArgFlag -> IO () # put :: BinHandle -> ArgFlag -> IO (Bin * ArgFlag) # get :: BinHandle -> IO ArgFlag #
Outputable tv => Outputable (TyVarBndr tv ArgFlag) # |
Methods ppr :: TyVarBndr tv ArgFlag -> SDoc # pprPrec :: Rational -> TyVarBndr tv ArgFlag -> SDoc #

type TyVarBinder = TyVarBndr TyVar ArgFlag #

Type Variable Binder

A `TyVarBinder` 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

binderVar :: TyVarBndr tv argf -> tv #

binderVars :: [TyVarBndr tv argf] -> [tv] #

binderArgFlag :: TyVarBndr tv argf -> argf #

binderKind :: TyVarBndr TyVar argf -> Kind #

isVisibleArgFlag :: ArgFlag -> Bool #

Does this `ArgFlag` classify an argument that is written in Haskell?

isInvisibleArgFlag :: ArgFlag -> Bool #

Does this `ArgFlag` classify an argument that is not written in Haskell?

sameVis :: ArgFlag -> ArgFlag -> Bool #

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.

## Constructing TyVar's

mkTyVar :: Name -> Kind -> TyVar #

mkTcTyVar :: Name -> Kind -> TcTyVarDetails -> TyVar #

## Taking `TyVar`s apart

tyVarName :: TyVar -> Name #

tyVarKind :: TyVar -> Kind #

tcTyVarDetails :: TyVar -> TcTyVarDetails #

setTcTyVarDetails :: TyVar -> TcTyVarDetails -> TyVar #

## Modifying `TyVar`s

setTyVarName :: TyVar -> Name -> TyVar #

setTyVarUnique :: TyVar -> Unique -> TyVar #

setTyVarKind :: TyVar -> Kind -> TyVar #

updateTyVarKind :: (Kind -> Kind) -> TyVar -> TyVar #

updateTyVarKindM :: Monad m => (Kind -> m Kind) -> TyVar -> m TyVar #

nonDetCmpVar :: Var -> Var -> Ordering #

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]