Why @view add a "true &&" before the view call?

I’m try to look into the @avx macro offered by LoopVectorization.jl, which replace the Base.materialize(!) with the auther defined function.

I want to use the same design to make my own module to support macro like @par b .= f.(a) to perform multithreads broadcast, then I found that the @view macro will add a true && before the view call, leading to IR with Core.GotoNode and Expr(:gotoifnot,true,...), while @views don’t.
LoopVectorization.jl will throw a error when this happen.

It confuse me that the meaning of true && here. For macro I want, a replacement of Expr(::&&) before Meta.lower() is enough, but I still wonder why we need it.

This will probably be changing, see https://github.com/JuliaLang/julia/pull/36780.

The comment says

# wrap in a let block to prevent accidentally redefining `view` if used on the LHS, e.g.
#   @view(A[x]) = 2

Before the proposed change it was not a let block, but true &&, which had the same effect: To not redefine view by accident:

julia> view(A, :, a) = b
view (generic function with 1 method)
3 Likes