@inbounds like mechanism?

metaprogramming

#1

In the ArgCheck package, there is the @argcheck macro that can be used to check function arguments:

julia> using ArgCheck

julia> f(x) = (@argcheck x >= 0; x)
f (generic function with 1 method)

julia> f(1)
1

julia> f(-1)
ERROR: ArgumentError: x >= 0 must hold. Got
x => -1
0 => 0

However in performance critical code you may not want the branch that is introduced by @argcheck.
This is similar to the situation with boundschecks. Now in the case of boundschecks there is the @inbounds macro. It would be nice to have an analogous @noargcheck to suppress @argcheck. Is it possible to implement such a thing in a package?


#2

See Generalizing bounds checking


#3

You can create a shim around the macro as described in https://github.com/KristofferC/TimerOutputs.jl/blob/master/README.md#overhead. This need to be defined in non precompiled code so you can chose at run time whether the macro should be active or not.


#4

Or (perhaps preferably) use a const Ref{Bool} instead of a Bool, as @jameson suggested in my earlier post.