Unverified Commit 28c9eefa authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: iter_reachable_modules (#93315)

Add `iter_reachable_modules` and `iter_reachable_nodes`. They actually respect unused references
parent 6d2cb42f
......@@ -31,9 +31,9 @@ pub struct ClientReferenceData(FxHashMap<ResolvedVc<Box<dyn Module>>, ClientMani
pub async fn map_client_references(
graph: ResolvedVc<ModuleGraphLayer>,
) -> Result<Vc<ClientReferenceData>> {
let graph = graph.await?;
let manifest = graph
.iter_nodes()
.await?
.iter_reachable_modules()?
.map(|module| async move {
if let Some(client_reference_module) =
ResolvedVc::try_downcast_type::<EcmascriptClientReferenceModule>(module)
......
......@@ -123,7 +123,7 @@ pub async fn map_next_dynamic(
let actions =
graph
.await?
.iter_nodes()
.iter_reachable_modules()?
.map(|module| async move {
if let Some(dynamic_entry_module) =
ResolvedVc::try_downcast_type::<NextDynamicEntryModule>(module)
......
......@@ -527,7 +527,7 @@ pub async fn map_server_actions(
) -> Result<Vc<AllModuleActions>> {
let actions = graph
.await?
.iter_nodes()
.iter_reachable_modules()?
.map(async |module| {
// TODO: compare module contexts instead?
let layer = match module.ident().await?.layer.as_ref() {
......
......@@ -4,7 +4,7 @@ use turbo_tasks::{OperationVc, ResolvedVc, TryFlatJoinIterExt, Vc};
use crate::{
module::Module,
module_graph::{GraphTraversalAction, ModuleGraph, ModuleGraphLayer},
module_graph::{GraphTraversalAction, ModuleGraph, ModuleGraphLayer, SingleModuleGraphNode},
};
/// This lists all the modules that are async (self or transitively because they reference another
......@@ -44,13 +44,11 @@ async fn compute_async_module_info_single(
};
let graph = graph.read_strongly_consistent().await?;
let self_async_modules = graph
.enumerate_nodes()
.map(async |(_, node)| {
.iter_reachable_nodes()?
.map(async |node| {
Ok(match node {
super::SingleModuleGraphNode::Module(node) => {
node.is_self_async().await?.then_some(*node)
}
super::SingleModuleGraphNode::VisitedModule { idx: _, module } => {
SingleModuleGraphNode::Module(node) => node.is_self_async().await?.then_some(*node),
SingleModuleGraphNode::VisitedModule { idx: _, module } => {
// If a module is async in the parent then we need to mark reverse dependencies
// async in this graph as well.
parent_async_modules
......
......@@ -140,7 +140,7 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
let inner_span = tracing::info_span!("collect mergeable modules");
let mergeable = module_graph
.iter_nodes()
.iter_reachable_modules()?
.map(async |module| {
if let Some(mergeable) =
ResolvedVc::try_downcast::<Box<dyn MergeableModule>>(module)
......
......@@ -4,7 +4,7 @@ use turbo_tasks::{ResolvedVc, TryJoinIterExt, Vc};
use crate::{
module::{Module, ModuleSideEffects},
module_graph::{GraphTraversalAction, ModuleGraph, ModuleGraphLayer},
module_graph::{GraphTraversalAction, ModuleGraph, ModuleGraphLayer, SingleModuleGraphNode},
};
/// This lists all the modules that are side effect free
......@@ -43,16 +43,16 @@ async fn compute_side_effect_free_module_info_single(
let parent_side_effect_free_modules = parent_side_effect_free_modules.await?;
let graph = graph.await?;
let module_side_effects = graph
.enumerate_nodes()
.map(async |(_, node)| {
.iter_reachable_nodes()?
.map(async |node| {
Ok(match node {
super::SingleModuleGraphNode::Module(module) => {
SingleModuleGraphNode::Module(module) => {
// This turbo task always has a cache hit since it is called when building the
// module graph. we could consider moving this information
// into to the module graph, but then changes would invalidate the whole graph.
(*module, *module.side_effects().await?)
}
super::SingleModuleGraphNode::VisitedModule { idx: _, module } => (
SingleModuleGraphNode::VisitedModule { idx: _, module } => (
*module,
if parent_side_effect_free_modules.contains(module) {
ModuleSideEffects::SideEffectFree
......
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