Optimization level setting (-O / --optimize)

Couple of questions regarding this.

First, is there a good way to determine inside the Julia session what the current setting of the optimization level is?

Second, is there some reason this behavior is correct?

$ julia -O # no error

$ julia --optimize -t auto # no error

$ julia -t auto -O # no error

$ julia -O1 -t auto # no error

$ julia -O -t auto
ERROR: julia: invalid argument to -O (-t)

$ julia -O -v
ERROR: julia: invalid argument to -O (-v)

According to the docs,

-O, --optimize={0,1,2*,3} Set the optimization level (level is 3 if -O is used without a level)

… it seems that the bit about -O being used without a level only works if it is the last argument.

The same kind of thing happens with the -g flag

$ julia -g -t auto
ERROR: julia: invalid argument to -g (-t)

It’s probably not part of the public API, but I think Base.JLOptions().opt_level gives you that information.

shell$ julia -e 'println(Base.JLOptions().opt_level)'
2
shell$ julia -O3 -e 'println(Base.JLOptions().opt_level)'                                                                                
3
1 Like