OptionalArgChecks

Provides two macros, @mark and @skip which give users control over skipping arbitrary code in functions for better performance.

For convenience, this package also exports @argcheck and @check from the package ArgCheck.jl and provides the macro @skipargcheck to skip these checks.

Warning

This package is still experimental, and there might be undiscovered bugs. Please open an issue, if you encounter any problems.

Warning

Currently, @skip and @skipargcheck will not recurse through keyword arguments, due to limitations in IRTools.

API

OptionalArgChecks.@markMacro
@mark label ex

Marks ex as an optional argument check, so when a function is called via @skip with label label, ex will be omitted.

julia> function half(x::Integer)
           @mark check_even iseven(x) || throw(DomainError(x, "x has to be an even number"))
           return x ÷ 2
       end
half (generic function with 1 method)

julia> half(4)
2

julia> half(3)
ERROR: DomainError with 3:
x has to be an even number
[...]

julia> @skip check_even half(3)
1
source
OptionalArgChecks.@skipMacro
@skip label ex[[ recursive=true]]
@skip [label1, label2, ...] ex[[ recursive=true]]

For every function call in ex, expressions marked with label label (or any of the labels label* respectively) using the macro @mark get omitted recursively.

source