1
1
use 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
+ } ;
3
5
use rustc_middle:: mir:: { self , BasicBlock , StatementKind } ;
4
6
use rustc_middle:: ty:: TyCtxt ;
5
- use rustc_span:: Span ;
6
7
7
- use crate :: coverage:: graph:: { BasicCoverageBlock , CoverageGraph } ;
8
+ use crate :: coverage:: graph:: CoverageGraph ;
8
9
use crate :: coverage:: hir_info:: ExtractedHirInfo ;
9
10
use crate :: coverage:: spans:: extract_refined_covspans;
10
11
use crate :: coverage:: unexpand:: unexpand_into_body_span;
11
12
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
-
26
13
#[ 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 > ,
30
16
}
31
17
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 > (
35
21
tcx : TyCtxt < ' tcx > ,
36
22
mir_body : & mir:: Body < ' tcx > ,
37
23
hir_info : & ExtractedHirInfo ,
38
24
graph : & CoverageGraph ,
39
25
) -> ExtractedMappings {
40
- let mut code_mappings = vec ! [ ] ;
41
- let mut branch_pairs = vec ! [ ] ;
26
+ let mut mappings = vec ! [ ] ;
42
27
43
28
// 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 ) ;
45
30
46
- branch_pairs . extend ( extract_branch_pairs ( mir_body, hir_info, graph) ) ;
31
+ extract_branch_mappings ( mir_body, hir_info, graph, & mut mappings ) ;
47
32
48
- ExtractedMappings { code_mappings , branch_pairs }
33
+ ExtractedMappings { mappings }
49
34
}
50
35
51
36
fn resolve_block_markers (
@@ -69,19 +54,18 @@ fn resolve_block_markers(
69
54
block_markers
70
55
}
71
56
72
- pub ( super ) fn extract_branch_pairs (
57
+ pub ( super ) fn extract_branch_mappings (
73
58
mir_body : & mir:: Body < ' _ > ,
74
59
hir_info : & ExtractedHirInfo ,
75
60
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 } ;
78
64
79
65
let block_markers = resolve_block_markers ( coverage_info_hi, mir_body) ;
80
66
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 {
85
69
// For now, ignore any branch span that was introduced by
86
70
// expansion. This makes things like assert macros less noisy.
87
71
if !raw_span. ctxt ( ) . outer_expn_data ( ) . is_root ( ) {
@@ -94,7 +78,7 @@ pub(super) fn extract_branch_pairs(
94
78
let true_bcb = bcb_from_marker ( true_marker) ?;
95
79
let false_bcb = bcb_from_marker ( false_marker) ?;
96
80
97
- Some ( BranchPair { span, true_bcb, false_bcb } )
98
- } )
99
- . collect :: < Vec < _ > > ( )
81
+ Mapping { span, kind : MappingKind :: Branch { true_bcb, false_bcb } }
82
+ } ,
83
+ ) ) ;
100
84
}
0 commit comments