Skip to content
Snippets Groups Projects
Commit 4ff13740 authored by David Feuer's avatar David Feuer Committed by Ben Gamari
Browse files

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 dd3b06aa)
parent 820b88c2
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment