Repository navigation
Conversation
8ccbcd8 to
f7456d7
Compare
f7456d7 to
fe87cd4
Compare
Ready behind this PR: one guard that empties twenty-four of the entriesSince the list in this check only shrinks when a handler actually stops escaping, the natural follow-up is to fix a slice. The cheapest slice is the Measured on a branch stacked on this one ( with the fail-first control being "remove exactly that guard": and two-operand lowers unchanged: All 28 Why I am not opening it as a second PR yet
If the slice is not the one you would choose, the sweep is 40 lines and reruns in a second, so any group of the remaining 33 is a candidate — the AI-assisted. |
… handlers)
Nine handlers in `tools/startup/gfx2hlsl.py` index `ops[0]`/`ops[1]`/`ops[2]` without checking how many
operands they were given, and they answer a malformed instruction with `IndexError` instead of
`Unsupported`. The batch translator records that as `internal error` -- its own marker for a translator
defect, not a missing lowering -- and the single-shader path does not catch it at all.
Three guards, each in the one body that several handlers share, cover thirty-three handlers:
op_s_cmp_*_i32/u32, s_cmpk_*_i32/u32 one factory, 24 handlers len(ops) != 2
s_and/or/andn2_saveexec_b32/b64 one body, 5 handlers len(ops) != 2
s_andn2_wrexec_b32/b64 one body, 2 handlers len(ops) != 2
s_cselect_b32/b64 scalar_select, 2 handlers len(ops) != 3
Measured with the sweep that no decoder output can produce (none, one to four VGPRs, a truncated register,
an attribute token):
before: 33 of the 33 escaped with IndexError
after: none escape; PENDING 57 -> 24
Two- and three-operand lowers are unchanged, checked directly rather than by reading the diff:
s_cmp_lt_u32 s0, s1 -> scc = s0 < s1;
s_and_saveexec_b32 s0, s1 -> s0 = exec; exec = (exec & s1) & 1; scc = exec != 0;
s_andn2_wrexec_b32 s2, s3 -> exec = (s3 & ~exec) & 1; scc = exec != 0; s2 = exec;
s_cselect_b32 s4,s5,s6 -> s4 = scc ? s5 : s6;
Fail-first, one control per guard -- remove exactly that guard and the ratchet names exactly the handlers
that share the body:
saveexec guard exit 1 named 5: s_and_saveexec_b32, s_and_saveexec_b64, s_andn2_saveexec_b64,
s_or_saveexec_b32, s_or_saveexec_b64
wrexec guard exit 1 named 2: s_andn2_wrexec_b32, s_andn2_wrexec_b64
cselect guard exit 1 named 2: s_cselect_b32, s_cselect_b64
restored exit 0 78 handlers, 24 pending
All 28 `tests/startup_gfx2hlsl_*_check.py` exit 0.
This is a follow-up to R0Y00#2063, which introduces `tests/startup_gfx2hlsl_handler_arity_check.py`; the branch
is based on it so the list edit sits next to the guards that empty those entries.
Update: the slice is now thirty-three handlers, in three guardsBoth PRs are green here, so I extended the branch that is waiting behind this one. Instead of only Measured on One control per guard, removing exactly that guard: Valid forms unchanged, checked directly: All 28 Still waiting on this PR rather than racing it: AI-assisted. |
…med operands
Every `Stage.op_*` handler is fed operand shapes the decoder cannot produce: none, one to four plain VGPRs,
a truncated register and an attribute token. A handler must answer each one with `Unsupported`, because that
is the only exception the translator treats as a refusal:
* `Stage.translate` records `Unsupported` as a refusal and any other exception as `handler_error(...)`,
which labels the entry `internal error` -- the project's marker for a translator defect, not a missing
lowering, so R0Y00#1723's census counts it as a gap it cannot act on;
* with `refusals is None` (single-shader translation) nothing is caught at all, so the same input exits
with a traceback instead of a refusal line.
On main the sweep finds 260 escapes across 57 of 76 handlers:
IndexError: 236 TypeError: 24
IndexError buffer_load_dword (no operands)
IndexError image_load v0 / v0 v1 / v0 v1 v2
TypeError s_bfm_b32 v[0 v1 'NoneType' object is not subscriptable
TypeError v_fma_mixhi_f16 not enough arguments for format string
These shapes cannot come from `decode_instruction`, so this is not a live decode bug; it is a robustness
invariant that was untested. Fixing all 57 handlers is not one reviewable change, so this pins the current
state instead: `PENDING` lists the handlers that do not hold the invariant today.
* a handler outside `PENDING` that starts escaping fails the check;
* an entry in `PENDING` that stops escaping also fails, with "remove it from PENDING";
* a `PENDING` entry that is not a handler fails, so a rename shows up here.
Verified with two controls against `tools/startup/gfx2hlsl.py`:
# a compliant handler starts indexing an operand without a length check
handler s_load_dword answers () with IndexError; it must raise Unsupported -> 1 failed
# a pending handler gains a length check
handler v_mov_b32 now refuses every shape; remove it from PENDING -> 1 failed
Command and result:
out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_handler_arity_check.py
startup gfx2hlsl handler arity checks: 76 handlers, 57 pending exit 0
Registered as `startup_gfx2hlsl_handler_arity` in CMakeLists.txt, added to the platform-independent run list
in `.github/workflows/windows.yml`, and listed in the AGENTS.md Pure-Python section so the documented list
stays in step (the twelve older omissions are R0Y00#2053's subject, not repeated here).
fe87cd4 to
b3a3951
Compare
… handlers)
Nine handlers in `tools/startup/gfx2hlsl.py` index `ops[0]`/`ops[1]`/`ops[2]` without checking how many
operands they were given, and they answer a malformed instruction with `IndexError` instead of
`Unsupported`. The batch translator records that as `internal error` -- its own marker for a translator
defect, not a missing lowering -- and the single-shader path does not catch it at all.
Three guards, each in the one body that several handlers share, cover thirty-three handlers:
op_s_cmp_*_i32/u32, s_cmpk_*_i32/u32 one factory, 24 handlers len(ops) != 2
s_and/or/andn2_saveexec_b32/b64 one body, 5 handlers len(ops) != 2
s_andn2_wrexec_b32/b64 one body, 2 handlers len(ops) != 2
s_cselect_b32/b64 scalar_select, 2 handlers len(ops) != 3
Measured with the sweep that no decoder output can produce (none, one to four VGPRs, a truncated register,
an attribute token):
before: 33 of the 33 escaped with IndexError
after: none escape; PENDING 57 -> 24
Two- and three-operand lowers are unchanged, checked directly rather than by reading the diff:
s_cmp_lt_u32 s0, s1 -> scc = s0 < s1;
s_and_saveexec_b32 s0, s1 -> s0 = exec; exec = (exec & s1) & 1; scc = exec != 0;
s_andn2_wrexec_b32 s2, s3 -> exec = (s3 & ~exec) & 1; scc = exec != 0; s2 = exec;
s_cselect_b32 s4,s5,s6 -> s4 = scc ? s5 : s6;
Fail-first, one control per guard -- remove exactly that guard and the ratchet names exactly the handlers
that share the body:
saveexec guard exit 1 named 5: s_and_saveexec_b32, s_and_saveexec_b64, s_andn2_saveexec_b64,
s_or_saveexec_b32, s_or_saveexec_b64
wrexec guard exit 1 named 2: s_andn2_wrexec_b32, s_andn2_wrexec_b64
cselect guard exit 1 named 2: s_cselect_b32, s_cselect_b64
restored exit 0 78 handlers, 24 pending
All 28 `tests/startup_gfx2hlsl_*_check.py` exit 0.
This is a follow-up to R0Y00#2063, which introduces `tests/startup_gfx2hlsl_handler_arity_check.py`; the branch
is based on it so the list edit sits next to the guards that empty those entries.
Superseded by #2104I opened #2104, which is this check together with the guards that empty 33 of its Nothing about this PR's content changes: Sorry for the duplicate in the queue — my fault for splitting it this way to begin with. AI-assisted. |
|
Closing this one myself: #2104 carries the same check verbatim except that its Verified rather than assumed: So nothing in this PR is lost. Keeping both in the queue asked a reviewer to compare two versions of the same file for no benefit, and the decision I offered What changed my mind about which to keep: #2092 has just merged, and it is the same shape as #2104 — a production change that ships its check. That is the If you would rather review the fixture alone first, closing this does not block that: the fixture is the first commit of #2104 and its behaviour is identical AI-assisted. |
… handlers)
Nine handlers in `tools/startup/gfx2hlsl.py` index `ops[0]`/`ops[1]`/`ops[2]` without checking how many
operands they were given, and they answer a malformed instruction with `IndexError` instead of
`Unsupported`. The batch translator records that as `internal error` -- its own marker for a translator
defect, not a missing lowering -- and the single-shader path does not catch it at all.
Three guards, each in the one body that several handlers share, cover thirty-three handlers:
op_s_cmp_*_i32/u32, s_cmpk_*_i32/u32 one factory, 24 handlers len(ops) != 2
s_and/or/andn2_saveexec_b32/b64 one body, 5 handlers len(ops) != 2
s_andn2_wrexec_b32/b64 one body, 2 handlers len(ops) != 2
s_cselect_b32/b64 scalar_select, 2 handlers len(ops) != 3
Measured with the sweep that no decoder output can produce (none, one to four VGPRs, a truncated register,
an attribute token):
before: 33 of the 33 escaped with IndexError
after: none escape; PENDING 57 -> 24
Two- and three-operand lowers are unchanged, checked directly rather than by reading the diff:
s_cmp_lt_u32 s0, s1 -> scc = s0 < s1;
s_and_saveexec_b32 s0, s1 -> s0 = exec; exec = (exec & s1) & 1; scc = exec != 0;
s_andn2_wrexec_b32 s2, s3 -> exec = (s3 & ~exec) & 1; scc = exec != 0; s2 = exec;
s_cselect_b32 s4,s5,s6 -> s4 = scc ? s5 : s6;
Fail-first, one control per guard -- remove exactly that guard and the ratchet names exactly the handlers
that share the body:
saveexec guard exit 1 named 5: s_and_saveexec_b32, s_and_saveexec_b64, s_andn2_saveexec_b64,
s_or_saveexec_b32, s_or_saveexec_b64
wrexec guard exit 1 named 2: s_andn2_wrexec_b32, s_andn2_wrexec_b64
cselect guard exit 1 named 2: s_cselect_b32, s_cselect_b64
restored exit 0 78 handlers, 24 pending
All 28 `tests/startup_gfx2hlsl_*_check.py` exit 0.
This is a follow-up to R0Y00#2063, which introduces `tests/startup_gfx2hlsl_handler_arity_check.py`; the branch
is based on it so the list edit sits next to the guards that empty those entries.
… handlers)
Nine handlers in `tools/startup/gfx2hlsl.py` index `ops[0]`/`ops[1]`/`ops[2]` without checking how many
operands they were given, and they answer a malformed instruction with `IndexError` instead of
`Unsupported`. The batch translator records that as `internal error` -- its own marker for a translator
defect, not a missing lowering -- and the single-shader path does not catch it at all.
Three guards, each in the one body that several handlers share, cover thirty-three handlers:
op_s_cmp_*_i32/u32, s_cmpk_*_i32/u32 one factory, 24 handlers len(ops) != 2
s_and/or/andn2_saveexec_b32/b64 one body, 5 handlers len(ops) != 2
s_andn2_wrexec_b32/b64 one body, 2 handlers len(ops) != 2
s_cselect_b32/b64 scalar_select, 2 handlers len(ops) != 3
Measured with the sweep that no decoder output can produce (none, one to four VGPRs, a truncated register,
an attribute token):
before: 33 of the 33 escaped with IndexError
after: none escape; PENDING 57 -> 24
Two- and three-operand lowers are unchanged, checked directly rather than by reading the diff:
s_cmp_lt_u32 s0, s1 -> scc = s0 < s1;
s_and_saveexec_b32 s0, s1 -> s0 = exec; exec = (exec & s1) & 1; scc = exec != 0;
s_andn2_wrexec_b32 s2, s3 -> exec = (s3 & ~exec) & 1; scc = exec != 0; s2 = exec;
s_cselect_b32 s4,s5,s6 -> s4 = scc ? s5 : s6;
Fail-first, one control per guard -- remove exactly that guard and the ratchet names exactly the handlers
that share the body:
saveexec guard exit 1 named 5: s_and_saveexec_b32, s_and_saveexec_b64, s_andn2_saveexec_b64,
s_or_saveexec_b32, s_or_saveexec_b64
wrexec guard exit 1 named 2: s_andn2_wrexec_b32, s_andn2_wrexec_b64
cselect guard exit 1 named 2: s_cselect_b32, s_cselect_b64
restored exit 0 78 handlers, 24 pending
All 28 `tests/startup_gfx2hlsl_*_check.py` exit 0.
This is a follow-up to R0Y00#2063, which introduces `tests/startup_gfx2hlsl_handler_arity_check.py`; the branch
is based on it so the list edit sits next to the guards that empty those entries.
What
A ratchet check for an invariant that was untested: every
Stage.op_*handler must answer malformed operand shapes withUnsupported, never anything else.Why it matters, in this repository's own terms:
Stage.translaterecordsUnsupportedas a refusal and any other exception ashandler_error(...), labelledinternal error— the marker for a translator defect.#1723's census reads those as gaps it cannot act on.refusals is None(single-shader translation) nothing is caught at all, so the same input exits with a traceback instead of a refusal line.Measured on
main76 handlers × 7 shapes (none, one to four VGPRs, a truncated register, an attribute token):
Reachability, stated plainly: these shapes cannot come from
decode_instruction, which always produces the operand form of the encoding. So this is not a live decode bug — it is robustness for the text entry point the unit fixtures use. Fixing all 57 handlers is not one reviewable change, so this PR pins the current state instead.The ratchet
Two controls, run by hand against
tools/startup/gfx2hlsl.py:Verification
Neighbours still green:
startup_gfx2hlsl_swap_check.py,startup_gfx2hlsl_mad_check.py,startup_gfx2hlsl_operand_count_check.py.Registered as
startup_gfx2hlsl_handler_arityinCMakeLists.txt, added to the platform-independent list in.github/workflows/windows.yml, and listed in the AGENTS.md section so the documented list stays in step — the twelve older omissions there are #2053's subject and are not repeated in this PR.Scope
Test only; no handler is changed. The 57 entries are the honest current state, and the list is meant to shrink.
Notes
Rebased after #2024, and the ratchet already earned its keep
mainadded two handlers while this PR was open (s_bitcmp0_b32,s_bitcmp1_b32from #2024). The rebase intoCMakeLists.txtwas a two-sidedaddition and both registrations are kept. Re-run after the rebase:
Both new handlers are already compliant, so the check passes without touching them — and if either had indexed an operand before checking its count,
it would have failed here rather than silently adding a 58th entry later. That is the behaviour this PR exists for.
Neighbours after the rebase:
startup_gfx2hlsl_s_bitcmp_check.py,startup_gfx2hlsl_swap_check.py,startup_triage_run_check.py— all exit 0.