[GHC] #13016: SPECIALIZE INLINE doesn't necessarily inline specializations of a recursive function

GHC ghc-devs at haskell.org
Sun May 7 19:55:03 UTC 2017


#13016: SPECIALIZE INLINE doesn't necessarily inline specializations of a recursive
function
-------------------------------------+-------------------------------------
        Reporter:  nfrisby           |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.0.1
      Resolution:                    |             Keywords:  Inlining
Operating System:  Unknown/Multiple  |         Architecture:
 Type of failure:  Runtime           |  Unknown/Multiple
  performance bug                    |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #13014            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by dfeuer):

 Just for the heck of it, I decided to try translating this into class
 style:

 {{{#!hs
 class BangColon e where
   (!:) :: Arr e -> Int -> e

 instance BangColon Int where
   {-# SPECIALISE INLINE (!:) :: Arr Int -> Int -> Int #-}
   ArrInt ba !: i = ba * i
 instance (BangColon a, BangColon b) => BangColon (a, b) where
   {-# SPECIALISE INLINE (!:) :: (BangColon a, BangColon b)
                              => Arr (a, b) -> Int -> (a, b) #-}
   ArrPair a1 a2 !: i = (a1 !: i, a2 !: i)
 }}}

 Written this way, the specializations inline as requested, producing

 {{{#!hs
 Dp.example2 :: Int
 [GblId,
  Caf=NoCafRefs,
  Str=m,
  Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
          WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 20}]
 Dp.example2 = GHC.Types.I# 10#

 -- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0}
 Dp.example1 :: Int
 [GblId,
  Caf=NoCafRefs,
  Str=m,
  Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
          WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 20}]
 Dp.example1 = GHC.Types.I# 15#

 -- RHS size: {terms: 3, types: 2, coercions: 0, joins: 0/0}
 example :: (Int, Int)
 [GblId,
  Caf=NoCafRefs,
  Str=m,
  Unf=Unf{Src=<vanilla>, TopLvl=True, Value=True, ConLike=True,
          WorkFree=True, Expandable=True, Guidance=IF_ARGS [] 10 30}]
 example = (Dp.example2, Dp.example1)
 }}}

 So the problem seems confined to the GADT function case.

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


More information about the ghc-tickets mailing list