TcDerivUtils

ghc-8.4.1: The GHC API

Safe Haskell | None
Language | Haskell2010

TcDerivUtils

Synopsis

- type DerivM = ReaderT DerivEnv TcRn
- data DerivEnv = DerivEnv {
  - denv_overlap_mode :: Maybe OverlapMode
  - denv_tvs :: [TyVar]
  - denv_cls :: Class
  - denv_cls_tys :: [Type]
  - denv_tc :: TyCon
  - denv_tc_args :: [Type]
  - denv_rep_tc :: TyCon
  - denv_rep_tc_args :: [Type]
  - denv_mtheta :: DerivContext
  - denv_strat :: Maybe DerivStrategy
  }
- data DerivSpec theta = DS {
  - ds_loc :: SrcSpan
  - ds_name :: Name
  - ds_tvs :: [TyVar]
  - ds_theta :: theta
  - ds_cls :: Class
  - ds_tys :: [Type]
  - ds_tc :: TyCon
  - ds_overlap :: Maybe OverlapMode
  - ds_mechanism :: DerivSpecMechanism
  }
- pprDerivSpec :: Outputable theta => DerivSpec theta -> SDoc
- data DerivSpecMechanism
  - = DerivSpecStock (SrcSpan -> TyCon -> [Type] -> TcM (LHsBinds GhcPs, BagDerivStuff, [Name]))
  - | DerivSpecNewtype Type
  - | DerivSpecAnyClass
- isDerivSpecStock :: DerivSpecMechanism -> Bool
- isDerivSpecNewtype :: DerivSpecMechanism -> Bool
- isDerivSpecAnyClass :: DerivSpecMechanism -> Bool
- type DerivContext = Maybe ThetaType
- data DerivStatus
  - = CanDerive
  - | DerivableClassError SDoc
  - | DerivableViaInstance
  - | NonDerivableClass SDoc
- data PredOrigin = PredOrigin PredType CtOrigin TypeOrKind
- data ThetaOrigin = ThetaOrigin {
  - to_tvs :: [TyVar]
  - to_givens :: ThetaType
  - to_wanted_origins :: [PredOrigin]
  }
- mkPredOrigin :: CtOrigin -> TypeOrKind -> PredType -> PredOrigin
- mkThetaOrigin :: CtOrigin -> TypeOrKind -> [TyVar] -> ThetaType -> ThetaType -> ThetaOrigin
- mkThetaOriginFromPreds :: [PredOrigin] -> ThetaOrigin
- substPredOrigin :: HasCallStack => TCvSubst -> PredOrigin -> PredOrigin
- checkSideConditions :: DynFlags -> DerivContext -> Class -> [TcType] -> TyCon -> DerivStatus
- hasStockDeriving :: Class -> Maybe (SrcSpan -> TyCon -> [Type] -> TcM (LHsBinds GhcPs, BagDerivStuff, [Name]))
- canDeriveAnyClass :: DynFlags -> Validity
- std_class_via_coercible :: Class -> Bool
- non_coercible_class :: Class -> Bool
- newDerivClsInst :: ThetaType -> DerivSpec theta -> TcM ClsInst
- extendLocalInstEnv :: [ClsInst] -> TcM a -> TcM a

# Documentation

type DerivM = ReaderT DerivEnv TcRn Source #

To avoid having to manually plumb everything in `DerivEnv` throughout various functions in `TcDeriv` and `TcDerivInfer`, we use `DerivM`, which is a simple reader around `TcRn`.

data DerivEnv Source #

Contains all of the information known about a derived instance when determining what its `EarlyDerivSpec` should be.

Constructors

DerivEnv |
Fields denv_overlap_mode :: Maybe OverlapMode Is this an overlapping instance? denv_tvs :: [TyVar] Universally quantified type variables in the instance denv_cls :: Class Class for which we need to derive an instance denv_cls_tys :: [Type] Other arguments to the class except the last denv_tc :: TyCon Type constructor for which the instance is requested (last arguments to the type class) denv_tc_args :: [Type] Arguments to the type constructor denv_rep_tc :: TyCon The representation tycon for `denv_tc` (for data family instances) denv_rep_tc_args :: [Type] The representation types for `denv_tc_args` (for data family instances) denv_mtheta :: DerivContext `Just` the context of the instance, for standalone deriving. `Nothing` for `deriving` clauses. denv_strat :: Maybe DerivStrategy `Just` if user requests a particular deriving strategy. Otherwise, `Nothing`.

Instances

Outputable DerivEnv Source # |
Instance details Methods ppr :: DerivEnv -> SDoc Source # pprPrec :: Rational -> DerivEnv -> SDoc Source #

