From d224963eaf72ffe69a7925f11883a8c35201b3c7 Mon Sep 17 00:00:00 2001 From: Chris Foster Date: Wed, 8 Apr 2020 20:57:11 +1000 Subject: [PATCH] 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. --- base/Base.jl | 16 +++++++++++++++- base/client.jl | 2 +- base/loading.jl | 6 ++++-- src/jlfrontend.scm | 2 +- src/toplevel.c | 15 ++++++--------- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/base/Base.jl b/base/Base.jl index d8596df632de1..634fee3c418b4 100644 --- a/base/Base.jl +++ b/base/Base.jl @@ -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 @@ -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 diff --git a/base/client.jl b/base/client.jl index f101360324156..61e93f41c7b38 100644 --- a/base/client.jl +++ b/base/client.jl @@ -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 """ diff --git a/base/loading.jl b/base/loading.jl index 333d66b212510..ed2939ddf0fe7 100644 --- a/base/loading.jl +++ b/base/loading.jl @@ -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") @@ -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)))) diff --git a/src/jlfrontend.scm b/src/jlfrontend.scm index 6624c71be2e66..727e3d7cf4158 100644 --- a/src/jlfrontend.scm +++ b/src/jlfrontend.scm @@ -187,7 +187,7 @@ (= (call eval ,x) (block ,@loc - (call (core eval) ,name ,x))) + (call (top eval) ,name ,x))) (= (call include ,x) (block ,@loc diff --git a/src/toplevel.c b/src/toplevel.c index 86e9c215c6644..9bfb089c80263 100644 --- a/src/toplevel.c +++ b/src/toplevel.c @@ -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); } @@ -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