Repository navigation
COBOL record_data: read every program's DATA DIVISION in a multi-program source (#4245) - #4360
Merged
Merged
Conversation
…ram source (#4245) A source holding several programs (a nested program, batch-compiled siblings; IBM DBB epscsmrd.cbl has 13 PROGRAM-IDs) has one DATA DIVISION per program. The engine's _cobol_records and the answer key's _data_items read only the first one. Both now read each DATA DIVISION up to its own PROCEDURE DIVISION, and no group stays open from one program into the next. GalaxyIR derives each item's owning program (EngineDataItem.program) from the programs' PROCEDURE DIVISION lines. Name resolution is scoped to the program a statement is written in, so sibling programs' same-named records are separate storage. This covers data_flows, call_contracts, dynamic CALL targets, DL/I operands and field_lineage. Record keys and spans carry the program. A name a program does not declare falls back to the nearest earlier program (a container's GLOBAL item). The refraction differential gains a forge_first_program cause: the forge still renders a multi-program source from its first program only. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo
Contributor
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 #4245
What was broken
A source can hold several programs: a nested program, or batch-compiled siblings. IBM DBB
epscsmrd.cblhas 13 PROGRAM-IDs, and estate-crucible H-0031 plants PAYMAIN with a nested PAYCALC and a sibling'PAYRPT'. Each program has its own DATA DIVISION. Both readers took the firstDATA DIVISIONmatch up to the firstPROCEDURE DIVISION, so the other programs' items were never read:mainframe_boundary._cobol_records: epscsmrd had 65 records, the last at line 138;cobol_answer_key._data_items: the same 65.The fix
EngineDataItem.programfrom the programs' PROCEDURE DIVISION lines. An item belongs to the first program whose PROCEDURE DIVISION follows it, and a statement belongs to the last program whose PROCEDURE DIVISION precedes it. This holds for nested programs and siblings alike. A one-program source, or one where the PROCEDURE DIVISIONs don't pair up with the PROGRAM-IDs, is unscoped, which is the old reading.WS-AREAvisible, each MOVE becameambiguous, and the storage key(file, root name)merged two different records. GalaxyIR now scopes name resolution to the program a statement is written in, and record keys and spans carryprogram. Scoped consumers:data_flowscall_contracts: caller and callee bytes.CALL 'PAYRPT'also enters PAYRPT's ownPROCEDURE DIVISION USING.dynamic_call_targets: VALUEs and MOVEs.ims_callsandims_psbs: VALUE lookups.field_lineage: new optionalprogram=argument; overlap and keys compare the program.01 GLOBAL-DATA IS GLOBAL. The compiler rejects any other undeclared name, so this fallback is safe. Without it, 6 NIST MOVEs regressed to unresolved during development.Not scoped (they keep the whole-file lookup they had): CICS COMMAREA/record lookups (
commarea_contracts,_commarea_unpack, CICSrecord_of,_position_in,_length_expr). Multi-program CICS members are rare. These lookups take the first match or require a unique one, so they are no worse than before.Evidence (before → after)
tests/cobol_mainframe/test_multi_program_data_4245.py(9 tests; 8 fail on main). It covers a nested program plus a quoted sibling:MOVE WS-IN TO WS-Ain PAYMAIN resolves toWS-AREA/PAYMAIN @0+4, and in PAYRPT toWS-AREA/PAYRPT @2+8(bothambiguouswith only the reader fix);CALL 'PAYRPT'pairs with LK-RPT (12 bytes);CALL WS-PGMgives PAYSUB1 vs PAYSUB2;field_lineage(program=)stays in its program;programNone.test_completeness.py). OneMOVE XML-CODE TO ERROR-CODEbecamesystem. The 18 still open are XML PARSE special registers (XML-TEXT / XML-NTEXT): 11 in EPSCSMRD and 7 in EPSCSMRT, not this issue.Estate-crucible (v0.3.0), main 8be548a → this branch
No other horror or channel moves (32/49 horrors pass).
Golden masters (both legs regenerated; identical diffs)
MOVE L-A1 TO L-Cnow resolves its source.I checked every flow in the 7 multi-program crucible sources before and after. The only change is that one resolution. The GLOBAL fallback keeps IC2284's GLO-DATA-1..4 and IC2344's DILFRAP resolved.
pytest -m golden_cruciblepasses in both venvs.Found while reading the golden diff: IC2244's new 77-level items get the FILE SECTION 01 above them as parent. This is a pre-existing bug (366 such rows on main). It is filed as #4359 and not fixed here.
Ground-truth ledger
ground_truth_ledger.py update: no change.check: clean (10 mismatches, all the deliberateengine_dead_is_unreferenced_by_name).Refraction differential
DBB
[full]was blessed at 33 unexplained, with a note to "re-bless when #4245 lands". The forge'scobol_schema_forgestill renders a multi-program source from its first program only. So I added the causeforge_first_program: a schema delta that the engine's schema over the first program alone does not show. The rule has a unit test and a row indocs/refraction_engine_differential.md. DBB is now 26 unexplained (the same 26 first-programforge_flat_schemanames as before), 198forge_first_program. The baseline note was rewritten; the gate number only went down.Local checks
tests/cobol_mainframe,tests/extractionandtests/core_engine(pinned corpora): 13,231 passed in the full venv.mypy_audit --ci,ruff_audit --ci(0.16.0) anddead_key_audit --cireport nothing new.🤖 Generated with Claude Code
https://claude.ai/code/session_01FNWHcUSn5p7eMxFTsB5rFo