Skip to main content

Checked

Struct Checked 

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

A program that passed every check, ready to be evaluated.

It owns every source file of the root, the declarations with their resolved types, the type and meaning of every expression, and the warnings found on the way.

Implementations§

Source§

impl Checked

Source

pub fn schema(&self) -> SchemaIndex

Returns every declared struct field and sum variant with its doc comment, for tooling such as completion and documentation.

Source§

impl Checked

Source

pub fn summary(&self) -> String

Returns a readable listing of what the checker inferred: the root struct, the signature of every top-level function and the type of every top-level let, the call graph, and, for every checked body, what each statement contributes to, with its type and priority and the self fields it reads.

The listing is meant for tests and debugging. Its format may change in any release.

Source§

impl Checked

Source

pub fn warnings(&self) -> &Diagnostics

Returns the warnings found while checking.

Source

pub fn files(&self) -> impl Iterator<Item = (FileId, &str)>

Returns every file of the program with its display name, in the order the files were loaded.

Source

pub fn source(&self, file: FileId) -> Option<&str>

Returns the source text of a file.

Source

pub fn inputs(&self) -> impl Iterator<Item = (&Path, &str)>

Returns every source file the program was read from, with its exact source text, once each and ordered by path.

A file inside an import root is named by the import root joined with its relative path, a standard module by std/<name>, a host module by its import path such as ns/target, and a prelude file or implicit part by the name the host gave it. The program depends only on these texts and on the configuration of the host, so a host can key a cache of evaluations by hashing both with a hash function of its choice.

Source§

impl Checked

Source

pub fn eval(&self, limits: &Limits) -> Result<Evaluated, Diagnostics>

Evaluates the program within limits.

Statements are evaluated in order: the host’s implicit parts first, then the entry files. Their contributions are merged by priority, self is resolved on the merged value, and the final value is checked for missing required fields, refinements and references.

§Errors

Returns the diagnostics of the evaluation when it fails: the first error of evaluating an expression, such as a division by zero or a crossed limit, or every conflict of the merge, every self cycle, every missing required field, every violated refinement and every reference to an undeclared block.

§Examples
use stav::{Host, ImportRoot, Limits, MemoryLoader, RootSpec};

let base = "struct Root { port: Int = 80 }\nport = default(8080)\n";
let prod = "port = 443\n";
let loader = MemoryLoader::new()
    .with_file("app/base.stav", base)
    .with_file("app/prod.stav", prod);
let root = RootSpec {
    root_struct: "Root".to_owned(),
    entries: vec!["app/base.stav".into(), "app/prod.stav".into()],
    import_roots: vec![ImportRoot::new("app")],
};
let evaluated = stav::check(&Host::new(loader), &root)?.eval(&Limits::default())?;
assert_eq!(evaluated.to_canonical_json(), r#"{"port":443}"#);

Trait Implementations§

Source§

impl Debug for Checked

Source§

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

Formats the value using the given formatter. 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.