Skip to content

Commit 38b0dd9

Browse files
authored
feat: passthrough panics for parallel-running futures (#2737)
1 parent dbd29d3 commit 38b0dd9

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

crates/rspack_core/src/compiler/compilation.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -922,11 +922,7 @@ impl Compilation {
922922
})
923923
.collect::<FuturesResults<_>>();
924924

925-
let chunk_ukey_and_manifest = results
926-
.into_inner()
927-
.into_iter()
928-
.collect::<std::result::Result<Vec<_>, _>>()
929-
.expect("Failed to resolve render_manifest results");
925+
let chunk_ukey_and_manifest = results.into_inner();
930926

931927
chunk_ukey_and_manifest
932928
.into_iter()
@@ -1169,8 +1165,7 @@ impl Compilation {
11691165
})
11701166
.collect::<FuturesResults<_>>()
11711167
.into_inner();
1172-
for item in chunk_hash_results {
1173-
let (chunk_ukey, hash) = item.expect("Failed to resolve chunk_hash results");
1168+
for (chunk_ukey, hash) in chunk_hash_results {
11741169
if let Some(chunk) = self.chunk_by_ukey.get_mut(&chunk_ukey) {
11751170
hash?.hash(&mut chunk.hash);
11761171
}
@@ -1271,8 +1266,7 @@ impl Compilation {
12711266
.collect::<FuturesResults<_>>()
12721267
.into_inner();
12731268

1274-
for item in hash_results {
1275-
let (chunk_ukey, hashes) = item.expect("Failed to resolve content_hash results");
1269+
for (chunk_ukey, hashes) in hash_results {
12761270
hashes?.into_iter().for_each(|hash| {
12771271
if let Some(chunk) = self.chunk_by_ukey.get_mut(&chunk_ukey) && let Some((source_type, hash)) = hash {
12781272
chunk.content_hash.insert(source_type, hash);

crates/rspack_futures/src/lib.rs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ use std::{
44
};
55

66
use async_scoped::{Scope, TokioScope};
7-
use tokio::task::JoinError;
8-
9-
type FuturesResult<T> = Vec<Result<T, JoinError>>;
107

8+
/// Run futures in parallel.
9+
///
10+
///
11+
/// # Panic
12+
///
13+
/// Panics if any task panics.
1114
///
1215
/// A rough demo of how this works:
1316
///
@@ -26,11 +29,11 @@ type FuturesResult<T> = Vec<Result<T, JoinError>>;
2629
/// ```
2730
#[derive(Default)]
2831
pub struct FuturesResults<T> {
29-
inner: FuturesResult<T>,
32+
inner: Vec<T>,
3033
}
3134

3235
impl<T> FuturesResults<T> {
33-
pub fn into_inner(self) -> FuturesResult<T> {
36+
pub fn into_inner(self) -> Vec<T> {
3437
self.inner
3538
}
3639
}
@@ -50,12 +53,26 @@ where
5053
});
5154
});
5255

53-
Self { inner }
56+
Self {
57+
inner: inner
58+
.into_iter()
59+
.map(|i| match i {
60+
Ok(i) => i,
61+
Err(err) => {
62+
if err.is_panic() {
63+
std::panic::resume_unwind(err.into_panic())
64+
} else {
65+
unreachable!("Error should be a panic {err}")
66+
}
67+
}
68+
})
69+
.collect(),
70+
}
5471
}
5572
}
5673

5774
impl<T> Deref for FuturesResults<T> {
58-
type Target = FuturesResult<T>;
75+
type Target = Vec<T>;
5976

6077
fn deref(&self) -> &Self::Target {
6178
&self.inner

crates/rspack_plugin_copy/src/lib.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,7 @@ impl CopyPlugin {
415415
return None;
416416
}
417417

418-
Some(
419-
copied_result
420-
.into_inner()
421-
.into_iter()
422-
.flat_map(|it| it.ok())
423-
.collect::<Vec<_>>(),
424-
)
418+
Some(copied_result.into_inner())
425419
}
426420
Err(e) => {
427421
if pattern.no_error_on_missing {

0 commit comments

Comments
 (0)