Commit be6b69e5 authored by Tobias Koppers's avatar Tobias Koppers

Turbopack: more efficient hanging detection implementation when not enabled

use macros to avoid constructing notes and descriptions when not enabled.
This also avoids looking up the task type for every task when hanging detection is not enabled.
parent 53a46b39
...@@ -32,8 +32,10 @@ use turbo_tasks::{ ...@@ -32,8 +32,10 @@ use turbo_tasks::{
Backend, BackendJobId, CachedTaskType, CellContent, TaskExecutionSpec, TransientTaskRoot, Backend, BackendJobId, CachedTaskType, CellContent, TaskExecutionSpec, TransientTaskRoot,
TransientTaskType, TurboTasksExecutionError, TypedCellContent, TransientTaskType, TurboTasksExecutionError, TypedCellContent,
}, },
event::{Event, EventListener}, event::{Event, EventListener, event_note},
listen_event,
message_queue::TimingEvent, message_queue::TimingEvent,
new_event,
registry::{self, get_value_type_global_name}, registry::{self, get_value_type_global_name},
task_statistics::TaskStatisticsApi, task_statistics::TaskStatisticsApi,
trace::TraceRawVcs, trace::TraceRawVcs,
...@@ -256,9 +258,9 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -256,9 +258,9 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
snapshot_completed: Condvar::new(), snapshot_completed: Condvar::new(),
last_snapshot: AtomicU64::new(0), last_snapshot: AtomicU64::new(0),
stopping: AtomicBool::new(false), stopping: AtomicBool::new(false),
stopping_event: Event::new(|| "TurboTasksBackend::stopping_event".to_string()), stopping_event: new_event!(|| "TurboTasksBackend::stopping_event".to_string()),
idle_start_event: Event::new(|| "TurboTasksBackend::idle_start_event".to_string()), idle_start_event: new_event!(|| "TurboTasksBackend::idle_start_event".to_string()),
idle_end_event: Event::new(|| "TurboTasksBackend::idle_end_event".to_string()), idle_end_event: new_event!(|| "TurboTasksBackend::idle_end_event".to_string()),
#[cfg(feature = "verify_aggregation_graph")] #[cfg(feature = "verify_aggregation_graph")]
is_idle: AtomicBool::new(false), is_idle: AtomicBool::new(false),
task_statistics: TaskStatisticsApi::default(), task_statistics: TaskStatisticsApi::default(),
...@@ -448,39 +450,42 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -448,39 +450,42 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
let mut ctx = self.execute_context(turbo_tasks); let mut ctx = self.execute_context(turbo_tasks);
let mut task = ctx.task(task_id, TaskDataCategory::All); let mut task = ctx.task(task_id, TaskDataCategory::All);
fn listen_to_done_event<B: BackingStorage>( #[allow(dead_code, reason = "used for hanging detection")]
fn done_event_note<B: BackingStorage>(
this: &TurboTasksBackendInner<B>, this: &TurboTasksBackendInner<B>,
reader: Option<TaskId>, reader: Option<TaskId>,
done_event: &Event, ) -> impl Fn() -> String + Send + Sync + 'static {
) -> EventListener { let reader_desc = reader.map(|r| this.get_task_event_note(r));
let reader_desc = reader.map(|r| this.get_task_desc_fn(r)); move || {
done_event.listen_with_note(move || {
if let Some(reader_desc) = reader_desc.as_ref() { if let Some(reader_desc) = reader_desc.as_ref() {
format!("try_read_task_output from {}", reader_desc()) format!("try_read_task_output from {}", reader_desc())
} else { } else {
"try_read_task_output (untracked)".to_string() "try_read_task_output (untracked)".to_string()
} }
}) }
} }
fn check_in_progress<B: BackingStorage>( fn check_in_progress<B: BackingStorage>(
this: &TurboTasksBackendInner<B>, _this: &TurboTasksBackendInner<B>,
task: &impl TaskGuard, task: &impl TaskGuard,
reader: Option<TaskId>, _reader: Option<TaskId>,
ctx: &impl ExecuteContext<'_>, ctx: &impl ExecuteContext<'_>,
) -> Option<std::result::Result<std::result::Result<RawVc, EventListener>, anyhow::Error>> ) -> Option<std::result::Result<std::result::Result<RawVc, EventListener>, anyhow::Error>>
{ {
match get!(task, InProgress) { match get!(task, InProgress) {
Some(InProgressState::Scheduled { done_event, .. }) => { Some(InProgressState::Scheduled { done_event, .. }) => Some(Ok(Err(
Some(Ok(Err(listen_to_done_event(this, reader, done_event)))) listen_event!(done_event, done_event_note(_this, _reader)),
} ))),
Some(InProgressState::InProgress(box InProgressStateInner { Some(InProgressState::InProgress(box InProgressStateInner {
done, done,
done_event, done_event,
.. ..
})) => { })) => {
if !*done { if !*done {
Some(Ok(Err(listen_to_done_event(this, reader, done_event)))) Some(Ok(Err(listen_event!(
done_event,
done_event_note(_this, _reader)
))))
} else { } else {
None None
} }
...@@ -557,7 +562,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -557,7 +562,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
} }
get!(task, Activeness).unwrap() get!(task, Activeness).unwrap()
}; };
let listener = activeness.all_clean_event.listen_with_note(move || { let listener = listen_event!(activeness.all_clean_event, move || {
format!("try_read_task_output (strongly consistent) from {reader:?}") format!("try_read_task_output (strongly consistent) from {reader:?}")
}); });
drop(task); drop(task);
...@@ -612,19 +617,21 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -612,19 +617,21 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
return result; return result;
} }
let reader_desc = reader.map(|r| self.get_task_desc_fn(r)); let note = event_note!({
let note = move || { let reader_desc = reader.map(|r| self.get_task_event_note(r));
if let Some(reader_desc) = reader_desc.as_ref() { move || {
format!("try_read_task_output (recompute) from {}", reader_desc()) if let Some(reader_desc) = reader_desc.as_ref() {
} else { format!("try_read_task_output (recompute) from {}", reader_desc())
"try_read_task_output (recompute, untracked)".to_string() } else {
"try_read_task_output (recompute, untracked)".to_string()
}
} }
}; });
// Output doesn't exist. We need to schedule the task to compute it. // Output doesn't exist. We need to schedule the task to compute it.
let (item, listener) = CachedDataItem::new_scheduled_with_listener( let (item, listener) = CachedDataItem::new_scheduled_with_listener(
TaskExecutionReason::OutputNotAvailable, TaskExecutionReason::OutputNotAvailable,
self.get_task_desc_fn(task_id), self.get_task_event_note(task_id),
note, note,
); );
// It's not possible that the task is InProgress at this point. If it is InProgress { // It's not possible that the task is InProgress at this point. If it is InProgress {
...@@ -756,7 +763,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -756,7 +763,7 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
} else if !is_scheduled } else if !is_scheduled
&& task.add(CachedDataItem::new_scheduled( && task.add(CachedDataItem::new_scheduled(
TaskExecutionReason::CellNotAvailable, TaskExecutionReason::CellNotAvailable,
self.get_task_desc_fn(task_id), self.get_task_event_note(task_id),
)) ))
{ {
turbo_tasks.schedule(task_id); turbo_tasks.schedule(task_id);
...@@ -769,24 +776,26 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -769,24 +776,26 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
&self, &self,
task: &mut impl TaskGuard, task: &mut impl TaskGuard,
task_id: TaskId, task_id: TaskId,
reader: Option<TaskId>, _reader: Option<TaskId>,
cell: CellId, cell: CellId,
) -> (EventListener, bool) { ) -> (EventListener, bool) {
let reader_desc = reader.map(|r| self.get_task_desc_fn(r)); let _note = event_note!({
let note = move || { let reader_desc = _reader.map(|r| self.get_task_event_note(r));
if let Some(reader_desc) = reader_desc.as_ref() { move || {
format!("try_read_task_cell (in progress) from {}", reader_desc()) if let Some(reader_desc) = reader_desc.as_ref() {
} else { format!("try_read_task_cell (in progress) from {}", reader_desc())
"try_read_task_cell (in progress, untracked)".to_string() } else {
"try_read_task_cell (in progress, untracked)".to_string()
}
} }
}; });
if let Some(in_progress) = get!(task, InProgressCell { cell }) { if let Some(in_progress) = get!(task, InProgressCell { cell }) {
// Someone else is already computing the cell // Someone else is already computing the cell
let listener = in_progress.event.listen_with_note(note); let listener = listen_event!(in_progress.event, _note);
return (listener, false); return (listener, false);
} }
let in_progress = InProgressCellState::new(task_id, cell); let in_progress = InProgressCellState::new(task_id, cell);
let listener = in_progress.event.listen_with_note(note); let listener = listen_event!(in_progress.event, _note);
task.add_new(CachedDataItem::InProgressCell { task.add_new(CachedDataItem::InProgressCell {
cell, cell,
value: in_progress, value: in_progress,
...@@ -812,15 +821,16 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> { ...@@ -812,15 +821,16 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
None None
} }
// TODO feature flag that for hanging detection only fn get_task_event_note(&self, _task_id: TaskId) -> impl Fn() -> String + Send + Sync + 'static {
fn get_task_desc_fn(&self, task_id: TaskId) -> impl Fn() -> String + Send + Sync + 'static { event_note!({
let task_type = self.lookup_task_type(task_id); let task_type = self.lookup_task_type(_task_id);
move || { move || {
task_type.as_ref().map_or_else( task_type.as_ref().map_or_else(
|| format!("{task_id:?} transient"), || format!("{_task_id:?} transient"),
|task_type| format!("{task_id:?} {task_type}"), |task_type| format!("{_task_id:?} {task_type}"),
) )
} }
})
} }
fn snapshot(&self) -> Option<(Instant, bool)> { fn snapshot(&self) -> Option<(Instant, bool)> {
......
...@@ -1219,7 +1219,7 @@ impl AggregationUpdateQueue { ...@@ -1219,7 +1219,7 @@ impl AggregationUpdateQueue {
None None
}; };
if let Some(reason) = should_schedule { if let Some(reason) = should_schedule {
let description = ctx.get_task_desc_fn(task_id); let description = ctx.get_task_event_note(task_id);
if task.add(CachedDataItem::new_scheduled(reason, description)) { if task.add(CachedDataItem::new_scheduled(reason, description)) {
ctx.schedule(task_id); ctx.schedule(task_id);
} }
......
...@@ -27,7 +27,7 @@ impl ConnectChildOperation { ...@@ -27,7 +27,7 @@ impl ConnectChildOperation {
if !ctx.should_track_children() { if !ctx.should_track_children() {
let mut task = ctx.task(child_task_id, TaskDataCategory::All); let mut task = ctx.task(child_task_id, TaskDataCategory::All);
if !task.has_key(&CachedDataItemKey::Output {}) { if !task.has_key(&CachedDataItemKey::Output {}) {
let description = ctx.get_task_desc_fn(child_task_id); let description = ctx.get_task_event_note(child_task_id);
let should_schedule = task.add(CachedDataItem::new_scheduled( let should_schedule = task.add(CachedDataItem::new_scheduled(
TaskExecutionReason::Connect, TaskExecutionReason::Connect,
description, description,
...@@ -80,7 +80,7 @@ impl ConnectChildOperation { ...@@ -80,7 +80,7 @@ impl ConnectChildOperation {
let mut task = ctx.task(child_task_id, TaskDataCategory::All); let mut task = ctx.task(child_task_id, TaskDataCategory::All);
if !task.has_key(&CachedDataItemKey::Output {}) { if !task.has_key(&CachedDataItemKey::Output {}) {
let description = ctx.get_task_desc_fn(child_task_id); let description = ctx.get_task_event_note(child_task_id);
let should_schedule = task.add(CachedDataItem::new_scheduled( let should_schedule = task.add(CachedDataItem::new_scheduled(
TaskExecutionReason::Connect, TaskExecutionReason::Connect,
description, description,
......
...@@ -296,7 +296,7 @@ pub fn make_task_dirty_internal( ...@@ -296,7 +296,7 @@ pub fn make_task_dirty_internal(
}; };
if should_schedule { if should_schedule {
let description = ctx.get_task_desc_fn(task_id); let description = ctx.get_task_event_note(task_id);
if task.add(CachedDataItem::new_scheduled( if task.add(CachedDataItem::new_scheduled(
TaskExecutionReason::Invalidated, TaskExecutionReason::Invalidated,
description, description,
......
...@@ -60,7 +60,7 @@ pub trait ExecuteContext<'e>: Sized { ...@@ -60,7 +60,7 @@ pub trait ExecuteContext<'e>: Sized {
where where
T: Clone + Into<AnyOperation>; T: Clone + Into<AnyOperation>;
fn suspending_requested(&self) -> bool; fn suspending_requested(&self) -> bool;
fn get_task_desc_fn(&self, task_id: TaskId) -> impl Fn() -> String + Send + Sync + 'static; fn get_task_event_note(&self, task_id: TaskId) -> impl Fn() -> String + Send + Sync + 'static;
fn get_task_description(&self, task_id: TaskId) -> String; fn get_task_description(&self, task_id: TaskId) -> String;
fn should_track_children(&self) -> bool; fn should_track_children(&self) -> bool;
fn should_track_dependencies(&self) -> bool; fn should_track_dependencies(&self) -> bool;
...@@ -260,8 +260,8 @@ where ...@@ -260,8 +260,8 @@ where
self.backend.suspending_requested() self.backend.suspending_requested()
} }
fn get_task_desc_fn(&self, task_id: TaskId) -> impl Fn() -> String + Send + Sync + 'static { fn get_task_event_note(&self, task_id: TaskId) -> impl Fn() -> String + Send + Sync + 'static {
self.backend.get_task_desc_fn(task_id) self.backend.get_task_event_note(task_id)
} }
fn get_task_description(&self, task_id: TaskId) -> String { fn get_task_description(&self, task_id: TaskId) -> String {
......
...@@ -7,7 +7,7 @@ use turbo_tasks::{ ...@@ -7,7 +7,7 @@ use turbo_tasks::{
TypedSharedReference, ValueTypeId, TypedSharedReference, ValueTypeId,
backend::TurboTasksExecutionError, backend::TurboTasksExecutionError,
event::{Event, EventListener}, event::{Event, EventListener},
registry, listen_event, new_event, registry,
}; };
use crate::{ use crate::{
...@@ -89,12 +89,14 @@ pub struct ActivenessState { ...@@ -89,12 +89,14 @@ pub struct ActivenessState {
} }
impl ActivenessState { impl ActivenessState {
pub fn new(id: TaskId) -> Self { pub fn new(_id: TaskId) -> Self {
Self { Self {
active_counter: 0, active_counter: 0,
root_ty: None, root_ty: None,
active_until_clean: false, active_until_clean: false,
all_clean_event: Event::new(move || format!("ActivenessState::all_clean_event {id:?}")), all_clean_event: new_event!(move || format!(
"ActivenessState::all_clean_event {_id:?}"
)),
} }
} }
...@@ -534,9 +536,9 @@ transient_traits!(InProgressCellState); ...@@ -534,9 +536,9 @@ transient_traits!(InProgressCellState);
impl Eq for InProgressCellState {} impl Eq for InProgressCellState {}
impl InProgressCellState { impl InProgressCellState {
pub fn new(task_id: TaskId, cell: CellId) -> Self { pub fn new(_task_id: TaskId, _cell: CellId) -> Self {
InProgressCellState { InProgressCellState {
event: Event::new(move || format!("InProgressCellState::event ({task_id} {cell:?})")), event: new_event!(move || format!("InProgressCellState::event ({_task_id} {_cell:?})")),
} }
} }
} }
...@@ -725,11 +727,11 @@ impl CachedDataItem { ...@@ -725,11 +727,11 @@ impl CachedDataItem {
pub fn new_scheduled( pub fn new_scheduled(
reason: TaskExecutionReason, reason: TaskExecutionReason,
description: impl Fn() -> String + Sync + Send + 'static, _description: impl Fn() -> String + Sync + Send + 'static,
) -> Self { ) -> Self {
CachedDataItem::InProgress { CachedDataItem::InProgress {
value: InProgressState::Scheduled { value: InProgressState::Scheduled {
done_event: Event::new(move || format!("{} done_event", description())), done_event: new_event!(move || format!("{} done_event", _description())),
reason, reason,
}, },
} }
...@@ -737,11 +739,11 @@ impl CachedDataItem { ...@@ -737,11 +739,11 @@ impl CachedDataItem {
pub fn new_scheduled_with_listener( pub fn new_scheduled_with_listener(
reason: TaskExecutionReason, reason: TaskExecutionReason,
description: impl Fn() -> String + Sync + Send + 'static, _description: impl Fn() -> String + Sync + Send + 'static,
note: impl Fn() -> String + Sync + Send + 'static, _note: impl Fn() -> String + Sync + Send + 'static,
) -> (Self, EventListener) { ) -> (Self, EventListener) {
let done_event = Event::new(move || format!("{} done_event", description())); let done_event = new_event!(move || format!("{} done_event", _description()));
let listener = done_event.listen_with_note(note); let listener = listen_event!(done_event, _note);
( (
CachedDataItem::InProgress { CachedDataItem::InProgress {
value: InProgressState::Scheduled { done_event, reason }, value: InProgressState::Scheduled { done_event, reason },
......
...@@ -11,7 +11,7 @@ use criterion::{ ...@@ -11,7 +11,7 @@ use criterion::{
}; };
use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher}; use notify::{Config, RecommendedWatcher, RecursiveMode, Watcher};
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
use turbo_tasks::event::Event; use turbo_tasks::event::new_event;
use turbo_tasks_fs::rope::{Rope, RopeBuilder}; use turbo_tasks_fs::rope::{Rope, RopeBuilder};
fn bench_file_watching(c: &mut Criterion) { fn bench_file_watching(c: &mut Criterion) {
...@@ -32,7 +32,7 @@ fn bench_file_watching(c: &mut Criterion) { ...@@ -32,7 +32,7 @@ fn bench_file_watching(c: &mut Criterion) {
BenchmarkId::new("bench_file_watching", "change file"), BenchmarkId::new("bench_file_watching", "change file"),
move |b| { move |b| {
let (tx, rx) = channel(); let (tx, rx) = channel();
let event = Arc::new(Event::new(|| "test event".to_string())); let event = Arc::new(new_event!(|| "test event".to_string()));
let mut watcher = RecommendedWatcher::new(tx, Config::default()).unwrap(); let mut watcher = RecommendedWatcher::new(tx, Config::default()).unwrap();
watcher.watch(temp_path, RecursiveMode::Recursive).unwrap(); watcher.watch(temp_path, RecursiveMode::Recursive).unwrap();
......
...@@ -3,7 +3,7 @@ use std::{collections::hash_map::Entry, hash::Hash, marker::PhantomData}; ...@@ -3,7 +3,7 @@ use std::{collections::hash_map::Entry, hash::Hash, marker::PhantomData};
use parking_lot::Mutex; use parking_lot::Mutex;
use rustc_hash::FxHashMap; use rustc_hash::FxHashMap;
use serde::{Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer};
use turbo_tasks::event::Event; use turbo_tasks::{event::Event, new_event};
pub struct MutexMap<K> { pub struct MutexMap<K> {
map: Mutex<FxHashMap<K, Option<(Event, usize)>>>, map: Mutex<FxHashMap<K, Option<(Event, usize)>>>,
...@@ -30,7 +30,7 @@ impl<'a, K: Eq + Hash + Clone> MutexMap<K> { ...@@ -30,7 +30,7 @@ impl<'a, K: Eq + Hash + Clone> MutexMap<K> {
event.listen() event.listen()
} }
None => { None => {
let event = Event::new(|| "MutexMap".to_string()); let event = new_event!(|| "MutexMap".to_string());
let listener = event.listen(); let listener = event.listen();
*state = Some((event, 0)); *state = Some((event, 0));
listener listener
......
...@@ -20,6 +20,7 @@ use turbo_tasks::{ ...@@ -20,6 +20,7 @@ use turbo_tasks::{
backend::{CellContent, TaskCollectiblesMap, TypedCellContent}, backend::{CellContent, TaskCollectiblesMap, TypedCellContent},
event::{Event, EventListener}, event::{Event, EventListener},
message_queue::CompilationEvent, message_queue::CompilationEvent,
new_event,
test_helpers::with_turbo_tasks_for_testing, test_helpers::with_turbo_tasks_for_testing,
util::{SharedError, StaticOrArc}, util::{SharedError, StaticOrArc},
}; };
...@@ -51,7 +52,7 @@ impl VcStorage { ...@@ -51,7 +52,7 @@ impl VcStorage {
let i = { let i = {
let mut tasks = self.tasks.lock().unwrap(); let mut tasks = self.tasks.lock().unwrap();
let i = tasks.len(); let i = tasks.len();
tasks.push(Task::Spawned(Event::new(move || { tasks.push(Task::Spawned(new_event!(move || {
format!("Task({i})::event") format!("Task({i})::event")
}))); })));
i i
......
...@@ -22,6 +22,7 @@ use crate::{ ...@@ -22,6 +22,7 @@ use crate::{
emit, emit,
event::{Event, EventListener}, event::{Event, EventListener},
manager::turbo_tasks_future_scope, manager::turbo_tasks_future_scope,
new_event,
trace::TraceRawVcs, trace::TraceRawVcs,
util::SharedError, util::SharedError,
}; };
...@@ -85,7 +86,7 @@ impl EffectInstance { ...@@ -85,7 +86,7 @@ impl EffectInstance {
EffectState::NotStarted(_) => { EffectState::NotStarted(_) => {
let EffectState::NotStarted(inner) = std::mem::replace( let EffectState::NotStarted(inner) = std::mem::replace(
&mut *guard, &mut *guard,
EffectState::Started(Event::new(|| "Effect".to_string())), EffectState::Started(new_event!(|| "Effect".to_string())),
) else { ) else {
unreachable!(); unreachable!();
}; };
......
...@@ -27,30 +27,26 @@ pub struct Event { ...@@ -27,30 +27,26 @@ pub struct Event {
#[cfg(not(feature = "hanging_detection"))] #[cfg(not(feature = "hanging_detection"))]
impl Event { impl Event {
/// see [event_listener::Event]::new /// see [event_listener::Event]::new
#[allow(
clippy::new_without_default,
reason = "We don't want the Default trait to be consistent with the hanging_detection \
version"
)]
#[inline(always)] #[inline(always)]
pub fn new(_description: impl Fn() -> String + Sync + Send + 'static) -> Self { pub fn new() -> Self {
Self { Self {
event: event_listener::Event::new(), event: event_listener::Event::new(),
} }
} }
/// see [event_listener::Event]::listen /// see [event_listener::Event]::listen
#[inline(always)]
pub fn listen(&self) -> EventListener { pub fn listen(&self) -> EventListener {
EventListener { EventListener {
listener: self.event.listen(), listener: self.event.listen(),
} }
} }
/// see [event_listener::Event]::listen
pub fn listen_with_note(
&self,
_note: impl Fn() -> String + Sync + Send + 'static,
) -> EventListener {
EventListener {
listener: self.event.listen(),
}
}
/// pulls out the event listener, leaving a new, empty event in its place. /// pulls out the event listener, leaving a new, empty event in its place.
pub fn take(&mut self) -> Self { pub fn take(&mut self) -> Self {
Self { Self {
...@@ -74,7 +70,7 @@ impl Event { ...@@ -74,7 +70,7 @@ impl Event {
pub fn listen(&self) -> EventListener { pub fn listen(&self) -> EventListener {
EventListener { EventListener {
description: self.description.clone(), description: self.description.clone(),
note: Arc::new(|| String::new()), note: Arc::new(String::new),
future: Some(Box::pin(timeout( future: Some(Box::pin(timeout(
Duration::from_secs(10), Duration::from_secs(10),
self.event.listen(), self.event.listen(),
...@@ -210,3 +206,59 @@ impl Future for EventListener { ...@@ -210,3 +206,59 @@ impl Future for EventListener {
Poll::Ready(()) Poll::Ready(())
} }
} }
pub fn no_note() -> String {
String::new()
}
#[cfg(not(feature = "hanging_detection"))]
#[macro_export]
macro_rules! listen_event {
($self:expr, $note:expr) => {
$self.listen()
};
}
#[cfg(not(feature = "hanging_detection"))]
#[macro_export]
macro_rules! new_event {
($description:expr) => {
$crate::event::Event::new()
};
}
#[cfg(not(feature = "hanging_detection"))]
#[macro_export]
macro_rules! event_note {
($note:expr) => {
$crate::event::no_note
};
}
#[cfg(feature = "hanging_detection")]
#[macro_export]
macro_rules! listen_event {
($self:expr, $note:expr) => {
$self.listen_with_note($note)
};
}
#[cfg(feature = "hanging_detection")]
#[macro_export]
macro_rules! new_event {
($description:expr) => {
$crate::event::Event::new($description)
};
}
#[cfg(feature = "hanging_detection")]
#[macro_export]
macro_rules! event_note {
($note:expr) => {
$note
};
}
pub use event_note;
pub use listen_event;
pub use new_event;
...@@ -34,9 +34,11 @@ use crate::{ ...@@ -34,9 +34,11 @@ use crate::{
event::{Event, EventListener}, event::{Event, EventListener},
id::{BackendJobId, ExecutionId, LocalTaskId, TRANSIENT_TASK_BIT, TraitTypeId}, id::{BackendJobId, ExecutionId, LocalTaskId, TRANSIENT_TASK_BIT, TraitTypeId},
id_factory::IdFactoryWithReuse, id_factory::IdFactoryWithReuse,
listen_event,
macro_helpers::NativeFunction, macro_helpers::NativeFunction,
magic_any::MagicAny, magic_any::MagicAny,
message_queue::{CompilationEvent, CompilationEventQueue}, message_queue::{CompilationEvent, CompilationEventQueue},
new_event,
raw_vc::{CellId, RawVc}, raw_vc::{CellId, RawVc},
registry, registry,
serialization_invalidation::SerializationInvalidator, serialization_invalidation::SerializationInvalidator,
...@@ -507,10 +509,10 @@ impl<B: Backend + 'static> TurboTasks<B> { ...@@ -507,10 +509,10 @@ impl<B: Backend + 'static> TurboTasks<B> {
scheduled_tasks: AtomicUsize::new(0), scheduled_tasks: AtomicUsize::new(0),
start: Default::default(), start: Default::default(),
aggregated_update: Default::default(), aggregated_update: Default::default(),
event: Event::new(|| "TurboTasks::event".to_string()), event: new_event!(|| "TurboTasks::event".to_string()),
event_start: Event::new(|| "TurboTasks::event_start".to_string()), event_start: new_event!(|| "TurboTasks::event_start".to_string()),
event_foreground: Event::new(|| "TurboTasks::event_foreground".to_string()), event_foreground: new_event!(|| "TurboTasks::event_foreground".to_string()),
event_background: Event::new(|| "TurboTasks::event_background".to_string()), event_background: new_event!(|| "TurboTasks::event_background".to_string()),
program_start: Instant::now(), program_start: Instant::now(),
compilation_events: CompilationEventQueue::default(), compilation_events: CompilationEventQueue::default(),
}); });
...@@ -794,7 +796,7 @@ impl<B: Backend + 'static> TurboTasks<B> { ...@@ -794,7 +796,7 @@ impl<B: Backend + 'static> TurboTasks<B> {
.with(|gts| { .with(|gts| {
let mut gts_write = gts.write().unwrap(); let mut gts_write = gts.write().unwrap();
let local_task_id = gts_write.create_local_task(LocalTask::Scheduled { let local_task_id = gts_write.create_local_task(LocalTask::Scheduled {
done_event: Event::new({ done_event: new_event!({
move || format!("LocalTask({task_type})::done_event") move || format!("LocalTask({task_type})::done_event")
}), }),
}); });
...@@ -983,9 +985,7 @@ impl<B: Backend + 'static> TurboTasks<B> { ...@@ -983,9 +985,7 @@ impl<B: Backend + 'static> TurboTasks<B> {
aggregation: Duration, aggregation: Duration,
timeout: Duration, timeout: Duration,
) -> Option<UpdateInfo> { ) -> Option<UpdateInfo> {
let listener = self let listener = listen_event!(self.event, || "wait for update info".to_string());
.event
.listen_with_note(|| "wait for update info".to_string());
let wait_for_finish = { let wait_for_finish = {
let (update, reason_set) = &mut *self.aggregated_update.lock().unwrap(); let (update, reason_set) = &mut *self.aggregated_update.lock().unwrap();
if aggregation.is_zero() { if aggregation.is_zero() {
...@@ -1009,9 +1009,8 @@ impl<B: Backend + 'static> TurboTasks<B> { ...@@ -1009,9 +1009,8 @@ impl<B: Backend + 'static> TurboTasks<B> {
listener.await; listener.await;
} else { } else {
// wait for start, then wait for finish or timeout // wait for start, then wait for finish or timeout
let start_listener = self let start_listener =
.event_start listen_event!(self.event_start, || "wait for update info".to_string());
.listen_with_note(|| "wait for update info".to_string());
if self.currently_scheduled_tasks.load(Ordering::Acquire) == 0 { if self.currently_scheduled_tasks.load(Ordering::Acquire) == 0 {
start_listener.await; start_listener.await;
} else { } else {
...@@ -1029,7 +1028,7 @@ impl<B: Backend + 'static> TurboTasks<B> { ...@@ -1029,7 +1028,7 @@ impl<B: Backend + 'static> TurboTasks<B> {
() = tokio::time::sleep(aggregation) => { () = tokio::time::sleep(aggregation) => {
break; break;
} }
() = self.event.listen_with_note(|| "wait for update info".to_string()) => { () = listen_event!(self.event, || "wait for update info".to_string()) => {
// Resets the sleep // Resets the sleep
} }
} }
...@@ -1063,7 +1062,7 @@ impl<B: Backend + 'static> TurboTasks<B> { ...@@ -1063,7 +1062,7 @@ impl<B: Backend + 'static> TurboTasks<B> {
self.backend.stopping(self); self.backend.stopping(self);
self.stopped.store(true, Ordering::Release); self.stopped.store(true, Ordering::Release);
{ {
let listener = self.event.listen_with_note(|| "wait for stop".to_string()); let listener = listen_event!(self.event, || "wait for stop".to_string());
if self.currently_scheduled_tasks.load(Ordering::Acquire) != 0 { if self.currently_scheduled_tasks.load(Ordering::Acquire) != 0 {
listener.await; listener.await;
} }
...@@ -1096,7 +1095,7 @@ impl<B: Backend + 'static> TurboTasks<B> { ...@@ -1096,7 +1095,7 @@ impl<B: Backend + 'static> TurboTasks<B> {
TURBO_TASKS TURBO_TASKS
.scope(this.clone(), async move { .scope(this.clone(), async move {
while this.currently_scheduled_tasks.load(Ordering::Acquire) != 0 { while this.currently_scheduled_tasks.load(Ordering::Acquire) != 0 {
let listener = this.event.listen_with_note(|| { let listener = listen_event!(this.event, || {
"background job waiting for execution".to_string() "background job waiting for execution".to_string()
}); });
if this.currently_scheduled_tasks.load(Ordering::Acquire) != 0 { if this.currently_scheduled_tasks.load(Ordering::Acquire) != 0 {
......
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