Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/next-api/src/analyze.rs
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,7 @@ pub async fn analyze_module_graphs(module_graphs: Vc<ModuleGraphs>) -> Result<Vc
let mut all_edges = FxIndexSet::default();
let mut all_async_edges = FxIndexSet::default();
for &module_graph in module_graphs.await? {
let module_graph = module_graph.read_graphs().await?;
let module_graph = module_graph.await?;
module_graph.traverse_edges_unordered(|parent, node| {
if let Some((parent_node, reference)) = parent {
all_modules.insert(parent_node);
Expand Down
42 changes: 20 additions & 22 deletions crates/next-api/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -919,12 +919,12 @@ impl AppProject {
// Only propagate the visited_modules of the parent layout(s), not
// across siblings such as loading.js and
// page.js.
visited_modules.concatenate(graph)
VisitedModules::concatenate(visited_modules, graph)
} else {
// Prevents graph index from getting out of sync.
// TODO We should remove VisitedModule entirely in favor of lookups
// in SingleModuleGraph
visited_modules.with_incremented_index()
VisitedModules::with_incremented_index(visited_modules)
};
}
visited_modules
Expand All @@ -946,10 +946,10 @@ impl AppProject {
should_read_binding_usage,
);
graphs.push(graph);
visited_modules = visited_modules.concatenate(graph);
visited_modules = VisitedModules::concatenate(visited_modules, graph);

let base = ModuleGraph::from_graphs(graphs.clone());
let additional_entries = endpoint.additional_entries(base);
let additional_entries = endpoint.additional_entries(base.connect());
let additional_module_graph = SingleModuleGraph::new_with_entries_visited_intern(
additional_entries.owned().await?,
visited_modules,
Expand All @@ -958,31 +958,29 @@ impl AppProject {
);
graphs.push(additional_module_graph);

let full_with_unused_references =
ModuleGraph::from_graphs(graphs).to_resolved().await?;

let full = if *self
let remove_unused_imports = *self
.project
.next_config()
.turbopack_remove_unused_imports(next_mode)
.await?
{
full_with_unused_references
.without_unused_references(
*compute_binding_usage_info(full_with_unused_references, true)
.resolve_strongly_consistent()
.await?,
)
.to_resolved()
.await?
.await?;

let binding_usage_info = remove_unused_imports.then(|| {
compute_binding_usage_info(
ModuleGraph::from_graphs(graphs.clone()),
should_read_binding_usage,
)
});

let full = if let Some(binding_usage_info) = binding_usage_info {
ModuleGraph::from_graphs_without_unused_references(graphs, binding_usage_info)
} else {
full_with_unused_references
ModuleGraph::from_graphs(graphs)
Comment on lines +967 to +977
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let binding_usage_info = remove_unused_imports.then(|| {
compute_binding_usage_info(
ModuleGraph::from_graphs(graphs.clone()),
should_read_binding_usage,
)
});
let full = if let Some(binding_usage_info) = binding_usage_info {
ModuleGraph::from_graphs_without_unused_references(graphs, binding_usage_info)
} else {
full_with_unused_references
ModuleGraph::from_graphs(graphs)
let (full, binding_usage_info) = if remove_unused_imports {
let full_with_unused_references = ModuleGraph::from_graphs(graphs.clone());
let binding_usage_info = compute_binding_usage_info(
full_with_unused_references,
should_read_binding_usage,
);
(
ModuleGraph::from_graphs_without_unused_references(graphs, binding_usage_info),
Some(binding_usage_info),
)
} else {
(ModuleGraph::from_graphs(graphs), None)

Type mismatch in binding_usage_info assignment - closure returns Future instead of OperationVc

Fix on Vercel

};

Ok(BaseAndFullModuleGraph {
base: base.to_resolved().await?,
full_with_unused_references,
full,
base: base.connect().to_resolved().await?,
full: full.connect().to_resolved().await?,
binding_usage_info,
}
.cell())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/next-api/src/client_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_hash::FxHashMap;
use turbo_tasks::{
NonLocalValue, ResolvedVc, TryFlatJoinIterExt, Vc, debug::ValueDebugFormat, trace::TraceRawVcs,
};
use turbopack_core::{module::Module, module_graph::SingleModuleGraph};
use turbopack_core::{module::Module, module_graph::ModuleGraph};
use turbopack_css::chunk::CssChunkPlaceable;

#[derive(
Expand All @@ -29,7 +29,7 @@ pub struct ClientReferenceData(FxHashMap<ResolvedVc<Box<dyn Module>>, ClientMani

#[turbo_tasks::function]
pub async fn map_client_references(
graph: Vc<SingleModuleGraph>,
graph: ResolvedVc<ModuleGraph>,
) -> Result<Vc<ClientReferenceData>> {
let graph = graph.await?;
let manifest = graph
Expand Down
4 changes: 2 additions & 2 deletions crates/next-api/src/dynamic_imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use turbopack_core::{
availability_info::AvailabilityInfo,
},
module::Module,
module_graph::{ModuleGraph, SingleModuleGraph},
module_graph::ModuleGraph,
output::{OutputAssetsReference, OutputAssetsWithReferenced},
};

Expand Down Expand Up @@ -122,7 +122,7 @@ pub struct DynamicImportEntries(
);

#[turbo_tasks::function]
pub async fn map_next_dynamic(graph: Vc<SingleModuleGraph>) -> Result<Vc<DynamicImportEntries>> {
pub async fn map_next_dynamic(graph: ResolvedVc<ModuleGraph>) -> Result<Vc<DynamicImportEntries>> {
let actions = graph
.await?
.iter_nodes()
Expand Down
64 changes: 36 additions & 28 deletions crates/next-api/src/module_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand All @@ -35,7 +35,7 @@ use crate::{

#[turbo_tasks::value]
pub struct NextDynamicGraph {
graph: SingleModuleGraphWithBindingUsage,
graph: ResolvedVc<ModuleGraph>,
is_single_page: bool,

/// list of NextDynamicEntryModules
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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>,
Expand All @@ -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
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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,
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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?;
Expand Down
25 changes: 12 additions & 13 deletions crates/next-api/src/pages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ impl PageEndpoint {
should_read_binding_usage,
);
graphs.push(graph);
visited_modules = visited_modules.concatenate(graph);
visited_modules = VisitedModules::concatenate(visited_modules, graph);
}

let graph = SingleModuleGraph::new_with_entries_visited_intern(
Expand All @@ -747,21 +747,20 @@ impl PageEndpoint {
);
graphs.push(graph);

let mut graph = ModuleGraph::from_graphs(graphs);

if *project
let remove_unused_imports = *project
.next_config()
.turbopack_remove_unused_imports(next_mode)
.await?
{
graph = graph.without_unused_references(
*compute_binding_usage_info(graph.to_resolved().await?, true)
.resolve_strongly_consistent()
.await?,
);
}
.await?;

let graph = if remove_unused_imports {
let graph = ModuleGraph::from_graphs(graphs.clone());
let binding_usage_info = compute_binding_usage_info(graph, true);
ModuleGraph::from_graphs_without_unused_references(graphs, binding_usage_info)
} else {
ModuleGraph::from_graphs(graphs)
};

Ok(graph)
Ok(graph.connect())
} else {
Ok(*project.whole_app_module_graphs().await?.full)
}
Expand Down
Loading
Loading