You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Related to #48, mentioned on Slack and @vchuravy encouraged me to open an issue.
using Cassette: Cassette
Cassette.@context Ctx
# Here's the "normal" case where we don't accept keyword argumentsf(_args...) =println("f")
function Cassette.overdub(ctx::Ctx, ::typeof(f), args...)
iffalse# But really, sometimes true.:hielse# When there are no keywords, everything is fine.
Cassette.recurse(ctx, f, args...)
endend# Cassette.overdub(Ctx(), () -> f(1))# And here's the weird one with kwargsg(_args...; _kwargs...) =println("g")
Cassette.overdub(ctx::Ctx, ::Core.kwftype(typeof(g)), kwargs, ::typeof(g), args...) =
Cassette.overdub(ctx, g, args...; kwargs...)
function Cassette.overdub(ctx::Ctx, ::typeof(g), args...; kwargs...)
iffalse# But really, sometimes true.:hielse# How can I recurse into f with keywords?# 1. This throws an exception:# Cassette.recurse(ctx, g, args...; kwargs...)# 2. This just loops back to this point, causing a stack overflow:# Cassette.recurse(ctx, () -> g(args...; kwargs...))"????????????"endend# Cassette.overdub(Ctx(), () -> g(; x=1))
To me, this is expected behaviour:
Option 1 shouldn't work because recurse is not defined with keyword arguments.
Option 2 recurses into a new anon function, which then calls g(args...; kwargs...), which reaches overdub(ctx::Ctx, ::Core.kwftype(typeof(g)), kwargs, ::typeof(g), args...), which calls overdub(ctx::Ctx, ::typeof(g), args...; kwargs...), which once again hits that recurse. So infinite recursion is justified.
The real solution here is to somehow be able to pass keywords to recurse. Is there a way that we can define a method of recurse that accepts keywords, similar to what we can do with overdub?
The text was updated successfully, but these errors were encountered:
Related to #48, mentioned on Slack and @vchuravy encouraged me to open an issue.
To me, this is expected behaviour:
Option 1 shouldn't work because
recurse
is not defined with keyword arguments.Option 2 recurses into a new anon function, which then calls
g(args...; kwargs...)
, which reachesoverdub(ctx::Ctx, ::Core.kwftype(typeof(g)), kwargs, ::typeof(g), args...)
, which callsoverdub(ctx::Ctx, ::typeof(g), args...; kwargs...)
, which once again hits thatrecurse
. So infinite recursion is justified.The real solution here is to somehow be able to pass keywords to
recurse
. Is there a way that we can define a method ofrecurse
that accepts keywords, similar to what we can do withoverdub
?The text was updated successfully, but these errors were encountered: