[commit: ghc] wip/T11731: Add a final demand analyzer run right before TidyCore (5932738)

git at git.haskell.org git at git.haskell.org
Thu Mar 31 14:36:23 UTC 2016


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

On branch  : wip/T11731
Link       : http://ghc.haskell.org/trac/ghc/changeset/593273810213a6a1b1941d4d00f815e523bfcd99/ghc

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

commit 593273810213a6a1b1941d4d00f815e523bfcd99
Author: Joachim Breitner <mail at joachim-breitner.de>
Date:   Thu Mar 31 10:18:15 2016 +0200

    Add a final demand analyzer run right before TidyCore
    
    in order to have precise used-once information in the exported
    strictness signatures, as well as precise used-once information on
    thunks. This avoids the bad effects of #11731.


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

593273810213a6a1b1941d4d00f815e523bfcd99
 compiler/simplCore/SimplCore.hs |  5 +++++
 compiler/stranal/DmdAnal.hs     | 28 ++++++++++++++++++++++++++++
 2 files changed, 33 insertions(+)

diff --git a/compiler/simplCore/SimplCore.hs b/compiler/simplCore/SimplCore.hs
index 98bcf2a..1ff0cee 100644
--- a/compiler/simplCore/SimplCore.hs
+++ b/compiler/simplCore/SimplCore.hs
@@ -319,6 +319,11 @@ getCoreToDo dflags
             [simpl_phase 0 ["post-late-ww"] max_iter]
           ),
 
+        -- Final run of the demand_analyser, ensures that one-shot thunks are
+        -- really really one-shot thunks. Only needed if the demand analyser
+        -- has run at all. See Note [Final Demand Analyser run] in DmdAnal
+        runWhen (strictness || late_dmd_anal) CoreDoStrictness,
+
         maybe_rule_check (Phase 0)
      ]
 
diff --git a/compiler/stranal/DmdAnal.hs b/compiler/stranal/DmdAnal.hs
index 20f65d5..4d3fd09 100644
--- a/compiler/stranal/DmdAnal.hs
+++ b/compiler/stranal/DmdAnal.hs
@@ -1331,4 +1331,32 @@ of the Id, and start from "bottom".  Nowadays the Id can have a current
 strictness, because interface files record strictness for nested bindings.
 To know when we are in the first iteration, we look at the ae_virgin
 field of the AnalEnv.
+
+
+Note [Final Demand Analyser run]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Some of the information that the demand analyser determines is not always
+preserved by the simplifier, for example, the simplifier will happily rewrite
+  \y [Demand=1*U] let x = y in x + x
+to
+  \y [Demand=1*U] y + y
+which is quite a lie.
+
+The once-used information is (currently) only used by the code generator, though. So we
+ * do not bother keeping this information up-to-date in the simplifier, or
+   removing it after the demand analyser is done (keeping in mind not to
+   critically rely on this information in, say, the simplifier).
+   It should still be fine to use this as in heuristics, e.g. when deciding to
+   inline things, as the data will usually be correct.
+ * Just before TidyCore, we add a pass of the demand analyse, without
+   subsequent worker/wrapper and simplifier, right before TidyCore.
+   This way, correct information  finds its way into the module interface
+   (strictness signatures!) and the code generator (single-entry thunks!)
+
+Note that the single-call information (C1(..)) can be relied upon, as the
+simplifier tends to be very careful about not duplicating actual function
+calls.
+
+Also see #11731.
 -}



More information about the ghc-commits mailing list