Unverified Commit 6e894cfc authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

Turbopack: Make `ReadVcFuture::strongly_consistent` private (#90843)

This method is needed with `turbo-tasks` to implement `OperationVc`, but exposing it to other crates turns it into a footgun, because it allows you to attempt to read a `Vc` or `ResolvedVc` with strong consistency, which doesn't have a well-defined meaning.
parent 8e7d186f
...@@ -2253,43 +2253,40 @@ impl Project { ...@@ -2253,43 +2253,40 @@ impl Project {
} }
} }
/// Get HMR version for the specified target.
#[turbo_tasks::function]
async fn hmr_version(
self: Vc<Self>,
chunk_name: RcStr,
target: HmrTarget,
) -> Result<Vc<Box<dyn Version>>> {
let content = self.hmr_content(chunk_name, target).await?;
if let Some(content) = &*content {
Ok(content.version())
} else {
Ok(Vc::upcast(NotFoundVersion::new()))
}
}
/// Get the version state for an HMR session. Initialized with the first seen /// Get the version state for an HMR session. Initialized with the first seen
/// version in that session. /// version in that session.
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn hmr_version_state( pub async fn hmr_version_state(
self: Vc<Self>, self: ResolvedVc<Self>,
chunk_name: RcStr, chunk_name: RcStr,
target: HmrTarget, target: HmrTarget,
session: TransientInstance<()>, session: TransientInstance<()>,
) -> Result<Vc<VersionState>> { ) -> Result<Vc<VersionState>> {
let version = self.hmr_version(chunk_name, target);
// The session argument is important to avoid caching this function between // The session argument is important to avoid caching this function between
// sessions. // sessions.
let _ = session; let _ = session;
#[turbo_tasks::function(operation)]
async fn hmr_version_operation(
this: ResolvedVc<Project>,
chunk_name: RcStr,
target: HmrTarget,
) -> Result<Vc<Box<dyn Version>>> {
let content = this.hmr_content(chunk_name, target).await?;
if let Some(content) = &*content {
Ok(content.version())
} else {
Ok(Vc::upcast(NotFoundVersion::new()))
}
}
let version_op = hmr_version_operation(self, chunk_name, target);
// INVALIDATION: This is intentionally untracked to avoid invalidating this // INVALIDATION: This is intentionally untracked to avoid invalidating this
// function completely. We want to initialize the VersionState with the // function completely. We want to initialize the VersionState with the
// first seen version of the session. // first seen version of the session.
let state = VersionState::new( let state = VersionState::new(
version version_op
.into_trait_ref() .read_trait_strongly_consistent()
.strongly_consistent()
.untracked() .untracked()
.await?, .await?,
) )
......
...@@ -7,8 +7,8 @@ use serde::{Deserialize, Serialize}; ...@@ -7,8 +7,8 @@ use serde::{Deserialize, Serialize};
pub use turbo_tasks_macros::OperationValue; pub use turbo_tasks_macros::OperationValue;
use crate::{ use crate::{
CollectiblesSource, IntoTraitRef, RawVc, ReadVcFuture, ResolvedVc, TaskInput, TraitRef, CollectiblesSource, IntoTraitRef, RawVc, ReadVcFuture, ResolvedVc, TaskInput, UpcastStrict, Vc,
UpcastStrict, Vc, VcValueTrait, VcValueType, marker_trait::impl_auto_marker_trait, VcValueTrait, VcValueTraitCast, VcValueType, marker_trait::impl_auto_marker_trait,
trace::TraceRawVcs, trace::TraceRawVcs,
}; };
...@@ -145,11 +145,11 @@ impl<T: ?Sized> OperationVc<T> { ...@@ -145,11 +145,11 @@ impl<T: ?Sized> OperationVc<T> {
/// consistent][crate::ReadConsistency::Strong] read of the value. /// consistent][crate::ReadConsistency::Strong] read of the value.
/// ///
/// This ensures that all internal tasks are finished before the read is returned. /// This ensures that all internal tasks are finished before the read is returned.
pub async fn read_trait_strongly_consistent(self) -> Result<TraitRef<T>> pub fn read_trait_strongly_consistent(self) -> ReadVcFuture<T, VcValueTraitCast<T>>
where where
T: VcValueTrait, T: VcValueTrait,
{ {
self.connect().into_trait_ref().strongly_consistent().await self.connect().into_trait_ref().strongly_consistent()
} }
} }
......
...@@ -161,7 +161,7 @@ where ...@@ -161,7 +161,7 @@ where
Cast: VcCast, Cast: VcCast,
{ {
/// Do not use this: Use [`OperationVc::read_strongly_consistent`] instead. /// Do not use this: Use [`OperationVc::read_strongly_consistent`] instead.
pub fn strongly_consistent(mut self) -> Self { pub(crate) fn strongly_consistent(mut self) -> Self {
self.raw = self.raw.strongly_consistent(); self.raw = self.raw.strongly_consistent();
self self
} }
......
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