Skip to content

wave64_halves: --census a bad entry field is one error line, not a traceback - #4892

Open
SebSilent wants to merge 2 commits into
ItsNotRexed:mainfrom
SebSilent:fix/wave64-census-entry-types
Open

SebSilent wants to merge 2 commits into
ItsNotRexed:mainfrom
SebSilent:fix/wave64-census-entry-types

Conversation

@SebSilent

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new BUILD item, wave64_halves census entry fields

Depends on: builds on #1651 (merged, the document-shape guards). Open #4686 (--census --why) edits the same census() loop; whichever lands second needs a small rebase. The two changes are independent (this one validates field types, #4686 adds a why accumulator).

What and why

wave64_halves.py --census got document-shape guards in #1651 (unreadable path, non-JSON, non-dict root all become one ERROR: line, exit 2). But census() still trusted the per-entry fields:

  • wave64_graphics (the tier) is used as a Counter key. A list or dict tier is unhashable -> TypeError; an int tier works until two entries have mixed-type tiers, then sorted() raises TypeError.
  • wave64_graphics_reasons / wave64_graphics_idioms go to Counter.update. A non-list (e.g. an int) is not iterable -> TypeError; a list of lists/dicts is unhashable -> TypeError.

All exit 1 with a traceback. A malformed index.json is a usage error, like the cases #1651 already handles.

This validates each counted entry has a string tier and list-of-string reasons/idioms, raises ValueError, and catches it in main() as one ERROR: line, exit 2. The message names the field and its type, not the shader (the census is counts-only and must not leak shader names, as the existing CLI test checks).

Tested

Linux (CachyOS), Python 3.14.10. CPU only, no game files; synthetic index.json fixtures.

  • python -m pytest tests/test_wave64_halves_fixtures.py: 10 passed (9 existing + 1 new test with 6 subtests plus a mixed-tier case: list/dict/int tier, int reasons, list-of-list reasons, string idioms, mixed string+int tiers).
  • Red before: with the tool change stashed, the new test raises TypeError: cannot use 'list' as a dict key at wave64_halves.py:1527 (exit 1); green after with the fix (exit 2, one error line, no shader name, no stdout).
  • python -m compileall -q tools/wave64_halves.py tests/test_wave64_halves_fixtures.py, git diff --check: clean.

AI-assisted: yes (Tacit).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a, no translator rule)

…aceback

ItsNotRexed#1651 guarded the document shape (unreadable/non-JSON/non-dict) but not the
per-entry fields. A non-string wave64_graphics tier is unhashable (TypeError
on the Counter key), a non-list reasons/idioms is not iterable, a list of
non-strings is unhashable, and mixed-type tiers blow up sorted(): all exit 1
with a traceback. Validate each counted entry has a string tier and
list-of-string reasons/idioms, raise ValueError, and catch it in main() as
one ERROR line exit 2 naming the field, not the shader. Six synthetic cases
plus mixed tiers, red before green after.
@DenRakEiw

Copy link
Copy Markdown
Contributor

Tested on Windows 11 / Python 3.12.10 at head SHA 0850fb4a540599d2dcefd4aae5f124fb1e769d7c.

  • Trial-merge onto origin/main (d974c88a): clean (git diff --cached --check clean).
  • python -I -m pytest tests/test_wave64_halves_fixtures.py -v: 9 passed, 1 skipped (test_fixtures_are_classified_as_their_headers_say, requires llvm-mc / SPIR-V tools; note direct python -I tests/test_wave64_halves_fixtures.py fails with ModuleNotFoundError: No module named 'conftest' because -I omits tests/ from sys.path and the module uses pytest fixtures).
  • Code read: census() in tools/wave64_halves.py validates that wave64_graphics is a str and wave64_graphics_reasons / wave64_graphics_idioms are lists of str before updating Counters, raising ValueError without shader names for main() to turn into a single ERROR: line with exit code 2.