data DerivSpec theta Source #

Constructors

DS |
Fields ds_loc :: SrcSpan ds_name :: Name ds_tvs :: [TyVar] ds_theta :: theta ds_cls :: Class ds_tys :: [Type] ds_tc :: TyCon ds_overlap :: Maybe OverlapMode ds_mechanism :: DerivSpecMechanism

Instances

Outputable theta => Outputable (DerivSpec theta) Source # |
Instance details Methods ppr :: DerivSpec theta -> SDoc Source # pprPrec :: Rational -> DerivSpec theta -> SDoc Source #

pprDerivSpec :: Outputable theta => DerivSpec theta -> SDoc Source #

data DerivSpecMechanism Source #

Constructors

DerivSpecStock (SrcSpan -> TyCon -> [Type] -> TcM (LHsBinds GhcPs, BagDerivStuff, [Name])) |
DerivSpecNewtype Type |
DerivSpecAnyClass |

Instances

Outputable DerivSpecMechanism Source # |
Instance details Methods ppr :: DerivSpecMechanism -> SDoc Source # pprPrec :: Rational -> DerivSpecMechanism -> SDoc Source #

isDerivSpecStock :: DerivSpecMechanism -> Bool Source #

isDerivSpecNewtype :: DerivSpecMechanism -> Bool Source #

isDerivSpecAnyClass :: DerivSpecMechanism -> Bool Source #

type DerivContext = Maybe ThetaType Source #

data DerivStatus Source #

Constructors

CanDerive |
DerivableClassError SDoc |
DerivableViaInstance |
NonDerivableClass SDoc |

data PredOrigin Source #

A `PredType` annotated with the origin of the constraint `CtOrigin`, and whether or the constraint deals in types or kinds.

Constructors

PredOrigin PredType CtOrigin TypeOrKind |

Instances

Outputable PredOrigin Source # |
Instance details Methods ppr :: PredOrigin -> SDoc Source # pprPrec :: Rational -> PredOrigin -> SDoc Source #

data ThetaOrigin Source #

A list of wanted `PredOrigin` constraints (`to_wanted_origins`) alongside any corresponding given constraints (`to_givens`) and locally quantified type variables (`to_tvs`).

In most cases, `to_givens` will be empty, as most deriving mechanisms (e.g., stock and newtype deriving) do not require given constraints. The exception is `DeriveAnyClass`, which can involve given constraints. For example, if you tried to derive an instance for the following class using `DeriveAnyClass`:

    class Foo a where
      bar :: a -> b -> String
      default bar :: (Show a, Ix b) => a -> b -> String
      bar = show

      baz :: Eq a => a -> a -> Bool
      default baz :: Ord a => a -> a -> Bool
      baz x y = compare x y == EQ

Then it would generate two `ThetaOrigin`s, one for each method:

    [ ThetaOrigin { to_tvs            = [b]
                  , to_givens         = []
                  , to_wanted_origins = [Show a, Ix b] }
    , ThetaOrigin { to_tvs            = []
                  , to_givens         = [Eq a]
                  , to_wanted_origins = [Ord a] }
    ]

Constructors

ThetaOrigin |
Fields to_tvs :: [TyVar] to_givens :: ThetaType to_wanted_origins :: [PredOrigin]

Instances

Outputable ThetaOrigin Source # |
Instance details Methods ppr :: ThetaOrigin -> SDoc Source # pprPrec :: Rational -> ThetaOrigin -> SDoc Source #

mkPredOrigin :: CtOrigin -> TypeOrKind -> PredType -> PredOrigin Source #

mkThetaOrigin :: CtOrigin -> TypeOrKind -> [TyVar] -> ThetaType -> ThetaType -> ThetaOrigin Source #

mkThetaOriginFromPreds :: [PredOrigin] -> ThetaOrigin Source #

substPredOrigin :: HasCallStack => TCvSubst -> PredOrigin -> PredOrigin Source #

checkSideConditions :: DynFlags -> DerivContext -> Class -> [TcType] -> TyCon -> DerivStatus Source #

hasStockDeriving :: Class -> Maybe (SrcSpan -> TyCon -> [Type] -> TcM (LHsBinds GhcPs, BagDerivStuff, [Name])) Source #

canDeriveAnyClass :: DynFlags -> Validity Source #

std_class_via_coercible :: Class -> Bool Source #

non_coercible_class :: Class -> Bool Source #

newDerivClsInst :: ThetaType -> DerivSpec theta -> TcM ClsInst Source #

extendLocalInstEnv :: [ClsInst] -> TcM a -> TcM a Source #