Calling a macro from within a macro, revisited

I know this is an old thread, but I’ve ended up back here a few times, so I think it might be useful to add on. I saw that the @simd macro uses an esc() outside the entire expression like this: https://github.com/JuliaLang/julia/blob/1b93d53fc4bb59350ada898038ed4de2994cce33/base/simdloop.jl#L127-L129

Following a similar pattern seems to work for wrapping @simd. I have a macro

macro innerloop(ex)
    return esc( :( @simd ivdep $ex ) )
end

so I can change the macros applied to inner loops throughout my code. It seems to be working at first glance. Not sure if it’s a general solution, and I confess I’m fairly new to Julia and not really comfortable with how macros/metaprogramming work - should this work? Anyone have comments?

2 Likes