Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In nested contexts method_for_inference_limit_heuristics is not properly set when there is an overdub(::Ctx, f::Any,...) method #150

Open
shashi opened this issue Oct 10, 2019 · 2 comments

Comments

@shashi
Copy link

shashi commented Oct 10, 2019

julia> using Cassette: overdub, recurse

julia> Cassette.@context Foo;

julia> CI, rt = @code_typed overdub(Foo(), overdub, Foo(), f)
CodeInfo(
1return Main.nothing
) => Nothing

julia> CI.method_for_inference_limit_heuristics
f() in Main at REPL[6]:1

Good ✅

julia> Cassette.overdub(::Foo, f, args...) = f(args...)

julia> CI, rt = @code_typed overdub(Foo(), overdub, Foo(), f)
CodeInfo(
1return
) => Nothing

julia> CI.method_for_inference_limit_heuristics
# nothing

Not good ❌

cc @vchuravy

@shashi
Copy link
Author

shashi commented Oct 11, 2019

Documenting some more findings.

We attempted extracting the method of f where Cassette sets the method_for_inference_limit_heuristics field. But because of the catch-all overdub method, we do not have access to even the type of f since the method signature is all any.

Also there may not be a suitable method for f: e.g. when defining how Duals work using overdub, we're actually trying to substitute for this method some overdubbed action which does not exist.

One thought I had is maybe the inference logic can do with just the types of the variables that a function is called with, but this may require lots of surgery to Core.Compiler.

@vchuravy
Copy link
Member

We should keep in mind what CI.method_for_inference_limit_heuristics is for.

Given an actual callgraph from a program:

f:
  g:
    h:
  m:

Inference uses the call graph to detect call cycles, and limit inferences. We want to retain the structure of the graph when we overdub it.
The graph above get's turned into:

overdub:
  overdub:
    overdub:
  overdub:

So instead of having a callgraph without a cycle, we now have a cycle (and now self-recursion rules kick in). CI.method_for_inference_limit_heuristics communicates the original call-graph, but as Shashi noted if you implement a overdub for all f and use recurse you now introduce cycles again...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants