turbo_tasks/serialization_invalidation.rs
1use std::hash::Hash;
2
3use bincode::{Decode, Encode};
4use turbo_tasks_macros::NonLocalValue;
5
6use crate as turbo_tasks;
7use crate::{TaskId, manager::with_turbo_tasks, trace::TraceRawVcs};
8
9/// Allows a turbo-tasks value type to notify the backend that its serialized
10/// state has changed out-of-band (i.e. without going through the normal
11/// output-cell mechanism).
12///
13/// `invalidate` must always be called from within a turbo-tasks execution
14/// context (i.e. inside a `#[turbo_tasks::function]` body or a `State`
15/// mutation triggered from one), so `TURBO_TASKS` task-local is always
16/// available and we do not need to capture handles at construction time.
17#[derive(Clone, Hash, Eq, PartialEq, Encode, Decode, TraceRawVcs, NonLocalValue)]
18pub struct SerializationInvalidator {
19 task: TaskId,
20}
21
22impl SerializationInvalidator {
23 pub fn invalidate(&self) {
24 with_turbo_tasks(|tt| tt.invalidate_serialization(self.task));
25 }
26
27 /// The task whose serialized form should be re-emitted on the next
28 /// snapshot. Exposed so callers that already hold a `TurboTasksApi`
29 /// reference can fold the serialization-invalidation into a larger
30 /// batch without paying for another `with_turbo_tasks` lookup.
31 pub(crate) fn task(&self) -> TaskId {
32 self.task
33 }
34
35 pub(crate) fn new(task_id: TaskId) -> Self {
36 Self { task: task_id }
37 }
38}