Remove ad-hoc fromIntegral rules
fromIntegral is defined as: {-# NOINLINE [1] fromIntegral #-} fromIntegral :: (Integral a, Num b) => a -> b fromIntegral = fromInteger . toInteger Before this patch, we had a lot of rewrite rules for fromIntegral, to avoid passing through Integer when there is a faster way, e.g.: "fromIntegral/Int->Word" fromIntegral = \(I# x#) -> W# (int2Word# x#) "fromIntegral/Word->Int" fromIntegral = \(W# x#) -> I# (word2Int# x#) "fromIntegral/Word->Word" fromIntegral = id :: Word -> Word Since we have added sized types and primops (Word8#, Int16#, etc.) and Natural, this approach didn't really scale as there is a combinatorial explosion of types. In addition, we really want these conversions to be optimized for all these types and in every case (not only when fromIntegral is explicitly used). This patch removes all those ad-hoc fromIntegral rules. Instead we rely on inlining and built-in constant-folding rules. There are not too many native conversions between Integer/Natural and fixed size types, so we can handle them all explicitly. Foreign.C.Types was using rules to ensure that fromIntegral rules "sees" through the newtype wrappers,e.g.: {-# RULES "fromIntegral/a->CSize" fromIntegral = \x -> CSize (fromIntegral x) "fromIntegral/CSize->a" fromIntegral = \(CSize x) -> fromIntegral x #-} But they aren't necessary because coercions due to newtype deriving are pushed out of the way. So this patch removes these rules (as fromIntegral is now inlined, they won't match anymore anyway). Summary: * INLINE `fromIntegral` * Add some missing constant-folding rules * Remove every fromIntegral ad-hoc rules (fix #19907) Fix #20062 (missing fromIntegral rules for sized primitives) Performance: - T12545 wiggles (tracked by #19414) Metric Decrease: T12545 T10359 Metric Increase: T12545
parent
b128a880
Pipeline #39405 canceled
Stage: tool-lint
Stage: quick-build
Stage: full-build
Stage: packaging
Stage: testing
Stage: deploy
Showing
- compiler/GHC/Core/Opt/ConstantFold.hs 230 additions, 59 deletionscompiler/GHC/Core/Opt/ConstantFold.hs
- libraries/base/Foreign/C/Types.hs 0 additions, 46 deletionslibraries/base/Foreign/C/Types.hs
- libraries/base/GHC/Float.hs 0 additions, 4 deletionslibraries/base/GHC/Float.hs
- libraries/base/GHC/Int.hs 0 additions, 69 deletionslibraries/base/GHC/Int.hs
- libraries/base/GHC/Num.hs 7 additions, 8 deletionslibraries/base/GHC/Num.hs
- libraries/base/GHC/Real.hs 7 additions, 48 deletionslibraries/base/GHC/Real.hs
- libraries/base/GHC/Word.hs 2 additions, 79 deletionslibraries/base/GHC/Word.hs
- testsuite/tests/numeric/should_compile/T20062.hs 1008 additions, 0 deletionstestsuite/tests/numeric/should_compile/T20062.hs
- testsuite/tests/numeric/should_compile/all.T 1 addition, 0 deletionstestsuite/tests/numeric/should_compile/all.T
Loading