LCOV - code coverage report
Current view: top level - src - interpreter.c (source / functions) Hit Total Coverage
Test: [build process] commit ef510b1f346f4c9f9d86eaceace5ca54961a1dbc Lines: 304 481 63.2 %
Date: 2022-07-17 01:01:28 Functions: 14 16 87.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 191 376 50.8 %

           Branch data     Line data    Source code
       1                 :            : // This file is a part of Julia. License is MIT: https://julialang.org/license
       2                 :            : 
       3                 :            : #include <stdlib.h>
       4                 :            : #include <setjmp.h>
       5                 :            : #ifdef _OS_WINDOWS_
       6                 :            : #include <malloc.h>
       7                 :            : #endif
       8                 :            : #include "julia.h"
       9                 :            : #include "julia_internal.h"
      10                 :            : #include "builtin_proto.h"
      11                 :            : #include "julia_assert.h"
      12                 :            : 
      13                 :            : #ifdef __cplusplus
      14                 :            : extern "C" {
      15                 :            : #endif
      16                 :            : 
      17                 :            : typedef struct {
      18                 :            :     jl_code_info_t *src; // contains the names and number of slots
      19                 :            :     jl_method_instance_t *mi; // MethodInstance we're executing, or NULL if toplevel
      20                 :            :     jl_module_t *module; // context for globals
      21                 :            :     jl_value_t **locals; // slots for holding local slots and ssavalues
      22                 :            :     jl_svec_t *sparam_vals; // method static parameters, if eval-ing a method body
      23                 :            :     size_t ip; // Leak the currently-evaluating statement index to backtrace capture
      24                 :            :     int preevaluation; // use special rules for pre-evaluating expressions (deprecated--only for ccall handling)
      25                 :            :     int continue_at; // statement index to jump to after leaving exception handler (0 if none)
      26                 :            : } interpreter_state;
      27                 :            : 
      28                 :            : 
      29                 :            : // general alloca rules are incompatible on C and C++, so define a macro that deals with the difference
      30                 :            : #ifdef __cplusplus
      31                 :            : #define JL_CPPALLOCA(var,n)                                                         \
      32                 :            :   var = (decltype(var))alloca((n))
      33                 :            : #else
      34                 :            : #define JL_CPPALLOCA(var,n)                                                         \
      35                 :            :   JL_GCC_IGNORE_START("-Wc++-compat")                                               \
      36                 :            :   var = alloca((n));                                                                \
      37                 :            :   JL_GCC_IGNORE_STOP
      38                 :            : #endif
      39                 :            : 
      40                 :            : #ifdef __clang_gcanalyzer__
      41                 :            : 
      42                 :            : extern void JL_GC_ENABLEFRAME(interpreter_state*) JL_NOTSAFEPOINT;
      43                 :            : 
      44                 :            : // This is necessary, because otherwise the analyzer considers this undefined
      45                 :            : // behavior and terminates the exploration
      46                 :            : #define JL_GC_PUSHFRAME(frame,locals,n)     \
      47                 :            :   JL_CPPALLOCA(frame, sizeof(*frame)+((n) * sizeof(jl_value_t*)));  \
      48                 :            :   memset(&frame[1], 0, sizeof(void*) * n); \
      49                 :            :   _JL_GC_PUSHARGS((jl_value_t**)&frame[1], n); \
      50                 :            :   locals = (jl_value_t**)&frame[1];
      51                 :            : 
      52                 :            : #else
      53                 :            : 
      54                 :            : #define JL_GC_ENCODE_PUSHFRAME(n)  ((((size_t)(n))<<2)|2)
      55                 :            : 
      56                 :            : #define JL_GC_PUSHFRAME(frame,locals,n)                                             \
      57                 :            :   JL_CPPALLOCA(frame, sizeof(*frame)+(((n)+3)*sizeof(jl_value_t*)));                \
      58                 :            :   ((void**)&frame[1])[0] = NULL;                                                    \
      59                 :            :   ((void**)&frame[1])[1] = (void*)JL_GC_ENCODE_PUSHFRAME(n);                        \
      60                 :            :   ((void**)&frame[1])[2] = jl_pgcstack;                                             \
      61                 :            :   memset(&((void**)&frame[1])[3], 0, (n)*sizeof(jl_value_t*));                      \
      62                 :            :   jl_pgcstack = (jl_gcframe_t*)&(((void**)&frame[1])[1]);                           \
      63                 :            :   locals = &((jl_value_t**)&frame[1])[3];
      64                 :            : 
      65                 :            : // we define this separately so that we can populate the frame before we add it to the backtrace
      66                 :            : // it's recommended to mark the containing function with NOINLINE, though not essential
      67                 :            : #define JL_GC_ENABLEFRAME(frame) \
      68                 :            :   ((void**)&frame[1])[0] = __builtin_frame_address(0);
      69                 :            : 
      70                 :            : #endif
      71                 :            : 
      72                 :            : 
      73                 :            : static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s);
      74                 :            : static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s, size_t ip, int toplevel);
      75                 :            : 
      76                 :            : // method definition form
      77                 :            : 
      78                 :     145952 : static jl_value_t *eval_methoddef(jl_expr_t *ex, interpreter_state *s)
      79                 :            : {
      80                 :     145952 :     jl_value_t **args = jl_array_ptr_data(ex->args);
      81                 :            : 
      82                 :            :     // generic function definition
      83         [ +  + ]:     145952 :     if (jl_expr_nargs(ex) == 1) {
      84                 :      89767 :         jl_value_t **args = jl_array_ptr_data(ex->args);
      85                 :      89767 :         jl_sym_t *fname = (jl_sym_t*)args[0];
      86                 :      89767 :         jl_module_t *modu = s->module;
      87         [ -  + ]:      89767 :         if (jl_is_globalref(fname)) {
      88                 :          0 :             modu = jl_globalref_mod(fname);
      89                 :          0 :             fname = jl_globalref_name(fname);
      90                 :            :         }
      91         [ -  + ]:      89767 :         if (!jl_is_symbol(fname)) {
      92                 :          0 :             jl_error("method: invalid declaration");
      93                 :            :         }
      94                 :      89767 :         jl_value_t *bp_owner = (jl_value_t*)modu;
      95                 :      89767 :         jl_binding_t *b = jl_get_binding_for_method_def(modu, fname);
      96                 :      89767 :         _Atomic(jl_value_t*) *bp = &b->value;
      97                 :      89767 :         jl_value_t *gf = jl_generic_function_def(b->name, b->owner, bp, bp_owner, b);
      98                 :      89767 :         return gf;
      99                 :            :     }
     100                 :            : 
     101                 :      56185 :     jl_value_t *atypes = NULL, *meth = NULL, *fname = NULL;
     102                 :      56185 :     JL_GC_PUSH3(&atypes, &meth, &fname);
     103                 :            : 
     104                 :      56185 :     fname = eval_value(args[0], s);
     105                 :      56185 :     jl_methtable_t *mt = NULL;
     106         [ -  + ]:      56185 :     if (jl_typeis(fname, jl_methtable_type)) {
     107                 :          0 :         mt = (jl_methtable_t*)fname;
     108                 :            :     }
     109                 :      56185 :     atypes = eval_value(args[1], s);
     110                 :      56185 :     meth = eval_value(args[2], s);
     111                 :      56185 :     jl_method_def((jl_svec_t*)atypes, mt, (jl_code_info_t*)meth, s->module);
     112                 :      56185 :     JL_GC_POP();
     113                 :      56185 :     return jl_nothing;
     114                 :            : }
     115                 :            : 
     116                 :            : // expression evaluator
     117                 :            : 
     118                 :     588169 : static jl_value_t *do_call(jl_value_t **args, size_t nargs, interpreter_state *s)
     119                 :            : {
     120                 :            :     jl_value_t **argv;
     121         [ -  + ]:     588169 :     assert(nargs >= 1);
     122                 :     588169 :     JL_GC_PUSHARGS(argv, nargs);
     123                 :            :     size_t i;
     124         [ +  + ]:    2511490 :     for (i = 0; i < nargs; i++)
     125                 :    1923320 :         argv[i] = eval_value(args[i], s);
     126                 :     588169 :     jl_value_t *result = jl_apply(argv, nargs);
     127                 :     588163 :     JL_GC_POP();
     128                 :     588163 :     return result;
     129                 :            : }
     130                 :            : 
     131                 :          0 : static jl_value_t *do_invoke(jl_value_t **args, size_t nargs, interpreter_state *s)
     132                 :            : {
     133                 :            :     jl_value_t **argv;
     134         [ #  # ]:          0 :     assert(nargs >= 2);
     135                 :          0 :     JL_GC_PUSHARGS(argv, nargs - 1);
     136                 :            :     size_t i;
     137         [ #  # ]:          0 :     for (i = 1; i < nargs; i++)
     138                 :          0 :         argv[i] = eval_value(args[i], s);
     139                 :          0 :     jl_method_instance_t *meth = (jl_method_instance_t*)args[0];
     140         [ #  # ]:          0 :     assert(jl_is_method_instance(meth));
     141                 :          0 :     jl_value_t *result = jl_invoke(argv[1], &argv[2], nargs - 2, meth);
     142                 :          0 :     JL_GC_POP();
     143                 :          0 :     return result;
     144                 :            : }
     145                 :            : 
     146                 :   41145100 : jl_value_t *jl_eval_global_var(jl_module_t *m, jl_sym_t *e)
     147                 :            : {
     148                 :   41145100 :     jl_value_t *v = jl_get_global(m, e);
     149         [ -  + ]:   41145100 :     if (v == NULL)
     150                 :          0 :         jl_undefined_var_error(e);
     151                 :   41145100 :     return v;
     152                 :            : }
     153                 :            : 
     154                 :    1477530 : static int jl_source_nslots(jl_code_info_t *src) JL_NOTSAFEPOINT
     155                 :            : {
     156                 :    1477530 :     return jl_array_len(src->slotflags);
     157                 :            : }
     158                 :            : 
     159                 :     725693 : static int jl_source_nssavalues(jl_code_info_t *src) JL_NOTSAFEPOINT
     160                 :            : {
     161         [ +  - ]:     725693 :     return jl_is_long(src->ssavaluetypes) ? jl_unbox_long(src->ssavaluetypes) : jl_array_len(src->ssavaluetypes);
     162                 :            : }
     163                 :            : 
     164                 :     648474 : static void eval_stmt_value(jl_value_t *stmt, interpreter_state *s)
     165                 :            : {
     166                 :     648474 :     jl_value_t *res = eval_value(stmt, s);
     167                 :     648468 :     s->locals[jl_source_nslots(s->src) + s->ip] = res;
     168                 :     648468 : }
     169                 :            : 
     170                 :    2988030 : static jl_value_t *eval_value(jl_value_t *e, interpreter_state *s)
     171                 :            : {
     172                 :    2988030 :     jl_code_info_t *src = s->src;
     173         [ +  + ]:    2988030 :     if (jl_is_ssavalue(e)) {
     174                 :     620773 :         ssize_t id = ((jl_ssavalue_t*)e)->id - 1;
     175   [ +  -  +  -  :     620773 :         if (src == NULL || id >= jl_source_nssavalues(src) || id < 0 || s->locals == NULL)
             +  -  -  + ]
     176                 :          0 :             jl_error("access to invalid SSAValue");
     177                 :            :         else
     178                 :     620773 :             return s->locals[jl_source_nslots(src) + id];
     179                 :            :     }
     180   [ +  +  +  -  :    2367260 :     if (jl_is_slot(e) || jl_is_argument(e)) {
                   -  + ]
     181                 :      72627 :         ssize_t n = jl_slot_number(e);
     182   [ +  -  +  -  :      72627 :         if (src == NULL || n > jl_source_nslots(src) || n < 1 || s->locals == NULL)
             +  -  -  + ]
     183                 :          0 :             jl_error("access to invalid slot number");
     184                 :      72627 :         jl_value_t *v = s->locals[n - 1];
     185         [ -  + ]:      72627 :         if (v == NULL)
     186                 :          0 :             jl_undefined_var_error((jl_sym_t*)jl_array_ptr_ref(src->slotnames, n - 1));
     187                 :      72627 :         return v;
     188                 :            :     }
     189         [ +  + ]:    2294630 :     if (jl_is_quotenode(e)) {
     190                 :     316838 :         return jl_quotenode_value(e);
     191                 :            :     }
     192         [ +  + ]:    1977790 :     if (jl_is_globalref(e)) {
     193                 :     566162 :         return jl_eval_global_var(jl_globalref_mod(e), jl_globalref_name(e));
     194                 :            :     }
     195         [ +  + ]:    1411630 :     if (jl_is_symbol(e)) {  // bare symbols appear in toplevel exprs not wrapped in `thunk`
     196                 :     398146 :         return jl_eval_global_var(s->module, (jl_sym_t*)e);
     197                 :            :     }
     198         [ -  + ]:    1013480 :     if (jl_is_pinode(e)) {
     199                 :          0 :         jl_value_t *val = eval_value(jl_fieldref_noalloc(e, 0), s);
     200                 :            : #ifndef JL_NDEBUG
     201                 :          0 :         JL_GC_PUSH1(&val);
     202                 :          0 :         jl_typeassert(val, jl_fieldref_noalloc(e, 1));
     203                 :          0 :         JL_GC_POP();
     204                 :            : #endif
     205                 :          0 :         return val;
     206                 :            :     }
     207   [ +  -  +  -  :    1013480 :     assert(!jl_is_phinode(e) && !jl_is_phicnode(e) && !jl_is_upsilonnode(e) && "malformed IR");
                   +  - ]
     208         [ +  + ]:    1013480 :     if (!jl_is_expr(e))
     209                 :     293273 :         return e;
     210                 :     720212 :     jl_expr_t *ex = (jl_expr_t*)e;
     211                 :     720212 :     jl_value_t **args = jl_array_ptr_data(ex->args);
     212                 :     720212 :     size_t nargs = jl_array_len(ex->args);
     213                 :     720212 :     jl_sym_t *head = ex->head;
     214         [ +  + ]:     720212 :     if (head == jl_call_sym) {
     215                 :     588169 :         return do_call(args, nargs, s);
     216                 :            :     }
     217         [ -  + ]:     132043 :     else if (head == jl_invoke_sym) {
     218                 :          0 :         return do_invoke(args, nargs, s);
     219                 :            :     }
     220         [ -  + ]:     132043 :     else if (head == jl_invoke_modify_sym) {
     221                 :          0 :         return do_call(args + 1, nargs - 1, s);
     222                 :            :     }
     223         [ +  + ]:     132043 :     else if (head == jl_isdefined_sym) {
     224                 :       1847 :         jl_value_t *sym = args[0];
     225                 :       1847 :         int defined = 0;
     226   [ +  -  +  -  :       1847 :         if (jl_is_slot(sym) || jl_is_argument(sym)) {
                   -  + ]
     227                 :          0 :             ssize_t n = jl_slot_number(sym);
     228   [ #  #  #  #  :          0 :             if (src == NULL || n > jl_source_nslots(src) || n < 1 || s->locals == NULL)
             #  #  #  # ]
     229                 :          0 :                 jl_error("access to invalid slot number");
     230                 :          0 :             defined = s->locals[n - 1] != NULL;
     231                 :            :         }
     232         [ -  + ]:       1847 :         else if (jl_is_globalref(sym)) {
     233                 :          0 :             defined = jl_boundp(jl_globalref_mod(sym), jl_globalref_name(sym));
     234                 :            :         }
     235         [ +  - ]:       1847 :         else if (jl_is_symbol(sym)) {
     236                 :       1847 :             defined = jl_boundp(s->module, (jl_sym_t*)sym);
     237                 :            :         }
     238   [ #  #  #  # ]:          0 :         else if (jl_is_expr(sym) && ((jl_expr_t*)sym)->head == jl_static_parameter_sym) {
     239                 :          0 :             ssize_t n = jl_unbox_long(jl_exprarg(sym, 0));
     240         [ #  # ]:          0 :             assert(n > 0);
     241   [ #  #  #  # ]:          0 :             if (s->sparam_vals && n <= jl_svec_len(s->sparam_vals)) {
     242                 :          0 :                 jl_value_t *sp = jl_svecref(s->sparam_vals, n - 1);
     243                 :          0 :                 defined = !jl_is_typevar(sp);
     244                 :            :             }
     245                 :            :             else {
     246                 :            :                 // static parameter val unknown needs to be an error for ccall
     247                 :          0 :                 jl_error("could not determine static parameter value");
     248                 :            :             }
     249                 :            :         }
     250                 :            :         else {
     251                 :          0 :             assert(0 && "malformed isdefined expression");
     252                 :            :         }
     253         [ +  + ]:       1847 :         return defined ? jl_true : jl_false;
     254                 :            :     }
     255         [ -  + ]:     130196 :     else if (head == jl_throw_undef_if_not_sym) {
     256                 :          0 :         jl_value_t *cond = eval_value(args[1], s);
     257         [ #  # ]:          0 :         assert(jl_is_bool(cond));
     258         [ #  # ]:          0 :         if (cond == jl_false) {
     259                 :          0 :             jl_sym_t *var = (jl_sym_t*)args[0];
     260         [ #  # ]:          0 :             if (var == jl_getfield_undefref_sym)
     261                 :          0 :                 jl_throw(jl_undefref_exception);
     262                 :            :             else
     263                 :          0 :                 jl_undefined_var_error(var);
     264                 :            :         }
     265                 :          0 :         return jl_nothing;
     266                 :            :     }
     267         [ +  + ]:     130196 :     else if (head == jl_new_sym) {
     268                 :            :         jl_value_t **argv;
     269                 :        409 :         JL_GC_PUSHARGS(argv, nargs);
     270         [ +  + ]:       1171 :         for (size_t i = 0; i < nargs; i++)
     271                 :        762 :             argv[i] = eval_value(args[i], s);
     272                 :        409 :         jl_value_t *v = jl_new_structv((jl_datatype_t*)argv[0], &argv[1], nargs - 1);
     273                 :        409 :         JL_GC_POP();
     274                 :        409 :         return v;
     275                 :            :     }
     276         [ -  + ]:     129787 :     else if (head == jl_splatnew_sym) {
     277                 :            :         jl_value_t **argv;
     278                 :          0 :         JL_GC_PUSHARGS(argv, 2);
     279                 :          0 :         argv[0] = eval_value(args[0], s);
     280                 :          0 :         argv[1] = eval_value(args[1], s);
     281                 :          0 :         jl_value_t *v = jl_new_structt((jl_datatype_t*)argv[0], argv[1]);
     282                 :          0 :         JL_GC_POP();
     283                 :          0 :         return v;
     284                 :            :     }
     285         [ -  + ]:     129787 :     else if (head == jl_new_opaque_closure_sym) {
     286                 :            :         jl_value_t **argv;
     287                 :          0 :         JL_GC_PUSHARGS(argv, nargs);
     288         [ #  # ]:          0 :         for (size_t i = 0; i < nargs; i++)
     289                 :          0 :             argv[i] = eval_value(args[i], s);
     290         [ #  # ]:          0 :         JL_NARGSV(new_opaque_closure, 4);
     291                 :          0 :         jl_value_t *ret = (jl_value_t*)jl_new_opaque_closure((jl_tupletype_t*)argv[0], argv[1], argv[2],
     292                 :          0 :             argv[3], argv+4, nargs-4);
     293                 :          0 :         JL_GC_POP();
     294                 :          0 :         return ret;
     295                 :            :     }
     296         [ +  + ]:     129787 :     else if (head == jl_static_parameter_sym) {
     297                 :         44 :         ssize_t n = jl_unbox_long(args[0]);
     298         [ -  + ]:         44 :         assert(n > 0);
     299   [ +  -  +  - ]:         44 :         if (s->sparam_vals && n <= jl_svec_len(s->sparam_vals)) {
     300                 :         44 :             jl_value_t *sp = jl_svecref(s->sparam_vals, n - 1);
     301   [ +  -  -  + ]:         44 :             if (jl_is_typevar(sp) && !s->preevaluation)
     302                 :          0 :                 jl_undefined_var_error(((jl_tvar_t*)sp)->name);
     303                 :         44 :             return sp;
     304                 :            :         }
     305                 :            :         // static parameter val unknown needs to be an error for ccall
     306                 :          0 :         jl_error("could not determine static parameter value");
     307                 :            :     }
     308         [ +  + ]:     129743 :     else if (head == jl_copyast_sym) {
     309                 :      39972 :         return jl_copy_ast(eval_value(args[0], s));
     310                 :            :     }
     311         [ -  + ]:      89771 :     else if (head == jl_exc_sym) {
     312                 :          0 :         return jl_current_exception();
     313                 :            :     }
     314         [ -  + ]:      89771 :     else if (head == jl_boundscheck_sym) {
     315                 :          0 :         return jl_true;
     316                 :            :     }
     317   [ +  -  +  -  :      89771 :     else if (head == jl_meta_sym || head == jl_coverageeffect_sym || head == jl_inbounds_sym || head == jl_loopinfo_sym ||
             +  -  +  - ]
     318   [ +  -  +  -  :      89771 :              head == jl_aliasscope_sym || head == jl_popaliasscope_sym || head == jl_inline_sym || head == jl_noinline_sym) {
             +  -  -  + ]
     319                 :          0 :         return jl_nothing;
     320                 :            :     }
     321   [ +  +  +  + ]:      89771 :     else if (head == jl_gc_preserve_begin_sym || head == jl_gc_preserve_end_sym) {
     322                 :            :         // The interpreter generally keeps values that were assigned in this scope
     323                 :            :         // rooted. If the interpreter learns to be more aggressive here, we may
     324                 :            :         // want to explicitly root these values.
     325                 :          4 :         return jl_nothing;
     326                 :            :     }
     327   [ +  -  +  - ]:      89767 :     else if (head == jl_method_sym && nargs == 1) {
     328                 :      89767 :         return eval_methoddef(ex, s);
     329                 :            :     }
     330         [ #  # ]:          0 :     else if (head == jl_foreigncall_sym) {
     331                 :          0 :         jl_error("`ccall` requires the compiler");
     332                 :            :     }
     333         [ #  # ]:          0 :     else if (head == jl_cfunction_sym) {
     334                 :          0 :         jl_error("`cfunction` requires the compiler");
     335                 :            :     }
     336                 :          0 :     jl_errorf("unsupported or misplaced expression %s", jl_symbol_name(head));
     337                 :            :     abort();
     338                 :            : }
     339                 :            : 
     340                 :            : // phi nodes don't behave like proper instructions, so we require a special interpreter to handle them
     341                 :     832198 : static size_t eval_phi(jl_array_t *stmts, interpreter_state *s, size_t ns, size_t to)
     342                 :            : {
     343                 :     832198 :     size_t from = s->ip;
     344                 :     832198 :     size_t ip = to;
     345                 :     832198 :     unsigned nphi = 0;
     346         [ +  - ]:     832198 :     for (ip = to; ip < ns; ip++) {
     347                 :     832198 :         jl_value_t *e = jl_array_ptr_ref(stmts, ip);
     348         [ +  - ]:     832198 :         if (!jl_is_phinode(e))
     349                 :     832198 :             break;
     350                 :          0 :         nphi += 1;
     351                 :            :     }
     352         [ -  + ]:     832198 :     if (nphi) {
     353                 :          0 :         jl_value_t **dest = &s->locals[jl_source_nslots(s->src) + to];
     354                 :            :         jl_value_t **phis; // = (jl_value_t**)alloca(sizeof(jl_value_t*) * nphi);
     355                 :          0 :         JL_GC_PUSHARGS(phis, nphi);
     356         [ #  # ]:          0 :         for (unsigned i = 0; i < nphi; i++) {
     357                 :          0 :             jl_value_t *e = jl_array_ptr_ref(stmts, to + i);
     358         [ #  # ]:          0 :             assert(jl_is_phinode(e));
     359                 :          0 :             jl_array_t *edges = (jl_array_t*)jl_fieldref_noalloc(e, 0);
     360                 :          0 :             ssize_t edge = -1;
     361                 :          0 :             size_t closest = to; // implicit edge has `to <= edge - 1 < to + i`
     362                 :            :             // this is because we could see the following IR (all 1-indexed):
     363                 :            :             //   goto %3 unless %cond
     364                 :            :             //   %2 = phi ...
     365                 :            :             //   %3 = phi (1)[1 => %a], (2)[2 => %b]
     366                 :            :             // from = 1, to = closest = 2, i = 1 --> edge = 2, edge_from = 2, from = 2
     367         [ #  # ]:          0 :             for (unsigned j = 0; j < jl_array_len(edges); ++j) {
     368                 :          0 :                 size_t edge_from = ((int32_t*)jl_array_data(edges))[j]; // 1-indexed
     369         [ #  # ]:          0 :                 if (edge_from == from + 1) {
     370         [ #  # ]:          0 :                     if (edge == -1)
     371                 :          0 :                         edge = j;
     372                 :            :                 }
     373   [ #  #  #  # ]:          0 :                 else if (closest < edge_from && edge_from < (to + i + 1)) {
     374                 :            :                     // if we found a nearer implicit branch from fall-through,
     375                 :            :                     // that occurred since the last explicit branch,
     376                 :            :                     // we should use the value from that edge instead
     377                 :          0 :                     edge = j;
     378                 :          0 :                     closest = edge_from;
     379                 :            :                 }
     380                 :            :             }
     381                 :          0 :             jl_value_t *val = NULL;
     382                 :          0 :             unsigned n_oldphi = closest - to;
     383         [ #  # ]:          0 :             if (n_oldphi) {
     384                 :            :                 // promote this implicit branch to a basic block start
     385                 :            :                 // and move all phi values to their position in edges
     386                 :            :                 // note that we might have already processed some phi nodes
     387                 :            :                 // in this basic block, so we need to be extra careful here
     388                 :            :                 // to ignore those
     389         [ #  # ]:          0 :                 for (unsigned j = 0; j < n_oldphi; j++) {
     390                 :          0 :                     dest[j] = phis[j];
     391                 :            :                 }
     392         [ #  # ]:          0 :                 for (unsigned j = n_oldphi; j < i; j++) {
     393                 :            :                     // move the rest to the start of phis
     394                 :          0 :                     phis[j - n_oldphi] = phis[j];
     395                 :          0 :                     phis[j] = NULL;
     396                 :            :                 }
     397                 :          0 :                 from = closest - 1;
     398                 :          0 :                 i -= n_oldphi;
     399                 :          0 :                 dest += n_oldphi;
     400                 :          0 :                 to += n_oldphi;
     401                 :          0 :                 nphi -= n_oldphi;
     402                 :            :             }
     403         [ #  # ]:          0 :             if (edge != -1) {
     404                 :            :                 // if edges list doesn't contain last branch, or the value is explicitly undefined
     405                 :            :                 // then this value should be unused.
     406                 :          0 :                 jl_array_t *values = (jl_array_t*)jl_fieldref_noalloc(e, 1);
     407                 :          0 :                 val = jl_array_ptr_ref(values, edge);
     408         [ #  # ]:          0 :                 if (val)
     409                 :          0 :                     val = eval_value(val, s);
     410                 :            :             }
     411                 :          0 :             phis[i] = val;
     412                 :            :         }
     413                 :            :         // now move all phi values to their position in edges
     414         [ #  # ]:          0 :         for (unsigned j = 0; j < nphi; j++) {
     415                 :          0 :             dest[j] = phis[j];
     416                 :            :         }
     417                 :          0 :         JL_GC_POP();
     418                 :            :     }
     419                 :     832198 :     return ip;
     420                 :            : }
     421                 :            : 
     422                 :     104922 : static jl_value_t *eval_body(jl_array_t *stmts, interpreter_state *s, size_t ip, int toplevel)
     423                 :            : {
     424                 :            :     jl_handler_t __eh;
     425                 :     104922 :     size_t ns = jl_array_len(stmts);
     426                 :     104922 :     jl_task_t *ct = jl_current_task;
     427                 :            : 
     428                 :     832200 :     while (1) {
     429                 :     937122 :         s->ip = ip;
     430         [ -  + ]:     937122 :         if (ip >= ns)
     431                 :          0 :             jl_error("`body` expression must terminate in `return`. Use `block` instead.");
     432         [ +  + ]:     937122 :         if (toplevel)
     433                 :     935114 :             ct->world_age = jl_atomic_load_acquire(&jl_world_counter);
     434                 :     937122 :         jl_value_t *stmt = jl_array_ptr_ref(stmts, ip);
     435         [ -  + ]:     937122 :         assert(!jl_is_phinode(stmt));
     436                 :     937122 :         size_t next_ip = ip + 1;
     437   [ +  -  +  - ]:     937122 :         assert(!jl_is_phinode(stmt) && !jl_is_phicnode(stmt) && "malformed IR");
     438         [ +  + ]:     937122 :         if (jl_is_gotonode(stmt)) {
     439                 :       5090 :             next_ip = jl_gotonode_label(stmt) - 1;
     440                 :            :         }
     441         [ +  + ]:     932032 :         else if (jl_is_gotoifnot(stmt)) {
     442                 :      12807 :             jl_value_t *cond = eval_value(jl_gotoifnot_cond(stmt), s);
     443         [ +  + ]:      12807 :             if (cond == jl_false) {
     444                 :       6693 :                 next_ip = jl_gotoifnot_label(stmt) - 1;
     445                 :            :             }
     446         [ -  + ]:       6114 :             else if (cond != jl_true) {
     447                 :          0 :                 jl_type_error("if", (jl_value_t*)jl_bool_type, cond);
     448                 :            :             }
     449                 :            :         }
     450         [ +  + ]:     919225 :         else if (jl_is_returnnode(stmt)) {
     451                 :     104914 :             return eval_value(jl_returnnode_value(stmt), s);
     452                 :            :         }
     453         [ -  + ]:     814311 :         else if (jl_is_upsilonnode(stmt)) {
     454                 :          0 :             jl_value_t *val = jl_fieldref_noalloc(stmt, 0);
     455         [ #  # ]:          0 :             if (val)
     456                 :          0 :                 val = eval_value(val, s);
     457                 :          0 :             jl_value_t *phic = s->locals[jl_source_nslots(s->src) + ip];
     458         [ #  # ]:          0 :             assert(jl_is_ssavalue(phic));
     459                 :          0 :             ssize_t id = ((jl_ssavalue_t*)phic)->id - 1;
     460                 :          0 :             s->locals[jl_source_nslots(s->src) + id] = val;
     461                 :            :         }
     462         [ +  + ]:     814311 :         else if (jl_is_expr(stmt)) {
     463                 :            :             // Most exprs are allowed to end a BB by fall through
     464                 :     781769 :             jl_sym_t *head = ((jl_expr_t*)stmt)->head;
     465         [ +  + ]:     781769 :             if (head == jl_assign_sym) {
     466                 :      43777 :                 jl_value_t *lhs = jl_exprarg(stmt, 0);
     467                 :      43777 :                 jl_value_t *rhs = eval_value(jl_exprarg(stmt, 1), s);
     468   [ +  +  -  + ]:      43777 :                 if (jl_is_slot(lhs)) {
     469                 :      30037 :                     ssize_t n = jl_slot_number(lhs);
     470   [ +  -  +  - ]:      30037 :                     assert(n <= jl_source_nslots(s->src) && n > 0);
     471                 :      30037 :                     s->locals[n - 1] = rhs;
     472                 :            :                 }
     473                 :            :                 else {
     474                 :            :                     jl_module_t *modu;
     475                 :            :                     jl_sym_t *sym;
     476         [ +  + ]:      13740 :                     if (jl_is_globalref(lhs)) {
     477                 :        200 :                         modu = jl_globalref_mod(lhs);
     478                 :        200 :                         sym = jl_globalref_name(lhs);
     479                 :            :                     }
     480                 :            :                     else {
     481         [ -  + ]:      13540 :                         assert(jl_is_symbol(lhs));
     482                 :      13540 :                         modu = s->module;
     483                 :      13540 :                         sym = (jl_sym_t*)lhs;
     484                 :            :                     }
     485                 :      13740 :                     JL_GC_PUSH1(&rhs);
     486                 :      13740 :                     jl_binding_t *b = jl_get_binding_wr_or_error(modu, sym);
     487                 :      13740 :                     jl_checked_assignment(b, rhs);
     488                 :      13740 :                     JL_GC_POP();
     489                 :            :                 }
     490                 :            :             }
     491         [ +  + ]:     737992 :             else if (head == jl_enter_sym) {
     492                 :          2 :                 jl_enter_handler(&__eh);
     493                 :            :                 // This is a bit tricky, but supports the implementation of PhiC nodes.
     494                 :            :                 // They are conceptually slots, but the slot to store to doesn't get explicitly
     495                 :            :                 // mentioned in the store (aka the "UpsilonNode") (this makes them integrate more
     496                 :            :                 // nicely with the rest of the SSA representation). In a compiler, we would figure
     497                 :            :                 // out which slot to store to at compile time when we encounter the statement. We
     498                 :            :                 // can't quite do that here, but we do something similar: We scan the catch entry
     499                 :            :                 // block (the only place where PhiC nodes may occur) to find all the Upsilons we
     500                 :            :                 // can possibly encounter. Then, we remember which slot they store to (we abuse the
     501                 :            :                 // SSA value result array for this purpose). TODO: We could do this only the first
     502                 :            :                 // time we encounter a given enter.
     503                 :          2 :                 size_t catch_ip = jl_unbox_long(jl_exprarg(stmt, 0)) - 1;
     504         [ +  - ]:          2 :                 while (catch_ip < ns) {
     505                 :          2 :                     jl_value_t *phicnode = jl_array_ptr_ref(stmts, catch_ip);
     506         [ +  - ]:          2 :                     if (!jl_is_phicnode(phicnode))
     507                 :          2 :                         break;
     508                 :          0 :                     jl_array_t *values = (jl_array_t*)jl_fieldref_noalloc(phicnode, 0);
     509         [ #  # ]:          0 :                     for (size_t i = 0; i < jl_array_len(values); ++i) {
     510                 :          0 :                         jl_value_t *val = jl_array_ptr_ref(values, i);
     511         [ #  # ]:          0 :                         assert(jl_is_ssavalue(val));
     512                 :          0 :                         size_t upsilon = ((jl_ssavalue_t*)val)->id - 1;
     513         [ #  # ]:          0 :                         assert(jl_is_upsilonnode(jl_array_ptr_ref(stmts, upsilon)));
     514                 :          0 :                         s->locals[jl_source_nslots(s->src) + upsilon] = jl_box_ssavalue(catch_ip + 1);
     515                 :            :                     }
     516                 :          0 :                     s->locals[jl_source_nslots(s->src) + catch_ip] = NULL;
     517                 :          0 :                     catch_ip += 1;
     518                 :            :                 }
     519                 :            :                 // store current top of exception stack for restore in pop_exception.
     520                 :          2 :                 s->locals[jl_source_nslots(s->src) + ip] = jl_box_ulong(jl_excstack_state());
     521         [ +  + ]:          2 :                 if (!jl_setjmp(__eh.eh_ctx, 1)) {
     522                 :          2 :                     return eval_body(stmts, s, next_ip, toplevel);
     523                 :            :                 }
     524         [ +  - ]:          2 :                 else if (s->continue_at) { // means we reached a :leave expression
     525                 :          2 :                     ip = s->continue_at;
     526                 :          2 :                     s->continue_at = 0;
     527                 :          2 :                     continue;
     528                 :            :                 }
     529                 :            :                 else { // a real exception
     530                 :          0 :                     ip = catch_ip;
     531                 :          0 :                     continue;
     532                 :            :                 }
     533                 :            :             }
     534         [ +  + ]:     737990 :             else if (head == jl_leave_sym) {
     535                 :          2 :                 int hand_n_leave = jl_unbox_long(jl_exprarg(stmt, 0));
     536         [ -  + ]:          2 :                 assert(hand_n_leave > 0);
     537                 :            :                 // equivalent to jl_pop_handler(hand_n_leave), but retaining eh for longjmp:
     538                 :          2 :                 jl_handler_t *eh = ct->eh;
     539         [ -  + ]:          2 :                 while (--hand_n_leave > 0)
     540                 :          0 :                     eh = eh->prev;
     541                 :          2 :                 jl_eh_restore_state(eh);
     542                 :            :                 // leave happens during normal control flow, but we must
     543                 :            :                 // longjmp to pop the eval_body call for each enter.
     544                 :          2 :                 s->continue_at = next_ip;
     545                 :          2 :                 jl_longjmp(eh->eh_ctx, 1);
     546                 :            :             }
     547         [ -  + ]:     737988 :             else if (head == jl_pop_exception_sym) {
     548                 :          0 :                 size_t prev_state = jl_unbox_ulong(eval_value(jl_exprarg(stmt, 0), s));
     549                 :          0 :                 jl_restore_excstack(prev_state);
     550                 :            :             }
     551         [ +  + ]:     737988 :             else if (toplevel) {
     552   [ +  +  +  + ]:     736728 :                 if (head == jl_method_sym && jl_expr_nargs(stmt) > 1) {
     553                 :      56185 :                     eval_methoddef((jl_expr_t*)stmt, s);
     554                 :            :                 }
     555         [ +  + ]:     680543 :                 else if (head == jl_toplevel_sym) {
     556                 :         44 :                     jl_value_t *res = jl_toplevel_eval(s->module, stmt);
     557                 :         44 :                     s->locals[jl_source_nslots(s->src) + s->ip] = res;
     558                 :            :                 }
     559         [ +  + ]:     680499 :                 else if (jl_is_toplevel_only_expr(stmt)) {
     560                 :      65036 :                     jl_toplevel_eval(s->module, stmt);
     561                 :            :                 }
     562         [ +  + ]:     615463 :                 else if (head == jl_meta_sym) {
     563   [ +  +  +  + ]:        133 :                     if (jl_expr_nargs(stmt) == 1 && jl_exprarg(stmt, 0) == (jl_value_t*)jl_nospecialize_sym) {
     564                 :         16 :                         jl_set_module_nospecialize(s->module, 1);
     565                 :            :                     }
     566   [ +  +  +  + ]:        133 :                     if (jl_expr_nargs(stmt) == 1 && jl_exprarg(stmt, 0) == (jl_value_t*)jl_specialize_sym) {
     567                 :          7 :                         jl_set_module_nospecialize(s->module, 0);
     568                 :            :                     }
     569         [ +  + ]:        133 :                     if (jl_expr_nargs(stmt) == 2) {
     570         [ +  + ]:         46 :                         if (jl_exprarg(stmt, 0) == (jl_value_t*)jl_optlevel_sym) {
     571         [ +  - ]:         18 :                             if (jl_is_long(jl_exprarg(stmt, 1))) {
     572                 :         18 :                                 int n = jl_unbox_long(jl_exprarg(stmt, 1));
     573                 :         18 :                                 jl_set_module_optlevel(s->module, n);
     574                 :            :                             }
     575                 :            :                         }
     576         [ +  + ]:         28 :                         else if (jl_exprarg(stmt, 0) == (jl_value_t*)jl_compile_sym) {
     577         [ +  - ]:         14 :                             if (jl_is_long(jl_exprarg(stmt, 1))) {
     578                 :         14 :                                 jl_set_module_compile(s->module, jl_unbox_long(jl_exprarg(stmt, 1)));
     579                 :            :                             }
     580                 :            :                         }
     581         [ +  - ]:         14 :                         else if (jl_exprarg(stmt, 0) == (jl_value_t*)jl_infer_sym) {
     582         [ +  - ]:         14 :                             if (jl_is_long(jl_exprarg(stmt, 1))) {
     583                 :         14 :                                 jl_set_module_infer(s->module, jl_unbox_long(jl_exprarg(stmt, 1)));
     584                 :            :                             }
     585                 :            :                         }
     586         [ #  # ]:          0 :                         else if (jl_exprarg(stmt, 0) == (jl_value_t*)jl_max_methods_sym) {
     587         [ #  # ]:          0 :                             if (jl_is_long(jl_exprarg(stmt, 1))) {
     588                 :          0 :                                 jl_set_module_max_methods(s->module, jl_unbox_long(jl_exprarg(stmt, 1)));
     589                 :            :                             }
     590                 :            :                         }
     591                 :            :                     }
     592                 :            :                 }
     593                 :            :                 else {
     594                 :     615330 :                     eval_stmt_value(stmt, s);
     595                 :            :                 }
     596                 :            :             }
     597                 :            :             else {
     598                 :       1260 :                 eval_stmt_value(stmt, s);
     599                 :            :             }
     600                 :            :         }
     601         [ +  + ]:      32542 :         else if (jl_is_newvarnode(stmt)) {
     602                 :        658 :             jl_value_t *var = jl_fieldref(stmt, 0);
     603   [ -  +  -  - ]:        658 :             assert(jl_is_slot(var));
     604                 :        658 :             ssize_t n = jl_slot_number(var);
     605   [ +  -  +  - ]:        658 :             assert(n <= jl_source_nslots(s->src) && n > 0);
     606                 :        658 :             s->locals[n - 1] = NULL;
     607                 :            :         }
     608   [ +  +  -  + ]:      31884 :         else if (toplevel && jl_is_linenode(stmt)) {
     609                 :          0 :             jl_lineno = jl_linenode_line(stmt);
     610                 :            :         }
     611                 :            :         else {
     612                 :      31884 :             eval_stmt_value(stmt, s);
     613                 :            :         }
     614                 :     832198 :         ip = eval_phi(stmts, s, ns, next_ip);
     615                 :            :     }
     616                 :            :     abort();
     617                 :            : }
     618                 :            : 
     619                 :            : // preparing method IR for interpreter
     620                 :            : 
     621                 :        152 : jl_code_info_t *jl_code_for_interpreter(jl_method_instance_t *mi)
     622                 :            : {
     623                 :        152 :     jl_code_info_t *src = (jl_code_info_t*)mi->uninferred;
     624         [ +  - ]:        152 :     if (jl_is_method(mi->def.value)) {
     625   [ +  +  -  + ]:        152 :         if (!src || (jl_value_t*)src == jl_nothing) {
     626         [ +  - ]:         72 :             if (mi->def.method->source) {
     627                 :         72 :                 src = (jl_code_info_t*)mi->def.method->source;
     628                 :            :             }
     629                 :            :             else {
     630         [ #  # ]:          0 :                 assert(mi->def.method->generator);
     631                 :          0 :                 src = jl_code_for_staged(mi);
     632                 :            :             }
     633                 :            :         }
     634   [ +  -  +  - ]:        152 :         if (src && (jl_value_t*)src != jl_nothing) {
     635                 :        152 :             JL_GC_PUSH1(&src);
     636                 :        152 :             src = jl_uncompress_ir(mi->def.method, NULL, (jl_array_t*)src);
     637                 :        152 :             mi->uninferred = (jl_value_t*)src;
     638                 :        152 :             jl_gc_wb(mi, src);
     639                 :        152 :             JL_GC_POP();
     640                 :            :         }
     641                 :            :     }
     642   [ +  -  -  + ]:        152 :     if (!src || !jl_is_code_info(src)) {
     643                 :          0 :         jl_error("source missing for method called in interpreter");
     644                 :            :     }
     645                 :        152 :     return src;
     646                 :            : }
     647                 :            : 
     648                 :            : // interpreter entry points
     649                 :            : 
     650                 :         80 : jl_value_t *NOINLINE jl_fptr_interpret_call(jl_value_t *f, jl_value_t **args, uint32_t nargs, jl_code_instance_t *codeinst)
     651                 :            : {
     652                 :            :     interpreter_state *s;
     653                 :         80 :     jl_method_instance_t *mi = codeinst->def;
     654                 :         80 :     jl_code_info_t *src = jl_code_for_interpreter(mi);
     655                 :         80 :     jl_array_t *stmts = src->code;
     656         [ -  + ]:         80 :     assert(jl_typeis(stmts, jl_array_any_type));
     657                 :         80 :     unsigned nroots = jl_source_nslots(src) + jl_source_nssavalues(src) + 2;
     658                 :         80 :     jl_value_t **locals = NULL;
     659                 :         80 :     JL_GC_PUSHFRAME(s, locals, nroots);
     660                 :         80 :     locals[0] = (jl_value_t*)src;
     661                 :         80 :     locals[1] = (jl_value_t*)stmts;
     662                 :         80 :     s->locals = locals + 2;
     663                 :         80 :     s->src = src;
     664         [ -  + ]:         80 :     if (jl_is_module(mi->def.value)) {
     665                 :          0 :         s->module = mi->def.module;
     666                 :            :     }
     667                 :            :     else {
     668                 :         80 :         s->module = mi->def.method->module;
     669                 :         80 :         size_t defargs = mi->def.method->nargs;
     670                 :         80 :         int isva = mi->def.method->isva ? 1 : 0;
     671                 :            :         size_t i;
     672                 :         80 :         s->locals[0] = f;
     673   [ -  +  -  + ]:         80 :         assert(isva ? nargs + 2 >= defargs : nargs + 1 == defargs);
     674         [ +  + ]:        112 :         for (i = 1; i < defargs - isva; i++)
     675                 :         32 :             s->locals[i] = args[i - 1];
     676         [ -  + ]:         80 :         if (isva) {
     677         [ #  # ]:          0 :             assert(defargs >= 2);
     678                 :          0 :             s->locals[defargs - 1] = jl_f_tuple(NULL, &args[defargs - 2], nargs + 2 - defargs);
     679                 :            :         }
     680                 :            :     }
     681                 :         80 :     s->sparam_vals = mi->sparam_vals;
     682                 :         80 :     s->preevaluation = 0;
     683                 :         80 :     s->continue_at = 0;
     684                 :         80 :     s->mi = mi;
     685                 :         80 :     JL_GC_ENABLEFRAME(s);
     686                 :         80 :     jl_value_t *r = eval_body(stmts, s, 0, 0);
     687                 :         80 :     JL_GC_POP();
     688                 :         80 :     return r;
     689                 :            : }
     690                 :            : 
     691                 :            : JL_DLLEXPORT jl_callptr_t jl_fptr_interpret_call_addr = &jl_fptr_interpret_call;
     692                 :            : 
     693                 :          0 : jl_value_t *jl_interpret_opaque_closure(jl_opaque_closure_t *oc, jl_value_t **args, size_t nargs)
     694                 :            : {
     695                 :          0 :     jl_method_t *source = oc->source;
     696                 :          0 :     jl_code_info_t *code = jl_uncompress_ir(source, NULL, (jl_array_t*)source->source);
     697                 :            :     interpreter_state *s;
     698                 :          0 :     unsigned nroots = jl_source_nslots(code) + jl_source_nssavalues(code) + 2;
     699                 :          0 :     jl_task_t *ct = jl_current_task;
     700                 :          0 :     size_t last_age = ct->world_age;
     701                 :          0 :     ct->world_age = oc->world;
     702                 :          0 :     jl_value_t **locals = NULL;
     703                 :          0 :     JL_GC_PUSHFRAME(s, locals, nroots);
     704                 :          0 :     locals[0] = (jl_value_t*)oc;
     705                 :            :     // The analyzer has some trouble with this
     706                 :          0 :     locals[1] = (jl_value_t*)code;
     707                 :            :     JL_GC_PROMISE_ROOTED(code);
     708                 :          0 :     locals[2] = (jl_value_t*)oc->captures;
     709                 :          0 :     s->locals = locals + 2;
     710                 :          0 :     s->src = code;
     711                 :          0 :     s->module = source->module;
     712                 :          0 :     s->sparam_vals = NULL;
     713                 :          0 :     s->preevaluation = 0;
     714                 :          0 :     s->continue_at = 0;
     715                 :          0 :     s->mi = NULL;
     716                 :          0 :     size_t defargs = source->nargs;
     717                 :          0 :     int isva = source->isva;
     718   [ #  #  #  # ]:          0 :     assert(isva ? nargs + 2 >= defargs : nargs + 1 == defargs);
     719         [ #  # ]:          0 :     for (size_t i = 1; i < defargs - isva; i++)
     720                 :          0 :         s->locals[i] = args[i - 1];
     721         [ #  # ]:          0 :     if (isva) {
     722         [ #  # ]:          0 :         assert(defargs >= 2);
     723                 :          0 :         s->locals[defargs - 1] = jl_f_tuple(NULL, &args[defargs - 2], nargs + 2 - defargs);
     724                 :            :     }
     725                 :          0 :     JL_GC_ENABLEFRAME(s);
     726                 :          0 :     jl_value_t *r = eval_body(code->code, s, 0, 0);
     727                 :          0 :     locals[0] = r; // GC root
     728                 :            :     JL_GC_PROMISE_ROOTED(r);
     729                 :          0 :     jl_typeassert(r, jl_tparam1(jl_typeof(oc)));
     730                 :          0 :     ct->world_age = last_age;
     731                 :          0 :     JL_GC_POP();
     732                 :          0 :     return r;
     733                 :            : }
     734                 :            : 
     735                 :     104840 : jl_value_t *NOINLINE jl_interpret_toplevel_thunk(jl_module_t *m, jl_code_info_t *src)
     736                 :            : {
     737                 :            :     interpreter_state *s;
     738                 :     104840 :     unsigned nroots = jl_source_nslots(src) + jl_source_nssavalues(src);
     739                 :     104840 :     JL_GC_PUSHFRAME(s, s->locals, nroots);
     740                 :     104840 :     jl_array_t *stmts = src->code;
     741         [ -  + ]:     104840 :     assert(jl_typeis(stmts, jl_array_any_type));
     742                 :     104840 :     s->src = src;
     743                 :     104840 :     s->module = m;
     744                 :     104840 :     s->sparam_vals = jl_emptysvec;
     745                 :     104840 :     s->continue_at = 0;
     746                 :     104840 :     s->mi = NULL;
     747                 :     104840 :     JL_GC_ENABLEFRAME(s);
     748                 :     104840 :     jl_task_t *ct = jl_current_task;
     749                 :     104840 :     size_t last_age = ct->world_age;
     750                 :     104840 :     jl_value_t *r = eval_body(stmts, s, 0, 1);
     751                 :     104834 :     ct->world_age = last_age;
     752                 :     104834 :     JL_GC_POP();
     753                 :     104834 :     return r;
     754                 :            : }
     755                 :            : 
     756                 :            : // deprecated: do not use this method in new code
     757                 :            : // it uses special scoping / evaluation / error rules
     758                 :            : // which should instead be handled in lowering
     759                 :      45452 : jl_value_t *NOINLINE jl_interpret_toplevel_expr_in(jl_module_t *m, jl_value_t *e, jl_code_info_t *src, jl_svec_t *sparam_vals)
     760                 :            : {
     761                 :            :     interpreter_state *s;
     762                 :            :     jl_value_t **locals;
     763                 :      45452 :     JL_GC_PUSHFRAME(s, locals, 0);
     764                 :            :     (void)locals;
     765                 :      45452 :     s->src = src;
     766                 :      45452 :     s->module = m;
     767                 :      45452 :     s->sparam_vals = sparam_vals;
     768                 :      45452 :     s->preevaluation = (sparam_vals != NULL);
     769                 :      45452 :     s->continue_at = 0;
     770                 :      45452 :     s->mi = NULL;
     771                 :      45452 :     JL_GC_ENABLEFRAME(s);
     772                 :      45452 :     jl_value_t *v = eval_value(e, s);
     773         [ -  + ]:      45452 :     assert(v);
     774                 :      45452 :     JL_GC_POP();
     775                 :      45452 :     return v;
     776                 :            : }
     777                 :            : 
     778                 :       8773 : JL_DLLEXPORT size_t jl_capture_interp_frame(jl_bt_element_t *bt_entry,
     779                 :            :         void *stateend, size_t space_remaining)
     780                 :            : {
     781                 :       8773 :     interpreter_state *s = &((interpreter_state*)stateend)[-1];
     782                 :       8773 :     int need_module = !s->mi;
     783         [ +  + ]:       8773 :     int required_space = need_module ? 4 : 3;
     784         [ -  + ]:       8773 :     if (space_remaining < required_space)
     785                 :          0 :         return 0; // Should not happen
     786         [ +  + ]:       8773 :     size_t njlvalues = need_module ? 2 : 1;
     787                 :       8773 :     uintptr_t entry_tags = jl_bt_entry_descriptor(njlvalues, 0, JL_BT_INTERP_FRAME_TAG, s->ip);
     788                 :       8773 :     bt_entry[0].uintptr = JL_BT_NON_PTR_ENTRY;
     789                 :       8773 :     bt_entry[1].uintptr = entry_tags;
     790         [ +  + ]:      17538 :     bt_entry[2].jlvalue = s->mi  ? (jl_value_t*)s->mi  :
     791         [ +  - ]:       8765 :                           s->src ? (jl_value_t*)s->src : (jl_value_t*)jl_nothing;
     792         [ +  + ]:       8773 :     if (need_module) {
     793                 :            :         // If we only have a CodeInfo (s->src), we are in a top level thunk and
     794                 :            :         // need to record the module separately.
     795                 :       8765 :         bt_entry[3].jlvalue = (jl_value_t*)s->module;
     796                 :            :     }
     797                 :       8773 :     return required_space;
     798                 :            : }
     799                 :            : 
     800                 :            : 
     801                 :            : #ifdef __cplusplus
     802                 :            : }
     803                 :            : #endif

Generated by: LCOV version 1.14