Unverified Commit 08bd8fb0 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: simplify `ReducedGraphs` and `find_server_entries` (#81118)

- Renamed `ReducedGraphs` to `GlobalInformation`, these graphs never ended up getting reduced
- Simplify and rename `VisitClientReference`, as its only remaining use is finding server entries (layout segments), and not client references anymore.
parent 354900cd
...@@ -76,7 +76,7 @@ use crate::{ ...@@ -76,7 +76,7 @@ use crate::{
dynamic_imports::{NextDynamicChunkAvailability, collect_next_dynamic_chunks}, dynamic_imports::{NextDynamicChunkAvailability, collect_next_dynamic_chunks},
font::create_font_manifest, font::create_font_manifest,
loadable_manifest::create_react_loadable_manifest, loadable_manifest::create_react_loadable_manifest,
module_graph::get_reduced_graphs_for_endpoint, module_graph::get_global_information_for_endpoint,
nft_json::NftJsonAsset, nft_json::NftJsonAsset,
paths::{ paths::{
all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root, all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root,
...@@ -1261,15 +1261,15 @@ impl AppEndpoint { ...@@ -1261,15 +1261,15 @@ impl AppEndpoint {
} }
let client_shared_availability_info = client_shared_chunk_group.availability_info; let client_shared_availability_info = client_shared_chunk_group.availability_info;
let reduced_graphs = get_reduced_graphs_for_endpoint( let global_information = get_global_information_for_endpoint(
*module_graphs.base, *module_graphs.base,
*project.per_page_module_graph().await?, *project.per_page_module_graph().await?,
); );
let next_dynamic_imports = reduced_graphs let next_dynamic_imports = global_information
.get_next_dynamic_imports_for_endpoint(*rsc_entry) .get_next_dynamic_imports_for_endpoint(*rsc_entry)
.await?; .await?;
let client_references = reduced_graphs let client_references = global_information
.get_client_references_for_endpoint( .get_client_references_for_endpoint(
*rsc_entry, *rsc_entry,
matches!(this.ty, AppEndpointType::Page { .. }), matches!(this.ty, AppEndpointType::Page { .. }),
...@@ -1419,7 +1419,7 @@ impl AppEndpoint { ...@@ -1419,7 +1419,7 @@ impl AppEndpoint {
} }
} }
let actions = reduced_graphs.get_server_actions_for_endpoint( let actions = global_information.get_server_actions_for_endpoint(
*rsc_entry, *rsc_entry,
match runtime { match runtime {
NextRuntime::Edge => Vc::upcast(this.app_project.edge_rsc_module_context()), NextRuntime::Edge => Vc::upcast(this.app_project.edge_rsc_module_context()),
...@@ -2044,7 +2044,7 @@ impl Endpoint for AppEndpoint { ...@@ -2044,7 +2044,7 @@ impl Endpoint for AppEndpoint {
let rsc_entry = app_entry.rsc_entry; let rsc_entry = app_entry.rsc_entry;
let runtime = app_entry.config.await?.runtime.unwrap_or_default(); let runtime = app_entry.config.await?.runtime.unwrap_or_default();
let actions = get_reduced_graphs_for_endpoint( let actions = get_global_information_for_endpoint(
graph, graph,
*this.app_project.project().per_page_module_graph().await?, *this.app_project.project().per_page_module_graph().await?,
) )
......
...@@ -5,7 +5,7 @@ use either::Either; ...@@ -5,7 +5,7 @@ use either::Either;
use next_core::{ use next_core::{
next_client_reference::{ next_client_reference::{
ClientReference, ClientReferenceGraphResult, ClientReferenceType, ServerEntries, ClientReference, ClientReferenceGraphResult, ClientReferenceType, ServerEntries,
VisitedClientReferenceGraphNodes, find_server_entries, find_server_entries,
}, },
next_dynamic::NextDynamicEntryModule, next_dynamic::NextDynamicEntryModule,
next_manifests::ActionLayer, next_manifests::ActionLayer,
...@@ -57,30 +57,6 @@ impl NextDynamicGraph { ...@@ -57,30 +57,6 @@ impl NextDynamicGraph {
) -> Result<Vc<Self>> { ) -> Result<Vc<Self>> {
let mapped = map_next_dynamic(*graph); let mapped = map_next_dynamic(*graph);
// TODO shrink graph here, using the information from
// - `mapped` (which lists the relevant nodes)
// - `graph.entries` (which lists the page/route/... entries we need to keep)
// This would clone the graph and allow changing the node weights. We can probably get away
// with keeping the sidecar information separate from the graph itself, though.
//
// let mut reduced_modules: FxHashMap<Vc<Box<dyn Module>>, NodeIndex<u32>> =
// FxHashMap::default(); let mut reduced_graph = DiGraph::new();
// for idx in graph.node_indices() {
// let weight = *graph.node_weight(idx).unwrap();
// let new_idx = reduced_graph.add_node(weight);
// reduced_modules.insert(weight, new_idx);
// for e in graph.edges_directed(idx, petgraph::Direction::Outgoing) {
// let target_weight = *graph.node_weight(e.target()).context("Missing
// target")?; if let Some(new_target_idx) =
// reduced_modules.get(&target_weight) {
// reduced_graph.add_edge(new_idx, *new_target_idx, ()); } else {
// let new_idx = reduced_graph.add_node(target_weight);
// reduced_modules.insert(target_weight, new_idx);
// }
// }
// }
Ok(NextDynamicGraph { Ok(NextDynamicGraph {
is_single_page, is_single_page,
graph, graph,
...@@ -185,8 +161,6 @@ impl ServerActionsGraph { ...@@ -185,8 +161,6 @@ impl ServerActionsGraph {
) -> Result<Vc<Self>> { ) -> Result<Vc<Self>> {
let mapped = map_server_actions(*graph); let mapped = map_server_actions(*graph);
// TODO shrink graph here
Ok(ServerActionsGraph { Ok(ServerActionsGraph {
is_single_page, is_single_page,
graph, graph,
...@@ -283,8 +257,6 @@ impl ClientReferencesGraph { ...@@ -283,8 +257,6 @@ impl ClientReferencesGraph {
// already, which saves us a traversal. // already, which saves us a traversal.
let mapped = map_client_references(*graph); let mapped = map_client_references(*graph);
// TODO shrink graph here
Ok(Self { Ok(Self {
is_single_page, is_single_page,
graph, graph,
...@@ -390,10 +362,6 @@ impl ClientReferencesGraph { ...@@ -390,10 +362,6 @@ impl ClientReferencesGraph {
client_references_by_server_component, client_references_by_server_component,
server_utils: vec![], server_utils: vec![],
server_component_entries: vec![], server_component_entries: vec![],
// TODO remove
visited_nodes: VisitedClientReferenceGraphNodes::empty()
.to_resolved()
.await?,
} }
.cell()) .cell())
} }
...@@ -564,20 +532,19 @@ async fn validate_pages_css_imports( ...@@ -564,20 +532,19 @@ async fn validate_pages_css_imports(
/// The consumers of this shouldn't need to care about the exact contents since it's abstracted away /// The consumers of this shouldn't need to care about the exact contents since it's abstracted away
/// by the accessor functions, but /// by the accessor functions, but
/// - In dev, contains information about the modules of the current endpoint only /// - In dev, contains information about the modules of the current endpoint only
/// - In prod, there is a single `ReducedGraphs` for the whole app, containing all pages /// - In prod, there is a single `GlobalBuildInformation` for the whole app, containing all pages
#[turbo_tasks::value] #[turbo_tasks::value]
pub struct ReducedGraphs { pub struct GlobalBuildInformation {
next_dynamic: Vec<ResolvedVc<NextDynamicGraph>>, next_dynamic: Vec<ResolvedVc<NextDynamicGraph>>,
server_actions: Vec<ResolvedVc<ServerActionsGraph>>, server_actions: Vec<ResolvedVc<ServerActionsGraph>>,
client_references: Vec<ResolvedVc<ClientReferencesGraph>>, client_references: Vec<ResolvedVc<ClientReferencesGraph>>,
// Data for some more ad-hoc operations // Data for some more ad-hoc operations
bare_graphs: ResolvedVc<ModuleGraph>, bare_graphs: ResolvedVc<ModuleGraph>,
is_single_page: bool, is_single_page: bool,
// TODO add other graphs
} }
#[turbo_tasks::value_impl] #[turbo_tasks::value_impl]
impl ReducedGraphs { impl GlobalBuildInformation {
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn new(graphs: Vc<ModuleGraph>, is_single_page: bool) -> Result<Vc<Self>> { pub async fn new(graphs: Vc<ModuleGraph>, is_single_page: bool) -> Result<Vc<Self>> {
let graphs_ref = &graphs.await?.graphs; let graphs_ref = &graphs.await?.graphs;
...@@ -809,24 +776,25 @@ impl ReducedGraphs { ...@@ -809,24 +776,25 @@ impl ReducedGraphs {
} }
#[turbo_tasks::function(operation)] #[turbo_tasks::function(operation)]
fn get_reduced_graphs_for_endpoint_inner_operation( fn get_global_information_for_endpoint_inner_operation(
module_graph: ResolvedVc<ModuleGraph>, module_graph: ResolvedVc<ModuleGraph>,
is_single_page: bool, is_single_page: bool,
) -> Vc<ReducedGraphs> { ) -> Vc<GlobalBuildInformation> {
ReducedGraphs::new(*module_graph, is_single_page) GlobalBuildInformation::new(*module_graph, is_single_page)
} }
/// Generates a [ReducedGraph] for the given project and endpoint containing information that is /// Generates a [GlobalBuildInformation] for the given project and endpoint containing information
/// either global (module ids, chunking) or computed globally as a performance optimization (client /// that is either global (module ids, chunking) or computed globally as a performance optimization
/// references, etc). /// (client references, etc).
#[turbo_tasks::function] #[turbo_tasks::function]
pub async fn get_reduced_graphs_for_endpoint( pub async fn get_global_information_for_endpoint(
module_graph: ResolvedVc<ModuleGraph>, module_graph: ResolvedVc<ModuleGraph>,
is_single_page: bool, is_single_page: bool,
) -> Result<Vc<ReducedGraphs>> { ) -> Result<Vc<GlobalBuildInformation>> {
// TODO get rid of this function once everything inside of // TODO get rid of this function once everything inside of
// `get_reduced_graphs_for_endpoint_inner` calls `take_collectibles()` when needed // `get_global_information_for_endpoint_inner` calls `take_collectibles()` when needed
let result_op = get_reduced_graphs_for_endpoint_inner_operation(module_graph, is_single_page); let result_op =
get_global_information_for_endpoint_inner_operation(module_graph, is_single_page);
let result_vc = if !is_single_page { let result_vc = if !is_single_page {
let result_vc = result_op.resolve_strongly_consistent().await?; let result_vc = result_op.resolve_strongly_consistent().await?;
let _issues = result_op.take_collectibles::<Box<dyn Issue>>(); let _issues = result_op.take_collectibles::<Box<dyn Issue>>();
......
...@@ -70,7 +70,7 @@ use crate::{ ...@@ -70,7 +70,7 @@ use crate::{
}, },
font::create_font_manifest, font::create_font_manifest,
loadable_manifest::create_react_loadable_manifest, loadable_manifest::create_react_loadable_manifest,
module_graph::get_reduced_graphs_for_endpoint, module_graph::get_global_information_for_endpoint,
nft_json::NftJsonAsset, nft_json::NftJsonAsset,
paths::{ paths::{
all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root, all_paths_in_root, all_server_paths, get_asset_paths_from_root, get_js_paths_from_root,
...@@ -1012,7 +1012,7 @@ impl PageEndpoint { ...@@ -1012,7 +1012,7 @@ impl PageEndpoint {
let client_module_graph = self.client_module_graph(); let client_module_graph = self.client_module_graph();
let reduced_graphs = get_reduced_graphs_for_endpoint( let global_information = get_global_information_for_endpoint(
client_module_graph, client_module_graph,
*project.per_page_module_graph().await?, *project.per_page_module_graph().await?,
); );
...@@ -1043,12 +1043,12 @@ impl PageEndpoint { ...@@ -1043,12 +1043,12 @@ impl PageEndpoint {
.await? .await?
.module(); .module();
reduced_graphs global_information
.validate_pages_css_imports(self.client_module(), app_module) .validate_pages_css_imports(self.client_module(), app_module)
.await?; .await?;
} }
let next_dynamic_imports = reduced_graphs let next_dynamic_imports = global_information
.get_next_dynamic_imports_for_endpoint(self.client_module()) .get_next_dynamic_imports_for_endpoint(self.client_module())
.await?; .await?;
Some((next_dynamic_imports, client_availability_info)) Some((next_dynamic_imports, client_availability_info))
......
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