Commit 7373a852 authored by Benjamin Woodruff's avatar Benjamin Woodruff

Address review comments

parent fc1ae3fa
...@@ -1468,9 +1468,8 @@ function loadNative(importPath?: string) { ...@@ -1468,9 +1468,8 @@ function loadNative(importPath?: string) {
const customBindingsPath = !!__INTERNAL_CUSTOM_TURBOPACK_BINDINGS const customBindingsPath = !!__INTERNAL_CUSTOM_TURBOPACK_BINDINGS
? require.resolve(__INTERNAL_CUSTOM_TURBOPACK_BINDINGS) ? require.resolve(__INTERNAL_CUSTOM_TURBOPACK_BINDINGS)
: null : null
const customBindings: RawBindings = !!__INTERNAL_CUSTOM_TURBOPACK_BINDINGS const customBindings: RawBindings =
? require(__INTERNAL_CUSTOM_TURBOPACK_BINDINGS) customBindingsPath != null ? require(customBindingsPath!) : null
: null
let bindings: RawBindings = customBindings let bindings: RawBindings = customBindings
let bindingsPath = customBindingsPath let bindingsPath = customBindingsPath
let attempts: any[] = [] let attempts: any[] = []
...@@ -1481,8 +1480,8 @@ function loadNative(importPath?: string) { ...@@ -1481,8 +1480,8 @@ function loadNative(importPath?: string) {
try { try {
const bindingForTest = `${NEXT_TEST_NATIVE_DIR}/next-swc.${triple.platformArchABI}.node` const bindingForTest = `${NEXT_TEST_NATIVE_DIR}/next-swc.${triple.platformArchABI}.node`
// Use the binary directly to skip `pnpm pack` for testing as it's slow because of the large native binary. // Use the binary directly to skip `pnpm pack` for testing as it's slow because of the large native binary.
bindings = require(bindingForTest)
bindingsPath = require.resolve(bindingForTest) bindingsPath = require.resolve(bindingForTest)
bindings = require(bindingsPath)
infoLog( infoLog(
'next-swc build: local built @next/swc from NEXT_TEST_NATIVE_DIR' 'next-swc build: local built @next/swc from NEXT_TEST_NATIVE_DIR'
) )
......
...@@ -7,16 +7,16 @@ function getPoolId(cwd: string, filename: string) { ...@@ -7,16 +7,16 @@ function getPoolId(cwd: string, filename: string) {
} }
export async function runLoaderWorkerPool( export async function runLoaderWorkerPool(
binding: typeof import('./generated-native'), bindings: typeof import('./generated-native'),
bindingPath: string bindingPath: string
) { ) {
binding.registerWorkerScheduler( bindings.registerWorkerScheduler(
(creation) => { (creation) => {
const { const {
options: { filename, cwd }, options: { filename, cwd },
} = creation } = creation
let poolId = getPoolId(cwd, filename) const poolId = getPoolId(cwd, filename)
const worker = new Worker(/* turbopackIgnore: true*/ filename, { const worker = new Worker(/* turbopackIgnore: true*/ filename, {
workerData: { workerData: {
...@@ -39,12 +39,9 @@ export async function runLoaderWorkerPool( ...@@ -39,12 +39,9 @@ export async function runLoaderWorkerPool(
workerId, workerId,
} = termination } = termination
let poolId = getPoolId(cwd, filename) const poolId = getPoolId(cwd, filename)
const workers = loaderWorkers[poolId] const workers = loaderWorkers[poolId]
workers.get(workerId)?.terminate() workers.get(workerId)?.terminate()
workers.delete(workerId) workers.delete(workerId)
} }
) )
......
...@@ -240,12 +240,6 @@ impl AsRef<[u8]> for RcStr { ...@@ -240,12 +240,6 @@ impl AsRef<[u8]> for RcStr {
} }
} }
impl AsRef<str> for RcStr {
fn as_ref(&self) -> &str {
self.as_str()
}
}
impl From<RcStr> for BytesStr { impl From<RcStr> for BytesStr {
fn from(value: RcStr) -> Self { fn from(value: RcStr) -> Self {
Self::from_str_slice(value.as_str()) Self::from_str_slice(value.as_str())
......
...@@ -419,11 +419,11 @@ pub async fn get_evaluate_entries( ...@@ -419,11 +419,11 @@ pub async fn get_evaluate_entries(
asset_context: ResolvedVc<Box<dyn AssetContext>>, asset_context: ResolvedVc<Box<dyn AssetContext>>,
runtime_entries: Option<ResolvedVc<EvaluatableAssets>>, runtime_entries: Option<ResolvedVc<EvaluatableAssets>>,
) -> Result<Vc<EvaluateEntries>> { ) -> Result<Vc<EvaluateEntries>> {
#[cfg(all(feature = "process_pool", not(feature = "worker_pool")))] let runtime_module_path = if cfg!(all(feature = "process_pool", not(feature = "worker_pool"))) {
#[allow(unused_variables)] rcstr!("child_process/evaluate.ts")
let runtime_module_path = rcstr!("child_process/evaluate.ts"); } else {
#[cfg(feature = "worker_pool")] rcstr!("worker_thread/evaluate.ts")
let runtime_module_path = rcstr!("worker_thread/evaluate.ts"); };
let runtime_asset = asset_context let runtime_asset = asset_context
.process( .process(
...@@ -458,17 +458,18 @@ pub async fn get_evaluate_entries( ...@@ -458,17 +458,18 @@ pub async fn get_evaluate_entries(
let runtime_entries = { let runtime_entries = {
let mut entries = vec![]; let mut entries = vec![];
let global_module_path =
#[cfg(all(feature = "process_pool", not(feature = "worker_pool")))] if cfg!(all(feature = "process_pool", not(feature = "worker_pool"))) {
#[allow(unused_variables)] rcstr!("child_process/globals.ts")
let global_module_path = embed_file_path(rcstr!("child_process/globals.ts")); } else {
rcstr!("worker_thread/globals.ts")
#[cfg(feature = "worker_pool")] };
let global_module_path = embed_file_path(rcstr!("worker_thread/globals.ts"));
let globals_module = asset_context let globals_module = asset_context
.process( .process(
Vc::upcast(FileSource::new(global_module_path.owned().await?)), Vc::upcast(FileSource::new(
embed_file_path(global_module_path).owned().await?,
)),
ReferenceType::Internal(InnerAssets::empty().to_resolved().await?), ReferenceType::Internal(InnerAssets::empty().to_resolved().await?),
) )
.module(); .module();
......
...@@ -5,16 +5,13 @@ use tokio::sync::OwnedSemaphorePermit; ...@@ -5,16 +5,13 @@ use tokio::sync::OwnedSemaphorePermit;
pub enum AcquiredPermits { pub enum AcquiredPermits {
Idle { Idle {
// This is used for drop // This is used for drop
#[allow(dead_code)] _concurrency_permit: OwnedSemaphorePermit,
concurrency_permit: OwnedSemaphorePermit,
}, },
Fresh { Fresh {
// This is used for drop // This is used for drop
#[allow(dead_code)] _concurrency_permit: OwnedSemaphorePermit,
concurrency_permit: OwnedSemaphorePermit,
// This is used for drop // This is used for drop
#[allow(dead_code)] _bootup_permit: OwnedSemaphorePermit,
bootup_permit: OwnedSemaphorePermit,
}, },
} }
......
...@@ -603,7 +603,7 @@ impl ChildProcessPool { ...@@ -603,7 +603,7 @@ impl ChildProcessPool {
select! { select! {
idle_process_result = self.idle_processes.pop(&ACTIVE_POOLS) => { idle_process_result = self.idle_processes.pop(&ACTIVE_POOLS) => {
let process = idle_process_result.context("acquiring idle process permit")?; let process = idle_process_result.context("acquiring idle process permit")?;
Ok((process, AcquiredPermits::Idle { concurrency_permit })) Ok((process, AcquiredPermits::Idle { _concurrency_permit: concurrency_permit }))
}, },
bootup_permit = bootup => { bootup_permit = bootup => {
let bootup_permit = bootup_permit.context("acquiring bootup permit")?; let bootup_permit = bootup_permit.context("acquiring bootup permit")?;
...@@ -619,7 +619,7 @@ impl ChildProcessPool { ...@@ -619,7 +619,7 @@ impl ChildProcessPool {
} }
// Increase the allowed booting up processes // Increase the allowed booting up processes
self.bootup_semaphore.add_permits(1); self.bootup_semaphore.add_permits(1);
Ok((process, AcquiredPermits::Fresh { concurrency_permit, bootup_permit })) Ok((process, AcquiredPermits::Fresh { _concurrency_permit: concurrency_permit, _bootup_permit: bootup_permit }))
} }
} }
} }
......
...@@ -93,7 +93,12 @@ impl WorkerThreadPool { ...@@ -93,7 +93,12 @@ impl WorkerThreadPool {
{ {
let mut idle = self.state.idle_workers.lock(); let mut idle = self.state.idle_workers.lock();
if let Some(worker_id) = idle.pop() { if let Some(worker_id) = idle.pop() {
return Ok((worker_id, AcquiredPermits::Idle { concurrency_permit })); return Ok((
worker_id,
AcquiredPermits::Idle {
_concurrency_permit: concurrency_permit,
},
));
} }
} }
...@@ -102,7 +107,12 @@ impl WorkerThreadPool { ...@@ -102,7 +107,12 @@ impl WorkerThreadPool {
let mut waiters = self.state.waiters.lock(); let mut waiters = self.state.waiters.lock();
let mut idle = self.state.idle_workers.lock(); let mut idle = self.state.idle_workers.lock();
if let Some(worker_id) = idle.pop() { if let Some(worker_id) = idle.pop() {
return Ok((worker_id, AcquiredPermits::Idle { concurrency_permit })); return Ok((
worker_id,
AcquiredPermits::Idle {
_concurrency_permit: concurrency_permit,
},
));
} }
waiters.push(tx); waiters.push(tx);
} }
...@@ -117,7 +127,7 @@ impl WorkerThreadPool { ...@@ -117,7 +127,7 @@ impl WorkerThreadPool {
select! { select! {
worker_id = rx => { worker_id = rx => {
let worker_id = worker_id?; let worker_id = worker_id?;
Ok((worker_id, AcquiredPermits::Idle { concurrency_permit })) Ok((worker_id, AcquiredPermits::Idle { _concurrency_permit: concurrency_permit }))
} }
bootup_permit = bootup => { bootup_permit = bootup => {
let bootup_permit = bootup_permit.context("acquiring bootup permit")?; let bootup_permit = bootup_permit.context("acquiring bootup permit")?;
...@@ -132,7 +142,7 @@ impl WorkerThreadPool { ...@@ -132,7 +142,7 @@ impl WorkerThreadPool {
} }
self.bootup_semaphore.add_permits(1); self.bootup_semaphore.add_permits(1);
Ok((worker_id, AcquiredPermits::Fresh { concurrency_permit, bootup_permit })) Ok((worker_id, AcquiredPermits::Fresh { _concurrency_permit: concurrency_permit, _bootup_permit: bootup_permit }))
} }
} }
} }
...@@ -185,7 +195,7 @@ impl EvaluateOperation for WorkerThreadPool { ...@@ -185,7 +195,7 @@ impl EvaluateOperation for WorkerThreadPool {
} }
} }
})), })),
permits, _permits: permits,
channels, channels,
} }
}; };
......
...@@ -259,8 +259,7 @@ pub(crate) struct WorkerOperation { ...@@ -259,8 +259,7 @@ pub(crate) struct WorkerOperation {
pub(crate) worker_id: u32, pub(crate) worker_id: u32,
pub(crate) state: Arc<PoolState>, pub(crate) state: Arc<PoolState>,
pub(crate) on_drop: Option<Box<dyn FnOnce(u32) + Send + Sync>>, pub(crate) on_drop: Option<Box<dyn FnOnce(u32) + Send + Sync>>,
#[allow(dead_code)] pub(crate) _permits: AcquiredPermits,
pub(crate) permits: AcquiredPermits,
/// Pre-allocated channels for this task /// Pre-allocated channels for this task
pub(crate) channels: TaskChannels, pub(crate) channels: TaskChannels,
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment