`@interpret(x == 2)` and `@interpret(x) == 2` lead to different execution world ages
https://github.com/JuliaDebug/JuliaInterpreter.jl/blob/22f186bf2fcca6ef6b5570770035011441cb3bba/test/interpret.jl#L416-L420 is broken on Julia 1.12 and can be fixed by changing the test to @test @interpret(g_gf()) == 2. As much sense as I think that change makes, I decided to try to understand why this happens and only appeared now. It turns out that the error is thrown at https://github.com/JuliaDebug/JuliaInterpreter.jl/blob/22f186bf2fcca6ef6b5570770035011441cb3bba/src/construct.jl#L753, where we try to evaluate the arguments passed to the call, and for the current test the outer call is ==(g_gf(), 2). Thus it tries to Core.eval(Main, :(g_gf())), and this fails for reasons of world age.
Fundamentally this seems to be testing that JuliaInterpreter doesn't respect world ages properly. Should we ditch this test?
Yes, if that's what's intended, that would be a fine fix. But note that the test as written doesn't actually interpret g_gf(). If that's the goal, we need the parens. (EDIT: this was a response to a comment that was deleted.)
(I deleted my earlier reply because I posted it too early, sorry).
Maybe the test can be changed to
q = 0
function h()
eval(:(q = 2))
return q
end
@test @interpret(h() == 2)
?
I think @aviatesk has said that this whole optimization of resolving values early is invalid anyway though..
Yes, it doesn't seem to respect world ages. That may be more important with the bindings work in 1.12. Unfortunately, getting this fixed is probably not a small change, and the performance cost will likely be significant.
In an ideal world what we'd have is a whole invalidation framework for JuliaInterpreter now: resolve the bindings in the right world age, but when the world age updates you have to check for invalidations. Ugh.
So the easier thing is to boot out the optimization and get things at the time you need them (in the right world age).
I think @aviatesk has said that this whole optimization of resolving values early is invalid anyway though..
It's also been deactivated (which is partly why so much is broken)
https://github.com/JuliaDebug/JuliaInterpreter.jl/blob/822632d6f77323d338cf1e6765d1d6d5e10421c0/src/optimize.jl#L43