Skip to content

Commit ee9c3c6

Browse files
authored
Add slots to in-place marking (#92)
This should have been part of #89
1 parent af8e913 commit ee9c3c6

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

src/codeedges.jl

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,16 @@ end
877877
# For arrays, add any `push!`, `pop!`, `empty!` or `setindex!` statements
878878
# This is needed for the "Modify @enum" test in Revise
879879
function add_inplace!(isrequired, src, edges, norequire)
880+
function mark_if_inplace(stmt, j)
881+
_changed = false
882+
fname = stmt.args[1]
883+
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!)
884+
_changed = !isrequired[j]
885+
isrequired[j] = true
886+
end
887+
return _changed
888+
end
889+
880890
changed = false
881891
for (i, isreq) in pairs(isrequired)
882892
isreq || continue
@@ -886,10 +896,20 @@ function add_inplace!(isrequired, src, edges, norequire)
886896
if isexpr(stmt, :call) && length(stmt.args) >= 2
887897
arg = stmt.args[2]
888898
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
899+
changed |= mark_if_inplace(stmt, j)
900+
elseif @issslotnum(arg)
901+
id = arg.id
902+
# Check to see if we use this slot
903+
for k in edges.preds[j]
904+
isrequired[k] || continue
905+
predstmt = src.code[k]
906+
if isexpr(predstmt, :(=))
907+
lhs = predstmt.args[1]
908+
if @issslotnum(lhs) && lhs.id == id
909+
changed |= mark_if_inplace(stmt, j)
910+
break
911+
end
912+
end
893913
end
894914
end
895915
end

0 commit comments

Comments
 (0)