Invalid transformation in simplOptExpr
Prior to 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.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.0.1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |