Repository navigation
Conversation
fin-github
left a comment
There was a problem hiding this comment.
python -I tests/test_shader_ir.pyon the PR: 41 tests OK.- The PR's test file against
main(4a50caf):test_long_message_tail_is_counted_a_line_at_a_timefails (peak
memory over a quarter of the file), so the test catches the old whole-file read.
I checked the rewrite against the old function by hand: the header is still taken only from line 0, a line 0 that
starts with a tab is still parsed as an instruction, instruction parsing still stops at ; ---, and
invalid instruction encoding is still counted over the whole file, both before and after that marker. Passing each
line of the file through splitlines() also keeps a blank line ("\n".splitlines() == [""]). Looks good to me.
Tested on Windows 11 Pro 26200, CPython 3.14.4, applied on main 4a50caf. No GPU or game files used. AI-assisted (Claude Code).
…ING) parse_file read the whole listing into memory, split it into lines and joined them again to count the "invalid instruction encoding" messages. llvm-mc prints its whole input line under each of those messages, so the messages of a program with many undecodable words are many times the size of its instructions, and parse_file needed about twice the file size in memory to find the instructions at its start. Read the file one line at a time. Lines are split as str.splitlines() split the whole text, the first line is still the header unless it is an instruction, and the messages after "; ---" are counted without being kept. The result is the same for every input. tests/test_shader_ir.py gets a synthetic listing with 400 messages (4.5 MB). The base peaks at 9.2 MB for it and fails the new check; this change peaks at 0.17 MB. 20,000 random synthetic listings parse to the same result before and after. The standard-library tests and the translator suite add no failing file. AI-assisted (Claude Code). Co-authored-by: Plaaasma <47513553+Plaaasma@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
7367423 to
47d9c3b
Compare
|
Thanks for checking the memory regression. #984 brought streaming reads into main along with diagnostic offsets. The rebase keeps that parser and adds the large-tail and empty-file checks from this PR. All 41 shader IR tests passed on AI-assisted. |
Rebased onto
bfef489cat47d9c3b8. 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_fileread the whole listing into one string, split it into lines and, after the instructions, joined the lines again to count theinvalid instruction encodingmessages. The messages can be far larger than the instructions: llvm-mc prints its whole input line under every word it cannot decode, andshader_disasm.pygives 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), andparse_fileheld 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_filenow reads one line at a time. The messages after; ---are counted and dropped. Nothing else changes: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;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 newtest_long_message_tail_is_counted_a_line_at_a_timewrites a synthetic listing of two instructions and 400 messages that each repeat a 2,048-byte input line (4,519,727 bytes), and requirestracemalloc's peak duringparse_fileto 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.tools/shader_ir.py(an export of6293c1c4fwith only the test file replaced): 1 failure, that test,9229703 not less than 1129931. The other 40 pass there.; ---, 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'sparse_fileand this one.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) andtests/test_shader_ir_parse.py(3): all pass.ci.ymlruns it (compileall, everytests/test_*.pyoutsidetests/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
6293c1c4f, one commit.docs/design.md.🤖 Generated with Claude Code