Skip to content

Commit b3a040e

Browse files
committed
coverage: Use a stable sort when grouping mapped regions by file
If two or more mappings cover exactly the same region, their relative order will now be preserved from `get_expressions_and_counter_regions`, rather than being disturbed by implementation details of an unstable sort. The current order is: counter mappings, expression mappings, zero mappings. (LLVM does perform its own stable sort on the mappings, but that sort does not inspect whether the mapping uses a counter/expression/zero as its value.)
1 parent 27a46bb commit b3a040e

File tree

1 file changed

+1
-1
lines changed
  • compiler/rustc_codegen_llvm/src/coverageinfo

1 file changed

+1
-1
lines changed

compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ impl CoverageMapGenerator {
162162
// `file_id` (indexing files referenced by the current function), and construct the
163163
// function-specific `virtual_file_mapping` from `file_id` to its index in the module's
164164
// `filenames` array.
165-
counter_regions.sort_unstable_by_key(|(_counter, region)| *region);
165+
counter_regions.sort_by_key(|(_counter, region)| *region);
166166
for (counter, region) in counter_regions {
167167
let CodeRegion { file_name, start_line, start_col, end_line, end_col } = *region;
168168
let same_file = current_file_name.is_some_and(|p| p == file_name);

0 commit comments

Comments
 (0)