Skip to content

Commit 27a271b

Browse files
authored
[turbopack] Rename traverse_edges_from_entries_topological to traverse_edges_from_entries_dfs (#81481)
## Rename `traverse_edges_from_entries_topological` to `traverse_edges_from_entries_dfs` This PR renames the `traverse_edges_from_entries_topological` method to `traverse_edges_from_entries_dfs` to better reflect its actual behavior. The method performs a depth-first search traversal rather than a topological sort. The PR also: - Updates the method documentation to clarify that it performs a DFS traversal - Makes `ClientReferenceMapType` derive `Copy` for better ergonomics - Removes unnecessary `ResolvedVc::upcast` call in client references mapping - Renames some variables for clarity (`actions` → `client_references`) - Removes unused `module_graph_for_entries` function - Adds some tests for the traversal routine. Not very interesting for this traversal but should make it easier to test future traversals. These changes improve code clarity and correctness by ensuring the method name accurately describes its behavior.
1 parent a1339ec commit 27a271b

File tree

11 files changed

+334
-74
lines changed

11 files changed

+334
-74
lines changed

Cargo.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/next-api/src/client_references.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use turbopack::css::chunk::CssChunkPlaceable;
1313
use turbopack_core::{module::Module, module_graph::SingleModuleGraph};
1414

1515
#[derive(
16-
Clone, Serialize, Deserialize, Eq, PartialEq, TraceRawVcs, ValueDebugFormat, NonLocalValue,
16+
Copy, Clone, Serialize, Deserialize, Eq, PartialEq, TraceRawVcs, ValueDebugFormat, NonLocalValue,
1717
)]
1818
pub enum ClientReferenceMapType {
1919
EcmascriptClientReference {
@@ -31,7 +31,7 @@ pub struct ClientReferencesSet(FxHashMap<ResolvedVc<Box<dyn Module>>, ClientRefe
3131
pub async fn map_client_references(
3232
graph: Vc<SingleModuleGraph>,
3333
) -> Result<Vc<ClientReferencesSet>> {
34-
let actions = graph
34+
let client_references = graph
3535
.await?
3636
.iter_nodes()
3737
.map(|node| async move {
@@ -52,9 +52,9 @@ pub async fn map_client_references(
5252
{
5353
Ok(Some((
5454
module,
55-
ClientReferenceMapType::CssClientReference(ResolvedVc::upcast(
55+
ClientReferenceMapType::CssClientReference(
5656
client_reference_module.await?.client_module,
57-
)),
57+
),
5858
)))
5959
} else if let Some(server_component) =
6060
ResolvedVc::try_downcast_type::<NextServerComponentModule>(module)
@@ -69,5 +69,5 @@ pub async fn map_client_references(
6969
})
7070
.try_flat_join()
7171
.await?;
72-
Ok(Vc::cell(actions.into_iter().collect()))
72+
Ok(Vc::cell(client_references.into_iter().collect()))
7373
}

crates/next-api/src/module_graph.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ impl ClientReferencesGraph {
291291
let mut client_references_by_server_component =
292292
FxIndexMap::from_iter([(None, Vec::new())]);
293293

294-
graph.traverse_edges_from_entries_topological(
294+
graph.traverse_edges_from_entries_dfs(
295295
entries,
296296
// state_map is `module -> Option< the current so parent server component >`
297297
&mut FxHashMap::default(),

crates/next-api/src/project.rs

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -960,18 +960,6 @@ impl Project {
960960
})
961961
}
962962

963-
#[turbo_tasks::function]
964-
pub async fn module_graph_for_entries(
965-
self: Vc<Self>,
966-
entries: Vc<GraphEntries>,
967-
) -> Result<Vc<ModuleGraph>> {
968-
Ok(if *self.per_page_module_graph().await? {
969-
ModuleGraph::from_modules(entries, self.next_mode().await?.is_production())
970-
} else {
971-
*self.whole_app_module_graphs().await?.full
972-
})
973-
}
974-
975963
#[turbo_tasks::function]
976964
pub async fn whole_app_module_graphs(self: ResolvedVc<Self>) -> Result<Vc<ModuleGraphs>> {
977965
async move {

turbopack/crates/turbopack-core/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ turbo-tasks-build = { workspace = true }
5050
[dev-dependencies]
5151
rstest = { workspace = true }
5252
tokio = { workspace = true }
53+
turbo-tasks-testing = { workspace = true }
54+
turbo-tasks-backend = { workspace = true }
5355

5456
[features]
5557
default = []

turbopack/crates/turbopack-core/src/chunk/chunk_group.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ pub async fn chunk_group_content(
220220
entries.push(module_batches_graph.get_entry_index(entry).await?);
221221
}
222222

223-
module_batches_graph.traverse_edges_from_entries_topological(
223+
module_batches_graph.traverse_edges_from_entries_dfs(
224224
entries,
225225
&mut state,
226226
|parent_info, &node, state| {

turbopack/crates/turbopack-core/src/module_graph/async_module_info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ async fn compute_async_module_info_single(
7373
// modules in the SCC is async.
7474

7575
let mut async_modules = self_async_modules;
76-
graph.traverse_edges_from_entries_topological(
76+
graph.traverse_edges_from_entries_dfs(
7777
graph.entry_modules(),
7878
&mut (),
7979
|_, _, _| Ok(GraphTraversalAction::Continue),

turbopack/crates/turbopack-core/src/module_graph/merged_modules.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
251251
let mut visited = FxHashSet::default();
252252

253253
module_graph
254-
.traverse_edges_from_entries_topological(
254+
.traverse_edges_from_entries_dfs(
255255
chunk_group.entries(),
256256
&mut (),
257257
|parent_info, node, _| {
@@ -332,7 +332,7 @@ pub async fn compute_merged_modules(module_graph: Vc<ModuleGraph>) -> Result<Vc<
332332
FxHashSet::with_capacity_and_hasher(module_merged_groups.len(), Default::default());
333333

334334
module_graph
335-
.traverse_edges_from_entries_topological(
335+
.traverse_edges_from_entries_dfs(
336336
entries,
337337
&mut (),
338338
|_, _, _| Ok(GraphTraversalAction::Continue),

0 commit comments

Comments
 (0)