AI-assisted review (Gemini 4 Neon).

@shdann

shdann commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Tested 0850fb4 on Windows 11 with CPython 3.14.7. The CPU census checks pass.

python -I -m pytest -q tests/test_wave64_halves_fixtures.py reports 9 passes and 1 skip. The skipped shader fixture requires external assembler tools. On merge base d974c88, the new test fails with TypeError: cannot use 'list' as a dict key.

I also ran the CLI with two synthetic entries. The first entry has a valid tier. The second entry has wave64_graphics_reasons: ["valid", null]. The command exits with code 2. It prints one error that names the field. It prints no partial census.

AI-assisted.

…ry fields

ItsNotRexed#1651 asked for one ERROR line and exit 2 from a malformed census entry and ItsNotRexed#4892 did that for the
tier and the reason / idiom lists.  The why field of a tier C entry needs the same check: with
--census --why (SHADER-10) it is iterated to count where each reason comes from, so a null or an
int exited 1 with a TypeError traceback, and a plain string or a dict was taken apart into
characters or keys, matched no why line and counted nothing in silence.  Valid indexes are
untouched: rdna2spirv.py writes the field only when --wave64-why produced lines, and then as a
non-empty list of strings.
@SebSilent

Copy link
Copy Markdown
Contributor Author

@kacper-serewis's review finding on the #4686 + #4892 integration, as a second commit 1a144957: wave64_graphics_why now goes through the same field check as reasons/idioms.

Red, on a scratch merge of main d974c88a5 + #4686 09f87b92 + this branch with the why field left out of the checked tuple, --census and --census --why both:

wave64_graphics_why: null -> TypeError: 'NoneType' object is not iterable   (tools/wave64_halves.py:1673)
wave64_graphics_why: 7    -> TypeError: 'int' object is not iterable        (tools/wave64_halves.py:1673)

exit 1 with a traceback. A plain string or a dict raised nothing: it iterates into characters or keys, no piece has the 4 pipes a why line needs, and the why counts come out silently short. After the commit both modes answer one line, exit 2:

ERROR: index.json: wave64_graphics_why is NoneType, expected a list of strings

The field is checked for every counted entry, not only tier C, so --census and --census --why refuse the same index. An index rdna2spirv.py --wave64-why actually wrote is unaffected, there the field is a non-empty list of strings, which is what test_a_valid_why_field_still_censuses pins. Kev-Ball's corpus run on #4686 found all 8,245 tier C entries well formed, so this is the malformed input convention #1651 set rather than something the real index hits.

Tests: 5 cases added to test_a_bad_census_entry_field_is_one_line_not_a_traceback, plus the valid field test. tests/test_wave64_halves_fixtures.py 11 passed on this branch, 23 passed merged with #4686's tests/semantic/test_wave64_halves_why.py. compileall clean, scripts/check_no_game_data.py rc=0, synthetic fixtures only.

main is at 3faac557 now (rdna2spirv bounds branch); it touches neither file here and git merge-tree against it is clean, so I left the base as is. Claim: #4816 (comment). AI-assisted.

@KkelebekK

Copy link
Copy Markdown

Tested 1a144957 (merge-base d974c88a; git merge-tree against current main 3faac557 is clean) on AMD Radeon 780M (RADV PHOENIX, Mesa 26.2.6, gfx1103) and NVIDIA RTX 4070 Laptop (620.70.06), CachyOS Linux 7.3.4, Python 3.14.10, llvm-mc 23.1.4, SPIRV-Tools v2026.4: pass.

