Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

feat(swc_allocator): Add Box and Vec #10069

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions crates/swc_allocator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
#![deny(missing_docs)]
#![allow(clippy::derivable_impls)]

// TODO: Add types back
// pub use crate::types::*;
pub use crate::types::*;

pub mod allocators;
pub mod api;
Expand Down
71 changes: 35 additions & 36 deletions crates/swc_common/src/eq.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{cell::RefCell, rc::Rc, sync::Arc};

use num_bigint::BigInt;
use swc_allocator::nightly_only;

use crate::{BytePos, Span};

Expand Down Expand Up @@ -64,20 +63,20 @@ where
}
}

nightly_only!(
impl<T> EqIgnoreSpan for swc_allocator::vec::Vec<T>
where
T: EqIgnoreSpan,
{
fn eq_ignore_span(&self, other: &Self) -> bool {
self.len() == other.len()
&& self
.iter()
.zip(other.iter())
.all(|(a, b)| a.eq_ignore_span(b))
}
}
);
// nightly_only!(
// impl<T> EqIgnoreSpan for swc_allocator::vec::Vec<T>
// where
// T: EqIgnoreSpan,
// {
// fn eq_ignore_span(&self, other: &Self) -> bool {
// self.len() == other.len()
// && self
// .iter()
// .zip(other.iter())
// .all(|(a, b)| a.eq_ignore_span(b))
// }
// }
// );

/// Derive with `#[derive(TypeEq)]`.
pub trait TypeEq {
Expand Down Expand Up @@ -188,27 +187,27 @@ macro_rules! deref {

deref!(Box, Rc, Arc);

swc_allocator::nightly_only!(
impl<N> EqIgnoreSpan for swc_allocator::boxed::Box<N>
where
N: EqIgnoreSpan,
{
#[inline]
fn eq_ignore_span(&self, other: &Self) -> bool {
(**self).eq_ignore_span(&**other)
}
}

impl<N> TypeEq for swc_allocator::boxed::Box<N>
where
N: TypeEq,
{
#[inline]
fn type_eq(&self, other: &Self) -> bool {
(**self).type_eq(&**other)
}
}
);
// swc_allocator::nightly_only!(
// impl<N> EqIgnoreSpan for swc_allocator::boxed::Box<N>
// where
// N: EqIgnoreSpan,
// {
// #[inline]
// fn eq_ignore_span(&self, other: &Self) -> bool {
// (**self).eq_ignore_span(&**other)
// }
// }

// impl<N> TypeEq for swc_allocator::boxed::Box<N>
// where
// N: TypeEq,
// {
// #[inline]
// fn type_eq(&self, other: &Self) -> bool {
// (**self).type_eq(&**other)
// }
// }
// );

impl<N> EqIgnoreSpan for &N
where
Expand Down
20 changes: 10 additions & 10 deletions crates/swc_common/src/pos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,13 @@ where
}
}

swc_allocator::nightly_only!(
impl<T> Spanned for swc_allocator::boxed::Box<T>
where
T: Spanned,
{
fn span(&self) -> Span {
self.as_ref().span()
}
}
);
// swc_allocator::nightly_only!(
// impl<T> Spanned for swc_allocator::boxed::Box<T>
// where
// T: Spanned,
// {
// fn span(&self) -> Span {
// self.as_ref().span()
// }
// }
// );
30 changes: 15 additions & 15 deletions crates/swc_common/src/util/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,19 +55,19 @@ impl Take for Span {
}
}

swc_allocator::nightly_only!(
impl<T> Take for swc_allocator::boxed::Box<T>
where
T: Take,
{
fn dummy() -> Self {
swc_allocator::boxed::Box::new(T::dummy())
}
}
// swc_allocator::nightly_only!(
// impl<T> Take for swc_allocator::boxed::Box<T>
// where
// T: Take,
// {
// fn dummy() -> Self {
// swc_allocator::boxed::Box::new(T::dummy())
// }
// }

impl<T> Take for swc_allocator::vec::Vec<T> {
fn dummy() -> Self {
Default::default()
}
}
);
// impl<T> Take for swc_allocator::vec::Vec<T> {
// fn dummy() -> Self {
// Default::default()
// }
// }
// );
Loading