JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
44.95k stars 5.42k forks source link

`MethodError: no method matching active_module()` (leading to world age error), on Julia 1.11 #54780

Open charleskawczynski opened 2 weeks ago

charleskawczynski commented 2 weeks ago

We're seeing an odd MethodError on Julia 1.11 in ClimaCore CI (here):

field2arrays Unit Tests: Error During Test at /home/runner/work/ClimaCore.jl/ClimaCore.jl/test/MatrixFields/field2arrays.jl:6
  Got exception outside of a @test
  MethodError: no method matching active_module()
  You may have intended to import Base.active_module
  The applicable method may be too new: running in world age 26680, while current world is 27104.

  Closest candidates are:
    active_module(::REPL.LineEditREPL) (method too new to be called from this world context.)
     @ REPL /opt/hostedtoolcache/julia/1.11.0-beta2/x64/share/julia/stdlib/v1.11/REPL/src/REPL.jl:589
    active_module() (method too new to be called from this world context.)
     @ REPL /opt/hostedtoolcache/julia/1.11.0-beta2/x64/share/julia/stdlib/v1.11/REPL/src/REPL.jl:585
    active_module(::REPL.REPLDisplay) (method too new to be called from this world context.)
     @ REPL /opt/hostedtoolcache/julia/1.11.0-beta2/x64/share/julia/stdlib/v1.11/REPL/src/REPL.jl:591
    ...

  Stacktrace:
    [1] #invokelatest#2
      @ ./essentials.jl:1031 [inlined]
    [2] invokelatest
      @ ./essentials.jl:1028 [inlined]
    [3] active_module
      @ ./show.jl:519 [inlined]
    [4] show_type_name(io::IOBuffer, tn::Core.TypeName)
      @ Base ./show.jl:1058
    [5] show_datatype(io::IOBuffer, x::DataType, wheres::Vector{TypeVar})
      @ Base ./show.jl:1185
    [6] show_datatype
      @ ./show.jl:1094 [inlined]
    [7] _show_type(io::IOBuffer, x::Type)
      @ Base ./show.jl:978
    [8] show(io::IOBuffer, x::Type)
      @ Base ./show.jl:970
    [9] print(io::IOBuffer, x::Type)
      @ Base ./strings/io.jl:35
   [10] print_to_string(::String, ::Vararg{Any})
      @ Base ./strings/io.jl:148
   [11] string
      @ ./strings/io.jl:189 [inlined]
   [12] #s14#16
      @ ~/work/ClimaCore.jl/ClimaCore.jl/src/DataLayouts/DataLayouts.jl:172 [inlined]
   [13] var"#s14#16"(S::Any, Name::Any, ::Any, data::Any, ::Any)
      @ ClimaCore.DataLayouts ./none:0
   [14] (::Core.GeneratedFunctionStub)(::UInt64, ::LineNumberNode, ::Any, ::Vararg{Any})
      @ Core ./boot.jl:708
   [15] getproperty
      @ ~/work/ClimaCore.jl/ClimaCore.jl/src/DataLayouts/DataLayouts.jl:182 [inlined]
   [16] coordinates_data
      @ ~/work/ClimaCore.jl/ClimaCore.jl/src/Spaces/Spaces.jl:83 [inlined]
   [17] 

This same code works on Julia 1.10.

vtjnash commented 2 weeks ago

It looks like there was an issue with #46866, where is wrongly used invokelatest instead of using applicable to determine if a particular method was safe to call

vtjnash commented 2 weeks ago

Note that the thing this generated function may be doing (string-ify a Type) may be causing UB as well, since that operation accesses a significant amount of non-constant global state (to pretty-ify the result), which may trigger arbitrary UB.