timholy / Revise.jl

Automatically update function definitions in a running Julia session
https://timholy.github.io/Revise.jl/stable
Other
1.19k stars 109 forks source link

Error line numbers ignore changes to whitespace inside function body #814

Open colemanbroad opened 5 months ago

colemanbroad commented 5 months ago

I open a REPL and use includet() on the following...


# error line number reflects changes to comments and whitespace outside function body

function trial()

    # but here comments/whitespace changes are ignored

    1 # adding/changing expressions forces line number refresh 

    error()
end

Tested in julia 1.9, 1.10, 1.11alpha

timholy commented 1 month ago

Yeah, Revise deliberately discards whitespace-only differences within function bodies. Are you saying this upsets error reports in line numbers?

colemanbroad commented 1 month ago

Yep, the line numbers aren't updated when whitespace is added.

timholy commented 1 month ago

It works (or should) for whitespace added outside method bodies. The reason for the difference is that Revise can do external whitespace (e.g., adding a comment at the top of a file) "non-destructively," meaning it doesn't have to redefine any methods and thus does not trigger any invalidations. In contrast, the only way to update line numbering inside a method is to redefine the method. If that method is, e.g., Base.get(::Dict, ::Any, ::Any), you might be in for 60s or so of recompilation due to triggering a huge number of invalidations. Thus I've felt that the current system is the lesser of two evils.