Skip to content

Commit f89016d

Browse files
authored
Turbopack: improve eventual consistency (#86682)
as always..
1 parent daa822c commit f89016d

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::hash_map::Entry;
22

3-
use anyhow::{Result, bail};
3+
use anyhow::{Context, Result, bail};
44
use auto_hash_map::AutoSet;
55
use rustc_hash::{FxHashMap, FxHashSet};
66
use tracing::Instrument;
@@ -140,7 +140,9 @@ pub async fn compute_binding_usage_info(
140140
// If the current edge is an unused import, skip it
141141
match &ref_data.binding_usage.import {
142142
ImportUsage::Exports(exports) => {
143-
let source_used_exports = used_exports.get(&parent).unwrap();
143+
let source_used_exports = used_exports
144+
.get(&parent)
145+
.context("parent module must have usage info")?;
144146
if exports
145147
.iter()
146148
.all(|e| !source_used_exports.is_export_used(e))

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

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,13 @@ pub async fn compute_module_batches(
449449
|v| Either::Right(v.iter().copied()),
450450
)
451451
.map(|module| {
452-
let idx = *pre_batches.entries.get(&module).unwrap();
453-
(idx, 0)
452+
let idx = *pre_batches
453+
.entries
454+
.get(&module)
455+
.context("could not prebatch for module")?;
456+
Ok((idx, 0))
454457
})
455-
.collect::<Vec<_>>();
458+
.collect::<Result<Vec<_>>>()?;
456459
stack.reverse();
457460
let mut visited = FxHashSet::default();
458461
while let Some((idx, mut pos)) = stack.pop() {
@@ -501,7 +504,7 @@ pub async fn compute_module_batches(
501504
let idx = chunk_group_info
502505
.chunk_group_keys
503506
.get_index_of(&chunk_group_key)
504-
.unwrap();
507+
.context("could not find chunk group key for merged chunk group")?;
505508
ordered_entries[idx] = Some(merged_modules);
506509
}
507510
}
@@ -536,7 +539,9 @@ pub async fn compute_module_batches(
536539
let mut extracted_shared_items = 0;
537540
// Extract shared modules into separate batches
538541
for i in 0..parallel_module_to_pre_batch.len() {
539-
let (&module, batches) = parallel_module_to_pre_batch.get_index(i).unwrap();
542+
let (&module, batches) = parallel_module_to_pre_batch
543+
.get_index(i)
544+
.context("could not find parallel module to pre batch index")?;
540545
if batches.len() > 1 {
541546
// Create a new batch for the shared modules
542547
let batches_with_item_index = batches
@@ -545,10 +550,10 @@ pub async fn compute_module_batches(
545550
let batch_items = &pre_batches.batches[idx].items;
546551
let item_idx = batch_items
547552
.get_index_of(&PreBatchItem::ParallelModule(module))
548-
.unwrap();
549-
(idx, item_idx)
553+
.context("could not find batch item index for parallel module")?;
554+
Ok((idx, item_idx))
550555
})
551-
.collect::<Vec<_>>();
556+
.collect::<Result<Vec<_>>>()?;
552557
let mut selected_items = 1;
553558
fn get_item_at(
554559
pre_batches: &PreBatches,
@@ -564,7 +569,10 @@ pub async fn compute_module_batches(
564569
&pre_batches,
565570
batches_with_item_index[0].0,
566571
batches_with_item_index[0].1 + selected_items,
567-
) && parallel_module_to_pre_batch.get(next_module).unwrap().len()
572+
) && parallel_module_to_pre_batch
573+
.get(next_module)
574+
.context("could not find pre batch for parallel module")?
575+
.len()
568576
== batches.len()
569577
&& batches_with_item_index[1..]
570578
.iter()
@@ -602,7 +610,7 @@ pub async fn compute_module_batches(
602610
if let PreBatchItem::ParallelModule(module) = item {
603611
parallel_module_to_pre_batch
604612
.get_mut(module)
605-
.unwrap()
613+
.context("could not find pre batch for parallel module")?
606614
.clear();
607615
}
608616
}
@@ -624,7 +632,7 @@ pub async fn compute_module_batches(
624632
if let PreBatchItem::ParallelModule(module) = item {
625633
parallel_module_to_pre_batch
626634
.get_mut(module)
627-
.unwrap()
635+
.context("could not find pre batch for parallel module")?
628636
.clear();
629637
}
630638
}
@@ -852,7 +860,7 @@ pub async fn compute_module_batches(
852860
let idx = pre_batches
853861
.single_module_entries
854862
.get_index_of(&module)
855-
.unwrap();
863+
.context("could not find single module entry index")?;
856864
let idx = single_module_indices[idx];
857865
graph.add_edge(
858866
index,
@@ -882,7 +890,7 @@ pub async fn compute_module_batches(
882890
let idx = pre_batches
883891
.single_module_entries
884892
.get_index_of(&module)
885-
.unwrap();
893+
.context("could not find single module entry index")?;
886894
let idx = single_module_indices[idx];
887895
entries.insert(module, idx);
888896
}

0 commit comments

Comments
 (0)