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

fix(turbo-tasks): Implement `TaskInput for `ResolvedVc` (#70814)

`TaskInput` isn't needed/used for a bare `ResolvedVc`, as we'll expose
`ResolvedVc` arguments as `Vc`, but it is useful for structs that
contain `ResolvedVc` and want to derive `TaskInput`.

This PR also ports `next_core::app_structure::Entrypoint` to use
`ResolvedVc` as a way of testing this.
parent 809cce89
...@@ -627,7 +627,7 @@ pub fn app_entry_point_to_route( ...@@ -627,7 +627,7 @@ pub fn app_entry_point_to_route(
AppEndpoint { AppEndpoint {
ty: AppEndpointType::Page { ty: AppEndpointType::Page {
ty: AppPageEndpointType::Html, ty: AppPageEndpointType::Html,
loader_tree, loader_tree: *loader_tree,
}, },
app_project, app_project,
page: page.clone(), page: page.clone(),
...@@ -638,7 +638,7 @@ pub fn app_entry_point_to_route( ...@@ -638,7 +638,7 @@ pub fn app_entry_point_to_route(
AppEndpoint { AppEndpoint {
ty: AppEndpointType::Page { ty: AppEndpointType::Page {
ty: AppPageEndpointType::Rsc, ty: AppPageEndpointType::Rsc,
loader_tree, loader_tree: *loader_tree,
}, },
app_project, app_project,
page, page,
...@@ -656,7 +656,10 @@ pub fn app_entry_point_to_route( ...@@ -656,7 +656,10 @@ pub fn app_entry_point_to_route(
original_name: page.to_string(), original_name: page.to_string(),
endpoint: Vc::upcast( endpoint: Vc::upcast(
AppEndpoint { AppEndpoint {
ty: AppEndpointType::Route { path, root_layouts }, ty: AppEndpointType::Route {
path: *path,
root_layouts: *root_layouts,
},
app_project, app_project,
page, page,
} }
......
...@@ -10,8 +10,8 @@ use rustc_hash::FxHashMap; ...@@ -10,8 +10,8 @@ use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use tracing::Instrument; use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, RcStr, TaskInput, TryJoinIterExt, ValueToString, debug::ValueDebugFormat, trace::TraceRawVcs, RcStr, ResolvedVc, TaskInput, TryJoinIterExt,
Vc, ValueToString, Vc,
}; };
use turbo_tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath}; use turbo_tasks_fs::{DirectoryContent, DirectoryEntry, FileSystemEntryType, FileSystemPath};
use turbopack_core::issue::{ use turbopack_core::issue::{
...@@ -296,7 +296,6 @@ async fn get_directory_tree_internal( ...@@ -296,7 +296,6 @@ async fn get_directory_tree_internal(
let entry = entry.resolve_symlink().await?; let entry = entry.resolve_symlink().await?;
match entry { match entry {
DirectoryEntry::File(file) => { DirectoryEntry::File(file) => {
let file = file.resolve().await?;
// Do not process .d.ts files as routes // Do not process .d.ts files as routes
if basename.ends_with(".d.ts") { if basename.ends_with(".d.ts") {
continue; continue;
...@@ -304,15 +303,15 @@ async fn get_directory_tree_internal( ...@@ -304,15 +303,15 @@ async fn get_directory_tree_internal(
if let Some((stem, ext)) = basename.split_once('.') { if let Some((stem, ext)) = basename.split_once('.') {
if page_extensions_value.iter().any(|e| e == ext) { if page_extensions_value.iter().any(|e| e == ext) {
match stem { match stem {
"page" => modules.page = Some(file), "page" => modules.page = Some(*file),
"layout" => modules.layout = Some(file), "layout" => modules.layout = Some(*file),
"error" => modules.error = Some(file), "error" => modules.error = Some(*file),
"global-error" => modules.global_error = Some(file), "global-error" => modules.global_error = Some(*file),
"loading" => modules.loading = Some(file), "loading" => modules.loading = Some(*file),
"template" => modules.template = Some(file), "template" => modules.template = Some(*file),
"not-found" => modules.not_found = Some(file), "not-found" => modules.not_found = Some(*file),
"default" => modules.default = Some(file), "default" => modules.default = Some(*file),
"route" => modules.route = Some(file), "route" => modules.route = Some(*file),
_ => {} _ => {}
} }
} }
...@@ -334,9 +333,9 @@ async fn get_directory_tree_internal( ...@@ -334,9 +333,9 @@ async fn get_directory_tree_internal(
"opengraph-image" => &mut metadata_open_graph, "opengraph-image" => &mut metadata_open_graph,
"sitemap" => { "sitemap" => {
if dynamic { if dynamic {
modules.metadata.sitemap = Some(MetadataItem::Dynamic { path: file }); modules.metadata.sitemap = Some(MetadataItem::Dynamic { path: *file });
} else { } else {
modules.metadata.sitemap = Some(MetadataItem::Static { path: file }); modules.metadata.sitemap = Some(MetadataItem::Static { path: *file });
} }
continue; continue;
} }
...@@ -344,7 +343,7 @@ async fn get_directory_tree_internal( ...@@ -344,7 +343,7 @@ async fn get_directory_tree_internal(
}; };
if dynamic { if dynamic {
entry.push((number, MetadataWithAltItem::Dynamic { path: file })); entry.push((number, MetadataWithAltItem::Dynamic { path: *file }));
continue; continue;
} }
...@@ -360,16 +359,15 @@ async fn get_directory_tree_internal( ...@@ -360,16 +359,15 @@ async fn get_directory_tree_internal(
entry.push(( entry.push((
number, number,
MetadataWithAltItem::Static { MetadataWithAltItem::Static {
path: file, path: *file,
alt_path, alt_path,
}, },
)); ));
} }
DirectoryEntry::Directory(dir) => { DirectoryEntry::Directory(dir) => {
let dir = dir.resolve().await?;
// appDir ignores paths starting with an underscore // appDir ignores paths starting with an underscore
if !basename.starts_with('_') { if !basename.starts_with('_') {
let result = get_directory_tree(dir, page_extensions); let result = get_directory_tree(*dir, page_extensions);
subdirectories.insert(basename.clone(), result); subdirectories.insert(basename.clone(), result);
} }
} }
...@@ -484,12 +482,12 @@ impl AppPageLoaderTree { ...@@ -484,12 +482,12 @@ impl AppPageLoaderTree {
pub enum Entrypoint { pub enum Entrypoint {
AppPage { AppPage {
pages: Vec<AppPage>, pages: Vec<AppPage>,
loader_tree: Vc<AppPageLoaderTree>, loader_tree: ResolvedVc<AppPageLoaderTree>,
}, },
AppRoute { AppRoute {
page: AppPage, page: AppPage,
path: Vc<FileSystemPath>, path: ResolvedVc<FileSystemPath>,
root_layouts: Vc<Vec<Vc<FileSystemPath>>>, root_layouts: ResolvedVc<Vec<Vc<FileSystemPath>>>,
}, },
AppMetadata { AppMetadata {
page: AppPage, page: AppPage,
...@@ -557,7 +555,7 @@ fn add_app_page( ...@@ -557,7 +555,7 @@ fn add_app_page(
app_dir: Vc<FileSystemPath>, app_dir: Vc<FileSystemPath>,
result: &mut IndexMap<AppPath, Entrypoint>, result: &mut IndexMap<AppPath, Entrypoint>,
page: AppPage, page: AppPage,
loader_tree: Vc<AppPageLoaderTree>, loader_tree: ResolvedVc<AppPageLoaderTree>,
) { ) {
let mut e = match result.entry(page.clone().into()) { let mut e = match result.entry(page.clone().into()) {
Entry::Occupied(e) => e, Entry::Occupied(e) => e,
...@@ -616,8 +614,8 @@ fn add_app_route( ...@@ -616,8 +614,8 @@ fn add_app_route(
app_dir: Vc<FileSystemPath>, app_dir: Vc<FileSystemPath>,
result: &mut IndexMap<AppPath, Entrypoint>, result: &mut IndexMap<AppPath, Entrypoint>,
page: AppPage, page: AppPage,
path: Vc<FileSystemPath>, path: ResolvedVc<FileSystemPath>,
root_layouts: Vc<Vec<Vc<FileSystemPath>>>, root_layouts: ResolvedVc<Vec<Vc<FileSystemPath>>>,
) { ) {
let e = match result.entry(page.clone().into()) { let e = match result.entry(page.clone().into()) {
Entry::Occupied(e) => e, Entry::Occupied(e) => e,
...@@ -1046,7 +1044,7 @@ async fn directory_tree_to_entrypoints_internal( ...@@ -1046,7 +1044,7 @@ async fn directory_tree_to_entrypoints_internal(
directory_name: RcStr, directory_name: RcStr,
directory_tree: Vc<DirectoryTree>, directory_tree: Vc<DirectoryTree>,
app_page: AppPage, app_page: AppPage,
root_layouts: Vc<Vec<Vc<FileSystemPath>>>, root_layouts: ResolvedVc<Vec<Vc<FileSystemPath>>>,
) -> Result<Vc<Entrypoints>> { ) -> Result<Vc<Entrypoints>> {
let span = tracing::info_span!("build layout trees", name = display(&app_page)); let span = tracing::info_span!("build layout trees", name = display(&app_page));
directory_tree_to_entrypoints_internal_untraced( directory_tree_to_entrypoints_internal_untraced(
...@@ -1067,7 +1065,7 @@ async fn directory_tree_to_entrypoints_internal_untraced( ...@@ -1067,7 +1065,7 @@ async fn directory_tree_to_entrypoints_internal_untraced(
directory_name: RcStr, directory_name: RcStr,
directory_tree: Vc<DirectoryTree>, directory_tree: Vc<DirectoryTree>,
app_page: AppPage, app_page: AppPage,
root_layouts: Vc<Vec<Vc<FileSystemPath>>>, root_layouts: ResolvedVc<Vec<Vc<FileSystemPath>>>,
) -> Result<Vc<Entrypoints>> { ) -> Result<Vc<Entrypoints>> {
let mut result = IndexMap::new(); let mut result = IndexMap::new();
...@@ -1082,7 +1080,7 @@ async fn directory_tree_to_entrypoints_internal_untraced( ...@@ -1082,7 +1080,7 @@ async fn directory_tree_to_entrypoints_internal_untraced(
let root_layouts = if let Some(layout) = modules.layout { let root_layouts = if let Some(layout) = modules.layout {
let mut layouts = (*root_layouts.await?).clone(); let mut layouts = (*root_layouts.await?).clone();
layouts.push(layout); layouts.push(layout);
Vc::cell(layouts) ResolvedVc::cell(layouts)
} else { } else {
root_layouts root_layouts
}; };
...@@ -1104,7 +1102,10 @@ async fn directory_tree_to_entrypoints_internal_untraced( ...@@ -1104,7 +1102,10 @@ async fn directory_tree_to_entrypoints_internal_untraced(
app_dir, app_dir,
&mut result, &mut result,
app_page.complete(PageType::Page)?, app_page.complete(PageType::Page)?,
loader_tree.context("loader tree should be created for a page/default")?, loader_tree
.context("loader tree should be created for a page/default")?
.to_resolved()
.await?,
); );
} }
...@@ -1113,7 +1114,7 @@ async fn directory_tree_to_entrypoints_internal_untraced( ...@@ -1113,7 +1114,7 @@ async fn directory_tree_to_entrypoints_internal_untraced(
app_dir, app_dir,
&mut result, &mut result,
app_page.complete(PageType::Route)?, app_page.complete(PageType::Route)?,
route, route.to_resolved().await?,
root_layouts, root_layouts,
); );
} }
...@@ -1191,7 +1192,7 @@ async fn directory_tree_to_entrypoints_internal_untraced( ...@@ -1191,7 +1192,7 @@ async fn directory_tree_to_entrypoints_internal_untraced(
}, },
modules: modules.without_leafs(), modules: modules.without_leafs(),
global_metadata, global_metadata,
}.cell(); }.resolved_cell();
{ {
let app_page = app_page let app_page = app_page
...@@ -1223,7 +1224,7 @@ async fn directory_tree_to_entrypoints_internal_untraced( ...@@ -1223,7 +1224,7 @@ async fn directory_tree_to_entrypoints_internal_untraced(
subdir_name.clone(), subdir_name.clone(),
subdirectory, subdirectory,
child_app_page.clone(), child_app_page.clone(),
root_layouts, *root_layouts,
) )
.await?; .await?;
...@@ -1278,7 +1279,9 @@ async fn directory_tree_to_entrypoints_internal_untraced( ...@@ -1278,7 +1279,9 @@ async fn directory_tree_to_entrypoints_internal_untraced(
&mut result, &mut result,
page.clone(), page.clone(),
loader_tree loader_tree
.context("loader tree should be created for a page/default")?, .context("loader tree should be created for a page/default")?
.to_resolved()
.await?,
); );
} }
} }
......
...@@ -3,7 +3,9 @@ use std::{any::Any, fmt::Debug, future::Future, hash::Hash, time::Duration}; ...@@ -3,7 +3,9 @@ use std::{any::Any, fmt::Debug, future::Future, hash::Hash, time::Duration};
use anyhow::Result; use anyhow::Result;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use crate::{MagicAny, RcStr, TaskId, TransientInstance, TransientValue, Value, ValueTypeId, Vc}; use crate::{
MagicAny, RcStr, ResolvedVc, TaskId, TransientInstance, TransientValue, Value, ValueTypeId, Vc,
};
/// Trait to implement in order for a type to be accepted as a /// Trait to implement in order for a type to be accepted as a
/// [`#[turbo_tasks::function]`][crate::function] argument. /// [`#[turbo_tasks::function]`][crate::function] argument.
...@@ -108,6 +110,25 @@ where ...@@ -108,6 +110,25 @@ where
} }
} }
// `TaskInput` isn't needed/used for a bare `ResolvedVc`, as we'll expose `ResolvedVc` arguments as
// `Vc`, but it is useful for structs that contain `ResolvedVc` and want to derive `TaskInput`.
impl<T> TaskInput for ResolvedVc<T>
where
T: Send,
{
fn is_resolved(&self) -> bool {
true
}
fn is_transient(&self) -> bool {
self.node.is_transient()
}
async fn resolve(&self) -> Result<Self> {
Ok(*self)
}
}
impl<T> TaskInput for Value<T> impl<T> TaskInput for Value<T>
where where
T: Any T: Any
......
...@@ -1012,9 +1012,9 @@ async fn type_exists( ...@@ -1012,9 +1012,9 @@ async fn type_exists(
for path in result.symlinks.iter() { for path in result.symlinks.iter() {
refs.push(Vc::upcast(FileSource::new(**path))); refs.push(Vc::upcast(FileSource::new(**path)));
} }
let path = result.path.resolve().await?; let path = result.path;
Ok(if *path.get_type().await? == ty { Ok(if *path.get_type().await? == ty {
Some(path) Some(*path)
} else { } else {
None None
}) })
...@@ -1028,7 +1028,7 @@ async fn any_exists( ...@@ -1028,7 +1028,7 @@ async fn any_exists(
for path in result.symlinks.iter() { for path in result.symlinks.iter() {
refs.push(Vc::upcast(FileSource::new(**path))); refs.push(Vc::upcast(FileSource::new(**path)));
} }
let path = result.path.resolve().await?; let path = result.path;
let ty = *path.get_type().await?; let ty = *path.get_type().await?;
Ok( Ok(
if matches!( if matches!(
...@@ -1037,7 +1037,7 @@ async fn any_exists( ...@@ -1037,7 +1037,7 @@ async fn any_exists(
) { ) {
None None
} else { } else {
Some((ty, path)) Some((ty, *path))
}, },
) )
} }
......
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