Skip to content

Unreachable reached from builtin call to apply_iterate #34752

@maleadt

Description

@maleadt

The following code crashes with an illegal instruction on Julia 1.1+ (bisected to #28955):

struct a{T}
  b
  c
  function a(c, d...)
    e = length(d)
    e > 1 || error()
    new{Nothing}(d, 42)
  end
end

function h(g)
  g = (d = 42, c = g.c, dontcare = 42)
  a(g...)
end

h(a(42, 42, 42))

@code_warntype:

Variables
  #self#::Core.Compiler.Const(h, false)
  g@_2::a{Nothing}
  g@_3::Union{a{Nothing}, NamedTuple{(:d, :c, :dontcare),_A} where _A<:Tuple}

Body::Union{}
1 ─      (g@_3 = g@_2)
│   %2 = (:d, :c, :dontcare)::Core.Compiler.Const((:d, :c, :dontcare), false)
│   %3 = Core.apply_type(Core.NamedTuple, %2)::Core.Compiler.Const(NamedTuple{(:d, :c, :dontcare),T} where T<:Tuple, false)
│   %4 = Base.getproperty(g@_3::a{Nothing}, :c)::Any
│   %5 = Core.tuple(42, %4, 42)::Core.Compiler.PartialStruct(Tuple{Int64,Any,Int64}, Any[Core.Compiler.Const(42, false), Any, Core.Compiler.Const(42, false)])
│        (g@_3 = (%3)(%5))
│        Core._apply_iterate(Base.iterate, Main.a, g@_3::NamedTuple{(:d, :c, :dontcare),_A} where _A<:Tuple)
└──      Core.Compiler.Const(:(return %7), false)

The trap comes from here:

julia/src/codegen.cpp

Lines 4153 to 4155 in 79f31e4

if (res.typ == jl_bottom_type || expr_t == jl_bottom_type) {
CreateTrap(ctx.builder);
}

The call codegen stumbles on is Expr(:call, Core._apply_iterate, Base.iterate, Main.a, SSAValue(4)). Probably a dup of some other unreachable reached issue, but it's hard to tell.

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorcompiler:inferenceType inferenceregressionRegression in behavior compared to a previous version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions