11use  crate :: { 
2+     component:: ComponentId , 
23    schedule:: { 
34        BoxedSystemLabel ,  ExclusiveSystemContainer ,  InsertionPoint ,  ParallelExecutor , 
45        ParallelSystemContainer ,  ParallelSystemExecutor ,  RunCriteria ,  ShouldRun , 
@@ -263,22 +264,30 @@ impl SystemStage {
263264    } 
264265
265266    /// Logs execution order ambiguities between systems. System orders must be fresh. 
266-      fn  report_ambiguities ( & self )  { 
267+      fn  report_ambiguities ( & self ,   world :   & World )  { 
267268        debug_assert ! ( !self . systems_modified) ; 
268269        use  std:: fmt:: Write ; 
269270        fn  write_display_names_of_pairs ( 
270271            string :  & mut  String , 
271272            systems :  & [ impl  SystemContainer ] , 
272-             mut  ambiguities :  Vec < ( usize ,  usize ) > , 
273+             mut  ambiguities :  Vec < ( usize ,  usize ,  Vec < ComponentId > ) > , 
274+             world :  & World , 
273275        )  { 
274-             for  ( index_a,  index_b)  in  ambiguities. drain ( ..)  { 
276+             for  ( index_a,  index_b,  conflicts )  in  ambiguities. drain ( ..)  { 
275277                writeln ! ( 
276278                    string, 
277279                    " -- {:?} and {:?}" , 
278280                    systems[ index_a] . name( ) , 
279281                    systems[ index_b] . name( ) 
280282                ) 
281283                . unwrap ( ) ; 
284+                 if  !conflicts. is_empty ( )  { 
285+                     let  names = conflicts
286+                         . iter ( ) 
287+                         . map ( |id| world. components ( ) . get_info ( * id) . unwrap ( ) . name ( ) ) 
288+                         . collect :: < Vec < _ > > ( ) ; 
289+                     writeln ! ( string,  "    conflicts: {:?}" ,  names) . unwrap ( ) ; 
290+                 } 
282291            } 
283292        } 
284293        let  parallel = find_ambiguities ( & self . parallel ) ; 
@@ -295,23 +304,29 @@ impl SystemStage {
295304                . to_owned ( ) ; 
296305            if  !parallel. is_empty ( )  { 
297306                writeln ! ( string,  " * Parallel systems:" ) . unwrap ( ) ; 
298-                 write_display_names_of_pairs ( & mut  string,  & self . parallel ,  parallel) ; 
307+                 write_display_names_of_pairs ( & mut  string,  & self . parallel ,  parallel,  world ) ; 
299308            } 
300309            if  !at_start. is_empty ( )  { 
301310                writeln ! ( string,  " * Exclusive systems at start of stage:" ) . unwrap ( ) ; 
302-                 write_display_names_of_pairs ( & mut  string,  & self . exclusive_at_start ,  at_start) ; 
311+                 write_display_names_of_pairs ( 
312+                     & mut  string, 
313+                     & self . exclusive_at_start , 
314+                     at_start, 
315+                     world, 
316+                 ) ; 
303317            } 
304318            if  !before_commands. is_empty ( )  { 
305319                writeln ! ( string,  " * Exclusive systems before commands of stage:" ) . unwrap ( ) ; 
306320                write_display_names_of_pairs ( 
307321                    & mut  string, 
308322                    & self . exclusive_before_commands , 
309323                    before_commands, 
324+                     world, 
310325                ) ; 
311326            } 
312327            if  !at_end. is_empty ( )  { 
313328                writeln ! ( string,  " * Exclusive systems at end of stage:" ) . unwrap ( ) ; 
314-                 write_display_names_of_pairs ( & mut  string,  & self . exclusive_at_end ,  at_end) ; 
329+                 write_display_names_of_pairs ( & mut  string,  & self . exclusive_at_end ,  at_end,  world ) ; 
315330            } 
316331            info ! ( "{}" ,  string) ; 
317332        } 
@@ -456,7 +471,7 @@ fn topological_order(
456471
457472/// Returns vector containing all pairs of indices of systems with ambiguous execution order. 
458473/// Systems must be topologically sorted beforehand. 
459- fn  find_ambiguities ( systems :  & [ impl  SystemContainer ] )  -> Vec < ( usize ,  usize ) >  { 
474+ fn  find_ambiguities ( systems :  & [ impl  SystemContainer ] )  -> Vec < ( usize ,  usize ,   Vec < ComponentId > ) >  { 
460475    let  mut  ambiguity_set_labels = HashMap :: default ( ) ; 
461476    for  set in  systems. iter ( ) . flat_map ( |c| c. ambiguity_sets ( ) )  { 
462477        let  len = ambiguity_set_labels. len ( ) ; 
@@ -511,9 +526,17 @@ fn find_ambiguities(systems: &[impl SystemContainer]) -> Vec<(usize, usize)> {
511526        { 
512527            if  !processed. contains ( index_b) 
513528                && all_ambiguity_sets[ index_a] . is_disjoint ( & all_ambiguity_sets[ index_b] ) 
514-                 && !systems[ index_a] . is_compatible ( & systems[ index_b] ) 
515529            { 
516-                 ambiguities. push ( ( index_a,  index_b) ) ; 
530+                 let  a_access = systems[ index_a] . component_access ( ) ; 
531+                 let  b_access = systems[ index_b] . component_access ( ) ; 
532+                 if  let  ( Some ( a) ,  Some ( b) )  = ( a_access,  b_access)  { 
533+                     let  conflicts = a. get_conflicts ( b) ; 
534+                     if  !conflicts. is_empty ( )  { 
535+                         ambiguities. push ( ( index_a,  index_b,  conflicts) ) 
536+                     } 
537+                 }  else  { 
538+                     ambiguities. push ( ( index_a,  index_b,  Vec :: new ( ) ) ) ; 
539+                 } 
517540            } 
518541        } 
519542        processed. insert ( index_a) ; 
@@ -549,7 +572,7 @@ impl Stage for SystemStage {
549572            self . executor . rebuild_cached_data ( & self . parallel ) ; 
550573            self . executor_modified  = false ; 
551574            if  world. contains_resource :: < ReportExecutionOrderAmbiguities > ( )  { 
552-                 self . report_ambiguities ( ) ; 
575+                 self . report_ambiguities ( world ) ; 
553576            } 
554577        }  else  if  self . executor_modified  { 
555578            self . executor . rebuild_cached_data ( & self . parallel ) ; 
@@ -1184,7 +1207,7 @@ mod tests {
11841207        )  -> Vec < ( BoxedSystemLabel ,  BoxedSystemLabel ) >  { 
11851208            find_ambiguities ( systems) 
11861209                . drain ( ..) 
1187-                 . map ( |( index_a,  index_b) | { 
1210+                 . map ( |( index_a,  index_b,  _conflicts ) | { 
11881211                    ( 
11891212                        systems[ index_a] . labels ( ) [ 0 ] . clone ( ) , 
11901213                        systems[ index_b] . labels ( ) [ 0 ] . clone ( ) , 
0 commit comments