Closed OlivierSohn closed 6 years ago
I think GHC is clever enough to compile it down to same code. But this patch simplifies compiler job at very least. I'll merge it tomorrow
@Shimuuar In such a case, I always say to myself "let's look at the generated core" and then I do something else :) But in that particular case, even looking at core may be "not enough" as the optimization might happen at a later stage... Oh well...
Actually I expect that fromIntegral
will be rewritten to id
so everything will happen on core level. But I didn't check
I think you're right, it might be due to the 3rd RULE found here ?
{-# RULES
"fromIntegral/Word8->Word32" fromIntegral = \(W8# x#) -> W32# x#
"fromIntegral/Word16->Word32" fromIntegral = \(W16# x#) -> W32# x#
"fromIntegral/Word32->Word32" fromIntegral = id :: Word32 -> Word32
"fromIntegral/Word32->Integer" fromIntegral = toInteger :: Word32 -> Integer
"fromIntegral/a->Word32" fromIntegral = \x -> case fromIntegral x of W# x# -> W32# (narrow32Word# x#)
"fromIntegral/Word32->a" fromIntegral = \(W32# x#) -> fromIntegral (W# x#)
#-}
Yep!
I assume it will be faster this way. I couldn't benchmark it however, as the benchmark didn't compile and I didn't know how to fix the errors (I believe the compile errors are preexistent to this commit, note that I use stack to compile).