11use rustc_index:: IndexVec ;
2- use rustc_middle:: mir:: coverage:: { BlockMarkerId , BranchSpan , CoverageInfoHi , CoverageKind } ;
2+ use rustc_middle:: mir:: coverage:: {
3+ BlockMarkerId , BranchSpan , CoverageInfoHi , CoverageKind , Mapping , MappingKind ,
4+ } ;
35use rustc_middle:: mir:: { self , BasicBlock , StatementKind } ;
46use rustc_middle:: ty:: TyCtxt ;
5- use rustc_span:: Span ;
67
7- use crate :: coverage:: graph:: { BasicCoverageBlock , CoverageGraph } ;
8+ use crate :: coverage:: graph:: CoverageGraph ;
89use crate :: coverage:: hir_info:: ExtractedHirInfo ;
910use crate :: coverage:: spans:: extract_refined_covspans;
1011use crate :: coverage:: unexpand:: unexpand_into_body_span;
1112
12- /// Associates an ordinary executable code span with its corresponding BCB.
13- #[ derive( Debug ) ]
14- pub ( super ) struct CodeMapping {
15- pub ( super ) span : Span ,
16- pub ( super ) bcb : BasicCoverageBlock ,
17- }
18-
19- #[ derive( Debug ) ]
20- pub ( super ) struct BranchPair {
21- pub ( super ) span : Span ,
22- pub ( super ) true_bcb : BasicCoverageBlock ,
23- pub ( super ) false_bcb : BasicCoverageBlock ,
24- }
25-
2613#[ derive( Default ) ]
27- pub ( super ) struct ExtractedMappings {
28- pub ( super ) code_mappings : Vec < CodeMapping > ,
29- pub ( super ) branch_pairs : Vec < BranchPair > ,
14+ pub ( crate ) struct ExtractedMappings {
15+ pub ( crate ) mappings : Vec < Mapping > ,
3016}
3117
32- /// Extracts coverage-relevant spans from MIR, and associates them with
33- /// their corresponding BCBs .
34- pub ( super ) fn extract_all_mapping_info_from_mir < ' tcx > (
18+ /// Extracts coverage-relevant spans from MIR, and uses them to create
19+ /// coverage mapping data for inclusion in MIR .
20+ pub ( crate ) fn extract_mappings_from_mir < ' tcx > (
3521 tcx : TyCtxt < ' tcx > ,
3622 mir_body : & mir:: Body < ' tcx > ,
3723 hir_info : & ExtractedHirInfo ,
3824 graph : & CoverageGraph ,
3925) -> ExtractedMappings {
40- let mut code_mappings = vec ! [ ] ;
41- let mut branch_pairs = vec ! [ ] ;
26+ let mut mappings = vec ! [ ] ;
4227
4328 // Extract ordinary code mappings from MIR statement/terminator spans.
44- extract_refined_covspans ( tcx, mir_body, hir_info, graph, & mut code_mappings ) ;
29+ extract_refined_covspans ( tcx, mir_body, hir_info, graph, & mut mappings ) ;
4530
46- branch_pairs . extend ( extract_branch_pairs ( mir_body, hir_info, graph) ) ;
31+ extract_branch_mappings ( mir_body, hir_info, graph, & mut mappings ) ;
4732
48- ExtractedMappings { code_mappings , branch_pairs }
33+ ExtractedMappings { mappings }
4934}
5035
5136fn resolve_block_markers (
@@ -69,19 +54,18 @@ fn resolve_block_markers(
6954 block_markers
7055}
7156
72- pub ( super ) fn extract_branch_pairs (
57+ pub ( super ) fn extract_branch_mappings (
7358 mir_body : & mir:: Body < ' _ > ,
7459 hir_info : & ExtractedHirInfo ,
7560 graph : & CoverageGraph ,
76- ) -> Vec < BranchPair > {
77- let Some ( coverage_info_hi) = mir_body. coverage_info_hi . as_deref ( ) else { return vec ! [ ] } ;
61+ mappings : & mut Vec < Mapping > ,
62+ ) {
63+ let Some ( coverage_info_hi) = mir_body. coverage_info_hi . as_deref ( ) else { return } ;
7864
7965 let block_markers = resolve_block_markers ( coverage_info_hi, mir_body) ;
8066
81- coverage_info_hi
82- . branch_spans
83- . iter ( )
84- . filter_map ( |& BranchSpan { span : raw_span, true_marker, false_marker } | {
67+ mappings. extend ( coverage_info_hi. branch_spans . iter ( ) . filter_map (
68+ |& BranchSpan { span : raw_span, true_marker, false_marker } | try {
8569 // For now, ignore any branch span that was introduced by
8670 // expansion. This makes things like assert macros less noisy.
8771 if !raw_span. ctxt ( ) . outer_expn_data ( ) . is_root ( ) {
@@ -94,7 +78,7 @@ pub(super) fn extract_branch_pairs(
9478 let true_bcb = bcb_from_marker ( true_marker) ?;
9579 let false_bcb = bcb_from_marker ( false_marker) ?;
9680
97- Some ( BranchPair { span, true_bcb, false_bcb } )
98- } )
99- . collect :: < Vec < _ > > ( )
81+ Mapping { span, kind : MappingKind :: Branch { true_bcb, false_bcb } }
82+ } ,
83+ ) ) ;
10084}
0 commit comments