Skip to content

Commit 023fbdf

Browse files
authored
Add push! etc to selective eval if array is needed (#89)
For any created arrays, we need to execute commands that will modify them in-place.
1 parent dde32b1 commit 023fbdf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/codeedges.jl

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ function lines_required!(isrequired::AbstractVector{Bool}, objs, src::CodeInfo,
633633

634634
# So far, everything is generic graph traversal. Now we add some domain-specific information
635635
changed |= add_typedefs!(isrequired, src, edges, typedefs, norequire)
636+
changed |= add_inplace!(isrequired, src, edges, norequire)
636637

637638
iter += 1 # just for diagnostics
638639
end
@@ -873,6 +874,30 @@ function add_typedefs!(isrequired, src::CodeInfo, edges::CodeEdges, (typedef_blo
873874
return changed
874875
end
875876

877+
# For arrays, add any `push!`, `pop!`, `empty!` or `setindex!` statements
878+
# This is needed for the "Modify @enum" test in Revise
879+
function add_inplace!(isrequired, src, edges, norequire)
880+
changed = false
881+
for (i, isreq) in pairs(isrequired)
882+
isreq || continue
883+
for j in edges.succs[i]
884+
j norequire && continue
885+
stmt = src.code[j]
886+
if isexpr(stmt, :call) && length(stmt.args) >= 2
887+
arg = stmt.args[2]
888+
if @isssa(arg) && arg.id == i
889+
fname = stmt.args[1]
890+
if is_quotenode_egal(fname, Base.push!) || is_quotenode_egal(fname, Base.pop!) || is_quotenode_egal(fname, Base.empty!) || is_quotenode_egal(fname, Base.setindex!)
891+
changed |= !isrequired[j]
892+
isrequired[j] = true
893+
end
894+
end
895+
end
896+
end
897+
end
898+
return changed
899+
end
900+
876901
"""
877902
selective_eval!([recurse], frame::Frame, isrequired::AbstractVector{Bool}, istoplevel=false)
878903

0 commit comments

Comments
 (0)