X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;ds=sidebyside;f=ghc%2Fcompiler%2FstgSyn%2FCoreToStg.lhs;h=9ae0d2741bbd863643f285e59fb42b9aea43f32b;hb=30ee6ff795f017c433f27b37f290b29374545cec;hp=9397af6c74d868d99cb5c681ebce0c445b61c99e;hpb=ef5b4b146aa172d8ac10f39b5eb3d7a0f948d8f1;p=ghc-hetmet.git diff --git a/ghc/compiler/stgSyn/CoreToStg.lhs b/ghc/compiler/stgSyn/CoreToStg.lhs index 9397af6..9ae0d27 100644 --- a/ghc/compiler/stgSyn/CoreToStg.lhs +++ b/ghc/compiler/stgSyn/CoreToStg.lhs @@ -12,7 +12,7 @@ module CoreToStg ( coreToStg, coreExprToStg ) where #include "HsVersions.h" import CoreSyn -import CoreUtils ( rhsIsStatic, manifestArity, exprType ) +import CoreUtils ( rhsIsStatic, manifestArity, exprType, findDefault ) import StgSyn import Type @@ -32,7 +32,8 @@ import Maybes ( maybeToBool ) import Name ( getOccName, isExternalName, nameOccName ) import OccName ( occNameUserString, occNameFS ) import BasicTypes ( Arity ) -import CmdLineOpts ( DynFlags, opt_RuntimeTypes ) +import Packages ( HomeModules ) +import StaticFlags ( opt_RuntimeTypes ) import Outputable infixr 9 `thenLne` @@ -139,10 +140,10 @@ for x, solely to put in the SRTs lower down. %************************************************************************ \begin{code} -coreToStg :: DynFlags -> [CoreBind] -> IO [StgBinding] -coreToStg dflags pgm +coreToStg :: HomeModules -> [CoreBind] -> IO [StgBinding] +coreToStg hmods pgm = return pgm' - where (_, _, pgm') = coreTopBindsToStg dflags emptyVarEnv pgm + where (_, _, pgm') = coreTopBindsToStg hmods emptyVarEnv pgm coreExprToStg :: CoreExpr -> StgExpr coreExprToStg expr @@ -150,35 +151,35 @@ coreExprToStg expr coreTopBindsToStg - :: DynFlags + :: HomeModules -> IdEnv HowBound -- environment for the bindings -> [CoreBind] -> (IdEnv HowBound, FreeVarsInfo, [StgBinding]) -coreTopBindsToStg dflags env [] = (env, emptyFVInfo, []) -coreTopBindsToStg dflags env (b:bs) +coreTopBindsToStg hmods env [] = (env, emptyFVInfo, []) +coreTopBindsToStg hmods env (b:bs) = (env2, fvs2, b':bs') where -- env accumulates down the list of binds, fvs accumulates upwards - (env1, fvs2, b' ) = coreTopBindToStg dflags env fvs1 b - (env2, fvs1, bs') = coreTopBindsToStg dflags env1 bs + (env1, fvs2, b' ) = coreTopBindToStg hmods env fvs1 b + (env2, fvs1, bs') = coreTopBindsToStg hmods env1 bs coreTopBindToStg - :: DynFlags + :: HomeModules -> IdEnv HowBound -> FreeVarsInfo -- Info about the body -> CoreBind -> (IdEnv HowBound, FreeVarsInfo, StgBinding) -coreTopBindToStg dflags env body_fvs (NonRec id rhs) +coreTopBindToStg hmods env body_fvs (NonRec id rhs) = let env' = extendVarEnv env id how_bound - how_bound = LetBound TopLet (manifestArity rhs) + how_bound = LetBound TopLet $! manifestArity rhs (stg_rhs, fvs') = initLne env ( - coreToTopStgRhs dflags body_fvs (id,rhs) `thenLne` \ (stg_rhs, fvs') -> + coreToTopStgRhs hmods body_fvs (id,rhs) `thenLne` \ (stg_rhs, fvs') -> returnLne (stg_rhs, fvs') ) @@ -189,17 +190,17 @@ coreTopBindToStg dflags env body_fvs (NonRec id rhs) -- WARN(not (consistent caf_info bind), ppr id <+> ppr cafs <+> ppCafInfo caf_info) (env', fvs' `unionFVInfo` body_fvs, bind) -coreTopBindToStg dflags env body_fvs (Rec pairs) +coreTopBindToStg hmods env body_fvs (Rec pairs) = let (binders, rhss) = unzip pairs - extra_env' = [ (b, LetBound TopLet (manifestArity rhs)) + extra_env' = [ (b, LetBound TopLet $! manifestArity rhs) | (b, rhs) <- pairs ] env' = extendVarEnvList env extra_env' (stg_rhss, fvs') = initLne env' ( - mapAndUnzipLne (coreToTopStgRhs dflags body_fvs) pairs + mapAndUnzipLne (coreToTopStgRhs hmods body_fvs) pairs `thenLne` \ (stg_rhss, fvss') -> let fvs' = unionFVInfos fvss' in returnLne (stg_rhss, fvs') @@ -231,18 +232,18 @@ consistentCafInfo id bind \begin{code} coreToTopStgRhs - :: DynFlags + :: HomeModules -> FreeVarsInfo -- Free var info for the scope of the binding -> (Id,CoreExpr) -> LneM (StgRhs, FreeVarsInfo) -coreToTopStgRhs dflags scope_fv_info (bndr, rhs) +coreToTopStgRhs hmods scope_fv_info (bndr, rhs) = coreToStgExpr rhs `thenLne` \ (new_rhs, rhs_fvs, _) -> freeVarsToLiveVars rhs_fvs `thenLne` \ lv_info -> returnLne (mkTopStgRhs is_static rhs_fvs (mkSRT lv_info) bndr_info new_rhs, rhs_fvs) where bndr_info = lookupFVInfo scope_fv_info bndr - is_static = rhsIsStatic dflags rhs + is_static = rhsIsStatic hmods rhs mkTopStgRhs :: Bool -> FreeVarsInfo -> SRT -> StgBinderInfo -> StgExpr -> StgRhs @@ -333,7 +334,6 @@ coreToStgExpr (Note other_note expr) -- Cases require a little more real work. --- gaw 2004 coreToStgExpr (Case scrut bndr _ alts) = extendVarEnvLne [(bndr, LambdaBound)] ( mapAndUnzip3Lne vars_alt alts `thenLne` \ (alts2, fvs_s, escs_s) -> @@ -371,7 +371,7 @@ coreToStgExpr (Case scrut bndr _ alts) (getLiveVars alts_lv_info) bndr' (mkSRT alts_lv_info) - (mkStgAltType (idType bndr)) + (mkStgAltType (idType bndr) alts) alts2, scrut_fvs `unionFVInfo` alts_fvs_wo_bndr, alts_escs_wo_bndr `unionVarSet` getFVSet scrut_fvs @@ -411,15 +411,29 @@ coreToStgExpr (Let bind body) \end{code} \begin{code} -mkStgAltType scrut_ty +mkStgAltType scrut_ty alts = case splitTyConApp_maybe (repType scrut_ty) of Just (tc,_) | isUnboxedTupleTyCon tc -> UbxTupAlt tc | isPrimTyCon tc -> PrimAlt tc - | isHiBootTyCon tc -> PolyAlt -- Algebraic, but no constructors visible + | isHiBootTyCon tc -> look_for_better_tycon | isAlgTyCon tc -> AlgAlt tc | isFunTyCon tc -> PolyAlt | otherwise -> pprPanic "mkStgAlts" (ppr tc) Nothing -> PolyAlt + + where + -- Sometimes, the TyCon in the type of the scrutinee is an HiBootTyCon, + -- which may not have any constructors inside it. If so, then we + -- can get a better TyCon by grabbing the one from a constructor alternative + -- if one exists. + look_for_better_tycon + | ((DataAlt con, _, _) : _) <- data_alts = + AlgAlt (dataConTyCon con) + | otherwise = + ASSERT(null data_alts) + PolyAlt + where + (data_alts, _deflt) = findDefault alts \end{code}