Skip to content

Commit 398dc21

Browse files
authoredJul 15, 2024··
feat(allocator): Add a cargo feature (#9239)
**Description:** This PR is a part of #9230
1 parent b6c0468 commit 398dc21

File tree

15 files changed

+301
-2581
lines changed

15 files changed

+301
-2581
lines changed
 

‎Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bindings/Cargo.lock

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎bindings/binding_typescript_wasm/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ serde-wasm-bindgen = "0.4.5"
2222
serde_json = "1.0.120"
2323
swc_common = "0.35.0"
2424
swc_error_reporters = "0.19.0"
25-
swc_fast_ts_strip = "0.2.0"
25+
swc_fast_ts_strip = "0.2.1"
2626
tracing = { version = "0.1.37", features = ["max_level_off"] }
2727
wasm-bindgen = { version = "0.2.82", features = ["enable-interning"] }
2828
wasm-bindgen-futures = { version = "0.4.41" }

‎bindings/binding_typescript_wasm/__tests__/__snapshots__/transform.js.snap

+51-19
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,82 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`transform in strip-only mode should remove declare enum 1`] = `" "`;
3+
exports[`transform in strip-only mode should remove declare enum 1`] = `
4+
{
5+
"code": " ",
6+
"map": undefined,
7+
}
8+
`;
49

510
exports[`transform in strip-only mode should remove declare enum 2`] = `
6-
"
11+
{
12+
"code": "
713
8-
"
14+
",
15+
"map": undefined,
16+
}
917
`;
1018

1119
exports[`transform in strip-only mode should remove declare enum 3`] = `
12-
"
20+
{
21+
"code": "
1322
1423
15-
"
24+
",
25+
"map": undefined,
26+
}
1627
`;
1728

1829
exports[`transform in strip-only mode should strip complex expressions 1`] = `
19-
"const foo = {
30+
{
31+
"code": "const foo = {
2032
foo: 1 ,
2133
bar: "bar" ,
2234
} ;
23-
const bar = "bar";"
35+
const bar = "bar";",
36+
"map": undefined,
37+
}
2438
`;
2539

2640
exports[`transform in strip-only mode should strip nonnull assertions 1`] = `
27-
"const foo = 1 ;
28-
const bar = "bar";"
41+
{
42+
"code": "const foo = 1 ;
43+
const bar = "bar";",
44+
"map": undefined,
45+
}
2946
`;
3047

3148
exports[`transform in strip-only mode should strip satisfies 1`] = `
32-
"const foo = 1 ;
33-
const bar = "bar";"
49+
{
50+
"code": "const foo = 1 ;
51+
const bar = "bar";",
52+
"map": undefined,
53+
}
3454
`;
3555

3656
exports[`transform in strip-only mode should strip type annotations 1`] = `
37-
"const foo = 1;
38-
const bar = "bar";"
57+
{
58+
"code": "const foo = 1;
59+
const bar = "bar";",
60+
"map": undefined,
61+
}
3962
`;
4063

4164
exports[`transform in strip-only mode should strip type assertions 1`] = `
42-
"const foo = 1 ;
43-
const bar = "bar";"
65+
{
66+
"code": "const foo = 1 ;
67+
const bar = "bar";",
68+
"map": undefined,
69+
}
4470
`;
4571

4672
exports[`transform in strip-only mode should strip type declarations 1`] = `
47-
"const foo = 1;
73+
{
74+
"code": "const foo = 1;
4875
4976
50-
const bar = "bar";"
77+
const bar = "bar";",
78+
"map": undefined,
79+
}
5180
`;
5281

