summaryrefslogtreecommitdiff
path: root/compiler/utils/FastMutInt.hs
diff options
context:
space:
mode:
authorSergei Trofimovich <slyfox@gentoo.org>2017-04-02 16:12:18 +0100
committerSergei Trofimovich <slyfox@gentoo.org>2017-04-02 16:12:28 +0100
commitd89b0471888b15844b8bbf68159fe50830be8b24 (patch)
treed88c846b1e8b0f99fb869bef8624b2d388323c96 /compiler/utils/FastMutInt.hs
parent03e34256e2cba964adf6dcdb1682618f26400b3a (diff)
downloadhaskell-d89b0471888b15844b8bbf68159fe50830be8b24.tar.gz
FastMutInt: fix Int and Ptr sizes when crosscompiling
Similar to https://ghc.haskell.org/trac/ghc/ticket/13491 https://phabricator.haskell.org/D3122 SIZEOF_HSINT and SIZEOF_VOID_P are sizes of target platform. These values are usually not correct when stage1 is built. It means the code ```haskell newFastMutInt = IO $ \s -> case newByteArray# size s of { (# s, arr #) -> (# s, FastMutInt arr #) } where !(I# size) = SIZEOF_HSINT ``` would try to allocate only 4 bytes on 64-bit-host targeting 32-bit system. It does not matter in practice as newByteArray# implementation rounds up passed value to host's word size. But one day it might not. To prevent this class of problems in compiler/ directory 'MachDeps.h' contents is hidden when ghc-stage1 (-DSTAGE=1) is built. Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org> Reviewers: austin, rwbarton, simonmar, bgamari Reviewed By: bgamari Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D3405
Diffstat (limited to 'compiler/utils/FastMutInt.hs')
-rw-r--r--compiler/utils/FastMutInt.hs14
1 files changed, 5 insertions, 9 deletions
diff --git a/compiler/utils/FastMutInt.hs b/compiler/utils/FastMutInt.hs
index 4cde1216ed..2a6e7b83aa 100644
--- a/compiler/utils/FastMutInt.hs
+++ b/compiler/utils/FastMutInt.hs
@@ -1,4 +1,4 @@
-{-# LANGUAGE CPP, BangPatterns, MagicHash, UnboxedTuples #-}
+{-# LANGUAGE BangPatterns, MagicHash, UnboxedTuples #-}
{-# OPTIONS_GHC -O #-}
-- We always optimise this, otherwise performance of a non-optimised
-- compiler is severely affected
@@ -15,12 +15,7 @@ module FastMutInt(
readFastMutPtr, writeFastMutPtr
) where
-
-#include "../includes/MachDeps.h"
-#ifndef SIZEOF_HSINT
-#define SIZEOF_HSINT INT_SIZE_IN_BYTES
-#endif
-
+import Data.Bits
import GHC.Base
import GHC.Ptr
@@ -37,7 +32,7 @@ data FastMutInt = FastMutInt (MutableByteArray# RealWorld)
newFastMutInt = IO $ \s ->
case newByteArray# size s of { (# s, arr #) ->
(# s, FastMutInt arr #) }
- where !(I# size) = SIZEOF_HSINT
+ where !(I# size) = finiteBitSize (0 :: Int)
readFastMutInt (FastMutInt arr) = IO $ \s ->
case readIntArray# arr 0# s of { (# s, i #) ->
@@ -52,7 +47,8 @@ data FastMutPtr = FastMutPtr (MutableByteArray# RealWorld)
newFastMutPtr = IO $ \s ->
case newByteArray# size s of { (# s, arr #) ->
(# s, FastMutPtr arr #) }
- where !(I# size) = SIZEOF_VOID_P
+ -- GHC assumes 'sizeof (Int) == sizeof (Ptr a)'
+ where !(I# size) = finiteBitSize (0 :: Int)
readFastMutPtr (FastMutPtr arr) = IO $ \s ->
case readAddrArray# arr 0# s of { (# s, i #) ->