Skip to content

Commit d224963

Browse files
committed
Emit broken precompilation warning from julia layer
This allows us to use Core.eval() for moving additional code loading tools (jl_parse_eval_all) from C to Julia. It also allows us to use the normal logging system to format the warning more nicely.
1 parent 245d01e commit d224963

File tree

5 files changed

+27
-14
lines changed

5 files changed

+27
-14
lines changed

base/Base.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ setproperty!(x, f::Symbol, v) = setfield!(x, f, convert(fieldtype(typeof(x), f),
3535

3636
include("coreio.jl")
3737

38-
eval(x) = Core.eval(Base, x)
38+
eval(x) = eval(Base, x)
39+
# During bootstrap, Base.eval is simply Core.eval.
40+
# Later we redefine it to the full version.
3941
eval(m::Module, x) = Core.eval(m, x)
4042

4143
# init core docsystem
@@ -368,6 +370,18 @@ end
368370
include(mod::Module, _path::AbstractString) = _include(identity, mod, _path)
369371
include(mapexpr::Function, mod::Module, _path::AbstractString) = _include(mapexpr, mod, _path)
370372

373+
# Make `eval` point to the full version
374+
foreach(delete_method, methods(eval, (Module, Any)))
375+
function eval(m::Module, ex)
376+
if @ccall(jl_is_closed_module(m::Any)::Cint) != 0
377+
@warn """Eval into closed module `$m`.
378+
379+
**Incremental compilation may be fatally broken for this module**""" #=
380+
=# expression=ex mod=m
381+
end
382+
Core.eval(Base, ex)
383+
end
384+
371385
end_base_include = time_ns()
372386

373387
if is_primary_base_module

base/client.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ function include(fname::AbstractString)
429429
isa(fname, String) || (fname = Base.convert(String, fname)::String)
430430
Base._include(identity, Main, fname)
431431
end
432-
eval(x) = Core.eval(Main, x)
432+
eval(x) = Base.eval(Main, x)
433433
end
434434

435435
"""

base/loading.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ function _require(pkg::PkgId)
10701070
nothing
10711071
end
10721072

1073-
# relative-path load
1073+
# Code loading with a relative path --- include_string(), include(), evalfile()
10741074

10751075
"""
10761076
include_string([mapexpr::Function,] m::Module, code::AbstractString, filename::AbstractString="string")
@@ -1153,13 +1153,15 @@ function evalfile(path::AbstractString, args::Vector{String}=String[])
11531153
return Core.eval(Module(:__anon__),
11541154
Expr(:toplevel,
11551155
:(const ARGS = $args),
1156-
:(eval(x) = $(Expr(:core, :eval))(__anon__, x)),
1156+
:(eval(x) = $(Expr(:top, :eval))(__anon__, x)),
11571157
:(include(x) = $(Expr(:top, :include))(__anon__, x)),
11581158
:(include(mapexpr::Function, x) = $(Expr(:top, :include))(mapexpr, __anon__, x)),
11591159
:(include($path))))
11601160
end
11611161
evalfile(path::AbstractString, args::Vector) = evalfile(path, String[args...])
11621162

1163+
# Compile cache ----------------------------
1164+
11631165
function load_path_setup_code(load_path::Bool=true)
11641166
code = """
11651167
append!(empty!(Base.DEPOT_PATH), $(repr(map(abspath, DEPOT_PATH))))

src/jlfrontend.scm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
(= (call eval ,x)
188188
(block
189189
,@loc
190-
(call (core eval) ,name ,x)))
190+
(call (top eval) ,name ,x)))
191191
(= (call include ,x)
192192
(block
193193
,@loc

src/toplevel.c

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -832,15 +832,6 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_in(jl_module_t *m, jl_value_t *ex)
832832
const char *last_filename = jl_filename;
833833
jl_lineno = 1;
834834
jl_filename = "none";
835-
if (jl_options.incremental && jl_generating_output()) {
836-
if (!ptrhash_has(&jl_current_modules, (void*)m)) {
837-
if (m != jl_main_module) { // TODO: this was grand-fathered in
838-
jl_printf(JL_STDERR, "WARNING: eval into closed module %s:\n", jl_symbol_name(m->name));
839-
jl_static_show(JL_STDERR, ex);
840-
jl_printf(JL_STDERR, "\n ** incremental compilation may be fatally broken for this module **\n\n");
841-
}
842-
}
843-
}
844835
JL_TRY {
845836
v = jl_toplevel_eval(m, ex);
846837
}
@@ -1001,6 +992,12 @@ JL_DLLEXPORT jl_value_t *jl_load_file_string(const char *text, size_t len,
1001992
return result;
1002993
}
1003994

995+
JL_DLLEXPORT int jl_is_closed_module(jl_module_t *mod)
996+
{
997+
return jl_options.incremental && jl_generating_output() &&
998+
!ptrhash_has(&jl_current_modules, (void*)mod) &&
999+
mod != jl_main_module; // TODO: this was grand-fathered in
1000+
}
10041001

10051002
//--------------------------------------------------
10061003
// Code loading helpers for bootstrap

0 commit comments

Comments
 (0)