-
Notifications
You must be signed in to change notification settings - Fork 79
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
neotest: exclude RET statements from coverage #3617
Conversation
The sequence point bounds of all RET statements include the whole method body, for example: https://github.com/nspcc-dev/neo-go/blob/86ed214e8a53859fd85482370be20eb613c61419/pkg/compiler/codegen.go#L542-L543 Such behaviour breaks the resulting coverage report. A part of #3559. Signed-off-by: Anna Shaleva <[email protected]>
// which break the resulting coverage report. | ||
_, isRET := scriptRawCoverage.methodEndOffsets[uint16(point.Opcode)] | ||
if isRET { | ||
continue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my best attempt. I also tried to keep return statements in the coverage but "shorten" their bounds to a single "end" line, but it's not displayed properly and sometimes even wrong when there's no explicit "return" statement in the code. Hence, I decided to remove these sequence points from coverage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I'm still not sure if it's a good solution because: it does not exclude those RET statements that are not in the end of the method. Although such RET statements have proper bounds. So may be it's even bug in the compiler and RET statements shouldn't actually have such method-body-width bounds.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And if it's a compiler bug:
neo-go/pkg/compiler/codegen.go
Lines 539 to 543 in 86ed214
// This can be the case with void and named-return functions. | |
if !isInit && !isDeploy && !lastStmtIsReturn(decl.Body) { | |
c.processDefers() | |
c.saveSequencePoint(decl.Body) | |
emit.Opcodes(c.prog.BinWriter, opcode.RET) |
Then it's not clear what are the correct bounds for this "RET" opcode, because there's actually no
return
statement in the contract code itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally, if we keep everything as is on the compiler level, then on the neotest level we need some way to distinguish some "real" return statements that are presented in the code in the end of every method from "RET" statements that belong to void and named-return functions. Currently we can't distinguish them based on the given debug info format, hence this PR removes all RET statements that belong to the end of the function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I probably also need to check that no other statements except "RET" may be excluded by this code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And I probably also need to check that no other statements except "RET" may be excluded by this code.
OK, it’s not required, because our compiler always emit RET in the end of functions, and there's no function that ends with another instruction.
@Slava0135 you may take a look if you'd like to. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #3617 +/- ##
==========================================
- Coverage 85.15% 85.13% -0.03%
==========================================
Files 333 333
Lines 39022 39036 +14
==========================================
+ Hits 33231 33234 +3
- Misses 4221 4233 +12
+ Partials 1570 1569 -1 ☔ View full report in Codecov by Sentry. |
If overlaps can only ever happen with these RET ops then we don't need #3575 |
(though maybe take the tests from there, should have been a separate PR) |
No, there are multiple reasons for range overlapping, another one is described in #3559 (comment):
And even this is not the last place where instructions may overlap. |
Can you make some simple example of C# contract compiled with debug info? How does it treat these RETs that it also inevitably has? Likely it does something similar and in that sense it's the coverage tool job to process data appropriately. And in that sense the fix is OK. |
Four hours of attempts to build compiler, to make the released binary work and to compile a simple contract, I'm done with it. No working instructions, no clear documentation, no fresh NuGet modules. And they generate
The results are:
Hence, #3559 is a relevant issue even if we don't take into account overlapping RET statements.
And the following instructions range:
Pay attention to instructions 18 and 20 and their sequence points, it's the described approach. All in all, these "large" sequence points generated by Go compiler for some RET statements is a bug, will create an issue for that. But it's not easy to fix because we use two different approaches to sequence point generation, from what I saw, Go compiler doesn't bind any instructions to
|
Based on the comment above I'm closing this PR, because it's not a solution. |
Closed in favour of #3622. |
The sequence point bounds of all RET statements include the whole method body, for example:
neo-go/pkg/compiler/codegen.go
Lines 542 to 543 in 86ed214
Such behaviour breaks the resulting coverage report. A part of #3559.