fix(tools): count function-try-block definitions in nid_names.py #811

Merged
ebosido444-ai merged 1 commit from upstream-pr/811 into main 2026-10-06 20:59:34 +00:00
ebosido444-ai commented 2026-10-06 06:02:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ebosido444-ai on 2026-10-06T06:02:02Z.


What

Accurate tooling prevents the duplicate-PR churn and reviewer time burn: a bad rename-ready label becomes a duplicate definition, which becomes another PR fixing the collision. tools/nid_names.py misses function-try-block definitions (name(args) try { ... }): its DEFINITION regex has no try clause. tools/progress.py gained one in fix(tools): count function-try-block exports in progress.py, but the sibling scanner was never updated. 26 implemented exports (mostly libSceVideoOut) are invisible to collect_real_names, so a validated NID suggestion whose name is one of those 26 is labelled rename-ready; renaming such a stub creates a duplicate definition. This aligns the regex with tools/progress.py. Measured before/after over core/libs: 3303 -> 3329 definitions recognized (26 recovered).

Recovered names: sceVideoOutRegisterBuffers2, sceVideoOutSubmitChangeBufferAttribute2, sceVideoOutUnregisterBuffers, sceVideoOutSubmitFlip, sceVideoOutAddFlipEvent, sceVideoOutAddVblankEvent, sceVideoOutAddPreVblankStartEvent, sceVideoOutAddOutputModeEvent, sceVideoOutDeleteFlipEvent, sceVideoOutDeleteVblankEvent, sceVideoOutDeletePreVblankStartEvent, sceVideoOutDeleteOutputModeEvent, sceVideoOutOpen, sceVideoOutClose, sceVideoOutAllowOutputResolutionWqhdDetection, sceVideoOutSetFlipRate, and 10 more in libSceVideoOut/libSceLibcInternal.

Tested

Windows 11, Python 3.14 (no build):

  • Scanned core/libs before/after: 3303 -> 3329 definitions recognized (26 recovered).
  • Assert check that collect_real_names() covers every definition shape tools/progress.py accepts, and that compute_nid matches the independent base64 encoder in core/libs/tests/run_exception_tests.py (5 known symbols): passes.
  • Full tools/nid_names.py --json against zecoxao/sce_symbols (159,034 rows): 115 unknown rows, 0 MISMATCH, 102 rename-ready. On today's tree no row flips status -- the bug is latent and bites as soon as a suggestion resolves to one of the 26 names above.

