diff options
author | Andreas Klebinger <klebinger.andreas@gmx.at> | 2021-01-20 16:24:14 +0100 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-02-27 08:00:08 -0500 |
commit | 60bf4d7ca59e333db6349948b8140651d0190004 (patch) | |
tree | 706809fce670feb8b5799bebbf95c379593ec2f3 /libraries | |
parent | 966a768e9b99e72c9d98a1c971427044888d6de9 (diff) | |
download | haskell-60bf4d7ca59e333db6349948b8140651d0190004.tar.gz |
Fix typechecking time bug for large rationals (#15646)
When desugaring large overloaded literals we now avoid
computing the `Rational` value. Instead prefering to
store the significant and exponent as given where
reasonable and possible.
See Note [FractionalLit representation] for details.
Diffstat (limited to 'libraries')
-rw-r--r-- | libraries/base/GHC/Real.hs | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libraries/base/GHC/Real.hs b/libraries/base/GHC/Real.hs index 4329bb7355..696cb8a52e 100644 --- a/libraries/base/GHC/Real.hs +++ b/libraries/base/GHC/Real.hs @@ -817,3 +817,22 @@ integralEnumFromTo n m = map fromInteger [toInteger n .. toInteger m] integralEnumFromThenTo :: Integral a => a -> a -> a -> [a] integralEnumFromThenTo n1 n2 m = map fromInteger [toInteger n1, toInteger n2 .. toInteger m] + +-- mkRational related code + +data FractionalExponentBase + = Base2 + | Base10 + deriving (Show) + +mkRationalBase2 :: Rational -> Integer -> Rational +mkRationalBase2 r e = mkRationalWithExponentBase r e Base2 + +mkRationalBase10 :: Rational -> Integer -> Rational +mkRationalBase10 r e = mkRationalWithExponentBase r e Base10 + +mkRationalWithExponentBase :: Rational -> Integer + -> FractionalExponentBase -> Rational +mkRationalWithExponentBase r e feb = r * (eb ^^ e) + -- See Note [fractional exponent bases] for why only these bases. + where eb = case feb of Base2 -> 2 ; Base10 -> 10 |