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

Safe Haskell | Ignore
Language | GHC2021

GHC.Core.Map.Type

Contents

- Re-export generic interface
- Maps over `Type`s
  - With explicit scoping
- Utilities for use by friends only

Synopsis

- class Functor m => TrieMap (m :: Type -> Type) where
  - type Key (m :: Type -> Type)
  - emptyTM :: m a
  - lookupTM :: Key m -> m b -> Maybe b
  - alterTM :: Key m -> XT b -> m b -> m b
  - filterTM :: (a -> Bool) -> m a -> m a
  - foldTM :: (a -> b -> b) -> m a -> b -> b
- type XT a = Maybe a -> Maybe a
- data TypeMap a
- emptyTypeMap :: TypeMap a
- extendTypeMap :: TypeMap a -> Type -> a -> TypeMap a
- lookupTypeMap :: TypeMap a -> Type -> Maybe a
- foldTypeMap :: (a -> b -> b) -> b -> TypeMap a -> b
- data LooseTypeMap a
- data CmEnv
- lookupCME :: CmEnv -> Var -> Maybe BoundVar
- extendTypeMapWithScope :: TypeMap a -> CmEnv -> Type -> a -> TypeMap a
- lookupTypeMapWithScope :: TypeMap a -> CmEnv -> Type -> Maybe a
- mkDeBruijnContext :: [Var] -> CmEnv
- extendCME :: CmEnv -> Var -> CmEnv
- extendCMEs :: CmEnv -> [Var] -> CmEnv
- emptyCME :: CmEnv
- type TypeMapG = GenMap TypeMapX
- type CoercionMapG = GenMap CoercionMapX
- data DeBruijn a = D CmEnv a
- deBruijnize :: a -> DeBruijn a
- eqDeBruijnType :: DeBruijn Type -> DeBruijn Type -> Bool
- eqDeBruijnVar :: DeBruijn Var -> DeBruijn Var -> Bool
- data BndrMap a
- xtBndr :: CmEnv -> Var -> XT a -> BndrMap a -> BndrMap a
- lkBndr :: CmEnv -> Var -> BndrMap a -> Maybe a
- data VarMap a
- xtVar :: CmEnv -> Var -> XT a -> VarMap a -> VarMap a
- lkVar :: CmEnv -> Var -> VarMap a -> Maybe a
- lkDFreeVar :: Var -> DVarEnv a -> Maybe a
- xtDFreeVar :: Var -> XT a -> DVarEnv a -> DVarEnv a
- xtDNamed :: NamedThing n => n -> XT a -> DNameEnv a -> DNameEnv a
- lkDNamed :: NamedThing n => n -> DNameEnv a -> Maybe a

# Re-export generic interface

class Functor m => TrieMap (m :: Type -> Type) where #

Associated Types

type Key (m :: Type -> Type) #

Methods

emptyTM :: m a #

lookupTM :: Key m -> m b -> Maybe b #

alterTM :: Key m -> XT b -> m b -> m b #

filterTM :: (a -> Bool) -> m a -> m a #

foldTM :: (a -> b -> b) -> m a -> b -> b #

#### Instances

Instances details

TrieMap IntMap # |

Instance details

Defined in GHC.Data.TrieMap

Associated Types

type Key IntMap |
Instance details Defined in GHC.Data.TrieMap type Key IntMap = Int

Methods

emptyTM :: IntMap a #

lookupTM :: Key IntMap -> IntMap b -> Maybe b #

alterTM :: Key IntMap -> XT b -> IntMap b -> IntMap b #

filterTM :: (a -> Bool) -> IntMap a -> IntMap a #

foldTM :: (a -> b -> b) -> IntMap a -> b -> b #

TrieMap LabelMap # |

Instance details

Defined in GHC.Cmm.Dataflow.Label

Associated Types

type Key LabelMap |
Instance details Defined in GHC.Cmm.Dataflow.Label type Key LabelMap = Label

Methods

emptyTM :: LabelMap a #

lookupTM :: Key LabelMap -> LabelMap b -> Maybe b #

alterTM :: Key LabelMap -> XT b -> LabelMap b -> LabelMap b #

