summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lynagh <ian@well-typed.com>2012-12-14 19:23:17 +0000
committerIan Lynagh <ian@well-typed.com>2012-12-14 19:23:17 +0000
commit6409ba527bfd7c7b536d0c523c5f99186cd258db (patch)
tree9661d5f98e13631a4d03cd0c2ea0d7a3afc68fe5
parentca56668af97f534b3cff8717fc35d795a0bcb47d (diff)
downloadhaskell-6409ba527bfd7c7b536d0c523c5f99186cd258db.tar.gz
Rename remaining FastBytes usages to ByteString
-rw-r--r--compiler/basicTypes/Literal.lhs5
-rw-r--r--compiler/coreSyn/MkCore.lhs4
-rw-r--r--compiler/deSugar/Check.lhs2
-rw-r--r--compiler/deSugar/DsBinds.lhs2
-rw-r--r--compiler/deSugar/MatchLit.lhs4
-rw-r--r--compiler/hsSyn/HsLit.lhs3
-rw-r--r--compiler/parser/Lexer.x7
-rw-r--r--compiler/parser/ParserCore.y2
-rw-r--r--compiler/rename/RnExpr.lhs2
-rw-r--r--compiler/typecheck/TcInstDcls.lhs2
-rw-r--r--compiler/typecheck/TcTyClsDecls.lhs2
-rw-r--r--compiler/utils/Binary.hs2
-rw-r--r--compiler/utils/BufWrite.hs5
-rw-r--r--compiler/utils/FastString.lhs31
-rw-r--r--compiler/utils/Outputable.lhs5
15 files changed, 38 insertions, 40 deletions
diff --git a/compiler/basicTypes/Literal.lhs b/compiler/basicTypes/Literal.lhs
index 8fc42db9b5..c77915fef6 100644
--- a/compiler/basicTypes/Literal.lhs
+++ b/compiler/basicTypes/Literal.lhs
@@ -56,6 +56,7 @@ import DynFlags
import UniqFM
import Util
+import Data.ByteString (ByteString)
import Data.Int
import Data.Ratio
import Data.Word
@@ -85,7 +86,7 @@ data Literal
-- First the primitive guys
MachChar Char -- ^ @Char#@ - at least 31 bits. Create with 'mkMachChar'
- | MachStr FastBytes -- ^ A string-literal: stored and emitted
+ | MachStr ByteString -- ^ A string-literal: stored and emitted
-- UTF-8 encoded, we'll arrange to decode it
-- at runtime. Also emitted with a @'\0'@
-- terminator. Create with 'mkMachString'
@@ -250,7 +251,7 @@ mkMachChar = MachChar
-- e.g. some of the \"error\" functions in GHC.Err such as @GHC.Err.runtimeError@
mkMachString :: String -> Literal
-- stored UTF-8 encoded
-mkMachString s = MachStr (fastStringToFastBytes $ mkFastString s)
+mkMachString s = MachStr (fastStringToByteString $ mkFastString s)
mkLitInteger :: Integer -> Type -> Literal
mkLitInteger = LitInteger
diff --git a/compiler/coreSyn/MkCore.lhs b/compiler/coreSyn/MkCore.lhs
index e903ab2084..42f83151f7 100644
--- a/compiler/coreSyn/MkCore.lhs
+++ b/compiler/coreSyn/MkCore.lhs
@@ -284,11 +284,11 @@ mkStringExprFS str
| all safeChar chars
= do unpack_id <- lookupId unpackCStringName
- return (App (Var unpack_id) (Lit (MachStr (fastStringToFastBytes str))))
+ return (App (Var unpack_id) (Lit (MachStr (fastStringToByteString str))))
| otherwise
= do unpack_id <- lookupId unpackCStringUtf8Name
- return (App (Var unpack_id) (Lit (MachStr (fastStringToFastBytes str))))
+ return (App (Var unpack_id) (Lit (MachStr (fastStringToByteString str))))
where
chars = unpackFS str
diff --git a/compiler/deSugar/Check.lhs b/compiler/deSugar/Check.lhs
index ad590ae8d8..7736aa69ed 100644
--- a/compiler/deSugar/Check.lhs
+++ b/compiler/deSugar/Check.lhs
@@ -445,7 +445,7 @@ get_lit :: Pat id -> Maybe HsLit
get_lit (LitPat lit) = Just lit
get_lit (NPat (OverLit { ol_val = HsIntegral i}) mb _) = Just (HsIntPrim (mb_neg negate mb i))
get_lit (NPat (OverLit { ol_val = HsFractional f }) mb _) = Just (HsFloatPrim (mb_neg negateFractionalLit mb f))
-get_lit (NPat (OverLit { ol_val = HsIsString s }) _ _) = Just (HsStringPrim (fastStringToFastBytes s))
+get_lit (NPat (OverLit { ol_val = HsIsString s }) _ _) = Just (HsStringPrim (fastStringToByteString s))
get_lit _ = Nothing
mb_neg :: (a -> a) -> Maybe b -> a -> a
diff --git a/compiler/deSugar/DsBinds.lhs b/compiler/deSugar/DsBinds.lhs
index 1e3eb2d8c4..4b7f8c0dd4 100644
--- a/compiler/deSugar/DsBinds.lhs
+++ b/compiler/deSugar/DsBinds.lhs
@@ -776,7 +776,7 @@ dsEvTerm (EvSuperClass d n)
dsEvTerm (EvDelayedError ty msg) = return $ Var errorId `mkTyApps` [ty] `mkApps` [litMsg]
where
errorId = rUNTIME_ERROR_ID
- litMsg = Lit (MachStr (fastStringToFastBytes msg))
+ litMsg = Lit (MachStr (fastStringToByteString msg))
dsEvTerm (EvLit l) =
case l of
diff --git a/compiler/deSugar/MatchLit.lhs b/compiler/deSugar/MatchLit.lhs
index 03ddc22fbf..80f2124d1f 100644
--- a/compiler/deSugar/MatchLit.lhs
+++ b/compiler/deSugar/MatchLit.lhs
@@ -133,7 +133,7 @@ hsLitKey _ (HsCharPrim c) = MachChar c
hsLitKey _ (HsStringPrim s) = MachStr s
hsLitKey _ (HsFloatPrim f) = MachFloat (fl_value f)
hsLitKey _ (HsDoublePrim d) = MachDouble (fl_value d)
-hsLitKey _ (HsString s) = MachStr (fastStringToFastBytes s)
+hsLitKey _ (HsString s) = MachStr (fastStringToByteString s)
hsLitKey _ l = pprPanic "hsLitKey" (ppr l)
hsOverLitKey :: OutputableBndr a => HsOverLit a -> Bool -> Literal
@@ -145,7 +145,7 @@ litValKey (HsIntegral i) False = MachInt i
litValKey (HsIntegral i) True = MachInt (-i)
litValKey (HsFractional r) False = MachFloat (fl_value r)
litValKey (HsFractional r) True = MachFloat (negate (fl_value r))
-litValKey (HsIsString s) neg = ASSERT( not neg) MachStr (fastStringToFastBytes s)
+litValKey (HsIsString s) neg = ASSERT( not neg) MachStr (fastStringToByteString s)
\end{code}
%************************************************************************
diff --git a/compiler/hsSyn/HsLit.lhs b/compiler/hsSyn/HsLit.lhs
index 6ed92eb8a9..8c4818c2b5 100644
--- a/compiler/hsSyn/HsLit.lhs
+++ b/compiler/hsSyn/HsLit.lhs
@@ -24,6 +24,7 @@ import Type ( Type, Kind )
import Outputable
import FastString
+import Data.ByteString (ByteString)
import Data.Data
\end{code}
@@ -60,7 +61,7 @@ data HsLit
= HsChar Char -- Character
| HsCharPrim Char -- Unboxed character
| HsString FastString -- String
- | HsStringPrim FastBytes -- Packed bytes
+ | HsStringPrim ByteString -- Packed bytes
| HsInt Integer -- Genuinely an Int; arises from TcGenDeriv,
-- and from TRANSLATION
| HsIntPrim Integer -- literal Int#
diff --git a/compiler/parser/Lexer.x b/compiler/parser/Lexer.x
index 3ffa7db7f7..2746faa34e 100644
--- a/compiler/parser/Lexer.x
+++ b/compiler/parser/Lexer.x
@@ -77,6 +77,7 @@ import Util ( readRational )
import Control.Monad
import Data.Bits
+import Data.ByteString (ByteString)
import Data.Char
import Data.List
import Data.Maybe
@@ -552,7 +553,7 @@ data Token
| ITrational FractionalLit
| ITprimchar Char
- | ITprimstring FastBytes
+ | ITprimstring ByteString
| ITprimint Integer
| ITprimword Integer
| ITprimfloat FractionalLit
@@ -1244,8 +1245,8 @@ lex_string s = do
setInput i
if any (> '\xFF') s
then failMsgP "primitive string literal must contain only characters <= \'\\xFF\'"
- else let fb = unsafeMkFastBytesString (reverse s)
- in return (ITprimstring fb)
+ else let bs = unsafeMkByteString (reverse s)
+ in return (ITprimstring bs)
_other ->
return (ITstring (mkFastString (reverse s)))
else
diff --git a/compiler/parser/ParserCore.y b/compiler/parser/ParserCore.y
index 7f9a49a2b7..fbcc98346b 100644
--- a/compiler/parser/ParserCore.y
+++ b/compiler/parser/ParserCore.y
@@ -303,7 +303,7 @@ lit :: { Literal }
: '(' INTEGER '::' aty ')' { convIntLit $2 $4 }
| '(' RATIONAL '::' aty ')' { convRatLit $2 $4 }
| '(' CHAR '::' aty ')' { MachChar $2 }
- | '(' STRING '::' aty ')' { MachStr (fastStringToFastBytes (mkFastString $2)) }
+ | '(' STRING '::' aty ')' { MachStr (fastStringToByteString (mkFastString $2)) }
fs_var_occ :: { FastString }
: NAME { mkFastString $1 }
diff --git a/compiler/rename/RnExpr.lhs b/compiler/rename/RnExpr.lhs
index 606549161f..6b53da3a67 100644
--- a/compiler/rename/RnExpr.lhs
+++ b/compiler/rename/RnExpr.lhs
@@ -1190,7 +1190,7 @@ segsToStmts empty_rec_stmt ((defs, uses, fwds, ss) : segs) fvs_later
\begin{code}
srcSpanPrimLit :: DynFlags -> SrcSpan -> HsExpr Name
srcSpanPrimLit dflags span
- = HsLit (HsStringPrim (unsafeMkFastBytesString (showSDocOneLine dflags (ppr span))))
+ = HsLit (HsStringPrim (unsafeMkByteString (showSDocOneLine dflags (ppr span))))
mkAssertErrorExpr :: RnM (HsExpr Name)
-- Return an expression for (assertError "Foo.hs:27")
diff --git a/compiler/typecheck/TcInstDcls.lhs b/compiler/typecheck/TcInstDcls.lhs
index 236b834eb6..3b2d98ad05 100644
--- a/compiler/typecheck/TcInstDcls.lhs
+++ b/compiler/typecheck/TcInstDcls.lhs
@@ -1119,7 +1119,7 @@ tcInstanceMethods dfun_id clas tyvars dfun_ev_vars inst_tys
where
error_rhs dflags = L inst_loc $ HsApp error_fun (error_msg dflags)
error_fun = L inst_loc $ wrapId (WpTyApp meth_tau) nO_METHOD_BINDING_ERROR_ID
- error_msg dflags = L inst_loc (HsLit (HsStringPrim (unsafeMkFastBytesString (error_string dflags))))
+ error_msg dflags = L inst_loc (HsLit (HsStringPrim (unsafeMkByteString (error_string dflags))))
meth_tau = funResultTy (applyTys (idType sel_id) inst_tys)
error_string dflags = showSDoc dflags (hcat [ppr inst_loc, text "|", ppr sel_id ])
lam_wrapper = mkWpTyLams tyvars <.> mkWpLams dfun_ev_vars
diff --git a/compiler/typecheck/TcTyClsDecls.lhs b/compiler/typecheck/TcTyClsDecls.lhs
index f49a6637c0..eb1383584f 100644
--- a/compiler/typecheck/TcTyClsDecls.lhs
+++ b/compiler/typecheck/TcTyClsDecls.lhs
@@ -1707,7 +1707,7 @@ mkRecSelBind (tycon, sel_name)
inst_tys = tyConAppArgs data_ty
unit_rhs = mkLHsTupleExpr []
- msg_lit = HsStringPrim $ unsafeMkFastBytesString $
+ msg_lit = HsStringPrim $ unsafeMkByteString $
occNameString (getOccName sel_name)
---------------
diff --git a/compiler/utils/Binary.hs b/compiler/utils/Binary.hs
index e90addda26..e07577776a 100644
--- a/compiler/utils/Binary.hs
+++ b/compiler/utils/Binary.hs
@@ -716,7 +716,7 @@ type SymbolTable = Array Int Name
---------------------------------------------------------
putFS :: BinHandle -> FastString -> IO ()
-putFS bh fs = putBS bh $ fastStringToFastBytes fs
+putFS bh fs = putBS bh $ fastStringToByteString fs
getFS :: BinHandle -> IO FastString
getFS bh = do bs <- getBS bh
diff --git a/compiler/utils/BufWrite.hs b/compiler/utils/BufWrite.hs
index 8ad045bf66..c0dda03bbb 100644
--- a/compiler/utils/BufWrite.hs
+++ b/compiler/utils/BufWrite.hs
@@ -88,14 +88,11 @@ bPutStr (BufHandle buf r hdl) str = do
loop cs (i+1)
bPutFS :: BufHandle -> FastString -> IO ()
-bPutFS b fs = bPutFB b $ fastStringToFastBytes fs
+bPutFS b fs = bPutBS b $ fastStringToByteString fs
bPutFZS :: BufHandle -> FastZString -> IO ()
bPutFZS b fs = bPutBS b $ fastZStringToByteString fs
-bPutFB :: BufHandle -> FastBytes -> IO ()
-bPutFB b bs = BS.unsafeUseAsCStringLen bs $ bPutCStringLen b
-
bPutBS :: BufHandle -> ByteString -> IO ()
bPutBS b bs = BS.unsafeUseAsCStringLen bs $ bPutCStringLen b
diff --git a/compiler/utils/FastString.lhs b/compiler/utils/FastString.lhs
index 67327d526d..1eeab0f561 100644
--- a/compiler/utils/FastString.lhs
+++ b/compiler/utils/FastString.lhs
@@ -26,12 +26,11 @@
-- Use 'LitString' unless you want the facilities of 'FastString'.
module FastString
(
- -- * FastBytes
- FastBytes,
- fastStringToFastBytes,
+ -- * ByteString
+ fastStringToByteString,
mkFastStringByteString,
fastZStringToByteString,
- unsafeMkFastBytesString,
+ unsafeMkByteString,
hashByteString,
-- * FastZString
@@ -129,17 +128,15 @@ import GHC.Base ( unpackCString# )
#define hASH_TBL_SIZE_UNBOXED 4091#
-type FastBytes = ByteString
-
-fastStringToFastBytes :: FastString -> FastBytes
-fastStringToFastBytes f = fs_fb f
+fastStringToByteString :: FastString -> ByteString
+fastStringToByteString f = fs_bs f
fastZStringToByteString :: FastZString -> ByteString
fastZStringToByteString (FastZString bs) = bs
-- This will drop information if any character > '\xFF'
-unsafeMkFastBytesString :: String -> FastBytes
-unsafeMkFastBytesString = BSC.pack
+unsafeMkByteString :: String -> ByteString
+unsafeMkByteString = BSC.pack
hashByteString :: ByteString -> Int
hashByteString bs
@@ -177,7 +174,7 @@ Z-encoding used by the compiler internally.
data FastString = FastString {
uniq :: {-# UNPACK #-} !Int, -- unique id
n_chars :: {-# UNPACK #-} !Int, -- number of chars
- fs_fb :: {-# UNPACK #-} !FastBytes,
+ fs_bs :: {-# UNPACK #-} !ByteString,
fs_ref :: {-# UNPACK #-} !(IORef (Maybe FastZString))
} deriving Typeable
@@ -208,7 +205,7 @@ instance Data FastString where
cmpFS :: FastString -> FastString -> Ordering
cmpFS f1@(FastString u1 _ _ _) f2@(FastString u2 _ _ _) =
if u1 == u2 then EQ else
- compare (fastStringToFastBytes f1) (fastStringToFastBytes f2)
+ compare (fastStringToByteString f1) (fastStringToByteString f2)
#ifndef __HADDOCK__
foreign import ccall unsafe "ghc_memcmp"
@@ -416,7 +413,7 @@ hasZEncoding (FastString _ _ _ ref) =
-- | Returns @True@ if the 'FastString' is empty
nullFS :: FastString -> Bool
-nullFS f = BS.null (fs_fb f)
+nullFS f = BS.null (fs_bs f)
-- | Unpacks and decodes the FastString
unpackFS :: FastString -> String
@@ -426,7 +423,7 @@ unpackFS (FastString _ _ bs _) =
-- | Gives the UTF-8 encoded bytes corresponding to a 'FastString'
bytesFS :: FastString -> [Word8]
-bytesFS fs = BS.unpack $ fastStringToFastBytes fs
+bytesFS fs = BS.unpack $ fastStringToByteString fs
-- | Returns a Z-encoded version of a 'FastString'. This might be the
-- original, if it was already Z-encoded. The first time this
@@ -447,8 +444,8 @@ zEncodeFS fs@(FastString _ _ _ ref) =
appendFS :: FastString -> FastString -> FastString
appendFS fs1 fs2 = inlinePerformIO
$ mkFastStringByteString
- $ BS.append (fastStringToFastBytes fs1)
- (fastStringToFastBytes fs2)
+ $ BS.append (fastStringToByteString fs1)
+ (fastStringToByteString fs2)
concatFS :: [FastString] -> FastString
concatFS ls = mkFastString (Prelude.concat (map unpackFS ls)) -- ToDo: do better
@@ -491,7 +488,7 @@ getFastStringTable = do
-- |Outputs a 'FastString' with /no decoding at all/, that is, you
-- get the actual bytes in the 'FastString' written to the 'Handle'.
hPutFS :: Handle -> FastString -> IO ()
-hPutFS handle fs = BS.hPut handle $ fastStringToFastBytes fs
+hPutFS handle fs = BS.hPut handle $ fastStringToByteString fs
-- ToDo: we'll probably want an hPutFSLocal, or something, to output
-- in the current locale's encoding (for error messages and suchlike).
diff --git a/compiler/utils/Outputable.lhs b/compiler/utils/Outputable.lhs
index a56037b8b7..76555eb7ea 100644
--- a/compiler/utils/Outputable.lhs
+++ b/compiler/utils/Outputable.lhs
@@ -84,6 +84,7 @@ import Platform
import Pretty ( Doc, Mode(..) )
import Panic
+import Data.ByteString (ByteString)
import qualified Data.ByteString as BS
import Data.Char
import qualified Data.Map as M
@@ -740,8 +741,8 @@ pprHsString :: FastString -> SDoc
pprHsString fs = vcat (map text (showMultiLineString (unpackFS fs)))
-- | Special combinator for showing string literals.
-pprHsBytes :: FastBytes -> SDoc
-pprHsBytes fb = let escaped = concatMap escape $ BS.unpack fb
+pprHsBytes :: ByteString -> SDoc
+pprHsBytes bs = let escaped = concatMap escape $ BS.unpack bs
in vcat (map text (showMultiLineString escaped)) <> char '#'
where escape :: Word8 -> String
escape w = let c = chr (fromIntegral w)