[GHC] #7411: Exceptions are optimized away in certain situations
GHC
ghc-devs at haskell.org
Tue May 8 20:52:34 UTC 2018
#7411: Exceptions are optimized away in certain situations
-------------------------------------+-------------------------------------
Reporter: SimonHengel | Owner: tdammers
Type: bug | Status: new
Priority: high | Milestone: 8.6.1
Component: Compiler | Version: 7.6.1
Resolution: | Keywords: seq, deepseq,
| evaluate, exceptions
Operating System: Linux | Architecture: x86_64
| (amd64)
Type of failure: Incorrect result | Test Case:
at runtime | simplCore/should_fail/T7411
Blocked By: | Blocking:
Related Tickets: #5129 | Differential Rev(s):
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by dfeuer):
I think the `-fno-state-hack` is almost certainly a clue, although I'm not
exactly sure how it ends up relating in that specific example. What I
''suspect'' is happening (without actually tracing simplification) is
roughly this:
{{{#!hs
evaluate (undefined `seq` return ())
-- ===> inline
IO $ \s -> seq# (undefined `seq` IO (\s' -> (# s', () #))) s
-- ===> simplify the coercions for my sanity
IO $ \s -> seq# (IO $ undefined `seq` \s' -> (# s', () #)) s
-- ===> This is where I suspect things go sideways. I believe we generally
-- assume that it's okay to eta-expand IO things.
IO $ \s -> seq# (IO $ \s'' -> (undefined `seq` (\s' -> (# s', () #))) s'')
s
}}}
We've effectively turned a bottom with an `IO` type into a non-bottom `IO`
value that only ''returns'' a bottom. Then the `seq#` ends up going away:
{{{#!hs
-- ===> beta reduce past seq
IO $ \s -> seq# (IO $ \s'' -> undefined `seq` (# s'', () #)) s
-- ===> PrelRules.seqRule says we can eliminate seq# for WHNF things
IO $ \s -> (# s, IO $ \s'' -> undefined `seq` (# s'', () #))
}}}
I imagine the behavior is a bit fragile because it depends on GHC not
recognizing that the undefined value is in fact undefined, or at least not
recognizing it too early. I suspect the solution is likely to make
`-fpedantic-bottoms` go a little further than it currently does, although
I don't know enough to say just what.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/7411#comment:25>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list