JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.14k stars 5.43k forks source link

Broadcast view of `Base.Experimental.Const` fails on 1.11 #55075

Open hexaeder opened 2 weeks ago

hexaeder commented 2 weeks ago

The following code errors on v1.11-rc1 but works on 1.10 v1.11-beta2

a = Base.Experimental.Const([1,2,3])
b = rand(3)
b .= a # works as expected

av = view(a, 1:2)
bv = view(b, 1:2)
bv .= av # errors on v1.11-rc1
ERROR: MethodError: no method matching elsize(::Type{Base.Experimental.Const{Int64, 1}})
The function `elsize` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  elsize(::Type{Union{}}, Any...)
   @ Base array.jl:233
  elsize(::Type{<:SubArray{<:Any, <:Any, P}}) where P
   @ Base subarray.jl:442
  elsize(::Type{A}) where {T, A<:(Array{T})}
   @ Base array.jl:225
  ...

Stacktrace:
  [1] elsize(A::Base.Experimental.Const{Int64, 1})
    @ Base ./abstractarray.jl:257
  [2] _parentsmatch(A::Vector{Float64}, B::Base.Experimental.Const{Int64, 1})
    @ Base ./multidimensional.jl:1071
  [3] mightalias(A::SubArray{…}, B::SubArray{…})
    @ Base ./multidimensional.jl:1056
  [4] unalias(dest::SubArray{…}, A::SubArray{…})
    @ Base ./abstractarray.jl:1503
  [5] copyto!
    @ ./abstractarray.jl:1060 [inlined]
  [6] copyto!
    @ ./broadcast.jl:961 [inlined]
  [7] copyto!
    @ ./broadcast.jl:920 [inlined]
  [8] materialize!
    @ ./broadcast.jl:878 [inlined]
  [9] materialize!(dest::SubArray{…}, bc::Base.Broadcast.Broadcasted{…})
    @ Base.Broadcast ./broadcast.jl:875
 [10] top-level scope
    @ REPL[12]:1
 [11] top-level scope
    @ none:1
Some type information was truncated. Use `show(err)` to see complete types.
nsajko commented 2 weeks ago

You could probably use the UnsafeAssume package instead.

hexaeder commented 2 weeks ago

Thanks for the hint. The error appeared due to some @Const declarations in a KernelAbstractions.jl kernel on the CPU backend, so it's not really up to me to change it. However, it's not really breaking in my use case, and I can easily circumvent the problem, but since I noticed the regression from 1.10, I thought I'd report it.

nsajko commented 2 weeks ago

FTR this isn't necessarily a bug in Julia, it's possible this was an intentional change. Notice the Experimental.

hexaeder commented 2 weeks ago

Sure thing, it says Experimental quite prominently, so feel free to close the issue if it was intentionally.

I just noticed that error was introduce quite recently for v1.11.0-rc1, in v1.11.0.-beta2 still worked as expected, I changed my initial post accordingly.

Seems to be related to https://github.com/JuliaLang/julia/pull/54624