-
Notifications
You must be signed in to change notification settings - Fork 30.3k
Turbopack: snapshot the ModuleGraph to avoid (eventual) inconsistent graphs #88340
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
sokra
wants to merge
5
commits into
sokra/parallel-backend
Choose a base branch
from
sokra/module-graph-consistency
base: sokra/parallel-backend
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+412
−367
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
aed342a
Turbopack: pass binding info as operation to module graph
sokra 446b7ef
Turbopack: pass single module graph as operation to module graph
sokra 9067446
avoid pub fields for SingleModuleGraphWithBindingUsage
sokra 145bf7c
Turbopack: snapshot the ModuleGraph to avoid (eventual) inconsistent …
sokra 965d41d
cleanup
sokra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,7 +23,7 @@ use turbopack_core::{ | |
| context::AssetContext, | ||
| issue::{Issue, IssueExt, IssueSeverity, IssueStage, OptionStyledString, StyledString}, | ||
| module::Module, | ||
| module_graph::{GraphTraversalAction, ModuleGraph, SingleModuleGraphWithBindingUsage}, | ||
| module_graph::{GraphTraversalAction, ModuleGraph}, | ||
| }; | ||
| use turbopack_css::{CssModuleAsset, ModuleCssAsset}; | ||
|
|
||
|
|
@@ -35,7 +35,7 @@ use crate::{ | |
|
|
||
| #[turbo_tasks::value] | ||
| pub struct NextDynamicGraph { | ||
| graph: SingleModuleGraphWithBindingUsage, | ||
| graph: ResolvedVc<ModuleGraph>, | ||
| is_single_page: bool, | ||
|
|
||
| /// list of NextDynamicEntryModules | ||
|
|
@@ -52,12 +52,13 @@ impl NextDynamicGraphs { | |
| graphs: ResolvedVc<ModuleGraph>, | ||
| is_single_page: bool, | ||
| ) -> Result<Vc<Self>> { | ||
| let graphs_ref = &graphs.await?; | ||
| let graphs_ref = &graphs.iter_graphs().await?; | ||
| let next_dynamic = async { | ||
| graphs_ref | ||
| .iter_graphs() | ||
| .iter() | ||
| .map(|graph| { | ||
| NextDynamicGraph::new_with_entries(graph, is_single_page).to_resolved() | ||
| NextDynamicGraph::new_with_entries(graph.connect(), is_single_page) | ||
| .to_resolved() | ||
| }) | ||
| .try_join() | ||
| .await | ||
|
|
@@ -130,10 +131,10 @@ pub struct DynamicImportEntriesWithImporter( | |
| impl NextDynamicGraph { | ||
| #[turbo_tasks::function] | ||
| pub async fn new_with_entries( | ||
| graph: SingleModuleGraphWithBindingUsage, | ||
| graph: ResolvedVc<ModuleGraph>, | ||
| is_single_page: bool, | ||
| ) -> Result<Vc<Self>> { | ||
| let mapped = map_next_dynamic(*graph.graph); | ||
| let mapped = map_next_dynamic(*graph); | ||
|
|
||
| Ok(NextDynamicGraph { | ||
| is_single_page, | ||
|
|
@@ -151,7 +152,7 @@ impl NextDynamicGraph { | |
| let span = tracing::info_span!("collect next/dynamic imports for endpoint"); | ||
| async move { | ||
| let data = &*self.data.await?; | ||
| let graph = self.graph.read().await?; | ||
| let graph = self.graph.await?; | ||
|
|
||
| #[derive(Clone, PartialEq, Eq)] | ||
| enum VisitState { | ||
|
|
@@ -232,7 +233,7 @@ impl NextDynamicGraph { | |
|
|
||
| #[turbo_tasks::value] | ||
| pub struct ServerActionsGraph { | ||
| graph: SingleModuleGraphWithBindingUsage, | ||
| graph: ResolvedVc<ModuleGraph>, | ||
| is_single_page: bool, | ||
|
|
||
| /// (Layer, RSC or Browser module) -> list of actions | ||
|
|
@@ -249,12 +250,13 @@ impl ServerActionsGraphs { | |
| graphs: ResolvedVc<ModuleGraph>, | ||
| is_single_page: bool, | ||
| ) -> Result<Vc<Self>> { | ||
| let graphs_ref = &graphs.await?; | ||
| let graphs_ref = &graphs.iter_graphs().await?; | ||
| let server_actions = async { | ||
| graphs_ref | ||
| .iter_graphs() | ||
| .iter() | ||
| .map(|graph| { | ||
| ServerActionsGraph::new_with_entries(graph, is_single_page).to_resolved() | ||
| ServerActionsGraph::new_with_entries(graph.connect(), is_single_page) | ||
| .to_resolved() | ||
| }) | ||
| .try_join() | ||
| .await | ||
|
|
@@ -316,10 +318,10 @@ impl ServerActionsGraphs { | |
| impl ServerActionsGraph { | ||
| #[turbo_tasks::function] | ||
| pub async fn new_with_entries( | ||
| graph: SingleModuleGraphWithBindingUsage, | ||
| graph: ResolvedVc<ModuleGraph>, | ||
| is_single_page: bool, | ||
| ) -> Result<Vc<Self>> { | ||
| let mapped = map_server_actions(*graph.graph); | ||
| let mapped = map_server_actions(*graph); | ||
|
|
||
| Ok(ServerActionsGraph { | ||
| is_single_page, | ||
|
|
@@ -343,7 +345,7 @@ impl ServerActionsGraph { | |
| Cow::Borrowed(data) | ||
| } else { | ||
| // The graph contains the whole app, traverse and collect all reachable imports. | ||
| let graph = self.graph.read().await?; | ||
| let graph = self.graph.await?; | ||
|
|
||
| if !graph.graphs.first().unwrap().has_entry_module(entry) { | ||
| // the graph doesn't contain the entry, e.g. for the additional module graph | ||
|
|
@@ -407,7 +409,7 @@ impl ServerActionsGraph { | |
| #[turbo_tasks::value] | ||
| pub struct ClientReferencesGraph { | ||
| is_single_page: bool, | ||
| graph: SingleModuleGraphWithBindingUsage, | ||
| graph: ResolvedVc<ModuleGraph>, | ||
|
|
||
| /// List of client references (modules that entries into the client graph) | ||
| data: ResolvedVc<ClientReferenceData>, | ||
|
|
@@ -423,12 +425,13 @@ impl ClientReferencesGraphs { | |
| graphs: ResolvedVc<ModuleGraph>, | ||
| is_single_page: bool, | ||
| ) -> Result<Vc<Self>> { | ||
| let graphs_ref = &graphs.await?; | ||
| let graphs_ref = graphs.iter_graphs().await?; | ||
| let client_references = async { | ||
| graphs_ref | ||
| .iter_graphs() | ||
| .iter() | ||
| .map(|graph| { | ||
| ClientReferencesGraph::new_with_entries(graph, is_single_page).to_resolved() | ||
| ClientReferencesGraph::new_with_entries(graph.connect(), is_single_page) | ||
| .to_resolved() | ||
| }) | ||
| .try_join() | ||
| .await | ||
|
|
@@ -518,10 +521,10 @@ impl ClientReferencesGraphs { | |
| impl ClientReferencesGraph { | ||
| #[turbo_tasks::function] | ||
| pub async fn new_with_entries( | ||
| graph: SingleModuleGraphWithBindingUsage, | ||
| graph: ResolvedVc<ModuleGraph>, | ||
| is_single_page: bool, | ||
| ) -> Result<Vc<Self>> { | ||
| let mapped = map_client_references(*graph.graph); | ||
|
Comment on lines
518
to
-524
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Previously, the types ensured/made it obvious that this should be one of the individual stacked graphs. But not anymore, even though it's still the individual graph, as far as I can tell? |
||
| let mapped = map_client_references(*graph); | ||
|
|
||
| Ok(Self { | ||
| is_single_page, | ||
|
|
@@ -539,7 +542,7 @@ impl ClientReferencesGraph { | |
| let span = tracing::info_span!("collect client references for endpoint"); | ||
| async move { | ||
| let data = &*self.data.await?; | ||
| let graph = self.graph.read().await?; | ||
| let graph = self.graph.await?; | ||
|
|
||
| let entries = if !self.is_single_page { | ||
| if !graph.graphs.first().unwrap().has_entry_module(entry) { | ||
|
|
@@ -766,12 +769,12 @@ struct ModuleNameMap(#[bincode(with = "turbo_bincode::indexmap")] pub FxModuleNa | |
| #[tracing::instrument(level = "info", name = "validate pages css imports", skip_all)] | ||
| #[turbo_tasks::function] | ||
| async fn validate_pages_css_imports_individual( | ||
| graph: SingleModuleGraphWithBindingUsage, | ||
| graph: ResolvedVc<ModuleGraph>, | ||
| is_single_page: bool, | ||
| entry: Vc<Box<dyn Module>>, | ||
| app_module: ResolvedVc<Box<dyn Module>>, | ||
| ) -> Result<()> { | ||
| let graph = graph.read().await?; | ||
| let graph = graph.await?; | ||
| let entry = entry.to_resolved().await?; | ||
|
|
||
| let entries = if !is_single_page { | ||
|
|
@@ -869,12 +872,17 @@ pub async fn validate_pages_css_imports( | |
| entry: Vc<Box<dyn Module>>, | ||
| app_module: Vc<Box<dyn Module>>, | ||
| ) -> Result<()> { | ||
| let graphs = &graph.await?; | ||
| let graphs = graph.iter_graphs().await?; | ||
| graphs | ||
| .iter_graphs() | ||
| .iter() | ||
| .map(|graph| { | ||
| validate_pages_css_imports_individual(graph, is_single_page, entry, app_module) | ||
| .as_side_effect() | ||
| validate_pages_css_imports_individual( | ||
| graph.connect(), | ||
| is_single_page, | ||
| entry, | ||
| app_module, | ||
| ) | ||
| .as_side_effect() | ||
| }) | ||
| .try_join() | ||
| .await?; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Type mismatch in binding_usage_info assignment - closure returns Future instead of OperationVc