OccName

ghc-8.6.3: The GHC API

Safe Haskell | None
Language | Haskell2010

OccName

Contents

- The `NameSpace` type
  - Construction
  - Pretty Printing
- The `OccName` type
  - Construction
  - Derived `OccName`s
  - Deconstruction
- The `OccEnv` type
- The `OccSet` type
- Tidying up

Description

GHC uses several kinds of name internally:

- `OccName` represents names as strings with just a little more information: the "namespace" that the name came from, e.g. the namespace of value, type constructors or data constructors
- `RdrName`: see RdrName
- `Name`: see Name
- `Id`: see Id
- `Var`: see Var

Synopsis

- data NameSpace
- nameSpacesRelated :: NameSpace -> NameSpace -> Bool
- tcName :: NameSpace
- clsName :: NameSpace
- tcClsName :: NameSpace
- dataName :: NameSpace
- varName :: NameSpace
- tvName :: NameSpace
- srcDataName :: NameSpace
- pprNameSpace :: NameSpace -> SDoc
- pprNonVarNameSpace :: NameSpace -> SDoc
- pprNameSpaceBrief :: NameSpace -> SDoc
- data OccName
- pprOccName :: OccName -> SDoc
- mkOccName :: NameSpace -> String -> OccName
- mkOccNameFS :: NameSpace -> FastString -> OccName
- mkVarOcc :: String -> OccName
- mkVarOccFS :: FastString -> OccName
- mkDataOcc :: String -> OccName
- mkDataOccFS :: FastString -> OccName
- mkTyVarOcc :: String -> OccName
- mkTyVarOccFS :: FastString -> OccName
- mkTcOcc :: String -> OccName
- mkTcOccFS :: FastString -> OccName
- mkClsOcc :: String -> OccName
- mkClsOccFS :: FastString -> OccName
- mkDFunOcc :: String -> Bool -> OccSet -> OccName
- setOccNameSpace :: NameSpace -> OccName -> OccName
- demoteOccName :: OccName -> Maybe OccName
- class HasOccName name where
  - occName :: name -> OccName
