How constant propagation affects AllocCheck
mainIn some scenarios, check_allocs can successfully prove zero allocations without using Val{T} if the compiler can use constant propagation. This happens when a value is hard-coded as a constant within the function, allowing the compiler to determine which code paths are taken.
While constant propagation works for simple hard-coded values, it is not guaranteed to happen in all complex scenarios. Using the Val{T} pattern is the reliable way to ensure a value is treated as a constant throughout the function's execution.
@check_allocs function constant_myfun()
verbose = false # Hard-coded constant
verbose && @info "log"
return 0
end
constant_myfun() # May work via constant propagation