From: simonpj@microsoft.com Date: Wed, 17 Nov 2010 10:05:10 +0000 (+0000) Subject: Make (^) and (^^) INLINABLE X-Git-Url: http://git.megacz.com/?p=ghc-base.git;a=commitdiff_plain;h=f2e36773ae93fa526cc05981e8f928f14bf612c8 Make (^) and (^^) INLINABLE This makes them perform well robustly (e.g. in test perf/should_run/MethSharing) rather than relying on a rather delicate let-floating. See Note [Inlining (^) in Real.lhs --- diff --git a/GHC/Real.lhs b/GHC/Real.lhs index b3316d1..68e3784 100644 --- a/GHC/Real.lhs +++ b/GHC/Real.lhs @@ -424,6 +424,7 @@ odd = not . even Integer -> Integer -> Integer, Integer -> Int -> Integer, Int -> Int -> Int #-} +{-# INLINABLE (^) #-} -- See Note [Inlining (^)] (^) :: (Num a, Integral b) => a -> b -> a x0 ^ y0 | y0 < 0 = error "Negative exponent" | y0 == 0 = 1 @@ -439,8 +440,20 @@ x0 ^ y0 | y0 < 0 = error "Negative exponent" -- | raise a number to an integral power (^^) :: (Fractional a, Integral b) => a -> b -> a +{-# INLINABLE (^^) #-} -- See Note [Inlining (^) x ^^ n = if n >= 0 then x^n else recip (x^(negate n)) +{- Note [Inlining (^) + ~~~~~~~~~~~~~~~~~~~~~ + The INLINABLE pragma allows (^) to be specialised at its call sites. + If it is called repeatedly at the same type, that can make a huge + difference, because of those constants which can be repeatedly + calculated. + + Currently the fromInteger calls are not floated because we get + \d1 d2 x y -> blah + after the gentle round of simplification. -} + ------------------------------------------------------- -- Special power functions for Rational --