Skip to content

det: DFSORT SORT step cards lowered to a COBOL SORT program, proven against GnuCOBOL (Part of #4268) - #6975

Merged
squid-shepherd[bot] merged 2 commits into
mainfrom
churn/4268-20261029T0258Z
Oct 29, 2026
Merged

squid-shepherd[bot] merged 2 commits into
mainfrom
churn/4268-20261029T0258Z

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Part of #4268. The first slice the brief names (the SORT / MERGE / RELEASE / RETURN parser and SORT USING / GIVING) is already on main (#4286, #4540). This PR adds the next slice: a JCL SORT (DFSORT) step, modelled and proven.

What it does

  • gitgalaxy/tools/cobol_to_java/det/dfsort.py parses a SORT step's SYSIN and SYMNAMES into a model and lowers the step to a COBOL SORT program.
    • The oracle (GnuCOBOL in Docker) runs that program; the port is its det translation.
    • The SORTOUT bytes of the two are compared.
  • Modelled:
    • SORT / MERGE FIELDS=(p,m,f,o) with CH, BI, ZD and PD, FORMAT=, and FIELDS=COPY.
    • OPTION EQUALS (and the EQUALS operand), lowered to WITH DUPLICATES IN ORDER.
    • INCLUDE / OMIT COND: field against field or against a C'..', X'..' or decimal constant; AND / OR (& / |) with parentheses, AND binding tighter.
    • SYMNAMES fields and constants, with remarks.
    • Continuation lines and comments.
    • SORTIN as a concatenation of datasets.
  • Refused by name:
    • OUTREC / INREC / OUTFIL / SUM and every other statement.
    • The other formats.
    • Other OPTION or SORT operands.
    • MERGE without EQUALS (COBOL fixes an order DFSORT leaves open).
    • Cross-format comparisons.
    • A field outside the record.
  • Without EQUALS (the shipped default, EQUALS=NO), two records with equal keys and different bytes stop the port by name. The existing cobolrt/Sort behaviour is unchanged.
  • Oracle finding. Under -fsign=EBCDIC, GnuCOBOL's SORT rewrites a signed DISPLAY key's sign zone in the output records: 0001 comes out as 000A. DFSORT and Enterprise COBOL never change record bytes.
    • The lowering therefore carries a ZD or PD key as a copy ahead of the record and writes only the record.
    • This is recorded in F4 as a declared difference.
    • It also applies to a COBOL program's own SORT on a signed DISPLAY key over unsigned data; there the port already keeps the bytes, as IBM does.
  • docs/language_status/register/F4.md changes from REFUSED to PARTIAL and cites the DFSORT Application Programming Guide (SC23-6878).

Evidence

tests/cobol_mainframe/test_dfsort_4268.py, with EQUIVALENCE_E2E=1: GnuCOBOL and the det port produce byte-identical SORTOUT on six steps.

  • The verbatim CardDemo cards: TRANREPT STEP05R (ZD key plus INCLUDE over SYMNAMES date constants), SORTTEST, and COMBTRAN (two-dataset SORTIN).
  • COPY with OMIT.
  • OPTION EQUALS with a descending PD key and a BI key, with ties.
  • MERGE with EQUALS and INCLUDE.

Also in the file:

  • An equal-key run without EQUALS stops by name.
  • Parser and refusal unit tests.

Class / Sibling gaps

Class: JCL utility steps run by the generated batch job and the oracle (DFSORT, IEBGENER/ICEGENER, IDCAMS, IEFBR14). Census over the burned estates' JCL: CardDemo has 6 SORT, 17 IEBGENER, 63 IDCAMS and 11 IEFBR14 steps; CBSA has ICEGENER ×8, IEBGENER ×4 and IDCAMS ×2; GenApp has IDCAMS ×10 and IEBGENER ×2; zECS has IEBGENER ×29 and IDCAMS ×3. No burned COBOL program uses the SORT or MERGE verb.

Sibling gaps:

  • OUTREC FIELDS: CardDemo CREASTMT STEP010 and PRTCATBL.
  • OUTREC EDIT masks: PRTCATBL.
  • IDCAMS REPRO / DEFINE: COMBTRAN's second step, TRANREPT's REPROC, and most of the 63 CardDemo IDCAMS steps.
  • IEBGENER / ICEGENER: all four estates.
  • JclSteps.utility still refuses every utility step in the generated job; this model is not yet wired in.
  • Multi-step job harness: TRANREPT (SORT, then CBTRN03C).
  • FI and other formats, SUM, OUTFIL: no burned step needs them.

Remaining slices

  • Wire dfsort.py into the batch forge, so the generated job runs the SORT step instead of refusing it.
  • OUTREC / INREC FIELDS, including EDIT (CREASTMT, PRTCATBL).
  • IEBGENER / ICEGENER copy steps.
  • An IDCAMS REPRO / DEFINE subset.
  • A multi-step job case in the equivalence harness: TRANREPT, with SORT then CBTRN03C replacing the hand-sorted transact.txt.

Checklist

Checklist: partial [c:2148d504] -- the SORT programs are proven against the oracle in pytest; a tests/equivalence/ case that runs a SORT step is left
Checklist: partial [c:ac8b71e6] -- DFSORT subset modelled and proven; IEBGENER and IDCAMS REPRO / DEFINE are not modelled, and the forge still refuses every utility step
Checklist: partial [c:9e003ccd] -- F4 records the DFSORT subset and the oracle's key-sign rewrite; it gets updated again as IEBGENER / IDCAMS land

Gates

  • pr_gates --fast: 9/9 pass.
  • pr_gates --ratchets: 9 pass.
  • audit_check: all clear, after allowlisting the two DFSORT operand keys in dead_key_audit.
  • Guard tests plus the new file: 286 passed.
  • time_ratchet check: 0 over the limit.
  • register.py --check and audit --ci: clean.
  • Plain pytest run from /tmp: passes.

Lessons for agents

  • Under cobc -std=ibm -fsign=EBCDIC, GnuCOBOL's SORT rewrites the sign zone of a signed DISPLAY key in the records it writes (an unsigned 0001 comes out as 000A). Never prove record bytes through an oracle SORT keyed on a signed zoned field holding unsigned data; carry the key as a copy instead.

Facts checked:

🤖 Generated with Claude Code

squid-protocol and others added 2 commits October 28, 2026 23:15
…proven against GnuCOBOL (Part of #4268)

det/dfsort.py parses SYSIN / SYMNAMES (SORT / MERGE / COPY, INCLUDE / OMIT, OPTION EQUALS; CH, BI, ZD, PD) and
lowers the step to a COBOL SORT program; everything else is refused by name. The CardDemo TRANREPT, SORTTEST and
COMBTRAN cards are proven byte for byte (GnuCOBOL vs the det port). Register F4 updated.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@squid-protocol squid-protocol added the shepherd:merge Maintainer: merge when green (auto-merge, squash). Guide: docs/ci.md label Oct 29, 2026
@squid-shepherd

Copy link
Copy Markdown
Contributor

No description provided.

@squid-shepherd
squid-shepherd Bot marked this pull request as ready for review October 29, 2026 03:33
@squid-shepherd

Copy link
Copy Markdown
Contributor

No description provided.

@squid-shepherd
squid-shepherd Bot enabled auto-merge (squash) October 29, 2026 03:34
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

shepherd:merge Maintainer: merge when green (auto-merge, squash). Guide: docs/ci.md

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant