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
impl Checked
Sourcepub fn schema(&self) -> SchemaIndex
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
impl Checked
Sourcepub fn summary(&self) -> String
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
impl Checked
Sourcepub fn warnings(&self) -> &Diagnostics
pub fn warnings(&self) -> &Diagnostics
Returns the warnings found while checking.
Sourcepub fn files(&self) -> impl Iterator<Item = (FileId, &str)>
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.
Sourcepub fn inputs(&self) -> impl Iterator<Item = (&Path, &str)>
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
impl Checked
Sourcepub fn eval(&self, limits: &Limits) -> Result<Evaluated, Diagnostics>
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}"#);