Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@views macro causes module compilation failure #158

Open
prittjam opened this issue Sep 21, 2022 · 3 comments
Open

@views macro causes module compilation failure #158

prittjam opened this issue Sep 21, 2022 · 3 comments
Labels
enhancement New feature or request

Comments

@prittjam
Copy link

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.

@mcabbott
Copy link
Owner

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.

@prittjam
Copy link
Author

Thanks for the response. I think this would be a common gotcha and maybe worth putting in the docs.

@mcabbott mcabbott added the enhancement New feature or request label Apr 28, 2023
@mcabbott
Copy link
Owner

Maybe this macro should notice Base.maybeview, and thrown an informative error. That wouldn't be so hard to implement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants