Skip to content

Fix: careful with linenumber removal in order to improve code coverage - #281

Merged
lkdvos merged 2 commits into
masterfrom
ld-codecov
Jul 31, 2026
Merged

Fix: careful with linenumber removal in order to improve code coverage#281
lkdvos merged 2 commits into
masterfrom
ld-codecov

Conversation

@lkdvos

@lkdvos lkdvos commented Jun 15, 2026

Copy link
Copy Markdown
Member

This is a claude-aided attempt of resolving #280.
From what I could tell, the removal of the line numbers is what causes the codecov gaps.

@Jutho I'm not entirely sure if we really need these to begin with, or if this is just a cosmetic thing to make the generated expressions easier to inspect?

In any case, I still have to more carefully investigate if this actually resolves the issue, and additionally if this automatically carries over to @planar and @plansor.

@github-actions

github-actions Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Your PR no longer requires formatting changes. Thank you for your contribution!

Comment thread src/indexnotation/parser.jl Outdated
@Jutho

Jutho commented Jun 15, 2026

Copy link
Copy Markdown
Member

Other than my comment, I think this looks reasonable. I indeed removed line numbers to make the macroexpanded code more readable.

@lkdvos

lkdvos commented Jun 16, 2026

Copy link
Copy Markdown
Member Author

If the line number removal is just for the macro-expanded code, it might be reasonable to just disable it altogether? That also avoids the issues with @planar etc I think.

Note that I still need to check that this actually fixes the codecov issue, so this PR is not ready

@lkdvos
lkdvos marked this pull request as ready for review July 30, 2026 19:50
@lkdvos

lkdvos commented Jul 30, 2026

Copy link
Copy Markdown
Member Author

Update here: I reworked this slightly, basically just removing only the line number nodes that were inserted by us, while keeping the ones that were present in the original expression. From what I understand, this should be enough to attribute all of the code to the originating expressions, hopefully both making error messages as well as code coverage behave now.

@lkdvos
lkdvos requested a review from Jutho July 30, 2026 19:54
@lkdvos lkdvos linked an issue Jul 30, 2026 that may be closed by this pull request
@codecov

codecov Bot commented Jul 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

Files with missing lines Coverage Δ
ext/TensorOperationsBumperExt.jl 100.00% <100.00%> (+16.66%) ⬆️
src/indexnotation/contractiontrees.jl 100.00% <100.00%> (ø)
src/indexnotation/parser.jl 94.04% <100.00%> (+0.14%) ⬆️
src/indexnotation/postprocessors.jl 94.44% <100.00%> (+0.56%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lkdvos
lkdvos enabled auto-merge (squash) July 30, 2026 21:08
lkdvos and others added 2 commits July 31, 2026 09:38
Follow-up on the previous commit, addressing the two open questions in the
PR discussion.

Instead of recognizing parser-generated `LineNumberNode`s by string-prefix
matching against `TensorOperations/src`, snapshot the set of files referenced
by the `LineNumberNode`s of the expression handed to the parser -- taken
before any preprocessor runs, so those are by construction exactly the user's
line numbers -- and drop everything else. This also explains why the step
cannot be a stateless entry in `parser.postprocessors`: it needs state
captured before the preprocessors.

The path-prefix version missed two cases:

- `ext/`, which lies outside `src/`, so no extension was covered;
- `@planar`/`@plansor`, where TensorKit's own pre/postprocessors synthesize
  `LineNumberNode`s pointing into `TensorKit/src/planar/`. Verified that
  those are now stripped as well, so `@planar` and `@plansor` are fixed with
  no TensorKit-side change.

Note that both halves of this are needed, i.e. the removal is not merely
cosmetic: a synthesized `LineNumberNode` in block-statement position
re-attributes every statement that follows it to a line in TensorOperations'
own source, which steals the attribution from the user's line. Conversely,
`LineNumberNode`s outside block-statement position are left alone, since they
can be structurally required -- the `costcheck = :warn` path emits a `@warn`
macrocall whose second argument is one.

Verified end to end with `--code-coverage`: on PEPSKit's
`src/algorithms/contractions/ctmrg/enlarge_corner.jl` (the file from #280),
the four contraction statements of `enlarge_northwest_corner` go from no
coverage information at all to a hit count, taking the file from 12/72 to
28/88 reported lines. A deliberately-never-called function stays at 0 in both
cases, confirming the counts reflect real execution. Also checked on the
realistic CI path, i.e. `Pkg.test(coverage = true)` against a precompiled
package rather than an `include`d file.

While here:

- delete `removelinenumbernode`, which is unexported and now unused;
- drop the redundant removal in `insertcontractiontrees!`, since its output
  passes through the parser's final pass anyway;
- update `docs/src/man/implementation.md`, which still listed
  `removelinenumbernode` as an enabled default postprocessor;
- tighten the tests to assert the exact set of surviving line numbers and
  that every one of them comes from the test file, which the previous
  prefix-based assertion could not detect for `ext/`.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@lkdvos
lkdvos disabled auto-merge July 31, 2026 15:09
@lkdvos
lkdvos merged commit 94e79f0 into master Jul 31, 2026
8 of 10 checks passed
@lkdvos
lkdvos deleted the ld-codecov branch July 31, 2026 15:10
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.

@tensor begin ... end blocks shown uncovered in Codecov

2 participants