Exported functions and types

Index

Docstrings

AllocCheck.check_allocsFunction
check_allocs(func, types; ignore_throw=true)

Compiles the given function and types to LLVM IR and checks for allocations.

Returns a vector of AllocationSite, DynamicDispatch, and AllocatingRuntimeCall

Warning

The Julia language/compiler does not guarantee that this result is stable across Julia invocations.

If you rely on allocation-free code for safety/correctness, it is not sufficient to verify check_allocs in test code and expect that the corresponding call in production will not allocate at runtime.

For this case, you must use @check_allocs instead.

Example

julia> function foo(x::Int, y::Int)
           z = x + y
           return z
       end
foo (generic function with 1 method)

julia> allocs = check_allocs(foo, (Int, Int))
AllocCheck.AllocationSite[]
source
AllocCheck.@check_allocsMacro
@check_allocs ignore_throw=true (function def)

Wraps the provided function definition so that all calls to it will be automatically checked for allocations.

If the check fails, an AllocCheckFailure exception is thrown containing the detailed failures, including the backtrace for each defect.

Note: All calls to the wrapped function are effectively a dynamic dispatch, which means they are type-unstable and may allocate memory at function entry. @check_allocs only guarantees the absence of allocations after the function has started running.

Example

julia> @check_allocs multiply(x,y) = x*y
multiply (generic function with 1 method)

julia> multiply(1.5, 3.5) # no allocations for Float64
5.25

julia> multiply(rand(3,3), rand(3,3)) # matmul needs to allocate the result
ERROR: @check_allocs function contains 1 allocations.

Stacktrace:
 [1] macro expansion
   @ ~/repos/AllocCheck/src/macro.jl:134 [inlined]
 [2] multiply(x::Matrix{Float64}, y::Matrix{Float64})
   @ Main ./REPL[2]:133
 [3] top-level scope
   @ REPL[5]:1
source