filterTM :: (a -> Bool) -> LabelMap a -> LabelMap a #

foldTM :: (a -> b -> b) -> LabelMap a -> b -> b #

TrieMap CoreMap # |

Instance details

Defined in GHC.Core.Map.Expr

Associated Types

type Key CoreMap |
Instance details Defined in GHC.Core.Map.Expr type Key CoreMap = CoreExpr

Methods

emptyTM :: CoreMap a #

lookupTM :: Key CoreMap -> CoreMap b -> Maybe b #

alterTM :: Key CoreMap -> XT b -> CoreMap b -> CoreMap b #

filterTM :: (a -> Bool) -> CoreMap a -> CoreMap a #

foldTM :: (a -> b -> b) -> CoreMap a -> b -> b #

TrieMap BndrMap # |

Instance details

Defined in GHC.Core.Map.Type

Associated Types

type Key BndrMap |
Instance details Defined in GHC.Core.Map.Type type Key BndrMap = Var

Methods

emptyTM :: BndrMap a #

lookupTM :: Key BndrMap -> BndrMap b -> Maybe b #

alterTM :: Key BndrMap -> XT b -> BndrMap b -> BndrMap b #

filterTM :: (a -> Bool) -> BndrMap a -> BndrMap a #

foldTM :: (a -> b -> b) -> BndrMap a -> b -> b #

TrieMap LooseTypeMap # |

Instance details

Defined in GHC.Core.Map.Type

Associated Types

type Key LooseTypeMap |
Instance details Defined in GHC.Core.Map.Type type Key LooseTypeMap = Type

Methods

emptyTM :: LooseTypeMap a #

lookupTM :: Key LooseTypeMap -> LooseTypeMap b -> Maybe b #

alterTM :: Key LooseTypeMap -> XT b -> LooseTypeMap b -> LooseTypeMap b #

filterTM :: (a -> Bool) -> LooseTypeMap a -> LooseTypeMap a #

foldTM :: (a -> b -> b) -> LooseTypeMap a -> b -> b #

TrieMap TypeMap # |

Instance details

Defined in GHC.Core.Map.Type

Associated Types

type Key TypeMap |
Instance details Defined in GHC.Core.Map.Type type Key TypeMap = Type

Methods

emptyTM :: TypeMap a #

lookupTM :: Key TypeMap -> TypeMap b -> Maybe b #

alterTM :: Key TypeMap -> XT b -> TypeMap b -> TypeMap b #

filterTM :: (a -> Bool) -> TypeMap a -> TypeMap a #

foldTM :: (a -> b -> b) -> TypeMap a -> b -> b #

TrieMap VarMap # |

Instance details

Defined in GHC.Core.Map.Type

Associated Types

type Key VarMap |
Instance details Defined in GHC.Core.Map.Type type Key VarMap = Var

Methods

emptyTM :: VarMap a #

lookupTM :: Key VarMap -> VarMap b -> Maybe b #

alterTM :: Key VarMap -> XT b -> VarMap b -> VarMap b #

filterTM :: (a -> Bool) -> VarMap a -> VarMap a #

foldTM :: (a -> b -> b) -> VarMap a -> b -> b #

Ord k => TrieMap (Map k) # |

Instance details

Defined in GHC.Data.TrieMap

Associated Types

type Key (Map k) |
Instance details Defined in GHC.Data.TrieMap type Key (Map k) = k

Methods

emptyTM :: Map k a #

lookupTM :: Key (Map k) -> Map k b -> Maybe b #

alterTM :: Key (Map k) -> XT b -> Map k b -> Map k b #

filterTM :: (a -> Bool) -> Map k a -> Map k a #

foldTM :: (a -> b -> b) -> Map k a -> b -> b #

(Eq (Key m), TrieMap m) => TrieMap (GenMap m) # |

Instance details

Defined in GHC.Data.TrieMap

Associated Types

type Key (GenMap m) |
Instance details Defined in GHC.Data.TrieMap type Key (GenMap m) = Key m

Methods

emptyTM :: GenMap m a #

lookupTM :: Key (GenMap m) -> GenMap m b -> Maybe b #

