Unverified Commit f89016d7 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by GitHub

Turbopack: improve eventual consistency (#86682)

as always..
parent daa822c5
use std::collections::hash_map::Entry;
use anyhow::{Result, bail};
use anyhow::{Context, Result, bail};
use auto_hash_map::AutoSet;
use rustc_hash::{FxHashMap, FxHashSet};
use tracing::Instrument;
......@@ -140,7 +140,9 @@ pub async fn compute_binding_usage_info(
// If the current edge is an unused import, skip it
match &ref_data.binding_usage.import {
ImportUsage::Exports(exports) => {
let source_used_exports = used_exports.get(&parent).unwrap();
let source_used_exports = used_exports
.get(&parent)
.context("parent module must have usage info")?;
if exports
.iter()
.all(|e| !source_used_exports.is_export_used(e))
......
......@@ -449,10 +449,13 @@ pub async fn compute_module_batches(
|v| Either::Right(v.iter().copied()),
)
.map(|module| {
let idx = *pre_batches.entries.get(&module).unwrap();
(idx, 0)
let idx = *pre_batches
.entries
.get(&module)
.context("could not prebatch for module")?;
Ok((idx, 0))
})
.collect::<Vec<_>>();
.collect::<Result<Vec<_>>>()?;
stack.reverse();
let mut visited = FxHashSet::default();
while let Some((idx, mut pos)) = stack.pop() {
......@@ -501,7 +504,7 @@ pub async fn compute_module_batches(
let idx = chunk_group_info
.chunk_group_keys
.get_index_of(&chunk_group_key)
.unwrap();
.context("could not find chunk group key for merged chunk group")?;
ordered_entries[idx] = Some(merged_modules);
}
}
......@@ -536,7 +539,9 @@ pub async fn compute_module_batches(
let mut extracted_shared_items = 0;
// Extract shared modules into separate batches
for i in 0..parallel_module_to_pre_batch.len() {
let (&module, batches) = parallel_module_to_pre_batch.get_index(i).unwrap();
let (&module, batches) = parallel_module_to_pre_batch
.get_index(i)
.context("could not find parallel module to pre batch index")?;
if batches.len() > 1 {
// Create a new batch for the shared modules
let batches_with_item_index = batches
......@@ -545,10 +550,10 @@ pub async fn compute_module_batches(
let batch_items = &pre_batches.batches[idx].items;
let item_idx = batch_items
.get_index_of(&PreBatchItem::ParallelModule(module))
.unwrap();
(idx, item_idx)
.context("could not find batch item index for parallel module")?;
Ok((idx, item_idx))
})
.collect::<Vec<_>>();
.collect::<Result<Vec<_>>>()?;
let mut selected_items = 1;
fn get_item_at(
pre_batches: &PreBatches,
......@@ -564,7 +569,10 @@ pub async fn compute_module_batches(
&pre_batches,
batches_with_item_index[0].0,
batches_with_item_index[0].1 + selected_items,
) && parallel_module_to_pre_batch.get(next_module).unwrap().len()
) && parallel_module_to_pre_batch
.get(next_module)
.context("could not find pre batch for parallel module")?
.len()
== batches.len()
&& batches_with_item_index[1..]
.iter()
......@@ -602,7 +610,7 @@ pub async fn compute_module_batches(
if let PreBatchItem::ParallelModule(module) = item {
parallel_module_to_pre_batch
.get_mut(module)
.unwrap()
.context("could not find pre batch for parallel module")?
.clear();
}
}
......@@ -624,7 +632,7 @@ pub async fn compute_module_batches(
if let PreBatchItem::ParallelModule(module) = item {
parallel_module_to_pre_batch
.get_mut(module)
.unwrap()
.context("could not find pre batch for parallel module")?
.clear();
}
}
......@@ -852,7 +860,7 @@ pub async fn compute_module_batches(
let idx = pre_batches
.single_module_entries
.get_index_of(&module)
.unwrap();
.context("could not find single module entry index")?;
let idx = single_module_indices[idx];
graph.add_edge(
index,
......@@ -882,7 +890,7 @@ pub async fn compute_module_batches(
let idx = pre_batches
.single_module_entries
.get_index_of(&module)
.unwrap();
.context("could not find single module entry index")?;
let idx = single_module_indices[idx];
entries.insert(module, idx);
}
......
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