Skip to content

Fix a JET error regarding the existence of the local variable reducer at a certain point#169

Merged
DilumAluthge merged 3 commits intomasterfrom
dpa/cherrypick-jet-reducer-local-var-is-defined
Feb 21, 2026
Merged

Fix a JET error regarding the existence of the local variable reducer at a certain point#169
DilumAluthge merged 3 commits intomasterfrom
dpa/cherrypick-jet-reducer-local-var-is-defined

Conversation

@DilumAluthge
Copy link
Copy Markdown
Member

@DilumAluthge DilumAluthge commented Feb 12, 2026

┌ 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
└────────────────────

In the na == 1 branch, we just define reducer = identity.


Old PR description: 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.

…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
Copy link
Copy Markdown

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.46%. Comparing base (d06aa73) to head (3087e07).
⚠️ Report is 2 commits behind head on master.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

src/macros.jl Outdated
ref
end
else
@assert @isdefined reducer # Fixes a JET warning
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alright, we now initialize reducer = identity in the na == 1 branch.

And I manually confirmed that this still fixes the JET error.

Copy link
Copy Markdown
Member

@JamesWrigley JamesWrigley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@DilumAluthge DilumAluthge merged commit 1bc91f9 into master Feb 21, 2026
8 checks passed
@DilumAluthge DilumAluthge deleted the dpa/cherrypick-jet-reducer-local-var-is-defined branch February 21, 2026 08:19
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants