Skip to main content

AstAlloc

Struct AstAlloc 

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

Owns the arenas required to allocate new AST nodes and provide builder methods to create them.

§Drop and arena allocation

The most popular choice for arena is the bumpalo crate, which is a fast bump allocator that can handle heterogeneous data. However, it doesn’t support destructors, which is a problem because some of the nodes in the AST owns heap allocated data and needs to be de-allocated (numbers and parse errors currently).

Another choice is typed-arena and derivatives, which do run destructors, but can only store one type of values. As the number of types that need to be dropped is relatively small, we use a general bumpalo arena by default, and specialized typed arenas for stuff that need to be dropped.

§Guarantees

AstAlloc guarantees that the memory that has been allocated won’t be moved until Self is deallocated.

Implementations§

Source§

impl AstAlloc

Source

pub fn new() -> Self

Creates a new ast allocator.

Source

pub fn allocated_bytes(&self) -> usize

Return the current number of allocated bytes.

Source

pub fn alloc<T: Allocable>(&self, value: T) -> &T

Allocates an AST component in the arena.

Self never guarantees that all destructors are going to be run when using such a generic allocation function. We don’t want to allocate values that need to be dropped through this method, typically because they own heap-allocated data, such as numbers or parse errors. That’s why we use a marker trait to specify which types can be allocated freely. Types that need to be dropped don’t implement Allocable and have a dedicated method for allocation.

Source

pub fn alloc_many<T: Allocable, I>(&self, iter: I) -> &[T]
where I: IntoIterator<Item = T>, I::IntoIter: ExactSizeIterator,

Allocates a sequence of AST components in the arena.

See Self::alloc.

Source

pub fn alloc_singleton<T: Allocable>(&self, value: T) -> &[T]

Allocates an array with exactly one element in the arena.

Source

pub fn alloc_str<'ast>(&'ast self, s: &str) -> &'ast str

Allocates a string in the arena.

Source

pub fn clone_from<'to, T: CloneTo>(&'to self, data: T::Data<'_>) -> T::Data<'to>

Deep clone an already allocated AST component from another arena to the current one.

Source

pub fn clone_ref_from<'from, 'to, T>( &'to self, data: &'from T::Data<'from>, ) -> &'to T::Data<'to>
where T: for<'a> CloneTo<Data<'a>: Clone + Allocable>,

Same as Self::clone_from but take an arena-allocated reference instead.

Source

pub fn number(&self, number: Number) -> Node<'_>

Source

pub fn alloc_number(&self, number: Number) -> &Number

Source

pub fn string<'ast>(&'ast self, s: &str) -> Node<'ast>

Source

pub fn string_chunks<'ast, I>(&'ast self, chunks: I) -> Node<'ast>
where I: IntoIterator<Item = StringChunk<Ast<'ast>>>, I::IntoIter: ExactSizeIterator,

Source

pub fn fun<'ast, I>(&'ast self, args: I, body: Ast<'ast>) -> Node<'ast>
where I: IntoIterator<Item = Pattern<'ast>>, I::IntoIter: ExactSizeIterator,

Source

pub fn unary_fun<'ast>( &'ast self, arg: Pattern<'ast>, body: Ast<'ast>, ) -> Node<'ast>

Source

pub fn let_block<'ast, I>( &'ast self, bindings: I, body: Ast<'ast>, rec: bool, ) -> Node<'ast>
where I: IntoIterator<Item = LetBinding<'ast>>, I::IntoIter: ExactSizeIterator,

Source

pub fn app<'ast, I>(&'ast self, head: Ast<'ast>, args: I) -> Node<'ast>
where I: IntoIterator<Item = Ast<'ast>>, I::IntoIter: ExactSizeIterator,

Source

pub fn enum_variant<'ast>( &'ast self, tag: LocIdent, arg: Option<Ast<'ast>>, ) -> Node<'ast>

Source

pub fn record<'ast>(&'ast self, record: Record<'ast>) -> Node<'ast>

Source

pub fn record_data<'ast, Is, Ds>( &'ast self, includes: Is, field_defs: Ds, open: bool, ) -> &'ast Record<'ast>
where Ds: IntoIterator<Item = FieldDef<'ast>>, Is: IntoIterator<Item = Include<'ast>>, Ds::IntoIter: ExactSizeIterator, Is::IntoIter: ExactSizeIterator,

Source

pub fn if_then_else<'ast>( &'ast self, cond: Ast<'ast>, then_branch: Ast<'ast>, else_branch: Ast<'ast>, ) -> Node<'ast>

Source

pub fn match_expr<'ast, I>(&'ast self, branches: I) -> Node<'ast>
where I: IntoIterator<Item = MatchBranch<'ast>>, I::IntoIter: ExactSizeIterator,

Source

pub fn array<'ast, I>(&'ast self, elts: I) -> Node<'ast>
where I: IntoIterator<Item = Ast<'ast>>, I::IntoIter: ExactSizeIterator,

Source

pub fn prim_op<'ast, I>(&'ast self, op: PrimOp, args: I) -> Node<'ast>
where I: IntoIterator<Item = Ast<'ast>>, I::IntoIter: ExactSizeIterator,

Source

pub fn annotated<'ast>( &'ast self, annot: Annotation<'ast>, inner: Ast<'ast>, ) -> Node<'ast>

Source

pub fn annotation<'ast, I>( &'ast self, typ: Option<Type<'ast>>, contracts: I, ) -> Annotation<'ast>
where I: IntoIterator<Item = Type<'ast>>, I::IntoIter: ExactSizeIterator,

Source

pub fn import_path(&self, path: OsString, format: InputFormat) -> Node<'_>

Source

pub fn import_package(&self, id: Ident) -> Node<'_>

Source

pub fn typ<'ast>(&'ast self, typ: Type<'ast>) -> Node<'ast>

Source

pub fn type_data<'ast>( &'ast self, typ: TypeUnr<'ast>, pos: TermPos, ) -> &'ast Type<'ast>

Source

pub fn enum_rows<'ast>( &'ast self, erows: EnumRowsUnr<'ast>, ) -> &'ast EnumRows<'ast>

Source

pub fn record_rows<'ast>( &'ast self, rrows: RecordRowsUnr<'ast>, ) -> &'ast RecordRows<'ast>

Source

pub fn parse_error(&self, error: ParseError) -> Node<'_>

Source

pub fn record_pattern<'ast, I>( &'ast self, patterns: I, tail: TailPattern, pos: TermPos, ) -> &'ast RecordPattern<'ast>

Source

pub fn array_pattern<'ast, I>( &'ast self, patterns: I, tail: TailPattern, pos: TermPos, ) -> &'ast ArrayPattern<'ast>
where I: IntoIterator<Item = Pattern<'ast>>, I::IntoIter: ExactSizeIterator,

Source

pub fn or_pattern<'ast, I>( &'ast self, patterns: I, pos: TermPos, ) -> &'ast OrPattern<'ast>
where I: IntoIterator<Item = Pattern<'ast>>, I::IntoIter: ExactSizeIterator,

Trait Implementations§

Source§

impl Debug for AstAlloc

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, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

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> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T> ToDebugString for T
where T: Debug,

Source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
Source§

impl<T, U> TryConvert<'_, T> for U
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

Source§

fn try_convert( _: &AstAlloc, from: T, ) -> Result<U, <U as TryConvert<'_, T>>::Error>

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

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U