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/FastString.hs | |
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/FastString.hs')
-rw-r--r-- | compiler/utils/FastString.hs | 58 |
1 files changed, 29 insertions, 29 deletions
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 #-} |