[commit: ghc] wip/rwbarton-simplify: Fix space leaks in simplifier (#13426) (c1f25e5)

git at git.haskell.org git at git.haskell.org
Thu Mar 30 19:25:31 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/rwbarton-simplify
Link       : http://ghc.haskell.org/trac/ghc/changeset/c1f25e5e9b946a119587765dd57288bfee674d18/ghc

>---------------------------------------------------------------

commit c1f25e5e9b946a119587765dd57288bfee674d18
Author: Reid Barton <rwbarton at gmail.com>
Date:   Mon Mar 27 22:15:29 2017 -0400

    Fix space leaks in simplifier (#13426)
    
    Summary: The Join points commit (8d5cf8bf) introduced a space leak
    somewhere in the simplifier. The extra strictness added in this commit
    fixes the leak. Unfortunately I don't really understand the details.
    
    Test Plan: harbormaster
    
    Reviewers:
    
    Subscribers:


>---------------------------------------------------------------

c1f25e5e9b946a119587765dd57288bfee674d18
 compiler/simplCore/Simplify.hs | 26 +++++++++++++++++---------
 1 file changed, 17 insertions(+), 9 deletions(-)

diff --git a/compiler/simplCore/Simplify.hs b/compiler/simplCore/Simplify.hs
index e78714d..b130339 100644
--- a/compiler/simplCore/Simplify.hs
+++ b/compiler/simplCore/Simplify.hs
@@ -1001,16 +1001,21 @@ simplExprF1 env (Lit lit)      cont = rebuild env (Lit lit) cont
 simplExprF1 env (Tick t expr)  cont = simplTick env t expr cont
 simplExprF1 env (Cast body co) cont = simplCast env body co cont
 simplExprF1 env (Coercion co)  cont = simplCoercionF env co cont
-simplExprF1 env (Type ty)      cont = ASSERT( contIsRhsOrArg cont )
-                                      rebuild env (Type (substTy env ty)) cont
+simplExprF1 env (Type ty)      cont
+  = ASSERT( contIsRhsOrArg cont )
+    do { ty' <- simplType env ty
+       ; rebuild env (Type ty') cont }
 
 simplExprF1 env (App fun arg) cont
-  = simplExprF env fun $
-    case arg of
-      Type ty -> ApplyToTy  { sc_arg_ty  = substTy env ty
-                            , sc_hole_ty = substTy env (exprType fun)
-                            , sc_cont    = cont }
-      _       -> ApplyToVal { sc_arg = arg, sc_env = env
+  = case arg of
+      Type ty -> do { arg' <- simplType env ty
+                    ; hole' <- simplType env (exprType fun)
+                    ; simplExprF env fun $
+                      ApplyToTy { sc_arg_ty  = arg'
+                                , sc_hole_ty = hole'
+                                , sc_cont    = cont } }
+      _       -> simplExprF env fun $
+                 ApplyToVal { sc_arg = arg, sc_env = env
                             , sc_dup = NoDup, sc_cont = cont }
 
 simplExprF1 env expr@(Lam {}) cont
@@ -2217,7 +2222,10 @@ reallyRebuildCase env scrut case_bndr alts cont
 
         ; dflags <- getDynFlags
         ; let alts_ty' = contResultType dup_cont
-        ; case_expr <- mkCase dflags scrut' case_bndr' alts_ty' alts'
+        -- The seqType below is needed to avoid a space leak (#13426)
+        -- but I don't know why.
+        ; case_expr <- seqType alts_ty' `seq`
+                       mkCase dflags scrut' case_bndr' alts_ty' alts'
 
         -- Notice that rebuild gets the in-scope set from env', not alt_env
         -- (which in any case is only build in simplAlts)



More information about the ghc-commits mailing list