Skip to content

could not deduce element type of value when vcat-ing array with abstract eltype #2589

@penelopeysm

Description

@penelopeysm

The following errors on both forward- and reverse-mode on 1.11. (1.10 is fine for both modes)

import Enzyme: Enzyme, Forward, Reverse

function f(x)
    r = vcat(Any[1])
    return 0.0
end
params = rand(3)
f(params)

Enzyme.gradient(Forward, f, params)
Enzyme.gradient(Reverse, f, params)

This causes errors on any Turing model where there are two VarNames with the same symbol but different types, e.g. x.a and x.b since they get put together in the same vector and vcatted here.

Stack trace:

julia> Enzyme.gradient(Forward, f, params)
ERROR: Enzyme execution failed.
Enzyme: could not deduce element type of value within generic_memory_copyto of   %10 = phi {} addrspace(10)* [ %9, %L15 ], [ addrspacecast ({}* inttoptr (i64 4782741872 to {}*) to {} addrspace(10)*), %top ] within   call void @jl_genericmemory_copyto({} addrspace(10)* noundef %10, i64 %19, {} addrspace(10)* noundef %29, i64 %38, i64 %8) #13, !dbg !77

Stacktrace:
  [1] unsafe_copyto!
    @ ./genericmemory.jl:125 [inlined]
  [2] unsafe_copyto!
    @ ./array.jl:284 [inlined]
  [3] vcat
    @ ./array.jl:2234
  [4] f
    @ ./REPL[2]:2 [inlined]
  [5] fwddiffe3julia_f_8313wrap
    @ ./REPL[2]:0
  [6] macro expansion
    @ ~/.julia/packages/Enzyme/KdRPO/src/compiler.jl:5713 [inlined]
  [7] enzyme_call
    @ ~/.julia/packages/Enzyme/KdRPO/src/compiler.jl:5247 [inlined]
  [8] ForwardModeThunk
    @ ~/.julia/packages/Enzyme/KdRPO/src/compiler.jl:5138 [inlined]
  [9] autodiff
    @ ~/.julia/packages/Enzyme/KdRPO/src/Enzyme.jl:669 [inlined]
 [10] autodiff
    @ ~/.julia/packages/Enzyme/KdRPO/src/Enzyme.jl:538 [inlined]
 [11] macro expansion
    @ ~/.julia/packages/Enzyme/KdRPO/src/sugar.jl:671 [inlined]
 [12] gradient(::EnzymeCore.ForwardMode{…}, ::typeof(f), ::Vector{…}; chunk::Nothing, shadows::Tuple{…})
    @ Enzyme ~/.julia/packages/Enzyme/KdRPO/src/sugar.jl:573
 [13] gradient(::EnzymeCore.ForwardMode{false, EnzymeCore.FFIABI, false, false, false}, ::typeof(f), ::Vector{Float64})
    @ Enzyme ~/.julia/packages/Enzyme/KdRPO/src/sugar.jl:573
 [14] top-level scope
    @ REPL[5]:1
Some type information was truncated. Use `show(err)` to see complete types.

Environment:

julia> versioninfo()
Julia Version 1.11.7
Commit f2b3dbda30a (2025-09-08 12:10 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: macOS (arm64-apple-darwin24.0.0)
  CPU: 10 × Apple M1 Pro
  WORD_SIZE: 64
  LLVM: libLLVM-16.0.6 (ORCJIT, apple-m1)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)

(ppl) pkg> st
Status `~/ppl/Project.toml`
  [7da242da] Enzyme v0.13.75

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions