Closed ferrolho closed 2 years ago
The stacktrace goes through the following StaticArrays.jl files:
/src/traits.jl
/src/abstractarray.jl
/src/convert.jl
.Looking at the diff between versions https://github.com/JuliaArrays/StaticArrays.jl/compare/v1.4.4...v1.4.5, /src/traits.jl
and /src/abstractarray.jl
seem to have been left unchanged. However, /src/convert.jl
was heavily modified, so I suspect something is missing in there?
I'm almost sure it's a Cassette bug, the same one as this: https://github.com/JuliaLabs/Cassette.jl/issues/198 .
If there is no chance of having it fixed in Cassette then we may be able to fix it in StaticArrays.jl.
I'm seeing a similar (?) issue when loading ITensors.jl
and any version of StaticArrays
since 1.4.5
:
using Pkg
Pkg.activate(; temp=true)
Pkg.add(name="StaticArrays", version="1.4.5")
Pkg.add(name="ITensors")
using ITensors
using StaticArrays
With this setup I get:
julia> @MVector zeros(2)
ERROR: The size of type `MVector{N, 2} where N` is not known.
If you were trying to construct (or `convert` to) a `StaticArray` you
may need to add the size explicitly as a type parameter so its size is
inferrable to the Julia compiler (or performance would be terrible). For
example, you might try
m = zeros(3,3)
SMatrix(m) # this error
SMatrix{3,3}(m) # correct - size is inferrable
SArray{Tuple{3,3}}(m) # correct, note Tuple{3,3}
Stacktrace:
[1] error(s::String)
@ Base ./error.jl:33
[2] missing_size_error(#unused#::Type{MVector{N, 2} where N})
@ StaticArrays ~/.julia/packages/StaticArrays/G7IlJ/src/traits.jl:73
[3] Size(#unused#::Type{MVector{N, 2} where N})
@ StaticArrays ~/.julia/packages/StaticArrays/G7IlJ/src/traits.jl:90
[4] zeros(#unused#::Type{MVector{N, 2} where N})
@ StaticArrays ~/.julia/packages/StaticArrays/G7IlJ/src/arraymath.jl:1
[5] top-level scope
@ REPL[7]:1
julia> @MVector zeros(Int, 2)
ERROR: TypeError: in Type, in parameter, expected Type, got a value of type Tuple{DataType}
Stacktrace:
[1] Size(s::Type{Tuple{Int64}})
@ StaticArrays ~/.julia/packages/StaticArrays/G7IlJ/src/traits.jl:68
[2] Size
@ ~/.julia/packages/StaticArrays/G7IlJ/src/traits.jl:90 [inlined]
[3] zeros(#unused#::Type{MVector{Int64, 2}})
@ StaticArrays ~/.julia/packages/StaticArrays/G7IlJ/src/arraymath.jl:1
[4] top-level scope
@ REPL[8]:1
While with StaticArrays
version 1.4.4
and below it works fine:
using Pkg
Pkg.activate(; temp=true)
Pkg.add(name="StaticArrays", version="1.4.4")
Pkg.add(name="ITensors")
using ITensors
using StaticArrays
@MVector zeros(2)
@MVector zeros(Int, 2)
I get as expected:
julia> @MVector zeros(2)
2-element MVector{2, Float64} with indices SOneTo(2):
0.0
0.0
julia> @MVector zeros(Int, 2)
2-element MVector{2, Int64} with indices SOneTo(2):
0
0
EDIT: Version information:
julia> versioninfo()
Julia Version 1.7.3
Commit 742b9abb4d (2022-05-06 12:58 UTC)
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: Intel(R) Xeon(R) E-2176M CPU @ 2.70GHz
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-12.0.1 (ORCJIT, skylake)
Environment:
JULIA_EDITOR = vim
Now this is seriously weird:
julia> g(::Type{U}) where {U} = U
g (generic function with 2 methods)
julia> g(MVector)
MVector{N, T} where {T, N} (alias for MArray{Tuple{N}, T, 1, N} where {T, N})
julia> MVector
MVector (alias for MArray{Tuple{S}, T, 1, S} where {S, T})
Passing a type to a function makes it a different type?
Hm, at least it seems to work on Julia 1.8-rc1, so perhaps it's a Julia bug.
@mateuszbaran indeed, the issue I reported above is fixed in Julia 1.8-rc1 (the test above was using Julia 1.7.3).
@ferrolho could you check if adding this method:
@pure StaticArrays.has_size(::Type{SVector}) = false
solves your problem?
Yes! Yes, it does. Just tried it on StaticArrays.jl v1.5.0
and Julia 1.7.2
. I can't understand if this means it is a bug with StaticArrays.jl, Julia itself, or something else. Should I include this somewhere within my code for now, as a workaround?
It looks like a Cessette bug. I think I will just make a patch to StaticArrays.jl with this method, other people may encounter it too so this seems to be the best we can do.
Thank you!
You're welcome :slightly_smiling_face: .
@mateuszbaran looks like this also fixes the issue I reported above, thanks!
Hi! I have just run into this issue - https://github.com/JuliaRobotics/MeshCatMechanisms.jl/issues/68 - and after some trial and error downgrading StaticArrays, it seems that it started happening with the changes introduced in StaticArrays.jl@v1.4.5. Below is a MWE and the error it is triggering.
Any ideas on how to fix this? Thanks!