diff --git a/src/refelim.jl b/src/refelim.jl index f0de7e65..2278afbf 100644 --- a/src/refelim.jl +++ b/src/refelim.jl @@ -239,6 +239,9 @@ function eliminate_refs(ir::BBCode, refs::Tuple) # %1 = set_ref_at!(_1, refid, Main.a) # can be replaced with # %1 = Main.a + # In theory we could eliminate the SSA ID entirely and replace + # all uses of it with the GlobalRef/Argument directly. We'll + # leave that optimisation to the Julia compiler though. refid_to_ssaid_map[refid] = id push!(new_insts, (id, new_inst(value_arg))) else @@ -253,7 +256,7 @@ function eliminate_refs(ir::BBCode, refs::Tuple) ssaid = get(old_ssaid_to_new_ssaid_map, value_arg, value_arg) refid_to_ssaid_map[refid] = ssaid elseif value_arg isa GlobalRef || value_arg isa Argument - # Create a new SSA ID that points to the GlobalRef. + # Create a new SSA ID that points to the thing. new_id = ID() push!(new_insts, (new_id, new_inst(value_arg))) refid_to_ssaid_map[refid] = new_id diff --git a/test/copyable_task.jl b/test/copyable_task.jl index fb1f32dd..fcd8403a 100644 --- a/test/copyable_task.jl +++ b/test/copyable_task.jl @@ -293,11 +293,19 @@ __global_a = 1.0 end @testset "Return produce" begin # Test calling a function that does something with the return value of `produce`. - # In this case it just returns it. This used to error, see - # https://github.com/TuringLang/Libtask.jl/issues/190. - f(obs) = produce(obs) + # This used to error, see https://github.com/TuringLang/Libtask.jl/issues/190. + function f(obs) + x = produce(obs) + # produce(x) returns x + return if isnothing(x) + produce(1.0) + else + produce(x) + end + end tt = Libtask.TapedTask(nothing, f, :a) @test Libtask.consume(tt) === :a + @test Libtask.consume(tt) === :a @test Libtask.consume(tt) === nothing end