Skip to content

Type instability for vec[1, end] #525

@Ickaser

Description

@Ickaser

Describe the bug 🐞

Accessing a recursive array with [1, end] is type-unstable. Was type stable on v3.41 and earlier, broken on 3.42 and later. Related to @JoshuaLampert 's recent work, it seems.

Expected behavior

Type stability for array accesses.

Minimal Reproducible Example 👇

vecvec = VectorOfArray([fill(2.0, 2) for i in 1:10])
access_end(vec) = vec[1, end]
@code_warntype access_end(vecvec)

yields

MethodInstance for access_end(::VectorOfArray{Float64, 2, Vector{Vector{Float64}}})
  from access_end(vec) @ Main REPL[4]:1
Arguments
  #self#::Core.Const(Main.access_end)
  vec::VectorOfArray{Float64, 2, Vector{Vector{Float64}}}
Body::Any
1 ─ %1 = Base.lastindex(vec, 2)::Core.PartialStruct(RecursiveArrayTools.RaggedEnd, Any[Core.Const(0), Int64])
│   %2 = Base.getindex(vec, 1, %1)::Any
└──      return %2

Error & Stacktrace ⚠️

Digging around with Cthulhu, I see:

Image that is, starting at https://github.com/SciML/RecursiveArrayTools.jl/blob/6519ecf4fbf69a6134051d1fa11ad5685dd93c3a/src/vector_of_array.jl#L838, `cols`, `prefix`, `resolved`, `inner_nd`, `padded` all are getting boxed somehow and killing the inference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions