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

Safe Haskell | Ignore
Language | GHC2021

GHC.Core.InstEnv

Synopsis

- type DFunId = Id
- type InstMatch = (ClsInst, [DFunInstType])
- type ClsInstLookupResult = ([InstMatch], PotentialUnifiers, [InstMatch])
- data CanonicalEvidence
  - = EvCanonical
  - | EvNonCanonical
- data PotentialUnifiers
  - = NoUnifiers CanonicalEvidence
  - | OneOrMoreUnifiers (NonEmpty ClsInst)
- getCoherentUnifiers :: PotentialUnifiers -> [ClsInst]
- nullUnifiers :: PotentialUnifiers -> Bool
- data OverlapFlag = OverlapFlag {
  - overlapMode :: OverlapMode
  - isSafeOverlap :: Bool
  }
- data OverlapMode
  - = NoOverlap SourceText
  - | Overlappable SourceText
  - | Overlapping SourceText
  - | Overlaps SourceText
  - | Incoherent SourceText
  - | NonCanonical SourceText
- setOverlapModeMaybe :: OverlapFlag -> Maybe OverlapMode -> OverlapFlag
- data ClsInst = ClsInst {
  - is_cls_nm :: Name
  - is_tcs :: [RoughMatchTc]
  - is_dfun_name :: Name
  - is_tvs :: [TyVar]
  - is_cls :: Class
  - is_tys :: [Type]
  - is_dfun :: DFunId
  - is_flag :: OverlapFlag
  - is_orphan :: IsOrphan
  - is_warn :: Maybe (WarningTxt GhcRn)
  }
- type DFunInstType = Maybe Type
- pprInstance :: ClsInst -> SDoc
- pprInstanceHdr :: ClsInst -> SDoc
- pprDFunId :: DFunId -> SDoc
- pprInstances :: [ClsInst] -> SDoc
- instanceWarning :: ClsInst -> Maybe (WarningTxt GhcRn)
- instanceHead :: ClsInst -> ([TyVar], Class, [Type])
- instanceSig :: ClsInst -> ([TyVar], [Type], Class, [Type])
- mkLocalClsInst :: DFunId -> OverlapFlag -> [TyVar] -> Class -> [Type] -> Maybe (WarningTxt GhcRn) -> ClsInst
- mkImportedClsInst :: Name -> [RoughMatchTc] -> Name -> DFunId -> OverlapFlag -> IsOrphan -> Maybe (WarningTxt GhcRn) -> ClsInst
- instanceDFunId :: ClsInst -> DFunId
- updateClsInstDFuns :: (DFunId -> DFunId) -> InstEnv -> InstEnv
- updateClsInstDFun :: (DFunId -> DFunId) -> ClsInst -> ClsInst
- fuzzyClsInstCmp :: ClsInst -> ClsInst -> Ordering
- orphNamesOfClsInst :: ClsInst -> NameSet
- data InstEnvs = InstEnvs {
  - ie_global :: InstEnv
  - ie_local :: InstEnv
  - ie_visible :: VisibleOrphanModules
  }
- type VisibleOrphanModules = ModuleSet
- data InstEnv
- data LookupInstanceErrReason
  - = LookupInstErrNotExact
  - | LookupInstErrFlexiVar
  - | LookupInstErrNotFound
- mkInstEnv :: [ClsInst] -> InstEnv
- emptyInstEnv :: InstEnv
- unionInstEnv :: InstEnv -> InstEnv -> InstEnv
- extendInstEnv :: InstEnv -> ClsInst -> InstEnv
- filterInstEnv :: (ClsInst -> Bool) -> InstEnv -> InstEnv
- deleteFromInstEnv :: InstEnv -> ClsInst -> InstEnv
- deleteDFunFromInstEnv :: InstEnv -> DFunId -> InstEnv
- anyInstEnv :: (ClsInst -> Bool) -> InstEnv -> Bool
- identicalClsInstHead :: ClsInst -> ClsInst -> Bool
- extendInstEnvList :: InstEnv -> [ClsInst] -> InstEnv
- lookupUniqueInstEnv :: InstEnvs -> Class -> [Type] -> Either LookupInstanceErrReason (ClsInst, [Type])
- lookupInstEnv :: Bool -> InstEnvs -> Class -> [Type] -> ClsInstLookupResult
- instEnvElts :: InstEnv -> [ClsInst]
- instEnvClasses :: InstEnv -> UniqDSet Class
- mapInstEnv :: (ClsInst -> ClsInst) -> InstEnv -> InstEnv
- memberInstEnv :: InstEnv -> ClsInst -> Bool
- instIsVisible :: VisibleOrphanModules -> ClsInst -> Bool
- classInstances :: InstEnvs -> Class -> [ClsInst]
- instanceBindFun :: BindFun
- classNameInstances :: InstEnvs -> Name -> [ClsInst]
- instanceCantMatch :: [RoughMatchTc] -> [RoughMatchTc] -> Bool
- roughMatchTcs :: [Type] -> [RoughMatchTc]
- isOverlappable :: ClsInst -> Bool
- isOverlapping :: ClsInst -> Bool
- isIncoherent :: ClsInst -> Bool