5382
exports[`transform in strip-only mode should throw an error when it encounters a module 1`] = `
@@ -78,8 +107,11 @@ exports[`transform in strip-only mode should throw an error when it encounters a
78107
`;
79108

80109
exports[`transform should strip types 1`] = `
81-
"
110+
{
111+
"code": "
82112
export const foo = 1;
83113
84-
"
114+
",
115+
"map": undefined,
116+
}
85117
`;

‎bindings/binding_typescript_wasm/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Error;
22
use swc_common::{errors::ColorConfig, sync::Lrc, SourceMap, GLOBALS};
33
use swc_error_reporters::handler::{try_with_handler, HandlerOpts};
4-
use swc_fast_ts_strip::Options;
4+
use swc_fast_ts_strip::{Options, TransformOutput};
55
use wasm_bindgen::prelude::*;
66
use wasm_bindgen_futures::{
77
future_to_promise,
@@ -34,7 +34,7 @@ pub fn transform_sync(input: JsString, options: JsValue) -> Result<JsValue, JsVa
3434
Ok(serde_wasm_bindgen::to_value(&result)?)
3535
}
3636

37-
fn operate(input: String, options: Options) -> Result<String, Error> {
37+
fn operate(input: String, options: Options) -> Result<TransformOutput, Error> {
3838
let cm = Lrc::new(SourceMap::default());
3939

4040
try_with_handler(

‎crates/swc_allocator/Cargo.toml

+14-7
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,22 @@ name = "swc_allocator"
88
repository = { workspace = true }
99
version = "0.1.3"
1010

11+
[package.metadata.docs.rs]
12+
all-features = true
13+
rustdoc-args = ["--cfg", "docsrs"]
14+
15+
1116
[features]
12-
rkyv = ["dep:rkyv"]
13-
serde = ["dep:serde", "dep:serde_derive"]
17+
rkyv = ["dep:rkyv"]
18+
scoped = []
19+
serde = ["dep:serde", "dep:serde_derive"]
1420

1521
[dependencies]
1622
allocator-api2 = { workspace = true, features = ["serde"] }
1723
bumpalo = { workspace = true, features = [
18-
"allocator-api2",
19-
"boxed",
20-
"collections",
24+
"allocator-api2",
25+
"boxed",
26+
"collections",
2127
] }
2228
ptr_meta = { workspace = true }
2329
rkyv = { workspace = true, optional = true }
@@ -34,5 +40,6 @@ swc_malloc = { version = "0.5.10", path = "../swc_malloc" }
3440

3541

3642
[[bench]]
37-
harness = false
38-
name = "bench"
43+
features = ["scoped"]
44+
harness = false
45+
name = "bench"

‎crates/swc_allocator/benches/bench.rs

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
extern crate swc_malloc;
22

33
use codspeed_criterion_compat::{black_box, criterion_group, criterion_main, Bencher, Criterion};
4-
use swc_allocator::{FastAlloc, SwcAllocator};
4+
use swc_allocator::{boxed::Box as SwcBox, vec::Vec as SwcVec, Allocator, FastAlloc};
55

66
fn bench_alloc(c: &mut Criterion) {
77
fn direct_alloc_std(b: &mut Bencher, times: usize) {
@@ -16,38 +16,35 @@ fn bench_alloc(c: &mut Criterion) {
1616

1717
fn direct_alloc_no_scope(b: &mut Bencher, times: usize) {
1818
b.iter(|| {
19-
let mut vec = swc_allocator::vec::Vec::new();
19+
let mut vec = SwcVec::new();
2020
for i in 0..times {
21-
let item: swc_allocator::boxed::Box<usize> =
22-
black_box(swc_allocator::boxed::Box::new(black_box(i)));
21+
let item: SwcBox<usize> = black_box(SwcBox::new(black_box(i)));
2322
vec.push(item);
2423
}
2524
})
2625
}
2726

2827
fn fast_alloc_no_scope(b: &mut Bencher, times: usize) {
2928
b.iter(|| {
30-
let allocator = FastAlloc::default();
29+
let alloc = FastAlloc::default();
3130

32-
let mut vec = allocator.vec();
31+
let mut vec = SwcVec::new_in(alloc);
3332
for i in 0..times {
34-
let item: swc_allocator::boxed::Box<usize> =
35-
black_box(allocator.alloc(black_box(i)));
33+
let item: SwcBox<usize> = black_box(SwcBox::new_in(black_box(i), alloc));
3634
vec.push(item);
3735
}
3836
})
3937
}
4038

4139
fn direct_alloc_scoped(b: &mut Bencher, times: usize) {
4240
b.iter(|| {
43-
let allocator = SwcAllocator::default();
41+
let allocator = Allocator::default();
4442

4543
allocator.scope(|| {
46-
let mut vec = swc_allocator::vec::Vec::new();
44+
let mut vec = SwcVec::new();
4745

4846
for i in 0..times {
49-
let item: swc_allocator::boxed::Box<usize> =
50-
black_box(swc_allocator::boxed::Box::new(black_box(i)));
47+
let item: SwcBox<usize> = black_box(SwcBox::new(black_box(i)));
5148
vec.push(item);
5249
}
5350
});
@@ -56,14 +53,13 @@ fn bench_alloc(c: &mut Criterion) {
5653

5754
fn fast_alloc_scoped(b: &mut Bencher, times: usize) {
5855
b.iter(|| {
59-
SwcAllocator::default().scope(|| {
60-
let allocator = FastAlloc::default();
56+
Allocator::default().scope(|| {
57+
let alloc = FastAlloc::default();
6158

62-
let mut vec = allocator.vec();
59+
let mut vec = SwcVec::new_in(alloc);
6360

6461
for i in 0..times {
65-
let item: swc_allocator::boxed::Box<usize> =
66-
black_box(allocator.alloc(black_box(i)));
62+
let item: SwcBox<usize> = black_box(SwcBox::new_in(black_box(i), alloc));
6763
vec.push(item);
6864
}
6965
});

‎crates/swc_allocator/src/alloc.rs

+40-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,27 @@
1-
use std::{alloc::Layout, cell::Cell, mem::transmute, ptr::NonNull};
1+
use std::{
2+
alloc::Layout,
3+
cell::Cell,
4+
mem::transmute,
5+
ops::{Deref, DerefMut},
6+
ptr::NonNull,
7+
};
28

39
use allocator_api2::alloc::Global;
10+
use bumpalo::Bump;
411

5-
use crate::{FastAlloc, MemorySpace};
12+
use crate::FastAlloc;
613

714
thread_local! {
8-
static ALLOC: Cell<Option<&'static SwcAllocator>> = const { Cell::new(None) };
15+
static ALLOC: Cell<Option<&'static Allocator>> = const { Cell::new(None) };
916
}
1017

18+
/// The actual storage for [FastAlloc].
1119
#[derive(Default)]
12-
pub struct SwcAllocator(MemorySpace);
20+
pub struct Allocator {
21+
alloc: Bump,
22+
}
1323

14-
impl SwcAllocator {
24+
impl Allocator {
1525
/// Invokes `f` in a scope where the allocations are done in this allocator.
1626
#[inline(always)]
1727
pub fn scope<'a, F, R>(&'a self, f: F) -> R
@@ -20,7 +30,7 @@ impl SwcAllocator {
2030
{
2131
let s = unsafe {
2232
// Safery: We are using a scoped API
23-
transmute::<&'a SwcAllocator, &'static SwcAllocator>(self)
33+
transmute::<&'a Allocator, &'static Allocator>(self)
2434
};
2535

2636
ALLOC.set(Some(s));
@@ -49,7 +59,10 @@ impl FastAlloc {
4959
f: impl FnOnce(&dyn allocator_api2::alloc::Allocator, bool) -> T,
5060
) -> T {
5161
if let Some(arena) = &self.alloc {
52-
f((&&*arena.0) as &dyn allocator_api2::alloc::Allocator, true)
62+
f(
63+
(&&arena.alloc) as &dyn allocator_api2::alloc::Allocator,
64+
true,
65+
)
5366
} else {
5467
f(&allocator_api2::alloc::Global, false)
5568
}
@@ -159,3 +172,23 @@ unsafe impl allocator_api2::alloc::Allocator for FastAlloc {
159172
self
160173
}
161174
}
175+
176+
impl From<Bump> for Allocator {
177+
fn from(alloc: Bump) -> Self {
178+
Self { alloc }
179+
}
180+
}
181+
182+
impl Deref for Allocator {
183+
type Target = Bump;
184+
185+
fn deref(&self) -> &Bump {
186+
&self.alloc
187+
}
188+
}
189+
190+
impl DerefMut for Allocator {
191+
fn deref_mut(&mut self) -> &mut Bump {
192+
&mut self.alloc
193+
}
194+
}

‎crates/swc_allocator/src/boxed/mod.rs

+32-19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Faster box type.
2+
13
use std::{
24
borrow::{Borrow, BorrowMut},
35
fmt::{self, Debug, Display, Formatter},
@@ -14,13 +16,7 @@ mod rkyv;
1416
#[cfg(feature = "serde")]
1517
mod serde;
1618

17-
/// A special `Box` which has size of [`std::boxed::Box`] but **may** be
18-
/// allocated with a custom allocator.
19-
///
20-
///
21-
/// # Representation
22-
///
23-
/// The last bit is 1 if the box is allocated with a custom allocator.
19+
/// Faster alterantive for [`std::boxed::Box`].
2420
#[repr(transparent)]
2521
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
2622
pub struct Box<T: ?Sized>(pub(crate) allocator_api2::boxed::Box<T, FastAlloc>);
@@ -49,15 +45,38 @@ where
4945
}
5046

5147
impl<T> Box<T> {
52-
/// Allocates a new box with `value`.
48+
/// Allocates memory on the heap and then places `x` into it.
49+
///
50+
/// This doesn't actually allocate if `T` is zero-sized.
51+
///
52+
/// # Examples
53+
///
54+
/// ```
55+
/// let five = Box::new(5);
56+
/// ```
5357
///
54-
/// See [`std::boxed::Box::new`].
58+
/// Note: This is slower than using [Self::new_in] with cached [FastAlloc].
5559
#[inline(always)]
5660
pub fn new(value: T) -> Self {
57-
Self(allocator_api2::boxed::Box::new_in(
58-
value,
59-
FastAlloc::default(),
60-
))
61+
Self::new_in(value, Default::default())
62+
}
63+
64+
/// Allocates memory in the given allocator then places `x` into it.
65+
///
66+
/// This doesn't actually allocate if `T` is zero-sized.
67+
///
68+
/// # Examples
69+
///
70+
/// ```
71+
/// #![feature(allocator_api)]
72+
///
73+
/// use std::alloc::System;
74+
///
75+
/// let five = Box::new_in(5, System);
76+
/// ```
77+
#[inline(always)]
78+
pub fn new_in(value: T, alloc: FastAlloc) -> Self {
79+
Self(allocator_api2::boxed::Box::new_in(value, alloc))
6180
}
6281

