GHC.Core.TyCo.FVs

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

Safe Haskell | Ignore
Language | GHC2021

GHC.Core.TyCo.FVs

Contents

- Free type constructors
- Free vars with visible/invisible separate
- Occurrence-check expansion
- Well-scoped free variables
- Closing over kinds
- Raw materials

Synopsis

- shallowTyCoVarsOfType :: Type -> TyCoVarSet
- shallowTyCoVarsOfTypes :: [Type] -> TyCoVarSet
- tyCoVarsOfType :: Type -> TyCoVarSet
- tyCoVarsOfTypes :: [Type] -> TyCoVarSet
- tyCoVarsOfTypeDSet :: Type -> DTyCoVarSet
- tyCoVarsOfTypesDSet :: [Type] -> DTyCoVarSet
- tyCoFVsBndr :: ForAllTyBinder -> FV -> FV
- tyCoFVsVarBndr :: Var -> FV -> FV
- tyCoFVsVarBndrs :: [Var] -> FV -> FV
- tyCoFVsOfType :: Type -> FV
- tyCoVarsOfTypeList :: Type -> [TyCoVar]
- tyCoFVsOfTypes :: [Type] -> FV
- tyCoVarsOfTypesList :: [Type] -> [TyCoVar]
- deepTcvFolder :: TyCoFolder TyCoVarSet (Endo TyCoVarSet)
- shallowTyCoVarsOfTyVarEnv :: TyVarEnv Type -> TyCoVarSet
- shallowTyCoVarsOfCoVarEnv :: CoVarEnv Coercion -> TyCoVarSet
- shallowTyCoVarsOfCo :: Coercion -> TyCoVarSet
- shallowTyCoVarsOfCos :: [Coercion] -> TyCoVarSet
- tyCoVarsOfCo :: Coercion -> TyCoVarSet
- tyCoVarsOfCos :: [Coercion] -> TyCoVarSet
- tyCoVarsOfMCo :: MCoercion -> TyCoVarSet
- coVarsOfType :: Type -> CoVarSet
- coVarsOfTypes :: [Type] -> CoVarSet
- coVarsOfCo :: Coercion -> CoVarSet
- coVarsOfCos :: [Coercion] -> CoVarSet
- tyCoVarsOfCoDSet :: Coercion -> DTyCoVarSet
- tyCoFVsOfCo :: Coercion -> FV
- tyCoFVsOfCos :: [Coercion] -> FV
- tyCoVarsOfCoList :: Coercion -> [TyCoVar]
- almostDevoidCoVarOfCo :: CoVar -> Coercion -> Bool
- injectiveVarsOfType :: Bool -> Type -> FV
- injectiveVarsOfTypes :: Bool -> [Type] -> FV
- isInjectiveInType :: TyVar -> Type -> Bool
- invisibleVarsOfType :: Type -> FV
- invisibleVarsOfTypes :: [Type] -> FV
- anyFreeVarsOfType :: (TyCoVar -> Bool) -> Type -> Bool
- anyFreeVarsOfTypes :: (TyCoVar -> Bool) -> [Type] -> Bool
- anyFreeVarsOfCo :: (TyCoVar -> Bool) -> Coercion -> Bool
- noFreeVarsOfType :: Type -> Bool
- noFreeVarsOfTypes :: [Type] -> Bool
- noFreeVarsOfCo :: Coercion -> Bool
- tyConsOfType :: Type -> UniqSet TyCon
- tyConsOfTypes :: [Type] -> UniqSet TyCon
- visVarsOfTypes :: [Type] -> Pair TyCoVarSet
- visVarsOfType :: Type -> Pair TyCoVarSet
- occCheckExpand :: [Var] -> Type -> Maybe Type
- scopedSort :: [TyCoVar] -> [TyCoVar]
- tyCoVarsOfTypeWellScoped :: Type -> [TyVar]
- tyCoVarsOfTypesWellScoped :: [Type] -> [TyVar]
- closeOverKindsDSet :: DTyVarSet -> DTyVarSet
- closeOverKindsList :: [TyVar] -> [TyVar]
- closeOverKinds :: TyCoVarSet -> TyCoVarSet
- newtype Endo a = Endo {
  - appEndo :: a -> a
  }
- runTyCoVars :: Endo TyCoVarSet -> TyCoVarSet

# Documentation

shallowTyCoVarsOfType :: Type -> TyCoVarSet #

shallowTyCoVarsOfTypes :: [Type] -> TyCoVarSet #

tyCoVarsOfType :: Type -> TyCoVarSet #

tyCoVarsOfTypes :: [Type] -> TyCoVarSet #

tyCoVarsOfTypeDSet :: Type -> DTyCoVarSet #

`tyCoFVsOfType` that returns free variables of a type in a deterministic set. For explanation of why using `VarSet` is not deterministic see Note [Deterministic FV] in GHC.Utils.FV.

tyCoVarsOfTypesDSet :: [Type] -> DTyCoVarSet #

Returns free variables of types, including kind variables as a deterministic set. For type synonyms it does not expand the synonym.

tyCoFVsBndr :: ForAllTyBinder -> FV -> FV #

tyCoFVsVarBndr :: Var -> FV -> FV #

tyCoFVsVarBndrs :: [Var] -> FV -> FV #

tyCoFVsOfType :: Type -> FV #

The worker for `tyCoFVsOfType` and `tyCoFVsOfTypeList`. The previous implementation used `unionVarSet` which is O(n+m) and can make the function quadratic. It's exported, so that it can be composed with other functions that compute free variables. See Note [FV naming conventions] in GHC.Utils.FV.

Eta-expanded because that makes it run faster (apparently) See Note [FV eta expansion] in GHC.Utils.FV for explanation.

tyCoVarsOfTypeList :: Type -> [TyCoVar] #

`tyCoFVsOfType` that returns free variables of a type in deterministic order. For explanation of why using `VarSet` is not deterministic see Note [Deterministic FV] in GHC.Utils.FV.

tyCoFVsOfTypes :: [Type] -> FV #

tyCoVarsOfTypesList :: [Type] -> [TyCoVar] #

Returns free variables of types, including kind variables as a deterministically ordered list. For type synonyms it does not expand the synonym.

deepTcvFolder :: TyCoFolder TyCoVarSet (Endo TyCoVarSet) #

shallowTyCoVarsOfTyVarEnv :: TyVarEnv Type -> TyCoVarSet #

Returns free variables of types, including kind variables as a non-deterministic set. For type synonyms it does not expand the synonym.

shallowTyCoVarsOfCoVarEnv :: CoVarEnv Coercion -> TyCoVarSet #

shallowTyCoVarsOfCo :: Coercion -> TyCoVarSet #

shallowTyCoVarsOfCos :: [Coercion] -> TyCoVarSet #

tyCoVarsOfCo :: Coercion -> TyCoVarSet #

tyCoVarsOfCos :: [Coercion] -> TyCoVarSet #

tyCoVarsOfMCo :: MCoercion -> TyCoVarSet #

coVarsOfType :: Type -> CoVarSet #

coVarsOfTypes :: [Type] -> CoVarSet #

coVarsOfCo :: Coercion -> CoVarSet #

coVarsOfCos :: [Coercion] -> CoVarSet #

tyCoVarsOfCoDSet :: Coercion -> DTyCoVarSet #

Get a deterministic set of the vars free in a coercion

tyCoFVsOfCo :: Coercion -> FV #

tyCoFVsOfCos :: [Coercion] -> FV #

tyCoVarsOfCoList :: Coercion -> [TyCoVar] #

almostDevoidCoVarOfCo :: CoVar -> Coercion -> Bool #

Given a covar and a coercion, returns True if covar is almost devoid in the coercion. That is, covar can only appear in Refl and GRefl. See (FC6) in Note [ForAllCo] in GHC.Core.TyCo.Rep

injectiveVarsOfType #

Arguments

:: Bool | Should we look under injective type families? See Note [Coverage condition for injective type families] in GHC.Tc.Instance.Family.
-> Type |
-> FV |

Returns the free variables of a `Type` that are in injective positions. Specifically, it finds the free variables while:

- Expanding type synonyms
- Ignoring the coercion in `(ty |> co)`
- Ignoring the non-injective fields of a `TyConApp`

For example, if `F` is a non-injective type family, then:

    injectiveTyVarsOf( Either c (Maybe (a, F b c)) ) = {a,c}

If ``injectiveVarsOfType` ty = itvs`, then knowing `ty` fixes `itvs`. More formally, if `a` is in ``injectiveVarsOfType` ty` and `S1(ty) ~ S2(ty)`, then `S1(a) ~ S2(a)`, where `S1` and `S2` are arbitrary substitutions.

See `Note [When does a tycon application need an explicit kind signature?]`.

injectiveVarsOfTypes #

Arguments

:: Bool | look under injective type families? See Note [Coverage condition for injective type families] in GHC.Tc.Instance.Family.
-> [Type] |
-> FV |

Returns the free variables of a `Type` that are in injective positions. Specifically, it finds the free variables while:

- Expanding type synonyms
- Ignoring the coercion in `(ty |> co)`
- Ignoring the non-injective fields of a `TyConApp`

See `Note [When does a tycon application need an explicit kind signature?]`.

isInjectiveInType :: TyVar -> Type -> Bool #

invisibleVarsOfType :: Type -> FV #

Returns the set of variables that are used invisibly anywhere within the given type. A variable will be included even if it is used both visibly and invisibly. An invisible use site includes: * In the kind of a variable * In the kind of a bound variable in a forall * In a coercion * In a Specified or Inferred argument to a function See Note [VarBndrs, ForAllTyBinders, TyConBinders, and visibility] in GHC.Core.TyCo.Rep

