VectUtils.hs 15 KB
Newer Older
1
module VectUtils (
2
  collectAnnTypeBinders, collectAnnTypeArgs, isAnnTypeArg,
3
  collectAnnValBinders,
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
4
5
6
  dataConTagZ, mkDataConTag, mkDataConTagLit,

  newLocalVVar,
7

8
  mkBuiltinCo,
9
  mkPADictType, mkPArrayType, mkPReprType,
10

11
12
  parrayReprTyCon, parrayReprDataCon, mkVScrut,
  prDFunOfTyCon,
13
  paDictArgType, paDictOfType, paDFunType,
14
  paMethod, mkPR, lengthPA, replicatePA, emptyPA, packPA, combinePA, liftPA,
15
  zipScalars, scalarClosure,
16
  polyAbstract, polyApply, polyVApply,
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
17
  hoistBinding, hoistExpr, hoistPolyVExpr, takeHoisted,
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
18
19
  buildClosure, buildClosures,
  mkClosureApp
20
21
) where

22
import VectCore
23
24
import VectMonad

25
import MkCore
26
import CoreSyn
27
import CoreUtils
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
28
import Coercion
29
30
import Type
import TypeRep
31
import TyCon
32
import DataCon
33
import Var
34
35
36
import MkId               ( unwrapFamInstScrut )
import TysWiredIn
import BasicTypes         ( Boxity(..) )
37
import Literal            ( Literal, mkMachInt )
38

39
import Outputable
40
import FastString
41

twanvl's avatar
twanvl committed
42
43
import Control.Monad

44

45
46
47
48
49
50
51
52
53
54
55
56
collectAnnTypeArgs :: AnnExpr b ann -> (AnnExpr b ann, [Type])
collectAnnTypeArgs expr = go expr []
  where
    go (_, AnnApp f (_, AnnType ty)) tys = go f (ty : tys)
    go e                             tys = (e, tys)

collectAnnTypeBinders :: AnnExpr Var ann -> ([Var], AnnExpr Var ann)
collectAnnTypeBinders expr = go [] expr
  where
    go bs (_, AnnLam b e) | isTyVar b = go (b:bs) e
    go bs e                           = (reverse bs, e)

57
58
59
collectAnnValBinders :: AnnExpr Var ann -> ([Var], AnnExpr Var ann)
collectAnnValBinders expr = go [] expr
  where
60
61
    go bs (_, AnnLam b e) | isId b = go (b:bs) e
    go bs e                        = (reverse bs, e)
62

63
isAnnTypeArg :: AnnExpr b ann -> Bool
twanvl's avatar
twanvl committed
64
isAnnTypeArg (_, AnnType _) = True
65
66
isAnnTypeArg _              = False

rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
67
68
69
dataConTagZ :: DataCon -> Int
dataConTagZ con = dataConTag con - fIRST_TAG

70
mkDataConTagLit :: DataCon -> Literal
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
71
mkDataConTagLit = mkMachInt . toInteger . dataConTagZ
72

73
mkDataConTag :: DataCon -> CoreExpr
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
74
mkDataConTag = mkIntLitInt . dataConTagZ
75

76
77
78
79
80
81
82
83
splitPrimTyCon :: Type -> Maybe TyCon
splitPrimTyCon ty
  | Just (tycon, []) <- splitTyConApp_maybe ty
  , isPrimTyCon tycon
  = Just tycon

  | otherwise = Nothing

rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
84
85
mkBuiltinTyConApp :: (Builtins -> TyCon) -> [Type] -> VM Type
mkBuiltinTyConApp get_tc tys
86
  = do
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
87
88
      tc <- builtin get_tc
      return $ mkTyConApp tc tys
89

rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
90
91
mkBuiltinTyConApps :: (Builtins -> TyCon) -> [Type] -> Type -> VM Type
mkBuiltinTyConApps get_tc tys ty
92
  = do
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
93
94
      tc <- builtin get_tc
      return $ foldr (mk tc) ty tys
95
  where
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
96
    mk tc ty1 ty2 = mkTyConApp tc [ty1,ty2]
97

twanvl's avatar
twanvl committed
98
{-
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
99
mkBuiltinTyConApps1 :: (Builtins -> TyCon) -> Type -> [Type] -> VM Type
twanvl's avatar
twanvl committed
100
101
mkBuiltinTyConApps1 _      dft [] = return dft
mkBuiltinTyConApps1 get_tc _   tys
102
  = do
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
103
104
105
106
107
108
109
110
111
      tc <- builtin get_tc
      case tys of
        [] -> pprPanic "mkBuiltinTyConApps1" (ppr tc)
        _  -> return $ foldr1 (mk tc) tys
  where
    mk tc ty1 ty2 = mkTyConApp tc [ty1,ty2]

mkClosureType :: Type -> Type -> VM Type
mkClosureType arg_ty res_ty = mkBuiltinTyConApp closureTyCon [arg_ty, res_ty]
twanvl's avatar
twanvl committed
112
-}
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
113
114
115
116

mkClosureTypes :: [Type] -> Type -> VM Type
mkClosureTypes = mkBuiltinTyConApps closureTyCon

117
118
119
mkPReprType :: Type -> VM Type
mkPReprType ty = mkBuiltinTyConApp preprTyCon [ty]

rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
120
121
mkPADictType :: Type -> VM Type
mkPADictType ty = mkBuiltinTyConApp paTyCon [ty]
122
123

mkPArrayType :: Type -> VM Type
124
125
126
mkPArrayType ty
  | Just tycon <- splitPrimTyCon ty
  = do
127
128
129
130
      r <- lookupPrimPArray tycon
      case r of
        Just arr -> return $ mkTyConApp arr []
        Nothing  -> cantVectorise "Primitive tycon not vectorised" (ppr tycon)
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
131
mkPArrayType ty = mkBuiltinTyConApp parrayTyCon [ty]
132

133
134
mkBuiltinCo :: (Builtins -> TyCon) -> VM Coercion
mkBuiltinCo get_tc
135
  = do
136
137
      tc <- builtin get_tc
      return $ mkTyConApp tc []
138

139
140
141
142
143
144
145
146
147
148
parrayReprTyCon :: Type -> VM (TyCon, [Type])
parrayReprTyCon ty = builtin parrayTyCon >>= (`lookupFamInst` [ty])

parrayReprDataCon :: Type -> VM (DataCon, [Type])
parrayReprDataCon ty
  = do
      (tc, arg_tys) <- parrayReprTyCon ty
      let [dc] = tyConDataCons tc
      return (dc, arg_tys)

149
150
151
152
153
154
mkVScrut :: VExpr -> VM (VExpr, TyCon, [Type])
mkVScrut (ve, le)
  = do
      (tc, arg_tys) <- parrayReprTyCon (exprType ve)
      return ((ve, unwrapFamInstScrut tc arg_tys le), tc, arg_tys)

155
156
prDFunOfTyCon :: TyCon -> VM CoreExpr
prDFunOfTyCon tycon
157
158
159
  = liftM Var
  . maybeCantVectoriseM "No PR dictionary for tycon" (ppr tycon)
  $ lookupTyConPR tycon
160

161
162
163
164
165
166
paDictArgType :: TyVar -> VM (Maybe Type)
paDictArgType tv = go (TyVarTy tv) (tyVarKind tv)
  where
    go ty k | Just k' <- kindView k = go ty k'
    go ty (FunTy k1 k2)
      = do
Ian Lynagh's avatar
Ian Lynagh committed
167
          tv   <- newTyVar (fsLit "a") k1
168
169
170
171
172
173
174
175
176
          mty1 <- go (TyVarTy tv) k1
          case mty1 of
            Just ty1 -> do
                          mty2 <- go (AppTy ty (TyVarTy tv)) k2
                          return $ fmap (ForAllTy tv . FunTy ty1) mty2
            Nothing  -> go ty k2

    go ty k
      | isLiftedTypeKind k
