Skip to content

Commit f6a5f87

Browse files
committed
remove unnecessary true && part from at-view macro
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.
1 parent c32aeb5 commit f6a5f87

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

base/views.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,20 +123,18 @@ julia> A
123123
```
124124
"""
125125
macro view(ex)
126+
Meta.isexpr(ex, :ref) || throw(ArgumentError(
127+
"Invalid use of @view macro: argument must be a reference expression A[...]."))
128+
ex = replace_ref_begin_end!(ex)
126129
if Meta.isexpr(ex, :ref)
127-
ex = replace_ref_begin_end!(ex)
128-
if Meta.isexpr(ex, :ref)
129-
ex = Expr(:call, view, ex.args...)
130-
else # ex replaced by let ...; foo[...]; end
131-
if !(Meta.isexpr(ex, :let) && Meta.isexpr(ex.args[2], :ref))
132-
error("invalid expression")
133-
end
134-
ex.args[2] = Expr(:call, view, ex.args[2].args...)
135-
end
136-
Expr(:&&, true, esc(ex))
130+
ex = Expr(:call, view, ex.args...)
131+
elseif Meta.isexpr(ex, :let) && (arg2 = ex.args[2]; Meta.isexpr(arg2, :ref))
132+
# ex replaced by let ...; foo[...]; end
133+
ex.args[2] = Expr(:call, view, arg2.args...)
137134
else
138-
throw(ArgumentError("Invalid use of @view macro: argument must be a reference expression A[...]."))
135+
error("invalid expression")
139136
end
137+
return esc(ex)
140138
end
141139

142140
############################################################################

0 commit comments

Comments
 (0)