Skip to content

Commit

Permalink
Emit broken precompilation warning from julia layer
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
c42f committed Apr 8, 2020
1 parent 245d01e commit d224963
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 14 deletions.
16 changes: 15 additions & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ setproperty!(x, f::Symbol, v) = setfield!(x, f, convert(fieldtype(typeof(x), f),

include("coreio.jl")

eval(x) = Core.eval(Base, x)
eval(x) = eval(Base, x)
# During bootstrap, Base.eval is simply Core.eval.
# Later we redefine it to the full version.
eval(m::Module, x) = Core.eval(m, x)

# init core docsystem
Expand Down Expand Up @@ -368,6 +370,18 @@ end
include(mod::Module, _path::AbstractString) = _include(identity, mod, _path)
include(mapexpr::Function, mod::Module, _path::AbstractString) = _include(mapexpr, mod, _path)

# Make `eval` point to the full version
foreach(delete_method, methods(eval, (Module, Any)))
function eval(m::Module, ex)
if @ccall(jl_is_closed_module(m::Any)::Cint) != 0
@warn """Eval into closed module `$m`.
**Incremental compilation may be fatally broken for this module**""" #=
=# expression=ex mod=m
end
Core.eval(Base, ex)
end

end_base_include = time_ns()

if is_primary_base_module
Expand Down
2 changes: 1 addition & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ function include(fname::AbstractString)
isa(fname, String) || (fname = Base.convert(String, fname)::String)
Base._include(identity, Main, fname)
end
eval(x) = Core.eval(Main, x)
eval(x) = Base.eval(Main, x)
end

"""
Expand Down
6 changes: 4 additions & 2 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ function _require(pkg::PkgId)
nothing
end

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

"""
include_string([mapexpr::Function,] m::Module, code::AbstractString, filename::AbstractString="string")
Expand Down Expand Up @@ -1153,13 +1153,15 @@ function evalfile(path::AbstractString, args::Vector{String}=String[])
return Core.eval(Module(:__anon__),
Expr(:toplevel,
:(const ARGS = $args),
:(eval(x) = $(Expr(:core, :eval))(__anon__, x)),
:(eval(x) = $(Expr(:top, :eval))(__anon__, x)),
:(include(x) = $(Expr(:top, :include))(__anon__, x)),
:(include(mapexpr::Function, x) = $(Expr(:top, :include))(mapexpr, __anon__, x)),
:(include($path))))
end
evalfile(path::AbstractString, args::Vector) = evalfile(path, String[args...])

# Compile cache ----------------------------

function load_path_setup_code(load_path::Bool=true)
code = """
append!(empty!(Base.DEPOT_PATH), $(repr(map(abspath, DEPOT_PATH))))
Expand Down
2 changes: 1 addition & 1 deletion src/jlfrontend.scm
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@
(= (call eval ,x)
(block
,@loc
(call (core eval) ,name ,x)))
(call (top eval) ,name ,x)))
(= (call include ,x)
(block
,@loc
Expand Down
15 changes: 6 additions & 9 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -832,15 +832,6 @@ JL_DLLEXPORT jl_value_t *jl_toplevel_eval_in(jl_module_t *m, jl_value_t *ex)
const char *last_filename = jl_filename;
jl_lineno = 1;
jl_filename = "none";
if (jl_options.incremental && jl_generating_output()) {
if (!ptrhash_has(&jl_current_modules, (void*)m)) {
if (m != jl_main_module) { // TODO: this was grand-fathered in
jl_printf(JL_STDERR, "WARNING: eval into closed module %s:\n", jl_symbol_name(m->name));
jl_static_show(JL_STDERR, ex);
jl_printf(JL_STDERR, "\n ** incremental compilation may be fatally broken for this module **\n\n");
}
}
}
JL_TRY {
v = jl_toplevel_eval(m, ex);
}
Expand Down Expand Up @@ -1001,6 +992,12 @@ JL_DLLEXPORT jl_value_t *jl_load_file_string(const char *text, size_t len,
return result;
}

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

//--------------------------------------------------
// Code loading helpers for bootstrap
Expand Down

0 comments on commit d224963

Please sign in to comment.