pub enum Ty {
Show 27 variants
Unknown(Unknown),
Never,
Any,
Unit,
Bool,
Int,
Float,
Str,
Duration,
Error,
Range,
Array(Box<Ty>),
Vector(Box<Ty>),
Set(Box<Ty>),
Map(Box<Ty>, Box<Ty>),
MapEntry(Box<Ty>, Box<Ty>),
Option(Box<Ty>),
Result(Box<Ty>, Box<Ty>),
Task(Box<Ty>),
Shared(Box<Ty>),
Scope,
Struct(Arc<str>, Vec<Ty>),
Enum(Arc<str>, Vec<Ty>),
Fn(Arc<FnTy>),
Param(Arc<str>),
Dyn(Arc<str>),
Host(Arc<str>),
}Expand description
A Cove type.
A name inside one is shared by Arc rather than std::rc::Rc
because a type outlives the check that settled it: it is recorded in
Facts and published on Program, which the runtime holds behind an
Arc and moves onto the stack it runs a program on. Sharing atomically
is what lets a type be a fact about a checked package rather than a value
that dies with the checker.
Variants§
Unknown(Unknown)
The checker could not determine this type; see the module docs.
Never
The type of an expression that never produces a value, such as
return.
Any
Any: a value of some type, which a Host API schema declares where
nothing it does depends on which type that is.
This is a promise and not an absence, which is why it is a type of
its own rather than a Ty::Unknown. A schema writing
cove_schema::HostType::Any has said something exact — every value
is accepted here, and what comes back is checked at the boundary and
by nothing before it — where an unknown says only that the checker
did not find out. Spelling them the same made a call’s result and a
type parameter nobody settled indistinguishable, and left the
lowering asking the schema again at every position a value is
produced because the type it was handed could not tell it which of
the two it had.
It carries no information, so it compares equal to every type and
every operation on it abstains — exactly what the unconstrained
unknown standing here used to do, and the reason this change moves
no diagnostic. What it is not is a dyn Trait: the two share one
erased representation (docs/LINEAR_VM.md), and sharing a
representation is what cove_ir’s Shapes is for. As types they
are opposites — a dyn Display accepts only a conforming value and
answers only the trait’s methods, an Any accepts every value and
answers everything at run time — so writing one as the other would
put an exception on every Ty::Dyn in this pass and a reserved
trait name in the language.
Unit
Bool
Int
Float
Str
Duration
Error
Range
Array(Box<Ty>)
Vector(Box<Ty>)
Set(Box<Ty>)
Map(Box<Ty>, Box<Ty>)
MapEntry(Box<Ty>, Box<Ty>)
One key/value pair: what Map.of collects and what for binds
over a Map.
Option(Box<Ty>)
Result(Box<Ty>, Box<Ty>)
Task(Box<Ty>)
Shared<T>: mutable state more than one task may reach.
The Language Card names it in the sentence that keeps a vector out of
a task, and ADR 0008 makes it the one value that crosses a task
boundary by sharing rather than by copying. Its argument must
therefore be task-safe itself: a Shared<Vector<T>> would let a
vector be reached from two tasks, which is what that sentence forbids.
Scope
The value scope name { ... } binds.
Struct(Arc<str>, Vec<Ty>)
A struct this module declares, with its type arguments.
Enum(Arc<str>, Vec<Ty>)
An enum this module declares, with its type arguments.
Fn(Arc<FnTy>)
Param(Arc<str>)
A type parameter, rigid inside the body that declares it.
Dyn(Arc<str>)
dyn Display: a value of some type that conforms to the named trait,
carrying its implementation with it.
This is a type of its own, not a type parameter: it cannot be written
where a bounded type parameter is expected, and only the trait’s
self-taking methods can be called on it.
Host(Arc<str>)
A type a host module declares, named the way Cove source writes it:
http.Request, database.Connection.
It is nominal like every other type here and carries no arguments,
because cove_schema::HostType has none to carry. Whether the host
hands the value over or keeps it — a TypeSchema or a
ResourceSchema — does not change how it is written or compared, so
it does not change this either; what the schema says about it decides
what may be read from it and what may be called on it.
Implementations§
Source§impl Ty
impl Ty
Sourcepub fn instantiate(&self, generics: &[Arc<str>], args: &[Ty]) -> Ty
pub fn instantiate(&self, generics: &[Arc<str>], args: &[Ty]) -> Ty
This type as it stands when generics are the arguments args.
A declared type’s fields and an enum case’s payload are recorded once,
in terms of the type parameters the declaration binds:
Box<T>’s field is a T however many Box<Int>s a program holds. A
consumer holding a use — a Ty::Struct(name, args) — completes them
with this. args shorter than generics leaves the rest unknown,
which is what an unsettled type argument already means.
Trait Implementations§
Source§impl Display for Ty
Renders a type in the source form it would be written in, so a diagnostic
shows the type the reader wrote.
impl Display for Ty
Renders a type in the source form it would be written in, so a diagnostic shows the type the reader wrote.