-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
julia.h
2531 lines (2237 loc) · 109 KB
/
julia.h
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
#ifndef JULIA_H
#define JULIA_H
#if defined(JL_LIBRARY_EXPORTS_INTERNAL) || defined(JL_LIBRARY_EXPORTS_CODEGEN)
#define JL_LIBRARY_EXPORTS
#endif
#ifdef JL_LIBRARY_EXPORTS
// Generated file, needs to be searched in include paths so that the builddir
// retains priority
#include <jl_internal_funcs.inc>
#undef jl_setjmp
#undef jl_longjmp
#undef jl_egal
#undef jl_genericmemory_owner
#endif
#include "julia_fasttls.h"
#include "libsupport.h"
#include <stdint.h>
#include <string.h>
#include "htable.h"
#include "arraylist.h"
#include "analyzer_annotations.h"
#include <setjmp.h>
#ifndef _OS_WINDOWS_
# define jl_jmp_buf sigjmp_buf
# if defined(_CPU_ARM_) || defined(_CPU_PPC_) || defined(_CPU_WASM_)
# define MAX_ALIGN 8
# elif defined(_CPU_AARCH64_)
// int128 is 16 bytes aligned on aarch64
# define MAX_ALIGN 16
# elif defined(_P64)
// Generically we assume MAX_ALIGN is sizeof(void*)
# define MAX_ALIGN 8
# else
# define MAX_ALIGN 4
# endif
#else
# include "win32_ucontext.h"
# define jl_jmp_buf jmp_buf
# define MAX_ALIGN 8
#endif
// Define the largest size (bytes) of a properly aligned object that the
// processor family and compiler typically supports without a lock
// (assumed to be at least a pointer size). Since C is bad at handling 16-byte
// types, we currently use 8 here as the default.
#define MAX_ATOMIC_SIZE 8
#define MAX_POINTERATOMIC_SIZE 8
#ifdef _P64
#define NWORDS(sz) (((sz)+7)>>3)
#else
#define NWORDS(sz) (((sz)+3)>>2)
#endif
#if defined(__GNUC__)
# define JL_NORETURN __attribute__ ((noreturn))
# define JL_CONST_FUNC __attribute__((const))
# define JL_USED_FUNC __attribute__((used))
#else
# define JL_NORETURN
# define JL_CONST_FUNC
# define JL_USED_FUNC
#endif
#define container_of(ptr, type, member) \
((type *) ((char *)(ptr) - offsetof(type, member)))
typedef struct _jl_taggedvalue_t jl_taggedvalue_t;
typedef struct _jl_tls_states_t *jl_ptls_t;
#ifdef JL_LIBRARY_EXPORTS
#include "uv.h"
#endif
#include "julia_atomics.h"
#include "julia_threads.h"
#include "julia_assert.h"
#ifdef __cplusplus
extern "C" {
#endif
// core data types ------------------------------------------------------------
// the common fields are hidden before the pointer, but the following macro is
// used to indicate which types below are subtypes of jl_value_t
#define JL_DATA_TYPE
typedef struct _jl_value_t jl_value_t;
struct _jl_taggedvalue_bits {
uintptr_t gc:2;
uintptr_t in_image:1;
uintptr_t unused:1;
#ifdef _P64
uintptr_t tag:60;
#else
uintptr_t tag:28;
#endif
};
JL_EXTENSION struct _jl_taggedvalue_t {
union {
uintptr_t header;
jl_taggedvalue_t *next;
jl_value_t *type; // 16-byte aligned
struct _jl_taggedvalue_bits bits;
};
// jl_value_t value;
};
static inline jl_value_t *jl_to_typeof(uintptr_t t) JL_GLOBALLY_ROOTED JL_NOTSAFEPOINT;
#ifdef __clang_gcanalyzer__
JL_DLLEXPORT jl_taggedvalue_t *_jl_astaggedvalue(jl_value_t *v JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT;
#define jl_astaggedvalue(v) _jl_astaggedvalue((jl_value_t*)(v))
jl_value_t *_jl_valueof(jl_taggedvalue_t *tv JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT;
#define jl_valueof(v) _jl_valueof((jl_taggedvalue_t*)(v))
JL_DLLEXPORT jl_value_t *_jl_typeof(jl_value_t *v JL_PROPAGATES_ROOT) JL_NOTSAFEPOINT;
#define jl_typeof(v) (_jl_typeof((jl_value_t*)(v)))
#define jl_typetagof(v) ((uintptr_t)_jl_typeof((jl_value_t*)(v)))
#else
#define jl_astaggedvalue(v) \
((jl_taggedvalue_t*)((char*)(v) - sizeof(jl_taggedvalue_t)))
#define jl_valueof(v) \
((jl_value_t*)((char*)(v) + sizeof(jl_taggedvalue_t)))
#define jl_typeof(v) \
jl_to_typeof(jl_typetagof(v))
#define jl_typetagof(v) \
((jl_astaggedvalue(v)->header) & ~(uintptr_t)15)
#endif
static inline void jl_set_typeof(void *v, void *t) JL_NOTSAFEPOINT
{
// Do not call this on a value that is already initialized.
jl_taggedvalue_t *tag = jl_astaggedvalue(v);
jl_atomic_store_relaxed((_Atomic(jl_value_t*)*)&tag->type, (jl_value_t*)t);
}
#define jl_typeis(v,t) (jl_typeof(v)==(jl_value_t*)(t))
#define jl_typetagis(v,t) (jl_typetagof(v)==(uintptr_t)(t))
#define jl_set_typetagof(v,t,gc) (jl_set_typeof((v), (void*)(((uintptr_t)(t) << 4) | (gc))))
// Symbols are interned strings (hash-consed) stored as an invasive binary tree.
// The string data is nul-terminated and hangs off the end of the struct.
typedef struct _jl_sym_t {
JL_DATA_TYPE
_Atomic(struct _jl_sym_t*) left;
_Atomic(struct _jl_sym_t*) right;
uintptr_t hash; // precomputed hash value
// JL_ATTRIBUTE_ALIGN_PTRSIZE(char name[]);
} jl_sym_t;
// A numbered SSA value, for optimized code analysis and generation
// the `id` is a unique, small number
typedef struct _jl_ssavalue_t {
JL_DATA_TYPE
ssize_t id;
} jl_ssavalue_t;
// A SimpleVector is an immutable pointer array
// Data is stored at the end of this variable-length struct.
typedef struct {
JL_DATA_TYPE
size_t length;
// pointer size aligned
// jl_value_t *data[];
} jl_svec_t;
JL_EXTENSION typedef struct {
JL_DATA_TYPE
size_t length;
void *ptr;
// followed by padding and inline data, or owner pointer
#ifdef _P64
// union {
// jl_value_t *owner;
// T inl[];
// };
#else
//
// jl_value_t *owner;
// size_t padding[1];
// T inl[];
#endif
} jl_genericmemory_t;
JL_EXTENSION typedef struct {
JL_DATA_TYPE
void *ptr_or_offset;
jl_genericmemory_t *mem;
} jl_genericmemoryref_t;
JL_EXTENSION typedef struct {
JL_DATA_TYPE
jl_genericmemoryref_t ref;
size_t dimsize[]; // length for 1-D, otherwise length is mem->length
} jl_array_t;
typedef struct _jl_datatype_t jl_tupletype_t;
struct _jl_code_instance_t;
typedef struct _jl_method_instance_t jl_method_instance_t;
typedef struct _jl_globalref_t jl_globalref_t;
// TypeMap is an implicitly defined type
// that can consist of any of the following nodes:
// typedef TypeMap Union{TypeMapLevel, TypeMapEntry, Nothing}
// it forms a roughly tree-shaped structure, consisting of nodes of TypeMapLevels
// which split the tree when possible, for example based on the key into the tuple type at `offs`
// when key is a leaftype, (but only when the tree has enough entries for this to be
// more efficient than storing them sorted linearly)
// otherwise the leaf entries are stored sorted, linearly
typedef jl_value_t jl_typemap_t;
typedef jl_value_t *(jl_call_t)(jl_value_t*, jl_value_t**, uint32_t, struct _jl_code_instance_t*);
typedef jl_call_t *jl_callptr_t;
// "speccall" calling convention signatures.
// This describes some of the special ABI used by compiled julia functions.
extern jl_call_t jl_fptr_args;
JL_DLLEXPORT extern const jl_callptr_t jl_fptr_args_addr;
typedef jl_value_t *(*jl_fptr_args_t)(jl_value_t*, jl_value_t**, uint32_t);
extern jl_call_t jl_fptr_const_return;
JL_DLLEXPORT extern const jl_callptr_t jl_fptr_const_return_addr;
extern jl_call_t jl_fptr_sparam;
JL_DLLEXPORT extern const jl_callptr_t jl_fptr_sparam_addr;
typedef jl_value_t *(*jl_fptr_sparam_t)(jl_value_t*, jl_value_t**, uint32_t, jl_svec_t*);
extern jl_call_t jl_fptr_interpret_call;
JL_DLLEXPORT extern const jl_callptr_t jl_fptr_interpret_call_addr;
JL_DLLEXPORT extern const jl_callptr_t jl_f_opaque_closure_call_addr;
typedef struct _jl_line_info_node_t {
struct _jl_module_t *module;
jl_value_t *method; // may contain a jl_symbol, jl_method_t, or jl_method_instance_t
jl_sym_t *file;
int32_t line;
int32_t inlined_at;
} jl_line_info_node_t;
// the following mirrors `struct EffectsOverride` in `base/compiler/effects.jl`
typedef union __jl_purity_overrides_t {
struct {
uint8_t ipo_consistent : 1;
uint8_t ipo_effect_free : 1;
uint8_t ipo_nothrow : 1;
uint8_t ipo_terminates_globally : 1;
// Weaker form of `terminates` that asserts
// that any control flow syntactically in the method
// is guaranteed to terminate, but does not make
// assertions about any called functions.
uint8_t ipo_terminates_locally : 1;
uint8_t ipo_notaskstate : 1;
uint8_t ipo_inaccessiblememonly : 1;
uint8_t ipo_noub : 1;
} overrides;
uint8_t bits;
} _jl_purity_overrides_t;
// This type describes a single function body
typedef struct _jl_code_info_t {
// ssavalue-indexed arrays of properties:
jl_array_t *code; // Any array of statements
jl_value_t *codelocs; // Int32 array of indices into the line table
jl_value_t *ssavaluetypes; // types of ssa values (or count of them)
jl_array_t *ssaflags; // flags associated with each statement:
// 0 = inbounds
// 1 = inline
// 2 = noinline
// 3 = <reserved> strict-ieee (strictfp)
// 4 = effect-free (may be deleted if unused)
// 5-6 = <unused>
// 7 = has out-of-band info
// miscellaneous data:
jl_value_t *method_for_inference_limit_heuristics; // optional method used during inference
jl_value_t *linetable; // Table of locations [TODO: make this volatile like slotnames]
jl_array_t *slotnames; // names of local variables
jl_array_t *slotflags; // local var bit flags
// the following are optional transient properties (not preserved by compression--as they typically get stored elsewhere):
jl_value_t *slottypes; // inferred types of slots
jl_value_t *rettype;
jl_method_instance_t *parent; // context (optionally, if available, otherwise nothing)
jl_value_t *edges; // forward edges to method instances that must be invalidated
size_t min_world;
size_t max_world;
// various boolean properties:
uint8_t inferred;
uint8_t propagate_inbounds;
uint8_t has_fcall;
uint8_t nospecializeinfer;
// uint8 settings
uint8_t inlining; // 0 = default; 1 = @inline; 2 = @noinline
uint8_t constprop; // 0 = use heuristic; 1 = aggressive; 2 = none
_jl_purity_overrides_t purity;
// uint16 settings
uint16_t inlining_cost;
} jl_code_info_t;
// This type describes a single method definition, and stores data
// shared by the specializations of a function.
typedef struct _jl_method_t {
JL_DATA_TYPE
jl_sym_t *name; // for error reporting
struct _jl_module_t *module;
jl_sym_t *file;
int32_t line;
size_t primary_world;
size_t deleted_world;
// method's type signature. redundant with TypeMapEntry->specTypes
jl_value_t *sig;
// table of all jl_method_instance_t specializations we have
_Atomic(jl_value_t*) specializations; // allocated as [hashable, ..., NULL, linear, ....], or a single item
_Atomic(jl_array_t*) speckeyset; // index lookup by hash into specializations
jl_value_t *slot_syms; // compacted list of slot names (String)
jl_value_t *external_mt; // reference to the method table this method is part of, null if part of the internal table
jl_value_t *source; // original code template (jl_code_info_t, but may be compressed), null for builtins
_Atomic(jl_method_instance_t*) unspecialized; // unspecialized executable method instance, or null
jl_value_t *generator; // executable code-generating function if available
jl_array_t *roots; // pointers in generated code (shared to reduce memory), or null
// Identify roots by module-of-origin. We only track the module for roots added during incremental compilation.
// May be NULL if no external roots have been added, otherwise it's a Vector{UInt64}
jl_array_t *root_blocks; // RLE (build_id.lo, offset) pairs (even/odd indexing)
int32_t nroots_sysimg; // # of roots stored in the system image
jl_svec_t *ccallable; // svec(rettype, sig) if a ccallable entry point is requested for this
// cache of specializations of this method for invoke(), i.e.
// cases where this method was called even though it was not necessarily
// the most specific for the argument types.
_Atomic(jl_typemap_t*) invokes;
// A function that compares two specializations of this method, returning
// `true` if the first signature is to be considered "smaller" than the
// second for purposes of recursion analysis. Set to NULL to use
// the default recursion relation.
jl_value_t *recursion_relation;
uint32_t nargs;
uint32_t called; // bit flags: whether each of the first 8 arguments is called
uint32_t nospecialize; // bit flags: which arguments should not be specialized
uint32_t nkw; // # of leading arguments that are actually keyword arguments
// of another method.
// various boolean properties
uint8_t isva;
uint8_t is_for_opaque_closure;
uint8_t nospecializeinfer;
// uint8 settings
uint8_t constprop; // 0x00 = use heuristic; 0x01 = aggressive; 0x02 = none
uint8_t max_varargs; // 0xFF = use heuristic; otherwise, max # of args to expand
// varargs when specializing.
// Override the conclusions of inter-procedural effect analysis,
// forcing the conclusion to always true.
_jl_purity_overrides_t purity;
// hidden fields:
// lock for modifications to the method
jl_mutex_t writelock;
} jl_method_t;
// This type is a placeholder to cache data for a specType signature specialization of a Method
// can can be used as a unique dictionary key representation of a call to a particular Method
// with a particular set of argument types
struct _jl_method_instance_t {
JL_DATA_TYPE
union {
jl_value_t *value; // generic accessor
struct _jl_module_t *module; // this is a toplevel thunk
jl_method_t *method; // method this is specialized from
} def; // pointer back to the context for this code
jl_value_t *specTypes; // argument types this was specialized for
jl_svec_t *sparam_vals; // static parameter values, indexed by def.method->sparam_syms
_Atomic(jl_value_t*) uninferred; // cached uncompressed code, for generated functions, top-level thunks, or the interpreter
jl_array_t *backedges; // list of method-instances which call this method-instance; `invoke` records (invokesig, caller) pairs
jl_array_t *callbacks; // list of callback functions to inform external caches about invalidations
_Atomic(struct _jl_code_instance_t*) cache;
uint8_t inInference; // flags to tell if inference is running on this object
uint8_t cache_with_orig; // !cache_with_specTypes
_Atomic(uint8_t) precompiled; // true if this instance was generated by an explicit `precompile(...)` call
};
// OpaqueClosure
typedef struct _jl_opaque_closure_t {
JL_DATA_TYPE
jl_value_t *captures;
size_t world;
jl_method_t *source;
jl_fptr_args_t invoke;
void *specptr;
} jl_opaque_closure_t;
// This type represents an executable operation
typedef struct _jl_code_instance_t {
JL_DATA_TYPE
jl_method_instance_t *def; // method this is specialized from
_Atomic(struct _jl_code_instance_t*) next; // pointer to the next cache entry
// world range for which this object is valid to use
size_t min_world;
size_t max_world;
// inference state cache
jl_value_t *rettype; // return type for fptr
jl_value_t *rettype_const; // inferred constant return value, or null
_Atomic(jl_value_t *) inferred; // inferred jl_code_info_t (may be compressed), or jl_nothing, or null
//TODO: jl_array_t *edges; // stored information about edges from this object
//TODO: uint8_t absolute_max; // whether true max world is unknown
// purity results
// see also encode_effects() and decode_effects() in `base/compiler/effects.jl`,
uint32_t ipo_purity_bits;
// ipo_purity_flags:
// uint8_t ipo_consistent : 2;
// uint8_t ipo_effect_free : 2;
// uint8_t ipo_nothrow : 2;
// uint8_t ipo_terminates : 2;
// uint8_t ipo_nonoverlayed : 1;
// uint8_t ipo_notaskstate : 2;
// uint8_t ipo_inaccessiblememonly : 2;
_Atomic(uint32_t) purity_bits;
// purity_flags:
// uint8_t consistent : 2;
// uint8_t effect_free : 2;
// uint8_t nothrow : 2;
// uint8_t terminates : 2;
// uint8_t nonoverlayed : 1;
// uint8_t notaskstate : 2;
// uint8_t inaccessiblememonly : 2;
jl_value_t *argescapes; // escape information of call arguments
// compilation state cache
_Atomic(uint8_t) specsigflags; // & 0b001 == specptr is a specialized function signature for specTypes->rettype
// & 0b010 == invokeptr matches specptr
// & 0b100 == From image
_Atomic(uint8_t) precompile; // if set, this will be added to the output system image
uint8_t relocatability; // nonzero if all roots are built into sysimg or tagged by module key
_Atomic(jl_callptr_t) invoke; // jlcall entry point
union _jl_generic_specptr_t {
_Atomic(void*) fptr;
_Atomic(jl_fptr_args_t) fptr1;
// 2 constant
_Atomic(jl_fptr_sparam_t) fptr3;
// 4 interpreter
} specptr; // private data for `jlcall entry point
} jl_code_instance_t;
// all values are callable as Functions
typedef jl_value_t jl_function_t;
typedef struct {
JL_DATA_TYPE
jl_sym_t *name;
jl_value_t *lb; // lower bound
jl_value_t *ub; // upper bound
} jl_tvar_t;
// UnionAll type (iterated union over all values of a variable in certain bounds)
// written `body where lb<:var<:ub`
typedef struct {
JL_DATA_TYPE
jl_tvar_t *var;
jl_value_t *body;
} jl_unionall_t;
// represents the "name" part of a DataType, describing the syntactic structure
// of a type and storing all data common to different instantiations of the type,
// including a cache for hash-consed allocation of DataType objects.
typedef struct {
JL_DATA_TYPE
jl_sym_t *name;
struct _jl_module_t *module;
jl_svec_t *names; // field names
const uint32_t *atomicfields; // if any fields are atomic, we record them here
const uint32_t *constfields; // if any fields are const, we record them here
// `wrapper` is either the only instantiation of the type (if no parameters)
// or a UnionAll accepting parameters to make an instantiation.
jl_value_t *wrapper;
_Atomic(jl_value_t*) Typeofwrapper; // cache for Type{wrapper}
_Atomic(jl_svec_t*) cache; // sorted array
_Atomic(jl_svec_t*) linearcache; // unsorted array
struct _jl_methtable_t *mt;
jl_array_t *partial; // incomplete instantiations of this type
intptr_t hash;
int32_t n_uninitialized;
// type properties
uint8_t abstract:1;
uint8_t mutabl:1;
uint8_t mayinlinealloc:1;
uint8_t _reserved:5;
uint8_t max_methods; // override for inference's max_methods setting (0 = no additional limit or relaxation)
} jl_typename_t;
typedef struct {
JL_DATA_TYPE
jl_value_t *a;
jl_value_t *b;
} jl_uniontype_t;
// in little-endian, isptr is always the first bit, avoiding the need for a branch in computing isptr
typedef struct {
uint8_t isptr:1;
uint8_t size:7;
uint8_t offset; // offset relative to data start, excluding type tag
} jl_fielddesc8_t;
typedef struct {
uint16_t isptr:1;
uint16_t size:15;
uint16_t offset; // offset relative to data start, excluding type tag
} jl_fielddesc16_t;
typedef struct {
uint32_t isptr:1;
uint32_t size:31;
uint32_t offset; // offset relative to data start, excluding type tag
} jl_fielddesc32_t;
typedef struct {
uint32_t size;
uint32_t nfields;
uint32_t npointers; // number of pointers embedded inside
int32_t first_ptr; // index of the first pointer (or -1)
uint16_t alignment; // strictest alignment over all fields
struct { // combine these fields into a struct so that we can take addressof them
uint16_t haspadding : 1; // has internal undefined bytes
uint16_t fielddesc_type : 2; // 0 -> 8, 1 -> 16, 2 -> 32, 3 -> foreign type
// metadata bit only for GenericMemory eltype layout
uint16_t arrayelem_isboxed : 1;
uint16_t arrayelem_isunion : 1;
uint16_t padding : 11;
} flags;
// union {
// jl_fielddesc8_t field8[nfields];
// jl_fielddesc16_t field16[nfields];
// jl_fielddesc32_t field32[nfields];
// };
// union { // offsets relative to data start in words
// uint8_t ptr8[npointers];
// uint16_t ptr16[npointers];
// uint32_t ptr32[npointers];
// };
} jl_datatype_layout_t;
typedef struct _jl_datatype_t {
JL_DATA_TYPE
jl_typename_t *name;
struct _jl_datatype_t *super;
jl_svec_t *parameters;
jl_svec_t *types;
jl_value_t *instance; // for singletons
const jl_datatype_layout_t *layout;
// memoized properties (set on construction)
uint32_t hash;
uint16_t hasfreetypevars:1; // majority part of isconcrete computation
uint16_t isconcretetype:1; // whether this type can have instances
uint16_t isdispatchtuple:1; // aka isleaftupletype
uint16_t isbitstype:1; // relevant query for C-api and type-parameters
uint16_t zeroinit:1; // if one or more fields requires zero-initialization
uint16_t has_concrete_subtype:1; // If clear, no value will have this datatype
uint16_t maybe_subtype_of_cache:1; // Computational bit for has_concrete_supertype. See description in jltypes.c.
uint16_t isprimitivetype:1; // whether this is declared with 'primitive type' keyword (sized, no fields, and immutable)
uint16_t ismutationfree:1; // whether any mutable memory is reachable through this type (in the type or via fields)
uint16_t isidentityfree:1; // whether this type or any object reachable through its fields has non-content-based identity
uint16_t smalltag:6; // whether this type has a small-tag optimization
} jl_datatype_t;
typedef struct _jl_vararg_t {
JL_DATA_TYPE
jl_value_t *T;
jl_value_t *N;
} jl_vararg_t;
typedef struct _jl_weakref_t {
JL_DATA_TYPE
jl_value_t *value;
} jl_weakref_t;
typedef struct _jl_binding_t {
JL_DATA_TYPE
_Atomic(jl_value_t*) value;
jl_globalref_t *globalref; // cached GlobalRef for this binding
_Atomic(struct _jl_binding_t*) owner; // for individual imported bindings (NULL until 'resolved')
_Atomic(jl_value_t*) ty; // binding type
uint8_t constp:1;
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 imported:1;
uint8_t usingfailed:1;
uint8_t deprecated:2; // 0=not deprecated, 1=renamed, 2=moved to another package
uint8_t padding:1;
} jl_binding_t;
typedef struct {
uint64_t hi;
uint64_t lo;
} jl_uuid_t;
typedef struct _jl_module_t {
JL_DATA_TYPE
jl_sym_t *name;
struct _jl_module_t *parent;
_Atomic(jl_svec_t*) bindings;
_Atomic(jl_array_t*) bindingkeyset; // index lookup by name into bindings
// hidden fields:
arraylist_t usings; // modules with all bindings potentially imported
jl_uuid_t build_id;
jl_uuid_t uuid;
size_t primary_world;
_Atomic(uint32_t) counter;
int32_t nospecialize; // global bit flags: initialization for new methods
int8_t optlevel;
int8_t compile;
int8_t infer;
uint8_t istopmod;
int8_t max_methods;
jl_mutex_t lock;
intptr_t hash;
} jl_module_t;
typedef struct _jl_globalref_t {
jl_module_t *mod;
jl_sym_t *name;
jl_binding_t *binding;
} jl_globalref_t;
// one Type-to-Value entry
typedef struct _jl_typemap_entry_t {
JL_DATA_TYPE
_Atomic(struct _jl_typemap_entry_t*) next; // invasive linked list
jl_tupletype_t *sig; // the type signature for this entry
jl_tupletype_t *simplesig; // a simple signature for fast rejection
jl_svec_t *guardsigs;
size_t min_world;
size_t max_world;
union {
jl_value_t *value; // generic accessor
jl_method_instance_t *linfo; // [nullable] for guard entries
jl_method_t *method;
} func;
// memoized properties of sig:
int8_t isleafsig; // isleaftype(sig) & !any(isType, sig) : unsorted and very fast
int8_t issimplesig; // all(isleaftype | isAny | isType | isVararg, sig) : sorted and fast
int8_t va; // isVararg(sig)
} jl_typemap_entry_t;
// one level in a TypeMap tree (each level splits on a type at a given offset)
typedef struct _jl_typemap_level_t {
JL_DATA_TYPE
// these vectors contains vectors of more levels in their intended visit order
// with an index that gives the functionality of a sorted dict.
// next split may be on Type{T} as LeafTypes then TypeName's parents up to Any
// next split may be on LeafType
// next split may be on TypeName
_Atomic(jl_genericmemory_t*) arg1; // contains LeafType (in a map of non-abstract TypeName)
_Atomic(jl_genericmemory_t*) targ; // contains Type{LeafType} (in a map of non-abstract TypeName)
_Atomic(jl_genericmemory_t*) name1; // a map for a map for TypeName, for parents up to (excluding) Any
_Atomic(jl_genericmemory_t*) tname; // a map for Type{TypeName}, for parents up to (including) Any
// next a linear list of things too complicated at this level for analysis (no more levels)
_Atomic(jl_typemap_entry_t*) linear;
// finally, start a new level if the type at offs is Any
_Atomic(jl_typemap_t*) any;
} jl_typemap_level_t;
// contains the TypeMap for one Type
typedef struct _jl_methtable_t {
JL_DATA_TYPE
jl_sym_t *name; // sometimes used for debug printing
_Atomic(jl_typemap_t*) defs;
_Atomic(jl_genericmemory_t*) leafcache;
_Atomic(jl_typemap_t*) cache;
_Atomic(intptr_t) max_args; // max # of non-vararg arguments in a signature
jl_module_t *module; // sometimes used for debug printing
jl_array_t *backedges; // (sig, caller::MethodInstance) pairs
jl_mutex_t writelock;
uint8_t offs; // 0, or 1 to skip splitting typemap on first (function) argument
uint8_t frozen; // whether this accepts adding new methods
} jl_methtable_t;
typedef struct {
JL_DATA_TYPE
jl_sym_t *head;
jl_array_t *args;
} jl_expr_t;
typedef struct {
JL_DATA_TYPE
jl_tupletype_t *spec_types;
jl_svec_t *sparams;
jl_method_t *method;
// A bool on the julia side, but can be temporarily 0x2 as a sentinel
// during construction.
uint8_t fully_covers;
} jl_method_match_t;
// constants and type objects -------------------------------------------------
#define JL_SMALL_TYPEOF(XX) \
/* kinds */ \
XX(typeofbottom) \
XX(datatype) \
XX(unionall) \
XX(uniontype) \
/* type parameter objects */ \
XX(vararg) \
XX(tvar) \
XX(symbol) \
XX(module) \
/* special GC objects */ \
XX(simplevector) \
XX(string) \
XX(task) \
/* bits types with special allocators */ \
XX(bool) \
XX(char) \
/*XX(float16)*/ \
/*XX(float32)*/ \
/*XX(float64)*/ \
XX(int16) \
XX(int32) \
XX(int64) \
XX(int8) \
XX(uint16) \
XX(uint32) \
XX(uint64) \
XX(uint8) \
/* AST objects */ \
/* XX(argument) */ \
/* XX(newvarnode) */ \
/* XX(slotnumber) */ \
/* XX(ssavalue) */ \
/* end of JL_SMALL_TYPEOF */
enum jl_small_typeof_tags {
jl_null_tag = 0,
#define XX(name) jl_##name##_tag,
JL_SMALL_TYPEOF(XX)
#undef XX
jl_tags_count,
jl_bitstags_first = jl_char_tag, // n.b. bool is not considered a bitstype, since it can be compared by pointer
jl_max_tags = 64
};
extern JL_DLLIMPORT jl_datatype_t *jl_small_typeof[(jl_max_tags << 4) / sizeof(jl_datatype_t*)];
#ifndef JL_LIBRARY_EXPORTS_INTERNAL
static inline jl_value_t *jl_to_typeof(uintptr_t t)
{
if (t < (jl_max_tags << 4))
return (jl_value_t*)jl_small_typeof[t / sizeof(*jl_small_typeof)];
return (jl_value_t*)t;
}
#else
extern JL_HIDDEN jl_datatype_t *ijl_small_typeof[(jl_max_tags << 4) / sizeof(jl_datatype_t*)];
static inline jl_value_t *jl_to_typeof(uintptr_t t)
{
if (t < (jl_max_tags << 4))
return (jl_value_t*)ijl_small_typeof[t / sizeof(*ijl_small_typeof)];
return (jl_value_t*)t;
}
#endif
// kinds
extern JL_DLLIMPORT jl_datatype_t *jl_typeofbottom_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_datatype_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_uniontype_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_unionall_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_tvar_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_any_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_type_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_typename_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_typename_t *jl_type_typename JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_symbol_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_ssavalue_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_slotnumber_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_argument_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_const_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_partial_struct_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_partial_opaque_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_interconditional_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_method_match_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_simplevector_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_typename_t *jl_tuple_typename JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_typename_t *jl_vecelement_typename JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_anytuple_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_emptytuple_type JL_GLOBALLY_ROOTED;
#define jl_tuple_type jl_anytuple_type
extern JL_DLLIMPORT jl_unionall_t *jl_anytuple_type_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_vararg_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_function_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_builtin_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_opaque_closure_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_typename_t *jl_opaque_closure_typename JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_bottom_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_method_instance_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_code_instance_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_code_info_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_method_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_module_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_addrspace_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_typename_t *jl_addrspace_typename JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_addrspacecore_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_abstractarray_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_densearray_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_array_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_typename_t *jl_array_typename JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_genericmemory_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_typename_t *jl_genericmemory_typename JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_genericmemoryref_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_typename_t *jl_genericmemoryref_typename JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_weakref_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_abstractstring_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_string_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_errorexception_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_argumenterror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_loaderror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_initerror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_typeerror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_methoderror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_undefvarerror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_atomicerror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_lineinfonode_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_stackovf_exception JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_memory_exception JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_readonlymemory_exception JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_diverror_exception JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_undefref_exception JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_interrupt_exception JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_boundserror_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_an_empty_vec_any JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_an_empty_memory_any JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_an_empty_string JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_bool_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_char_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_int8_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_uint8_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_int16_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_uint16_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_int32_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_uint32_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_int64_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_uint64_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_float16_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_float32_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_float64_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_bfloat16_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_floatingpoint_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_number_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_void_type JL_GLOBALLY_ROOTED; // deprecated
extern JL_DLLIMPORT jl_datatype_t *jl_nothing_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_signed_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_voidpointer_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_uint8pointer_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_pointer_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_llvmpointer_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_ref_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_typename_t *jl_pointer_typename JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_typename_t *jl_llvmpointer_typename JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_typename_t *jl_namedtuple_typename JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_unionall_t *jl_namedtuple_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_task_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_pair_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_array_uint8_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_array_any_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_array_symbol_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_array_int32_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_array_uint32_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_array_uint64_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_memory_uint8_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_memory_any_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_memoryref_uint8_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_memoryref_any_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_expr_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_binding_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_globalref_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_linenumbernode_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_gotonode_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_gotoifnot_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_returnnode_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_phinode_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_pinode_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_phicnode_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_upsilonnode_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_quotenode_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_newvarnode_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_intrinsic_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_methtable_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_typemap_level_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_datatype_t *jl_typemap_entry_type JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_svec_t *jl_emptysvec JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_emptytuple JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_true JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_false JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_nothing JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_kwcall_func JL_GLOBALLY_ROOTED;
extern JL_DLLIMPORT jl_value_t *jl_libdl_dlopen_func JL_GLOBALLY_ROOTED;
// gc -------------------------------------------------------------------------
struct _jl_gcframe_t {
size_t nroots;
struct _jl_gcframe_t *prev;
// actual roots go here
};
// NOTE: it is the caller's responsibility to make sure arguments are
// rooted such that the gc can see them on the stack.
// `foo(f(), g())` is not safe,
// since the result of `f()` is not rooted during the call to `g()`,
// and the arguments to foo are not gc-protected during the call to foo.
// foo can't do anything about it, so the caller must do:
// jl_value_t *x=NULL, *y=NULL; JL_GC_PUSH2(&x, &y);
// x = f(); y = g(); foo(x, y)
#define jl_pgcstack (jl_current_task->gcstack)
#define JL_GC_ENCODE_PUSHARGS(n) (((size_t)(n))<<2)
#define JL_GC_ENCODE_PUSH(n) ((((size_t)(n))<<2)|1)
#ifdef __clang_gcanalyzer__
// When running with the analyzer make these real function calls, that are
// easier to detect in the analyzer
extern void JL_GC_PUSH1(void *) JL_NOTSAFEPOINT;
extern void JL_GC_PUSH2(void *, void *) JL_NOTSAFEPOINT;
extern void JL_GC_PUSH3(void *, void *, void *) JL_NOTSAFEPOINT;
extern void JL_GC_PUSH4(void *, void *, void *, void *) JL_NOTSAFEPOINT;
extern void JL_GC_PUSH5(void *, void *, void *, void *, void *) JL_NOTSAFEPOINT;
extern void JL_GC_PUSH7(void *, void *, void *, void *, void *, void *, void *) JL_NOTSAFEPOINT;
extern void JL_GC_PUSH8(void *, void *, void *, void *, void *, void *, void *, void *) JL_NOTSAFEPOINT;
extern void _JL_GC_PUSHARGS(jl_value_t **, size_t) JL_NOTSAFEPOINT;
// This is necessary, because otherwise the analyzer considers this undefined
// behavior and terminates the exploration
#define JL_GC_PUSHARGS(rts_var, n) \
rts_var = (jl_value_t **)alloca(sizeof(void*) * (n)); \
memset(rts_var, 0, sizeof(void*) * (n)); \
_JL_GC_PUSHARGS(rts_var, (n));
extern void JL_GC_POP() JL_NOTSAFEPOINT;
#else
#define JL_GC_PUSH1(arg1) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH(1), jl_pgcstack, arg1}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;
#define JL_GC_PUSH2(arg1, arg2) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH(2), jl_pgcstack, arg1, arg2}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;
#define JL_GC_PUSH3(arg1, arg2, arg3) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH(3), jl_pgcstack, arg1, arg2, arg3}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;
#define JL_GC_PUSH4(arg1, arg2, arg3, arg4) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH(4), jl_pgcstack, arg1, arg2, arg3, arg4}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;
#define JL_GC_PUSH5(arg1, arg2, arg3, arg4, arg5) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH(5), jl_pgcstack, arg1, arg2, arg3, arg4, arg5}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;
#define JL_GC_PUSH6(arg1, arg2, arg3, arg4, arg5, arg6) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH(6), jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;
#define JL_GC_PUSH7(arg1, arg2, arg3, arg4, arg5, arg6, arg7) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH(7), jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6, arg7}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;
#define JL_GC_PUSH8(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8) \
void *__gc_stkf[] = {(void*)JL_GC_ENCODE_PUSH(8), jl_pgcstack, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8}; \
jl_pgcstack = (jl_gcframe_t*)__gc_stkf;
#define JL_GC_PUSHARGS(rts_var,n) \
rts_var = ((jl_value_t**)alloca(((n)+2)*sizeof(jl_value_t*)))+2; \
((void**)rts_var)[-2] = (void*)JL_GC_ENCODE_PUSHARGS(n); \
((void**)rts_var)[-1] = jl_pgcstack; \
memset((void*)rts_var, 0, (n)*sizeof(jl_value_t*)); \
jl_pgcstack = (jl_gcframe_t*)&(((void**)rts_var)[-2])
#define JL_GC_POP() (jl_pgcstack = jl_pgcstack->prev)
#endif
JL_DLLEXPORT int jl_gc_enable(int on);
JL_DLLEXPORT int jl_gc_is_enabled(void);