[Git][ghc/ghc][wip/T24251] Wibbles

Simon Peyton Jones (@simonpj) gitlab at gitlab.haskell.org
Tue Jan 23 17:45:16 UTC 2024



Simon Peyton Jones pushed to branch wip/T24251 at Glasgow Haskell Compiler / GHC


Commits:
13faa355 by Simon Peyton Jones at 2024-01-23T17:44:49+00:00
Wibbles

- - - - -


1 changed file:

- compiler/GHC/Core/Opt/Simplify/Iteration.hs


Changes:

=====================================
compiler/GHC/Core/Opt/Simplify/Iteration.hs
=====================================
@@ -2838,18 +2838,21 @@ HOWEVER, there are some serious downsides to this transformation, so
 GHC doesn't do it any longer (#24251):
 
 * Suppose the Simplifier sees
-     case x of y { __DEFAULT ->
+     case x of y* { __DEFAULT ->
      let z = case y of { __DEFAULT -> expr } in
      z+1 }
-  In a single Simplifer pass we may:
-   - Eliminate the outer case because `y` is used strictly, AND
+  The "y*" means "y is used strictly in its scope.  Now we may:
    - Eliminate the inner case becuase `y` is evaluated.
-  Yikes!
+  Now the demand-info on `y` is not right, because `y` is no longer used
+  strictly in its scope.  But it is hard to spot that without doing a new
+  demand analysis.  So there is a danger that we will:
+   - Eliminate the outer case because `y` is used strictly
+  Yikes!  We can't eliminate both!
 
 * It introduces space leaks (#24251).  Consider
       go 0 where go x = x `seq` go (x + 1)
   It it an infinite loop, true, but it should not leak space. Yet if we drop
-  the `seq`, it will.
+  the `seq`, it will.  Another great example is #21741.
 
 * Dropping the outer `case can change the error behaviour.  For example, we might
   transform
@@ -2866,9 +2869,13 @@ some redundant-looking evals.  For example, consider
               True  -> case x of { Nothing -> False; Just z  -> z }
               False -> case x of { Nothing -> True;  Just z  -> z }
 That outer eval will be retained right through to code generation.  But in fact
-that is probably a /good/ thing.  Those inner (case x) expressions will be
-compiled a simple 'if', because the code generator can see that `x` is, at those
-points, evaluated and properly tagged.  If we dropped the outer eval, both the
+that is probably a /good/ thing:
+
+   Key point: those inner (case x) expressions will be compiled a simple 'if',
+   because the code generator can see that `x` is, at those points, evaluated
+   and properly tagged.
+
+If we dropped the outer eval, both the
 inner (case x) expressions would need to do a proper eval, pushing a return
 address, with an info table. See the example in #15631 where, in the
 Description, the (case ys) will be a simple multi-way jump.



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/13faa355b6c66c92fa7dd64261385d99bff1814b

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/13faa355b6c66c92fa7dd64261385d99bff1814b
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20240123/4d15e44d/attachment-0001.html>


More information about the ghc-commits mailing list