Package

io.chymyst

jc

Permalink

package jc

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 of Chymyst Core.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. jc
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Type Members

  1. final case class AtLeastOneEmitted(id: Int, name: String) extends OutputEnvironment with Product with Serializable

    Permalink

    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

    Id of the output environment construct.

    name

    Name of the construct: one of "do while", "condition of while", or "condition of do while".

  2. final class B[T, R] extends (T) ⇒ R with MolEmitter

    Permalink

    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.

    T

    Type of the value carried by the molecule.

    R

    Type of the value replied to the caller via the "reply" action.

  3. final class BlackboxMacros extends ReactionMacros

    Permalink
  4. final class BlockingPool extends Pool

    Permalink

    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.

  5. final case class ChooserBlock(id: Int, clause: Int, total: Int) extends OutputEnvironment with Product with Serializable

    Permalink

    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

    Id of the chooser construct.

    clause

    Zero-based index of the clause.

    total

    Total number of clauses in the chooser constructs (2 for if-then-else, 2 or greater for match-case).

  6. class CommonMacros extends AnyRef

    Permalink
  7. final case class ConstInputPattern(v: Any) extends InputPatternType with Product with Serializable

    Permalink

    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.

    v

    Value of the constant. This is nominally of type Any but actually is of the molecule's value type T.

  8. final case class ConstOutputPattern(v: Any) extends OutputPatternType with Product with Serializable

    Permalink
  9. final case class CrossMoleculeGuard(indices: Array[Int], symbols: Array[Symbol], cond: PartialFunction[List[Any], Unit]) extends Product with Serializable

    Permalink

    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.

    indices

    Integer indices of affected molecules in the reaction input.

    symbols

    Symbols of variables used by the guard condition.

    cond

    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.

  10. implicit final class EmitMultiple extends AnyRef

    Permalink

    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).

    returns

    An auxiliary class with a + operation.

  11. final class FixedPool extends Pool

    Permalink

    The fixed-thread implementation of a Chymyst thread pool.

  12. final case class FuncBlock(id: Int, name: String) extends OutputEnvironment with Product with Serializable

    Permalink

    Describes a molecule emitted under a function call.

    Describes a molecule emitted under a function call.

    id

    Id of the function call construct.

    name

    Fully qualified name of the function call, for example "scala.collection.TraversableLike.map".

  13. final case class FuncLambda(id: Int) extends OutputEnvironment with Product with Serializable

    Permalink

    Describes a molecule emitted under an anonymous function.

    Describes a molecule emitted under an anonymous function.

    id

    Id of the anonymous function construct.

  14. sealed trait GuardPresenceFlag extends AnyRef

    Permalink

    Indicates whether a reaction has a guard condition.

  15. final case class GuardPresent(staticGuard: Option[() ⇒ Boolean], crossGuards: Array[CrossMoleculeGuard]) extends GuardPresenceFlag with Product with Serializable

    Permalink

    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.

    staticGuard

    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).

    crossGuards

    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 => () })))
  16. final case class InputMoleculeInfo(molecule: MolEmitter, index: Int, flag: InputPatternType, sha1: String, valType: Symbol) extends Product with Serializable

    Permalink

    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.

    molecule

    The molecule emitter value that represents the input molecule.

    index

    Zero-based index of this molecule in the input list of the reaction.

    flag

    A value of type InputPatternType that describes the value pattern: wildcard, constant match, etc.

    sha1

    Hash sum of the input pattern's source code (desugared Scala representation).

    valType

    String representation of the type T of the molecule's value, e.g. for M[T] or B[T, R].

  17. sealed trait InputPatternType extends AnyRef

    Permalink

    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)
  18. final class M[T] extends (T) ⇒ Unit with MolEmitter

    Permalink

    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.

    T

    Type of the value carried by the molecule.

  19. sealed trait MolEmitter extends PersistentHashCode

    Permalink

    Abstract trait representing a molecule emitter.

    Abstract trait representing a molecule emitter. This trait is not parameterized by type and is used in collections of molecules that do not require knowledge of molecule types. Its only implementations are the classes B and M.

  20. final class MoleculeMacros extends CommonMacros

    Permalink
  21. trait MutCollection[T] extends AnyRef

    Permalink
  22. sealed trait MutableBag[T] extends MutCollection[T]

    Permalink

    Abstract container with multiset functionality.

    Abstract container with multiset functionality. Concrete implementations may optimize for specific access patterns.

    T

    Type of the value carried by molecule.

  23. final class MutableMapBag[T] extends MutableBag[T]

    Permalink

    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.

  24. class MutableMultiset[T] extends MutCollection[T]

    Permalink

    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.

    T

    Type of values held by the multiset.

  25. final class MutableQueueBag[T] extends MutableBag[T]

    Permalink

    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).

  26. final case class NotLastBlock(id: Int) extends OutputEnvironment with Product with Serializable

    Permalink

    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

    Id of the construct.

  27. final case class OtherInputPattern(matcher: PartialFunction[Any, Unit], vars: List[Symbol], irrefutable: Boolean) extends InputPatternType with Product with Serializable

    Permalink

    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.

    matcher

    Partial function that applies to the argument when the pattern matches.

    vars

    List of symbols representing the variables used in the pattern, in the left-to-right order.

    irrefutable

    true if the pattern will always match the argument of the correct type, false otherwise.

  28. sealed trait OutputEnvironment extends AnyRef

    Permalink

    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.

  29. final case class OutputMoleculeInfo(molecule: MolEmitter, flag: OutputPatternType, environments: List[OutputEnvironment]) extends Product with Serializable

    Permalink

    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.

    molecule

    The molecule emitter value that represents the output molecule.

    flag

    Type of the output pattern: either a constant value or other value.

    environments

    The code environment in which this output molecule was emitted.

  30. sealed trait OutputPatternType extends AnyRef

    Permalink

    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.

  31. sealed trait PersistentHashCode extends AnyRef

    Permalink

    Mix this trait into your class to make the has code persistent after the first time it's computed.

  32. abstract class Pool extends AutoCloseable

    Permalink

    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.

  33. final class PoolMacros extends CommonMacros

    Permalink
  34. final case class Reaction(info: ReactionInfo, body: ReactionBody, threadPool: Option[Pool], retry: Boolean) extends Product with Serializable

    Permalink

    Represents a reaction.

    Represents a reaction. This class is immutable.

    info

    A value of type ReactionInfo describing input and output molecules for this reaction.

    body

    Partial function of type InputMoleculeList => Any

    threadPool

    Thread pool on which this reaction will be scheduled. (By default, the common pool is used.)

    retry

    Whether the reaction should be run again when an exception occurs in its body. Default is false.

  35. final class ReactionInfo extends AnyRef

    Permalink
  36. class ReactionMacros extends CommonMacros

    Permalink
  37. final case class SimpleVarInput(v: Symbol, cond: Option[PartialFunction[Any, Unit]]) extends InputPatternType with Product with Serializable

    Permalink
  38. implicit final class SiteWithPool extends AnyVal

    Permalink
  39. sealed trait TypeMustBeUnit[A] extends AnyRef

    Permalink

    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 ().

    A

    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 ().

  40. final case class WarningsAndErrors(warnings: Seq[String], errors: Seq[String], reactionSite: String) extends Product with Serializable

    Permalink
  41. final case class Wrap[T](x: T) extends AnyVal with Product with Serializable

    Permalink

    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.

    T

    Type of the molecule value.

    x

    Molecule value wrapped and to be returned by unapply().

