Id

ghc-8.6.3: The GHC API

Safe Haskell | None
Language | Haskell2010

Id

Contents

- The main types
- In and Out variants
  - Simple construction
  - Taking an Id apart
  - Modifying an Id
  - Predicates on Ids
  - Evidence variables
  - Join variables
  - Inline pragma stuff
  - One-shot lambdas
  - Reading `IdInfo` fields
  - Writing `IdInfo` fields

Description

GHC uses several kinds of name internally:

- `OccName`: see OccName
- `RdrName`: see RdrName
- `Name`: see Name
- `Id` represents names that not only have a `Name` but also a `Type` and some additional details (a `IdInfo` and one of `LocalIdDetails` or `GlobalIdDetails`) that are added, modified and inspected by various compiler passes. These `Var` names may either be global or local, see Var
- `Var`: see Var

Synopsis

- data Var
- type Id = Var
- isId :: Var -> Bool
- type InVar = Var
- type InId = Id
- type OutVar = Var
- type OutId = Id
- mkGlobalId :: IdDetails -> Name -> Type -> IdInfo -> Id
- mkVanillaGlobal :: Name -> Type -> Id
- mkVanillaGlobalWithInfo :: Name -> Type -> IdInfo -> Id
- mkLocalId :: Name -> Type -> Id
- mkLocalCoVar :: Name -> Type -> CoVar
- mkLocalIdOrCoVar :: Name -> Type -> Id
- mkLocalIdOrCoVarWithInfo :: Name -> Type -> IdInfo -> Id
- mkLocalIdWithInfo :: Name -> Type -> IdInfo -> Id
- mkExportedLocalId :: IdDetails -> Name -> Type -> Id
- mkExportedVanillaId :: Name -> Type -> Id
- mkSysLocal :: FastString -> Unique -> Type -> Id
- mkSysLocalM :: MonadUnique m => FastString -> Type -> m Id
- mkSysLocalOrCoVar :: FastString -> Unique -> Type -> Id
- mkSysLocalOrCoVarM :: MonadUnique m => FastString -> Type -> m Id
- mkUserLocal :: OccName -> Unique -> Type -> SrcSpan -> Id
- mkUserLocalOrCoVar :: OccName -> Unique -> Type -> SrcSpan -> Id
- mkTemplateLocals :: [Type] -> [Id]
- mkTemplateLocalsNum :: Int -> [Type] -> [Id]
- mkTemplateLocal :: Int -> Type -> Id
- mkWorkerId :: Unique -> Id -> Type -> Id
- idName :: Id -> Name
- idType :: Id -> Kind
- idUnique :: Id -> Unique
- idInfo :: HasDebugCallStack => Id -> IdInfo
- idDetails :: Id -> IdDetails
- recordSelectorTyCon :: Id -> RecSelParent
- setIdName :: Id -> Name -> Id
- setIdUnique :: Id -> Unique -> Id
- setIdType :: Id -> Type -> Id
- setIdExported :: Id -> Id
- setIdNotExported :: Id -> Id
- globaliseId :: Id -> Id
- localiseId :: Id -> Id
- setIdInfo :: Id -> IdInfo -> Id
- lazySetIdInfo :: Id -> IdInfo -> Id
- modifyIdInfo :: HasDebugCallStack => (IdInfo -> IdInfo) -> Id -> Id
- maybeModifyIdInfo :: Maybe IdInfo -> Id -> Id
- zapLamIdInfo :: Id -> Id
- zapIdDemandInfo :: Id -> Id
- zapIdUsageInfo :: Id -> Id
- zapIdUsageEnvInfo :: Id -> Id
- zapIdUsedOnceInfo :: Id -> Id
- zapIdTailCallInfo :: Id -> Id
- zapFragileIdInfo :: Id -> Id
- zapIdStrictness :: Id -> Id
- zapStableUnfolding :: Id -> Id
- transferPolyIdInfo :: Id -> [Var] -> Id -> Id
- isImplicitId :: Id -> Bool
- isDeadBinder :: Id -> Bool
- isStrictId :: Id -> Bool
- isExportedId :: Var -> Bool
- isLocalId :: Var -> Bool
- isGlobalId :: Var -> Bool
- isRecordSelector :: Id -> Bool
- isNaughtyRecordSelector :: Id -> Bool
- isPatSynRecordSelector :: Id -> Bool
- isDataConRecordSelector :: Id -> Bool
- isClassOpId_maybe :: Id -> Maybe Class
- isDFunId :: Id -> Bool
- isPrimOpId :: Id -> Bool
- isPrimOpId_maybe :: Id -> Maybe PrimOp
- isFCallId :: Id -> Bool
- isFCallId_maybe :: Id -> Maybe ForeignCall
- isDataConWorkId :: Id -> Bool
- isDataConWorkId_maybe :: Id -> Maybe DataCon
- isDataConId_maybe :: Id -> Maybe DataCon
- idDataCon :: Id -> DataCon
- isConLikeId :: Id -> Bool
- isBottomingId :: Var -> Bool
- idIsFrom :: Module -> Id -> Bool
- hasNoBinding :: Id -> Bool
- type DictId = EvId
- isDictId :: Id -> Bool
- isEvVar :: Var -> Bool
- type JoinId = Id
- isJoinId :: Var -> Bool
- isJoinId_maybe :: Var -> Maybe JoinArity
- idJoinArity :: JoinId -> JoinArity
- asJoinId :: Id -> JoinArity -> JoinId
- asJoinId_maybe :: Id -> Maybe JoinArity -> Id
- zapJoinId :: Id -> Id
- idInlinePragma :: Id -> InlinePragma
- setInlinePragma :: Id -> InlinePragma -> Id
- modifyInlinePragma :: Id -> (InlinePragma -> InlinePragma) -> Id
- idInlineActivation :: Id -> Activation
- setInlineActivation :: Id -> Activation -> Id
- idRuleMatchInfo :: Id -> RuleMatchInfo
- isOneShotBndr :: Var -> Bool
- isProbablyOneShotLambda :: Id -> Bool
- setOneShotLambda :: Id -> Id
- clearOneShotLambda :: Id -> Id
- updOneShotInfo :: Id -> OneShotInfo -> Id
- setIdOneShotInfo :: Id -> OneShotInfo -> Id
- isStateHackType :: Type -> Bool
- stateHackOneShot :: OneShotInfo
- typeOneShot :: Type -> OneShotInfo
- idArity :: Id -> Arity
- idCallArity :: Id -> Arity
- idFunRepArity :: Id -> RepArity
- idUnfolding :: Id -> Unfolding
- realIdUnfolding :: Id -> Unfolding
- idSpecialisation :: Id -> RuleInfo
- idCoreRules :: Id -> [CoreRule]
- idHasRules :: Id -> Bool
- idCafInfo :: Id -> CafInfo
- idOneShotInfo :: Id -> OneShotInfo
- idStateHackOneShotInfo :: Id -> OneShotInfo
- idOccInfo :: Id -> OccInfo
- isNeverLevPolyId :: Id -> Bool
- setIdUnfolding :: Id -> Unfolding -> Id
- setCaseBndrEvald :: StrictnessMark -> Id -> Id
- setIdArity :: Id -> Arity -> Id
- setIdCallArity :: Id -> Arity -> Id
- setIdSpecialisation :: Id -> RuleInfo -> Id
- setIdCafInfo :: Id -> CafInfo -> Id
- setIdOccInfo :: Id -> OccInfo -> Id
- zapIdOccInfo :: Id -> Id
- setIdDemandInfo :: Id -> Demand -> Id
- setIdStrictness :: Id -> StrictSig -> Id
- idDemandInfo :: Id -> Demand
- idStrictness :: Id -> StrictSig

# The main types

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 # |
Instance details Defined in Var Methods (==) :: Var -> Var -> Bool # (/=) :: Var -> Var -> Bool #
Data Var # |
Instance details Defined in 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 # |
Instance details Defined in 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 #
OutputableBndr Var # |
Instance details Defined in PprCore Methods pprBndr :: BindingSite -> Var -> SDoc # pprPrefixOcc :: Var -> SDoc # pprInfixOcc :: Var -> SDoc # bndrIsJoin_maybe :: Var -> Maybe Int #
Outputable Var # |
Instance details Defined in Var Methods ppr :: Var -> SDoc # pprPrec :: Rational -> Var -> SDoc #
Uniquable Var # |
Instance details Defined in Var Methods getUnique :: Var -> Unique #
HasOccName Var # |
Instance details Defined in Var Methods occName :: Var -> OccName #
NamedThing Var # |
Instance details Defined in Var Methods getOccName :: Var -> OccName # getName :: Var -> Name #

type Id = Var #

Identifier

isId :: Var -> Bool #

# In and Out variants

type InVar = Var #

type InId = Id #

type OutVar = Var #

type OutId = Id #

## Simple construction

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

For an explanation of global vs. local `Id`s, see Var

mkVanillaGlobal :: Name -> Type -> Id #

Make a global `Id` without any extra information at all

mkVanillaGlobalWithInfo :: Name -> Type -> IdInfo -> Id #

Make a global `Id` with no global information but some generic `IdInfo`

