Interpret Main.foreach but keep Base.foreach as compiled

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

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

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.

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.