fix(hw-oracle): read the template and write the assembly source as UTF-8 #12084

Merged
legendary-cookie merged 1 commit from upstream-pr/12084 into main 2026-10-28 09:47:05 +00:00
legendary-cookie commented 2026-10-27 19:47:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by legendary-cookie on 2026-10-27T19:47:50Z.


What

assemble() in tools/hw-oracle/hw_oracle.py read template.s and wrote k.s with the locale encoding, while main() reads the body file as UTF-8 and the HIP path encodes the assembled text as UTF-8. On Windows (cp1252 locale, HIP runtime by default) a body containing a character cp1252 cannot encode, such as → in a comment, stopped at write_text with a raw UnicodeEncodeError before assembling. Both now use UTF-8. template.s is ASCII, so reading it is unchanged.

Tested

  • Windows 11, Python 3.14, python tools/hw-oracle/test_hw_oracle.py: 47 tests OK (3 skipped: Windows LLVM has no AMDGPU target, two POSIX fixtures). The new SourceEncodingTests.test_assembly_source_is_utf8 fails on main with UnicodeEncodeError: 'charmap' codec can't encode character '→' and passes with the change.
  • Debian 13 (WSL), Python 3.13, clang/ld.lld 19.1.7: 47 tests OK (1 skipped: Windows driver comgr), including AssemblyTests. k.s files written on Windows by this change, with → and é in a body comment, assemble and link with -mcpu=gfx1030.
  • Hardware, Windows 11, HIP runtime, AMD Radeon Graphics (gfx1036, driver 32.0.21045.5002): hw_oracle.py with body v_add_f32 v10, v4, v5 ; v4 + v5 → v10 and rows 1.0 2.0, 3.0 0.5 prints 40400000, 40600000, the same as an ASCII-only body on main; the same body on main stops with the UnicodeEncodeError.
  • tools/check_conventions.py --base origin/main passes; tools/pr_overlap.py reports no overlap.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5040120523 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12084). Originally posted by [legendary-cookie](https://github.com/legendary-cookie) on 2026-10-27T19:47:50Z. --- ### What `assemble()` in `tools/hw-oracle/hw_oracle.py` read `template.s` and wrote `k.s` with the locale encoding, while `main()` reads the body file as UTF-8 and the HIP path encodes the assembled text as UTF-8. On Windows (cp1252 locale, HIP runtime by default) a body containing a character cp1252 cannot encode, such as `→` in a comment, stopped at `write_text` with a raw `UnicodeEncodeError` before assembling. Both now use UTF-8. `template.s` is ASCII, so reading it is unchanged. ### Tested - Windows 11, Python 3.14, `python tools/hw-oracle/test_hw_oracle.py`: 47 tests OK (3 skipped: Windows LLVM has no AMDGPU target, two POSIX fixtures). The new `SourceEncodingTests.test_assembly_source_is_utf8` fails on `main` with `UnicodeEncodeError: 'charmap' codec can't encode character '→'` and passes with the change. - Debian 13 (WSL), Python 3.13, clang/ld.lld 19.1.7: 47 tests OK (1 skipped: Windows driver comgr), including `AssemblyTests`. `k.s` files written on Windows by this change, with `→` and `é` in a body comment, assemble and link with `-mcpu=gfx1030`. - Hardware, Windows 11, HIP runtime, AMD Radeon Graphics (gfx1036, driver 32.0.21045.5002): `hw_oracle.py` with body `v_add_f32 v10, v4, v5 ; v4 + v5 → v10` and rows `1.0 2.0`, `3.0 0.5` prints `40400000`, `40600000`, the same as an ASCII-only body on `main`; the same body on `main` stops with the `UnicodeEncodeError`. - `tools/check_conventions.py --base origin/main` passes; `tools/pr_overlap.py` reports no overlap. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-27 19:49:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-27T19:49:05Z.

Review: APPROVED


Reviewed exact head 3a91f8ab8e15a3a168f58e1c7099a41c50fc53a9. Explicit UTF-8 for both template input and assembled-source output matches the rest of the tool's UTF-8 handling. The new regression uses non-ASCII text and verifies the emitted bytes decode as UTF-8. I independently ran the full tools/hw-oracle/test_hw_oracle.py suite from the exact PR files on Linux: 47 tests passed, 2 skipped because this host lacks an AMDGPU-capable clang and the Windows driver COMGR runtime. The author reports the full suite on Windows and Debian, plus a Windows HIP hardware check that reproduces the prior failure and matches the ASCII-only output.

Conventions, intake and labels pass. The hosted Windows build linked the changed host-only test executables but skipped the subsequent product build and CTest steps; the Windows unit and hardware results above are author-reported, not run by that CI job. No issue found in this focused fix.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5673332485 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12084#pullrequestreview-5673332485). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-27T19:49:05Z. **Review:** APPROVED --- Reviewed exact head `3a91f8ab8e15a3a168f58e1c7099a41c50fc53a9`. Explicit UTF-8 for both template input and assembled-source output matches the rest of the tool's UTF-8 handling. The new regression uses non-ASCII text and verifies the emitted bytes decode as UTF-8. I independently ran the full `tools/hw-oracle/test_hw_oracle.py` suite from the exact PR files on Linux: 47 tests passed, 2 skipped because this host lacks an AMDGPU-capable clang and the Windows driver COMGR runtime. The author reports the full suite on Windows and Debian, plus a Windows HIP hardware check that reproduces the prior failure and matches the ASCII-only output. Conventions, intake and labels pass. The hosted Windows build linked the changed host-only test executables but skipped the subsequent product build and CTest steps; the Windows unit and hardware results above are author-reported, not run by that CI job. No issue found in this focused fix.
rooklz commented 2026-10-28 05:17:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by rooklz on 2026-10-28T05:17:10Z.

Review: APPROVED


Checked head 3a91f8ab8e on macOS (no Windows needed): a non-UTF-8 locale reproduces the bug.

  • git merge-tree with main 16954551ed is clean. check_conventions.py --base upstream/main passes and pr_overlap.py reports no overlap.
  • With main's hw_oracle.py and this test, under LC_ALL=en_US.ISO8859-1 python3.13 -X utf8=0 (locale.getencoding() = ISO8859-1), only the new test fails: ERROR: test_assembly_source_is_utf8 ... UnicodeEncodeError: 'latin-1' codec can't encode character '\u2192'. 46 others pass.
  • Head under the same locale: 47 OK (3 skipped) on Python 3.13 and on 3.9.6. Head under a UTF-8 locale: 47 OK. So the test catches the bug whenever the locale can't encode the body, not only with Windows cp1252.
  • I looked for other text I/O in hw_oracle.py that depends on the locale. --rows/--body already use UTF-8. The one left is subprocess.run(..., text=True) at L93, which reads the --target output and is ASCII, so it's fine as it is.

Non-blocking: if you reverted only the template.s read, no test would catch it, because the template is ASCII. That's fine, as the PR body says.

LGTM.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5678091835 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/12084#pullrequestreview-5678091835). Originally posted by [rooklz](https://github.com/rooklz) on 2026-10-28T05:17:10Z. **Review:** APPROVED --- Checked head `3a91f8ab8e` on macOS (no Windows needed): a non-UTF-8 locale reproduces the bug. - `git merge-tree` with `main` `16954551ed` is clean. `check_conventions.py --base upstream/main` passes and `pr_overlap.py` reports no overlap. - With `main`'s `hw_oracle.py` and this test, under `LC_ALL=en_US.ISO8859-1 python3.13 -X utf8=0` (`locale.getencoding()` = `ISO8859-1`), only the new test fails: `ERROR: test_assembly_source_is_utf8 ... UnicodeEncodeError: 'latin-1' codec can't encode character '\u2192'`. 46 others pass. - Head under the same locale: 47 OK (3 skipped) on Python 3.13 and on 3.9.6. Head under a UTF-8 locale: 47 OK. So the test catches the bug whenever the locale can't encode the body, not only with Windows cp1252. - I looked for other text I/O in `hw_oracle.py` that depends on the locale. `--rows`/`--body` already use UTF-8. The one left is `subprocess.run(..., text=True)` at L93, which reads the `--target` output and is ASCII, so it's fine as it is. Non-blocking: if you reverted only the `template.s` read, no test would catch it, because the template is ASCII. That's fine, as the PR body says. LGTM. AI-assisted: yes
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
boykopovar/AnyPS5!12084
No description provided.