Skip to content

Commit 235a7de

Browse files
KenoKristofferC
authored andcommitted
module: Tweak backdate-warning-turned error (#58651)
This makes two changes to the backdate-warning-turned-error (#58266): 1. Fix a bug where the error would only trigger the first time. We do only want to print once per process, but of course, we do want to error every time if enabled. 2. If we are in speculative execution context (generators and speculatively run functions during inference), always use the UndefVarError. Effects from these functions are not supposed to be observable, and it's very confusing if the printed warning goes away when depwarns are enabled. This is marginally more breaking, but the burden is on generated function authors (which already have to be world-age aware and are somewhat more regularly broken) and is consistent with other things that are stronger errors in pure context. Fixes #58648 (cherry picked from commit d2cc061)
1 parent 31bc1b7 commit 235a7de

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/module.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -846,8 +846,6 @@ JL_DLLEXPORT jl_module_t *jl_get_module_of_binding(jl_module_t *m, jl_sym_t *var
846846

847847
static NOINLINE void print_backdate_admonition(jl_binding_t *b) JL_NOTSAFEPOINT
848848
{
849-
if (jl_options.depwarn == JL_OPTIONS_DEPWARN_ERROR)
850-
jl_undefined_var_error(b->globalref->name, (jl_value_t*)b->globalref->mod);
851849
jl_safe_printf(
852850
"WARNING: Detected access to binding `%s.%s` in a world prior to its definition world.\n"
853851
" Julia 1.12 has introduced more strict world age semantics for global bindings.\n"
@@ -860,9 +858,13 @@ static NOINLINE void print_backdate_admonition(jl_binding_t *b) JL_NOTSAFEPOINT
860858

861859
static inline void check_backdated_binding(jl_binding_t *b, enum jl_partition_kind kind) JL_NOTSAFEPOINT
862860
{
863-
if (__unlikely(kind == PARTITION_KIND_BACKDATED_CONST) &&
864-
!(jl_atomic_fetch_or_relaxed(&b->flags, BINDING_FLAG_DID_PRINT_BACKDATE_ADMONITION) & BINDING_FLAG_DID_PRINT_BACKDATE_ADMONITION)) {
865-
print_backdate_admonition(b);
861+
if (__unlikely(kind == PARTITION_KIND_BACKDATED_CONST)) {
862+
// We don't want functions that inference executes speculatively to print this warning, so turn those into
863+
// an error for inference purposes.
864+
if (jl_current_task->ptls->in_pure_callback || jl_options.depwarn == JL_OPTIONS_DEPWARN_ERROR)
865+
jl_undefined_var_error(b->globalref->name, (jl_value_t*)b->globalref->mod);
866+
if (!(jl_atomic_fetch_or_relaxed(&b->flags, BINDING_FLAG_DID_PRINT_BACKDATE_ADMONITION) & BINDING_FLAG_DID_PRINT_BACKDATE_ADMONITION))
867+
print_backdate_admonition(b);
866868
}
867869
}
868870

0 commit comments

Comments
 (0)