summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Breitner <mail@joachim-breitner.de>2017-08-18 14:14:19 +0200
committerJoachim Breitner <mail@joachim-breitner.de>2017-08-18 14:16:03 +0200
commitfee253fc48d80b0cbd29ec90b5377c1981eb888f (patch)
treeef2e65f9a73044bb0c3a2dfe844f01b85324b831
parent02862140ee3fee6e522f0d73a1ac14e6cf29e501 (diff)
downloadhaskell-fee253fc48d80b0cbd29ec90b5377c1981eb888f.tar.gz
CSE.cseOneExpr: Set InScopeSet correctly
because this is a convenience function for API users, calculate the in-scope set from `exprFreeVars`.
-rw-r--r--compiler/simplCore/CSE.hs10
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/simplCore/CSE.hs b/compiler/simplCore/CSE.hs
index ccbdf3537d..ffbcdb4877 100644
--- a/compiler/simplCore/CSE.hs
+++ b/compiler/simplCore/CSE.hs
@@ -12,13 +12,14 @@ module CSE (cseProgram, cseOneExpr) where
import CoreSubst
import Var ( Var )
-import VarEnv ( elemInScopeSet )
+import VarEnv ( elemInScopeSet, mkInScopeSet )
import Id ( Id, idType, idInlineActivation, isDeadBinder
, zapIdOccInfo, zapIdUsageInfo, idInlinePragma
, isJoinId )
import CoreUtils ( mkAltExpr, eqExpr
, exprIsLiteralString
, stripTicksE, stripTicksT, mkTicks )
+import CoreFVs ( exprFreeVars )
import Type ( tyConAppArgs )
import CoreSyn
import Outputable
@@ -444,8 +445,13 @@ tryForCSE env expr
-- top of the replaced sub-expression. This is probably not too
-- useful in practice, but upholds our semantics.
+-- | Runs CSE on a single expression.
+--
+-- This entry point is not used in the compiler itself, but is provided
+-- as a convenient entry point for users of the GHC API.
cseOneExpr :: InExpr -> OutExpr
-cseOneExpr = cseExpr emptyCSEnv
+cseOneExpr e = cseExpr env e
+ where env = emptyCSEnv {cs_subst = mkEmptySubst (mkInScopeSet (exprFreeVars e)) }
cseExpr :: CSEnv -> InExpr -> OutExpr
cseExpr env (Type t) = Type (substTy (csEnvSubst env) t)