import CmdLineOpts ( DynFlag(..), DynFlags )
import TcMonad
-import TcEnv ( TcEnv, tcSetInstEnv, newDFunName, InstInfo(..), pprInstInfo,
+import TcEnv ( tcSetInstEnv, newDFunName, InstInfo(..), pprInstInfo,
tcLookupClass, tcLookupTyCon
)
import TcGenDeriv -- Deriv stuff
tyConTheta, maybeTyConSingleCon, isDataTyCon,
isEnumerationTyCon, TyCon
)
-import Type ( TauType, PredType(..), mkTyVarTys, mkTyConApp, isUnboxedType )
+import TcType ( ThetaType, mkTyVarTys, mkTyConApp,
+ isUnLiftedType, mkClassPred )
import Var ( TyVar )
import PrelNames
import Util ( zipWithEqual, sortLt )
-- The Name is the name for the DFun we'll build
-- The tyvars bind all the variables in the RHS
-type DerivRhs = [(Class, [TauType])] -- Same as a ThetaType!
- --[PredType] -- ... | Class Class [Type==TauType]
-
+type DerivRhs = ThetaType
type DerivSoln = DerivRhs
\end{code}
-- Fish the "deriving"-related information out of the TcEnv
-- and make the necessary "equations".
- makeDerivEqns mod tycl_decls `thenTc` \ eqns ->
+ makeDerivEqns tycl_decls `thenTc` \ eqns ->
if null eqns then
returnTc ([], EmptyBinds)
else
-- Make a Real dfun instead of the dummy one we have so far
gen_inst_info :: DFunId -> RenamedMonoBinds -> InstInfo
gen_inst_info dfun binds
- = InstInfo { iLocal = True, iDFunId = dfun,
+ = InstInfo { iDFunId = dfun,
iBinds = binds, iPrags = [] }
rn_meths meths = rnMethodBinds [] meths `thenRn` \ (meths', _) -> returnRn meths'
all those.
\begin{code}
-makeDerivEqns :: Module -> [RenamedTyClDecl] -> TcM [DerivEqn]
+makeDerivEqns :: [RenamedTyClDecl] -> TcM [DerivEqn]
-makeDerivEqns this_mod tycl_decls
+makeDerivEqns tycl_decls
= mapTc mk_eqn derive_these `thenTc` \ maybe_eqns ->
returnTc (catMaybes maybe_eqns)
where
-- Find the (Class,TyCon) pairs that must be `derived'
-- NB: only source-language decls have deriving, no imported ones do
derive_these = [ (clas,tycon)
- | TyData _ _ tycon _ _ _ (Just classes) _ _ _ <- tycl_decls,
+ | TyData {tcdName = tycon, tcdDerivs = Just classes} <- tycl_decls,
clas <- nub classes ]
------------------------------------------------------------------
offensive_class = clas_key `elem` needsDataDeclCtxtClassKeys
mk_constraints data_con
- = [ (clas, [arg_ty])
+ = [ mkClassPred clas [arg_ty]
| arg_ty <- dataConArgTys data_con tyvar_tys,
- not (isUnboxedType arg_ty) -- No constraints for unboxed types?
+ not (isUnLiftedType arg_ty) -- No constraints for unlifted types?
]
in
case chk_out clas tycon of
Just err -> addErrTc err `thenNF_Tc_`
returnNF_Tc Nothing
- Nothing -> newDFunName this_mod clas [ty] locn `thenNF_Tc` \ dfun_name ->
+ Nothing -> newDFunName clas [ty] locn `thenNF_Tc` \ dfun_name ->
returnNF_Tc (Just (dfun_name, clas, tycon, tyvars, constraints))
in
-- Simplify each RHS
tcSetInstEnv inst_env (
- listTc [ tcAddErrCtxt (derivCtxt tc) $
+ listTc [ tcAddSrcLoc (getSrcLoc tc) $
+ tcAddErrCtxt (derivCtxt tc) $
tcSimplifyThetas deriv_rhs
| (_, _,tc,_,deriv_rhs) <- orig_eqns ]
) `thenTc` \ next_solns ->
-- They'll appear later, when we do the top-level extendInstEnvs
mk_deriv_dfun (dfun_name, clas, tycon, tyvars, _) theta
- = mkDictFunId dfun_name clas tyvars [mkTyConApp tycon (mkTyVarTys tyvars)]
- (map pair2PredType theta)
-
- pair2PredType (clas, tautypes) = Class clas tautypes
+ = mkDictFunId dfun_name clas tyvars
+ [mkTyConApp tycon (mkTyVarTys tyvars)]
+ theta
\end{code}
%************************************************************************
con2tag_Foo :: Foo ... -> Int#
tag2con_Foo :: Int -> Foo ... -- easier if Int, not Int#
-maxtag_Foo :: Int -- ditto (NB: not unboxed)
+maxtag_Foo :: Int -- ditto (NB: not unlifted)
We have a @con2tag@ function for a tycon if: