@@ -13,7 +13,7 @@ use rustc_hir::intravisit::{walk_expr, Visitor};
13
13
use rustc_middle:: hir:: map:: Map ;
14
14
use rustc_middle:: hir:: nested_filter;
15
15
use rustc_middle:: mir:: coverage:: {
16
- CodeRegion , CoverageKind , DecisionInfo , FunctionCoverageInfo , Mapping , MappingKind ,
16
+ CoverageKind , DecisionInfo , FunctionCoverageInfo , Mapping , MappingKind , SourceRegion ,
17
17
} ;
18
18
use rustc_middle:: mir:: {
19
19
self , BasicBlock , BasicBlockData , SourceInfo , Statement , StatementKind , Terminator ,
@@ -159,7 +159,7 @@ fn create_mappings<'tcx>(
159
159
. expect ( "all BCBs with spans were given counters" )
160
160
. as_term ( )
161
161
} ;
162
- let region_for_span = |span : Span | make_code_region ( source_map, file_name, span, body_span) ;
162
+ let region_for_span = |span : Span | make_source_region ( source_map, file_name, span, body_span) ;
163
163
164
164
// Fully destructure the mappings struct to make sure we don't miss any kinds.
165
165
let ExtractedMappings {
@@ -175,9 +175,9 @@ fn create_mappings<'tcx>(
175
175
mappings. extend ( code_mappings. iter ( ) . filter_map (
176
176
// Ordinary code mappings are the simplest kind.
177
177
|& mappings:: CodeMapping { span, bcb } | {
178
- let code_region = region_for_span ( span) ?;
178
+ let source_region = region_for_span ( span) ?;
179
179
let kind = MappingKind :: Code ( term_for_bcb ( bcb) ) ;
180
- Some ( Mapping { kind, code_region } )
180
+ Some ( Mapping { kind, source_region } )
181
181
} ,
182
182
) ) ;
183
183
@@ -186,29 +186,29 @@ fn create_mappings<'tcx>(
186
186
let true_term = term_for_bcb ( true_bcb) ;
187
187
let false_term = term_for_bcb ( false_bcb) ;
188
188
let kind = MappingKind :: Branch { true_term, false_term } ;
189
- let code_region = region_for_span ( span) ?;
190
- Some ( Mapping { kind, code_region } )
189
+ let source_region = region_for_span ( span) ?;
190
+ Some ( Mapping { kind, source_region } )
191
191
} ,
192
192
) ) ;
193
193
194
194
mappings. extend ( mcdc_branches. iter ( ) . filter_map (
195
195
|& mappings:: MCDCBranch { span, true_bcb, false_bcb, condition_info, decision_depth : _ } | {
196
- let code_region = region_for_span ( span) ?;
196
+ let source_region = region_for_span ( span) ?;
197
197
let true_term = term_for_bcb ( true_bcb) ;
198
198
let false_term = term_for_bcb ( false_bcb) ;
199
199
let kind = match condition_info {
200
200
Some ( mcdc_params) => MappingKind :: MCDCBranch { true_term, false_term, mcdc_params } ,
201
201
None => MappingKind :: Branch { true_term, false_term } ,
202
202
} ;
203
- Some ( Mapping { kind, code_region } )
203
+ Some ( Mapping { kind, source_region } )
204
204
} ,
205
205
) ) ;
206
206
207
207
mappings. extend ( mcdc_decisions. iter ( ) . filter_map (
208
208
|& mappings:: MCDCDecision { span, bitmap_idx, num_conditions, .. } | {
209
- let code_region = region_for_span ( span) ?;
209
+ let source_region = region_for_span ( span) ?;
210
210
let kind = MappingKind :: MCDCDecision ( DecisionInfo { bitmap_idx, num_conditions } ) ;
211
- Some ( Mapping { kind, code_region } )
211
+ Some ( Mapping { kind, source_region } )
212
212
} ,
213
213
) ) ;
214
214
@@ -362,19 +362,13 @@ fn inject_statement(mir_body: &mut mir::Body<'_>, counter_kind: CoverageKind, bb
362
362
/// but it's hard to rule out entirely (especially in the presence of complex macros
363
363
/// or other expansions), and if it does happen then skipping a span or function is
364
364
/// better than an ICE or `llvm-cov` failure that the user might have no way to avoid.
365
- fn make_code_region (
365
+ #[ instrument( level = "debug" , skip( source_map) ) ]
366
+ fn make_source_region (
366
367
source_map : & SourceMap ,
367
368
file_name : Symbol ,
368
369
span : Span ,
369
370
body_span : Span ,
370
- ) -> Option < CodeRegion > {
371
- debug ! (
372
- "Called make_code_region(file_name={}, span={}, body_span={})" ,
373
- file_name,
374
- source_map. span_to_diagnostic_string( span) ,
375
- source_map. span_to_diagnostic_string( body_span)
376
- ) ;
377
-
371
+ ) -> Option < SourceRegion > {
378
372
let lo = span. lo ( ) ;
379
373
let hi = span. hi ( ) ;
380
374
@@ -424,7 +418,7 @@ fn make_code_region(
424
418
start_line = source_map. doctest_offset_line ( & file. name , start_line) ;
425
419
end_line = source_map. doctest_offset_line ( & file. name , end_line) ;
426
420
427
- check_code_region ( CodeRegion {
421
+ check_source_region ( SourceRegion {
428
422
file_name,
429
423
start_line : start_line as u32 ,
430
424
start_col : start_col as u32 ,
@@ -433,12 +427,12 @@ fn make_code_region(
433
427
} )
434
428
}
435
429
436
- /// If `llvm-cov` sees a code region that is improperly ordered (end < start),
430
+ /// If `llvm-cov` sees a source region that is improperly ordered (end < start),
437
431
/// it will immediately exit with a fatal error. To prevent that from happening,
438
432
/// discard regions that are improperly ordered, or might be interpreted in a
439
433
/// way that makes them improperly ordered.
440
- fn check_code_region ( code_region : CodeRegion ) -> Option < CodeRegion > {
441
- let CodeRegion { file_name : _, start_line, start_col, end_line, end_col } = code_region ;
434
+ fn check_source_region ( source_region : SourceRegion ) -> Option < SourceRegion > {
435
+ let SourceRegion { file_name : _, start_line, start_col, end_line, end_col } = source_region ;
442
436
443
437
// Line/column coordinates are supposed to be 1-based. If we ever emit
444
438
// coordinates of 0, `llvm-cov` might misinterpret them.
@@ -451,17 +445,17 @@ fn check_code_region(code_region: CodeRegion) -> Option<CodeRegion> {
451
445
let is_ordered = ( start_line, start_col) <= ( end_line, end_col) ;
452
446
453
447
if all_nonzero && end_col_has_high_bit_unset && is_ordered {
454
- Some ( code_region )
448
+ Some ( source_region )
455
449
} else {
456
450
debug ! (
457
- ?code_region ,
451
+ ?source_region ,
458
452
?all_nonzero,
459
453
?end_col_has_high_bit_unset,
460
454
?is_ordered,
461
- "Skipping code region that would be misinterpreted or rejected by LLVM"
455
+ "Skipping source region that would be misinterpreted or rejected by LLVM"
462
456
) ;
463
457
// If this happens in a debug build, ICE to make it easier to notice.
464
- debug_assert ! ( false , "Improper code region: {code_region :?}" ) ;
458
+ debug_assert ! ( false , "Improper source region: {source_region :?}" ) ;
465
459
None
466
460
}
467
461
}
0 commit comments