diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-04-11 21:27:53 +0200 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2025-05-01 10:20:31 +0200 |
| commit | d3ec14bbec7d3647a3c1a3bfdf2cafb0f72bf937 (patch) | |
| tree | 4485d31b3edeee71a11a188090a62f5178dbd8fb /compiler/rustc_data_structures/src/sync | |
| parent | 6e23095adf9209614a45f7f75fea36dad7b92afb (diff) | |
| download | rust-d3ec14bbec7d3647a3c1a3bfdf2cafb0f72bf937.tar.gz rust-d3ec14bbec7d3647a3c1a3bfdf2cafb0f72bf937.zip | |
Use thread local dep graph encoding
Diffstat (limited to 'compiler/rustc_data_structures/src/sync')
| -rw-r--r-- | compiler/rustc_data_structures/src/sync/parallel.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/sync/parallel.rs b/compiler/rustc_data_structures/src/sync/parallel.rs index 64db39cc4c6..ab65c7f3a6b 100644 --- a/compiler/rustc_data_structures/src/sync/parallel.rs +++ b/compiler/rustc_data_structures/src/sync/parallel.rs @@ -237,3 +237,13 @@ pub fn par_map<I: DynSend, T: IntoIterator<Item = I>, R: DynSend, C: FromIterato } }) } + +pub fn broadcast<R: DynSend>(op: impl Fn(usize) -> R + DynSync) -> Vec<R> { + if mode::is_dyn_thread_safe() { + let op = FromDyn::from(op); + let results = rayon_core::broadcast(|context| op.derive(op(context.index()))); + results.into_iter().map(|r| r.into_inner()).collect() + } else { + vec![op(0)] + } +} |
