Understanding JuliaInterpreter.jl and partial interpretation

Quick question about the new and exciting JuliaInterpreter.jl:

After reading the docs, I have two related questions about partial-interpretation:

  1. Interpreting a function call is recursive, right? When I call @interpret sum(list), this will also interpret any functions called inside sum (such as +, for example)?
  2. Assuming the answer to the above question is “yes”, is there any way to have it not do that? :smile:
    • I’d love the ability to say “hey, this function right here, this one takes a long time to compile/specialize. For now, please don’t recompile it, but still go ahead and do everything all normal-like for all the functions it calls.”
    • I can imagine there might be world-age issues with something like that though?

Thanks!

1 Like

Yes.

Yes, but not out-of-the-box. Ideally we’d have something like what @tim.holy proposes here, but that’s probably not going to happen quickly.

For now: If you look at the implementation of @interpret, you’ll see a call to finish_and_return!(frame). I think you should be able to replace that with finish_and_return!(Compiled(), frame) so that only that method is interpreted. Of course this will lead to all sorts of problems with e.g. kwargs wrappers and such, but you can take a look at Debugger.@run to (hopefully) step through those.

And yes, the interpreter is 265-ing, so YMMV.

You can always push! a method onto JuliaInterpreter.compiled_methods, and then it will not recurse into your method.

2 Likes

That’s not very helpful if you want to interpret a certain method but nothing that method calls though, which is what Nathan seems to want to do.

1 Like

:raised_hands: Haha yes Tim’s point did not escape my attention either. Neat! :slight_smile:

I’ll take a look into this. Thanks @pfitzseb.

Haha :’( Yeah that makes sense. thanks again!

Oh cool! Yeah, Sebastian is right that this probably won’t help me, since I wouldn’t know what functions that might call, but it’s still good to know about and might be helpful. Thanks Tim! :slight_smile:

After reading the code some more, I think what I’m really after is the exact inverse of compiled_methods. I want to have a Set of interpreted_methods, and run the interpreter such that only those methods will be interpreted, even if entered from a compiled method.

But the good news is that I also have control over all such methods, so i can also redefine them all to just be something like "set compiled_methods to be every method except me; run interpreter on this inner function _f()"…

I will play around with this when i get some time! :slight_smile: Thanks!

EDIT: but i guess this is basically identical to what @pfitzseb suggested, and his suggestion seems easier to manage. :slight_smile:

Calling a method f(args...) in compiled mode is literally executing the statement f(args...). You cannot “start” interpreting something called from f because the original compiled code is running.

Precisely. I suppose we could add a @interprethisexactcall macro to JuliaInterpreter.jl that does what I propose above and which you can add to whatever callsite you want (or create a wrapper and only use that).

So you mean something that is pretty much equivalent to @run but the interpretation mode set to Compiled()?