Julia Belyakova

Juliette: a formalization of world age and eval in Julia (2020–…)

A formalization of world age in the Julia language. World age is a mechanism that enables efficient and relatively simple implementation of multiple dispatch in the presence of eval. Namely, the world-age semantics allows Julia to optimize methods and method calls at certain points of the program execution, without ever needing to de-optimize them on the fly.

Questions/comments/feedback If you have any questions or comments about the project or related papers, please, feel free to email me or submit your feedback using this Google form. I would be happy to answer questions that you might have, learn about what is unclear or confusing, or receive any other feedback.

What’s in here?


Common questions


What is world age?

World age is a language mechanism that prevents new methods (functions) defined in eval to be called from an already running function. For example, consider the following program:

f(x) = 1

# g(x) calls f(x) once, then
# redefines f(x) in eval, and calls f(x) again
function g(x)
  v1 = f(x)
  v2 = (eval(:(f(x) = 0)); f(x))
  v1 * v2

# at this point, there are two methods:
# f(x) = 1 and g(x) = ...
g(5)     # 1

# at this point, method f is redefined:
# f(x) = 0
g(666)   # 0

Without the world age feature, call g(5) would return 0. This is because the first call to f returns 1, the second would return 0 (because f was redefined in eval), and 1*0 is 0.

However, in Julia, g(5) will actually return 1. Why? Because the redefinition f(x) = 0 from eval is not visible while g(5) is running. We can think of this mechanism in the following way: Julia’s run-time takes a snapshot of method definitions before the call g(5), and then uses the snapshot to resolve nested method calls.
But once g(5) is done, the new definition of f becomes visible, so the next call g(666) will return 0.