GHC.Types.Name

ghc-lib-parser-9.10.1.20250103: The GHC API, decoupled from GHC versions

Safe Haskell | Ignore
Language | GHC2021

GHC.Types.Name

Contents

- The main types
  - Creating `Name`s
  - Manipulating and deconstructing `Name`s
  - Predicates on `Name`s
- Class `NamedThing` and overloaded friends
- Orphan instances

Description

GHC uses several kinds of name internally:

- `OccName`: see GHC.Types.Name.Occurrence
- `RdrName`: see GHC.Types.Name.Reader
- `Name` is the type of names that have had their scoping and binding resolved. They have an `OccName` but also a `Unique` that disambiguates Names that have the same `OccName` and indeed is used for all `Name` comparison. Names also contain information about where they originated from, see GHC.Types.Name
- `Id`: see GHC.Types.Id
- `Var`: see GHC.Types.Var

Names are one of:

- External, if they name things declared in other modules. Some external Names are wired in, i.e. they name primitives defined in the compiler itself
- Internal, if they name things in the module being compiled. Some internal Names are system names, if they are names manufactured by the compiler

Synopsis

- data Name
- data BuiltInSyntax
  - = BuiltInSyntax
  - | UserSyntax
- mkSystemName :: Unique -> OccName -> Name
- mkSystemNameAt :: Unique -> OccName -> SrcSpan -> Name
- mkInternalName :: Unique -> OccName -> SrcSpan -> Name
- mkClonedInternalName :: Unique -> Name -> Name
- mkDerivedInternalName :: (OccName -> OccName) -> Unique -> Name -> Name
- mkSystemVarName :: Unique -> FastString -> Name
- mkSysTvName :: Unique -> FastString -> Name
- mkFCallName :: Unique -> FastString -> Name
- mkExternalName :: Unique -> Module -> OccName -> SrcSpan -> Name
- mkWiredInName :: Module -> OccName -> Unique -> TyThing -> BuiltInSyntax -> Name
- nameUnique :: Name -> Unique
- setNameUnique :: Name -> Unique -> Name
- nameOccName :: Name -> OccName
- nameNameSpace :: Name -> NameSpace
- nameModule :: HasDebugCallStack => Name -> Module
- nameModule_maybe :: Name -> Maybe Module
- setNameLoc :: Name -> SrcSpan -> Name
- tidyNameOcc :: Name -> OccName -> Name
- localiseName :: Name -> Name
- namePun_maybe :: Name -> Maybe FastString
- pprName :: IsLine doc => Name -> doc
- nameSrcLoc :: Name -> SrcLoc
- nameSrcSpan :: Name -> SrcSpan
- pprNameDefnLoc :: Name -> SDoc
- pprDefinedAt :: Name -> SDoc
- pprFullName :: Module -> Name -> SDoc
- pprTickyName :: Module -> Name -> SDoc
- isSystemName :: Name -> Bool
- isInternalName :: Name -> Bool
- isExternalName :: Name -> Bool
- isTyVarName :: Name -> Bool
- isTyConName :: Name -> Bool
- isDataConName :: Name -> Bool
- isValName :: Name -> Bool
- isVarName :: Name -> Bool
- isDynLinkName :: Platform -> Module -> Name -> Bool
- isFieldName :: Name -> Bool
- isWiredInName :: Name -> Bool
- isWiredIn :: NamedThing thing => thing -> Bool
- isBuiltInSyntax :: Name -> Bool
- isTupleTyConName :: Name -> Bool
- isSumTyConName :: Name -> Bool
- isUnboxedTupleDataConLikeName :: Name -> Bool
- isHoleName :: Name -> Bool
- wiredInNameTyThing_maybe :: Name -> Maybe TyThing
- nameIsLocalOrFrom :: Module -> Name -> Bool
- nameIsExternalOrFrom :: Module -> Name -> Bool
- nameIsHomePackage :: Module -> Name -> Bool
- nameIsHomePackageImport :: Module -> Name -> Bool
- nameIsFromExternalPackage :: HomeUnit -> Name -> Bool
- stableNameCmp :: Name -> Name -> Ordering
- class NamedThing a where
  - getOccName :: a -> OccName
  - getName :: a -> Name
