Skip to content

Only inline bare GlobalRef statements on Julia 1.12+#139

Merged
CarloLucibello merged 1 commit into
masterfrom
cl/guard-globalref-inline-1.12
Jun 15, 2026
Merged

Only inline bare GlobalRef statements on Julia 1.12+#139
CarloLucibello merged 1 commit into
masterfrom
cl/guard-globalref-inline-1.12

Conversation

@CarloLucibello

Copy link
Copy Markdown
Member

Summary

The GlobalRef branch in IR(::CodeInfo, ...) (src/ir/wrap.jl) inlines bare GlobalRef statements 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:

# Julia 1.12 lowers `a * b` to:
%1 = Main.:*
%2 = (%1)(_2, _3)
# IRTools folds it back to the pre-1.12 shape:
%2 = _2 * _3

The branch was unconditional, so it also ran on Julia 1.10/1.11. There, code_lowered never produces a bare GlobalRef statement — but downstream IR producers do. In particular Zygote's forward-mode dynamo emits bare GlobalRef statements, and folding those into their uses reshapes the IR enough that the dynamo's recursion stops terminating, blowing the stack with a StackOverflowError.

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 (pushforward of pushforward) recurses infinitely through literal_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

  • Reproduced the Zygote StackOverflowError on Julia 1.10 with registered IRTools 0.4.16; confirmed it disappears with this change while unrelated Zygote code is untouched.
  • IRTools test suite passes on Julia 1.10 and 1.12.
  • Zygote forward-mode tests + full Zygote suite pass on Julia 1.10 and 1.12 against this branch.
  • Verified empirically that Julia 1.12 hoists callees (so the branch is still needed there) and Julia 1.10 does not (so it must not fire).

🤖 Generated with Claude Code

@codecov

codecov Bot commented Jun 15, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 74.09%. Comparing base (6675b01) to head (4b8c062).

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.
📢 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.

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>
@CarloLucibello CarloLucibello force-pushed the cl/guard-globalref-inline-1.12 branch from d25e89a to 4b8c062 Compare June 15, 2026 14:52
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 CarloLucibello merged commit c8174be into master Jun 15, 2026
7 of 10 checks passed
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>
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.

1 participant