Unverified Commit 3f804193 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

Turbopack: Remove old `Vc::try_resolve_*` methods in favor of the `ResolvedVc`…

Turbopack: Remove old `Vc::try_resolve_*` methods in favor of the `ResolvedVc` alternatives (#89696)

These `try_resolve_*` methods predate the introduction of the `ResolvedVc` type.

`ResolvedVc` has efficient synchronous `try_downcast`/`try_sidecast` functions, and there are only a few callsites that need to do this, so it makes more sense to split the resolution and the casting into to separate calls.
parent d87bcc61
...@@ -9392,7 +9392,6 @@ dependencies = [ ...@@ -9392,7 +9392,6 @@ dependencies = [
"serde_json", "serde_json",
"shrink-to-fit", "shrink-to-fit",
"smallvec", "smallvec",
"thiserror 1.0.69",
"tokio", "tokio",
"tokio-util", "tokio-util",
"tracing", "tracing",
......
...@@ -661,11 +661,11 @@ impl PageEndpoint { ...@@ -661,11 +661,11 @@ impl PageEndpoint {
if matches!( if matches!(
*this.pages_project.project().next_mode().await?, *this.pages_project.project().next_mode().await?,
NextMode::Development NextMode::Development
) && let Some(chunkable) = Vc::try_resolve_downcast(page_loader).await? ) && let Some(chunkable) = ResolvedVc::try_downcast(page_loader.to_resolved().await?)
{ {
return Ok(Vc::upcast(HmrEntryModule::new( return Ok(Vc::upcast(HmrEntryModule::new(
AssetIdent::from_path(this.page.await?.base_path.clone()), AssetIdent::from_path(this.page.await?.base_path.clone()),
chunkable, *chunkable,
))); )));
} }
Ok(page_loader) Ok(page_loader)
...@@ -678,23 +678,23 @@ impl PageEndpoint { ...@@ -678,23 +678,23 @@ impl PageEndpoint {
let client_module = self.client_module(); let client_module = self.client_module();
let client_main_module = this.pages_project.client_main_module(); let client_main_module = this.pages_project.client_main_module();
let Some(client_module) = let Some(client_module) = ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(
Vc::try_resolve_sidecast::<Box<dyn EvaluatableAsset>>(client_module).await? client_module.to_resolved().await?,
else { ) else {
bail!("expected an evaluateable asset"); bail!("expected an evaluateable asset");
}; };
let Some(client_main_module) = let Some(client_main_module) = ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(
Vc::try_resolve_sidecast::<Box<dyn EvaluatableAsset>>(client_main_module).await? client_main_module.to_resolved().await?,
else { ) else {
bail!("expected an evaluateable asset"); bail!("expected an evaluateable asset");
}; };
let evaluatable_assets = this let evaluatable_assets = this
.pages_project .pages_project
.client_runtime_entries() .client_runtime_entries()
.with_entry(client_main_module) .with_entry(*client_main_module)
.with_entry(client_module); .with_entry(*client_module);
Ok(evaluatable_assets) Ok(evaluatable_assets)
} }
......
...@@ -74,11 +74,9 @@ pub(crate) async fn create_server_actions_manifest( ...@@ -74,11 +74,9 @@ pub(crate) async fn create_server_actions_manifest(
) -> Result<Vc<ServerActionsManifest>> { ) -> Result<Vc<ServerActionsManifest>> {
let loader = let loader =
build_server_actions_loader(project_path, page_name.clone(), actions, rsc_asset_context); build_server_actions_loader(project_path, page_name.clone(), actions, rsc_asset_context);
let evaluable = Vc::try_resolve_sidecast::<Box<dyn EvaluatableAsset>>(loader) let evaluable =
.await? ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(loader.to_resolved().await?)
.context("loader module must be evaluatable")? .context("loader module must be evaluatable")?;
.to_resolved()
.await?;
let chunk_item = loader.as_chunk_item(module_graph, chunking_context); let chunk_item = loader.as_chunk_item(module_graph, chunking_context);
let manifest = build_manifest( let manifest = build_manifest(
...@@ -145,12 +143,12 @@ pub(crate) async fn build_server_actions_loader( ...@@ -145,12 +143,12 @@ pub(crate) async fn build_server_actions_loader(
.module(); .module();
let Some(placeable) = let Some(placeable) =
Vc::try_resolve_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(module).await? ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(module.to_resolved().await?)
else { else {
bail!("internal module must be evaluatable"); bail!("internal module must be evaluatable");
}; };
Ok(placeable) Ok(*placeable)
} }
/// Builds a manifest containing every action's hashed id, with an internal /// Builds a manifest containing every action's hashed id, with an internal
......
...@@ -46,7 +46,7 @@ pub async fn get_middleware_module( ...@@ -46,7 +46,7 @@ pub async fn get_middleware_module(
// Validate that the module has the required exports // Validate that the module has the required exports
if let Some(ecma_module) = if let Some(ecma_module) =
Vc::try_resolve_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(*userland_module).await? ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(userland_module)
{ {
let exports = ecma_module.get_exports().await?; let exports = ecma_module.get_exports().await?;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use indoc::formatdoc; use indoc::formatdoc;
use turbo_rcstr::RcStr; use turbo_rcstr::RcStr;
use turbo_tasks::Vc; use turbo_tasks::{ResolvedVc, Vc};
use turbo_tasks_fs::{File, FileContent, FileSystemPath}; use turbo_tasks_fs::{File, FileContent, FileSystemPath};
use turbo_tasks_hash::hash_xxh3_hash64; use turbo_tasks_hash::hash_xxh3_hash64;
use turbopack_core::{ use turbopack_core::{
...@@ -229,7 +229,7 @@ pub async fn dynamic_image_metadata_source( ...@@ -229,7 +229,7 @@ pub async fn dynamic_image_metadata_source(
#[turbo_tasks::function] #[turbo_tasks::function]
async fn collect_direct_exports(module: Vc<Box<dyn Module>>) -> Result<Vc<Vec<RcStr>>> { async fn collect_direct_exports(module: Vc<Box<dyn Module>>) -> Result<Vc<Vec<RcStr>>> {
let Some(ecmascript_asset) = let Some(ecmascript_asset) =
Vc::try_resolve_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(module).await? ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(module.to_resolved().await?)
else { else {
return Ok(Default::default()); return Ok(Default::default());
}; };
......
...@@ -171,13 +171,13 @@ impl EcmascriptClientReferenceModule { ...@@ -171,13 +171,13 @@ impl EcmascriptClientReferenceModule {
.process(Vc::upcast(proxy_source), ReferenceType::Undefined) .process(Vc::upcast(proxy_source), ReferenceType::Undefined)
.module(); .module();
let Some(proxy_module) = let Some(proxy_module) = ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(
Vc::try_resolve_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(proxy_module).await? proxy_module.to_resolved().await?,
else { ) else {
bail!("proxy asset is not an ecmascript module"); bail!("proxy asset is not an ecmascript module");
}; };
Ok(proxy_module) Ok(*proxy_module)
} }
} }
...@@ -260,11 +260,9 @@ impl ChunkableModule for EcmascriptClientReferenceModule { ...@@ -260,11 +260,9 @@ impl ChunkableModule for EcmascriptClientReferenceModule {
let item = self let item = self
.proxy_module() .proxy_module()
.as_chunk_item(module_graph, *chunking_context); .as_chunk_item(module_graph, *chunking_context);
let ecmascript_item = Vc::try_resolve_downcast::<Box<dyn EcmascriptChunkItem>>(item) let ecmascript_item =
.await? ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkItem>>(item.to_resolved().await?)
.context("EcmascriptModuleAsset must implement EcmascriptChunkItem")? .context("EcmascriptModuleAsset must implement EcmascriptChunkItem")?;
.to_resolved()
.await?;
Ok(Vc::upcast( Ok(Vc::upcast(
EcmascriptClientReferenceProxyChunkItem { EcmascriptClientReferenceProxyChunkItem {
......
use anyhow::{Result, bail}; use anyhow::{Result, bail};
use turbo_tasks::Vc; use turbo_tasks::{ResolvedVc, Vc};
use turbopack::{ModuleAssetContext, transition::Transition}; use turbopack::{ModuleAssetContext, transition::Transition};
use turbopack_core::module::Module; use turbopack_core::module::Module;
use turbopack_ecmascript::chunk::EcmascriptChunkPlaceable; use turbopack_ecmascript::chunk::EcmascriptChunkPlaceable;
...@@ -32,12 +32,12 @@ impl Transition for NextServerUtilityTransition { ...@@ -32,12 +32,12 @@ impl Transition for NextServerUtilityTransition {
module: Vc<Box<dyn Module>>, module: Vc<Box<dyn Module>>,
_context: Vc<ModuleAssetContext>, _context: Vc<ModuleAssetContext>,
) -> Result<Vc<Box<dyn Module>>> { ) -> Result<Vc<Box<dyn Module>>> {
let Some(module) = let Some(module) = ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(
Vc::try_resolve_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(module).await? module.to_resolved().await?,
else { ) else {
bail!("not an ecmascript module"); bail!("not an ecmascript module");
}; };
Ok(Vc::upcast(NextServerUtilityModule::new(module))) Ok(Vc::upcast(NextServerUtilityModule::new(*module)))
} }
} }
...@@ -46,8 +46,7 @@ async fn all_in_one() { ...@@ -46,8 +46,7 @@ async fn all_in_one() {
let c_erased: Vc<Box<dyn Add>> = a_erased.add(b_erased); let c_erased: Vc<Box<dyn Add>> = a_erased.add(b_erased);
assert_eq!( assert_eq!(
*Vc::try_resolve_downcast_type::<Number>(c_erased) *ResolvedVc::try_downcast_type::<Number>(c_erased.to_resolved().await?)
.await?
.unwrap() .unwrap()
.await?, .await?,
42 42
......
...@@ -44,7 +44,6 @@ serde = { workspace = true, features = ["rc", "derive"] } ...@@ -44,7 +44,6 @@ serde = { workspace = true, features = ["rc", "derive"] }
serde_json = { workspace = true } serde_json = { workspace = true }
shrink-to-fit = { workspace = true, features = ["indexmap", "serde_json", "smallvec", "nightly"] } shrink-to-fit = { workspace = true, features = ["indexmap", "serde_json", "smallvec", "nightly"] }
smallvec = { workspace = true } smallvec = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["full"] } tokio = { workspace = true, features = ["full"] }
tokio-util = { workspace = true } tokio-util = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
......
...@@ -121,7 +121,7 @@ pub use crate::{ ...@@ -121,7 +121,7 @@ pub use crate::{
}, },
mapped_read_ref::MappedReadRef, mapped_read_ref::MappedReadRef,
output::OutputContent, output::OutputContent,
raw_vc::{CellId, RawVc, ReadRawVcFuture, ResolveTypeError}, raw_vc::{CellId, RawVc, ReadRawVcFuture},
read_options::{ReadCellOptions, ReadOutputOptions}, read_options::{ReadCellOptions, ReadOutputOptions},
read_ref::ReadRef, read_ref::ReadRef,
serialization_invalidation::SerializationInvalidator, serialization_invalidation::SerializationInvalidator,
......
...@@ -1887,20 +1887,6 @@ pub(crate) async fn read_task_output( ...@@ -1887,20 +1887,6 @@ pub(crate) async fn read_task_output(
} }
} }
pub(crate) async fn read_task_cell(
this: &dyn TurboTasksApi,
id: TaskId,
index: CellId,
options: ReadCellOptions,
) -> Result<TypedCellContent> {
loop {
match this.try_read_task_cell(id, index, options)? {
Ok(result) => return Ok(result),
Err(listener) => listener.await,
}
}
}
/// A reference to a task's cell with methods that allow updating the contents /// A reference to a task's cell with methods that allow updating the contents
/// of the cell. /// of the cell.
/// ///
......
...@@ -9,34 +9,20 @@ use anyhow::Result; ...@@ -9,34 +9,20 @@ use anyhow::Result;
use auto_hash_map::AutoSet; use auto_hash_map::AutoSet;
use bincode::{Decode, Encode}; use bincode::{Decode, Encode};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use thiserror::Error;
use crate::{ use crate::{
CollectiblesSource, ReadCellOptions, ReadConsistency, ReadOutputOptions, ResolvedVc, TaskId, CollectiblesSource, ReadCellOptions, ReadConsistency, ReadOutputOptions, ResolvedVc, TaskId,
TaskPersistence, TraitTypeId, ValueType, ValueTypeId, VcValueTrait, TaskPersistence, TraitTypeId, ValueTypeId, VcValueTrait,
backend::{CellContent, TypedCellContent}, backend::TypedCellContent,
event::EventListener, event::EventListener,
id::{ExecutionId, LocalTaskId}, id::{ExecutionId, LocalTaskId},
manager::{ manager::{
ReadCellTracking, ReadTracking, read_local_output, read_task_cell, read_task_output, ReadCellTracking, ReadTracking, read_local_output, read_task_output, with_turbo_tasks,
with_turbo_tasks,
}, },
registry::{self, get_value_type}, registry::{self, get_value_type},
turbo_tasks, turbo_tasks,
}; };
#[derive(Error, Debug)]
pub enum ResolveTypeError {
#[error("no content in the cell")]
NoContent,
#[error("the content in the cell has no type")]
UntypedContent,
#[error("content is not available as task execution failed")]
TaskError { source: anyhow::Error },
#[error("reading the cell content failed")]
ReadError { source: anyhow::Error },
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Encode, Decode)] #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, Encode, Decode)]
pub struct CellId { pub struct CellId {
pub type_id: ValueTypeId, pub type_id: ValueTypeId,
...@@ -161,78 +147,6 @@ impl RawVc { ...@@ -161,78 +147,6 @@ impl RawVc {
ReadRawVcFuture::new(self, None) ReadRawVcFuture::new(self, None)
} }
pub(crate) async fn resolve_trait(
self,
trait_type: TraitTypeId,
) -> Result<Option<RawVc>, ResolveTypeError> {
self.resolve_type_inner(|value_type_id| {
let value_type = get_value_type(value_type_id);
(value_type.has_trait(&trait_type), Some(value_type))
})
.await
}
pub(crate) async fn resolve_value(
self,
value_type: ValueTypeId,
) -> Result<Option<RawVc>, ResolveTypeError> {
self.resolve_type_inner(|cell_value_type| (cell_value_type == value_type, None))
.await
}
/// Helper for `resolve_trait` and `resolve_value`.
///
/// After finding a cell, returns `Ok(Some(...))` when `conditional` returns
/// `true`, and `Ok(None)` when `conditional` returns `false`.
///
/// As an optimization, `conditional` may return the `&'static ValueType` to
/// avoid a potential extra lookup later.
async fn resolve_type_inner(
self,
conditional: impl FnOnce(ValueTypeId) -> (bool, Option<&'static ValueType>),
) -> Result<Option<RawVc>, ResolveTypeError> {
let tt = turbo_tasks();
let mut current = self;
loop {
match current {
RawVc::TaskOutput(task) => {
current = read_task_output(&*tt, task, ReadOutputOptions::default())
.await
.map_err(|source| ResolveTypeError::TaskError { source })?;
}
RawVc::TaskCell(task, index) => {
let (ok, value_type) = conditional(index.type_id);
if !ok {
return Ok(None);
}
let value_type =
value_type.unwrap_or_else(|| registry::get_value_type(index.type_id));
let content = read_task_cell(
&*tt,
task,
index,
ReadCellOptions {
is_serializable_cell_content: value_type.bincode.is_some(),
..Default::default()
},
)
.await
.map_err(|source| ResolveTypeError::ReadError { source })?;
if let TypedCellContent(_, CellContent(Some(_))) = content {
return Ok(Some(RawVc::TaskCell(task, index)));
} else {
return Err(ResolveTypeError::NoContent);
}
}
RawVc::LocalOutput(execution_id, local_task_id, ..) => {
current = read_local_output(&*tt, execution_id, local_task_id)
.await
.map_err(|source| ResolveTypeError::TaskError { source })?;
}
}
}
}
/// See [`crate::Vc::resolve`]. /// See [`crate::Vc::resolve`].
pub(crate) async fn resolve(self) -> Result<RawVc> { pub(crate) async fn resolve(self) -> Result<RawVc> {
self.resolve_inner(ReadOutputOptions { self.resolve_inner(ReadOutputOptions {
......
...@@ -32,7 +32,7 @@ pub use self::{ ...@@ -32,7 +32,7 @@ pub use self::{
traits::{Dynamic, Upcast, UpcastStrict, VcValueTrait, VcValueType}, traits::{Dynamic, Upcast, UpcastStrict, VcValueTrait, VcValueType},
}; };
use crate::{ use crate::{
CellId, RawVc, ResolveTypeError, CellId, RawVc,
debug::{ValueDebug, ValueDebugFormat, ValueDebugFormatString}, debug::{ValueDebug, ValueDebugFormat, ValueDebugFormatString},
keyed::{KeyedAccess, KeyedEq}, keyed::{KeyedAccess, KeyedEq},
registry, registry,
...@@ -506,70 +506,6 @@ where ...@@ -506,70 +506,6 @@ where
} }
} }
impl<T> Vc<T>
where
T: VcValueTrait + ?Sized,
{
/// Attempts to sidecast the given `Vc<Box<dyn T>>` to a `Vc<Box<dyn K>>`.
/// This operation also resolves the `Vc`.
///
/// Returns `None` if the underlying value type does not implement `K`.
///
/// **Note:** if the trait T is required to implement K, use
/// `Vc::upcast(vc).resolve()` instead. This provides stronger guarantees,
/// removing the need for a `Result` return type.
pub async fn try_resolve_sidecast<K>(vc: Self) -> Result<Option<Vc<K>>, ResolveTypeError>
where
K: VcValueTrait + ?Sized,
{
debug_assert!(
<K as VcValueTrait>::get_trait_type_id() != <T as VcValueTrait>::get_trait_type_id(),
"Attempted to cast a type {} to itself, which is pointless. Use the value directly \
instead.",
crate::registry::get_trait(<T as VcValueTrait>::get_trait_type_id()).global_name
);
let raw_vc: RawVc = vc.node;
let raw_vc = raw_vc
.resolve_trait(<K as VcValueTrait>::get_trait_type_id())
.await?;
Ok(raw_vc.map(|raw_vc| Vc {
node: raw_vc,
_t: PhantomData,
}))
}
/// Attempts to downcast the given `Vc<Box<dyn T>>` to a `Vc<K>`, where `K`
/// is of the form `Box<dyn L>`, and `L` is a value trait.
/// This operation also resolves the `Vc`.
///
/// Returns `None` if the underlying value type is not a `K`.
pub async fn try_resolve_downcast<K>(vc: Self) -> Result<Option<Vc<K>>, ResolveTypeError>
where
K: UpcastStrict<T> + VcValueTrait + ?Sized,
{
Self::try_resolve_sidecast(vc).await
}
/// Attempts to downcast the given `Vc<Box<dyn T>>` to a `Vc<K>`, where `K`
/// is a value type.
/// This operation also resolves the `Vc`.
///
/// Returns `None` if the underlying value type is not a `K`.
pub async fn try_resolve_downcast_type<K>(vc: Self) -> Result<Option<Vc<K>>, ResolveTypeError>
where
K: UpcastStrict<T> + VcValueType,
{
let raw_vc: RawVc = vc.node;
let raw_vc = raw_vc
.resolve_value(<K as VcValueType>::get_value_type_id())
.await?;
Ok(raw_vc.map(|raw_vc| Vc {
node: raw_vc,
_t: PhantomData,
}))
}
}
impl<T> From<RawVc> for Vc<T> impl<T> From<RawVc> for Vc<T>
where where
T: ?Sized, T: ?Sized,
......
...@@ -260,8 +260,6 @@ where ...@@ -260,8 +260,6 @@ where
/// ///
/// **Note:** if the trait `T` is required to implement `K`, use [`ResolvedVc::upcast`] instead. /// **Note:** if the trait `T` is required to implement `K`, use [`ResolvedVc::upcast`] instead.
/// That method provides stronger guarantees, removing the need for a [`Option`] return type. /// That method provides stronger guarantees, removing the need for a [`Option`] return type.
///
/// See also: [`Vc::try_resolve_sidecast`].
pub fn try_sidecast<K>(this: Self) -> Option<ResolvedVc<K>> pub fn try_sidecast<K>(this: Self) -> Option<ResolvedVc<K>>
where where
K: VcValueTrait + ?Sized, K: VcValueTrait + ?Sized,
...@@ -292,8 +290,6 @@ where ...@@ -292,8 +290,6 @@ where
/// is of the form `Box<dyn L>`, and `L` is a value trait. /// is of the form `Box<dyn L>`, and `L` is a value trait.
/// ///
/// Returns `None` if the underlying value type is not a `K`. /// Returns `None` if the underlying value type is not a `K`.
///
/// See also: [`Vc::try_resolve_downcast`].
pub fn try_downcast<K>(this: Self) -> Option<ResolvedVc<K>> pub fn try_downcast<K>(this: Self) -> Option<ResolvedVc<K>>
where where
K: UpcastStrict<T> + VcValueTrait + ?Sized, K: UpcastStrict<T> + VcValueTrait + ?Sized,
...@@ -305,8 +301,6 @@ where ...@@ -305,8 +301,6 @@ where
/// Attempts to downcast the given `Vc<Box<dyn T>>` to a `Vc<K>`, where `K` is a value type. /// Attempts to downcast the given `Vc<Box<dyn T>>` to a `Vc<K>`, where `K` is a value type.
/// ///
/// Returns `None` if the underlying value type is not a `K`. /// Returns `None` if the underlying value type is not a `K`.
///
/// See also: [`Vc::try_resolve_downcast_type`].
pub fn try_downcast_type<K>(this: Self) -> Option<ResolvedVc<K>> pub fn try_downcast_type<K>(this: Self) -> Option<ResolvedVc<K>>
where where
K: UpcastStrict<T> + VcValueType, K: UpcastStrict<T> + VcValueType,
......
...@@ -70,7 +70,7 @@ pub async fn split_output_asset_into_parts( ...@@ -70,7 +70,7 @@ pub async fn split_output_asset_into_parts(
let lines_vc = file_content.lines().to_resolved().await?; let lines_vc = file_content.lines().to_resolved().await?;
let Some(generate_source_map) = let Some(generate_source_map) =
Vc::try_resolve_sidecast::<Box<dyn GenerateSourceMap>>(asset).await? ResolvedVc::try_sidecast::<Box<dyn GenerateSourceMap>>(asset.to_resolved().await?)
else { else {
return self_mapped(asset, content, lines_vc).await; return self_mapped(asset, content, lines_vc).await;
}; };
......
...@@ -71,7 +71,8 @@ impl ChunkData { ...@@ -71,7 +71,8 @@ impl ChunkData {
}; };
let path = path.to_string(); let path = path.to_string();
let Some(output_chunk) = Vc::try_resolve_sidecast::<Box<dyn OutputChunk>>(chunk).await? let Some(output_chunk) =
ResolvedVc::try_sidecast::<Box<dyn OutputChunk>>(chunk.to_resolved().await?)
else { else {
return Ok(Vc::cell(Some( return Ok(Vc::cell(Some(
ChunkData { ChunkData {
......
...@@ -43,13 +43,15 @@ async fn to_evaluatable( ...@@ -43,13 +43,15 @@ async fn to_evaluatable(
let module = asset_context let module = asset_context
.process(asset, ReferenceType::Entry(EntryReferenceSubType::Runtime)) .process(asset, ReferenceType::Entry(EntryReferenceSubType::Runtime))
.module(); .module();
let Some(entry) = Vc::try_resolve_downcast::<Box<dyn EvaluatableAsset>>(module).await? else { let Some(entry) =
ResolvedVc::try_downcast::<Box<dyn EvaluatableAsset>>(module.to_resolved().await?)
else {
bail!( bail!(
"{} is not a valid evaluated entry", "{} is not a valid evaluated entry",
module.ident().to_string().await? module.ident().to_string().await?
) )
}; };
Ok(entry) Ok(*entry)
} }
#[turbo_tasks::value(transparent)] #[turbo_tasks::value(transparent)]
......
...@@ -277,13 +277,10 @@ impl CssChunkItem for CssModuleChunkItem { ...@@ -277,13 +277,10 @@ impl CssChunkItem for CssModuleChunkItem {
ResolvedVc::try_downcast::<Box<dyn CssChunkPlaceable>>(module) ResolvedVc::try_downcast::<Box<dyn CssChunkPlaceable>>(module)
{ {
let item = placeable.as_chunk_item(*self.module_graph, *chunking_context); let item = placeable.as_chunk_item(*self.module_graph, *chunking_context);
if let Some(css_item) = if let Some(css_item) = ResolvedVc::try_downcast::<Box<dyn CssChunkItem>>(
Vc::try_resolve_downcast::<Box<dyn CssChunkItem>>(item).await? item.to_resolved().await?,
{ ) {
imports.push(CssImport::Internal( imports.push(CssImport::Internal(import_ref, css_item));
import_ref,
css_item.to_resolved().await?,
));
} }
} }
} }
...@@ -302,10 +299,10 @@ impl CssChunkItem for CssModuleChunkItem { ...@@ -302,10 +299,10 @@ impl CssChunkItem for CssModuleChunkItem {
ResolvedVc::try_downcast::<Box<dyn CssChunkPlaceable>>(module) ResolvedVc::try_downcast::<Box<dyn CssChunkPlaceable>>(module)
{ {
let item = placeable.as_chunk_item(*self.module_graph, *chunking_context); let item = placeable.as_chunk_item(*self.module_graph, *chunking_context);
if let Some(css_item) = if let Some(css_item) = ResolvedVc::try_downcast::<Box<dyn CssChunkItem>>(
Vc::try_resolve_downcast::<Box<dyn CssChunkItem>>(item).await? item.to_resolved().await?,
{ ) {
imports.push(CssImport::Composes(css_item.to_resolved().await?)); imports.push(CssImport::Composes(css_item));
} }
} }
} }
......
...@@ -178,8 +178,7 @@ impl ModuleCssAsset { ...@@ -178,8 +178,7 @@ impl ModuleCssAsset {
.inner(ReferenceType::Css(CssReferenceSubType::Analyze)) .inner(ReferenceType::Css(CssReferenceSubType::Analyze))
.module(); .module();
let inner = Vc::try_resolve_sidecast::<Box<dyn ProcessCss>>(inner) let inner = ResolvedVc::try_sidecast::<Box<dyn ProcessCss>>(inner.to_resolved().await?)
.await?
.context("inner asset should be CSS processable")?; .context("inner asset should be CSS processable")?;
let result = inner.get_css_with_placeholder().await?; let result = inner.get_css_with_placeholder().await?;
......
...@@ -187,7 +187,8 @@ async fn get_update_stream_item_operation( ...@@ -187,7 +187,8 @@ async fn get_update_stream_item_operation(
extend_issues(&mut plain_issues, peek_issues(proxy_result_op).await?); extend_issues(&mut plain_issues, peek_issues(proxy_result_op).await?);
let from = from.get(); let from = from.get();
if let Some(from) = Vc::try_resolve_downcast_type::<ProxyResult>(from).await? if let Some(from) =
ResolvedVc::try_downcast_type::<ProxyResult>(from.to_resolved().await?)
&& from.await? == proxy_result_value && from.await? == proxy_result_value
{ {
return Ok(UpdateStreamItem::Found { return Ok(UpdateStreamItem::Found {
......
...@@ -301,7 +301,11 @@ async fn find_export_from_reexports( ...@@ -301,7 +301,11 @@ async fn find_export_from_reexports(
// If we apply this logic to EcmascriptModuleAsset, we will resolve everything in the // If we apply this logic to EcmascriptModuleAsset, we will resolve everything in the
// target module. // target module.
if (Vc::try_resolve_downcast_type::<EcmascriptModuleAsset>(module_part).await?).is_none() { if (ResolvedVc::try_downcast_type::<EcmascriptModuleAsset>(
module_part.to_resolved().await?,
))
.is_none()
{
return Ok(find_export_from_reexports(module_part, export_name)); return Ok(find_export_from_reexports(module_part, export_name));
} }
} }
......
...@@ -392,13 +392,13 @@ pub async fn get_evaluate_entries( ...@@ -392,13 +392,13 @@ pub async fn get_evaluate_entries(
) )
.module(); .module();
let Some(globals_module) = let Some(globals_module) = ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(
Vc::try_resolve_sidecast::<Box<dyn EvaluatableAsset>>(globals_module).await? globals_module.to_resolved().await?,
else { ) else {
bail!("Internal module is not evaluatable"); bail!("Internal module is not evaluatable");
}; };
let mut entries = vec![globals_module.to_resolved().await?]; let mut entries = vec![globals_module];
if let Some(runtime_entries) = runtime_entries { if let Some(runtime_entries) = runtime_entries {
for &entry in &*runtime_entries.await? { for &entry in &*runtime_entries.await? {
entries.push(entry) entries.push(entry)
......
...@@ -445,7 +445,7 @@ async fn find_config_in_location( ...@@ -445,7 +445,7 @@ async fn find_config_in_location(
impl GenerateSourceMap for PostCssTransformedAsset { impl GenerateSourceMap for PostCssTransformedAsset {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn generate_source_map(&self) -> Result<Vc<FileContent>> { async fn generate_source_map(&self) -> Result<Vc<FileContent>> {
let source = Vc::try_resolve_sidecast::<Box<dyn GenerateSourceMap>>(*self.source).await?; let source = ResolvedVc::try_sidecast::<Box<dyn GenerateSourceMap>>(self.source);
match source { match source {
Some(source) => Ok(source.generate_source_map()), Some(source) => Ok(source.generate_source_map()),
None => Ok(FileContent::NotFound.cell()), None => Ok(FileContent::NotFound.cell()),
......
...@@ -441,11 +441,11 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -441,11 +441,11 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
.module(); .module();
let (evaluatable_assets, entry_modules) = if let Some(ecmascript) = let (evaluatable_assets, entry_modules) = if let Some(ecmascript) =
Vc::try_resolve_sidecast::<Box<dyn EvaluatableAsset>>(entry_module).await? ResolvedVc::try_sidecast::<Box<dyn EvaluatableAsset>>(entry_module.to_resolved().await?)
{ {
let evaluatable_assets = runtime_entries let evaluatable_assets = runtime_entries
.unwrap_or_else(EvaluatableAssets::empty) .unwrap_or_else(EvaluatableAssets::empty)
.with_entry(ecmascript); .with_entry(*ecmascript);
( (
evaluatable_assets, evaluatable_assets,
evaluatable_assets evaluatable_assets
...@@ -600,9 +600,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> { ...@@ -600,9 +600,7 @@ async fn run_test_operation(resource: RcStr) -> Result<Vc<FileSystemPath>> {
Runtime::NodeJs => { Runtime::NodeJs => {
OutputAssetsWithReferenced { OutputAssetsWithReferenced {
assets: ResolvedVc::cell(vec![ assets: ResolvedVc::cell(vec![
Vc::try_resolve_downcast_type::<NodeJsChunkingContext>(chunking_context) chunking_context
.await?
.unwrap()
.entry_chunk_group( .entry_chunk_group(
// `expected` expects a completely flat output directory. // `expected` expects a completely flat output directory.
chunk_root_path chunk_root_path
......
...@@ -82,25 +82,26 @@ impl WebAssemblyModuleAsset { ...@@ -82,25 +82,26 @@ impl WebAssemblyModuleAsset {
async fn loader_as_resolve_origin(self: Vc<Self>) -> Result<Vc<Box<dyn ResolveOrigin>>> { async fn loader_as_resolve_origin(self: Vc<Self>) -> Result<Vc<Box<dyn ResolveOrigin>>> {
let module = self.loader_as_module(); let module = self.loader_as_module();
let Some(esm_asset) = Vc::try_resolve_sidecast::<Box<dyn ResolveOrigin>>(module).await? let Some(esm_asset) =
ResolvedVc::try_sidecast::<Box<dyn ResolveOrigin>>(module.to_resolved().await?)
else { else {
bail!("WASM loader was not processed into an EcmascriptModuleAsset"); bail!("WASM loader was not processed into an EcmascriptModuleAsset");
}; };
Ok(esm_asset) Ok(*esm_asset)
} }
#[turbo_tasks::function] #[turbo_tasks::function]
async fn loader(self: Vc<Self>) -> Result<Vc<Box<dyn EcmascriptChunkPlaceable>>> { async fn loader(self: Vc<Self>) -> Result<Vc<Box<dyn EcmascriptChunkPlaceable>>> {
let module = self.loader_as_module(); let module = self.loader_as_module();
let Some(esm_asset) = let Some(esm_asset) = ResolvedVc::try_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(
Vc::try_resolve_sidecast::<Box<dyn EcmascriptChunkPlaceable>>(module).await? module.to_resolved().await?,
else { ) else {
bail!("WASM loader was not processed into an EcmascriptModuleAsset"); bail!("WASM loader was not processed into an EcmascriptModuleAsset");
}; };
Ok(esm_asset) Ok(*esm_asset)
} }
#[turbo_tasks::function] #[turbo_tasks::function]
...@@ -259,9 +260,9 @@ impl EcmascriptChunkItem for ModuleChunkItem { ...@@ -259,9 +260,9 @@ impl EcmascriptChunkItem for ModuleChunkItem {
let loader_asset = self.module.loader(); let loader_asset = self.module.loader();
let item = loader_asset.as_chunk_item(*self.module_graph, *self.chunking_context); let item = loader_asset.as_chunk_item(*self.module_graph, *self.chunking_context);
let ecmascript_item = Vc::try_resolve_downcast::<Box<dyn EcmascriptChunkItem>>(item) let ecmascript_item =
.await? ResolvedVc::try_downcast::<Box<dyn EcmascriptChunkItem>>(item.to_resolved().await?)
.context("EcmascriptModuleAsset must implement EcmascriptChunkItem")?; .context("EcmascriptModuleAsset must implement EcmascriptChunkItem")?;
let chunk_item_content = ecmascript_item let chunk_item_content = ecmascript_item
.content_with_async_module_info(async_module_info, false) .content_with_async_module_info(async_module_info, false)
......
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