Skip to content

Commit

Permalink
add default "auto" as option to --check-bounds (#41551)
Browse files Browse the repository at this point in the history
* add default "auto" as option to --check-bounds

* add to NEWS

(cherry picked from commit 7d0f769)
  • Loading branch information
IanButterworth authored and KristofferC committed Jul 19, 2021
1 parent c6a0d7d commit 9838ead
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 6 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ New language features
for example `a, b... = [1, 2, 3]`. This syntax is implemented using `Base.rest`,
which can be overloaded to customize its behavior for different collection types
([#37410]).
* The default behavior of observing `@inbounds` declarations is now an option via `auto` in `--check-bounds=yes|no|auto` ([#41551])

Language changes
----------------
Expand Down
2 changes: 1 addition & 1 deletion base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,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
Expand Down
4 changes: 2 additions & 2 deletions doc/man/julia.1
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,8 @@ Set the level of debug info generation to <n>
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}
Expand Down
4 changes: 4 additions & 0 deletions doc/src/devdocs/boundscheck.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,7 @@ Note this hierarchy has been designed to reduce the likelihood of method ambigui
to make `checkbounds` the place to specialize on array type, and try to avoid specializations
on index types; conversely, `checkindex` is intended to be specialized only on index type (especially,
the last argument).

## Emit bounds checks

Julia can be launched with `--check-bounds={yes|no|auto}` to emit bounds checks always, never, or respect @inbounds declarations.
2 changes: 1 addition & 1 deletion doc/src/manual/command-line-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ The following is a complete list of command-line switches available when launchi
|`-O`, `--optimize={0,1,2,3}` |Set the optimization level (default level is 2 if unspecified or 3 if used without a level)|
|`-g`, `-g <level>` |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`|
Expand Down
7 changes: 5 additions & 2 deletions src/jloptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,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 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
Expand Down Expand Up @@ -544,8 +545,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;
Expand Down
2 changes: 2 additions & 0 deletions test/cmdlineargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ let exename = `$(Base.julia_cmd()) --startup-file=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)"
Expand Down

0 comments on commit 9838ead

Please sign in to comment.