CpsPreprocessor

cps.CpsPreprocessor
trait CpsPreprocessor[F[_], C <: CpsMonadContext[F]]

Typeclass for preprocessing expressions inside async blocks before CPS transformation occurs.

The preprocessor receives the body expression and the monad context. The context is passed explicitly because the body has type A (not a context function), so the context cannot be summoned inside the body.

Use cases:

  • Durable monad: wrap vals with caching via ctx operations
  • Tracing monad: add trace calls
  • STM monad: add savepoints

Example implementation:

given CpsPreprocessor[Durable, DurableContext] with
 inline def preprocess[A](inline body: A)(inline ctx: DurableContext): A =
   ${ DurablePreprocessMacro.impl[A]('body, 'ctx) }

The preprocessor macro can transform val definitions, control flow conditions, and other expressions as needed by the monad semantics, using ctx directly.

Type parameters

C

The context type (subtype of CpsMonadContext[F])

F

The monad type

Attributes

Source
CpsPreprocessor.scala
Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Value members

Abstract methods

transparent inline def preprocess[A](inline body: A, inline ctx: C): A

Transform the body of an async block before CPS transformation.

Transform the body of an async block before CPS transformation.

Type parameters

A

The result type of the body expression

Value parameters

body

The body expression inside the async block

ctx

The monad context, passed explicitly for use in generated code

Attributes

Returns

The transformed body expression

Source
CpsPreprocessor.scala