From 4f88aa0fbd71b67be4a4910d312015ddc2a654ff Mon Sep 17 00:00:00 2001 From: Zalathar Date: Wed, 30 Aug 2023 20:08:13 +1000 Subject: [PATCH] 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 will also perform its own stable sort on these mappings, but that sort only compares file ID, start location, and `RegionKind`.) --- compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs index 5e897241cbb..1ad4b249947 100644 --- a/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs +++ b/compiler/rustc_codegen_llvm/src/coverageinfo/mapgen.rs @@ -180,7 +180,7 @@ fn write_coverage_mapping<'a>( // `file_id` (indexing files referenced by the current function), and construct the // function-specific `virtual_file_mapping` from `file_id` to its index in the module's // `filenames` array. - counter_regions.sort_unstable_by_key(|(_counter, region)| *region); + counter_regions.sort_by_key(|(_counter, region)| *region); for (counter, region) in counter_regions { let CodeRegion { file_name, start_line, start_col, end_line, end_col } = *region; let same_file = current_file_name.is_some_and(|p| p == file_name);