Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes for julia v1.10 #109

Merged

Conversation

IanButterworth
Copy link
Contributor

@IanButterworth IanButterworth commented Apr 25, 2023

Proposed fix for #108

Includes the fix from #112 to try and get CI green

@vtjnash

@codecov-commenter
Copy link

codecov-commenter commented Apr 25, 2023

Codecov Report

Patch coverage: 36.36% and project coverage change: -0.34 ⚠️

Comparison is base (62d5f42) 74.98% compared to head (68b9fa5) 74.64%.

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #109      +/-   ##
==========================================
- Coverage   74.98%   74.64%   -0.34%     
==========================================
  Files          15       15              
  Lines        1419     1428       +9     
==========================================
+ Hits         1064     1066       +2     
- Misses        355      362       +7     
Impacted Files Coverage Δ
src/reflection/utils.jl 90.43% <28.57%> (-4.01%) ⬇️
src/eval.jl 88.88% <50.00%> (-5.23%) ⬇️
src/reflection/reflection.jl 83.33% <50.00%> (-1.42%) ⬇️

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@static if VERSION < v"1.8.0-DEV.267"
@static if VERSION >= v"1.10.0-DEV.870"
function replace_code_newstyle!(ci, ir, _)
return Core.Compiler.replace_code_newstyle!(ci, ir)
Copy link
Contributor

Choose a reason for hiding this comment

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

you also might need to allocate slottypes, if you didn't already do that

    ci.slottypes isa Array || (ci.slottypes = [])

IanButterworth and others added 3 commits April 26, 2023 12:03
end
Base.Meta.partially_inline!(ci.code, [], method.sig, Any[sps...], 0, 0, :propagate)
Meta(method, mi, ci, method.nargs, sps)
end

function invoke_tweaks!(ci::CodeInfo)
ci.slottypes = [:todo, ci.slottypess[1], :todo, ci.slottypes[2:end]...]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't know what to put here where there is :todo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've gone with

  ci.slottypes = [typeof(invoke), ci.slottypess[1], Type, ci.slottypes[2:end]...]

@IanButterworth
Copy link
Contributor Author

I think I've done all the obvious stuff here. Seems like it needs someone with more IRTools knowledge

@IanButterworth
Copy link
Contributor Author

@aviatesk @vtjnash any idea what's going on here? I'm not familiar with IRTools at all

@vtjnash
Copy link
Contributor

vtjnash commented Apr 27, 2023

Oh, it is using APIs that Base doesn't have anymore and need to be converted to the new API

@maleadt
Copy link
Contributor

maleadt commented May 2, 2023

Here's with those APIs fixed: master...maleadt:IRTools.jl:replace_code_newstyle_fix
@IanButterworth Can you merge that here?

Only a couple of test failures remain.

Co-Authored-By: Tim Besard <383068+maleadt@users.noreply.github.com>
@IanButterworth IanButterworth changed the title fix replace_code_newstyle! on 1.10 Fixes for julia v1.10 May 2, 2023
@IanButterworth
Copy link
Contributor Author

IanButterworth commented May 2, 2023

Compiler: Test Failed at /home/runner/work/IRTools.jl/IRTools.jl/test/compiler.jl:93
  Expression: mullify(prod, [5, 10]) == 15
   Evaluated: 50 == 15

Is because https://github.com/IanButterworth/IRTools.jl/blob/668530fb38ca20678e0934efb3b74d93d8711925/test/compiler.jl#L80 is returning as nothing because https://github.com/IanButterworth/IRTools.jl/blob/6666ab00735fd52b73161c7fdf8755b8c4501a9c/src/ir/wrap.jl#L157-L158 is returning nothing.

Might this be related to Jameson's comment here f401a95#r111498985 @maleadt ?

Also, Zygote still fails to load with this in its current form, no method matching iterate(::Nothing) so appears to suffer a similar issue

@IanButterworth
Copy link
Contributor Author

Appears to be a world age issue

julia> @dynamo function mullify(a...)
         @show ir = IR(a...)
         ir == nothing && return
         ir = MacroTools.prewalk(ir) do x
           x isa GlobalRef && x.name == :(*) && return GlobalRef(Base, :+)
           return x
         end
         for (x, st) in ir
           isexpr(st.expr, :call) || continue
           ir[x] = xcall(Main, :mullify, st.expr.args...)
         end
         return ir
       end

julia> mullify(prod, [5, 10])
Tuple{Ts...} = Tuple{typeof(prod), Vector{Int64}}
m = IRTools.meta(Tuple{Ts...}) = nothing
ir = IR(a...) = nothing

julia> IRTools.meta(Tuple{typeof(prod), Vector{Int64}})
Metadata for prod(a::AbstractArray; dims, kw...) @ Base reducedim.jl:994

@maleadt
Copy link
Contributor

maleadt commented May 3, 2023

Might this be related to Jameson's comment here f401a95#r111498985 @maleadt ?

No, that's unrelated.

The problem is that @dynamo is fundamentally broken. Or at least the cases where the dynamo looks up Julia IR, which now needs to be done with world ages in mind (i.e. passing the age to reflection functions and setting edges on the returned CodeInfo), like the mullify one above. Sadly, this also seems like the way most packages use @dynamo.

@maleadt
Copy link
Contributor

maleadt commented May 3, 2023

Updated my fork; it passes tests now.

@IanButterworth
Copy link
Contributor Author

Great! Although Zygote still fails to precompile on https://github.com/FluxML/Zygote.jl/blob/2287a86d1692c0dfc568739a80ca909199f6adfe/src/precompile.jl#LL17C20-L17C20

But perhaps that shouldn't stop this being merged and released?

ERROR: LoadError: MethodError: no method matching iterate(::Nothing)

Closest candidates are:
  iterate(::Union{LinRange, StepRangeLen})
   @ Base range.jl:887
  iterate(::Union{LinRange, StepRangeLen}, ::Integer)
   @ Base range.jl:887
  iterate(::T) where T<:Union{Base.KeySet{<:Any, <:Dict}, Base.ValueIterator{<:Dict}}
   @ Base dict.jl:728
  ...

Stacktrace:
  [1] indexed_iterate(I::Nothing, i::Int64)
    @ Base ./tuple.jl:95
  [2] chain_rrule(::Zygote.ZygoteRuleConfig{Zygote.Context{false}}, ::typeof(Zygote.pow), ::Int64, ::Int64)
    @ Zygote ~/.julia/packages/Zygote/SuKWp/src/compiler/chainrules.jl:223 [inlined]
  [3] macro expansion
    @ Zygote ~/.julia/packages/Zygote/SuKWp/src/compiler/interface2.jl:0 [inlined]
  [4] _pullback(::Zygote.Context{false}, ::typeof(Zygote.pow), ::Int64, ::Int64)
    @ Zygote ~/.julia/packages/Zygote/SuKWp/src/compiler/interface2.jl:9
  [5] pullback(::Function, ::Zygote.Context{false}, ::Int64, ::Vararg{Int64})
    @ Zygote ~/.julia/packages/Zygote/SuKWp/src/compiler/interface.jl:44
  [6] pullback(::Function, ::Int64, ::Int64)
    @ Zygote ~/.julia/packages/Zygote/SuKWp/src/compiler/interface.jl:42
  [7] gradient(::Function, ::Int64, ::Vararg{Int64})
    @ Zygote ~/.julia/packages/Zygote/SuKWp/src/compiler/interface.jl:96
  [8] top-level scope
    @ ~/.julia/packages/Zygote/SuKWp/src/precompile.jl:17

@maleadt
Copy link
Contributor

maleadt commented May 3, 2023

I pushed another fix to my branch.

Some initial fixes for Zygote.jl are in https://github.com/maleadt/Zygote.jl/tree/dev, depending on this PR. This makes Zygote precompile and makes a smoke test gradient succeed, but there's more instances where the generated world age isn't propagated to reflection methods (resulting in nothing results, or in code reflection cannot be used from generated functions errors). Those should be relatively easy to fix though, with the core fixes in place.
EDIT: actually, it was only a single call to which. I've pushed a commit.

@IanButterworth
Copy link
Contributor Author

It would be good to get this released

@maleadt
Copy link
Contributor

maleadt commented May 9, 2023

@IanButterworth Can you merge the latest version of my branch?

@IanButterworth
Copy link
Contributor Author

I believe this branch is up to date with yours?

@maleadt
Copy link
Contributor

maleadt commented May 10, 2023

Ah yes, the GitHub UI is confusing here.

Can we get this (squash-)merged and tagged then? @CarloLucibello @ToucheSir

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.

5 participants