177
      = liftM Just (mkPADictType ty)
178

twanvl's avatar
twanvl committed
179
    go _ _ = return Nothing
180

181
182
183
184
185
186
187
188
189
190
191
192
193
194
paDictOfType :: Type -> VM CoreExpr
paDictOfType ty = paDictOfTyApp ty_fn ty_args
  where
    (ty_fn, ty_args) = splitAppTys ty

paDictOfTyApp :: Type -> [Type] -> VM CoreExpr
paDictOfTyApp ty_fn ty_args
  | Just ty_fn' <- coreView ty_fn = paDictOfTyApp ty_fn' ty_args
paDictOfTyApp (TyVarTy tv) ty_args
  = do
      dfun <- maybeV (lookupTyVarPA tv)
      paDFunApply dfun ty_args
paDictOfTyApp (TyConApp tc _) ty_args
  = do
195
196
      dfun <- maybeCantVectoriseM "No PA dictionary for tycon" (ppr tc)
            $ lookupTyConPA tc
197
      paDFunApply (Var dfun) ty_args
198
199
paDictOfTyApp ty _
  = cantVectorise "Can't construct PA dictionary for type" (ppr ty)
200

201
202
203
204
205
206
207
208
209
210
211
paDFunType :: TyCon -> VM Type
paDFunType tc
  = do
      margs <- mapM paDictArgType tvs
      res   <- mkPADictType (mkTyConApp tc arg_tys)
      return . mkForAllTys tvs
             $ mkFunTys [arg | Just arg <- margs] res
  where
    tvs = tyConTyVars tc
    arg_tys = mkTyVarTys tvs

212
213
214
215
216
217
paDFunApply :: CoreExpr -> [Type] -> VM CoreExpr
paDFunApply dfun tys
  = do
      dicts <- mapM paDictOfType tys
      return $ mkApps (mkTyApps dfun tys) dicts

218
219
type PAMethod = (Builtins -> Var, String)

twanvl's avatar
twanvl committed
220
pa_length, pa_replicate, pa_empty, pa_pack :: (Builtins -> Var, String)
221
222
223
pa_length    = (lengthPAVar,    "lengthPA")
pa_replicate = (replicatePAVar, "replicatePA")
pa_empty     = (emptyPAVar,     "emptyPA")
224
pa_pack      = (packPAVar,      "packPA")
225
226

paMethod :: PAMethod -> Type -> VM CoreExpr
twanvl's avatar
twanvl committed
227
paMethod (_method, name) ty
228
  | Just tycon <- splitPrimTyCon ty
229
230
231
  = liftM Var
  . maybeCantVectoriseM "No PA method" (text name <+> text "for" <+> ppr tycon)
  $ lookupPrimMethod tycon name
232

twanvl's avatar
twanvl committed
233
paMethod (method, _name) ty
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
234
235
236
237
238
  = do
      fn   <- builtin method
      dict <- paDictOfType ty
      return $ mkApps (Var fn) [Type ty, dict]

239
mkPR :: Type -> VM CoreExpr
240
241
242
243
244
mkPR ty
  = do
      fn   <- builtin mkPRVar
      dict <- paDictOfType ty
      return $ mkApps (Var fn) [Type ty, dict]
245

246
247
lengthPA :: Type -> CoreExpr -> VM CoreExpr
lengthPA ty x = liftM (`App` x) (paMethod pa_length ty)
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
248
249
250

replicatePA :: CoreExpr -> CoreExpr -> VM CoreExpr
replicatePA len x = liftM (`mkApps` [len,x])
251
                          (paMethod pa_replicate (exprType x))
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
252

253
emptyPA :: Type -> VM CoreExpr
254
emptyPA = paMethod pa_empty
255

256
packPA :: Type -> CoreExpr -> CoreExpr -> CoreExpr -> VM CoreExpr
257
packPA ty xs len sel = liftM (`mkApps` [xs, len, sel])
258
259
                             (paMethod pa_pack ty)

260
261
262
263
264
265
266
267
combinePA :: Type -> CoreExpr -> CoreExpr -> CoreExpr -> [CoreExpr]
          -> VM CoreExpr
combinePA ty len sel is xs
  = liftM (`mkApps` (len : sel : is : xs))
          (paMethod (combinePAVar n, "combine" ++ show n ++ "PA") ty)
  where
    n = length xs

268
269
270
271
272
273
liftPA :: CoreExpr -> VM CoreExpr
liftPA x
  = do
      lc <- builtin liftingContext
      replicatePA (Var lc) x

274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
zipScalars :: [Type] -> Type -> VM CoreExpr
zipScalars arg_tys res_ty
  = do
      scalar <- builtin scalarClass
      (dfuns, _) <- mapAndUnzipM (\ty -> lookupInst scalar [ty]) ty_args
      zipf <- builtin (scalarZip $ length arg_tys)
      return $ Var zipf `mkTyApps` ty_args `mkApps` map Var dfuns
    where
      ty_args = arg_tys ++ [res_ty]

scalarClosure :: [Type] -> Type -> CoreExpr -> CoreExpr -> VM CoreExpr
scalarClosure arg_tys res_ty scalar_fun array_fun
  = do
      ctr <- builtin (closureCtrFun $ length arg_tys)
      pas <- mapM paDictOfType (init arg_tys)
      return $ Var ctr `mkTyApps` (arg_tys ++ [res_ty])
                       `mkApps`   (pas ++ [scalar_fun, array_fun])

292
293
294
295
296
297
298
299
newLocalVVar :: FastString -> Type -> VM VVar
newLocalVVar fs vty
  = do
      lty <- mkPArrayType vty
      vv  <- newLocalVar fs vty
      lv  <- newLocalVar fs lty
      return (vv,lv)

rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
300
301
302
303
polyAbstract :: [TyVar] -> ((CoreExpr -> CoreExpr) -> VM a) -> VM a
polyAbstract tvs p
  = localV
  $ do
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
304
305
306
307
308
309
310
      mdicts <- mapM mk_dict_var tvs
      zipWithM_ (\tv -> maybe (defLocalTyVar tv) (defLocalTyVarWithPA tv . Var)) tvs mdicts
      p (mk_lams mdicts)
  where
    mk_dict_var tv = do
                       r <- paDictArgType tv
                       case r of
Ian Lynagh's avatar
Ian Lynagh committed
311
                         Just ty -> liftM Just (newLocalVar (fsLit "dPA") ty)
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
312
313
314
315
                         Nothing -> return Nothing

    mk_lams mdicts = mkLams (tvs ++ [dict | Just dict <- mdicts])

rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
316
317
polyApply :: CoreExpr -> [Type] -> VM CoreExpr
polyApply expr tys
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
318
319
320
321
  = do
      dicts <- mapM paDictOfType tys
      return $ expr `mkTyApps` tys `mkApps` dicts

322
323
324
325
326
327
polyVApply :: VExpr -> [Type] -> VM VExpr
polyVApply expr tys
  = do
      dicts <- mapM paDictOfType tys
      return $ mapVect (\e -> e `mkTyApps` tys `mkApps` dicts) expr

rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
328
329
330
331
hoistBinding :: Var -> CoreExpr -> VM ()
hoistBinding v e = updGEnv $ \env ->
  env { global_bindings = (v,e) : global_bindings env }

332
333
334
335
hoistExpr :: FastString -> CoreExpr -> VM Var
hoistExpr fs expr
  = do
      var <- newLocalVar fs (exprType expr)
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
336
      hoistBinding var expr
337
338
      return var

339
340
hoistVExpr :: VExpr -> VM VVar
hoistVExpr (ve, le)
341
  = do
342
      fs <- getBindName
343
344
345
      vv <- hoistExpr ('v' `consFS` fs) ve
      lv <- hoistExpr ('l' `consFS` fs) le
      return (vv, lv)
346

347
348
hoistPolyVExpr :: [TyVar] -> VM VExpr -> VM VExpr
hoistPolyVExpr tvs p
349
  = do
350
351
      expr <- closedV . polyAbstract tvs $ \abstract ->
              liftM (mapVect abstract) p
352
      fn   <- hoistVExpr expr
353
      polyVApply (vVar fn) (mkTyVarTys tvs)
354

355
356
357
358
359
360
361
takeHoisted :: VM [(Var, CoreExpr)]
takeHoisted
  = do
      env <- readGEnv id
      setGEnv $ env { global_bindings = [] }
      return $ global_bindings env

twanvl's avatar
twanvl committed
362
{-
363
364
365
366
367
368
369
370
371
372
373
boxExpr :: Type -> VExpr -> VM VExpr
boxExpr ty (vexpr, lexpr)
  | Just (tycon, []) <- splitTyConApp_maybe ty
  , isUnLiftedTyCon tycon
  = do
      r <- lookupBoxedTyCon tycon
      case r of
        Just tycon' -> let [dc] = tyConDataCons tycon'
                       in
                       return (mkConApp dc [vexpr], lexpr)
        Nothing     -> return (vexpr, lexpr)
twanvl's avatar
twanvl committed
374
-}
375

376
377
mkClosure :: Type -> Type -> Type -> VExpr -> VExpr -> VM VExpr
mkClosure arg_ty res_ty env_ty (vfn,lfn) (venv,lenv)
378
  = do
379
380
381
382
383
      dict <- paDictOfType env_ty
      mkv  <- builtin mkClosureVar
      mkl  <- builtin mkClosurePVar
      return (Var mkv `mkTyApps` [arg_ty, res_ty, env_ty] `mkApps` [dict, vfn, lfn, venv],
              Var mkl `mkTyApps` [arg_ty, res_ty, env_ty] `mkApps` [dict, vfn, lfn, lenv])
384

385
386
mkClosureApp :: Type -> Type -> VExpr -> VExpr -> VM VExpr
mkClosureApp arg_ty res_ty (vclo, lclo) (varg, larg)
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
387
388
389
390
391
392
  = do
      vapply <- builtin applyClosureVar
      lapply <- builtin applyClosurePVar
      return (Var vapply `mkTyApps` [arg_ty, res_ty] `mkApps` [vclo, varg],
              Var lapply `mkTyApps` [arg_ty, res_ty] `mkApps` [lclo, larg])

393
buildClosures :: [TyVar] -> [VVar] -> [Type] -> Type -> VM VExpr -> VM VExpr
twanvl's avatar
twanvl committed
394
buildClosures _   _    [] _ mk_body
395
  = mk_body
396
buildClosures tvs vars [arg_ty] res_ty mk_body
397
  = liftM vInlineMe (buildClosure tvs vars arg_ty res_ty mk_body)
398
buildClosures tvs vars (arg_ty : arg_tys) res_ty mk_body
399
400
  = do
      res_ty' <- mkClosureTypes arg_tys res_ty
Ian Lynagh's avatar
Ian Lynagh committed
401
      arg <- newLocalVVar (fsLit "x") arg_ty
402
403
      liftM vInlineMe
        . buildClosure tvs vars arg_ty res_ty'
404
        . hoistPolyVExpr tvs
405
        $ do
406
407
            lc <- builtin liftingContext
            clo <- buildClosures tvs (vars ++ [arg]) arg_tys res_ty mk_body
408
409
            return $ vLams lc (vars ++ [arg]) clo