# Documentation

type DFunId = Id Source #

Dictionary Function Identifier

type InstMatch = (ClsInst, [DFunInstType]) Source #

type ClsInstLookupResult = ([InstMatch], PotentialUnifiers, [InstMatch]) Source #

data CanonicalEvidence Source #

`CanonicalEvidence` says whether a piece of evidence has a singleton type; For example, given (d1 :: C Int), will any other (d2 :: C Int) do equally well? See Note [Coherence and specialisation: overview] above, and Note [Desugaring non-canonical evidence] in GHC.HsToCore.Binds

Constructors

EvCanonical |
EvNonCanonical |

#### Instances

Instances details

Outputable CanonicalEvidence Source # |
Instance details Defined in GHC.Core.InstEnv Methods ppr :: CanonicalEvidence -> SDoc Source #

data PotentialUnifiers Source #

Constructors

NoUnifiers CanonicalEvidence |
OneOrMoreUnifiers (NonEmpty ClsInst) |

#### Instances

Instances details

Semigroup PotentialUnifiers Source # |
Instance details Defined in GHC.Core.InstEnv Methods (<>) :: PotentialUnifiers -> PotentialUnifiers -> PotentialUnifiers Source # sconcat :: NonEmpty PotentialUnifiers -> PotentialUnifiers Source # stimes :: Integral b => b -> PotentialUnifiers -> PotentialUnifiers Source #
Outputable PotentialUnifiers Source # |
Instance details Defined in GHC.Core.InstEnv Methods ppr :: PotentialUnifiers -> SDoc Source #

getCoherentUnifiers :: PotentialUnifiers -> [ClsInst] Source #

nullUnifiers :: PotentialUnifiers -> Bool Source #

data OverlapFlag Source #

The semantics allowed for overlapping instances for a particular instance. See Note [Safe Haskell isSafeOverlap] in GHC.Core.InstEnv for a explanation of the `isSafeOverlap` field.

Constructors

OverlapFlag |

Fields

- overlapMode :: OverlapMode
- isSafeOverlap :: Bool

#### Instances

Instances details

Data OverlapFlag Source # |

Instance details

Defined in GHC.Types.Basic

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> OverlapFlag -> c OverlapFlag Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c OverlapFlag Source #

toConstr :: OverlapFlag -> Constr Source #

dataTypeOf :: OverlapFlag -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c OverlapFlag) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OverlapFlag) Source #

gmapT :: (forall b. Data b => b -> b) -> OverlapFlag -> OverlapFlag Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> OverlapFlag -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> OverlapFlag -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> OverlapFlag -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> OverlapFlag -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> OverlapFlag -> m OverlapFlag Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> OverlapFlag -> m OverlapFlag Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> OverlapFlag -> m OverlapFlag Source #

Binary OverlapFlag Source # |
Instance details Defined in GHC.Types.Basic Methods put_ :: WriteBinHandle -> OverlapFlag -> IO () Source # put :: WriteBinHandle -> OverlapFlag -> IO (Bin OverlapFlag) Source # get :: ReadBinHandle -> IO OverlapFlag Source #
Outputable OverlapFlag Source # |
Instance details Defined in GHC.Types.Basic Methods ppr :: OverlapFlag -> SDoc Source #
Eq OverlapFlag Source # |
Instance details Defined in GHC.Types.Basic Methods (==) :: OverlapFlag -> OverlapFlag -> Bool Source # (/=) :: OverlapFlag -> OverlapFlag -> Bool Source #

