diff --git a/base/exports.jl b/base/exports.jl index 44c0bd03fe84b..fdccd16ade659 100644 --- a/base/exports.jl +++ b/base/exports.jl @@ -1168,6 +1168,7 @@ export @polly, @assert, + @check, @__dot__, @enum, @label, diff --git a/base/options.jl b/base/options.jl index 099b61388023c..76fbb68014dc3 100644 --- a/base/options.jl +++ b/base/options.jl @@ -21,6 +21,7 @@ struct JLOptions opt_level::Int8 debug_level::Int8 check_bounds::Int8 + julia_debug::Int8 depwarn::Int8 warn_overwrite::Int8 can_inline::Int8 diff --git a/base/pkg/pkg.jl b/base/pkg/pkg.jl index 8f20166f8b0bb..5a7f4a531a1ab 100644 --- a/base/pkg/pkg.jl +++ b/base/pkg/pkg.jl @@ -86,7 +86,7 @@ init(meta::AbstractString=DEFAULT_META, branch::AbstractString=META_BRANCH) = Di function __init__() vers = "v$(VERSION.major).$(VERSION.minor)" - pushfirst!(Base.LOAD_CACHE_PATH, abspath(Dir._pkgroot(), "lib", vers)) + pushfirst!(Base.LOAD_CACHE_PATH, abspath(Dir._pkgroot(), "lib", Base.JLOptions().julia_debug == 1 ? "debug" : ""), vers) end """ diff --git a/base/sysimg.jl b/base/sysimg.jl index 066457c4a0052..63ecaafde2949 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -501,6 +501,14 @@ function __init__() init_threadcall() end +macro check(x) + if JLOptions().julia_debug == 1 + return :($(esc(x))) + else + return nothing + end +end + INCLUDE_STATE = 3 # include = include_relative end # baremodule Base diff --git a/doc/man/julia.1 b/doc/man/julia.1 index fe0b1716874d6..39f7619df3a9a 100644 --- a/doc/man/julia.1 +++ b/doc/man/julia.1 @@ -151,6 +151,10 @@ Control whether inlining is permitted (overrides functions declared as @inline) --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations) +.TP +--debug={yes|no} +Enable the @check macro and always emit bounds checks + .TP --math-mode={ieee|user} Always use IEEE semantics for math (ignoring declarations), diff --git a/src/jloptions.c b/src/jloptions.c index ea7ce05f36172..3d322f7db81f7 100644 --- a/src/jloptions.c +++ b/src/jloptions.c @@ -50,6 +50,11 @@ jl_options_t jl_options = { 0, // quiet 1, // debug_level [release build] #endif JL_OPTIONS_CHECK_BOUNDS_DEFAULT, // check_bounds +#ifdef JL_DEBUG_BUILD + 1, // julia debug mode [debug build] +#else + 0, // julia debug mode [release build] +#endif JL_OPTIONS_DEPWARN_ON, // deprecation warning 0, // method overwrite warning 1, // can_inline @@ -118,6 +123,7 @@ static const char opts[] = #endif " --inline={yes|no} Control whether inlining is permitted, including overriding @inline declarations\n" " --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)\n" + " --debug={yes|no} Enable the @check macro and always emit bounds checks\n" #ifdef USE_POLLY " --polly={yes|no} Enable or disable the polyhedral optimizer Polly (overrides @polly declaration)\n" #endif @@ -151,6 +157,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp) opt_code_coverage, opt_track_allocation, opt_check_bounds, + opt_julia_debug, opt_output_jit_bc, opt_output_unopt_bc, opt_output_bc, @@ -200,6 +207,7 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp) { "track-allocation",optional_argument, 0, opt_track_allocation }, { "optimize", optional_argument, 0, 'O' }, { "check-bounds", required_argument, 0, opt_check_bounds }, + { "debug", required_argument, 0, opt_julia_debug }, { "output-bc", required_argument, 0, opt_output_bc }, { "output-unopt-bc", required_argument, 0, opt_output_unopt_bc }, { "output-jit-bc", required_argument, 0, opt_output_jit_bc }, @@ -489,6 +497,16 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp) else jl_errorf("julia: invalid argument to --check-bounds={yes|no} (%s)", optarg); break; + case opt_julia_debug: + if (!strcmp(optarg,"yes")) { + jl_options.check_bounds = 1; + jl_options.check_bounds = JL_OPTIONS_CHECK_BOUNDS_ON; + } + else if (!strcmp(optarg,"no")) + jl_options.check_bounds = 0; + else + jl_errorf("julia: invalid argument to --debug={yes|no} (%s)", optarg); + break; case opt_output_bc: jl_options.outputbc = optarg; if (!jl_options.image_file_specified) jl_options.image_file = NULL; diff --git a/src/julia.h b/src/julia.h index 3a207c61f8d5d..e9acd4b40c818 100644 --- a/src/julia.h +++ b/src/julia.h @@ -1716,6 +1716,7 @@ typedef struct { int8_t malloc_log; int8_t opt_level; int8_t debug_level; + int8_t julia_debug; int8_t check_bounds; int8_t depwarn; int8_t warn_overwrite;