Skip to content

COBOL/PL/I units run to the next header, not the last GOBACK/EXIT/RETURN (#4301, #4283) - #4315

Merged
squid-protocol merged 2 commits into
mainfrom
fix/4301-cobol-pli-conditional-terminator
Oct 4, 2026
Merged

squid-protocol merged 2 commits into
mainfrom
fix/4301-cobol-pli-conditional-terminator

Conversation

@squid-protocol

@squid-protocol squid-protocol commented Oct 4, 2026 •

Copy link
Copy Markdown
Owner

Fixes #4301
Fixes #4283

What was broken

detector._slice_by_labels (Mode A) cut every unit at its last line-leading match of the shared assembly_returns vocabulary (RETURN|GOBACK|EXIT|...). That is right for assembler. It is wrong for COBOL and PL/I, where these words are statements:

  • a conditional terminator: IF ... GOBACK END-IF (CBSA UPDCUST.cbl:194, CRECUST.cbl:411, BANKDATA.cbl:406), a CICS RETURN TRANSID(...) line inside an IF (BNK1CAC/CCA/CCS/CRA/DAC/DCS/TFN/UAC, BNKMENU), PL/I ELSE RETURN; (DSF R0010422-25.pli)
  • the paragraph's own name: \bRETURN\b matches RETURN-TO-PREV-SCREEN. (CardDemo), so the unit was cut to its header line
  • EXIT PERFORM / EXIT PARAGRAPH / EXIT SECTION mid-body

Everything 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:

  • COBOL: the unit stops before a line-leading END PROGRAM (or END 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-])), so PERFORM END-PROGRAM-RTN or a literal can't end a unit. The marker line itself is not part of the unit.
  • PL/I: the unit stops after the procedure's own labelled END name;. A bare END; 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 ret cut.

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 PROGRAM into the next program's ID/DATA divisions. The NIST multi-program files and gnucobol_internals/syn_misc.at show that happening today: one P04 unit spanned 1,677 lines of unrelated test programs and collected phantom callees like something, prog2 and CBL_GC_FORK.

Evidence

Repro REPRO1.cbl from the issue, before → after:

unit before after
MAIN-PARA L11-13, calls_out_to=[] L11-18, [AFTER-GOBACK-TARGET, SUBPGM1, RETURN-TO-MENU, LOOP-PARA]
RETURN-TO-MENU L19-19, [] L19-21, [IN-RETURN-PARA-TARGET]
LOOP-PARA L22-25 (cut at EXIT PERFORM) L22-33, includes AFTER-EXIT-PERFORM-TARGET

Corpus (language-crucible v1.7.0), per-unit before/after dump of all 628 COBOL/PL/I files:

  • UPDCUST.cbl A010: L138-194 [] → L138-205 [UPDATE-CUSTOMER-VSAM, GET-ME-OUT-OF-HERE] (COBOL engine: UPDCUST records no PERFORM edges #4283)
  • CRECUST.cbl P010: L358-411 [] → L358-475, +7 edges (incl. CREDIT-CHECK, WRITE-CUSTOMER-VSAM)
  • BANKDATA.cbl A010: L370-406 → L370-673, +5 edges
  • BNK1CAC/CCA/CCS/CRA/DAC/DCS/TFN/UAC.cbl, BNKMENU.cbl A010: + POPULATE-TIME-DATE, ABEND-THIS-TASK
  • DSF R0010422/23/24/25.pli KONTROLL_AV_INPUT: + SEND_MAP
  • CardDemo RETURN-TO-* paragraphs (12): loc 1 → the full body. COBIL00C RETURN-TO-PREV-SCREEN is 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 PROGRAM or the next program's IDENTIFICATION DIVISION: CICS-Cobol 49, NIST ccvs85 39 (e.g. IC2344.2.cbl CCVS-999999 L361-471 → L361-361), syn_misc 28, lsp fixtures 18. Separately, DSF and zopeneditor PL/I procs now end at their own END 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 . after EXIT (CardDemo *-EXIT paragraphs, +1 line).

New tests: tests/extraction/languages/test_unit_end_4301.py has 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, hyphenated END-PROGRAM-RTN, PL/I ELSE RETURN;, and the unchanged assembly cut. Six of them fail on main.

Golden-master diff (both legs regenerated, identical shape: 6,063 diffs each)

  • Mainframe files (cobol/pli): the function-level channels move on the 140 files listed above: 5. Function Analysis 140 files; Calls Out To / Fan Out 16 files; Fan In 16; Usage Status 14; Unreferenced By Name 14; Function Archetype 48. The derived per-file channels follow from that: function z-scores, archetype mix and fingerprint, composition fit, structural magnitude, risk exposures, and directory-group magnitude/averages for the 9 mainframe directory groups. The global composition/impact for cobol/pli and the archetype distribution move with them.
  • Non-mainframe files: only Topological Coordinates X/Z (721 / 716 files, max |Δ| 0.81) and PageRank (35 files, Δ = 1e-6, the rounding level). X/Z move because spatial_mapper packs 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.py passes 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 | fp entries, one per field (dead and dead non-trivial). I assigned them to the existing deliberate cause engine_dead_is_unreferenced_by_name (#2806). The sibling *010 paragraphs 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 from PREMIERE SECTION. The engine-dead scoreboard goes from 247 to 256 (non-trivial: 211 to 220). ground_truth_ledger.py check is clean locally, and tests/cobol_mainframe passes (1,363).

Local checks

  • tests/extraction, tests/core_engine, tests/cobol_mainframe: 13,116 passed
  • mypy_audit --ci, ruff_audit --ci (ruff 0.16.0), dead_key_audit --ci: no new findings

Not in this PR

🤖 Generated with Claude Code

…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
@github-actions

github-actions Bot commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

…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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant