File tree Expand file tree Collapse file tree
compiler/rustc_data_structures/src/sync Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -128,12 +128,28 @@ fn par_slice<I: DynSend>(
128128 guard : & ParallelGuard ,
129129 for_each : impl Fn ( & mut I ) + DynSync + DynSend ,
130130) {
131+ match items {
132+ [ ] => return ,
133+ [ item] => {
134+ guard. run ( || for_each ( item) ) ;
135+ return ;
136+ }
137+ _ => ( ) ,
138+ }
139+
131140 let for_each = FromDyn :: from ( for_each) ;
132141 let mut items = for_each. derive ( items) ;
133142 rustc_thread_pool:: scope ( |s| {
134143 let proof = items. derive ( ( ) ) ;
135- let group_size = std:: cmp:: max ( items. len ( ) / 128 , 1 ) ;
136- for group in items. chunks_mut ( group_size) {
144+
145+ const MAX_GROUP_COUNT : usize = 128 ;
146+ let group_size = items. len ( ) . div_ceil ( MAX_GROUP_COUNT ) ;
147+ let groups = items. chunks_mut ( group_size) ;
148+
149+ // Reverse the order of the later functions since Rayon executes them in reverse
150+ // order when using a single thread. This ensures the execution order matches
151+ // that of a single threaded rustc.
152+ for group in groups. rev ( ) {
137153 let group = proof. derive ( group) ;
138154 s. spawn ( |_| {
139155 let mut group = group;
You can’t perform that action at this time.
0 commit comments