-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #116974 - Zalathar:signature-spans, r=oli-obk,cjgillot
coverage: Fix inconsistent handling of function signature spans While doing some more cleanup of `spans`, I noticed a strange inconsistency in how function signatures are handled. Normally the function signature span is treated as though it were executable as part of the start of the function, but in some cases the signature span disappears entirely from coverage, for no obvious reason. This is caused by the fact that spans created by `CoverageSpan::for_fn_sig` don't add the span to their `merged_spans` field (unlike normal statement/terminator spans). In cases where the span-processing code looks at those merged spans, it thinks the signature span is no longer visible and deletes it. Adding the signature span to `merged_spans` resolves the inconsistency. (Prior to #116409 this wouldn't have been possible, because there was no case in the old `CoverageStatement` enum representing a signature. Now that `merged_spans` is just a list of spans, that's no longer an obstacle.)
- Loading branch information
Showing
9 changed files
with
233 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
Function name: fn_sig_into_try::a | ||
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0a, 01, 04, 02] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 0 | ||
Number of file 0 mappings: 1 | ||
- Code(Counter(0)) at (prev + 10, 1) to (start + 4, 2) | ||
|
||
Function name: fn_sig_into_try::b | ||
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 10, 01, 02, 0f, 00, 02, 0f, 00, 10, 02, 01, 05, 00, 0c, 07, 01, 01, 00, 02] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 2 | ||
- expression 0 operands: lhs = Counter(0), rhs = Counter(1) | ||
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) | ||
Number of file 0 mappings: 4 | ||
- Code(Counter(0)) at (prev + 16, 1) to (start + 2, 15) | ||
- Code(Zero) at (prev + 2, 15) to (start + 0, 16) | ||
- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 12) | ||
= (c0 - c1) | ||
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) | ||
= (c1 + (c0 - c1)) | ||
|
||
Function name: fn_sig_into_try::c | ||
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 16, 01, 02, 17, 00, 02, 17, 00, 18, 02, 01, 05, 00, 0c, 07, 01, 01, 00, 02] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 2 | ||
- expression 0 operands: lhs = Counter(0), rhs = Counter(1) | ||
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) | ||
Number of file 0 mappings: 4 | ||
- Code(Counter(0)) at (prev + 22, 1) to (start + 2, 23) | ||
- Code(Zero) at (prev + 2, 23) to (start + 0, 24) | ||
- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 12) | ||
= (c0 - c1) | ||
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) | ||
= (c1 + (c0 - c1)) | ||
|
||
Function name: fn_sig_into_try::d | ||
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 1c, 01, 03, 0f, 00, 03, 0f, 00, 10, 02, 01, 05, 00, 0c, 07, 01, 01, 00, 02] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 2 | ||
- expression 0 operands: lhs = Counter(0), rhs = Counter(1) | ||
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub) | ||
Number of file 0 mappings: 4 | ||
- Code(Counter(0)) at (prev + 28, 1) to (start + 3, 15) | ||
- Code(Zero) at (prev + 3, 15) to (start + 0, 16) | ||
- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 12) | ||
= (c0 - c1) | ||
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2) | ||
= (c1 + (c0 - c1)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#![feature(coverage_attribute)] | ||
// compile-flags: --edition=2021 | ||
|
||
// Regression test for inconsistent handling of function signature spans that | ||
// are followed by code using the `?` operator. | ||
// | ||
// For each of these similar functions, the line containing the function | ||
// signature should be handled in the same way. | ||
|
||
fn a() -> Option<i32> | ||
{ | ||
Some(7i32); | ||
Some(0) | ||
} | ||
|
||
fn b() -> Option<i32> | ||
{ | ||
Some(7i32)?; | ||
Some(0) | ||
} | ||
|
||
fn c() -> Option<i32> | ||
{ | ||
let _ = Some(7i32)?; | ||
Some(0) | ||
} | ||
|
||
fn d() -> Option<i32> | ||
{ | ||
let _: () = (); | ||
Some(7i32)?; | ||
Some(0) | ||
} | ||
|
||
#[coverage(off)] | ||
fn main() { | ||
a(); | ||
b(); | ||
c(); | ||
d(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
LL| |#![feature(coverage_attribute)] | ||
LL| |// compile-flags: --edition=2021 | ||
LL| | | ||
LL| |// Regression test for inconsistent handling of function signature spans that | ||
LL| |// are followed by code using the `?` operator. | ||
LL| |// | ||
LL| |// For each of these similar functions, the line containing the function | ||
LL| |// signature should be handled in the same way. | ||
LL| | | ||
LL| 1|fn a() -> Option<i32> | ||
LL| 1|{ | ||
LL| 1| Some(7i32); | ||
LL| 1| Some(0) | ||
LL| 1|} | ||
LL| | | ||
LL| 1|fn b() -> Option<i32> | ||
LL| 1|{ | ||
LL| 1| Some(7i32)?; | ||
^0 | ||
LL| 1| Some(0) | ||
LL| 1|} | ||
LL| | | ||
LL| 1|fn c() -> Option<i32> | ||
LL| 1|{ | ||
LL| 1| let _ = Some(7i32)?; | ||
^0 | ||
LL| 1| Some(0) | ||
LL| 1|} | ||
LL| | | ||
LL| 1|fn d() -> Option<i32> | ||
LL| 1|{ | ||
LL| 1| let _: () = (); | ||
LL| 1| Some(7i32)?; | ||
^0 | ||
LL| 1| Some(0) | ||
LL| 1|} | ||
LL| | | ||
LL| |#[coverage(off)] | ||
LL| |fn main() { | ||
LL| | a(); | ||
LL| | b(); | ||
LL| | c(); | ||
LL| | d(); | ||
LL| |} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
#![feature(coverage_attribute)] | ||
// compile-flags: --edition=2021 | ||
|
||
// Regression test for inconsistent handling of function signature spans that | ||
// are followed by code using the `?` operator. | ||
// | ||
// For each of these similar functions, the line containing the function | ||
// signature should be handled in the same way. | ||
|
||
fn a() -> Option<i32> | ||
{ | ||
Some(7i32); | ||
Some(0) | ||
} | ||
|
||
fn b() -> Option<i32> | ||
{ | ||
Some(7i32)?; | ||
Some(0) | ||
} | ||
|
||
fn c() -> Option<i32> | ||
{ | ||
let _ = Some(7i32)?; | ||
Some(0) | ||
} | ||
|
||
fn d() -> Option<i32> | ||
{ | ||
let _: () = (); | ||
Some(7i32)?; | ||
Some(0) | ||
} | ||
|
||
#[coverage(off)] | ||
fn main() { | ||
a(); | ||
b(); | ||
c(); | ||
d(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters