# Strange Revise error

**URL:** <https://discourse.julialang.org/t/strange-revise-error/91018>\
**Category:** General Usage\
**Tags:** revise\
**Created:** [November 29, 2022, 11:09pm UTC](https://discourse.julialang.org/t/strange-revise-error/91018 "2022-11-29T23:09:04Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![brianguenter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brianguenter/32/29519_2.png) [@brianguenter](https://discourse.julialang.org/u/brianguenter)\
**Post date:** [November 29, 2022, 11:09pm UTC](https://discourse.julialang.org/t/strange-revise-error/91018/1 "2022-11-29T23:09:04Z")

</div>

I have run into a strange error that appears to be related to Revise. Revise reports a problem with a function

> **Revise error message**
>
> ```julia
> julia> Revise.retry()
> ┌ Error: Failed to revise /home/brian/repos/Differentiation/src/Factoring.jl
> │ exception =
> │ function type in method definition is not a type
> │ Stacktrace:
> │ [1] top-level scope @ ~/repos/Differentiation/src/Factoring.jl:108
> │ Revise evaluation error at /home/brian/repos/Differentiation/src/Factoring.jl:108
> │    
> └ @ Revise ~/.julia/packages/Revise/do2nH/src/packagedef.jl:715
> ┌ Error: Failed to revise /home/brian/repos/Differentiation/src/Factoring.jl
> │ exception =
> │ function type in method definition is not a type
> │ Stacktrace:
> │ [1] top-level scope @ ~/repos/Differentiation/src/Factoring.jl:108
> │ Revise evaluation error at /home/brian/repos/Differentiation/src/Factoring.jl:108
> │    
> └ @ Revise ~/.julia/packages/Revise/do2nH/src/packagedef.jl:715
> 
> ```

and once this error occurs once it seems impossible to get rid of it no matter how the code in the function is altered. The error message is exactly the same at the same line number even if that line number is no longer in the function.

Tried making a MWE but it’s difficult; can’t just comment out parts of the code until the error goes away because it never goes away.

Here is the function causing the problem:

> **Function causing the problem**
>
> ```julia
> function frontier_nodes(graph::DerivativeGraph, base_node::T, dom_node::T) where {T<:Integer}
> # condition for a frontier node for the dominance case, i.e., base_node > dom_node. Post dominance conditions in parentheses: 
> # frontier node is contained in the domainance subgraph (base_node,dom_node) and
> # frontier node has a child that is not part of the dominance subgraph
> # Edges on the path from frontier node to base_node have to be preserved after factorization because these paths are not part of the factored subgraph.
> 
> nodes_on_frontier = Set{T}()
> 
> validate_node_numbers(graph, base_node, dom_node)
> 
> if base_node > dom_node
> if !dom(graph, base_node, dom_node)
> throw(ErrorException("tried to find frontier nodes in an invalid subgraph. Should have dom(base_node,dom_node) == true but it isn't."))
> end
> 
> function dom_frontier_test(x) 
> if x == dom_node || x == base_node
> return false
> else
> for child_num in node_children_numbers(graph, x)
> if !in_subgraph(graph, base_node, dom_node, child_num)
> return true
> end
> end
> 
> return false
> end
> end
> 
> inside_test = (x) -> dom(graph, base_node, x) && x <= base_node
> relation = (x) -> (x == base_node) ? T[] : node_parent_numbers(graph, x)
> _frontier_nodes(dom_node, relation, dom_frontier_test, inside_test, nodes_on_frontier)
> else
> if !pdom(graph, base_node, dom_node) #maybe should throw an exception here?
> throw(ErrorException("tried to find frontier nodes in an invalid subgraph. Should have pdom(base_node,dom_node) == true but it isn't."))
> end
> 
> function pdom_frontier_test(x)
> if x == dom_node || x == base_node
> return false
> else
> for parent_num in node_parent_numbers(graph, x)
> if !in_subgraph(graph, base_node, dom_node, parent_num)
> return true
> end
> end
> 
> return false
> end
> end
> 
> #this might be inefficient if the inside_test function has to be compiled each time because it captures base_node.
> inside_test = (x) -> x >= base_node && pdom(graph, base_node, x) #base_node can satisfy the frontier test but it doesn't matter because no edges will be preserved. So base node shouldn't be in list of frontier nodes.
> relation = (x) -> node_children_numbers(graph, x)
> _frontier_nodes(dom_node, relation, pdom_frontier_test, inside_test, nodes_on_frontier)
> end
> 
> return nodes_on_frontier
> end
> export frontier_nodes
> 
> ```

Once the error is triggered no code change seems able to make Revise not report the error. If almost every line of code inside the function is commented out

> **Function with most code commented out**
>
> ```julia
> 
> function frontier_nodes(graph::DerivativeGraph, base_node::T, dom_node::T) where {T<:Integer}
> # condition for a frontier node for the dominance case, i.e., base_node > dom_node. Post dominance conditions in parentheses: 
> # frontier node is contained in the domainance subgraph (base_node,dom_node) and
> # frontier node has a child that is not part of the dominance subgraph
> # Edges on the path from frontier node to base_node have to be preserved after factorization because these paths are not part of the factored subgraph.
> 
> nodes_on_frontier = Set{T}()
> 
> # validate_node_numbers(graph, base_node, dom_node)
> 
> # if base_node > dom_node
> # if !dom(graph, base_node, dom_node)
> # throw(ErrorException("tried to find frontier nodes in an invalid subgraph. Should have dom(base_node,dom_node) == true but it isn't."))
> # end
> 
> # function dom_frontier_test(x) 
> # if x == dom_node || x == base_node
> # return false
> # else
> # for child_num in node_children_numbers(graph, x)
> # if !in_subgraph(graph, base_node, dom_node, child_num)
> # return true
> # end
> # end
> 
> # return false
> # end
> # end
> 
> # inside_test = (x) -> dom(graph, base_node, x) && x <= base_node
> # relation = (x) -> (x == base_node) ? T[] : node_parent_numbers(graph, x)
> # _frontier_nodes(dom_node, relation, dom_frontier_test, inside_test, nodes_on_frontier)
> # else
> # if !pdom(graph, base_node, dom_node) #maybe should throw an exception here?
> # throw(ErrorException("tried to find frontier nodes in an invalid subgraph. Should have pdom(base_node,dom_node) == true but it isn't."))
> # end
> 
> # function pdom_frontier_test(x)
> # if x == dom_node || x == base_node
> # return false
> # else
> # for parent_num in node_parent_numbers(graph, x)
> # if !in_subgraph(graph, base_node, dom_node, parent_num)
> # return true
> # end
> # end
> 
> # return false
> # end
> # end
> 
> # #this might be inefficient if the inside_test function has to be compiled each time because it captures base_node.
> # inside_test = (x) -> x >= base_node && pdom(graph, base_node, x) #base_node can satisfy the frontier test but it doesn't matter because no edges will be preserved. So base node shouldn't be in list of frontier nodes.
> # relation = (x) -> node_children_numbers(graph, x)
> # _frontier_nodes(dom_node, relation, pdom_frontier_test, inside_test, nodes_on_frontier)
> # end
> 
> return nodes_on_frontier
> end
> export frontier_nodes
> 
> ```

Revise still gives the same error message, with the same line number. If I then kill and restart the REPL and call this same function it runs fine with no Revise errors.

If the commented code is uncommented then the error appears again. Recommenting exactly the same lines that were uncommented doesn’t cause the error to go away.

If all the commented code is deleted then Revise reports the same error at the same line number, 108, even though that line number isn’t in the function anymore.

Has anybody encountered this problem before?

---

<div class="post-metadata">

**Author:** ![Dan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dan/32/42581_2.png) [@Dan](https://discourse.julialang.org/u/Dan)\
**Post date:** [November 29, 2022, 11:40pm UTC](https://discourse.julialang.org/t/strange-revise-error/91018/2 "2022-11-29T23:40:43Z")

</div>

Just a hunch. `pdom_frontier_test` is defined and used on both branches of the `if` statement. Perhaps having a different function name for each branch will unconfuse Revise. This should not matter to the logic of the code.

If that is not an option, maybe defining a ‘stub’ function and assigning to `pdom_frontier_test` before the `if` split. Then inside the `if`, reassig to the specifc branch version.

Totally hunch based and untested suggestion.

---

<div class="post-metadata">

**Author:** ![brianguenter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brianguenter/32/29519_2.png) [@brianguenter](https://discourse.julialang.org/u/brianguenter)\
**Post date:** [November 30, 2022, 12:30am UTC](https://discourse.julialang.org/t/strange-revise-error/91018/3 "2022-11-30T00:30:50Z")

</div>

Thanks for the suggestion but I think pdom\_frontier\_test is only defined in one branch of the if. dom\_frontier\_test is defined in the other.

But your suggestion got me thinking that Revise might be having trouble tracking the functions being defined inside frontier\_nodes. So I moved dom\_frontier\_test and pdom\_frontier\_test outside of frontier\_nodes. Now Revise is happy and everything works.

Thanks for the nudge in the right direction.

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 30, 2022, 9:30am UTC](https://discourse.julialang.org/t/strange-revise-error/91018/4 "2022-11-30T09:30:56Z")

</div>

I won’t pretend I’ve actually read your code or understand the solution, but if you think it might have been reasonable to expect of Revise to track the definitions in their original place it might be worth an issue?

---

<div class="post-metadata">

**Author:** ![brianguenter](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brianguenter/32/29519_2.png) [@brianguenter](https://discourse.julialang.org/u/brianguenter)\
**Post date:** [November 30, 2022, 10:45pm UTC](https://discourse.julialang.org/t/strange-revise-error/91018/5 "2022-11-30T22:45:30Z")

</div>

I spoke too soon. The same revise error is back now, even after I moved the function definitions outside of the frontier\_nodes function.

This looks like a bug. The code compiles and runs fine the first time. Then after any change that causes Revise to look at the file the error pops up and doesn’t go away, apparently no matter what changes are made to the code including completely deleting the function that caused the Revise error. Same error, same line number.

The only way to make it go away is to kill the REPL and restart. That doesn’t seem like the way Revise should work.

I’ll file an issue.
