Commit 6409ba52 authored by ian@well-typed.com's avatar ian@well-typed.com

Rename remaining FastBytes usages to ByteString

parent ca56668a
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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}
%************************************************************************
......
......@@ -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#
......
......@@ -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
......
......@@ -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 }
......
......@@ -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")
......
......@@ -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
......
......@@ -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)
---------------
......
......@@ -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
......
......@@ -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
......
......@@ -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).
......
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment