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

Restart reason: Change in binding resolution

Open Keno opened this issue 6 years ago • 2 comments

Say you accidentally write something like this in a package:

foo() = iterate(...)
iterate(a::Foo) = ...

The second definition is wrong. What was intended was to extend Base.iterate. Now, if I add the missing Base., revise will delete the method, but the binding in foo will still resolve to the (now methodless) iterate function in my module. Not sure this can be addressed in the near term, but wanted to document it as a reason I had to restart my session.

Keno avatar Feb 01 '19 06:02 Keno

Interesting. The rewrite I'm getting started on now, based on lowered code (https://github.com/JuliaDebug/ASTInterpreter2.jl/issues/32), offers an opportunity to fix this via backedges. Your timing was fortuitous.

timholy avatar Feb 01 '19 08:02 timholy

I have a "fix" for this in the branch teh/bindings, but there's one teeny problem. I think I was fooled by the fact that you can do

julia> first = 0
0

julia> first = Base.first
first (generic function with 24 methods)

but when you try this with functions:

julia> struct Iter end

julia> iterate(i::Iter) = i, nothing
iterate (generic function with 1 method)

julia> iterate(i::Iter, ::Any) = nothing
iterate (generic function with 2 methods)

julia> mths = methods(iterate)
# 2 methods for generic function "iterate":
[1] iterate(i::Iter) in Main at REPL[2]:1
[2] iterate(i::Iter, ::Any) in Main at REPL[3]:1

julia> Base.delete_method(mths.ms[1])

julia> Base.delete_method(mths.ms[2])

julia> iterate = Base.iterate
ERROR: invalid redefinition of constant iterate
Stacktrace:
 [1] top-level scope at none:0

Know of any workaround?

timholy avatar Apr 06 '19 18:04 timholy