Skip to content

Commit ae53a35

Browse files
authored
test(parallel): Add test to debug segfault on windows x64 (#9857)
**Description:** - Diff range: v1.10.4...v1.10.6 **Related issue:** - #9855
1 parent 624680b commit ae53a35

File tree

7 files changed

+296
-114
lines changed

7 files changed

+296
-114
lines changed

Diff for: .github/workflows/CI.yml

+1-6
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,7 @@ jobs:
497497
fail-fast: false
498498
matrix:
499499
crate:
500-
- better_scoped_tls
501-
- string_enum
502-
# - swc
503-
- swc_bundler
504-
# - swc_ecma_codegen
505-
# - swc_ecma_minifier
500+
- swc_parallel
506501
steps:
507502
- uses: actions/checkout@v4
508503
with:

Diff for: Cargo.lock

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

Diff for: crates/swc_ecma_utils/src/parallel.rs

+4-108
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,10 @@
33
use once_cell::sync::Lazy;
44
use swc_common::GLOBALS;
55
use swc_ecma_ast::*;
6-
use swc_parallel::join;
7-
8-
use self::private::Sealed;
9-
10-
mod private {
11-
pub trait Sealed {}
12-
13-
impl<T> Sealed for Vec<T> {}
14-
impl<T> Sealed for &mut Vec<T> {}
15-
impl<T> Sealed for &mut [T] {}
16-
impl<T> Sealed for &[T] {}
17-
}
6+
use swc_parallel::{
7+
items::{IntoItems, Items},
8+
join,
9+
};
1810

1911
static CPU_COUNT: Lazy<usize> = Lazy::new(num_cpus::get);
2012

@@ -36,102 +28,6 @@ pub trait Parallel: swc_common::sync::Send + swc_common::sync::Sync {
3628
fn after_module_items(&mut self, _stmts: &mut Vec<ModuleItem>) {}
3729
}
3830

39-
pub trait IntoItems: Sealed {
40-
type Elem;
41-
type Items: Items<Elem = Self::Elem>;
42-
43-
fn into_items(self) -> Self::Items;
44-
}
45-
46-
impl<T, I> IntoItems for I
47-
where
48-
I: Items<Elem = T>,
49-
{
50-
type Elem = T;
51-
type Items = I;
52-
53-
fn into_items(self) -> Self::Items {
54-
self
55-
}
56-
}
57-
58-
impl<'a, T> IntoItems for &'a mut Vec<T>
59-
where
60-
T: Send + Sync,
61-
{
62-
type Elem = &'a mut T;
63-
type Items = &'a mut [T];
64-
65-
fn into_items(self) -> Self::Items {
66-
self
67-
}
68-
}
69-
70-
/// This is considered as a private type and it's NOT A PUBLIC API.
71-
#[allow(clippy::len_without_is_empty)]
72-
pub trait Items: Sized + IntoIterator<Item = Self::Elem> + Send + Sealed {
73-
type Elem: Send + Sync;
74-
75-
fn len(&self) -> usize;
76-
77-
#[cfg(feature = "concurrent")]
78-
fn split_at(self, idx: usize) -> (Self, Self);
79-
}
80-
81-
impl<T> Items for Vec<T>
82-
where
83-
T: Send + Sync,
84-
{
85-
type Elem = T;
86-
87-
fn len(&self) -> usize {
88-
Vec::len(self)
89-
}
90-
91-
#[cfg(feature = "concurrent")]
92-
fn split_at(mut self, at: usize) -> (Self, Self) {
93-
let b = self.split_off(at);
94-
95-
(self, b)
96-
}
97-
}
98-
99-
impl<'a, T> Items for &'a mut [T]
100-
where
101-
T: Send + Sync,
102-
{
103-
type Elem = &'a mut T;
104-
105-
fn len(&self) -> usize {
106-
<[T]>::len(self)
107-
}
108-
109-
#[cfg(feature = "concurrent")]
110-
fn split_at(self, at: usize) -> (Self, Self) {
111-
let (a, b) = self.split_at_mut(at);
112-
113-
(a, b)
114-
}
115-
}
116-
117-
impl<'a, T> Items for &'a [T]
118-
where
119-
T: Send + Sync,
120-
{
121-
type Elem = &'a T;
122-
123-
fn len(&self) -> usize {
124-
<[T]>::len(self)
125-
}
126-
127-
#[cfg(feature = "concurrent")]
128-
fn split_at(self, at: usize) -> (Self, Self) {
129-
let (a, b) = self.split_at(at);
130-
131-
(a, b)
132-
}
133-
}
134-
13531
pub trait ParallelExt: Parallel {
13632
/// Invoke `op` in parallel, if `swc_ecma_utils` is compiled with
13733
/// concurrent feature enabled and `nodes.len()` is bigger than threshold.

Diff for: crates/swc_parallel/Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ version = "1.0.1"
1212
default = ["parallel"]
1313
# Make it really parallel
1414
parallel = ["chili"]
15+
# Alias for parallel, just for CI. Do not use it if you are not working on SWC.
16+
concurrent = ["parallel"]
1517

1618
[dependencies]
1719
chili = { workspace = true, optional = true }
1820
once_cell = { workspace = true }
21+
22+
[dev-dependencies]
23+
hstr = { workspace = true }
24+
scoped-tls = { workspace = true }

Diff for: crates/swc_parallel/src/items.rs

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
use self::private::Sealed;
2+
3+
mod private {
4+
pub trait Sealed {}
5+
6+
impl<T> Sealed for Vec<T> {}
7+
impl<T> Sealed for &mut Vec<T> {}
8+
impl<T> Sealed for &mut [T] {}
9+
impl<T> Sealed for &[T] {}
10+
}
11+
pub trait IntoItems: Sealed {
12+
type Elem;
13+
type Items: Items<Elem = Self::Elem>;
14+
15+
fn into_items(self) -> Self::Items;
16+
}
17+
18+
impl<T, I> IntoItems for I
19+
where
20+
I: Items<Elem = T>,
21+
{
22+
type Elem = T;
23+
type Items = I;
24+
25+
fn into_items(self) -> Self::Items {
26+
self
27+
}
28+
}
29+
30+
impl<'a, T> IntoItems for &'a mut Vec<T>
31+
where
32+
T: Send + Sync,
33+
{
34+
type Elem = &'a mut T;
35+
type Items = &'a mut [T];
36+
37+
fn into_items(self) -> Self::Items {
38+
self
39+
}
40+
}
41+
42+
/// This is considered as a private type and it's NOT A PUBLIC API.
43+
#[allow(clippy::len_without_is_empty)]
44+
pub trait Items: Sized + IntoIterator<Item = Self::Elem> + Send + Sealed {
45+
type Elem: Send + Sync;
46+
47+
fn len(&self) -> usize;
48+
49+
fn split_at(self, idx: usize) -> (Self, Self);
50+
}
51+
52+
impl<T> Items for Vec<T>
53+
where
54+
T: Send + Sync,
55+
{
56+
type Elem = T;
57+
58+
fn len(&self) -> usize {
59+
Vec::len(self)
60+
}
61+
62+
fn split_at(mut self, at: usize) -> (Self, Self) {
63+
let b = self.split_off(at);
64+
65+
(self, b)
66+
}
67+
}
68+
69+
impl<'a, T> Items for &'a mut [T]
70+
where
71+
T: Send + Sync,
72+
{
73+
type Elem = &'a mut T;
74+
75+
fn len(&self) -> usize {
76+
<[T]>::len(self)
77+
}
78+
79+
fn split_at(self, at: usize) -> (Self, Self) {
80+
let (a, b) = self.split_at_mut(at);
81+
82+
(a, b)
83+
}
84+
}
85+
86+
impl<'a, T> Items for &'a [T]
87+
where
88+
T: Send + Sync,
89+
{
90+
type Elem = &'a T;
91+
92+
fn len(&self) -> usize {
93+
<[T]>::len(self)
94+
}
95+
96+
fn split_at(self, at: usize) -> (Self, Self) {
97+
let (a, b) = self.split_at(at);
98+
99+
(a, b)
100+
}
101+
}
102+
//

Diff for: crates/swc_parallel/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
use std::{cell::RefCell, mem::transmute};
44

5+
pub mod items;
6+
57
#[derive(Default)]
68
pub struct MaybeScope<'a>(ScopeLike<'a>);
79

0 commit comments

Comments
 (0)