License | BSD-3-Clause |
---|---|
Maintainer | Jamie Willis |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
This module contains the types that represent statically known information that can be refined and manipulated within a single compilation unit: i.e. not crossing recursion or call boundaries.
Since: 1.4.0.0
Synopsis
- type StaHandler# s o a = Code (Rep o) -> Code (ST s (Maybe a))
- data StaHandler s o a = StaHandler (Maybe (Offset o)) (StaHandlerCase WStaHandler# s o a) (Maybe (StaHandlerCase WDynHandler s o a))
- data StaHandlerCase h s (o :: Type) a
- data WStaHandler# s o a
- data WDynHandler s o a
- mkStaHandler :: Offset o -> StaHandler# s o a -> StaHandler s o a
- mkStaHandlerNoOffset :: StaHandler# s o a -> StaHandler s o a
- mkStaHandlerDyn :: forall s o a. Maybe (Offset o) -> DynHandler s o a -> StaHandler s o a
- mkStaHandlerFull :: forall s o a. Offset o -> DynHandler s o a -> Code (ST s (Maybe a)) -> DynHandler s o a -> StaHandler s o a
- staHandler# :: StaHandler s o a -> StaHandler# s o a
- staHandlerEval :: StaHandler s o a -> Offset o -> Code (ST s (Maybe a))
- staHandlerCharacteristicSta :: StaHandlerCase WStaHandler# s o a -> InputCharacteristic -> StaHandler# s o a
- staHandlerCharacteristicDyn :: StaHandlerCase WDynHandler s o a -> (Code (ST s (Maybe a)) -> DynHandler s o a) -> InputCharacteristic -> DynHandler s o a
- type StaCont# s o a x = Code x -> Code (Rep o) -> Code (ST s (Maybe a))
- data StaCont s o a x = StaCont (StaCont# s o a x) (Maybe (DynCont s o a x))
- mkStaCont :: StaCont# s o a x -> StaCont s o a x
- mkStaContDyn :: DynCont s o a x -> StaCont s o a x
- staCont# :: StaCont s o a x -> StaCont# s o a x
- data QSubroutine s o a x = forall rs. QSubroutine (StaFunc rs s o a x) (Regs rs)
- data StaSubroutine s o a x
- type StaSubroutine# s o a x = DynCont s o a x -> Code (Rep o) -> DynHandler s o a -> Code (ST s (Maybe a))
- type family StaFunc (rs :: [Type]) s o a x where ...
- qSubroutine :: forall s o a x rs. DynFunc rs s o a x -> Regs rs -> Metadata -> QSubroutine s o a x
- mkStaSubroutine :: StaSubroutine# s o a x -> StaSubroutine s o a x
- mkStaSubroutineMeta :: Metadata -> StaSubroutine# s o a x -> StaSubroutine s o a x
- staSubroutine# :: StaSubroutine s o a x -> StaSubroutine# s o a x
- meta :: StaSubroutine s o a x -> Metadata
Handlers
type StaHandler# s o a = Code (Rep o) -> Code (ST s (Maybe a)) Source #
This represents the translation of Handler#
but where the static function structure has been exposed. This allows for β-reduction
on handlers, a simple form of inlining optimisation.
Since: 1.4.0.0
data StaHandler s o a Source #
Compared with StaHandler#
, this type allows for the encoding of various static
properties of handlers which can be carried around during the lifetime of the handlers.
This information allows the engine to optimise more aggressively, leveraging
domain-specific optimisation data.
Since: 1.5.0.0
StaHandler | |
|
data StaHandlerCase h s (o :: Type) a Source #
Represents potentially three handlers: one for unknown offset cases, one for offset known to be
the same, and another for offset known to be different (see mkStaHandlerFull
). Parameterised by
a generic handler type, which is instantiated to one of WStaHandler#
or WDynHandler
.
Since: 1.5.0.0
data WStaHandler# s o a Source #
Wraps a StaHandler#
.
Since: 1.5.0.0
data WDynHandler s o a Source #
Wraps a DynHandler
.
Since: 1.5.0.0
StaHandler
Builders
The following functions are builders of StaHandler
.
mkStaHandler :: Offset o -> StaHandler# s o a -> StaHandler s o a Source #
Augments a StaHandler#
with information about what the offset is that
the handler has captured. This is a purely static handler, which is not
derived from a dynamic one.
Since: 1.4.0.0
mkStaHandlerNoOffset :: StaHandler# s o a -> StaHandler s o a Source #
Converts a StaHandler#
into a StaHandler
without any information
about the captured offset. This is a purely static handler, not derived
from a dynamic one.
Since: 1.4.0.0
mkStaHandlerDyn :: forall s o a. Maybe (Offset o) -> DynHandler s o a -> StaHandler s o a Source #
Converts a DynHandler
into a
StaHandler
taking into account the possibility that captured offset
information is available. The dynamic handler used to construct this
static handler is maintained as the origin of the handler. This means
if it is converted back the conversion is free.
Since: 1.4.0.0
:: forall s o a. Offset o | The offset captured by the creation of the handler. |
-> DynHandler s o a | The full handler, which can be used when offsets are incomparable and must perform the check. |
-> Code (ST s (Maybe a)) | The code that is executed when the captured offset matches the input. |
-> DynHandler s o a | The handler to be executed when offsets are known not to match. |
-> StaHandler s o a | A handler that carries this information around for later refinement. |
When the behaviours of a handler given input that matches or does not match
its captured offset are known, this function can be used to construct a
StaHandler
that stores this information. This can in turn be used in
conjunction with staHandlerEval
to statically refine the application of
a handler to its argument.
Since: 1.4.0.0
StaHandler
Interpreters
The following functions interpret or extract information from StaHandler
.
staHandler# :: StaHandler s o a -> StaHandler# s o a Source #
Given a static handler, extracts the underlying handler which has "forgotten" any static domain-specific information it had been attached to.
Since: 1.4.0.0
staHandlerEval :: StaHandler s o a -> Offset o -> Code (ST s (Maybe a)) Source #
Unlike staHandler#
, which returns a handler that accepts
, this
function accepts a full Code
(Rep
o)Offset
,
which can be used to refine the outcome of the execution of the handler as follows:
If the handler has a registered captured offset, and these offsets are comparable:
- If the offsets are equal, use the code to be executed on matching offset (See
mkStaHandlerFull
) - If the offsets are not equal, invoke the sub-handler, skipping the if check (see
mkStaHandlerFull
)
- If the offsets are equal, use the code to be executed on matching offset (See
- If the handler is missing a captured offset, or they are incomparable (from different sources) then execute the full handler, which will perform a runtime check for equivalence.
Since: 1.4.0.0
staHandlerCharacteristicSta :: StaHandlerCase WStaHandler# s o a -> InputCharacteristic -> StaHandler# s o a Source #
Selects the correct case out of a StaHandlerCase
depending on what the InputCharacteristic
that
governs the use of the handler is. This means that it can select any of the three cases.
Since: 1.5.0.0
staHandlerCharacteristicDyn Source #
:: StaHandlerCase WDynHandler s o a | |
-> (Code (ST s (Maybe a)) -> DynHandler s o a) | How to convert the input-same case to a |
-> InputCharacteristic | |
-> DynHandler s o a |
Selects the correct case out of a StaHandlerCase
depending on what the InputCharacteristic
that
governs the use of the handler is. This means that it can select any of the three cases.
Since: 1.5.0.0
Return Continuations
type StaCont# s o a x = Code x -> Code (Rep o) -> Code (ST s (Maybe a)) Source #
This represents the translation of Cont#
but where the static function structure has been exposed. This allows for β-reduction
on continuations, a simple form of inlining optimisation.
Since: 1.4.0.0
Compared with StaCont#
, this type also bundles the static continuation
with its dynamic origin, if available.
Since: 1.4.0.0
mkStaCont :: StaCont# s o a x -> StaCont s o a x Source #
Wraps a StaCont#
up, under the knowledge that it is purely static and
not derived from any dynamic continuation.
Since: 1.4.0.0
mkStaContDyn :: DynCont s o a x -> StaCont s o a x Source #
staCont# :: StaCont s o a x -> StaCont# s o a x Source #
Given a static continuation, extracts the underlying continuation which has "forgotten" any static domain-specific information it had been attached to.
Since: 1.4.0.0
Subroutines
data QSubroutine s o a x Source #
Wraps a StaFunc
with its free registers, which are kept existential.
Since: 1.4.0.0
forall rs. QSubroutine (StaFunc rs s o a x) (Regs rs) |
data StaSubroutine s o a x Source #
Packages a StaSubroutine#
along with statically determined metadata that describes it derived from
static analysis.
Since: 1.5.0.0
type StaSubroutine# s o a x = DynCont s o a x -> Code (Rep o) -> DynHandler s o a -> Code (ST s (Maybe a)) Source #
This represents the translation of Subroutine#
but where the static function structure has been exposed. This allows for β-reduction
on subroutines, a simple form of inlining optimisation: useful for iteration.
Since: 1.5.0.0
type family StaFunc (rs :: [Type]) s o a x where ... Source #
This represents the translation of Func
but where the static function structure has been exposed. This allows for β-reduction
on subroutines with registers, a simple form of inlining optimisation.
Since: 1.4.0.0
Subroutine Builders
qSubroutine :: forall s o a x rs. DynFunc rs s o a x -> Regs rs -> Metadata -> QSubroutine s o a x Source #
Converts a DynFunc
that relies
on zero or more free registers into a QSubroutine
, where the registers are
existentially bounds to the function.
Since: 1.5.0.0
mkStaSubroutine :: StaSubroutine# s o a x -> StaSubroutine s o a x Source #
Converts a StaSubroutine#
into a StaSubroutine
by providing the empty meta.
Since: 1.5.0.0
mkStaSubroutineMeta :: Metadata -> StaSubroutine# s o a x -> StaSubroutine s o a x Source #
Converts a StaSubroutine#
into a StaSubroutine
by providing its metadata.
Since: 1.5.0.0
Subroutine Extractors
staSubroutine# :: StaSubroutine s o a x -> StaSubroutine# s o a x Source #
Extracts the underlying subroutine.
meta :: StaSubroutine s o a x -> Metadata Source #
Extracts the metadata from a subroutine.