Skip to content

-Winline-rule-shadowing: Different for single and multi method classes?

Playing around with this file

module MethodRules where

class C1 a where
  m1 :: Maybe a

class C2 a where
  m2 :: Maybe a
  m2' :: Maybe a

foo :: Maybe a
foo = Nothing

{-# RULES "m1" m1 = foo #-}
{-# RULES "m2" m2 = foo #-}

I get

ghc -O2 -Winline-rule-shadowing MethodRules.hs  -ddump-rules -fforce-recomp 
[1 of 1] Compiling MethodRules      ( MethodRules.hs, MethodRules.o )

MethodRules.hs:13:11: warning: [-Winline-rule-shadowing]
    Rule "m1" may never fire because ‘m1’ might inline first
    Probable fix: add an INLINE[n] or NOINLINE[n] pragma for ‘m1’
   |
13 | {-# RULES "m1" m1 = foo #-}
   |           ^^^^^^^^^^^^^

==================== Tidy Core rules ====================
"m1" forall (@ a) ($dC1 :: C1 a). m1 @ a $dC1 = foo @ a
"m2" forall (@ a) ($dC2 :: C2 a). m2 @ a $dC2 = foo @ a

I find it odd that the inline-rule-shadowing warning behaves so different depending on whether the class is a single-method class or not.

Furthermore, I found no way to avoid the warning: I can’t add an {-# NOINLINE #-} pragma to a class method (see #10595). Worse, in terms of developer confusion, if the method happens to have a default implementation, I can add the {-# NOININE #-} pragma, but it would apply to the default method (I think), and will not prevent this warning.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information