alterTM :: Key (GenMap m) -> XT b -> GenMap m b -> GenMap m b #

filterTM :: (a -> Bool) -> GenMap m a -> GenMap m a #

foldTM :: (a -> b -> b) -> GenMap m a -> b -> b #

TrieMap m => TrieMap (ListMap m) # |

Instance details

Defined in GHC.Data.TrieMap

Associated Types

type Key (ListMap m) |
Instance details Defined in GHC.Data.TrieMap type Key (ListMap m) = [Key m]

Methods

emptyTM :: ListMap m a #

lookupTM :: Key (ListMap m) -> ListMap m b -> Maybe b #

alterTM :: Key (ListMap m) -> XT b -> ListMap m b -> ListMap m b #

filterTM :: (a -> Bool) -> ListMap m a -> ListMap m a #

foldTM :: (a -> b -> b) -> ListMap m a -> b -> b #

TrieMap m => TrieMap (MaybeMap m) # |

Instance details

Defined in GHC.Data.TrieMap

Associated Types

type Key (MaybeMap m) |
Instance details Defined in GHC.Data.TrieMap type Key (MaybeMap m) = Maybe (Key m)

Methods

emptyTM :: MaybeMap m a #

lookupTM :: Key (MaybeMap m) -> MaybeMap m b -> Maybe b #

alterTM :: Key (MaybeMap m) -> XT b -> MaybeMap m b -> MaybeMap m b #

filterTM :: (a -> Bool) -> MaybeMap m a -> MaybeMap m a #

foldTM :: (a -> b -> b) -> MaybeMap m a -> b -> b #

Uniquable key => TrieMap (UniqDFM key) # |

Instance details

Defined in GHC.Data.TrieMap

Associated Types

type Key (UniqDFM key) |
Instance details Defined in GHC.Data.TrieMap type Key (UniqDFM key) = key

Methods

emptyTM :: UniqDFM key a #

lookupTM :: Key (UniqDFM key) -> UniqDFM key b -> Maybe b #

alterTM :: Key (UniqDFM key) -> XT b -> UniqDFM key b -> UniqDFM key b #

filterTM :: (a -> Bool) -> UniqDFM key a -> UniqDFM key a #

foldTM :: (a -> b -> b) -> UniqDFM key a -> b -> b #

type XT a = Maybe a -> Maybe a #

# Maps over `Type`s

data TypeMap a #

`TypeMap a` is a map from `Type` to `a`. If you are a client, this is the type you want. The keys in this map may have different kinds.

#### Instances

Instances details

Functor TypeMap # |
Instance details Defined in GHC.Core.Map.Type Methods fmap :: (a -> b) -> TypeMap a -> TypeMap b # (<$) :: a -> TypeMap b -> TypeMap a #
TrieMap TypeMap # |

Instance details

Defined in GHC.Core.Map.Type

Associated Types

type Key TypeMap |
Instance details Defined in GHC.Core.Map.Type type Key TypeMap = Type

Methods

emptyTM :: TypeMap a #

lookupTM :: Key TypeMap -> TypeMap b -> Maybe b #

alterTM :: Key TypeMap -> XT b -> TypeMap b -> TypeMap b #

filterTM :: (a -> Bool) -> TypeMap a -> TypeMap a #

foldTM :: (a -> b -> b) -> TypeMap a -> b -> b #

type Key TypeMap # |
Instance details Defined in GHC.Core.Map.Type type Key TypeMap = Type

emptyTypeMap :: TypeMap a #

extendTypeMap :: TypeMap a -> Type -> a -> TypeMap a #

lookupTypeMap :: TypeMap a -> Type -> Maybe a #

foldTypeMap :: (a -> b -> b) -> b -> TypeMap a -> b #

data LooseTypeMap a #

A `LooseTypeMap` doesn't do a kind-check. Thus, when lookup up (t |> g), you'll find entries inserted under (t), even if (g) is non-reflexive.

#### Instances

Instances details

Functor LooseTypeMap # |
Instance details Defined in GHC.Core.Map.Type Methods fmap :: (a -> b) -> LooseTypeMap a -> LooseTypeMap b # (<$) :: a -> LooseTypeMap b -> LooseTypeMap a #
TrieMap LooseTypeMap # |

