Skip to content

StackOverflow when inferring Base.vect with many (>1000) arguments #55341

Closed
@topolarity

Description

@topolarity
julia> x = 1.0
           # foo() = [x, 1.0, 2.0, 3.0, ...]
julia> @eval foo() = [x, $([Float64(i) for i=1:1000]...)]
foo (generic function with 1 method)

julia> foo()
Internal error: stack overflow in type inference of foo().
This might be caused by recursion over very long tuples or argument lists.

The problematic inference stack looks (roughly) like this:

1. Base.vect(::Any, ::Float64 (1000 times)...)
2. Base.promote_typeof(::Any, ::Float64, ::Float64, ::Float64, ::Float64 (1000 times)...)
3. Base.promote_typeof(::Any, ::Float64 (999 times)...)
4. Base.promote_typeof(::Any, ::Float64 (998 times)...)
5. Base.promote_typeof(::Any, ::Float64 (997 times)...)
   etc... (996 more times)

Code like this can apparently end up generated by MTK (SymbolicUtils.Code.create_array), which is where I encountered this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions