Repository navigation
COBOL: record each PROCEDURE DIVISION's entry code as a calls-only unit (#4302) - #4323
Merged
Merged
Conversation
…it (#4302) Statements between `PROCEDURE DIVISION.` and the first paragraph or section header -- a batch program's main line -- belonged to no unit, so the top of the program's call tree (PERFORM/CALL/GO TO) was recorded nowhere and the paragraphs it drives had no caller. Each PROCEDURE DIVISION's entry code (from the header's separator period to the first unit header, or the program's end / next program's header) now becomes a calls-only `__global_context__` bucket, Python's module-level shape: stored in synthetic_unit_data, out of the function population, no weight. Kept only when it carries an edge. Sibling and nested programs each get their own. Golden masters regenerated in both legs. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo
Contributor
squid-protocol
marked this pull request as ready for review
October 4, 2026 15:49
This was referenced Oct 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #4302
What was broken
A COBOL program can run statements right after
PROCEDURE DIVISION., before any paragraph or section header. Batch mains do this all the time: open the files, loop, close,GOBACK. Mode A only creates units at headers, so that code belonged to no unit. Its PERFORM/CALL/GO TO targets were recorded nowhere, and the paragraphs it drives had no caller. COBOL also never got a synthetic top-level slice the way Python gets__global_context__.The fix
I chose the second shape the acceptance criteria offer: a synthetic calls-only slice in
synthetic_unit_data, like Python's module-level bucket.For each
PROCEDURE DIVISIONheader, the entry code runs from the header's separator period (aUSING …/RETURNING …clause may span lines) to the first unit header after it. If the program ends first, or the next program's header comes first (#4301's_COBOL_UNIT_END_RE), it stops there. The entry code becomes a calls-only__global_context__unit:is_synthetic_sliceandcalls_only, so it stays out of the function population andfunction_data;calls_out_toandtransfers_to, and the call resolver turns those into edges;start_line;DISPLAY … STOP RUNmain produces no row.Why not a real unit: a real unit would add a function to every such program. That changes the function population, the answer key's
unitsfield and the dead-code census. The calls-only slice records the edges, which is what the issue is about, without inventing a paragraph.The code is in
detector._cobol_procedure_entry_units, called right after_slice_by_labelsfor COBOL.Evidence
__global_context__L7-10 hascalls_out_to = [ENTRY-TARGET, MAIN-PARA].[0000-ACCTFILE-OPEN, 1000-ACCTFILE-GET-NEXT, 9000-ACCTFILE-CLOSE]. All three paragraphs go from fan-in 0 to 1 in the golden output.gnucobol_internals/syn_misc.atadds 17. It is an autotest file with many embedded test programs, and its entry regions run into the harness text (AT_SETUP([... CALL USING ...])).tests/extraction/languages/test_cobol_procedure_entry_4302.py: 6 tests, 5 of which fail on main. They cover:PERFORM UNTIL;USINGheader plus GO TO →transfers_to;Golden-master diff (both legs regenerated: 830 diffs each, same paths)
CALL.cbl, Z-SMSMESSAGES.cbl): newfcall:file edges from entry-code CALLs.Row Counts/Functionsgoes from 49,030 to 49,057. The graph DB keeps a function node per (file, caller) for synthetic callers too, as it does for Python's bucket.correlate_scopeduses unit ranges, so a state mutation in the entry code can no longer pair with a branch inside the first paragraph within 150 chars.equationsfor CASH00 are byte-identical before and after.pytest -m golden_cruciblepasses in both venvs.Ground-truth ledger
ground_truth_ledger.py checkis clean. The answer key scoresfunction_dataunits, which this PR does not change, so there are no ledger changes.Local checks
tests/extraction,tests/core_engine,tests/cobol_mainframe: 13,156 passedmypy_audit --ci,ruff_audit --ci(0.16.0),dead_key_audit --ci: nothing newNoted, not in scope
calls_outrule's known gaps, not from this change:PERFORM 5 TIMES→5(tutorial.cob) andPERFORM FOREVER(syn_misc) are COBOL engine: inline PERFORM forms produce phantom callees (TEST,FOREVER,WS-NofWS-N TIMES,3,END-IFafterEXIT PERFORM) #4305;CALL STATIC "stuff"→STATIC(syn_misc).__global_context__, so in the call graph their edges merge per file. They stay separate rows insynthetic_unit_data(distinctstart_line).🤖 Generated with Claude Code