Branch data Line data Source code
1 : : // This file is a part of Julia. License is MIT: https://julialang.org/license
2 : :
3 : : /*
4 : : implementations of built-in functions
5 : : */
6 : : #include "platform.h"
7 : :
8 : : #include <stdlib.h>
9 : : #include <stdio.h>
10 : : #include <string.h>
11 : : #include <stdarg.h>
12 : : #include <setjmp.h>
13 : : #include <sys/types.h>
14 : : #include <errno.h>
15 : : #include <fcntl.h>
16 : : #include <inttypes.h>
17 : : #if defined(_OS_WINDOWS_)
18 : : #include <malloc.h>
19 : : #else
20 : : #include <unistd.h>
21 : : #endif
22 : : #include <ctype.h>
23 : : #include "julia.h"
24 : : #include "julia_internal.h"
25 : : #include "builtin_proto.h"
26 : : #include "intrinsics.h"
27 : : #include "julia_assert.h"
28 : :
29 : : #ifdef __cplusplus
30 : : extern "C" {
31 : : #endif
32 : :
33 : : // egal and object_id ---------------------------------------------------------
34 : :
35 : 1976430000 : static int bits_equal(const void *a, const void *b, int sz) JL_NOTSAFEPOINT
36 : : {
37 [ + + + + : 1976430000 : switch (sz) {
+ ]
38 : 4739640 : case 1: return *(int8_t*)a == *(int8_t*)b;
39 : : // Let compiler constant folds the following.
40 : 27740 : case 2: return memcmp(a, b, 2) == 0;
41 : 602181000 : case 4: return memcmp(a, b, 4) == 0;
42 : 1317980000 : case 8: return memcmp(a, b, 8) == 0;
43 : 51504200 : default: return memcmp(a, b, sz) == 0;
44 : : }
45 : : }
46 : :
47 : : // The frequently used jl_egal function deserves special attention when it
48 : : // comes to performance which is made challenging by the fact that the
49 : : // function has to handle quite a few different cases and because it is
50 : : // called recursively. To optimize performance many special cases are
51 : : // handle with separate comparisons which can dramatically reduce the run
52 : : // time of the function. The compiler can translate these simple tests
53 : : // with little effort, e.g., few registers are used.
54 : : //
55 : : // The complex cases require more effort and more registers to be translated
56 : : // efficiently. The effected cases include comparing tuples and fields. If
57 : : // the code to perform these operation would be inlined in the jl_egal
58 : : // function then the compiler would generate at the or close to the top of
59 : : // the function a prologue which saves all the callee-save registers and at
60 : : // the end the respective epilogue. The result is that even the fast cases
61 : : // are slowed down.
62 : : //
63 : : // The solution is to keep the code in jl_egal simple and split out the
64 : : // (more) complex cases into their own functions which are marked with
65 : : // NOINLINE.
66 : 221802000 : static int NOINLINE compare_svec(jl_svec_t *a, jl_svec_t *b) JL_NOTSAFEPOINT
67 : : {
68 : 221802000 : size_t i, l = jl_svec_len(a);
69 [ + + ]: 221802000 : if (l != jl_svec_len(b))
70 : 31694500 : return 0;
71 [ + + ]: 326064000 : for (i = 0; i < l; i++) {
72 [ + + ]: 312702000 : if (!jl_egal(jl_svecref(a, i), jl_svecref(b, i)))
73 : 176746000 : return 0;
74 : : }
75 : 13361800 : return 1;
76 : : }
77 : :
78 : : // See comment above for an explanation of NOINLINE.
79 : 249988000 : static int NOINLINE compare_fields(const jl_value_t *a, const jl_value_t *b, jl_datatype_t *dt) JL_NOTSAFEPOINT
80 : : {
81 : 249988000 : size_t nf = jl_datatype_nfields(dt);
82 : : // npointers is used at end, but fetched here for locality with nfields.
83 : 249988000 : int npointers = ((jl_datatype_t*)dt)->layout->npointers;
84 [ + + ]: 576792000 : for (size_t f = 0; f < nf; f++) {
85 : 328548000 : size_t offs = jl_field_offset(dt, f);
86 : 328548000 : char *ao = (char*)a + offs;
87 : 328548000 : char *bo = (char*)b + offs;
88 [ + + ]: 328548000 : if (jl_field_isptr(dt, f)) {
89 : : // Save ptr recursion until the end -- only recurse if otherwise equal
90 : : // Note that we also skip comparing the pointers for null here, because
91 : : // null fields are rare so it can save CPU to delay this read too.
92 : 325479000 : continue;
93 : : }
94 : : else {
95 : 3068370 : jl_datatype_t *ft = (jl_datatype_t*)jl_field_type_concrete(dt, f);
96 [ + + ]: 3068370 : if (jl_is_uniontype(ft)) {
97 : 161 : size_t idx = jl_field_size(dt, f) - 1;
98 : 161 : uint8_t asel = ((uint8_t*)ao)[idx];
99 : 161 : uint8_t bsel = ((uint8_t*)bo)[idx];
100 [ + + ]: 161 : if (asel != bsel)
101 : 37 : return 0;
102 : 124 : ft = (jl_datatype_t*)jl_nth_union_component((jl_value_t*)ft, asel);
103 : : }
104 [ + + ]: 3068210 : else if (ft->layout->first_ptr >= 0) {
105 : : // If the field is a inline immutable that can be undef
106 : : // we need to check for undef first since undef struct
107 : : // may have fields that are different but should still be treated as equal.
108 : 28561 : int32_t idx = ft->layout->first_ptr;
109 : 28561 : jl_value_t *ptra = ((jl_value_t**)ao)[idx];
110 : 28561 : jl_value_t *ptrb = ((jl_value_t**)bo)[idx];
111 [ + + ]: 28561 : if ((ptra == NULL) != (ptrb == NULL)) {
112 : 4 : return 0;
113 : : }
114 [ + + ]: 28557 : else if (ptra == NULL) { // implies ptrb == NULL
115 : 133 : continue; // skip this field (it is #undef)
116 : : }
117 : : }
118 [ + + ]: 3068200 : if (!ft->layout->haspadding) {
119 [ + + ]: 3049830 : if (!bits_equal(ao, bo, ft->size))
120 : 1734600 : return 0;
121 : : }
122 : : else {
123 [ - + ]: 18367 : assert(jl_datatype_nfields(ft) > 0);
124 [ + + ]: 18367 : if (!compare_fields((jl_value_t*)ao, (jl_value_t*)bo, ft))
125 : 8489 : return 0;
126 : : }
127 : : }
128 : : }
129 : : // If we've gotten here, the objects are bitwise equal, besides their pointer fields.
130 : : // Now, we will recurse into jl_egal for the pointed-to elements, which might be
131 : : // arbitrarily expensive.
132 [ + + ]: 303365000 : for (size_t p = 0; p < npointers; p++) {
133 : 271490000 : size_t offs = jl_ptr_offset(dt, p);
134 : 271490000 : jl_value_t *af = ((jl_value_t**)a)[offs];
135 : 271490000 : jl_value_t *bf = ((jl_value_t**)b)[offs];
136 [ + + ]: 271490000 : if (af != bf) {
137 [ + + + + ]: 236699000 : if (af == NULL || bf == NULL)
138 : 1728 : return 0;
139 [ + + ]: 236697000 : if (!jl_egal(af, bf))
140 : 216368000 : return 0;
141 : : }
142 : : }
143 : 31874600 : return 1;
144 : : }
145 : :
146 :14704600000 : static int egal_types(const jl_value_t *a, const jl_value_t *b, jl_typeenv_t *env, int tvar_names) JL_NOTSAFEPOINT
147 : : {
148 [ + + ]:14704600000 : if (a == b)
149 : 5220570000 : return 1;
150 : 9484050000 : jl_datatype_t *dt = (jl_datatype_t*)jl_typeof(a);
151 [ + + ]: 9484050000 : if (dt != (jl_datatype_t*)jl_typeof(b))
152 : 291283000 : return 0;
153 [ + + ]: 9192760000 : if (dt == jl_datatype_type) {
154 : 7352960000 : jl_datatype_t *dta = (jl_datatype_t*)a;
155 : 7352960000 : jl_datatype_t *dtb = (jl_datatype_t*)b;
156 [ + + ]: 7352960000 : if (dta->name != dtb->name)
157 : 2015180000 : return 0;
158 : 5337780000 : size_t i, l = jl_nparams(dta);
159 [ + + ]: 5337780000 : if (jl_nparams(dtb) != l)
160 : 333972000 : return 0;
161 [ + + ]: 7467480000 : for (i = 0; i < l; i++) {
162 [ + + ]: 7414250000 : if (!egal_types(jl_tparam(dta, i), jl_tparam(dtb, i), env, tvar_names))
163 : 4950580000 : return 0;
164 : : }
165 : 53225100 : return 1;
166 : : }
167 [ + + ]: 1839800000 : if (dt == jl_tvar_type) {
168 : 39409400 : jl_typeenv_t *pe = env;
169 [ + + ]: 73062100 : while (pe != NULL) {
170 [ + + ]: 73012500 : if (pe->var == (jl_tvar_t*)a)
171 : 39359800 : return pe->val == b;
172 : 33652700 : pe = pe->prev;
173 : : }
174 : 49643 : return 0;
175 : : }
176 [ + + ]: 1800390000 : if (dt == jl_unionall_type) {
177 : 1546360000 : jl_unionall_t *ua = (jl_unionall_t*)a;
178 : 1546360000 : jl_unionall_t *ub = (jl_unionall_t*)b;
179 [ + + + + ]: 1546360000 : if (tvar_names && ua->var->name != ub->var->name)
180 : 9896980 : return 0;
181 [ + + + + ]: 1536460000 : if (!(egal_types(ua->var->lb, ub->var->lb, env, tvar_names) && egal_types(ua->var->ub, ub->var->ub, env, tvar_names)))
182 : 263082000 : return 0;
183 : 1273380000 : jl_typeenv_t e = { ua->var, (jl_value_t*)ub->var, env };
184 : 1273380000 : return egal_types(ua->body, ub->body, &e, tvar_names);
185 : : }
186 [ + + ]: 254031000 : if (dt == jl_uniontype_type) {
187 [ + + + + ]: 77865800 : return egal_types(((jl_uniontype_t*)a)->a, ((jl_uniontype_t*)b)->a, env, tvar_names) &&
188 : 24396700 : egal_types(((jl_uniontype_t*)a)->b, ((jl_uniontype_t*)b)->b, env, tvar_names);
189 : : }
190 [ + + ]: 200562000 : if (dt == jl_vararg_type) {
191 : 3026180 : jl_vararg_t *vma = (jl_vararg_t*)a;
192 : 3026180 : jl_vararg_t *vmb = (jl_vararg_t*)b;
193 [ + - ]: 3026180 : jl_value_t *vmaT = vma->T ? vma->T : (jl_value_t*)jl_any_type;
194 [ + - ]: 3026180 : jl_value_t *vmbT = vmb->T ? vmb->T : (jl_value_t*)jl_any_type;
195 [ + + ]: 3026180 : if (!egal_types(vmaT, vmbT, env, tvar_names))
196 : 849658 : return 0;
197 [ + + + + ]: 2176530 : if (vma->N && vmb->N)
198 : 37633 : return egal_types(vma->N, vmb->N, env, tvar_names);
199 [ + + + + ]: 2138890 : return !vma->N && !vmb->N;
200 : : }
201 [ + + ]: 197535000 : if (dt == jl_symbol_type)
202 : 79451 : return 0;
203 [ - + ]: 197456000 : assert(!dt->name->mutabl);
204 : 197456000 : return jl_egal__bits(a, b, dt);
205 : : }
206 : :
207 : 2826850000 : JL_DLLEXPORT int jl_types_egal(jl_value_t *a, jl_value_t *b)
208 : : {
209 : 2826850000 : return egal_types(a, b, NULL, 0);
210 : : }
211 : :
212 : 0 : JL_DLLEXPORT int (jl_egal)(const jl_value_t *a JL_MAYBE_UNROOTED, const jl_value_t *b JL_MAYBE_UNROOTED) JL_NOTSAFEPOINT
213 : : {
214 : : // warning: a,b may NOT have been gc-rooted by the caller
215 : 0 : return jl_egal(a, b);
216 : : }
217 : :
218 : 1303250000 : JL_DLLEXPORT int jl_egal__unboxed(const jl_value_t *a JL_MAYBE_UNROOTED, const jl_value_t *b JL_MAYBE_UNROOTED, jl_datatype_t *dt) JL_NOTSAFEPOINT
219 : : {
220 : : // warning: a,b may NOT have been gc-rooted by the caller
221 : 1303250000 : return jl_egal__unboxed_(a, b, dt);
222 : : }
223 : :
224 : 857913000 : int jl_egal__special(const jl_value_t *a JL_MAYBE_UNROOTED, const jl_value_t *b JL_MAYBE_UNROOTED, jl_datatype_t *dt) JL_NOTSAFEPOINT
225 : : {
226 [ + + ]: 857913000 : if (dt == jl_simplevector_type)
227 : 37 : return compare_svec((jl_svec_t*)a, (jl_svec_t*)b);
228 [ + + ]: 857913000 : if (dt == jl_datatype_type) {
229 : 852808000 : jl_datatype_t *dta = (jl_datatype_t*)a;
230 : 852808000 : jl_datatype_t *dtb = (jl_datatype_t*)b;
231 [ + + ]: 852808000 : if (dta->name != dtb->name)
232 : 607771000 : return 0;
233 [ + + + + : 245037000 : if (dta->name != jl_tuple_typename && (dta->isconcretetype || dtb->isconcretetype))
+ + ]
234 : 23235100 : return 0;
235 : 221802000 : return compare_svec(dta->parameters, dtb->parameters);
236 : : }
237 [ + - ]: 5104700 : if (dt == jl_string_type) {
238 : 5104700 : size_t l = jl_string_len(a);
239 [ + + ]: 5104700 : if (jl_string_len(b) != l)
240 : 2177300 : return 0;
241 : 2927410 : return !memcmp(jl_string_data(a), jl_string_data(b), l);
242 : : }
243 : 0 : assert(0 && "unreachable");
244 : : return 0;
245 : : }
246 : :
247 : 2266100000 : int jl_egal__bits(const jl_value_t *a JL_MAYBE_UNROOTED, const jl_value_t *b JL_MAYBE_UNROOTED, jl_datatype_t *dt) JL_NOTSAFEPOINT
248 : : {
249 : 2266100000 : size_t sz = jl_datatype_size(dt);
250 [ - + ]: 2266100000 : if (sz == 0)
251 : 0 : return 1;
252 : 2266100000 : size_t nf = jl_datatype_nfields(dt);
253 [ + + + + ]: 2266100000 : if (nf == 0 || !dt->layout->haspadding)
254 : 1973380000 : return bits_equal(a, b, sz);
255 [ + + ]: 292716000 : if (dt == jl_unionall_type)
256 : 42746300 : return egal_types(a, b, NULL, 1);
257 : 249969000 : return compare_fields(a, b, dt);
258 : : }
259 : :
260 : : // object_id ------------------------------------------------------------------
261 : :
262 : 135943000 : static uintptr_t bits_hash(const void *b, size_t sz) JL_NOTSAFEPOINT
263 : : {
264 [ + + + + : 135943000 : switch (sz) {
+ ]
265 : 609884 : case 1: return int32hash(*(const int8_t*)b);
266 : 1085 : case 2: return int32hash(jl_load_unaligned_i16(b));
267 : 24018 : case 4: return int32hash(jl_load_unaligned_i32(b));
268 : : #ifdef _P64
269 : 133012000 : case 8: return int64hash(jl_load_unaligned_i64(b));
270 : : #else
271 : : case 8: return int64to32hash(jl_load_unaligned_i64(b));
272 : : #endif
273 : 2295900 : default:
274 : : #ifdef _P64
275 : 2295900 : return memhash((const char*)b, sz);
276 : : #else
277 : : return memhash32((const char*)b, sz);
278 : : #endif
279 : : }
280 : : }
281 : :
282 : 175803000 : static uintptr_t NOINLINE hash_svec(jl_svec_t *v) JL_NOTSAFEPOINT
283 : : {
284 : 175803000 : uintptr_t h = 0;
285 : 175803000 : size_t i, l = jl_svec_len(v);
286 [ + + ]: 501628000 : for (i = 0; i < l; i++) {
287 : 325824000 : jl_value_t *x = jl_svecref(v, i);
288 [ + + ]: 325824000 : uintptr_t u = (x == NULL) ? 0 : jl_object_id(x);
289 : 325824000 : h = bitmix(h, u);
290 : : }
291 : 175803000 : return h;
292 : : }
293 : :
294 : : static uintptr_t immut_id_(jl_datatype_t *dt, jl_value_t *v, uintptr_t h) JL_NOTSAFEPOINT;
295 : :
296 : : typedef struct _varidx {
297 : : jl_tvar_t *var;
298 : : struct _varidx *prev;
299 : : } jl_varidx_t;
300 : :
301 : 21660600 : static uintptr_t type_object_id_(jl_value_t *v, jl_varidx_t *env) JL_NOTSAFEPOINT
302 : : {
303 [ - + ]: 21660600 : if (v == NULL)
304 : 0 : return 0;
305 : 21660600 : jl_datatype_t *tv = (jl_datatype_t*)jl_typeof(v);
306 [ + + ]: 21660600 : if (tv == jl_tvar_type) {
307 : 4259670 : jl_varidx_t *pe = env;
308 : 4259670 : int i = 0;
309 [ + + ]: 7503370 : while (pe != NULL) {
310 [ + + ]: 7503360 : if (pe->var == (jl_tvar_t*)v)
311 : 4259660 : return (i<<8) + 42;
312 : 3243700 : i++;
313 : 3243700 : pe = pe->prev;
314 : : }
315 : 12 : return inthash((uintptr_t)v);
316 : : }
317 [ + + ]: 17400900 : if (tv == jl_uniontype_type) {
318 : 707474 : return bitmix(bitmix(jl_object_id((jl_value_t*)tv),
319 : : type_object_id_(((jl_uniontype_t*)v)->a, env)),
320 : : type_object_id_(((jl_uniontype_t*)v)->b, env));
321 : : }
322 [ + + ]: 16693500 : if (tv == jl_unionall_type) {
323 : 3866260 : jl_unionall_t *u = (jl_unionall_t*)v;
324 : 3866260 : uintptr_t h = u->var->name->hash;
325 : 3866260 : h = bitmix(h, type_object_id_(u->var->lb, env));
326 : 3866260 : h = bitmix(h, type_object_id_(u->var->ub, env));
327 : 3866260 : jl_varidx_t e = { u->var, env };
328 : 3866260 : return bitmix(h, type_object_id_(u->body, &e));
329 : : }
330 [ + + ]: 12827200 : if (tv == jl_datatype_type) {
331 : 7156770 : jl_datatype_t *dtv = (jl_datatype_t*)v;
332 [ + + ]: 7156770 : if (dtv->isconcretetype)
333 : 569763 : return dtv->hash;
334 : 6587010 : uintptr_t h = ~dtv->name->hash;
335 : 6587010 : size_t i, l = jl_nparams(v);
336 [ + + ]: 12689800 : for (i = 0; i < l; i++) {
337 : 6102820 : h = bitmix(h, type_object_id_(jl_tparam(v, i), env));
338 : : }
339 : 6587010 : return h;
340 : : }
341 [ + + ]: 5670440 : if (tv == jl_vararg_type) {
342 : 641470 : jl_vararg_t *vm = (jl_vararg_t*)v;
343 [ + - ]: 641470 : jl_value_t *t = vm->T ? vm->T : (jl_value_t*)jl_any_type;
344 [ + + ]: 641470 : jl_value_t *n = vm->N ? vm->N : jl_nothing;
345 : 641470 : return bitmix(type_object_id_(t, env),
346 : : type_object_id_(n, env));
347 : : }
348 [ + + ]: 5028970 : if (tv == jl_symbol_type)
349 : 15 : return ((jl_sym_t*)v)->hash;
350 [ - + ]: 5028960 : assert(!tv->name->mutabl);
351 : 5028960 : return immut_id_(tv, v, tv->hash);
352 : : }
353 : :
354 : 225430000 : static uintptr_t immut_id_(jl_datatype_t *dt, jl_value_t *v, uintptr_t h) JL_NOTSAFEPOINT
355 : : {
356 : 225430000 : size_t sz = jl_datatype_size(dt);
357 [ + + ]: 225430000 : if (sz == 0)
358 : 7423660 : return ~h;
359 : 218006000 : size_t f, nf = jl_datatype_nfields(dt);
360 [ + + + + : 218006000 : if (nf == 0 || (!dt->layout->haspadding && dt->layout->npointers == 0)) {
+ + ]
361 : : // operate element-wise if there are unused bits inside,
362 : : // otherwise just take the whole data block at once
363 : : // a few select pointers (notably symbol) also have special hash values
364 : : // which may affect the stability of the objectid hash, even though
365 : : // they don't affect egal comparison
366 : 135943000 : return bits_hash(v, sz) ^ h;
367 : : }
368 [ + + ]: 82063600 : if (dt == jl_unionall_type)
369 : 1261140 : return type_object_id_(v, NULL);
370 [ + + ]: 257548000 : for (f = 0; f < nf; f++) {
371 : 176745000 : size_t offs = jl_field_offset(dt, f);
372 : 176745000 : char *vo = (char*)v + offs;
373 : : uintptr_t u;
374 [ + + ]: 176745000 : if (jl_field_isptr(dt, f)) {
375 : 176705000 : jl_value_t *f = *(jl_value_t**)vo;
376 [ + + ]: 176705000 : u = (f == NULL) ? 0 : jl_object_id(f);
377 : : }
378 : : else {
379 : 39967 : jl_datatype_t *fieldtype = (jl_datatype_t*)jl_field_type_concrete(dt, f);
380 [ + + ]: 39967 : if (jl_is_uniontype(fieldtype)) {
381 : 11 : uint8_t sel = ((uint8_t*)vo)[jl_field_size(dt, f) - 1];
382 : 11 : fieldtype = (jl_datatype_t*)jl_nth_union_component((jl_value_t*)fieldtype, sel);
383 : : }
384 [ + - + - : 39967 : assert(jl_is_datatype(fieldtype) && !fieldtype->name->abstract && !fieldtype->name->mutabl);
+ - ]
385 : 39967 : int32_t first_ptr = fieldtype->layout->first_ptr;
386 [ + + + + ]: 39967 : if (first_ptr >= 0 && ((jl_value_t**)vo)[first_ptr] == NULL) {
387 : : // If the field is a inline immutable that can be can be undef
388 : : // we need to check to check for undef first since undef struct
389 : : // may have fields that are different but should still be treated as equal.
390 : 202 : u = 0;
391 : : }
392 : : else {
393 : 39765 : u = immut_id_(fieldtype, (jl_value_t*)vo, 0);
394 : : }
395 : : }
396 : 176745000 : h = bitmix(h, u);
397 : : }
398 : 80802500 : return h;
399 : : }
400 : :
401 : 408077000 : static uintptr_t NOINLINE jl_object_id__cold(jl_datatype_t *dt, jl_value_t *v) JL_NOTSAFEPOINT
402 : : {
403 [ + + ]: 408077000 : if (dt == jl_simplevector_type)
404 : 15 : return hash_svec((jl_svec_t*)v);
405 [ + + ]: 408077000 : if (dt == jl_datatype_type) {
406 : 175803000 : jl_datatype_t *dtv = (jl_datatype_t*)v;
407 : 175803000 : uintptr_t h = ~dtv->name->hash;
408 : 175803000 : return bitmix(h, hash_svec(dtv->parameters));
409 : : }
410 [ + + ]: 232274000 : if (dt == jl_string_type) {
411 : : #ifdef _P64
412 : 486640 : return memhash_seed(jl_string_data(v), jl_string_len(v), 0xedc3b677);
413 : : #else
414 : : return memhash32_seed(jl_string_data(v), jl_string_len(v), 0xedc3b677);
415 : : #endif
416 : : }
417 [ + + ]: 231787000 : if (dt->name->mutabl)
418 : 11426200 : return inthash((uintptr_t)v);
419 : 220361000 : return immut_id_(dt, v, dt->hash);
420 : : }
421 : :
422 : 1089130000 : JL_DLLEXPORT inline uintptr_t jl_object_id_(jl_value_t *tv, jl_value_t *v) JL_NOTSAFEPOINT
423 : : {
424 : 1089130000 : jl_datatype_t *dt = (jl_datatype_t*)tv;
425 [ + + ]: 1089130000 : if (dt == jl_symbol_type)
426 : 353132000 : return ((jl_sym_t*)v)->hash;
427 [ + + ]: 736000000 : if (dt == jl_typename_type)
428 : 23982600 : return ((jl_typename_t*)v)->hash;
429 [ + + ]: 712017000 : if (dt == jl_datatype_type) {
430 : 479743000 : jl_datatype_t *dtv = (jl_datatype_t*)v;
431 [ + + ]: 479743000 : if (dtv->isconcretetype)
432 : 303940000 : return dtv->hash;
433 : : }
434 : 408077000 : return jl_object_id__cold(dt, v);
435 : : }
436 : :
437 : :
438 : 599170000 : JL_DLLEXPORT uintptr_t jl_object_id(jl_value_t *v) JL_NOTSAFEPOINT
439 : : {
440 : 599170000 : return jl_object_id_(jl_typeof(v), v);
441 : : }
442 : :
443 : : // eq hash table --------------------------------------------------------------
444 : :
445 : : #include "iddict.c"
446 : :
447 : : // object model and type primitives -------------------------------------------
448 : :
449 : 11003700 : JL_CALLABLE(jl_f_is)
450 : : {
451 [ - + - + ]: 11003700 : JL_NARGS(===, 2, 2);
452 [ + + ]: 11003700 : return jl_egal(args[0], args[1]) ? jl_true : jl_false;
453 : : }
454 : :
455 : 89465 : JL_CALLABLE(jl_f_typeof)
456 : : {
457 [ - + - + ]: 89465 : JL_NARGS(typeof, 1, 1);
458 : 89465 : return jl_typeof(args[0]);
459 : : }
460 : :
461 : 14862600 : JL_CALLABLE(jl_f_sizeof)
462 : : {
463 [ - + - + ]: 14862600 : JL_NARGS(sizeof, 1, 1);
464 : 14862600 : jl_value_t *x = args[0];
465 [ + + + + ]: 14862600 : if (jl_is_unionall(x) || jl_is_uniontype(x)) {
466 : 5718 : x = jl_unwrap_unionall(x);
467 : 5718 : size_t elsize = 0;
468 : 5718 : int isinline = jl_uniontype_size(x, &elsize);
469 [ + + ]: 5718 : if (isinline)
470 : 5714 : return jl_box_long(elsize);
471 [ - + ]: 4 : if (!jl_is_datatype(x))
472 : 0 : jl_error("Argument is an abstract type and does not have a definite size.");
473 : : }
474 [ + + ]: 14856900 : if (jl_is_datatype(x)) {
475 : 335588 : jl_datatype_t *dx = (jl_datatype_t*)x;
476 [ + + ]: 335588 : if (dx->layout == NULL) {
477 [ + + ]: 17 : if (dx->name->abstract)
478 : 13 : jl_errorf("Abstract type %s does not have a definite size.", jl_symbol_name(dx->name->name));
479 : : else
480 : 4 : jl_errorf("Argument is an incomplete %s type and does not have a definite size.", jl_symbol_name(dx->name->name));
481 : : }
482 [ + + ]: 335571 : if (jl_is_layout_opaque(dx->layout))
483 : 355 : jl_errorf("Type %s does not have a definite size.", jl_symbol_name(dx->name->name));
484 : 335216 : return jl_box_long(jl_datatype_size(x));
485 : : }
486 [ + + ]: 14521300 : if (x == jl_bottom_type)
487 : 1 : jl_error("The empty type does not have a definite size since it does not have instances.");
488 [ + + ]: 14521300 : if (jl_is_array(x)) {
489 : 7 : return jl_box_long(jl_array_len(x) * ((jl_array_t*)x)->elsize);
490 : : }
491 [ - + ]: 14521300 : if (jl_is_string(x))
492 : 0 : return jl_box_long(jl_string_len(x));
493 [ + + ]: 14521300 : if (jl_is_symbol(x))
494 : 10426 : return jl_box_long(strlen(jl_symbol_name((jl_sym_t*)x)));
495 [ - + ]: 14510900 : if (jl_is_svec(x))
496 : 0 : return jl_box_long((1+jl_svec_len(x))*sizeof(void*));
497 : 14510900 : jl_datatype_t *dt = (jl_datatype_t*)jl_typeof(x);
498 [ - + ]: 14510900 : assert(jl_is_datatype(dt));
499 [ - + ]: 14510900 : assert(!dt->name->abstract);
500 : 14510900 : return jl_box_long(jl_datatype_size(dt));
501 : : }
502 : :
503 : 138509000 : JL_CALLABLE(jl_f_issubtype)
504 : : {
505 [ - + - + ]: 138509000 : JL_NARGS(<:, 2, 2);
506 : 138509000 : jl_value_t *a = args[0], *b = args[1];
507 [ + + ]: 138509000 : JL_TYPECHK(<:, type, a);
508 [ + + ]: 138509000 : JL_TYPECHK(<:, type, b);
509 [ + + ]: 138509000 : return (jl_subtype(a,b) ? jl_true : jl_false);
510 : : }
511 : :
512 : 33329500 : JL_CALLABLE(jl_f_isa)
513 : : {
514 [ - + - + ]: 33329500 : JL_NARGS(isa, 2, 2);
515 [ + + ]: 33329500 : JL_TYPECHK(isa, type, args[1]);
516 [ + + ]: 33329500 : return (jl_isa(args[0],args[1]) ? jl_true : jl_false);
517 : : }
518 : :
519 : 4871300 : JL_CALLABLE(jl_f_typeassert)
520 : : {
521 [ - + - + ]: 4871300 : JL_NARGS(typeassert, 2, 2);
522 [ + + ]: 4871300 : JL_TYPECHK(typeassert, type, args[1]);
523 [ + + ]: 4871300 : if (!jl_isa(args[0],args[1]))
524 : 6 : jl_type_error("typeassert", args[1], args[0]);
525 : 4871300 : return args[0];
526 : : }
527 : :
528 : 73 : JL_CALLABLE(jl_f_throw)
529 : : {
530 [ - + - + ]: 73 : JL_NARGS(throw, 1, 1);
531 : 73 : jl_throw(args[0]);
532 : : return jl_nothing;
533 : : }
534 : :
535 : 2194 : JL_CALLABLE(jl_f_ifelse)
536 : : {
537 [ - + - + ]: 2194 : JL_NARGS(ifelse, 3, 3);
538 [ - + ]: 2194 : JL_TYPECHK(ifelse, bool, args[0]);
539 [ + - ]: 2194 : return (args[0] == jl_false ? args[2] : args[1]);
540 : : }
541 : :
542 : : // apply ----------------------------------------------------------------------
543 : :
544 : 73169 : static NOINLINE jl_svec_t *_copy_to(size_t newalloc, jl_value_t **oldargs, size_t oldalloc)
545 : : {
546 : : size_t j;
547 : 73169 : jl_svec_t *newheap = jl_alloc_svec_uninit(newalloc);
548 : 73169 : jl_value_t **newargs = jl_svec_data(newheap);
549 [ + + ]: 4099090 : for (j = 0; j < oldalloc; j++)
550 : 4025920 : newargs[j] = oldargs[j];
551 [ + + ]: 3308060 : for (; j < newalloc; j++)
552 : 3234890 : newargs[j] = NULL;
553 : 73169 : return newheap;
554 : : }
555 : :
556 : 291554000 : STATIC_INLINE void _grow_to(jl_value_t **root, jl_value_t ***oldargs, jl_svec_t **arg_heap, size_t *n_alloc, size_t newalloc, size_t extra)
557 : : {
558 : 291554000 : size_t oldalloc = *n_alloc;
559 [ + + ]: 291554000 : if (oldalloc >= newalloc)
560 : 291481000 : return;
561 [ + - ]: 73169 : if (extra)
562 : : // grow by an extra 50% if newalloc is still only a guess
563 : 73169 : newalloc += oldalloc / 2 + 16;
564 : : JL_GC_PROMISE_ROOTED(*oldargs);
565 : 73169 : jl_svec_t *newheap = _copy_to(newalloc, *oldargs, oldalloc);
566 : 73169 : *root = (jl_value_t*)newheap;
567 : 73169 : *arg_heap = newheap;
568 : 73169 : *oldargs = jl_svec_data(newheap);
569 : 73169 : *n_alloc = newalloc;
570 : : }
571 : :
572 : 94822300 : static jl_value_t *do_apply( jl_value_t **args, uint32_t nargs, jl_value_t *iterate)
573 : : {
574 : 94822300 : jl_function_t *f = args[0];
575 [ + + ]: 94822300 : if (nargs == 2) {
576 : : // some common simple cases
577 [ + + ]: 19691900 : if (f == jl_builtin_svec) {
578 [ - + ]: 1374780 : if (jl_is_svec(args[1]))
579 : 0 : return args[1];
580 [ + + ]: 1374780 : if (jl_is_array(args[1])) {
581 : 1373250 : size_t n = jl_array_len(args[1]);
582 : 1373250 : jl_svec_t *t = jl_alloc_svec(n);
583 : 1373250 : JL_GC_PUSH1(&t);
584 [ + + ]: 3415750 : for (size_t i = 0; i < n; i++) {
585 : 2042500 : jl_svecset(t, i, jl_arrayref((jl_array_t*)args[1], i));
586 : : }
587 : 1373250 : JL_GC_POP();
588 : 1373250 : return (jl_value_t*)t;
589 : : }
590 : : }
591 [ + + + + ]: 18317200 : else if (f == jl_builtin_tuple && jl_is_tuple(args[1])) {
592 : 6 : return args[1];
593 : : }
594 : : }
595 : : // estimate how many real arguments we appear to have
596 : 93449000 : size_t precount = 1;
597 : 93449000 : size_t extra = 0;
598 : : size_t i;
599 [ + + ]: 382058000 : for (i = 1; i < nargs; i++) {
600 [ + + ]: 288609000 : if (jl_is_svec(args[i])) {
601 : 19614600 : precount += jl_svec_len(args[i]);
602 : : }
603 [ + + - + ]: 268994000 : else if (jl_is_tuple(args[i]) || jl_is_namedtuple(args[i])) {
604 : 202051000 : precount += jl_nfields(args[i]);
605 : : }
606 [ + + ]: 66943200 : else if (jl_is_array(args[i])) {
607 : 66904000 : precount += jl_array_len(args[i]);
608 : : }
609 : : else {
610 : 39234 : extra += 1;
611 : : }
612 : : }
613 [ + + - + ]: 93449000 : if (extra && iterate == NULL) {
614 : 0 : jl_undefined_var_error(jl_symbol("iterate"));
615 : : }
616 : : // allocate space for the argument array and gc roots for it
617 : : // based on our previous estimates
618 : : // use the stack if we have a good estimate that it is small
619 : : // otherwise, use the heap and grow it incrementally
620 : : // and if there are any extra elements, we'll also need a couple extra roots
621 : 93449000 : int onstack = (precount + 32 * extra < jl_page_size / sizeof(jl_value_t*));
622 [ + + + + ]: 93449000 : size_t stackalloc = onstack ? (precount + 4 * extra + (extra ? 16 : 0)) : 1;
623 : : size_t n_alloc;
624 : : jl_value_t **roots;
625 [ + + + + : 93449000 : JL_GC_PUSHARGS(roots, stackalloc + (extra ? 2 : 0));
+ + ]
626 : : jl_value_t **newargs;
627 : 93449000 : jl_svec_t *arg_heap = NULL;
628 [ + + ]: 93449000 : if (onstack) {
629 : 93449000 : newargs = roots;
630 : 93449000 : n_alloc = stackalloc;
631 : : }
632 : : else {
633 : : // put arguments on the heap if there are too many
634 : 38 : newargs = NULL;
635 : 38 : n_alloc = precount;
636 [ + + ]: 38 : if (extra)
637 : : // grow by an extra 50% if newalloc is still only a guess
638 : 2 : n_alloc += n_alloc / 2 + 16;
639 : 38 : arg_heap = jl_alloc_svec(n_alloc);
640 : 38 : roots[0] = (jl_value_t*)arg_heap;
641 : 38 : newargs = jl_svec_data(arg_heap);
642 : : }
643 : 93449000 : newargs[0] = f;
644 : 93449000 : precount -= 1;
645 : 93449000 : size_t n = 1;
646 [ + + ]: 382058000 : for (i = 1; i < nargs; i++) {
647 : 288609000 : jl_value_t *ai = args[i];
648 [ + + ]: 288609000 : if (jl_is_svec(ai)) {
649 : 19614600 : jl_svec_t *t = (jl_svec_t*)ai;
650 : 19614600 : size_t j, al = jl_svec_len(t);
651 [ + + ]: 19614600 : precount = (precount > al) ? precount - al : 0;
652 : 19614600 : _grow_to(&roots[0], &newargs, &arg_heap, &n_alloc, n + precount + al, extra);
653 [ - + ]: 19614600 : assert(newargs != NULL); // inform GCChecker that we didn't write a NULL here
654 [ + + ]: 79349500 : for (j = 0; j < al; j++) {
655 : 59734900 : newargs[n++] = jl_svecref(t, j);
656 : : // GC Note: here we assume that the return value of `jl_svecref`
657 : : // will not be young if `arg_heap` becomes old
658 : : // since they are allocated before `arg_heap`. Otherwise,
659 : : // we need to add write barrier for !onstack
660 : : }
661 : : }
662 [ + + - + ]: 471045000 : else if (jl_is_tuple(ai) || jl_is_namedtuple(ai)) {
663 : 202051000 : size_t j, al = jl_nfields(ai);
664 [ + + ]: 202051000 : precount = (precount > al) ? precount - al : 0;
665 : 202051000 : _grow_to(&roots[0], &newargs, &arg_heap, &n_alloc, n + precount + al, extra);
666 [ - + ]: 202051000 : assert(newargs != NULL); // inform GCChecker that we didn't write a NULL here
667 [ + + ]: 412950000 : for (j = 0; j < al; j++) {
668 : : // jl_fieldref may allocate.
669 : 210899000 : newargs[n++] = jl_fieldref(ai, j);
670 [ + + ]: 210899000 : if (arg_heap)
671 : 120002000 : jl_gc_wb(arg_heap, newargs[n - 1]);
672 : : }
673 : : }
674 [ + + ]: 66943200 : else if (jl_is_array(ai)) {
675 : 66904000 : jl_array_t *aai = (jl_array_t*)ai;
676 : 66904000 : size_t j, al = jl_array_len(aai);
677 [ + + ]: 66904000 : precount = (precount > al) ? precount - al : 0;
678 : 66904000 : _grow_to(&roots[0], &newargs, &arg_heap, &n_alloc, n + precount + al, extra);
679 [ - + ]: 66904000 : assert(newargs != NULL); // inform GCChecker that we didn't write a NULL here
680 [ + + ]: 66904000 : if (aai->flags.ptrarray) {
681 [ + + ]: 228799000 : for (j = 0; j < al; j++) {
682 : 163960000 : jl_value_t *arg = jl_array_ptr_ref(aai, j);
683 : : // apply with array splatting may have embedded NULL value (#11772)
684 [ + + ]: 163960000 : if (__unlikely(arg == NULL))
685 : 1 : jl_throw(jl_undefref_exception);
686 : 163960000 : newargs[n++] = arg;
687 [ + + ]: 163960000 : if (arg_heap)
688 : 2021780 : jl_gc_wb(arg_heap, arg);
689 : : }
690 : : }
691 : : else {
692 [ + + ]: 49491900 : for (j = 0; j < al; j++) {
693 : 47426400 : newargs[n++] = jl_arrayref(aai, j);
694 [ + + ]: 47426400 : if (arg_heap)
695 : 41007100 : jl_gc_wb(arg_heap, newargs[n - 1]);
696 : : }
697 : : }
698 : : }
699 : : else {
700 [ - + ]: 39234 : assert(extra > 0);
701 : : jl_value_t *args[2];
702 : 39234 : args[0] = ai;
703 : 39234 : jl_value_t *next = jl_apply_generic(iterate, args, 1);
704 [ + + ]: 3023850 : while (next != jl_nothing) {
705 : 2984620 : roots[stackalloc] = next;
706 : 2984620 : jl_value_t *value = jl_get_nth_field_checked(next, 0);
707 : 2984620 : roots[stackalloc + 1] = value;
708 : 2984620 : jl_value_t *state = jl_get_nth_field_checked(next, 1);
709 : 2984620 : roots[stackalloc] = state;
710 : 2984620 : _grow_to(&roots[0], &newargs, &arg_heap, &n_alloc, n + precount + 1, extra);
711 : : JL_GC_ASSERT_LIVE(value);
712 : 2984620 : newargs[n++] = value;
713 [ + + ]: 2984620 : if (arg_heap)
714 : 2343600 : jl_gc_wb(arg_heap, value);
715 : 2984620 : roots[stackalloc + 1] = NULL;
716 : : JL_GC_ASSERT_LIVE(state);
717 : 2984620 : args[1] = state;
718 : 2984620 : next = jl_apply_generic(iterate, args, 2);
719 : : }
720 : 39229 : roots[stackalloc] = NULL;
721 : 39229 : extra -= 1;
722 : : }
723 : : }
724 [ + + ]: 93449000 : if (arg_heap) {
725 : : // optimization: keep only the first root, free the others
726 : : #ifndef __clang_gcanalyzer__
727 : 29026 : ((void**)roots)[-2] = (void*)JL_GC_ENCODE_PUSHARGS(1);
728 : : #endif
729 : : }
730 : 93449000 : jl_value_t *result = jl_apply(newargs, n);
731 : 93418900 : JL_GC_POP();
732 : 93418900 : return result;
733 : : }
734 : :
735 : 94820800 : JL_CALLABLE(jl_f__apply_iterate)
736 : : {
737 [ + + ]: 94820800 : JL_NARGSV(_apply_iterate, 2);
738 : 94820800 : return do_apply(args + 1, nargs - 1, args[0]);
739 : : }
740 : :
741 : : // this is like `_apply`, but with quasi-exact checks to make sure it is pure
742 : 1486 : JL_CALLABLE(jl_f__apply_pure)
743 : : {
744 : 1486 : jl_task_t *ct = jl_current_task;
745 : 1486 : int last_in = ct->ptls->in_pure_callback;
746 : 1486 : jl_value_t *ret = NULL;
747 [ + + + + ]: 2970 : JL_TRY {
748 : 1486 : ct->ptls->in_pure_callback = 1;
749 : : // because this function was declared pure,
750 : : // we should be allowed to run it in any world
751 : : // so we run it in the newest world;
752 : : // because, why not :)
753 : : // and `promote` works better this way
754 : 1486 : size_t last_age = ct->world_age;
755 : 1486 : ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
756 : 1486 : ret = do_apply(args, nargs, NULL);
757 : 1484 : ct->world_age = last_age;
758 : 1484 : ct->ptls->in_pure_callback = last_in;
759 : : }
760 [ + - ]: 2 : JL_CATCH {
761 : 2 : ct->ptls->in_pure_callback = last_in;
762 : 2 : jl_rethrow();
763 : : }
764 : 1484 : return ret;
765 : : }
766 : :
767 : : // this is like a regular call, but always runs in the newest world
768 : 204718 : JL_CALLABLE(jl_f__call_latest)
769 : : {
770 : 204718 : jl_task_t *ct = jl_current_task;
771 : 204718 : size_t last_age = ct->world_age;
772 [ + - ]: 204718 : if (!ct->ptls->in_pure_callback)
773 : 204718 : ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
774 : 204718 : jl_value_t *ret = jl_apply(args, nargs);
775 : 204453 : ct->world_age = last_age;
776 : 204453 : return ret;
777 : : }
778 : :
779 : : // Like call_in_world, but runs in the specified world.
780 : : // If world > jl_atomic_load_acquire(&jl_world_counter), run in the latest world.
781 : 4 : JL_CALLABLE(jl_f__call_in_world)
782 : : {
783 [ - + ]: 4 : JL_NARGSV(_apply_in_world, 2);
784 : 4 : jl_task_t *ct = jl_current_task;
785 : 4 : size_t last_age = ct->world_age;
786 [ - + ]: 4 : JL_TYPECHK(_apply_in_world, ulong, args[0]);
787 : 4 : size_t world = jl_unbox_ulong(args[0]);
788 [ + - ]: 4 : if (!ct->ptls->in_pure_callback) {
789 : 4 : ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
790 [ + + ]: 4 : if (ct->world_age > world)
791 : 2 : ct->world_age = world;
792 : : }
793 : 4 : jl_value_t *ret = jl_apply(&args[1], nargs - 1);
794 : 4 : ct->world_age = last_age;
795 : 4 : return ret;
796 : : }
797 : :
798 : 2864140 : JL_CALLABLE(jl_f__call_in_world_total)
799 : : {
800 [ - + ]: 2864140 : JL_NARGSV(_call_in_world_total, 2);
801 [ - + ]: 2864140 : JL_TYPECHK(_apply_in_world, ulong, args[0]);
802 : 2864140 : jl_task_t *ct = jl_current_task;
803 : 2864140 : int last_in = ct->ptls->in_pure_callback;
804 : 2864140 : jl_value_t *ret = NULL;
805 : 2864140 : size_t last_age = ct->world_age;
806 [ + + + + ]: 5699310 : JL_TRY {
807 : 2864140 : ct->ptls->in_pure_callback = 1;
808 : 2864140 : size_t world = jl_unbox_ulong(args[0]);
809 : 2864140 : ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
810 [ + + ]: 2864140 : if (ct->world_age > world)
811 : 17223 : ct->world_age = world;
812 : 2864140 : ret = jl_apply(&args[1], nargs - 1);
813 : 2835180 : ct->world_age = last_age;
814 : 2835180 : ct->ptls->in_pure_callback = last_in;
815 : : }
816 [ + - ]: 28958 : JL_CATCH {
817 : 28958 : ct->ptls->in_pure_callback = last_in;
818 : 28958 : jl_rethrow();
819 : : }
820 : 2835180 : return ret;
821 : : }
822 : :
823 : : // tuples ---------------------------------------------------------------------
824 : :
825 : 55260000 : JL_CALLABLE(jl_f_tuple)
826 : : {
827 : : size_t i;
828 [ + + ]: 55260000 : if (nargs == 0)
829 : 4549770 : return (jl_value_t*)jl_emptytuple;
830 : 50710300 : jl_datatype_t *tt = jl_inst_arg_tuple_type(args[0], &args[1], nargs, 0);
831 : : JL_GC_PROMISE_ROOTED(tt); // it is a concrete type
832 [ + + ]: 50710300 : if (tt->instance != NULL)
833 : 1604760 : return tt->instance;
834 : 49105500 : jl_task_t *ct = jl_current_task;
835 : 49105500 : jl_value_t *jv = jl_gc_alloc(ct->ptls, jl_datatype_size(tt), tt);
836 [ + + ]: 157328000 : for (i = 0; i < nargs; i++)
837 : 108222000 : set_nth_field(tt, jv, i, args[i], 0);
838 : 49105500 : return jv;
839 : : }
840 : :
841 : 871663 : JL_CALLABLE(jl_f_svec)
842 : : {
843 : : size_t i;
844 [ + + ]: 871663 : if (nargs == 0)
845 : 311720 : return (jl_value_t*)jl_emptysvec;
846 : 559943 : jl_svec_t *t = jl_alloc_svec_uninit(nargs);
847 [ + + ]: 1644620 : for (i = 0; i < nargs; i++) {
848 : 1084680 : jl_svecset(t, i, args[i]);
849 : : }
850 : 559943 : return (jl_value_t*)t;
851 : : }
852 : :
853 : : // struct operations ------------------------------------------------------------
854 : :
855 : 38580 : enum jl_memory_order jl_get_atomic_order(jl_sym_t *order, char loading, char storing)
856 : : {
857 [ + + ]: 38580 : if (order == jl_not_atomic_sym)
858 : 853 : return jl_memory_order_notatomic;
859 [ + + + + ]: 37727 : if (order == jl_unordered_sym && (loading ^ storing))
860 : 158 : return jl_memory_order_unordered;
861 [ + + + + : 37569 : if (order == jl_monotonic_sym && (loading || storing))
+ - ]
862 : 12087 : return jl_memory_order_monotonic;
863 [ + + + + ]: 25482 : if (order == jl_acquire_sym && loading)
864 : 15249 : return jl_memory_order_acquire;
865 [ + + + + ]: 10233 : if (order == jl_release_sym && storing)
866 : 2684 : return jl_memory_order_release;
867 [ + + + + : 7549 : if (order == jl_acquire_release_sym && loading && storing)
+ + ]
868 : 5913 : return jl_memory_order_acq_rel;
869 [ + + ]: 1636 : if (order == jl_sequentially_consistent_sym)
870 : 1170 : return jl_memory_order_seq_cst;
871 : 466 : return jl_memory_order_invalid;
872 : : }
873 : :
874 : 1370 : enum jl_memory_order jl_get_atomic_order_checked(jl_sym_t *order, char loading, char storing)
875 : : {
876 : 1370 : enum jl_memory_order mo = jl_get_atomic_order(order, loading, storing);
877 [ + + ]: 1370 : if (mo < 0) // invalid
878 : 75 : jl_atomic_error("invalid atomic ordering");
879 : 1295 : return mo;
880 : : }
881 : :
882 : 363113000 : static inline size_t get_checked_fieldindex(const char *name, jl_datatype_t *st, jl_value_t *v, jl_value_t *arg, int mutabl)
883 : : {
884 [ + + ]: 363113000 : if (mutabl) {
885 [ - + ]: 406860 : if (st == jl_module_type)
886 : 0 : jl_error("cannot assign variables in other modules");
887 [ + + ]: 406860 : if (!st->name->mutabl)
888 : 4 : jl_errorf("%s: immutable struct of type %s cannot be changed", name, jl_symbol_name(st->name->name));
889 : : }
890 : : size_t idx;
891 [ + + ]: 363113000 : if (jl_is_long(arg)) {
892 : 137233000 : idx = jl_unbox_long(arg) - 1;
893 [ + + ]: 137233000 : if (idx >= jl_datatype_nfields(st))
894 : 64 : jl_bounds_error(v, arg);
895 : : }
896 : : else {
897 [ + + ]: 225880000 : JL_TYPECHKS(name, symbol, arg);
898 : 225880000 : idx = jl_field_index(st, (jl_sym_t*)arg, 1);
899 : : }
900 [ + + + + ]: 363112000 : if (mutabl && jl_field_isconst(st, idx)) {
901 : 11 : jl_errorf("%s: const field .%s of type %s cannot be changed", name,
902 : 11 : jl_symbol_name((jl_sym_t*)jl_svec_ref(jl_field_names(st), idx)), jl_symbol_name(st->name->name));
903 : : }
904 : 363112000 : return idx;
905 : : }
906 : :
907 : 374981000 : JL_CALLABLE(jl_f_getfield)
908 : : {
909 : 374981000 : enum jl_memory_order order = jl_memory_order_unspecified;
910 [ + + - + ]: 374981000 : JL_NARGS(getfield, 2, 4);
911 [ + + ]: 374981000 : if (nargs == 4) {
912 [ - + ]: 2 : JL_TYPECHK(getfield, symbol, args[2]);
913 [ - + ]: 2 : JL_TYPECHK(getfield, bool, args[3]);
914 : 2 : order = jl_get_atomic_order_checked((jl_sym_t*)args[2], 1, 0);
915 : : }
916 [ + + ]: 374981000 : else if (nargs == 3) {
917 [ + + ]: 39079500 : if (!jl_is_bool(args[2])) {
918 [ - + ]: 191 : JL_TYPECHK(getfield, symbol, args[2]);
919 : 191 : order = jl_get_atomic_order_checked((jl_sym_t*)args[2], 1, 0);
920 : : }
921 : : }
922 : 374981000 : jl_value_t *v = args[0];
923 : 374981000 : jl_value_t *vt = jl_typeof(v);
924 [ + + ]: 374981000 : if (vt == (jl_value_t*)jl_module_type)
925 : 12274500 : return jl_f_getglobal(NULL, args, 2); // we just ignore the atomic order and boundschecks
926 : 362706000 : jl_datatype_t *st = (jl_datatype_t*)vt;
927 : 362706000 : size_t idx = get_checked_fieldindex("getfield", st, v, args[1], 0);
928 : 362705000 : int isatomic = jl_field_isatomic(st, idx);
929 [ + + + + : 362705000 : if (!isatomic && order != jl_memory_order_notatomic && order != jl_memory_order_unspecified)
+ + ]
930 : 48 : jl_atomic_error("getfield: non-atomic field cannot be accessed atomically");
931 [ + + + + ]: 362705000 : if (isatomic && order == jl_memory_order_notatomic)
932 : 13 : jl_atomic_error("getfield: atomic field cannot be accessed non-atomically");
933 : 362705000 : v = jl_get_nth_field_checked(v, idx);
934 [ + + + + ]: 362705000 : if (order >= jl_memory_order_acq_rel || order == jl_memory_order_acquire)
935 : 85 : jl_fence(); // `v` already had at least consume ordering
936 : 362705000 : return v;
937 : : }
938 : :
939 : 406228 : JL_CALLABLE(jl_f_setfield)
940 : : {
941 : 406228 : enum jl_memory_order order = jl_memory_order_notatomic;
942 [ - + - + ]: 406228 : JL_NARGS(setfield!, 3, 4);
943 [ + + ]: 406228 : if (nargs == 4) {
944 [ - + ]: 133 : JL_TYPECHK(setfield!, symbol, args[3]);
945 : 133 : order = jl_get_atomic_order_checked((jl_sym_t*)args[3], 0, 1);
946 : : }
947 : 406228 : jl_value_t *v = args[0];
948 : 406228 : jl_datatype_t *st = (jl_datatype_t*)jl_typeof(v);
949 : 406228 : size_t idx = get_checked_fieldindex("setfield!", st, v, args[1], 1);
950 : 406213 : int isatomic = !!jl_field_isatomic(st, idx);
951 [ + + ]: 406213 : if (isatomic == (order == jl_memory_order_notatomic))
952 [ + + ]: 73 : jl_atomic_error(isatomic ? "setfield!: atomic field cannot be written non-atomically"
953 : : : "setfield!: non-atomic field cannot be written atomically");
954 : 406140 : jl_value_t *ft = jl_field_type_concrete(st, idx);
955 [ + + ]: 406140 : if (!jl_isa(args[2], ft))
956 : 2 : jl_type_error("setfield!", ft, args[2]);
957 [ + + + + ]: 406138 : if (order >= jl_memory_order_acq_rel || order == jl_memory_order_release)
958 : 33 : jl_fence(); // `st->[idx]` will have at least relaxed ordering
959 : 406138 : set_nth_field(st, v, idx, args[2], isatomic);
960 : 406138 : return args[2];
961 : : }
962 : :
963 : 173 : JL_CALLABLE(jl_f_swapfield)
964 : : {
965 : 173 : enum jl_memory_order order = jl_memory_order_notatomic;
966 [ - + - + ]: 173 : JL_NARGS(swapfield!, 3, 4);
967 [ + + ]: 173 : if (nargs == 4) {
968 [ - + ]: 160 : JL_TYPECHK(swapfield!, symbol, args[3]);
969 : 160 : order = jl_get_atomic_order_checked((jl_sym_t*)args[3], 1, 1);
970 : : }
971 : 173 : jl_value_t *v = args[0];
972 : 173 : jl_datatype_t *st = (jl_datatype_t*)jl_typeof(v);
973 : 173 : size_t idx = get_checked_fieldindex("swapfield!", st, v, args[1], 1);
974 : 172 : int isatomic = !!jl_field_isatomic(st, idx);
975 [ + + ]: 172 : if (isatomic == (order == jl_memory_order_notatomic))
976 [ + + ]: 85 : jl_atomic_error(isatomic ? "swapfield!: atomic field cannot be written non-atomically"
977 : : : "swapfield!: non-atomic field cannot be written atomically");
978 : 87 : v = swap_nth_field(st, v, idx, args[2], isatomic); // always seq_cst, if isatomic needed at all
979 : 82 : return v;
980 : : }
981 : :
982 : 188 : JL_CALLABLE(jl_f_modifyfield)
983 : : {
984 : 188 : enum jl_memory_order order = jl_memory_order_notatomic;
985 [ - + - + ]: 188 : JL_NARGS(modifyfield!, 4, 5);
986 [ + + ]: 188 : if (nargs == 5) {
987 [ - + ]: 175 : JL_TYPECHK(modifyfield!, symbol, args[4]);
988 : 175 : order = jl_get_atomic_order_checked((jl_sym_t*)args[4], 1, 1);
989 : : }
990 : 188 : jl_value_t *v = args[0];
991 : 188 : jl_datatype_t *st = (jl_datatype_t*)jl_typeof(v);
992 : 188 : size_t idx = get_checked_fieldindex("modifyfield!", st, v, args[1], 1);
993 : 187 : int isatomic = !!jl_field_isatomic(st, idx);
994 [ + + ]: 187 : if (isatomic == (order == jl_memory_order_notatomic))
995 [ + + ]: 87 : jl_atomic_error(isatomic ? "modifyfield!: atomic field cannot be written non-atomically"
996 : : : "modifyfield!: non-atomic field cannot be written atomically");
997 : 100 : v = modify_nth_field(st, v, idx, args[2], args[3], isatomic); // always seq_cst, if isatomic needed at all
998 : 95 : return v;
999 : : }
1000 : :
1001 : 273 : JL_CALLABLE(jl_f_replacefield)
1002 : : {
1003 : 273 : enum jl_memory_order success_order = jl_memory_order_notatomic;
1004 [ - + - + ]: 273 : JL_NARGS(replacefield!, 4, 6);
1005 [ + + ]: 273 : if (nargs >= 5) {
1006 [ - + ]: 248 : JL_TYPECHK(replacefield!, symbol, args[4]);
1007 : 248 : success_order = jl_get_atomic_order_checked((jl_sym_t*)args[4], 1, 1);
1008 : : }
1009 : 273 : enum jl_memory_order failure_order = success_order;
1010 [ + + ]: 273 : if (nargs == 6) {
1011 [ - + ]: 214 : JL_TYPECHK(replacefield!, symbol, args[5]);
1012 : 214 : failure_order = jl_get_atomic_order_checked((jl_sym_t*)args[5], 1, 0);
1013 : : }
1014 [ + + ]: 273 : if (failure_order > success_order)
1015 : 2 : jl_atomic_error("invalid atomic ordering");
1016 : : // TODO: filter more invalid ordering combinations?
1017 : 271 : jl_value_t *v = args[0];
1018 : 271 : jl_datatype_t *st = (jl_datatype_t*)jl_typeof(v);
1019 : 271 : size_t idx = get_checked_fieldindex("replacefield!", st, v, args[1], 1);
1020 : 270 : int isatomic = !!jl_field_isatomic(st, idx);
1021 [ + + ]: 270 : if (isatomic == (success_order == jl_memory_order_notatomic))
1022 [ + + ]: 86 : jl_atomic_error(isatomic ? "replacefield!: atomic field cannot be written non-atomically"
1023 : : : "replacefield!: non-atomic field cannot be written atomically");
1024 [ + + ]: 184 : if (isatomic == (failure_order == jl_memory_order_notatomic))
1025 [ + - ]: 60 : jl_atomic_error(isatomic ? "replacefield!: atomic field cannot be accessed non-atomically"
1026 : : : "replacefield!: non-atomic field cannot be accessed atomically");
1027 : 124 : v = replace_nth_field(st, v, idx, args[2], args[3], isatomic); // always seq_cst, if isatomic needed at all
1028 : 114 : return v;
1029 : : }
1030 : :
1031 : :
1032 : 22214800 : static jl_value_t *get_fieldtype(jl_value_t *t, jl_value_t *f, int dothrow)
1033 : : {
1034 [ + + ]: 22214800 : if (jl_is_unionall(t)) {
1035 : 40257 : jl_value_t *u = t;
1036 : 40257 : JL_GC_PUSH1(&u);
1037 : 40257 : u = get_fieldtype(((jl_unionall_t*)t)->body, f, dothrow);
1038 : 40251 : u = jl_type_unionall(((jl_unionall_t*)t)->var, u);
1039 : 40251 : JL_GC_POP();
1040 : 40251 : return u;
1041 : : }
1042 [ + + ]: 22174600 : if (jl_is_uniontype(t)) {
1043 : : jl_value_t **u;
1044 : : jl_value_t *r;
1045 : 11 : JL_GC_PUSHARGS(u, 2);
1046 : 11 : u[0] = get_fieldtype(((jl_uniontype_t*)t)->a, f, 0);
1047 : 11 : u[1] = get_fieldtype(((jl_uniontype_t*)t)->b, f, 0);
1048 [ + + + + : 11 : if (u[0] == jl_bottom_type && u[1] == jl_bottom_type && dothrow) {
+ - ]
1049 : : // error if all types in the union might have
1050 : 1 : get_fieldtype(((jl_uniontype_t*)t)->a, f, 1);
1051 : 0 : get_fieldtype(((jl_uniontype_t*)t)->b, f, 1);
1052 : : }
1053 : 10 : r = jl_type_union(u, 2);
1054 : 10 : JL_GC_POP();
1055 : 10 : return r;
1056 : : }
1057 [ - + ]: 22174500 : if (!jl_is_datatype(t))
1058 : 0 : jl_type_error("fieldtype", (jl_value_t*)jl_datatype_type, t);
1059 : 22174500 : jl_datatype_t *st = (jl_datatype_t*)t;
1060 : : int field_index;
1061 [ + + ]: 22174500 : if (jl_is_long(f)) {
1062 : 22158900 : field_index = jl_unbox_long(f) - 1;
1063 : : }
1064 : : else {
1065 [ - + ]: 15622 : JL_TYPECHK(fieldtype, symbol, f);
1066 : 15622 : field_index = jl_field_index(st, (jl_sym_t*)f, dothrow);
1067 [ - + ]: 15614 : if (field_index == -1)
1068 : 0 : return jl_bottom_type;
1069 : : }
1070 [ + + ]: 22174500 : if (st->name == jl_namedtuple_typename) {
1071 : 21049 : jl_value_t *nm = jl_tparam0(st);
1072 [ + + ]: 21049 : if (jl_is_tuple(nm)) {
1073 : 21029 : int nf = jl_nfields(nm);
1074 [ + - + + ]: 21029 : if (field_index < 0 || field_index >= nf) {
1075 [ + - ]: 1 : if (dothrow)
1076 : 1 : jl_bounds_error(t, f);
1077 : : else
1078 : 0 : return jl_bottom_type;
1079 : : }
1080 : : }
1081 : 21048 : jl_value_t *tt = jl_tparam1(st);
1082 [ + + ]: 21058 : while (jl_is_typevar(tt))
1083 : 10 : tt = ((jl_tvar_t*)tt)->ub;
1084 [ - + ]: 21048 : if (tt == (jl_value_t*)jl_any_type)
1085 : 0 : return (jl_value_t*)jl_any_type;
1086 : 21048 : JL_GC_PUSH1(&f);
1087 [ + + ]: 21048 : if (jl_is_symbol(f))
1088 : 593 : f = jl_box_long(field_index+1);
1089 : 21048 : jl_value_t *ft = get_fieldtype(tt, f, dothrow);
1090 : 21045 : JL_GC_POP();
1091 : 21045 : return ft;
1092 : : }
1093 [ + - ]: 22153500 : jl_svec_t *types = jl_get_fieldtypes(st);
1094 : 22153500 : int nf = jl_svec_len(types);
1095 [ + + + + : 22153500 : if (nf > 0 && field_index >= nf-1 && st->name == jl_tuple_typename) {
+ + ]
1096 : 4084130 : jl_value_t *ft = jl_field_type(st, nf-1);
1097 [ + + ]: 4084130 : if (jl_is_vararg(ft))
1098 : 175 : return jl_unwrap_vararg(ft);
1099 : : }
1100 [ + + + + ]: 22153300 : if (field_index < 0 || field_index >= nf) {
1101 [ + + ]: 13 : if (dothrow)
1102 : 8 : jl_bounds_error(t, f);
1103 : : else
1104 : 5 : return jl_bottom_type;
1105 : : }
1106 : 22153300 : return jl_field_type(st, field_index);
1107 : : }
1108 : :
1109 : 22153500 : JL_CALLABLE(jl_f_fieldtype)
1110 : : {
1111 [ - + - + ]: 22153500 : JL_NARGS(fieldtype, 2, 3);
1112 [ - + ]: 22153500 : if (nargs == 3) {
1113 [ # # ]: 0 : JL_TYPECHK(fieldtype, bool, args[2]);
1114 : : }
1115 : 22153500 : return get_fieldtype(args[0], args[1], 1);
1116 : : }
1117 : :
1118 : 29 : JL_CALLABLE(jl_f_nfields)
1119 : : {
1120 [ - + - + ]: 29 : JL_NARGS(nfields, 1, 1);
1121 : 29 : jl_datatype_t *xt = (jl_datatype_t*)jl_typeof(args[0]);
1122 : 29 : return jl_box_long(jl_datatype_nfields(xt));
1123 : : }
1124 : :
1125 : 770231000 : JL_CALLABLE(jl_f_isdefined)
1126 : : {
1127 : 770231000 : jl_module_t *m = NULL;
1128 : 770231000 : jl_sym_t *s = NULL;
1129 [ + + - + ]: 770231000 : JL_NARGS(isdefined, 2, 3);
1130 : 770231000 : enum jl_memory_order order = jl_memory_order_unspecified;
1131 [ + + ]: 770231000 : if (nargs == 3) {
1132 [ - + ]: 192 : JL_TYPECHK(isdefined, symbol, args[2]);
1133 : 192 : order = jl_get_atomic_order_checked((jl_sym_t*)args[2], 1, 0);
1134 : : }
1135 [ + + ]: 770231000 : if (jl_is_module(args[0])) {
1136 [ + + ]: 746034000 : JL_TYPECHK(isdefined, symbol, args[1]);
1137 : 746034000 : m = (jl_module_t*)args[0];
1138 : 746034000 : s = (jl_sym_t*)args[1];
1139 [ + + ]: 746034000 : return jl_boundp(m, s) ? jl_true : jl_false; // is seq_cst already
1140 : : }
1141 : 24197200 : jl_datatype_t *vt = (jl_datatype_t*)jl_typeof(args[0]);
1142 [ - + ]: 24197200 : assert(jl_is_datatype(vt));
1143 : : size_t idx;
1144 [ + + ]: 24197200 : if (jl_is_long(args[1])) {
1145 : 10856700 : idx = jl_unbox_long(args[1]) - 1;
1146 [ + + ]: 10856700 : if (idx >= jl_datatype_nfields(vt)) {
1147 [ - + ]: 24 : if (order != jl_memory_order_unspecified)
1148 : 0 : jl_atomic_error("isdefined: atomic ordering cannot be specified for nonexistent field");
1149 : 24 : return jl_false;
1150 : : }
1151 : : }
1152 : : else {
1153 [ - + ]: 13340500 : JL_TYPECHK(isdefined, symbol, args[1]);
1154 : 13340500 : idx = jl_field_index(vt, (jl_sym_t*)args[1], 0);
1155 [ + + ]: 13340500 : if ((int)idx == -1) {
1156 [ - + ]: 5421080 : if (order != jl_memory_order_unspecified)
1157 : 0 : jl_atomic_error("isdefined: atomic ordering cannot be specified for nonexistent field");
1158 : 5421080 : return jl_false;
1159 : : }
1160 : : }
1161 : 18776100 : int isatomic = jl_field_isatomic(vt, idx);
1162 [ + + + + : 18776100 : if (!isatomic && order != jl_memory_order_notatomic && order != jl_memory_order_unspecified)
+ + ]
1163 : 48 : jl_atomic_error("isdefined: non-atomic field cannot be accessed atomically");
1164 [ + + + + ]: 18776000 : if (isatomic && order == jl_memory_order_notatomic)
1165 : 12 : jl_atomic_error("isdefined: atomic field cannot be accessed non-atomically");
1166 : 18776000 : int v = jl_field_isdefined(args[0], idx);
1167 [ + + ]: 18776000 : if (v == 2) {
1168 [ + + ]: 2216560 : if (order > jl_memory_order_notatomic)
1169 : 24 : jl_fence(); // isbits case has no ordering already
1170 : : }
1171 : : else {
1172 [ + + + + ]: 16559500 : if (order >= jl_memory_order_acq_rel || order == jl_memory_order_acquire)
1173 : 12 : jl_fence(); // `v` already gave at least consume ordering
1174 : : }
1175 [ + + ]: 18776000 : return v ? jl_true : jl_false;
1176 : : }
1177 : :
1178 : :
1179 : : // module bindings
1180 : :
1181 : 646752000 : JL_CALLABLE(jl_f_getglobal)
1182 : : {
1183 : 646752000 : enum jl_memory_order order = jl_memory_order_monotonic;
1184 [ - + - + ]: 646752000 : JL_NARGS(getglobal, 2, 3);
1185 [ - + ]: 646752000 : if (nargs == 3) {
1186 [ # # ]: 0 : JL_TYPECHK(getglobal, symbol, args[2]);
1187 : 0 : order = jl_get_atomic_order_checked((jl_sym_t*)args[2], 1, 0);
1188 : : }
1189 [ - + ]: 646752000 : JL_TYPECHK(getglobal, module, args[0]);
1190 [ - + ]: 646752000 : JL_TYPECHK(getglobal, symbol, args[1]);
1191 [ - + ]: 646752000 : if (order == jl_memory_order_notatomic)
1192 : 0 : jl_atomic_error("getglobal: module binding cannot be read non-atomically");
1193 : 646752000 : jl_value_t *v = jl_eval_global_var((jl_module_t*)args[0], (jl_sym_t*)args[1]);
1194 : : // is seq_cst already, no fence needed
1195 : 646752000 : return v;
1196 : : }
1197 : :
1198 : 203 : JL_CALLABLE(jl_f_setglobal)
1199 : : {
1200 : 203 : enum jl_memory_order order = jl_memory_order_monotonic;
1201 [ - + - + ]: 203 : JL_NARGS(setglobal!, 3, 4);
1202 [ + + ]: 203 : if (nargs == 4) {
1203 [ - + ]: 7 : JL_TYPECHK(setglobal!, symbol, args[3]);
1204 : 7 : order = jl_get_atomic_order_checked((jl_sym_t*)args[3], 0, 1);
1205 : : }
1206 [ - + ]: 203 : JL_TYPECHK(setglobal!, module, args[0]);
1207 [ - + ]: 203 : JL_TYPECHK(setglobal!, symbol, args[1]);
1208 [ + + ]: 203 : if (order == jl_memory_order_notatomic)
1209 : 2 : jl_atomic_error("setglobal!: module binding cannot be written non-atomically");
1210 : : // is seq_cst already, no fence needed
1211 : 201 : jl_binding_t *b = jl_get_binding_wr_or_error((jl_module_t*)args[0], (jl_sym_t*)args[1]);
1212 : 201 : jl_checked_assignment(b, args[2]);
1213 : 200 : return args[2];
1214 : : }
1215 : :
1216 : 23448 : JL_CALLABLE(jl_f_get_binding_type)
1217 : : {
1218 [ - + - + ]: 23448 : JL_NARGS(get_binding_type, 2, 2);
1219 [ - + ]: 23448 : JL_TYPECHK(get_binding_type, module, args[0]);
1220 [ - + ]: 23448 : JL_TYPECHK(get_binding_type, symbol, args[1]);
1221 : 23448 : jl_module_t *mod = (jl_module_t*)args[0];
1222 : 23448 : jl_sym_t *sym = (jl_sym_t*)args[1];
1223 : 23448 : jl_value_t *ty = jl_binding_type(mod, sym);
1224 [ + + ]: 23448 : if (ty == (jl_value_t*)jl_nothing) {
1225 : 1558 : jl_binding_t *b = jl_get_binding_wr(mod, sym, 0);
1226 [ + + + + ]: 1558 : if (b && b->owner == mod) {
1227 : 107 : jl_value_t *old_ty = NULL;
1228 : 107 : jl_atomic_cmpswap_relaxed(&b->ty, &old_ty, (jl_value_t*)jl_any_type);
1229 : 107 : return jl_atomic_load_relaxed(&b->ty);
1230 : : }
1231 : 1451 : return (jl_value_t*)jl_any_type;
1232 : : }
1233 : 21890 : return ty;
1234 : : }
1235 : :
1236 : 45 : JL_CALLABLE(jl_f_set_binding_type)
1237 : : {
1238 [ - + - + ]: 45 : JL_NARGS(set_binding_type!, 2, 3);
1239 [ - + ]: 45 : JL_TYPECHK(set_binding_type!, module, args[0]);
1240 [ - + ]: 45 : JL_TYPECHK(set_binding_type!, symbol, args[1]);
1241 [ + - ]: 45 : jl_value_t *ty = nargs == 2 ? (jl_value_t*)jl_any_type : args[2];
1242 [ - + ]: 45 : JL_TYPECHK(set_binding_type!, type, ty);
1243 : 45 : jl_binding_t *b = jl_get_binding_wr((jl_module_t*)args[0], (jl_sym_t*)args[1], 1);
1244 : 45 : jl_value_t *old_ty = NULL;
1245 [ + + + - ]: 45 : if (!jl_atomic_cmpswap_relaxed(&b->ty, &old_ty, ty) && ty != old_ty) {
1246 [ - + ]: 4 : if (nargs == 2)
1247 : 0 : return jl_nothing;
1248 : 4 : jl_errorf("cannot set type for global %s. It already has a value or is already set to a different type.",
1249 : : jl_symbol_name(b->name));
1250 : : }
1251 : 41 : return jl_nothing;
1252 : : }
1253 : :
1254 : :
1255 : : // apply_type -----------------------------------------------------------------
1256 : :
1257 : 169174000 : int jl_valid_type_param(jl_value_t *v)
1258 : : {
1259 [ + + ]: 169174000 : if (jl_is_tuple(v)) {
1260 : : // NOTE: tuples of symbols are not currently bits types, but have been
1261 : : // allowed as type parameters. this is a bit ugly.
1262 : 1640280 : jl_value_t *tt = jl_typeof(v);
1263 : 1640280 : size_t i, l = jl_nparams(tt);
1264 [ + + ]: 2326150 : for(i=0; i < l; i++) {
1265 : 685867 : jl_value_t *pi = jl_tparam(tt,i);
1266 [ + + + + ]: 685867 : if (!(pi == (jl_value_t*)jl_symbol_type || jl_isbits(pi)))
1267 : 1 : return 0;
1268 : : }
1269 : 1640280 : return 1;
1270 : : }
1271 [ + + ]: 167533000 : if (jl_is_vararg(v))
1272 : 6 : return 0;
1273 : : // TODO: maybe more things
1274 [ + + + + : 167533000 : return jl_is_type(v) || jl_is_typevar(v) || jl_is_symbol(v) || jl_isbits(jl_typeof(v));
+ + + + ]
1275 : : }
1276 : :
1277 : 82052300 : JL_CALLABLE(jl_f_apply_type)
1278 : : {
1279 [ - + ]: 82052300 : JL_NARGSV(apply_type, 1);
1280 : : int i;
1281 [ + + ]: 82052300 : if (args[0] == (jl_value_t*)jl_anytuple_type) {
1282 [ + + ]: 175687000 : for(i=1; i < nargs; i++) {
1283 : 129785000 : jl_value_t *pi = args[i];
1284 : : // TODO: should possibly only allow Types and TypeVars, but see
1285 : : // https://github.com/JuliaLang/julia/commit/85f45974a581ab9af955bac600b90d9ab00f093b#commitcomment-13041922
1286 [ + + ]: 129785000 : if (jl_is_vararg(pi)) {
1287 [ + + ]: 309231 : if (i != nargs-1)
1288 : 2 : jl_type_error_rt("Tuple", "non-final parameter", (jl_value_t*)jl_type_type, pi);
1289 : : }
1290 [ - + ]: 129475000 : else if (!jl_valid_type_param(pi)) {
1291 : 0 : jl_type_error_rt("Tuple", "parameter", (jl_value_t*)jl_type_type, pi);
1292 : : }
1293 : : }
1294 : 45902600 : return (jl_value_t*)jl_apply_tuple_type_v(&args[1], nargs-1);
1295 : : }
1296 [ + + ]: 36149800 : else if (args[0] == (jl_value_t*)jl_uniontype_type) {
1297 : : // Union{} has extra restrictions, so it needs to be checked after
1298 : : // substituting typevars (a valid_type_param check here isn't sufficient).
1299 : 2713060 : return (jl_value_t*)jl_type_union(&args[1], nargs-1);
1300 : : }
1301 [ + + ]: 33436700 : else if (jl_is_vararg(args[0])) {
1302 : 270426 : jl_vararg_t *vm = (jl_vararg_t*)args[0];
1303 [ + - ]: 270426 : if (!vm->T) {
1304 [ - + - + ]: 270426 : JL_NARGS(apply_type, 2, 3);
1305 [ + + ]: 270426 : return (jl_value_t*)jl_wrap_vararg(args[1], nargs == 3 ? args[2] : NULL);
1306 : : }
1307 [ # # ]: 0 : else if (!vm->N) {
1308 [ # # # # ]: 0 : JL_NARGS(apply_type, 2, 2);
1309 : 0 : return (jl_value_t*)jl_wrap_vararg(vm->T, args[1]);
1310 : : }
1311 : : }
1312 [ + - ]: 33166300 : else if (jl_is_unionall(args[0])) {
1313 [ + + ]: 72004300 : for(i=1; i < nargs; i++) {
1314 : 38838100 : jl_value_t *pi = args[i];
1315 [ + + ]: 38838100 : if (!jl_valid_type_param(pi)) {
1316 [ - + ]: 8 : jl_type_error_rt("Type", "parameter",
1317 : 8 : jl_isa(pi, (jl_value_t*)jl_number_type) ?
1318 : : (jl_value_t*)jl_long_type : (jl_value_t*)jl_type_type,
1319 : : pi);
1320 : : }
1321 : : }
1322 : 33166300 : return jl_apply_type(args[0], &args[1], nargs-1);
1323 : : }
1324 : 0 : jl_type_error("Type{...} expression", (jl_value_t*)jl_unionall_type, args[0]);
1325 : : }
1326 : :
1327 : : // generic function reflection ------------------------------------------------
1328 : :
1329 : 93176 : JL_CALLABLE(jl_f_applicable)
1330 : : {
1331 [ - + ]: 93176 : JL_NARGSV(applicable, 1);
1332 : 93176 : size_t world = jl_current_task->world_age;
1333 [ + + ]: 93176 : return jl_method_lookup(args, nargs, world) != NULL ? jl_true : jl_false;
1334 : : }
1335 : :
1336 : 2932 : JL_CALLABLE(jl_f_invoke)
1337 : : {
1338 [ - + ]: 2932 : JL_NARGSV(invoke, 2);
1339 : 2932 : jl_value_t *argtypes = args[1];
1340 : 2932 : JL_GC_PUSH1(&argtypes);
1341 [ + + ]: 2932 : if (!jl_is_tuple_type(jl_unwrap_unionall(args[1])))
1342 : 1 : jl_type_error("invoke", (jl_value_t*)jl_anytuple_type_type, args[1]);
1343 [ + + ]: 2931 : if (!jl_tuple_isa(&args[2], nargs - 2, (jl_datatype_t*)argtypes))
1344 : 2 : jl_error("invoke: argument type error");
1345 : 2929 : jl_value_t *res = jl_gf_invoke(argtypes, args[0], &args[2], nargs - 1);
1346 : 2926 : JL_GC_POP();
1347 : 2926 : return res;
1348 : : }
1349 : :
1350 : 32 : JL_CALLABLE(jl_f_invoke_kwsorter)
1351 : : {
1352 [ - + ]: 32 : JL_NARGSV(invoke, 3);
1353 : 32 : jl_value_t *kwargs = args[0];
1354 : : // args[1] is `invoke` itself
1355 : 32 : jl_value_t *func = args[2];
1356 : 32 : jl_value_t *argtypes = args[3];
1357 : 32 : jl_value_t *kws = jl_get_keyword_sorter(func);
1358 : 32 : JL_GC_PUSH1(&argtypes);
1359 [ + - ]: 32 : if (jl_is_tuple_type(argtypes)) {
1360 : : // construct a tuple type for invoking a keyword sorter by putting the kw container type
1361 : : // and the type of the function at the front.
1362 : 32 : size_t i, nt = jl_nparams(argtypes) + 2;
1363 [ + - ]: 32 : if (nt < jl_page_size/sizeof(jl_value_t*)) {
1364 : 32 : jl_value_t **types = (jl_value_t**)alloca(nt*sizeof(jl_value_t*));
1365 : 32 : types[0] = (jl_value_t*)jl_namedtuple_type;
1366 [ + + ]: 32 : types[1] = jl_is_type(func) ? (jl_value_t*)jl_wrap_Type(func) : jl_typeof(func);
1367 [ + + ]: 92 : for (i = 2; i < nt; i++)
1368 : 60 : types[i] = jl_tparam(argtypes, i - 2);
1369 : 32 : argtypes = (jl_value_t*)jl_apply_tuple_type_v(types, nt);
1370 : : }
1371 : : else {
1372 : 0 : jl_svec_t *types = jl_alloc_svec_uninit(nt);
1373 : 0 : JL_GC_PUSH1(&types);
1374 : 0 : jl_svecset(types, 0, jl_namedtuple_type);
1375 [ # # ]: 0 : jl_svecset(types, 1, jl_is_type(func) ? (jl_value_t*)jl_wrap_Type(func) : jl_typeof(func));
1376 [ # # ]: 0 : for (i = 2; i < nt; i++)
1377 : 0 : jl_svecset(types, i, jl_tparam(argtypes, i - 2));
1378 : 0 : argtypes = (jl_value_t*)jl_apply_tuple_type(types);
1379 : 0 : JL_GC_POP();
1380 : : }
1381 : : }
1382 : : else {
1383 : : // invoke will throw an error
1384 : : }
1385 : 32 : args[0] = kws;
1386 : 32 : args[1] = argtypes;
1387 : 32 : args[2] = kwargs;
1388 : 32 : args[3] = func;
1389 : 32 : jl_value_t *res = jl_f_invoke(NULL, args, nargs);
1390 : 32 : JL_GC_POP();
1391 : 32 : return res;
1392 : : }
1393 : :
1394 : : // Expr constructor for internal use ------------------------------------------
1395 : :
1396 : 122721000 : jl_expr_t *jl_exprn(jl_sym_t *head, size_t n)
1397 : : {
1398 : 122721000 : jl_task_t *ct = jl_current_task;
1399 : 122721000 : jl_array_t *ar = jl_alloc_vec_any(n);
1400 : 122723000 : JL_GC_PUSH1(&ar);
1401 : 122723000 : jl_expr_t *ex = (jl_expr_t*)jl_gc_alloc(ct->ptls, sizeof(jl_expr_t),
1402 : : jl_expr_type);
1403 : 122720000 : ex->head = head;
1404 : 122720000 : ex->args = ar;
1405 : 122720000 : JL_GC_POP();
1406 : 122720000 : return ex;
1407 : : }
1408 : :
1409 : 75460600 : JL_CALLABLE(jl_f__expr)
1410 : : {
1411 : 75460600 : jl_task_t *ct = jl_current_task;
1412 [ - + ]: 75460600 : JL_NARGSV(Expr, 1);
1413 [ - + ]: 75460600 : JL_TYPECHK(Expr, symbol, args[0]);
1414 : 75460600 : jl_array_t *ar = jl_alloc_vec_any(nargs-1);
1415 : 75460600 : JL_GC_PUSH1(&ar);
1416 [ + + ]: 296541000 : for(size_t i=0; i < nargs-1; i++)
1417 : 221080000 : jl_array_ptr_set(ar, i, args[i+1]);
1418 : 75460300 : jl_expr_t *ex = (jl_expr_t*)jl_gc_alloc(ct->ptls, sizeof(jl_expr_t),
1419 : : jl_expr_type);
1420 : 75453500 : ex->head = (jl_sym_t*)args[0];
1421 : 75453500 : ex->args = ar;
1422 : 75453500 : JL_GC_POP();
1423 : 75453500 : return (jl_value_t*)ex;
1424 : : }
1425 : :
1426 : : // Typevar constructor for internal use
1427 : 114632000 : JL_DLLEXPORT jl_tvar_t *jl_new_typevar(jl_sym_t *name, jl_value_t *lb, jl_value_t *ub)
1428 : : {
1429 [ + + + + : 114632000 : if (lb != jl_bottom_type && !jl_is_type(lb) && !jl_is_typevar(lb))
+ + ]
1430 : 2 : jl_type_error_rt("TypeVar", "lower bound", (jl_value_t *)jl_type_type, lb);
1431 [ + + + + : 114632000 : if (ub != (jl_value_t *)jl_any_type && !jl_is_type(ub) && !jl_is_typevar(ub))
+ + ]
1432 : 4 : jl_type_error_rt("TypeVar", "upper bound", (jl_value_t *)jl_type_type, ub);
1433 : 114632000 : jl_task_t *ct = jl_current_task;
1434 : 114632000 : jl_tvar_t *tv = (jl_tvar_t *)jl_gc_alloc(ct->ptls, sizeof(jl_tvar_t), jl_tvar_type);
1435 : 114632000 : tv->name = name;
1436 : 114632000 : tv->lb = lb;
1437 : 114632000 : tv->ub = ub;
1438 : 114632000 : return tv;
1439 : : }
1440 : :
1441 : 418592 : JL_CALLABLE(jl_f__typevar)
1442 : : {
1443 [ - + - + ]: 418592 : JL_NARGS(TypeVar, 3, 3);
1444 [ - + ]: 418592 : JL_TYPECHK(TypeVar, symbol, args[0]);
1445 : 418592 : return (jl_value_t *)jl_new_typevar((jl_sym_t*)args[0], args[1], args[2]);
1446 : : }
1447 : :
1448 : : // arrays ---------------------------------------------------------------------
1449 : :
1450 : 5694 : JL_CALLABLE(jl_f_arraysize)
1451 : : {
1452 [ - + - + ]: 5694 : JL_NARGS(arraysize, 2, 2);
1453 [ - + ]: 5694 : JL_TYPECHK(arraysize, array, args[0]);
1454 : 5694 : jl_array_t *a = (jl_array_t*)args[0];
1455 : 5694 : size_t nd = jl_array_ndims(a);
1456 [ - + ]: 5694 : JL_TYPECHK(arraysize, long, args[1]);
1457 : 5694 : int dno = jl_unbox_long(args[1]);
1458 [ - + ]: 5694 : if (dno < 1)
1459 : 0 : jl_error("arraysize: dimension out of range");
1460 [ - + ]: 5694 : if (dno > nd)
1461 : 0 : return jl_box_long(1);
1462 : 5694 : return jl_box_long((&a->nrows)[dno-1]);
1463 : : }
1464 : :
1465 : 22389200 : static size_t array_nd_index(jl_array_t *a, jl_value_t **args, size_t nidxs,
1466 : : const char *fname)
1467 : : {
1468 : 22389200 : size_t i = 0;
1469 : 22389200 : size_t k, stride = 1;
1470 : 22389200 : size_t nd = jl_array_ndims(a);
1471 [ + + ]: 44779700 : for (k = 0; k < nidxs; k++) {
1472 [ - + ]: 22390400 : if (!jl_is_long(args[k]))
1473 : 0 : jl_type_error(fname, (jl_value_t*)jl_long_type, args[k]);
1474 : 22390400 : size_t ii = jl_unbox_long(args[k]) - 1;
1475 : 22390400 : i += ii * stride;
1476 [ + + ]: 22390400 : size_t d = (k >= nd) ? 1 : jl_array_dim(a, k);
1477 [ + + - + ]: 22390400 : if (k < nidxs - 1 && ii >= d)
1478 : 0 : jl_bounds_error_v((jl_value_t*)a, args, nidxs);
1479 : 22390400 : stride *= d;
1480 : : }
1481 [ - + ]: 22389200 : for (; k < nd; k++)
1482 : 0 : stride *= jl_array_dim(a, k);
1483 [ - + ]: 22389200 : if (i >= stride)
1484 : 0 : jl_bounds_error_v((jl_value_t*)a, args, nidxs);
1485 : 22389200 : return i;
1486 : : }
1487 : :
1488 : 14483500 : JL_CALLABLE(jl_f_arrayref)
1489 : : {
1490 [ - + ]: 14483500 : JL_NARGSV(arrayref, 3);
1491 [ - + ]: 14483500 : JL_TYPECHK(arrayref, bool, args[0]);
1492 [ - + ]: 14483500 : JL_TYPECHK(arrayref, array, args[1]);
1493 : 14483500 : jl_array_t *a = (jl_array_t*)args[1];
1494 : 14483500 : size_t i = array_nd_index(a, &args[2], nargs - 2, "arrayref");
1495 : 14483500 : return jl_arrayref(a, i);
1496 : : }
1497 : :
1498 : 0 : JL_CALLABLE(jl_f_const_arrayref)
1499 : : {
1500 : 0 : return jl_f_arrayref(F, args, nargs);
1501 : : }
1502 : :
1503 : 7905700 : JL_CALLABLE(jl_f_arrayset)
1504 : : {
1505 [ - + ]: 7905700 : JL_NARGSV(arrayset, 4);
1506 [ - + ]: 7905700 : JL_TYPECHK(arrayset, bool, args[0]);
1507 [ - + ]: 7905700 : JL_TYPECHK(arrayset, array, args[1]);
1508 : 7905700 : jl_array_t *a = (jl_array_t*)args[1];
1509 : 7905700 : size_t i = array_nd_index(a, &args[3], nargs - 3, "arrayset");
1510 : 7905700 : jl_arrayset(a, args[2], i);
1511 : 7905700 : return args[1];
1512 : : }
1513 : :
1514 : : // type definition ------------------------------------------------------------
1515 : :
1516 : 25832 : JL_CALLABLE(jl_f__structtype)
1517 : : {
1518 [ - + - + ]: 25832 : JL_NARGS(_structtype, 7, 7);
1519 [ - + ]: 25832 : JL_TYPECHK(_structtype, module, args[0]);
1520 [ - + ]: 25832 : JL_TYPECHK(_structtype, symbol, args[1]);
1521 [ - + ]: 25832 : JL_TYPECHK(_structtype, simplevector, args[2]);
1522 [ - + ]: 25832 : JL_TYPECHK(_structtype, simplevector, args[3]);
1523 [ - + ]: 25832 : JL_TYPECHK(_structtype, simplevector, args[4]);
1524 [ - + ]: 25832 : JL_TYPECHK(_structtype, bool, args[5]);
1525 [ - + ]: 25832 : JL_TYPECHK(_structtype, long, args[6]);
1526 : 25832 : jl_value_t *fieldnames = args[3];
1527 : 25832 : jl_value_t *fieldattrs = args[4];
1528 : 25832 : jl_datatype_t *dt = NULL;
1529 : 25832 : dt = jl_new_datatype((jl_sym_t*)args[1], (jl_module_t*)args[0], NULL, (jl_svec_t*)args[2],
1530 : : (jl_svec_t*)fieldnames, NULL, (jl_svec_t*)fieldattrs,
1531 : 25832 : 0, args[5]==jl_true ? 1 : 0, jl_unbox_long(args[6]));
1532 : 25831 : return dt->name->wrapper;
1533 : : }
1534 : :
1535 : 195 : JL_CALLABLE(jl_f__abstracttype)
1536 : : {
1537 [ - + - + ]: 195 : JL_NARGS(_abstracttype, 3, 3);
1538 [ - + ]: 195 : JL_TYPECHK(_abstracttype, module, args[0]);
1539 [ - + ]: 195 : JL_TYPECHK(_abstracttype, symbol, args[1]);
1540 [ - + ]: 195 : JL_TYPECHK(_abstracttype, simplevector, args[2]);
1541 : 195 : jl_datatype_t *dt = jl_new_abstracttype(args[1], (jl_module_t*)args[0], NULL, (jl_svec_t*)args[2]);
1542 : 195 : return dt->name->wrapper;
1543 : : }
1544 : :
1545 : 93 : JL_CALLABLE(jl_f__primitivetype)
1546 : : {
1547 [ - + - + ]: 93 : JL_NARGS(_primitivetype, 4, 4);
1548 [ - + ]: 93 : JL_TYPECHK(_primitivetype, module, args[0]);
1549 [ - + ]: 93 : JL_TYPECHK(_primitivetype, symbol, args[1]);
1550 [ - + ]: 93 : JL_TYPECHK(_primitivetype, simplevector, args[2]);
1551 : 93 : jl_sym_t *name = (jl_sym_t*)args[1];
1552 : 93 : jl_value_t *vnb = args[3];
1553 [ - + ]: 93 : if (!jl_is_long(vnb))
1554 : 0 : jl_errorf("invalid declaration of primitive type %s",
1555 : : jl_symbol_name((jl_sym_t*)name));
1556 : 93 : ssize_t nb = jl_unbox_long(vnb);
1557 [ + - + - : 93 : if (nb < 1 || nb >= (1 << 23) || (nb & 7) != 0)
- + ]
1558 : 0 : jl_errorf("invalid number of bits in primitive type %s",
1559 : : jl_symbol_name((jl_sym_t*)name));
1560 : 93 : jl_datatype_t *dt = jl_new_primitivetype(args[1], (jl_module_t*)args[0], NULL, (jl_svec_t*)args[2], nb);
1561 : 93 : return dt->name->wrapper;
1562 : : }
1563 : :
1564 : 26118 : static void jl_set_datatype_super(jl_datatype_t *tt, jl_value_t *super)
1565 : : {
1566 : 26118 : const char *error = NULL;
1567 [ + + ]: 26118 : if (!jl_is_datatype(super))
1568 : 2 : error = "can only subtype data types";
1569 [ - + ]: 26116 : else if (tt->super != NULL)
1570 : 0 : error = "type already has a supertype";
1571 [ + + ]: 26116 : else if (tt->name == ((jl_datatype_t*)super)->name)
1572 : 1 : error = "a type cannot subtype itself";
1573 [ + + ]: 26115 : else if (jl_is_tuple_type(super))
1574 : 1 : error = "cannot subtype a tuple type";
1575 [ + + ]: 26114 : else if (jl_is_namedtuple_type(super))
1576 : 1 : error = "cannot subtype a named tuple type";
1577 [ + + ]: 26113 : else if (jl_subtype(super, (jl_value_t*)jl_type_type))
1578 : 2 : error = "cannot add subtypes to Type";
1579 [ + + ]: 26111 : else if (jl_subtype(super, (jl_value_t*)jl_builtin_type))
1580 : 1 : error = "cannot add subtypes to Core.Builtin";
1581 [ + + ]: 26110 : else if (!jl_is_abstracttype(super))
1582 : 1 : error = "can only subtype abstract types";
1583 [ + + ]: 26118 : if (error)
1584 : 9 : jl_errorf("invalid subtyping in definition of %s: %s.", jl_symbol_name(tt->name->name), error);
1585 : 26109 : tt->super = (jl_datatype_t*)super;
1586 : 26109 : jl_gc_wb(tt, tt->super);
1587 : 26109 : }
1588 : :
1589 : 26118 : JL_CALLABLE(jl_f__setsuper)
1590 : : {
1591 [ - + - + ]: 26118 : JL_NARGS(_setsuper!, 2, 2);
1592 : 26118 : jl_datatype_t *dt = (jl_datatype_t*)jl_unwrap_unionall(args[0]);
1593 [ - + ]: 26118 : JL_TYPECHK(_setsuper!, datatype, (jl_value_t*)dt);
1594 : 26118 : jl_set_datatype_super(dt, args[1]);
1595 : 26109 : return jl_nothing;
1596 : : }
1597 : :
1598 : 1 : JL_CALLABLE(jl_f_donotdelete)
1599 : : {
1600 : 1 : return jl_nothing;
1601 : : }
1602 : :
1603 : 330295 : JL_CALLABLE(jl_f_finalizer)
1604 : : {
1605 : : // NOTE the compiler may temporarily insert additional argument for the later inlining pass
1606 [ - + - + ]: 330295 : JL_NARGS(finalizer, 2, 4);
1607 : 330295 : jl_task_t *ct = jl_current_task;
1608 : 330295 : jl_gc_add_finalizer_(ct->ptls, args[1], args[0]);
1609 : 330295 : return jl_nothing;
1610 : : }
1611 : :
1612 : 27 : static int equiv_field_types(jl_value_t *old, jl_value_t *ft)
1613 : : {
1614 : 27 : size_t nf = jl_svec_len(ft);
1615 [ - + ]: 27 : if (jl_svec_len(old) != nf)
1616 : 0 : return 0;
1617 : : size_t i;
1618 [ + + ]: 62 : for (i = 0; i < nf; i++) {
1619 : 38 : jl_value_t *ta = jl_svecref(old, i);
1620 : 38 : jl_value_t *tb = jl_svecref(ft, i);
1621 [ + + ]: 38 : if (jl_has_free_typevars(ta)) {
1622 [ + - + + ]: 29 : if (!jl_has_free_typevars(tb) || !jl_egal(ta, tb))
1623 : 1 : return 0;
1624 : : }
1625 [ + - + - : 18 : else if (jl_has_free_typevars(tb) || jl_typeof(ta) != jl_typeof(tb) ||
+ + ]
1626 : 9 : !jl_types_equal(ta, tb)) {
1627 : 2 : return 0;
1628 : : }
1629 : : }
1630 : 24 : return 1;
1631 : : }
1632 : :
1633 : : // If a field can reference its enclosing type, then the inlining
1634 : : // recursive depth is not statically bounded for some layouts, so we cannot
1635 : : // inline it. The only way fields can reference this type (due to
1636 : : // syntax-enforced restrictions) is via being passed as a type parameter. Thus
1637 : : // we can conservatively check this by examining only the parameters of the
1638 : : // dependent types.
1639 : : // affects_layout is a hack introduced by #35275 to workaround a problem
1640 : : // introduced by #34223: it checks whether we will potentially need to
1641 : : // compute the layout of the object before we have fully computed the types of
1642 : : // the fields during recursion over the allocation of the parameters for the
1643 : : // field types (of the concrete subtypes)
1644 : 14839 : static int references_name(jl_value_t *p, jl_typename_t *name, int affects_layout) JL_NOTSAFEPOINT
1645 : : {
1646 [ + + ]: 14839 : if (jl_is_uniontype(p))
1647 [ + - + + ]: 196 : return references_name(((jl_uniontype_t*)p)->a, name, affects_layout) ||
1648 : 98 : references_name(((jl_uniontype_t*)p)->b, name, affects_layout);
1649 [ + + ]: 14741 : if (jl_is_unionall(p))
1650 [ + - ]: 68 : return references_name((jl_value_t*)((jl_unionall_t*)p)->var->lb, name, 0) ||
1651 [ + - + + ]: 68 : references_name((jl_value_t*)((jl_unionall_t*)p)->var->ub, name, 0) ||
1652 : 34 : references_name(((jl_unionall_t*)p)->body, name, affects_layout);
1653 [ + + ]: 14707 : if (jl_is_typevar(p))
1654 : 5186 : return 0; // already checked by unionall, if applicable
1655 [ + + ]: 9521 : if (jl_is_datatype(p)) {
1656 : 9261 : jl_datatype_t *dp = (jl_datatype_t*)p;
1657 [ + + + + ]: 9261 : if (affects_layout && dp->name == name)
1658 : 8 : return 1;
1659 : : // affects_layout checks whether we will need to attempt to layout this
1660 : : // type (based on whether all copies of it have the same layout) in
1661 : : // that case, we still need to check the recursive parameters for
1662 : : // layout recursion happening also, but we know it won't itself cause
1663 : : // problems for the layout computation
1664 : 9253 : affects_layout = ((jl_datatype_t*)jl_unwrap_unionall(dp->name->wrapper))->layout == NULL;
1665 : 9253 : size_t i, l = jl_nparams(p);
1666 [ + + ]: 12785 : for (i = 0; i < l; i++) {
1667 [ + + ]: 3536 : if (references_name(jl_tparam(p, i), name, affects_layout))
1668 : 4 : return 1;
1669 : : }
1670 : : }
1671 : 9509 : return 0;
1672 : : }
1673 : :
1674 : :
1675 : 26096 : JL_CALLABLE(jl_f__typebody)
1676 : : {
1677 [ - + - + ]: 26096 : JL_NARGS(_typebody!, 1, 2);
1678 : 26096 : jl_datatype_t *dt = (jl_datatype_t*)jl_unwrap_unionall(args[0]);
1679 [ - + ]: 26096 : JL_TYPECHK(_typebody!, datatype, (jl_value_t*)dt);
1680 [ + + ]: 26096 : if (nargs == 2) {
1681 : 25809 : jl_value_t *ft = args[1];
1682 [ - + ]: 25809 : JL_TYPECHK(_typebody!, simplevector, ft);
1683 : 25809 : size_t nf = jl_svec_len(ft);
1684 [ + + ]: 34838 : for (size_t i = 0; i < nf; i++) {
1685 : 9030 : jl_value_t *elt = jl_svecref(ft, i);
1686 [ + + + + ]: 9030 : if (!jl_is_type(elt) && !jl_is_typevar(elt)) {
1687 : 1 : jl_type_error_rt(jl_symbol_name(dt->name->name),
1688 : : "type definition",
1689 : : (jl_value_t*)jl_type_type, elt);
1690 : : }
1691 : : }
1692 [ + + ]: 25808 : if (dt->types != NULL) {
1693 [ + + ]: 27 : if (!equiv_field_types((jl_value_t*)dt->types, ft))
1694 : 3 : jl_errorf("invalid redefinition of type %s", jl_symbol_name(dt->name->name));
1695 : : }
1696 : : else {
1697 : 25781 : dt->types = (jl_svec_t*)ft;
1698 : 25781 : jl_gc_wb(dt, ft);
1699 : : // If a supertype can reference the same type, then we may not be
1700 : : // able to compute the layout of the object before needing to
1701 : : // publish it, so we must assume it cannot be inlined, if that
1702 : : // check passes, then we also still need to check the fields too.
1703 [ + + + + : 25781 : if (!dt->name->mutabl && (nf == 0 || !references_name((jl_value_t*)dt->super, dt->name, 1))) {
+ + ]
1704 : 25262 : int mayinlinealloc = 1;
1705 : : size_t i;
1706 [ + + ]: 32563 : for (i = 0; i < nf; i++) {
1707 : 7308 : jl_value_t *fld = jl_svecref(ft, i);
1708 [ + + ]: 7308 : if (references_name(fld, dt->name, 1)) {
1709 : 7 : mayinlinealloc = 0;
1710 : 7 : break;
1711 : : }
1712 : : }
1713 : 25262 : dt->name->mayinlinealloc = mayinlinealloc;
1714 : : }
1715 : : }
1716 : : }
1717 : :
1718 [ + - + + ]: 52184 : JL_TRY {
1719 : 26092 : jl_reinstantiate_inner_types(dt);
1720 : : }
1721 [ # # ]: 0 : JL_CATCH {
1722 : 0 : dt->name->partial = NULL;
1723 : 0 : jl_rethrow();
1724 : : }
1725 : :
1726 [ + + ]: 26092 : if (jl_is_structtype(dt))
1727 : 25805 : jl_compute_field_offsets(dt);
1728 : 26092 : return jl_nothing;
1729 : : }
1730 : :
1731 : : // this is a heuristic for allowing "redefining" a type to something identical
1732 : 40 : static int equiv_type(jl_value_t *ta, jl_value_t *tb)
1733 : : {
1734 : 40 : jl_datatype_t *dta = (jl_datatype_t*)jl_unwrap_unionall(ta);
1735 [ - + ]: 40 : if (!jl_is_datatype(dta))
1736 : 0 : return 0;
1737 : 40 : jl_datatype_t *dtb = (jl_datatype_t*)jl_unwrap_unionall(tb);
1738 [ + - ]: 40 : if (!(jl_typeof(dta) == jl_typeof(dtb) &&
1739 [ + - ]: 40 : dta->name->name == dtb->name->name &&
1740 [ + - ]: 40 : dta->name->abstract == dtb->name->abstract &&
1741 [ + - ]: 40 : dta->name->mutabl == dtb->name->mutabl &&
1742 [ + + ]: 40 : dta->name->n_uninitialized == dtb->name->n_uninitialized &&
1743 [ + + + + : 35 : (jl_svec_len(jl_field_names(dta)) != 0 || dta->size == dtb->size) &&
- - ]
1744 [ + - ]: 34 : (dta->name->atomicfields == NULL
1745 [ + - ]: 34 : ? dtb->name->atomicfields == NULL
1746 [ # # ]: 0 : : (dtb->name->atomicfields != NULL &&
1747 [ - - - + ]: 2 : memcmp(dta->name->atomicfields, dtb->name->atomicfields, (jl_svec_len(dta->name->names) + 31) / 32 * sizeof(uint32_t)) == 0)) &&
1748 [ + + ]: 34 : (dta->name->constfields == NULL
1749 [ + - ]: 32 : ? dtb->name->constfields == NULL
1750 [ + + ]: 3 : : (dtb->name->constfields != NULL &&
1751 [ + - ]: 1 : memcmp(dta->name->constfields, dtb->name->constfields, (jl_svec_len(dta->name->names) + 31) / 32 * sizeof(uint32_t)) == 0)) &&
1752 [ + + ]: 32 : jl_egal((jl_value_t*)jl_field_names(dta), (jl_value_t*)jl_field_names(dtb)) &&
1753 [ - + ]: 31 : jl_nparams(dta) == jl_nparams(dtb)))
1754 : 9 : return 0;
1755 : 31 : jl_value_t *a=NULL, *b=NULL;
1756 : 31 : int ok = 1;
1757 : 31 : JL_GC_PUSH2(&a, &b);
1758 : 31 : a = jl_rewrap_unionall((jl_value_t*)dta->super, dta->name->wrapper);
1759 : 31 : b = jl_rewrap_unionall((jl_value_t*)dtb->super, dtb->name->wrapper);
1760 [ - + ]: 31 : if (!jl_types_equal(a, b))
1761 : 0 : goto no;
1762 [ + - + + ]: 62 : JL_TRY {
1763 : 31 : a = jl_apply_type(dtb->name->wrapper, jl_svec_data(dta->parameters), jl_nparams(dta));
1764 : : }
1765 [ # # ]: 0 : JL_CATCH {
1766 : 0 : ok = 0;
1767 : : }
1768 [ - + ]: 31 : if (!ok)
1769 : 0 : goto no;
1770 [ - + ]: 31 : assert(jl_is_datatype(a));
1771 : 31 : a = dta->name->wrapper;
1772 : 31 : b = dtb->name->wrapper;
1773 [ + + ]: 58 : while (jl_is_unionall(a)) {
1774 : 30 : jl_unionall_t *ua = (jl_unionall_t*)a;
1775 : 30 : jl_unionall_t *ub = (jl_unionall_t*)b;
1776 [ + - + + ]: 30 : if (!jl_types_egal(ua->var->lb, ub->var->lb) || !jl_types_egal(ua->var->ub, ub->var->ub) ||
1777 [ + + ]: 28 : ua->var->name != ub->var->name)
1778 : 3 : goto no;
1779 : 27 : a = jl_instantiate_unionall(ua, (jl_value_t*)ub->var);
1780 : 27 : b = ub->body;
1781 : : }
1782 : 28 : JL_GC_POP();
1783 : 28 : return 1;
1784 : 3 : no:
1785 : 3 : JL_GC_POP();
1786 : 3 : return 0;
1787 : : }
1788 : :
1789 : 40 : JL_CALLABLE(jl_f__equiv_typedef)
1790 : : {
1791 [ - + - + ]: 40 : JL_NARGS(_equiv_typedef, 2, 2);
1792 [ + + ]: 40 : return equiv_type(args[0], args[1]) ? jl_true : jl_false;
1793 : : }
1794 : :
1795 : : // IntrinsicFunctions ---------------------------------------------------------
1796 : :
1797 : : static void (*runtime_fp[num_intrinsics])(void);
1798 : : static unsigned intrinsic_nargs[num_intrinsics];
1799 : :
1800 : 4004380 : JL_CALLABLE(jl_f_intrinsic_call)
1801 : : {
1802 [ - + ]: 4004380 : JL_TYPECHK(intrinsic_call, intrinsic, F);
1803 : 4004380 : enum intrinsic f = (enum intrinsic)*(uint32_t*)jl_data_ptr(F);
1804 [ + + + + ]: 4004380 : if (f == cglobal && nargs == 1)
1805 : 1 : f = cglobal_auto;
1806 : 4004380 : unsigned fargs = intrinsic_nargs[f];
1807 [ + + ]: 4004380 : if (!fargs)
1808 : 1 : jl_errorf("`%s` must be compiled to be called", jl_intrinsic_name(f));
1809 [ - + - + ]: 4004380 : JL_NARGS(intrinsic_call, fargs, fargs);
1810 : :
1811 : : union {
1812 : : void (*fptr)(void);
1813 : : jl_value_t *(*call1)(jl_value_t*);
1814 : : jl_value_t *(*call2)(jl_value_t*, jl_value_t*);
1815 : : jl_value_t *(*call3)(jl_value_t*, jl_value_t*, jl_value_t*);
1816 : : jl_value_t *(*call4)(jl_value_t*, jl_value_t*, jl_value_t*, jl_value_t*);
1817 : : jl_value_t *(*call5)(jl_value_t*, jl_value_t*, jl_value_t*, jl_value_t*, jl_value_t*);
1818 : : } fptr;
1819 : 4004380 : fptr.fptr = runtime_fp[f];
1820 [ + + + + : 4004380 : switch (fargs) {
+ - ]
1821 : 2431720 : case 1:
1822 : 2431720 : return fptr.call1(args[0]);
1823 : 1048340 : case 2:
1824 : 1048340 : return fptr.call2(args[0], args[1]);
1825 : 524317 : case 3:
1826 : 524317 : return fptr.call3(args[0], args[1], args[2]);
1827 : 1 : case 4:
1828 : 1 : return fptr.call4(args[0], args[1], args[2], args[3]);
1829 : 2 : case 5:
1830 : 2 : return fptr.call5(args[0], args[1], args[2], args[3], args[4]);
1831 : 0 : default:
1832 : 0 : assert(0 && "unexpected number of arguments to an intrinsic function");
1833 : : }
1834 : : jl_gc_debug_critical_error();
1835 : : abort();
1836 : : }
1837 : :
1838 : 120 : JL_DLLEXPORT const char *jl_intrinsic_name(int f)
1839 : : {
1840 [ - - - + : 120 : switch ((enum intrinsic)f) {
- + - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - -
- - - - +
- - - - -
+ + + + -
+ + - - ]
1841 : 0 : default: return "invalid";
1842 : : #define ADD_I(func, nargs) case func: return #func;
1843 : : #define ADD_HIDDEN ADD_I
1844 : : #define ALIAS ADD_I
1845 : 120 : INTRINSICS
1846 : : #undef ADD_I
1847 : : #undef ADD_HIDDEN
1848 : : #undef ALIAS
1849 : : }
1850 : : }
1851 : :
1852 : 9866330 : unsigned jl_intrinsic_nargs(int f)
1853 : : {
1854 : 9866330 : return intrinsic_nargs[f];
1855 : : }
1856 : :
1857 : : // init -----------------------------------------------------------------------
1858 : :
1859 : 52716 : static void add_intrinsic_properties(enum intrinsic f, unsigned nargs, void (*pfunc)(void))
1860 : : {
1861 : 52716 : intrinsic_nargs[f] = nargs;
1862 : 52716 : runtime_fp[f] = pfunc;
1863 : 52716 : }
1864 : :
1865 : 91 : static void add_intrinsic(jl_module_t *inm, const char *name, enum intrinsic f) JL_GC_DISABLED
1866 : : {
1867 : 91 : jl_value_t *i = jl_permbox32(jl_intrinsic_type, (int32_t)f);
1868 : 91 : jl_sym_t *sym = jl_symbol(name);
1869 : 91 : jl_set_const(inm, sym, i);
1870 : 91 : jl_module_export(inm, sym);
1871 : 91 : }
1872 : :
1873 : 573 : void jl_init_intrinsic_properties(void) JL_GC_DISABLED
1874 : : {
1875 : : #define ADD_I(name, nargs) add_intrinsic_properties(name, nargs, (void(*)(void))&jl_##name);
1876 : : #define ADD_HIDDEN ADD_I
1877 : : #define ALIAS(alias, base) add_intrinsic_properties(alias, intrinsic_nargs[base], runtime_fp[base]);
1878 : 573 : INTRINSICS
1879 : : #undef ADD_I
1880 : : #undef ADD_HIDDEN
1881 : : #undef ALIAS
1882 : 573 : }
1883 : :
1884 : 1 : void jl_init_intrinsic_functions(void) JL_GC_DISABLED
1885 : : {
1886 : 1 : jl_module_t *inm = jl_new_module(jl_symbol("Intrinsics"));
1887 : 1 : inm->parent = jl_core_module;
1888 : 1 : jl_set_const(jl_core_module, jl_symbol("Intrinsics"), (jl_value_t*)inm);
1889 : 1 : jl_mk_builtin_func(jl_intrinsic_type, "IntrinsicFunction", jl_f_intrinsic_call);
1890 : 1 : jl_mk_builtin_func(
1891 : 1 : (jl_datatype_t*)jl_unwrap_unionall((jl_value_t*)jl_opaque_closure_type),
1892 : : "OpaqueClosure", jl_f_opaque_closure_call);
1893 : :
1894 : : #define ADD_I(name, nargs) add_intrinsic(inm, #name, name);
1895 : : #define ADD_HIDDEN(name, nargs)
1896 : : #define ALIAS ADD_I
1897 : 1 : INTRINSICS
1898 : : #undef ADD_I
1899 : : #undef ADD_HIDDEN
1900 : : #undef ALIAS
1901 : 1 : }
1902 : :
1903 : 67 : static void add_builtin(const char *name, jl_value_t *v)
1904 : : {
1905 : 67 : jl_set_const(jl_core_module, jl_symbol(name), v);
1906 : 67 : }
1907 : :
1908 : 157747 : jl_fptr_args_t jl_get_builtin_fptr(jl_value_t *b)
1909 : : {
1910 [ - + ]: 157747 : assert(jl_isa(b, (jl_value_t*)jl_builtin_type));
1911 : 157747 : jl_typemap_entry_t *entry = (jl_typemap_entry_t*)jl_atomic_load_relaxed(&jl_gf_mtable(b)->defs);
1912 : 157747 : jl_method_instance_t *mi = jl_atomic_load_relaxed(&entry->func.method->unspecialized);
1913 : 157747 : jl_code_instance_t *ci = jl_atomic_load_relaxed(&mi->cache);
1914 : 157747 : return jl_atomic_load_relaxed(&ci->specptr.fptr1);
1915 : : }
1916 : :
1917 : 44 : static jl_value_t *add_builtin_func(const char *name, jl_fptr_args_t fptr)
1918 : : {
1919 : 44 : return jl_mk_builtin_func(NULL, name, fptr)->instance;
1920 : : }
1921 : :
1922 : 1 : void jl_init_primitives(void) JL_GC_DISABLED
1923 : : {
1924 : 1 : jl_builtin_is = add_builtin_func("===", jl_f_is);
1925 : 1 : jl_builtin_typeof = add_builtin_func("typeof", jl_f_typeof);
1926 : 1 : jl_builtin_sizeof = add_builtin_func("sizeof", jl_f_sizeof);
1927 : 1 : jl_builtin_issubtype = add_builtin_func("<:", jl_f_issubtype);
1928 : 1 : jl_builtin_isa = add_builtin_func("isa", jl_f_isa);
1929 : 1 : jl_builtin_typeassert = add_builtin_func("typeassert", jl_f_typeassert);
1930 : 1 : jl_builtin_throw = add_builtin_func("throw", jl_f_throw);
1931 : 1 : jl_builtin_tuple = add_builtin_func("tuple", jl_f_tuple);
1932 : 1 : jl_builtin_ifelse = add_builtin_func("ifelse", jl_f_ifelse);
1933 : :
1934 : : // field access
1935 : 1 : jl_builtin_getfield = add_builtin_func("getfield", jl_f_getfield);
1936 : 1 : jl_builtin_setfield = add_builtin_func("setfield!", jl_f_setfield);
1937 : 1 : jl_builtin_swapfield = add_builtin_func("swapfield!", jl_f_swapfield);
1938 : 1 : jl_builtin_modifyfield = add_builtin_func("modifyfield!", jl_f_modifyfield);
1939 : 1 : jl_builtin_replacefield = add_builtin_func("replacefield!", jl_f_replacefield);
1940 : 1 : jl_builtin_fieldtype = add_builtin_func("fieldtype", jl_f_fieldtype);
1941 : 1 : jl_builtin_nfields = add_builtin_func("nfields", jl_f_nfields);
1942 : 1 : jl_builtin_isdefined = add_builtin_func("isdefined", jl_f_isdefined);
1943 : :
1944 : : // module bindings
1945 : 1 : jl_builtin_getglobal = add_builtin_func("getglobal", jl_f_getglobal);
1946 : 1 : jl_builtin_setglobal = add_builtin_func("setglobal!", jl_f_setglobal);
1947 : 1 : add_builtin_func("get_binding_type", jl_f_get_binding_type);
1948 : 1 : add_builtin_func("set_binding_type!", jl_f_set_binding_type);
1949 : :
1950 : : // array primitives
1951 : 1 : jl_builtin_arrayref = add_builtin_func("arrayref", jl_f_arrayref);
1952 : 1 : jl_builtin_const_arrayref = add_builtin_func("const_arrayref", jl_f_arrayref);
1953 : 1 : jl_builtin_arrayset = add_builtin_func("arrayset", jl_f_arrayset);
1954 : 1 : jl_builtin_arraysize = add_builtin_func("arraysize", jl_f_arraysize);
1955 : :
1956 : : // method table utils
1957 : 1 : jl_builtin_applicable = add_builtin_func("applicable", jl_f_applicable);
1958 : 1 : jl_builtin_invoke = add_builtin_func("invoke", jl_f_invoke);
1959 : 1 : jl_typename_t *itn = ((jl_datatype_t*)jl_typeof(jl_builtin_invoke))->name;
1960 : 1 : jl_value_t *ikws = jl_new_generic_function_with_supertype(itn->name, jl_core_module, jl_builtin_type);
1961 : 1 : itn->mt->kwsorter = ikws;
1962 : 1 : jl_gc_wb(itn->mt, ikws);
1963 : 1 : jl_mk_builtin_func((jl_datatype_t*)jl_typeof(ikws), jl_symbol_name(jl_gf_name(ikws)), jl_f_invoke_kwsorter);
1964 : :
1965 : : // internal functions
1966 : 1 : jl_builtin_apply_type = add_builtin_func("apply_type", jl_f_apply_type);
1967 : 1 : jl_builtin__apply_iterate = add_builtin_func("_apply_iterate", jl_f__apply_iterate);
1968 : 1 : jl_builtin__expr = add_builtin_func("_expr", jl_f__expr);
1969 : 1 : jl_builtin_svec = add_builtin_func("svec", jl_f_svec);
1970 : 1 : add_builtin_func("_apply_pure", jl_f__apply_pure);
1971 : 1 : add_builtin_func("_call_latest", jl_f__call_latest);
1972 : 1 : add_builtin_func("_call_in_world", jl_f__call_in_world);
1973 : 1 : add_builtin_func("_call_in_world_total", jl_f__call_in_world_total);
1974 : 1 : add_builtin_func("_typevar", jl_f__typevar);
1975 : 1 : add_builtin_func("_structtype", jl_f__structtype);
1976 : 1 : add_builtin_func("_abstracttype", jl_f__abstracttype);
1977 : 1 : add_builtin_func("_primitivetype", jl_f__primitivetype);
1978 : 1 : add_builtin_func("_setsuper!", jl_f__setsuper);
1979 : 1 : jl_builtin__typebody = add_builtin_func("_typebody!", jl_f__typebody);
1980 : 1 : add_builtin_func("_equiv_typedef", jl_f__equiv_typedef);
1981 : 1 : jl_builtin_donotdelete = add_builtin_func("donotdelete", jl_f_donotdelete);
1982 : 1 : add_builtin_func("finalizer", jl_f_finalizer);
1983 : :
1984 : : // builtin types
1985 : 1 : add_builtin("Any", (jl_value_t*)jl_any_type);
1986 : 1 : add_builtin("Type", (jl_value_t*)jl_type_type);
1987 : 1 : add_builtin("Nothing", (jl_value_t*)jl_nothing_type);
1988 : 1 : add_builtin("nothing", (jl_value_t*)jl_nothing);
1989 : 1 : add_builtin("TypeName", (jl_value_t*)jl_typename_type);
1990 : 1 : add_builtin("DataType", (jl_value_t*)jl_datatype_type);
1991 : 1 : add_builtin("TypeVar", (jl_value_t*)jl_tvar_type);
1992 : 1 : add_builtin("UnionAll", (jl_value_t*)jl_unionall_type);
1993 : 1 : add_builtin("Union", (jl_value_t*)jl_uniontype_type);
1994 : 1 : add_builtin("TypeofBottom", (jl_value_t*)jl_typeofbottom_type);
1995 : 1 : add_builtin("Tuple", (jl_value_t*)jl_anytuple_type);
1996 : 1 : add_builtin("TypeofVararg", (jl_value_t*)jl_vararg_type);
1997 : 1 : add_builtin("SimpleVector", (jl_value_t*)jl_simplevector_type);
1998 : :
1999 : 1 : add_builtin("Module", (jl_value_t*)jl_module_type);
2000 : 1 : add_builtin("MethodTable", (jl_value_t*)jl_methtable_type);
2001 : 1 : add_builtin("Method", (jl_value_t*)jl_method_type);
2002 : 1 : add_builtin("CodeInstance", (jl_value_t*)jl_code_instance_type);
2003 : 1 : add_builtin("TypeMapEntry", (jl_value_t*)jl_typemap_entry_type);
2004 : 1 : add_builtin("TypeMapLevel", (jl_value_t*)jl_typemap_level_type);
2005 : 1 : add_builtin("Symbol", (jl_value_t*)jl_symbol_type);
2006 : 1 : add_builtin("SSAValue", (jl_value_t*)jl_ssavalue_type);
2007 : 1 : add_builtin("Slot", (jl_value_t*)jl_abstractslot_type);
2008 : 1 : add_builtin("SlotNumber", (jl_value_t*)jl_slotnumber_type);
2009 : 1 : add_builtin("TypedSlot", (jl_value_t*)jl_typedslot_type);
2010 : 1 : add_builtin("Argument", (jl_value_t*)jl_argument_type);
2011 : 1 : add_builtin("Const", (jl_value_t*)jl_const_type);
2012 : 1 : add_builtin("PartialStruct", (jl_value_t*)jl_partial_struct_type);
2013 : 1 : add_builtin("PartialOpaque", (jl_value_t*)jl_partial_opaque_type);
2014 : 1 : add_builtin("InterConditional", (jl_value_t*)jl_interconditional_type);
2015 : 1 : add_builtin("MethodMatch", (jl_value_t*)jl_method_match_type);
2016 : 1 : add_builtin("IntrinsicFunction", (jl_value_t*)jl_intrinsic_type);
2017 : 1 : add_builtin("Function", (jl_value_t*)jl_function_type);
2018 : 1 : add_builtin("Builtin", (jl_value_t*)jl_builtin_type);
2019 : 1 : add_builtin("MethodInstance", (jl_value_t*)jl_method_instance_type);
2020 : 1 : add_builtin("CodeInfo", (jl_value_t*)jl_code_info_type);
2021 : 1 : add_builtin("Ref", (jl_value_t*)jl_ref_type);
2022 : 1 : add_builtin("Ptr", (jl_value_t*)jl_pointer_type);
2023 : 1 : add_builtin("LLVMPtr", (jl_value_t*)jl_llvmpointer_type);
2024 : 1 : add_builtin("Task", (jl_value_t*)jl_task_type);
2025 : 1 : add_builtin("OpaqueClosure", (jl_value_t*)jl_opaque_closure_type);
2026 : :
2027 : 1 : add_builtin("AbstractArray", (jl_value_t*)jl_abstractarray_type);
2028 : 1 : add_builtin("DenseArray", (jl_value_t*)jl_densearray_type);
2029 : 1 : add_builtin("Array", (jl_value_t*)jl_array_type);
2030 : :
2031 : 1 : add_builtin("Expr", (jl_value_t*)jl_expr_type);
2032 : 1 : add_builtin("LineNumberNode", (jl_value_t*)jl_linenumbernode_type);
2033 : 1 : add_builtin("LineInfoNode", (jl_value_t*)jl_lineinfonode_type);
2034 : 1 : add_builtin("GotoNode", (jl_value_t*)jl_gotonode_type);
2035 : 1 : add_builtin("GotoIfNot", (jl_value_t*)jl_gotoifnot_type);
2036 : 1 : add_builtin("ReturnNode", (jl_value_t*)jl_returnnode_type);
2037 : 1 : add_builtin("PiNode", (jl_value_t*)jl_pinode_type);
2038 : 1 : add_builtin("PhiNode", (jl_value_t*)jl_phinode_type);
2039 : 1 : add_builtin("PhiCNode", (jl_value_t*)jl_phicnode_type);
2040 : 1 : add_builtin("UpsilonNode", (jl_value_t*)jl_upsilonnode_type);
2041 : 1 : add_builtin("QuoteNode", (jl_value_t*)jl_quotenode_type);
2042 : 1 : add_builtin("NewvarNode", (jl_value_t*)jl_newvarnode_type);
2043 : 1 : add_builtin("GlobalRef", (jl_value_t*)jl_globalref_type);
2044 : 1 : add_builtin("NamedTuple", (jl_value_t*)jl_namedtuple_type);
2045 : :
2046 : 1 : add_builtin("Bool", (jl_value_t*)jl_bool_type);
2047 : 1 : add_builtin("UInt8", (jl_value_t*)jl_uint8_type);
2048 : 1 : add_builtin("UInt16", (jl_value_t*)jl_uint16_type);
2049 : 1 : add_builtin("UInt32", (jl_value_t*)jl_uint32_type);
2050 : 1 : add_builtin("UInt64", (jl_value_t*)jl_uint64_type);
2051 : 1 : add_builtin("Int32", (jl_value_t*)jl_int32_type);
2052 : 1 : add_builtin("Int64", (jl_value_t*)jl_int64_type);
2053 : : #ifdef _P64
2054 : 1 : add_builtin("Int", (jl_value_t*)jl_int64_type);
2055 : : #else
2056 : : add_builtin("Int", (jl_value_t*)jl_int32_type);
2057 : : #endif
2058 : :
2059 : 1 : add_builtin("AbstractString", (jl_value_t*)jl_abstractstring_type);
2060 : 1 : add_builtin("String", (jl_value_t*)jl_string_type);
2061 : 1 : }
2062 : :
2063 : : #ifdef __cplusplus
2064 : : }
2065 : : #endif
|