[PR #6339] [MERGED] Shader packs: a parameter or local named like a bool uniform hides it #6810

Closed
opened 2026-11-03 06:27:20 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6339
Author: @Joansitoh
Created: 11/1/2026
Status: ✅ Merged
Merged: 11/1/2026
Merged by: @ludovic111

Base: main ← Head: fix/6241-bool-uniform-shadow


📝 Commits (6)

  • 5db3adb Shader packs: a parameter or local named like a bool uniform hides it
  • 7ebed75 Test the bool uniform read in main
  • be512ea Scope a hidden name to its block
  • db13dfa Hide a bool uniform behind for-header variables and second declarators; sharper tests
  • 93ce3a8 End a for-header variable's scope at an unbraced body's statement; stronger block test
  • 9696cd3 End a for body's hiding at a rewritten return/discard statement too

📊 Changes

2 files changed (+240 additions, -7 deletions)

View changed files

📝 crates/horizon-shaders/src/translate/mod.rs (+161 -0)
📝 crates/horizon-shaders/src/translate/rewrite.rs (+79 -7)

📄 Description

🤖 Opened by Joansitoh's AI agent (Claude Code, Sonnet 5.5), not by Joansitoh personally.

What

In the shader translator, every token naming a bool uniform became (hz_bool_<name> != 0), including a parameter, local or struct member of the same name (bool (hz_bool_hideGUI != 0)), which naga rejects. Now such a name hides the uniform, as GLSL scoping says.

rewrite.rs:

  • The sampler hiding (declaration detection, .member skip) also covers bool uniforms.
  • A hidden name is dropped at the } closing its block, so the uniform is back after an inner block.
  • A for header's variable (and second declarators in it) ends with the loop: its {} body, or the ; of a single-statement body.
  • Second declarators (bool a = 1, hideGUI = 0;) are recognised when the statement starts with a type and a name.
  • A depth-0 ; (a prototype) ends its parameters' scope, which also fixes the same leak for sampler parameters.

Known limitations: in an unbraced for body the hiding ends at the first ; (for (...) if (c) a; else b; unhides before else b; for (...) if (c) { ... } keeps it until the next ; at that depth). A comma operator that assigns (x = 1, hideGUI = 2; after a non-declaration start) is not treated as a declarator.

Vanilla reference

No Java oracle: GLSL 4.60 spec §4.2 (scoping) is the reference, as in the issue.

How tested

  • The issue's example verbatim: translates, naga parses it, f/h keep their hideGUI argument, f/g/h contain no uniform read (!= 0), hz_main does.
  • Struct member and v.hideGUI; uniform back after an inner block with a same-named local; for-header variable and second declarators (braced, unbraced and return bodies); sampler parameter reused as an inner-block local.
  • The uniform-reading tests fail without the fix.

pr_ready (--quick --base upstream/main): Scope 2 files +240 −7 ✅, Public tree ✅, Python tests 594 ✅, rustfmt ✅, clippy ✅, horizon-shaders 119 passed ✅, doc tests ✅.
No harness covers this directly (no oracle). Remaining affected harnesses: run by CI's parity job.

CONTRIBUTING.md and CLAUDE.md were followed. A separate read-only Sonnet 5.5 review of the final diff answered SIN DEFECTO.

Suggested label: none

Fixes #6241

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/6339 **Author:** [@Joansitoh](https://github.com/Joansitoh) **Created:** 11/1/2026 **Status:** ✅ Merged **Merged:** 11/1/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `fix/6241-bool-uniform-shadow` --- ### 📝 Commits (6) - [`5db3adb`](https://github.com/horizon-rust/horizon/commit/5db3adb4e52eec6d9b246c85f4224da465e90ab8) Shader packs: a parameter or local named like a bool uniform hides it - [`7ebed75`](https://github.com/horizon-rust/horizon/commit/7ebed75520d1cc259300f3203ebd61385abc1e32) Test the bool uniform read in main - [`be512ea`](https://github.com/horizon-rust/horizon/commit/be512ea4e9ab1888a59f1b3b696c0bfdcab3d4df) Scope a hidden name to its block - [`db13dfa`](https://github.com/horizon-rust/horizon/commit/db13dfa15c9f015ed4a3e539a2644193217566a5) Hide a bool uniform behind for-header variables and second declarators; sharper tests - [`93ce3a8`](https://github.com/horizon-rust/horizon/commit/93ce3a81a72f1c8da470871fe1db3c2564bb7c4c) End a for-header variable's scope at an unbraced body's statement; stronger block test - [`9696cd3`](https://github.com/horizon-rust/horizon/commit/9696cd39eab467ac2edad7b165bbb16d0f03a883) End a for body's hiding at a rewritten return/discard statement too ### 📊 Changes **2 files changed** (+240 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-shaders/src/translate/mod.rs` (+161 -0) 📝 `crates/horizon-shaders/src/translate/rewrite.rs` (+79 -7) </details> ### 📄 Description > 🤖 Opened by Joansitoh's AI agent (Claude Code, Sonnet 5.5), not by Joansitoh personally. ## What In the shader translator, every token naming a `bool` uniform became `(hz_bool_<name> != 0)`, including a parameter, local or struct member of the same name (`bool (hz_bool_hideGUI != 0)`), which naga rejects. Now such a name hides the uniform, as GLSL scoping says. `rewrite.rs`: - The sampler hiding (declaration detection, `.member` skip) also covers bool uniforms. - A hidden name is dropped at the `}` closing its block, so the uniform is back after an inner block. - A `for` header's variable (and second declarators in it) ends with the loop: its `{}` body, or the `;` of a single-statement body. - Second declarators (`bool a = 1, hideGUI = 0;`) are recognised when the statement starts with a type and a name. - A depth-0 `;` (a prototype) ends its parameters' scope, which also fixes the same leak for sampler parameters. Known limitations: in an unbraced `for` body the hiding ends at the first `;` (`for (...) if (c) a; else b;` unhides before `else b`; `for (...) if (c) { ... }` keeps it until the next `;` at that depth). A comma operator that assigns (`x = 1, hideGUI = 2;` after a non-declaration start) is not treated as a declarator. ## Vanilla reference No Java oracle: GLSL 4.60 spec §4.2 (scoping) is the reference, as in the issue. ## How tested - The issue's example verbatim: translates, naga parses it, `f`/`h` keep their `hideGUI` argument, `f`/`g`/`h` contain no uniform read (`!= 0`), `hz_main` does. - Struct member and `v.hideGUI`; uniform back after an inner block with a same-named local; `for`-header variable and second declarators (braced, unbraced and `return` bodies); sampler parameter reused as an inner-block local. - The uniform-reading tests fail without the fix. **pr_ready** (`--quick --base upstream/main`): Scope 2 files +240 −7 ✅, Public tree ✅, Python tests 594 ✅, rustfmt ✅, clippy ✅, horizon-shaders 119 passed ✅, doc tests ✅. No harness covers this directly (no oracle). Remaining affected harnesses: run by CI's parity job. CONTRIBUTING.md and CLAUDE.md were followed. A separate read-only Sonnet 5.5 review of the final diff answered SIN DEFECTO. Suggested label: none Fixes #6241 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-03 06:27:20 +07:00
Sign in to join this conversation.
No milestone
No project
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.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#6810
No description provided.