Skip to content

Adapt for julia 1.13#2818

Open
XLin0mu wants to merge 4 commits intoEnzymeAD:mainfrom
XLin0mu:main
Open

Adapt for julia 1.13#2818
XLin0mu wants to merge 4 commits intoEnzymeAD:mainfrom
XLin0mu:main

Conversation

@XLin0mu
Copy link
Copy Markdown

@XLin0mu XLin0mu commented Apr 17, 2026

Fixes #2817

@Antipath1
Copy link
Copy Markdown
Contributor

Can you add inside of the CI.yml to the version "~1.13.0-0" so the CI runs against the 1.13 Beta ?

Copy link
Copy Markdown
Contributor

@Antipath1 Antipath1 left a comment

Choose a reason for hiding this comment

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

Thank you so much for putting this PR together! I really appreciate you taking the time to address 1.13 compatibility while it's still in Beta.

I've left a couple of inline suggestions to make sure we don't accidentally break compatibility with older versions while fixing 1.13. Let me know if you have any questions about them.

@maintainers: Could someone please add a 1.13 label to this PR and like in general as there will probably be more problems with 1.13 in the future I would suspect?

Comment thread src/utils.jl
typeof(Base.StackTraces.show_spec_sig),
typeof(Core.throw_inexacterror),
typeof(Base.throw_boundserror),
typeof(Base._shrink),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I am confused what the reasoning for removing this line entirely is for shouldn't this be wrapped in an @static if Version < 1.13 block instead?

