Repository navigation
fix(cobol): link the paragraphs inside a PERFORM ... THRU range - #5424
pavansystems wants to merge 2 commits into
Conversation
|
Thanks for the pull request, @pavansystems. A maintainer will review it soon. Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions. A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic. |
There was a problem hiding this comment.
Graphify review 
1 bug (1 preexisting) · 2 possible issues to check · Medium impact
The COBOL extractor now records procedure order and adds call edges for paragraphs inside valid `PERFORM ...
A section performed through itself omits its paragraphs ·
cobol.py:386
2 possible issues we couldn't confirm
- A PERFORM THRU range's middle paragraphs can lose their
perform_rangelabel when a GO TO already linked them ·graphify/extractors/cobol.py:401 - The paragraph id list is rebuilt for every PERFORM range, so large programs pay for it repeatedly ·
graphify/extractors/cobol.py:390
They don't change the score.
Code graph · 38 functions depend on this change
- 625 of 625 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed c0d66fc · 2 earlier findings not re-checked
| order = procedure_order.get(program_id, []) | ||
| ids = [paragraph_id for paragraph_id, _ in order] | ||
| start, end = ids.index(start_id), ids.index(end_id) | ||
| if end <= start: |
There was a problem hiding this comment.
Performing a section through itself omits its paragraphs
When a caller performs a section THRU the same section, the graph links the section but omits the paragraphs it contains.
Expand equal section endpoints in extract_cobol.
Evidence · checked against the code
Expected: The graph contains calls edges from the caller to the paragraphs in that section.
Actually: The endpoint calls resolve to the section, but the range expansion skips equal endpoint indices, leaving the section's paragraphs without calls edges from the caller.
This was already on the base branch; the change keeps it.
- Independent source review: Reviewed the range tests: they cover distinct endpoints and a range ending at a section, but not identical section endpoints. The identical endpoints are not rescued by endpoint processing; both resolve to the section itself, not its paragraphs.
- Some lookups asked for files or lines that do not exist; the review was told and carried on.
Prompt to fix with AI
In graphify/extractors/cobol.py, extract_cobol (lines 337-340):
Problem: Performing a section through itself omits its paragraphs
Expected: The graph contains calls edges from the caller to the paragraphs in that section.
Actually: The endpoint calls resolve to the section, but the range expansion skips equal endpoint indices, leaving the section's paragraphs without calls edges from the caller.
Fix it at the cause, and add a test that fails without the fix.
Graphify · Checked against the code · View in Graphify
| end += 1 | ||
| # The end of the range already has its endpoint edge; add_edge keeps that one. | ||
| for paragraph_id in ids[start + 1:end + 1]: | ||
| add_edge(caller_id, paragraph_id, "calls", line, context="perform_range") |
There was a problem hiding this comment.
Paragraph ranges create calls to intervening section nodes
A PERFORM A-PARA THRU Z-PARA that crosses a section boundary can show a call to the intervening section, even though the range names paragraphs rather than that section.
Exclude section nodes when expanding paragraph ranges in extract_cobol.
Evidence · checked against the code
Expected: The graph represents the range's paragraphs as call targets, not the intervening section header as a separately named target.
Actually: The range loop adds a calls edge to each intermediate entry, including section nodes.
- Independent source review: Reviewed the existing section-range test: it explicitly names section nodes as endpoints and does not cover paragraph endpoints crossing an intervening section. It does not negate the reported case.
Prompt to fix with AI
In graphify/extractors/cobol.py, extract_cobol (lines 346-349):
Problem: Paragraph ranges create calls to intervening section nodes
Expected: The graph represents the range's paragraphs as call targets, not the intervening section header as a separately named target.
Actually: The range loop adds a calls edge to each intermediate entry, including section nodes.
Fix it at the cause, and add a test that fails without the fix.
Graphify · Checked against the code · View in Graphify
5345eb7 to
c0d66fc
Compare
| # left at the two endpoint edges above. | ||
| for caller_id, program_id, first, last, line in pending_ranges: | ||
| start_id = paragraphs.get((program_id, first.casefold())) | ||
| end_id = paragraphs.get((program_id, last.casefold())) |
There was a problem hiding this comment.
A section performed through itself omits its paragraphs
When a caller uses PERFORM SEC THRU SEC, the graph links the caller to SEC but leaves out the paragraphs in that section.
Handle equal PERFORM THRU endpoints in extract_cobol.
Evidence · checked against the code
Expected: The graph links the caller to the paragraphs in that section as part of the performed range.
Actually: The section is linked as an endpoint, but the equal endpoint indices cause range processing to skip before section paragraphs are added.
This was already on the base branch; the change keeps it.
- Independent source review: The section-range test covers a range from
FIRST-SECthrough a different section, and checks that paragraphs in the ending section are linked. It does not cover identical endpoints; its distinct endpoint indices avoid the skip condition. - Some lookups asked for files or lines that do not exist; the review was told and carried on.
Prompt to fix with AI
In graphify/extractors/cobol.py, extract_cobol (lines 383-386):
Problem: A section performed through itself omits its paragraphs
Expected: The graph links the caller to the paragraphs in that section as part of the performed range.
Actually: The section is linked as an endpoint, but the equal endpoint indices cause range processing to skip before section paragraphs are added.
Fix it at the cause, and add a test that fails without the fix.
Graphify · Checked against the code · View in Graphify
`PERFORM A THRU Z` runs every paragraph written from A to Z, but only the two ends got a `calls` edge (Graphify-Labs#3814). A paragraph in the middle of a range had no inbound edge: "what performs M?" answered nothing, and M looked like dead code unless something else performed it by name. Record each program's paragraphs and sections in the order they are written, and once the program has been read link the performing paragraph to everything between the two ends, tagged `context: "perform_range"`. A range that ends on a section runs to the end of that section, so its paragraphs are included up to the next section header. The range is filled in only when both ends are paragraphs of the same program and the end is written after the start. Otherwise the two endpoint edges stay as they were and nothing is added. Not covered: paragraphs that a COPY statement inside the range brings in from a copybook (the extractor reads one file at a time), and a GO TO that leaves the range early. Regression tests: a range with two paragraphs in the middle, with a reversed and an unresolved range as controls, and a range that ends on a section. Both fail without the change. Co-Authored-By: Claude Fable 5.2 <[email protected]>
The reversed range (`PERFORM Z-PARA THRU A-PARA`) and the unresolved one stood in the same paragraph as the real range over the same paragraphs, so the test could not tell a range that was wrongly filled in from the real one. They now stand in a paragraph of their own, which must get its endpoint edges and nothing between them. Co-Authored-By: Claude Fable 5.2 <[email protected]>
c0d66fc to
ae7b949
Compare
…a-57 Both change extraction output and ship in the same release as the 56->57 bump, so they share schema 57 with a combined rationale. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Shipped in v0.9.121, landed via authorship-preserving cherry-pick so your commits keep your name. Thanks @pavansystems! |
… 0.9.121 v8 0.9.121 also lands schema 57 (Rust Graphify-Labs#5398, COBOL Graphify-Labs#5424-Graphify-Labs#5426). Bump _AST_CACHE_SCHEMA to 58 with the C/C++ reachability lead and keep v8's schema-57 text verbatim as "prior (57)". Co-Authored-By: Claude Opus 5.5 <[email protected]>
What does this PR do?
PERFORM A THRU Zruns every paragraph written from A to Z, but only the two ends get acallsedge (the behaviour from #3814). A paragraph in the middle of a range has no inbound edge: "what performs M?" answers nothing, and M looks like dead code unless something else performs it by name.This records each program's paragraphs and sections in the order they are written and, once the program has been read, links the performing paragraph to everything between the two ends, tagged
context: "perform_range". A range that ends on a section runs to the end of that section, so its paragraphs are included up to the next section header.The range is filled in only when both ends are paragraphs of the same program and the end is written after the start. Otherwise the two endpoint edges stay as they were and nothing is added.
Not covered: paragraphs that a
COPYstatement inside the range brings in from a copybook (the extractor reads one file at a time), and aGO TOthat leaves the range early.Follow-up commit (
test(cobol): tell a reversed THRU range apart from a real one), after the automated review: the reversed and the unresolved range stood in the same paragraph as the real one, so the test could not tell a wrongly filled range from the real one. They now stand in a paragraph of their own. No change to the extractor.Rebased onto
v8after #5423 landed (conflicts incobol.pyand the test file, resolved by keeping both sides).On the two points of the second automated review, neither changed here:
PERFORM S THRU Son one section does not link the section's paragraphs. A plainPERFORM Sof a section does not either, onv8as here; linking a section's paragraphs when the section is performed is a separate change.Type of change
Verification & Invariants
Invariant: the two endpoint edges are emitted exactly as before. The edges in between are added only for a range whose ends both resolve in the same program in source order; a reversed or unresolved range adds nothing (both are controls in the test).
Persisted state: the AST cache holds per-file results from before this change, so a cached COBOL file keeps its old result until the file changes or the cache is cleared. I did not bump
_AST_CACHE_SCHEMA, following the earlier COBOL fixes; say so if you want it bumped.How was this tested?
On this branch (macOS, Python from
uv sync --all-extras --frozen):The new tests were also run against unmodified
v8, where they fail.Before the rebase, the full suite (
uv run --frozen --all-extras pytest tests) passed on a local branch that combined this change with my other COBOL changes (11883 passed, 165 skipped, 1 xfailed). Not rerun on this branch after the rebase; the COBOL tests were.The combined branch was also run on a private COBOL codebase and the result compared with links I had been adding outside Graphify; it produced no link that the comparison did not also have.
Graphify-specific checklist
uv run python -m tools.skillgen --bless) when changing their source fragments. (Not applicable: no skill fragment changed.)The code, tests and this description were written with Claude Code; the commit carries a
Co-Authored-Byline.🤖 Generated with Claude Code