diff options
author | Sylvain Henry <hsyl20@gmail.com> | 2018-11-22 11:31:16 -0500 |
---|---|---|
committer | Ben Gamari <ben@smart-cactus.org> | 2018-11-22 12:11:15 -0500 |
commit | 13bb4bf44e6e690133be334bbf0c63fcae5db34a (patch) | |
tree | ee7a9a9f60ca936b16cc15a46c758d4dc51abfd7 /compiler/utils | |
parent | f5fbecc85967218fd8ba6512f10eea2daf2812ac (diff) | |
download | haskell-13bb4bf44e6e690133be334bbf0c63fcae5db34a.tar.gz |
Rename literal constructors
In a previous patch we replaced some built-in literal constructors
(MachInt, MachWord, etc.) with a single LitNumber constructor.
In this patch we replace the `Mach` prefix of the remaining constructors
with `Lit` for consistency (e.g., LitChar, LitLabel, etc.).
Sadly the name `LitString` was already taken for a kind of FastString
and it would become misleading to have both `LitStr` (literal
constructor renamed after `MachStr`) and `LitString` (FastString
variant). Hence this patch renames the FastString variant `PtrString`
(which is more accurate) and the literal string constructor now uses the
least surprising `LitString` name.
Both `Literal` and `LitString/PtrString` have recently seen breaking
changes so doing this kind of renaming now shouldn't harm much.
Reviewers: hvr, goldfire, bgamari, simonmar, jrtc27, tdammers
Subscribers: tdammers, rwbarton, thomie, carter
Differential Revision: https://phabricator.haskell.org/D4881
Diffstat (limited to 'compiler/utils')
-rw-r--r-- | compiler/utils/BufWrite.hs | 8 | ||||
-rw-r--r-- | compiler/utils/FastString.hs | 58 | ||||
-rw-r--r-- | compiler/utils/Outputable.hs | 2 | ||||
-rw-r--r-- | compiler/utils/Pretty.hs | 22 |
4 files changed, 45 insertions, 45 deletions
diff --git a/compiler/utils/BufWrite.hs b/compiler/utils/BufWrite.hs index 99c043ce41..f4b406fe90 100644 --- a/compiler/utils/BufWrite.hs +++ b/compiler/utils/BufWrite.hs @@ -19,7 +19,7 @@ module BufWrite ( bPutStr, bPutFS, bPutFZS, - bPutLitString, + bPutPtrString, bPutReplicate, bFlush, ) where @@ -98,15 +98,15 @@ bPutCStringLen b@(BufHandle buf r hdl) cstr@(ptr, len) = do copyBytes (buf `plusPtr` i) ptr len writeFastMutInt r (i + len) -bPutLitString :: BufHandle -> LitString -> IO () -bPutLitString b@(BufHandle buf r hdl) l@(LitString a len) = l `seq` do +bPutPtrString :: BufHandle -> PtrString -> IO () +bPutPtrString b@(BufHandle buf r hdl) l@(PtrString a len) = l `seq` do i <- readFastMutInt r if (i+len) >= buf_size then do hPutBuf hdl buf i writeFastMutInt r 0 if (len >= buf_size) then hPutBuf hdl a len - else bPutLitString b l + else bPutPtrString b l else do copyBytes (buf `plusPtr` i) a len writeFastMutInt r (i+len) diff --git a/compiler/utils/FastString.hs b/compiler/utils/FastString.hs index 5869449f86..c53eff1dd1 100644 --- a/compiler/utils/FastString.hs +++ b/compiler/utils/FastString.hs @@ -16,7 +16,7 @@ -- * Generated by 'fsLit'. -- * Turn into 'Outputable.SDoc' with 'Outputable.ftext'. -- --- ['LitString'] +-- ['PtrString'] -- -- * Pointer and size of a Latin-1 encoded string. -- * Practically no operations. @@ -28,7 +28,7 @@ -- * It assumes Latin-1 as the encoding, therefore it cannot represent -- arbitrary Unicode strings. -- --- Use 'LitString' unless you want the facilities of 'FastString'. +-- Use 'PtrString' unless you want the facilities of 'FastString'. module FastString ( -- * ByteString @@ -79,19 +79,19 @@ module FastString getFastStringTable, hasZEncoding, - -- * LitStrings - LitString (..), + -- * PtrStrings + PtrString (..), -- ** Construction sLit, - mkLitString#, - mkLitString, + mkPtrString#, + mkPtrString, -- ** Deconstruction - unpackLitString, + unpackPtrString, -- ** Operations - lengthLS + lengthPS ) where #include "HsVersions.h" @@ -627,21 +627,21 @@ hPutFS handle fs = BS.hPut handle $ fastStringToByteString fs -- in the current locale's encoding (for error messages and suchlike). -- ----------------------------------------------------------------------------- --- LitStrings, here for convenience only. +-- PtrStrings, here for convenience only. --- | A 'LitString' is a pointer to some array of Latin-1 encoded chars. -data LitString = LitString !(Ptr Word8) !Int +-- | A 'PtrString' is a pointer to some array of Latin-1 encoded chars. +data PtrString = PtrString !(Ptr Word8) !Int --- | Wrap an unboxed address into a 'LitString'. -mkLitString# :: Addr# -> LitString -mkLitString# a# = LitString (Ptr a#) (ptrStrLength (Ptr a#)) +-- | Wrap an unboxed address into a 'PtrString'. +mkPtrString# :: Addr# -> PtrString +mkPtrString# a# = PtrString (Ptr a#) (ptrStrLength (Ptr a#)) --- | Encode a 'String' into a newly allocated 'LitString' using Latin-1 +-- | Encode a 'String' into a newly allocated 'PtrString' using Latin-1 -- encoding. The original string must not contain non-Latin-1 characters -- (above codepoint @0xff@). -{-# INLINE mkLitString #-} -mkLitString :: String -> LitString -mkLitString s = +{-# INLINE mkPtrString #-} +mkPtrString :: String -> PtrString +mkPtrString s = -- we don't use `unsafeDupablePerformIO` here to avoid potential memory leaks -- and because someone might be using `eqAddr#` to check for string equality. unsafePerformIO (do @@ -654,17 +654,17 @@ mkLitString s = pokeByteOff p n (fromIntegral (ord c) :: Word8) loop (1+n) cs loop 0 s - return (LitString p len) + return (PtrString p len) ) --- | Decode a 'LitString' back into a 'String' using Latin-1 encoding. --- This does not free the memory associated with 'LitString'. -unpackLitString :: LitString -> String -unpackLitString (LitString (Ptr p#) (I# n#)) = unpackNBytes# p# n# +-- | Decode a 'PtrString' back into a 'String' using Latin-1 encoding. +-- This does not free the memory associated with 'PtrString'. +unpackPtrString :: PtrString -> String +unpackPtrString (PtrString (Ptr p#) (I# n#)) = unpackNBytes# p# n# --- | Return the length of a 'LitString' -lengthLS :: LitString -> Int -lengthLS (LitString _ n) = n +-- | Return the length of a 'PtrString' +lengthPS :: PtrString -> Int +lengthPS (PtrString _ n) = n -- ----------------------------------------------------------------------------- -- under the carpet @@ -673,14 +673,14 @@ foreign import ccall unsafe "strlen" ptrStrLength :: Ptr Word8 -> Int {-# NOINLINE sLit #-} -sLit :: String -> LitString -sLit x = mkLitString x +sLit :: String -> PtrString +sLit x = mkPtrString x {-# NOINLINE fsLit #-} fsLit :: String -> FastString fsLit x = mkFastString x {-# RULES "slit" - forall x . sLit (unpackCString# x) = mkLitString# x #-} + forall x . sLit (unpackCString# x) = mkPtrString# x #-} {-# RULES "fslit" forall x . fsLit (unpackCString# x) = mkFastString# x #-} diff --git a/compiler/utils/Outputable.hs b/compiler/utils/Outputable.hs index 929c7f3d58..28fd48783c 100644 --- a/compiler/utils/Outputable.hs +++ b/compiler/utils/Outputable.hs @@ -553,7 +553,7 @@ empty :: SDoc char :: Char -> SDoc text :: String -> SDoc ftext :: FastString -> SDoc -ptext :: LitString -> SDoc +ptext :: PtrString -> SDoc ztext :: FastZString -> SDoc int :: Int -> SDoc integer :: Integer -> SDoc diff --git a/compiler/utils/Pretty.hs b/compiler/utils/Pretty.hs index 1a8bc23205..32b982855a 100644 --- a/compiler/utils/Pretty.hs +++ b/compiler/utils/Pretty.hs @@ -270,7 +270,7 @@ data TextDetails = Chr {-# UNPACK #-} !Char -- ^ A single Char fragment | Str String -- ^ A whole String fragment | PStr FastString -- a hashed string | ZStr FastZString -- a z-encoded string - | LStr {-# UNPACK #-} !LitString + | LStr {-# UNPACK #-} !PtrString -- a '\0'-terminated array of bytes | RStr {-# UNPACK #-} !Int {-# UNPACK #-} !Char -- a repeated character (e.g., ' ') @@ -306,17 +306,17 @@ text s = textBeside_ (Str s) (length s) Empty -- RULE that turns (text "abc") into (ptext (A# "abc"#)) to avoid the -- intermediate packing/unpacking of the string. {-# RULES "text/str" - forall a. text (unpackCString# a) = ptext (mkLitString# a) + forall a. text (unpackCString# a) = ptext (mkPtrString# a) #-} {-# RULES "text/unpackNBytes#" - forall p n. text (unpackNBytes# p n) = ptext (LitString (Ptr p) (I# n)) + forall p n. text (unpackNBytes# p n) = ptext (PtrString (Ptr p) (I# n)) #-} ftext :: FastString -> Doc ftext s = textBeside_ (PStr s) (lengthFS s) Empty -ptext :: LitString -> Doc -ptext s = textBeside_ (LStr s) (lengthLS s) Empty +ptext :: PtrString -> Doc +ptext s = textBeside_ (LStr s) (lengthPS s) Empty ztext :: FastZString -> Doc ztext s = textBeside_ (ZStr s) (lengthFZS s) Empty @@ -941,7 +941,7 @@ txtPrinter (Chr c) s = c:s txtPrinter (Str s1) s2 = s1 ++ s2 txtPrinter (PStr s1) s2 = unpackFS s1 ++ s2 txtPrinter (ZStr s1) s2 = zString s1 ++ s2 -txtPrinter (LStr s1) s2 = unpackLitString s1 ++ s2 +txtPrinter (LStr s1) s2 = unpackPtrString s1 ++ s2 txtPrinter (RStr n c) s2 = replicate n c ++ s2 -- | The general rendering interface. @@ -1053,15 +1053,15 @@ printDoc_ mode pprCols hdl doc -- NB. not hPutFS, we want this to go through -- the I/O library's encoding layer. (#3398) put (ZStr s) next = hPutFZS hdl s >> next - put (LStr s) next = hPutLitString hdl s >> next + put (LStr s) next = hPutPtrString hdl s >> next put (RStr n c) next = hPutStr hdl (replicate n c) >> next done = return () -- hPutChar hdl '\n' -- some versions of hPutBuf will barf if the length is zero -hPutLitString :: Handle -> LitString -> IO () -hPutLitString _handle (LitString _ 0) = return () -hPutLitString handle (LitString a l) = hPutBuf handle a l +hPutPtrString :: Handle -> PtrString -> IO () +hPutPtrString _handle (PtrString _ 0) = return () +hPutPtrString handle (PtrString a l) = hPutBuf handle a l -- Printing output in LeftMode is performance critical: it's used when -- dumping C and assembly output, so we allow ourselves a few dirty @@ -1099,7 +1099,7 @@ layLeft b (TextBeside s _ p) = s `seq` (put b s >> layLeft b p) put b (Str s) = bPutStr b s put b (PStr s) = bPutFS b s put b (ZStr s) = bPutFZS b s - put b (LStr s) = bPutLitString b s + put b (LStr s) = bPutPtrString b s put b (RStr n c) = bPutReplicate b n c layLeft _ _ = panic "layLeft: Unhandled case" |