Skip to content

Commit ee978ee

Browse files
committed
persist and compare errors and panics
1 parent e04b09a commit ee978ee

File tree

4 files changed

+74
-59
lines changed

4 files changed

+74
-59
lines changed

turbopack/crates/turbo-tasks-backend/src/backend/mod.rs

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use std::{
1616
thread::available_parallelism,
1717
};
1818

19-
use anyhow::{bail, Result};
19+
use anyhow::{anyhow, bail, Result};
2020
use auto_hash_map::{AutoMap, AutoSet};
2121
use parking_lot::{Condvar, Mutex};
2222
use rustc_hash::{FxHashMap, FxHashSet, FxHasher};
@@ -560,38 +560,46 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
560560

561561
if let Some(output) = get!(task, Output) {
562562
let result = match output {
563-
OutputValue::Cell(cell) => Some(Ok(Ok(RawVc::TaskCell(cell.task, cell.cell)))),
564-
OutputValue::Output(task) => Some(Ok(Ok(RawVc::TaskOutput(*task)))),
565-
OutputValue::Error | OutputValue::Panic => {
566-
get!(task, Error).map(|error| Err(error.clone().into()))
563+
OutputValue::Cell(cell) => Ok(Ok(RawVc::TaskCell(cell.task, cell.cell))),
564+
OutputValue::Output(task) => Ok(Ok(RawVc::TaskOutput(*task))),
565+
OutputValue::Error(error) => {
566+
let err: anyhow::Error = error.clone().into();
567+
Err(err.context(format!(
568+
"Execution of {} failed",
569+
ctx.get_task_description(task_id)
570+
)))
571+
}
572+
OutputValue::Panic(Some(panic)) => Err(anyhow!(
573+
"Panic in {}: {}",
574+
ctx.get_task_description(task_id),
575+
panic
576+
)),
577+
OutputValue::Panic(None) => {
578+
Err(anyhow!("Panic in {}", ctx.get_task_description(task_id)))
567579
}
568580
};
569-
if let Some(result) = result {
570-
if self.should_track_dependencies() {
571-
if let Some(reader) = reader {
572-
let _ = task.add(CachedDataItem::OutputDependent {
573-
task: reader,
581+
if self.should_track_dependencies() {
582+
if let Some(reader) = reader {
583+
let _ = task.add(CachedDataItem::OutputDependent {
584+
task: reader,
585+
value: (),
586+
});
587+
drop(task);
588+
589+
let mut reader_task = ctx.task(reader, TaskDataCategory::Data);
590+
if reader_task
591+
.remove(&CachedDataItemKey::OutdatedOutputDependency { target: task_id })
592+
.is_none()
593+
{
594+
let _ = reader_task.add(CachedDataItem::OutputDependency {
595+
target: task_id,
574596
value: (),
575597
});
576-
drop(task);
577-
578-
let mut reader_task = ctx.task(reader, TaskDataCategory::Data);
579-
if reader_task
580-
.remove(&CachedDataItemKey::OutdatedOutputDependency {
581-
target: task_id,
582-
})
583-
.is_none()
584-
{
585-
let _ = reader_task.add(CachedDataItem::OutputDependency {
586-
target: task_id,
587-
value: (),
588-
});
589-
}
590598
}
591599
}
592-
593-
return result;
594600
}
601+
602+
return result;
595603
}
596604

597605
let reader_desc = reader.map(|r| self.get_task_desc_fn(r));

turbopack/crates/turbo-tasks-backend/src/backend/operation/update_output.rs

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::{borrow::Cow, mem::take};
22

3-
use anyhow::{anyhow, Result};
3+
use anyhow::Result;
44
use serde::{Deserialize, Serialize};
55
use turbo_tasks::{util::SharedError, RawVc, TaskId};
66

@@ -65,7 +65,6 @@ impl UpdateOutputOperation {
6565
.then(|| new_children.iter().copied().collect())
6666
.unwrap_or_default();
6767

68-
let old_error = task.remove(&CachedDataItemKey::Error {});
6968
let current_output = get!(task, Output);
7069
let output_value = match output {
7170
Ok(Ok(RawVc::TaskOutput(output_task_id))) => {
@@ -95,23 +94,20 @@ impl UpdateOutputOperation {
9594
panic!("LocalOutput must not be output of a task");
9695
}
9796
Ok(Err(err)) => {
98-
task.insert(CachedDataItem::Error {
99-
value: SharedError::new(err.context(format!(
100-
"Execution of {} failed",
101-
ctx.get_task_description(task_id)
102-
))),
103-
});
104-
OutputValue::Error
97+
if let Some(OutputValue::Error(old_error)) = current_output {
98+
if old_error.eq_stack(&err) {
99+
return;
100+
}
101+
}
102+
OutputValue::Error(SharedError::new(err))
105103
}
106104
Err(panic) => {
107-
task.insert(CachedDataItem::Error {
108-
value: SharedError::new(anyhow!(
109-
"Panic in {}: {:?}",
110-
ctx.get_task_description(task_id),
111-
panic
112-
)),
113-
});
114-
OutputValue::Panic
105+
if let Some(OutputValue::Panic(old_panic)) = current_output {
106+
if old_panic.as_deref() == panic.as_deref() {
107+
return;
108+
}
109+
}
110+
OutputValue::Panic(panic.map(|s| s.into()))
115111
}
116112
};
117113
let old_content = task.insert(CachedDataItem::Output {
@@ -137,7 +133,6 @@ impl UpdateOutputOperation {
137133

138134
drop(task);
139135
drop(old_content);
140-
drop(old_error);
141136

142137
UpdateOutputOperation::MakeDependentTasksDirty {
143138
#[cfg(feature = "trace_task_dirty")]

turbopack/crates/turbo-tasks-backend/src/data.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use std::cmp::Ordering;
22

33
use rustc_hash::FxHashSet;
44
use serde::{Deserialize, Serialize};
5+
use turbo_rcstr::RcStr;
56
use turbo_tasks::{
67
event::{Event, EventListener},
78
registry,
@@ -52,20 +53,20 @@ pub struct CollectiblesRef {
5253
pub collectible_type: TraitTypeId,
5354
}
5455

55-
#[derive(Debug, Copy, Clone, PartialEq, Eq, Serialize, Deserialize)]
56+
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
5657
pub enum OutputValue {
5758
Cell(CellRef),
5859
Output(TaskId),
59-
Error,
60-
Panic,
60+
Error(SharedError),
61+
Panic(Option<RcStr>),
6162
}
6263
impl OutputValue {
6364
fn is_transient(&self) -> bool {
6465
match self {
6566
OutputValue::Cell(cell) => cell.task.is_transient(),
6667
OutputValue::Output(task) => task.is_transient(),
67-
OutputValue::Error => false,
68-
OutputValue::Panic => false,
68+
OutputValue::Error(_) => false,
69+
OutputValue::Panic(_) => false,
6970
}
7071
}
7172
}
@@ -482,12 +483,6 @@ pub enum CachedDataItem {
482483
target: CollectiblesRef,
483484
value: (),
484485
},
485-
486-
// Transient Error State
487-
#[serde(skip)]
488-
Error {
489-
value: SharedError,
490-
},
491486
}
492487

493488
impl CachedDataItem {
@@ -523,7 +518,6 @@ impl CachedDataItem {
523518
CachedDataItem::OutdatedOutputDependency { .. } => false,
524519
CachedDataItem::OutdatedCellDependency { .. } => false,
525520
CachedDataItem::OutdatedCollectiblesDependency { .. } => false,
526-
CachedDataItem::Error { .. } => false,
527521
}
528522
}
529523

@@ -578,7 +572,6 @@ impl CachedDataItem {
578572
| Self::OutdatedCollectiblesDependency { .. }
579573
| Self::InProgressCell { .. }
580574
| Self::InProgress { .. }
581-
| Self::Error { .. }
582575
| Self::Activeness { .. } => TaskDataCategory::All,
583576
}
584577
}
@@ -617,7 +610,6 @@ impl CachedDataItemKey {
617610
CachedDataItemKey::OutdatedOutputDependency { .. } => false,
618611
CachedDataItemKey::OutdatedCellDependency { .. } => false,
619612
CachedDataItemKey::OutdatedCollectiblesDependency { .. } => false,
620-
CachedDataItemKey::Error { .. } => false,
621613
}
622614
}
623615

@@ -660,7 +652,6 @@ impl CachedDataItemType {
660652
| Self::OutdatedCollectiblesDependency { .. }
661653
| Self::InProgressCell { .. }
662654
| Self::InProgress { .. }
663-
| Self::Error { .. }
664655
| Self::Activeness { .. } => TaskDataCategory::All,
665656
}
666657
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,27 @@ impl SharedError {
3232
inner: Arc::new(err),
3333
}
3434
}
35+
36+
pub fn eq_stack(&self, other: &anyhow::Error) -> bool {
37+
if self.to_string() != other.to_string() {
38+
return false;
39+
}
40+
let mut source = self.source();
41+
let mut other_source = other.source();
42+
loop {
43+
if source.is_none() && other_source.is_none() {
44+
return true;
45+
}
46+
let (Some(source_err), Some(other_source_err)) = (source, other_source) else {
47+
return false;
48+
};
49+
if source_err.to_string() != other_source_err.to_string() {
50+
return false;
51+
}
52+
source = source_err.source();
53+
other_source = other_source_err.source();
54+
}
55+
}
3556
}
3657

3758
impl StdError for SharedError {

0 commit comments

Comments
 (0)