- getSrcLoc :: NamedThing a => a -> SrcLoc
- getSrcSpan :: NamedThing a => a -> SrcSpan
- getOccString :: NamedThing a => a -> String
- getOccFS :: NamedThing a => a -> FastString
- pprInfixName :: (Outputable a, NamedThing a) => a -> SDoc
- pprPrefixName :: NamedThing a => a -> SDoc
- pprModulePrefix :: PprStyle -> Module -> OccName -> SDoc
- pprNameUnqualified :: Name -> SDoc
- nameStableString :: Name -> String
- module GHC.Types.Name.Occurrence

# The main types

data Name #

A unique, unambiguous name for something, containing information about where that thing originated.

#### Instances

Instances details

NFData Name # |
Instance details Defined in GHC.Types.Name Methods rnf :: Name -> () #
Data Name # |
Instance details Defined in GHC.Types.Name Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Name -> c Name # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Name # toConstr :: Name -> Constr # dataTypeOf :: Name -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Name) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Name) # gmapT :: (forall b. Data b => b -> b) -> Name -> Name # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Name -> r # gmapQ :: (forall d. Data d => d -> u) -> Name -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Name -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Name -> m Name # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Name -> m Name # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Name -> m Name #
NamedThing Name # |
Instance details Defined in GHC.Types.Name Methods getOccName :: Name -> OccName # getName :: Name -> Name #
HasOccName Name # |
Instance details Defined in GHC.Types.Name Methods occName :: Name -> OccName #
Uniquable Name # |
Instance details Defined in GHC.Types.Name Methods getUnique :: Name -> Unique #
Binary Name # | Assumes that the `Name` is a non-binding one. See `putIfaceTopBndr` and `getIfaceTopBndr` for serializing binding `Name`s. See `UserData` for the rationale for this distinction.
Instance details Defined in GHC.Types.Name Methods put_ :: BinHandle -> Name -> IO () # put :: BinHandle -> Name -> IO (Bin Name) # get :: BinHandle -> IO Name #
Outputable Name # |
Instance details Defined in GHC.Types.Name Methods ppr :: Name -> SDoc #
OutputableBndr Name # |
Instance details Defined in GHC.Types.Name Methods pprBndr :: BindingSite -> Name -> SDoc # pprPrefixOcc :: Name -> SDoc # pprInfixOcc :: Name -> SDoc # bndrIsJoin_maybe :: Name -> JoinPointHood #
Eq Name # | The same comments as for `Name`'s `Ord` instance apply.
Instance details Defined in GHC.Types.Name Methods (==) :: Name -> Name -> Bool # (/=) :: Name -> Name -> Bool #
Ord Name # | Caution: This instance is implemented via `nonDetCmpUnique`, which means that the ordering is not stable across deserialization or rebuilds. See `nonDetCmpUnique` for further information, and #15240 for a bug caused by improper use of this instance.
Instance details Defined in GHC.Types.Name Methods compare :: Name -> Name -> Ordering # (<) :: Name -> Name -> Bool # (<=) :: Name -> Name -> Bool # (>) :: Name -> Name -> Bool # (>=) :: Name -> Name -> Bool # max :: Name -> Name -> Name # min :: Name -> Name -> Name #
type Anno Name # |
Instance details Defined in GHC.Hs.Extension type Anno Name = SrcSpanAnnN

data BuiltInSyntax #

BuiltInSyntax is for things like `(:)`, `[]` and tuples, which have special syntactic forms. They aren't in scope as such.

Constructors

BuiltInSyntax |
UserSyntax |

## Creating `Name`s

mkSystemName :: Unique -> OccName -> Name #

Create a name brought into being by the compiler

mkSystemNameAt :: Unique -> OccName -> SrcSpan -> Name #

mkInternalName :: Unique -> OccName -> SrcSpan -> Name #

Create a name which is (for now at least) local to the current module and hence does not need a `Module` to disambiguate it from other `Name`s

mkClonedInternalName :: Unique -> Name -> Name #

mkDerivedInternalName :: (OccName -> OccName) -> Unique -> Name -> Name #

mkSystemVarName :: Unique -> FastString -> Name #

mkSysTvName :: Unique -> FastString -> Name #

mkFCallName :: Unique -> FastString -> Name #

Make a name for a foreign call

mkExternalName :: Unique -> Module -> OccName -> SrcSpan -> Name #

Create a name which definitely originates in the given module

mkWiredInName :: Module -> OccName -> Unique -> TyThing -> BuiltInSyntax -> Name #

Create a name which is actually defined by the compiler itself

## Manipulating and deconstructing `Name`s

nameUnique :: Name -> Unique #

setNameUnique :: Name -> Unique -> Name #

nameOccName :: Name -> OccName #

nameNameSpace :: Name -> NameSpace #

nameModule :: HasDebugCallStack => Name -> Module #

nameModule_maybe :: Name -> Maybe Module #

setNameLoc :: Name -> SrcSpan -> Name #

tidyNameOcc :: Name -> OccName -> Name #

localiseName :: Name -> Name #

Make the `Name` into an internal name, regardless of what it was to begin with

namePun_maybe :: Name -> Maybe FastString #

pprName :: IsLine doc => Name -> doc #

nameSrcLoc :: Name -> SrcLoc #

nameSrcSpan :: Name -> SrcSpan #

pprNameDefnLoc :: Name -> SDoc #

pprDefinedAt :: Name -> SDoc #

pprFullName :: Module -> Name -> SDoc #

Print fully qualified name (with unit-id, module and unique)

pprTickyName :: Module -> Name -> SDoc #

Print a ticky ticky styled name

Module argument is the module to use for internal and system names. When printing the name in a ticky profile, the module name is included even for local things. However, ticky uses the format "x (M)" rather than "M.x". Hence, this function provides a separation from normal styling.

## Predicates on `Name`s

isSystemName :: Name -> Bool #

isInternalName :: Name -> Bool #

isExternalName :: Name -> Bool #

isTyVarName :: Name -> Bool #

isTyConName :: Name -> Bool #

isDataConName :: Name -> Bool #

isValName :: Name -> Bool #

isVarName :: Name -> Bool #

isDynLinkName :: Platform -> Module -> Name -> Bool #

Will the `Name` come from a dynamically linked package?

isFieldName :: Name -> Bool #

isWiredInName :: Name -> Bool #

isWiredIn :: NamedThing thing => thing -> Bool #

isBuiltInSyntax :: Name -> Bool #

isTupleTyConName :: Name -> Bool #

isSumTyConName :: Name -> Bool #

isUnboxedTupleDataConLikeName :: Name -> Bool #

This matches a datacon as well as its worker and promoted tycon.

isHoleName :: Name -> Bool #

wiredInNameTyThing_maybe :: Name -> Maybe TyThing #

nameIsLocalOrFrom :: Module -> Name -> Bool #

Returns True if the name is (a) Internal (b) External but from the specified module (c) External but from the `interactive` package

The key idea is that False means: the entity is defined in some other module you can find the details (type, fixity, instances) in some interface file those details will be stored in the EPT or HPT

True means: the entity is defined in this module or earlier in the GHCi session you can find details (type, fixity, instances) in the TcGblEnv or TcLclEnv

The isInteractiveModule part is because successive interactions of a GHCi session each give rise to a fresh module (Ghci1, Ghci2, etc), but they all come from the magic `interactive` package; and all the details are kept in the TcLclEnv, TcGblEnv, NOT in the HPT or EPT. See Note [The interactive package] in GHC.Runtime.Context

nameIsExternalOrFrom :: Module -> Name -> Bool #

Returns True if the name is external or from the `interactive` package See documentation of `nameIsLocalOrFrom` function

nameIsHomePackage :: Module -> Name -> Bool #

nameIsHomePackageImport :: Module -> Name -> Bool #

nameIsFromExternalPackage :: HomeUnit -> Name -> Bool #

Returns True if the Name comes from some other package: neither this package nor the interactive package.

stableNameCmp :: Name -> Name -> Ordering #

Compare Names lexicographically This only works for Names that originate in the source code or have been tidied.

# Class `NamedThing` and overloaded friends

class NamedThing a where #

A class allowing convenient access to the `Name` of various datatypes

Minimal complete definition

getName

Methods

getOccName :: a -> OccName #

getName :: a -> Name #

#### Instances

Instances details