data OverlapMode Source #

Constructors

NoOverlap SourceText | This instance must not overlap another `NoOverlap` instance. However, it may be overlapped by `Overlapping` instances, and it may overlap `Overlappable` instances.
Overlappable SourceText | Silently ignore this instance if you find a more specific one that matches the constraint you are trying to resolve Example: constraint (Foo [Int]) instance Foo [Int] instance {-# OVERLAPPABLE #-} Foo [a] Since the second instance has the Overlappable flag, the first instance will be chosen (otherwise its ambiguous which to choose)
Overlapping SourceText | Silently ignore any more general instances that may be used to solve the constraint. Example: constraint (Foo [Int]) instance {-# OVERLAPPING #-} Foo [Int] instance Foo [a] Since the first instance has the Overlapping flag, the second---more general---instance will be ignored (otherwise it is ambiguous which to choose)
Overlaps SourceText | Equivalent to having both `Overlapping` and `Overlappable` flags.

Incoherent SourceText

Behave like Overlappable and Overlapping, and in addition pick an arbitrary one if there are multiple matching candidates, and don't worry about later instantiation

Example: constraint (Foo [b]) instance {-# INCOHERENT -} Foo [Int] instance Foo [a] Without the Incoherent flag, we'd complain that instantiating `b` would change which instance was chosen. See also Note [Incoherent instances] in GHC.Core.InstEnv

NonCanonical SourceText

Behave like Incoherent, but the instance choice is observable by the program behaviour. See Note [Coherence and specialisation: overview].

We don't have surface syntax for the distinction between Incoherent and NonCanonical instances; instead, the flag `-f{no-}specialise-incoherents` (on by default) controls whether `INCOHERENT` instances are regarded as Incoherent or NonCanonical.

#### Instances

Instances details

Data OverlapMode Source # |

Instance details

Defined in GHC.Types.Basic

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> OverlapMode -> c OverlapMode Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c OverlapMode Source #

toConstr :: OverlapMode -> Constr Source #

dataTypeOf :: OverlapMode -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c OverlapMode) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c OverlapMode) Source #

gmapT :: (forall b. Data b => b -> b) -> OverlapMode -> OverlapMode Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> OverlapMode -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> OverlapMode -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> OverlapMode -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> OverlapMode -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> OverlapMode -> m OverlapMode Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> OverlapMode -> m OverlapMode Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> OverlapMode -> m OverlapMode Source #

Binary OverlapMode Source # |
Instance details Defined in GHC.Types.Basic Methods put_ :: WriteBinHandle -> OverlapMode -> IO () Source # put :: WriteBinHandle -> OverlapMode -> IO (Bin OverlapMode) Source # get :: ReadBinHandle -> IO OverlapMode Source #
Outputable OverlapMode Source # |
Instance details Defined in GHC.Types.Basic Methods ppr :: OverlapMode -> SDoc Source #
Eq OverlapMode Source # |
Instance details Defined in GHC.Types.Basic Methods (==) :: OverlapMode -> OverlapMode -> Bool Source # (/=) :: OverlapMode -> OverlapMode -> Bool Source #
type Anno OverlapMode Source # |
Instance details Defined in GHC.Hs.Decls type Anno OverlapMode = SrcSpanAnnP

setOverlapModeMaybe :: OverlapFlag -> Maybe OverlapMode -> OverlapFlag Source #

data ClsInst Source #

A type-class instance. Note that there is some tricky laziness at work here. See Note [ClsInst laziness and the rough-match fields] for more details.

Constructors

ClsInst |

Fields

- is_cls_nm :: Name

  Class name

- is_tcs :: [RoughMatchTc]

  Top of type args The class itself is always the first element of this list

- is_dfun_name :: Name

  `is_dfun_name = idName . is_dfun`.

  We use `is_dfun_name` for the visibility check, `instIsVisible`, which needs to know the `Module` which the dictionary is defined in. However, we cannot use the `Module` attached to `is_dfun` since doing so would mean we would potentially pull in an entire interface file unnecessarily. This was the cause of #12367.

- is_tvs :: [TyVar]
- is_cls :: Class
- is_tys :: [Type]
- is_dfun :: DFunId
- is_flag :: OverlapFlag
- is_orphan :: IsOrphan
- is_warn :: Maybe (WarningTxt GhcRn)

#### Instances

Instances details

Data ClsInst Source # |

Instance details

Defined in GHC.Core.InstEnv

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> ClsInst -> c ClsInst Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c ClsInst Source #

toConstr :: ClsInst -> Constr Source #

dataTypeOf :: ClsInst -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c ClsInst) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c ClsInst) Source #

