Id

ghc-7.10.2: The GHC API

Safe Haskell | None
Language | Haskell2010

Id

Contents

- The main types
  - Simple construction
  - Taking an Id apart
  - Modifying an Id
  - Predicates on Ids
  - Evidence 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
- mkGlobalId :: IdDetails -> Name -> Type -> IdInfo -> Id
- mkVanillaGlobal :: Name -> Type -> Id
- mkVanillaGlobalWithInfo :: Name -> Type -> IdInfo -> Id
- mkLocalId :: Name -> Type -> Id
- mkLocalIdWithInfo :: Name -> Type -> IdInfo -> Id
- mkExportedLocalId :: IdDetails -> Name -> Type -> Id
- mkSysLocal :: FastString -> Unique -> Type -> Id
- mkSysLocalM :: MonadUnique m => FastString -> Type -> m Id
- mkUserLocal :: OccName -> Unique -> Type -> SrcSpan -> Id
- mkUserLocalM :: MonadUnique m => OccName -> Type -> SrcSpan -> m Id
- mkDerivedLocalM :: MonadUnique m => (OccName -> OccName) -> Id -> Type -> m Id
- mkTemplateLocals :: [Type] -> [Id]
- mkTemplateLocalsNum :: Int -> [Type] -> [Id]
- mkTemplateLocal :: Int -> Type -> Id
- mkWorkerId :: Unique -> Id -> Type -> Id
- mkWiredInIdName :: Module -> FastString -> Unique -> Id -> Name
- idName :: Id -> Name
- idType :: Id -> Kind
- idUnique :: Id -> Unique
- idInfo :: Id -> IdInfo
- idDetails :: Id -> IdDetails
- idRepArity :: Id -> RepArity
- recordSelectorFieldLabel :: Id -> (TyCon, FieldLabel)
- 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 :: (IdInfo -> IdInfo) -> Id -> Id
- maybeModifyIdInfo :: Maybe IdInfo -> Id -> Id
- zapLamIdInfo :: Id -> Id
- zapIdDemandInfo :: Id -> Id
- zapIdUsageInfo :: Id -> Id
- zapFragileIdInfo :: Id -> Id
- zapIdStrictness :: 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
- 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 :: Id -> Bool
- idIsFrom :: Module -> Id -> Bool
- hasNoBinding :: Id -> Bool
- type DictId = EvId
- isDictId :: Id -> Bool
- dfunNSilent :: Id -> Int
- isEvVar :: Var -> Bool
- 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
- isOneShotLambda :: Id -> 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
- idUnfolding :: Id -> Unfolding
- realIdUnfolding :: Id -> Unfolding
- idSpecialisation :: Id -> SpecInfo
- idCoreRules :: Id -> [CoreRule]
- idHasRules :: Id -> Bool
- idCafInfo :: Id -> CafInfo
- idOneShotInfo :: Id -> OneShotInfo
- idOccInfo :: Id -> OccInfo
- setIdUnfoldingLazily :: Id -> Unfolding -> Id
- setIdUnfolding :: Id -> Unfolding -> Id
- setIdArity :: Id -> Arity -> Id
- setIdCallArity :: Id -> Arity -> Id
- setIdSpecialisation :: Id -> SpecInfo -> 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 Source

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

Instances

Eq Var |
Data Var |
Ord Var |
Outputable Var |
Uniquable Var |
NamedThing Var |
type PostRn Id ty = ty |
type PostTc Id ty = ty |

type Id = Var Source

isId :: Var -> Bool Source

## Simple construction

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

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

mkVanillaGlobal :: Name -> Type -> Id Source

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

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

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

mkLocalId :: Name -> Type -> Id Source

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

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

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

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]

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

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 Source

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

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

mkUserLocalM :: MonadUnique m => OccName -> Type -> SrcSpan -> m Id Source

mkDerivedLocalM :: MonadUnique m => (OccName -> OccName) -> Id -> Type -> m Id Source

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

Create a template local for a series of types

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

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

mkTemplateLocal :: Int -> Type -> Id Source

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 Source

Workers get local names. CoreTidy will externalise these if necessary

mkWiredInIdName :: Module -> FastString -> Unique -> Id -> Name Source

## Taking an Id apart

idName :: Id -> Name Source

idType :: Id -> Kind Source

idUnique :: Id -> Unique Source

