Struct SymbolTable

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

The global symbol table, mapping names to their definitions.

Names in the symbol table are unique, including between different types of object stored in the symbol table. For example, you cannot have a letting and decision variable with the same name.

§Symbol Kinds

The symbol table tracks the following types of symbol:

§Decision Variables

find NAME: DOMAIN

See DecisionVariable.

§Lettings

Lettings define constants, of which there are two types:

  • Constant values: letting val be A, where A is an Expression.

    A can be any integer, boolean, or matrix expression. A can include references to other lettings, model parameters, and, unlike Savile Row, decision variables.

  • Constant domains: letting Domain be domain D, where D is a Domain.

    D can include references to other lettings and model parameters, and, unlike Savile Row, decision variables.

Unless otherwise stated, these follow the semantics specified in section 2.2.2 of the Savile Row manual (version 1.9.1 at time of writing).

Implementations§

Source§

impl SymbolTable

Source

pub fn new() -> SymbolTable

Creates an empty symbol table.

Source

pub fn with_parent(parent: Rc<RefCell<SymbolTable>>) -> SymbolTable

Creates an empty symbol table with the given parent.

Source

pub fn lookup_local(&self, name: &Name) -> Option<Rc<Declaration>>

Looks up the declaration with the given name in the current scope only.

Returns None if there is no declaration with that name in the current scope.

Source

pub fn lookup(&self, name: &Name) -> Option<Rc<Declaration>>

Looks up the declaration with the given name, checking all enclosing scopes.

Returns None if there is no declaration with that name in scope.

Source

pub fn insert(&mut self, declaration: Rc<Declaration>) -> Option<()>

Inserts a declaration into the symbol table.

Returns None if there is already a symbol with this name in the local scope.

Source

pub fn update_insert(&mut self, declaration: Rc<Declaration>)

Updates or adds a declaration in the immediate local scope.

Source

pub fn return_type(&self, name: &Name) -> Option<ReturnType>

Looks up the return type for name if it has one and is in scope.

Source

pub fn return_type_local(&self, name: &Name) -> Option<ReturnType>

Looks up the return type for name if has one and is in the local scope.

Source

pub fn domain(&self, name: &Name) -> Option<Domain>

Looks up the domain of name if it has one and is in scope.

This method can return domain references: if a ground domain is always required, use SymbolTable::resolve_domain.

Source

pub fn resolve_domain(&self, name: &Name) -> Option<Domain>

Looks up the domain of name, resolving domain references to ground domains.

See SymbolTable::domain.

Source

pub fn into_iter_local(self) -> LocalIntoIter

Iterates over entries in the local symbol table only.

Source

pub fn extend(&mut self, other: SymbolTable)

Extends the symbol table with the given symbol table, updating the gensym counter if necessary.

Source

pub fn gensym(&self) -> Name

Returns an arbitrary variable name that is not in the symbol table.

Source

pub fn parent_mut_unchecked(&mut self) -> &mut Option<Rc<RefCell<SymbolTable>>>

Gets the parent of this symbol table as a mutable reference.

This function provides no sanity checks.

Trait Implementations§

Source§

impl Biplate<Expression> for SymbolTable

Source§

fn biplate( &self, ) -> (Tree<Expression>, Box<dyn Fn(Tree<Expression>) -> SymbolTable>)

Definition of a Biplate. Read more
§

fn with_children_bi(&self, children: VecDeque<To>) -> Self

Reconstructs the node with the given children. Read more
§

fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self

Biplate variant of [Uniplate::descend] Read more
§

fn universe_bi(&self) -> VecDeque<To>

Gets all children of a node, including itself and all children. Read more
§

fn children_bi(&self) -> VecDeque<To>

Returns the children of a type. If to == from then it returns the original element (in contrast to children). Read more
§

fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self

Applies the given function to all nodes bottom up. Read more
§

fn holes_bi(&self) -> impl Iterator<Item = (To, Arc<dyn Fn(To) -> Self>)>

Returns an iterator over all direct children of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
§

fn contexts_bi(&self) -> impl Iterator<Item = (To, Arc<dyn Fn(To) -> Self>)>

Returns an iterator over the universe of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
Source§

impl Biplate<SubModel> for SymbolTable

Source§

fn biplate( &self, ) -> (Tree<SubModel>, Box<dyn Fn(Tree<SubModel>) -> SymbolTable>)

Definition of a Biplate. Read more
§

fn with_children_bi(&self, children: VecDeque<To>) -> Self

Reconstructs the node with the given children. Read more
§

fn descend_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self

Biplate variant of [Uniplate::descend] Read more
§

fn universe_bi(&self) -> VecDeque<To>

Gets all children of a node, including itself and all children. Read more
§

fn children_bi(&self) -> VecDeque<To>

Returns the children of a type. If to == from then it returns the original element (in contrast to children). Read more
§

fn transform_bi(&self, op: Arc<dyn Fn(To) -> To>) -> Self

Applies the given function to all nodes bottom up. Read more
§

fn holes_bi(&self) -> impl Iterator<Item = (To, Arc<dyn Fn(To) -> Self>)>

Returns an iterator over all direct children of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
§

fn contexts_bi(&self) -> impl Iterator<Item = (To, Arc<dyn Fn(To) -> Self>)>

Returns an iterator over the universe of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
Source§

impl Clone for SymbolTable

Source§

fn clone(&self) -> SymbolTable

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SymbolTable

Source§

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

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

impl Default for SymbolTable

Source§

fn default() -> SymbolTable

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

impl DefaultWithId for SymbolTable

Source§

fn default_with_id(id: u32) -> SymbolTable

Creates a new default value of type T, but with the given id.
Source§

impl<'de> Deserialize<'de> for SymbolTable

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<SymbolTable, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl HasId for SymbolTable

Source§

fn id(&self) -> u32

The id of this object. Read more
Source§

impl IntoIterator for SymbolTable

Source§

fn into_iter(self) -> <SymbolTable as IntoIterator>::IntoIter

Iterates over symbol table entries in scope.

Source§

type Item = (Name, Rc<Declaration>)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
Source§

impl PartialEq for SymbolTable

Source§

fn eq(&self, other: &SymbolTable) -> 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 Serialize for SymbolTable

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Uniplate for SymbolTable

Source§

fn uniplate( &self, ) -> (Tree<SymbolTable>, Box<dyn Fn(Tree<SymbolTable>) -> SymbolTable>)

Definition of a Uniplate. Read more
§

fn descend(&self, op: Arc<dyn Fn(Self) -> Self>) -> Self

Applies a function to all direct children of this Read more
§

fn universe(&self) -> VecDeque<Self>

Gets all children of a node, including itself and all children. Read more
§

fn children(&self) -> VecDeque<Self>

Gets the direct children (maximal substructures) of a node.
§

fn with_children(&self, children: VecDeque<Self>) -> Self

Reconstructs the node with the given children. Read more
§

fn transform(&self, f: Arc<dyn Fn(Self) -> Self>) -> Self

Applies the given function to all nodes bottom up.
§

fn rewrite(&self, f: Arc<dyn Fn(Self) -> Option<Self>>) -> Self

Rewrites by applying a rule everywhere it can.
§

fn cata<T>(&self, op: Arc<dyn Fn(Self, VecDeque<T>) -> T>) -> T

Performs a fold-like computation on each value. Read more
§

fn holes(&self) -> impl Iterator<Item = (Self, Arc<dyn Fn(Self) -> Self>)>

Returns an iterator over all direct children of the input, paired with a function that “fills the hole” where the child was with a new value.
§

fn contexts(&self) -> impl Iterator<Item = (Self, Arc<dyn Fn(Self) -> Self>)>

Returns an iterator over the universe of the input, paired with a function that “fills the hole” where the child was with a new value. Read more
Source§

impl Eq for SymbolTable

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, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

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

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<I> IntoStreamingIterator for I
where I: IntoIterator,

Source§

fn into_streaming_iter(self) -> Convert<Self::IntoIter>

Source§

fn into_streaming_iter_ref<'a, T>(self) -> ConvertRef<'a, Self::IntoIter, T>
where Self: IntoIterator<Item = &'a T>, T: ?Sized,

Turns an IntoIterator of references into a StreamingIterator. Read more
Source§

fn into_streaming_iter_mut<'a, T>(self) -> ConvertMut<'a, Self::IntoIter, T>
where Self: IntoIterator<Item = &'a mut T>, T: ?Sized,

Turns an IntoIterator of mutable references into a StreamingIteratorMut. Read more
Source§

impl<T> Serialize for T
where T: Serialize + ?Sized,

Source§

fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>

Source§

fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,