Repository navigation
fix(cobol): link a GO TO to the paragraph it jumps to - #5423
pavansystems wants to merge 2 commits into
Conversation
The COBOL extractor read PERFORM and CALL but had no pattern for GO TO, so a jump left no edge. A paragraph that is only ever reached by `GO TO` (an exit or error paragraph, typically) had no inbound edge and looked like dead code, and a walk along the control flow stopped at every jump. Emit a `calls` edge from the paragraph the statement stands in to each target, tagged `context: "go_to"` so a jump can be told apart from a PERFORM without a new relation. `GO TO A B C DEPENDING ON X` links A, B and C. The target list ends at DEPENDING (a data name follows) and at OF/IN (the section that qualifies the paragraph before it follows), so neither is taken for a target. Targets resolve against the same per-program paragraph table as PERFORM, and a name that is not a paragraph of the program yields no edge. Text inside quotes and EXEC blocks is not read, as for PERFORM. Not covered: `GO` without `TO`, a target list that runs on over several lines, and a GO TO changed at run time by ALTER. When a paragraph both performs and jumps to the same target, the one edge kept is the PERFORM. Regression tests: a plain GO TO, and GO TO ... DEPENDING ON with a qualified target. Both fail without the change. Co-Authored-By: Claude Fable 5.2 <[email protected]>
|
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 · 3 possible issues to check · Medium impact
The extractor adds GO TO transfers as calls edges marked with context="go_to", including targets in DEPENDING ON lists.
A matching
PERFORM hides the GO TO edge context · cobol.py:363
3 possible issues we couldn't confirm
- Depending-on test uses qualified GO TO targets that are not inside the named sections, so it locks in ignoring the qualifier ·
tests/test_cobol_extractor.py:237 - Docstring says a qualified
A OF SECtarget is not a target, but the test expects A-PARA to be linked ·tests/test_cobol_extractor.py:228 - Redundant assertion repeats the exclusion already checked for MAIN-PARA to WORK-PARA in the GO TO test ·
tests/test_cobol_extractor.py:223
They don't change the score.
Code graph · 34 functions depend on this change
- 620 of 620 test files are affected by this change.
- Gate, test list and every flagged function: in the Graphify check.
Reviewed 3ed7273 · 3 earlier findings not re-checked · Full report in the Graphify check
The target list of a GO TO ran on to the end of the line: every word after the first target was tried as a paragraph name. In `IF A = 1 GO TO ERR-PARA ELSE SET CHOICE TO TRUE`, a paragraph named CHOICE became a jump target. A plain `GO TO A` has exactly one target, so only the first word is taken. Only `GO TO A B C DEPENDING ON X` has several: there the list runs up to DEPENDING. A second GO TO on the same line is read as a statement of its own, with its own target. In a DEPENDING list, `OF`/`IN` ended the list, so the targets after a qualified name were lost (`GO TO A OF S1, B DEPENDING ON X` missed B). The section that qualifies a name is now left out and the list goes on. One fixture line ran one column past column 72 and lost its period; it is shortened. Regression tests: a line with a paragraph name after the jump and a line with two jumps, and a DEPENDING list with a qualified name in the middle. Both fail without the change. Co-Authored-By: Claude Fable 5.2 <[email protected]>
| for caller_id, program_id, name, line in pending_go_tos: | ||
| target_id = paragraphs.get((program_id, name.casefold())) | ||
| if target_id is not None: | ||
| add_edge(caller_id, target_id, "calls", line, context="go_to") |
There was a problem hiding this comment.
A matching
PERFORM hides the GO TO edge context
When the same paragraph both performs and jumps to a target, the graph keeps only an untagged calls edge, so consumers looking for context: go_to miss the jump.
Merge context: go_to into an existing edge in add_edge.
Evidence · checked against the code
Expected: The graph marks the jump edge with context="go_to".
Actually: The earlier untagged PERFORM edge suppresses the later GO TO edge during deduplication.
- Independent source review: Reviewed the GO TO tests: they check tagged jumps, including multiple targets and multiple GO TO statements on a line, but none combines PERFORM and GO TO to the same target. No guard or alternate path in the inspected extraction code preserves the context for that duplicate pair.
Prompt to fix with AI
In graphify/extractors/cobol.py, add_edge (lines 360-363):
Problem: A matching `PERFORM` hides the `GO TO` edge context
Expected: The graph marks the jump edge with context="go_to".
Actually: The earlier untagged PERFORM edge suppresses the later GO TO edge during deduplication.
Fix it at the cause, and add a test that fails without the fix.
Graphify · Checked against the code · View in Graphify
…batch Fold the Python-lambda (#5417), Go-import-shadow (#5411) and COBOL GO-TO (#5423) AST-output changes into one combined _AST_CACHE_SCHEMA bump 53 -> 54, so cached Python/Go/COBOL extractions re-run. Fix the #5422 regression test's cwd-fragile `query` assertion to check the queried node (returncode==0 is the real invariant). 0.9.119 changelog and version bump. The headline is the #5320 anyio regression fix (graph commands broke on core installs in 0.9.118). Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Landed in v0.9.119 via an authorship-preserving cherry-pick. A COBOL GO TO now emits a calls edge to the paragraph it jumps to (including each target of GO TO ... DEPENDING ON), fail-closed on an unknown target. Maintainer tweak: added the AST cache schema bump so cached COBOL files re-extract. Thanks @pavansystems! |
What does this PR do?
The COBOL extractor reads
PERFORMandCALLbut has no pattern forGO TO, so a jump leaves no edge. A paragraph that is only reached byGO TO(typically an exit or error paragraph) has no inbound edge and looks like dead code, and a walk along the control flow stops at every jump.This adds a
callsedge from the paragraph the statement stands in to each target, taggedcontext: "go_to", so a jump can be told apart from aPERFORMwithout a new relation.GO TO A B C DEPENDING ON Xlinks A, B and C.DEPENDING(a data name follows) and atOF/IN(the qualifying section follows), so neither is taken for a target.PERFORM. A name that is not a paragraph of the program yields no edge.EXECblocks is not read, as forPERFORM.Not covered:
GOwithoutTO, a target list that runs on over several lines, and aGO TOchanged at run time byALTER. When a paragraph both performs and jumps to the same target, the one edge kept is thePERFORM.I found no existing issue for this.
Follow-up commit (
fix(cobol): give a plain GO TO one target), after the automated review:IF A = 1 GO TO ERR-PARA ELSE SET CHOICE TO TRUEa paragraph namedCHOICEbecame a target. A plainGO TOnow has one target; only aDEPENDING ONlist has several. A secondGO TOon the same line is read on its own.DEPENDING ONlist,OF/INended the list, so targets after a qualified name were lost. The qualifying section is now skipped and the list goes on. (This replaces the second bullet above aboutOF/IN.)Type of change
Verification & Invariants
Invariant: an edge is only emitted for a target that is a paragraph of the same program; anything else stays unlinked rather than guessed. Existing
PERFORMandCALLedges are unchanged.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.The full suite (
uv run --frozen --all-extras pytest tests) was run on a local branch that combines this change with my three other COBOL PRs (#5423 to #5426) and one further COBOL change not yet submitted, not on this branch alone: 11883 passed, 165 skipped, 1 xfailed, none failed (rerun after the follow-up commits).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