FluxML / IRTools.jl

Mike's Little Intermediate Representation
MIT License
111 stars 35 forks source link

`code reflection cannot be used from generated functions` on Julia 1.10 #111

Closed IanButterworth closed 1 year ago

IanButterworth commented 1 year ago

Even with #109 which seems to be the fix for #108 there are many issues in nightly CI #110

i.e.

IR: Error During Test at /home/runner/work/IRTools.jl/IRTools.jl/test/ir.jl:47
  Test threw exception
  Expression: f(nothing, 2, 3) == 3
  code reflection cannot be used from generated functions
  Stacktrace:
    [1] error(s::String)
      @ Base ./error.jl:35
    [2] method_instances(f::Any, t::Any, world::UInt64)
      @ Base ./reflection.jl:1176
    [3] #code_lowered#15
      @ ./reflection.jl:976 [inlined]
    [4] code_lowered
      @ ./reflection.jl:966 [inlined]
    [5] build_codeinfo(ir::IRTools.Inner.IR)
      @ IRTools.Inner ~/work/IRTools.jl/IRTools.jl/src/eval.jl:7
    [6] #s66#5
      @ ~/work/IRTools.jl/IRTools.jl/src/eval.jl:19 [inlined]
    [7] var"#s66#5"(::Any, arg1::Any, arg2::Any, arg3::Any)
      @ Main ./none:0
    [8] (::Core.GeneratedFunctionStub)(::UInt64, ::LineNumberNode, ::Any, ::Vararg{Any})
      @ Core ./boot.jl:602
    [9] macro expansion
      @ /opt/hostedtoolcache/julia/nightly/x64/share/julia/stdlib/v1.10/Test/src/Test.jl:478 [inlined]
   [10] top-level scope
      @ ~/work/IRTools.jl/IRTools.jl/test/ir.jl:47
IanButterworth commented 1 year ago

first bad commit https://github.com/JuliaLang/julia/pull/49113

Test Summary:       | Pass  Fail  Error  Broken  Total   Time
IRTools             |   24     1     26       1     52  26.3s
  IR                |    2            7              9  12.1s
  Analysis          |    3                           3   0.8s
  Reflection        |    5                           5   0.1s
  Compiler          |    2           19       1     22   3.8s
  Relooper          |   12                          12   3.0s
  Doctests: IRTools |          1                     1   5.9s
ERROR: LoadError: Some tests did not pass: 24 passed, 1 failed, 26 errored, 1 broken.

commit before https://github.com/JuliaLang/julia/commit/8ca8ef3857b3ba272cb05ccc829dffe9e3cfdb48

Test Summary: | Pass  Broken  Total   Time
IRTools       |   60       1     61  33.0s
     Testing IRTools tests passed 

@aviatesk any tips on what to do here?

maleadt commented 1 year ago

first bad commit JuliaLang/julia#49113

That would surprise me. The error comes from the changes in https://github.com/JuliaLang/julia/pull/48766. Basically, it is now forbidden to call code reflection from generated functions, unless explicitly managing codeinfo edges and invalidation thereof. In practice, this means using the lower-level form of @generated which exposes the current world age, propagating that to the returned code info, and using it to invoke code reflection methods with (i.e. forward the world argument).

A good example of this: https://github.com/JuliaDebug/CassetteOverlay.jl/pull/29

IanButterworth commented 1 year ago

You're right, I was only looking at the test summary. It's actually hitting #108 on that commit

IR: Error During Test at /Users/ian/.julia/packages/IRTools/WiQqY/test/ir.jl:34
  Test threw exception
  Expression: foo(mylog2, 3.3) === mylog2(3.3)
  MethodError: no method matching replace_code_newstyle!(::Core.CodeInfo, ::Core.Compiler.IRCode, ::Int64)

  Closest candidates are:
    replace_code_newstyle!(::Core.CodeInfo, ::Core.Compiler.IRCode)
maleadt commented 1 year ago

Should be fixed by https://github.com/FluxML/IRTools.jl/pull/109