@@ -241,6 +241,7 @@ static jl_binding_t *new_binding(jl_module_t *mod, jl_sym_t *name)
241
241
b -> exportp = 0 ;
242
242
b -> publicp = 0 ;
243
243
b -> deprecated = 0 ;
244
+ b -> did_print_backdate_admonition = 0 ;
244
245
JL_GC_PUSH1 (& b );
245
246
b -> globalref = jl_new_globalref (mod , name , b );
246
247
jl_gc_wb (b , b -> globalref );
@@ -322,36 +323,64 @@ JL_DLLEXPORT jl_module_t *jl_get_module_of_binding(jl_module_t *m, jl_sym_t *var
322
323
return b -> globalref -> mod ; // TODO: deprecate this?
323
324
}
324
325
326
+ static NOINLINE void print_backdate_admonition (jl_binding_t * b )
327
+ {
328
+ jl_printf (JL_STDERR ,
329
+ "WARNING: Detected access to binding `%s.%s` in a world prior to its definition world.\n"
330
+ " Julia 1.12 has introduced more strict world age semantics for global bindings.\n"
331
+ " !!! This code may malfunction under Revise.\n"
332
+ " !!! This code will error in future versions of Julia.\n"
333
+ "Hint: Add an appropriate `invokelatest` around the access to this binding.\n" ,
334
+ jl_symbol_name (b -> globalref -> mod -> name ), jl_symbol_name (b -> globalref -> name ));
335
+ b -> did_print_backdate_admonition = 1 ;
336
+ }
337
+
338
+ static inline void check_backdated_binding (jl_binding_t * b , enum jl_partition_kind kind )
339
+ {
340
+ if (__unlikely (kind == BINDING_KIND_BACKDATED_CONST ) &&
341
+ !b -> did_print_backdate_admonition ) {
342
+ print_backdate_admonition (b );
343
+ }
344
+ }
345
+
325
346
JL_DLLEXPORT jl_value_t * jl_get_binding_value (jl_binding_t * b )
326
347
{
327
348
jl_binding_partition_t * bpart = jl_get_binding_partition (b , jl_current_task -> world_age );
328
349
jl_ptr_kind_union_t pku = jl_walk_binding_inplace (& b , & bpart , jl_current_task -> world_age );
329
- if (jl_bkind_is_some_guard (decode_restriction_kind (pku )))
350
+ enum jl_partition_kind kind = decode_restriction_kind (pku );
351
+ if (jl_bkind_is_some_guard (kind ))
330
352
return NULL ;
331
- if (jl_bkind_is_some_constant (decode_restriction_kind (pku )))
353
+ if (jl_bkind_is_some_constant (kind )) {
354
+ check_backdated_binding (b , kind );
332
355
return decode_restriction_value (pku );
356
+ }
333
357
return jl_atomic_load_relaxed (& b -> value );
334
358
}
335
359
336
360
JL_DLLEXPORT jl_value_t * jl_get_binding_value_seqcst (jl_binding_t * b )
337
361
{
338
362
jl_binding_partition_t * bpart = jl_get_binding_partition (b , jl_current_task -> world_age );
339
363
jl_ptr_kind_union_t pku = jl_walk_binding_inplace (& b , & bpart , jl_current_task -> world_age );
340
- if (jl_bkind_is_some_guard (decode_restriction_kind (pku )))
364
+ enum jl_partition_kind kind = decode_restriction_kind (pku );
365
+ if (jl_bkind_is_some_guard (kind ))
341
366
return NULL ;
342
- if (jl_bkind_is_some_constant (decode_restriction_kind (pku )))
367
+ if (jl_bkind_is_some_constant (kind )) {
368
+ check_backdated_binding (b , kind );
343
369
return decode_restriction_value (pku );
370
+ }
344
371
return jl_atomic_load (& b -> value );
345
372
}
346
373
347
374
JL_DLLEXPORT jl_value_t * jl_get_binding_value_if_const (jl_binding_t * b )
348
375
{
349
376
jl_binding_partition_t * bpart = jl_get_binding_partition (b , jl_current_task -> world_age );
350
377
jl_ptr_kind_union_t pku = jl_walk_binding_inplace (& b , & bpart , jl_current_task -> world_age );
351
- if (jl_bkind_is_some_guard (decode_restriction_kind (pku )))
378
+ enum jl_partition_kind kind = decode_restriction_kind (pku );
379
+ if (jl_bkind_is_some_guard (kind ))
352
380
return NULL ;
353
- if (!jl_bkind_is_some_constant (decode_restriction_kind ( pku ) ))
381
+ if (!jl_bkind_is_some_constant (kind ))
354
382
return NULL ;
383
+ check_backdated_binding (b , kind );
355
384
return decode_restriction_value (pku );
356
385
}
357
386
@@ -368,10 +397,12 @@ JL_DLLEXPORT jl_value_t *jl_get_binding_value_if_resolved_and_const(jl_binding_t
368
397
if (bpart -> min_world > jl_current_task -> world_age || jl_current_task -> world_age > max_world )
369
398
return NULL ;
370
399
jl_ptr_kind_union_t pku = jl_atomic_load_relaxed (& bpart -> restriction );
371
- if (jl_bkind_is_some_guard (decode_restriction_kind (pku )))
400
+ enum jl_partition_kind kind = decode_restriction_kind (pku );
401
+ if (jl_bkind_is_some_guard (kind ))
372
402
return NULL ;
373
- if (!jl_bkind_is_some_constant (decode_restriction_kind ( pku ) ))
403
+ if (!jl_bkind_is_some_constant (kind ))
374
404
return NULL ;
405
+ check_backdated_binding (b , kind );
375
406
return decode_restriction_value (pku );
376
407
}
377
408
@@ -388,12 +419,15 @@ JL_DLLEXPORT jl_value_t *jl_get_binding_value_if_resolved(jl_binding_t *b)
388
419
if (bpart -> min_world > jl_current_task -> world_age || jl_current_task -> world_age > max_world )
389
420
return NULL ;
390
421
jl_ptr_kind_union_t pku = jl_atomic_load_relaxed (& bpart -> restriction );
391
- if (jl_bkind_is_some_guard (decode_restriction_kind (pku )))
422
+ enum jl_partition_kind kind = decode_restriction_kind (pku );
423
+ if (jl_bkind_is_some_guard (kind ))
392
424
return NULL ;
393
- if (jl_bkind_is_some_import (decode_restriction_kind ( pku ) ))
425
+ if (jl_bkind_is_some_import (kind ))
394
426
return NULL ;
395
- if (jl_bkind_is_some_constant (decode_restriction_kind (pku )))
427
+ if (jl_bkind_is_some_constant (kind )) {
428
+ check_backdated_binding (b , kind );
396
429
return decode_restriction_value (pku );
430
+ }
397
431
return jl_atomic_load_relaxed (& b -> value );
398
432
}
399
433
@@ -895,13 +929,26 @@ JL_DLLEXPORT int jl_boundp(jl_module_t *m, jl_sym_t *var, int allow_import) // u
895
929
jl_binding_t * b = jl_get_module_binding (m , var , allow_import );
896
930
if (!b )
897
931
return 0 ;
932
+ jl_binding_partition_t * bpart = jl_get_binding_partition (b , jl_current_task -> world_age );
933
+ if (!bpart )
934
+ return 0 ;
935
+ jl_ptr_kind_union_t pku = jl_atomic_load_relaxed (& bpart -> restriction );
898
936
if (!allow_import ) {
899
- jl_binding_partition_t * bpart = jl_get_binding_partition (b , jl_current_task -> world_age );
900
- if (!bpart || jl_bkind_is_some_import (decode_restriction_kind (jl_atomic_load_relaxed (& bpart -> restriction ))))
937
+ if (!bpart || jl_bkind_is_some_import (decode_restriction_kind (pku )))
901
938
return 0 ;
902
- return jl_get_binding_value (b ) != NULL ;
939
+ } else {
940
+ if (jl_bkind_is_some_guard (decode_restriction_kind (pku ))) {
941
+ jl_resolve_owner (b , b -> globalref -> mod , b -> globalref -> name , NULL , jl_current_task -> world_age );
942
+ }
943
+ pku = jl_walk_binding_inplace (& b , & bpart , jl_current_task -> world_age );
944
+ }
945
+ if (jl_bkind_is_some_guard (decode_restriction_kind (pku )))
946
+ return 0 ;
947
+ if (jl_bkind_is_some_constant (decode_restriction_kind (pku ))) {
948
+ // N.B.: No backdated check for isdefined
949
+ return 1 ;
903
950
}
904
- return jl_reresolve_binding_value_seqcst ( b ) != NULL ;
951
+ return jl_atomic_load ( & b -> value ) != NULL ;
905
952
}
906
953
907
954
JL_DLLEXPORT int jl_defines_or_exports_p (jl_module_t * m , jl_sym_t * var )
0 commit comments