Skip to content

Commit

Permalink
chore: 🤖 refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
IWANABETHATGUY committed Jan 22, 2025
1 parent f95647b commit a519e6e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
7 changes: 1 addition & 6 deletions crates/oxc_allocator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ pub use vec::Vec;
pub struct Allocator {
bump: Bump,
}

impl Allocator {
/// Create a new [`Allocator`] with no initial capacity.
///
Expand Down Expand Up @@ -464,12 +465,6 @@ impl Allocator {
}
}

impl Allocator {
/// Create a new bump-allocated memory arena.
pub fn with_capacity(size: usize) -> Self {
Self { bump: Bump::with_capacity(size) }
}
}
/// SAFETY: Not actually safe, but for enabling `Send` for downstream crates.
unsafe impl Send for Allocator {}
/// SAFETY: Not actually safe, but for enabling `Sync` for downstream crates.
Expand Down
13 changes: 8 additions & 5 deletions crates/oxc_semantic/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,8 @@ impl SymbolTable {
/// use another `Allocator` to avoid memory leak
#[must_use]
pub fn clone_with_another_arena(&self) -> SymbolTable {
let allocator = self.inner.with_dependent(|alloc, _| Allocator::with_capacity(0));
let allocator =
self.inner.with_dependent(|alloc, _| Allocator::with_capacity(alloc.capacity()));
Self {
spans: self.spans.clone(),
flags: self.flags.clone(),
Expand All @@ -336,10 +337,12 @@ impl SymbolTable {
references: self.references.clone(),
inner: SymbolTableCell::new(allocator, |allocator| {
self.inner.with_dependent(|_allocator, inner| {
let names = inner.names.clone_in(&allocator);
let redeclaration_spans = inner.redeclaration_spans.clone_in(&allocator);
let resolved_references = inner.resolved_references.clone_in(&allocator);
SymbolTableInner { names, redeclaration_spans, resolved_references }
let names = inner.names.clone_in_with_semantic_ids(allocator);
let redeclaration_spans =
inner.redeclaration_spans.clone_in_with_semantic_ids(allocator);
let resolved_references =
inner.resolved_references.clone_in_with_semantic_ids(allocator);
SymbolTableInner { names, resolved_references, redeclaration_spans }
})
}),
}
Expand Down
19 changes: 12 additions & 7 deletions tasks/ast_tools/src/derives/clone_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,12 @@ fn derive_enum(def: &EnumDef) -> TokenStream {
fn derive_struct(def: &StructDef) -> TokenStream {
let ty_ident = def.ident();
let needs_override_clone_in_with_semantic_ids = Cell::new(false);
let (alloc_ident, clone_in_body, clone_in_with_semantic_ids_body) = if def.fields.is_empty() {
let (alloc_ident, clone_in_body, clone_in_with_semantic_ids_function) = if def.fields.is_empty()
{
(format_ident!("_"), quote!(#ty_ident), quote!())
} else {
let alloc_ident = format_ident!("allocator");
let fields = def
let clone_in_fields = def
.fields
.iter()
.map(|field| {
Expand Down Expand Up @@ -104,15 +105,19 @@ fn derive_struct(def: &StructDef) -> TokenStream {
} else {
quote!()
};
(alloc_ident, quote!(#ty_ident { #(#fields),* }), clone_in_with_semantic_ids_token_stream)
(
alloc_ident,
quote!(#ty_ident { #(#clone_in_fields),* }),
clone_in_with_semantic_ids_token_stream,
)
};

impl_clone_in(
&ty_ident,
def.has_lifetime,
&alloc_ident,
&clone_in_body,
&clone_in_with_semantic_ids_body,
&clone_in_with_semantic_ids_function,
)
}

Expand All @@ -121,7 +126,7 @@ fn impl_clone_in(
has_lifetime: bool,
alloc_ident: &Ident,
clone_in_body: &TokenStream,
clone_in_with_semantic_ids_body: &TokenStream,
clone_in_with_semantic_ids_function: &TokenStream,
) -> TokenStream {
if has_lifetime {
quote! {
Expand All @@ -131,7 +136,7 @@ fn impl_clone_in(
#clone_in_body
}

#clone_in_with_semantic_ids_body
#clone_in_with_semantic_ids_function
}
}
} else {
Expand All @@ -142,7 +147,7 @@ fn impl_clone_in(
#clone_in_body
}

#clone_in_with_semantic_ids_body
#clone_in_with_semantic_ids_function
}
}
}
Expand Down

0 comments on commit a519e6e

Please sign in to comment.