Unverified Commit ab874537 authored by Benjamin Woodruff's avatar Benjamin Woodruff Committed by GitHub

chore(turbopack): Mark `ResolvedVc::resolve` as deprecated to prevent resolving…

chore(turbopack): Mark `ResolvedVc::resolve` as deprecated to prevent resolving an already-resolved ResolvedVc (#75168)

Same as we were already doing for `ResolvedVc::to_resolved`.

This function essentially just acts like a deref when called on `ResolvedVc`.

I'd eventually like to replace `Vc::resolve` with `Vc::to_resolved`. These are the easiest callsites to remove.
parent 72be937a
...@@ -50,18 +50,21 @@ pub async fn emit_assets( ...@@ -50,18 +50,21 @@ pub async fn emit_assets(
.iter() .iter()
.copied() .copied()
.map(|asset| async move { .map(|asset| async move {
let asset = asset.resolve().await?;
let path = asset.ident().path(); let path = asset.ident().path();
let span = tracing::info_span!("emit asset", name = %path.to_string().await?); let span = tracing::info_span!("emit asset", name = %path.to_string().await?);
async move { async move {
let path = path.await?; let path = path.await?;
Ok(if path.is_inside_ref(&*node_root.await?) { Ok(if path.is_inside_ref(&*node_root.await?) {
Some(emit(asset)) Some(emit(*asset))
} else if path.is_inside_ref(&*client_relative_path.await?) { } else if path.is_inside_ref(&*client_relative_path.await?) {
// Client assets are emitted to the client output path, which is prefixed // Client assets are emitted to the client output path, which is prefixed
// with _next. We need to rebase them to remove that // with _next. We need to rebase them to remove that
// prefix. // prefix.
Some(emit_rebase(asset, client_relative_path, client_output_path)) Some(emit_rebase(
*asset,
client_relative_path,
client_output_path,
))
} else { } else {
None None
}) })
......
...@@ -275,8 +275,6 @@ impl AfterResolvePlugin for ExternalCjsModulesResolvePlugin { ...@@ -275,8 +275,6 @@ impl AfterResolvePlugin for ExternalCjsModulesResolvePlugin {
]); ]);
}; };
let result = result.resolve().await?;
let result_from_original_location = result_from_original_location.resolve().await?;
if result_from_original_location != result { if result_from_original_location != result {
let package_json_file = find_context_file( let package_json_file = find_context_file(
result.ident().path().parent().resolve().await?, result.ident().path().parent().resolve().await?,
......
...@@ -73,7 +73,10 @@ where ...@@ -73,7 +73,10 @@ where
pub(crate) node: Vc<T>, pub(crate) node: Vc<T>,
} }
impl<T> ResolvedVc<T> { impl<T> ResolvedVc<T>
where
T: ?Sized,
{
/// This function exists to intercept calls to Vc::to_resolved through dereferencing /// This function exists to intercept calls to Vc::to_resolved through dereferencing
/// a ResolvedVc. Converting to Vc and re-resolving it puts unnecessary stress on /// a ResolvedVc. Converting to Vc and re-resolving it puts unnecessary stress on
/// the turbo tasks engine. /// the turbo tasks engine.
...@@ -81,6 +84,10 @@ impl<T> ResolvedVc<T> { ...@@ -81,6 +84,10 @@ impl<T> ResolvedVc<T> {
pub async fn to_resolved(self) -> Result<Self> { pub async fn to_resolved(self) -> Result<Self> {
Ok(self) Ok(self)
} }
#[deprecated(note = "No point in resolving a vc that is already resolved")]
pub async fn resolve(self) -> Result<Vc<T>> {
Ok(self.node)
}
} }
impl<T> Copy for ResolvedVc<T> where T: ?Sized {} impl<T> Copy for ResolvedVc<T> where T: ?Sized {}
......
...@@ -70,10 +70,9 @@ impl EcmascriptChunkItem for EcmascriptModuleFacadeChunkItem { ...@@ -70,10 +70,9 @@ impl EcmascriptChunkItem for EcmascriptModuleFacadeChunkItem {
let references = self.module.references(); let references = self.module.references();
let references_ref = references.await?; let references_ref = references.await?;
let mut code_gens = Vec::with_capacity(references_ref.len() + 2); let mut code_gens = Vec::with_capacity(references_ref.len() + 2);
for r in references_ref.iter() { for r in &references_ref {
let r = r.resolve().await?;
if let Some(code_gen) = if let Some(code_gen) =
Vc::try_resolve_sidecast::<Box<dyn CodeGenerateableWithAsyncModuleInfo>>(r).await? ResolvedVc::try_sidecast_sync::<Box<dyn CodeGenerateableWithAsyncModuleInfo>>(*r)
{ {
code_gens.push(code_gen.code_generation( code_gens.push(code_gen.code_generation(
*self.module_graph, *self.module_graph,
...@@ -81,7 +80,7 @@ impl EcmascriptChunkItem for EcmascriptModuleFacadeChunkItem { ...@@ -81,7 +80,7 @@ impl EcmascriptChunkItem for EcmascriptModuleFacadeChunkItem {
async_module_info, async_module_info,
)); ));
} else if let Some(code_gen) = } else if let Some(code_gen) =
Vc::try_resolve_sidecast::<Box<dyn CodeGenerateable>>(r).await? ResolvedVc::try_sidecast_sync::<Box<dyn CodeGenerateable>>(*r)
{ {
code_gens.push(code_gen.code_generation(*self.module_graph, *chunking_context)); code_gens.push(code_gen.code_generation(*self.module_graph, *chunking_context));
} }
......
...@@ -285,7 +285,7 @@ pub async fn resolve_node_gyp_build_files( ...@@ -285,7 +285,7 @@ pub async fn resolve_node_gyp_build_files(
if let Some(captured) = if let Some(captured) =
GYP_BUILD_TARGET_NAME.captures(&config_file.content().to_str()?) GYP_BUILD_TARGET_NAME.captures(&config_file.content().to_str()?)
{ {
let mut resolved: FxIndexMap<RcStr, Vc<Box<dyn Source>>> = let mut resolved: FxIndexMap<RcStr, ResolvedVc<Box<dyn Source>>> =
FxIndexMap::with_capacity_and_hasher(captured.len(), Default::default()); FxIndexMap::with_capacity_and_hasher(captured.len(), Default::default());
for found in captured.iter().skip(1).flatten() { for found in captured.iter().skip(1).flatten() {
let name = found.as_str(); let name = found.as_str();
...@@ -299,10 +299,7 @@ pub async fn resolve_node_gyp_build_files( ...@@ -299,10 +299,7 @@ pub async fn resolve_node_gyp_build_files(
if let Some((_, ResolveResultItem::Source(source))) = if let Some((_, ResolveResultItem::Source(source))) =
resolved_prebuilt_file.primary.first() resolved_prebuilt_file.primary.first()
{ {
resolved.insert( resolved.insert(format!("build/Release/{name}.node").into(), *source);
format!("build/Release/{name}.node").into(),
source.resolve().await?,
);
merged_affecting_sources merged_affecting_sources
.extend(resolved_prebuilt_file.affecting_sources.iter().copied()); .extend(resolved_prebuilt_file.affecting_sources.iter().copied());
} }
...@@ -315,7 +312,7 @@ pub async fn resolve_node_gyp_build_files( ...@@ -315,7 +312,7 @@ pub async fn resolve_node_gyp_build_files(
Ok(( Ok((
RequestKey::new(key), RequestKey::new(key),
ResolvedVc::upcast( ResolvedVc::upcast(
RawModule::new(source).to_resolved().await?, RawModule::new(*source).to_resolved().await?,
), ),
)) ))
}) })
......
...@@ -45,18 +45,17 @@ impl AggregatedGraph { ...@@ -45,18 +45,17 @@ impl AggregatedGraph {
#[turbo_tasks::function] #[turbo_tasks::function]
async fn references(self: Vc<Self>) -> Result<Vc<AggregatedGraphsSet>> { async fn references(self: Vc<Self>) -> Result<Vc<AggregatedGraphsSet>> {
Ok(match *self.await? { Ok(match &*self.await? {
AggregatedGraph::Leaf(asset) => { AggregatedGraph::Leaf(asset) => {
let mut refs = HashSet::new(); let mut refs = HashSet::new();
for reference in asset.references().await?.iter() { for reference in asset.references().await? {
let reference = reference.resolve().await?; if asset != reference {
if asset != reference.to_resolved().await? { refs.insert(AggregatedGraph::leaf(**reference).to_resolved().await?);
refs.insert(AggregatedGraph::leaf(reference).to_resolved().await?);
} }
} }
AggregatedGraphsSet { set: refs }.into() AggregatedGraphsSet { set: refs }.into()
} }
AggregatedGraph::Node { ref references, .. } => { AggregatedGraph::Node { references, .. } => {
let mut set = HashSet::new(); let mut set = HashSet::new();
for item in references for item in references
.iter() .iter()
......
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