- tvs = tyConTyVars vect_tc
- arg_tys = mkTyVarTys tvs
- res_ty = mkTyConApp vect_tc arg_tys
-
- orig_worker = dataConWorkId orig_dc
-
- mk_vect = return . mkConApp vect_dc $ map Type arg_tys
- mk_lift = do
- len <- newLocalVar FSLIT("n") intPrimTy
- arr_tys <- mapM mkPArrayType dc_tys
- args <- mapM (newLocalVar FSLIT("xs")) arr_tys
- shapes <- shapeReplicate shape (Var len) (mkIntLitInt dc_num)
-
- empty_pre <- mapM emptyPA (concat pre)
- empty_post <- mapM emptyPA (concat post)
-
- return . mkLams (len : args)
- . wrapFamInstBody arr_tc arg_tys
- . mkConApp arr_dc
- $ map Type arg_tys ++ shapes
- ++ empty_pre
- ++ map Var args
- ++ empty_post
-
-data Shape = Shape {
- shapeReprTys :: [Type]
- , shapeStrictness :: [StrictnessMark]
- , shapeLength :: [CoreExpr] -> VM CoreExpr
- , shapeReplicate :: CoreExpr -> CoreExpr -> VM [CoreExpr]
- }
-
-tyConShape :: TyCon -> VM Shape
-tyConShape vect_tc
- | isProductTyCon vect_tc
- = return $ Shape {
- shapeReprTys = [intPrimTy]
- , shapeStrictness = [NotMarkedStrict]
- , shapeLength = \[len] -> return len
- , shapeReplicate = \len _ -> return [len]
- }
-
- | otherwise
+ var_tys = mkTyVarTys $ tyConTyVars vect_tc
+ el_ty = mkTyConApp vect_tc var_tys
+
+ [pdata_con] = tyConDataCons pdata_tc
+
+ from_sum _ res _ EmptySum = return (res, [])
+ from_sum res_ty res expr (UnarySum r) = from_con res_ty res expr r
+ from_sum res_ty res expr (Sum { repr_psum_tc = psum_tc
+ , repr_sel_ty = sel_ty
+ , repr_con_tys = tys
+ , repr_cons = cons })
+ = do
+ sel <- newLocalVar (fsLit "sel") sel_ty
+ ptys <- mapM mkPDataType tys
+ vars <- newLocalVars (fsLit "xs") ptys
+ (res', args) <- fold from_con res_ty res (map Var vars) cons
+ let scrut = unwrapFamInstScrut psum_tc tys expr
+ body = mkWildCase scrut (exprType scrut) res_ty
+ [(DataAlt psum_con, sel : vars, res')]
+ return (body, Var sel : args)
+ where
+ [psum_con] = tyConDataCons psum_tc
+
+
+ from_con res_ty res expr (ConRepr _ r) = from_prod res_ty res expr r
+
+ from_prod _ res _ EmptyProd = return (res, [])
+ from_prod res_ty res expr (UnaryProd r)
+ = from_comp res_ty res expr r
+ from_prod res_ty res expr (Prod { repr_ptup_tc = ptup_tc
+ , repr_comp_tys = tys
+ , repr_comps = comps })
+ = do
+ ptys <- mapM mkPDataType tys
+ vars <- newLocalVars (fsLit "ys") ptys
+ (res', args) <- fold from_comp res_ty res (map Var vars) comps
+ let scrut = unwrapFamInstScrut ptup_tc tys expr
+ body = mkWildCase scrut (exprType scrut) res_ty
+ [(DataAlt ptup_con, vars, res')]
+ return (body, args)
+ where
+ [ptup_con] = tyConDataCons ptup_tc
+
+ from_comp _ res expr (Keep _ _) = return (res, [expr])
+ from_comp _ res expr (Wrap ty)
+ = do
+ wrap_tc <- builtin wrapTyCon
+ (pwrap_tc, _) <- pdataReprTyCon (mkTyConApp wrap_tc [ty])
+ return (res, [unwrapNewTypeBody pwrap_tc [ty]
+ $ unwrapFamInstScrut pwrap_tc [ty] expr])
+
+ fold f res_ty res exprs rs = foldrM f' (res, []) (zip exprs rs)
+ where
+ f' (expr, r) (res, args) = do
+ (res', args') <- f res_ty res expr r
+ return (res', args' ++ args)
+
+buildPRDict :: TyCon -> TyCon -> TyCon -> SumRepr -> VM CoreExpr
+buildPRDict vect_tc prepr_tc _ r