@@ -301,7 +301,7 @@ struct implicit_search_resolution jl_resolve_implicit_import(jl_binding_t *b, mo
301
301
imp_resolution .binding_or_const = tempbpart -> restriction ;
302
302
imp_resolution .debug_only_ultimate_binding = (jl_binding_t * )tempbpart -> restriction ;
303
303
imp_resolution .ultimate_kind = PARTITION_KIND_IMPLICIT_GLOBAL ;
304
- } else if (kind == PARTITION_KIND_GLOBAL || kind == PARTITION_KIND_DECLARED || kind == PARTITION_KIND_BACKDATED_CONST ) {
304
+ } else if (kind == PARTITION_KIND_GLOBAL || kind == PARTITION_KIND_DECLARED ) {
305
305
imp_resolution .binding_or_const = (jl_value_t * )tempb ;
306
306
imp_resolution .debug_only_ultimate_binding = tempb ;
307
307
imp_resolution .ultimate_kind = PARTITION_KIND_IMPLICIT_GLOBAL ;
@@ -595,50 +595,6 @@ JL_DLLEXPORT jl_binding_partition_t *jl_declare_constant_val3(
595
595
} else {
596
596
new_bpart = jl_replace_binding_locked (b , bpart , val , constant_kind , new_world );
597
597
}
598
- int need_backdate = new_world && val ;
599
- if (need_backdate ) {
600
- // We will backdate as long as this partition was never explicitly
601
- // declared const, global, or imported.
602
- jl_binding_partition_t * prev_bpart = bpart ;
603
- for (;;) {
604
- enum jl_partition_kind prev_kind = jl_binding_kind (prev_bpart );
605
- if (jl_bkind_is_some_constant (prev_kind ) || prev_kind == PARTITION_KIND_GLOBAL ||
606
- jl_bkind_is_some_import (prev_kind )) {
607
- need_backdate = 0 ;
608
- break ;
609
- }
610
- size_t prev_bpart_min_world = jl_atomic_load_relaxed (& prev_bpart -> min_world );
611
- if (prev_bpart_min_world == 0 )
612
- break ;
613
- prev_bpart = jl_get_binding_partition (b , prev_bpart_min_world - 1 );
614
- }
615
- }
616
- // If backdate is required, replace each existing partition by a new one.
617
- // We can't use one binding to cover the entire range, because we need to
618
- // keep the flags partitioned.
619
- if (need_backdate ) {
620
- jl_binding_partition_t * prev_bpart = bpart ;
621
- jl_binding_partition_t * backdate_bpart = new_binding_partition ();
622
- new_prev_bpart = backdate_bpart ;
623
- while (1 ) {
624
- backdate_bpart -> kind = (size_t )PARTITION_KIND_BACKDATED_CONST | (prev_bpart -> kind & 0xf0 );
625
- backdate_bpart -> restriction = val ;
626
- jl_atomic_store_relaxed (& backdate_bpart -> min_world ,
627
- jl_atomic_load_relaxed (& prev_bpart -> min_world ));
628
- jl_gc_wb_fresh (backdate_bpart , val );
629
- jl_atomic_store_relaxed (& backdate_bpart -> max_world ,
630
- jl_atomic_load_relaxed (& prev_bpart -> max_world ));
631
- prev_bpart = jl_atomic_load_relaxed (& prev_bpart -> next );
632
- if (!prev_bpart )
633
- break ;
634
- jl_binding_partition_t * next_prev_bpart = new_binding_partition ();
635
- jl_atomic_store_relaxed (& backdate_bpart -> next , next_prev_bpart );
636
- jl_gc_wb (backdate_bpart , next_prev_bpart );
637
- backdate_bpart = next_prev_bpart ;
638
- }
639
- jl_atomic_store_release (& new_bpart -> next , new_prev_bpart );
640
- jl_gc_wb (new_bpart , new_prev_bpart );
641
- }
642
598
}
643
599
JL_GC_POP ();
644
600
return new_bpart ;
@@ -866,29 +822,6 @@ JL_DLLEXPORT jl_module_t *jl_get_module_of_binding(jl_module_t *m, jl_sym_t *var
866
822
return b ? b -> globalref -> mod : m ;
867
823
}
868
824
869
- static NOINLINE void print_backdate_admonition (jl_binding_t * b ) JL_NOTSAFEPOINT
870
- {
871
- jl_safe_printf (
872
- "WARNING: Detected access to binding `%s.%s` in a world prior to its definition world.\n"
873
- " Julia 1.12 has introduced more strict world age semantics for global bindings.\n"
874
- " !!! This code may malfunction under Revise.\n"
875
- " !!! This code will error in future versions of Julia.\n"
876
- "Hint: Add an appropriate `invokelatest` around the access to this binding.\n"
877
- "To make this warning an error, and hence obtain a stack trace, use `julia --depwarn=error`.\n" ,
878
- jl_symbol_name (b -> globalref -> mod -> name ), jl_symbol_name (b -> globalref -> name ));
879
- }
880
-
881
- static inline void check_backdated_binding (jl_binding_t * b , enum jl_partition_kind kind ) JL_NOTSAFEPOINT
882
- {
883
- if (__unlikely (kind == PARTITION_KIND_BACKDATED_CONST )) {
884
- // We don't want functions that inference executes speculatively to print this warning, so turn those into
885
- // an error for inference purposes.
886
- if (jl_current_task -> ptls -> in_pure_callback || jl_options .depwarn == JL_OPTIONS_DEPWARN_ERROR )
887
- jl_undefined_var_error (b -> globalref -> name , (jl_value_t * )b -> globalref -> mod );
888
- if (!(jl_atomic_fetch_or_relaxed (& b -> flags , BINDING_FLAG_DID_PRINT_BACKDATE_ADMONITION ) & BINDING_FLAG_DID_PRINT_BACKDATE_ADMONITION ))
889
- print_backdate_admonition (b );
890
- }
891
- }
892
825
893
826
JL_DLLEXPORT jl_value_t * jl_get_binding_value (jl_binding_t * b )
894
827
{
@@ -900,10 +833,19 @@ JL_DLLEXPORT jl_value_t *jl_get_binding_value_in_world(jl_binding_t *b, size_t w
900
833
jl_binding_partition_t * bpart = jl_get_binding_partition (b , world );
901
834
jl_walk_binding_inplace (& b , & bpart , world );
902
835
enum jl_partition_kind kind = jl_binding_kind (bpart );
836
+ if (kind == PARTITION_KIND_GUARD ) {
837
+ // Retry lookup in current world counter for guard partitions (unless in pure callback)
838
+ if (!jl_current_task -> ptls -> in_pure_callback ) {
839
+ size_t current_world = jl_atomic_load_acquire (& jl_world_counter );
840
+ if (current_world != world ) {
841
+ return jl_get_binding_value_in_world (b , current_world );
842
+ }
843
+ }
844
+ return NULL ;
845
+ }
903
846
if (jl_bkind_is_some_guard (kind ))
904
847
return NULL ;
905
848
if (jl_bkind_is_some_constant (kind )) {
906
- check_backdated_binding (b , kind );
907
849
return bpart -> restriction ;
908
850
}
909
851
assert (!jl_bkind_is_some_import (kind ));
@@ -923,10 +865,19 @@ static jl_value_t *jl_get_binding_value_depwarn(jl_binding_t *b, size_t world)
923
865
jl_walk_binding_inplace (& b , & bpart , world );
924
866
}
925
867
enum jl_partition_kind kind = jl_binding_kind (bpart );
868
+ if (kind == PARTITION_KIND_GUARD ) {
869
+ // Retry lookup in current world counter for guard partitions (unless in pure callback)
870
+ if (!jl_current_task -> ptls -> in_pure_callback ) {
871
+ size_t current_world = jl_atomic_load_acquire (& jl_world_counter );
872
+ if (current_world != world ) {
873
+ return jl_get_binding_value_depwarn (b , current_world );
874
+ }
875
+ }
876
+ return NULL ;
877
+ }
926
878
if (jl_bkind_is_some_guard (kind ))
927
879
return NULL ;
928
880
if (jl_bkind_is_some_constant (kind )) {
929
- check_backdated_binding (b , kind );
930
881
return bpart -> restriction ;
931
882
}
932
883
assert (!jl_bkind_is_some_import (kind ));
@@ -939,10 +890,19 @@ JL_DLLEXPORT jl_value_t *jl_get_binding_value_seqcst(jl_binding_t *b)
939
890
jl_binding_partition_t * bpart = jl_get_binding_partition (b , world );
940
891
jl_walk_binding_inplace (& b , & bpart , world );
941
892
enum jl_partition_kind kind = jl_binding_kind (bpart );
893
+ if (kind == PARTITION_KIND_GUARD ) {
894
+ // Retry lookup in current world counter for guard partitions (unless in pure callback)
895
+ if (!jl_current_task -> ptls -> in_pure_callback ) {
896
+ size_t current_world = jl_atomic_load_acquire (& jl_world_counter );
897
+ if (current_world != world ) {
898
+ return jl_get_binding_value_in_world (b , current_world );
899
+ }
900
+ }
901
+ return NULL ;
902
+ }
942
903
if (jl_bkind_is_some_guard (kind ))
943
904
return NULL ;
944
905
if (jl_bkind_is_some_constant (kind )) {
945
- check_backdated_binding (b , kind );
946
906
return bpart -> restriction ;
947
907
}
948
908
assert (!jl_bkind_is_some_import (kind ));
@@ -1478,13 +1438,34 @@ JL_DLLEXPORT int jl_boundp(jl_module_t *m, jl_sym_t *var, int allow_import) // u
1478
1438
jl_walk_binding_inplace (& b , & bpart , jl_current_task -> world_age );
1479
1439
}
1480
1440
enum jl_partition_kind kind = jl_binding_kind (bpart );
1441
+ if (kind == PARTITION_KIND_GUARD ) {
1442
+ // Retry lookup in current world counter for guard partitions (unless in pure callback)
1443
+ if (!jl_current_task -> ptls -> in_pure_callback ) {
1444
+ size_t current_world = jl_atomic_load_acquire (& jl_world_counter );
1445
+ if (current_world != jl_current_task -> world_age ) {
1446
+ jl_binding_partition_t * current_bpart = jl_get_binding_partition (b , current_world );
1447
+ if (!current_bpart )
1448
+ return 0 ;
1449
+ if (!allow_import ) {
1450
+ if (!current_bpart || jl_bkind_is_some_import (jl_binding_kind (current_bpart )))
1451
+ return 0 ;
1452
+ } else {
1453
+ jl_walk_binding_inplace (& b , & current_bpart , current_world );
1454
+ }
1455
+ enum jl_partition_kind current_kind = jl_binding_kind (current_bpart );
1456
+ if (jl_bkind_is_some_guard (current_kind ))
1457
+ return 0 ;
1458
+ if (jl_bkind_is_defined_constant (current_kind )) {
1459
+ return 1 ;
1460
+ }
1461
+ return jl_atomic_load (& b -> value ) != NULL ;
1462
+ }
1463
+ }
1464
+ return 0 ;
1465
+ }
1481
1466
if (jl_bkind_is_some_guard (kind ))
1482
1467
return 0 ;
1483
1468
if (jl_bkind_is_defined_constant (kind )) {
1484
- if (__unlikely (kind == PARTITION_KIND_BACKDATED_CONST )) {
1485
- return !(jl_current_task -> ptls -> in_pure_callback || jl_options .depwarn == JL_OPTIONS_DEPWARN_ERROR );
1486
- }
1487
- // N.B.: No backdated admonition for isdefined
1488
1469
return 1 ;
1489
1470
}
1490
1471
return jl_atomic_load (& b -> value ) != NULL ;
0 commit comments