Maintainer | maurerl@cs.uoregon.edu |
---|---|
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
The AST for Sequent Core, with basic operations.
- data Value b
- data Frame b
- type Cont b = [Frame b]
- data Command b = Command {}
- data Bind b
- data Alt b = Alt AltCon [b] (Command b)
- data AltCon :: *
- type SeqCoreValue = Value Var
- type SeqCoreFrame = Frame Var
- type SeqCoreCont = Cont Var
- type SeqCoreCommand = Command Var
- type SeqCoreBind = Bind Var
- type SeqCoreAlt = Alt Var
- mkCommand :: [Bind b] -> Value b -> Cont b -> Command b
- valueCommand :: Value b -> Command b
- varCommand :: Id -> Command b
- lambdas :: [b] -> Command b -> Command b
- addLets :: [Bind b] -> Command b -> Command b
- extendCont :: Command b -> Cont b -> Command b
- collectLambdas :: Command b -> ([b], Command b)
- collectArgs :: Cont b -> ([Command b], Cont b)
- isLambda :: Command b -> Bool
- isTypeArg :: Command b -> Bool
- isCoArg :: Command b -> Bool
- isErasedArg :: Command b -> Bool
- isRuntimeArg :: Command b -> Bool
- isTypeValue :: Value b -> Bool
- isCoValue :: Value b -> Bool
- isErasedValue :: Value b -> Bool
- isRuntimeValue :: Value b -> Bool
- isTrivial :: HasId b => Command b -> Bool
- isTrivialValue :: HasId b => Value b -> Bool
- isTrivialCont :: Cont b -> Bool
- isTrivialFrame :: Frame b -> Bool
- commandAsSaturatedCall :: Command b -> Maybe (Value b, [Command b], Cont b)
- asSaturatedCall :: Value b -> Cont b -> Maybe ([Command b], Cont b)
- asValueCommand :: Command b -> Maybe (Value b)
- valueArity :: Value b -> Int
- commandType :: SeqCoreCommand -> Type
- (=~=) :: AlphaEq a => a -> a -> Bool
- class AlphaEq a where
- type AlphaEnv = RnEnv2
- class HasId a where
- identifier :: a -> Id
AST Types
An atomic value. These include literals, lambdas, and variables, as well as
types and coercions (see GHC's Expr
for the reasoning).
Lit Literal | A primitive literal value. |
Var Id | A term variable. Must not be a
nullary constructor; use |
Lam b (Command b) | A function. The body is a computation,
that is, a |
Cons DataCon [Command b] | A value formed by a saturated constructor application. |
Type Type | A type. Used to pass a type as an argument to a type-level lambda. |
Coercion Coercion | A coercion. Used to pass evidence
for the |
OutputableBndr b => Outputable (Value b) | |
HasId b => AlphaEq (Value b) |
A stack frame. A continuation is simply a list of these. Each represents the outer part of a Haskell expression, with a "hole" where a value can be placed. Computation in the sequent calculus is expressed as the interaction of a value with a continuation.
App (Command b) | Apply the value to an argument, which may be a computation. |
Case b Type [Alt b] | Perform case analysis on the value. |
Cast Coercion | Cast the value using the given proof. |
Tick (Tickish Id) | Annotate the enclosed frame. Used by the profiler. |
OutputableBndr b => Outputable (Frame b) | |
HasId b => AlphaEq (Frame b) |
type Cont b = [Frame b] Source
A continuation, expressed as a list of Frame
s. In terms of the sequent
calculus, here nil
stands for a free covariable; since Haskell does not
allow for control effects, we only allow for one covariable.
A general computation. A command brings together a list of bindings, some value, and a continuation saying what to do with that value. The value and continuation comprise a cut in the sequent calculus.
Invariant: If cmdValue
is a variable representing a constructor, then
cmdCont
must not begin with as many App
frames as the constructor's
arity. In other words, the command must not represent a saturated application
of a constructor. Such an application should be represented by a Cons
value
instead. When in doubt, use mkCommand
to enforce this invariant.
OutputableBndr b => Outputable (Command b) | |
HasId b => AlphaEq (Command b) |
A binding. Similar to the Bind
datatype from GHC. Can be either a single
non-recursive binding or a mutually recursive block.
NonRec b (Command b) | A single non-recursive binding. |
Rec [(b, Command b)] | A block of mutually recursive bindings. |
OutputableBndr b => Outputable (Bind b) | |
HasId b => AlphaEq (Bind b) |
A case alternative. Given by the head constructor (or literal), a list of
bound variables (empty for a literal), and the body as a Command
.
OutputableBndr b => Outputable (Alt b) | |
HasId b => AlphaEq (Alt b) |
data AltCon :: *
A case alternative constructor (i.e. pattern match)
Constructors
valueCommand :: Value b -> Command b Source
Constructs a command that simply returns a value.
varCommand :: Id -> Command b Source
Constructs a command that simply returns a variable.
lambdas :: [b] -> Command b -> Command b Source
Constructs a number of lambdas surrounding a function body.
addLets :: [Bind b] -> Command b -> Command b Source
Adds the given bindings outside those in the given command.
extendCont :: Command b -> Cont b -> Command b Source
Adds the given continuation frames to the end of those in the given command.
Deconstructors
collectLambdas :: Command b -> ([b], Command b) Source
Divide a command into a sequence of lambdas and a body. If c
is not a
lambda, then collectLambdas c == ([], c)
.
collectArgs :: Cont b -> ([Command b], Cont b) Source
Divide a continuation into a sequence of arguments and an outer
continuation. If k
is not an application continuation, then
collectArgs k == ([], k)
.
isLambda :: Command b -> Bool Source
True if the given command is a simple lambda, with no let bindings and no continuation.
isTypeArg :: Command b -> Bool Source
True if the given command simply returns a type as a value. This may only
be true of a command appearing as an argument (that is, inside an App
frame) or as the body of a let
.
isCoArg :: Command b -> Bool Source
True if the given command simply returns a coercion as a value. This may
only be true of a command appearing as an argument (that is, inside an App
frame) or as the body of a let
.
isErasedArg :: Command b -> Bool Source
True if the given command simply returns a value that is either a type or
a coercion. This may only be true of a command appearing as an argument (that
is, inside an App
frame) or as the body of a let
.
isRuntimeArg :: Command b -> Bool Source
True if the given command appears at runtime. Types and coercions are erased.
isTypeValue :: Value b -> Bool Source
True if the given value is a type. See Type
.
isErasedValue :: Value b -> Bool Source
True if the given value is a type or coercion.
isRuntimeValue :: Value b -> Bool Source
True if the given value appears at runtime.
isTrivial :: HasId b => Command b -> Bool Source
True if the given command represents no actual run-time computation or
allocation. For this to hold, it must have no let
bindings, and its value
and its continuation must both be trivial. Equivalent to
exprIsTrivial
in GHC.
isTrivialValue :: HasId b => Value b -> Bool Source
True if the given value represents no actual run-time computation. Some literals are not trivial, and a lambda whose argument is not erased or whose body is non-trivial is also non-trivial.
isTrivialCont :: Cont b -> Bool Source
True if the given continuation represents no actual run-time computation. This holds if all of its frames are trivial (perhaps because it is the empty continuation).
isTrivialFrame :: Frame b -> Bool Source
True if the given continuation represents no actual run-time computation. This is true of casts and of applications of erased arguments (types and coercions). Ticks are not considered trivial, since this would cause them to be inlined.
commandAsSaturatedCall :: Command b -> Maybe (Value b, [Command b], Cont b) Source
If a command represents a saturated call to some function, splits it into the function, the arguments, and the remaining continuation after the arguments.
asSaturatedCall :: Value b -> Cont b -> Maybe ([Command b], Cont b) Source
If the given value is a function, and the given continuation would provide enough arguments to saturate it, returns the arguments and the remainder of the continuation.
asValueCommand :: Command b -> Maybe (Value b) Source
If a command does nothing but provide a value, returns that value.
Calculations
valueArity :: Value b -> Int Source
Compute (a conservative estimate of) the arity of a value. If the value is a variable, this may be a lower bound.
commandType :: SeqCoreCommand -> Type Source
Compute the type of a command.
Alpha-equivalence
(=~=) :: AlphaEq a => a -> a -> Bool infix 4 Source
True if the two given terms are the same, up to renaming of bound variables.
The class of types that can be compared up to alpha-equivalence.
The type of the environment of an alpha-equivalence comparison. Only needed
by user code if two terms need to be compared under some assumed
correspondences between free variables. See GHC's VarEnv
module for
operations.