Skip to main content

Module value

Module value 

Source
Expand description

Runtime values.

Assignment and ordinary argument passing use one rule: field-wise shallow copy. That rule is encoded directly in Clone: cloning a struct or enum copies its fields, cloning an Array shares immutable storage, and cloning a Vector copies only the handle so aliases observe the same elements and length. Cove never performs an implicit deep copy.

§What an embedding host should write

A host builds a value through a constructor — Value::unit, Value::bool, Value::int, Value::float, Value::duration, Value::string, Value::range_of, Value::array, Value::set, Value::map, Value::structure, Value::enumeration, Value::from_resource, Value::host_fn, Value::host_module, Value::type_value, Value::ok, Value::err, Value::some, Value::none, Value::error — and reads one through a reader: Value::field, Value::fields, Value::case, Value::payload, Value::items, Value::elements, Value::entries, Value::declared_type, Value::range, Value::resource, Value::host_op, Value::arity, and the scalar as_* family. Between them they cover every shape that crosses the Host API boundary, and none of them says how the runtime holds one.

A host that wants to be told what kind of value it has calls Value::view and matches ValueView, which is exhaustive on purpose.

There is no variant to match, and that is the point. Value’s variants were pub until ADR 0028, and every change to what a value is was therefore a source break for the hosts that matched one: issue #104 moved a struct from a Box to an Rc, issue #109 put a bound host operation’s two names behind one pointer to take every value in the program from forty bytes to twenty-four, issue #121 replaced a closure’s parameter list with an arity, and issue #183 replaced an enum payload’s Vec<Value> with Payload. Each was invisible through the constructors and visible through a match, and each was rescued individually — twice by luck and once by a hand-written Deref shim. Issue #196 asked whether that should keep being paid for; ADR 0028 decision 6 answers no, for every variant and not a chosen subset, because a partial seal leaves the API a mixture and makes “which half may I match on” a question every embedder has to hold in their head.

What a host loses is the compile error that said the language changed, and ValueView gives exactly that back: after this a representation change is invisible and a new kind of Cove value is a compile error at every match, which is the right way round.

The readers are issue #186’s answer to the same question on the way out; what they promise, what borrowing them forecloses, and what they do with a wrong shape are stated once, on the impl Value block that holds them.

Structs§

Closure
A closure captures its environment by value at creation time.
ClosureView
What a host may read of a callback.
DynValue
The contents of a dyn Trait value, which Value::dyn_trait names and no other reader admits.
Elements
A Vector’s elements, borrowed.
Entries
A Map’s entries, in ascending key order.
EnumValue
EnumView
An enum value’s name, case, and payload.
HostFnValue
The two names a bound host operation is: the host module the operation belongs to, and the operation itself.
InvalidKey
Why a value cannot be a Map key or Set element.
LinearClosure
A closure the linear-memory backend made: which function runs, and the environment object it reads its captures out of.
Members
A Set’s elements, in ascending key order.
RangeBounds
The half-open bounds of a Range value, widened to i128 so that an inclusive i64::MAX end cannot overflow.
SharedView
A Shared cell, which has nothing readable on it.
StructValue
StructView
A struct value’s name and fields.
TaskScopeView
What a host may read of a task scope.
TaskView
What a host may read of a task handle.
Value
A Cove value.
VectorStorage
Growable vector storage. Length, capacity, and elements all belong to the shared storage, so growth stays visible through every alias.

Enums§

ClosureBody
Where a closure’s body is, which is the one thing about a closure the two backends do not agree on.
MapKey
A value usable as a Map key or Set element.
Payload
What an enum case carries, held inline for the arities that occur.
ValueView
What kind of Cove value this is: the stable public classification, and the exhaustive match a host is allowed to write.