diff --git a/crates/oxc_allocator/src/clone_in.rs b/crates/oxc_allocator/src/clone_in.rs index 6fe455dc7c1df3..ae22d08305afd9 100644 --- a/crates/oxc_allocator/src/clone_in.rs +++ b/crates/oxc_allocator/src/clone_in.rs @@ -33,6 +33,7 @@ pub trait CloneIn<'new_alloc>: Sized { fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned; /// Almost same as `clone_in`, but for some special type, it will also clone the semantic ids. + /// Please use this method only if you make sure the semantic info is synced with the ast. #[inline] fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { self.clone_in(allocator) diff --git a/crates/oxc_allocator/src/lib.rs b/crates/oxc_allocator/src/lib.rs index 050f1bd94b5ad2..e06e352e3f720c 100644 --- a/crates/oxc_allocator/src/lib.rs +++ b/crates/oxc_allocator/src/lib.rs @@ -32,911 +32,3 @@ pub use convert::{FromIn, IntoIn}; pub use hash_map::HashMap; pub use string::String; pub use vec::Vec; -<<<<<<< HEAD -||||||| parent of 692c44faf (feat: 🎸 make data in arena cloneable) - -/// A bump-allocated memory arena. -/// -/// # Anatomy of an Allocator -/// -/// [`Allocator`] is flexibly sized. It grows as required as you allocate data into it. -/// -/// To do that, an [`Allocator`] consists of multiple memory chunks. -/// -/// [`Allocator::new`] creates a new allocator without any chunks. When you first allocate an object -/// into it, it will lazily create an initial chunk, the size of which is determined by the size of that -/// first allocation. -/// -/// As more data is allocated into the [`Allocator`], it will likely run out of capacity. At that point, -/// a new memory chunk is added, and further allocations will use this new chunk (until it too runs out -/// of capacity, and *another* chunk is added). -/// -/// The data from the 1st chunk is not copied into the 2nd one. It stays where it is, which means -/// `&` or `&mut` references to data in the first chunk remain valid. This is unlike e.g. `Vec` which -/// copies all existing data when it grows. -/// -/// Each chunk is at least double the size of the last one, so growth in capacity is exponential. -/// -/// [`Allocator::reset`] keeps only the last chunk (the biggest one), and discards any other chunks, -/// returning their memory to the global allocator. The last chunk has its cursor rewound back to -/// the start, so it's empty, ready to be re-used for allocating more data. -/// -/// # Recycling allocators -/// -/// For good performance, it's ideal to create an [`Allocator`], and re-use it over and over, rather than -/// repeatedly creating and dropping [`Allocator`]s. -/// -/// ``` -/// // This is good! -/// use oxc_allocator::Allocator; -/// let mut allocator = Allocator::new(); -/// -/// # fn do_stuff(_n: usize, _allocator: &Allocator) {} -/// for i in 0..100 { -/// do_stuff(i, &allocator); -/// // Reset the allocator, freeing the memory used by `do_stuff` -/// allocator.reset(); -/// } -/// ``` -/// -/// ``` -/// // DON'T DO THIS! -/// # use oxc_allocator::Allocator; -/// # fn do_stuff(_n: usize, _allocator: &Allocator) {} -/// for i in 0..100 { -/// let allocator = Allocator::new(); -/// do_stuff(i, &allocator); -/// } -/// ``` -/// -/// ``` -/// // DON'T DO THIS EITHER! -/// # use oxc_allocator::Allocator; -/// # let allocator = Allocator::new(); -/// # fn do_stuff(_n: usize, _allocator: &Allocator) {} -/// for i in 0..100 { -/// do_stuff(i, &allocator); -/// // We haven't reset the allocator, so we haven't freed the memory used by `do_stuff`. -/// // The allocator will grow and grow, consuming more and more memory. -/// } -/// ``` -/// -/// ## Why is re-using an [`Allocator`] good for performance? -/// -/// 3 reasons: -/// -/// #### 1. Avoid expensive system calls -/// -/// Creating an [`Allocator`] is a fairly expensive operation as it involves a call into global allocator, -/// which in turn will likely make a system call. Ditto when the [`Allocator`] is dropped. -/// Re-using an existing [`Allocator`] avoids these costs. -/// -/// #### 2. CPU cache -/// -/// Re-using an existing allocator means you're re-using the same block of memory. If that memory was -/// recently accessed, it's likely to be warm in the CPU cache, so memory accesses will be much faster -/// than accessing "cold" sections of main memory. -/// -/// This can have a very significant positive impact on performance. -/// -/// #### 3. Capacity stabilization -/// -/// The most efficient [`Allocator`] is one with only 1 chunk which has sufficient capacity for -/// everything you're going to allocate into it. -/// -/// Why? -/// -/// 1. Every allocation will occur without the allocator needing to grow. -/// -/// 2. This makes the "is there sufficient capacity to allocate this?" check in [`alloc`] completely -/// predictable (the answer is always "yes"). The CPU's branch predictor swiftly learns this, -/// speeding up operation. -/// -/// 3. When the [`Allocator`] is reset, there are no excess chunks to discard, so no system calls. -/// -/// Because [`reset`] keeps only the biggest chunk (see above), re-using the same [`Allocator`] -/// for multiple similar workloads will result in the [`Allocator`] swiftly stabilizing at a capacity -/// which is sufficient to service those workloads with a single chunk. -/// -/// If workload is completely uniform, it reaches stable state on the 3rd round. -/// -/// ``` -/// # use oxc_allocator::Allocator; -/// let mut allocator = Allocator::new(); -/// -/// fn workload(allocator: &Allocator) { -/// // Allocate 4 MB of data in small chunks -/// for i in 0..1_000_000u32 { -/// allocator.alloc(i); -/// } -/// } -/// -/// // 1st round -/// workload(&allocator); -/// -/// // `allocator` has capacity for 4 MB data, but split into many chunks. -/// // `reset` throws away all chunks except the last one which will be approx 2 MB. -/// allocator.reset(); -/// -/// // 2nd round -/// workload(&allocator); -/// -/// // `workload` filled the 2 MB chunk, so a 2nd chunk was created of double the size (4 MB). -/// // `reset` discards the smaller chunk, leaving only a single 4 MB chunk. -/// allocator.reset(); -/// -/// // 3rd round -/// // `allocator` now has sufficient capacity for all allocations in a single 4 MB chunk. -/// workload(&allocator); -/// -/// // `reset` has no chunks to discard. It keeps the single 4 MB chunk. No system calls. -/// allocator.reset(); -/// -/// // More rounds -/// // All serviced without needing to grow the allocator, and with no system calls. -/// for _ in 0..100 { -/// workload(&allocator); -/// allocator.reset(); -/// } -/// ``` -/// -/// [`reset`]: Allocator::reset -/// [`alloc`]: Allocator::alloc -/// -/// # No `Drop`s -/// -/// Objects allocated into Oxc memory arenas are never [`Dropped`](Drop). -/// Memory is released in bulk when the allocator is dropped, without dropping the individual -/// objects in the arena. -/// -/// Therefore, it would produce a memory leak if you allocated [`Drop`] types into the arena -/// which own memory allocations outside the arena. -/// -/// Static checks make this impossible to do. [`Allocator::alloc`], [`Box::new_in`], [`Vec::new_in`], -/// [`HashMap::new_in`], and all other methods which store data in the arena will refuse to compile -/// if called with a [`Drop`] type. -/// -/// ```ignore -/// use oxc_allocator::{Allocator, Box}; -/// -/// let allocator = Allocator::new(); -/// -/// struct Foo { -/// pub a: i32 -/// } -/// -/// impl std::ops::Drop for Foo { -/// fn drop(&mut self) {} -/// } -/// -/// // This will fail to compile because `Foo` implements `Drop` -/// let foo = Box::new_in(Foo { a: 0 }, &allocator); -/// -/// struct Bar { -/// v: std::vec::Vec, -/// } -/// -/// // This will fail to compile because `Bar` contains a `std::vec::Vec`, and it implements `Drop` -/// let bar = Box::new_in(Bar { v: vec![1, 2, 3] }, &allocator); -/// ``` -/// -/// # Examples -/// -/// Consumers of the [`oxc` umbrella crate](https://crates.io/crates/oxc) pass -/// [`Allocator`] references to other tools. -/// -/// ```ignore -/// use oxc::{allocator::Allocator, parser::Parser, span::SourceType}; -/// -/// let allocator = Allocator::default(); -/// let parsed = Parser::new(&allocator, "let x = 1;", SourceType::default()); -/// assert!(parsed.errors.is_empty()); -/// ``` -#[derive(Default)] -pub struct Allocator { - bump: Bump, -} - -impl Allocator { - /// Create a new [`Allocator`] with no initial capacity. - /// - /// This method does not reserve any memory to back the allocator. Memory for allocator's initial - /// chunk will be reserved lazily, when you make the first allocation into this [`Allocator`] - /// (e.g. with [`Allocator::alloc`], [`Box::new_in`], [`Vec::new_in`], [`HashMap::new_in`]). - /// - /// If you can estimate the amount of memory the allocator will require to fit what you intend to - /// allocate into it, it is generally preferable to create that allocator with [`with_capacity`], - /// which reserves that amount of memory upfront. This will avoid further system calls to allocate - /// further chunks later on. This point is less important if you're re-using the allocator multiple - /// times. - /// - /// See [`Allocator`] docs for more information on efficient use of [`Allocator`]. - /// - /// [`with_capacity`]: Allocator::with_capacity - // - // `#[inline(always)]` because just delegates to `bumpalo` method - #[expect(clippy::inline_always)] - #[inline(always)] - pub fn new() -> Self { - Self { bump: Bump::new() } - } - - /// Create a new [`Allocator`] with specified capacity. - /// - /// See [`Allocator`] docs for more information on efficient use of [`Allocator`]. - // - // `#[inline(always)]` because just delegates to `bumpalo` method - #[expect(clippy::inline_always)] - #[inline(always)] - pub fn with_capacity(capacity: usize) -> Self { - Self { bump: Bump::with_capacity(capacity) } - } - - /// Allocate an object in this [`Allocator`] and return an exclusive reference to it. - /// - /// # Panics - /// Panics if reserving space for `T` fails. - /// - /// # Examples - /// ``` - /// use oxc_allocator::Allocator; - /// - /// let allocator = Allocator::default(); - /// let x = allocator.alloc([1u8; 20]); - /// assert_eq!(x, &[1u8; 20]); - /// ``` - // - // `#[inline(always)]` because this is a very hot path and `Bump::alloc` is a very small function. - // We always want it to be inlined. - #[expect(clippy::inline_always)] - #[inline(always)] - pub fn alloc(&self, val: T) -> &mut T { - const { - assert!(!needs_drop::(), "Cannot allocate Drop type in arena"); - } - - self.bump.alloc(val) - } - - /// Copy a string slice into this [`Allocator`] and return a reference to it. - /// - /// # Panics - /// Panics if reserving space for the string fails. - /// - /// # Examples - /// ``` - /// use oxc_allocator::Allocator; - /// let allocator = Allocator::default(); - /// let hello = allocator.alloc_str("hello world"); - /// assert_eq!(hello, "hello world"); - /// ``` - // - // `#[inline(always)]` because this is a hot path and `Bump::alloc_str` is a very small function. - // We always want it to be inlined. - #[expect(clippy::inline_always)] - #[inline(always)] - pub fn alloc_str<'alloc>(&'alloc self, src: &str) -> &'alloc mut str { - self.bump.alloc_str(src) - } - - /// Reset this allocator. - /// - /// Performs mass deallocation on everything allocated in this arena by resetting the pointer - /// into the underlying chunk of memory to the start of the chunk. - /// Does not run any `Drop` implementations on deallocated objects. - /// - /// If this arena has allocated multiple chunks to bump allocate into, then the excess chunks - /// are returned to the global allocator. - /// - /// # Examples - /// ``` - /// use oxc_allocator::Allocator; - /// - /// let mut allocator = Allocator::default(); - /// - /// // Allocate a bunch of things. - /// { - /// for i in 0..100 { - /// allocator.alloc(i); - /// } - /// } - /// - /// // Reset the arena. - /// allocator.reset(); - /// - /// // Allocate some new things in the space previously occupied by the - /// // original things. - /// for j in 200..400 { - /// allocator.alloc(j); - /// } - /// ``` - // - // `#[inline(always)]` because it just delegates to `bumpalo` - #[expect(clippy::inline_always)] - #[inline(always)] - pub fn reset(&mut self) { - self.bump.reset(); - } - - /// Calculate the total capacity of this [`Allocator`] including all chunks, in bytes. - /// - /// Note: This is the total amount of memory the [`Allocator`] owns NOT the total size of data - /// that's been allocated in it. If you want the latter, use [`used_bytes`] instead. - /// - /// # Examples - /// ``` - /// use oxc_allocator::Allocator; - /// - /// let capacity = 64 * 1024; // 64 KiB - /// let mut allocator = Allocator::with_capacity(capacity); - /// allocator.alloc(123u64); // 8 bytes - /// - /// // Result is the capacity (64 KiB), not the size of allocated data (8 bytes). - /// // `Allocator::with_capacity` may allocate a bit more than requested. - /// assert!(allocator.capacity() >= capacity); - /// ``` - /// - /// [`used_bytes`]: Allocator::used_bytes - // - // `#[inline(always)]` because it just delegates to `bumpalo` - #[expect(clippy::inline_always)] - #[inline(always)] - pub fn capacity(&self) -> usize { - self.bump.allocated_bytes() - } - - /// Calculate the total size of data used in this [`Allocator`], in bytes. - /// - /// This is the total amount of memory that has been *used* in the [`Allocator`], NOT the amount of - /// memory the [`Allocator`] owns. If you want the latter, use [`capacity`] instead. - /// - /// The result includes: - /// - /// 1. Padding bytes between objects which have been allocated to preserve alignment of types - /// where they have different alignments or have larger-than-typical alignment. - /// 2. Excess capacity in [`Vec`]s, [`String`]s and [`HashMap`]s. - /// 3. Objects which were allocated but later dropped. [`Allocator`] does not re-use allocations, - /// so anything which is allocated into arena continues to take up "dead space", even after it's - /// no longer referenced anywhere. - /// 4. "Dead space" left over where a [`Vec`], [`String`] or [`HashMap`] has grown and had to make - /// a new allocation to accommodate its new larger size. Its old allocation continues to take up - /// "dead" space in the allocator, unless it was the most recent allocation. - /// - /// In practice, this almost always means that the result returned from this function will be an - /// over-estimate vs the amount of "live" data in the arena. - /// - /// However, if you are using the result of this method to create a new `Allocator` to clone - /// an AST into, it is theoretically possible (though very unlikely) that it may be a slight - /// under-estimate of the capacity required in new allocator to clone the AST into, depending - /// on the order that `&str`s were allocated into arena in parser vs the order they get allocated - /// during cloning. The order allocations are made in affects the amount of padding bytes required. - /// - /// # Examples - /// ``` - /// use oxc_allocator::{Allocator, Vec}; - /// - /// let capacity = 64 * 1024; // 64 KiB - /// let mut allocator = Allocator::with_capacity(capacity); - /// - /// allocator.alloc(1u8); // 1 byte with alignment 1 - /// allocator.alloc(2u8); // 1 byte with alignment 1 - /// allocator.alloc(3u64); // 8 bytes with alignment 8 - /// - /// // Only 10 bytes were allocated, but 16 bytes were used, in order to align `3u64` on 8 - /// assert_eq!(allocator.used_bytes(), 16); - /// - /// allocator.reset(); - /// - /// let mut vec = Vec::::with_capacity_in(2, &allocator); - /// - /// // Allocate something else, so `vec`'s allocation is not the most recent - /// allocator.alloc(123u64); - /// - /// // `vec` has to grow beyond it's initial capacity - /// vec.extend([1, 2, 3, 4]); - /// - /// // `vec` takes up 32 bytes, and `123u64` takes up 8 bytes = 40 total. - /// // But there's an additional 16 bytes consumed for `vec`'s original capacity of 2, - /// // which is still using up space - /// assert_eq!(allocator.used_bytes(), 56); - /// ``` - /// - /// [`capacity`]: Allocator::capacity - pub fn used_bytes(&self) -> usize { - let mut bytes = 0; - // SAFETY: No allocations are made while `chunks_iter` is alive. No data is read from the chunks. - let chunks_iter = unsafe { self.bump.iter_allocated_chunks_raw() }; - for (_, size) in chunks_iter { - bytes += size; - } - bytes - } - - /// Get inner [`bumpalo::Bump`]. - /// - /// This method is not public. We don't want to expose `bumpalo::Allocator` to user. - /// The fact that we're using `bumpalo` is an internal implementation detail. - // - // `#[inline(always)]` because it's a no-op - #[expect(clippy::inline_always)] - #[inline(always)] - pub(crate) fn bump(&self) -> &Bump { - &self.bump - } -} - -/// 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. -unsafe impl Sync for Allocator {} - -#[cfg(test)] -mod test { - use crate::Allocator; - - #[test] - fn test_api() { - let mut allocator = Allocator::default(); - { - let array = allocator.alloc([123; 10]); - assert_eq!(array, &[123; 10]); - let str = allocator.alloc_str("hello"); - assert_eq!(str, "hello"); - } - allocator.reset(); - } -} -======= - -/// A bump-allocated memory arena. -/// -/// # Anatomy of an Allocator -/// -/// [`Allocator`] is flexibly sized. It grows as required as you allocate data into it. -/// -/// To do that, an [`Allocator`] consists of multiple memory chunks. -/// -/// [`Allocator::new`] creates a new allocator without any chunks. When you first allocate an object -/// into it, it will lazily create an initial chunk, the size of which is determined by the size of that -/// first allocation. -/// -/// As more data is allocated into the [`Allocator`], it will likely run out of capacity. At that point, -/// a new memory chunk is added, and further allocations will use this new chunk (until it too runs out -/// of capacity, and *another* chunk is added). -/// -/// The data from the 1st chunk is not copied into the 2nd one. It stays where it is, which means -/// `&` or `&mut` references to data in the first chunk remain valid. This is unlike e.g. `Vec` which -/// copies all existing data when it grows. -/// -/// Each chunk is at least double the size of the last one, so growth in capacity is exponential. -/// -/// [`Allocator::reset`] keeps only the last chunk (the biggest one), and discards any other chunks, -/// returning their memory to the global allocator. The last chunk has its cursor rewound back to -/// the start, so it's empty, ready to be re-used for allocating more data. -/// -/// # Recycling allocators -/// -/// For good performance, it's ideal to create an [`Allocator`], and re-use it over and over, rather than -/// repeatedly creating and dropping [`Allocator`]s. -/// -/// ``` -/// // This is good! -/// use oxc_allocator::Allocator; -/// let mut allocator = Allocator::new(); -/// -/// # fn do_stuff(_n: usize, _allocator: &Allocator) {} -/// for i in 0..100 { -/// do_stuff(i, &allocator); -/// // Reset the allocator, freeing the memory used by `do_stuff` -/// allocator.reset(); -/// } -/// ``` -/// -/// ``` -/// // DON'T DO THIS! -/// # use oxc_allocator::Allocator; -/// # fn do_stuff(_n: usize, _allocator: &Allocator) {} -/// for i in 0..100 { -/// let allocator = Allocator::new(); -/// do_stuff(i, &allocator); -/// } -/// ``` -/// -/// ``` -/// // DON'T DO THIS EITHER! -/// # use oxc_allocator::Allocator; -/// # let allocator = Allocator::new(); -/// # fn do_stuff(_n: usize, _allocator: &Allocator) {} -/// for i in 0..100 { -/// do_stuff(i, &allocator); -/// // We haven't reset the allocator, so we haven't freed the memory used by `do_stuff`. -/// // The allocator will grow and grow, consuming more and more memory. -/// } -/// ``` -/// -/// ## Why is re-using an [`Allocator`] good for performance? -/// -/// 3 reasons: -/// -/// #### 1. Avoid expensive system calls -/// -/// Creating an [`Allocator`] is a fairly expensive operation as it involves a call into global allocator, -/// which in turn will likely make a system call. Ditto when the [`Allocator`] is dropped. -/// Re-using an existing [`Allocator`] avoids these costs. -/// -/// #### 2. CPU cache -/// -/// Re-using an existing allocator means you're re-using the same block of memory. If that memory was -/// recently accessed, it's likely to be warm in the CPU cache, so memory accesses will be much faster -/// than accessing "cold" sections of main memory. -/// -/// This can have a very significant positive impact on performance. -/// -/// #### 3. Capacity stabilization -/// -/// The most efficient [`Allocator`] is one with only 1 chunk which has sufficient capacity for -/// everything you're going to allocate into it. -/// -/// Why? -/// -/// 1. Every allocation will occur without the allocator needing to grow. -/// -/// 2. This makes the "is there sufficient capacity to allocate this?" check in [`alloc`] completely -/// predictable (the answer is always "yes"). The CPU's branch predictor swiftly learns this, -/// speeding up operation. -/// -/// 3. When the [`Allocator`] is reset, there are no excess chunks to discard, so no system calls. -/// -/// Because [`reset`] keeps only the biggest chunk (see above), re-using the same [`Allocator`] -/// for multiple similar workloads will result in the [`Allocator`] swiftly stabilizing at a capacity -/// which is sufficient to service those workloads with a single chunk. -/// -/// If workload is completely uniform, it reaches stable state on the 3rd round. -/// -/// ``` -/// # use oxc_allocator::Allocator; -/// let mut allocator = Allocator::new(); -/// -/// fn workload(allocator: &Allocator) { -/// // Allocate 4 MB of data in small chunks -/// for i in 0..1_000_000u32 { -/// allocator.alloc(i); -/// } -/// } -/// -/// // 1st round -/// workload(&allocator); -/// -/// // `allocator` has capacity for 4 MB data, but split into many chunks. -/// // `reset` throws away all chunks except the last one which will be approx 2 MB. -/// allocator.reset(); -/// -/// // 2nd round -/// workload(&allocator); -/// -/// // `workload` filled the 2 MB chunk, so a 2nd chunk was created of double the size (4 MB). -/// // `reset` discards the smaller chunk, leaving only a single 4 MB chunk. -/// allocator.reset(); -/// -/// // 3rd round -/// // `allocator` now has sufficient capacity for all allocations in a single 4 MB chunk. -/// workload(&allocator); -/// -/// // `reset` has no chunks to discard. It keeps the single 4 MB chunk. No system calls. -/// allocator.reset(); -/// -/// // More rounds -/// // All serviced without needing to grow the allocator, and with no system calls. -/// for _ in 0..100 { -/// workload(&allocator); -/// allocator.reset(); -/// } -/// ``` -/// -/// [`reset`]: Allocator::reset -/// [`alloc`]: Allocator::alloc -/// -/// # No `Drop`s -/// -/// Objects allocated into Oxc memory arenas are never [`Dropped`](Drop). -/// Memory is released in bulk when the allocator is dropped, without dropping the individual -/// objects in the arena. -/// -/// Therefore, it would produce a memory leak if you allocated [`Drop`] types into the arena -/// which own memory allocations outside the arena. -/// -/// Static checks make this impossible to do. [`Allocator::alloc`], [`Box::new_in`], [`Vec::new_in`], -/// [`HashMap::new_in`], and all other methods which store data in the arena will refuse to compile -/// if called with a [`Drop`] type. -/// -/// ```ignore -/// use oxc_allocator::{Allocator, Box}; -/// -/// let allocator = Allocator::new(); -/// -/// struct Foo { -/// pub a: i32 -/// } -/// -/// impl std::ops::Drop for Foo { -/// fn drop(&mut self) {} -/// } -/// -/// // This will fail to compile because `Foo` implements `Drop` -/// let foo = Box::new_in(Foo { a: 0 }, &allocator); -/// -/// struct Bar { -/// v: std::vec::Vec, -/// } -/// -/// // This will fail to compile because `Bar` contains a `std::vec::Vec`, and it implements `Drop` -/// let bar = Box::new_in(Bar { v: vec![1, 2, 3] }, &allocator); -/// ``` -/// -/// # Examples -/// -/// Consumers of the [`oxc` umbrella crate](https://crates.io/crates/oxc) pass -/// [`Allocator`] references to other tools. -/// -/// ```ignore -/// use oxc::{allocator::Allocator, parser::Parser, span::SourceType}; -/// -/// let allocator = Allocator::default(); -/// let parsed = Parser::new(&allocator, "let x = 1;", SourceType::default()); -/// assert!(parsed.errors.is_empty()); -/// ``` -#[derive(Default)] -pub struct Allocator { - bump: Bump, -} - -impl Allocator { - /// Create a new [`Allocator`] with no initial capacity. - /// - /// This method does not reserve any memory to back the allocator. Memory for allocator's initial - /// chunk will be reserved lazily, when you make the first allocation into this [`Allocator`] - /// (e.g. with [`Allocator::alloc`], [`Box::new_in`], [`Vec::new_in`], [`HashMap::new_in`]). - /// - /// If you can estimate the amount of memory the allocator will require to fit what you intend to - /// allocate into it, it is generally preferable to create that allocator with [`with_capacity`], - /// which reserves that amount of memory upfront. This will avoid further system calls to allocate - /// further chunks later on. This point is less important if you're re-using the allocator multiple - /// times. - /// - /// See [`Allocator`] docs for more information on efficient use of [`Allocator`]. - /// - /// [`with_capacity`]: Allocator::with_capacity - // - // `#[inline(always)]` because just delegates to `bumpalo` method - #[expect(clippy::inline_always)] - #[inline(always)] - pub fn new() -> Self { - Self { bump: Bump::new() } - } - - /// Create a new [`Allocator`] with specified capacity. - /// - /// See [`Allocator`] docs for more information on efficient use of [`Allocator`]. - // - // `#[inline(always)]` because just delegates to `bumpalo` method - #[expect(clippy::inline_always)] - #[inline(always)] - pub fn with_capacity(capacity: usize) -> Self { - Self { bump: Bump::with_capacity(capacity) } - } - - /// Allocate an object in this [`Allocator`] and return an exclusive reference to it. - /// - /// # Panics - /// Panics if reserving space for `T` fails. - /// - /// # Examples - /// ``` - /// use oxc_allocator::Allocator; - /// - /// let allocator = Allocator::default(); - /// let x = allocator.alloc([1u8; 20]); - /// assert_eq!(x, &[1u8; 20]); - /// ``` - // - // `#[inline(always)]` because this is a very hot path and `Bump::alloc` is a very small function. - // We always want it to be inlined. - #[expect(clippy::inline_always)] - #[inline(always)] - pub fn alloc(&self, val: T) -> &mut T { - const { - assert!(!needs_drop::(), "Cannot allocate Drop type in arena"); - } - - self.bump.alloc(val) - } - - /// Copy a string slice into this [`Allocator`] and return a reference to it. - /// - /// # Panics - /// Panics if reserving space for the string fails. - /// - /// # Examples - /// ``` - /// use oxc_allocator::Allocator; - /// let allocator = Allocator::default(); - /// let hello = allocator.alloc_str("hello world"); - /// assert_eq!(hello, "hello world"); - /// ``` - // - // `#[inline(always)]` because this is a hot path and `Bump::alloc_str` is a very small function. - // We always want it to be inlined. - #[expect(clippy::inline_always)] - #[inline(always)] - pub fn alloc_str<'alloc>(&'alloc self, src: &str) -> &'alloc mut str { - self.bump.alloc_str(src) - } - - /// Reset this allocator. - /// - /// Performs mass deallocation on everything allocated in this arena by resetting the pointer - /// into the underlying chunk of memory to the start of the chunk. - /// Does not run any `Drop` implementations on deallocated objects. - /// - /// If this arena has allocated multiple chunks to bump allocate into, then the excess chunks - /// are returned to the global allocator. - /// - /// # Examples - /// ``` - /// use oxc_allocator::Allocator; - /// - /// let mut allocator = Allocator::default(); - /// - /// // Allocate a bunch of things. - /// { - /// for i in 0..100 { - /// allocator.alloc(i); - /// } - /// } - /// - /// // Reset the arena. - /// allocator.reset(); - /// - /// // Allocate some new things in the space previously occupied by the - /// // original things. - /// for j in 200..400 { - /// allocator.alloc(j); - /// } - /// ``` - // - // `#[inline(always)]` because it just delegates to `bumpalo` - #[expect(clippy::inline_always)] - #[inline(always)] - pub fn reset(&mut self) { - self.bump.reset(); - } - - /// Calculate the total capacity of this [`Allocator`] including all chunks, in bytes. - /// - /// Note: This is the total amount of memory the [`Allocator`] owns NOT the total size of data - /// that's been allocated in it. If you want the latter, use [`used_bytes`] instead. - /// - /// # Examples - /// ``` - /// use oxc_allocator::Allocator; - /// - /// let capacity = 64 * 1024; // 64 KiB - /// let mut allocator = Allocator::with_capacity(capacity); - /// allocator.alloc(123u64); // 8 bytes - /// - /// // Result is the capacity (64 KiB), not the size of allocated data (8 bytes). - /// // `Allocator::with_capacity` may allocate a bit more than requested. - /// assert!(allocator.capacity() >= capacity); - /// ``` - /// - /// [`used_bytes`]: Allocator::used_bytes - // - // `#[inline(always)]` because it just delegates to `bumpalo` - #[expect(clippy::inline_always)] - #[inline(always)] - pub fn capacity(&self) -> usize { - self.bump.allocated_bytes() - } - - /// Calculate the total size of data used in this [`Allocator`], in bytes. - /// - /// This is the total amount of memory that has been *used* in the [`Allocator`], NOT the amount of - /// memory the [`Allocator`] owns. If you want the latter, use [`capacity`] instead. - /// - /// The result includes: - /// - /// 1. Padding bytes between objects which have been allocated to preserve alignment of types - /// where they have different alignments or have larger-than-typical alignment. - /// 2. Excess capacity in [`Vec`]s, [`String`]s and [`HashMap`]s. - /// 3. Objects which were allocated but later dropped. [`Allocator`] does not re-use allocations, - /// so anything which is allocated into arena continues to take up "dead space", even after it's - /// no longer referenced anywhere. - /// 4. "Dead space" left over where a [`Vec`], [`String`] or [`HashMap`] has grown and had to make - /// a new allocation to accommodate its new larger size. Its old allocation continues to take up - /// "dead" space in the allocator, unless it was the most recent allocation. - /// - /// In practice, this almost always means that the result returned from this function will be an - /// over-estimate vs the amount of "live" data in the arena. - /// - /// However, if you are using the result of this method to create a new `Allocator` to clone - /// an AST into, it is theoretically possible (though very unlikely) that it may be a slight - /// under-estimate of the capacity required in new allocator to clone the AST into, depending - /// on the order that `&str`s were allocated into arena in parser vs the order they get allocated - /// during cloning. The order allocations are made in affects the amount of padding bytes required. - /// - /// # Examples - /// ``` - /// use oxc_allocator::{Allocator, Vec}; - /// - /// let capacity = 64 * 1024; // 64 KiB - /// let mut allocator = Allocator::with_capacity(capacity); - /// - /// allocator.alloc(1u8); // 1 byte with alignment 1 - /// allocator.alloc(2u8); // 1 byte with alignment 1 - /// allocator.alloc(3u64); // 8 bytes with alignment 8 - /// - /// // Only 10 bytes were allocated, but 16 bytes were used, in order to align `3u64` on 8 - /// assert_eq!(allocator.used_bytes(), 16); - /// - /// allocator.reset(); - /// - /// let mut vec = Vec::::with_capacity_in(2, &allocator); - /// - /// // Allocate something else, so `vec`'s allocation is not the most recent - /// allocator.alloc(123u64); - /// - /// // `vec` has to grow beyond it's initial capacity - /// vec.extend([1, 2, 3, 4]); - /// - /// // `vec` takes up 32 bytes, and `123u64` takes up 8 bytes = 40 total. - /// // But there's an additional 16 bytes consumed for `vec`'s original capacity of 2, - /// // which is still using up space - /// assert_eq!(allocator.used_bytes(), 56); - /// ``` - /// - /// [`capacity`]: Allocator::capacity - pub fn used_bytes(&self) -> usize { - let mut bytes = 0; - // SAFETY: No allocations are made while `chunks_iter` is alive. No data is read from the chunks. - let chunks_iter = unsafe { self.bump.iter_allocated_chunks_raw() }; - for (_, size) in chunks_iter { - bytes += size; - } - bytes - } - - /// Get inner [`bumpalo::Bump`]. - /// - /// This method is not public. We don't want to expose `bumpalo::Allocator` to user. - /// The fact that we're using `bumpalo` is an internal implementation detail. - // - // `#[inline(always)]` because it's a no-op - #[expect(clippy::inline_always)] - #[inline(always)] - pub(crate) fn bump(&self) -> &Bump { - &self.bump - } -} - -/// 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. -unsafe impl Sync for Allocator {} - -#[cfg(test)] -mod test { - use crate::Allocator; - - #[test] - fn test_api() { - let mut allocator = Allocator::default(); - { - let array = allocator.alloc([123; 10]); - assert_eq!(array, &[123; 10]); - let str = allocator.alloc_str("hello"); - assert_eq!(str, "hello"); - } - allocator.reset(); - } -} ->>>>>>> 692c44faf (feat: 🎸 make data in arena cloneable) diff --git a/crates/oxc_ast/src/generated/derive_clone_in.rs b/crates/oxc_ast/src/generated/derive_clone_in.rs index 56acb47bf61e8b..1dfe6eef66df53 100644 --- a/crates/oxc_ast/src/generated/derive_clone_in.rs +++ b/crates/oxc_ast/src/generated/derive_clone_in.rs @@ -96,6 +96,18 @@ impl<'new_alloc> CloneIn<'new_alloc> for RegExpPattern<'_> { Self::Pattern(it) => RegExpPattern::Pattern(CloneIn::clone_in(it, allocator)), } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::Raw(it) => RegExpPattern::Raw(CloneIn::clone_in_with_semantic_ids(it, allocator)), + Self::Invalid(it) => { + RegExpPattern::Invalid(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Pattern(it) => { + RegExpPattern::Pattern(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for Program<'_> { @@ -239,6 +251,137 @@ impl<'new_alloc> CloneIn<'new_alloc> for Expression<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::BooleanLiteral(it) => { + Expression::BooleanLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NullLiteral(it) => { + Expression::NullLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NumericLiteral(it) => { + Expression::NumericLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BigIntLiteral(it) => { + Expression::BigIntLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::RegExpLiteral(it) => { + Expression::RegExpLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::StringLiteral(it) => { + Expression::StringLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TemplateLiteral(it) => { + Expression::TemplateLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Identifier(it) => { + Expression::Identifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::MetaProperty(it) => { + Expression::MetaProperty(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Super(it) => { + Expression::Super(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ArrayExpression(it) => { + Expression::ArrayExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ArrowFunctionExpression(it) => Expression::ArrowFunctionExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::AssignmentExpression(it) => { + Expression::AssignmentExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::AwaitExpression(it) => { + Expression::AwaitExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BinaryExpression(it) => { + Expression::BinaryExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::CallExpression(it) => { + Expression::CallExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ChainExpression(it) => { + Expression::ChainExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ClassExpression(it) => { + Expression::ClassExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ConditionalExpression(it) => Expression::ConditionalExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::FunctionExpression(it) => { + Expression::FunctionExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ImportExpression(it) => { + Expression::ImportExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::LogicalExpression(it) => { + Expression::LogicalExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NewExpression(it) => { + Expression::NewExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ObjectExpression(it) => { + Expression::ObjectExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ParenthesizedExpression(it) => Expression::ParenthesizedExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::SequenceExpression(it) => { + Expression::SequenceExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TaggedTemplateExpression(it) => Expression::TaggedTemplateExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ThisExpression(it) => { + Expression::ThisExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::UnaryExpression(it) => { + Expression::UnaryExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::UpdateExpression(it) => { + Expression::UpdateExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::YieldExpression(it) => { + Expression::YieldExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::PrivateInExpression(it) => { + Expression::PrivateInExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::JSXElement(it) => { + Expression::JSXElement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::JSXFragment(it) => { + Expression::JSXFragment(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSAsExpression(it) => { + Expression::TSAsExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSSatisfiesExpression(it) => Expression::TSSatisfiesExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSTypeAssertion(it) => { + Expression::TSTypeAssertion(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSNonNullExpression(it) => { + Expression::TSNonNullExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSInstantiationExpression(it) => Expression::TSInstantiationExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ComputedMemberExpression(it) => Expression::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StaticMemberExpression(it) => Expression::StaticMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateFieldExpression(it) => Expression::PrivateFieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for IdentifierName<'_> { @@ -451,6 +594,145 @@ impl<'new_alloc> CloneIn<'new_alloc> for ArrayExpressionElement<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::SpreadElement(it) => ArrayExpressionElement::SpreadElement( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::Elision(it) => { + ArrayExpressionElement::Elision(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BooleanLiteral(it) => ArrayExpressionElement::BooleanLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::NullLiteral(it) => ArrayExpressionElement::NullLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::NumericLiteral(it) => ArrayExpressionElement::NumericLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::BigIntLiteral(it) => ArrayExpressionElement::BigIntLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::RegExpLiteral(it) => ArrayExpressionElement::RegExpLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StringLiteral(it) => ArrayExpressionElement::StringLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TemplateLiteral(it) => ArrayExpressionElement::TemplateLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::Identifier(it) => ArrayExpressionElement::Identifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::MetaProperty(it) => ArrayExpressionElement::MetaProperty( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::Super(it) => { + ArrayExpressionElement::Super(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ArrayExpression(it) => ArrayExpressionElement::ArrayExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ArrowFunctionExpression(it) => ArrayExpressionElement::ArrowFunctionExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::AssignmentExpression(it) => ArrayExpressionElement::AssignmentExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::AwaitExpression(it) => ArrayExpressionElement::AwaitExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::BinaryExpression(it) => ArrayExpressionElement::BinaryExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::CallExpression(it) => ArrayExpressionElement::CallExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ChainExpression(it) => ArrayExpressionElement::ChainExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ClassExpression(it) => ArrayExpressionElement::ClassExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ConditionalExpression(it) => ArrayExpressionElement::ConditionalExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::FunctionExpression(it) => ArrayExpressionElement::FunctionExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ImportExpression(it) => ArrayExpressionElement::ImportExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::LogicalExpression(it) => ArrayExpressionElement::LogicalExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::NewExpression(it) => ArrayExpressionElement::NewExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ObjectExpression(it) => ArrayExpressionElement::ObjectExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ParenthesizedExpression(it) => ArrayExpressionElement::ParenthesizedExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::SequenceExpression(it) => ArrayExpressionElement::SequenceExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TaggedTemplateExpression(it) => ArrayExpressionElement::TaggedTemplateExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ThisExpression(it) => ArrayExpressionElement::ThisExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::UnaryExpression(it) => ArrayExpressionElement::UnaryExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::UpdateExpression(it) => ArrayExpressionElement::UpdateExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::YieldExpression(it) => ArrayExpressionElement::YieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateInExpression(it) => ArrayExpressionElement::PrivateInExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::JSXElement(it) => ArrayExpressionElement::JSXElement( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::JSXFragment(it) => ArrayExpressionElement::JSXFragment( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSAsExpression(it) => ArrayExpressionElement::TSAsExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSSatisfiesExpression(it) => ArrayExpressionElement::TSSatisfiesExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSTypeAssertion(it) => ArrayExpressionElement::TSTypeAssertion( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSNonNullExpression(it) => ArrayExpressionElement::TSNonNullExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSInstantiationExpression(it) => { + ArrayExpressionElement::TSInstantiationExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::ComputedMemberExpression(it) => ArrayExpressionElement::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StaticMemberExpression(it) => ArrayExpressionElement::StaticMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateFieldExpression(it) => ArrayExpressionElement::PrivateFieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'alloc> CloneIn<'alloc> for Elision { @@ -483,6 +765,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for ObjectPropertyKind<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::ObjectProperty(it) => ObjectPropertyKind::ObjectProperty( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::SpreadProperty(it) => ObjectPropertyKind::SpreadProperty( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for ObjectProperty<'_> { @@ -618,6 +911,143 @@ impl<'new_alloc> CloneIn<'new_alloc> for PropertyKey<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::StaticIdentifier(it) => { + PropertyKey::StaticIdentifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::PrivateIdentifier(it) => { + PropertyKey::PrivateIdentifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BooleanLiteral(it) => { + PropertyKey::BooleanLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NullLiteral(it) => { + PropertyKey::NullLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NumericLiteral(it) => { + PropertyKey::NumericLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BigIntLiteral(it) => { + PropertyKey::BigIntLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::RegExpLiteral(it) => { + PropertyKey::RegExpLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::StringLiteral(it) => { + PropertyKey::StringLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TemplateLiteral(it) => { + PropertyKey::TemplateLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Identifier(it) => { + PropertyKey::Identifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::MetaProperty(it) => { + PropertyKey::MetaProperty(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Super(it) => { + PropertyKey::Super(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ArrayExpression(it) => { + PropertyKey::ArrayExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ArrowFunctionExpression(it) => PropertyKey::ArrowFunctionExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::AssignmentExpression(it) => PropertyKey::AssignmentExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::AwaitExpression(it) => { + PropertyKey::AwaitExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BinaryExpression(it) => { + PropertyKey::BinaryExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::CallExpression(it) => { + PropertyKey::CallExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ChainExpression(it) => { + PropertyKey::ChainExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ClassExpression(it) => { + PropertyKey::ClassExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ConditionalExpression(it) => PropertyKey::ConditionalExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::FunctionExpression(it) => { + PropertyKey::FunctionExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ImportExpression(it) => { + PropertyKey::ImportExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::LogicalExpression(it) => { + PropertyKey::LogicalExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NewExpression(it) => { + PropertyKey::NewExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ObjectExpression(it) => { + PropertyKey::ObjectExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ParenthesizedExpression(it) => PropertyKey::ParenthesizedExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::SequenceExpression(it) => { + PropertyKey::SequenceExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TaggedTemplateExpression(it) => PropertyKey::TaggedTemplateExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ThisExpression(it) => { + PropertyKey::ThisExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::UnaryExpression(it) => { + PropertyKey::UnaryExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::UpdateExpression(it) => { + PropertyKey::UpdateExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::YieldExpression(it) => { + PropertyKey::YieldExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::PrivateInExpression(it) => { + PropertyKey::PrivateInExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::JSXElement(it) => { + PropertyKey::JSXElement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::JSXFragment(it) => { + PropertyKey::JSXFragment(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSAsExpression(it) => { + PropertyKey::TSAsExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSSatisfiesExpression(it) => PropertyKey::TSSatisfiesExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSTypeAssertion(it) => { + PropertyKey::TSTypeAssertion(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSNonNullExpression(it) => { + PropertyKey::TSNonNullExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSInstantiationExpression(it) => PropertyKey::TSInstantiationExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ComputedMemberExpression(it) => PropertyKey::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StaticMemberExpression(it) => PropertyKey::StaticMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateFieldExpression(it) => PropertyKey::PrivateFieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'alloc> CloneIn<'alloc> for PropertyKind { @@ -690,6 +1120,20 @@ impl<'new_alloc> CloneIn<'new_alloc> for MemberExpression<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::ComputedMemberExpression(it) => MemberExpression::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StaticMemberExpression(it) => MemberExpression::StaticMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateFieldExpression(it) => MemberExpression::PrivateFieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for ComputedMemberExpression<'_> { @@ -877,27 +1321,159 @@ impl<'new_alloc> CloneIn<'new_alloc> for Argument<'_> { } } } -} - -impl<'new_alloc> CloneIn<'new_alloc> for UpdateExpression<'_> { - type Cloned = UpdateExpression<'new_alloc>; - fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { - UpdateExpression { - span: CloneIn::clone_in(&self.span, allocator), - operator: CloneIn::clone_in(&self.operator, allocator), - prefix: CloneIn::clone_in(&self.prefix, allocator), - argument: CloneIn::clone_in(&self.argument, allocator), - } - } -} -impl<'new_alloc> CloneIn<'new_alloc> for UnaryExpression<'_> { - type Cloned = UnaryExpression<'new_alloc>; - fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { - UnaryExpression { - span: CloneIn::clone_in(&self.span, allocator), - operator: CloneIn::clone_in(&self.operator, allocator), - argument: CloneIn::clone_in(&self.argument, allocator), + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::SpreadElement(it) => { + Argument::SpreadElement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BooleanLiteral(it) => { + Argument::BooleanLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NullLiteral(it) => { + Argument::NullLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NumericLiteral(it) => { + Argument::NumericLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BigIntLiteral(it) => { + Argument::BigIntLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::RegExpLiteral(it) => { + Argument::RegExpLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::StringLiteral(it) => { + Argument::StringLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TemplateLiteral(it) => { + Argument::TemplateLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Identifier(it) => { + Argument::Identifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::MetaProperty(it) => { + Argument::MetaProperty(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Super(it) => Argument::Super(CloneIn::clone_in_with_semantic_ids(it, allocator)), + Self::ArrayExpression(it) => { + Argument::ArrayExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ArrowFunctionExpression(it) => Argument::ArrowFunctionExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::AssignmentExpression(it) => { + Argument::AssignmentExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::AwaitExpression(it) => { + Argument::AwaitExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BinaryExpression(it) => { + Argument::BinaryExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::CallExpression(it) => { + Argument::CallExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ChainExpression(it) => { + Argument::ChainExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ClassExpression(it) => { + Argument::ClassExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ConditionalExpression(it) => { + Argument::ConditionalExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::FunctionExpression(it) => { + Argument::FunctionExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ImportExpression(it) => { + Argument::ImportExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::LogicalExpression(it) => { + Argument::LogicalExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NewExpression(it) => { + Argument::NewExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ObjectExpression(it) => { + Argument::ObjectExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ParenthesizedExpression(it) => Argument::ParenthesizedExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::SequenceExpression(it) => { + Argument::SequenceExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TaggedTemplateExpression(it) => Argument::TaggedTemplateExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ThisExpression(it) => { + Argument::ThisExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::UnaryExpression(it) => { + Argument::UnaryExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::UpdateExpression(it) => { + Argument::UpdateExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::YieldExpression(it) => { + Argument::YieldExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::PrivateInExpression(it) => { + Argument::PrivateInExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::JSXElement(it) => { + Argument::JSXElement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::JSXFragment(it) => { + Argument::JSXFragment(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSAsExpression(it) => { + Argument::TSAsExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSSatisfiesExpression(it) => { + Argument::TSSatisfiesExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSTypeAssertion(it) => { + Argument::TSTypeAssertion(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSNonNullExpression(it) => { + Argument::TSNonNullExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSInstantiationExpression(it) => Argument::TSInstantiationExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ComputedMemberExpression(it) => Argument::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StaticMemberExpression(it) => { + Argument::StaticMemberExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::PrivateFieldExpression(it) => { + Argument::PrivateFieldExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } +} + +impl<'new_alloc> CloneIn<'new_alloc> for UpdateExpression<'_> { + type Cloned = UpdateExpression<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + UpdateExpression { + span: CloneIn::clone_in(&self.span, allocator), + operator: CloneIn::clone_in(&self.operator, allocator), + prefix: CloneIn::clone_in(&self.prefix, allocator), + argument: CloneIn::clone_in(&self.argument, allocator), + } + } +} + +impl<'new_alloc> CloneIn<'new_alloc> for UnaryExpression<'_> { + type Cloned = UnaryExpression<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + UnaryExpression { + span: CloneIn::clone_in(&self.span, allocator), + operator: CloneIn::clone_in(&self.operator, allocator), + argument: CloneIn::clone_in(&self.argument, allocator), } } } @@ -1001,6 +1577,44 @@ impl<'new_alloc> CloneIn<'new_alloc> for AssignmentTarget<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::AssignmentTargetIdentifier(it) => AssignmentTarget::AssignmentTargetIdentifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSAsExpression(it) => { + AssignmentTarget::TSAsExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSSatisfiesExpression(it) => AssignmentTarget::TSSatisfiesExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSNonNullExpression(it) => AssignmentTarget::TSNonNullExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSTypeAssertion(it) => AssignmentTarget::TSTypeAssertion( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSInstantiationExpression(it) => AssignmentTarget::TSInstantiationExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ComputedMemberExpression(it) => AssignmentTarget::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StaticMemberExpression(it) => AssignmentTarget::StaticMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateFieldExpression(it) => AssignmentTarget::PrivateFieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ArrayAssignmentTarget(it) => AssignmentTarget::ArrayAssignmentTarget( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ObjectAssignmentTarget(it) => AssignmentTarget::ObjectAssignmentTarget( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for SimpleAssignmentTarget<'_> { @@ -1036,6 +1650,42 @@ impl<'new_alloc> CloneIn<'new_alloc> for SimpleAssignmentTarget<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::AssignmentTargetIdentifier(it) => { + SimpleAssignmentTarget::AssignmentTargetIdentifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::TSAsExpression(it) => SimpleAssignmentTarget::TSAsExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSSatisfiesExpression(it) => SimpleAssignmentTarget::TSSatisfiesExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSNonNullExpression(it) => SimpleAssignmentTarget::TSNonNullExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSTypeAssertion(it) => SimpleAssignmentTarget::TSTypeAssertion( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSInstantiationExpression(it) => { + SimpleAssignmentTarget::TSInstantiationExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::ComputedMemberExpression(it) => SimpleAssignmentTarget::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StaticMemberExpression(it) => SimpleAssignmentTarget::StaticMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateFieldExpression(it) => SimpleAssignmentTarget::PrivateFieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for AssignmentTargetPattern<'_> { @@ -1050,6 +1700,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for AssignmentTargetPattern<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::ArrayAssignmentTarget(it) => AssignmentTargetPattern::ArrayAssignmentTarget( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ObjectAssignmentTarget(it) => AssignmentTargetPattern::ObjectAssignmentTarget( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for ArrayAssignmentTarget<'_> { @@ -1141,6 +1802,61 @@ impl<'new_alloc> CloneIn<'new_alloc> for AssignmentTargetMaybeDefault<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::AssignmentTargetWithDefault(it) => { + AssignmentTargetMaybeDefault::AssignmentTargetWithDefault( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::AssignmentTargetIdentifier(it) => { + AssignmentTargetMaybeDefault::AssignmentTargetIdentifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::TSAsExpression(it) => AssignmentTargetMaybeDefault::TSAsExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSSatisfiesExpression(it) => AssignmentTargetMaybeDefault::TSSatisfiesExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSNonNullExpression(it) => AssignmentTargetMaybeDefault::TSNonNullExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSTypeAssertion(it) => AssignmentTargetMaybeDefault::TSTypeAssertion( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSInstantiationExpression(it) => { + AssignmentTargetMaybeDefault::TSInstantiationExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::ComputedMemberExpression(it) => { + AssignmentTargetMaybeDefault::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::StaticMemberExpression(it) => { + AssignmentTargetMaybeDefault::StaticMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::PrivateFieldExpression(it) => { + AssignmentTargetMaybeDefault::PrivateFieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::ArrayAssignmentTarget(it) => AssignmentTargetMaybeDefault::ArrayAssignmentTarget( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ObjectAssignmentTarget(it) => { + AssignmentTargetMaybeDefault::ObjectAssignmentTarget( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for AssignmentTargetWithDefault<'_> { @@ -1170,6 +1886,21 @@ impl<'new_alloc> CloneIn<'new_alloc> for AssignmentTargetProperty<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::AssignmentTargetPropertyIdentifier(it) => { + AssignmentTargetProperty::AssignmentTargetPropertyIdentifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::AssignmentTargetPropertyProperty(it) => { + AssignmentTargetProperty::AssignmentTargetPropertyProperty( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for AssignmentTargetPropertyIdentifier<'_> { @@ -1253,6 +1984,26 @@ impl<'new_alloc> CloneIn<'new_alloc> for ChainElement<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::CallExpression(it) => { + ChainElement::CallExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSNonNullExpression(it) => ChainElement::TSNonNullExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ComputedMemberExpression(it) => ChainElement::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StaticMemberExpression(it) => ChainElement::StaticMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateFieldExpression(it) => ChainElement::PrivateFieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for ParenthesizedExpression<'_> { @@ -1345,6 +2096,107 @@ impl<'new_alloc> CloneIn<'new_alloc> for Statement<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::BlockStatement(it) => { + Statement::BlockStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BreakStatement(it) => { + Statement::BreakStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ContinueStatement(it) => { + Statement::ContinueStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::DebuggerStatement(it) => { + Statement::DebuggerStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::DoWhileStatement(it) => { + Statement::DoWhileStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::EmptyStatement(it) => { + Statement::EmptyStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ExpressionStatement(it) => { + Statement::ExpressionStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ForInStatement(it) => { + Statement::ForInStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ForOfStatement(it) => { + Statement::ForOfStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ForStatement(it) => { + Statement::ForStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::IfStatement(it) => { + Statement::IfStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::LabeledStatement(it) => { + Statement::LabeledStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ReturnStatement(it) => { + Statement::ReturnStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::SwitchStatement(it) => { + Statement::SwitchStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ThrowStatement(it) => { + Statement::ThrowStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TryStatement(it) => { + Statement::TryStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::WhileStatement(it) => { + Statement::WhileStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::WithStatement(it) => { + Statement::WithStatement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::VariableDeclaration(it) => { + Statement::VariableDeclaration(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::FunctionDeclaration(it) => { + Statement::FunctionDeclaration(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ClassDeclaration(it) => { + Statement::ClassDeclaration(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSTypeAliasDeclaration(it) => Statement::TSTypeAliasDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSInterfaceDeclaration(it) => Statement::TSInterfaceDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSEnumDeclaration(it) => { + Statement::TSEnumDeclaration(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSModuleDeclaration(it) => { + Statement::TSModuleDeclaration(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSImportEqualsDeclaration(it) => Statement::TSImportEqualsDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ImportDeclaration(it) => { + Statement::ImportDeclaration(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ExportAllDeclaration(it) => { + Statement::ExportAllDeclaration(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ExportDefaultDeclaration(it) => Statement::ExportDefaultDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ExportNamedDeclaration(it) => Statement::ExportNamedDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSExportAssignment(it) => { + Statement::TSExportAssignment(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSNamespaceExportDeclaration(it) => Statement::TSNamespaceExportDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for Directive<'_> { @@ -1417,21 +2269,50 @@ impl<'new_alloc> CloneIn<'new_alloc> for Declaration<'_> { } } } -} - -impl<'new_alloc> CloneIn<'new_alloc> for VariableDeclaration<'_> { - type Cloned = VariableDeclaration<'new_alloc>; - fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { - VariableDeclaration { - span: CloneIn::clone_in(&self.span, allocator), - kind: CloneIn::clone_in(&self.kind, allocator), - declarations: CloneIn::clone_in(&self.declarations, allocator), - declare: CloneIn::clone_in(&self.declare, allocator), - } - } -} -impl<'alloc> CloneIn<'alloc> for VariableDeclarationKind { + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::VariableDeclaration(it) => { + Declaration::VariableDeclaration(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::FunctionDeclaration(it) => { + Declaration::FunctionDeclaration(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ClassDeclaration(it) => { + Declaration::ClassDeclaration(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSTypeAliasDeclaration(it) => Declaration::TSTypeAliasDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSInterfaceDeclaration(it) => Declaration::TSInterfaceDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSEnumDeclaration(it) => { + Declaration::TSEnumDeclaration(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSModuleDeclaration(it) => { + Declaration::TSModuleDeclaration(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSImportEqualsDeclaration(it) => Declaration::TSImportEqualsDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } +} + +impl<'new_alloc> CloneIn<'new_alloc> for VariableDeclaration<'_> { + type Cloned = VariableDeclaration<'new_alloc>; + fn clone_in(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + VariableDeclaration { + span: CloneIn::clone_in(&self.span, allocator), + kind: CloneIn::clone_in(&self.kind, allocator), + declarations: CloneIn::clone_in(&self.declarations, allocator), + declare: CloneIn::clone_in(&self.declare, allocator), + } + } +} + +impl<'alloc> CloneIn<'alloc> for VariableDeclarationKind { type Cloned = VariableDeclarationKind; fn clone_in(&self, _: &'alloc Allocator) -> Self::Cloned { match self { @@ -1662,6 +2543,140 @@ impl<'new_alloc> CloneIn<'new_alloc> for ForStatementInit<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::VariableDeclaration(it) => ForStatementInit::VariableDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::BooleanLiteral(it) => { + ForStatementInit::BooleanLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NullLiteral(it) => { + ForStatementInit::NullLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NumericLiteral(it) => { + ForStatementInit::NumericLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BigIntLiteral(it) => { + ForStatementInit::BigIntLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::RegExpLiteral(it) => { + ForStatementInit::RegExpLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::StringLiteral(it) => { + ForStatementInit::StringLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TemplateLiteral(it) => ForStatementInit::TemplateLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::Identifier(it) => { + ForStatementInit::Identifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::MetaProperty(it) => { + ForStatementInit::MetaProperty(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Super(it) => { + ForStatementInit::Super(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ArrayExpression(it) => ForStatementInit::ArrayExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ArrowFunctionExpression(it) => ForStatementInit::ArrowFunctionExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::AssignmentExpression(it) => ForStatementInit::AssignmentExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::AwaitExpression(it) => ForStatementInit::AwaitExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::BinaryExpression(it) => ForStatementInit::BinaryExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::CallExpression(it) => { + ForStatementInit::CallExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ChainExpression(it) => ForStatementInit::ChainExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ClassExpression(it) => ForStatementInit::ClassExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ConditionalExpression(it) => ForStatementInit::ConditionalExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::FunctionExpression(it) => ForStatementInit::FunctionExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ImportExpression(it) => ForStatementInit::ImportExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::LogicalExpression(it) => ForStatementInit::LogicalExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::NewExpression(it) => { + ForStatementInit::NewExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ObjectExpression(it) => ForStatementInit::ObjectExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ParenthesizedExpression(it) => ForStatementInit::ParenthesizedExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::SequenceExpression(it) => ForStatementInit::SequenceExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TaggedTemplateExpression(it) => ForStatementInit::TaggedTemplateExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ThisExpression(it) => { + ForStatementInit::ThisExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::UnaryExpression(it) => ForStatementInit::UnaryExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::UpdateExpression(it) => ForStatementInit::UpdateExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::YieldExpression(it) => ForStatementInit::YieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateInExpression(it) => ForStatementInit::PrivateInExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::JSXElement(it) => { + ForStatementInit::JSXElement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::JSXFragment(it) => { + ForStatementInit::JSXFragment(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSAsExpression(it) => { + ForStatementInit::TSAsExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSSatisfiesExpression(it) => ForStatementInit::TSSatisfiesExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSTypeAssertion(it) => ForStatementInit::TSTypeAssertion( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSNonNullExpression(it) => ForStatementInit::TSNonNullExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSInstantiationExpression(it) => ForStatementInit::TSInstantiationExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ComputedMemberExpression(it) => ForStatementInit::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StaticMemberExpression(it) => ForStatementInit::StaticMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateFieldExpression(it) => ForStatementInit::PrivateFieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for ForInStatement<'_> { @@ -1729,6 +2744,47 @@ impl<'new_alloc> CloneIn<'new_alloc> for ForStatementLeft<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::VariableDeclaration(it) => ForStatementLeft::VariableDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::AssignmentTargetIdentifier(it) => ForStatementLeft::AssignmentTargetIdentifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSAsExpression(it) => { + ForStatementLeft::TSAsExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSSatisfiesExpression(it) => ForStatementLeft::TSSatisfiesExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSNonNullExpression(it) => ForStatementLeft::TSNonNullExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSTypeAssertion(it) => ForStatementLeft::TSTypeAssertion( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSInstantiationExpression(it) => ForStatementLeft::TSInstantiationExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ComputedMemberExpression(it) => ForStatementLeft::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StaticMemberExpression(it) => ForStatementLeft::StaticMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateFieldExpression(it) => ForStatementLeft::PrivateFieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ArrayAssignmentTarget(it) => ForStatementLeft::ArrayAssignmentTarget( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ObjectAssignmentTarget(it) => ForStatementLeft::ObjectAssignmentTarget( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for ForOfStatement<'_> { @@ -1929,6 +2985,23 @@ impl<'new_alloc> CloneIn<'new_alloc> for BindingPatternKind<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::BindingIdentifier(it) => BindingPatternKind::BindingIdentifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ObjectPattern(it) => BindingPatternKind::ObjectPattern( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ArrayPattern(it) => { + BindingPatternKind::ArrayPattern(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::AssignmentPattern(it) => BindingPatternKind::AssignmentPattern( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for AssignmentPattern<'_> { @@ -2204,6 +3277,26 @@ impl<'new_alloc> CloneIn<'new_alloc> for ClassElement<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::StaticBlock(it) => { + ClassElement::StaticBlock(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::MethodDefinition(it) => { + ClassElement::MethodDefinition(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::PropertyDefinition(it) => { + ClassElement::PropertyDefinition(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::AccessorProperty(it) => { + ClassElement::AccessorProperty(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSIndexSignature(it) => { + ClassElement::TSIndexSignature(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for MethodDefinition<'_> { @@ -2334,6 +3427,31 @@ impl<'new_alloc> CloneIn<'new_alloc> for ModuleDeclaration<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::ImportDeclaration(it) => ModuleDeclaration::ImportDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ExportAllDeclaration(it) => ModuleDeclaration::ExportAllDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ExportDefaultDeclaration(it) => ModuleDeclaration::ExportDefaultDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ExportNamedDeclaration(it) => ModuleDeclaration::ExportNamedDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSExportAssignment(it) => ModuleDeclaration::TSExportAssignment( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSNamespaceExportDeclaration(it) => { + ModuleDeclaration::TSNamespaceExportDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + } + } } impl<'alloc> CloneIn<'alloc> for AccessorPropertyType { @@ -2417,6 +3535,22 @@ impl<'new_alloc> CloneIn<'new_alloc> for ImportDeclarationSpecifier<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::ImportSpecifier(it) => ImportDeclarationSpecifier::ImportSpecifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ImportDefaultSpecifier(it) => ImportDeclarationSpecifier::ImportDefaultSpecifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ImportNamespaceSpecifier(it) => { + ImportDeclarationSpecifier::ImportNamespaceSpecifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for ImportSpecifier<'_> { @@ -2485,6 +3619,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for ImportAttributeKey<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::Identifier(it) => { + ImportAttributeKey::Identifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::StringLiteral(it) => ImportAttributeKey::StringLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for ExportNamedDeclaration<'_> { @@ -2694,6 +3839,162 @@ impl<'new_alloc> CloneIn<'new_alloc> for ExportDefaultDeclarationKind<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::FunctionDeclaration(it) => ExportDefaultDeclarationKind::FunctionDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ClassDeclaration(it) => ExportDefaultDeclarationKind::ClassDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSInterfaceDeclaration(it) => { + ExportDefaultDeclarationKind::TSInterfaceDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::BooleanLiteral(it) => ExportDefaultDeclarationKind::BooleanLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::NullLiteral(it) => ExportDefaultDeclarationKind::NullLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::NumericLiteral(it) => ExportDefaultDeclarationKind::NumericLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::BigIntLiteral(it) => ExportDefaultDeclarationKind::BigIntLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::RegExpLiteral(it) => ExportDefaultDeclarationKind::RegExpLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StringLiteral(it) => ExportDefaultDeclarationKind::StringLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TemplateLiteral(it) => ExportDefaultDeclarationKind::TemplateLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::Identifier(it) => ExportDefaultDeclarationKind::Identifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::MetaProperty(it) => ExportDefaultDeclarationKind::MetaProperty( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::Super(it) => ExportDefaultDeclarationKind::Super( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ArrayExpression(it) => ExportDefaultDeclarationKind::ArrayExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ArrowFunctionExpression(it) => { + ExportDefaultDeclarationKind::ArrowFunctionExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::AssignmentExpression(it) => ExportDefaultDeclarationKind::AssignmentExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::AwaitExpression(it) => ExportDefaultDeclarationKind::AwaitExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::BinaryExpression(it) => ExportDefaultDeclarationKind::BinaryExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::CallExpression(it) => ExportDefaultDeclarationKind::CallExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ChainExpression(it) => ExportDefaultDeclarationKind::ChainExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ClassExpression(it) => ExportDefaultDeclarationKind::ClassExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ConditionalExpression(it) => ExportDefaultDeclarationKind::ConditionalExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::FunctionExpression(it) => ExportDefaultDeclarationKind::FunctionExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ImportExpression(it) => ExportDefaultDeclarationKind::ImportExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::LogicalExpression(it) => ExportDefaultDeclarationKind::LogicalExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::NewExpression(it) => ExportDefaultDeclarationKind::NewExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ObjectExpression(it) => ExportDefaultDeclarationKind::ObjectExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ParenthesizedExpression(it) => { + ExportDefaultDeclarationKind::ParenthesizedExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::SequenceExpression(it) => ExportDefaultDeclarationKind::SequenceExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TaggedTemplateExpression(it) => { + ExportDefaultDeclarationKind::TaggedTemplateExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::ThisExpression(it) => ExportDefaultDeclarationKind::ThisExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::UnaryExpression(it) => ExportDefaultDeclarationKind::UnaryExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::UpdateExpression(it) => ExportDefaultDeclarationKind::UpdateExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::YieldExpression(it) => ExportDefaultDeclarationKind::YieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateInExpression(it) => ExportDefaultDeclarationKind::PrivateInExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::JSXElement(it) => ExportDefaultDeclarationKind::JSXElement( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::JSXFragment(it) => ExportDefaultDeclarationKind::JSXFragment( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSAsExpression(it) => ExportDefaultDeclarationKind::TSAsExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSSatisfiesExpression(it) => ExportDefaultDeclarationKind::TSSatisfiesExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSTypeAssertion(it) => ExportDefaultDeclarationKind::TSTypeAssertion( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSNonNullExpression(it) => ExportDefaultDeclarationKind::TSNonNullExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSInstantiationExpression(it) => { + ExportDefaultDeclarationKind::TSInstantiationExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::ComputedMemberExpression(it) => { + ExportDefaultDeclarationKind::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::StaticMemberExpression(it) => { + ExportDefaultDeclarationKind::StaticMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + Self::PrivateFieldExpression(it) => { + ExportDefaultDeclarationKind::PrivateFieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for ModuleExportName<'_> { @@ -2711,6 +4012,20 @@ impl<'new_alloc> CloneIn<'new_alloc> for ModuleExportName<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::IdentifierName(it) => { + ModuleExportName::IdentifierName(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::IdentifierReference(it) => ModuleExportName::IdentifierReference( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StringLiteral(it) => { + ModuleExportName::StringLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for TSThisParameter<'_> { @@ -2768,6 +4083,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSEnumMemberName<'_> { Self::String(it) => TSEnumMemberName::String(CloneIn::clone_in(it, allocator)), } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::Identifier(it) => { + TSEnumMemberName::Identifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::String(it) => { + TSEnumMemberName::String(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for TSTypeAnnotation<'_> { @@ -2808,6 +4134,35 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSLiteral<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::BooleanLiteral(it) => { + TSLiteral::BooleanLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NullLiteral(it) => { + TSLiteral::NullLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NumericLiteral(it) => { + TSLiteral::NumericLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BigIntLiteral(it) => { + TSLiteral::BigIntLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::RegExpLiteral(it) => { + TSLiteral::RegExpLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::StringLiteral(it) => { + TSLiteral::StringLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TemplateLiteral(it) => { + TSLiteral::TemplateLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::UnaryExpression(it) => { + TSLiteral::UnaryExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for TSType<'_> { @@ -2884,6 +4239,125 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSType<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::TSAnyKeyword(it) => { + TSType::TSAnyKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSBigIntKeyword(it) => { + TSType::TSBigIntKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSBooleanKeyword(it) => { + TSType::TSBooleanKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSIntrinsicKeyword(it) => { + TSType::TSIntrinsicKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSNeverKeyword(it) => { + TSType::TSNeverKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSNullKeyword(it) => { + TSType::TSNullKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSNumberKeyword(it) => { + TSType::TSNumberKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSObjectKeyword(it) => { + TSType::TSObjectKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSStringKeyword(it) => { + TSType::TSStringKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSSymbolKeyword(it) => { + TSType::TSSymbolKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSUndefinedKeyword(it) => { + TSType::TSUndefinedKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSUnknownKeyword(it) => { + TSType::TSUnknownKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSVoidKeyword(it) => { + TSType::TSVoidKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSArrayType(it) => { + TSType::TSArrayType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSConditionalType(it) => { + TSType::TSConditionalType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSConstructorType(it) => { + TSType::TSConstructorType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSFunctionType(it) => { + TSType::TSFunctionType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSImportType(it) => { + TSType::TSImportType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSIndexedAccessType(it) => { + TSType::TSIndexedAccessType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSInferType(it) => { + TSType::TSInferType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSIntersectionType(it) => { + TSType::TSIntersectionType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSLiteralType(it) => { + TSType::TSLiteralType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSMappedType(it) => { + TSType::TSMappedType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSNamedTupleMember(it) => { + TSType::TSNamedTupleMember(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSQualifiedName(it) => { + TSType::TSQualifiedName(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSTemplateLiteralType(it) => { + TSType::TSTemplateLiteralType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSThisType(it) => { + TSType::TSThisType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSTupleType(it) => { + TSType::TSTupleType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSTypeLiteral(it) => { + TSType::TSTypeLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSTypeOperatorType(it) => { + TSType::TSTypeOperatorType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSTypePredicate(it) => { + TSType::TSTypePredicate(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSTypeQuery(it) => { + TSType::TSTypeQuery(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSTypeReference(it) => { + TSType::TSTypeReference(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSUnionType(it) => { + TSType::TSUnionType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSParenthesizedType(it) => { + TSType::TSParenthesizedType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::JSDocNullableType(it) => { + TSType::JSDocNullableType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::JSDocNonNullableType(it) => { + TSType::JSDocNonNullableType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::JSDocUnknownType(it) => { + TSType::JSDocUnknownType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for TSConditionalType<'_> { @@ -3077,64 +4551,189 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTupleElement<'_> { Self::TSConditionalType(it) => { TSTupleElement::TSConditionalType(CloneIn::clone_in(it, allocator)) } - Self::TSConstructorType(it) => { - TSTupleElement::TSConstructorType(CloneIn::clone_in(it, allocator)) + Self::TSConstructorType(it) => { + TSTupleElement::TSConstructorType(CloneIn::clone_in(it, allocator)) + } + Self::TSFunctionType(it) => { + TSTupleElement::TSFunctionType(CloneIn::clone_in(it, allocator)) + } + Self::TSImportType(it) => { + TSTupleElement::TSImportType(CloneIn::clone_in(it, allocator)) + } + Self::TSIndexedAccessType(it) => { + TSTupleElement::TSIndexedAccessType(CloneIn::clone_in(it, allocator)) + } + Self::TSInferType(it) => TSTupleElement::TSInferType(CloneIn::clone_in(it, allocator)), + Self::TSIntersectionType(it) => { + TSTupleElement::TSIntersectionType(CloneIn::clone_in(it, allocator)) + } + Self::TSLiteralType(it) => { + TSTupleElement::TSLiteralType(CloneIn::clone_in(it, allocator)) + } + Self::TSMappedType(it) => { + TSTupleElement::TSMappedType(CloneIn::clone_in(it, allocator)) + } + Self::TSNamedTupleMember(it) => { + TSTupleElement::TSNamedTupleMember(CloneIn::clone_in(it, allocator)) + } + Self::TSQualifiedName(it) => { + TSTupleElement::TSQualifiedName(CloneIn::clone_in(it, allocator)) + } + Self::TSTemplateLiteralType(it) => { + TSTupleElement::TSTemplateLiteralType(CloneIn::clone_in(it, allocator)) + } + Self::TSThisType(it) => TSTupleElement::TSThisType(CloneIn::clone_in(it, allocator)), + Self::TSTupleType(it) => TSTupleElement::TSTupleType(CloneIn::clone_in(it, allocator)), + Self::TSTypeLiteral(it) => { + TSTupleElement::TSTypeLiteral(CloneIn::clone_in(it, allocator)) + } + Self::TSTypeOperatorType(it) => { + TSTupleElement::TSTypeOperatorType(CloneIn::clone_in(it, allocator)) + } + Self::TSTypePredicate(it) => { + TSTupleElement::TSTypePredicate(CloneIn::clone_in(it, allocator)) + } + Self::TSTypeQuery(it) => TSTupleElement::TSTypeQuery(CloneIn::clone_in(it, allocator)), + Self::TSTypeReference(it) => { + TSTupleElement::TSTypeReference(CloneIn::clone_in(it, allocator)) + } + Self::TSUnionType(it) => TSTupleElement::TSUnionType(CloneIn::clone_in(it, allocator)), + Self::TSParenthesizedType(it) => { + TSTupleElement::TSParenthesizedType(CloneIn::clone_in(it, allocator)) + } + Self::JSDocNullableType(it) => { + TSTupleElement::JSDocNullableType(CloneIn::clone_in(it, allocator)) + } + Self::JSDocNonNullableType(it) => { + TSTupleElement::JSDocNonNullableType(CloneIn::clone_in(it, allocator)) + } + Self::JSDocUnknownType(it) => { + TSTupleElement::JSDocUnknownType(CloneIn::clone_in(it, allocator)) + } + } + } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::TSOptionalType(it) => { + TSTupleElement::TSOptionalType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSRestType(it) => { + TSTupleElement::TSRestType(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSAnyKeyword(it) => { + TSTupleElement::TSAnyKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSBigIntKeyword(it) => { + TSTupleElement::TSBigIntKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSBooleanKeyword(it) => { + TSTupleElement::TSBooleanKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSIntrinsicKeyword(it) => TSTupleElement::TSIntrinsicKeyword( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSNeverKeyword(it) => { + TSTupleElement::TSNeverKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSNullKeyword(it) => { + TSTupleElement::TSNullKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSNumberKeyword(it) => { + TSTupleElement::TSNumberKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSObjectKeyword(it) => { + TSTupleElement::TSObjectKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSStringKeyword(it) => { + TSTupleElement::TSStringKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSSymbolKeyword(it) => { + TSTupleElement::TSSymbolKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSUndefinedKeyword(it) => TSTupleElement::TSUndefinedKeyword( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSUnknownKeyword(it) => { + TSTupleElement::TSUnknownKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSVoidKeyword(it) => { + TSTupleElement::TSVoidKeyword(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSArrayType(it) => { + TSTupleElement::TSArrayType(CloneIn::clone_in_with_semantic_ids(it, allocator)) } + Self::TSConditionalType(it) => TSTupleElement::TSConditionalType( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSConstructorType(it) => TSTupleElement::TSConstructorType( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), Self::TSFunctionType(it) => { - TSTupleElement::TSFunctionType(CloneIn::clone_in(it, allocator)) + TSTupleElement::TSFunctionType(CloneIn::clone_in_with_semantic_ids(it, allocator)) } Self::TSImportType(it) => { - TSTupleElement::TSImportType(CloneIn::clone_in(it, allocator)) - } - Self::TSIndexedAccessType(it) => { - TSTupleElement::TSIndexedAccessType(CloneIn::clone_in(it, allocator)) + TSTupleElement::TSImportType(CloneIn::clone_in_with_semantic_ids(it, allocator)) } - Self::TSInferType(it) => TSTupleElement::TSInferType(CloneIn::clone_in(it, allocator)), - Self::TSIntersectionType(it) => { - TSTupleElement::TSIntersectionType(CloneIn::clone_in(it, allocator)) + Self::TSIndexedAccessType(it) => TSTupleElement::TSIndexedAccessType( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSInferType(it) => { + TSTupleElement::TSInferType(CloneIn::clone_in_with_semantic_ids(it, allocator)) } + Self::TSIntersectionType(it) => TSTupleElement::TSIntersectionType( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), Self::TSLiteralType(it) => { - TSTupleElement::TSLiteralType(CloneIn::clone_in(it, allocator)) + TSTupleElement::TSLiteralType(CloneIn::clone_in_with_semantic_ids(it, allocator)) } Self::TSMappedType(it) => { - TSTupleElement::TSMappedType(CloneIn::clone_in(it, allocator)) - } - Self::TSNamedTupleMember(it) => { - TSTupleElement::TSNamedTupleMember(CloneIn::clone_in(it, allocator)) + TSTupleElement::TSMappedType(CloneIn::clone_in_with_semantic_ids(it, allocator)) } + Self::TSNamedTupleMember(it) => TSTupleElement::TSNamedTupleMember( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), Self::TSQualifiedName(it) => { - TSTupleElement::TSQualifiedName(CloneIn::clone_in(it, allocator)) + TSTupleElement::TSQualifiedName(CloneIn::clone_in_with_semantic_ids(it, allocator)) } - Self::TSTemplateLiteralType(it) => { - TSTupleElement::TSTemplateLiteralType(CloneIn::clone_in(it, allocator)) + Self::TSTemplateLiteralType(it) => TSTupleElement::TSTemplateLiteralType( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSThisType(it) => { + TSTupleElement::TSThisType(CloneIn::clone_in_with_semantic_ids(it, allocator)) } - Self::TSThisType(it) => TSTupleElement::TSThisType(CloneIn::clone_in(it, allocator)), - Self::TSTupleType(it) => TSTupleElement::TSTupleType(CloneIn::clone_in(it, allocator)), - Self::TSTypeLiteral(it) => { - TSTupleElement::TSTypeLiteral(CloneIn::clone_in(it, allocator)) + Self::TSTupleType(it) => { + TSTupleElement::TSTupleType(CloneIn::clone_in_with_semantic_ids(it, allocator)) } - Self::TSTypeOperatorType(it) => { - TSTupleElement::TSTypeOperatorType(CloneIn::clone_in(it, allocator)) + Self::TSTypeLiteral(it) => { + TSTupleElement::TSTypeLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) } + Self::TSTypeOperatorType(it) => TSTupleElement::TSTypeOperatorType( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), Self::TSTypePredicate(it) => { - TSTupleElement::TSTypePredicate(CloneIn::clone_in(it, allocator)) - } - Self::TSTypeQuery(it) => TSTupleElement::TSTypeQuery(CloneIn::clone_in(it, allocator)), - Self::TSTypeReference(it) => { - TSTupleElement::TSTypeReference(CloneIn::clone_in(it, allocator)) + TSTupleElement::TSTypePredicate(CloneIn::clone_in_with_semantic_ids(it, allocator)) } - Self::TSUnionType(it) => TSTupleElement::TSUnionType(CloneIn::clone_in(it, allocator)), - Self::TSParenthesizedType(it) => { - TSTupleElement::TSParenthesizedType(CloneIn::clone_in(it, allocator)) + Self::TSTypeQuery(it) => { + TSTupleElement::TSTypeQuery(CloneIn::clone_in_with_semantic_ids(it, allocator)) } - Self::JSDocNullableType(it) => { - TSTupleElement::JSDocNullableType(CloneIn::clone_in(it, allocator)) + Self::TSTypeReference(it) => { + TSTupleElement::TSTypeReference(CloneIn::clone_in_with_semantic_ids(it, allocator)) } - Self::JSDocNonNullableType(it) => { - TSTupleElement::JSDocNonNullableType(CloneIn::clone_in(it, allocator)) + Self::TSUnionType(it) => { + TSTupleElement::TSUnionType(CloneIn::clone_in_with_semantic_ids(it, allocator)) } + Self::TSParenthesizedType(it) => TSTupleElement::TSParenthesizedType( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::JSDocNullableType(it) => TSTupleElement::JSDocNullableType( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::JSDocNonNullableType(it) => TSTupleElement::JSDocNonNullableType( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), Self::JSDocUnknownType(it) => { - TSTupleElement::JSDocUnknownType(CloneIn::clone_in(it, allocator)) + TSTupleElement::JSDocUnknownType(CloneIn::clone_in_with_semantic_ids(it, allocator)) } } } @@ -3259,6 +4858,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeName<'_> { Self::QualifiedName(it) => TSTypeName::QualifiedName(CloneIn::clone_in(it, allocator)), } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::IdentifierReference(it) => { + TSTypeName::IdentifierReference(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::QualifiedName(it) => { + TSTypeName::QualifiedName(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for TSQualifiedName<'_> { @@ -3426,6 +5036,28 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSSignature<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::TSIndexSignature(it) => { + TSSignature::TSIndexSignature(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSPropertySignature(it) => { + TSSignature::TSPropertySignature(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSCallSignatureDeclaration(it) => TSSignature::TSCallSignatureDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSConstructSignatureDeclaration(it) => { + TSSignature::TSConstructSignatureDeclaration(CloneIn::clone_in_with_semantic_ids( + it, allocator, + )) + } + Self::TSMethodSignature(it) => { + TSSignature::TSMethodSignature(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for TSIndexSignature<'_> { @@ -3565,6 +5197,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypePredicateName<'_> { Self::This(it) => TSTypePredicateName::This(CloneIn::clone_in(it, allocator)), } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::Identifier(it) => { + TSTypePredicateName::Identifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::This(it) => { + TSTypePredicateName::This(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for TSModuleDeclaration<'_> { @@ -3615,6 +5258,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSModuleDeclarationName<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::Identifier(it) => TSModuleDeclarationName::Identifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StringLiteral(it) => TSModuleDeclarationName::StringLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for TSModuleDeclarationBody<'_> { @@ -3629,6 +5283,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSModuleDeclarationBody<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::TSModuleDeclaration(it) => TSModuleDeclarationBody::TSModuleDeclaration( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSModuleBlock(it) => TSModuleDeclarationBody::TSModuleBlock( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for TSModuleBlock<'_> { @@ -3688,6 +5353,20 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSTypeQueryExprName<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::TSImportType(it) => TSTypeQueryExprName::TSImportType( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::IdentifierReference(it) => TSTypeQueryExprName::IdentifierReference( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::QualifiedName(it) => TSTypeQueryExprName::QualifiedName( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for TSImportType<'_> { @@ -3738,6 +5417,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSImportAttributeName<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::Identifier(it) => TSImportAttributeName::Identifier( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StringLiteral(it) => TSImportAttributeName::StringLiteral( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for TSFunctionType<'_> { @@ -3876,6 +5566,20 @@ impl<'new_alloc> CloneIn<'new_alloc> for TSModuleReference<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::ExternalModuleReference(it) => TSModuleReference::ExternalModuleReference( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::IdentifierReference(it) => TSModuleReference::IdentifierReference( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::QualifiedName(it) => { + TSModuleReference::QualifiedName(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for TSExternalModuleReference<'_> { @@ -4058,6 +5762,26 @@ impl<'new_alloc> CloneIn<'new_alloc> for JSXElementName<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::Identifier(it) => { + JSXElementName::Identifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::IdentifierReference(it) => JSXElementName::IdentifierReference( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::NamespacedName(it) => { + JSXElementName::NamespacedName(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::MemberExpression(it) => { + JSXElementName::MemberExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ThisExpression(it) => { + JSXElementName::ThisExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for JSXNamespacedName<'_> { @@ -4097,6 +5821,20 @@ impl<'new_alloc> CloneIn<'new_alloc> for JSXMemberExpressionObject<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::IdentifierReference(it) => JSXMemberExpressionObject::IdentifierReference( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::MemberExpression(it) => JSXMemberExpressionObject::MemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ThisExpression(it) => JSXMemberExpressionObject::ThisExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for JSXExpressionContainer<'_> { @@ -4232,6 +5970,140 @@ impl<'new_alloc> CloneIn<'new_alloc> for JSXExpression<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::EmptyExpression(it) => { + JSXExpression::EmptyExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BooleanLiteral(it) => { + JSXExpression::BooleanLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NullLiteral(it) => { + JSXExpression::NullLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NumericLiteral(it) => { + JSXExpression::NumericLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BigIntLiteral(it) => { + JSXExpression::BigIntLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::RegExpLiteral(it) => { + JSXExpression::RegExpLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::StringLiteral(it) => { + JSXExpression::StringLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TemplateLiteral(it) => { + JSXExpression::TemplateLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Identifier(it) => { + JSXExpression::Identifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::MetaProperty(it) => { + JSXExpression::MetaProperty(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Super(it) => { + JSXExpression::Super(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ArrayExpression(it) => { + JSXExpression::ArrayExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ArrowFunctionExpression(it) => JSXExpression::ArrowFunctionExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::AssignmentExpression(it) => JSXExpression::AssignmentExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::AwaitExpression(it) => { + JSXExpression::AwaitExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::BinaryExpression(it) => { + JSXExpression::BinaryExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::CallExpression(it) => { + JSXExpression::CallExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ChainExpression(it) => { + JSXExpression::ChainExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ClassExpression(it) => { + JSXExpression::ClassExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ConditionalExpression(it) => JSXExpression::ConditionalExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::FunctionExpression(it) => JSXExpression::FunctionExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ImportExpression(it) => { + JSXExpression::ImportExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::LogicalExpression(it) => { + JSXExpression::LogicalExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NewExpression(it) => { + JSXExpression::NewExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ObjectExpression(it) => { + JSXExpression::ObjectExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ParenthesizedExpression(it) => JSXExpression::ParenthesizedExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::SequenceExpression(it) => JSXExpression::SequenceExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TaggedTemplateExpression(it) => JSXExpression::TaggedTemplateExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ThisExpression(it) => { + JSXExpression::ThisExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::UnaryExpression(it) => { + JSXExpression::UnaryExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::UpdateExpression(it) => { + JSXExpression::UpdateExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::YieldExpression(it) => { + JSXExpression::YieldExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::PrivateInExpression(it) => JSXExpression::PrivateInExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::JSXElement(it) => { + JSXExpression::JSXElement(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::JSXFragment(it) => { + JSXExpression::JSXFragment(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSAsExpression(it) => { + JSXExpression::TSAsExpression(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSSatisfiesExpression(it) => JSXExpression::TSSatisfiesExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSTypeAssertion(it) => { + JSXExpression::TSTypeAssertion(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::TSNonNullExpression(it) => JSXExpression::TSNonNullExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::TSInstantiationExpression(it) => JSXExpression::TSInstantiationExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ComputedMemberExpression(it) => JSXExpression::ComputedMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::StaticMemberExpression(it) => JSXExpression::StaticMemberExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::PrivateFieldExpression(it) => JSXExpression::PrivateFieldExpression( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'alloc> CloneIn<'alloc> for JSXEmptyExpression { @@ -4251,6 +6123,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for JSXAttributeItem<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::Attribute(it) => { + JSXAttributeItem::Attribute(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::SpreadAttribute(it) => JSXAttributeItem::SpreadAttribute( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'new_alloc> CloneIn<'new_alloc> for JSXAttribute<'_> { @@ -4284,6 +6167,17 @@ impl<'new_alloc> CloneIn<'new_alloc> for JSXAttributeName<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::Identifier(it) => { + JSXAttributeName::Identifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NamespacedName(it) => { + JSXAttributeName::NamespacedName(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for JSXAttributeValue<'_> { @@ -4300,6 +6194,23 @@ impl<'new_alloc> CloneIn<'new_alloc> for JSXAttributeValue<'_> { Self::Fragment(it) => JSXAttributeValue::Fragment(CloneIn::clone_in(it, allocator)), } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::StringLiteral(it) => { + JSXAttributeValue::StringLiteral(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ExpressionContainer(it) => JSXAttributeValue::ExpressionContainer( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::Element(it) => { + JSXAttributeValue::Element(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Fragment(it) => { + JSXAttributeValue::Fragment(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for JSXIdentifier<'_> { @@ -4325,6 +6236,24 @@ impl<'new_alloc> CloneIn<'new_alloc> for JSXChild<'_> { Self::Spread(it) => JSXChild::Spread(CloneIn::clone_in(it, allocator)), } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::Text(it) => JSXChild::Text(CloneIn::clone_in_with_semantic_ids(it, allocator)), + Self::Element(it) => { + JSXChild::Element(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Fragment(it) => { + JSXChild::Fragment(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::ExpressionContainer(it) => { + JSXChild::ExpressionContainer(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Spread(it) => { + JSXChild::Spread(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'new_alloc> CloneIn<'new_alloc> for JSXSpreadChild<'_> { diff --git a/crates/oxc_regular_expression/src/generated/derive_clone_in.rs b/crates/oxc_regular_expression/src/generated/derive_clone_in.rs index 62f9e4ef10fde6..9d441983bf3155 100644 --- a/crates/oxc_regular_expression/src/generated/derive_clone_in.rs +++ b/crates/oxc_regular_expression/src/generated/derive_clone_in.rs @@ -63,6 +63,45 @@ impl<'new_alloc> CloneIn<'new_alloc> for Term<'_> { Self::NamedReference(it) => Term::NamedReference(CloneIn::clone_in(it, allocator)), } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::BoundaryAssertion(it) => { + Term::BoundaryAssertion(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::LookAroundAssertion(it) => { + Term::LookAroundAssertion(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Quantifier(it) => { + Term::Quantifier(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Character(it) => { + Term::Character(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::Dot(it) => Term::Dot(CloneIn::clone_in_with_semantic_ids(it, allocator)), + Self::CharacterClassEscape(it) => { + Term::CharacterClassEscape(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::UnicodePropertyEscape(it) => { + Term::UnicodePropertyEscape(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::CharacterClass(it) => { + Term::CharacterClass(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::CapturingGroup(it) => { + Term::CapturingGroup(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::IgnoreGroup(it) => { + Term::IgnoreGroup(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::IndexedReference(it) => { + Term::IndexedReference(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + Self::NamedReference(it) => { + Term::NamedReference(CloneIn::clone_in_with_semantic_ids(it, allocator)) + } + } + } } impl<'alloc> CloneIn<'alloc> for BoundaryAssertion { @@ -244,6 +283,29 @@ impl<'new_alloc> CloneIn<'new_alloc> for CharacterClassContents<'_> { } } } + + fn clone_in_with_semantic_ids(&self, allocator: &'new_alloc Allocator) -> Self::Cloned { + match self { + Self::CharacterClassRange(it) => CharacterClassContents::CharacterClassRange( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::CharacterClassEscape(it) => CharacterClassContents::CharacterClassEscape( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::UnicodePropertyEscape(it) => CharacterClassContents::UnicodePropertyEscape( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::Character(it) => CharacterClassContents::Character( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::NestedCharacterClass(it) => CharacterClassContents::NestedCharacterClass( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + Self::ClassStringDisjunction(it) => CharacterClassContents::ClassStringDisjunction( + CloneIn::clone_in_with_semantic_ids(it, allocator), + ), + } + } } impl<'alloc> CloneIn<'alloc> for CharacterClassRange { diff --git a/crates/oxc_syntax/src/reference.rs b/crates/oxc_syntax/src/reference.rs index dfd234f8db993a..953b5887976dbd 100644 --- a/crates/oxc_syntax/src/reference.rs +++ b/crates/oxc_syntax/src/reference.rs @@ -1,7 +1,7 @@ #![allow(missing_docs)] // fixme use bitflags::bitflags; use nonmax::NonMaxU32; -use oxc_allocator::CloneIn; +use oxc_allocator::{Allocator, CloneIn}; use oxc_index::Idx; #[cfg(feature = "serialize")] use serde::{Serialize, Serializer}; @@ -14,11 +14,15 @@ pub struct ReferenceId(NonMaxU32); impl<'alloc> CloneIn<'alloc> for ReferenceId { type Cloned = Self; - fn clone_in(&self, _: &'alloc oxc_allocator::Allocator) -> Self::Cloned { + fn clone_in(&self, _: &'alloc Allocator) -> Self { + // `clone_in` should never reach this, because `CloneIn` skips semantic ID fields + unreachable!(); + } + + fn clone_in_with_semantic_ids(&self, _: &'alloc Allocator) -> Self { *self } } - impl Idx for ReferenceId { #[allow(clippy::cast_possible_truncation)] fn from_usize(idx: usize) -> Self { diff --git a/tasks/ast_tools/src/derives/clone_in.rs b/tasks/ast_tools/src/derives/clone_in.rs index f7601e48ca93a4..0eb705d797aeef 100644 --- a/tasks/ast_tools/src/derives/clone_in.rs +++ b/tasks/ast_tools/src/derives/clone_in.rs @@ -54,13 +54,49 @@ fn derive_enum(def: &EnumDef) -> TokenStream { .collect_vec(); let alloc_ident = if used_alloc { format_ident!("allocator") } else { format_ident!("_") }; - let body = quote! { + let clone_in_body = quote! { match self { #(#matches),* } }; - impl_clone_in(&ty_ident, def.has_lifetime, &alloc_ident, &body, "e!()) + let clone_in_with_semantic_ids_token_stream = if used_alloc { + let matches = def + .all_variants() + .map(|var| { + let ident = var.ident(); + if var.is_unit() { + quote!(Self :: #ident => #ty_ident :: #ident) + } else { + quote!(Self :: #ident(it) => #ty_ident :: #ident(CloneIn::clone_in_with_semantic_ids(it, allocator))) + } + }) + .collect_vec(); + + let alloc_ident_param = if def.has_lifetime { + quote!(#alloc_ident: &'new_alloc Allocator) + } else { + quote!(#alloc_ident: &'alloc Allocator) + }; + quote!( + ///@@line_break + fn clone_in_with_semantic_ids(&self, #alloc_ident_param) -> Self::Cloned { + match self { + #(#matches),* + } + } + ) + } else { + quote!() + }; + + impl_clone_in( + &ty_ident, + def.has_lifetime, + &alloc_ident, + &clone_in_body, + &clone_in_with_semantic_ids_token_stream, + ) } fn derive_struct(def: &StructDef) -> TokenStream { @@ -93,9 +129,14 @@ fn derive_struct(def: &StructDef) -> TokenStream { let ident = field.ident(); quote!(#ident: CloneIn::clone_in_with_semantic_ids(&self.#ident, allocator)) }); + let alloc_ident_param = if def.has_lifetime { + quote!(#alloc_ident: &'new_alloc Allocator) + } else { + quote!(#alloc_ident: &'alloc Allocator) + }; quote!( ///@@line_break - fn clone_in_with_semantic_ids(&self, #alloc_ident: &'new_alloc Allocator) -> Self::Cloned { + fn clone_in_with_semantic_ids(&self, #alloc_ident_param) -> Self::Cloned { #ty_ident { #(#fields),* } } )