X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Fcompiler%2FdeSugar%2FDsBinds.lhs;h=4f2323d4edc7770538699fa7da0c9fbe14ac2da1;hb=2007c7e67ddea6e16f4c8e013a453b073232459a;hp=2131f60c273806ed2636cb508a448f41d1384471;hpb=acaa2124a9427aec9ccc96e0c8b6e067a85916e0;p=ghc-hetmet.git diff --git a/ghc/compiler/deSugar/DsBinds.lhs b/ghc/compiler/deSugar/DsBinds.lhs index 2131f60..4f2323d 100644 --- a/ghc/compiler/deSugar/DsBinds.lhs +++ b/ghc/compiler/deSugar/DsBinds.lhs @@ -17,29 +17,23 @@ import {-# SOURCE #-} DsExpr( dsExpr ) import HsSyn -- lots of things import CoreSyn -- lots of things -import CoreUtils ( coreExprType ) +import CoreUtils ( exprType, mkInlineMe, mkSCC ) import TcHsSyn ( TypecheckedMonoBinds ) import DsMonad import DsGRHSs ( dsGuarded ) import DsUtils import Match ( matchWrapper ) -import BasicTypes ( RecFlag(..) ) -import CmdLineOpts ( opt_SccProfilingOn, opt_AutoSccsOnAllToplevs, - opt_AutoSccsOnExportedToplevs, opt_AutoSccsOnDicts - ) -import CostCentre ( CostCentre, mkAutoCC, IsCafCC(..) ) -import Id ( idType, idName, isUserExportedId, isSpecPragmaId, Id ) +import CmdLineOpts ( opt_AutoSccsOnAllToplevs, opt_AutoSccsOnExportedToplevs ) +import CostCentre ( mkAutoCC, IsCafCC(..) ) +import Id ( idType, idName, isExportedId, isSpecPragmaId, Id ) import NameSet -import VarEnv import VarSet -import Type ( mkTyVarTy, isDictTy ) -import Subst ( mkTyVarSubst, substTy ) +import TcType ( mkTyVarTy ) +import Subst ( substTyWith ) import TysWiredIn ( voidTy ) import Outputable - -import Maybe -import IOExts (trace) +import Maybe ( isJust ) \end{code} %************************************************************************ @@ -84,11 +78,9 @@ dsMonoBinds _ (VarMonoBind var expr) rest dsMonoBinds auto_scc (FunMonoBind fun _ matches locn) rest = putSrcLocDs locn $ - matchWrapper (FunMatch fun) matches error_string `thenDs` \ (args, body) -> + matchWrapper (FunRhs fun) matches `thenDs` \ (args, body) -> addAutoScc auto_scc (fun, mkLams args body) `thenDs` \ pair -> returnDs (pair : rest) - where - error_string = "function " ++ showSDoc (ppr fun) dsMonoBinds auto_scc (PatMonoBind pat grhss locn) rest = putSrcLocDs locn $ @@ -97,8 +89,20 @@ dsMonoBinds auto_scc (PatMonoBind pat grhss locn) rest mapDs (addAutoScc auto_scc) sel_binds `thenDs` \ sel_binds -> returnDs (sel_binds ++ rest) - -- Common case: one exported variable - -- All non-recursive bindings come through this way + -- Common special case: no type or dictionary abstraction + -- For the (rare) case when there are some mixed-up + -- dictionary bindings (for which a Rec is convenient) + -- we reply on the enclosing dsBind to wrap a Rec around. +dsMonoBinds auto_scc (AbsBinds [] [] exports inlines binds) rest + = dsMonoBinds (addSccs auto_scc exports) binds []`thenDs` \ core_prs -> + let + core_prs' = addLocalInlines exports inlines core_prs + exports' = [(global, Var local) | (_, global, local) <- exports] + in + returnDs (core_prs' ++ exports' ++ rest) + + -- Another common case: one exported variable + -- Non-recursive bindings come through this way dsMonoBinds auto_scc (AbsBinds all_tyvars dicts exps@[(tyvars, global, local)] inlines binds) rest = ASSERT( all (`elem` tyvars) all_tyvars ) @@ -106,50 +110,46 @@ dsMonoBinds auto_scc let -- Always treat the binds as recursive, because the typechecker -- makes rather mixed-up dictionary bindings - core_binds = [Rec core_prs] - global' = (global, mkInline (idName global `elemNameSet` inlines) $ - mkLams tyvars $ mkLams dicts $ - mkDsLets core_binds (Var local)) - in - returnDs (global' : rest) + core_bind = Rec core_prs - -- Another common special case: no type or dictionary abstraction -dsMonoBinds auto_scc (AbsBinds [] [] exports inlines binds) rest - = dsMonoBinds (addSccs auto_scc exports) binds []`thenDs` \ core_prs -> - let - exports' = [(global, Var local) | (_, global, local) <- exports] + -- The mkInline does directly what the + -- addLocalInlines do in the other cases + export' = (global, mkInline (idName global `elemNameSet` inlines) $ + mkLams tyvars $ mkLams dicts $ + Let core_bind (Var local)) in - returnDs (addLocalInlines exports inlines core_prs ++ exports' ++ rest) + returnDs (export' : rest) dsMonoBinds auto_scc (AbsBinds all_tyvars dicts exports inlines binds) rest = dsMonoBinds (addSccs auto_scc exports) binds []`thenDs` \ core_prs -> let - core_binds = [Rec (addLocalInlines exports inlines core_prs)] + -- Rec because of mixed-up dictionary bindings + core_bind = Rec (addLocalInlines exports inlines core_prs) tup_expr = mkTupleExpr locals - tup_ty = coreExprType tup_expr + tup_ty = exprType tup_expr poly_tup_expr = mkLams all_tyvars $ mkLams dicts $ - mkDsLets core_binds tup_expr + Let core_bind tup_expr locals = [local | (_, _, local) <- exports] local_tys = map idType locals in - newSysLocalDs (coreExprType poly_tup_expr) `thenDs` \ poly_tup_id -> + newSysLocalDs (exprType poly_tup_expr) `thenDs` \ poly_tup_id -> let dict_args = map Var dicts mk_bind (tyvars, global, local) n -- locals !! n == local = -- Need to make fresh locals to bind in the selector, because -- some of the tyvars will be bound to voidTy - newSysLocalsDs (map (substTy env) local_tys) `thenDs` \ locals' -> - newSysLocalDs (substTy env tup_ty) `thenDs` \ tup_id -> + newSysLocalsDs (map substitute local_tys) `thenDs` \ locals' -> + newSysLocalDs (substitute tup_ty) `thenDs` \ tup_id -> returnDs (global, mkLams tyvars $ mkLams dicts $ mkTupleSelector locals' (locals' !! n) tup_id $ mkApps (mkTyApps (Var poly_tup_id) ty_args) dict_args) where mk_ty_arg all_tyvar | all_tyvar `elem` tyvars = mkTyVarTy all_tyvar | otherwise = voidTy - ty_args = map mk_ty_arg all_tyvars - env = mkTyVarSubst all_tyvars ty_args + ty_args = map mk_ty_arg all_tyvars + substitute = substTyWith all_tyvars ty_args in zipWithDs mk_bind exports [0..] `thenDs` \ export_binds -> -- don't scc (auto-)annotate the tuple itself. @@ -165,7 +165,7 @@ dsMonoBinds auto_scc (AbsBinds all_tyvars dicts exports inlines binds) rest \begin{code} mkInline :: Bool -> CoreExpr -> CoreExpr -mkInline True body = Note InlineMe body +mkInline True body = mkInlineMe body mkInline False body = body addLocalInlines :: [(a, Id, Id)] -> NameSet -> [(Id,CoreExpr)] -> [(Id,CoreExpr)] @@ -194,7 +194,7 @@ addSccs NoSccs exports = NoSccs addSccs TopLevel exports = TopLevelAddSccs (\id -> case [ exp | (_,exp,loc) <- exports, loc == id ] of (exp:_) | opt_AutoSccsOnAllToplevs || - (isUserExportedId exp && + (isExportedId exp && opt_AutoSccsOnExportedToplevs) -> Just exp _ -> Nothing) @@ -204,18 +204,15 @@ addAutoScc :: AutoScc -- if needs be, decorate toplevs? -> DsM (Id, CoreExpr) addAutoScc (TopLevelAddSccs auto_scc_fn) pair@(bndr, core_expr) - | do_auto_scc && worthSCC core_expr - = getModuleAndGroupDs `thenDs` \ (mod,grp) -> - returnDs (bndr, Note (SCC (mkAutoCC top_bndr mod grp NotCafCC)) core_expr) + | do_auto_scc + = getModuleDs `thenDs` \ mod -> + returnDs (bndr, mkSCC (mkAutoCC top_bndr mod NotCafCC) core_expr) where do_auto_scc = isJust maybe_auto_scc maybe_auto_scc = auto_scc_fn bndr (Just top_bndr) = maybe_auto_scc + addAutoScc _ pair = returnDs pair - -worthSCC (Note (SCC _) _) = False -worthSCC (Con _ _) = False -worthSCC core_expr = True \end{code} If profiling and dealing with a dict binding,