[PR #1283] [CLOSED] shader_ir: read a listing a line at a time (TOOLS-DISASM-BOUNDED-LISTING) #1315

Closed
opened 2026-11-26 20:20:50 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1283
Author: @Moriz82
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: split/tools-disasm-bounded-listing


📝 Commits (1)

  • 47d9c3b shader_ir: read a listing a line at a time (TOOLS-DISASM-BOUNDED-LISTING)

📊 Changes

1 file changed (+35 additions, -0 deletions)

View changed files

📝 tests/test_shader_ir.py (+35 -0)

📄 Description

Rebased onto bfef489c at 47d9c3b8. Main already streams listings and retains the diagnostic offsets. This diff adds the large-tail and empty-file checks, which pass with the current parser. The shader IR suite passed 41 tests.

Claimed in the coordination issue as: TOOLS-DISASM-BOUNDED-LISTING (claim).

Part of the split of #984 into small pull requests.

Depends on: none
Overlaps: #984 is the parent integration. #623 (open, OLD-10020) hands llvm-mc its input in lines of 64 bytes in tools/shader_disasm.py; that also bounds what llvm-mc repeats under each message, so the integration's own change to that line (one dword per line) is left to #623 and is not repeated here. This pull request is the reader's side, tools/shader_ir.py, which #623 does not touch. #365 (open) rewords the docstring of the same file, 230 lines above this hunk. Both merge cleanly with this branch (each applied to the base and merged three-way).

What and why

shader_ir.parse_file read the whole listing into one string, split it into lines and, after the instructions, joined the lines again to count the invalid instruction encoding messages. The messages can be far larger than the instructions: llvm-mc prints its whole input line under every word it cannot decode, and shader_disasm.py gives it the program as one line and writes its messages to the end of the listing. A program of N bytes with B undecodable words leaves about 5·N·B bytes of messages (plus the caret lines), and parse_file held about twice the file in memory to read the few instructions at its start. Every tool that parses listings goes through it, the translator included.

parse_file now reads one line at a time. The messages after ; --- are counted and dropped. Nothing else changes:

  • lines are split as str.splitlines() split the whole text (each line of the file is passed through it), so a listing with a form feed or another of its separators parses as before;
  • the first line is still the header, and still an instruction when it starts with a tab;
  • the result dictionary has the same keys in the same order.

With #623 new listings get short message lines. Listings written before it, and any program with very many undecodable words, still have long tails, and those are the ones this is for.

Tested

Linux (CachyOS, kernel 7.3.5), Python 3.14. One commit on 6293c1c4f.

  • python3 -I tests/test_shader_ir.py: 41 tests pass (39 before, 2 new). The new test_long_message_tail_is_counted_a_line_at_a_time writes a synthetic listing of two instructions and 400 messages that each repeat a 2,048-byte input line (4,519,727 bytes), and requires tracemalloc's peak during parse_file to stay under a quarter of the file size. Peak with this change: 172,394 bytes (Python 3.14 reads through a 128 KiB buffer). The other new test covers an empty file and a last line without a newline.
  • The same test file with the base commit's tools/shader_ir.py (an export of 6293c1c4f with only the test file replaced): 1 failure, that test, 9229703 not less than 1129931. The other 40 pass there.
  • With 1,600 messages (22,879,127 bytes, not part of the test): base peak 46,124,671 bytes, this change 178,412 bytes.
  • A differential run that is not part of the change: 20,000 random listings built from 23 synthetic lines (headers, instructions with and without encodings, directives, ; ---, message lines, lines with form feed, NEL, U+2028 and U+001E, joined with LF, CRLF or CR, with and without a final newline) give equal dictionaries, key order included, from the base's parse_file and this one.
  • Files that call parse_file: tests/test_cf_ref.py (26), tests/test_cf_ref_edge_fixes.py (5), tests/test_wave_diff.py (12), tests/test_sampler_source_census.py (30), tests/test_wave32_pixel_scan.py (13), tests/test_rdna2spirv_decode.py (25), tests/semantic/test_missing_encoding.py (3) and tests/test_shader_ir_parse.py (3): all pass.
  • The CI loop as ci.yml runs it (compileall, every tests/test_*.py outside tests/semantic, the semantic suite, the tracked-file guard), on the committed tree: one failing file, tests/test_imhex_patterns.py, which fails on the base commit too and is the only one there. Semantic suite: 470 files, 6,168 tests, 0 files failed, the same counts as the base.
  • python3 -I scripts/check_no_game_data.py: passes.

Not run: a real corpus (no listing of a game shader was read for this), native Windows or macOS, the runtime build (no C++ or build file changes).

GPUs tested: none (a text parser).

AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named.

Checklist

  • Based on upstream main 6293c1c4f, one commit.
  • One topic: one function and its tests.
  • No game data, keys or decryption; the listings in the tests are hand-written.
  • No translator rule changed, so no row in docs/design.md.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1283 **Author:** [@Moriz82](https://github.com/Moriz82) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `split/tools-disasm-bounded-listing` --- ### 📝 Commits (1) - [`47d9c3b`](https://github.com/ubiquitarianism/leonida/commit/47d9c3b8fb57e54798efe7ea6902a0500961d977) shader_ir: read a listing a line at a time (TOOLS-DISASM-BOUNDED-LISTING) ### 📊 Changes **1 file changed** (+35 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_shader_ir.py` (+35 -0) </details> ### 📄 Description **Rebased onto `bfef489c` at `47d9c3b8`.** Main already streams listings and retains the diagnostic offsets. This diff adds the large-tail and empty-file checks, which pass with the current parser. The shader IR suite passed 41 tests. Claimed in the coordination issue as: TOOLS-DISASM-BOUNDED-LISTING ([claim](https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7144686585)). Part of the split of #984 into small pull requests. Depends on: none Overlaps: #984 is the parent integration. #623 (open, OLD-10020) hands llvm-mc its input in lines of 64 bytes in `tools/shader_disasm.py`; that also bounds what llvm-mc repeats under each message, so the integration's own change to that line (one dword per line) is left to #623 and is not repeated here. This pull request is the reader's side, `tools/shader_ir.py`, which #623 does not touch. #365 (open) rewords the docstring of the same file, 230 lines above this hunk. Both merge cleanly with this branch (each applied to the base and merged three-way). ### What and why `shader_ir.parse_file` read the whole listing into one string, split it into lines and, after the instructions, joined the lines again to count the `invalid instruction encoding` messages. The messages can be far larger than the instructions: llvm-mc prints its whole input line under every word it cannot decode, and `shader_disasm.py` gives it the program as one line and writes its messages to the end of the listing. A program of N bytes with B undecodable words leaves about 5·N·B bytes of messages (plus the caret lines), and `parse_file` held about twice the file in memory to read the few instructions at its start. Every tool that parses listings goes through it, the translator included. `parse_file` now reads one line at a time. The messages after `; ---` are counted and dropped. Nothing else changes: - lines are split as `str.splitlines()` split the whole text (each line of the file is passed through it), so a listing with a form feed or another of its separators parses as before; - the first line is still the header, and still an instruction when it starts with a tab; - the result dictionary has the same keys in the same order. With #623 new listings get short message lines. Listings written before it, and any program with very many undecodable words, still have long tails, and those are the ones this is for. ### Tested Linux (CachyOS, kernel 7.3.5), Python 3.14. One commit on `6293c1c4f`. - `python3 -I tests/test_shader_ir.py`: 41 tests pass (39 before, 2 new). The new `test_long_message_tail_is_counted_a_line_at_a_time` writes a synthetic listing of two instructions and 400 messages that each repeat a 2,048-byte input line (4,519,727 bytes), and requires `tracemalloc`'s peak during `parse_file` to stay under a quarter of the file size. Peak with this change: 172,394 bytes (Python 3.14 reads through a 128 KiB buffer). The other new test covers an empty file and a last line without a newline. - The same test file with the base commit's `tools/shader_ir.py` (an export of `6293c1c4f` with only the test file replaced): **1 failure**, that test, `9229703 not less than 1129931`. The other 40 pass there. - With 1,600 messages (22,879,127 bytes, not part of the test): base peak 46,124,671 bytes, this change 178,412 bytes. - A differential run that is not part of the change: 20,000 random listings built from 23 synthetic lines (headers, instructions with and without encodings, directives, `; ---`, message lines, lines with form feed, NEL, U+2028 and U+001E, joined with LF, CRLF or CR, with and without a final newline) give equal dictionaries, key order included, from the base's `parse_file` and this one. - Files that call `parse_file`: `tests/test_cf_ref.py` (26), `tests/test_cf_ref_edge_fixes.py` (5), `tests/test_wave_diff.py` (12), `tests/test_sampler_source_census.py` (30), `tests/test_wave32_pixel_scan.py` (13), `tests/test_rdna2spirv_decode.py` (25), `tests/semantic/test_missing_encoding.py` (3) and `tests/test_shader_ir_parse.py` (3): all pass. - The CI loop as `ci.yml` runs it (compileall, every `tests/test_*.py` outside `tests/semantic`, the semantic suite, the tracked-file guard), on the committed tree: one failing file, `tests/test_imhex_patterns.py`, which fails on the base commit too and is the only one there. Semantic suite: 470 files, 6,168 tests, 0 files failed, the same counts as the base. - `python3 -I scripts/check_no_game_data.py`: passes. Not run: a real corpus (no listing of a game shader was read for this), native Windows or macOS, the runtime build (no C++ or build file changes). GPUs tested: none (a text parser). AI-assisted: yes (Claude Code). The numbers above come from runs on the machine named. ### Checklist - [x] Based on upstream main `6293c1c4f`, one commit. - [x] One topic: one function and its tests. - [x] No game data, keys or decryption; the listings in the tests are hand-written. - [x] No translator rule changed, so no row in `docs/design.md`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
4ld0 2026-11-26 20:20:50 +01:00
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1315
No description provided.