Conversation
Substitute `arr` for `v` when `arr` is free in the `body`. This is very nice for copy propagation, but not possible in the typed representation.
|
Clarification from mine and Anders' discussion: the variable This is morally safe in single threaded code if |
|
The point of @josefs clarification was what I was after in my previous comment in the other pull request as well. That should be fixed in the comment in this commit as well. Mutable is really just a different word for "very hard", especially in the context of concurrency. It sounds reasonable that this is safe in a single threaded context. I have no idea whether we are guaranteed to be in a single threaded context at all times though. |
Substitute `arr` for `v` when `arr` is not used in the `body`. This is very nice for copy propagation, but not possible in the typed representation.
|
Just a note: Peter has been talking about type checking the simplified code as a way to catch errors. Maybe there should be an |
|
Another possibility is to do this kind of rewrite at a lower level representation, i.e. the imperative representation. At that point there is no distinction between mutable and immutable arrays. |
Substitute
arrforvwhenarris free in thebody.This is very nice for copy propagation, but not possible in the typed
representation.
Is this rewrite morally safe? I.e. is it enough to check that
arris free in thebodyor do we risk leaking an alias toarr?/cc @pjonsson, @emilaxelsson, @josefs