Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(ast)!: remove ReferenceFlag from IdentifierReference #5077

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
9 changes: 1 addition & 8 deletions crates/oxc_ast/src/ast/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use oxc_syntax::{
operator::{
AssignmentOperator, BinaryOperator, LogicalOperator, UnaryOperator, UpdateOperator,
},
reference::{ReferenceFlags, ReferenceId},
reference::ReferenceId,
scope::ScopeId,
symbol::SymbolId,
};
Expand Down Expand Up @@ -239,13 +239,6 @@ pub struct IdentifierReference<'a> {
#[serde(skip)]
#[clone_in(default)]
pub reference_id: Cell<Option<ReferenceId>>,
/// Flags indicating how the reference is used.
///
/// This gets set in the bind step of semantic analysis, and will always be
/// [`ReferenceFlags::None`] immediately after parsing.
#[serde(skip)]
#[clone_in(default)]
pub reference_flags: ReferenceFlags,
}

/// `x` in `const x = 0;`
Expand Down
20 changes: 3 additions & 17 deletions crates/oxc_ast/src/ast_impl/js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ use std::{borrow::Cow, cell::Cell, fmt, hash::Hash};

use oxc_allocator::{Box, FromIn, Vec};
use oxc_span::{Atom, GetSpan, SourceType, Span};
use oxc_syntax::{
operator::UnaryOperator,
reference::{ReferenceFlags, ReferenceId},
scope::ScopeFlags,
};
use oxc_syntax::{operator::UnaryOperator, reference::ReferenceId, scope::ScopeFlags};

