Improving the Int/Word story inside GHC

Simon Marlow marlowsd at
Thu Aug 7 20:56:33 UTC 2014

On 07/08/14 16:01, Johan Tibell wrote:
> On Thu, Aug 7, 2014 at 4:36 PM, Simon Marlow <marlowsd at> wrote:
>> I think doing the comparison with Integer is the right fix.  Relying on Word
>> being big enough for these things is technically wrong because we might be
>> cross-compiling from a smaller word size.
> That sounds like an easier fix and I will try that. Unfortunately
> working with Integers means lots of our convenience functions, such as
> wordsToBytes, go out the window, as the all work on Byte/WordOff.
> Here's an example that now gets more annoying:
>      shouldInlinePrimOp dflags NewArrayOp [(CmmLit (CmmInt n _)), init]
>        | wordsToBytes dflags (fromInteger n) <= maxInlineAllocSize dflags =

Maybe wordsToBytes should be overloaded on Integral (with specialisations).


> Most of our array primops are likely* still wrong, as the code that
> generates them uses Int everywhere. Still also sounds like a problem
> for cross-compiling.
> * In some cases we might be lucky and the Int is never introspected
> any we just look at the bits (i.e. pretend it's a Word) when we
> generate code.

More information about the ghc-devs mailing list