Skip to content

Commit

Permalink
fix build
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Jan 6, 2025
1 parent a22fb77 commit 59d9b23
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion crates/swc_parallel/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
#![cfg_attr(not(feature = "parallel"), allow(unused_variables))]

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

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

enum ScopeLike<'a> {
Scope(Scope<'a>),
#[cfg(feature = "parallel")]
Global(Option<chili::Scope<'a>>),
}

impl Default for ScopeLike<'_> {
fn default() -> Self {
ScopeLike::Global(None)
#[cfg(feature = "parallel")]
{
ScopeLike::Global(None)
}

#[cfg(not(feature = "parallel"))]
{
ScopeLike::Scope(Scope(std::marker::PhantomData))
}
}
}

Expand All @@ -26,19 +37,25 @@ impl<'a> MaybeScope<'a> {
where
F: FnOnce(Scope<'a>) -> R,
{
#[cfg(feature = "parallel")]
let scope: &mut chili::Scope = match &mut self.0 {
ScopeLike::Scope(scope) => unsafe {
transmute::<&mut chili::Scope, &mut chili::Scope>(&mut scope.0)
},
#[cfg(feature = "parallel")]
ScopeLike::Global(global_scope) => {
let scope = global_scope.get_or_insert_with(|| chili::Scope::global());

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

#[cfg(feature = "parallel")]
let scope = Scope(scope);

#[cfg(not(feature = "parallel"))]
let scope = Scope(std::marker::PhantomData);

f(scope)
}
}
Expand Down Expand Up @@ -109,6 +126,7 @@ where
RA: Send,
RB: Send,
{
#[cfg(feature = "parallel")]
let (ra, rb) = scope.0.join(
|scope| {
let scope = Scope(unsafe { transmute::<&mut chili::Scope, &mut chili::Scope>(scope) });
Expand All @@ -122,5 +140,11 @@ where
},
);

#[cfg(not(feature = "parallel"))]
let (ra, rb) = (
oper_a(Scope(std::marker::PhantomData)),
oper_b(Scope(std::marker::PhantomData)),
);

(ra, rb)
}

0 comments on commit 59d9b23

Please sign in to comment.