Skip to main content

Ty

Enum Ty 

Source
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(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

Source

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 Clone for Ty

Source§

fn clone(&self) -> Ty

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Ty

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
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.

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Ty

Source§

fn eq(&self, other: &Ty) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Ty

Auto Trait Implementations§

§

impl Freeze for Ty

§

impl RefUnwindSafe for Ty

§

impl Send for Ty

§

impl Sync for Ty

§

impl Unpin for Ty

§

impl UnsafeUnpin for Ty

§

impl UnwindSafe for Ty

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.