diff --git a/base/deprecated.jl b/base/deprecated.jl index 70aa533b1a97f..9b70231113c31 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1356,17 +1356,7 @@ end using .DSP export conv, conv2, deconv, filt, filt!, xcorr -module Test -for f in [Symbol("@inferred"), Symbol("@test"), Symbol("@test_approx_eq"), - Symbol("@test_approx_eq_eps"), Symbol("@test_broken"), Symbol("@test_nowarn"), - Symbol("@test_skip"), Symbol("@test_throws"), Symbol("@test_warn"), - Symbol("@testset"), :GenericArray, :GenericDict, :GenericSet, :GenericString, - :detect_ambiguities, :detect_unbound_args] - @eval Base.@deprecate_moved $f "Test" true true -end -end -export Test -deprecate(@__MODULE__, :Test) +@deprecate_binding Test nothing true ", run `using Test` instead" @deprecate_moved SharedArray "SharedArrays" true true diff --git a/src/module.c b/src/module.c index 91514d1503454..7f3cfce998786 100644 --- a/src/module.c +++ b/src/module.c @@ -233,7 +233,7 @@ void jl_binding_deprecation_warning(jl_binding_t *b); JL_DLLEXPORT jl_binding_t *jl_get_binding_or_error(jl_module_t *m, jl_sym_t *var) { - jl_binding_t *b = jl_get_binding_(m, var, NULL); + jl_binding_t *b = jl_get_binding(m, var); if (b == NULL) jl_undefined_var_error(var); if (b->deprecated) @@ -283,15 +283,20 @@ static void module_import_(jl_module_t *to, jl_module_t *from, jl_sym_t *s, jl_symbol_name(to->name)); } else { - if (b->deprecated && to != jl_main_module && to != jl_base_module && - jl_options.depwarn != JL_OPTIONS_DEPWARN_OFF) { - /* with #22763, external packages wanting to replace - deprecated Base bindings should simply export the new - binding */ - jl_printf(JL_STDERR, - "WARNING: importing deprecated binding %s.%s into %s.\n", - jl_symbol_name(from->name), jl_symbol_name(s), - jl_symbol_name(to->name)); + if (b->deprecated) { + if (b->value == jl_nothing) { + return; + } + else if (to != jl_main_module && to != jl_base_module && + jl_options.depwarn != JL_OPTIONS_DEPWARN_OFF) { + /* with #22763, external packages wanting to replace + deprecated Base bindings should simply export the new + binding */ + jl_printf(JL_STDERR, + "WARNING: importing deprecated binding %s.%s into %s.\n", + jl_symbol_name(from->name), jl_symbol_name(s), + jl_symbol_name(to->name)); + } } jl_binding_t **bp = (jl_binding_t**)ptrhash_bp(&to->bindings, s); diff --git a/src/toplevel.c b/src/toplevel.c index 3bc5f4bd233fd..7da07e3a1f55d 100644 --- a/src/toplevel.c +++ b/src/toplevel.c @@ -363,12 +363,27 @@ static int jl_eval_expr_with_compiler_p(jl_value_t *e, int compileloops, jl_modu return 0; } +static jl_module_t *call_require(jl_sym_t *var) +{ + static jl_value_t *require_func = NULL; + jl_module_t *m = NULL; + if (require_func == NULL && jl_base_module != NULL) + require_func = jl_get_global(jl_base_module, jl_symbol("require")); + if (require_func != NULL) { + jl_value_t *reqargs[2] = {require_func, (jl_value_t*)var}; + m = (jl_module_t*)jl_apply(reqargs, 2); + } + if (m == NULL || !jl_is_module(m)) { + jl_errorf("failed to load module %s", jl_symbol_name(var)); + } + return m; +} + // either: // - sets *name and returns the module to import *name from // - sets *name to NULL and returns a module to import static jl_module_t *eval_import_path(jl_module_t *from, jl_array_t *args, jl_sym_t **name, const char *keyword) { - static jl_value_t *require_func=NULL; jl_sym_t *var = (jl_sym_t*)jl_array_ptr_ref(args, 0); size_t i = 1; jl_module_t *m = NULL; @@ -385,15 +400,7 @@ static jl_module_t *eval_import_path(jl_module_t *from, jl_array_t *args, jl_sym m = jl_base_module; } else { - if (require_func == NULL && jl_base_module != NULL) - require_func = jl_get_global(jl_base_module, jl_symbol("require")); - if (require_func != NULL) { - jl_value_t *reqargs[2] = {require_func, (jl_value_t*)var}; - m = (jl_module_t*)jl_apply(reqargs, 2); - } - if (m == NULL || !jl_is_module(m)) { - jl_errorf("failed to load module %s", jl_symbol_name(var)); - } + m = call_require(var); } if (i == jl_array_len(args)) return m; @@ -472,6 +479,16 @@ static void import_module(jl_module_t *m, jl_module_t *import) jl_set_const(m, name, (jl_value_t*)import); } +// replace Base.X with top-level X +static jl_module_t *deprecation_replacement_module(jl_module_t *parent, jl_sym_t *name) +{ + if (parent == jl_base_module) { + if (name == jl_symbol("Test") || name == jl_symbol("Mmap")) + return call_require(name); + } + return NULL; +} + jl_value_t *jl_toplevel_eval_flex(jl_module_t *m, jl_value_t *e, int fast, int expanded) { jl_ptls_t ptls = jl_get_ptls_states(); @@ -519,7 +536,11 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *m, jl_value_t *e, int fast, int e } } else { - jl_module_use(m, import, name); + jl_module_t *replacement = deprecation_replacement_module(import, name); + if (replacement) + jl_module_using(m, replacement); + else + jl_module_use(m, import, name); } return jl_nothing; } @@ -530,7 +551,11 @@ jl_value_t *jl_toplevel_eval_flex(jl_module_t *m, jl_value_t *e, int fast, int e import_module(m, import); } else { - jl_module_import(m, import, name); + jl_module_t *replacement = deprecation_replacement_module(import, name); + if (replacement) + import_module(m, replacement); + else + jl_module_import(m, import, name); } return jl_nothing; }