Skip to content

Commit 3285528

Browse files
IanButterworthKristofferC
authored andcommitted
add default "auto" as option to --check-bounds (#41551)
* add default "auto" as option to --check-bounds * add to NEWS (cherry picked from commit 7d0f769)
1 parent ac3bbb0 commit 3285528

File tree

7 files changed

+16
-6
lines changed

7 files changed

+16
-6
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ New language features
3030
for example `a, b... = [1, 2, 3]`. This syntax is implemented using `Base.rest`,
3131
which can be overloaded to customize its behavior for different collection types
3232
([#37410]).
33+
* The default behavior of observing `@inbounds` declarations is now an option via `auto` in `--check-bounds=yes|no|auto` ([#41551])
3334

3435
Language changes
3536
----------------

base/util.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ function julia_cmd(julia=joinpath(Sys.BINDIR::String, julia_exename()))
154154
elseif opts.check_bounds == 2
155155
"no" # off
156156
else
157-
"" # "default"
157+
"" # default = "auto"
158158
end
159159
isempty(check_bounds) || push!(addflags, "--check-bounds=$check_bounds")
160160
end

doc/man/julia.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,8 +158,8 @@ Set the level of debug info generation to <n>
158158
Control whether inlining is permitted (overrides functions declared as @inline)
159159

160160
.TP
161-
--check-bounds={yes|no}
162-
Emit bounds checks always or never (ignoring declarations)
161+
--check-bounds={yes|no|auto}
162+
Emit bounds checks always, never, or respect @inbounds declarations
163163

164164
.TP
165165
--math-mode={ieee|user}

doc/src/devdocs/boundscheck.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,7 @@ Note this hierarchy has been designed to reduce the likelihood of method ambigui
8989
to make `checkbounds` the place to specialize on array type, and try to avoid specializations
9090
on index types; conversely, `checkindex` is intended to be specialized only on index type (especially,
9191
the last argument).
92+
93+
## Emit bounds checks
94+
95+
Julia can be launched with `--check-bounds={yes|no|auto}` to emit bounds checks always, never, or respect @inbounds declarations.

doc/src/manual/command-line-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ The following is a complete list of command-line switches available when launchi
3030
|`-O`, `--optimize={0,1,2,3}` |Set the optimization level (default level is 2 if unspecified or 3 if used without a level)|
3131
|`-g`, `-g <level>` |Enable / Set the level of debug info generation (default level is 1 if unspecified or 2 if used without a level)|
3232
|`--inline={yes\|no}` |Control whether inlining is permitted, including overriding `@inline` declarations|
33-
|`--check-bounds={yes\|no}` |Emit bounds checks always or never (ignoring declarations)|
33+
|`--check-bounds={yes\|no\|auto}` |Emit bounds checks always, never, or respect @inbounds declarations|
3434
|`--math-mode={ieee,fast}` |Disallow or enable unsafe floating point optimizations (overrides @fastmath declaration)|
3535
|`--code-coverage={none\|user\|all}` |Count executions of source lines|
3636
|`--code-coverage` |equivalent to `--code-coverage=user`|

src/jloptions.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ static const char opts[] =
129129
" (default level is 1 if unspecified or 2 if used without a level)\n"
130130
#endif
131131
" --inline={yes|no} Control whether inlining is permitted, including overriding @inline declarations\n"
132-
" --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)\n"
132+
" --check-bounds={yes|no|auto}\n"
133+
" Emit bounds checks always, never, or respect @inbounds declarations\n"
133134
#ifdef USE_POLLY
134135
" --polly={yes|no} Enable or disable the polyhedral optimizer Polly (overrides @polly declaration)\n"
135136
#endif
@@ -544,8 +545,10 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
544545
jl_options.check_bounds = JL_OPTIONS_CHECK_BOUNDS_ON;
545546
else if (!strcmp(optarg,"no"))
546547
jl_options.check_bounds = JL_OPTIONS_CHECK_BOUNDS_OFF;
548+
else if (!strcmp(optarg,"auto"))
549+
jl_options.check_bounds = JL_OPTIONS_CHECK_BOUNDS_DEFAULT;
547550
else
548-
jl_errorf("julia: invalid argument to --check-bounds={yes|no} (%s)", optarg);
551+
jl_errorf("julia: invalid argument to --check-bounds={yes|no|auto} (%s)", optarg);
549552
break;
550553
case opt_output_bc:
551554
jl_options.outputbc = optarg;

test/cmdlineargs.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,8 @@ let exename = `$(Base.julia_cmd()) --startup-file=no`
378378
filter!(a -> !startswith(a, "--check-bounds="), exename_default_checkbounds.exec)
379379
@test parse(Int, readchomp(`$exename_default_checkbounds -E "Int(Base.JLOptions().check_bounds)"`)) ==
380380
JL_OPTIONS_CHECK_BOUNDS_DEFAULT
381+
@test parse(Int, readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)"
382+
--check-bounds=auto`)) == JL_OPTIONS_CHECK_BOUNDS_DEFAULT
381383
@test parse(Int, readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)"
382384
--check-bounds=yes`)) == JL_OPTIONS_CHECK_BOUNDS_ON
383385
@test parse(Int, readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)"

0 commit comments

Comments
 (0)