Libtask.jl
Libtask.jl copied to clipboard
[WIP] A way to add kwarg support to #164
I had a branch locally with some initial work on kwarg-support, and now, thanks to #164, it works!
julia> f(x; y=2) = (produce(2x + y); return 2x)
f (generic function with 1 method)
julia> g(x) = f(f(x))
g (generic function with 1 method)
julia> Libtask.is_primitive(::typeof(f), x) = false
julia> task = Libtask.TapedTask(g, 1)
TapedTask{typeof(g), Tuple{Int64}}(Task (runnable) @0x00007f9f16a160e0, TapedFunction:
* .func => g
* .ir =>
------------------
CodeInfo(
1 ─ %1 = Main.f(x)::Int64
│ %2 = Main.f(%1)::Int64
└── return %2
)
------------------
, (1,), Channel{Any}(0), Channel{Int64}(0), Any[])
julia> consume(task)
4
julia> consume(task)
6
julia> consume(task)
A few very important drawbacks:
- [ ] Currently only work on Julia 1.9, but it should be possible to make it work on previous versions by making use of
Core.kwftype. - [ ] Will have name-clashes with
cacheanddeepcopy_typesthat are used in Libtask.jl. This can be resolved by a) renaming those to something less common, e.g.__libtask__cache__or something, and b) throwing an error if we hit it.
EDIT: I wanted to make this PR to your branch @willtebbutt but couldn't because that branch is on your fork.
TBH I think I prefer this to making changes in DynamicPPL, as originally discussed. This way we keep all the complexity in Libtask, rather than shifting some of the complexity of Libtask into the design of DynamicPPL.jl