Program

Struct Program 

Source
pub struct Program {
    pub name: Identifier,
    pub constants: BTreeMap<QualifiedIdentifier, Constant>,
    pub evaluators: BTreeMap<QualifiedIdentifier, EvaluatorFunction>,
    pub functions: BTreeMap<QualifiedIdentifier, Function>,
    pub buses: BTreeMap<QualifiedIdentifier, Bus>,
    pub periodic_columns: BTreeMap<QualifiedIdentifier, PeriodicColumn>,
    pub public_inputs: BTreeMap<Identifier, PublicInput>,
    pub trace_columns: Vec<TraceSegment>,
    pub boundary_constraints: Vec<Statement>,
    pub integrity_constraints: Vec<Statement>,
}
Expand description

This represents a fully parsed AirScript program, with all imports resolved/parsed/merged.

It has undergone initial semantic analysis, which guarantees that all names are resolved to their definitions. Semantic analysis also runs a variety of validation checks while performing name resolution, including basic type checking, constraint validation, and more.

Additionally, a Program has had most dead code eliminated. Specifically any items which are not referred to from the root module directly or transitively, are not present in the Program structure. Currently, analysis doesn’t check for dead code within functions or constraint blocks, so that is the only area in which dead code may still exist.

Fields§

§name: Identifier

The name of an AirScript program is the name of its root module.

§constants: BTreeMap<QualifiedIdentifier, Constant>

The set of used constants referenced in this program.

§evaluators: BTreeMap<QualifiedIdentifier, EvaluatorFunction>

The set of used evaluator functions referenced in this program.

§functions: BTreeMap<QualifiedIdentifier, Function>

The set of used pure functions referenced in this program.

§buses: BTreeMap<QualifiedIdentifier, Bus>

The set of used buses referenced in this program.

§periodic_columns: BTreeMap<QualifiedIdentifier, PeriodicColumn>

The set of used periodic columns referenced in this program.

§public_inputs: BTreeMap<Identifier, PublicInput>

The set of public inputs defined in the root module

NOTE: Public inputs are only visible in the root module, so we do not use QualifiedIdentifier as a key into this collection.

§trace_columns: Vec<TraceSegment>

The set of trace columns of the main trace defined in the root module

§boundary_constraints: Vec<Statement>

The boundary_constraints block defined in the root module

It is guaranteed that this is non-empty

§integrity_constraints: Vec<Statement>

The integrity_constraints block in the root module

It is guaranteed that this is non-empty

Implementations§

Source§

impl Program

Source

pub fn new(name: Identifier) -> Self

Creates a new, empty Program.

§SAFETY

This function technically violates the guarantees described above in the module docs, however it is useful for testing purposes to allow constructing a valid Program piece-by-piece. It is up to the caller to ensure that they construct a Program that adheres to all of the expected guarantees.

NOTE: It isn’t strictly unsafe in the Rust sense to fail to uphold the guarantees described above; it will simply cause compilation to fail unexpectedly with a panic at some point. As a result, this function isn’t marked unsafe, but should be treated like it is anyway.

Source

pub fn load( diagnostics: &DiagnosticsHandler, root: ModuleId, library: Library, ) -> Result<Self, SemanticAnalysisError>

Load a program from a library of modules, of which one should be a root module.

When called, it is expected that the library has had import resolution performed, and that the library contains a root module.

Trait Implementations§

Source§

impl Debug for Program

Source§

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

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

impl Display for Program

Source§

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

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

impl Parse for Program

Source§

type Parser = ProgramParser

The concrete type of the parser implementation Read more
Source§

type Error = ParseError

The concrete type of errors which are produced by the parser Read more
Source§

type Config = ()

The concrete type representing the parser configuration. Read more
Source§

type Token = Result<(SourceIndex, Token, SourceIndex), ParseError>

The concrete type of the lexical token consumed by the parser Read more
Source§

fn root_file_error(source: Error, path: PathBuf) -> Self::Error

Constructs an instance of Self::Error when a [std:::io::Error] is raised Read more
Source§

fn parse<S>( parser: &Parser, diagnostics: &DiagnosticsHandler, source: S, ) -> Result<Self, Self::Error>
where S: Source,

Parses a [T] from the given Source. Read more
Source§

fn parse_tokens<S: IntoIterator<Item = Result<(SourceIndex, Token, SourceIndex), ParseError>>>( diagnostics: &DiagnosticsHandler, codemap: Arc<CodeMap>, tokens: S, ) -> Result<Self, Self::Error>

Parses a [T] from the given token stream. Read more
Source§

impl PartialEq for Program

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · 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 Eq for Program

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.