Skip to content

GitLab

  • Menu
Projects Groups Snippets
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
  • Sign in / Register
  • GHC GHC
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 4,859
    • Issues 4,859
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 454
    • Merge requests 454
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Glasgow Haskell Compiler
  • GHCGHC
  • Issues
  • #20535
Closed
Open
Created Oct 20, 2021 by Joachim Breitner@nomeataDeveloper

-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
Assignee
Assign to
Time tracking