Skip to content

Commit

Permalink
print admonition for auto-import only once per module (JuliaLang#57378)
Browse files Browse the repository at this point in the history
Quiets the build somewhat, after JuliaLang#57311 made it noisy.
  • Loading branch information
vtjnash authored Feb 13, 2025
1 parent db874ff commit 6b39a81
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,8 @@ typedef struct _jl_binding_t {
uint8_t exportp:1; // `public foo` sets `publicp`, `export foo` sets both `publicp` and `exportp`
uint8_t publicp:1; // exportp without publicp is not allowed.
uint8_t deprecated:2; // 0=not deprecated, 1=renamed, 2=moved to another package
uint8_t padding:3;
uint8_t did_print_implicit_import_admonition:1;
uint8_t padding:2;
} jl_binding_t;

typedef struct {
Expand Down
10 changes: 7 additions & 3 deletions src/module.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ static jl_binding_t *new_binding(jl_module_t *mod, jl_sym_t *name)
b->publicp = 0;
b->deprecated = 0;
b->did_print_backdate_admonition = 0;
b->did_print_implicit_import_admonition = 0;
JL_GC_PUSH1(&b);
b->globalref = jl_new_globalref(mod, name, b);
jl_gc_wb(b, b->globalref);
Expand Down Expand Up @@ -537,14 +538,14 @@ JL_DLLEXPORT jl_module_t *jl_get_module_of_binding(jl_module_t *m, jl_sym_t *var

static NOINLINE void print_backdate_admonition(jl_binding_t *b) JL_NOTSAFEPOINT
{
b->did_print_backdate_admonition = 1;
jl_safe_printf(
"WARNING: Detected access to binding `%s.%s` in a world prior to its definition world.\n"
" Julia 1.12 has introduced more strict world age semantics for global bindings.\n"
" !!! This code may malfunction under Revise.\n"
" !!! This code will error in future versions of Julia.\n"
"Hint: Add an appropriate `invokelatest` around the access to this binding.\n",
jl_symbol_name(b->globalref->mod->name), jl_symbol_name(b->globalref->name));
b->did_print_backdate_admonition = 1;
}

static inline void check_backdated_binding(jl_binding_t *b, enum jl_partition_kind kind) JL_NOTSAFEPOINT
Expand Down Expand Up @@ -696,10 +697,12 @@ JL_DLLEXPORT jl_binding_t *jl_get_binding_for_method_def(jl_module_t *m, jl_sym_
else if (kind != BINDING_KIND_IMPORTED) {
int should_error = strcmp(jl_symbol_name(var), "=>") == 0;
jl_module_t *from = jl_binding_dbgmodule(b, m, var);
if (should_error)
if (should_error) {
jl_errorf("invalid method definition in %s: function %s.%s must be explicitly imported to be extended",
jl_module_debug_name(m), jl_module_debug_name(from), jl_symbol_name(var));
else
}
else if (!b->did_print_implicit_import_admonition) {
b->did_print_implicit_import_admonition = 1;
jl_printf(JL_STDERR, "WARNING: Constructor for type \"%s\" was extended in `%s` without explicit qualification or import.\n"
" NOTE: Assumed \"%s\" refers to `%s.%s`. This behavior is deprecated and may differ in future versions.`\n"
" NOTE: This behavior may have differed in Julia versions prior to 1.12.\n"
Expand All @@ -709,6 +712,7 @@ JL_DLLEXPORT jl_binding_t *jl_get_binding_for_method_def(jl_module_t *m, jl_sym_
jl_symbol_name(var), jl_module_debug_name(from), jl_symbol_name(var),
jl_symbol_name(var), jl_symbol_name(var), jl_module_debug_name(from), jl_symbol_name(var),
jl_module_debug_name(from), jl_symbol_name(var));
}
}
return ownerb;
}
Expand Down

0 comments on commit 6b39a81

Please sign in to comment.