Skip to content

Commit f6f5141

Browse files
committed
rename and fixes
1 parent d425b40 commit f6f5141

File tree

3 files changed

+21
-9
lines changed

3 files changed

+21
-9
lines changed

turbopack/crates/turbo-tasks-fs/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ use tracing::Instrument;
6060
use turbo_rcstr::RcStr;
6161
use turbo_tasks::{
6262
debug::ValueDebugFormat, effect, mark_session_dependent, mark_stateful, trace::TraceRawVcs,
63-
ApplyEffectContext, Completion, InvalidationReason, Invalidator, NonLocalValue, ReadRef,
63+
ApplyEffectsContext, Completion, InvalidationReason, Invalidator, NonLocalValue, ReadRef,
6464
ResolvedVc, ValueToString, Vc,
6565
};
6666
use turbo_tasks_hash::{
@@ -402,7 +402,7 @@ impl DiskFileSystemInner {
402402
}
403403

404404
async fn create_directory(self: &Arc<Self>, directory: &Path) -> Result<()> {
405-
let already_created = ApplyEffectContext::with_or_insert_with(
405+
let already_created = ApplyEffectsContext::with_or_insert_with(
406406
DiskFileSystemApplyContext::default,
407407
|fs_context| fs_context.created_directories.contains(directory),
408408
);
@@ -415,7 +415,7 @@ impl DiskFileSystemInner {
415415
path = display(directory.display())
416416
))
417417
.await?;
418-
ApplyEffectContext::with(|fs_context: &mut DiskFileSystemApplyContext| {
418+
ApplyEffectsContext::with(|fs_context: &mut DiskFileSystemApplyContext| {
419419
fs_context
420420
.created_directories
421421
.insert(directory.to_path_buf())

turbopack/crates/turbo-tasks/src/effect.rs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55
mem::replace,
66
panic,
77
pin::Pin,
8+
sync::Arc,
89
};
910

1011
use anyhow::{anyhow, Result};
@@ -98,10 +99,10 @@ impl EffectInstance {
9899
listener.await;
99100
}
100101
State::NotStarted(EffectInner { future }) => {
101-
let join_handle = tokio::spawn(
102+
let join_handle = tokio::spawn(ApplyEffectsContext::in_current_scope(
102103
turbo_tasks_future_scope(turbo_tasks::turbo_tasks(), future)
103104
.instrument(Span::current()),
104-
);
105+
));
105106
let result = match join_handle.await {
106107
Ok(Err(err)) => Err(SharedError::new(err)),
107108
Err(err) => {
@@ -279,15 +280,26 @@ impl Effects {
279280

280281
task_local! {
281282
/// The context of the current effects application.
282-
static APPLY_EFFECTS_CONTEXT: Mutex<ApplyEffectContext>;
283+
static APPLY_EFFECTS_CONTEXT: Arc<Mutex<ApplyEffectsContext>>;
283284
}
284285

285286
#[derive(Default)]
286-
pub struct ApplyEffectContext {
287+
pub struct ApplyEffectsContext {
287288
data: FxHashMap<TypeId, Box<dyn Any + Send + Sync>>,
288289
}
289290

290-
impl ApplyEffectContext {
291+
impl ApplyEffectsContext {
292+
fn in_current_scope<F: Future>(f: F) -> impl Future<Output = F::Output> {
293+
let current = Self::current();
294+
APPLY_EFFECTS_CONTEXT.scope(current, f)
295+
}
296+
297+
fn current() -> Arc<Mutex<Self>> {
298+
APPLY_EFFECTS_CONTEXT
299+
.try_with(|mutex| mutex.clone())
300+
.expect("No effect context found")
301+
}
302+
291303
fn with_context<T, F: FnOnce(&mut Self) -> T>(f: F) -> T {
292304
APPLY_EFFECTS_CONTEXT
293305
.try_with(|mutex| f(&mut mutex.lock()))

turbopack/crates/turbo-tasks/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ use auto_hash_map::AutoSet;
9090
pub use collectibles::CollectiblesSource;
9191
pub use completion::{Completion, Completions};
9292
pub use display::ValueToString;
93-
pub use effect::{apply_effects, effect, get_effects, ApplyEffectContext, Effects};
93+
pub use effect::{apply_effects, effect, get_effects, ApplyEffectsContext, Effects};
9494
pub use id::{
9595
ExecutionId, FunctionId, LocalTaskId, SessionId, TaskId, TraitTypeId, ValueTypeId,
9696
TRANSIENT_TASK_BIT,

0 commit comments

Comments
 (0)