Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Generating derived instance declarations
This module is nominally `subordinate'
to GHC.Tc.Deriv, which is the
`official'
interface to deriving-related things.
This is where we do all the grimy bindings' generation.
Synopsis
- data AuxBindSpec
- gen_Eq_binds :: SrcSpan -> DerivInstTys -> TcM (LHsBinds GhcPs, Bag AuxBindSpec)
- gen_Ord_binds :: SrcSpan -> DerivInstTys -> TcM (LHsBinds GhcPs, Bag AuxBindSpec)
- gen_Enum_binds :: SrcSpan -> DerivInstTys -> TcM (LHsBinds GhcPs, Bag AuxBindSpec)
- gen_Bounded_binds :: SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec)
- gen_Ix_binds :: SrcSpan -> DerivInstTys -> TcM (LHsBinds GhcPs, Bag AuxBindSpec)
- gen_Show_binds :: (Name -> Fixity) -> SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec)
- gen_Read_binds :: (Name -> Fixity) -> SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec)
- gen_Data_binds :: SrcSpan -> DerivInstTys -> TcM (LHsBinds GhcPs, Bag AuxBindSpec)
- gen_Lift_binds :: SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec)
- gen_Newtype_binds :: SrcSpan -> Class -> [TyVar] -> [Type] -> Type -> (LHsBinds GhcPs, [LSig GhcPs])
- gen_Newtype_fam_insts :: SrcSpan -> Class -> [TyVar] -> [Type] -> Type -> TcM [FamInst]
- mkCoerceClassMethEqn :: Class -> [TyVar] -> [Type] -> Type -> Id -> Pair Type
- genAuxBinds :: DynFlags -> SrcSpan -> Bag AuxBindSpec -> Bag (LHsBind GhcPs, LSig GhcPs)
- ordOpTbl :: [(Type, (RdrName, RdrName, RdrName, RdrName, RdrName))]
- boxConTbl :: [(Type, LHsExpr GhcPs -> LHsExpr GhcPs)]
- litConTbl :: [(Type, LHsExpr GhcPs -> LHsExpr GhcPs)]
- mkRdrFunBind :: LocatedN RdrName -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsBind GhcPs
- mkRdrFunBindEC :: Arity -> (LHsExpr GhcPs -> LHsExpr GhcPs) -> LocatedN RdrName -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsBind GhcPs
- mkRdrFunBindSE :: Arity -> LocatedN RdrName -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsBind GhcPs
- error_Expr :: String -> LHsExpr GhcPs
- getPossibleDataCons :: TyCon -> [Type] -> [DataCon]
- data DerivInstTys = DerivInstTys {
- dit_cls_tys :: [Type]
- dit_tc :: TyCon
- dit_tc_args :: [Type]
- dit_rep_tc :: TyCon
- dit_rep_tc_args :: [Type]
- dit_dc_inst_arg_env :: DataConEnv [Type]
- buildDataConInstArgEnv :: TyCon -> [Type] -> DataConEnv [Type]
- derivDataConInstArgTys :: DataCon -> DerivInstTys -> [Type]
- substDerivInstTys :: TCvSubst -> DerivInstTys -> DerivInstTys
- zonkDerivInstTys :: ZonkEnv -> DerivInstTys -> TcM DerivInstTys
Documentation
data AuxBindSpec Source #
A declarative description of an auxiliary binding that should be
generated. See Note [Auxiliary binders]
for a more detailed description
of how these are used.
DerivTag2Con TyCon RdrName |
|
DerivMaxTag TyCon RdrName |
|
DerivDataDataType TyCon RdrName [RdrName] |
|
DerivDataConstr DataCon RdrName RdrName |
|
gen_Eq_binds :: SrcSpan -> DerivInstTys -> TcM (LHsBinds GhcPs, Bag AuxBindSpec) Source #
gen_Ord_binds :: SrcSpan -> DerivInstTys -> TcM (LHsBinds GhcPs, Bag AuxBindSpec) Source #
gen_Enum_binds :: SrcSpan -> DerivInstTys -> TcM (LHsBinds GhcPs, Bag AuxBindSpec) Source #
gen_Bounded_binds :: SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec) Source #
gen_Ix_binds :: SrcSpan -> DerivInstTys -> TcM (LHsBinds GhcPs, Bag AuxBindSpec) Source #
gen_Show_binds :: (Name -> Fixity) -> SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec) Source #
gen_Read_binds :: (Name -> Fixity) -> SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec) Source #
gen_Data_binds :: SrcSpan -> DerivInstTys -> TcM (LHsBinds GhcPs, Bag AuxBindSpec) Source #
gen_Lift_binds :: SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, Bag AuxBindSpec) Source #
gen_Newtype_binds :: SrcSpan -> Class -> [TyVar] -> [Type] -> Type -> (LHsBinds GhcPs, [LSig GhcPs]) Source #
genAuxBinds :: DynFlags -> SrcSpan -> Bag AuxBindSpec -> Bag (LHsBind GhcPs, LSig GhcPs) Source #
Take a Bag
of AuxBindSpec
s and generate the code for auxiliary
bindings based on the declarative descriptions in the supplied
AuxBindSpec
s. See Note [Auxiliary binders]
.
mkRdrFunBindEC :: Arity -> (LHsExpr GhcPs -> LHsExpr GhcPs) -> LocatedN RdrName -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsBind GhcPs Source #
Produces a function binding. When no equations are given, it generates a binding of the given arity and an empty case expression for the last argument that it passes to the given function to produce the right-hand side.
mkRdrFunBindSE :: Arity -> LocatedN RdrName -> [LMatch GhcPs (LHsExpr GhcPs)] -> LHsBind GhcPs Source #
Produces a function binding. When there are no equations, it generates a binding with the given arity that produces an error based on the name of the type of the last argument.
getPossibleDataCons :: TyCon -> [Type] -> [DataCon] Source #
getPossibleDataCons tycon tycon_args
returns the constructors of tycon
whose return types match when checked against tycon_args
.
See Note [Filter out impossible GADT data constructors]
data DerivInstTys Source #
Information about the arguments to the class in a stock- or
newtype-derived instance. For a deriving
-generated instance declaration
such as this one:
instance Ctx => Cls cls_ty_1 ... cls_ty_m (TC tc_arg_1 ... tc_arg_n) where ...
dit_cls_tys
corresponds tocls_ty_1 ... cls_ty_m
.dit_tc
corresponds toTC
.dit_tc_args
corresponds totc_arg_1 ... tc_arg_n
.
See Note [DerivEnv and DerivSpecMechanism]
in GHC.Tc.Deriv.Utils for a
more in-depth explanation, including the relationship between
dit_tc
dit_rep_tc
and dit_tc_args
dit_rep_tc_args
.
A DerivInstTys
value can be seen as a more structured representation of
the denv_inst_tys
in a DerivEnv
, as the denv_inst_tys
is equal to
dit_cls_tys ++ [
. Other parts of the
instance declaration can be found in the mkTyConApp
dit_tc dit_tc_args]DerivEnv
. For example, the Cls
in the example above corresponds to the denv_cls
field of DerivEnv
.
Similarly, the type variables that appear in a DerivInstTys
value are the
same type variables as the denv_tvs
in the parent DerivEnv
. Accordingly,
if we are inferring an instance context, the type variables will be TcTyVar
skolems. Otherwise, they will be ordinary TyVar
s.
See Note [Overlap and deriving]
in GHC.Tc.Deriv.Infer.
DerivInstTys | |
|
Instances
Outputable DerivInstTys Source # | |
Defined in GHC.Tc.Deriv.Generate ppr :: DerivInstTys -> SDoc Source # |
buildDataConInstArgEnv :: TyCon -> [Type] -> DataConEnv [Type] Source #
constructs a cache that maps
each of buildDataConInstArgEnv
tycon arg_tystycon
's data constructors to their field types, with are to be
instantiated with arg_tys
.
See Note [Instantiating field types in stock deriving]
.
derivDataConInstArgTys :: DataCon -> DerivInstTys -> [Type] Source #
Look up a data constructor's instantiated field types in a DerivInstTys
.
See Note [Instantiating field types in stock deriving]
.
substDerivInstTys :: TCvSubst -> DerivInstTys -> DerivInstTys Source #
Apply a substitution to all of the Type
s contained in a DerivInstTys
.
See Note [Instantiating field types in stock deriving]
for why we need to
substitute into a DerivInstTys
in the first place.
zonkDerivInstTys :: ZonkEnv -> DerivInstTys -> TcM DerivInstTys Source #
Zonk the TcTyVar
s in a DerivInstTys
value to TyVar
s.
See Note [What is zonking?]
in GHC.Tc.Utils.TcMType.
This is only used in the final zonking step when inferring
the context for a derived instance.
See Note [Overlap and deriving]
in GHC.Tc.Deriv.Infer.