summaryrefslogtreecommitdiff
path: root/compiler/stranal/DmdAnal.hs
diff options
context:
space:
mode:
authorDavid Feuer <david.feuer@gmail.com>2017-03-13 15:18:49 -0400
committerBen Gamari <ben@smart-cactus.org>2017-03-13 15:18:56 -0400
commitdd3b06aa2d44fa160e36097ce90c4574160bd4eb (patch)
treeaf71c83c0c0b203a00801fab0737368aa79ec0ad /compiler/stranal/DmdAnal.hs
parent72ab738caf7539b12c88b7b0b23096d31cc0ab0f (diff)
downloadhaskell-dd3b06aa2d44fa160e36097ce90c4574160bd4eb.tar.gz
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
Diffstat (limited to 'compiler/stranal/DmdAnal.hs')
-rw-r--r--compiler/stranal/DmdAnal.hs12
1 files changed, 8 insertions, 4 deletions
diff --git a/compiler/stranal/DmdAnal.hs b/compiler/stranal/DmdAnal.hs
index 9271eda8c5..25a4f8b912 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