From efe96ecc1206e6679fabbdb97d35b5277f706e48 Mon Sep 17 00:00:00 2001 From: Dunqing <29533304+Dunqing@users.noreply.github.com> Date: Wed, 18 Dec 2024 06:38:59 +0000 Subject: [PATCH] refactor(semantic): use `Stack` for function stack node ids (#7984) --- Cargo.lock | 1 + crates/oxc_semantic/Cargo.toml | 1 + crates/oxc_semantic/src/builder.rs | 5 +++-- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 33961783c9cd1..3b32c9a4b2a44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1920,6 +1920,7 @@ dependencies = [ "oxc_allocator", "oxc_ast", "oxc_cfg", + "oxc_data_structures", "oxc_diagnostics", "oxc_ecmascript", "oxc_index", diff --git a/crates/oxc_semantic/Cargo.toml b/crates/oxc_semantic/Cargo.toml index 09466b26b9475..facd8e08fcfa6 100644 --- a/crates/oxc_semantic/Cargo.toml +++ b/crates/oxc_semantic/Cargo.toml @@ -22,6 +22,7 @@ doctest = false oxc_allocator = { workspace = true } oxc_ast = { workspace = true } oxc_cfg = { workspace = true } +oxc_data_structures = { workspace = true } oxc_diagnostics = { workspace = true } oxc_ecmascript = { workspace = true } oxc_index = { workspace = true } diff --git a/crates/oxc_semantic/src/builder.rs b/crates/oxc_semantic/src/builder.rs index e2af5fd23b8b3..4671d8282a008 100644 --- a/crates/oxc_semantic/src/builder.rs +++ b/crates/oxc_semantic/src/builder.rs @@ -5,6 +5,7 @@ use std::{ mem, }; +use oxc_data_structures::stack::Stack; use rustc_hash::FxHashMap; use oxc_ast::{ast::*, AstKind, Visit}; @@ -77,7 +78,7 @@ pub struct SemanticBuilder<'a> { pub(crate) current_symbol_flags: SymbolFlags, pub(crate) current_scope_id: ScopeId, /// Stores current `AstKind::Function` and `AstKind::ArrowFunctionExpression` during AST visit - pub(crate) function_stack: Vec, + pub(crate) function_stack: Stack, // To make a namespace/module value like // we need the to know the modules we are inside // and when we reach a value declaration we set it @@ -137,7 +138,7 @@ impl<'a> SemanticBuilder<'a> { current_symbol_flags: SymbolFlags::empty(), current_reference_flags: ReferenceFlags::empty(), current_scope_id, - function_stack: vec![], + function_stack: Stack::with_capacity(16), namespace_stack: vec![], nodes: AstNodes::default(), hoisting_variables: FxHashMap::default(),