Note [caseRules for dataToTag]

GHC/Core/Opt/ConstantFold.hs:3589 compiler

See also Note [DataToTag overview] in GHC.Tc.Instance.Class.

We want to transform
  case dataToTagSmall# x of
    DEFAULT -> e1
    1# -> e2
into
  case x of
    DEFAULT -> e1
    (:) _ _ -> e2

(Note the need for some wildcard binders in the 'cons' case.)

This transformation often enables further optimisation via
case-flattening and case-of-known-constructor and can be very
important for code using derived Eq instances.

We can apply this transformation only when we can easily get the
constructors from the type at which dataToTagSmall# is used.  And we
cannot apply this transformation at "type data"-related types without
breaking invariant I1 from Note [Type data declarations] in
GHC.Rename.Module.  That leaves exactly the types satisfying condition
DTT2 from Note [DataToTag overview] in GHC.Tc.Instance.Class.

All of the above applies identically for `dataToTagLarge#`.  And
thanks to wrinkle DTW5, there is no need to worry about large-tag
arguments for `dataToTagSmall#`; those cause undefined behavior anyway.

References 2

Referenced by 7