[PR #6821] [MERGED] Shader packs: a function reaching its end without a return returns zero #7113

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

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/6821
Author: @arslanarm
Created: 11/2/2026
Status: ✅ Merged
Merged: 11/2/2026
Merged by: @ludovic111

Base: main ← Head: shaderpacks/implicit-return-value


📝 Commits (1)

  • 3df1f09 Shader packs: a function reaching its end without a return returns zero

📊 Changes

1 file changed (+94 additions, -1 deletions)

View changed files

📝 crates/horizon-shaders/src/translate/mod.rs (+94 -1)

📄 Description

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

What and why

Fixes #6809.

GLSL lets a function that returns a value reach its closing brace without a return; the value it gives back then is undefined (GLSL 4.60, 6.1). naga's GLSL frontend ends every body that can reach its end with a return of no value (naga::proc::ensure_block_returns), and its validator then refuses the function ("The return expression None does not match the declared return type"), so the program was skipped.

compile now gives those end returns the result type's zero (Expression::ZeroValue) before validating, walking the same tail positions naga fills: the last statement of a block, both branches of a trailing if, the non-fall-through cases of a trailing switch. A function that ends in its own return is untouched.

Measured with real_packs over Modrinth's 40 most-downloaded shader packs (SHOW_ERRORS=1), against main at 3a264943c: composite-style programs 1500 ok / 54 failing → 1506 / 48. The six programs no longer skipped are Lux v1.3's composite5 and RedHat v34.3.1's composite, each in all three dimensions; no program that translated before fails now.

Overlap: item 2 of #6784 (opened earlier, by abit-foggy) fixes the same issue by adding return ty(0); at each non-void function's closing brace. Measured on the same 40 packs it recovers the same programs; it leaves a function returning a struct failing (after_struct in this pull request's test). I found the overlap after opening this one; noted in #6784's thread.

Test: functions_reaching_their_end_return_zero (a loop, an if without else, a switch without default, a struct result; it fails on main with the issue's error).

Kind

  • parity: Horizon now does what vanilla 26.3 does
  • bug: a crash or a breakage
  • perf: faster, or less memory
  • feature: something new for players (listed under New in the release notes)
  • extra: Horizon-only, off by default
  • tooling: tools, CI, tests, harnesses
  • docs

Vanilla reference

Horizon-only (shader packs; vanilla has no such feature). The rule followed is the GLSL 4.60 specification, 6.1; glslangValidator 1.4.363 accepts the issue's example.

Other projects' code

naga 30.0.1 (MIT OR Apache-2.0), https://docs.rs/crate/naga/30.0.1/source/: read src/proc/terminator.rs (ensure_block_returns) and src/front/glsl/functions.rs (add_function) to see where the frontend adds its return. Nothing copied. No Iris, OptiFine or pack code read; Lux and RedHat were only run as black boxes.

Self-check

pr_ready (tools/pr_ready.py --quick on plony-pc, against origin/main at 3a264943c, 2 min 32 s)

Check Result
Scope ✅ 1 files, +94 −1
Cargo.lock ✅ unchanged
Public tree ✅
Python tests ✅ 602 passed (31 s)
rustfmt ✅ (6 s)
clippy ✅ (1 min 52 s)
tests: horizon-shaders ✅ 124 passed (2 s)
doc tests ✅ 0 passed
content root tests ➖ content root untouched
mod API up to date ➖ native hooks untouched
tokens.css up to date ➖ theme untouched
launcher rustfmt ➖ launcher untouched
launcher clippy ➖ launcher untouched
launcher tests ➖ launcher untouched
Parity ➖ not run (--quick): CI's parity job picks the affected harnesses
Label player-facing: feature if players get something new, no label for a fix (release-now if urgent)

🤖 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/6821 **Author:** [@arslanarm](https://github.com/arslanarm) **Created:** 11/2/2026 **Status:** ✅ Merged **Merged:** 11/2/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `shaderpacks/implicit-return-value` --- ### 📝 Commits (1) - [`3df1f09`](https://github.com/horizon-rust/horizon/commit/3df1f09d3500b2e136280f8cb19129502006b03a) Shader packs: a function reaching its end without a return returns zero ### 📊 Changes **1 file changed** (+94 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-shaders/src/translate/mod.rs` (+94 -1) </details> ### 📄 Description > 🤖 Opened by arslanarm's AI agent (Claude Code, Claude Opus 5.5), not by arslanarm personally. ## What and why Fixes #6809. GLSL lets a function that returns a value reach its closing brace without a `return`; the value it gives back then is undefined (GLSL 4.60, 6.1). naga's GLSL frontend ends every body that can reach its end with a `return` of no value (`naga::proc::ensure_block_returns`), and its validator then refuses the function ("The `return` expression None does not match the declared return type"), so the program was skipped. `compile` now gives those end returns the result type's zero (`Expression::ZeroValue`) before validating, walking the same tail positions naga fills: the last statement of a block, both branches of a trailing `if`, the non-fall-through cases of a trailing `switch`. A function that ends in its own `return` is untouched. Measured with `real_packs` over Modrinth's 40 most-downloaded shader packs (`SHOW_ERRORS=1`), against main at 3a264943c: composite-style programs 1500 ok / 54 failing → 1506 / 48. The six programs no longer skipped are Lux v1.3's `composite5` and RedHat v34.3.1's `composite`, each in all three dimensions; no program that translated before fails now. **Overlap:** item 2 of #6784 (opened earlier, by abit-foggy) fixes the same issue by adding `return ty(0);` at each non-void function's closing brace. Measured on the same 40 packs it recovers the same programs; it leaves a function returning a struct failing (`after_struct` in this pull request's test). I found the overlap after opening this one; noted in #6784's thread. Test: `functions_reaching_their_end_return_zero` (a loop, an `if` without `else`, a `switch` without `default`, a struct result; it fails on main with the issue's error). ## Kind - [ ] parity: Horizon now does what vanilla 26.3 does - [x] bug: a crash or a breakage - [ ] perf: faster, or less memory - [ ] feature: something new for players (listed under New in the release notes) - [ ] extra: Horizon-only, off by default - [ ] tooling: tools, CI, tests, harnesses - [ ] docs ## Vanilla reference Horizon-only (shader packs; vanilla has no such feature). The rule followed is the GLSL 4.60 specification, 6.1; `glslangValidator` 1.4.363 accepts the issue's example. ## Other projects' code naga 30.0.1 (MIT OR Apache-2.0), https://docs.rs/crate/naga/30.0.1/source/: read `src/proc/terminator.rs` (`ensure_block_returns`) and `src/front/glsl/functions.rs` (`add_function`) to see where the frontend adds its return. Nothing copied. No Iris, OptiFine or pack code read; Lux and RedHat were only run as black boxes. ## Self-check **pr_ready** (`tools/pr_ready.py --quick` on plony-pc, against origin/main at 3a264943c, 2 min 32 s) | Check | Result | | --- | --- | | Scope | ✅ 1 files, +94 −1 | | Cargo.lock | ✅ unchanged | | Public tree | ✅ | | Python tests | ✅ 602 passed (31 s) | | rustfmt | ✅ (6 s) | | clippy | ✅ (1 min 52 s) | | tests: horizon-shaders | ✅ 124 passed (2 s) | | doc tests | ✅ 0 passed | | content root tests | ➖ content root untouched | | mod API up to date | ➖ native hooks untouched | | tokens.css up to date | ➖ theme untouched | | launcher rustfmt | ➖ launcher untouched | | launcher clippy | ➖ launcher untouched | | launcher tests | ➖ launcher untouched | | Parity | ➖ not run (--quick): CI's parity job picks the affected harnesses | | Label | player-facing: `feature` if players get something new, no label for a fix (`release-now` if urgent) | 🤖 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:34:08 +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#7113
No description provided.