isBoolTy, isUnitTy, isPrimitiveType,
tcSplitTyConApp_maybe
)
-import Type ( splitTyConApp_maybe, repType, eqType ) -- Sees the representation type
+import Type ( repType, eqType ) -- Sees the representation type
import PrimOp ( PrimOp(TouchOp) )
import TysPrim ( realWorldStatePrimTy,
byteArrayPrimTyCon, mutableByteArrayPrimTyCon,
prim_arg
[(DEFAULT,[],body)])
- -- Newtypes
-- Data types with a single constructor, which has a single, primitive-typed arg
-- This deals with Int, Float etc
| is_product_type && data_con_arity == 1
)
-- Byte-arrays, both mutable and otherwise; hack warning
+ -- We're looking for values of type ByteArray, MutableByteArray
+ -- data ByteArray ix = ByteArray ix ix ByteArray#
+ -- data MutableByteArray s ix = MutableByteArray ix ix (MutableByteArray# s)
| is_product_type &&
data_con_arity == 3 &&
maybeToBool maybe_arg3_tycon &&
where
arg_ty = repType (exprType arg)
-- The repType looks through any newtype or
- -- implicit-parameter wrappings on the argument.
+ -- implicit-parameter wrappings on the argument;
+ -- this is necessary, because isBoolTy (in particular) does not.
+
maybe_product_type = splitProductType_maybe arg_ty
is_product_type = maybeToBool maybe_product_type
Just (_, _, data_con, data_con_arg_tys) = maybe_product_type
boxResult arg_ids result_ty
= case tcSplitTyConApp_maybe result_ty of
+ -- This split absolutely has to be a tcSplit, because we must
+ -- see the IO type; and it's a newtype which is transparent to splitTyConApp.
-- The result is IO t, so wrap the result in an IO constructor
Just (io_tycon, [io_res_ty]) | io_tycon `hasKey` ioTyConKey
| isUnitTy result_ty_rep
= (Nothing, \e -> Var unitDataConId)
- -- Base case 3: the boolean type ()
+ -- Base case 3: the boolean type
| isBoolTy result_ty_rep
= (Just intPrimTy, \e -> Case e (mkWildId intPrimTy)
[(DEFAULT ,[],Var trueDataConId ),
| otherwise
= pprPanic "resultWrapper" (ppr result_ty)
where
- result_ty_rep = repType result_ty
-
+ result_ty_rep = repType result_ty -- Look through any newtypes/implicit parameters
\end{code}