Repository navigation
COBOL/PL/I units run to the next header, not the last GOBACK/EXIT/RETURN (#4301, #4283) - #4315
Merged
Merged
Conversation
…URN (#4301, #4283) Mode A (_slice_by_labels) cut every unit at its last line-leading match of the shared assembly_returns vocabulary. In COBOL and PL/I those words are statements: a GOBACK inside IF ... END-IF, a CICS RETURN TRANSID on its own line inside an IF, PL/I ELSE RETURN;, EXIT PERFORM / EXIT PARAGRAPH mid-body, and even the paragraph's own header (RETURN-TO-PREV-SCREEN.). Everything after the cut fell outside every unit, losing its PERFORM/CALL edges (UPDCUST had none at all, #4283). COBOL and PL/I now take no terminator cut. A unit runs to the next unit header, or to its structural end: COBOL stops before a line-leading END PROGRAM (and its OO/function siblings, END DECLARATIVES) or the next program's DIVISION / *-ID header; PL/I stops after the procedure's own labelled `END name;`. Assembly and the other Mode A languages keep the cut. Golden masters regenerated in both legs (full + zero-dep); every change is mainframe unit spans/edges plus the layout ripple of the changed directory magnitudes (X/Z only) and PageRank at the 1e-6 rounding level. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo
Contributor
…e it (#4301) The CBSA BNK1*/BNKMENU A010 paragraphs were only 'named' by an abend message literal ('... - A010 - RETURN TRANSID ... FAIL') in the code the old terminator cut left outside the paragraph. With the tail back inside A010, nothing outside its own span names it, so the engine's by-name liveness reports it unused -- the existing deliberate #2806 divergence (engine dead = unreferenced by name; A010 is reached by fall-through from the PREMIERE section header), the same cause its sibling *010 paragraphs already carry. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo
squid-protocol
marked this pull request as ready for review
October 4, 2026 15:22
This was referenced Oct 4, 2026
Merged
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 #4301
Fixes #4283
What was broken
detector._slice_by_labels(Mode A) cut every unit at its last line-leading match of the sharedassembly_returnsvocabulary (RETURN|GOBACK|EXIT|...). That is right for assembler. It is wrong for COBOL and PL/I, where these words are statements:IF ... GOBACK END-IF(CBSAUPDCUST.cbl:194,CRECUST.cbl:411,BANKDATA.cbl:406), a CICSRETURN TRANSID(...)line inside anIF(BNK1CAC/CCA/CCS/CRA/DAC/DCS/TFN/UAC,BNKMENU), PL/IELSE RETURN;(DSFR0010422-25.pli)\bRETURN\bmatchesRETURN-TO-PREV-SCREEN.(CardDemo), so the unit was cut to its header lineEXIT PERFORM/EXIT PARAGRAPH/EXIT SECTIONmid-bodyEverything after the cut was outside every unit, so its PERFORM/CALL edges, LOC and complexity were lost. UPDCUST had no PERFORM edges at all (#4283).
The fix
I took the structural option the acceptance criteria list first, not the per-language keyword opt-out. COBOL and PL/I no longer take the terminator cut. A unit runs to the next unit header, or to its structural end:
END PROGRAM(orEND FUNCTION/METHOD/CLASS/FACTORY/OBJECT/DECLARATIVES), or before the next program's... DIVISION/PROGRAM-ID-style header. The match is line-leading after the cols 1-6 sequence area, and it needs a whole word ((?![\w-])), soPERFORM END-PROGRAM-RTNor a literal can't end a unit. The marker line itself is not part of the unit.END name;. A bareEND;can close a DO group or BEGIN block, so it is not used. A procedure closed by an unlabelled END still runs to the next header, which is the same approximation as before for nested procs.Assembly, REXX, batch, ABAP, Fortran and the other Mode A languages are unchanged. A regression test pins assembly's
retcut.Why structural and not the opt-out: the opt-out (criterion 2) would also need hyphen-aware matching at line start. It would still leave the last paragraph of a program running through
END PROGRAMinto the next program's ID/DATA divisions. The NIST multi-program files andgnucobol_internals/syn_misc.atshow that happening today: oneP04unit spanned 1,677 lines of unrelated test programs and collected phantom callees likesomething,prog2andCBL_GC_FORK.Evidence
Repro
REPRO1.cblfrom the issue, before → after:calls_out_to=[][AFTER-GOBACK-TARGET, SUBPGM1, RETURN-TO-MENU, LOOP-PARA][][IN-RETURN-PARA-TARGET]EXIT PERFORM)AFTER-EXIT-PERFORM-TARGETCorpus (language-crucible v1.7.0), per-unit before/after dump of all 628 COBOL/PL/I files:
UPDCUST.cblA010: L138-194[]→ L138-205[UPDATE-CUSTOMER-VSAM, GET-ME-OUT-OF-HERE](COBOL engine: UPDCUST records no PERFORM edges #4283)CRECUST.cblP010: L358-411[]→ L358-475, +7 edges (incl. CREDIT-CHECK, WRITE-CUSTOMER-VSAM)BANKDATA.cblA010: L370-406 → L370-673, +5 edgesBNK1CAC/CCA/CCS/CRA/DAC/DCS/TFN/UAC.cbl,BNKMENU.cblA010: +POPULATE-TIME-DATE,ABEND-THIS-TASKR0010422/23/24/25.pliKONTROLL_AV_INPUT: +SEND_MAPRETURN-TO-*paragraphs (12): loc 1 → the full body. COBIL00CRETURN-TO-PREV-SCREENis L273-273 → L273-284.Totals: 141 files have a unit change, and no unit was added or removed. 170 spans grew and 150 shrank. 36 edges were added across 17 files, and 28 were removed. Every removed edge was a phantom from
gnucobol_internals/syn_misc.at, where a unit used to swallow later test programs. Examples:something,without,FOREVER,prog2,CBL_GC_FORK, and 60-digit literals.The spans that shrank stop at
END PROGRAMor the next program'sIDENTIFICATION DIVISION: CICS-Cobol 49, NIST ccvs85 39 (e.g.IC2344.2.cblCCVS-999999 L361-471 → L361-361), syn_misc 28, lsp fixtures 18. Separately, DSF and zopeneditor PL/I procs now end at their ownEND name;instead of running into the blank lines before the next PROC.Spans that grew, other than the ones listed above, mostly gain the paragraph's closing
.afterEXIT(CardDemo*-EXITparagraphs, +1 line).New tests:
tests/extraction/languages/test_unit_end_4301.pyhas 9 tests. They cover the verbatim repro (all three shapes), a CICS RETURN inside IF, EXIT PARAGRAPH, END PROGRAM and sibling-program caps, a nested-program header, hyphenatedEND-PROGRAM-RTN, PL/IELSE RETURN;, and the unchanged assembly cut. Six of them fail on main.Golden-master diff (both legs regenerated, identical shape: 6,063 diffs each)
Topological CoordinatesX/Z (721 / 716 files, max |Δ| 0.81) and PageRank (35 files, Δ = 1e-6, the rounding level). X/Z move becausespatial_mapperpacks directory sectors in a spiral whose radii depend on group magnitude. The mainframe groups' magnitudes changed, so later sectors shift. Y is hash jitter only and does not move, which is consistent with this. PageRank is a whole-graph distribution, so it shifts when edges are added. No non-mainframe file's own extraction (functions, edges, counts) changed.pytest -m golden_crucible tests/test_golden_crucible.pypasses in both venvs.Ground-truth ledger (mainframe-ground-truth)
There are 18 new
engine | dead* | BNK1{CAC,CCA,CCS,CRA,DAC,DCS,TFN,UAC}/BNKMENU.cbl | A010 | fpentries, one per field (dead and dead non-trivial). I assigned them to the existing deliberate causeengine_dead_is_unreferenced_by_name(#2806). The sibling*010paragraphs of the same files already carry that cause.Why they appear: before this PR, the only text that "named" A010 was an abend-message literal (
'BNK1CAC - A010 - RETURN TRANSID(OCAC) FAIL', BNK1CAC.cbl:258/301) in the code the old cut had left outside A010. With that code back inside A010, nothing outside its own span names it. The engine's by-name liveness therefore calls it unused, while the key has it reached by fall-through fromPREMIERE SECTION. The engine-dead scoreboard goes from 247 to 256 (non-trivial: 211 to 220).ground_truth_ledger.py checkis clean locally, andtests/cobol_mainframepasses (1,363).Local checks
tests/extraction,tests/core_engine,tests/cobol_mainframe: 13,116 passedmypy_audit --ci,ruff_audit --ci(ruff 0.16.0),dead_key_audit --ci: no new findingsNot in this PR
PERFORM TEST ...andEXIT PERFORMfollowed byEND-IFread as callees: these are COBOL engine: inline PERFORM forms produce phantom callees (TEST,FOREVER,WS-NofWS-N TIMES,3,END-IFafterEXIT PERFORM) #4305 and were already there. One newTESTedge shows up inBANKDATA.cblbecause its body is now inside a unit. The repro's LOOP-PARA also showsEND-IF/TEST. I left them for COBOL engine: inline PERFORM forms produce phantom callees (TEST,FOREVER,WS-NofWS-N TIMES,3,END-IFafterEXIT PERFORM) #4305.🤖 Generated with Claude Code