Closed
Description
There is a weird edge case when defining a TapedTask
with arguments but not using them in the body of the function. For example:
function f(x)
produce(1)
end
trace = TapedTask(f, 2)
consume(trace)
yields an empty sequence error:
ERROR: LoadError: ArgumentError: reducing over an empty collection is not allowed
Stacktrace:
[1] _empty_reduce_error()
@ Base ./reduce.jl:301
[2] reduce_empty(op::Function, #unused#::Type{Int64})
@ Base ./reduce.jl:311
[3] reduce_empty(op::Base.BottomRF{typeof(max)}, #unused#::Type{Int64})
@ Base ./reduce.jl:330
[4] reduce_empty_iter
@ ./reduce.jl:357 [inlined]
[5] reduce_empty_iter
@ ./reduce.jl:356 [inlined]
[6] foldl_impl
@ ./reduce.jl:49 [inlined]
[7] mapfoldl_impl
@ ./reduce.jl:44 [inlined]
[8] #mapfoldl#244
@ ./reduce.jl:162 [inlined]
[9] mapfoldl
@ ./reduce.jl:162 [inlined]
[10] #mapreduce#248
@ ./reduce.jl:289 [inlined]
[11] mapreduce
@ ./reduce.jl:289 [inlined]
[12] #maximum#258
@ ./reduce.jl:737 [inlined]
[13] maximum
@ ./reduce.jl:737 [inlined]
[14] translate!(tape::Vector{Libtask.AbstractInstruction}, ir::Core.CodeInfo)
@ Libtask ~/Documents/projects/turing/AdvancedPS.jl/Libtask.jl/src/tapedfunction.jl:320
The same runs fine if the arg is used within the function body:
function f(x)
produce(x)
end
trace = TapedTask(f, 2)
consume(trace) # 2
The issue seems to be the way the arg_slots
are constructed here:
Libtask.jl/src/tapedfunction.jl
Lines 317 to 320 in 8ea2899
Metadata
Metadata
Assignees
Labels
No labels