Skip to content

Commit

Permalink
fix #23978, deprecation message for Base.Test (#23983)
Browse files Browse the repository at this point in the history
also automatically load packages moved from Base.X to stdlib
  • Loading branch information
JeffBezanson authored Oct 5, 2017
1 parent 16139d0 commit 92fa0f3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 33 deletions.
12 changes: 1 addition & 11 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
25 changes: 15 additions & 10 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down
49 changes: 37 additions & 12 deletions src/toplevel.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down

2 comments on commit 92fa0f3

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.