Help with solving a world age error in package on julia master


#1

My package https://github.com/KristofferC/OhMyREPL.jl started failing on master with the error.

julia> WARNING: Caught an exception in the keymap:
ERROR: MethodError: no method matching (::OhMyREPL.Prompt.##1#28)(::Base.LineEdit.MIState, ::Base.REPL.LineEditREPL, ::String)
The applicable method may be too new: running in world age 20392, while current world is 20418.
Closest candidates are:
  #1(::Any, ::Any, ::Any) at /home/kristoffer/.julia/v0.6/OhMyREPL/src/repl.jl:72 (method too new to be called from this world context.)

The error occurs as soon as the package is loaded and a key is pressed.
What the function is supposed to do is to change some hotkeys the REPL normally use to call a few other functions. IIUC this error happens when a method defined in a running context is tried to be called in that context? The method that is said to be too new (at OhMyREPL/src/repl.jl:72) is an anonymous function that gets bound to a key,

    D["*"]    = (s, data, c) ->  (LineEdit.edit_insert(s, c); rewrite_with_ANSI(s))

How should I rewrite this function as to not run into the current problems?


#2

I made a minimum working example that exhibits the problem:

module REPLInserter

import Base.LineEdit

say_hello() = println("Hello")

function create_keybindings()
	D = Dict{Any, Any}()
    D["*"]    = (s, data, c) ->  (LineEdit.edit_insert(s, c); say_hello())
    return D
end
const KEYBINDS = create_keybindings()


function insert_keybindings()
    repl = Base.active_repl
    mirepl = isdefined(repl,:mi) ? repl.mi : repl
    main_mode = mirepl.interface.modes[1]
    main_mode.keymap_dict = LineEdit.keymap([KEYBINDS, main_mode.keymap_dict])
end

end

REPLInserter.insert_keybindings()

Run this, then press a button in the REPL.


#3

I have no idea what the solution is, but it started happening on the 0.6 Travis for me as well, though with the eval function:
https://travis-ci.org/JuliaInterop/CxxWrap.jl/jobs/186630015#L247


#4

The REPL issue is a base REPL bug. the CxxWrap one is most likely a package bug.


#5

Also Cuba.jl and Cubature.jl are currently failing on Julia master:

Any hint about how to fix this?


#6

More info about my crash here: https://github.com/JuliaLang/julia/issues/19754#issuecomment-269646295

But it seems more appropriate to discuss here, then. I have no idea what the error even means, let alone what I might be doing wrong to provoke it.


#7

The error means that you are calling a method that’s too new. See here for the doc. The error message shows you that it’s the module specific eval that’s too new and since these are automatically defined when the module is created it’s likely caused by creating modules dynamically and trying to call methods (eval) defined in it. This seems to be what you are doing.

The easiest workaround is to use eval(mod, expr) instead of mod.eval(expr). Also note that instead of using try-catch and eval of a single simple with a no-op interpolation you can just do

if isdefined(parent_module, mod_sym)
    jl_mod = getfield(parent_module, mod_sym)
else
    jl_mod = Core.eval(parent_module, :(module $mod_sym end))
end

No need for jl_mod = nothing either.


#8

I’m reading that section of the manual right now, I hope to understand how to adapt the package.

However there is no eval nor try-catch in Cuba.jl, I’m not sure what you’re referring to.


#9

That was the reply to @barche It’s harder to see the issue from the log for Cuba.jl Is it using generated functions?


#10

No. A possible pitfall may be generic_integrand! function:


A pointer to this function is defined at init time.

I wouldn’t say there is any function redefinition in Cuba.jl (and Cubature.jl is pretty similar), the manual didn’t help me much.


#11

Thanks a lot, working fine now! An additional complication was that the eval at the reported line wasn’t actually the problem, it was later use of eval (in the new module) that triggered it. Replacing all other occurrences with Core.eval fixed it though.


#12

It would be good to have a better solution for callback functions than calling eval. https://github.com/JuliaLang/julia/issues/19774