877
877
# For arrays, add any `push!`, `pop!`, `empty!` or `setindex!` statements
878
878
# This is needed for the "Modify @enum" test in Revise
879
879
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
+
880
890
changed = false
881
891
for (i, isreq) in pairs (isrequired)
882
892
isreq || continue
@@ -886,10 +896,20 @@ function add_inplace!(isrequired, src, edges, norequire)
886
896
if isexpr (stmt, :call ) && length (stmt. args) >= 2
887
897
arg = stmt. args[2 ]
888
898
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
893
913
end
894
914
end
895
915
end
0 commit comments