ghc-8.4.1: The GHC API

Safe HaskellNone
LanguageHaskell2010

FastString

Contents

Description

There are two principal string types used internally by GHC:

FastString
  • A compact, hash-consed, representation of character strings.
  • Comparison is O(1), and you can get a Unique from them.
  • Generated by fsLit.
  • Turn into SDoc with ftext.
LitString
  • Just a wrapper for the Addr# of a C string (Ptr CChar).
  • Practically no operations.
  • Outputing them is fast.
  • Generated by sLit.
  • Turn into SDoc with ptext
  • Requires manual memory management. Improper use may lead to memory leaks or dangling pointers.
  • It assumes Latin-1 as the encoding, therefore it cannot represent arbitrary Unicode strings.

Use LitString unless you want the facilities of FastString.

Synopsis

ByteString

mkFastStringByteString :: ByteString -> FastString Source #

Create a FastString from an existing ForeignPtr; the difference between this and mkFastStringBytes is that we don't have to copy the bytes if the string is new to the table.

FastZString

data FastZString Source #

Instances
NFData FastZString Source # 
Instance details

Methods

rnf :: FastZString -> () #

FastStrings

data FastString Source #

A FastString is an array of bytes, hashed to support fast O(1) comparison. It is also associated with a character encoding, so that we know how to convert a FastString to the local encoding, or to the Z-encoding used by the compiler internally.

FastStrings support a memoized conversion to the Z-encoding via zEncodeFS.

Constructors

FastString 

Fields

Instances
Eq FastString Source # 
Instance details
Data FastString Source # 
Instance details

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> FastString -> c FastString #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c FastString #

toConstr :: FastString -> Constr #

dataTypeOf :: FastString -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c FastString) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c FastString) #

gmapT :: (forall b. Data b => b -> b) -> FastString -> FastString #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> FastString -> r #

gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> FastString -> r #

gmapQ :: (forall d. Data d => d -> u) -> FastString -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> FastString -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> FastString -> m FastString #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> FastString -> m FastString #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> FastString -> m FastString #

Ord FastString Source # 
Instance details
Show FastString Source # 
Instance details
IsString FastString Source # 
Instance details
Semigroup FastString Source # 
Instance details
Monoid FastString Source # 
Instance details
Outputable FastString Source # 
Instance details
Uniquable FastString Source # 
Instance details
Binary FastString Source # 
Instance details

Construction

mkFastString :: String -> FastString Source #

Creates a UTF-8 encoded FastString from a String

mkFastStringByteList :: [Word8] -> FastString Source #

Creates a FastString from a UTF-8 encoded [Word8]

mkFastStringForeignPtr :: Ptr Word8 -> ForeignPtr Word8 -> Int -> IO FastString Source #

Create a FastString from an existing ForeignPtr; the difference between this and mkFastStringBytes is that we don't have to copy the bytes if the string is new to the table.

Deconstruction

unpackFS :: FastString -> String Source #

Unpacks and decodes the FastString

bytesFS :: FastString -> [Word8] Source #

Gives the UTF-8 encoded bytes corresponding to a FastString

Encoding

zEncodeFS :: FastString -> FastZString Source #

Returns a Z-encoded version of a FastString. This might be the original, if it was already Z-encoded. The first time this function is applied to a particular FastString, the results are memoized.

Operations

lengthFS :: FastString -> Int Source #

Returns the length of the FastString in characters

nullFS :: FastString -> Bool Source #

Returns True if the FastString is empty

Outputing

hPutFS :: Handle -> FastString -> IO () Source #

Outputs a FastString with no decoding at all, that is, you get the actual bytes in the FastString written to the Handle.

Internal

hasZEncoding :: FastString -> Bool Source #

Returns True if this FastString is not Z-encoded but already has a Z-encoding cached (used in producing stats).

LitStrings

type LitString = Ptr Word8 Source #

A LitString is a pointer to some null-terminated array of bytes.

Construction

mkLitString# :: Addr# -> LitString Source #

Wrap an unboxed address into a LitString.

mkLitString :: String -> LitString Source #

Encode a String into a newly allocated LitString using Latin-1 encoding. The original string must not contain non-Latin-1 characters (above codepoint 0xff).

Deconstruction

unpackLitString :: LitString -> String Source #

Decode a LitString back into a String using Latin-1 encoding. This does not free the memory associated with LitString.

Operations

lengthLS :: LitString -> Int Source #

Compute the length of a LitString, which must necessarily be null-terminated.