mkLocalId :: Name -> Type -> Id #

For an explanation of global vs. local `Id`s, see Var

mkLocalCoVar :: Name -> Type -> CoVar #

Make a local CoVar

mkLocalIdOrCoVar :: Name -> Type -> Id #

Like `mkLocalId`, but checks the type to see if it should make a covar

mkLocalIdOrCoVarWithInfo :: Name -> Type -> IdInfo -> Id #

Make a local id, with the IdDetails set to CoVarId if the type indicates so.

mkLocalIdWithInfo :: Name -> Type -> IdInfo -> Id #

mkExportedLocalId :: IdDetails -> Name -> Type -> Id #

Create a local `Id` that is marked as exported. This prevents things attached to it from being removed as dead code. See Note [Exported LocalIds]

mkExportedVanillaId :: Name -> Type -> Id #

mkSysLocal :: FastString -> Unique -> Type -> Id #

Create a system local `Id`. These are local `Id`s (see Var) that are created by the compiler out of thin air

mkSysLocalM :: MonadUnique m => FastString -> Type -> m Id #

mkSysLocalOrCoVar :: FastString -> Unique -> Type -> Id #

Like `mkSysLocal`, but checks to see if we have a covar type

mkSysLocalOrCoVarM :: MonadUnique m => FastString -> Type -> m Id #

mkUserLocal :: OccName -> Unique -> Type -> SrcSpan -> Id #

Create a user local `Id`. These are local `Id`s (see Var) with a name and location that the user might recognize

mkUserLocalOrCoVar :: OccName -> Unique -> Type -> SrcSpan -> Id #

Like `mkUserLocal`, but checks if we have a coercion type

mkTemplateLocals :: [Type] -> [Id] #

Create a template local for a series of types

mkTemplateLocalsNum :: Int -> [Type] -> [Id] #

Create a template local for a series of type, but start from a specified template local

mkTemplateLocal :: Int -> Type -> Id #

Create a template local: a family of system local `Id`s in bijection with `Int`s, typically used in unfoldings

mkWorkerId :: Unique -> Id -> Type -> Id #

Workers get local names. CoreTidy will externalise these if necessary

## Taking an Id apart

idName :: Id -> Name #

idType :: Id -> Kind #

idUnique :: Id -> Unique #

idInfo :: HasDebugCallStack => Id -> IdInfo #

idDetails :: Id -> IdDetails #

recordSelectorTyCon :: Id -> RecSelParent #

If the `Id` is that for a record selector, extract the `sel_tycon`. Panic otherwise.

## Modifying an Id

setIdName :: Id -> Name -> Id #

setIdUnique :: Id -> Unique -> Id #

setIdType :: Id -> Type -> Id #

Not only does this set the `Id` `Type`, it also evaluates the type to try and reduce space usage

setIdExported :: Id -> Id #

setIdNotExported :: Id -> Id #

globaliseId :: Id -> Id #

If it's a local, make it global

localiseId :: Id -> Id #

setIdInfo :: Id -> IdInfo -> Id #

lazySetIdInfo :: Id -> IdInfo -> Id #

modifyIdInfo :: HasDebugCallStack => (IdInfo -> IdInfo) -> Id -> Id #

maybeModifyIdInfo :: Maybe IdInfo -> Id -> Id #

zapLamIdInfo :: Id -> Id #

zapIdDemandInfo :: Id -> Id #

zapIdUsageInfo :: Id -> Id #

zapIdUsageEnvInfo :: Id -> Id #

zapIdUsedOnceInfo :: Id -> Id #

zapIdTailCallInfo :: Id -> Id #

zapFragileIdInfo :: Id -> Id #

zapIdStrictness :: Id -> Id #

zapStableUnfolding :: Id -> Id #

transferPolyIdInfo :: Id -> [Var] -> Id -> Id #

## Predicates on Ids

isImplicitId :: Id -> Bool #

`isImplicitId` tells whether an `Id`s info is implied by other declarations, so we don't need to put its signature in an interface file, even if it's mentioned in some other interface unfolding.

isDeadBinder :: Id -> Bool #

isStrictId :: Id -> Bool #

This predicate says whether the `Id` has a strict demand placed on it or has a type such that it can always be evaluated strictly (i.e an unlifted type, as of GHC 7.6). We need to check separately whether the `Id` has a so-called "strict type" because if the demand for the given `id` hasn't been computed yet but `id` has a strict type, we still want `isStrictId id` to be `True`.

isExportedId :: Var -> Bool #

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

isLocalId :: Var -> Bool #

isGlobalId :: Var -> Bool #

isRecordSelector :: Id -> Bool #

isNaughtyRecordSelector :: Id -> Bool #

