Skip to content

Commit a2b7105

Browse files
authored
build(swc_parallel): Fix build on CI (#9844)
1 parent ff7cc27 commit a2b7105

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

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

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1+
#![cfg_attr(not(feature = "parallel"), allow(unused_variables))]
2+
13
use std::{cell::RefCell, mem::transmute};
24

35
#[derive(Default)]
46
pub struct MaybeScope<'a>(ScopeLike<'a>);
57

68
enum ScopeLike<'a> {
79
Scope(Scope<'a>),
10+
#[cfg(feature = "parallel")]
811
Global(Option<chili::Scope<'a>>),
912
}
1013

1114
impl Default for ScopeLike<'_> {
1215
fn default() -> Self {
13-
ScopeLike::Global(None)
16+
#[cfg(feature = "parallel")]
17+
{
18+
ScopeLike::Global(None)
19+
}
20+
21+
#[cfg(not(feature = "parallel"))]
22+
{
23+
ScopeLike::Scope(Scope(std::marker::PhantomData))
24+
}
1425
}
1526
}
1627

@@ -26,19 +37,25 @@ impl<'a> MaybeScope<'a> {
2637
where
2738
F: FnOnce(Scope<'a>) -> R,
2839
{
40+
#[cfg(feature = "parallel")]
2941
let scope: &mut chili::Scope = match &mut self.0 {
3042
ScopeLike::Scope(scope) => unsafe {
3143
transmute::<&mut chili::Scope, &mut chili::Scope>(&mut scope.0)
3244
},
45+
#[cfg(feature = "parallel")]
3346
ScopeLike::Global(global_scope) => {
3447
let scope = global_scope.get_or_insert_with(|| chili::Scope::global());
3548

3649
unsafe { transmute::<&mut chili::Scope, &mut chili::Scope>(scope) }
3750
}
3851
};
3952

53+
#[cfg(feature = "parallel")]
4054
let scope = Scope(scope);
4155

56+
#[cfg(not(feature = "parallel"))]
57+
let scope = Scope(std::marker::PhantomData);
58+
4259
f(scope)
4360
}
4461
}
@@ -109,6 +126,7 @@ where
109126
RA: Send,
110127
RB: Send,
111128
{
129+
#[cfg(feature = "parallel")]
112130
let (ra, rb) = scope.0.join(
113131
|scope| {
114132
let scope = Scope(unsafe { transmute::<&mut chili::Scope, &mut chili::Scope>(scope) });
@@ -122,5 +140,11 @@ where
122140
},
123141
);
124142

143+
#[cfg(not(feature = "parallel"))]
144+
let (ra, rb) = (
145+
oper_a(Scope(std::marker::PhantomData)),
146+
oper_b(Scope(std::marker::PhantomData)),
147+
);
148+
125149
(ra, rb)
126150
}

0 commit comments

Comments
 (0)