Improving the Int/Word story inside GHC
marlowsd at gmail.com
Thu Aug 7 14:36:27 UTC 2014
On 07/08/2014 12:10, Johan Tibell wrote:
> Inside GHC we mostly use Int instead of Word, even when we want to
> represent non-negative values, such as sizes of things or indices into
> things. This is now causing some grief in
> https://ghc.haskell.org/trac/ghc/ticket/9416, where an allocation
> boundary case test fails with a segfault because a n < m Int comparison
> I tried to fix the issue by changing the type of maxInlineAllocSize,
> which is used on one side of the above comparison, to Word. However,
> that unravels a bunch of other issues, such as wordsToBytes, ByteOff,
> etc are all Int-valued quantities.
> I could perhaps work around these problems by judicious use of
> fromIntegral in StgCmmPrim, but I'm a bit unhappy about it because it 1)
> makes the code uglier and 2) needs to be done in quite a few places.
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.
More information about the ghc-devs