Module

Struct Module 

Source
pub struct Module {
Show 13 fields pub span: SourceSpan, pub name: ModuleId, pub ty: ModuleType, pub imports: BTreeMap<ModuleId, Import>, pub constants: BTreeMap<Identifier, Constant>, pub evaluators: BTreeMap<Identifier, EvaluatorFunction>, pub functions: BTreeMap<Identifier, Function>, pub periodic_columns: BTreeMap<Identifier, PeriodicColumn>, pub public_inputs: BTreeMap<Identifier, PublicInput>, pub trace_columns: Vec<TraceSegment>, pub buses: BTreeMap<Identifier, Bus>, pub boundary_constraints: Option<Span<Vec<Statement>>>, pub integrity_constraints: Option<Span<Vec<Statement>>>,
}
Expand description

This represents the parsed contents of a single AirScript module

When parsing successfully produces a Module, it is guaranteed that:

  • Fields which are only allowed in root modules are empty/unset in library modules
  • Fields which must be present in root modules are guaranteed to be present in a root module
  • It is guaranteed that at least one boundary constraint and one integrity constraint are present in a root module
  • No duplicate module-level declarations were present
  • All globally-visible declarations are unique

However, most validation is not run at this stage, but rather later when producing a Program. In particular, variable declarations are not checked, and imports are only partially validated here, in that we check for obviously overlapping imports, but cannot fully validate them until later. Likewise we do not validate constraints, look for invalid variable usages, etc.

Fields§

§span: SourceSpan§name: ModuleId§ty: ModuleType§imports: BTreeMap<ModuleId, Import>§constants: BTreeMap<Identifier, Constant>§evaluators: BTreeMap<Identifier, EvaluatorFunction>§functions: BTreeMap<Identifier, Function>§periodic_columns: BTreeMap<Identifier, PeriodicColumn>§public_inputs: BTreeMap<Identifier, PublicInput>§trace_columns: Vec<TraceSegment>§buses: BTreeMap<Identifier, Bus>§boundary_constraints: Option<Span<Vec<Statement>>>§integrity_constraints: Option<Span<Vec<Statement>>>

Implementations§

Source§

impl Module

Source

pub fn new(ty: ModuleType, span: SourceSpan, name: ModuleId) -> Self

Constructs an empty module of the specified type, with the given span and name.

§SAFETY

Similar to Program::new, this function simply constructs an empty Module, and so it does not uphold any guarantees described in it’s documentation. It is up to the caller to guarantee that they construct a valid module that upholds those guarantees, otherwise it is expected that compilation will panic at some point down the line.

Source

pub fn from_declarations( diagnostics: &DiagnosticsHandler, ty: ModuleType, span: SourceSpan, name: Identifier, declarations: Vec<Declaration>, ) -> Result<Self, SemanticAnalysisError>

Constructs a module of the specified type, with the given span and name, using the provided declarations.

The resulting module has had some initial semantic analysis performed as described in the module docs. It is expected that this module will be added to a Library and used to construct a Program before it is considered fully validated.

Source

pub fn is_root(&self) -> bool

Source

pub fn is_library(&self) -> bool

Source

pub fn exports(&self) -> impl Iterator<Item = Export<'_>> + '_

Traverse all of the items exported from this module

Source

pub fn get(&self, id: &Identifier) -> Option<Export<'_>>

Get the export with the given identifier, if it can be found

Trait Implementations§

Source§

impl Debug for Module

Source§

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

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

impl Parse for Module

Source§

type Parser = AnyModuleParser

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 Module

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 Spanned for Module

Source§

impl Eq for Module

Auto Trait Implementations§

§

impl Freeze for Module

§

impl RefUnwindSafe for Module

§

impl Send for Module

§

impl Sync for Module

§

impl Unpin for Module

§

impl UnwindSafe for Module

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