Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data Literal
- mkMachInt :: DynFlags -> Integer -> Literal
- mkMachWord :: DynFlags -> Integer -> Literal
- mkMachInt64 :: Integer -> Literal
- mkMachWord64 :: Integer -> Literal
- mkMachFloat :: Rational -> Literal
- mkMachDouble :: Rational -> Literal
- mkMachChar :: Char -> Literal
- mkMachString :: String -> Literal
- mkLitInteger :: Integer -> Type -> Literal
- literalType :: Literal -> Type
- hashLiteral :: Literal -> Int
- absentLiteralOf :: TyCon -> Maybe Literal
- pprLiteral :: (SDoc -> SDoc) -> Literal -> SDoc
- litIsDupable :: DynFlags -> Literal -> Bool
- litIsTrivial :: Literal -> Bool
- litIsLifted :: Literal -> Bool
- inIntRange :: DynFlags -> Integer -> Bool
- inWordRange :: DynFlags -> Integer -> Bool
- tARGET_MAX_INT :: DynFlags -> Integer
- inCharRange :: Char -> Bool
- isZeroLit :: Literal -> Bool
- litFitsInChar :: Literal -> Bool
- litValue :: Literal -> Integer
- word2IntLit :: DynFlags -> Literal -> Literal
- int2WordLit :: DynFlags -> Literal -> Literal
- narrow8IntLit :: Literal -> Literal
- narrow16IntLit :: Literal -> Literal
- narrow32IntLit :: Literal -> Literal
- narrow8WordLit :: Literal -> Literal
- narrow16WordLit :: Literal -> Literal
- narrow32WordLit :: Literal -> Literal
- char2IntLit :: Literal -> Literal
- int2CharLit :: Literal -> Literal
- float2IntLit :: Literal -> Literal
- int2FloatLit :: Literal -> Literal
- double2IntLit :: Literal -> Literal
- int2DoubleLit :: Literal -> Literal
- nullAddrLit :: Literal
- float2DoubleLit :: Literal -> Literal
- double2FloatLit :: Literal -> Literal
Main data type
So-called Literal
s are one of:
MachChar Char |
|
MachStr ByteString | A string-literal: stored and emitted
UTF-8 encoded, we'll arrange to decode it
at runtime. Also emitted with a |
MachNullAddr | The |
MachInt Integer |
|
MachInt64 Integer |
|
MachWord Integer |
|
MachWord64 Integer |
|
MachFloat Rational |
|
MachDouble Rational |
|
MachLabel FastString (Maybe Int) FunctionOrData | A label literal. Parameters: 1) The name of the symbol mentioned in the declaration 2) The size (in bytes) of the arguments
the label expects. Only applicable with
|
LitInteger Integer Type |
Creating Literals
mkMachString :: String -> Literal Source #
Creates a Literal
of type Addr#
, which is appropriate for passing to
e.g. some of the "error" functions in GHC.Err such as GHC.Err.runtimeError
Operations on Literals
hashLiteral :: Literal -> Int Source #
Predicates on Literals and their contents
litIsDupable :: DynFlags -> Literal -> Bool Source #
True if code space does not go bad if we duplicate this literal
Currently we treat it just like litIsTrivial
litIsTrivial :: Literal -> Bool Source #
True if there is absolutely no penalty to duplicating the literal. False principally of strings.
"Why?", you say? I'm glad you asked. Well, for one duplicating strings would blow up code sizes. Not only this, it's also unsafe.
Consider a program that wants to traverse a string. One way it might do this is to first compute the Addr# pointing to the end of the string, and then, starting from the beginning, bump a pointer using eqAddr# to determine the end. For instance,
-- Given pointers to the start and end of a string, count how many zeros -- the string contains. countZeros :: Addr -> -> Int countZeros start end = go start 0 where go off n | off `addrEq#` end = n | otherwise = go (off `plusAddr#` 1) n' where n' | isTrue off 0 0#) = n + 1 | otherwise = n
Consider what happens if we considered strings to be trivial (and therefore
duplicable) and emitted a call like countZeros "hello"
. The beginning and end pointers do not belong to the same
string, meaning that an iteration like the above would blow up terribly.
This is what happened in #12757.plusAddr
# 5)
Ultimately the solution here is to make primitive strings a bit more structured, ensuring that the compiler can't inline in ways that will break user code. One approach to this is described in #8472.
litIsLifted :: Literal -> Bool Source #
tARGET_MAX_INT :: DynFlags -> Integer Source #
inCharRange :: Char -> Bool Source #
isZeroLit :: Literal -> Bool Source #
Tests whether the literal represents a zero of whatever type it is
litFitsInChar :: Literal -> Bool Source #
Coercions
narrow8IntLit :: Literal -> Literal Source #
narrow16IntLit :: Literal -> Literal Source #
narrow32IntLit :: Literal -> Literal Source #
narrow8WordLit :: Literal -> Literal Source #
narrow16WordLit :: Literal -> Literal Source #
narrow32WordLit :: Literal -> Literal Source #
char2IntLit :: Literal -> Literal Source #
int2CharLit :: Literal -> Literal Source #
float2IntLit :: Literal -> Literal Source #
int2FloatLit :: Literal -> Literal Source #
double2IntLit :: Literal -> Literal Source #
int2DoubleLit :: Literal -> Literal Source #
float2DoubleLit :: Literal -> Literal Source #
double2FloatLit :: Literal -> Literal Source #