Skip to content

Scoverage: fix broken warnings related to tail recursion and infinite loop detection#25941

Merged
SolalPirelli merged 4 commits intoscala:mainfrom
anatoliykmetyuk:fix/051-broken-warnings
Apr 28, 2026
Merged

Scoverage: fix broken warnings related to tail recursion and infinite loop detection#25941
SolalPirelli merged 4 commits intoscala:mainfrom
anatoliykmetyuk:fix/051-broken-warnings

Conversation

@anatoliykmetyuk
Copy link
Copy Markdown
Contributor

Fixes a bunch of warnings broken by scoverage related to tail recursion and infinite loops detection. Warnings were broken by:

  • Coverage modifying the trees to inject instrumentation, breaking assumptions by the loop detection and tail recursion phases.
  • Coverage modifying the spans of the trees when instrumenting them, which breaks the positions at which warnings are reported.

The solution by phases affected:

InstrumentCoverage - phase that instruments the trees to inject coverage probes:

  • Do not instrument literal booleans in if conditions - they are getting in the way of rewriting if statements with literal conditions into their respective then or else branches.
  • Preserve the spans of the trees when instrumenting them, so that warnings are reported at the original position of the code.

CheckLoopingImplicits - phase that detects infinite loops in initializers:

  • Ignore coverage probes as ones not capable of leading to an infinite loop.
  • Strip the coverage instrumentation from RHS of defs before analyzing them for loops.

TailRec - phase that rewrites tail recursive calls into loops:

  • Modified isInfiniteRecCall - the method that detects infinite loops in tail recursive calls - to allow coverage probes as ones not capable of breaking an infinite loop.
  • In transform, modify the default getter index in recursive call argument position to peel through the coverage instrumentation to recover the original default-getter parameter index.

How much have you relied on LLM-based tools in this contribution?

Moderately, for codebase analysis and tracing.

How was the solution tested?

sbt "testCompilation --enable-coverage-phase"

@anatoliykmetyuk anatoliykmetyuk marked this pull request as ready for review April 28, 2026 05:26
@anatoliykmetyuk
Copy link
Copy Markdown
Contributor Author

CI is red due to main being red. Will rebase once main is green again.

Copy link
Copy Markdown
Contributor

@SolalPirelli SolalPirelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is a consequence of InstrumentCoverage having to be early because coverage needs to instrument code the user actually wrote rather than code the compiler produced after optimizations?

@anatoliykmetyuk
Copy link
Copy Markdown
Contributor Author

Yeah, quite a lot of issues are a consequence of the coverage phase being early and breaking the assumptions of the later phases.

@anatoliykmetyuk anatoliykmetyuk force-pushed the fix/051-broken-warnings branch from 46ae818 to e7deae3 Compare April 28, 2026 11:47
@SolalPirelli SolalPirelli merged commit 88140bc into scala:main Apr 28, 2026
45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants