ConcurrentExecutionContext

data class ConcurrentExecutionContext(val procedure: Struct? = null, val unificator: Unificator = Unificator.default, val libraries: Runtime = Runtime.empty(), val flags: FlagStore = FlagStore.empty(), val staticKb: Theory = Theory.empty(unificator), val dynamicKb: MutableTheory = MutableTheory.empty(unificator), val operators: OperatorSet = getAllOperators(libraries, staticKb, dynamicKb).toOperatorSet(), val inputChannels: InputStore = InputStore.fromStandard(), val outputChannels: OutputStore = OutputStore.fromStandard(), val customData: CustomDataStore = CustomDataStore.empty(), val substitution: Substitution.Unifier = Substitution.empty(), val query: Struct = Truth.TRUE, val goals: Cursor<out Term> = Cursor.empty(), val rule: Rule? = null, val primitive: Solve.Response? = null, val startTime: TimeInstant, val maxDuration: TimeDuration = TimeDuration.MAX_VALUE, val parent: ConcurrentExecutionContext? = null, val depth: Int = 0, val step: Long = 0) : ExecutionContext

The ExecutionContext implementation for :solve-concurrent: an immutable node of the resolution tree that it.unibo.tuprolog.solve.concurrent.fsm.States carry around and derive from, chained back to the root goal via parent. Each concurrently-running coroutine spawned while resolving a goal (see ConcurrentSolver) owns its own chain of these, so no synchronization is needed to read pathToRoot/logicStackTrace from within a single branch -- only knowledge-base mutation shared across branches (see ConcurrentSolver's concurrency caveat) is unsynchronized.

depth/step/parent together encode the position of this context within the (conceptually tree-shaped, but per-branch linear) resolution: parent is null exactly at the isRoot context (depth == 0), and every non-root context has a strictly greater depth than its parent (enforced by the init block). goals is the (possibly partially consumed) Cursor of remaining conjuncts for query at this point in the resolution; rule/primitive record which clause or primitive response, respectively, is currently being executed to produce the next context down the chain.

Constructors

Link copied to clipboard
constructor(procedure: Struct? = null, unificator: Unificator = Unificator.default, libraries: Runtime = Runtime.empty(), flags: FlagStore = FlagStore.empty(), staticKb: Theory = Theory.empty(unificator), dynamicKb: MutableTheory = MutableTheory.empty(unificator), operators: OperatorSet = getAllOperators(libraries, staticKb, dynamicKb).toOperatorSet(), inputChannels: InputStore = InputStore.fromStandard(), outputChannels: OutputStore = OutputStore.fromStandard(), customData: CustomDataStore = CustomDataStore.empty(), substitution: Substitution.Unifier = Substitution.empty(), query: Struct = Truth.TRUE, goals: Cursor<out Term> = Cursor.empty(), rule: Rule? = null, primitive: Solve.Response? = null, startTime: TimeInstant, maxDuration: TimeDuration = TimeDuration.MAX_VALUE, parent: ConcurrentExecutionContext? = null, depth: Int = 0, step: Long = 0)

Properties

Link copied to clipboard

The first term still to be resolved in goals, or null if goals has been fully consumed.

Link copied to clipboard
open override val customData: CustomDataStore
Link copied to clipboard
val depth: Int

how many parent links separate this context from the root one; 0 for the root context.

Link copied to clipboard
open override val dynamicKb: MutableTheory
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val flags: FlagStore
Link copied to clipboard
val goals: Cursor<out Term>

the remaining conjuncts (of query, or of the current rule's body) still to be resolved.

Link copied to clipboard
open override val inputChannels: InputStore
Link copied to clipboard

The Vars whose bindings must be preserved when substitution is filtered/restricted while moving between contexts (e.g. when returning from a sub-goal to its parent): those of query at the root, propagated down together with the variables of whatever is left in goals at each step.

Link copied to clipboard

Whether this context represents a genuine "activation record" -- i.e. the entry point of a new procedure call -- as opposed to an intermediate context created while unfolding a conjunction/disjunction within the same call. Used to filter pathToRoot down to logicStackTrace.

Link copied to clipboard

Whether this is the root context of the resolution tree, i.e. it has no parent (depth == 0).

Link copied to clipboard
open override val libraries: Runtime
Link copied to clipboard
open override val logicStackTrace: List<Struct>

The Prolog call stack trace up to this context, built by walking pathToRoot and keeping isActivationRecord entries.

Link copied to clipboard
open override val maxDuration: TimeDuration
Link copied to clipboard
open override val operators: OperatorSet
Link copied to clipboard
open override val outputChannels: OutputStore
Link copied to clipboard

the context this one was created from (e.g. when descending into a sub-goal), or null if this isRoot.

Link copied to clipboard

This context, followed by every parent, up to (and including) the isRoot one.

Link copied to clipboard

the response of the primitive currently being executed, if any.

Link copied to clipboard
open override val procedure: Struct?
Link copied to clipboard

the original goal this whole activation record chain is trying to prove.

Link copied to clipboard
Link copied to clipboard
val rule: Rule?

the clause currently being tried against it.unibo.tuprolog.solve.concurrent.fsm.State.context's current goal, if any.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
open override val startTime: TimeInstant
Link copied to clipboard
open override val staticKb: Theory
Link copied to clipboard
val step: Long

a monotonically increasing counter of resolution steps taken along this branch, mostly useful for debugging/tracing.

Link copied to clipboard
Link copied to clipboard
open override val unificator: Unificator
Link copied to clipboard

Functions

Link copied to clipboard
open override fun apply(sideEffect: SideEffect): ConcurrentExecutionContext
open override fun apply(sideEffects: Iterable<SideEffect>): ConcurrentExecutionContext
open override fun apply(sideEffects: Sequence<SideEffect>): ConcurrentExecutionContext

Same as ExecutionContext.apply, but statically typed to return a ConcurrentExecutionContext.

Link copied to clipboard

Creates a new ConcurrentExecutionContext descending into ConcurrentExecutionContext.currentGoal as a sub-goal: the new context's ConcurrentExecutionContext.goals become just that goal, its ConcurrentExecutionContext.parent is this context, and its ConcurrentExecutionContext.depth/ ConcurrentExecutionContext.step are incremented by one. Used by StatePrimitiveSelection/StateRuleSelection when a goal is not last-call-optimizable, so it gets its own stack frame to backtrack into.

Link copied to clipboard

Same as createChild, additionally attaching rule as the clause StateRuleExecution will unify against.

Link copied to clipboard
open override fun createMutableSolver(unificator: Unificator, libraries: Runtime, flags: FlagStore, staticKb: Theory, dynamicKb: Theory, inputChannels: InputStore, outputChannels: OutputStore): MutableSolver

Creates a new MutableSolver backed by this same resolution strategy, sharing this context's state unless overridden.

Link copied to clipboard
open override fun createSolver(unificator: Unificator, libraries: Runtime, flags: FlagStore, staticKb: Theory, dynamicKb: Theory, inputChannels: InputStore, outputChannels: OutputStore): ConcurrentSolver

Creates a new ConcurrentSolver, sharing this context's state unless overridden.

Link copied to clipboard

Same as createChild, but keeps ConcurrentExecutionContext.parent unchanged instead of pointing it at this context -- used for the last-call-optimized case (see ConcurrentExecutionContext and LastCallOptimization), reusing the current stack frame rather than growing the chain of ConcurrentExecutionContext.parents.

Link copied to clipboard

Same as replaceWithChild, additionally attaching rule as the clause StateRuleExecution will unify against.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard
open override fun update(unificator: Unificator, libraries: Runtime, flags: FlagStore, staticKb: Theory, dynamicKb: Theory, operators: OperatorSet, inputChannels: InputStore, outputChannels: OutputStore, customData: CustomDataStore): ConcurrentExecutionContext

Same as ExecutionContext.update, but statically typed to return a ConcurrentExecutionContext.