about summary refs log tree commit diff
path: root/src/librustc_data_structures/sync.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/librustc_data_structures/sync.rs')
-rw-r--r--src/librustc_data_structures/sync.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/librustc_data_structures/sync.rs b/src/librustc_data_structures/sync.rs
index cae3087fe58..7fef1f374d6 100644
--- a/src/librustc_data_structures/sync.rs
+++ b/src/librustc_data_structures/sync.rs
@@ -127,6 +127,13 @@ cfg_if! {
         pub use self::serial_join as join;
         pub use self::serial_scope as scope;
 
+        #[macro_export]
+        macro_rules! parallel {
+            ($($blocks:tt),*) => {
+                $($blocks)*;
+            }
+        }
+
         pub use std::iter::Iterator as ParallelIterator;
 
         pub fn par_iter<T: IntoIterator>(t: T) -> T::IntoIter {
@@ -271,6 +278,26 @@ cfg_if! {
         use std::thread;
         pub use rayon::{join, scope};
 
+        #[macro_export]
+        macro_rules! parallel {
+            (impl [$($c:tt,)*] [$block:tt $(, $rest:tt)*]) => {
+                parallel!(impl [$block, $($c,)*] [$($rest),*])
+            };
+            (impl [$($blocks:tt,)*] []) => {
+                ::rustc_data_structures::sync::scope(|s| {
+                    $(
+                        s.spawn(|_| $blocks);
+                    )*
+                })
+            };
+            ($($blocks:tt),*) => {
+                // Reverse the order of the blocks since Rayon executes them in reverse order
+                // when using a single thread. This ensures the execution order matches that
+                // of a single threaded rustc
+                parallel!(impl [] [$($blocks),*]);
+            };
+        }
+
         pub use rayon_core::WorkerLocal;
 
         pub use rayon::iter::ParallelIterator;