Finish breaking up VectBuiltIn and VectMonad, and add comments
[ghc-hetmet.git] / compiler / vectorise / Vectorise.hs
1 {-# OPTIONS -fno-warn-missing-signatures #-}
2
3 module Vectorise( vectorise )
4 where
5
6 import VectUtils
7 import VectVar
8 import VectType
9 import Vectorise.Vect
10 import Vectorise.Env
11 import Vectorise.Monad
12 import Vectorise.Builtins
13
14 import HscTypes hiding      ( MonadThings(..) )
15
16 import Module               ( PackageId )
17 import CoreSyn
18 import CoreUtils
19 import CoreUnfold           ( mkInlineRule )
20 import MkCore               ( mkWildCase )
21 import CoreFVs
22 import CoreMonad            ( CoreM, getHscEnv )
23 import DataCon
24 import TyCon
25 import Type
26 import FamInstEnv           ( extendFamInstEnvList )
27 import Var
28 import VarEnv
29 import VarSet
30 import Id
31 import OccName
32 import BasicTypes           ( isLoopBreaker )
33
34 import Literal
35 import TysWiredIn
36 import TysPrim              ( intPrimTy )
37
38 import Outputable
39 import FastString
40 import Util                 ( zipLazy )
41 import Control.Monad
42 import Data.List            ( sortBy, unzip4 )
43
44
45 debug           = False
46 dtrace s x      = if debug then pprTrace "Vectorise" s x else x
47
48 -- | Vectorise a single module.
49 --   Takes the package containing the DPH backend we're using. Eg either dph-par or dph-seq.
50 vectorise :: PackageId -> ModGuts -> CoreM ModGuts
51 vectorise backend guts 
52  = do hsc_env <- getHscEnv
53       liftIO $ vectoriseIO backend hsc_env guts
54
55
56 -- | Vectorise a single monad, given its HscEnv (code gen environment).
57 vectoriseIO :: PackageId -> HscEnv -> ModGuts -> IO ModGuts
58 vectoriseIO backend hsc_env guts
59  = do -- Get information about currently loaded external packages.
60       eps <- hscEPS hsc_env
61
62       -- Combine vectorisation info from the current module, and external ones.
63       let info = hptVectInfo hsc_env `plusVectInfo` eps_vect_info eps
64
65       -- Run the main VM computation.
66       Just (info', guts') <- initV backend hsc_env guts info (vectModule guts)
67       return (guts' { mg_vect_info = info' })
68
69
70 -- | Vectorise a single module, in the VM monad.
71 vectModule :: ModGuts -> VM ModGuts
72 vectModule guts
73  = do -- Vectorise the type environment.
74       -- This may add new TyCons and DataCons.
75       -- TODO: What new binds do we get back here?
76       (types', fam_insts, tc_binds) <- vectTypeEnv (mg_types guts)
77
78       -- TODO: What is this?
79       let fam_inst_env' = extendFamInstEnvList (mg_fam_inst_env guts) fam_insts
80       updGEnv (setFamInstEnv fam_inst_env')
81
82       -- dicts   <- mapM buildPADict pa_insts
83       -- workers <- mapM vectDataConWorkers pa_insts
84
85       -- Vectorise all the top level bindings.
86       binds'  <- mapM vectTopBind (mg_binds guts)
87
88       return $ guts { mg_types        = types'
89                     , mg_binds        = Rec tc_binds : binds'
90                     , mg_fam_inst_env = fam_inst_env'
91                     , mg_fam_insts    = mg_fam_insts guts ++ fam_insts
92                     }
93
94
95 -- | Try to vectorise a top-level binding.
96 --   If it doesn't vectorise then return it unharmed.
97 --
98 --   For example, for the binding 
99 --
100 --   @  
101 --      foo :: Int -> Int
102 --      foo = \x -> x + x
103 --   @
104 --  
105 --   we get
106 --   @
107 --      foo  :: Int -> Int
108 --      foo  = \x -> vfoo $: x                  
109 -- 
110 --      v_foo :: Closure void vfoo lfoo
111 --      v_foo = closure vfoo lfoo void        
112 -- 
113 --      vfoo :: Void -> Int -> Int
114 --      vfoo = ...
115 --
116 --      lfoo :: PData Void -> PData Int -> PData Int
117 --      lfoo = ...
118 --   @ 
119 --
120 --   @vfoo@ is the "vectorised", or scalar, version that does the same as the original
121 --   function foo, but takes an explicit environment.
122 -- 
123 --   @lfoo@ is the "lifted" version that works on arrays.
124 --
125 --   @v_foo@ combines both of these into a `Closure` that also contains the
126 --   environment.
127 --
128 --   The original binding @foo@ is rewritten to call the vectorised version
129 --   present in the closure.
130 --
131 vectTopBind :: CoreBind -> VM CoreBind
132 vectTopBind b@(NonRec var expr)
133  = do
134       (inline, expr')   <- vectTopRhs var expr
135       var'              <- vectTopBinder var inline expr'
136
137       -- Vectorising the body may create other top-level bindings.
138       hs        <- takeHoisted
139
140       -- To get the same functionality as the original body we project
141       -- out its vectorised version from the closure.
142       cexpr     <- tryConvert var var' expr
143
144       return . Rec $ (var, cexpr) : (var', expr') : hs
145   `orElseV`
146     return b
147
148 vectTopBind b@(Rec bs)
149  = do
150       (vars', _, exprs') 
151         <- fixV $ \ ~(_, inlines, rhss) ->
152             do vars' <- sequence [vectTopBinder var inline rhs
153                                       | (var, ~(inline, rhs)) <- zipLazy vars (zip inlines rhss)]
154                (inlines', exprs') 
155                      <- mapAndUnzipM (uncurry vectTopRhs) bs
156
157                return (vars', inlines', exprs')
158
159       hs     <- takeHoisted
160       cexprs <- sequence $ zipWith3 tryConvert vars vars' exprs
161       return . Rec $ zip vars cexprs ++ zip vars' exprs' ++ hs
162   `orElseV`
163     return b
164   where
165     (vars, exprs) = unzip bs
166
167
168 -- | Make the vectorised version of this top level binder, and add the mapping
169 --   between it and the original to the state. For some binder @foo@ the vectorised
170 --   version is @$v_foo@
171 --
172 --   NOTE: vectTopBinder *MUST* be lazy in inline and expr because of how it is
173 --   used inside of fixV in vectTopBind
174 vectTopBinder 
175         :: Var          -- ^ Name of the binding.
176         -> Inline       -- ^ Whether it should be inlined, used to annotate it.
177         -> CoreExpr     -- ^ RHS of the binding, used to set the `Unfolding` of the returned `Var`.
178         -> VM Var       -- ^ Name of the vectorised binding.
179
180 vectTopBinder var inline expr
181  = do
182       -- Vectorise the type attached to the var.
183       vty  <- vectType (idType var)
184
185       -- Make the vectorised version of binding's name, and set the unfolding used for inlining.
186       var' <- liftM (`setIdUnfolding` unfolding) 
187            $  cloneId mkVectOcc var vty
188
189       -- Add the mapping between the plain and vectorised name to the state.
190       defGlobalVar var var'
191
192       return var'
193   where
194     unfolding = case inline of
195                   Inline arity -> mkInlineRule expr (Just arity)
196                   DontInline   -> noUnfolding
197
198
199 -- | Vectorise the RHS of a top-level binding, in an empty local environment.
200 vectTopRhs 
201         :: Var          -- ^ Name of the binding.
202         -> CoreExpr     -- ^ Body of the binding.
203         -> VM (Inline, CoreExpr)
204
205 vectTopRhs var expr
206  = dtrace (vcat [text "vectTopRhs", ppr expr])
207  $ closedV
208  $ do (inline, vexpr) <- inBind var
209                       $ vectPolyExpr (isLoopBreaker $ idOccInfo var)
210                                       (freeVars expr)
211       return (inline, vectorised vexpr)
212
213
214 -- | Project out the vectorised version of a binding from some closure,
215 --      or return the original body if that doesn't work.       
216 tryConvert 
217         :: Var          -- ^ Name of the original binding (eg @foo@)
218         -> Var          -- ^ Name of vectorised version of binding (eg @$vfoo@)
219         -> CoreExpr     -- ^ The original body of the binding.
220         -> VM CoreExpr
221
222 tryConvert var vect_var rhs
223   = fromVect (idType var) (Var vect_var) `orElseV` return rhs
224
225
226 -- ----------------------------------------------------------------------------
227 -- Expressions
228
229
230 -- | Vectorise a polymorphic expression
231 vectPolyExpr 
232         :: Bool                 -- ^ When vectorising the RHS of a binding, whether that
233                                 --   binding is a loop breaker.
234         -> CoreExprWithFVs
235         -> VM (Inline, VExpr)
236
237 vectPolyExpr loop_breaker (_, AnnNote note expr)
238  = do (inline, expr') <- vectPolyExpr loop_breaker expr
239       return (inline, vNote note expr')
240
241 vectPolyExpr loop_breaker expr
242  = dtrace (vcat [text "vectPolyExpr", ppr (deAnnotate expr)])
243  $ do
244       arity <- polyArity tvs
245       polyAbstract tvs $ \args ->
246         do
247           (inline, mono') <- vectFnExpr False loop_breaker mono
248           return (addInlineArity inline arity,
249                   mapVect (mkLams $ tvs ++ args) mono')
250   where
251     (tvs, mono) = collectAnnTypeBinders expr
252
253
254 -- | Vectorise a core expression.
255 vectExpr :: CoreExprWithFVs -> VM VExpr
256 vectExpr (_, AnnType ty)
257   = liftM vType (vectType ty)
258
259 vectExpr (_, AnnVar v) 
260   = vectVar v
261
262 vectExpr (_, AnnLit lit) 
263   = vectLiteral lit
264
265 vectExpr (_, AnnNote note expr)
266   = liftM (vNote note) (vectExpr expr)
267
268 vectExpr e@(_, AnnApp _ arg)
269   | isAnnTypeArg arg
270   = vectTyAppExpr fn tys
271   where
272     (fn, tys) = collectAnnTypeArgs e
273
274 vectExpr (_, AnnApp (_, AnnVar v) (_, AnnLit lit))
275   | Just con <- isDataConId_maybe v
276   , is_special_con con
277   = do
278       let vexpr = App (Var v) (Lit lit)
279       lexpr <- liftPD vexpr
280       return (vexpr, lexpr)
281   where
282     is_special_con con = con `elem` [intDataCon, floatDataCon, doubleDataCon]
283
284
285 -- TODO: Avoid using closure application for dictionaries.
286 -- vectExpr (_, AnnApp fn arg)
287 --  | if is application of dictionary 
288 --    just use regular app instead of closure app.
289
290 -- for lifted version. 
291 --      do liftPD (sub a dNumber)
292 --      lift the result of the selection, not sub and dNumber seprately. 
293
294 vectExpr (_, AnnApp fn arg)
295  = dtrace (text "AnnApp" <+> ppr (deAnnotate fn) <+> ppr (deAnnotate arg))
296  $ do
297       arg_ty' <- vectType arg_ty
298       res_ty' <- vectType res_ty
299
300       dtrace (text "vectorising fn " <> ppr (deAnnotate fn))  $ return ()
301       fn'     <- vectExpr fn
302       dtrace (text "fn' = "       <> ppr fn') $ return ()
303
304       arg'    <- vectExpr arg
305
306       mkClosureApp arg_ty' res_ty' fn' arg'
307   where
308     (arg_ty, res_ty) = splitFunTy . exprType $ deAnnotate fn
309
310 vectExpr (_, AnnCase scrut bndr ty alts)
311   | Just (tycon, ty_args) <- splitTyConApp_maybe scrut_ty
312   , isAlgTyCon tycon
313   = vectAlgCase tycon ty_args scrut bndr ty alts
314   where
315     scrut_ty = exprType (deAnnotate scrut)
316
317 vectExpr (_, AnnLet (AnnNonRec bndr rhs) body)
318   = do
319       vrhs <- localV . inBind bndr . liftM snd $ vectPolyExpr False rhs
320       (vbndr, vbody) <- vectBndrIn bndr (vectExpr body)
321       return $ vLet (vNonRec vbndr vrhs) vbody
322
323 vectExpr (_, AnnLet (AnnRec bs) body)
324   = do
325       (vbndrs, (vrhss, vbody)) <- vectBndrsIn bndrs
326                                 $ liftM2 (,)
327                                   (zipWithM vect_rhs bndrs rhss)
328                                   (vectExpr body)
329       return $ vLet (vRec vbndrs vrhss) vbody
330   where
331     (bndrs, rhss) = unzip bs
332
333     vect_rhs bndr rhs = localV
334                       . inBind bndr
335                       . liftM snd
336                       $ vectPolyExpr (isLoopBreaker $ idOccInfo bndr) rhs
337
338 vectExpr e@(_, AnnLam bndr _)
339   | isId bndr = liftM snd $ vectFnExpr True False e
340 {-
341 onlyIfV (isEmptyVarSet fvs) (vectScalarLam bs $ deAnnotate body)
342                 `orElseV` vectLam True fvs bs body
343   where
344     (bs,body) = collectAnnValBinders e
345 -}
346
347 vectExpr e = cantVectorise "Can't vectorise expression" (ppr $ deAnnotate e)
348
349
350 -- | Vectorise an expression with an outer lambda abstraction.
351 vectFnExpr 
352         :: Bool                 -- ^ When the RHS of a binding, whether that binding should be inlined.
353         -> Bool                 -- ^ Whether the binding is a loop breaker.
354         -> CoreExprWithFVs      -- ^ Expression to vectorise. Must have an outer `AnnLam`.
355         -> VM (Inline, VExpr)
356
357 vectFnExpr inline loop_breaker e@(fvs, AnnLam bndr _)
358   | isId bndr = onlyIfV (isEmptyVarSet fvs)
359                         (mark DontInline . vectScalarLam bs $ deAnnotate body)
360                 `orElseV` mark inlineMe (vectLam inline loop_breaker fvs bs body)
361   where
362     (bs,body) = collectAnnValBinders e
363
364 vectFnExpr _ _ e = mark DontInline $ vectExpr e
365
366 mark :: Inline -> VM a -> VM (Inline, a)
367 mark b p = do { x <- p; return (b,x) }
368
369
370 -- | Vectorise a function where are the args have scalar type, that is Int, Float or Double.
371 vectScalarLam 
372         :: [Var]        -- ^ Bound variables of function.
373         -> CoreExpr     -- ^ Function body.
374         -> VM VExpr
375 vectScalarLam args body
376  = dtrace (vcat [text "vectScalarLam ", ppr args, ppr body])
377  $ do scalars <- globalScalars
378       onlyIfV (all is_scalar_ty arg_tys
379                && is_scalar_ty res_ty
380                && is_scalar (extendVarSetList scalars args) body
381                && uses scalars body)
382         $ do
383             fn_var  <- hoistExpr (fsLit "fn") (mkLams args body) DontInline
384             zipf    <- zipScalars arg_tys res_ty
385             clo     <- scalarClosure arg_tys res_ty (Var fn_var)
386                                                 (zipf `App` Var fn_var)
387             clo_var <- hoistExpr (fsLit "clo") clo DontInline
388             lclo    <- liftPD (Var clo_var)
389             return (Var clo_var, lclo)
390   where
391     arg_tys = map idType args
392     res_ty  = exprType body
393
394     is_scalar_ty ty 
395         | Just (tycon, [])   <- splitTyConApp_maybe ty
396         =    tycon == intTyCon
397           || tycon == floatTyCon
398           || tycon == doubleTyCon
399
400         | otherwise = False
401
402     is_scalar vs (Var v)     = v `elemVarSet` vs
403     is_scalar _ e@(Lit _)    = is_scalar_ty $ exprType e
404     is_scalar vs (App e1 e2) = is_scalar vs e1 && is_scalar vs e2
405     is_scalar _ _            = False
406
407     -- A scalar function has to actually compute something. Without the check,
408     -- we would treat (\(x :: Int) -> x) as a scalar function and lift it to
409     -- (map (\x -> x)) which is very bad. Normal lifting transforms it to
410     -- (\n# x -> x) which is what we want.
411     uses funs (Var v)     = v `elemVarSet` funs 
412     uses funs (App e1 e2) = uses funs e1 || uses funs e2
413     uses _ _              = False
414
415
416 vectLam 
417         :: Bool                 -- ^ When the RHS of a binding, whether that binding should be inlined.
418         -> Bool                 -- ^ Whether the binding is a loop breaker.
419         -> VarSet               -- ^ The free variables in the body.
420         -> [Var]                -- 
421         -> CoreExprWithFVs
422         -> VM VExpr
423
424 vectLam inline loop_breaker fvs bs body
425  = dtrace (vcat [ text "vectLam "
426                 , text "free vars    = " <> ppr fvs
427                 , text "binding vars = " <> ppr bs
428                 , text "body         = " <> ppr (deAnnotate body)])
429
430  $ do tyvars    <- localTyVars
431       (vs, vvs) <- readLEnv $ \env ->
432                    unzip [(var, vv) | var <- varSetElems fvs
433                                     , Just vv <- [lookupVarEnv (local_vars env) var]]
434
435       arg_tys   <- mapM (vectType . idType) bs
436
437       dtrace (text "arg_tys = " <> ppr arg_tys) $ return ()
438
439       res_ty    <- vectType (exprType $ deAnnotate body)
440
441       dtrace (text "res_ty = " <> ppr res_ty) $ return ()
442
443       buildClosures tyvars vvs arg_tys res_ty
444         . hoistPolyVExpr tyvars (maybe_inline (length vs + length bs))
445         $ do
446             lc              <- builtin liftingContext
447             (vbndrs, vbody) <- vectBndrsIn (vs ++ bs) (vectExpr body)
448
449             dtrace (text "vbody = " <> ppr vbody) $ return ()
450
451             vbody' <- break_loop lc res_ty vbody
452             return $ vLams lc vbndrs vbody'
453   where
454     maybe_inline n | inline    = Inline n
455                    | otherwise = DontInline
456
457     break_loop lc ty (ve, le)
458       | loop_breaker
459       = do
460           empty <- emptyPD ty
461           lty <- mkPDataType ty
462           return (ve, mkWildCase (Var lc) intPrimTy lty
463                         [(DEFAULT, [], le),
464                          (LitAlt (mkMachInt 0), [], empty)])
465
466       | otherwise = return (ve, le)
467  
468
469 vectTyAppExpr :: CoreExprWithFVs -> [Type] -> VM VExpr
470 vectTyAppExpr (_, AnnVar v) tys = vectPolyVar v tys
471 vectTyAppExpr e tys = cantVectorise "Can't vectorise expression"
472                         (ppr $ deAnnotate e `mkTyApps` tys)
473
474 -- We convert
475 --
476 --   case e :: t of v { ... }
477 --
478 -- to
479 --
480 --   V:    let v' = e in case v' of _ { ... }
481 --   L:    let v' = e in case v' `cast` ... of _ { ... }
482 --
483 -- When lifting, we have to do it this way because v must have the type
484 -- [:V(T):] but the scrutinee must be cast to the representation type. We also
485 -- have to handle the case where v is a wild var correctly.
486 --
487
488 -- FIXME: this is too lazy
489 vectAlgCase :: TyCon -> [Type] -> CoreExprWithFVs -> Var -> Type
490             -> [(AltCon, [Var], CoreExprWithFVs)]
491             -> VM VExpr
492 vectAlgCase _tycon _ty_args scrut bndr ty [(DEFAULT, [], body)]
493   = do
494       vscrut         <- vectExpr scrut
495       (vty, lty)     <- vectAndLiftType ty
496       (vbndr, vbody) <- vectBndrIn bndr (vectExpr body)
497       return $ vCaseDEFAULT vscrut vbndr vty lty vbody
498
499 vectAlgCase _tycon _ty_args scrut bndr ty [(DataAlt _, [], body)]
500   = do
501       vscrut         <- vectExpr scrut
502       (vty, lty)     <- vectAndLiftType ty
503       (vbndr, vbody) <- vectBndrIn bndr (vectExpr body)
504       return $ vCaseDEFAULT vscrut vbndr vty lty vbody
505
506 vectAlgCase _tycon _ty_args scrut bndr ty [(DataAlt dc, bndrs, body)]
507   = do
508       (vty, lty) <- vectAndLiftType ty
509       vexpr      <- vectExpr scrut
510       (vbndr, (vbndrs, (vect_body, lift_body)))
511          <- vect_scrut_bndr
512           . vectBndrsIn bndrs
513           $ vectExpr body
514       let (vect_bndrs, lift_bndrs) = unzip vbndrs
515       (vscrut, lscrut, pdata_tc, _arg_tys) <- mkVScrut (vVar vbndr)
516       vect_dc <- maybeV (lookupDataCon dc)
517       let [pdata_dc] = tyConDataCons pdata_tc
518
519       let vcase = mk_wild_case vscrut vty vect_dc  vect_bndrs vect_body
520           lcase = mk_wild_case lscrut lty pdata_dc lift_bndrs lift_body
521
522       return $ vLet (vNonRec vbndr vexpr) (vcase, lcase)
523   where
524     vect_scrut_bndr | isDeadBinder bndr = vectBndrNewIn bndr (fsLit "scrut")
525                     | otherwise         = vectBndrIn bndr
526
527     mk_wild_case expr ty dc bndrs body
528       = mkWildCase expr (exprType expr) ty [(DataAlt dc, bndrs, body)]
529
530 vectAlgCase tycon _ty_args scrut bndr ty alts
531   = do
532       vect_tc     <- maybeV (lookupTyCon tycon)
533       (vty, lty)  <- vectAndLiftType ty
534
535       let arity = length (tyConDataCons vect_tc)
536       sel_ty <- builtin (selTy arity)
537       sel_bndr <- newLocalVar (fsLit "sel") sel_ty
538       let sel = Var sel_bndr
539
540       (vbndr, valts) <- vect_scrut_bndr
541                       $ mapM (proc_alt arity sel vty lty) alts'
542       let (vect_dcs, vect_bndrss, lift_bndrss, vbodies) = unzip4 valts
543
544       vexpr <- vectExpr scrut
545       (vect_scrut, lift_scrut, pdata_tc, _arg_tys) <- mkVScrut (vVar vbndr)
546       let [pdata_dc] = tyConDataCons pdata_tc
547
548       let (vect_bodies, lift_bodies) = unzip vbodies
549
550       vdummy <- newDummyVar (exprType vect_scrut)
551       ldummy <- newDummyVar (exprType lift_scrut)
552       let vect_case = Case vect_scrut vdummy vty
553                            (zipWith3 mk_vect_alt vect_dcs vect_bndrss vect_bodies)
554
555       lc <- builtin liftingContext
556       lbody <- combinePD vty (Var lc) sel lift_bodies
557       let lift_case = Case lift_scrut ldummy lty
558                            [(DataAlt pdata_dc, sel_bndr : concat lift_bndrss,
559                              lbody)]
560
561       return . vLet (vNonRec vbndr vexpr)
562              $ (vect_case, lift_case)
563   where
564     vect_scrut_bndr | isDeadBinder bndr = vectBndrNewIn bndr (fsLit "scrut")
565                     | otherwise         = vectBndrIn bndr
566
567     alts' = sortBy (\(alt1, _, _) (alt2, _, _) -> cmp alt1 alt2) alts
568
569     cmp (DataAlt dc1) (DataAlt dc2) = dataConTag dc1 `compare` dataConTag dc2
570     cmp DEFAULT       DEFAULT       = EQ
571     cmp DEFAULT       _             = LT
572     cmp _             DEFAULT       = GT
573     cmp _             _             = panic "vectAlgCase/cmp"
574
575     proc_alt arity sel _ lty (DataAlt dc, bndrs, body)
576       = do
577           vect_dc <- maybeV (lookupDataCon dc)
578           let ntag = dataConTagZ vect_dc
579               tag  = mkDataConTag vect_dc
580               fvs  = freeVarsOf body `delVarSetList` bndrs
581
582           sel_tags  <- liftM (`App` sel) (builtin (selTags arity))
583           lc        <- builtin liftingContext
584           elems     <- builtin (selElements arity ntag)
585
586           (vbndrs, vbody)
587             <- vectBndrsIn bndrs
588              . localV
589              $ do
590                  binds    <- mapM (pack_var (Var lc) sel_tags tag)
591                            . filter isLocalId
592                            $ varSetElems fvs
593                  (ve, le) <- vectExpr body
594                  return (ve, Case (elems `App` sel) lc lty
595                              [(DEFAULT, [], (mkLets (concat binds) le))])
596                  -- empty    <- emptyPD vty
597                  -- return (ve, Case (elems `App` sel) lc lty
598                  --             [(DEFAULT, [], Let (NonRec flags_var flags_expr)
599                  --                             $ mkLets (concat binds) le),
600                  --               (LitAlt (mkMachInt 0), [], empty)])
601           let (vect_bndrs, lift_bndrs) = unzip vbndrs
602           return (vect_dc, vect_bndrs, lift_bndrs, vbody)
603
604     proc_alt _ _ _ _ _ = panic "vectAlgCase/proc_alt"
605
606     mk_vect_alt vect_dc bndrs body = (DataAlt vect_dc, bndrs, body)
607
608     pack_var len tags t v
609       = do
610           r <- lookupVar v
611           case r of
612             Local (vv, lv) ->
613               do
614                 lv'  <- cloneVar lv
615                 expr <- packByTagPD (idType vv) (Var lv) len tags t
616                 updLEnv (\env -> env { local_vars = extendVarEnv
617                                                 (local_vars env) v (vv, lv') })
618                 return [(NonRec lv' expr)]
619
620             _ -> return []
621