Should GHC stabilize unfoldings for small interesting RHSs
Consider this (not very useful) simple example:
module A where
{-# NOINLINE foo #-}
foo :: Enum a => a -> a
foo x = x
{-# RULES
"mySucc" forall . foo (42 :: Int) = 42
#-}
module B where
bar x = foo x
Should users expect bar 42
to trigger the rule? Currently it generally doesn't. This bit me in #20359 (closed). Which also has a bit of explaination why it doesn't.
We could in theory try to make rhs unfoldings stable if they are small enough. But that might cause a lot of churn in the simplifier. We could limit it to small unfoldings which mention a binding with associated rules. But what if the rules are not in scope at the definition site?
For some reason I had assumed we generally make small rhss available as stable (unoptimized) unfoldings by default. This isn't the case however. We optimize the binding as usual and only towards the end of simplification we make a stable unfolding based on the optimized RHS.
There are good reasons for this. But if I was initially confused about this point I imagine it doesn't hurt to make a ticket about the state of things.