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?
-
The formalization of the world-age semantics in a core calculus called Juliette. The calculus operates with explicit method tables and models
eval
with a simpler global-evaluation construct. -
An implementation of the calculus as a Redex model (Redex is a Racket-based DSL) with a transpiler from Julia to Juliette (the calculus is instantiated with a small number of standard types and functions for arithmetic and equality).
-
Static and dynamic analysis of
eval
usage in registered Julia package (implemented in Julia).
Papers
-
OOPSLA 2020
World Age in Julia: Optimizing Method Dispatch in the Presence of EvalAuthors: Julia Belyakova, Benjamin Chung, Jack Gelinas, Jameson Nash, Ross Tate, Jan Vitek
DOI: 10.1145/3428275
Venue: Proc. ACM Program. Lang., Volume 4, OOPSLA, Article 207 (26 pages)
Reviews
Dynamic programming languages face semantic and performance challenges in the presence of features, such as eval, that can inject new code into a running program. The Julia programming language introduces the novel concept of world age to insulate optimized code from one of the most disruptive side-effects of eval: changes to the definition of an existing function. This paper provides the first formal semantics of world age in a core calculus named Juliette, and shows how world age enables compiler optimizations, such as inlining, in the presence of eval. While Julia also provides programmers with the means to bypass world age, we found that this mechanism is not used extensively: a static analysis of over 4,000 registered Julia packages shows that only 4-9% of packages bypass world age. This suggests that Julia's semantics aligns with programmer expectations. -
OOPSLA 2020 Extended (arXiv)
World Age in Julia: Optimizing Method Dispatch in the Presence of Eval (Extended Version)Authors: Julia Belyakova, Benjamin Chung, Jack Gelinas, Jameson Nash, Ross Tate, Jan Vitek
Venue: arXiv on Programming Languages (43 pages)
Common questions
- TBD
Informal
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
end
# 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.