summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Graf <sebastian.graf@kit.edu>2020-01-13 11:07:28 +0100
committerBen Gamari <ben@smart-cactus.org>2020-02-06 17:22:56 -0500
commit1942be2e7dbb358bd4678b41f98d871f258d7b88 (patch)
tree41ebac77cf8a1aecd0281bf3a432091e8c374a4d
parent28a52b9aa167d8bc344713e479412b9cc36c1e64 (diff)
downloadhaskell-1942be2e7dbb358bd4678b41f98d871f258d7b88.tar.gz
Revert "`exprOkForSpeculation` for Note [IO hack in the demand analyser]"
This reverts commit ce64b397777408731c6dd3f5c55ea8415f9f565b on the grounds of the regression it would introduce in a couple of packages. Fixes #17653. Also undoes a slight metric increase in #13701 introduced by that commit that we didn't see prior to !1983. Metric Decrease: T13701 (cherry picked from commit 071a58c673054d170320bdc8ef222c0f67d22497)
-rw-r--r--compiler/stranal/DmdAnal.hs22
1 files changed, 11 insertions, 11 deletions
diff --git a/compiler/stranal/DmdAnal.hs b/compiler/stranal/DmdAnal.hs
index 86806bab0a..babcd68341 100644
--- a/compiler/stranal/DmdAnal.hs
+++ b/compiler/stranal/DmdAnal.hs
@@ -333,7 +333,10 @@ io_hack_reqd scrut con bndrs
| (bndr:_) <- bndrs
, con == tupleDataCon Unboxed 2
, idType bndr `eqType` realWorldStatePrimTy
- = not (exprOkForSpeculation scrut)
+ , (fun, _) <- collectArgs scrut
+ = case fun of
+ Var f -> not (isPrimOpId f)
+ _ -> True
| otherwise
= False
@@ -384,18 +387,15 @@ getMaskingState# is not going to diverge or throw an exception! This
situation actually arises in GHC.IO.Handle.Internals.wantReadableHandle
(on an MVar not an Int), and made a material difference.
-So if the scrutinee is ok-for-speculation, we *don't* apply the state hack,
-because we are free to push evaluation of the scrutinee after evaluation of
-expressions from the (single) case alternative.
-
-A few examples for different scrutinees:
+So if the scrutinee is a primop call, we *don't* apply the
+state hack:
- If it is a simple, terminating one like getMaskingState,
- applying the hack would be over-conservative.
- - If the primop is raise# then it returns bottom (so not ok-for-speculation),
- but the result from the case alternatives are discarded anyway.
+ applying the hack is over-conservative.
+ - If the primop is raise# then it returns bottom, so
+ the case alternatives are already discarded.
- If the primop can raise a non-IO exception, like
- divide by zero (so not ok-for-speculation), then we are also bottoming out
- anyway and don't mind evaluating 'x' first.
+ divide by zero or seg-fault (eg writing an array
+ out of bounds) then we don't mind evaluating 'x' first.
Note [Demand on the scrutinee of a product case]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~