Instance details

Defined in GHC.Core.Map.Type

Associated Types

type Key LooseTypeMap |
Instance details Defined in GHC.Core.Map.Type type Key LooseTypeMap = Type

Methods

emptyTM :: LooseTypeMap a #

lookupTM :: Key LooseTypeMap -> LooseTypeMap b -> Maybe b #

alterTM :: Key LooseTypeMap -> XT b -> LooseTypeMap b -> LooseTypeMap b #

filterTM :: (a -> Bool) -> LooseTypeMap a -> LooseTypeMap a #

foldTM :: (a -> b -> b) -> LooseTypeMap a -> b -> b #

type Key LooseTypeMap # |
Instance details Defined in GHC.Core.Map.Type type Key LooseTypeMap = Type

## With explicit scoping

data CmEnv #

lookupCME :: CmEnv -> Var -> Maybe BoundVar #

extendTypeMapWithScope :: TypeMap a -> CmEnv -> Type -> a -> TypeMap a #

Extend a `TypeMap` with a type in the given context. `extendTypeMapWithScope m (mkDeBruijnContext [a,b,c]) t v` is equivalent to `extendTypeMap m (forall a b c. t) v`, but allows reuse of the context over multiple insertions.

lookupTypeMapWithScope :: TypeMap a -> CmEnv -> Type -> Maybe a #

mkDeBruijnContext :: [Var] -> CmEnv #

Construct a deBruijn environment with the given variables in scope. e.g. `mkDeBruijnEnv [a,b,c]` constructs a context `forall a b c.`

extendCME :: CmEnv -> Var -> CmEnv #

extendCMEs :: CmEnv -> [Var] -> CmEnv #

emptyCME :: CmEnv #

# Utilities for use by friends only

type TypeMapG = GenMap TypeMapX #

`TypeMapG a` is a map from `DeBruijn Type` to `a`. The extended key makes it suitable for recursive traversal, since it can track binders, but it is strictly internal to this module. If you are including a `TypeMap` inside another `TrieMap`, this is the type you want. Note that this lookup does not do a kind-check. Thus, all keys in this map must have the same kind. Also note that this map respects the distinction between `Type` and `Constraint`, despite the fact that they are equivalent type synonyms in Core.

type CoercionMapG = GenMap CoercionMapX #

data DeBruijn a #

`DeBruijn a` represents `a` modulo alpha-renaming. This is achieved by equipping the value with a `CmEnv`, which tracks an on-the-fly deBruijn numbering. This allows us to define an `Eq` instance for `DeBruijn a`, even if this was not (easily) possible for `a`. Note: we purposely don't export the constructor. Make a helper function if you find yourself needing it.

Constructors

D CmEnv a |

#### Instances

Instances details

Eq (DeBruijn CoreAlt) # |
Instance details Defined in GHC.Core.Map.Expr Methods (==) :: DeBruijn CoreAlt -> DeBruijn CoreAlt -> Bool # (/=) :: DeBruijn CoreAlt -> DeBruijn CoreAlt -> Bool #
Eq (DeBruijn CoreExpr) # |
Instance details Defined in GHC.Core.Map.Expr Methods (==) :: DeBruijn CoreExpr -> DeBruijn CoreExpr -> Bool # (/=) :: DeBruijn CoreExpr -> DeBruijn CoreExpr -> Bool #
Eq (DeBruijn Coercion) # |
Instance details Defined in GHC.Core.Map.Type Methods (==) :: DeBruijn Coercion -> DeBruijn Coercion -> Bool # (/=) :: DeBruijn Coercion -> DeBruijn Coercion -> Bool #
Eq (DeBruijn Type) # |
Instance details Defined in GHC.Core.Map.Type Methods (==) :: DeBruijn Type -> DeBruijn Type -> Bool # (/=) :: DeBruijn Type -> DeBruijn Type -> Bool #
Eq (DeBruijn Var) # |
Instance details Defined in GHC.Core.Map.Type Methods (==) :: DeBruijn Var -> DeBruijn Var -> Bool # (/=) :: DeBruijn Var -> DeBruijn Var -> Bool #
Eq (DeBruijn a) => Eq (DeBruijn (Maybe a)) # |
Instance details Defined in GHC.Core.Map.Type Methods (==) :: DeBruijn (Maybe a) -> DeBruijn (Maybe a) -> Bool # (/=) :: DeBruijn (Maybe a) -> DeBruijn (Maybe a) -> Bool #
Eq (DeBruijn a) => Eq (DeBruijn [a]) # |
Instance details Defined in GHC.Core.Map.Type Methods (==) :: DeBruijn [a] -> DeBruijn [a] -> Bool # (/=) :: DeBruijn [a] -> DeBruijn [a] -> Bool #

deBruijnize :: a -> DeBruijn a #

Synthesizes a `DeBruijn a` from an `a`, by assuming that there are no bound binders (an empty `CmEnv`). This is usually what you want if there isn't already a `CmEnv` in scope.

eqDeBruijnType :: DeBruijn Type -> DeBruijn Type -> Bool #

eqDeBruijnVar :: DeBruijn Var -> DeBruijn Var -> Bool #

data BndrMap a #

A `BndrMap` is a `TypeMapG` which allows us to distinguish between binding forms whose binders have different types. For example, if we are doing a `TrieMap` lookup on `(x :: Int) -> ()`, we should not pick up an entry in the `TrieMap` for `(x :: Bool) -> ()`: we can disambiguate this by matching on the type (or kind, if this a binder in a type) of the binder.

We also need to do the same for multiplicity! Which, since multiplicities are encoded simply as a `Type`, amounts to have a Trie for a pair of types. Tries of pairs are composition.

#### Instances

Instances details

Functor BndrMap # |
Instance details Defined in GHC.Core.Map.Type Methods fmap :: (a -> b) -> BndrMap a -> BndrMap b # (<$) :: a -> BndrMap b -> BndrMap a #
TrieMap BndrMap # |

Instance details

Defined in GHC.Core.Map.Type

Associated Types

type Key BndrMap |
Instance details Defined in GHC.Core.Map.Type type Key BndrMap = Var

Methods

emptyTM :: BndrMap a #

lookupTM :: Key BndrMap -> BndrMap b -> Maybe b #

alterTM :: Key BndrMap -> XT b -> BndrMap b -> BndrMap b #

filterTM :: (a -> Bool) -> BndrMap a -> BndrMap a #

foldTM :: (a -> b -> b) -> BndrMap a -> b -> b #

type Key BndrMap # |
Instance details Defined in GHC.Core.Map.Type type Key BndrMap = Var

xtBndr :: CmEnv -> Var -> XT a -> BndrMap a -> BndrMap a #

lkBndr :: CmEnv -> Var -> BndrMap a -> Maybe a #

data VarMap a #

#### Instances

Instances details

Functor VarMap # |
Instance details Defined in GHC.Core.Map.Type Methods fmap :: (a -> b) -> VarMap a -> VarMap b # (<$) :: a -> VarMap b -> VarMap a #
TrieMap VarMap # |

Instance details

Defined in GHC.Core.Map.Type

Associated Types

type Key VarMap |
Instance details Defined in GHC.Core.Map.Type type Key VarMap = Var

Methods

emptyTM :: VarMap a #

lookupTM :: Key VarMap -> VarMap b -> Maybe b #

alterTM :: Key VarMap -> XT b -> VarMap b -> VarMap b #

filterTM :: (a -> Bool) -> VarMap a -> VarMap a #

foldTM :: (a -> b -> b) -> VarMap a -> b -> b #

type Key VarMap # |
Instance details Defined in GHC.Core.Map.Type type Key VarMap = Var

xtVar :: CmEnv -> Var -> XT a -> VarMap a -> VarMap a #

lkVar :: CmEnv -> Var -> VarMap a -> Maybe a #

lkDFreeVar :: Var -> DVarEnv a -> Maybe a #

xtDFreeVar :: Var -> XT a -> DVarEnv a -> DVarEnv a #

xtDNamed :: NamedThing n => n -> XT a -> DNameEnv a -> DNameEnv a #

lkDNamed :: NamedThing n => n -> DNameEnv a -> Maybe a #