gmapT :: (forall b. Data b => b -> b) -> ClsInst -> ClsInst Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> ClsInst -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> ClsInst -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> ClsInst -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> ClsInst -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> ClsInst -> m ClsInst Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> ClsInst -> m ClsInst Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> ClsInst -> m ClsInst Source #

NamedThing ClsInst Source # |
Instance details Defined in GHC.Core.InstEnv Methods getOccName :: ClsInst -> OccName Source # getName :: ClsInst -> Name Source #
Outputable ClsInst Source # |
Instance details Defined in GHC.Core.InstEnv Methods ppr :: ClsInst -> SDoc Source #

type DFunInstType = Maybe Type Source #

pprInstance :: ClsInst -> SDoc Source #

pprInstanceHdr :: ClsInst -> SDoc Source #

pprDFunId :: DFunId -> SDoc Source #

pprInstances :: [ClsInst] -> SDoc Source #

instanceWarning :: ClsInst -> Maybe (WarningTxt GhcRn) Source #

instanceHead :: ClsInst -> ([TyVar], Class, [Type]) Source #

instanceSig :: ClsInst -> ([TyVar], [Type], Class, [Type]) Source #

mkLocalClsInst :: DFunId -> OverlapFlag -> [TyVar] -> Class -> [Type] -> Maybe (WarningTxt GhcRn) -> ClsInst Source #

mkImportedClsInst Source #

Arguments

:: Name | the name of the class
-> [RoughMatchTc] | the rough match signature of the instance
-> Name | the `Name` of the dictionary binding
-> DFunId | the `Id` of the dictionary.
-> OverlapFlag | may this instance overlap?
-> IsOrphan | is this instance an orphan?
-> Maybe (WarningTxt GhcRn) | warning emitted when solved
-> ClsInst |

instanceDFunId :: ClsInst -> DFunId Source #

updateClsInstDFuns :: (DFunId -> DFunId) -> InstEnv -> InstEnv Source #

updateClsInstDFun :: (DFunId -> DFunId) -> ClsInst -> ClsInst Source #

fuzzyClsInstCmp :: ClsInst -> ClsInst -> Ordering Source #

A fuzzy comparison function for class instances, intended for sorting instances before displaying them to the user.

orphNamesOfClsInst :: ClsInst -> NameSet Source #

Collects the names of concrete types and type constructors that make up the head of a class instance. For instance, given `class Foo a b`:

`instance Foo (Either (Maybe Int) a) Bool` would yield [Either, Maybe, Int, Bool]

Used in the implementation of ":info" in GHCi.

The `tcSplitSigmaTy` is because of instance Foo a => Baz T where ... The decl is an orphan if Baz and T are both not locally defined, even if Foo *is* locally defined

data InstEnvs Source #

`InstEnvs` represents the combination of the global type class instance environment, the local type class instance environment, and the set of transitively reachable orphan modules (according to what modules have been directly imported) used to test orphan instance visibility.

Constructors

InstEnvs |

Fields

- ie_global :: InstEnv
- ie_local :: InstEnv
- ie_visible :: VisibleOrphanModules

type VisibleOrphanModules = ModuleSet Source #

Set of visible orphan modules, according to what modules have been directly imported. This is based off of the dep_orphs field, which records transitively reachable orphan modules (modules that define orphan instances).

data InstEnv Source #

#### Instances

Instances details

Outputable InstEnv Source # |
Instance details Defined in GHC.Core.InstEnv Methods ppr :: InstEnv -> SDoc Source #

data LookupInstanceErrReason Source #

Why a particular typeclass application couldn't be looked up.

Constructors

LookupInstErrNotExact | Tyvars aren't an exact match.
LookupInstErrFlexiVar | One of the tyvars is flexible.
LookupInstErrNotFound | No matching instance was found.

#### Instances

Instances details

Generic LookupInstanceErrReason Source # |

Instance details

Defined in GHC.Core.InstEnv

Associated Types

