JuliaLang / AllocCheck.jl

AllocCheck
Other
209 stars 8 forks source link

Call-site macro #45

Open carstenbauer opened 8 months ago

carstenbauer commented 8 months ago

Came up on discourse.

Would be nice to have a macro that is similar to @code_* and others and that can be used like

@check_allocs multiply(rand(10,10), rand(10,10))

rather than having to augment the method definition (and run the allocation check on every call). I assume this is straightforward given that there already is the check_allocs function that works on the function signature alone.

jariji commented 8 months ago
@check_allocs multiply(rand(10,10), rand(10,10))

What is that expression supposed to say about the allocations in rand(10, 10)? Is there supposed to be a $ escape or setup= like in BenchmarkTools.@benchmark?

carstenbauer commented 8 months ago

Nothing. Similar to @code_* it is only supposed to analyze the method itself. It should figure out the function signature from the given argument values, but that's it. Hence there is no need for interpolation syntax IMO.

topolarity commented 8 months ago

Just to round out the discussion, I wanted to point out https://github.com/JuliaLang/AllocCheck.jl/pull/49 which is relevant for some of use cases mentioned on Discourse

If you need hard guarantees that some code is allocation-free, then right now you (unfortunately) have to go through the @check_allocs entry point.

That said, a call-site macro sounds like a fine idea to me :+1: