Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

What about:

  x := &a
  a = sort(a)
  print(x)  // Sorted?
To detect whether something can be mutated in place will require static analysis to see if there are aliases or pointers to the data. If this is an optimization that's based on whether something is safe to mutate in-place, you'll run into the problem where performance becomes different depending on whether something can be optimized or not. For example, adding "x" makes the sort call suddenly perform worse since the compiler sees that it can't mutate "a" in-place.

This is assuming that you allow multiple aliases to the same data. The reason Rust has lifetimes and borrowing is precisely to be safe about mutation. Rust wouldn't allow sort() to modify "a" in-place in the above code.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: