mkPADictType, mkPArrayType, mkPReprType,
parrayCoerce, parrayReprTyCon, parrayReprDataCon, mkVScrut,
- prDictOfType, prCoerce,
+ prDFunOfTyCon, prCoerce,
paDictArgType, paDictOfType, paDFunType,
- paMethod, lengthPA, replicatePA, emptyPA, liftPA,
+ paMethod, mkPR, lengthPA, replicatePA, emptyPA, liftPA,
polyAbstract, polyApply, polyVApply,
hoistBinding, hoistExpr, hoistPolyVExpr, takeHoisted,
buildClosure, buildClosures,
import Name ( Name )
import PrelNames
import TysWiredIn
+import TysPrim ( intPrimTy )
import BasicTypes ( Boxity(..) )
import Outputable
data TyConRepr = TyConRepr {
repr_tyvars :: [TyVar]
, repr_tys :: [[Type]]
+ , arr_shape_tys :: [Type]
+ , arr_repr_tys :: [[Type]]
, repr_prod_tycons :: [Maybe TyCon]
, repr_prod_data_cons :: [Maybe DataCon]
mkTyConRepr :: TyCon -> VM TyConRepr
mkTyConRepr vect_tc
= do
- prod_tycons <- mapM (mk_tycon prodTyCon) rep_tys
+ uarr <- builtin uarrTyCon
+ prod_tycons <- mapM (mk_tycon prodTyCon) rep_tys
let prod_tys = zipWith mk_tc_app_maybe prod_tycons rep_tys
- sum_tycon <- mk_tycon sumTyCon prod_tys
+ sum_tycon <- mk_tycon sumTyCon prod_tys
+ arr_repr_tys <- mapM (mapM mkPArrayType . arr_repr_elem_tys) rep_tys
return $ TyConRepr {
repr_tyvars = tyvars
, repr_tys = rep_tys
+ , arr_shape_tys = mk_shape uarr
+ , arr_repr_tys = arr_repr_tys
, repr_prod_tycons = prod_tycons
, repr_prod_data_cons = map (fmap mk_single_datacon) prod_tycons
data_cons = tyConDataCons vect_tc
rep_tys = map dataConRepArgTys data_cons
+ is_product | [_] <- data_cons = True
+ | otherwise = False
+
+ mk_shape uarr = intPrimTy : mk_sel uarr
+
+ mk_sel uarr | is_product = []
+ | otherwise = [uarr_int, uarr_int]
+ where
+ uarr_int = mkTyConApp uarr [intTy]
+
mk_tycon get_tc tys
| n > 1 = builtin (Just . get_tc n)
| otherwise = return Nothing
mk_tc_app_maybe Nothing [ty] = ty
mk_tc_app_maybe (Just tc) tys = mkTyConApp tc tys
+ arr_repr_elem_tys [] = [unitTy]
+ arr_repr_elem_tys tys = tys
+
mkToArrPRepr :: CoreExpr -> CoreExpr -> [[CoreExpr]] -> VM CoreExpr
mkToArrPRepr len sel ess
= do
(tc, arg_tys) <- parrayReprTyCon (exprType ve)
return ((ve, unwrapFamInstScrut tc arg_tys le), tc, arg_tys)
-prDictOfType :: Type -> VM CoreExpr
-prDictOfType orig_ty
- | Just (tycon, ty_args) <- splitTyConApp_maybe orig_ty
- = do
- dfun <- traceMaybeV "prDictOfType" (ppr tycon) (lookupTyConPR tycon)
- prDFunApply (Var dfun) ty_args
-
-prDFunApply :: CoreExpr -> [Type] -> VM CoreExpr
-prDFunApply dfun tys
- = do
- args <- mapM mkDFunArg arg_tys
- return $ mkApps mono_dfun args
- where
- mono_dfun = mkTyApps dfun tys
- (arg_tys, _) = splitFunTys (exprType mono_dfun)
-
-mkDFunArg :: Type -> VM CoreExpr
-mkDFunArg ty
- | Just (tycon, [arg]) <- splitTyConApp_maybe ty
-
- = let name = tyConName tycon
-
- get_dict | name == paTyConName = paDictOfType
- | name == prTyConName = prDictOfType
- | otherwise = pprPanic "mkDFunArg" (ppr ty)
-
- in get_dict arg
-
-mkDFunArg ty = pprPanic "mkDFunArg" (ppr ty)
+prDFunOfTyCon :: TyCon -> VM CoreExpr
+prDFunOfTyCon tycon
+ = liftM Var (traceMaybeV "prDictOfTyCon" (ppr tycon) (lookupTyConPR tycon))
prCoerce :: TyCon -> [Type] -> CoreExpr -> VM CoreExpr
prCoerce repr_tc args expr