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

Safe Haskell | Ignore
Language | GHC2021

GHC.Types.Name.Cache

Contents

- OrigNameCache
- Known-key names

Description

The Name Cache

Synopsis

- data NameCache = NameCache {
  - nsUniqChar :: !Char
  - nsNames :: !(MVar OrigNameCache)
  }
- newNameCache :: IO NameCache
- newNameCacheWith :: Char -> OrigNameCache -> IO NameCache
- initNameCache :: Char -> [Name] -> IO NameCache
- takeUniqFromNameCache :: NameCache -> IO Unique
- updateNameCache' :: NameCache -> (OrigNameCache -> IO (OrigNameCache, c)) -> IO c
- updateNameCache :: NameCache -> Module -> OccName -> (OrigNameCache -> IO (OrigNameCache, c)) -> IO c
- type OrigNameCache = ModuleEnv (OccEnv Name)
- lookupOrigNameCache :: OrigNameCache -> Module -> OccName -> Maybe Name
- extendOrigNameCache' :: OrigNameCache -> Name -> OrigNameCache
- extendOrigNameCache :: OrigNameCache -> Module -> OccName -> Name -> OrigNameCache
- knownKeysOrigNameCache :: OrigNameCache
- isKnownOrigName_maybe :: Module -> OccName -> Maybe Name

# Documentation

data NameCache #

The NameCache makes sure that there is just one Unique assigned for each original name; i.e. (module-name, occ-name) pair and provides something of a lookup mechanism for those names.

Constructors

NameCache |

Fields

- nsUniqChar :: !Char
- nsNames :: !(MVar OrigNameCache)

newNameCache :: IO NameCache #

Initialize a new name cache

newNameCacheWith :: Char -> OrigNameCache -> IO NameCache #

This is a version of `newNameCache` that lets you supply your own unique tag and set of known key names. This can go wrong if the tag supplied is one reserved by GHC for internal purposes. See #26055 for an example.

Use `newNameCache` when possible.

initNameCache :: Char -> [Name] -> IO NameCache #

Deprecated: Use newNameCache or newNameCacheWith instead

This takes a tag for uniques to be generated and the list of knownKeyNames These must be initialized properly to ensure that names generated from this NameCache do not conflict with known key names.

Use `newNameCache` or `newNameCacheWith` instead

takeUniqFromNameCache :: NameCache -> IO Unique #

updateNameCache' :: NameCache -> (OrigNameCache -> IO (OrigNameCache, c)) -> IO c #

Update the name cache with the given function

updateNameCache :: NameCache -> Module -> OccName -> (OrigNameCache -> IO (OrigNameCache, c)) -> IO c #

Update the name cache with the given function

Additionally, it ensures that the given Module and OccName are evaluated. If not, chaos can ensue: we read the name-cache then pull on mod (say) which does some stuff that modifies the name cache This did happen, with tycon_mod in GHC.IfaceToCore.tcIfaceAlt (DataAlt..)

# OrigNameCache

type OrigNameCache = ModuleEnv (OccEnv Name) #

Per-module cache of original `OccName`s given `Name`s

lookupOrigNameCache :: OrigNameCache -> Module -> OccName -> Maybe Name #

extendOrigNameCache' :: OrigNameCache -> Name -> OrigNameCache #

extendOrigNameCache :: OrigNameCache -> Module -> OccName -> Name -> OrigNameCache #

# Known-key names

knownKeysOrigNameCache :: OrigNameCache #

isKnownOrigName_maybe :: Module -> OccName -> Maybe Name #