[project @ 2003-06-23 11:46:40 by simonpj]
authorsimonpj <unknown>
Mon, 23 Jun 2003 11:46:40 +0000 (11:46 +0000)
committersimonpj <unknown>
Mon, 23 Jun 2003 11:46:40 +0000 (11:46 +0000)
commite7fb057f50a0d78291f64cc6ccf488f90982bc83
tree9e98e81ae966b73d9475e7eec3729db9598628b2
parent0c33b675b26b627963c7a2ac00d6dd4c551fbcac
[project @ 2003-06-23 11:46:40 by simonpj]
------------------------------------------------------
Make the strictness analyser more conservative for I/O
------------------------------------------------------

Consider
do { let len = <expensive> ;
   ; when (...) (exitWith ExitSuccess)
   ; print len }

Is it safe to evaluate <expensive> before doing the 'when'?  Remember,
<expensive> might raise an exception etc as well.

Normal strictness analysis answer: yes, because either the when... diverges
or raises an exception, or the print will happen.

Correct I/O answer: no, because it's perfectly OK to terminate the program
successfully.  And don't say the 'len' could be pushed down, because (a) sometimes
it can't and (b) sometimes the compiler might float it out.

This commit adds a hack to the demand analyser, so that it treats a case that
looks like I/O (unboxed pair, real-world as first bindre) specially, by lub'ing
the returned strictness type with TopType.  A bit like adding a dummy never-taken
branch.  This seems a bit hack-oid, but it's quick and it works.  Not clear
how to do it 'right', either.

Test is in stranal/should_run/strun003.
ghc/compiler/stranal/DmdAnal.lhs