-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
The @views
macro should only affect "rvalue" indexing expressions, as shown in,
julia> @macroexpand @views x[a:b] = c
:(x[a:b] = c)
Until recently, this also works for indexing with begin
or end
# Julia 1.13.0-DEV.989
julia> @macroexpand @views x[begin:end] = c
:(x[(firstindex)(x):(lastindex)(x)] = c)
but is broken (I assume as an side effect of #59239) now
# 1.13.0-DEV.1030
julia> @macroexpand @views x[begin:end] = c
:(begin
local var"##S#139" = x
#= views.jl:117 =#
#= views.jl:117 =#
(Base.maybeview)(var"##S#139", (firstindex)(var"##S#139"):(lastindex)(var"##S#139"))
end = c)
Note that this is clearly macro hygiene related and it was also broken previously if the array object is a non-trivial expression,
# Julia 1.13.0-DEV.989
julia> @macroexpand @views f(x)[begin:end] = c
:(let var"##S#289" = f(x)
(Base.maybeview)(var"##S#289", (firstindex)(var"##S#289"):(lastindex)(var"##S#289"))
end = c)
Although it wasn't explicitly stated, the document for @views
seems to be pretty reassuring that only expressions that is an "rvalue" array indexing will be affected so I assume array assignment should be supported (implemented as no-op). This also have real-world use https://github.com/SciML/BoundaryValueDiffEq.jl/blob/25e9002100500c527cd217d014aab19e047d1d2a/lib/BoundaryValueDiffEqFIRK/src/collocation.jl#L135 that's now broken.