- isDerivedOccName :: OccName -> Bool
- mkDataConWrapperOcc :: OccName -> OccName
- mkWorkerOcc :: OccName -> OccName
- mkMatcherOcc :: OccName -> OccName
- mkBuilderOcc :: OccName -> OccName
- mkDefaultMethodOcc :: OccName -> OccName
- isDefaultMethodOcc :: OccName -> Bool
- isTypeableBindOcc :: OccName -> Bool
- mkNewTyCoOcc :: OccName -> OccName
- mkClassOpAuxOcc :: OccName -> OccName
- mkCon2TagOcc :: OccName -> OccName
- mkTag2ConOcc :: OccName -> OccName
- mkMaxTagOcc :: OccName -> OccName
- mkClassDataConOcc :: OccName -> OccName
- mkDictOcc :: OccName -> OccName
- mkIPOcc :: OccName -> OccName
- mkSpecOcc :: OccName -> OccName
- mkForeignExportOcc :: OccName -> OccName
- mkRepEqOcc :: OccName -> OccName
- mkGenR :: OccName -> OccName
- mkGen1R :: OccName -> OccName
- mkDataTOcc :: OccName -> OccSet -> OccName
- mkDataCOcc :: OccName -> OccSet -> OccName
- mkDataConWorkerOcc :: OccName -> OccName
- mkSuperDictSelOcc :: Int -> OccName -> OccName
- mkSuperDictAuxOcc :: Int -> OccName -> OccName
- mkLocalOcc :: Unique -> OccName -> OccName
- mkMethodOcc :: OccName -> OccName
- mkInstTyTcOcc :: String -> OccSet -> OccName
- mkInstTyCoOcc :: OccName -> OccName
- mkEqPredCoOcc :: OccName -> OccName
- mkRecFldSelOcc :: String -> OccName
- mkTyConRepOcc :: OccName -> OccName
- occNameFS :: OccName -> FastString
- occNameString :: OccName -> String
- occNameSpace :: OccName -> NameSpace
- isVarOcc :: OccName -> Bool
- isTvOcc :: OccName -> Bool
- isTcOcc :: OccName -> Bool
- isDataOcc :: OccName -> Bool
- isDataSymOcc :: OccName -> Bool
- isSymOcc :: OccName -> Bool
- isValOcc :: OccName -> Bool
- parenSymOcc :: OccName -> SDoc -> SDoc
- startsWithUnderscore :: OccName -> Bool
- isTcClsNameSpace :: NameSpace -> Bool
- isTvNameSpace :: NameSpace -> Bool
- isDataConNameSpace :: NameSpace -> Bool
- isVarNameSpace :: NameSpace -> Bool
- isValNameSpace :: NameSpace -> Bool
- data OccEnv a
- emptyOccEnv :: OccEnv a
- unitOccEnv :: OccName -> a -> OccEnv a
- extendOccEnv :: OccEnv a -> OccName -> a -> OccEnv a
- mapOccEnv :: (a -> b) -> OccEnv a -> OccEnv b
- lookupOccEnv :: OccEnv a -> OccName -> Maybe a
- mkOccEnv :: [(OccName, a)] -> OccEnv a
- mkOccEnv_C :: (a -> a -> a) -> [(OccName, a)] -> OccEnv a
- extendOccEnvList :: OccEnv a -> [(OccName, a)] -> OccEnv a
- elemOccEnv :: OccName -> OccEnv a -> Bool
- occEnvElts :: OccEnv a -> [a]
- foldOccEnv :: (a -> b -> b) -> b -> OccEnv a -> b
- plusOccEnv :: OccEnv a -> OccEnv a -> OccEnv a
- plusOccEnv_C :: (a -> a -> a) -> OccEnv a -> OccEnv a -> OccEnv a
- extendOccEnv_C :: (a -> a -> a) -> OccEnv a -> OccName -> a -> OccEnv a
- extendOccEnv_Acc :: (a -> b -> b) -> (a -> b) -> OccEnv b -> OccName -> a -> OccEnv b
- filterOccEnv :: (elt -> Bool) -> OccEnv elt -> OccEnv elt
- delListFromOccEnv :: OccEnv a -> [OccName] -> OccEnv a
- delFromOccEnv :: OccEnv a -> OccName -> OccEnv a
- alterOccEnv :: (Maybe elt -> Maybe elt) -> OccEnv elt -> OccName -> OccEnv elt
- pprOccEnv :: (a -> SDoc) -> OccEnv a -> SDoc
- type OccSet = UniqSet OccName
- emptyOccSet :: OccSet
- unitOccSet :: OccName -> OccSet
- mkOccSet :: [OccName] -> OccSet
- extendOccSet :: OccSet -> OccName -> OccSet
- extendOccSetList :: OccSet -> [OccName] -> OccSet
- unionOccSets :: OccSet -> OccSet -> OccSet
- unionManyOccSets :: [OccSet] -> OccSet
- minusOccSet :: OccSet -> OccSet -> OccSet
- elemOccSet :: OccName -> OccSet -> Bool
- isEmptyOccSet :: OccSet -> Bool
- intersectOccSet :: OccSet -> OccSet -> OccSet
- intersectsOccSet :: OccSet -> OccSet -> Bool
- filterOccSet :: (OccName -> Bool) -> OccSet -> OccSet
- type TidyOccEnv = UniqFM Int
- emptyTidyOccEnv :: TidyOccEnv
- initTidyOccEnv :: [OccName] -> TidyOccEnv
- tidyOccName :: TidyOccEnv -> OccName -> (TidyOccEnv, OccName)
- avoidClashesOccEnv :: TidyOccEnv -> [OccName] -> TidyOccEnv
- type FastStringEnv a = UniqFM a
- emptyFsEnv :: FastStringEnv a
- lookupFsEnv :: FastStringEnv a -> FastString -> Maybe a
- extendFsEnv :: FastStringEnv a -> FastString -> a -> FastStringEnv a
- mkFsEnv :: [(FastString, a)] -> FastStringEnv a