Exact reproducers (run at 96499c8; on main without the fix the count assert sees 0 recovered):

  1. Definition counts -- unique names, old noexcept-only pattern vs the fix:

    git checkout 96499c8
    python - <<'PYEOF'
    import re, sys
    sys.path.insert(0, 'tools')
    import nid_names
    from pathlib import Path
    OLD = re.compile(r"\bAPS5_VABI\s+(\w+)\s*([^;{])\s(?:noexcept\s*)?{")
    texts = [p.read_text(errors="replace") for p in sorted((nid_names.ROOT / "core" / "libs").rglob("*.cpp"))]
    old_u = {m for t in texts for m in OLD.findall(t)}
    new_u = {m for t in texts for m in nid_names.DEFINITION.findall(t)}
    print("unique definition names: %d -> %d (recovered %d)" % (len(old_u), len(new_u), len(new_u - old_u)))
    print("recovered sample:", sorted(new_u - old_u)[:8])
    assert len(new_u - old_u) == 26 and 'sceVideoOutOpen' in new_u - old_u
    print("assert exactly 26 function-try-block definitions recovered, incl. sceVideoOutOpen: yes")
    PYEOF

    unique definition names: 3303 -> 3329 (recovered 26)
    recovered sample: ['sceVideoOutAddFlipEvent', 'sceVideoOutAddOutputModeEvent', 'sceVideoOutAddPreVblankStartEvent', 'sceVideoOutAddVblankEvent', 'sceVideoOutAdjustColor', 'sceVideoOutAllowOutputResolutionWqhdDetection', 'sceVideoOutClose', 'sceVideoOutConfigureOutput']
    assert exactly 26 function-try-block definitions recovered, incl. sceVideoOutOpen: yes

  2. compute_nid vs the independent encoder in core/libs/tests/run_exception_tests.py (5 known symbols):

    python - <<'PYEOF'
    import base64, hashlib, sys
    sys.path.insert(0, 'tools')
    import nid_names
    def ref_nid(symbol):
    digest = hashlib.sha1(symbol.encode() + bytes.fromhex('518d64a635ded8c1e6b039b1c3e55230')).digest()
    return base64.b64encode(digest[:8][::-1]).decode().rstrip('=').replace('/', '-')
    syms = ['sceVideoOutOpen', 'sceVideoOutClose', 'sceVideoOutSubmitFlip', 'sceVideoOutAddFlipEvent', 'sceVideoOutSetFlipRate']
    assert all(nid_names.compute_nid(s) == ref_nid(s) for s in syms)
    print("assert compute_nid == run_exception_tests.nid for 5 known symbols: PASS 5/5")
    PYEOF

    assert compute_nid == run_exception_tests.nid for 5 known symbols: PASS 5/5

  3. Full --json run + status tally:

    python tools/nid_names.py --json > rows.json
    python - <<'PYEOF'
    import json, collections
    rows = json.load(open("rows.json"))["rows"]
    tally = collections.Counter(r["status"] for r in rows)
    assert len(rows) == 115 and tally["MISMATCH"] == 0 and tally["rename-ready"] == 102
    print("rows: %d, statuses: %s, db_entries: %d" % (len(rows), dict(tally), json.load(open("rows.json"))["db_entries"]))
    PYEOF

    rows: 115, statuses: {'rename-ready': 102, 'unknown': 12, 'already-implemented': 1}, db_entries: 159034

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 (n/a, tooling)
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (n/a)
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

