pub struct OperationSchema {
pub name: &'static str,
pub params: &'static [HostType],
pub variadic: bool,
pub result: HostType,
pub capability: &'static str,
pub effect: Effect,
pub cancellable: bool,
pub recordable: bool,
pub result_is_task_safe: bool,
}Expand description
One operation of one host module.
Every field is read by something: HostRegistry::call checks name and
arity before it dispatches, holds a call to params before the host sees
it and the host to result after it answers, params and result render
the signature a diagnostic shows, capability is the gate, and
result_is_task_safe answers the Language Card’s rule for values leaving
a host call for a task. cove-sema reads params and result too, at
the call site, where a mistake still has a span to point at. effect,
cancellable, and recordable are the three ADR 0001 facts whose
consumers are named but not yet built — cove replay for recordable,
cove impact for effect, and for cancellable, a host that could
abandon a call in flight: a cancelled task stops at its next safepoint,
which is after the call it is already inside returns.
Fields§
§name: &'static strThe name Cove source calls, such as println.
params: &'static [HostType]Parameter types in declaration order.
This is a promise both ends hold a call to rather than a label on it:
cove check checks each argument at its call site, and the boundary
checks them again for the hosts the checker cannot see.
variadic: boolWhether the last parameter is variadic.
Cove writes a variadic parameter items: T... and makes it an
immutable Array<T> inside the callee, so it accepts zero or more
arguments: a variadic operation’s minimum arity is one less than
params.len().
result: HostTypeThe type the operation produces.
This is a promise the boundary holds the host to rather than a label
on it: HostRegistry checks what the host answered against this
before handing it on, so an operation cannot declare one type and
produce another. cove_runtime::schema::Admits says how far the check
goes.
capability: &'static strThe capability a host must grant before this operation may be called.
effect: EffectWhether the operation reads, writes reversibly, or writes irreversibly.
cancellable: boolWhether abandoning a call that is already in flight is meaningful and safe. A wait can be abandoned because nothing has happened yet; a write that has already reached the outside world cannot.
recordable: boolWhether the call’s result can be recorded and handed back later
without calling the host again, which is what cove replay needs.
An operation that opens a resource is recordable, because ADR 0013 makes a handle a name rather than a live thing: what the trace records is the identity the host issued, and a replay hands the same identity back and answers the calls made on it from the trace too.
result_is_task_safe: boolWhether the value this operation produces may cross a task boundary.
The Language Card puts this decision here rather than in the value: “Host resources declare task-safety in their Host API schema.”
Implementations§
Source§impl OperationSchema
impl OperationSchema
Sourcepub fn accepts(&self, arity: usize) -> bool
pub fn accepts(&self, arity: usize) -> bool
Whether a call with arity arguments has the right number of them.
Sourcepub fn param(&self, index: usize) -> Option<&'static HostType>
pub fn param(&self, index: usize) -> Option<&'static HostType>
The type declared for the argument at index.
A variadic operation’s last parameter answers for every argument from
its own position onwards, because that is what items: T... means:
one declared T and as many arguments of it as the call likes. An
index past a fixed operation’s parameters has no declared type, which
is an arity mistake and reported as one.
Sourcepub fn signature(&self) -> String
pub fn signature(&self) -> String
The signature, in the form it would be written in Cove source, without
the module qualifier: println(String...) -> Result<Unit, Error>.
Sourcepub fn expected_arity(&self) -> String
pub fn expected_arity(&self) -> String
How many arguments this operation takes, phrased for a diagnostic.
Trait Implementations§
Source§impl Clone for OperationSchema
impl Clone for OperationSchema
Source§fn clone(&self) -> OperationSchema
fn clone(&self) -> OperationSchema
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for OperationSchema
Source§impl Debug for OperationSchema
impl Debug for OperationSchema
impl Eq for OperationSchema
Source§impl PartialEq for OperationSchema
impl PartialEq for OperationSchema
Source§fn eq(&self, other: &OperationSchema) -> bool
fn eq(&self, other: &OperationSchema) -> bool
self and other values to be equal, and is used by ==.