idInfo :: Id -> IdInfo Source

idDetails :: Id -> IdDetails Source

idRepArity :: Id -> RepArity Source

recordSelectorFieldLabel :: Id -> (TyCon, FieldLabel) Source

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

## Modifying an Id

setIdName :: Id -> Name -> Id Source

setIdUnique :: Id -> Unique -> Id Source

setIdType :: Id -> Type -> Id Source

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

setIdExported :: Id -> Id Source

setIdNotExported :: Id -> Id Source

globaliseId :: Id -> Id Source

If it's a local, make it global

localiseId :: Id -> Id Source

setIdInfo :: Id -> IdInfo -> Id Source

lazySetIdInfo :: Id -> IdInfo -> Id Source

modifyIdInfo :: (IdInfo -> IdInfo) -> Id -> Id Source

maybeModifyIdInfo :: Maybe IdInfo -> Id -> Id Source

zapLamIdInfo :: Id -> Id Source

zapIdDemandInfo :: Id -> Id Source

zapIdUsageInfo :: Id -> Id Source

zapFragileIdInfo :: Id -> Id Source

zapIdStrictness :: Id -> Id Source

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

## Predicates on Ids

isImplicitId :: Id -> Bool Source

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

isStrictId :: Id -> Bool Source

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 Source

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

isLocalId :: Var -> Bool Source

isGlobalId :: Var -> Bool Source

isRecordSelector :: Id -> Bool Source

isNaughtyRecordSelector :: Id -> Bool Source

isClassOpId_maybe :: Id -> Maybe Class Source

isDFunId :: Id -> Bool Source

isPrimOpId :: Id -> Bool Source

isPrimOpId_maybe :: Id -> Maybe PrimOp Source

isFCallId :: Id -> Bool Source

isFCallId_maybe :: Id -> Maybe ForeignCall Source

isDataConWorkId :: Id -> Bool Source

isDataConWorkId_maybe :: Id -> Maybe DataCon Source

isDataConId_maybe :: Id -> Maybe DataCon Source

idDataCon :: Id -> DataCon Source

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 Source

isBottomingId :: Id -> Bool Source

Returns true if an application to n args would diverge

idIsFrom :: Module -> Id -> Bool Source

hasNoBinding :: Id -> Bool Source

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

## Evidence variables

type DictId = EvId Source

isDictId :: Id -> Bool Source

dfunNSilent :: Id -> Int Source

isEvVar :: Var -> Bool Source

## Inline pragma stuff

idInlinePragma :: Id -> InlinePragma Source

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

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

idInlineActivation :: Id -> Activation Source

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

idRuleMatchInfo :: Id -> RuleMatchInfo Source

## One-shot lambdas

isOneShotBndr :: Var -> Bool Source

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

isOneShotLambda :: Id -> Bool Source

Returns whether the lambda associated with the `Id` is certainly applied at most once. You probably want to use `isOneShotBndr` instead

isProbablyOneShotLambda :: Id -> Bool Source

setOneShotLambda :: Id -> Id Source

clearOneShotLambda :: Id -> Id Source

updOneShotInfo :: Id -> OneShotInfo -> Id Source

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

isStateHackType :: Type -> Bool Source

stateHackOneShot :: OneShotInfo Source

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

typeOneShot :: Type -> OneShotInfo Source

## Reading `IdInfo` fields

idArity :: Id -> Arity Source

idCallArity :: Id -> Arity Source

idUnfolding :: Id -> Unfolding Source

realIdUnfolding :: Id -> Unfolding Source

idSpecialisation :: Id -> SpecInfo Source

idCoreRules :: Id -> [CoreRule] Source

idHasRules :: Id -> Bool Source

idCafInfo :: Id -> CafInfo infixl 1 Source

idOneShotInfo :: Id -> OneShotInfo Source

idOccInfo :: Id -> OccInfo Source

## Writing `IdInfo` fields

setIdUnfoldingLazily :: Id -> Unfolding -> Id infixl 1 Source

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

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

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

setIdSpecialisation :: Id -> SpecInfo -> Id infixl 1 Source

setIdCafInfo :: Id -> CafInfo -> Id Source

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

zapIdOccInfo :: Id -> Id Source

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

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

idDemandInfo :: Id -> Demand Source

idStrictness :: Id -> StrictSig Source