invisibleVarsOfTypes :: [Type] -> FV #

Like `invisibleVarsOfType`, but for many types.

anyFreeVarsOfType :: (TyCoVar -> Bool) -> Type -> Bool #

anyFreeVarsOfTypes :: (TyCoVar -> Bool) -> [Type] -> Bool #

anyFreeVarsOfCo :: (TyCoVar -> Bool) -> Coercion -> Bool #

noFreeVarsOfType :: Type -> Bool #

noFreeVarsOfTypes :: [Type] -> Bool #

noFreeVarsOfCo :: Coercion -> Bool #

# Free type constructors

tyConsOfType :: Type -> UniqSet TyCon #

All type constructors occurring in the type; looking through type synonyms, but not newtypes. When it finds a Class, it returns the class TyCon.

tyConsOfTypes :: [Type] -> UniqSet TyCon #

# Free vars with visible/invisible separate

visVarsOfTypes :: [Type] -> Pair TyCoVarSet #

visVarsOfType :: Type -> Pair TyCoVarSet #

Retrieve the free variables in this type, splitting them based on whether they are used visibly or invisibly. Invisible ones come first.

# Occurrence-check expansion

occCheckExpand :: [Var] -> Type -> Maybe Type #

# Well-scoped free variables

scopedSort :: [TyCoVar] -> [TyCoVar] #

Do a topological sort on a list of tyvars, so that binders occur before occurrences E.g. given [ a::k, k::*, b::k ] it'll return a well-scoped list [ k::*, a::k, b::k ]

This is a deterministic sorting operation (that is, doesn't depend on Uniques).

It is also meant to be stable: that is, variables should not be reordered unnecessarily. This is specified in Note [ScopedSort] See also Note [Ordering of implicit variables] in GHC.Rename.HsType

tyCoVarsOfTypeWellScoped :: Type -> [TyVar] #

Get the free vars of a type in scoped order

tyCoVarsOfTypesWellScoped :: [Type] -> [TyVar] #

Get the free vars of types in scoped order

# Closing over kinds

closeOverKindsDSet :: DTyVarSet -> DTyVarSet #

Add the kind variables free in the kinds of the tyvars in the given set. Returns a deterministic set.

closeOverKindsList :: [TyVar] -> [TyVar] #

Add the kind variables free in the kinds of the tyvars in the given set. Returns a deterministically ordered list.

closeOverKinds :: TyCoVarSet -> TyCoVarSet #

# Raw materials

newtype Endo a #

The monoid of endomorphisms under composition.

    Endo f <> Endo g == Endo (f . g)

#### Examples

Expand

    >>> let computation = Endo ("Hello, " ++) <> Endo (++ "!")
    >>> appEndo computation "Haskell"
    "Hello, Haskell!"

    >>> let computation = Endo (*3) <> Endo (+1)
    >>> appEndo computation 1
    6

Constructors

Endo |
Fields appEndo :: a -> a

#### Instances

Instances details

Monoid (Endo a) | @since base-2.01
Instance details Defined in GHC.Internal.Data.Semigroup.Internal Methods mempty :: Endo a # mappend :: Endo a -> Endo a -> Endo a # mconcat :: [Endo a] -> Endo a #
Semigroup (Endo a) | @since base-4.9.0.0
Instance details Defined in GHC.Internal.Data.Semigroup.Internal Methods (<>) :: Endo a -> Endo a -> Endo a # sconcat :: NonEmpty (Endo a) -> Endo a # stimes :: Integral b => b -> Endo a -> Endo a #
Generic (Endo a) |
Instance details Defined in GHC.Internal.Data.Semigroup.Internal Associated Types
type Rep (Endo a) | @since base-4.7.0.0
Instance details Defined in GHC.Internal.Data.Semigroup.Internal type Rep (Endo a) = D1 ('MetaData "Endo" "GHC.Internal.Data.Semigroup.Internal" "ghc-internal" 'True) (C1 ('MetaCons "Endo" 'PrefixI 'True) (S1 ('MetaSel ('Just "appEndo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a -> a))))
Methods from :: Endo a -> Rep (Endo a) x # to :: Rep (Endo a) x -> Endo a #
type Rep (Endo a) | @since base-4.7.0.0
Instance details Defined in GHC.Internal.Data.Semigroup.Internal type Rep (Endo a) = D1 ('MetaData "Endo" "GHC.Internal.Data.Semigroup.Internal" "ghc-internal" 'True) (C1 ('MetaCons "Endo" 'PrefixI 'True) (S1 ('MetaSel ('Just "appEndo") 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 (a -> a))))

runTyCoVars :: Endo TyCoVarSet -> TyCoVarSet #