JuliaLang / julia

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

`copy!(::Memory{Int}, ::Vector{Int})` causes JET warnings #56634

Open nsajko opened 1 week ago

nsajko commented 1 week ago
julia> using JET

julia> report_opt(copy!, Tuple{Memory{Int}, Vector{Int}})
═════ 1 possible error found ═════
┌ copy!(dst::Memory{Int64}, src::Vector{Int64}) @ Base ./abstractarray.jl:914
│ runtime dispatch detected: resize!(dst::Memory{Int64}, %12::Int64)
└────────────────────

julia> report_call(copy!, Tuple{Memory{Int}, Vector{Int}})
═════ 1 possible error found ═════
┌ copy!(dst::Memory{Int64}, src::Vector{Int64}) @ Base ./abstractarray.jl:914
│ no matching method found `resize!(::Memory{Int64}, ::Int64)`: resize!(dst::Memory{Int64}, length(src::Vector{Int64})::Int64)
└────────────────────

Should copy! get a specialized method, given that it's not resizable?

The workaround is to call copyto! instead.

aviatesk commented 1 week ago

This seems to be more of a design issue with Memory rather than a problem with JET? Memory is an AbstractVector, but since its size is fixed, it doesn’t support resize!.
Defining a method like resize(::Memory) = error("Memory isn't resizable") could silence JET while also providing a clear error message for users.