Note [caseRules for dataToTag]
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
- Type data declarations GHC.Rename.Module
- DataToTag overview GHC.Tc.Instance.Class
Referenced by 7
- DataToTag overview GHC.Tc.Instance.Class ×2
- GHC.Core.Opt.ConstantFold call site
- Scrutinee Constant Folding GHC.Core.Opt.Simplify.Utils
- Example of case-merging and caseRules GHC.Core.Opt.Simplify.Utils
- GHC.Core.Opt.Simplify.Utils call site
- GHC.Tc.Instance.Class call site