This PR changes no C++ and no shader, so the test programs were built from main af70fc78 (the only runtime/ delta to main 3faac557 is the xgameruntime shims). The GPU part is a no-regression check only.

  • python -I -m pytest -q tests/test_wave64_halves_fixtures.py: 11 passed, 0 skipped (the llvm-mc/SPIR-V fixture test ran).
  • Same test file on the merge-base tool (d974c88a): test_a_bad_census_entry_field_is_one_line_not_a_traceback fails with TypeError: unhashable type: 'list' at tools/wave64_halves.py:1527; the other 10 pass.
  • python -I -m unittest discover -s tests/semantic -p "test_wave64_halves*.py": 131 tests OK.
  • --census CLI on hand-made indexes (one valid entry plus one bad entry), PR vs merge-base:
    • wave64_graphics a list: PR exit 2, 1 stderr line; base exit 1, 10-line traceback. Same for an int tier.
    • wave64_graphics_reasons null, ["valid", null]; wave64_graphics_idioms a dict; wave64_graphics_why int or null: PR exit 2, 1 line naming the field, nothing on stdout. Base exit 0 and counts silently (a null reasons is now an error, where the base accepted it).
    • A valid wave64_graphics_why list: exit 0 on both.
    • On a real index (243 synthetic fixtures translated from runtime/test/shaders) the census output is byte-identical to the base (A 10 / B 7 / C 14).
  • Note: on this base wave64_graphics_why is neither written by rdna2spirv.py nor read by --census; the check anticipates wave64_halves: --census --why counts where the tier C reasons come from (new SHADER item) #4686 and costs nothing until then.
  • scripts/run_gpu_tests.py (full suite, 217 tests), per-test status identical to main 3faac557 on all three configurations, 0 FAIL:
Configuration Result
780M, plain (native wave64) 202/217 passed, 15 skipped
RTX 4070, plain 170/217 passed, 47 skipped
RTX 4070, LEONIDA_W64_EMULATE=1 201/217 passed, 16 skipped

Synthetic inputs only, no game data. AI-assisted.

@kapitche

Copy link
Copy Markdown
Contributor

Tested 1a14495 merged with main 3faac55 (merge result 9462718) on Linux (WSL2 Ubuntu 22.04) / Python 3.12.16, -I -m pytest (the file imports conftest, so it is a pytest file): pass.

  • tests/test_wave64_halves_fixtures.py: 11 collected, 10 passed, 1 skipped, 0 failed. The skip is the llvm-mc/amdgcn + spirv-as/spirv-val fixture test (none on this Linux box); the two new tests are pure Python and ran.
  • Negative control: tools/wave64_halves.py from main with the PR's tests: test_a_bad_census_entry_field_is_one_line_not_a_traceback fails with TypeError: unhashable type: 'list' (1 failed, 9 passed, 1 skipped). With the PR's file, all pass.
  • Read the full diff: the guard covers a non-string tier, and a non-list or non-string-item wave64_graphics_reasons/_idioms/_why, as one ERROR: line and exit 2 without the shader name; a valid --wave64-why index still censuses (exit 0). I also tried entries with a list stage or a missing stage: those are not counted by the census (needs a wave64 VS/PS/GS tier), so no traceback.
  • Not run natively on Windows (pure Python, no platform-specific code); Windows runs by other reviewers are already on the thread.

@memorypressure

Copy link
Copy Markdown

Verified against current main (3faac55, merges cleanly): the new tests/test_wave64_halves_fixtures.py gives 11 passed under pytest (correctly refusing to run silently under python -I), and the closest existing coverage, tests/semantic/test_wave64_halves.py, passes 101 tests unchanged. The --census type guards and the single-error-line path read right. One flag: gh reports no CI checks on this branch — worth confirming CI triggered. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@Atomic258

Copy link
Copy Markdown
Contributor

Tested 1a14495 on Windows Server 2022, CPython 3.13.12: pass

  • pytest tests/test_wave64_halves_fixtures.py -> 10 passed, 1 skipped
  • Negative control (tools/wave64_halves.py swapped to upstream/main): 1 failed - differentiates

git diff --check clean; python -m compileall -q exit 0. No game files, no GPU. AI-assisted (Devin).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants