diff options
author | Simon Peyton Jones <simonpj@microsoft.com> | 2014-08-25 12:24:55 +0100 |
---|---|---|
committer | Austin Seipp <austin@well-typed.com> | 2014-11-03 07:41:01 -0600 |
commit | 9622fcaf4a2bbe650a588dec4ffff85105b2bdcb (patch) | |
tree | c23f97f23ea53a4914f8e7fa9cf2013005eb1d61 | |
parent | fcece34760929d79dea3e9871462cb927f60aa5c (diff) | |
download | haskell-9622fcaf4a2bbe650a588dec4ffff85105b2bdcb.tar.gz |
Introduce the Call data types
This is just a small refactoring that makes the code a bit clearer,
using a data type instead of a triple. We get better pretty-printing too.
(cherry picked from commit c0fe1d9e7a9f23d050319c77f3a38264f3aa22f8)
-rw-r--r-- | compiler/specialise/SpecConstr.lhs | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/compiler/specialise/SpecConstr.lhs b/compiler/specialise/SpecConstr.lhs index faedb94413..609dcfd864 100644 --- a/compiler/specialise/SpecConstr.lhs +++ b/compiler/specialise/SpecConstr.lhs @@ -33,6 +33,7 @@ import Rules import Type hiding ( substTy ) import TyCon ( isRecursiveTyCon, tyConName ) import Id +import PprCore ( pprParendExpr ) import MkCore ( mkImpossibleExpr ) import Var import VarEnv @@ -1017,15 +1018,27 @@ data ScUsage } -- The domain is OutIds type CallEnv = IdEnv [Call] -type Call = (ValueEnv, [CoreArg]) +data Call = Call Id [CoreArg] ValueEnv -- The arguments of the call, together with the -- env giving the constructor bindings at the call site + -- We keep the function mainly for debug output + +instance Outputable Call where + ppr (Call fn args _) = ppr fn <+> fsep (map pprParendExpr args) nullUsage :: ScUsage nullUsage = SCU { scu_calls = emptyVarEnv, scu_occs = emptyVarEnv } combineCalls :: CallEnv -> CallEnv -> CallEnv combineCalls = plusVarEnv_C (++) + where +-- plus cs ds | length res > 1 +-- = pprTrace "combineCalls" (vcat [ ptext (sLit "cs:") <+> ppr cs +-- , ptext (sLit "ds:") <+> ppr ds]) +-- res +-- | otherwise = res +-- where +-- res = cs ++ ds combineUsage :: ScUsage -> ScUsage -> ScUsage combineUsage u1 u2 = SCU { scu_calls = combineCalls (scu_calls u1) (scu_calls u2), @@ -1283,7 +1296,7 @@ scApp env (other_fn, args) mkVarUsage :: ScEnv -> Id -> [CoreExpr] -> ScUsage mkVarUsage env fn args = case lookupHowBound env fn of - Just RecFun -> SCU { scu_calls = unitVarEnv fn [(sc_vals env, args)] + Just RecFun -> SCU { scu_calls = unitVarEnv fn [Call fn args (sc_vals env)] , scu_occs = emptyVarEnv } Just RecArg -> SCU { scu_calls = emptyVarEnv , scu_occs = unitVarEnv fn arg_occ } @@ -1709,7 +1722,7 @@ callToPats :: ScEnv -> [ArgOcc] -> Call -> UniqSM (Maybe (CallPat, ValueEnv)) -- Type variables come first, since they may scope -- over the following term variables -- The [CoreExpr] are the argument patterns for the rule -callToPats env bndr_occs (con_env, args) +callToPats env bndr_occs (Call _ args con_env) | length args < length bndr_occs -- Check saturated = return Nothing | otherwise |