Is there a way to manually trigger a world_age update?

Just for reference, this is the kind of world age error you might get:

The applicable method may be too new: running in world age 21937, while current world is 22335.

The ways around it are:

  • Base.invokelatest
  • Core._apply_latest

But they both actually call the function.

Is there a way to do a simple update world age without a ccall?

// for the sake of this question, assume it is “safe” to update the world age. this is not done in the middle of a function or in the midst of a long string of calls

relevant posts:

1 Like

I’m confused about what you are trying to do.

invokelatest is needed when you are in a function f trying to call a function g, but you want to invoke a version of g that is newer that the version of f that is currently running. The “current world” is the age of the code that is currently running.

You obviously cannot recompile f while you are running it. But this means that you can’t invoke g in the “normal” way — for a normal function call, g might have been inlined (which will obviously not call the latest version). Also, when f was compiled, type inference (hopefully) determined the return type of g and specialized f’s code for that result … the latest g may have changed its return type.

So, invokelatest(g, ...) calls g in a way that always chases the Function pointer, and the compilation of f assumes that the return type is Any (i.e. the result is type unstable, because the return type of g may change). This obviously hurts performance, which is why you only use invokelatest in specialized circumstances.