@views macro causes module compilation failure
If I used @views on a function that uses Tullio, the module won't compile. Perhaps this is known or intended, but I don't understand the behavior. Removal of @views allows compilation.
I wouldn't call this intended but it is unfortunately expected. Macros are expanded outermost first (the opposite order to functions) and thus @views changes code before @tullio sees it, and produces something it has no idea how to digest:
julia> @macroexpand1 @views f(x) = @tullio _[i] := x[i]^2
:(f(x) = begin
#= REPL[203]:1 =#
#= REPL[203]:1 =# @tullio let var"##a#421" = _, var"##i#422" = i
var"##a#421"[var"##i#422"] = (Base.maybeview)(var"##a#421", var"##i#422"):(Base.maybeview)(x, i) ^ 2
end
end)
Macros can opt out of this, by expanding their arguments. If @views did this, it would act on the code @tullio produces, and would be less likely to cause trouble. But it doesn't.
Thanks for the response. I think this would be a common gotcha and maybe worth putting in the docs.
Maybe this macro should notice Base.maybeview, and thrown an informative error. That wouldn't be so hard to implement.