After reading the docs, I have two related questions about partial-interpretation:
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)?
Assuming the answer to the above question is “yes”, is there any way to have it not do that?
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?
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.
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!
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! Thanks!
EDIT: but i guess this is basically identical to what @pfitzseb suggested, and his suggestion seems easier to manage.
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).