Skip to content

Commit 192d938

Browse files
authored
Merge branch 'main' into mhauru/produce-wrap-loop
2 parents d6f247a + 4d606eb commit 192d938

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/copyable_task.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -902,6 +902,15 @@ function derive_copyable_task_ir(ir::BBCode)::Tuple{BBCode,Tuple,Vector{Any}}
902902
prod_val = deref_id
903903
end
904904

905+
# Set the ref for this statement, as we would for any other call or invoke.
906+
# The TapedTask may need to read this ref when it resumes, if the return
907+
# value of `produce` is used within the original function.
908+
if is_used_dict[id]
909+
out_ind = ssa_id_to_ref_index_map[id]
910+
set_ref = Expr(:call, set_ref_at!, refs_id, out_ind, prod_val)
911+
push!(inst_pairs, (ID(), new_inst(set_ref)))
912+
end
913+
905914
# Construct a `ProducedValue`.
906915
val_id = ID()
907916
push!(inst_pairs, (val_id, new_inst(Expr(:call, ProducedValue, prod_val))))

test/copyable_task.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,13 @@
241241
@test Libtask.consume(tt) === :a
242242
@test Libtask.consume(tt) === :b
243243
@test Libtask.consume(tt) === :c
244+
@testset "Return produce" begin
245+
# Test calling a function that does something with the return value of `produce`.
246+
# In this case it just returns it. This used to error, see
247+
# https://github.com/TuringLang/Libtask.jl/issues/190.
248+
f(obs) = produce(obs)
249+
tt = Libtask.TapedTask(nothing, f, :a)
250+
@test Libtask.consume(tt) === :a
244251
@test Libtask.consume(tt) === nothing
245252
end
246253
end

0 commit comments

Comments
 (0)