Skip to content

Commit fc02d07

Browse files
authored
Separate JuliaLowering.eval() from Core.eval() (#70)
Overloading `Core.eval()` with `SyntaxTree` was a cute trick but I believe it causes invalidations in the include machinery (Base.IncludeInto) and doesn't really integrate JuliaLowering properly because it doesn't let us implement `Core.eval(::Module, ::Expr)`. Instead we need hooks to do the integration properly. For now, implementing `eval` as a separate function helps quite a lot with precompile time - about a 15% reduction on my machine.
1 parent f72d616 commit fc02d07

File tree

6 files changed

+12
-13
lines changed

6 files changed

+12
-13
lines changed

src/JuliaLowering.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1+
# Use a baremodule because we're implementing `include` and `eval`
12
baremodule JuliaLowering
23

3-
# ^ Use baremodule because we're implementing `Base.include` and `Core.eval`.
44
using Base
55
# We define a separate _include() for use in this module to avoid mixing method
66
# tables with the public `JuliaLowering.include()` API
77
const _include = Base.IncludeInto(JuliaLowering)
8-
using Core: eval
98

109
if parentmodule(JuliaLowering) === Base
1110
using Base.JuliaSyntax

src/eval.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ else
5959
end)
6060
end
6161

62-
eval(@__MODULE__, code)
62+
Core.eval(@__MODULE__, code)
6363
end
6464
end
6565

@@ -349,7 +349,7 @@ end
349349

350350
#-------------------------------------------------------------------------------
351351
# Our version of eval takes our own data structures
352-
@fzone "JL: eval" function Core.eval(mod::Module, ex::SyntaxTree; expr_compat_mode::Bool=false)
352+
@fzone "JL: eval" function eval(mod::Module, ex::SyntaxTree; expr_compat_mode::Bool=false)
353353
k = kind(ex)
354354
if k == K"toplevel"
355355
x = nothing
@@ -359,8 +359,8 @@ end
359359
return x
360360
end
361361
linear_ir = lower(mod, ex; expr_compat_mode)
362-
expr_form = to_lowered_expr(mod, linear_ir)
363-
eval(mod, expr_form)
362+
thunk = to_lowered_expr(mod, linear_ir)
363+
Core.eval(mod, thunk)
364364
end
365365

366366
"""

src/macro_expansion.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ function eval_macro_name(ctx::MacroExpansionContext, mctx::MacroContext, ex::Syn
149149
mod = current_layer(ctx).mod
150150
expr_form = to_lowered_expr(mod, ex5)
151151
try
152-
eval(mod, expr_form)
152+
Core.eval(mod, expr_form)
153153
catch err
154154
throw(MacroExpansionError(mctx, ex, "Macro not found", :all, err))
155155
end

src/runtime.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ function eval_module(parentmod, modname, expr_compat_mode, body)
229229
# mod = @ccall jl_new_module(Symbol(modname)::Symbol, parentmod::Module)::Any
230230
# ...
231231
name = Symbol(modname)
232-
eval(parentmod, :(
232+
Core.eval(parentmod, :(
233233
baremodule $name
234234
$eval($name, $body; expr_compat_mode=$expr_compat_mode)
235235
end
@@ -246,21 +246,21 @@ function eval_import(imported::Bool, to::Module, from::Union{Expr, Nothing}, pat
246246
ex = isnothing(from) ?
247247
Expr(head, paths...) :
248248
Expr(head, Expr(Symbol(":"), from, paths...))
249-
Base.eval(to, ex)
249+
Core.eval(to, ex)
250250
end
251251
end
252252

253253
function eval_using(to::Module, path::Expr)
254254
if _Base_has_eval_import
255255
Base._eval_using(to, path)
256256
else
257-
Base.eval(to, Expr(:using, path))
257+
Core.eval(to, Expr(:using, path))
258258
end
259259
end
260260

261261
function eval_public(mod::Module, is_exported::Bool, identifiers)
262262
# symbol jl_module_public is no longer exported as of #57765
263-
eval(mod, Expr((is_exported ? :export : :public), map(Symbol, identifiers)...))
263+
Core.eval(mod, Expr((is_exported ? :export : :public), map(Symbol, identifiers)...))
264264
end
265265

266266
#--------------------------------------------------

test/scopes.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ function wrapscope(ex, scope_type)
6666
end
6767

6868
assign_z_2 = parsestmt(SyntaxTree, "begin z = 2 end", filename="foo.jl")
69-
JuliaLowering.eval(test_mod, :(z=1))
69+
Base.eval(test_mod, :(z=1))
7070
@test test_mod.z == 1
7171
# neutral (eg, for loops) and hard (eg, let) scopes create a new binding for z
7272
JuliaLowering.eval(test_mod, wrapscope(assign_z_2, :neutral))

test/utils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ function format_ir_for_test(mod, case)
163163
if kind(ex) == K"macrocall" && kind(ex[1]) == K"MacroName" && ex[1].name_val == "@ast_"
164164
# Total hack, until @ast_ can be implemented in terms of new-style
165165
# macros.
166-
ex = JuliaLowering.eval(mod, Expr(ex))
166+
ex = Base.eval(mod, Expr(ex))
167167
end
168168
x = JuliaLowering.lower(mod, ex)
169169
if case.expect_error

0 commit comments

Comments
 (0)