[GHC] #14951: SpecContsr needs two runs when one should suffice

GHC ghc-devs at haskell.org
Wed Mar 21 17:15:54 UTC 2018


#14951: SpecContsr needs two runs when one should suffice
-------------------------------------+-------------------------------------
        Reporter:  nomeata           |                Owner:  (none)
            Type:  task              |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.2.2
      Resolution:                    |             Keywords:  SpecConstr
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:  #14844            |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by sgraf):

 You could thread the `SPEC` value through your RHS. This will require an
 additional `INLINE` binding, unless you want to fix up call sites, too.
 Assuming you loopified `foo`:

 {{{
 foo :: Integer -> (a -> b -> Bool) -> (a,b) -> Bool
 foo = $wfoo SPEC
   where
     $wfoo !_ 0 _ _ = False
     $wfoo !_ f t = l s' t
        where
          l 0 t = False
          l 1 t = case t of (x,y) -> f x y
          l n (x,y) = l (n-1) (x,y)
          s' = large s
 {-# INLINE foo #-}

 bar1 :: Integer -> (a -> b -> Bool) -> a -> b -> Bool
 bar1 s f x y = foo s f (x,y)

 bar2 :: Integer ->  (a -> b -> Bool) -> a -> b -> Bool
 bar2 s f x y = foo (s + 1) f (x,y)
 }}}

 Provided the simplifier inlines `foo` before !SpecConstr runs, this should
 make sure that `$wfoo` will be specialised for its call pattern. This
 would not need !SpecConstr to change at all, I think.

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


More information about the ghc-tickets mailing list