The DEFINITION regex is now duplicated in tools/progress.py and tools/nid_names.py (the drift that caused this). Happy to extract a shared constant if you want that hardened -- separate PR.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4754800909 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/811). Originally posted by [ebosido444-ai](https://github.com/ebosido444-ai) on 2026-10-06T06:02:02Z. --- ### What Accurate tooling prevents the duplicate-PR churn and reviewer time burn: a bad `rename-ready` label becomes a duplicate definition, which becomes another PR fixing the collision. `tools/nid_names.py` misses function-try-block definitions (`name(args) try { ... }`): its `DEFINITION` regex has no `try` clause. `tools/progress.py` gained one in `fix(tools): count function-try-block exports in progress.py`, but the sibling scanner was never updated. 26 implemented exports (mostly libSceVideoOut) are invisible to `collect_real_names`, so a validated NID suggestion whose name is one of those 26 is labelled `rename-ready`; renaming such a stub creates a duplicate definition. This aligns the regex with `tools/progress.py`. Measured before/after over `core/libs`: 3303 -> 3329 definitions recognized (26 recovered). Recovered names: `sceVideoOutRegisterBuffers2`, `sceVideoOutSubmitChangeBufferAttribute2`, `sceVideoOutUnregisterBuffers`, `sceVideoOutSubmitFlip`, `sceVideoOutAddFlipEvent`, `sceVideoOutAddVblankEvent`, `sceVideoOutAddPreVblankStartEvent`, `sceVideoOutAddOutputModeEvent`, `sceVideoOutDeleteFlipEvent`, `sceVideoOutDeleteVblankEvent`, `sceVideoOutDeletePreVblankStartEvent`, `sceVideoOutDeleteOutputModeEvent`, `sceVideoOutOpen`, `sceVideoOutClose`, `sceVideoOutAllowOutputResolutionWqhdDetection`, `sceVideoOutSetFlipRate`, and 10 more in libSceVideoOut/libSceLibcInternal. ### Tested Windows 11, Python 3.14 (no build): - Scanned `core/libs` before/after: 3303 -> 3329 definitions recognized (26 recovered). - Assert check that `collect_real_names()` covers every definition shape `tools/progress.py` accepts, and that `compute_nid` matches the independent base64 encoder in `core/libs/tests/run_exception_tests.py` (5 known symbols): passes. - Full `tools/nid_names.py --json` against zecoxao/sce_symbols (159,034 rows): 115 unknown rows, 0 MISMATCH, 102 rename-ready. On today's tree no row flips status -- the bug is latent and bites as soon as a suggestion resolves to one of the 26 names above. Exact reproducers (run at `96499c8`; on `main` without the fix the count assert sees 0 recovered): 1. Definition counts -- unique names, old `noexcept`-only pattern vs the fix: git checkout 96499c8 python - <<'PYEOF' import re, sys sys.path.insert(0, 'tools') import nid_names from pathlib import Path OLD = re.compile(r"\bAPS5_VABI\s+(\w+)\s*\([^;{]*\)\s*(?:noexcept\s*)?\{") texts = [p.read_text(errors="replace") for p in sorted((nid_names.ROOT / "core" / "libs").rglob("*.cpp"))] old_u = {m for t in texts for m in OLD.findall(t)} new_u = {m for t in texts for m in nid_names.DEFINITION.findall(t)} print("unique definition names: %d -> %d (recovered %d)" % (len(old_u), len(new_u), len(new_u - old_u))) print("recovered sample:", sorted(new_u - old_u)[:8]) assert len(new_u - old_u) == 26 and 'sceVideoOutOpen' in new_u - old_u print("assert exactly 26 function-try-block definitions recovered, incl. sceVideoOutOpen: yes") PYEOF unique definition names: 3303 -> 3329 (recovered 26) recovered sample: ['sceVideoOutAddFlipEvent', 'sceVideoOutAddOutputModeEvent', 'sceVideoOutAddPreVblankStartEvent', 'sceVideoOutAddVblankEvent', 'sceVideoOutAdjustColor', 'sceVideoOutAllowOutputResolutionWqhdDetection', 'sceVideoOutClose', 'sceVideoOutConfigureOutput'] assert exactly 26 function-try-block definitions recovered, incl. sceVideoOutOpen: yes 2. `compute_nid` vs the independent encoder in `core/libs/tests/run_exception_tests.py` (5 known symbols): python - <<'PYEOF' import base64, hashlib, sys sys.path.insert(0, 'tools') import nid_names def ref_nid(symbol): digest = hashlib.sha1(symbol.encode() + bytes.fromhex('518d64a635ded8c1e6b039b1c3e55230')).digest() return base64.b64encode(digest[:8][::-1]).decode().rstrip('=').replace('/', '-') syms = ['sceVideoOutOpen', 'sceVideoOutClose', 'sceVideoOutSubmitFlip', 'sceVideoOutAddFlipEvent', 'sceVideoOutSetFlipRate'] assert all(nid_names.compute_nid(s) == ref_nid(s) for s in syms) print("assert compute_nid == run_exception_tests.nid for 5 known symbols: PASS 5/5") PYEOF assert compute_nid == run_exception_tests.nid for 5 known symbols: PASS 5/5 3. Full `--json` run + status tally: python tools/nid_names.py --json > rows.json python - <<'PYEOF' import json, collections rows = json.load(open("rows.json"))["rows"] tally = collections.Counter(r["status"] for r in rows) assert len(rows) == 115 and tally["MISMATCH"] == 0 and tally["rename-ready"] == 102 print("rows: %d, statuses: %s, db_entries: %d" % (len(rows), dict(tally), json.load(open("rows.json"))["db_entries"])) PYEOF rows: 115, statuses: {'rename-ready': 102, 'unknown': 12, 'already-implemented': 1}, db_entries: 159034 ### Checklist - [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 - [x] Unimplemented paths throw (n/a, tooling) - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source (n/a) - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes The `DEFINITION` regex is now duplicated in `tools/progress.py` and `tools/nid_names.py` (the drift that caused this). Happy to extract a shared constant if you want that hardened -- separate PR.
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!811
No description provided.