[commit: ghc] ghc-8.2: Broaden demand analysis IO hack notes (4ff1374)
git at git.haskell.org
git at git.haskell.org
Mon Mar 13 21:44:30 UTC 2017
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-8.2
Link : http://ghc.haskell.org/trac/ghc/changeset/4ff1374074e6fac48512c62f5baf9e1863883a23/ghc
>---------------------------------------------------------------
commit 4ff1374074e6fac48512c62f5baf9e1863883a23
Author: David Feuer <david.feuer at gmail.com>
Date: Mon Mar 13 15:18:49 2017 -0400
Broaden demand analysis IO hack notes
The I/O hack for demand analysis has broader and arguably more
important implications than the note expressed. Broaden it.
[skip ci]
Reviewers: austin, bgamari
Reviewed By: bgamari
Subscribers: carter, rwbarton, thomie
Differential Revision: https://phabricator.haskell.org/D3307
(cherry picked from commit dd3b06aa2d44fa160e36097ce90c4574160bd4eb)
>---------------------------------------------------------------
4ff1374074e6fac48512c62f5baf9e1863883a23
compiler/stranal/DmdAnal.hs | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/compiler/stranal/DmdAnal.hs b/compiler/stranal/DmdAnal.hs
index 9271eda..25a4f8b 100644
--- a/compiler/stranal/DmdAnal.hs
+++ b/compiler/stranal/DmdAnal.hs
@@ -344,10 +344,14 @@ dmdAnalAlt env dmd case_bndr (con,bndrs,rhs)
{- Note [IO hack in the demand analyser]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There's a hack here for I/O operations. Consider
- case foo x s of { (# s, r #) -> y }
-Is this strict in 'y'? Normally yes, but what if 'foo' is an I/O
-operation that simply terminates the program (not in an erroneous way)?
-In that case we should not evaluate 'y' before the call to 'foo'.
+
+ case foo x s of { (# s', r #) -> y }
+
+Is this strict in 'y'? Often not! If foo x s performs some observable action
+(including raising an exception with raiseIO#, modifying a mutable variable, or
+even ending the program normally), then we must not force 'y' (which may fail
+to terminate) until we have performed foo x s.
+
Hackish solution: spot the IO-like situation and add a virtual branch,
as if we had
case foo x s of
More information about the ghc-commits
mailing list