Comment thread src/utils.jl
typeof(Base.throw_boundserror),
typeof(Base._shrink),
@static(
if VERSION < v"1.13-"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
if VERSION < v"1.13-"
if v"1.11-" <= VERSION < v"1.13-"

Memoryref wass only introduced in 1.11 which causes the CI to fail on 1.10.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's a copy-pasted mistake, logic about Base.memoryref for 1.11 still exists in later context, thanks for remind!

@XLin0mu
Copy link
Copy Markdown
Author

XLin0mu commented May 2, 2026

For test/integration/random

Problem happend in:

# integration/random.jl: line 60-67
    fn2() = begin
        # TODO(#2253): MersenneTwister without seed leads to illegal instructions
        rng = MersenneTwister(0)
        x = zeros(Float64, 2, 3)
        Random.rand!(rng, x)
        return x
    end
    hlo = @code_hlo fn2()

Trace from test log:

Error in testset Random.jl Overlay:
Error During Test at /__w/Reactant.jl/Reactant.jl/test/integration/random.jl:5
  Got exception outside of a @test
  ArgumentError: cannot reinterpret `Reactant.TracedRNumber{UInt32}` as `UInt32`, type `Reactant.TracedRNumber{UInt32}` is not a bits type
  Stacktrace:
    [1] throwbits
      @ ./reinterpretarray.jl:16
    [2] call_with_reactant
      @ ./none:-1 [inlined]
    [3] call_with_reactant(::Reactant.EnsureReturnType{Union{}}, ::Base.var"#throwbits#throwbits##0", ::Type{Reactant.TracedRNumber{UInt32}}, ::Type{UInt32}, ::Type{Reactant.TracedRNumber{UInt32}})
      @ Reactant /__w/Reactant.jl/Reactant.jl/src/utils.jl:0
    [4] call_with_reactant
      @ ./none:-1 [inlined]
    [5] call_with_reactant(::Reactant.EnsureReturnType{Union{}}, ::typeof(reinterpret), ::Type{UInt32}, ::Reactant.TracedRArray{UInt32, 1})
      @ Reactant /__w/Reactant.jl/Reactant.jl/src/utils.jl:0
    [6] initstate!
      @ /__w/_tool/julia/1.13.0-beta3/x64/share/julia/stdlib/v1.13/Random/src/MersenneTwister.jl:250
    [7] call_with_reactant
      @ ./none:-1 [inlined]
    [8] call_with_reactant(::Reactant.EnsureReturnType{Union{}}, ::typeof(Random.initstate!), ::Random.MersenneTwister, ::Reactant.TracedRArray{UInt32, 1}, ::Int64)
      @ Reactant /__w/Reactant.jl/Reactant.jl/src/utils.jl:0
    [9] call_with_reactant
      @ ./none:-1 [inlined]
   [10] call_with_reactant(::Reactant.EnsureReturnType{Union{}}, ::typeof(Random.seed!), ::Random.MersenneTwister, ::Int64)
      @ Reactant /__w/Reactant.jl/Reactant.jl/src/utils.jl:0
   [11] MersenneTwister
      @ /__w/_tool/julia/1.13.0-beta3/x64/share/julia/stdlib/v1.13/Random/src/MersenneTwister.jl:75

Which directly casued by this change:

in julia 1.12:

# stdlib/Random/src/RNGs.jl: line 378
seed!(r::MersenneTwister, seed) = initstate!(r, hash_seed(seed), seed)

in julia 1.13:

# stdlib\Random\src\MersenneTwister.jl: line 265
seed!(r::MersenneTwister, seed) = initstate!(r, rand(SeedHasher(seed), UInt32, 8), seed)

This exception seems relative to implementation of Reactant and more changes in 1.13 stdlib/Random.

For test/integration/optimisers

Problem happend in:

# integration/optimisers.jl: line 16-28
@testset "Correct Aliasing" begin
    ps = Reactant.to_rarray((a=ones(4), b=ones(2), c=ones(4)))
    opt = Reactant.to_rarray(Descent(0.001f0); track_numbers=true)

    st_opt = @jit Optimisers.setup(opt, ps)

    @test st_opt.a.rule.eta.data === st_opt.b.rule.eta.data

    gs = Reactant.to_rarray((a=ones(4), b=ones(2), c=ones(4)))

    hlo = @code_hlo Optimisers.update(st_opt, ps, gs) # HERE
    @test length(findall("stablehlo.broadcast_in_dim", repr(hlo))) == 2
end

Trace when execute the line manually:

julia> t′ = Optimisers.fmap(copy, tree; exclude=Optimisers.maywrite)  # walks inside Leaf
ERROR: could not load symbol "jl_expand":
/root/julia/bin/../lib/julia/libjulia-internal.so.1.13: undefined symbol: jl_expand
Stacktrace:
  [1] __cacheget_generator__(world::UInt64, source::Method, self::Type, cache::Type, x::Type, args::Tuple{DataType, DataType})
    @ Functors ~/.julia/packages/Functors/LbNAu/src/cache.jl:24
  [2] (::Functors.CachedWalk{…})(::Function, ::ConcretePJRTNumber{…})
    @ Functors ~/.julia/packages/Functors/LbNAu/src/walks.jl:175
  [3] recurse
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:54 [inlined]
  [4] map
    @ ./tuple.jl:354 [inlined]
  [5] map
    @ ./namedtuple.jl:263 [inlined]
  [6] _map
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:3 [inlined]
  [7] DefaultWalk
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:73 [inlined]
  [8] ExcludeWalk
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:126 [inlined]
  [9] CachedWalk
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:177 [inlined]
 [10] recurse
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:54 [inlined]
 [11] map(f::Functors.var"#recurse#execute##0"{Functors.CachedWalk{}}, t::Tuple{Descent{…}, Nothing, Bool})
    @ Base ./tuple.jl:356
 [12] map(::Function, ::@NamedTuple{rule::Descent{ConcretePJRTNumber{Float32, 1}}, state::Nothing, frozen::Bool})
    @ Base ./namedtuple.jl:263
 [13] _map
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:3 [inlined]
 [14] (::Functors.DefaultWalk)(::Function, ::Optimisers.Leaf{Descent{ConcretePJRTNumber{Float32, 1}}, Nothing})
    @ Functors ~/.julia/packages/Functors/LbNAu/src/walks.jl:73
 [15] ExcludeWalk
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:126 [inlined]
 [16] (::Functors.CachedWalk{…})(::Function, ::Optimisers.Leaf{…})
    @ Functors ~/.julia/packages/Functors/LbNAu/src/walks.jl:177
 [17] recurse
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:54 [inlined]
 [18] map
    @ ./tuple.jl:356 [inlined]
 [19] map
    @ ./namedtuple.jl:263 [inlined]
 [20] _map
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:3 [inlined]
 [21] DefaultWalk
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:73 [inlined]
 [22] ExcludeWalk
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:126 [inlined]
 [23] CachedWalk
    @ ~/.julia/packages/Functors/LbNAu/src/walks.jl:177 [inlined]
 [24] execute(::Functors.CachedWalk{…}, ::@NamedTuple{})
    @ Functors ~/.julia/packages/Functors/LbNAu/src/walks.jl:55
 [25] fmap(::Function, ::@NamedTuple{}; exclude::Function, walk::Functors.DefaultWalk, cache::IdDict{…}, prune::Functors.NoKeyword)
    @ Functors ~/.julia/packages/Functors/LbNAu/src/maps.jl:11
 [26] kwcall(::@NamedTuple{}, ::typeof(Functors.fmap), ::Function, ::@NamedTuple{})
    @ Functors ~/.julia/packages/Functors/LbNAu/src/maps.jl:3
 [27] top-level scope
    @ REPL[20]:1
Some type information was truncated. Use `show(err)` to see complete types.

Which caused by the things about :jl_expand changing from:

# 1.12 Base/meta.jl:line 163
lower(m::Module, @nospecialize(x)) = ccall(:jl_expand, Any, (Any, Any), x, m)

# 1.12  Base/expr.jl:line 1667-1668
function generated_body_to_codeinfo(ex::Expr, defmod::Module, isva::Bool)
    ci = ccall(:jl_expand, Any, (Any, Any), ex, defmod)

to:

# 1.13 Base/meta.jl:line 275
lower(m::Module, @nospecialize(x)) = Core._lower(x, m, "none", 0, typemax(Csize_t), false)[1]

# 1.13  Base/expr.jl:line 1800-1802
function generated_body_to_codeinfo(ex::Expr, defmod::Module, isva::Bool)
    ci = ccall(:jl_fl_lower, Any, (Any, Any, Ptr{UInt8}, Csize_t, Csize_t, Cint),
               ex, defmod, "none", 0, typemax(Csize_t), 0)[1]

Where the :jl_expand disapeard in julia 1.13

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.

Reactant compile failed at julia 1.13

2 participants