Infiltrator.jl icon indicating copy to clipboard operation
Infiltrator.jl copied to clipboard

`@infiltrate` stops working when Revise encounters parse errors

Open ExpandingMan opened this issue 4 years ago • 12 comments

Consider including the following script with includet

using Infiltrator

function test()
    ϕ = "what"
    @infiltrate
    sin(ϕ)
end

At first, this works as expected. Then, I cause a parsing error by changing "what" to "what'. Revise the throws the following error as expected

┌ Error: Failed to revise /home/expandingman/src/scrap.jl
│   exception =
│    LoadError: "incomplete: invalid string syntax"
│    Stacktrace:
│     [1] parse_source!(mod_exprs_sigs::OrderedCollections.OrderedDict{Module, OrderedCollections.OrderedDict{Revise.Relocat
bleExpr, Union{Nothing, Vector{Any}}}}, src::String, filename::String, mod::Module; mode::Symbol)
│       @ Revise ~/.julia/packages/Revise/OgnOk/src/parsing.jl:45
│    in expression starting at /home/expandingman/src/scrap.jl:7
└ @ Revise ~/.julia/packages/Revise/OgnOk/src/packagedef.jl:709
┌ Warning: The running code does not match the saved version for the following files:
│
│   /home/expandingman/src/scrap.jl
│
│ If the error was due to evaluation order, it can sometimes be resolved by calling `Revise.retry()`.
│ Use Revise.errors() to report errors again. Only the first error in each file is shown.
│ Your prompt color may be yellow until the errors are resolved.
└ @ Revise ~/.julia/packages/Revise/OgnOk/src/packagedef.jl:817

After fixing the string and recovering Revise with Revise.revise(), Revise is again working as expected. Infiltrator, however, does not and no longer breaks at @infiltrate even if I move it. I can confirm that Revise is working properly with print statements or whatever else, so this looks like purely an Infiltrator issue, though I can't rule out that something funky is happening in Revise that is stopping it from expanding the macro properly.

ExpandingMan avatar Sep 06 '21 13:09 ExpandingMan

Hm, interestingly enough I can't repro this issue. Just to be sure, you're on the latest version of both packages? Also, what Julia version are you on?

pfitzseb avatar Sep 06 '21 14:09 pfitzseb

Yup, latest tagged version of both packages. On Julia 1.6.2. This is using a startup.jl which can be found here.

ExpandingMan avatar Sep 06 '21 14:09 ExpandingMan

Very weird. With you startup file I get

λ j1 -q
julia> includet("test.jl")

julia> test()
Infiltrating test() at test.jl:5:

infil> 

0.9092974268256817

shell> cat test.jl
┌ Error: Failed to revise /home/pfitzseb/test.jl
│   exception =
│    LoadError: "incomplete: invalid string syntax"
│    Stacktrace:
│     [1] parse_source!(mod_exprs_sigs::OrderedCollections.OrderedDict{Module, OrderedCollections.OrderedDict{Revise.RelocatableExpr, Union{Nothing, Vector{Any}}}}, src::String, filename::String, mod::Module; mode::Symbol)
│       @ Revise ~/.julia/packages/Revise/OgnOk/src/parsing.jl:45
│    in expression starting at /home/pfitzseb/test.jl:8
└ @ Revise ~/.julia/packages/Revise/OgnOk/src/packagedef.jl:709
┌ Warning: The running code does not match the saved version for the following files:
│ 
│   /home/pfitzseb/test.jl
│ 
│ If the error was due to evaluation order, it can sometimes be resolved by calling `Revise.retry()`.
│ Use Revise.errors() to report errors again. Only the first error in each file is shown.
│ Your prompt color may be yellow until the errors are resolved.
└ @ Revise ~/.julia/packages/Revise/OgnOk/src/packagedef.jl:817
using Infiltrator

function test()
    ϕ = "what'
    @infiltrate
    sin(3)
end


julia> test()
Infiltrating test() at test.jl:5:

infil> 

0.9092974268256817

shell> cat test.jl
using Infiltrator

function test()
    ϕ = "what"
    @infiltrate
    sin(3)
end

julia> test()
Infiltrating test() at test.jl:5:

infil> 

0.1411200080598672

pfitzseb avatar Sep 06 '21 14:09 pfitzseb

Ah! No, I think I figured it out, it's the combination of the two errors. Don't pass 3 to sin, pass \phi to deliberately get the error. I get the behavior you're showing from the code you shared. Try doing exactly what I originally posted.

Btw, for the hell of it I tried this in a fresh environment and it makes no difference.

I've also changed by startup.jl so I do using Revise outside of atreplinit as is suggested in more recent versions of the Revise docs. Again, this makes no difference.

ExpandingMan avatar Sep 06 '21 14:09 ExpandingMan

Still no luck:

λ j1 -q
julia> includet("test.jl")

julia> test()
Infiltrating test() at test.jl:5:

infil> 

ERROR: MethodError: no method matching sin(::String)
Closest candidates are:
  sin(::Float16) at math.jl:1159
  sin(::ComplexF16) at math.jl:1160
  sin(::Complex{T}) where T at complex.jl:831
  ...
Stacktrace:
 [1] test()
   @ Main ~/test.jl:6
 [2] top-level scope
   @ REPL[2]:1
 [3] top-level scope
   @ ~/.julia/dev/Infiltrator/src/Infiltrator.jl:473

shell> cat test.jl
┌ Error: Failed to revise /home/pfitzseb/test.jl
│   exception =
│    LoadError: "incomplete: invalid string syntax"
│    Stacktrace:
│     [1] parse_source!(mod_exprs_sigs::OrderedCollections.OrderedDict{Module, OrderedCollections.OrderedDict{Revise.RelocatableExpr, Union{Nothing, Vector{Any}}}}, src::String, filename::String, mod::Module; mode::Symbol)
│       @ Revise ~/.julia/packages/Revise/OgnOk/src/parsing.jl:45
│    in expression starting at /home/pfitzseb/test.jl:7
└ @ Revise ~/.julia/packages/Revise/OgnOk/src/packagedef.jl:709
┌ Warning: The running code does not match the saved version for the following files:
│ 
│   /home/pfitzseb/test.jl
│ 
│ If the error was due to evaluation order, it can sometimes be resolved by calling `Revise.retry()`.
│ Use Revise.errors() to report errors again. Only the first error in each file is shown.
│ Your prompt color may be yellow until the errors are resolved.
└ @ Revise ~/.julia/packages/Revise/OgnOk/src/packagedef.jl:817
using Infiltrator

function test()
    ϕ = "what'
    @infiltrate
    sin(ϕ)
end


julia> test()
Infiltrating test() at test.jl:5:

infil> 

ERROR: MethodError: no method matching sin(::String)
Closest candidates are:
  sin(::Float16) at math.jl:1159
  sin(::ComplexF16) at math.jl:1160
  sin(::Complex{T}) where T at complex.jl:831
  ...
Stacktrace:
 [1] test()
   @ Main ~/test.jl:6
 [2] top-level scope
   @ REPL[4]:1
 [3] top-level scope
   @ ~/.julia/dev/Infiltrator/src/Infiltrator.jl:473

shell> cat test.jl
using Infiltrator

function test()
    ϕ = "what"
    @infiltrate
    sin(ϕ)
end


julia> test()
Infiltrating test() at test.jl:5:

infil> 

ERROR: MethodError: no method matching sin(::String)
Closest candidates are:
  sin(::Float16) at math.jl:1159
  sin(::ComplexF16) at math.jl:1160
  sin(::Complex{T}) where T at complex.jl:831
  ...
Stacktrace:
 [1] test()
   @ Main ~/test.jl:6
 [2] top-level scope
   @ REPL[6]:1
 [3] top-level scope
   @ ~/.julia/dev/Infiltrator/src/Infiltrator.jl:473

julia> Revise.revise()

julia> test()
Infiltrating test() at test.jl:5:

infil> 

ERROR: MethodError: no method matching sin(::String)
Closest candidates are:
  sin(::Float16) at math.jl:1159
  sin(::ComplexF16) at math.jl:1160
  sin(::Complex{T}) where T at complex.jl:831
  ...
Stacktrace:
 [1] test()
   @ Main ~/test.jl:6
 [2] top-level scope
   @ REPL[8]:1
 [3] top-level scope
   @ ~/.julia/dev/Infiltrator/src/Infiltrator.jl:473

pfitzseb avatar Sep 06 '21 14:09 pfitzseb

I'm incredibly confused... I can reproduce this quite reliably...

ExpandingMan avatar Sep 06 '21 14:09 ExpandingMan

The fact that I was able to achieve the same behavior you got when I changed the code a bit may suggest that this is a terrifying heisenbug... :fearful:

ExpandingMan avatar Sep 06 '21 14:09 ExpandingMan

If you have time it would be useful to see what Revise's debug tools say to your situation: https://timholy.github.io/Revise.jl/stable/debugging/.

pfitzseb avatar Sep 06 '21 14:09 pfitzseb

I'm so confused... I can't even get Revise to capture any logs... I'm using Revise.debug_logger but it never gets populated...

Maybe there is something really whacked out about my Revise? At this point I don't know what that can be though, I'm just using latest tags, and now my startup.jl does exactly what Revise recommends. I'm pretty stumped.

ExpandingMan avatar Sep 06 '21 17:09 ExpandingMan

Pinging @timholy in case he has any idea what's going on here.

pfitzseb avatar Sep 07 '21 07:09 pfitzseb

A small update on this, still experiencing this, it's still pretty annoying, and I still can't seem to figure out what's going on. However, so far it seems that when I do Revise.revise() it fixes the problem, which might suggest this is more of a Revise problem than an infiltrator problem. Perhaps it's failing to properly expand the macro when it gest updated? No idea

ExpandingMan avatar Sep 12 '21 16:09 ExpandingMan

Still can't isolate this but I've been dealing with this for quite a while now so I wanted to update with my experiences...

This still happens all the time and is very annoying, however, any time it does happen I can always fix it by explicitly calling Revise.revise(), so at least there is a quick workaround. It always starts happening after making an edit involving @infiltrate, not otherwise.

ExpandingMan avatar Sep 22 '21 00:09 ExpandingMan

I'll close this for now. Feel free to reopen this or open a new issues if you encounter the bug again.

pfitzseb avatar Apr 08 '24 11:04 pfitzseb