IRTools.jl icon indicating copy to clipboard operation
IRTools.jl copied to clipboard

Codegen assertion fails in 1.5.0-DEV.51

Open phipsgabler opened this issue 5 years ago • 3 comments

I have been observing an assertion failure in codegen.cpp since about a month on nightly (see here), but couldn't yet find a minimal example.

codegen.cpp:4353: jl_cgval_t emit_expr(jl_codectx_t&, jl_value_t*, ssize_t): Assertion `token.V->getType()->isTokenTy()' failed.

signal (6): Aborted
in expression starting at /home/travis/build/phipsgabler/DynamicComputationGraphs.jl/test/test_basics.jl:6
gsignal at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7f25a5a3cbd6)
__assert_fail at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
emit_expr at /buildworker/worker/package_linux64/build/src/codegen.cpp:4353

Maybe this change has something to do with it -- the part of the code causing this is where gc_preserve_end_sym expressions are handled.

phipsgabler avatar Feb 17 '20 18:02 phipsgabler

It would be great to understand whether this actually comes from IRTools or the package (e.g. by showing that a no-op dynamo errors like this). And if so, helpful if we can narrow it down to a specific function that causes the error, and it's likely pretty easy to fix.

MikeInnes avatar Feb 18 '20 16:02 MikeInnes

I talked to @simeonschaub on Slack about it, maybe he has a shorter example?

phipsgabler avatar Feb 20 '20 08:02 phipsgabler

Here's a more minimal example that crashes on nightly:

using IRTools: @dynamo, IR, recurse!, block, branches, branch!

macro mark(ex)
    return Expr(
        :block,
        Expr(:meta, :begin_mark),
        esc(ex),
        Expr(:meta, :end_mark),
    )
end

@dynamo function skip(x...)
    ir = IR(x...)
    ir === nothing && return

    tape = []

    for (x, st) in ir
        is_layer_begin = Meta.isexpr(st.expr, :meta) &&
            st.expr.args[1] === :begin_mark
        is_layer_end =  Meta.isexpr(st.expr, :meta) &&
            st.expr.args[1] === :end_mark

        if is_layer_begin
            push!(tape, :a)
        elseif is_layer_end
            pop!(tape)
        end
    end

    recurse!(ir)
    return ir
end

function inner()
    ret = Int[]
    push!(ret, 2)
    @mark push!(ret, 3)
    ret
end

function outer()
    ret = Int[]
    push!(ret, 1)
    x = inner()
    append!(ret, x)
    @mark push!(ret, 4)
    push!(ret, 5)
    ret
end

skip(outer)

simeonschaub avatar Feb 20 '20 09:02 simeonschaub