Only inline bare GlobalRef statements on Julia 1.12+#139
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #139 +/- ##
=======================================
Coverage 74.09% 74.09%
=======================================
Files 15 15
Lines 1521 1521
=======================================
Hits 1127 1127
Misses 394 394 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The `GlobalRef` branch in `IR(::CodeInfo, ...)` inlines bare `GlobalRef` statements into their use sites. This was added to undo Julia 1.12's lowering change, which hoists a call's callee into its own statement (`%4 = Main.:*; %5 = (%4)(%2, %3)`), restoring the older IR shape (`%5 = %2 * %3`). The branch was unconditional, so it also fired on Julia 1.10/1.11, where lowering never produces a bare `GlobalRef` statement. There it has no business running on the IR coming straight from `code_lowered`, but downstream IR producers — notably Zygote's forward-mode dynamo — do emit bare `GlobalRef` statements, and folding those into their uses reshaped the IR enough to make the dynamo's recursion non-terminating, blowing the stack (Zygote's nested `pushforward` on Julia 1.10). Gate the branch behind `VERSION >= v"1.12.0-DEV.173"` (the same boundary already used for the 1.12 debug-info changes in this file) so pre-1.12 behaviour is unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
d25e89a to
4b8c062
Compare
CarloLucibello
added a commit
to FluxML/Zygote.jl
that referenced
this pull request
Jun 15, 2026
IRTools 0.4.16 inlined bare `GlobalRef` statements unconditionally, which broke Zygote's forward-mode dynamo on Julia 1.10/1.11 with a `StackOverflowError` in nested `pushforward`. Fixed in IRTools 0.4.17 (FluxML/IRTools.jl#139); require it. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
CarloLucibello
added a commit
to FluxML/Zygote.jl
that referenced
this pull request
Jun 15, 2026
IRTools 0.4.16 inlined bare `GlobalRef` statements unconditionally, which broke Zygote's forward-mode dynamo on Julia 1.10/1.11 with a `StackOverflowError` in nested `pushforward`. Fixed in IRTools 0.4.17 (FluxML/IRTools.jl#139); require it. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
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
The
GlobalRefbranch inIR(::CodeInfo, ...)(src/ir/wrap.jl) inlines bareGlobalRefstatements into their use sites. It was added in #134 to undo Julia 1.12's lowering change, which hoists a call's callee into its own statement:The branch was unconditional, so it also ran on Julia 1.10/1.11. There,
code_lowerednever produces a bareGlobalRefstatement — but downstream IR producers do. In particular Zygote's forward-mode dynamo emits bareGlobalRefstatements, and folding those into their uses reshapes the IR enough that the dynamo's recursion stops terminating, blowing the stack with aStackOverflowError.This surfaced as a CI failure in Zygote on Julia 1.10 after it bumped to IRTools 0.4.16 (FluxML/Zygote.jl#1638): nested forward-mode AD (
pushforwardofpushforward) recurses infinitely throughliteral_indexed_iterate.Fix
Gate the branch behind
VERSION >= v"1.12.0-DEV.173"— the same boundary already used for the 1.12 debug-info handling in this file — so pre-1.12 behaviour is exactly as it was before #134.Validation
StackOverflowErroron Julia 1.10 with registered IRTools 0.4.16; confirmed it disappears with this change while unrelated Zygote code is untouched.🤖 Generated with Claude Code