410
411
412
413
-- (clo <x1,...,xn> <f,f^>, aclo (Arr lc xs1 ... xsn) <f,f^>)
--   where
--     f  = \env v -> case env of <x1,...,xn> -> e x1 ... xn v
--     f^ = \env v -> case env of Arr l xs1 ... xsn -> e^ l x1 ... xn v
414
--
415
416
buildClosure :: [TyVar] -> [VVar] -> Type -> Type -> VM VExpr -> VM VExpr
buildClosure tvs vars arg_ty res_ty mk_body
417
  = do
418
      (env_ty, env, bind) <- buildEnv vars
Ian Lynagh's avatar
Ian Lynagh committed
419
420
      env_bndr <- newLocalVVar (fsLit "env") env_ty
      arg_bndr <- newLocalVVar (fsLit "arg") arg_ty
421

422
      fn <- hoistPolyVExpr tvs
423
          $ do
424
              lc    <- builtin liftingContext
425
426
              body  <- mk_body
              body' <- bind (vVar env_bndr)
427
                            (vVarApps lc body (vars ++ [arg_bndr]))
428
              return . vInlineMe $ vLamsWithoutLC [env_bndr, arg_bndr] body'
429

430
      mkClosure arg_ty res_ty env_ty fn env
431

432
433
buildEnv :: [VVar] -> VM (Type, VExpr, VExpr -> VExpr -> VM VExpr)
buildEnv vvs
434
  = do
435
      lc <- builtin liftingContext
436
      let (ty, venv, vbind) = mkVectEnv tys vs
437
      (lenv, lbind) <- mkLiftEnv lc tys ls
438
      return (ty, (venv, lenv),
439
440
441
442
443
              \(venv,lenv) (vbody,lbody) ->
              do
                let vbody' = vbind venv vbody
                lbody' <- lbind lenv lbody
                return (vbody', lbody'))
444
  where
445
    (vs,ls) = unzip vvs
446
    tys     = map varType vs
447
448

mkVectEnv :: [Type] -> [Var] -> (Type, CoreExpr, CoreExpr -> CoreExpr -> CoreExpr)
twanvl's avatar
twanvl committed
449
mkVectEnv []   []  = (unitTy, Var unitDataConId, \_ body -> body)
450
451
mkVectEnv [ty] [v] = (ty, Var v, \env body -> Let (NonRec v env) body)
mkVectEnv tys  vs  = (ty, mkCoreTup (map Var vs),
452
                        \env body -> mkWildCase env ty (exprType body)
453
454
455
456
                                       [(DataAlt (tupleCon Boxed (length vs)), vs, body)])
  where
    ty = mkCoreTupTy tys

457
mkLiftEnv :: Var -> [Type] -> [Var] -> VM (CoreExpr, CoreExpr -> CoreExpr -> VM CoreExpr)
458
mkLiftEnv lc [ty] [v]
459
460
  = return (Var v, \env body ->
                   do
461
                     len <- lengthPA ty (Var v)
462
                     return . Let (NonRec v env)
463
                            $ Case len lc (exprType body) [(DEFAULT, [], body)])
464
465

-- NOTE: this transparently deals with empty environments
466
mkLiftEnv lc tys vs
467
  = do
468
      (env_tc, env_tyargs) <- parrayReprTyCon vty
rl@cse.unsw.edu.au's avatar
rl@cse.unsw.edu.au committed
469
470
471
472
473

      bndrs <- if null vs then do
                                 v <- newDummyVar unitTy
                                 return [v]
                          else return vs
474
475
476
      let [env_con] = tyConDataCons env_tc
          
          env = Var (dataConWrapId env_con)
477
                `mkTyApps`  env_tyargs
478
                `mkApps`    (Var lc : args)
479

480
481
          bind env body = let scrut = unwrapFamInstScrut env_tc env_tyargs env
                          in
482
                          return $ mkWildCase scrut (exprType scrut)
483
                                        (exprType body)
484
                                        [(DataAlt env_con, lc : bndrs, body)]
485
486
487
488
      return (env, bind)
  where
    vty = mkCoreTupTy tys

489
490
491
    args  | null vs   = [Var unitDataConId]
          | otherwise = map Var vs