[GHC] #13798: Invalid transformation in simplOptExpr
GHC
ghc-devs at haskell.org
Wed Jun 7 16:36:16 UTC 2017
#13798: Invalid transformation in simplOptExpr
-------------------------------------+-------------------------------------
Reporter: simonpj | Owner: (none)
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 8.0.1
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
Prior to
[https://git.haskell.org/ghc.git/commitdiff/1722fa106e10e63160bb2322e2ccb830fd5b9ab3
this commit], `CoreOpt.simple_opt_expr` transforms
{{{
case e of (b :: t1 ~# t2)
DEFAULT -> rhs
==>
rhs
}}}
That was plain wrong when `e` diverges, or calls `error`. Hence the
commit.
But the commit does this
{{{
case Coercible_sc e of (b :: t1 ~# t2)
DEFAULT -> rhs
==>
rhs
}}}
narrowing the scope of the transformation
to when the scrutinee is application of the Coercible superclass selector
{{{
Coercible_sc :: Coercible a b -> (a ~R# b)
}}}
Here's the code from `CoreOpt`:
{{{
| isDeadBinder b
, [(DEFAULT, _, rhs)] <- as
, isCoercionType (varType b)
, (Var fun, _args) <- collectArgs e
, fun `hasKey` coercibleSCSelIdKey
-- without this last check, we get #11230
= go rhs
}}}
But that's bizarrely ad-hoc. And, worse, it is flat-out wrong... what if
`e` diverges?
It's not actually hurting anyone right now, but what we should
really do is use `exprOkForSpeculation`; and teach `exprOkForSpeculation`
how to deal with class-op selectors.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/13798>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list