Improve exprOkForSpeculation for classops
This patch fixes #22745 (closed) and #15205 (closed), which are about GHC's
failure to discard unnecessary superclass selections that
yield coercions. See
GHC.Core.Utils Note [exprOkForSpeculation and type classes]
The main changes are:
-
exprOkForSpeculation
has a new (very simple) case forClassOpId
-
ClassOpId
has a field that says if the return type is a "terminating type"; i.e. unlifted or non-newtype dictionary type. -
Define
GHC.Type.isTerminatingType
to identify these types. -
Write new
Note [NON-BOTTOM_DICTS invariant]
in GHC.Core, and refer to it