Skip to main content

Compiler

Struct Compiler 

Source
pub struct Compiler { /* private fields */ }
Expand description

A checking pipeline, and the Host API schemas it reads.

The default reads the shipped schemas and nothing else, which is what every cove command does. An embedder adds the modules it registers.

Implementations§

Source§

impl Compiler

Source

pub fn new() -> Compiler

A pipeline that reads the shipped Host API schemas.

Source

pub fn with_host_schema(self, schema: ModuleSchema) -> Compiler

Adds one host module’s description.

The schema is checked against exactly as a shipped module’s is: the module may be named by a use, no package module may shadow it, calls into it are checked at the call site, its types may be written and initialized, its resources answer the operations it declares, and a function reaching it requires the capability the schema names.

Source

pub fn with_host_schemas( self, schemas: impl IntoIterator<Item = ModuleSchema>, ) -> Compiler

Adds every host module in schemas.

This is what pairs a checker with a set of registered hosts in one line: cove_runtime::HostRegistry::module_schemas hands back the table every registered module declared itself with, and passing it here checks the program against the same descriptions the run will enforce.

Source

pub fn with_schemas(self, schemas: HostSchemas) -> Compiler

Reads schemas and nothing else, replacing whatever this pipeline was reading.

This is how an embedding whose registry is its own says so. with_host_schema and with_host_schemas add to the shipped tables, which is right for a run that registers the shipped hosts and some of its own. A run that registers neither wants cove_schema::HostSchemas::only, so that a use files in a program it is about to run is reported by the checker rather than by the boundary:

let program = Compiler::new()
    .with_schemas(HostSchemas::only(hosts.module_schemas()))
    .compile(&package)?;
Source

pub fn host_schemas(&self) -> &HostSchemas

The host modules this pipeline can see.

Source

pub fn resolve(&self, package: &Package) -> Result<Program, Vec<Diagnostic>>

Resolves package: names, imports, capabilities, and the call graph.

Source

pub fn check(&self, package: &Package, program: &Program) -> Vec<Diagnostic>

Type-checks an already resolved package, reporting errors and warnings together.

Source

pub fn compile(&self, package: &Package) -> Result<Program, Vec<Diagnostic>>

Resolves and type-checks package, which is what cove check does.

The returned program carries Program::facts: the type the checker settled for every expression, and the declaration each resolved method call reaches.

Warnings and notes from both halves are carried on the returned program’s Program::notices rather than mixed into its errors, so a caller can report them without having to decide which of them stopped anything. A failure reports the errors first and the warnings after, because a reader looking for what went wrong should not have to read past what merely could.

Trait Implementations§

Source§

impl Clone for Compiler

Source§

fn clone(&self) -> Compiler

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 Compiler

Source§

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

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

impl Default for Compiler

Source§

fn default() -> Compiler

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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, 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.