[GHC] #16122: `round :: Double -> Int64` much slower than `fromIntegral @Int @Int64 . round`

GHC ghc-devs at haskell.org
Fri Jan 4 09:25:29 UTC 2019


#16122: `round :: Double -> Int64` much slower than `fromIntegral @Int @Int64 .
round`
-------------------------------------+-------------------------------------
        Reporter:  Fuuzetsu          |                Owner:  (none)
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.6.3
      Resolution:                    |             Keywords:
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by simonpj):

 Here is what is happening

 * There is a built-in rule for `round` that rewrites `round (RFDict _ _ r
 _ _) = r`; that is, `round` applied to a suitable dictionary just selects
 the method.

 * Currently, built-in rules are always active; they can't be delayed to a
 later phase. This could be changed relatively easily, but that's the way
 it is right now.

 * Rules are applied to the RHS of other rules, if the phases allow; this
 seems reasonable. After all, that's what will happen whenever the rule is
 applied.

 * In particular, the built-in rule is applied to the RHS of the rule in
 `GHC.Int`, as comment:3 says.

 * I think the reason things go wrong is that in the RHS of hte rule in
 `GHC.Int` you really want to apply the rule `"round/Double->Int"` in
 `GHC.Float`, but perhaps it is not imported by `GHC.Int`?

 Anyway, probably the best solution here is to rewrite the rule in
 `GHC.Int` to
 {{{
 "round/Double->Int64"
     round    = (fromIntegral :: Int -> Int64) . GHC.Float.roundDoubleInt
 }}}
 (And maybe the same for `fromIntegral`?)

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


More information about the ghc-tickets mailing list