Unverified Commit 8bb30f2d authored by Luke Sandberg's avatar Luke Sandberg Committed by GitHub

[turbopack] drop TransientState (#92853)

It's dead
parent 9de87449
......@@ -101,7 +101,7 @@ pub use crate::{
read_ref::ReadRef,
serialization_invalidation::SerializationInvalidator,
spawn::{JoinHandle, block_for_future, block_in_place, spawn, spawn_blocking, spawn_thread},
state::{State, TransientState, parking_lot_mutex_bincode},
state::{State, parking_lot_mutex_bincode},
task::{
SharedReference, TypedSharedReference,
task_input::{EitherTaskInput, TaskInput},
......
......@@ -1949,7 +1949,7 @@ pub fn mark_invalidator() {
}
/// Marks the current task as stateful. This is used to indicate that the task
/// has interior mutability (e.g., via State or TransientState), which means
/// has interior mutability (e.g., via [`State`][crate::State]), which means
/// the task may produce different outputs even with the same inputs.
///
/// Only has an effect when the `verify_determinism` feature is enabled.
......
......@@ -82,7 +82,6 @@ macro_rules! impl_auto_marker_trait {
<<T as $crate::VcValueType>::Read as $crate::VcRead<T>>::Target: $trait
{}
unsafe impl<T: $trait> $trait for $crate::State<T> {}
unsafe impl<T: $trait> $trait for $crate::TransientState<T> {}
unsafe impl<T: $trait> $trait for $crate::TransientValue<T> {}
unsafe impl<T: $trait> $trait for $crate::TransientInstance<T> {}
unsafe impl $trait for $crate::event::Event {}
......
......@@ -12,8 +12,7 @@ use tracing::trace_span;
use crate::{
Invalidator, OperationValue, SerializationInvalidator, get_invalidator,
get_serialization_invalidator, manager::with_turbo_tasks, mark_session_dependent,
mark_stateful, trace::TraceRawVcs,
get_serialization_invalidator, manager::with_turbo_tasks, trace::TraceRawVcs,
};
#[derive(Encode, Decode)]
......@@ -291,109 +290,3 @@ impl<T: PartialEq> State<T> {
self.serialization_invalidator.invalidate();
}
}
#[derive(Encode, Decode)]
#[bincode(bounds = "")]
pub struct TransientState<T> {
#[bincode(skip, default = "default_transient_state_inner")]
inner: Mutex<StateInner<Option<T>>>,
}
fn default_transient_state_inner<T>() -> Mutex<StateInner<Option<T>>> {
Mutex::new(StateInner::new(None))
}
impl<T: Debug> Debug for TransientState<T> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("TransientState")
.field("value", &self.inner.lock().value)
.finish()
}
}
impl<T: TraceRawVcs> TraceRawVcs for TransientState<T> {
fn trace_raw_vcs(&self, trace_context: &mut crate::trace::TraceRawVcsContext) {
self.inner.lock().value.trace_raw_vcs(trace_context);
}
}
impl<T> Default for TransientState<T> {
fn default() -> Self {
// Need to be explicit to ensure marking as stateful.
Self::new()
}
}
impl<T> PartialEq for TransientState<T> {
fn eq(&self, _other: &Self) -> bool {
false
}
}
impl<T> Eq for TransientState<T> {}
impl<T> TransientState<T> {
pub fn new() -> Self {
mark_stateful();
Self {
inner: Mutex::new(StateInner::new(None)),
}
}
/// Gets the current value of the state. The current task will be registered
/// as dependency of the state and will be invalidated when the state
/// changes.
pub fn get(&self) -> StateRef<'_, Option<T>> {
mark_session_dependent();
let invalidator = get_invalidator();
let mut inner = self.inner.lock();
if let Some(invalidator) = invalidator {
inner.add_invalidator(invalidator);
}
StateRef {
serialization_invalidator: None,
inner,
mutated: false,
}
}
/// Gets the current value of the state. Untracked.
pub fn get_untracked(&self) -> StateRef<'_, Option<T>> {
let inner = self.inner.lock();
StateRef {
serialization_invalidator: None,
inner,
mutated: false,
}
}
/// Sets the current state without comparing it with the old value. This
/// should only be used if one is sure that the value has changed.
pub fn set_unconditionally(&self, value: T) {
let mut inner = self.inner.lock();
inner.set_unconditionally(Some(value));
}
/// Updates the current state with the `update` function. The `update`
/// function need to return `true` when the value was modified. Exposing
/// the current value from the `update` function is not allowed and will
/// result in incorrect cache invalidation.
pub fn update_conditionally(&self, update: impl FnOnce(&mut Option<T>) -> bool) {
let mut inner = self.inner.lock();
inner.update_conditionally(update);
}
}
impl<T: PartialEq> TransientState<T> {
/// Update the current state when the `value` is different from the current
/// value. `T` must implement [PartialEq] for this to work.
pub fn set(&self, value: T) {
let mut inner = self.inner.lock();
inner.set(Some(value));
}
/// Unset the current value.
pub fn unset(&self) {
let mut inner = self.inner.lock();
inner.set(None);
}
}
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