As discussed in https://github.com/TuringLang/Turing.jl/pull/1237, it would be nice to implement the iteration interface for CTask since then it would be possible to use alternatives such as resumable functions in the particle filter implementations in Turing in a straightforward way (currently produce and consume statements are hardcoded). However, currently CTask is just a function that returns a Task for which stack copying has been enabled. Implementing the iteration interface for Task would be pretty bad type piracy (BTW Base.copy(::Task) in the current code is also type piracy). To avoid this I suggest adding a CTask struct that is defined as
struct CTask
task::Task
end
Then Base.copy and Base.iterate could be implemented without committing type piracy. The downside would be that one would probably have to forward a bunch of methods defined for Task (such istaskstarted etc.) to task.
Do you think I should give it a try, or are there any other suggestions?
As discussed in https://github.com/TuringLang/Turing.jl/pull/1237, it would be nice to implement the iteration interface for
CTask
since then it would be possible to use alternatives such as resumable functions in the particle filter implementations in Turing in a straightforward way (currentlyproduce
andconsume
statements are hardcoded). However, currentlyCTask
is just a function that returns aTask
for which stack copying has been enabled. Implementing the iteration interface forTask
would be pretty bad type piracy (BTWBase.copy(::Task)
in the current code is also type piracy). To avoid this I suggest adding aCTask
struct that is defined asThen
Base.copy
andBase.iterate
could be implemented without committing type piracy. The downside would be that one would probably have to forward a bunch of methods defined forTask
(suchistaskstarted
etc.) totask
.Do you think I should give it a try, or are there any other suggestions?