isPatSynRecordSelector :: Id -> Bool #

isDataConRecordSelector :: Id -> Bool #

isClassOpId_maybe :: Id -> Maybe Class #

isDFunId :: Id -> Bool #

isPrimOpId :: Id -> Bool #

isPrimOpId_maybe :: Id -> Maybe PrimOp #

isFCallId :: Id -> Bool #

isFCallId_maybe :: Id -> Maybe ForeignCall #

isDataConWorkId :: Id -> Bool #

isDataConWorkId_maybe :: Id -> Maybe DataCon #

isDataConId_maybe :: Id -> Maybe DataCon #

idDataCon :: Id -> DataCon #

Get from either the worker or the wrapper `Id` to the `DataCon`. Currently used only in the desugarer.

INVARIANT: `idDataCon (dataConWrapId d) = d`: remember, `dataConWrapId` can return either the wrapper or the worker

isConLikeId :: Id -> Bool #

isBottomingId :: Var -> Bool #

Returns true if an application to n args would diverge

idIsFrom :: Module -> Id -> Bool #

hasNoBinding :: Id -> Bool #

Returns `True` of an `Id` which may not have a binding, even though it is defined in this module.

## Evidence variables

type DictId = EvId #

Dictionary Identifier

isDictId :: Id -> Bool #

isEvVar :: Var -> Bool #

## Join variables

type JoinId = Id #

isJoinId :: Var -> Bool #

isJoinId_maybe :: Var -> Maybe JoinArity #

idJoinArity :: JoinId -> JoinArity #

asJoinId :: Id -> JoinArity -> JoinId infixl 1 #

asJoinId_maybe :: Id -> Maybe JoinArity -> Id infixl 1 #

zapJoinId :: Id -> Id #

## Inline pragma stuff

idInlinePragma :: Id -> InlinePragma #

setInlinePragma :: Id -> InlinePragma -> Id infixl 1 #

modifyInlinePragma :: Id -> (InlinePragma -> InlinePragma) -> Id #

idInlineActivation :: Id -> Activation #

setInlineActivation :: Id -> Activation -> Id infixl 1 #

idRuleMatchInfo :: Id -> RuleMatchInfo #

## One-shot lambdas

isOneShotBndr :: Var -> Bool #

Returns whether the lambda associated with the `Id` is certainly applied at most once This one is the "business end", called externally. It works on type variables as well as Ids, returning True Its main purpose is to encapsulate the Horrible State Hack See Note [The state-transformer hack] in CoreArity

isProbablyOneShotLambda :: Id -> Bool #

setOneShotLambda :: Id -> Id #

clearOneShotLambda :: Id -> Id #

updOneShotInfo :: Id -> OneShotInfo -> Id #

setIdOneShotInfo :: Id -> OneShotInfo -> Id infixl 1 #

isStateHackType :: Type -> Bool #

stateHackOneShot :: OneShotInfo #

Should we apply the state hack to values of this `Type`?

typeOneShot :: Type -> OneShotInfo #

## Reading `IdInfo` fields

idArity :: Id -> Arity #

idCallArity :: Id -> Arity #

idFunRepArity :: Id -> RepArity #

idUnfolding :: Id -> Unfolding #

realIdUnfolding :: Id -> Unfolding #

idSpecialisation :: Id -> RuleInfo #

idCoreRules :: Id -> [CoreRule] #

idHasRules :: Id -> Bool #

idCafInfo :: Id -> CafInfo infixl 1 #

idOneShotInfo :: Id -> OneShotInfo #

idStateHackOneShotInfo :: Id -> OneShotInfo #

Like `idOneShotInfo`, but taking the Horrible State Hack in to account See Note [The state-transformer hack] in CoreArity

idOccInfo :: Id -> OccInfo #

isNeverLevPolyId :: Id -> Bool #

## Writing `IdInfo` fields

setIdUnfolding :: Id -> Unfolding -> Id infixl 1 #

setCaseBndrEvald :: StrictnessMark -> Id -> Id #

setIdArity :: Id -> Arity -> Id infixl 1 #

setIdCallArity :: Id -> Arity -> Id infixl 1 #

setIdSpecialisation :: Id -> RuleInfo -> Id infixl 1 #

setIdCafInfo :: Id -> CafInfo -> Id #

setIdOccInfo :: Id -> OccInfo -> Id infixl 1 #

zapIdOccInfo :: Id -> Id #

setIdDemandInfo :: Id -> Demand -> Id infixl 1 #

setIdStrictness :: Id -> StrictSig -> Id infixl 1 #

idDemandInfo :: Id -> Demand #

idStrictness :: Id -> StrictSig #