Skip to content

Commit

Permalink
remove unnecessary true && part from at-view macro
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
aviatesk committed Jan 27, 2024
1 parent c32aeb5 commit f6a5f87
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions base/views.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +123,18 @@ julia> A
```
"""
macro view(ex)
Meta.isexpr(ex, :ref) || throw(ArgumentError(
"Invalid use of @view macro: argument must be a reference expression A[...]."))
ex = replace_ref_begin_end!(ex)
if Meta.isexpr(ex, :ref)
ex = replace_ref_begin_end!(ex)
if Meta.isexpr(ex, :ref)
ex = Expr(:call, view, ex.args...)
else # ex replaced by let ...; foo[...]; end
if !(Meta.isexpr(ex, :let) && Meta.isexpr(ex.args[2], :ref))
error("invalid expression")
end
ex.args[2] = Expr(:call, view, ex.args[2].args...)
end
Expr(:&&, true, esc(ex))
ex = Expr(:call, view, ex.args...)
elseif Meta.isexpr(ex, :let) && (arg2 = ex.args[2]; Meta.isexpr(arg2, :ref))
# ex replaced by let ...; foo[...]; end
ex.args[2] = Expr(:call, view, arg2.args...)
else
throw(ArgumentError("Invalid use of @view macro: argument must be a reference expression A[...]."))
error("invalid expression")
end
return esc(ex)
end

############################################################################
Expand Down

0 comments on commit f6a5f87

Please sign in to comment.