This module exports some utility functions of no great interest.
\begin{code}
-#include "HsVersions.h"
-
module DsUtils (
CanItFail(..), EquationInfo(..), MatchResult(..),
+ EqnNo, EqnSet,
combineGRHSMatchResults,
combineMatchResults,
- dsExprToAtom,
+ dsExprToAtomGivenTy, DsCoreArg,
mkCoAlgCaseMatchResult,
- mkAppDs, mkConDs, mkPrimDs,
+ mkAppDs, mkConDs, mkPrimDs, mkErrorAppDs,
mkCoLetsMatchResult,
mkCoPrimCaseMatchResult,
mkFailurePair,
mkSelectorBinds,
mkTupleBind,
mkTupleExpr,
- selectMatchVars
+ mkTupleSelector,
+ selectMatchVars,
+ showForErr
) where
-import Ubiq
-import DsLoop ( match, matchSimply )
+#include "HsVersions.h"
+
+import {-# SOURCE #-} Match (match, matchSimply )
-import HsSyn ( HsExpr(..), OutPat(..), HsLit(..),
- Match, HsBinds, Stmt, Qual, PolyType, ArithSeqInfo )
-import TcHsSyn ( TypecheckedPat(..) )
-import DsHsSyn ( outPatType )
+import HsSyn ( HsExpr(..), OutPat(..), HsLit(..), Fixity,
+ Match, HsBinds, Stmt, DoOrListComp, HsType, ArithSeqInfo )
+import TcHsSyn ( TypecheckedPat )
+import DsHsSyn ( outPatType, collectTypedPatBinders )
import CoreSyn
import DsMonad
-import CoreUtils ( coreExprType, escErrorMsg, mkCoreIfThenElse, mkErrorApp )
-import PrelInfo ( stringTy )
-import Id ( idType, getInstantiatedDataConSig, mkTupleCon,
- DataCon(..), DictVar(..), Id(..), GenId )
-import TyCon ( mkTupleTyCon )
-import Type ( mkTyVarTys, mkRhoTy, mkFunTys, isUnboxedType,
- applyTyCon, getAppDataTyCon
+import CoreUtils ( coreExprType, mkCoreIfThenElse )
+import PrelVals ( iRREFUT_PAT_ERROR_ID, voidId )
+import Id ( idType, dataConArgTys,
+ DataCon, DictVar, Id, GenId )
+import Literal ( Literal(..) )
+import PrimOp ( PrimOp )
+import TyCon ( isNewTyCon, tyConDataCons )
+import Type ( mkTyVarTys, mkRhoTy, mkForAllTys, mkFunTy,
+ isUnpointedType, mkTyConApp, splitAlgTyConApp,
+ Type
)
-import UniqSet ( mkUniqSet, minusUniqSet, uniqSetToList, UniqSet(..) )
-import Util ( panic, assertPanic )
+import BasicTypes ( Unused )
+import TysPrim ( voidTy )
+import TysWiredIn ( tupleTyCon, unitDataCon, tupleCon )
+import UniqSet ( mkUniqSet, minusUniqSet, uniqSetToList, UniqSet )
+import Unique ( Unique )
+import Outputable
+\end{code}
+
-quantifyTy = panic "DsUtils.quantifyTy"
-splitDictType = panic "DsUtils.splitDictType"
-mkCoTyApps = panic "DsUtils.mkCoTyApps"
+%************************************************************************
+%* *
+%* Selecting match variables
+%* *
+%************************************************************************
+
+We're about to match against some patterns. We want to make some
+@Ids@ to use as match variables. If a pattern has an @Id@ readily at
+hand, which should indeed be bound to the pattern as a whole, then use it;
+otherwise, make one up.
+
+\begin{code}
+selectMatchVars :: [TypecheckedPat] -> DsM [Id]
+selectMatchVars pats
+ = mapDs var_from_pat_maybe pats
+ where
+ var_from_pat_maybe (VarPat var) = returnDs var
+ var_from_pat_maybe (AsPat var pat) = returnDs var
+ var_from_pat_maybe (LazyPat pat) = var_from_pat_maybe pat
+ var_from_pat_maybe other_pat
+ = newSysLocalDs (outPatType other_pat) -- OK, better make up one...
\end{code}
+
%************************************************************************
%* *
%* type synonym EquationInfo and access functions for its pieces *
worthy of a type synonym and a few handy functions.
\begin{code}
+
+type EqnNo = Int
+type EqnSet = UniqSet EqnNo
+
data EquationInfo
= EqnInfo
+ EqnNo -- The number of the equation
+ DsMatchContext -- The context info is used when producing warnings
+ -- about shadowed patterns. It's the context
+ -- of the *first* thing matched in this group.
+ -- Should perhaps be a list of them all!
[TypecheckedPat] -- the patterns for an eqn
MatchResult -- Encapsulates the guards and bindings
\end{code}
-- failure point(s). The expression should
-- be duplicatable!
- DsMatchContext -- The context info is used when producing warnings
- -- about shadowed patterns. It's the context
- -- of the *first* thing matched in this group.
- -- Should perhaps be a list of them all!
-
data CanItFail = CanFail | CantFail
orFail CantFail CantFail = CantFail
mkCoLetsMatchResult :: [CoreBinding] -> MatchResult -> MatchResult
-mkCoLetsMatchResult binds (MatchResult can_it_fail ty body_fn cxt)
- = MatchResult can_it_fail ty (\body -> mkCoLetsAny binds (body_fn body)) cxt
+mkCoLetsMatchResult binds (MatchResult can_it_fail ty body_fn)
+ = MatchResult can_it_fail ty (\body -> mkCoLetsAny binds (body_fn body))
mkGuardedMatchResult :: CoreExpr -> MatchResult -> DsM MatchResult
-mkGuardedMatchResult pred_expr (MatchResult can_it_fail ty body_fn cxt)
+mkGuardedMatchResult pred_expr (MatchResult can_it_fail ty body_fn)
= returnDs (MatchResult CanFail
ty
(\fail -> mkCoreIfThenElse pred_expr (body_fn fail) fail)
- cxt
)
mkCoPrimCaseMatchResult :: Id -- Scrutinee
= newSysLocalDs (idType var) `thenDs` \ wild ->
returnDs (MatchResult CanFail
ty1
- (mk_case alts wild)
- cxt1)
+ (mk_case alts wild))
where
- ((_,MatchResult _ ty1 _ cxt1) : _) = alts
+ ((_,MatchResult _ ty1 _) : _) = alts
mk_case alts wild fail_expr
= Case (Var var) (PrimAlts final_alts (BindDefault wild fail_expr))
where
final_alts = [ (lit, body_fn fail_expr)
- | (lit, MatchResult _ _ body_fn _) <- alts
+ | (lit, MatchResult _ _ body_fn) <- alts
]
mkCoAlgCaseMatchResult :: Id -- Scrutinee
-> [(DataCon, [Id], MatchResult)] -- Alternatives
-> DsM MatchResult
+
mkCoAlgCaseMatchResult var alts
+ | isNewTyCon tycon -- newtype case; use a let
+ = ASSERT( newtype_sanity )
+ returnDs (mkCoLetsMatchResult [coercion_bind] match_result)
+
+ | otherwise -- datatype case
= -- Find all the constructors in the type which aren't
-- explicitly mentioned in the alternatives:
case un_mentioned_constructors of
[] -> -- All constructors mentioned, so no default needed
returnDs (MatchResult can_any_alt_fail
ty1
- (mk_case alts (\ignore -> NoDefault))
- cxt1)
+ (mk_case alts (\ignore -> NoDefault)))
[con] -> -- Just one constructor missing, so add a case for it
-- We need to build new locals for the args of the constructor,
-- and figuring out their types is somewhat tiresome.
let
- (_,arg_tys,_) = getInstantiatedDataConSig con tycon_arg_tys
+ arg_tys = dataConArgTys con tycon_arg_tys
in
newSysLocalsDs arg_tys `thenDs` \ arg_ids ->
-- Now we are ready to construct the new alternative
let
- new_alt = (con, arg_ids, MatchResult CanFail ty1 id NoMatchContext)
+ new_alt = (con, arg_ids, MatchResult CanFail ty1 id)
in
returnDs (MatchResult CanFail
ty1
- (mk_case (new_alt:alts) (\ignore -> NoDefault))
- cxt1)
+ (mk_case (new_alt:alts) (\ignore -> NoDefault)))
other -> -- Many constructors missing, so use a default case
newSysLocalDs scrut_ty `thenDs` \ wild ->
returnDs (MatchResult CanFail
ty1
- (mk_case alts (\fail_expr -> BindDefault wild fail_expr))
- cxt1)
+ (mk_case alts (\fail_expr -> BindDefault wild fail_expr)))
where
+ -- Common stuff
scrut_ty = idType var
- (tycon, tycon_arg_tys, data_cons) = getAppDataTyCon scrut_ty
+ (tycon, tycon_arg_tys, _) = splitAlgTyConApp scrut_ty
+
+ -- Stuff for newtype
+ (con_id, arg_ids, match_result) = head alts
+ arg_id = head arg_ids
+ coercion_bind = NonRec arg_id (Coerce (CoerceOut con_id)
+ (idType arg_id)
+ (Var var))
+ newtype_sanity = null (tail alts) && null (tail arg_ids)
+
+ -- Stuff for data types
+ data_cons = tyConDataCons tycon
un_mentioned_constructors
= uniqSetToList (mkUniqSet data_cons `minusUniqSet` mkUniqSet [ con | (con, _, _) <- alts] )
match_results = [match_result | (_,_,match_result) <- alts]
- (MatchResult _ ty1 _ cxt1 : _) = match_results
- can_any_alt_fail = foldr1 orFail [can_it_fail | MatchResult can_it_fail _ _ _ <- match_results]
+ (MatchResult _ ty1 _ : _) = match_results
+ can_any_alt_fail = foldr1 orFail [can_it_fail | MatchResult can_it_fail _ _ <- match_results]
mk_case alts deflt_fn fail_expr
= Case (Var var) (AlgAlts final_alts (deflt_fn fail_expr))
where
final_alts = [ (con, args, body_fn fail_expr)
- | (con, args, MatchResult _ _ body_fn _) <- alts
+ | (con, args, MatchResult _ _ body_fn) <- alts
]
combineMatchResults :: MatchResult -> MatchResult -> DsM MatchResult
-combineMatchResults (MatchResult CanFail ty1 body_fn1 cxt1)
- (MatchResult can_it_fail2 ty2 body_fn2 cxt2)
+combineMatchResults (MatchResult CanFail ty1 body_fn1)
+ (MatchResult can_it_fail2 ty2 body_fn2)
= mkFailurePair ty1 `thenDs` \ (bind_fn, duplicatable_expr) ->
let
new_body_fn1 = \body1 -> Let (bind_fn body1) (body_fn1 duplicatable_expr)
new_body_fn2 = \body2 -> new_body_fn1 (body_fn2 body2)
in
- returnDs (MatchResult can_it_fail2 ty1 new_body_fn2 cxt1)
+ returnDs (MatchResult can_it_fail2 ty1 new_body_fn2)
-combineMatchResults match_result1@(MatchResult CantFail ty body_fn1 cxt1)
+combineMatchResults match_result1@(MatchResult CantFail ty body_fn1)
match_result2
= returnDs match_result1
-- The difference in combineGRHSMatchResults is that there is no
-- need to let-bind to avoid code duplication
combineGRHSMatchResults :: MatchResult -> MatchResult -> DsM MatchResult
-combineGRHSMatchResults (MatchResult CanFail ty1 body_fn1 cxt1)
- (MatchResult can_it_fail ty2 body_fn2 cxt2)
- = returnDs (MatchResult can_it_fail ty1 (\ body -> body_fn1 (body_fn2 body)) cxt1)
+combineGRHSMatchResults (MatchResult CanFail ty1 body_fn1)
+ (MatchResult can_it_fail ty2 body_fn2)
+ = returnDs (MatchResult can_it_fail ty1 (\ body -> body_fn1 (body_fn2 body)))
combineGRHSMatchResults match_result1 match_result2
= -- Delegate to avoid duplication of code
%************************************************************************
\begin{code}
-dsExprToAtom :: CoreExpr -- The argument expression
+dsArgToAtom :: DsCoreArg -- The argument expression
-> (CoreArg -> DsM CoreExpr) -- Something taking the argument *atom*,
-- and delivering an expression E
-> DsM CoreExpr -- Either E or let x=arg-expr in E
-dsExprToAtom (Var v) continue_with = continue_with (VarArg v)
-dsExprToAtom (Lit v) continue_with = continue_with (LitArg v)
-
-dsExprToAtom arg_expr continue_with
- = let
- ty = coreExprType arg_expr
- in
- newSysLocalDs ty `thenDs` \ arg_id ->
+dsArgToAtom (TyArg t) continue_with = continue_with (TyArg t)
+dsArgToAtom (LitArg l) continue_with = continue_with (LitArg l)
+dsArgToAtom (VarArg arg) continue_with = dsExprToAtomGivenTy arg (coreExprType arg) continue_with
+
+dsExprToAtomGivenTy
+ :: CoreExpr -- The argument expression
+ -> Type -- Type of the argument
+ -> (CoreArg -> DsM CoreExpr) -- Something taking the argument *atom*,
+ -- and delivering an expression E
+ -> DsM CoreExpr -- Either E or let x=arg-expr in E
+
+dsExprToAtomGivenTy (Var v) arg_ty continue_with = continue_with (VarArg v)
+dsExprToAtomGivenTy (Lit v) arg_ty continue_with = continue_with (LitArg v)
+dsExprToAtomGivenTy arg_expr arg_ty continue_with
+ = newSysLocalDs arg_ty `thenDs` \ arg_id ->
continue_with (VarArg arg_id) `thenDs` \ body ->
returnDs (
- if isUnboxedType ty
+ if isUnpointedType arg_ty
then Case arg_expr (PrimAlts [] (BindDefault arg_id body))
else Let (NonRec arg_id arg_expr) body
)
-dsExprsToAtoms :: [CoreExpr]
+dsArgsToAtoms :: [DsCoreArg]
-> ([CoreArg] -> DsM CoreExpr)
-> DsM CoreExpr
-dsExprsToAtoms [] continue_with
- = continue_with []
+dsArgsToAtoms [] continue_with = continue_with []
-dsExprsToAtoms (arg:args) continue_with
- = dsExprToAtom arg $ \ arg_atom ->
- dsExprsToAtoms args $ \ arg_atoms ->
+dsArgsToAtoms (arg:args) continue_with
+ = dsArgToAtom arg $ \ arg_atom ->
+ dsArgsToAtoms args $ \ arg_atoms ->
continue_with (arg_atom:arg_atoms)
\end{code}
%* *
%************************************************************************
-Plumb the desugarer's @UniqueSupply@ in/out of the @UniqSupply@ monad
-world.
\begin{code}
-mkAppDs :: CoreExpr -> [Type] -> [CoreExpr] -> DsM CoreExpr
-mkConDs :: Id -> [Type] -> [CoreExpr] -> DsM CoreExpr
-mkPrimDs :: PrimOp -> [Type] -> [CoreExpr] -> DsM CoreExpr
+type DsCoreArg = GenCoreArg CoreExpr{-NB!-} Unused
-mkAppDs fun tys arg_exprs
- = dsExprsToAtoms arg_exprs $ \ vals ->
- returnDs (mkApp fun [] tys vals)
+mkAppDs :: CoreExpr -> [DsCoreArg] -> DsM CoreExpr
+mkConDs :: Id -> [DsCoreArg] -> DsM CoreExpr
+mkPrimDs :: PrimOp -> [DsCoreArg] -> DsM CoreExpr
-mkConDs con tys arg_exprs
- = dsExprsToAtoms arg_exprs $ \ vals ->
- returnDs (mkCon con [] tys vals)
+mkAppDs fun args
+ = dsArgsToAtoms args $ \ atoms ->
+ returnDs (mkGenApp fun atoms)
-mkPrimDs op tys arg_exprs
- = dsExprsToAtoms arg_exprs $ \ vals ->
- returnDs (mkPrim op [] tys vals)
+mkConDs con args
+ = dsArgsToAtoms args $ \ atoms ->
+ returnDs (Con con atoms)
+
+mkPrimDs op args
+ = dsArgsToAtoms args $ \ atoms ->
+ returnDs (Prim op atoms)
+\end{code}
+
+\begin{code}
+showForErr :: Outputable a => a -> String -- Boring but useful
+showForErr thing = showSDoc (ppr thing)
+
+mkErrorAppDs :: Id -- The error function
+ -> Type -- Type to which it should be applied
+ -> String -- The error message string to pass
+ -> DsM CoreExpr
+
+mkErrorAppDs err_id ty msg
+ = getSrcLocDs `thenDs` \ src_loc ->
+ let
+ full_msg = showSDoc (hcat [ppr src_loc, text "|", text msg])
+ msg_lit = NoRepStr (_PK_ full_msg)
+ in
+ returnDs (mkApp (Var err_id) [ty] [LitArg msg_lit])
\end{code}
%************************************************************************
expressions.
\begin{code}
-mkSelectorBinds :: [TyVar] -- Variables wrt which the pattern is polymorphic
- -> TypecheckedPat -- The pattern
- -> [(Id,Id)] -- Monomorphic and polymorphic binders for
- -- the pattern
- -> CoreExpr -- Expression to which the pattern is bound
+mkSelectorBinds :: TypecheckedPat -- The pattern
+ -> CoreExpr -- Expression to which the pattern is bound
-> DsM [(Id,CoreExpr)]
-mkSelectorBinds tyvars pat locals_and_globals val_expr
- = getSrcLocDs `thenDs` \ (src_file, src_line) ->
-
- if is_simple_tuple_pat pat then
- mkTupleBind tyvars [] locals_and_globals val_expr
- else
- newSysLocalDs stringTy `thenDs` \ str_var -> -- to hold the string
- let
- src_loc_str = escErrorMsg ('"' : src_file) ++ "%l" ++ src_line
- error_string = src_loc_str ++ "%~" --> ": pattern-match failed on an irrefutable pattern"
- error_msg = mkErrorApp res_ty str_var error_string
- in
- matchSimply val_expr pat res_ty local_tuple error_msg `thenDs` \ tuple_expr ->
- mkTupleBind tyvars [] locals_and_globals tuple_expr
+mkSelectorBinds (VarPat v) val_expr
+ = returnDs [(v, val_expr)]
+
+mkSelectorBinds pat val_expr
+ | is_simple_tuple_pat pat
+ = mkTupleBind binders val_expr
+
+ | otherwise
+ = mkErrorAppDs iRREFUT_PAT_ERROR_ID res_ty pat_string `thenDs` \ error_expr ->
+ matchSimply val_expr LetMatch pat res_ty local_tuple error_expr `thenDs` \ tuple_expr ->
+ mkTupleBind binders tuple_expr
+
where
- locals = [local | (local, _) <- locals_and_globals]
- local_tuple = mkTupleExpr locals
+ binders = collectTypedPatBinders pat
+ local_tuple = mkTupleExpr binders
res_ty = coreExprType local_tuple
is_simple_tuple_pat (TuplePat ps) = all is_var_pat ps
is_var_pat (VarPat v) = True
is_var_pat other = False -- Even wild-card patterns aren't acceptable
-\end{code}
-We're about to match against some patterns. We want to make some
-@Ids@ to use as match variables. If a pattern has an @Id@ readily at
-hand, which should indeed be bound to the pattern as a whole, then use it;
-otherwise, make one up.
-\begin{code}
-selectMatchVars :: [TypecheckedPat] -> DsM [Id]
-selectMatchVars pats
- = mapDs var_from_pat_maybe pats
- where
- var_from_pat_maybe (VarPat var) = returnDs var
- var_from_pat_maybe (AsPat var pat) = returnDs var
- var_from_pat_maybe (LazyPat pat) = var_from_pat_maybe pat
- var_from_pat_maybe other_pat
- = newSysLocalDs (outPatType other_pat) -- OK, better make up one...
+ pat_string = showSDoc (ppr pat)
\end{code}
-\begin{code}
-mkTupleBind :: [TyVar] -- Abstract wrt these...
- -> [DictVar] -- ... and these
-
- -> [(Id, Id)] -- Local, global pairs, equal in number
- -- to the size of the tuple. The types
- -- of the globals is the generalisation of
- -- the corresp local, wrt the tyvars and dicts
-
- -> CoreExpr -- Expr whose value is a tuple; the expression
- -- may mention the tyvars and dicts
-
- -> DsM [(Id, CoreExpr)] -- Bindings for the globals
-\end{code}
-
-The general call is
-\begin{verbatim}
- mkTupleBind tyvars dicts [(l1,g1), ..., (ln,gn)] tup_expr
-\end{verbatim}
-If $n=1$, the result is:
-\begin{verbatim}
- g1 = /\ tyvars -> \ dicts -> rhs
-\end{verbatim}
-Otherwise, the result is:
-\begin{verbatim}
- tup = /\ tyvars -> \ dicts -> tup_expr
- g1 = /\ tyvars -> \ dicts -> case (tup tyvars dicts) of
- (l1, ..., ln) -> l1
- ...etc...
-\end{verbatim}
-
-\begin{code}
-mkTupleBind tyvars dicts [(local,global)] tuple_expr
- = returnDs [(global, mkLam tyvars dicts tuple_expr)]
-\end{code}
-
-The general case:
\begin{code}
-mkTupleBind tyvars dicts local_global_prs tuple_expr
- = newSysLocalDs tuple_var_ty `thenDs` \ tuple_var ->
+mkTupleBind :: [Id] -- Names of tuple components
+ -> CoreExpr -- Expr whose value is a tuple of correct type
+ -> DsM [(Id, CoreExpr)] -- Bindings for the globals
- zipWithDs (mk_selector (Var tuple_var))
- local_global_prs
- [(0::Int) .. (length local_global_prs - 1)]
- `thenDs` \ tup_selectors ->
- returnDs (
- (tuple_var, mkLam tyvars dicts tuple_expr)
- : tup_selectors
- )
- where
- locals, globals :: [Id]
- locals = [local | (local,global) <- local_global_prs]
- globals = [global | (local,global) <- local_global_prs]
-
- no_of_binders = length local_global_prs
- tyvar_tys = mkTyVarTys tyvars
-
- tuple_var_ty :: Type
- tuple_var_ty
- = case (quantifyTy tyvars (mkRhoTy theta
- (applyTyCon (mkTupleTyCon no_of_binders)
- (map idType locals)))) of
- (_{-tossed templates-}, ty) -> ty
- where
- theta = map (splitDictType . idType) dicts
- mk_selector :: CoreExpr -> (Id, Id) -> Int -> DsM (Id, CoreExpr)
+mkTupleBind [local] tuple_expr
+ = returnDs [(local, tuple_expr)]
- mk_selector tuple_var_expr (local, global) which_local
- = mapDs duplicateLocalDs locals{-the whole bunch-} `thenDs` \ binders ->
- let
- selected = binders !! which_local
- in
- returnDs (
- global,
- mkLam tyvars dicts (
- mkTupleSelector (mkApp_XX (mkCoTyApps tuple_var_expr tyvar_tys) dicts)
- binders selected)
- )
-
-mkApp_XX :: CoreExpr -> [Id] -> CoreExpr
-mkApp_XX expr [] = expr
-mkApp_XX expr (id:ids) = mkApp_XX (App expr (VarArg id)) ids
+mkTupleBind locals tuple_expr
+ = newSysLocalDs (coreExprType tuple_expr) `thenDs` \ tuple_var ->
+ let
+ mk_bind local = (local, mkTupleSelector locals local (Var tuple_var))
+ in
+ returnDs ( (tuple_var, tuple_expr) :
+ map mk_bind locals )
\end{code}
-
@mkTupleExpr@ builds a tuple; the inverse to @mkTupleSelector@. If it
has only one element, it is the identity function.
\begin{code}
mkTupleExpr :: [Id] -> CoreExpr
-mkTupleExpr [] = Con (mkTupleCon 0) []
+mkTupleExpr [] = Con unitDataCon []
mkTupleExpr [id] = Var id
-mkTupleExpr ids = mkCon (mkTupleCon (length ids))
- [{-usages-}]
+mkTupleExpr ids = mkCon (tupleCon (length ids))
(map idType ids)
[ VarArg i | i <- ids ]
\end{code}
just the identity.
\begin{code}
-mkTupleSelector :: CoreExpr -- Scrutinee
- -> [Id] -- The tuple args
+mkTupleSelector :: [Id] -- The tuple args
-> Id -- The selected one
+ -> CoreExpr -- Scrutinee
-> CoreExpr
-mkTupleSelector expr [] the_var = panic "mkTupleSelector"
+mkTupleSelector [] the_var scrut = panic "mkTupleSelector"
-mkTupleSelector expr [var] should_be_the_same_var
+mkTupleSelector [var] should_be_the_same_var scrut
= ASSERT(var == should_be_the_same_var)
- expr
+ scrut
-mkTupleSelector expr vars the_var
- = Case expr (AlgAlts [(mkTupleCon arity, vars, Var the_var)]
+mkTupleSelector vars the_var scrut
+ = Case scrut (AlgAlts [(tupleCon arity, vars, Var the_var)]
NoDefault)
where
arity = length vars
only boxed types can be let-bound, we just turn the fail into a function
for the primitive case:
\begin{verbatim}
- let fail.33 :: () -> Int#
+ let fail.33 :: Void -> Int#
fail.33 = \_ -> error "Help"
in
case x of
p1 -> ...
- p2 -> fail.33 ()
- p3 -> fail.33 ()
+ p2 -> fail.33 void
+ p3 -> fail.33 void
p4 -> ...
\end{verbatim}
CoreExpr) -- Either the fail variable, or fail variable
-- applied to unit tuple
mkFailurePair ty
- | isUnboxedType ty
- = newFailLocalDs (mkFunTys [unit_ty] ty) `thenDs` \ fail_fun_var ->
- newSysLocalDs unit_ty `thenDs` \ fail_fun_arg ->
+ | isUnpointedType ty
+ = newFailLocalDs (voidTy `mkFunTy` ty) `thenDs` \ fail_fun_var ->
+ newSysLocalDs voidTy `thenDs` \ fail_fun_arg ->
returnDs (\ body ->
NonRec fail_fun_var (Lam (ValBinder fail_fun_arg) body),
- App (Var fail_fun_var) (VarArg unit_id))
+ App (Var fail_fun_var) (VarArg voidId))
| otherwise
= newFailLocalDs ty `thenDs` \ fail_var ->
returnDs (\ body -> NonRec fail_var body, Var fail_var)
+\end{code}
+
-unit_id :: Id -- out here to avoid CAF (sigh)
-unit_id = mkTupleCon 0
-unit_ty :: Type
-unit_ty = idType unit_id
-\end{code}