Macro that inlines functions

I want to use some inlinable functions with @turbo for cleaner syntax, which currently does not work.

Is it possible to write a macro that gets an expression, and then for every function that should inline, replaces it by the function body? This way I could use my inlinable functions and write something like @inline_expand @turbo expr.

not really. Macro can’t see runtime value thus it won’t know what’s the method body to “paste” in place of your function call

I’m not sure I completely understand, the expression that should be inlined should be completely known at compile time, right?

macros run on source code before anything happens, not during compile time

My bad, you’re right. Then it would not work if there’s any dispatch going on. However, in my case I just want to write some functions, basically as an alias to make the code a bit cleaner and semantically easier to understand. The macro could scan the source code to find the function body in this case.

you can use GitHub - rafaqz/Mixers.jl: Julia mixin macros. Mixed, not stirred to “puke” the source code body into the location you want. @pour

Not sure I understand your question correctly, but the @inline macro is supposed to work at the call site as well: Essentials · The Julia Language

@inline block

Give a hint to the compiler that calls within block are worth inlining.

# The compiler will try to inline `f`
@inline f(...)

# The compiler will try to inline `f`, `g` and `+`
@inline f(...) + g(...)

Note for your hypothetical macro to fulfil its purpose it would need to be expanded before the outer @turbo. I think (but do not know) that the outermost macro is expanded first. If that is the case then even your hypothetical macro solution could not work.

IIUC, the issue that @f.ij wants to do something like:

@turbo ....
    myfunction(...)
end

to write cleaner code inside the loop. However in that case LoopVectorization.jl cannot see inside the function call to optimize stuff.

oh, in that case @pour won’t work, because macro evaluation is outside-in (opposite of function evaluations)

I assumed the same thing but it does seem to work, I’m not a great fan of the syntax though. Moreover I’m fine with writing a macro that wraps around @turbo.