Fix a JET error regarding the existence of the local variable reducer at a certain point#169
Merged
DilumAluthge merged 3 commits intomasterfrom Feb 21, 2026
Conversation
…r` at a certain point ``` ┌ var"@distributed"(__source__::LineNumberNode, __module__::Module, args::Vararg{Any}) @ Distributed /workpath/Distributed.jl/src/macros.jl:363 │ local variable `reducer` may be undefined: reducer::Any └──────────────────── ``` By the time we get to this location in the code, we know that the local variable `reducer` exists, by the following reasoning. If the number of arguments is 1, then we have already returned before this point. If the number of arguments is neither 1 nor 2, then we have already thrown an exception by this point. Thus, if we reach this line, the number of arguments must be 2. Since the number of arguments is 2, we know that we executed the `reducer = args[1]` line above, which means that `reducer` is defined. (cherry picked from commit cdb1106)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #169 +/- ##
==========================================
+ Coverage 79.45% 79.46% +0.01%
==========================================
Files 10 10
Lines 1957 1958 +1
==========================================
+ Hits 1555 1556 +1
Misses 402 402 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
JamesWrigley
requested changes
Feb 20, 2026
src/macros.jl
Outdated
| ref | ||
| end | ||
| else | ||
| @assert @isdefined reducer # Fixes a JET warning |
Member
There was a problem hiding this comment.
Nitpicking, I dislike this kind of control-flow where variables are only sometimes created. I would prefer initializing reducer to e.g. identity and removing the assert.
Member
Author
There was a problem hiding this comment.
Alright, we now initialize reducer = identity in the na == 1 branch.
And I manually confirmed that this still fixes the JET error.
DilumAluthge
added a commit
to JuliaParallel/DistributedNext.jl
that referenced
this pull request
Feb 22, 2026
…r` at a certain point (#169) This is a forward-port of JuliaLang/Distributed.jl#169 (JuliaLang/Distributed.jl@1bc91f9). ``` ┌ var"@distributed"(__source__::LineNumberNode, __module__::Module, args::Vararg{Any}) @ Distributed /workpath/Distributed.jl/src/macros.jl:363 │ local variable `reducer` may be undefined: reducer::Any └──────────────────── ``` (cherry picked from commit 1bc91f97a75c1ac321ed28dfca072cbabfad7b4c)
64 tasks
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.
In the
na == 1branch, we just definereducer = identity.Old PR description:
By the time we get to this location in the code, we know that the local variablereducerexists, by the following reasoning. If the number of arguments is 1, then we have already returned before this point. If the number of arguments is neither 1 nor 2, then we have already thrown an exception by this point. Thus, if we reach this line, the number of arguments must be 2. Since the number of arguments is 2, we know that we executed thereducer = args[1]line above, which means thatreduceris defined.