Skip to content

Commit cb67358

Browse files
committed
review fixups
1 parent cfd8cd7 commit cb67358

File tree

7 files changed

+49
-29
lines changed

7 files changed

+49
-29
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use turbo_tasks::{
3131
TraitTypeId, TurboTasksBackendApi, ValueTypeId,
3232
backend::{
3333
Backend, CachedTaskType, CellContent, TaskExecutionSpec, TransientTaskRoot,
34-
TransientTaskType, TurboTasksExecutionError, TypedCellContent,
34+
TransientTaskType, TurboTasksExecutionError, TypedCellContent, VerificationMode,
3535
},
3636
event::{Event, EventListener},
3737
message_queue::TimingEvent,
@@ -2681,14 +2681,14 @@ impl<B: BackingStorage> TurboTasksBackendInner<B> {
26812681
task_id: TaskId,
26822682
cell: CellId,
26832683
content: CellContent,
2684-
never_equal: bool,
2684+
verification_mode: VerificationMode,
26852685
turbo_tasks: &dyn TurboTasksBackendApi<TurboTasksBackend<B>>,
26862686
) {
26872687
operation::UpdateCellOperation::run(
26882688
task_id,
26892689
cell,
26902690
content,
2691-
never_equal,
2691+
verification_mode,
26922692
self.execute_context(turbo_tasks),
26932693
);
26942694
}
@@ -3282,11 +3282,11 @@ impl<B: BackingStorage> Backend for TurboTasksBackend<B> {
32823282
task_id: TaskId,
32833283
cell: CellId,
32843284
content: CellContent,
3285-
never_equal: bool,
3285+
verification_mode: VerificationMode,
32863286
turbo_tasks: &dyn TurboTasksBackendApi<Self>,
32873287
) {
32883288
self.0
3289-
.update_task_cell(task_id, cell, content, never_equal, turbo_tasks);
3289+
.update_task_cell(task_id, cell, content, verification_mode, turbo_tasks);
32903290
}
32913291

32923292
fn mark_own_task_as_finished(

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ use std::mem::take;
22

33
use serde::{Deserialize, Serialize};
44
use smallvec::SmallVec;
5+
#[cfg(not(feature = "verify_determinism"))]
6+
use turbo_tasks::backend::VerificationMode;
57
use turbo_tasks::{CellId, TaskId, TypedSharedReference, backend::CellContent};
68

79
#[cfg(feature = "trace_task_dirty")]
@@ -44,8 +46,8 @@ impl UpdateCellOperation {
4446
task_id: TaskId,
4547
cell: CellId,
4648
content: CellContent,
47-
#[cfg(feature = "verify_determinism")] never_equal: bool,
48-
#[cfg(not(feature = "verify_determinism"))] _never_equal: bool,
49+
#[cfg(feature = "verify_determinism")] verification_mode: VerificationMode,
50+
#[cfg(not(feature = "verify_determinism"))] _verification_mode: VerificationMode,
4951
mut ctx: impl ExecuteContext,
5052
) {
5153
let content = if let CellContent(Some(new_content)) = content {
@@ -74,10 +76,13 @@ impl UpdateCellOperation {
7476

7577
// Check if this assumption holds.
7678
#[cfg(feature = "verify_determinism")]
77-
if !is_stateful && !never_equal && content.as_ref() != old_content {
79+
if !is_stateful
80+
&& matches!(verification_mode, VerificationMode::EqualityCheck)
81+
&& content.as_ref() != old_content
82+
{
7883
let task_description = ctx.get_task_description(task_id);
7984
let cell_type = turbo_tasks::registry::get_value_type(cell.type_id).global_name;
80-
println!(
85+
eprintln!(
8186
"Task {} updated cell #{} (type: {}) while recomputing",
8287
task_description, cell.index, cell_type
8388
);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use tokio::sync::mpsc::Receiver;
1818
use turbo_tasks::{
1919
CellId, ExecutionId, InvalidationReason, LocalTaskId, MagicAny, RawVc, ReadCellOptions,
2020
ReadOutputOptions, TaskId, TaskPersistence, TraitTypeId, TurboTasksApi, TurboTasksCallApi,
21-
backend::{CellContent, TaskCollectiblesMap, TypedCellContent},
21+
backend::{CellContent, TaskCollectiblesMap, TypedCellContent, VerificationMode},
2222
event::{Event, EventListener},
2323
message_queue::CompilationEvent,
2424
test_helpers::with_turbo_tasks_for_testing,
@@ -266,7 +266,7 @@ impl TurboTasksApi for VcStorage {
266266
task: TaskId,
267267
index: CellId,
268268
content: CellContent,
269-
_never_equal: bool,
269+
_verification_mode: VerificationMode,
270270
) {
271271
let mut map = self.cells.lock().unwrap();
272272
let cell = map.entry((task, index)).or_default();

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,11 @@ impl From<anyhow::Error> for TurboTasksExecutionError {
497497
}
498498
}
499499

500+
pub enum VerificationMode {
501+
EqualityCheck,
502+
Skip,
503+
}
504+
500505
pub trait Backend: Sync + Send {
501506
#[allow(unused_variables)]
502507
fn startup(&self, turbo_tasks: &dyn TurboTasksBackendApi<Self>) {}
@@ -621,7 +626,7 @@ pub trait Backend: Sync + Send {
621626
task: TaskId,
622627
index: CellId,
623628
content: CellContent,
624-
never_equal: bool,
629+
verification_mode: VerificationMode,
625630
turbo_tasks: &dyn TurboTasksBackendApi<Self>,
626631
);
627632

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use crate::{
2525
VcValueTrait, VcValueType,
2626
backend::{
2727
Backend, CachedTaskType, CellContent, TaskCollectiblesMap, TaskExecutionSpec,
28-
TransientTaskType, TurboTasksExecutionError, TypedCellContent,
28+
TransientTaskType, TurboTasksExecutionError, TypedCellContent, VerificationMode,
2929
},
3030
capture_future::CaptureFuture,
3131
event::{Event, EventListener},
@@ -160,7 +160,7 @@ pub trait TurboTasksApi: TurboTasksCallApi + Sync + Send {
160160
task: TaskId,
161161
index: CellId,
162162
content: CellContent,
163-
never_equal: bool,
163+
verification_mode: VerificationMode,
164164
);
165165
fn mark_own_task_as_finished(&self, task: TaskId);
166166
fn set_own_task_aggregation_number(&self, task: TaskId, aggregation_number: u32);
@@ -1365,10 +1365,10 @@ impl<B: Backend + 'static> TurboTasksApi for TurboTasks<B> {
13651365
task: TaskId,
13661366
index: CellId,
13671367
content: CellContent,
1368-
never_equal: bool,
1368+
verification_mode: VerificationMode,
13691369
) {
13701370
self.backend
1371-
.update_task_cell(task, index, content, never_equal, self);
1371+
.update_task_cell(task, index, content, verification_mode, self);
13721372
}
13731373

13741374
fn connect_task(&self, task: TaskId) {
@@ -1786,7 +1786,7 @@ impl CurrentCellRef {
17861786
self.current_task,
17871787
self.index,
17881788
CellContent(Some(update)),
1789-
false,
1789+
VerificationMode::EqualityCheck,
17901790
)
17911791
}
17921792
}
@@ -1869,7 +1869,7 @@ impl CurrentCellRef {
18691869
}
18701870

18711871
/// Unconditionally updates the content of the cell.
1872-
pub fn update<T>(&self, new_value: T, never_equal: bool)
1872+
pub fn update<T>(&self, new_value: T, verification_mode: VerificationMode)
18731873
where
18741874
T: VcValueType,
18751875
{
@@ -1880,7 +1880,7 @@ impl CurrentCellRef {
18801880
CellContent(Some(SharedReference::new(triomphe::Arc::new(
18811881
<T::Read as VcRead<T>>::value_to_repr(new_value),
18821882
)))),
1883-
never_equal,
1883+
verification_mode,
18841884
)
18851885
}
18861886

@@ -1892,9 +1892,13 @@ impl CurrentCellRef {
18921892
///
18931893
/// The [`SharedReference`] is expected to use the `<T::Read as
18941894
/// VcRead<T>>::Repr` type for its representation of the value.
1895-
pub fn update_with_shared_reference(&self, shared_ref: SharedReference, never_equal: bool) {
1895+
pub fn update_with_shared_reference(
1896+
&self,
1897+
shared_ref: SharedReference,
1898+
verification_mode: VerificationMode,
1899+
) {
18961900
let tt = turbo_tasks();
1897-
let update = if !never_equal {
1901+
let update = if matches!(verification_mode, VerificationMode::EqualityCheck) {
18981902
let content = tt
18991903
.read_own_task_cell(
19001904
self.current_task,
@@ -1920,7 +1924,7 @@ impl CurrentCellRef {
19201924
self.current_task,
19211925
self.index,
19221926
CellContent(Some(shared_ref)),
1923-
never_equal,
1927+
verification_mode,
19241928
)
19251929
}
19261930
}

turbopack/crates/turbo-tasks/src/vc/cell_mode.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
use std::{any::type_name, marker::PhantomData};
22

33
use super::{read::VcRead, traits::VcValueType};
4-
use crate::{RawVc, Vc, manager::find_cell_by_type, task::shared_reference::TypedSharedReference};
4+
use crate::{
5+
RawVc, Vc, backend::VerificationMode, manager::find_cell_by_type,
6+
task::shared_reference::TypedSharedReference,
7+
};
58

69
type VcReadTarget<T> = <<T as VcValueType>::Read as VcRead<T>>::Target;
710
type VcReadRepr<T> = <<T as VcValueType>::Read as VcRead<T>>::Repr;
@@ -37,7 +40,10 @@ where
3740
{
3841
fn cell(inner: VcReadTarget<T>) -> Vc<T> {
3942
let cell = find_cell_by_type(T::get_value_type_id());
40-
cell.update(<T::Read as VcRead<T>>::target_to_value(inner), true);
43+
cell.update(
44+
<T::Read as VcRead<T>>::target_to_value(inner),
45+
VerificationMode::Skip,
46+
);
4147
Vc {
4248
node: cell.into(),
4349
_t: PhantomData,
@@ -47,7 +53,7 @@ where
4753
fn raw_cell(content: TypedSharedReference) -> RawVc {
4854
debug_assert_repr::<T>(&content);
4955
let cell = find_cell_by_type(content.type_id);
50-
cell.update_with_shared_reference(content.reference, true);
56+
cell.update_with_shared_reference(content.reference, VerificationMode::Skip);
5157
cell.into()
5258
}
5359
}

turbopack/crates/turbopack-node/src/evaluate.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use serde_json::Value as JsonValue;
1616
use turbo_rcstr::rcstr;
1717
use turbo_tasks::{
1818
Completion, Effects, FxIndexMap, NonLocalValue, OperationVc, RawVc, ReadRef, ResolvedVc,
19-
TaskInput, TryJoinIterExt, Vc, VcValueType, duration_span, fxindexmap, get_effects,
20-
mark_finished, prevent_gc, trace::TraceRawVcs, util::SharedError,
19+
TaskInput, TryJoinIterExt, Vc, VcValueType, backend::VerificationMode, duration_span,
20+
fxindexmap, get_effects, mark_finished, prevent_gc, trace::TraceRawVcs, util::SharedError,
2121
};
2222
use turbo_tasks_bytes::{Bytes, Stream};
2323
use turbo_tasks_env::{EnvMap, ProcessEnv};
@@ -403,7 +403,7 @@ pub async fn custom_evaluate(
403403
let (sender, receiver) = unbounded();
404404
cell.update(
405405
JavaScriptEvaluation(JavaScriptStream::new_open(vec![], Box::new(receiver))),
406-
true,
406+
VerificationMode::Skip,
407407
);
408408
let initial = Mutex::new(Some(sender));
409409

@@ -423,7 +423,7 @@ pub async fn custom_evaluate(
423423
vec![],
424424
Box::new(receiver),
425425
)),
426-
true,
426+
VerificationMode::Skip,
427427
);
428428
sender
429429
}

0 commit comments

Comments
 (0)