# The `NameSpace` type

data NameSpace #

Instances

Eq NameSpace # |
Instance details Defined in OccName Methods (==) :: NameSpace -> NameSpace -> Bool # (/=) :: NameSpace -> NameSpace -> Bool #
Ord NameSpace # |
Instance details Defined in OccName Methods compare :: NameSpace -> NameSpace -> Ordering # (<) :: NameSpace -> NameSpace -> Bool # (<=) :: NameSpace -> NameSpace -> Bool # (>) :: NameSpace -> NameSpace -> Bool # (>=) :: NameSpace -> NameSpace -> Bool # max :: NameSpace -> NameSpace -> NameSpace # min :: NameSpace -> NameSpace -> NameSpace #
Binary NameSpace # |
Instance details Defined in OccName Methods put_ :: BinHandle -> NameSpace -> IO () # put :: BinHandle -> NameSpace -> IO (Bin NameSpace) # get :: BinHandle -> IO NameSpace #

nameSpacesRelated :: NameSpace -> NameSpace -> Bool #

## Construction

There are two forms of data constructor:

Source data constructors
  The data constructors mentioned in Haskell source code
Real data constructors
  The data constructors of the representation type, which may not be the same as the source type

For example:

    data T = T !(Int, Int)

The source datacon has type `(Int, Int) -> T` The real datacon has type `Int -> Int -> T`

GHC chooses a representation based on the strictness etc.

tcName :: NameSpace #

clsName :: NameSpace #

tcClsName :: NameSpace #

dataName :: NameSpace #

varName :: NameSpace #

tvName :: NameSpace #

srcDataName :: NameSpace #

## Pretty Printing

pprNameSpace :: NameSpace -> SDoc #

pprNonVarNameSpace :: NameSpace -> SDoc #

pprNameSpaceBrief :: NameSpace -> SDoc #

# The `OccName` type

data OccName #

Occurrence Name

In this context that means: "classified (i.e. as a type name, value name, etc) but not qualified and not yet resolved"

Instances

Eq OccName # |
Instance details Defined in OccName Methods (==) :: OccName -> OccName -> Bool # (/=) :: OccName -> OccName -> Bool #
Data OccName # |
Instance details Defined in OccName Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> OccName -> c OccName Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c OccName Source # toConstr :: OccName -> Constr Source # dataTypeOf :: OccName -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c OccName) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OccName) Source # gmapT :: (forall b. Data b => b -> b) -> OccName -> OccName Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> OccName -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> OccName -> r Source # gmapQ :: (forall d. Data d => d -> u) -> OccName -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> OccName -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> OccName -> m OccName Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> OccName -> m OccName Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> OccName -> m OccName Source #
Ord OccName # |
Instance details Defined in OccName Methods compare :: OccName -> OccName -> Ordering # (<) :: OccName -> OccName -> Bool # (<=) :: OccName -> OccName -> Bool # (>) :: OccName -> OccName -> Bool # (>=) :: OccName -> OccName -> Bool # max :: OccName -> OccName -> OccName # min :: OccName -> OccName -> OccName #
NFData OccName # |
Instance details Defined in OccName Methods rnf :: OccName -> () Source #
OutputableBndr OccName # |
Instance details Defined in OccName Methods pprBndr :: BindingSite -> OccName -> SDoc # pprPrefixOcc :: OccName -> SDoc # pprInfixOcc :: OccName -> SDoc # bndrIsJoin_maybe :: OccName -> Maybe Int #
Outputable OccName # |
Instance details Defined in OccName Methods ppr :: OccName -> SDoc # pprPrec :: Rational -> OccName -> SDoc #
Uniquable OccName # |
Instance details Defined in OccName Methods getUnique :: OccName -> Unique #
Binary OccName # |
Instance details Defined in OccName Methods put_ :: BinHandle -> OccName -> IO () # put :: BinHandle -> OccName -> IO (Bin OccName) # get :: BinHandle -> IO OccName #
HasOccName OccName # |
Instance details Defined in OccName Methods occName :: OccName -> OccName #

pprOccName :: OccName -> SDoc #

## Construction

mkOccName :: NameSpace -> String -> OccName #

mkOccNameFS :: NameSpace -> FastString -> OccName #

mkVarOcc :: String -> OccName #

mkVarOccFS :: FastString -> OccName #

mkDataOcc :: String -> OccName #

mkDataOccFS :: FastString -> OccName #

mkTyVarOcc :: String -> OccName #

mkTyVarOccFS :: FastString -> OccName #

mkTcOcc :: String -> OccName #

mkTcOccFS :: FastString -> OccName #

mkClsOcc :: String -> OccName #

mkClsOccFS :: FastString -> OccName #

mkDFunOcc #

Arguments

:: String | Typically the class and type glommed together e.g. `OrdMaybe`. Only used in debug mode, for extra clarity
-> Bool | Is this a hs-boot instance DFun?
-> OccSet | avoid these Occs
-> OccName | E.g. `$f3OrdMaybe`

setOccNameSpace :: NameSpace -> OccName -> OccName #

demoteOccName :: OccName -> Maybe OccName #

class HasOccName name where #

Other names in the compiler add additional information to an OccName. This class provides a consistent way to access the underlying OccName.

Methods

occName :: name -> OccName #

Instances

HasOccName Name # |
Instance details Defined in Name Methods occName :: Name -> OccName #
HasOccName OccName # |
Instance details Defined in OccName Methods occName :: OccName -> OccName #
HasOccName GlobalRdrElt # |
Instance details Defined in TcHoleErrors Methods occName :: GlobalRdrElt -> OccName #
HasOccName RdrName # |
Instance details Defined in RdrName Methods occName :: RdrName -> OccName #
HasOccName Var # |
Instance details Defined in Var Methods occName :: Var -> OccName #
HasOccName IfaceConDecl # |
Instance details Defined in IfaceSyn Methods occName :: IfaceConDecl -> OccName #
HasOccName IfaceClassOp # |
Instance details Defined in IfaceSyn Methods occName :: IfaceClassOp -> OccName #
HasOccName IfaceDecl # |
Instance details Defined in IfaceSyn Methods occName :: IfaceDecl -> OccName #
HasOccName TcBinder # |
Instance details Defined in TcRnTypes Methods occName :: TcBinder -> OccName #
HasOccName name => HasOccName (IEWrappedName name) # |
Instance details Defined in HsImpExp Methods occName :: IEWrappedName name -> OccName #
(HasOccName a, HasOccName b) => HasOccName (Either a b) # |
Instance details Defined in TcHoleErrors Methods occName :: Either a b -> OccName #

## Derived `OccName`s

isDerivedOccName :: OccName -> Bool #

Test for definitions internally generated by GHC. This predicte is used to suppress printing of internal definitions in some debug prints

mkDataConWrapperOcc :: OccName -> OccName #

mkWorkerOcc :: OccName -> OccName #

mkMatcherOcc :: OccName -> OccName #

mkBuilderOcc :: OccName -> OccName #

mkDefaultMethodOcc :: OccName -> OccName #

isDefaultMethodOcc :: OccName -> Bool #

isTypeableBindOcc :: OccName -> Bool #

Is an `OccName` one of a Typeable `TyCon` or `Module` binding? This is needed as these bindings are renamed differently. See Note [Grand plan for Typeable] in TcTypeable.

mkNewTyCoOcc :: OccName -> OccName #

mkClassOpAuxOcc :: OccName -> OccName #

mkCon2TagOcc :: OccName -> OccName #

mkTag2ConOcc :: OccName -> OccName #

mkMaxTagOcc :: OccName -> OccName #

