diff --git a/crates/oxc_ast/src/ast_kind_impl.rs b/crates/oxc_ast/src/ast_kind_impl.rs index 9601ee7211a78..7281a0f03c11c 100644 --- a/crates/oxc_ast/src/ast_kind_impl.rs +++ b/crates/oxc_ast/src/ast_kind_impl.rs @@ -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::*}; @@ -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 @@ -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(), } } } @@ -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(), } } } @@ -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::*; diff --git a/crates/oxc_ast/src/generated/ast_kind.rs b/crates/oxc_ast/src/generated/ast_kind.rs index 2c66b27c07574..f39a72f25e6c8 100644 --- a/crates/oxc_ast/src/generated/ast_kind.rs +++ b/crates/oxc_ast/src/generated/ast_kind.rs @@ -6,7 +6,7 @@ use std::ptr; -use oxc_allocator::{Address, GetAddress}; +use oxc_allocator::{Address, GetAddress, UnstableAddress}; use oxc_span::{GetSpan, Span}; use crate::ast::*; @@ -623,192 +623,192 @@ impl GetSpan for AstKind<'_> { impl GetAddress for AstKind<'_> { fn address(&self) -> Address { match *self { - Self::Program(it) => Address::from_ref(it), - Self::IdentifierName(it) => Address::from_ref(it), - Self::IdentifierReference(it) => Address::from_ref(it), - Self::BindingIdentifier(it) => Address::from_ref(it), - Self::LabelIdentifier(it) => Address::from_ref(it), - Self::ThisExpression(it) => Address::from_ref(it), - Self::ArrayExpression(it) => Address::from_ref(it), - Self::Elision(it) => Address::from_ref(it), - Self::ObjectExpression(it) => Address::from_ref(it), - Self::ObjectProperty(it) => Address::from_ref(it), - Self::TemplateLiteral(it) => Address::from_ref(it), - Self::TaggedTemplateExpression(it) => Address::from_ref(it), - Self::TemplateElement(it) => Address::from_ref(it), - Self::ComputedMemberExpression(it) => Address::from_ref(it), - Self::StaticMemberExpression(it) => Address::from_ref(it), - Self::PrivateFieldExpression(it) => Address::from_ref(it), - Self::CallExpression(it) => Address::from_ref(it), - Self::NewExpression(it) => Address::from_ref(it), - Self::MetaProperty(it) => Address::from_ref(it), - Self::SpreadElement(it) => Address::from_ref(it), - Self::UpdateExpression(it) => Address::from_ref(it), - Self::UnaryExpression(it) => Address::from_ref(it), - Self::BinaryExpression(it) => Address::from_ref(it), - Self::PrivateInExpression(it) => Address::from_ref(it), - Self::LogicalExpression(it) => Address::from_ref(it), - Self::ConditionalExpression(it) => Address::from_ref(it), - Self::AssignmentExpression(it) => Address::from_ref(it), - Self::ArrayAssignmentTarget(it) => Address::from_ref(it), - Self::ObjectAssignmentTarget(it) => Address::from_ref(it), - Self::AssignmentTargetRest(it) => Address::from_ref(it), - Self::AssignmentTargetWithDefault(it) => Address::from_ref(it), - Self::AssignmentTargetPropertyIdentifier(it) => Address::from_ref(it), - Self::AssignmentTargetPropertyProperty(it) => Address::from_ref(it), - Self::SequenceExpression(it) => Address::from_ref(it), - Self::Super(it) => Address::from_ref(it), - Self::AwaitExpression(it) => Address::from_ref(it), - Self::ChainExpression(it) => Address::from_ref(it), - Self::ParenthesizedExpression(it) => Address::from_ref(it), - Self::Directive(it) => Address::from_ref(it), - Self::Hashbang(it) => Address::from_ref(it), - Self::BlockStatement(it) => Address::from_ref(it), - Self::VariableDeclaration(it) => Address::from_ref(it), - Self::VariableDeclarator(it) => Address::from_ref(it), - Self::EmptyStatement(it) => Address::from_ref(it), - Self::ExpressionStatement(it) => Address::from_ref(it), - Self::IfStatement(it) => Address::from_ref(it), - Self::DoWhileStatement(it) => Address::from_ref(it), - Self::WhileStatement(it) => Address::from_ref(it), - Self::ForStatement(it) => Address::from_ref(it), - Self::ForInStatement(it) => Address::from_ref(it), - Self::ForOfStatement(it) => Address::from_ref(it), - Self::ContinueStatement(it) => Address::from_ref(it), - Self::BreakStatement(it) => Address::from_ref(it), - Self::ReturnStatement(it) => Address::from_ref(it), - Self::WithStatement(it) => Address::from_ref(it), - Self::SwitchStatement(it) => Address::from_ref(it), - Self::SwitchCase(it) => Address::from_ref(it), - Self::LabeledStatement(it) => Address::from_ref(it), - Self::ThrowStatement(it) => Address::from_ref(it), - Self::TryStatement(it) => Address::from_ref(it), - Self::CatchClause(it) => Address::from_ref(it), - Self::CatchParameter(it) => Address::from_ref(it), - Self::DebuggerStatement(it) => Address::from_ref(it), - Self::AssignmentPattern(it) => Address::from_ref(it), - Self::ObjectPattern(it) => Address::from_ref(it), - Self::BindingProperty(it) => Address::from_ref(it), - Self::ArrayPattern(it) => Address::from_ref(it), - Self::BindingRestElement(it) => Address::from_ref(it), - Self::Function(it) => Address::from_ref(it), - Self::FormalParameters(it) => Address::from_ref(it), - Self::FormalParameter(it) => Address::from_ref(it), - Self::FunctionBody(it) => Address::from_ref(it), - Self::ArrowFunctionExpression(it) => Address::from_ref(it), - Self::YieldExpression(it) => Address::from_ref(it), - Self::Class(it) => Address::from_ref(it), - Self::ClassBody(it) => Address::from_ref(it), - Self::MethodDefinition(it) => Address::from_ref(it), - Self::PropertyDefinition(it) => Address::from_ref(it), - Self::PrivateIdentifier(it) => Address::from_ref(it), - Self::StaticBlock(it) => Address::from_ref(it), - Self::AccessorProperty(it) => Address::from_ref(it), - Self::ImportExpression(it) => Address::from_ref(it), - Self::ImportDeclaration(it) => Address::from_ref(it), - Self::ImportSpecifier(it) => Address::from_ref(it), - Self::ImportDefaultSpecifier(it) => Address::from_ref(it), - Self::ImportNamespaceSpecifier(it) => Address::from_ref(it), - Self::WithClause(it) => Address::from_ref(it), - Self::ImportAttribute(it) => Address::from_ref(it), - Self::ExportNamedDeclaration(it) => Address::from_ref(it), - Self::ExportDefaultDeclaration(it) => Address::from_ref(it), - Self::ExportAllDeclaration(it) => Address::from_ref(it), - Self::ExportSpecifier(it) => Address::from_ref(it), - Self::V8IntrinsicExpression(it) => Address::from_ref(it), - Self::BooleanLiteral(it) => Address::from_ref(it), - Self::NullLiteral(it) => Address::from_ref(it), - Self::NumericLiteral(it) => Address::from_ref(it), - Self::StringLiteral(it) => Address::from_ref(it), - Self::BigIntLiteral(it) => Address::from_ref(it), - Self::RegExpLiteral(it) => Address::from_ref(it), - Self::JSXElement(it) => Address::from_ref(it), - Self::JSXOpeningElement(it) => Address::from_ref(it), - Self::JSXClosingElement(it) => Address::from_ref(it), - Self::JSXFragment(it) => Address::from_ref(it), - Self::JSXOpeningFragment(it) => Address::from_ref(it), - Self::JSXClosingFragment(it) => Address::from_ref(it), - Self::JSXNamespacedName(it) => Address::from_ref(it), - Self::JSXMemberExpression(it) => Address::from_ref(it), - Self::JSXExpressionContainer(it) => Address::from_ref(it), - Self::JSXEmptyExpression(it) => Address::from_ref(it), - Self::JSXAttribute(it) => Address::from_ref(it), - Self::JSXSpreadAttribute(it) => Address::from_ref(it), - Self::JSXIdentifier(it) => Address::from_ref(it), - Self::JSXSpreadChild(it) => Address::from_ref(it), - Self::JSXText(it) => Address::from_ref(it), - Self::TSThisParameter(it) => Address::from_ref(it), - Self::TSEnumDeclaration(it) => Address::from_ref(it), - Self::TSEnumBody(it) => Address::from_ref(it), - Self::TSEnumMember(it) => Address::from_ref(it), - Self::TSTypeAnnotation(it) => Address::from_ref(it), - Self::TSLiteralType(it) => Address::from_ref(it), - Self::TSConditionalType(it) => Address::from_ref(it), - Self::TSUnionType(it) => Address::from_ref(it), - Self::TSIntersectionType(it) => Address::from_ref(it), - Self::TSParenthesizedType(it) => Address::from_ref(it), - Self::TSTypeOperator(it) => Address::from_ref(it), - Self::TSArrayType(it) => Address::from_ref(it), - Self::TSIndexedAccessType(it) => Address::from_ref(it), - Self::TSTupleType(it) => Address::from_ref(it), - Self::TSNamedTupleMember(it) => Address::from_ref(it), - Self::TSOptionalType(it) => Address::from_ref(it), - Self::TSRestType(it) => Address::from_ref(it), - Self::TSAnyKeyword(it) => Address::from_ref(it), - Self::TSStringKeyword(it) => Address::from_ref(it), - Self::TSBooleanKeyword(it) => Address::from_ref(it), - Self::TSNumberKeyword(it) => Address::from_ref(it), - Self::TSNeverKeyword(it) => Address::from_ref(it), - Self::TSIntrinsicKeyword(it) => Address::from_ref(it), - Self::TSUnknownKeyword(it) => Address::from_ref(it), - Self::TSNullKeyword(it) => Address::from_ref(it), - Self::TSUndefinedKeyword(it) => Address::from_ref(it), - Self::TSVoidKeyword(it) => Address::from_ref(it), - Self::TSSymbolKeyword(it) => Address::from_ref(it), - Self::TSThisType(it) => Address::from_ref(it), - Self::TSObjectKeyword(it) => Address::from_ref(it), - Self::TSBigIntKeyword(it) => Address::from_ref(it), - Self::TSTypeReference(it) => Address::from_ref(it), - Self::TSQualifiedName(it) => Address::from_ref(it), - Self::TSTypeParameterInstantiation(it) => Address::from_ref(it), - Self::TSTypeParameter(it) => Address::from_ref(it), - Self::TSTypeParameterDeclaration(it) => Address::from_ref(it), - Self::TSTypeAliasDeclaration(it) => Address::from_ref(it), - Self::TSClassImplements(it) => Address::from_ref(it), - Self::TSInterfaceDeclaration(it) => Address::from_ref(it), - Self::TSInterfaceBody(it) => Address::from_ref(it), - Self::TSPropertySignature(it) => Address::from_ref(it), - Self::TSIndexSignature(it) => Address::from_ref(it), - Self::TSCallSignatureDeclaration(it) => Address::from_ref(it), - Self::TSMethodSignature(it) => Address::from_ref(it), - Self::TSConstructSignatureDeclaration(it) => Address::from_ref(it), - Self::TSIndexSignatureName(it) => Address::from_ref(it), - Self::TSInterfaceHeritage(it) => Address::from_ref(it), - Self::TSTypePredicate(it) => Address::from_ref(it), - Self::TSModuleDeclaration(it) => Address::from_ref(it), - Self::TSModuleBlock(it) => Address::from_ref(it), - Self::TSTypeLiteral(it) => Address::from_ref(it), - Self::TSInferType(it) => Address::from_ref(it), - Self::TSTypeQuery(it) => Address::from_ref(it), - Self::TSImportType(it) => Address::from_ref(it), - Self::TSImportTypeQualifiedName(it) => Address::from_ref(it), - Self::TSFunctionType(it) => Address::from_ref(it), - Self::TSConstructorType(it) => Address::from_ref(it), - Self::TSMappedType(it) => Address::from_ref(it), - Self::TSTemplateLiteralType(it) => Address::from_ref(it), - Self::TSAsExpression(it) => Address::from_ref(it), - Self::TSSatisfiesExpression(it) => Address::from_ref(it), - Self::TSTypeAssertion(it) => Address::from_ref(it), - Self::TSImportEqualsDeclaration(it) => Address::from_ref(it), - Self::TSExternalModuleReference(it) => Address::from_ref(it), - Self::TSNonNullExpression(it) => Address::from_ref(it), - Self::Decorator(it) => Address::from_ref(it), - Self::TSExportAssignment(it) => Address::from_ref(it), - Self::TSNamespaceExportDeclaration(it) => Address::from_ref(it), - Self::TSInstantiationExpression(it) => Address::from_ref(it), - Self::JSDocNullableType(it) => Address::from_ref(it), - Self::JSDocNonNullableType(it) => Address::from_ref(it), - Self::JSDocUnknownType(it) => Address::from_ref(it), + Self::Program(it) => it.unstable_address(), + Self::IdentifierName(it) => it.unstable_address(), + Self::IdentifierReference(it) => it.unstable_address(), + Self::BindingIdentifier(it) => it.unstable_address(), + Self::LabelIdentifier(it) => it.unstable_address(), + Self::ThisExpression(it) => it.unstable_address(), + Self::ArrayExpression(it) => it.unstable_address(), + Self::Elision(it) => it.unstable_address(), + Self::ObjectExpression(it) => it.unstable_address(), + Self::ObjectProperty(it) => it.unstable_address(), + Self::TemplateLiteral(it) => it.unstable_address(), + Self::TaggedTemplateExpression(it) => it.unstable_address(), + Self::TemplateElement(it) => it.unstable_address(), + Self::ComputedMemberExpression(it) => it.unstable_address(), + Self::StaticMemberExpression(it) => it.unstable_address(), + Self::PrivateFieldExpression(it) => it.unstable_address(), + Self::CallExpression(it) => it.unstable_address(), + Self::NewExpression(it) => it.unstable_address(), + Self::MetaProperty(it) => it.unstable_address(), + Self::SpreadElement(it) => it.unstable_address(), + Self::UpdateExpression(it) => it.unstable_address(), + Self::UnaryExpression(it) => it.unstable_address(), + Self::BinaryExpression(it) => it.unstable_address(), + Self::PrivateInExpression(it) => it.unstable_address(), + Self::LogicalExpression(it) => it.unstable_address(), + Self::ConditionalExpression(it) => it.unstable_address(), + Self::AssignmentExpression(it) => it.unstable_address(), + Self::ArrayAssignmentTarget(it) => it.unstable_address(), + Self::ObjectAssignmentTarget(it) => it.unstable_address(), + Self::AssignmentTargetRest(it) => it.unstable_address(), + Self::AssignmentTargetWithDefault(it) => it.unstable_address(), + Self::AssignmentTargetPropertyIdentifier(it) => it.unstable_address(), + Self::AssignmentTargetPropertyProperty(it) => it.unstable_address(), + Self::SequenceExpression(it) => it.unstable_address(), + Self::Super(it) => it.unstable_address(), + Self::AwaitExpression(it) => it.unstable_address(), + Self::ChainExpression(it) => it.unstable_address(), + Self::ParenthesizedExpression(it) => it.unstable_address(), + Self::Directive(it) => it.unstable_address(), + Self::Hashbang(it) => it.unstable_address(), + Self::BlockStatement(it) => it.unstable_address(), + Self::VariableDeclaration(it) => it.unstable_address(), + Self::VariableDeclarator(it) => it.unstable_address(), + Self::EmptyStatement(it) => it.unstable_address(), + Self::ExpressionStatement(it) => it.unstable_address(), + Self::IfStatement(it) => it.unstable_address(), + Self::DoWhileStatement(it) => it.unstable_address(), + Self::WhileStatement(it) => it.unstable_address(), + Self::ForStatement(it) => it.unstable_address(), + Self::ForInStatement(it) => it.unstable_address(), + Self::ForOfStatement(it) => it.unstable_address(), + Self::ContinueStatement(it) => it.unstable_address(), + Self::BreakStatement(it) => it.unstable_address(), + Self::ReturnStatement(it) => it.unstable_address(), + Self::WithStatement(it) => it.unstable_address(), + Self::SwitchStatement(it) => it.unstable_address(), + Self::SwitchCase(it) => it.unstable_address(), + Self::LabeledStatement(it) => it.unstable_address(), + Self::ThrowStatement(it) => it.unstable_address(), + Self::TryStatement(it) => it.unstable_address(), + Self::CatchClause(it) => it.unstable_address(), + Self::CatchParameter(it) => it.unstable_address(), + Self::DebuggerStatement(it) => it.unstable_address(), + Self::AssignmentPattern(it) => it.unstable_address(), + Self::ObjectPattern(it) => it.unstable_address(), + Self::BindingProperty(it) => it.unstable_address(), + Self::ArrayPattern(it) => it.unstable_address(), + Self::BindingRestElement(it) => it.unstable_address(), + Self::Function(it) => it.unstable_address(), + Self::FormalParameters(it) => it.unstable_address(), + Self::FormalParameter(it) => it.unstable_address(), + Self::FunctionBody(it) => it.unstable_address(), + Self::ArrowFunctionExpression(it) => it.unstable_address(), + Self::YieldExpression(it) => it.unstable_address(), + Self::Class(it) => it.unstable_address(), + Self::ClassBody(it) => it.unstable_address(), + Self::MethodDefinition(it) => it.unstable_address(), + Self::PropertyDefinition(it) => it.unstable_address(), + Self::PrivateIdentifier(it) => it.unstable_address(), + Self::StaticBlock(it) => it.unstable_address(), + Self::AccessorProperty(it) => it.unstable_address(), + Self::ImportExpression(it) => it.unstable_address(), + Self::ImportDeclaration(it) => it.unstable_address(), + Self::ImportSpecifier(it) => it.unstable_address(), + Self::ImportDefaultSpecifier(it) => it.unstable_address(), + Self::ImportNamespaceSpecifier(it) => it.unstable_address(), + Self::WithClause(it) => it.unstable_address(), + Self::ImportAttribute(it) => it.unstable_address(), + Self::ExportNamedDeclaration(it) => it.unstable_address(), + Self::ExportDefaultDeclaration(it) => it.unstable_address(), + Self::ExportAllDeclaration(it) => it.unstable_address(), + Self::ExportSpecifier(it) => it.unstable_address(), + Self::V8IntrinsicExpression(it) => it.unstable_address(), + Self::BooleanLiteral(it) => it.unstable_address(), + Self::NullLiteral(it) => it.unstable_address(), + Self::NumericLiteral(it) => it.unstable_address(), + Self::StringLiteral(it) => it.unstable_address(), + Self::BigIntLiteral(it) => it.unstable_address(), + Self::RegExpLiteral(it) => it.unstable_address(), + Self::JSXElement(it) => it.unstable_address(), + Self::JSXOpeningElement(it) => it.unstable_address(), + Self::JSXClosingElement(it) => it.unstable_address(), + Self::JSXFragment(it) => it.unstable_address(), + Self::JSXOpeningFragment(it) => it.unstable_address(), + Self::JSXClosingFragment(it) => it.unstable_address(), + Self::JSXNamespacedName(it) => it.unstable_address(), + Self::JSXMemberExpression(it) => it.unstable_address(), + Self::JSXExpressionContainer(it) => it.unstable_address(), + Self::JSXEmptyExpression(it) => it.unstable_address(), + Self::JSXAttribute(it) => it.unstable_address(), + Self::JSXSpreadAttribute(it) => it.unstable_address(), + Self::JSXIdentifier(it) => it.unstable_address(), + Self::JSXSpreadChild(it) => it.unstable_address(), + Self::JSXText(it) => it.unstable_address(), + Self::TSThisParameter(it) => it.unstable_address(), + Self::TSEnumDeclaration(it) => it.unstable_address(), + Self::TSEnumBody(it) => it.unstable_address(), + Self::TSEnumMember(it) => it.unstable_address(), + Self::TSTypeAnnotation(it) => it.unstable_address(), + Self::TSLiteralType(it) => it.unstable_address(), + Self::TSConditionalType(it) => it.unstable_address(), + Self::TSUnionType(it) => it.unstable_address(), + Self::TSIntersectionType(it) => it.unstable_address(), + Self::TSParenthesizedType(it) => it.unstable_address(), + Self::TSTypeOperator(it) => it.unstable_address(), + Self::TSArrayType(it) => it.unstable_address(), + Self::TSIndexedAccessType(it) => it.unstable_address(), + Self::TSTupleType(it) => it.unstable_address(), + Self::TSNamedTupleMember(it) => it.unstable_address(), + Self::TSOptionalType(it) => it.unstable_address(), + Self::TSRestType(it) => it.unstable_address(), + Self::TSAnyKeyword(it) => it.unstable_address(), + Self::TSStringKeyword(it) => it.unstable_address(), + Self::TSBooleanKeyword(it) => it.unstable_address(), + Self::TSNumberKeyword(it) => it.unstable_address(), + Self::TSNeverKeyword(it) => it.unstable_address(), + Self::TSIntrinsicKeyword(it) => it.unstable_address(), + Self::TSUnknownKeyword(it) => it.unstable_address(), + Self::TSNullKeyword(it) => it.unstable_address(), + Self::TSUndefinedKeyword(it) => it.unstable_address(), + Self::TSVoidKeyword(it) => it.unstable_address(), + Self::TSSymbolKeyword(it) => it.unstable_address(), + Self::TSThisType(it) => it.unstable_address(), + Self::TSObjectKeyword(it) => it.unstable_address(), + Self::TSBigIntKeyword(it) => it.unstable_address(), + Self::TSTypeReference(it) => it.unstable_address(), + Self::TSQualifiedName(it) => it.unstable_address(), + Self::TSTypeParameterInstantiation(it) => it.unstable_address(), + Self::TSTypeParameter(it) => it.unstable_address(), + Self::TSTypeParameterDeclaration(it) => it.unstable_address(), + Self::TSTypeAliasDeclaration(it) => it.unstable_address(), + Self::TSClassImplements(it) => it.unstable_address(), + Self::TSInterfaceDeclaration(it) => it.unstable_address(), + Self::TSInterfaceBody(it) => it.unstable_address(), + Self::TSPropertySignature(it) => it.unstable_address(), + Self::TSIndexSignature(it) => it.unstable_address(), + Self::TSCallSignatureDeclaration(it) => it.unstable_address(), + Self::TSMethodSignature(it) => it.unstable_address(), + Self::TSConstructSignatureDeclaration(it) => it.unstable_address(), + Self::TSIndexSignatureName(it) => it.unstable_address(), + Self::TSInterfaceHeritage(it) => it.unstable_address(), + Self::TSTypePredicate(it) => it.unstable_address(), + Self::TSModuleDeclaration(it) => it.unstable_address(), + Self::TSModuleBlock(it) => it.unstable_address(), + Self::TSTypeLiteral(it) => it.unstable_address(), + Self::TSInferType(it) => it.unstable_address(), + Self::TSTypeQuery(it) => it.unstable_address(), + Self::TSImportType(it) => it.unstable_address(), + Self::TSImportTypeQualifiedName(it) => it.unstable_address(), + Self::TSFunctionType(it) => it.unstable_address(), + Self::TSConstructorType(it) => it.unstable_address(), + Self::TSMappedType(it) => it.unstable_address(), + Self::TSTemplateLiteralType(it) => it.unstable_address(), + Self::TSAsExpression(it) => it.unstable_address(), + Self::TSSatisfiesExpression(it) => it.unstable_address(), + Self::TSTypeAssertion(it) => it.unstable_address(), + Self::TSImportEqualsDeclaration(it) => it.unstable_address(), + Self::TSExternalModuleReference(it) => it.unstable_address(), + Self::TSNonNullExpression(it) => it.unstable_address(), + Self::Decorator(it) => it.unstable_address(), + Self::TSExportAssignment(it) => it.unstable_address(), + Self::TSNamespaceExportDeclaration(it) => it.unstable_address(), + Self::TSInstantiationExpression(it) => it.unstable_address(), + Self::JSDocNullableType(it) => it.unstable_address(), + Self::JSDocNonNullableType(it) => it.unstable_address(), + Self::JSDocUnknownType(it) => it.unstable_address(), } } } diff --git a/crates/oxc_linter/src/rules/typescript/explicit_module_boundary_types.rs b/crates/oxc_linter/src/rules/typescript/explicit_module_boundary_types.rs index 7c39816790008..79b504194c53f 100644 --- a/crates/oxc_linter/src/rules/typescript/explicit_module_boundary_types.rs +++ b/crates/oxc_linter/src/rules/typescript/explicit_module_boundary_types.rs @@ -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, @@ -297,11 +297,13 @@ enum Fn<'a> { Arrow(&'a ArrowFunctionExpression<'a>), None, } + impl Fn<'_> { fn address(self) -> Option
{ + // 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, } } @@ -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)); } @@ -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)); } diff --git a/crates/oxc_semantic/src/binder.rs b/crates/oxc_semantic/src/binder.rs index ceb53eb3e5234..9378da62c094b 100644 --- a/crates/oxc_semantic/src/binder.rs +++ b/crates/oxc_semantic/src/binder.rs @@ -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; @@ -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; diff --git a/crates/oxc_transformer/src/decorator/legacy/mod.rs b/crates/oxc_transformer/src/decorator/legacy/mod.rs index 2c6932390b1b1..04d4bf4cd1b5a 100644 --- a/crates/oxc_transformer/src/decorator/legacy/mod.rs +++ b/crates/oxc_transformer/src/decorator/legacy/mod.rs @@ -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; @@ -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); @@ -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); } diff --git a/crates/oxc_transformer/src/es2022/class_properties/class.rs b/crates/oxc_transformer/src/es2022/class_properties/class.rs index 77520ee244efc..4a8b400019c24 100644 --- a/crates/oxc_transformer/src/es2022/class_properties/class.rs +++ b/crates/oxc_transformer/src/es2022/class_properties/class.rs @@ -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::{ @@ -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() { diff --git a/crates/oxc_transformer/src/jsx/refresh.rs b/crates/oxc_transformer/src/jsx/refresh.rs index 19416ca231157..43499f2f3c755 100644 --- a/crates/oxc_transformer/src/jsx/refresh.rs +++ b/crates/oxc_transformer/src/jsx/refresh.rs @@ -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::{ @@ -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); } diff --git a/crates/oxc_transformer_plugins/src/replace_global_defines.rs b/crates/oxc_transformer_plugins/src/replace_global_defines.rs index 84436f8ce0648..1ff900c8d62a6 100644 --- a/crates/oxc_transformer_plugins/src/replace_global_defines.rs +++ b/crates/oxc_transformer_plugins/src/replace_global_defines.rs @@ -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; @@ -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()); } } @@ -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; } } diff --git a/tasks/ast_tools/src/generators/ast_kind.rs b/tasks/ast_tools/src/generators/ast_kind.rs index b0991e586ff36..5c82f48c77587 100644 --- a/tasks/ast_tools/src/generators/ast_kind.rs +++ b/tasks/ast_tools/src/generators/ast_kind.rs @@ -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!(), }; @@ -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