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

refactor(turbopack/next-core): Remove uses of generic vc collections (#70815)

Removes the uses of generic vc collections in
`next-core/src/app_structure.rs` and it's callsites.

## Why?

Rather than extended support for `Vc` generics to `ResolvedVc`, I plan
to remove support for them entirely. That means fixing all the callsites
(there's not many).

Removing this is needed to get us to a point where 100% of structs can
be `ResolvedValue`, because structs using these fields cannot otherwise
be ported over to `ResolvedVc`.

## Okay, but Why?

Explained here:
https://github.com/vercel/turborepo/pull/8843#issuecomment-2253158412

I expect removing support for this will decrease the overall size of the
codebase, as the logic for supporting generics is rather complicated.
parent 189f2da2
...@@ -5,7 +5,7 @@ use next_core::{ ...@@ -5,7 +5,7 @@ use next_core::{
app_segment_config::NextSegmentConfig, app_segment_config::NextSegmentConfig,
app_structure::{ app_structure::{
get_entrypoints, AppPageLoaderTree, Entrypoint as AppEntrypoint, get_entrypoints, AppPageLoaderTree, Entrypoint as AppEntrypoint,
Entrypoints as AppEntrypoints, MetadataItem, Entrypoints as AppEntrypoints, FileSystemPathVec, MetadataItem,
}, },
get_edge_resolve_options_context, get_next_package, get_edge_resolve_options_context, get_next_package,
next_app::{ next_app::{
...@@ -705,7 +705,7 @@ enum AppEndpointType { ...@@ -705,7 +705,7 @@ enum AppEndpointType {
}, },
Route { Route {
path: Vc<FileSystemPath>, path: Vc<FileSystemPath>,
root_layouts: Vc<Vec<Vc<FileSystemPath>>>, root_layouts: Vc<FileSystemPathVec>,
}, },
Metadata { Metadata {
metadata: MetadataItem, metadata: MetadataItem,
...@@ -737,7 +737,7 @@ impl AppEndpoint { ...@@ -737,7 +737,7 @@ impl AppEndpoint {
async fn app_route_entry( async fn app_route_entry(
&self, &self,
path: Vc<FileSystemPath>, path: Vc<FileSystemPath>,
root_layouts: Vc<Vec<Vc<FileSystemPath>>>, root_layouts: Vc<FileSystemPathVec>,
next_config: Vc<NextConfig>, next_config: Vc<NextConfig>,
) -> Result<Vc<AppEntry>> { ) -> Result<Vc<AppEntry>> {
let root_layouts = root_layouts.await?; let root_layouts = root_layouts.await?;
...@@ -747,7 +747,7 @@ impl AppEndpoint { ...@@ -747,7 +747,7 @@ impl AppEndpoint {
let mut config = NextSegmentConfig::default(); let mut config = NextSegmentConfig::default();
for layout in root_layouts.iter().rev() { for layout in root_layouts.iter().rev() {
let source = Vc::upcast(FileSource::new(*layout)); let source = Vc::upcast(FileSource::new(**layout));
let layout_config = parse_segment_config_from_source(source); let layout_config = parse_segment_config_from_source(source);
config.apply_parent_config(&*layout_config.await?); config.apply_parent_config(&*layout_config.await?);
} }
......
...@@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize}; ...@@ -11,7 +11,7 @@ use serde::{Deserialize, Serialize};
use tracing::Instrument; use tracing::Instrument;
use turbo_tasks::{ use turbo_tasks::{
debug::ValueDebugFormat, trace::TraceRawVcs, RcStr, ResolvedVc, TaskInput, TryJoinIterExt, debug::ValueDebugFormat, trace::TraceRawVcs, RcStr, ResolvedVc, TaskInput, TryJoinIterExt,
ValueToString, Vc, ValueDefault, 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::{
...@@ -467,6 +467,17 @@ impl AppPageLoaderTree { ...@@ -467,6 +467,17 @@ impl AppPageLoaderTree {
} }
} }
#[turbo_tasks::value(transparent)]
pub struct FileSystemPathVec(Vec<ResolvedVc<FileSystemPath>>);
#[turbo_tasks::value_impl]
impl ValueDefault for FileSystemPathVec {
#[turbo_tasks::function]
fn value_default() -> Vc<Self> {
Vc::cell(Vec::new())
}
}
#[derive( #[derive(
Clone, Clone,
PartialEq, PartialEq,
...@@ -487,7 +498,7 @@ pub enum Entrypoint { ...@@ -487,7 +498,7 @@ pub enum Entrypoint {
AppRoute { AppRoute {
page: AppPage, page: AppPage,
path: ResolvedVc<FileSystemPath>, path: ResolvedVc<FileSystemPath>,
root_layouts: ResolvedVc<Vec<Vc<FileSystemPath>>>, root_layouts: ResolvedVc<FileSystemPathVec>,
}, },
AppMetadata { AppMetadata {
page: AppPage, page: AppPage,
...@@ -615,7 +626,7 @@ fn add_app_route( ...@@ -615,7 +626,7 @@ fn add_app_route(
result: &mut IndexMap<AppPath, Entrypoint>, result: &mut IndexMap<AppPath, Entrypoint>,
page: AppPage, page: AppPage,
path: ResolvedVc<FileSystemPath>, path: ResolvedVc<FileSystemPath>,
root_layouts: ResolvedVc<Vec<Vc<FileSystemPath>>>, root_layouts: ResolvedVc<FileSystemPathVec>,
) { ) {
let e = match result.entry(page.clone().into()) { let e = match result.entry(page.clone().into()) {
Entry::Occupied(e) => e, Entry::Occupied(e) => e,
...@@ -709,7 +720,7 @@ fn directory_tree_to_entrypoints( ...@@ -709,7 +720,7 @@ fn directory_tree_to_entrypoints(
app_dir: Vc<FileSystemPath>, app_dir: Vc<FileSystemPath>,
directory_tree: Vc<DirectoryTree>, directory_tree: Vc<DirectoryTree>,
global_metadata: Vc<GlobalMetadata>, global_metadata: Vc<GlobalMetadata>,
root_layouts: Vc<Vec<Vc<FileSystemPath>>>, root_layouts: Vc<FileSystemPathVec>,
) -> Vc<Entrypoints> { ) -> Vc<Entrypoints> {
directory_tree_to_entrypoints_internal( directory_tree_to_entrypoints_internal(
app_dir, app_dir,
...@@ -792,6 +803,9 @@ fn check_duplicate( ...@@ -792,6 +803,9 @@ fn check_duplicate(
} }
} }
#[turbo_tasks::value(transparent)]
struct AppPageLoaderTreeOption(Option<ResolvedVc<AppPageLoaderTree>>);
/// creates the loader tree for a specific route (pathname / [AppPath]) /// creates the loader tree for a specific route (pathname / [AppPath])
#[turbo_tasks::function] #[turbo_tasks::function]
async fn directory_tree_to_loader_tree( async fn directory_tree_to_loader_tree(
...@@ -802,7 +816,7 @@ async fn directory_tree_to_loader_tree( ...@@ -802,7 +816,7 @@ async fn directory_tree_to_loader_tree(
app_page: AppPage, app_page: AppPage,
// the page this loader tree is constructed for // the page this loader tree is constructed for
for_app_path: AppPath, for_app_path: AppPath,
) -> Result<Vc<Option<Vc<AppPageLoaderTree>>>> { ) -> Result<Vc<AppPageLoaderTreeOption>> {
let plain_tree = &*directory_tree.into_plain().await?; let plain_tree = &*directory_tree.into_plain().await?;
let tree = directory_tree_to_loader_tree_internal( let tree = directory_tree_to_loader_tree_internal(
...@@ -814,7 +828,7 @@ async fn directory_tree_to_loader_tree( ...@@ -814,7 +828,7 @@ async fn directory_tree_to_loader_tree(
for_app_path, for_app_path,
)?; )?;
Ok(Vc::cell(tree.map(|tree| tree.cell()))) Ok(Vc::cell(tree.map(AppPageLoaderTree::resolved_cell)))
} }
fn directory_tree_to_loader_tree_internal( fn directory_tree_to_loader_tree_internal(
...@@ -1044,7 +1058,7 @@ async fn directory_tree_to_entrypoints_internal( ...@@ -1044,7 +1058,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: ResolvedVc<Vec<Vc<FileSystemPath>>>, root_layouts: ResolvedVc<FileSystemPathVec>,
) -> 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(
...@@ -1065,7 +1079,7 @@ async fn directory_tree_to_entrypoints_internal_untraced( ...@@ -1065,7 +1079,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: ResolvedVc<Vec<Vc<FileSystemPath>>>, root_layouts: ResolvedVc<FileSystemPathVec>,
) -> Result<Vc<Entrypoints>> { ) -> Result<Vc<Entrypoints>> {
let mut result = IndexMap::new(); let mut result = IndexMap::new();
...@@ -1078,8 +1092,8 @@ async fn directory_tree_to_entrypoints_internal_untraced( ...@@ -1078,8 +1092,8 @@ async fn directory_tree_to_entrypoints_internal_untraced(
// segment config. https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes#segment-runtime-option // segment config. https://nextjs.org/docs/app/building-your-application/rendering/edge-and-nodejs-runtimes#segment-runtime-option
// Pass down layouts from each tree to apply segment config when adding route. // Pass down layouts from each tree to apply segment config when adding route.
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_value();
layouts.push(layout); layouts.push(layout.to_resolved().await?);
ResolvedVc::cell(layouts) ResolvedVc::cell(layouts)
} else { } else {
root_layouts root_layouts
......
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