Skip to content
Snippets Groups Projects
Commit 354ce404 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

[project @ 1999-06-28 16:29:45 by simonpj]

* Add Type.repType

* Re-express splitRepTyConApp_maybe using repType

* Use the new repType in Core2Stg

	The bug was that we ended up with a binding like
		let x = /\a -> 3# +# y
		in ...
	and this should turn into an STG case, but the big lambda
	fooled the core-to-STG pass
parent 26caf834
No related merge requests found
% %
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
% %
% $Id: CgCase.lhs,v 1.33 1999/06/24 13:04:16 simonmar Exp $ % $Id: CgCase.lhs,v 1.34 1999/06/28 16:29:45 simonpj Exp $
% %
%******************************************************** %********************************************************
%* * %* *
...@@ -62,7 +62,7 @@ import TyCon ( TyCon, isEnumerationTyCon, isUnboxedTupleTyCon, ...@@ -62,7 +62,7 @@ import TyCon ( TyCon, isEnumerationTyCon, isUnboxedTupleTyCon,
isNewTyCon, isAlgTyCon, isFunTyCon, isPrimTyCon, isNewTyCon, isAlgTyCon, isFunTyCon, isPrimTyCon,
tyConDataCons, tyConFamilySize ) tyConDataCons, tyConFamilySize )
import Type ( Type, typePrimRep, splitAlgTyConApp, import Type ( Type, typePrimRep, splitAlgTyConApp,
splitTyConApp_maybe, splitRepTyConApp_maybe ) splitTyConApp_maybe, repType )
import Unique ( Unique, Uniquable(..), mkBuiltinUnique ) import Unique ( Unique, Uniquable(..), mkBuiltinUnique )
import Maybes ( maybeToBool ) import Maybes ( maybeToBool )
import Util import Util
...@@ -981,7 +981,7 @@ possibleHeapCheck NoGC _ _ tags lbl code ...@@ -981,7 +981,7 @@ possibleHeapCheck NoGC _ _ tags lbl code
\begin{code} \begin{code}
getScrutineeTyCon :: Type -> Maybe TyCon getScrutineeTyCon :: Type -> Maybe TyCon
getScrutineeTyCon ty = getScrutineeTyCon ty =
case splitRepTyConApp_maybe ty of case splitTyConApp_maybe (repType ty) of
Nothing -> Nothing Nothing -> Nothing
Just (tc,_) -> Just (tc,_) ->
if isFunTyCon tc then Nothing else -- not interested in funs if isFunTyCon tc then Nothing else -- not interested in funs
......
% %
% (c) The GRASP/AQUA Project, Glasgow University, 1992-1998 % (c) The GRASP/AQUA Project, Glasgow University, 1992-1998
% %
% $Id: CgExpr.lhs,v 1.28 1999/06/24 13:04:18 simonmar Exp $ % $Id: CgExpr.lhs,v 1.29 1999/06/28 16:29:45 simonpj Exp $
% %
%******************************************************** %********************************************************
%* * %* *
...@@ -48,7 +48,7 @@ import PrimOp ( primOpOutOfLine, ...@@ -48,7 +48,7 @@ import PrimOp ( primOpOutOfLine,
import PrimRep ( getPrimRepSize, PrimRep(..), isFollowableRep ) import PrimRep ( getPrimRepSize, PrimRep(..), isFollowableRep )
import TyCon ( maybeTyConSingleCon, import TyCon ( maybeTyConSingleCon,
isUnboxedTupleTyCon, isEnumerationTyCon ) isUnboxedTupleTyCon, isEnumerationTyCon )
import Type ( Type, typePrimRep, splitTyConApp_maybe, splitRepTyConApp_maybe ) import Type ( Type, typePrimRep, splitTyConApp_maybe, repType )
import Maybes ( assocMaybe, maybeToBool ) import Maybes ( assocMaybe, maybeToBool )
import Unique ( mkBuiltinUnique ) import Unique ( mkBuiltinUnique )
import BasicTypes ( TopLevelFlag(..), RecFlag(..) ) import BasicTypes ( TopLevelFlag(..), RecFlag(..) )
...@@ -462,7 +462,7 @@ primRetUnboxedTuple op args res_ty ...@@ -462,7 +462,7 @@ primRetUnboxedTuple op args res_ty
allocate some temporaries for the return values. allocate some temporaries for the return values.
-} -}
let let
(tc,ty_args) = case splitRepTyConApp_maybe res_ty of (tc,ty_args) = case splitTyConApp_maybe (repType res_ty) of
Nothing -> pprPanic "primRetUnboxedTuple" (ppr res_ty) Nothing -> pprPanic "primRetUnboxedTuple" (ppr res_ty)
Just pr -> pr Just pr -> pr
prim_reps = map typePrimRep ty_args prim_reps = map typePrimRep ty_args
......
...@@ -34,7 +34,7 @@ import Const ( Con(..), Literal(..), isLitLitLit, conStrictness, isWHNFC ...@@ -34,7 +34,7 @@ import Const ( Con(..), Literal(..), isLitLitLit, conStrictness, isWHNFC
import VarEnv import VarEnv
import PrimOp ( PrimOp(..), primOpUsg, primOpSig ) import PrimOp ( PrimOp(..), primOpUsg, primOpSig )
import Type ( isUnLiftedType, isUnboxedTupleType, Type, splitFunTy_maybe, import Type ( isUnLiftedType, isUnboxedTupleType, Type, splitFunTy_maybe,
UsageAnn(..), tyUsg, applyTy, mkUsgTy ) UsageAnn(..), tyUsg, applyTy, mkUsgTy, repType )
import TysPrim ( intPrimTy ) import TysPrim ( intPrimTy )
import UniqSupply -- all of it, really import UniqSupply -- all of it, really
import Util ( lengthExceeds ) import Util ( lengthExceeds )
...@@ -813,10 +813,10 @@ mkStgBind (NonRecF bndr rhs dem floats) body ...@@ -813,10 +813,10 @@ mkStgBind (NonRecF bndr rhs dem floats) body
mk_stg_let bndr rhs dem floats body mk_stg_let bndr rhs dem floats body
#endif #endif
| isUnLiftedType bndr_ty -- Use a case/PrimAlts | isUnLiftedType bndr_rep_ty -- Use a case/PrimAlts
= ASSERT( not (isUnboxedTupleType bndr_ty) ) = ASSERT( not (isUnboxedTupleType bndr_rep_ty) )
mkStgBinds floats $ mkStgBinds floats $
mkStgCase rhs bndr (StgPrimAlts bndr_ty [] (StgBindDefault body)) mkStgCase rhs bndr (StgPrimAlts bndr_rep_ty [] (StgBindDefault body))
| is_whnf | is_whnf
= if is_strict then = if is_strict then
...@@ -836,19 +836,19 @@ mk_stg_let bndr rhs dem floats body ...@@ -836,19 +836,19 @@ mk_stg_let bndr rhs dem floats body
= if is_strict then = if is_strict then
-- Strict let with non-WHNF rhs -- Strict let with non-WHNF rhs
mkStgBinds floats $ mkStgBinds floats $
mkStgCase rhs bndr (StgAlgAlts bndr_ty [] (StgBindDefault body)) mkStgCase rhs bndr (StgAlgAlts bndr_rep_ty [] (StgBindDefault body))
else else
-- Lazy let with non-WHNF rhs, so keep the floats in the RHS -- Lazy let with non-WHNF rhs, so keep the floats in the RHS
mkStgBinds floats rhs `thenUs` \ new_rhs -> mkStgBinds floats rhs `thenUs` \ new_rhs ->
returnUs (StgLet (StgNonRec bndr (exprToRhs dem NotTopLevel new_rhs)) body) returnUs (StgLet (StgNonRec bndr (exprToRhs dem NotTopLevel new_rhs)) body)
where where
bndr_ty = idType bndr bndr_rep_ty = repType (idType bndr)
is_strict = isStrictDem dem is_strict = isStrictDem dem
is_whnf = case rhs of is_whnf = case rhs of
StgCon _ _ _ -> True StgCon _ _ _ -> True
StgLam _ _ _ -> True StgLam _ _ _ -> True
other -> False other -> False
-- Split at the first strict binding -- Split at the first strict binding
splitFloats fs@(NonRecF _ _ dem _ : _) splitFloats fs@(NonRecF _ _ dem _ : _)
......
...@@ -29,10 +29,10 @@ module Type ( ...@@ -29,10 +29,10 @@ module Type (
zipFunTys, zipFunTys,
mkTyConApp, mkTyConTy, splitTyConApp_maybe, mkTyConApp, mkTyConTy, splitTyConApp_maybe,
splitAlgTyConApp_maybe, splitAlgTyConApp, splitRepTyConApp_maybe, splitAlgTyConApp_maybe, splitAlgTyConApp,
mkDictTy, splitDictTy_maybe, isDictTy, mkDictTy, splitDictTy_maybe, isDictTy,
mkSynTy, isSynTy, deNoteType, mkSynTy, isSynTy, deNoteType, repType,
mkUsgTy, isUsgTy{- dont use -}, isNotUsgTy, splitUsgTy, unUsgTy, tyUsg, mkUsgTy, isUsgTy{- dont use -}, isNotUsgTy, splitUsgTy, unUsgTy, tyUsg,
...@@ -529,27 +529,6 @@ isDictTy (NoteTy _ ty) = isDictTy ty ...@@ -529,27 +529,6 @@ isDictTy (NoteTy _ ty) = isDictTy ty
isDictTy other = False isDictTy other = False
\end{code} \end{code}
splitRepTyConApp_maybe is like splitTyConApp_maybe except
that it looks through
(a) for-alls, and
(b) newtypes
in addition to synonyms. It's useful in the back end where we're not
interested in newtypes anymore.
\begin{code}
splitRepTyConApp_maybe :: Type -> Maybe (TyCon, [Type])
splitRepTyConApp_maybe (FunTy arg res) = Just (funTyCon, [arg,res])
splitRepTyConApp_maybe (NoteTy _ ty) = splitRepTyConApp_maybe ty
splitRepTyConApp_maybe (ForAllTy _ ty) = splitRepTyConApp_maybe ty
splitRepTyConApp_maybe (TyConApp tc tys)
| isNewTyCon tc
= case splitFunTy_maybe (applyTys (dataConType (head (tyConDataCons tc))) tys) of
Just (rep_ty, _) -> splitRepTyConApp_maybe rep_ty
| otherwise
= Just (tc,tys)
splitRepTyConApp_maybe other = Nothing
\end{code}
--------------------------------------------------------------------- ---------------------------------------------------------------------
SynTy SynTy
~~~~~ ~~~~~
...@@ -592,6 +571,23 @@ interfaces. Notably this plays a role in tcTySigs in TcBinds.lhs. ...@@ -592,6 +571,23 @@ interfaces. Notably this plays a role in tcTySigs in TcBinds.lhs.
repType looks through
(a) for-alls, and
(b) newtypes
in addition to synonyms. It's useful in the back end where we're not
interested in newtypes anymore.
\begin{code}
repType :: Type -> Type
repType (NoteTy _ ty) = repType ty
repType (ForAllTy _ ty) = repType ty
repType (TyConApp tc tys) | isNewTyCon tc
= case splitFunTy_maybe (applyTys (dataConType (head (tyConDataCons tc))) tys) of
Just (rep_ty, _) -> repType rep_ty
repType other_ty = other_ty
\end{code}
--------------------------------------------------------------------- ---------------------------------------------------------------------
UsgNote UsgNote
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment