@inbounds like mechanism?

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?

1 Like

See Generalizing bounds checking

1 Like

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.

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