mirror of
https://github.com/danbulant/oxc
synced 2026-05-19 12:19:15 +00:00
feat(ast)!: remove unused and not useful ContentHash (#8483)
`ContentEq` is preferred.
This commit is contained in:
parent
c83ce5c6cf
commit
7eb6ccde66
12 changed files with 9 additions and 2732 deletions
3
.github/.generated_ast_watch_list.yml
vendored
3
.github/.generated_ast_watch_list.yml
vendored
|
|
@ -22,9 +22,6 @@ src:
|
|||
- 'crates/oxc_ast/src/generated/derive_content_eq.rs'
|
||||
- 'crates/oxc_regular_expression/src/generated/derive_content_eq.rs'
|
||||
- 'crates/oxc_syntax/src/generated/derive_content_eq.rs'
|
||||
- 'crates/oxc_ast/src/generated/derive_content_hash.rs'
|
||||
- 'crates/oxc_regular_expression/src/generated/derive_content_hash.rs'
|
||||
- 'crates/oxc_syntax/src/generated/derive_content_hash.rs'
|
||||
- 'crates/oxc_ast/src/generated/derive_estree.rs'
|
||||
- 'crates/oxc_regular_expression/src/generated/derive_estree.rs'
|
||||
- 'crates/oxc_span/src/generated/derive_estree.rs'
|
||||
|
|
|
|||
|
|
@ -206,12 +206,6 @@ impl ContentEq for RegExpLiteral<'_> {
|
|||
}
|
||||
}
|
||||
|
||||
impl ContentHash for RegExpLiteral<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.regex, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for RegExp<'_> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "/{}/{}", self.pattern, self.flags)
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -62,7 +62,6 @@ mod generated {
|
|||
pub mod ast_kind;
|
||||
pub mod derive_clone_in;
|
||||
pub mod derive_content_eq;
|
||||
pub mod derive_content_hash;
|
||||
#[cfg(feature = "serialize")]
|
||||
pub mod derive_estree;
|
||||
pub mod derive_get_address;
|
||||
|
|
|
|||
|
|
@ -1,211 +0,0 @@
|
|||
// Auto-generated code, DO NOT EDIT DIRECTLY!
|
||||
// To edit this generated file you have to edit `tasks/ast_tools/src/derives/content_hash.rs`
|
||||
|
||||
#![allow(clippy::match_same_arms)]
|
||||
|
||||
use std::{hash::Hasher, mem::discriminant};
|
||||
|
||||
use oxc_span::hash::ContentHash;
|
||||
|
||||
use crate::ast::*;
|
||||
|
||||
impl ContentHash for Pattern<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.body, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for Disjunction<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.body, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for Alternative<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.body, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for Term<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
match self {
|
||||
Self::BoundaryAssertion(it) => ContentHash::content_hash(it, state),
|
||||
Self::LookAroundAssertion(it) => ContentHash::content_hash(it, state),
|
||||
Self::Quantifier(it) => ContentHash::content_hash(it, state),
|
||||
Self::Character(it) => ContentHash::content_hash(it, state),
|
||||
Self::Dot(it) => ContentHash::content_hash(it, state),
|
||||
Self::CharacterClassEscape(it) => ContentHash::content_hash(it, state),
|
||||
Self::UnicodePropertyEscape(it) => ContentHash::content_hash(it, state),
|
||||
Self::CharacterClass(it) => ContentHash::content_hash(it, state),
|
||||
Self::CapturingGroup(it) => ContentHash::content_hash(it, state),
|
||||
Self::IgnoreGroup(it) => ContentHash::content_hash(it, state),
|
||||
Self::IndexedReference(it) => ContentHash::content_hash(it, state),
|
||||
Self::NamedReference(it) => ContentHash::content_hash(it, state),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for BoundaryAssertion {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.kind, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for BoundaryAssertionKind {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for LookAroundAssertion<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.kind, state);
|
||||
ContentHash::content_hash(&self.body, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for LookAroundAssertionKind {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for Quantifier<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.min, state);
|
||||
ContentHash::content_hash(&self.max, state);
|
||||
ContentHash::content_hash(&self.greedy, state);
|
||||
ContentHash::content_hash(&self.body, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for Character {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.kind, state);
|
||||
ContentHash::content_hash(&self.value, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for CharacterKind {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for CharacterClassEscape {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.kind, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for CharacterClassEscapeKind {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for UnicodePropertyEscape<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.negative, state);
|
||||
ContentHash::content_hash(&self.strings, state);
|
||||
ContentHash::content_hash(&self.name, state);
|
||||
ContentHash::content_hash(&self.value, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for Dot {
|
||||
fn content_hash<H: Hasher>(&self, _: &mut H) {}
|
||||
}
|
||||
|
||||
impl ContentHash for CharacterClass<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.negative, state);
|
||||
ContentHash::content_hash(&self.strings, state);
|
||||
ContentHash::content_hash(&self.kind, state);
|
||||
ContentHash::content_hash(&self.body, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for CharacterClassContentsKind {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for CharacterClassContents<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
match self {
|
||||
Self::CharacterClassRange(it) => ContentHash::content_hash(it, state),
|
||||
Self::CharacterClassEscape(it) => ContentHash::content_hash(it, state),
|
||||
Self::UnicodePropertyEscape(it) => ContentHash::content_hash(it, state),
|
||||
Self::Character(it) => ContentHash::content_hash(it, state),
|
||||
Self::NestedCharacterClass(it) => ContentHash::content_hash(it, state),
|
||||
Self::ClassStringDisjunction(it) => ContentHash::content_hash(it, state),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for CharacterClassRange {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.min, state);
|
||||
ContentHash::content_hash(&self.max, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for ClassStringDisjunction<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.strings, state);
|
||||
ContentHash::content_hash(&self.body, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for ClassString<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.strings, state);
|
||||
ContentHash::content_hash(&self.body, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for CapturingGroup<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.name, state);
|
||||
ContentHash::content_hash(&self.body, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for IgnoreGroup<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.modifiers, state);
|
||||
ContentHash::content_hash(&self.body, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for Modifiers {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.enabling, state);
|
||||
ContentHash::content_hash(&self.disabling, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for Modifier {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.ignore_case, state);
|
||||
ContentHash::content_hash(&self.multiline, state);
|
||||
ContentHash::content_hash(&self.sticky, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for IndexedReference {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.index, state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for NamedReference<'_> {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&self.name, state);
|
||||
}
|
||||
}
|
||||
|
|
@ -9,7 +9,6 @@ mod surrogate_pair;
|
|||
mod generated {
|
||||
mod derive_clone_in;
|
||||
mod derive_content_eq;
|
||||
mod derive_content_hash;
|
||||
#[cfg(feature = "serialize")]
|
||||
mod derive_estree;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,54 +0,0 @@
|
|||
// Auto-generated code, DO NOT EDIT DIRECTLY!
|
||||
// To edit this generated file you have to edit `tasks/ast_tools/src/derives/content_hash.rs`
|
||||
|
||||
#![allow(clippy::match_same_arms)]
|
||||
|
||||
use std::{hash::Hasher, mem::discriminant};
|
||||
|
||||
use oxc_span::hash::ContentHash;
|
||||
|
||||
use crate::number::*;
|
||||
|
||||
use crate::operator::*;
|
||||
|
||||
impl ContentHash for NumberBase {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for BigintBase {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for AssignmentOperator {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for BinaryOperator {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for LogicalOperator {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for UnaryOperator {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
}
|
||||
}
|
||||
|
||||
impl ContentHash for UpdateOperator {
|
||||
fn content_hash<H: Hasher>(&self, state: &mut H) {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
}
|
||||
}
|
||||
|
|
@ -16,7 +16,6 @@ pub mod xml_entities;
|
|||
mod generated {
|
||||
mod derive_clone_in;
|
||||
mod derive_content_eq;
|
||||
mod derive_content_hash;
|
||||
#[cfg(feature = "serialize")]
|
||||
mod derive_estree;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,14 @@ use crate::{
|
|||
util::ToIdent,
|
||||
};
|
||||
|
||||
use super::{content_hash::IGNORE_FIELD_TYPES, define_derive, Derive};
|
||||
use super::{define_derive, Derive};
|
||||
|
||||
const IGNORE_FIELD_TYPES: [/* type name */ &str; 4] = [
|
||||
"Span",
|
||||
"ScopeId",
|
||||
"SymbolId",
|
||||
"ReferenceId",
|
||||
];
|
||||
|
||||
pub struct DeriveContentEq;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,117 +0,0 @@
|
|||
use itertools::Itertools;
|
||||
use proc_macro2::TokenStream;
|
||||
use quote::quote;
|
||||
|
||||
use crate::{
|
||||
schema::{EnumDef, GetGenerics, Schema, StructDef, ToType, TypeDef},
|
||||
util::ToIdent,
|
||||
};
|
||||
|
||||
use super::{define_derive, Derive};
|
||||
|
||||
pub struct DeriveContentHash;
|
||||
|
||||
define_derive!(DeriveContentHash);
|
||||
|
||||
pub const IGNORE_FIELD_TYPES: [/* type name */ &str; 4] = [
|
||||
"Span",
|
||||
"ScopeId",
|
||||
"SymbolId",
|
||||
"ReferenceId",
|
||||
];
|
||||
|
||||
impl Derive for DeriveContentHash {
|
||||
fn trait_name() -> &'static str {
|
||||
"ContentHash"
|
||||
}
|
||||
|
||||
fn prelude() -> TokenStream {
|
||||
quote! {
|
||||
#![allow(clippy::match_same_arms)]
|
||||
|
||||
///@@line_break
|
||||
use std::{hash::Hasher, mem::discriminant};
|
||||
|
||||
///@@line_break
|
||||
use oxc_span::hash::ContentHash;
|
||||
}
|
||||
}
|
||||
|
||||
fn derive(&mut self, def: &TypeDef, _: &Schema) -> TokenStream {
|
||||
let (hasher, body) = match &def {
|
||||
TypeDef::Enum(it) => derive_enum(it),
|
||||
TypeDef::Struct(it) => derive_struct(it),
|
||||
};
|
||||
|
||||
impl_content_hash(def, hasher, &body)
|
||||
}
|
||||
}
|
||||
|
||||
fn derive_enum(def: &EnumDef) -> (&str, TokenStream) {
|
||||
let mut body = quote! {
|
||||
ContentHash::content_hash(&discriminant(self), state);
|
||||
};
|
||||
|
||||
body.extend(if def.is_unit() {
|
||||
TokenStream::default()
|
||||
} else {
|
||||
let mut non_exhaustive = false;
|
||||
let matches = def
|
||||
.all_variants()
|
||||
.filter_map(|var| {
|
||||
let ident = var.ident();
|
||||
if var.is_unit() {
|
||||
non_exhaustive = true;
|
||||
None
|
||||
} else {
|
||||
Some(quote!(Self :: #ident(it) => ContentHash::content_hash(it, state)))
|
||||
}
|
||||
})
|
||||
.collect_vec();
|
||||
let exhaust = non_exhaustive.then(|| quote!(_ => {}));
|
||||
quote! {
|
||||
match self {
|
||||
#(#matches),*
|
||||
#exhaust
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
("state", body)
|
||||
}
|
||||
|
||||
fn derive_struct(def: &StructDef) -> (&str, TokenStream) {
|
||||
if def.fields.is_empty() {
|
||||
("_", TokenStream::default())
|
||||
} else {
|
||||
let fields = def
|
||||
.fields
|
||||
.iter()
|
||||
.filter(|field| {
|
||||
!IGNORE_FIELD_TYPES.iter().any(|it| field.typ.name().inner_name() == *it)
|
||||
})
|
||||
.map(|field| {
|
||||
let ident = field.ident();
|
||||
quote!(ContentHash::content_hash(&self.#ident, state);)
|
||||
})
|
||||
.collect_vec();
|
||||
if fields.is_empty() {
|
||||
("_", TokenStream::default())
|
||||
} else {
|
||||
("state", quote!(#(#fields)*))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn impl_content_hash(def: &TypeDef, hasher_name: &str, body: &TokenStream) -> TokenStream {
|
||||
let ty = if def.has_lifetime() { def.to_elided_type() } else { def.to_type_elide() };
|
||||
let hasher = hasher_name.to_ident();
|
||||
|
||||
quote! {
|
||||
impl ContentHash for #ty {
|
||||
fn content_hash<H: Hasher>(&self, #hasher: &mut H) {
|
||||
#body
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -13,14 +13,12 @@ use crate::{
|
|||
|
||||
mod clone_in;
|
||||
mod content_eq;
|
||||
mod content_hash;
|
||||
mod estree;
|
||||
mod get_address;
|
||||
mod get_span;
|
||||
|
||||
pub use clone_in::DeriveCloneIn;
|
||||
pub use content_eq::DeriveContentEq;
|
||||
pub use content_hash::DeriveContentHash;
|
||||
pub use estree::DeriveESTree;
|
||||
pub use get_address::DeriveGetAddress;
|
||||
pub use get_span::{DeriveGetSpan, DeriveGetSpanMut};
|
||||
|
|
|
|||
|
|
@ -18,8 +18,7 @@ mod schema;
|
|||
mod util;
|
||||
|
||||
use derives::{
|
||||
DeriveCloneIn, DeriveContentEq, DeriveContentHash, DeriveESTree, DeriveGetAddress,
|
||||
DeriveGetSpan, DeriveGetSpanMut,
|
||||
DeriveCloneIn, DeriveContentEq, DeriveESTree, DeriveGetAddress, DeriveGetSpan, DeriveGetSpanMut,
|
||||
};
|
||||
use generators::{
|
||||
AssertLayouts, AstBuilderGenerator, AstKindGenerator, Generator, GetIdGenerator,
|
||||
|
|
@ -80,7 +79,6 @@ fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
|
|||
.generate(DeriveGetSpan)
|
||||
.generate(DeriveGetSpanMut)
|
||||
.generate(DeriveContentEq)
|
||||
.generate(DeriveContentHash)
|
||||
.generate(DeriveESTree)
|
||||
.generate(AssertLayouts)
|
||||
.generate(AstKindGenerator)
|
||||
|
|
|
|||
Loading…
Reference in a new issue