#[cfg(feature = "serialize")]
#[wasm_bindgen::prelude::wasm_bindgen(typescript_custom_section)]
Expand Down Expand Up @@ -330,21 +326,11 @@ impl<'a> Hash for IdentifierReference<'a> {

impl<'a> IdentifierReference<'a> {
pub fn new(span: Span, name: Atom<'a>) -> Self {
Self {
span,
name,
reference_id: Cell::default(),
reference_flags: ReferenceFlags::default(),
}
Self { span, name, reference_id: Cell::default() }
}

pub fn new_read(span: Span, name: Atom<'a>, reference_id: Option<ReferenceId>) -> Self {
Self {
span,
name,
reference_id: Cell::new(reference_id),
reference_flags: ReferenceFlags::Read,
}
Self { span, name, reference_id: Cell::new(reference_id) }
}

#[inline]
Expand Down
32 changes: 15 additions & 17 deletions crates/oxc_ast/src/generated/assert_layouts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ const _: () = {
assert!(offset_of!(IdentifierReference, span) == 0usize);
assert!(offset_of!(IdentifierReference, name) == 8usize);
assert!(offset_of!(IdentifierReference, reference_id) == 24usize);
assert!(offset_of!(IdentifierReference, reference_flags) == 28usize);

assert!(size_of::<BindingIdentifier>() == 32usize);
assert!(align_of::<BindingIdentifier>() == 8usize);
Expand Down Expand Up @@ -1471,12 +1470,11 @@ const _: () = {
assert!(offset_of!(IdentifierName, span) == 0usize);
assert!(offset_of!(IdentifierName, name) == 8usize);

assert!(size_of::<IdentifierReference>() == 24usize);
assert!(size_of::<IdentifierReference>() == 20usize);
assert!(align_of::<IdentifierReference>() == 4usize);
assert!(offset_of!(IdentifierReference, span) == 0usize);
assert!(offset_of!(IdentifierReference, name) == 8usize);
assert!(offset_of!(IdentifierReference, reference_id) == 16usize);
assert!(offset_of!(IdentifierReference, reference_flags) == 20usize);

assert!(size_of::<BindingIdentifier>() == 20usize);
assert!(align_of::<BindingIdentifier>() == 4usize);
Expand Down Expand Up @@ -1696,11 +1694,11 @@ const _: () = {
assert!(size_of::<AssignmentTargetProperty>() == 8usize);
assert!(align_of::<AssignmentTargetProperty>() == 4usize);

assert!(size_of::<AssignmentTargetPropertyIdentifier>() == 40usize);
assert!(size_of::<AssignmentTargetPropertyIdentifier>() == 36usize);
assert!(align_of::<AssignmentTargetPropertyIdentifier>() == 4usize);
assert!(offset_of!(AssignmentTargetPropertyIdentifier, span) == 0usize);
assert!(offset_of!(AssignmentTargetPropertyIdentifier, binding) == 8usize);
assert!(offset_of!(AssignmentTargetPropertyIdentifier, init) == 32usize);
assert!(offset_of!(AssignmentTargetPropertyIdentifier, init) == 28usize);

assert!(size_of::<AssignmentTargetPropertyProperty>() == 24usize);
assert!(align_of::<AssignmentTargetPropertyProperty>() == 4usize);
Expand Down Expand Up @@ -2120,12 +2118,12 @@ const _: () = {
assert!(size_of::<ImportDeclarationSpecifier>() == 8usize);
assert!(align_of::<ImportDeclarationSpecifier>() == 4usize);

assert!(size_of::<ImportSpecifier>() == 60usize);
assert!(size_of::<ImportSpecifier>() == 56usize);
assert!(align_of::<ImportSpecifier>() == 4usize);
assert!(offset_of!(ImportSpecifier, span) == 0usize);
assert!(offset_of!(ImportSpecifier, imported) == 8usize);
assert!(offset_of!(ImportSpecifier, local) == 36usize);
assert!(offset_of!(ImportSpecifier, import_kind) == 56usize);
assert!(offset_of!(ImportSpecifier, local) == 32usize);
assert!(offset_of!(ImportSpecifier, import_kind) == 52usize);

assert!(size_of::<ImportDefaultSpecifier>() == 28usize);
assert!(align_of::<ImportDefaultSpecifier>() == 4usize);
Expand Down Expand Up @@ -2161,31 +2159,31 @@ const _: () = {
assert!(offset_of!(ExportNamedDeclaration, export_kind) == 48usize);
assert!(offset_of!(ExportNamedDeclaration, with_clause) == 52usize);

assert!(size_of::<ExportDefaultDeclaration>() == 44usize);
assert!(size_of::<ExportDefaultDeclaration>() == 40usize);
assert!(align_of::<ExportDefaultDeclaration>() == 4usize);
assert!(offset_of!(ExportDefaultDeclaration, span) == 0usize);
assert!(offset_of!(ExportDefaultDeclaration, declaration) == 8usize);
assert!(offset_of!(ExportDefaultDeclaration, exported) == 16usize);

assert!(size_of::<ExportAllDeclaration>() == 96usize);
assert!(size_of::<ExportAllDeclaration>() == 92usize);
assert!(align_of::<ExportAllDeclaration>() == 4usize);
assert!(offset_of!(ExportAllDeclaration, span) == 0usize);
assert!(offset_of!(ExportAllDeclaration, exported) == 8usize);
assert!(offset_of!(ExportAllDeclaration, source) == 36usize);
assert!(offset_of!(ExportAllDeclaration, with_clause) == 52usize);
assert!(offset_of!(ExportAllDeclaration, export_kind) == 92usize);
assert!(offset_of!(ExportAllDeclaration, source) == 32usize);
assert!(offset_of!(ExportAllDeclaration, with_clause) == 48usize);
assert!(offset_of!(ExportAllDeclaration, export_kind) == 88usize);

assert!(size_of::<ExportSpecifier>() == 68usize);
assert!(size_of::<ExportSpecifier>() == 60usize);
assert!(align_of::<ExportSpecifier>() == 4usize);
assert!(offset_of!(ExportSpecifier, span) == 0usize);
assert!(offset_of!(ExportSpecifier, local) == 8usize);
assert!(offset_of!(ExportSpecifier, exported) == 36usize);
assert!(offset_of!(ExportSpecifier, export_kind) == 64usize);
assert!(offset_of!(ExportSpecifier, exported) == 32usize);
assert!(offset_of!(ExportSpecifier, export_kind) == 56usize);

assert!(size_of::<ExportDefaultDeclarationKind>() == 8usize);
assert!(align_of::<ExportDefaultDeclarationKind>() == 4usize);

assert!(size_of::<ModuleExportName>() == 28usize);
assert!(size_of::<ModuleExportName>() == 24usize);
assert!(align_of::<ModuleExportName>() == 4usize);

assert!(size_of::<TSThisParameter>() == 28usize);
Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/ast_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,6 @@ impl<'a> AstBuilder<'a> {
span,
name: name.into_in(self.allocator),
reference_id: Default::default(),
reference_flags: Default::default(),
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/oxc_ast/src/generated/derive_clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,6 @@ impl<'old_alloc, 'new_alloc> CloneIn<'new_alloc> for IdentifierReference<'old_al
span: self.span.clone_in(allocator),
name: self.name.clone_in(allocator),
reference_id: Default::default(),
reference_flags: Default::default(),
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions crates/oxc_minifier/src/node_util/check_for_state_change.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use oxc_ast::ast::*;

use oxc_semantic::ReferenceFlags;
use oxc_syntax::operator::UnaryOperator;

/// A "simple" operator is one whose children are expressions, has no direct side-effects.
Expand Down Expand Up @@ -33,7 +32,11 @@ impl<'a, 'b> CheckForStateChange<'a, 'b> for Expression<'a> {
.expressions
.iter()
.any(|expr| expr.check_for_state_change(check_for_new_objects)),
Self::Identifier(ident) => ident.reference_flags == ReferenceFlags::Write,
Self::Identifier(_ident) =>
/* TODO: ident.reference_flags == ReferenceFlags::Write */
{
false
}
Self::UnaryExpression(unary_expr) => {
unary_expr.check_for_state_change(check_for_new_objects)
}
Expand Down
3 changes: 1 addition & 2 deletions crates/oxc_transformer/src/typescript/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,7 @@ impl<'a> TypeScript<'a> {
) -> Expression<'a> {
match type_name {
TSTypeName::IdentifierReference(ident) => {
let mut ident = ident.clone();
ident.reference_flags = ReferenceFlags::Read;
let ident = ident.clone();
let reference_id = ident.reference_id.get().unwrap();
let reference = ctx.symbols_mut().get_reference_mut(reference_id);
*reference.flags_mut() = ReferenceFlags::Read;
Expand Down
14 changes: 2 additions & 12 deletions crates/oxc_traverse/src/context/scoping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,12 +284,7 @@ impl TraverseScoping {
flags: ReferenceFlags,
) -> IdentifierReference<'a> {
let reference_id = self.create_bound_reference(symbol_id, flags);
IdentifierReference {
span,
name,
reference_id: Cell::new(Some(reference_id)),
reference_flags: flags,
}
IdentifierReference { span, name, reference_id: Cell::new(Some(reference_id)) }
}

/// Create an unbound reference
Expand All @@ -312,12 +307,7 @@ impl TraverseScoping {
flags: ReferenceFlags,
) -> IdentifierReference<'a> {
let reference_id = self.create_unbound_reference(name.to_compact_str(), flags);
IdentifierReference {
span,
name,
reference_id: Cell::new(Some(reference_id)),
reference_flags: flags,
}
IdentifierReference { span, name, reference_id: Cell::new(Some(reference_id)) }
}

/// Create a reference optionally bound to a `SymbolId`.
Expand Down