X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FdeSugar%2FDsCCall.lhs;h=47eb7c1b56b91585bfbd29ba75d76f5333d812b0;hb=e7498a3ee1d0484d02a9e86633cc179c76ebf36e;hp=b54e111991732992fbcb906ac546318fb1b39fdf;hpb=7d61cb61daa5e433a0cb85b34b7f0c58b2f961ff;p=ghc-hetmet.git diff --git a/ghc/compiler/deSugar/DsCCall.lhs b/ghc/compiler/deSugar/DsCCall.lhs index b54e111..47eb7c1 100644 --- a/ghc/compiler/deSugar/DsCCall.lhs +++ b/ghc/compiler/deSugar/DsCCall.lhs @@ -8,7 +8,7 @@ module DsCCall ( dsCCall ) where -import Ubiq +IMP_Ubiq() import CoreSyn @@ -16,20 +16,20 @@ import DsMonad import DsUtils import CoreUtils ( coreExprType ) -import Id ( getInstantiatedDataConSig, mkTupleCon ) +import Id ( dataConArgTys, mkTupleCon ) import Maybes ( maybeToBool ) import PprStyle ( PprStyle(..) ) import PprType ( GenType{-instances-} ) -import PrelInfo ( byteArrayPrimTy, getStatePairingConInfo, - packStringForCId, realWorldStatePrimTy, - realWorldStateTy, realWorldTy, stateDataCon, - stringTy ) import Pretty +import PrelVals ( packStringForCId ) import PrimOp ( PrimOp(..) ) -import Type ( isPrimType, maybeAppDataTyCon, eqTy ) +import Type ( isPrimType, maybeAppDataTyConExpandingDicts, eqTy, maybeBoxedPrimType ) +import TysPrim ( byteArrayPrimTy, realWorldTy, realWorldStatePrimTy ) +import TysWiredIn ( getStatePairingConInfo, + realWorldStateTy, stateDataCon, + stringTy + ) import Util ( pprPanic, pprError, panic ) - -maybeBoxedPrimType = panic "DsCCall.maybeBoxedPrimType" \end{code} Desugaring of @ccall@s consists of adding some state manipulation, @@ -107,7 +107,7 @@ unboxArg arg -- Primitive types -- ADR Question: can this ever be used? None of the PrimTypes are - -- instances of the _CCallable class. + -- instances of the CCallable class. | isPrimType arg_ty = returnDs (arg, \body -> body) @@ -131,7 +131,7 @@ unboxArg arg length data_con_arg_tys == 2 && not (isPrimType data_con_arg_ty1) && isPrimType data_con_arg_ty2 - -- and, of course, it is an instance of _CCallable + -- and, of course, it is an instance of CCallable -- ( tycon == byteArrayTyCon || -- tycon == mutableByteArrayTyCon ) = newSysLocalsDs data_con_arg_tys `thenDs` \ vars@[ixs_var, arr_cts_var] -> @@ -147,38 +147,7 @@ unboxArg arg \ body -> Case arg (AlgAlts [(box_data_con,[prim_arg],body)] NoDefault) ) - -- ... continued below .... -\end{code} - -As an experiment, I'm going to unpack any "acceptably small" -enumeration. This code will never get used in the main version -because enumerations would have triggered type errors but I've -disabled type-checking in my version. ADR - -To Will: It might be worth leaving this in (but commented out) until -we decide what's happening with enumerations. ADR - -\begin{code} -#if 0 - -- MAYBE LATER: - -- Data types with a nullary constructors (enumeration) - | isEnumerationType arg_ty && -- enumeration - (length data_cons) <= 5 -- "acceptably short" - = newSysLocalDs the_prim_arg_ty `thenDs` \ prim_arg -> - - let - alts = [ (con, [], mkMachInt i) | (con,i) <- data_cons `zip` [0..] ] - arg_tag = Case arg (AlgAlts alts) NoDefault - in - - returnDs (Var prim_arg, - \ body -> Case arg_tag (PrimAlts [(prim_arg, body)] NoDefault) - ) -#endif -\end{code} -\begin{code} - -- ... continued from above .... | otherwise = pprPanic "unboxArg: " (ppr PprDebug arg_ty) where @@ -187,12 +156,12 @@ we decide what's happening with enumerations. ADR maybe_boxed_prim_arg_ty = maybeBoxedPrimType arg_ty (Just (box_data_con, the_prim_arg_ty)) = maybe_boxed_prim_arg_ty - maybe_data_type = maybeAppDataTyCon arg_ty + maybe_data_type = maybeAppDataTyConExpandingDicts arg_ty is_data_type = maybeToBool maybe_data_type (Just (tycon, tycon_arg_tys, data_cons)) = maybe_data_type (the_data_con : other_data_cons) = data_cons - (_, data_con_arg_tys, _) = getInstantiatedDataConSig the_data_con tycon_arg_tys + data_con_arg_tys = dataConArgTys the_data_con tycon_arg_tys (data_con_arg_ty1 : data_con_arg_ty2 : _) = data_con_arg_tys can't_see_datacons_error thing ty @@ -256,43 +225,15 @@ boxResult result_ty \prim_app -> Case prim_app (AlgAlts [the_alt] NoDefault) ) -#if 0 - -- MAYBE LATER??? - - -- Data types with several nullary constructors (Enumerated types) - | isEnumerationType result_ty && -- Enumeration - (length data_cons) <= 5 -- fairly short - = - newSysLocalDs realWorldStatePrimTy `thenDs` \ prim_state_id -> - newSysLocalDs intPrimTy `thenDs` \ prim_result_id -> - - mkConDs stateDataCon [realWorldTy] [Var prim_state_id] `thenDs` \ new_state -> - - let - alts = [ (mkMachInt i, con) | (i, con) <- [0..] `zip` data_cons ] - the_result = Case prim_result_id (PrimAlts alts) NoDefault - in - - mkConDs (mkTupleCon 2) - [result_ty, realWorldStateTy] - [the_result, new_state] `thenDs` \ the_pair -> - let - the_alt = (state_and_prim_datacon, [prim_state_id, prim_result_id], the_pair) - in - returnDs (state_and_prim_ty, - \prim_app -> Case prim_app (AlgAlts [the_alt] NoDefault) - ) -#endif - | otherwise = pprPanic "boxResult: " (ppr PprDebug result_ty) where - maybe_data_type = maybeAppDataTyCon result_ty + maybe_data_type = maybeAppDataTyConExpandingDicts result_ty Just (tycon, tycon_arg_tys, data_cons) = maybe_data_type (the_data_con : other_data_cons) = data_cons - (_, data_con_arg_tys, _) = getInstantiatedDataConSig the_data_con tycon_arg_tys + data_con_arg_tys = dataConArgTys the_data_con tycon_arg_tys (the_prim_result_ty : other_args_tys) = data_con_arg_tys (state_and_prim_datacon, state_and_prim_ty) = getStatePairingConInfo the_prim_result_ty