add(compiler): support early return in if/for bodies - #4
Merged
Conversation
odvcencio
force-pushed
the
fix/return-defects
branch
from
July 27, 2026 04:53
542b9ea to
d4a6812
Compare
- Allow `return` nested inside if/for bodies in surface() and feedback() (Phase 1); vertex() continues to reject early returns since assigned varyings would be undefined - Add hir.Return and ir.ReturnCF nodes; parser's subBlock appends a Return instead of erroring on a trailing return statement - Wire per-backend ReturnFn so void-returning entries (GLSL/GLES fragments, WGSL/Metal compute) write the output global then bare-return, while typed entries emit plain `return val;` - Retire the 'B2a limitation' wording with a descriptive diagnostic naming the unsupported control-flow shape for super.surface() parents - Extend collectGeoStmt and derivative detection to cover early returns so geo-only usages and dpdx-in-return still resolve correctly
odvcencio
force-pushed
the
feat/early-return
branch
from
July 27, 2026 04:58
26e012e to
4fc68c4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Enable
returnstatements insideifandforblocks in surface and feedback bodies, allowing conditional early exits from shaders. The parser accepts returns at any nesting depth, emitting a newReturnCFIR node, while backend emitters use a pluggableReturnFnto handle void-returning entry functions (GLSL/GLES fragment shaders, feedback compute kernels). Vertex bodies retain the restriction to prevent undefined varying assignments.Changes
hir.Returnstatements instead of rejecting them; retain the block-level guard that nothing may follow a return.hir.Returnandir.ReturnCFtypes to carry early-exit values through lowering and emission.super.surfaceinlining diagnostics to reference control flow instead of the retired B2a label.Resolver.ReturnFnto the emitter; GLSL/GLES write the output global (gl_FragColor/fragColor) beforereturn;, and feedback kernels writeoutState[cellIndex]before returning.