- funnyParallelOp SeqOp = True
- funnyParallelOp ParOp = True
- funnyParallelOp ForkOp = True
- funnyParallelOp _ = False
-
- discrim_ty = coreExprType discrim
-
- alts_to_stg (PrimAlts _ (BindDefault binder rhs))
- = coreExprToStg env rhs `thenUs` \ (stg_rhs, rhs_binds) ->
- let
- stg_deflt = StgBindDefault binder False stg_rhs
- in
- returnUs (StgPrimAlts discrim_ty [] stg_deflt, rhs_binds)
-
--- OK, back to real life...
-
-coreExprToStg env (Case discrim alts)
- = coreExprToStg env discrim `thenUs` \ (stg_discrim, discrim_binds) ->
- alts_to_stg discrim alts `thenUs` \ (stg_alts, alts_binds) ->
- getUnique `thenUs` \ uniq ->
- returnUs (
- StgCase stg_discrim
- bOGUS_LVs
- bOGUS_LVs
- uniq
- stg_alts,
- discrim_binds `unionBags` alts_binds
- )
- where
- discrim_ty = coreExprType discrim
- (_, discrim_ty_args, _) = getAppDataTyConExpandingDicts discrim_ty
-
- alts_to_stg discrim (AlgAlts alts deflt)
- = default_to_stg discrim deflt `thenUs` \ (stg_deflt, deflt_binds) ->
- mapAndUnzipUs boxed_alt_to_stg alts `thenUs` \ (stg_alts, alts_binds) ->
- returnUs (StgAlgAlts discrim_ty stg_alts stg_deflt,
- deflt_binds `unionBags` unionManyBags alts_binds)
- where
- boxed_alt_to_stg (con, bs, rhs)
- = coreExprToStg env rhs `thenUs` \ (stg_rhs, rhs_binds) ->
- returnUs ((spec_con, bs, [ True | b <- bs ]{-bogus use mask-}, stg_rhs),
- rhs_binds)
- where
- spec_con = mkSpecialisedCon con discrim_ty_args
-
- alts_to_stg discrim (PrimAlts alts deflt)
- = default_to_stg discrim deflt `thenUs` \ (stg_deflt,deflt_binds) ->
- mapAndUnzipUs unboxed_alt_to_stg alts `thenUs` \ (stg_alts, alts_binds) ->
- returnUs (StgPrimAlts discrim_ty stg_alts stg_deflt,
- deflt_binds `unionBags` unionManyBags alts_binds)
- where
- unboxed_alt_to_stg (lit, rhs)
- = coreExprToStg env rhs `thenUs` \ (stg_rhs, rhs_binds) ->
- returnUs ((lit, stg_rhs), rhs_binds)
-
- default_to_stg discrim NoDefault
- = returnUs (StgNoDefault, emptyBag)
-
- default_to_stg discrim (BindDefault binder rhs)
- = coreExprToStg new_env rhs `thenUs` \ (stg_rhs, rhs_binds) ->
- returnUs (StgBindDefault binder True{-used? no it is lying-} stg_rhs,
- rhs_binds)
- where
- --
- -- We convert case x of {...; x' -> ...x'...}
- -- to
- -- case x of {...; _ -> ...x... }
- --
- -- See notes in SimplCase.lhs, near simplDefault for the reasoning.
- -- It's quite easily done: simply extend the environment to bind the
- -- default binder to the scrutinee.
- --
- new_env = case discrim of
- Var v -> addOneToIdEnv env binder (stgLookup env v)
- other -> env