diff --git a/NEWS.md b/NEWS.md index 445f3b84ad178..53cd1632c5aec 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ New language features * `Module(:name, false, false)` can be used to create a `module` that does not import `Core`. ([#40110]) * `@inline` and `@noinline` annotations may now be used in function bodies. ([#41312]) +* The default behavior of observing `@inbounds` declarations is now an option via `auto` in `--check-bounds=yes|no|auto` ([#41551]) Language changes ---------------- diff --git a/base/util.jl b/base/util.jl index 503ba5c390e1c..a8bbd92116a83 100644 --- a/base/util.jl +++ b/base/util.jl @@ -174,7 +174,7 @@ function julia_cmd(julia=joinpath(Sys.BINDIR::String, julia_exename())) elseif opts.check_bounds == 2 "no" # off else - "" # "default" + "" # default = "auto" end isempty(check_bounds) || push!(addflags, "--check-bounds=$check_bounds") end diff --git a/doc/man/julia.1 b/doc/man/julia.1 index 8e2ed9f94c76a..76277e39bc079 100644 --- a/doc/man/julia.1 +++ b/doc/man/julia.1 @@ -162,8 +162,8 @@ Set the level of debug info generation to Control whether inlining is permitted (overrides functions declared as @inline) .TP ---check-bounds={yes|no} -Emit bounds checks always or never (ignoring declarations) +--check-bounds={yes|no|auto} +Emit bounds checks always, never, or respect @inbounds declarations .TP --math-mode={ieee|user} diff --git a/doc/src/devdocs/boundscheck.md b/doc/src/devdocs/boundscheck.md index 300d7f8b72993..4f9c247db8c80 100644 --- a/doc/src/devdocs/boundscheck.md +++ b/doc/src/devdocs/boundscheck.md @@ -92,4 +92,4 @@ the last argument). ## Emit bounds checks -Julia can be launched with `--check-bounds={yes|no}` to emit bounds checks always or never (ignoring declarations). +Julia can be launched with `--check-bounds={yes|no|auto}` to emit bounds checks always, never, or respect @inbounds declarations. diff --git a/doc/src/manual/command-line-options.md b/doc/src/manual/command-line-options.md index 47d581af430e5..a0fe1849cc7b1 100644 --- a/doc/src/manual/command-line-options.md +++ b/doc/src/manual/command-line-options.md @@ -31,7 +31,7 @@ The following is a complete list of command-line switches available when launchi |`--min-optlevel={0,1,2,3}` |Set the lower bound on per-module optimization (default is 0)| |`-g`, `-g ` |Enable / Set the level of debug info generation (default level is 1 if unspecified or 2 if used without a level)| |`--inline={yes\|no}` |Control whether inlining is permitted, including overriding `@inline` declarations| -|`--check-bounds={yes\|no}` |Emit bounds checks always or never (ignoring declarations)| +|`--check-bounds={yes\|no\|auto}` |Emit bounds checks always, never, or respect @inbounds declarations| |`--math-mode={ieee,fast}` |Disallow or enable unsafe floating point optimizations (overrides @fastmath declaration)| |`--code-coverage={none\|user\|all}` |Count executions of source lines| |`--code-coverage` |equivalent to `--code-coverage=user`| diff --git a/src/jloptions.c b/src/jloptions.c index 3fb06fd4e7340..ab1af72a04c79 100644 --- a/src/jloptions.c +++ b/src/jloptions.c @@ -131,7 +131,8 @@ static const char opts[] = " (default level is 1 if unspecified or 2 if used without a level)\n" #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 @inbounds declarations)\n" + " --check-bounds={yes|no|auto}\n" + " Emit bounds checks always, never, or respect @inbounds declarations\n" #ifdef USE_POLLY " --polly={yes|no} Enable or disable the polyhedral optimizer Polly (overrides @polly declaration)\n" #endif @@ -565,8 +566,10 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp) jl_options.check_bounds = JL_OPTIONS_CHECK_BOUNDS_ON; else if (!strcmp(optarg,"no")) jl_options.check_bounds = JL_OPTIONS_CHECK_BOUNDS_OFF; + else if (!strcmp(optarg,"auto")) + jl_options.check_bounds = JL_OPTIONS_CHECK_BOUNDS_DEFAULT; else - jl_errorf("julia: invalid argument to --check-bounds={yes|no} (%s)", optarg); + jl_errorf("julia: invalid argument to --check-bounds={yes|no|auto} (%s)", optarg); break; case opt_output_bc: jl_options.outputbc = optarg; diff --git a/test/cmdlineargs.jl b/test/cmdlineargs.jl index fbf60acdbc848..c5e82b681a3c4 100644 --- a/test/cmdlineargs.jl +++ b/test/cmdlineargs.jl @@ -396,6 +396,8 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no` filter!(a -> !startswith(a, "--check-bounds="), exename_default_checkbounds.exec) @test parse(Int, readchomp(`$exename_default_checkbounds -E "Int(Base.JLOptions().check_bounds)"`)) == JL_OPTIONS_CHECK_BOUNDS_DEFAULT + @test parse(Int, readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)" + --check-bounds=auto`)) == JL_OPTIONS_CHECK_BOUNDS_DEFAULT @test parse(Int, readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)" --check-bounds=yes`)) == JL_OPTIONS_CHECK_BOUNDS_ON @test parse(Int, readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)"