Use explicit Word32/Int32 in place of Int in the on-disk .hi file
authorSimon Marlow <marlowsd@gmail.com>
Fri, 21 Aug 2009 15:50:28 +0000 (15:50 +0000)
committerSimon Marlow <marlowsd@gmail.com>
Fri, 21 Aug 2009 15:50:28 +0000 (15:50 +0000)
For: FastStrings, Names, and Bin values.  This makes .hi files smaller
on 64-bit platforms, while also making the format a bit more robust.

compiler/basicTypes/Name.lhs
compiler/iface/BinIface.hs
compiler/utils/Binary.hs

index 9f23f96..cb6785a 100644 (file)
@@ -83,6 +83,7 @@ import FastString
 import Outputable
 
 import Data.Array
+import Data.Word        ( Word32 )
 \end{code}
 
 %************************************************************************
@@ -368,7 +369,7 @@ instance Binary Name where
 
    get bh = do
         i <- get bh
-        return $! (ud_symtab (getUserData bh) ! i)
+        return $! (ud_symtab (getUserData bh) ! fromIntegral (i::Word32))
 \end{code}
 
 %************************************************************************
index 864bbde..3cfb43d 100644 (file)
@@ -287,13 +287,13 @@ putName BinSymbolTable{
   = do
     symtab_map <- readIORef symtab_map_ref
     case lookupUFM symtab_map name of
-      Just (off,_) -> put_ bh off
+      Just (off,_) -> put_ bh (fromIntegral off :: Word32)
       Nothing -> do
          off <- readFastMutInt symtab_next
          writeFastMutInt symtab_next (off+1)
          writeIORef symtab_map_ref
              $! addToUFM symtab_map name (off,name)
-         put_ bh off          
+         put_ bh (fromIntegral off :: Word32)
 
 
 data BinSymbolTable = BinSymbolTable {
@@ -310,10 +310,10 @@ putFastString BinDictionary { bin_dict_next = j_r,
     out <- readIORef out_r
     let uniq = getUnique f
     case lookupUFM out uniq of
-        Just (j, _)  -> put_ bh j
+        Just (j, _)  -> put_ bh (fromIntegral j :: Word32)
         Nothing -> do
            j <- readFastMutInt j_r
-           put_ bh j
+           put_ bh (fromIntegral j :: Word32)
            writeFastMutInt j_r (j + 1)
            writeIORef out_r $! addToUFM out uniq (j, f)
 
index e633f35..249480a 100644 (file)
@@ -551,8 +551,8 @@ instance (Integral a, Binary a) => Binary (Ratio a) where
 #endif
 
 instance Binary (Bin a) where
-  put_ bh (BinPtr i) = put_ bh i
-  get bh = do i <- get bh; return (BinPtr i)
+  put_ bh (BinPtr i) = put_ bh (fromIntegral i :: Int32)
+  get bh = do i <- get bh; return (BinPtr (fromIntegral (i :: Int32)))
 
 -- -----------------------------------------------------------------------------
 -- Instances for Data.Typeable stuff
@@ -707,7 +707,7 @@ instance Binary FastString where
 
   get bh = do
         j <- get bh
-        return $! (ud_dict (getUserData bh) ! j)
+        return $! (ud_dict (getUserData bh) ! (fromIntegral (j :: Word32)))
 
 -- Here to avoid loop