type Rep LookupInstanceErrReason |

Instance details

Defined in GHC.Core.InstEnv

type Rep LookupInstanceErrReason = D1 ('MetaData "LookupInstanceErrReason" "GHC.Core.InstEnv" "ghc-lib-parser-9.12.2.20250421-CLarrBnVGcX5rqdmHKZO6f" 'False) (C1 ('MetaCons "LookupInstErrNotExact" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "LookupInstErrFlexiVar" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "LookupInstErrNotFound" 'PrefixI 'False) (U1 :: Type -> Type)))

Methods

from :: LookupInstanceErrReason -> Rep LookupInstanceErrReason x Source #

to :: Rep LookupInstanceErrReason x -> LookupInstanceErrReason Source #

type Rep LookupInstanceErrReason Source # |

Instance details

Defined in GHC.Core.InstEnv

type Rep LookupInstanceErrReason = D1 ('MetaData "LookupInstanceErrReason" "GHC.Core.InstEnv" "ghc-lib-parser-9.12.2.20250421-CLarrBnVGcX5rqdmHKZO6f" 'False) (C1 ('MetaCons "LookupInstErrNotExact" 'PrefixI 'False) (U1 :: Type -> Type) :+: (C1 ('MetaCons "LookupInstErrFlexiVar" 'PrefixI 'False) (U1 :: Type -> Type) :+: C1 ('MetaCons "LookupInstErrNotFound" 'PrefixI 'False) (U1 :: Type -> Type)))

mkInstEnv :: [ClsInst] -> InstEnv Source #

emptyInstEnv :: InstEnv Source #

unionInstEnv :: InstEnv -> InstEnv -> InstEnv Source #

Makes no particular effort to detect conflicts.

extendInstEnv :: InstEnv -> ClsInst -> InstEnv Source #

filterInstEnv :: (ClsInst -> Bool) -> InstEnv -> InstEnv Source #

deleteFromInstEnv :: InstEnv -> ClsInst -> InstEnv Source #

deleteDFunFromInstEnv :: InstEnv -> DFunId -> InstEnv Source #

anyInstEnv :: (ClsInst -> Bool) -> InstEnv -> Bool Source #

identicalClsInstHead :: ClsInst -> ClsInst -> Bool Source #

True when when the instance heads are the same e.g. both are Eq [(a,b)] Used for overriding in GHCi Obviously should be insensitive to alpha-renaming

extendInstEnvList :: InstEnv -> [ClsInst] -> InstEnv Source #

lookupUniqueInstEnv :: InstEnvs -> Class -> [Type] -> Either LookupInstanceErrReason (ClsInst, [Type]) Source #

Look up an instance in the given instance environment. The given class application must match exactly one instance and the match may not contain any flexi type variables. If the lookup is unsuccessful, yield 'Left errorMessage'.

lookupInstEnv :: Bool -> InstEnvs -> Class -> [Type] -> ClsInstLookupResult Source #

See Note [Rules for instance lookup] ^ See Note [Safe Haskell Overlapping Instances] in GHC.Tc.Solver ^ See Note [Safe Haskell Overlapping Instances Implementation] in GHC.Tc.Solver

instEnvElts :: InstEnv -> [ClsInst] Source #

instEnvClasses :: InstEnv -> UniqDSet Class Source #

mapInstEnv :: (ClsInst -> ClsInst) -> InstEnv -> InstEnv Source #

memberInstEnv :: InstEnv -> ClsInst -> Bool Source #

Checks for an exact match of ClsInst in the instance environment. We use this when we do signature checking in GHC.Tc.Module

instIsVisible :: VisibleOrphanModules -> ClsInst -> Bool Source #

Test if an instance is visible, by checking that its origin module is in `VisibleOrphanModules`. See Note [Instance lookup and orphan instances]

classInstances :: InstEnvs -> Class -> [ClsInst] Source #

instanceBindFun :: BindFun Source #

classNameInstances :: InstEnvs -> Name -> [ClsInst] Source #

instanceCantMatch :: [RoughMatchTc] -> [RoughMatchTc] -> Bool Source #

roughMatchTcs :: [Type] -> [RoughMatchTc] Source #

isOverlappable :: ClsInst -> Bool Source #

isOverlapping :: ClsInst -> Bool Source #

isIncoherent :: ClsInst -> Bool Source #