-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
remove unnecessary true &&
part from at-view
macro
#53064
Conversation
That was already present in #16564 by @simonbyrne, and the motivation was given in #16564 (comment)
If anything, this needs a test, and maybe an explicit comment in the code, to avoid further confusion. |
I traced back through the Update: Oh, I see that @giordano also pointed out the same thing. But it seems that you are making a bunch of other changes as well? |
Thank you. Certainly there is a difference from the previous code in cases like |
Using |
FWIW, it results in a syntax error even on this PR (unless we import julia> let A = [1,2], idx = (1,2)
@view(A[idx]) = 2
view(A, 1:2)
end
ERROR: syntax: invalid function name "Base.view" around REPL[18]:2
Stacktrace:
[1] top-level scope
@ REPL[18]:1 |
I really don't think anyone would expect |
I don't think that changes anything (anymore?). The macro (now?) plops the function itself into the AST. The error message talks about a "function name" and uses the stringified name, but it's not getting a name — it's getting a function object. It's the same as: julia> function f end
f (generic function with 0 methods)
julia> @eval ($f)(x) = x
ERROR: syntax: invalid function name "Main.f" Edit: Ah, yes, the original definition from #16564 generated an AST like |
The modification that expands `@view A[i]` to `true && view(A, i)` appears to go back as far as #20247. However, I'm not entirely sure why this is necessary. Considering that just expanding it to `view(A, i)` still seems to pass the base test suite, I wonder if it might be just better to get rid of that part.
Thanks for your input, Bauman. Embedding the function object directly allows for triggering a syntax error, independent of imports. I've kept comments and tests as a future reference. I think now this PR is ready to go. |
When the frontend lowers an expression like `lhs .+= rhs`, it needs to prevent evaluating the LHS more than once before re-writing to `lhs .= lhs .+ rhs`. If the LHS was a `let` block — commonly generated by `@views` and (since #53064) `@view` — the lowering pass had previously been emitting an invalid `let` temporary. This very directly addresses that case. Fixes #53107. Fixes #44356.
The modification that expands
@view A[i]
totrue && view(A, i)
appears to go back as far as #20247. However, I'm not entirely sure why this is necessary. Considering that just expanding it toview(A, i)
still seems to pass the base test suite, I wonder if it might be just better to get rid of that part.