[GHC] #12689: DataCon wrappers get in the way of rules

GHC ghc-devs at haskell.org
Tue Oct 11 15:12:38 UTC 2016


#12689: DataCon wrappers get in the way of rules
-------------------------------------+-------------------------------------
           Reporter:  nomeata        |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.0.1
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  None/Unknown
  Unknown/Multiple                   |
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 This is a spin-off of
 https://ghc.haskell.org/trac/ghc/ticket/12618#comment:25:

 Simon writes there:

 Actually this is already a problem today. It's just rendered more
 prominent now that even `(:)` has a wrapper. Consider
 {{{#!hs
 data T = MkT {-# UNPACK #-} !Int

 {-# RULES

 "fT" f MkT = True
 "gT" forall x. g (MkT x) = x
   #-}

 f :: (Int -> T) -> Bool
 {-# NOINLINE f #-}
 f x = True

 g :: T -> Int
 {-# NOINLINE g #-}
 g (MkT x) = x+1
 }}}
 yields
 {{{
 Foo.hs:9:1: warning: [-Winline-rule-shadowing]
     Rule "fT" may never fire because 'Foo.$WMkT' might inline first
     Probable fix: add an INLINE[n] or NOINLINE[n] pragma for 'Foo.$WMkT'

 Foo.hs:10:1: warning: [-Winline-rule-shadowing]
     Rule "gT" may never fire because 'Foo.$WMkT' might inline first
     Probable fix: add an INLINE[n] or NOINLINE[n] pragma for 'Foo.$WMkT'
 }}}
 What to do? If we are to match these rules, we really must delay inlining
 the wrapper for `MkT` (after inlining we get a mess of unboxing etc). So
 either we must allow you to add a `NOINLINE` pragma to `MkT`; or we must
 add one automatically (e.g. `NOINLINE [1]`).

 Delaying all consructor-wrapper inlining to phase 1 is potentially quite
 drastic, because case-of-known-constructor wouldn't happen until the
 wrappers are inlined. Maybe that's ok; I'm not sure. Worth trying I think.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12689>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list