Opened 7 years ago

Closed 7 years ago

#5973 closed bug (invalid)

Rewrite rule not firing for typeclass

Reported by: SamAnklesaria Owned by: SamAnklesaria
Priority: normal Milestone:
Component: Compiler Version: 7.4.1
Keywords: Cc: pho@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

The following rewrite rule fires for a normal function, but fails to fire as the method of a typeclass.

{-# OPTIONS_GHC -O -ddump-rule-firings #-}
module RewriteProblems where

{-# RULES
"rewrite/class"    forall a. id1 (id1 a) = RDUnit
"rewrite/static"   forall a. id1' (id1' a) = RDUnit
   #-}

class Ider a where
    id1 :: a -> a

data RewriteD = RDUnit

instance Ider RewriteD where
    {-# INLINE[1] id1 #-}
    id1 a = RDUnit

classTest :: RewriteD
classTest = id1 (id1 RDUnit)

staticTest :: RewriteD
staticTest = id1' (id1' RDUnit)

{-# INLINE[1] id1' #-}
id1' :: RewriteD -> RewriteD
id1' a = RDUnit

Change History (4)

comment:1 Changed 7 years ago by SamAnklesaria

Owner: set to SamAnklesaria

comment:2 Changed 7 years ago by PHO

Cc: pho@… added

comment:3 Changed 7 years ago by michalt

Thanks for reporting! However, I can't reproduce this. For HEAD I get:

> ~/dev/ghc-clean/inplace/bin/ghc-stage2 -rtsopts Test.hs
[1 of 1] Compiling RewriteProblems  ( Test.hs, Test.o )
Rule fired: rewrite/static
Rule fired: rewrite/class

and for GHC 7.4.1:

> ghc -rtsopts Test.hs
[1 of 1] Compiling RewriteProblems  ( Test.hs, Test.o )
Rule fired: rewrite/static
Rule fired: rewrite/class

So both rules fire. Have you tested with GHC 7.4 or HEAD?

comment:4 Changed 7 years ago by SamAnklesaria

Resolution: invalid
Status: newclosed

I had only tested with a prior version of GHC (7.0.4). With 7.4, as you demonstrate, the rules fire.

Note: See TracTickets for help on using tickets.