mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 12:21:58 +00:00
refactor(semantic): rename Counts to Stats (#5753)
Pure refactor. Just rename the type.
This commit is contained in:
parent
042afa9fd6
commit
667170cbfc
3 changed files with 15 additions and 15 deletions
|
|
@ -22,7 +22,6 @@ use crate::{
|
||||||
binder::Binder,
|
binder::Binder,
|
||||||
checker,
|
checker,
|
||||||
class::ClassTableBuilder,
|
class::ClassTableBuilder,
|
||||||
counter::Counts,
|
|
||||||
diagnostics::redeclaration,
|
diagnostics::redeclaration,
|
||||||
jsdoc::JSDocBuilder,
|
jsdoc::JSDocBuilder,
|
||||||
label::UnusedLabels,
|
label::UnusedLabels,
|
||||||
|
|
@ -30,6 +29,7 @@ use crate::{
|
||||||
node::{AstNodes, NodeFlags, NodeId},
|
node::{AstNodes, NodeFlags, NodeId},
|
||||||
reference::{Reference, ReferenceFlags, ReferenceId},
|
reference::{Reference, ReferenceFlags, ReferenceId},
|
||||||
scope::{Bindings, ScopeFlags, ScopeId, ScopeTree},
|
scope::{Bindings, ScopeFlags, ScopeId, ScopeTree},
|
||||||
|
stats::Stats,
|
||||||
symbol::{SymbolFlags, SymbolId, SymbolTable},
|
symbol::{SymbolFlags, SymbolId, SymbolTable},
|
||||||
unresolved_stack::UnresolvedReferencesStack,
|
unresolved_stack::UnresolvedReferencesStack,
|
||||||
JSDocFinder, Semantic,
|
JSDocFinder, Semantic,
|
||||||
|
|
@ -232,10 +232,10 @@ impl<'a> SemanticBuilder<'a> {
|
||||||
// Avoiding this growth produces up to 30% perf boost on our benchmarks.
|
// Avoiding this growth produces up to 30% perf boost on our benchmarks.
|
||||||
// TODO: It would be even more efficient to calculate counts in parser to avoid
|
// TODO: It would be even more efficient to calculate counts in parser to avoid
|
||||||
// this extra AST traversal.
|
// this extra AST traversal.
|
||||||
let counts = Counts::count(program);
|
let stats = Stats::count(program);
|
||||||
self.nodes.reserve(counts.nodes);
|
self.nodes.reserve(stats.nodes);
|
||||||
self.scope.reserve(counts.scopes);
|
self.scope.reserve(stats.scopes);
|
||||||
self.symbols.reserve(counts.symbols, counts.references);
|
self.symbols.reserve(stats.symbols, stats.references);
|
||||||
|
|
||||||
// Visit AST to generate scopes tree etc
|
// Visit AST to generate scopes tree etc
|
||||||
self.visit_program(program);
|
self.visit_program(program);
|
||||||
|
|
@ -243,13 +243,13 @@ impl<'a> SemanticBuilder<'a> {
|
||||||
// Check that estimated counts accurately
|
// Check that estimated counts accurately
|
||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
{
|
{
|
||||||
let actual_counts = Counts {
|
let actual_stats = Stats {
|
||||||
nodes: self.nodes.len(),
|
nodes: self.nodes.len(),
|
||||||
scopes: self.scope.len(),
|
scopes: self.scope.len(),
|
||||||
symbols: self.symbols.len(),
|
symbols: self.symbols.len(),
|
||||||
references: self.symbols.references.len(),
|
references: self.symbols.references.len(),
|
||||||
};
|
};
|
||||||
Counts::assert_accurate(&actual_counts, &counts);
|
Stats::assert_accurate(&actual_stats, &stats);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checking syntax error on module record requires scope information from the previous AST pass
|
// Checking syntax error on module record requires scope information from the previous AST pass
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,6 @@ mod binder;
|
||||||
mod builder;
|
mod builder;
|
||||||
mod checker;
|
mod checker;
|
||||||
mod class;
|
mod class;
|
||||||
mod counter;
|
|
||||||
mod diagnostics;
|
mod diagnostics;
|
||||||
mod jsdoc;
|
mod jsdoc;
|
||||||
mod label;
|
mod label;
|
||||||
|
|
@ -31,6 +30,7 @@ mod module_record;
|
||||||
mod node;
|
mod node;
|
||||||
mod reference;
|
mod reference;
|
||||||
mod scope;
|
mod scope;
|
||||||
|
mod stats;
|
||||||
mod symbol;
|
mod symbol;
|
||||||
mod unresolved_stack;
|
mod unresolved_stack;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,18 +14,18 @@ use oxc_ast::{
|
||||||
use oxc_syntax::scope::{ScopeFlags, ScopeId};
|
use oxc_syntax::scope::{ScopeFlags, ScopeId};
|
||||||
|
|
||||||
#[derive(Default, Debug)]
|
#[derive(Default, Debug)]
|
||||||
pub(crate) struct Counts {
|
pub(crate) struct Stats {
|
||||||
pub nodes: usize,
|
pub nodes: usize,
|
||||||
pub scopes: usize,
|
pub scopes: usize,
|
||||||
pub symbols: usize,
|
pub symbols: usize,
|
||||||
pub references: usize,
|
pub references: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Counts {
|
impl Stats {
|
||||||
pub fn count(program: &Program) -> Self {
|
pub fn count(program: &Program) -> Self {
|
||||||
let mut counts = Counts::default();
|
let mut stats = Stats::default();
|
||||||
counts.visit_program(program);
|
stats.visit_program(program);
|
||||||
counts
|
stats
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(not(debug_assertions), expect(dead_code))]
|
#[cfg_attr(not(debug_assertions), expect(dead_code))]
|
||||||
|
|
@ -33,7 +33,7 @@ impl Counts {
|
||||||
assert_eq!(actual.nodes, estimated.nodes, "nodes count mismatch");
|
assert_eq!(actual.nodes, estimated.nodes, "nodes count mismatch");
|
||||||
assert_eq!(actual.scopes, estimated.scopes, "scopes count mismatch");
|
assert_eq!(actual.scopes, estimated.scopes, "scopes count mismatch");
|
||||||
assert_eq!(actual.references, estimated.references, "references count mismatch");
|
assert_eq!(actual.references, estimated.references, "references count mismatch");
|
||||||
// `Counts` may overestimate number of symbols, because multiple `BindingIdentifier`s
|
// `Stats` may overestimate number of symbols, because multiple `BindingIdentifier`s
|
||||||
// can result in only a single symbol.
|
// can result in only a single symbol.
|
||||||
// e.g. `var x; var x;` = 2 x `BindingIdentifier` but 1 x symbol.
|
// e.g. `var x; var x;` = 2 x `BindingIdentifier` but 1 x symbol.
|
||||||
// This is not a big problem - allocating a `Vec` with excess capacity is cheap.
|
// This is not a big problem - allocating a `Vec` with excess capacity is cheap.
|
||||||
|
|
@ -48,7 +48,7 @@ impl Counts {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Visit<'a> for Counts {
|
impl<'a> Visit<'a> for Stats {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn enter_node(&mut self, _: AstKind<'a>) {
|
fn enter_node(&mut self, _: AstKind<'a>) {
|
||||||
self.nodes += 1;
|
self.nodes += 1;
|
||||||
Loading…
Reference in a new issue