Value Members

  1. object +

    Permalink

    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.

  2. object AllMatchersAreTrivial extends GuardPresenceFlag with Product with Serializable

    Permalink

    Indicates that a guard was initially absent and, in addition, all molecules have trivial matchers - this reaction can start with any molecule values.

  3. object BlockingIdle

    Permalink

    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.

  4. object BlockingPool

    Permalink
  5. object Core

    Permalink
  6. object FixedPool

    Permalink
  7. object GuardAbsent extends GuardPresenceFlag with Product with Serializable

    Permalink

    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.

  8. object Macros

    Permalink
  9. object OtherOutputPattern extends OutputPatternType with Product with Serializable

    Permalink
  10. implicit val UnitArgImplicit: TypeMustBeUnit[Unit]

    Permalink

    We need to have a single implicit instance of TypeMustBeUnit[Unit].

  11. object UnitTypeMustBeUnit extends TypeMustBeUnit[Unit]

    Permalink

    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.

  12. object WildcardInput extends InputPatternType with Product with Serializable

    Permalink
  13. macro def b[T, R]: B[T, R]

    Permalink

    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.

    T

    Type of the value carried by the molecule.

    R

    Type of the reply value.

    returns

    A new instance of class io.chymyst.jc.B[T,R].

  14. def cleanup[T, R](resource: ⇒ T)(cleanup: (T) ⇒ Unit)(doWork: (T) ⇒ R): Try[R]

    Permalink

    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.

    T

    Type of the resource value.

    R

    Type of the result of doWork.

    resource

    A value of type T that needs to be created for use by doWork.

    cleanup

    A closure that will perform the necessary cleanup on the resource.

    doWork

    A closure that will perform useful work, using the resource.

    returns

    The value returned by doWork, wrapped in a Try.

  15. def clearGlobalErrorLog(): Unit

    Permalink

    Clear the global error log used by all reaction sites to report runtime errors.

  16. def cpuCores: Int

    Permalink

    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.

    returns

    The number of available CPU cores.

  17. lazy val defaultPool: BlockingPool

    Permalink

    This pool is used for sites that do not specify a thread pool.

  18. def globalErrorLog: Iterable[String]

    Permalink

    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.

    returns

    An Iterable representing the complete error log.

  19. macro def go(reactionBody: ReactionBody): Reaction

    Permalink

    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.

    reactionBody

    The body of the reaction. This must be a partial function with pattern-matching on molecules.

    returns

    A Reaction value, containing the reaction body as well as static information about input and output molecules.

  20. macro def m[T]: M[T]

    Permalink

    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.

    T

    Type of the value carried by the molecule.

    returns

    A new instance of class io.chymyst.jc.M[T].

  21. def site(reactions: Reaction*): WarningsAndErrors

    Permalink

    site() call with a default reaction pool.

  22. def site(reactionPool: Pool)(reactions: Reaction*): WarningsAndErrors

    Permalink

    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.

    reactionPool

    Thread pool for running new reactions.

    reactions

    One or more reactions of type Reaction

    returns

    List of warning messages.

  23. def withPool[T](pool: ⇒ Pool)(doWork: (Pool) ⇒ T): Try[T]

    Permalink

    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.

    T

    Type of the value returned by the closure.

    pool

    A thread pool value, evaluated lazily - typically BlockingPool(...).

    doWork

    A closure, typically containing a site(pool)(...) call.

    returns

    The value returned by the closure, wrapped in a Try.

Inherited from AnyRef

Inherited from Any

Ungrouped