Repository navigation
Expand file tree
/
Copy pathmodule.c
More file actions
2533 lines (2327 loc) · 109 KB
/
Copy pathmodule.c
File metadata and controls
2533 lines (2327 loc) · 109 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// This file is a part of Julia. License is MIT: https://julialang.org/license
//
/*
modules and top-level bindings
*/
#include "julia.h"
#include "julia_internal.h"
#include "julia_assert.h"
#ifdef __cplusplus
extern "C" {
#endif
// A fresh partition is the last (oldest) in its chain, so its `next` field holds
// a backreference to the owning binding rather than another partition. Callers
// that link it ahead of another partition overwrite this.
static jl_binding_partition_t *new_binding_partition(jl_binding_t *b) JL_CANSAFEPOINT
{
jl_binding_partition_t *bpart = (jl_binding_partition_t*)jl_gc_alloc(jl_current_task->ptls, sizeof(jl_binding_partition_t), jl_binding_partition_type);
bpart->restriction = NULL;
bpart->kind = (size_t)PARTITION_KIND_GUARD;
jl_atomic_store_relaxed(&bpart->min_world, 0);
jl_atomic_store_relaxed(&bpart->max_world, (size_t)-1);
jl_gc_write_atomic_fresh(bpart, bpart->next, jl_binding_partition_t, (jl_binding_partition_t*)b, relaxed);
return bpart;
}
// Whether `p`, a value loaded from a partition's `next` field (or a binding's
// `partitions` field), refers to an actual partition, as opposed to NULL (an
// empty chain) or the owning-binding backreference stored in the last partition
// of a chain.
STATIC_INLINE int is_some_partition(jl_binding_partition_t *p) JL_NOTSAFEPOINT
{
return p != NULL && jl_is_binding_partition((jl_value_t*)p);
}
// Recover the `jl_binding_t` that owns `bpart` by walking the chain to its end:
// the last (oldest) partition's `next` is a backreference to the owning binding.
JL_DLLEXPORT jl_binding_t *jl_binding_partition_owner(jl_binding_partition_t *bpart JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT
{
jl_binding_partition_t *next = jl_atomic_load_relaxed(&bpart->next);
while (is_some_partition(next)) {
bpart = next;
next = jl_atomic_load_relaxed(&bpart->next);
}
return (jl_binding_t*)next;
}
struct implicit_search_gap {
_Atomic(jl_binding_partition_t *) *insert;
jl_binding_partition_t *replace;
jl_value_t *parent;
size_t min_world;
size_t max_world;
size_t inherited_flags;
};
STATIC_INLINE jl_binding_partition_t *jl_get_binding_partition__(jl_binding_t *b JL_PROPAGATES_ROOT, size_t world, struct implicit_search_gap *gap) JL_GLOBALLY_ROOTED
{
// Iterate through the list of binding partitions, keeping track of where to insert a new one for an implicit
// resolution if necessary.
while (is_some_partition(gap->replace)) {
size_t replace_min_world = jl_atomic_load_relaxed(&gap->replace->min_world);
if (world >= replace_min_world)
break;
gap->insert = &gap->replace->next;
gap->max_world = replace_min_world - 1;
gap->parent = (jl_value_t*)gap->replace;
// The last partition's `next` is the owning-binding backreference, so
// `gap->replace` becomes that binding (not a partition) at end-of-chain.
gap->replace = jl_atomic_load_relaxed(gap->insert);
}
if (is_some_partition(gap->replace) && world <= jl_atomic_load_relaxed(&gap->replace->max_world)) {
return gap->replace;
}
gap->min_world = is_some_partition(gap->replace) ? jl_atomic_load_relaxed(&gap->replace->max_world) + 1 : 0;
if (is_some_partition(gap->replace))
gap->inherited_flags = gap->replace->kind & PARTITION_MASK_FLAG;
else
gap->inherited_flags = 0;
return NULL;
}
STATIC_INLINE jl_binding_partition_t *jl_get_binding_partition_if_present(jl_binding_t *b JL_PROPAGATES_ROOT, size_t world, struct implicit_search_gap *gap)
{
gap->parent = (jl_value_t*)b;
gap->insert = &b->partitions;
gap->replace = jl_atomic_load_relaxed(gap->insert);
gap->min_world = 0;
gap->max_world = ~(size_t)0;
gap->inherited_flags = 0;
return jl_get_binding_partition__(b, world, gap);
}
struct implicit_search_resolution {
enum jl_partition_kind ultimate_kind;
jl_value_t *binding_or_const;
size_t min_world;
size_t max_world;
int saw_cycle;
int should_be_reexported; // Set if resolved through a using with JL_MODULE_USING_REEXPORT
//// Not semantic, but used for reflection.
// If non-null, the unique module from which this binding was imported
jl_module_t *debug_only_import_from;
// If non-null, the unique binding imported. For PARTITION_KIND_IMPLICIT_GLOBAL, always matches binding_or_const.
// Must have trust_cache = 0.
jl_binding_t *debug_only_ultimate_binding;
// Deprecation flags (PARTITION_FLAG_DEPRECATED / _DEPWARN, together with
// _IMPLICITLY_DEPRECATED to mark their provenance) to set on the resolved
// partition. A deprecated constant imported through `using` resolves to IMPLICIT_CONST
// (its value), so -- unlike a deprecated global, whose flag lives on the leaf the depwarn
// walk reaches -- there is no leaf to carry the deprecation. Recording it here and OR-ing
// it onto the importer's partition lets the walk (and `isdeprecated`)
// find it directly on the resolved partition, so access through `using` warns consistently
// for constants and globals. It is OR-ed together when constants unify.
size_t deprecation_flags;
};
static const size_t DEPWARN_FLAGS = PARTITION_FLAG_DEPRECATED | PARTITION_FLAG_DEPWARN | PARTITION_FLAG_IMPLICITLY_DEPRECATED;
// Flags to carry over when replacing a partition. Deprecation set by implicit resolution
// belongs to the imported binding, so it does not survive replacement; explicitly set
// deprecation does.
size_t jl_carried_binding_flags(jl_binding_partition_t *bpart) JL_NOTSAFEPOINT
{
size_t flags = bpart->kind & PARTITION_MASK_FLAG;
if (flags & PARTITION_FLAG_IMPLICITLY_DEPRECATED)
flags &= ~DEPWARN_FLAGS;
return flags;
}
static size_t WORLDMAX(size_t a, size_t b) { return a > b ? a : b; }
static size_t WORLDMIN(size_t a, size_t b) { return a > b ? b : a; }
static void update_implicit_resolution(struct implicit_search_resolution *to_update, struct implicit_search_resolution resolution)
{
to_update->min_world = WORLDMAX(to_update->min_world, resolution.min_world);
to_update->max_world = WORLDMIN(to_update->max_world, resolution.max_world);
to_update->saw_cycle |= resolution.saw_cycle;
to_update->should_be_reexported |= resolution.should_be_reexported;
if (resolution.ultimate_kind == PARTITION_FAKE_KIND_CYCLE) {
// Cycles get ignored. This causes the resolution to only be partial, so we can't
// cache it. This gets tracked in saw_cycle;
to_update->saw_cycle = 1;
return;
}
if (resolution.ultimate_kind == PARTITION_KIND_GUARD) {
// Ignore guard imports
return;
}
if (to_update->ultimate_kind == PARTITION_KIND_GUARD) {
to_update->ultimate_kind = resolution.ultimate_kind;
to_update->binding_or_const = resolution.binding_or_const;
to_update->deprecation_flags = resolution.deprecation_flags;
to_update->debug_only_import_from = resolution.debug_only_import_from;
to_update->debug_only_ultimate_binding = resolution.debug_only_ultimate_binding;
return;
}
int same;
if (resolution.ultimate_kind != to_update->ultimate_kind) {
same = 0;
}
else if (resolution.ultimate_kind == PARTITION_KIND_IMPLICIT_CONST) {
// Unify constants by `egal`
same = jl_egal(resolution.binding_or_const, to_update->binding_or_const);
}
else {
same = resolution.binding_or_const == to_update->binding_or_const;
}
if (same) {
// Deprecation is weak: unified constants are deprecated only if every contributing
// import was (`impstate`/`depimpstate` keep deprecated and non-deprecated resolutions
// apart, so this only OR-s together same-strength imports).
to_update->deprecation_flags |= resolution.deprecation_flags;
if (resolution.debug_only_import_from != to_update->debug_only_import_from) {
to_update->debug_only_import_from = NULL;
}
if (resolution.debug_only_ultimate_binding != to_update->debug_only_ultimate_binding) {
to_update->debug_only_ultimate_binding = NULL;
}
return;
}
to_update->ultimate_kind = PARTITION_KIND_FAILED;
to_update->binding_or_const = NULL;
to_update->deprecation_flags = 0;
to_update->debug_only_import_from = NULL;
to_update->debug_only_ultimate_binding = NULL;
}
static jl_binding_partition_t *jl_implicit_import_resolved(jl_binding_t *b, struct implicit_search_gap gap, struct implicit_search_resolution resolution) JL_CANSAFEPOINT
{
// The deprecation flags come from the resolution (the imported binding), not from the
// importer's own inherited flags, so a stale deprecation from a prior resolution of this
// binding does not persist across a re-resolution (e.g. after the source is un-deprecated).
size_t new_kind = resolution.ultimate_kind | (gap.inherited_flags & ~DEPWARN_FLAGS) | resolution.deprecation_flags;
// If the resolution indicates this should be reexported, add the implicit export flag
if (resolution.should_be_reexported) {
new_kind |= PARTITION_FLAG_IMPLICITLY_EXPORTED;
}
size_t new_max_world = gap.max_world < resolution.max_world ? gap.max_world : resolution.max_world;
size_t new_min_world = gap.min_world > resolution.min_world ? gap.min_world : resolution.min_world;
jl_binding_partition_t *next = gap.replace;
if (jl_is_binding_partition(gap.parent)) {
// Check if we can merge this into the previous binding partition
jl_binding_partition_t *prev = (jl_binding_partition_t *)gap.parent;
assert(new_max_world != ~(size_t)0); // It is inconsistent to have a gap with `gap.parent` set, but max_world == ~(size_t)0
size_t expected_prev_min_world = new_max_world + 1;
if (prev->restriction == resolution.binding_or_const && prev->kind == new_kind) {
retry:
if (!jl_atomic_cmpswap(&prev->min_world, &expected_prev_min_world, new_min_world)) {
if (expected_prev_min_world <= new_min_world) {
return prev;
}
else if (expected_prev_min_world <= new_max_world) {
// Concurrent modification of the partition. However, our lookup is still valid,
// so we should still be able to extend the partition.
goto retry;
}
// There remains a gap - proceed
} else {
if (is_some_partition(next)) {
size_t next_min_world = jl_atomic_load_relaxed(&next->min_world);
expected_prev_min_world = new_min_world;
for (;;) {
// We've updated the previous partition - check if we've closed a gap
size_t next_max_world = jl_atomic_load_relaxed(&next->max_world);
if (next_max_world >= expected_prev_min_world-1 && next->kind == new_kind && next->restriction == resolution.binding_or_const) {
if (jl_atomic_cmpswap(&prev->min_world, &expected_prev_min_world, next_min_world)) {
jl_binding_partition_t *nextnext = jl_atomic_load_relaxed(&next->next);
jl_gc_wb(prev, (void*)&prev->next, nextnext);
if (!jl_atomic_cmpswap(&prev->next, &next, nextnext)) {
// `next` may have been merged into its subsequent partition - we need to retry
assert(is_some_partition(next));
continue;
}
// N.B.: This can lose modifications to next->{min_world, next}.
// However, those modifications could only have been for another implicit
// partition, so we are ok to lose them and recompute them later if necessary.
}
assert(expected_prev_min_world <= new_min_world);
}
break;
}
}
return prev;
}
}
}
jl_binding_partition_t *new_bpart = new_binding_partition(b);
jl_atomic_store_relaxed(&new_bpart->max_world, new_max_world);
new_bpart->kind = new_kind;
jl_gc_write_fresh(new_bpart, new_bpart->restriction, jl_value_t, resolution.binding_or_const);
if (is_some_partition(next)) {
// See if we can merge the next partition into this one
size_t next_max_world = jl_atomic_load_relaxed(&next->max_world);
if (next_max_world == new_min_world - 1 && next->kind == new_kind && next->restriction == resolution.binding_or_const) {
// See above for potentially losing modifications to next.
new_min_world = jl_atomic_load_acquire(&next->min_world);
next = jl_atomic_load_relaxed(&next->next);
}
}
jl_atomic_store_relaxed(&new_bpart->min_world, new_min_world);
if (is_some_partition(next))
jl_atomic_store_relaxed(&new_bpart->next, next);
// else `new_bpart` is the last in the chain, so leave its `next` as the
// owning-binding backreference set by `new_binding_partition`.
jl_gc_wb(gap.parent, (void*)gap.insert, new_bpart);
if (!jl_atomic_cmpswap(gap.insert, &gap.replace, new_bpart))
return NULL;
return new_bpart;
}
// find a binding from a module's `usings` list
static struct implicit_search_resolution jl_resolve_implicit_import(jl_binding_t *b, modstack_t *st, size_t world, int trust_cache) JL_CANSAFEPOINT
{
// First check if we've hit a cycle in this resolution
{
modstack_t *tmp = st;
for (; tmp != NULL; tmp = tmp->prev) {
if (tmp->b == b) {
return (struct implicit_search_resolution){ PARTITION_FAKE_KIND_CYCLE, NULL, 0, ~(size_t)0, 1, 0, NULL, NULL, 0 };
}
}
}
jl_module_t *m = b->globalref->mod;
jl_sym_t *var = b->globalref->name;
modstack_t top = { b, st };
struct implicit_search_resolution impstate;
struct implicit_search_resolution depimpstate;
size_t min_world = 0;
size_t max_world = ~(size_t)0;
impstate = depimpstate = (struct implicit_search_resolution){ PARTITION_KIND_GUARD, NULL, min_world, max_world, 0, 0, NULL, NULL, 0 };
JL_LOCK(&m->lock);
int i = (int)module_usings_length(m) - 1;
JL_UNLOCK(&m->lock);
for (; i >= 0 && impstate.ultimate_kind != PARTITION_KIND_FAILED; --i) {
JL_LOCK(&m->lock);
struct _jl_module_using data = *module_usings_getidx(m, i);
JL_UNLOCK(&m->lock);
if (data.min_world > world) {
max_world = WORLDMIN(max_world, data.min_world - 1);
continue;
}
if (data.max_world < world) {
min_world = WORLDMAX(min_world, data.max_world + 1);
continue;
}
min_world = WORLDMAX(min_world, data.min_world);
max_world = WORLDMIN(max_world, data.max_world);
jl_module_t *imp = data.mod;
uint8_t has_reexports = jl_atomic_load_relaxed(&imp->has_reexports);
JL_GC_PROMISE_ROOTED(imp);
jl_binding_t *tempb = jl_get_module_binding(imp, var, 0);
if (!tempb) {
// If the binding has never been allocated, it could not have been marked exported, so
// it is irrelevant for our resolution. We can move on.
// Exception: if this module has reexports, the binding might be reexported from another module,
// so we need to create the binding to trigger implicit resolution
if (!has_reexports)
continue;
tempb = jl_get_module_binding(imp, var, 1); // Create the binding
}
struct implicit_search_gap gap;
jl_binding_partition_t *tempbpart;
tempbpart = jl_get_binding_partition_if_present(tempb, world, &gap);
size_t tempbpart_flags = tempbpart ? (tempbpart->kind & PARTITION_MASK_FLAG) : gap.inherited_flags;
while (tempbpart && jl_bkind_is_some_explicit_import(jl_binding_kind(tempbpart))) {
max_world = WORLDMIN(max_world, jl_atomic_load_relaxed(&tempbpart->max_world));
min_world = WORLDMAX(min_world, jl_atomic_load_relaxed(&tempbpart->min_world));
tempb = (jl_binding_t*)tempbpart->restriction;
tempbpart = jl_get_binding_partition_if_present(tempb, world, &gap);
}
int tempbpart_valid = tempbpart && (trust_cache || !jl_bkind_is_some_implicit(jl_binding_kind(tempbpart)));
size_t tembppart_max_world = tempbpart_valid ? jl_atomic_load_relaxed(&tempbpart->max_world) : gap.max_world;
size_t tembppart_min_world = tempbpart ? WORLDMAX(jl_atomic_load_relaxed(&tempbpart->min_world), gap.min_world) : gap.min_world;
max_world = WORLDMIN(max_world, tembppart_max_world);
min_world = WORLDMAX(min_world, tembppart_min_world);
uint8_t is_any_exported = jl_bpart_is_exported(tempbpart_flags);
if (!is_any_exported && (tempbpart_valid || !has_reexports)) {
// Partition not exported - skip.
continue;
}
struct implicit_search_resolution *comparison = &impstate;
if (impstate.ultimate_kind != PARTITION_KIND_GUARD) {
if (tempbpart_flags & PARTITION_FLAG_DEPRECATED) {
// Deprecated, but we already have a non-deprecated binding for this - skip.
continue;
}
} else if (tempbpart_flags & PARTITION_FLAG_DEPRECATED) {
if (depimpstate.ultimate_kind == PARTITION_KIND_FAILED) {
// We've already decided that the deprecated bindings are ambiguous, so skip this, but
// keep going to look for non-deprecated bindings.
continue;
}
comparison = &depimpstate;
}
struct implicit_search_resolution imp_resolution = { PARTITION_KIND_GUARD, NULL, min_world, max_world, 0, 0, NULL, NULL, 0 };
if (!tempbpart_valid) {
imp_resolution = jl_resolve_implicit_import(tempb, &top, world, trust_cache);
// imp_resolution is the resolution for import into tempb (which may have been cached for tempb
// if we're not in a cycle). `imp_resolution.should_be_reexported` indicates whether the binding
// should be reexported from `imp`, not `m`, so check here.
if (!(tempbpart_flags & PARTITION_FLAG_EXPORTED) && !imp_resolution.should_be_reexported)
continue;
imp_resolution.should_be_reexported = 0;
} else {
enum jl_partition_kind kind = jl_binding_kind(tempbpart);
// Copy the imported binding's deprecation onto the importer's partition,
// marked implicit so it is dropped again if the partition is replaced.
imp_resolution.deprecation_flags = tempbpart_flags & DEPWARN_FLAGS;
if (imp_resolution.deprecation_flags)
imp_resolution.deprecation_flags |= PARTITION_FLAG_IMPLICITLY_DEPRECATED;
if (kind == PARTITION_KIND_IMPLICIT_GLOBAL) {
imp_resolution.binding_or_const = tempbpart->restriction;
imp_resolution.debug_only_ultimate_binding = (jl_binding_t*)tempbpart->restriction;
imp_resolution.ultimate_kind = PARTITION_KIND_IMPLICIT_GLOBAL;
} else if (kind == PARTITION_KIND_GLOBAL || kind == PARTITION_KIND_DECLARED || kind == PARTITION_KIND_BACKDATED_CONST) {
imp_resolution.binding_or_const = (jl_value_t *)tempb;
imp_resolution.debug_only_ultimate_binding = tempb;
imp_resolution.ultimate_kind = PARTITION_KIND_IMPLICIT_GLOBAL;
} else if (jl_bkind_is_defined_constant(kind)) {
assert(tempbpart->restriction);
imp_resolution.binding_or_const = tempbpart->restriction;
imp_resolution.ultimate_kind = PARTITION_KIND_IMPLICIT_CONST;
imp_resolution.debug_only_ultimate_binding = tempb;
} else if (kind == PARTITION_KIND_FAILED) {
imp_resolution.binding_or_const = NULL;
imp_resolution.debug_only_ultimate_binding = tempb;
imp_resolution.ultimate_kind = PARTITION_KIND_FAILED;
}
}
// If this using has the reexport flag, mark that the binding should be reexported
if (data.flags & JL_MODULE_USING_REEXPORT) {
imp_resolution.should_be_reexported = 1;
}
imp_resolution.debug_only_import_from = imp;
update_implicit_resolution(comparison, imp_resolution);
if (!tempbpart && !imp_resolution.saw_cycle) {
// Independent of whether or not we trust the cache, we have independently computed the implicit resolution
// for this import, so we can put it in the cache.
jl_implicit_import_resolved(tempb, gap, imp_resolution);
}
}
if (impstate.ultimate_kind == PARTITION_KIND_GUARD && depimpstate.ultimate_kind != PARTITION_KIND_GUARD) {
depimpstate.min_world = WORLDMAX(depimpstate.min_world, min_world);
depimpstate.max_world = WORLDMIN(depimpstate.max_world, max_world);
return depimpstate;
}
impstate.min_world = WORLDMAX(impstate.min_world, min_world);
impstate.max_world = WORLDMIN(impstate.max_world, max_world);
return impstate;
}
JL_DLLEXPORT jl_binding_partition_t *jl_maybe_reresolve_implicit(jl_binding_t *b, size_t new_max_world) JL_CANSAFEPOINT
{
struct implicit_search_gap gap;
while (1) {
jl_binding_partition_t *bpart = jl_get_binding_partition_if_present(b, new_max_world+1, &gap);
assert(bpart == jl_atomic_load_relaxed(&b->partitions));
assert(bpart);
struct implicit_search_resolution resolution = jl_resolve_implicit_import(b, NULL, new_max_world+1, 0);
int resolution_unchanged = bpart->restriction == resolution.binding_or_const && jl_binding_kind(bpart) == resolution.ultimate_kind &&
(bpart->kind & DEPWARN_FLAGS) == resolution.deprecation_flags;
size_t bpart_min_world = jl_atomic_load_relaxed(&bpart->min_world);
if (resolution.min_world == bpart_min_world) {
// The resolution has the same world bounds - it must be unchanged
assert(resolution_unchanged);
return bpart;
} else if (resolution_unchanged) {
// If the resolution is unchanged, we can still keep the bpart
assert(resolution.min_world > bpart_min_world);
return bpart;
}
assert(resolution.min_world == new_max_world+1 && "Missed an invalidation or bad resolution bounds");
size_t expected_max_world = ~(size_t)0;
if (jl_atomic_cmpswap(&bpart->max_world, &expected_max_world, new_max_world))
{
gap.min_world = new_max_world+1;
gap.inherited_flags = bpart->kind & PARTITION_MASK_FLAG;
jl_binding_partition_t *new_bpart = jl_implicit_import_resolved(b, gap, resolution);
if (new_bpart)
return new_bpart;
}
}
}
JL_DLLEXPORT void jl_update_loaded_bpart(jl_binding_t *b, jl_binding_partition_t *bpart)
{
struct implicit_search_resolution resolution = jl_resolve_implicit_import(b, NULL, jl_atomic_load_acquire(&jl_world_counter), 0);
jl_atomic_store_relaxed(&bpart->min_world, resolution.min_world);
jl_atomic_store_relaxed(&bpart->max_world, resolution.max_world);
jl_gc_write(bpart, bpart->restriction, jl_value_t, resolution.binding_or_const);
bpart->kind = resolution.ultimate_kind | resolution.deprecation_flags;
}
static void jl_walk_binding_inplace(jl_binding_t **bnd, jl_binding_partition_t **pbpart, size_t world) JL_CANSAFEPOINT
{
jl_binding_partition_t *bpart = *pbpart;
while (1) {
enum jl_partition_kind kind = jl_binding_kind(bpart);
if (!jl_bkind_is_some_binding_import(kind))
break;
assert(jl_is_binding(bpart->restriction));
*bnd = (jl_binding_t*)bpart->restriction;
bpart = jl_get_binding_partition(*bnd, world);
}
*pbpart = bpart;
}
// Walk imports to the leaf while reporting whether any partition along the way carries a
// deprecation `flag` (`PARTITION_FLAG_DEPWARN` for the access warning, or
// `PARTITION_FLAG_DEPRECATED` for `isdeprecated`), suppressed once an explicit import is
// passed (the `import`/`using: x` site is what should be fixed).
// `skip_initial` leaves `*pbpart` itself out of that report, for a caller that was handed the
// partition and so owns its deprecation: only what the walk reaches from there is reported.
static void jl_walk_binding_inplace_depwarn(jl_binding_t **bnd, jl_binding_partition_t **pbpart, size_t world, size_t flag, int *found, int skip_initial) JL_CANSAFEPOINT
{
int passed_explicit = 0;
int skip = skip_initial;
jl_binding_partition_t *bpart = *pbpart;
while (1) {
enum jl_partition_kind kind = jl_binding_kind(bpart);
if (!passed_explicit && !skip && found)
*found |= bpart->kind & flag;
skip = 0;
if (!jl_bkind_is_some_binding_import(kind))
break;
if (kind != PARTITION_KIND_IMPLICIT_GLOBAL)
passed_explicit = 1;
assert(jl_is_binding(bpart->restriction)); // as in `jl_walk_binding_inplace`
*bnd = (jl_binding_t*)bpart->restriction;
bpart = jl_get_binding_partition(*bnd, world);
}
*pbpart = bpart;
}
// Walk `(b, bpart)` to the leaf of the access, warning for a deprecation the walk reports.
// `depwarn` selects whether to apply the deprecation rule at all; `skip_initial` is passed
// through, and decides whether `bpart` itself is part of what is reported.
static jl_binding_partition_t *walk_to_leaf_depwarn(jl_binding_t *b, jl_binding_partition_t *bpart, size_t world, int depwarn, int skip_initial) JL_CANSAFEPOINT
{
if (depwarn && jl_options.depwarn) {
int needs_depwarn = 0;
jl_walk_binding_inplace_depwarn(&b, &bpart, world, PARTITION_FLAG_DEPWARN, &needs_depwarn, skip_initial);
if (needs_depwarn)
jl_binding_deprecation_warning(b);
}
else {
jl_walk_binding_inplace(&b, &bpart, world);
}
return bpart;
}
STATIC_INLINE jl_binding_partition_t *jl_get_binding_partition_(jl_binding_t *b JL_PROPAGATES_ROOT, jl_value_t *parent, _Atomic(jl_binding_partition_t *)*insert, size_t world, size_t max_world, modstack_t *st) JL_CANSAFEPOINT JL_GLOBALLY_ROOTED
{
assert(jl_is_binding(b));
struct implicit_search_gap gap;
gap.parent = parent;
gap.insert = insert;
gap.inherited_flags = 0;
gap.min_world = 0;
gap.max_world = max_world;
while (1) {
gap.replace = jl_atomic_load_relaxed(gap.insert);
jl_binding_partition_t *bpart = jl_get_binding_partition__(b, world, &gap);
if (bpart)
return bpart;
struct implicit_search_resolution resolution = jl_resolve_implicit_import(b, NULL, world, 1);
jl_binding_partition_t *new_bpart = jl_implicit_import_resolved(b, gap, resolution);
if (new_bpart)
return new_bpart;
}
}
jl_binding_partition_t *jl_get_binding_partition(jl_binding_t *b, size_t world) {
if (!b)
return NULL;
// Duplicate the code for the entry frame for branch prediction
return jl_get_binding_partition_(b, (jl_value_t*)b, &b->partitions, world, ~(size_t)0, NULL);
}
jl_binding_partition_t *jl_get_binding_partition_with_hint(jl_binding_t *b, jl_binding_partition_t *prev, size_t world) JL_GLOBALLY_ROOTED {
// Helper for getting a binding partition for an older world after we've already looked up the partition for a newer world
assert(b);
size_t prev_min_world = jl_atomic_load_relaxed(&prev->min_world);
return jl_get_binding_partition_(b, (jl_value_t*)prev, &prev->next, world, prev_min_world-1, NULL);
}
JL_DLLEXPORT size_t jl_binding_backedges_length(jl_binding_t *b) JL_CANSAFEPOINT
{
JL_LOCK(&b->globalref->mod->lock);
size_t len = 0;
if (b->backedges)
len = jl_array_len(b->backedges);
JL_UNLOCK(&b->globalref->mod->lock);
return len;
}
JL_DLLEXPORT jl_value_t *jl_binding_backedges_getindex(jl_binding_t *b, size_t i) JL_CANSAFEPOINT
{
JL_LOCK(&b->globalref->mod->lock);
assert(b->backedges);
jl_value_t *ret = jl_array_ptr_ref(b->backedges, i-1);
JL_UNLOCK(&b->globalref->mod->lock);
return ret;
}
static jl_module_t *jl_new_module__(jl_sym_t *name, jl_module_t *parent) JL_CANSAFEPOINT
{
jl_task_t *ct = jl_current_task;
const jl_uuid_t uuid_zero = {0, 0};
jl_module_t *m = (jl_module_t*)jl_gc_alloc(ct->ptls, sizeof(jl_module_t),
jl_module_type);
jl_set_typetagof(m, jl_module_tag, 0);
assert(jl_is_symbol(name));
m->name = name;
m->parent = parent ? parent : m;
m->istopmod = 0;
m->uuid = uuid_zero;
static _Atomic(unsigned int) mcounter; // simple counter backup, in case hrtime is not incrementing
unsigned int count = jl_atomic_fetch_add_relaxed(&mcounter, 1);
// TODO: this is used for ir decompression and is liable to hash collisions so use more of the bits
m->build_id.lo = bitmix(jl_hrtime() + count, jl_rand());
if (!m->build_id.lo)
m->build_id.lo++; // build id 0 is invalid
m->build_id.hi = ~(uint64_t)0;
jl_atomic_store_relaxed(&m->counter, 1);
m->usings_backedges = jl_nothing;
m->scanned_methods = jl_nothing;
m->nospecialize = 0;
m->optlevel = -1;
m->compile = -1;
m->infer = -1;
m->max_methods = -1;
jl_atomic_store_relaxed(&m->has_reexports, 0);
jl_atomic_store_relaxed(&m->export_set_changed_since_require_world, 0);
m->file = jl_empty_sym;
m->line = 0;
m->hash = parent == NULL ? bitmix(name->hash, jl_module_type->hash) :
bitmix(name->hash, parent->hash);
JL_MUTEX_INIT(&m->lock, "module->lock");
jl_atomic_store_relaxed(&m->bindings, jl_emptysvec);
jl_atomic_store_relaxed(&m->bindingkeyset, (jl_genericmemory_t*)jl_an_empty_memory_any);
arraylist_new(&m->usings, 0);
return m;
}
static void jl_add_default_names(jl_module_t *m, uint8_t default_using_core, uint8_t self_name) JL_CANSAFEPOINT
{
if (jl_core_module) {
// Bootstrap: Before jl_core_module is defined, we don't have enough infrastructure
// for bindings, so Core itself gets special handling in jltypes.c
if (default_using_core) {
jl_module_initial_using(m, jl_core_module);
}
if (self_name) {
// export own name, so "using Foo" makes "Foo" itself visible
jl_set_initial_const(m, m->name, (jl_value_t*)m, 1);
}
}
}
jl_module_t *jl_new_module_(jl_sym_t *name, jl_module_t *parent, uint32_t edition,
uint8_t default_using_core, uint8_t self_name)
{
jl_module_t *m = jl_new_module__(name, parent);
JL_GC_PUSH1(&m);
jl_set_module_edition(m, edition);
JL_LOCK(&world_counter_lock);
jl_add_default_names(m, default_using_core, self_name);
JL_UNLOCK(&world_counter_lock);
JL_GC_POP();
return m;
}
// Precondition: world_counter_lock is held
JL_DLLEXPORT jl_binding_partition_t *jl_declare_constant_val3(
jl_binding_t *b, jl_module_t *mod, jl_sym_t *var, jl_value_t *val,
enum jl_partition_kind constant_kind, size_t new_world)
{
jl_binding_partition_t *new_prev_bpart = NULL;
JL_GC_PUSH2(&val, &new_prev_bpart);
if (!b) {
b = jl_get_module_binding(mod, var, 1);
}
jl_binding_partition_t *new_bpart = NULL;
jl_binding_partition_t *bpart = jl_get_binding_partition(b, new_world);
while (!new_bpart) {
enum jl_partition_kind kind = jl_binding_kind(bpart);
if (jl_bkind_is_some_constant(kind) && !jl_bkind_is_some_implicit(kind)) {
if (!val) {
new_bpart = bpart;
break;
}
jl_value_t *old = bpart->restriction;
JL_GC_PROMISE_ROOTED(old);
if (val == old || (val && old && jl_egal(val, old))) {
new_bpart = bpart;
break;
}
} else if (jl_bkind_is_some_explicit_import(kind)) {
jl_errorf("cannot declare %s.%s constant; it was already declared as an import",
jl_symbol_name(mod->name), jl_symbol_name(var));
} else if (kind == PARTITION_KIND_GLOBAL) {
jl_errorf("cannot declare %s.%s constant; it was already declared global",
jl_symbol_name(mod->name), jl_symbol_name(var));
}
if (jl_atomic_load_relaxed(&bpart->min_world) == new_world) {
bpart->kind = constant_kind | jl_carried_binding_flags(bpart);
jl_gc_write(bpart, bpart->restriction, jl_value_t, val);
new_bpart = bpart;
} else {
new_bpart = jl_replace_binding_locked(b, bpart, val, constant_kind, new_world);
}
int need_backdate = new_world && val;
if (need_backdate) {
// We will backdate as long as this partition was never explicitly
// declared const, global, or imported.
jl_binding_partition_t *prev_bpart = bpart;
for (;;) {
enum jl_partition_kind prev_kind = jl_binding_kind(prev_bpart);
if (jl_bkind_is_some_constant(prev_kind) || prev_kind == PARTITION_KIND_GLOBAL ||
jl_bkind_is_some_import(prev_kind)) {
need_backdate = 0;
break;
}
size_t prev_bpart_min_world = jl_atomic_load_relaxed(&prev_bpart->min_world);
if (prev_bpart_min_world == 0)
break;
prev_bpart = jl_get_binding_partition(b, prev_bpart_min_world - 1);
}
}
// If backdate is required, replace each existing partition by a new one.
// We can't use one binding to cover the entire range, because we need to
// keep the flags partitioned.
if (need_backdate) {
jl_binding_partition_t *prev_bpart = bpart;
jl_binding_partition_t *backdate_bpart = new_binding_partition(b);
new_prev_bpart = backdate_bpart;
while (1) {
backdate_bpart->kind = (size_t)PARTITION_KIND_BACKDATED_CONST | (prev_bpart->kind & 0xf0);
jl_gc_write_fresh(backdate_bpart, backdate_bpart->restriction, jl_value_t, val);
jl_atomic_store_relaxed(&backdate_bpart->min_world,
jl_atomic_load_relaxed(&prev_bpart->min_world));
jl_atomic_store_relaxed(&backdate_bpart->max_world,
jl_atomic_load_relaxed(&prev_bpart->max_world));
prev_bpart = jl_atomic_load_relaxed(&prev_bpart->next);
if (!is_some_partition(prev_bpart))
break;
jl_binding_partition_t *next_prev_bpart = new_binding_partition(b);
jl_gc_write_atomic(backdate_bpart, backdate_bpart->next, jl_binding_partition_t, next_prev_bpart, relaxed);
backdate_bpart = next_prev_bpart;
}
jl_gc_write_atomic(new_bpart, new_bpart->next, jl_binding_partition_t, new_prev_bpart, release);
}
}
JL_GC_POP();
return new_bpart;
}
JL_DLLEXPORT jl_module_t *jl_new_module(jl_sym_t *name, jl_module_t *parent)
{
uint32_t edition = parent ? jl_get_module_edition(parent) : OLDEST_EDITION;
return jl_new_module_(name, parent, edition, 1, 1);
}
JL_DLLEXPORT uint32_t jl_module_next_counter(jl_module_t *m)
{
return jl_atomic_fetch_add_relaxed(&m->counter, 1);
}
JL_DLLEXPORT jl_value_t *jl_f_new_module(jl_sym_t *name, uint8_t std_imports, uint8_t default_names) JL_CANSAFEPOINT
{
// TODO: should we prohibit this during incremental compilation?
// TODO: the parent module is a lie
jl_module_t *m = jl_new_module_(
name, jl_main_module, OLDEST_EDITION, default_names, default_names);
JL_GC_PUSH1(&m);
if (std_imports && jl_base_module != NULL)
jl_add_standard_imports(m);
JL_GC_POP();
// TODO: should we somehow try to gc-root this correctly?
return (jl_value_t*)m;
}
JL_DLLEXPORT void jl_set_module_edition(jl_module_t *m, uint32_t ed)
{
jl_atomic_store_relaxed(&m->edition, ed);
}
JL_DLLEXPORT uint32_t jl_get_module_edition(jl_module_t *m)
{
return jl_atomic_load_relaxed(&m->edition);
}
JL_DLLEXPORT void jl_set_module_nospecialize(jl_module_t *self, int on)
{
self->nospecialize = (on ? -1 : 0);
}
JL_DLLEXPORT void jl_set_module_optlevel(jl_module_t *self, int lvl)
{
self->optlevel = lvl;
}
JL_DLLEXPORT int jl_get_module_optlevel(jl_module_t *m)
{
int lvl = m->optlevel;
while (lvl == -1 && m->parent != m && m != jl_base_module) {
m = m->parent;
lvl = m->optlevel;
}
return lvl;
}
JL_DLLEXPORT void jl_set_module_compile(jl_module_t *self, int value)
{
self->compile = value;
}
JL_DLLEXPORT int jl_get_module_compile(jl_module_t *m)
{
int value = m->compile;
while (value == -1 && m->parent != m && m != jl_base_module) {
m = m->parent;
value = m->compile;
}
return value;
}
JL_DLLEXPORT void jl_set_module_infer(jl_module_t *self, int value)
{
self->infer = value;
// no reason to specialize if inference is off
if (!value)
jl_set_module_nospecialize(self, 1);
}
JL_DLLEXPORT int jl_get_module_infer(jl_module_t *m)
{
int value = m->infer;
while (value == -1 && m->parent != m && m != jl_base_module) {
m = m->parent;
value = m->infer;
}
return value;
}
JL_DLLEXPORT void jl_set_module_max_methods(jl_module_t *self, int value)
{
self->max_methods = value;
}
JL_DLLEXPORT int jl_get_module_max_methods(jl_module_t *m)
{
int value = m->max_methods;
while (value == -1 && m->parent != m && m != jl_base_module) {
m = m->parent;
value = m->max_methods;
}
return value;
}
JL_DLLEXPORT void jl_set_istopmod(jl_module_t *self, uint8_t isprimary)
{
self->istopmod = 1;
if (isprimary) {
jl_top_module = self;
}
}
JL_DLLEXPORT uint8_t jl_istopmod(jl_module_t *mod)
{
return mod->istopmod;
}
static jl_globalref_t *jl_new_globalref(jl_module_t *mod, jl_sym_t *name, jl_binding_t *b) JL_CANSAFEPOINT
{
jl_task_t *ct = jl_current_task;
jl_globalref_t *g = (jl_globalref_t*)jl_gc_alloc(ct->ptls, sizeof(jl_globalref_t), jl_globalref_type);
jl_set_typetagof(g, jl_globalref_tag, 0);
jl_gc_write_fresh(g, g->mod, jl_module_t, mod);
jl_gc_write_fresh(g, g->name, jl_sym_t, name);
jl_gc_write_fresh(g, g->binding, jl_binding_t, b);
return g;
}
static jl_binding_t *new_binding(jl_module_t *mod, jl_sym_t *name) JL_CANSAFEPOINT
{
jl_task_t *ct = jl_current_task;
assert(jl_is_module(mod) && jl_is_symbol(name));
jl_binding_t *b = (jl_binding_t*)jl_gc_alloc(ct->ptls, sizeof(jl_binding_t), jl_binding_type);
jl_atomic_store_relaxed(&b->value, NULL);
jl_atomic_store_relaxed(&b->partitions, NULL);
b->globalref = NULL;
b->backedges = NULL;
jl_atomic_store_relaxed(&b->flags, 0);
JL_GC_PUSH1(&b);
jl_gc_write(b, b->globalref, jl_globalref_t, jl_new_globalref(mod, name, b));
JL_GC_POP();
return b;
}
extern jl_mutex_t jl_modules_mutex;
static int is_module_open(jl_module_t *m) JL_CANSAFEPOINT
{
JL_LOCK(&jl_modules_mutex);
int open = ptrhash_has(&jl_current_modules, (void*)m);
if (!open && jl_module_init_order != NULL) {
size_t i, l = jl_array_len(jl_module_init_order);
for (i = 0; i < l; i++) {
if (m == (jl_module_t*)jl_array_ptr_ref(jl_module_init_order, i)) {
open = 1;
break;
}
}
}
JL_UNLOCK(&jl_modules_mutex);
return open;
}
void check_safe_newbinding(jl_module_t *m, jl_sym_t *var)
{
if (jl_current_task->ptls->in_pure_callback)
jl_errorf("new strong globals cannot be created in a generated function. Declare them outside using `global x::Any`.");
if (jl_options.incremental && jl_generating_output() && !is_module_open(m)) {
jl_errorf("Creating a new global in closed module `%s` (`%s`) breaks incremental compilation "
"because the side effects will not be permanent.",
jl_symbol_name(m->name), jl_symbol_name(var));
}
}
static jl_module_t *jl_binding_dbgmodule(jl_binding_t *b) JL_CANSAFEPOINT JL_GLOBALLY_ROOTED;
// Raise the error for a write to a binding that is not a writable global.
static void JL_NORETURN jl_binding_not_writable_error(jl_binding_t *b, jl_module_t *m, jl_sym_t *s, enum jl_partition_kind kind) JL_CANSAFEPOINT
{
assert(kind != PARTITION_KIND_GLOBAL && kind != PARTITION_KIND_DECLARED);
if (jl_bkind_is_some_guard(kind)) {
jl_errorf("Global %s.%s does not exist and cannot be assigned.\n"
"Note: Julia 1.9 and 1.10 inadvertently omitted this error check (#56933).\n"
"Hint: Declare it using `global %s` inside `%s` before attempting assignment.",
jl_symbol_name(m->name), jl_symbol_name(s),
jl_symbol_name(s), jl_symbol_name(m->name));
}
else if (jl_bkind_is_some_constant(kind) && kind != PARTITION_KIND_IMPLICIT_CONST) {
jl_errorf("invalid assignment to constant %s.%s. This redefinition may be permitted using the `const` keyword.",
jl_symbol_name(m->name), jl_symbol_name(s));
}
else {
jl_module_t *from = jl_binding_dbgmodule(b);
if (from == m || !from)
jl_errorf("cannot assign a value to imported variable %s.%s",
jl_symbol_name(m->name), jl_symbol_name(s));
else
jl_errorf("cannot assign a value to imported variable %s.%s from module %s",
jl_symbol_name(from->name), jl_symbol_name(s), jl_symbol_name(m->name));
}
}
// Checks that the binding in general is currently writable, but does not perform any checks on the
// value to be written into the binding.
// `bpart` is the partition the caller resolved this store against, or NULL to resolve `b` at the current world.
JL_DLLEXPORT void jl_check_binding_currently_writable(jl_binding_t *b, jl_binding_partition_t *bpart, jl_module_t *m, jl_sym_t *s)
{
if (bpart == NULL) {
bpart = jl_get_binding_partition(b, jl_current_task->world_age);
if (bpart->kind & PARTITION_FLAG_DEPWARN)
jl_binding_depwarn(b);
}
enum jl_partition_kind kind = jl_binding_kind(bpart);
if (kind != PARTITION_KIND_GLOBAL && kind != PARTITION_KIND_DECLARED)
jl_binding_not_writable_error(b, m, s, kind);
}
JL_DLLEXPORT jl_binding_t *jl_get_binding_wr(jl_module_t *m JL_PROPAGATES_ROOT, jl_sym_t *var)
{
jl_binding_t *b = jl_get_module_binding(m, var, 1);
jl_check_binding_currently_writable(b, NULL, m, var);
return b;
}
// return module of binding
JL_DLLEXPORT jl_module_t *jl_get_module_of_binding(jl_module_t *m, jl_sym_t *var) JL_CANSAFEPOINT
{
size_t world = jl_current_task->world_age;
jl_binding_t *b = jl_get_module_binding(m, var, 1);
jl_binding_partition_t *bpart = jl_get_binding_partition(b, world);
jl_walk_binding_inplace(&b, &bpart, world);
if (jl_binding_kind(bpart) == PARTITION_KIND_IMPLICIT_CONST) {
struct implicit_search_resolution resolution = jl_resolve_implicit_import(b, NULL, world, 0);
if (!resolution.debug_only_ultimate_binding)
jl_error("Constant binding was imported from multiple modules");
b = resolution.debug_only_ultimate_binding;
}
return b ? b->globalref->mod : m;
}
static NOINLINE void print_backdate_admonition(jl_binding_t *b) JL_NOTSAFEPOINT
{
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"
"To make this warning an error, and hence obtain a stack trace, use `julia --depwarn=error`.\n",
jl_symbol_name(b->globalref->mod->name), jl_symbol_name(b->globalref->name));
}
static inline void check_backdated_binding(jl_binding_t *b, enum jl_partition_kind kind) JL_NOTSAFEPOINT
{
if (__unlikely(kind == PARTITION_KIND_BACKDATED_CONST)) {
// We don't want functions that inference executes speculatively to print this warning, so turn those into
// an error for inference purposes.
if (jl_current_task->ptls->in_pure_callback || jl_options.depwarn == JL_OPTIONS_DEPWARN_ERROR)
jl_undefined_var_error(b->globalref->name, (jl_value_t*)b->globalref->mod);
if (!(jl_atomic_fetch_or_relaxed(&b->flags, BINDING_FLAG_DID_PRINT_BACKDATE_ADMONITION) & BINDING_FLAG_DID_PRINT_BACKDATE_ADMONITION))
print_backdate_admonition(b);