diff options
Diffstat (limited to 'compiler/rustc_mir_transform/src/coverage/query.rs')
| -rw-r--r-- | compiler/rustc_mir_transform/src/coverage/query.rs | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/compiler/rustc_mir_transform/src/coverage/query.rs b/compiler/rustc_mir_transform/src/coverage/query.rs index cd89fbe772d..ef86358b205 100644 --- a/compiler/rustc_mir_transform/src/coverage/query.rs +++ b/compiler/rustc_mir_transform/src/coverage/query.rs @@ -123,11 +123,20 @@ fn coverage_ids_info<'tcx>( } } - // FIXME(Zalathar): It should be possible to sort `priority_list[1..]` by - // `!bcbs_seen.contains(bcb)` to simplify the mappings even further, at the - // expense of some churn in the tests. When doing so, also consider removing - // the sorts in `transcribe_counters`. - let node_counters = make_node_counters(&fn_cov_info.node_flow_data, &fn_cov_info.priority_list); + // Clone the priority list so that we can re-sort it. + let mut priority_list = fn_cov_info.priority_list.clone(); + // The first ID in the priority list represents the synthetic "sink" node, + // and must remain first so that it _never_ gets a physical counter. + debug_assert_eq!(priority_list[0], priority_list.iter().copied().max().unwrap()); + assert!(!bcbs_seen.contains(priority_list[0])); + // Partition the priority list, so that unreachable nodes (removed by MIR opts) + // are sorted later and therefore are _more_ likely to get a physical counter. + // This is counter-intuitive, but it means that `transcribe_counters` can + // easily skip those unused physical counters and replace them with zero. + // (The original ordering remains in effect within both partitions.) + priority_list[1..].sort_by_key(|&bcb| !bcbs_seen.contains(bcb)); + + let node_counters = make_node_counters(&fn_cov_info.node_flow_data, &priority_list); let coverage_counters = transcribe_counters(&node_counters, &bcb_needs_counter, &bcbs_seen); let CoverageCounters { |
