# Interpret Main.foreach but keep Base.foreach as compiled

**URL:** <https://discourse.julialang.org/t/interpret-main-foreach-but-keep-base-foreach-as-compiled/104000>\
**Category:** Tooling\
**Tags:** debug\
**Created:** [September 18, 2023, 8:14pm UTC](https://discourse.julialang.org/t/interpret-main-foreach-but-keep-base-foreach-as-compiled/104000 "2023-09-18T20:14:07Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mariusd](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mariusd/32/23231_2.png) [@mariusd](https://discourse.julialang.org/u/mariusd)\
**Post date:** [September 18, 2023, 8:14pm UTC](https://discourse.julialang.org/t/interpret-main-foreach-but-keep-base-foreach-as-compiled/104000/1 "2023-09-18T20:14:07Z")

</div>

I’m currently debugging the Tracker.jl package, and see this line [https://github.com/FluxML/Tracker.jl/blob/master/src/back.jl#L38C6-L38C6](https://github.com/FluxML/Tracker.jl/blob/master/src/back.jl#L38C6-L38C6). `foreach` calls the `back` method and because `foreach` is compiled, I cannot debug the `back` method.

**JuliaInterpreter related question:**  
Can I set `foreach` to be interpreted in `Main` and `Tracker`, while keeping it as compiled in all other modules?  
I want to have `foreach, map, broadcast` etc as interpreted just where they are used in my code, while keeping them compiled in all the other modules. It looks like it does not work currently, but is there a way to achieve this behaviour? I think this would be great for the debugging experience.

 ![Screenshot from 2023-09-18 10-38-26](https://global.discourse-cdn.com/julialang/original/3X/1/c/1c672cf858489753b06baa89d4e770062073eb25.png)

@tim.holy, @kristoffer.carlsson, @pfitzseb

---

<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:** [September 18, 2023, 9:04pm UTC](https://discourse.julialang.org/t/interpret-main-foreach-but-keep-base-foreach-as-compiled/104000/2 "2023-09-18T21:04:29Z")

</div>

> Can I set `foreach` to be interpreted in `Main` and `Tracker`, while keeping it as compiled in all other modules?

Kinda. The decision is made based on the method, not the function level in JuliaInterpreter. VS Code however only has a function level interface IIRC (it’s possible but unlikely that `foo(::Bar, ::Baz)` also works).

With direct Debugger.jl usage you can also just slap your `@run` statement into whatever function you’re looking at to make the debugging session more local, but I’m not sure if that would help in this specific case.

---

<div class="post-metadata">

**Author:** ![mrufsvold](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mrufsvold/32/31600_2.png) [@mrufsvold](https://discourse.julialang.org/u/mrufsvold)\
**Post date:** [September 19, 2023, 11:11pm UTC](https://discourse.julialang.org/t/interpret-main-foreach-but-keep-base-foreach-as-compiled/104000/3 "2023-09-19T23:11:37Z")

</div>

I certainly don’t know more than @pfitzseb on this, but it’s been my experience that if a method call is compiled, all its child calls are compiled, even if they would otherwise be marked as interpreted.

So if you leave `Base` compiled, with the exception of `foreach`, it’s my understanding that anywhere Base calls `foreach` would still run compiled. Only when an noncompiled method calls `foreach` would it be interpreted.