mkClassDataConOcc :: OccName -> OccName #

mkDictOcc :: OccName -> OccName #

mkIPOcc :: OccName -> OccName #

mkSpecOcc :: OccName -> OccName #

mkForeignExportOcc :: OccName -> OccName #

mkRepEqOcc :: OccName -> OccName #

mkGenR :: OccName -> OccName #

mkGen1R :: OccName -> OccName #

mkDataTOcc #

Arguments

:: OccName | TyCon or data con string
-> OccSet | avoid these Occs
-> OccName | E.g. `$f3OrdMaybe` data T = MkT ... deriving( Data ) needs definitions for $tT :: Data.Generics.Basics.DataType $cMkT :: Data.Generics.Basics.Constr

mkDataCOcc #

Arguments

:: OccName | TyCon or data con string
-> OccSet | avoid these Occs
-> OccName | E.g. `$f3OrdMaybe` data T = MkT ... deriving( Data ) needs definitions for $tT :: Data.Generics.Basics.DataType $cMkT :: Data.Generics.Basics.Constr

mkDataConWorkerOcc :: OccName -> OccName #

mkSuperDictSelOcc #

Arguments

:: Int | Index of superclass, e.g. 3
-> OccName | Class, e.g. `Ord`
-> OccName | Derived `Occname`, e.g. `$p3Ord`

mkSuperDictAuxOcc :: Int -> OccName -> OccName #

mkLocalOcc #

Arguments

:: Unique | Unique to combine with the `OccName`
-> OccName | Local name, e.g. `sat`
-> OccName | Nice unique version, e.g. `$L23sat`

mkMethodOcc :: OccName -> OccName #

mkInstTyTcOcc #

Arguments

:: String | Family name, e.g. `Map`
-> OccSet | avoid these Occs
-> OccName |
    R:Map

Derive a name for the representation type constructor of a `data`/`newtype` instance.

mkInstTyCoOcc :: OccName -> OccName #

mkEqPredCoOcc :: OccName -> OccName #

mkRecFldSelOcc :: String -> OccName #

mkTyConRepOcc :: OccName -> OccName #

## Deconstruction

occNameFS :: OccName -> FastString #

occNameString :: OccName -> String #

occNameSpace :: OccName -> NameSpace #

isVarOcc :: OccName -> Bool #

isTvOcc :: OccName -> Bool #

isTcOcc :: OccName -> Bool #

isDataOcc :: OccName -> Bool #

isDataSymOcc :: OccName -> Bool #

Test if the `OccName` is a data constructor that starts with a symbol (e.g. `:`, or `[]`)

isSymOcc :: OccName -> Bool #

Test if the `OccName` is that for any operator (whether it is a data constructor or variable or whatever)

isValOcc :: OccName -> Bool #

Value `OccNames`s are those that are either in the variable or data constructor namespaces

parenSymOcc :: OccName -> SDoc -> SDoc #

Wrap parens around an operator

startsWithUnderscore :: OccName -> Bool #

Haskell 98 encourages compilers to suppress warnings about unsed names in a pattern if they start with `_`: this implements that test

isTcClsNameSpace :: NameSpace -> Bool #

isTvNameSpace :: NameSpace -> Bool #

isDataConNameSpace :: NameSpace -> Bool #

isVarNameSpace :: NameSpace -> Bool #

isValNameSpace :: NameSpace -> Bool #

# The `OccEnv` type

data OccEnv a #

Instances

Data a => Data (OccEnv a) # |
Instance details Defined in OccName Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> OccEnv a -> c (OccEnv a) Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (OccEnv a) Source # toConstr :: OccEnv a -> Constr Source # dataTypeOf :: OccEnv a -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (OccEnv a)) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (OccEnv a)) Source # gmapT :: (forall b. Data b => b -> b) -> OccEnv a -> OccEnv a Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> OccEnv a -> r Source # gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> OccEnv a -> r Source # gmapQ :: (forall d. Data d => d -> u) -> OccEnv a -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> OccEnv a -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> OccEnv a -> m (OccEnv a) Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> OccEnv a -> m (OccEnv a) Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> OccEnv a -> m (OccEnv a) Source #
Outputable a => Outputable (OccEnv a) # |
Instance details Defined in OccName Methods ppr :: OccEnv a -> SDoc # pprPrec :: Rational -> OccEnv a -> SDoc #

emptyOccEnv :: OccEnv a #

unitOccEnv :: OccName -> a -> OccEnv a #

extendOccEnv :: OccEnv a -> OccName -> a -> OccEnv a #

mapOccEnv :: (a -> b) -> OccEnv a -> OccEnv b #

lookupOccEnv :: OccEnv a -> OccName -> Maybe a #

mkOccEnv :: [(OccName, a)] -> OccEnv a #

mkOccEnv_C :: (a -> a -> a) -> [(OccName, a)] -> OccEnv a #

extendOccEnvList :: OccEnv a -> [(OccName, a)] -> OccEnv a #

elemOccEnv :: OccName -> OccEnv a -> Bool #

occEnvElts :: OccEnv a -> [a] #

foldOccEnv :: (a -> b -> b) -> b -> OccEnv a -> b #

plusOccEnv :: OccEnv a -> OccEnv a -> OccEnv a #

plusOccEnv_C :: (a -> a -> a) -> OccEnv a -> OccEnv a -> OccEnv a #

extendOccEnv_C :: (a -> a -> a) -> OccEnv a -> OccName -> a -> OccEnv a #

extendOccEnv_Acc :: (a -> b -> b) -> (a -> b) -> OccEnv b -> OccName -> a -> OccEnv b #

filterOccEnv :: (elt -> Bool) -> OccEnv elt -> OccEnv elt #

delListFromOccEnv :: OccEnv a -> [OccName] -> OccEnv a #

delFromOccEnv :: OccEnv a -> OccName -> OccEnv a #

alterOccEnv :: (Maybe elt -> Maybe elt) -> OccEnv elt -> OccName -> OccEnv elt #

pprOccEnv :: (a -> SDoc) -> OccEnv a -> SDoc #

# The `OccSet` type

type OccSet = UniqSet OccName #

emptyOccSet :: OccSet #

unitOccSet :: OccName -> OccSet #

mkOccSet :: [OccName] -> OccSet #

extendOccSet :: OccSet -> OccName -> OccSet #

extendOccSetList :: OccSet -> [OccName] -> OccSet #

unionOccSets :: OccSet -> OccSet -> OccSet #

unionManyOccSets :: [OccSet] -> OccSet #

minusOccSet :: OccSet -> OccSet -> OccSet #

elemOccSet :: OccName -> OccSet -> Bool #

isEmptyOccSet :: OccSet -> Bool #

intersectOccSet :: OccSet -> OccSet -> OccSet #

intersectsOccSet :: OccSet -> OccSet -> Bool #

filterOccSet :: (OccName -> Bool) -> OccSet -> OccSet #

# Tidying up

type TidyOccEnv = UniqFM Int #

emptyTidyOccEnv :: TidyOccEnv #

initTidyOccEnv :: [OccName] -> TidyOccEnv #

tidyOccName :: TidyOccEnv -> OccName -> (TidyOccEnv, OccName) #

avoidClashesOccEnv :: TidyOccEnv -> [OccName] -> TidyOccEnv #

type FastStringEnv a = UniqFM a #

A non-deterministic set of FastStrings. See Note [Deterministic UniqFM] in UniqDFM for explanation why it's not deterministic and why it matters. Use DFastStringEnv if the set eventually gets converted into a list or folded over in a way where the order changes the generated code.

emptyFsEnv :: FastStringEnv a #

lookupFsEnv :: FastStringEnv a -> FastString -> Maybe a #

extendFsEnv :: FastStringEnv a -> FastString -> a -> FastStringEnv a #

mkFsEnv :: [(FastString, a)] -> FastStringEnv a #