Skip to main content

Stats

Struct Stats 

Source
pub struct Stats {
    pub nodes: u32,
    pub scopes: u32,
    pub symbols: u32,
    pub references: u32,
}
Expand description

Statistics about data held in Semantic.

Comprises number of AST nodes, scopes, symbols, and references.

These counts can be used to pre-allocate sufficient capacity in AstNodes, ScopeTree, and SymbolTable to store info for all these items.

§Example

use oxc_ast::ast::Program;
use oxc_semantic::{Semantic, Stats};

fn print_stats_from_semantic(semantic: &Semantic) {
    dbg!(semantic.stats());
}

fn print_stats_from_ast(program: &Program) {
    dbg!(Stats::count(program));
}

Fields§

§nodes: u32

Number of AST nodes.

§scopes: u32

Number of lexical scopes.

§symbols: u32

Number of semantic symbols.

§references: u32

Number of identifier references.

Implementations§

Source§

impl Stats

Source

pub fn new(nodes: u32, scopes: u32, symbols: u32, references: u32) -> Self

Create new Stats from specified counts.

Source

pub fn count(program: &Program<'_>) -> Self

Gather Stats by visiting AST and counting nodes, scopes, symbols, and references.

Nodes, scopes and references counts will be exactly accurate. Symbols count may be an over-estimate if there are multiple declarations for a single symbol. e.g. var x; var x; will produce a count of 2 symbols, but this is actually only 1 symbol.

If semantic analysis has already been run on AST, prefer getting counts with Semantic::stats. They will be 100% accurate, and very cheap to obtain, whereas this method performs a complete AST traversal.

Source

pub fn increase_by(self, excess: f64) -> Self

Increase scope, symbol, and reference counts by provided excess.

excess is provided as a fraction. e.g. to over-allocate by 20%, pass 0.2 as excess.

Source

pub fn assert_accurate(self, actual: Self)

Assert that estimated Stats match actual.

§Panics

Panics if stats are not accurate.

Trait Implementations§

Source§

impl Clone for Stats

Source§

fn clone(&self) -> Stats

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Stats

Source§

impl Debug for Stats

Source§

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

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

impl Default for Stats

Source§

fn default() -> Stats

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

Auto Trait Implementations§

§

impl Freeze for Stats

§

impl RefUnwindSafe for Stats

§

impl Send for Stats

§

impl Sync for Stats

§

impl Unpin for Stats

§

impl UnsafeUnpin for Stats

§

impl UnwindSafe for Stats

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<'a, T> FromIn<'a, T> for T

Source§

fn from_in(t: T, _: &'a Allocator) -> T

Converts to this type from the input type within the given allocator.
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<'a, T, U> IntoIn<'a, U> for T
where U: FromIn<'a, T>,

Source§

fn into_in(self, allocator: &'a Allocator) -> U

Converts this type into the (usually inferred) input type within the given allocator.
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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.