Describes an output environment that is guaranteed to emit the molecule at least once.
Describes an output environment that is guaranteed to emit the molecule at least once. This is currently used only in a do-while construct.
Id of the output environment construct.
Name of the construct: one of "do while"
, "condition of while"
, or "condition of do while"
.
Blocking molecule class.
Blocking molecule class. Instance is mutable until the molecule is bound to a reaction site and until all reactions involving this molecule are declared.
Type of the value carried by the molecule.
Type of the value replied to the caller via the "reply" action.
A cached pool that increases its thread count whenever a blocking molecule is emitted, and decreases afterwards.
A cached pool that increases its thread count whenever a blocking molecule is emitted, and decreases afterwards.
The BlockingIdle
function, similar to scala.concurrent.blocking
, is used to annotate expressions that should lead to an increase of thread count, and to a decrease of thread count once the idle blocking call returns.
Describes a molecule emitted in a chooser clause, that is, in an if-then-else
or match-case
construct.
Describes a molecule emitted in a chooser clause, that is, in an if-then-else
or match-case
construct.
Id of the chooser construct.
Zero-based index of the clause.
Total number of clauses in the chooser constructs (2 for if-then-else
, 2 or greater for match-case
).
Represents molecules that have constant pattern matchers, such as a(1)
.
Represents molecules that have constant pattern matchers, such as a(1)
.
Constant pattern matchers are either literal values (Int
, String
, Symbol
, etc.) or special values such as None
, Nil
, ()
,
as well as Some
, Left
, Right
, List
, and tuples of constant matchers.
Value of the constant. This is nominally of type Any
but actually is of the molecule's value type T
.
Represents the structure of the cross-molecule guard condition for a reaction.
Represents the structure of the cross-molecule guard condition for a reaction. A cross-molecule guard constrains values of several molecules at once.
Integer indices of affected molecules in the reaction input.
Symbols of variables used by the guard condition.
Partial function that applies to its argument, of type List[Any]
, if the cross-molecule guard evaluates to true
on these values.
The arguments of the partial function must correspond to the values of the affected molecules, in the order of the reaction input.
Convenience syntax: users can write a(x) + b(y)
to emit several molecules at once.
Convenience syntax: users can write a(x) + b(y)
to emit several molecules at once.
However, the molecules are still emitted one by one in the present implementation.
So, a(x) + b(y) + c(z)
is equivalent to a(x); b(y); c(z)
.
An auxiliary class with a +
operation.
The fixed-thread implementation of a Chymyst
thread pool.
Describes a molecule emitted under a function call.
Describes a molecule emitted under a function call.
Id of the function call construct.
Fully qualified name of the function call, for example "scala.collection.TraversableLike.map"
.
Describes a molecule emitted under an anonymous function.
Describes a molecule emitted under an anonymous function.
Id of the anonymous function construct.
Indicates whether a reaction has a guard condition.
Indicates whether guard conditions are required for this reaction to start.
Indicates whether guard conditions are required for this reaction to start.
The guard is parsed into a flat conjunction of guard clauses, which are then analyzed for cross-dependencies between molecules.
For example, consider the reaction
go { case a(x) + b(y) + c(z) if x > n && y > 0 && y > z && n > 1 => ...}
Here n
is an integer value defined outside the reaction.
The conditions for starting this reaction is that a(x)
has value x
such that x > n
; that b(y)
has value y
such that y > 0
;
that c(z)
has value z
such that y > z
; and finally that n > 1
, independently of any molecule values.
The condition n > 1
is a static guard. The condition x > n
restricts only the molecule a(x)
and therefore can be moved out of the guard
into the per-molecule conditional inside InputMoleculeInfo for that molecule. Similarly, the condition y > 0
can be moved out of the guard.
However, the condition y > z
relates two different molecule values; it is a cross-molecule guard.
Any guard condition given by the reaction code will be converted to the Conjunctive Normal Form, and split into a static guard, a set of per-molecule conditionals, and a set of cross-molecule guards.
The conjunction of all the clauses of the guard that are independent of pattern variables. This closure can be called in order to determine whether the reaction should even be considered to start, regardless of the presence of molecules. In this example, the value of staticGuard
will be Some(() => n > 1)
.
A list of values of type CrossMoleculeGuard, each representing one cross-molecule clauses of the guard. The partial function Any => Unit
should be called with the arguments representing the tuples of pattern variables from each molecule used by the cross guard.
In the present example, the value of crossGuards
will be an array with the single element
CrossMoleculeGuard(indices = Array(1, 2), List((List('y, 'z), { case List(y: Int, z: Int) if y > z => () })))
Compile-time information about an input molecule pattern in a certain reaction where the molecule is consumed.
Compile-time information about an input molecule pattern in a certain reaction where the molecule is consumed.
The molecule emitter value that represents the input molecule.
Zero-based index of this molecule in the input list of the reaction.
A value of type InputPatternType that describes the value pattern: wildcard, constant match, etc.
Hash sum of the input pattern's source code (desugared Scala representation).
String representation of the type T
of the molecule's value, e.g. for M[T]
or B[T, R]
.
Represents compile-time information about the pattern matching for values carried by input molecules.
Represents compile-time information about the pattern matching for values carried by input molecules.
Possibilities:
a(_)
is represented by WildcardInput
a(x)
is represented by SimpleVarInput with value SimpleVar(v = 'x, cond = None)
a(x) if x > 0
is represented by SimpleVarInput with value SimpleVar(v = 'x, cond = Some({ case x : Int if x > 0 => }))
a(Some(1))
is represented by ConstInputPattern with value SimpleConst(v = Some(1))
a( (x, Some((y,z)))) ) if x > y
is represented by OtherInputPattern with value
OtherInputPattern(matcher = { case (x, Some((y,z)))) if x > y => }, vars = List('x, 'y, 'z), isIrrefutable = false)
Non-blocking molecule class.
Non-blocking molecule class. Instance is mutable until the molecule is bound to a reaction site and until all reactions involving this molecule are declared.
Type of the value carried by the molecule.
Abstract trait representing a molecule emitter.
Abstract container with multiset functionality.
Abstract container with multiset functionality. Concrete implementations may optimize for specific access patterns.
Type of the value carried by molecule.
Implementation using guava's com.google.common.collect.ConcurrentHashMultiset
.
Implementation using guava's com.google.common.collect.ConcurrentHashMultiset
.
This is suitable for types that have a small number of possible values (i.e. Core.simpleTypes), or for molecules constrained by cross-molecule dependencies where selection by value is important.
A simple, limited multiset implementation currently only used by Core.streamDiff.
A simple, limited multiset implementation currently only used by Core.streamDiff. - Not thread-safe. - No iterators over values.
Type of values held by the multiset.
Implementation using java.util.concurrent.ConcurrentLinkedQueue
.
Implementation using java.util.concurrent.ConcurrentLinkedQueue
.
This is suitable for molecule value types that have a large number of possible values (so that a Map
storage would be inefficient),
or for cases where we do not need to group molecules by value (pipelined molecules).
Describes a molecule that is _not_ emitted last in a statement block.
Describes a molecule that is _not_ emitted last in a statement block.
Id of the construct.
Represents a general pattern that is neither a wildcard nor a single variable nor a constant.
Represents a general pattern that is neither a wildcard nor a single variable nor a constant.
Examples of such patterns are a(Some(x))
and a( (x, _, 2, List(a, b)) )
.
A pattern is recognized to be _irrefutable_ when it is a tuple where all places are either simple variables or wildcards.
For example, a( z@(x, y, _) )
is an irrefutable pattern for a 3-tuple type.
On the other hand, a( (x, _, Some(_) ) )
is not irrefutable because it fails to match a( (_, _, None) )
.
Another recognized case of irrefutable patterns is a single case class that extends a sealed trait.
Partial function that applies to the argument when the pattern matches.
List of symbols representing the variables used in the pattern, in the left-to-right order.
true
if the pattern will always match the argument of the correct type, false
otherwise.
Describe the code environment within which an output molecule is being emitted.
Describe the code environment within which an output molecule is being emitted.
Possible environments are ChooserBlock describing an if
or match
expression with clauses,
and a function call FuncBlock.
For example, if (x>0) a(x) else b(x)
is a chooser block environment with 2 clauses,
while (1 to 10).foreach(a)
is a function block environment
and (x) => a(x)
is a FuncLambda environment.
Compile-time information about an output molecule pattern in a reaction.
Compile-time information about an output molecule pattern in a reaction. This class is immutable.
The molecule emitter value that represents the output molecule.
Type of the output pattern: either a constant value or other value.
The code environment in which this output molecule was emitted.
Represents the value pattern of an emitted output molecule.
Represents the value pattern of an emitted output molecule. We distinguish only constant value patterns and all other patterns.
Mix this trait into your class to make the has code persistent after the first time it's computed.
A pool of execution threads, or another way of running tasks (could use actors or whatever else).
A pool of execution threads, or another way of running tasks (could use actors or whatever else).
Tasks submitted for execution can have Chymyst-specific info (useful for debugging) when scheduled using runReaction
.
The pool can be shut down, in which case all further tasks will be refused.
Represents a reaction.
Represents a reaction. This class is immutable.
A value of type ReactionInfo describing input and output molecules for this reaction.
Partial function of type InputMoleculeList => Any
Thread pool on which this reaction will be scheduled. (By default, the common pool is used.)
Whether the reaction should be run again when an exception occurs in its body. Default is false.
Syntax helper for zero-argument molecule emitters.
Syntax helper for zero-argument molecule emitters.
This trait has a single method, getUnit
, which returns a value of type T
, but the only instance will exist if T
is Unit
and will return ()
.
Type of the molecule value. If this is Unit
, we will have an implicit value of type TypeIsUnit[A]
, which will define getUnit
to return ()
.
Wrapper for unapply()
.
Wrapper for unapply()
. According to https://github.com/scala/scala/pull/2848 the unapply()
function can return any
type that directly contains methods isEmpty: Boolean
and get: T
where T
can be either a tuple type with extractors _1, _2 etc.,
or another type.
This wrapper is for wrapping a value that is unconditionally returned by unapply()
, as molecule extractors must do.
Since that value is of an unknown type T
, we can't add the named extractor API on top of that type. So we must use this wrapper.
Type of the molecule value.
Molecule value wrapped and to be returned by unapply()
.
Convenience syntax: provides an unapply
operation, so that users can write the chemical notation, such as
a(x) + b(y) + ...
, in reaction input patterns.
Convenience syntax: provides an unapply
operation, so that users can write the chemical notation, such as
a(x) + b(y) + ...
, in reaction input patterns.
Pattern-matching can be used on molecule values at will, for example:
go { case a(MyCaseClass(x, y)) + b(Some(z)) if x > z => ... }
The chemical notation should be used only with the left-associative +
operator grouped to the left.
Input patterns with a right-associative grouping of the +
operator, for example a(x) + ( b(y) + c(z) )
, are rejected at compile time.
Indicates that a guard was initially absent and, in addition, all molecules have trivial matchers - this reaction can start with any molecule values.
This is similar to scala.concurrent.blocking and is used to annotate expressions that should lead to a possible increase of thread count.
This is similar to scala.concurrent.blocking and is used to annotate expressions that should lead to a possible increase of thread count.
Multiple nested calls to BlockingIdle
are equivalent to one call.
Indicates that a guard was initially present but has been simplified, or it was absent but some molecules have nontrivial pattern matchers (not a wildcard and not a simple variable).
Indicates that a guard was initially present but has been simplified, or it was absent but some molecules have nontrivial pattern matchers (not a wildcard and not a simple variable). In any case, no cross-molecule guard conditions need to be checked for this reaction to start.
We need to have a single implicit instance of TypeMustBeUnit[Unit]
.
Syntax helper for molecules with unit values.
Syntax helper for molecules with unit values.
An implicit value of TypeMustBeUnit[A]
is available only if A == Unit
.
Declare a new blocking molecule emitter.
Declare a new blocking molecule emitter. The name of the molecule will be automatically assigned (via macro) to the name of the enclosing variable.
Type of the value carried by the molecule.
Type of the reply value.
A new instance of class io.chymyst.jc.B[T,R]
.
Run a closure with a resource that is allocated and safely cleaned up after use.
Run a closure with a resource that is allocated and safely cleaned up after use. Resource will be cleaned up even if the closure throws an exception.
Type of the resource value.
Type of the result of doWork
.
A value of type T
that needs to be created for use by doWork
.
A closure that will perform the necessary cleanup on the resource.
A closure that will perform useful work, using the resource.
The value returned by doWork
, wrapped in a Try
.
Clear the global error log used by all reaction sites to report runtime errors.
A convenience method that fetches the number of CPU cores of the current machine.
A convenience method that fetches the number of CPU cores of the current machine.
The number of available CPU cores.
This pool is used for sites that do not specify a thread pool.
Access the global error log used by all reaction sites to report runtime errors.
Access the global error log used by all reaction sites to report runtime errors.
An Iterable
representing the complete error log.
This is the main method for defining reactions.
This is the main method for defining reactions. Examples:
go { a(_) => ... }
go { a (_) => ...}.withRetry onThreads threadPool
The macro also obtains statically checkable information about input and output molecules in the reaction.
The body of the reaction. This must be a partial function with pattern-matching on molecules.
A Reaction value, containing the reaction body as well as static information about input and output molecules.
Declare a new non-blocking molecule emitter.
Declare a new non-blocking molecule emitter. The name of the molecule will be automatically assigned (via macro) to the name of the enclosing variable.
Type of the value carried by the molecule.
A new instance of class io.chymyst.jc.M[T]
.
site()
call with a default reaction pool.
Create a reaction site with one or more reactions.
Create a reaction site with one or more reactions. All input and output molecules in reactions used in this site should have been already defined, and input molecules should not be already bound to another site.
Thread pool for running new reactions.
One or more reactions of type Reaction
List of warning messages.
A helper method to run a closure that uses a thread pool, safely closing the pool after use.
A helper method to run a closure that uses a thread pool, safely closing the pool after use.
Type of the value returned by the closure.
A thread pool value, evaluated lazily - typically BlockingPool(...)
.
A closure, typically containing a site(pool)(...)
call.
The value returned by the closure, wrapped in a Try
.
This object contains code that should be visible to users of
Chymyst Core
. It also serves as an interface to macros. This allows users to import just one package and use all functionality ofChymyst Core
.