6382
/// Moves the value out of the box.
@@ -627,9 +646,3 @@ where
627646
self.0.len()
628647
}
629648
}
630-
631-
impl FastAlloc {
632-
pub fn alloc<T>(&self, t: T) -> Box<T> {
633-
Box(allocator_api2::boxed::Box::new_in(t, self.clone()))
634-
}
635-
}

‎crates/swc_allocator/src/lib.rs

+25-32
Original file line numberDiff line numberDiff line change
@@ -3,43 +3,36 @@
33
//! API designed after [`oxc_allocator`](https://github.com/oxc-project/oxc/tree/725571aad193ec6ba779c820baeb4a7774533ed7/crates/oxc_allocator/src).
44
55
#![allow(clippy::needless_doctest_main)]
6+
#![cfg_attr(docsrs, feature(doc_cfg))]
7+
#![deny(missing_docs)]
68

7-
use std::ops::{Deref, DerefMut};
8-
9-
use bumpalo::Bump;
10-
11-
pub use crate::alloc::SwcAllocator;
9+
pub use crate::alloc::Allocator;
1210

1311
mod alloc;
1412
pub mod boxed;
1513
pub mod vec;
1614

17-
#[derive(Clone)]
15+
/// Fast allocator, effectively working as a cache.
16+
///
17+
/// This type implements [Default] and [Copy]. This type is intended to stored
18+
/// in a variable or a field in a struct before allocating code, and used as the
19+
/// seocnd argument in [crate::boxed::Box::new_in] and
20+
/// [crate::vec::Vec::new_in].
21+
///
22+
/// [crate::boxed::Box::new] and [crate::vec::Vec::new] are slower than using
23+
/// this field because they use [FastAlloc::default] internally, which is slower
24+
/// than store [FastAlloc] in a variable.
25+
///
26+
///
27+
///
28+
/// # Misc
29+
///
30+
/// It implements [`allocator_api2::alloc::Allocator`]. So it can be used as the
31+
/// second argument for [`allocator_api2::boxed::Box`] and
32+
/// [`allocator_api2::vec::Vec`]. But you should prefer using
33+
/// [`crate::boxed::Box`] and [`crate::vec::Vec`], which is a wrapper around the
34+
/// original types.
35+
#[derive(Clone, Copy)]
1836
pub struct FastAlloc {
19-
alloc: Option<&'static SwcAllocator>,
20-
}
21-
22-
#[derive(Default)]
23-
struct MemorySpace {
24-
alloc: Bump,
25-
}
26-
27-
impl From<Bump> for MemorySpace {
28-
fn from(alloc: Bump) -> Self {
29-
Self { alloc }
30-
}
31-
}
32-
33-
impl Deref for MemorySpace {
34-
type Target = Bump;
35-
36-
fn deref(&self) -> &Bump {
37-
&self.alloc
38-
}
39-
}
40-
41-
impl DerefMut for MemorySpace {
42-
fn deref_mut(&mut self) -> &mut Bump {
43-
&mut self.alloc
44-
}
37+
alloc: Option<&'static Allocator>,
4538
}

‎crates/swc_allocator/src/vec/mod.rs

+110-19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
//! Faster vec type.
2+
13
use std::ops::{Deref, DerefMut};
24

35
#[cfg(feature = "rkyv")]
46
mod rkyv;
57

68
use crate::{boxed::Box, FastAlloc};
79

10+
/// Faster version of [`std::vec::Vec`].
811
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
912
#[repr(transparent)]
1013
#[cfg_attr(
@@ -14,15 +17,116 @@ use crate::{boxed::Box, FastAlloc};
1417
pub struct Vec<T>(allocator_api2::vec::Vec<T, FastAlloc>);
1518

1619
impl<T> Vec<T> {
20+
/// Constructs a new, empty `Vec<T>`.
21+
///
22+
/// The vector will not allocate until elements are pushed onto it.
23+
///
24+
/// # Examples
25+
///
26+
/// ```
27+
/// # #![allow(unused_mut)]
28+
/// let mut vec: Vec<i32> = Vec::new();
29+
/// ```
30+
///
31+
/// Note: This is slower than using [Self::new_in] with cached [FastAlloc].
1732
pub fn new() -> Self {
18-
Default::default()
33+
Self::new_in(Default::default())
1934
}
2035

36+
/// Constructs a new, empty `Vec<T, A>`.
37+
///
38+
/// The vector will not allocate until elements are pushed onto it.
39+
///
40+
/// See [std::vec::Vec::new_in] for more information.
41+
pub fn new_in(alloc: FastAlloc) -> Self {
42+
Self(allocator_api2::vec::Vec::new_in(alloc))
43+
}
44+
45+
/// Constructs a new, empty `Vec<T>` with at least the specified capacity.
46+
///
47+
/// The vector will be able to hold at least `capacity` elements without
48+
/// reallocating. This method is allowed to allocate for more elements than
49+
/// `capacity`. If `capacity` is 0, the vector will not allocate.
50+
///
51+
/// It is important to note that although the returned vector has the
52+
/// minimum *capacity* specified, the vector will have a zero *length*. For
53+
/// an explanation of the difference between length and capacity, see
54+
/// *[Capacity and reallocation]*.
55+
///
56+
/// If it is important to know the exact allocated capacity of a `Vec`,
57+
/// always use the [`capacity`] method after construction.
58+
///
59+
/// For `Vec<T>` where `T` is a zero-sized type, there will be no allocation
60+
/// and the capacity will always be `usize::MAX`.
61+
///
62+
/// [Capacity and reallocation]: #capacity-and-reallocation
63+
/// [`capacity`]: Vec::capacity
64+
///
65+
/// # Panics
66+
///
67+
/// Panics if the new capacity exceeds `isize::MAX` bytes.
68+
///
69+
/// # Examples
70+
///
71+
/// ```
72+
/// let mut vec = Vec::with_capacity(10);
73+
///
74+
/// // The vector contains no items, even though it has capacity for more
75+
/// assert_eq!(vec.len(), 0);
76+
/// assert!(vec.capacity() >= 10);
77+
///
78+
/// // These are all done without reallocating...
79+
/// for i in 0..10 {
80+
/// vec.push(i);
81+
/// }
82+
/// assert_eq!(vec.len(), 10);
83+
/// assert!(vec.capacity() >= 10);
84+
///
85+
/// // ...but this may make the vector reallocate
86+
/// vec.push(11);
87+
/// assert_eq!(vec.len(), 11);
88+
/// assert!(vec.capacity() >= 11);
89+
///
90+
/// // A vector of a zero-sized type will always over-allocate, since no
91+
/// // allocation is necessary
92+
/// let vec_units = Vec::<()>::with_capacity(10);
93+
/// assert_eq!(vec_units.capacity(), usize::MAX);
94+
/// ```
95+
///
96+
/// Note: This is slower than using [Self::with_capacity_in] with cached
97+
/// [FastAlloc].
2198
pub fn with_capacity(capacity: usize) -> Self {
22-
Self(allocator_api2::vec::Vec::with_capacity_in(
23-
capacity,
24-
FastAlloc::default(),
25-
))
99+
Self::with_capacity_in(capacity, Default::default())
100+
}
101+
102+
/// Constructs a new, empty `Vec<T, A>` with at least the specified capacity
103+
/// with the provided allocator.
104+
///
105+
/// The vector will be able to hold at least `capacity` elements without
106+
/// reallocating. This method is allowed to allocate for more elements than
107+
/// `capacity`. If `capacity` is 0, the vector will not allocate.
108+
///
109+
/// It is important to note that although the returned vector has the
110+
/// minimum *capacity* specified, the vector will have a zero *length*. For
111+
/// an explanation of the difference between length and capacity, see
112+
/// *[Capacity and reallocation]*.
113+
///
114+
/// If it is important to know the exact allocated capacity of a `Vec`,
115+
/// always use the [`capacity`] method after construction.
116+
///
117+
/// For `Vec<T, A>` where `T` is a zero-sized type, there will be no
118+
/// allocation and the capacity will always be `usize::MAX`.
119+
///
120+
/// [Capacity and reallocation]: #capacity-and-reallocation
121+
/// [`capacity`]: Vec::capacity
122+
///
123+
/// # Panics
124+
///
125+
/// Panics if the new capacity exceeds `isize::MAX` bytes.
126+
///
127+
/// See [std::vec::Vec::with_capacity_in] for more information.
128+
pub fn with_capacity_in(capacity: usize, alloc: FastAlloc) -> Self {
129+
Self(allocator_api2::vec::Vec::with_capacity_in(capacity, alloc))
26130
}
27131

28132
/// Converts the vector into [`Box<[T]>`][owned slice].
@@ -105,7 +209,7 @@ impl<T> Vec<T> {
105209
/// * `capacity` needs to be the capacity that the pointer was allocated
106210
/// with.
107211
/// * The allocated size in bytes must be no larger than `isize::MAX`. See
108-
/// the safety documentation of [`pointer::offset`].
212+
/// the safety documentation of [`std::pointer::offset`].
109213
///
110214
/// These requirements are always upheld by any `ptr` that has been
111215
/// allocated via `Vec<T>`. Other allocation sources are allowed if the
@@ -243,16 +347,3 @@ impl<T> Extend<T> for Vec<T> {
243347
self.0.extend(iter)
244348
}
245349
}
246-
247-
impl FastAlloc {
248-
pub fn vec<T>(&self) -> Vec<T> {
249-
Vec(allocator_api2::vec::Vec::new_in(self.clone()))
250-
}
251-
252-
pub fn vec_with_capacity<T>(&self, capacity: usize) -> Vec<T> {
253-
Vec(allocator_api2::vec::Vec::with_capacity_in(
254-
capacity,
255-
self.clone(),
256-
))
257-
}
258-
}

‎crates/swc_allocator/tests/apis.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use criterion::black_box;
2-
use swc_allocator::SwcAllocator;
2+
use swc_allocator::Allocator;
33

44
#[test]
55
fn direct_alloc_std() {
@@ -22,7 +22,7 @@ fn direct_alloc_no_scope() {
2222

2323
#[test]
2424
fn direct_alloc_in_scope() {
25-
let allocator = SwcAllocator::default();
25+
let allocator = Allocator::default();
2626

2727
allocator.scope(|| {
2828
let mut vec = swc_allocator::vec::Vec::new();

‎crates/swc_atoms/words.txt

-2,454
This file was deleted.

‎crates/swc_core/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ doctest = false
3838
## but changes internal logics to perform differently. These flag should be turned on in combination with
3939
## actual features. Refer build.rs for more details.
4040

41+
scoped-alloc = ["swc_allocator/scoped"]
42+
4143
# swc_common/ahash
4244
common_ahash = ["swc_common/ahash"]
4345

@@ -381,6 +383,7 @@ swc_transform_common = { optional = true, version = "0.1.0", path =
381383
swc_typescript = { optional = true, version = "0.2.0", path = "../swc_typescript" }
382384
testing = { optional = true, version = "0.37.0", path = "../testing" }
383385
# TODO: eventually swc_plugin_runner needs to remove default features
386+
swc_allocator = { version = "0.1.2", path = "../swc_allocator" }
384387
swc_plugin_runner = { optional = true, version = "0.110.0", path = "../swc_plugin_runner", default-features = false }
385388

386389
[build-dependencies]

‎crates/swc_core/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#![cfg_attr(docsrs, feature(doc_cfg))]
22

3+
pub extern crate swc_allocator as alloc;
4+
35
#[cfg(feature = "swc_atoms")]
46
#[cfg_attr(docsrs, doc(cfg(feature = "swc_atoms")))]
57
pub use swc_atoms as atoms;

0 commit comments

Comments
 (0)
Please sign in to comment.