NamedThing Class # |
Instance details Defined in GHC.Core.Class Methods getOccName :: Class -> OccName # getName :: Class -> Name #
NamedThing ConLike # |
Instance details Defined in GHC.Core.ConLike Methods getOccName :: ConLike -> OccName # getName :: ConLike -> Name #
NamedThing DataCon # |
Instance details Defined in GHC.Core.DataCon Methods getOccName :: DataCon -> OccName # getName :: DataCon -> Name #
NamedThing FamInst # |
Instance details Defined in GHC.Core.FamInstEnv Methods getOccName :: FamInst -> OccName # getName :: FamInst -> Name #
NamedThing ClsInst # |
Instance details Defined in GHC.Core.InstEnv Methods getOccName :: ClsInst -> OccName # getName :: ClsInst -> Name #
NamedThing PatSyn # |
Instance details Defined in GHC.Core.PatSyn Methods getOccName :: PatSyn -> OccName # getName :: PatSyn -> Name #
NamedThing TyCon # |
Instance details Defined in GHC.Core.TyCon Methods getOccName :: TyCon -> OccName # getName :: TyCon -> Name #
NamedThing IfaceClassOp # |
Instance details Defined in GHC.Iface.Syntax Methods getOccName :: IfaceClassOp -> OccName # getName :: IfaceClassOp -> Name #
NamedThing IfaceConDecl # |
Instance details Defined in GHC.Iface.Syntax Methods getOccName :: IfaceConDecl -> OccName # getName :: IfaceConDecl -> Name #
NamedThing IfaceDecl # |
Instance details Defined in GHC.Iface.Syntax Methods getOccName :: IfaceDecl -> OccName # getName :: IfaceDecl -> Name #
NamedThing HoleFitCandidate # |
Instance details Defined in GHC.Tc.Errors.Hole.FitTypes Methods getOccName :: HoleFitCandidate -> OccName # getName :: HoleFitCandidate -> Name #
NamedThing InvalidFamInstQTv # |
Instance details Defined in GHC.Tc.Errors.Types Methods getOccName :: InvalidFamInstQTv -> OccName # getName :: InvalidFamInstQTv -> Name #
NamedThing Name # |
Instance details Defined in GHC.Types.Name Methods getOccName :: Name -> OccName # getName :: Name -> Name #
NamedThing TyThing # |
Instance details Defined in GHC.Types.TyThing Methods getOccName :: TyThing -> OccName # getName :: TyThing -> Name #
NamedThing Var # |
Instance details Defined in GHC.Types.Var Methods getOccName :: Var -> OccName # getName :: Var -> Name #
NamedThing (CoAxiom br) # |
Instance details Defined in GHC.Core.Coercion.Axiom Methods getOccName :: CoAxiom br -> OccName # getName :: CoAxiom br -> Name #
NamedThing e => NamedThing (Located e) # |
Instance details Defined in GHC.Types.Name Methods getOccName :: Located e -> OccName # getName :: Located e -> Name #
NamedThing (Located a) => NamedThing (LocatedAn an a) # |
Instance details Defined in GHC.Parser.Annotation Methods getOccName :: LocatedAn an a -> OccName # getName :: LocatedAn an a -> Name #
NamedThing tv => NamedThing (VarBndr tv flag) # |
Instance details Defined in GHC.Types.Var Methods getOccName :: VarBndr tv flag -> OccName # getName :: VarBndr tv flag -> Name #
NamedThing (HsTyVarBndr flag GhcRn) # |
Instance details Defined in GHC.Hs.Type Methods getOccName :: HsTyVarBndr flag GhcRn -> OccName # getName :: HsTyVarBndr flag GhcRn -> Name #

getSrcLoc :: NamedThing a => a -> SrcLoc #

getSrcSpan :: NamedThing a => a -> SrcSpan #

getOccString :: NamedThing a => a -> String #

getOccFS :: NamedThing a => a -> FastString #

pprInfixName :: (Outputable a, NamedThing a) => a -> SDoc #

pprPrefixName :: NamedThing a => a -> SDoc #

pprModulePrefix :: PprStyle -> Module -> OccName -> SDoc #

pprNameUnqualified :: Name -> SDoc #

Print the string of Name unqualifiedly directly.

nameStableString :: Name -> String #

Get a string representation of a `Name` that's unique and stable across recompilations. Used for deterministic generation of binds for derived instances. eg. "$aeson_70dylHtv1FFGeai1IoxcQr$Data.Aeson.Types.Internal$String"

module GHC.Types.Name.Occurrence

# Orphan instances

NFData FieldLabel # |
Instance details Methods rnf :: FieldLabel -> () #