# Understanding JuliaInterpreter.jl and partial interpretation

**URL:** <https://discourse.julialang.org/t/understanding-juliainterpreter-jl-and-partial-interpretation/23320>\
**Category:** Tooling\
**Tags:** question, package\
**Created:** [April 19, 2019, 6:30pm UTC](https://discourse.julialang.org/t/understanding-juliainterpreter-jl-and-partial-interpretation/23320 "2019-04-19T18:30:04Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![NHDaly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nhdaly/32/1413_2.png) [@NHDaly](https://discourse.julialang.org/u/NHDaly)\
**Post date:** [April 19, 2019, 6:30pm UTC](https://discourse.julialang.org/t/understanding-juliainterpreter-jl-and-partial-interpretation/23320/1 "2019-04-19T18:30:04Z")

</div>

Quick question about the new and exciting [JuliaInterpreter.jl](https://github.com/JuliaDebug/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? 😄
  - 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!

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [April 19, 2019, 7:51pm UTC](https://discourse.julialang.org/t/understanding-juliainterpreter-jl-and-partial-interpretation/23320/2 "2019-04-19T19:51:40Z")

</div>

> [@NHDaly](#):
>
> 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)?

Yes.

> [@NHDaly](#):
>
> 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](https://github.com/JuliaDebug/JuliaInterpreter.jl/issues/44), but that’s probably not going to happen quickly.

For now: If you look at the [implementation of `@interpret`](https://github.com/JuliaDebug/JuliaInterpreter.jl/blob/7deef4429ae90658d9351e05e3be42181a142b79/src/construct.jl#L656-L677), you’ll see a call to [`finish_and_return!(frame)`](https://github.com/JuliaDebug/JuliaInterpreter.jl/blob/2c7ef5788352db40b3bfab7500a2cf52471f9de6/src/commands.jl#L21-L33). 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](https://github.com/JuliaDebug/JuliaInterpreter.jl/issues/262), so YMMV.

---

<div class="post-metadata">

**Author:** ![tim.holy](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tim.holy/32/52_2.png) [@tim.holy](https://discourse.julialang.org/u/tim.holy)\
**Post date:** [April 19, 2019, 7:58pm UTC](https://discourse.julialang.org/t/understanding-juliainterpreter-jl-and-partial-interpretation/23320/3 "2019-04-19T19:58:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [April 19, 2019, 8:01pm UTC](https://discourse.julialang.org/t/understanding-juliainterpreter-jl-and-partial-interpretation/23320/4 "2019-04-19T20:01:02Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![NHDaly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nhdaly/32/1413_2.png) [@NHDaly](https://discourse.julialang.org/u/NHDaly)\
**Post date:** [April 19, 2019, 11:24pm UTC](https://discourse.julialang.org/t/understanding-juliainterpreter-jl-and-partial-interpretation/23320/5 "2019-04-19T23:24:30Z")

</div>

> [@pfitzseb](#):
>
> Yes, but not out-of-the-box. Ideally we’d have something like what @tim.holy proposes [here](https://github.com/JuliaDebug/JuliaInterpreter.jl/issues/44), but that’s probably not going to happen quickly.

🙌 Haha yes Tim’s point did not escape my attention either. Neat! 🙂

> [@pfitzseb](#):
>
> For now: …

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

> [@pfitzseb](#):
>
> And yes, the interpreter is [265-ing](https://github.com/JuliaDebug/JuliaInterpreter.jl/issues/262), so YMMV.

Haha 😢 Yeah that makes sense. thanks again!

> [@tim.holy](#):
>
> You can always `push!` a method onto `JuliaInterpreter.compiled_methods` , and then it will not recurse into your method.

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! 🙂

---

<div class="post-metadata">

**Author:** ![NHDaly](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nhdaly/32/1413_2.png) [@NHDaly](https://discourse.julialang.org/u/NHDaly)\
**Post date:** [April 19, 2019, 11:31pm UTC](https://discourse.julialang.org/t/understanding-juliainterpreter-jl-and-partial-interpretation/23320/6 "2019-04-19T23:31:01Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 20, 2019, 6:20am UTC](https://discourse.julialang.org/t/understanding-juliainterpreter-jl-and-partial-interpretation/23320/7 "2019-04-20T06:20:17Z")

</div>

> [@NHDaly](#):
>
> and run the interpreter such that only those methods will be interpreted, even if entered from a compiled method.

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.

---

<div class="post-metadata">

**Author:** ![pfitzseb](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pfitzseb/32/45566_2.png) [@pfitzseb](https://discourse.julialang.org/u/pfitzseb)\
**Post date:** [April 20, 2019, 11:03am UTC](https://discourse.julialang.org/t/understanding-juliainterpreter-jl-and-partial-interpretation/23320/8 "2019-04-20T11:03:42Z")

</div>

> [@kristoffer.carlsson](#):
>
> 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).

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [April 20, 2019, 4:26pm UTC](https://discourse.julialang.org/t/understanding-juliainterpreter-jl-and-partial-interpretation/23320/9 "2019-04-20T16:26:49Z")

</div>

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