Fix nested def in @triton.jit to raise intended UnsupportedLanguageConstruct#10004
Open
swjng wants to merge 3 commits intotriton-lang:mainfrom
Open
Fix nested def in @triton.jit to raise intended UnsupportedLanguageConstruct#10004swjng wants to merge 3 commits intotriton-lang:mainfrom
def in @triton.jit to raise intended UnsupportedLanguageConstruct#10004swjng wants to merge 3 commits intotriton-lang:mainfrom
Conversation
UnsupportedLanguageConstruct for nested def inside @triton.jit
b0f6a01 to
6cef83e
Compare
UnsupportedLanguageConstruct for nested def inside @triton.jitStopIteration with UnsupportedLanguageConstruct for nested def in @triton.jit
StopIteration with UnsupportedLanguageConstruct for nested def in @triton.jitdef in @triton.jit to raise intended UnsupportedLanguageConstruct
peterbell10
approved these changes
Apr 13, 2026
Defining a nested function inside a @triton.jit kernel previously
produced an opaque error message:
CompilationError: StopIteration()
Root cause: visit_FunctionDef called visit(node.args) before checking
`if self.fn:`. For a nested def, visit_arg calls
next(p for p in self.jit_fn.params if p.name == node.arg)
which raises StopIteration because the nested function's parameters
are not in the outer JIT function's param list. The visitor's generic
exception handler then wrapped StopIteration as a CompilationError
with an uninformative message.
Fix: move the `if self.fn:` guard before visit(node.args) so that
UnsupportedLanguageConstruct is raised immediately with a message
that tells the user to move helper functions to module level.
Nested def was already an unsupported construct; this change only
improves the error message surfaced to users.
bcb512e to
832544e
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.
New contributor declaration
I am not making a trivial change, such as fixing a typo in a comment.
I have written a PR description following these rules.
I have run
pre-commit run --from-ref origin/main --to-ref HEAD.Select one of the following.
/python/testfor end-to-end testsSelect one of the following.
littests.Problem
Defining a nested function inside a
@triton.jitkernel surfaces an opaque error:Before this change:
The message
StopIteration()gives the user no indication of what went wrong.Root cause
visit_FunctionDefincode_generator.pycalledself.visit(node.args)before checkingif self.fn:. For a nested def,visit_argcallswhich raises
StopIterationbecause the nested function's parameters are not in the outer JIT function's param list. The visitor's generic exception handler then wrapsStopIterationas aCompilationErrorwith the barerepras its message.Fix
Move the
if self.fn:guard beforeself.visit(node.args)so thatUnsupportedLanguageConstructis raised immediately with a message directing the user to move helper functions to module level.Nested
defwas already an unsupported construct (the guard existed, just in the wrong order). This change only improves the error message.Test
test_err_nested_function_definpython/test/unit/language/test_compile_errors.py:StopIterationdoes not appear in the error messagenested function