Skip to content

Commit

Permalink
add --show-eval for showing where top level eval is in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
IanButterworth committed Jan 23, 2025
1 parent f91436e commit 2e0f2bf
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 0 deletions.
6 changes: 6 additions & 0 deletions base/loading.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2846,6 +2846,12 @@ function include_string(mapexpr::Function, mod::Module, code::AbstractString,
# Wrap things to be eval'd in a :toplevel expr to carry line
# information as part of the expr.
line_and_ex.args[2] = ex
show_eval = JLOptions().show_eval
if show_eval == 2 # show everything
println("eval: ", line_and_ex)
elseif show_eval == 1 # show top location only
println("eval: ", line_and_ex.args[1])
end
result = Core.eval(mod, line_and_ex)
end
return result
Expand Down
1 change: 1 addition & 0 deletions base/options.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ struct JLOptions
heap_size_hint::UInt64
trace_compile_timing::Int8
trim::Int8
show_eval::Int8
task_metrics::Int8
timeout_for_safepoint_straggler_s::Int16
end
Expand Down
14 changes: 14 additions & 0 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ JL_DLLEXPORT void jl_init_options(void)
0, // heap-size-hint
0, // trace_compile_timing
JL_TRIM_NO, // trim
0, // show-eval
0, // task_metrics
-1, // timeout_for_safepoint_straggler_s
};
Expand Down Expand Up @@ -330,6 +331,7 @@ static const char opts_hidden[] =
" and can throw errors. With unsafe-warn warnings will be\n"
" printed for dynamic call sites that might lead to such\n"
" errors. In safe mode compile-time errors are given instead.\n"
" --show-eval={loc|full|no*} Show the expression being evaluated before eval.\n"
;

JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
Expand Down Expand Up @@ -381,6 +383,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
opt_gc_threads,
opt_permalloc_pkgimg,
opt_trim,
opt_show_eval,
opt_experimental_features,
};
static const char* const shortopts = "+vhqH:e:E:L:J:C:it:p:O:g:m:";
Expand Down Expand Up @@ -450,6 +453,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
{ "permalloc-pkgimg",required_argument, 0, opt_permalloc_pkgimg },
{ "heap-size-hint", required_argument, 0, opt_heap_size_hint },
{ "trim", optional_argument, 0, opt_trim },
{ "show-eval", optional_argument, 0, opt_show_eval },
{ 0, 0, 0, 0 }
};

Expand Down Expand Up @@ -994,6 +998,16 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
else
jl_errorf("julia: invalid argument to --trim={safe|no|unsafe|unsafe-warn} (%s)", optarg);
break;
case opt_show_eval:
if (optarg == NULL || !strcmp(optarg,"loc"))
jl_options.show_eval = 1;
else if (!strcmp(optarg,"full"))
jl_options.show_eval = 2;
else if (!strcmp(optarg,"no"))
jl_options.show_eval = 0;
else
jl_errorf("julia: invalid argument to --show-eval={yes|no} (%s)", optarg);
break;
case opt_task_metrics:
if (!strcmp(optarg, "no"))
jl_options.task_metrics = JL_OPTIONS_TASK_METRICS_OFF;
Expand Down
1 change: 1 addition & 0 deletions src/jloptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ typedef struct {
uint64_t heap_size_hint;
int8_t trace_compile_timing;
int8_t trim;
int8_t show_eval;
int8_t task_metrics;
int16_t timeout_for_safepoint_straggler_s;
} jl_options_t;
Expand Down

0 comments on commit 2e0f2bf

Please sign in to comment.