Remove code that isn't used now that we assume that GHC >= 6.4
[ghc-hetmet.git] / compiler / utils / FastString.lhs
index 2448f16..ac79b5b 100644 (file)
@@ -5,13 +5,13 @@
 {-
 FastString:     A compact, hash-consed, representation of character strings.
                 Comparison is O(1), and you can get a Unique from them.
 {-
 FastString:     A compact, hash-consed, representation of character strings.
                 Comparison is O(1), and you can get a Unique from them.
-                Generated by the FSLIT macro
+                Generated by fsLit
                 Turn into SDoc with Outputable.ftext
 
 LitString:      Just a wrapper for the Addr# of a C string (Ptr CChar).
                 Practically no operations
                 Outputing them is fast
                 Turn into SDoc with Outputable.ftext
 
 LitString:      Just a wrapper for the Addr# of a C string (Ptr CChar).
                 Practically no operations
                 Outputing them is fast
-                Generated by the SLIT macro
+                Generated by sLit
                 Turn into SDoc with Outputable.ptext
 
 Use LitString unless you want the facilities of FastString
                 Turn into SDoc with Outputable.ptext
 
 Use LitString unless you want the facilities of FastString
@@ -62,18 +62,17 @@ module FastString
         LitString,
 #if defined(__GLASGOW_HASKELL__)
         mkLitString#,
         LitString,
 #if defined(__GLASGOW_HASKELL__)
         mkLitString#,
-#else
-        mkLitString,
 #endif
 #endif
+        mkLitString,
         unpackLitString,
         strLength,
 
         unpackLitString,
         strLength,
 
-        ptrStrLength
+        ptrStrLength,
+
+        sLit,
+        fsLit,
        ) where
 
        ) where
 
--- This #define suppresses the "import FastString" that
--- HsVersions otherwise produces
-#define COMPILING_FAST_STRING
 #include "HsVersions.h"
 
 import Encoding
 #include "HsVersions.h"
 
 import Encoding
@@ -88,12 +87,13 @@ import System.IO
 import System.IO.Unsafe ( unsafePerformIO )
 import Data.IORef       ( IORef, newIORef, readIORef, writeIORef )
 import Data.Maybe       ( isJust )
 import System.IO.Unsafe ( unsafePerformIO )
 import Data.IORef       ( IORef, newIORef, readIORef, writeIORef )
 import Data.Maybe       ( isJust )
-#if !defined(__GLASGOW_HASKELL__)
 import Data.Char        ( ord )
 import Data.Char        ( ord )
-#endif
 
 import GHC.IOBase       ( IO(..) )
 import GHC.Ptr          ( Ptr(..) )
 
 import GHC.IOBase       ( IO(..) )
 import GHC.Ptr          ( Ptr(..) )
+#if defined(__GLASGOW_HASKELL__)
+import GHC.Base         ( unpackCString# )
+#endif
 
 #define hASH_TBL_SIZE          4091
 #define hASH_TBL_SIZE_UNBOXED  4091#
 
 #define hASH_TBL_SIZE          4091
 #define hASH_TBL_SIZE_UNBOXED  4091#
@@ -503,7 +503,7 @@ type LitString = Ptr Word8
 #if defined(__GLASGOW_HASKELL__)
 mkLitString# :: Addr# -> LitString
 mkLitString# a# = Ptr a#
 #if defined(__GLASGOW_HASKELL__)
 mkLitString# :: Addr# -> LitString
 mkLitString# a# = Ptr a#
-#else
+#endif
 --can/should we use FastTypes here?
 --Is this likely to be memory-preserving if only used on constant strings?
 --should we inline it? If lucky, that would make a CAF that wouldn't
 --can/should we use FastTypes here?
 --Is this likely to be memory-preserving if only used on constant strings?
 --should we inline it? If lucky, that would make a CAF that wouldn't
@@ -522,10 +522,12 @@ mkLitString s =
      loop n (c:cs) = do
         pokeByteOff p n (fromIntegral (ord c) :: Word8)
         loop (1+n) cs
      loop n (c:cs) = do
         pokeByteOff p n (fromIntegral (ord c) :: Word8)
         loop (1+n) cs
+     -- XXX GHC isn't smart enough to know that we have already covered
+     -- this case.
+     loop _ [] = panic "mkLitString"
    loop 0 s
    return p
  )
    loop 0 s
    return p
  )
-#endif
 
 unpackLitString :: LitString -> String
 unpackLitString p_ = case pUnbox p_ of
 
 unpackLitString :: LitString -> String
 unpackLitString p_ = case pUnbox p_ of
@@ -571,7 +573,16 @@ pokeCAString ptr str =
   in
   go str 0
 
   in
   go str 0
 
-#if defined(__GLASGOW_HASKELL__) && __GLASGOW_HASKELL__ <= 602
-peekCAStringLen = peekCStringLen
-#endif
+{-# NOINLINE sLit #-}
+sLit :: String -> LitString
+sLit x  = mkLitString x
+
+{-# NOINLINE fsLit #-}
+fsLit :: String -> FastString
+fsLit x = mkFastString x
+
+{-# RULES "slit"
+    forall x . sLit  (unpackCString# x) = mkLitString#  x #-}
+{-# RULES "fslit"
+    forall x . fsLit (unpackCString# x) = mkFastString# x #-}
 \end{code}
 \end{code}