Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions crates/oxc_ast/src/ast_kind_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This module provides methods and utilities for working with [`AstKind`],
//! including type checking, conversions, and tree traversal helpers.

use oxc_allocator::{Address, GetAddress};
use oxc_allocator::{Address, GetAddress, UnstableAddress};
use oxc_span::{Atom, GetSpan};

use super::{AstKind, ast::*};
Expand Down Expand Up @@ -324,8 +324,7 @@ impl<'a> AstKind<'a> {
// Only match if ident is the assignee
// - not the default value e.g. `({ assignee = ident } = obj)`.
AstKind::AssignmentTargetPropertyIdentifier(assign_target) => {
let binding = &assign_target.binding;
Address::from_ref(binding) == self.address()
assign_target.binding.unstable_address() == self.address()
}
// `({ prop: ident } = obj)`
// Only match if ident is the assignee
Expand Down Expand Up @@ -742,9 +741,9 @@ impl GetAddress for MemberExpressionKind<'_> {
#[inline] // This should boil down to a single instruction
fn address(&self) -> Address {
match *self {
Self::Computed(member_expr) => Address::from_ref(member_expr),
Self::Static(member_expr) => Address::from_ref(member_expr),
Self::PrivateField(member_expr) => Address::from_ref(member_expr),
Self::Computed(member_expr) => member_expr.unstable_address(),
Self::Static(member_expr) => member_expr.unstable_address(),
Self::PrivateField(member_expr) => member_expr.unstable_address(),
}
}
}
Expand Down Expand Up @@ -798,12 +797,12 @@ impl GetAddress for ModuleDeclarationKind<'_> {
#[inline] // This should boil down to a single instruction
fn address(&self) -> Address {
match *self {
Self::Import(decl) => Address::from_ref(decl),
Self::ExportAll(decl) => Address::from_ref(decl),
Self::ExportNamed(decl) => Address::from_ref(decl),
Self::ExportDefault(decl) => Address::from_ref(decl),
Self::TSExportAssignment(decl) => Address::from_ref(decl),
Self::TSNamespaceExport(decl) => Address::from_ref(decl),
Self::Import(decl) => decl.unstable_address(),
Self::ExportAll(decl) => decl.unstable_address(),
Self::ExportNamed(decl) => decl.unstable_address(),
Self::ExportDefault(decl) => decl.unstable_address(),
Self::TSExportAssignment(decl) => decl.unstable_address(),
Self::TSNamespaceExport(decl) => decl.unstable_address(),
}
}
}
Expand Down Expand Up @@ -831,11 +830,12 @@ impl GetAddress for PropertyKeyKind<'_> {
#[inline] // This should boil down to a single instruction
fn address(&self) -> Address {
match *self {
Self::Static(ident) => Address::from_ref(ident),
Self::Private(ident) => Address::from_ref(ident),
Self::Static(ident) => ident.unstable_address(),
Self::Private(ident) => ident.unstable_address(),
}
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
374 changes: 187 additions & 187 deletions crates/oxc_ast/src/generated/ast_kind.rs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{borrow::Cow, ops::Deref};

use oxc_allocator::Address;
use oxc_allocator::{Address, UnstableAddress};
use oxc_ast::{AstKind, ast::*};
use oxc_ast_visit::{
Visit,
Expand Down Expand Up @@ -297,11 +297,13 @@ enum Fn<'a> {
Arrow(&'a ArrowFunctionExpression<'a>),
None,
}

impl Fn<'_> {
fn address(self) -> Option<Address> {
// AST is immutable in linter, so `unstable_address` produces stable `Address`es
match self {
Fn::Fn(f) => Some(Address::from_ref(f)),
Fn::Arrow(a) => Some(Address::from_ref(a)),
Fn::Fn(f) => Some(f.unstable_address()),
Fn::Arrow(a) => Some(a.unstable_address()),
Fn::None => None,
}
}
Expand Down Expand Up @@ -392,8 +394,11 @@ impl<'a, 'c> ExplicitTypesChecker<'a, 'c> {
let Some(body) = func.body.as_deref() else {
return;
};

walk::walk_function_body(self, body);
let is_hof = self.is_higher_order_function(Address::from_ref(func));

// AST is immutable in linter, so `unstable_address` produces stable `Address`es
let is_hof = self.is_higher_order_function(func.unstable_address());
if !is_hof && !is_allowed() {
self.ctx.diagnostic(func_missing_return_type(span));
}
Expand Down Expand Up @@ -450,7 +455,9 @@ impl<'a, 'c> ExplicitTypesChecker<'a, 'c> {
}
} else {
walk::walk_function_body(self, &arrow.body);
let is_hof = self.is_higher_order_function(Address::from_ref(arrow));

// AST is immutable in linter, so `unstable_address` produces stable `Address`es
let is_hof = self.is_higher_order_function(arrow.unstable_address());
if !is_hof && !is_allowed() {
self.ctx.diagnostic(func_missing_return_type(span));
}
Expand Down
5 changes: 3 additions & 2 deletions crates/oxc_semantic/src/binder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! Declare symbol for `BindingIdentifier`s

use oxc_allocator::{Address, GetAddress};
use oxc_allocator::{GetAddress, UnstableAddress};
use oxc_ast::{AstKind, ast::*};
use oxc_ecmascript::{BoundNames, IsSimpleParameterList};
use oxc_span::GetSpan;
Expand Down Expand Up @@ -418,7 +418,8 @@ fn get_module_instance_state_impl<'a, 'b>(
current_node_id: NodeId,
module_declaration_stmts: &mut Vec<&'b Statement<'a>>,
) -> ModuleInstanceState {
let address = Address::from_ref(decl);
// `SemanticBuilder` takes an immutable reference to AST, so `unstable_address` produces stable `Address`es
let address = decl.unstable_address();

if let Some(state) = builder.module_instance_state_cache.get(&address) {
return *state;
Expand Down
10 changes: 5 additions & 5 deletions crates/oxc_transformer/src/decorator/legacy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod metadata;

use std::mem;

use oxc_allocator::{Address, GetAddress, TakeIn, Vec as ArenaVec};
use oxc_allocator::{Address, GetAddress, TakeIn, UnstableAddress, Vec as ArenaVec};
use oxc_ast::{NONE, ast::*};
use oxc_ast_visit::{Visit, VisitMut};
use oxc_data_structures::stack::NonEmptyStack;
Expand Down Expand Up @@ -682,10 +682,10 @@ impl<'a> LegacyDecorator<'a, '_> {
Self::insert_decorations_into_class_static_block(class, decorations, ctx);
} else {
let address = match ctx.parent() {
Ancestor::ExportDefaultDeclarationDeclaration(_)
| Ancestor::ExportNamedDeclarationDeclaration(_) => ctx.parent().address(),
parent @ (Ancestor::ExportDefaultDeclarationDeclaration(_)
| Ancestor::ExportNamedDeclarationDeclaration(_)) => parent.address(),
// `Class` is always stored in a `Box`, so has a stable memory location
_ => Address::from_ref(class),
_ => class.unstable_address(),
};

decoration_stmts.push(constructor_decoration);
Expand Down Expand Up @@ -778,7 +778,7 @@ impl<'a> LegacyDecorator<'a, '_> {
parent @ (Ancestor::ExportDefaultDeclarationDeclaration(_)
| Ancestor::ExportNamedDeclarationDeclaration(_)) => parent.address(),
// `Class` is always stored in a `Box`, so has a stable memory location
_ => Address::from_ref(class),
_ => class.unstable_address(),
};
self.decorations.entry(stmt_address).or_default().append(&mut decoration_stmts);
}
Expand Down
4 changes: 2 additions & 2 deletions crates/oxc_transformer/src/es2022/class_properties/class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//! Transform of class itself.

use indexmap::map::Entry;
use oxc_allocator::{Address, GetAddress, TakeIn};
use oxc_allocator::{Address, GetAddress, TakeIn, UnstableAddress};
use oxc_ast::{NONE, ast::*};
use oxc_span::SPAN;
use oxc_syntax::{
Expand Down Expand Up @@ -478,7 +478,7 @@ impl<'a> ClassProperties<'a, '_> {
parent @ (Ancestor::ExportDefaultDeclarationDeclaration(_)
| Ancestor::ExportNamedDeclarationDeclaration(_)) => parent.address(),
// `Class` is always stored in a `Box`, so has a stable memory location
_ => Address::from_ref(class),
_ => class.unstable_address(),
};

if !self.insert_before.is_empty() {
Expand Down
5 changes: 3 additions & 2 deletions crates/oxc_transformer/src/jsx/refresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ use rustc_hash::{FxHashMap, FxHashSet};
use sha1::{Digest, Sha1};

use oxc_allocator::{
Address, CloneIn, GetAddress, StringBuilder as ArenaStringBuilder, TakeIn, Vec as ArenaVec,
CloneIn, GetAddress, StringBuilder as ArenaStringBuilder, TakeIn, UnstableAddress,
Vec as ArenaVec,
};
use oxc_ast::{AstBuilder, NONE, ast::*, match_expression};
use oxc_ast_visit::{
Expand Down Expand Up @@ -307,7 +308,7 @@ impl<'a> Traverse<'a, TransformState<'a>> for ReactRefresh<'a, '_> {
// Otherwise just a `function Foo() {}`
// which is a `Statement::FunctionDeclaration`.
// `Function` is always stored in a `Box`, so has a stable memory address.
_ => Address::from_ref(func),
_ => func.unstable_address(),
};
self.ctx.statement_injector.insert_after(&address, statement);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{cmp::Ordering, sync::Arc};

use rustc_hash::FxHashSet;

use oxc_allocator::{Address, Allocator, GetAddress};
use oxc_allocator::{Address, Allocator, GetAddress, UnstableAddress};
use oxc_ast::ast::*;
use oxc_ast_visit::{VisitMut, walk_mut};
use oxc_diagnostics::OxcDiagnostic;
Expand Down Expand Up @@ -261,7 +261,7 @@ impl<'a> Traverse<'a, ()> for ReplaceGlobalDefines<'a> {
if self.replace_define_with_assignment_expr(node, ctx) {
self.mark_as_changed();
// `AssignmentExpression` is stored in a `Box`, so has a stable memory location
self.ast_node_lock = Some(Address::from_ref(node));
self.ast_node_lock = Some(node.unstable_address());
}
}

Expand All @@ -271,7 +271,7 @@ impl<'a> Traverse<'a, ()> for ReplaceGlobalDefines<'a> {
_: &mut TraverseCtx<'a>,
) {
// `AssignmentExpression` is stored in a `Box`, so has a stable memory location
if self.ast_node_lock == Some(Address::from_ref(node)) {
if self.ast_node_lock == Some(node.unstable_address()) {
self.ast_node_lock = None;
}
}
Expand Down
4 changes: 2 additions & 2 deletions tasks/ast_tools/src/generators/ast_kind.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ impl Generator for AstKindGenerator {
span_match_arms.extend(quote!( Self::#type_ident(it) => it.span(), ));

let get_address = match type_def {
TypeDef::Struct(_) => quote!(Address::from_ref(it)),
TypeDef::Struct(_) => quote!(it.unstable_address()),
TypeDef::Enum(_) => quote!(it.address()),
_ => unreachable!(),
};
Expand Down Expand Up @@ -134,7 +134,7 @@ impl Generator for AstKindGenerator {
use std::ptr;

///@@line_break
use oxc_allocator::{Address, GetAddress};
use oxc_allocator::{Address, GetAddress, UnstableAddress};
use oxc_span::{GetSpan, Span};

///@@line_break
Expand Down
Loading