I am considering an optimization pass to run after refFlatten that turns:<br> val y = !x<br> val () = x := y<br>into a noop.<br><br>I think the best way to do this is run a DFS and tag refs with a serial number. A deref (!) records the serial number on the assigned variable and any reassignments of that variable. Finally, if a reference is written to (:=), check the variable to see if it is a load of this variable with identical serial number, if so, remove the assignment. If not, increase the serial number.<br>
<br>That way in<br> val y = !x<br> val () = x := !x + 1<br> val z = !x<br> val a = !x<br> val () = x := z<br> val () = x := a<br> val () = x := y<br>the 2nd and 3rd assignments get eliminated, but not 1st and 4th.<br>
<br>This optimization is specifically a follow-up optimization to DeepFlatten. If DeepFlatten turned a ref tuple into a record, chances are that a lot of the fields are unmodified when it gets rewritten. In my particular application only 1-3 fields out of 21 or more get changed, so this would be a good speed-up for me at least.<br>
<br>Any comments?<br><br>