Evaluator¶
The reference machine is the library's small-step interpreter for Quivers Indexed Effect Core (QIEC), a CEK machine that applies one rule at a time. Each step shows how a request is handled, how a value is returned, and which continuation resumes, so the machine fixes how a well-typed computation runs (Reynolds, 1972).
evaluator
¶
Small-step reference evaluator for the Quivers Indexed Effect Core.
The evaluator is deliberately an interpreter, not an optimized execution
engine. It gives Return, Bind, Perform, and Handle one
operational meaning against which lowerings and backend runtimes can be tested.
Core terms remain serializable: host values and executable handler clauses live
only in :class:RuntimeAttachments and are addressed by stable QIEC IDs.
Every number the machine computes is a tensor of the run's
quivers.qiec.numbers.NumberDomain, so a value keeps the gradient of everything it was computed
from, through calls, recursion and handler clauses; a number is read as a host value only where a
branch, an index into structured values, or an item key needs a discrete one.
Handlers are lexical and deep. A resumption reinstalls the matched handler and every inner continuation frame, whereas a handler clause is evaluated only in the outer context. This distinction is easiest to make explicit with the CEK machine below: handling an operation splits the continuation at its matching handler boundary.
RuntimeValidator
¶
A predicate a host value must pass to inhabit a QIEC type.
It returns False to reject the value; True or None accepts it.
OperationClause
¶
A host implementation of one handler operation clause.
It receives the request, the delimited continuation, and the clause's
runtime services, and returns the clause's answer, a :class:Forward, or a
:class:TailResume.
ReturnClause
¶
A host implementation of a handler's return clause.
It receives the handled computation's final value and the clause's runtime services, and returns the handler's answer.
ResponseHook
¶
A callback applied to the reply a forwarded request receives.
It returns the value the resumed computation receives in place of the reply.
EvaluationTraceHook
¶
A callback receiving each evaluator event's name and detail mapping.
EvaluationError
¶
Bases: RuntimeError
Base class for failures at the typed-core/runtime boundary.
MissingAttachmentError
¶
Bases: EvaluationError
A stable runtime reference has no value or handler attachment.
RuntimeTypeMismatch
¶
Bases: EvaluationError
A host result failed the validator for its QIEC result type.
FuelExhaustedError
¶
Bases: EvaluationError
The step budget ran out before the computation finished.
General recursion is allowed to diverge, so a budget is the only way a caller can bound a run. Exhaustion is reported as an ordinary evaluation failure rather than a host recursion error, which the machine's explicit stack never raises.
| PARAMETER | DESCRIPTION |
|---|---|
steps
|
The budget that was exhausted; kept on the error as
TYPE:
|
Source code in src/quivers/qiec/evaluator.py
UnknownComputationError
¶
Bases: EvaluationError
A call names a computation the evaluator was not given a body for.
UnhandledEffectError
¶
UnhandledEffectError(request: EffectRequest)
Bases: EvaluationError
No enclosing lexical handler accepts an effect request.
| PARAMETER | DESCRIPTION |
|---|---|
request
|
The request nothing handled; kept on the error as
TYPE:
|
Source code in src/quivers/qiec/evaluator.py
InvalidHandlerError
¶
Bases: EvaluationError
A runtime handler contradicts its checked structural signature.
HandlerManifest
didactic-model
¶
HandlerManifest(*, definitions: Mapping[HandlerId, HandlerDef] = field(opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
Immutable checked handler definitions accepted by an evaluator.
Construct this from a :class:KernelRegistry after its declarations have
passed kernel registration. Runtime clause objects are then accepted only
when their complete structural definitions equal the manifest entry, not
merely when their stable IDs collide.
| PARAMETER | DESCRIPTION |
|---|---|
definitions
|
The checked handler definitions by identity.
TYPE:
|
from_registry
classmethod
¶
from_registry(registry: KernelRegistry) -> HandlerManifest
Build a manifest from a checked registry.
| PARAMETER | DESCRIPTION |
|---|---|
registry
|
A registry whose handlers have already been checked.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HandlerManifest
|
A manifest over those handlers. |
Source code in src/quivers/qiec/evaluator.py
ResumptionUsageError
¶
Bases: EvaluationError
A handler clause used its resumption outside the declared grade.
NonDuplicableContinuationError
¶
Bases: ResumptionUsageError
An unrestricted clause captured state that cannot safely be copied.
RuntimeConstructor
didactic-model
¶
RuntimeConstructor(*, constructor: ConstructorId = field(opaque=True, extras=OPAQUE_BY_VALUE), static_arguments: tuple[StaticArgument, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), fields: tuple[HeldValue, ...] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), result_type: TypeExpr = field(opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
Erased runtime representation of a checked constructor value.
Constructor metadata, scalar fields, tuples, nested models, and tensors of integers or truth values compare by value. Real tensors and live host objects retain identity, so a gradient is never merged.
| PARAMETER | DESCRIPTION |
|---|---|
constructor
|
The constructor's stable identity.
TYPE:
|
static_arguments
|
The constructor's telescope instantiation, as evaluated static data.
TYPE:
|
fields
|
The evaluated field values, in declaration order.
TYPE:
|
result_type
|
The family type the value inhabits.
TYPE:
|
RuntimeRecord
didactic-model
¶
RuntimeRecord(*, labels: tuple[str, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), values: tuple[HeldValue, ...] = field(opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
Erased runtime representation of a record value.
| PARAMETER | DESCRIPTION |
|---|---|
labels
|
The field labels, in canonical order.
TYPE:
|
values
|
The field values, aligned with
TYPE:
|
field
¶
field(label: str) -> HeldValue
The value of one field.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
The field's label.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HeldValue
|
Its value. |
| RAISES | DESCRIPTION |
|---|---|
EvaluationError
|
If the record has no such field. |
Source code in src/quivers/qiec/evaluator.py
RuntimeVariant
didactic-model
¶
RuntimeVariant(*, label: str, payload: HeldValue = field(opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
Erased runtime representation of a variant value.
| PARAMETER | DESCRIPTION |
|---|---|
label
|
The alternative.
TYPE:
|
payload
|
The value the alternative carries.
TYPE:
|
RuntimeClosure
didactic-model
¶
RuntimeClosure(*, function: Lambda = field(opaque=True, extras=OPAQUE_BY_VALUE), environment: Mapping[Local, HeldValue] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), group: tuple[RecursiveBinding, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
A function value: its code and the bindings it captured.
| PARAMETER | DESCRIPTION |
|---|---|
function
|
The function's code.
TYPE:
|
environment
|
The bindings in scope where the function was built.
TYPE:
|
group
|
The local definitions the function belongs to, which its body sees as closures over the same environment; empty for a function that is not locally recursive.
TYPE:
|
bindings
¶
The bindings the function's body runs under, before its argument.
| RETURNS | DESCRIPTION |
|---|---|
Scope[Local, HeldValue]
|
The captured environment, with each definition of the group bound to its closure. |
Source code in src/quivers/qiec/evaluator.py
HoleClosure
didactic-model
¶
HoleClosure(*, hole: HoleValue = field(opaque=True, extras=OPAQUE_BY_VALUE), environment: Mapping[Local, HeldValue] = field(opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
A typed hole as the machine holds it: the hole and its bindings.
Evaluating a hole builds its closure instead of a value. The closure
flows wherever a value may flow without being inspected (into a
binding, a field, an argument, a result); a step that must inspect it
stops the run with an indeterminate result. Filling the hole evaluates
the filling under environment, the bindings in scope where the hole
was reached, so a filling may mention the locals the hole could see.
| PARAMETER | DESCRIPTION |
|---|---|
hole
|
The hole term reached.
TYPE:
|
environment
|
The bindings in scope where it was reached.
TYPE:
|
AttachmentBinding
didactic-model
¶
AttachmentBinding(*, value: HeldValue = field(opaque=True, extras=OPAQUE_BY_IDENTITY), type: TypeExpr = field(opaque=True, extras=OPAQUE_BY_VALUE), validator: RuntimeValidator = field(opaque=True, extras=OPAQUE_BY_IDENTITY), duplicable: bool = False)
Bases: QiecModel
One host value attached to an otherwise serializable core term.
The value and validator retain identity; its checked type compares by value.
duplicable is a semantic assertion about the host value, not merely a
promise that copy.copy happens to work. Multi-shot resumptions reject
captured attachment values unless this bit was supplied explicitly.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The host value.
TYPE:
|
type
|
The type the value inhabits.
TYPE:
|
validator
|
The predicate that checks a host value against
TYPE:
|
duplicable
|
Whether an unrestricted resumption may capture the value.
TYPE:
|
RuntimeClause
didactic-model
¶
RuntimeClause(*, invoke: OperationClause = field(opaque=True, extras=OPAQUE_BY_IDENTITY), result_validator: RuntimeValidator = field(opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
Executable operation clause and validator for the resumed value.
Both executable callables retain identity.
| PARAMETER | DESCRIPTION |
|---|---|
invoke
|
The clause body, called with the request, its resumption, and a clause context.
TYPE:
|
result_validator
|
The predicate every value resumed through this clause must pass.
TYPE:
|
RuntimeHandler
didactic-model
¶
RuntimeHandler(*, definition: HandlerDef = field(opaque=True, extras=OPAQUE_BY_VALUE), clauses: Mapping[OperationId, RuntimeClause] = field(opaque=True, extras=OPAQUE_BY_VALUE), return_clause: ReturnClause = field(default=_identity_return, opaque=True, extras=OPAQUE_BY_IDENTITY), input_validator: RuntimeValidator = field(default=_accept, opaque=True, extras=OPAQUE_BY_IDENTITY), output_validator: RuntimeValidator = field(default=_accept, opaque=True, extras=OPAQUE_BY_IDENTITY), duplicable_context: bool = False, mutable_context: bool = False, fork_context: Callable[['RuntimeHandler'], 'RuntimeHandler'] | None = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY), context_factory: Callable[[], 'RuntimeHandler'] | None = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY), on_enter: Callable[[], None] | None = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY), on_exit: Callable[[], None] | None = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY), on_drop: Callable[[], None] | None = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
Executable attachment for a structural :class:HandlerDef.
The checked definition contains coverage, grades, input/output types, and introduced effects. This attachment contains only process-local code and state. It is never serialized as QIEC.
Definitions and clause maps compare by value. Executable callbacks retain identity, and each installation creates its own mutable state.
| PARAMETER | DESCRIPTION |
|---|---|
definition
|
The checked declaration this attachment implements.
TYPE:
|
clauses
|
One runtime clause per covered operation, by identity.
TYPE:
|
return_clause
|
How the handler answers the computation's return; the identity return by default.
TYPE:
|
input_validator
|
The predicate the handled computation's result must pass.
TYPE:
|
output_validator
|
The predicate the handler's answer must pass.
TYPE:
|
duplicable_context
|
Whether an unrestricted resumption may capture an installation of this handler.
TYPE:
|
mutable_context
|
Whether an installation carries state; such a handler needs a
TYPE:
|
fork_context
|
Builds an independent copy of an installation for another shot; required when the context is both mutable and duplicable.
TYPE:
|
context_factory
|
Builds a fresh installation each time the handler is installed.
TYPE:
|
on_enter
|
Called when an installation is entered.
TYPE:
|
on_exit
|
Called once when the handled computation completes.
TYPE:
|
on_drop
|
Called once when the handled computation is abandoned instead;
exclusive with
TYPE:
|
RuntimeAttachments
didactic-model
¶
RuntimeAttachments(*, values: dict[AttachmentId, AttachmentBinding] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY), handlers: dict[HandlerId, RuntimeHandler] = field(default_factory=dict, opaque=True, extras=OPAQUE_BY_IDENTITY), numbers: NumberDomain = field(default_factory=default), distributions: DistributionBackend = field(default_factory=distribution_backend, opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
Process-local values and handlers keyed by stable core identifiers.
Each record owns fresh mutable tables whose identities survive updates. It also fixes what the invocation's numbers are and what samples and scores its distributions, so every provider attached to it and every clause running in it read the same.
| PARAMETER | DESCRIPTION |
|---|---|
values
|
Attached host values by attachment identity.
TYPE:
|
handlers
|
Runtime handlers by handler identity.
TYPE:
|
numbers
|
The dtype and device of the invocation's numbers; torch's default floating dtype on the CPU unless given.
TYPE:
|
distributions
|
The backend that samples and scores the invocation's distributions; the installed backend unless given.
TYPE:
|
bind_value
¶
bind_value(attachment: AttachmentId, value: object, type: TypeExpr, *, validator: RuntimeValidator = _accept, duplicable: bool = False) -> AttachmentRef
Attach a host value and return its stable core reference.
| PARAMETER | DESCRIPTION |
|---|---|
attachment
|
The identity the core term refers to the value by.
TYPE:
|
value
|
The host value.
TYPE:
|
type
|
The type the core ascribes to it.
TYPE:
|
validator
|
Checks the value really inhabits that type. The default accepts anything, for a value the static check already settles.
TYPE:
|
duplicable
|
Whether the value may be copied. This is an assertion about the value, not a guess: a multi-shot resumption capturing a non-duplicable attachment is refused, because copying it would give two continuations a shared mutable thing.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AttachmentRef
|
The core reference to use in a term. |
| RAISES | DESCRIPTION |
|---|---|
InvalidHandlerError
|
If the identity is already bound to a different value, type, validator, or duplicability. Rebinding is refused rather than overwriting, since a term already built would silently start meaning something else. |
RuntimeValidationError
|
If the validator rejects the value. |
Source code in src/quivers/qiec/evaluator.py
bind_handler
¶
bind_handler(handler: RuntimeHandler) -> HandlerId
Attach executable clauses to their structural handler identity.
| PARAMETER | DESCRIPTION |
|---|---|
handler
|
The executable handler, already checked against its declaration.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HandlerId
|
The identity it was bound under. |
| RAISES | DESCRIPTION |
|---|---|
InvalidHandlerError
|
If a different handler is already bound to that identity. |
Source code in src/quivers/qiec/evaluator.py
RuntimeRequest
didactic-model
¶
RuntimeRequest(*, core: EffectRequest = field(opaque=True, extras=OPAQUE_BY_VALUE), arguments: tuple[HeldValue, ...] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), resumption_path: tuple[int, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE), dynamic_path: tuple[DynamicAddressFrame, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
An evaluated request supplied to a process-local handler clause.
The core request and address compare by value. Host arguments retain their tuple's identity and the live values it holds.
| PARAMETER | DESCRIPTION |
|---|---|
core
|
The stable request as written, before evaluation.
TYPE:
|
arguments
|
The evaluated value arguments, in order.
TYPE:
|
resumption_path
|
The ordinal of each resumption taken to reach this request.
TYPE:
|
dynamic_path
|
The call, local-instance, and operation-clause frames live when the request was performed, outermost first within each path.
TYPE:
|
instance
property
¶
instance: EffectInstanceId
The lexical instance this request was performed on.
| RETURNS | DESCRIPTION |
|---|---|
EffectInstanceId
|
The instance, which decides which handler answers. |
operation
property
¶
operation: OperationId
The operation requested.
| RETURNS | DESCRIPTION |
|---|---|
OperationId
|
The operation, which decides which clause answers. |
address
property
¶
Return the static, dynamic, and multi-shot address components.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, tuple[tuple[str, str | int], ...], tuple[int, ...]]
|
The source site, the dynamic address frames, and the resumption path. Active caller shots precede the shots already recorded in the request's rewritten provenance. |
ClauseComputation
didactic-model
¶
ClauseComputation(*, computation: Computation = field(opaque=True, extras=OPAQUE_BY_VALUE), bindings: tuple[tuple[Local, HeldValue], ...] = field(default=(), opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
Ask the evaluator to run a structural clause body outside the handler.
The computation compares by value; host bindings retain identity.
Host values introduced by a handler must first be installed through
:meth:ClauseContext.attach; arbitrary callback closures do not enter the
computation tree.
| PARAMETER | DESCRIPTION |
|---|---|
computation
|
The stable computation to run.
TYPE:
|
bindings
|
Locals the computation refers to, each with its evaluated value.
TYPE:
|
Forward
didactic-model
¶
Forward(*, on_response: ResponseHook | None = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
Forward a request to an outer handler, optionally observing its reply.
The optional response hook retains identity.
| PARAMETER | DESCRIPTION |
|---|---|
on_response
|
Called with the outer handler's answer before it reaches the
resumed computation, or
TYPE:
|
TailResume
didactic-model
¶
TailResume(*, value: HeldValue = field(opaque=True, extras=OPAQUE_BY_IDENTITY), arguments: tuple[HeldValue, ...] | None = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
Resume a clause's continuation in place, on the machine's own stack.
The resumed host value retains identity, including tensor gradients.
A foreign clause that answers with this resumes once, exactly as an
authored resume(value) in tail position does: the captured frames
return to the machine's stack and the handler's return clause applies
when the computation completes. Unlike calling the resumption from
the clause, which drives the continuation in a nested host call that
stays pending until it returns, this leaves no host frame behind, so a
multi-shot resumption captured later inside the same handler may run
the continuation any number of times.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
What the resumed operation supplies.
TYPE:
|
arguments
|
The values the handler's parameters have while the continuation
runs, or
TYPE:
|
ContinuationFrame
didactic-model
¶
Bases: QiecModel
One frame of the reference evaluator's explicit continuation stack.
The evaluator creates and consumes every frame. A handler clause sees
frames only through the :class:ClauseContext and :class:Resumption
the evaluator hands it, and never inspects or builds one itself; the
class exists so those two constructors can name the stack they capture.
Frame subclasses compare checked kernel terms by value and retain live environments, handler state, and callbacks by identity.
ClauseContext
¶
ClauseContext(evaluator: Evaluator, environment: Mapping[Local, object], outer_stack: tuple[ContinuationFrame, ...], resumption_path: tuple[int, ...], request: RuntimeRequest | None, arguments: tuple[object, ...])
Disciplined runtime services available to an attached handler clause.
| PARAMETER | DESCRIPTION |
|---|---|
evaluator
|
The evaluator running the clause.
TYPE:
|
environment
|
The bindings in scope at the handler.
TYPE:
|
outer_stack
|
The continuation frames outside the handler.
TYPE:
|
resumption_path
|
The ordinal of each resumption taken to reach the clause.
TYPE:
|
request
|
The request the clause answers, or
TYPE:
|
arguments
|
The current values of the handler's parameters.
TYPE:
|
Source code in src/quivers/qiec/evaluator.py
request
property
¶
request: RuntimeRequest | None
The request this clause is answering.
| RETURNS | DESCRIPTION |
|---|---|
RuntimeRequest or None
|
The request, or None in a return clause, which answers a completed computation rather than an operation. |
arguments
property
¶
The current values of the handler's parameters.
| RETURNS | DESCRIPTION |
|---|---|
tuple[object, ...]
|
One value per declared parameter, in declaration order. |
attachments
property
¶
attachments: RuntimeAttachments
The host values available to this clause.
| RETURNS | DESCRIPTION |
|---|---|
RuntimeAttachments
|
The evaluator's attachment table. |
emit_trace
¶
Emit a handler event through an installed execution observer.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
The stable event name.
TYPE:
|
detail
|
A function producing JSON-compatible data, or None to omit the event. Without a trace hook, the function is never called.
TYPE:
|
Source code in src/quivers/qiec/evaluator.py
evaluate
¶
evaluate(computation: Computation) -> object
Evaluate a clause body in the outer handler context.
A delimiter prevents the clause body from consuming the continuation outside the handled expression. Effects performed here can reach only handlers outside the matched handler, which is the chosen deep-handler semantics.
| PARAMETER | DESCRIPTION |
|---|---|
computation
|
The clause body to run.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
What the body produced. |
Source code in src/quivers/qiec/evaluator.py
attach
¶
attach(value: object, type: TypeExpr, *, role: str, validator: RuntimeValidator = _accept, duplicable: bool = False) -> AttachmentRef
Install a generated host value under a deterministic runtime ID.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The host value to attach.
TYPE:
|
type
|
The type the core ascribes to it.
TYPE:
|
role
|
What the value is for, which enters its derived identity.
TYPE:
|
validator
|
Checks the value inhabits the type.
TYPE:
|
duplicable
|
Whether the value may be copied by a multi-shot resumption.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
AttachmentRef
|
A reference usable in a core term. The identity derives from the run, the request, and the role rather than being generated, so a trace can name the same attachment twice. |
Source code in src/quivers/qiec/evaluator.py
Resumption
¶
Resumption(evaluator: Evaluator, request: RuntimeRequest, grade: ResumptionGrade | ResumptionInterval, captured_environment: Mapping[Local, object], captured_stack: tuple[ContinuationFrame, ...], outer_stack: tuple[ContinuationFrame, ...], validator: RuntimeValidator, path: tuple[int, ...])
Dynamically checked, delimited continuation supplied to one clause.
| PARAMETER | DESCRIPTION |
|---|---|
evaluator
|
The evaluator that captured the continuation.
TYPE:
|
request
|
The request whose result the continuation awaits.
TYPE:
|
grade
|
How often the clause may invoke the continuation.
TYPE:
|
captured_environment
|
The bindings in scope at the request.
TYPE:
|
captured_stack
|
The continuation frames between the request and the handler.
TYPE:
|
outer_stack
|
The continuation frames outside the handler.
TYPE:
|
validator
|
The predicate every resumed value must pass.
TYPE:
|
path
|
The ordinal of each resumption taken to reach the clause.
TYPE:
|
Source code in src/quivers/qiec/evaluator.py
grade
property
¶
grade: ResumptionGrade | ResumptionInterval
The grade this resumption is held to.
| RETURNS | DESCRIPTION |
|---|---|
ResumptionGrade or ResumptionInterval
|
The declared grade, checked statically and again here. |
calls
property
¶
How many times this resumption has been invoked so far.
| RETURNS | DESCRIPTION |
|---|---|
int
|
The count, which the grade bounds. |
__call__
¶
__call__(value: object, arguments: tuple[HeldValue, ...] | None = None) -> object
Resume the suspended computation with a value.
The static analysis already rejects a clause that can exceed its grade. This guard stays because it protects against a foreign handler, whose body the analysis never saw, and against a compiler bug: a grade is what lets a runtime discard a continuation, so exceeding it is not recoverable.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
What the resumed operation supplies.
TYPE:
|
arguments
|
The values the handler's parameters have while the
continuation runs, or
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
What the resumed computation produced. |
| RAISES | DESCRIPTION |
|---|---|
ResumptionUsageError
|
If the next call exceeds the grade's upper bound or an interval token is closed or shared. |
NonDuplicableContinuationError
|
If an unrestricted resumption would have to copy a captured value that is not duplicable. |
RuntimeValidationError
|
If the value does not inhabit the operation's result type. |
Source code in src/quivers/qiec/evaluator.py
2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 | |
Evaluator
¶
Evaluator(attachments: RuntimeAttachments | None = None, *, handler_manifest: HandlerManifest | None = None, trace_hook: EvaluationTraceHook | None = None, module: QiecModule | None = None, fuel: int | None = None, type_validator: Callable[[TypeExpr], RuntimeValidator | None] | None = None)
Execute QIEC computations with explicit runtime attachments.
| PARAMETER | DESCRIPTION |
|---|---|
attachments
|
The host values and handlers available; empty by default.
TYPE:
|
handler_manifest
|
Checked handler definitions every attached handler must match
exactly on each :meth:
TYPE:
|
trace_hook
|
Called with each execution event's name and payload, or
TYPE:
|
module
|
The module whose named computations calls resolve to and whose
authored handlers
TYPE:
|
fuel
|
The number of machine steps a run may take before failing with
:class:
TYPE:
|
type_validator
|
Supplies the host validator for a type at an authored handler's
boundaries: the values it is resumed with, the handled
computation's result, and its answer.
TYPE:
|
Source code in src/quivers/qiec/evaluator.py
evaluate
¶
evaluate(computation: Computation, environment: Mapping[Local, object] | None = None) -> object
Evaluate a closed or explicitly supplied computation.
| PARAMETER | DESCRIPTION |
|---|---|
computation
|
The computation to run.
TYPE:
|
environment
|
Values for the computation's free locals. None means it is closed.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
What the computation produced. |
| RAISES | DESCRIPTION |
|---|---|
EvaluationError
|
If a request reaches no handler, a handler is missing from the manifest, a resumption exceeds its grade, or a host value fails validation. |
Source code in src/quivers/qiec/evaluator.py
evaluate_checked
¶
evaluate_checked(computation: Computation, registry: KernelRegistry, environment: Mapping[Local, object] | None = None) -> object
Kernel-check a computation and fail closed on handler attachments.
| PARAMETER | DESCRIPTION |
|---|---|
computation
|
The computation to run.
TYPE:
|
registry
|
Declarations to check it against.
TYPE:
|
environment
|
Values for its free locals.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
What the computation produced. |
| RAISES | DESCRIPTION |
|---|---|
KernelError
|
If the computation does not check. |
EvaluationError
|
If execution fails, as in |
Source code in src/quivers/qiec/evaluator.py
evaluate_validated
¶
evaluate_validated(computation: Computation, registry: KernelRegistry, environment: Mapping[Local, object] | None = None) -> object
Run a computation a module validation has already checked.
validate_module checks every body of a module against its
registry; a caller holding that registry runs such a body
without checking it again. The handler manifest is still held
against the attachments.
| PARAMETER | DESCRIPTION |
|---|---|
computation
|
The computation to run, a body of the validated module.
TYPE:
|
registry
|
The registry the module validated against.
TYPE:
|
environment
|
Values for its free locals.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
What the computation produced. |
| RAISES | DESCRIPTION |
|---|---|
EvaluationError
|
If execution fails, as in |
Source code in src/quivers/qiec/evaluator.py
evaluate_value
¶
Erase and evaluate a checked QIEC value.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The value to evaluate.
TYPE:
|
environment
|
Values for its free locals.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
object
|
The value as the machine holds it, or an |
Source code in src/quivers/qiec/evaluator.py
resume
¶
resume(indeterminate: Indeterminate, fills: Mapping[str, Value]) -> HeldValue
Fill holes and continue an indeterminate run where it stopped.
A suspended run continues from the step that needed a hole, so nothing before that step runs again; a run that finished with open holes in its value has those holes replaced by their fillings. A filling is a value evaluated under the bindings of the hole it fills, and may contain holes of its own. Fillings accumulate: a hole filled once stays filled for every later resumption of this evaluator.
| PARAMETER | DESCRIPTION |
|---|---|
indeterminate
|
The result of a run of this evaluator.
TYPE:
|
fills
|
Fillings by hole name. The caller has checked each against its hole's goal.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
HeldValue
|
The run's value, or a further |
| RAISES | DESCRIPTION |
|---|---|
EvaluationError
|
If the suspension is not this evaluator's latest one (a suspension is a one-shot continuation), or the hole was needed inside host code, whose frames could not be suspended. |
Source code in src/quivers/qiec/evaluator.py
3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 | |
abandon
¶
abandon(indeterminate: Indeterminate) -> None
Release the handlers a suspended run holds, without resuming it.
| PARAMETER | DESCRIPTION |
|---|---|
indeterminate
|
The result of a run of this evaluator.
TYPE:
|
Source code in src/quivers/qiec/evaluator.py
Suspension
didactic-model
¶
Suspension(*, evaluator: Evaluator = field(opaque=True, extras=OPAQUE_BY_IDENTITY), current: Computation | _Returned = field(opaque=True, extras=OPAQUE_BY_IDENTITY), environment: Mapping[Local, HeldValue] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), stack: tuple[_Frame, ...] = field(opaque=True, extras=OPAQUE_BY_IDENTITY), resumption_path: tuple[int, ...] = field(opaque=True, extras=OPAQUE_BY_VALUE))
Bases: QiecModel
The state of a run stopped at a step that needs an open hole.
The step has not run, so continuing the state after the hole is filled replays exactly that step. A suspension is a one-shot continuation: its frames own live handler state, so it resumes once.
| PARAMETER | DESCRIPTION |
|---|---|
evaluator
|
The evaluator that stopped, which alone can continue it.
TYPE:
|
current
|
The step that needs the hole.
TYPE:
|
environment
|
The bindings in scope at that step.
TYPE:
|
stack
|
The frame stack beneath it.
TYPE:
|
resumption_path
|
The resumption address in force.
TYPE:
|
Indeterminate
didactic-model
¶
Indeterminate(*, value: HeldValue = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY), needed: HoleClosure | None = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY), closures: tuple[HoleClosure, ...] = field(default=(), opaque=True, extras=OPAQUE_BY_IDENTITY), suspension: Suspension | None = field(default=None, opaque=True, extras=OPAQUE_BY_IDENTITY))
Bases: QiecModel
The result of a run that depends on a hole with no filling.
A run around holes produces one of two indeterminate results. If a
step had to inspect an open hole, the run stopped there: needed is
that hole's closure and suspension continues the run after a
filling. If the run finished but its value holds open holes (a hole
returned, or stored in a field), value is that partial value and
closures lists its open holes; filling them settles the value.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
The partial value, or None when the run stopped before finishing.
TYPE:
|
needed
|
The closure of the hole the run stopped on, if it stopped.
TYPE:
|
closures
|
Every open hole closure the result depends on, in the order met.
TYPE:
|
suspension
|
The suspended machine, when the run stopped where the evaluator can continue it; None for a finished run or for a hole needed inside a foreign handler clause.
TYPE:
|
holes
¶
The names of the open holes the result depends on.
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, ...]
|
Each name once, in the order met. |
Source code in src/quivers/qiec/evaluator.py
Cited sources¶
John C. Reynolds. Definitional Interpreters for Higher-Order Programming Languages. In Proceedings of the ACM Annual Conference, volume 2, 717–740. 1972. doi:10.1145/800194.805852.